From roggero.n at gmail.com Fri Sep 6 19:17:58 2013 From: roggero.n at gmail.com (roggero.n at gmail.com) Date: Fri, 6 Sep 2013 16:17:58 -0700 (PDT) Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: Message-ID: <481dce27-9615-440c-858f-2ad0529f192f@googlegroups.com> shut off the HD, start the SO form an USB and shut on again the HD From shubhxx54 at gmail.com Sat Sep 21 03:19:02 2013 From: shubhxx54 at gmail.com (shubhxx54 at gmail.com) Date: Sat, 21 Sep 2013 00:19:02 -0700 (PDT) Subject: Beginner - GUI devlopment in Tkinter - Any IDE with drag and drop feature like Visual Studio? In-Reply-To: References: Message-ID: i am very confuse about gui development in python .. i installed qt creator .. but it has no option for python.. how can i bulit any app using drag n drop facilities ... i am trying wxpython .. plz help me . how i use wxpython .. plzz help me.. From asmbansal2 at gmail.com Sat Sep 21 04:06:03 2013 From: asmbansal2 at gmail.com (Aseem Bansal) Date: Sat, 21 Sep 2013 01:06:03 -0700 (PDT) Subject: Beginner - GUI devlopment in Tkinter - Any IDE with drag and drop feature like Visual Studio? In-Reply-To: References: Message-ID: <489b4888-0113-4dd2-8a5e-1218286e428e@googlegroups.com> You need to install PySide for GUI development. You don't need Qt Creator. When you have PySide installed there is a Qt Designer in your python installation directory. You use that for drag and drop GUI development. Search google for PySide and you'll find tutorials for that. From davea at davea.name Sat Sep 21 09:19:31 2013 From: davea at davea.name (Dave Angel) Date: Sat, 21 Sep 2013 13:19:31 +0000 (UTC) Subject: Beginner - GUI devlopment in Tkinter - Any IDE with drag and drop feature like Visual Studio? References: Message-ID: On 21/9/2013 03:19, shubhxx54 at gmail.com wrote: > i am very confuse about gui development in python .. > i installed qt creator .. but it has no option for python.. > how can i bulit any app using drag n drop facilities ... > i am trying wxpython .. > plz help me . > how i use wxpython .. > plzz help me.. > You mention three different GUI toolkits: 1) subject line says Tkinter 2) you say wxpython 3) your qt creator is presumably connected with qt You need to get some consistent set of tools. -- DaveA From metaliobovinus at gmail.com Thu Sep 5 18:21:28 2013 From: metaliobovinus at gmail.com (Metallicow) Date: Thu, 5 Sep 2013 15:21:28 -0700 (PDT) Subject: PEP8 79 char max In-Reply-To: References: <51F6C5F5.5020201@Gmail.com> <51f6e1d8$0$30000$c3e8da3$5496439d@news.astraweb.com> <51F6ED13.5010508@Gmail.com> Message-ID: <640206d7-a42f-4ae8-b9d6-cd5b3d158a6c@googlegroups.com> Well as for my opinion, it is more closer to the truth than others because... Experience: 1. I know Python and have read the PEP8. 2. I have knowledge of/worked with the Printing Trades. 3. Grandfather owned/operated own Printshop for 40+yrs. Which I also worked in at one point. If you are still using equipment that requires 79, then chances are you have/will already gone out of business or are keeping/using said equipment for nostalgic purposes. As far as math goes. 10 is a nice round number. So multiples of 10 are prefer. 80 being my personal choice for editing. Zen says: Simple is better than complex. Use a round number. Integer math is easier than float math for the majority of the population. Time yourself, not the interpreter with these three questions: In the face of ambiguity, refuse the temptation to guess. If it helps get out the old school pen and paper. Question1: 80/8 Question2: 79/8 Question3: How many chars does you calculator(real or virtual) support? Zen says: Special cases aren't special enough to break the rules. PEP8 isn't a rule. Rules are defined by the equipment/device developers. Ask yourself... How often do you actually use these 79char devices? Of course it is understandable for something small that can fit in your pocket might have less. For Example a smartphone. Zen says: Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. PEP8 would have been better to define various numbers for realworld types of equipment/devices based on average general type of equipment/device specs. Closing Zen: If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Yep, that's my nuts and bolts on the issue. Walk into you local Printshop and ask them about this stuff. Then on your way out the door, ask for a business card and see how many chars are on that also. Beware: You might actually learn something about advertising while you are there also. :) From tjreedy at udel.edu Thu Sep 5 21:47:01 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 05 Sep 2013 21:47:01 -0400 Subject: PEP8 79 char max In-Reply-To: <640206d7-a42f-4ae8-b9d6-cd5b3d158a6c@googlegroups.com> References: <51F6C5F5.5020201@Gmail.com> <51f6e1d8$0$30000$c3e8da3$5496439d@news.astraweb.com> <51F6ED13.5010508@Gmail.com> <640206d7-a42f-4ae8-b9d6-cd5b3d158a6c@googlegroups.com> Message-ID: On 9/5/2013 6:21 PM, Metallicow wrote: > > If you are still using equipment that requires 79, then chances are you have/will already gone out of business or are keeping/using said equipment for nostalgic purposes. > > As far as math goes. 10 is a nice round number. 79 chars + 1 cursor (or \n) == 80, the nice round number. Anyway, it is just a guideline. Ignore it if you wish. -- Terry Jan Reedy From metaliobovinus at gmail.com Thu Sep 5 22:59:34 2013 From: metaliobovinus at gmail.com (Metallicow) Date: Thu, 5 Sep 2013 19:59:34 -0700 (PDT) Subject: PEP8 79 char max In-Reply-To: References: <51F6C5F5.5020201@Gmail.com> <51f6e1d8$0$30000$c3e8da3$5496439d@news.astraweb.com> <51F6ED13.5010508@Gmail.com> <640206d7-a42f-4ae8-b9d6-cd5b3d158a6c@googlegroups.com> Message-ID: <86d2dc56-05b4-45e8-b2e8-0fc128ec3724@googlegroups.com> On Thursday, September 5, 2013 8:47:01 PM UTC-5, Terry Reedy wrote: > On 9/5/2013 6:21 PM, Metallicow wrote: > > > > > > If you are still using equipment that requires 79, then chances are you have/will already gone out of business or are keeping/using said equipment for nostalgic purposes. > > > > > > As far as math goes. 10 is a nice round number. > > > > 79 chars + 1 cursor (or \n) == 80, the nice round number. > > > > Anyway, it is just a guideline. Ignore it if you wish. > > > > -- > > Terry Jan Reedy Well, what I interpret as the PEP8 79 is chars visible minus the '\n' or '\r\n'(which would be 2; 81) line enders. This is not stated in PEP8. PEP8 needs a bit of revision anyway, In my opinion... According to real-world standards for equipment/devices. linking to a table/list of affected devices/minNumbers should be the norm. or.... ... from codingguidelines import PEPStandards ... or something similar(Official PEP Zen Guidelines) From steve+comp.lang.python at pearwood.info Fri Sep 6 00:01:31 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Sep 2013 04:01:31 GMT Subject: PEP8 79 char max References: <51F6C5F5.5020201@Gmail.com> <51f6e1d8$0$30000$c3e8da3$5496439d@news.astraweb.com> <51F6ED13.5010508@Gmail.com> <640206d7-a42f-4ae8-b9d6-cd5b3d158a6c@googlegroups.com> <86d2dc56-05b4-45e8-b2e8-0fc128ec3724@googlegroups.com> Message-ID: <5229539b$0$29988$c3e8da3$5496439d@news.astraweb.com> On Thu, 05 Sep 2013 19:59:34 -0700, Metallicow wrote: > PEP8 needs a bit of revision anyway, In my opinion... According to > real-world standards for equipment/devices. linking to a table/list of > affected devices/minNumbers should be the norm. or.... I don't believe you have thought this through, or in any detail. The first problem is, what "real-world standards" are you talking about? What sort of devices are you referring to? How is this supposed to work in practice? If I write a Python module, which device am I supposed to pick? It's a particularly ill-thought-out suggestion when you consider than PEP 8 is for the Python standard library, and any document in the std lib will be read on a vast number of different devices, using different monitors with different screen resolutions and different widths, in different editors using different typefaces on different operating systems by people of different visual acuity. The point of a coding standard for maximum line width is to average out all those myriad differences and give something which works pretty well overall regardless of the device. In other words, the coding standard defines a minimum capability (in this case, "you can display at least 79 characters per line") and recommends you write to that standard. > from codingguidelines import PEPStandards > > ... or something similar(Official PEP Zen Guidelines) And that's especially badly thought out. How is an import that occurs when the code is *run* supposed to make a difference to the way the code is *written*? -- Steven From metaliobovinus at gmail.com Fri Sep 6 00:21:39 2013 From: metaliobovinus at gmail.com (Metallicow) Date: Thu, 5 Sep 2013 21:21:39 -0700 (PDT) Subject: PEP8 79 char max In-Reply-To: <5229539b$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <51F6C5F5.5020201@Gmail.com> <51f6e1d8$0$30000$c3e8da3$5496439d@news.astraweb.com> <51F6ED13.5010508@Gmail.com> <640206d7-a42f-4ae8-b9d6-cd5b3d158a6c@googlegroups.com> <86d2dc56-05b4-45e8-b2e8-0fc128ec3724@googlegroups.com> <5229539b$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thursday, September 5, 2013 11:01:31 PM UTC-5, Steven D'Aprano wrote: > And that's especially badly thought out. How is an import that occurs > when the code is *run* supposed to make a difference to the way the code > is *written*? Proofreading. Or maybe call it pre typesetting. From metaliobovinus at gmail.com Fri Sep 6 09:34:07 2013 From: metaliobovinus at gmail.com (Metallicow) Date: Fri, 6 Sep 2013 06:34:07 -0700 (PDT) Subject: PEP8 79 char max In-Reply-To: <5229539b$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <51F6C5F5.5020201@Gmail.com> <51f6e1d8$0$30000$c3e8da3$5496439d@news.astraweb.com> <51F6ED13.5010508@Gmail.com> <640206d7-a42f-4ae8-b9d6-cd5b3d158a6c@googlegroups.com> <86d2dc56-05b4-45e8-b2e8-0fc128ec3724@googlegroups.com> <5229539b$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2c50861b-5bce-4977-8879-3456cb7f3bc3@googlegroups.com> On Thursday, September 5, 2013 11:01:31 PM UTC-5, Steven D'Aprano wrote: > On Thu, 05 Sep 2013 19:59:34 -0700, Metallicow wrote: > > PEP8 needs a bit of revision anyway, In my opinion... According to > > real-world standards for equipment/devices. linking to a table/list of > > affected devices/minNumbers should be the norm. or.... > > I don't believe you have thought this through, or in any detail. The > first problem is, what "real-world standards" are you talking about? What > sort of devices are you referring to? How is this supposed to work in > practice? If I write a Python module, which device am I supposed to pick? http://en.wikipedia.org/wiki/Revision Why even define a number? I causes people to argue about it. It is a variable. I meant a "Reference" Table of equipment/devices. Most Auto shop have a "Cross-Reference book". Also Johnny Cash built a vehicle from 30 years or so different years parts(or I know people who do/can). Reference PEP8 standard to: A Technical manual per say. If not make it simple. A multiple of 10, 80 being the closest int and also errors on 79 devices. Which then said device should be added to the reference manual. Or 70. Also the pro/cons of this argument should be added to a "Quick-Reference". Sorry if my opinion was not clear, the first time I posted. As I have been answered before, you CANNOT edit posts here. But you could with python... From metaliobovinus at gmail.com Fri Sep 6 12:07:24 2013 From: metaliobovinus at gmail.com (Metallicow) Date: Fri, 6 Sep 2013 09:07:24 -0700 (PDT) Subject: PEP8 79 char max In-Reply-To: <2c50861b-5bce-4977-8879-3456cb7f3bc3@googlegroups.com> References: <51F6C5F5.5020201@Gmail.com> <51f6e1d8$0$30000$c3e8da3$5496439d@news.astraweb.com> <51F6ED13.5010508@Gmail.com> <640206d7-a42f-4ae8-b9d6-cd5b3d158a6c@googlegroups.com> <86d2dc56-05b4-45e8-b2e8-0fc128ec3724@googlegroups.com> <5229539b$0$29988$c3e8da3$5496439d@news.astraweb.com> <2c50861b-5bce-4977-8879-3456cb7f3bc3@googlegroups.com> Message-ID: <7af80c61-4700-43eb-892e-91d7b35684dc@googlegroups.com> Google(will) Search This Message: Industry Standards, PEP8, Whitespace, Print, Printing, Opinion' I could add more... For example: Pantone color wheel. From skip at pobox.com Fri Sep 6 06:09:37 2013 From: skip at pobox.com (Skip Montanaro) Date: Fri, 6 Sep 2013 05:09:37 -0500 Subject: PEP8 79 char max In-Reply-To: <86d2dc56-05b4-45e8-b2e8-0fc128ec3724@googlegroups.com> References: <51F6C5F5.5020201@Gmail.com> <51f6e1d8$0$30000$c3e8da3$5496439d@news.astraweb.com> <51F6ED13.5010508@Gmail.com> <640206d7-a42f-4ae8-b9d6-cd5b3d158a6c@googlegroups.com> <86d2dc56-05b4-45e8-b2e8-0fc128ec3724@googlegroups.com> Message-ID: > Well, what I interpret as the PEP8 79 is chars visible minus the '\n' or '\r\n'(which would be 2; 81) line enders. You young un's. Always makin' stuff up... :-) In these days of fancy single-user PCs with sophisticated window systems, people tend to forget that BITD there was a thriving market for serially-connected terminals (most only had 80 columns and 24 rows) connected to timesharing machines of various kinds (DEC VAX and PDP-11 machines were extremely common in the Unix world). Many (some? most? all?) of those terminals had a "feature" where if a character was displayed in column 80, the cursor would automatically wrap around and blink mindlessly in column 1 of the next row. That was even more unpleasant behavior if you happened to enter text in the last column of the last row, as then your cursor would blink in row 1, column 1. I think there is a termcap code that specifies whether or not a given terminal exhibits this behavior. Hence 79. /etc/termcap on my OpenSuSE system has over 1600 entries, most for terminals which were resigned to the junk heap decades ago. Today, we can probably just get by with entries for a couple xterm or ansi variants. And thank goodness for SIGWINCH. :-) Skip From python.list at tim.thechases.com Fri Sep 6 06:35:25 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 6 Sep 2013 05:35:25 -0500 Subject: PEP8 79 char max In-Reply-To: References: <51F6C5F5.5020201@Gmail.com> <51f6e1d8$0$30000$c3e8da3$5496439d@news.astraweb.com> <51F6ED13.5010508@Gmail.com> <640206d7-a42f-4ae8-b9d6-cd5b3d158a6c@googlegroups.com> <86d2dc56-05b4-45e8-b2e8-0fc128ec3724@googlegroups.com> Message-ID: <20130906053525.1b07b775@bigbox.christie.dr> On 2013-09-06 05:09, Skip Montanaro wrote: > And thank goodness for SIGWINCH. :-) BEDEVERE: How do you know she is a SIGWINCH? VILLAGER: She looks like one. CROWD: Right! Yeah! Yeah! :-) I'm just glad it's no longer 40-chars-per-column and purely upper-case like the Apple ][+ on which I cut my programming teeth. -tkc From timothy.c.delaney at gmail.com Fri Sep 6 06:47:38 2013 From: timothy.c.delaney at gmail.com (Tim Delaney) Date: Fri, 6 Sep 2013 20:47:38 +1000 Subject: PEP8 79 char max In-Reply-To: <20130906053525.1b07b775@bigbox.christie.dr> References: <51F6C5F5.5020201@Gmail.com> <51f6e1d8$0$30000$c3e8da3$5496439d@news.astraweb.com> <51F6ED13.5010508@Gmail.com> <640206d7-a42f-4ae8-b9d6-cd5b3d158a6c@googlegroups.com> <86d2dc56-05b4-45e8-b2e8-0fc128ec3724@googlegroups.com> <20130906053525.1b07b775@bigbox.christie.dr> Message-ID: On 6 September 2013 20:35, Tim Chase wrote: > On 2013-09-06 05:09, Skip Montanaro wrote: > > And thank goodness for SIGWINCH. :-) > > BEDEVERE: How do you know she is a SIGWINCH? > > VILLAGER: She looks like one. > > CROWD: Right! Yeah! Yeah! > > > :-) > > I'm just glad it's no longer 40-chars-per-column and purely > upper-case like the Apple ][+ on which I cut my programming teeth. > Couldn't you switch the ][+ into high-res mode? You could with the IIe. Made programming in DOS 3.3 BASIC so much nicer. Tim Delaney -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Fri Sep 6 08:56:26 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 6 Sep 2013 07:56:26 -0500 Subject: PEP8 79 char max In-Reply-To: References: <51F6C5F5.5020201@Gmail.com> <51f6e1d8$0$30000$c3e8da3$5496439d@news.astraweb.com> <51F6ED13.5010508@Gmail.com> <640206d7-a42f-4ae8-b9d6-cd5b3d158a6c@googlegroups.com> <86d2dc56-05b4-45e8-b2e8-0fc128ec3724@googlegroups.com> <20130906053525.1b07b775@bigbox.christie.dr> Message-ID: <20130906075626.307ecfb5@bigbox.christie.dr> On 2013-09-06 20:47, Tim Delaney wrote: > On 6 September 2013 20:35, Tim Chase wrote: > > I'm just glad it's no longer 40-chars-per-column and purely > > upper-case like the Apple ][+ on which I cut my programming teeth. > > Couldn't you switch the ][+ into high-res mode? You could with the > IIe. Made programming in DOS 3.3 BASIC so much nicer. There was an 80-column add-on card that also supported lower-case (though, IIRC, you also had to do a hardware hack to wire the key to the joystick button to get it to be recognized in certain cases). The IIe was a far better machine, having the 80-column card built in. PR#3 :-) I'm also glad Python doesn't require prefixing lines with line-numbers for GOTO/GOSUB purposes, then requiring external the line-renumbering utilities that AppleSoft BASIC required :-S -tkc From neilc at norwich.edu Fri Sep 6 09:12:35 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 6 Sep 2013 13:12:35 GMT Subject: PEP8 79 char max References: <51F6C5F5.5020201@Gmail.com> <51f6e1d8$0$30000$c3e8da3$5496439d@news.astraweb.com> <51F6ED13.5010508@Gmail.com> <640206d7-a42f-4ae8-b9d6-cd5b3d158a6c@googlegroups.com> <86d2dc56-05b4-45e8-b2e8-0fc128ec3724@googlegroups.com> <20130906053525.1b07b775@bigbox.christie.dr> Message-ID: On 2013-09-06, Tim Chase wrote: > On 2013-09-06 20:47, Tim Delaney wrote: >> On 6 September 2013 20:35, Tim Chase wrote: >> > I'm just glad it's no longer 40-chars-per-column and purely >> > upper-case like the Apple ][+ on which I cut my programming >> > teeth. >> >> Couldn't you switch the ][+ into high-res mode? You could with >> the IIe. Made programming in DOS 3.3 BASIC so much nicer. > > There was an 80-column add-on card that also supported > lower-case (though, IIRC, you also had to do a hardware hack to > wire the key to the joystick button to get it to be > recognized in certain cases). The IIe was a far better > machine, having the 80-column card built in. PR#3 :-) > > I'm also glad Python doesn't require prefixing lines with > line-numbers for GOTO/GOSUB purposes, then requiring external > the line-renumbering utilities that AppleSoft BASIC required > :-S Though its graphics and sound were far inferior, as a C64 user I was really jealous of the speed of the built-in Apple disk drives. The only programming I did on them was typing in some of the programs from "Compute!", back before it converted format to C64 only. Anybody care for a game of Laserchess? -- Neil Cerutti From metaliobovinus at gmail.com Fri Sep 6 08:24:42 2013 From: metaliobovinus at gmail.com (Metallicow) Date: Fri, 6 Sep 2013 05:24:42 -0700 (PDT) Subject: PEP8 79 char max In-Reply-To: References: <51F6C5F5.5020201@Gmail.com> <51f6e1d8$0$30000$c3e8da3$5496439d@news.astraweb.com> <51F6ED13.5010508@Gmail.com> <640206d7-a42f-4ae8-b9d6-cd5b3d158a6c@googlegroups.com> <86d2dc56-05b4-45e8-b2e8-0fc128ec3724@googlegroups.com> <20130906053525.1b07b775@bigbox.christie.dr> Message-ID: RailRoadTieWidth = 79.1234567890 >>> 79 = 'Width Of A Horse"s Ass' File "", line 1 SyntaxError: can't assign to literal >>>RailRoadTieWidth.attribute ("American", "Steam") >>>79.attribute = ("Roman", "Chariot") File "", line 1 79.attribute = ("Roman", "Chariot") ^ SyntaxError: invalid syntax Excuse me if this may be improper in you native language, butt... If the interpreter didn't have a sense of humor, I believe most people wouldn't use python. Most often it will return an answer, that is concise, but with a bit of flair. From steve+comp.lang.python at pearwood.info Thu Sep 5 23:40:46 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Sep 2013 03:40:46 GMT Subject: PEP8 79 char max References: <51F6C5F5.5020201@Gmail.com> <51f6e1d8$0$30000$c3e8da3$5496439d@news.astraweb.com> <51F6ED13.5010508@Gmail.com> <640206d7-a42f-4ae8-b9d6-cd5b3d158a6c@googlegroups.com> Message-ID: <52294ebd$0$29988$c3e8da3$5496439d@news.astraweb.com> On Thu, 05 Sep 2013 15:21:28 -0700, Metallicow wrote: > Well as for my opinion, it is more closer to the truth than others > because... Experience: > 1. I know Python and have read the PEP8. 2. I have knowledge of/worked > with the Printing Trades. 3. Grandfather owned/operated own Printshop > for 40+yrs. Which I also worked in at one point. Thanks for the comments, and welcome, but I really don't have a clue what the relevance of most of them are. > If you are still using equipment that requires 79, then chances are you > have/will already gone out of business or are keeping/using said > equipment for nostalgic purposes. The point is not that there is *equipment* that requires 79 characters per line, but that *reading text* is better with a maximum line length closer to 79 characters than (say) 140 characters. I've just randomly picked up a magazine (less than 50 characters per line) and two books (60 and 82 characters per line respectively). The exact max line length picked is not, in and of itself, critical. PEP 8 could have picked 60 characters, or 72, or 77, or 82. 79 characters (plus newline) happens to be a better choice than (say) 77 or 82 for historical reasons: some *old* computer equipment was limited to 79 characters (plus newline), and consequently some *new* computer software expects the same convention to be held. In a sense, it's a bit like the old urban legend about the width of the Space Shuttle booster rockets being determined by the width of ancient Roman chariots. http://www.snopes.com/history/american/gauge.asp While the precise details are wrong, the general claim is more or less true for boring and unremarkable reasons. > As far as math goes. 10 is a nice round number. So multiples of 10 are > prefer. 80 being my personal choice for editing. That gives you 80 visible characters plus newline = 81 characters in total. Quick, what's 81/7? > Zen says: Simple is better than complex. Use a round number. Integer > math is easier than float math for the majority of the population. Time > yourself, not the interpreter with these three questions: In the face of > ambiguity, refuse the temptation to guess. If it helps get out the old > school pen and paper. Question1: 80/8 > Question2: 79/8 I don't see the point of this. Why divide by 8? What is this supposed to demonstrate? Also, you're tossing around koans from a Zen that are irrelevant. 79 or 80, both are equally simple. Where is the ambiguity? The reader might be forgiven for thinking you're trying to dazzle them and pull the wool over their eyes by tossing out references to the Zen that sound good but have no relevance to the question being discussed. > Question3: How many chars does you calculator(real or virtual) support? Seven. Are you suggesting that we should limit our code to a maximum of seven characters per line? If not, I don't see the point of your question. > Zen says: Special cases aren't special enough to break the rules. PEP8 > isn't a rule. Rules are defined by the equipment/device developers. PEP 8 certainly is a collection of rules. They are mandatory for new code added to the standard library, and optional but recommended for third party libraries. > Ask yourself... How often do you actually use these 79char devices? My brain is better at reading lines with maximum line length of 79 characters than 140 characters. How often do I use my brain? At least once a day. [...] > Zen says: > Although practicality beats purity. > Errors should never pass silently. > Unless explicitly silenced. And yet, a bird in the hand saves nine, and the early bird bells the cat. > PEP8 would have been better to define various numbers for realworld > types of equipment/devices based on average general type of > equipment/device specs. No it would not. That would be silly. > Closing Zen: > If the implementation is hard to explain, it's a bad idea. If the > implementation is easy to explain, it may be a good idea. The implementation is easy to explain: stop typing before you reach 79 characters, and start a new line of code. > Yep, that's my nuts and bolts on the issue. Walk into you local > Printshop and ask them about this stuff. Then on your way out the door, > ask for a business card and see how many chars are on that also. Beware: > You might actually learn something about advertising while you are there > also. :) I don't need to ask them for a business card, since I have a nice collection of them. Most of them have < 40 characters per line. A few have < 60 characters on the longest line. None of them come even close to 79 characters per line. What's your point? That we should limit ourselves to code that fits on a business card? -- Steven From metaliobovinus at gmail.com Fri Sep 6 00:19:30 2013 From: metaliobovinus at gmail.com (Metallicow) Date: Thu, 5 Sep 2013 21:19:30 -0700 (PDT) Subject: PEP8 79 char max In-Reply-To: <52294ebd$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <51F6C5F5.5020201@Gmail.com> <51f6e1d8$0$30000$c3e8da3$5496439d@news.astraweb.com> <51F6ED13.5010508@Gmail.com> <640206d7-a42f-4ae8-b9d6-cd5b3d158a6c@googlegroups.com> <52294ebd$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7045d76b-fdaf-4f95-9e6d-852a6af5ab16@googlegroups.com> On Thursday, September 5, 2013 10:40:46 PM UTC-5, Steven D'Aprano wrote: > Thanks for the comments, and welcome, but I really don't have a clue what > the relevance of most of them are. Real-world Experience. > > If you are still using equipment that requires 79, then chances are you > > have/will already gone out of business or are keeping/using said > > equipment for nostalgic purposes. > > The point is not that there is *equipment* that requires 79 characters > per line, but that *reading text* is better with a maximum line length > closer to 79 characters than (say) 140 characters. I've just randomly > picked up a magazine (less than 50 characters per line) and two books (60 > and 82 characters per line respectively). The argument I am suggesting is 79 vs 80. > The exact max line length picked is not, in and of itself, critical. PEP > > 8 could have picked 60 characters, or 72, or 77, or 82. 79 characters > (plus newline) happens to be a better choice than (say) 77 or 82 for > historical reasons: some *old* computer equipment was limited to 79 > characters (plus newline), and consequently some *new* computer software > expects the same convention to be held. I propose 80 for Zen: Simplicity. > In a sense, it's a bit like the old urban legend about the width of the > Space Shuttle booster rockets being determined by the width of ancient > Roman chariots. Haha. *Gets a Laugh* > http://www.snopes.com/history/american/gauge.asp > > While the precise details are wrong, the general claim is more or less > true for boring and unremarkable reasons. Ok. > > As far as math goes. 10 is a nice round number. So multiples of 10 are > > prefer. 80 being my personal choice for editing. > That gives you 80 visible characters plus newline = 81 characters in > total. Quick, what's 81/7? We are focusing on end-users, which might be simple minded. Simple is better than complex. > > Zen says: Simple is better than complex. Use a round number. Integer > > math is easier than float math for the majority of the population. Time > > yourself, not the interpreter with these three questions: In the face of > > ambiguity, refuse the temptation to guess. If it helps get out the old > > school pen and paper. Question1: 80/8 > > Question2: 79/8 > I don't see the point of this. Why divide by 8? What is this supposed to > demonstrate? Divide by any simple number is 0 simple enouch...? > Also, you're tossing around koans from a Zen that are irrelevant. 79 or > 80, both are equally simple. Where is the ambiguity? The reader might be > forgiven for thinking you're trying to dazzle them and pull the wool over > their eyes by tossing out references to the Zen that sound good but have > no relevance to the question being discussed. No., 79 and 80 are not equally simple. 79 is odd, and 80 is even. > > > Question3: How many chars does you calculator(real or virtual) support? > Seven. Are you suggesting that we should limit our code to a maximum of Ok. Mine displays ten. This question was to get most people off their duff and grab a piece of old-school tech. Might be solar in nature. > seven characters per line? If not, I don't see the point of your question. See above answer. > > Zen says: Special cases aren't special enough to break the rules. PEP8 > > isn't a rule. Rules are defined by the equipment/device developers. > PEP 8 certainly is a collection of rules. They are mandatory for new code > added to the standard library, and optional but recommended for third > party libraries. What are the official rules, then... None...? > > Ask yourself... How often do you actually use these 79char devices? > My brain is better at reading lines with maximum line length of 79 > characters than 140 characters. How often do I use my brain? At least > once a day. > [...] Ok. I prefer 80 remember. Simple. base 10. > > Zen says: > > Although practicality beats purity. > > Errors should never pass silently. > > Unless explicitly silenced. > And yet, a bird in the hand saves nine, and the early bird bells the cat. if python.notDefined(): cats != birds != cats > > PEP8 would have been better to define various numbers for realworld > > types of equipment/devices based on average general type of > > equipment/device specs. > No it would not. That would be silly. Well... Why Not? What do you use? > > Closing Zen: > > If the implementation is hard to explain, it's a bad idea. If the > > implementation is easy to explain, it may be a good idea. > The implementation is easy to explain: stop typing before you reach 79 > characters, and start a new line of code. I believe Guido once worked for google, why doesn't the software reflect your preferences. Ask google, or him, not me. > > Yep, that's my nuts and bolts on the issue. Walk into you local > > Printshop and ask them about this stuff. Then on your way out the door, > > ask for a business card and see how many chars are on that also. Beware: > > You might actually learn something about advertising while you are there > > also. :) > I don't need to ask them for a business card, since I have a nice > collection of them. Most of them have < 40 characters per line. A few > have < 60 characters on the longest line. None of them come even close to > 79 characters per line. > What's your point? That we should limit ourselves to code that fits on a > business card? My grandfather once told me, "If you can put you resume on a business card, you will succeed in life." My business card reads "Jack-of-all-trades\nMaster of one: That's my Trade Secret." > -- > > Steven Love these... > > > > > > > provided by google. > production time of post - >'s Simplicity. Thanks Again for comments/opinions. It teaches everyone. From storchaka at gmail.com Sat Sep 7 14:00:47 2013 From: storchaka at gmail.com (Serhiy Storchaka) Date: Sat, 07 Sep 2013 21:00:47 +0300 Subject: PEP8 79 char max In-Reply-To: <52294ebd$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <51F6C5F5.5020201@Gmail.com> <51f6e1d8$0$30000$c3e8da3$5496439d@news.astraweb.com> <51F6ED13.5010508@Gmail.com> <640206d7-a42f-4ae8-b9d6-cd5b3d158a6c@googlegroups.com> <52294ebd$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: 06.09.13 06:40, Steven D'Aprano ???????(??): > PEP 8 certainly is a collection of rules. They are mandatory for new code > added to the standard library, and optional but recommended for third > party libraries. No. They are optional but recommended for new code added to the standard library, and indifferent for third party libraries. But generally there are no much reasons to not obey PEP 8. From rustompmody at gmail.com Tue Sep 3 12:58:18 2013 From: rustompmody at gmail.com (rusi) Date: Tue, 3 Sep 2013 09:58:18 -0700 (PDT) Subject: Editing tabular data In-Reply-To: References: Message-ID: <8156866f-d259-49f9-affb-61b73f52a563@googlegroups.com> On Friday, August 2, 2013 12:05:53 PM UTC+5:30, Ben Finney wrote: > Skip Montanaro writes: > > > I really love Emacs, however... [?] > > > > This is clearly a case where choosing the proper tool is important. I > > agree that using a spreadsheet to edit a 3x5 CSV file is likely > > overkill (might just as well use Notepad or TextEdit), but tabular > > data are tabular data, no matter how they might be delimited, and if > > there are many of those little data critters, there are better tools > > than a text editor (or Python IDE) for maintaining them. > > It seems an obvious thing for powerful text editors like Emacs and Vim > to have a third-party mode for editing CSV data with a tabular > interface. > > > Indeed, such modes exist; one that I found immediately for Emacs is > . Has anyone got a good > Emacs mode for editing CSV data as a table and saving it back to CSV > data? Emacs users can have the cake and eat it too; ie use spreadsheet functionality without having to use a separate spreadsheet file and software. The basic idea is to use org-mode which has a table editor with spreadsheet functionality while continuing to live within a plain text editor. It allows to edit a table entirely written in plain text in a visually appealing and clean way, while keeping a (less readable) python data structure in sync with it. The example file is below the --------------- Caveats: The orig_table string is there only make the source for the table. The name orig_table is not necessary; a naked triple-string will also work. The triple string is there to pacify python in the face of non valid syntax. Ideal would have been comments but python does not have multiline comments The table between the #BEGIN RECEIVE ORGTBL marks and the #END RECEIVE ORGTBL marks is the target or the recipient for the transformed version of the plain text table. Experiment as follows: 1. Save the stuff below --------- as something.py 2. Start editing the file in emacs 3. Join the 3 lines into 1 line with single space separators. +ORGTBL: SEND marks orgtbl-to-generic :lfmt " \"%s\": [%s,%s,%s,%s,%s]," :llfmt " \"%s\": [%s,%s,%s,%s,%s]" [It has to be one line, but if I kept it one line, it will be randomly be garbled in the mail!] This line gives the table a name ("marks") so that you can use several tables in one file, and it specifies how the syntax should be changed when syncing the python version of the table data. 4. Start orgtbl minor mode with M-x orgtbl-mode Mode line should show python and orgtbl 5. Delete the contents (keep the 2 # lines intact) of the python table 6. Place cursor within the orig_table and 'send' it as follows 7. Send is done with any one of 'C-c C-c' or 'C-u C-c C-c' or 'C-u C-u C-c C-c' The first just sends the table as is The second recomputes the formulas top-down and then sends The third recomputes until fixpoint (you really should not be making such a table!!) 8. Play with the table editor by using TAB and S-TAB to walk through fields and change them, use C-u C-c C-c again to sync the python version of the table 9. In case the above does now work (if your orgmode is too old) the orig_table_2 should hopefully work even for older org versions It furthermore shows the ability to skip columns and to format column widths to convenience. ---------------------------------- orig_table = """ #+ORGTBL: SEND marks orgtbl-to-generic :lfmt " \"%s\": [%s,%s,%s,%s,%s]," :llfmt " \"%s\": [%s,%s,%s,%s,%s]" | abe | 1 | 2 | 3 | 4 | 10 | | beth | 9 | 1 | 5 | 9 | 24 | | catherine | 5 | 6 | 7 | 5 | 23 | #+TBLFM: $6=$2+$3+$4+$5 """ stud_db = { # Dont handedit # BEGIN RECEIVE ORGTBL marks "abe": [1,2,3,4,10], "beth": [9,1,5,9,24], "catherine": [5,6,7,5,23] # END RECEIVE ORGTBL marks } ## In case the above does not work (if org-version too old) orig_table_2 = """ #+ORGTBL: SEND marks2 orgtbl-to-csv :skip 2 | Name | T1 | T2 | T3 | T4 | Total | | <6> | | | | | | | abe | 1 | 2 | 3 | 4 | 10 | | beth | 9 | 1 | 5 | 9 | 24 | | catherine | 5 | 6 | 7 | 5 | 23 | #+TBLFM: $6=$2+$3+$4+$5 """ stud_db_2 = { # Dont handedit # BEGIN RECEIVE ORGTBL marks2 abe,1,2,3,4,10 beth,9,1,5,9,24 catherine,5,6,7,5,23 # END RECEIVE ORGTBL marks2 From rustompmody at gmail.com Sun Sep 22 22:21:15 2013 From: rustompmody at gmail.com (rusi) Date: Sun, 22 Sep 2013 19:21:15 -0700 (PDT) Subject: Functional Programming and python In-Reply-To: References: Message-ID: Combining your two questions -- Recently: What minimum should a person know before saying "I know Python" And earlier this On Sunday, August 4, 2013 10:00:35 PM UTC+5:30, Aseem Bansal wrote: > If there is an issue in place for improving the lambda forms then that's > good. I wanted a link about functional programming because it is mentioned as > if it were a household word. Python is not a functional programming language; however it supports most of FP better than traditional languages like C/Java. eg with iterators/generators + itertools + functools you can do most of what lazy lists give in haskell Some discussion here: http://stackoverflow.com/questions/1017621/why-isnt-python-very-good-for-functional-programming [Not everything said there is correct; eg python supports currying better than haskell which is surprising considering that Haskell's surname is Curry!] So if I may break your question into two: 1. Why should a programmer of a non-FP language know FP? 2. What in FP should a (any|all) programmer know? I touched upon these in two blog-posts: 1. http://blog.languager.org/2013/06/functional-programming-invades.html 2. http://blog.languager.org/2012/10/functional-programming-lost-booty.html Also most programmers without an FP background have a poor appreciation of the centrality of recursion in CS; see http://blog.languager.org/2012/05/recursion-pervasive-in-cs.html From vito.detullio at gmail.com Mon Sep 23 14:24:53 2013 From: vito.detullio at gmail.com (Vito De Tullio) Date: Mon, 23 Sep 2013 20:24:53 +0200 Subject: Functional Programming and python References: Message-ID: rusi wrote: > [Not everything said there is correct; eg python supports currying better > [than haskell which is surprising considering that Haskell's surname is > [Curry!] AFAIK python does not support currying at all (if not via some decorators or something like that). Instead every function in haskell implicitly support currying... so... how does "no support" is better than "full support"? -- By ZeD From jpiitula at ling.helsinki.fi Tue Sep 24 03:06:07 2013 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 24 Sep 2013 10:06:07 +0300 Subject: Functional Programming and python References: Message-ID: Vito De Tullio writes: > rusi wrote: > > > [Not everything said there is correct; eg python supports currying > > better [than haskell which is surprising considering that > > Haskell's surname is [Curry!] > > AFAIK python does not support currying at all (if not via some > decorators or something like that). I suppose rusi means functools.partial: >>> from functools import partial >>> trip = lambda x,y,z: (x,y,z) >>> partial(trip,'a','b')('c') ('a', 'b', 'c') It also supports keyword arguments. > Instead every function in haskell implicitly support currying... > so... how does "no support" is better than "full support"? Yes. I'm satisfied that Python does, but what can be seen as a shortcoming in Haskell? Just curious. From rustompmody at gmail.com Tue Sep 24 03:08:53 2013 From: rustompmody at gmail.com (rusi) Date: Tue, 24 Sep 2013 00:08:53 -0700 (PDT) Subject: Functional Programming and python In-Reply-To: References: Message-ID: <840ba5b2-761b-4f89-990b-75218e3cd7fb@googlegroups.com> On Monday, September 23, 2013 11:54:53 PM UTC+5:30, Vito De Tullio wrote: > rusi wrote: > > > [Not everything said there is correct; eg python supports currying better > > [than haskell which is surprising considering that Haskell's surname is > > [Curry!] > > > AFAIK python does not support currying at all (if not via some decorators or > something like that). > > > Instead every function in haskell implicitly support currying... so... how > does "no support" is better than "full support"? Without resorting to lambdas/new-functions: With functools.partial one can freeze any subset of a function(callable's) parameters. In Haskell one can only freeze the first parameter or at most with a right section the second From jpiitula at ling.helsinki.fi Tue Sep 24 03:42:51 2013 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 24 Sep 2013 10:42:51 +0300 Subject: Functional Programming and python References: <840ba5b2-761b-4f89-990b-75218e3cd7fb@googlegroups.com> Message-ID: rusi writes: > Without resorting to lambdas/new-functions: > With functools.partial one can freeze any subset of a > function(callable's) parameters. > > In Haskell one can only freeze the first parameter or at most with > a right section the second You have an f of type A -> B -> C -> D -> E in Haskell, you can freeze the first three parameters by calling it with three arguments. These are equivalent: f a b c d (f a b c) d (f a b) c d (f a) b c d So it's any initial sequence of arguments, not just the first. And I thought such types were preferred over A * B * C * D -> E in Haskell, so you tend to get this for free. Not sure of the syntax here - it's been long since I did anything at all with Haskell. A difference seems to be that in Python, a call can refer to named parameters. This gives functools.partial some power over Haskell. Another difference is that the value of functools.partial is always a function that needs to be called with the remaining arguments, even if there are none. Both the creation and the evaluation of the curried functions just happens in Haskell. (I also think that the word "currying" used to refer to what Haskell does and it's an extension to use it to mean any partial evaluation.) From rustompmody at gmail.com Tue Sep 24 08:14:53 2013 From: rustompmody at gmail.com (rusi) Date: Tue, 24 Sep 2013 05:14:53 -0700 (PDT) Subject: Functional Programming and python In-Reply-To: References: <840ba5b2-761b-4f89-990b-75218e3cd7fb@googlegroups.com> Message-ID: <9b9126bc-875a-4045-9613-d2d81b30cf1c@googlegroups.com> On Tuesday, September 24, 2013 1:12:51 PM UTC+5:30, Jussi Piitulainen wrote: > rusi writes: > > > Without resorting to lambdas/new-functions: > > With functools.partial one can freeze any subset of a > > function(callable's) parameters. > > > > > In Haskell one can only freeze the first parameter or at most with > > a right section the second > > You have an f of type A -> B -> C -> D -> E in Haskell, you can freeze > the first three parameters by calling it with three arguments. These > are equivalent: > > f a b c d > (f a b c) d > (f a b) c d > (f a) b c d > > So it's any initial sequence of arguments, not just the first. Agreed. I missed that. However as n increases there are n initial sequences (Haskell) whereas there are 2^n possible subsets (Python) (2^n - 1 if we remove the fully saturated case). So I would argue that Python syntax gives more flexibility in this direction than Haskell. Add the further feature of **args and its even more > > (I also think that the word "currying" used to refer to what Haskell > does and it's an extension to use it to mean any partial evaluation.) Hmm? Seems this is a contentious issue http://en.wikipedia.org/wiki/Currying#Contrast_with_partial_function_application which links to this LtU post that I find neat: --------------- If I have a function f:(x,y)->z, I can't apply it to only one of its arguments. I can curry it, turning it into a function g:x->(y->z) ... and I can apply g to only one of the original arguments. But turning f into g and applying g to some x are technically different things. I suspect the confusion arises because originally currying was a technique to model multiple-argument functions in a single-argument framework and was a meta-operation. In ML-like languages, the functions are typically already curried, so the only operation you see being done is partial application. --------------- from http://lambda-the-ultimate.org/node/2266 ------------- Anyways thanks for that Ive added it to my 'lost-booty' list http://blog.languager.org/2012/10/functional-programming-lost-booty.html#curry From jpiitula at ling.helsinki.fi Tue Sep 24 10:51:19 2013 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 24 Sep 2013 17:51:19 +0300 Subject: Functional Programming and python References: <840ba5b2-761b-4f89-990b-75218e3cd7fb@googlegroups.com> <9b9126bc-875a-4045-9613-d2d81b30cf1c@googlegroups.com> Message-ID: rusi writes: > On Tuesday, September 24, 2013 1:12:51 PM UTC+5:30, Jussi Piitulainen wrote: > > rusi writes: > > > > > Without resorting to lambdas/new-functions: > > > With functools.partial one can freeze any subset of a > > > function(callable's) parameters. > > > > > In Haskell one can only freeze the first parameter or at most > > > with a right section the second > > > > You have an f of type A -> B -> C -> D -> E in Haskell, you can > > freeze the first three parameters by calling it with three > > arguments. These are equivalent: > > > > f a b c d > > (f a b c) d > > (f a b) c d > > (f a) b c d > > > > So it's any initial sequence of arguments, not just the first. > > Agreed. I missed that. Ok. > However as n increases there are n initial sequences (Haskell) > whereas there are 2^n possible subsets (Python) (2^n - 1 if we > remove the fully saturated case). So I would argue that Python > syntax gives more flexibility in this direction than Haskell. Strictly speaking and in principle, yes. I'm not sure how important this is in practice: the positional parameter list should be short anyway, Haskell does have the special mechanism for the second, and there is always the fully general mechanism (lambda) in both languages (and in another language I use that has neither built-in currying nor keyword parameters :). I agree that the ability to identify arguments by name gives a useful amount of quite practical power, and I see that functools.partial uses it nicely. So, no real disagreement on this from me. Would the type system get in the way of providing some analogous function in Haskell? I don't know. > Add the further feature of **args and its even more > > > (I also think that the word "currying" used to refer to what > > Haskell does and it's an extension to use it to mean any partial > > evaluation.) > > Hmm[] Seems this is a contentious issue > http://en.wikipedia.org/wiki/Currying#Contrast_with_partial_function_application > > which links to this LtU post that I find neat: [snip] Thanks. I don't think I have anything useful to add, though. From rustompmody at gmail.com Tue Sep 24 11:07:55 2013 From: rustompmody at gmail.com (rusi) Date: Tue, 24 Sep 2013 08:07:55 -0700 (PDT) Subject: Functional Programming and python In-Reply-To: References: <840ba5b2-761b-4f89-990b-75218e3cd7fb@googlegroups.com> <9b9126bc-875a-4045-9613-d2d81b30cf1c@googlegroups.com> Message-ID: <32dd86b4-e99d-485b-a2b3-bc173f67289d@googlegroups.com> On Tuesday, September 24, 2013 8:21:19 PM UTC+5:30, Jussi Piitulainen wrote: > Would the type system get in the way of providing some analogous > function in Haskell? I don't know. Yes. The haskell curry curry f x y = f (x,y) is really only curry2 curry3 would be curry3 f x y z = f (x,y,z) and so on upwards Vanilla Haskell makes it real hard to put all these under one type umbrella By comparison python's partial is quite effortless. And this is an old conundrum in programming language design: In C printf is easy to write and NOT put into the language but into external libraries In Pascal, writeln cannot be outside the language because as a user defined function, its type would not fit the type system. And so printf can be made to crash quite easily; not so writeln! From rosuav at gmail.com Tue Sep 24 11:26:21 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 Sep 2013 01:26:21 +1000 Subject: Functional Programming and python In-Reply-To: <32dd86b4-e99d-485b-a2b3-bc173f67289d@googlegroups.com> References: <840ba5b2-761b-4f89-990b-75218e3cd7fb@googlegroups.com> <9b9126bc-875a-4045-9613-d2d81b30cf1c@googlegroups.com> <32dd86b4-e99d-485b-a2b3-bc173f67289d@googlegroups.com> Message-ID: On Wed, Sep 25, 2013 at 1:07 AM, rusi wrote: > And this is an old conundrum in programming language design: > > In C printf is easy to write and NOT put into the language but into external libraries > In Pascal, writeln cannot be outside the language because as a user defined function, its type would not fit the type system. > > And so printf can be made to crash quite easily; not so writeln! I assume you're talking about mismatching percent-markers and arguments, there. That's because of a limitation in C's variadic function support, ameliorated somewhat by gcc's warnings system, and completely solved by other languages in which (s)printf can still be an external function, but with reliable type checking. It's not whether it's part of the language or not that does that. ChrisA From rustompmody at gmail.com Tue Sep 24 13:25:07 2013 From: rustompmody at gmail.com (rusi) Date: Tue, 24 Sep 2013 10:25:07 -0700 (PDT) Subject: Functional Programming and python In-Reply-To: References: <840ba5b2-761b-4f89-990b-75218e3cd7fb@googlegroups.com> <9b9126bc-875a-4045-9613-d2d81b30cf1c@googlegroups.com> <32dd86b4-e99d-485b-a2b3-bc173f67289d@googlegroups.com> Message-ID: On Tuesday, September 24, 2013 8:56:21 PM UTC+5:30, Chris Angelico wrote: > On Wed, Sep 25, 2013 at 1:07 AM, rusi wrote: > > And this is an old conundrum in programming language design: > > > > In C printf is easy to write and NOT put into the language but into external libraries > > > In Pascal, writeln cannot be outside the language because as a user defined function, its type would not fit the type system. > > > > And so printf can be made to crash quite easily; not so writeln! > > I assume you're talking about mismatching percent-markers and > arguments, there. That's because of a limitation in C's variadic > function support, ameliorated somewhat by gcc's warnings system, and > completely solved by other languages in which (s)printf can still be > an external function, but with reliable type checking. It's not > whether it's part of the language or not that does that. Sure there can be and are specific workarounds. My point was a general one: Strong type system: Some desirable programs will get kicked out Weak type system: Some undesirable programs will slip in 'Exactly' correct type system: Impossible by halting problem From nobody at nowhere.org Mon Sep 30 13:04:32 2013 From: nobody at nowhere.org (Franck Ditter) Date: Mon, 30 Sep 2013 19:04:32 +0200 Subject: Functional Programming and python References: Message-ID: In article , rusi wrote: > Combining your two questions -- Recently: > What minimum should a person know before saying "I know Python" > > And earlier this > On Sunday, August 4, 2013 10:00:35 PM UTC+5:30, Aseem Bansal wrote: > > If there is an issue in place for improving the lambda forms then that's > > good. I wanted a link about functional programming because it is mentioned as > > if it were a household word. > > Python is not a functional programming language; however it supports most of FP better than traditional languages like C/Java. > eg with iterators/generators + itertools + functools you can do most of what lazy lists give in haskell > > Some discussion here: http://stackoverflow.com/questions/1017621/why-isnt-python-very-good-for-functional-programming > > [Not everything said there is correct; eg python supports currying better than haskell which is surprising considering that Haskell's surname is Curry!] > > So if I may break your question into two: > 1. Why should a programmer of a non-FP language know FP? > 2. What in FP should a (any|all) programmer know? > > I touched upon these in two blog-posts: > 1. http://blog.languager.org/2013/06/functional-programming-invades.html > 2. http://blog.languager.org/2012/10/functional-programming-lost-booty.html > > Also most programmers without an FP background have a poor appreciation of the centrality of recursion in CS; see > http://blog.languager.org/2012/05/recursion-pervasive-in-cs.html Good approach of FP in Python, but two points make me crazy : 1. Tail recursion is not optimized. We are in 2013, why ? This is known technology (since 1960). And don't answer with "good programmers don't use recursion", this is bullshit. 2. Lambda-expression body is limited to one expression. Why ? Why the hell those limitations ? In this aspect, Javascript has a cooler approach. franck From rosuav at gmail.com Mon Sep 30 13:17:45 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 1 Oct 2013 03:17:45 +1000 Subject: Functional Programming and python In-Reply-To: References: Message-ID: On Tue, Oct 1, 2013 at 3:04 AM, Franck Ditter wrote: > 1. Tail recursion is not optimized. We are in 2013, why ? This is known technology (since 1960). > And don't answer with "good programmers don't use recursion", this is bullshit. I've yet to see any value in having the compiler/interpreter optimize tail recursion that can't be achieved just as well, and usually more clearly, with simple iteration. Recursion's important; tail recursion's important; tail recursion optimization isn't. (But I do sometimes yearn for a goto.) > 2. Lambda-expression body is limited to one expression. Why ? > Why the hell those limitations ? In this aspect, Javascript has a cooler approach. Since you can just use def in the middle of another function, the difference between def and lambda isn't all that huge. Yes, def isn't an expression - but Python's lambda gives an incredibly compact notation for the common case. Compare these two snippets: # Python odd_numbers = filter(lambda x: x%2, numbers) //Pike odd_numbers = filter(numbers, lambda(int x) {return x%2;}) Aside from the type declaration and the argument order, these two snippets are doing exactly the same thing in exactly the same way. Python's version is way more compact. Pike's version lets you put multiple statements into the expression... but most of the time you don't need that. Both approaches have their value. ChrisA From neilc at norwich.edu Mon Sep 30 14:36:28 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 30 Sep 2013 18:36:28 GMT Subject: Functional Programming and python References: Message-ID: On 2013-09-30, Franck Ditter wrote: > In article , > rusi wrote: >> I touched upon these in two blog-posts: >> 1. http://blog.languager.org/2013/06/functional-programming-invades.html >> 2. http://blog.languager.org/2012/10/functional-programming-lost-booty.html >> >> Also most programmers without an FP background have a poor >> appreciation of the centrality of recursion in CS; see >> http://blog.languager.org/2012/05/recursion-pervasive-in-cs.html > > Good approach of FP in Python, but two points make me crazy : > 1. Tail recursion is not optimized. We are in 2013, why ? This > is known technology (since 1960). And don't answer with "good > programmers don't use recursion", this is bullshit. If you've got a set of recursive functions with recursive calls in tail-call position it's pretty easy to convert to a solution that doesn't blow the stack. Converting to a while loop is usually straightforward, or you try trampolining. If the calls aren't in tail-call position then you wouldn't get tail-call optimization from a language like scheme, either. Getting calls in tail position is often the sticking point, and tail-call optimization doesn't help with that. I think the Python rationale also discusses how it would make tracebacks harder to understand if stackframes could clobber each other. Personally I think that's more a theoretical than a practical problem. Languages with tail-call optimization aren't impossible to debug. > 2. Lambda-expression body is limited to one expression. Why ? > Why the hell those limitations ? In this aspect, Javascript has > a cooler approach. It's in the Design and History FAQ. http://docs.python.org/3/faq/design.html Why can?t lambda forms contain statements? Python lambda forms cannot contain statements because Python?s syntactic framework can?t handle statements nested inside expressions. However, in Python, this is not a serious problem. Unlike lambda forms in other languages, where they add functionality, Python lambdas are only a shorthand notation if you?re too lazy to define a function. Functions are already first class objects in Python, and can be declared in a local scope. Therefore the only advantage of using a lambda form instead of a locally-defined function is that you don?t need to invent a name for the function ? but that?s just a local variable to which the function object (which is exactly the same type of object that a lambda form yields) is assigned! What I usually end up with is a dictionary of callbacks, with the simple functions defined in-line and the more complex functions defined just before that and referenced instead. -- Neil Cerutti From steve+comp.lang.python at pearwood.info Mon Sep 30 20:14:15 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Oct 2013 00:14:15 GMT Subject: Functional Programming and python References: Message-ID: <524a13d7$0$29974$c3e8da3$5496439d@news.astraweb.com> On Mon, 30 Sep 2013 18:36:28 +0000, Neil Cerutti quoted: > Why can?t lambda forms contain statements? Gah! Please fix your news client! (I see you're using slrn.) The \x92 bytes found in your message are apostrophes (technically: right single quotation marks), encoded using the legacy Windows-1252 codec, but your news client is falsely advertising it as US-ASCII: Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 8bit It's almost 2014, it is unspeakably poor form that an application is still making this mistake. Is there an updated version of slrn that fixes this? Can you manually force it to use UTF-8? Can you report this as a bug? In case you aren't too clear on the concepts, here are two Must Read links: http://www.joelonsoftware.com/articles/Unicode.html http://nedbatchelder.com/text/unipain.html -- Steven From antoon.pardon at rece.vub.ac.be Mon Sep 30 14:29:01 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 30 Sep 2013 20:29:01 +0200 Subject: Functional Programming and python In-Reply-To: References: Message-ID: <5249C2ED.3040008@rece.vub.ac.be> Op 30-09-13 19:04, Franck Ditter schreef: > > Good approach of FP in Python, but two points make me crazy : > 1. Tail recursion is not optimized. We are in 2013, why ? This is known technology (since 1960). > And don't answer with "good programmers don't use recursion", this is bullshit. Guido doesn't like it. > 2. Lambda-expression body is limited to one expression. Why ? > Why the hell those limitations ? In this aspect, Javascript has a cooler approach. Guido prefers it that way. -- Antoon Pardon From piet at vanoostrum.org Mon Sep 30 14:55:47 2013 From: piet at vanoostrum.org (Piet van Oostrum) Date: Mon, 30 Sep 2013 14:55:47 -0400 Subject: Functional Programming and python References: Message-ID: Franck Ditter writes: > Good approach of FP in Python, but two points make me crazy : > 1. Tail recursion is not optimized. We are in 2013, why ? This is known technology (since 1960). > And don't answer with "good programmers don't use recursion", this is bullshit. Tail recursion optimization throws away valuable stack trace information in case of an error. > 2. Lambda-expression body is limited to one expression. Why ? Allowing general statements in a lambda body makes indentation more difficult, I think. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From antoon.pardon at rece.vub.ac.be Mon Sep 30 16:37:46 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 30 Sep 2013 22:37:46 +0200 Subject: Functional Programming and python In-Reply-To: References: Message-ID: <5249E11A.4030807@rece.vub.ac.be> Op 30-09-13 20:55, Piet van Oostrum schreef: > Franck Ditter writes: > >> Good approach of FP in Python, but two points make me crazy : >> 1. Tail recursion is not optimized. We are in 2013, why ? This is known technology (since 1960). >> And don't answer with "good programmers don't use recursion", this is bullshit. > > Tail recursion optimization throws away valuable stack trace information in case of an error. This is hardly relevant. Because what are we told to use instead of tail calls? We are told to use loops. But when you use a loop the stack trace doesn't contain the values of previous runs through the loop. So how valuable is that stack frame information when the proposed alternative doesn't produces it either. -- Antoon Pardon From python.list at tim.thechases.com Mon Sep 30 17:02:18 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 30 Sep 2013 16:02:18 -0500 Subject: Functional Programming and python In-Reply-To: References: Message-ID: <20130930160218.326d518b@bigbox.christie.dr> On 2013-09-30 19:04, Franck Ditter wrote: > two points make me crazy : > 1. Tail recursion is not optimized. We are in 2013, why ? This is > known technology (since 1960). And don't answer with "good > programmers don't use recursion", I seem to recall hearing that the primary reason it hadn't been implemented is because of Python's super-dynamism (to make up a word). That a function could be a tail recursion in one call, but the calling the same name could then become rebound. I'm making up the example, but I think it was something like this: def kablooie(*args): if not args: def kablooie(*args): woah() do_something(args) kablooie(args[1:]) where tail recursion optimization would do weird things. -tkc From tjreedy at udel.edu Mon Sep 30 21:03:41 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 Sep 2013 21:03:41 -0400 Subject: Functional Programming and python In-Reply-To: <20130930160218.326d518b@bigbox.christie.dr> References: <20130930160218.326d518b@bigbox.christie.dr> Message-ID: On 9/30/2013 5:02 PM, Tim Chase wrote: > On 2013-09-30 19:04, Franck Ditter wrote: >> two points make me crazy : >> 1. Tail recursion is not optimized. We are in 2013, why ? This is >> known technology (since 1960). And don't answer with "good >> programmers don't use recursion", > > I seem to recall hearing that the primary reason it hadn't been > implemented is because of Python's super-dynamism (to make up a > word). Right. A tail call is a call immediately followed by a return (in the byte code or equivalent). A recursive tail call is a tail call to the function containing the tail call. In Python, the function to be called in a call is not determined until the call is made. This is because the function expression is evaluated to a function object at runtime, not when the function is compiled. It would be trivial to detect and somewhat optimize all tail calls in CPython. But the result would be to delete traceback info with *all* tail calls, not just for recursive tail calls. Some functions have multiple recursive calls, as with divide and conquer algorithms and graph traversal. The last recursive call might or might not be a tail call. When it is, having calls omitted from the traceback might be undesireable. It might be disconcerting, for instance, if the number of calls in the traceback for a balanced binary tree algorithm did *not* match the level where the error took place. > That a function could be a tail recursion in one call, but > the calling the same name could then become rebound. I'm making up > the example, but I think it was something like this: > > def kablooie(*args): > if not args: > def kablooie(*args): > woah() > do_something(args) > kablooie(args[1:]) > > where tail recursion optimization would do weird things. -- Terry Jan Reedy From rustompmody at gmail.com Mon Sep 30 21:36:01 2013 From: rustompmody at gmail.com (rusi) Date: Mon, 30 Sep 2013 18:36:01 -0700 (PDT) Subject: Functional Programming and python In-Reply-To: References: <20130930160218.326d518b@bigbox.christie.dr> Message-ID: <08fef68f-dc0d-43a4-9e28-635272fb59cf@googlegroups.com> On Tuesday, October 1, 2013 6:11:18 AM UTC+5:30, Steven D'Aprano wrote: > On Mon, 30 Sep 2013 19:04:32 +0200, Franck Ditter wrote: > > 2. Lambda-expression body is limited to one expression. Why ? > > Nobody has come up with syntax that is unambiguous, would allow multiple > statements in an expression, doesn't break backwards compatibility, and > isn't ugly. > > Since lambda is just a convenience, not a necessity -- it almost got > dropped from Python 3 -- it is not worth compromising on those design > requirements just for multiple-statement lambdas. It simply isn't > important enough. Agreed. ?-expressions are fundamental to functional programming theory; they are not strictly necessary to practical functional programming. [Miranda one of the predecessors to haskell and a seminal FP language had no ?-expressions ] I find serious limitations in python from the pov of effectively doing FP; ?-expression limitations not the most crucial. eg - scope leakage in comprehensions - no comprehensions for tuples - need to use assignments to simulate let - mutable default parameters leak scope On Monday, September 30, 2013 10:47:45 PM UTC+5:30, Chris Angelico wrote: > On Tue, Oct 1, 2013 at 3:04 AM, Franck Ditter wrote: > > > 1. Tail recursion is not optimized. We are in 2013, why ? This is known technology (since 1960). > > And don't answer with "good programmers don't use recursion", this is bullshit. > > I've yet to see any value in having the compiler/interpreter optimize > tail recursion that can't be achieved just as well, and usually more > clearly, with simple iteration. Recursion's important; tail > recursion's important; tail recursion optimization isn't. Yeah -- since register allocation is isomorphic to graph-coloring[1] and graph-coloring is computationally hard[2], lets all go back to machine language! [1] http://en.wikipedia.org/wiki/Register_allocation#Isomorphism_to_graph_colorability [2] http://en.wikipedia.org/wiki/Graph_coloring#Algorithms > (But I do sometimes yearn for a goto.) Ha! In Scheme, a tail call IS a goto with parameter re-assignment The real advantage to mandatory tail-call optimized language like scheme is pedagogical. Students brought up on a scheme-like philosophy are liable to see recursion and iteration as synonymous [Certain common forms of recursion are more easily expressed as loops] and be more easy switching between them. Recursion is just too central to the business of programming to afford having it pushed to one side in beginner's heads. http://blog.languager.org/2012/05/recursion-pervasive-in-cs.html The irony is that most non-FP programmers imagine that FP consists of using recursion for any and everything. See the progression and specially the last entry here http://www.willamette.edu/~fruehr/haskell/evolution.html - no loops - no recursion - if possible no variables (the 'pointless' version) From steve+comp.lang.python at pearwood.info Mon Sep 30 20:41:18 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Oct 2013 00:41:18 GMT Subject: Functional Programming and python References: Message-ID: <524a1a2e$0$29974$c3e8da3$5496439d@news.astraweb.com> On Mon, 30 Sep 2013 19:04:32 +0200, Franck Ditter wrote: > Good approach of FP in Python, but two points make me crazy : 1. Tail > recursion is not optimized. We are in 2013, why ? This is known > technology (since 1960). And don't answer with "good programmers don't > use recursion", this is bullshit. Tail recursion optimization isn't really that useful. There is a HUGE universe of recursive problems which are not tail-recursive, and so cannot be optimized at all, or at least not automatically. Instead of encouraging people to rewrite such code using tail-recursion, which usually ends up obfuscating the code and introducing subtle bugs, it is better to encourage them to rewrite it to be iterative instead of recursive. Or just use recursion -- in many cases (although not all), if you have to recurse so many times that you pass the limit, your code is probably doing something wrong. So tail-recursion optimization only helps in a tiny subset of recursive problems. Usually it doesn't help at all. And one cost is that you lose debugging information. Don't think of a single recursive function, where the traceback is extremely boring: py> f() Traceback (most recent call last): File "", line 1, in File "", line 2, in f File "", line 2, in f [...] File "", line 2, in f File "", line 2, in f File "", line 2, in f RuntimeError: maximum recursion depth exceeded Think of mutually recursive functions, where f calls g which calls h which sometimes calls f and sometimes calls g... Personally, I'm not 100% convinced by these arguments. I think having a runtime option to enable or disable tail recursive optimizations would make Python a better language. Not by a lot, but by a tiny bit. But the people who would actually do the work don't care enough to do it, and the people who say they care don't bother doing the work. > 2. Lambda-expression body is limited > to one expression. Why ? Nobody has come up with syntax that is unambiguous, would allow multiple statements in an expression, doesn't break backwards compatibility, and isn't ugly. Since lambda is just a convenience, not a necessity -- it almost got dropped from Python 3 -- it is not worth compromising on those design requirements just for multiple-statement lambdas. It simply isn't important enough. -- Steven From wuwei23 at gmail.com Mon Sep 30 21:03:53 2013 From: wuwei23 at gmail.com (alex23) Date: Tue, 01 Oct 2013 11:03:53 +1000 Subject: Functional Programming and python In-Reply-To: References: Message-ID: On 1/10/2013 3:04 AM, Franck Ditter wrote: > 1. Tail recursion is not optimized. We are in 2013, why ? This is known technology (since 1960). > And don't answer with "good programmers don't use recursion", this is bullshit. Here's an article Guido wrote explaining his reasoning: http://neopythonic.blogspot.com.au/2009/04/tail-recursion-elimination.html From veritatem.ignotam at gmail.com Wed Sep 4 14:45:51 2013 From: veritatem.ignotam at gmail.com (Veritatem Ignotam) Date: Wed, 04 Sep 2013 14:45:51 -0400 Subject: Reading from stdin first, then use curses In-Reply-To: <20130831083103.GA570@Discworld.fritz.box> References: <20130811120511.GA8223@Discworld.fritz.box> <20130831083103.GA570@Discworld.fritz.box> Message-ID: <52277FDF.9050209@gmail.com> I'd like to bump this. I asked a similar question a few weeks ago and had no reply. Here's my question: I'm fairly new to python and even newer to curses. Does any one have a good solution for how to embed the output of a subprocess (ex. subprocess.Popen("htop", stdout=subprocess.PIPE)) into an ncurses window? So for example, the terminal window is broken up into quadrants and the top right has htop running inside. I'd imagine this would involve some kind of terminal emulation as the dimensions of the window would need to be queried by htop. If anyone could please point me in the right direction, I'd be very grateful Thanks, Ignotus On 08/31/2013 04:31 AM, Timo Schmiade wrote: > Hi again, > > sorry for replying to my own mail, but is there really no solution? Can > curses really not be used in this situation? > > Thanks again, > > Timo > > On Sun, Aug 11, 2013 at 02:05:11PM +0200, Timo Schmiade wrote: >> Hi all, >> >> I wrote a replacement for urlview to properly extract URLs from emails. >> You can find the first draft here: >> >> https://github.com/the-isz/pyurlview >> >> When I call it with an email file passed to the '-f' argument, it does >> pretty much what I want already. However, I intend to use it in mutt, >> which pipes the message to the program like so: >> >> macro pager \cu 'pyurlview.py' 'Follow links with pyurlview' >> >> The problem is rather obvious but - unfortunately - not so easy to solve: >> >> * The program reads the mail from stdin >> * The terminal in which it runs is a pseudo-terminal (pipe) >> * curses is not able to accept user input from the pseudo-terminal >> >> The question is: >> >> How do I read from stdin first and afterwards allow curses to read user >> input? >> >> Thanks in advance and kind regards, >> >> Timo From antoon.pardon at rece.vub.ac.be Wed Sep 4 15:57:12 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 04 Sep 2013 21:57:12 +0200 Subject: Reading from stdin first, then use curses In-Reply-To: <52277FDF.9050209@gmail.com> References: <20130811120511.GA8223@Discworld.fritz.box> <20130831083103.GA570@Discworld.fritz.box> <52277FDF.9050209@gmail.com> Message-ID: <52279098.5040902@rece.vub.ac.be> Op 04-09-13 20:45, Veritatem Ignotam schreef: > I'd like to bump this. I asked a similar question a few weeks ago and > had no reply. Here's my question: > > I'm fairly new to python and even newer to curses. Does any one have a > good solution for how to embed the output of a subprocess (ex. > subprocess.Popen("htop", stdout=subprocess.PIPE)) into an ncurses > window? So for example, the terminal window is broken up into quadrants > and the top right has htop running inside. I'd imagine this would > involve some kind of terminal emulation as the dimensions of the window > would need to be queried by htop. > > If anyone could please point me in the right direction, I'd be very grateful Search for pty in the python documentation. -- Antoon Pardon. From antoon.pardon at rece.vub.ac.be Sun Sep 1 16:36:46 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Sun, 01 Sep 2013 22:36:46 +0200 Subject: Reading from stdin first, then use curses In-Reply-To: <20130811120511.GA8223@Discworld.fritz.box> References: <20130811120511.GA8223@Discworld.fritz.box> Message-ID: <5223A55E.2010205@rece.vub.ac.be> Op 11-08-13 14:05, Timo Schmiade schreef: > Hi all, > > I wrote a replacement for urlview to properly extract URLs from emails. > You can find the first draft here: > > https://github.com/the-isz/pyurlview > > When I call it with an email file passed to the '-f' argument, it does > pretty much what I want already. However, I intend to use it in mutt, > which pipes the message to the program like so: > > macro pager \cu 'pyurlview.py' 'Follow links with pyurlview' > > The problem is rather obvious but - unfortunately - not so easy to solve: > > * The program reads the mail from stdin > * The terminal in which it runs is a pseudo-terminal (pipe) > * curses is not able to accept user input from the pseudo-terminal > > The question is: > > How do I read from stdin first and afterwards allow curses to read user > input? > Well you could close fd 0. Then open /dev/tty en dup the fd to 0. Then start curses. -- Antoon Pardon From steve+comp.lang.python at pearwood.info Sun Sep 1 04:10:30 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Sep 2013 08:10:30 GMT Subject: Encapsulation unpythonic? References: <8255dfbd-a2a1-4ab7-b900-ee19faa459f2@googlegroups.com> <8c7c4854-70e1-46e7-a3ff-a3206c4c5c27@googlegroups.com> <5221567b$0$6599$c3e8da3$5496439d@news.astraweb.com> <5221d7ab$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5222f675$0$6599$c3e8da3$5496439d@news.astraweb.com> On Sat, 31 Aug 2013 05:57:47 -0700, Fabrice Pombet wrote: > Steve, I think that your definition of encapsulation is too wide to give > a reasonable answer to the question at hand. My definition of encapsulation is based on the plain language definition. It is also common in computer programming circles to talk about encapsulation in this way. OOP designers may (or may not) have been the first to declare "encapsulation" was a design principle, but programmers have been using the *principle* of encapsulation since before Grace Hopper was an admiral. See, for example, coders talking about encapsulation in C and Powershell: http://ejrh.wordpress.com/2011/04/29/encapsulation-in-c/ https://www.simple-talk.com/dotnet/.net-tools/further-down-the-rabbit- hole-powershell-modules-and-encapsulation/ OOP languages give us *more* and *better* ways to encapsulate code and data, but they did not invent the principle. > If I understand you > correctly, you are taking encapsulation as a language characteristic, > rather than a principle. No, it is both. The coder may or may not decide to encapsulate code in subroutines/functions/classes, and the language may or may not allow it. Languages differ in their ability to allow the programmer to encapsulate. Some languages, like early BASIC, give you no ability to encapsulate code or data at all. All variables are global, and there are no functions, just a big blob of code in a single file. There aren't even data structures as such, except strings, so you cannot even group related pieces of data into a struct or record. Some languages, like Python, give you many ways to encapsulate code and data: you can group related code in a function, related functions in a class, related classes in a module, related modules in a package. That's pretty much exactly the same sort of things that you can do in Java. C++ has an additional "namespace" data structure that Python doesn't have, but that's just a mechanism for encapsulation. Encapsulation and information hiding are distinct things -- you can have one without the other. C, for example, creates a new scope inside for- loops, so that the for-loop variable is hidden from the rest of the function. Apart from a pair of braces, there is no encapsulation, but there is information hiding. Or you could design a language that encapsulated code into functions and classes, but put all variables in a single, global, shared namespace (little, or no, information hiding). It is a myth, and a very obnoxious one, that encapsulation and information hiding were invented by OOP. What is a function but a way to hide the implementation of a chunk of code from the caller? What are local variables but a way to hide variables used by one function from another? Coders were using information hiding, separation of concerns, and encapsulation in the 1950s, long before OOP. They just didn't call them by those names. They just called them "writing good code". Actually, functions are *not necessarily* a way to hide implementation. There are languages where you can jump into the middle of a function. So you can encapsulate a chunk of code into a function, without hiding the implementation details. Just as you can encapsulate code and data into a class, without hiding the implementation details, if you declare everything public. > Plus, you seem to forget that encapsulation is > an OOP principle, and, forgive me if I am wrong, does not apply normally > to functions or languages like C. I haven't forgotten it, because it isn't true. One of the most obnoxious and annoying traits of OOP zealots, especially academics, is that they act as if programming did not exist before Java and C++, or if you're really lucky, Smalltalk. (Somehow they nearly always forget about Simula.) Perhaps because OOP was so late to be invented (structured programming goes back to Fortran in the 1950s, functional programming to Lisp only a few years after that), and because it was so heavily hyped as "the solution" to every programming difficulty, too many people ignore anything outside of the OOP. They wrongly believe that since Python isn't a "pure" OOP language (according to some bizarre understanding of "pure" that often considers C++ and Java pure), Python cannot possibly have "OOP principles" like encapsulation, information hiding, separation of concerns. That point of view is sheerest nonsense. > Please read Steve Holden's (in chaz') > definition, and tell us whether you think that Python enforces strongly > this principle, I think that would be a good basis for an agreement. Are you referring to this quote? "encapsulation is the idea that the only way to access or change the data inside an object is by calling its methods." I disagree with that definition. That's a poor definition, one that has no relation to the plain English meaning of the word "encapsulation", nor to how the word is commonly used in the great bulk of programming circles. By referring to "objects" and "methods" it wrongly assumes that encapsulation can only apply to OOP. I quote from The Free On-line Dictionary of Computing: encapsulation 1. The technique used by layered protocols in which a layer adds header information to the protocol data unit (PDU) from the layer above. As an example, in Internet terminology, a packet would contain a header from the physical layer, followed by a header from the network layer (IP), followed by a header from the transport layer (TCP), followed by the application protocol data. 2. The ability to provide users with a well-defined interface to a set of functions in a way which hides their internal workings. In object-oriented programming, the technique of keeping together data structures and the methods (procedures) which act on them. Definition 1 is irrelevant to this discussion, but definition 2 makes it absolutely clear that it is not just about OOP. > My > answer is no, it doesn't, but it allows you to abide by it if you want > to. Unlike Java or C++ who would tend to do exactly the contrary > (enforces it strictly, and (possibly?) allow you to discard it at times > with a few jiffies (or not? I don't know)) Java and C++ allow you to declare members as public, so it is *not true* that calling methods is the only way to change members. If you accept Steve Holden's (wrong) definition above, Java and C++ don't have encapsulation either. -- Steven From rosuav at gmail.com Sun Sep 1 04:21:41 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 1 Sep 2013 18:21:41 +1000 Subject: Encapsulation unpythonic? In-Reply-To: <5222f675$0$6599$c3e8da3$5496439d@news.astraweb.com> References: <8255dfbd-a2a1-4ab7-b900-ee19faa459f2@googlegroups.com> <8c7c4854-70e1-46e7-a3ff-a3206c4c5c27@googlegroups.com> <5221567b$0$6599$c3e8da3$5496439d@news.astraweb.com> <5221d7ab$0$6599$c3e8da3$5496439d@news.astraweb.com> <5222f675$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Sep 1, 2013 at 6:10 PM, Steven D'Aprano wrote: > Java and C++ allow you to declare members as public, so it is *not true* > that calling methods is the only way to change members. If you accept > Steve Holden's (wrong) definition above, Java and C++ don't have > encapsulation either. That said, though, when you consider the language ecosystem rather than just the language, there is a strong tendency for Java and C++ code to wrap everything up with functions (no public data members), whereas Python code is far more likely to have external code directly access data inside an object. You usually will find Java code calling methods to change members, whereas that's done in Python only when there's a need for it. ChrisA From fp2161 at gmail.com Sun Sep 1 06:09:59 2013 From: fp2161 at gmail.com (Fabrice Pombet) Date: Sun, 1 Sep 2013 03:09:59 -0700 (PDT) Subject: Encapsulation unpythonic? In-Reply-To: References: <8255dfbd-a2a1-4ab7-b900-ee19faa459f2@googlegroups.com> <8c7c4854-70e1-46e7-a3ff-a3206c4c5c27@googlegroups.com> <5221567b$0$6599$c3e8da3$5496439d@news.astraweb.com> <5221d7ab$0$6599$c3e8da3$5496439d@news.astraweb.com> <5222f675$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9c11126f-93e8-461c-b487-bafc6b146269@googlegroups.com> > That said, though, when you consider the language ecosystem rather > > than just the language, there is a strong tendency for Java and C++ > > code to wrap everything up with functions (no public data members), > > whereas Python code is far more likely to have external code directly > > access data inside an object. You usually will find Java code calling > > methods to change members, whereas that's done in Python only when > > there's a need for it. Yep, this is precisely my point, if you take encapsulation as a philosophical principle, Java and C++ would tend to be abiding by it, as a "default" setting that you can at times change, whereas python would tend to be the contrary. In other words, you can set some encapsulation if and when you want to, but you can leave your code without it when it's not needed/inconvenient. So I guess that we are actually all agreeing on this one. From ethan at stoneleaf.us Sun Sep 1 14:42:35 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 01 Sep 2013 11:42:35 -0700 Subject: Encapsulation unpythonic? In-Reply-To: <9c11126f-93e8-461c-b487-bafc6b146269@googlegroups.com> References: <8255dfbd-a2a1-4ab7-b900-ee19faa459f2@googlegroups.com> <8c7c4854-70e1-46e7-a3ff-a3206c4c5c27@googlegroups.com> <5221567b$0$6599$c3e8da3$5496439d@news.astraweb.com> <5221d7ab$0$6599$c3e8da3$5496439d@news.astraweb.com> <5222f675$0$6599$c3e8da3$5496439d@news.astraweb.com> <9c11126f-93e8-461c-b487-bafc6b146269@googlegroups.com> Message-ID: <52238A9B.1050900@stoneleaf.us> On 09/01/2013 03:09 AM, Fabrice Pombet wrote: > > So I guess that we are actually all agreeing on this one. No, we are not. "encapsulation" != "inaccessible except by getters/setters" -- ~Ethan~ From roy at panix.com Sun Sep 1 15:13:06 2013 From: roy at panix.com (Roy Smith) Date: Sun, 01 Sep 2013 15:13:06 -0400 Subject: Encapsulation unpythonic? References: <8255dfbd-a2a1-4ab7-b900-ee19faa459f2@googlegroups.com> <8c7c4854-70e1-46e7-a3ff-a3206c4c5c27@googlegroups.com> <5221567b$0$6599$c3e8da3$5496439d@news.astraweb.com> <5221d7ab$0$6599$c3e8da3$5496439d@news.astraweb.com> <5222f675$0$6599$c3e8da3$5496439d@news.astraweb.com> <9c11126f-93e8-461c-b487-bafc6b146269@googlegroups.com> Message-ID: In article , Ethan Furman wrote: > On 09/01/2013 03:09 AM, Fabrice Pombet wrote: > > > > So I guess that we are actually all agreeing on this one. > > No, we are not. > > "encapsulation" != "inaccessible except by getters/setters" Nothing is accessible in Python except via getters and setters. The only difference between Python and, say, C++ in this regard is that the Python compiler writes them for you most of the time and doesn't make you put ()'s at the end of the name :-) From ethan at stoneleaf.us Sun Sep 1 16:33:25 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 01 Sep 2013 13:33:25 -0700 Subject: Encapsulation unpythonic? In-Reply-To: References: <8255dfbd-a2a1-4ab7-b900-ee19faa459f2@googlegroups.com> <8c7c4854-70e1-46e7-a3ff-a3206c4c5c27@googlegroups.com> <5221567b$0$6599$c3e8da3$5496439d@news.astraweb.com> <5221d7ab$0$6599$c3e8da3$5496439d@news.astraweb.com> <5222f675$0$6599$c3e8da3$5496439d@news.astraweb.com> <9c11126f-93e8-461c-b487-bafc6b146269@googlegroups.com> Message-ID: <5223A495.5070103@stoneleaf.us> On 09/01/2013 12:13 PM, Roy Smith wrote: > In article , > Ethan Furman wrote: > >> On 09/01/2013 03:09 AM, Fabrice Pombet wrote: >>> >>> So I guess that we are actually all agreeing on this one. >> >> No, we are not. >> >> "encapsulation" != "inaccessible except by getters/setters" > > Nothing is accessible in Python except via getters and setters. The > only difference between Python and, say, C++ in this regard is that the > Python compiler writes them for you most of the time and doesn't make > you put ()'s at the end of the name :-) class Javaesque: __value = None def get_value(self): return self.__value def set_value(self, new_value): validate(new_value) self.__value = new_value class ProtectedPython: _value = None @property def value(self): return self._value @value.setter def value(self, new_value) validate(new_value) self._value = new_value class PlainPython: value = None In the Javaesque class we see the unPythonic way of using getters/setters; in the ProtectedPython* class we see the pythonic way of providing getters/setters**; in the PlainPython class we have the standard, unprotected, direct access to the class attribute. No where in PlainPython is a getter/setter defined, nor does Python define one for us behind our backs. If you have evidence to the contrary I'd like to see it. * Not the best name, but oh well. ** In Python, using @property makes getter/setter usage look just like normal attribute usage, which is cool. -- ~Ethan~ From timothy.c.delaney at gmail.com Sun Sep 1 17:54:53 2013 From: timothy.c.delaney at gmail.com (Tim Delaney) Date: Mon, 2 Sep 2013 07:54:53 +1000 Subject: Encapsulation unpythonic? In-Reply-To: <5223A495.5070103@stoneleaf.us> References: <8255dfbd-a2a1-4ab7-b900-ee19faa459f2@googlegroups.com> <8c7c4854-70e1-46e7-a3ff-a3206c4c5c27@googlegroups.com> <5221567b$0$6599$c3e8da3$5496439d@news.astraweb.com> <5221d7ab$0$6599$c3e8da3$5496439d@news.astraweb.com> <5222f675$0$6599$c3e8da3$5496439d@news.astraweb.com> <9c11126f-93e8-461c-b487-bafc6b146269@googlegroups.com> <5223A495.5070103@stoneleaf.us> Message-ID: On 2 September 2013 06:33, Ethan Furman wrote: > > class PlainPython: > > value = None > > > In the Javaesque class we see the unPythonic way of using getters/setters; > in the ProtectedPython* class we see the pythonic way of providing > getters/setters**; in the PlainPython class we have the standard, > unprotected, direct access to the class attribute. > > No where in PlainPython is a getter/setter defined, nor does Python define > one for us behind our backs. > > If you have evidence to the contrary I'd like to see it. > I think Roy is referring to the fact that attribute access is implemented via __getattr__ / __getattribute__ / __setattr__ / __delattr__. From one point of view, he's absolutely correct - nearly all attributes are accessed via getters/setters in Python. Tim Delaney -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Sun Sep 1 20:24:34 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 01 Sep 2013 17:24:34 -0700 Subject: Encapsulation unpythonic? In-Reply-To: References: <8255dfbd-a2a1-4ab7-b900-ee19faa459f2@googlegroups.com> <8c7c4854-70e1-46e7-a3ff-a3206c4c5c27@googlegroups.com> <5221567b$0$6599$c3e8da3$5496439d@news.astraweb.com> <5221d7ab$0$6599$c3e8da3$5496439d@news.astraweb.com> <5222f675$0$6599$c3e8da3$5496439d@news.astraweb.com> <9c11126f-93e8-461c-b487-bafc6b146269@googlegroups.com> <5223A495.5070103@stoneleaf.us> Message-ID: <5223DAC2.50103@stoneleaf.us> On 09/01/2013 02:54 PM, Tim Delaney wrote: > Roy Smith wrote: >> >> Nothing is accessible in Python except via getters and setters. The >> only difference between Python and, say, C++ in this regard is that the >> Python compiler writes them for you most of the time and doesn't make >> you put ()'s at the end of the name > > I think Roy is referring to the fact that attribute access is implemented via __getattr__ / __getattribute__ / > __setattr__ / __delattr__. From one point of view, he's absolutely correct - nearly all attributes are accessed via > getters/setters in Python. Seems to me there is a difference between an underlying generic protocol for data manipulation and "Python writing them [getters/setters] for you". -- ~Ethan~ From roy at panix.com Sun Sep 1 20:59:25 2013 From: roy at panix.com (Roy Smith) Date: Sun, 01 Sep 2013 20:59:25 -0400 Subject: Encapsulation unpythonic? References: <8255dfbd-a2a1-4ab7-b900-ee19faa459f2@googlegroups.com> <8c7c4854-70e1-46e7-a3ff-a3206c4c5c27@googlegroups.com> <5221567b$0$6599$c3e8da3$5496439d@news.astraweb.com> <5221d7ab$0$6599$c3e8da3$5496439d@news.astraweb.com> <5222f675$0$6599$c3e8da3$5496439d@news.astraweb.com> <9c11126f-93e8-461c-b487-bafc6b146269@googlegroups.com> <5223A495.5070103@stoneleaf.us> Message-ID: In article , Ethan Furman wrote: > On 09/01/2013 02:54 PM, Tim Delaney wrote: > > Roy Smith wrote: > >> > >> Nothing is accessible in Python except via getters and setters. The > >> only difference between Python and, say, C++ in this regard is that the > >> Python compiler writes them for you most of the time and doesn't make > >> you put ()'s at the end of the name > > > > I think Roy is referring to the fact that attribute access is implemented > > via __getattr__ / __getattribute__ / > > __setattr__ / __delattr__. From one point of view, he's absolutely correct > > - nearly all attributes are accessed via > > getters/setters in Python. > > Seems to me there is a difference between an underlying generic protocol for > data manipulation and "Python writing them > [getters/setters] for you". Why? When I write "foo.bar", a bunch of generic code gets run which figures out what value to return. If I don't like the generic behavior, I can write my own __getattrr__(), etc, and make it do whatever I want. How is that any different from, in C++, if you don't write a default constructor, the compiler will write one for you. If you don't like the generic behavior you get from that, you can write your own and make it do whatever you want. From steve+comp.lang.python at pearwood.info Sun Sep 1 22:57:37 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 Sep 2013 02:57:37 GMT Subject: Encapsulation unpythonic? References: <8255dfbd-a2a1-4ab7-b900-ee19faa459f2@googlegroups.com> <8c7c4854-70e1-46e7-a3ff-a3206c4c5c27@googlegroups.com> <5221567b$0$6599$c3e8da3$5496439d@news.astraweb.com> <5221d7ab$0$6599$c3e8da3$5496439d@news.astraweb.com> <5222f675$0$6599$c3e8da3$5496439d@news.astraweb.com> <9c11126f-93e8-461c-b487-bafc6b146269@googlegroups.com> <5223A495.5070103@stoneleaf.us> Message-ID: <5223fea0$0$6599$c3e8da3$5496439d@news.astraweb.com> On Sun, 01 Sep 2013 20:59:25 -0400, Roy Smith wrote: > In article , > Ethan Furman wrote: > >> On 09/01/2013 02:54 PM, Tim Delaney wrote: >> > Roy Smith wrote: >> >> >> >> Nothing is accessible in Python except via getters and setters. The >> >> only difference between Python and, say, C++ in this regard is that >> >> the Python compiler writes them for you most of the time and doesn't >> >> make you put ()'s at the end of the name >> > >> > I think Roy is referring to the fact that attribute access is >> > implemented via __getattr__ / __getattribute__ / >> > __setattr__ / __delattr__. From one point of view, he's absolutely >> > correct - nearly all attributes are accessed via getters/setters in >> > Python. >> >> Seems to me there is a difference between an underlying generic >> protocol for data manipulation and "Python writing them >> [getters/setters] for you". > > Why? When I write "foo.bar", a bunch of generic code gets run which > figures out what value to return. If I don't like the generic behavior, > I can write my own __getattrr__(), etc, and make it do whatever I want. > > How is that any different from, in C++, if you don't write a default > constructor, the compiler will write one for you. If you don't like the > generic behavior you get from that, you can write your own and make it > do whatever you want. And fundamentally, all programming is flipping bits, therefore all languages are exactly the same, right? :-) I can't speak for C++, but comparing Java and Python there are differences: - Java the language makes it a pain to change your mind and convert a public attribute to a computed attribute. Since the pain of changing your mind far outweighs the pain of writing trivial getters/setters up front, it is good defensive practice to make attribute access via getters just in case. Python makes it trivial to change your mind, and so YAGNI rules and you shouldn't write getters unless you actually need them. - Perhaps because the focus in Java is on massive projects with large numbers of barely adequate coders, Java tries to protect the average coder from shooting themselves in the foot. Consequently, Java encourages a philosophy of "default deny" when it comes to attribute access: don't give your caller access to anything except the absolute minimum you know they need. In Python, the focus tends to be more about smaller projects with small teams of better than average coders, and a philosophy of "we're all adults here". Consequently, Python code tends towards "everything not explicitly prohibited is permitted". - Similarly, while Java the language doesn't force you to *explicitly* declare members as public (if you don't declare members private, they are public), it strongly encourages you to think about information hiding and explicitly mark members as public. Python does not. There is no way to explicitly mark attributes as public. - The Java compiler enforces public/private, while Python treats it as a convention. (At least for pure-Python code.) But notice that they are differences of degree, not kind. Java encourages information hiding in classes, but does not prohibit you from making members public, and using reflection you can break into classes and get access to anything; Python allows information hiding, but trusts the programmer to honour "private" names, and reflection is such a fundamental part of Python that we don't even call it that. -- Steven From ethan at stoneleaf.us Mon Sep 2 00:15:03 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 01 Sep 2013 21:15:03 -0700 Subject: Encapsulation unpythonic? In-Reply-To: References: <8255dfbd-a2a1-4ab7-b900-ee19faa459f2@googlegroups.com> <8c7c4854-70e1-46e7-a3ff-a3206c4c5c27@googlegroups.com> <5221567b$0$6599$c3e8da3$5496439d@news.astraweb.com> <5221d7ab$0$6599$c3e8da3$5496439d@news.astraweb.com> <5222f675$0$6599$c3e8da3$5496439d@news.astraweb.com> <9c11126f-93e8-461c-b487-bafc6b146269@googlegroups.com> <5223A495.5070103@stoneleaf.us> Message-ID: <522410C7.6040909@stoneleaf.us> On 09/01/2013 05:59 PM, Roy Smith wrote: > Ethan Furman wrote: >> On 09/01/2013 02:54 PM, Tim Delaney wrote: >>> Roy Smith wrote: >>>> >>>> Nothing is accessible in Python except via getters and setters. The >>>> only difference between Python and, say, C++ in this regard is that the >>>> Python compiler writes them for you most of the time and doesn't make >>>> you put ()'s at the end of the name >>> >>> I think Roy is referring to the fact that attribute access is implemented >>> via __getattr__ / __getattribute__ / >>> __setattr__ / __delattr__. From one point of view, he's absolutely correct >>> - nearly all attributes are accessed via >>> getters/setters in Python. >> >> Seems to me there is a difference between an underlying generic protocol for >> data manipulation and "Python writing them >> [getters/setters] for you". > > Why? When I write "foo.bar", a bunch of generic code gets run which > figures out what value to return. If I don't like the generic behavior, > I can write my own __getattrr__(), etc, and make it do whatever I want. I don't yet know C++ so I can't speak to it. In Python if you are writing your own __getattr__, etc., you are writing the underlying protocol itself. To write a getter/setter you would just use def get_soemthing(...) def set_something(...) or, even better @property def something(...) Maybe, as Steven said, it's just a matter of degree: my understanding of getters/setters is that they are per attribute, while __getattr__ will be called for every attribute not otherwise found, __setattr__ will be called for every assignment, __delattr__ will be called for every deletion, and all that is assuming you haven't written your own __getattribute__ and completely changed the rules for your class. -- ~Ethan~ From roy at panix.com Sun Sep 1 18:02:50 2013 From: roy at panix.com (Roy Smith) Date: Sun, 01 Sep 2013 18:02:50 -0400 Subject: Encapsulation unpythonic? References: <8255dfbd-a2a1-4ab7-b900-ee19faa459f2@googlegroups.com> <8c7c4854-70e1-46e7-a3ff-a3206c4c5c27@googlegroups.com> <5221567b$0$6599$c3e8da3$5496439d@news.astraweb.com> <5221d7ab$0$6599$c3e8da3$5496439d@news.astraweb.com> <5222f675$0$6599$c3e8da3$5496439d@news.astraweb.com> <9c11126f-93e8-461c-b487-bafc6b146269@googlegroups.com> <5223A495.5070103@stoneleaf.us> Message-ID: In article , Tim Delaney wrote: > On 2 September 2013 06:33, Ethan Furman wrote: > > > > > class PlainPython: > > > > value = None > > > > > > In the Javaesque class we see the unPythonic way of using getters/setters; > > in the ProtectedPython* class we see the pythonic way of providing > > getters/setters**; in the PlainPython class we have the standard, > > unprotected, direct access to the class attribute. > > > > No where in PlainPython is a getter/setter defined, nor does Python define > > one for us behind our backs. > > > > If you have evidence to the contrary I'd like to see it. > > > > I think Roy is referring to the fact that attribute access is implemented > via __getattr__ / __getattribute__ / __setattr__ / __delattr__. From one > point of view, he's absolutely correct - nearly all attributes are accessed > via getters/setters in Python. > > Tim Delaney Thank you. From steve+comp.lang.python at pearwood.info Sun Sep 1 21:57:28 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 Sep 2013 01:57:28 GMT Subject: Encapsulation unpythonic? References: <8255dfbd-a2a1-4ab7-b900-ee19faa459f2@googlegroups.com> <8c7c4854-70e1-46e7-a3ff-a3206c4c5c27@googlegroups.com> <5221567b$0$6599$c3e8da3$5496439d@news.astraweb.com> <5221d7ab$0$6599$c3e8da3$5496439d@news.astraweb.com> <5222f675$0$6599$c3e8da3$5496439d@news.astraweb.com> <9c11126f-93e8-461c-b487-bafc6b146269@googlegroups.com> Message-ID: <5223f087$0$6599$c3e8da3$5496439d@news.astraweb.com> On Sun, 01 Sep 2013 15:13:06 -0400, Roy Smith wrote: > In article , > Ethan Furman wrote: > >> On 09/01/2013 03:09 AM, Fabrice Pombet wrote: >> > >> > So I guess that we are actually all agreeing on this one. >> >> No, we are not. >> >> "encapsulation" != "inaccessible except by getters/setters" > > Nothing is accessible in Python except via getters and setters. The > only difference between Python and, say, C++ in this regard is that the > Python compiler writes them for you most of the time and doesn't make > you put ()'s at the end of the name :-) Very clever! Pedantic, and an unusual look at what's going on under the hood! I wanted to say it was *not quite correct*, because you can read or write directly to the instance dict: instance.__dict__['name'] = 42 If I understand Python's internals correctly, __dict__ is a slot, and so bypasses the usual getattr machinary. But even if so, __dict__['name'] uses the dictionary __get/setitem__ method, so it's still a getter/setter under the hood. In any case, even if you are *technically* correct that Python has getters and setters under the hood, that's not quite what the discussion here is about. But I'm sure you realise that :-) -- Steven From ben+python at benfinney.id.au Sun Sep 1 19:32:16 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 02 Sep 2013 09:32:16 +1000 Subject: Encapsulation unpythonic? References: <8255dfbd-a2a1-4ab7-b900-ee19faa459f2@googlegroups.com> <8c7c4854-70e1-46e7-a3ff-a3206c4c5c27@googlegroups.com> <5221567b$0$6599$c3e8da3$5496439d@news.astraweb.com> <5221d7ab$0$6599$c3e8da3$5496439d@news.astraweb.com> <5222f675$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7weh98w22n.fsf@benfinney.id.au> Steven D'Aprano writes: > [?] programmers have been using the *principle* of encapsulation since > before Grace Hopper was an admiral. [?] > Encapsulation and information hiding are distinct things -- you can > have one without the other. [?] > One of the most obnoxious and annoying traits of OOP zealots, > especially academics, is that they act as if programming did not exist > before Java and C++, or if you're really lucky, Smalltalk. (Somehow > they nearly always forget about Simula.) Yes. That's something which has been pointed out to such people, even in the Java community, for most (all?) of Java's history. Here's a JavaWorld article from 2001, by a Java programmer, with the clear title ?Encapsulation is not information hiding?: Encapsulation refers to the bundling of data with the methods that operate on that data. Often that definition is misconstrued to mean that the data is somehow hidden. (That site unfortunately slices up the article into many pages to increase advertising hits and reader frustration, my apologies.) One of the more annoying traits of humanity is that whatever context we first encounter a term is disproportionately privileged, causing us to irrationally dismiss better (more useful, more reasonable, more pedagogically appropriate, more historically correct, etc.) definitions. This thread is an excellent illustration that the field of programming is no exception. -- \ Moriarty: ?Forty thousand million billion dollars? That money | `\ must be worth a fortune!? ?The Goon Show, _The Sale of | _o__) Manhattan_ | Ben Finney From roy at panix.com Sun Sep 1 20:52:04 2013 From: roy at panix.com (Roy Smith) Date: Sun, 01 Sep 2013 20:52:04 -0400 Subject: Encapsulation unpythonic? References: <8255dfbd-a2a1-4ab7-b900-ee19faa459f2@googlegroups.com> <8c7c4854-70e1-46e7-a3ff-a3206c4c5c27@googlegroups.com> <5221567b$0$6599$c3e8da3$5496439d@news.astraweb.com> <5221d7ab$0$6599$c3e8da3$5496439d@news.astraweb.com> <5222f675$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Ben Finney wrote: > One of the more annoying traits of humanity is that whatever context we > first encounter a term is disproportionately privileged, causing us to > irrationally dismiss better (more useful, more reasonable, more > pedagogically appropriate, more historically correct, etc.) definitions. Known in the education world as "The law of primacy". From rhodri at wildebst.demon.co.uk Mon Sep 2 19:29:42 2013 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 03 Sep 2013 00:29:42 +0100 Subject: Encapsulation unpythonic? References: <8255dfbd-a2a1-4ab7-b900-ee19faa459f2@googlegroups.com> <8c7c4854-70e1-46e7-a3ff-a3206c4c5c27@googlegroups.com> <5221567b$0$6599$c3e8da3$5496439d@news.astraweb.com> <5221d7ab$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, 31 Aug 2013 12:46:52 +0100, Steven D'Aprano wrote: > # THIS DOES NOT HAPPEN IN PYTHON > # or any other language, as far as I am aware > x = 23 > y = x # y now has the value 23 > x = 42 # change the value of the object ### NOT SO! ### > print y > => prints 42 Not directly, but FORTRAN did (does?) allow you to achieve this oh-so-undesirable result indirectly. FORTRAN passes arguments to functions and procedures by reference. That includes passing constants, which effectively get put into hidden variables and passed across. Changes to the "constant" parameters in the function can happen just as with any pass-by-reference, which would be fine if you promptly threw the constant away. Unfortunately smart compilers used to (still do?) keep pools of these common constant "variables" around rather than creating new ones all the time, so changes to "constants" persisted. Many's the poor natural scientist who was perplexed to find that 0 suddenly had the value 1! -- Rhodri James *-* Wildebeest Herder to the Masses From dihedral88888 at gmail.com Mon Sep 2 17:43:08 2013 From: dihedral88888 at gmail.com (88888 Dihedral) Date: Mon, 2 Sep 2013 14:43:08 -0700 (PDT) Subject: Encapsulation unpythonic? In-Reply-To: <8c7c4854-70e1-46e7-a3ff-a3206c4c5c27@googlegroups.com> References: <8255dfbd-a2a1-4ab7-b900-ee19faa459f2@googlegroups.com> <8c7c4854-70e1-46e7-a3ff-a3206c4c5c27@googlegroups.com> Message-ID: <9badc8a4-cb4c-4b82-9658-15a21d891ec9@googlegroups.com> Fabrice Pombet? 2013?8?31????UTC+8??1?43?28???? > On Saturday, August 17, 2013 2:26:32 PM UTC+2, Fernando Saldanha wrote: > > > I am new to Python, with experience in Java, C++ and R. > > > > > > > > > > > > As I understand encapsulation is not a big thing in the Python world. I read that you can put two underscores before the name of a variable within a class declaration but in the many examples of code I looked at this is not widely used. I also read that encapsulation is "unpythonic." > > > > > > > > > > > > Questions: > > > > > > > > > 2) If it is in fact true that encapsulation is rarely used, how do I deal with the fact that other programmers can easily alter the values of members of my classes? > > > > > Fernando, it is widely accepted that Python pays very little attention to encapsulation as a principle set in stone. Chaz's definition of encapsulation is also mine. Now you need to consider that taking this principle off the hostel of OOP does not mean that you can do whatever you fancy and you can't make anything unsettable. > > > > There are plenty of techniques within Python that allow you to protect your arguments (in particular, decorators) inside a Class. > > > > Now, lets get to the pretentious philosophical discussion: I guess encapsulation is quite the opposite of, say, dynamic typing, which is arguably core in Python. In practice this allows Python to be less verbose: at the end of the day, if you look back at your previous languages, don't you find that some of their compulsory features are usually more of a pain than something useful in practice? And after all, whither encapsulation? Can't we just have objects whose arguments are determined externally if we want to? > > And that is the ballgame: as my old tutor says: "the claptrap of setters and getters does not need to be here if it is unnecessary". I would add: "so long as you can have them when you deem it necessary", and Python allows that. The way to perform encapsulation in Python can be achieved by writing methods in C to be compiled as an extension which can be used by all instances of some classes in the upper level. CYTHON is easy to be used for the job. From andy.kannberg at gmail.com Mon Sep 2 10:21:03 2013 From: andy.kannberg at gmail.com (Andy Kannberg) Date: Mon, 2 Sep 2013 16:21:03 +0200 Subject: optparse question (python 2.6) Message-ID: Hi all, I tried with the example Peter gave me, and it works. But only when the options are boolean. At least, that is my conclusion with experimenting. I'll elaborate: The code to create 'mutually exclusive options': option_names = [ "l", "o" , "s" ] toggled_options = [name for name in option_names if getattr(opts, name)] if len(toggled_options) > 1: s = repr(toggled_options).strip("[]") parser.error("options %s are mutually exclusive" % s) The options: parser = optparse.OptionParser() parser.add_option('-l', help='Show optionset list', dest='l', action='store_true' ) parser.add_option('-o', help='Show content of optionset ', dest='o', action='store') parser.add_option('-s', help='Set optionset for a host', dest='s', action='store' , nargs=2) The first option, -l, doesn't require an argument The second option, -o, does require one argument. The third option, -s does require 2 arguments. I need to add 4 more options, which all need one or more arguments. Now, when I run the program with the options defined as above, everything works, except, the 'mutually exclusive' part. Because only the -l option is set to 'true' when selected. When I modify the options to this: parser = optparse.OptionParser() parser.add_option('-l', help='Show optionset list', dest='l', action='store_true' ) parser.add_option('-o', help='Show content of optionset ', dest='o', action='store_true') parser.add_option('-s', help='Set optionset for a host', dest='s', action='store_true' , nargs=2) I get this error: # ./listopt3.py -o -l Traceback (most recent call last): File "./listopt3.py", line 8, in parser.add_option('-s', help='Set optionset for a host', dest='s', action='store_true' , nargs=2) File "/usr/lib64/python2.6/optparse.py", line 1012, in add_option option = self.option_class(*args, **kwargs) File "/usr/lib64/python2.6/optparse.py", line 577, in __init__ checker(self) File "/usr/lib64/python2.6/optparse.py", line 706, in _check_nargs self) optparse.OptionError: option -s: 'nargs' must not be supplied for action 'store_true' So, apparanly, using boolean AND arguments isn't allowed. I'm still learning Python, so if someone can point me in the right direction would be great! cheers, Andy 2013/8/27 Andy Kannberg > Hello Peter, > > Thanks for the example. For now I am restricted to Python 2.6, so no > argparse for me at the moment. > > cheers, > Andy > > > 2013/8/26 Peter Otten <__peter__ at web.de> > >> Andy Kannberg wrote: >> >> > Hi python-guru's, >> > >> > I am new to Python, coming from a long history of Unix/linux shell >> > programming. >> > I am creating a Python script (In Python 2.6) which should be able to >> > read command line options and arguments. >> > So far, I figured out how to do that with optparse. I can add options >> (and >> > arguments ) . >> > There are about 7 options that can be selected. >> > >> > However, I can't seem to figure out how to force that only one option is >> > allowed when the script is invoked. In other words: How to restrict the >> > script to accept only one of the available options ? >> >> You have to do it manually, like in the example >> >> >> http://docs.python.org/2.6/library/optparse.html#how-optparse-handles-errors >> >> if options.a and options.b: >> parser.error("options -a and -b are mutually exclusive") >> >> which could be generalized to (untested) >> >> option_names = ["foo", "bar", "baz", ...] >> toggled_options = [name for name in option_names if getattr(options, >> name)] >> if len(toggled_options) > 1: >> s = repr(toggled_options).strip("[]") >> parser.error("options %s are mutually exclusive" % s) >> >> If you are not restricted to the standard library use >> >> https://pypi.python.org/pypi/argparse >> >> which was added to the stdlib in 2.7 and has "mutually exclusive groups", >> see >> >> http://docs.python.org/2/library/argparse.html#mutual-exclusion >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Mon Sep 2 11:33:53 2013 From: __peter__ at web.de (Peter Otten) Date: Mon, 02 Sep 2013 17:33:53 +0200 Subject: optparse question (python 2.6) References: Message-ID: Andy Kannberg wrote: > I tried with the example Peter gave me, and it works. But only when the > options are boolean. At least, that is my conclusion with experimenting. > I'll elaborate: > > The code to create 'mutually exclusive options': > > option_names = [ "l", "o" , "s" ] > toggled_options = [name for name in option_names if getattr(opts, name)] > if len(toggled_options) > 1: > s = repr(toggled_options).strip("[]") > parser.error("options %s are mutually exclusive" % s) This doesn't actually create mutually exclusive options, it just checks if there are conflicting options after they are parsed, and exists with an error message when conflicts are found. > The options: > > parser = optparse.OptionParser() > parser.add_option('-l', help='Show optionset list', dest='l', > action='store_true' ) > parser.add_option('-o', help='Show content of optionset ', dest='o', > action='store') > parser.add_option('-s', help='Set optionset for a host', dest='s', > action='store' , nargs=2) > > The first option, -l, doesn't require an argument > The second option, -o, does require one argument. > The third option, -s does require 2 arguments. > > I need to add 4 more options, which all need one or more arguments. > > Now, when I run the program with the options defined as above, everything > works, except, the 'mutually exclusive' part. Because only the -l option > is set to 'true' when selected. When I modify the options to this: > > parser = optparse.OptionParser() > parser.add_option('-l', help='Show optionset list', dest='l', > action='store_true' ) > parser.add_option('-o', help='Show content of optionset ', dest='o', > action='store_true') > parser.add_option('-s', help='Set optionset for a host', dest='s', > action='store_true' , nargs=2) > > I get this error: > > # ./listopt3.py -o -l > Traceback (most recent call last): > File "./listopt3.py", line 8, in > parser.add_option('-s', help='Set optionset for a host', dest='s', > action='store_true' , nargs=2) > File "/usr/lib64/python2.6/optparse.py", line 1012, in add_option > option = self.option_class(*args, **kwargs) > File "/usr/lib64/python2.6/optparse.py", line 577, in __init__ > checker(self) > File "/usr/lib64/python2.6/optparse.py", line 706, in _check_nargs > self) > optparse.OptionError: option -s: 'nargs' must not be supplied for action > 'store_true' > > So, apparanly, using boolean AND arguments isn't allowed. > I'm still learning Python, so if someone can point me in the right > direction would be great! You don't need the action="store_true" for every option, only for those that act as a flag, i. e. are present or not, but don't carry a value. Here is a working example: $ cat optparse_mutually_exclusive.py import optparse parser = optparse.OptionParser() parser.add_option("-l", "--list-optionsets", help="Show optionset list", action="store_true") parser.add_option("-o", "--show-options", help="Show content of optionset") parser.add_option("-s", "--set-options", help="Set optionset for a host", nargs=2) options, args = parser.parse_args() option_names = ["list_optionsets", "show_options", "set_options"] toggled_options = [name for name in option_names if getattr(options, name)] if len(toggled_options) > 1: s = repr(toggled_options).strip("[]") parser.error("options %s are mutually exclusive" % s) print options Let's run it a few times: $ python2.6 optparse_mutually_exclusive.py -h Usage: optparse_mutually_exclusive.py [options] Options: -h, --help show this help message and exit -l, --list-optionsets Show optionset list -o SHOW_OPTIONS, --show-options=SHOW_OPTIONS Show content of optionset -s SET_OPTIONS, --set-options=SET_OPTIONS Set optionset for a host $ python2.6 optparse_mutually_exclusive.py --list-optionsets {'list_optionsets': True, 'show_options': None, 'set_options': None} $ python2.6 optparse_mutually_exclusive.py --list-optionsets --show-options Usage: optparse_mutually_exclusive.py [options] optparse_mutually_exclusive.py: error: --show-options option requires an argument $ python2.6 optparse_mutually_exclusive.py --show-options foo {'list_optionsets': None, 'show_options': 'foo', 'set_options': None} $ python2.6 optparse_mutually_exclusive.py --show-options foo -s bar baz Usage: optparse_mutually_exclusive.py [options] optparse_mutually_exclusive.py: error: options 'show_options', 'set_options' are mutually exclusive $ python2.6 optparse_mutually_exclusive.py foo -s bar baz {'list_optionsets': None, 'show_options': None, 'set_options': ('bar', 'baz')} I should mention one important restriction with this approach: the default value must be "falsy" like None, [], "", 0, and the value provided by the user must be "truish" like -1, 42.0, "foo", ["a", "b"]. Also, ceterum censeo ;) -- there is a version of argparse available for download on https://pypi.python.org/pypi/argparse that should work with Python 2.6 and offers a better approach, see http://docs.python.org/2/library/argparse.html#sub-commands for the documentation. From kurt.alfred.mueller at gmail.com Thu Sep 5 03:42:36 2013 From: kurt.alfred.mueller at gmail.com (Kurt Mueller) Date: Thu, 05 Sep 2013 09:42:36 +0200 Subject: split lines from stdin into a list of unicode strings In-Reply-To: References: <521DB58E.5000102@gmail.com> Message-ID: <522835EC.1010407@gmail.com> Am 29.08.2013 11:12, schrieb Peter Otten: > kurt.alfred.mueller at gmail.com wrote: >> On Wednesday, August 28, 2013 1:13:36 PM UTC+2, Dave Angel wrote: >>> On 28/8/2013 04:32, Kurt Mueller wrote: >>>> For some text manipulation tasks I need a template to split lines >>>> from stdin into a list of strings the way shlex.split() does it. >>>> The encoding of the input can vary. > You can compromise and read ahead a limited number of lines. Here's my demo > script (The interesting part is detect_encoding(), I got a bit distracted by > unrelated stuff...). The script does one extra decode/encode cycle -- it > should be easy to avoid that if you run into performance issues. I took your script as a template. But I used the libmagic library (pyhton-magic) instead of chardet. See http://linux.die.net/man/3/libmagic and https://github.com/ahupp/python-magic ( I made tests with files of different size, up to 1.2 [GB] ) I had following issues: - I a real file, the encoding was detected as 'ascii' for detect_lines=1000. In line 1002 there was an umlaut character. So then the line.decode(encoding) failed. I think to add the errors parameter, line.decode(encoding, errors='replace') - If the buffer was bigger than about some Megabytes, the returned encoding from libmagic was always None. The big files had very long lines ( more than 4k per line ). So with detect_lines=1000 this limit was exceeded. - The magic.buffer() ( the equivalent of chardet.detect() ) takes about 2 seconds per megabyte buffer. -- Kurt Mueller From __peter__ at web.de Thu Sep 5 04:33:59 2013 From: __peter__ at web.de (Peter Otten) Date: Thu, 05 Sep 2013 10:33:59 +0200 Subject: split lines from stdin into a list of unicode strings References: <521DB58E.5000102@gmail.com> <522835EC.1010407@gmail.com> Message-ID: Kurt Mueller wrote: > Am 29.08.2013 11:12, schrieb Peter Otten: >> kurt.alfred.mueller at gmail.com wrote: >>> On Wednesday, August 28, 2013 1:13:36 PM UTC+2, Dave Angel wrote: >>>> On 28/8/2013 04:32, Kurt Mueller wrote: >>>>> For some text manipulation tasks I need a template to split lines >>>>> from stdin into a list of strings the way shlex.split() does it. >>>>> The encoding of the input can vary. > >> You can compromise and read ahead a limited number of lines. Here's my >> demo script (The interesting part is detect_encoding(), I got a bit >> distracted by unrelated stuff...). The script does one extra >> decode/encode cycle -- it should be easy to avoid that if you run into >> performance issues. > > I took your script as a template. > But I used the libmagic library (pyhton-magic) instead of chardet. > See http://linux.die.net/man/3/libmagic > and https://github.com/ahupp/python-magic > ( I made tests with files of different size, up to 1.2 [GB] ) > > I had following issues: > > - I a real file, the encoding was detected as 'ascii' for > detect_lines=1000. > In line 1002 there was an umlaut character. So then the > line.decode(encoding) failed. I think to add the errors parameter, > line.decode(encoding, errors='replace') Tough luck ;) You could try and tackle the problem by skipping leading ascii-only lines. Untested: def detect_encoding(instream, encoding, detect_lines, skip_ascii=True): if encoding is None: encoding = instream.encoding if encoding is None: if skip_ascii: try: for line in instream: yield line.decode("ascii") except UnicodeDecodeError: pass else: return head = [line] head.extend(islice(instream, detect_lines-1)) encoding = chardet.detect("".join(head))["encoding"] instream = chain(head, instream) for line in instream: yield line.decode(encoding) Or keep two lists, one with all, and one with only non-ascii lines, and read lines until there are enough lines in the list of non-ascii strings to make a good guess. Then take that list to determine the encoding. You can even combine both approaches... > - If the buffer was bigger than about some Megabytes, the returned > encoding > from libmagic was always None. The big files had very long lines ( more > than 4k per line ). So with detect_lines=1000 this limit was exceeded. > > - The magic.buffer() ( the equivalent of chardet.detect() ) takes about 2 > seconds > per megabyte buffer. From kurt.alfred.mueller at gmail.com Thu Sep 5 09:25:50 2013 From: kurt.alfred.mueller at gmail.com (Kurt Mueller) Date: Thu, 05 Sep 2013 15:25:50 +0200 Subject: split lines from stdin into a list of unicode strings In-Reply-To: References: <521DB58E.5000102@gmail.com> <522835EC.1010407@gmail.com> Message-ID: <5228865E.7000400@gmail.com> Am 05.09.2013 10:33, schrieb Peter Otten: > Kurt Mueller wrote: >> Am 29.08.2013 11:12, schrieb Peter Otten: >>> kurt.alfred.mueller at gmail.com wrote: >>>> On Wednesday, August 28, 2013 1:13:36 PM UTC+2, Dave Angel wrote: >>>>> On 28/8/2013 04:32, Kurt Mueller wrote: >>>>>> For some text manipulation tasks I need a template to split lines >>>>>> from stdin into a list of strings the way shlex.split() does it. >>>>>> The encoding of the input can vary. >> I took your script as a template. >> But I used the libmagic library (pyhton-magic) instead of chardet. >> See http://linux.die.net/man/3/libmagic >> and https://github.com/ahupp/python-magic >> ( I made tests with files of different size, up to 1.2 [GB] ) >> I had following issues: >> - I a real file, the encoding was detected as 'ascii' for >> detect_lines=1000. >> In line 1002 there was an umlaut character. So then the >> line.decode(encoding) failed. I think to add the errors parameter, >> line.decode(encoding, errors='replace') > > Tough luck ;) You could try and tackle the problem by skipping leading > ascii-only lines. Untested: > > def detect_encoding(instream, encoding, detect_lines, skip_ascii=True): > if encoding is None: > encoding = instream.encoding > if encoding is None: > if skip_ascii: > try: > for line in instream: > yield line.decode("ascii") > except UnicodeDecodeError: > pass > else: > return > head = [line] > head.extend(islice(instream, detect_lines-1)) > encoding = chardet.detect("".join(head))["encoding"] > instream = chain(head, instream) > for line in instream: > yield line.decode(encoding) I find this solution as a generator very nice. With just some small modifications it runs fine for now. ( line is undefined if skip_ascii is False. ) For ascii only files chardet or libmagic will not be bothered. And the detect_lines comes not in charge, until there are some non ascii characters. ------------------------------------------------------------------------------ def decode_stream_lines( inpt_strm, enco_type, numb_inpt, skip_asci=True, ): if enco_type is None: enco_type = inpt_strm.encoding if enco_type is None: line_head = [] if skip_asci: try: for line in inpt_strm: yield line.decode( 'ascii' ) except UnicodeDecodeError: line_head = [ line ] # last line was not ascii else: return # all lines were ascii line_head.extend( islice( inpt_strm, numb_inpt - 1 ) ) magc_enco = magic.open( magic.MAGIC_MIME_ENCODING ) magc_enco.load() enco_type = magc_enco.buffer( "".join( line_head ) ) magc_enco.close() print( I_AM + '-ERROR: enco_type=' + repr( enco_type ), file=sys.stderr, ) if enco_type.rfind( 'binary' ) >= 0: # binary, application/mswordbinary, application/vnd.ms-excelbinary and the like return inpt_strm = chain( line_head, inpt_strm ) for line in inpt_strm: yield line.decode( enco_type, errors='replace' ) ------------------------------------------------------------------------------ Thank you very much! -- Kurt Mueller From wayne at waynewerner.com Thu Sep 5 16:26:18 2013 From: wayne at waynewerner.com (Wayne Werner) Date: Thu, 5 Sep 2013 15:26:18 -0500 (CDT) Subject: Moving to Python for web In-Reply-To: <05537ea8-4993-4ad2-baa7-4ccdf5268c5d@googlegroups.com> References: <52bbd0bc-7c3e-4c85-bfe1-7fd4912945be@googlegroups.com> <05537ea8-4993-4ad2-baa7-4ccdf5268c5d@googlegroups.com> Message-ID: On Thu, 29 Aug 2013, Andreas Ecaz wrote: > I've decided to go with Flask! It's now running on UWSGI with NGINX. Hopefully I can get some stuff done :) > > > @Chris ?Kwpolska? Warrick > > I just don't like the big frameworks, for me there is too much magic going on. I'm a huge fan of Flask - I also find that when you start to learn more and more about Flask you can see how Django would be super useful, if you need all the bells and whistles. -W From invalid at invalid.invalid Mon Sep 2 10:20:51 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 2 Sep 2013 14:20:51 +0000 (UTC) Subject: semicolon at end of python's statements References: <1377735506.18906.15.camel@debian> <1FETt.52607$Mw4.14965@fx15.am4> <7wob8gywds.fsf@benfinney.id.au> <52213435$0$6599$c3e8da3$5496439d@news.astraweb.com> <87vc2mz3v1.fsf@no-fixed-abode.cable.virginmedia.net> Message-ID: On 2013-08-31, Paul Rudin wrote: > Jussi Piitulainen writes: > > >> # Option 1.5 >> for spam in sequence: >> if not predicate(spam): continue >> process(spam) >> >> This saves an indent level. > > Just out of interest: is saving an indent level a useful thing? Perhaps he's worried about the world running out of tabs? I heard that most of the tab mines are in China and they're going to stop exporting... -- Grant From python.list at tim.thechases.com Mon Sep 2 10:45:10 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 2 Sep 2013 09:45:10 -0500 Subject: semicolon at end of python's statements In-Reply-To: References: <1377735506.18906.15.camel@debian> <1FETt.52607$Mw4.14965@fx15.am4> <7wob8gywds.fsf@benfinney.id.au> <52213435$0$6599$c3e8da3$5496439d@news.astraweb.com> <87vc2mz3v1.fsf@no-fixed-abode.cable.virginmedia.net> Message-ID: <20130902094510.4c4c871f@bigbox.christie.dr> On 2013-09-02 14:20, Grant Edwards wrote: > >> This saves an indent level. > > > > Just out of interest: is saving an indent level a useful thing? > > Perhaps he's worried about the world running out of tabs? > > I heard that most of the tab mines are in China and they're going to > stop exporting... And buying all that indentation supports terrorists. Conserve whitespace or the terrorists win! :-) -tkc From roy at panix.com Mon Sep 2 10:47:30 2013 From: roy at panix.com (Roy Smith) Date: Mon, 02 Sep 2013 10:47:30 -0400 Subject: semicolon at end of python's statements References: <1377735506.18906.15.camel@debian> <1FETt.52607$Mw4.14965@fx15.am4> <7wob8gywds.fsf@benfinney.id.au> <52213435$0$6599$c3e8da3$5496439d@news.astraweb.com> <87vc2mz3v1.fsf@no-fixed-abode.cable.virginmedia.net> Message-ID: In article , Tim Chase wrote: > On 2013-09-02 14:20, Grant Edwards wrote: > > >> This saves an indent level. > > > > > > Just out of interest: is saving an indent level a useful thing? > > > > Perhaps he's worried about the world running out of tabs? > > > > I heard that most of the tab mines are in China and they're going to > > stop exporting... > > And buying all that indentation supports terrorists. Conserve > whitespace or the terrorists win! :-) What really gets me is the stupid TSA. You're allowed to bring as many spaces as you want on an airplane, but they confiscate all your tabs as the security checkpoint. From python.list at tim.thechases.com Mon Sep 2 13:58:46 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 2 Sep 2013 12:58:46 -0500 Subject: semicolon at end of python's statements In-Reply-To: References: <1377735506.18906.15.camel@debian> <1FETt.52607$Mw4.14965@fx15.am4> <7wob8gywds.fsf@benfinney.id.au> <52213435$0$6599$c3e8da3$5496439d@news.astraweb.com> <87vc2mz3v1.fsf@no-fixed-abode.cable.virginmedia.net> Message-ID: <20130902125846.68fdfa6b@bigbox.christie.dr> On 2013-09-02 10:47, Roy Smith wrote: > > > Perhaps he's worried about the world running out of tabs? > > > > > > I heard that most of the tab mines are in China and they're > > > going to stop exporting... > > > > And buying all that indentation supports terrorists. Conserve > > whitespace or the terrorists win! :-) > > What really gets me is the stupid TSA. You're allowed to bring as > many spaces as you want on an airplane, but they confiscate all > your tabs as the security checkpoint. Well, they *are* the "Tab Safety Administration". ;-) -tkc From rosuav at gmail.com Mon Sep 2 17:07:01 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 Sep 2013 07:07:01 +1000 Subject: semicolon at end of python's statements In-Reply-To: <20130902125846.68fdfa6b@bigbox.christie.dr> References: <1377735506.18906.15.camel@debian> <1FETt.52607$Mw4.14965@fx15.am4> <7wob8gywds.fsf@benfinney.id.au> <52213435$0$6599$c3e8da3$5496439d@news.astraweb.com> <87vc2mz3v1.fsf@no-fixed-abode.cable.virginmedia.net> <20130902125846.68fdfa6b@bigbox.christie.dr> Message-ID: On Tue, Sep 3, 2013 at 3:58 AM, Tim Chase wrote: > On 2013-09-02 10:47, Roy Smith wrote: >> > > Perhaps he's worried about the world running out of tabs? >> > > >> > > I heard that most of the tab mines are in China and they're >> > > going to stop exporting... >> > >> > And buying all that indentation supports terrorists. Conserve >> > whitespace or the terrorists win! :-) >> >> What really gets me is the stupid TSA. You're allowed to bring as >> many spaces as you want on an airplane, but they confiscate all >> your tabs as the security checkpoint. > > Well, they *are* the "Tab Safety Administration". ;-) Plus, they need to keep on confiscating them. It's all part of the surveillance schemes the government's doing - trying to keep tabs on everyone. ChrisA From antoon.pardon at rece.vub.ac.be Sun Sep 1 13:58:14 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Sun, 01 Sep 2013 19:58:14 +0200 Subject: semicolon at end of python's statements In-Reply-To: <52213435$0$6599$c3e8da3$5496439d@news.astraweb.com> References: <1377735506.18906.15.camel@debian> <1FETt.52607$Mw4.14965@fx15.am4> <7wob8gywds.fsf@benfinney.id.au> <52213435$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52238036.3030609@rece.vub.ac.be> Op 31-08-13 02:09, Steven D'Aprano schreef: > On Fri, 30 Aug 2013 11:32:17 +0100, F?bio Santos wrote: > >> On 29 Aug 2013 23:20, "Ben Finney" wrote: >>> >>> F?bio Santos writes: >>> >>>> It is a shame that this is not possible in python. for..if exists in >>>> comprehensions and not in regular loops but that would be nice >>>> sometimes. >>> >>> So you use it in a generator expression, and iterate over the >>> generator: >>> >>> for foo in (spam for spam in sequence if predicate(spam)): >>> process(spam) >>> >>> That way, there's no need for new syntax. >> >> The problem I have with that strategy is that it is repetitive and >> hinders readability. You wrote "for" and "in" twice, and spam (a pretty >> useless intermediate variable) thrice! > > There is no need for spam to be "intermediate", and the fact that it > shouldn't be is demonstrated by Ben's error in referring to "process > (spam)" instead of "process(foo)". > > We really are spoiled for choice here. We can write any of these: > > # Option 1 > for spam in sequence: > if predicate(spam): > process(spam) > > # Option 2 > for spam in filter(predicate, sequence): > process(spam) > > # Option 3 > for spam in (spam for spam in sequence if predicate(spam)): > process(spam) > > > Adding a fourth option: > > for spam in sequence if predicate(spam): > process(spam) > > saves absolutely nothing except a line and an indent level, neither of > which are in short supply, and gains nothing in readability over Option 1. I find this rather disenginuous. Dare to suggest here that python might benetif by incluidng end markers for its suits because it would make it clearer how many indent levels were done, and chances are someone here will suggest that too many indent levels are a sign of bad coding practice, but when someone suggests a change that would allow him to structure his program more like how he sees it and indent levels are not short in supply, suggesting there is no problem, no matter how many one uses. -- Antoon Pardon From antoon.pardon at rece.vub.ac.be Sun Sep 1 15:58:15 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Sun, 01 Sep 2013 21:58:15 +0200 Subject: semicolon at end of python's statements In-Reply-To: <52213435$0$6599$c3e8da3$5496439d@news.astraweb.com> References: <1377735506.18906.15.camel@debian> <1FETt.52607$Mw4.14965@fx15.am4> <7wob8gywds.fsf@benfinney.id.au> <52213435$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52239C57.9090506@rece.vub.ac.be> Op 31-08-13 02:09, Steven D'Aprano schreef: > On Fri, 30 Aug 2013 11:32:17 +0100, F?bio Santos wrote: > > > We really are spoiled for choice here. We can write any of these: > > # Option 1 > for spam in sequence: > if predicate(spam): > process(spam) > > > Adding a fourth option: > > for spam in sequence if predicate(spam): > process(spam) > > saves absolutely nothing except a line and an indent level, neither of > which are in short supply, and gains nothing in readability over Option 1. So what is the big difference between this situation and the following: | else: | if condition: | whatever which in python we can write: | elif condition: | whatever So either is seems this was a design mistake or a line and an indent level can be important enough to allow a combination of controls. -- Antoon Pardon From python at mrabarnett.plus.com Sun Sep 1 19:30:35 2013 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 02 Sep 2013 00:30:35 +0100 Subject: semicolon at end of python's statements In-Reply-To: <52239C57.9090506@rece.vub.ac.be> References: <1377735506.18906.15.camel@debian> <1FETt.52607$Mw4.14965@fx15.am4> <7wob8gywds.fsf@benfinney.id.au> <52213435$0$6599$c3e8da3$5496439d@news.astraweb.com> <52239C57.9090506@rece.vub.ac.be> Message-ID: <5223CE1B.4040102@mrabarnett.plus.com> On 01/09/2013 20:58, Antoon Pardon wrote: > Op 31-08-13 02:09, Steven D'Aprano schreef: >> On Fri, 30 Aug 2013 11:32:17 +0100, F?bio Santos wrote: >> > >> >> We really are spoiled for choice here. We can write any of these: >> >> # Option 1 >> for spam in sequence: >> if predicate(spam): >> process(spam) >> > >> >> Adding a fourth option: >> >> for spam in sequence if predicate(spam): >> process(spam) >> >> saves absolutely nothing except a line and an indent level, neither of >> which are in short supply, and gains nothing in readability over Option 1. > > So what is the big difference between this situation and the following: > > | else: > | if condition: > | whatever > > which in python we can write: > > | elif condition: > | whatever > > > So either is seems this was a design mistake or a line and an indent > level can be important enough to allow a combination of controls. > 'elif' is for cascading ifs: if ...: ... elif ...: ... elif ...: ... elif ...: ... else: ... Without 'elif' you would be forced to write: if ...: ... else: if ...: ... else: if ...: ... else: if ...: ... else: ... On the other hand, for...if is much less of a problem. From antoon.pardon at rece.vub.ac.be Mon Sep 2 04:29:05 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 02 Sep 2013 10:29:05 +0200 Subject: semicolon at end of python's statements In-Reply-To: <5223CE1B.4040102@mrabarnett.plus.com> References: <1377735506.18906.15.camel@debian> <1FETt.52607$Mw4.14965@fx15.am4> <7wob8gywds.fsf@benfinney.id.au> <52213435$0$6599$c3e8da3$5496439d@news.astraweb.com> <52239C57.9090506@rece.vub.ac.be> <5223CE1B.4040102@mrabarnett.plus.com> Message-ID: <52244C51.1080201@rece.vub.ac.be> Op 02-09-13 01:30, MRAB schreef: > On 01/09/2013 20:58, Antoon Pardon wrote: >> Op 31-08-13 02:09, Steven D'Aprano schreef: >>> On Fri, 30 Aug 2013 11:32:17 +0100, F?bio Santos wrote: >>> >> >>> >>> We really are spoiled for choice here. We can write any of these: >>> >>> # Option 1 >>> for spam in sequence: >>> if predicate(spam): >>> process(spam) >>> >> >>> >>> Adding a fourth option: >>> >>> for spam in sequence if predicate(spam): >>> process(spam) >>> >>> saves absolutely nothing except a line and an indent level, neither of >>> which are in short supply, and gains nothing in readability over >>> Option 1. >> >> So what is the big difference between this situation and the following: >> >> | else: >> | if condition: >> | whatever >> >> which in python we can write: >> >> | elif condition: >> | whatever >> >> >> So either is seems this was a design mistake or a line and an indent >> level can be important enough to allow a combination of controls. >> > 'elif' is for cascading ifs: > > if ...: > ... > elif ...: > ... > elif ...: > ... > elif ...: > ... > else: > ... > > Without 'elif' you would be forced to write: > > if ...: > ... > else: > if ...: > ... > else: > if ...: > ... > else: > if ...: > ... > else: > ... > > On the other hand, for...if is much less of a problem. So what is the problem with being forced to write it like this? We have just learned that there is no short supply of indent levels, so why should this bother us? The only reason this should bother us, is if we think that indent levels are a somewhat limited commodity and/or the way we view the process structure is better illustrated written the first way. But if we think those arguments carry some weight, there is no reason to only consider them in the case of an else if combination. Why should we be more concerned with cascading ifs than with cascading controls in general? Not that I expect this to change, but it illustrates why for a number of people the forced indentation can be an annoyance. All these discussions about combining controls would have been unnecessary without the enforced strict indentation. In that case we wouldn't have needed elif because we could have just written "else: if" or "else if" we wouldn't now be discussing the pro and cons of loop comprehension because we could have just layed out the code so that it illustrated our intention of a loop comprehension. -- Antoon Pardon From steve at pearwood.info Mon Sep 2 05:52:17 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 02 Sep 2013 09:52:17 GMT Subject: semicolon at end of python's statements References: <1377735506.18906.15.camel@debian> <1FETt.52607$Mw4.14965@fx15.am4> <7wob8gywds.fsf@benfinney.id.au> <52213435$0$6599$c3e8da3$5496439d@news.astraweb.com> <52239C57.9090506@rece.vub.ac.be> <5223CE1B.4040102@mrabarnett.plus.com> Message-ID: <52245fd0$0$2743$c3e8da3$76491128@news.astraweb.com> On Mon, 02 Sep 2013 10:29:05 +0200, Antoon Pardon wrote: > Why should we be more > concerned with cascading ifs than with cascading controls in general? What cascading controls? for element in seq: if filter: is not a cascading control. [...] > All these discussions > about combining controls would have been unnecessary without the > enforced strict indentation. Instead, we would have spent 100 times as much time and energy debating the One True Indentation Scheme, akin to the brace wars that went on for *years* in the C community. And still haven't completely gone. > we wouldn't now be > discussing the pro and cons of loop comprehension because we could have > just layed out the code so that it illustrated our intention of a loop > comprehension. Which the current syntax is perfectly fine at doing. -- Steven From rosuav at gmail.com Mon Sep 2 06:14:40 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 Sep 2013 20:14:40 +1000 Subject: semicolon at end of python's statements In-Reply-To: <52245fd0$0$2743$c3e8da3$76491128@news.astraweb.com> References: <1377735506.18906.15.camel@debian> <1FETt.52607$Mw4.14965@fx15.am4> <7wob8gywds.fsf@benfinney.id.au> <52213435$0$6599$c3e8da3$5496439d@news.astraweb.com> <52239C57.9090506@rece.vub.ac.be> <5223CE1B.4040102@mrabarnett.plus.com> <52245fd0$0$2743$c3e8da3$76491128@news.astraweb.com> Message-ID: On Mon, Sep 2, 2013 at 7:52 PM, Steven D'Aprano wrote: > Instead, we would have spent 100 times as much time and energy debating > the One True Indentation Scheme, akin to the brace wars that went on for > *years* in the C community. And still haven't completely gone. You mean like debating tabs vs spaces in Python code? ChrisA From antoon.pardon at rece.vub.ac.be Mon Sep 2 06:52:45 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 02 Sep 2013 12:52:45 +0200 Subject: semicolon at end of python's statements In-Reply-To: <52245fd0$0$2743$c3e8da3$76491128@news.astraweb.com> References: <1377735506.18906.15.camel@debian> <1FETt.52607$Mw4.14965@fx15.am4> <7wob8gywds.fsf@benfinney.id.au> <52213435$0$6599$c3e8da3$5496439d@news.astraweb.com> <52239C57.9090506@rece.vub.ac.be> <5223CE1B.4040102@mrabarnett.plus.com> <52245fd0$0$2743$c3e8da3$76491128@news.astraweb.com> Message-ID: <52246DFD.9000603@rece.vub.ac.be> Op 02-09-13 11:52, Steven D'Aprano schreef: > On Mon, 02 Sep 2013 10:29:05 +0200, Antoon Pardon wrote: > >> Why should we be more >> concerned with cascading ifs than with cascading controls in general? > > What cascading controls? > > for element in seq: > if filter: > > > > is not a cascading control. Why not? > [...] >> All these discussions >> about combining controls would have been unnecessary without the >> enforced strict indentation. > > Instead, we would have spent 100 times as much time and energy debating > the One True Indentation Scheme, akin to the brace wars that went on for > *years* in the C community. And still haven't completely gone. So? Indeed there are too many people looking at these things as fighting for the one true way. That is IMO part a big part of the problem. I have no problem if someone else uses a different style than I do. Python as a language tries too hard to enforce a one true way. >> we wouldn't now be >> discussing the pro and cons of loop comprehension because we could have >> just layed out the code so that it illustrated our intention of a loop >> comprehension. > > Which the current syntax is perfectly fine at doing. Then you and I differ on what perfectly fine looks like. -- Antoon Pardon From modulok at gmail.com Mon Sep 2 19:17:36 2013 From: modulok at gmail.com (Modulok) Date: Mon, 2 Sep 2013 17:17:36 -0600 Subject: semicolon at end of python's statements In-Reply-To: <52246DFD.9000603@rece.vub.ac.be> References: <1377735506.18906.15.camel@debian> <1FETt.52607$Mw4.14965@fx15.am4> <7wob8gywds.fsf@benfinney.id.au> <52213435$0$6599$c3e8da3$5496439d@news.astraweb.com> <52239C57.9090506@rece.vub.ac.be> <5223CE1B.4040102@mrabarnett.plus.com> <52245fd0$0$2743$c3e8da3$76491128@news.astraweb.com> <52246DFD.9000603@rece.vub.ac.be> Message-ID: > So? Indeed there are too many people looking at these things as fighting > for the one true way. That is IMO part a big part of the problem. I have > no problem if someone else uses a different style than I do. Python as > a language tries too hard to enforce a one true way. > > Try maintaining a non-trivial body of JavaScript, or Perl (that you didn't write) for a while. You'll soon appreciate the One True Way of thinking lol. -Modulok- -------------- next part -------------- An HTML attachment was scrubbed... URL: From roy at panix.com Mon Sep 2 19:54:06 2013 From: roy at panix.com (Roy Smith) Date: Mon, 02 Sep 2013 19:54:06 -0400 Subject: semicolon at end of python's statements References: <1377735506.18906.15.camel@debian> <1FETt.52607$Mw4.14965@fx15.am4> <7wob8gywds.fsf@benfinney.id.au> <52213435$0$6599$c3e8da3$5496439d@news.astraweb.com> <52239C57.9090506@rece.vub.ac.be> <5223CE1B.4040102@mrabarnett.plus.com> <52245fd0$0$2743$c3e8da3$76491128@news.astraweb.com> <52246DFD.9000603@rece.vub.ac.be> Message-ID: In article , Modulok wrote: > > So? Indeed there are too many people looking at these things as fighting > > for the one true way. That is IMO part a big part of the problem. I have > > no problem if someone else uses a different style than I do. Python as > > a language tries too hard to enforce a one true way. > > > > > > Try maintaining a non-trivial body of JavaScript, or Perl (that you didn't > write) for a while. You'll soon appreciate the One True Way of thinking lol. > > -Modulok- There is indeed value in One True Way. Part of the value is that everybody learns That Way and it makes it easier to understand everybody else's code. But, more than that, it saves the zillions of hours of time wasted arguing about which way is better. For example, at work, we've agreed that pep-8 is our style guide for Python. We don't follow it very closely, and we've each developed our own styles that deviate from it in specific ways, but at least we no longer have arguments about stupid things like how much whitespace to use. Mostly, we all just put up with each other's eccentricities. We all know that the only valid argument is whether some piece of code is or isn't pep-8 compliant, and if we drag out that argument, we risk having it thrown back in our own faces. I believe Reagan and Gorbachev used much the same strategy. From modulok at gmail.com Mon Sep 2 20:56:38 2013 From: modulok at gmail.com (Modulok) Date: Mon, 2 Sep 2013 18:56:38 -0600 Subject: semicolon at end of python's statements In-Reply-To: References: <1377735506.18906.15.camel@debian> <1FETt.52607$Mw4.14965@fx15.am4> <7wob8gywds.fsf@benfinney.id.au> <52213435$0$6599$c3e8da3$5496439d@news.astraweb.com> <52239C57.9090506@rece.vub.ac.be> <5223CE1B.4040102@mrabarnett.plus.com> <52245fd0$0$2743$c3e8da3$76491128@news.astraweb.com> <52246DFD.9000603@rece.vub.ac.be> Message-ID: > But, more than that, it saves the zillions of hours of > time wasted arguing about which way is better. > XD Nice. That's about the best supporting argument I've heard. -Modulok- -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Mon Sep 2 10:57:35 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 Sep 2013 14:57:35 GMT Subject: semicolon at end of python's statements References: <1377735506.18906.15.camel@debian> <1FETt.52607$Mw4.14965@fx15.am4> <7wob8gywds.fsf@benfinney.id.au> <52213435$0$6599$c3e8da3$5496439d@news.astraweb.com> <52239C57.9090506@rece.vub.ac.be> <5223CE1B.4040102@mrabarnett.plus.com> <52245fd0$0$2743$c3e8da3$76491128@news.astraweb.com> Message-ID: <5224a75f$0$6599$c3e8da3$5496439d@news.astraweb.com> On Mon, 02 Sep 2013 20:14:40 +1000, Chris Angelico wrote: > On Mon, Sep 2, 2013 at 7:52 PM, Steven D'Aprano > wrote: >> Instead, we would have spent 100 times as much time and energy debating >> the One True Indentation Scheme, akin to the brace wars that went on >> for *years* in the C community. And still haven't completely gone. > > You mean like debating tabs vs spaces in Python code? Yes, only worse. There's only two choices between tabs and spaces ("Tabs!" "No, spaces!"). With optional indentation, there has to be some sort of marker, like braces or BEGIN/END, so we have: for item in seq: { do_this() } for item in seq: { do_this() } for item in seq: { do_this(); } for item in seq: { do_this() } for item in seq: { do_this() } for item in seq: { do_this() } for item in seq: { do_this() } and so on, until your brain explodes. -- Steven From steve at pearwood.info Mon Sep 2 04:05:02 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 02 Sep 2013 08:05:02 GMT Subject: semicolon at end of python's statements References: <1377735506.18906.15.camel@debian> <1FETt.52607$Mw4.14965@fx15.am4> <7wob8gywds.fsf@benfinney.id.au> <52213435$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: <522446ae$0$2743$c3e8da3$76491128@news.astraweb.com> On Sun, 01 Sep 2013 21:58:15 +0200, Antoon Pardon wrote: > Op 31-08-13 02:09, Steven D'Aprano schreef: >> Adding a fourth option: >> >> for spam in sequence if predicate(spam): >> process(spam) >> >> saves absolutely nothing except a line and an indent level, neither of >> which are in short supply, and gains nothing in readability over Option >> 1. > > So what is the big difference between this situation and the following: > > | else: > | if condition: > | whatever > > which in python we can write: > > | elif condition: > | whatever > > > So either is seems this was a design mistake or a line and an indent > level can be important enough to allow a combination of controls. The difference is that elif is syntax for chaining potentially large numbers of else if clauses: if a: else: if b: else: if c: else: if d: else: It's not uncommon to have, say, a dozen separate elif clauses. Put that inside a method inside a class and you've got an indent of 56 spaces inside the final else block. But that's not really the problem, the real problem is that repeated nesting like this obscures the fact that it is a chain of if...if...if...if and all the if's really should be at the same indentation level. In contrast, you never need to write something like this: for item in seq: if a: if b: if c: if d: ... since that's better written as for item in seq: if a and b and c and d: So a "filtered for" only includes a single if clause. Multiple if clauses don't match the "one line or two" scenario: for item in seq: if cond: elif predicate: else: is not an option. With a single if, filtering the for loop, this is an option: # with or without the first colon for item in seq: if cond: versus: for item in seq: if cond: What's the benefit of the first version? It doesn't make it any more obvious that the for is being filtered. It doesn't keep a whole chain of if clauses together. It doesn't let you do anything that you haven't already done. It just saves an indent and a newline. The cost, on the other hand, includes the risk that people will try to do this: for item in seq: if cond: do_this() do_that() else: do_something else() which is clearly nonsense. Worse is this: for item in seq: if cond: do_this() do_that() else: do_something else() which is still nonsense but won't raise SyntaxError. It would be a Bad Thing if adding a legal else clause to a legal if clause caused a syntax error. But the only way to prevent that is to prohibit the for...if one line version in the first place. *None* of these objections apply to the list comp version of for, where the "block" consists of a single statement before the "for". So despite a superficial (very superficial) similarity between [expr for item in seq if filter] and for item in seq if filter: expr I believe that Python is right to allow the first and prohibit the second. -- Steven From antoon.pardon at rece.vub.ac.be Mon Sep 2 05:45:19 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 02 Sep 2013 11:45:19 +0200 Subject: semicolon at end of python's statements In-Reply-To: <522446ae$0$2743$c3e8da3$76491128@news.astraweb.com> References: <1377735506.18906.15.camel@debian> <1FETt.52607$Mw4.14965@fx15.am4> <7wob8gywds.fsf@benfinney.id.au> <52213435$0$6599$c3e8da3$5496439d@news.astraweb.com> <522446ae$0$2743$c3e8da3$76491128@news.astraweb.com> Message-ID: <52245E2F.4020909@rece.vub.ac.be> Op 02-09-13 10:05, Steven D'Aprano schreef: > On Sun, 01 Sep 2013 21:58:15 +0200, Antoon Pardon wrote: > >> Op 31-08-13 02:09, Steven D'Aprano schreef: > >>> Adding a fourth option: >>> >>> for spam in sequence if predicate(spam): >>> process(spam) >>> >>> saves absolutely nothing except a line and an indent level, neither of >>> which are in short supply, and gains nothing in readability over Option >>> 1. >> >> So what is the big difference between this situation and the following: >> >> | else: >> | if condition: >> | whatever >> >> which in python we can write: >> >> | elif condition: >> | whatever >> >> >> So either is seems this was a design mistake or a line and an indent >> level can be important enough to allow a combination of controls. > > > The difference is that elif is syntax for chaining potentially large > numbers of else if clauses: > > if a: > else: > if b: > else: > if c: > else: > if d: > else: > > It's not uncommon to have, say, a dozen separate elif clauses. Put that > inside a method inside a class and you've got an indent of 56 spaces > inside the final else block. But that's not really the problem, the real > problem is that repeated nesting like this obscures the fact that it is a > chain of if...if...if...if and all the if's really should be at the same > indentation level. > In contrast, you never need to write something like this: > > for item in seq: if a: if b: if c: if d: ... > > since that's better written as > > for item in seq: if a and b and c and d: > > So a "filtered for" only includes a single if clause. Multiple if clauses > don't match the "one line or two" scenario: > > for item in seq: if cond: elif predicate: else: > > is not an option. With a single if, filtering the for loop, this is an > option: > > # with or without the first colon > for item in seq: if cond: > > > versus: > > for item in seq: > if cond: > > > What's the benefit of the first version? It doesn't make it any more > obvious that the for is being filtered. It makes that just as obvious as using an elif makes it obvious we are having a chain of ifs. It is not obvious because it can be logically deduced, but is is obvious by how programmic idioms start occuring. Just as people sometime prefer | else: | if ... If they think that illustrates the decision process more clearly people could chose whether to use the combined or seperated controls depending on whether they considered the if as the filter part of an iterator or as an independ decision proces. > It doesn't keep a whole chain of > if clauses together. It doesn't let you do anything that you haven't > already done. It just saves an indent and a newline. The cost, on the > other hand, includes the risk that people will try to do this: > > for item in seq: if cond: > do_this() > do_that() > else: > do_something else() > > which is clearly nonsense. Worse is this: > > for item in seq: if cond: > do_this() > do_that() > else: > do_something else() > > which is still nonsense but won't raise SyntaxError. Why shouldn't this raise a SyntaxError? > It would be a Bad Thing if adding a legal else clause to a legal if > clause caused a syntax error. But we are not necessarily talking about an if clause, we can be talking about an iterator with a filter attached, or about a combined control. > But the only way to prevent that is to > prohibit the for...if one line version in the first place. No it isn't. > *None* of these objections apply to the list comp version of for, where > the "block" consists of a single statement before the "for". So despite a > superficial (very superficial) similarity between > > [expr for item in seq if filter] > > and > > for item in seq if filter: > expr > > I believe that Python is right to allow the first and prohibit the second. Fine, at this point I'll think we'll just have to agree to disagree. -- Antoon Pardon From fabiosantosart at gmail.com Mon Sep 2 06:42:53 2013 From: fabiosantosart at gmail.com (=?ISO-8859-1?Q?F=E1bio_Santos?=) Date: Mon, 02 Sep 2013 11:42:53 +0100 Subject: semicolon at end of python's statements In-Reply-To: <52245E2F.4020909@rece.vub.ac.be> References: <1377735506.18906.15.camel@debian> <1FETt.52607$Mw4.14965@fx15.am4> <7wob8gywds.fsf@benfinney.id.au> <52213435$0$6599$c3e8da3$5496439d@news.astraweb.com> <522446ae$0$2743$c3e8da3$76491128@news.astraweb.com> <52245E2F.4020909@rece.vub.ac.be> Message-ID: <52246BAD.9050403@gmail.com> On 09/02/2013 10:45 AM, Antoon Pardon wrote: > Op 02-09-13 10:05, Steven D'Aprano schreef: >> It doesn't keep a whole chain of >> if clauses together. It doesn't let you do anything that you haven't >> already done. It just saves an indent and a newline. The cost, on the >> other hand, includes the risk that people will try to do this: >> >> for item in seq: if cond: >> do_this() >> do_that() >> else: >> do_something else() >> >> which is clearly nonsense. Worse is this: >> >> for item in seq: if cond: >> do_this() >> do_that() >> else: >> do_something else() >> >> which is still nonsense but won't raise SyntaxError. > Why shouldn't this raise a SyntaxError? > Because it would be parsed as a valid for .. else construct. Either that or become ambiguous to the programmer, who would not be sure whether he was writing an else clause for the `if`, or for the `for`. From antoon.pardon at rece.vub.ac.be Mon Sep 2 06:58:23 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 02 Sep 2013 12:58:23 +0200 Subject: semicolon at end of python's statements In-Reply-To: <52246BAD.9050403@gmail.com> References: <1377735506.18906.15.camel@debian> <1FETt.52607$Mw4.14965@fx15.am4> <7wob8gywds.fsf@benfinney.id.au> <52213435$0$6599$c3e8da3$5496439d@news.astraweb.com> <522446ae$0$2743$c3e8da3$76491128@news.astraweb.com> <52245E2F.4020909@rece.vub.ac.be> <52246BAD.9050403@gmail.com> Message-ID: <52246F4F.7080108@rece.vub.ac.be> Op 02-09-13 12:42, F?bio Santos schreef: > On 09/02/2013 10:45 AM, Antoon Pardon wrote: >> Op 02-09-13 10:05, Steven D'Aprano schreef: >>> It doesn't keep a whole chain of >>> if clauses together. It doesn't let you do anything that you haven't >>> already done. It just saves an indent and a newline. The cost, on the >>> other hand, includes the risk that people will try to do this: >>> >>> for item in seq: if cond: >>> do_this() >>> do_that() >>> else: >>> do_something else() >>> >>> which is clearly nonsense. Worse is this: >>> >>> for item in seq: if cond: >>> do_this() >>> do_that() >>> else: >>> do_something else() >>> >>> which is still nonsense but won't raise SyntaxError. >> Why shouldn't this raise a SyntaxError? >> > Because it would be parsed as a valid for .. else construct. Either that > or become ambiguous to the programmer, who would not be sure whether he > was writing an else clause for the `if`, or for the `for`. I didn't thought about that, but in that case why should we automatically think of it as nonsense? I also don't see how this would be that ambigous. The else lines up with the for, so it seems rather obvious for which he was writing an else clause. -- Antoon Pardon From albert.visser at gmail.com Mon Sep 2 13:44:33 2013 From: albert.visser at gmail.com (albert visser) Date: Mon, 02 Sep 2013 19:44:33 +0200 Subject: semicolon at end of python's statements In-Reply-To: <52246F4F.7080108@rece.vub.ac.be> References: <1377735506.18906.15.camel@debian> <1FETt.52607$Mw4.14965@fx15.am4> <7wob8gywds.fsf@benfinney.id.au> <52213435$0$6599$c3e8da3$5496439d@news.astraweb.com> <522446ae$0$2743$c3e8da3$76491128@news.astraweb.com> <52245E2F.4020909@rece.vub.ac.be> <52246BAD.9050403@gmail.com> <52246F4F.7080108@rece.vub.ac.be> Message-ID: On Mon, 02 Sep 2013 12:58:23 +0200, Antoon Pardon wrote: > Op 02-09-13 12:42, F?bio Santos schreef: >> On 09/02/2013 10:45 AM, Antoon Pardon wrote: >>> Op 02-09-13 10:05, Steven D'Aprano schreef: [...] >>>> >>>> for item in seq: if cond: >>>> do_this() >>>> do_that() >>>> else: >>>> do_something else() >>>> >>>> which is still nonsense but won't raise SyntaxError. >>> Why shouldn't this raise a SyntaxError? >>> >> Because it would be parsed as a valid for .. else construct. Either that >> or become ambiguous to the programmer, who would not be sure whether he >> was writing an else clause for the `if`, or for the `for`. > [...] > > I also don't see how this would be that ambigous. The else > lines up with the for, so it seems rather obvious for which > he was writing an else clause. > My first association would be with the for, but someone could also be thinking it's referring to the if on the same line, because there wouldn't be any other way to write it (besides nesting the if). I wouldn't like this syntax anyway, two colons and all. When I first saw the idea of a nested for .. if construct the thing that came to mind was another nesting, namely that of context managers. While I don't mind using with : with : do_stuff I like being able to do e.g. with open('some_file') as _in, open('another_file', 'w') as _out: because it makes it obvious that the context managers are related. Expressing that the for and the if are related also appeals to me. Another parallel might be slicing, where you can specify not only a start and an end value, but also an interval (which could be seen as a kind of filtering condition). I think that if you really want to show the "filtered for" as a somewhat different concept than a for that just happens to have an if in its suite, that should be made visible. Coming back to my first association mentioned above, why not use a comma? for in , : (come to think of it, it has the added bonus that you won't get ambiguity what an else might be about). Somehow this makes sense to me. But then, I also like 'x = y if else z'. Moreover, I'm Dutch (...) Albert Visser -- Using Opera's mail client: http://www.opera.com/mail/ From roy at panix.com Mon Sep 2 13:53:48 2013 From: roy at panix.com (Roy Smith) Date: Mon, 02 Sep 2013 13:53:48 -0400 Subject: semicolon at end of python's statements References: <1377735506.18906.15.camel@debian> <1FETt.52607$Mw4.14965@fx15.am4> <7wob8gywds.fsf@benfinney.id.au> <52213435$0$6599$c3e8da3$5496439d@news.astraweb.com> <522446ae$0$2743$c3e8da3$76491128@news.astraweb.com> <52245E2F.4020909@rece.vub.ac.be> <52246BAD.9050403@gmail.com> <52246F4F.7080108@rece.vub.ac.be> Message-ID: In article , "albert visser" wrote: > I like being able to do e.g. > > with open('some_file') as _in, open('another_file', 'w') as _out: It would be nice if you could write that as: with open('some_file'), open('another_file, 'w') as _in, _out: From neilc at norwich.edu Tue Sep 3 13:15:36 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 3 Sep 2013 17:15:36 GMT Subject: semicolon at end of python's statements References: <1377735506.18906.15.camel@debian> <1FETt.52607$Mw4.14965@fx15.am4> <7wob8gywds.fsf@benfinney.id.au> <52213435$0$6599$c3e8da3$5496439d@news.astraweb.com> <522446ae$0$2743$c3e8da3$76491128@news.astraweb.com> <52245E2F.4020909@rece.vub.ac.be> <52246BAD.9050403@gmail.com> <52246F4F.7080108@rece.vub.ac.be> Message-ID: On 2013-09-02, Roy Smith wrote: > In article , > "albert visser" wrote: > >> I like being able to do e.g. >> >> with open('some_file') as _in, open('another_file', 'w') as _out: > > It would be nice if you could write that as: > > with open('some_file'), open('another_file, 'w') as _in, _out: 3.2 and above provide contextlib.ExitStack, which I just now learned about. with contextlib.ExitStack() as stack: _in = stack.enter_context(open('some_file')) _out = stack.enter_context(open('another_file', 'w')) It ain't beautiful, but it unfolds the nesting and gets rid of the with statement's line-wrap problems. -- Neil Cerutti From neilc at norwich.edu Tue Sep 3 16:00:47 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 3 Sep 2013 20:00:47 GMT Subject: semicolon at end of python's statements References: <1377735506.18906.15.camel@debian> <1FETt.52607$Mw4.14965@fx15.am4> <7wob8gywds.fsf@benfinney.id.au> <52213435$0$6599$c3e8da3$5496439d@news.astraweb.com> <522446ae$0$2743$c3e8da3$76491128@news.astraweb.com> <52245E2F.4020909@rece.vub.ac.be> <52246BAD.9050403@gmail.com> <52246F4F.7080108@rece.vub.ac.be> Message-ID: On 2013-09-03, Neil Cerutti wrote: > 3.2 and above provide contextlib.ExitStack, which I just now > learned about. > > with contextlib.ExitStack() as stack: > _in = stack.enter_context(open('some_file')) > _out = stack.enter_context(open('another_file', 'w')) > > It ain't beautiful, but it unfolds the nesting and gets rid of > the with statement's line-wrap problems. It just occurred to me that in most of my use cases ExitStack saves me from coming up with a name for the file objects at all, since they are needed only to make csv objects. Here's a csv file transformer pattern: import contextlib import csv import transform with contextlib.ExitStack() as stack: reader = csv.DictReader(stack.enter_context(open('some_file', newline=''))) writer = csv.DictWriter( stack.enter_context(open('another_file', 'w', newline='')), fieldnames=reader.fieldnames) writer.writeheader() for record in reader: writer.writerow(transform.transform(record)) Too bad it's so dense looking. -- Neil Cerutti From antoon.pardon at rece.vub.ac.be Tue Sep 3 03:32:41 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 03 Sep 2013 09:32:41 +0200 Subject: semicolon at end of python's statements In-Reply-To: <52258DCC.5060507@rece.vub.ac.be> References: <52258DCC.5060507@rece.vub.ac.be> Message-ID: <52259099.1000404@rece.vub.ac.be> Op 03-09-13 01:17, Modulok schreef: > > So? Indeed there are too many people looking at these things as fighting > for the one true way. That is IMO part a big part of the problem. I have > no problem if someone else uses a different style than I do. Python as > a language tries too hard to enforce a one true way. > > Try maintaining a non-trivial body of JavaScript, or Perl (that you didn't > write) for a while. You'll soon appreciate the One True Way of thinking lol. My impression is that everyone appreciates the One True Way but only because they identify their own way as the One True Way. And sure it can be a good thing to enforce a One True Way for a specific project or for all company code, but there is no need that all projects would need the same One True Way. -- Antoon Pardon From duncan.booth at invalid.invalid Thu Sep 5 07:33:50 2013 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 5 Sep 2013 11:33:50 GMT Subject: semicolon at end of python's statements References: <1377735506.18906.15.camel@debian> Message-ID: Chris Angelico wrote: > On Thu, Aug 29, 2013 at 10:18 AM, Mohsen Pahlevanzadeh > wrote: >> Dear all, >> >> I'm C++ programmer and unfortunately put semicolon at end of my >> statements in python. >> >> Quesion: >> What's really defferences between putting semicolon and don't put? > > Very little. Putting the semicolon makes you look like a C programmer > who's new to Python; omitting it makes you look like you actually > understand Python :) > > As a C and C++ programmer myself, I know where you're coming from, but > putting semicolons at the ends of Python statements is as useless as > putting ((((lots of (((irritating (((superfluous > (((parentheses))))))))))))) in your C++ code. The parser won't mind, > but subsequent programmers will wonder what these unnecessary > syntactic elements are for. > > ChrisA > Someone I knew actually used these definitions when writing C in a Pascalish, Algol68ish style (if I remembered them correctly): #define IF if((( #define AND ))&&(( #define OR )||( #define THEN ))){ #define ELSE }else{ #define FI } -- Duncan Booth http://kupuguy.blogspot.com From rosuav at gmail.com Thu Sep 5 08:02:51 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 Sep 2013 22:02:51 +1000 Subject: semicolon at end of python's statements In-Reply-To: References: <1377735506.18906.15.camel@debian> Message-ID: On Thu, Sep 5, 2013 at 9:33 PM, Duncan Booth wrote: > Someone I knew actually used these definitions when writing C in a Pascalish, Algol68ish > style (if I remembered them correctly): > > #define IF if((( > #define AND ))&&(( > #define OR )||( > #define THEN ))){ > #define ELSE }else{ > #define FI } Because s/he thought it made for better code, or as a joke? Usually I see this sort of thing as the latter... ChrisA From jeremy at jeremysanders.net Thu Sep 5 10:05:58 2013 From: jeremy at jeremysanders.net (Jeremy Sanders) Date: Thu, 05 Sep 2013 16:05:58 +0200 Subject: semicolon at end of python's statements References: <1377735506.18906.15.camel@debian> Message-ID: Chris Angelico wrote: > Because s/he thought it made for better code, or as a joke? Usually I > see this sort of thing as the latter... http://oldhome.schmorp.de/marc/bournegol.html http://utcc.utoronto.ca/~cks/space/blog/programming/BourneGol Jeremy From rosuav at gmail.com Thu Sep 5 10:13:36 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Sep 2013 00:13:36 +1000 Subject: semicolon at end of python's statements In-Reply-To: References: <1377735506.18906.15.camel@debian> Message-ID: On Fri, Sep 6, 2013 at 12:05 AM, Jeremy Sanders wrote: > Chris Angelico wrote: > >> Because s/he thought it made for better code, or as a joke? Usually I >> see this sort of thing as the latter... > > http://oldhome.schmorp.de/marc/bournegol.html > http://utcc.utoronto.ca/~cks/space/blog/programming/BourneGol Yep, that's some impressive code right there! ChrisA From duncan.booth at invalid.invalid Thu Sep 5 11:15:07 2013 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 5 Sep 2013 15:15:07 GMT Subject: semicolon at end of python's statements References: <1377735506.18906.15.camel@debian> Message-ID: Chris Angelico wrote: > On Fri, Sep 6, 2013 at 12:05 AM, Jeremy Sanders > wrote: >> Chris Angelico wrote: >> >>> Because s/he thought it made for better code, or as a joke? Usually I >>> see this sort of thing as the latter... It was intended for clearer code, which is true if you don't like curly braces, and who does round here? >> >> http://oldhome.schmorp.de/marc/bournegol.html >> http://utcc.utoronto.ca/~cks/space/blog/programming/BourneGol > > Yep, that's some impressive code right there! > > ChrisA > That brings back memories all right, but its not as good as the version I remember as it doesn't 'fix' the logical operator priorities. -- Duncan Booth http://kupuguy.blogspot.com From invalid at invalid.invalid Thu Sep 5 10:04:15 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 5 Sep 2013 14:04:15 +0000 (UTC) Subject: semicolon at end of python's statements References: <1377735506.18906.15.camel@debian> Message-ID: On 2013-09-05, Duncan Booth wrote: > Someone I knew actually used these definitions when writing C in a > Pascalish, Algol68ish style (if I remembered them correctly): > > #define IF if((( > #define AND ))&&(( > #define OR )||( > #define THEN ))){ > #define ELSE }else{ > #define FI } Yep, I once knew somebody who used a set of macros like that to make C programs look as much like some dialect of BASIC as possible. He also wrote his letters/memos in Lotus 1,2,3... -- Grant Edwards grant.b.edwards Yow! I want to mail a at bronzed artichoke to gmail.com Nicaragua! From james.harris.1 at gmail.com Wed Sep 4 07:41:06 2013 From: james.harris.1 at gmail.com (James Harris) Date: Wed, 4 Sep 2013 12:41:06 +0100 Subject: Python TUI that will work on DOS/Windows and Unix/Linux References: Message-ID: "James Harris" wrote in message news:kvmvpg$g96$1 at dont-email.me... > Am looking for a TUI (textual user interface) mechanism to allow a Python > program to create and update a display in text mode. For example, if a > command prompt was sized 80x25 it would be made up of 80 x 25 = 2000 > characters. The Python program would need to be able to write to any of > those 2000 characters at any time though in practice the display would > normally be arranged by dividing it up into non-overlapping rectangular > regions. > > I have seen that there are various libraries: urwid, newt, console, dialog > etc. But they seem to be either for Unix or for DOS, not for both. I am > looking for a library that will run under either. In case anyone else is following this, people have emailed me directly suggesting ncurses, pdcurses and these: Pygcurse (http://inventwithpython.com/pygcurse/) UniCurses (http://sourceforge.net/projects/pyunicurses/) Naturally, all of these are centred on curses. I have been reading up on it and must say that the whole curses approach seems rather antiquated. I appreciate the suggestions and they may be what I need to do but from what I have seen of curses it was designed principally to provide common ways to control cursor-based terminals. That was a-la-mode in the days when we had terminals with different cursor control strings and I remember programming VT100 and VT52 monitors or terminals like them. But now it seems cumbersome. I haven't thought too much about it so this is not a design proposal but it might be better to divide a display up into non-overlapping windows and treat each one separately. Writes to one would not be able to affect the others. A given window could allow writes to fixed locations or could behave as a glass teletype, writing to the bottom of the window and scrolling as needed, or could behave as a viewing port into a data structure. Something like that may be more useful to a programmer even if it has to use curses underneath because that's all that the OS provides. James From j.j.molenaar at gmail.com Tue Sep 10 18:50:27 2013 From: j.j.molenaar at gmail.com (Joost Molenaar) Date: Wed, 11 Sep 2013 00:50:27 +0200 Subject: Python TUI that will work on DOS/Windows and Unix/Linux In-Reply-To: References: Message-ID: Have you looked at Blessings? I never tried it, but the API seems much cleaner than Curses. https://pypi.python.org/pypi/blessings/ -- Joost Molenaar -------------- next part -------------- An HTML attachment was scrubbed... URL: From torriem at gmail.com Tue Sep 10 20:06:34 2013 From: torriem at gmail.com (Michael Torrie) Date: Tue, 10 Sep 2013 18:06:34 -0600 Subject: Python TUI that will work on DOS/Windows and Unix/Linux In-Reply-To: References: Message-ID: <522FB40A.4030306@gmail.com> On 09/04/2013 05:41 AM, James Harris wrote: > Naturally, all of these are centred on curses. I have been reading up on it > and must say that the whole curses approach seems rather antiquated. I > appreciate the suggestions and they may be what I need to do but from what I > have seen of curses it was designed principally to provide common ways to > control cursor-based terminals. That was a-la-mode in the days when we had > terminals with different cursor control strings and I remember programming > VT100 and VT52 monitors or terminals like them. But now it seems cumbersome. Well it's the same problem you're trying to solve today. You've got a text console with a cursor you can move around and print out text. Besides with any modern operation system you can't write directly to the screen anyway, like we used to back in the DOS days when we poked directly into video memory. > I haven't thought too much about it so this is not a design proposal but it > might be better to divide a display up into non-overlapping windows and > treat each one separately. Writes to one would not be able to affect the > others. A given window could allow writes to fixed locations or could behave > as a glass teletype, writing to the bottom of the window and scrolling as > needed, or could behave as a viewing port into a data structure. Something > like that may be more useful to a programmer even if it has to use curses > underneath because that's all that the OS provides. A toolkit (that's old, arguably), that might help you is TVision, a port of the old Turbo Vision library that formed the foundation for Borland's old DOS IDEs back in the day (check wikipedia). And it looked quite beautiful back then, actually. There is a Python binding for it here: https://pypi.python.org/pypi/PyTVision The original C++ is here: http://tvision.sourceforge.net/ TVision does run on DOS, Windows console, and of course Unix, though you'd need the appropriate shared library. Or you could write your own, based on top of something like curses. From james.harris.1 at gmail.com Wed Sep 11 12:18:34 2013 From: james.harris.1 at gmail.com (James Harris) Date: Wed, 11 Sep 2013 17:18:34 +0100 Subject: Python TUI that will work on DOS/Windows and Unix/Linux References: Message-ID: "Michael Torrie" wrote in message news:mailman.229.1378858009.5461.python-list at python.org... ... > A toolkit (that's old, arguably), that might help you is TVision, a port > of the old Turbo Vision library that formed the foundation for Borland's > old DOS IDEs back in the day (check wikipedia). And it looked quite > beautiful back then, actually. There is a Python binding for it here: > > https://pypi.python.org/pypi/PyTVision That looks very good. For the record, I have been emailed about npyscreen and urwid. And I have found a hex editor with the kind of interface I had in mind. Here are some links for anyone else who is interested. http://www.sigala.it/sergio/tvision/images.html http://www.npcole.com/npyscreen/ http://excess.org/urwid/examples.html http://www.hexedit.com/hex-edit-shots.htm James From steve+comp.lang.python at pearwood.info Sun Sep 1 00:29:16 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Sep 2013 04:29:16 GMT Subject: Best practice for generalizing and documenting each method's behaviour References: Message-ID: <5222c29b$0$6599$c3e8da3$5496439d@news.astraweb.com> On Fri, 30 Aug 2013 11:04:28 -0700, niubao56 wrote: > I'm starting a small project coding in Python as I learn the ropes. As > the project grows bigger, there are more and more overlapping and even > redundant methods. For example, several classes have a > checkAndClean_obj_state() method. If just one or two such classes, it is > easy to analyze the behaviour of them and design the optimal interaction > for all objects. However, when there are many of such classes, exactly > at what point to invoke check and clean behaviour becomes a little > blurred. There is a desperate need for generalizing and documenting the > behaviour of each such class, preferably in a flowchart. I'm currently > doing the flowchart manually but the job becomes a bit overwhelming. If you are suffering from UML burnout in a *small* project, as you say you are working on, then I suspect your program design may be suffering from excessive use of classes and Java-itis. Ravioli code is just as bad as spaghetti code. What do you consider "small"? As far as I am concerned, if it is not *absolutely obvious* at what point to invoke check and clean behaviour, then the chances are very high that this checkAndClean_obj_state method either does too much, or what it does is poorly thought out. For example: * Why do you not check and clean the object at creation time? * Why does one method do both "check" and "clean"? * Once it is checked, how is it possible that it becomes unchecked? * And similarly for cleaned? * Is your code controlling a nuclear reactor? If not, then maybe you don't actually have to call checkAndClean_obj_state before *every* operation, just call it once at creation time and let the chips fall where they may. The Python philosophy is that we're all adults here, and you can't stop somebody from shooting themselves in the foot. As for your desperate need to generalise the behaviour of each class, don't fall prey to the temptation to over-generalization. Every time you think of generalizing something, say to yourself "YAGNI" (You Ain't Gonna Need It). You must be your own harshest critic, and demand real benefit before generalizing a class, not just "it might be useful some day". You can always generalize and refactor next month. Regarding documentation, I never find writing documentation a problem, because I nearly always write the documentation *before* the code. How else do I know what the code is supposed to do if I haven't written it down first? I cannot tell you how many times I've discarded what seemed like a good API in my head, because *writing it down* showed me that it actually sucked. > I wonder what Python pros are using for analyzing and documenting > classes/functions behaviours and interactions? Is UML the only way? > Personally I found UML is a bit overkill for a one person project, but > I'm not sure if it is the right direction. I'd appreciate any insight. > Many thanks. http://drpaulcarter.blogspot.com.au/2009/03/uml-considered-harmful.html http://c2.com/cgi/wiki?UmlConsideredHarmful And the perspective of a TDD/XP zealot: http://c2.com/cgi/wiki?UmlDoesntWorkForDesign Personally, I like English. I prefer to document my code in English, not jargon. UML is a language, but it is a jargon language, and while I'm sure that some people like it, I do not. I can never remember what all the dots and circles and arrows mean. If I was working on a giant project with 80 other people and millions of lines of code, perhaps it would be worth learning UML for parts of the design. But for a one-man project with only thousands of lines of code? I doubt it. -- Steven From nikos.gr33k at gmail.com Sun Sep 1 02:50:23 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Sat, 31 Aug 2013 23:50:23 -0700 (PDT) Subject: UnicodeDecodeError issue In-Reply-To: References: Message-ID: ?? ???????, 31 ????????? 2013 9:41:27 ?.?. UTC+3, ? ??????? Ferrous Cranus ??????: > Suddenly my webiste superhost.gr running my main python script presents > > me with this error: > > > > Code: > > UnicodeDecodeError('utf-8', b'\xb6\xe3\xed\xf9\xf3\xf4\xef > > \xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2', 0, 1, > > 'invalid start byte') > > > > > > Does anyone know what this means? > > > > > > -- > > Webhost Good morning Steven, Ye i'm aware that i need to define variables before i try to make use of them. I have study all of your examples and then re-view my code and i can *assure* you that the line statement that tied to set the 'host' variable is very early at the top of the script(of course after imports), and the cur.execute comes after. The problem here is not what you say, that i try to drink k a coffee before actually making one first but rather than i cannot drink the coffee although i know *i have tried* to make one first. i will upload the code for you to prove my sayings at pastebin. http://pastebin.com/J97guApQ From rosuav at gmail.com Sun Sep 1 03:12:45 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 1 Sep 2013 17:12:45 +1000 Subject: UnicodeDecodeError issue In-Reply-To: References: Message-ID: On Sun, Sep 1, 2013 at 4:50 PM, Ferrous Cranus wrote: > Ye i'm aware that i need to define variables before i try to make use of them. > I have study all of your examples and then re-view my code and i can *assure* you that the line statement that tied to set the 'host' variable is very early at the top of the script(of course after imports), and the cur.execute comes after. > > The problem here is not what you say, that i try to drink k a coffee before actually making one first but rather than i cannot drink the coffee although i know *i have tried* to make one first. > > > i will upload the code for you to prove my sayings at pastebin. > > http://pastebin.com/J97guApQ You're setting host inside a try/except block. Are you getting exceptions that prevent it from being set, perhaps? Also... do you seriously (a) block access if no Referer: header, and (b) permit that access anyway if the user has a non-blank cookie named 'admin'? Seriously?? ChrisA From nikos at superhost.gr Sun Sep 1 03:23:52 2013 From: nikos at superhost.gr (Ferrous Cranus) Date: Sun, 01 Sep 2013 10:23:52 +0300 Subject: UnicodeDecodeError issue In-Reply-To: References: Message-ID: ???? 1/9/2013 10:12 ??, ?/? Chris Angelico ??????: > On Sun, Sep 1, 2013 at 4:50 PM, Ferrous Cranus wrote: >> Ye i'm aware that i need to define variables before i try to make use of them. >> I have study all of your examples and then re-view my code and i can *assure* you that the line statement that tied to set the 'host' variable is very early at the top of the script(of course after imports), and the cur.execute comes after. >> >> The problem here is not what you say, that i try to drink k a coffee before actually making one first but rather than i cannot drink the coffee although i know *i have tried* to make one first. >> >> >> i will upload the code for you to prove my sayings at pastebin. >> >> http://pastebin.com/J97guApQ > > You're setting host inside a try/except block. Are you getting > exceptions that prevent it from being set, perhaps? > > Also... do you seriously (a) block access if no Referer: header, and > (b) permit that access anyway if the user has a non-blank cookie named > 'admin'? Seriously?? > > ChrisA > I have checked th output of the erro log a tthe very moment that files.py tris to run and i receive this: [Sun Sep 01 07:17:52 2013] [error] [client 108.162.231.113] ValueError: underlying buffer has been detached, referer: http://superhost.gr/ [Sun Sep 01 07:17:52 2013] [error] [client 108.162.231.113] , referer: http://superhost.gr/ [Sun Sep 01 07:17:52 2013] [error] [client 108.162.231.113] Original exception was:, referer: http://superhost.gr/ [Sun Sep 01 07:17:52 2013] [error] [client 108.162.231.113] Traceback (most recent call last):, referer: http://superhost.gr/ [Sun Sep 01 07:17:52 2013] [error] [client 108.162.231.113] File "/home/nikos/public_html/cgi-bin/files.py", line 135, in , referer: http://superhost.gr/ [Sun Sep 01 07:17:52 2013] [error] [client 108.162.231.113] cur.execute('''INSERT INTO files (url, host, city, lastvisit) VALUES (%s, %s, %s, %s)''', (filename, host, city, lastvisit) ), referer: http://superhost.gr/ [Sun Sep 01 07:17:52 2013] [error] [client 108.162.231.113] NameError: name 'host' is not defined, referer: http://superhost.gr/ Let alone that i when i try to set the 'host' variable i get this line at my '/tmp/err.out' nikos at superhost.gr [~]# cat /tmp/err.out UnicodeDecodeError('utf-8', b'\xb6\xe3\xed\xf9\xf3\xf4\xef \xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2', 0, 1, 'invalid start byte') -- Webhost From rosuav at gmail.com Sun Sep 1 03:28:20 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 1 Sep 2013 17:28:20 +1000 Subject: UnicodeDecodeError issue In-Reply-To: References: Message-ID: On Sun, Sep 1, 2013 at 5:23 PM, Ferrous Cranus wrote: > Let alone that i when i try to set the 'host' variable i get this line at my > '/tmp/err.out' > > > nikos at superhost.gr [~]# cat /tmp/err.out > > UnicodeDecodeError('utf-8', b'\xb6\xe3\xed\xf9\xf3\xf4\xef > \xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2', 0, 1, > 'invalid start byte') So host isn't being set because of this error, which you're blithely carrying on after and assuming that things have happened. Solve this problem, only then move on. Otherwise you WILL confuse yourself further. ChrisA From davea at davea.name Sun Sep 1 06:35:07 2013 From: davea at davea.name (Dave Angel) Date: Sun, 1 Sep 2013 10:35:07 +0000 (UTC) Subject: UnicodeDecodeError issue References: Message-ID: On 1/9/2013 03:23, Ferrous Cranus wrote: > ???? 1/9/2013 10:12 ??, ?/? Chris Angelico ??????: >> On Sun, Sep 1, 2013 at 4:50 PM, Ferrous Cranus wrote: >>> Ye i'm aware that i need to define variables before i try to make use of them. >>> I have study all of your examples and then re-view my code and i can *assure* you that the line statement that tied to set the 'host' variable is very early at the top of the script(of course after imports), and the cur.execute comes after. >>> >>> The problem here is not what you say, that i try to drink k a coffee before actually making one first but rather than i cannot drink the coffee although i know *i have tried* to make one first. >>> >>> >>> i will upload the code for you to prove my sayings at pastebin. >>> >>> http://pastebin.com/J97guApQ >> >> You're setting host inside a try/except block. Are you getting >> exceptions that prevent it from being set, perhaps? >> > > Let alone that i when i try to set the 'host' variable i get this line > at my '/tmp/err.out' > > > nikos at superhost.gr [~]# cat /tmp/err.out > UnicodeDecodeError('utf-8', b'\xb6\xe3\xed\xf9\xf3\xf4\xef > \xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2', 0, 1, > 'invalid start byte') > Let's examine the relevant code from your pastebin above: try: gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') city = gi.time_zone_by_addr( os.environ['REMOTE_ADDR'] ) or gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or socket.gethostbyaddr( os.environ['HTTP_CF_CONNECTING_IP'] )[0] or "Proxy Detected" except Exception as e: print( repr(e), file=open( '/tmp/err.out', 'w' ) ) Presumably you do realize that any exception on any of the three lines will skip the remainder, and print that line to the /tmp/err.out file? And that if any exception occurs, it'll be before 'host' is initialized at all? Possibly before 'city' is initialized, or even 'gi' ? So there's no reason yet to assume that somehow setting the 'host' variable triggers anything. When in doubt, consider including only one line in any given try block. But let's try simpler changes. Your file mode is 'w' which will wipe out anything written earlier. Yet if the exception does not happen, the file will still contain error(s) from some earlier run. You should open (and truncate) the file before the first use, then use the same handle in each exception at which you want to record any information. Further, you ought to put more into the file than just the repr(e) value. For starters, the Traceback would be nice. If I were doing it, I'd be printing repr(sys.exc_info()) to that file. I'd also have some kind of label, so that once I had more than one of these in the code, I'd have an easyt way to tell which was which. This is my first crack at it (untested): errout = open("/tmp/err.out", "w") #opens and truncates the error output file try: gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') city = gi.time_zone_by_addr( os.environ['REMOTE_ADDR'] ) or gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) host =socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or socket.gethostbyaddr( os.environ['HTTP_CF_CONNECTING_IP'] )[0] or "Proxy Detected" except Exception as e: print( "Xyzzy exception-", repr(sys.exc_info()), file=errout) errout.flush() Note that I haven't had to use exc_info() in my own code, so I'm sure it could be formatted prettier. But right now, you need to stop throwing away useful information. -- DaveA From rosuav at gmail.com Sun Sep 1 06:51:10 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 1 Sep 2013 20:51:10 +1000 Subject: UnicodeDecodeError issue In-Reply-To: References: Message-ID: On Sun, Sep 1, 2013 at 8:35 PM, Dave Angel wrote: > Your file mode is 'w' which will wipe out anything written earlier. Yet > if the exception does not happen, the file will still contain error(s) > from some earlier run. You should open (and truncate) the file before > the first use, then use the same handle in each exception at which you > want to record any information. Hmm, I'd go the other way, and append to the file every time there's an error - otherwise, one successful page load will wipe out the error from a previous one. But I agree that the inconsistency is not helping him. ChrisA From nikos at superhost.gr Sun Sep 1 09:59:35 2013 From: nikos at superhost.gr (Ferrous Cranus) Date: Sun, 01 Sep 2013 16:59:35 +0300 Subject: UnicodeDecodeError issue In-Reply-To: References: Message-ID: ???? 1/9/2013 1:35 ??, ?/? Dave Angel ??????: > This is my first crack at it (untested): > > errout = open("/tmp/err.out", "w") #opens and truncates the error > output file > try: > gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') > city = gi.time_zone_by_addr( os.environ['REMOTE_ADDR'] ) or > gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) > host =socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or > socket.gethostbyaddr( os.environ['HTTP_CF_CONNECTING_IP'] )[0] or > "Proxy Detected" > except Exception as e: > print( "Xyzzy exception-", repr(sys.exc_info()), file=errout) > errout.flush() > > > Note that I haven't had to use exc_info() in my own code, so I'm sure it > could be formatted prettier. But right now, you need to stop throwing > away useful information. First of all thank you for your detailed information Dave. I have tried all you said, the above example you provided me, but i'm afraid even with your approach which should have given more error specific information the output of the err file remains. nikos at superhost.gr [~]# cat /tmp/err.out UnicodeDecodeError('utf-8', b'\xb6\xe3\xed\xf9\xf3\xf4\xef \xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2', 0, 1, 'invalid start byte') -- Webhost From davea at davea.name Sun Sep 1 11:40:10 2013 From: davea at davea.name (Dave Angel) Date: Sun, 1 Sep 2013 15:40:10 +0000 (UTC) Subject: UnicodeDecodeError issue References: Message-ID: On 1/9/2013 09:59, Ferrous Cranus wrote: > ???? 1/9/2013 1:35 ??, ?/? Dave Angel ??????: >> This is my first crack at it (untested): >> >> errout = open("/tmp/err.out", "w") #opens and truncates the error >> output file >> try: >> gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') >> city = gi.time_zone_by_addr( os.environ['REMOTE_ADDR'] ) or >> gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) >> host =socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or >> socket.gethostbyaddr( os.environ['HTTP_CF_CONNECTING_IP'] )[0] or >> "Proxy Detected" >> except Exception as e: >> print( "Xyzzy exception-", repr(sys.exc_info()), file=errout) >> errout.flush() >> >> >> Note that I haven't had to use exc_info() in my own code, so I'm sure it >> could be formatted prettier. But right now, you need to stop throwing >> away useful information. > > First of all thank you for your detailed information Dave. > I have tried all you said, the above example you provided me, but i'm > afraid even with your approach which should have given more error > specific information the output of the err file remains. > > > nikos at superhost.gr [~]# cat /tmp/err.out > UnicodeDecodeError('utf-8', b'\xb6\xe3\xed\xf9\xf3\xf4\xef > \xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2', 0, 1, > 'invalid start byte') > > > See my other response. The above file did NOT result from running the code above. It is missing the "Xyzzy" label. -- Signature file not found From steve+comp.lang.python at pearwood.info Sun Sep 1 04:35:12 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Sep 2013 08:35:12 GMT Subject: UnicodeDecodeError issue References: Message-ID: <5222fc40$0$6599$c3e8da3$5496439d@news.astraweb.com> On Sat, 31 Aug 2013 23:50:23 -0700, Ferrous Cranus wrote: > ?? ???????, 31 ????????? 2013 9:41:27 ?.?. UTC+3, ? ??????? Ferrous > Cranus ??????: >> Suddenly my webiste superhost.gr running my main python script presents >> >> me with this error: >> >> >> >> Code: >> >> UnicodeDecodeError('utf-8', b'\xb6\xe3\xed\xf9\xf3\xf4\xef >> >> \xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2', 0, 1, >> >> 'invalid start byte') >> >> >> >> >> >> Does anyone know what this means? >> >> >> >> >> >> -- >> >> Webhost > > Good morning Steven, > > Ye i'm aware that i need to define variables before i try to make use of > them. I have study all of your examples and then re-view my code and i > can *assure* you that the line statement that tied to set the 'host' > variable is very early at the top of the script(of course after > imports), and the cur.execute comes after. > > The problem here is not what you say, that i try to drink k a coffee > before actually making one first but rather than i cannot drink the > coffee although i know *i have tried* to make one first. > > > i will upload the code for you to prove my sayings at pastebin. > > http://pastebin.com/J97guApQ You are mistaken. In line 20-25, you have this: try: gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') city = gi.time_zone_by_addr( os.environ['REMOTE_ADDR'] ) or gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or socket.gethostbyaddr( os.environ['HTTP_CF_CONNECTING_IP'] )[0] or "Proxy Detected" except Exception as e: print( repr(e), file=open( '/tmp/err.out', 'w' ) ) An error occurs inside that block, *before* host gets set. Who knows what the error is? You have access to the err.out file, but apparently you aren't reading it to find out. Then, 110 lines later, at line 135, you try to access the value of "host" that never got set. Your job is to read the error in /tmp/err.out, see what is failing, and fix it. -- Steven From nikos at superhost.gr Sun Sep 1 10:08:19 2013 From: nikos at superhost.gr (Ferrous Cranus) Date: Sun, 01 Sep 2013 17:08:19 +0300 Subject: UnicodeDecodeError issue In-Reply-To: <5222fc40$0$6599$c3e8da3$5496439d@news.astraweb.com> References: <5222fc40$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: ???? 1/9/2013 11:35 ??, ?/? Steven D'Aprano ??????: > On Sat, 31 Aug 2013 23:50:23 -0700, Ferrous Cranus wrote: > >> ?? ???????, 31 ????????? 2013 9:41:27 ?.?. UTC+3, ? ??????? Ferrous >> Cranus ??????: >>> Suddenly my webiste superhost.gr running my main python script presents >>> >>> me with this error: >>> >>> >>> >>> Code: >>> >>> UnicodeDecodeError('utf-8', b'\xb6\xe3\xed\xf9\xf3\xf4\xef >>> >>> \xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2', 0, 1, >>> >>> 'invalid start byte') >>> >>> >>> >>> >>> >>> Does anyone know what this means? >>> >>> >>> >>> >>> >>> -- >>> >>> Webhost >> >> Good morning Steven, >> >> Ye i'm aware that i need to define variables before i try to make use of >> them. I have study all of your examples and then re-view my code and i >> can *assure* you that the line statement that tied to set the 'host' >> variable is very early at the top of the script(of course after >> imports), and the cur.execute comes after. >> >> The problem here is not what you say, that i try to drink k a coffee >> before actually making one first but rather than i cannot drink the >> coffee although i know *i have tried* to make one first. >> >> >> i will upload the code for you to prove my sayings at pastebin. >> >> http://pastebin.com/J97guApQ > > > You are mistaken. In line 20-25, you have this: > > try: > gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') > city = gi.time_zone_by_addr( os.environ['REMOTE_ADDR'] ) or > gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) > host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or > socket.gethostbyaddr( os.environ['HTTP_CF_CONNECTING_IP'] )[0] > or "Proxy Detected" > except Exception as e: > print( repr(e), file=open( '/tmp/err.out', 'w' ) ) > > > An error occurs inside that block, *before* host gets set. Who knows what > the error is? You have access to the err.out file, but apparently you > aren't reading it to find out. > > Then, 110 lines later, at line 135, you try to access the value of "host" > that never got set. > > Your job is to read the error in /tmp/err.out, see what is failing, and > fix it. > > But i'm Steven! That why i make use of it to read it immediately after my script run at browser time. i have even included a sys.exit(0) after the try:/except block: Here is it: errout = open( '/tmp/err.out', 'w' ) # opens and truncates the error output file try: gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') city = gi.time_zone_by_addr( os.environ['REMOTE_ADDR'] ) or gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or socket.gethostbyaddr( os.environ['HTTP_CF_CONNECTING_IP'] )[0] or "Proxy Detected" except Exception as e: print( "Xyzzy exception-", repr( sys.exc_info() ), file=errout ) errout.flush() sys.exit(0) and the output of error file is: nikos at superhost.gr [~]# cat /tmp/err.out UnicodeDecodeError('utf-8', b'\xb6\xe3\xed\xf9\xf3\xf4\xef \xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2', 0, 1, 'invalid start byte') -- Webhost -- Webhost From nikos at superhost.gr Sun Sep 1 10:25:23 2013 From: nikos at superhost.gr (Ferrous Cranus) Date: Sun, 01 Sep 2013 17:25:23 +0300 Subject: UnicodeDecodeError issue In-Reply-To: References: <5222fc40$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: ???? 1/9/2013 5:08 ??, ?/? Ferrous Cranus ??????: > ???? 1/9/2013 11:35 ??, ?/? Steven D'Aprano ??????: >> On Sat, 31 Aug 2013 23:50:23 -0700, Ferrous Cranus wrote: >> >>> ?? ???????, 31 ????????? 2013 9:41:27 ?.?. UTC+3, ? ??????? Ferrous >>> Cranus ??????: >>>> Suddenly my webiste superhost.gr running my main python script presents >>>> >>>> me with this error: >>>> >>>> >>>> >>>> Code: >>>> >>>> UnicodeDecodeError('utf-8', b'\xb6\xe3\xed\xf9\xf3\xf4\xef >>>> >>>> \xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2', 0, 1, >>>> >>>> 'invalid start byte') >>>> >>>> >>>> >>>> >>>> >>>> Does anyone know what this means? >>>> >>>> >>>> >>>> >>>> >>>> -- >>>> >>>> Webhost >>> >>> Good morning Steven, >>> >>> Ye i'm aware that i need to define variables before i try to make use of >>> them. I have study all of your examples and then re-view my code and i >>> can *assure* you that the line statement that tied to set the 'host' >>> variable is very early at the top of the script(of course after >>> imports), and the cur.execute comes after. >>> >>> The problem here is not what you say, that i try to drink k a coffee >>> before actually making one first but rather than i cannot drink the >>> coffee although i know *i have tried* to make one first. >>> >>> >>> i will upload the code for you to prove my sayings at pastebin. >>> >>> http://pastebin.com/J97guApQ >> >> >> You are mistaken. In line 20-25, you have this: >> >> try: >> gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') >> city = gi.time_zone_by_addr( os.environ['REMOTE_ADDR'] ) or >> gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) >> host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or >> socket.gethostbyaddr( os.environ['HTTP_CF_CONNECTING_IP'] )[0] >> or "Proxy Detected" >> except Exception as e: >> print( repr(e), file=open( '/tmp/err.out', 'w' ) ) >> >> >> An error occurs inside that block, *before* host gets set. Who knows what >> the error is? You have access to the err.out file, but apparently you >> aren't reading it to find out. >> >> Then, 110 lines later, at line 135, you try to access the value of "host" >> that never got set. >> >> Your job is to read the error in /tmp/err.out, see what is failing, and >> fix it. >> >> > > But i'm Steven! That why i make use of it to read it immediately after > my script run at browser time. > > i have even included a sys.exit(0) after the try:/except block: > > Here is it: > > > errout = open( '/tmp/err.out', 'w' ) # opens and truncates the > error output file > try: > gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') > city = gi.time_zone_by_addr( os.environ['REMOTE_ADDR'] ) or > gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) > host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or > socket.gethostbyaddr( os.environ['HTTP_CF_CONNECTING_IP'] )[0] or "Proxy > Detected" > except Exception as e: > print( "Xyzzy exception-", repr( sys.exc_info() ), file=errout ) > errout.flush() > > sys.exit(0) > > and the output of error file is: > > > nikos at superhost.gr [~]# cat /tmp/err.out > UnicodeDecodeError('utf-8', b'\xb6\xe3\xed\xf9\xf3\xf4\xef > \xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2', 0, 1, > 'invalid start byte') > But i noticed that err.out and /usr/local/apache/logs/error_log produced different output. In any case i check both: nikos at superhost.gr [~]# chmod 777 /tmp/err2.out ouput of error_log nikos at superhost.gr [~]# [Sun Sep 01 14:23:46 2013] [error] [client 173.245.49.120] Premature end of script headers: metrites.py [Sun Sep 01 14:23:46 2013] [error] [client 173.245.49.120] File does not exist: /home/nikos/public_html/500.shtml Also i have even changed output error filename. turns out empty. nikos at superhost.gr [~]# cat /tmp/err2.out -- Webhost From davea at davea.name Sun Sep 1 11:36:24 2013 From: davea at davea.name (Dave Angel) Date: Sun, 1 Sep 2013 15:36:24 +0000 (UTC) Subject: UnicodeDecodeError issue References: <5222fc40$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 1/9/2013 10:08, Ferrous Cranus wrote: > Here is it: > > > errout = open( '/tmp/err.out', 'w' ) # opens and truncates the error > output file > try: > gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') > city = gi.time_zone_by_addr( os.environ['REMOTE_ADDR'] ) or > gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) > host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or > socket.gethostbyaddr( os.environ['HTTP_CF_CONNECTING_IP'] )[0] or "Proxy > Detected" > except Exception as e: > print( "Xyzzy exception-", repr( sys.exc_info() ), file=errout ) > errout.flush() > > sys.exit(0) > > and the output of error file is: > > > nikos at superhost.gr [~]# cat /tmp/err.out > UnicodeDecodeError('utf-8', b'\xb6\xe3\xed\xf9\xf3\xf4\xef > \xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2', 0, 1, > 'invalid start byte') > Nope. The label "Xyzzy exception" is not in that file, so that's not the file you created in this run. Further, if that line existed before, it would have been wiped out by the open with mode "w". i suggest you add yet another write to that file, immediately after opening it: errout = open( '/tmp/err.out', 'w' ) # opens and truncates the error print("starting run", file=errorout) errout.flush() Until you can reliably examine the same file that was logging your errors, you're just spinning your wheels. you might even want to write the time to the file, so that you can tell whether it was now, or 2 days ago that the run was made. -- DaveA From nikos at superhost.gr Sun Sep 1 12:10:50 2013 From: nikos at superhost.gr (Ferrous Cranus) Date: Sun, 01 Sep 2013 19:10:50 +0300 Subject: UnicodeDecodeError issue In-Reply-To: References: <5222fc40$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: ???? 1/9/2013 6:36 ??, ?/? Dave Angel ??????: > On 1/9/2013 10:08, Ferrous Cranus wrote: > > >> Here is it: >> >> >> errout = open( '/tmp/err.out', 'w' ) # opens and truncates the error >> output file >> try: >> gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') >> city = gi.time_zone_by_addr( os.environ['REMOTE_ADDR'] ) or >> gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) >> host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or >> socket.gethostbyaddr( os.environ['HTTP_CF_CONNECTING_IP'] )[0] or "Proxy >> Detected" >> except Exception as e: >> print( "Xyzzy exception-", repr( sys.exc_info() ), file=errout ) >> errout.flush() >> >> sys.exit(0) >> >> and the output of error file is: >> >> >> nikos at superhost.gr [~]# cat /tmp/err.out >> UnicodeDecodeError('utf-8', b'\xb6\xe3\xed\xf9\xf3\xf4\xef >> \xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2', 0, 1, >> 'invalid start byte') >> > > Nope. The label "Xyzzy exception" is not in that file, so that's not > the file you created in this run. Further, if that line existed before, > it would have been wiped out by the open with mode "w". > > i suggest you add yet another write to that file, immediately after > opening it: > > errout = open( '/tmp/err.out', 'w' ) # opens and truncates the error > print("starting run", file=errorout) > errout.flush() > > Until you can reliably examine the same file that was logging your > errors, you're just spinning your wheels. you might even want to write > the time to the file, so that you can tell whether it was now, or 2 days > ago that the run was made. > > I tried it and it printed nothing. But suddenly thw ebpage sttaed to run and i get n invalid byte entried and no weird messge files.py is working as expcted. what on earht? Now i ahve thso error: # ================================================================================================================= # DATABASE INSERTS - do not increment the counter if a Cookie is set to the visitors browser already # ================================================================================================================= if( not vip and re.search( r'(msn|gator|amazon|yandex|reverse|cloudflare|who|fetch|barracuda|spider|google|crawl|pingdom)', host ) is None ): print( "i'm in and data is: ", host ) try: #find the needed counter for the page URL if os.path.exists( path + page ) or os.path.exists( cgi_path + page ): cur.execute('''SELECT ID FROM counters WHERE url = %s''', page ) data = cur.fetchone() #URL is unique, so should only be one if not data: #first time for page; primary key is automatic, hit is defaulted cur.execute('''INSERT INTO counters (url) VALUES (%s)''', page ) cID = cur.lastrowid #get the primary key value of the new record else: #found the page, save primary key and use it to issue hit UPDATE cID = data[0] cur.execute('''UPDATE counters SET hits = hits + 1 WHERE ID = %s''', cID ) #find the visitor record for the (saved) cID and current host cur.execute('''SELECT * FROM visitors WHERE counterID = %s and host = %s''', (cID, host) ) data = cur.fetchone() #cID&host are unique if not data: #first time for this host on this page, create new record cur.execute('''INSERT INTO visitors (counterID, host, city, useros, browser, lastvisit) VALUES (%s, %s, %s, %s, %s, %s)''', (cID, host, city, useros, browser, date) ) else: #found the page, save its primary key for later use vID = data[0] #UPDATE record using retrieved vID cur.execute('''UPDATE visitors SET city = %s, useros = %s, browser = %s, hits = hits + 1, lastvisit = %s WHERE counterID = %s and host = %s''', (city, useros, browser, date, vID, host) ) con.commit() #if we made it here, the transaction is complete except pymysql.ProgrammingError as e: print( repr(e) ) con.rollback() #something failed, rollback the entire transaction sys.exit(0) i get no counter increment when visitors visit my webpage. What on eart is going on? How the previous error with the invalid byte somehtign got solved? -- Webhost From nikos at superhost.gr Sun Sep 1 18:23:48 2013 From: nikos at superhost.gr (Ferrous Cranus) Date: Mon, 02 Sep 2013 01:23:48 +0300 Subject: UnicodeDecodeError issue In-Reply-To: References: <5222fc40$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: ???? 1/9/2013 7:10 ??, ?/? Ferrous Cranus ??????: > ???? 1/9/2013 6:36 ??, ?/? Dave Angel ??????: >> On 1/9/2013 10:08, Ferrous Cranus wrote: >> >> >>> Here is it: >>> >>> >>> errout = open( '/tmp/err.out', 'w' ) # opens and truncates the >>> error >>> output file >>> try: >>> gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') >>> city = gi.time_zone_by_addr( os.environ['REMOTE_ADDR'] ) or >>> gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) >>> host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or >>> socket.gethostbyaddr( os.environ['HTTP_CF_CONNECTING_IP'] )[0] or "Proxy >>> Detected" >>> except Exception as e: >>> print( "Xyzzy exception-", repr( sys.exc_info() ), file=errout ) >>> errout.flush() >>> >>> sys.exit(0) >>> >>> and the output of error file is: >>> >>> >>> nikos at superhost.gr [~]# cat /tmp/err.out >>> UnicodeDecodeError('utf-8', b'\xb6\xe3\xed\xf9\xf3\xf4\xef >>> \xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2', 0, 1, >>> 'invalid start byte') >>> >> >> Nope. The label "Xyzzy exception" is not in that file, so that's not >> the file you created in this run. Further, if that line existed before, >> it would have been wiped out by the open with mode "w". >> >> i suggest you add yet another write to that file, immediately after >> opening it: >> >> errout = open( '/tmp/err.out', 'w' ) # opens and truncates the >> error >> print("starting run", file=errorout) >> errout.flush() >> >> Until you can reliably examine the same file that was logging your >> errors, you're just spinning your wheels. you might even want to write >> the time to the file, so that you can tell whether it was now, or 2 days >> ago that the run was made. >> >> > > > I tried it and it printed nothing. > But suddenly thw ebpage sttaed to run and i get n invalid byte entried > and no weird messge files.py is working as expcted. > what on earht? > > Now i ahve thso error: > > # > ================================================================================================================= > > # DATABASE INSERTS - do not increment the counter if a Cookie is set to > the visitors browser already > # > ================================================================================================================= > > if( not vip and re.search( > r'(msn|gator|amazon|yandex|reverse|cloudflare|who|fetch|barracuda|spider|google|crawl|pingdom)', > host ) is None ): > > print( "i'm in and data is: ", host ) > try: > #find the needed counter for the page URL > if os.path.exists( path + page ) or os.path.exists( cgi_path + > page ): > cur.execute('''SELECT ID FROM counters WHERE url = %s''', > page ) > data = cur.fetchone() #URL is unique, so should only > be one > > if not data: > #first time for page; primary key is automatic, hit is > defaulted > cur.execute('''INSERT INTO counters (url) VALUES (%s)''', > page ) > cID = cur.lastrowid #get the primary key value of > the new record > else: > #found the page, save primary key and use it to issue hit > UPDATE > cID = data[0] > cur.execute('''UPDATE counters SET hits = hits + 1 WHERE ID > = %s''', cID ) > > #find the visitor record for the (saved) cID and current host > cur.execute('''SELECT * FROM visitors WHERE counterID = %s and > host = %s''', (cID, host) ) > data = cur.fetchone() #cID&host are unique > > if not data: > #first time for this host on this page, create new record > cur.execute('''INSERT INTO visitors (counterID, host, city, > useros, browser, lastvisit) VALUES (%s, %s, %s, %s, %s, %s)''', (cID, > host, city, useros, browser, date) ) > else: > #found the page, save its primary key for later use > vID = data[0] > #UPDATE record using retrieved vID > cur.execute('''UPDATE visitors SET city = %s, useros = %s, > browser = %s, hits = hits + 1, lastvisit = %s > WHERE counterID = %s and host = > %s''', (city, useros, browser, date, vID, host) ) > > con.commit() #if we made it here, the transaction is > complete > > except pymysql.ProgrammingError as e: > print( repr(e) ) > con.rollback() #something failed, rollback the entire > transaction > sys.exit(0) > > > i get no counter increment when visitors visit my webpage. > What on eart is going on? > > How the previous error with the invalid byte somehtign got solved? > i still wonder how come the invalid byte messge dissapeared -- Webhost From davea at davea.name Sun Sep 1 19:14:26 2013 From: davea at davea.name (Dave Angel) Date: Sun, 1 Sep 2013 23:14:26 +0000 (UTC) Subject: UnicodeDecodeError issue References: <5222fc40$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 1/9/2013 18:23, Ferrous Cranus wrote: >> > i still wonder how come the invalid byte messge dissapeared > Too bad you never bothered to narrow it down to its source. It could be anywhere on those three lines. If I had to guess, I'd figure it was one of those environment variables. The Linux environment variables are strings of bytes, and the os.environ is a dict of strings. Apparently it converts them using utf-8, and if you've somehow set them using some other encoding, you could be getting that error. Have you tried to decode those bytes in various encodings other than utf-8 ? -- Signature file not found From nikos at superhost.gr Mon Sep 2 00:16:34 2013 From: nikos at superhost.gr (Ferrous Cranus) Date: Mon, 02 Sep 2013 07:16:34 +0300 Subject: UnicodeDecodeError issue In-Reply-To: References: <5222fc40$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: ???? 2/9/2013 2:14 ??, ?/? Dave Angel ??????: > On 1/9/2013 18:23, Ferrous Cranus wrote: > > >>> >> i still wonder how come the invalid byte messge dissapeared >> > > Too bad you never bothered to narrow it down to its source. if only i knew how up until yesterday when they were appearing. > It could > be anywhere on those three lines. If I had to guess, I'd figure it was > one of those environment variables. The Linux environment variables are > strings of bytes, and the os.environ is a dict of strings. Apparently > it converts them using utf-8, and if you've somehow set them using some > other encoding, you could be getting that error. > > Have you tried to decode those bytes in various encodings other than > utf-8 ? No, because i wasn't aware of what string/variable they were pertaining at. -- Webhost From davea at davea.name Mon Sep 2 07:38:04 2013 From: davea at davea.name (Dave Angel) Date: Mon, 2 Sep 2013 11:38:04 +0000 (UTC) Subject: UnicodeDecodeError issue References: <5222fc40$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2/9/2013 00:16, Ferrous Cranus wrote: >> >> Have you tried to decode those bytes in various encodings other than >> utf-8 ? > > > No, because i wasn't aware of what string/variable they were pertaining at. > > http://pypi.python.org/pypi/chardet is a package which tries to 'guess' an encoding for a string of bytes. I happen to have the 2.7 version installed, but not the 3.x version, so the following is in 2.7. Same thing should work in 3.3.... >>> chardet.detect(b'\xb6\xe3\xed\xf9\xf3\xf4\xef\xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2') {'confidence': 0.9638983132261467, 'encoding': 'windows-1253'} >>> print b'\xb6\xe3\xed\xf9\xf3\xf4\xef\xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2'.decode('windows-1253') ???????????? ?????????? I don't have a clue what it might be; it's not English, and I don't know whatever language it may be in. Does that string make any sense to you? You may want to try it on your own machine, since the email may obscure the encoding. Or you might want to do the decode using whatever the default encoding is for that server. The Linux 'file' utility thinks this string is in ISO-8859, so you might want to try a decode('ISO-8859-1') as well. (and maybe ISO-8859-2, -3, -4, and -5) -- DaveA From python at mrabarnett.plus.com Mon Sep 2 07:56:29 2013 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 02 Sep 2013 12:56:29 +0100 Subject: UnicodeDecodeError issue In-Reply-To: References: <5222fc40$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52247CED.9050101@mrabarnett.plus.com> On 02/09/2013 12:38, Dave Angel wrote: > On 2/9/2013 00:16, Ferrous Cranus wrote: >>> >>> Have you tried to decode those bytes in various encodings other than >>> utf-8 ? >> >> No, because i wasn't aware of what string/variable they were pertaining at. >> > http://pypi.python.org/pypi/chardet > > is a package which tries to 'guess' an encoding for a string of bytes. > I happen to have the 2.7 version installed, but not the 3.x version, so > the following is in 2.7. Same thing should work in 3.3.... > >>>> chardet.detect(b'\xb6\xe3\xed\xf9\xf3\xf4\xef\xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2') > {'confidence': 0.9638983132261467, 'encoding': 'windows-1253'} >>>> print b'\xb6\xe3\xed\xf9\xf3\xf4\xef\xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2'.decode('windows-1253') > ???????????? ?????????? > > I don't have a clue what it might be; it's not English, and I don't > know whatever language it may be in. > You don't recognise Greek? > Does that string make any sense to you? You may want to try it on your > own machine, since the email may obscure the encoding. Or you might > want to do the decode using whatever the default encoding is for that > server. > > The Linux 'file' utility thinks this string is in ISO-8859, so you might > want to try a decode('ISO-8859-1') as well. (and maybe ISO-8859-2, -3, > -4, and -5) > It's ISO-8859-7 (Greek). From davea at davea.name Mon Sep 2 08:24:16 2013 From: davea at davea.name (Dave Angel) Date: Mon, 2 Sep 2013 12:24:16 +0000 (UTC) Subject: UnicodeDecodeError issue References: <5222fc40$0$6599$c3e8da3$5496439d@news.astraweb.com> <52247CED.9050101@mrabarnett.plus.com> Message-ID: On 2/9/2013 07:56, MRAB wrote: > On 02/09/2013 12:38, Dave Angel wrote: >> ???????????? ?????????? >> >> I don't have a clue what it might be; it's not English, and I don't >> know whatever language it may be in. >> > You don't recognise Greek? I recognize most of those as Greek characters, but as I said, I don't know Greek. And because I can't recognize words, I can't assume it might not be some other language that uses the same glyphs. > >> Does that string make any sense to you? You may want to try it on your >> own machine, since the email may obscure the encoding. Or you might >> want to do the decode using whatever the default encoding is for that >> server. >> >> The Linux 'file' utility thinks this string is in ISO-8859, so you might >> want to try a decode('ISO-8859-1') as well. (and maybe ISO-8859-2, -3, >> -4, and -5) >> > It's ISO-8859-7 (Greek). -- DaveA From python at mrabarnett.plus.com Mon Sep 2 10:44:34 2013 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 02 Sep 2013 15:44:34 +0100 Subject: UnicodeDecodeError issue In-Reply-To: References: <5222fc40$0$6599$c3e8da3$5496439d@news.astraweb.com> <52247CED.9050101@mrabarnett.plus.com> Message-ID: <5224A452.50000@mrabarnett.plus.com> On 02/09/2013 13:24, Dave Angel wrote: > On 2/9/2013 07:56, MRAB wrote: > >> On 02/09/2013 12:38, Dave Angel wrote: > > > >>> ???????????? ?????????? >>> >>> I don't have a clue what it might be; it's not English, and I don't >>> know whatever language it may be in. >>> >> You don't recognise Greek? > > I recognize most of those as Greek characters, but as I said, I don't > know Greek. And because I can't recognize words, I can't assume it > might not be some other language that uses the same glyphs. > I don't know Greek either, and I don't think there's any other language that uses the Greek alphabet. >> >>> Does that string make any sense to you? You may want to try it on your >>> own machine, since the email may obscure the encoding. Or you might >>> want to do the decode using whatever the default encoding is for that >>> server. >>> >>> The Linux 'file' utility thinks this string is in ISO-8859, so you might >>> want to try a decode('ISO-8859-1') as well. (and maybe ISO-8859-2, -3, >>> -4, and -5) >>> >> It's ISO-8859-7 (Greek). > From rosuav at gmail.com Mon Sep 2 18:45:00 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 Sep 2013 08:45:00 +1000 Subject: UnicodeDecodeError issue In-Reply-To: <5224A452.50000@mrabarnett.plus.com> References: <5222fc40$0$6599$c3e8da3$5496439d@news.astraweb.com> <52247CED.9050101@mrabarnett.plus.com> <5224A452.50000@mrabarnett.plus.com> Message-ID: On Tue, Sep 3, 2013 at 12:44 AM, MRAB wrote: > I don't know Greek either, and I don't think there's any other language > that uses the Greek alphabet. Assuming you don't count mathematics as a language. ChrisA From joel.goldstick at gmail.com Mon Sep 2 20:49:56 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 2 Sep 2013 20:49:56 -0400 Subject: UnicodeDecodeError issue In-Reply-To: References: <5222fc40$0$6599$c3e8da3$5496439d@news.astraweb.com> <52247CED.9050101@mrabarnett.plus.com> <5224A452.50000@mrabarnett.plus.com> Message-ID: On Mon, Sep 2, 2013 at 6:45 PM, Chris Angelico wrote: > On Tue, Sep 3, 2013 at 12:44 AM, MRAB wrote: >> I don't know Greek either, and I don't think there's any other language >> that uses the Greek alphabet. > > Assuming you don't count mathematics as a language. You need to be rigorous to make mathematical assumptions. One bad assumtion and proof == poof! > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick http://joelgoldstick.com From steve+comp.lang.python at pearwood.info Tue Sep 3 10:56:52 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Sep 2013 14:56:52 GMT Subject: UnicodeDecodeError issue References: <5222fc40$0$6599$c3e8da3$5496439d@news.astraweb.com> <52247CED.9050101@mrabarnett.plus.com> <5224A452.50000@mrabarnett.plus.com> Message-ID: <5225f8b4$0$6599$c3e8da3$5496439d@news.astraweb.com> On Tue, 03 Sep 2013 08:45:00 +1000, Chris Angelico wrote: > On Tue, Sep 3, 2013 at 12:44 AM, MRAB > wrote: >> I don't know Greek either, and I don't think there's any other language >> that uses the Greek alphabet. > > Assuming you don't count mathematics as a language. There are a few languages which use the Greek alphabet, with variations. Coptic is the main one, although Greek and Coptic letters have their own Unicode symbols, in order to support works which need to distinguish them. Armenian and, of course, Cyrillic, are derived from the Greek alphabet; actually so is the Latin alphabet. Other languages that used, or use, the Greek alphabet include quite a few ancient languages, including Gaulish and Bactrian. Old Nubian in the Middle Ages used the Greek alphabet plus a few additional letters. A number of Slavic languages used the Greek alphabet, although now they use Cyrillic. Some Albanian dialects still use the Greek alphabet, as do a couple of Turkic languages from the Balkans. See the Wikipedia entry on the Greek alphabet for more. -- Steven From wxjmfauth at gmail.com Tue Sep 3 11:23:55 2013 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Tue, 3 Sep 2013 08:23:55 -0700 (PDT) Subject: UnicodeDecodeError issue In-Reply-To: References: <5222fc40$0$6599$c3e8da3$5496439d@news.astraweb.com> <52247CED.9050101@mrabarnett.plus.com> Message-ID: <3510a783-79ac-48b0-90a9-8262d28eeba0@googlegroups.com> Le lundi 2 septembre 2013 16:44:34 UTC+2, MRAB a ?crit?: > On 02/09/2013 13:24, Dave Angel wrote: > > > On 2/9/2013 07:56, MRAB wrote: > > > > > >> On 02/09/2013 12:38, Dave Angel wrote: > > > > > > > > > > > >>> ???????????? ?????????? > > >>> > > >>> I don't have a clue what it might be; it's not English, and I don't > > >>> know whatever language it may be in. > > >>> > > >> You don't recognise Greek? > > > > > > I recognize most of those as Greek characters, but as I said, I don't > > > know Greek. And because I can't recognize words, I can't assume it > > > might not be some other language that uses the same glyphs. > > > > > I don't know Greek either, and I don't think there's any other language > > that uses the Greek alphabet. > > > > >> > > >>> Does that string make any sense to you? You may want to try it on your > > >>> own machine, since the email may obscure the encoding. Or you might > > >>> want to do the decode using whatever the default encoding is for that > > >>> server. > > >>> > > >>> The Linux 'file' utility thinks this string is in ISO-8859, so you might > > >>> want to try a decode('ISO-8859-1') as well. (and maybe ISO-8859-2, -3, > > >>> -4, and -5) > > >>> > > >> It's ISO-8859-7 (Greek). > > > -------- The Latin alphabet uses Greek lettering. The Cyrillic alphabet uses Greek lettering. Greek: One should not confuse modern Greek with ancient Greek, polytonic Greek full of diacritics. Plenty of European languages (~15) based on the Latin alphabet uses some ancient Greek diacritics. Now unicode. Everything is working very smoothly with the endorsed coding schemes of Unicode.org. Expectedly it fails (behaves badly) with Python and its Flexible Sting Representation, mainly because it relies on the latin-1 (iso-8859-1) set. To take the problem the other way, one can take these linguistic ascpects to illustrate the wrong design of the FSR. jmf From antoon.pardon at rece.vub.ac.be Wed Sep 4 04:01:50 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 04 Sep 2013 10:01:50 +0200 Subject: UnicodeDecodeError issue In-Reply-To: <3510a783-79ac-48b0-90a9-8262d28eeba0@googlegroups.com> References: <5222fc40$0$6599$c3e8da3$5496439d@news.astraweb.com> <52247CED.9050101@mrabarnett.plus.com> <3510a783-79ac-48b0-90a9-8262d28eeba0@googlegroups.com> Message-ID: <5226E8EE.6000403@rece.vub.ac.be> Op 03-09-13 17:23, wxjmfauth at gmail.com schreef: > -------- > > The Latin alphabet uses Greek lettering. > > The Cyrillic alphabet uses Greek lettering. > > Greek: One should not confuse modern Greek > with ancient Greek, polytonic Greek full > of diacritics. > > Plenty of European languages (~15) based on the Latin > alphabet uses some ancient Greek diacritics. > > Now unicode. > > Everything is working very smoothly with the endorsed coding > schemes of Unicode.org. > > Expectedly it fails (behaves badly) with Python and its > Flexible Sting Representation, mainly because it relies on > the latin-1 (iso-8859-1) set. You really seem obsessed. There is no reason at all to think that is problem is related to the FSR. You are only bringing this up, because you are looking for opportunities to complain about the FSR. > To take the problem the other way, one can take these > linguistic ascpects to illustrate the wrong design of > the FSR. No you can't, you are just assuming so because you feel it would confirm your bias against the FSR. -- Antoon Pardon From wxjmfauth at gmail.com Wed Sep 4 10:08:39 2013 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 4 Sep 2013 07:08:39 -0700 (PDT) Subject: UnicodeDecodeError issue In-Reply-To: References: <5222fc40$0$6599$c3e8da3$5496439d@news.astraweb.com> <52247CED.9050101@mrabarnett.plus.com> <3510a783-79ac-48b0-90a9-8262d28eeba0@googlegroups.com> Message-ID: <0bce060d-ec91-4739-ac21-9a60795c9611@googlegroups.com> Le mercredi 4 septembre 2013 10:01:50 UTC+2, Antoon Pardon a ?crit?: > Op 03-09-13 17:23, wxjmfauth at gmail.com schreef: > > > > > -------- > > > > > > The Latin alphabet uses Greek lettering. > > > > > > The Cyrillic alphabet uses Greek lettering. > > > > > > Greek: One should not confuse modern Greek > > > with ancient Greek, polytonic Greek full > > > of diacritics. > > > > > > Plenty of European languages (~15) based on the Latin > > > alphabet uses some ancient Greek diacritics. > > > > > > Now unicode. > > > > > > Everything is working very smoothly with the endorsed coding > > > schemes of Unicode.org. > > > > > > Expectedly it fails (behaves badly) with Python and its > > > Flexible Sting Representation, mainly because it relies on > > > the latin-1 (iso-8859-1) set. > > > > You really seem obsessed. There is no reason at all to think that is > > problem is related to the FSR. You are only bringing this up, because > > you are looking for opportunities to complain about the FSR. > > > > > To take the problem the other way, one can take these > > > linguistic ascpects to illustrate the wrong design of > > > the FSR. > > > > No you can't, you are just assuming so because you feel it would > > confirm your bias against the FSR. > > > > -- > > Antoon Pardon -------- jmf From nikos at superhost.gr Mon Sep 2 07:49:03 2013 From: nikos at superhost.gr (Ferrous Cranus) Date: Mon, 02 Sep 2013 14:49:03 +0300 Subject: UnicodeDecodeError issue In-Reply-To: References: <5222fc40$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: ???? 2/9/2013 2:38 ??, ?/? Dave Angel ??????: > On 2/9/2013 00:16, Ferrous Cranus wrote: > > >>> >>> Have you tried to decode those bytes in various encodings other than >>> utf-8 ? >> >> >> No, because i wasn't aware of what string/variable they were pertaining at. >> >> > > http://pypi.python.org/pypi/chardet > > is a package which tries to 'guess' an encoding for a string of bytes. > I happen to have the 2.7 version installed, but not the 3.x version, so > the following is in 2.7. Same thing should work in 3.3.... > >>>> chardet.detect(b'\xb6\xe3\xed\xf9\xf3\xf4\xef\xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2') > {'confidence': 0.9638983132261467, 'encoding': 'windows-1253'} >>>> print b'\xb6\xe3\xed\xf9\xf3\xf4\xef\xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2'.decode('windows-1253') > ???????????? ?????????? > > > I don't have a clue what it might be; it's not English, and I don't > know whatever language it may be in. > > Does that string make any sense to you? Yes it does, it mean "Unknown Hostname" > The Linux 'file' utility thinks this string is in ISO-8859, so you might > want to try a decode('ISO-8859-1') as well. (and maybe ISO-8859-2, -3, > -4, and -5) How did you test it? The utility afaik analyzes a file's encodings not string encodings. nikos at superhost.gr [~]# file www/cgi-bin/files.py www/cgi-bin/files.py: a /usr/bin/python script text executable -- Webhost From davea at davea.name Mon Sep 2 08:21:45 2013 From: davea at davea.name (Dave Angel) Date: Mon, 2 Sep 2013 12:21:45 +0000 (UTC) Subject: UnicodeDecodeError issue References: <5222fc40$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2/9/2013 07:49, Ferrous Cranus wrote: > ???? 2/9/2013 2:38 ??, ?/? Dave Angel ??????: >> >> Does that string make any sense to you? > > Yes it does, it mean "Unknown Hostname" > >> The Linux 'file' utility thinks this string is in ISO-8859, so you might >> want to try a decode('ISO-8859-1') as well. (and maybe ISO-8859-2, -3, >> -4, and -5) > > How did you test it? The utility afaik analyzes a file's encodings not > string encodings. > Starting with the byte string in the error message: >>> f = open("junk.txt", "w") >>> f.write(b'\xb6\xe3\xed\xf9\xf3\xf4\xef\xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2\n') >>> f.close() > nikos at superhost.gr [~]# file www/cgi-bin/files.py > www/cgi-bin/files.py: a /usr/bin/python script text executable > > No point in doing that, as the string in question doesn't exist there. -- DaveA From nikos at superhost.gr Mon Sep 2 11:05:03 2013 From: nikos at superhost.gr (Ferrous Cranus) Date: Mon, 02 Sep 2013 18:05:03 +0300 Subject: UnicodeDecodeError issue In-Reply-To: References: <5222fc40$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: ???? 2/9/2013 3:21 ??, ?/? Dave Angel ??????: > Starting with the byte string in the error message: >>>> f = open("junk.txt", "w") >>>> f.write(b'\xb6\xe3\xed\xf9\xf3\xf4\xef\xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2\n') >>>> f.close() ?ndeed but yet again, file checks out the encoding of the filename that consists of these lines above, not of the actual strings. -- Webhost From davea at davea.name Mon Sep 2 14:28:36 2013 From: davea at davea.name (Dave Angel) Date: Mon, 2 Sep 2013 18:28:36 +0000 (UTC) Subject: UnicodeDecodeError issue References: <5222fc40$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2/9/2013 11:05, Ferrous Cranus wrote: > ???? 2/9/2013 3:21 ??, ?/? Dave Angel ??????: >> Starting with the byte string in the error message: >>>>> f = open("junk.txt", "w") >>>>> f.write(b'\xb6\xe3\xed\xf9\xf3\xf4\xef\xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2\n') >>>>> f.close() > > > ?ndeed but yet again, file checks out the encoding of the filename that > consists of these lines above, not of the actual strings. > > 'file' does nothing interesting with the filename, it just opens it and examines the contents. For example, file www/cgi-bin/files.py will examine the Python source file, not run it. So first in the interpreter, I ran >>>> f = open("junk.txt", "w") >>>> f.write(b'\xb6\xe3\xed\xf9\xf3\xf4\xef\xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2\n') >>>> f.close() then at the bash prompt, I ran: davea at think2:~$ file junk.txt junk.txt: ISO-8859 text davea at think2:~$ -- DaveA From nikos.gr33k at gmail.com Wed Sep 4 04:35:06 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Wed, 4 Sep 2013 01:35:06 -0700 (PDT) Subject: UnicodeDecodeError issue In-Reply-To: References: <5222fc40$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3e549761-4323-4379-b4e4-ce51597d59c0@googlegroups.com> ?? ???????, 2 ??????????? 2013 9:28:36 ?.?. UTC+3, ? ??????? Dave Angel ??????: > On 2/9/2013 11:05, Ferrous Cranus wrote: > > > > > ???? 2/9/2013 3:21 ??, ?/? Dave Angel ??????: > > >> Starting with the byte string in the error message: > > >>>>> f = open("junk.txt", "w") > > >>>>> f.write(b'\xb6\xe3\xed\xf9\xf3\xf4\xef\xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2\n') > > >>>>> f.close() > > > > > > > > > ?ndeed but yet again, file checks out the encoding of the filename that > > > consists of these lines above, not of the actual strings. > > > > > > > > > > 'file' does nothing interesting with the filename, it just opens it and > > examines the contents. For example, > > > > file www/cgi-bin/files.py > > > > will examine the Python source file, not run it. > > > > So first in the interpreter, I ran > > > > >>>> f = open("junk.txt", "w") > > >>>> f.write(b'\xb6\xe3\xed\xf9\xf3\xf4\xef\xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2\n') > > >>>> f.close() > > > > then at the bash prompt, I ran: > > > > davea at think2:~$ file junk.txt > > junk.txt: ISO-8859 text That is one Clever Idea Dave. I take it that the charset of the file 'junk.txt' gets identified by the characters encoding that read form within the file? But wait a minute: What editor do you uses to write these 3 lines? I mean am a bit confused. i for example i 'nano tets.py' which has within: f = open("junk.txt", "w") f.write(b'\xb6\xe3\xed\xf9\xf3\xf4\xef\xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2\n') f.close() then when i save the file within nano for example by default in utf-8 charset how would it be able to detect the bytestring within that is supposed to be of greek-iso's From davea at davea.name Wed Sep 4 07:26:18 2013 From: davea at davea.name (Dave Angel) Date: Wed, 4 Sep 2013 11:26:18 +0000 (UTC) Subject: UnicodeDecodeError issue References: <5222fc40$0$6599$c3e8da3$5496439d@news.astraweb.com> <3e549761-4323-4379-b4e4-ce51597d59c0@googlegroups.com> Message-ID: On 4/9/2013 04:35, Ferrous Cranus wrote: > ?? ???????, 2 ??????????? 2013 9:28:36 ?.?. UTC+3, ? ??????? Dave Angel ??????: >> On 2/9/2013 11:05, Ferrous Cranus wrote: >> >> >> >> > ???? 2/9/2013 3:21 ??, ?/? Dave Angel ??????: >> >> >> Starting with the byte string in the error message: >> >> >>>>> f = open("junk.txt", "w") >> >> >>>>> f.write(b'\xb6\xe3\xed\xf9\xf3\xf4\xef\xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2\n') >> >> >>>>> f.close() >> >> > >> >> > >> >> > ?ndeed but yet again, file checks out the encoding of the filename that >> >> > consists of these lines above, not of the actual strings. >> >> > >> >> > >> >> >> >> 'file' does nothing interesting with the filename, it just opens it and >> >> examines the contents. For example, >> >> >> >> file www/cgi-bin/files.py >> >> >> >> will examine the Python source file, not run it. >> >> >> >> So first in the interpreter, I ran >> >> >> >> >>>> f = open("junk.txt", "w") >> >> >>>> f.write(b'\xb6\xe3\xed\xf9\xf3\xf4\xef\xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2\n') >> >> >>>> f.close() >> >> >> >> then at the bash prompt, I ran: >> >> >> >> davea at think2:~$ file junk.txt >> >> junk.txt: ISO-8859 text > > > That is one Clever Idea Dave. > > I take it that the charset of the file 'junk.txt' gets identified by the characters encoding that read form within the file? 'file' only guesses the most likely encoding for 'junk.txt' But at least it can know it's not utf-8, since that would give an decoding error. That's why, whenever 'file' makes its verdict, it's up to you to check it by displaying the data after decoding it with that tentative encoding. > > But wait a minute: What editor do you uses to write these 3 lines? > I mean am a bit confused. As I said right above, "in the interpreter, I ran"... And if that's not clear enough, you can see the >>>> prompts that the Python interpreter uses. By interpeter, I mean I ran Python with no parameters. I did not run IDLE or any other IDE, that might take it upon itself to interfere. > > i for example i 'nano tets.py' which has within: > > f = open("junk.txt", "w") > f.write(b'\xb6\xe3\xed\xf9\xf3\xf4\xef\xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2\n') > f.close() > > then when i save the file within nano for example by default in utf-8 charset That's the encoding for the file tets.py, and you'll notice that it's actually ASCII. Notice that the string I copied from the error message uses escape sequences for all non-ASCII bytes. > > how would it be able to detect the bytestring within that is supposed to be of greek-iso's I wouldn't be running 'file' on the tets.py file, but on the junk.txt file created when you run python tets.py So since the tets.py file was a sidetrack, I just ran those three lines in the interpreter. -- DaveA From nikos at superhost.gr Wed Sep 4 07:38:41 2013 From: nikos at superhost.gr (Ferrous Cranus) Date: Wed, 04 Sep 2013 14:38:41 +0300 Subject: UnicodeDecodeError issue In-Reply-To: References: <5222fc40$0$6599$c3e8da3$5496439d@news.astraweb.com> <3e549761-4323-4379-b4e4-ce51597d59c0@googlegroups.com> Message-ID: ???? 4/9/2013 2:26 ??, ?/? Dave Angel ??????: > On 4/9/2013 04:35, Ferrous Cranus wrote: > >> ?? ???????, 2 ??????????? 2013 9:28:36 ?.?. UTC+3, ? ??????? Dave Angel ??????: >>> On 2/9/2013 11:05, Ferrous Cranus wrote: >>> >>> >>> >>>> ???? 2/9/2013 3:21 ??, ?/? Dave Angel ??????: >>> >>>>> Starting with the byte string in the error message: >>> >>>>>>>> f = open("junk.txt", "w") >>> >>>>>>>> f.write(b'\xb6\xe3\xed\xf9\xf3\xf4\xef\xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2\n') >>> >>>>>>>> f.close() >>> >>>> >>> >>>> >>> >>>> ?ndeed but yet again, file checks out the encoding of the filename that >>> >>>> consists of these lines above, not of the actual strings. >>> >>>> >>> >>>> >>> >>> >>> >>> 'file' does nothing interesting with the filename, it just opens it and >>> >>> examines the contents. For example, >>> >>> >>> >>> file www/cgi-bin/files.py >>> >>> >>> >>> will examine the Python source file, not run it. >>> >>> >>> >>> So first in the interpreter, I ran >>> >>> >>> >>>>>>> f = open("junk.txt", "w") >>> >>>>>>> f.write(b'\xb6\xe3\xed\xf9\xf3\xf4\xef\xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2\n') >>> >>>>>>> f.close() >>> >>> >>> >>> then at the bash prompt, I ran: >>> >>> >>> >>> davea at think2:~$ file junk.txt >>> >>> junk.txt: ISO-8859 text >> >> >> That is one Clever Idea Dave. >> >> I take it that the charset of the file 'junk.txt' gets identified by the characters encoding that read form within the file? > > 'file' only guesses the most likely encoding for 'junk.txt' But at > least it can know it's not utf-8, since that would give an decoding > error. > > That's why, whenever 'file' makes its verdict, it's up to you to check > it by displaying the data after decoding it with that tentative > encoding. > >> >> But wait a minute: What editor do you uses to write these 3 lines? >> I mean am a bit confused. > > As I said right above, "in the interpreter, I ran"... > And if that's not clear enough, you can see the >>>> prompts that the > Python interpreter uses. By interpeter, I mean I ran Python with no > parameters. I did not run IDLE or any other IDE, that might take it > upon itself to interfere. > > >> >> i for example i 'nano tets.py' which has within: >> >> f = open("junk.txt", "w") >> f.write(b'\xb6\xe3\xed\xf9\xf3\xf4\xef\xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2\n') >> f.close() >> >> then when i save the file within nano for example by default in utf-8 charset > > That's the encoding for the file tets.py, and you'll notice that it's > actually ASCII. Notice that the string I copied from the error message > uses escape sequences for all non-ASCII bytes. > >> >> how would it be able to detect the bytestring within that is supposed to be of greek-iso's > > I wouldn't be running 'file' on the tets.py file, but on the junk.txt > file created when you run > python tets.py > > So since the tets.py file was a sidetrack, I just ran those three lines > in the interpreter. > I'm still consused about this. say we save those 3 lines inside junk.txt and we save it by default as utf-8 when we 'file junk.txt' what will file respond with? filename's charset? or will it llook at the bystering within to decide what encoding it uses? fi -- Webhost From davea at davea.name Wed Sep 4 08:38:04 2013 From: davea at davea.name (Dave Angel) Date: Wed, 4 Sep 2013 12:38:04 +0000 (UTC) Subject: UnicodeDecodeError issue References: <5222fc40$0$6599$c3e8da3$5496439d@news.astraweb.com> <3e549761-4323-4379-b4e4-ce51597d59c0@googlegroups.com> Message-ID: On 4/9/2013 07:38, Ferrous Cranus wrote: > ???? 4/9/2013 2:26 ??, ?/? Dave Angel ??????: >> >>>> >>>> So first in the interpreter, I ran >>>> >>>> >>>> >>>>>>>> f = open("junk.txt", "w") >>>> >>>>>>>> f.write(b'\xb6\xe3\xed\xf9\xf3\xf4\xef\xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2\n') >>>> >>>>>>>> f.close() >>>> >>>> >>>> >> So since the tets.py file was a sidetrack, I just ran those three lines >> in the interpreter. >> > I'm still consused about this. > > say we save those 3 lines inside junk.txt and we save it by default as utf-8 > > when we 'file junk.txt' > > what will file respond with? junk2.txt: ASCII text > > filename's charset? > > or > > will it llook at the bystering within to decide what encoding it uses? > 'file' isn't magic. And again, it doesn't look at the filename, it looks at the content. What heuristics it uses, I don't know, but it has hundreds of them. ( I wish you hadn't confused the issue by using the same name junk.txt for an entirely different purpose) When it looks at a file like this one, it looks only at the bytes within it. In this case, the instance of 'file' on my machine decides it's an ASCII file. if I add an silly shebang line #!/usr/tmp/pyttthon it says junk2.txt: a /usr/tmp/pyttthon script, ASCII text executable It doesn't know it's python, it just trusts the shebang line. And it identifies it as ASCII, not utf-8, since there are no non-ascii characters in it. It certainly does not try to interpret the b'xxxx' byte string by Python syntax rules. -- DaveA From cs at zip.com.au Thu Sep 5 00:42:08 2013 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 5 Sep 2013 14:42:08 +1000 Subject: UnicodeDecodeError issue In-Reply-To: References: Message-ID: <20130905044208.GA99563@cskk.homeip.net> On 04Sep2013 12:38, Dave Angel wrote: | 'file' isn't magic. Chuckle... | What heuristics it uses, I don't know, but it has | hundreds of them. ... because the file of heuristics is /usr/share/file/magic :-) See "man 5 magic". Cheers, -- Cameron Simpson A vacuum is a hell of a lot better than some of the stuff that nature replaces it with. - Tenessee Williams From nikos at superhost.gr Wed Sep 4 10:29:31 2013 From: nikos at superhost.gr (Ferrous Cranus) Date: Wed, 04 Sep 2013 17:29:31 +0300 Subject: UnicodeDecodeError issue In-Reply-To: References: <5222fc40$0$6599$c3e8da3$5496439d@news.astraweb.com> <3e549761-4323-4379-b4e4-ce51597d59c0@googlegroups.com> Message-ID: ???? 4/9/2013 3:38 ??, ?/? Dave Angel ??????: > 'file' isn't magic. And again, it doesn't look at the filename, it > looks at the content. So, you are saying that it looks a the content of the file and not of what encoding we used to save the file into? But the contents have within: f.write(b'\xb6\xe3\xed\xf9\xf3\xf4\xef\xfc\xed\xef\xec\xe1 \xf3\xf\xf3\xf4\xde\xec\xe1\xf4\xef\xf2\n') so it should have said greek-iso and not ascii. -- Webhost From davea at davea.name Wed Sep 4 20:17:36 2013 From: davea at davea.name (Dave Angel) Date: Thu, 5 Sep 2013 00:17:36 +0000 (UTC) Subject: UnicodeDecodeError issue References: <5222fc40$0$6599$c3e8da3$5496439d@news.astraweb.com> <3e549761-4323-4379-b4e4-ce51597d59c0@googlegroups.com> Message-ID: On 4/9/2013 10:29, Ferrous Cranus wrote: > ???? 4/9/2013 3:38 ??, ?/? Dave Angel ??????: >> 'file' isn't magic. And again, it doesn't look at the filename, it >> looks at the content. > So, you are saying that it looks a the content of the file and not of > what encoding we used to save the file into? That's right. There's no place where your text editor stores the encoding it used, so 'file' has to guess, based only on the content. > > But the contents have within: > > f.write(b'\xb6\xe3\xed\xf9\xf3\xf4\xef\xfc\xed\xef\xec\xe1 > \xf3\xf\xf3\xf4\xde\xec\xe1\xf4\xef\xf2\n') > > so it should have said greek-iso and not ascii. > No, that line is totally ASCII. Only when it's EXECUTED by Python will a non ASCII byte string object be created. Like I said, 'file' doesn't know the first thing about Python syntax, nor should it. -- Signature file not found From steve at pearwood.info Wed Sep 4 23:07:43 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 05 Sep 2013 03:07:43 GMT Subject: UnicodeDecodeError issue References: <5222fc40$0$6599$c3e8da3$5496439d@news.astraweb.com> <3e549761-4323-4379-b4e4-ce51597d59c0@googlegroups.com> Message-ID: <5227f57e$0$2743$c3e8da3$76491128@news.astraweb.com> On Thu, 05 Sep 2013 00:17:36 +0000, Dave Angel wrote: > On 4/9/2013 10:29, Ferrous Cranus wrote: > >> ???? 4/9/2013 3:38 ??, ?/? Dave Angel ??????: >>> 'file' isn't magic. And again, it doesn't look at the filename, it >>> looks at the content. >> So, you are saying that it looks a the content of the file and not of >> what encoding we used to save the file into? > > That's right. There's no place where your text editor stores the > encoding it used, so 'file' has to guess, based only on the content. Correct. The thing that people often fail to understand is that there is no *reliable* way to store the encoding used for a text file in the text file itself. The encoding is *metadata*, not data: it is data about the data, and consequently it has to be stored "out of band". It has to be stored somewhere else, outside of the file. In the case of text files, it is usually not stored anywhere at all. IBM mainframes assume that text files are using EBCDIC; modern Linux systems assume text files are UTF-8; old DOS applications assume text files are ASCII. Some text editors will try to guess the encoding, using various heuristics such as "if the file starts with \xFE\xFF it is UTF-16" but none of them are foolproof: http://blogs.msdn.com/b/oldnewthing/archive/2004/03/24/95235.aspx sometimes with amusing consequences: http://www.hoax-slayer.com/bush-hid-the-facts-notepad.html >> But the contents have within: >> >> f.write(b'\xb6\xe3\xed\xf9\xf3\xf4\xef\xfc\xed\xef\xec\xe1 >> \xf3\xf\xf3\xf4\xde\xec\xe1\xf4\xef\xf2\n') >> >> so it should have said greek-iso and not ascii. But the above byte string is also valid ISO-8859-5 (Cyrillic): '?????????????\x0f????????\n' ISO-8859-2 (Central European): '?????????????\x0f????????\n' and ISO-8859-4 (Baltic): '?????????????\x0f????????\n' Surely you don't expect the file utility to actually recognise that '?????????????\x0f????????\n' makes a valid Greek phrase while the others are not meaningful? > No, that line is totally ASCII. Only when it's EXECUTED by Python will > a non ASCII byte string object be created. Like I said, 'file' doesn't > know the first thing about Python syntax, nor should it. Technically, it's not ASCII, since ASCII only knows about bytes \x00 through \x7F (decimal 0 through 127). That's why it isn't correct to describe Python bytes strings as "ASCII strings". They're byte strings that happen to be displayed as ASCII-plus-other-stuff. -- Steven From rosuav at gmail.com Wed Sep 4 23:59:17 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 Sep 2013 13:59:17 +1000 Subject: UnicodeDecodeError issue In-Reply-To: <5227f57e$0$2743$c3e8da3$76491128@news.astraweb.com> References: <5222fc40$0$6599$c3e8da3$5496439d@news.astraweb.com> <3e549761-4323-4379-b4e4-ce51597d59c0@googlegroups.com> <5227f57e$0$2743$c3e8da3$76491128@news.astraweb.com> Message-ID: On Thu, Sep 5, 2013 at 1:07 PM, Steven D'Aprano wrote: > Technically, it's not ASCII, since ASCII only knows about bytes \x00 > through \x7F (decimal 0 through 127). That's why it isn't correct to > describe Python bytes strings as "ASCII strings". They're byte strings > that happen to be displayed as ASCII-plus-other-stuff. The line of code is itself entirely ASCII. The sequence REVERSE SOLIDUS, LATIN SMALL LETTER X, LATIN SMALL LETTER B, DIGIT SIX is four Unicode characters that are in the ASCII set. That Python interprets them as representing the byte value 182 doesn't change that; the line of code *is* ASCII. ChrisA From steve at pearwood.info Thu Sep 5 01:28:07 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 05 Sep 2013 05:28:07 GMT Subject: UnicodeDecodeError issue References: <5222fc40$0$6599$c3e8da3$5496439d@news.astraweb.com> <3e549761-4323-4379-b4e4-ce51597d59c0@googlegroups.com> <5227f57e$0$2743$c3e8da3$76491128@news.astraweb.com> Message-ID: <52281667$0$2743$c3e8da3$76491128@news.astraweb.com> On Thu, 05 Sep 2013 13:59:17 +1000, Chris Angelico wrote: > On Thu, Sep 5, 2013 at 1:07 PM, Steven D'Aprano > wrote: >> Technically, it's not ASCII, since ASCII only knows about bytes \x00 >> through \x7F (decimal 0 through 127). That's why it isn't correct to >> describe Python bytes strings as "ASCII strings". They're byte strings >> that happen to be displayed as ASCII-plus-other-stuff. > > The line of code is itself entirely ASCII. ......^^^^^^^^^^^^^^^^^^^^^^ Ah, so it is. Sorry, I got confused about what was being spoken about. Apologies to Dave for casting aspersions on his knowledge :-) -- Steven From wayne at waynewerner.com Wed Sep 11 07:36:11 2013 From: wayne at waynewerner.com (Wayne Werner) Date: Wed, 11 Sep 2013 06:36:11 -0500 (CDT) Subject: print function and unwanted trailing space In-Reply-To: <5221a693$0$2059$426a74cc@news.free.fr> References: <5221a693$0$2059$426a74cc@news.free.fr> Message-ID: On Sat, 31 Aug 2013, candide wrote: > # ----------------------------- > for i in range(5): > print(i, end=' ') # <- The last ' ' is unwanted > print() > # ----------------------------- Then why not define end='' instead? -W From marduk at letterboxes.org Thu Sep 12 15:25:30 2013 From: marduk at letterboxes.org (Albert Hopkins) Date: Thu, 12 Sep 2013 15:25:30 -0400 Subject: print function and unwanted trailing space In-Reply-To: References: <5221a693$0$2059$426a74cc@news.free.fr> Message-ID: <1379013930.948.21264905.546552BC@webmail.messagingengine.com> On Wed, Sep 11, 2013, at 07:36 AM, Wayne Werner wrote: > On Sat, 31 Aug 2013, candide wrote: > > # ----------------------------- > > for i in range(5): > > print(i, end=' ') # <- The last ' ' is unwanted > > print() > > # ----------------------------- > > Then why not define end='' instead? I think the OP meant that ' ' is wanted up until the final item.. so something like for i in range(4): print(i, end=' ') print(4) or, better: print(' '.join(str(i) for i in range(5))) From __peter__ at web.de Sun Sep 1 02:53:10 2013 From: __peter__ at web.de (Peter Otten) Date: Sun, 01 Sep 2013 08:53:10 +0200 Subject: argparse - specify order of argument parsing? References: Message-ID: Eduardo Alvarez wrote: > When using argparse, is there a way to specify in what order arguments > get parsed? I am writing a script whose parameters can be modified in > the following order: > > Defaults -> config file -> command-line switches. > > However, I want to give the option of specifying a config file using a > command line switch as well, so logically, that file should be parsed > before any other arguments are applied. However, it seems that > parse_args() parses arguments in the order they're given, so if the > config file switch is not given first, the config file will overwrite > whatever was in the command-line switches, which should have higher > priority. > > Thank you in advance, If you use http://docs.python.org/dev/library/argparse.html#fromfile-prefix-chars to read the configuration file it should be obvious to the user that the order is significant. You can even construct multiple config files with partially overlapping options: $ cat load_options.py import argparse parser = argparse.ArgumentParser(fromfile_prefix_chars="@") parser.add_argument("--infile") parser.add_argument("--outfile") parser.add_argument("--logfile") print(parser.parse_args()) $ cat option1.txt --infile=alpha.txt --outfile=beta.txt $ cat option2.txt --outfile=GAMMA.txt --logfile=DELTA.txt $ python load_options.py @option1.txt @option2.txt Namespace(infile='alpha.txt', logfile='DELTA.txt', outfile='GAMMA.txt') $ python load_options.py @option2.txt @option1.txt Namespace(infile='alpha.txt', logfile='DELTA.txt', outfile='beta.txt') If you insist you could modify the argument list with the following hack: sys.argv[1:] = sorted(sys.argv[1:], key=lambda arg: arg.startswith("@"), reverse=True) There might also be a way to utilize parse_known_args(). From anntzer.lee at gmail.com Sun Sep 1 00:51:47 2013 From: anntzer.lee at gmail.com (anntzer.lee at gmail.com) Date: Sat, 31 Aug 2013 21:51:47 -0700 (PDT) Subject: gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow) In-Reply-To: References: Message-ID: <48c8f8ca-d8c1-4a60-ba7f-8e8b00993f15@googlegroups.com> It is the call to gethostbyname_ex that is very slow. The call to gethostname is quick (and returns the same string as /usr/bin/hostname). On Saturday, August 31, 2013 6:01:00 PM UTC-7, Roy Smith wrote: > In article , > > anntzer.lee at gmail.com wrote: > > > > > Hi, > > > > > > At startup, IPython (qtconsole) calls > > > "socket.gethostbyname_ex(socket.gethostname())[2]" to find a list of IP > > > addresses that point to the machine. On a Linux server that I manage this > > > call is extremely slow (>20s)... which I have trouble understanding as "ip > > > addr show" seems to give the same information nearly instantaneously. Is > > > there anything I can do to make this faster? Can this be a network > > > configuration issue (I am behind a router)? > > > > It's almost certainly some sort of configuration issue which is causing > > some DNS query to timeout. The first step, is to figure out which part > > is taking so long. Open up a python shell and run: > > > > >>> name = socket.gethostname() > > > > see how long that takes and what it returns. Then, assuming it returns > > a string containing your hostname (massive handwave about what that > > actually means), try > > > > >>> socket.gethostbyname_ex(name) > > > > and see how long that takes and what it returns. At least at that point > > you'll have cut the problem in half. > > > > If I had to guess, you've got a missing PTR record, because that's what > > most people screw up. From torriem at gmail.com Sun Sep 1 01:06:43 2013 From: torriem at gmail.com (Michael Torrie) Date: Sat, 31 Aug 2013 23:06:43 -0600 Subject: gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow) In-Reply-To: <48c8f8ca-d8c1-4a60-ba7f-8e8b00993f15@googlegroups.com> References: <48c8f8ca-d8c1-4a60-ba7f-8e8b00993f15@googlegroups.com> Message-ID: <5222CB63.9040304@gmail.com> On 08/31/2013 10:51 PM, anntzer.lee at gmail.com wrote: > It is the call to gethostbyname_ex that is very slow. The call to > gethostname is quick (and returns the same string as > /usr/bin/hostname). What gethostbyname_ex and /usr/bin/hostname do are very different things. gethostbyname_ex does a DNS lookup against a server. /usr/bin/hostname just checks a local computer setting. I don't see why you are comparing the two. /usr/bin/hostname is not going to help you find a list of IP addresses that point to a machine. From roy at panix.com Sun Sep 1 06:57:37 2013 From: roy at panix.com (Roy Smith) Date: Sun, 01 Sep 2013 06:57:37 -0400 Subject: gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow) References: <48c8f8ca-d8c1-4a60-ba7f-8e8b00993f15@googlegroups.com> Message-ID: In article <48c8f8ca-d8c1-4a60-ba7f-8e8b00993f15 at googlegroups.com>, anntzer.lee at gmail.com wrote: > It is the call to gethostbyname_ex that is very slow. The call to > gethostname is quick (and returns the same string as /usr/bin/hostname). First, please stop posting with Google Groups. It makes a total mess of the quoted text. Next, what happens when you use the command-line tools (nslookup or dig) to translate your hostname to an IP address, and what happens if you then try to reverse translate that IP address back to a name? > This issue is independent of IPython: > > $ time python -c 'import socket; > print(socket.gethostbyname_ex(socket.gethostname())[2])' > ['192.168.0.102'] > python -c 0.07s user 0.02s system 0% cpu 28.190 total The real point is not that it's independent of IPython, it has nothing to do with Python at all. What you've got here is a network configuration issue. You would do better to recreate this problem with the native OS command line tools and then ask about it on a forum dedicated to your operating system. From anntzer.lee at gmail.com Sun Sep 1 13:13:36 2013 From: anntzer.lee at gmail.com (anntzer.lee at gmail.com) Date: Sun, 1 Sep 2013 10:13:36 -0700 (PDT) Subject: gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow) In-Reply-To: References: <48c8f8ca-d8c1-4a60-ba7f-8e8b00993f15@googlegroups.com> Message-ID: <6dd8a3da-d2f5-4b6b-aa44-b256a4cb3237@googlegroups.com> On Saturday, August 31, 2013 10:06:43 PM UTC-7, Michael Torrie wrote: > On 08/31/2013 10:51 PM, anntzer.lee at gmail.com wrote: > > > It is the call to gethostbyname_ex that is very slow. The call to > > gethostname is quick (and returns the same string as > > /usr/bin/hostname). > > What gethostbyname_ex and /usr/bin/hostname do are very different > things. gethostbyname_ex does a DNS lookup against a server. > /usr/bin/hostname just checks a local computer setting. I don't see why > you are comparing the two. /usr/bin/hostname is not going to help you > find a list of IP addresses that point to a machine. I was just replying to the previous comment "name = socket.gethostname() see how long that takes and what it returns. Then, assuming it returns a string containing your hostname (massive handwave about what that actually means)", saying that gethostname resolves my own hostname instantaneously. From rosuav at gmail.com Sun Sep 1 07:37:34 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 1 Sep 2013 21:37:34 +1000 Subject: gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow) In-Reply-To: References: Message-ID: On Sun, Sep 1, 2013 at 10:03 AM, wrote: > At startup, IPython (qtconsole) calls "socket.gethostbyname_ex(socket.gethostname())[2]" to find a list of IP addresses that point to the machine. On a Linux server that I manage this call is extremely slow (>20s)... which I have trouble understanding as "ip addr show" seems to give the same information nearly instantaneously. Is there anything I can do to make this faster? Can this be a network configuration issue (I am behind a router)? Yes, it most definitely CAN be a network config issue. The C function you want to be calling is getifaddrs(), and I don't think there's a way to call that from core Python. But a Google search for 'python getifaddrs' shows up a few third-party modules that might be of use to you; that'd be a lot quicker and more reliable than trying to look up your own hostname and depending on the results. ChrisA From anntzer.lee at gmail.com Sun Sep 1 16:37:38 2013 From: anntzer.lee at gmail.com (anntzer.lee at gmail.com) Date: Sun, 1 Sep 2013 13:37:38 -0700 (PDT) Subject: gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow) In-Reply-To: References: Message-ID: <9cca25d5-186d-4a92-893c-f7985fad7a55@googlegroups.com> On Sunday, September 1, 2013 4:37:34 AM UTC-7, Chris Angelico wrote: > Yes, it most definitely CAN be a network config issue. The C function > you want to be calling is getifaddrs(), and I don't think there's a > way to call that from core Python. But a Google search for 'python > getifaddrs' shows up a few third-party modules that might be of use to > you; that'd be a lot quicker and more reliable than trying to look up > your own hostname and depending on the results. > > ChrisA I tried using netifaces (https://pypi.python.org/pypi/netifaces) which seems to rely on getifaddrs (according to the doc, I didn't check the source). Again, it returns nearly instantaneously the correct IP address. From rosuav at gmail.com Sun Sep 1 17:03:56 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 Sep 2013 07:03:56 +1000 Subject: gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow) In-Reply-To: <9cca25d5-186d-4a92-893c-f7985fad7a55@googlegroups.com> References: <9cca25d5-186d-4a92-893c-f7985fad7a55@googlegroups.com> Message-ID: On Mon, Sep 2, 2013 at 6:37 AM, wrote: > On Sunday, September 1, 2013 4:37:34 AM UTC-7, Chris Angelico wrote: > >> Yes, it most definitely CAN be a network config issue. The C function >> you want to be calling is getifaddrs(), and I don't think there's a >> way to call that from core Python. But a Google search for 'python >> getifaddrs' shows up a few third-party modules that might be of use to >> you; that'd be a lot quicker and more reliable than trying to look up >> your own hostname and depending on the results. >> >> ChrisA > > I tried using netifaces (https://pypi.python.org/pypi/netifaces) which seems to rely on getifaddrs (according to the doc, I didn't check the source). Again, it returns nearly instantaneously the correct IP address. Perfect! ChrisA From anntzer.lee at gmail.com Mon Sep 2 01:28:21 2013 From: anntzer.lee at gmail.com (anntzer.lee at gmail.com) Date: Sun, 1 Sep 2013 22:28:21 -0700 (PDT) Subject: gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow) In-Reply-To: References: <9cca25d5-186d-4a92-893c-f7985fad7a55@googlegroups.com> Message-ID: <00843d58-db21-4cf0-9430-85362a1dd66f@googlegroups.com> On Sunday, September 1, 2013 2:03:56 PM UTC-7, Chris Angelico wrote: > > I tried using netifaces (https://pypi.python.org/pypi/netifaces) which seems to rely on getifaddrs (according to the doc, I didn't check the source). Again, it returns nearly instantaneously the correct IP address. > > Perfect! > > ChrisA Not really for my use case -- it isn't that *I* want to know my public IP address, but rather that IPython wants to know it. Of course I could patch IPython's source to use netifaces but that sounds like an overkill. As it happens I found a better way: just add the proper entry to /etc/hosts. Still, thanks for the suggestions. Antony From rosuav at gmail.com Mon Sep 2 06:42:12 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 Sep 2013 20:42:12 +1000 Subject: gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow) In-Reply-To: <00843d58-db21-4cf0-9430-85362a1dd66f@googlegroups.com> References: <9cca25d5-186d-4a92-893c-f7985fad7a55@googlegroups.com> <00843d58-db21-4cf0-9430-85362a1dd66f@googlegroups.com> Message-ID: On Mon, Sep 2, 2013 at 3:28 PM, wrote: > On Sunday, September 1, 2013 2:03:56 PM UTC-7, Chris Angelico wrote: > >> > I tried using netifaces (https://pypi.python.org/pypi/netifaces) which seems to rely on getifaddrs (according to the doc, I didn't check the source). Again, it returns nearly instantaneously the correct IP address. >> >> Perfect! >> >> ChrisA > > Not really for my use case -- it isn't that *I* want to know my public IP address, but rather that IPython wants to know it. Of course I could patch IPython's source to use netifaces but that sounds like an overkill. > > As it happens I found a better way: just add the proper entry to /etc/hosts. Ah, I see what you mean. If it were possible with core Python, I would recommend raising a bug with IPython, as the current method is susceptible to external issues. But to just get your problem solved, yes, a host file entry sounds like it's the best way to go. ChrisA From roy at panix.com Mon Sep 2 08:45:26 2013 From: roy at panix.com (Roy Smith) Date: Mon, 02 Sep 2013 08:45:26 -0400 Subject: gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow) References: <9cca25d5-186d-4a92-893c-f7985fad7a55@googlegroups.com> <00843d58-db21-4cf0-9430-85362a1dd66f@googlegroups.com> Message-ID: In article <00843d58-db21-4cf0-9430-85362a1dd66f at googlegroups.com>, anntzer.lee at gmail.com wrote: > As it happens I found a better way: just add the proper entry to /etc/hosts. You have not found a better way. You still have a network (or more specifically, DNS) configuration that's broken. What you have found is a pragmatic way to solve your immediate problem and get some work done. That is certainly useful (and I've done it plenty of times), but you need to understand that what you've done is hidden the problem, not solved it. From anntzer.lee at gmail.com Mon Sep 2 13:52:36 2013 From: anntzer.lee at gmail.com (anntzer.lee at gmail.com) Date: Mon, 2 Sep 2013 10:52:36 -0700 (PDT) Subject: gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow) In-Reply-To: References: <9cca25d5-186d-4a92-893c-f7985fad7a55@googlegroups.com> <00843d58-db21-4cf0-9430-85362a1dd66f@googlegroups.com> Message-ID: <3f4962dc-b139-4a67-8d0f-f2d59952a45f@googlegroups.com> On Monday, September 2, 2013 5:45:26 AM UTC-7, Roy Smith wrote: > In article <00843d58-db21-4cf0-9430-85362a1dd66f at googlegroups.com>, > anntzer.lee at gmail.com wrote: > > > As it happens I found a better way: just add the proper entry to /etc/hosts. > > You have not found a better way. You still have a network (or more > specifically, DNS) configuration that's broken. > > What you have found is a pragmatic way to solve your immediate problem > and get some work done. That is certainly useful (and I've done it > plenty of times), but you need to understand that what you've done is > hidden the problem, not solved it. To be honest, knowing nothing about DNS configuration, I don't even know if adding the entry to /etc/hosts is the "proper" fix or if the issue should be fixed somewhere else (or perhaps "didn't know", as you seem to imply that that is not the correct way). From rosuav at gmail.com Mon Sep 2 17:12:45 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 Sep 2013 07:12:45 +1000 Subject: gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow) In-Reply-To: <3f4962dc-b139-4a67-8d0f-f2d59952a45f@googlegroups.com> References: <9cca25d5-186d-4a92-893c-f7985fad7a55@googlegroups.com> <00843d58-db21-4cf0-9430-85362a1dd66f@googlegroups.com> <3f4962dc-b139-4a67-8d0f-f2d59952a45f@googlegroups.com> Message-ID: On Tue, Sep 3, 2013 at 3:52 AM, wrote: > To be honest, knowing nothing about DNS configuration, I don't even know if adding the entry to /etc/hosts is the "proper" fix or if the issue should be fixed somewhere else (or perhaps "didn't know", as you seem to imply that that is not the correct way). Since you can't change the code, it's almost certainly the best solution available to you. It's more-or-less equivalent to speeding up your DNS lookups massively. The main downside is that if something changes, you need to change it in DNS and in your hosts file; as Roy says, it's a pragmatic solution rather than a perfect one. ChrisA From rui.maciel at gmail.com Sun Sep 1 07:17:26 2013 From: rui.maciel at gmail.com (Rui Maciel) Date: Sun, 01 Sep 2013 12:17:26 +0100 Subject: Newbie: use of built-in exceptions Message-ID: Are there any guidelines on the use (and abuse) of Python's built-in exceptions, telling where it's ok to raise them and where it's preferable to define custom exceptions instead? Thanks in advance, Rui Maciel From kwpolska at gmail.com Sun Sep 1 07:26:30 2013 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Sun, 1 Sep 2013 13:26:30 +0200 Subject: Newbie: use of built-in exceptions In-Reply-To: References: Message-ID: On Sun, Sep 1, 2013 at 1:17 PM, Rui Maciel wrote: > Are there any guidelines on the use (and abuse) of Python's built-in exceptions, telling where > it's ok to raise them and where it's preferable to define custom exceptions instead? There are no rules. You should use common sense instead: if the exception fits your needs (eg. ValueError when incorrect output occurs) then use it. -- Chris ?Kwpolska? Warrick PGP: 5EAAEA16 stop html mail | always bottom-post | only UTF-8 makes sense From cs at zip.com.au Mon Sep 2 20:36:42 2013 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 3 Sep 2013 10:36:42 +1000 Subject: Newbie: use of built-in exceptions In-Reply-To: References: Message-ID: <20130903003642.GA68757@cskk.homeip.net> On 01Sep2013 13:26, Chris ?Kwpolska? Warrick wrote: | On Sun, Sep 1, 2013 at 1:17 PM, Rui Maciel wrote: | > Are there any guidelines on the use (and abuse) of Python's built-in exceptions, telling where | > it's ok to raise them and where it's preferable to define custom exceptions instead? | | There are no rules. You should use common sense instead: if the | exception fits your needs (eg. ValueError when incorrect output | occurs) then use it. A converse rule I use is: do I need to catch this specially and commonly? My usual example is parsing: one could legitimately raise ValueError for bad syntax, but I'd rather raise ValueError only for mistaken calls to functions with bad values, so: class ParseError(ValueError): def __init__(self, context, complaint): self.context = context # eg: file, lineno ValueError.__init__(self, complaint) def parse(filename): with open(filename) as fp: ... raise ParseError( (filename, lineno), "comma expected" ) try: result = parse("datafile") except ParseError as e: ... This also shows any reason: adding extra context information to an expection. This is all just examples of course. Cheers, -- Cameron Simpson Whether you're getting laid or not, the glass is still half empty. - Dan Hillman, alt.peeves Massgasm From rui.maciel at gmail.com Mon Sep 2 13:32:53 2013 From: rui.maciel at gmail.com (Rui Maciel) Date: Mon, 02 Sep 2013 18:32:53 +0100 Subject: Newbie: use of built-in exceptions References: Message-ID: Chris ?Kwpolska? Warrick wrote: > There are no rules. You should use common sense instead: if the > exception fits your needs (eg. ValueError when incorrect output > occurs) then use it. Ok, thanks for the tip. Rui Maciel From mohsen at pahlevanzadeh.org Sun Sep 1 14:53:37 2013 From: mohsen at pahlevanzadeh.org (Mohsen Pahlevanzadeh) Date: Sun, 01 Sep 2013 23:23:37 +0430 Subject: What does mean @ sign in first of statement Message-ID: <1378061617.6921.3.camel@debian> Dear all, What does mean @ sign in first of statement such as: ////////////////////// @hybrid_property def fullname(self): return self.firstname + " " + self.lastname /////////////////// Sorry for cheap question. Yours, Mohsen From kwpolska at gmail.com Sun Sep 1 14:57:20 2013 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Sun, 1 Sep 2013 20:57:20 +0200 Subject: What does mean @ sign in first of statement In-Reply-To: <1378061617.6921.3.camel@debian> References: <1378061617.6921.3.camel@debian> Message-ID: On Sun, Sep 1, 2013 at 8:53 PM, Mohsen Pahlevanzadeh wrote: > Dear all, > > What does mean @ sign in first of statement such as: > > ////////////////////// > @hybrid_property > def fullname(self): > return self.firstname + " " + self.lastname > /////////////////// > > Sorry for cheap question. > > Yours, > Mohsen > > -- > http://mail.python.org/mailman/listinfo/python-list @hybrid_property is a decorator. Great resource: http://simeonfranklin.com/blog/2012/jul/1/python-decorators-in-12-steps/ -- Chris ?Kwpolska? Warrick PGP: 5EAAEA16 stop html mail | always bottom-post | only UTF-8 makes sense From tausciam at gmail.com Sun Sep 1 15:39:30 2013 From: tausciam at gmail.com (tausciam at gmail.com) Date: Sun, 1 Sep 2013 12:39:30 -0700 (PDT) Subject: connecting clicked signal to different slots depending on function executing Message-ID: I have one tablewidget I want to use for two different uses, audio and video. If cover art is displayed and the user clicks the cover art, it emits a cell clicked and gets the list of the songs. If video thumbnails are displayed, it emits a cell clicked and plays the video fullscreen. So, I have the same signal going to two different slots. Is there any way to break that connection before I define it again? In other words, in the audio section I could have something like: [break video signal/slot connection] self.tableWidget.cellClicked.connect(self.audiocell_clicked) and then for the video section: [break audio signal/slot connection] self.tableWidget.cellClicked.connect(self.videocell_clicked) From tausciam at gmail.com Sun Sep 1 15:44:44 2013 From: tausciam at gmail.com (tausciam at gmail.com) Date: Sun, 1 Sep 2013 12:44:44 -0700 (PDT) Subject: connecting clicked signal to different slots depending on function executing In-Reply-To: References: Message-ID: <0e2cc185-70f5-4e43-a555-af3e408f7145@googlegroups.com> I should add that I know about: self.tableWidget.cellClicked.disconnect(self.videocell_clicked) but, when I do that, if the connection is not there, then the program crashes. So, how could I check to see if the connection is there then break it? From tausciam at gmail.com Sun Sep 1 15:57:16 2013 From: tausciam at gmail.com (tausciam at gmail.com) Date: Sun, 1 Sep 2013 12:57:16 -0700 (PDT) Subject: connecting clicked signal to different slots depending on function executing In-Reply-To: References: Message-ID: <6d0228a9-d9a2-4f4e-acdd-46abbafa623a@googlegroups.com> Nevermind..... I found that it would let me create the connection again then when I disconnected, it would disconnect all of the instances... so I ended up with: self.tableWidget.cellClicked.connect(self.videocell_clicked) self.tableWidget.cellClicked.disconnect(self.videocell_clicked) self.tableWidget.cellClicked.connect(self.audiocell_clicked) If there's a better way to do this, I'd be interested in hearing about it. From gary719_list1 at verizon.net Sun Sep 1 16:52:01 2013 From: gary719_list1 at verizon.net (Gary Roach) Date: Sun, 01 Sep 2013 13:52:01 -0700 Subject: MySQL data types vs Django/Python data types Message-ID: <5223A8F1.9080905@verizon.net> Hi all, System: Debian Wheezy Linux Python 2.7 Django 1.5 MySql 5.5 I am new to Python and Django and am having trouble matching Python data types with those of MySQL. MySQL has about 7 basic data types including Blobs, Binaries, etc. It also has a rich selection of geometry types. In addition, types like INT have 7 or 8 different options like Primary Key, zero fill, auto inc, etc. I can't seem to find anything in python to match these. I am trying to build a model.py for an existing database that was created with MySQL Workbench. I do not wish to use anything other than MySQL because of the complexity of my storage needs (searchable text, PDF, Audio, Video and Photos). The text searches will often be word phrase searches through thousands of documents. I need the speed and the data type flexibility. How do I build or modify a model.py to do this. I really don't want to write a model.py manually. That would really be a major pain. Workbench to the database an import to Django and edit is my choice. Unfortunately, the model.py produced has lost most of the functionality of the original database and I can't seem to figure out how to fix it. Any help will be sincerely appreciated. Gary R. From fabiosantosart at gmail.com Wed Sep 4 05:28:44 2013 From: fabiosantosart at gmail.com (=?ISO-8859-1?Q?F=E1bio_Santos?=) Date: Wed, 4 Sep 2013 10:28:44 +0100 Subject: MySQL data types vs Django/Python data types In-Reply-To: <5223A8F1.9080905@verizon.net> References: <5223A8F1.9080905@verizon.net> Message-ID: On 1 Sep 2013 21:54, "Gary Roach" wrote: > > Hi all, > > System: > Debian Wheezy Linux > Python 2.7 > Django 1.5 > MySql 5.5 > > I am new to Python and Django and am having trouble matching Python data types with those of MySQL. MySQL has about 7 basic data types including Blobs, Binaries, etc. It also has a rich selection of geometry types. In addition, types like INT have 7 or 8 different options like Primary Key, zero fill, auto inc, etc. I can't seem to find anything in python to match these. I am trying to build a model.py for an existing database that was created with MySQL Workbench. First, I want to state that you need to understand that Django was designed to help build simple, common use case web apps. Database skins, as someone put it. The ORM is very easy to use, although it is not well prepared for some things. It also has a very nice advantage, which is being compatible with many RDBMS so you can have postgresql on the production server and sqlite on your development machine. This ends up being bad too. For instance, if it is not possible to do something in a specific rdbms, for instance, let's say blobs, Django will not be able to implement it because it has to support those several rdbms. There are many hacks ( http://djangosnippets.org/snippets/1597/ ) but hacks will be hacks and you want your app to be reliable and not compromise your code quality right from the start, right? Many field options have equivalents in Django (primary key, auto increment). You just have to find them. For auto increment there is AutoField. Primary key is an option of the base Field (so you can provide it as a keyword argument to any field). Also if you want gis geometry data types (is that what you meant?) you can install and use geodjango. > I do not wish to use anything other than MySQL because of the complexity of my storage needs (searchable text, PDF, Audio, Video and Photos). The text searches will often be word phrase searches through thousands of documents. I need the speed and the data type flexibility. Are you sure mysql is up to it? For searchable text you will want to have an index, and while mysql's FULLTEXT kind of works, it is clearly not a core feature. Some options for it are enabled or disabled in compile time. Also, I won't judge but it's often wrong to use a rdbms to store PDF/audio/video. Those belong in the file system or nosql storage. > How do I build or modify a model.py to do this. I really don't want to write a model.py manually. That would really be a major pain. Workbench to the database an import to Django and edit is my choice. Unfortunately, the model.py produced has lost most of the functionality of the original database and I can't seem to figure out how to fix it. > > Any help will be sincerely appreciated. > > Gary R. A lot can be done by using the database manually. Django helps you a bit here, for instance it gives you access to the database cursor for raw SQL access to the database, supports custom fields, and every orm query "chain" (like MyModel.objects.all().filter(...)) can be incremented with raw SQL "where" and "select" clauses. But you might not want to be using Django or at least not its ORM. -------------- next part -------------- An HTML attachment was scrubbed... URL: From materile11 at gmail.com Sun Sep 1 20:03:40 2013 From: materile11 at gmail.com (materile11 at gmail.com) Date: Sun, 1 Sep 2013 17:03:40 -0700 (PDT) Subject: =?ISO-8859-1?Q?How_to_split_with_=22=5C=22_character=2C_and_licence_copylef?= =?ISO-8859-1?Q?t_mirror_of_=A9?= Message-ID: Hello everybody I'm trying to run this: >>> a = 'E:\Dropbox\jjfsdjjsdklfj\sdfjksdfkjslkj\flute.wav' >>> a.split('\') SyntaxError: EOL while scanning string literal I think that the character '\' is the problem, but unfortunately I'm developing a small app for windows and I need to show only the name of the .wav file, in this case 'flute.wav'. I also want to know how to mirror a character, in my case this one ?, because I'll use the Copyleft http://en.wikipedia.org/wiki/Copyleft to distribute my app. Thanks. From cs at zip.com.au Sun Sep 1 20:23:41 2013 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 2 Sep 2013 10:23:41 +1000 Subject: How to split with "\" =?utf-8?Q?charac?= =?utf-8?Q?ter=2C_and_licence_copyleft_mirror_of_=C2=A9?= In-Reply-To: References: Message-ID: <20130902002341.GA92516@cskk.homeip.net> On 01Sep2013 17:03, materile11 at gmail.com wrote: | | >>> a = 'E:\Dropbox\jjfsdjjsdklfj\sdfjksdfkjslkj\flute.wav' | >>> a.split('\') | SyntaxError: EOL while scanning string literal | | | I think that the character '\' is the problem, but unfortunately I'm developing a small app for windows and I need to show only the name of the .wav file, in this case 'flute.wav'. Firstly, you want to say '\\' for a slosh (just as you would say '\n' for a linefeed). However, you really should use the os.path module, in particular os.path.split(). Have a read of: http://docs.python.org/3/library/os.path.html#module-os.path http://docs.python.org/2/library/os.path.html#module-os.path | I also want to know how to mirror a character, in my case this | one ?, because I'll use the Copyleft http://en.wikipedia.org/wiki/Copyleft | to distribute my app. Isn't that a copyright symbol? I'd have a look at the "uncidoedata" module, myself. Cheers, -- Cameron Simpson Just because Unix is a multiuser system doesn't mean I want to share it with anybody! - Paul Tomblin, in rec.aviation.military From python.list at tim.thechases.com Sun Sep 1 20:40:33 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 1 Sep 2013 19:40:33 -0500 Subject: How to split with "\" character, and licence copyleft mirror of =?UTF-8?B?wqk=?= In-Reply-To: <20130902002341.GA92516@cskk.homeip.net> References: <20130902002341.GA92516@cskk.homeip.net> Message-ID: <20130901194033.307cde3c@bigbox.christie.dr> On 2013-09-02 10:23, Cameron Simpson wrote: > | I also want to know how to mirror a character, in my case this > | one ?, because I'll use the Copyleft > http://en.wikipedia.org/wiki/Copyleft | to distribute my app. > > Isn't that a copyright symbol? I'd have a look at the "uncidoedata" > module, myself. Thanks to his link (which would have been more helpful with the URL fragment: http://en.wikipedia.org/wiki/Copyleft#Symbol ), I suspect the he means that it should be "the mirror image of a copyright symbol". And that would be "unicodedata", not "uncidoedata" (I don't think that was the reversing he was talking about ;-) -tkc From python.list at tim.thechases.com Sun Sep 1 20:34:16 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 1 Sep 2013 19:34:16 -0500 Subject: How to split with "\" character, and licence copyleft mirror of =?UTF-8?B?wqk=?= In-Reply-To: References: Message-ID: <20130901193416.4c4fc064@bigbox.christie.dr> On 2013-09-01 17:03, materile11 at gmail.com wrote: > Hello everybody > I'm trying to run this: > > > >>> a = 'E:\Dropbox\jjfsdjjsdklfj\sdfjksdfkjslkj\flute.wav' > >>> a.split('\') > > SyntaxError: EOL while scanning string literal > > > I think that the character '\' is the problem, but unfortunately > I'm developing a small app for windows and I need to show only the > name of the .wav file, in this case 'flute.wav'. To directly answer your question, you need to escape the "\" so it's a.split('\\') That said, it's far better to use Python's built-ins to do the processing for you: >>> import os >>> print os.path.basename(a) flute.wav which does what you want *and* works cross-platform: [on Linux] >>> a = '/home/tkc/path/to/flute.wav' >>> print os.path.basename(a) flute.wav > I also want to know how to mirror a character, in my case this one > ?, because I'll use the Copyleft This can't be done in much of a general way: Unicode doesn't specify this character, and the URL you provided suggests combining two Unicode characters to get ?? Unfortunately, (1) it requires a display that knows how to produce that, which many terminals can't; and (2) it's purely visual, not semantic. If that's what you really want, you should be able to use: copyleft_symbol = u"\u2184\u20DD" Just be aware that it may not always display the way you expect it to. -tkc From timr at probo.com Sun Sep 1 22:40:01 2013 From: timr at probo.com (Tim Roberts) Date: Sun, 01 Sep 2013 19:40:01 -0700 Subject: How to split with "\" character, and licence copyleft mirror of © References: Message-ID: materile11 at gmail.com wrote: >Hello everybody >I'm trying to run this: > > >>>> a = 'E:\Dropbox\jjfsdjjsdklfj\sdfjksdfkjslkj\flute.wav' >>>> a.split('\') > >SyntaxError: EOL while scanning string literal > > >I think that the character '\' is the problem, but unfortunately I'm >developing a small app for windows and I need to show only the name >of the .wav file, in this case 'flute.wav'. I assume you know that backslash has a special meaning in string constants. For example the string '\n\r' contains exactly two characters, and no backslashes. When you want to use an actual backslash in an ordinary string constant, you have to double it. So, you could have written your code as: a = 'E:\\Dropbox\\jjfsdjjsdklfj\\sdfjksdfkjslkj\\flute.wav' a.split('\\') Another altrnative is to use "raw" strings, in which backslashes are not interpreted: a = r'E:\Dropbox\jjfsdjjsdklfj\sdfjksdfkjslkj\flute.wav' a.split(r'\') I assume your filename is actually input to your program, and not as a constant in your code, so that may not be a problem. However, there is an API to do exactly what you're asking: >>> import os >>> a=r'E:\Dropbox\one\two\three\flute.wav' >>> os.path.split(a) ('E:\\Dropbox\\one\\two\\three', 'flute.wav') >>> os.path.split(a)[1] 'flute.wav' >>> >I also want to know how to mirror a character, in my case this one ?, >because I'll use the Copyleft http://en.wikipedia.org/wiki/Copyleft >to distribute my app. You can't "mirror" a character. That is an invented glyph that is not present in Unicode. Fortunately, the character doesn't have any legal meaning, so you can just include explanatory text in your description that identifies your license. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From ethan at stoneleaf.us Mon Sep 2 16:22:37 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 02 Sep 2013 13:22:37 -0700 Subject: =?ISO-8859-1?Q?Re=3A_How_to_split_with_=22=5C=22_cha?= =?ISO-8859-1?Q?racter=2C_and_licence_copyleft_mirror_of_=A9?= In-Reply-To: References: Message-ID: <5224F38D.3060506@stoneleaf.us> On 09/01/2013 07:40 PM, Tim Roberts wrote: > > Another altrnative is to use "raw" strings, in which backslashes are not > interpreted: > a = r'E:\Dropbox\jjfsdjjsdklfj\sdfjksdfkjslkj\flute.wav' > a.split(r'\') Not quite. --> r'\' File "", line 1 r'\' ^ SyntaxError: EOL while scanning string literal In a raw string, the backslash is buggy (IMNSHO) when it's the last character. Given the above error, you might think that to get a single-quote in a string delimited by single-quotes that you would use r'\'', but no: --> r'\'' "\\'" you get a backslash and a single-quote. And if you try to escape the backslash to get only one? --> r'\\' '\\\\' You get two. Grrrr. -- ~Ethan~ From steve+comp.lang.python at pearwood.info Mon Sep 2 22:06:54 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Sep 2013 02:06:54 GMT Subject: How to split with "\" character, and licence copyleft mirror of =?iso-8859-1?b?qQ==?= References: Message-ID: <5225443e$0$6599$c3e8da3$5496439d@news.astraweb.com> On Mon, 02 Sep 2013 13:22:37 -0700, Ethan Furman wrote: > In a raw string, the backslash is buggy (IMNSHO) when it's the last > character. Given the above error, you might think that to get a > single-quote in a string delimited by single-quotes that you would use > r'\'', but no: > > --> r'\'' > "\\'" You get exactly what you asked for. It's a raw string, right, so backslash has no special powers, and "backslash C" should give you exactly backslash followed by C, for any character C. Which is exactly what you do get. So that's working correctly, as far as it goes. > you get a backslash and a single-quote. And if you try to escape the > backslash to get only one? > > --> r'\\' > '\\\\' > > You get two. Grrrr. Again, working as expected. Since backslash has no special powers, if you enter a string with backslash backslash, you ought to get two backslashes. Just as you do. The *real* mystery is how the first example r'\'' succeeds in the first place, and that gives you a clue as to why r'\' doesn't. The answer is discussed in this bug report: http://bugs.python.org/issue1271 Summarising, the parser understands backslash as an escape character, and when it scans the string r'\'' the backslash escapes the inner quote, but then when Python generates the string it skips the backslash escape mechanism. Since the parser knows that backslash escapes, it fails to parse r'\' and you get a SyntaxError. If you stick stuff at the end of the line, you get the SyntaxError at another place: py> s = r'\'[:] # and more File "", line 1 s = r'\'[:] # and more ^ SyntaxError: EOL while scanning string literal So the real bug is with the parser. It is likely that nobody noticed this bug in the first place because the current behaviour doesn't matter for regexes, which is the primary purpose of raw strings. You can't end a regex with an unescaped backslash, so r'abc\'' is an illegal regex and it doesn't matter if you can't create it. -- Steven From python.list at tim.thechases.com Tue Sep 3 06:31:59 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 3 Sep 2013 05:31:59 -0500 Subject: How to split with "\" character, and licence copyleft mirror of =?UTF-8?B?wqk=?= In-Reply-To: <5225443e$0$6599$c3e8da3$5496439d@news.astraweb.com> References: <5225443e$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20130903053159.5221f886@bigbox.christie.dr> On 2013-09-03 02:06, Steven D'Aprano wrote: >> So the real bug is with the parser. > > It is likely that nobody noticed this bug in the first place > because the current behaviour doesn't matter for regexes, which is > the primary purpose of raw strings. You can't end a regex with an > unescaped backslash, so r'abc\'' is an illegal regex and it doesn't > matter if you can't create it. I'd contend that the two primary purposes of raw strings (this is starting to sound like a Spanish Inquisition sketch) are regexes and DOS/Win32 file path literals. And I hit this trailing-backslash case all the time, as Vim's path-completion defaults to putting the trailing backslash at the end. So I might be entering a literal like r"c:\win and hit which expands to r"c:\Windows\ for which I then need to both remove the backslash and close the quote. If Python's parser just blithely ignored terminal backslashes, I could just close the quote and get on with my day. -tkc From random832 at fastmail.us Tue Sep 3 14:31:59 2013 From: random832 at fastmail.us (random832 at fastmail.us) Date: Tue, 03 Sep 2013 14:31:59 -0400 Subject: =?UTF-8?Q?Re=3A=20How=20to=20split=20w?= =?UTF-8?Q?ith=20=22\=22=20character=2C?= =?UTF-8?Q?=20and=20licence=20copyl?= =?UTF-8?Q?eft=20mirror=20of=20=C2=A9?= In-Reply-To: <20130903053159.5221f886@bigbox.christie.dr> References: <5225443e$0$6599$c3e8da3$5496439d@news.astraweb.com> <20130903053159.5221f886@bigbox.christie.dr> Message-ID: <1378233119.19340.17472661.2B035ED4@webmail.messagingengine.com> On Tue, Sep 3, 2013, at 6:31, Tim Chase wrote: > I'd contend that the two primary purposes of raw strings (this is > starting to sound like a Spanish Inquisition sketch) are regexes and > DOS/Win32 file path literals. And I hit this trailing-backslash case > all the time, as Vim's path-completion defaults to putting the > trailing backslash at the end. So I might be entering a literal like > > r"c:\win > > and hit which expands to > > r"c:\Windows\ > > for which I then need to both remove the backslash and close the > quote. If Python's parser just blithely ignored terminal > backslashes, I could just close the quote and get on with my day. Of course, in 99% of situations where you can use a windows pathname in Python, you are free to use it with a forward slash instead of a backslash. The fact that you're using vim's file completion, which automatically normalizes the path separator, is why you're running into this issue when other people may not. Maybe enabling the 'shellslash' option (which changes it to use forward slash) will help you, though you should be aware this also affects the expansion of the % variable, even in the :! command, which can cause problems with certain usage patterns. From timr at probo.com Thu Sep 5 23:33:09 2013 From: timr at probo.com (Tim Roberts) Date: Thu, 05 Sep 2013 20:33:09 -0700 Subject: How to split with "\" character, and licence copyleft mirror of © References: <5225443e$0$6599$c3e8da3$5496439d@news.astraweb.com> <20130903053159.5221f886@bigbox.christie.dr> Message-ID: <84ji2914grkpljfom0kihfpfvlo33bssbo@4ax.com> random832 at fastmail.us wrote: > >Of course, in 99% of situations where you can use a windows pathname in >Python, you are free to use it with a forward slash instead of a >backslash. This is actually worth repeating, because it's not well known. ALL Windows APIs handle forward and backward slashes interchangably. It is only the command interpreter that requires the backslash. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From tjreedy at udel.edu Fri Sep 6 02:15:50 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 06 Sep 2013 02:15:50 -0400 Subject: =?UTF-8?B?UmU6IEhvdyB0byBzcGxpdCB3aXRoICJcIiBjaGFyYWN0ZXIsIGFuZCA=?= =?UTF-8?B?bGljZW5jZSBjb3B5bGVmdCBtaXJyb3Igb2Yg77+9?= In-Reply-To: <84ji2914grkpljfom0kihfpfvlo33bssbo@4ax.com> References: <5225443e$0$6599$c3e8da3$5496439d@news.astraweb.com> <20130903053159.5221f886@bigbox.christie.dr> <84ji2914grkpljfom0kihfpfvlo33bssbo@4ax.com> Message-ID: On 9/5/2013 11:33 PM, Tim Roberts wrote: > random832 at fastmail.us wrote: >> >> Of course, in 99% of situations where you can use a windows pathname in >> Python, you are free to use it with a forward slash instead of a >> backslash. > > This is actually worth repeating, because it's not well known. > > ALL Windows APIs handle forward and backward slashes interchangably. It is > only the command interpreter that requires the backslash. and only for the path the the command, when needed, and not for the arguments of the command. Example, in a python development directory > pcbuild\python_d tools/scripts/patchcheck.py -- Terry Jan Reedy From fabiosantosart at gmail.com Wed Sep 11 06:16:31 2013 From: fabiosantosart at gmail.com (=?ISO-8859-1?Q?F=E1bio_Santos?=) Date: Wed, 11 Sep 2013 11:16:31 +0100 Subject: =?UTF-8?Q?Re=3A_How_to_split_with_=22=5C=22_character=2C_and_licence_cop?= =?UTF-8?Q?yleft_mirror_of_=EF=BF=BD?= In-Reply-To: References: <5225443e$0$6599$c3e8da3$5496439d@news.astraweb.com> <20130903053159.5221f886@bigbox.christie.dr> <84ji2914grkpljfom0kihfpfvlo33bssbo@4ax.com> Message-ID: On 6 Sep 2013 07:18, "Terry Reedy" wrote: > > On 9/5/2013 11:33 PM, Tim Roberts wrote: >> >> random832 at fastmail.us wrote: >>> >>> >>> Of course, in 99% of situations where you can use a windows pathname in >>> Python, you are free to use it with a forward slash instead of a >>> backslash. >> >> >> This is actually worth repeating, because it's not well known. >> >> ALL Windows APIs handle forward and backward slashes interchangably. It is >> only the command interpreter that requires the backslash. > > > and only for the path the the command, when needed, and not for the arguments of the command. Example, in a python development directory > > > pcbuild\python_d tools/scripts/patchcheck.py > Interesting. I was pretty sure that forward slashes were allowed in this situation, just that tab completion didn't work unless you used backslashes. Well, fortunately I'm not able to check that these days. -------------- next part -------------- An HTML attachment was scrubbed... URL: From random832 at fastmail.us Fri Sep 6 09:29:00 2013 From: random832 at fastmail.us (random832 at fastmail.us) Date: Fri, 06 Sep 2013 09:29:00 -0400 Subject: =?UTF-8?Q?Re=3A=20How=20to=20split=20w?= =?UTF-8?Q?ith=20=22\=22=20character=2C?= =?UTF-8?Q?=20and=20licence=20copyl?= =?UTF-8?Q?eft=20mirror=20of=20=C2=A9?= In-Reply-To: <84ji2914grkpljfom0kihfpfvlo33bssbo@4ax.com> References: <5225443e$0$6599$c3e8da3$5496439d@news.astraweb.com> <20130903053159.5221f886@bigbox.christie.dr> <84ji2914grkpljfom0kihfpfvlo33bssbo@4ax.com> Message-ID: <1378474140.17410.18708105.4CC623F1@webmail.messagingengine.com> On Thu, Sep 5, 2013, at 23:33, Tim Roberts wrote: > random832 at fastmail.us wrote: > > > >Of course, in 99% of situations where you can use a windows pathname in > >Python, you are free to use it with a forward slash instead of a > >backslash. > > This is actually worth repeating, because it's not well known. > > ALL Windows APIs handle forward and backward slashes interchangably. It > is only the command interpreter that requires the backslash. Technically, that's not strictly true. There are certain strings you can open that will only work with backslashes, relating to device paths and/or the magic \\?\ prefix that removes the PATH_MAX limit (CreateFileW only). That was what I meant by 99%. And many situations in the command interpreter that require a backslash can be used with forward slash by surrounding the string in quotes, which you need to do anyway when you have an arbitrary string that may contain spaces. From materile11 at gmail.com Mon Sep 2 00:20:43 2013 From: materile11 at gmail.com (materile11 at gmail.com) Date: Sun, 1 Sep 2013 21:20:43 -0700 (PDT) Subject: =?ISO-8859-1?Q?Re=3A_How_to_split_with_=22=5C=22_character=2C_and_licence_cop?= =?ISO-8859-1?Q?yleft_mirror_of_=A9?= In-Reply-To: References: Message-ID: El domingo, 1 de septiembre de 2013 19:34:16 UTC-5, Tim Chase escribi?: > On 2013-09-01 17:03, materile11 at gmail.com wrote: > > > Hello everybody > > > I'm trying to run this: > > > > > > > > > >>> a = 'E:\Dropbox\jjfsdjjsdklfj\sdfjksdfkjslkj\flute.wav' > > > >>> a.split('\') > > > > > > SyntaxError: EOL while scanning string literal > > > > > > > > > I think that the character '\' is the problem, but unfortunately > > > I'm developing a small app for windows and I need to show only the > > > name of the .wav file, in this case 'flute.wav'. > > > > To directly answer your question, you need to escape the "\" so it's > > > > a.split('\\') > > > > That said, it's far better to use Python's built-ins to do the > > processing for you: > > > > >>> import os > > >>> print os.path.basename(a) > > flute.wav > > > > which does what you want *and* works cross-platform: > > > > [on Linux] > > >>> a = '/home/tkc/path/to/flute.wav' > > >>> print os.path.basename(a) > > flute.wav > > > > > I also want to know how to mirror a character, in my case this one > > > ?, because I'll use the Copyleft > > > > This can't be done in much of a general way: Unicode doesn't specify > > this character, and the URL you provided suggests combining two > > Unicode characters to get ?? Unfortunately, (1) it requires a > > display that knows how to produce that, which many terminals can't; > > and (2) it's purely visual, not semantic. If that's what you really > > want, you should be able to use: > > > > copyleft_symbol = u"\u2184\u20DD" > > > > Just be aware that it may not always display the way you expect it to. > > > > -tkc Thank you, I've used the os.path.basename to solve my problem. Regards. From mohsen at pahlevanzadeh.org Sun Sep 1 20:38:11 2013 From: mohsen at pahlevanzadeh.org (Mohsen Pahlevanzadeh) Date: Mon, 02 Sep 2013 05:08:11 +0430 Subject: pyqt and doesnt work out of mainwindow Message-ID: <1378082291.6921.4.camel@debian> Dear all, My question is at: http://stackoverflow.com/questions/18564293/main-program-work-good-but-when-put-it-into-a-function-doesnt-work-pyqt before answering, thank you.... Yours, mohsen From xxxxx at xxxxxx.xxx Sun Sep 1 21:26:16 2013 From: xxxxx at xxxxxx.xxx (Tommy Vee) Date: Sun, 01 Sep 2013 21:26:16 -0400 Subject: Simplex Algorithm Message-ID: <1PRUt.242963$ZD2.40442@fx19.iad> Anyone know where I can get an easy to use Python class or algorithm for the Simplex optimization algorithm? I've tried the one in the link below, but I can't figure out if a) I'm using it properly, or b) where to get the solution. BTW, I tried some test scenarios using MS Excel's "Solver" and just can't get this algorithm to match Excel's results (which is spot on). http://taw9.hubpages.com/hub/Simplex-Algorithm-in-Python BTW, if I can't something to work, I'm going to be forced to use the VBA programmatic Excel interface. That wouldn't be too bad, but the data comes from a DB and getting it properly positioned to use Excel's "Solver" is very painful. A Python approach would be much cleaner. Thanks, TommyVee From oscar.j.benjamin at gmail.com Mon Sep 2 04:06:38 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 2 Sep 2013 09:06:38 +0100 Subject: Simplex Algorithm In-Reply-To: <1PRUt.242963$ZD2.40442@fx19.iad> References: <1PRUt.242963$ZD2.40442@fx19.iad> Message-ID: On Sep 2, 2013 2:31 AM, "Tommy Vee" wrote: > > Anyone know where I can get an easy to use Python class or algorithm for the Simplex optimization algorithm? I've tried the one in the link below, but I can't figure out if a) I'm using it properly, or b) where to get the solution. BTW, I tried some test scenarios using MS Excel's "Solver" and just can't get this algorithm to match Excel's results (which is spot on). > > http://taw9.hubpages.com/hub/Simplex-Algorithm-in-Python > > BTW, if I can't something to work, I'm going to be forced to use the VBA programmatic Excel interface. That wouldn't be too bad, but the data comes from a DB and getting it properly positioned to use Excel's "Solver" is very painful. A Python approach would be much cleaner. Are you able to use scipy? It has the simplex algorithm (among many others) in its optimize module: http://docs.scipy.org/doc/scipy/reference/tutorial/optimize.html Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Mon Sep 2 05:45:07 2013 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 02 Sep 2013 10:45:07 +0100 Subject: Simplex Algorithm In-Reply-To: References: <1PRUt.242963$ZD2.40442@fx19.iad> Message-ID: On 2013-09-02 09:06, Oscar Benjamin wrote: > > On Sep 2, 2013 2:31 AM, "Tommy Vee" wrote: > > > > Anyone know where I can get an easy to use Python class or algorithm for the > Simplex optimization algorithm? I've tried the one in the link below, but I > can't figure out if a) I'm using it properly, or b) where to get the solution. > BTW, I tried some test scenarios using MS Excel's "Solver" and just can't get > this algorithm to match Excel's results (which is spot on). > > > > http://taw9.hubpages.com/hub/Simplex-Algorithm-in-Python > > > > BTW, if I can't something to work, I'm going to be forced to use the VBA > programmatic Excel interface. That wouldn't be too bad, but the data comes from > a DB and getting it properly positioned to use Excel's "Solver" is very painful. > A Python approach would be much cleaner. > > Are you able to use scipy? It has the simplex algorithm (among many others) in > its optimize module: > http://docs.scipy.org/doc/scipy/reference/tutorial/optimize.html Careful. Confusingly, there are two optimization algorithms known as "the simplex algorithm". The one the OP wants is for solving a linear programming problem (minimize a linear combination of variables subject to linear inequality constraints). The simplex algorithm that scipy implements is more properly termed "the Nelder-Mead simplex algorithm" for unconstrained local nonlinear minimization problems without derivative information. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From robert.kern at gmail.com Mon Sep 2 05:55:43 2013 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 02 Sep 2013 10:55:43 +0100 Subject: Simplex Algorithm In-Reply-To: <1PRUt.242963$ZD2.40442@fx19.iad> References: <1PRUt.242963$ZD2.40442@fx19.iad> Message-ID: On 2013-09-02 02:26, Tommy Vee wrote: > Anyone know where I can get an easy to use Python class or algorithm for the > Simplex optimization algorithm? I've tried the one in the link below, but I > can't figure out if a) I'm using it properly, or b) where to get the solution. > BTW, I tried some test scenarios using MS Excel's "Solver" and just can't get > this algorithm to match Excel's results (which is spot on). > > http://taw9.hubpages.com/hub/Simplex-Algorithm-in-Python > > BTW, if I can't something to work, I'm going to be forced to use the VBA > programmatic Excel interface. That wouldn't be too bad, but the data comes from > a DB and getting it properly positioned to use Excel's "Solver" is very > painful. A Python approach would be much cleaner. Can you show some of the test scenarios that you tried? There are different conventions in how to represent a linear programming problem, and different solvers may choose different conventions. You may have to convert between representations. You may have better luck with the PuLP interface: https://pypi.python.org/pypi/PuLP PuLP itself is just a modelling language rather than a solver, but the sources do contain compiled binaries for the CoinMP solver so it will work out-of-box on popular platforms, like Windows. https://projects.coin-or.org/CoinMP -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From vitaletom1 at gmail.com Mon Sep 2 10:42:47 2013 From: vitaletom1 at gmail.com (Tommy Vee) Date: Mon, 02 Sep 2013 10:42:47 -0400 Subject: Simplex Algorithm In-Reply-To: References: <1PRUt.242963$ZD2.40442@fx19.iad> Message-ID: <5224A3E7.1020200@xxxxxx.xxx> On 9/2/2013 4:06 AM, Oscar Benjamin wrote: > > On Sep 2, 2013 2:31 AM, "Tommy Vee" wrote: > > > > Anyone know where I can get an easy to use Python class or algorithm > for the Simplex optimization algorithm? I've tried the one in the link > below, but I can't figure out if a) I'm using it properly, or b) where > to get the solution. BTW, I tried some test scenarios using MS Excel's > "Solver" and just can't get this algorithm to match Excel's results > (which is spot on). > > > > http://taw9.hubpages.com/hub/Simplex-Algorithm-in-Python > > > > BTW, if I can't something to work, I'm going to be forced to use the > VBA programmatic Excel interface. That wouldn't be too bad, but the data > comes from a DB and getting it properly positioned to use Excel's > "Solver" is very painful. A Python approach would be much cleaner. > > Are you able to use scipy? It has the simplex algorithm (among many > others) in its optimize module: > http://docs.scipy.org/doc/scipy/reference/tutorial/optimize.html > > Oscar > scipy would be another possibility of last resort. I will take a look. Thanks. From xxxxx at xxxxxx.xxx Mon Sep 2 10:42:47 2013 From: xxxxx at xxxxxx.xxx (Tommy Vee) Date: Mon, 02 Sep 2013 10:42:47 -0400 Subject: Simplex Algorithm In-Reply-To: References: <1PRUt.242963$ZD2.40442@fx19.iad> Message-ID: <5224A3E7.1020200@xxxxxx.xxx> On 9/2/2013 4:06 AM, Oscar Benjamin wrote: > > On Sep 2, 2013 2:31 AM, "Tommy Vee" wrote: > > > > Anyone know where I can get an easy to use Python class or algorithm > for the Simplex optimization algorithm? I've tried the one in the link > below, but I can't figure out if a) I'm using it properly, or b) where > to get the solution. BTW, I tried some test scenarios using MS Excel's > "Solver" and just can't get this algorithm to match Excel's results > (which is spot on). > > > > http://taw9.hubpages.com/hub/Simplex-Algorithm-in-Python > > > > BTW, if I can't something to work, I'm going to be forced to use the > VBA programmatic Excel interface. That wouldn't be too bad, but the data > comes from a DB and getting it properly positioned to use Excel's > "Solver" is very painful. A Python approach would be much cleaner. > > Are you able to use scipy? It has the simplex algorithm (among many > others) in its optimize module: > http://docs.scipy.org/doc/scipy/reference/tutorial/optimize.html > > Oscar > scipy would be another possibility of last resort. I will take a look. Thanks. From vitaletom1 at gmail.com Mon Sep 2 11:06:11 2013 From: vitaletom1 at gmail.com (Tommy Vee) Date: Mon, 02 Sep 2013 11:06:11 -0400 Subject: Simplex Algorithm In-Reply-To: References: <1PRUt.242963$ZD2.40442@fx19.iad> Message-ID: <5224A963.4040304@xxxxxx.xxx> On 9/2/2013 5:55 AM, Robert Kern wrote: > On 2013-09-02 02:26, Tommy Vee wrote: >> Anyone know where I can get an easy to use Python class or algorithm >> for the >> Simplex optimization algorithm? I've tried the one in the link below, >> but I >> can't figure out if a) I'm using it properly, or b) where to get the >> solution. >> BTW, I tried some test scenarios using MS Excel's "Solver" and just >> can't get >> this algorithm to match Excel's results (which is spot on). >> >> http://taw9.hubpages.com/hub/Simplex-Algorithm-in-Python >> >> BTW, if I can't something to work, I'm going to be forced to use the VBA >> programmatic Excel interface. That wouldn't be too bad, but the data >> comes from >> a DB and getting it properly positioned to use Excel's "Solver" is very >> painful. A Python approach would be much cleaner. > > Can you show some of the test scenarios that you tried? There are > different conventions in how to represent a linear programming problem, > and different solvers may choose different conventions. You may have to > convert between representations. > > You may have better luck with the PuLP interface: > > https://pypi.python.org/pypi/PuLP > > PuLP itself is just a modelling language rather than a solver, but the > sources do contain compiled binaries for the CoinMP solver so it will > work out-of-box on popular platforms, like Windows. > > https://projects.coin-or.org/CoinMP > Thank you, I will definitely look at these and other options. BTW, try the test scenario in the link I sent. Very simple, only 3 variables. Maximize: 2x+3y+2z Constraints: 2x+y+z <=4, x+2y+z <=7, z <= 5 The algorithm displays the Tableau after each pivot, but where is the answer for x, y and z? When I run this in Excel's Solver, I get x=0, y=3, z=1. which is indeed the maximized solution (11). From xxxxx at xxxxxx.xxx Mon Sep 2 11:06:11 2013 From: xxxxx at xxxxxx.xxx (Tommy Vee) Date: Mon, 02 Sep 2013 11:06:11 -0400 Subject: Simplex Algorithm In-Reply-To: References: <1PRUt.242963$ZD2.40442@fx19.iad> Message-ID: <5224A963.4040304@xxxxxx.xxx> On 9/2/2013 5:55 AM, Robert Kern wrote: > On 2013-09-02 02:26, Tommy Vee wrote: >> Anyone know where I can get an easy to use Python class or algorithm >> for the >> Simplex optimization algorithm? I've tried the one in the link below, >> but I >> can't figure out if a) I'm using it properly, or b) where to get the >> solution. >> BTW, I tried some test scenarios using MS Excel's "Solver" and just >> can't get >> this algorithm to match Excel's results (which is spot on). >> >> http://taw9.hubpages.com/hub/Simplex-Algorithm-in-Python >> >> BTW, if I can't something to work, I'm going to be forced to use the VBA >> programmatic Excel interface. That wouldn't be too bad, but the data >> comes from >> a DB and getting it properly positioned to use Excel's "Solver" is very >> painful. A Python approach would be much cleaner. > > Can you show some of the test scenarios that you tried? There are > different conventions in how to represent a linear programming problem, > and different solvers may choose different conventions. You may have to > convert between representations. > > You may have better luck with the PuLP interface: > > https://pypi.python.org/pypi/PuLP > > PuLP itself is just a modelling language rather than a solver, but the > sources do contain compiled binaries for the CoinMP solver so it will > work out-of-box on popular platforms, like Windows. > > https://projects.coin-or.org/CoinMP > Thank you, I will definitely look at these and other options. BTW, try the test scenario in the link I sent. Very simple, only 3 variables. Maximize: 2x+3y+2z Constraints: 2x+y+z <=4, x+2y+z <=7, z <= 5 The algorithm displays the Tableau after each pivot, but where is the answer for x, y and z? When I run this in Excel's Solver, I get x=0, y=3, z=1. which is indeed the maximized solution (11). From robert.kern at gmail.com Mon Sep 2 11:43:48 2013 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 02 Sep 2013 16:43:48 +0100 Subject: Simplex Algorithm In-Reply-To: <5224A963.4040304@xxxxxx.xxx> References: <1PRUt.242963$ZD2.40442@fx19.iad> <5224A963.4040304@xxxxxx.xxx> Message-ID: On 2013-09-02 16:06, Tommy Vee wrote: > On 9/2/2013 5:55 AM, Robert Kern wrote: >> On 2013-09-02 02:26, Tommy Vee wrote: >>> Anyone know where I can get an easy to use Python class or algorithm >>> for the >>> Simplex optimization algorithm? I've tried the one in the link below, >>> but I >>> can't figure out if a) I'm using it properly, or b) where to get the >>> solution. >>> BTW, I tried some test scenarios using MS Excel's "Solver" and just >>> can't get >>> this algorithm to match Excel's results (which is spot on). >>> >>> http://taw9.hubpages.com/hub/Simplex-Algorithm-in-Python >>> >>> BTW, if I can't something to work, I'm going to be forced to use the VBA >>> programmatic Excel interface. That wouldn't be too bad, but the data >>> comes from >>> a DB and getting it properly positioned to use Excel's "Solver" is very >>> painful. A Python approach would be much cleaner. >> >> Can you show some of the test scenarios that you tried? There are >> different conventions in how to represent a linear programming problem, >> and different solvers may choose different conventions. You may have to >> convert between representations. >> >> You may have better luck with the PuLP interface: >> >> https://pypi.python.org/pypi/PuLP >> >> PuLP itself is just a modelling language rather than a solver, but the >> sources do contain compiled binaries for the CoinMP solver so it will >> work out-of-box on popular platforms, like Windows. >> >> https://projects.coin-or.org/CoinMP >> > > Thank you, I will definitely look at these and other options. BTW, try the test > scenario in the link I sent. Very simple, only 3 variables. > > Maximize: 2x+3y+2z > > Constraints: 2x+y+z <=4, x+2y+z <=7, z <= 5 > > The algorithm displays the Tableau after each pivot, but where is the answer for > x, y and z? You will have to read up on the Dantzig Simplex Algorithm to learn how to read off the results from the final tableau. My understanding is that you look at the columns representing the basic variables (in this case, the second, third, and fourth columns represent x, y, and z, respectively). If the column is all 0s except for a single 1, then the row with the 1 has the variable's value in the rightmost column. If the column has other values in it, then the variable's value is 0. > When I run this in Excel's Solver, I get x=0, y=3, z=1. which is indeed the > maximized solution (11). The final tableau for this problem looks like this: [[ 1. 1. 0. 0. 1. 1. 0. 11.] [ 0. 3. 0. 1. 2. -1. 0. 1.] [ 0. -1. 1. 0. -1. 1. 0. 3.] [ 0. -3. 0. 0. -2. 1. 1. 4.]] So, for x, we look in the second column and notice that it has a bunch of different values in it, so x=0. For y, we look in the third column and see that it has its single 1 in the third row. Looking all the way on the right for that row, we get a 3. For z, we look in the fourth column and see that it has its single 1 in the second row. Looking all the way on the right for that row, we get a 1. So this solver does reproduce the result x=0, y=3, z=1. The maximized solution is in the upper-rightmost element of the tableau, 11. Sound like a pain in the ass to code up that logic? It is. PuLP and other industrial grade solver interfaces won't make you go through this. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From vitaletom1 at gmail.com Mon Sep 2 14:59:50 2013 From: vitaletom1 at gmail.com (Tommy Vee) Date: Mon, 02 Sep 2013 14:59:50 -0400 Subject: Simplex Algorithm In-Reply-To: References: <1PRUt.242963$ZD2.40442@fx19.iad> <5224A963.4040304@xxxxxx.xxx> Message-ID: <5224E026.9080005@xxxxxx.xxx> On 9/2/2013 11:43 AM, Robert Kern wrote: > On 2013-09-02 16:06, Tommy Vee wrote: >> On 9/2/2013 5:55 AM, Robert Kern wrote: >>> On 2013-09-02 02:26, Tommy Vee wrote: >>>> Anyone know where I can get an easy to use Python class or algorithm >>>> for the >>>> Simplex optimization algorithm? I've tried the one in the link below, >>>> but I >>>> can't figure out if a) I'm using it properly, or b) where to get the >>>> solution. >>>> BTW, I tried some test scenarios using MS Excel's "Solver" and just >>>> can't get >>>> this algorithm to match Excel's results (which is spot on). >>>> >>>> http://taw9.hubpages.com/hub/Simplex-Algorithm-in-Python >>>> >>>> BTW, if I can't something to work, I'm going to be forced to use the >>>> VBA >>>> programmatic Excel interface. That wouldn't be too bad, but the data >>>> comes from >>>> a DB and getting it properly positioned to use Excel's "Solver" is very >>>> painful. A Python approach would be much cleaner. >>> >>> Can you show some of the test scenarios that you tried? There are >>> different conventions in how to represent a linear programming problem, >>> and different solvers may choose different conventions. You may have to >>> convert between representations. >>> >>> You may have better luck with the PuLP interface: >>> >>> https://pypi.python.org/pypi/PuLP >>> >>> PuLP itself is just a modelling language rather than a solver, but the >>> sources do contain compiled binaries for the CoinMP solver so it will >>> work out-of-box on popular platforms, like Windows. >>> >>> https://projects.coin-or.org/CoinMP >>> >> >> Thank you, I will definitely look at these and other options. BTW, >> try the test >> scenario in the link I sent. Very simple, only 3 variables. >> >> Maximize: 2x+3y+2z >> >> Constraints: 2x+y+z <=4, x+2y+z <=7, z <= 5 >> >> The algorithm displays the Tableau after each pivot, but where is the >> answer for >> x, y and z? > > You will have to read up on the Dantzig Simplex Algorithm to learn how > to read off the results from the final tableau. My understanding is that > you look at the columns representing the basic variables (in this case, > the second, third, and fourth columns represent x, y, and z, > respectively). If the column is all 0s except for a single 1, then the > row with the 1 has the variable's value in the rightmost column. If the > column has other values in it, then the variable's value is 0. > >> When I run this in Excel's Solver, I get x=0, y=3, z=1. which is >> indeed the >> maximized solution (11). > > The final tableau for this problem looks like this: > > [[ 1. 1. 0. 0. 1. 1. 0. 11.] > [ 0. 3. 0. 1. 2. -1. 0. 1.] > [ 0. -1. 1. 0. -1. 1. 0. 3.] > [ 0. -3. 0. 0. -2. 1. 1. 4.]] > > So, for x, we look in the second column and notice that it has a bunch > of different values in it, so x=0. > > For y, we look in the third column and see that it has its single 1 in > the third row. Looking all the way on the right for that row, we get a 3. > > For z, we look in the fourth column and see that it has its single 1 in > the second row. Looking all the way on the right for that row, we get a 1. > > So this solver does reproduce the result x=0, y=3, z=1. The maximized > solution is in the upper-rightmost element of the tableau, 11. > > Sound like a pain in the ass to code up that logic? It is. PuLP and > other industrial grade solver interfaces won't make you go through this. > You nailed it. Thanks for help. And you're right. This is too painful, I just read the PuLP doc and it may be a lot easier. From xxxxx at xxxxxx.xxx Mon Sep 2 14:59:50 2013 From: xxxxx at xxxxxx.xxx (Tommy Vee) Date: Mon, 02 Sep 2013 14:59:50 -0400 Subject: Simplex Algorithm In-Reply-To: References: <1PRUt.242963$ZD2.40442@fx19.iad> <5224A963.4040304@xxxxxx.xxx> Message-ID: <5224E026.9080005@xxxxxx.xxx> On 9/2/2013 11:43 AM, Robert Kern wrote: > On 2013-09-02 16:06, Tommy Vee wrote: >> On 9/2/2013 5:55 AM, Robert Kern wrote: >>> On 2013-09-02 02:26, Tommy Vee wrote: >>>> Anyone know where I can get an easy to use Python class or algorithm >>>> for the >>>> Simplex optimization algorithm? I've tried the one in the link below, >>>> but I >>>> can't figure out if a) I'm using it properly, or b) where to get the >>>> solution. >>>> BTW, I tried some test scenarios using MS Excel's "Solver" and just >>>> can't get >>>> this algorithm to match Excel's results (which is spot on). >>>> >>>> http://taw9.hubpages.com/hub/Simplex-Algorithm-in-Python >>>> >>>> BTW, if I can't something to work, I'm going to be forced to use the >>>> VBA >>>> programmatic Excel interface. That wouldn't be too bad, but the data >>>> comes from >>>> a DB and getting it properly positioned to use Excel's "Solver" is very >>>> painful. A Python approach would be much cleaner. >>> >>> Can you show some of the test scenarios that you tried? There are >>> different conventions in how to represent a linear programming problem, >>> and different solvers may choose different conventions. You may have to >>> convert between representations. >>> >>> You may have better luck with the PuLP interface: >>> >>> https://pypi.python.org/pypi/PuLP >>> >>> PuLP itself is just a modelling language rather than a solver, but the >>> sources do contain compiled binaries for the CoinMP solver so it will >>> work out-of-box on popular platforms, like Windows. >>> >>> https://projects.coin-or.org/CoinMP >>> >> >> Thank you, I will definitely look at these and other options. BTW, >> try the test >> scenario in the link I sent. Very simple, only 3 variables. >> >> Maximize: 2x+3y+2z >> >> Constraints: 2x+y+z <=4, x+2y+z <=7, z <= 5 >> >> The algorithm displays the Tableau after each pivot, but where is the >> answer for >> x, y and z? > > You will have to read up on the Dantzig Simplex Algorithm to learn how > to read off the results from the final tableau. My understanding is that > you look at the columns representing the basic variables (in this case, > the second, third, and fourth columns represent x, y, and z, > respectively). If the column is all 0s except for a single 1, then the > row with the 1 has the variable's value in the rightmost column. If the > column has other values in it, then the variable's value is 0. > >> When I run this in Excel's Solver, I get x=0, y=3, z=1. which is >> indeed the >> maximized solution (11). > > The final tableau for this problem looks like this: > > [[ 1. 1. 0. 0. 1. 1. 0. 11.] > [ 0. 3. 0. 1. 2. -1. 0. 1.] > [ 0. -1. 1. 0. -1. 1. 0. 3.] > [ 0. -3. 0. 0. -2. 1. 1. 4.]] > > So, for x, we look in the second column and notice that it has a bunch > of different values in it, so x=0. > > For y, we look in the third column and see that it has its single 1 in > the third row. Looking all the way on the right for that row, we get a 3. > > For z, we look in the fourth column and see that it has its single 1 in > the second row. Looking all the way on the right for that row, we get a 1. > > So this solver does reproduce the result x=0, y=3, z=1. The maximized > solution is in the upper-rightmost element of the tableau, 11. > > Sound like a pain in the ass to code up that logic? It is. PuLP and > other industrial grade solver interfaces won't make you go through this. > You nailed it. Thanks for help. And you're right. This is too painful, I just read the PuLP doc and it may be a lot easier. From schesis at gmail.com Sun Sep 1 23:22:20 2013 From: schesis at gmail.com (Zero Piraeus) Date: Sun, 1 Sep 2013 23:22:20 -0400 Subject: How to split with "\" character, and licence copyleft mirror of (c) Message-ID: : On 1 September 2013 22:40, Tim Roberts wrote: > Another altrnative is to use "raw" strings, in which backslashes are not > interpreted: > a = r'E:\Dropbox\jjfsdjjsdklfj\sdfjksdfkjslkj\flute.wav' > a.split(r'\') Acually, that doesn't work: >>> a = r'E:\Dropbox\jjfsdjjsdklfj\sdfjksdfkjslkj\flute.wav' >>> a.split('\') File "", line 1 a.split('\') ^ SyntaxError: EOL while scanning string literal ... because you can't end a raw string with a backslash: http://docs.python.org/3/faq/design.html#why-can-t-raw-strings-r-strings-end-with-a-backslash -[]z. From rosuav at gmail.com Mon Sep 2 17:30:52 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 Sep 2013 07:30:52 +1000 Subject: How to split with "\" character, and licence copyleft mirror of (c) Message-ID: On Tue, Sep 3, 2013 at 6:22 AM, Ethan Furman wrote: > In a raw string, the backslash is buggy (IMNSHO) when it's the last > character. It's an inevitable consequence of using the backslash to escape the quote character. If instead, a raw string doubled the quote character (like in REXX), it'd need no other escape: r'\' --> '\\' r'''' --> "'" Too late to change now. ChrisA From Russ.Paielli at gmail.com Mon Sep 2 00:24:41 2013 From: Russ.Paielli at gmail.com (Russ P.) Date: Sun, 1 Sep 2013 21:24:41 -0700 (PDT) Subject: A Pragmatic Case for Static Typing Message-ID: <8bc2f539-ae7a-4cd8-83c0-91449aecd616@googlegroups.com> I just stumbled across this video and found it interesting: http://vimeo.com/72870631 My apologies if it has been posted here already. From no.email at nospam.invalid Mon Sep 2 04:10:34 2013 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 02 Sep 2013 01:10:34 -0700 Subject: A Pragmatic Case for Static Typing References: <8bc2f539-ae7a-4cd8-83c0-91449aecd616@googlegroups.com> Message-ID: <7xfvtnwsn9.fsf@ruckus.brouhaha.com> "Russ P." writes: > I just stumbled across this video and found it interesting: > http://vimeo.com/72870631 > My apologies if it has been posted here already. The slides for it are here, so I didn't bother watching the 1 hour video: http://gbaz.github.io/slides/hurt-statictyping-07-2013.pdf I guess for Python programmers looking to expand their horizons a bit, it's worth at least looking at the slides. But, it may overstate its case a little bit. Haskell's type system is way cool but the language introduces other headaches into programming. From steve at pearwood.info Mon Sep 2 05:44:20 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 02 Sep 2013 09:44:20 GMT Subject: A Pragmatic Case for Static Typing References: <8bc2f539-ae7a-4cd8-83c0-91449aecd616@googlegroups.com> <7xfvtnwsn9.fsf@ruckus.brouhaha.com> Message-ID: <52245df4$0$2743$c3e8da3$76491128@news.astraweb.com> On Mon, 02 Sep 2013 01:10:34 -0700, Paul Rubin wrote: > "Russ P." writes: >> I just stumbled across this video and found it interesting: >> http://vimeo.com/72870631 >> My apologies if it has been posted here already. > > The slides for it are here, so I didn't bother watching the 1 hour > video: > > http://gbaz.github.io/slides/hurt-statictyping-07-2013.pdf > > I guess for Python programmers looking to expand their horizons a bit, > it's worth at least looking at the slides. But, it may overstate its > case a little bit. Haskell's type system is way cool but the language > introduces other headaches into programming. I haven't watched the video, but the slides are worth reading, although if you're familiar with this: https://cdsmith.wordpress.com/2011/01/09/an-old-article-i-wrote/ there might not be anything new in it. I think there is a lot to be said for advanced static-typed languages like Haskell, as opposed to "dumb" static-typed languages like C, Java, Pascal etc. One factor I don't see very often mentioned is that static typing increases coupling between distant parts of your code. If func() changes from returning int to MyInt, everything that calls func now needs to be modified to accept MyInt, no matter how similar MyInt is to int. You have to make changes just to satisfy the compiler. -- Steven From roy at panix.com Mon Sep 2 09:37:53 2013 From: roy at panix.com (Roy Smith) Date: Mon, 02 Sep 2013 09:37:53 -0400 Subject: A Pragmatic Case for Static Typing References: <8bc2f539-ae7a-4cd8-83c0-91449aecd616@googlegroups.com> <7xfvtnwsn9.fsf@ruckus.brouhaha.com> <52245df4$0$2743$c3e8da3$76491128@news.astraweb.com> Message-ID: In article <52245df4$0$2743$c3e8da3$76491128 at news.astraweb.com>, Steven D'Aprano wrote: > One factor I don't see very often mentioned is that static typing > increases coupling between distant parts of your code. If func() changes > from returning int to MyInt, everything that calls func now needs to be > modified to accept MyInt, no matter how similar MyInt is to int. You have > to make changes just to satisfy the compiler. This really ties in with what I was getting at in: Message-ID : Subject: Re: Interface and duck typing woes Date: Wed, 28 Aug 2013 21:27:34 -0400 Every interface requires certain things and promises certain things (i.e. the contract). At some point, the caller and the callee have to agree on what's required, what's allowed, and what's a bug. There's lots of ways of doing that. At one end of the spectrum, there's the type bondage languages like C++ and Java. But even there, you have things like: double sqrt (double x); which only tells part of the "what's required" story. For the rest of the story, you have to resort to reading the natural language documentation: "If the argument is negative, a domain error occurs" At the other end of the spectrum, there's Python's duck typing, which says, "Give me something, and I'll let you know if I can't deal with it". But we're still not playing 20 questions. Presumably, the callee gives you some kind of hint about what sort of duck they're expecting. It seems to me that any time you can encapsulate knowledge about the contract into something that's machine readable, you've added value. Now you can have automated tools do something useful with that knowledge. Maybe that means raising an error at compile time, or when you run a static analysis tool. Or, more apropos to Python, at function call time using pep-3107 annotations. So, let's go back to your original statement (requoted here for convenience): > One factor I don't see very often mentioned is that static typing > increases coupling between distant parts of your code. If func() changes > from returning int to MyInt, everything that calls func now needs to be > modified to accept MyInt, no matter how similar MyInt is to int. You have > to make changes just to satisfy the compiler. It's not that static typing has increased coupling. The coupling has always been there, it's just that now it's being enforced at compile time. What's the difference between int and MyInt? I'm going to speculate that ints are 64 bit 2s-complement binary and MyInts are BCD-encoded fixed-width character strings with leading blank padding. The problem is NOT that static typing forced me to change every place that calls func(). The problem is that func() has fundamentally changed, and THAT is what's forcing me to change all my code that calls it. The static typing just lets me communicate that to the compiler. I actually think Java was on the right track with interfaces. They are essentially duck typing enforced at compile time. Rather than saying, "You must pass me a Duck", you're saying, "You must pass me something that has quack(), waddle(), and poop() methods". If I later change func() to also call your_object.fly(), I've changed the contract on you. And whether you know about it or not, your code and my code are coupled. The difference is that with static typing, you find out about it quickly, and with pythonic duck typing, you may not find out about it until three years later when some unusual condition finally causes the fly() code path to get executed and you've long since moved on to another project. The next step is to understand that the real contract may be more complex than can be easily encapsulated in a type or annotation or whatever. The contract may be: "You must pass me something that can quack(), waddle(), and poop(). In addition, if it's a full moon, it must also be able to fly()." So, the big question is, how should I specify that to a human, and how should I specify that to the computer? From nobody at nowhere.com Mon Sep 2 21:10:37 2013 From: nobody at nowhere.com (Nobody) Date: Tue, 03 Sep 2013 02:10:37 +0100 Subject: A Pragmatic Case for Static Typing References: <8bc2f539-ae7a-4cd8-83c0-91449aecd616@googlegroups.com> <7xfvtnwsn9.fsf@ruckus.brouhaha.com> <52245df4$0$2743$c3e8da3$76491128@news.astraweb.com> Message-ID: On Mon, 02 Sep 2013 09:44:20 +0000, Steven D'Aprano wrote: > One factor I don't see very often mentioned is that static typing > increases coupling between distant parts of your code. If func() changes > from returning int to MyInt, everything that calls func now needs to be > modified to accept MyInt, no matter how similar MyInt is to int. You have > to make changes just to satisfy the compiler. Not if the language has type inference (e.g. Haskell, or C++ templates). From joel.goldstick at gmail.com Mon Sep 2 21:36:40 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 2 Sep 2013 21:36:40 -0400 Subject: A Pragmatic Case for Static Typing In-Reply-To: References: <8bc2f539-ae7a-4cd8-83c0-91449aecd616@googlegroups.com> <7xfvtnwsn9.fsf@ruckus.brouhaha.com> <52245df4$0$2743$c3e8da3$76491128@news.astraweb.com> Message-ID: On Mon, Sep 2, 2013 at 9:10 PM, Nobody wrote: > On Mon, 02 Sep 2013 09:44:20 +0000, Steven D'Aprano wrote: > >> One factor I don't see very often mentioned is that static typing >> increases coupling between distant parts of your code. If func() changes >> from returning int to MyInt, everything that calls func now needs to be >> modified to accept MyInt, no matter how similar MyInt is to int. You have >> to make changes just to satisfy the compiler. > > Not if the language has type inference (e.g. Haskell, or C++ templates). > > -- > http://mail.python.org/mailman/listinfo/python-list My personal reason for working with python (dynamic typing) as opposed to Java or C++ is that (in general) I don't like company environments that use Java or C++. Its the world of huge software teams. Python seems to be more in vogue in smaller environments which suit my interests. I used to write in C and a little C++ back in the Borland C++ days (90s?). I'm not familiar with Haskell, except having heard the name, but I also know it isn't as popular in the job market as say python or ruby or C++ or Java. So, while I'm off topic, sometimes the reason to choose one methodology over another has to do less with the merits than on other factors. That said, python 'feels' extremely right to me. Having come from PHP for the last dozen years that shouldn't surprise anyone! -- Joel Goldstick http://joelgoldstick.com From rosuav at gmail.com Mon Sep 2 08:04:58 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 Sep 2013 22:04:58 +1000 Subject: A Pragmatic Case for Static Typing In-Reply-To: <7xfvtnwsn9.fsf@ruckus.brouhaha.com> References: <8bc2f539-ae7a-4cd8-83c0-91449aecd616@googlegroups.com> <7xfvtnwsn9.fsf@ruckus.brouhaha.com> Message-ID: On Mon, Sep 2, 2013 at 6:10 PM, Paul Rubin wrote: > "Russ P." writes: >> I just stumbled across this video and found it interesting: >> http://vimeo.com/72870631 >> My apologies if it has been posted here already. > > The slides for it are here, so I didn't bother watching the 1 hour video: > > http://gbaz.github.io/slides/hurt-statictyping-07-2013.pdf Thanks for that. I have no desire to watch an hour-long video about this! ChrisA From roy at panix.com Mon Sep 2 08:41:21 2013 From: roy at panix.com (Roy Smith) Date: Mon, 02 Sep 2013 08:41:21 -0400 Subject: A Pragmatic Case for Static Typing References: <8bc2f539-ae7a-4cd8-83c0-91449aecd616@googlegroups.com> <7xfvtnwsn9.fsf@ruckus.brouhaha.com> Message-ID: In article <7xfvtnwsn9.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > "Russ P." writes: > > I just stumbled across this video and found it interesting: > > http://vimeo.com/72870631 > > My apologies if it has been posted here already. > > The slides for it are here, so I didn't bother watching the 1 hour video: > > http://gbaz.github.io/slides/hurt-statictyping-07-2013.pdf Thank you for posting that. My favorite slide (especially since for the past few years, I've mostly worked in 3 person teams). > Brian's Observation: > > At 3 people on a team, there is a 50% chance that >> at least one of them is a full-time idiot. > > As the teams grow larger, the probability of not > having an idiot on the team falls rapidly to zero. From rosuav at gmail.com Mon Sep 2 18:43:21 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 Sep 2013 08:43:21 +1000 Subject: A Pragmatic Case for Static Typing In-Reply-To: References: <8bc2f539-ae7a-4cd8-83c0-91449aecd616@googlegroups.com> <7xfvtnwsn9.fsf@ruckus.brouhaha.com> Message-ID: On Mon, Sep 2, 2013 at 10:41 PM, Roy Smith wrote: > In article <7xfvtnwsn9.fsf at ruckus.brouhaha.com>, > Paul Rubin wrote: > >> "Russ P." writes: >> > I just stumbled across this video and found it interesting: >> > http://vimeo.com/72870631 >> > My apologies if it has been posted here already. >> >> The slides for it are here, so I didn't bother watching the 1 hour video: >> >> http://gbaz.github.io/slides/hurt-statictyping-07-2013.pdf > > Thank you for posting that. > > My favorite slide (especially since for the past few years, I've mostly > worked in 3 person teams). > >> Brian's Observation: >> >> At 3 people on a team, there is a 50% chance that >>> at least one of them is a full-time idiot. My favorite too. I was reading it on the bus and I cracked up loudly enough to draw some looks from fellow passengers. I currently work on a two-person team (the boss/owner and me, nobody else), reduced from three-person a year and a bit ago by the departure of our full-time idiot. Since then, my boss and I have completely rewritten *EVERY* piece of code he contributed to the project; for the bulk of the project we weren't using source control (I recommended it, boss reckoned we didn't need it) and just did our own separate subprojects (I worked on the back end, our resident idiot had control of the PHP and Javascript front end). Boss now thinks it'd be worth rehiring the guy, because he had a recommendation/decision batting record of pretty much .000, so we should ask his advice and then do the opposite. (I'm still waiting for my boss to notice that it was Idiot (btw, his moniker, not mine, used in a number of commit messages removing his code) who recommended that we use PHP.) Yep. Full-time idiot. Though this may be an extreme and unusually-literal example. ChrisA From Russ.Paielli at gmail.com Mon Sep 2 14:33:34 2013 From: Russ.Paielli at gmail.com (Russ P.) Date: Mon, 2 Sep 2013 11:33:34 -0700 (PDT) Subject: A Pragmatic Case for Static Typing In-Reply-To: <7xfvtnwsn9.fsf@ruckus.brouhaha.com> References: <8bc2f539-ae7a-4cd8-83c0-91449aecd616@googlegroups.com> <7xfvtnwsn9.fsf@ruckus.brouhaha.com> Message-ID: On Monday, September 2, 2013 1:10:34 AM UTC-7, Paul Rubin wrote: > "Russ P." writes: > > > I just stumbled across this video and found it interesting: > > > http://vimeo.com/72870631 > > > My apologies if it has been posted here already. > > > > The slides for it are here, so I didn't bother watching the 1 hour video: > > > > http://gbaz.github.io/slides/hurt-statictyping-07-2013.pdf > > > > I guess for Python programmers looking to expand their horizons a bit, > > it's worth at least looking at the slides. But, it may overstate its > > case a little bit. Haskell's type system is way cool but the language > > introduces other headaches into programming. I thought the video was amusing, but I am probably easily amused. I noticed that he did not list my current main language, Scala, as statically typed. I am not sure why, but perhaps because it inherits null from Java. In any case, his main point was that static typing reduces time to working code. I have no doubt that is true for large-scale programming, but I doubt it is true for small-scale programming. The question is where the crossover point is. From lfcpaulrice at gmail.com Mon Sep 2 11:03:02 2013 From: lfcpaulrice at gmail.com (Paul Rice) Date: Mon, 2 Sep 2013 08:03:02 -0700 (PDT) Subject: user interfaces python3.x Message-ID: Im new to python3.x (well, programming as a whole. Never done before) and was wondering how do i get a proper interface instead of just writing. Im using android device(sl4a and py34a). Ive heard something about kivy for android is that what i need if so does anyone know of a tutorial to use it? Thanks in advance. From steve+comp.lang.python at pearwood.info Mon Sep 2 12:08:04 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 Sep 2013 16:08:04 GMT Subject: user interfaces python3.x References: Message-ID: <5224b7e4$0$6599$c3e8da3$5496439d@news.astraweb.com> On Mon, 02 Sep 2013 08:03:02 -0700, Paul Rice wrote: > Im new to python3.x (well, programming as a whole. Never done before) > and was wondering how do i get a proper interface instead of just > writing. A "proper" interface huh? Well, I'd love to tell you the answer, but I don't know what icon to use, so I could only use writing, and I know you hate that. (If you think text is not a proper interface, you're going to have a bad time as a programmer. 99% of your programming time will be writing.) Care to give us a hint what you think is a "proper" interface? Qt, GTK, Carbon, web browser, direct interface to the brain, something else? > Im using android device(sl4a and py34a). Ive heard something > about kivy for android is that what i need if so does anyone know of a > tutorial to use it? Thanks in advance. Here, let me google that for you: https://duckduckgo.com/?q=kivy+tutorial Are those links satisfactory? -- Steven From paul.nospam at rudin.co.uk Mon Sep 2 12:18:34 2013 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Mon, 02 Sep 2013 17:18:34 +0100 Subject: user interfaces python3.x References: <5224b7e4$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87hae3yz6t.fsf@no-fixed-abode.cable.virginmedia.net> Steven D'Aprano writes: > On Mon, 02 Sep 2013 08:03:02 -0700, Paul Rice wrote: > >> Im new to python3.x (well, programming as a whole. Never done before) >> and was wondering how do i get a proper interface instead of just >> writing. > > A "proper" interface huh? Well, I'd love to tell you the answer... ...but holy wars would ensue. From joel.goldstick at gmail.com Mon Sep 2 13:06:02 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 2 Sep 2013 13:06:02 -0400 Subject: user interfaces python3.x In-Reply-To: <87hae3yz6t.fsf@no-fixed-abode.cable.virginmedia.net> References: <5224b7e4$0$6599$c3e8da3$5496439d@news.astraweb.com> <87hae3yz6t.fsf@no-fixed-abode.cable.virginmedia.net> Message-ID: On Mon, Sep 2, 2013 at 12:18 PM, Paul Rudin wrote: > Steven D'Aprano writes: > >> On Mon, 02 Sep 2013 08:03:02 -0700, Paul Rice wrote: >> >>> Im new to python3.x (well, programming as a whole. Never done before) >>> and was wondering how do i get a proper interface instead of just >>> writing. You might try asking questions on the python-tutor list. If you have never studied or tried to write computer programs, you won't be making nifty android apps any time soon. You might scream, but try the basic python tutorial at python.org first to see if you like 'programming'. Warning, it involves words and letters, not icons. >> >> A "proper" interface huh? Well, I'd love to tell you the answer... > > ...but holy wars would ensue. > > -- > http://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick http://joelgoldstick.com From lfcpaulrice at gmail.com Mon Sep 2 13:00:20 2013 From: lfcpaulrice at gmail.com (Paul Rice) Date: Mon, 2 Sep 2013 10:00:20 -0700 (PDT) Subject: user interfaces python3.x In-Reply-To: <5224b7e4$0$6599$c3e8da3$5496439d@news.astraweb.com> References: <5224b7e4$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3eafbb7c-1a41-4892-9660-4904f81c3b7f@googlegroups.com> I know that most of my time will be writing . I dont think i specified very well what im asking. What i mean by proper interface is a interface like for an app or something, let me give u an example; Say i have made a phonebook just for this example and i want to use it like a normal phonebook in your phone instead of in writing. So basically making it like an app or something ? Does that make sense ? Lol From joe.fbs.junior at gmail.com Mon Sep 2 13:16:29 2013 From: joe.fbs.junior at gmail.com (Joe Junior) Date: Mon, 2 Sep 2013 14:16:29 -0300 Subject: user interfaces python3.x In-Reply-To: <3eafbb7c-1a41-4892-9660-4904f81c3b7f@googlegroups.com> References: <5224b7e4$0$6599$c3e8da3$5496439d@news.astraweb.com> <3eafbb7c-1a41-4892-9660-4904f81c3b7f@googlegroups.com> Message-ID: On 2 September 2013 14:00, Paul Rice wrote: > > I know that most of my time will be writing . I dont think i specified very well what im asking. > What i mean by proper interface is a interface like for an app or something, let me give u an example; > Say i have made a phonebook just for this example and i want to use it like a normal phonebook in your phone instead of in writing. So basically making it like an app or something ? > Does that make sense ? Lol He's just messing with you. What you want is to write GUI (Graphical User Interface) Application. The examples Steven cited like GTK and Qt are libraries that provides it. The word "Interface" means a lot of things in programming. -- Joe From joel.goldstick at gmail.com Mon Sep 2 13:30:14 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 2 Sep 2013 13:30:14 -0400 Subject: user interfaces python3.x In-Reply-To: References: <5224b7e4$0$6599$c3e8da3$5496439d@news.astraweb.com> <3eafbb7c-1a41-4892-9660-4904f81c3b7f@googlegroups.com> Message-ID: On Mon, Sep 2, 2013 at 1:16 PM, Joe Junior wrote: > On 2 September 2013 14:00, Paul Rice wrote: >> >> I know that most of my time will be writing . I dont think i specified very well what im asking. >> What i mean by proper interface is a interface like for an app or something, let me give u an example; >> Say i have made a phonebook just for this example and i want to use it like a normal phonebook in your phone instead of in writing. So basically making it like an app or something ? >> Does that make sense ? Lol > > He's just messing with you. What you want is to write GUI (Graphical > User Interface) Application. The examples Steven cited like GTK and Qt > are libraries that provides it. The word "Interface" means a lot of > things in programming. Except that those libraries don't work in Android phone environments. I've never looked into writing code for a phone, but I would suppose that a prerequisite for writing smart phone apps is to understand more in general how to write a software application. Guessing from the way the OP poses his question, he has a lot more to learn than a specific GUI library. So, maybe the answers were a little facetious, but the question could be taken as either completely naive, or as completely pompous. To answer the second interpretation is maybe more fun! > > > > > -- > Joe > -- > http://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick http://joelgoldstick.com From joe.fbs.junior at gmail.com Mon Sep 2 13:45:15 2013 From: joe.fbs.junior at gmail.com (Joe Junior) Date: Mon, 2 Sep 2013 14:45:15 -0300 Subject: user interfaces python3.x In-Reply-To: References: <5224b7e4$0$6599$c3e8da3$5496439d@news.astraweb.com> <3eafbb7c-1a41-4892-9660-4904f81c3b7f@googlegroups.com> Message-ID: On 2 September 2013 14:30, Joel Goldstick wrote: > On Mon, Sep 2, 2013 at 1:16 PM, Joe Junior wrote: >> On 2 September 2013 14:00, Paul Rice wrote: >>> >>> I know that most of my time will be writing . I dont think i specified very well what im asking. >>> What i mean by proper interface is a interface like for an app or something, let me give u an example; >>> Say i have made a phonebook just for this example and i want to use it like a normal phonebook in your phone instead of in writing. So basically making it like an app or something ? >>> Does that make sense ? Lol >> >> He's just messing with you. What you want is to write GUI (Graphical >> User Interface) Application. The examples Steven cited like GTK and Qt >> are libraries that provides it. The word "Interface" means a lot of >> things in programming. > > Except that those libraries don't work in Android phone environments. > I've never looked into writing code for a phone, but I would suppose > that a prerequisite for writing smart phone apps is to understand more > in general how to write a software application. Guessing from the way > the OP poses his question, he has a lot more to learn than a specific > GUI library. > > So, maybe the answers were a little facetious, but the question could > be taken as either completely naive, or as completely pompous. To > answer the second interpretation is maybe more fun! I'm always for some fun, I just thought I should tell the OP what was going on. :-) And Qt can work on Android, with some effort. But you're absolutely right, mobile development can be quite harder than desktop, and the OP has some studying to do. I'd recommend he first tried some desktop development, a little googling on tkinter or PyQt can do him good, since he wants to learn about GUI development, even though it might not directly translate to mobile developtment. -- Joe From lfcpaulrice at gmail.com Mon Sep 2 14:26:49 2013 From: lfcpaulrice at gmail.com (Paul Rice) Date: Mon, 2 Sep 2013 11:26:49 -0700 (PDT) Subject: user interfaces python3.x In-Reply-To: References: <5224b7e4$0$6599$c3e8da3$5496439d@news.astraweb.com> <3eafbb7c-1a41-4892-9660-4904f81c3b7f@googlegroups.com> Message-ID: <6c1d1143-0736-440e-b96a-9a8737a633bd@googlegroups.com> Sorry for the wording of the question buy finally i have an answer. Thanks From steve+comp.lang.python at pearwood.info Mon Sep 2 22:43:55 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Sep 2013 02:43:55 GMT Subject: user interfaces python3.x References: <5224b7e4$0$6599$c3e8da3$5496439d@news.astraweb.com> <3eafbb7c-1a41-4892-9660-4904f81c3b7f@googlegroups.com> <6c1d1143-0736-440e-b96a-9a8737a633bd@googlegroups.com> Message-ID: <52254ceb$0$6599$c3e8da3$5496439d@news.astraweb.com> On Mon, 02 Sep 2013 11:26:49 -0700, Paul Rice wrote: > Sorry for the wording of the question buy finally i have an answer. > Thanks Actually, if you were paying attention, you actually had an answer in the very first response. Two answers really: even if you knew absolutely nothing about programming or user interfaces and didn't have the foggiest clue what I was talking about, you could have -- should have -- googled the terms I mentioned, Qt, GTK and Carbon, for some clues. Add "Python" to the search terms, and you would learn even more. Then, even if you didn't quite have the complete answer you wanted, you would at least have the vocabulary to ask the question. And of course the second question, about Kivy, was also answered. If you had followed the link I provided, or even typed "kivy tutorial" into the search engine of your choice, you would have found the tutorials you were asking about. -- Steven From lfcpaulrice at gmail.com Mon Sep 2 14:28:14 2013 From: lfcpaulrice at gmail.com (Paul Rice) Date: Mon, 2 Sep 2013 11:28:14 -0700 (PDT) Subject: user interfaces python3.x In-Reply-To: References: <5224b7e4$0$6599$c3e8da3$5496439d@news.astraweb.com> <3eafbb7c-1a41-4892-9660-4904f81c3b7f@googlegroups.com> Message-ID: <0e59f5f3-7f29-4930-860f-7527a3bd3b40@googlegroups.com> Sorry for the wording of the question buy finally i have an answer. Thanks From dan at tombstonezero.net Mon Sep 2 13:13:44 2013 From: dan at tombstonezero.net (Dan Sommers) Date: Mon, 02 Sep 2013 17:13:44 GMT Subject: user interfaces python3.x References: < 5224b7e4$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, 02 Sep 2013 16:08:04 +0000, Steven D'Aprano wrote: > (If you think text is not a proper interface, you're going to have a > bad time as a programmer. 99% of your programming time will be > writing.) I'm a programmer, and I spend way more than 1% of my programming time drawing, even taking into account that a lot of what I draw contains writing. A diagram is often worth a kword. (Now if only I had a satisfactory drawing tool on a computer; I keep running out of, paper, wall, and window space.) I also spend way more than 1% of my programming time thinking. How can this work? How can this fail? How can I test this? Will this handle tomorrow's problem (YAGNI notwithstanding)? And then there's the time I spend listening. Customers, managers, and coworkers inflict (not always respectively) requirements, constraints, and other ideas on me. And talking, becuase sometimes, I have something to say, too. With all due respect, if I spent 99% of my programming time writing, I'd be a pretty lousy programmer! ;-) That said, most of the best programmers I know (or have known) have excellent written communication skills. -- Dan From papillion at gmail.com Mon Sep 2 12:06:30 2013 From: papillion at gmail.com (Anthony Papillion) Date: Mon, 02 Sep 2013 11:06:30 -0500 Subject: How can I remove the first line of a multi-line string? Message-ID: <5224B786.2050606@gmail.com> Hello Everyone, I have a multi-line string and I need to remove the very first line from it. How can I do that? I looked at StringIO but I can't seem to figure out how to properly use it to remove the first line. Basically, I want to toss the first line but keep everything else. Can anyone put me on the right path? I know it is probably easy but I'm still learning Python and don't have all the string functions down yet. Thanks, Anthony From kwpolska at gmail.com Mon Sep 2 12:12:35 2013 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Mon, 2 Sep 2013 18:12:35 +0200 Subject: How can I remove the first line of a multi-line string? In-Reply-To: <5224B786.2050606@gmail.com> References: <5224B786.2050606@gmail.com> Message-ID: On Mon, Sep 2, 2013 at 6:06 PM, Anthony Papillion wrote: > Hello Everyone, > > I have a multi-line string and I need to remove the very first line from > it. How can I do that? I looked at StringIO but I can't seem to figure > out how to properly use it to remove the first line. Basically, I want > to toss the first line but keep everything else. Can anyone put me on > the right path? I know it is probably easy but I'm still learning Python > and don't have all the string functions down yet. > > Thanks, > Anthony > -- > http://mail.python.org/mailman/listinfo/python-list Use split() and join() methods of strings, along with slicing. Like this: fullstring = """foo bar baz""" sansfirstline = '\n'.join(fullstring.split('\n')[1:]) The last line does this: 1. fullstring.split('\n') turns it into a list of ['foo', 'bar', 'baz'] 2. the [1:] slice removes the first element, making it ['bar', 'baz'] 3. Finally, '\n'.join() turns the list into a string separated by newlines ("""bar baz""") -- Chris ?Kwpolska? Warrick PGP: 5EAAEA16 stop html mail | always bottom-post | only UTF-8 makes sense From papillion at gmail.com Mon Sep 2 12:24:06 2013 From: papillion at gmail.com (Anthony Papillion) Date: Mon, 02 Sep 2013 11:24:06 -0500 Subject: How can I remove the first line of a multi-line string? (SOLVED) In-Reply-To: References: <5224B786.2050606@gmail.com> Message-ID: <5224BBA6.5070702@gmail.com> On 09/02/2013 11:12 AM, Chris ?Kwpolska? Warrick wrote: > On Mon, Sep 2, 2013 at 6:06 PM, Anthony Papillion wrote: >> Hello Everyone, >> >> I have a multi-line string and I need to remove the very first line from >> it. How can I do that? I looked at StringIO but I can't seem to figure >> out how to properly use it to remove the first line. Basically, I want >> to toss the first line but keep everything else. Can anyone put me on >> the right path? I know it is probably easy but I'm still learning Python >> and don't have all the string functions down yet. >> >> Thanks, >> Anthony >> -- >> http://mail.python.org/mailman/listinfo/python-list > > Use split() and join() methods of strings, along with slicing. Like this: > > fullstring = """foo > bar > baz""" > > sansfirstline = '\n'.join(fullstring.split('\n')[1:]) > > The last line does this: > 1. fullstring.split('\n') turns it into a list of ['foo', 'bar', 'baz'] > 2. the [1:] slice removes the first element, making it ['bar', 'baz'] > 3. Finally, '\n'.join() turns the list into a string separated by > newlines ("""bar > baz""") This, of course, worked like a charm. I really need to study the string methods. In the work I'm doing they are going to come in very handy. Thank you, Chris! Anthony From python at mrabarnett.plus.com Mon Sep 2 12:53:32 2013 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 02 Sep 2013 17:53:32 +0100 Subject: How can I remove the first line of a multi-line string? In-Reply-To: References: <5224B786.2050606@gmail.com> Message-ID: <5224C28C.9070404@mrabarnett.plus.com> On 02/09/2013 17:12, Chris ?Kwpolska? Warrick wrote: > On Mon, Sep 2, 2013 at 6:06 PM, Anthony Papillion wrote: >> Hello Everyone, >> >> I have a multi-line string and I need to remove the very first line from >> it. How can I do that? I looked at StringIO but I can't seem to figure >> out how to properly use it to remove the first line. Basically, I want >> to toss the first line but keep everything else. Can anyone put me on >> the right path? I know it is probably easy but I'm still learning Python >> and don't have all the string functions down yet. >> >> Thanks, >> Anthony >> -- >> http://mail.python.org/mailman/listinfo/python-list > > Use split() and join() methods of strings, along with slicing. Like this: > > fullstring = """foo > bar > baz""" > > sansfirstline = '\n'.join(fullstring.split('\n')[1:]) > > The last line does this: > 1. fullstring.split('\n') turns it into a list of ['foo', 'bar', 'baz'] > 2. the [1:] slice removes the first element, making it ['bar', 'baz'] > 3. Finally, '\n'.join() turns the list into a string separated by > newlines ("""bar > baz""") > Another way is to use .partition: >>> fullstring = """foo\nbar\nbaz""" >>> fullstring.partition("\n")[2] 'bar\nbaz' From roy at panix.com Mon Sep 2 13:07:11 2013 From: roy at panix.com (Roy Smith) Date: Mon, 02 Sep 2013 13:07:11 -0400 Subject: How can I remove the first line of a multi-line string? (SOLVED) References: <5224B786.2050606@gmail.com> Message-ID: In article , Anthony Papillion wrote: > On 09/02/2013 11:12 AM, Chris ???Kwpolska??? Warrick wrote: > > On Mon, Sep 2, 2013 at 6:06 PM, Anthony Papillion > > wrote: > >> Hello Everyone, > >> > >> I have a multi-line string and I need to remove the very first line from > >> it. How can I do that? I looked at StringIO but I can't seem to figure > >> out how to properly use it to remove the first line. Basically, I want > >> to toss the first line but keep everything else. Can anyone put me on > >> the right path? I know it is probably easy but I'm still learning Python > >> and don't have all the string functions down yet. > >> > >> Thanks, > >> Anthony > >> -- > >> http://mail.python.org/mailman/listinfo/python-list > > > > Use split() and join() methods of strings, along with slicing. Like this: > > > > fullstring = """foo > > bar > > baz""" > > > > sansfirstline = '\n'.join(fullstring.split('\n')[1:]) > > > > The last line does this: > > 1. fullstring.split('\n') turns it into a list of ['foo', 'bar', 'baz'] > > 2. the [1:] slice removes the first element, making it ['bar', 'baz'] > > 3. Finally, '\n'.join() turns the list into a string separated by > > newlines ("""bar > > baz""") > > This, of course, worked like a charm. I really need to study the string > methods. In the work I'm doing they are going to come in very handy. > Thank you, Chris! Let me toss out a couple of other possibilities. Not necessarily better, but if you're learning about strings, you might as well learn some other ways to do it: s = """foo bar baz""" print "using index..." i = s.index('\n') print s[i+1:] print "using regex..." import re print re.sub(r'^[^\n]*\n', '', s) I'll admit, the split/slice/join solution is probably the easiest to implement (and to understand when you're reading the code). But, it copies all the data twice; once when split() runs, and again when join() runs. Both the index and regex solutions should only do a single copy. For huge strings, this might matter. For a three-liner as in your example, it doesn't make any difference. From fabiosantosart at gmail.com Wed Sep 11 08:08:18 2013 From: fabiosantosart at gmail.com (=?ISO-8859-1?Q?F=E1bio_Santos?=) Date: Wed, 11 Sep 2013 13:08:18 +0100 Subject: How can I remove the first line of a multi-line string? (SOLVED) In-Reply-To: References: <5224B786.2050606@gmail.com> Message-ID: On 2 Sep 2013 18:13, "Roy Smith" wrote: > > In article , > Anthony Papillion wrote: > > > On 09/02/2013 11:12 AM, Chris ?Kwpolska? Warrick wrote: > > > On Mon, Sep 2, 2013 at 6:06 PM, Anthony Papillion > > > wrote: > > >> Hello Everyone, > > >> > > >> I have a multi-line string and I need to remove the very first line from > > >> it. How can I do that? I looked at StringIO but I can't seem to figure > > >> out how to properly use it to remove the first line. Basically, I want > > >> to toss the first line but keep everything else. Can anyone put me on > > >> the right path? I know it is probably easy but I'm still learning Python > > >> and don't have all the string functions down yet. > > >> > > >> Thanks, > > >> Anthony > > >> -- > > >> http://mail.python.org/mailman/listinfo/python-list > > > > > > Use split() and join() methods of strings, along with slicing. Like this: > > > > > > fullstring = """foo > > > bar > > > baz""" > > > > > > sansfirstline = '\n'.join(fullstring.split('\n')[1:]) > > > > > > The last line does this: > > > 1. fullstring.split('\n') turns it into a list of ['foo', 'bar', 'baz'] > > > 2. the [1:] slice removes the first element, making it ['bar', 'baz'] > > > 3. Finally, '\n'.join() turns the list into a string separated by > > > newlines ("""bar > > > baz""") > > > > This, of course, worked like a charm. I really need to study the string > > methods. In the work I'm doing they are going to come in very handy. > > Thank you, Chris! > > Let me toss out a couple of other possibilities. Not necessarily > better, but if you're learning about strings, you might as well learn > some other ways to do it: > > > s = """foo > > bar > > baz""" > > print "using index..." > i = s.index('\n') > print s[i+1:] > > print "using regex..." > import re > print re.sub(r'^[^\n]*\n', '', s) > > > I'll admit, the split/slice/join solution is probably the easiest to > implement (and to understand when you're reading the code). But, it > copies all the data twice; once when split() runs, and again when join() > runs. Both the index and regex solutions should only do a single copy. > For huge strings, this might matter. For a three-liner as in your > example, it doesn't make any difference. > Is there not a limit argument to str.split? This should be trivial. first, rest = multiline_str.split('\n', 1) -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Wed Sep 11 08:42:54 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 11 Sep 2013 08:42:54 -0400 Subject: How can I remove the first line of a multi-line string? (SOLVED) In-Reply-To: References: <5224B786.2050606@gmail.com> Message-ID: On 9/11/2013 8:08 AM, F?bio Santos wrote: > Is there not a limit argument to str.split? This should be trivial. Yes, I posted an example using it the first day. I also showed how to use iter and next with files and avoid copying. > first, rest = multiline_str.split('\n', 1) This does not work right is there is no '\n' Then someone pointed out first, dummy, rest = partition('\n') which does work with no '\n' -- Terry Jan Reedy From roy at panix.com Wed Sep 11 09:03:27 2013 From: roy at panix.com (Roy Smith) Date: Wed, 11 Sep 2013 09:03:27 -0400 Subject: How can I remove the first line of a multi-line string? (SOLVED) References: <5224B786.2050606@gmail.com> Message-ID: In article , F?bio Santos wrote: One suggested solution: > > > > sansfirstline = '\n'.join(fullstring.split('\n')[1:]) To which I suggested a couple of alternatives: > > i = s.index('\n') > > print s[i+1:] > > [...] > > print re.sub(r'^[^\n]*\n', '', s) > > I'll admit, the split/slice/join solution is probably the easiest to > > implement (and to understand when you're reading the code). But, it > > copies all the data twice; once when split() runs, and again when join() > > runs. Both the index and regex solutions should only do a single copy. > > For huge strings, this might matter. For a three-liner as in your > > example, it doesn't make any difference. > > > > Is there not a limit argument to str.split? This should be trivial. > > first, rest = multiline_str.split('\n', 1) This certainly prevents the extra splitting and re-compositing of the additional lines. One thing to watch out for is that split(s, 1) does *at most* 1 split. If the original string didn't have any newlines, you would end up with a single-item list and the unpack would fail. You can get around that with: rest = multiline_str.split('\n', 1)[-1] but that's kind of cryptic. Looking back at my solutions suggested above, s.index() fails in the same situation (throws ValueError). The regex solution works fine, once again proving that 1970's technology is still superior to all this newfangled stuff. A coworker recently introduced me to what is apparently a classic essay (http://www.team.net/mjb/hawg.html). If Unix is the Hole Hawg of operating systems, then regexes are the Hole Hawg of string processing tools. Those of us who grew up around them, appreciate their power and have learned how to use them without chopping off any fingers. And we look on with a mix of amusement and pity at the current crop of programmers who play with index(), split(), startswith(), rpartition(), etc and think they're using real tools :-) For the record, I have never used a Hole Hawg. I do, however, own a Milwaukee 1/2" drill. Which also comes with the screw-in handle for two-handed operation. I've had that get away from me a couple of times, so I figure it's about my limit. Torque is a wonderful thing until the thing you're drilling into weighs more than you do. From oscar.j.benjamin at gmail.com Mon Sep 2 12:18:26 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 2 Sep 2013 17:18:26 +0100 Subject: How can I remove the first line of a multi-line string? In-Reply-To: <5224B786.2050606@gmail.com> References: <5224B786.2050606@gmail.com> Message-ID: On 2 September 2013 17:06, Anthony Papillion wrote: > Hello Everyone, > > I have a multi-line string and I need to remove the very first line from > it. How can I do that? I looked at StringIO but I can't seem to figure > out how to properly use it to remove the first line. Basically, I want > to toss the first line but keep everything else. Can anyone put me on > the right path? I know it is probably easy but I'm still learning Python > and don't have all the string functions down yet. >>> a = '''asd ... qwe ... rty''' >>> print(a) asd qwe rty >>> a.splitlines() ['asd', 'qwe', 'rty'] >>> a.splitlines(True) # Keep the new lines ['asd\n', 'qwe\n', 'rty'] >>> a.splitlines(True)[1:] # remove first line ['qwe\n', 'rty'] >>> ''.join(a.splitlines(True)[1:]) # recombine 'qwe\nrty' >>> a = ''.join(a.splitlines(True)[1:]) >>> print(a) qwe rty Oscar From vlastimil.brom at gmail.com Mon Sep 2 13:18:36 2013 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Mon, 2 Sep 2013 19:18:36 +0200 Subject: How can I remove the first line of a multi-line string? In-Reply-To: <5224B786.2050606@gmail.com> References: <5224B786.2050606@gmail.com> Message-ID: 2013/9/2 Anthony Papillion : > Hello Everyone, > > I have a multi-line string and I need to remove the very first line from > it. How can I do that? I looked at StringIO but I can't seem to figure > out how to properly use it to remove the first line. Basically, I want > to toss the first line but keep everything else. Can anyone put me on > the right path? I know it is probably easy but I'm still learning Python > and don't have all the string functions down yet. > > Thanks, > Anthony > -- > http://mail.python.org/mailman/listinfo/python-list Hi, it is probably not worth it for such simple replacement, but just to add another possibility to the already mentioned methods - you can use regular expression replacement: >>> import re >>> re.sub(r"^.*\n", "", "abc\ndef\nghi") 'def\nghi' >>> hth, vbr From tjreedy at udel.edu Mon Sep 2 18:19:17 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 02 Sep 2013 18:19:17 -0400 Subject: How can I remove the first line of a multi-line string? In-Reply-To: <5224B786.2050606@gmail.com> References: <5224B786.2050606@gmail.com> Message-ID: On 9/2/2013 12:06 PM, Anthony Papillion wrote: > I have a multi-line string and I need to remove the very first line from > it. How can I do that? I looked at StringIO but I can't seem to figure > out how to properly use it to remove the first line. Basically, I want > to toss the first line but keep everything else. Can anyone put me on > the right path? I know it is probably easy but I'm still learning Python > and don't have all the string functions down yet. Simply splitting off the first line, using the maxsplit parameter, is more efficient that splitting all lines and joining all but the first. I presume you also want to remove a single line without \n to split on. def keeprest(s): try: return s.split('\n', 1)[1] except IndexError: return '' for s in ('', 'a', 'a\n', 'a\nrest\n'): print('for', repr(s), 'kept:', repr(keeprest(s))) >>> for '' kept: '' for 'a' kept: '' for 'a\n' kept: '' for 'a\nrest\n' kept: 'rest\n' MRAB's s.partition('\n')[2] has exactly the same result as keeprest(s) as, by design, it handles the no-separator case and always returns a triple. I believe it is the equivalent (in C for CPython) of def partition(self, string, splitter): try: first, rest = string.split(splitter, maxsplit=1) return (first, splitter, rest) except ValueError: # from impossible assignment of 1 item to 2 names return (string, '', '') --- If you have *any* iterable of lines and want to process the first line differently than the rest (including just ignoring it), you can use first = True: for line in lines: if first: process_first(line) first = False else: process_rest(line) *or* it = iter(sometext) try: first = next(it) except StopIteration: # always catch this with explicit next pass At this point, *it* now represents the rest of the text and you can pass it to any function expecting an iterable of lines. -- Terry Jan Reedy From mrcoludk at gmail.com Mon Sep 2 13:11:42 2013 From: mrcoludk at gmail.com (mrcoludk at gmail.com) Date: Mon, 2 Sep 2013 10:11:42 -0700 (PDT) Subject: Cookie or not..? Message-ID: <1ad0741f-b1a7-4226-bda6-8a4f194243fb@googlegroups.com> Hello Group. I am a Python noob, and need some help. I am trying to log in to website using python and parse info after login. In a browser, this link will log me in and keep me loged in: http://[domain].com/loginh.aspx?SID=[xxx]&USER=[xxx]&PW=[xxx] (sorry for the tripple x, but it is actually not something nasty :-) ) I normally do this import os import shutil import utils import urllib2 lobj = urllib2.urlopen('[URL-sorce]') print lobj.read() ... and then parse output, but i need to login to get all info. Any input will be appreciated. From joel.goldstick at gmail.com Mon Sep 2 13:22:34 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 2 Sep 2013 13:22:34 -0400 Subject: Cookie or not..? In-Reply-To: <1ad0741f-b1a7-4226-bda6-8a4f194243fb@googlegroups.com> References: <1ad0741f-b1a7-4226-bda6-8a4f194243fb@googlegroups.com> Message-ID: On Mon, Sep 2, 2013 at 1:11 PM, wrote: > Hello Group. > > I am a Python noob, and need some help. I am trying to log in to website using python and parse info after login. > > In a browser, this link will log me in and keep me loged in: > http://[domain].com/loginh.aspx?SID=[xxx]&USER=[xxx]&PW=[xxx] > > (sorry for the tripple x, but it is actually not something nasty :-) ) > > > I normally do this > > > import os > import shutil > import utils > import urllib2 > > lobj = urllib2.urlopen('[URL-sorce]') > print lobj.read() > > > ... and then parse output, but i need to login to get all info. > > Any input will be appreciated. > -- > http://mail.python.org/mailman/listinfo/python-list You will need to understand a little about http protocol, and cookies. Try starting here: http://docs.python-requests.org/en/latest/ -- Joel Goldstick http://joelgoldstick.com From dieter at handshake.de Tue Sep 3 02:02:01 2013 From: dieter at handshake.de (dieter) Date: Tue, 03 Sep 2013 08:02:01 +0200 Subject: Cookie or not..? References: <1ad0741f-b1a7-4226-bda6-8a4f194243fb@googlegroups.com> Message-ID: <87sixm30km.fsf@handshake.de> mrcoludk at gmail.com writes: > I am a Python noob, and need some help. I am trying to log in to website using python and parse info after login. > > In a browser, this link will log me in and keep me loged in: > http://[domain].com/loginh.aspx?SID=[xxx]&USER=[xxx]&PW=[xxx] > > (sorry for the tripple x, but it is actually not something nasty :-) ) Look at the "cookielib" (called "cookiejar" for Python 3) module in Python's library. From nagle at animats.com Mon Sep 2 13:43:19 2013 From: nagle at animats.com (John Nagle) Date: Mon, 02 Sep 2013 10:43:19 -0700 Subject: Python FTP timeout value not effective Message-ID: I'm reading files from an FTP server at the U.S. Securities and Exchange Commission. This code has been running successfully for years. Recently, they imposed a consistent connection delay of 20 seconds at FTP connection, presumably because they're having some denial of service attack. Python 2.7 urllib2 doesn't seem to use the timeout specified. After 20 seconds, it gives up and times out. Here's the traceback: Internal error in EDGAR update: .... File "./edgar/edgarnetutil.py", line 53, in urlopen return(urllib2.urlopen(url,timeout=timeout)) File "/opt/python27/lib/python2.7/urllib2.py", line 126, in urlopen return _opener.open(url, data, timeout) File "/opt/python27/lib/python2.7/urllib2.py", line 394, in open response = self._open(req, data) File "/opt/python27/lib/python2.7/urllib2.py", line 412, in _open '_open', req) File "/opt/python27/lib/python2.7/urllib2.py", line 372, in _call_chain result = func(*args) File "/opt/python27/lib/python2.7/urllib2.py", line 1379, in ftp_open fw = self.connect_ftp(user, passwd, host, port, dirs, req.timeout) File "/opt/python27/lib/python2.7/urllib2.py", line 1400, in connect_ftp fw = ftpwrapper(user, passwd, host, port, dirs, timeout) File "/opt/python27/lib/python2.7/urllib.py", line 860, in __init__ self.init() File "/opt/python27/lib/python2.7/urllib.py", line 866, in init self.ftp.connect(self.host, self.port, self.timeout) File "/opt/python27/lib/python2.7/ftplib.py", line 132, in connect self.sock = socket.create_connection((self.host, self.port), self.timeout) File "/opt/python27/lib/python2.7/socket.py", line 571, in create_connection raise err URLError: Periodic update completed in 21.1 seconds. ---------------------------------------------- Here's the relevant code: TIMEOUTSECS = 60 ## give up waiting for server after 60 seconds ... def urlopen(url,timeout=TIMEOUTSECS) : if url.endswith(".gz") : # gzipped file, must decompress first nd = urllib2.urlopen(url,timeout=timeout) # get connection ... # (NOT .gz FILE, DOESN'T TAKE THIS PATH) else : return(urllib2.urlopen(url,timeout=timeout)) # (OPEN FAILS) TIMEOUTSECS used to be 20 seconds, and I increased it to 60. It didn't help. This isn't an OS problem. The above traceback was on a Linux system. On Windows 7, it fails with "URLError: " But in both cases, the command line FTP client will work, after a consistent 20 second delay before the login prompt. So the Python timeout parameter isn't working. John Nagle From db3l.net at gmail.com Mon Sep 2 18:00:27 2013 From: db3l.net at gmail.com (David Bolen) Date: Mon, 02 Sep 2013 18:00:27 -0400 Subject: Python FTP timeout value not effective References: Message-ID: John Nagle writes: > Here's the relevant code: > > TIMEOUTSECS = 60 ## give up waiting for server after 60 seconds > ... > def urlopen(url,timeout=TIMEOUTSECS) : > if url.endswith(".gz") : # gzipped file, must decompress first > nd = urllib2.urlopen(url,timeout=timeout) # get connection > ... # (NOT .gz FILE, DOESN'T TAKE THIS PATH) > else : > return(urllib2.urlopen(url,timeout=timeout)) # (OPEN FAILS) > > > TIMEOUTSECS used to be 20 seconds, and I increased it to 60. It didn't > help. I apologize if it's an obvious question, but is there any possibility that the default value to urlopen is not being used, but some other timeout is being supplied? Or that somehow TIMEOUTSECS is being redefined before being used by the urlopen definition? Can you (or have you) verified the actual timeout parameter value being supplied to urllib2.urlopen? The fact that you seem to still be timing out very close to the prior 20s timeout value seems a little curious, since there's no timeout by default (barring an application level global socket default), so it feels like a value being supplied. Not sure which 2.7 you're using, but I tried the below with both 2.7.3 and 2.7.5 on Linux since they were handy, and the timeout parameter seems to be working properly at least in a case I can simulate (xxx is a firewalled host so the connection attempt just gets black-holed until the timeout): >>> import time, urllib2 >>> def test(timeout): ... print time.ctime() ... try: ... urllib2.urlopen('ftp://xxx', timeout=timeout) ... except: ... print 'Error' ... print time.ctime() ... >>> test(5) Mon Sep 2 17:36:15 2013 Error Mon Sep 2 17:36:20 2013 >>> test(20) Mon Sep 2 17:36:23 2013 Error Mon Sep 2 17:36:44 2013 >>> test(60) Mon Sep 2 17:36:50 2013 Error Mon Sep 2 17:37:50 2013 It's tougher to simulate a host that artificially delays the connection attempt but then succeeds, so maybe it's an issue related specifically to that implementation. Depending on how the delay is implemented (delaying SYN response versus accepting the connection but just delaying the welcome banner, for example), I suppose it may be tickling some very specific bug. Since all communication essentially boils down to I/O over the socket, it seems to me likely that those cases should still fail over time periods related to the timeout supplied, unlike your actual results, which makes me wonder about the actual urllib2.urlopen timeout parameter. -- David From rosuav at gmail.com Mon Sep 2 18:35:33 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 Sep 2013 08:35:33 +1000 Subject: Python FTP timeout value not effective In-Reply-To: References: Message-ID: On Tue, Sep 3, 2013 at 3:43 AM, John Nagle wrote: > "URLError: failed because the connected party did not properly respond after a > period of time, or established connection failed because connected host > has failed to respond>" > > But in both cases, the command line FTP client will work, after a > consistent 20 second delay before the login prompt. So the > Python timeout parameter isn't working. That's a socket timeout, not an FTP timeout - that's why the timeout parameter isn't doing anything. Are you sure it's just a 20-second delay there? Check if there's something else blocking the connection somehow. Can you telnet to that computer on port 21? ChrisA From tjreedy at udel.edu Mon Sep 2 20:04:59 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 02 Sep 2013 20:04:59 -0400 Subject: Python FTP timeout value not effective In-Reply-To: References: Message-ID: On 9/2/2013 1:43 PM, John Nagle wrote: > I'm reading files from an FTP server at the U.S. Securities and > Exchange Commission. This code has been running successfully for > years. Recently, they imposed a consistent connection delay > of 20 seconds at FTP connection, presumably because they're having > some denial of service attack. Python 2.7 urllib2 doesn't > seem to use the timeout specified. After 20 seconds, it > gives up and times out. > > Here's the traceback: > > Internal error in EDGAR update: Connection timed out> > .... > File "./edgar/edgarnetutil.py", line 53, in urlopen > > File "/opt/python27/lib/python2.7/socket.py", line 571, in > create_connection ... > raise err > URLError: > > Periodic update completed in 21.1 seconds. > ---------------------------------------------- > > Here's the relevant code: > > TIMEOUTSECS = 60 ## give up waiting for server after 60 seconds > ... > def urlopen(url,timeout=TIMEOUTSECS) : > if url.endswith(".gz") : # gzipped file, must decompress first > nd = urllib2.urlopen(url,timeout=timeout) # get connection > ... # (NOT .gz FILE, DOESN'T TAKE THIS PATH) > else : > return(urllib2.urlopen(url,timeout=timeout)) # (OPEN FAILS) I looked at the 3.3 urllib.retrieve.urlopen code and timeout is passed through a couple of layers but is it hard to see if it reaches the socket connection call. I would also try python3.3 as timeout may have been changed a bit. There are some 'timeout' issues on the tracker, such as http://bugs.python.org/issue4079 http://bugs.python.org/issue18417 but these do not obviously apply to an explicitly passed timeout I would also try using ftplib, which cuts out lots of the general purpose layers urlopen. FTP.__init__ stores timeout in self.timeout and calls connect(), which passes self.timeout to socket.create_connection. >>> import ftplib >>> ftp = ftplib.FTP("ftp.sec.gov") >>> ftp.login() '230-Anonymous access granted, restrictions apply\n \n Please read the file README.txt\n230 it was last modified on Tue Aug 15 14:29:31 2000 - 4765 days ago' >>> ftp.sendcmd('help') "214-The following commands are recognized (* =>'s unimplemented):\n CWD XCWD CDUP XCUP SMNT* QUIT PORT PASV \n EPRT EPSV ALLO* RNFR RNTO DELE MDTM RMD \n XRMD MKD XMKD PWD XPWD SIZE SYST HELP \n NOOP FEAT OPTS AUTH* CCC* CONF* ENC* MIC* \n PBSZ* PROT* TYPE STRU MODE RETR STOR STOU \n APPE REST ABOR USER PASS ACCT* REIN* LIST \n NLST STAT SITE MLSD MLST \n214 Direct comments to root at clone11.sec.gov" I tried to read 'README.txt but I do not know how to use the commands or local FTP methods. > TIMEOUTSECS used to be 20 seconds, and I increased it to 60. It didn't > help. > > This isn't an OS problem. The above traceback was on a Linux system. > On Windows 7, it fails with > > "URLError: failed because the connected party did not properly respond after a > period of time, or established connection failed because connected host > has failed to respond>" > > But in both cases, the command line FTP client will work, after a > consistent 20 second delay before the login prompt. So the > Python timeout parameter isn't working. -- Terry Jan Reedy From jcasale at activenetwerx.com Mon Sep 2 18:13:27 2013 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Mon, 2 Sep 2013 22:13:27 +0000 Subject: sqlite issue in 2.7.5 Message-ID: I have been battling an issue hopefully someone here has insight with. I have a database with a few tables I perform a query against with some joins against columns collated with NOCASE that leverage = comparisons. Running the query on the database opened in sqlitestudio returns the results in under a minute. Running the query in Python with sqlite3 doesn't return results for several hours. I haven't figured out what pragmas or other shortcuts sqlitestudio uses to provide the results so fast. Using apsw returns the dataset nearly instantaneously but the connection/cursor/commit differences are too drastic and would force far too large a rewrite for the module change. Anyone by chance know the underlying changes required in the sqlite3 module to replicate what sqlitestudio is doing behind the scenes? Thanks, jlc From alister.ware at ntlworld.com Tue Sep 3 08:22:42 2013 From: alister.ware at ntlworld.com (Alister) Date: Tue, 03 Sep 2013 12:22:42 GMT Subject: sqlite issue in 2.7.5 References: Message-ID: On Mon, 02 Sep 2013 22:13:27 +0000, Joseph L. Casale wrote: > I have been battling an issue hopefully someone here has insight with. > > I have a database with a few tables I perform a query against with some > joins against columns collated with NOCASE that leverage = comparisons. > > Running the query on the database opened in sqlitestudio returns the > results in under a minute. Running the query in Python with sqlite3 > doesn't return results for several hours. I haven't figured out what > pragmas or other shortcuts sqlitestudio uses to provide the results so > fast. > > Using apsw returns the dataset nearly instantaneously but the > connection/cursor/commit differences are too drastic and would force far > too large a rewrite for the module change. > > Anyone by chance know the underlying changes required in the sqlite3 > module to replicate what sqlitestudio is doing behind the scenes? > > Thanks, > jlc you are almost certainly doing something drastically wrong can you provides examples of your code & the data structure otherwise I doubt that anyone will be able to assist. -- To err is human, to forgive, beyond the scope of the Operating System. From mbg1708 at planetmail.com Mon Sep 9 19:55:50 2013 From: mbg1708 at planetmail.com (mbg1708 at planetmail.com) Date: Mon, 9 Sep 2013 16:55:50 -0700 (PDT) Subject: sqlite issue in 2.7.5 In-Reply-To: References: Message-ID: <13e070df-ea58-4b51-867e-24d223a788e3@googlegroups.com> On Tuesday, September 3, 2013 8:22:42 AM UTC-4, Alister wrote: > On Mon, 02 Sep 2013 22:13:27 +0000, Joseph L. Casale wrote: > > > > > I have been battling an issue hopefully someone here has insight with. > > > > > > I have a database with a few tables I perform a query against with some > > > joins against columns collated with NOCASE that leverage = comparisons. > > > > > > Running the query on the database opened in sqlitestudio returns the > > > results in under a minute. Running the query in Python with sqlite3 > > > doesn't return results for several hours. I haven't figured out what > > > pragmas or other shortcuts sqlitestudio uses to provide the results so > > > fast. > > > > > > Using apsw returns the dataset nearly instantaneously but the > > > connection/cursor/commit differences are too drastic and would force far > > > too large a rewrite for the module change. > > > > > > Anyone by chance know the underlying changes required in the sqlite3 > > > module to replicate what sqlitestudio is doing behind the scenes? > > > > > > Thanks, > > > jlc > > > > you are almost certainly doing something drastically wrong > > can you provides examples of your code & the data structure otherwise I > > doubt that anyone will be able to assist. > > > -- > > To err is human, to forgive, beyond the scope of the Operating System. This pragma speeds up most processes 10-20 times (yes 10-20): pragma synchronous=OFF See the SQLITE documentation for an explanation. I've found no problems with this setting. From jcasale at activenetwerx.com Mon Sep 9 20:42:20 2013 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Tue, 10 Sep 2013 00:42:20 +0000 Subject: sqlite issue in 2.7.5 In-Reply-To: <13e070df-ea58-4b51-867e-24d223a788e3@googlegroups.com> References: <13e070df-ea58-4b51-867e-24d223a788e3@googlegroups.com> Message-ID: > This pragma speeds up most processes 10-20 times (yes 10-20): > pragma synchronous=OFF > > See the SQLITE documentation for an explanation. > I've found no problems with this setting. Aside from database integrity and consistency? :) I have that one set to OFF as my case mandates data processing and the database is secondary and not re-used, nor required if the process halts. The issue I actually had was after several large bulk inserts, statistics for indices were no longer valid and the statements performing several joins that would leverage them were not performing well. Not knowing this and accessing the data from different methods would cause the symptoms to manifest to varying degrees. Ultimately, after all the inserts I run an ANALYZE command that takes ~30 seconds and a query that normally takes ~2 hours was done in less than 2 seconds. jlc From mohsen at pahlevanzadeh.org Mon Sep 2 20:48:04 2013 From: mohsen at pahlevanzadeh.org (Mohsen Pahlevanzadeh) Date: Tue, 03 Sep 2013 05:18:04 +0430 Subject: problem of double import in python Message-ID: <1378169284.6921.16.camel@debian> Dear all, I remember to avoiding to confusing compiler for header, use ///////////////// // in my include file #define MYHEADER_H // and in others code use: #ifndef MYHEADER_H #include blahblah ///////////////////////// Unfortunately, i prevent to same error, double import to python, but i don't know how to solve, Even i don't know policy of python programmers. You'll make me happy if explain me... Yours, Mohsen From wuwei23 at gmail.com Mon Sep 2 21:07:53 2013 From: wuwei23 at gmail.com (alex23) Date: Tue, 03 Sep 2013 11:07:53 +1000 Subject: problem of double import in python In-Reply-To: References: Message-ID: On 3/09/2013 10:48 AM, Mohsen Pahlevanzadeh wrote: > Unfortunately, i prevent to same error, double import to python, but i > don't know how to solve, Even i don't know policy of python programmers. You don't need to do anything, Python takes care of this for you. During execution, a module is only loaded the first time it is imported. Every following import will notice that it has already been loaded and return a reference to the module instead. From mohsen at pahlevanzadeh.org Mon Sep 2 21:16:26 2013 From: mohsen at pahlevanzadeh.org (Mohsen Pahlevanzadeh) Date: Tue, 03 Sep 2013 05:46:26 +0430 Subject: problem of double import in python In-Reply-To: <1378169284.6921.16.camel@debian> References: <1378169284.6921.16.camel@debian> Message-ID: <1378170986.6921.19.camel@debian> When i uncomment //// from common.interface.interface import ShowHide //// in file contains Ui_Materials class i get the following traceback: ////////////////////////// Traceback (most recent call last): File "./main.py", line 110, in main() File "./main.py", line 91, in main interfaceObj.showMaterials() File "/home/mohsen/codes/amlak/amlak/src/common/interface/interface.py", line 80, in showMaterials self.ui = Ui_Materials() NameError: global name 'Ui_Materials' is not defined ////////////////////////////////// Yours, Mohsen On Tue, 2013-09-03 at 05:18 +0430, Mohsen Pahlevanzadeh wrote: > Dear all, > > I remember to avoiding to confusing compiler for header, use > ///////////////// > // in my include file > #define MYHEADER_H > // and in others code use: > #ifndef MYHEADER_H > #include blahblah > ///////////////////////// > > Unfortunately, i prevent to same error, double import to python, but i > don't know how to solve, Even i don't know policy of python programmers. > > You'll make me happy if explain me... > > Yours, > Mohsen > From joel.goldstick at gmail.com Mon Sep 2 21:29:45 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 2 Sep 2013 21:29:45 -0400 Subject: problem of double import in python In-Reply-To: <1378170986.6921.19.camel@debian> References: <1378169284.6921.16.camel@debian> <1378170986.6921.19.camel@debian> Message-ID: On Mon, Sep 2, 2013 at 9:16 PM, Mohsen Pahlevanzadeh wrote: > When i uncomment > //// > from common.interface.interface import ShowHide The line above only loads interface.interface.ShowHide I > //// > in file contains Ui_Materials class i get the following traceback: > ////////////////////////// > Traceback (most recent call last): > File "./main.py", line 110, in > main() > File "./main.py", line 91, in main > interfaceObj.showMaterials() > File > "/home/mohsen/codes/amlak/amlak/src/common/interface/interface.py", line > 80, in showMaterials > self.ui = Ui_Materials() > NameError: global name 'Ui_Materials' is not defined You should do this: import common.interface.interface later do this: self.ui = common.interface.interface.Ui_Materials() If you are annoyed by the long names you can do this: import common.interface.interface as ci then self.ui = ci.Ui_Materials. Look up the section in python.org on importing modules to learn more -- Joel Goldstick http://joelgoldstick.com From gaurangnshah at gmail.com Tue Sep 3 00:45:57 2013 From: gaurangnshah at gmail.com (gaurangnshah at gmail.com) Date: Mon, 2 Sep 2013 21:45:57 -0700 (PDT) Subject: How to execute command on remote windows machine Message-ID: <33a44ace-33d1-493f-85cb-4f0a093368af@googlegroups.com> Hi Guys, I have a requirement where i need to kill one process on remote windows machine. Following command just works fine if i have to kill process on local machine os.system('taskkill /f /im processName.exe') However I am not able to figure out how to execute this command on remote windows machine. Note: my local machine is also windows (machine from where i have to execute command) so is there any way i can execute command from windows machine on remote windows machine ? From steve at pearwood.info Tue Sep 3 01:19:13 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 03 Sep 2013 05:19:13 GMT Subject: How to execute command on remote windows machine References: <33a44ace-33d1-493f-85cb-4f0a093368af@googlegroups.com> Message-ID: <52257151$0$2743$c3e8da3$76491128@news.astraweb.com> On Mon, 02 Sep 2013 21:45:57 -0700, gaurangnshah wrote: > so is there any way i can execute command from windows machine on remote > windows machine ? You are looking for information on "Remote Procedure Calls", or RPC. There are obvious security implementations from enabling RPC, imagine if random people on the internet could shut down whichever processes they like on your machine. But having said that, there are a number of excellent RPC libraries for Python. Here are two I have (briefly) used: http://pythonhosted.org/Pyro4/ https://pypi.python.org/pypi/rpyc -- Steven From wuwei23 at gmail.com Tue Sep 3 01:33:17 2013 From: wuwei23 at gmail.com (alex23) Date: Tue, 03 Sep 2013 15:33:17 +1000 Subject: How to execute command on remote windows machine In-Reply-To: <33a44ace-33d1-493f-85cb-4f0a093368af@googlegroups.com> References: <33a44ace-33d1-493f-85cb-4f0a093368af@googlegroups.com> Message-ID: On 3/09/2013 2:45 PM, gaurangnshah at gmail.com wrote: > I have a requirement where i need to kill one process on remote windows machine. > Following command just works fine if i have to kill process on local machine > > os.system('taskkill /f /im processName.exe') > > However I am not able to figure out how to execute this command on remote windows machine. The simplest way is from your local machine. taskkill accepts a /s parameter which can specify a remote machine by IP or name. http://technet.microsoft.com/en-us/library/bb491009.aspx From gaurangnshah at gmail.com Tue Sep 3 02:45:38 2013 From: gaurangnshah at gmail.com (gaurangnshah at gmail.com) Date: Mon, 2 Sep 2013 23:45:38 -0700 (PDT) Subject: How to execute command on remote windows machine In-Reply-To: References: <33a44ace-33d1-493f-85cb-4f0a093368af@googlegroups.com> Message-ID: <74ce5096-46df-42e4-ad30-fd6f5d22f40f@googlegroups.com> Hi alex I tried the command you suggested however it is giving me following error. ERROR: The RPC server is unavailable. On Tuesday, 3 September 2013 11:03:17 UTC+5:30, alex23 wrote: > On 3/09/2013 2:45 PM, gaurangnshah at gmail.com wrote: > > > I have a requirement where i need to kill one process on remote windows machine. > > > Following command just works fine if i have to kill process on local machine > > > > > > os.system('taskkill /f /im processName.exe') > > > > > > However I am not able to figure out how to execute this command on remote windows machine. > > > > The simplest way is from your local machine. taskkill accepts a /s > > parameter which can specify a remote machine by IP or name. > > > > http://technet.microsoft.com/en-us/library/bb491009.aspx On Tuesday, 3 September 2013 11:03:17 UTC+5:30, alex23 wrote: > On 3/09/2013 2:45 PM, gaurangnshah at gmail.com wrote: > > > I have a requirement where i need to kill one process on remote windows machine. > > > Following command just works fine if i have to kill process on local machine > > > > > > os.system('taskkill /f /im processName.exe') > > > > > > However I am not able to figure out how to execute this command on remote windows machine. > > > > The simplest way is from your local machine. taskkill accepts a /s > > parameter which can specify a remote machine by IP or name. > > > > http://technet.microsoft.com/en-us/library/bb491009.aspx From jeanmichel at sequans.com Tue Sep 3 05:44:01 2013 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 3 Sep 2013 11:44:01 +0200 (CEST) Subject: How to execute command on remote windows machine In-Reply-To: <74ce5096-46df-42e4-ad30-fd6f5d22f40f@googlegroups.com> Message-ID: <716039553.47511070.1378201441651.JavaMail.root@sequans.com> ----- Original Message ----- > Hi alex > > I tried the command you suggested however it is giving me following > error. > > ERROR: The RPC server is unavailable. Hi, Please do not top post :) If python is installed on the remote machine, using execnet http://codespeak.net/execnet/ is very easy. Its only requirement is python being installed on both machines. JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From random832 at fastmail.us Tue Sep 3 08:39:18 2013 From: random832 at fastmail.us (random832 at fastmail.us) Date: Tue, 03 Sep 2013 08:39:18 -0400 Subject: How to execute command on remote windows machine In-Reply-To: <33a44ace-33d1-493f-85cb-4f0a093368af@googlegroups.com> References: <33a44ace-33d1-493f-85cb-4f0a093368af@googlegroups.com> Message-ID: <1378211958.24424.17322289.1A7478CF@webmail.messagingengine.com> On Tue, Sep 3, 2013, at 0:45, gaurangnshah at gmail.com wrote: > Hi Guys, > > I have a requirement where i need to kill one process on remote windows > machine. > Following command just works fine if i have to kill process on local > machine > > os.system('taskkill /f /im processName.exe') > > However I am not able to figure out how to execute this command on remote > windows machine. > > Note: my local machine is also windows (machine from where i have to > execute command) > > so is there any way i can execute command from windows machine on remote > windows machine ? The taskkill command actually has an option for this: /S. I don't know what mechanism it uses or what you would have to do to give yourself permission to use it. -- Random832 From jeanmichel at sequans.com Tue Sep 3 09:57:22 2013 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 3 Sep 2013 15:57:22 +0200 (CEST) Subject: How to execute command on remote windows machine In-Reply-To: Message-ID: <691125559.47760759.1378216642547.JavaMail.root@sequans.com> ----- Original Message ----- > I tried it, however it seems really complicated. > If you have used it before, can you show me how can i do it ? > Gaurang Shah > Blog: qtp-help.blogspot.com > Mobile: +91 738756556 Please don't ask question off-list. It's not complicated at all. The documentation has a lot of examples: http://codespeak.net/execnet/example/test_info.html#execute-source-code-in-subprocess-communicate-through-a-channel makegateway by defaut execute the code on the local machine. You simply need to use something like makegateway("ssh=myRemoteMachine") cheers, JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From dihedral88888 at gmail.com Tue Sep 3 10:21:11 2013 From: dihedral88888 at gmail.com (88888 Dihedral) Date: Tue, 3 Sep 2013 07:21:11 -0700 (PDT) Subject: How to execute command on remote windows machine In-Reply-To: <33a44ace-33d1-493f-85cb-4f0a093368af@googlegroups.com> References: <33a44ace-33d1-493f-85cb-4f0a093368af@googlegroups.com> Message-ID: gauran... at gmail.com? 2013?9?3????UTC+8??12?45?57???? > Hi Guys, > > > > I have a requirement where i need to kill one process on remote windows machine. > > Following command just works fine if i have to kill process on local machine > > > > os.system('taskkill /f /im processName.exe') > > > > However I am not able to figure out how to execute this command on remote windows machine. > > > > Note: my local machine is also windows (machine from where i have to execute command) > > > > so is there any way i can execute command from windows machine on remote windows machine ? This is trivial. First install the VNC on the remote site and make sure your VNC is working in the proper forground. Just write a mouse/keyboard emulator service on the remote site with the propper port opened by python scripts. Use the control computer to send commands to the remote site. This scheme will work under unix-linux-windows OS. From nikos at superhost.gr Tue Sep 3 03:48:13 2013 From: nikos at superhost.gr (Ferrous Cranus) Date: Tue, 03 Sep 2013 10:48:13 +0300 Subject: Cannot form correctly the FORM part of the header when sending mail Message-ID: Hello, i have written the following snipper of code to help me send mail: ================================================================================================================= # if html form is submitted then send user mail #================================================================================================================ if( mailform ): try: if (FROM is None) or (MESSAGE is None) or ('@' not in FROM) or ('????? ??? ???' in MESSAGE): print( "

?????????? ????? ?? mail ??? ??? ???? ?? ????????? ???!

" ) else: # prepare mail data TO = "nikos at superhost.gr" SUBJECT = u"Mail ??? ??? ?????????: ( %s )" % FROM MESSAGE = "From: %s\r\n" + "To: %s\r\n" + "Subject: %s\r\n" + MESSAGE + "\r\n" MESSAGE = MESSAGE % ( FROM, TO, SUBJECT ) MESSAGE = MESSAGE.encode('utf-8') # open Gmail's SMTP server server = smtplib.SMTP('smtp.gmail.com:587') server.ehlo() server.starttls() # next, log in to the server server.login("nikos.gr33k at gmail.com", "rmrcdherpbsfggcw") # send the mail server.sendmail( FROM, [TO], MESSAGE ) print( "

????????? ???? ??? ?? ??????????! ?? ???????????? ???? ??? ????? :-)

" ) except Exception as e: print( repr(e), file=open( '/tmp/err.out', 'a' ) ) sys.exit(0) ======================================================================= It works as expected, but the the problem is that it display the FROM part as being send from ,my personal GMail account when it supposed to be shown the format variable field that was passed by index.html to the mail.py script. Si there a workaround for that please? -- Webhost From feedthetroll at gmx.de Tue Sep 3 05:33:28 2013 From: feedthetroll at gmx.de (feedthetroll at gmx.de) Date: Tue, 3 Sep 2013 02:33:28 -0700 (PDT) Subject: Cannot form correctly the FORM part of the header when sending mail In-Reply-To: References: Message-ID: Am Dienstag, 3. September 2013 09:48:13 UTC+2 schrieb Ferrous Cranus: > Hello, > i have written the following snipper of code to help me send mail: > ... > server.login("nikos.gr33k at gmail.com", "......") HE DID IT AGAIN! The login works with the posted password! Nikos, you should change your password IMMEDIATELY! > ... From nikos at superhost.gr Tue Sep 3 06:44:21 2013 From: nikos at superhost.gr (Ferrous Cranus) Date: Tue, 03 Sep 2013 13:44:21 +0300 Subject: Cannot form correctly the FORM part of the header when sending mail In-Reply-To: References: Message-ID: ???? 3/9/2013 12:33 ??, ?/? feedthetroll at gmx.de ??????: > Am Dienstag, 3. September 2013 09:48:13 UTC+2 schrieb Ferrous Cranus: >> Hello, >> i have written the following snipper of code to help me send mail: >> ... >> server.login("nikos.gr33k at gmail.com", "......") > HE DID IT AGAIN! The login works with the posted password! > Nikos, you should change your password IMMEDIATELY! .. OMG! I cannot believe i'm being *that* careless, so many times. -- Webhost From piet at vanoostrum.org Tue Sep 3 22:14:31 2013 From: piet at vanoostrum.org (Piet van Oostrum) Date: Tue, 03 Sep 2013 22:14:31 -0400 Subject: Cannot form correctly the FORM part of the header when sending mail References: Message-ID: Ferrous Cranus writes: > Hello, > i have written the following snipper of code to help me send mail: > [snip] > # prepare mail data > TO = "nikos at superhost.gr" > > SUBJECT = u"Mail ??? ??? ?????????: ( %s )" % FROM > > MESSAGE = "From: %s\r\n" + "To: %s\r\n" + "Subject: %s\r\n" > + MESSAGE + "\r\n" > MESSAGE = MESSAGE % ( FROM, TO, SUBJECT ) > MESSAGE = MESSAGE.encode('utf-8') First a couple of remarks: 1. You should add an empty line between the headers and the message (I suppose the message does not start with an empty line). 2. It is better to do the % substitution only on the headers, not including the message, just in case the message contains a % sign. That makes it: MESSAGE = "From: %s\r\n" + "To: %s\r\n" + "Subject: %s\r\n\r\n" % ( FROM, TO, SUBJECT ) + MESSAGE + "\r\n" MESSAGE = MESSAGE.encode('utf-8') 3. It is bad coding style in Python to use all-caps variables. Better use message instead of MESSAGE etc. [snip] > It works as expected, but the the problem is that it display the FROM > part as being send from ,my personal GMail account when it supposed to > be shown the format variable field that was passed by index.html to the > mail.py script. Where does it display that? Do you happen to read that mail in a Microsoft program? If yes, then it is the fault of that program. Read the mail in some other program and you will probably see that the proper From address is there. The problem is that Gmail inserts a "Sender" header with your account (email address) and certain Microsoft programs use that to display as the From address instead of the real From address. It's against the rules, but then, Microsoft makes its own rules and who is going to stop them? And maybe there are other mail programs that do the same. AFAIK there is no way to get rid of that Sender line. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From nikos.gr33k at gmail.com Wed Sep 4 05:57:17 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Wed, 4 Sep 2013 02:57:17 -0700 (PDT) Subject: Cannot form correctly the FORM part of the header when sending mail In-Reply-To: References: Message-ID: <31119ff9-f3ff-4eba-99eb-5b0d85f94008@googlegroups.com> ?? ???????, 4 ??????????? 2013 5:14:31 ?.?. UTC+3, ? ??????? Piet van Oostrum ??????: > Where does it display that? > Do you happen to read that mail in a Microsoft program? yes. Thunderbird. > If yes, then it is the fault of that program. Read the mail in some > other program and you will probably see that the proper From address is > there. i used retrieval of 'nikosatsuperhost.gr' within GMail's service. Same way of dispalyment there too. > The problem is that Gmail inserts a "Sender" header with your account > (email address) and certain Microsoft programs use that to display as > the From address instead of the real From address. I think it's logical to act that way. The real 'FROM' address that GMail uses to send mail from my 'mail.py' to some recipient is my real GMail's account address, and not the FROM address that any arbitrary poster posts in a html webform hwich can be totally fake, i.e. jackass at hahaha.com I believe any kind of mail client will be have this way. We need some way to dicth the Sender FROM string or alter it to the one uses in the webform. From davea at davea.name Wed Sep 4 07:15:15 2013 From: davea at davea.name (Dave Angel) Date: Wed, 4 Sep 2013 11:15:15 +0000 (UTC) Subject: Cannot form correctly the FORM part of the header when sending mail References: <31119ff9-f3ff-4eba-99eb-5b0d85f94008@googlegroups.com> Message-ID: On 4/9/2013 05:57, Ferrous Cranus wrote: > ?? ???????, 4 ??????????? 2013 5:14:31 ?.?. UTC+3, ? ??????? Piet van Oostrum ??????: > >> Where does it display that? >> Do you happen to read that mail in a Microsoft program? > > yes. Thunderbird. When did Microsoft take over Thunderbird's development???? In any case, Thunderbird has te ability to display the actual message received. See menu: View->MessageSource > >> If yes, then it is the fault of that program. Read the mail in some >> other program and you will probably see that the proper From address is >> there. > > i used retrieval of 'nikosatsuperhost.gr' within GMail's service. > > Same way of dispalyment there too. > > >> The problem is that Gmail inserts a "Sender" header with your account >> (email address) and certain Microsoft programs use that to display as >> the From address instead of the real From address. > > I think it's logical to act that way. > > The real 'FROM' address that GMail uses to send mail from my 'mail.py' to some recipient is my real GMail's account address, and not the FROM address that any arbitrary poster posts in a html webform hwich can be totally fake, i.e. jackass at hahaha.com > > I believe any kind of mail client will be have this way. > We need some way to dicth the Sender FROM string or alter it to the one uses in the webform. -- DaveA From nikos at superhost.gr Wed Sep 4 07:29:15 2013 From: nikos at superhost.gr (Ferrous Cranus) Date: Wed, 04 Sep 2013 14:29:15 +0300 Subject: Cannot form correctly the FORM part of the header when sending mail In-Reply-To: References: <31119ff9-f3ff-4eba-99eb-5b0d85f94008@googlegroups.com> Message-ID: ???? 4/9/2013 2:15 ??, ?/? Dave Angel ??????: >> ?? ???????, 4 ??????????? 2013 5:14:31 ?.?. UTC+3, ? ??????? Piet van Oostrum ??????: >>> Where does it display that? >>> Do you happen to read that mail in a Microsoft program? >> yes. Thunderbird. > When did Microsoft take over Thunderbird's development???? > > In any case, Thunderbird has te ability to display the actual message > received. See menu: > View->MessageSource > I meant i'm using ThunderBird and not Outlook Express. I doesn't matter what the mail headers say but the actual presentation of the email which state always that it was sent by my personal GMail address and not from the mail address that was posted int he webform -- Webhost From davea at davea.name Wed Sep 4 08:21:48 2013 From: davea at davea.name (Dave Angel) Date: Wed, 4 Sep 2013 12:21:48 +0000 (UTC) Subject: Cannot form correctly the FORM part of the header when sending mail References: <31119ff9-f3ff-4eba-99eb-5b0d85f94008@googlegroups.com> Message-ID: On 4/9/2013 07:29, Ferrous Cranus wrote: > ???? 4/9/2013 2:15 ??, ?/? Dave Angel ??????: >>> ?? ???????, 4 ??????????? 2013 5:14:31 ?.?. UTC+3, ? ??????? Piet van Oostrum ??????: >>>> Where does it display that? >>>> Do you happen to read that mail in a Microsoft program? >>> yes. Thunderbird. >> When did Microsoft take over Thunderbird's development???? >> >> In any case, Thunderbird has te ability to display the actual message >> received. See menu: >> View->MessageSource >> > > I meant i'm using ThunderBird and not Outlook Express. > > I doesn't matter what the mail headers say but the actual presentation > of the email which state always that it was sent by my personal GMail > address and not from the mail address that was posted int he webform > One way to distinguish a bug in the python logic and in gmail, from a bug in the mail reader is to examine the message source. Others may be able to guess what it looks like, but I cannot. -- DaveA From piet at vanoostrum.org Wed Sep 4 12:22:21 2013 From: piet at vanoostrum.org (Piet van Oostrum) Date: Wed, 04 Sep 2013 12:22:21 -0400 Subject: Cannot form correctly the FORM part of the header when sending mail References: <31119ff9-f3ff-4eba-99eb-5b0d85f94008@googlegroups.com> Message-ID: Ferrous Cranus writes: > I think it's logical to act that way. I think it is not, see my other post on this subject. > The real 'FROM' address that GMail uses to send mail from my 'mail.py' > to some recipient is my real GMail's account address, and not the FROM > address that any arbitrary poster posts in a html webform hwich can be > totally fake, i.e. jackass at hahaha.com No, it's not, as I explained. Gmail uses the From address that you specified, but added the Sender header with your Gmail account in it. Now your email agent usesdisplays the Sender address as the From, which is misleading. > I believe any kind of mail client will be have this way. No, my mail client doesn'tdo that. > We need some way to dicth the Sender FROM string or alter it to the > one uses in the webform. You cannot ditch the Send from the sent email, as this is something Gmail automatically provides. Maybe as some kind of spam detector, which is reasonable. Actually providing the Sender in situations like this is what the RFC requires, so Gmail is totally, completely correct in doing this. The problem is completely on the receiving side, but Dave has told you how to solve it. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From piet at vanoostrum.org Wed Sep 4 12:16:05 2013 From: piet at vanoostrum.org (Piet van Oostrum) Date: Wed, 04 Sep 2013 12:16:05 -0400 Subject: Cannot form correctly the FORM part of the header when sending mail References: <47707536-3398-4ce7-9872-da90073d7e93@googlegroups.com> Message-ID: Ferrous Cranus writes: > I this hoq you mean? [...] > > SUBJECT = u"Mail ??? ??? ?????????: ( %s )" % FROM > > MESSAGE = "\nFrom: %s\r\n" + "To: %s\r\n" + "Subject: %s\r\n\r\n" % ( FROM, [TO], SUBJECT ) + MESSAGE + "\r\n" > MESSAGE = MESSAGE.encode('utf-8') [...] > but now iam getting this error message: > > sendmail => %s 13-09-04 12:29:22 (, TypeError('not all arguments converted during string formatting',), ) > That is because you changed TO in [TO]. That causes the error. ** And the \n at the beginning shouldn't be there. ** MESSAGE = "From: %s\r\n" + "To: %s\r\n" + "Subject: %s\r\n\r\n" % ( FROM, TO, SUBJECT ) + MESSAGE + "\r\n" You could even change that to: MESSAGE = "From: %s\r\n" + "To: %s\r\n" + "Subject: %s\r\n\r\n%s\r\n" % (FROM, TO, SUBJECT, MESSAGE) which I think is nicer. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From piet at vanoostrum.org Wed Sep 4 17:38:33 2013 From: piet at vanoostrum.org (Piet van Oostrum) Date: Wed, 04 Sep 2013 17:38:33 -0400 Subject: Cannot form correctly the FORM part of the header when sending mail References: <47707536-3398-4ce7-9872-da90073d7e93@googlegroups.com> Message-ID: Piet van Oostrum writes: > Ferrous Cranus writes: > >> I this hoq you mean? > [...] >> >> SUBJECT = u"Mail ??? ??? ?????????: ( %s )" % FROM >> >> MESSAGE = "\nFrom: %s\r\n" + "To: %s\r\n" + "Subject: %s\r\n\r\n" % ( FROM, [TO], SUBJECT ) + MESSAGE + "\r\n" >> MESSAGE = MESSAGE.encode('utf-8') > [...] >> but now iam getting this error message: >> >> sendmail => %s 13-09-04 12:29:22 (, TypeError('not all arguments converted during string formatting',), ) >> > That is because you changed TO in [TO]. That causes the error. > > ** And the \n at the beginning shouldn't be there. ** > > MESSAGE = "From: %s\r\n" + "To: %s\r\n" + "Subject: %s\r\n\r\n" % ( FROM, TO, SUBJECT ) + MESSAGE + "\r\n" > > You could even change that to: > > MESSAGE = "From: %s\r\n" + "To: %s\r\n" + "Subject: %s\r\n\r\n%s\r\n" % (FROM, TO, SUBJECT, MESSAGE) There was another error in that line: The string at the left of the % should be in parentheses, or be a single string: MESSAGE = ("From: %s\r\n" + "To: %s\r\n" + "Subject: %s\r\n\r\n%s\r\n") % ( FROM, TO, SUBJECT, MESSAGE) or MESSAGE = "From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n%s\r\n" % ( FROM, TO, SUBJECT, MESSAGE) or even MESSAGE = "From: %s\r\n" "To: %s\r\n" "Subject: %s\r\n\r\n%s\r\n" % ( FROM, TO, SUBJECT, MESSAGE) Another note: I did some expriments with Gmail and it seems that it also changes the >From header if the address given is not one that you registerd with your gmail account. So it is even worse than I thought. (In practice I didn't notice this because I have all the email addresses I use registered.) -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From nikos at superhost.gr Thu Sep 5 02:31:41 2013 From: nikos at superhost.gr (Ferrous Cranus) Date: Thu, 05 Sep 2013 09:31:41 +0300 Subject: Cannot form correctly the FORM part of the header when sending mail In-Reply-To: References: <47707536-3398-4ce7-9872-da90073d7e93@googlegroups.com> Message-ID: ???? 4/9/2013 7:16 ??, ?/? Piet van Oostrum ??????: > Ferrous Cranus writes: > >> I this hoq you mean? > [...] >> >> SUBJECT = u"Mail ??? ??? ?????????: ( %s )" % FROM >> >> MESSAGE = "\nFrom: %s\r\n" + "To: %s\r\n" + "Subject: %s\r\n\r\n" % ( FROM, [TO], SUBJECT ) + MESSAGE + "\r\n" >> MESSAGE = MESSAGE.encode('utf-8') > [...] >> but now iam getting this error message: >> >> sendmail => %s 13-09-04 12:29:22 (, TypeError('not all arguments converted during string formatting',), ) >> > That is because you changed TO in [TO]. That causes the error. > > ** And the \n at the beginning shouldn't be there. ** > > MESSAGE = "From: %s\r\n" + "To: %s\r\n" + "Subject: %s\r\n\r\n" % ( FROM, TO, SUBJECT ) + MESSAGE + "\r\n" > > You could even change that to: > > MESSAGE = "From: %s\r\n" + "To: %s\r\n" + "Subject: %s\r\n\r\n%s\r\n" % (FROM, TO, SUBJECT, MESSAGE) > > which I think is nicer. > Now i have it like you said: UBJECT = u"SuperHost Guest Mail ??? ??? [ %s ]" % FROM MESSAGE = "From: %s\n" + "To: %s\n" + "Subject: %s\n\n%s\n" % (FROM, TO, SUBJECT, MESSAGE) MESSAGE = MESSAGE.encode('utf-8') but i still get the same error messgae i use '\n' though and not '\r\n' but this is not an issue. -- Webhost From steve at pearwood.info Thu Sep 5 04:58:24 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 05 Sep 2013 08:58:24 GMT Subject: Cannot form correctly the FORM part of the header when sending mail References: <47707536-3398-4ce7-9872-da90073d7e93@googlegroups.com> Message-ID: <522847af$0$2743$c3e8da3$76491128@news.astraweb.com> On Thu, 05 Sep 2013 09:31:41 +0300, Ferrous Cranus wrote: [...] > UBJECT = u"SuperHost Guest Mail ??? ??? [ %s ]" % FROM > > MESSAGE = "From: %s\n" + "To: %s\n" + "Subject: %s\n\n%s\n" % (FROM, TO, > SUBJECT, MESSAGE) > MESSAGE = MESSAGE.encode('utf-8') > > > but i still get the same error messgae And? What is the error message telling you? Don't just ask for help every single time you get an exception. The error says: TypeError: not all arguments converted during string formatting What does that mean? The string formatting operator is % and you can, and should, experiment on it yourself: py> "aaaa %s" % 'hello' 'aaaa hello' Now try to get the error you see: py> "aaaa%s" % ('hello', "world") Traceback (most recent call last): File "", line 1, in TypeError: not all arguments converted during string formatting You have two strings on the right hand side of the % operator, but only one %s target on the left. Now how about this? py> "aa%s" + "bb%s" % ("hello", "world") Traceback (most recent call last): File "", line 1, in TypeError: not all arguments converted during string formatting What's the precedence of + and % operators? Which one gets executed first? Hint: py> 8 + 2 % 5 10 py> (8 + 2) % 5 0 py> 8 + (2 % 5) 10 Even though these examples are with ints, not strings, the precedence is the same. Go back to your code. Read your code. Does it look closer to this: 8 + 2 % 5 or this? (8 + 2) % 5 Can you solve this problem now? -- Steven From nikos at superhost.gr Thu Sep 5 05:34:43 2013 From: nikos at superhost.gr (Ferrous Cranus) Date: Thu, 05 Sep 2013 12:34:43 +0300 Subject: Cannot form correctly the FORM part of the header when sending mail In-Reply-To: <522847af$0$2743$c3e8da3$76491128@news.astraweb.com> References: <47707536-3398-4ce7-9872-da90073d7e93@googlegroups.com> <522847af$0$2743$c3e8da3$76491128@news.astraweb.com> Message-ID: Even though these examples are with ints, not strings, the precedence is the same. Go back to your code. Read your code. Does it look closer to this: 8 + 2 % 5 or this? (8 + 2) % 5 Can you solve this problem now? Yes Steven, according to your precedence example now i can: MESSAGE = ( "From: %s\n" + "To: %s\n" + "Subject: %s\n\n%s\n" ) % ( FROM, TO, SUBJECT, MESSAGE ) MESSAGE = MESSAGE.encode('utf-8') it just need the whole concatenation thing in parenthesis so to be executed first but now: # send the mail server.sendmail( [ MESSAGE ] ) or # send the mail server.sendmail( MESSAGE ) both fail. From nikos at superhost.gr Thu Sep 5 05:36:57 2013 From: nikos at superhost.gr (Ferrous Cranus) Date: Thu, 05 Sep 2013 12:36:57 +0300 Subject: Cannot form correctly the FORM part of the header when sending mail In-Reply-To: References: <47707536-3398-4ce7-9872-da90073d7e93@googlegroups.com> <522847af$0$2743$c3e8da3$76491128@news.astraweb.com> Message-ID: ???? 5/9/2013 12:34 ??, ?/? Ferrous Cranus ??????: > > Even though these examples are with ints, not strings, the precedence is > the same. > > Go back to your code. Read your code. Does it look closer to this: > > 8 + 2 % 5 > > or this? > > (8 + 2) % 5 > > > Can you solve this problem now? > > Yes Steven, according to your precedence example now i can: > > MESSAGE = ( "From: %s\n" + "To: %s\n" + "Subject: %s\n\n%s\n" ) % ( > FROM, TO, SUBJECT, MESSAGE ) > MESSAGE = MESSAGE.encode('utf-8') > > > > it just need the whole concatenation thing in parenthesis so to be > executed first but now: > > > # send the mail > server.sendmail( [ MESSAGE ] ) > > or > > # send the mail > server.sendmail( MESSAGE ) > > both fail. The error messge says: nikos at superhost.gr [~]# cat /tmp/err.out sendmail => 13-09-05 12:20:53 (, TypeError("sendmail() missing 2 required positional arguments: 'to_addrs' and 'msg'",), ) nikos at superhost.gr [~]# but all of the needed args are within MESSAGE. Cant it take it from there? -- Webhost From davea at davea.name Thu Sep 5 06:33:20 2013 From: davea at davea.name (Dave Angel) Date: Thu, 5 Sep 2013 10:33:20 +0000 (UTC) Subject: Cannot form correctly the FORM part of the header when sending mail References: <47707536-3398-4ce7-9872-da90073d7e93@googlegroups.com> <522847af$0$2743$c3e8da3$76491128@news.astraweb.com> Message-ID: On 5/9/2013 05:36, Ferrous Cranus wrote: > > > nikos at superhost.gr [~]# cat /tmp/err.out > sendmail => 13-09-05 12:20:53 (, > TypeError("sendmail() missing 2 required positional arguments: > 'to_addrs' and 'msg'",), ) > nikos at superhost.gr [~]# > > but all of the needed args are within MESSAGE. > Cant it take it from there? > Do you know how to find a link like this? http://docs.python.org/3.3/library/smtplib.html#smtplib.SMTP.sendmail -- DaveA From nikos at superhost.gr Thu Sep 5 06:48:54 2013 From: nikos at superhost.gr (Ferrous Cranus) Date: Thu, 05 Sep 2013 13:48:54 +0300 Subject: Cannot form correctly the FORM part of the header when sending mail In-Reply-To: References: <47707536-3398-4ce7-9872-da90073d7e93@googlegroups.com> <522847af$0$2743$c3e8da3$76491128@news.astraweb.com> Message-ID: ???? 5/9/2013 1:33 ??, ?/? Dave Angel ??????: > On 5/9/2013 05:36, Ferrous Cranus wrote: > >> >> >> nikos at superhost.gr [~]# cat /tmp/err.out >> sendmail => 13-09-05 12:20:53 (, >> TypeError("sendmail() missing 2 required positional arguments: >> 'to_addrs' and 'msg'",), ) >> nikos at superhost.gr [~]# >> >> but all of the needed args are within MESSAGE. >> Cant it take it from there? >> > > Do you know how to find a link like this? > > http://docs.python.org/3.3/library/smtplib.html#smtplib.SMTP.sendmail > > is there way to alter tha FROM field to the one used in the webform by the visitor? GMail adds the Sender by default is there some other service that doesn't and use the FROM field? -- Webhost From feedthetroll at gmx.de Thu Sep 5 07:02:22 2013 From: feedthetroll at gmx.de (feedthetroll at gmx.de) Date: Thu, 5 Sep 2013 04:02:22 -0700 (PDT) Subject: Cannot form correctly the FORM part of the header when sending mail In-Reply-To: References: <47707536-3398-4ce7-9872-da90073d7e93@googlegroups.com> <522847af$0$2743$c3e8da3$76491128@news.astraweb.com> Message-ID: <3d96733e-d18d-4bed-8fe2-b5e9f2132bad@googlegroups.com> Am Donnerstag, 5. September 2013 12:48:54 UTC+2 schrieb Ferrous Cranus: > is there way to alter tha FROM field to the one used in the webform by > the visitor? Yes it ist. You did it in your code. But gmail alters it AFTER you. So again, you did not care to read / understand the answers you got. > GMail adds the Sender by default is there some other service that > doesn't and use the FROM field? Yes. Already answered: Am Mittwoch, 4. September 2013 14:18:55 UTC+2 schrieb Heiko Wundram: > Am 03.09.2013 09:48, schrieb Ferrous Cranus: >> Is there a workaround for that please? > Yes, use/setup your own mailserver. Google will not allow you to send > as ("i.e., From:") an arbitrary address besides the one you've > authenticated as. And again, you did not care to read / understand the answers you got. So again: You are a troll. From nikos at superhost.gr Thu Sep 5 07:20:23 2013 From: nikos at superhost.gr (Ferrous Cranus) Date: Thu, 05 Sep 2013 14:20:23 +0300 Subject: Cannot form correctly the FORM part of the header when sending mail In-Reply-To: <3d96733e-d18d-4bed-8fe2-b5e9f2132bad@googlegroups.com> References: <47707536-3398-4ce7-9872-da90073d7e93@googlegroups.com> <522847af$0$2743$c3e8da3$76491128@news.astraweb.com> <3d96733e-d18d-4bed-8fe2-b5e9f2132bad@googlegroups.com> Message-ID: ???? 5/9/2013 2:02 ??, ?/? feedthetroll at gmx.de ??????: >> Am 03.09.2013 09:48, schrieb Ferrous Cranus: >>> Is there a workaround for that please? >> Yes, use/setup your own mailserver. Google will not allow you to send >> as ("i.e., From:") an arbitrary address besides the one you've >> authenticated as. > And again, you did not care to read / understand the answers you got. > > So again: You are a troll. I'm perfectly awra of the answers given to me. I do car to read them and do care to udnerstand them. I need information on how to setup my own mail server i cannot even connect to my 'mail.mydomain.com' mail server like i do with GMail's. So: server = smtplib.SMTP(localhost) doesn't help, i cannot efen connect to my localhost mail server form within my script. An alternative is needed, one that doesnt add up things as Sender but uses fROM field isntead. -- Webhost -- Webhost From feedthetroll at gmx.de Thu Sep 5 08:18:26 2013 From: feedthetroll at gmx.de (feedthetroll at gmx.de) Date: Thu, 5 Sep 2013 05:18:26 -0700 (PDT) Subject: Cannot form correctly the FORM part of the header when sending mail In-Reply-To: References: <47707536-3398-4ce7-9872-da90073d7e93@googlegroups.com> <522847af$0$2743$c3e8da3$76491128@news.astraweb.com> <3d96733e-d18d-4bed-8fe2-b5e9f2132bad@googlegroups.com> Message-ID: <1af8193f-c6d0-4bcf-aa72-0f8f6f70c0c9@googlegroups.com> Am Donnerstag, 5. September 2013 13:20:23 UTC+2 schrieb Ferrous Cranus: > ???? 5/9/2013 2:02 ??, ?/? feedthetroll ??????: >>> Am 03.09.2013 09:48, schrieb Ferrous Cranus: >>>> Is there a workaround for that please? >>> Yes, use/setup your own mailserver. Google will not allow you to send >>> as ("i.e., From:") an arbitrary address besides the one you've >>> authenticated as. >> And again, you did not care to read / understand the answers you got. >> So again: You are a troll. > > I'm perfectly awra of the answers given to me. I do car to read them and > do care to udnerstand them. > > I need information on how to setup my own mail server > i cannot even connect to my 'mail.mydomain.com' mail server like i do > with GMail's. And you can solve this promblem by asking "How can I change the FROM field with python?" (which was your last question in this context, after you read and understood the cited answers)? ... Good luck! Beeing serious: Which mailserver did you install? postfix, exim, sendmail, ...? Check that and read its dokumentation how to configure authentication. Then you can use it. And if you get stuck: A python list is NOT THE RIGHT PLACE to ask questions about the configuration of mailservers. Find the correct list for your mailserver and ask there! > > So: > server = smtplib.SMTP(localhost) > doesn't help, i cannot efen connect to my localhost mail server form > within my script. See above. > An alternative is needed, one that doesnt add up things as Sender but > uses fROM field isntead. No problem. Configure your own mail server the way you want it to work. But remembering your attitude to security-things it would be better for us if you did NOT adminstrate a mailserver. We do not need another open relay. From nikos at superhost.gr Thu Sep 5 08:36:19 2013 From: nikos at superhost.gr (Ferrous Cranus) Date: Thu, 05 Sep 2013 15:36:19 +0300 Subject: Cannot form correctly the FORM part of the header when sending mail In-Reply-To: <1af8193f-c6d0-4bcf-aa72-0f8f6f70c0c9@googlegroups.com> References: <47707536-3398-4ce7-9872-da90073d7e93@googlegroups.com> <522847af$0$2743$c3e8da3$76491128@news.astraweb.com> <3d96733e-d18d-4bed-8fe2-b5e9f2132bad@googlegroups.com> <1af8193f-c6d0-4bcf-aa72-0f8f6f70c0c9@googlegroups.com> Message-ID: ???? 5/9/2013 3:18 ??, ?/? feedthetroll at gmx.de ??????: > Beeing serious: > Which mailserver did you install? postfix, exim, sendmail, ...? > Check that and read its dokumentation how to configure authentication. > Then you can use it. > And if you get stuck: A python list is NOT THE RIGHT PLACE to ask questions about the configuration of mailservers. Find the correct list for your mailserver and ask there! My WHM uses DoveCot as enaled mail server but i have no idea how to setip up to work. i cannot connect to it via my python script. i looked over at my WHM for configuration but i didnt find out how to properly configure it. -- Webhost From feedthetroll at gmx.de Thu Sep 5 09:29:08 2013 From: feedthetroll at gmx.de (feedthetroll at gmx.de) Date: Thu, 5 Sep 2013 06:29:08 -0700 (PDT) Subject: Cannot form correctly the FORM part of the header when sending mail In-Reply-To: References: <47707536-3398-4ce7-9872-da90073d7e93@googlegroups.com> <522847af$0$2743$c3e8da3$76491128@news.astraweb.com> <3d96733e-d18d-4bed-8fe2-b5e9f2132bad@googlegroups.com> <1af8193f-c6d0-4bcf-aa72-0f8f6f70c0c9@googlegroups.com> Message-ID: <72eb69f7-83b4-4dc4-8cea-a26c8081effb@googlegroups.com> Am Donnerstag, 5. September 2013 14:36:19 UTC+2 schrieb Ferrous Cranus: > ???? 5/9/2013 3:18 ??, ?/? feedthetroll ??????: >> Beeing serious: >> Which mailserver did you install? postfix, exim, sendmail, ...? >> Check that and read its dokumentation how to configure authentication. >> Then you can use it. > >> And if you get stuck: A python list is NOT THE RIGHT PLACE to ask questions >> about the configuration of mailservers. Find the correct list for your >> mailserver and ask there! > > My WHM WHM (http://www.globalacronyms.com/whm): Meaning of Acronym WHM Language Category Watt Hour Meter Acronym in English Science, Unit Measure, Chemistry, Biology, Acronym Work Hour Management Acronym in English General, Common Abbreviation, Slang, Acronym > uses DoveCot as enaled mail server but i have no idea how to > setip up to work. > i cannot connect to it via my python script. OK, I should have been more exact: To send mails you need a "smtp-server" (MTA - Mail Transfer Agent, Message Transport Agent) like postfix, exim, sendmail, ... DoveCot is good for "reading" mail (="mailbox management", "pop3(s)", "imap(s)"). You cannot send mails using DoveCot. (You can use a WebMailService to access DoveCot for reading and a MTA for sending mails.) So you have to find out, which MTA you installed (you have root access, don't you) and configure it. But this is (like so often) becoming extremely offtopic. > i looked over at my WHM for configuration but i didnt find out how to > properly configure it. http://www.dovecot.org/documentation.html - but DoveCot won't help you here. From nikos at superhost.gr Thu Sep 5 09:38:25 2013 From: nikos at superhost.gr (Ferrous Cranus) Date: Thu, 05 Sep 2013 16:38:25 +0300 Subject: Cannot form correctly the FORM part of the header when sending mail In-Reply-To: <72eb69f7-83b4-4dc4-8cea-a26c8081effb@googlegroups.com> References: <47707536-3398-4ce7-9872-da90073d7e93@googlegroups.com> <522847af$0$2743$c3e8da3$76491128@news.astraweb.com> <3d96733e-d18d-4bed-8fe2-b5e9f2132bad@googlegroups.com> <1af8193f-c6d0-4bcf-aa72-0f8f6f70c0c9@googlegroups.com> <72eb69f7-83b4-4dc4-8cea-a26c8081effb@googlegroups.com> Message-ID: ???? 5/9/2013 4:29 ??, ?/? feedthetroll at gmx.de ??????: >> uses DoveCot as enaled mail server but i have no idea how to >> setip up to work. >> i cannot connect to it via my python script. > OK, I should have been more exact: > To send mails you need a "smtp-server" (MTA - Mail Transfer Agent, Message Transport Agent) like postfix, exim, sendmail, ... > > DoveCot is good for "reading" mail (="mailbox management", "pop3(s)", "imap(s)"). You cannot send mails using DoveCot. (You can use a WebMailService to access DoveCot for reading and a MTA for sending mails.) > > So you have to find out, which MTA you installed (you have root access, don't you) and configure it. > > But this is (like so often) becoming extremely offtopic. i as root just inatslled sendmail and mailx. i have edited the ~/.mailrc to use: nikos at superhost.gr [~/www/cgi-bin]# cat ~/.mailrc account gmail { set smtp-use-starttls set smtp=smtp://smtp.gmail.com:587 set smtp-auth=login set smtp-auth-user=may)gmail set smtp-auth-password=my_gmail_pass_not_stupid_enough_to_wite _it_again } And now i'm trying to: cmd = "echo %s | mailx -A gmail -r %s -s %s %s" % (MESSAGE, FROM, SUBJECT, TO) p=subprocess.Popen( cmd, shell=True, stdout=subprocess.PIPE ) output, errors = p.communicate() print( errors, output ) Any ideas please why this fails to work? while i remove the '-A gmail' string in the cmd line then i can send fast mail but only to mail containing the @superhost.gr trail. i need to be eble to send to external mails to. -- Webhost From nikos at superhost.gr Thu Sep 5 10:01:16 2013 From: nikos at superhost.gr (Ferrous Cranus) Date: Thu, 05 Sep 2013 17:01:16 +0300 Subject: Cannot form correctly the FORM part of the header when sending mail In-Reply-To: References: <47707536-3398-4ce7-9872-da90073d7e93@googlegroups.com> <522847af$0$2743$c3e8da3$76491128@news.astraweb.com> <3d96733e-d18d-4bed-8fe2-b5e9f2132bad@googlegroups.com> <1af8193f-c6d0-4bcf-aa72-0f8f6f70c0c9@googlegroups.com> <72eb69f7-83b4-4dc4-8cea-a26c8081effb@googlegroups.com> Message-ID: ???? 5/9/2013 4:38 ??, ?/? Ferrous Cranus ??????: > ???? 5/9/2013 4:29 ??, ?/? feedthetroll at gmx.de ??????: >>> uses DoveCot as enaled mail server but i have no idea how to >>> setip up to work. >>> i cannot connect to it via my python script. >> OK, I should have been more exact: >> To send mails you need a "smtp-server" (MTA - Mail Transfer Agent, >> Message Transport Agent) like postfix, exim, sendmail, ... >> >> DoveCot is good for "reading" mail (="mailbox management", "pop3(s)", >> "imap(s)"). You cannot send mails using DoveCot. (You can use a >> WebMailService to access DoveCot for reading and a MTA for sending >> mails.) >> >> So you have to find out, which MTA you installed (you have root >> access, don't you) and configure it. >> >> But this is (like so often) becoming extremely offtopic. > > > i as root just inatslled > > sendmail and mailx. i have edited the ~/.mailrc to use: > > > nikos at superhost.gr [~/www/cgi-bin]# cat ~/.mailrc > account gmail { > set smtp-use-starttls > set smtp=smtp://smtp.gmail.com:587 > set smtp-auth=login > set smtp-auth-user=may)gmail > set smtp-auth-password=my_gmail_pass_not_stupid_enough_to_wite _it_again > } > > > > And now i'm trying to: > > > cmd = "echo %s | mailx -A gmail -r %s -s %s %s" % (MESSAGE, FROM, > SUBJECT, TO) > p=subprocess.Popen( cmd, shell=True, stdout=subprocess.PIPE ) > output, errors = p.communicate() > print( errors, output ) > > > Any ideas please why this fails to work? > while i remove the '-A gmail' string in the cmd line then i can send > fast mail but only to mail containing the @superhost.gr trail. > > i need to be eble to send to external mails to. > Missing "nss-config-dir" variable. . . . message not sent. Missing "nss-config-dir" variable. . . . message not sent. Missing "nss-config-dir" variable. . . . message not sent. Missing "nss-config-dir" variable. . . . message not sent. Missing "nss-config-dir" variable. . . . message not sent. Missing "nss-config-dir" variable. . . . message not sent. is what iam receivign as error output -- Webhost From wuwei23 at gmail.com Thu Sep 5 23:38:38 2013 From: wuwei23 at gmail.com (alex23) Date: Fri, 06 Sep 2013 13:38:38 +1000 Subject: Cannot form correctly the FORM part of the header when sending mail In-Reply-To: References: <47707536-3398-4ce7-9872-da90073d7e93@googlegroups.com> <522847af$0$2743$c3e8da3$76491128@news.astraweb.com> <3d96733e-d18d-4bed-8fe2-b5e9f2132bad@googlegroups.com> <1af8193f-c6d0-4bcf-aa72-0f8f6f70c0c9@googlegroups.com> <72eb69f7-83b4-4dc4-8cea-a26c8081effb@googlegroups.com> Message-ID: On 6/09/2013 12:01 AM, Ferrous Cranus wrote: >> Any ideas please why this fails to work? > Missing "nss-config-dir" variable. > . . . message not sent. > Missing "nss-config-dir" variable. > . . . message not sent. > Missing "nss-config-dir" variable. > . . . message not sent. > Missing "nss-config-dir" variable. > . . . message not sent. > Missing "nss-config-dir" variable. > . . . message not sent. > Missing "nss-config-dir" variable. > . . . message not sent. > > is what iam receivign as error output You haven't set the configuration value 'nss-config-dir'. You're welcome. From feedthetroll at gmx.de Thu Sep 5 11:00:06 2013 From: feedthetroll at gmx.de (feedthetroll at gmx.de) Date: Thu, 5 Sep 2013 08:00:06 -0700 (PDT) Subject: Cannot form correctly the FORM part of the header when sending mail In-Reply-To: References: <47707536-3398-4ce7-9872-da90073d7e93@googlegroups.com> <522847af$0$2743$c3e8da3$76491128@news.astraweb.com> <3d96733e-d18d-4bed-8fe2-b5e9f2132bad@googlegroups.com> <1af8193f-c6d0-4bcf-aa72-0f8f6f70c0c9@googlegroups.com> <72eb69f7-83b4-4dc4-8cea-a26c8081effb@googlegroups.com> Message-ID: <948e61a7-5b72-4ab9-a234-ce304344165a@googlegroups.com> Am Donnerstag, 5. September 2013 15:38:25 UTC+2 schrieb Ferrous Cranus: > ???? 5/9/2013 4:29 ??, ?/? feedthetroll ??????: >>> uses DoveCot as enaled mail server but i have no idea how to >>> setip up to work. >>> i cannot connect to it via my python script. >> OK, I should have been more exact: >> To send mails you need a "smtp-server" (MTA - Mail Transfer Agent, >> Message Transport Agent) like postfix, exim, sendmail, ... >> >> DoveCot is good for "reading" mail (="mailbox management", "pop3(s)", >> "imap(s)"). You cannot send mails using DoveCot. (You can use a >> WebMailService to access DoveCot for reading and a MTA for sending mails.) >> >> So you have to find out, which MTA you installed (you have root access, >> don't you) and configure it. >> >> But this is (like so often) becoming extremely offtopic. > > i as root just inatslled > > sendmail and mailx. i have edited the ~/.mailrc to use: > > nikos at superhost.gr [~/www/cgi-bin]# cat ~/.mailrc > account gmail { > set smtp-use-starttls > set smtp=smtp://smtp.gmail.com:587 > set smtp-auth=login > set smtp-auth-user=may)gmail > set smtp-auth-password=my_gmail_pass_not_stupid_enough_to_wite _it_again > } Don't use gmail. Gmail is the cause of your problem. As long as you use it (whatever way you use) the problem will persist. USE YOUR SENDMAIL. > And now i'm trying to: > cmd = "echo %s | mailx -A gmail -r %s -s %s %s" % (MESSAGE, FROM, > SUBJECT, TO) > p=subprocess.Popen( cmd, shell=True, stdout=subprocess.PIPE ) > output, errors = p.communicate() > print( errors, output ) DONT INVOKE THIS VIA PYTHON. Use the shell. If it works there, you can try it with python. > Any ideas please why this fails to work? > while i remove the '-A gmail' string in the cmd line then i can send > fast mail but only to mail containing the @superhost.gr trail. > i need to be eble to send to external mails to. THIS IS NOT A SENDMAIL LIST! Solve your sendmail-problem and then, if it still does not work from python come back with a smart question. FUP: comp.mail.sendmail From nikos at superhost.gr Thu Sep 5 11:59:42 2013 From: nikos at superhost.gr (Ferrous Cranus) Date: Thu, 05 Sep 2013 18:59:42 +0300 Subject: Cannot form correctly the FORM part of the header when sending mail In-Reply-To: <948e61a7-5b72-4ab9-a234-ce304344165a@googlegroups.com> References: <47707536-3398-4ce7-9872-da90073d7e93@googlegroups.com> <522847af$0$2743$c3e8da3$76491128@news.astraweb.com> <3d96733e-d18d-4bed-8fe2-b5e9f2132bad@googlegroups.com> <1af8193f-c6d0-4bcf-aa72-0f8f6f70c0c9@googlegroups.com> <72eb69f7-83b4-4dc4-8cea-a26c8081effb@googlegroups.com> <948e61a7-5b72-4ab9-a234-ce304344165a@googlegroups.com> Message-ID: ???? 5/9/2013 6:00 ??, ?/? feedthetroll at gmx.de ??????: > Am Donnerstag, 5. September 2013 15:38:25 UTC+2 schrieb Ferrous Cranus: >> ???? 5/9/2013 4:29 ??, ?/? feedthetroll ??????: >>>> uses DoveCot as enaled mail server but i have no idea how to >>>> setip up to work. >>>> i cannot connect to it via my python script. >>> OK, I should have been more exact: >>> To send mails you need a "smtp-server" (MTA - Mail Transfer Agent, >>> Message Transport Agent) like postfix, exim, sendmail, ... >>> >>> DoveCot is good for "reading" mail (="mailbox management", "pop3(s)", >>> "imap(s)"). You cannot send mails using DoveCot. (You can use a >>> WebMailService to access DoveCot for reading and a MTA for sending mails.) >>> >>> So you have to find out, which MTA you installed (you have root access, >>> don't you) and configure it. >>> >>> But this is (like so often) becoming extremely offtopic. >> >> i as root just inatslled >> >> sendmail and mailx. i have edited the ~/.mailrc to use: >> >> nikos at superhost.gr [~/www/cgi-bin]# cat ~/.mailrc >> account gmail { >> set smtp-use-starttls >> set smtp=smtp://smtp.gmail.com:587 >> set smtp-auth=login >> set smtp-auth-user=may)gmail >> set smtp-auth-password=my_gmail_pass_not_stupid_enough_to_wite _it_again >> } > Don't use gmail. Gmail is the cause of your problem. As long as you use it (whatever way you use) the problem will persist. USE YOUR SENDMAIL. > >> And now i'm trying to: >> cmd = "echo %s | mailx -A gmail -r %s -s %s %s" % (MESSAGE, FROM, >> SUBJECT, TO) >> p=subprocess.Popen( cmd, shell=True, stdout=subprocess.PIPE ) >> output, errors = p.communicate() >> print( errors, output ) > DONT INVOKE THIS VIA PYTHON. Use the shell. If it works there, you can try it with python. > >> Any ideas please why this fails to work? >> while i remove the '-A gmail' string in the cmd line then i can send >> fast mail but only to mail containing the @superhost.gr trail. >> i need to be eble to send to external mails to. > THIS IS NOT A SENDMAIL LIST! > Solve your sendmail-problem and then, if it still does not work from python come back with a smart question. > > FUP: comp.mail.sendmail > pok i will ask to sendmail list but tell me please mailx and senmail are 2 differnt MTAs or mailx makes use of sendmail MTA? -- Webhost From feedthetroll at gmx.de Thu Sep 5 12:50:31 2013 From: feedthetroll at gmx.de (feedthetroll at gmx.de) Date: Thu, 5 Sep 2013 09:50:31 -0700 (PDT) Subject: Cannot form correctly the FORM part of the header when sending mail In-Reply-To: References: <47707536-3398-4ce7-9872-da90073d7e93@googlegroups.com> <522847af$0$2743$c3e8da3$76491128@news.astraweb.com> <3d96733e-d18d-4bed-8fe2-b5e9f2132bad@googlegroups.com> <1af8193f-c6d0-4bcf-aa72-0f8f6f70c0c9@googlegroups.com> <72eb69f7-83b4-4dc4-8cea-a26c8081effb@googlegroups.com> <948e61a7-5b72-4ab9-a234-ce304344165a@googlegroups.com> Message-ID: <90899fa1-3680-41f3-9ed3-08fb752d3764@googlegroups.com> Am Donnerstag, 5. September 2013 17:59:42 UTC+2 schrieb Ferrous Cranus: > ok i will ask to sendmail list Take a look at: > but tell me please mailx and senmail are 2 differnt MTAs or mailx makes > use of sendmail MTA? mailx is a MUA (Mail User Agent) used to read and write mails. For sending mails it uses the MTA. From steve+comp.lang.python at pearwood.info Thu Sep 5 13:50:49 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Sep 2013 17:50:49 GMT Subject: Cannot form correctly the FORM part of the header when sending mail References: <47707536-3398-4ce7-9872-da90073d7e93@googlegroups.com> <522847af$0$2743$c3e8da3$76491128@news.astraweb.com> <3d96733e-d18d-4bed-8fe2-b5e9f2132bad@googlegroups.com> <1af8193f-c6d0-4bcf-aa72-0f8f6f70c0c9@googlegroups.com> <72eb69f7-83b4-4dc4-8cea-a26c8081effb@googlegroups.com> <948e61a7-5b72-4ab9-a234-ce304344165a@googlegroups.com> Message-ID: <5228c478$0$29988$c3e8da3$5496439d@news.astraweb.com> On Thu, 05 Sep 2013 18:59:42 +0300, Ferrous Cranus wrote: > but tell me please mailx and senmail are 2 differnt MTAs or mailx makes > use of sendmail MTA? Nikos, I know you can write English better than that. Are you deliberately trying to look less intelligent? -- Steven From piet at vanoostrum.org Fri Sep 6 00:48:32 2013 From: piet at vanoostrum.org (Piet van Oostrum) Date: Fri, 06 Sep 2013 00:48:32 -0400 Subject: Cannot form correctly the FORM part of the header when sending mail References: <47707536-3398-4ce7-9872-da90073d7e93@googlegroups.com> <522847af$0$2743$c3e8da3$76491128@news.astraweb.com> <3d96733e-d18d-4bed-8fe2-b5e9f2132bad@googlegroups.com> <1af8193f-c6d0-4bcf-aa72-0f8f6f70c0c9@googlegroups.com> <72eb69f7-83b4-4dc4-8cea-a26c8081effb@googlegroups.com> Message-ID: Nikos, if you can't use the smtp server at mail.superhost.gr, or if that has the same restrictions I may have a solution for you. This is a bit off-topic on the Python list/group, s I will throw in a line of Python code to make it on-topic :) I suppose you have the following reasons to want to have the original email address in the message: (1) so that you can see who sent the message, (2) so that you can reply to the original sender. Let's say that the from address was user at example.com Problem 1 can be solved in two ways: (a) Just put the email address in front of the subject line, like: Subject: (From user at example.com) Original subject line (b) This solution is a bit more tricky. - Get a separate email address that you use for these messages, like nikos at hotmail.com. Register this as one of your email addresses in gmail. For this it must be a real email address that belongs to you, not a fake address. When it is registered with gmail, gmail will not change it if found in a From header. Make sure that Thunderbird DOES NOT KNOW that this email address belongs to you (i.e. don't use this email address for normal work). Gmail will send you a message to this address to verify that it belongs to you so you must access it through some other means, like a web interface. - Now in the generated email you put the original sender in the comment and your new email address as the real address like: From: "user at example.com" Because Thunderbird doesn't know nikos at hotmail.com it will display the other one, user at example.com. Make sure that the email address doesn't contain a quote character. Better still check that only legal characters are used. Problem 2 can easily be solved by adding a Reply-To header with the original from address. Gmail will not change this. So the code becomes something like: MESSAGE = "From: \"{0}\" \r\n" "Reply-To: {0}\r\n" "To: {1}\r\n" "Subject: (From {0}) {2}\r\n\r\n{3}\r\n".format(FROM, TO, SUBJECT, MESSAGE) In my opinion a better solution would be to filter your mesaage through procmail or similar on your receiving computer. For example put the from address in an X-From header and let the filter replace the From header with the address from the X-From. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From nikos at superhost.gr Fri Sep 6 02:44:40 2013 From: nikos at superhost.gr (Ferrous Cranus) Date: Fri, 06 Sep 2013 09:44:40 +0300 Subject: Cannot form correctly the FORM part of the header when sending mail In-Reply-To: References: <47707536-3398-4ce7-9872-da90073d7e93@googlegroups.com> <522847af$0$2743$c3e8da3$76491128@news.astraweb.com> <3d96733e-d18d-4bed-8fe2-b5e9f2132bad@googlegroups.com> <1af8193f-c6d0-4bcf-aa72-0f8f6f70c0c9@googlegroups.com> <72eb69f7-83b4-4dc4-8cea-a26c8081effb@googlegroups.com> Message-ID: ???? 6/9/2013 7:48 ??, ?/? Piet van Oostrum ??????: > hotmail.com. Register this as one of your email addresses in > gmail. For this it must be a real email address that belongs to you, > not a fake address. When it is registered with gmail, gmail will not > change it if found in a From header. Hello Piet, I'am not sure what you mean by registering a mail address with GMail. Do you mean to add more that one mail account addresses within my GMail account? If you mean that i must tell you that in the pop settinsg inside my gmail.com account i use nikos at superhost.gr and nikos at ath.forthnet.gr as other sending nad retrival mail accounts. Is this what you mean? > So the code becomes something like: > MESSAGE = "From: \"{0}\" \r\n" "Reply-To: {0}\r\n" "To: {1}\r\n" "Subject: (From {0}) {2}\r\n\r\n{3}\r\n".format(FROM, TO, SUBJECT, MESSAGE) If you mean the above then i just have tried, but still not mail gets send. MESSAGE = "From: \"{0}\" \r\n" "Reply-To: {0}\r\n" "To: {1}\r\n" "Subject: (From {0}) {2}\r\n\r\n{3}\r\n".format( FROM, TO, SUBJECT, MESSAGE ) MESSAGE = MESSAGE.encode('utf-8') # open Gmail's SMTP server server = smtplib.SMTP('smtp.gmail.com:587') server.ehlo() server.starttls() # next, log in to the server server.login("my_personal at gmail.com", "my_password") Please elaborate further, thank you. -- Webhost From steve+comp.lang.python at pearwood.info Thu Sep 5 13:28:36 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Sep 2013 17:28:36 GMT Subject: Cannot form correctly the FORM part of the header when sending mail References: <47707536-3398-4ce7-9872-da90073d7e93@googlegroups.com> <522847af$0$2743$c3e8da3$76491128@news.astraweb.com> Message-ID: <5228bf44$0$29988$c3e8da3$5496439d@news.astraweb.com> On Thu, 05 Sep 2013 12:36:57 +0300, Ferrous Cranus wrote: > nikos at superhost.gr [~]# cat /tmp/err.out sendmail => 13-09-05 12:20:53 > (, TypeError("sendmail() missing 2 required > positional arguments: 'to_addrs' and 'msg'",), 0x7f3fb4f44488>) nikos at superhost.gr [~]# > > but all of the needed args are within MESSAGE. Cant it take it from > there? Obviously not. If it could, it would. -- Steven From piet at vanoostrum.org Thu Sep 5 11:19:11 2013 From: piet at vanoostrum.org (Piet van Oostrum) Date: Thu, 05 Sep 2013 11:19:11 -0400 Subject: Cannot form correctly the FORM part of the header when sending mail References: <47707536-3398-4ce7-9872-da90073d7e93@googlegroups.com> <522847af$0$2743$c3e8da3$76491128@news.astraweb.com> Message-ID: Ferrous Cranus writes: > it just need the whole concatenation thing in parenthesis so to be > executed first but now: > > > # send the mail > server.sendmail( [ MESSAGE ] ) > > or > > # send the mail > server.sendmail( MESSAGE ) > > both fail. The first thing you should do then is to look up the documentation of sendmail. http://docs.python.org/ has a good index where you can look for sendmail. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From modelnine at modelnine.org Wed Sep 4 08:18:55 2013 From: modelnine at modelnine.org (Heiko Wundram) Date: Wed, 04 Sep 2013 14:18:55 +0200 Subject: Cannot form correctly the FORM part of the header when sending mail In-Reply-To: References: Message-ID: <5227252F.3060500@modelnine.org> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Am 03.09.2013 09:48, schrieb Ferrous Cranus: > Si there a workaround for that please? Yes, use/setup your own mailserver. Google will not allow you to send as ("i.e., From:") an arbitrary address besides the one you've authenticated as. - -- - --- Heiko. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.20 (MingW32) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJSJyUuAAoJEDMqpHf921/SksoIAJyFyYDN9zj/SypXERj+W1wK fRuby0EyfWWMQayJ7SlbiSUzK3OF1ZVxO5s3WqGdXWI2WhXrrZbltuMyHedlBcqy Dl9F1MtpItg01weICAYJCNcTNm649PCAuc47zbGahE7tDeJwU9xNlgEgXfnpx+eX RvtyYAJlYnz5MTfftYZS9AxxEbaA+k5TNHcVE+5m3YX3Uno6rW+T19H4z4wC374K MHxN4jS+z/qaZ+fDIkK6Uq8aRC5PA9pI37iTD5dJFikKugcp/9AqssnsEUkhMAGV dcGPJnI1tiGrSLY6Q8q31DpkAlO79ETA4ag0yGvnjtmR/ZZjENlb2Ikls7JOA9Y= =JDjl -----END PGP SIGNATURE----- From nikos at superhost.gr Wed Sep 4 10:29:59 2013 From: nikos at superhost.gr (Ferrous Cranus) Date: Wed, 04 Sep 2013 17:29:59 +0300 Subject: Cannot form correctly the FORM part of the header when sending mail In-Reply-To: References: Message-ID: ???? 4/9/2013 3:18 ??, ?/? Heiko Wundram ??????: > Am 03.09.2013 09:48, schrieb Ferrous Cranus: >> Si there a workaround for that please? > Yes, use/setup your own mailserver. Google will not allow you to send > as ("i.e., From:") an arbitrary address besides the one you've > authenticated as. Hello Heiko, You mean to ditch Google's SMTP server and use 'mail.superhost.gr' ? Are you sure the same thing wont happen there too? -- Webhost From piet at vanoostrum.org Wed Sep 4 13:33:39 2013 From: piet at vanoostrum.org (Piet van Oostrum) Date: Wed, 04 Sep 2013 13:33:39 -0400 Subject: Cannot form correctly the FORM part of the header when sending mail References: Message-ID: Ferrous Cranus writes: > ???? 4/9/2013 3:18 ??, ?/? Heiko Wundram ??????: >> Am 03.09.2013 09:48, schrieb Ferrous Cranus: >>> Si there a workaround for that please? >> Yes, use/setup your own mailserver. Google will not allow you to send >> as ("i.e., From:") an arbitrary address besides the one you've >> authenticated as. > > Hello Heiko, > > You mean to ditch Google's SMTP server and use 'mail.superhost.gr' ? > > Are you sure the same thing wont happen there too? > Just try it. In your email program, let it show all headers. Or if you don't trust that, just let the mail be sent to me. I can see exactly how it is. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From piet at vanoostrum.org Wed Sep 4 12:06:55 2013 From: piet at vanoostrum.org (Piet van Oostrum) Date: Wed, 04 Sep 2013 12:06:55 -0400 Subject: Cannot form correctly the FORM part of the header when sending mail References: Message-ID: Heiko Wundram writes: > Am 03.09.2013 09:48, schrieb Ferrous Cranus: >> Si there a workaround for that please? > > Yes, use/setup your own mailserver. Google will not allow you to send > as ("i.e., From:") an arbitrary address besides the one you've > authenticated as. Actually, it does allow you. Only it adds the "Sender" header with your email address. The Sender field is to be used when the message is sent by another person than the author of the message. For example when John at example.com writes an email, but the actual sending of the email is done by his secretary Charles at example.com, the following headers should be present. From: John at example.com Sender: Charles at example.com The mail agent should display John as the originator of the email, and replies should go to him, unless the user chooses differently. However, when there is an error in the transmission, error messages should go to Charles. At least that is what the RFC's say. And I think that is the logical way to do it. Now some Microsoft mail programs will send replies to Charles, which is incorrect. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From nikos at superhost.gr Wed Sep 4 12:49:51 2013 From: nikos at superhost.gr (Ferrous Cranus) Date: Wed, 04 Sep 2013 12:49:51 -0400 Subject: How to exit a cgi file after a download In-Reply-To: References: Message-ID: <4159689.hlvflXlB94@mach-123> Python help. I use the following code in a cgi file to give the client a download link to download a file. --- print "%s" % (' Down Load ') ---- A click on "Down Load" opens a pop up browser window which allows the user to choose where to download the "Setup.zip" file, then after the download, the pop up window closes. My problem is that I want the cgi form, which contains the link, to also close after the download. The only way I can figure out to close the cgi window is to give the user a button to close it. Without closing it, the client can download again and forever if they choose to because the cgi window is open and the link is still active. I am trying to find a way to close the cgi file or call another file after the download without adding a close button and asking the client to close the window. jd From random832 at fastmail.us Wed Sep 4 16:23:33 2013 From: random832 at fastmail.us (random832 at fastmail.us) Date: Wed, 04 Sep 2013 16:23:33 -0400 Subject: How to exit a cgi file after a download In-Reply-To: <4159689.hlvflXlB94@mach-123> References: <4159689.hlvflXlB94@mach-123> Message-ID: <1378326213.28455.17988565.4F92791E@webmail.messagingengine.com> On Wed, Sep 4, 2013, at 12:49, Ferrous Cranus wrote: > Without closing it, the client can download > again and forever if they choose to because > the cgi window is open and the link is still > active. Why is this a problem? They usually won't want to, and if they do want to (for example if they accidentally canceled the download) I don't see why not to let them. The solution should be to give them a unique download link that will only work once (or only for a certain period of time), not to close the window. From benjamin.kaplan at case.edu Wed Sep 4 16:51:00 2013 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 4 Sep 2013 13:51:00 -0700 Subject: How to exit a cgi file after a download In-Reply-To: <4159689.hlvflXlB94@mach-123> References: <4159689.hlvflXlB94@mach-123> Message-ID: On Sep 4, 2013 1:29 PM, "Ferrous Cranus" wrote: > > Python help. > > I use the following code in a cgi file > to give the client a download link to > download a file. > > --- > > print "%s" % (' Down > Load ') > > ---- > > A click on "Down Load" opens a pop up browser > window which allows the user to choose where > to download the "Setup.zip" file, then after > the download, the pop up window closes. > > My problem is that I want the cgi form, which > contains the link, to also close after the > download. The only way I can figure out to > close the cgi window is to give the user a > button to close it. > > Without closing it, the client can download > again and forever if they choose to because > the cgi window is open and the link is still > active. > > I am trying to find a way to close the cgi > file or call another file after the download > without adding a close button and asking the > client to close the window. > > jd > > There is no such thing as a "cgi form" or "cgi window". Your cgi script runs when the user requests a Web page, generates a page, and then ends. At that point, python has stopped running. If your want the client's browser window to close, that's not a python problem. If you want to invalidate the download link after one successful download, you'll have to add a unique identifier to the url and keep track of which identifiers are still valid. -------------- next part -------------- An HTML attachment was scrubbed... URL: From inq1ltd at inqvista.com Thu Sep 5 12:33:42 2013 From: inq1ltd at inqvista.com (inq1ltd) Date: Thu, 05 Sep 2013 12:33:42 -0400 Subject: How to exit a cgi file after a download In-Reply-To: References: <4159689.hlvflXlB94@mach-123> Message-ID: <2704651.qENHhhZOpd@mach-123> There is no such thing as a "cgi form" or "cgi window". Your cgi script runs when the user requests a Web page, generates a page, and then ends. At that point, python has stopped running. If your want the client's browser window to close, that's not a python problem. If you want to invalidate the download link after one successful download, you'll have to add a unique identifier to the url and keep track of which identifiers are still valid. Thanks for responding, Technically cgi is a script. But a form is what a cgi script file can create. The form I asked about is html, it was generated by a cgi script file. So I should have written; a cgi script file generated html form, or a cgi script file generated html window. Lazy writing. My mistake. However I asked a question which now is mute. Once the user downloads the data the user can copy it, so why limit the download?. I appreciate the response, jd inqvista.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From inq1ltd at inqvista.com Wed Sep 4 14:44:23 2013 From: inq1ltd at inqvista.com (inq1ltd) Date: Wed, 04 Sep 2013 14:44:23 -0400 Subject: How to exit a cgi file after a download. In-Reply-To: References: Message-ID: <2469245.AuzWJNP2xm@mach-123> Python help. I use the following code in a cgi file to give the client a download link to download a file. --- print "%s" % (' Down Load ') ---- A click on "Down Load" opens a pop up browser window which allows the user to choose where to download the "Setup.zip" file, then after the download, the pop up window closes. My problem is that I want the cgi form, which contains the link, to also close after the download. The only way I can figure out to close the cgi window is to give the user a button to close it. Without closing it, the client can download again and forever if they choose to because the cgi window is open and the link is still active. I am trying to find a way to close the cgi file or call another file after the download without adding a close button and asking the client to close the window. jd From joel.goldstick at gmail.com Wed Sep 4 15:42:33 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Wed, 4 Sep 2013 15:42:33 -0400 Subject: How to exit a cgi file after a download. In-Reply-To: <2469245.AuzWJNP2xm@mach-123> References: <2469245.AuzWJNP2xm@mach-123> Message-ID: This same message comes up under one of Niko's many aliases. Is this another? Why post twice? On Wed, Sep 4, 2013 at 2:44 PM, inq1ltd wrote: > Python help. > > I use the following code in a cgi file > to give the client a download link to > download a file. > > --- > > print "%s" % (' Down > Load ') > > ---- > > A click on "Down Load" opens a pop up browser > window which allows the user to choose where > to download the "Setup.zip" file, then after > the download, the pop up window closes. > > My problem is that I want the cgi form, which > contains the link, to also close after the > download. The only way I can figure out to > close the cgi window is to give the user a > button to close it. > > Without closing it, the client can download > again and forever if they choose to because > the cgi window is open and the link is still > active. > > I am trying to find a way to close the cgi > file or call another file after the download > without adding a close button and asking the > client to close the window. > > jd > > > > -- > https://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick http://joelgoldstick.com From wuwei23 at gmail.com Wed Sep 4 19:56:25 2013 From: wuwei23 at gmail.com (alex23) Date: Thu, 05 Sep 2013 09:56:25 +1000 Subject: How to exit a cgi file after a download. In-Reply-To: References: <2469245.AuzWJNP2xm@mach-123> Message-ID: On 5/09/2013 5:42 AM, Joel Goldstick wrote: > This same message comes up under one of Niko's many aliases. Is this > another? Why post twice? Because he's a troll. From venkatesh.totad at gmail.com Tue Sep 3 09:54:50 2013 From: venkatesh.totad at gmail.com (Venkatesh) Date: Tue, 3 Sep 2013 06:54:50 -0700 (PDT) Subject: Unable to redirect the subprocess CMD.exe to txt file. Please help !!! Message-ID: <3c50a8aa-261f-447d-b07c-cdad3a5465e0@googlegroups.com> Hello comp.lang.python Group, I am trying to invoke a subprocess in Python as below import sys import time import os import subprocess DETACHED_PROCESS = 0x00000008 path = r'C:\Windows\System32\cmd.exe /k ping www.google.com -n 4 >> temp.txt' p = subprocess.Popen("%s"%(path), stdout = subprocess.PIPE, stderr = subprocess.STDOUT, creationflags=DETACHED_PROCESS) With this code, unable to invoke the subprocess and hence not able to store the Ping statistics in the file. Any help on this OR any better way of achieving this?? From wrw at mac.com Tue Sep 3 10:22:22 2013 From: wrw at mac.com (William Ray Wing) Date: Tue, 03 Sep 2013 10:22:22 -0400 Subject: Unable to redirect the subprocess CMD.exe to txt file. Please help !!! In-Reply-To: <3c50a8aa-261f-447d-b07c-cdad3a5465e0@googlegroups.com> References: <3c50a8aa-261f-447d-b07c-cdad3a5465e0@googlegroups.com> Message-ID: <2581D296-FB96-4521-B840-C1606955971F@mac.com> On Sep 3, 2013, at 9:54 AM, Venkatesh wrote: > Hello comp.lang.python Group, > > I am trying to invoke a subprocess in Python as below > > import sys > import time > import os > import subprocess > DETACHED_PROCESS = 0x00000008 > > path = r'C:\Windows\System32\cmd.exe /k ping www.google.com -n 4 >> temp.txt' > p = subprocess.Popen("%s"%(path), stdout = subprocess.PIPE, stderr = subprocess.STDOUT, creationflags=DETACHED_PROCESS) > > With this code, unable to invoke the subprocess and hence not able to store the Ping statistics in the file. > > Any help on this OR any better way of achieving this?? > > > -- > https://mail.python.org/mailman/listinfo/python-list I use the following in OS-X, should be very similar in Windows. import subprocess ping_result = subprocess.Popen(['ping', '-c1', '-t1', self.target_IP], stderr=subprocess.PIPE, stdout = subprocess.PIPE).communicate()[0] self.target_IP is a string containing the IP address, which is defined elsewhere. ping_result contains the complete returned string from the ping command. Note the -c switch (count = 1 ping packet) and the -t switch (force exit after one second). you will have to parse the returned string to extract the stats. -Bill From random832 at fastmail.us Tue Sep 3 12:21:42 2013 From: random832 at fastmail.us (random832 at fastmail.us) Date: Tue, 03 Sep 2013 12:21:42 -0400 Subject: Unable to redirect the subprocess CMD.exe to txt file. Please help !!! In-Reply-To: <3c50a8aa-261f-447d-b07c-cdad3a5465e0@googlegroups.com> References: <3c50a8aa-261f-447d-b07c-cdad3a5465e0@googlegroups.com> Message-ID: <1378225302.28086.17418213.0AE56B5F@webmail.messagingengine.com> On Tue, Sep 3, 2013, at 9:54, Venkatesh wrote: > Hello comp.lang.python Group, > > I am trying to invoke a subprocess in Python as below > > import sys > import time > import os > import subprocess > DETACHED_PROCESS = 0x00000008 > > path = r'C:\Windows\System32\cmd.exe /k ping www.google.com -n 4 >> > temp.txt' > p = subprocess.Popen("%s"%(path), stdout = subprocess.PIPE, stderr = > subprocess.STDOUT, creationflags=DETACHED_PROCESS) > > With this code, unable to invoke the subprocess and hence not able to > store the Ping statistics in the file. > > Any help on this OR any better way of achieving this?? You should use /c, instead of /k. /k creates an interactive prompt. I think you're being a bit overly complicated though by invoking cmd at all. What about this? subprocess.Popen("ping www.google.com -n 4", stdout=open('temp.txt','a'), ...) From gildororonar at mail-on.us Tue Sep 3 12:07:26 2013 From: gildororonar at mail-on.us (Gildor Oronar) Date: Wed, 04 Sep 2013 00:07:26 +0800 Subject: to be pythonic: should caller or callee log? Message-ID: What would you choose? Do you put logging routine into caller or callee? My intuitive answer is "callee does the logging, because that's where action takes place", like this: class Account(): def transaction(self, amount, target): logging.info("Start transaction of %s to %s" % (amount, target)) ... if '__name__' == '__main__' .... account.transaction(amount, target) Simple and easy. Put logging code to the caller would be tedious - the function is called about 20 times in different places. So far so good, but we grew up to have 10 different account classes: class AbsctractAccount(): class CreditAccount(AbstractAccount): def transaction(self, amount, target): logging.info("Start transaction of %s to %s" % (amount, target)) ... class DebitAccount(AbstractAccount): def transaction(self, amount, target): logging.info("Start transaction of %s to %s" % (amount, target)) ... class SomeOtherAccount(...) .... Then letting the callee do the logging is also tedious now. What is the best practise here? If, for the convenience, we define transaction function in AbstractAccount to just do the logging, and change inherited classes, like this: class AbsctractAccount(): def transaction(self, amount, target): logging.info("Start transaction of %s to %s" % (amount, target)) class DebitAccount(AbstractAccount): def transaction(self, amount, target): super().transaction(amount,target) .... Then we gethered logging code pieces all to one place, but it begets two other problems. 1. It is a "surprise" that super().transaction must be called first, not last, and that it does only the logging. 2. The code used to check whether "transaction" is implemented: if hasAttr(DebitAccount, 'transaction'): # clear to read has to be changed to check whether "transaction" is inherited: if not DebitAccount.transaction is AbstractAccount.transaction: whose purpose is confusing, and whose cause is a little surprise too. Also, the pythonic "boldly calling and watching for exception" stopped working, because instead of getting AttributeError, we would get a line of log and nothing more. From tjreedy at udel.edu Tue Sep 3 17:01:22 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 03 Sep 2013 17:01:22 -0400 Subject: to be pythonic: should caller or callee log? In-Reply-To: References: Message-ID: On 9/3/2013 12:07 PM, Gildor Oronar wrote: > What would you choose? Do you put logging routine into caller or callee? > My intuitive answer is "callee does the logging, because that's where > action takes place", like this: > > class Account(): > def transaction(self, amount, target): > logging.info("Start transaction of %s to %s" % (amount, target)) > ... > > if '__name__' == '__main__' > .... > account.transaction(amount, target) > > > Simple and easy. Put logging code to the caller would be tedious - the > function is called about 20 times in different places. > > So far so good, but we grew up to have 10 different account classes: > > class AbsctractAccount(): > > class CreditAccount(AbstractAccount): > def transaction(self, amount, target): > logging.info("Start transaction of %s to %s" % (amount, target)) > ... > > class DebitAccount(AbstractAccount): > def transaction(self, amount, target): > logging.info("Start transaction of %s to %s" % (amount, target)) > ... > > class SomeOtherAccount(...) > .... > > Then letting the callee do the logging is also tedious now. > > What is the best practise here? > > If, for the convenience, we define transaction function in > AbstractAccount to just do the logging, and change inherited classes, > like this: > > class AbsctractAccount(): > def transaction(self, amount, target): > logging.info("Start transaction of %s to %s" % (amount, target)) > > class DebitAccount(AbstractAccount): > def transaction(self, amount, target): > super().transaction(amount,target) > .... > > Then we gethered logging code pieces all to one place, but it begets two > other problems. > > 1. It is a "surprise" that super().transaction must be called first, Not to me ;-). That is fairly standard in super examples I have seen posted. > not last, and that it does only the logging. If that is the only thing in common ... > 2. The code used to check whether "transaction" is implemented: > if hasAttr(DebitAccount, 'transaction'): # clear to read > has to be changed to check whether "transaction" is inherited: > if not DebitAccount.transaction is AbstractAccount.transaction: > > whose purpose is confusing, and whose cause is a little surprise too. I would expect that every account class has a transaction method. * If so, just call it, but assertIsNot(DebitAccount.transaction, AbstractAccount.transaction) for every subclass in your test suite. * If not, perhaps you need an abstract subclass TransAccount. Then use hasattr in production code and the isnot test in test code. > Also, the pythonic "boldly calling and watching for exception" stopped > working, because instead of getting AttributeError, we would get a line > of log and nothing more. This is what test suites are for. -- Terry Jan Reedy From ethan at stoneleaf.us Tue Sep 3 22:26:09 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 03 Sep 2013 19:26:09 -0700 Subject: to be pythonic: should caller or callee log? In-Reply-To: References: Message-ID: <52269A41.5010704@stoneleaf.us> On 09/03/2013 09:07 AM, Gildor Oronar wrote: > What would you choose? Do you put logging routine into caller or callee? My intuitive answer is "callee does the > logging, because that's where action takes place", like this: > > class Account(): > def transaction(self, amount, target): > logging.info("Start transaction of %s to %s" % (amount, target)) > ... > > So far so good, but we grew up to have 10 different account classes: > > class AbsctractAccount(): > > class CreditAccount(AbstractAccount): > def transaction(self, amount, target): > logging.info("Start transaction of %s to %s" % (amount, target)) > ... > > class DebitAccount(AbstractAccount): > def transaction(self, amount, target): > logging.info("Start transaction of %s to %s" % (amount, target)) > ... > > class SomeOtherAccount(...) > .... > > Then letting the callee do the logging is also tedious now. > > What is the best practise here? > > If, for the convenience, we define transaction function in AbstractAccount to just do the logging, and change inherited > classes, like this: > > class AbsctractAccount(): > def transaction(self, amount, target): > logging.info("Start transaction of %s to %s" % (amount, target)) > > class DebitAccount(AbstractAccount): > def transaction(self, amount, target): > super().transaction(amount,target) > .... In this instance you're not really gaining anything by using inheritance: before you had one line for logging, after you have one line to call super(); in either case if you forget the one line you don't get a log entry. I would say it is not really the caller's or the callee's job to do the logging, even though it should be done. What would be really handy is a function that sat in between the caller and callee that logged for you -- you know, a decorator: # not tested, but hopefully you get the idea def log(func): def wrapper(*args, **kwds): text = [] if args: text.append(str(args)) if kwds: text.append(str(kwds)) text = ', '.join(text) if text: logging.info("%s called with %s" % (func.__name__, text) else: logging.info("%s called" % func.__name__) return func(*args, **kwds) return wrapper Then you can say: class WhateverAccount: @log def transaction(self, amount, target): ... True, you still one line, but moves the logging concern outside the function, where it doesn't really belong. It also makes it really easy to see if a function will be logged or not. -- ~Ethan~ From gildororonar at mail-on.us Wed Sep 4 03:44:17 2013 From: gildororonar at mail-on.us (Gildor Oronar) Date: Wed, 04 Sep 2013 15:44:17 +0800 Subject: to be pythonic: should caller or callee log? In-Reply-To: References: Message-ID: El 04/09/13 10:26, Ethan Furman escribi?: > I would say it is not really the caller's or the callee's job to do the > logging, even though it should be done. What would be really handy is a > function that sat in between the caller and callee that logged for you > -- you know, a decorator: Thanks a lot! My knowledge to decorator is so limited to @staticmethod that I don't know I can write my own decorator. This is a good lesson to learn. Your example lead me to explore and find this article which addressed the case of using decorator to log: http://simeonfranklin.com/blog/2012/jul/1/python-decorators-in-12-steps/ (To googler who find this post: search 'log' in the above article) From gildororonar at mail-on.us Wed Sep 4 03:44:27 2013 From: gildororonar at mail-on.us (Gildor Oronar) Date: Wed, 04 Sep 2013 15:44:27 +0800 Subject: to be pythonic: should caller or callee log? In-Reply-To: References: Message-ID: Thanks: El 04/09/13 05:01, Terry Reedy escribi?: > I would expect that every account class has a transaction method. > * If so, just call it, but > assertIsNot(DebitAccount.transaction, AbstractAccount.transaction) > for every subclass in your test suite. > * If not, perhaps you need an abstract subclass TransAccount. Then use > hasattr in production code and the isnot test in test code. I would assume that you categorize this as a unit test problem, because you consider an Acount not implementing Transaction is a bug, right? There are two occassions an account is intended not having Transaction function, both not test-related: 1. The acount doesn't offer this feature. e.g. Certificate of Deposit. This can be in TransAccount. 2. The 3rd-party account offer this feature but doesn't qualify the software's requirement, e.g. not returning the result in 3 seconds, and is avoided when planning the deal (I am writing an auto-trade software). This case you cannot categorize those who can into TransAccount, beacause 1) that naming imply other accounts don't do transaction but they do, just not good enough; 2) when other accounts becomes good enough, the change (to inheritance) is a bit too invasive. From urtizvereaxaxa at gmail.com Wed Sep 4 08:14:24 2013 From: urtizvereaxaxa at gmail.com (Xaxa Urtiz) Date: Wed, 4 Sep 2013 05:14:24 -0700 (PDT) Subject: to be pythonic: should caller or callee log? In-Reply-To: References: Message-ID: <148ea321-c4e3-457b-bcc8-865f480c80b6@googlegroups.com> Le mercredi 4 septembre 2013 09:44:27 UTC+2, Gildor Oronar a ?crit?: > Thanks: > > > > El 04/09/13 05:01, Terry Reedy escribi?: > > > > > I would expect that every account class has a transaction method. > > > * If so, just call it, but > > > assertIsNot(DebitAccount.transaction, AbstractAccount.transaction) > > > for every subclass in your test suite. > > > * If not, perhaps you need an abstract subclass TransAccount. Then use > > > hasattr in production code and the isnot test in test code. > > > > I would assume that you categorize this as a unit test problem, because > > you consider an Acount not implementing Transaction is a bug, right? > > > > There are two occassions an account is intended not having Transaction > > function, both not test-related: > > > > 1. The acount doesn't offer this feature. e.g. Certificate of Deposit. > > This can be in TransAccount. > > > > 2. The 3rd-party account offer this feature but doesn't qualify the > > software's requirement, e.g. not returning the result in 3 seconds, and > > is avoided when planning the deal (I am writing an auto-trade software). > > This case you cannot categorize those who can into TransAccount, > > beacause 1) that naming imply other accounts don't do transaction but > > they do, just not good enough; 2) when other accounts becomes good > > enough, the change (to inheritance) is a bit too invasive. Hello, and what about something like that : class AbsctractAccount(): def transaction(self, amount, target): logging.info("Start transaction of %s to %s" % (amount, target)) self.DoTransaction(amount,target) def DoTransaction(self,amount,target): pass # or raise notimplemented or do not implement this methods in the abstract class ... class DebitAccount(AbstractAccount): def DoTransaction(self, amount, target): ... class SomeOtherAccount(...) .... like that you only have to write the logging function once. From gildororonar at mail-on.us Fri Sep 6 11:05:59 2013 From: gildororonar at mail-on.us (Gildor Oronar) Date: Fri, 06 Sep 2013 23:05:59 +0800 Subject: to be pythonic: should caller or callee log? In-Reply-To: <148ea321-c4e3-457b-bcc8-865f480c80b6@googlegroups.com> References: <148ea321-c4e3-457b-bcc8-865f480c80b6@googlegroups.com> Message-ID: <5229EF57.3090709@mail-on.us> El 04/09/13 20:14, Xaxa Urtiz escribi?: > and what about something like that : > > > class AbsctractAccount(): > def transaction(self, amount, target): > logging.info("Start transaction of %s to %s" % (amount, target)) > self.DoTransaction(amount,target) > > def DoTransaction(self,amount,target): > pass # or raise notimplemented or do not implement this methods in the abstract class > ... > > class DebitAccount(AbstractAccount): > def DoTransaction(self, amount, target): > ... > > class SomeOtherAccount(...) > .... > like that you only have to write the logging function once. Thanks for the hint! This also work well, and has the advantage of being specific to this function -- I did use decorator as Ethan suggested, which works for most of the case, but there is function (other than transaction) needs specialized logging because the function doesn't return anything but changes a class variable -- using a special decorator for just one function is over-generalizing, and your method kicks in. From brak at gameservers.com Tue Sep 3 16:15:07 2013 From: brak at gameservers.com (Brian Rak) Date: Tue, 03 Sep 2013 16:15:07 -0400 Subject: PyPi Module Removal Message-ID: <5226434B.2020103@gameservers.com> I was trying to install wxPython earlier today. Not RTFMing, I tried 'easy_install wx', which ended up installing this strange module: https://pypi.python.org/pypi/wx Looking at the download stats, it seems to be confusing ~1000 users a month, while not providing any significant functionality. I don't really have any way to contact the author of the module. Is there any way to have this deleted/renamed? From joel.goldstick at gmail.com Tue Sep 3 16:52:17 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 3 Sep 2013 16:52:17 -0400 Subject: PyPi Module Removal In-Reply-To: <5226434B.2020103@gameservers.com> References: <5226434B.2020103@gameservers.com> Message-ID: On Tue, Sep 3, 2013 at 4:15 PM, Brian Rak wrote: > I was trying to install wxPython earlier today. Not RTFMing, I tried > 'easy_install wx', which ended up installing this strange module: > https://pypi.python.org/pypi/wx > > Looking at the download stats, it seems to be confusing ~1000 users a month, > while not providing any significant functionality. > > I don't really have any way to contact the author of the module. Is there > any way to have this deleted/renamed? > -- > https://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick http://joelgoldstick.com From joel.goldstick at gmail.com Tue Sep 3 16:56:48 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 3 Sep 2013 16:56:48 -0400 Subject: PyPi Module Removal In-Reply-To: References: <5226434B.2020103@gameservers.com> Message-ID: On Tue, Sep 3, 2013 at 4:52 PM, Joel Goldstick wrote: > On Tue, Sep 3, 2013 at 4:15 PM, Brian Rak wrote: >> I was trying to install wxPython earlier today. Not RTFMing, I tried >> 'easy_install wx', which ended up installing this strange module: >> https://pypi.python.org/pypi/wx >> >> Looking at the download stats, it seems to be confusing ~1000 users a month, >> while not providing any significant functionality. >> >> I don't really have any way to contact the author of the module. Is there >> any way to have this deleted/renamed? >> -- >> https://mail.python.org/mailman/listinfo/python-list > > > > -- > Joel Goldstick > http://joelgoldstick.com Sorry for empty mail. You can use pip: pip uninstall -- Joel Goldstick http://joelgoldstick.com From skip at pobox.com Tue Sep 3 16:56:09 2013 From: skip at pobox.com (Skip Montanaro) Date: Tue, 3 Sep 2013 15:56:09 -0500 Subject: PyPi Module Removal In-Reply-To: <5226434B.2020103@gameservers.com> References: <5226434B.2020103@gameservers.com> Message-ID: > I don't really have any way to contact the author of the module. Is there > any way to have this deleted/renamed? Not directly, but I opened a ticked in the PyPI bug tracker. Skip From brak at gameservers.com Tue Sep 3 16:59:57 2013 From: brak at gameservers.com (Brian Rak) Date: Tue, 03 Sep 2013 16:59:57 -0400 Subject: PyPi Module Removal In-Reply-To: References: <5226434B.2020103@gameservers.com> Message-ID: <52264DCD.5040606@gameservers.com> Thanks! Wasn't really sure where I should have reported that. On 9/3/2013 4:56 PM, Skip Montanaro wrote: >> I don't really have any way to contact the author of the module. Is there >> any way to have this deleted/renamed? > Not directly, but I opened a ticked in the PyPI bug tracker. > > Skip From tjreedy at udel.edu Tue Sep 3 17:08:39 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 03 Sep 2013 17:08:39 -0400 Subject: PyPi Module Removal In-Reply-To: <5226434B.2020103@gameservers.com> References: <5226434B.2020103@gameservers.com> Message-ID: On 9/3/2013 4:15 PM, Brian Rak wrote: > I was trying to install wxPython earlier today. Not RTFMing, I tried > 'easy_install wx', which ended up installing this strange module: > https://pypi.python.org/pypi/wx > > Looking at the download stats, it seems to be confusing ~1000 users a > month, while not providing any significant functionality. > > I don't really have any way to contact the author of the module. Is > there any way to have this deleted/renamed? There is a PyPI/catalog mailing list, which I believe is the one mirrored as gmane.comp.python.org at news.gmane.com. However, the PyPI admins are reluctant to unilaterally delete a package. They might try to contact the owner of 'wx'. To bad wcPython did not grab the abbreviation. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Tue Sep 3 22:28:18 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Sep 2013 02:28:18 GMT Subject: PyPi Module Removal References: Message-ID: <52269ac1$0$6599$c3e8da3$5496439d@news.astraweb.com> On Tue, 03 Sep 2013 16:15:07 -0400, Brian Rak wrote: > I was trying to install wxPython earlier today. Not RTFMing, I tried > 'easy_install wx', which ended up installing this strange module: > https://pypi.python.org/pypi/wx > > Looking at the download stats, it seems to be confusing ~1000 users a > month, while not providing any significant functionality. Ah, Unix users. Who else would imagine that the way to install something called "wxPython" was to use "install wx"? :-) -- Steven From skip.montanaro at gmail.com Tue Sep 3 22:49:17 2013 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Tue, 3 Sep 2013 21:49:17 -0500 Subject: PyPi Module Removal In-Reply-To: <52269ac1$0$6599$c3e8da3$5496439d@news.astraweb.com> References: <52269ac1$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: > Ah, Unix users. Who else would imagine that the way to install something > called "wxPython" was to use "install wx"? I'm not a wxPython user, but it seems the package/module you import in your programs is "wx". Not an unreasonable guess at the PyPI package name. Skip -------------- next part -------------- An HTML attachment was scrubbed... URL: From brak at gameservers.com Tue Sep 3 23:30:45 2013 From: brak at gameservers.com (Brian Rak) Date: Tue, 03 Sep 2013 23:30:45 -0400 Subject: PyPi Module Removal In-Reply-To: References: <52269ac1$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5226A965.5010600@gameservers.com> On 9/3/2013 10:49 PM, Skip Montanaro wrote: > > > > Ah, Unix users. Who else would imagine that the way to install something > > called "wxPython" was to use "install wx"? > > I'm not a wxPython user, but it seems the package/module you import in > your programs is "wx". Not an unreasonable guess at the PyPI package name. > > Skip > Yep, that was my thinking entirely. 'import wx' = 'pip install wx'. Seems perfectly logical to me. From errol.anderson at gsds.co.nz Tue Sep 3 16:41:57 2013 From: errol.anderson at gsds.co.nz (Errol Anderson) Date: Wed, 4 Sep 2013 08:41:57 +1200 Subject: Conflict between Python 2.5 and 2.7 Message-ID: <002301cea8e6$08d62740$1a8275c0$@gsds.co.nz> I look after a Delphi program that uses Python 2.5 (via Python for Delphi). A customer who uses a modeling program that requires Python 2.7 experiences a Python conflict when trying to run the Delphi program. I have installed both Python 2.5 and 2.7 on a test-bed computer and can run the Delphi program. I have searched the FAQ, and have found some mention of being able to set a default Python version when installing, which I presume has occurred when the customer installed Python 2.7, so that the Delphi program is being directed to Python 2.7. However, I do not see this option when I install Python 2.7, and I do not see how to remove this option so I can advise the customer what to do. The programs are running under Windows 7 - 32-bit. Any assistance gratefully received. Best regards Errol Anderson -------------- next part -------------- An HTML attachment was scrubbed... URL: From me at davecotter.com Tue Sep 3 16:50:27 2013 From: me at davecotter.com (David M. Cotter) Date: Tue, 3 Sep 2013 13:50:27 -0700 (PDT) Subject: can't find win32api from embedded pyrun call In-Reply-To: <1150830594.337374.48170@p79g2000cwp.googlegroups.com> References: <1150765862.185334.53290@u72g2000cwu.googlegroups.com> <1150778593.107920.286580@b68g2000cwa.googlegroups.com> <1150830594.337374.48170@p79g2000cwp.googlegroups.com> Message-ID: I find i'm having this problem, but the solution you found isn't quite specific enough for me to be able to follow it. I'm embedding Python27 in my app. I have users install ActivePython27 in order to take advantage of python in my app, so the python installation can't be touched as it's on a user's machine. When I attempt to do: >import win32api i get this: >Traceback (most recent call last): > File "startup.py", line 5, in >ImportError: DLL load failed: The specified module could not be found. I someone suggested i manually load the dependent libraries in the correct order, like this: >import pywintypes >import pythoncom >import win32api but then i get this: >Traceback (most recent call last): > File "startup.py", line 3, in > File "C:\Python27\lib\site-packages\win32\lib\pywintypes.py", line 124, in > __import_pywin32_system_module__("pywintypes", globals()) > File "C:\Python27\lib\site-packages\win32\lib\pywintypes.py", line 64, in __import_pywin32_system_module__ > import _win32sysloader ImportError: DLL load failed: The specified module could not be found. the ultimate goal here is actually to do this: >from win32com.client.gencache import EnsureDispatch which currently yields: >Traceback (most recent call last): > File "startup.py", line 3, in > File "C:\Python27\lib\site-packages\win32com\__init__.py", line 5, in > import win32api, sys, os >ImportError: DLL load failed: The specified module could not be found. So, if anyone has any idea, that would be super duper great. thanks so much! notes: my paths are definitely set correctly From me at davecotter.com Wed Sep 4 00:32:26 2013 From: me at davecotter.com (David M. Cotter) Date: Tue, 3 Sep 2013 21:32:26 -0700 (PDT) Subject: can't find win32api from embedded pyrun call In-Reply-To: References: <1150765862.185334.53290@u72g2000cwu.googlegroups.com> <1150778593.107920.286580@b68g2000cwa.googlegroups.com> <1150830594.337374.48170@p79g2000cwp.googlegroups.com> Message-ID: <36a4e567-e3d9-4bc3-99d7-42f22020ca0b@googlegroups.com> note that when the script is called, i DO see this in the output window: > 'kJams 2 Debug.exe': Loaded 'C:\Python27\Lib\site-packages\win32\win32api.pyd' > 'kJams 2 Debug.exe': Loaded 'C:\Windows\SysWOW64\pywintypes27.dll' > 'kJams 2 Debug.exe': Unloaded 'C:\Python27\Lib\site-packages\win32\win32api.pyd' > 'kJams 2 Debug.exe': Unloaded 'C:\Windows\SysWOW64\pywintypes27.dll' From mail at timgolden.me.uk Wed Sep 4 03:50:59 2013 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 04 Sep 2013 08:50:59 +0100 Subject: can't find win32api from embedded pyrun call In-Reply-To: References: <1150765862.185334.53290@u72g2000cwu.googlegroups.com> <1150778593.107920.286580@b68g2000cwa.googlegroups.com> <1150830594.337374.48170@p79g2000cwp.googlegroups.com> Message-ID: <5226E663.80200@timgolden.me.uk> On 03/09/2013 21:50, David M. Cotter wrote: > I find i'm having this problem, but the solution you found isn't > quite specific enough for me to be able to follow it. > > I'm embedding Python27 in my app. I have users install > ActivePython27 in order to take advantage of python in my app, so the > python installation can't be touched as it's on a user's machine. > > When I attempt to do: >> import win32api > > i get this: >> Traceback (most recent call last): File "startup.py", line 5, in >> ImportError: DLL load failed: The specified module could >> not be found. You'll likely get more input from the guys on the python-win32 list. Most times I've come across this issue it's been because the pywin32 package (or the whole Python distribution if you're using ActiveState) was not installed as an administrator / elevated. I'm not sure I've ever fathomed why, and the investigation isn't helped by the import dance which the pywin32 code does. I don't remember solving it without a reinstall on the user's machine. TJG From me at davecotter.com Fri Sep 6 15:43:35 2013 From: me at davecotter.com (David M. Cotter) Date: Fri, 6 Sep 2013 12:43:35 -0700 (PDT) Subject: can't find win32api from embedded pyrun call In-Reply-To: <1150765862.185334.53290@u72g2000cwu.googlegroups.com> References: <1150765862.185334.53290@u72g2000cwu.googlegroups.com> Message-ID: <36b8c17a-2966-4a21-9b82-cbd6cc22b793@googlegroups.com> the problem was: ActivePython does not install debug libraries, so you must link with release libraries in your project. but if you run the debug version, you're linking against debug libraries which conflict with the ones linked to by python. "fixed" by running the release version. basically, it's not possible to debug with ActivePython due to ActiveState not including debug libs. grr From mohsen at pahlevanzadeh.org Tue Sep 3 17:30:16 2013 From: mohsen at pahlevanzadeh.org (Mohsen Pahlevanzadeh) Date: Wed, 04 Sep 2013 02:00:16 +0430 Subject: unbound method () must be called with ... instance as first argument (got nothing instead) Message-ID: <1378243816.6921.32.camel@debian> Dear all, I have the following two lines code in my setup frame: ////////////////////// self.showHideConstructor = ui.interface.interface.ShowHide() QtCore.QObject.connect(self.pushButtonAdd, QtCore.SIGNAL(_fromUtf8("clicked()")),self.showHideConstructor,ui.interface.interface.ShowHide.showFindMaterials()) ////////////////////// and i have module ui.interface.interface , it contains ShowHide class, and it consists showFindMaterials() method. When i run program , i get the following traceback : /////////////////////////////////////////// Traceback (most recent call last): File "./main.py", line 113, in main() File "./main.py", line 94, in main interfaceObj.showMaterials() File "/home/mohsen/codes/amlak/amlak/src/ui/interface/interface.py", line 82, in showMaterials self.ui.setupUi(self.Frame) File "/home/mohsen/codes/amlak/amlak/src/ui/materialsFrame.py", line 92, in setupUi QtCore.QObject.connect(self.pushButtonAdd, QtCore.SIGNAL(_fromUtf8("clicked()")),self.showHideConstructor,ui.interface.interface.ShowHide.showFindMaterials()) TypeError: unbound method showFindMaterials() must be called with ShowHide instance as first argument (got nothing instead) /////////////////////////////////////////////// Where's problem? From mohsen at pahlevanzadeh.org Tue Sep 3 17:53:20 2013 From: mohsen at pahlevanzadeh.org (Mohsen Pahlevanzadeh) Date: Wed, 04 Sep 2013 02:23:20 +0430 Subject: unbound method () must be called with ... instance as first argument (got nothing instead) In-Reply-To: <1378243816.6921.32.camel@debian> References: <1378243816.6921.32.camel@debian> Message-ID: <1378245200.6921.34.camel@debian> Solved, i changed my connect function to: QtCore.QObject.connect(self.pushButtonAdd, QtCore.SIGNAL(_fromUtf8("clicked()")),self.showHideConstructor.showFindMaterials) On Wed, 2013-09-04 at 02:00 +0430, Mohsen Pahlevanzadeh wrote: > Dear all, > > I have the following two lines code in my setup frame: > ////////////////////// > self.showHideConstructor = ui.interface.interface.ShowHide() > QtCore.QObject.connect(self.pushButtonAdd, > QtCore.SIGNAL(_fromUtf8("clicked()")),self.showHideConstructor,ui.interface.interface.ShowHide.showFindMaterials()) > ////////////////////// > > and i have module ui.interface.interface , it contains ShowHide class, > and it consists showFindMaterials() method. > > When i run program , i get the following traceback : > /////////////////////////////////////////// > Traceback (most recent call last): > File "./main.py", line 113, in > main() > File "./main.py", line 94, in main > interfaceObj.showMaterials() > File "/home/mohsen/codes/amlak/amlak/src/ui/interface/interface.py", > line 82, in showMaterials > self.ui.setupUi(self.Frame) > File "/home/mohsen/codes/amlak/amlak/src/ui/materialsFrame.py", line > 92, in setupUi > QtCore.QObject.connect(self.pushButtonAdd, > QtCore.SIGNAL(_fromUtf8("clicked()")),self.showHideConstructor,ui.interface.interface.ShowHide.showFindMaterials()) > TypeError: unbound method showFindMaterials() must be called with > ShowHide instance as first argument (got nothing instead) > /////////////////////////////////////////////// > > Where's problem? > > > From hayesstw at telkomsa.net Wed Sep 4 01:26:47 2013 From: hayesstw at telkomsa.net (Steve Hayes) Date: Wed, 04 Sep 2013 07:26:47 +0200 Subject: Beginner's guide to Python Message-ID: Can anyone recommend a web site that gives a good beginner's guide to Python? One that tells one, especially -- -- what kind of projects Python is good for -- what kind of projects it is not good for -- a simple explanation of how it works -- a kind of beginner's tutotial and guide to its syntax I've read about Python, and installed it on my computer when I found it on a DVD that came with a magazine, but I haven't got a clue about how to use it. So any advice on the best web sites for absolute novices would be welcome. -- Steve Hayes from Tshwane, South Africa Blog: http://khanya.wordpress.com E-mail - see web page, or parse: shayes at dunelm full stop org full stop uk From prash.bg at gmail.com Wed Sep 4 02:19:42 2013 From: prash.bg at gmail.com (prashanth B.G) Date: Wed, 4 Sep 2013 11:49:42 +0530 Subject: Beginner's guide to Python In-Reply-To: References: Message-ID: Hi Steve , These links might be of help . http://swaroopch.com/notes/python/ -- Very well explained for beginners http://www.diveintopython.net/ -- Must read to pick up advanced stuff . This can also be used as a starting point to figure out what python might be used for . Hope this works for you . Thanks. On Wed, Sep 4, 2013 at 10:56 AM, Steve Hayes wrote: > Can anyone recommend a web site that gives a good beginner's guide to > Python? > > One that tells one, especially -- > > -- what kind of projects Python is good for > -- what kind of projects it is not good for > -- a simple explanation of how it works > -- a kind of beginner's tutotial and guide to its syntax > > I've read about Python, and installed it on my computer when I found it on > a > DVD that came with a magazine, but I haven't got a clue about how to use > it. > > So any advice on the best web sites for absolute novices would be welcome. > > > -- > Steve Hayes from Tshwane, South Africa > Blog: http://khanya.wordpress.com > E-mail - see web page, or parse: shayes at dunelm full stop org full stop > uk > -- > https://mail.python.org/mailman/listinfo/python-list > -- *****HAVE A NICE DAY ***** Prashanth -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed Sep 4 03:10:06 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Sep 2013 17:10:06 +1000 Subject: Beginner's guide to Python In-Reply-To: References: Message-ID: On Wed, Sep 4, 2013 at 3:26 PM, Steve Hayes wrote: > Can anyone recommend a web site that gives a good beginner's guide to Python? > > One that tells one, especially -- > > -- what kind of projects Python is good for > -- what kind of projects it is not good for > -- a simple explanation of how it works > -- a kind of beginner's tutotial and guide to its syntax > > I've read about Python, and installed it on my computer when I found it on a > DVD that came with a magazine, but I haven't got a clue about how to use it. > > So any advice on the best web sites for absolute novices would be welcome. I'd start with the standard docs tutorial: http://docs.python.org/3/tutorial/ Which version of Python have you installed? You may want to consider, if the DVD has an old version, getting the latest one off the web site. ChrisA From invalid at invalid.invalid Wed Sep 4 10:03:09 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 4 Sep 2013 14:03:09 +0000 (UTC) Subject: Beginner's guide to Python References: Message-ID: On 2013-09-04, Steve Hayes wrote: > Can anyone recommend a web site that gives a good beginner's guide to Python? http://www.greenteapress.com/thinkpython/ > -- what kind of projects Python is good for Text processing Scientific data analysis and visualization Database stuff CRM Web sites Data communications Games System administration tools > -- what kind of projects it is not good for OS kernels and device drivers > -- a simple explanation of how it works That depends on what "it" is. > -- a kind of beginner's tutotial and guide to its syntax Google "python tutorial" -- Grant Edwards grant.b.edwards Yow! It's a lot of fun at being alive ... I wonder if gmail.com my bed is made?!? From hayesstw at telkomsa.net Wed Sep 4 12:09:59 2013 From: hayesstw at telkomsa.net (Steve Hayes) Date: Wed, 04 Sep 2013 18:09:59 +0200 Subject: Beginner's guide to Python References: Message-ID: <4pme29dkaedt1desg8fu0s68ltp9vk339g@4ax.com> On Wed, 4 Sep 2013 14:03:09 +0000 (UTC), Grant Edwards wrote: >On 2013-09-04, Steve Hayes wrote: > >> Can anyone recommend a web site that gives a good beginner's guide to Python? > >http://www.greenteapress.com/thinkpython/ > >> -- what kind of projects Python is good for > >Text processing >Scientific data analysis and visualization >Database stuff >CRM >Web sites >Data communications >Games >System administration tools > >> -- what kind of projects it is not good for > >OS kernels and device drivers Thanks very much for this, and to others who also replied. -- Steve Hayes from Tshwane, South Africa Blog: http://khanya.wordpress.com E-mail - see web page, or parse: shayes at dunelm full stop org full stop uk From robotsondrugs at gmail.com Thu Sep 5 00:03:17 2013 From: robotsondrugs at gmail.com (Andrew Berg) Date: Wed, 04 Sep 2013 23:03:17 -0500 Subject: Beginner's guide to Python In-Reply-To: References: Message-ID: <52280285.4040902@gmail.com> On 2013.09.04 22:39, Dennis Lee Bieber wrote: > On Wed, 04 Sep 2013 07:26:47 +0200, Steve Hayes > declaimed the following: > >>Can anyone recommend a web site that gives a good beginner's guide to Python? >> >>One that tells one, especially -- >> >>-- what kind of projects Python is good for > > So far as I know, Python is "Turing-complete" -- it can be used for > anything... So is Brainfuck, but I wouldn't say it's good for *any* project... -- CPython 3.3.2 | Windows NT 6.2.9200 / FreeBSD 9.2 From rosuav at gmail.com Thu Sep 5 00:14:34 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 Sep 2013 14:14:34 +1000 Subject: Beginner's guide to Python In-Reply-To: <52280285.4040902@gmail.com> References: <52280285.4040902@gmail.com> Message-ID: On Thu, Sep 5, 2013 at 2:03 PM, Andrew Berg wrote: > On 2013.09.04 22:39, Dennis Lee Bieber wrote: >> On Wed, 04 Sep 2013 07:26:47 +0200, Steve Hayes >> declaimed the following: >> >>>Can anyone recommend a web site that gives a good beginner's guide to Python? >>> >>>One that tells one, especially -- >>> >>>-- what kind of projects Python is good for >> >> So far as I know, Python is "Turing-complete" -- it can be used for >> anything... > So is Brainfuck, but I wouldn't say it's good for *any* project... There are always surprises. A few years ago (okay, a good few now) I was gobsmacked to learn that JavaScript, which I'd always thought was for web browsers only, could be used for writing web *servers*. And the inverse is true, too - Pike, a language specifically designed for building servers (specifically MUDs - plain text), has bindings for GTK, so it can be used for writing graphical desktop applications. But there are definite goals and philosophies that affect whether a language is good for something or not. Python is extremely well suited to short scripts that do one tiny thing and immediately shut down, because it has an absolute minimum of boilerplate; other languages, where you have to wrap your code up in "int main() { ... }" are less suited to that. On the flip side, Python's object model tends to be less well suited to massive scaling; I don't know about PyPy and other Pythons, but certainly CPython isn't designed to run on arbitrary numbers of cores (once you go to multiprocessing, you then need to worry about IPC; if you work in a lower level language like C, you can use threads and directly access each other's memory). "Everything is permissible" - but not everything is constructive. [1] Sometimes you're fighting the language rather than working with it. ChrisA [1] Did you know that the Corinthian church needed advice on programming? First letter, tenth chapter, twenty-third verse. From steve at pearwood.info Thu Sep 5 03:27:58 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 05 Sep 2013 07:27:58 GMT Subject: Beginner's guide to Python References: <52280285.4040902@gmail.com> Message-ID: <5228327e$0$2743$c3e8da3$76491128@news.astraweb.com> On Thu, 05 Sep 2013 14:14:34 +1000, Chris Angelico wrote: > ...Python's object model tends to be less well suited to massive > scaling; That's probably true. > I don't know about PyPy and other Pythons, but certainly > CPython isn't designed to run on arbitrary numbers of cores (once you go > to multiprocessing, you then need to worry about IPC; if you work in a > lower level language like C, you can use threads and directly access > each other's memory). I think that's an exaggeration. CPython *is* designed to run on an arbitrary number of cores, but you need to approach it via techniques that you might not use in other languages. It would only be valid to say that "CPython is not designed to use multiple cores" if threads were the *only* valid way to use multiple cores. "Use multiprocessing" is just as much a valid way to use multiple cores as "use threads" might be in another language, and by some accounts, better than threads. Or you can use IronPython or Jython, neither of which have the GIL. Or use Stackless: http://entitycrisis.blogspot.com.au/2009/06/stackless-vs-gil-its-draw.html -- Steven From vnkumbhani at gmail.com Wed Sep 4 02:05:57 2013 From: vnkumbhani at gmail.com (vnkumbhani at gmail.com) Date: Tue, 3 Sep 2013 23:05:57 -0700 (PDT) Subject: how to detect comment in source code file ? Message-ID: <1fbab13d-bb98-465e-affe-f2fddeec8138@googlegroups.com> how works python interpreter for finding comment ? if possible find nested comment ? From ben+python at benfinney.id.au Wed Sep 4 03:02:42 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 04 Sep 2013 17:02:42 +1000 Subject: how to detect comment in source code file ? References: <1fbab13d-bb98-465e-affe-f2fddeec8138@googlegroups.com> Message-ID: <7w38plkr1p.fsf@benfinney.id.au> vnkumbhani at gmail.com writes: > how works python interpreter for finding comment ? It works as specified in the language reference. In particular, see . > if possible find nested comment ? Python's comments are line-end comments only. The syntax does not allow multi-line nor nested comments. -- \ ?If you go flying back through time and you see somebody else | `\ flying forward into the future, it's probably best to avoid eye | _o__) contact.? ?Jack Handey | Ben Finney From paul at rudin.co.uk Wed Sep 4 03:18:23 2013 From: paul at rudin.co.uk (Paul Rudin) Date: Wed, 04 Sep 2013 08:18:23 +0100 Subject: how to detect comment in source code file ? References: <1fbab13d-bb98-465e-affe-f2fddeec8138@googlegroups.com> Message-ID: <87a9jtoy0w.fsf@no-fixed-abode.cable.virginmedia.net> Ben Finney writes: > vnkumbhani at gmail.com writes: > >> how works python interpreter for finding comment ? > > It works as specified in the language reference. In particular, see > . > >> if possible find nested comment ? > > Python's comments are line-end comments only. The syntax does not allow > multi-line nor nested comments. Although you can use unbound multi-line strings as a kind of comment. But its often better to make the strings into doc strings proper. From steve at pearwood.info Wed Sep 4 21:56:49 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 05 Sep 2013 01:56:49 GMT Subject: how to detect comment in source code file ? References: <1fbab13d-bb98-465e-affe-f2fddeec8138@googlegroups.com> Message-ID: <5227e4e1$0$2743$c3e8da3$76491128@news.astraweb.com> On Wed, 04 Sep 2013 17:02:42 +1000, Ben Finney wrote: > vnkumbhani at gmail.com writes: > >> how works python interpreter for finding comment ? > > It works as specified in the language reference. In particular, see > . > >> if possible find nested comment ? > > Python's comments are line-end comments only. The syntax does not allow > multi-line nor nested comments. While that's technically true, you can use bare strings as de facto comments. The compiler drops any bare strings it sees, so one can nest pseudo-comments like this: do_this() """ do_that() do_something() # Make the widget work correctly. ''' for x in range(5): do_something_else() ''' do_something_different() """ In the above, everything except do_this() is commented out by being turned into a string. -- Steven From vincent.vandevyvre at swing.be Thu Sep 5 01:33:18 2013 From: vincent.vandevyvre at swing.be (Vincent Vande Vyvre) Date: Thu, 05 Sep 2013 07:33:18 +0200 Subject: how to detect comment in source code file ? In-Reply-To: <1fbab13d-bb98-465e-affe-f2fddeec8138@googlegroups.com> References: <1fbab13d-bb98-465e-affe-f2fddeec8138@googlegroups.com> Message-ID: <5228179E.7010500@swing.be> Le 04/09/2013 08:05, vnkumbhani at gmail.com a ?crit : > how works python interpreter for finding comment ? > if possible find nested comment ? If you need to find it yourself, you can use the module tokenize. ex.: --------------------------------------------------------------- import tokenize from StringIO import StringIO script = "# importing comment\nfrom foo import baz"\ "if baz.vers < 2:\n AUTO = False # Retrocompatibility" def find_comment(): print script cmt = tokenize.COMMENT tokens = tokenize.generate_tokens(StringIO(script).readline) for typ, _, begin, _, _ in tokens: if typ == cmt: print 'Find comment line %s at column %s' % begin find_comment() --------------------------------------------------------------- (for Python 3 import StringIO from io) -- Vincent V.V. Oqapy . Qarte . PaQager From piet at vanoostrum.org Thu Sep 5 08:11:51 2013 From: piet at vanoostrum.org (Piet van Oostrum) Date: Thu, 05 Sep 2013 08:11:51 -0400 Subject: how to detect comment in source code file ? References: <1fbab13d-bb98-465e-affe-f2fddeec8138@googlegroups.com> Message-ID: Dennis Lee Bieber writes: > On Tue, 3 Sep 2013 23:05:57 -0700 (PDT), vnkumbhani at gmail.com declaimed the > following: > >>how works python interpreter for finding comment ? >>if possible find nested comment ? > > Python does not have "nested comment". Comments begin at any # > character that is not inside a string (something inside ' or " pairs). You could consider this a kind of nested comment :) # if condition: # # calculate the amount # amount = sum(parts) -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From vnkumbhani at gmail.com Wed Sep 4 02:13:29 2013 From: vnkumbhani at gmail.com (vnkumbhani at gmail.com) Date: Tue, 3 Sep 2013 23:13:29 -0700 (PDT) Subject: how does not work nested comment in python? Message-ID: <551579b9-951e-4f46-bb10-488d39eac6a7@googlegroups.com> example: print "hello" # print comment +"world" => single line comment print "hello" '''print comment''' +"world" => multiple line comment From vlastimil.brom at gmail.com Wed Sep 4 03:55:19 2013 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Wed, 4 Sep 2013 09:55:19 +0200 Subject: how does not work nested comment in python? In-Reply-To: <551579b9-951e-4f46-bb10-488d39eac6a7@googlegroups.com> References: <551579b9-951e-4f46-bb10-488d39eac6a7@googlegroups.com> Message-ID: 2013/9/4 : > example: > > print "hello" # print comment +"world" => single line comment > print "hello" '''print comment''' +"world" => multiple line comment > -- > https://mail.python.org/mailman/listinfo/python-list Hi, python only has single line comments, which apply from a "#" to the end of the respective line. There are some possibilities/workarounds/hacks for "commenting out", i.e. (temporarily) disabling, parts of the code if False: Sometimes triple-quoted multiline strings are (mis)used this way """""" which actually converts the code to a not accessible multiline string. However, triple quoting is not an official means for multiline comments. What you are seeing in your second example is implicit string concatenation (which works regardless of the type of the quotes) - adjacent string literals in the code are joined automatically: >>> "abc" 'def' """ghi""" '''jkl''' 'abcdefghijkl' >>> hth, vbr From davea at davea.name Wed Sep 4 08:08:50 2013 From: davea at davea.name (Dave Angel) Date: Wed, 4 Sep 2013 12:08:50 +0000 (UTC) Subject: how does not work nested comment in python? References: <551579b9-951e-4f46-bb10-488d39eac6a7@googlegroups.com> Message-ID: On 4/9/2013 02:13, vnkumbhani at gmail.com wrote: > example: > > print "hello" # print comment +"world" => single line comment >>> print "hello" # print comment +"world" => single line comment hello > print "hello" '''print comment''' +"world" => multiple line comment >>> print "hello" '''print comment''' +"world" => multiple line comment File "", line 1 print "hello" '''print comment''' +"world" => multiple line comment ^ SyntaxError: invalid syntax >>> print "hello" '''print comment''' +"world" helloprint commentworld What is your question? The first line has a comment on it, the second one does not. -- DaveA From info at egenix.com Wed Sep 4 05:01:21 2013 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Wed, 04 Sep 2013 11:01:21 +0200 Subject: ANN: eGenix pyOpenSSL Distribution 0.13.2.1.0.1.5 Message-ID: <5226F6E1.8000100@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com pyOpenSSL Distribution Version 0.13.2.1.0.1.5 An easy-to-install and easy-to-use distribution of the pyOpenSSL Python interface for OpenSSL - available for Windows, Mac OS X and Unix platforms This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-pyOpenSSL-Distribution-0.13.2.1.0.1.5.html ________________________________________________________________________ INTRODUCTION The eGenix.com pyOpenSSL Distribution includes everything you need to get started with SSL in Python. It comes with an easy-to-use installer that includes the most recent OpenSSL library versions in pre-compiled form, making your application independent of OS provided OpenSSL libraries: http://www.egenix.com/products/python/pyOpenSSL/ pyOpenSSL is an open-source Python add-on that allows writing SSL/TLS- aware network applications as well as certificate management tools: https://launchpad.net/pyopenssl/ OpenSSL is an open-source implementation of the SSL/TLS protocol: http://www.openssl.org/ ________________________________________________________________________ NEWS This new release of the eGenix.com pyOpenSSL Distribution includes a set of updates related to security problems reported by Christian Heimes: New in the eGenix pyOpenSSL Distribution ---------------------------------------- * Added a patch by Christian Heimes to pyOpenSSL: This addresses the CVE-2013-4238 related problem with embedded NUL bytes in subjectAltNames and also fixes a memory leak in the X509 .get_extension() method. * Christian Heimes also pointed us to a problem with the included CA root bundle, which turns out to be rather wide-spread. Mozilla's certificate bundle includes more than just the trusted CA root certificates. It also includes several explicitly untrusted root certificates and even single untrusted server certificates. Our investigation showed that while OpenSSL does handle trust parameters in the certificates, it doesn't use this information during certificate verification, if the certificate is passed in together with other trusted certificates. Future OpenSSL versions may add this support, but at least versions up to and including 1.0.1e don't have it. To work around this problem, we have split the bundle file into separate bundles, each with different trust settings included. The explicitly untrusted certificates are no longer included in the lists to avoid potentially trusting these untrusted (root) certificates. Many thanks to Christian Heimes for these reports. * Added new TRUST_* constants to the OpenSSL.ca_bundle module and new purpose parameters to various bundle query functions. * Fixed a missing import in the https_client.py example. As always, we provide binaries that include both pyOpenSSL and the necessary OpenSSL libraries for all supported platforms: Windows x86 and x64, Linux x86 and x64, Mac OS X PPC, x86 and x64. We've also added egg-file distribution versions of our eGenix.com pyOpenSSL Distribution for Windows, Linux and Mac OS X to the available download options. These make setups using e.g. zc.buildout and other egg-file based installers a lot easier. ________________________________________________________________________ DOWNLOADS The download archives and instructions for installing the package can be found at: http://www.egenix.com/products/python/pyOpenSSL/ ________________________________________________________________________ UPGRADING Before installing this version of pyOpenSSL, please make sure that you uninstall any previously installed pyOpenSSL version. Otherwise, you could end up not using the included OpenSSL libs. _______________________________________________________________________ SUPPORT Commercial support for these packages is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. ________________________________________________________________________ MORE INFORMATION For more information about the eGenix pyOpenSSL Distribution, licensing and download instructions, please visit our web-site or write to sales at egenix.com. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Sep 04 2013) >>> Python Projects, Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope/Plone.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::::: Try our mxODBC.Connect Python Database Interface for free ! :::::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From mukeshtiwari.iiitm at gmail.com Wed Sep 4 07:12:09 2013 From: mukeshtiwari.iiitm at gmail.com (mukesh tiwari) Date: Wed, 4 Sep 2013 04:12:09 -0700 (PDT) Subject: Downloading the feed using feedparser Message-ID: <09b4225c-47f7-46ee-bb67-9a59a0a21bbc@googlegroups.com> Hello all, I am trying to download the feed of http://blogs.forrester.com/feed but I am stuck with a problem. >>> import feedparser >>> d = feedparser.parse('http://blogs.forrester.com/feed') >>> d.etag u'"1378291653-1"' >>> d.modified 'Wed, 04 Sep 2013 10:47:33 +0000' >>> feedparser.parse('http://blogs.forrester.com/feed', etag=d.etag, modified=d.modified).status 200 When I am running this, should not this be 304 ( The content can't be change so fast in a moment or this server is not configured properly ). If I rely on this then whenever I run the code, I will download the content irrespective of content changed or not. Could some one please suggest me how to avoid the duplicate download ? The below one is working fine so if I try to download again then I will get 304 response since no data is changed on server. >>> d = feedparser.parse("feed://feeds.huffingtonpost.com/HP/MostPopular") >>> d.etag u'Vx5oxwMUzEFvFpd6BNR23912Zk4' >>> d.modified 'Wed, 04 Sep 2013 10:32:06 GMT' >>> feedparser.parse("feed://feeds.huffingtonpost.com/HP/MostPopular", etag= d.etag, modified=d.modified).status 304 Thank you Mukesh Tiwari From irmen.NOSPAM at xs4all.nl Wed Sep 4 14:26:17 2013 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Wed, 04 Sep 2013 20:26:17 +0200 Subject: Downloading the feed using feedparser In-Reply-To: <09b4225c-47f7-46ee-bb67-9a59a0a21bbc@googlegroups.com> References: <09b4225c-47f7-46ee-bb67-9a59a0a21bbc@googlegroups.com> Message-ID: <52277b4a$0$15902$e4fe514c@news.xs4all.nl> On 4-9-2013 13:12, mukesh tiwari wrote: > Hello all, I am trying to download the feed of http://blogs.forrester.com/feed but I > am stuck with a problem. > >>>> import feedparser d = feedparser.parse('http://blogs.forrester.com/feed') >>>> d.etag > u'"1378291653-1"' >>>> d.modified > 'Wed, 04 Sep 2013 10:47:33 +0000' > >>>> feedparser.parse('http://blogs.forrester.com/feed', etag=d.etag, >>>> modified=d.modified).status > 200 > > When I am running this, should not this be 304 ( The content can't be change so fast > in a moment or this server is not configured properly ). If I rely on this then > whenever I run the code, I will download the content irrespective of content changed > or not. Could some one please suggest me how to avoid the duplicate download ? No it's correct because repeatedly downloading that URL gives me a different etag and last-modified header in the server's response. Their server is very likely to be generating the data on the fly every time you retrieve that location. Why do you assume this can't change so fast? It is very likely not a static file that is being retrieved, but rather a piece of content that is generated for every request, by their server application. > > The below one is working fine so if I try to download again then I will get 304 > response since no data is changed on server. > >>>> d = feedparser.parse("feed://feeds.huffingtonpost.com/HP/MostPopular") d.etag http, I pressume...........^^^^ But yeah, that url gives the same etag and last-modified header in the response, when repeatedly downloading it. This is probably a static file that is being updated once in a while. Irmen From python.list at tim.thechases.com Wed Sep 4 11:04:03 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 4 Sep 2013 10:04:03 -0500 Subject: Dealing with \r in CSV fields in Python2.4 Message-ID: <20130904100403.163b42bd@bigbox.christie.dr> I've got some old 2.4 code (requires an external lib that hasn't been upgraded) that needs to process a CSV file where some of the values contain \r characters. It appears that in more recent versions (just tested in 2.7; docs suggest this was changed in 2.5), Python does the Right Thing? and just creates values in the row containing that \r. However, in 2.4, the csv module chokes on it with _csv.Error: newline inside string as demoed by the example code at the bottom of this email. What's the best way to deal with this? At the moment, I'm just using something like def unCR(f): for line in f: yield line.replace('\r', '') f = file('input.csv', 'rb') for row in csv.reader(unCR(f)): code_to_process(row) but this throws away data that I'd really prefer to keep if possible. I know 2.4 isn't exactly popular, and in an ideal world, I'd just upgrade to a later 2.x version that does what I need. Any old-time 2.4 pythonistas have sage advice for me? -tkc from cStringIO import StringIO import csv f = file('out.txt', 'wb') w = csv.writer(f) w.writerow(["One", "Two"]) w.writerow(["First\rSecond", "Third"]) f.close() f = file('out.txt', 'rb') r = csv.reader(f) for i, row in enumerate(r): # works in 2.7, fails in 2.4 print repr(row) f.close() From skip at pobox.com Wed Sep 4 11:20:36 2013 From: skip at pobox.com (Skip Montanaro) Date: Wed, 4 Sep 2013 10:20:36 -0500 Subject: Dealing with \r in CSV fields in Python2.4 In-Reply-To: <20130904100403.163b42bd@bigbox.christie.dr> References: <20130904100403.163b42bd@bigbox.christie.dr> Message-ID: > _csv.Error: newline inside string How are the lines actually terminated, with \r\n or with just \n? If it's just \n, what happens if you specify \n as the line terminator? Skip From python.list at tim.thechases.com Wed Sep 4 11:32:48 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 4 Sep 2013 10:32:48 -0500 Subject: Dealing with \r in CSV fields in Python2.4 In-Reply-To: References: <20130904100403.163b42bd@bigbox.christie.dr> Message-ID: <20130904103248.79fc54c7@bigbox.christie.dr> On 2013-09-04 10:20, Skip Montanaro wrote: > > _csv.Error: newline inside string > > How are the lines actually terminated, with \r\n or with just \n? If > it's just \n, what happens if you specify \n as the line terminator? Unfortunately, the customer feed contains DOS newlines ("\r\n"). I'm not quite sure what """ Note The reader is hard-coded to recognize either '\r' or '\n' as end-of-line, and ignores lineterminator. This behavior may change in the future. """ means at [1]. Does that mean that efforts to change the lineterminator don't have any effect? Or that you can't (currently) specify anything other than "\r" or "\n"? Though that is a bit tangent to the actual issue. -tkc [1] http://docs.python.org/2/library/csv.html From python at mrabarnett.plus.com Wed Sep 4 11:31:06 2013 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 04 Sep 2013 16:31:06 +0100 Subject: Dealing with \r in CSV fields in Python2.4 In-Reply-To: <20130904100403.163b42bd@bigbox.christie.dr> References: <20130904100403.163b42bd@bigbox.christie.dr> Message-ID: <5227523A.7040900@mrabarnett.plus.com> On 04/09/2013 16:04, Tim Chase wrote: > I've got some old 2.4 code (requires an external lib that hasn't been > upgraded) that needs to process a CSV file where some of the values > contain \r characters. It appears that in more recent versions (just > tested in 2.7; docs suggest this was changed in 2.5), Python does the > Right Thing? and just creates values in the row containing that \r. > However, in 2.4, the csv module chokes on it with > > _csv.Error: newline inside string > > as demoed by the example code at the bottom of this email. What's the > best way to deal with this? At the moment, I'm just using something > like > > def unCR(f): > for line in f: > yield line.replace('\r', '') > > f = file('input.csv', 'rb') > for row in csv.reader(unCR(f)): > code_to_process(row) > > but this throws away data that I'd really prefer to keep if possible. > > I know 2.4 isn't exactly popular, and in an ideal world, I'd just > upgrade to a later 2.x version that does what I need. Any old-time > 2.4 pythonistas have sage advice for me? > [snip] You could try replacing the '\r' with another character that doesn't appear elsewhere and then change it back afterwards. MARKER = '\x01' def cr_to_marker(f): for line in f: yield line.replace('\r', MARKER) def marker_to_cr(item): return item.replace(MARKER, '\r') f = file('out.txt', 'rb') r = csv.reader(cr_to_marker(f)) for i, row in enumerate(r): # works in 2.7, fails in 2.4 row = [marker_to_cr(item) for item in row] print repr(row) f.close() Which OS are you using? On Windows the lines (rows) end with '\r\n', so the last item of each row will end with '\r', which you'll need to strip off. (That would be a problem only if the last item of a row could end with '\r'.) From python.list at tim.thechases.com Wed Sep 4 11:41:17 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 4 Sep 2013 10:41:17 -0500 Subject: Dealing with \r in CSV fields in Python2.4 In-Reply-To: <5227523A.7040900@mrabarnett.plus.com> References: <20130904100403.163b42bd@bigbox.christie.dr> <5227523A.7040900@mrabarnett.plus.com> Message-ID: <20130904104117.0320dd8f@bigbox.christie.dr> On 2013-09-04 16:31, MRAB wrote: > You could try replacing the '\r' with another character that doesn't > appear elsewhere and then change it back afterwards. > > MARKER = '\x01' > > def cr_to_marker(f): > for line in f: > yield line.replace('\r', MARKER) > > def marker_to_cr(item): > return item.replace(MARKER, '\r') > > f = file('out.txt', 'rb') > r = csv.reader(cr_to_marker(f)) > for i, row in enumerate(r): # works in 2.7, fails in 2.4 > row = [marker_to_cr(item) for item in row] > print repr(row) > f.close() This works pretty well. I'm not sure if there's a grave performance penalty for mucking with strings so much, but at this point my Care-o-Meter is barely registering, as long as it works. > Which OS are you using? On Windows the lines (rows) end with > '\r\n', so the last item of each row will end with '\r', which > you'll need to strip off. (That would be a problem only if the last > item of a row could end with '\r'.) It's on Win32. -tkc From tjreedy at udel.edu Wed Sep 4 17:15:10 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 04 Sep 2013 17:15:10 -0400 Subject: Dealing with \r in CSV fields in Python2.4 In-Reply-To: <20130904100403.163b42bd@bigbox.christie.dr> References: <20130904100403.163b42bd@bigbox.christie.dr> Message-ID: On 9/4/2013 11:04 AM, Tim Chase wrote: > I've got some old 2.4 code (requires an external lib that hasn't been > upgraded) that needs to process a CSV file where some of the values > contain \r characters. It appears that in more recent versions (just > tested in 2.7; docs suggest this was changed in 2.5), Python does the > Right Thing? and just creates values in the row containing that \r. > However, in 2.4, the csv module chokes on it with > > _csv.Error: newline inside string > > as demoed by the example code at the bottom of this email. While probably not necessary for this problem, one can use more that one Python version to solve a problem. For instance, You could use a current version to read the data and transform it so that it can be piped to 2.4 code running in a subprocess. > What's the > best way to deal with this? At the moment, I'm just using something > like > > def unCR(f): > for line in f: > yield line.replace('\r', '') > > f = file('input.csv', 'rb') > for row in csv.reader(unCR(f)): > code_to_process(row) > > but this throws away data that I'd really prefer to keep if possible. > > I know 2.4 isn't exactly popular, and in an ideal world, I'd just > upgrade to a later 2.x version that does what I need. Any old-time > 2.4 pythonistas have sage advice for me? > > -tkc > > > from cStringIO import StringIO > import csv > f = file('out.txt', 'wb') > w = csv.writer(f) > w.writerow(["One", "Two"]) > w.writerow(["First\rSecond", "Third"]) > f.close() > > f = file('out.txt', 'rb') > r = csv.reader(f) > for i, row in enumerate(r): # works in 2.7, fails in 2.4 > print repr(row) > f.close() > > -- Terry Jan Reedy From lo0446 at my.bristol.ac.uk Wed Sep 4 12:32:28 2013 From: lo0446 at my.bristol.ac.uk (Azureaus) Date: Wed, 4 Sep 2013 09:32:28 -0700 (PDT) Subject: Find out where a class is used throughout a program. Message-ID: <9d290db6-b9cb-41af-8107-e7f27d2da6d0@googlegroups.com> Hi All, I'm fairly new to Python so please forgive me If I sound confused or include anything a bit irrelevant. I've had some great responses from this group already though so thanks. I have a source file that is laid out roughly like class: class methods methods init statement class: method It doesn't seem to have a run method unlike other similar source files I have so it seems to be that this is being referenced from other files and is almost a 'utility file'. To try and make this question as general as possible - is there a way of finding out / visualising where a particular class is called/used throughout a program? I need to find out the way in which these classes are being used and their typical input (and where the output from these are going) so I can have a play around and really figure out how it works. Without a run method to call, or an idea of expected input/output it's difficult. Also without some sort of trace it's difficult. I spoke to colleague and was told to look into dir() method in a Python shell which I will do this evening but if anyone has any suggestions that would be great. Even better if you think this is what I'm after a quick example/use case would be even better. Or maybe I'm looking at this the wrong way and you can point me towards some docs? Thanks for your help. From dieter at handshake.de Wed Sep 4 16:08:10 2013 From: dieter at handshake.de (dieter) Date: Wed, 04 Sep 2013 22:08:10 +0200 Subject: Find out where a class is used throughout a program. References: <9d290db6-b9cb-41af-8107-e7f27d2da6d0@googlegroups.com> Message-ID: <8761ugl591.fsf@handshake.de> Azureaus writes: > ... > is there a way of finding out / visualising where a particular class is called/used throughout a program? I do not know a simple and reliable way. When I face such a situation, I use standard operating system utilities (e.g. "grep -r" under *nix) to search for occurrences of the class name in the source tree. This often gives good results when the class name has been well chosen. Recently (within the last 2 months), I have seen the announcement (on "...python.announce") of a tracing tool (I forgot the package's name; maybe, it has been "CodeInspector"). When I have understood the announcement correctly, then it traces concrete runs and allows you to explore where objects (e.g. classes) have been used *in these runs*. From tjreedy at udel.edu Wed Sep 4 17:36:47 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 04 Sep 2013 17:36:47 -0400 Subject: Find out where a class is used throughout a program. In-Reply-To: <8761ugl591.fsf@handshake.de> References: <9d290db6-b9cb-41af-8107-e7f27d2da6d0@googlegroups.com> <8761ugl591.fsf@handshake.de> Message-ID: On 9/4/2013 4:08 PM, dieter wrote: > Azureaus writes: >> ... >> is there a way of finding out / visualising where a particular class is called/used throughout a program? > I do not know a simple and reliable way. > > When I face such a situation, I use standard operating system > utilities (e.g. "grep -r" under *nix) to search for occurrences of > the class name in the source tree. This often gives good > results when the class name has been well chosen. Idle has a built-in 'grep' called 'Find in Files' on the Edit menu. I use it routinely. By default, it searches for the current text selection, if there is one, in all files in the directory containing the current file (and subdirectories). Idle's grep uses Python's re module, so one does not have to learn another re dialect. So it works the same, with Unicode text, on all systems, including Windows, which does not come with grep. The (undocumented) limitation is that it searches each line separately, so it cannot search for multiline patterns. (I would not be surprised if grep does that same, as it also reports line numbers and multiple hits in a file.) > Recently (within the last 2 months), I have seen the announcement > (on "...python.announce") of a tracing tool (I forgot the package's > name; maybe, it has been "CodeInspector"). When I have understood > the announcement correctly, then it traces concrete runs > and allows you to explore where objects (e.g. classes) have > been used *in these runs*. -- Terry Jan Reedy From irmen.NOSPAM at xs4all.nl Wed Sep 4 16:40:46 2013 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Wed, 04 Sep 2013 22:40:46 +0200 Subject: Find out where a class is used throughout a program. In-Reply-To: References: <9d290db6-b9cb-41af-8107-e7f27d2da6d0@googlegroups.com> Message-ID: <52279acf$0$16007$e4fe514c@news.xs4all.nl> On 4-9-2013 22:08, dieter wrote: > Azureaus writes: >> ... >> is there a way of finding out / visualising where a particular class is called/used throughout a program? > > I do not know a simple and reliable way. Not 100% reliable, but arguably easier than reverting to simple text search tools, is using a Python IDE such as PyCharm. It does a remarkable job most of the time to show you the usages and dependencies of various items in your program. It does this by actually parsing the source and not simply performing a text based search. Irmen From wuwei23 at gmail.com Wed Sep 4 20:11:32 2013 From: wuwei23 at gmail.com (alex23) Date: Thu, 05 Sep 2013 10:11:32 +1000 Subject: Find out where a class is used throughout a program. In-Reply-To: <9d290db6-b9cb-41af-8107-e7f27d2da6d0@googlegroups.com> References: <9d290db6-b9cb-41af-8107-e7f27d2da6d0@googlegroups.com> Message-ID: On 5/09/2013 2:32 AM, Azureaus wrote: > To try and make this question as general as possible - is there a way of finding out / visualising where a particular class is called/used throughout a program? One option is to produce call graphs of the running code: http://pycallgraph.slowchop.com/ From roy at panix.com Wed Sep 4 21:48:00 2013 From: roy at panix.com (Roy Smith) Date: Wed, 04 Sep 2013 21:48:00 -0400 Subject: Find out where a class is used throughout a program. References: <9d290db6-b9cb-41af-8107-e7f27d2da6d0@googlegroups.com> Message-ID: In article <9d290db6-b9cb-41af-8107-e7f27d2da6d0 at googlegroups.com>, Azureaus wrote: > To try and make this question as general as possible - is there a way of > finding out / visualising where a particular class is called/used throughout > a program? Sure. $ cd $ find . -name "*.py" | xargs grep MyClassName. From steve at pearwood.info Wed Sep 4 22:16:07 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 05 Sep 2013 02:16:07 GMT Subject: Find out where a class is used throughout a program. References: <9d290db6-b9cb-41af-8107-e7f27d2da6d0@googlegroups.com> Message-ID: <5227e966$0$2743$c3e8da3$76491128@news.astraweb.com> On Wed, 04 Sep 2013 09:32:28 -0700, Azureaus wrote: > To try and make this question as general as possible - is there a way of > finding out / visualising where a particular class is called/used > throughout a program? I need to find out the way in which these classes > are being used and their typical input (and where the output from these > are going) so I can have a play around and really figure out how it > works. Without a run method to call, or an idea of expected input/output > it's difficult. Also without some sort of trace it's difficult. Does the class not come with any documentation? Start the Python interactive interpreter, and then enter these two lines: import name_of_module help(name_of_module.MyClassName) where, of course, you replace name_of_module with the actual name of the module, and MyClassName with the actual name of the class. If that doesn't solve your problem, you can use the searching tools of your choice to search for uses of the class. Open some source file in your editor and search for "MyClassName" and see what comes up. Repeat for any other source files you care about. On a Linux or Mac system, you can use external tools. At the shell (not the Python shell, the operating system's shell) enter: cd directory/where/my/source/code/lives grep *.py MyClassName or similar. Windows may have a similar tool, but I don't know what it is. -- Steven From davea at davea.name Thu Sep 5 05:08:23 2013 From: davea at davea.name (Dave Angel) Date: Thu, 5 Sep 2013 09:08:23 +0000 (UTC) Subject: Find out where a class is used throughout a program. References: <9d290db6-b9cb-41af-8107-e7f27d2da6d0@googlegroups.com> Message-ID: On 4/9/2013 12:32, Azureaus wrote: > Hi All, > I'm fairly new to Python so please forgive me If I sound confused or include anything a bit irrelevant. I've had some great responses from this group already though so thanks. > > I have a source file that is laid out roughly like > > class: > class methods > methods > init statement Perhaps you mean the __init__() method ? This method is invoked when an object of this class is created, and generally has the job of initializing the instance data. There may also (or instead) be a __new__() method, which is the constructor. > class: > method > > It doesn't seem to have a run method unlike other similar source files I have so it seems to be that this is being referenced from other files and is almost a 'utility file'. A method is a function located inside a class. i think by "run method" you are referring to top-level code. That is code that is executed when the script/module is first loaded. You are right that if there is no top-level code, then the file must be intended as a module (or library, as it is sometimes called). However nearly every module will have some top-level code, even if it's only an import statement or a class instance assignment. > > To try and make this question as general as possible - is there a way of finding out / visualising where a particular class is called/used throughout a program? I need to find out the way in which these classes are being used and their typical input (and where the output from these are going) so I can have a play around and really figure out how it works. Without a run method to call, or an idea of expected input/output it's difficult. Also without some sort of trace it's difficult. As others have pointed out, an IDE can help greatly with this. But your first line of attack should be the documentation included with the file(s). If there's none, then perhaps it's throwaway code, and not worth worrying about. > > I spoke to colleague and was told to look into dir() method in a Python shell which I will do this evening but if anyone has any suggestions that would be great. Even better if you think this is what I'm after a quick example/use case would be even better. Or maybe I'm looking at this the wrong way and you can point me towards some docs? > Thanks for your help. -- DaveA From lo0446 at my.bristol.ac.uk Thu Sep 5 08:42:21 2013 From: lo0446 at my.bristol.ac.uk (Azureaus) Date: Thu, 5 Sep 2013 05:42:21 -0700 (PDT) Subject: Find out where a class is used throughout a program. In-Reply-To: <9d290db6-b9cb-41af-8107-e7f27d2da6d0@googlegroups.com> References: <9d290db6-b9cb-41af-8107-e7f27d2da6d0@googlegroups.com> Message-ID: <6974f400-49b0-4067-9bd3-03b642ab5a82@googlegroups.com> On Wednesday, 4 September 2013 17:32:28 UTC+1, Azureaus wrote: > Hi All, > > I'm fairly new to Python so please forgive me If I sound confused or include anything a bit irrelevant. I've had some great responses from this group already though so thanks. > > > > I have a source file that is laid out roughly like > > > > class: > > class methods > > methods > > init statement > > class: > > method > > > > It doesn't seem to have a run method unlike other similar source files I have so it seems to be that this is being referenced from other files and is almost a 'utility file'. > > > > To try and make this question as general as possible - is there a way of finding out / visualising where a particular class is called/used throughout a program? I need to find out the way in which these classes are being used and their typical input (and where the output from these are going) so I can have a play around and really figure out how it works. Without a run method to call, or an idea of expected input/output it's difficult. Also without some sort of trace it's difficult. > > > > I spoke to colleague and was told to look into dir() method in a Python shell which I will do this evening but if anyone has any suggestions that would be great. Even better if you think this is what I'm after a quick example/use case would be even better. Or maybe I'm looking at this the wrong way and you can point me towards some docs? > > Thanks for your help. Thanks you all for your time and responses they have been a great help. The practical examples were especially helpful. I'm going to go through the suggestions and try them out to find which one is most suited but overall I feel like my understanding/knowledge of Python has increased which is really the whole point. I think I'm going to be a regular here :) From rosuav at gmail.com Thu Sep 5 08:53:55 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 Sep 2013 22:53:55 +1000 Subject: Find out where a class is used throughout a program. In-Reply-To: <6974f400-49b0-4067-9bd3-03b642ab5a82@googlegroups.com> References: <9d290db6-b9cb-41af-8107-e7f27d2da6d0@googlegroups.com> <6974f400-49b0-4067-9bd3-03b642ab5a82@googlegroups.com> Message-ID: On Thu, Sep 5, 2013 at 10:42 PM, Azureaus wrote: > I think I'm going to be a regular here :) Glad to have you around! Interesting and thoughtful questions, as much as informative answers, are what make this list/group worth being in. I originally came to ask a question, hung around to answer a few, and stuck here because there's so much awesome and crazy wit... ChrisA From tavares at fe.up.pt Wed Sep 4 13:00:16 2013 From: tavares at fe.up.pt (tavares at fe.up.pt) Date: Wed, 4 Sep 2013 10:00:16 -0700 (PDT) Subject: =?windows-1252?Q?ICCEBS_2013_=96_Announce_=26_Invitation?= Message-ID: <0596a582-3fb6-4c5e-81e1-d0515bebd54a@googlegroups.com> Dear Colleague, We are pleased to announce the International Conference on Computational and Experimental Biomedical Sciences (ICCEBS2013 - www.fe.up.pt/~iccebs) in Ponta Delgada, S Miguel Island, Azores, October 20-22, 2013. The use of more robust, affordable and efficient techniques and technologies with application in Biomedical Sciences is presently a subject of huge interest and demand, and ICCEBS is intended to be a privileged discussion forum to define their key stakeholders. ICCEBS will bring together researchers from around the world representing several scientific fields related to Biomedical Sciences, including Engineering, Medicine, Biomechanics, Bioengineering, Biomaterials, Experimental Mechanics, Computer Sciences, Computational Mathematics, Hardware Developers and Manufactures, Electronic and Instrumentation and Materials Science. TOPICS In ICCEBS2013 will be considered topics of (not limited to): - Analysis and diagnosis; - Applications in medicine; - Applications in veterinary; - Artificial organs; - Bioengineering; - Biofluid; - Biological microelectromechanical systems, Labs-on-chips and Life-chips; - Biomaterials; - Biomedical devices; - Computational bio- imaging and visualization; - Computational methods; - Computer aided diagnosis; - Computer assisted surgery; - Experimental mechanics; - Implantology; - Medical robotics; - Minimally invasive devices and techniques; - Molecular and Cellular Biomechanics; - Numeral methods; - Prosthesis and orthosis; - Rehabilitation; - ImagingSignal processing and analysis; - Simulation; - Software development; - Sustainability; - Technical aids; - Telemedicine; - Tissue engineering; - Virtual reality. Due to your very interesting and key research activities, we would like to invite you to participate in ICCEBS2013 and share your expertize. Your contribution is welcomed, and we would be honored if you could accept this invitation. INVITED KEYNOTES ?The Biomechanics Detective & Clues to Expensive Unintentional Injuries? James A. Ashton-Miller - University of Michigan, USA ?Experimental and numerical microstructural modelling of vascular tissues? Estefan?a Pe?a Baquedano - Universidad de Zaragoza, Spain ?Modelling flow induced ATP/ADP concentration transport in patient-specific arteries? Perumal Nithiarasu - Swansea University, UK DATES - Deadline for one page abstract submission: 30th September 2013; - Authors? notification: 5th October 2013; - Deadline for full papers (not mandatory): 15th January 2014. PUBLICATIONS - Abstracts: All accepted abstracts will be distributed in a USB pen. - Full Papers (not mandatory): The proceedings book of ICCEBS2013, with all full papers, will be published by Springer under the Book Series Lecture Notes in Computational Vision and Biomechanics (www.springer.com/series/8910). - The organizers will prepare the publishing of a book with 20 invited works from the most important ones presented in ICCEBS2013 (extended versions). The book will be published by Springer under the Book Series Lecture Notes in Computational Vision and Biomechanics (www.springer.com/series/8910). - Additionally, the organizers will encourage the submission of extended versions of the accepted works to related International Journals; particularly, for special journal issues dedicated to ICCEBS2013. Two already confirmed possibilities are: Computer Methods in Biomechanics and Biomedical Engineering: Imaging & Visualization (www.tandfonline.com/loi/tciv20) and International Journal for Computational Vision and Biomechanics (www.fe.up.pt/~ijcvb). AWARD A best work prize will be given by the conference organizers to the best work presented in ICCEBS2013. Best wishes, Jo?o Manuel R. S. Tavares, Universidade do Porto, Portugal (tavares at fe.up.pt) Renato Natal Jorge, Universidade do Porto, Portugal (rnatal at fe.up.pt) (ICCEBS co-chairs) PS. For more information, you are invited to visit the conference webpage at: www.fe.up.pt/~iccebs. From oisin.mulvihill at gmail.com Wed Sep 4 13:05:13 2013 From: oisin.mulvihill at gmail.com (Oisin Mulvihill) Date: Wed, 4 Sep 2013 18:05:13 +0100 Subject: nozama-cloudsearch-service a local Amazon CloudSearch instance. Message-ID: Hello, Have you ever wanted to test your app against a dev version of your production CloudSearch? Is management saying budget constraints won't allow this? Then Nozama CloudSearch is for you. It is a light weight implementation of Amazon's CloudSearch service you can run locally. Its has additional REST API features which allow inspection of data in a way not available via Amazon CloudSearch. It is BSD licensed and available now from pypi https://pypi.python.org/pypi/nozama-cloudsearch-service: easy_install nozama-cloudsearch-service Or from source code checkout from github here: * https://github.com/oisinmulvihill/nozama-cloudsearch It also has documentation which it self hosts or can be seen on readthedocs: * https://nozama-cloudsearch.readthedocs.org/en/latest/index.html I've implemented batch uploading and I'm working on search at present. I thought I'd get this out early in case others are hitting against this. I'd welcome contributions. I don't intend this to be a replacement for Amazon CloudSearch. Its a helper service I use it as part of a vagrant+puppet provisioned developer environment. This emulates our production environment locally. All the best, Oisin -------------- next part -------------- An HTML attachment was scrubbed... URL: From davide.dalmasso at gmail.com Wed Sep 4 16:06:53 2013 From: davide.dalmasso at gmail.com (Davide Dalmasso) Date: Wed, 4 Sep 2013 13:06:53 -0700 (PDT) Subject: Broadcasting TimeSeries Message-ID: <6b13a66f-ff9a-4f82-b2d1-2231b8f4e94e@googlegroups.com> Hello, I opened my Python Shell and I wrote the following: >>> import numpy as np >>> import pandas as pd then I made a function >>> def afunc(aframe): return aframe - aframe.mean(axis=1) and I defined a DataFrame with time as index >>> A = pd.DataFrame(np.random.randn(5,3),columns=['a','b','c'],index=pd.date_range(start='1984-12-20',periods=5)) >>> A a b c 1984-12-20 -0.257916 -0.137923 -0.669796 1984-12-21 -1.632874 -1.850365 1.571715 1984-12-22 1.185828 -0.149839 -1.565930 1984-12-23 -0.757311 0.034627 0.794608 1984-12-24 0.548785 -1.126786 -0.438457 now, if I call the function the following error is generated: >>> afunc(A) Traceback (most recent call last): File "", line 1, in afunc(A) File "", line 2, in afunc return aframe - aframe.mean(axis=1) File "C:\Python33\lib\site-packages\pandas\core\frame.py", line 217, in f return self._combine_series(other, na_op, fill_value, axis, level) File "C:\Python33\lib\site-packages\pandas\core\frame.py", line 3601, in _combine_series return self._combine_series_infer(other, func, fill_value) File "C:\Python33\lib\site-packages\pandas\core\frame.py", line 3619, in _combine_series_infer FutureWarning) File "C:\Python33\lib\idlelib\PyShell.py", line 60, in idle_showwarning file.write(warnings.formatwarning(message, category, filename, AttributeError: 'NoneType' object has no attribute 'write' then I recall the same function (without any change) and the function works! >>> afunc(A) a b c 1984-12-20 0.097295 0.217289 -0.314584 1984-12-21 -0.995699 -1.213190 2.208890 1984-12-22 1.362475 0.026808 -1.389283 1984-12-23 -0.781285 0.010652 0.770633 1984-12-24 0.887604 -0.787967 -0.099637 Why does this happen? Why I must call the function two times before it finally works? How can I overcome this problem? Many thanks in advance Davide From tjreedy at udel.edu Wed Sep 4 18:00:06 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 04 Sep 2013 18:00:06 -0400 Subject: Broadcasting TimeSeries In-Reply-To: <6b13a66f-ff9a-4f82-b2d1-2231b8f4e94e@googlegroups.com> References: <6b13a66f-ff9a-4f82-b2d1-2231b8f4e94e@googlegroups.com> Message-ID: On 9/4/2013 4:06 PM, Davide Dalmasso wrote: > I opened my Python Shell and I wrote the following: This is with Idle. I believe you are running on Windows. >>>> import numpy as np >>>> import pandas as pd > > then I made a function > >>>> def afunc(aframe): > return aframe - aframe.mean(axis=1) > > and I defined a DataFrame with time as index > >>>> A = pd.DataFrame(np.random.randn(5,3),columns=['a','b','c'],index=pd.date_range(start='1984-12-20',periods=5)) >>>> A > a b c > 1984-12-20 -0.257916 -0.137923 -0.669796 > 1984-12-21 -1.632874 -1.850365 1.571715 > 1984-12-22 1.185828 -0.149839 -1.565930 > 1984-12-23 -0.757311 0.034627 0.794608 > 1984-12-24 0.548785 -1.126786 -0.438457 > > now, if I call the function the following error is generated: > >>>> afunc(A) > Traceback (most recent call last): > File "", line 1, in > afunc(A) > File "", line 2, in afunc > return aframe - aframe.mean(axis=1) > File "C:\Python33\lib\site-packages\pandas\core\frame.py", line 217, in f > return self._combine_series(other, na_op, fill_value, axis, level) > File "C:\Python33\lib\site-packages\pandas\core\frame.py", line 3601, in _combine_series > return self._combine_series_infer(other, func, fill_value) > File "C:\Python33\lib\site-packages\pandas\core\frame.py", line 3619, in _combine_series_infer > FutureWarning) > File "C:\Python33\lib\idlelib\PyShell.py", line 60, in idle_showwarning > file.write(warnings.formatwarning(message, category, filename, > AttributeError: 'NoneType' object has no attribute 'write' This was a bug in Idle when run directly on Windows, from Start or an icon. In this circumstance, there is no stderr stream to write to. I fixed it last June by catching the AttributeError and ignoring the warning. The fix will be in the next 2.7 and 3.3 releases and is in the 3.4 releases (currently 0a1, soon 0a2). The problem (of no stderr) is avoided now, while still using Idle, by starting Idle from a Command Prompt window (Start/Accessories): python -m idlelib or by starting the standard interpreter (from Start or icon) and entering >>> import idlelib.idle > then I recall the same function (without any change) and the function works! pandas must have a mechanism to only issue the warning once. >>>> afunc(A) > a b c > 1984-12-20 0.097295 0.217289 -0.314584 > 1984-12-21 -0.995699 -1.213190 2.208890 > 1984-12-22 1.362475 0.026808 -1.389283 > 1984-12-23 -0.781285 0.010652 0.770633 > 1984-12-24 0.887604 -0.787967 -0.099637 > > Why does this happen? Why I must call the function two times before it finally works? > How can I overcome this problem? Answered, I believe. -- Terry Jan Reedy From mohsen at pahlevanzadeh.org Wed Sep 4 19:30:50 2013 From: mohsen at pahlevanzadeh.org (Mohsen Pahlevanzadeh) Date: Thu, 05 Sep 2013 04:00:50 +0430 Subject: a dialog for throublshooting instead of print command pyqt Message-ID: <1378337450.6921.43.camel@debian> Dear all, I need to a dialg such as aler in javascript in pyqt, my question is at: http://stackoverflow.com/questions/18625406/a-dialog-for-throublshooting-instead-of-print-command-pyqt Before answering, thank you... Yours, Mohsen From wolftracks at invalid.com Wed Sep 4 23:08:32 2013 From: wolftracks at invalid.com (W. eWatson) Date: Wed, 04 Sep 2013 20:08:32 -0700 Subject: Modest book on Python grahpics several years ago Message-ID: About 4-5 years ago, two authors (possibly one) wrote a book on Python for beginners. It was probably no more than 200 pages thick, and likely cost close to $25. Several years later they wrote another book on Python graphics. Does anyone recall the name of these books? I don't think it was published by a well known publisher. From Chandru_Rajendran at infosys.com Wed Sep 4 23:47:02 2013 From: Chandru_Rajendran at infosys.com (Chandru Rajendran) Date: Thu, 5 Sep 2013 03:47:02 +0000 Subject: Cross Platform Message-ID: Hi all, I have a doubt regarding the python cross platform. If we write Class in windows ,whether we can without any modifications in Linux, if so then how about the GUI programming and Libraries. Please provide needful information. Thanks, Chandru **************** CAUTION - Disclaimer ***************** This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely for the use of the addressee(s). If you are not the intended recipient, please notify the sender by e-mail and delete the original message. Further, you are not to copy, disclose, or distribute this e-mail or its contents to any other person and any such actions are unlawful. This e-mail may contain viruses. Infosys has taken every reasonable precaution to minimize this risk, but is not liable for any damage you may sustain as a result of any virus in this e-mail. You should carry out your own virus checks before opening the e-mail or attachment. Infosys reserves the right to monitor and review the content of all messages sent to or from this e-mail address. Messages sent to or from this e-mail address may be stored on the Infosys e-mail system. ***INFOSYS******** End of Disclaimer ********INFOSYS*** From wrw at mac.com Thu Sep 5 08:48:04 2013 From: wrw at mac.com (William Ray Wing) Date: Thu, 05 Sep 2013 08:48:04 -0400 Subject: Cross Platform In-Reply-To: References: Message-ID: <0D13A0D9-91A2-4E6F-B8BD-42BA8C41EEFA@mac.com> On Sep 4, 2013, at 11:47 PM, Chandru Rajendran wrote: > Hi all, > > I have a doubt regarding the python cross platform. I think you mean you have a question... > If we write Class in windows ,whether we can without any modifications in Linux, if so then how about the GUI programming and Libraries. > Please provide needful information. > > Thanks, > Chandru > If (and this is a big if), but if you restrict yourself to using libraries which are themselves cross platform (Google "Python standard library" without the quotes) and don't spawn sub-jobs that invoke os-specific operations, then yes - python can be completely and cleanly cross platform. With respect to GUI programming, that simply means using one of the cross-platform GUI libraries. In this context Tk and ttk (which are part of the standard library) have the advantage of being both cross platform AND offering native appearance on all platforms. -Bill From Chandru_Rajendran at infosys.com Thu Sep 5 08:50:47 2013 From: Chandru_Rajendran at infosys.com (Chandru Rajendran) Date: Thu, 5 Sep 2013 12:50:47 +0000 Subject: Cross Platform In-Reply-To: <0D13A0D9-91A2-4E6F-B8BD-42BA8C41EEFA@mac.com> References: <0D13A0D9-91A2-4E6F-B8BD-42BA8C41EEFA@mac.com> Message-ID: Thank you William. -----Original Message----- From: William Ray Wing [mailto:wrw at mac.com] Sent: Thursday, September 05, 2013 6:18 PM To: Chandru Rajendran Cc: William Ray Wing; python-list at python.org Subject: Re: Cross Platform On Sep 4, 2013, at 11:47 PM, Chandru Rajendran wrote: > Hi all, > > I have a doubt regarding the python cross platform. I think you mean you have a question... > If we write Class in windows ,whether we can without any modifications in Linux, if so then how about the GUI programming and Libraries. > Please provide needful information. > > Thanks, > Chandru > If (and this is a big if), but if you restrict yourself to using libraries which are themselves cross platform (Google "Python standard library" without the quotes) and don't spawn sub-jobs that invoke os-specific operations, then yes - python can be completely and cleanly cross platform. With respect to GUI programming, that simply means using one of the cross-platform GUI libraries. In this context Tk and ttk (which are part of the standard library) have the advantage of being both cross platform AND offering native appearance on all platforms. -Bill **************** CAUTION - Disclaimer ***************** This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely for the use of the addressee(s). If you are not the intended recipient, please notify the sender by e-mail and delete the original message. Further, you are not to copy, disclose, or distribute this e-mail or its contents to any other person and any such actions are unlawful. This e-mail may contain viruses. Infosys has taken every reasonable precaution to minimize this risk, but is not liable for any damage you may sustain as a result of any virus in this e-mail. You should carry out your own virus checks before opening the e-mail or attachment. Infosys reserves the right to monitor and review the content of all messages sent to or from this e-mail address. Messages sent to or from this e-mail address may be stored on the Infosys e-mail system. ***INFOSYS******** End of Disclaimer ********INFOSYS*** From mohsen at pahlevanzadeh.org Thu Sep 5 00:17:30 2013 From: mohsen at pahlevanzadeh.org (Mohsen Pahlevanzadeh) Date: Thu, 05 Sep 2013 08:47:30 +0430 Subject: NameError: global name '' is not defined , but a bit differences Message-ID: <1378354650.6005.4.camel@debian> Dear all , i get the error : NameError: global name 'ui' is not defined Complete question is at : http://stackoverflow.com/questions/18627608/nameerror-global-name-is-not-defined-but-differences Before answering, Thank you for your attention...! Yours, Mohsen From benjamin.kaplan at case.edu Thu Sep 5 01:38:40 2013 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 4 Sep 2013 22:38:40 -0700 Subject: NameError: global name '' is not defined , but a bit differences In-Reply-To: <1378354650.6005.4.camel@debian> References: <1378354650.6005.4.camel@debian> Message-ID: On Wed, Sep 4, 2013 at 9:17 PM, Mohsen Pahlevanzadeh wrote: > Dear all , > > i get the error : > > NameError: global name 'ui' is not defined > > Complete question is at : > http://stackoverflow.com/questions/18627608/nameerror-global-name-is-not-defined-but-differences > > Before answering, Thank you for your attention...! > > > Yours, > Mohsen > > Please don't just post a link to Stack Overflow for your questions. It means that if Stack Overflow ever shuts down, this question is useless to anyone else looking at this post and also adds an extra step to anyone on this list wanting to answer your question- we're helping you in our spare time because we want to help people with these things. Please don't make us do extra work to help you. Just a note- doing a "from module import *" is considered poor coding style because it makes it difficult to figure out where all the names are coming from, especially if you start doing multiple import *s in a single code file. Either explicitly import the names you need ("from ui.interface.interface import InterfaceCodes") or import the module without adding the names to the local namespace ("import ui.interface.interface") From tjreedy at udel.edu Thu Sep 5 03:47:22 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 05 Sep 2013 03:47:22 -0400 Subject: NameError: global name '' is not defined , but a bit differences In-Reply-To: References: <1378354650.6005.4.camel@debian> Message-ID: On 9/5/2013 1:38 AM, Benjamin Kaplan wrote: > On Wed, Sep 4, 2013 at 9:17 PM, Mohsen Pahlevanzadeh > wrote: >> i get the error : >> >> NameError: global name 'ui' is not defined >> >> Complete question is at : >> http://stackoverflow.com/questions/18627608/nameerror-global-name-is-not-defined-but-differences Mohsen, I consider this post to be close to spamming in that its purpose is to drive traffic to your post on SO. SO says you posted the question 3 hrs ago, while my mail agent says you posted the link two hours ago. Ask a question on one forum and stick with that for at least a few days. > Please don't just post a link to Stack Overflow for your questions. It > means that if Stack Overflow ever shuts down, this question is useless > to anyone else looking at this post and also adds an extra step to > anyone on this list wanting to answer your question- we're helping you > in our spare time because we want to help people with these things. > Please don't make us do extra work to help you. > > Just a note- doing a "from module import *" is considered poor coding > style because it makes it difficult to figure out where all the names > are coming from, especially if you start doing multiple import *s in a > single code file. Either explicitly import the names you need ("from > ui.interface.interface import InterfaceCodes") or import the module > without adding the names to the local namespace ("import > ui.interface.interface") -- Terry Jan Reedy From mohsen at pahlevanzadeh.org Thu Sep 5 21:51:09 2013 From: mohsen at pahlevanzadeh.org (Mohsen Pahlevanzadeh) Date: Fri, 06 Sep 2013 06:21:09 +0430 Subject: NameError: global name '' is not defined , but a bit differences In-Reply-To: References: <1378354650.6005.4.camel@debian> Message-ID: <1378432269.6005.14.camel@debian> On Wed, 2013-09-04 at 22:38 -0700, Benjamin Kaplan wrote: > On Wed, Sep 4, 2013 at 9:17 PM, Mohsen Pahlevanzadeh > wrote: > > Dear all , > > > > i get the error : > > > > NameError: global name 'ui' is not defined > > > > Complete question is at : > > http://stackoverflow.com/questions/18627608/nameerror-global-name-is-not-defined-but-differences > > > > Before answering, Thank you for your attention...! > > > > > > Yours, > > Mohsen > > > > > > Please don't just post a link to Stack Overflow for your questions. It > means that if Stack Overflow ever shuts down, this question is useless > to anyone else looking at this post and also adds an extra step to > anyone on this list wanting to answer your question- we're helping you > in our spare time because we want to help people with these things. > Please don't make us do extra work to help you. > > Just a note- doing a "from module import *" is considered poor coding > style because it makes it difficult to figure out where all the names > are coming from, especially if you start doing multiple import *s in a > single code file. Either explicitly import the names you need ("from > ui.interface.interface import InterfaceCodes") or import the module > without adding the names to the local namespace ("import > ui.interface.interface") Sorry for my behaviour.... But dear Benjamin, i want to start a disscussion about migrating to C++ to python , Specially in OOD/P , and i want to start at stackoverflow and let post to python ML about 1 mounth later. (NOT Question) --mohsen From robert.gliguroski at gmail.com Thu Sep 5 04:37:51 2013 From: robert.gliguroski at gmail.com (Robert Gliguroski) Date: Thu, 5 Sep 2013 01:37:51 -0700 (PDT) Subject: Python KeyError Message-ID: Dear Sirs, I would like to ask a question that may seem a little off-topic but since it is related to Python and I really cannot solve it - I thought to try to ask for some help here. I have installed OpenERP, an open source ERP software and then I installed an extension for connecting it to Magento. But when I configure it and try to connect them, I am getting and error that says: "File "/opt/openerp/v7/server/openerp/modules/registry.py", line 102, in __getitem__ return self.models[model_name] KeyError: u'magento.instance'" This is the function in the registry.py file: "def __getitem__(self, model_name): """ Return a model for a given name or raise KeyError if it doesn't exist.""" return self.models[model_name] " Any help is appreciated, thanks From ethan at stoneleaf.us Fri Sep 6 16:16:35 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 06 Sep 2013 13:16:35 -0700 Subject: Python KeyError In-Reply-To: References: Message-ID: <522A3823.2010402@stoneleaf.us> On 09/05/2013 01:37 AM, Robert Gliguroski wrote: > > I have installed OpenERP, an open source ERP software and then I installed an extension for connecting it to Magento. But when I configure it and try to connect them, I am getting and error that says: >[snip] You might try asking at either StackOverflow[0] or OpenERP's Q&A website[1]. [0] http://stackoverflow.com [1] http://help.openerp.com -- ~Ethan~ From buypharmacypill at gmail.com Thu Sep 5 06:00:13 2013 From: buypharmacypill at gmail.com (buypharmacypill at gmail.com) Date: Thu, 5 Sep 2013 03:00:13 -0700 (PDT) Subject: Buy carisoprodol online In-Reply-To: <5eb6a85c-ec3d-43d2-a430-e16bcf1a0c0d@r27g2000yqn.googlegroups.com> References: <5eb6a85c-ec3d-43d2-a430-e16bcf1a0c0d@r27g2000yqn.googlegroups.com> Message-ID: <9b107f07-ce27-4aee-9ab5-385ab3736903@googlegroups.com> Soma or Carisoprodol is basically a muscle relaxing medicine which is used in combination to cure muscle tightening and muscles pains after an injury or because of some other musculoskeletal condition. Soma or carisoprodol drugs have the composition called Carisoprodol which is used for treatment of relentless musculoskeletal disorders in the adults. Although having analgesic properties this drug is not recommended for treating other body aches and pains and should only be used as a drug for muscle relaxant. New York City Call Us on our TOLL FREE Customer Services Number. 1-855-251-3111 E - Mail - topdrugmart@ gmail.com Website ->: http://www.topdrugmart.com/muscle-relaxant/buy-soma-carisoprodol.html From jldunn2000 at gmail.com Thu Sep 5 08:09:20 2013 From: jldunn2000 at gmail.com (loial) Date: Thu, 5 Sep 2013 05:09:20 -0700 (PDT) Subject: Using netrc when user password is blank Message-ID: I am having issues using the netrc package for users where the password is blank. It works fine for users with password is not blank and is spacified in the .netrc I am not sure if this is an issue with the .netrc file or my use of the .netrc package. .netrc file looks like : machine myserver login john password Code is username, ignore, password = netrc.netrc().hosts[hostname] This fails saying the .netrc is malformed. How should I specify the line in the .netc when the password is blank? Or is it not possible From lo0446 at my.bristol.ac.uk Thu Sep 5 08:39:37 2013 From: lo0446 at my.bristol.ac.uk (Azureaus) Date: Thu, 5 Sep 2013 05:39:37 -0700 (PDT) Subject: Importing Definitions Message-ID: <28b859f6-f14b-49d2-9e14-5d3febd33441@googlegroups.com> Hi all, Thank you all for your help so far in the group. Lets say I have some definitions in a module1.py e.g. import sys A,B,C,D,E = range(5) def method1(): more code end Then a second module module2.py where I wish to use these definitions import module1.py print A This will throw an error saying "global name 'A' is not defined." Now I know if there was a method I wanted to reference I could do something like this in module2. from module1 import method1 which would mean from that point on I could just reference it as method1 rather than module1.method1, is there such a way I could do this with definitions?? Thanks! From rosuav at gmail.com Thu Sep 5 08:50:35 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 Sep 2013 22:50:35 +1000 Subject: Importing Definitions In-Reply-To: <28b859f6-f14b-49d2-9e14-5d3febd33441@googlegroups.com> References: <28b859f6-f14b-49d2-9e14-5d3febd33441@googlegroups.com> Message-ID: On Thu, Sep 5, 2013 at 10:39 PM, Azureaus wrote: > Lets say I have some definitions in a module1.py e.g. > > import sys > A,B,C,D,E = range(5) > def method1(): > more code > end > > Then a second module module2.py where I wish to use these definitions > import module1.py > print A > > This will throw an error saying "global name 'A' is not defined." > > Now I know if there was a method I wanted to reference I could do something like this in module2. > from module1 import method1 > > which would mean from that point on I could just reference it as method1 rather than module1.method1, is there such a way I could do this with definitions?? You can! Any name will work, functions aren't special. from module1 import method1, A, B, C, D, E If you want all of them at once, you may want: from module1 import * but this can make your code confusing. ChrisA From __peter__ at web.de Thu Sep 5 09:00:13 2013 From: __peter__ at web.de (Peter Otten) Date: Thu, 05 Sep 2013 15:00:13 +0200 Subject: Importing Definitions References: <28b859f6-f14b-49d2-9e14-5d3febd33441@googlegroups.com> Message-ID: Azureaus wrote: > This will throw an error saying "global name 'A' is not defined." > > Now I know if there was a method I wanted to reference I could do > something like this in module2. > from module1 import method1 What a crazy idea! How could anyone ever think of that! > which would mean from that point on I could just reference it as method1 > rather than module1.method1, is there such a way I could do this with > definitions?? Please read the tutorial, especially http://docs.python.org/2/tutorial/modules.html#more-on-modules before you come up with more crazy shit like this ;) From ethan at stoneleaf.us Thu Sep 5 08:56:41 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 05 Sep 2013 05:56:41 -0700 Subject: Importing Definitions In-Reply-To: <28b859f6-f14b-49d2-9e14-5d3febd33441@googlegroups.com> References: <28b859f6-f14b-49d2-9e14-5d3febd33441@googlegroups.com> Message-ID: <52287F89.5080703@stoneleaf.us> On 09/05/2013 05:39 AM, Azureaus wrote: > > This will throw an error saying "global name 'A' is not defined." In Python, "global" really means "module-level". > Now I know if there was a method I wanted to reference I could do something like this in module2. > from module1 import method1 > > which would mean from that point on I could just reference it as method1 rather than module1.method1, is there such a way I could do this with definitions?? from module1 import data1 -- ~Ethan~ From steve+comp.lang.python at pearwood.info Thu Sep 5 13:28:13 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Sep 2013 17:28:13 GMT Subject: Importing Definitions References: <28b859f6-f14b-49d2-9e14-5d3febd33441@googlegroups.com> Message-ID: <5228bf2d$0$29988$c3e8da3$5496439d@news.astraweb.com> On Thu, 05 Sep 2013 22:50:35 +1000, Chris Angelico wrote: > On Thu, Sep 5, 2013 at 10:39 PM, Azureaus > wrote: >> Now I know if there was a method I wanted to reference I could do >> something like this in module2. from module1 import method1 >> >> which would mean from that point on I could just reference it as >> method1 rather than module1.method1, is there such a way I could do >> this with definitions?? > > You can! Any name will work, functions aren't special. > > from module1 import method1, A, B, C, D, E Better practice is to use: import module1 print module1.A print module2.B and so forth since that makes it far more clear what you are doing and where they come from. But it's not compulsory. > If you want all of them at once, you may want: > > from module1 import * > > but this can make your code confusing. Shame on you Chris :-) Don't teach newbies to set their head on fire before teaching them where the fire extinguisher is. Azureaus, don't use the form "from module import *" unless you really need to, and as a beginner, you almost never really need to. (And as an expert, you will really need to even less!) -- Steven From skip at pobox.com Thu Sep 5 14:06:56 2013 From: skip at pobox.com (Skip Montanaro) Date: Thu, 5 Sep 2013 13:06:56 -0500 Subject: Importing Definitions In-Reply-To: <5228bf2d$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <28b859f6-f14b-49d2-9e14-5d3febd33441@googlegroups.com> <5228bf2d$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: >> You can! Any name will work, functions aren't special. >> >> from module1 import method1, A, B, C, D, E > > Better practice is to use: > > import module1 > print module1.A > print module2.B > > and so forth since that makes it far more clear what you are doing and > where they come from. But it's not compulsory. Maybe I'm imagining things, but I think it's pretty common to see some big-ass modules imported using "from module import *". While people may think that's expedient, I think it can often be the source of subtle bugs. Skip From oscar.j.benjamin at gmail.com Fri Sep 6 06:05:34 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Fri, 6 Sep 2013 11:05:34 +0100 Subject: Importing Definitions In-Reply-To: References: <28b859f6-f14b-49d2-9e14-5d3febd33441@googlegroups.com> <5228bf2d$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 5 September 2013 19:06, Skip Montanaro wrote: >>> You can! Any name will work, functions aren't special. >>> >>> from module1 import method1, A, B, C, D, E >> >> Better practice is to use: >> >> import module1 >> print module1.A >> print module2.B >> >> and so forth since that makes it far more clear what you are doing and >> where they come from. But it's not compulsory. > > Maybe I'm imagining things, but I think it's pretty common to see some > big-ass modules imported using "from module import *". While people > may think that's expedient, I think it can often be the source of > subtle bugs. It is common in scientific programming e.g. 'from numpy import *' and so on. And actually I think that it is a reasonable thing to do in cases where: 1) You're writing a single smallish module/script. 2) The imported module is well-known and anyone who doesn't know it won't understand your code anyway. 3) You're only doing one star-import. 4) You're using a lot of symbols from that import in lots of places in your code. Consider for example, this script: #!/usr/bin/env python import numpy import matplotlib.pyplot k = 1 f = 10 x = numpy.arange(0, 3, 0.01) y = numpy.exp(k * x) * numpy.sin(2 * numpy.pi * x) matplotlib.pyplot.plot(x, y) matplotlib.pyplot.show() I write a lot of scripts that look roughly like that except they're usually quite a bit bigger. Written as above, the word numpy would appear dozens of times in a single script. Because of this it's commonplace to abbreviate the module names on import e.g.: #!/usr/bin/env python import numpy as np import matplotlib.pyplot as plt k = 1 f = 10 x = np.arange(0, 3, 0.01) y = np.exp(k * x) * np.sin(2 * np.pi * x) plt.plot(x, y) plt.show() But still in situations where you have to write 'np.' 3 or more times on a line, it just becomes a distraction in your code. Of course you can just import the names you want e.g.: #!/usr/bin/env python from numpy import arange, exp, sin, pi from matplotlib.pyplot import plot, show k = 1 f = 10 x = arange(0, 3, 0.01) y = exp(k * x) * sin(2 * pi * x) plot(x, y) show() But this just gets annoying. In practice I'll probably end up importing 20 or so names. When writing a script like this I probably tweak and rerun it continuously and so when I decide that actually I meant cos not sin then I run it and get: $ ./tmp3.py Traceback (most recent call last): File "./tmp3.py", line 9, in y = exp(k * x) * cos(2 * pi * x) NameError: name 'cos' is not defined And then I have to go back and edit the import line. This kind of thing just wastes a bit of time while I'm working. So the matplotlib folks created a special module called "pylab" that brings together the symbols from numpy and matplotlib and is specifically designed so that you can star-import it when writing this kind of code interactively or in a script: #!/usr/bin/env python from pylab import * k = 1 f = 10 x = arange(0, 3, 0.01) y = exp(k * x) * sin(2 * pi * x) plot(x, y) show() The pylab star-import brings a *huge* number of symbols into the current namespace: $ python -c 'import pylab; print(len(pylab.__dict__))' 933 However, it's very common that this set of symbols comprises everything that a script needs. Personally I don't think there's anything wrong with using that in a script (with the caveats I mentioned above). A similar case is in a script that uses sympy (I wouldn't do it with pylab and sympy together though). In either case I would tend to think that I'm essentially using an augmentation of builtins. Just as you need to know roughly what's in builtins to understand ordinary Python code, you need to know what's in pylab or sympy to understand this script. Oscar From lo0446 at my.bristol.ac.uk Fri Sep 6 05:10:42 2013 From: lo0446 at my.bristol.ac.uk (Azureaus) Date: Fri, 6 Sep 2013 02:10:42 -0700 (PDT) Subject: Importing Definitions In-Reply-To: <28b859f6-f14b-49d2-9e14-5d3febd33441@googlegroups.com> References: <28b859f6-f14b-49d2-9e14-5d3febd33441@googlegroups.com> Message-ID: <4a58302f-8b6e-4ba3-92ec-9490b6c98470@googlegroups.com> Thanks for the advice, much appreciated - I didn't realise you could also import definitions. I do always read the documentation before posting but sometimes I don't know how it's necessarily applicable to my own case sometimes - hence the post. I'll avoid using '*' at all costs, I've had the pleasure of going through lots of Python code recently not written by myself and I can see how that would make it a total nightmare to figure out what was going on. I think Python is awesome and look forward to actually getting good with it. Cheers! On Thursday, 5 September 2013 13:39:37 UTC+1, Azureaus wrote: > Hi all, > > Thank you all for your help so far in the group. > > > > Lets say I have some definitions in a module1.py e.g. > > > > import sys > > A,B,C,D,E = range(5) > > def method1(): > > more code > > end > > > > Then a second module module2.py where I wish to use these definitions > > import module1.py > > print A > > > > This will throw an error saying "global name 'A' is not defined." > > > > Now I know if there was a method I wanted to reference I could do something like this in module2. > > from module1 import method1 > > > > which would mean from that point on I could just reference it as method1 rather than module1.method1, is there such a way I could do this with definitions?? > > > > Thanks! From fabiofz at gmail.com Thu Sep 5 08:42:03 2013 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Thu, 5 Sep 2013 09:42:03 -0300 Subject: PyDev 2.8.2 released Message-ID: Hi All, PyDev 2.8.2 has been released Details on PyDev: http://pydev.org Details on its development: http://pydev.blogspot.com Become a supporter and help to keep it going forward: https://sw-brainwy.rhcloud.com/ Release Highlights: ------------------------------- * The type inference engine now accepts comments in the format **#@type a: str** to get the type. * Interpreter configuration properly deals with characters with ampersand. * Interactive console can now work with PySide and wxPython to create widgets without blocking. * Debugger now working properly with Jython 2.1. * Markups in sphinx or epydoc format can now have a different color in docstrings. * Code-completion for the sphinx markup is provided in docstrings. * Fixed issue when resolving module names (which could make PyDev find modules as Lib.math instead of math if the interpreter folder was added to the PYTHONPATH and not only the Lib folder). * When configuring project source folders (PYTHONPATH), it's possible to make use of the PROJECT_DIR_NAME variable. * **Patches by Trey Greer**: * PyLint 1.0 is now properly supported. * **Patches by Jonah Graham:** * Fixed issue in interactive console interaction with XML-RPC. * Interactive console history is saved to persistent location. * It's possible to filter variables in the variables view menu (can be activated with Ctrl+F10 focusing the variables view > PyDev, select/deselect filters). * Eclipse variables are expanded in the initial interpreter commands for the interactive console. * An evaluate button (same as Ctrl+Alt+Enter) is now available in the toolbar. * **Patches by by Anselm Kruis:** * Fixed issues related to having the interpreter or workspace in locations with non-ascii characters. * **Patches by Jeremy Carroll:** * It's now possible to use PEP-8 style imports (default now, can be unconfigured at window > preferencs > pydev > editor > code style > imports). * It's possible to configure the organize imports to remove unused imports (must be enabled in window > preferencs > pydev > editor > code style > imports). * **Patches by Andrew Ferrazzutti:** * Better heuristics to discover file in workspace related to open files when debugging. * Improvements in the PyDev project configuration and wizard. * It's possible to mark/unmark folders as source folders with a right-click context menu. * Auto-Configuration of interpreter streamlined. * **Patches by Andre Berg:** * It's possible to have a change action which will keep a variable updated when file is changed (i.e.: __date__ = '2013-01-01' would be updated when file is saved to a new date). What is PyDev? --------------------------- PyDev is a plugin that enables users to use Eclipse for Python, Jython and IronPython development -- making Eclipse a first class Python IDE -- It comes with many goodies such as code completion, syntax highlighting, syntax analysis, refactor, debug and many others. Cheers, -- Fabio Zadrozny ------------------------------------------------------ Software Developer PyDev - Python Development Environment for Eclipse http://pydev.org http://pydev.blogspot.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From Chandru_Rajendran at infosys.com Thu Sep 5 09:03:59 2013 From: Chandru_Rajendran at infosys.com (Chandru Rajendran) Date: Thu, 5 Sep 2013 13:03:59 +0000 Subject: Plot in MatPlotLib Message-ID: Hi all, I have written the types to plot in Matplotlib. #Usage Type 1 plt.plot(t,s) plt.show() #Usage type 2 fig=plt.figure() ax=fig.add_subplot(111) ax.plot(t,s) plt.show() I want difference between these types and other ways in which we can use plot. Thanks & Regards, Chandru **************** CAUTION - Disclaimer ***************** This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely for the use of the addressee(s). If you are not the intended recipient, please notify the sender by e-mail and delete the original message. Further, you are not to copy, disclose, or distribute this e-mail or its contents to any other person and any such actions are unlawful. This e-mail may contain viruses. Infosys has taken every reasonable precaution to minimize this risk, but is not liable for any damage you may sustain as a result of any virus in this e-mail. You should carry out your own virus checks before opening the e-mail or attachment. Infosys reserves the right to monitor and review the content of all messages sent to or from this e-mail address. Messages sent to or from this e-mail address may be stored on the Infosys e-mail system. ***INFOSYS******** End of Disclaimer ********INFOSYS*** -------------- next part -------------- An HTML attachment was scrubbed... URL: From alexander.borghgraef at gmail.com Thu Sep 5 10:35:19 2013 From: alexander.borghgraef at gmail.com (hareksu) Date: Thu, 5 Sep 2013 07:35:19 -0700 (PDT) Subject: Pcap network buffer Message-ID: <672f9711-3d12-466e-acd1-5294f984697d@googlegroups.com> Hi all, I've been writing an application for capturing multiple HD network video streams using a linux laptop with packet capture. For this I've used pcapy, which wraps parts of libpcap. The problem is that with the default network buffer size, I end up with corrupted video, so I changed the default buffer size and tried again, to no avail. I dug into the problem a bit, and noticed that both tcpdump and wireshark can set the buffer size, in which case I record without problem, and the libpcap C library has an fucntion pcap_set_buffer_size reflecting this, but neither pcapy or pylibpcap seem to include this functionality. So my question is this: is there a python way to set this buffer size, or do I need to write this in C? Thanks in advance. -- Me From jsrig88 at gmail.com Thu Sep 5 12:37:57 2013 From: jsrig88 at gmail.com (jsrig88 at gmail.com) Date: Thu, 5 Sep 2013 09:37:57 -0700 (PDT) Subject: Could someone please paraphrase this statement about variables and functions in Python? Message-ID: <867bb85f-853a-4cd5-a33b-63f9619dbe1e@googlegroups.com> I am going through the tutorials on docs.python.org, and I came across this excerpt from http://docs.python.org/3/tutorial/controlflow.html: "The execution of a function introduces a new symbol table used for the local variables of the function. More precisely, all variable assignments in a function store the value in the local symbol table; whereas variable references first look in the local symbol table, then in the local symbol tables of enclosing functions, then in the global symbol table, and finally in the table of built-in names. Thus, global variables cannot be directly assigned a value within a function (unless named in a global statement), although they may be referenced. "The actual parameters (arguments) to a function call are introduced in the local symbol table of the called function when it is called; thus, arguments are passed using call by value (where the value is always an object reference, not the value of the object). [1] When a function calls another function, a new local symbol table is created for that call." Even as a professional programmer, I'm not really able to follow this. It seems self-contradictory, amgiguous, and incomplete. The problem with looking for this information elsewhere is that it's not going to be all in one spot like this half the time, and it's not going to be readily searchable on Google without more knowledge of what it's referring to. However this looks like something that's too important to overlook. I can tell it's referring to things like scope, pass-by-value, references, probably the call stack, etc., but it is written extremely poorly. Translation please? Thanks! From davea at davea.name Thu Sep 5 13:11:34 2013 From: davea at davea.name (Dave Angel) Date: Thu, 5 Sep 2013 17:11:34 +0000 (UTC) Subject: Could someone please paraphrase this statement about variables and functions in Python? References: <867bb85f-853a-4cd5-a33b-63f9619dbe1e@googlegroups.com> Message-ID: On 5/9/2013 12:37, jsrig88 at gmail.com wrote: > I am going through the tutorials on docs.python.org, and I came across this excerpt from http://docs.python.org/3/tutorial/controlflow.html: > > "The execution of a function introduces a new symbol table used for the local variables of the function. More precisely, all variable assignments in a function store the value in the local symbol table; whereas variable references first look in the local symbol table, then in the local symbol tables of enclosing functions, then in the global symbol table, and finally in the table of built-in names. Thus, global variables cannot be directly assigned a value within a function (unless named in a global statement), although they may be referenced. That new symbol table is per call, thus it's equivalent to a stack frame. A new stack frame is created when the function is called. The names in that stack frame are the function parameter names, plus all the names that are assigned to within that function, minus any names that were declared as global or as nonlocal. The list of such names is determined at compile time,not during the run of the function. Any reference within that function to names NOT in that local symbol table will be resolved at run time in a particular order; first in any enclosing functions (nested function definitions, which is NOT the same as nested calls), then in the global namespace, then in builtins. If the name cannot be found in any of those places, you'll get a runtime exception, something like NameError: global name 'b' is not defined > > "The actual parameters (arguments) to a function call are introduced in the local > symbol table of the called function when it is called; thus, arguments are passed > using call by value (where the value is always an object reference, not the value > of the object). [1] When a function calls another function, a new local symbol > table is created for that call." > > Even as a professional programmer, I'm not really able to follow this. It seems self-contradictory, amgiguous, and incomplete. The problem with looking for this information elsewhere is that it's not going to be all in one spot like this half the time, and it's not going to be readily searchable on Google without more knowledge of what it's referring to. However this looks like something that's too important to overlook. > > I can tell it's referring to things like scope, pass-by-value, references, probably the call stack, etc., but it is written extremely poorly. Translation please? Thanks! Python doesn't do pass-by-value nor pass-by-reference. The expression in the calling argument is some object. During a call to a function, that object is bound to the parameter name, which is a local variable in the called function. The object is NOT copied, it is effectively shared. if the object is immutable, the distinction is unimportant, but if the object is changed, it's changed for all names that are bound to the same object. -- DaveA From neilc at norwich.edu Thu Sep 5 13:13:46 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 5 Sep 2013 17:13:46 GMT Subject: Could someone please paraphrase this statement about variables and functions in Python? References: <867bb85f-853a-4cd5-a33b-63f9619dbe1e@googlegroups.com> Message-ID: On 2013-09-05, jsrig88 at gmail.com wrote: > I am going through the tutorials on docs.python.org, and I came > across this excerpt from > http://docs.python.org/3/tutorial/controlflow.html: > > "The execution of a function introduces a new symbol table used > for the local variables of the function. More precisely, all > variable assignments in a function store the value in the local > symbol table; whereas variable references first look in the > local symbol table, then in the local symbol tables of > enclosing functions, then in the global symbol table, and > finally in the table of built-in names. Thus, global variables > cannot be directly assigned a value within a function (unless > named in a global statement), although they may be referenced. Every function has its own scope, which is a list of its local variables. When you assign to a local name in a function, you are assigning to the symbol table that stores those variables. Not spelled out exactly is that every unqualified name assigned to in a function is assumed to be a local variable. So this is an error: >>> x = 5 >>> def foo(): ... print(x) ... x = 7 ... >>> foo() Traceback (most recent call last): File "", line 1, in File "", line 2, in foo UnboundLocalError: local variable 'x' referenced before assignment If the assignement to x is removed, then you can refer to the global variable just fine. >>> x = 5 >>> def foo(): ... print(x) ... >>> foo() 5 In a function, you can allow assignment to global variables using the global statement. >>> x = 5 >>> def foo(): ... global x ... print(x) ... x = 7 ... >>> foo() 5 >>> x 7 > "The actual parameters (arguments) to a function call are > introduced in the local symbol table of the called function > when it is called; thus, arguments are passed using call by > value (where the value is always an object reference, not the > value of the object). [1] When a function calls another > function, a new local symbol table is created for that call." When you call a function, it is as if an assignment of the arguments to the function paramters takes place. def foo(x, y): print(x, y) When I call foo(1, 2), the effect is: 1. The local variable x is assigned to the object returned by the expression 1 2. The local y is assigned to the object returned by the expression 2 3. The body of function foo is run. Assignments in Python are name-binding. Objects are passed into functions by assignment. If you understand how assignment works in Python, that's a good explanation. Finally, every time you call a function a new symbol table is built. So I can do the following without names conflicting: def foo(x, y): if x == 0: return y y *= 2 return foo(x-1, y) > Even as a professional programmer, I'm not really able to > follow this. It seems self-contradictory, amgiguous, and > incomplete. The problem with looking for this information > elsewhere is that it's not going to be all in one spot like > this half the time, and it's not going to be readily searchable > on Google without more knowledge of what it's referring to. > However this looks like something that's too important to > overlook. It's not ambiguous, self-contradictory or incomplete. But it's very densely packed with information; perhaps it's too complete. > I can tell it's referring to things like scope, pass-by-value, > references, probably the call stack, etc., but it is written > extremely poorly. Translation please? Thanks! I don't think that's a fair criticism, but it might be too technical for a language tutorial. -- Neil Cerutti From tjreedy at udel.edu Thu Sep 5 13:24:50 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 05 Sep 2013 13:24:50 -0400 Subject: Could someone please paraphrase this statement about variables and functions in Python? In-Reply-To: <867bb85f-853a-4cd5-a33b-63f9619dbe1e@googlegroups.com> References: <867bb85f-853a-4cd5-a33b-63f9619dbe1e@googlegroups.com> Message-ID: On 9/5/2013 12:37 PM, jsrig88 at gmail.com wrote: > I am going through the tutorials on docs.python.org, and I came across this excerpt from http://docs.python.org/3/tutorial/controlflow.html: > > "The execution of a function introduces a new symbol table used for the local variables of the function. More precisely, all variable assignments in a function store the value in the local symbol table; whereas variable references first look in the local symbol table, then in the local symbol tables of enclosing functions, then in the global symbol table, and finally in the table of built-in names. Thus, global variables cannot be directly assigned a value within a function (unless named in a global statement), although they may be referenced. > > "The actual parameters (arguments) to a function call are introduced in the local > symbol table of the called function when it is called; thus, arguments are passed > using call by value (where the value is always an object reference, not the value > of the object). [1] When a function calls another function, a new local symbol > table is created for that call." > > Even as a professional programmer, I'm not really able to follow this. It seems self-contradictory, amgiguous, and incomplete. The problem with looking for this information elsewhere is that it's not going to be all in one spot like this half the time, and it's not going to be readily searchable on Google without more knowledge of what it's referring to. However this looks like something that's too important to overlook. The only incompleteness is that 'global statememt' should be 'global or nonlocal statement'. > I can tell it's referring to things like scope, pass-by-value, references, probably the call stack, etc., but it is written extremely poorly. Translation please? Thanks! Without knowing your personal language, translating into a language you would understand is an impossible task. I would replace 'variable' with 'name', 'symbol table' with 'nmespace', 'call by object reference value' with 'call by object', and 'global' with 'modular'. Maybe that helps you, maybe it confuses you more. The importance thing you must understand is that Python is an object-based language and that calling a function (like assignment statement in general) does not copy the argument objects. I suggest that you study the behavior of actual examples both in the tutorial and ones you make up. If you are actually baffled by some behavior, ask a spedific question. PS. Try not to double post. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Thu Sep 5 13:48:27 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Sep 2013 17:48:27 GMT Subject: Could someone please paraphrase this statement about variables and functions in Python? References: <867bb85f-853a-4cd5-a33b-63f9619dbe1e@googlegroups.com> Message-ID: <5228c3ea$0$29988$c3e8da3$5496439d@news.astraweb.com> On Thu, 05 Sep 2013 09:37:57 -0700, jsrig88 wrote: > I am going through the tutorials on docs.python.org, and I came across > this excerpt from http://docs.python.org/3/tutorial/controlflow.html: > > "The execution of a function introduces a new symbol table used for the > local variables of the function. More precisely, all variable > assignments in a function store the value in the local symbol table; > whereas variable references first look in the local symbol table, then > in the local symbol tables of enclosing functions, then in the global > symbol table, and finally in the table of built-in names. Thus, global > variables cannot be directly assigned a value within a function (unless > named in a global statement), although they may be referenced. The above sounds like it was written by an assembly language programmer, rather than a Python coder. Anyway, here's a translation: When you call a function, the function creates an internal table of variable names. (Each name is a symbol. Hence a table of names is a symbol table.) Assignments inside the function (e.g. "x = 1") creates an entry in that function's table of variable names. On the other hand, merely referring to a variable name *without* assigning to it (e.g. "print x", or "x.attribute") searches for that variable by checking the local table of local variables, then the local variables of any enclosing functions, then the global variables, and finally the built-ins. The consequence of this is that all assignments like: x = 1 automatically force "x" to be a local variable. To make "x" a global variable, and hence assign to the global table of variables instead of the local table, you need to declare it as a global first using "global x" somewhere in the body of the function (conventionally at the top of the function, although anywhere will do). > "The actual parameters (arguments) to a function call are introduced in > the local symbol table of the called function when it is called; thus, > arguments are passed using call by value (where the value is always an > object reference, not the value of the object). Every time somebody uses "call by value" in that way, God kills a kitten. Translation: Arguments to the function are treated as local variables. Arguments are not passed using call by value, although Java programmers will describe it that way. Nor are they passed as call by reference, although Ruby programmers will describe it that way. Both are guilty of misusing a simple term in a very unhelpful way, since call by value and call by reference have long standing meanings that are nothing like what Python (or Java, or Ruby) do. See here for further explanation: http://mail.python.org/pipermail/tutor/2010-December/080505.html The site appears to be down at the moment, but you can try the google cache instead: http://webcache.googleusercontent.com/search?q=cache:tuQDYATR8HAJ:http://mail.python.org/pipermail/tutor/2010-December/080505.html > [1] When a function > calls another function, a new local symbol table is created for that > call." Every call to a function has its own independent set of local variables. > Even as a professional programmer, I'm not really able to follow this. > It seems self-contradictory, amgiguous, and incomplete. It's not really any of those things. I'd call it pretentious, unnecessarily jargon-filled for a tutorial, and (in the case of the call- by-value comment) not just unhelpful but actively harmful. -- Steven From jsrig88 at gmail.com Thu Sep 5 12:40:59 2013 From: jsrig88 at gmail.com (jsrig88 at gmail.com) Date: Thu, 5 Sep 2013 09:40:59 -0700 (PDT) Subject: Could someone please paraphrase this statement about variables and functions in Python? Message-ID: Could someone please paraphrase this statement about variables and functions in Python? I am going through the tutorials on docs.python.org, and I came across this excerpt from http://docs.python.org/3/tutorial/controlflow.html: "The execution of a function introduces a new symbol table used for the local variables of the function. More precisely, all variable assignments in a function store the value in the local symbol table; whereas variable references first look in the local symbol table, then in the local symbol tables of enclosing functions, then in the global symbol table, and finally in the table of built-in names. Thus, global variables cannot be directly assigned a value within a function (unless named in a global statement), although they may be referenced. "The actual parameters (arguments) to a function call are introduced in the local symbol table of the called function when it is called; thus, arguments are passed using call by value (where the value is always an object reference, not the value of the object). [1] When a function calls another function, a new local symbol table is created for that call." Even as a professional programmer, I'm not really able to follow this. It appears to be self-contradictory, amgiguous, incomplete, and possessive of logical missteps. The problem with looking for this information elsewhere is that it's not going to be all in one spot like this half the time, and it's not going to be readily searchable on Google without more knowledge of what it's referring to. However this looks like something that's too important to overlook. I can tell it's referring to things like scope, pass-by-value, references, probably the call stack, etc., but it is written extremely poorly. Translation please? Thanks! From joel.goldstick at gmail.com Thu Sep 5 13:05:17 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Thu, 5 Sep 2013 13:05:17 -0400 Subject: Could someone please paraphrase this statement about variables and functions in Python? In-Reply-To: References: Message-ID: On Thu, Sep 5, 2013 at 12:40 PM, wrote: > Could someone please paraphrase this statement about variables and functions in Python? > > I am going through the tutorials on docs.python.org, and I came across this excerpt from http://docs.python.org/3/tutorial/controlflow.html: > > "The execution of a function introduces a new symbol table used for the local variables of the function. More precisely, all variable assignments in a function store the value in the local symbol table; whereas variable references first look in the local symbol table, then in the local symbol tables of enclosing functions, then in the global symbol table, and finally in the table of built-in names. Thus, global variables cannot be directly assigned a value within a function (unless named in a global statement), although they may be referenced. > > "The actual parameters (arguments) to a function call are introduced in the local symbol table of the called function when it is called; thus, arguments are passed using call by value (where the value is always an object reference, not the value of the object). [1] When a function calls another function, a new local symbol table is created for that call." > > Even as a professional programmer, I'm not really able to follow this. It appears to be self-contradictory, amgiguous, incomplete, and possessive of logical missteps. The problem with looking for this information elsewhere is that it's not going to be all in one spot like this half the time, and it's not going to be readily searchable on Google without more knowledge of what it's referring to. However this looks like something that's too important to overlook. > > I can tell it's referring to things like scope, pass-by-value, references, probably the call stack, etc., but it is written extremely poorly. Translation please? Thanks! > -- > https://mail.python.org/mailman/listinfo/python-list Nearly everyone gets confused by this initially. You should google python namespaces -- Joel Goldstick http://joelgoldstick.com From newspost2012 at gmx.de Thu Sep 5 13:12:12 2013 From: newspost2012 at gmx.de (newspost2012 at gmx.de) Date: Thu, 5 Sep 2013 10:12:12 -0700 (PDT) Subject: Could someone please paraphrase this statement about variables and functions in Python? In-Reply-To: References: Message-ID: Am Donnerstag, 5. September 2013 19:05:17 UTC+2 schrieb Joel Goldstick: > On Thu, Sep 5, 2013 at 12:40 PM, wrote: >> ... >> Even as a professional programmer, I'm not really able to follow this. >> It appears to be self-contradictory, amgiguous, incomplete, and possessive >> of logical missteps. The problem with looking for this information >> elsewhere is that it's not going to be all in one spot like this half the >> time, and it's not going to be readily searchable on Google without more >> knowledge of what it's referring to. However this looks like something >> that's too important to overlook. >> >> I can tell it's referring to things like scope, pass-by-value, references, >> probably the call stack, etc., but it is written extremely poorly. >> Translation please? Thanks! > > Nearly everyone gets confused by this initially. You should google > python namespaces You can also take a look at http://nedbatchelder.com/text/names.html It was a great help for me. Many thanks Ned! - martin - From apennebakergg at gmail.com Thu Sep 5 14:19:26 2013 From: apennebakergg at gmail.com (Andrew Pennebaker) Date: Thu, 5 Sep 2013 11:19:26 -0700 (PDT) Subject: Bundle pip with Python for Windows users Message-ID: In the future, could Python for Windows come with pip? It would simplify package installation for users and developers, often a quite involved and tricky process. http://www.pip-installer.org/en/latest/ From tjreedy at udel.edu Thu Sep 5 14:44:41 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 05 Sep 2013 14:44:41 -0400 Subject: Bundle pip with Python for Windows users In-Reply-To: References: Message-ID: On 9/5/2013 2:19 PM, Andrew Pennebaker wrote: > In the future, could Python for Windows come with pip? It would simplify package installation for users and developers, often a quite involved and tricky process. http://python.org/dev/peps/pep-0453/ "Explicit bootstrapping of pip in Python installations" The proposal is to use a version of pip to install the latest version of pip with future releases of all versions, with all PSF distributions. . -- Terry Jan Reedy From wuwei23 at gmail.com Thu Sep 5 23:33:33 2013 From: wuwei23 at gmail.com (alex23) Date: Fri, 06 Sep 2013 13:33:33 +1000 Subject: Bundle pip with Python for Windows users In-Reply-To: References: Message-ID: On 6/09/2013 4:19 AM, Andrew Pennebaker wrote: > In the future, could Python for Windows come with pip? The ActiveState Windows installers for Python include pip, along with a bunch of other niceties and conveniences. From menkomigen6 at gmail.com Thu Sep 5 15:27:26 2013 From: menkomigen6 at gmail.com (Paul Pittlerson) Date: Thu, 5 Sep 2013 12:27:26 -0700 (PDT) Subject: Multiprocessing / threading confusion Message-ID: I'm trying to understand data handling using multiprocessing and threading, haven't gotten very far without running into problems. This is my code: #!/usr/bin/python from multiprocessing import Process from multiprocessing import Queue from multiprocessing import current_process from threading import Thread import time def gogo(qu): w = Worker(qu) w.start() class Worker(Thread): def __init__(self, Que): super (Worker, self).__init__() self._pid = current_process().pid self.que = Que self.que.put('started worker %s' % self._pid) def run(self): self.que.put('%s ticked' % self._pid) def __del__(self): self.que.put('%s has exited' % self._pid) class Debugger(Thread): def __init__(self, q): super(Debugger, self).__init__() self.q = q def run(self): while True: time.sleep(1) if not self.q.empty(): print self.q.get() else: break; if __name__ == '__main__': debug_q = Queue() debug = Debugger(debug_q) debug.start() for i in range(5): d = Process(target=gogo, args=(debug_q,)) d.start() What I expect to happen is the Debugger object will receive one string at a time, and read it from the queue. But that's not what I see the the output, the "started worker" stuff seems to print for every process, but "ticked" and "exited" will show up in unpredictable ways, I'm guessing they overwrite each other and therefore will not always appear in the output. So I'm looking for help in trying to make sense of this kind of stuff, I thought this was the basic functionality that Queue() would take care of unless there is some other problem in my code. From marduk at python.net Thu Sep 5 18:28:39 2013 From: marduk at python.net (marduk at python.net) Date: Thu, 05 Sep 2013 18:28:39 -0400 Subject: Multiprocessing / threading confusion In-Reply-To: References: Message-ID: <1378420119.27119.18480025.1F2FE34D@webmail.messagingengine.com> On Thu, Sep 5, 2013, at 03:27 PM, Paul Pittlerson wrote: > I'm trying to understand data handling using multiprocessing and > threading, haven't gotten very far without running into problems. This is > my code: [snip (not sure why you are using multiprocessing and threading at the same time] > What I expect to happen is the Debugger object will receive one string at > a time, and read it from the queue. But that's not what I see the the > output, the "started worker" stuff seems to print for every process, but > "ticked" and "exited" will show up in unpredictable ways, I'm guessing > they overwrite each other and therefore will not always appear in the > output. > > So I'm looking for help in trying to make sense of this kind of stuff, I > thought this was the basic functionality that Queue() would take care of > unless there is some other problem in my code. My output is probably totally different than your output. I only get the processes starting. Here's why: This stuff all runs asynchronously. When you start the "Debugger" thread.. I see you put a sleep() in it, but that guarantees nothing. At least on my machine which is somewhat loaded ATM, by the time the Processes are started, the Debugger thread has already finished (because of the check to see if the queue was empty). Apparently it is took longer than 1 second from the time the Debugger was started and the first Process was started. Likewise, what you are getting is probably a case where the queue is momentarily empty by the time the debugger loop gets ahold of the queue lock and checks to see if it's empty. Therefore the Debugger quits. Also because of the asynchronicity of processes, threads, you can not guarantee the order that the processes will get the opportunity to put() into the queue. Also you can't (and shouldn't) depend on the time that __del__ gets called. It can get called at any time, in any order and sometimes not at all.* Hope this helps. * http://docs.python.org/3/reference/datamodel.html?highlight=__del__#object.__del__ From rosuav at gmail.com Thu Sep 5 18:46:40 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Sep 2013 08:46:40 +1000 Subject: Multiprocessing / threading confusion In-Reply-To: References: Message-ID: On Fri, Sep 6, 2013 at 5:27 AM, Paul Pittlerson wrote: > I'm trying to understand data handling using multiprocessing and threading, haven't gotten very far without running into problems. This is my code: > > > What I expect to happen is the Debugger object will receive one string at a time, and read it from the queue. But that's not what I see the the output, the "started worker" stuff seems to print for every process, but "ticked" and "exited" will show up in unpredictable ways, I'm guessing they overwrite each other and therefore will not always appear in the output. > > So I'm looking for help in trying to make sense of this kind of stuff, I thought this was the basic functionality that Queue() would take care of unless there is some other problem in my code. The first thing I notice is that your Debugger will quit as soon as its one-secondly poll results in no data. This may or may not be a problem for your code, but I'd classify it as code smell at best. Is your goal here to make sure Debugger doesn't stop your process from exiting? If so, a simpler and safer solution is to make it a daemon thread. The other thing I see here is your use of __del__ to print your exit message. I don't know if Thread objects are involved in reference loops, but if they are, __del__ (probably) won't be called immediately on thread termination. Your subprocesses are a little odd; they spin off another thread, then halt the first thread. Why not simply do the work in the first thread? You then treat the thread's __del__ method as the process's death, which isn't strictly true, but probably close enough. ChrisA From menkomigen6 at gmail.com Thu Sep 5 19:34:52 2013 From: menkomigen6 at gmail.com (Paul Pittlerson) Date: Thu, 5 Sep 2013 16:34:52 -0700 (PDT) Subject: Multiprocessing / threading confusion In-Reply-To: References: Message-ID: <9d088493-8224-4a48-a2d3-5b7207dc8947@googlegroups.com> On Friday, September 6, 2013 1:28:39 AM UTC+3, mar... at python.net wrote: > Also you can't (and shouldn't) depend on the time that __del__ gets > called. It can get called at any time, in any order and sometimes not > at all.* Wow I did not know that! I was counting on that it reliably gets called when the object is destroyed. From rosuav at gmail.com Thu Sep 5 23:00:49 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Sep 2013 13:00:49 +1000 Subject: Multiprocessing / threading confusion In-Reply-To: <9d088493-8224-4a48-a2d3-5b7207dc8947@googlegroups.com> References: <9d088493-8224-4a48-a2d3-5b7207dc8947@googlegroups.com> Message-ID: On Fri, Sep 6, 2013 at 9:34 AM, Paul Pittlerson wrote: > On Friday, September 6, 2013 1:28:39 AM UTC+3, mar... at python.net wrote: > >> Also you can't (and shouldn't) depend on the time that __del__ gets >> called. It can get called at any time, in any order and sometimes not >> at all.* > > Wow I did not know that! I was counting on that it reliably gets called when the object is destroyed. Even that isn't technically reliable, though in CPython, objects will usually be __del__'d promptly as long as they're not in reference cycles. But the main problem here is that the destruction of the object has nothing to do with the ending of the thread or process; the object will hang around for as long as the caller might want it. You'll want to put your "end of process" code at the bottom of run(), I think, unless there's some other place for it. ChrisA From menkomigen6 at gmail.com Thu Sep 5 20:03:30 2013 From: menkomigen6 at gmail.com (Paul Pittlerson) Date: Thu, 5 Sep 2013 17:03:30 -0700 (PDT) Subject: Multiprocessing / threading confusion In-Reply-To: References: Message-ID: On Friday, September 6, 2013 1:46:40 AM UTC+3, Chris Angelico wrote: > The first thing I notice is that your Debugger will quit as soon as > its one-secondly poll results in no data. This may or may not be a > problem for your code, but I'd classify it as code smell at best. Is > your goal here to make sure Debugger doesn't stop your process from > exiting? If so, a simpler and safer solution is to make it a daemon > thread. I didn't think it would be a problem, because unless the system is very slow, the functions will finish in a fraction of a second, on my machine it does not matter whether I have it set as 0.1 second or several seconds, the output is still the same. It's not eloquent, but the point was just to exit the test when no more prints are to be made. But how can I fix the actual bug I was asking about though? I want to print ticked and exited for all the processes, just to acknowledge to myself that the code is working.. so I can proceed to experiment with more complexity! :D From piet at vanoostrum.org Thu Sep 5 23:54:34 2013 From: piet at vanoostrum.org (Piet van Oostrum) Date: Thu, 05 Sep 2013 23:54:34 -0400 Subject: Multiprocessing / threading confusion References: Message-ID: Paul Pittlerson writes: > On Friday, September 6, 2013 1:46:40 AM UTC+3, Chris Angelico wrote: > >> The first thing I notice is that your Debugger will quit as soon as >> its one-secondly poll results in no data. This may or may not be a >> problem for your code, but I'd classify it as code smell at best. Is >> your goal here to make sure Debugger doesn't stop your process from >> exiting? If so, a simpler and safer solution is to make it a daemon >> thread. > > I didn't think it would be a problem, because unless the system is very > slow, the functions will finish in a fraction of a second, on my machine > it does not matter whether I have it set as 0.1 second or several seconds, > the output is still the same. It's not eloquent, but the point was just to > exit the test when no more prints are to be made. > > But how can I fix the actual bug I was asking about though? I want to > print ticked and exited for all the processes, just to acknowledge to > myself that the code is working.. so I can proceed to experiment with > more complexity! :D On my system I get the output: started worker 75501 75501 ticked 75501 has exited started worker 75505 75505 ticked 75505 has exited started worker 75504 started worker 75502 started worker 75503 75502 ticked 75502 has exited 75504 ticked 75504 has exited 75503 ticked 75503 has exited So all the provesses have their 'started' 'ticked' and 'exited' message. But as others have indicated, because your code is timing dependent, that is just coincidental. Because multiprocessing/multithreading is inherently non-deterministic, the order of the messages will be unpredictable. But you should not make the exiting of the Debugger non deterministic, as you have it now. One way to do this is to count the number of processes that have exited, and wait until all are done. In this case you could count the number of 'exited' messages that have arrived. def run(self): nbr_process = 5 while True: time.sleep(1) msg = self.q.get() print msg if 'exited' in msg: nbr_process -= 1 if nbr_process == 0: break Of course the 5 should be given as a parameter. This still leaves you with the uncertainty of the __del__ being called. Why not just put the message at the end of the Worker run code? def run(self): self.que.put('%s ticked' % self._pid) # do some work time.sleep(1) self.que.put('%s has exited' % self._pid) However, in my experiments (bot Python 2.7.5 and 3.3.2 on Mac OS X 10.6.8) it seems that there is a problem with a Thread inside a Process: When the main thread of the Process is finished, the other Thread is also terminated, as if it is a daemon thread. Although self.daemon == False!! You can check this with the following Worker code: def run(self): for n in range(5): self.que.put('%s tick %d' % (self._pid, n)) # do some work time.sleep(1) self.que.put('%s has exited' % self._pid) It appears that not all ticks are deliverd. In my system, only one tick per thread, and then it disappears. I have no idea if this is a bug. I certainly couldn't find it documented. The solution to this is to put a join statement in gogo: def gogo(qu): w = Worker(qu) w.start() w.join() -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From piet at vanoostrum.org Fri Sep 6 00:28:05 2013 From: piet at vanoostrum.org (Piet van Oostrum) Date: Fri, 06 Sep 2013 00:28:05 -0400 Subject: Multiprocessing / threading confusion References: Message-ID: Piet van Oostrum writes: > def run(self): > for n in range(5): > self.que.put('%s tick %d' % (self._pid, n)) > # do some work > time.sleep(1) > self.que.put('%s has exited' % self._pid) To prevent the 'exited' message to disappear if there is an exception in the thread you should protect it with try -- finally: def run(self): try: for n in range(5): self.que.put('%s tick %d' % (self._pid, n)) # do some work time.sleep(1) finally: self.que.put('%s has exited' % self._pid) This doesn't help for the premature termination of the thread, as that isn't an exception. But use the w.join() for that. Or you could put the 'exited' message after the w.join() command. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From menkomigen6 at gmail.com Fri Sep 6 14:27:05 2013 From: menkomigen6 at gmail.com (Paul Pittlerson) Date: Fri, 6 Sep 2013 11:27:05 -0700 (PDT) Subject: Multiprocessing / threading confusion In-Reply-To: References: Message-ID: Ok here is the fixed and shortened version of my script: #!/usr/bin/python from multiprocessing import Process, Queue, current_process from threading import Thread from time import sleep class Worker(): def __init__(self, Que): self._pid = current_process().pid self.que = Que self.que.put('started worker %s' % self._pid) for n in range(5): self.que.put('%s tick %d' % (self._pid, n)) # do some work sleep(0.01) self.que.put('%s has exited' % self._pid) class Debugger(Thread): def __init__(self, q): super(Debugger, self).__init__() self.q = q def run(self): while True: sleep(0.1) if not self.q.empty(): print self.q.get() else: break # if __name__ == '__main__': debug_q = Queue() debug = Debugger(debug_q) debug.start() for i in range(5): d = Process(target=Worker, args=(debug_q,)) d.start() This works great on linux, but does not run on windows (7). The behavior was: I opened it with double clicking and so a window appeared and disappeared (no text) then I opened it with IDLE and ran it there, where it worked a couple times. Then reopened it with IDLE and this time it did not work at all. After that the script did not run either through IDLE or opening directly. What may be the reason it works on linux, but seems buggy on windows? From skip at pobox.com Fri Sep 6 14:53:51 2013 From: skip at pobox.com (Skip Montanaro) Date: Fri, 6 Sep 2013 13:53:51 -0500 Subject: Multiprocessing / threading confusion In-Reply-To: References: Message-ID: On Fri, Sep 6, 2013 at 1:27 PM, Paul Pittlerson wrote: > Ok here is the fixed and shortened version of my script: Before going any further, I think you need to return to marduk's response and consider if you really and truly need both threads and fork (via multiprocessing). http://www.linuxprogrammingblog.com/threads-and-fork-think-twice-before-using-them Skip From davea at davea.name Fri Sep 6 16:34:53 2013 From: davea at davea.name (Dave Angel) Date: Fri, 6 Sep 2013 20:34:53 +0000 (UTC) Subject: Multiprocessing / threading confusion References: Message-ID: On 6/9/2013 14:27, Paul Pittlerson wrote: f> Ok here is the fixed and shortened version of my script: > > #!/usr/bin/python > > from multiprocessing import Process, Queue, current_process > from threading import Thread > from time import sleep > > class Worker(): > def __init__(self, Que): > self._pid = current_process().pid > self.que = Que > self.que.put('started worker %s' % self._pid) > > for n in range(5): > self.que.put('%s tick %d' % (self._pid, n)) > # do some work > sleep(0.01) > > self.que.put('%s has exited' % self._pid) > > class Debugger(Thread): > def __init__(self, q): > super(Debugger, self).__init__() > self.q = q > > def run(self): > while True: > > sleep(0.1) > > if not self.q.empty(): > print self.q.get() > > else: > break > # > > if __name__ == '__main__': > > debug_q = Queue() > debug = Debugger(debug_q) > debug.start() > > for i in range(5): > > d = Process(target=Worker, args=(debug_q,)) > d.start() > > This works great on linux, but does not run on windows (7). The behavior was: I > opened it with double clicking and so a window appeared and disappeared (no > text) then I opened it with IDLE and ran it there, where it worked a couple > times. Then reopened it with IDLE and this time it did not work at all. After > that the script did not run either through IDLE or opening directly. > > What may be the reason it works on linux, but seems buggy on windows? In Linux, the Process() class works very differently. One effect is that it's probably much quicker than in Windows. But also, the relationship between the original process and the extra 5 is different. I wouldn't even try to debug anything else till I add join() calls for both the extra thread and the 5 extra processes. You could just stick a raw_input() at the end to fake it, but that's just a temporary hack. Untested: if __name__ == '__main__': debug_q = Queue() debug = Debugger(debug_q) debug.start() processes = [] for i in range(5): d = Process(target=Worker, args=(debug_q,)) processes.append(d) d.start() for proc in processes: proc.join() debug.join() As for running it in various shells, you missed the only one worth using: run it in the cmd shell. When you double-click, you can't really be sure if that temporary cmd shell was really empty before it vanished; it might just not have bothered to update its pixels on its way out. And any IDE shell like IDLE has so many other glitches in it, that bugs like these are as likely to be the IDE's fault as anything else. -- DaveA From piet at vanoostrum.org Fri Sep 6 17:15:56 2013 From: piet at vanoostrum.org (Piet van Oostrum) Date: Fri, 06 Sep 2013 17:15:56 -0400 Subject: Multiprocessing / threading confusion References: Message-ID: Paul Pittlerson writes: [...] > def run(self): > while True: > > sleep(0.1) > > if not self.q.empty(): > print self.q.get() > > else: > break [...] > This works great on linux, but does not run on windows (7). The behavior was: I > opened it with double clicking and so a window appeared and disappeared (no > text) then I opened it with IDLE and ran it there, where it worked a couple > times. Then reopened it with IDLE and this time it did not work at all. After > that the script did not run either through IDLE or opening directly. > > What may be the reason it works on linux, but seems buggy on windows? That it works on Linux is just coincidence. Your script is still timing dependent because the while loop in Debug.run stops when the queue is empty. As has been explained in other answers, the queue can just become empty when Debug empties it faster than the other processes can fill it. That is entirely dependent on the scheduling of the O.S. so you have no control over it. You must use a safe way to stop, for example to count the exited messages. Another way is to join all the processes in the main program, and after that put a special END message to the queue, which causes Debug to stop: class Debugger(Thread): ... def run(self): while True: sleep(0.1) msg = self.q.get() print(msg) if 'END' in msg: break ..main.. processes = [] for i in range(5): d = Process(target=Worker, args=(debug_q,)) d.start() processes.append(d) for p in processes: p.join() debug_q.put('END') -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From bv4bv4bv4 at gmail.com Thu Sep 5 15:58:50 2013 From: bv4bv4bv4 at gmail.com (bv4bv4bv4 at gmail.com) Date: Thu, 5 Sep 2013 12:58:50 -0700 (PDT) Subject: THE POPULATION OF MUSLIMS Message-ID: <0c006e83-dcbe-46ec-b7ef-bd86ac6b6307@googlegroups.com> THE POPULATION OF MUSLIMS Islam today is a global religion. It is no longer confined to Muslim majority countries such as Egypt, Saudi Arabia or Indonesia. Small but significant communities exist across Europe, the Americas and Australasia. For some time Muslims have been an invisible presence in the western world but one decade into the 21st century Muslims are no longer curiosities. They are as much at home in London Paris or Chicago as they are in Istanbul, Damascus and Jakarta. In 2011 Muslims in the West also no longer exist in immigrant communities but are second, third and fourth generation citizens participating in professional and civic life. Islam is said to be the fastest growing religion in the United States. It is estimated that more than 1 million Americans have converted to Islam. In recent years due to an Islamic revival, believing and practicing Muslims have established a visible presence not only in Islamic societies but also in the West. What do the latest data and statistics tell us about the number of Muslims in the world. Where do they live? How many are born into the Muslim faith and how many choose to convert to Islam? The majority of the following statistics and data come from the Pew Research Centre. According to the Pew[1] Islam is growing about 2.9% per year. This is faster than the total world population which increases about 2.3% annually. The world?s Muslim population is expected to increase by about 35% in the next 20 years. In mid 2010 the Pew forum estimated that there were 1.57 billion Muslims in the world. This represents 22% of the world?s population. Islam is the second largest religion in the world, beaten only by Christianity which represents 33% of the world?s population with a little over 2 billion adherents. The Pew Forum on Religion & Public Life stated that Islam is the fastest-growing religion in Europe. Driven by immigration and high birth rates, the number of Muslims on the continent has tripled in the last 30 years. Most demographers forecast a similar or even higher rate of growth in the coming decades. If current trends continue 79 countries will have a million or more Muslim inhabitants in 2030, up from 72 countries in 2011. The seven new countries are expected to be Belgium, Canada, Congo, Djibouti, Guinea Bissau, Netherlands and Togo. About 60% of the world?s Muslims will continue to live in the Asia-Pacific region, while about 20% will live in the Middle East and North Africa, as is the case in 2010. One of the biggest changes expected is that Pakistan will almost certainly surpass Indonesia as the country with the single largest Muslim population. [2] In 2011 statistics tell us that 74.1% of the world?s Muslims live in the 49 countries in which Muslims make up a majority of the population. More than a fifth of all Muslims (23.3%) live in non-Muslim-majority countries in the developing world. These minority Muslim populations are often quite large. India, for example, has the third-largest population of Muslims worldwide. China has more Muslims than Syria, while Russia is home to more Muslims than Jordan and Libya combined. [3] About 3% of the world?s Muslims live in more-developed regions, such as Europe, North America, Australia, New Zealand and Japan. [4] In the United States, the population projections show the number of Muslims more than doubling over the next two decades, rising from 2.6 million in 2010 to 6.2 million in 2030. The number of Muslims in Canada is expected to nearly triple in the next 20 years, from about 940,000 in 2010 to nearly 2.7 million in 2030. Muslims are expected to make up 6.6% of Canada?s total population in 2030, up from 2.8% today. Argentina is expected to have the third-largest Muslim population in the Americas, after the U.S. and Canada. Argentina, with about 1 million Muslims in 2010, is now in second place, behind the U.S. In Europe as a whole, the Muslim share of the population is expected to grow by nearly one-third over the next 20 years, rising from 6% of the region?s inhabitants in 2010 to 8% in 2030. In absolute numbers, Europe?s Muslim population is projected to grow from 44.1 million in 2010 to 58.2 million in 2030. Nearly three-in-ten people living in the Asia-Pacific region in 2030 (27.3%) will be Muslim, up from about a quarter in 2010 (24.8%) and roughly a fifth in 1990 (21.6%). Muslims make up only about 2% of the population in China, but because the country is so populous, its Muslim population is expected to be the 19th largest in the world in 2030. The growth rates of religions are usually due to conversions, higher birth and fertility rates and in many countries religions grow because of immigration. While the global Muslim population is expected to grow at a faster rate than the non-Muslim population, the Muslim population nevertheless is expected to grow at a slower pace in the next two decades than it did in the previous two decades. Finding statistics and data about the number of people converting to Islam from other religions or atheism can be difficult. This is usually not a question asked by government authorities or research centers. In the next article we will discuss Muslim growth rates across the globe due to conversion and immigration. Islam is a global religion, and as we learned in the previous article it is no longer confined to those countries we think of as Arabic or Asian. Close to 1.6 billion people across the globe identify as Muslim. Growth projections paint a picture of unprecedented growth, faster than the world population growth. 2011 statistics tell us that 74.1% of the world?s Muslims live in the 49 countries in which Muslims make up a majority of the population. More than a fifth of all Muslims (23.3%) live in non-Muslim-majority countries in the developing world, and about 3% of the world's Muslims live in more-developed regions, such as Europe, North America, and Australia. Where in fact do these 3% of Muslims come from? Immigration and conversion account for a large percentage of Muslims living in predominantly western countries. Governments tend to keep strict immigration records however religious affiliation is not always recorded. Conversion statistics are notoriously unreliable but do reveal that the number of people converting to Islam is also experiencing a high growth rate. From across the globe and from various sources, both Muslim and non Muslim, government and nongovernmental, we have collected and collated statistical data in an effort to present a clear picture of how Muslim growth rates are proceeding into the second decade of the 21st century. Let us begin in Australia. According to the 2006 census, 1.7% of the Australian population identified with Islam, this represents a population growth of 20.9% on the 2001 count ? only Hinduism (55.1%) and ?no religion? (27.5%) had bigger percentage jumps in the same five-year period. Where did this 20% growth rate come from? Apparently 36% were born in Australia, the majority claiming Lebanese, Turkish or broadly defined Arab ancestry. [5] Other immigration source countries include the predominantly Muslim Iraq, Afghanistan, Pakistan, Indonesia and Bangladesh. However, approximately two-fifths of Australia?s Muslims live in Melbourne, and originate from over 70 countries. [6] There are no reliable statistics for conversions to Islam but mosques across Australia report that conversions take place frequently. A report published in January 2011 by the Washington-based Pew Research centre[7] suggests Muslim numbers in Australia will increase by 80 percent, compared with 18 per cent for the population overall, growing from 399,000 at present to 714,000. This is due first to higher reproduction rates - Muslim families typically have four or more children, while other Australians have one or two - and, second, to migration from Muslim majority countries such as mentioned above. The estimates of how many Muslims live in Europe vary wildly, depending on where the statistics are from. It is made even more difficult by the fact that they are the largest religious minority in Europe, and Islam is the fastest growing religion. As would be expected Europe?s Muslim population are ethnically and linguistically diverse and Muslim immigrants in Europe hail from a variety of Middle Eastern, African, and Asian countries. Converts are a tiny subset of the Muslim population, but their numbers are growing. Studies in Germany and France have each estimated around 4,000 conversions a year in Europe or their respective countries. In Germany, the estimated 4,000 converts each year[8], can be compared with an annual average of 300 in the late 1990s, still, less than 1 percent of Germany?s 3.3 million Muslims are converts. A report by France?s domestic intelligence agency, published by Le Figaro, estimated last year[9] that there were 30,000 to 50,000 converts in France. The bulk of French Muslims are French citizens, and Islam is France?s second highest ranked religion. Muslims are a minority in the United Kingdom, making up 2.7 per cent of the country's total population of some 60 million people. The number of converts to Islam is, as expected very difficult to either predict or find hard data about. One British newspaper however, the Independent, reports that the number of Britons converting to Islam has nearly doubled in the past decade, despite the fact that the UK has witnessed a rise in Islamophobia. This is according to a comprehensive study by inter-faith think tank Faith Matters. Previous estimates have placed the number of Muslim converts in the UK at between 14,000 and 25,000, but this study suggests that the real figure could be as high as 100,000, with as many as 5,000 new conversions each year. By using data from the Scottish 2001 census - the only survey to ask respondents what their religion was at birth as well as at the time of the survey - researchers broke down what proportion of Muslim converts there were and then extrapolated the figures for Britain as a whole. [10] In the United states of America, according to the Pew Research Centre, roughly two-thirds (65%) of adult Muslims living in the United States were born elsewhere, and 39% have come to the U.S. since 1990. A relatively large proportion of Muslim immigrants are from Arab countries, but many also come from Pakistan and other South Asian countries. Among native-born Muslims, slightly more than half are African American (20% of U.S. Muslims overall), many of whom are converts to Islam. [11] As is the case in Europe and Australia, researchers say getting accurate estimates of converts to Islam is the most difficult challenge of all. Data on conversion from another religion to Islam is virtually non-existent, and what estimates exist are based on conversion rates to other faiths that may not apply to the Muslim experience. Statistics about converts to Islam are much easier to find in Arabian Gulf countries where Islamic Cultural Centres keep meticulous records. For instance in Dubai, Huda Khalfan Al Kaabi, head of the New Muslims Section in the Islamic Affairs and Charitable Activities Department (IACAD) said, 1,365 people converted to Islam from January to June 2009 as compared to 878 over the same period in 2008. Observing that 3,763 expatriates from 72 countries had converted to Islam in an 18 month period, Al Kaabi said most of them were from the Philippines, Russia, China and India. Globalisation has contributed to the spread of Islam around the world, either by immigration or conversion. Borders are more fluid than ever before and many people are able to make clear decisions about where they want to live and what religion they want to follow. With or without hard statistical data it is possible to see clearly that across the globe people are converting to Islam in large numbers. Islam is a global religion, no longer based on ethnicity or nationality. http://www.islamreligion.com/articles/4394/ http://www.islamreligion.com/articles/4421/ thank you . [1] The Pew Research Centre is an American think tank organization based in Washington, D.C. that provides information on issues, attitudes and trends shaping the United States and the world. [2] http://pewresearch.org/pubs/1872/muslim-population-projections-worldwide-fast-growth [3] according to Pew reports in 2009 [4] http://pewresearch.org/pubs/1872/muslim-population-projections-worldwide-fast-growth. [5] Statistical snapshot on Muslim Australians from a Human Rights and Equal Opportunity Commission (HREOC) fact sheet. [6]http://museumvictoria.com.au/immigrationmuseum/discoverycentre/your-questions/muslim-australians/ [7] Pew Research Centre's Forum on Religion and Public Life, The Future of the Global Muslim Population: Projections for 2010-2030. Using figures from the Australian Bureau of Statistics. [8] A study financed by the Interior Ministry and carried out by the Soest-based Muslim institute Islam Archive Germany. (2004-5) [9] http://www.religionnewsblog.com/7916/europe-fears-threat-from-its-converts-to-islam [10] http://faith- matters.org/resources/publicationsreports/218-report-on-converts-to-islam-in-the-uk-a-minority-within-a-minority [11]http://pewresearch.org/assets/pdf/muslim- americans.pdf From tjreedy at udel.edu Fri Sep 6 02:10:28 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 06 Sep 2013 02:10:28 -0400 Subject: OT spam (was Re: THE POPULATION OF MUSLIMS) In-Reply-To: <0c006e83-dcbe-46ec-b7ef-bd86ac6b6307@googlegroups.com> References: <0c006e83-dcbe-46ec-b7ef-bd86ac6b6307@googlegroups.com> Message-ID: On 9/5/2013 3:58 PM, bv4bv4bv4 at gmail.com wrote: Religious rant that passed the spam filter and moderation mechanism. I am a new moderator and have asked the others if we can block this address. Please do not add to the spam posts that do appear by commenting on them. We do the best be can with the software we have and do discard a couple of posts a day. -- Terry Jan Reedy From skwyang93 at gmail.com Thu Sep 5 16:08:24 2013 From: skwyang93 at gmail.com (skwyang93 at gmail.com) Date: Thu, 5 Sep 2013 13:08:24 -0700 (PDT) Subject: Newbie question related to Boolean in Python Message-ID: 1. bear_moved = False 2. 3. while True: 4. next = raw_input("> ") 5. 6. if next == "take honey": 7. dead("The bear looks at you then slaps your face off.") 8. elif next == "taunt bear" and not bear_moved: 9. print "The bear has moved from the door. You can go through." 10. 11. bear_moved = True 12. elif next == "taunt bear" and bear_moved: 13. dead("The bear gets pissed off and chews your leg off.") 14. elif next == "open door" and bear_moved: 15. gold_room() 16. else: 17. print "I got no idea what that means. # This is just to show my understanding of Boolean. In line 8-9, if my input is "taunt bear", the result is true and true, which will continue the loop. # So what confused me is line 12-13. if my input is taunt bear, is it suppose to be taunt bear == "taunt bear" and bear_moved which is true and true? which means the loop will continue instead of cancelling it. Thanks in advance for spending your time to answer my question. Source: Learnpythonthehardway From neilc at norwich.edu Thu Sep 5 16:38:30 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 5 Sep 2013 20:38:30 GMT Subject: Newbie question related to Boolean in Python References: Message-ID: On 2013-09-05, skwyang93 at gmail.com wrote: > 1. bear_moved = False > 2. > 3. while True: > 4. next = raw_input("> ") > 5. > 6. if next == "take honey": > 7. dead("The bear looks at you then slaps your face off.") > 8. elif next == "taunt bear" and not bear_moved: > 9. print "The bear has moved from the door. You can go through." > 10. > 11. bear_moved = True > 12. elif next == "taunt bear" and bear_moved: > 13. dead("The bear gets pissed off and chews your leg off.") > 14. elif next == "open door" and bear_moved: > 15. gold_room() > 16. else: > 17. print "I got no idea what that means. > > # This is just to show my understanding of Boolean. In line 8-9, if my input is "taunt bear", the result is true and true, which will continue the loop. > > # So what confused me is line 12-13. if my input is taunt bear, is it suppose to be taunt bear == "taunt bear" and bear_moved which is true and true? which means the loop will continue instead of cancelling it. > > Thanks in advance for spending your time to answer my question. Your logic looks OK, but the indentation on your code is screwy. It should not compile like that. There may be indentation errors, but I don't want to make assumptions when the indentation is definitely not what your real code says. Can you cut and paste your code directly instead of retyping it? -- Neil Cerutti From skwyang93 at gmail.com Thu Sep 5 19:36:55 2013 From: skwyang93 at gmail.com (Thomas Yang) Date: Thu, 5 Sep 2013 16:36:55 -0700 (PDT) Subject: Newbie question related to Boolean in Python In-Reply-To: References: Message-ID: bear_moved = False while True: next = raw_input("> ") if next == "take honey": dead("The bear looks at you then slaps your face off.") elif next == "taunt bear" and not bear_moved: print "The bear has moved from the door. You can go through." bear_moved = True elif next == "taunt bear" and bear_moved: dead("The bear gets pissed off and chews your leg off.") elif next == "open door" and bear_moved: gold_room() else: print "I got no idea what that means." # sorry if it looks confusing, this is the real code From steve+comp.lang.python at pearwood.info Thu Sep 5 22:28:07 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Sep 2013 02:28:07 GMT Subject: Newbie question related to Boolean in Python References: Message-ID: <52293db6$0$29988$c3e8da3$5496439d@news.astraweb.com> On Thu, 05 Sep 2013 16:36:55 -0700, Thomas Yang wrote: > bear_moved = False > > while True: > next = raw_input("> ") > > if next == "take honey": > dead("The bear looks at you then slaps your face off.") > elif next == "taunt bear" and not bear_moved: > print "The bear has moved from the door. You can go > through." > bear_moved = True > elif next == "taunt bear" and bear_moved: > dead("The bear gets pissed off and chews your leg off.") > elif next == "open door" and bear_moved: > gold_room() > else: > print "I got no idea what that means." > > # sorry if it looks confusing, this is the real code No it isn't, because it gives an indent error. The first line is unindented, the second line is indented. One of those must be wrong. py> bear_moved = False py> while True: File "", line 1 while True: ^ IndentationError: unexpected indent Please be careful of indentation. Python's indentation rules are great for code, but not so great for copying and pasting into emails and websites. So beware, and take extra care with indentation. Copied from your previous message, your question was: > # So what confused me is line 12-13. if my input is taunt bear, is it > suppose to be taunt bear == "taunt bear" and bear_moved which is true > and true? which means the loop will continue instead of cancelling it. The relevant two lines are: > elif next == "taunt bear" and bear_moved: > dead("The bear gets pissed off and chews your leg off.") I don't understand your question. Nothing cancels the loop anywhere. Presumably the loop repeats forever, unless the function dead() contains a sys.exit or similar. The first time around the loop, the bear has not moved, and presumably is blocking the door. So the variable `bear_moved` is false. If the user's command is "taunt bear" (the poorly named variable `next`) then the first time around the loop this if statement will trigger: if next == "taunt bear" and not bear_moved: a message will print stating that the bear moves away from the door, and `bear_moved` will be set to True. At that point, the *entire* if...elif...else block is finished, execution will jump to the end of the loop, and the next loop will begin. The second time through the loop, the user is prompted for a command again. If the user enters "taunt bear" a second time, then if next == "taunt bear" and bear_moved: is triggered, since this time `bear_moved` is True, and the bear eats the character. Does this answer your question? -- Steven From davea at davea.name Thu Sep 5 16:47:35 2013 From: davea at davea.name (Dave Angel) Date: Thu, 5 Sep 2013 20:47:35 +0000 (UTC) Subject: Newbie question related to Boolean in Python References: Message-ID: On 5/9/2013 16:08, skwyang93 at gmail.com wrote: > 1. bear_moved = False > 2. > 3. while True: > 4. next = raw_input("> ") > 5. > 6. if next == "take honey": > 7. dead("The bear looks at you then slaps your face off.") > 8. elif next == "taunt bear" and not bear_moved: > 9. print "The bear has moved from the door. You can go through." > 10. > 11. bear_moved = True > 12. elif next == "taunt bear" and bear_moved: > 13. dead("The bear gets pissed off and chews your leg off.") > 14. elif next == "open door" and bear_moved: > 15. gold_room() > 16. else: > 17. print "I got no idea what that means. > Please indent by 4, not 2 characters. It's very hard to see what's lined up with what. And that's compounded by having the line numbers there so that the first 9 lines are shifted left. > # This is just to show my understanding of Boolean. In line 8-9, if my input is "taunt bear", the result is true and true, which will continue the loop. Those lines have compound if conditions. Line 8 will be true/true only the first time you type "taunt bear". Notice the operator "not" in front of bear_moved. > > # So what confused me is line 12-13. if my input is taunt bear, is it suppose to be taunt bear == "taunt bear" and bear_moved which is true and true? which means the loop will continue instead of cancelling it. Line 12 will be true/true only if you've already run line 11. Since bear_moved = False initially, the only way you get true /true here is by answering "taunt bear" twice. > > Thanks in advance for spending your time to answer my question. > Source: Learnpythonthehardway -- DaveA From timr at probo.com Fri Sep 6 00:02:04 2013 From: timr at probo.com (Tim Roberts) Date: Thu, 05 Sep 2013 21:02:04 -0700 Subject: Newbie question related to Boolean in Python References: Message-ID: skwyang93 at gmail.com wrote: > ># This is just to show my understanding of Boolean. In line 8-9, if >my input is "taunt bear", the result is true and true, which will >continue the loop. > > So what confused me is line 12-13. if my input is taunt bear, is it >suppose to be taunt bear == "taunt bear" and bear_moved which is >true and true? which means the loop will continue instead of cancelling it. I'm not quite sure what you're expecting. There is nothing in any of the cases that will exit the loop. The loop is infinite. I assume (with no evidence) that the "dead" function calls sys.exit, which kills the program. In that case, this makes a little bit of sense. The first time you type "taunt bear", bear_moved is set True and the loop runs again. If you type "taunt bear" a second time, then the bear is pissed off and you call dead(). -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From errol.anderson at gsds.co.nz Fri Sep 6 00:23:56 2013 From: errol.anderson at gsds.co.nz (Errol Anderson) Date: Fri, 6 Sep 2013 16:23:56 +1200 Subject: "Python for Delphi' Assistance Message-ID: <008901ceaab8$e75b2e60$b6118b20$@gsds.co.nz> The Delphi program I maintain uses 'Python for Delphi' to run Python scripts within the program. The latest version of 'Python for Delphi' appears to stop at Delphi 2006 with Python 2.5, while I would like to run Delphi 2007 with Python 2.7. Are there any 'Python for Delphi' users out there who could help me. Best regards Errol Anderson -------------- next part -------------- An HTML attachment was scrubbed... URL: From chandan_psr at yahoo.co.in Fri Sep 6 02:14:22 2013 From: chandan_psr at yahoo.co.in (chandan kumar) Date: Fri, 6 Sep 2013 14:14:22 +0800 (SGT) Subject: Python Debugger tool Message-ID: <1378448062.88328.YahooMailBasic@web190504.mail.sg3.yahoo.com> Hi Is any one aware of free ipython debugger tool.How good is this tool for a beginner to use like ,placing breakpoints,checking variables ,call stack (function flow) etc.I don't like to use python PDB . I have heard about wingware ,pycharm which are licensed versions.Used wingware trail version and felt pretty good tool for beginners. Please let know your views on ipython.Let me know about any python free debugger tools Best Regards, Chandan From rafadurancastaneda at gmail.com Fri Sep 6 02:53:25 2013 From: rafadurancastaneda at gmail.com (=?iso-8859-1?Q?Rafael_Dur=E1n_Casta=F1eda?=) Date: Fri, 6 Sep 2013 08:53:25 +0200 Subject: Python Debugger tool In-Reply-To: <1378448062.88328.YahooMailBasic@web190504.mail.sg3.yahoo.com> References: <1378448062.88328.YahooMailBasic@web190504.mail.sg3.yahoo.com> Message-ID: El 06/09/2013, a las 08:14, chandan kumar escribi?: > Hi > > Is any one aware of free ipython debugger tool.How good is this tool for a beginner to use like ,placing breakpoints,checking variables ,call stack (function flow) etc.I don't like to use python PDB . > I have heard about wingware ,pycharm which are licensed versions.Used wingware trail version and felt pretty good tool for beginners. > > Please let know your views on ipython.Let me know about any python free debugger tools > > > Best Regards, > Chandan > -- > https://mail.python.org/mailman/listinfo/python-list Ipdb works fine for me. https://pypi.python.org/pypi/ipdb From fabiofz at gmail.com Fri Sep 6 07:30:22 2013 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Fri, 6 Sep 2013 08:30:22 -0300 Subject: Python Debugger tool In-Reply-To: <1378448062.88328.YahooMailBasic@web190504.mail.sg3.yahoo.com> References: <1378448062.88328.YahooMailBasic@web190504.mail.sg3.yahoo.com> Message-ID: On Fri, Sep 6, 2013 at 3:14 AM, chandan kumar wrote: > Hi > > Is any one aware of free ipython debugger tool.How good is this tool for > a beginner to use like ,placing breakpoints,checking variables ,call stack > (function flow) etc.I don't like to use python PDB . > I have heard about wingware ,pycharm which are licensed versions.Used > wingware trail version and felt pretty good tool for beginners. > > Please let know your views on ipython.Let me know about any python free > debugger tools > Just a note: the debugger in PyCharm is actually a fork of the PyDev debugger, so, using PyDev (which is Open Source) may be an option if you'd like something more visual than the IPython debugger (see: http://pydev.org/manual_adv_debugger.html for the debugger and http://pydev.org/manual_101_root.html for installing/configuring PyDev initially). Cheers, Fabio > > > Best Regards, > Chandan > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From wxjmfauth at gmail.com Fri Sep 6 05:11:56 2013 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Fri, 6 Sep 2013 02:11:56 -0700 (PDT) Subject: Chardet, file, ... and the Flexible String Representation Message-ID: <4ce85ea8-4a4c-46cf-a546-ad999576a5f7@googlegroups.com> Short comment about the "detection" tools from a previous discussion. The tools supposed to detect the coding scheme are all working with a simple logical mathematical rule: p ==> q <==> non q ==> non p . Shortly -- and consequence -- they do not detect a coding scheme they only detect "a" possible coding schme. The Flexible String Representation has conceptually to face the same problem. It splits "unicode" in chunks and it has to solve two problems at the same time, the coding and the handling of multiple "char sets". The problem? It fails. "This poor Flexible String Representation does not succeed to solve the problem it create itsself." Workaround: add more flags (see PEP 3xx.) Still thinking "mathematics" (limit). For a given repertoire of characters one can assume that every char has its own flag (because of the usage of multiple coding schemes). Conceptually, one will quickly realize, at the end, that they will be an equal amount of flags and an amount of characters and the only valid solution it to work with a unique set of encoded code points, where every element of this set *is* its own flag. Curiously, that's what the utf-* (and btw other coding schemes in the byte string world) are doing (with plenty of other advantages). Already said. An healthy coding scheme can only work with a unique set of encoded code points. That's why we have to live today with all these coding schemes. jmf From steve+comp.lang.python at pearwood.info Fri Sep 6 06:57:48 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Sep 2013 10:57:48 GMT Subject: Chardet, file, ... and the Flexible String Representation References: <4ce85ea8-4a4c-46cf-a546-ad999576a5f7@googlegroups.com> Message-ID: <5229b52c$0$29988$c3e8da3$5496439d@news.astraweb.com> On Fri, 06 Sep 2013 02:11:56 -0700, wxjmfauth wrote: > Short comment about the "detection" tools from a previous discussion. > > The tools supposed to detect the coding scheme are all working with a > simple logical mathematical rule: > > p ==> q <==> non q ==> non p . Incorrect. chardet does a statistical analysis of the bytes, and tries to guess what language they are likely to come from. The algorithm is described here: https://github.com/erikrose/chardet/blob/master/docs/how-it-works.html (although that's rather inconvenient to read), and here: http://www-archive.mozilla.org/projects/intl/ UniversalCharsetDetection.html chardet is a Python port of the Mozilla charset guesser, so they use the same algorithm. > Shortly -- and consequence -- they do not detect a coding scheme they > only detect "a" possible coding schme. That at least is correct. > The Flexible String Representation has conceptually to face the same > problem. No it doesn't. -- Steven From antoon.pardon at rece.vub.ac.be Fri Sep 6 07:10:37 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Fri, 06 Sep 2013 13:10:37 +0200 Subject: Chardet, file, ... and the Flexible String Representation In-Reply-To: <4ce85ea8-4a4c-46cf-a546-ad999576a5f7@googlegroups.com> References: <4ce85ea8-4a4c-46cf-a546-ad999576a5f7@googlegroups.com> Message-ID: <5229B82D.8000601@rece.vub.ac.be> Op 06-09-13 11:11, wxjmfauth at gmail.com schreef: > > The Flexible String Representation has conceptually to > face the same problem. It splits "unicode" in chunks and > it has to solve two problems at the same time, the coding > and the handling of multiple "char sets". The problem? Not true. The FSR always uses the same coding. An "A" is always coded as 65. -- Antoon Pardon From ned at nedbatchelder.com Fri Sep 6 07:02:56 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 06 Sep 2013 07:02:56 -0400 Subject: Chardet, file, ... and the Flexible String Representation In-Reply-To: <4ce85ea8-4a4c-46cf-a546-ad999576a5f7@googlegroups.com> References: <4ce85ea8-4a4c-46cf-a546-ad999576a5f7@googlegroups.com> Message-ID: <5229B660.7020304@nedbatchelder.com> On 9/6/13 5:11 AM, wxjmfauth at gmail.com wrote: > The Flexible String Representation has conceptually to > face the same problem. It splits "unicode" in chunks and > it has to solve two problems at the same time, the coding > and the handling of multiple "char sets". The problem? > It fails. Just once, please say *how* it fails. :( --Ned. From piet at vanoostrum.org Fri Sep 6 11:46:14 2013 From: piet at vanoostrum.org (Piet van Oostrum) Date: Fri, 06 Sep 2013 11:46:14 -0400 Subject: Chardet, file, ... and the Flexible String Representation References: <4ce85ea8-4a4c-46cf-a546-ad999576a5f7@googlegroups.com> Message-ID: wxjmfauth at gmail.com writes: > The Flexible String Representation has conceptually to > face the same problem. It splits "unicode" in chunks and > it has to solve two problems at the same time, the coding > and the handling of multiple "char sets". The problem? > It fails. > "This poor Flexible String Representation does not succeed > to solve the problem it create itsself." The FSR does not split unicode in chuncks. It does not create problems and therefore it doesn't have to solve this. The FSR simply stores a Unicode string as an array[*] of ints (the Unicode code points of the characters of the string. That's it. Then it uses a memory-efficient way to store this array of ints. But that has nothing to do with character sets. The same principle could be used for any array of ints. So you are seeking problems where there are none. And you would have a lot more peace of mind if you stopped doing this. [*] array in the C sense. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From rosuav at gmail.com Fri Sep 6 12:04:52 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 7 Sep 2013 02:04:52 +1000 Subject: Chardet, file, ... and the Flexible String Representation In-Reply-To: References: <4ce85ea8-4a4c-46cf-a546-ad999576a5f7@googlegroups.com> Message-ID: On Sat, Sep 7, 2013 at 1:46 AM, Piet van Oostrum wrote: > The FSR simply stores a Unicode string as an array[*] of ints (the Unicode code points of the characters of the string. That's it. Then it uses a memory-efficient way to store this array of ints. But that has nothing to do with character sets. The same principle could be used for any array of ints. Python does, in fact, store integers in different-sized blocks of memory according to size - though not for anything smaller than 32-bit. >>> sys.getsizeof(100) 14 >>> sys.getsizeof(1000000000000000000000000000000000) 28 So why this is suddenly a bad thing for characters is a mystery none but he can comprehend. ChrisA From random832 at fastmail.us Fri Sep 6 12:59:08 2013 From: random832 at fastmail.us (random832 at fastmail.us) Date: Fri, 06 Sep 2013 12:59:08 -0400 Subject: Chardet, file, ... and the Flexible String Representation In-Reply-To: References: <4ce85ea8-4a4c-46cf-a546-ad999576a5f7@googlegroups.com> Message-ID: <1378486748.10472.18800565.3DE728D7@webmail.messagingengine.com> On Fri, Sep 6, 2013, at 11:46, Piet van Oostrum wrote: > The FSR does not split unicode in chuncks. It does not create problems > and therefore it doesn't have to solve this. > > The FSR simply stores a Unicode string as an array[*] of ints (the > Unicode code points of the characters of the string. That's it. Then it > uses a memory-efficient way to store this array of ints. But that has > nothing to do with character sets. The same principle could be used for > any array of ints. I think the source of the confusion is that it is described in terms of UCS-2 and Latin-1, which people often think of (especially latin-1) as different encodings rather than merely storing code points in a narrower type. ---- Incidentally, how does all this interact with ctypes unicode_buffers, which slice as strings and must be UTF-16 on windows? This was fine pre-FSR when unicode objects were UTF-16, but I'm not sure how it would work now. From rosuav at gmail.com Fri Sep 6 13:04:59 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 7 Sep 2013 03:04:59 +1000 Subject: Chardet, file, ... and the Flexible String Representation In-Reply-To: <1378486748.10472.18800565.3DE728D7@webmail.messagingengine.com> References: <4ce85ea8-4a4c-46cf-a546-ad999576a5f7@googlegroups.com> <1378486748.10472.18800565.3DE728D7@webmail.messagingengine.com> Message-ID: On Sat, Sep 7, 2013 at 2:59 AM, wrote: > Incidentally, how does all this interact with ctypes unicode_buffers, > which slice as strings and must be UTF-16 on windows? This was fine > pre-FSR when unicode objects were UTF-16, but I'm not sure how it would > work now. That would be pre-FSR *with a Narrow build*, which was the default on Windows but not everywhere. But I don't know or use ctypes, so an answer to your actual question will have to come from someone else. ChrisA From random832 at fastmail.us Mon Sep 9 14:34:36 2013 From: random832 at fastmail.us (random832 at fastmail.us) Date: Mon, 09 Sep 2013 14:34:36 -0400 Subject: Chardet, file, ... and the Flexible String Representation In-Reply-To: References: <4ce85ea8-4a4c-46cf-a546-ad999576a5f7@googlegroups.com> <1378486748.10472.18800565.3DE728D7@webmail.messagingengine.com> Message-ID: <1378751676.20097.19809157.789868C5@webmail.messagingengine.com> On Fri, Sep 6, 2013, at 13:04, Chris Angelico wrote: > On Sat, Sep 7, 2013 at 2:59 AM, wrote: > > Incidentally, how does all this interact with ctypes unicode_buffers, > > which slice as strings and must be UTF-16 on windows? This was fine > > pre-FSR when unicode objects were UTF-16, but I'm not sure how it would > > work now. > > That would be pre-FSR *with a Narrow build*, which was the default on > Windows but not everywhere. But I don't know or use ctypes, so an > answer to your actual question will have to come from someone else. I did a couple tests - it works as well as can be expected for reading, but completely breaks for writing (due to sequence size checks not matching) From ian.g.kelly at gmail.com Mon Sep 9 15:03:43 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 9 Sep 2013 13:03:43 -0600 Subject: Chardet, file, ... and the Flexible String Representation In-Reply-To: <1378751676.20097.19809157.789868C5@webmail.messagingengine.com> References: <4ce85ea8-4a4c-46cf-a546-ad999576a5f7@googlegroups.com> <1378486748.10472.18800565.3DE728D7@webmail.messagingengine.com> <1378751676.20097.19809157.789868C5@webmail.messagingengine.com> Message-ID: On Sep 9, 2013 12:36 PM, wrote: > > On Fri, Sep 6, 2013, at 13:04, Chris Angelico wrote: > > On Sat, Sep 7, 2013 at 2:59 AM, wrote: > > > Incidentally, how does all this interact with ctypes unicode_buffers, > > > which slice as strings and must be UTF-16 on windows? This was fine > > > pre-FSR when unicode objects were UTF-16, but I'm not sure how it would > > > work now. > > > > That would be pre-FSR *with a Narrow build*, which was the default on > > Windows but not everywhere. But I don't know or use ctypes, so an > > answer to your actual question will have to come from someone else. > > I did a couple tests - it works as well as can be expected for reading, > but completely breaks for writing (due to sequence size checks not > matching) Do you mean that it breaks when overwriting Python string object buffers, or when overwriting arbitrary C strings either received from C code or created with create_unicode_buffer? If the former, I think that is to be expected since ctypes ultimately can't know what is the actual type of the pointer it was handed -- much as in C, that's up to the programmer to get right. I also think it's very bad practice to be overwriting those anyway, since Python strings are supposed to be immutable. If the latter, that sounds like a bug in ctypes to me. -------------- next part -------------- An HTML attachment was scrubbed... URL: From random832 at fastmail.us Mon Sep 9 15:27:55 2013 From: random832 at fastmail.us (random832 at fastmail.us) Date: Mon, 09 Sep 2013 15:27:55 -0400 Subject: Chardet, file, ... and the Flexible String Representation In-Reply-To: References: <4ce85ea8-4a4c-46cf-a546-ad999576a5f7@googlegroups.com> <1378486748.10472.18800565.3DE728D7@webmail.messagingengine.com> <1378751676.20097.19809157.789868C5@webmail.messagingengine.com> Message-ID: <1378754875.10227.19853781.2A750091@webmail.messagingengine.com> On Mon, Sep 9, 2013, at 15:03, Ian Kelly wrote: > Do you mean that it breaks when overwriting Python string object buffers, > or when overwriting arbitrary C strings either received from C code or > created with create_unicode_buffer? > > If the former, I think that is to be expected since ctypes ultimately > can't > know what is the actual type of the pointer it was handed -- much as in > C, > that's up to the programmer to get right. I also think it's very bad > practice to be overwriting those anyway, since Python strings are > supposed > to be immutable. > > If the latter, that sounds like a bug in ctypes to me. I was talking about writing to the buffer object from python, i.e. with slice assignment. >>> s = 'Test \U00010000' >>> len(s) 6 >>> buf = create_unicode_buffer(32) >>> buf[:6] = s TypeError: one character unicode string expected >>> buf[:7] = s ValueError: Can only assign sequence of same size >>> buf[:7] = 'Test \ud800\udc00' >>> buf[:7] 'Test \U00010000' # len = 6 Assigning with .value works, however, which may be a viable workaround for most situations. The "one character unicode string expected" message is a bit cryptic. From storchaka at gmail.com Wed Sep 11 17:11:38 2013 From: storchaka at gmail.com (Serhiy Storchaka) Date: Thu, 12 Sep 2013 00:11:38 +0300 Subject: Chardet, file, ... and the Flexible String Representation In-Reply-To: <1378754875.10227.19853781.2A750091@webmail.messagingengine.com> References: <4ce85ea8-4a4c-46cf-a546-ad999576a5f7@googlegroups.com> <1378486748.10472.18800565.3DE728D7@webmail.messagingengine.com> <1378751676.20097.19809157.789868C5@webmail.messagingengine.com> <1378754875.10227.19853781.2A750091@webmail.messagingengine.com> Message-ID: 09.09.13 22:27, random832 at fastmail.us ???????(??): > On Mon, Sep 9, 2013, at 15:03, Ian Kelly wrote: >> Do you mean that it breaks when overwriting Python string object buffers, >> or when overwriting arbitrary C strings either received from C code or >> created with create_unicode_buffer? >> >> If the former, I think that is to be expected since ctypes ultimately >> can't >> know what is the actual type of the pointer it was handed -- much as in >> C, >> that's up to the programmer to get right. I also think it's very bad >> practice to be overwriting those anyway, since Python strings are >> supposed >> to be immutable. >> >> If the latter, that sounds like a bug in ctypes to me. > > I was talking about writing to the buffer object from python, i.e. with > slice assignment. >>>> s = 'Test \U00010000' >>>> len(s) > 6 >>>> buf = create_unicode_buffer(32) >>>> buf[:6] = s > TypeError: one character unicode string expected >>>> buf[:7] = s > ValueError: Can only assign sequence of same size >>>> buf[:7] = 'Test \ud800\udc00' >>>> buf[:7] > 'Test \U00010000' # len = 6 > > Assigning with .value works, however, which may be a viable workaround > for most situations. The "one character unicode string expected" message > is a bit cryptic. Please report a bug on http://bugs.python.org/. From wxjmfauth at gmail.com Mon Sep 9 10:28:21 2013 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Mon, 9 Sep 2013 07:28:21 -0700 (PDT) Subject: Chardet, file, ... and the Flexible String Representation In-Reply-To: References: <4ce85ea8-4a4c-46cf-a546-ad999576a5f7@googlegroups.com> Message-ID: <04abbe99-ca1e-40b5-86c7-64b0e5d9de9c@googlegroups.com> Le vendredi 6 septembre 2013 17:46:14 UTC+2, Piet van Oostrum a ?crit?: > wxjmfauth at gmail.com writes: > > > > > The Flexible String Representation has conceptually to > > > face the same problem. It splits "unicode" in chunks and > > > it has to solve two problems at the same time, the coding > > > and the handling of multiple "char sets". The problem? > > > It fails. > > > "This poor Flexible String Representation does not succeed > > > to solve the problem it create itsself." > > > > The FSR does not split unicode in chuncks. It does not create problems and therefore it doesn't have to solve this. > > > > The FSR simply stores a Unicode string as an array[*] of ints (the Unicode code points of the characters of the string. That's it. Then it uses a memory-efficient way to store this array of ints. But that has nothing to do with character sets. The same principle could be used for any array of ints. > > > > So you are seeking problems where there are none. And you would have a lot more peace of mind if you stopped doing this. > > > > [*] array in the C sense. > > -- > > Piet van Oostrum > > WWW: http://pietvanoostrum.com/ > > PGP key: [8DAE142BE17999C4] ---------- Due to its nature, a character cann't be handled in the same way a one another type. That's the purpose of the UTF. ----- Chunk latin-1, perfomance ref: >>> timeit.timeit("a = 'hundred'; 'x' in a") 0.13144639994075646 >>> timeit.timeit("a = 'hundrez'; 'x' in a") 0.13780295544393084 Chunk ucs2, perfomance >>> timeit.timeit("a = 'hundre?'; 'x' in a") 0.23505392241617074 Chunk ucs4, perfomance >>> timeit.timeit("a = 'hundre\U0001d11e'; 'x' in a") 0.26266673650735584 Comment: Such differences never happen with utf. ----- Chunk latin-1, memory >>> sys.getsizeof('a') 26 Chunk ucs2, memory >>> sys.getsizeof('?') 40 Comment: 14 bytes more than latin-1 Chunk ucs4, memory >>> sys.getsizeof('\U0001d11e') 44 Comment: 18 bytes more than latin-1 Comment: With utf, a char (in string or not) never exceed 4 bytes. ----- 'a' + '?' in utf, conceptually Concatenate the *unicode tranformation units*. Some kind of a real direct 'a' + '?'. 'a' + '?' in FSR, conceptually 1) Check the "internal coding" of 'a' 2) Check the "internal coding" of '?' 3) Compare these codings 4a) If they match, concatenate the bytes 4b) If they do not match 5) Reencode the string which has to 6) Concatenate 7) Set the "internal coding" status for further processing ----- Complicate and full of side effects, eg : >>> sys.getsizeof('a') 26 >>> sys.getsizeof('a?') 39 Is not a latin-1 "?" supposed to count as a latin-1 "a" ? ---- I picked up random methods, there may be variations, basically this general behaviour is always expected. jmf From ned at nedbatchelder.com Mon Sep 9 12:38:26 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 09 Sep 2013 12:38:26 -0400 Subject: Chardet, file, ... and the Flexible String Representation In-Reply-To: <04abbe99-ca1e-40b5-86c7-64b0e5d9de9c@googlegroups.com> References: <4ce85ea8-4a4c-46cf-a546-ad999576a5f7@googlegroups.com> <04abbe99-ca1e-40b5-86c7-64b0e5d9de9c@googlegroups.com> Message-ID: <522DF982.7060106@nedbatchelder.com> On 9/9/13 10:28 AM, wxjmfauth at gmail.com wrote: > Le vendredi 6 septembre 2013 17:46:14 UTC+2, Piet van Oostrum a ?crit : >> wxjmfauth at gmail.com writes: >> >> >> >>> The Flexible String Representation has conceptually to >>> face the same problem. It splits "unicode" in chunks and >>> it has to solve two problems at the same time, the coding >>> and the handling of multiple "char sets". The problem? >>> It fails. >>> "This poor Flexible String Representation does not succeed >>> to solve the problem it create itsself." >> >> >> The FSR does not split unicode in chuncks. It does not create problems and therefore it doesn't have to solve this. >> >> >> >> The FSR simply stores a Unicode string as an array[*] of ints (the Unicode code points of the characters of the string. That's it. Then it uses a memory-efficient way to store this array of ints. But that has nothing to do with character sets. The same principle could be used for any array of ints. >> >> >> >> So you are seeking problems where there are none. And you would have a lot more peace of mind if you stopped doing this. >> >> >> >> [*] array in the C sense. >> >> -- >> >> Piet van Oostrum >> >> WWW: http://pietvanoostrum.com/ >> >> PGP key: [8DAE142BE17999C4] > ---------- > > > Due to its nature, a character cann't be handled in the > same way a one another type. That's the purpose of the UTF. > > ----- > > Chunk latin-1, perfomance > > ref: >>>> timeit.timeit("a = 'hundred'; 'x' in a") > 0.13144639994075646 > >>>> timeit.timeit("a = 'hundrez'; 'x' in a") > 0.13780295544393084 > > Chunk ucs2, perfomance > >>>> timeit.timeit("a = 'hundre?'; 'x' in a") > 0.23505392241617074 > > Chunk ucs4, perfomance > >>>> timeit.timeit("a = 'hundre\U0001d11e'; 'x' in a") > 0.26266673650735584 > > Comment: Such differences never happen with utf. > > ----- > > Chunk latin-1, memory > >>>> sys.getsizeof('a') > 26 > > Chunk ucs2, memory > >>>> sys.getsizeof('?') > 40 > > Comment: 14 bytes more than latin-1 > > Chunk ucs4, memory > >>>> sys.getsizeof('\U0001d11e') > 44 > > Comment: 18 bytes more than latin-1 > > Comment: With utf, a char (in string or not) never exceed 4 > > bytes. > > ----- > > 'a' + '?' in utf, conceptually > > Concatenate the *unicode tranformation units*. > Some kind of a real direct 'a' + '?'. > > > 'a' + '?' in FSR, conceptually > > 1) Check the "internal coding" of 'a' > 2) Check the "internal coding" of '?' > 3) Compare these codings > > 4a) If they match, concatenate the bytes > > 4b) If they do not match > 5) Reencode the string which has to > 6) Concatenate > 7) Set the "internal coding" status for > further processing > > ----- > > Complicate and full of side effects, eg : > >>>> sys.getsizeof('a') > 26 >>>> sys.getsizeof('a?') > 39 > > Is not a latin-1 "?" supposed to count as a latin-1 "a" ? > > ---- > > I picked up random methods, there may be variations, basically > this general behaviour is always expected. > > > jmf > jmf, thanks for your reply. You've calmed my fears that there is something wrong with the Flexible String Representation. None of the examples you show demonstrate any behavior contrary to the Unicode spec. --Ned. From tjreedy at udel.edu Mon Sep 9 16:47:43 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 09 Sep 2013 16:47:43 -0400 Subject: Chardet, file, ... and the Flexible String Representation In-Reply-To: <522DF982.7060106@nedbatchelder.com> References: <4ce85ea8-4a4c-46cf-a546-ad999576a5f7@googlegroups.com> <04abbe99-ca1e-40b5-86c7-64b0e5d9de9c@googlegroups.com> <522DF982.7060106@nedbatchelder.com> Message-ID: On 9/9/2013 12:38 PM, Ned Batchelder wrote: > jmf, thanks for your reply. You've calmed my fears that there is > something wrong with the Flexible String Representation. None of the > examples you show demonstrate any behavior contrary to the Unicode spec. The goals of the new unicode implementation: 1. one implementation on all platforms, working the same on all platforms. 2. works correctly 3. O(1) indexing 4. save as much space as sensibly possible 5. not too much time penalty for the space saving. The new implementation succeeded on all points. It exceeded the goal for 5. With much optimization work, there essentially is no overall time penalty left. Jmf's size examples show success with respect to goal 4. He apparently disagrees with that goal and would replace it with something else. At least some of his time examples show that saving space can save time, as was predicted when the FSR was being developed. -- Terry Jan Reedy From torriem at gmail.com Mon Sep 9 13:05:44 2013 From: torriem at gmail.com (Michael Torrie) Date: Mon, 09 Sep 2013 11:05:44 -0600 Subject: Chardet, file, ... and the Flexible String Representation In-Reply-To: <04abbe99-ca1e-40b5-86c7-64b0e5d9de9c@googlegroups.com> References: <4ce85ea8-4a4c-46cf-a546-ad999576a5f7@googlegroups.com> <04abbe99-ca1e-40b5-86c7-64b0e5d9de9c@googlegroups.com> Message-ID: <522DFFE8.4070608@gmail.com> On 09/09/2013 08:28 AM, wxjmfauth at gmail.com wrote: > Comment: Such differences never happen with utf. But with utf, slicing strings is O(n) (well that's a simplification as someone showed an algorithm that is log n), whereas a fixed-width encoding (Latin-1, UCS-2, UCS-4) is O(1). Do you understand what this means? > Complicate and full of side effects, eg : > >>>> sys.getsizeof('a') > 26 >>>> sys.getsizeof('a?') > 39 Why on earth are you doing getsizeof? What are you expecting to prove? Why are you even trying to concern yourself with implementation details? As a programmer you should deal with unicode. Period. All you should care about is that you can properly index or slice a unicode string and that unicode strings can be operated on at a reasonable speed. IE string[4] should give you the character at position 4. len(string) should return the length of the string in *characters*. The byte encoding used behind the scenes is of no consequence other than speed (and you have not shown any problem with speed). > > Is not a latin-1 "?" supposed to count as a latin-1 "a" ? Of course it does. 'a?'[0] == 'a' and 'a?'[1] == '?'. len('a?') returns 2. > I picked up random methods, there may be variations, basically > this general behaviour is always expected. Eh? Can you point to something in the unicode spec that doesn't work? I don't even know that much about unicode yet it's clear you're either deliberately muddying the waters with your stupid and pointless arguments against FCS or you don't really understand the difference between unicode and byte encoding. Which is it? From steve at pearwood.info Tue Sep 10 00:58:41 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 10 Sep 2013 04:58:41 GMT Subject: Chardet, file, ... and the Flexible String Representation References: <4ce85ea8-4a4c-46cf-a546-ad999576a5f7@googlegroups.com> <04abbe99-ca1e-40b5-86c7-64b0e5d9de9c@googlegroups.com> Message-ID: <522ea700$0$29999$c3e8da3$5496439d@news.astraweb.com> On Mon, 09 Sep 2013 11:05:44 -0600, Michael Torrie wrote: > On 09/09/2013 08:28 AM, wxjmfauth at gmail.com wrote: >> Comment: Such differences never happen with utf. > > But with utf, slicing strings is O(n) (well that's a simplification as > someone showed an algorithm that is log n), whereas a fixed-width > encoding (Latin-1, UCS-2, UCS-4) is O(1). UTF-32 is fixed-width. UTF-16 is not, but if you limit yourself to only characters in the Basic Multilingual Plane, it is functionally equivalent to UCS-2 and therefore fixed-width. > Do you understand what this means? Talking about "utf" in general as JMF does is a good sign that he doesn't. Which UTF? I know of at least eight: UTF-1 UTF-7 UTF-8 UTF-9 # this one is a joke, but it does work UTF-16 # in two varieties, big-endian and little-endian UTF-18 # another joke UTF-32 # likewise two varieties UTF-EBCDIC although only 3 (perhaps 4, if you include UTF-7) are in common use. [...] > I don't even know that much about unicode yet it's clear you're either > deliberately muddying the waters with your stupid and pointless > arguments against FCS or you don't really understand the difference > between unicode and byte encoding. Which is it? I have been watching JMF get a mad-on about the flexible string representation since he first noticed it, and in my opinion, his complaints are based entirely on resentment that ASCII users save more memory than non-ASCII users. Even if it means everyone is worse off, he is utterly opposed to giving ASCII users any benefit. Of course, he neglects to consider that *every single Python user* is an ASCII user, since most strings in Python are pure ASCII. Names of builtins, standard library modules, variables, attributes, most of them are ASCII. -- Steven From random832 at fastmail.us Tue Sep 10 11:36:33 2013 From: random832 at fastmail.us (random832 at fastmail.us) Date: Tue, 10 Sep 2013 11:36:33 -0400 Subject: Chardet, file, ... and the Flexible String Representation In-Reply-To: <04abbe99-ca1e-40b5-86c7-64b0e5d9de9c@googlegroups.com> References: <4ce85ea8-4a4c-46cf-a546-ad999576a5f7@googlegroups.com> <04abbe99-ca1e-40b5-86c7-64b0e5d9de9c@googlegroups.com> Message-ID: <1378827393.10095.20226209.018269F4@webmail.messagingengine.com> On Mon, Sep 9, 2013, at 10:28, wxjmfauth at gmail.com wrote: *time performance differences* > > Comment: Such differences never happen with utf. Why is this bad? Keeping in mind that otherwise they would all be almost as slow as the UCS-4 case. > >>> sys.getsizeof('a') > 26 > >>> sys.getsizeof('?') > 40 > >>> sys.getsizeof('\U0001d11e') > 44 > > Comment: 18 bytes more than latin-1 > > Comment: With utf, a char (in string or not) never exceed 4 A string is an object and needs to store the length, along with any overhead relating to object headers. I believe there is also an appended null character. Also, ASCII strings are stored differently from Latin-1 strings. >>> sys.getsizeof('a'*999) 1048 = 49 bytes overhead, 1 byte per character. >>> sys.getsizeof('\xa4'*999) 1072 = 74 bytes overhead, 1 byte per character. >>> sys.getsizeof('\u20ac'*999) 2072 = 76 bytes overhead, 2 bytes per character. >>> sys.getsizeof('\U0001d11e'*999) 4072 = 80 bytes overhead, 4 bytes per character. (I bet sys.getsizeof('\xa4') will return 38 on your system, so 44 is only six bytes more, not 18) If we did not have the FSR, everything would be 4 bytes per character. We might have less overhead, but a string only has to be 25 characters long before the savings from the shorter representation outweigh even having _no_ overhead, and every four bytes of overhead reduces that number by one. And you have a 32-bit python build, which has less overhead than mine - in yours, strings only have to be seven characters long for the FSR to be worth it. Assume the minimum possible overhead is two words for the object header, a size, and a pointer - i.e. sixteen bytes, compared to the 25 you've demonstrated for ASCII, and strings only need to be _two_ characters long for the FSR to be a better deal than always using UCS4 strings. The need for four-byte-per-character strings would not go away by eliminating the FSR, so you're basically saying that everything should be constrained to the worst-case performance scenario. From leo.carnovale at gmail.com Fri Sep 6 06:20:02 2013 From: leo.carnovale at gmail.com (leo.carnovale at gmail.com) Date: Fri, 6 Sep 2013 03:20:02 -0700 (PDT) Subject: file handling issues Message-ID: I am making this little game and I am trying to make some sort of script that does the following: >Checks to see if a file exists >If it does, check the numbers in it >If it doesn't, make one and fill it with some numbers >Sorts out if the numbers in the file are in the right format >If they are, then store them >If not, remake it again >THEN, check if there is a pass. >If there is, check if it fits the key and go on if so >If not, ask for a new one, check it, go on if its correct. Every time I run it, it says the key is 0!? I can not for the life of me figure out what it is doing. The code: Thanks Leo From leo.carnovale at gmail.com Fri Sep 6 06:22:48 2013 From: leo.carnovale at gmail.com (leo.carnovale at gmail.com) Date: Fri, 6 Sep 2013 03:22:48 -0700 (PDT) Subject: file handling issues In-Reply-To: References: Message-ID: On Friday, 6 September 2013 20:20:02 UTC+10, leo.ca... at gmail.com wrote: > I am making this little game and I am trying to make some sort of script that does the following: > > >Checks to see if a file exists > > >If it does, check the numbers in it > > >If it doesn't, make one and fill it with some numbers > > >Sorts out if the numbers in the file are in the right format > > >If they are, then store them > > >If not, remake it again > > >THEN, check if there is a pass. > > >If there is, check if it fits the key and go on if so > > >If not, ask for a new one, check it, go on if its correct. > > > > Every time I run it, it says the key is 0!? > > I can not for the life of me figure out what it is doing. > > > > The code: > > > > > > Thanks > > > > Leo Probably should also mention this, The KEY is what the user is presented with, and to use the program, they must enter a corresponding PASS which is created with a special manipulator that I made. From piet at vanoostrum.org Fri Sep 6 12:17:03 2013 From: piet at vanoostrum.org (Piet van Oostrum) Date: Fri, 06 Sep 2013 12:17:03 -0400 Subject: file handling issues References: Message-ID: leo.carnovale at gmail.com writes: > I am making this little game and I am trying to make some sort of script that does the following: >>Checks to see if a file exists > >If it does, check the numbers in it > >If it doesn't, make one and fill it with some numbers >>Sorts out if the numbers in the file are in the right format > >If they are, then store them > >If not, remake it again >>THEN, check if there is a pass. > >If there is, check if it fits the key and go on if so > >If not, ask for a new one, check it, go on if its correct. > > Every time I run it, it says the key is 0!? > I can not for the life of me figure out what it is doing. > > The code: > > What a mess is that code. First that messing around with the key is crazy. You probably want to do some crypto on it, but why don't you just use some standard crypto algorithm? The you have defined T as True and F as False, but sometimes you use T and sometimes True, and as far as I can see you never use F. Just stay with True and false as it makes the code more readable. Once you use "with open('Key')", all other case you use f = open('Key',...) f.read() or f.write() f.close() Be consistenst and use always "with open..." There are at least three palces where you write a key to the file. Make a function for this; it makes your code more structured. And please, put spaces aroud the = signs. Now the real problem: if newpas: f=open("Key","w") print("No pass found!") print("Your wonderful key is: ",int(keys[0])) pasw=input("What is your pass? : ") elif newkey: f=open("Key","w") Here you open the file for writing but you never write anything to it. This makes the file empty. And apparently you do not check this the next time you open it. If you would have used a function to write a key to the file, this probably would not have occurred. if mess_with(keys[0])==pasw: hesin=1 print("Your in!") f=open("Key","w") Here you open the file again with the same variable. This causes the old value to be lost and the file probably to be closed. Just messy. print("writing %s" % str(keys[0])+pasw) f.write(str(keys[0])+pasw) f.close() else: hesin=0 And how are people supposed to guess an 8 character password? Are they supposed to do that weird calculation on their calculators or some such? -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From leo.carnovale at gmail.com Fri Sep 6 23:03:14 2013 From: leo.carnovale at gmail.com (Leo Carnovale) Date: Fri, 6 Sep 2013 20:03:14 -0700 (PDT) Subject: file handling issues In-Reply-To: References: Message-ID: <43df7574-a7cd-45e2-a067-ae9c83c3a720@googlegroups.com> On Saturday, 7 September 2013 02:17:03 UTC+10, Piet van Oostrum wrote: > leo.carnovale at gmail.com writes: > > > > > I am making this little game and I am trying to make some sort of script that does the following: > > >>Checks to see if a file exists > > > >If it does, check the numbers in it > > > >If it doesn't, make one and fill it with some numbers > > >>Sorts out if the numbers in the file are in the right format > > > >If they are, then store them > > > >If not, remake it again > > >>THEN, check if there is a pass. > > > >If there is, check if it fits the key and go on if so > > > >If not, ask for a new one, check it, go on if its correct. > > > > > > Every time I run it, it says the key is 0!? > > > I can not for the life of me figure out what it is doing. > > > > > > The code: > > > > > > > > > > What a mess is that code. First that messing around with the key is > > crazy. You probably want to do some crypto on it, but why don't you just > > use some standard crypto algorithm? > > > > The you have defined T as True and F as False, but sometimes you use T > > and sometimes True, and as far as I can see you never use F. Just stay > > with True and false as it makes the code more readable. > > > > Once you use "with open('Key')", all other case you use > > f = open('Key',...) > > f.read() or f.write() > > f.close() > > > > Be consistenst and use always "with open..." > > > > There are at least three palces where you write a key to the file. Make > > a function for this; it makes your code more structured. > > > > And please, put spaces aroud the = signs. > > > > Now the real problem: > > > > if newpas: > > f=open("Key","w") > > print("No pass found!") > > print("Your wonderful key is: ",int(keys[0])) > > pasw=input("What is your pass? : ") > > elif newkey: > > f=open("Key","w") > > > > Here you open the file for writing but you never write anything to it. > > This makes the file empty. And apparently you do not check this the next > > time you open it. If you would have used a function to write a key to > > the file, this probably would not have occurred. > > > > if mess_with(keys[0])==pasw: > > hesin=1 > > print("Your in!") > > f=open("Key","w") > > > > Here you open the file again with the same variable. This causes the old > > value to be lost and the file probably to be closed. Just messy. > > > > print("writing %s" % str(keys[0])+pasw) > > f.write(str(keys[0])+pasw) > > f.close() > > else: > > hesin=0 > > > > And how are people supposed to guess an 8 character password? Are they > > supposed to do that weird calculation on their calculators or some such? > > > > -- > > Piet van Oostrum > > WWW: http://pietvanoostrum.com/ > > PGP key: [8DAE142BE17999C4] Yes the code is a mess, I have been tempted to re write the whole thing... The reason for the messiness is firstly because I am relatively new to programming and because this is the result of me tinkering around with previous code, which was still messy, but cleaner than this. So the open("key","w") clears the file straight away? That helps a lot, thanks, this will definitely save me a lot of time in the future. Also the user doesn't guess the pass, I would give it to them. After they enter it, they go on to the guessing game (not shown in the code). Thanks for the help! Leo From leo.carnovale at gmail.com Fri Sep 6 23:05:15 2013 From: leo.carnovale at gmail.com (Leo Carnovale) Date: Fri, 6 Sep 2013 20:05:15 -0700 (PDT) Subject: file handling issues In-Reply-To: <43df7574-a7cd-45e2-a067-ae9c83c3a720@googlegroups.com> References: <43df7574-a7cd-45e2-a067-ae9c83c3a720@googlegroups.com> Message-ID: <41b6c459-ea3b-4714-9c52-fa916bd5c15c@googlegroups.com> On Saturday, 7 September 2013 13:03:14 UTC+10, Leo Carnovale wrote: > On Saturday, 7 September 2013 02:17:03 UTC+10, Piet van Oostrum wrote: > > > leo.carnovale at gmail.com writes: > > > > > > > > > > > > > I am making this little game and I am trying to make some sort of script that does the following: > > > > > > >>Checks to see if a file exists > > > > > > > >If it does, check the numbers in it > > > > > > > >If it doesn't, make one and fill it with some numbers > > > > > > >>Sorts out if the numbers in the file are in the right format > > > > > > > >If they are, then store them > > > > > > > >If not, remake it again > > > > > > >>THEN, check if there is a pass. > > > > > > > >If there is, check if it fits the key and go on if so > > > > > > > >If not, ask for a new one, check it, go on if its correct. > > > > > > > > > > > > > > Every time I run it, it says the key is 0!? > > > > > > > I can not for the life of me figure out what it is doing. > > > > > > > > > > > > > > The code: > > > > > > > > > > > > > > > > > > > > > > > > > > What a mess is that code. First that messing around with the key is > > > > > > crazy. You probably want to do some crypto on it, but why don't you just > > > > > > use some standard crypto algorithm? > > > > > > > > > > > > The you have defined T as True and F as False, but sometimes you use T > > > > > > and sometimes True, and as far as I can see you never use F. Just stay > > > > > > with True and false as it makes the code more readable. > > > > > > > > > > > > Once you use "with open('Key')", all other case you use > > > > > > f = open('Key',...) > > > > > > f.read() or f.write() > > > > > > f.close() > > > > > > > > > > > > Be consistenst and use always "with open..." > > > > > > > > > > > > There are at least three palces where you write a key to the file. Make > > > > > > a function for this; it makes your code more structured. > > > > > > > > > > > > And please, put spaces aroud the = signs. > > > > > > > > > > > > Now the real problem: > > > > > > > > > > > > if newpas: > > > > > > f=open("Key","w") > > > > > > print("No pass found!") > > > > > > print("Your wonderful key is: ",int(keys[0])) > > > > > > pasw=input("What is your pass? : ") > > > > > > elif newkey: > > > > > > f=open("Key","w") > > > > > > > > > > > > Here you open the file for writing but you never write anything to it. > > > > > > This makes the file empty. And apparently you do not check this the next > > > > > > time you open it. If you would have used a function to write a key to > > > > > > the file, this probably would not have occurred. > > > > > > > > > > > > if mess_with(keys[0])==pasw: > > > > > > hesin=1 > > > > > > print("Your in!") > > > > > > f=open("Key","w") > > > > > > > > > > > > Here you open the file again with the same variable. This causes the old > > > > > > value to be lost and the file probably to be closed. Just messy. > > > > > > > > > > > > print("writing %s" % str(keys[0])+pasw) > > > > > > f.write(str(keys[0])+pasw) > > > > > > f.close() > > > > > > else: > > > > > > hesin=0 > > > > > > > > > > > > And how are people supposed to guess an 8 character password? Are they > > > > > > supposed to do that weird calculation on their calculators or some such? > > > > > > > > > > > > -- > > > > > > Piet van Oostrum > > > > > > WWW: http://pietvanoostrum.com/ > > > > > > PGP key: [8DAE142BE17999C4] > > > > Yes the code is a mess, I have been tempted to re write the whole thing... > > The reason for the messiness is firstly because I am relatively new to programming and because this is the result of me tinkering around with previous code, which was still messy, but cleaner than this. > > > > So the open("key","w") clears the file straight away? That helps a lot, thanks, this will definitely save me a lot of time in the future. Also the user doesn't guess the pass, I would give it to them. After they enter it, they go on to the guessing game (not shown in the code). > > > > Thanks for the help! > > > > Leo Ah and one other thing! What is this crypto algorithm you speak of? I desperately need some sort of encryption as at the moment anyone can simply open the text file and change the numbers to numbers that work! Where can I learn more about it? From torriem at gmail.com Fri Sep 6 23:58:43 2013 From: torriem at gmail.com (Michael Torrie) Date: Fri, 06 Sep 2013 21:58:43 -0600 Subject: file handling issues In-Reply-To: <41b6c459-ea3b-4714-9c52-fa916bd5c15c@googlegroups.com> References: <43df7574-a7cd-45e2-a067-ae9c83c3a720@googlegroups.com> <41b6c459-ea3b-4714-9c52-fa916bd5c15c@googlegroups.com> Message-ID: <522AA473.8070600@gmail.com> On 09/06/2013 09:05 PM, Leo Carnovale wrote: > Ah and one other thing! What is this crypto algorithm you speak of? I > desperately need some sort of encryption as at the moment anyone can > simply open the text file and change the numbers to numbers that > work! Where can I learn more about it? There are two kinds of cryptography, generally. Symmetric and asymmetric. Your needs will dictate which system you use. Symmetric cryptography means that the sake encryption key that was used to encrypt the data is used to decrypt it. Asymmetric cryptography basically means one key is used to encrypt a message and another key is used to decrypt the message. In your case, perhaps symmetric encryption is most logical, though I'm not at all clear what you are doing. However you'll have to embed the encryption key in your python source code, which isn't hidden at all. And actually any program that embeds a symmetric key in its code can be cracked rather easily. Python has many libraries to support encryption. Some are in the standard library. Search for python and crypto to see what docs are available. You might want to read up on basic cryptography principles as well. From leo.carnovale at gmail.com Sat Sep 7 02:22:47 2013 From: leo.carnovale at gmail.com (Leo Carnovale) Date: Fri, 6 Sep 2013 23:22:47 -0700 (PDT) Subject: file handling issues In-Reply-To: References: <43df7574-a7cd-45e2-a067-ae9c83c3a720@googlegroups.com> <41b6c459-ea3b-4714-9c52-fa916bd5c15c@googlegroups.com> Message-ID: <7c29fe93-9437-4de8-b5e5-9730d2cbb20f@googlegroups.com> On Saturday, 7 September 2013 13:58:43 UTC+10, Michael Torrie wrote: > On 09/06/2013 09:05 PM, Leo Carnovale wrote: > > > Ah and one other thing! What is this crypto algorithm you speak of? I > > > desperately need some sort of encryption as at the moment anyone can > > > simply open the text file and change the numbers to numbers that > > > work! Where can I learn more about it? > > > > There are two kinds of cryptography, generally. Symmetric and > > asymmetric. Your needs will dictate which system you use. Symmetric > > cryptography means that the sake encryption key that was used to encrypt > > the data is used to decrypt it. Asymmetric cryptography basically means > > one key is used to encrypt a message and another key is used to decrypt > > the message. > > > > In your case, perhaps symmetric encryption is most logical, though I'm > > not at all clear what you are doing. However you'll have to embed the > > encryption key in your python source code, which isn't hidden at all. > > And actually any program that embeds a symmetric key in its code can be > > cracked rather easily. > > > > Python has many libraries to support encryption. Some are in the > > standard library. Search for python and crypto to see what docs are > > available. You might want to read up on basic cryptography principles > > as well. Thanks! Obviously, I need to do a lot of research. From piet at vanoostrum.org Sat Sep 7 15:33:02 2013 From: piet at vanoostrum.org (Piet van Oostrum) Date: Sat, 07 Sep 2013 15:33:02 -0400 Subject: file handling issues References: <43df7574-a7cd-45e2-a067-ae9c83c3a720@googlegroups.com> <41b6c459-ea3b-4714-9c52-fa916bd5c15c@googlegroups.com> Message-ID: Leo Carnovale writes: > Ah and one other thing! > What is this crypto algorithm you speak of? I desperately need some sort of encryption as at the moment anyone can simply open the text file and change the numbers to numbers that work! > Where can I learn more about it? You can google for cryptography or look in Wikipedia. Now the question is: will this game be played through the internet or on someone's computer? If it is run on a computer then both the program and the keyfile will be on that computer, so whatever algorithm you use the user can use it either to detect the password derived from the key or choose his own password and generate the corresponding key and put it in the file. Or even change the program and take the check out. You could use some obfuscation to make it difficult, like they do in DRM but basically you cannot hode it from the user. If you use an internet connection then of course you can keep the relevant data outside of the reach of the user. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From stascrash at gmail.com Fri Sep 6 11:00:13 2013 From: stascrash at gmail.com (stas poritskiy) Date: Fri, 6 Sep 2013 08:00:13 -0700 (PDT) Subject: how to trouble shoot - RuntimeError: Open Failed Message-ID: <8e84343f-1eff-4ed4-bfa7-aaf5755b5114@googlegroups.com> hey guys, I am working on application. App is processing a list of files in folders. Folders act as a NEW-LOOP. so if all files in one folder had been worked on, file is then saved and next folder is picked up. it works fine only if i have a SINGLE folder, however, when another folder is there, i get this RuntimeError: Open Failed. I checked if those could be the files by leaving only single (another folder), however all was fine. Questions - How can i trouble shoot what is causing the problem? i don't know where to begin. Thanks! From steve+comp.lang.python at pearwood.info Fri Sep 6 11:27:14 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Sep 2013 15:27:14 GMT Subject: how to trouble shoot - RuntimeError: Open Failed References: <8e84343f-1eff-4ed4-bfa7-aaf5755b5114@googlegroups.com> Message-ID: <5229f452$0$29988$c3e8da3$5496439d@news.astraweb.com> On Fri, 06 Sep 2013 08:00:13 -0700, stas poritskiy wrote: > hey guys, > I am working on application. App is processing a list of files in > folders. Folders act as a NEW-LOOP. so if all files in one folder had > been worked on, file is then saved and next folder is picked up. it > works fine only if i have a SINGLE folder, however, when another folder > is there, i get this RuntimeError: Open Failed. I checked if those could > be the files by leaving only single (another folder), however all was > fine. Questions - How can i trouble shoot what is causing the problem? i > don't know where to begin. You should ALWAYS begin with the entire traceback, not just the last line. Everything starting with: Traceback (most recent call last): and ending with the last line, which in your case will be something like "RuntimeError: Open failed". The most important part is that the traceback will actually show you the line that fails. Secondly, whose code is this? I assume it is code you have written. In that case, do you have something like this in your code? try: blah blah blah # whatever, doesn't matter what this is except: raise RuntimeError("Open failed") If so, take it out immediately! All you are doing is catching a *useful* exception that Python generates, and replacing it with an utterly useless exception that does nothing but hide the true cause of the problem and make debugging much more difficult. That will do to start. If you still need help, please copy and paste the entire traceback. Also, demonstrating a *minimal* amount of code that causes this error will help. Although this is written for Java programmers, the same principles apply to Python code too: http://sscce.org/ -- Steven From neilc at norwich.edu Fri Sep 6 11:39:04 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 6 Sep 2013 15:39:04 GMT Subject: how to trouble shoot - RuntimeError: Open Failed References: <8e84343f-1eff-4ed4-bfa7-aaf5755b5114@googlegroups.com> Message-ID: On 2013-09-06, stas poritskiy wrote: > I am working on application. App is processing a list of files > in folders. Folders act as a NEW-LOOP. so if all files in one > folder had been worked on, file is then saved and next folder > is picked up. it works fine only if i have a SINGLE folder, > however, when another folder is there, i get this RuntimeError: > Open Failed. I checked if those could be the files by leaving > only single (another folder), however all was fine. Questions - > How can i trouble shoot what is causing the problem? i don't > know where to begin. We can help better if you show some of your code; a minimal cut-down version that exhibits the error is ideal. Are you literally getting a RuntimeError? That would be weird. -- Neil Cerutti From stascrash at gmail.com Fri Sep 6 13:05:41 2013 From: stascrash at gmail.com (stas poritskiy) Date: Fri, 6 Sep 2013 10:05:41 -0700 (PDT) Subject: how to trouble shoot - RuntimeError: Open Failed In-Reply-To: References: <8e84343f-1eff-4ed4-bfa7-aaf5755b5114@googlegroups.com> Message-ID: <3d5be177-cda2-4612-9117-a2ed9a448f6d@googlegroups.com> The code in development is mine, and i am using the API provided by a main developer. At the moment, i am not using any try/except functionality. here is the full Exception output: [CODE] Exception in Tkinter callback Traceback (most recent call last): File "C:\Python27\32bit\lib\lib-tk\Tkinter.py", line 1470, in __call__ return self.func(*args) File "E:\sporitskiy\HON\Project\scene7\s7operator\gui.py", line 59, in cmd1 = lambda: vntProcessor.colData(folders.path, folders.subFolders) File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 184, in colData setVars() File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 79, in __call__ self.batchFiles() File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 55, in batchFiles self.vntConnect.createVNTobjects(self.vntObjMgroup.keyList, self.vntLtoF.keyValList, self.vntObjFile.keyList, myPath) File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 113, in createVNTobjects self.createImage(groupName, layerName, fileName, imagePath, self.vntGroups) File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 137, in createImage img = open_image(imageFile) File "", line 2, in open_image File "C:\Python27\32bit\lib\site-packages\s7vampy\arg_validator.py", line 213, in __call__ return func(*args, **keywords) File "C:\Python27\32bit\lib\site-packages\s7vampy\image.py", line 181, in open_image return Image(_S7VAM_IMAGE.Open(filename)) RuntimeError: Open Failed: 'C:/Users/sporitskiy/Desktop/Practice/HIWM2MSB/hiwm2mpa_upholstery_esq_leather_ro_12_0001.tif' [/CODE] -- Just a few words on what this all does -- Structure: 3 modules Module 1 - dataPreparation.py -responsible for string processing - made of several classes and methods that receive PATH to directory, collect all files in a LIST, after that for each file based on type of file name it sorts it out to appropriate categories that can be accessed through class instances. Module 2 - gui.py - Responsible for GUI. It crates a simple GUi-layout that offer BROWSE button (to get the PATH), QUIT button to exit application, LISTBOX that lists subfolders from the PATH, and BATCH button that must execute the main processor. Module 3 - vntProcessor.py - Responsible for processing of collected data. This module is based of an API of another application. It receives the values from the BATCH-button and invokes specific methods based on sorting that was performed using MODULE 1. My approach: i created an instance of GUI and call it to start interface ( have a window open) in the interface, i browse for specific folder, so my PATH variable is set. my list box is populated with subfolders.(using Tkinter for gui) my next step should be to press the BATCH folder and forward all of the values (PATH and ARRAY of SUBFOLDERS) to my Module 3 (processor). and as soon as my script tries to open NEXT FOLDER is when i get this RuntimeError, but if i leave the same folder by itself - everything is fine. If by looking at the Exception Log i posted, you could tell me what portion of the code i should show here - it would be very helpful. thanks! On Friday, September 6, 2013 10:39:04 AM UTC-5, Neil Cerutti wrote: > On 2013-09-06, stas poritskiy wrote: > > > I am working on application. App is processing a list of files > > > in folders. Folders act as a NEW-LOOP. so if all files in one > > > folder had been worked on, file is then saved and next folder > > > is picked up. it works fine only if i have a SINGLE folder, > > > however, when another folder is there, i get this RuntimeError: > > > Open Failed. I checked if those could be the files by leaving > > > only single (another folder), however all was fine. Questions - > > > How can i trouble shoot what is causing the problem? i don't > > > know where to begin. > > > > We can help better if you show some of your code; a minimal > > cut-down version that exhibits the error is ideal. > > > > Are you literally getting a RuntimeError? That would be weird. > > > > -- > > Neil Cerutti From tjreedy at udel.edu Fri Sep 6 14:49:57 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 06 Sep 2013 14:49:57 -0400 Subject: how to trouble shoot - RuntimeError: Open Failed In-Reply-To: <3d5be177-cda2-4612-9117-a2ed9a448f6d@googlegroups.com> References: <8e84343f-1eff-4ed4-bfa7-aaf5755b5114@googlegroups.com> <3d5be177-cda2-4612-9117-a2ed9a448f6d@googlegroups.com> Message-ID: On 9/6/2013 1:05 PM, stas poritskiy wrote: > The code in development is mine, and i am using the API provided by a main developer. > > At the moment, i am not using any try/except functionality. > > here is the full Exception output: > [CODE] > Exception in Tkinter callback > Traceback (most recent call last): > File "C:\Python27\32bit\lib\lib-tk\Tkinter.py", line 1470, in __call__ > return self.func(*args) > File "E:\sporitskiy\HON\Project\scene7\s7operator\gui.py", line 59, in > cmd1 = lambda: vntProcessor.colData(folders.path, folders.subFolders) > File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 184, in colData > setVars() > File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 79, in __call__ > self.batchFiles() > File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 55, in batchFiles > self.vntConnect.createVNTobjects(self.vntObjMgroup.keyList, self.vntLtoF.keyValList, self.vntObjFile.keyList, myPath) > File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 113, in createVNTobjects > self.createImage(groupName, layerName, fileName, imagePath, self.vntGroups) > File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 137, in createImage > img = open_image(imageFile) > File "", line 2, in open_image > File "C:\Python27\32bit\lib\site-packages\s7vampy\arg_validator.py", line 213, in __call__ > return func(*args, **keywords) > File "C:\Python27\32bit\lib\site-packages\s7vampy\image.py", line 181, in open_image > return Image(_S7VAM_IMAGE.Open(filename)) > RuntimeError: Open Failed: 'C:/Users/sporitskiy/Desktop/Practice/HIWM2MSB/hiwm2mpa_upholstery_esq_leather_ro_12_0001.tif' We were confused because the failed open should be an IOError. If Image is indeed converting such to RuntimeError, it should not. It should just let the original error bubble up. It is possibly tossing information in the process. The first thing I would do is to look at the code around that line in image.py and remove the exception replacement if there is one. -- Terry Jan Reedy From stascrash at gmail.com Fri Sep 6 15:28:05 2013 From: stascrash at gmail.com (stas poritskiy) Date: Fri, 6 Sep 2013 12:28:05 -0700 (PDT) Subject: how to trouble shoot - RuntimeError: Open Failed In-Reply-To: References: <8e84343f-1eff-4ed4-bfa7-aaf5755b5114@googlegroups.com> <3d5be177-cda2-4612-9117-a2ed9a448f6d@googlegroups.com> Message-ID: <1fcd9616-adeb-4184-aeca-92038841fb3b@googlegroups.com> Guys, as i was writing a very detailed message with code samples, following the guide that Steven linked, i found the problem. a pretty lame one, actually. in my class that was processing the images, i created an object instance, via __INIT__ , self.data = attributes() but i was iterating through list of folders, so object was filled with the correct data, but it was never re-initialized for the new one. i move my objects into a function, and called the function on each loop-start, so objects are re-created and re-filled with the data. Terry, yeah, your confusion was right, and pointing out that i was supposed to get IOError. that lead me to inspect code again and again :) anyways, thanks and sorry for the mess ) On Friday, September 6, 2013 1:49:57 PM UTC-5, Terry Reedy wrote: > On 9/6/2013 1:05 PM, stas poritskiy wrote: > > > The code in development is mine, and i am using the API provided by a main developer. > > > > > > At the moment, i am not using any try/except functionality. > > > > > > here is the full Exception output: > > > [CODE] > > > Exception in Tkinter callback > > > Traceback (most recent call last): > > > File "C:\Python27\32bit\lib\lib-tk\Tkinter.py", line 1470, in __call__ > > > return self.func(*args) > > > File "E:\sporitskiy\HON\Project\scene7\s7operator\gui.py", line 59, in > > > cmd1 = lambda: vntProcessor.colData(folders.path, folders.subFolders) > > > File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 184, in colData > > > setVars() > > > File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 79, in __call__ > > > self.batchFiles() > > > File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 55, in batchFiles > > > self.vntConnect.createVNTobjects(self.vntObjMgroup.keyList, self.vntLtoF.keyValList, self.vntObjFile.keyList, myPath) > > > File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 113, in createVNTobjects > > > self.createImage(groupName, layerName, fileName, imagePath, self.vntGroups) > > > File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 137, in createImage > > > img = open_image(imageFile) > > > File "", line 2, in open_image > > > File "C:\Python27\32bit\lib\site-packages\s7vampy\arg_validator.py", line 213, in __call__ > > > return func(*args, **keywords) > > > File "C:\Python27\32bit\lib\site-packages\s7vampy\image.py", line 181, in open_image > > > return Image(_S7VAM_IMAGE.Open(filename)) > > > RuntimeError: Open Failed: 'C:/Users/sporitskiy/Desktop/Practice/HIWM2MSB/hiwm2mpa_upholstery_esq_leather_ro_12_0001.tif' > > > > We were confused because the failed open should be an IOError. If Image > > is indeed converting such to RuntimeError, it should not. It should just > > let the original error bubble up. It is possibly tossing information in > > the process. The first thing I would do is to look at the code around > > that line in image.py and remove the exception replacement if there is one. > > > > -- > > Terry Jan Reedy From steve+comp.lang.python at pearwood.info Fri Sep 6 12:56:07 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Sep 2013 16:56:07 GMT Subject: Confessions of a terrible programmer Message-ID: <522a0927$0$29988$c3e8da3$5496439d@news.astraweb.com> Not specifically about Python, but still relevant: http://blog.kickin-the-darkness.com/2007/09/confessions-of-terrible-programmer.html -- Steven From joel.goldstick at gmail.com Fri Sep 6 13:17:20 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 6 Sep 2013 13:17:20 -0400 Subject: Confessions of a terrible programmer In-Reply-To: <522a0927$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <522a0927$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Sep 6, 2013 at 12:56 PM, Steven D'Aprano wrote: > Not specifically about Python, but still relevant: > > http://blog.kickin-the-darkness.com/2007/09/confessions-of-terrible-programmer.html > > > > > > -- > Steven > -- > https://mail.python.org/mailman/listinfo/python-list Pardon me, but I completely don't get this article. Let me in on what is supposed to be the joke please! -- Joel Goldstick http://joelgoldstick.com From rosuav at gmail.com Fri Sep 6 13:43:32 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 7 Sep 2013 03:43:32 +1000 Subject: Confessions of a terrible programmer In-Reply-To: References: <522a0927$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Sep 7, 2013 at 3:17 AM, Joel Goldstick wrote: > On Fri, Sep 6, 2013 at 12:56 PM, Steven D'Aprano > wrote: >> Not specifically about Python, but still relevant: >> >> http://blog.kickin-the-darkness.com/2007/09/confessions-of-terrible-programmer.html >> >> >> >> >> >> -- >> Steven >> -- >> https://mail.python.org/mailman/listinfo/python-list > > Pardon me, but I completely don't get this article. Let me in on what > is supposed to be the joke please! It's a "ha-ha only serious" article. The point is: You can't write good code by being a good programmer. You MUST [1] acknowledge that you write buggy code, and then code accordingly. Sometimes you'll write bugs that result in egg on the face. I fixed one this week that had been lying around for ages; if the user provided a particular (and unusual, though not malformed) set of input, and the program was running in the first hour after midnight UTC on a Thursday, it would go into an infinite loop, because I'd missed decrementing something. More often - especially if you do things like the author there does - you'll have a program that bombs really fast on startup, or at least bombs noisily when something goes wrong. Those bugs are easy to find and, often, easy to fix. Those bugs we can deal with. The other point to note is that it takes a competent debugger to figure out problems, and that's in many ways a more important skill than writing code. Taking another example from this week at work: My boss was tinkering with our AJAX system, using his Linux development box and one of our Linux test servers. He clicks a button in either Google Chrome or Iceweasel (Debian's old build of Firefox), the server does stuff, and stuff happens promptly. He crosses over to his Windows XP laptop to try the same button in IE8 (the oldest and stupidest browser we support), and there's a 20-second lag before the server does its stuff. But adding logging showed that the AJAX call was taking less than a second, so it couldn't be that. Turned out the request was given a job time based on the client's clock, which was 20 seconds ahead of the server, so the job got delayed by those 20 seconds. Would you, when debugging an AJAX+PHP system, think to check if clocks are synchronized? Only if you know how to debug. Good programmers can, and can pinpoint problems without looking at a single line of code. Claiming you'll write perfect code is arrogance beyond measure. Acknowledging that there'll be bugs and building systems to cope with (and remove) them is the critical humility for programmers. [1] http://www.ietf.org/rfc/rfc2119.txt ChrisA From skip at pobox.com Fri Sep 6 13:48:28 2013 From: skip at pobox.com (Skip Montanaro) Date: Fri, 6 Sep 2013 12:48:28 -0500 Subject: Confessions of a terrible programmer In-Reply-To: References: <522a0927$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: > Pardon me, but I completely don't get this article. Let me in on what > is supposed to be the joke please! I don't really think there's a joke. I think the author is saying in a somewhat sly way is that often, the difference between a terrible programmer and a great programmer is the discipline applied to the task, and intelligent use of the tools at hand. Catch as many errors as you can as early as possible (before other people see your original stabs at a solution) and when your code is set loose in the wild you will seem like a great programmer. Little do your colleagues know that your tools protect them from your terrible programming. Skip From walterhurry at lavabit.com Fri Sep 6 14:31:08 2013 From: walterhurry at lavabit.com (Walter Hurry) Date: Fri, 6 Sep 2013 18:31:08 +0000 (UTC) Subject: Confessions of a terrible programmer References: <522a0927$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, 06 Sep 2013 13:17:20 -0400, Joel Goldstick wrote: > On Fri, Sep 6, 2013 at 12:56 PM, Steven D'Aprano > wrote: >> Not specifically about Python, but still relevant: >> >> http://blog.kickin-the-darkness.com/2007/09/confessions-of-terrible- programmer.html > > Pardon me, but I completely don't get this article. Let me in on what > is supposed to be the joke please! No joke. Defensive programming is the only way to go if one is writing a serious system, whatever the language. From steve+comp.lang.python at pearwood.info Fri Sep 6 20:13:18 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Sep 2013 00:13:18 GMT Subject: Confessions of a terrible programmer References: <522a0927$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <522a6f9e$0$29988$c3e8da3$5496439d@news.astraweb.com> On Fri, 06 Sep 2013 13:17:20 -0400, Joel Goldstick wrote: > On Fri, Sep 6, 2013 at 12:56 PM, Steven D'Aprano > wrote: >> Not specifically about Python, but still relevant: >> >> http://blog.kickin-the-darkness.com/2007/09/confessions-of-terrible- programmer.html > Pardon me, but I completely don't get this article. Let me in on what > is supposed to be the joke please! It isn't intended as a joke. The article is serious, but it wraps its serious message in a bit of mild humour: here is a guy who calls himself a terrible programmer, but his projects are always completed on time and on budget, while "good" programmers' projects are late, over-budget and buggy. The irony is that those who think of themselves as "good programmers" end up writing worse code than those who think of themselves as "terrible programmers", because the self-aware terrible programmers use all the tools in the programmer toolbox to improve their code and the others don't. The author of that blog piece is too polite to say so, but I suspect that there's a certain amount of Dunning-Kruger Effect going on... http://en.wikipedia.org/wiki/Dunning?Kruger_effect but I digress. -- Steven From tjreedy at udel.edu Fri Sep 6 14:52:28 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 06 Sep 2013 14:52:28 -0400 Subject: Confessions of a terrible programmer In-Reply-To: <522a0927$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <522a0927$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 9/6/2013 12:56 PM, Steven D'Aprano wrote: > Not specifically about Python, but still relevant: to what? > http://blog.kickin-the-darkness.com/2007/09/confessions-of-terrible-programmer.html I think link posts should have at least a sentence summarizing the content of the linked page so I would have some idea of whether it is worth me clicking it. -- Terry Jan Reedy From rustompmody at gmail.com Mon Sep 16 10:56:09 2013 From: rustompmody at gmail.com (rusi) Date: Mon, 16 Sep 2013 07:56:09 -0700 (PDT) Subject: Confessions of a terrible programmer In-Reply-To: <522a0927$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <522a0927$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9bed8537-9e50-4a10-94ef-a4d92db853f8@googlegroups.com> On Friday, September 6, 2013 10:26:07 PM UTC+5:30, Steven D'Aprano wrote: > Not specifically about Python, but still relevant: > > http://blog.kickin-the-darkness.com/2007/09/confessions-of-terrible-programmer.html Nice post -- thanks! Prompted this from me http://blog.languager.org/2013/09/poorest-computer-users-are-programmers.html From ben+python at benfinney.id.au Sat Sep 7 02:03:26 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 07 Sep 2013 16:03:26 +1000 Subject: Installing resource data files and finding them Message-ID: <7wr4d1p3rl.fsf@benfinney.id.au> Howdy all, How do I package a Python application with its resource files separate from the Python modules, such that the resource files can be discovered by the Python code when it runs? I am working on an existing Python application code base. The application currently assumes that its resource files will be installed to the same location as the python modules (using the Distutils ?package_data? option). But this violates the Filesystem Hierarchy Standard used on GNU+Linux . By that standard, platform-independent resources belong in ?/usr/share/??, while platform-dependent code libraries belong in ?/usr/lib/??. Currently the upstream Python code uses ?os.path.dirname(__file__)? and similar, to discover the location of the resource files. It thereby assumes that the resource files are installed to the same location as the Python code. The Distutils ?package_data? option appears to enforce this, and I can't find any way for the files to be installed to a different place using that option. The Distutils ?data_files? option doesn't seem suitable for this purpose. It allows the location to be specified (using ?python ./setup.py --data-files=FOODIR?),, but there appears to be no way for the application to know what location was specified later. I will need to change both the build configuration and the application code, so that instead it allows the resource files to be installed to an appropriate location on the target system, and seeks the data files in the correct location when run later. Of course, the code should continue to work on systems that don't conform to the FHS and allow resource data files to live alongside platform code, so I can't just hard-code the new location. I had hoped to use Python's standard library (Distutils? Distribute? Something else?) to access the resources once installed to the correct location. This needs to allow the choice of location to be made at install-time, but discovered by the application at run-time. Is there a way to do that, or is this a problem still unsolved in Python? -- \ ?Most people, I think, don't even know what a rootkit is, so | `\ why should they care about it?? ?Thomas Hesse, Sony BMG, 2006 | _o__) | Ben Finney From ben+python at benfinney.id.au Sun Sep 8 23:51:16 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 09 Sep 2013 13:51:16 +1000 Subject: Installing resource data files and finding them References: <7wr4d1p3rl.fsf@benfinney.id.au> Message-ID: <7wk3iq3b63.fsf@benfinney.id.au> Ben Finney writes: > I will need to change both the build configuration and the application > code, so that instead it allows the resource files to be installed to > an appropriate location on the target system, and seeks the data files > in the correct location when run later. I've used an ugly hack to work around this problem: * Patch the ?MANIFEST.in? and ?setup.py? to omit all mention of the resource files. This makes the Python Distutils simply omit the resource files and not install them at all. * Add a series of rules to the package builder to explicitly install the resource files to a temporary build location. Make sure these rules work for the multiple binary packages and for multiple builds. * Install the resource files for each package to an FHS-compliant location outside the Python package. * Make a symlink within each installed package to the resource location for the package. That works for now. It's ugly and a maintenance burden, though: I would hate to need to do this for resource files in every Python package. > I had hoped to use Python's standard library (Distutils? Distribute? > Something else?) to access the resources once installed to the correct > location. This needs to allow the choice of location to be made at > install-time, but discovered by the application at run-time. Ideally I wouldn't need to subvert Distutils, but could somehow tell it what I need and have it record the install-time decisions for the run-time application's needs. I'm still hoping there is a standard-library way to do this. Please let me know. -- \ ?You are welcome to visit the cemetery where famous Russian and | `\ Soviet composers, artists, and writers are buried daily except | _o__) Thursday.? ?Russian orthodox monastery, Moscow | Ben Finney From Larry.Martell at gmail.com Sat Sep 7 06:55:02 2013 From: Larry.Martell at gmail.com (Larry.Martell at gmail.com) Date: Sat, 7 Sep 2013 03:55:02 -0700 (PDT) Subject: python script hangs when run from subprocess Message-ID: <8a22147e-ab55-4890-b982-9d905f1f8934@googlegroups.com> I have a python script and when I run it directly from the command line it runs to completion. But I need to run it from another script. I do that like this: p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) rv = p.wait() out_buf = p.stdout.read() When I do this, wait never returns. If I trace the underlying script it's always in the same write to stderr that never seems to complete: write(2, "/KA22/05Feb12/Images/12063LBO003"..., 24457 I run many other scripts and commands in the same manner, and they all complete, it's just this one. Anyone have any ideas why this is happening, and how I can further debug or fix this? TIA! -larry From __peter__ at web.de Sat Sep 7 07:19:25 2013 From: __peter__ at web.de (Peter Otten) Date: Sat, 07 Sep 2013 13:19:25 +0200 Subject: python script hangs when run from subprocess References: <8a22147e-ab55-4890-b982-9d905f1f8934@googlegroups.com> Message-ID: Larry.Martell at gmail.com wrote: > I have a python script and when I run it directly from the command line it > runs to completion. But I need to run it from another script. I do that > like this: > > p = subprocess.Popen(cmd, stdout=subprocess.PIPE, > stderr=subprocess.STDOUT) rv = p.wait() > out_buf = p.stdout.read() > > When I do this, wait never returns. If I trace the underlying script it's > always in the same write to stderr that never seems to complete: > > write(2, "/KA22/05Feb12/Images/12063LBO003"..., 24457 > > I run many other scripts and commands in the same manner, and they all > complete, it's just this one. Anyone have any ideas why this is happening, > and how I can further debug or fix this? The script writes to an OS buffer, and when that buffer is full it blocks forever. p.wait() in turn then waits forever for the script to terminate... As a fix try out_buf = subprocess.Popen(...).communicate()[0] This uses threads or select (depending on the OS) to avoid the problem -- and is prominently mentionend in the documentation: http://docs.python.org/2/library/subprocess.html#subprocess.Popen.wait From nobody at nowhere.com Sat Sep 7 11:47:47 2013 From: nobody at nowhere.com (Nobody) Date: Sat, 07 Sep 2013 16:47:47 +0100 Subject: python script hangs when run from subprocess References: <8a22147e-ab55-4890-b982-9d905f1f8934@googlegroups.com> Message-ID: On Sat, 07 Sep 2013 03:55:02 -0700, Larry.Martell at gmail.com wrote: > I have a python script and when I run it directly from the command line > it runs to completion. But I need to run it from another script. I do > that like this: > > p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) > rv = p.wait() > out_buf = p.stdout.read() > > When I do this, wait never returns. The last two statements are the wrong way around. If you're reading a process' output via a pipe, you shouldn't wait() for it until it has closed its end of the pipe. As it stands, you have a potential deadlock. If the subprocess tries to write more data than will fit into the pipe, it will block until the parent reads from the pipe. But the parent won't read from the pipe until after the subprocess has terminated, which won't happen because the subprocess is blocked waiting for the parent to read from the pipe ... From Larry.Martell at gmail.com Sat Sep 7 13:24:59 2013 From: Larry.Martell at gmail.com (Larry.Martell at gmail.com) Date: Sat, 7 Sep 2013 10:24:59 -0700 (PDT) Subject: python script hangs when run from subprocess In-Reply-To: References: <8a22147e-ab55-4890-b982-9d905f1f8934@googlegroups.com> Message-ID: On Saturday, September 7, 2013 9:47:47 AM UTC-6, Nobody wrote: > On Sat, 07 Sep 2013 03:55:02 -0700, Larry.Martell at gmail.com wrote: > > > > > I have a python script and when I run it directly from the command line > > > it runs to completion. But I need to run it from another script. I do > > > that like this: > > > > > > p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) > > > rv = p.wait() > > > out_buf = p.stdout.read() > > > > > > When I do this, wait never returns. > > > > The last two statements are the wrong way around. If you're reading a > > process' output via a pipe, you shouldn't wait() for it until it has > > closed its end of the pipe. > > > > As it stands, you have a potential deadlock. If the subprocess tries to > > write more data than will fit into the pipe, it will block until the > > parent reads from the pipe. But the parent won't read from the pipe until > > after the subprocess has terminated, which won't happen because the > > subprocess is blocked waiting for the parent to read from the pipe ... Thanks. I reversed the order of the wait and read calls, and it no longer hangs. From Larry.Martell at gmail.com Sat Sep 7 13:24:07 2013 From: Larry.Martell at gmail.com (Larry.Martell at gmail.com) Date: Sat, 7 Sep 2013 10:24:07 -0700 (PDT) Subject: python script hangs when run from subprocess In-Reply-To: References: <8a22147e-ab55-4890-b982-9d905f1f8934@googlegroups.com> Message-ID: <1d6c7803-f23b-4fbc-b4cc-346b5dfddc11@googlegroups.com> On Saturday, September 7, 2013 5:19:25 AM UTC-6, Peter Otten wrote: > Larry.Martell at gmail.com wrote: > > > > > I have a python script and when I run it directly from the command line it > > > runs to completion. But I need to run it from another script. I do that > > > like this: > > > > > > p = subprocess.Popen(cmd, stdout=subprocess.PIPE, > > > stderr=subprocess.STDOUT) rv = p.wait() > > > out_buf = p.stdout.read() > > > > > > When I do this, wait never returns. If I trace the underlying script it's > > > always in the same write to stderr that never seems to complete: > > > > > > write(2, "/KA22/05Feb12/Images/12063LBO003"..., 24457 > > > > > > I run many other scripts and commands in the same manner, and they all > > > complete, it's just this one. Anyone have any ideas why this is happening, > > > and how I can further debug or fix this? > > > > The script writes to an OS buffer, and when that buffer is full it blocks > > forever. p.wait() in turn then waits forever for the script to terminate... > > > > As a fix try > > > > out_buf = subprocess.Popen(...).communicate()[0] > > > > > > This uses threads or select (depending on the OS) to avoid the problem -- > > and is prominently mentionend in the documentation: > > > > http://docs.python.org/2/library/subprocess.html#subprocess.Popen.wait Thanks. I hadn't seen this. I'll check it out. From aaronspencermartin at gmail.com Sat Sep 7 21:17:46 2013 From: aaronspencermartin at gmail.com (Aaron Martin) Date: Sat, 7 Sep 2013 18:17:46 -0700 Subject: Can I trust downloading Python? Message-ID: Hi, I am thinking about getting a software but it requires python, so that brought up a few questions. Is it safe do download python, and does it come with spam or advertisements? If it doesn't then should I get the latest version? I mostly want to know if it is safe to download, because most of the time downloading free stuff off the internet comes with spam and all that, so I want to know if I can trust downloading it. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat Sep 7 21:35:43 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 8 Sep 2013 11:35:43 +1000 Subject: Can I trust downloading Python? In-Reply-To: References: Message-ID: On Sun, Sep 8, 2013 at 11:17 AM, Aaron Martin wrote: > Hi, I am thinking about getting a software but it requires python, so that > brought up a few questions. Is it safe do download python, and does it come > with spam or advertisements? If it doesn't then should I get the latest > version? I mostly want to know if it is safe to download, because most of > the time downloading free stuff off the internet comes with spam and all > that, so I want to know if I can trust downloading it. Yes, you can trust Python. If you don't like the precompiled versions, you can simply download the source code (plain text files) and build your own, so any advertising in it could be removed very easily - and would thus be worthless, so nobody bothers to put any there. Open Source is different from ad-funded software; both of them cost you no money, but there's a complete difference in philosophy. Definitely get the latest version (currently 3.3, soon 3.4). Python keeps getting new features and improvements. ChrisA From ben+python at benfinney.id.au Sat Sep 7 23:01:58 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 08 Sep 2013 13:01:58 +1000 Subject: Can I trust downloading Python? References: Message-ID: <7wy5782ezd.fsf@benfinney.id.au> Aaron Martin writes: > Hi, I am thinking about getting a software but it requires python, so > that brought up a few questions. Is it safe do download python, and > does it come with spam or advertisements? Python is free software, meaning that every recipient is free to improve it and redistribute the result. Free software rarely has the problems you describe ? spam and advertisements ? and never has them for long, because those problems are quickly improved (by eradicating the annoying problem), and the improved version becomes what people share. > If it doesn't then should I get the latest version? The latest stable version is Python 3.3, and this version is strongly recommended for people who will be developing with Python. But you say that you are getting Python because you have some other program that requires Python. Which version of Python does it require? Download and install the latest version that is supported for the program you are wanting to use. > I mostly want to know if it is safe to download, because most of the > time downloading free stuff off the internet comes with spam and all > that, so I want to know if I can trust downloading it. Ah, your experience is with zero-cost non-free software. Non-free software is prone to have spam and advertisements, and many other problems that arise from disrespect for the recipient's freedom. So your caution is well advised. Know that free software respects your freedom, and Python is free software. Welcome, and good fortune to you in using Python! -- \ ?I was trying to daydream, but my mind kept wandering.? ?Steven | `\ Wright | _o__) | Ben Finney From torriem at gmail.com Sat Sep 7 23:04:59 2013 From: torriem at gmail.com (Michael Torrie) Date: Sat, 07 Sep 2013 21:04:59 -0600 Subject: Can I trust downloading Python? In-Reply-To: References: Message-ID: <522BE95B.9040905@gmail.com> On 09/07/2013 07:17 PM, Aaron Martin wrote: > Hi, I am thinking about getting a software but it requires python, so that > brought up a few questions. Is it safe do download python, and does it come > with spam or advertisements? If it doesn't then should I get the latest > version? I mostly want to know if it is safe to download, because most of > the time downloading free stuff off the internet comes with spam and all > that, so I want to know if I can trust downloading it. Yes if you download binaries from the official sources (python.org web site) there is a reasonable assumption that the binary is free from malware or viruses. I've never heard of programmings coming with spam before ;). Usually that arrives unbidden in my inbox. As for trusting python in general, I do trust the python developers, but recent NSA revelations call just about all aspects of computing, trust, and privacy into doubt. From davea at davea.name Sat Sep 7 23:37:15 2013 From: davea at davea.name (Dave Angel) Date: Sun, 8 Sep 2013 03:37:15 +0000 (UTC) Subject: Can I trust downloading Python? References: Message-ID: On 7/9/2013 21:17, Aaron Martin wrote: > Hi, I am thinking about getting a software but it requires python, so that > brought up a few questions. Is it safe do download python, and does it come > with spam or advertisements? If it doesn't then should I get the latest > version? I mostly want to know if it is safe to download, because most of > the time downloading free stuff off the internet comes with spam and all > that, so I want to know if I can trust downloading it. > Python is available without ads, trojans, viruses, or other malware. However, the internet is a big place, and there are undoubtedly some places which will add their own garbage to the download. If you get Python from python.org, or from activestate.com, it'll be safe. Someone here will be glad to give you a link, once you identify just what you actually need: 1) what OS are you running? Actually, we can be pretty sure you're running Windows, since any other common operating system would have already included Python. But you will need to know whether it's 32bit or 64 bit OS. You can run a 32bit Python on 64bit OS, but not the oter way around. And most people just match the bitness of Python against the bitness of the OS. 2) What version of Python does that software you're talking about require? The two most lkely candidates are 2.7 or 3.3 There are packages out there that haven't yet ported to 3.x, so you may be stuck with 2.7. But if the package is older, you might even need 2.6 -- DaveA From steve+comp.lang.python at pearwood.info Sun Sep 8 08:32:15 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 Sep 2013 12:32:15 GMT Subject: Can I trust downloading Python? References: Message-ID: <522c6e4e$0$29988$c3e8da3$5496439d@news.astraweb.com> On Sat, 07 Sep 2013 21:04:59 -0600, Michael Torrie wrote: > As for trusting python in general, I do trust the python developers, but > recent NSA revelations call just about all aspects of computing, trust, > and privacy into doubt. "Recent" revelations? Where have you been for the last, oh, 20 odd years? Remember when people who talked about Carnivore and Echelon were considered in tin-foil hat territory? I do. I think it was Paul Krugman who talks about the one thing worse than being wrong is being right too soon. In context, he's referring to the Bush administration's adventures in Iraq, and how those who were right a decade ago are still routinely ignored even after being proven right, while the Very Serious People who were utterly, obviously wrong are still feted as experts. The same applies to the surveillance society. This didn't just appear overnight. You don't build programmes the size and complexity of PRISM, Tempora, Stellawind, X-Keyscore, Dropmire, and no doubt others that we still don't know about, overnight. When it comes to NSA spying, before Edward Snowden, there were these other guys: http://www.usatoday.com/story/news/politics/2013/06/16/snowden-whistleblower-nsa-officials-roundtable/2428809/ And if you think it's just the NSA, you *really* haven't been paying attention. From 2005: http://www.noplacetohide.net/ -- Steven From chottel at earthlink.net Sun Sep 8 12:08:11 2013 From: chottel at earthlink.net (Charles Hottel) Date: Sun, 8 Sep 2013 12:08:11 -0400 Subject: Can I trust downloading Python? References: <522c6e4e$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: "Steven D'Aprano" wrote in message news:522c6e4e$0$29988$c3e8da3$5496439d at news.astraweb.com... > On Sat, 07 Sep 2013 21:04:59 -0600, Michael Torrie wrote: > >> As for trusting python in general, I do trust the python developers, but >> recent NSA revelations call just about all aspects of computing, trust, >> and privacy into doubt. > > "Recent" revelations? Where have you been for the last, oh, 20 odd years? > > Remember when people who talked about Carnivore and Echelon were > considered in tin-foil hat territory? I do. > > I think it was Paul Krugman who talks about the one thing worse than > being wrong is being right too soon. In context, he's referring to the > Bush administration's adventures in Iraq, and how those who were right a > decade ago are still routinely ignored even after being proven right, > while the Very Serious People who were utterly, obviously wrong are still > feted as experts. The same applies to the surveillance society. This > didn't just appear overnight. You don't build programmes the size and > complexity of PRISM, Tempora, Stellawind, X-Keyscore, Dropmire, and no > doubt others that we still don't know about, overnight. > > When it comes to NSA spying, before Edward Snowden, there were these > other guys: > > http://www.usatoday.com/story/news/politics/2013/06/16/snowden-whistleblower-nsa-officials-roundtable/2428809/ > > > And if you think it's just the NSA, you *really* haven't been paying > attention. From 2005: > > http://www.noplacetohide.net/ > > > > -- > Steven I think this article is relevant althought the code examples are not Python but C: http://cm.bell-labs.com/who/ken/trust.html From rosuav at gmail.com Sun Sep 8 12:39:09 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 Sep 2013 02:39:09 +1000 Subject: Can I trust downloading Python? In-Reply-To: References: <522c6e4e$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Sep 9, 2013 at 2:08 AM, Charles Hottel wrote: > I think this article is relevant althought the code examples are not Python > but C: > > http://cm.bell-labs.com/who/ken/trust.html That is quite true, and yet not truly helpful here :) It's like pointing out that we could be being fed false information, and then suggesting that The Matrix is technically possible. Once you start distrusting to that level, you become paranoid to a point that's inappropriate to all but the most critical situations. I'd accept and maybe even recommend that sort of paranoia if you're running a nuclear power station, or an automated weapon system capable of firing missiles that destroy the planet, or a bank that holds everyone's money. For the average Joe, there's no point panicking. Also: That hack works beautifully when there's precisely one C compiler. In today's world, there are many (well known ones like gcc, clang, MS Visual Studio (whatever the compiler from that is called), and a bunch of lesser-known ones as well), and it's pretty easy to just grab a different compiler and build. The chances that your code will be falsely compiled by TWO compilers would have to be infinitesimal, and you needn't stop at two. Since many people build (to take one example) gcc from source, using an old version of gcc, the hack would have to be propagated to all current gcc builds in some way - you can't simply build once and install the binary as the official C compiler, not in today's distributed society. (If you're truly paranoid, you might believe that gcc has had the hack in it since its inception. But some people build gcc using other compilers, too.) If you can't trust any code you didn't write yourself, you're left with Rene Descartes' line "I think, therefore I am" - it's impossible to prove anything else, since you can't trust your senses. So go ahead! Distrust everything and use nothing. Or accept that, even if you're the target of a huge conspiracy, it doesn't even matter, because life still goes on :) ChrisA From steve at pearwood.info Mon Sep 9 05:41:54 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 09 Sep 2013 09:41:54 GMT Subject: Can I trust downloading Python? References: <522c6e4e$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <522d97e1$0$29893$c3e8da3$5496439d@news.astraweb.com> On Mon, 09 Sep 2013 02:39:09 +1000, Chris Angelico wrote: > On Mon, Sep 9, 2013 at 2:08 AM, Charles Hottel > wrote: >> I think this article is relevant althought the code examples are not >> Python but C: >> >> http://cm.bell-labs.com/who/ken/trust.html > > That is quite true, and yet not truly helpful here :) It's like pointing > out that we could be being fed false information, and then suggesting > that The Matrix is technically possible. Once you start distrusting to > that level, you become paranoid to a point that's inappropriate to all > but the most critical situations. I'd accept and maybe even recommend > that sort of paranoia if you're running a nuclear power station, or an > automated weapon system capable of firing missiles that destroy the > planet, or a bank that holds everyone's money. For the average Joe, > there's no point panicking. > > Also: That hack works beautifully when there's precisely one C compiler. > In today's world, there are many (well known ones like gcc, clang, MS > Visual Studio (whatever the compiler from that is called), and a bunch > of lesser-known ones as well), and it's pretty easy to just grab a > different compiler and build. The chances that your code will be falsely > compiled by TWO compilers would have to be infinitesimal, and you > needn't stop at two. That logic is dubious. Compilers aren't compromised by chance, and we don't know the a priori probability of any specific compiler being compromised. That depends on the attacker, surely? We know, for example, that the NSA has compromised multiple brands of router, smart phone and similar. If they, or some other similar organisation with equivalent capabilities, were going to attack compilers in the same manner, they surely wouldn't stop at one. Would people notice? How often do people compare the machine code output of two different compilers, looking for back-doors in the generated code? Would you know where to look? If you found some differences, wouldn't you likely just chalk it up to different compilers producing different code? I think the best argument against this suggestion is that it would be an order of magnitude harder to compromise open source compilers, as you discuss below, and therefore gcc is *probably* (but not certainly) safe. But closed source? If Microsoft inserted a backdoor into Windows 8 on behalf of the NSA, as seems to be the case, then surely they'd also do the same to Visual Studio if asked. Organisations like the NSA don't operate under the rule "if there is one single uncompromised machine on the planet, we've lost". It's a numbers game. If (hypothetically speaking) they had inserted backdoors into Visual Studio, gcc and clang, but not Larry's Cool C Compiler, I don't think they're going to lose sleep over that. > Since many people build (to take one example) gcc > from source, using an old version of gcc, the hack would have to be > propagated to all current gcc builds in some way - you can't simply > build once and install the binary as the official C compiler, not in > today's distributed society. (If you're truly paranoid, you might > believe that gcc has had the hack in it since its inception. But some > people build gcc using other compilers, too.) Yep, I agree -- although probably no individual has inspected the entire tool chain involved in building gcc, enough people have inspected each individual component that we can be reasonably confident that it is okay. > If you can't trust any code you didn't write yourself, You trust yourself? You sheeple! The truly cautious man doesn't even trust himself. You might be an unconscious sleeper agent. Haven't you watched The Running Man? (Ha ha only serious.) -- Steven From papillion at gmail.com Mon Sep 9 07:02:18 2013 From: papillion at gmail.com (Anthony Papillion) Date: Mon, 09 Sep 2013 06:02:18 -0500 Subject: Can I trust downloading Python? In-Reply-To: <522d97e1$0$29893$c3e8da3$5496439d@news.astraweb.com> References: <522c6e4e$0$29988$c3e8da3$5496439d@news.astraweb.com> <522d97e1$0$29893$c3e8da3$5496439d@news.astraweb.com> Message-ID: <522DAABA.6040307@gmail.com> On 09/09/2013 04:41 AM, Steven D'Aprano wrote: > On Mon, 09 Sep 2013 02:39:09 +1000, Chris Angelico wrote: > >> On Mon, Sep 9, 2013 at 2:08 AM, Charles Hottel >> wrote: >>> I think this article is relevant althought the code examples are not >>> Python but C: >>> >>> http://cm.bell-labs.com/who/ken/trust.html >> >> That is quite true, and yet not truly helpful here :) It's like pointing >> out that we could be being fed false information, and then suggesting >> that The Matrix is technically possible. Once you start distrusting to >> that level, you become paranoid to a point that's inappropriate to all >> but the most critical situations. I'd accept and maybe even recommend >> that sort of paranoia if you're running a nuclear power station, or an >> automated weapon system capable of firing missiles that destroy the >> planet, or a bank that holds everyone's money. For the average Joe, >> there's no point panicking. >> >> Also: That hack works beautifully when there's precisely one C compiler. >> In today's world, there are many (well known ones like gcc, clang, MS >> Visual Studio (whatever the compiler from that is called), and a bunch >> of lesser-known ones as well), and it's pretty easy to just grab a >> different compiler and build. The chances that your code will be falsely >> compiled by TWO compilers would have to be infinitesimal, and you >> needn't stop at two. > > That logic is dubious. Compilers aren't compromised by chance, and we > don't know the a priori probability of any specific compiler being > compromised. That depends on the attacker, surely? We know, for example, > that the NSA has compromised multiple brands of router, smart phone and > similar. If they, or some other similar organisation with equivalent > capabilities, were going to attack compilers in the same manner, they > surely wouldn't stop at one. But (and this is stepping into *really* paranoid territory here. But maybe not beyond the realm of possibility) it would not be so hard to compromise compilers at the chip level. If the NSA were to strike an agreement with, say, Intel so that every time a compiler ran on the system, secret code was discreetly inserted into the binary, it would be nearly impossible to detect and a very elegant solution to a tough problem. From torriem at gmail.com Mon Sep 9 12:23:22 2013 From: torriem at gmail.com (Michael Torrie) Date: Mon, 09 Sep 2013 10:23:22 -0600 Subject: Can I trust downloading Python? In-Reply-To: <522DAABA.6040307@gmail.com> References: <522c6e4e$0$29988$c3e8da3$5496439d@news.astraweb.com> <522d97e1$0$29893$c3e8da3$5496439d@news.astraweb.com> <522DAABA.6040307@gmail.com> Message-ID: <522DF5FA.5090202@gmail.com> On 09/09/2013 05:02 AM, Anthony Papillion wrote: > But (and this is stepping into *really* paranoid territory here. But > maybe not beyond the realm of possibility) it would not be so hard to > compromise compilers at the chip level. If the NSA were to strike an > agreement with, say, Intel so that every time a compiler ran on the > system, secret code was discreetly inserted into the binary, it would be > nearly impossible to detect and a very elegant solution to a tough problem. Indeed it is really paranoid territory, but now doesn't seem quite as far fetched as one originally thought a few years ago! We'll still trust (we have to; we have no other choice), but the level of trust in computers in general has certainly gone down a notch and will never quite be the same. From wrw at mac.com Mon Sep 9 12:40:45 2013 From: wrw at mac.com (William Ray Wing) Date: Mon, 09 Sep 2013 12:40:45 -0400 Subject: Can I trust downloading Python? In-Reply-To: <522DF5FA.5090202@gmail.com> References: <522c6e4e$0$29988$c3e8da3$5496439d@news.astraweb.com> <522d97e1$0$29893$c3e8da3$5496439d@news.astraweb.com> <522DAABA.6040307@gmail.com> <522DF5FA.5090202@gmail.com> Message-ID: <23C93617-F6EC-422F-B8B3-BA97F60D3321@mac.com> On Sep 9, 2013, at 12:23 PM, Michael Torrie wrote: > On 09/09/2013 05:02 AM, Anthony Papillion wrote: >> But (and this is stepping into *really* paranoid territory here. But >> maybe not beyond the realm of possibility) it would not be so hard to >> compromise compilers at the chip level. If the NSA were to strike an >> agreement with, say, Intel so that every time a compiler ran on the >> system, secret code was discreetly inserted into the binary, it would be >> nearly impossible to detect and a very elegant solution to a tough problem. > > Indeed it is really paranoid territory, but now doesn't seem quite as > far fetched as one originally thought a few years ago! We'll still > trust (we have to; we have no other choice), but the level of trust in > computers in general has certainly gone down a notch and will never > quite be the same. > > > -- > https://mail.python.org/mailman/listinfo/python-list I think that is pretty far fetched. It requires recognition that a compiler is being compiled. I'd be REALLY surprised if there were a unique sequence of hardware instructions that was common across every possible compiler (current and future) and which wouldn't (couldn't) exist in arbitrary non-compiller execution, which could be used to trigger insertion of a backdoor. -Bill From torriem at gmail.com Mon Sep 9 12:44:33 2013 From: torriem at gmail.com (Michael Torrie) Date: Mon, 09 Sep 2013 10:44:33 -0600 Subject: Can I trust downloading Python? In-Reply-To: <23C93617-F6EC-422F-B8B3-BA97F60D3321@mac.com> References: <522c6e4e$0$29988$c3e8da3$5496439d@news.astraweb.com> <522d97e1$0$29893$c3e8da3$5496439d@news.astraweb.com> <522DAABA.6040307@gmail.com> <522DF5FA.5090202@gmail.com> <23C93617-F6EC-422F-B8B3-BA97F60D3321@mac.com> Message-ID: <522DFAF1.4080700@gmail.com> On 09/09/2013 10:40 AM, William Ray Wing wrote: > I think that is pretty far fetched. It requires recognition that a > compiler is being compiled. I'd be REALLY surprised if there were a > unique sequence of hardware instructions that was common across every > possible compiler (current and future) and which wouldn't (couldn't) > exist in arbitrary non-compiller execution, which could be used to > trigger insertion of a backdoor. Agreed. Most of the damage done by the NSA is in the realm of social engineering more than technical. IE they compromise companies more than the algorithms themselves. The end points always are the weak things. And yes, Free software that is open source is more resistant to such tampering. From feliphil at gmx.net Sun Sep 8 09:29:55 2013 From: feliphil at gmx.net (Wolfgang Keller) Date: Sun, 8 Sep 2013 15:29:55 +0200 Subject: Can I trust downloading Python? References: Message-ID: <20130908152955.a99bbab4c50123260d22d420@gmx.net> > Definitely get the latest version (currently 3.3, soon 3.4). Python > keeps getting new features and improvements. Python scripts or applications might not be compatible with Python 3.x and require 2.x instead. Sincerely, Wolfgang From tjreedy at udel.edu Sun Sep 8 15:29:17 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 08 Sep 2013 15:29:17 -0400 Subject: Can I trust downloading Python? In-Reply-To: <20130908152955.a99bbab4c50123260d22d420@gmx.net> References: <20130908152955.a99bbab4c50123260d22d420@gmx.net> Message-ID: On 9/8/2013 9:29 AM, Wolfgang Keller wrote: >> Definitely get the latest version (currently 3.3, soon 3.4). Python >> keeps getting new features and improvements. > > Python scripts or applications might not be compatible with Python 3.x > and require 2.x instead. And the other way around. -- Terry Jan Reedy From llanitedave at veawb.coop Sun Sep 8 22:24:11 2013 From: llanitedave at veawb.coop (llanitedave) Date: Sun, 8 Sep 2013 19:24:11 -0700 (PDT) Subject: Can I trust downloading Python? In-Reply-To: References: Message-ID: I capitalize "Free" to avoid confusing it with "free as in beer". On Sunday, September 8, 2013 3:01:58 AM UTC, Ben Finney wrote: > Aaron Martin writes: > > > > > Hi, I am thinking about getting a software but it requires python, so > > > that brought up a few questions. Is it safe do download python, and > > > does it come with spam or advertisements? > > > > Python is free software, meaning that every recipient is free to improve > > it and redistribute the result. > > > > > > > > Free software rarely has the problems you describe ? spam and > > advertisements ? and never has them for long, because those problems are > > quickly improved (by eradicating the annoying problem), and the improved > > version becomes what people share. > > > > > If it doesn't then should I get the latest version? > > > > The latest stable version is Python 3.3, and this version is strongly > > recommended for people who will be developing with Python. > > > > But you say that you are getting Python because you have some other > > program that requires Python. Which version of Python does it require? > > Download and install the latest version that is supported for the > > program you are wanting to use. > > > > > I mostly want to know if it is safe to download, because most of the > > > time downloading free stuff off the internet comes with spam and all > > > that, so I want to know if I can trust downloading it. > > > > Ah, your experience is with zero-cost non-free software. Non-free > > software is prone to have spam and advertisements, and many other > > problems that arise from disrespect for the recipient's freedom. So your > > caution is well advised. > > > > Know that free software respects your freedom, and Python is free > > software. > > > > > > > > Welcome, and good fortune to you in using Python! > > > > -- > > \ ?I was trying to daydream, but my mind kept wandering.? ?Steven | > > `\ Wright | > > _o__) | > > Ben Finney From none at none.com Mon Sep 9 08:19:11 2013 From: none at none.com (Fattburger) Date: Mon, 09 Sep 2013 12:19:11 GMT Subject: Can I trust downloading Python? Message-ID: <31jXt.43447$Hr1.23199@en-nntp-03.dc1.easynews.com> On Sun, 08 Sep 2013 03:37:15 +0000, Dave Angel wrote: > 1) what OS are you running? Actually, we can be pretty sure you're > running Windows, since any other common operating system would have > already included Python. Plus I don't often run into Linux users who worry about viruses, unless the braces-and-pimples crowd has expanded its horizons recently and started creating malware that does anything in Linux. From steve+comp.lang.python at pearwood.info Mon Sep 9 20:06:04 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Sep 2013 00:06:04 GMT Subject: Can I trust downloading Python? References: <31jXt.43447$Hr1.23199@en-nntp-03.dc1.easynews.com> Message-ID: <522e626c$0$29988$c3e8da3$5496439d@news.astraweb.com> On Mon, 09 Sep 2013 12:19:11 +0000, Fattburger wrote: > On Sun, 08 Sep 2013 03:37:15 +0000, Dave Angel wrote: > >> 1) what OS are you running? Actually, we can be pretty sure you're >> running Windows, since any other common operating system would have >> already included Python. > > Plus I don't often run into Linux users who worry about viruses, unless > the braces-and-pimples crowd has expanded its horizons recently and > started creating malware that does anything in Linux. Hello, the 1990s called and want their stereotypes back. Malware in 2013 is not about loser nerds erasing your hard drive for the lulz. It's a multi-million dollar a year business, mostly driven by spammers, but with small yet profitable niche markets for industrial espionage and blackmail ("we've encrypted your files -- pay us $100 and we'll send you the key"). Plus so-called law enforcement[1] uses it to break into people's computers, for keylogging, etc., and you better believe they have cracks targeted at Linux. Of course, Linux is a much harder target than the average unpatched Windows box, and there are probably easier ways to get access to your files if they really need to. But really, we've learned *nothing* from the viruses of the 1990s. Remember when we used to talk about how crazy it was to download code from untrusted sites on the Internet and execute it? We're still doing it, a hundred times a day. Every time you go on the Internet, you download other people's code and execute it. Javascript, Flash, HTML5, PDF are all either executable, or they include executable components. Now they're *supposed* to be sandboxed, but we've gone from "don't execute untrusted code" to "let's hope my browser doesn't have any bugs that the untrusted code might exploit". The people driving malware these days are not script-kiddies, but professionals, up to and including some of the smartest and most highly funded professionals in the world. Stuxnet anyone? [1] I say "so-called", because far too often the people who are supposed to be upholding the law are actually breaking the law with impunity. -- Steven From oscar.j.benjamin at gmail.com Tue Sep 10 05:45:16 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 10 Sep 2013 10:45:16 +0100 Subject: Can I trust downloading Python? In-Reply-To: <522e626c$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <31jXt.43447$Hr1.23199@en-nntp-03.dc1.easynews.com> <522e626c$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 10 September 2013 01:06, Steven D'Aprano wrote: > On Mon, 09 Sep 2013 12:19:11 +0000, Fattburger wrote: > > But really, we've learned *nothing* from the viruses of the 1990s. > Remember when we used to talk about how crazy it was to download code > from untrusted sites on the Internet and execute it? We're still doing > it, a hundred times a day. Every time you go on the Internet, you > download other people's code and execute it. Javascript, Flash, HTML5, > PDF are all either executable, or they include executable components. Now > they're *supposed* to be sandboxed, but we've gone from "don't execute > untrusted code" to "let's hope my browser doesn't have any bugs that the > untrusted code might exploit". You could have also mentioned pip/PyPI in that. 'pip install X' downloads and runs arbitrary code from a largely unmonitored and uncontrolled code repository. The maintainers of PyPI can only try to ensure that the original author of X would remain in control of what happens and could remove a package X if it were discovered to be malware. However they don't have anything like the resources to monitor all the code coming in so it's essentially a system based on trust in the authors where the only requirement to be an author is that you have an email address. Occasionally I see the suggestion to do 'sudo pip install X' which literally gives root permissions to arbitrary code coming straight from the net. Oscar From rosuav at gmail.com Tue Sep 10 06:05:10 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 10 Sep 2013 20:05:10 +1000 Subject: Can I trust downloading Python? In-Reply-To: <522e626c$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <31jXt.43447$Hr1.23199@en-nntp-03.dc1.easynews.com> <522e626c$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Sep 10, 2013 at 10:06 AM, Steven D'Aprano wrote: > Of course, Linux is a much > harder target than the average unpatched Windows box, and there are > probably easier ways to get access to your files if they really need to. Plus "Linux" isn't a single target. You can search the internet for Windows XP boxes and there's an extremely high chance they'll all be running the same base services; when you're attacking Linux, there's a much MUCH smaller set of common code, with most attacks being aimed at an application - which may or may not be running on any given computer. So there's a lot less chance that you'll be randomly assaulted just for connecting to the internet; the attacks are most likely to come from browsing a site that exploits a Javascript vulnerability. I'm not particularly bothered by the possibility of someone snooping at what I'm doing. Oh how terrible, they'll discover that I'm just as nerdy in private as I am in public... ChrisA From werotizy at freent.dd Tue Sep 10 06:26:55 2013 From: werotizy at freent.dd (Tom P) Date: Tue, 10 Sep 2013 12:26:55 +0200 Subject: Can I trust downloading Python? In-Reply-To: References: <31jXt.43447$Hr1.23199@en-nntp-03.dc1.easynews.com> <522e626c$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 10.09.2013 11:45, Oscar Benjamin wrote: > On 10 September 2013 01:06, Steven D'Aprano > wrote: >> On Mon, 09 Sep 2013 12:19:11 +0000, Fattburger wrote: >> >> But really, we've learned *nothing* from the viruses of the 1990s. >> Remember when we used to talk about how crazy it was to download code >> from untrusted sites on the Internet and execute it? We're still doing >> it, a hundred times a day. Every time you go on the Internet, you >> download other people's code and execute it. Javascript, Flash, HTML5, >> PDF are all either executable, or they include executable components. Now >> they're *supposed* to be sandboxed, but we've gone from "don't execute >> untrusted code" to "let's hope my browser doesn't have any bugs that the >> untrusted code might exploit". > > You could have also mentioned pip/PyPI in that. 'pip install X' > downloads and runs arbitrary code from a largely unmonitored and > uncontrolled code repository. The maintainers of PyPI can only try to > ensure that the original author of X would remain in control of what > happens and could remove a package X if it were discovered to be > malware. However they don't have anything like the resources to > monitor all the code coming in so it's essentially a system based on > trust in the authors where the only requirement to be an author is > that you have an email address. Occasionally I see the suggestion to > do 'sudo pip install X' which literally gives root permissions to > arbitrary code coming straight from the net. > > > Oscar > Interesting observation From steve+comp.lang.python at pearwood.info Tue Sep 10 10:40:37 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Sep 2013 14:40:37 GMT Subject: Can I trust downloading Python? References: <31jXt.43447$Hr1.23199@en-nntp-03.dc1.easynews.com> <522e626c$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <522f2f65$0$29988$c3e8da3$5496439d@news.astraweb.com> On Tue, 10 Sep 2013 10:45:16 +0100, Oscar Benjamin wrote: > On 10 September 2013 01:06, Steven D'Aprano > wrote: [rant about executing code over the internet] > You could have also mentioned pip/PyPI in that. 'pip install X' > downloads and runs arbitrary code from a largely unmonitored and > uncontrolled code repository. The maintainers of PyPI can only try to > ensure that the original author of X would remain in control of what > happens and could remove a package X if it were discovered to be > malware. However they don't have anything like the resources to monitor > all the code coming in so it's essentially a system based on trust in > the authors where the only requirement to be an author is that you have > an email address. Occasionally I see the suggestion to do 'sudo pip > install X' which literally gives root permissions to arbitrary code > coming straight from the net. Sure, but there's a significant difference here. If I were to run "pip install foo", I'm explicitly choosing to trust that code. If I don't trust it, I simply don't run pip install. Merely going to the PyPI website for package "foo" doesn't run foo, nor does viewing the code, or even running "hg update" (or git) on the repository. By default, foo doesn't run unless I explicitly run it. pip is *fail safe* -- if it fails, or if I don't run it, nothing gets executed. In contrast, if I go to foo.com, the default is "everything will run". I have *no idea* what's going to happen until I get there. The default is "run anything, unless explicitly turned off" instead of "don't run, unless explicitly turned on". Even if I run NoScript in my browser, or turn off Javascript in my browser, I'm hoping that there isn't some executable protocol that NoScript doesn't block, or only partially blocks ("What do you mean web fonts contain executable code?"), or maybe I turned Javascript back on so some other site works and forgot to turn it off again. Our browsers are fail unsafe -- if they fail, they can run untrusted code. You can't even say "well if you don't trust foo.com, don't go there" because while foo.com itself might be trusted, they're probably selling advertising, and the advert itself is executable and could come from anyone, anywhere. Imagine that every time you walked into a shop, the shop could instantly, irreversibly and silently deduct whatever amount of money from your credit card it liked, unless you remembered to put your credit card inside a metal wallet before entering the store. But most stores won't let you in if you do, or at least the shopping experience is painful. So we just hope that the store won't take advantage of that ability and rob us blind. That's not too far from the Internet security model. -- Steven From feliphil at gmx.net Tue Sep 10 12:20:48 2013 From: feliphil at gmx.net (Wolfgang Keller) Date: Tue, 10 Sep 2013 18:20:48 +0200 Subject: Can I trust downloading Python? References: <31jXt.43447$Hr1.23199@en-nntp-03.dc1.easynews.com> <522e626c$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20130910182048.9fb5c15137155e8a3d98ddc5@gmx.net> > Every time you go on the Internet, you download other people's code > and execute it. Javascript, Flash, HTML5, PDF are all either > executable, or they include executable components. That's why I deactivate all of these by default. And why I *hate* so-called "web designers" who *require* activation of such fancy flashy nonsense gadgets. PDF files are an exception since PDF was originally designed as a "safe" subset of Postscript (postscript viruses had been demonstrated). Now Adobe has jeopardized this by allowing embedding of Javascript in PDF files (but that as well is deactivated by default for me). Sincerely, Wolfgang From nobody at nowhere.com Mon Sep 9 21:28:45 2013 From: nobody at nowhere.com (Nobody) Date: Tue, 10 Sep 2013 02:28:45 +0100 Subject: Can I trust downloading Python? References: Message-ID: On Sun, 08 Sep 2013 03:37:15 +0000, Dave Angel wrote: > You can run a 32bit Python on 64bit OS, but not the oter way > around. And most people just match the bitness of Python against the > bitness of the OS. AFAICT, most people run 32-bit Python on any version of Windows. [And this isn't limited to Python; most of the software on my Win64 system is 32-bit. And most of the 64-bit software is accounted for by software which has to be 64-bit due to containing device drivers, shell extensions or similar.] Any add-on package which provides pre-compiled binaries will provide 32-bit binaries. Some of them will also provide 64-bit binaries, some of them won't. So unless you think that you might need to use more than 3-4 GiB of RAM for a single Python process, or you need to use certain libraries which are only available as 64-bit, getting the 32-bit version is typically the safest option. From mr.roboto.ny at gmail.com Wed Sep 11 14:05:56 2013 From: mr.roboto.ny at gmail.com (Mr. Roboto) Date: Wed, 11 Sep 2013 11:05:56 -0700 (PDT) Subject: Can I trust downloading Python? In-Reply-To: References: Message-ID: <9ea8d49b-3043-4283-bef3-2f0e41e32461@googlegroups.com> On Saturday, September 7, 2013 9:17:46 PM UTC-4, Aaron Martin wrote: > Hi, I am thinking about getting a software but it requires python, so that brought up a few questions. Is it safe do download python, and does it come with spam or advertisements? If it doesn't then should I get the latest version? I mostly want to know if it is safe?to download, because most of the time?downloading free stuff off the internet comes with?spam and all that, so I want to know if I can trust downloading it. Hope others find this article helpful and relevant: http://www.eweek.com/developer/open-source-python-code-sets-new-standard-for-quality-study.html/?kc=EWKNLEAU09102013BESTOF2&dni=77668545&rni=22939981 A development testing company (Coverity) reports that the core Python platform has a very low number of source code defects and its developers effect repairs to known flaws very readily, as compared to other open-source projects. I can't attest to the validity of the claim (one way or the other), but it is something worth noting.... From bluefielder at gmail.com Sat Sep 7 21:41:50 2013 From: bluefielder at gmail.com (BlueFielder) Date: Sat, 7 Sep 2013 18:41:50 -0700 (PDT) Subject: Help - Python syntax - repeats script through subordinate folders Message-ID: <3f4f33ee-c8e7-4154-a817-c74b26b00301@googlegroups.com> I'm NOT a programmer?. but I have a little Python script that converts files, that are in a folder, from one format to another. Script = fxp2aupreset.py I can successfully run it from the command line: 1st, I placed the folder that I named 'ddd' on the desktop so that it's easy to get to. 2. Terminal : cd ~/Desktop/ddd 3. Then I run the script from terminal : python ./fxp2aupreset.py ./ aumu Alb3 LinP vstdata It executes fine and does it's job. BUT? I have per 7600 files that are segregated into 86 folders. I want to keep this folder structure. So, What I need the script to do is to start at the parent folder (ddd) and then go through each subordinate (child) folder and perform its task on all files. I found this syntax on the web that is somehow supposed to do what I need: for /r %a in (*.fxp) do example.py "%a" BUT ? I have no idea how to combine the syntax. Could someone put this together for me please. Something that I could just copy and paste into Terminal. I would be most grateful. Thank you very much! From rosuav at gmail.com Sat Sep 7 21:56:25 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 8 Sep 2013 11:56:25 +1000 Subject: Help - Python syntax - repeats script through subordinate folders In-Reply-To: <3f4f33ee-c8e7-4154-a817-c74b26b00301@googlegroups.com> References: <3f4f33ee-c8e7-4154-a817-c74b26b00301@googlegroups.com> Message-ID: On Sun, Sep 8, 2013 at 11:41 AM, BlueFielder wrote: > 3. Then I run the script from terminal : python ./fxp2aupreset.py ./ aumu Alb3 LinP vstdata > > It executes fine and does it's job. > > BUT? I have per 7600 files that are segregated into 86 folders. > I want to keep this folder structure. > > So, What I need the script to do is to start at the parent folder (ddd) and then go through each subordinate (child) folder and perform its task on all files. > > I found this syntax on the web that is somehow supposed to do what I need: > > for /r %a in (*.fxp) do example.py "%a" > > BUT ? I have no idea how to combine the syntax. Your initial command and path suggest you're on a Unix-like system (these days that most likely means either Linux or Mac OS), but the FOR command at the end is a Windows command, so that's not going to work. However, Unix does have a find command, so that should work for you. Do you need to run your script once for each file, or once for each directory? Based on your use of "for /r", I'm thinking once per directory. $ find -type d -execdir bash -c 'cd {}; python ./fxp2aupreset.py ./ aumu Alb3 LinP vstdata' \; I'm sure there's a tidier way to do it, but this should work! ChrisA From bluefielder at gmail.com Sat Sep 7 22:52:54 2013 From: bluefielder at gmail.com (BlueFielder) Date: Sat, 7 Sep 2013 19:52:54 -0700 (PDT) Subject: Help - Python syntax - repeats script through subordinate folders In-Reply-To: References: <3f4f33ee-c8e7-4154-a817-c74b26b00301@googlegroups.com> Message-ID: <38324fe2-cbad-4466-a19f-efc0d99f0883@googlegroups.com> On Saturday, September 7, 2013 9:56:25 PM UTC-4, Chris Angelico wrote: > Your initial command and path suggest you're on a Unix-like system > > (these days that most likely means either Linux or Mac OS), but the > > FOR command at the end is a Windows command, so that's not going to > > work. However, Unix does have a find command, so that should work Hi Chris. Thank you so much for your rely. Yes?. I am doing this on a Mac OS > > Do you need to run your script once for each file, or once for each > > directory? Based on your use of "for /r", I'm thinking once per > > directory. I wish to run the script just once on the parent folder?. and have it run through all the 86 subordinate folders that reside in that parent folder. > $ find -type d -execdir bash -c 'cd {}; python ./fxp2aupreset.py ./ > > aumu Alb3 LinP vstdata' \; > > > I'm sure there's a tidier way to do it, but this should work! OK I will try that as soon as I can and post the results. FWIW: I'm not convened with 'tidy' ? as I will only being coin this once. So very kind of you to help. HT to you sir. From bluefielder at gmail.com Sat Sep 7 22:59:59 2013 From: bluefielder at gmail.com (BlueFielder) Date: Sat, 7 Sep 2013 19:59:59 -0700 (PDT) Subject: Help - Python syntax - repeats script through subordinate folders In-Reply-To: <38324fe2-cbad-4466-a19f-efc0d99f0883@googlegroups.com> References: <3f4f33ee-c8e7-4154-a817-c74b26b00301@googlegroups.com> <38324fe2-cbad-4466-a19f-efc0d99f0883@googlegroups.com> Message-ID: <21ac62b9-221a-4180-b759-0a8c73c6ef9c@googlegroups.com> Failed: Here is the command with the results: -------- CiMac:ddd camforx$ $ find -type d -execdir bash -c 'cd {}; python ./fxp2aupreset.py ./ aumu Alb3 LinP vstdata' \; -bash: $: command not found ---------- With CiMac = HD ddd = folder on the desktop of user camforx From rosuav at gmail.com Sat Sep 7 23:01:34 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 8 Sep 2013 13:01:34 +1000 Subject: Help - Python syntax - repeats script through subordinate folders In-Reply-To: <21ac62b9-221a-4180-b759-0a8c73c6ef9c@googlegroups.com> References: <3f4f33ee-c8e7-4154-a817-c74b26b00301@googlegroups.com> <38324fe2-cbad-4466-a19f-efc0d99f0883@googlegroups.com> <21ac62b9-221a-4180-b759-0a8c73c6ef9c@googlegroups.com> Message-ID: On Sun, Sep 8, 2013 at 12:59 PM, BlueFielder wrote: > > Failed: > > Here is the command with the results: > -------- > > CiMac:ddd camforx$ $ find -type d -execdir bash -c 'cd {}; python ./fxp2aupreset.py ./ aumu Alb3 LinP vstdata' \; > -bash: $: command not found Oh! Omit the dollar sign, that was representing your prompt :) ChrisA From bluefielder at gmail.com Sat Sep 7 23:09:44 2013 From: bluefielder at gmail.com (BlueFielder) Date: Sat, 7 Sep 2013 20:09:44 -0700 (PDT) Subject: Help - Python syntax - repeats script through subordinate folders In-Reply-To: References: <3f4f33ee-c8e7-4154-a817-c74b26b00301@googlegroups.com> <38324fe2-cbad-4466-a19f-efc0d99f0883@googlegroups.com> <21ac62b9-221a-4180-b759-0a8c73c6ef9c@googlegroups.com> Message-ID: <6291a5d0-ad20-4689-bc1b-570c9e635108@googlegroups.com> I 'think' I did as you instructed ?. but that too failed. :( CiMac:ddd camforx$ find -type d -execdir bash -c 'cd {}; python ./fxp2aupreset.py ./ aumu Alb3 LinP vstdata' \; find: illegal option -- t usage: find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression] find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression] From torriem at gmail.com Sat Sep 7 23:34:53 2013 From: torriem at gmail.com (Michael Torrie) Date: Sat, 07 Sep 2013 21:34:53 -0600 Subject: Help - Python syntax - repeats script through subordinate folders In-Reply-To: <6291a5d0-ad20-4689-bc1b-570c9e635108@googlegroups.com> References: <3f4f33ee-c8e7-4154-a817-c74b26b00301@googlegroups.com> <38324fe2-cbad-4466-a19f-efc0d99f0883@googlegroups.com> <21ac62b9-221a-4180-b759-0a8c73c6ef9c@googlegroups.com> <6291a5d0-ad20-4689-bc1b-570c9e635108@googlegroups.com> Message-ID: <522BF05D.6050909@gmail.com> On 09/07/2013 09:09 PM, BlueFielder wrote: > I 'think' I did as you instructed ?. but that too failed. :( > > > CiMac:ddd camforx$ find -type d -execdir bash -c 'cd {}; python ./fxp2aupreset.py ./ aumu Alb3 LinP vstdata' \; > find: illegal option -- t > usage: find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression] > find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression] Some versions of find require a path first. Try this (all one line): find . -type d -execdir bash -c 'cd {}; python ./fxp2aupreset.py ./ aumu Alb3 LinP vstdata' \; From rosuav at gmail.com Sat Sep 7 23:37:11 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 8 Sep 2013 13:37:11 +1000 Subject: Help - Python syntax - repeats script through subordinate folders In-Reply-To: <522BF05D.6050909@gmail.com> References: <3f4f33ee-c8e7-4154-a817-c74b26b00301@googlegroups.com> <38324fe2-cbad-4466-a19f-efc0d99f0883@googlegroups.com> <21ac62b9-221a-4180-b759-0a8c73c6ef9c@googlegroups.com> <6291a5d0-ad20-4689-bc1b-570c9e635108@googlegroups.com> <522BF05D.6050909@gmail.com> Message-ID: On Sun, Sep 8, 2013 at 1:34 PM, Michael Torrie wrote: > On 09/07/2013 09:09 PM, BlueFielder wrote: >> I 'think' I did as you instructed ?. but that too failed. :( >> >> >> CiMac:ddd camforx$ find -type d -execdir bash -c 'cd {}; python ./fxp2aupreset.py ./ aumu Alb3 LinP vstdata' \; >> find: illegal option -- t >> usage: find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression] >> find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression] > > Some versions of find require a path first. Try this (all one line): > > find . -type d -execdir bash -c 'cd {}; python ./fxp2aupreset.py ./ > aumu Alb3 LinP vstdata' \; Thanks Michael. I'm using GNU find on Debian Linux (or on Ubuntu, depending on which computer I test on), so I can't be sure what's different. ChrisA From bluefielder at gmail.com Sat Sep 7 23:54:54 2013 From: bluefielder at gmail.com (BlueFielder) Date: Sat, 7 Sep 2013 20:54:54 -0700 (PDT) Subject: Help - Python syntax - repeats script through subordinate folders In-Reply-To: References: <3f4f33ee-c8e7-4154-a817-c74b26b00301@googlegroups.com> <38324fe2-cbad-4466-a19f-efc0d99f0883@googlegroups.com> <21ac62b9-221a-4180-b759-0a8c73c6ef9c@googlegroups.com> <6291a5d0-ad20-4689-bc1b-570c9e635108@googlegroups.com> <522BF05D.6050909@gmail.com> Message-ID: <47fcbf3c-4416-4f47-8070-7baad5fa2cc7@googlegroups.com> Thanks guys ? that too failed. It's late here and I'm bushed. I'll get back to this tomorrow morning. Much appreciated. It's probably important that I point out that I put the file ' fxp2aupreset.py ' in the root directory (ddd) . Just to keep things all together. Again ?. I have NO idea how to do any of this. Also ?the root folder only contains the .py file and subfolders. The subfolders contain 100's of the files that I wish to convert. If you want to take a look at the last results ?. In my DropBox here >> https://dl.dropboxusercontent.com/u/65969526/Results.rtf Good night all, and thank you again. From jsf80238 at gmail.com Sat Sep 7 22:12:34 2013 From: jsf80238 at gmail.com (Jason Friedman) Date: Sat, 7 Sep 2013 20:12:34 -0600 Subject: Weighted choices Message-ID: choices = dict() choices["apple"] = 10 choices["pear"] = 20 choices["banana"] = 15 choices["orange"] = 25 choices["kiwi"] = 30 I want to pick sets of fruit, three in a set, where the chance of selecting a given fruit is proportional to its weight. In the example above, pears should appear twice as often as apples and kiwis should appear twice as often as bananas. I see this solution (http://stackoverflow.com/questions/3679694/a-weighted-version-of-random-choice) but it is for single choices at a time. random.sample() does not provide a "weight" argument. I can picture how to write this with many, many lines of code but I have a feeling there is an elegant solution. From __peter__ at web.de Sun Sep 8 02:13:16 2013 From: __peter__ at web.de (Peter Otten) Date: Sun, 08 Sep 2013 08:13:16 +0200 Subject: Weighted choices References: Message-ID: Jason Friedman wrote: > choices = dict() > choices["apple"] = 10 > choices["pear"] = 20 > choices["banana"] = 15 > choices["orange"] = 25 > choices["kiwi"] = 30 > > I want to pick sets of fruit, three in a set, where the chance of > selecting a given fruit is proportional to its weight. In the example > above, pears should appear twice as often as apples and kiwis should > appear twice as often as bananas. > > I see this solution > (http://stackoverflow.com/questions/3679694/a-weighted-version-of-random- choice) > but it is for single choices at a time. random.sample() does not > provide a "weight" argument. > > I can picture how to write this with many, many lines of code but I > have a feeling there is an elegant solution. Let's assume for a moment that you always have low integral weights. Given data = [] for weight, value in choices.items(): data.extend([value]*weight) picking values with N = 3 sample = [random.choice(data) for i in range(N)] does not give te same probabilities as sample = random.sample(data, N) Which one doe you want? If it's the former, i. e. picking an item does not affect the item's probability, just adapt Raymond Hettinger's def weighted_choice(choices): values, weights = zip(*choices) total = 0 cum_weights = [] for w in weights: total += w cum_weights.append(total) x = random() * total i = bisect(cum_weights, x) return values[i] to (untested) def weighted_choice_iter(choices): values, weights = zip(*choices) total = 0 cum_weights = [] for w in weights: total += w cum_weights.append(total) while True: x = random() * total i = bisect(cum_weights, x) yield values[i] def weighted_choices(choices, N): return list(itertools.islice(weighted_choice_iter(choices), N)) print weighted_choices(choices, 3) From antoon.pardon at rece.vub.ac.be Sun Sep 8 13:48:55 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Sun, 08 Sep 2013 19:48:55 +0200 Subject: Weighted choices In-Reply-To: References: Message-ID: <522CB887.9090000@rece.vub.ac.be> Op 08-09-13 04:12, Jason Friedman schreef: > choices = dict() > choices["apple"] = 10 > choices["pear"] = 20 > choices["banana"] = 15 > choices["orange"] = 25 > choices["kiwi"] = 30 > > I want to pick sets of fruit, three in a set, where the chance of > selecting a given fruit is proportional to its weight. In the example > above, pears should appear twice as often as apples and kiwis should > appear twice as often as bananas. Just a small question. Is a set of three bananas an acceptable outcome? -- Antoon Pardon From cs at zip.com.au Sun Sep 8 20:49:13 2013 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 9 Sep 2013 10:49:13 +1000 Subject: Weighted choices In-Reply-To: References: Message-ID: <20130909004913.GA58240@cskk.homeip.net> On 08Sep2013 20:21, Dennis Lee Bieber wrote: | However, I would not use a dictionary for this. An ordered list should | work better... for small samples a list containing repeats (by weight) of | each choice, and then use a random integer whose range is 0..len(list)-1 | would suffice. | | choices = ["apple", "apple", "apple", ..., "kiwi", "kiwi" ] Scales badly as soon as the weights get even slightly big (or high res). | For longer lists, storing a tuple with the accumulating weight, and | scanning from the beginning | | choices = [(10, "Apple"), (10+20, "Pear"), (10+20+15, "Banana")... ] | | generate random integer in the range of the sum of the weights, and accept | the last tuple whose first element is less than the integer. Search it with the bisect module, not linearly! Cheers, -- Cameron Simpson From antoon.pardon at rece.vub.ac.be Mon Sep 9 03:12:05 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 09 Sep 2013 09:12:05 +0200 Subject: Weighted choices In-Reply-To: References: <522CB887.9090000@rece.vub.ac.be> Message-ID: <522D74C5.6040409@rece.vub.ac.be> Op 09-09-13 02:21, Dennis Lee Bieber schreef: > On Sun, 08 Sep 2013 19:48:55 +0200, Antoon Pardon > declaimed the following: > >> Op 08-09-13 04:12, Jason Friedman schreef: >>> choices = dict() >>> choices["apple"] = 10 >>> choices["pear"] = 20 >>> choices["banana"] = 15 >>> choices["orange"] = 25 >>> choices["kiwi"] = 30 >>> >>> I want to pick sets of fruit, three in a set, where the chance of >>> selecting a given fruit is proportional to its weight. In the example >>> above, pears should appear twice as often as apples and kiwis should >>> appear twice as often as bananas. >> >> Just a small question. Is a set of three bananas an acceptable outcome? > > If we are talking probabilities, regardless of what the weighting is, > it should be probable (if unlikely) to get three-of-a-kind. Why should that be? I'm unfamiliar with any kind of imperative that discourages people from wanting sets with three different kinds of fruit. -- Antoon Pardon From steve at pearwood.info Mon Sep 9 05:11:45 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 09 Sep 2013 09:11:45 GMT Subject: Weighted choices References: <522CB887.9090000@rece.vub.ac.be> Message-ID: <522d90d1$0$29893$c3e8da3$5496439d@news.astraweb.com> On Mon, 09 Sep 2013 09:12:05 +0200, Antoon Pardon wrote: > Op 09-09-13 02:21, Dennis Lee Bieber schreef: >> On Sun, 08 Sep 2013 19:48:55 +0200, Antoon Pardon >> declaimed the following: >> >>> Op 08-09-13 04:12, Jason Friedman schreef: >>>> choices = dict() >>>> choices["apple"] = 10 >>>> choices["pear"] = 20 >>>> choices["banana"] = 15 >>>> choices["orange"] = 25 >>>> choices["kiwi"] = 30 >>>> >>>> I want to pick sets of fruit, three in a set, where the chance of >>>> selecting a given fruit is proportional to its weight. In the >>>> example above, pears should appear twice as often as apples and kiwis >>>> should appear twice as often as bananas. >>> >>> Just a small question. Is a set of three bananas an acceptable >>> outcome? >> >> If we are talking probabilities, regardless of what the weighting is, >> it should be probable (if unlikely) to get three-of-a-kind. > > Why should that be? I'm unfamiliar with any kind of imperative that > discourages people from wanting sets with three different kinds of > fruit. Then that's hardly *random*, is it? Or at least, it is a non-uniform distribution, with much less randomness that a free choice. The OP specifies that the chance of selecting a given fruit is proportional to its weight. That is not the case if you insist each piece of fruit must be different. E.g. consider the case where there are five different kinds of fruit (apple, pear, etc.) and you choose five pieces. You *must* get one each of apple, pear etc., no matter how small the weights are, and so the probability of getting set(apple, pear, banana, orange, kiwi) is exactly 1, even if there are ten million apples to choose from and only one orange. A more important question is, should the selection be done with or without replacement? That is, after selecting by chance an apple, does that mean there is one fewer apple to select next time, and hence the weight need to be slightly reduced? Or is the apple returned to the pool, and the weights remain unchanged? -- Steven From antoon.pardon at rece.vub.ac.be Mon Sep 9 06:01:37 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 09 Sep 2013 12:01:37 +0200 Subject: Weighted choices In-Reply-To: <522d90d1$0$29893$c3e8da3$5496439d@news.astraweb.com> References: <522CB887.9090000@rece.vub.ac.be> <522d90d1$0$29893$c3e8da3$5496439d@news.astraweb.com> Message-ID: <522D9C81.80606@rece.vub.ac.be> Op 09-09-13 11:11, Steven D'Aprano schreef: > On Mon, 09 Sep 2013 09:12:05 +0200, Antoon Pardon wrote: > >> Op 09-09-13 02:21, Dennis Lee Bieber schreef: >>> On Sun, 08 Sep 2013 19:48:55 +0200, Antoon Pardon >>> declaimed the following: >>> >>>> Op 08-09-13 04:12, Jason Friedman schreef: >>>>> choices = dict() >>>>> choices["apple"] = 10 >>>>> choices["pear"] = 20 >>>>> choices["banana"] = 15 >>>>> choices["orange"] = 25 >>>>> choices["kiwi"] = 30 >>>>> >>>>> I want to pick sets of fruit, three in a set, where the chance of >>>>> selecting a given fruit is proportional to its weight. In the >>>>> example above, pears should appear twice as often as apples and kiwis >>>>> should appear twice as often as bananas. >>>> >>>> Just a small question. Is a set of three bananas an acceptable >>>> outcome? >>> >>> If we are talking probabilities, regardless of what the weighting > is, >>> it should be probable (if unlikely) to get three-of-a-kind. >> >> Why should that be? I'm unfamiliar with any kind of imperative that >> discourages people from wanting sets with three different kinds of >> fruit. > > Then that's hardly *random*, is it? Or at least, it is a non-uniform > distribution, with much less randomness that a free choice. I don't see how a problem where one can pick a number of items from a collection, without refilling that collection after each choice makes it that much less random. > The OP specifies that the chance of selecting a given fruit is > proportional to its weight. That is not the case if you insist each piece > of fruit must be different. So? It wouldn't be the first time, a specification wasn't complete or not eniterly what the OP really wanted. As far as I can see, it happens often enough that someone answers the question he thinks the OP wants to ask, instead of the question that was really asked. Noone seems to have a problem with that. So what is the big problem now if I explicitly ask whether that is the case here or not? If the OP had answerd "no", that wouldn't have been a problem, but I'm surprised to get these kind of reactions just for inquiring. > E.g. consider the case where there are five > different kinds of fruit (apple, pear, etc.) and you choose five pieces. > You *must* get one each of apple, pear etc., no matter how small the > weights are, and so the probability of getting set(apple, pear, banana, > orange, kiwi) is exactly 1, even if there are ten million apples to > choose from and only one orange. So? You think it never happened some wanted to solve a problem without a solution? > A more important question is, should the selection be done with or > without replacement? Is it? Because my question and your question are very similar. You see when you just start with one piece of fruit of each at the beginning and you don't replace, the outcome is that you can't get three bananas as outcome. > That is, after selecting by chance an apple, does > that mean there is one fewer apple to select next time, and hence the > weight need to be slightly reduced? Or is the apple returned to the pool, > and the weights remain unchanged? So you don't have any problem with adjusting the weight, ... unless there is only one apple available which would mean the weight would be adjusted to 0. -- Antoon Pardon From __peter__ at web.de Mon Sep 9 05:29:21 2013 From: __peter__ at web.de (Peter Otten) Date: Mon, 09 Sep 2013 11:29:21 +0200 Subject: Weighted choices References: Message-ID: Jason Friedman wrote: [You may have sent this in private mail by accident, so I take the freedom to bring this back to the mailing list] > I'm realizing with your question which was roughly: Do picks from a pool influence probability of subsequent picks, i. e. weather the pool is finite or infinite. > about which I want, though, leads me > to state the actual problem, which takes longer to explain. Giving the actual problem is always a good idea as it allows answers that aren't limited by your grasp of the problem. > I coach a flag football team of 11-year-olds. A stated goal of the > league is that every player should get nearly equal playing time and > that winning is of secondary importance. That said, some players just > can't throw the ball at all, and having a quarterback who cannot throw > is no fun for anyone. The other coach and I will pick two players who > will be the quarterback for any given snap. The other players can play > any position (center, receiver, runner) other than quarterback. > > The game is 5-on-5 and our roster contains ten players, and we can > expect a random player or two missing on any given week. I'm trying > to come up with a system that causes at least one of those > quarterbacks to be on the offensive field on every play. Further, to > compensate for the fact that the quarterback gets to touch the ball on > every play, we want the quarterbacks to appear at the non-quarterback > positions somewhat less than the other players. > > This is all quite challenging. 11-year-olds are exquisitely tuned to > unfairness and most have a keen idea of the play that will surely > score a touchdown if only the clueless coach would let them run it. > Oh, and the originator of this play will be the key > quarterback/runner/receiver for the play. Oh, and in case the coach > forgets, they will remind him. OK, you're well inside the "finite" domain. Also, you probably want less than the "natural" randomness. I'd probably shuffle the potential quarterbacks and the others in independent lists, and then pick one half of each to form a team. The other half would play in the next game. Additionally you can keep track of every player's total number of games and games not played in a row, and apply a correction if either exceeds a limit acceptable for a kid. As for the actual position in the team, that a least should be left for the coach to decide. Personally I would prefer to have some discussion between the kids with the coach having an eye on the shy or not-so-popular ones -- and if that leads to more lost games than necessary, so be it. From jsf80238 at gmail.com Mon Sep 9 22:27:39 2013 From: jsf80238 at gmail.com (Jason Friedman) Date: Mon, 9 Sep 2013 20:27:39 -0600 Subject: Weighted choices In-Reply-To: References: Message-ID: >> I coach a flag football team of 11-year-olds. A stated goal of the >> league is that every player should get nearly equal playing time and >> that winning is of secondary importance. That said, some players just >> can't throw the ball at all, and having a quarterback who cannot throw >> is no fun for anyone. The other coach and I will pick two players who >> will be the quarterback for any given snap. The other players can play >> any position (center, receiver, runner) other than quarterback. >> >> The game is 5-on-5 and our roster contains ten players, and we can >> expect a random player or two missing on any given week. I'm trying >> to come up with a system that causes at least one of those >> quarterbacks to be on the offensive field on every play. Further, to >> compensate for the fact that the quarterback gets to touch the ball on >> every play, we want the quarterbacks to appear at the non-quarterback >> positions somewhat less than the other players. >> >> This is all quite challenging. 11-year-olds are exquisitely tuned to >> unfairness and most have a keen idea of the play that will surely >> score a touchdown if only the clueless coach would let them run it. >> Oh, and the originator of this play will be the key >> quarterback/runner/receiver for the play. Oh, and in case the coach >> forgets, they will remind him. > > OK, you're well inside the "finite" domain. Also, you probably want less > than the "natural" randomness. I'd probably shuffle the potential > quarterbacks and the others in independent lists, and then pick one half of > each to form a team. The other half would play in the next game. > Additionally you can keep track of every player's total number of games and > games not played in a row, and apply a correction if either exceeds a limit > acceptable for a kid. PIcking half to play one game and half to play the other is not an option. For one, there really isn't a concept of half when a variable number of players are available on a given Saturday. For two, we could have an unexpected absence, or during the game an injury. For three, the parents paid to have their child play in the league, and the league runs until the end of October, not long enough for that strategy to work out. From antoon.pardon at rece.vub.ac.be Tue Sep 10 03:15:46 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 10 Sep 2013 09:15:46 +0200 Subject: Weighted choices In-Reply-To: References: Message-ID: <522EC722.9080606@rece.vub.ac.be> Op 10-09-13 04:27, Jason Friedman schreef: >>> I coach a flag football team of 11-year-olds. A stated goal of the >>> league is that every player should get nearly equal playing time and >>> that winning is of secondary importance. That said, some players just >>> can't throw the ball at all, and having a quarterback who cannot throw >>> is no fun for anyone. The other coach and I will pick two players who >>> will be the quarterback for any given snap. The other players can play >>> any position (center, receiver, runner) other than quarterback. >>> >>> The game is 5-on-5 and our roster contains ten players, and we can >>> expect a random player or two missing on any given week. I'm trying >>> to come up with a system that causes at least one of those >>> quarterbacks to be on the offensive field on every play. Further, to >>> compensate for the fact that the quarterback gets to touch the ball on >>> every play, we want the quarterbacks to appear at the non-quarterback >>> positions somewhat less than the other players. >>> >>> This is all quite challenging. 11-year-olds are exquisitely tuned to >>> unfairness and most have a keen idea of the play that will surely >>> score a touchdown if only the clueless coach would let them run it. >>> Oh, and the originator of this play will be the key >>> quarterback/runner/receiver for the play. Oh, and in case the coach >>> forgets, they will remind him. >> >> OK, you're well inside the "finite" domain. Also, you probably want less >> than the "natural" randomness. I'd probably shuffle the potential >> quarterbacks and the others in independent lists, and then pick one half of >> each to form a team. The other half would play in the next game. >> Additionally you can keep track of every player's total number of games and >> games not played in a row, and apply a correction if either exceeds a limit >> acceptable for a kid. > > PIcking half to play one game and half to play the other is not an > option. For one, there really isn't a concept of half when a variable > number of players are available on a given Saturday. For two, we > could have an unexpected absence, or during the game an injury. For > three, the parents paid to have their child play in the league, and > the league runs until the end of October, not long enough for that > strategy to work out. First pick a quarterback, Then for picking players, I would start with giving each player some weight. After each game you adjust those weights. Those that were fielded get their weight adjusted down. Those who were not get their weight adjusted up. You might choose to adjust those that were absent too, maybe up but not us much as those present but not fielded, with an upper limit of double starting weight. Since the quarterbacks are fielded more, their weight will be less when you pick the rest of the team, so they will play less at other positions. Starting weights and adjustment will have to be picked by simulating a season and see what works. -- Antoon Pardon From oscar.j.benjamin at gmail.com Tue Sep 10 06:27:45 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 10 Sep 2013 11:27:45 +0100 Subject: Weighted choices In-Reply-To: References: Message-ID: On 10 September 2013 03:27, Jason Friedman wrote: >> >> OK, you're well inside the "finite" domain. Also, you probably want less >> than the "natural" randomness. I'd probably shuffle the potential >> quarterbacks and the others in independent lists, and then pick one half of >> each to form a team. The other half would play in the next game. >> Additionally you can keep track of every player's total number of games and >> games not played in a row, and apply a correction if either exceeds a limit >> acceptable for a kid. > > PIcking half to play one game and half to play the other is not an > option. For one, there really isn't a concept of half when a variable > number of players are available on a given Saturday. For two, we > could have an unexpected absence, or during the game an injury. For > three, the parents paid to have their child play in the league, and > the league runs until the end of October, not long enough for that > strategy to work out. Don't take the "pick half" idea so literally. Look at it a different way: attempt to form a team from all the players who didn't play in the last game. If that group of players isn't enough to form a team then they're all in the team and the remainder is chosen randomly from those that did play in the last game. Here's a concrete example: Dave hasn't played for 3 games John, Bob and Steve haven't played for 2 games Baz, Joe and Tom haven't played for 1 game James and Tim played the last game. Those are all the players that could make it on Saturday but you need to choose 6. You want either of Bob or Tim for quarterback. Bob hasn't played for longer so you choose him. Obviously Dave's in because he hasn't played for longer than everyone else. That's not enough for a team though so you'll need John and Tom as well. That makes 4 so you need 2 more. However there are three players left that didn't play in the last game. At this point you put their three names in a hat and draw out 2 giving Baz and Tom. So Joe has to sit this one out but he's pretty much definitely in the next game. Rather than drawing names out of a hat, you could use the total number of games played as a tiebreaker and only resort to coin-flipping or whatever when you get a tie for that as well. You could do the same for quarterback selection as well but based on how often they've been quarterback and then how many games they've played and then flip a coin. This algorithm is not really that random but since it depends on who's available on what day it will probably jumble up the teams over time at the same time as being broadly fair to each of the children. For the quarterbacks you'll always be picking the ones that played least recently so as long as your quarterback pool is oversized in proportion to the number of players they'll end up playing as much as everyone else. i.e. if a team has 1 quarterback and 5 players then your total quarterback pool should be more than 1/5 of the total player pool (this is also probably necessary to guarantee having a quarterback anyway). Oscar From anikom15 at gmail.com Mon Sep 9 01:14:05 2013 From: anikom15 at gmail.com (=?ISO-8859-1?Q?Westley_Mart=EDnez?=) Date: Sun, 8 Sep 2013 22:14:05 -0700 (PDT) Subject: Building tkinter on Windows Message-ID: <6df18f7b-d8d1-4fd3-b9dc-6a06e46fb04b@googlegroups.com> Hello. Can anyone tell me how to build tkinter on Windows? I've downloaded the source, ran Tools/buildbot/external.bat to build the external dependencies. I copied tcl85g.dll and tk85g.dll to PCBuild. I built the Visual Studio solution. Everything built fine without errors. Everything seems to work except tkinter. It says: Traceback (most recent call last): File "", line 1, in File "...\cpython-idle\lib\tkinter\__init__.py", line 36, in from tkinter import _fix File "...\cpython-idle\lib\tkinter\_fix.py", line 65, in import _tkinter ImportError: DLL load failed: The specified module could not be found. I'm thinking I didn't put the DLLs in the right place, but I don't have any idea where to put them and Google isn't helping. From tjreedy at udel.edu Mon Sep 9 03:43:16 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 09 Sep 2013 03:43:16 -0400 Subject: Building tkinter on Windows In-Reply-To: <6df18f7b-d8d1-4fd3-b9dc-6a06e46fb04b@googlegroups.com> References: <6df18f7b-d8d1-4fd3-b9dc-6a06e46fb04b@googlegroups.com> Message-ID: On 9/9/2013 1:14 AM, Westley Mart?nez wrote: > Hello. Can anyone tell me how to build tkinter on Windows? I've downloaded the source, ran Tools/buildbot/external.bat to build the external dependencies. I copied tcl85g.dll and tk85g.dll to PCBuild. I built the Visual Studio solution. Everything built fine without errors. Everything seems to work except tkinter. It says: > > Traceback (most recent call last): > File "", line 1, in > File "...\cpython-idle\lib\tkinter\__init__.py", line 36, in > from tkinter import _fix > File "...\cpython-idle\lib\tkinter\_fix.py", line 65, in > import _tkinter > ImportError: DLL load failed: The specified module could not be found. > > I'm thinking I didn't put the DLLs in the right place, but I don't have any idea where to put them and Google isn't helping. Some combination of the README instructions, external.bat, and the project files are not correct. There may be an issue on the tracker. I believe I copied tcl85g.dll and tk85g.dll into .../py3x/pcbuild from .../tcltk/bin and that resolved the problem for me. But you say you did that. Did _tkinter_d.pyd get built (in pcbuild)? -- Terry Jan Reedy From anikom15 at gmail.com Tue Sep 10 01:51:24 2013 From: anikom15 at gmail.com (=?ISO-8859-1?Q?Westley_Mart=EDnez?=) Date: Mon, 9 Sep 2013 22:51:24 -0700 (PDT) Subject: Building tkinter on Windows In-Reply-To: References: <6df18f7b-d8d1-4fd3-b9dc-6a06e46fb04b@googlegroups.com> Message-ID: <2168578f-1183-4bcc-a2f2-828d9faef0c2@googlegroups.com> On Monday, September 9, 2013 12:43:16 AM UTC-7, Terry Reedy wrote: > Some combination of the README instructions, external.bat, and the > > project files are not correct. There may be an issue on the tracker. I > > believe I copied tcl85g.dll and tk85g.dll into .../py3x/pcbuild from > > .../tcltk/bin and that resolved the problem for me. But you say you did > > that. Did _tkinter_d.pyd get built (in pcbuild)? Well, after doing a clean clone and rebuilding everything it worked. I'm not sure what the issue was, but something must've went wrong the first time. I see you've opened an issue about this. I think the README definitely needs to be updated. It's not very user friendly and is somewhat ambiguous. Also, I think the dev guide could be improved as well. I think Windows users (actually, I'm more of Linux user, but whatever) tend to get the short end of the stick in a lot of open-source projects. I think that's a trend that needs to change. From mohsen at pahlevanzadeh.org Mon Sep 9 01:15:16 2013 From: mohsen at pahlevanzadeh.org (Mohsen Pahlevanzadeh) Date: Mon, 09 Sep 2013 09:45:16 +0430 Subject: Logical error in filling QTableWidget and filling all of nodes Message-ID: <1378703716.6005.47.camel@debian> Dear All, I have the following code (PyQt): ///////////////// searchFrameObject.tableWidget.setRowCount(rowCounter) searchFrameObject.tableWidget.setColumnCount(5) for row in range(rowCounter): for column in range(5): for result in query: item = QtGui.QTableWidgetItem(_fromUtf8(result.name)) item.setFlags(item.flags() ^ QtCore.Qt.ItemIsEnabled) searchFrameObject.tableWidget.setItem(row,column,item) #item = QtGui.QTableWidgetItem(String(result.bought_price)) #item.setFlags(item.flags() ^ QtCore.Qt.ItemIsEnabled) #searchFrameObject.tableWidget.setItem(row,column+1,item) #item = QtGui.QTableWidgetItem(result.bought_date) #item.setFlags(item.flags() ^ QtCore.Qt.ItemIsEnabled) #searchFrameObject.tableWidget.setItem(row,column+2,item) item = QtGui.QTableWidgetItem(result.stock) item.setFlags(item.flags() ^ QtCore.Qt.ItemIsEnabled) searchFrameObject.tableWidget.setItem(row,column+3,item) item = QtGui.QTableWidgetItem(result.minimum_bound) item.setFlags(item.flags() ^ QtCore.Qt.ItemIsEnabled) searchFrameObject.tableWidget.setItem(row,column+4,item) //////////////// When i search in DB, i print result.name or print result.stock , everything is OK. But when i import them into QtableWidget i see just node result.name addeed to widgets. (all of nodes filled from result.name) My Question is , How i fill rows and columns with my fields? Yours, Mohsen From python at mrabarnett.plus.com Mon Sep 9 07:24:04 2013 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 09 Sep 2013 12:24:04 +0100 Subject: Logical error in filling QTableWidget and filling all of nodes In-Reply-To: <1378703716.6005.47.camel@debian> References: <1378703716.6005.47.camel@debian> Message-ID: <522DAFD4.4030901@mrabarnett.plus.com> On 09/09/2013 06:15, Mohsen Pahlevanzadeh wrote: > Dear All, > > I have the following code (PyQt): > > ///////////////// > searchFrameObject.tableWidget.setRowCount(rowCounter) > searchFrameObject.tableWidget.setColumnCount(5) > > for row in range(rowCounter): > for column in range(5): > for result in query: > > item = QtGui.QTableWidgetItem(_fromUtf8(result.name)) > item.setFlags(item.flags() ^ QtCore.Qt.ItemIsEnabled) > searchFrameObject.tableWidget.setItem(row,column,item) > > #item = QtGui.QTableWidgetItem(String(result.bought_price)) > #item.setFlags(item.flags() ^ QtCore.Qt.ItemIsEnabled) > #searchFrameObject.tableWidget.setItem(row,column+1,item) > > #item = QtGui.QTableWidgetItem(result.bought_date) > #item.setFlags(item.flags() ^ QtCore.Qt.ItemIsEnabled) > #searchFrameObject.tableWidget.setItem(row,column+2,item) > > item = QtGui.QTableWidgetItem(result.stock) > item.setFlags(item.flags() ^ QtCore.Qt.ItemIsEnabled) > searchFrameObject.tableWidget.setItem(row,column+3,item) > > item = QtGui.QTableWidgetItem(result.minimum_bound) > item.setFlags(item.flags() ^ QtCore.Qt.ItemIsEnabled) > searchFrameObject.tableWidget.setItem(row,column+4,item) > //////////////// > > When i search in DB, i print result.name or print result.stock , > everything is OK. But when i import them into QtableWidget i see just > node result.name addeed to widgets. (all of nodes filled from > result.name) > > My Question is , How i fill rows and columns with my fields? > I don't understand why you're iterating across the columns: for column in range(5): and also setting multiple columns on each iteration: searchFrameObject.tableWidget.setItem(row,column,item) ... searchFrameObject.tableWidget.setItem(row,column+3,item) ... searchFrameObject.tableWidget.setItem(row,column+4,item) That means that: when 'column' is 0 you're setting column 0 to result.name, column 3 to result.stock, and column 4 to result.minimum_bound; when 'column' is 1 you're setting column 1 to result.name, column 4 to result.stock, and column 5 to result.minimum_bound; etc. From none at none.com Mon Sep 9 08:22:39 2013 From: none at none.com (Fattburger) Date: Mon, 09 Sep 2013 12:22:39 GMT Subject: anyone trying out the alpha? Message-ID: I just read that Python 3.4.0a is out in alpha. Any of you going to try it out? I don't have any bright ideas for testing it, myself. From tjreedy at udel.edu Mon Sep 9 11:10:02 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 09 Sep 2013 11:10:02 -0400 Subject: anyone trying out the alpha? In-Reply-To: References: Message-ID: On 9/9/2013 8:22 AM, Fattburger wrote: > I just read that Python 3.4.0a is out in alpha. Any of you going to try > it out? 3.4.0whatever is essentially 3.3.2 with additional bug fixes that will also appear in 3.3.3 plus a few additional bugfixes that were not backported plus new features. The only things 'unstable', compared to previous releases, are the new features. For one thing, the APIs may still be changed. > I don't have any bright ideas for testing it, myself. If you have any code with automated tests, it is good idea to run them now with the alpha. -- Terry Jan Reedy From larry at hastings.org Mon Sep 9 08:02:27 2013 From: larry at hastings.org (Larry Hastings) Date: Mon, 09 Sep 2013 21:02:27 +0900 Subject: [RELEASED] Python 3.4.0a2 Message-ID: <522DB8D3.1030803@hastings.org> On behalf of the Python development team, I'm chuffed to announce the second alpha release of Python 3.4. This is a preview release, and its use is not recommended for production settings. Python 3.4 includes a range of improvements of the 3.x series, including hundreds of small improvements and bug fixes. Major new features and changes in the 3.4 release series so far include: * PEP 435, a standardized "enum" module * PEP 442, improved semantics for object finalization * PEP 443, adding single-dispatch generic functions to the standard library * PEP 445, a new C API for implementing custom memory allocators * PEP 446, changing file descriptors to not be inherited by default in subprocesses * PEP 447, a new magic method for metaclasses (``__typelookup__``) * PEP 448, making automatic sequence unpacking more general To download Python 3.4.0a2 visit: http://www.python.org/download/releases/3.4.0/ Please consider trying Python 3.4.0a2 with your code and reporting any issues you notice to: http://bugs.python.org/ Enjoy! -- Larry Hastings, Release Manager larry at hastings.org (on behalf of the entire python-dev team and 3.4's contributors) From brett at python.org Mon Sep 9 08:16:06 2013 From: brett at python.org (Brett Cannon) Date: Mon, 9 Sep 2013 08:16:06 -0400 Subject: [python-committers] [RELEASED] Python 3.4.0a2 In-Reply-To: <522DB8D3.1030803@hastings.org> References: <522DB8D3.1030803@hastings.org> Message-ID: On Mon, Sep 9, 2013 at 8:02 AM, Larry Hastings wrote: > > On behalf of the Python development team, I'm chuffed to announce the > second alpha release of Python 3.4. > > This is a preview release, and its use is not recommended for > production settings. > > Python 3.4 includes a range of improvements of the 3.x series, including > hundreds of small improvements and bug fixes. Major new features and > changes in the 3.4 release series so far include: > > * PEP 435, a standardized "enum" module > * PEP 442, improved semantics for object finalization > * PEP 443, adding single-dispatch generic functions to the standard library > * PEP 445, a new C API for implementing custom memory allocators > * PEP 446, changing file descriptors to not be inherited by default > in subprocesses > * PEP 447, a new magic method for metaclasses (``__typelookup__``) > * PEP 448, making automatic sequence unpacking more general > Those last two PEPs are still in draft form and not accepted nor have any committed code yet. -------------- next part -------------- An HTML attachment was scrubbed... URL: From solipsis at pitrou.net Mon Sep 9 08:30:08 2013 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 9 Sep 2013 14:30:08 +0200 Subject: [RELEASED] Python 3.4.0a2 References: <522DB8D3.1030803@hastings.org> Message-ID: <20130909143008.55385087@pitrou.net> Le Mon, 9 Sep 2013 08:16:06 -0400, Brett Cannon a ?crit : > On Mon, Sep 9, 2013 at 8:02 AM, Larry Hastings > wrote: > > > > > On behalf of the Python development team, I'm chuffed to announce > > the second alpha release of Python 3.4. > > > > This is a preview release, and its use is not recommended for > > production settings. > > > > Python 3.4 includes a range of improvements of the 3.x series, > > including hundreds of small improvements and bug fixes. Major new > > features and changes in the 3.4 release series so far include: > > > > * PEP 435, a standardized "enum" module > > * PEP 442, improved semantics for object finalization > > * PEP 443, adding single-dispatch generic functions to the standard > > library > > * PEP 445, a new C API for implementing custom memory allocators > > * PEP 446, changing file descriptors to not be inherited by default > > in subprocesses > > * PEP 447, a new magic method for metaclasses (``__typelookup__``) > > * PEP 448, making automatic sequence unpacking more general > > > > Those last two PEPs are still in draft form and not accepted nor have > any committed code yet. Unless Larry enthusiastically sneaked them into the release. Regards Antoine. From larry at hastings.org Mon Sep 9 09:40:34 2013 From: larry at hastings.org (Larry Hastings) Date: Mon, 09 Sep 2013 22:40:34 +0900 Subject: [RELEASED] Python 3.4.0a2 In-Reply-To: <20130909143008.55385087@pitrou.net> References: <522DB8D3.1030803@hastings.org> <20130909143008.55385087@pitrou.net> Message-ID: <522DCFD2.1000907@hastings.org> On 09/09/2013 09:30 PM, Antoine Pitrou wrote: > Le Mon, 9 Sep 2013 08:16:06 -0400, > Brett Cannon a ?crit : >> Those last two PEPs are still in draft form and not accepted nor have >> any committed code yet. > Unless Larry enthusiastically sneaked them into the release. Whoops. Nope, I'm not that enthusiastic. I'll remove it from the web site, but obviously I can't do anything about the announcement. //arry/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From victor.stinner at gmail.com Mon Sep 9 08:30:50 2013 From: victor.stinner at gmail.com (Victor Stinner) Date: Mon, 9 Sep 2013 14:30:50 +0200 Subject: [python-committers] [RELEASED] Python 3.4.0a2 In-Reply-To: <522DB8D3.1030803@hastings.org> References: <522DB8D3.1030803@hastings.org> Message-ID: 2013/9/9 Larry Hastings : > Python 3.4 includes a range of improvements of the 3.x series, including > hundreds of small improvements and bug fixes. Major new features and > changes in the 3.4 release series so far include: > > * PEP 446, changing file descriptors to not be inherited by default > in subprocesses The title of the PEP is "Make newly created file descriptors non-inheritable". It has an impact on all functions creating files and sockets not only the subprocess module. You can also add a link to the nice What?s New In Python 3.4 document: http://docs.python.org/dev/whatsnew/3.4.html Victor From solipsis at pitrou.net Mon Sep 9 08:45:51 2013 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 9 Sep 2013 14:45:51 +0200 Subject: [python-committers] [RELEASED] Python 3.4.0a2 References: <522DB8D3.1030803@hastings.org> Message-ID: <20130909144551.76b84640@pitrou.net> Le Mon, 9 Sep 2013 14:30:50 +0200, Victor Stinner a ?crit : > 2013/9/9 Larry Hastings : > > Python 3.4 includes a range of improvements of the 3.x series, > > including hundreds of small improvements and bug fixes. Major new > > features and changes in the 3.4 release series so far include: > > > > * PEP 446, changing file descriptors to not be inherited by default > > in subprocesses > > The title of the PEP is "Make newly created file descriptors > non-inheritable". It has an impact on all functions creating files and > sockets not only the subprocess module. I don't think Larry's description is wrong. "Non-inheritable" is a shorthand for "non-inheritable in subprocesses" with "subprocesses" taken in the general sense (i.e. not only created with the subprocess module). Regards Antoine. From victor.stinner at gmail.com Mon Sep 9 15:51:46 2013 From: victor.stinner at gmail.com (Victor Stinner) Date: Mon, 9 Sep 2013 21:51:46 +0200 Subject: [python-committers] [RELEASED] Python 3.4.0a2 In-Reply-To: <20130909144551.76b84640@pitrou.net> References: <522DB8D3.1030803@hastings.org> <20130909144551.76b84640@pitrou.net> Message-ID: 2013/9/9 Antoine Pitrou : > Le Mon, 9 Sep 2013 14:30:50 +0200, > Victor Stinner a ?crit : >> 2013/9/9 Larry Hastings : >> > Python 3.4 includes a range of improvements of the 3.x series, >> > including hundreds of small improvements and bug fixes. Major new >> > features and changes in the 3.4 release series so far include: >> > >> > * PEP 446, changing file descriptors to not be inherited by default >> > in subprocesses >> >> The title of the PEP is "Make newly created file descriptors >> non-inheritable". It has an impact on all functions creating files and >> sockets not only the subprocess module. > > I don't think Larry's description is wrong. "Non-inheritable" is a > shorthand for "non-inheritable in subprocesses" with "subprocesses" > taken in the general sense (i.e. not only created with the subprocess > module). Oh, I misunderstood "in subprocesses", I read "in the subprocess module". The definition of FD inheritance is tricky. For example, on UNIX "non-inheritable" file descriptors are still inherited at fork :-) I hope that the documentation is explicit enough: http://docs.python.org/dev/library/os.html#inheritance-of-file-descriptors Victor From ishish at domhain.de Mon Sep 9 08:48:06 2013 From: ishish at domhain.de (ishish) Date: Mon, 09 Sep 2013 13:48:06 +0100 Subject: [RELEASED] Python 3.4.0a2 In-Reply-To: <522DB8D3.1030803@hastings.org> References: <522DB8D3.1030803@hastings.org> Message-ID: <3b9408860bab450d7d8fdf87ce864af2@home.minuskel.de> Am 09.09.2013 13:02, schrieb Larry Hastings: > > To download Python 3.4.0a2 visit: > > http://www.python.org/download/releases/3.4.0/ [quote] Python 3.4.0 alpha 2 was released on September 10th, 2013... [/quote] Import from __future__ ?? ;-) From mahsan9861 at gmail.com Mon Sep 9 12:36:21 2013 From: mahsan9861 at gmail.com (mahsan9861 at gmail.com) Date: Mon, 9 Sep 2013 09:36:21 -0700 (PDT) Subject: python REST API access fails after adding date to URL Message-ID: <37fa354c-691c-45f9-ab31-807f86340e4d@googlegroups.com> Hi, So the REST API calls work great with out the URL appended to the URL.However as soon as I do add the URL, because I want to retrieve the data on a daily basis, the calls fail and the server will return a 401 and say signature invalid.The code is below: import oauth2 as oauth import time from random import getrandbits from base64 import b64encode import hashlib import urllib import hmac import base64 import urllib2 import httplib import requests CONSUMER_KEY='xxxx' CONSUMER_SECRET='xxxx' TOKEN_KEY='xxxx' TOKEN_SECRET='xxxx' def getURL(baseURL,params): sortedParams = sorted(params.items()) for head in sortedParams: print head[0] print head[1] baseURL += '&' + head[0] + '="' + head[1] + '"' print baseURL return baseURL #set header parameters http_headers = {} http_headers['oauth_version'] = '1.0' http_headers['oauth_nonce'] = oauth.generate_nonce() http_headers['oauth_consumer_key'] = CONSUMER_KEY http_headers['oauth_signature_method'] = 'HMAC-SHA1' http_headers['oauth_token'] = TOKEN_KEY http_headers['oauth_timestamp'] = str(int(time.time())) #base url base_url = 'https://dacv.liveperson.net/dataAccess/account/accountNumber/visitorSession' #sort headers in lexicographical order and encode url params = urllib.urlencode(sorted(http_headers.items())) encoded_url = urllib.quote_plus(base_url) #generate base string with all headers,encoded and ready to generate signature signature_base_string = 'GET&' + encoded_url + '&' + urllib.quote_plus(params) #generate signiture key = CONSUMER_SECRET + '&' + TOKEN_SECRET hashed = hmac.new(key, signature_base_string, hashlib.sha1) http_headers['oauth_signature'] = urllib.quote_plus(base64.b64encode(hashed.digest())) #set up header oauth_header = 'OAuth oauth_consumer_key="' + http_headers['oauth_consumer_key'] + '",' +'oauth_nonce="' + http_headers['oauth_nonce'] + '",' +'oauth_signature_method="' + http_headers['oauth_signature_method'] + '",' +'oauth_token="' + http_headers['oauth_token'] + '",' +'oauth_timestamp="' + http_headers['oauth_timestamp'] + '",' +'oauth_version="' + http_headers['oauth_version'] + '",' +'oauth_signature="' + http_headers['oauth_signature'] + '"' req = urllib2.Request(base_url) req.add_header('Authorization',oauth_header) response = urllib2.urlopen(req) print response From dieter at handshake.de Tue Sep 10 02:15:43 2013 From: dieter at handshake.de (dieter) Date: Tue, 10 Sep 2013 08:15:43 +0200 Subject: python REST API access fails after adding date to URL References: <37fa354c-691c-45f9-ab31-807f86340e4d@googlegroups.com> Message-ID: <87d2ohw6b4.fsf@handshake.de> mahsan9861 at gmail.com writes: > So the REST API calls work great with out the URL appended to the URL.However as soon as I do add the URL, because I want to retrieve the data on a daily basis, the calls fail and the server will return a 401 and say signature invalid. Apparently, you do something wrong with the signing. It is highly likely that you must append any request parameters (as a query string) to the url before you determine the signature. Alternatively, the web service you contact might not expect a query string and might therefore not consider it when it recreates the signature. Then, the signature check would fail as you and the service compute it in a different way. Check the available documentation for your web service. Does it support request parameters (query strings). What does it (or the "oauth" spec) about signature requirements for those parameters. From mahsan9861 at gmail.com Tue Sep 10 10:33:39 2013 From: mahsan9861 at gmail.com (mahsan9861 at gmail.com) Date: Tue, 10 Sep 2013 07:33:39 -0700 (PDT) Subject: python REST API access fails after adding date to URL In-Reply-To: References: <37fa354c-691c-45f9-ab31-807f86340e4d@googlegroups.com> Message-ID: <8a64d6c4-dd35-4f0e-88a2-8b5c2f093ac5@googlegroups.com> Sorry about the typo I meant append the date to the URL. So at the end of the current URL adding ?date=ddmmyyyy. But I will go through the documentation to see if I missed anything, but as far as I remember it said to just append the date in that format. From mahsan9861 at gmail.com Tue Sep 10 11:42:31 2013 From: mahsan9861 at gmail.com (mahsan9861 at gmail.com) Date: Tue, 10 Sep 2013 08:42:31 -0700 (PDT) Subject: python REST API access fails after adding date to URL In-Reply-To: <8a64d6c4-dd35-4f0e-88a2-8b5c2f093ac5@googlegroups.com> References: <37fa354c-691c-45f9-ab31-807f86340e4d@googlegroups.com> <8a64d6c4-dd35-4f0e-88a2-8b5c2f093ac5@googlegroups.com> Message-ID: Found a solution. For query string you have to add it to both the http_headers dictionary AND to the URL when making the Request.

old line:

http_headers = {} http_headers['oauth_version'] = '1.0'

new line:

http_headers = {} http_headers['date'] = 'ddmmyyyy' #add this line http_headers['oauth_version'] = '1.0'

old line:

req = urllib2.Request(base_url)

new line:

req = urllib2.Request(base_url + '?date=ddmmyyyy') From mahsan9861 at gmail.com Tue Sep 10 11:44:41 2013 From: mahsan9861 at gmail.com (mahsan9861 at gmail.com) Date: Tue, 10 Sep 2013 08:44:41 -0700 (PDT) Subject: python REST API access fails after adding date to URL In-Reply-To: <8a64d6c4-dd35-4f0e-88a2-8b5c2f093ac5@googlegroups.com> References: <37fa354c-691c-45f9-ab31-807f86340e4d@googlegroups.com> <8a64d6c4-dd35-4f0e-88a2-8b5c2f093ac5@googlegroups.com> Message-ID: <381d34a8-36a7-4982-9816-36aee397b9e0@googlegroups.com> Found a solution. For query string you have to add it to both the http_headers dictionary AND to the URL when making the Request. old line: http_headers = {} http_headers['oauth_version'] = '1.0' new line: http_headers = {} http_headers['date'] = 'ddmmyyyy' #add this line http_headers['oauth_version'] = '1.0' old line: req = urllib2.Request(base_url) new line: req = urllib2.Request(base_url + '?date=ddmmyyyy') Everything else remains the same. From eamonnrea at gmail.com Mon Sep 9 13:39:43 2013 From: eamonnrea at gmail.com (eamonnrea at gmail.com) Date: Mon, 9 Sep 2013 10:39:43 -0700 (PDT) Subject: Monitor key presses in Python? Message-ID: <57051d11-abd9-4621-9618-1574cd37545c@googlegroups.com> Is there a way to detect if the user presses a key in Python that works on most OS's? I've only seen 1 method, and that only works in Python 2.6 and less. If you get the key, can you store it in a variable? Also, is there a way to create a callback in Python? From davea at davea.name Mon Sep 9 14:19:40 2013 From: davea at davea.name (Dave Angel) Date: Mon, 9 Sep 2013 18:19:40 +0000 (UTC) Subject: Monitor key presses in Python? References: <57051d11-abd9-4621-9618-1574cd37545c@googlegroups.com> Message-ID: On 9/9/2013 13:39, eamonnrea at gmail.com wrote: > Is there a way to detect if the user presses a key in Python that works on most OS's? I've only seen 1 method, and that only works in Python 2.6 and less. If you get the key, can you store it in a variable? > > Also, is there a way to create a callback in Python? What is usually meant by "a callback" is a function object. In Python, functions are first class objects. You just use the function name without the parentheses. def my_function(): print "Executing my_function" b = my_function # b is now a function object b() Likewise, instead of storing it in a global, you might pass it to a method which stores it as an object attribute, or whatever. Also of interest is that you can easily create partial functions, where some of the parameters are already decided. See the docs for functools.partial And if you're trying to use a method as a callback, you can store the bound-method, which is effectively a partial including the self parameter. Finally, don't forget lambda functions, which can be useful if you're trying to create a simple function and don't need a name for it. -- DaveA From gordon at panix.com Mon Sep 9 14:40:35 2013 From: gordon at panix.com (John Gordon) Date: Mon, 9 Sep 2013 18:40:35 +0000 (UTC) Subject: Monitor key presses in Python? References: <57051d11-abd9-4621-9618-1574cd37545c@googlegroups.com> Message-ID: In <57051d11-abd9-4621-9618-1574cd37545c at googlegroups.com> eamonnrea at gmail.com writes: > Is there a way to detect if the user presses a key in Python that works on > most OS's? That depends on what you're really asking; your question is somewhat vague. Are you asking for a function that waits for the user to press a key and then returns the key that was pressed? Or are you asking for a function that detects whether a key has been pressed at all? -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From steve+comp.lang.python at pearwood.info Mon Sep 9 19:37:33 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Sep 2013 23:37:33 GMT Subject: Monitor key presses in Python? References: <57051d11-abd9-4621-9618-1574cd37545c@googlegroups.com> Message-ID: <522e5bbd$0$29988$c3e8da3$5496439d@news.astraweb.com> On Mon, 09 Sep 2013 10:39:43 -0700, eamonnrea wrote: > Is there a way to detect if the user presses a key in Python that works > on most OS's? I've only seen 1 method, and that only works in Python 2.6 > and less. http://code.activestate.com/recipes/577977 I have just tried the above under Linux in Python 3.3, and it works fine. I have no way of testing it under Windows. > If you get the key, can you store it in a variable? You're new to programming, aren't you? :-) Yes you can store it in a variable. Anything that is returned can be stored in a variable. Here is an example: py> def example(): ... print("Press any character key... ") ... c = getch() ... print("You typed: '%c'" % c) ... py> example() Press any character key... You typed: 'y' The above is running under Python 3.3. > Also, is there a way to create a callback in Python? The answer to your question as you ask it is "Yes, naturally." Callback is short for *callback function* and describes the *purpose* of the function, not how you write it or what it does. But a better answer is, "A callback to what? It depends on what is doing the calling back." -- Steven From nobody at nowhere.com Mon Sep 9 21:33:17 2013 From: nobody at nowhere.com (Nobody) Date: Tue, 10 Sep 2013 02:33:17 +0100 Subject: Monitor key presses in Python? References: <57051d11-abd9-4621-9618-1574cd37545c@googlegroups.com> Message-ID: On Mon, 09 Sep 2013 10:39:43 -0700, eamonnrea wrote: > Is there a way to detect if the user presses a key in Python that works on > most OS's? I've only seen 1 method, and that only works in Python 2.6 and > less. There's no "generic" solution to this. At a minimum, there's getting "key presses" from a windowing system and getting character input from a terminal or console. The two cases are themselves quite different, and each case has differences between operating systems. From torriem at gmail.com Mon Sep 9 22:43:34 2013 From: torriem at gmail.com (Michael Torrie) Date: Mon, 09 Sep 2013 20:43:34 -0600 Subject: Monitor key presses in Python? In-Reply-To: <57051d11-abd9-4621-9618-1574cd37545c@googlegroups.com> References: <57051d11-abd9-4621-9618-1574cd37545c@googlegroups.com> Message-ID: <522E8756.5070503@gmail.com> On 09/09/2013 11:39 AM, eamonnrea at gmail.com wrote: > Is there a way to detect if the user presses a key in Python that > works on most OS's? I've only seen 1 method, and that only works in > Python 2.6 and less. If you get the key, can you store it in a > variable? > > Also, is there a way to create a callback in Python? Some python programs display a graphical user interface. Others run in a text-mode console (dos prompt, unix shell, etc). And yet others don't have any display at all. If you're talking about a graphical user interface app (windows, dialogs, buttons, etc), then you'll have to rely on the particular user interface library you are using to provide that sort of access. If you're just running in a dos box, or a unix terminal, then there are other ways of doing what you want, but I'm not sure any one way is portable across all operating systems. I did find this code segment that claims to work on windows and unix: http://code.activestate.com/recipes/134892/ Anyway tell us more about what environment and kind of program you are dealing with. As for callbacks, of course. functions are objects in python. You can pass them as arguments, assign them to variables, and then call them. All graphical user interface libraries rely on them to handle events. From invalid at invalid.invalid Tue Sep 10 10:18:09 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 10 Sep 2013 14:18:09 +0000 (UTC) Subject: Monitor key presses in Python? References: <57051d11-abd9-4621-9618-1574cd37545c@googlegroups.com> Message-ID: On 2013-09-09, eamonnrea at gmail.com wrote: > Is there a way to detect if the user presses a key in Python that > works on most OS's? No. Unless by "most OSes" you mean "most Unixes" or "most Windows". > I've only seen 1 method, and that only works in > Python 2.6 and less. > If you get the key, can you store it in a variable? Sure. > Also, is there a way to create a callback in Python? Yes. -- Grant Edwards grant.b.edwards Yow! I'm having an at EMOTIONAL OUTBURST!! But, gmail.com uh, WHY is there a WAFFLE in my PAJAMA POCKET?? From eamonnrea at gmail.com Sat Sep 14 13:44:36 2013 From: eamonnrea at gmail.com (eamonnrea at gmail.com) Date: Sat, 14 Sep 2013 10:44:36 -0700 (PDT) Subject: Monitor key presses in Python? In-Reply-To: References: <57051d11-abd9-4621-9618-1574cd37545c@googlegroups.com> Message-ID: <5c59400c-45ca-40f0-846c-05bef3eb0233@googlegroups.com> It might sound strange, but I'd need this to run without the user knowing.I believe I can do this by making the file a .pyw file, and use a GUI library to monitor the key presses. I think I could use PyGame, PyGlet and/or Cocos2d as well. From roy at panix.com Sat Sep 14 14:03:42 2013 From: roy at panix.com (Roy Smith) Date: Sat, 14 Sep 2013 14:03:42 -0400 Subject: Monitor key presses in Python? References: <57051d11-abd9-4621-9618-1574cd37545c@googlegroups.com> <5c59400c-45ca-40f0-846c-05bef3eb0233@googlegroups.com> Message-ID: In article <5c59400c-45ca-40f0-846c-05bef3eb0233 at googlegroups.com>, eamonnrea at gmail.com wrote: > It might sound strange, but I'd need this to run without the user knowing. It's called a keylogger. And after all the revelations about the NSA over the past few weeks, it doesn't sound strange at all. From eamonnrea at gmail.com Sat Sep 14 14:10:28 2013 From: eamonnrea at gmail.com (eamonnrea at gmail.com) Date: Sat, 14 Sep 2013 11:10:28 -0700 (PDT) Subject: Monitor key presses in Python? In-Reply-To: References: <57051d11-abd9-4621-9618-1574cd37545c@googlegroups.com> <5c59400c-45ca-40f0-846c-05bef3eb0233@googlegroups.com> Message-ID: I didnt wanna say that, in case people threw a fit and stuff. So yeah, how would I monitor the key presses? From davea at davea.name Sat Sep 14 18:03:56 2013 From: davea at davea.name (Dave Angel) Date: Sat, 14 Sep 2013 22:03:56 +0000 (UTC) Subject: Monitor key presses in Python? References: <57051d11-abd9-4621-9618-1574cd37545c@googlegroups.com> <5c59400c-45ca-40f0-846c-05bef3eb0233@googlegroups.com> Message-ID: On 14/9/2013 14:10, eamonnrea at gmail.com wrote: > I didnt wanna say that, in case people threw a fit and stuff. > > So yeah, how would I monitor the key presses? There's a huge difference between monitoring key presses within your own process, and intercepting them system-wide. if you need to see keystrokes even when your window does not have the focus, then you need to call some system DLL function, (some kind of "system hook", which you can probably do using the platform module, or the ctypes module, or some module that I wouldn't have on Linux. This type of code is not the least bit portable, which just means I can't test things here to try to help. Note also that if you get one of the ActivePython implementations from ActiveState, you'll get PyWin32, which may well have a function just for the purpose. See: http://docs.activestate.com/activepython/2.5/pywin32/PyWin32.HTML I'm sure it can be separately downloaded, but when I used to run Windows, I just got the whole package. The ActivePython also had the best offline documentation I was able to find at the time. See also Tim Golden's win32 web page: http://timgolden.me.uk/python/win32_how_do_i.html There is a separate win32 mailing list; see: https://mail.python.org/mailman/listinfo/python-win32 Possibly the most frequent poster there is Tim Golden, so search his site first. -- DaveA From no.email at nospam.invalid Sat Sep 14 14:42:23 2013 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 14 Sep 2013 11:42:23 -0700 Subject: Monitor key presses in Python? References: <57051d11-abd9-4621-9618-1574cd37545c@googlegroups.com> <5c59400c-45ca-40f0-846c-05bef3eb0233@googlegroups.com> Message-ID: <7xeh8rz1m8.fsf@ruckus.brouhaha.com> eamonnrea at gmail.com writes: > I'd need this to run without the user knowing. You are asking for programming advice when you should probably be asking for legal advice instead, about interception of electronic communications. We are not qualified to give legal advice here. From mohsen at pahlevanzadeh.org Mon Sep 9 16:10:59 2013 From: mohsen at pahlevanzadeh.org (Mohsen Pahlevanzadeh) Date: Tue, 10 Sep 2013 00:40:59 +0430 Subject: a gift function and a question Message-ID: <1378757459.6005.55.camel@debian> Dear all, I have a gift for mailing list: //////////////////////////////// def integerToPersian(number): listedPersian = ['?','?','?','?','?','?','?','?','?','?'] listedEnglish = ['0','1','2','3','4','5','6','7','8','9'] returnList = list() listedTmpString = list(str(number)) for i in listedTmpString: returnList.append(listedPersian[listedEnglish.index(i)]) return ''.join(returnList) //////////////////////////////////// When you call it such as : "integerToPersian(3455)" , it return ????, ???? is equivalent to 3455 in Persian and Arabic language.When you read a number such as reading from databae, and want to show in widget, this function is very useful. My question is , do you have reverse of this function? persianToInteger? Yours, Mohsen From random832 at fastmail.us Mon Sep 9 16:20:25 2013 From: random832 at fastmail.us (random832 at fastmail.us) Date: Mon, 09 Sep 2013 16:20:25 -0400 Subject: a gift function and a question In-Reply-To: <1378757459.6005.55.camel@debian> References: <1378757459.6005.55.camel@debian> Message-ID: <1378758025.32118.19881065.6BD771B7@webmail.messagingengine.com> On Mon, Sep 9, 2013, at 16:10, Mohsen Pahlevanzadeh wrote: > My question is , do you have reverse of this function? persianToInteger? The int constructor is able to handle different forms of decimal numerals directly: >>> int('\u06f3\u06f4\u06f5\u06f5') 3455 From mohsen at pahlevanzadeh.org Tue Sep 10 02:26:19 2013 From: mohsen at pahlevanzadeh.org (Mohsen Pahlevanzadeh) Date: Tue, 10 Sep 2013 10:56:19 +0430 Subject: a gift function and a question In-Reply-To: <1378758025.32118.19881065.6BD771B7@webmail.messagingengine.com> References: <1378757459.6005.55.camel@debian> <1378758025.32118.19881065.6BD771B7@webmail.messagingengine.com> Message-ID: <1378794379.6005.73.camel@debian> I completed my two functions, i say may be poeple can use them: ######################################33 def integerToPersian(number): listedPersian = ['?','?','?','?','?','?','?','?','?','?'] listedEnglish = ['0','1','2','3','4','5','6','7','8','9'] returnList = list() for i in list(str(number)): returnList.append(listedPersian[listedEnglish.index(i)]) return ''.join(returnList) def persianToInterger(persianNumber): listedTmpString = list(persianNumber.decode("utf-8")) returnList = list() for i in listedTmpString: returnList.append(unicodedata.digit(i)) return int (''.join(str(x) for x in returnList)) #######################################33 On Mon, 2013-09-09 at 16:20 -0400, random832 at fastmail.us wrote: > On Mon, Sep 9, 2013, at 16:10, Mohsen Pahlevanzadeh wrote: > > My question is , do you have reverse of this function? persianToInteger? > > The int constructor is able to handle different forms of decimal > numerals directly: > > >>> int('\u06f3\u06f4\u06f5\u06f5') > 3455 From __peter__ at web.de Tue Sep 10 03:46:44 2013 From: __peter__ at web.de (Peter Otten) Date: Tue, 10 Sep 2013 09:46:44 +0200 Subject: a gift function and a question References: <1378757459.6005.55.camel@debian> <1378758025.32118.19881065.6BD771B7@webmail.messagingengine.com> <1378794379.6005.73.camel@debian> Message-ID: Mohsen Pahlevanzadeh wrote: > I completed my two functions, i say may be poeple can use them: > ######################################33 > def integerToPersian(number): > listedPersian = ['?','?','?','?','?','?','?','?','?','?'] > listedEnglish = ['0','1','2','3','4','5','6','7','8','9'] > returnList = list() > > for i in list(str(number)): > returnList.append(listedPersian[listedEnglish.index(i)]) > > return ''.join(returnList) > > def persianToInterger(persianNumber): > listedTmpString = list(persianNumber.decode("utf-8")) > returnList = list() > > for i in listedTmpString: > returnList.append(unicodedata.digit(i)) > > return int (''.join(str(x) for x in returnList)) There is also the str.translate() method which takes a translation dict. Characters not in that dict will be left unaltered: >>> persian = "??????????" >>> english = "0123456789" >>> _p2e = str.maketrans(persian, english) >>> _e2p = str.maketrans(english, persian) >>> def persian_to_english(s): return s.translate(_p2e) ... >>> def english_to_persian(s): return s.translate(_e2p) ... >>> english_to_persian("alpha 12321 beta") 'alpha ????? beta' >>> persian_to_english(_) 'alpha 12321 beta' [Advanced usage] If you prefer to get an error you can subclass dict: >>> class NoDigitError(Exception): ... pass ... >>> class StrictDict(dict): ... def __missing__(self, key): ... raise NoDigitError("Illegal codepoint #{}".format(key)) ... >>> _e2p = StrictDict(str.maketrans(english, persian)) >>> english_to_persian("543") '???' >>> english_to_persian("x543") Traceback (most recent call last): File "", line 1, in File "", line 1, in english_to_persian File "", line 3, in __missing__ __main__.NoDigitError: Illegal codepoint #120 From steve at pearwood.info Tue Sep 10 03:01:20 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 10 Sep 2013 07:01:20 GMT Subject: a gift function and a question References: Message-ID: <522ec3c0$0$29999$c3e8da3$5496439d@news.astraweb.com> On Tue, 10 Sep 2013 00:40:59 +0430, Mohsen Pahlevanzadeh wrote: > Dear all, > > I have a gift for mailing list: > > //////////////////////////////// > def integerToPersian(number): > listedPersian = ['?','?','?','?','?','?','?','?','?','?'] > listedEnglish = ['0','1','2','3','4','5','6','7','8','9'] > returnList = list() > listedTmpString = list(str(number)) > for i in listedTmpString: > returnList.append(listedPersian[listedEnglish.index(i)]) > return ''.join(returnList) > //////////////////////////////////// > When you call it such as : "integerToPersian(3455)" , it return ????, > ???? is equivalent to 3455 in Persian and Arabic language.When you read > a number such as reading from databae, and want to show in widget, this > function is very useful. Thank you Mohsen! Here is a slightly more idiomatic version of the same function. This is written for Python 3: def integerToPersian(number): """Convert positive integers to Persian. >>> integerToPersian(3455) '????' Does not support negative numbers. """ digit_map = dict(zip('0123456789', '??????????')) digits = [digit_map[c] for c in str(number)] return ''.join(digits) Python 2 version will be nearly the same except it needs to use the u prefix on the strings. > My question is , do you have reverse of this function? persianToInteger? The Python built-in int function already supports that: py> int('????') 3455 -- Steven From random832 at fastmail.us Tue Sep 10 09:50:25 2013 From: random832 at fastmail.us (random832 at fastmail.us) Date: Tue, 10 Sep 2013 09:50:25 -0400 Subject: a gift function and a question In-Reply-To: <522ec3c0$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <522ec3c0$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1378821025.26774.20195477.2F178EC2@webmail.messagingengine.com> On Tue, Sep 10, 2013, at 3:01, Steven D'Aprano wrote: > def integerToPersian(number): > """Convert positive integers to Persian. > > >>> integerToPersian(3455) > '????' > > Does not support negative numbers. > """ > digit_map = dict(zip('0123456789', '??????????')) > digits = [digit_map[c] for c in str(number)] > return ''.join(digits) You can support negative numbers if you use digit_map.get(c,c). From steve+comp.lang.python at pearwood.info Tue Sep 10 11:11:21 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Sep 2013 15:11:21 GMT Subject: a gift function and a question References: <522ec3c0$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <522f3699$0$29988$c3e8da3$5496439d@news.astraweb.com> On Tue, 10 Sep 2013 07:01:20 +0000, Steven D'Aprano wrote: > On Tue, 10 Sep 2013 00:40:59 +0430, Mohsen Pahlevanzadeh wrote: >> My question is , do you have reverse of this function? >> persianToInteger? > > The Python built-in int function already supports that: > > > py> int('????') > 3455 Oh, I forgot to mention, this works back to at least Python 2.4, provided you remember to use Unicode strings rather than bytes: py> b = '????' # This fails. py> int(b) Traceback (most recent call last): File "", line 1, in ValueError: invalid literal for int() with base 10: '\xdb\xb3\xdb\xb4\xdb \xb5\xdb\xb5' py> py> s = u'????' # This works. py> int(s) 3455 -- Steven From steve at pearwood.info Tue Sep 10 02:09:25 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 10 Sep 2013 06:09:25 GMT Subject: Language design Message-ID: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> Some time ago, Tom Christiansen wrote about the "Seven Deadly Sins of Perl": http://www.perl.com/doc/FMTEYEWTK/versus/perl.html What design mistakes, traps or gotchas do you think Python has? Gotchas are not necessarily a bad thing, there may be good reasons for it, but they're surprising. To get started, here are a couple of mine: - Python is so dynamic, that there is hardly anything at all that can be optimized at compile time. - The behaviour of mutable default variables is a gotcha. - Operators that call dunder methods like __add__ don't use the same method resolution rules as regular methods, they bypass the instance and go straight to the type, at least for new-style classes. -- Steven From pavel at schon.cz Tue Sep 10 02:59:49 2013 From: pavel at schon.cz (diverman) Date: Mon, 9 Sep 2013 23:59:49 -0700 (PDT) Subject: Language design In-Reply-To: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: No exactly bad, but can suprise >>> foo=([],) >>> foo[0] += ['bar'] Traceback (most recent call last): File "", line 1, in TypeError: 'tuple' object does not support item assignment >>> foo (['bar'],) Dne ?ter?, 10. z??? 2013 8:09:25 UTC+2 Steven D'Aprano napsal(a): > Some time ago, Tom Christiansen wrote about the "Seven Deadly Sins of > > Perl": > > > > http://www.perl.com/doc/FMTEYEWTK/versus/perl.html > > > > > > What design mistakes, traps or gotchas do you think Python has? Gotchas > > are not necessarily a bad thing, there may be good reasons for it, but > > they're surprising. > > > > To get started, here are a couple of mine: > > > > > > - Python is so dynamic, that there is hardly anything at all that can be > > optimized at compile time. > > > > - The behaviour of mutable default variables is a gotcha. > > > > - Operators that call dunder methods like __add__ don't use the same > > method resolution rules as regular methods, they bypass the instance and > > go straight to the type, at least for new-style classes. > > > > > > > > -- > > Steven From ben+python at benfinney.id.au Tue Sep 10 03:07:09 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 10 Sep 2013 17:07:09 +1000 Subject: Language design References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7wbo412m02.fsf@benfinney.id.au> Steven D'Aprano writes: > What design mistakes, traps or gotchas do you think Python has? * Imports are fiendishly complex, hidden below deceptively simple syntax. It's a reasonable expectation that one can import a module from a source code file given its path on the filesystem, but this turns out to be much more complicated than in many other languages. There are reasons for this, some good, some merely historical baggage, some workarounds for OS misdesign, and some that may be Python's own mistakes. Those reasons are difficult to appreciate when first encountering the problem. * Somewhat related, and not really part of language design: The import mechanism and the packaging tools are woefully behind the state of the art in getting applications and their libraries to cooperate with operating system package management. This has the terrible effect that developers choose to insulate Python from the operating system, essentially losing all the benefits of the operating system package manager for their dependencies and needing to re-implement package management all over again, badly. This is largely the fault of operating systems with package dependency managers that are poor (Apple's) to nonexistent (Microsoft's). But the result is that Python's tools have been particularly woeful in this area compared to some other languages, and the Python community now has learned to subvert all OS package managers, even the good ones. > Gotchas are not necessarily a bad thing, there may be good reasons for > it, but they're surprising. * Python requires every programmer to know, or quickly learn, the basics of Unicode: to know that text is not, and never will be again, synonymous with a sequence of bytes. This is, in the long run, a good thing for all programmers and those who will use their programs. Programmers should expect to deal with non-ASCII text earlier than the innocent might suppose, and the likelihood goes up all the time. The sooner we replace the erroneous ?text is ASCII? in the common wisdom with ?text is Unicode?, the better. Nevertheless, the outstanding robustness of Python's Unicode support is different from most languages, and so is a gotcha. -- \ ?Life does not cease to be funny when people die any more than | `\ it ceases to be serious when people laugh.? ?George Bernard Shaw | _o__) | Ben Finney From wayne at waynewerner.com Wed Sep 11 07:42:12 2013 From: wayne at waynewerner.com (Wayne Werner) Date: Wed, 11 Sep 2013 06:42:12 -0500 (CDT) Subject: Language design In-Reply-To: <7wbo412m02.fsf@benfinney.id.au> References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <7wbo412m02.fsf@benfinney.id.au> Message-ID: On Tue, 10 Sep 2013, Ben Finney wrote: > The sooner we replace the erroneous > ?text is ASCII? in the common wisdom with ?text is Unicode?, the > better. I'd actually argue that it's better to replace the common wisdom with "text is binary data, and we should normally look at that text through Unicode eyes". A little less catchy, but more accurate ;) -W From davea at davea.name Wed Sep 11 08:05:52 2013 From: davea at davea.name (Dave Angel) Date: Wed, 11 Sep 2013 12:05:52 +0000 (UTC) Subject: Language design References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <7wbo412m02.fsf@benfinney.id.au> Message-ID: On 11/9/2013 07:42, Wayne Werner wrote: > On Tue, 10 Sep 2013, Ben Finney wrote: >> The sooner we replace the erroneous >> ?text is ASCII? in the common wisdom with ?text is Unicode?, the >> better. > > I'd actually argue that it's better to replace the common wisdom with > "text is binary data, and we should normally look at that text through > Unicode eyes". A little less catchy, but more accurate ;) > > -W > "Text is unicode, but text files are binary, and need to be decoded on read, and encoded on write. Most other external textual data is also binary, and similarly need to be converted before use" -- DaveA From ben+python at benfinney.id.au Wed Sep 11 19:16:29 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 12 Sep 2013 09:16:29 +1000 Subject: Language design References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <7wbo412m02.fsf@benfinney.id.au> Message-ID: <7w38pb2ble.fsf@benfinney.id.au> Wayne Werner writes: > On Tue, 10 Sep 2013, Ben Finney wrote: > > The sooner we replace the erroneous > > ?text is ASCII? in the common wisdom with ?text is Unicode?, the > > better. > > I'd actually argue that it's better to replace the common wisdom with > "text is binary data, and we should normally look at that text through > Unicode eyes". A little less catchy, but more accurate ;) No, that's inaccurate. A sequence of bytes is binary data. Unicode is not binary data. There are encodings which map Unicode to a sequence of bytes, but text is not binary data. -- \ ?For fast acting relief, try slowing down.? ?Jane Wagner, via | `\ Lily Tomlin | _o__) | Ben Finney From dreamingforward at gmail.com Wed Sep 11 20:25:57 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Wed, 11 Sep 2013 17:25:57 -0700 Subject: Language design In-Reply-To: <7w38pb2ble.fsf@benfinney.id.au> References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <7wbo412m02.fsf@benfinney.id.au> <7w38pb2ble.fsf@benfinney.id.au> Message-ID: >> On Tue, 10 Sep 2013, Ben Finney wrote: >> > The sooner we replace the erroneous >> > ?text is ASCII? in the common wisdom with ?text is Unicode?, the >> > better. >> >> I'd actually argue that it's better to replace the common wisdom with >> "text is binary data, and we should normally look at that text through >> Unicode eyes". A little less catchy, but more accurate ;) > > No, that's inaccurate. A sequence of bytes is binary data. Unicode is > not binary data. Well now, this is an area that is not actually well-defined. I would say 16-bit Unicode is binary data if you're encoding in base 65,536, just as 8-bit ascii is binary data if you're encoding in base-256. Which is to say: there is no intervening data to suggest a TYPE. -- MarkJ Tacoma, Washington From rosuav at gmail.com Wed Sep 11 20:31:26 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 Sep 2013 10:31:26 +1000 Subject: Language design In-Reply-To: References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <7wbo412m02.fsf@benfinney.id.au> <7w38pb2ble.fsf@benfinney.id.au> Message-ID: On Thu, Sep 12, 2013 at 10:25 AM, Mark Janssen wrote: >>> On Tue, 10 Sep 2013, Ben Finney wrote: >>> > The sooner we replace the erroneous >>> > ?text is ASCII? in the common wisdom with ?text is Unicode?, the >>> > better. >>> >>> I'd actually argue that it's better to replace the common wisdom with >>> "text is binary data, and we should normally look at that text through >>> Unicode eyes". A little less catchy, but more accurate ;) >> >> No, that's inaccurate. A sequence of bytes is binary data. Unicode is >> not binary data. > > Well now, this is an area that is not actually well-defined. I would > say 16-bit Unicode is binary data if you're encoding in base 65,536, > just as 8-bit ascii is binary data if you're encoding in base-256. > Which is to say: there is no intervening data to suggest a TYPE. Unicode is not 16-bit any more than ASCII is 8-bit. And you used the word "encod[e]", which is the standard way to turn Unicode into bytes anyway. No, a Unicode string is a series of codepoints - it's most similar to a list of ints than to a stream of bytes. ChrisA From dreamingforward at gmail.com Wed Sep 11 20:37:16 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Wed, 11 Sep 2013 17:37:16 -0700 Subject: Language design In-Reply-To: References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <7wbo412m02.fsf@benfinney.id.au> <7w38pb2ble.fsf@benfinney.id.au> Message-ID: > Unicode is not 16-bit any more than ASCII is 8-bit. And you used the > word "encod[e]", which is the standard way to turn Unicode into bytes > anyway. No, a Unicode string is a series of codepoints - it's most > similar to a list of ints than to a stream of bytes. Okay, now you're in blah, blah land. --mark From rosuav at gmail.com Wed Sep 11 20:40:15 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 Sep 2013 10:40:15 +1000 Subject: Language design In-Reply-To: References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <7wbo412m02.fsf@benfinney.id.au> <7w38pb2ble.fsf@benfinney.id.au> Message-ID: On Thu, Sep 12, 2013 at 10:37 AM, Mark Janssen wrote: >> Unicode is not 16-bit any more than ASCII is 8-bit. And you used the >> word "encod[e]", which is the standard way to turn Unicode into bytes >> anyway. No, a Unicode string is a series of codepoints - it's most >> similar to a list of ints than to a stream of bytes. > > Okay, now you're in blah, blah land. Eh? Apart from the grammatical oddity (artifact of editing - should be "more similar" not "most similar"), I don't see anything wrong in what I said there. ChrisA From benjamin.kaplan at case.edu Wed Sep 11 20:54:33 2013 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 11 Sep 2013 17:54:33 -0700 Subject: Language design In-Reply-To: References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <7wbo412m02.fsf@benfinney.id.au> <7w38pb2ble.fsf@benfinney.id.au> Message-ID: On Wed, Sep 11, 2013 at 5:37 PM, Mark Janssen wrote: >> Unicode is not 16-bit any more than ASCII is 8-bit. And you used the >> word "encod[e]", which is the standard way to turn Unicode into bytes >> anyway. No, a Unicode string is a series of codepoints - it's most >> similar to a list of ints than to a stream of bytes. > > Okay, now you're in blah, blah land. > > --mark > -- There's no such thing as 16-bit Unicode. Unicode is a sequence of characters, not a sequence of bytes. It's an abstract thing. To work with it on a computer, you need to use a byte encoding because computers don't deal with with abstract things. UTF-16 is one encoding method that can map any character defined in Unicode to a sequence of bytes. UTF-16 isn't Unicode, it's just a function that maps a byte string to a character string. Python's unicode class is a character string- as far as the user is concerned, it's made up of those abstract "character" things and not bytes at all. From ben+python at benfinney.id.au Wed Sep 11 20:57:04 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 12 Sep 2013 10:57:04 +1000 Subject: Language design References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <7wbo412m02.fsf@benfinney.id.au> <7w38pb2ble.fsf@benfinney.id.au> Message-ID: <7wk3im26xr.fsf@benfinney.id.au> Mark Janssen writes: > > Unicode is not 16-bit any more than ASCII is 8-bit. And you used the > > word "encod[e]", which is the standard way to turn Unicode into bytes > > anyway. No, a Unicode string is a series of codepoints - it's most > > similar to a list of ints than to a stream of bytes. > > Okay, now you're in blah, blah land. Text is (in the third millennium) Unicode. Unicode text is not binary data and never will be. Unicode text can be *encoded* to binary data, and that data can be *decoded* back to Unicode text. The two are never the same thing. You're demonstrating my point: the pernicious ?text is binary data? falsehood needs to be eradicated from everything today's programmers learn. We need the simple facts about the basic difference between text and bytes to be learned by every programmer as early as can feasible. -- \ ???????? (The virtuous are not abandoned, | `\ they shall surely have neighbours.) | _o__) ???? Confucius, 551 BCE ? 479 BCE | Ben Finney From steve+comp.lang.python at pearwood.info Wed Sep 11 22:33:06 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 Sep 2013 02:33:06 GMT Subject: Language design References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <7wbo412m02.fsf@benfinney.id.au> <7w38pb2ble.fsf@benfinney.id.au> Message-ID: <523127e2$0$29988$c3e8da3$5496439d@news.astraweb.com> On Thu, 12 Sep 2013 10:31:26 +1000, Chris Angelico wrote: > On Thu, Sep 12, 2013 at 10:25 AM, Mark Janssen > wrote: >> Well now, this is an area that is not actually well-defined. I would >> say 16-bit Unicode is binary data if you're encoding in base 65,536, >> just as 8-bit ascii is binary data if you're encoding in base-256. >> Which is to say: there is no intervening data to suggest a TYPE. > > Unicode is not 16-bit any more than ASCII is 8-bit. And you used the > word "encod[e]", which is the standard way to turn Unicode into bytes > anyway. No, a Unicode string is a series of codepoints - it's most > similar to a list of ints than to a stream of bytes. And not necessarily ints, for that matter. Let's be clear: the most obvious, simple, hardware-efficient way to implement a Unicode string holding arbitrary characters is as an array of 32-bit signed integers restricted to the range 0x0 - 0x10FFFF. That gives you a one-to-one mapping of int <-> code point. But it's not the only way. One could implement Unicode strings using any similar one-to-one mapping. Taking a leaf out of the lambda calculus, I might implement each code point like this: NULL pointer <=> Code point 0 ^NULL <=> Code point 1 ^^NULL <=> Code point 2 ^^^NULL <=> Code point 3 and so on, where ^ means "pointer to". Obviously this is mathematically neat, but practically impractical. Code point U+10FFFF would require a chain of 1114111 pointer-to-pointer-to- pointer before the NULL. But it would work. Or alternatively, I might choose to use floats, mapping (say) 0.25 <=> U+0376. Or whatever. What we can say, though, is that to represent the full Unicode charset requires 21 bits per code-point, although you can get away with fewer bits if you have some out-of-band mechanism for recognising restricted subsets of the charset. (E.g. you could use just 7 bits if you only handled the characters in ASCII, or just 3 bits if you only cared about decimal digits.) In practice, computers tend to be much faster when working with multiples of 8 bits, so we use 32 bits instead of 21. In that sense, Unicode is a 32 bit character set. But Unicode is absolutely not a 16 bit character set. And of course you can use *more* bits than 21, or 32. If you had a computer where the native word-size was (say) 50 bits, it would make sense to use 50 bits per character. As for the question of "binary data versus text", well, that's a thorny one, because really *everything* in a computer is binary data, since it's stored using bits. But we can choose to *interpret* some binary data as text, just as we interpret some binary data as pictures, sound files, video, Powerpoint presentations, and so forth. A reasonable way of defining a text file might be: If you decode the bytes making up an alleged text file into code-points, using the correct encoding (which needs to be known a priori, or stored out of band somehow), then provided that none of the code-points have Unicode General Category Cc, Cf, Cs, Co or Cn (control, format, surrogate, private-use, non-character/reserved), you can claim that it is at least plausible that the file contains text. Whether that text is meaningful is another story. You might wish to allow Cf and possibly even Co (format and private-use), depending on the application. -- Steven From roy at panix.com Wed Sep 11 22:43:20 2013 From: roy at panix.com (Roy Smith) Date: Wed, 11 Sep 2013 22:43:20 -0400 Subject: Language design References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <7wbo412m02.fsf@benfinney.id.au> <7w38pb2ble.fsf@benfinney.id.au> <523127e2$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <523127e2$0$29988$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > just 3 bits if you only cared about decimal digits. That's a neat trick. From rosuav at gmail.com Wed Sep 11 22:58:26 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 Sep 2013 12:58:26 +1000 Subject: Language design In-Reply-To: References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <7wbo412m02.fsf@benfinney.id.au> <7w38pb2ble.fsf@benfinney.id.au> <523127e2$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Sep 12, 2013 at 12:43 PM, Roy Smith wrote: > In article <523127e2$0$29988$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > >> just 3 bits if you only cared about decimal digits. > > That's a neat trick. It is! It's one of the fancy things we can do in the Land Downunder. By the time we've dodged spiders, snakes, and Drop Bears, squeezing ten options into three bits is easy! Of course, we always keep a fourth bit lying around for when the tourists come through. 33% extra profit when we sell them the unnecessary spare bit. ChrisA From steve at pearwood.info Thu Sep 12 01:08:31 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 12 Sep 2013 05:08:31 GMT Subject: Language design References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <7wbo412m02.fsf@benfinney.id.au> <7w38pb2ble.fsf@benfinney.id.au> <523127e2$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52314c4f$0$29999$c3e8da3$5496439d@news.astraweb.com> On Wed, 11 Sep 2013 22:43:20 -0400, Roy Smith wrote: > In article <523127e2$0$29988$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > >> just 3 bits if you only cared about decimal digits. > > That's a neat trick. Well obviously it's compressed. :-) Sorry for the typo, I meant 4. -- Steven From dreamingforward at gmail.com Wed Sep 11 17:22:21 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Wed, 11 Sep 2013 14:22:21 -0700 Subject: Language design In-Reply-To: <7wbo412m02.fsf@benfinney.id.au> References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <7wbo412m02.fsf@benfinney.id.au> Message-ID: > * Imports are fiendishly complex, hidden below deceptively simple > syntax. > > It's a reasonable expectation that one can import a module from a > source code file given its path on the filesystem, but this turns out > to be much more complicated than in many other languages. Why is this so difficult? Add a Graph class to the collections module (networkx is quite good) and simply check for circular imports. The remaining difficulty I encounter is because the user hasn't defined their PYTHONPATH variable. -- MarkJ Tacoma, Washington From ben+python at benfinney.id.au Wed Sep 11 19:19:58 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 12 Sep 2013 09:19:58 +1000 Subject: Language design References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <7wbo412m02.fsf@benfinney.id.au> Message-ID: <7wy5730wv5.fsf@benfinney.id.au> Mark Janssen writes: > > * Imports are fiendishly complex, hidden below deceptively simple > > syntax. > > > > It's a reasonable expectation that one can import a module from a > > source code file given its path on the filesystem, but this turns out > > to be much more complicated than in many other languages. > > Why is this so difficult? I don't know, you'll have to ask the people who designed it that way. > Add a Graph class to the collections module (networkx is quite good) > and simply check for circular imports. Er? That doesn't address the task of importing a module from a source code file given its path on the filesystem. Other languages have the equivalent of ?include "/path/to/file.py"?, but Python doesn't. That's the misdesign I'm describing. -- \ ?Just because nobody complains doesn't mean all parachutes are | `\ perfect.? ?Benny Hill | _o__) | Ben Finney From tjreedy at udel.edu Wed Sep 11 19:51:58 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 11 Sep 2013 19:51:58 -0400 Subject: Language design In-Reply-To: <7wy5730wv5.fsf@benfinney.id.au> References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <7wbo412m02.fsf@benfinney.id.au> <7wy5730wv5.fsf@benfinney.id.au> Message-ID: On 9/11/2013 7:19 PM, Ben Finney wrote: > Er? That doesn't address the task of importing a module from a source > code file given its path on the filesystem. > > Other languages have the equivalent of ?include "/path/to/file.py"?, Some includes are equivalent to with open("/path/to/file.py") as f: exec(f.read()) > but Python doesn't. which Python does have. Python also has __import__("/path/to/file.py"), which is used by import when the module does not exist. -- Terry Jan Reedy From dreamingforward at gmail.com Wed Sep 11 20:34:42 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Wed, 11 Sep 2013 17:34:42 -0700 Subject: Language design In-Reply-To: <7wy5730wv5.fsf@benfinney.id.au> References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <7wbo412m02.fsf@benfinney.id.au> <7wy5730wv5.fsf@benfinney.id.au> Message-ID: >> Why is this so difficult? >> Add a Graph class to the collections module (networkx is quite good) >> and simply check for circular imports. > > Er? That doesn't address the task of importing a module from a source > code file given its path on the filesystem. That's true, I guess was hooked on Python's abstraction mechanism for making the file system invisible. But I like the idea of programming *relative* path addressing, so you can create a sort of "name space" for your modules. So instead of "import /path/to/file.py" which makes a system dependency (i.e. *yours*), you could have "import TestPackage.collections.bag" (using periods for file path separators in keeping with the Pythonic Way). -- MarkJ Tacoma, Washington From antoon.pardon at rece.vub.ac.be Tue Sep 10 03:58:22 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 10 Sep 2013 09:58:22 +0200 Subject: Language design In-Reply-To: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <522ED11E.4050106@rece.vub.ac.be> Op 10-09-13 08:09, Steven D'Aprano schreef: > Some time ago, Tom Christiansen wrote about the "Seven Deadly Sins of > Perl": > > http://www.perl.com/doc/FMTEYEWTK/versus/perl.html > > > What design mistakes, traps or gotchas do you think Python has? Gotchas > are not necessarily a bad thing, there may be good reasons for it, but > they're surprising. > > To get started, here are a couple of mine: > > > - Python is so dynamic, that there is hardly anything at all that can be > optimized at compile time. > > - The behaviour of mutable default variables is a gotcha. > > - Operators that call dunder methods like __add__ don't use the same > method resolution rules as regular methods, they bypass the instance and > go straight to the type, at least for new-style classes. Slice semantics in combination with negative indices. Take ls = range[10] What is the reverse of ls[a : b]? It is [b-1 : a-1: -1] Except of course when a == 0 or b == 0. -- Antoon Pardon From rosuav at gmail.com Tue Sep 10 06:20:47 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 10 Sep 2013 20:20:47 +1000 Subject: Language design In-Reply-To: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Sep 10, 2013 at 4:09 PM, Steven D'Aprano wrote: > What design mistakes, traps or gotchas do you think Python has? Gotchas > are not necessarily a bad thing, there may be good reasons for it, but > they're surprising. Significant indentation. It gets someone every day, it seems. The fact that importing twice doesn't reexecute any code. The whole "consenting adults" philosophy. I happen to quite like it, as do many of the regulars here, but it does trip up a lot of programmers who've come from other languages. Like you say, not necessarily a bad thing; but Admiral Ackbars all the same. ChrisA From antoon.pardon at rece.vub.ac.be Fri Sep 13 03:04:06 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Fri, 13 Sep 2013 09:04:06 +0200 Subject: Language design In-Reply-To: References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5232B8E6.8050508@rece.vub.ac.be> Op 10-09-13 12:20, Chris Angelico schreef: > On Tue, Sep 10, 2013 at 4:09 PM, Steven D'Aprano wrote: >> What design mistakes, traps or gotchas do you think Python has? Gotchas >> are not necessarily a bad thing, there may be good reasons for it, but >> they're surprising. > > Significant indentation. It gets someone every day, it seems. > Not only that. There are a lot of python code snippets on the net that for whatever reason lost their indentation. There is no algorithm that can restore the lost structure. -- Antoon Pardon From steve+comp.lang.python at pearwood.info Fri Sep 13 06:13:54 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 Sep 2013 10:13:54 GMT Subject: Language design References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5232e562$0$29988$c3e8da3$5496439d@news.astraweb.com> On Fri, 13 Sep 2013 09:04:06 +0200, Antoon Pardon wrote: > Op 10-09-13 12:20, Chris Angelico schreef: >> On Tue, Sep 10, 2013 at 4:09 PM, Steven D'Aprano >> wrote: >>> What design mistakes, traps or gotchas do you think Python has? >>> Gotchas are not necessarily a bad thing, there may be good reasons for >>> it, but they're surprising. >> >> Significant indentation. It gets someone every day, it seems. >> >> > Not only that. There are a lot of python code snippets on the net that > for whatever reason lost their indentation. There is no algorithm that > can restore the lost structure. Is there an algorithm that will restore the lost structure if you delete all the braces from C source code? Perhaps if web sites and mail clients routinely deleted braces, we'd see the broken-by-design software being fixed instead of blaming the language. -- Steven From rosuav at gmail.com Fri Sep 13 07:16:49 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 13 Sep 2013 21:16:49 +1000 Subject: Language design In-Reply-To: <5232e562$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <5232e562$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Sep 13, 2013 at 8:13 PM, Steven D'Aprano wrote: > On Fri, 13 Sep 2013 09:04:06 +0200, Antoon Pardon wrote: > >> Op 10-09-13 12:20, Chris Angelico schreef: >>> On Tue, Sep 10, 2013 at 4:09 PM, Steven D'Aprano >>> wrote: >>>> What design mistakes, traps or gotchas do you think Python has? >>>> Gotchas are not necessarily a bad thing, there may be good reasons for >>>> it, but they're surprising. >>> >>> Significant indentation. It gets someone every day, it seems. >>> >>> >> Not only that. There are a lot of python code snippets on the net that >> for whatever reason lost their indentation. There is no algorithm that >> can restore the lost structure. > > Is there an algorithm that will restore the lost structure if you delete > all the braces from C source code? > > Perhaps if web sites and mail clients routinely deleted braces, we'd see > the broken-by-design software being fixed instead of blaming the language. While I don't deny your statement, I'd like to point out that English usually isn't overly concerned with formatting. You can take this paragraph of text, unwrap it, and then reflow it to any width you like, without materially changing my points. C follows a rule of English which Python breaks, ergo software designed to cope only with English can better cope with C code than with Python code. Removing all braces would be like removing all punctuation - very like, in fact - a very real change to the content, and destruction of important information. Python is extremely unusual in making indentation important information, thus running afoul of systems that aren't meant for any code. But if you look at the quoted text above, I specifically retained your declaration that "Gotchas are not necessarily a bad thing" when citing significant indentation. I'm not here to argue that Python made the wrong choice; I'm only arguing that it frequently confuses people. ChrisA From tjreedy at udel.edu Fri Sep 13 15:32:00 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 13 Sep 2013 15:32:00 -0400 Subject: Language design In-Reply-To: References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <5232e562$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 9/13/2013 7:16 AM, Chris Angelico wrote: > On Fri, Sep 13, 2013 at 8:13 PM, Steven D'Aprano > wrote: >> On Fri, 13 Sep 2013 09:04:06 +0200, Antoon Pardon wrote: >>> Not only that. There are a lot of python code snippets on the net that >>> for whatever reason lost their indentation. There is no algorithm that >>> can restore the lost structure. I believe tabs are worse than spaces with respect to getting lost. >> Is there an algorithm that will restore the lost structure if you delete >> all the braces from C source code? >> >> Perhaps if web sites and mail clients routinely deleted braces, we'd see >> the broken-by-design software being fixed instead of blaming the language. > > While I don't deny your statement, I'd like to point out that English > usually isn't overly concerned with formatting. Poetry, including that in English, often *is* concerned with formatting. Code is more like poetry than prose. > You can take this > paragraph of text, unwrap it, and then reflow it to any width you > like, without materially changing my points. But you cannot do that with poetry! Or mathematical formulas. Or tables. Or text with headers and paragraphs and indented quotations. Etc. What percentage of published books on your bookshelf have NO significant indentation? As far as I know for mine, it is 0. > C follows a rule of English which you just made up, and which is drastically wrong, > which Python breaks, > ergo software designed to cope only with English impoverished plain unformatted prose > can better cope with C code than with Python code. Software that removes formatting info is broken for English as well as Python. > Python is extremely unusual in making indentation > important information You have it backwards. Significant indentation is *normal* in English. C in unusual is being able to write a whole text on a single line. When I was a child, paragraphs were marked by tab indents. The change to new-fangled double spacing with no indent seems to have come along with computer text processing. Perhaps this is because software is more prone to dropping tabs that return characters. -- Terry Jan Reedy From rosuav at gmail.com Fri Sep 13 19:57:36 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 14 Sep 2013 09:57:36 +1000 Subject: Language design In-Reply-To: References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <5232e562$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Sep 14, 2013 at 5:32 AM, Terry Reedy wrote: > Poetry, including that in English, often *is* concerned with formatting. > Code is more like poetry than prose. > > >> You can take this >> paragraph of text, unwrap it, and then reflow it to any width you >> like, without materially changing my points. > > > But you cannot do that with poetry! Evangelical vicar in want of a portable second-hand font. Would dispose, for the same, of a portrait, in frame, of the Bishop-elect of Vermont. I think you could quite easily reconstruct the formatting of that, based on its internal structure. Even in poetry, English doesn't depend on its formatting nearly as much as Python does; and even there, it's line breaks, not indentation - so we're talking more like REXX than Python. In fact, it's not uncommon for poetry to be laid out on a single line with slashes to divide lines: A boat beneath a sunny sky / Lingering onward dreamily / In an evening of July / Children three that nestle near, / Eager eye and willing ear / Pleased a simple tale to hear... in the same way that I might write: call sqlexec "connect to words"; call sqlexec "create table dict (word varchar(20) not null)"; call sqlexec "insert into dict values ('spam')"; call sqlexec "insert into dict values ('ham')" To be sure, it looks nicer laid out with line breaks; but it's possible to replace them with other markers. And indentation still is completely insignificant. The only case I can think of in English of indentation mattering is the one you mentioned of first line of subsequent paragraphs, not by any means a universal convention and definitely not the primary structure of the entire document. Making line breaks significant usually throws people. It took my players a lot of time and hints to figure this out: http://rosuav.com/1/?id=969 ChrisA From dreamingforward at gmail.com Fri Sep 13 20:28:18 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Fri, 13 Sep 2013 17:28:18 -0700 Subject: Language design In-Reply-To: References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <5232e562$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Sep 13, 2013 at 4:57 PM, Chris Angelico wrote: > Evangelical vicar in want of a portable second-hand font. Would > dispose, for the same, of a portrait, in frame, of the Bishop-elect of > Vermont. > > I think you could quite easily reconstruct the formatting of that, > based on its internal structure. Even in poetry, English doesn't > depend on its formatting nearly as much as Python does; (Just to dispose of this old argument:) Both Python and English depend on both syntactical, material delimiters and whitespace. While it may seem that Python depends more on whitespace than English, that is highly contentious, poetry or not. Take some literature, remove all the tabs at paragraph start and CRs at paragraph-end so that it all runs together and you'll find that it impossible to read -- you just won't be able to enter into the universe that the author is attempting to build. -- MarkJ Tacoma, Washington From vito.detullio at gmail.com Sat Sep 14 01:25:17 2013 From: vito.detullio at gmail.com (Vito De Tullio) Date: Sat, 14 Sep 2013 07:25:17 +0200 Subject: Language design References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <5232e562$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: Chris Angelico wrote: > Making line breaks significant usually throws people. It took my > players a lot of time and hints to figure this out: > http://rosuav.com/1/?id=969 fukin' Gaston! -- By ZeD From neilc at norwich.edu Wed Sep 18 10:57:00 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 18 Sep 2013 14:57:00 GMT Subject: Language design References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <5232e562$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-09-13, Chris Angelico wrote: > On Sat, Sep 14, 2013 at 5:32 AM, Terry Reedy wrote: >> Poetry, including that in English, often *is* concerned with formatting. >> Code is more like poetry than prose. >> >> >>> You can take this >>> paragraph of text, unwrap it, and then reflow it to any width you >>> like, without materially changing my points. >> >> >> But you cannot do that with poetry! > > Evangelical vicar in want of a portable second-hand font. Would > dispose, for the same, of a portrait, in frame, of the Bishop-elect of > Vermont. > > I think you could quite easily reconstruct the formatting of > that, based on its internal structure. Even in poetry, English > doesn't depend on its formatting nearly as much as Python does; > and even there, it's line breaks, not indentation - so we're > talking more like REXX than Python. In fact, it's not uncommon > for poetry to be laid out on a single line with slashes to > divide lines: There's lots of poetry with significant indentation, though. Imbuing the shape of the text on the page with significance is a thing. -- Neil Cerutti From rosuav at gmail.com Wed Sep 18 11:02:27 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 Sep 2013 01:02:27 +1000 Subject: Language design In-Reply-To: References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <5232e562$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Sep 19, 2013 at 12:57 AM, Neil Cerutti wrote: > There's lots of poetry with significant indentation, though. > Imbuing the shape of the text on the page with significance is a > thing. And you can do that with C code, too. Doesn't mean that indentation is important to C; it means that you're layering different types of information into a single piece of work. It's like Perl code drawn in the shape of a camel - a beautiful hack. ChrisA From neilc at norwich.edu Wed Sep 18 11:08:57 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 18 Sep 2013 15:08:57 GMT Subject: Language design References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <5232e562$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-09-18, Chris Angelico wrote: > On Thu, Sep 19, 2013 at 12:57 AM, Neil Cerutti wrote: >> There's lots of poetry with significant indentation, though. >> Imbuing the shape of the text on the page with significance is a >> thing. > > And you can do that with C code, too. Doesn't mean that > indentation is important to C; it means that you're layering > different types of information into a single piece of work. > It's like Perl code drawn in the shape of a camel - a beautiful > hack. I just meant you can't condense whitespace in a poem and retain all its meaning. It will break certain kinds of quotation styles in publications, as well. -- Neil Cerutti From rosuav at gmail.com Wed Sep 18 11:12:39 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 Sep 2013 01:12:39 +1000 Subject: Language design In-Reply-To: References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <5232e562$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Sep 19, 2013 at 1:08 AM, Neil Cerutti wrote: > On 2013-09-18, Chris Angelico wrote: >> On Thu, Sep 19, 2013 at 12:57 AM, Neil Cerutti wrote: >>> There's lots of poetry with significant indentation, though. >>> Imbuing the shape of the text on the page with significance is a >>> thing. >> >> And you can do that with C code, too. Doesn't mean that >> indentation is important to C; it means that you're layering >> different types of information into a single piece of work. >> It's like Perl code drawn in the shape of a camel - a beautiful >> hack. > > I just meant you can't condense whitespace in a poem and retain > all its meaning. It will break certain kinds of quotation styles > in publications, as well. Sure. I'm still trying to work out if it's possible to deliver a verbal speech with fancy information in its written version... English is a fun language to tinker with! ChrisA From wrw at mac.com Wed Sep 18 12:58:14 2013 From: wrw at mac.com (William Ray Wing) Date: Wed, 18 Sep 2013 12:58:14 -0400 Subject: Language design In-Reply-To: References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <5232e562$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8264DD11-8FD7-42A4-A36A-C2CACDF4385F@mac.com> On Sep 18, 2013, at 11:12 AM, Chris Angelico wrote: > On Thu, Sep 19, 2013 at 1:08 AM, Neil Cerutti wrote: >> On 2013-09-18, Chris Angelico wrote: >>> On Thu, Sep 19, 2013 at 12:57 AM, Neil Cerutti wrote: >>>> There's lots of poetry with significant indentation, though. >>>> Imbuing the shape of the text on the page with significance is a >>>> thing. >>> >>> And you can do that with C code, too. Doesn't mean that >>> indentation is important to C; it means that you're layering >>> different types of information into a single piece of work. >>> It's like Perl code drawn in the shape of a camel - a beautiful >>> hack. >> >> I just meant you can't condense whitespace in a poem and retain >> all its meaning. It will break certain kinds of quotation styles >> in publications, as well. > > Sure. I'm still trying to work out if it's possible to deliver a > verbal speech with fancy information in its written version... English > is a fun language to tinker with! > > ChrisA > -- > Just to add a data point on the importance of formatting in language. New Testament Greek is/was written with no punctuation, no spaces between words, and no distinction between upper and lower case. This frequently results in the Greek equivalent of the follow English: "iamnowhereiameverywhere" which can be "translated" as either "I am now here, I am everywhere." _or_ "I am nowhere, I am everywhere." In other words, two very different meanings. So, without context or further information, the intent of the original writer can't be inferred. -Bill From wxjmfauth at gmail.com Wed Sep 18 13:45:18 2013 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 18 Sep 2013 10:45:18 -0700 (PDT) Subject: Language design In-Reply-To: References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <5232e562$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <58d30740-049b-41b2-a6ec-c6b0c51f6322@googlegroups.com> >>> 1and 0 0 >>> 'a'or 1 'a' >>> 5if True else 999 5 jmf From neilc at norwich.edu Wed Sep 18 13:55:54 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 18 Sep 2013 17:55:54 GMT Subject: Language design References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <5232e562$0$29988$c3e8da3$5496439d@news.astraweb.com> <58d30740-049b-41b2-a6ec-c6b0c51f6322@googlegroups.com> Message-ID: On 2013-09-18, wxjmfauth at gmail.com wrote: >>>> 1and 0 > 0 >>>> 'a'or 1 > 'a' >>>> 5if True else 999 > 5 Curse you, FSR! Oh, wait... -- Neil Cerutti From antoon.pardon at rece.vub.ac.be Fri Sep 13 07:28:32 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Fri, 13 Sep 2013 13:28:32 +0200 Subject: Language design In-Reply-To: <5232e562$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <5232e562$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5232F6E0.5060506@rece.vub.ac.be> Op 13-09-13 12:13, Steven D'Aprano schreef: > On Fri, 13 Sep 2013 09:04:06 +0200, Antoon Pardon wrote: > >> Op 10-09-13 12:20, Chris Angelico schreef: >>> On Tue, Sep 10, 2013 at 4:09 PM, Steven D'Aprano >>> wrote: >>>> What design mistakes, traps or gotchas do you think Python has? >>>> Gotchas are not necessarily a bad thing, there may be good reasons for >>>> it, but they're surprising. >>> >>> Significant indentation. It gets someone every day, it seems. >>> >>> >> Not only that. There are a lot of python code snippets on the net that >> for whatever reason lost their indentation. There is no algorithm that >> can restore the lost structure. > > Is there an algorithm that will restore the lost structure if you delete > all the braces from C source code? Yes, almost. Just look at the indentation of the program and you will probably be able to restore the braces in 99% of the programs. > Perhaps if web sites and mail clients routinely deleted braces, we'd see > the broken-by-design software being fixed instead of blaming the language. The world is not perfect. If products in your design are hard to repair after some kind of hiccup, then I think the design can be blamed for that. Good design is more than being ok when nothing goes wrong. Good design is also about being recoverable when things do go wrong. -- Antoon Pardon From nobody at nowhere.com Tue Sep 10 20:03:48 2013 From: nobody at nowhere.com (Nobody) Date: Wed, 11 Sep 2013 01:03:48 +0100 Subject: Language design References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, 10 Sep 2013 17:07:09 +1000, Ben Finney wrote: > * Python requires every programmer to know, or quickly learn, the basics > of Unicode: to know that text is not, and never will be again, > synonymous with a sequence of bytes. If only the Python developers would learn the same lesson ... Some of them are so hooked on Unicode that they won't accept that sometimes a sequence of bytes really is just a sequence of bytes. Primary example: most of the POSIX API. From steve+comp.lang.python at pearwood.info Tue Sep 10 20:53:53 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Sep 2013 00:53:53 GMT Subject: Language design References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <522fbf21$0$29988$c3e8da3$5496439d@news.astraweb.com> On Wed, 11 Sep 2013 01:03:48 +0100, Nobody wrote: > On Tue, 10 Sep 2013 17:07:09 +1000, Ben Finney wrote: > >> * Python requires every programmer to know, or quickly learn, the >> basics >> of Unicode: to know that text is not, and never will be again, >> synonymous with a sequence of bytes. > > If only the Python developers would learn the same lesson ... > > Some of them are so hooked on Unicode that they won't accept that > sometimes a sequence of bytes really is just a sequence of bytes. > Primary example: most of the POSIX API. And lo, Guido's Time Machine strikes again. Python 3 has not one but TWO built-in types for handling sequences of bytes: * bytes # immutable string of bytes * bytearray # mutable array of bytes and most routines that handle file names accept either text strings or bytes strings: py> open('a?', 'w').write("hello\n") 6 py> open(b'a\xc3\x9f', 'r').read() 'hello\n' -- Steven From nobody at nowhere.com Thu Sep 12 13:23:32 2013 From: nobody at nowhere.com (Nobody) Date: Thu, 12 Sep 2013 18:23:32 +0100 Subject: Language design References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <522fbf21$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, 11 Sep 2013 00:53:53 +0000, Steven D'Aprano wrote: > and most routines that handle file names accept either text strings or > bytes strings: I was going to say "that just leaves environ and argv". But I see that os.environb was added in 3.2. Which just leaves argv. From clp2 at rebertia.com Tue Sep 10 21:46:00 2013 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 10 Sep 2013 18:46:00 -0700 Subject: Language design In-Reply-To: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: * No explicit variable declarations (modulo `global`+`nonlocal`) means that variable name typos can't be reliably detected at compile-time. * The value of the loop variable at call-time for functions defined within a loop trips people up. * No self-balancing tree datatype of any kind is included in the std lib. * Function scope rather than block scope (e.g. `while` doesn't introduce a new scope) [Personally, I don't have much of a problem with this, but some people do.] * No anonymous block syntax (cf. Ruby or Smalltalk). Makes it harder/uglier to define/use custom control structures. The `with` statement would have been unnecessary. Cheers, Chris On Mon, Sep 9, 2013 at 11:09 PM, Steven D'Aprano wrote: > Some time ago, Tom Christiansen wrote about the "Seven Deadly Sins of > Perl": > > http://www.perl.com/doc/FMTEYEWTK/versus/perl.html > > > What design mistakes, traps or gotchas do you think Python has? Gotchas > are not necessarily a bad thing, there may be good reasons for it, but > they're surprising. > > To get started, here are a couple of mine: > > > - Python is so dynamic, that there is hardly anything at all that can be > optimized at compile time. > > - The behaviour of mutable default variables is a gotcha. > > - Operators that call dunder methods like __add__ don't use the same > method resolution rules as regular methods, they bypass the instance and > go straight to the type, at least for new-style classes. > > > > -- > Steven > -- > https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Wed Sep 11 00:21:14 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 11 Sep 2013 14:21:14 +1000 Subject: Language design In-Reply-To: References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Sep 11, 2013 at 11:46 AM, Chris Rebert wrote: > * The value of the loop variable at call-time for functions defined > within a loop trips people up. Related: The confusion of 'with' vs __del__ vs del wrt open files etc. Using 'with' does not guarantee the object's destruction, but the destruction of the object and the exiting of the with block do have the same effect, which is confusing. Personally, I'd prefer a guarantee that this name expires at this point, plus a guarantee that - if there are no other references - the object will be cleaned up immediately; it's generally true in CPython, and if that could actually be made a language feature, there'd be no need for 'with' and no issues with confusing people. ChrisA From burak.arslan at arskom.com.tr Wed Sep 11 06:38:06 2013 From: burak.arslan at arskom.com.tr (Burak Arslan) Date: Wed, 11 Sep 2013 13:38:06 +0300 Subject: Language design In-Reply-To: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5230480E.2030406@arskom.com.tr> On 09/10/13 09:09, Steven D'Aprano wrote: > What design mistakes, traps or gotchas do you think Python has? My favourite gotcha is this: elt, = elts It's a nice and compact way to do both: assert len(elts) == 0 elt = elts[0] but it sure looks strange at first sight. As a bonus, it works on any iterable, not just ones that support __getitem__. burak From ethan at stoneleaf.us Wed Sep 11 10:52:12 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 11 Sep 2013 07:52:12 -0700 Subject: Language design In-Reply-To: <5230480E.2030406@arskom.com.tr> References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <5230480E.2030406@arskom.com.tr> Message-ID: <5230839C.8050302@stoneleaf.us> On 09/11/2013 03:38 AM, Burak Arslan wrote: > On 09/10/13 09:09, Steven D'Aprano wrote: >> What design mistakes, traps or gotchas do you think Python has? > > My favourite gotcha is this: > > elt, = elts > > It's a nice and compact way to do both: > > assert len(elts) == 0 Perhaps you meant 'assert len(elts) == 1' ? -- ~Ethan~ From burak.arslan at arskom.com.tr Wed Sep 11 11:41:53 2013 From: burak.arslan at arskom.com.tr (Burak Arslan) Date: Wed, 11 Sep 2013 18:41:53 +0300 Subject: Language design In-Reply-To: <5230839C.8050302@stoneleaf.us> References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <5230480E.2030406@arskom.com.tr> <5230839C.8050302@stoneleaf.us> Message-ID: <52308F41.4050300@arskom.com.tr> On 09/11/13 17:52, Ethan Furman wrote: > On 09/11/2013 03:38 AM, Burak Arslan wrote: >> On 09/10/13 09:09, Steven D'Aprano wrote: >>> What design mistakes, traps or gotchas do you think Python has? >> >> My favourite gotcha is this: >> >> elt, = elts >> >> It's a nice and compact way to do both: >> >> assert len(elts) == 0 > > Perhaps you meant 'assert len(elts) == 1' ? > yes :) From joshua at landau.ws Thu Sep 12 00:17:44 2013 From: joshua at landau.ws (Joshua Landau) Date: Thu, 12 Sep 2013 05:17:44 +0100 Subject: Language design In-Reply-To: <5230480E.2030406@arskom.com.tr> References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <5230480E.2030406@arskom.com.tr> Message-ID: On 11 September 2013 11:38, Burak Arslan wrote: > On 09/10/13 09:09, Steven D'Aprano wrote: >> What design mistakes, traps or gotchas do you think Python has? > > My favourite gotcha is this: > > elt, = elts > > It's a nice and compact way to do both: > > assert len(elts) == 0 > elt = elts[0] > > but it sure looks strange at first sight. As a bonus, it works on any > iterable, not just ones that support __getitem__. I very much enjoy the "[elt] = elts" spelling, although I don't get how this is a "gotcha". It's just a semi-obscure usage of unpacking. From neilc at norwich.edu Wed Sep 11 10:32:57 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 11 Sep 2013 14:32:57 GMT Subject: Language design References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-09-11, Burak Arslan wrote: > On 09/10/13 09:09, Steven D'Aprano wrote: >> What design mistakes, traps or gotchas do you think Python has? > > My favourite gotcha is this: > > elt, = elts > > It's a nice and compact way to do both: > > assert len(elts) == 0 > elt = elts[0] I'm confused. Your rewrite looks like an assertion error or an IndexError. -- Neil Cerutti From rosuav at gmail.com Wed Sep 11 10:46:02 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 Sep 2013 00:46:02 +1000 Subject: Language design In-Reply-To: References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Sep 12, 2013 at 12:32 AM, Neil Cerutti wrote: > On 2013-09-11, Burak Arslan wrote: >> My favourite gotcha is this: >> >> elt, = elts >> >> It's a nice and compact way to do both: >> >> assert len(elts) == 0 >> elt = elts[0] > > I'm confused. Your rewrite looks like an assertion error or an > IndexError. Presumably he meant to assert that the length is 1. If elts is a list, then yes, these are equivalent, though the expanded form is actually a bit different (since any iterable can be used). ChrisA From python at markusrother.de Wed Sep 11 16:41:50 2013 From: python at markusrother.de (Markus Rother) Date: Wed, 11 Sep 2013 22:41:50 +0200 Subject: Language design In-Reply-To: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5230D58E.9020508@markusrother.de> Hello all, Thanks for this thread. Here are my two cents... On 10.09.2013 08:09, Steven D'Aprano wrote: > What design mistakes, traps or gotchas do you think Python has? Gotchas > are not necessarily a bad thing, there may be good reasons for it, but > they're surprising. """ 1. Occasionally, one encounters a strange idiom. Syntactically legal and consistent, though: >>> +4++4 8 >>> -4+-4 -8 >>> -4-+4 -8 2. Reduce removed from standard library. That is a big fail, in my opinion. 3. The default return value of methods is None instead of self. If it was self, it would be possible to chain method calls (which is called a cascade in smalltalk). >>> lst = [] >>> lst.append(1).append(2).append(3) ## FAIL Traceback (most recent call last): ... AttributeError: 'NoneType' object has no attribute 'append' Instead, this works: >>> class Coll(list): ... ... def add(self, e): ... self.append(e) ... return self ... >>> lst = Coll() >>> lst.add(1).add(2).add(3) ## OK [1, 2, 3] A very practical use case is, that the return value of None makes all of these methods unusable for reduce. >>> from functools import reduce ... >>> many = [{1: 'a'}, {2: 'b'}, {3: 'c'}] ... >>> reduce(lambda d, other : d.update(other), many, {}) ## FAIL Traceback (most recent call last): ... AttributeError: 'NoneType' object has no attribute 'update' Again, one would have to define an update function with an explicit return value. >>> many = [{1: 'a'}, {2: 'b'}, {3: 'c'}] ... >>> def fn(d, other): ... d.update(other) ... return d ... >>> reduce(fn, many, {}) ## OK {1: 'a', 2: 'b', 3: 'c'} 4. As has been mentioned already, some built-in functions do magic stuff behind the scenes: >>> () == [] False But: >>> bool(().__eq__([])) True Because: >>> ().__eq__([]) NotImplemented which yields True when cast to boolean. """ Greets, Markus From ethan at stoneleaf.us Wed Sep 11 17:15:20 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 11 Sep 2013 14:15:20 -0700 Subject: Language design In-Reply-To: <5230D58E.9020508@markusrother.de> References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <5230D58E.9020508@markusrother.de> Message-ID: <5230DD68.2080703@stoneleaf.us> On 09/11/2013 01:41 PM, Markus Rother wrote: > > 4. As has been mentioned already, some built-in functions do magic > stuff behind the scenes: That's why they're called magic methods. ;) > >>> () == [] > False > > But: > > >>> bool(().__eq__([])) > True This is not a trap, this is simply the wrong way to do it. The magic methods (aka dunder methods) are there for Python to call, not you (except under special circumstances, such as when writing your own dunder methods). -- ~Ethan~ From python at markusrother.de Thu Sep 12 13:51:31 2013 From: python at markusrother.de (Markus Rother) Date: Thu, 12 Sep 2013 19:51:31 +0200 Subject: Language design In-Reply-To: <5230DD68.2080703@stoneleaf.us> References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <5230D58E.9020508@markusrother.de> <5230DD68.2080703@stoneleaf.us> Message-ID: <5231FF23.20600@markusrother.de> On 11.09.2013 23:15, Ethan Furman wrote: > On 09/11/2013 01:41 PM, Markus Rother wrote: >> >>> () == [] >> False >> >> But: >> >> >>> bool(().__eq__([])) >> True > > This is not a trap, this is simply the wrong way to do it. The magic > methods (aka dunder methods) are there for Python to call, not you > (except under special circumstances, such as when writing your own > dunder methods). While trying to do it, I learned that its not the right way to do it. However, I was not satisfied with the fact, that there is no built in pure function for operations on primitives. Such that >>> def get_do_stuff (fn): ... def do_stuff(x,y): ... return fn(x,y) ... return do_stuff I understand that python is not a functional language, but it frustrates me at times. Markus From ethan at stoneleaf.us Thu Sep 12 14:05:25 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 12 Sep 2013 11:05:25 -0700 Subject: Language design In-Reply-To: <5231FF23.20600@markusrother.de> References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <5230D58E.9020508@markusrother.de> <5230DD68.2080703@stoneleaf.us> <5231FF23.20600@markusrother.de> Message-ID: <52320265.7080908@stoneleaf.us> On 09/12/2013 10:51 AM, Markus Rother wrote: > On 11.09.2013 23:15, Ethan Furman wrote: >> On 09/11/2013 01:41 PM, Markus Rother wrote: >>> >>> () == [] >>> False >>> >>> But: >>> >>> >>> bool(().__eq__([])) >>> True >> >> This is not a trap, this is simply the wrong way to do it. The magic >> methods (aka dunder methods) are there for Python to call, not you >> (except under special circumstances, such as when writing your own >> dunder methods). > > While trying to do it, I learned that its not the right way to do it. > However, I was not satisfied with the fact, that there is no built in > pure function for operations on primitives. Such that > >>>> def get_do_stuff (fn): > ... def do_stuff(x,y): > ... return fn(x,y) > ... return do_stuff > > I understand that python is not a functional language, but it > frustrates me at times. --> import operator --> operator.__all__ # public api methods are in __all__ ['abs', 'add', 'and_', 'attrgetter', 'concat', 'contains', 'countOf', 'delitem', 'eq', 'floordiv', 'ge', 'getitem', 'gt', 'iadd', 'iand', 'iconcat', 'ifloordiv', 'ilshift', 'imod', 'imul', 'index', 'indexOf', 'inv', 'invert', 'ior', 'ipow', 'irshift', 'is_', 'is_not', 'isub', 'itemgetter', 'itruediv', 'ixor', 'le', 'length_hint', 'lshift', 'lt', 'methodcaller', 'mod', 'mul', 'ne', 'neg', 'not_', 'or_', 'pos', 'pow', 'rshift', 'setitem', 'sub', 'truediv', 'truth', 'xor'] Imports are a Good Thing; not everything has to be built in. -- ~Ethan~ From neilc at norwich.edu Thu Sep 12 14:06:44 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 12 Sep 2013 18:06:44 GMT Subject: Language design References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <5230D58E.9020508@markusrother.de> <5230DD68.2080703@stoneleaf.us> Message-ID: On 2013-09-12, Markus Rother wrote: > On 11.09.2013 23:15, Ethan Furman wrote: >> On 09/11/2013 01:41 PM, Markus Rother wrote: >>> >>> () == [] >>> False >>> >>> But: >>> >>> >>> bool(().__eq__([])) >>> True >> >> This is not a trap, this is simply the wrong way to do it. The magic >> methods (aka dunder methods) are there for Python to call, not you >> (except under special circumstances, such as when writing your own >> dunder methods). > > While trying to do it, I learned that its not the right way to do it. > However, I was not satisfied with the fact, that there is no built in > pure function for operations on primitives. Such that > >>>> def get_do_stuff (fn): > ... def do_stuff(x,y): > ... return fn(x,y) > ... return do_stuff > > I understand that python is not a functional language, but it > frustrates me at times. >>> import operator >>> equal = get_do_stuff(operator.eq)(7, 7.0) True -- Neil Cerutti From rosuav at gmail.com Wed Sep 11 19:27:18 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 Sep 2013 09:27:18 +1000 Subject: Language design In-Reply-To: <5230D58E.9020508@markusrother.de> References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <5230D58E.9020508@markusrother.de> Message-ID: On Thu, Sep 12, 2013 at 6:41 AM, Markus Rother wrote: > 3. The default return value of methods is None instead of self. > If it was self, it would be possible to chain method calls (which > is called a cascade in smalltalk). > > > >>> lst = [] > >>> lst.append(1).append(2).append(3) ## FAIL > Traceback (most recent call last): > ... > AttributeError: 'NoneType' object has no attribute 'append' That's a policy decision: a method (or function) will *EITHER* return a value, *OR* mutate its primary argument (in the case of a method, that's self). It reduces the chances of code like this: foo = [1, 4, 2, 8, 5, 7] largest_digit = foo.sort()[-1] one_seventh = ''.join(map(str,foo)) If you used sorted(foo) instead of foo.sort(), this wouldn't crash out, and it'd do what you expect. Having foo.sort() return self would mean this wouldn't crash, but would potentially do something surprising. But while I understand the reasoning behind it, I don't entirely agree. There are times when I use Pike's sort() function [1], which does return its mutated argument, something like this: foo = sort(blah_blah_blah()) Why should that be split into two statements? Or alternatively, why should an extra copy of the list be created (if you use Python's sorted() here)? But for the new programmer, this is a convenient safety-net, and if list.sort() worked the other way, it'd be just as much a gotcha ("I ask for a sorted list, and it also changed the original?!??"). ChrisA [1] http://pike.lysator.liu.se/generated/manual/modref/ex/predef_3A_3A/sort.html From python at markusrother.de Thu Sep 12 14:13:00 2013 From: python at markusrother.de (Markus Rother) Date: Thu, 12 Sep 2013 20:13:00 +0200 Subject: Language design In-Reply-To: References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <5230D58E.9020508@markusrother.de> Message-ID: <5232042C.3020700@markusrother.de> On 12.09.2013 01:27, Chris Angelico wrote: > On Thu, Sep 12, 2013 at 6:41 AM, Markus Rother wrote: >> 3. The default return value of methods is None instead of self. >> If it was self, it would be possible to chain method calls (which >> is called a cascade in smalltalk). >> >> >> >>> lst = [] >> >>> lst.append(1).append(2).append(3) ## FAIL >> Traceback (most recent call last): >> ... >> AttributeError: 'NoneType' object has no attribute 'append' > > That's a policy decision: a method (or function) will *EITHER* return > a value, *OR* mutate its primary argument (in the case of a method, > that's self). You are stating: "All getters must be free of side effects". That is not the case. Furthermore, the demand for getters with hidden side effects is the reasoning behind properties. The policy could as well be: a method (not a function) will either return a value, or return self, whether or not the object was mutated. > Why should that be split into two statements? Or alternatively, why > should an extra copy of the list be created (if you use Python's > sorted() here)? But for the new programmer, this is a convenient > safety-net, and if list.sort() worked the other way, it'd be just as > much a gotcha ("I ask for a sorted list, and it also changed the > original?!??"). I understand the point you are making in the end, in the interest of having an easy to start with language. Markus From rosuav at gmail.com Thu Sep 12 17:53:39 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 13 Sep 2013 07:53:39 +1000 Subject: Language design In-Reply-To: <5232042C.3020700@markusrother.de> References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <5230D58E.9020508@markusrother.de> <5232042C.3020700@markusrother.de> Message-ID: On Fri, Sep 13, 2013 at 4:13 AM, Markus Rother wrote: > On 12.09.2013 01:27, Chris Angelico wrote: >> On Thu, Sep 12, 2013 at 6:41 AM, Markus Rother wrote: >>> 3. The default return value of methods is None instead of self. >>> If it was self, it would be possible to chain method calls (which >>> is called a cascade in smalltalk). >> >> That's a policy decision: a method (or function) will *EITHER* return >> a value, *OR* mutate its primary argument (in the case of a method, >> that's self). > > You are stating: "All getters must be free of side effects". > That is not the case. Furthermore, the demand for getters with hidden > side effects is the reasoning behind properties. This isn't a language feature here, just a stdlib policy. It's more akin to Ruby's habit of adorning the mutating methods with an exclamation mark - it's a way of stopping you from accidentally doing what you didn't mean to do. There's a sharp distinction between list.sort(), which mutates in place and returns None, and sorted(), which doesn't touch its argument and returns a new list. ChrisA From dreamingforward at gmail.com Wed Sep 11 17:30:54 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Wed, 11 Sep 2013 14:30:54 -0700 Subject: Language design In-Reply-To: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: 1) It tried to make Object the parent of every class. No one's close enough to God to make that work. 2) It didn't make dicts inherit from sets when they were added to Python. 3) It used the set literal for dict, so that there's no obvious way to do it. This didn't get changed in Py3k. 4?) It allowed [reference] variables to be used as dict keys. This creates a parsing difficulty for me, mentally. Keys should be direct, hashable values, not hidden in a variable name. A few of the top of the head.... Mark On Mon, Sep 9, 2013 at 11:09 PM, Steven D'Aprano wrote: > Some time ago, Tom Christiansen wrote about the "Seven Deadly Sins of > Perl": > > http://www.perl.com/doc/FMTEYEWTK/versus/perl.html > > > What design mistakes, traps or gotchas do you think Python has? Gotchas > are not necessarily a bad thing, there may be good reasons for it, but > they're surprising. > > To get started, here are a couple of mine: > > > - Python is so dynamic, that there is hardly anything at all that can be > optimized at compile time. > > - The behaviour of mutable default variables is a gotcha. > > - Operators that call dunder methods like __add__ don't use the same > method resolution rules as regular methods, they bypass the instance and > go straight to the type, at least for new-style classes. > > > > -- > Steven > -- > https://mail.python.org/mailman/listinfo/python-list -- MarkJ Tacoma, Washington From ramit.prasad at jpmorgan.com.dmarc.invalid Wed Sep 11 17:56:43 2013 From: ramit.prasad at jpmorgan.com.dmarc.invalid (Prasad, Ramit) Date: Wed, 11 Sep 2013 21:56:43 +0000 Subject: Language design In-Reply-To: References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF474186E9190@SCACMX007.exchad.jpmchase.net> Mark Janssen wrote: > 1) It tried to make Object the parent of every class. No one's close > enough to God to make that work. > 2) It didn't make dicts inherit from sets when they were added to Python. > 3) It used the set literal for dict, so that there's no obvious way to > do it. This didn't get changed in Py3k. > 4?) It allowed [reference] variables to be used as dict keys. This > creates a parsing difficulty for me, mentally. Keys should be direct, > hashable values, not hidden in a variable name. What do you mean by 4? Do you mean that keys should only be hardcoded? I am going to assume you meant something different, as that sounds like a terrible idea to me... > > A few of the top of the head.... > > Mark This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ben+python at benfinney.id.au Wed Sep 11 19:22:37 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 12 Sep 2013 09:22:37 +1000 Subject: Please omit false legalese footers (was: Language design) References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF474186E9190@SCACMX007.exchad.jpmchase.net> Message-ID: <7wtxhr0wqq.fsf_-_@benfinney.id.au> "Prasad, Ramit" writes: > This email is confidential and subject to important disclaimers and > conditions including on offers for the purchase or sale of securities, > accuracy and completeness of information, viruses, confidentiality, > legal privilege, and legal entity disclaimers, available at > http://www.jpmorgan.com/pages/disclosures/email. No, your message was not confidential. You sent it to a public mailing list, presumably by choice. So please omit such false and pointless legal rubbish from your messages here. -- \ ?I'd take the awe of understanding over the awe of ignorance | `\ any day.? ?Douglas Adams | _o__) | Ben Finney From skip at pobox.com Thu Sep 12 05:27:51 2013 From: skip at pobox.com (Skip Montanaro) Date: Thu, 12 Sep 2013 04:27:51 -0500 Subject: Please omit false legalese footers (was: Language design) In-Reply-To: <7wtxhr0wqq.fsf_-_@benfinney.id.au> References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF474186E9190@SCACMX007.exchad.jpmchase.net> <7wtxhr0wqq.fsf_-_@benfinney.id.au> Message-ID: More likely, JP Morgan's mail system added that footer to the message on the way out the virtual door. My recommendation would be to not post using your company email address. Get a free email address. Skip From oscar.j.benjamin at gmail.com Thu Sep 12 05:44:36 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 12 Sep 2013 10:44:36 +0100 Subject: Please omit false legalese footers (was: Language design) In-Reply-To: References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF474186E9190@SCACMX007.exchad.jpmchase.net> <7wtxhr0wqq.fsf_-_@benfinney.id.au> Message-ID: On 12 September 2013 10:27, Skip Montanaro wrote: > > More likely, JP Morgan's mail system added that footer to the message > on the way out the virtual door. My recommendation would be to not > post using your company email address. Get a free email address. It wouldn't surprise me if JPMorgan would block free email addresses on site. Oscar From invalid at invalid.invalid Thu Sep 12 16:12:27 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 12 Sep 2013 20:12:27 +0000 (UTC) Subject: Please omit false legalese footers (was: Language design) References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF474186E9190@SCACMX007.exchad.jpmchase.net> Message-ID: On 2013-09-11, Ben Finney wrote: > "Prasad, Ramit" writes: > >> This email is confidential and subject to important disclaimers and >> conditions including on offers for the purchase or sale of securities, >> accuracy and completeness of information, viruses, confidentiality, >> legal privilege, and legal entity disclaimers, available at >> http://www.jpmorgan.com/pages/disclosures/email. > > No, your message was not confidential. You sent it to a public > mailing list, presumably by choice. So please omit such false and > pointless legal rubbish from your messages here. OTOH, perhaps it was confidential. In which case, J. P. Morgan might want to know that ramit.prasad is sending confidential information to a pulic mailing list. -- Grant Edwards grant.b.edwards Yow! BARRY ... That was at the most HEART-WARMING gmail.com rendition of "I DID IT MY WAY" I've ever heard!! From steve+comp.lang.python at pearwood.info Wed Sep 11 19:40:22 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Sep 2013 23:40:22 GMT Subject: Language design References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5230ff66$0$29988$c3e8da3$5496439d@news.astraweb.com> On Wed, 11 Sep 2013 14:30:54 -0700, Mark Janssen wrote: > 1) It tried to make Object the parent of every class. Tried, and succeeded. > No one's close enough to God to make that work. Non-sequitor. One doesn't need to be close to a deity to have a single root of the object hierarchy. > 2) It didn't make dicts inherit from sets when they were added to > Python. Why would you want dicts to inherit from sets? > 3) It used the set literal for dict, so that there's no obvious > way to do it. This didn't get changed in Py3k. No, it uses the dict literal for dicts. And the obvious way to form an empty set is by calling set(), the same as str(), int(), list(), float(), tuple(), dict(), ... > 4?) It allowed > [reference] variables to be used as dict keys. This creates a parsing > difficulty for me, mentally. Keys should be direct, hashable values, > not hidden in a variable name. I don't even understand what you are talking about here. "[reference] variables"? What does that mean? Dict keys are direct, hashable values, and I have no idea what you mean by "hidden in a variable name". -- Steven From dreamingforward at gmail.com Wed Sep 11 20:49:09 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Wed, 11 Sep 2013 17:49:09 -0700 Subject: Language design In-Reply-To: <5230ff66$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <5230ff66$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: >> 1) It tried to make Object the parent of every class. > > Tried, and succeeded. Really? Are you saying you (and the community at-large) always derive from Object as your base class? >> No one's close enough to God to make that work. > > Non-sequitor. One doesn't need to be close to a deity to have a single > root of the object hierarchy. But wait is it the "base" (at the bottom of the hierarchy) or is it the "parent" at the top? You see, you, like everyone else has been using these terms loosely, confusing yourself. >> 2) It didn't make dicts inherit from sets when they were added to >> Python. > > Why would you want dicts to inherit from sets? A dict is-a set of {key:object, key:object} pairs bound together with a colon ":". By inheriting from sets you get a lot of useful functionality for free. That you don't know how you could use that functionality is a failure of your imagination, not of the general idea. >> 3) It used the set literal for dict, so that there's no obvious >> way to do it. This didn't get changed in Py3k. > > No, it uses the dict literal for dicts. Right. The dict literal should be {:} -- the one obvious way to do it. Pay me later. > And the obvious way to form an empty set is by calling set(), the same as > str(), int(), list(), float(), tuple(), dict(), ... Blah, blah. Let me know when you got everyone migrated over to Python.v3. >> 4?) It allowed >> [reference] variables to be used as dict keys. This creates a parsing >> difficulty for me, mentally. Keys should be direct, hashable values, >> not hidden in a variable name. > > I don't even understand what you are talking about here. "[reference] > variables"? What does that mean? It's a just a tricky point, that I will wait to comment on. --mark From tjreedy at udel.edu Wed Sep 11 21:40:39 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 11 Sep 2013 21:40:39 -0400 Subject: Language design In-Reply-To: References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <5230ff66$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 9/11/2013 8:49 PM, Mark Janssen wrote: >>> 1) It tried to make Object the parent of every class. >> >> Tried, and succeeded. > > Really? Are you saying you (and the community at-large) always derive > from Object as your base class? The name is 'object', and yes, everyone does it because it is automatic. (I am including indirect inheritance, and excluding weird metaclass games.) >>> class C(): pass >>> dir(C) ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__'] Just *where* do you think all those methods come from. >>> C.__bases__ (,) > But wait is it the "base" (at the bottom of the hierarchy) or is it > the "parent" at the top? This sort of quibbling should be beneath you. > A dict is-a set of {key:object, key:object} pairs bound together with > a colon ":". Yes... but there is a very important additional condition: each key appears only once. Humans are primates, but that is not a sufficient characterization. > By inheriting from sets you get a lot of useful > functionality for free. Actually, you get a lot of un-useful functionality for free. Because of the extra condition, the rule for adding a key:object pair to a dict is different from the rule for adding a key:object pair to a set of such pairs. The set-union of two dicts is not necessarily a dict. To put is another way, dicts as set subclasses would violate the Liskov Substitution Principle. 'Homogenous' sets (of strings, numbers) would be proper subclasses of set. > Right. The dict literal should be {:} and the set literal 'should' be {}, and would be if Python were redesigned from scratch. Is your imagination so stunted that you actually think we did not discuss that when designing Python 3? We did, but Guido rejected switching because he thought it would cause too much pain and discourage adoption of Python 3 even more than the other code-breaking changes that were made. -- Terry Jan Reedy From rosuav at gmail.com Wed Sep 11 21:41:16 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 Sep 2013 11:41:16 +1000 Subject: Language design In-Reply-To: References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <5230ff66$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Sep 12, 2013 at 10:49 AM, Mark Janssen wrote: >>> 1) It tried to make Object the parent of every class. >> >> Tried, and succeeded. > > Really? Are you saying you (and the community at-large) always derive > from Object as your base class? Uhh, yep? It kinda happens automatically for me: Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)] on win32 >>> class Foo: pass >>> Foo.__bases__ (,) Yeah, I think I'm always deriving from object. Also, if ever I write code that has to run also on 2.x, I'll do that explicitly, to be sure it works the same way. ChrisA From steve at pearwood.info Thu Sep 12 01:33:45 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 12 Sep 2013 05:33:45 GMT Subject: Language design References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <5230ff66$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52315238$0$29999$c3e8da3$5496439d@news.astraweb.com> By the way, please keep attributions for those you are quoting. It is rude otherwise. On Wed, 11 Sep 2013 17:49:09 -0700, Mark Janssen wrote: >>> 1) It tried to make Object the parent of every class. >> >> Tried, and succeeded. > > Really? Are you saying you (and the community at-large) always derive > from Object as your base class? Not directly, that would be silly. But if you derive from int, or dict, or ValueError, or any other type, you're indirectly deriving from object since they derive from object. In Python 3, *everything* derives from object. In Python 2, the situation is slightly different in that there are still legacy ("old style" or "classic") classes, but that's an old version of Python. It's not quite obsolete as yet, but in another five years or so it will be. The important thing is, as of *right now*, there are Python versions where object is the base class of every class. >>> No one's close enough to God to make that work. >> >> Non-sequitor. One doesn't need to be close to a deity to have a single >> root of the object hierarchy. > > But wait is it the "base" (at the bottom of the hierarchy) or is it the > "parent" at the top? You see, you, like everyone else has been using > these terms loosely, confusing yourself. Depends on whether I'm standing on my head or not. Or more importantly, it depends on whether I visualise my hierarchy going top->down or bottom->up. Both are relevant, and both end up with the *exact same hierarchy* with only the direction reversed. >>> 2) It didn't make dicts inherit from sets when they were added to >>> Python. >> >> Why would you want dicts to inherit from sets? > > A dict is-a set of {key:object, key:object} pairs bound together with a > colon ":". It certainly is not. py> {'x': []} # Lists can be in dicts. {'x': []} py> set([[]]) # But not in sets. Traceback (most recent call last): File "", line 1, in TypeError: unhashable type: 'list' > By inheriting from sets you get a lot of useful > functionality for free. That you don't know how you could use that > functionality is a failure of your imagination, not of the general idea. No you don't. You get a bunch of ill-defined methods that don't make sense on dicts. For example: what is the intersection of these two dicts? {'a': 1, 'b': 3} {'a': 3, 'b': 5} I can see SIX possibilities: {} {'a': 1, 'b': 3} {'a': 3, 'b': 5} {'a': 3} {'b': 3} raise an exception >>> 3) It used the set literal for dict, so that there's no obvious way to >>> do it. This didn't get changed in Py3k. >> >> No, it uses the dict literal for dicts. > > Right. The dict literal should be {:} -- the one obvious way to do it. I don't agree it is obvious. It is as obvious as (,) being the empty tuple or [,] being the empty list. > Pay me later. > >> And the obvious way to form an empty set is by calling set(), the same >> as str(), int(), list(), float(), tuple(), dict(), ... > > Blah, blah. Let me know when you got everyone migrated over to > Python.v3. What does this have to do with Python 3? It works fine in Python 2. >>> 4?) It allowed >>> [reference] variables to be used as dict keys. This creates a parsing >>> difficulty for me, mentally. Keys should be direct, hashable values, >>> not hidden in a variable name. >> >> I don't even understand what you are talking about here. "[reference] >> variables"? What does that mean? > > It's a just a tricky point, that I will wait to comment on. I'm looking forward to an explanation, as I'm intrigued. -- Steven From dreamingforward at gmail.com Thu Sep 12 23:23:21 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Thu, 12 Sep 2013 20:23:21 -0700 Subject: Language design In-Reply-To: <52315238$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <5230ff66$0$29988$c3e8da3$5496439d@news.astraweb.com> <52315238$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: >> Really? Are you saying you (and the community at-large) always derive >> from Object as your base class? > > Not directly, that would be silly. Silly? "Explicit is better than implicit"... right? >> But wait is it the "base" (at the bottom of the hierarchy) or is it the >> "parent" at the top? You see, you, like everyone else has been using >> these terms loosely, confusing yourself. > > Depends on whether I'm standing on my head or not. > > Or more importantly, it depends on whether I visualise my hierarchy going > top->down or bottom->up. Both are relevant, and both end up with the > *exact same hierarchy* with only the direction reversed. Ha, "only the direction reversed". That little directionality that you're passing by so blithely is the difference between whether you're talking about galaxies or atoms. Please. The simplicity of Python has seduced you into making an "equivocation" of sorts. It's subtle and no one in the field has noticed it. It crept in slowly and imperceptively. >> By inheriting from sets you get a lot of useful >> functionality for free. That you don't know how you could use that >> functionality is a failure of your imagination, not of the general idea. > > No you don't. You get a bunch of ill-defined methods that don't make > sense on dicts. They are not necessarily ill-defined. Keep in mind Python already chose (way back in 1.x) to arbitrary overwrite the values in a key collision. So this problem isn't new. You've simply adapted to this limitation without knowing what you were missing. >>>> 3) It used the set literal for dict, so that there's no obvious way to >>>> do it. This didn't get changed in Py3k. >>> >>> No, it uses the dict literal for dicts. >> >> Right. The dict literal should be {:} -- the one obvious way to do it. > > I don't agree it is obvious. It is as obvious as (,) being the empty tuple > or [,] being the empty list. You're just being argumentative. If there are sets as built-ins, then {:} is the obvious dict literal, because {} is the obvious one for set. You don't need [,] to be the list literal because there is no simpler list-type. >>> And the obvious way to form an empty set is by calling set(), the same >>> as str(), int(), list(), float(), tuple(), dict(), ... >> >> Blah, blah. Let me know when you got everyone migrated over to >> Python.v3. > > What does this have to do with Python 3? It works fine in Python 2. I mean, you're suggestions are coming from a "believer", not someone wanting to understand the limitations of python or whether v3 has succeeded at achieving its potential. >>> I don't even understand what you are talking about here. "[reference] >>> variables"? What does that mean? >> >> It's a just a tricky point, that I will wait to comment on. > > I'm looking forward to an explanation, as I'm intrigued. Well, wer'e here at junior-high. It will take some time.... -- MarkJ Tacoma, Washington From steve+comp.lang.python at pearwood.info Fri Sep 13 01:08:04 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 Sep 2013 05:08:04 GMT Subject: Language design References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <5230ff66$0$29988$c3e8da3$5496439d@news.astraweb.com> <52315238$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52329db3$0$29988$c3e8da3$5496439d@news.astraweb.com> On Thu, 12 Sep 2013 20:23:21 -0700, Mark Janssen wrote: >>> Really? Are you saying you (and the community at-large) always derive >>> from Object as your base class? >> >> Not directly, that would be silly. > > Silly? "Explicit is better than implicit"... right? If I'm inheriting from str, I inherit from str explicitly: class MyStr(str): ... and then str in turn inherits from object explicitly. I certainly do not inherit from object and then re-implement all the string methods from scratch: class MyStr(object): def __new__(cls, value): ... def upper(self): ... def lower(self): ... # and so on... That would be ridiculous, and goes against the very idea of inheritance. But nor do I feel the need to explicitly list the entire superclass hierarchy: class MyStr(str, object): ... which would be silly. Only somebody who doesn't understand how inheritance works in Python would do that. There's simply no need for it, and in fact it would be actively harmful for larger hierarchies. >>> But wait is it the "base" (at the bottom of the hierarchy) or is it >>> the "parent" at the top? You see, you, like everyone else has been >>> using these terms loosely, confusing yourself. >> >> Depends on whether I'm standing on my head or not. >> >> Or more importantly, it depends on whether I visualise my hierarchy >> going top->down or bottom->up. Both are relevant, and both end up with >> the *exact same hierarchy* with only the direction reversed. > > Ha, "only the direction reversed". That little directionality that > you're passing by so blithely is the difference between whether you're > talking about galaxies or atoms. It makes no difference whether I write: atoms -> stars -> galaxies or galaxies <- stars <- atoms nor does it make any difference if I write the chain starting at the top and pointing down, or at the bottom and pointing up. Your objection implies that writing family trees with the most distant ancestor (the root of the tree) at the top of the page somehow confuses people into thinking that perhaps they are the progenitor of people who lived generations earlier. That's absurd -- people simply are not as stupid as you think. > The simplicity of Python has seduced you into making an "equivocation" > of sorts. It's subtle and no one in the field has noticed it. It crept > in slowly and imperceptively. Ah, and now we come to the heart of the matter -- people have been drawing tree-structures with the root at the top of the page for centuries, and Mark Janssen is the first person to have realised that they've got it all backwards. >>> By inheriting from sets you get a lot of useful functionality for >>> free. That you don't know how you could use that functionality is a >>> failure of your imagination, not of the general idea. >> >> No you don't. You get a bunch of ill-defined methods that don't make >> sense on dicts. > > They are not necessarily ill-defined. Keep in mind Python already chose > (way back in 1.x) to arbitrary overwrite the values in a key collision. > So this problem isn't new. You've simply adapted to this limitation > without knowing what you were missing. No, Python didn't "arbitrarily" choose this behaviour. It is standard, normal behaviour for a key-value mapping, and it is the standard behaviour because it is the only behaviour that makes sense for a general purpose mapping. Python did not invent dicts (although it may have invented the choice of name "dict"). If you think of inheritance in the Liskov Substitution sense, then you might *consider* building dicts on top of sets. But it doesn't really work, because there is no way to sensibly keep set-behaviour for dicts. For example, take intersection of two sets s and t. It is a basic principle of set intersection that s&t == t&s. But now, take two dicts with the same keys but different values, d and e. What values should be used when calculating d&e compared to e&d? Since they are different values, we can either: * prefer the values from the left argument over that from the right; * prefer the values from the right argument over that from the left; * refuse to choose and raise an exception; * consider the intersection empty The first three choices will break the Liskov Substitution Principle, since now dicts *cannot* be substituted for sets. The fourth also breaks Liskov, but for a different reason: # sets (key in s) and (key in t) implies (key in s&t); but # dicts (key in d) and (key in e) *does not* imply (key in d&e) So whatever you do, you are screwed Liskov-wise. You cannot derive dicts from sets and still keep the Liskov Substitution Principle. Of course, LSP is not the only way to design your inheritance hierarchies. An alternative is to design them in terms of delegating implementation to the superclass. As Raymond Hettinger puts it, your classes tells it's parent to do some of the work. But in this case, you're still screwed: you can derive sets from dicts, and in fact the first implementation of sets in Python did exactly that, but you cannot derive dicts from sets. So either way, whether you are an OOP purist who designs your classes with type-theoretic purity and the Liskov Substitution Principle in mind, or a pragmatist who designs your classes with delegation of implementation in mind, you can't sensibly derive dicts from sets. >>>>> 3) It used the set literal for dict, so that there's no obvious way >>>>> to do it. This didn't get changed in Py3k. >>>> >>>> No, it uses the dict literal for dicts. >>> >>> Right. The dict literal should be {:} -- the one obvious way to do >>> it. >> >> I don't agree it is obvious. It is as obvious as (,) being the empty >> tuple or [,] being the empty list. > > You're just being argumentative. If there are sets as built-ins, then > {:} is the obvious dict literal, because {} is the obvious one for set. > You don't need [,] to be the list literal because there is no simpler > list-type. The point is that the obvious way to write an empty collection is using a pair of delimiters, not to shove an arbitrary separator separating nothing at all in there: [] is an empty list, not [,] () is an empty tuple, not (,) {} is an empty (dict|set), not {,} or {:} We can't have {} be both an empty set and an empty dict, so one of the two has to miss out. Neither is more obvious than the other. dicts are more important data structures, and they have historical precedence, so they win. If Python was being re-invented from scratch now, or if sets had been around just as long as dicts, people might have chosen to given sets higher priority than dicts, but frankly I doubt it. It's much more common to want an empty dict than an empty set, at least in my experience. >>>> And the obvious way to form an empty set is by calling set(), the >>>> same as str(), int(), list(), float(), tuple(), dict(), ... >>> >>> Blah, blah. Let me know when you got everyone migrated over to >>> Python.v3. >> >> What does this have to do with Python 3? It works fine in Python 2. > > I mean, you're suggestions are coming from a "believer", not someone > wanting to understand the limitations of python or whether v3 has > succeeded at achieving its potential. "not someone wanting to understand the limitations of python..." -- are you aware that I started this thread? -- Steven From rosuav at gmail.com Fri Sep 13 03:39:27 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 13 Sep 2013 17:39:27 +1000 Subject: Language design In-Reply-To: <52329db3$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <5230ff66$0$29988$c3e8da3$5496439d@news.astraweb.com> <52315238$0$29999$c3e8da3$5496439d@news.astraweb.com> <52329db3$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Sep 13, 2013 at 3:08 PM, Steven D'Aprano wrote: > For example, take intersection of two sets s and t. It is a basic > principle of set intersection that s&t == t&s. Note that, while this is true, the two are not actually identical: >>> set1 = {0,1,2} >>> set2 = {0.0,1.0,3.0} >>> set1&set2 {0.0, 1.0} >>> set2&set1 {0, 1} >>> (set1&set2) == (set2&set1) True I'd actually posit that Python has this particular one backward (I'd be more inclined to keep the left operand's value), but it's completely insignificant to most usage. But in any case, there's already the possibility that a set union can be forced to make a choice between two equal objects, so we're already a bit beyond the purity of mathematics. Python could have implemented dicts much more like "sets with values", with set semantics maintained throughout, but it'd require some oddities: >>> {1:"asdf"} == {1:"asdf"} True >>> {1:"asdf"} == {1:"qwer"} False "Sets with values" semantics would demand that these both be True, which is grossly unintuitive. So while it may be true in pure mathematics that a set is-a dict (or a dict is-a set), it's bound to create at least as many gotchas as it solves. ChrisA From dreamingforward at gmail.com Sat Sep 14 22:37:44 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Sat, 14 Sep 2013 19:37:44 -0700 Subject: Language design In-Reply-To: <52329db3$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <5230ff66$0$29988$c3e8da3$5496439d@news.astraweb.com> <52315238$0$29999$c3e8da3$5496439d@news.astraweb.com> <52329db3$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: >>>> Really? Are you saying you (and the community at-large) always derive >>>> from Object as your base class? >>> >>> Not directly, that would be silly. >> >> Silly? "Explicit is better than implicit"... right? > > If I'm inheriting from str, I inherit from str explicitly: > > class MyStr(str): ... > > and then str in turn inherits from object explicitly. I certainly do not > inherit from object and then re-implement all the string methods from > scratch: I know that. Str already inherits from object (due to the language definition). Your inheritance from object is implied by your inheritance from a child class (str), but note there is an implied directionality: you don't say str is the parent of object. But tell me this: is str the superclass of object or is it the other way around? > class MyStr(object): > def __new__(cls, value): ... > def upper(self): ... > def lower(self): ... > # and so on... > > That would be ridiculous, and goes against the very idea of inheritance. > But nor do I feel the need to explicitly list the entire superclass > hierarchy: > > class MyStr(str, object): > ... Now you've lost your marbles. You are arguing points that a python programmer would not argue. Now, since I know you to be a decent python programmer, I can only conclude that your sanity is in question. > which would be silly. Only somebody who doesn't understand how > inheritance works in Python would do that. There's simply no need for it, > and in fact it would be actively harmful for larger hierarchies. Explicitly inheriting from object ("class myBase(object):" rather than "class myBase():") would not be "actively harmful" in any way. >>>> But wait is it the "base" (at the bottom of the hierarchy) or is it >>>> the "parent" at the top? You see, you, like everyone else has been >>>> using these terms loosely, confusing yourself. >>> >>> Depends on whether I'm standing on my head or not. >>> >>> Or more importantly, it depends on whether I visualise my hierarchy >>> going top->down or bottom->up. Both are relevant, and both end up with >>> the *exact same hierarchy* with only the direction reversed. >> >> Ha, "only the direction reversed". That little directionality that >> you're passing by so blithely is the difference between whether you're >> talking about galaxies or atoms. > > It makes no difference whether I write: > > atoms -> stars -> galaxies > > or > > galaxies <- stars <- atoms > > nor does it make any difference if I write the chain starting at the top > and pointing down, or at the bottom and pointing up. Here again, your sanity is questioned. You are simply wrong. Atoms lie within galaxies, but galaxies do not lie within atoms (poetic license excluded); i.e. there is a difference, whether your talking about syntactically by the parser or conceptually by a human being. Somewhere you have to put yourself in the middle. And that point defines how you relate to the machine -- towards abstraction (upwards) or towards the concrete (to the machine itself). >> The simplicity of Python has seduced you into making an "equivocation" >> of sorts. It's subtle and no one in the field has noticed it. It crept >> in slowly and imperceptively. > > Ah, and now we come to the heart of the matter -- people have been > drawing tree-structures with the root at the top of the page for > centuries, and Mark Janssen is the first person to have realised that > they've got it all backwards. I'll be waiting for your apology once you simply grasp the simple (however inconvenient and unbelievable) truth. ;*) >>>> By inheriting from sets you get a lot of useful functionality for >>>> free. That you don't know how you could use that functionality is a >>>> failure of your imagination, not of the general idea. >>> >>> No you don't. You get a bunch of ill-defined methods that don't make >>> sense on dicts. >> >> They are not necessarily ill-defined. Keep in mind Python already chose >> (way back in 1.x) to arbitrary overwrite the values in a key collision. >> So this problem isn't new. You've simply adapted to this limitation >> without knowing what you were missing. > > No, Python didn't "arbitrarily" choose this behaviour. Perhaps you don't recall the discussion. > It is standard, > normal behaviour for a key-value mapping, and it is the standard > behaviour because it is the only behaviour that makes sense for a general > purpose mapping. No. Please don't propagate your limited sense of things as if it "the only way to do it". > Python did not invent dicts (although it may have invented the choice of > name "dict"). > > If you think of inheritance in the Liskov Substitution sense, then you > might *consider* building dicts on top of sets. But it doesn't really > work, because there is no way to sensibly keep set-behaviour for dicts. There's no need to preserve LSP -- it's just one way to think about class relations. In fact, I'll argue that one should not -- because the field has not perfected the object model adequately, so it would lead to a suboptimal situation akin to premature optimization. The conceptual abstraction is most important: a subtype (child class) should do everything that its parent does. (That's far from a complete definition, but I'm just laying the groundwork to start to understand the breadth of ideas and in this landscape of OOP and how they relate to each other.) > For example, take intersection of two sets s and t. It is a basic > principle of set intersection that s&t == t&s. That's called "commutation", grasshopper. That's the word you want to use. > But now, take two dicts with the same keys but different values, d and e. > What values should be used when calculating d&e compared to e&d? Since > they are different values, we can either: > > * prefer the values from the left argument over that from the right; > * prefer the values from the right argument over that from the left; ...the way python effectively does it: d1.update(d2) -- the values in d2 overwrite the values in d1. This is a semi-arbitrary decision. But here's how it should be done: any (op)eration: d1 op d2, should first apply op to the keys of (d1,d2), and then again apply to the values in a recursive fashion to the values. Now one will have to define what should happen for things like __sub__ and such but at least we have a solid framework for starting to think about it in a more sophisticated way. > * refuse to choose and raise an exception; > * consider the intersection empty > > The first three choices will break the Liskov Substitution Principle, > since now dicts *cannot* be substituted for sets. The fourth also breaks > Liskov, but for a different reason: I'm not going to evaluate your claim because I don't care about LSP. Why you obsess over it is simply because it's how you've come to make sense of the confusion that is in the field. > # sets > (key in s) and (key in t) implies (key in s&t); > > but > > # dicts > (key in d) and (key in e) *does not* imply (key in d&e) > Eh? How so? There is a straightforward and obvious mapping from a dict to a set, so your last line could be re-written as key in (set(d)&set(e)) where it is clear that it *is* indeed equivalent. > So either way, whether you are an OOP purist who designs your classes > with type-theoretic purity and the Liskov Substitution Principle in mind, > or a pragmatist who designs your classes with delegation of > implementation in mind, you can't sensibly derive dicts from sets. You *can* sensibly derive dicts from sets, because there is a clear function that can map a dict to a set. The dict, then, is just a specialization of set. As an attempt to try to nail this terminology down. There's "extending" a type, and there's "specializing" a type. One adds more methods and one refines what the methods do. They are different. >>>> Right. The dict literal should be {:} -- the one obvious way to do >>>> it. >>> >>> I don't agree it is obvious. It is as obvious as (,) being the empty >>> tuple or [,] being the empty list. >> >> You're just being argumentative. If there are sets as built-ins, then >> {:} is the obvious dict literal, because {} is the obvious one for set. >> You don't need [,] to be the list literal because there is no simpler >> list-type. > > The point is that the obvious way to write an empty collection is using a > pair of delimiters, not to shove an arbitrary separator separating > nothing at all in there: It's not a arbitrary separator, it is the obvious one, given that set is already using the the empty curly braces and dict uses the colon as a separator. >>>>> And the obvious way to form an empty set is by calling set(), the >>>>> same as str(), int(), list(), float(), tuple(), dict(), ... >>>> >>>> Blah, blah. Let me know when you got everyone migrated over to >>>> Python.v3. >>> >>> What does this have to do with Python 3? It works fine in Python 2. >> >> I mean, you're suggestions are coming from a "believer", not someone >> wanting to understand the limitations of python or whether v3 has >> succeeded at achieving its potential. > > "not someone wanting to understand the limitations of python..." -- are > you aware that I started this thread? Hence, the irony. -- MarkJ Tacoma, Washington From antoon.pardon at rece.vub.ac.be Sun Sep 15 03:57:57 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Sun, 15 Sep 2013 09:57:57 +0200 Subject: Language design In-Reply-To: References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <5230ff66$0$29988$c3e8da3$5496439d@news.astraweb.com> <52315238$0$29999$c3e8da3$5496439d@news.astraweb.com> <52329db3$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52356885.9090905@rece.vub.ac.be> Op 15-09-13 04:37, Mark Janssen schreef: >>> >>> Ha, "only the direction reversed". That little directionality that >>> you're passing by so blithely is the difference between whether you're >>> talking about galaxies or atoms. >> >> It makes no difference whether I write: >> >> atoms -> stars -> galaxies >> >> or >> >> galaxies <- stars <- atoms >> >> nor does it make any difference if I write the chain starting at the top >> and pointing down, or at the bottom and pointing up. > > Here again, your sanity is questioned. You are simply wrong. Atoms > lie within galaxies, but galaxies do not lie within atoms (poetic > license excluded); No body is questioning that. What is being pointed out is, that it doesn't make a difference whether you say that atoms lie within galaxies or you say galaxies have atoms in them. It doesn't matter which of the items you mention first in defining the relation between the two. > i.e. there is a difference, whether your talking > about syntactically by the parser or conceptually by a human being. > Somewhere you have to put yourself in the middle. And that point > defines how you relate to the machine -- towards abstraction (upwards) > or towards the concrete (to the machine itself). Maybe, but where you put yourself is not determined by such unimportant details as to which of the components in a relation you mention first. a < b or b > a, are two ways to write the exact same relation and someone arguing that there is an important difference because in the first case we mention a first while in the second case we mention b first is only illustrating his own confusion. And that is essentially what you are doing. -- Antoon Pardon From steve+comp.lang.python at pearwood.info Wed Sep 11 19:40:35 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Sep 2013 23:40:35 GMT Subject: Language design References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5230ff73$0$29988$c3e8da3$5496439d@news.astraweb.com> On Wed, 11 Sep 2013 22:41:50 +0200, Markus Rother wrote: > 2. Reduce removed from standard library. That is a big fail, in my > opinion. And Guido's Time Machine strikes again! py> from functools import reduce py> reduce [...] > 4. As has been mentioned already, some built-in functions do magic > stuff behind the scenes: > > >>> () == [] > False > > > But: > > > >>> bool(().__eq__([])) > True > > > Because: > > > >>> ().__eq__([]) > NotImplemented > > > which yields True when cast to boolean. """ I don't see that this is a gotcha, let alone a design mistake. There's no reason to be calling __eq__ directly instead of == but if you do, you're responsible for handling the operator protocol yourself. Namely, if the operator special method returns NotImplemented, you're supposed to reverse the operands and try again. -- Steven From python at markusrother.de Thu Sep 12 14:24:44 2013 From: python at markusrother.de (Markus Rother) Date: Thu, 12 Sep 2013 20:24:44 +0200 Subject: Language design In-Reply-To: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <523206EC.8090404@markusrother.de> On 10.09.2013 08:09, Steven D'Aprano wrote: > What design mistakes, traps or gotchas do you think Python has? Gotchas > are not necessarily a bad thing, there may be good reasons for it, but > they're surprising. I have one more: Dictionaries should iterate over their items instead of their keys. Looking forward to contrary opinions. Greets, Markus From ned at nedbatchelder.com Thu Sep 12 14:37:47 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Thu, 12 Sep 2013 14:37:47 -0400 Subject: Language design In-Reply-To: <523206EC.8090404@markusrother.de> References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <523206EC.8090404@markusrother.de> Message-ID: <523209FB.2040703@nedbatchelder.com> On 9/12/13 2:24 PM, Markus Rother wrote: > On 10.09.2013 08:09, Steven D'Aprano wrote: >> What design mistakes, traps or gotchas do you think Python has? Gotchas >> are not necessarily a bad thing, there may be good reasons for it, but >> they're surprising. > I have one more: > > Dictionaries should iterate over their items instead of their keys. I understand the natural desire for this, and I sometimes forget and have to add a ".items()" to my loops. But if you consider how "in" should work with dicts, it's only reasonable that "k in d" examine if a key is in a dict, not if an item is in a dict. And once you have "in" working like that, it's reasonable for iteration to work on keys. Dicts act like collections of keys, each with an associated value. --Ned. > Looking forward to contrary opinions. > > Greets, > Markus From tjreedy at udel.edu Thu Sep 12 14:46:21 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 12 Sep 2013 14:46:21 -0400 Subject: Language design In-Reply-To: <523206EC.8090404@markusrother.de> References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <523206EC.8090404@markusrother.de> Message-ID: On 9/12/2013 2:24 PM, Markus Rother wrote: > Dictionaries should iterate over their items instead of their keys. Dictionaries *can* iterate by keys, values, or items. You would prefer that the default iteration be by items rather than keys. > Looking forward to contrary opinions. When the issue was discussed and decided, a majority of developers preferred keys. A large factor was experience and expectation that iterating by keys is more common than than iterating by items, coupled with the idea that the most common usage should be the default. -- Terry Jan Reedy From neilc at norwich.edu Thu Sep 12 15:18:19 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 12 Sep 2013 19:18:19 GMT Subject: Language design References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-09-12, Markus Rother wrote: > On 10.09.2013 08:09, Steven D'Aprano wrote: >> What design mistakes, traps or gotchas do you think Python has? Gotchas >> are not necessarily a bad thing, there may be good reasons for it, but >> they're surprising. > > I have one more: > > Dictionaries should iterate over their items instead of their keys. > > Looking forward to contrary opinions. Consider the 'in' operator. -- Neil Cerutti From stascrash at gmail.com Tue Sep 10 17:08:45 2013 From: stascrash at gmail.com (stas poritskiy) Date: Tue, 10 Sep 2013 14:08:45 -0700 (PDT) Subject: Dealing with Lists Message-ID: <33650fe9-802e-477d-a361-6d4bdeb28762@googlegroups.com> Greetings to all! i ran into a little logic problem and trying to figure it out. my case is as follows: i have a list of items each item represents a Group i need to create a set of nested groups, so, for example: myGroups = ["head", "neck", "arms", "legs"] i need to get them to be represented like this: (if you can imaging a folder structure) head |_> neck |_> arms |_>legs and so on until i hit the last element. what i thought would work (but don't know really how to advance here) is: def createVNTgroups(self, groupsData): #function recieves the LIST of group elements, INDEX0 is always the #MAIN-ROOT of the tree for i in range(len(groupsData)): print groupsData[i] for q in range(1, len(groupsData)): print groupsData[q] could someone give me a hint? thanks in advance! From stascrash at gmail.com Tue Sep 10 17:10:41 2013 From: stascrash at gmail.com (stas poritskiy) Date: Tue, 10 Sep 2013 14:10:41 -0700 (PDT) Subject: Dealing with Lists In-Reply-To: <33650fe9-802e-477d-a361-6d4bdeb28762@googlegroups.com> References: <33650fe9-802e-477d-a361-6d4bdeb28762@googlegroups.com> Message-ID: <7debc7d9-159c-4fd3-ada3-4f82661ccaed@googlegroups.com> there is a little bit more to this, but i think when i will be able to process the list the way i need it i can continue on my own. From matt.komyanek at gmail.com Tue Sep 10 17:31:18 2013 From: matt.komyanek at gmail.com (matt.komyanek at gmail.com) Date: Tue, 10 Sep 2013 14:31:18 -0700 (PDT) Subject: Dealing with Lists In-Reply-To: <33650fe9-802e-477d-a361-6d4bdeb28762@googlegroups.com> References: <33650fe9-802e-477d-a361-6d4bdeb28762@googlegroups.com> Message-ID: <990d4b72-af39-4f70-9e0d-9d389d1e442e@googlegroups.com> What you're asking is a Ragged Hierarchy. On Tuesday, September 10, 2013 5:08:45 PM UTC-4, stas poritskiy wrote: > Greetings to all! > > > > i ran into a little logic problem and trying to figure it out. > > > > my case is as follows: > > > > i have a list of items each item represents a Group > > > > i need to create a set of nested groups, > > > > so, for example: > > > > myGroups = ["head", "neck", "arms", "legs"] > > > > i need to get them to be represented like this: > > (if you can imaging a folder structure) > > > > head > > |_> neck > > |_> arms > > |_>legs > > > > and so on until i hit the last element. > > > > what i thought would work (but don't know really how to advance here) is: > > > > def createVNTgroups(self, groupsData): > > #function recieves the LIST of group elements, INDEX0 is always the > > #MAIN-ROOT of the tree > > > > for i in range(len(groupsData)): > > print groupsData[i] > > > > for q in range(1, len(groupsData)): > > > > print groupsData[q] > > > > could someone give me a hint? > > > > thanks in advance! From davea at davea.name Tue Sep 10 17:51:03 2013 From: davea at davea.name (Dave Angel) Date: Tue, 10 Sep 2013 21:51:03 +0000 (UTC) Subject: Dealing with Lists References: <33650fe9-802e-477d-a361-6d4bdeb28762@googlegroups.com> Message-ID: On 10/9/2013 17:08, stas poritskiy wrote: > Greetings to all! > > i ran into a little logic problem and trying to figure it out. > > my case is as follows: > > i have a list of items each item represents a Group > > i need to create a set of nested groups, > > so, for example: > > myGroups = ["head", "neck", "arms", "legs"] > > i need to get them to be represented like this: > (if you can imaging a folder structure) > > head > |_> neck > |_> arms > |_>legs I don't know what's meant by that |_> symbol. If it's really supposed to be like subdirectories, there'd be a name associated with the sublist. In which case you'd probably want dicts, not lists. So I'd have to guess you want something like: ["head", ["neck", ["arms", ["legs"]]]] To turn your list into that one, I'd write something like (untested): def chop_up(mylist): if len(mylist) == 1: return mylist return [mylist[0], chop_up(mylist[1:])] I suspect your real problem is totally different, but this was an interesting exercise. -- DaveA From stascrash at gmail.com Tue Sep 10 18:11:13 2013 From: stascrash at gmail.com (stas poritskiy) Date: Tue, 10 Sep 2013 15:11:13 -0700 (PDT) Subject: Dealing with Lists In-Reply-To: References: <33650fe9-802e-477d-a361-6d4bdeb28762@googlegroups.com> Message-ID: <3d1eaccc-cf89-4eb0-b96c-b22a0a2f758e@googlegroups.com> Those simbols are just for visual representation. I need to store each of the first elements of a par, so I can reference to them as to a parent of another group. So head is parent of neck, while neck is parent of arms and so on. I'm not sure I understand how to apply your chop list example, dave From davea at davea.name Tue Sep 10 18:32:25 2013 From: davea at davea.name (Dave Angel) Date: Tue, 10 Sep 2013 22:32:25 +0000 (UTC) Subject: Dealing with Lists References: <33650fe9-802e-477d-a361-6d4bdeb28762@googlegroups.com> <3d1eaccc-cf89-4eb0-b96c-b22a0a2f758e@googlegroups.com> Message-ID: On 10/9/2013 18:11, stas poritskiy wrote: Please include some quotation from the message you're replying to. We can't tell who this was responding to until the very last line, where you mention my name. But since you're using buggy googlegroups, you'd better also read http://wiki.python.org/moin/GoogleGroupsPython > Those simbols are just for visual representation. > Fine. I just don't know what they represent. > I need to store each of the first elements of a par, so I can reference to them as to a parent of another group. Don't know what that means either. > > So head is parent of neck, while neck is parent of arms and so on. They're just strings, not parents of anything. But the real question is whether that list I described is what you wanted: ["head", ["neck", ["arms", ["legs"]]]] > > I'm not sure I understand how to apply your chop list example, dave Call it with a list, and it returns a different one. if I guessed your intent, then the returned list will be correct. If not, then not. myGroups = ["head", "neck", "arms", "legs"] my_directory = chop_up(myGroups) print my_directory Maybe what you were really intending was to build a class that you can create several instances, where an attribute of each instance referred to any children it might have, and a different attribute supplied the instance's name. -- DaveA From roy at panix.com Tue Sep 10 18:30:00 2013 From: roy at panix.com (Roy Smith) Date: Tue, 10 Sep 2013 18:30:00 -0400 Subject: Dealing with Lists References: <33650fe9-802e-477d-a361-6d4bdeb28762@googlegroups.com> <3d1eaccc-cf89-4eb0-b96c-b22a0a2f758e@googlegroups.com> Message-ID: In article <3d1eaccc-cf89-4eb0-b96c-b22a0a2f758e at googlegroups.com>, stas poritskiy wrote: > So head is parent of neck, while neck is parent of arms and so on. The head bone's connected to the neck bone. The neck bone's connected to the arm bone... From steve+comp.lang.python at pearwood.info Tue Sep 10 22:14:06 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Sep 2013 02:14:06 GMT Subject: Dealing with Lists References: <33650fe9-802e-477d-a361-6d4bdeb28762@googlegroups.com> Message-ID: <522fd1ee$0$29988$c3e8da3$5496439d@news.astraweb.com> On Tue, 10 Sep 2013 14:08:45 -0700, stas poritskiy wrote: > Greetings to all! > > i ran into a little logic problem and trying to figure it out. > > my case is as follows: > > i have a list of items each item represents a Group > i need to create a set of nested groups, > so, for example: > > myGroups = ["head", "neck", "arms", "legs"] What is the rule for grouping these items? Below, you suggest: head encloses neck neck encloses arms arms encloses legs which seems rather strange. But if it is *always* the case that each item encloses the next item: def print_nested_list(alist): spaces = ' '*4 for level, item in enumerate(alist): if level != 0: indent = spaces*(level-1) + ' ' print (indent + '|_>'), # note comma print item which gives us this: py> print_nested_list(['head', 'neck', 'arms', 'legs']) head |_> neck |_> arms |_> legs as requested. -- Steven From davea at davea.name Tue Sep 10 22:24:44 2013 From: davea at davea.name (Dave Angel) Date: Wed, 11 Sep 2013 02:24:44 +0000 (UTC) Subject: Dealing with Lists References: <33650fe9-802e-477d-a361-6d4bdeb28762@googlegroups.com> <522fd1ee$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 10/9/2013 22:14, Steven D'Aprano wrote: > On Tue, 10 Sep 2013 14:08:45 -0700, stas poritskiy wrote: > >> Greetings to all! >> >> i ran into a little logic problem and trying to figure it out. >> >> my case is as follows: >> >> i have a list of items each item represents a Group >> i need to create a set of nested groups, >> so, for example: >> >> myGroups = ["head", "neck", "arms", "legs"] > > > What is the rule for grouping these items? Below, you suggest: > > head encloses neck > neck encloses arms > arms encloses legs > > which seems rather strange. But if it is *always* the case that each item > encloses the next item: > > def print_nested_list(alist): > spaces = ' '*4 > for level, item in enumerate(alist): > if level != 0: > indent = spaces*(level-1) + ' ' > print (indent + '|_>'), # note comma > print item > > > which gives us this: > > py> print_nested_list(['head', 'neck', 'arms', 'legs']) > head > |_> neck > |_> arms > |_> legs > > > as requested. > > Very nice. But what I want to know is how did you know that Stan (the OP) wanted his printed output to be formatted that way? He said: >>>>> i need to create a set of nested groups, and >>>>> store each of the first elements of a par, so I can reference to them as to a parent of another group. -- DaveA From steve+comp.lang.python at pearwood.info Tue Sep 10 23:13:48 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Sep 2013 03:13:48 GMT Subject: Dealing with Lists References: <33650fe9-802e-477d-a361-6d4bdeb28762@googlegroups.com> <522fd1ee$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <522fdfec$0$29988$c3e8da3$5496439d@news.astraweb.com> On Wed, 11 Sep 2013 02:24:44 +0000, Dave Angel wrote: > On 10/9/2013 22:14, Steven D'Aprano wrote: > >> On Tue, 10 Sep 2013 14:08:45 -0700, stas poritskiy wrote: >> >>> Greetings to all! >>> >>> i ran into a little logic problem and trying to figure it out. >>> >>> my case is as follows: >>> >>> i have a list of items each item represents a Group i need to create a >>> set of nested groups, so, for example: >>> >>> myGroups = ["head", "neck", "arms", "legs"] >> >> >> What is the rule for grouping these items? Below, you suggest: >> >> head encloses neck >> neck encloses arms >> arms encloses legs >> >> which seems rather strange. But if it is *always* the case that each >> item encloses the next item: >> >> def print_nested_list(alist): >> spaces = ' '*4 >> for level, item in enumerate(alist): >> if level != 0: >> indent = spaces*(level-1) + ' ' >> print (indent + '|_>'), # note comma >> print item >> >> >> which gives us this: >> >> py> print_nested_list(['head', 'neck', 'arms', 'legs']) head >> |_> neck >> |_> arms >> |_> legs >> >> >> as requested. >> >> >> > Very nice. But what I want to know is how did you know that Stan (the > OP) wanted his printed output to be formatted that way? I don't. Stan's email is unclear. But he does show an example: [quote] so, for example: myGroups = ["head", "neck", "arms", "legs"] i need to get them to be represented like this: (if you can imaging a folder structure) head |_> neck |_> arms |_>legs and so on until i hit the last element. [end quote] so I just provided that. > He said: > >>>>>> i need to create a set of nested groups, > and >>>>>> store each of the first elements of a par, so I can reference to >>>>>> them as to a parent of another group. I have no idea what that means :-) I *guess* that what Stan is actually looking for is something like a dictionary-based solution, not lists: {'head': {'neck': {'arms': {}, 'legs': {}}}} which gives: head encloses neck neck encloses arms and legs arms enclose nothing legs enclose nothing or: {'head': {'neck': {'arms': {'legs': {}}}}} which gives: head encloses neck neck encloses arms arms encloses legs legs enclose nothing but I can't really tell for sure. In this second case, using dicts, I might try something like this recursive solution: def print_nested_dict(adict, level=0): if adict == {}: return for key, subdict in sorted(adict.items()): if level != 0: spaces = ' '*4 indent = spaces*(level-1) + ' ' print (indent + '|_>'), # note comma if subdict == {}: print key else: print "%s:-" % key print_nested_dict(subdict, level+1) Given: d = {'head': {'neck': {'legs': {'toes': {}}, 'arms': {'thumbs': {}, 'fingers': {}}}}} we can see this output: py> print_nested_dict(d) head:- |_> neck:- |_> arms:- |_> fingers |_> thumbs |_> legs:- |_> toes -- Steven From stascrash at gmail.com Tue Sep 10 23:44:49 2013 From: stascrash at gmail.com (stas poritskiy) Date: Tue, 10 Sep 2013 20:44:49 -0700 (PDT) Subject: Dealing with Lists In-Reply-To: <522fdfec$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <33650fe9-802e-477d-a361-6d4bdeb28762@googlegroups.com> <522fd1ee$0$29988$c3e8da3$5496439d@news.astraweb.com> <522fdfec$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: Guys, i appreciate the effort put in here, i guess i should've started a little wider on description. sorry for confusion, here it goes: I am developing a script/application that uses adobe Scene7 API. the idea here is mass process a ton of files (hundreds of thousands), we generate image files from 3d applications (3d max in our case), and each rendered file carries a specific naming convention such as this: name_group-subgroup-subgroup_layer_type_zdepth.extention. this translates in a nice array, that i first split using uderscore " _ ". this results in a list that has always the same size. Please note that in the section with group-subgroup-subroug - number of subgroups should can be ANY, and the separator there is dash " - ", so when the first split " _ " occurs, i generate a separate element in my FIRST LIST that has all these groups. I then take the groups and run another split using the dash " - ", to create a new list for only groups. In the second list, what i have is the first element at index 0 - being alwasy the most top (root) group. and all the subgroups are nested inside there. Each subgroup is a parent of the following subroup, thus - above in my diagram i used the body parts as example of logical dependency (sorry if this was unclear, again), now, the next step is using API and its classes i create an instance of an object that generates the group for the file that will created via series of additional methods, the file structure (think of Photoshop as an reference) would have the main group, and a subgroup in it, and so on, depending on the type of the element that we are creating identified in the file name. (this would be using the FIRST LIST created originally) For me to create a subgroup using the API, the first (parent) group should be already created, otherwise, i cannot use a non-existing element to assign a subgroup, therefore , i first my create the ROOT group located at index0 i then must make a subgroup, so the line of code would look similar to this: #creating first group(root) group = intance.add_group(str(name)) #creating subgroup(child of root) subgroup = group.add_group(str(name)) since i don't know how many subgroups each file would have, i want to create a loop, that will do that for me but i am running in a problem, trying to understand the logic for that loop. let me know if you guys need more info from me. On Tuesday, September 10, 2013 10:13:48 PM UTC-5, Steven D'Aprano wrote: > On Wed, 11 Sep 2013 02:24:44 +0000, Dave Angel wrote: > > > > > On 10/9/2013 22:14, Steven D'Aprano wrote: > > > > > >> On Tue, 10 Sep 2013 14:08:45 -0700, stas poritskiy wrote: > > >> > > >>> Greetings to all! > > >>> > > >>> i ran into a little logic problem and trying to figure it out. > > >>> > > >>> my case is as follows: > > >>> > > >>> i have a list of items each item represents a Group i need to create a > > >>> set of nested groups, so, for example: > > >>> > > >>> myGroups = ["head", "neck", "arms", "legs"] > > >> > > >> > > >> What is the rule for grouping these items? Below, you suggest: > > >> > > >> head encloses neck > > >> neck encloses arms > > >> arms encloses legs > > >> > > >> which seems rather strange. But if it is *always* the case that each > > >> item encloses the next item: > > >> > > >> def print_nested_list(alist): > > >> spaces = ' '*4 > > >> for level, item in enumerate(alist): > > >> if level != 0: > > >> indent = spaces*(level-1) + ' ' > > >> print (indent + '|_>'), # note comma > > >> print item > > >> > > >> > > >> which gives us this: > > >> > > >> py> print_nested_list(['head', 'neck', 'arms', 'legs']) head > > >> |_> neck > > >> |_> arms > > >> |_> legs > > >> > > >> > > >> as requested. > > >> > > >> > > >> > > > Very nice. But what I want to know is how did you know that Stan (the > > > OP) wanted his printed output to be formatted that way? > > > > I don't. Stan's email is unclear. But he does show an example: > > > > [quote] > > so, for example: > > > > myGroups = ["head", "neck", "arms", "legs"] > > > > i need to get them to be represented like this: (if you can imaging a > > folder structure) > > > > head > > |_> neck > > |_> arms > > |_>legs > > > > and so on until i hit the last element. > > [end quote] > > > > > > so I just provided that. > > > > > He said: > > > > > >>>>>> i need to create a set of nested groups, > > > and > > >>>>>> store each of the first elements of a par, so I can reference to > > >>>>>> them as to a parent of another group. > > > > > > I have no idea what that means :-) > > > > > > I *guess* that what Stan is actually looking for is something like a > > dictionary-based solution, not lists: > > > > {'head': {'neck': {'arms': {}, 'legs': {}}}} > > > > which gives: > > > > head encloses neck > > neck encloses arms and legs > > arms enclose nothing > > legs enclose nothing > > > > > > or: > > > > {'head': {'neck': {'arms': {'legs': {}}}}} > > > > which gives: > > > > head encloses neck > > neck encloses arms > > arms encloses legs > > legs enclose nothing > > > > > > but I can't really tell for sure. In this second case, using dicts, I > > might try something like this recursive solution: > > > > > > def print_nested_dict(adict, level=0): > > if adict == {}: > > return > > for key, subdict in sorted(adict.items()): > > if level != 0: > > spaces = ' '*4 > > indent = spaces*(level-1) + ' ' > > print (indent + '|_>'), # note comma > > if subdict == {}: > > print key > > else: > > print "%s:-" % key > > print_nested_dict(subdict, level+1) > > > > > > Given: > > > > d = {'head': {'neck': {'legs': {'toes': {}}, 'arms': {'thumbs': {}, > > 'fingers': {}}}}} > > > > we can see this output: > > > > py> print_nested_dict(d) > > head:- > > |_> neck:- > > |_> arms:- > > |_> fingers > > |_> thumbs > > |_> legs:- > > |_> toes > > > > > > > > > > -- > > Steven From stascrash at gmail.com Tue Sep 10 23:52:20 2013 From: stascrash at gmail.com (stas poritskiy) Date: Tue, 10 Sep 2013 20:52:20 -0700 (PDT) Subject: Dealing with Lists In-Reply-To: <522fdfec$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <33650fe9-802e-477d-a361-6d4bdeb28762@googlegroups.com> <522fd1ee$0$29988$c3e8da3$5496439d@news.astraweb.com> <522fdfec$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1ef6a37a-e888-4ecc-a82a-477e19490723@googlegroups.com> Steven, i think you got on the right track with your proposal, although i am not going after the "visual" represenatation that you were able to create, rather a structural one, i think this might work for me, instead of printing, i could be using my commands to make elements (instances of API objects to create my groups inside the file) but one question i might have is : once i created first instance object which in my example is : groups = intance.add_group(str(name)) how would i temporary preserve this name as a reference for the next iteration for the subroups? On Tuesday, September 10, 2013 10:13:48 PM UTC-5, Steven D'Aprano wrote: > On Wed, 11 Sep 2013 02:24:44 +0000, Dave Angel wrote: > > > > > On 10/9/2013 22:14, Steven D'Aprano wrote: > > > > > >> On Tue, 10 Sep 2013 14:08:45 -0700, stas poritskiy wrote: > > >> > > >>> Greetings to all! > > >>> > > >>> i ran into a little logic problem and trying to figure it out. > > >>> > > >>> my case is as follows: > > >>> > > >>> i have a list of items each item represents a Group i need to create a > > >>> set of nested groups, so, for example: > > >>> > > >>> myGroups = ["head", "neck", "arms", "legs"] > > >> > > >> > > >> What is the rule for grouping these items? Below, you suggest: > > >> > > >> head encloses neck > > >> neck encloses arms > > >> arms encloses legs > > >> > > >> which seems rather strange. But if it is *always* the case that each > > >> item encloses the next item: > > >> > > >> def print_nested_list(alist): > > >> spaces = ' '*4 > > >> for level, item in enumerate(alist): > > >> if level != 0: > > >> indent = spaces*(level-1) + ' ' > > >> print (indent + '|_>'), # note comma > > >> print item > > >> > > >> > > >> which gives us this: > > >> > > >> py> print_nested_list(['head', 'neck', 'arms', 'legs']) head > > >> |_> neck > > >> |_> arms > > >> |_> legs > > >> > > >> > > >> as requested. > > >> > > >> > > >> > > > Very nice. But what I want to know is how did you know that Stan (the > > > OP) wanted his printed output to be formatted that way? > > > > I don't. Stan's email is unclear. But he does show an example: > > > > [quote] > > so, for example: > > > > myGroups = ["head", "neck", "arms", "legs"] > > > > i need to get them to be represented like this: (if you can imaging a > > folder structure) > > > > head > > |_> neck > > |_> arms > > |_>legs > > > > and so on until i hit the last element. > > [end quote] > > > > > > so I just provided that. > > > > > He said: > > > > > >>>>>> i need to create a set of nested groups, > > > and > > >>>>>> store each of the first elements of a par, so I can reference to > > >>>>>> them as to a parent of another group. > > > > > > I have no idea what that means :-) > > > > > > I *guess* that what Stan is actually looking for is something like a > > dictionary-based solution, not lists: > > > > {'head': {'neck': {'arms': {}, 'legs': {}}}} > > > > which gives: > > > > head encloses neck > > neck encloses arms and legs > > arms enclose nothing > > legs enclose nothing > > > > > > or: > > > > {'head': {'neck': {'arms': {'legs': {}}}}} > > > > which gives: > > > > head encloses neck > > neck encloses arms > > arms encloses legs > > legs enclose nothing > > > > > > but I can't really tell for sure. In this second case, using dicts, I > > might try something like this recursive solution: > > > > > > def print_nested_dict(adict, level=0): > > if adict == {}: > > return > > for key, subdict in sorted(adict.items()): > > if level != 0: > > spaces = ' '*4 > > indent = spaces*(level-1) + ' ' > > print (indent + '|_>'), # note comma > > if subdict == {}: > > print key > > else: > > print "%s:-" % key > > print_nested_dict(subdict, level+1) > > > > > > Given: > > > > d = {'head': {'neck': {'legs': {'toes': {}}, 'arms': {'thumbs': {}, > > 'fingers': {}}}}} > > > > we can see this output: > > > > py> print_nested_dict(d) > > head:- > > |_> neck:- > > |_> arms:- > > |_> fingers > > |_> thumbs > > |_> legs:- > > |_> toes > > > > > > > > > > -- > > Steven From stascrash at gmail.com Wed Sep 11 10:47:30 2013 From: stascrash at gmail.com (stas poritskiy) Date: Wed, 11 Sep 2013 07:47:30 -0700 (PDT) Subject: Dealing with Lists In-Reply-To: <1ef6a37a-e888-4ecc-a82a-477e19490723@googlegroups.com> References: <33650fe9-802e-477d-a361-6d4bdeb28762@googlegroups.com> <522fd1ee$0$29988$c3e8da3$5496439d@news.astraweb.com> <522fdfec$0$29988$c3e8da3$5496439d@news.astraweb.com> <1ef6a37a-e888-4ecc-a82a-477e19490723@googlegroups.com> Message-ID: <40438965-ec5f-409f-87af-4fb2290ec891@googlegroups.com> ok, so i think that getting the nested list is a little more for what i need, however, i could be wrong here, i got confused with Dave's suggestion. so, i got my lists broken up in a list of lists, but how would i access each of the elements? When i implement this solution my output list (the new one, after CHOPPING) prints like this: [u'arms', [u'a', [u'super', [u'group', [u'type', [u'is', [u'here']]]]]]] so i assume the "indexing" here would be similar to this: 0 1 0 1 0 1 0 1 0 1 0 [u'arms', [u'a', [u'super', [u'group', [u'type', [u'is', [u'here']]]]]]] Basically speaking ( each generated list would be the len=2 ? so, in my understanding, if i need to call the parenet for my FIRST group(most fist created), i would go and call chopGrps[0] this would get me "arms" and if i need to get the second element, (which should be "a" i would call chopGrps[1] but instead, i get the REST of the lists stored there. so what position does "a" take in this nested list? and this same question would apply to the rest of the items Thanks guys! On Tuesday, September 10, 2013 10:52:20 PM UTC-5, stas poritskiy wrote: > Steven, > > i think you got on the right track with your proposal, > > although i am not going after the "visual" represenatation that you were able to create, rather a structural one, i think this might work for me, > > instead of printing, i could be using my commands to make elements (instances of API objects to create my groups inside the file) > > > > but one question i might have is : > > > > once i created first instance object which in my example is : > > groups = intance.add_group(str(name)) > > > > how would i temporary preserve this name as a reference for the next iteration for the subroups? > > > > On Tuesday, September 10, 2013 10:13:48 PM UTC-5, Steven D'Aprano wrote: > > > On Wed, 11 Sep 2013 02:24:44 +0000, Dave Angel wrote: > > > > > > > > > > > > > On 10/9/2013 22:14, Steven D'Aprano wrote: > > > > > > > > > > > > > >> On Tue, 10 Sep 2013 14:08:45 -0700, stas poritskiy wrote: > > > > > > >> > > > > > > >>> Greetings to all! > > > > > > >>> > > > > > > >>> i ran into a little logic problem and trying to figure it out. > > > > > > >>> > > > > > > >>> my case is as follows: > > > > > > >>> > > > > > > >>> i have a list of items each item represents a Group i need to create a > > > > > > >>> set of nested groups, so, for example: > > > > > > >>> > > > > > > >>> myGroups = ["head", "neck", "arms", "legs"] > > > > > > >> > > > > > > >> > > > > > > >> What is the rule for grouping these items? Below, you suggest: > > > > > > >> > > > > > > >> head encloses neck > > > > > > >> neck encloses arms > > > > > > >> arms encloses legs > > > > > > >> > > > > > > >> which seems rather strange. But if it is *always* the case that each > > > > > > >> item encloses the next item: > > > > > > >> > > > > > > >> def print_nested_list(alist): > > > > > > >> spaces = ' '*4 > > > > > > >> for level, item in enumerate(alist): > > > > > > >> if level != 0: > > > > > > >> indent = spaces*(level-1) + ' ' > > > > > > >> print (indent + '|_>'), # note comma > > > > > > >> print item > > > > > > >> > > > > > > >> > > > > > > >> which gives us this: > > > > > > >> > > > > > > >> py> print_nested_list(['head', 'neck', 'arms', 'legs']) head > > > > > > >> |_> neck > > > > > > >> |_> arms > > > > > > >> |_> legs > > > > > > >> > > > > > > >> > > > > > > >> as requested. > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > > Very nice. But what I want to know is how did you know that Stan (the > > > > > > > OP) wanted his printed output to be formatted that way? > > > > > > > > > > > > I don't. Stan's email is unclear. But he does show an example: > > > > > > > > > > > > [quote] > > > > > > so, for example: > > > > > > > > > > > > myGroups = ["head", "neck", "arms", "legs"] > > > > > > > > > > > > i need to get them to be represented like this: (if you can imaging a > > > > > > folder structure) > > > > > > > > > > > > head > > > > > > |_> neck > > > > > > |_> arms > > > > > > |_>legs > > > > > > > > > > > > and so on until i hit the last element. > > > > > > [end quote] > > > > > > > > > > > > > > > > > > so I just provided that. > > > > > > > > > > > > > He said: > > > > > > > > > > > > > >>>>>> i need to create a set of nested groups, > > > > > > > and > > > > > > >>>>>> store each of the first elements of a par, so I can reference to > > > > > > >>>>>> them as to a parent of another group. > > > > > > > > > > > > > > > > > > I have no idea what that means :-) > > > > > > > > > > > > > > > > > > I *guess* that what Stan is actually looking for is something like a > > > > > > dictionary-based solution, not lists: > > > > > > > > > > > > {'head': {'neck': {'arms': {}, 'legs': {}}}} > > > > > > > > > > > > which gives: > > > > > > > > > > > > head encloses neck > > > > > > neck encloses arms and legs > > > > > > arms enclose nothing > > > > > > legs enclose nothing > > > > > > > > > > > > > > > > > > or: > > > > > > > > > > > > {'head': {'neck': {'arms': {'legs': {}}}}} > > > > > > > > > > > > which gives: > > > > > > > > > > > > head encloses neck > > > > > > neck encloses arms > > > > > > arms encloses legs > > > > > > legs enclose nothing > > > > > > > > > > > > > > > > > > but I can't really tell for sure. In this second case, using dicts, I > > > > > > might try something like this recursive solution: > > > > > > > > > > > > > > > > > > def print_nested_dict(adict, level=0): > > > > > > if adict == {}: > > > > > > return > > > > > > for key, subdict in sorted(adict.items()): > > > > > > if level != 0: > > > > > > spaces = ' '*4 > > > > > > indent = spaces*(level-1) + ' ' > > > > > > print (indent + '|_>'), # note comma > > > > > > if subdict == {}: > > > > > > print key > > > > > > else: > > > > > > print "%s:-" % key > > > > > > print_nested_dict(subdict, level+1) > > > > > > > > > > > > > > > > > > Given: > > > > > > > > > > > > d = {'head': {'neck': {'legs': {'toes': {}}, 'arms': {'thumbs': {}, > > > > > > 'fingers': {}}}}} > > > > > > > > > > > > we can see this output: > > > > > > > > > > > > py> print_nested_dict(d) > > > > > > head:- > > > > > > |_> neck:- > > > > > > |_> arms:- > > > > > > |_> fingers > > > > > > |_> thumbs > > > > > > |_> legs:- > > > > > > |_> toes > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > > > Steven From stascrash at gmail.com Wed Sep 11 10:57:21 2013 From: stascrash at gmail.com (stas poritskiy) Date: Wed, 11 Sep 2013 07:57:21 -0700 (PDT) Subject: Dealing with Lists In-Reply-To: <40438965-ec5f-409f-87af-4fb2290ec891@googlegroups.com> References: <33650fe9-802e-477d-a361-6d4bdeb28762@googlegroups.com> <522fd1ee$0$29988$c3e8da3$5496439d@news.astraweb.com> <522fdfec$0$29988$c3e8da3$5496439d@news.astraweb.com> <1ef6a37a-e888-4ecc-a82a-477e19490723@googlegroups.com> <40438965-ec5f-409f-87af-4fb2290ec891@googlegroups.com> Message-ID: <5f2d171b-acbb-4ba6-96d5-3a32a5fdda59@googlegroups.com> ok, while writing this, i figured out where those elements are located, so each element is always at the position 0, and to get deeper i have to follow something similar to this chopGrp = [[u'arms', [u'a', [u'super', [u'group', [u'type', [u'is', [u'here']]]]]]] print chopGrp[1][1][1][1][0] (this would get me "type" from the list) >>>type this is getting somewhere, now, i am confused what type of iteration loop i should make, where each element is being called by itself, so i could reference the previous element as its Parent. so if i make this manually as a pseudo code: chopGrp[0] #gets me "arms" print "Parent is: " + chopGrp[0] chopGrp[1][0] #gets me "a" print "Child is: " + chopGrp[1][0] and the next iteration should take the chopGrp[1][0] and make it a parent of chopGrp[1][1][0] any hints? On Wednesday, September 11, 2013 9:47:30 AM UTC-5, stas poritskiy wrote: > ok, so i think that getting the nested list is a little more for what i need, > > however, i could be wrong here, > > i got confused with Dave's suggestion. so, i got my lists broken up in a list of lists, but how would i access each of the elements? > > When i implement this solution my output list (the new one, after CHOPPING) prints like this: > > > > [u'arms', [u'a', [u'super', [u'group', [u'type', [u'is', [u'here']]]]]]] > > so i assume the "indexing" here would be similar to this: > > 0 1 > > 0 1 > > 0 1 > > 0 1 > > 0 1 > > 0 > > [u'arms', [u'a', [u'super', [u'group', [u'type', [u'is', [u'here']]]]]]] > > > > Basically speaking ( each generated list would be the len=2 ? > > > > so, in my understanding, if i need to call the parenet for my FIRST group(most fist created), > > i would go and call > > chopGrps[0] > > this would get me "arms" > > and if i need to get the second element, (which should be "a" > > i would call chopGrps[1] > > but instead, i get the REST of the lists stored there. > > > > so what position does "a" take in this nested list? > > and this same question would apply to the rest of the items > > > > Thanks guys! > > > > > > On Tuesday, September 10, 2013 10:52:20 PM UTC-5, stas poritskiy wrote: > > > Steven, > > > > > > i think you got on the right track with your proposal, > > > > > > although i am not going after the "visual" represenatation that you were able to create, rather a structural one, i think this might work for me, > > > > > > instead of printing, i could be using my commands to make elements (instances of API objects to create my groups inside the file) > > > > > > > > > > > > but one question i might have is : > > > > > > > > > > > > once i created first instance object which in my example is : > > > > > > groups = intance.add_group(str(name)) > > > > > > > > > > > > how would i temporary preserve this name as a reference for the next iteration for the subroups? > > > > > > > > > > > > On Tuesday, September 10, 2013 10:13:48 PM UTC-5, Steven D'Aprano wrote: > > > > > > > On Wed, 11 Sep 2013 02:24:44 +0000, Dave Angel wrote: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > On 10/9/2013 22:14, Steven D'Aprano wrote: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >> On Tue, 10 Sep 2013 14:08:45 -0700, stas poritskiy wrote: > > > > > > > > > > > > > > >> > > > > > > > > > > > > > > >>> Greetings to all! > > > > > > > > > > > > > > >>> > > > > > > > > > > > > > > >>> i ran into a little logic problem and trying to figure it out. > > > > > > > > > > > > > > >>> > > > > > > > > > > > > > > >>> my case is as follows: > > > > > > > > > > > > > > >>> > > > > > > > > > > > > > > >>> i have a list of items each item represents a Group i need to create a > > > > > > > > > > > > > > >>> set of nested groups, so, for example: > > > > > > > > > > > > > > >>> > > > > > > > > > > > > > > >>> myGroups = ["head", "neck", "arms", "legs"] > > > > > > > > > > > > > > >> > > > > > > > > > > > > > > >> > > > > > > > > > > > > > > >> What is the rule for grouping these items? Below, you suggest: > > > > > > > > > > > > > > >> > > > > > > > > > > > > > > >> head encloses neck > > > > > > > > > > > > > > >> neck encloses arms > > > > > > > > > > > > > > >> arms encloses legs > > > > > > > > > > > > > > >> > > > > > > > > > > > > > > >> which seems rather strange. But if it is *always* the case that each > > > > > > > > > > > > > > >> item encloses the next item: > > > > > > > > > > > > > > >> > > > > > > > > > > > > > > >> def print_nested_list(alist): > > > > > > > > > > > > > > >> spaces = ' '*4 > > > > > > > > > > > > > > >> for level, item in enumerate(alist): > > > > > > > > > > > > > > >> if level != 0: > > > > > > > > > > > > > > >> indent = spaces*(level-1) + ' ' > > > > > > > > > > > > > > >> print (indent + '|_>'), # note comma > > > > > > > > > > > > > > >> print item > > > > > > > > > > > > > > >> > > > > > > > > > > > > > > >> > > > > > > > > > > > > > > >> which gives us this: > > > > > > > > > > > > > > >> > > > > > > > > > > > > > > >> py> print_nested_list(['head', 'neck', 'arms', 'legs']) head > > > > > > > > > > > > > > >> |_> neck > > > > > > > > > > > > > > >> |_> arms > > > > > > > > > > > > > > >> |_> legs > > > > > > > > > > > > > > >> > > > > > > > > > > > > > > >> > > > > > > > > > > > > > > >> as requested. > > > > > > > > > > > > > > >> > > > > > > > > > > > > > > >> > > > > > > > > > > > > > > >> > > > > > > > > > > > > > > > Very nice. But what I want to know is how did you know that Stan (the > > > > > > > > > > > > > > > OP) wanted his printed output to be formatted that way? > > > > > > > > > > > > > > > > > > > > > > > > > > > > I don't. Stan's email is unclear. But he does show an example: > > > > > > > > > > > > > > > > > > > > > > > > > > > > [quote] > > > > > > > > > > > > > > so, for example: > > > > > > > > > > > > > > > > > > > > > > > > > > > > myGroups = ["head", "neck", "arms", "legs"] > > > > > > > > > > > > > > > > > > > > > > > > > > > > i need to get them to be represented like this: (if you can imaging a > > > > > > > > > > > > > > folder structure) > > > > > > > > > > > > > > > > > > > > > > > > > > > > head > > > > > > > > > > > > > > |_> neck > > > > > > > > > > > > > > |_> arms > > > > > > > > > > > > > > |_>legs > > > > > > > > > > > > > > > > > > > > > > > > > > > > and so on until i hit the last element. > > > > > > > > > > > > > > [end quote] > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > so I just provided that. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > He said: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >>>>>> i need to create a set of nested groups, > > > > > > > > > > > > > > > and > > > > > > > > > > > > > > >>>>>> store each of the first elements of a par, so I can reference to > > > > > > > > > > > > > > >>>>>> them as to a parent of another group. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > I have no idea what that means :-) > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > I *guess* that what Stan is actually looking for is something like a > > > > > > > > > > > > > > dictionary-based solution, not lists: > > > > > > > > > > > > > > > > > > > > > > > > > > > > {'head': {'neck': {'arms': {}, 'legs': {}}}} > > > > > > > > > > > > > > > > > > > > > > > > > > > > which gives: > > > > > > > > > > > > > > > > > > > > > > > > > > > > head encloses neck > > > > > > > > > > > > > > neck encloses arms and legs > > > > > > > > > > > > > > arms enclose nothing > > > > > > > > > > > > > > legs enclose nothing > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > or: > > > > > > > > > > > > > > > > > > > > > > > > > > > > {'head': {'neck': {'arms': {'legs': {}}}}} > > > > > > > > > > > > > > > > > > > > > > > > > > > > which gives: > > > > > > > > > > > > > > > > > > > > > > > > > > > > head encloses neck > > > > > > > > > > > > > > neck encloses arms > > > > > > > > > > > > > > arms encloses legs > > > > > > > > > > > > > > legs enclose nothing > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > but I can't really tell for sure. In this second case, using dicts, I > > > > > > > > > > > > > > might try something like this recursive solution: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > def print_nested_dict(adict, level=0): > > > > > > > > > > > > > > if adict == {}: > > > > > > > > > > > > > > return > > > > > > > > > > > > > > for key, subdict in sorted(adict.items()): > > > > > > > > > > > > > > if level != 0: > > > > > > > > > > > > > > spaces = ' '*4 > > > > > > > > > > > > > > indent = spaces*(level-1) + ' ' > > > > > > > > > > > > > > print (indent + '|_>'), # note comma > > > > > > > > > > > > > > if subdict == {}: > > > > > > > > > > > > > > print key > > > > > > > > > > > > > > else: > > > > > > > > > > > > > > print "%s:-" % key > > > > > > > > > > > > > > print_nested_dict(subdict, level+1) > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Given: > > > > > > > > > > > > > > > > > > > > > > > > > > > > d = {'head': {'neck': {'legs': {'toes': {}}, 'arms': {'thumbs': {}, > > > > > > > > > > > > > > 'fingers': {}}}}} > > > > > > > > > > > > > > > > > > > > > > > > > > > > we can see this output: > > > > > > > > > > > > > > > > > > > > > > > > > > > > py> print_nested_dict(d) > > > > > > > > > > > > > > head:- > > > > > > > > > > > > > > |_> neck:- > > > > > > > > > > > > > > |_> arms:- > > > > > > > > > > > > > > |_> fingers > > > > > > > > > > > > > > |_> thumbs > > > > > > > > > > > > > > |_> legs:- > > > > > > > > > > > > > > |_> toes > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > > > > > > > > > > > Steven From __peter__ at web.de Wed Sep 11 12:17:58 2013 From: __peter__ at web.de (Peter Otten) Date: Wed, 11 Sep 2013 18:17:58 +0200 Subject: Dealing with Lists References: <33650fe9-802e-477d-a361-6d4bdeb28762@googlegroups.com> <522fd1ee$0$29988$c3e8da3$5496439d@news.astraweb.com> <522fdfec$0$29988$c3e8da3$5496439d@news.astraweb.com> <1ef6a37a-e888-4ecc-a82a-477e19490723@googlegroups.com> <40438965-ec5f-409f-87af-4fb2290ec891@googlegroups.com> <5f2d171b-acbb-4ba6-96d5-3a32a5fdda59@googlegroups.com> Message-ID: stas poritskiy wrote: By now your post consists of over 1300 lines, most of them containing nothing but quoting marks. Please be courteous to your readers and avoid that. https://wiki.python.org/moin/GoogleGroupsPython may be helpful. > ok, while writing this, i figured out where those elements are located, > so each element is always at the position 0, and to get deeper i have to > follow something similar to this chopGrp = [[u'arms', [u'a', [u'super', > [u'group', [u'type', [u'is', [u'here']]]]]]] > > print chopGrp[1][1][1][1][0] (this would get me "type" from the list) >>>>type > > this is getting somewhere, now, i am confused what type of iteration loop > i should make, where each element is being called by itself, > > so i could reference the previous element as its Parent. > so if i make this manually as a pseudo code: > > chopGrp[0] #gets me "arms" > print "Parent is: " + chopGrp[0] > chopGrp[1][0] #gets me "a" > print "Child is: " + chopGrp[1][0] > > and the next iteration should take the > > chopGrp[1][0] and make it a parent of chopGrp[1][1][0] Again, be courteous and give actual self-contained runnable Python code. I doubt that anyone can make much of the above > any hints? My impression is that much of your confusion stems from using generic lists where items in different positions have a different meaning for different posters and it is difficult to keep track of what's what. I suggest you bite the bullet and go for a class-based approach. Then, when you talk about "children" or "parent" it is clear that you find them in the Node's attribute of the same name. Proceed to express your tasks in plain English as clearly as you can, and only then try to transform them into code. To get you started here's what a simple tree might look like: $ cat tree.py from __future__ import print_function from collections import OrderedDict as Children class Node: def __init__(self, name, parent=None): self.name = name self.parent = parent self.children = Children() if parent is not None: self.parent.children[name] = self def show(self, level=0): print(" " * level, self.name, sep="") for child in self.children.values(): child.show(level + 1) class Tree(Node): def __init__(self): Node.__init__(self, None) def ensure(self, path): """Add node with all intermediate nodes""" node = self for name in path: try: node = node.children[name] except KeyError: node = Node(name, node) return node def show(self, level=0): for child in self.children.values(): child.show() if __name__ == "__main__": data = """\ plant flower tulip plant flower lily animal mammal cat animal mammal zebra animal reptile snake animal reptile snake python animal reptile snake boa """ paths = [line.split() for line in data.splitlines()] tree = Tree() for path in paths: tree.ensure(path) tree.show() And here's the output of the demo: $ python tree.py plant flower tulip lily animal mammal cat zebra reptile snake python boa From gogobebe2 at gmail.com Wed Sep 11 00:49:52 2013 From: gogobebe2 at gmail.com (William Bryant) Date: Tue, 10 Sep 2013 21:49:52 -0700 (PDT) Subject: Help please, why doesn't it show the next input? Message-ID: Hey, I am very new to python, I am 13 years old. I want to be able to make a program the caculates the mean, meadian and mode. When i run the program, an input field pops up and says 'Does your list contain, a number or a string?' like I want it to, but when I type in something that is not one of valid field options: "String" or "string" or "STRING" or "s" or "S" or "str" or "Number" or "number" or "NUMBER" or "N" or "N" or "int" or "num", nothing happens, please tell me what I did wrong. Thanks :D Here is my code: #----- Variables that I am using, including the list. -----# #False means num #True means string num_or_string = "" amount_numbers = [] List = [] I = "Does your list contain, a number or a string?" #----- Functions that I am using. -----# input(I) def NOS(): if I == "String" or "string" or "STRING" or "s" or "S" or "str": pass elif I == "Number" or "number" or "NUMBER" or "N" or "N" or "int" or "num": pass else: global I I = "You did not enter a valid field, :P Sorry." input(I) From gordon at panix.com Wed Sep 11 01:11:23 2013 From: gordon at panix.com (John Gordon) Date: Wed, 11 Sep 2013 05:11:23 +0000 (UTC) Subject: Help please, why doesn't it show the next input? References: Message-ID: In William Bryant writes: > Hey, I am very new to python, I am 13 years old. I want to be able to make = > a program the caculates the mean, meadian and mode. When i run the program,= > an input field pops up and says 'Does your list contain, a number or a str= > ing?' like I want it to, but when I type in something that is not one of va= > lid field options: "String" or "string" or "STRING" or "s" or "S" or "str" = > or "Number" or "number" or "NUMBER" or "N" or "N" or "int" or "num", nothin= > g happens, please tell me what I did wrong. Thanks :D Here is my code: > #----- Variables that I am using, including the list. --= > ---# > #False means num > #True means string > num_or_string =3D "" > amount_numbers =3D [] > List =3D [] > I =3D "Does your list contain, a number or a string?" > #----- Functions that I am using. -= > ----# > input(I) > def NOS(): > if I =3D=3D "String" or "string" or "STRING" or "s" or "S" or "str": > pass > elif I =3D=3D "Number" or "number" or "NUMBER" or "N" or "N" or "int" o= > r "num": > pass > else: > global I > I =3D "You did not enter a valid field, :P Sorry." > input(I) First of all, you haven't given us your whole program. I know this because while you've defined the NOS function, it isn't actually called anywhere. You must have left that part out. Anyway, I think you're doing two things wrong: 1. You aren't capturing the user's input. The input() function returns the user's input, but you aren't assigning this to a variable; it's just being thrown away. You should call input() like this: user_input = input(I) (Also, it would probably be clearer to use a name like "prompt" instead of "I".) 2. You aren't using the compound "if" statement correctly. You can't do this (well, you CAN, but it won't do what you want): if a == 1 or 2 or 3: You should fully spell out each condition, like this: if a == 1 or a == 2 or a == 3: -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From gogobebe2 at gmail.com Wed Sep 11 01:39:01 2013 From: gogobebe2 at gmail.com (William Bryant) Date: Tue, 10 Sep 2013 22:39:01 -0700 (PDT) Subject: Help please, why doesn't it show the next input? In-Reply-To: References: Message-ID: <2dba1d63-16f0-412d-b650-0cdc27c3b57e@googlegroups.com> On Wednesday, September 11, 2013 5:11:23 PM UTC+12, John Gordon wrote: > In William Bryant writes: > > > > > Hey, I am very new to python, I am 13 years old. I want to be able to make = > > > a program the caculates the mean, meadian and mode. When i run the program,= > > > an input field pops up and says 'Does your list contain, a number or a str= > > > ing?' like I want it to, but when I type in something that is not one of va= > > > lid field options: "String" or "string" or "STRING" or "s" or "S" or "str" = > > > or "Number" or "number" or "NUMBER" or "N" or "N" or "int" or "num", nothin= > > > g happens, please tell me what I did wrong. Thanks :D Here is my code: > > > > > #----- Variables that I am using, including the list. --= > > > ---# > > > > > #False means num > > > #True means string > > > num_or_string =3D "" > > > amount_numbers =3D [] > > > List =3D [] > > > I =3D "Does your list contain, a number or a string?" > > > > > #----- Functions that I am using. -= > > > ----# > > > input(I) > > > > > def NOS(): > > > if I =3D=3D "String" or "string" or "STRING" or "s" or "S" or "str": > > > pass > > > elif I =3D=3D "Number" or "number" or "NUMBER" or "N" or "N" or "int" o= > > > r "num": > > > pass > > > else: > > > global I > > > I =3D "You did not enter a valid field, :P Sorry." > > > input(I) > > > > First of all, you haven't given us your whole program. I know this because > > while you've defined the NOS function, it isn't actually called anywhere. > > You must have left that part out. > > > > Anyway, I think you're doing two things wrong: > > > > 1. You aren't capturing the user's input. The input() function returns > > the user's input, but you aren't assigning this to a variable; it's just > > being thrown away. You should call input() like this: > > > > user_input = input(I) > > > > (Also, it would probably be clearer to use a name like "prompt" instead > > of "I".) > > > > 2. You aren't using the compound "if" statement correctly. You can't > > do this (well, you CAN, but it won't do what you want): > > > > if a == 1 or 2 or 3: > > > > You should fully spell out each condition, like this: > > > > if a == 1 or a == 2 or a == 3: > > > > -- > > John Gordon A is for Amy, who fell down the stairs > > gordon at panix.com B is for Basil, assaulted by bears > > -- Edward Gorey, "The Gashlycrumb Tinies" Thanks so much for putting your time into helping me!! It worked! Could you tell me if I did anything wrong this time? :) #----- Variables that I am using, including the list. -----# num_or_string = "" amount_numbers = [] List = [] prompt = "Does your list contain, a number or a string?" #----- Functions that I am using. -----# user_input1 = input(prompt) user_input1 def NOS(): if user_input1 == "String" or user_input1 == "string" or user_input1 == "STRING" or user_input1 == "s" or user_input1 == "S" or user_input1 == "str": print("a") elif user_input1 == "Number" or user_input1 == "number" or user_input1 == "NUMBER" or user_input1 == "N" or user_input1 == "N" or user_input1 == "int" or user_input1 == "num": print("a") else: global user_input2 global prompt prompt = "You did not enter a valid field, :P Sorry." user_input2 = input(prompt) user_input2 NOS2() def NOS2(): if user_input2 == "String" or user_input2 == "string" or user_input2 == "STRING" or user_input2 == "s" or user_input2 == "S" or user_input2 == "str": print("a") elif user_input2 == "Number" or user_input2 == "number" or user_input2 == "NUMBER" or user_input2 == "N" or user_input2 == "N" or user_input2 == "int" or user_input2 == "num": print("a") else: global user_input2 global prompt prompt = "You did not enter a valid field, :P Sorry." user_input2 = input(prompt) user_input2 NOS2() NOS() From jugurtha.hadjar at gmail.com Wed Sep 11 05:32:02 2013 From: jugurtha.hadjar at gmail.com (Jugurtha Hadjar) Date: Wed, 11 Sep 2013 10:32:02 +0100 Subject: Help please, why doesn't it show the next input? In-Reply-To: <2dba1d63-16f0-412d-b650-0cdc27c3b57e@googlegroups.com> References: <2dba1d63-16f0-412d-b650-0cdc27c3b57e@googlegroups.com> Message-ID: <52303892.9000305@gmail.com> Hello, William On 09/11/2013 06:39 AM, William Bryant wrote: > user_input1 = input(prompt) I take it you are using Python 3.x . If that's not the case, take a look at raw_input(). > def NOS(): > if user_input1 == "String" or user_input1 == "string" or user_input1 == "STRING" or user_input1 == "s" or user_input1 == "S" or user_input1 == "str": > print("a") What if you create a list containing these, and then you check if the user_input is contained in that list. But before that, get the lower-case of it so you don't deal with String sTring string, s, S, etc... Something like this You add this to the variables you are using section string_list = ['string', 's'] When you want to check the check if user_input.lower() in string_list: {your_code_here} > elif user_input1 == "Number" or user_input1 == "number" or user_input1 == "NUMBER" or user_input1 == "N" or user_input1 == "N" or user_input1 == "int" or user_input1 == "num": > print("a") Same goes with that But some questions: 1 - Why does the user have to specify that, why doesn't the program itself tell if it is a string or a number ? You just give it the data and it's up to him to tell. 2 - What is it you are trying to accomplish: Maybe there are shortcuts or better ways to do things. -- ~Jugurtha Hadjar, From davea at davea.name Wed Sep 11 07:50:53 2013 From: davea at davea.name (Dave Angel) Date: Wed, 11 Sep 2013 11:50:53 +0000 (UTC) Subject: Help please, why doesn't it show the next input? References: <2dba1d63-16f0-412d-b650-0cdc27c3b57e@googlegroups.com> Message-ID: On 11/9/2013 01:39, William Bryant wrote: > On Wednesday, September 11, 2013 5:11:23 PM UTC+12, John Gordon wrote: >> In William Bryant writes: >> >> >> >> > Hey, I am very new to python, I am 13 years old. I want to be able to make = >> >> > a program the caculates the mean, meadian and mode. When i run the program,= >> >> > an input field pops up and says 'Does your list contain, a number or a str= >> >> > ing?' like I want it to, but when I type in something that is not one of va= >> >> > lid field options: "String" or "string" or "STRING" or "s" or "S" or "str" = Thanks for quoting some context. However, since you're using buggy googlegroups, please either constrain your quoting to a couple of lines, or fix its display to NOT doublespace everything. See http://wiki.python.org/moin/GoogleGroupsPython > > Thanks so much for putting your time into helping me!! It worked! Could you tell me if I did anything wrong this time? :) > > #----- Variables that I am using, including the list. -----# > > num_or_string = "" > amount_numbers = [] > List = [] > prompt = "Does your list contain, a number or a string?" > > #----- Functions that I am using. -----# > user_input1 = input(prompt) > user_input1 This last line does nothing useful. You may be confused because in the debugger, a lone expression getes its value printed. But that's a debugger feature not a language one. If you want to see what got input, you'd want to use print() function. Looks like the second function is identical to the first. if I'm right, then just change the NOS2 into NOS1, and save lots of redundancy. > > def NOS(): > if user_input1 == "String" or user_input1 == "string" or user_input1 == "STRING" or user_input1 == "s" or user_input1 == "S" or user_input1 == "str": > print("a") > elif user_input1 == "Number" or user_input1 == "number" or user_input1 == "NUMBER" or user_input1 == "N" or user_input1 == "N" or user_input1 == "int" or user_input1 == "num": > print("a") > else: > global user_input2 > global prompt > prompt = "You did not enter a valid field, :P Sorry." > user_input2 = input(prompt) > user_input2 > NOS2() Here you're using the recursive call to NOS() to substitute for a loop. Recursion is very useful, but in this case, it hides what's really happening, and it prevents you from writing a conventional function with parameters and return value. I don't know what NOS is supposed to stand for, but it's generally useful if a function does a simply described single thing. In this case, it gets input from the user, and asks the user repeatedly till he/she gets it right. So the function should do its own input, and not expect the top-level code to already have asked once. Something like: SOMETHING = [ .... list of the valid inputs ] def query_user(prompt): while true: udata = input(prompt) if udata.lower() in SOMETHING return udata print("Invalid field, sorry") And now you call this function the same way you would have called input() function: user_input1 = query_user("Does your list contain, a number or a string?") > > NOS() -- DaveA From gogobebe2 at gmail.com Wed Sep 11 15:31:43 2013 From: gogobebe2 at gmail.com (William Bryant) Date: Wed, 11 Sep 2013 12:31:43 -0700 (PDT) Subject: Help please, why doesn't it show the next input? In-Reply-To: References: <2dba1d63-16f0-412d-b650-0cdc27c3b57e@googlegroups.com> Message-ID: @Dave Angel What is .lower() ? From davea at davea.name Wed Sep 11 16:32:17 2013 From: davea at davea.name (Dave Angel) Date: Wed, 11 Sep 2013 20:32:17 +0000 (UTC) Subject: Help please, why doesn't it show the next input? References: <2dba1d63-16f0-412d-b650-0cdc27c3b57e@googlegroups.com> Message-ID: On 11/9/2013 15:31, William Bryant wrote: > @Dave Angel > > What is .lower() ? It is a method on the str class. You could teach yourself. At the interpreter prompt, type >>>> help("test response".lower) Or on the web: http://docs.python.org/2/library/stdtypes.html#str.lower There are lots of other interesting methods in the str class, listed on that section of that page. -- DaveA From ramit.prasad at jpmorgan.com.dmarc.invalid Wed Sep 11 15:58:27 2013 From: ramit.prasad at jpmorgan.com.dmarc.invalid (Prasad, Ramit) Date: Wed, 11 Sep 2013 19:58:27 +0000 Subject: Help please, why doesn't it show the next input? In-Reply-To: References: <2dba1d63-16f0-412d-b650-0cdc27c3b57e@googlegroups.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF474186E6F29@SCACMX007.exchad.jpmchase.net> William Bryant wrote: > Sent: Wednesday, September 11, 2013 2:32 PM > To: python-list at python.org > Subject: Re: Help please, why doesn't it show the next input? > > @Dave Angel > > What is .lower() ? Thanks for bottom posting and trimming, but you should leave some content quoted for context. Otherwise people will not what you are referring to. You can find answers to questions like this in the API. http://docs.python.org/2/library/stdtypes.html#str.lower I would recommend taking time to get familiar with the Athena interpreter. It can also answer questions like this (but with less detail than the web API). You can use dir() to find the attributes on any object. help() will give you docstring for the attribute/class. >>> 'A'.lower() 'a' >>> help(''.lower) Help on built-in function lower: lower(...) S.lower() -> string Return a copy of the string S converted to lowercase. >>> help(dir) Help on built-in function dir in module __builtin__: dir(...) dir([object]) -> list of strings If called without an argument, return the names in the current scope. Else, return an alphabetized list of names comprising (some of) the attributes of the given object, and of attributes reachable from it. If the object supplies a method named __dir__, it will be used; otherwise the default dir() logic is used and returns: for a module object: the module's attributes. for a class object: its attributes, and recursively the attributes of its bases. for any other object: its attributes, its class's attributes, and recursively the attributes of its class's base classes. >>> dir('') ['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem_\ _', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__\ ', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclass\ hook__', '_formatter_field_name_split', '_formatter_parser', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expan\ dtabs', 'find', 'format', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lo\ wer', 'lstrip', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'starts\ with', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill'] If you want to see all the relevant information you can use help() on the class [e.g. help(str)]. I think help(class) will not show functions that start with _ unless they are python magic dunder functions (e.g. __str__). ~Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From tjreedy at udel.edu Wed Sep 11 17:14:51 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 11 Sep 2013 17:14:51 -0400 Subject: Help please, why doesn't it show the next input? In-Reply-To: References: <2dba1d63-16f0-412d-b650-0cdc27c3b57e@googlegroups.com> Message-ID: On 9/11/2013 3:31 PM, William Bryant wrote: > What is .lower() ? The Python docs have a pretty good index that includes 'lower() (str method)'. Learn to use it. If you know that .lower is a str method, >>> help(str.lower) at interactive prompt prints a page. Learn to use help(ob) also. -- Terry Jan Reedy From gogobebe2 at gmail.com Wed Sep 11 15:33:02 2013 From: gogobebe2 at gmail.com (William Bryant) Date: Wed, 11 Sep 2013 12:33:02 -0700 (PDT) Subject: Help please, why doesn't it show the next input? In-Reply-To: References: <2dba1d63-16f0-412d-b650-0cdc27c3b57e@googlegroups.com> Message-ID: @Jugurtha Hadjar What does user_input.lower() mean/do? From gordon at panix.com Wed Sep 11 15:46:52 2013 From: gordon at panix.com (John Gordon) Date: Wed, 11 Sep 2013 19:46:52 +0000 (UTC) Subject: Help please, why doesn't it show the next input? References: <2dba1d63-16f0-412d-b650-0cdc27c3b57e@googlegroups.com> Message-ID: In William Bryant writes: > @Jugurtha Hadjar > What does user_input.lower() mean/do? String objects have a number of built-in functions, lower() being one of them. It returns a copy of the string with all uppercase letters converted to lowercase. Example: >>> x = "Hello There" >>> y = x.lower() >>> print y hello there -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From jugurtha.hadjar at gmail.com Wed Sep 11 21:08:54 2013 From: jugurtha.hadjar at gmail.com (Jugurtha Hadjar) Date: Thu, 12 Sep 2013 02:08:54 +0100 Subject: Help please, why doesn't it show the next input? In-Reply-To: References: <2dba1d63-16f0-412d-b650-0cdc27c3b57e@googlegroups.com> Message-ID: <52311426.9010007@gmail.com> On 09/11/2013 08:33 PM, William Bryant wrote: > @Jugurtha Hadjar > What does user_input.lower() mean/do? > Hello, As did other people point out, it returns the lower case of a string. It's not user_input.lower(), it's any_string.lower() For example: Try this on your python prompt mystring = "ThIs Is ThE wAy SoMe StUpId PeOpLe WrItE i DoN't KnOw WhY!" mystring.lower() -- ~Jugurtha Hadjar, From jugurtha.hadjar at gmail.com Wed Sep 11 21:14:41 2013 From: jugurtha.hadjar at gmail.com (Jugurtha Hadjar) Date: Thu, 12 Sep 2013 02:14:41 +0100 Subject: Help please, why doesn't it show the next input? In-Reply-To: <52311426.9010007@gmail.com> References: <2dba1d63-16f0-412d-b650-0cdc27c3b57e@googlegroups.com> <52311426.9010007@gmail.com> Message-ID: <52311581.3050805@gmail.com> On 09/12/2013 02:08 AM, Jugurtha Hadjar wrote: > Try this on your python prompt > > mystring = "ThIs Is ThE wAy SoMe StUpId PeOpLe WrItE i DoN't KnOw WhY!" > mystring.lower() > This should return: "You shouldn't treat people of stupid, but I feel your pain", or let's be more realistic: "this is the way some stupid people write i don't know why!" -- ~Jugurtha Hadjar, From gogobebe2 at gmail.com Thu Sep 12 02:04:41 2013 From: gogobebe2 at gmail.com (William Bryant) Date: Wed, 11 Sep 2013 23:04:41 -0700 (PDT) Subject: Help please, why doesn't it show the next input? In-Reply-To: References: Message-ID: <75200616-79f5-4088-a967-d3a1381716f2@googlegroups.com> Thanks everyone for helping but I did listen to you :3 Sorry. This is my code, it works, I know it's not the best way to do it and it's the long way round but it is one of my first programs ever and I'm happy with it: '''#*************************************************************************''' #* Name: Mode-Median-Mean Calculator *# #* *# #* Purpose: To calculate the mode, median and mean of a list of numbers *# #* and the mode of a list of strings because that is what we are *# #* learning in math atm in school :P *# #* *# #* Author: William Bryant *# #* *# #* Created: 11/09/2013 *# #* *# #* Copyright: (c) William 2013 *# #* *# #* Licence: IDK :3 *# '''**************************************************************************''' #-----# ~~Import things I am using~~ #-----# # | # | # \/ import time import itertools #-----# ~~Variables that I am using, including the list.~~ #-----# # | # | # \/ num_or_string = None amount_numbers = [] List = [] prompt = "Does your list contain, a number or a string? \nEnter: " user_inputHMNn = None user_inputHMNs = None #-----# ~~Functions that I am using.~~ #-----# # | # | # \/ user_inputNOS = input(prompt) user_inputNOS time.sleep(1.5) def NOS(): if user_inputNOS == "String" or user_inputNOS == "string" or user_inputNOS == "STRING" or user_inputNOS == "s" or user_inputNOS == "S" or user_inputNOS == "str": HMNs() elif user_inputNOS == "Number" or user_inputNOS == "number" or user_inputNOS == "NUMBER" or user_inputNOS == "N" or user_inputNOS == "N" or user_inputNOS == "int" or user_inputNOS == "num": HMNn() else: global user_inputNOS2 global prompt prompt = "You did not enter a valid field, :P Sorry. \nEnter: " user_inputNOS2 = input(prompt) user_inputNOS2 time.sleep(1.5) NOS2() def NOS2(): if user_inputNOS2 == "String" or user_inputNOS2 == "string" or user_inputNOS2 == "STRING" or user_inputNOS2 == "s" or user_inputNOS2 == "S" or user_inputNOS2 == "str": HMNs() elif user_inputNOS2 == "Number" or user_inputNOS2 == "number" or user_inputNOS2 == "NUMBER" or user_inputNOS2 == "N" or user_inputNOS2 == "N" or user_inputNOS2 == "int" or user_inputNOS2 == "num": HMNn() else: global prompt prompt = "You did not enter a valid field, :P Sorry. \nEnter: " user_inputNOS2 time.sleep(1.5) NOS2() def HMNs(): global TheStr, user_inputHMNs, List_input user_inputHMNs = input("You picked string. This program cannot calculate the mean or median, but it can calculate the mode. :D How many strings are you using in your list? (Can not be a decimal number) \nEnter: ") user_inputHMNs time.sleep(1.5) TheStr = int(user_inputHMNs) for i in range(TheStr): List_input = input("Enter your strings. (One in each input field): ") List.append(List_input) print("Your list -> ", List) def HMNn(): global TheNum, user_inputHMNn, List_input user_inputHMNn = input("You picked number. :D How many numbers are you using in your list? (Can not be a decimal number) \nEnter: ") user_inputHMNn time.sleep(1.5) TheNum = int(user_inputHMNn) for i in range(TheNum): List_input = input("Enter your numbers. (One in each input field): ") List.append(List_input) print("Your list -> ", List) #-----# ~~The functions which need calling~~ #-----# # | # | # \/ NOS() Not done. I'll finish it today! :) Oh and thanks so much for helping, you guys are really nice :D Thanks a lot. From oscar.j.benjamin at gmail.com Thu Sep 12 05:39:33 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 12 Sep 2013 10:39:33 +0100 Subject: Help please, why doesn't it show the next input? In-Reply-To: <75200616-79f5-4088-a967-d3a1381716f2@googlegroups.com> References: <75200616-79f5-4088-a967-d3a1381716f2@googlegroups.com> Message-ID: On 12 September 2013 07:04, William Bryant wrote: > Thanks everyone for helping but I did listen to you :3 Sorry. This is my code, it works, I know it's not the best way to do it and it's the long way round but it is one of my first programs ever and I'm happy with it: Hi William, I'm glad you've solved your initial problem and I just wanted to make a couple of comments about how your program could be simplified or improved. The comments are below. > > '''#*************************************************************************''' > #* Name: Mode-Median-Mean Calculator *# > #* *# > #* Purpose: To calculate the mode, median and mean of a list of numbers *# > #* and the mode of a list of strings because that is what we are *# > #* learning in math atm in school :P *# > #* *# > #* Author: William Bryant *# > #* *# > #* Created: 11/09/2013 *# > #* *# > #* Copyright: (c) William 2013 *# > #* *# > #* Licence: IDK :3 *# > '''**************************************************************************''' > > > > > #-----# ~~Import things I am using~~ #-----# > > # | > # | > # \/ > > import time > import itertools > > > > #-----# ~~Variables that I am using, including the list.~~ #-----# > > # | > # | > # \/ > > num_or_string = None > amount_numbers = [] > List = [] > prompt = "Does your list contain, a number or a string? \nEnter: " > user_inputHMNn = None > user_inputHMNs = None Of the declarations above only List and prompt are needed. Actually though I wouldn't use either of those. List should really be a local variable inside the functions below. And it would be better to write prompt inline e.g.: answer = input("Does your list contain, a number or a string? \nEnter: ") That makes it easier to understand what's happening when you look at the code. So I would remove all of those variable declarations. In some other programming languages there are reasons to use declarations like those above but not in Python. > > #-----# ~~Functions that I am using.~~ #-----# > > # | > # | > # \/ > > user_inputNOS = input(prompt) > user_inputNOS > time.sleep(1.5) > > def NOS(): > if user_inputNOS == "String" or user_inputNOS == "string" or user_inputNOS == "STRING" or user_inputNOS == "s" or user_inputNOS == "S" or user_inputNOS == "str": > HMNs() > elif user_inputNOS == "Number" or user_inputNOS == "number" or user_inputNOS == "NUMBER" or user_inputNOS == "N" or user_inputNOS == "N" or user_inputNOS == "int" or user_inputNOS == "num": > HMNn() > else: > global user_inputNOS2 > global prompt > prompt = "You did not enter a valid field, :P Sorry. \nEnter: " > user_inputNOS2 = input(prompt) > user_inputNOS2 > time.sleep(1.5) > NOS2() > > def NOS2(): > if user_inputNOS2 == "String" or user_inputNOS2 == "string" or user_inputNOS2 == "STRING" or user_inputNOS2 == "s" or user_inputNOS2 == "S" or user_inputNOS2 == "str": > HMNs() > elif user_inputNOS2 == "Number" or user_inputNOS2 == "number" or user_inputNOS2 == "NUMBER" or user_inputNOS2 == "N" or user_inputNOS2 == "N" or user_inputNOS2 == "int" or user_inputNOS2 == "num": > HMNn() > else: > global prompt > prompt = "You did not enter a valid field, :P Sorry. \nEnter: " > user_inputNOS2 > time.sleep(1.5) > NOS2() The functions above are almost identical. The main difference is just that NOS2() doesn't call input() which I assume is accidental. So you could simplify this by only having one function NOS() and having it call itself rather than NOS2() at the end. Then it would look like: def NOS(): # code here ... NOS() However this is not a common way to use recursive function calls. What this really does is repeat something forever in a loop. The common way to do this is to use a for-loop or a while-loop. For example you can get the same effect with: while True: # Loops forever (until the break) answer = input("Does your list contain, a number or a string? \nEnter: ") answer = answer.lower() if answer in ("string", "str", "s"): HMNs() elif answer in ("number", "num", "n", "int"): HMNn() elif answer in ("quit", "q"): break # Exits the while loop else: print("You did not enter a valid field, :P Sorry.") time.sleep(1.5) You can put this code in a function or otherwise just move it below the functions it calls (i.e. HMNs and HMNn) since code doesn't need to be in functions in a Python script. > def HMNs(): > global TheStr, user_inputHMNs, List_input > user_inputHMNs = input("You picked string. This program cannot calculate the mean or median, but it can calculate the mode. :D How many strings are you using in your list? (Can not be a decimal number) \nEnter: ") > user_inputHMNs > time.sleep(1.5) > TheStr = int(user_inputHMNs) > for i in range(TheStr): > List_input = input("Enter your strings. (One in each input field): ") > List.append(List_input) > print("Your list -> ", List) > > def HMNn(): > global TheNum, user_inputHMNn, List_input > user_inputHMNn = input("You picked number. :D How many numbers are you using in your list? (Can not be a decimal number) \nEnter: ") > user_inputHMNn > time.sleep(1.5) > TheNum = int(user_inputHMNn) > for i in range(TheNum): > List_input = input("Enter your numbers. (One in each input field): ") > List.append(List_input) > print("Your list -> ", List) Using global variables in the functions above is confusing and error-prone. The simpler and safer way to do it is to use local variables in each function. To do this remove the global statements and assign an empty list to the name List inside the function like this: def HMNn(): List = [] user_inputHMNn = ... # more code Then you don't need to declare List at the top of your script. Oscar From gogobebe2 at gmail.com Fri Sep 13 18:12:09 2013 From: gogobebe2 at gmail.com (William Bryant) Date: Fri, 13 Sep 2013 15:12:09 -0700 (PDT) Subject: Help please, why doesn't it show the next input? In-Reply-To: References: <75200616-79f5-4088-a967-d3a1381716f2@googlegroups.com> Message-ID: <364bcdb3-fdd5-4774-b7d2-040e2ccb4cfd@googlegroups.com> On Thursday, September 12, 2013 9:39:33 PM UTC+12, Oscar Benjamin wrote: > On 12 September 2013 07:04, William Bryant wrote: > > > Thanks everyone for helping but I did listen to you :3 Sorry. This is my code, it works, I know it's not the best way to do it and it's the long way round but it is one of my first programs ever and I'm happy with it: > > > > Hi William, I'm glad you've solved your initial problem and I just > > wanted to make a couple of comments about how your program could be > > simplified or improved. The comments are below. > Hello, I've done this so far but why doesn't the mode function work? '''#*************************************************************************''' #* Name: Mode-Median-Mean Calculator *# #* *# #* Purpose: To calculate the mode, median and mean of a list of numbers *# #* and the mode of a list of strings because that is what we are *# #* learning in math atm in school :P *# #* *# #* Author: William Bryant *# #* *# #* Created: 11/09/2013 *# #* *# #* Copyright: (c) William 2013 *# #* *# #* Licence: IDK :3 *# '''**************************************************************************''' #-----# ~~Import things I am using~~ #-----# # | # | # \/ import time import itertools #-----# ~~Variables that I am using, including the list.~~ #-----# # | # | # \/ List = [] NumberOfXItems = [] Themode = [] #-----# ~~Functions that I am using.~~ #-----# # | # | # \/ def HMNs(): global TheStr, user_inputHMNs, List_input, List user_inputHMNs = input("You picked string. This program cannot calculate the mean or median, but it can calculate the mode. :D How many strings are you using in your list? (Can not be a decimal number) \nEnter: ") user_inputHMNs time.sleep(1.5) TheStr = int(user_inputHMNs) for i in range(TheStr): List_input = input("Enter your strings. (One in each input field): ") List.append(List_input) print("Your list -> ", List) if List.count == int(user_inputHMNs): break mode() def HMNn(): global TheNum, user_inputHMNn, List_input, List user_inputHMNn = input("You picked number. :D How many numbers are you using in your list? (Can not be a decimal number) \nEnter: ") user_inputHMNn time.sleep(1.5) TheNum = int(user_inputHMNn) for i in range(TheNum): List_input = input("Enter your numbers. (One in each input field): ") List_input = int(List_input) List.append(List_input) print("Your list -> ", List) if List.count == int(user_inputHMNn): break mode() def NOS(): while True: # Loops forever (until the break) answer = input("Does your list contain a number or a string? \nEnter: ") answer = answer.lower() if answer in ("string", "str", "s"): HMNs() break elif answer in ("number", "num", "n", "int"): HMNn() break elif answer in ("quit", "q"): break # Exits the while loop else: print("You did not enter a valid field, :P Sorry. \nEnter: ") time.sleep(1.5) def mode(): global NumberOfXItems, Themode for i in List: NumberOfXItems.append(i) NumberOfXItems.append(List.count(i)) Themode = max(NumberOfXItems) print(Themode) #-----# ~~The functions which need calling~~ #-----# # | # | # \/ NOS() From gordon at panix.com Fri Sep 13 18:41:15 2013 From: gordon at panix.com (John Gordon) Date: Fri, 13 Sep 2013 22:41:15 +0000 (UTC) Subject: Help please, why doesn't it show the next input? References: <75200616-79f5-4088-a967-d3a1381716f2@googlegroups.com> <364bcdb3-fdd5-4774-b7d2-040e2ccb4cfd@googlegroups.com> Message-ID: In <364bcdb3-fdd5-4774-b7d2-040e2ccb4cfd at googlegroups.com> William Bryant writes: > Hello, I've done this so far but why doesn't the mode function work? > def mode(): > global NumberOfXItems, Themode > for i in List: > NumberOfXItems.append(i) > NumberOfXItems.append(List.count(i)) > Themode = max(NumberOfXItems) > print(Themode) As far as I can see, you're appending each of the user's numbers onto NumberOfXItems, and you're also appending the number of times each number occurs. So, if the user had entered these numbers: 5 9 9 9 15 100 100 NumberOfXItems would end up looking like this: 5 1 9 3 9 3 9 3 15 1 100 2 100 2 The max is 100, but 9 is the most often-occuring number. Also, since NumberOfXItems mixes user input and the counts of that input, you risk getting a max that the user didn't even enter. For example if the user entered these numbers: 1 1 1 1 1 1 2 3 NumberOfXItems would end up looking like this: 1 6 1 6 1 6 1 6 1 6 1 6 2 1 3 1 The max is 6, which is a count, not user input. mode would be much better written like this: def mode(mylist): max_occurrences = 0 themode = None for i in mylist: thecount = mylist.count(i) if thecount > max_occurrences: max_occurrences = thecount themode = i print(themode) -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From python at mrabarnett.plus.com Fri Sep 13 18:48:49 2013 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 13 Sep 2013 23:48:49 +0100 Subject: Help please, why doesn't it show the next input? In-Reply-To: <364bcdb3-fdd5-4774-b7d2-040e2ccb4cfd@googlegroups.com> References: <75200616-79f5-4088-a967-d3a1381716f2@googlegroups.com> <364bcdb3-fdd5-4774-b7d2-040e2ccb4cfd@googlegroups.com> Message-ID: <52339651.5080400@mrabarnett.plus.com> On 13/09/2013 23:12, William Bryant wrote: > On Thursday, September 12, 2013 9:39:33 PM UTC+12, Oscar Benjamin wrote: >> On 12 September 2013 07:04, William Bryant wrote: >> >> > Thanks everyone for helping but I did listen to you :3 Sorry. This is my code, it works, I know it's not the best way to do it and it's the long way round but it is one of my first programs ever and I'm happy with it: >> >> >> >> Hi William, I'm glad you've solved your initial problem and I just >> >> wanted to make a couple of comments about how your program could be >> >> simplified or improved. The comments are below. >> > > Hello, I've done this so far but why doesn't the mode function work? > > '''#*************************************************************************''' > #* Name: Mode-Median-Mean Calculator *# > #* *# > #* Purpose: To calculate the mode, median and mean of a list of numbers *# > #* and the mode of a list of strings because that is what we are *# > #* learning in math atm in school :P *# > #* *# > #* Author: William Bryant *# > #* *# > #* Created: 11/09/2013 *# > #* *# > #* Copyright: (c) William 2013 *# > #* *# > #* Licence: IDK :3 *# > '''**************************************************************************''' > > > > > #-----# ~~Import things I am using~~ #-----# > > # | > # | > # \/ > > import time > import itertools > > > > #-----# ~~Variables that I am using, including the list.~~ #-----# > > # | > # | > # \/ > Global variables and no parameter passing: yuck! :-) > List = [] > NumberOfXItems = [] > Themode = [] > > #-----# ~~Functions that I am using.~~ #-----# > > # | > # | > # \/ > Your function names aren't meaningful. > def HMNs(): > global TheStr, user_inputHMNs, List_input, List > user_inputHMNs = input("You picked string. This program cannot calculate the mean or median, but it can calculate the mode. :D How many strings are you using in your list? (Can not be a decimal number) \nEnter: ") This line doesn't do anything: > user_inputHMNs > time.sleep(1.5) This variable is an integer, yet it's called 'TheStr'. > TheStr = int(user_inputHMNs) > for i in range(TheStr): > List_input = input("Enter your strings. (One in each input field): ") > List.append(List_input) > print("Your list -> ", List) Here you're comparing the list's .count method with an integer. It'll never be true! > if List.count == int(user_inputHMNs): > break > mode() > > def HMNn(): > global TheNum, user_inputHMNn, List_input, List > user_inputHMNn = input("You picked number. :D How many numbers are you using in your list? (Can not be a decimal number) \nEnter: ") > user_inputHMNn > time.sleep(1.5) > TheNum = int(user_inputHMNn) > for i in range(TheNum): > List_input = input("Enter your numbers. (One in each input field): ") > List_input = int(List_input) > List.append(List_input) > print("Your list -> ", List) The same bug as above: > if List.count == int(user_inputHMNn): > break > mode() > def NOS(): > while True: # Loops forever (until the break) > answer = input("Does your list contain a number or a string? \nEnter: ") > answer = answer.lower() > if answer in ("string", "str", "s"): > HMNs() > break > elif answer in ("number", "num", "n", "int"): > HMNn() > break > elif answer in ("quit", "q"): > break # Exits the while loop > else: > print("You did not enter a valid field, :P Sorry. \nEnter: ") > time.sleep(1.5) > > def mode(): > global NumberOfXItems, Themode > for i in List: Here you're appending an item and then the number of times that the item occurs: > NumberOfXItems.append(i) > NumberOfXItems.append(List.count(i)) Here you're getting the maximum entry, be it an item or the number of times an item occurs (see above). Have a look at the Counter class from the collections module: > Themode = max(NumberOfXItems) > print(Themode) > > > > #-----# ~~The functions which need calling~~ #-----# > > # | > # | > # \/ > > NOS() > From gogobebe2 at gmail.com Fri Sep 13 19:34:04 2013 From: gogobebe2 at gmail.com (William Bryant) Date: Fri, 13 Sep 2013 16:34:04 -0700 (PDT) Subject: Help please, why doesn't it show the next input? In-Reply-To: References: <75200616-79f5-4088-a967-d3a1381716f2@googlegroups.com> <364bcdb3-fdd5-4774-b7d2-040e2ccb4cfd@googlegroups.com> Message-ID: <0b2215c0-c496-4df8-a5c1-27ce3632365c@googlegroups.com> Thanks for the contructive critisism - :D I'll try fix it up! From info at egenix.com Wed Sep 11 04:14:05 2013 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Wed, 11 Sep 2013 10:14:05 +0200 Subject: ANN: eGenix PyRun - One file Python Runtime 1.3.0 Message-ID: <5230264D.1000008@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix PyRun - One file Python Runtime Version 1.3.0 An easy-to-use single file relocatable Python run-time - available for Linux, Mac OS X and Unix platforms, with support for Python 2.5, 2.6 and 2.7 This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-PyRun-1.3.0-GA.html ________________________________________________________________________ INTRODUCTION Our new eGenix PyRun combines a Python interpreter with an almost complete Python standard library into a single easy-to-use executable, that does not require a system wide installation and is fully relocatable. eGenix PyRun's executable only needs 11MB, but still supports most Python application and scripts - and it can be further compressed to just 3-4MB using upx. Compared to a regular Python installation of typically 100MB on disk, this makes eGenix PyRun ideal for applications and scripts that need to be distributed to many target machines, client installations or customers. It makes "installing" Python on a Unix based system as simple as copying a single file. We have been using the product internally in our mxODBC Connect Server since 2008 with great success and have now extracted it into a stand-alone open-source product. We provide both the source archive to build your own eGenix PyRun, as well as pre-compiled binaries for Linux, FreeBSD and Mac OS X, as 32- and 64-bit versions. The binaries can be downloaded manually, or you can let our automatic install script install-pyrun take care of the installation: ./install-pyrun dir and you're done. Please see the product page for more details: http://www.egenix.com/products/python/PyRun/ ________________________________________________________________________ NEWS This is a new minor release of eGenix PyRun, which comes with updates to the latest Python releases and includes a number of compatibility enhancements. New Features ------------ * Upgraded eGenix PyRun to work with and use Python 2.7.5 per default. * Upgraded eGenix PyRun to use Python 2.6.8 as default Python 2.6 version. * PyRun will now create a symlink from "pyrunX.X" to "pythonX.X" and "pyrunX.X" to "python" in the bin/ dir to enhance compatibility with scripts and applications that hardwire the name of the Python interpreter to "python". Other Changes ------------- * Removed the compiler package from being compiled into PyRun. If needed, it can be installed separately. Note that the compiler package needs the parser module which is not compiled into PyRun either, but is still available as extension module. * Removed the Tkinter Python module from being compiled into PyRun. If needed, it can be installed separately. Note that the Tkinter module needs the _tkinter C module, which is not compiled into PyRun either, but is still available as extension module. * Fixed sys.argv when using interactive mode to default to ['']. * All eGenix PyRun distribution packages are now GPG signed with our release key and come with MD5 and SHA1 hashes to check for download corruption. install-pyrun Quick Installation Enhancements --------------------------------------------- Since version 1.1.0, eGenix PyRun includes a shell script called install-pyrun, which greatly simplifies installation of eGenix PyRun. It works much like the virtualenv shell script used for creating new virtual environments (except that there's nothing virtual about PyRun environments). https://downloads.egenix.com/python/install-pyrun With the script, an eGenix PyRun installation is as simple as running: ./install-pyrun targetdir We have enhanced this script somewhat since the last release: * install-pyrun now defaults to always installing the most recent setuptools and pip versions from PyPI. * install-pyrun now installs setuptools instead of distribute, after the two projects got merged and continued under the older name. * Added new option --pyrun-executable to define an alternative name for the executable, which is then also used when installing setuptools and pip, e.g. "python" for even better compatibility with standard Python. * install-run will now prefer curl over wget when downloading packages from PyPI. * install-pyrun local distribution options will now also work with relative paths. * install-pyrun now defaults to installing setuptools 1.1.1 and pip 1.4.1 when looking for local downloads of these tools. * The short options in install-pyrun now also have corresponding long option names. Other Changes ------------- * Fixed SyntaxWarning in pyrunX.X: name 'pyrun_script' is assigned to before global declaration global pyrun_script Presentation at EuroPython 2012 ------------------------------- Marc-Andr? Lemburg, CEO of eGenix, gave a presentation about eGenix PyRun at EuroPython 2012 last year. The talk video as well as the slides are available on our website: http://www.egenix.com/library/presentations/EuroPython2012-eGenix-PyRun/ ________________________________________________________________________ LICENSE eGenix PyRun is distributed under the eGenix.com Public License 1.1.0 which is an Open Source license similar to the Python license. You can use eGenix PyRun in both commercial and non-commercial settings without fee or charge. Please see our license page for more details: http://www.egenix.com/products/python/PyRun/license.html The package comes with full source code. ________________________________________________________________________ DOWNLOADS The download archives and instructions for installing eGenix PyRun can be found at: http://www.egenix.com/products/python/PyRun/ As always, we are providing pre-built binaries for all common platforms: Windows 32/64-bit, Linux 32/64-bit, FreeBSD 32/64-bit, Mac OS X 32/64-bit. Source code archives are available for installation on other platforms, such as Solaris, AIX, HP-UX, etc. _______________________________________________________________________ SUPPORT Commercial support for this product is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. ________________________________________________________________________ MORE INFORMATION For more information about eGenix PyRun, licensing and download instructions, please visit our web-site: http://www.egenix.com/products/python/PyRun/ About Python (http://www.python.org/): Python is an object-oriented Open Source programming language which runs on all modern platforms. By integrating ease-of-use, clarity in coding, enterprise application connectivity and rapid application design, Python establishes an ideal programming platform for today's IT challenges. About eGenix (http://www.egenix.com/): eGenix is a software project, consulting and product company specializing in expert project services and professional quality products for companies, Python users and developers. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Sep 11 2013) >>> Python Projects, Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope/Plone.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2013-09-04: Released eGenix pyOpenSSL 0.13.2 ... http://egenix.com/go48 2013-09-20: PyCon UK 2013, Coventry, UK ... 9 days to go 2013-09-28: PyDDF Sprint ... 17 days to go eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From bennettk9999 at gmail.com Wed Sep 11 06:45:08 2013 From: bennettk9999 at gmail.com (Kenroy Bennett) Date: Wed, 11 Sep 2013 03:45:08 -0700 (PDT) Subject: Telnet to remote system and format output via web page Message-ID: <8ac501c2-8fbc-4b6c-9e71-49c811f8fb5e@googlegroups.com> Hi I would like to create a web app using flask or cgi library along with telnetlib to telnet to specific servers and execute commands and retrieve the output. The output will then be formatted and outputted to a webpage . . Is this the best way of getting info from a remote system to be output to a web page? Is flask over kill for project like this ? Thanks, Kenroy From jugurtha.hadjar at gmail.com Wed Sep 11 08:45:58 2013 From: jugurtha.hadjar at gmail.com (Jugurtha Hadjar) Date: Wed, 11 Sep 2013 13:45:58 +0100 Subject: Telnet to remote system and format output via web page In-Reply-To: <8ac501c2-8fbc-4b6c-9e71-49c811f8fb5e@googlegroups.com> References: <8ac501c2-8fbc-4b6c-9e71-49c811f8fb5e@googlegroups.com> Message-ID: <52306606.7090801@gmail.com> On 09/11/2013 11:45 AM, Kenroy Bennett wrote: > Hi > > > I would like to create a web app using flask or cgi library along with telnetlib to telnet to specific servers and execute commands and retrieve the output. > The output will then be formatted and outputted to a webpage . > Is security an issue ? How sensitive is the information you are querying ? Must it be Telnet ? -- ~Jugurtha Hadjar, From rodrick.brown at gmail.com Wed Sep 11 10:13:46 2013 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Wed, 11 Sep 2013 10:13:46 -0400 Subject: Telnet to remote system and format output via web page In-Reply-To: <52306606.7090801@gmail.com> References: <8ac501c2-8fbc-4b6c-9e71-49c811f8fb5e@googlegroups.com> <52306606.7090801@gmail.com> Message-ID: <-7222838418607307603@unknownmsgid> I would use something like fabric to automatically login to hosts via ssh then parse the data myself to generate static HTML pages in a document root. Having a web app execute remote commands on a server is so wrong in many ways. Sent from my iPhone On Sep 11, 2013, at 8:56 AM, Jugurtha Hadjar wrote: > On 09/11/2013 11:45 AM, Kenroy Bennett wrote: >> Hi >> >> >> I would like to create a web app using flask or cgi library along with telnetlib to telnet to specific servers and execute commands and retrieve the output. >> The output will then be formatted and outputted to a webpage . > > > Is security an issue ? How sensitive is the information you are querying ? Must it be Telnet ? > > > -- > ~Jugurtha Hadjar, > -- > https://mail.python.org/mailman/listinfo/python-list From jeanmichel at sequans.com Fri Sep 13 08:31:15 2013 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 13 Sep 2013 14:31:15 +0200 (CEST) Subject: Telnet to remote system and format output via web page In-Reply-To: <-7222838418607307603@unknownmsgid> Message-ID: <348363986.56298340.1379075475818.JavaMail.root@sequans.com> ----- Original Message ----- > I would use something like fabric to automatically login to hosts via > ssh then parse the data myself to generate static HTML pages in a > document root. > > Having a web app execute remote commands on a server is so wrong in > many ways. Such as ? JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From rosuav at gmail.com Fri Sep 13 08:55:52 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 13 Sep 2013 22:55:52 +1000 Subject: Telnet to remote system and format output via web page In-Reply-To: <348363986.56298340.1379075475818.JavaMail.root@sequans.com> References: <-7222838418607307603@unknownmsgid> <348363986.56298340.1379075475818.JavaMail.root@sequans.com> Message-ID: On Fri, Sep 13, 2013 at 10:31 PM, Jean-Michel Pichavant wrote: > ----- Original Message ----- >> I would use something like fabric to automatically login to hosts via >> ssh then parse the data myself to generate static HTML pages in a >> document root. >> >> Having a web app execute remote commands on a server is so wrong in >> many ways. > > Such as ? It depends exactly _how_ it's able to execute remote commands. If it can telnet in as a fairly-privileged user and transmit arbitrary strings to be executed, then any compromise of the web server becomes a complete takedown of the back-end server. You're basically circumventing the protection that most web servers employ, that of running in a highly permissions-restricted user. On the other hand, if the "execute remote commands" part is done by connecting to a shell that executes its own choice of command safely, then you're not forfeiting anything. Suppose you make this the login shell for the user foo at some-computer: #!/bin/sh head -4 /proc/meminfo You can then telnet to that user to find out how much RAM that computer has free. It's telnet, it's executing a command on the remote server... but it's safe. (For something like this, I'd be inclined to run a specific "memory usage daemon" that takes connections on some higher port, rather than having it look like a shell, but this is a viable demo.) I've done things like this before, though using SSH rather than TELNET. ChrisA From jeanmichel at sequans.com Wed Sep 11 08:51:41 2013 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 11 Sep 2013 14:51:41 +0200 (CEST) Subject: Telnet to remote system and format output via web page In-Reply-To: <8ac501c2-8fbc-4b6c-9e71-49c811f8fb5e@googlegroups.com> Message-ID: <1658370978.54343700.1378903900991.JavaMail.root@sequans.com> ----- Original Message ----- > Hi > > > I would like to create a web app using flask or cgi library along > with telnetlib to telnet to specific servers and execute commands > and retrieve the output. > The output will then be formatted and outputted to a webpage . > > . Is this the best way of getting info from a remote system to be > output to a web page? > > Is flask over kill for project like this ? > > Thanks, > Kenroy > -- > https://mail.python.org/mailman/listinfo/python-list I never used Flask, but most of python web framework provide an easy/quick way of setting up a web application server. So I'd say Flask is just fine. What concerns me is the telnet protocol you plan to use for remote execution. Do you have any other options ? are you trying to execute on a remote unix like system ? Anyway if you must stick with telnet, I don't see anything wrong in your plan, Flask + telnetlib should do the trick. JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From chandan_psr at yahoo.co.in Wed Sep 11 08:50:30 2013 From: chandan_psr at yahoo.co.in (chandan kumar) Date: Wed, 11 Sep 2013 20:50:30 +0800 (SGT) Subject: global variable across modules Message-ID: <1378903830.83908.YahooMailBasic@web190503.mail.sg3.yahoo.com> Hi , I'm trying to understand using global variable across different modules.Here is what i have tried so far without much success.Please ignore any indentation issue? in the below code. Filename:Test1.py Debug_Value = " " import Test2 def globalValmethod(): ? ? global Debug_Value ? ? Debug_Value =10 ? ? Test2.globalValTest() globalValmethod() -----Execute the method Filename:Test2.py import Test1 from Test1 import * def globalValTest() ? ? print "Golabal Value" Debug_Value ? ? In Test2.py file I wanted to print the global value ,Debug_Value as 10.I'm not getting expected result.Please can any one point where exactly i'm doing wrong. Similarly , how can i use global variable inside a class and use the same value of global variable in different class?Is that possible?if Yes please give me some pointers on implementing. Best Regards, Chandan From rosuav at gmail.com Wed Sep 11 09:15:23 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 11 Sep 2013 23:15:23 +1000 Subject: global variable across modules In-Reply-To: <1378903830.83908.YahooMailBasic@web190503.mail.sg3.yahoo.com> References: <1378903830.83908.YahooMailBasic@web190503.mail.sg3.yahoo.com> Message-ID: On Wed, Sep 11, 2013 at 10:50 PM, chandan kumar wrote: > In Test2.py file I wanted to print the global value ,Debug_Value as 10.I'm not getting expected result.Please can any one point where exactly i'm doing wrong. > > Similarly , how can i use global variable inside a class and use the same value of global variable in different class?Is that possible?if Yes please give me some pointers on implementing. Python simply doesn't have that kind of global. What you have is module-level "variables" [1] which you can then import. But importing is just another form of assignment: # Test1.py Debug_Value = " " # Test2.py from Test1 import * # is exactly equivalent to Debug_Value = " " It simply sets that in Test2's namespace. There's no linkage across. (By the way, I strongly recommend NOT having the circular import that you have here. It'll make a mess of you sooner or later; you actually, due to the way Python loads things, have two copies of one of your modules in memory.) When you then reassign to Debug_Value inside Test1, you disconnect it from its previous value and connect it to a new one, and the assignment in the other module isn't affected. Here's a much simpler approach: # library.py foo = 0 def bar(): global foo foo += 1 # application.py import library library.bar() print(library.foo) This has a simple linear invocation sequence: you invoke the application from the command line, and it calls on its library. No confusion, no mess; and you can reference the library's globals by qualified name. Everything's clear and everything works. ChrisA [1] They're not really variables, they're name bindings. But close enough for this discussion. From johnhpote at o2.co.uk Wed Sep 11 17:49:09 2013 From: johnhpote at o2.co.uk (John Pote) Date: Wed, 11 Sep 2013 22:49:09 +0100 Subject: global variable across modules In-Reply-To: References: <1378903830.83908.YahooMailBasic@web190503.mail.sg3.yahoo.com> Message-ID: <9B9863FC-086A-4A0B-87BF-8F4AD070C90E@o2.co.uk> Chris, Interesting. > > # Test1.py > Debug_Value = " " > > # Test2.py > from Test1 import * > # is exactly equivalent to > Debug_Value = " " > I take it then that assigning to Debug_Value in Test2.py will not change the value of Debug_Value in Test1.py. That being the case it would be wrong to assume that the following are identical import sys and from sys import * (the latter being a convenience to avoid having to write sys. before every variable). Thus assigning to sys.stdout would change the standard out destination in every module importing sys whereas from sys import * stdout = foo.dst would only change stdout in the current module and sys.stdout would remain unchanged. Is my understanding here correct? As to global usage I do find it useful to have a file called something like 'preferences.py' and put in there constants to be used throughout the application. But I use these strictly read only. It is good in that system wide constants are defined in one place only. Also if the constants are put inside a class, possibly with getter methods, instantiated as a singleton then initially the values can be typed directly into the preferences file. Later the constructor could be changed to read the constants from an initialisation file of your own format (e.g. .ini or JSON). Thus users without python experience might find it easier to change them without having to look at any python code. On the other hand I appreciate simple constant assignments should be easy enough to change without needing to know any Python. Also remember that accessing any form of global that is shared between multiple threads is a recipe for disaster unless appropriate locks are used. A significant advantage of not using globals (except for system wide constants) is that is makes testing of individual modules easier. The less coupling there is between modules the easier it is to understand and test. Regards all, John -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at davea.name Wed Sep 11 18:15:16 2013 From: davea at davea.name (Dave Angel) Date: Wed, 11 Sep 2013 22:15:16 +0000 (UTC) Subject: global variable across modules References: <1378903830.83908.YahooMailBasic@web190503.mail.sg3.yahoo.com> <9B9863FC-086A-4A0B-87BF-8F4AD070C90E@o2.co.uk> Message-ID: On 11/9/2013 17:49, John Pote wrote: > Chris, > Interesting. >> >> # Test1.py >> Debug_Value = " " >> >> # Test2.py >> from Test1 import * >> # is exactly equivalent to >> Debug_Value = " " >> > I take it then that assigning to Debug_Value in Test2.py will not change the value of Debug_Value in Test1.py. That's correct. But it would be clearer to say that binding a new object to Debug_Value in Test2.py after Test1.py has already done its import does not change the binding that Test1.py has for Debug_Value. Note that if the object was mutable (which string is not), then it would be possible to change the object. In that case, both names would refer to the new value of the object. > > That being the case it would be wrong to assume that the following are identical > > import sys > > and > > from sys import * > > (the latter being a convenience to avoid having to write sys. before every variable). Right, they're not even close. > > Thus assigning to sys.stdout would change the standard out destination in every module importing sys whereas > > from sys import * > stdout = foo.dst > > would only change stdout in the current module and sys.stdout would remain unchanged. > > Is my understanding here correct? Yes. But notice that when you do print() in any module, it indirectly refers to sys.stdout, even if you have changed your own module's stdout. > > Chris,
Interesting. 

# Test1.py
Debug_Value = " "

# Test2.py
from Test1 import *
# is exactly equivalent to
Debug_Value = " "

I take it then that assigning to Debug_Value in Test2.py will not change the value of Debug_Value in Test1.py.

That being the case it would be wrong to assume that the following are identical

import sys

and

from sys import *

(the latter being a convenience  to avoid having to write sys. before every variable).

Thus assigning to sys.stdout would change the standard out destination in every module importing sys whereas

from sys import *
stdout = foo.dst

would only change stdout in the current module and sys.stdout would remain unchanged.

Is my understanding here correct?

As to global usage I do find it useful to have a file called something like 'preferences.py' and put in there constants to be used throughout the application. But I use these strictly read only. It is good in that system wide constants are defined in one place only. Also if the constants are put inside a class, possibly with getter methods, instantiated as a singleton then initially the values can be typed directly into the preferences file. Later the constructor could be changed to read the constants from an initialisation file of your own format (e.g. .ini or JSON). Thus users without python experience might find it easier to change them without having to look at any python code. On the other hand I appreciate simple constant assignments should be easy enough to change without needing to know any Python.

Also remember that accessing any form of global that is shared between multiple threads is a recipe for disaster unless appropriate locks are used. A significant advantage of not using globals (except for system wide constants) is that is makes testing of individual modules easier. The less coupling there is between modules the easier it is to understand and test.

Regards all,
John
> > Try fixing your email program to use text, not html. This time it's just wasted space in each copy of the message (where space is money). But next time it might lead to indentation problems and other miscommunication. -- DaveA From johnhpote at o2.co.uk Wed Sep 11 20:10:07 2013 From: johnhpote at o2.co.uk (John Pote) Date: Thu, 12 Sep 2013 01:10:07 +0100 Subject: global variable across modules In-Reply-To: <9B9863FC-086A-4A0B-87BF-8F4AD070C90E@o2.co.uk> References: <1378903830.83908.YahooMailBasic@web190503.mail.sg3.yahoo.com> <9B9863FC-086A-4A0B-87BF-8F4AD070C90E@o2.co.uk> Message-ID: <19062112-8817-4E2B-99D8-AC2BE699CC91@o2.co.uk> Sorry about the html - did not realise. Thanks for your comments. John On 11 Sep 2013, at 22:49, John Pote wrote: > Chris, > Interesting. >> >> # Test1.py >> Debug_Value = " " >> >> # Test2.py >> from Test1 import * >> # is exactly equivalent to >> Debug_Value = " " >> > I take it then that assigning to Debug_Value in Test2.py will not change the value of Debug_Value in Test1.py. > > That being the case it would be wrong to assume that the following are identical > > import sys > > and > > from sys import * > > (the latter being a convenience to avoid having to write sys. before every variable). > > Thus assigning to sys.stdout would change the standard out destination in every module importing sys whereas > > from sys import * > stdout = foo.dst > > would only change stdout in the current module and sys.stdout would remain unchanged. > > Is my understanding here correct? > > As to global usage I do find it useful to have a file called something like 'preferences.py' and put in there constants to be used throughout the application. But I use these strictly read only. It is good in that system wide constants are defined in one place only. Also if the constants are put inside a class, possibly with getter methods, instantiated as a singleton then initially the values can be typed directly into the preferences file. Later the constructor could be changed to read the constants from an initialisation file of your own format (e.g. .ini or JSON). Thus users without python experience might find it easier to change them without having to look at any python code. On the other hand I appreciate simple constant assignments should be easy enough to change without needing to know any Python. > > Also remember that accessing any form of global that is shared between multiple threads is a recipe for disaster unless appropriate locks are used. A significant advantage of not using globals (except for system wide constants) is that is makes testing of individual modules easier. The less coupling there is between modules the easier it is to understand and test. > > Regards all, > John > -- > https://mail.python.org/mailman/listinfo/python-list From davea at davea.name Wed Sep 11 16:02:32 2013 From: davea at davea.name (Dave Angel) Date: Wed, 11 Sep 2013 20:02:32 +0000 (UTC) Subject: global variable across modules References: <1378903830.83908.YahooMailBasic@web190503.mail.sg3.yahoo.com> Message-ID: On 11/9/2013 08:50, chandan kumar wrote: > Hi , > > I'm trying to understand using global variable across different modules. Python doesn't have such a thing, unless you consider builtins. > Here is what i have tried so far without much success.Please ignore any > indentation issue? in the below code. > Which one is the script, and which one an imported module? You have bugs ether wayl, but different ones. I have to assume something, so I'll assume Test2.py is your script. > Filename:Test1.py > > Debug_Value = " " > > import Test2 Nasty business. Any time you have recursive imports, you can expect trouble. But importing the script is doubly bad. You'll be importing a second copy of the script, pretending it's a module, and you'll be RUNNING it before this Test1 module. Maybe that doesn't matter, since the script does nothing useful. But once you fix the other problems, this one will be a big problem. > > def globalValmethod(): > ? ? global Debug_Value > ? ? Debug_Value =10 > ? ? Test2.globalValTest() > > globalValmethod() -----Execute the method > > Filename:Test2.py > > import Test1 > from Test1 import * Bad practice. I wish the above syntax were not in the language. > > def globalValTest() > ? ? print "Golabal Value" Debug_Value You omitted any top-level code, so this function won't be called anyway. > ? ? > In Test2.py file I wanted to print the global value ,Debug_Value as 10.I'm not getting expected result.Please can any one point where exactly i'm doing wrong. After you fix the above, you'll still have the problem that you apparently don't understand that these "variables" are names referring to objects. If you have two names bound to the same object, and you rebind one of them (inside globalValmethod()), the other remains bound to the original object. After you rename your files so I can tell which one is intended as the script, and which as the module, then clean up the other problems, and remove one of the imports. Then if you're still confused, ask again. > > Similarly , how can i use global variable inside a class and use the same value of global variable in different class?Is that possible?if Yes please give me some pointers on implementing. There are no global variables inside a class. There are class attributes which are sort-of global, and it's legal to use the global statement inside a method, as with any other function. But the main question is probably, why are you so hung up on globals? If it's changeable, it usually should NOT be global. Good uses for globals are things like math.pi or command-line options. The first is always the same, and the second is initialized before anyone will use it, and never changed afterwards. incidentally, class names, module names, and top-level function names are also global, and these are normally not changeable. -- DaveA From ndbecker2 at gmail.com Wed Sep 11 09:03:49 2013 From: ndbecker2 at gmail.com (Neal Becker) Date: Wed, 11 Sep 2013 09:03:49 -0400 Subject: why syntax change in lambda Message-ID: In py2.7 this was accepted, but not in py3.3. Is this intentional? It seems to violate the 'principle' that extraneous parentheses are usually allowed/ignored In [1]: p = lambda x: x In [2]: p = lambda (x): x File "", line 1 p = lambda (x): x ^ SyntaxError: invalid syntax From oscar.j.benjamin at gmail.com Wed Sep 11 09:11:22 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 11 Sep 2013 14:11:22 +0100 Subject: why syntax change in lambda In-Reply-To: References: Message-ID: On 11 September 2013 14:03, Neal Becker wrote: > In py2.7 this was accepted, but not in py3.3. Is this intentional? It seems to > violate the 'principle' that extraneous parentheses are usually allowed/ignored > > In [1]: p = lambda x: x > > In [2]: p = lambda (x): x > File "", line 1 > p = lambda (x): x > ^ > SyntaxError: invalid syntax I guess it's related to the removal of auto-unpacking of arguments. i.e. in 2.x: >>> f = lambda (x, y), z: (x, y, z) >>> f([1, 2], 3) (1, 2, 3) However this was removed in 3.x so >>> f = lambda (x, y), z: (x, y, z) File "", line 1 f = lambda (x, y), z: (x, y, z) ^ SyntaxError: invalid syntax Removing that feature would allow a simplification of the lambda syntax that would have no need to admit any kind of brackets. Oscar From steve+comp.lang.python at pearwood.info Wed Sep 11 20:09:48 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 Sep 2013 00:09:48 GMT Subject: why syntax change in lambda References: Message-ID: <5231064c$0$29988$c3e8da3$5496439d@news.astraweb.com> On Wed, 11 Sep 2013 09:03:49 -0400, Neal Becker wrote: > In py2.7 this was accepted, but not in py3.3. Is this intentional? It > seems to violate the 'principle' that extraneous parentheses are usually > allowed/ignored > > In [1]: p = lambda x: x > > In [2]: p = lambda (x): x > File "", line 1 > p = lambda (x): x > ^ > SyntaxError: invalid syntax It is not specific to lambda, it has to do with the removal of argument unpacking in function argument lists: # allowed in Python 2, not in Python 3 def f(a, b, (c, d), e): pass In Python 3, the parser appears to disallow any extra parentheses inside the parameter list, even if strictly speaking they don't do anything: py> def f(a, b, (c), d, e): File "", line 1 def f(a, b, (c), d, e): ^ SyntaxError: invalid syntax -- Steven From roy at panix.com Wed Sep 11 09:09:55 2013 From: roy at panix.com (Roy Smith) Date: Wed, 11 Sep 2013 09:09:55 -0400 Subject: Python in XKCD today Message-ID: http://xkcd.com/1263/ From jugurtha.hadjar at gmail.com Wed Sep 11 20:59:05 2013 From: jugurtha.hadjar at gmail.com (Jugurtha Hadjar) Date: Thu, 12 Sep 2013 01:59:05 +0100 Subject: Python in XKCD today In-Reply-To: References: Message-ID: <523111D9.40603@gmail.com> On 09/11/2013 02:09 PM, Roy Smith wrote: > http://xkcd.com/1263/ > Nice one! -- ~Jugurtha Hadjar, From duncan.booth at invalid.invalid Fri Sep 13 06:54:22 2013 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 13 Sep 2013 10:54:22 GMT Subject: Python in XKCD today References: Message-ID: Roy Smith wrote: > http://xkcd.com/1263/ So now I guess someone has to actually implement the script. At least, that's (sort of) what happened for xkcd 353 so there's a precedent. -- Duncan Booth http://kupuguy.blogspot.com From mnish1984 at gmail.com Wed Sep 11 10:14:04 2013 From: mnish1984 at gmail.com (mnish1984 at gmail.com) Date: Wed, 11 Sep 2013 07:14:04 -0700 (PDT) Subject: better and user friendly IDE recommended? Message-ID: <091bbe36-8cf9-412f-b7e9-2b3cc89dd363@googlegroups.com> Hey i am a programmer but new to python. Can anyone guide me in knowing which is a better IDE used to develop web related apps that connect to DB using python? From awilliam at whitemice.org Wed Sep 11 15:51:56 2013 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Wed, 11 Sep 2013 15:51:56 -0400 Subject: better and user friendly IDE recommended? In-Reply-To: <091bbe36-8cf9-412f-b7e9-2b3cc89dd363@googlegroups.com> References: <091bbe36-8cf9-412f-b7e9-2b3cc89dd363@googlegroups.com> Message-ID: <1378929116.12406.6.camel@linux-86wr.site> On Wed, 2013-09-11 at 07:14 -0700, mnish1984 at gmail.com wrote: > Hey i am a programmer but new to python. Can anyone guide me in knowing which is a better IDE used to develop web related apps that connect to DB using python? geany; it's awesome. -- Adam Tauno Williams GPG D95ED383 Systems Administrator, Python Developer, LPI / NCLA From ben+python at benfinney.id.au Wed Sep 11 19:44:35 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 12 Sep 2013 09:44:35 +1000 Subject: better and user friendly IDE recommended? References: <091bbe36-8cf9-412f-b7e9-2b3cc89dd363@googlegroups.com> Message-ID: <7wppse2aak.fsf@benfinney.id.au> mnish1984 at gmail.com writes: > Hey i am a programmer but new to python. Welcome! Congratulations on finding Python. > Can anyone guide me in knowing which is a better IDE used to develop > web related apps that connect to DB using python? The question of IDEs is a common one, and is a matter of aesthetics as much as functionality. Many of use use general-purpose development environments, which will repay learning in much broader range of tasks than only Python programming. Here is a Wiki page on the topic, with discussions and reviews . My main advice: Avoid non-free (that is, proprietary) software for your development tools. Learning a set of development tools is a significant investment, and you should not tie that investment to a single vendor; if they lose interest for whatever reason, your investment is stranded. Free software is essential to ensure your tools can continue beyond the copyright holders of today. -- \ ?Corporation, n. An ingenious device for obtaining individual | `\ profit without individual responsibility.? ?Ambrose Bierce, | _o__) _The Devil's Dictionary_, 1906 | Ben Finney From joshua at landau.ws Thu Sep 12 03:09:27 2013 From: joshua at landau.ws (Joshua Landau) Date: Thu, 12 Sep 2013 08:09:27 +0100 Subject: better and user friendly IDE recommended? In-Reply-To: <7wppse2aak.fsf@benfinney.id.au> References: <091bbe36-8cf9-412f-b7e9-2b3cc89dd363@googlegroups.com> <7wppse2aak.fsf@benfinney.id.au> Message-ID: On 12 September 2013 00:44, Ben Finney wrote: > mnish1984 at gmail.com writes: > > My main advice: Avoid non-free (that is, proprietary) software for your > development tools. Learning a set of development tools is a significant > investment, and you should not tie that investment to a single vendor; > if they lose interest for whatever reason, your investment is stranded. If the time learning a set of tools is enough to make the choice between tools, I suggest avoiding, say, Vim. I find that going for whatever makes you most productive is more important than trying to minimise the learning time. Most software is much easier to learn that Vim, if you have to replace it after 10 years or not. YMMV. --- OP, I suggest Sublime Text as an editor 'cause that's my editor so it must be the best choice. It's no IDE, though, if it really matters to you. From ben+python at benfinney.id.au Thu Sep 12 04:04:06 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 12 Sep 2013 18:04:06 +1000 Subject: better and user friendly IDE recommended? References: <091bbe36-8cf9-412f-b7e9-2b3cc89dd363@googlegroups.com> <7wppse2aak.fsf@benfinney.id.au> Message-ID: <7w8uz21n61.fsf@benfinney.id.au> Joshua Landau writes: > On 12 September 2013 00:44, Ben Finney wrote: > > mnish1984 at gmail.com writes: > > > > My main advice: Avoid non-free (that is, proprietary) software for your > > development tools. Learning a set of development tools is a significant > > investment, and you should not tie that investment to a single vendor; > > if they lose interest for whatever reason, your investment is stranded. > > If the time learning a set of tools is enough to make the choice > between tools, I suggest avoiding, say, Vim. Rather, the effort (not merely time) spent learning a set of tools is enough to advise choosing tools that will be around and supported by the community for a long time, and have a wide applicability. Any software that is non-free cannot be improved by its community, only by the vendor. That makes it a poor choice for a tool that takes effort to learn (such as an IDE); it can be abandoned by one party, and then no-one can improve it further. Free software does not have that problem. Development tools need to repay their user's investment by being usefully applicable to a wide variety of tasks. The set of tasks a programmer needs to perform is broad, and cannot be anticipated early on; the tools need to be flexible and adaptable by the community of users to tasks that the tool vendor never thought of. So Vim and Emacs are both good investments by that standard. > I find that going for whatever makes you most productive is more > important than trying to minimise the learning time. Agreed, and productivity is greatly improved if the tool one has already learned to use can be used for a broad range of tasks for many years. > Most software is much easier to learn that Vim, if you have to replace > it after 10 years or not. Having to learn many incompatible tools for what is effectively the same task ? whether that task is editing text, running the test suite, interacting with VCS, invoking a debugger, and so on through many other IDE tasks ? is a poor investment. Better to learn these once, in a single powerful tool that can be maintained independent of any one vendor for as long as its community is interested. -- \ ?Never express yourself more clearly than you are able to | `\ think.? ?Niels Bohr | _o__) | Ben Finney From joshua at landau.ws Thu Sep 12 06:02:50 2013 From: joshua at landau.ws (Joshua Landau) Date: Thu, 12 Sep 2013 11:02:50 +0100 Subject: better and user friendly IDE recommended? In-Reply-To: <7w8uz21n61.fsf@benfinney.id.au> References: <091bbe36-8cf9-412f-b7e9-2b3cc89dd363@googlegroups.com> <7wppse2aak.fsf@benfinney.id.au> <7w8uz21n61.fsf@benfinney.id.au> Message-ID: On 12 September 2013 09:04, Ben Finney wrote: > Joshua Landau writes: > >> On 12 September 2013 00:44, Ben Finney wrote: >> > mnish1984 at gmail.com writes: >> > >> > My main advice: Avoid non-free (that is, proprietary) software for your >> > development tools. Learning a set of development tools is a significant >> > investment, and you should not tie that investment to a single vendor; >> > if they lose interest for whatever reason, your investment is stranded. >> >> If the time learning a set of tools is enough to make the choice >> between tools, I suggest avoiding, say, Vim. > > Rather, the effort (not merely time) spent learning a set of tools is > enough to advise choosing tools that will be around and supported by the > community for a long time, and have a wide applicability. The sum time it takes to make Vim a good editor and subsequently learn it is comparable to doing the same for a good number of other editors. Vim's quite hard to learn, see? If you accept that point, you should accept that if Vim is worth the investment then, ignoring issues of other editors being of different quality?, the potential of support for your editor being dropped involves no greater opportunity cost than learning Vim. As Vim is obviously an editor many consider worth learning, we can conclude than if you prefer certain non-free alternatives you are not putting undue effort on yourself. Of course, there are a lot of other good reasons for OSS to be favoured and there are a lot of reasons to like other things, too. ? Whatever that means --- I conclude that I am right and everyone else is wrong, because if it were not the case I would be wrong and I've already asserted that I am not. From wayne at waynewerner.com Thu Sep 12 10:22:47 2013 From: wayne at waynewerner.com (Wayne Werner) Date: Thu, 12 Sep 2013 09:22:47 -0500 (CDT) Subject: better and user friendly IDE recommended? In-Reply-To: <7w8uz21n61.fsf@benfinney.id.au> References: <091bbe36-8cf9-412f-b7e9-2b3cc89dd363@googlegroups.com> <7wppse2aak.fsf@benfinney.id.au> <7w8uz21n61.fsf@benfinney.id.au> Message-ID: On Thu, 12 Sep 2013, Ben Finney wrote: > Better to learn these once, in a single powerful tool that can be > maintained independent of any one vendor for as long as its community is > interested. And if you're a developer, even a community of one is enough ;) -W From paul.nospam at rudin.co.uk Thu Sep 12 11:47:26 2013 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Thu, 12 Sep 2013 16:47:26 +0100 Subject: better and user friendly IDE recommended? References: <091bbe36-8cf9-412f-b7e9-2b3cc89dd363@googlegroups.com> <7wppse2aak.fsf@benfinney.id.au> Message-ID: <87vc26oxdd.fsf@no-fixed-abode.cable.virginmedia.net> Joshua Landau writes: > If the time learning a set of tools is enough to make the choice > between tools, I suggest avoiding, say, Vim. That's a big if. If you expect to spend a lot of time editing text, code, etc. over the next few years then it's definitely learning at least one of vim or emacs to a reasonable degree of competency. From veritatem.ignotam at gmail.com Thu Sep 12 12:00:11 2013 From: veritatem.ignotam at gmail.com (Veritatem Ignotam) Date: Thu, 12 Sep 2013 12:00:11 -0400 Subject: better and user friendly IDE recommended? In-Reply-To: <87vc26oxdd.fsf@no-fixed-abode.cable.virginmedia.net> References: <091bbe36-8cf9-412f-b7e9-2b3cc89dd363@googlegroups.com> <7wppse2aak.fsf@benfinney.id.au> <87vc26oxdd.fsf@no-fixed-abode.cable.virginmedia.net> Message-ID: <5231E50B.1090807@gmail.com> Is this thread going to evolve into your classic vim vs. emacs, sweet! Also, Paul is completely right. V.I. On 09/12/2013 11:47 AM, Paul Rudin wrote: > Joshua Landau writes: > >> If the time learning a set of tools is enough to make the choice >> between tools, I suggest avoiding, say, Vim. > That's a big if. > > If you expect to spend a lot of time editing text, code, etc. over the > next few years then it's definitely learning at least one of vim or > emacs to a reasonable degree of competency. From joe.fbs.junior at gmail.com Thu Sep 12 13:04:20 2013 From: joe.fbs.junior at gmail.com (Joe Junior) Date: Thu, 12 Sep 2013 14:04:20 -0300 Subject: better and user friendly IDE recommended? In-Reply-To: <5231E50B.1090807@gmail.com> References: <091bbe36-8cf9-412f-b7e9-2b3cc89dd363@googlegroups.com> <7wppse2aak.fsf@benfinney.id.au> <87vc26oxdd.fsf@no-fixed-abode.cable.virginmedia.net> <5231E50B.1090807@gmail.com> Message-ID: On 12 September 2013 13:00, Veritatem Ignotam wrote: > Is this thread going to evolve into your classic vim vs. emacs, sweet! Who doesn't love those? ;-) On 09/12/2013 11:47 AM, Paul Rudin wrote: > > Joshua Landau writes: > >> If the time learning a set of tools is enough to make the choice >> between tools, I suggest avoiding, say, Vim. > > That's a big if. > > If you expect to spend a lot of time editing text, code, etc. over the > next few years then it's definitely learning at least one of vim or > emacs to a reasonable degree of competency. I kinda disagree. Though I use and love emacs as my main editor, simple things you take for granted in modern editors are simply not there, and you end up spending some precious time finding out how to have it (like a right-margin marker). Of course that's not a real issue, since in the end you'll have everything and much more after configuring and saving your .emacs in the cloud so everything is always to your liking. But then comes another problem: we don't live in a bubble. If you'll ever have to use another programmer's box, you're screwed (That's why I avoid getting used to non-standard packages). Not to mention the mental switch. Not everything I need to use has emacs-binding (I guess the same is true for vim-binding) and, most of the time, the binding sucks anyway. But the point I really disagree is that typing/editing speed impacts so much programmer's productivity. In my experience I spend a lot more time as a programmer (big emphasis on "lot") reading, thinking and designing then writing code. So I find a good navigation tool more important. My solution/suggestion for python: emacs (in cua-mode for me) with Jedi. Joe From joshua at landau.ws Mon Sep 16 00:42:26 2013 From: joshua at landau.ws (Joshua Landau) Date: Mon, 16 Sep 2013 05:42:26 +0100 Subject: better and user friendly IDE recommended? In-Reply-To: <87vc26oxdd.fsf@no-fixed-abode.cable.virginmedia.net> References: <091bbe36-8cf9-412f-b7e9-2b3cc89dd363@googlegroups.com> <7wppse2aak.fsf@benfinney.id.au> <87vc26oxdd.fsf@no-fixed-abode.cable.virginmedia.net> Message-ID: On 12 September 2013 16:47, Paul Rudin wrote: > Joshua Landau writes: > >> If the time learning a set of tools is enough to make the choice >> between tools, I suggest avoiding, say, Vim. > > That's a big if. > > If you expect to spend a lot of time editing text, code, etc. over the > next few years then it's definitely learning at least one of vim or > emacs to a reasonable degree of competency. You misunderstood my argument. I was trying to say that because people are willing to put the time in to learn Vim and Emacs, there's already a precedent that the time spent *isn't* enough to make the choice between tools, and thus the argument I was responding to was wrong. From menkomigen6 at gmail.com Thu Sep 12 06:55:12 2013 From: menkomigen6 at gmail.com (Paul Pittlerson) Date: Thu, 12 Sep 2013 03:55:12 -0700 (PDT) Subject: better and user friendly IDE recommended? In-Reply-To: <091bbe36-8cf9-412f-b7e9-2b3cc89dd363@googlegroups.com> References: <091bbe36-8cf9-412f-b7e9-2b3cc89dd363@googlegroups.com> Message-ID: <1e53d18c-e4f0-4905-b81b-d4dc1c28b9cf@googlegroups.com> On Wednesday, September 11, 2013 5:14:04 PM UTC+3, mnishpsyched wrote: > Hey i am a programmer but new to python. Can anyone guide me in knowing which is a better IDE used to develop web related apps that connect to DB using python? If you are a programmer in the sense that you are a proficient in something like C or Java, then whatever development environment you used for that type of coding will surely work just as well for writing python scripts. But to answer your question: If you want something modern and fresh, maybe give Sublime Text a try. Personally, my favorite is Geany, because it has all the functionality and customization I want from an editor, but is not very bloated. From fabiofz at gmail.com Thu Sep 12 08:12:52 2013 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Thu, 12 Sep 2013 09:12:52 -0300 Subject: better and user friendly IDE recommended? In-Reply-To: <091bbe36-8cf9-412f-b7e9-2b3cc89dd363@googlegroups.com> References: <091bbe36-8cf9-412f-b7e9-2b3cc89dd363@googlegroups.com> Message-ID: You'll probably get way too many answers (everyone has its own personal favorite). I suggest you check: http://stackoverflow.com/questions/81584/what-ide-to-use-for-python and https://wiki.python.org/moin/IntegratedDevelopmentEnvironments, grab the ones you think are worth it, experiment with them a bit and use what works best for you. Cheers, Fabio On Wed, Sep 11, 2013 at 11:14 AM, wrote: > Hey i am a programmer but new to python. Can anyone guide me in knowing > which is a better IDE used to develop web related apps that connect to DB > using python? > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From anikom15 at gmail.com Thu Sep 12 13:23:16 2013 From: anikom15 at gmail.com (=?ISO-8859-1?Q?Westley_Mart=EDnez?=) Date: Thu, 12 Sep 2013 10:23:16 -0700 (PDT) Subject: better and user friendly IDE recommended? In-Reply-To: <091bbe36-8cf9-412f-b7e9-2b3cc89dd363@googlegroups.com> References: <091bbe36-8cf9-412f-b7e9-2b3cc89dd363@googlegroups.com> Message-ID: <542729ed-5788-4d38-abdc-020c55131f4a@googlegroups.com> On Wednesday, September 11, 2013 7:14:04 AM UTC-7, mnishpsyched wrote: > Hey i am a programmer but new to python. Can anyone guide me in knowing which is a better IDE used to develop web related apps that connect to DB using python? I use vim and idle. From mortuuslordofdeads at gmail.com Thu Sep 12 17:15:27 2013 From: mortuuslordofdeads at gmail.com (=?ISO-8859-1?Q?Adri=E1n_Espinosa?=) Date: Thu, 12 Sep 2013 14:15:27 -0700 (PDT) Subject: better and user friendly IDE recommended? In-Reply-To: <091bbe36-8cf9-412f-b7e9-2b3cc89dd363@googlegroups.com> References: <091bbe36-8cf9-412f-b7e9-2b3cc89dd363@googlegroups.com> Message-ID: El mi?rcoles, 11 de septiembre de 2013 16:14:04 UTC+2, mnishpsyched escribi?: > Hey i am a programmer but new to python. Can anyone guide me in knowing which is a better IDE used to develop web related apps that connect to DB using python? Hi and welcome. I suggest you to use IntelliJ IDEA. It has a plugin for Python and Django (web framework). It works flawlessly. From memilanuk at gmail.com Sat Sep 14 17:22:56 2013 From: memilanuk at gmail.com (memilanuk) Date: Sat, 14 Sep 2013 14:22:56 -0700 Subject: better and user friendly IDE recommended? In-Reply-To: References: <091bbe36-8cf9-412f-b7e9-2b3cc89dd363@googlegroups.com> Message-ID: On 09/12/2013 02:15 PM, Adri?n Espinosa wrote: > I suggest you to use IntelliJ IDEA. It has a plugin for Python and Django (web framework). It works flawlessly. > If one were inclined to go that route, wouldn't PyCharm typically be a better choice? From eric at invalid.com Sun Sep 15 22:48:50 2013 From: eric at invalid.com (EricF) Date: Mon, 16 Sep 2013 02:48:50 GMT Subject: better and user friendly IDE recommended? References: <091bbe36-8cf9-412f-b7e9-2b3cc89dd363@googlegroups.com> Message-ID: In article , memilanuk wrote: >On 09/12/2013 02:15 PM, Adri?n Espinosa wrote: > >> I suggest you to use IntelliJ IDEA. It has a plugin for Python and Django > (web framework). It works flawlessly. >> > >If one were inclined to go that route, wouldn't PyCharm typically be a >better choice? > If you also do Java, IntelliJ Idea may be the better choice, if not, PyCharm. Idea + the plug in gives you the capabilities of PyCharm. Eric From rustompmody at gmail.com Tue Sep 17 09:56:18 2013 From: rustompmody at gmail.com (rusi) Date: Tue, 17 Sep 2013 06:56:18 -0700 (PDT) Subject: better and user friendly IDE recommended? In-Reply-To: <091bbe36-8cf9-412f-b7e9-2b3cc89dd363@googlegroups.com> References: <091bbe36-8cf9-412f-b7e9-2b3cc89dd363@googlegroups.com> Message-ID: On Wednesday, September 11, 2013 7:44:04 PM UTC+5:30, mnishpsyched wrote: > Hey i am a programmer but new to python. Can anyone guide me in knowing which is a better IDE used to develop web related apps that connect to DB using python? Just saw this http://www.youtube.com/watch?v=1-dUkyn_fZA Yeah... scientific programming and web programming are hardly the same :-) Still it might be worth 20 minutes of your time From wanderer at dialup4less.com Wed Sep 11 10:26:32 2013 From: wanderer at dialup4less.com (Wanderer) Date: Wed, 11 Sep 2013 07:26:32 -0700 (PDT) Subject: Send alt key to subprocess.PIPE stdin Message-ID: <38b49476-607e-43ed-bd70-804ff8329ad0@googlegroups.com> How do I send the command 'Alt+D' to subprocess.PIPE? My code is import subprocess rsconfig = subprocess.Popen(["C:\Program Files\Photometrics\PVCam64\utilities\RSConfig\RSConfig.exe", ],stdin=subprocess.PIPE) rsconfig.stdin.write('Alt+D') Thanks From nobody at nowhere.com Wed Sep 11 13:18:07 2013 From: nobody at nowhere.com (Nobody) Date: Wed, 11 Sep 2013 18:18:07 +0100 Subject: Send alt key to subprocess.PIPE stdin References: <38b49476-607e-43ed-bd70-804ff8329ad0@googlegroups.com> Message-ID: On Wed, 11 Sep 2013 07:26:32 -0700, Wanderer wrote: > How do I send the command 'Alt+D' to subprocess.PIPE? You don't. GUI programs don't read stdin, they receive key press events from the windowing system. From gherron at digipen.edu Wed Sep 11 13:43:09 2013 From: gherron at digipen.edu (Gary Herron) Date: Wed, 11 Sep 2013 10:43:09 -0700 Subject: Send alt key to subprocess.PIPE stdin In-Reply-To: <38b49476-607e-43ed-bd70-804ff8329ad0@googlegroups.com> References: <38b49476-607e-43ed-bd70-804ff8329ad0@googlegroups.com> Message-ID: <5230ABAD.4020002@digipen.edu> On 09/11/2013 07:26 AM, Wanderer wrote: > How do I send the command 'Alt+D' to subprocess.PIPE? > > My code is > > import subprocess > rsconfig = subprocess.Popen(["C:\Program Files\Photometrics\PVCam64\utilities\RSConfig\RSConfig.exe", ],stdin=subprocess.PIPE) > > rsconfig.stdin.write('Alt+D') > > Thanks That question doesn't really make sense. A pipe provides a method to transfer a stream of bytes. You could indeed send that byte across the pipe, but it's just a byte, written by one process and read by another process. The receiving process can examine the byte stream, and do whatever it wants in response. By calling it a _command_, you seem to expect some particular behavior out of the receiving process. Please tell us *what* that might be, and we'll see what we can do to help out. Gary Herron -- Dr. Gary Herron Department of Computer Science DigiPen Institute of Technology (425) 895-4418 From wanderer at dialup4less.com Wed Sep 11 16:15:48 2013 From: wanderer at dialup4less.com (Wanderer) Date: Wed, 11 Sep 2013 13:15:48 -0700 (PDT) Subject: Send alt key to subprocess.PIPE stdin In-Reply-To: References: <38b49476-607e-43ed-bd70-804ff8329ad0@googlegroups.com> Message-ID: <16f83d11-3bcf-4bf4-9890-cdb896ae1a29@googlegroups.com> On Wednesday, September 11, 2013 1:43:09 PM UTC-4, Gary Herron wrote: > On 09/11/2013 07:26 AM, Wanderer wrote: > > > How do I send the command 'Alt+D' to subprocess.PIPE? > > > > > > My code is > > > > > > import subprocess > > > rsconfig = subprocess.Popen(["C:\Program Files\Photometrics\PVCam64\utilities\RSConfig\RSConfig.exe", ],stdin=subprocess.PIPE) > > > > > > rsconfig.stdin.write('Alt+D') > > > > > > Thanks > > > > That question doesn't really make sense. A pipe provides a method to > > transfer a stream of bytes. You could indeed send that byte across the > > pipe, but it's just a byte, written by one process and read by another > > process. The receiving process can examine the byte stream, and do > > whatever it wants in response. > > > > By calling it a _command_, you seem to expect some particular behavior > > out of the receiving process. Please tell us *what* that might be, and > > we'll see what we can do to help out. > > > > Gary Herron > > > > > > > > -- > > Dr. Gary Herron > > Department of Computer Science > > DigiPen Institute of Technology > > (425) 895-4418 I found Sendkeys works. import subprocess import time import SendKeys rsconfig = subprocess.Popen(["C:\Program Files\Photometrics\PVCam64\utilities\RSConfig\RSConfig.exe", ]) time.sleep(2) SendKeys.SendKeys('%D\n', with_newlines=True) Basically there is a dialog with a Done button and 'Alt D' selects the Done button. The subprocess program runs some interface code which sets up an ini file that the rest of the program needs. But then I run into another problem with Windows permissions. The program needs to edit this ini file located in the C:\Windows directory. Windows won't let you without administrator permissions. So then I run into login issues, etc. I kind of gave up and this program has to be run outside my main program. It's annoying since it's just this stupid little text ini file, but I can't convince Windows it doesn't matter if gets edited because it's in a system directory. From davea at davea.name Wed Sep 11 16:23:57 2013 From: davea at davea.name (Dave Angel) Date: Wed, 11 Sep 2013 20:23:57 +0000 (UTC) Subject: Send alt key to subprocess.PIPE stdin References: <38b49476-607e-43ed-bd70-804ff8329ad0@googlegroups.com> Message-ID: On 11/9/2013 10:26, Wanderer wrote: > How do I send the command 'Alt+D' to subprocess.PIPE? That's not a command, it's a keystroke combination. And without knowing what RSConfig.exe is looking to get its keystrokes, it might not even be possible to feed it any keystrokes via the pipe. if the program does indeed use stdin, there's no portable encoding for Alt-D. But if your program only runs on one particular platform, you might be able to find docs for that platform that explain it. > > My code is > > import subprocess > rsconfig = subprocess.Popen(["C:\Program Files\Photometrics\PVCam64\utilities\RSConfig\RSConfig.exe", ],stdin=subprocess.PIPE) That string will only work by accident. You need to make it a raw string, or use forward slashes, or double them. As it happens, with this PARTICULAR set of directories, you won't get into trouble with Python 2.7.3 -- DaveA From wanderer at dialup4less.com Thu Sep 12 10:06:01 2013 From: wanderer at dialup4less.com (Wanderer) Date: Thu, 12 Sep 2013 07:06:01 -0700 (PDT) Subject: Send alt key to subprocess.PIPE stdin In-Reply-To: References: <38b49476-607e-43ed-bd70-804ff8329ad0@googlegroups.com> Message-ID: <54dfa194-a84d-4b65-b9d8-1b26ec090fb3@googlegroups.com> On Wednesday, September 11, 2013 4:23:57 PM UTC-4, Dave Angel wrote: > On 11/9/2013 10:26, Wanderer wrote: > > > > > How do I send the command 'Alt+D' to subprocess.PIPE? > > > > That's not a command, it's a keystroke combination. And without knowing > > what RSConfig.exe is looking to get its keystrokes, it might not even be > > possible to feed it any keystrokes via the pipe. > > > > if the program does indeed use stdin, there's no portable encoding for > > Alt-D. But if your program only runs on one particular platform, you > > might be able to find docs for that platform that explain it. > > > > > > > > My code is > > > > > > import subprocess > > > rsconfig = subprocess.Popen(["C:\Program Files\Photometrics\PVCam64\utilities\RSConfig\RSConfig.exe", ],stdin=subprocess.PIPE) > > > > That string will only work by accident. You need to make it a raw > > string, or use forward slashes, or double them. As it happens, with > > this PARTICULAR set of directories, you won't get into trouble with > > Python 2.7.3 > > > > > > > > -- > > DaveA Thanks, I didn't know that. I thought there would be some \n \t kind of combination or a unicode string for all the key combinations on my keyboard. From rosuav at gmail.com Thu Sep 12 11:27:53 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 13 Sep 2013 01:27:53 +1000 Subject: Send alt key to subprocess.PIPE stdin In-Reply-To: <54dfa194-a84d-4b65-b9d8-1b26ec090fb3@googlegroups.com> References: <38b49476-607e-43ed-bd70-804ff8329ad0@googlegroups.com> <54dfa194-a84d-4b65-b9d8-1b26ec090fb3@googlegroups.com> Message-ID: On Fri, Sep 13, 2013 at 12:06 AM, Wanderer wrote: > Thanks, I didn't know that. I thought there would be some \n \t kind of combination or a unicode string for all the key combinations on my keyboard. Unicode identifies every character, but keystrokes aren't characters. Consider, for instance, the difference between the keypress Shift+A and the letter produced - even in the most simple ASCII-only US-only situation, that could produce either "A" or (if Caps Lock is active) "a". So if you actually want to trigger Shift+A, you can't represent that with a character. Controlling a GUI app has to be done with keystrokes, so it needs a GUI controlling tool. That said, though: These sorts of keystrokes often can be represented with escape sequences (I just tried it in xterm and Alt-D came out as "\e[d"), so you could control a console program using sequences that you could put into a string. But that's not true of your typical GUI system. ChrisA From nobody at nowhere.com Thu Sep 12 13:20:14 2013 From: nobody at nowhere.com (Nobody) Date: Thu, 12 Sep 2013 18:20:14 +0100 Subject: Send alt key to subprocess.PIPE stdin References: <38b49476-607e-43ed-bd70-804ff8329ad0@googlegroups.com> <54dfa194-a84d-4b65-b9d8-1b26ec090fb3@googlegroups.com> Message-ID: On Fri, 13 Sep 2013 01:27:53 +1000, Chris Angelico wrote: > That said, though: These sorts of keystrokes often can be represented > with escape sequences (I just tried it in xterm and Alt-D came out as > "\e[d"), Technically, that would be Meta-D (even if your Meta key has "Alt" printed on it). Alt- produces chr(ord(char)+128); Meta- produces "\e"+char. At least, that's the historical distinction between Meta and Alt. With xterm, the behaviour is configurable via the resources altIsNotMeta, altSendsEscape and metaSendsEscape. None of which has anything to do with trying to feed a GUI program key events via stdin ... From pestrella at gmail.com Wed Sep 11 11:04:06 2013 From: pestrella at gmail.com (pestrella at gmail.com) Date: Wed, 11 Sep 2013 08:04:06 -0700 (PDT) Subject: TypeError in date_parse.py Message-ID: <09d39e02-c741-4a46-b34f-551e11118e7b@googlegroups.com> Hello, I'm running an application using python 2.7 with django 1.5 and when posting a page I get the error "TypeError" I guess it is something related to timestamps? Below I paste part of the code I think is causing the problem and the stacktace I see Any help is welcome, Thanks! Paula ============================= # Compute duration for this item. duration = None if end_timestamp and start_timestamp: start_datetime = datetime.fromtimestamp(float(start_timestamp)) end_datetime = datetime.fromtimestamp(float(end_timestamp)) duration = end_datetime - start_datetime ============================= POST Request URL: http://127.0.0.1:8000/appraise/evaluation/7b31d05e50584d2b92b4a04d85e68ce3/ Django Version: 1.5.2 Exception Type: TypeError Exception Value: expected string or buffer Exception Location: /usr/local/lib/python2.7/dist-packages/django/utils/dateparse.py in parse_time, line 50 Python Executable: /usr/bin/python Python Version: 2.7.2 Python Path: ['../Appraise-Software/appraise', '/home/paula/.local/lib/python2.7/site-packages/setuptools-1.1.4-py2.7.egg', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/home/paula/.local/lib/python2.7/site-packages', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PIL', '/usr/lib/python2.7/dist-packages/gst-0.10', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7', '/usr/lib/python2.7/dist-packages/ubuntu-sso-client', '/usr/lib/python2.7/dist-packages/ubuntuone-client', '/usr/lib/python2.7/dist-packages/ubuntuone-control-panel', '/usr/lib/python2.7/dist-packages/ubuntuone-couch', '/usr/lib/python2.7/dist-packages/ubuntuone-installer', '/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol'] From gordon at panix.com Wed Sep 11 12:15:01 2013 From: gordon at panix.com (John Gordon) Date: Wed, 11 Sep 2013 16:15:01 +0000 (UTC) Subject: TypeError in date_parse.py References: <09d39e02-c741-4a46-b34f-551e11118e7b@googlegroups.com> Message-ID: In <09d39e02-c741-4a46-b34f-551e11118e7b at googlegroups.com> pestrella at gmail.com writes: > ============================= > # Compute duration for this item. > duration = None > if end_timestamp and start_timestamp: > start_datetime = datetime.fromtimestamp(float(start_timestamp)) > end_datetime = datetime.fromtimestamp(float(end_timestamp)) > duration = end_datetime - start_datetime > ============================= What is the type and value of start_timestamp and end_timestamp? -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From pestrella at gmail.com Wed Sep 11 13:02:08 2013 From: pestrella at gmail.com (pestrella at gmail.com) Date: Wed, 11 Sep 2013 10:02:08 -0700 (PDT) Subject: TypeError in date_parse.py In-Reply-To: References: <09d39e02-c741-4a46-b34f-551e11118e7b@googlegroups.com> Message-ID: <3d0038fd-00ec-4560-ab0d-06528f838026@googlegroups.com> I think it's a float, I see in the code if request.method == "POST": end_timestamp = request.POST.get('end_timestamp', None) start_timestamp = request.POST.get('start_timestamp', None) and in the debug of django <3d0038fd-00ec-4560-ab0d-06528f838026@googlegroups.com> Message-ID: In <3d0038fd-00ec-4560-ab0d-06528f838026 at googlegroups.com> pestrella at gmail.com writes: > I think it's a float, I see in the code > if request.method == "POST": > end_timestamp = request.POST.get('end_timestamp', None) > start_timestamp = request.POST.get('start_timestamp', None) > and in the debug of django > Scott, Yes. As Mark Hammond suggested I took a look into the code/console modules. I wound up using InteractiveConsole from the code module. I'm sure my requirements are completely different from yours but I'll explain what I did anyway... I was working with a client/server architecture where I wanted the client to be able to interact with a server-side Python console. Yes, I know this is a huge security hole. It is only used as a debugging console to be able to interactively inspect the state of the remote server process from within the client application itself. This 3rd party client server application I was customizing allows me to write my own services. So I wrote a service that accepts a string (the python line) and returns two strings and a boolean (stdout, stderr, and whether or not the interpreter expects more input). That boolean basically controls whether the console should show a ">>>" or a "..." and comes from InteractiveConsole.push. To get stdout and stderr I monkey patched sys.stdout and sys.stderr with an instance of MyBuffer. class MyBuffer(object): def __init__(self): self.buffer = [] def write(self, data): self.buffer.append(data) def get(self): ret = ''.join(self.buffer) self.buffer = [] return ret In my subclass of InteractiveConsole I defined the following... def __init__(self, *args, **kwargs): InteractiveConsole.__init__(self, *args, **kwargs) self.mb_out = MyBuffer() self.mb_err = MyBuffer() def process(self, s): sys.stdout, sys.stderr = self.mb_out, self.mb_err more = self.push(s) sys.stdout, sys.stderr = sys.__stdout__, sys.__stderr__ return self.mb_out.get(), self.mb_err.get(), more My service (written in c++), upon initialization gets a handle to a singleton instance of this InteractiveConsole sublcass using the Python C APIs. When the service responds to a request it uses the Python C APIs to call the process method above and returns the two strings and the boolean. The client, which happens to be Java/Eclipse based, then has something that resembles a Python console in the GUI and uses that single service to interact with the remote Python console. Lots of stuff going on but it works very well. On Wed, Sep 11, 2013 at 1:42 PM, Scott wrote: > Eric, > > https://mail.python.org/pipermail/python-list/2011-March/600441.html > > Did you ever figure this out? I'm trying to embed an interactive > interpreter, and I'm sure that python has an easy way to do this, but I > can't seem to find it... > > Thanks, > -C. Scott! Brown > -------------- next part -------------- An HTML attachment was scrubbed... URL: From zughumancapital at yahoo.com.br Wed Sep 11 15:00:13 2013 From: zughumancapital at yahoo.com.br (zughumancapital) Date: Wed, 11 Sep 2013 19:00:13 -0000 Subject: Oportunidade: Desenvolvedor Python Message-ID: Arpex Capital seleciona para uma de suas empresas: Desenvolvedor Python Objetivo geral da Posi??o: Desenvolver software est?vel e de primeira linha, que ser? incorporado ? plataforma de WiFi mais moderna atualmente. Pr?-requisitos: - Conhecimento em Python - MongoDB - Cloud computing, BigData - Pensamento l?gico e anal?tico - Capacidade de absorver tecnologias novas de forma constante Deveres: - Escrever software s?lido em Python Forma??o: Irrelevante (n?o cobramos) Local de Trabalho: S?o Paulo/SP A empresa oferece remunera??o compat?vel com o mercado + Benef?cios. Os interessados dever?o enviar o CV para kgarcia at arpexcapital.com.br , mencionando no assunto Desenvolvedor Python. From eamonnrea at gmail.com Wed Sep 11 16:55:59 2013 From: eamonnrea at gmail.com (eamonnrea at gmail.com) Date: Wed, 11 Sep 2013 13:55:59 -0700 (PDT) Subject: Python GUI? Message-ID: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> There are a few known GUI toolkits out there, and the main ones from what I can tell are: Tkinter -- Simple to use, but limited PyQT -- You have a GUI designer, so I'm not going to count that PyGTK -- Gnome officially back this I think wxPython -- Very nice, very professional, approved by Python creator, but alas hard to get started with So, what are your personal preferences and why? Why use X over Y? I, personally, really like wxPython, but I also really like Tkinter. I've messed with PyGTK, but I'd choose wxPython over it. Have you got anything to say on what one I should be using(excluding PyQT because it has a D&D designer >:( )? Is Tkinter really dead? Should I stick with wxPython? It's might be similar to the "What language to use" argument, or the "What background to code on" argument(I prefer darker backgrounds xD Please don't argue about this though!), in the sense that there is *no* answer, just preference. Also, with wxPython, it has kind of a "flow" layout like JFrame, whereas it will adjust it's layout to look like a native Mac App, Windows app or Linux App, correct? It'll look almost identical, right? Not that it matters, I'm just curious! :D Thanks! From torriem at gmail.com Thu Sep 12 01:05:14 2013 From: torriem at gmail.com (Michael Torrie) Date: Wed, 11 Sep 2013 23:05:14 -0600 Subject: Python GUI? In-Reply-To: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> Message-ID: <52314B8A.6060304@gmail.com> On 09/11/2013 02:55 PM, eamonnrea at gmail.com wrote: > PyQT -- You have a GUI designer, so I'm not going to count that What do you mean? Gtk has a GUI designer too. what of it? > I, personally, really like wxPython, but I also really like Tkinter. > I've messed with PyGTK, but I'd choose wxPython over it. Not me. wxWidgets' event model is way too MFC-esque for me. Does it still use event numbers that you define? Shudder. Gtk and Qt's method of signals and slots is by far the most powerful and flexible. > Have you got anything to say on what one I should be using(excluding > PyQT because it has a D&D designer >:( )? Is Tkinter really dead? > Should I stick with wxPython? I still don't understand why you are excluding Qt. All modern toolkits are heading towards imperative GUI design. With Gtk I use Glade and GtkBuilder. My GUI is in a nice XML file that gets loaded and manipulated by my python class. It's extremely clean. And in the case of compiled programming, you don't have to recompile just to tweak something like a layout. At the moment if someone were to come in from scratch and ask what GUI toolkit to use, I would answer Qt with PySide. It's the most cross-platform of all the toolkits, and it's one of the most mature. Gtk is also good, but Windows and Mac support is always lagging behind X11, and it's not as good at fitting into the native look and feel. > Also, with wxPython, it has kind of a "flow" layout like JFrame, > whereas it will adjust it's layout to look like a native Mac App, > Windows app or Linux App, correct? It'll look almost identical, > right? Not that it matters, I'm just curious! :D Possibly. I know Qt and Gtk both can flip the button orders, etc to look more native. And all good toolkits give you layout managers so you never have to resort to fixed layouts. Qt's layout system is very different than Gtk's, but once you get the feel of it (use the Qt Designer program!), it makes a lot of sense. From eamonnrea at gmail.com Thu Sep 12 12:03:08 2013 From: eamonnrea at gmail.com (eamonnrea at gmail.com) Date: Thu, 12 Sep 2013 09:03:08 -0700 (PDT) Subject: Python GUI? In-Reply-To: References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> Message-ID: On Thursday, September 12, 2013 6:05:14 AM UTC+1, Michael Torrie wrote: > On 09/11/2013 02:55 PM, eamonnrea at gmail.com wrote: > > > PyQT -- You have a GUI designer, so I'm not going to count that > > > > What do you mean? Gtk has a GUI designer too. what of it? > > > > > I, personally, really like wxPython, but I also really like Tkinter. > > > I've messed with PyGTK, but I'd choose wxPython over it. > > > > Not me. wxWidgets' event model is way too MFC-esque for me. Does it > > still use event numbers that you define? Shudder. > > > > Gtk and Qt's method of signals and slots is by far the most powerful and > > flexible. > > > > > Have you got anything to say on what one I should be using(excluding > > > PyQT because it has a D&D designer >:( )? Is Tkinter really dead? > > > Should I stick with wxPython? > > > > I still don't understand why you are excluding Qt. All modern toolkits > > are heading towards imperative GUI design. With Gtk I use Glade and > > GtkBuilder. My GUI is in a nice XML file that gets loaded and > > manipulated by my python class. It's extremely clean. And in the case > > of compiled programming, you don't have to recompile just to tweak > > something like a layout. > > > > At the moment if someone were to come in from scratch and ask what GUI > > toolkit to use, I would answer Qt with PySide. It's the most > > cross-platform of all the toolkits, and it's one of the most mature. > > Gtk is also good, but Windows and Mac support is always lagging behind > > X11, and it's not as good at fitting into the native look and feel. > > > > > Also, with wxPython, it has kind of a "flow" layout like JFrame, > > > whereas it will adjust it's layout to look like a native Mac App, > > > Windows app or Linux App, correct? It'll look almost identical, > > > right? Not that it matters, I'm just curious! :D > > > > Possibly. I know Qt and Gtk both can flip the button orders, etc to > > look more native. And all good toolkits give you layout managers so you > > never have to resort to fixed layouts. Qt's layout system is very > > different than Gtk's, but once you get the feel of it (use the Qt > > Designer program!), it makes a lot of sense. I didn't realise GTK has a GUI designer too :( I don't like it when you can D&D to position things. I don't understand why someone wouldn't want to write the positioning code, and have fun with the debugging. That's the best part about writing a program, in my opinion. I'm against D&D with programming, and I'm not sure why. From robert.kern at gmail.com Thu Sep 12 12:23:54 2013 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 12 Sep 2013 17:23:54 +0100 Subject: Python GUI? In-Reply-To: References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> Message-ID: On 2013-09-12 17:03, eamonnrea at gmail.com wrote: > On Thursday, September 12, 2013 6:05:14 AM UTC+1, Michael Torrie wrote: >> On 09/11/2013 02:55 PM, eamonnrea at gmail.com wrote: >> Possibly. I know Qt and Gtk both can flip the button orders, etc to >> look more native. And all good toolkits give you layout managers so you >> never have to resort to fixed layouts. Qt's layout system is very >> different than Gtk's, but once you get the feel of it (use the Qt >> Designer program!), it makes a lot of sense. > > I didn't realise GTK has a GUI designer too :( > > I don't like it when you can D&D to position things. I don't understand why someone wouldn't want to write the positioning code, and have fun with the debugging. That's the best part about writing a program, in my opinion. I'm against D&D with programming, and I'm not sure why. There is nothing forcing you to use the GUI designers if you don't want to. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From benjamin.kaplan at case.edu Thu Sep 12 12:51:49 2013 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 12 Sep 2013 09:51:49 -0700 Subject: Python GUI? In-Reply-To: References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> Message-ID: On Sep 12, 2013 9:06 AM, wrote: > > On Thursday, September 12, 2013 6:05:14 AM UTC+1, Michael Torrie wrote: > > On 09/11/2013 02:55 PM, eamonnrea at gmail.com wrote: > > > > > PyQT -- You have a GUI designer, so I'm not going to count that > > > > What do you mean? Gtk has a GUI designer too. what of it > > > > > I, personally, really like wxPython, but I also really like Tkinter. > > > > > I've messed with PyGTK, but I'd choose wxPython over it. > > > > Not me. wxWidgets' event model is way too MFC-esque for me. Does it > > > > still use event numbers that you define? Shudder. > > > > Gtk and Qt's method of signals and slots is by far the most powerful and > > flexible. > > > > > Have you got anything to say on what one I should be using(excluding > > > > > PyQT because it has a D&D designer >:( )? Is Tkinter really dead? > > > > > Should I stick with wxPython? > > I still don't understand why you are excluding Qt. All modern toolkits > > > > are heading towards imperative GUI design. With Gtk I use Glade and > > > > GtkBuilder. My GUI is in a nice XML file that gets loaded and > > > > manipulated by my python class. It's extremely clean. And in the case > > > > of compiled programming, you don't have to recompile just to tweak > > > > something like a layout. > > At the moment if someone were to come in from scratch and ask what GUI > > toolkit to use, I would answer Qt with PySide. It's the most > > cross-platform of all the toolkits, and it's one of the most mature. > > > > Gtk is also good, but Windows and Mac support is always lagging behind > > > > X11, and it's not as good at fitting into the native look and feel. > > > > Also, with wxPython, it has kind of a "flow" layout like JFrame, > > > > > whereas it will adjust it's layout to look like a native Mac App, > > > > > Windows app or Linux App, correct? It'll look almost identical, > > > > > right? Not that it matters, I'm just curious! :D > > > > > > > > Possibly. I know Qt and Gtk both can flip the button orders, etc to > > > > look more native. And all good toolkits give you layout managers so you > > > > never have to resort to fixed layouts. Qt's layout system is very > > > > different than Gtk's, but once you get the feel of it (use the Qt > > > > Designer program!), it makes a lot of sense. > > I didn't realise GTK has a GUI designer too :( > > I don't like it when you can D&D to position things. I don't understand why someone wouldn't want to write the positioning code, and have fun with the debugging. That's the best part about writing a program, in my opinion. I'm against D&D with programming, and I'm not sure why. > -- > There are gui designers for wx as well. Doesn't mean you ever have to use any of them (although I wouldn't want to write windows forms code by hand). I do find it generally nicer to work with the markup formats (xrc for wx, xaml for wpf, and so on) rather than trying to describe a gui in a programming language. The main difference between wx and qt is that qt looks native on every platform while wx *is* native on every platform (it uses native controls wherever possible). This means that wx integrates into the OS better, but your also more likely to need OS-specific tweaks in wx, at least from my experience from a few years ago. -------------- next part -------------- An HTML attachment was scrubbed... URL: From davecook at nowhere.net Thu Sep 12 14:50:31 2013 From: davecook at nowhere.net (Dave Cook) Date: 12 Sep 2013 18:50:31 GMT Subject: Python GUI? References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> Message-ID: <52320cf7$0$10776$c3e8da3$1cbc7475@news.astraweb.com> On 2013-09-12, Robert Kern wrote: > There is nothing forcing you to use the GUI designers if you don't want to. There's also a markup language available, enaml: http://docs.enthought.com/enaml/ Dave Cook From davecook at nowhere.net Thu Sep 12 17:36:57 2013 From: davecook at nowhere.net (Dave Cook) Date: 12 Sep 2013 21:36:57 GMT Subject: Python GUI? References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> <52320cf7$0$10776$c3e8da3$1cbc7475@news.astraweb.com> Message-ID: <523233f9$0$58640$c3e8da3$12bcf670@news.astraweb.com> On 2013-09-12, Dave Cook wrote: > There's also a markup language available, enaml: > > http://docs.enthought.com/enaml/ I should have mentioned that it's *Python*-based markup, not an XML horrorshow. http://pyvideo.org/video/1231/enaml-a-framework-for-building-declarative-user Dave Cook From torriem at gmail.com Thu Sep 12 23:02:42 2013 From: torriem at gmail.com (Michael Torrie) Date: Thu, 12 Sep 2013 21:02:42 -0600 Subject: Python GUI? In-Reply-To: References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> Message-ID: <52328052.2020207@gmail.com> On 09/12/2013 10:03 AM, eamonnrea at gmail.com wrote: > I didn't realise GTK has a GUI designer too :( > > I don't like it when you can D&D to position things. I don't > understand why someone wouldn't want to write the positioning code, > and have fun with the debugging. That's the best part about writing a > program, in my opinion. I'm against D&D with programming, and I'm not > sure why. Oh, I understand now. You mean you dislike the old fixed-position, pixel-based layouts that visual studio used to use, right? Well, rest easy, because both Gtk and Qt use layout managers (packing managers) instead. Much more flexible, and can automatically resize as a window sizes, and deal with things like dpi changes. And in both cases you don't have to use the imperative tools. You can still hand-code your GUI in code in Gtk, Qt, or any other gui system. In any event I think you should give both Glade-3 and Qt Designer a serious look. I think your hate of gui designers is about 10 years out of date now, even if you still prefer not to use them. From torriem at gmail.com Thu Sep 12 23:18:01 2013 From: torriem at gmail.com (Michael Torrie) Date: Thu, 12 Sep 2013 21:18:01 -0600 Subject: Python GUI? In-Reply-To: <52328052.2020207@gmail.com> References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> <52328052.2020207@gmail.com> Message-ID: <523283E9.6030705@gmail.com> On 09/12/2013 09:02 PM, Michael Torrie wrote: > In any event I think you should give both Glade-3 and Qt Designer a > serious look. I think your hate of gui designers is about 10 years out > of date now, even if you still prefer not to use them. This is a bit old but still how Qt works: http://thelins.se/learnqt/2009/05/qt-layouts-the-basics/ From eamonnrea at gmail.com Fri Sep 13 14:23:25 2013 From: eamonnrea at gmail.com (eamonnrea at gmail.com) Date: Fri, 13 Sep 2013 11:23:25 -0700 (PDT) Subject: Python GUI? In-Reply-To: References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> Message-ID: <0c43a0f4-1cd5-4598-aafd-a09543f6e659@googlegroups.com> On Friday, September 13, 2013 4:02:42 AM UTC+1, Michael Torrie wrote: > On 09/12/2013 10:03 AM, eamonnrea at gmail.com wrote: >I think your hate of gui designers is about 10 years out of date now, > even if you still prefer not to use them. So, you are recommending not to code as much? :'( That is what depresses me. These "tools" depress me! I don't understand why people don't want to code. It's time consuming: But that's the point!!! It *should* be time consuming. It *should* take time to make programs. Speed isn't the main thing, fun is. And these "tools" are taking the fun away. From torriem at gmail.com Sat Sep 14 00:03:19 2013 From: torriem at gmail.com (Michael Torrie) Date: Fri, 13 Sep 2013 22:03:19 -0600 Subject: Python GUI? In-Reply-To: <0c43a0f4-1cd5-4598-aafd-a09543f6e659@googlegroups.com> References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> <0c43a0f4-1cd5-4598-aafd-a09543f6e659@googlegroups.com> Message-ID: <5233E007.1040007@gmail.com> On 09/13/2013 12:23 PM, eamonnrea at gmail.com wrote: > On Friday, September 13, 2013 4:02:42 AM UTC+1, Michael Torrie > wrote: >> On 09/12/2013 10:03 AM, eamonnrea at gmail.com wrote: I think your >> hate of gui designers is about 10 years out of date now, even if >> you still prefer not to use them. > > So, you are recommending not to code as much? :'( That is what > depresses me. These "tools" depress me! And some people think that automatic transmissions are depressing. To each his own. > I don't understand why people don't want to code. It's time > consuming: But that's the point!!! It *should* be time consuming. It > *should* take time to make programs. Speed isn't the main thing, fun > is. And these "tools" are taking the fun away. And nothing in Gtk, Qt, Tk, wx, or any other modern toolkit prevents you from declaratively creating your GUI. And for small programs there's nothing wrong with coding the gui by hand (and in fact I recommend it). As complexity rises, though, I'd rather just code the creative parts of things, and not busy-code, which is what gui code becomes. Much of it is boiler-plate, cut and pasted, etc. From feliphil at gmx.net Sat Sep 14 13:15:42 2013 From: feliphil at gmx.net (Wolfgang Keller) Date: Sat, 14 Sep 2013 19:15:42 +0200 Subject: Python GUI? References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> <0c43a0f4-1cd5-4598-aafd-a09543f6e659@googlegroups.com> Message-ID: <20130914191542.07ab20194ccee9b8e9ebcd71@gmx.net> > As complexity rises, though, I'd rather just code the creative parts > of things, and not busy-code, which is what gui code becomes. Much > of it is boiler-plate, cut and pasted, etc. If much of the code for a GUI is boiler-plate, busy-code etc. than I would suggest that the framework is not really as efficient as it should be. In fact that's one of the issues I still have with Python: The language in general is very efficient, allows to do a lot with very little code. But all GUI frameworks that I had a look at seem to be not "pythonic" at all in this regard. Except for PyGUI maybe, but that's far from being as extensive as wxPython or PyQt. So for GUI applications, Python doesn't seem to have any advantage over #?$%&! like C++ etc. concerning code efficiency. X-( Sincerely, Wolfgang From davecook at nowhere.net Sun Sep 15 18:13:15 2013 From: davecook at nowhere.net (Dave Cook) Date: 15 Sep 2013 22:13:15 GMT Subject: Python GUI? References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> <0c43a0f4-1cd5-4598-aafd-a09543f6e659@googlegroups.com> <20130914191542.07ab20194ccee9b8e9ebcd71@gmx.net> Message-ID: <523630fb$0$17123$c3e8da3$dd9697d2@news.astraweb.com> On 2013-09-14, Wolfgang Keller wrote: > If much of the code for a GUI is boiler-plate, busy-code etc. than I > would suggest that the framework is not really as efficient as it > should be. There are very few Python GUI frameworks as such. They are almost all just toolkits, not frameworks in the sense of, say, Django. Enthought has some interesting GUI framework projects which I haven't tried: http://code.enthought.com/projects/ Dabo would be another example. Dave Cook From rustompmody at gmail.com Tue Sep 17 10:55:30 2013 From: rustompmody at gmail.com (rusi) Date: Tue, 17 Sep 2013 07:55:30 -0700 (PDT) Subject: Python GUI? In-Reply-To: References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> Message-ID: <63de767b-1df3-4981-b86e-dbf8fa10c9e0@googlegroups.com> On Thursday, September 12, 2013 10:21:49 PM UTC+5:30, Benjamin Kaplan wrote: > The main difference between wx and qt is that qt looks native on every platform > while wx *is* native on every platform (it uses native controls wherever > possible). This means that wx integrates into the OS better, but your also more > likely to need OS-specific tweaks in wx, at least from my experience from a few > years ago. For someone who is GUI-challenged, can you please expand on that a bit? From benjamin.kaplan at case.edu Tue Sep 17 12:19:28 2013 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 17 Sep 2013 09:19:28 -0700 Subject: Python GUI? In-Reply-To: <63de767b-1df3-4981-b86e-dbf8fa10c9e0@googlegroups.com> References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> <63de767b-1df3-4981-b86e-dbf8fa10c9e0@googlegroups.com> Message-ID: On Tue, Sep 17, 2013 at 7:55 AM, rusi wrote: > On Thursday, September 12, 2013 10:21:49 PM UTC+5:30, Benjamin Kaplan wrote: > >> The main difference between wx and qt is that qt looks native on every platform >> while wx *is* native on every platform (it uses native controls wherever >> possible). This means that wx integrates into the OS better, but your also more >> likely to need OS-specific tweaks in wx, at least from my experience from a few >> years ago. > > For someone who is GUI-challenged, can you please expand on that a bit? > -- Sure. Every platform provides its own GUI library (Cocoa on Mac OS X, Win32 on Windows). Other programs that want to hook into yours, such as screen readers, are familiar with the platform's native GUI elements- it knows what a Win32 combo box is, and it knows how to read the text inside it. The other way to make a GUI is to take a blank canvas and draw on it yourself. This is more flexible and provides a more consistent experience across platforms, but unless you specifically go out of your way to provide hooks for other programs to jump in, all they see is a bunch of pixels on the screen. In addition, drawing your own stuff won't necessarily give you the "normal for the operating system" behavior on other things, like tab behavior. It's possible for non-native GUI environments to mimic this behavior (and QT does a pretty good job of this), but there's always going to be little things that seem a bit off. The situation is a bit more complicated because QT is the native toolkit on KDE, so in that environment, QT will be more "correct" than wx, which would be using GTK if present and plain X11 if it isn't. From torriem at gmail.com Wed Sep 18 16:10:12 2013 From: torriem at gmail.com (Michael Torrie) Date: Wed, 18 Sep 2013 14:10:12 -0600 Subject: Python GUI? In-Reply-To: References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> <63de767b-1df3-4981-b86e-dbf8fa10c9e0@googlegroups.com> Message-ID: <523A08A4.50202@gmail.com> On 09/17/2013 10:19 AM, Benjamin Kaplan wrote: > Sure. Every platform provides its own GUI library (Cocoa on Mac OS X, > Win32 on Windows). Other programs that want to hook into yours, such > as screen readers, are familiar with the platform's native GUI > elements- it knows what a Win32 combo box is, and it knows how to read > the text inside it. > > The other way to make a GUI is to take a blank canvas and draw on it > yourself. This is more flexible and provides a more consistent > experience across platforms, but unless you specifically go out of > your way to provide hooks for other programs to jump in, all they see > is a bunch of pixels on the screen. In addition, drawing your own > stuff won't necessarily give you the "normal for the operating system" > behavior on other things, like tab behavior. It's possible for > non-native GUI environments to mimic this behavior (and QT does a > pretty good job of this), but there's always going to be little things > that seem a bit off. > > The situation is a bit more complicated because QT is the native > toolkit on KDE, so in that environment, QT will be more "correct" than > wx, which would be using GTK if present and plain X11 if it isn't. I don't think the distinction you're drawing is really all that important. Almost all platforms now have accessibility APIs which are a way better way to go than relying than trying to scrape the information by peaking into GUI structures that could change. And on Windows, while the Win32 widget stuff you speak of is a lowest common denominator, few modern apps use it directly anymore. MS Office set the the example early on by creating a new widget set for every release (using the blank canvas method you describe!). .Net apps using winforms use yet another widget set. They all now use the theming API to draw their widgets (just like Qt does on Windows), but do their own even processing, etc. And it turns out that wxWidget's use of the old win32 widgets means that some widgets just look plain old and out of place on a new Windows 7 or 8 machine, though MS has tried to make the older widgets work better with the new theming api: http://wiki.wxwidgets.org/WxFAQ#Why_does_my_app_take_a_Windows-95-like_look_on_Windows_.3F My point is, the former method isn't actually the best way to go in the long run. The second turns out to work out better, once things like accessibility frameworks and theming apis are in place. Perhaps in the future MS Windows will just provide a drawing method and a theming api. From rustompmody at gmail.com Tue Sep 17 12:51:50 2013 From: rustompmody at gmail.com (rusi) Date: Tue, 17 Sep 2013 09:51:50 -0700 (PDT) Subject: Python GUI? In-Reply-To: References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> <63de767b-1df3-4981-b86e-dbf8fa10c9e0@googlegroups.com> Message-ID: On Tuesday, September 17, 2013 9:49:28 PM UTC+5:30, Benjamin Kaplan wrote: > On Tue, Sep 17, 2013 at 7:55 AM, rusi wrote: > > > On Thursday, September 12, 2013 10:21:49 PM UTC+5:30, Benjamin Kaplan wrote: > > > > >> The main difference between wx and qt is that qt looks native on every platform > >> while wx *is* native on every platform (it uses native controls wherever > >> possible). This means that wx integrates into the OS better, but your also more > >> likely to need OS-specific tweaks in wx, at least from my experience from a few > >> years ago. > > > > For someone who is GUI-challenged, can you please expand on that a bit? > > -- > > Sure. Every platform provides its own GUI library (Cocoa on Mac OS X, > Win32 on Windows). Other programs that want to hook into yours, such > as screen readers, are familiar with the platform's native GUI > elements- it knows what a Win32 combo box is, and it knows how to read > the text inside it. > > > The other way to make a GUI is to take a blank canvas and draw on it > yourself. This is more flexible and provides a more consistent > experience across platforms, but unless you specifically go out of > your way to provide hooks for other programs to jump in, all they see > is a bunch of pixels on the screen. In addition, drawing your own > stuff won't necessarily give you the "normal for the operating system" > behavior on other things, like tab behavior. It's possible for > non-native GUI environments to mimic this behavior (and QT does a > pretty good job of this), but there's always going to be little things > that seem a bit off. Thanks for the explanation. However I am not able to square it up: You seem to be saying that QT draws on a blank canvas rather than calling out to the OS library. You also seem to be saying that QT (for the most part) Does the Right Thing for each platform. From benjamin.kaplan at case.edu Tue Sep 17 13:57:26 2013 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 17 Sep 2013 10:57:26 -0700 Subject: Python GUI? In-Reply-To: References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> <63de767b-1df3-4981-b86e-dbf8fa10c9e0@googlegroups.com> Message-ID: On Tue, Sep 17, 2013 at 9:51 AM, rusi wrote: > On Tuesday, September 17, 2013 9:49:28 PM UTC+5:30, Benjamin Kaplan wrote: >> On Tue, Sep 17, 2013 at 7:55 AM, rusi wrote: >> >> > On Thursday, September 12, 2013 10:21:49 PM UTC+5:30, Benjamin Kaplan wrote: >> >> > >> >> The main difference between wx and qt is that qt looks native on every platform >> >> while wx *is* native on every platform (it uses native controls wherever >> >> possible). This means that wx integrates into the OS better, but your also more >> >> likely to need OS-specific tweaks in wx, at least from my experience from a few >> >> years ago. >> > >> > For someone who is GUI-challenged, can you please expand on that a bit? >> > -- >> >> Sure. Every platform provides its own GUI library (Cocoa on Mac OS X, >> Win32 on Windows). Other programs that want to hook into yours, such >> as screen readers, are familiar with the platform's native GUI >> elements- it knows what a Win32 combo box is, and it knows how to read >> the text inside it. >> >> >> The other way to make a GUI is to take a blank canvas and draw on it >> yourself. This is more flexible and provides a more consistent >> experience across platforms, but unless you specifically go out of >> your way to provide hooks for other programs to jump in, all they see >> is a bunch of pixels on the screen. In addition, drawing your own >> stuff won't necessarily give you the "normal for the operating system" >> behavior on other things, like tab behavior. It's possible for >> non-native GUI environments to mimic this behavior (and QT does a >> pretty good job of this), but there's always going to be little things >> that seem a bit off. > > Thanks for the explanation. However I am not able to square it up: > > You seem to be saying that QT draws on a blank canvas rather than calling out to the OS library. > You also seem to be saying that QT (for the most part) Does the Right Thing for each platform. > -- Right. The QT developers have been working for years to get their controls to quack like the native ones, even though they aren't native. They started from controls that looked and worked the same on all platforms and have been trying to get them to play nicely with the environment they're running in. wx has been working from the opposite direction- they started with wrapping the native API and have been working on getting their API to make programs come out the same even when using different underlying toolkits. When I used wx about 5 years ago, some of the layout got messed up when we first ran the program (developed on Linux/GTK+) on a Mac because of some differences between how Carbon and GTK+ draw their controls. From davecook at nowhere.net Thu Sep 12 14:35:09 2013 From: davecook at nowhere.net (Dave Cook) Date: 12 Sep 2013 18:35:09 GMT Subject: Python GUI? References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> Message-ID: <5232095d$0$51478$c3e8da3$eb767761@news.astraweb.com> On 2013-09-12, Michael Torrie wrote: > Not me. wxWidgets' event model is way too MFC-esque for me. Does it > still use event numbers that you define? Shudder. You don't have to define IDs explicitly. That's been the case for a long time. > Gtk and Qt's method of signals and slots is by far the most powerful and > flexible. wxPython's event manager adds some flexibility. Dave Cook From malaclypse2 at gmail.com Thu Sep 12 13:09:58 2013 From: malaclypse2 at gmail.com (Jerry Hill) Date: Thu, 12 Sep 2013 13:09:58 -0400 Subject: Python GUI? In-Reply-To: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> Message-ID: On Wed, Sep 11, 2013 at 4:55 PM, wrote: > Have you got anything to say on what one I should be using(excluding PyQT because it has a D&D designer >:( )? Is Tkinter really dead? Should I stick with wxPython? If that's a reason for excluding a GUI toolkit, you're in trouble. Drag and drop layout tools exist for all of your proposed systems. -- Jerry From ian at feete.org Thu Sep 12 16:17:17 2013 From: ian at feete.org (Ian Foote) Date: Thu, 12 Sep 2013 21:17:17 +0100 Subject: Python GUI? In-Reply-To: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> Message-ID: <5232214D.8000206@feete.org> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 11/09/13 21:55, eamonnrea at gmail.com wrote: > There are a few known GUI toolkits out there, and the main ones > from what I can tell are: > > Tkinter -- Simple to use, but limited PyQT -- You have a GUI > designer, so I'm not going to count that PyGTK -- Gnome officially > back this I think wxPython -- Very nice, very professional, > approved by Python creator, but alas hard to get started with > > So, what are your personal preferences and why? Why use X over Y? > > I, personally, really like wxPython, but I also really like > Tkinter. I've messed with PyGTK, but I'd choose wxPython over it. > > Have you got anything to say on what one I should be > using(excluding PyQT because it has a D&D designer >:( )? Is > Tkinter really dead? Should I stick with wxPython? > > It's might be similar to the "What language to use" argument, or > the "What background to code on" argument(I prefer darker > backgrounds xD Please don't argue about this though!), in the sense > that there is *no* answer, just preference. > > Also, with wxPython, it has kind of a "flow" layout like JFrame, > whereas it will adjust it's layout to look like a native Mac App, > Windows app or Linux App, correct? It'll look almost identical, > right? Not that it matters, I'm just curious! :D > > Thanks! > Another GUI toolkit is kivy (kivy.org). It has a focus on supporting a wide range of platforms, including Android and IOs, and various input devices (mouse, keyboard, touchscreen, etc). Kivy is in active development and I think is well worth a look. Regards, Ian F -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJSMiFNAAoJEODsV4MF7PWzOsAH/3hidUN4pNxDG5ox2hNmfFkz g8D+hhXz/zKC+MpEh2iEm9G9NhaxoSTLQkcsUs5bxL9MvIQ0TYy68/vbQddRA52I GN0ofz8+E5h7MX57wegE/uxv0N9+CjdpWfwOfESoR5TXGUD8tr9ONEKAENLvod3W JUgU0KvN410J8+2yxI+LKpqezW3hNr43VoUO4zEmRgCm6KEK6wdKdooI5j45tb9r HW7vZgd12RCzE4XMVSBRl20xcYB9isi9erP7UnTCep8FUQKV0XxdnXY00rEBPQEm 7hgh66dIX5c2SC3fPgiYHFA7fSv7x4hrCJcokr+z5LEfdzRInra01tqnQLxnA+Q= =uPwE -----END PGP SIGNATURE----- From peter.milliken at gmail.com Thu Sep 12 23:39:05 2013 From: peter.milliken at gmail.com (Peter) Date: Thu, 12 Sep 2013 20:39:05 -0700 (PDT) Subject: Python GUI? In-Reply-To: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> Message-ID: I stuck with Tkinter combined with PMW for a very long time, but the lack of extra widgets finally drove me to look elsewhere. I tried PyQT but didn't have a good experience. I can't remember details, but things just seemed to have little "gotchas" - which the mailing list were very helpful with sorting out, but I found it frustrating to keep asking for help over little items of unexpected behaviour. I have not tried PyGTK so cannot comment. I finally decided on wxPython - with my basis of Tkinter (graysons book) it was quite easy to pick up and run with. The wxPython book is quite good and helps get started and using it. I would suggest if you buy and read that, then you will no longer find wxPython difficult to get started with. From torriem at gmail.com Fri Sep 13 00:15:16 2013 From: torriem at gmail.com (Michael Torrie) Date: Thu, 12 Sep 2013 22:15:16 -0600 Subject: Python GUI? In-Reply-To: References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> Message-ID: <52329154.6010903@gmail.com> On 09/12/2013 09:39 PM, Peter wrote: > I stuck with Tkinter combined with PMW for a very long time, but the > lack of extra widgets finally drove me to look elsewhere. > > I tried PyQT but didn't have a good experience. I can't remember > details, but things just seemed to have little "gotchas" - which the > mailing list were very helpful with sorting out, but I found it > frustrating to keep asking for help over little items of unexpected > behaviour. Interesting. I have used Qt and PyQt, and except for the fact that PyQt isn't very pythonic (feels like C++ translated directly to Python), I never had any problems with it. Maybe since I was already familiar with signals and slots programming I never found any unexpected behavior[1]. I've never used Tkinter, and I only ever used wxWidgets once (back when it was called wxWindows), and the close similarity to MFC at the time (which I was fleeing) didn't sit right with me. Also the flexible layout that Qt and Gtk encouraged was a big plus in my mind. I guess you like what you get used to. From cmpython at gmail.com Fri Sep 13 01:14:37 2013 From: cmpython at gmail.com (CM) Date: Thu, 12 Sep 2013 22:14:37 -0700 (PDT) Subject: Python GUI? In-Reply-To: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> Message-ID: <6cbe30ed-595b-4a61-abaf-83aaa8ff9090@googlegroups.com> > Tkinter -- Simple to use, but limited > > PyQT -- You have a GUI designer, so I'm not going to count that As others have pointed out, that's nonsensical. If you don't like the GUI designer, just don't use it. > wxPython -- Very nice, very professional, approved by Python creator, but alas hard to get started with Why is it hard to get started with? Download the installer, install, and: import wx app = wx.App(False) frame = wx.Frame(None, -1, "Hello World") frame.Show(True) app.MainLoop() From kw at codebykevin.com Fri Sep 13 09:27:56 2013 From: kw at codebykevin.com (Kevin Walzer) Date: Fri, 13 Sep 2013 09:27:56 -0400 Subject: Python GUI? In-Reply-To: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> Message-ID: On 9/11/13 4:55 PM, eamonnrea at gmail.com wrote: > Tkinter -- Simple to use, but limited With the themed widget introduced in Tk 8.5, Tkinter is now a peer to the other GUI toolkits in most respects, surpasses them in some (canvas widget), and lags behind in just two areas: printing (several platform-specific solutions but no cross-platform API) and HTML display (a few extensions but no standard widget set). I've stayed with Tkinter because it fits my brain the best. Old complaints about it being ugly or limited no longer hold water. --Kevin -- Kevin Walzer Code by Kevin/Mobile Code by Kevin http://www.codebykevin.com http://www.wtmobilesoftware.com From tjreedy at udel.edu Fri Sep 13 15:47:00 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 13 Sep 2013 15:47:00 -0400 Subject: Python GUI? In-Reply-To: References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> Message-ID: On 9/13/2013 9:27 AM, Kevin Walzer wrote: > On 9/11/13 4:55 PM, eamonnrea at gmail.com wrote: >> Tkinter -- Simple to use, but limited > > With the themed widget introduced in Tk 8.5, Tkinter is now a peer to > the other GUI toolkits in most respects, surpasses them in some (canvas > widget), and lags behind in just two areas: printing (several > platform-specific solutions but no cross-platform API) and HTML display > (a few extensions but no standard widget set). I would add the ancient and limited image support, both for input and canvas output. Modern SVG output instead of ancient (possibly buggy) PostScript would be a real improvement. Otherwise, I have become more impressed with the text widget as I have studied the Idle code. Even that does not use everything. I have not looked at the text widget in other guis to compare. -- Terry Jan Reedy From eamonnrea at gmail.com Fri Sep 13 13:31:17 2013 From: eamonnrea at gmail.com (eamonnrea at gmail.com) Date: Fri, 13 Sep 2013 10:31:17 -0700 (PDT) Subject: Python GUI? In-Reply-To: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> Message-ID: <76784bad-cd6d-48f9-b358-54afb2784f11@googlegroups.com> I don't like the idea of being able to drag and drop anything in the programming world. Outside of that, I use D&D programs a lot. I got into GUI programming because I thought that I could get away from them, but I guess not. Maybe I'm against them because if I can't code, I don't have anything else to do with my time. If I don't program, the only other thing I have to do is... well... nothing. So, because of this, they're making programming easier... by not coding as much. Oh well, guess coding is dead :( From gordon at panix.com Fri Sep 13 14:39:19 2013 From: gordon at panix.com (John Gordon) Date: Fri, 13 Sep 2013 18:39:19 +0000 (UTC) Subject: Python GUI? References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> <76784bad-cd6d-48f9-b358-54afb2784f11@googlegroups.com> Message-ID: In <76784bad-cd6d-48f9-b358-54afb2784f11 at googlegroups.com> eamonnrea at gmail.com writes: > they're making programming easier... by not coding as much. Oh well, > guess coding is dead :( Pressing keys on a keyboard was never the hard part of coding. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From joe.fbs.junior at gmail.com Fri Sep 13 14:49:43 2013 From: joe.fbs.junior at gmail.com (Joe Junior) Date: Fri, 13 Sep 2013 15:49:43 -0300 Subject: Python GUI? In-Reply-To: References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> <76784bad-cd6d-48f9-b358-54afb2784f11@googlegroups.com> Message-ID: On 13 September 2013 15:39, John Gordon wrote: > In <76784bad-cd6d-48f9-b358-54afb2784f11 at googlegroups.com> eamonnrea at gmail.com writes: > >> they're making programming easier... by not coding as much. Oh well, >> guess coding is dead :( > > Pressing keys on a keyboard was never the hard part of coding. > Nor the fun part. Joe From eamonnrea at gmail.com Fri Sep 13 15:37:03 2013 From: eamonnrea at gmail.com (eamonnrea at gmail.com) Date: Fri, 13 Sep 2013 12:37:03 -0700 (PDT) Subject: Python GUI? In-Reply-To: References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> <76784bad-cd6d-48f9-b358-54afb2784f11@googlegroups.com> Message-ID: I disagree with you. It's not hard, and I apologise if its ever sounded that way, but it is the fun part for me. I love spending hours(days even) debugging. Well, thanks all for depressing me. Time to give up programming and find something else to do with my life. From joe.fbs.junior at gmail.com Fri Sep 13 15:50:13 2013 From: joe.fbs.junior at gmail.com (Joe Junior) Date: Fri, 13 Sep 2013 16:50:13 -0300 Subject: Python GUI? In-Reply-To: References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> <76784bad-cd6d-48f9-b358-54afb2784f11@googlegroups.com> Message-ID: On 13 September 2013 16:37, wrote: > I disagree with you. It's not hard, and I apologise if its ever sounded that way, but it is the fun part for me. I love spending hours(days even) debugging. > > Well, thanks all for depressing me. Time to give up programming and find something else to do with my life. > -- > https://mail.python.org/mailman/listinfo/python-list lol! You made my day. :-D Well, you can always ignore any and all graphical design tools if you're working alone. And write all those Xs and Ys and widths and heights all day long. None of the mentioned graphical toolkits forces you to use them. And if you like debugging, GUI is not the main dish! Try networking and concurrent programming, loads and loads of fun! Of course, that's lots of other unnecessary time consuming stuff you can do. You just have to use your imagination. Joe From eamonnrea at gmail.com Fri Sep 13 16:40:45 2013 From: eamonnrea at gmail.com (eamonnrea at gmail.com) Date: Fri, 13 Sep 2013 13:40:45 -0700 (PDT) Subject: Python GUI? In-Reply-To: References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> <76784bad-cd6d-48f9-b358-54afb2784f11@googlegroups.com> Message-ID: <36e6997f-fd5b-4456-97a4-16384cfe0289@googlegroups.com> On Friday, September 13, 2013 8:50:13 PM UTC+1, Joe Junior wrote: > On 13 September 2013 16:37, wrote: > > > I disagree with you. It's not hard, and I apologise if its ever sounded that way, but it is the fun part for me. I love spending hours(days even) debugging. > > > > > > Well, thanks all for depressing me. Time to give up programming and find something else to do with my life. > > > -- > > > https://mail.python.org/mailman/listinfo/python-list > > > > lol! You made my day. :-D > > > > Well, you can always ignore any and all graphical design tools if > > you're working alone. And write all those Xs and Ys and widths and > > heights all day long. None of the mentioned graphical toolkits forces > > you to use them. > > > > And if you like debugging, GUI is not the main dish! Try networking > > and concurrent programming, loads and loads of fun! > > > > Of course, that's lots of other unnecessary time consuming stuff you > > can do. You just have to use your imagination. > > > > Joe I was planning on getting into networking, but like I said, thanks to most people encouraging less coding, I don't code anymore. Glad I made your day though. :-) And "unnecessary time consuming stuff" -- That's my problem. Is *shouldn't* be unnecessary! It should be something that has to be done. That's what annoys me!! From steve+comp.lang.python at pearwood.info Fri Sep 13 20:21:55 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Sep 2013 00:21:55 GMT Subject: Python GUI? References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> <76784bad-cd6d-48f9-b358-54afb2784f11@googlegroups.com> Message-ID: <5233ac22$0$29988$c3e8da3$5496439d@news.astraweb.com> On Fri, 13 Sep 2013 12:37:03 -0700, eamonnrea wrote: > I disagree with you. It's not hard, and I apologise if its ever sounded > that way, but it is the fun part for me. I love spending hours(days > even) debugging. > > Well, thanks all for depressing me. Time to give up programming and find > something else to do with my life. What on earth are you talking about? If you like cutting trees down with an axe, the existence of chainsaws doesn't stop you from still using an axe. If you don't like GUI app builders, don't use one. -- Steven From eamonnrea at gmail.com Fri Sep 13 20:38:50 2013 From: eamonnrea at gmail.com (eamonnrea at gmail.com) Date: Fri, 13 Sep 2013 17:38:50 -0700 (PDT) Subject: Python GUI? In-Reply-To: <5233ac22$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> <76784bad-cd6d-48f9-b358-54afb2784f11@googlegroups.com> <5233ac22$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <13ae937d-65ad-4cf7-9f20-58c10ef96b78@googlegroups.com> But is it efficient to use an axe? Is it sensible to use an axe when there is a chainsaw? No. Eventually, everyone will be using chainsaws, and no one will be using axes. This is my point: to have fun and be productive, but apparently it's not possible. From ben+python at benfinney.id.au Fri Sep 13 21:23:03 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 14 Sep 2013 11:23:03 +1000 Subject: Python GUI? References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> <76784bad-cd6d-48f9-b358-54afb2784f11@googlegroups.com> <5233ac22$0$29988$c3e8da3$5496439d@news.astraweb.com> <13ae937d-65ad-4cf7-9f20-58c10ef96b78@googlegroups.com> Message-ID: <7wtxhoyz60.fsf@benfinney.id.au> eamonnrea at gmail.com writes: > But is it efficient to use an axe? Which criterion is more important to *you* ? fun, or efficiency? > Is it sensible to use an axe when there is a chainsaw? No. Which criterion is more important to *you* ? fun, or sensibility? > Eventually, everyone will be using chainsaws, and no one will be using > axes. Which criterion is more important to *you* ? fun, or popularity? > This is my point: to have fun and be productive, but apparently it's > not possible. Who has said that's not possible? If you find using a tool to be both fun and productive, use it and be happy. If not, use something else. -- \ ?They can not take away our self respect if we do not give it | `\ to them.? ?Mohandas Gandhi | _o__) | Ben Finney From eamonnrea at gmail.com Sat Sep 14 07:54:43 2013 From: eamonnrea at gmail.com (eamonnrea at gmail.com) Date: Sat, 14 Sep 2013 04:54:43 -0700 (PDT) Subject: Python GUI? In-Reply-To: References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> <76784bad-cd6d-48f9-b358-54afb2784f11@googlegroups.com> <5233ac22$0$29988$c3e8da3$5496439d@news.astraweb.com> <13ae937d-65ad-4cf7-9f20-58c10ef96b78@googlegroups.com> Message-ID: On Saturday, September 14, 2013 2:23:03 AM UTC+1, Ben Finney wrote: > eamonnrea at gmail.com writes: > > > > > But is it efficient to use an axe? > > > > Which criterion is more important to *you* ? fun, or efficiency? > > > > > Is it sensible to use an axe when there is a chainsaw? No. > > > > Which criterion is more important to *you* ? fun, or sensibility? > > > > > Eventually, everyone will be using chainsaws, and no one will be using > > > axes. > > > > Which criterion is more important to *you* ? fun, or popularity? > > > > > This is my point: to have fun and be productive, but apparently it's > > > not possible. > > > > Who has said that's not possible? If you find using a tool to be both > > fun and productive, use it and be happy. If not, use something else. > > > > -- > > \ ?They can not take away our self respect if we do not give it | > > `\ to them.? ?Mohandas Gandhi | > > _o__) | > > Ben Finney I hadn't thought of it that way! Thanks! :) I suppose it's like saying "Why use a MacBook when you could use X computer instead? Because I prefer Macs". Also, this thread hasn't been a troll. I'm completely serious. Why is it when I ask things like this people think I'm trolling?? :( From rosuav at gmail.com Sat Sep 14 08:07:30 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 14 Sep 2013 22:07:30 +1000 Subject: Python GUI? In-Reply-To: References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> <76784bad-cd6d-48f9-b358-54afb2784f11@googlegroups.com> <5233ac22$0$29988$c3e8da3$5496439d@news.astraweb.com> <13ae937d-65ad-4cf7-9f20-58c10ef96b78@googlegroups.com> Message-ID: On Sat, Sep 14, 2013 at 9:54 PM, wrote: > Also, this thread hasn't been a troll. I'm completely serious. Why is it when I ask things like this people think I'm trolling?? :( This is python-list. We're used to duck-typing. If it looks like a file, we can write to it... if it looks like a troll, we can "throw eggs" to try to get it to move away from the rickety bridge, then type "fee; fie; foe; foo" to get the eggs back. Hmm. Am I showing my age, or my nerdiness? ChrisA From davea at davea.name Fri Sep 13 22:05:41 2013 From: davea at davea.name (Dave Angel) Date: Sat, 14 Sep 2013 02:05:41 +0000 (UTC) Subject: Python GUI? References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> <76784bad-cd6d-48f9-b358-54afb2784f11@googlegroups.com> Message-ID: On 13/9/2013 15:37, eamonnrea at gmail.com wrote: > I disagree with you. It's not hard, and I apologise if its ever sounded that way, but it is the fun part for me. I love spending hours(days even) debugging. > > Well, thanks all for depressing me. Time to give up programming and find something else to do with my life. I expect that this thread has all been a troll, but on the off chance that I'm wrong... I spent 40+ years programming for various companies, and the only GUI programs I wrote were for my personal use. Many times I worked on processors that weren't even in existence yet, and wrote my own tools to deal with them. Other times, there were tools I didn't like, and I wrote my own to replace them. One example of that is the keypunch. Another is paper tape punch. I was really glad to stop dealing with either of those. Still other times, tools were great, and I used them with pleasure. If the tool was flexible, I extended it. And if it was limited, I replaced it, or found a replacement. Many times I've chosen a particular approach to solving a problem mainly because it was something I hadn't done before. On one project, I wrote code whose job was to generate about 40,000 lines of C++ code that I didn't feel like typing in, and maintaining afterward. The data that described what those lines should look like was under the control of another (very large) company, and they could change it any time they liked. Most changes "just worked." If you seriously can't find anything interesting to do in software, and tools to do it with, then maybe you should take up fishing. With a bamboo pole and a piece of string. -- DaveA From neilc at norwich.edu Fri Sep 13 15:56:15 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 13 Sep 2013 19:56:15 GMT Subject: Python GUI? References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> <76784bad-cd6d-48f9-b358-54afb2784f11@googlegroups.com> Message-ID: On 2013-09-13, Joe Junior wrote: > On 13 September 2013 15:39, John Gordon wrote: >> In <76784bad-cd6d-48f9-b358-54afb2784f11 at googlegroups.com> >> eamonnrea at gmail.com writes: >>> they're making programming easier... by not coding as much. >>> Oh well, guess coding is dead :( >> >> Pressing keys on a keyboard was never the hard part of coding. > > Nor the fun part. When John Henry was a little baby, Sittin' on his daddy's knee, He Telneted to the server with a tiny bit of code, and said: Emacs will be the death of me, Lord, Lord! Emacs will be the death of me. Well John Henry said to the captain: Go on and bring your toolkit round, I'll pound out your GUI with a hundred thousand keystrokes, And throw that GUI Builder down, Lord, Lord! I'll throw that GUI Builder down. Well John Henry hammered on his keyboard, Till is fingers were bloody stumps, And the very last words that were entered in his .blog were: GUI Builders are for chumps, Lord, Lord! Those GUI builders are for chumps. -- Neil Cerutti From eamonnrea at gmail.com Fri Sep 13 16:40:55 2013 From: eamonnrea at gmail.com (eamonnrea at gmail.com) Date: Fri, 13 Sep 2013 13:40:55 -0700 (PDT) Subject: Python GUI? In-Reply-To: References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> <76784bad-cd6d-48f9-b358-54afb2784f11@googlegroups.com> Message-ID: On Friday, September 13, 2013 8:56:15 PM UTC+1, Neil Cerutti wrote: > On 2013-09-13, Joe Junior wrote: > > > On 13 September 2013 15:39, John Gordon wrote: > > >> In <76784bad-cd6d-48f9-b358-54afb2784f11 at googlegroups.com> > > >> eamonnrea at gmail.com writes: > > >>> they're making programming easier... by not coding as much. > > >>> Oh well, guess coding is dead :( > > >> > > >> Pressing keys on a keyboard was never the hard part of coding. > > > > > > Nor the fun part. > > > > When John Henry was a little baby, > > Sittin' on his daddy's knee, > > He Telneted to the server with a tiny bit of code, and said: > > Emacs will be the death of me, Lord, Lord! > > Emacs will be the death of me. > > > > Well John Henry said to the captain: > > Go on and bring your toolkit round, > > I'll pound out your GUI with a hundred thousand keystrokes, > > And throw that GUI Builder down, Lord, Lord! > > I'll throw that GUI Builder down. > > > > Well John Henry hammered on his keyboard, > > Till is fingers were bloody stumps, > > And the very last words that were entered in his .blog were: > > GUI Builders are for chumps, Lord, Lord! > > Those GUI builders are for chumps. > > > > -- > > Neil Cerutti I don't fully understand the meaning of that, but that was a good poem! From llanitedave at veawb.coop Wed Sep 18 22:47:55 2013 From: llanitedave at veawb.coop (llanitedave) Date: Wed, 18 Sep 2013 19:47:55 -0700 (PDT) Subject: Python GUI? In-Reply-To: <76784bad-cd6d-48f9-b358-54afb2784f11@googlegroups.com> References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> <76784bad-cd6d-48f9-b358-54afb2784f11@googlegroups.com> Message-ID: <9b7fea33-9b33-4690-b0e1-39648b48b5e1@googlegroups.com> On Friday, September 13, 2013 10:31:17 AM UTC-7, Eamonn Rea wrote: > I don't like the idea of being able to drag and drop anything in the programming world. Outside of that, I use D&D programs a lot. I got into GUI programming because I thought that I could get away from them, but I guess not. > > > > Maybe I'm against them because if I can't code, I don't have anything else to do with my time. If I don't program, the only other thing I have to do is... well... nothing. So, because of this, they're making programming easier... by not coding as much. Oh well, guess coding is dead :( Why do you feel the need to project your personal issues onto the whole world? Nobody is forcing you to use Drag and Drop -- you simply have the option to do so, or not. I don't use it either, but I sure don't fill up with angst just because someone else might actually enjoy using it. From petmertens at gmail.com Fri Sep 13 13:51:39 2013 From: petmertens at gmail.com (petmertens at gmail.com) Date: Fri, 13 Sep 2013 10:51:39 -0700 (PDT) Subject: Python GUI? In-Reply-To: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> Message-ID: <1099959b-37fc-4ce2-8ded-78fc7609f3d3@googlegroups.com> Enthought.traits !! http://code.enthought.com/projects/traits/ I started using traits a couple of months ago and I really like it. Traits provides a framework which creates a UI based on your data structures. Using some "hints" you can do anything you want. Just check out their website and try the examples. Even creating an executable out of it is quite easy using bbfreeze. The "negative" thing about is that the user group doesn't seem to be very large. In other words: if you get stuck on something, there aren't many people to help you. This however should not prevent you from using traits. Just try it and let me know what you think about it. From metaliobovinus at gmail.com Fri Sep 20 14:34:23 2013 From: metaliobovinus at gmail.com (Metallicow) Date: Fri, 20 Sep 2013 11:34:23 -0700 (PDT) Subject: Python GUI? In-Reply-To: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> Message-ID: <47f5416e-bc22-465a-8c39-b9cbfc6bbf72@googlegroups.com> On Wednesday, September 11, 2013 3:55:59 PM UTC-5, Eamonn Rea wrote: > There are a few known GUI toolkits out there, and the main ones from what I can tell are: > > > > Tkinter -- Simple to use, but limited > > PyQT -- You have a GUI designer, so I'm not going to count that > > PyGTK -- Gnome officially back this I think > > wxPython -- Very nice, very professional, approved by Python creator, but alas hard to get started with > > > > So, what are your personal preferences and why? Why use X over Y? > > > > I, personally, really like wxPython, but I also really like Tkinter. I've messed with PyGTK, but I'd choose wxPython over it. > > > > Have you got anything to say on what one I should be using(excluding PyQT because it has a D&D designer >:( )? Is Tkinter really dead? Should I stick with wxPython? > > > > It's might be similar to the "What language to use" argument, or the "What background to code on" argument(I prefer darker backgrounds xD Please don't argue about this though!), in the sense that there is *no* answer, just preference. > I prefer wx over qt for these reasons. Robin works for qt now. *Funny isn't it...* Basically, To change qt(PySide) you need to pretty much need to be employed by qt, not the case with wx(is not a *For profit*, but you can donate.). In my opinion, in the long run(foreseeing from this point forward) wx will win, because anybody can create a popular fork. And if it is good enough, it might get accepted into the standard dist also. As far as "mature", well, the previous statement shows that he can make money doing it also and enjoy doing what he does in his spare time. I believe Guido has the privilege of spending half of his time "At work and getting paid for it." on python. And Project Phoenix(Py2/3) is still on the way. We'll revisit this question next year. From torriem at gmail.com Fri Sep 20 15:49:50 2013 From: torriem at gmail.com (Michael Torrie) Date: Fri, 20 Sep 2013 13:49:50 -0600 Subject: Python GUI? In-Reply-To: <47f5416e-bc22-465a-8c39-b9cbfc6bbf72@googlegroups.com> References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> <47f5416e-bc22-465a-8c39-b9cbfc6bbf72@googlegroups.com> Message-ID: <523CA6DE.8060701@gmail.com> On 09/20/2013 12:34 PM, Metallicow wrote: > I prefer wx over qt for these reasons. Robin works for qt now. *Funny > isn't it...* Basically, To change qt(PySide) you need to pretty much > need to be employed by qt, not the case with wx(is not a *For > profit*, but you can donate.). In my opinion, in the long > run(foreseeing from this point forward) wx will win, because anybody > can create a popular fork. And if it is good enough, it might get > accepted into the standard dist also. Qt is not a company. Qt is an open source project owned and sponsored by Digia and also Nokia, though Nokia's participation will probably be reduced now that Microsoft has bought Nokia. Two years ago, at least, lots of code commits came from outside Nokia. Now, PySide was originally a Nokia project when they owned Qt, and I know they did have contributions from the community. I don't see any evidence things have changed. Your logical reasoning is certainly faulty on one point, however. Why would you claim wx is forkable but PySide (or even Qt) is not? Both are completely open source and free software (as in LGPL). From metaliobovinus at gmail.com Fri Sep 20 15:58:14 2013 From: metaliobovinus at gmail.com (Metallicow) Date: Fri, 20 Sep 2013 12:58:14 -0700 (PDT) Subject: Python GUI? In-Reply-To: References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> <47f5416e-bc22-465a-8c39-b9cbfc6bbf72@googlegroups.com> Message-ID: <8c3ea55a-027d-451a-976d-de299949246a@googlegroups.com> Sorry about that, nokia is/was. qt was developed(IIRC) for phones. Someone made money. And a lot of it. wx is a more or less a "free" project. I don't use a phone anymore. If I had a touch screen phone and was a developer, I still wouldn't use one. I have my many reasons why... From torriem at gmail.com Fri Sep 20 18:49:48 2013 From: torriem at gmail.com (Michael Torrie) Date: Fri, 20 Sep 2013 16:49:48 -0600 Subject: Python GUI? In-Reply-To: <8c3ea55a-027d-451a-976d-de299949246a@googlegroups.com> References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> <47f5416e-bc22-465a-8c39-b9cbfc6bbf72@googlegroups.com> <8c3ea55a-027d-451a-976d-de299949246a@googlegroups.com> Message-ID: <523CD10C.6040308@gmail.com> On 09/20/2013 01:58 PM, Metallicow wrote: > Sorry about that, nokia is/was. qt was developed(IIRC) for phones. > Someone made money. And a lot of it. wx is a more or less a "free" > project. I don't use a phone anymore. If I had a touch screen phone > and was a developer, I still wouldn't use one. I have my many reasons > why... Qt was first available back in 1995 from TrollTech, Inc. Qt was always about a good cross-platform UI toolkit that made it possible to develop rich apps on Windows, Linux, and Mac. Qt was one of the very first modern GUI toolkits available on Linux. I used KDE 1.0, which was based on Qt back in 1998, long before cell phones with touch screens! In fact I owe the KDE and Qt developers a debt of gratitude because KDE 1.0 was really the first desktop that was usable to me as a Windows 95 refuge. Moved to Linux and haven't looked back. Qt only recently got touch stuff added, that make it work on phones and tablets. And the same touch stuff is going into GTK+, and I'm sure wx will get it too soon, if they want to stay relevant. And yes someone made money on Qt back in the day, as the company TrollTech developed and marketed the toolkit for many years. Back in the 90s, a dispute over the open source licensing of the Qt source code led to the creation of the Gnome project and desktop, using what became known as the Gtk+ library. Now, however, Qt is under the LGPL so it's both free and open source in every way, and we are essentially reaping the rewards of a very long and expensive development history, all for free! Whether it was generosity or desperation, it does not matter. So I'm guessing you don't use Linux either, since people including Linus Torvalds have become rich developing Linux. Most linux development and even governance is under the auspices of some for-profit companies. Yet it flourishes and has remained a free and open OS, thanks to Torvalds' foresight to choose the GPL as the license for the kernel, which evens the playing field and regulates the corporate influence. Sounds to me like you've never used Qt in any of its versions. I have used Qt, GTK+, and wx, and they are all fine toolkits. My current preference is GTK+. From robert.kern at gmail.com Fri Sep 20 19:34:26 2013 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 21 Sep 2013 00:34:26 +0100 Subject: Python GUI? In-Reply-To: <47f5416e-bc22-465a-8c39-b9cbfc6bbf72@googlegroups.com> References: <1a8b14b3-85f3-4515-ba43-9b40e1a89f1d@googlegroups.com> <47f5416e-bc22-465a-8c39-b9cbfc6bbf72@googlegroups.com> Message-ID: On 2013-09-20 19:34, Metallicow wrote: > I prefer wx over qt for these reasons. > Robin works for qt now. *Funny isn't it...* Lying about someone's employment is not very funny. Robin does not work for "Qt" or even Digia, the nearest thing to a corporate "owner" of Qt these days. https://www.enthought.com/company/team/devs/ > Basically, To change qt(PySide) you need to pretty much need to be employed by qt, This is emphatically incorrect, by your own example. Robin does indeed contribute to the PySide project. Both Qt and PySide are both open to and *driven by* contributions from the community. http://qt-project.org/contribute http://qt-project.org/wiki/PySideContributors -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From cmottice at gmail.com Wed Sep 11 23:03:10 2013 From: cmottice at gmail.com (Cory Mottice) Date: Wed, 11 Sep 2013 20:03:10 -0700 (PDT) Subject: Parsing an html line and pulling out only numbers that meet a certain criteria Message-ID: I am using line.rfind to parse a particular line of html code. For example, this is the line of html code I am parsing: 79°Lo 56° and this is the code I use to split the line to (in this case) pull out the '79'. position0 = line.rfind('{}'.format(date1.strftime("%a"))) if position0 > 0 : self.high0 = lines[line_number + 4].split('')[0].split('">')[-1] Now I need to only pull out that number if it is >=94 and <=37. If it does not meet this criteria, I don't want anything to happen. Any ideas? Thank you in advance! From gordon at panix.com Thu Sep 12 01:40:12 2013 From: gordon at panix.com (John Gordon) Date: Thu, 12 Sep 2013 05:40:12 +0000 (UTC) Subject: Parsing an html line and pulling out only numbers that meet a certain criteria References: Message-ID: In Cory Mottice writes: > I am using line.rfind to parse a particular line of html code. For example, this is the line of html code I am parsing: > 79°Lo 56° > and this is the code I use to split the line to (in this case) pull out the '79'. > position0 = line.rfind('{}'.format(date1.strftime("%a"))) > if position0 > 0 : > self.high0 = lines[line_number + 4].split('')[0].split('">')[-1] > Now I need to only pull out that number if it is >=94 and <=37. If it > does not meet this criteria, I don't want anything to happen. Any ideas? > Thank you in advance! If you have the string value in a variable, you can call int() to convert it to an integer, like so: x = "57" # string value y = int(x) # integer value But what do you mean by you "don't want anything to happen"? Obviously you have to do the work of grabbing the correct part of the line and parsing it to an integer value; you can't magically undo that work if the value isn't in the desired range. Do you mean that you don't want to assign it to self.high0? That's easy; assign it to a temporary variable first, and only assign it to self.high0 if it falls in the desired range. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From davea at davea.name Thu Sep 12 06:36:24 2013 From: davea at davea.name (Dave Angel) Date: Thu, 12 Sep 2013 10:36:24 +0000 (UTC) Subject: Parsing an html line and pulling out only numbers that meet a certain criteria References: Message-ID: On 11/9/2013 23:03, Cory Mottice wrote: > I am using line.rfind to parse a particular line of html code. For example, this is the line of html code I am parsing: > > 79°Lo 56° > > and this is the code I use to split the line to (in this case) pull out the '79'. > > position0 = line.rfind('{}'.format(date1.strftime("%a"))) > if position0 > 0 : > self.high0 = lines[line_number + 4].split('')[0].split('">')[-1] > > Now I need to only pull out that number if it is >=94 and <=37. If it does not meet this criteria, I don't want anything to happen. Any ideas? Thank you in advance! Since no integer is both >=94 and <=37, you'd never have to worry about it. But assuming there's a typo there, temp = lines[line_number + 4......... if 94 <= int(temp) <= 37: self.high0 = temp -- DaveA From chandan_psr at yahoo.co.in Thu Sep 12 02:15:47 2013 From: chandan_psr at yahoo.co.in (chandan kumar) Date: Thu, 12 Sep 2013 14:15:47 +0800 (SGT) Subject: Accessing class attribute Message-ID: <1378966547.35546.YahooMailBasic@web190504.mail.sg3.yahoo.com> Hi , I'm new to python ,please correct me if there is any thing wrong with the way accessing class attributes. Please see the below code .I have inherited confid in ExpectId class, changed self.print_msg to Hello. Now inherited confid in TestprintmsgID class.Now I wanted to print self.print_msg value (which is changed under ExpectId class) as Hello under TestprintmsgID. I end up with error saying TestprintmsgID has no attribute self.print_msg. Atleast i expect the null to be printed. class confid(): def __init__(self): self.print_msg = "" class ExpectId(confid): def __init__(self): self.print_msg = " Hello" def expectmethod(self): print "self.print_mesg = ",self.print_msg class TestprintmsgID(confid): def __init__(self): "Created Instance" def printmsgmethod(self): print "printmsgmethod print_msg val = ",self.print_msg---- Here is the Attribute error if __name__ == '__main__': ins1 =ExpectId() ins1.expectmethod() ins2 = TestprintmsgID() ins2.printmsgmethod() Best Regards, Chandan From __peter__ at web.de Thu Sep 12 02:45:21 2013 From: __peter__ at web.de (Peter Otten) Date: Thu, 12 Sep 2013 08:45:21 +0200 Subject: Accessing class attribute References: <1378966547.35546.YahooMailBasic@web190504.mail.sg3.yahoo.com> Message-ID: chandan kumar wrote: > Hi , > > I'm new to python ,please correct me if there is any thing wrong with the > way accessing class attributes. > > Please see the below code .I have inherited confid in ExpectId class, > changed self.print_msg to Hello. Now inherited confid in TestprintmsgID > class.Now I wanted to print self.print_msg value (which is changed under > ExpectId class) as Hello under TestprintmsgID. I end up with error saying > TestprintmsgID has no attribute self.print_msg. Atleast i expect the null > to be printed. > > > > class confid(): > def __init__(self): > self.print_msg = "" > > class ExpectId(confid): > > def __init__(self): > self.print_msg = " Hello" > > def expectmethod(self): > print "self.print_mesg = ",self.print_msg > > class TestprintmsgID(confid): > > def __init__(self): > "Created Instance" > > def printmsgmethod(self): > print "printmsgmethod print_msg val = ",self.print_msg---- Here is > the Attribute error If the class has an __init__() method the initializer of the base class is not invoked automatically. In the above code the initializer of TestprintmsgId does nothing, so you can avoid it. ExpectId.__init__() however must invoke confid.__init_(). The complete example: class confid(): def __init__(self): self.print_msg = "" class ExpectId(confid): def __init__(self): confid.__init__(self) self.print_msg = " Hello" def expectmethod(self): print "self.print_mesg = ",self.print_msg class TestprintmsgID(confid): def printmsgmethod(self): print "printmsgmethod print_msg val = ",self.print_msg Note that there is an alternative way to invoke a baseclass method using super() which works only for "newstyle classes", i. e. classes that inherit from object: class confid(object): def __init__(self): self.print_msg = "" class ExpectId(confid): def __init__(self): super(ExpectId, self).__init__() self.print_msg = " Hello" def expectmethod(self): print "self.print_mesg = ",self.print_msg class TestprintmsgID(confid): def printmsgmethod(self): print "printmsgmethod print_msg val = ",self.print_msg From __peter__ at web.de Thu Sep 12 03:04:26 2013 From: __peter__ at web.de (Peter Otten) Date: Thu, 12 Sep 2013 09:04:26 +0200 Subject: Accessing class attribute References: <1378966547.35546.YahooMailBasic@web190504.mail.sg3.yahoo.com> Message-ID: Peter Otten wrote: > chandan kumar wrote: > >> Hi , >> >> I'm new to python ,please correct me if there is any thing wrong with the >> way accessing class attributes. >> >> Please see the below code .I have inherited confid in ExpectId class, >> changed self.print_msg to Hello. Now inherited confid in TestprintmsgID >> class.Now I wanted to print self.print_msg value (which is changed under >> ExpectId class) as Hello under TestprintmsgID. I end up with error >> saying >> TestprintmsgID has no attribute self.print_msg. Atleast i expect the >> null to be printed. >> >> >> >> class confid(): >> def __init__(self): >> self.print_msg = "" >> >> class ExpectId(confid): >> >> def __init__(self): >> self.print_msg = " Hello" >> >> def expectmethod(self): >> print "self.print_mesg = ",self.print_msg >> >> class TestprintmsgID(confid): >> >> def __init__(self): >> "Created Instance" >> >> def printmsgmethod(self): >> print "printmsgmethod print_msg val = ",self.print_msg---- Here >> is >> the Attribute error > > If the class has an __init__() method the initializer of the base class is > not invoked automatically. > > In the above code the initializer of TestprintmsgId does nothing, so you > can avoid it. ExpectId.__init__() however must invoke confid.__init_(). > > The complete example: Sorry, my examples don't show what I wanted to show. I assumed a class hierarchy confid <-- ExpectId <-- TestprintmsgId Also, ExpectId.__init__() need not invoke confid.__init__() in this particular case because both set the same attribute. The general ideas however still stand: (1) if you write an __init__() method it should invoke the __init__() method of the baseclass. (2) omit no-op __init__() methods altogether. Again, sorry for the confusion! From davea at davea.name Thu Sep 12 06:23:45 2013 From: davea at davea.name (Dave Angel) Date: Thu, 12 Sep 2013 10:23:45 +0000 (UTC) Subject: Accessing class attribute References: <1378966547.35546.YahooMailBasic@web190504.mail.sg3.yahoo.com> Message-ID: On 12/9/2013 02:15, chandan kumar wrote: > Hi , > > I'm new to python Welcome. I hope you enjoy your time here, and that the language treats you as well as it's treated me. > ,please correct me if there is any thing wrong with the way accessing class attributes. None of the following uses class attributes, but instead uses instance attributes. For example, any attri bute created with self.xxxx = inside an instance method will bei an instance attribute. Class attributes are typically created by assignments outside any method. > > Please see the below code .I have inherited confid in ExpectId class, changed self.print_msg to Hello. Now inherited confid in TestprintmsgID class.Now I wanted to print self.print_msg value (which is changed under ExpectId class) as Hello under TestprintmsgID. I end up with error saying TestprintmsgID has no attribute self.print_msg. Atleast i expect the null to be printed. Please include the full error message, (including the traceback), rather than just paraphrasing. In this case, it's easy to guess, but frequently it is not. > > > > class confid(): In Python 2, you always want to derive from object. That's to signal the compiler to use "new style" classes, which have been the preferred way for many years. Python 3 only has new-style classes. class confid(object): > def __init__(self): > self.print_msg = "" > > class ExpectId(confid): > > def __init__(self): > self.print_msg = " Hello" > > def expectmethod(self): > print "self.print_mesg = ",self.print_msg > Each instance of ExpectId is also an instance of confid. > class TestprintmsgID(confid): > > def __init__(self): > "Created Instance" > > def printmsgmethod(self): > print "printmsgmethod print_msg val = ",self.print_msg---- Here is the Attribute error > > Each instance of TestprintmsgID is also an instance of confid, but NOT of ExpectID. The base class methods are not automatically called when the child class methods are. if you want them called, you have to do it explicitly. In particular, you should always call the base class __init__() method from your __init__() method. It didn't happen to matter in the case of ExpectID, but it does here. Preferred way to do that is to add a line to iTextprintmsgID's __init__() method: super(ExpectId, self).__init__() should appear at the beginning of your initializer. This will eliminate your Attribute error. But it will still see a value for print_msg of bank string. > if __name__ == '__main__': > ins1 =ExpectId() > ins1.expectmethod() > > ins2 = TestprintmsgID() > ins2.printmsgmethod() > I think you're expecting that deriving from a class somehow patches the existing class. But it doesn't. The existence of the ExpectedID class only affects instances of that class, not instances of TestprintmsgID. If you wanted those to be affected, you'd be needing to inherit from ExpectID, rather than just from confid. If you did that, you'd see a value of "Hello". -- DaveA From Chandru_Rajendran at infosys.com Thu Sep 12 05:59:40 2013 From: Chandru_Rajendran at infosys.com (Chandru Rajendran) Date: Thu, 12 Sep 2013 09:59:40 +0000 Subject: Pep8 plugin for visual studio Message-ID: Hi all, I am new to python. Please give information about Pep8 style checker plugin for VS2012. Thanks in Advance, Chandru **************** CAUTION - Disclaimer ***************** This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely for the use of the addressee(s). If you are not the intended recipient, please notify the sender by e-mail and delete the original message. Further, you are not to copy, disclose, or distribute this e-mail or its contents to any other person and any such actions are unlawful. This e-mail may contain viruses. Infosys has taken every reasonable precaution to minimize this risk, but is not liable for any damage you may sustain as a result of any virus in this e-mail. You should carry out your own virus checks before opening the e-mail or attachment. Infosys reserves the right to monitor and review the content of all messages sent to or from this e-mail address. Messages sent to or from this e-mail address may be stored on the Infosys e-mail system. ***INFOSYS******** End of Disclaimer ********INFOSYS*** -------------- next part -------------- An HTML attachment was scrubbed... URL: From gssivacharan at gmail.com Thu Sep 12 07:15:31 2013 From: gssivacharan at gmail.com (Mobi Esprits) Date: Thu, 12 Sep 2013 04:15:31 -0700 (PDT) Subject: Python Programmers requirement Exp 2 - 3 yrs Message-ID: Hi, We have python programmers requirement with an experience of 2 -3 yrs. Job location shall be bangalore. Interested candidates can send their resume to hr at mobiesprits.com Please do not forget to mention the experience in the subject line. Best Regards, Mobi Esprtis Software Technologies Pvt. Ltd. From ben+python at benfinney.id.au Fri Sep 13 01:27:42 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 13 Sep 2013 15:27:42 +1000 Subject: Python Programmers requirement Exp 2 - 3 yrs References: Message-ID: <7w38p91eb5.fsf@benfinney.id.au> Mobi Esprits writes: > We have python programmers requirement with an experience of 2 -3 yrs. Please do not use this discussion forum for job advertisements. Instead, please use the Python Job Board which is designed for this purpose . -- \ ?Faith may be defined briefly as an illogical belief in the | `\ occurrence of the improbable.? ?Henry L. Mencken | _o__) | Ben Finney From ddp.ludo44 at gmail.com Thu Sep 12 07:17:46 2013 From: ddp.ludo44 at gmail.com (Ddp Ludo) Date: Thu, 12 Sep 2013 04:17:46 -0700 (PDT) Subject: Access to objects in a frame on a web page Message-ID: Hello, I am trying to program a robot which will allow me to test whether a default password has been changed on my intranet servers . And I 'm stuck since 2 days ... HTML structure of the page: I try to go to fill the username field and I turn around because of the frames. I tried to do it with mechanize . But as we can see, there is no body in the web page, so I can not instantiate the object form and get the fields on the page via this method. I can directly open the htm page where username and the enable button , but it does not work . It lacks all parent functions to actually start the identification. Here is the beginning of my code works . It connects to my page and correctly returns me the source code. br = mechanize.Browser () br.set_all_readonly ( False ) br.set_handle_robots ( False ) # ignore robots br.set_handle_refresh ( False ) # can sometimes hang without this br.addheaders = [( 'User - Agent ', ' Firefox' ) ] url = " file :/ / / root/Prog/html/AC1.htm " response = br.open (url) response.read print () Then, searching the internet, it seemed to understand that the frames were referred by links () class lnkList = [] br.links for lnk in (): lnkList.append ( lnk.url ) print " links " , lnk.url It correctly list my links. But can not use follow_link ( ) find_link .... I can not do it .... impossible to reach my username field .... After the best , I can get the pointer of the frame object, but I use mechanize no more .... frame = sys._getframe (2) print frame Does anyone know a solution? Either using code or in my thinking and my approach to the problem. Excuse my poor english. Thank you in advance . From info at wingware.com Thu Sep 12 08:36:53 2013 From: info at wingware.com (Wingware) Date: Thu, 12 Sep 2013 08:36:53 -0400 Subject: ANN: Wing IDE 4.1.14 released Message-ID: <5231B565.6090500@wingware.com> Hi, Wingware has released version 4.1.14 of Wing IDE, our integrated development environment designed specifically for the Python programming language. Wing IDE provides a professional quality code editor with vi, emacs, and other key bindings, auto-completion, call tips, refactoring, context-aware auto-editing, a powerful graphical debugger, version control, unit testing, search, and many other features. For details see http://wingware.com/ This minor maintenance release includes: Fix dropped debugger connections when using Python 3.3 Allow C debugger such as gdb to attach to a debug process running under Python 3 Allow auto-showing the Debug I/O tool only on first output for each debug session Don't show the run args dialog when restarting the debug process (and use same args) Go to correct symbol when selection range is non-empty Fix auto-editing when inserting HTML comments to avoid duplicate > 6 other minor bug fixes For a complete change log see http://wingware.com/pub/wingide/4.1.14/CHANGELOG.txt Free trial: http://wingware.com/wingide/trial Downloads: http://wingware.com/downloads Feature matrix: http://wingware.com/wingide/features More information: http://wingware.com/ Sales: http://wingware.com/store/purchase Upgrades: https://wingware.com/store/upgrade Questions? Don't hesitate to email us at support at wingware.com. Thanks, -- Stephan Deibel Wingware | Python IDE Advancing Software Development www.wingware.com From altugozgercek at gmail.com Thu Sep 12 11:43:13 2013 From: altugozgercek at gmail.com (altugozgercek at gmail.com) Date: Thu, 12 Sep 2013 08:43:13 -0700 (PDT) Subject: Expected an indented block Message-ID: Hey guys ! its my first topic and I'm gonna start with a problem :) Im totally beginner in Python and each time I try to run this program it gives me the error down below: http://imgur.com/ufUAMTs I'm using Sublime Text, same problems occured in TextWrangler and in Vim too. I tried python3 python.py too nothing has changed. Thanks in advance. From rosuav at gmail.com Thu Sep 12 11:51:16 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 13 Sep 2013 01:51:16 +1000 Subject: Expected an indented block In-Reply-To: References: Message-ID: On Fri, Sep 13, 2013 at 1:43 AM, wrote: > Hey guys ! its my first topic and I'm gonna start with a problem :) Im totally beginner in Python and each time I try to run this program it gives me the error down below: > > http://imgur.com/ufUAMTs > > I'm using Sublime Text, same problems occured in TextWrangler and in Vim too. I tried python3 python.py too nothing has changed. Thanks in advance. Without the code, we can't much help. But look at line 3 - it probably has an if, while, or for statement. Did you write python.py? Did you copy and paste it from somewhere? If the latter, make sure you retain indentation, as it's important to Python - and it's not always possible to figure out how far things should be indented otherwise. If python.py isn't very large, you'd do well to simply include its content in-line here. Including the full traceback (as text, not as an image) is also extremely helpful. In a few years, this list/newsgroup thread will be being read by hundreds or thousands of people, not all of whom will want to click web links to figure out what you're saying - and that's assuming imgur is still holding your image, which I'm not sure is guaranteed. Text is reliable! ChrisA From gordon at panix.com Thu Sep 12 11:57:19 2013 From: gordon at panix.com (John Gordon) Date: Thu, 12 Sep 2013 15:57:19 +0000 (UTC) Subject: Expected an indented block References: Message-ID: In altugozgercek at gmail.com writes: > Hey guys ! its my first topic and I'm gonna start with a problem :) Im > totally beginner in Python and each time I try to run this program it > gives me the error down below: > http://imgur.com/ufUAMTs That error involves the previous program line, which your screenshot doesn't show, so it's hard to say exactly what the problem is. However, I'll take a guess that the previous line is an "if" statement, which requires that the following line be indented. Did you indent the print statement? This error can also be caused by using a mix of tabs and spaces on the same line. Don't do that. (And by the way, it's generally better to post errors and code as text instead of a screenshot.) -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From antoine at python.org Thu Sep 12 12:04:45 2013 From: antoine at python.org (Antoine Pitrou) Date: Thu, 12 Sep 2013 16:04:45 +0000 (UTC) Subject: ANN: Obelus 0.1 -- Asterisk AMI / AGI implementation Message-ID: Hello, I'm pleased to announce the first release of Obelus, a MIT-licensed library to interact with Asterisk using the AMI and AGI protocols. This is version 0.1, and as such some APIs are a bit draftish and not guaranteed to be stable accross future releases. Also, documentation is far from exhaustive. Quick links ----------- * Project page: https://pypi.python.org/pypi/obelus/ * Source code, issue tracker: https://bitbucket.org/optiflowsrd/obelus * Documentation (incomplete): https://obelus.readthedocs.org Features -------- * Python 2 and Python 3 support. * AMI, FastAGI and Async AGI support. * Event-driven API friendly towards non-blocking ("async") network programming styles. * :pep:`3156`-style protocol implementations. * Framework-agnostic. * Adapters for the `Tornado`_, `Twisted`_, `Tulip`_ network programming frameworks. * Unit-tested. Requirements ------------ * Python 2.7, 3.2 or later. Regards Antoine. From stephen.boulet at gmail.com Thu Sep 12 19:01:20 2013 From: stephen.boulet at gmail.com (stephen.boulet at gmail.com) Date: Thu, 12 Sep 2013 16:01:20 -0700 (PDT) Subject: Stripping characters from windows clipboard with win32clipboard from excel Message-ID: <13c19665-6dc9-49fe-88c8-52c643892eba@googlegroups.com> I have an excel file. When I select cells, copy from excel, and then use win32clipboard to get the contents of the clipboard, I have a 131071 character string. When I save the file as a text file, and use the python 3.3 open command to read its contents, I only have 80684 characters. Excel (and other programs too) appends a bunch of b'\x00' (or similar) characters. Is there a pythonic way to strip these out? From steve+comp.lang.python at pearwood.info Thu Sep 12 20:19:30 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 Sep 2013 00:19:30 GMT Subject: Stripping characters from windows clipboard with win32clipboard from excel References: <13c19665-6dc9-49fe-88c8-52c643892eba@googlegroups.com> Message-ID: <52325a12$0$29988$c3e8da3$5496439d@news.astraweb.com> On Thu, 12 Sep 2013 16:01:20 -0700, stephen.boulet wrote: > I have an excel file. When I select cells, copy from excel, and then use > win32clipboard to get the contents of the clipboard, I have a 131071 > character string. How exactly are you using win32clipboard, and what exact result are you getting? Start with a smaller selection of cells, say, two cells, so the amount of data is manageable. I doubt very much you are getting 131071 *characters*. Perhaps you are getting that many *bytes*. Or perhaps you are getting HTML-formatted text. Without seeing what is in the clipboard, who can tell? Remember that the clipboard can contain multiple versions of the same data. > When I save the file as a text file, and use the python 3.3 open command > to read its contents, I only have 80684 characters. How exactly are you using the open function? The result you get may differ drastically depending on what you do. > Excel (and other programs too) appends a bunch of b'\x00' (or similar) > characters. Append to what? The .xls file? The text file? What tool are you using to see this? > Is there a pythonic way to strip these out? It's hard to tell from the limited description, but my guess is that you are misinterpreting what you are seeing. Part of the evidence for this is that you are conflating bytes and characters, e.g. above where you refer to the NUL *byte* b'\x00' as a character. Bytes are not characters. Scrub that out of your brain. They never were, not even back in the old ASCII days (may they soon be forgotten), despite what many people think. My guess is that when you save the spreadsheet as text, either Excel by default, or possibly because you have ticked a checkbox, have set it to save using the UTF-16 encoding. That's a good thing (not ideal, ideally they ought to use UTF-8, but UTF-16 is not a bad choice). But when you open the file in Python, Python defaults to UTF-8, which means you get an bunch of extraneous NULs when opening the file in text mode, or b'\x00' null bytes in binary mode. For example: py> with open('/tmp/rubbish', 'w', encoding='utf-16be') as f: ... f.write('hello world blah blah blah\n') ... 27 py> with open('/tmp/rubbish', 'r') as f: # default encoding is UTF-8 ... f.read() ... '\x00h\x00e\x00l\x00l\x00o\x00 \x00w\x00o\x00r\x00l\x00d\x00 \x00b\x00l \x00a\x00h\x00 \x00b\x00l\x00a\x00h\x00 \x00b\x00l\x00a\x00h\x00\n' If you look carefully, you will see that every character appears to be preceded by the NUL control character, \x00. But that's because you've used the wrong encoding to decode the bytes in the file back to characters. The right way to do this is: py> with open('/tmp/rubbish', 'r', encoding='utf-16be') as f: ... f.read() ... 'hello world blah blah blah\n' Which encoding should you use? Unfortunately, there is no clean way for text files to record which encoding to use inside the file itself, so it's often impossible to know for sure. This is why everyone should move towards using UTF-8 everywhere. But I digress. The fact that you show the NULs as *bytes* b'\x00' rather than characters '\x00' suggests that you might be reading the file in binary mode. Presumably you did this because you got an error when trying to read it in text mode. If you got this error: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte then you should go back to text mode, but use 'utf-16' as the codec: open(filename, 'w', encoding='utf-16') Otherwise, if the NULs appear before the letters, as in my example, use 'utf-16be'. If they appear after the letters, use 'utf-16le'. The existence of three oh-so-very-slightly different versions of UTF-16 is why it is a sub-optimal encoding, and it is oh-so-bloody-typical that Microsoft screwed it up for everyone by picking it as their default implementation. If they had sensibly used UTF-8, you wouldn't be having this problem. Of course, it is possible I've misdiagnosed your problem. I've had to guess a lot because you didn't show us what you actually did to get the results you say you got. -- Steven From stephen.boulet at gmail.com Thu Sep 12 20:58:15 2013 From: stephen.boulet at gmail.com (stephen.boulet at gmail.com) Date: Thu, 12 Sep 2013 17:58:15 -0700 (PDT) Subject: Stripping characters from windows clipboard with win32clipboard from excel In-Reply-To: <13c19665-6dc9-49fe-88c8-52c643892eba@googlegroups.com> References: <13c19665-6dc9-49fe-88c8-52c643892eba@googlegroups.com> Message-ID: <74479771-2726-4a34-8fd6-531d64c5b7a5@googlegroups.com> Hi Steven. Here is my code: import win32clipboard, win32con def getclipboard(): win32clipboard.OpenClipboard() s = win32clipboard.GetClipboardData(win32con.CF_TEXT) win32clipboard.CloseClipboard() return s I use this helper function to grab the text on the clipboard and do useful things with it. Sorry about the description; I have stuff to learn about strings and python 3.3. To get the string length, I just do len(s). There were 10 columns and 700+ rows of data, so len(s) returned 80684 from an excel spreadsheet saved as a text file. >From the clipboard contents copied from the spreadsheet, the characters s[:80684] were the visible cell contents, and s[80684:] all started with "b'\x0" and lack any useful info for what I'm trying to accomplish. From python at mrabarnett.plus.com Thu Sep 12 21:56:53 2013 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 13 Sep 2013 02:56:53 +0100 Subject: Stripping characters from windows clipboard with win32clipboard from excel In-Reply-To: <74479771-2726-4a34-8fd6-531d64c5b7a5@googlegroups.com> References: <13c19665-6dc9-49fe-88c8-52c643892eba@googlegroups.com> <74479771-2726-4a34-8fd6-531d64c5b7a5@googlegroups.com> Message-ID: <523270E5.7050901@mrabarnett.plus.com> On 13/09/2013 01:58, stephen.boulet at gmail.com wrote: > Hi Steven. Here is my code: > > import win32clipboard, win32con > > def getclipboard(): > win32clipboard.OpenClipboard() > s = win32clipboard.GetClipboardData(win32con.CF_TEXT) > win32clipboard.CloseClipboard() > return s > > I use this helper function to grab the text on the clipboard and do useful things with it. > > Sorry about the description; I have stuff to learn about strings and python 3.3. > > To get the string length, I just do len(s). There were 10 columns and 700+ rows of data, so len(s) returned 80684 from an excel spreadsheet saved as a text file. > >>From the clipboard contents copied from the spreadsheet, the characters s[:80684] were the visible cell contents, and s[80684:] all started with "b'\x0" and lack any useful info for what I'm trying to accomplish. > From my own experiments (although not with Excel) it appears that GetClipboardData returns bytes (a bytestring), not (Unicode) strings. From nhodgson at iinet.net.au Thu Sep 12 23:43:46 2013 From: nhodgson at iinet.net.au (Neil Hodgson) Date: Fri, 13 Sep 2013 13:43:46 +1000 Subject: Stripping characters from windows clipboard with win32clipboard from excel In-Reply-To: <74479771-2726-4a34-8fd6-531d64c5b7a5@googlegroups.com> References: <13c19665-6dc9-49fe-88c8-52c643892eba@googlegroups.com> <74479771-2726-4a34-8fd6-531d64c5b7a5@googlegroups.com> Message-ID: <3PKdndBR7KeRF6_PnZ2dnUVZ_u6dnZ2d@westnet.com.au> Stephen Boulet: > From the clipboard contents copied from the spreadsheet, the characters s[:80684] were the visible cell contents, and s[80684:] all started with "b'\x0" and lack any useful info for what I'm trying to accomplish. Looks like Excel is rounding up its clipboard allocation to the next 64K. There used to be good reasons for trying to leave some extra room on the clipboard and avoid reallocating the block but I thought that was over a long time ago. To strip NULs off the end of the string use s.rstrip('\0') Neil From stephen.boulet at gmail.com Fri Sep 13 10:31:45 2013 From: stephen.boulet at gmail.com (stephen.boulet at gmail.com) Date: Fri, 13 Sep 2013 07:31:45 -0700 (PDT) Subject: Stripping characters from windows clipboard with win32clipboard from excel In-Reply-To: <3PKdndBR7KeRF6_PnZ2dnUVZ_u6dnZ2d@westnet.com.au> References: <13c19665-6dc9-49fe-88c8-52c643892eba@googlegroups.com> <74479771-2726-4a34-8fd6-531d64c5b7a5@googlegroups.com> <3PKdndBR7KeRF6_PnZ2dnUVZ_u6dnZ2d@westnet.com.au> Message-ID: On Thursday, September 12, 2013 10:43:46 PM UTC-5, Neil Hodgson wrote: > Stephen Boulet: > > > > > From the clipboard contents copied from the spreadsheet, the characters s[:80684] were the visible cell contents, and s[80684:] all started with "b'\x0" and lack any useful info for what I'm trying to accomplish. > > > > Looks like Excel is rounding up its clipboard allocation to the next > > 64K. There used to be good reasons for trying to leave some extra room > > on the clipboard and avoid reallocating the block but I thought that was > > over a long time ago. > > > > To strip NULs off the end of the string use s.rstrip('\0') Hm, that gives me a "Type str doesn't support the buffer API" message. From neilc at norwich.edu Fri Sep 13 10:37:03 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 13 Sep 2013 14:37:03 GMT Subject: Stripping characters from windows clipboard with win32clipboard from excel References: <13c19665-6dc9-49fe-88c8-52c643892eba@googlegroups.com> <74479771-2726-4a34-8fd6-531d64c5b7a5@googlegroups.com> <3PKdndBR7KeRF6_PnZ2dnUVZ_u6dnZ2d@westnet.com.au> Message-ID: On 2013-09-13, stephen.boulet at gmail.com wrote: > On Thursday, September 12, 2013 10:43:46 PM UTC-5, Neil Hodgson wrote: >> Stephen Boulet: >> >> >> >> > From the clipboard contents copied from the spreadsheet, the characters s[:80684] were the visible cell contents, and s[80684:] all started with "b'\x0" and lack any useful info for what I'm trying to accomplish. >> >> >> >> Looks like Excel is rounding up its clipboard allocation to the next >> >> 64K. There used to be good reasons for trying to leave some extra room >> >> on the clipboard and avoid reallocating the block but I thought that was >> >> over a long time ago. >> >> >> >> To strip NULs off the end of the string use s.rstrip('\0') > > Hm, that gives me a "Type str doesn't support the buffer API" > message. Type mismatch. Try: s.rstrip(b"\0") -- Neil Cerutti From stephen.boulet at gmail.com Fri Sep 13 10:38:09 2013 From: stephen.boulet at gmail.com (stephen.boulet at gmail.com) Date: Fri, 13 Sep 2013 07:38:09 -0700 (PDT) Subject: Stripping characters from windows clipboard with win32clipboard from excel In-Reply-To: References: <13c19665-6dc9-49fe-88c8-52c643892eba@googlegroups.com> <74479771-2726-4a34-8fd6-531d64c5b7a5@googlegroups.com> <3PKdndBR7KeRF6_PnZ2dnUVZ_u6dnZ2d@westnet.com.au> Message-ID: <12ce40fd-bb6e-4249-a38d-7521c27a2825@googlegroups.com> On Friday, September 13, 2013 9:31:45 AM UTC-5, stephen... at gmail.com wrote: > On Thursday, September 12, 2013 10:43:46 PM UTC-5, Neil Hodgson wrote: > > > Stephen Boulet: > > > > > > > > > > > > > From the clipboard contents copied from the spreadsheet, the characters s[:80684] were the visible cell contents, and s[80684:] all started with "b'\x0" and lack any useful info for what I'm trying to accomplish. > > > > > > > > > > > > Looks like Excel is rounding up its clipboard allocation to the next > > > > > > 64K. There used to be good reasons for trying to leave some extra room > > > > > > on the clipboard and avoid reallocating the block but I thought that was > > > > > > over a long time ago. > > > > > > > > > > > > To strip NULs off the end of the string use s.rstrip('\0') > > > > Hm, that gives me a "Type str doesn't support the buffer API" message. Aha, I need to use str(s, encoding='utf8').rstrip('\0'). From random832 at fastmail.us Fri Sep 13 12:09:29 2013 From: random832 at fastmail.us (random832 at fastmail.us) Date: Fri, 13 Sep 2013 12:09:29 -0400 Subject: Stripping characters from windows clipboard with win32clipboard from excel In-Reply-To: <12ce40fd-bb6e-4249-a38d-7521c27a2825@googlegroups.com> References: <13c19665-6dc9-49fe-88c8-52c643892eba@googlegroups.com> <74479771-2726-4a34-8fd6-531d64c5b7a5@googlegroups.com> <3PKdndBR7KeRF6_PnZ2dnUVZ_u6dnZ2d@westnet.com.au> <12ce40fd-bb6e-4249-a38d-7521c27a2825@googlegroups.com> Message-ID: <1379088569.32542.21628745.0F1856DA@webmail.messagingengine.com> On Fri, Sep 13, 2013, at 10:38, stephen.boulet at gmail.com wrote: > > Hm, that gives me a "Type str doesn't support the buffer API" message. > > Aha, I need to use str(s, encoding='utf8').rstrip('\0'). It's not a solution to your problem, but why aren't you using CF_UNICODETEXT, particularly if you're using python 3? And if you're not, utf8 is the incorrect encoding, you should be using encoding='mbcs' to interact with the CF_TEXT clipboard. Anyway, to match behavior found in other applications when pasting from the clipboard, I would suggest using: if s.contains('\0'): s = s[:s.index('\0')] Which will also remove non-null bytes after the first null (but if the clipboard contains these, it won't be pasted into e.g. notepad). From random832 at fastmail.us Wed Sep 18 15:19:38 2013 From: random832 at fastmail.us (random832 at fastmail.us) Date: Wed, 18 Sep 2013 15:19:38 -0400 Subject: Stripping characters from windows clipboard with win32clipboard from excel In-Reply-To: <1379088569.32542.21628745.0F1856DA@webmail.messagingengine.com> References: <13c19665-6dc9-49fe-88c8-52c643892eba@googlegroups.com> <74479771-2726-4a34-8fd6-531d64c5b7a5@googlegroups.com> <3PKdndBR7KeRF6_PnZ2dnUVZ_u6dnZ2d@westnet.com.au> <12ce40fd-bb6e-4249-a38d-7521c27a2825@googlegroups.com> <1379088569.32542.21628745.0F1856DA@webmail.messagingengine.com> Message-ID: <1379531978.20462.23649901.784C47A5@webmail.messagingengine.com> On Fri, Sep 13, 2013, at 12:09, random832 at fastmail.us wrote: > Anyway, to match behavior found in other applications when pasting from > the clipboard, I would suggest using: > > if s.contains('\0'): s = s[:s.index('\0')] > > Which will also remove non-null bytes after the first null (but if the > clipboard contains these, it won't be pasted into e.g. notepad). I did some testing and confirmed you MUST do this - if you copy multiple things from Excel, it may reuse this buffer and not clear the end of it. From stephen.boulet at gmail.com Tue Sep 17 12:00:07 2013 From: stephen.boulet at gmail.com (stephen.boulet at gmail.com) Date: Tue, 17 Sep 2013 09:00:07 -0700 (PDT) Subject: Stripping characters from windows clipboard with win32clipboard from excel In-Reply-To: <13c19665-6dc9-49fe-88c8-52c643892eba@googlegroups.com> References: <13c19665-6dc9-49fe-88c8-52c643892eba@googlegroups.com> Message-ID: On Thursday, September 12, 2013 6:01:20 PM UTC-5, stephen... at gmail.com wrote: > I have an excel file. When I select cells, copy from excel, and then use win32clipboard to get the contents of the clipboard, I have a 131071 character string. > > > > When I save the file as a text file, and use the python 3.3 open command to read its contents, I only have 80684 characters. > > > > Excel (and other programs too) appends a bunch of b'\x00' (or similar) characters. > > > > Is there a pythonic way to strip these out? Odd behavior from excel. It seems as though the clipboard contents will vary according to the clipboard size. For example, in my 13 column row I select 2023 rows, copy to the clipboard, and def getclipboard(): win32clipboard.OpenClipboard() s = win32clipboard.GetClipboardData(win32con.CF_TEXT) win32clipboard.CloseClipboard() return s s = getclipboard() len(s) gives me 16298. If I select one additional row, len(s) balloons to 32767. In the first case, s[-10:] is b'0.032573\r\n'. In the second case, s[-10:] is b'\x008\x008\x000\x005\x00\t' Does anyone know what is going on with that? From stephen.boulet at gmail.com Wed Sep 18 15:28:44 2013 From: stephen.boulet at gmail.com (stephen.boulet at gmail.com) Date: Wed, 18 Sep 2013 12:28:44 -0700 (PDT) Subject: Stripping characters from windows clipboard with win32clipboard from excel In-Reply-To: <13c19665-6dc9-49fe-88c8-52c643892eba@googlegroups.com> References: <13c19665-6dc9-49fe-88c8-52c643892eba@googlegroups.com> Message-ID: Thanks to everyone for their help. Using everyone's suggestions, this seems to work: import win32clipboard, win32con def getclipboard(): win32clipboard.OpenClipboard() s = win32clipboard.GetClipboardData(win32con.CF_UNICODETEXT) win32clipboard.CloseClipboard() if '\0' in s: s = s[:s.index('\0')] return s From python at mrabarnett.plus.com Wed Sep 18 15:40:53 2013 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 18 Sep 2013 20:40:53 +0100 Subject: Stripping characters from windows clipboard with win32clipboard from excel In-Reply-To: References: <13c19665-6dc9-49fe-88c8-52c643892eba@googlegroups.com> Message-ID: <523A01C5.4080705@mrabarnett.plus.com> On 18/09/2013 20:28, stephen.boulet at gmail.com wrote: > Thanks to everyone for their help. Using everyone's suggestions, this seems to work: > > import win32clipboard, win32con > > def getclipboard(): > win32clipboard.OpenClipboard() > s = win32clipboard.GetClipboardData(win32con.CF_UNICODETEXT) > win32clipboard.CloseClipboard() > if '\0' in s: > s = s[:s.index('\0')] > return s > That'll look for a null character and, if it finds one, then look for it again. Of course, that probably isn't an issue in practice. However, an alternative way of doing it is to use the .partition method: return s.partition('\0')[0] From davea at davea.name Wed Sep 18 16:13:20 2013 From: davea at davea.name (Dave Angel) Date: Wed, 18 Sep 2013 20:13:20 +0000 (UTC) Subject: Stripping characters from windows clipboard with win32clipboard from excel References: <13c19665-6dc9-49fe-88c8-52c643892eba@googlegroups.com> <523A01C5.4080705@mrabarnett.plus.com> Message-ID: On 18/9/2013 15:40, MRAB wrote: > On 18/09/2013 20:28, stephen.boulet at gmail.com wrote: >> Thanks to everyone for their help. Using everyone's suggestions, this seems to work: >> >> import win32clipboard, win32con >> >> def getclipboard(): >> win32clipboard.OpenClipboard() >> s = win32clipboard.GetClipboardData(win32con.CF_UNICODETEXT) >> win32clipboard.CloseClipboard() >> if '\0' in s: >> s = s[:s.index('\0')] >> return s >> > That'll look for a null character and, if it finds one, then look for > it again. Of course, that probably isn't an issue in practice. > > However, an alternative way of doing it is to use the .partition method: > > return s.partition('\0')[0] So is the bug in Excel, in Windows, or in the Python library? Somebody is falling down on the job; if Windows defines the string as ending at the first null, then the Python interface should use that when defining the text defined with CF_UNICODETEXT. Or maybe it's an example of ill-defined Windows specs. -- DaveA From random832 at fastmail.us Thu Sep 19 10:39:27 2013 From: random832 at fastmail.us (random832 at fastmail.us) Date: Thu, 19 Sep 2013 10:39:27 -0400 Subject: Stripping characters from windows clipboard with win32clipboard from excel In-Reply-To: References: <13c19665-6dc9-49fe-88c8-52c643892eba@googlegroups.com> <523A01C5.4080705@mrabarnett.plus.com> Message-ID: <1379601567.28666.23983705.79F63462@webmail.messagingengine.com> On Wed, Sep 18, 2013, at 16:13, Dave Angel wrote: > So is the bug in Excel, in Windows, or in the Python library? Somebody > is falling down on the job; if Windows defines the string as ending at > the first null, then the Python interface should use that when defining > the text defined with CF_UNICODETEXT. > > Or maybe it's an example of ill-defined Windows specs. I think it's a matter of ill-defined windows specs - the clipboard data has an exact size, and in principle that size is always used, for example, for numerous binary formats. But the text clipboard has often been treated as a C string by a wide variety of different applications, so one could argue that has become a de facto standard. From nhodgson at iinet.net.au Wed Sep 18 17:40:52 2013 From: nhodgson at iinet.net.au (Neil Hodgson) Date: Thu, 19 Sep 2013 07:40:52 +1000 Subject: Stripping characters from windows clipboard with win32clipboard from excel In-Reply-To: References: <13c19665-6dc9-49fe-88c8-52c643892eba@googlegroups.com> <523A01C5.4080705@mrabarnett.plus.com> Message-ID: Dave Angel: > So is the bug in Excel, in Windows, or in the Python library? Somebody > is falling down on the job; if Windows defines the string as ending at > the first null, then the Python interface should use that when defining > the text defined with CF_UNICODETEXT. Everything is performing correctly. win32clipboard is low-level direct access to the Win32 clipboard API. A higher level API which is more easily used from Python could be defined on top of this if anyone was motivated. Neil From davea at davea.name Wed Sep 18 19:51:57 2013 From: davea at davea.name (Dave Angel) Date: Wed, 18 Sep 2013 23:51:57 +0000 (UTC) Subject: Stripping characters from windows clipboard with win32clipboard from excel References: <13c19665-6dc9-49fe-88c8-52c643892eba@googlegroups.com> <523A01C5.4080705@mrabarnett.plus.com> Message-ID: On 18/9/2013 17:40, Neil Hodgson wrote: > Dave Angel: > >> So is the bug in Excel, in Windows, or in the Python library? Somebody >> is falling down on the job; if Windows defines the string as ending at >> the first null, then the Python interface should use that when defining >> the text defined with CF_UNICODETEXT. > > Everything is performing correctly. win32clipboard is low-level > direct access to the Win32 clipboard API. A higher level API which is > more easily used from Python could be defined on top of this if anyone > was motivated. > > Neil Clearly you miss the point. If the clipboard API is defined to return a null-terminated string, then the problem is in the Python library which doesn't do a strlen() (or the wide-character equivalent; I forget its name) on the results. But there's a big if there. Somebody is either ill specified or poorly implemented here. -- DaveA From neilc at norwich.edu Thu Sep 19 11:53:12 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 19 Sep 2013 15:53:12 GMT Subject: Stripping characters from windows clipboard with win32clipboard from excel References: <13c19665-6dc9-49fe-88c8-52c643892eba@googlegroups.com> <523A01C5.4080705@mrabarnett.plus.com> Message-ID: On 2013-09-18, Dave Angel wrote: > On 18/9/2013 17:40, Neil Hodgson wrote: > >> Dave Angel: >> >>> So is the bug in Excel, in Windows, or in the Python library? Somebody >>> is falling down on the job; if Windows defines the string as ending at >>> the first null, then the Python interface should use that when defining >>> the text defined with CF_UNICODETEXT. >> >> Everything is performing correctly. win32clipboard is low-level >> direct access to the Win32 clipboard API. A higher level API which is >> more easily used from Python could be defined on top of this if anyone >> was motivated. >> >> Neil > > Clearly you miss the point. If the clipboard API is defined to > return a null-terminated string, then the problem is in the > Python library which doesn't do a strlen() (or the > wide-character equivalent; I forget its name) on the results. Python can't really know if you're pasting text or a screenshot or what. -- Neil Cerutti From davea at davea.name Thu Sep 19 15:58:24 2013 From: davea at davea.name (Dave Angel) Date: Thu, 19 Sep 2013 19:58:24 +0000 (UTC) Subject: Stripping characters from windows clipboard with win32clipboard from excel References: <13c19665-6dc9-49fe-88c8-52c643892eba@googlegroups.com> <523A01C5.4080705@mrabarnett.plus.com> Message-ID: On 19/9/2013 11:53, Neil Cerutti wrote: > On 2013-09-18, Dave Angel wrote: >> On 18/9/2013 17:40, Neil Hodgson wrote: >> >>> Dave Angel: >>> >>>> So is the bug in Excel, in Windows, or in the Python library? Somebody >>>> is falling down on the job; if Windows defines the string as ending at >>>> the first null, then the Python interface should use that when defining >>>> the text defined with CF_UNICODETEXT. >>> >>> Everything is performing correctly. win32clipboard is low-level >>> direct access to the Win32 clipboard API. A higher level API which is >>> more easily used from Python could be defined on top of this if anyone >>> was motivated. >>> >>> Neil >> >> Clearly you miss the point. If the clipboard API is defined to >> return a null-terminated string, then the problem is in the >> Python library which doesn't do a strlen() (or the >> wide-character equivalent; I forget its name) on the results. > > Python can't really know if you're pasting text or a screenshot > or what. > CF_UNICODETEXT gives it a pretty good clue. But random832 has already mentioned that it's an ill-specified Windows interface; different programs deal with it differently. No way that a the Python library should deal with that. -- DaveA From baoca82 at gmail.com Thu Sep 12 19:31:14 2013 From: baoca82 at gmail.com (Trandang Bao) Date: Fri, 13 Sep 2013 06:31:14 +0700 Subject: ImportError: No module named Image Message-ID: Dear Python.org, Recently, I have been studying OpenCV to detect and recognize faces using C++. In order to execute source code demonstration from the OpenCV website I need to run Python to crop image first. Unfortunately, the message error is 'ImportError: No module named Image' when I run the Python script ( this script is provided by OpenCV website). I installed python-2.7.amd64 and downloaded PIL-1.1.7.win32-py2.7 to install Image library. However, the message error is 'Python version 2.7 required, which was not found in the registry'. And then, I downloaded the script written by Joakim L?w for Secret Labs AB / PythonWare to register registry in my computer. But the message error is "Unable to register. You probably have the another Python installation". I spent one month to search this issue on the internet but I cannot find the answer. So I decide to write this email to Python.org. I hope you give me the solution or advice to resolve my issue. I am looking forward your respond. I hope to hear from you soon. Thanks, Tran Dang Bao -------------- next part -------------- An HTML attachment was scrubbed... URL: From jugurtha.hadjar at gmail.com Thu Sep 12 21:01:00 2013 From: jugurtha.hadjar at gmail.com (Jugurtha Hadjar) Date: Fri, 13 Sep 2013 02:01:00 +0100 Subject: ImportError: No module named Image In-Reply-To: References: Message-ID: <523263CC.2070106@gmail.com> On 09/13/2013 12:31 AM, Trandang Bao wrote: > Dear Python.org, > I installed > python-2.7.amd64 and downloaded PIL-1.1.7.win32-py2.7 to install Image > library. However, the message error is 'Python version 2.7 required, > which was not found in the registry'. One is a 32 bit installer, the other is a 64 bit installer. They don't look at the same place in the Registry. Try to have them both the same (both 32 for example). Also, it'd be useful to put exactly what you've done to make it reproducible to some extent, and to post the names of the files you used (like the script you used. I can Google the guy's name, but he might have written dozens of things, so .. which one). -- ~Jugurtha Hadjar, From mohsen at pahlevanzadeh.org Thu Sep 12 20:33:40 2013 From: mohsen at pahlevanzadeh.org (Mohsen Pahlevanzadeh) Date: Fri, 13 Sep 2013 05:03:40 +0430 Subject: When i leave a LineEdit widget and run slot Message-ID: <1379032420.9698.19.camel@debian> Dear all, QtCore.QObject.connect(self.checkBox, QtCore.SIGNAL(_fromUtf8("clicked(bool)")), lambda: self.interfaceCodesConstructor.setFilterList(self,"name",self.lineEdit.text())) I code pyqt, I have the following code: /////////////////////// QtCore.QObject.connect(self.checkBox, QtCore.SIGNAL(_fromUtf8("clicked(bool)")), lambda: self.interfaceCodesConstructor.setFilterList(self,"name",self.lineEdit.text())) ////////////////////////// Abobe code causes When i click on checkbox, my function : setFilterList will be run. i need to run above function: "setFilterList(self,"name",self.lineEdit.text())" When i leave a LineEdit widget, But i don't know its signal. My question is : What's its signal when you leave a widget such as LineEdit? Yours, Mohsen From vincent.vandevyvre at swing.be Fri Sep 13 06:49:03 2013 From: vincent.vandevyvre at swing.be (Vincent Vande Vyvre) Date: Fri, 13 Sep 2013 12:49:03 +0200 Subject: When i leave a LineEdit widget and run slot In-Reply-To: <1379032420.9698.19.camel@debian> References: <1379032420.9698.19.camel@debian> Message-ID: <5232ED9F.5020006@swing.be> Le 13/09/2013 02:33, Mohsen Pahlevanzadeh a ?crit : > Dear all, > > QtCore.QObject.connect(self.checkBox, > QtCore.SIGNAL(_fromUtf8("clicked(bool)")), lambda: > self.interfaceCodesConstructor.setFilterList(self,"name",self.lineEdit.text())) > I code pyqt, I have the following code: > > /////////////////////// > QtCore.QObject.connect(self.checkBox, > QtCore.SIGNAL(_fromUtf8("clicked(bool)")), lambda: > self.interfaceCodesConstructor.setFilterList(self,"name",self.lineEdit.text())) > ////////////////////////// > > Abobe code causes When i click on checkbox, my function : setFilterList > will be run. > > i need to run above function: > "setFilterList(self,"name",self.lineEdit.text())" When i leave a > LineEdit widget, But i don't know its signal. > > My question is : What's its signal when you leave a widget such as > LineEdit? > > Yours, > Mohsen > The signal editingFinished() is made for that. http://pyqt.sourceforge.net/Docs/PyQt4/qlineedit.html#editingFinished -- Vincent V.V. Oqapy . Qarte . PaQager From josiah.carlson at gmail.com Thu Sep 12 22:06:10 2013 From: josiah.carlson at gmail.com (Josiah Carlson) Date: Thu, 12 Sep 2013 19:06:10 -0700 Subject: Ann: rom 0.20 - Redis object mapper for Python Message-ID: Hey everyone, As time progresses, so does my Redis object mapper. The "rom" package is a Redis object mapper for Python. It sports an interface similar to Django's ORM, SQLAlchemy + Elixir, or Appengine's datastore. The changelog for recent releases can be seen below my signature. You can find the package at: https://www.github.com/josiahcarlson/rom https://pypi.python.org/pypi/rom And docs can be found at: http://pythonhosted.org/rom/ Please CC me on any replies if you have any questions or comments. Thank you, - Josiah #----------------------------------- 0.20 ------------------------------------ [changed] Added exception when performing .all(), .execute(), or .count() on query objects that have had no filters or attribute ordering provided. This addresses issue #12. [changed] Moved column definitions to their own module, shouldn't affect any normal uses of rom. [added] For users of Redis 2.6 and later, there is a beta Lua-enabled writing option that allows for multiple unique columns on models. In some cases, this may improve performance when writing many entities very quickly. [added] The ability to reload an entity from Redis, optionally discarding any modifications to the object itself. Check out the documentation for Model.refresh(), Session.refresh(), and Session.refresh_all() [added] Tests for the newly changed/added features. [changed] Tests no longer use flushdb() - all test models/indexes/etc. are prefixed with RomTest, and we find/delete such keys before and after any tests are run. Now anyone can reasonably run the test suite. #----------------------------------- 0.19 ------------------------------------ [fixed] Thanks to a bug report by https://github.com/MickeyKim , was notified of a bug when using unique indexes, which is now fixed and has a testcase. #----------------------------------- 0.18 ------------------------------------ [fixed] Thanks to a bug report by https://github.com/MickeyKim , was notified and received an interim patch for a bug that could cause deleted entities to be resurrected on session.commit() or session.flush() . This has now been fixed and a testcase has been added. #----------------------------------- 0.17 ------------------------------------ [added] LGPL 3 licensing option. -------------- next part -------------- An HTML attachment was scrubbed... URL: From otlasanju at gmail.com Fri Sep 13 01:55:13 2013 From: otlasanju at gmail.com (sanju dhoomakethu) Date: Thu, 12 Sep 2013 22:55:13 -0700 (PDT) Subject: Python -COMMETHOD ,No return value obtained/received Message-ID: <35d91bea-39ec-461c-8ec7-194dcd308428@googlegroups.com> I am very new to COM programming, Our project requires the Python script to make communication with a COM dll which is written in C#. The generated COM signature in Python is as below COMMETHOD([dispid(1610743820)], HRESULT, 'test', ( ['in', 'out'], POINTER(_midlSAFEARRAY(c_double)), 'test' ), ( ['retval', 'out'], POINTER(VARIANT_BOOL), 'pRetVal' )), Where as the C# code for the same is public bool test(ref double[,] test) { if (test == null) test = new double[1,2]; test[0,0] = 0.0; test[0,1] = 0.5; return true; } Note: the above is the dummy functions i have created to explain the issue Now when I try to invoke the COM method from Python , I am only getting the values passed by reference to the method (sweepValuesX) as return value and not the actual return value (which has to be either true/false) My function call is as below print apxWrapper.test() and the output is ((0.0, 0.5),) Note: Since i was not able to find a way to pass the last arguement from Python ,I just omitted the last argument for trial purpose Any hints why this is happening is highly appreciated or to be specific I have two questions 1> How Can i pass the argument to be passed by reference from Python especially array (both single and multidimensional)(POINTER(_midlSAFEARRAY(c_double))) 2> How can i get the actual return value (true/false) Sanjay From papillion at gmail.com Fri Sep 13 09:00:47 2013 From: papillion at gmail.com (Anthony Papillion) Date: Fri, 13 Sep 2013 08:00:47 -0500 Subject: Another question about JSON Message-ID: <52330C7F.7070203@gmail.com> Hello Again Everyone, I'm still working to get my head around JSON and I thought I'd done so until I ran into this bit of trouble. I'm trying to work with the CoinBase API. If I type this into my browser: https://coinbase.com/api/v1/prices/buy I get the following JSON returned {"subtotal":{"amount":"128.00","currency":"USD"},"fees":[{"coinbase":{"amount":"1.28","currency":"USD"}},{"bank":{"amount":"0.15","currency":"USD"}}],"total":{"amount":"129.43","currency":"USD"},"amount":"129.43","currency":"USD"} So far, so good. Now, I want to simply print out that bit of JSON (just to know I've got it) and I try to use the following code: returnedJSON = json.loads('https://coinbase.com/api/v1/prices/buy') print returnedString And I get a traceback that says: No JSON object could be decoded. The specific traceback is: Traceback (most recent call last): File "coinbase_bot.py", line 31, in getCurrentBitcoinPrice() File "coinbase_bot.py", line 28, in getCurrentBitcoinPrice returnedString = json.loads(BASE_API_URL + '/prices/buy') File "/usr/lib/python2.7/json/__init__.py", line 326, in loads return _default_decoder.decode(s) File "/usr/lib/python2.7/json/decoder.py", line 366, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python2.7/json/decoder.py", line 384, in raw_decode raise ValueError("No JSON object could be decoded") ValueError: No JSON object could be decoded I'm very confused since the URL is obviously returned a JSON string. Can anyone help me figure this out? What am I doing wrong? Thanks in advance! Anthony -- Anthony Papillion XMPP/Jabber: cypherpunk at patts.us OTR Fingerprint: 4F5CE6C07F5DCE4A2569B72606E5C00A21DA24FA SIP: 17772471988 at callcentric.com PGP Key: 0xE1608145 From __peter__ at web.de Fri Sep 13 09:24:25 2013 From: __peter__ at web.de (Peter Otten) Date: Fri, 13 Sep 2013 15:24:25 +0200 Subject: Another question about JSON References: <52330C7F.7070203@gmail.com> Message-ID: Anthony Papillion wrote: > Hello Again Everyone, > > I'm still working to get my head around JSON and I thought I'd done so > until I ran into this bit of trouble. I'm trying to work with the > CoinBase API. If I type this into my browser: > > https://coinbase.com/api/v1/prices/buy > > I get the following JSON returned > > {"subtotal":{"amount":"128.00","currency":"USD"},"fees":[{"coinbase": {"amount":"1.28","currency":"USD"}},{"bank": {"amount":"0.15","currency":"USD"}}],"total": {"amount":"129.43","currency":"USD"},"amount":"129.43","currency":"USD"} > > So far, so good. Now, I want to simply print out that bit of JSON (just > to know I've got it) and I try to use the following code: > > returnedJSON = json.loads('https://coinbase.com/api/v1/prices/buy') > print returnedString > > And I get a traceback that says: No JSON object could be decoded. The > specific traceback is: > > Traceback (most recent call last): > File "coinbase_bot.py", line 31, in > getCurrentBitcoinPrice() > File "coinbase_bot.py", line 28, in getCurrentBitcoinPrice > returnedString = json.loads(BASE_API_URL + '/prices/buy') > File "/usr/lib/python2.7/json/__init__.py", line 326, in loads > return _default_decoder.decode(s) > File "/usr/lib/python2.7/json/decoder.py", line 366, in decode > obj, end = self.raw_decode(s, idx=_w(s, 0).end()) > File "/usr/lib/python2.7/json/decoder.py", line 384, in raw_decode > raise ValueError("No JSON object could be decoded") > ValueError: No JSON object could be decoded > > > I'm very confused since the URL is obviously returned a JSON string. Can > anyone help me figure this out? What am I doing wrong? Let's see: >>> help(json.loads) Help on function loads in module json: loads(s, encoding=None, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw) Deserialize ``s`` (a ``str`` or ``unicode`` instance containing a JSON document) to a Python object. [...] So json.loads() expects its first argument to b valid json, no a URL. You have to retrieve the data using other means before you can deserialize it: data = urllib2.urlopen(...).read() returned_json = json.loads(data) Replacing ... with something that works is left as an exercise. (It seems that you have to use a Request object rather than a URL, and that the default "Python-urllib/2.7" is not an acceptable user agent. From papillion at gmail.com Fri Sep 13 11:05:24 2013 From: papillion at gmail.com (Anthony Papillion) Date: Fri, 13 Sep 2013 10:05:24 -0500 Subject: Another question about JSON In-Reply-To: References: <52330C7F.7070203@gmail.com> Message-ID: <523329B4.5020902@gmail.com> On 09/13/2013 08:24 AM, Peter Otten wrote: > Anthony Papillion wrote: > >> And I get a traceback that says: No JSON object could be decoded. The >> specific traceback is: >> >> Traceback (most recent call last): >> File "coinbase_bot.py", line 31, in >> getCurrentBitcoinPrice() >> File "coinbase_bot.py", line 28, in getCurrentBitcoinPrice >> returnedString = json.loads(BASE_API_URL + '/prices/buy') >> File "/usr/lib/python2.7/json/__init__.py", line 326, in loads >> return _default_decoder.decode(s) >> File "/usr/lib/python2.7/json/decoder.py", line 366, in decode >> obj, end = self.raw_decode(s, idx=_w(s, 0).end()) >> File "/usr/lib/python2.7/json/decoder.py", line 384, in raw_decode >> raise ValueError("No JSON object could be decoded") >> ValueError: No JSON object could be decoded > > So json.loads() expects its first argument to b valid json, no a URL. > You have to retrieve the data using other means before you can deserialize > it: > > data = urllib2.urlopen(...).read() > returned_json = json.loads(data) > > Replacing ... with something that works is left as an exercise. (It seems > that you have to use a Request object rather than a URL, and that the > default "Python-urllib/2.7" is not an acceptable user agent. Thank you Peter! That was all I needed. So here's the code I came up with that seems to work: req = urllib2.Request(BASE_URL + '/prices/buy') req.add_unredirected_header('User-Agent', USER_AGENT) resp = urllib2.urlopen(req).read() data - json.loads(resp) return data['amount'] Thank you for the help! Anthony -- Anthony Papillion XMPP/Jabber: cypherpunk at patts.us OTR Fingerprint: 4F5CE6C07F5DCE4A2569B72606E5C00A21DA24FA SIP: 17772471988 at callcentric.com PGP Key: 0xE1608145 From gordon at panix.com Fri Sep 13 10:35:00 2013 From: gordon at panix.com (John Gordon) Date: Fri, 13 Sep 2013 14:35:00 +0000 (UTC) Subject: Another question about JSON References: Message-ID: In Anthony Papillion writes: > I'm still working to get my head around JSON and I thought I'd done so > until I ran into this bit of trouble. I'm trying to work with the > CoinBase API. If I type this into my browser: > https://coinbase.com/api/v1/prices/buy > I get the following JSON returned > {"subtotal":{"amount":"128.00","currency":"USD"},"fees":[{"coinbase":{"amount":"1.28","currency":"USD"}},{"bank":{"amount":"0.15","currency":"USD"}}],"total":{"amount":"129.43","currency":"USD"},"amount":"129.43","currency":"USD"} > So far, so good. Now, I want to simply print out that bit of JSON (just > to know I've got it) and I try to use the following code: > returnedJSON = json.loads('https://coinbase.com/api/v1/prices/buy') > print returnedString JSON is a notation for exchanging data; it knows nothing about URLs. It's up to you to connect to the URL and read the data into a string, and then pass that string to json.loads(). -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From petmertens at gmail.com Fri Sep 13 13:35:51 2013 From: petmertens at gmail.com (petmertens at gmail.com) Date: Fri, 13 Sep 2013 10:35:51 -0700 (PDT) Subject: Get the selected tab in a enthought traits application Message-ID: <7aba29d3-dc9e-4a9c-82d5-edfab19d767c@googlegroups.com> Hi, I have a traits application with a tabbed group: Group( Group(label="a", dock='tab'), Group(label="b", dock='tab'), layout='tabbed') Beneath the tabbed group, there is button which should perform some action depending on the selected tab. So I would like to know which of both tabs, 'a' or 'b', is selected (i.e. active). Any ideas? Thanks From shi at somewhere.be Sun Sep 15 03:56:24 2013 From: shi at somewhere.be (shi) Date: Sun, 15 Sep 2013 09:56:24 +0200 Subject: Get the selected tab in a enthought traits application References: <7aba29d3-dc9e-4a9c-82d5-edfab19d767c@googlegroups.com> Message-ID: > Any ideas? I think you will have more chance for an answer in a more specialized list, e.g. the enthought-dev mailing list, which is also accessible via gmane: http:// dir.gmane.org / gmane.comp.python.enthought.devel Stefaan. From appabhishek5 at gmail.com Fri Sep 13 15:02:26 2013 From: appabhishek5 at gmail.com (Abhishek Pawar) Date: Fri, 13 Sep 2013 12:02:26 -0700 (PDT) Subject: new to python Message-ID: <7de0d650-7148-4084-84cb-e6abe568de64@googlegroups.com> what should i do after learning python to get more comfortable with python? From ben+python at benfinney.id.au Fri Sep 13 15:15:56 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 14 Sep 2013 05:15:56 +1000 Subject: new to python References: <7de0d650-7148-4084-84cb-e6abe568de64@googlegroups.com> Message-ID: <7wy570zg5v.fsf@benfinney.id.au> Abhishek Pawar writes: > what should i do after learning python to get more comfortable with > python? Welcome! Congratulations on finding Python. Get comfortable with Python by spending time working through beginner documentation and doing all the exercises. Get comfortable with Python by spending time applying your skills to some programming problems you already have. Isn't that the reason you learned Python in the first place? Good hunting to you! -- \ ?[W]e are still the first generation of users, and for all that | `\ we may have invented the net, we still don't really get it.? | _o__) ?Douglas Adams | Ben Finney From python at mrabarnett.plus.com Fri Sep 13 15:22:31 2013 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 13 Sep 2013 20:22:31 +0100 Subject: new to python In-Reply-To: <7de0d650-7148-4084-84cb-e6abe568de64@googlegroups.com> References: <7de0d650-7148-4084-84cb-e6abe568de64@googlegroups.com> Message-ID: <523365F7.7080704@mrabarnett.plus.com> On 13/09/2013 20:02, Abhishek Pawar wrote: > what should i do after learning python to get more comfortable with python? > There's really nothing better than practice, so start writing something that will be interesting or useful to you. It doesn't have to be amazing! :-) From appabhishek5 at gmail.com Fri Sep 13 15:46:03 2013 From: appabhishek5 at gmail.com (Abhishek Pawar) Date: Fri, 13 Sep 2013 12:46:03 -0700 (PDT) Subject: new to python In-Reply-To: References: <7de0d650-7148-4084-84cb-e6abe568de64@googlegroups.com> Message-ID: <98192fe9-dab9-443a-9650-2a662459c50d@googlegroups.com> On Saturday, September 14, 2013 12:45:56 AM UTC+5:30, Ben Finney wrote: > Abhishek Pawar writes: > > > > > what should i do after learning python to get more comfortable with > > > python? > > > > Welcome! Congratulations on finding Python. > thanks you inspire me > > > Get comfortable with Python by spending time working through beginner > > documentation and doing > > all the exercises. > > > > Get comfortable with Python by spending time applying your skills to > > some programming problems you already have. Isn't that the reason you > > learned Python in the first place? > > > > Good hunting to you! > > > > -- > > \ ?[W]e are still the first generation of users, and for all that | > > `\ we may have invented the net, we still don't really get it.? | > > _o__) ?Douglas Adams | > > Ben Finney From appabhishek5 at gmail.com Fri Sep 13 15:48:36 2013 From: appabhishek5 at gmail.com (Abhishek Pawar) Date: Fri, 13 Sep 2013 12:48:36 -0700 (PDT) Subject: new to python In-Reply-To: References: <7de0d650-7148-4084-84cb-e6abe568de64@googlegroups.com> Message-ID: <7023d3c6-32c0-44a5-9ea1-fd4ee09bc508@googlegroups.com> On Saturday, September 14, 2013 12:45:56 AM UTC+5:30, Ben Finney wrote: > Abhishek Pawar writes: > > > > > what should i do after learning python to get more comfortable with > > > python? > > > > Welcome! Congratulations on finding Python. > > > > Get comfortable with Python by spending time working through beginner > > documentation and doing > > all the exercises. > > > > Get comfortable with Python by spending time applying your skills to > > some programming problems you already have. Isn't that the reason you > > learned Python in the first place? > > > > Good hunting to you! > > > > -- > > \ ?[W]e are still the first generation of users, and for all that | > > `\ we may have invented the net, we still don't really get it.? | > > _o__) ?Douglas Adams | > > Ben Finney thank you Ben From steve+comp.lang.python at pearwood.info Fri Sep 13 21:02:36 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Sep 2013 01:02:36 GMT Subject: new to python References: <7de0d650-7148-4084-84cb-e6abe568de64@googlegroups.com> Message-ID: <5233b5ab$0$29988$c3e8da3$5496439d@news.astraweb.com> On Fri, 13 Sep 2013 12:02:26 -0700, Abhishek Pawar wrote: > what should i do after learning python to get more comfortable with > python? Write programs with Python. Lots of programs. Even just little programs which you throw away afterwards is fine. The important part is, write write write. Don't forget to run them too. If you just write, you'll never know if they work or not. If they don't work, keep writing and debugging until they work. Read programs. Lots of programs. I recommend you read the code in the standard library, you will learn a lot from it. Some of the code is a bit old and not necessarily "best practice" any more, but it is still good code. -- Steven From mnish1984 at gmail.com Sat Sep 14 02:34:07 2013 From: mnish1984 at gmail.com (mnishpsyched) Date: Fri, 13 Sep 2013 23:34:07 -0700 (PDT) Subject: Need help to sort out the below code... Message-ID: <9f6d4a88-4ae4-4e61-9f73-c074ec3f487f@googlegroups.com> Hello guys, i am new to programming and trying to solve this small coding: my purpose is to take in values from the user based on a menu provided for selection the output looks like this... please select from the following menu: 1. pizza 2. steak 3. pasta 4. burger type in any number from above for selection.. you have selected: 1. Pizza The bill amounted for Pizza is $20 along with tax of $0.15 will make upto $20.15 the code i have written for this is as follows: print """ Please select from the following menu: 1. pizza 2. steak 3. pasta 4. burger type in any number from above for selection.. """ pz = raw_input() pz = int(pz) st = raw_input() st = int(st) ps = raw_input() ps = int(ps) bg = raw_input() bg = int(bg) if pz == 1 : print "You have selected", pz, ".pizza" pr_pz = 20 tx_pz = 0.15 tot = pr_pz + tx_pz print "The bill amounted for Pizza is $", pr_pz, "along with tax of $", tx_pz, "will make upto $", tot elif st == 2 : print "You have selected", st, ".Steak" pr_st = 40 tx_st = 0.20 print "The bill amounted for Steak is $", pr_st, "along with tax of $", tx_st, "will make upto $", tot..................... ........................... but my program doesn't output the selection once i type in any number from the list..Please help me to sort it out... From tjreedy at udel.edu Sat Sep 14 03:50:04 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 Sep 2013 03:50:04 -0400 Subject: Need help to sort out the below code... In-Reply-To: <9f6d4a88-4ae4-4e61-9f73-c074ec3f487f@googlegroups.com> References: <9f6d4a88-4ae4-4e61-9f73-c074ec3f487f@googlegroups.com> Message-ID: On 9/14/2013 2:34 AM, mnishpsyched wrote: > Hello guys, > i am new to programming and trying to solve this small coding: my purpose is to take in values from the user based on a menu provided for selection > > the output looks like this... > > please select from the following menu: > 1. pizza > 2. steak > 3. pasta > 4. burger > type in any number from above for selection.. > > you have selected: 1. Pizza > The bill amounted for Pizza is $20 along with tax of $0.15 will make upto $20.15 > > the code i have written for this is as follows: > > print """ > Please select from the following menu: > 1. pizza > 2. steak > 3. pasta > 4. burger > type in any number from above for selection.. > """ > > pz = raw_input() > pz = int(pz) > > st = raw_input() > st = int(st) > > ps = raw_input() > ps = int(ps) > > bg = raw_input() > bg = int(bg) > There should only be one input statement: choice = int(raw_input()) The program now requires 4 inputs, which is not what you want. Since you are starting, consider using 3.3 insteadd of Python 2 unless you have a very good reason. > if pz == 1 : if choice == 1: etc. > print "You have selected", pz, ".pizza" > pr_pz = 20 > tx_pz = 0.15 > tot = pr_pz + tx_pz > print "The bill amounted for Pizza is $", pr_pz, "along with tax of $", tx_pz, "willmake upto $", tot Take out 'amounted' > elif st == 2 : > print "You have selected", st, ".Steak" > pr_st = 40 > tx_st = 0.20 > print "The bill amounted for Steak is $", pr_st, "along with tax of $", tx_st, "will make upto $", tot..................... > ........................... > but my program doesn't output the selection once i type in any number from the list. Because it is waiting for 3 more inputs. See above. Now, you can shorten and improve the program after the one input statement. data = ( ('Pizza', 20.0, 0.15), ('Steak', 40.0, 0.20), ('Pasta', 14.0, 0.12), ('Burger', 23.0, 0.17), ) if 1 <= choice <= len(data): product, price, tax = data[choice] bill = "The bill for {} is {}, along with tax of {}, total {}" print(bill.format(product, price, tax, price + tax)) else: print('I do not know what you mean.') print() is for 3.x, but works here for 2.x also. -- Terry Jan Reedy From jugurtha.hadjar at gmail.com Sat Sep 14 04:38:19 2013 From: jugurtha.hadjar at gmail.com (Jugurtha Hadjar) Date: Sat, 14 Sep 2013 09:38:19 +0100 Subject: Need help to sort out the below code... In-Reply-To: <9f6d4a88-4ae4-4e61-9f73-c074ec3f487f@googlegroups.com> References: <9f6d4a88-4ae4-4e61-9f73-c074ec3f487f@googlegroups.com> Message-ID: <5234207B.5040302@gmail.com> Hello, mnishpsyched.. You also want the VAT to be computed as a percentage _of_ something, and not hard-coded, so that if you change the price of the pizza, you only have to change one value (pr_pz) instead of two values pr_pz and tx_tz (as the second is computed from the first). You only multiply by coefficients, and these coefficients (the percentage the state charges) is less likely to change than the costs of ingredients or your margins (money moves faster than legislation). -- ~Jugurtha Hadjar, From gordon at panix.com Sat Sep 14 10:42:51 2013 From: gordon at panix.com (John Gordon) Date: Sat, 14 Sep 2013 14:42:51 +0000 (UTC) Subject: Need help to sort out the below code... References: <9f6d4a88-4ae4-4e61-9f73-c074ec3f487f@googlegroups.com> Message-ID: In <9f6d4a88-4ae4-4e61-9f73-c074ec3f487f at googlegroups.com> mnishpsyched writes: > print """ > Please select from the following menu: > 1. pizza > 2. steak > 3. pasta > 4. burger > type in any number from above for selection.. > """ > pz = raw_input() > pz = int(pz) > st = raw_input() > st = int(st) > ps = raw_input() > ps = int(ps) > bg = raw_input() > bg = int(bg) > but my program doesn't output the selection once i type in any number > from the list..Please help me to sort it out... That's because you're calling raw_input() four times, thus the user must type in a number four times. You probably want something like this: user_choice = raw_input() user_choice = int(user_choice) if user_choice == 1: print "You have selected", user_choice, ".pizza" .... .... elif user_choice == 2: print "You have selected", st, ".Steak" .... .... -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From marco.buttu at gmail.com Sat Sep 14 04:14:27 2013 From: marco.buttu at gmail.com (Marco Buttu) Date: Sat, 14 Sep 2013 10:14:27 +0200 Subject: PEP-442 - Python 3.4 and finalizations (__del__) Message-ID: Hi all. Will the following code in Python 3.4 print "Goodbye from B()" and "Goodbye from A(): class A: def __init__(self, a): self.a = a print('In A.__init__()') def __del__(self): print('Goodbye from A()') class B: def __init__(self): self.b = A(self) # Reference cycle print('In B.__init__()') def __del__(self): print('Goodbye from B()') b = B() del b Regards, Marco -- Marco Buttu From steve+comp.lang.python at pearwood.info Sat Sep 14 05:42:33 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Sep 2013 09:42:33 GMT Subject: PEP-442 - Python 3.4 and finalizations (__del__) References: Message-ID: <52342f89$0$29988$c3e8da3$5496439d@news.astraweb.com> On Sat, 14 Sep 2013 10:14:27 +0200, Marco Buttu wrote: > Hi all. Will the following code in Python 3.4 print "Goodbye from B()" > and "Goodbye from A(): Perhaps you should try it and find out. [steve at ando ~]$ python3.4 -E Python 3.4.0a1+ (default:becbb65074e1, Aug 26 2013, 03:57:58) [GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> >>> class A: ... def __init__(self, a): ... self.a = a ... print('In A.__init__()') ... def __del__(self): ... print('Goodbye from A()') ... >>> class B: ... def __init__(self): ... self.b = A(self) # Reference cycle ... print('In B.__init__()') ... def __del__(self): ... print('Goodbye from B()') ... >>> b = B() In A.__init__() In B.__init__() >>> del b >>> >>> >>> import gc >>> gc.collect() Goodbye from B() Goodbye from A() 4 >>> Does that answer your question? -- Steven From marco.buttu at gmail.com Sat Sep 14 06:10:57 2013 From: marco.buttu at gmail.com (Marco Buttu) Date: Sat, 14 Sep 2013 12:10:57 +0200 Subject: PEP-442 - Python 3.4 and finalizations (__del__) References: <52342f89$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 09/14/2013 11:42 AM, Steven D'Aprano wrote: > Perhaps you should try it and find out. Hi Steven, thanks for your answer. I tried it with Python 3.4a2, but I did not see any output from __del__(). > [steve at ando ~]$ python3.4 -E > Python 3.4.0a1+ (default:becbb65074e1, Aug 26 2013, 03:57:58) > [GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux > Type "help", "copyright", "credits" or "license" for more information. >>>> >>> >>>> >>>class A: > .... def __init__(self, a): > .... self.a = a > .... print('In A.__init__()') > .... def __del__(self): > .... print('Goodbye from A()') > .... >>>> >>>class B: > .... def __init__(self): > .... self.b = A(self) # Reference cycle > .... print('In B.__init__()') > .... def __del__(self): > .... print('Goodbye from B()') > .... >>>> >>>b = B() > In A.__init__() > In B.__init__() >>>> >>>del b >>>> >>> >>>> >>> >>>> >>>import gc >>>> >>>gc.collect() > Goodbye from B() > Goodbye from A() > 4 I thought in this case, the __del__() methods should have called automatically... > Does that answer your question? Yes, thanks a lot Steven, I saw the gc.collect() does not call the __del__() method in Python 3.3, so I think I will look at the documentation of gc in order to understand better. Thanks again, Marco -- Marco Buttu From exhuma at gmail.com Sat Sep 14 05:08:16 2013 From: exhuma at gmail.com (Michel Albert) Date: Sat, 14 Sep 2013 02:08:16 -0700 (PDT) Subject: How to display ReST properly on pypi? Message-ID: <950cde69-932e-4ba2-b473-c7f7e9892e2d@googlegroups.com> In general, I write my README files using the ReST syntax. But when I do, they don't show up formatted on pypi (see for example https://pypi.python.org/pypi/config_resolver/3.3.0). How do I get it to be formatted properly? Also, is there a way to specify that the "description" field in setup.py is formatted as ReST? From kwpolska at gmail.com Sat Sep 14 05:53:12 2013 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Sat, 14 Sep 2013 11:53:12 +0200 Subject: How to display ReST properly on pypi? In-Reply-To: <950cde69-932e-4ba2-b473-c7f7e9892e2d@googlegroups.com> References: <950cde69-932e-4ba2-b473-c7f7e9892e2d@googlegroups.com> Message-ID: On Sat, Sep 14, 2013 at 11:08 AM, Michel Albert wrote: > In general, I write my README files using the ReST syntax. But when I do, they don't show up formatted on pypi (see for example https://pypi.python.org/pypi/config_resolver/3.3.0). > > How do I get it to be formatted properly? > > Also, is there a way to specify that the "description" field in setup.py is formatted as ReST? > -- > https://mail.python.org/mailman/listinfo/python-list rst2html crashes with your file. Also, `py:class` is Sphinx-only and won?t work with the Cheeseshop and produce garbage in the output. [kwpolska at kwpolska-lin config_resolver-3.3.0]% rst2html README.rst README.rst:67: (WARNING/2) Inline emphasis start-string without end-string. README.rst:108: (ERROR/3) Unknown interpreted text role "py:class". README.rst:115: (ERROR/3) Unknown interpreted text role "py:class". README.rst:121: (ERROR/3) Unknown interpreted text role "py:class". README.rst:142: (SEVERE/4) Problems with "include" directive path: InputError: [Errno 2] No such file or directory: 'CHANGES'. Exiting due to level-4 (SEVERE) system message. [kwpolska at kwpolska-lin config_resolver-3.3.0]% echo $? 1 [kwpolska at kwpolska-lin config_resolver-3.3.0]% -- Chris ?Kwpolska? Warrick PGP: 5EAAEA16 stop html mail | always bottom-post | only UTF-8 makes sense From exhuma at gmail.com Sat Sep 14 06:02:37 2013 From: exhuma at gmail.com (Michel Albert) Date: Sat, 14 Sep 2013 03:02:37 -0700 (PDT) Subject: How to display ReST properly on pypi? In-Reply-To: References: <950cde69-932e-4ba2-b473-c7f7e9892e2d@googlegroups.com> Message-ID: Ah... I understand. Makes sense. I was confused that it worked properly on github, but not on pypi, so I never even thought about checking it in rst2html. I thought I would need to specify somewhere manually that it was formatted as ReST instead of plain-text. Thanks for the info. On Saturday, 14 September 2013 11:53:12 UTC+2, Chris ?Kwpolska? Warrick wrote: > On Sat, Sep 14, 2013 at 11:08 AM, Michel Albert wrote: > > > In general, I write my README files using the ReST syntax. But when I do, they don't show up formatted on pypi (see for example https://pypi.python.org/pypi/config_resolver/3.3.0). > > > > > > How do I get it to be formatted properly? > > > > > > Also, is there a way to specify that the "description" field in setup.py is formatted as ReST? > > > -- > > > https://mail.python.org/mailman/listinfo/python-list > > > > rst2html crashes with your file. Also, `py:class` is Sphinx-only and > > won?t work with the Cheeseshop and produce garbage in the output. > > > > [kwpolska at kwpolska-lin config_resolver-3.3.0]% rst2html README.rst > > README.rst:67: (WARNING/2) Inline emphasis start-string without end-string. > > README.rst:108: (ERROR/3) Unknown interpreted text role "py:class". > > README.rst:115: (ERROR/3) Unknown interpreted text role "py:class". > > README.rst:121: (ERROR/3) Unknown interpreted text role "py:class". > > README.rst:142: (SEVERE/4) Problems with "include" directive path: > > InputError: [Errno 2] No such file or directory: 'CHANGES'. > > Exiting due to level-4 (SEVERE) system message. > > [kwpolska at kwpolska-lin config_resolver-3.3.0]% echo $? > > 1 > > [kwpolska at kwpolska-lin config_resolver-3.3.0]% > > > > -- > > Chris ?Kwpolska? Warrick > > PGP: 5EAAEA16 > > stop html mail | always bottom-post | only UTF-8 makes sense From manojrout70 at gmail.com Sat Sep 14 07:33:42 2013 From: manojrout70 at gmail.com (Manoj Rout) Date: Sat, 14 Sep 2013 04:33:42 -0700 (PDT) Subject: Appending data to an excel sheet by python code Message-ID: <87454429-bd36-44b2-bef1-055d976c16ae@googlegroups.com> hi i want to append some data to an existing excel sheet by reading from file.But here i am facing 2 problem.first is when i am reading from file. import re file=open("C:\Workspace\WS2\P1\Dave\Generated\src\UART001\UART001_Conf.c","r") strings=re.search(r'(?<=(.Mode = UART_))\w+',file.read()) string=re.search(r'(?<=(.StopBit = UART_))\w+',file.read()) print strings.group() print string.group() workbook.close() Here if i will read only once then it is fine and not showing any error.But if i will do it for second time i.e.2nd string i have to search and print both of them,then it is showing error. And one more problem how to append some data to an existing excel sheet by python code. so can u please help me on this problem. Thanks and with regards Manoj Rout From python at mrabarnett.plus.com Sat Sep 14 13:06:27 2013 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 14 Sep 2013 18:06:27 +0100 Subject: Appending data to an excel sheet by python code In-Reply-To: <87454429-bd36-44b2-bef1-055d976c16ae@googlegroups.com> References: <87454429-bd36-44b2-bef1-055d976c16ae@googlegroups.com> Message-ID: <52349793.1020603@mrabarnett.plus.com> On 14/09/2013 12:33, Manoj Rout wrote: > hi > i want to append some data to an existing excel sheet by reading from file.But here i am facing 2 problem.first is when i am reading from file. > > > import re > It's a good idea to use raw string literals for file paths on Windows. Alternatively, you could use forward slashes instead of backslashes. > file=open("C:\Workspace\WS2\P1\Dave\Generated\src\UART001\UART001_Conf.c","r") Here you're reading the entire file: > strings=re.search(r'(?<=(.Mode = UART_))\w+',file.read()) Here you're trying to read the entire file again, but you're already read to its end, so you'll now get an empty string: > string=re.search(r'(?<=(.StopBit = UART_))\w+',file.read()) > > print strings.group() > print string.group() > What's 'workbook'? Don't you mean 'file'? > workbook.close() > > > > Here if i will read only once then it is fine and not showing any error.But if i will do it for second time i.e.2nd string i have to search and print both of them,then it is showing error. > You haven't shown the traceback, so I have to guess what the error was. > And one more problem how to append some data to an existing excel sheet by python code. > > so can u please help me on this problem. > From petmertens at gmail.com Sat Sep 14 13:28:32 2013 From: petmertens at gmail.com (petmertens at gmail.com) Date: Sat, 14 Sep 2013 10:28:32 -0700 (PDT) Subject: Appending data to an excel sheet by python code In-Reply-To: <87454429-bd36-44b2-bef1-055d976c16ae@googlegroups.com> References: <87454429-bd36-44b2-bef1-055d976c16ae@googlegroups.com> Message-ID: Did you consider using xlrd and xlwt? I guess these package provide a solution to your problem. From varunnayyar at hotmail.com Sat Sep 14 11:33:15 2013 From: varunnayyar at hotmail.com (varun nayyar) Date: Sat, 14 Sep 2013 15:33:15 +0000 Subject: Issue in installing xlwt package Message-ID: Hello,I am using windows 7 32 bit and installed python 2.7.5When i am trying to install xlwt 0.7.5 package from cmd prompt it shows Access Denied.When i run the cmd in administrator mode I am getting the following error: Fatal Python error: Py_Initialize: can't initialize sys standard streamsImportError: No module named encodings.utf_8 This application has requested the Runtime to terminate it in an unusual way.Please contact the application's support team for more information. -------------- next part -------------- An HTML attachment was scrubbed... URL: From eamonnrea at gmail.com Sat Sep 14 13:39:20 2013 From: eamonnrea at gmail.com (eamonnrea at gmail.com) Date: Sat, 14 Sep 2013 10:39:20 -0700 (PDT) Subject: =?ISO-8859-1?B?UHl0aG9uICsgTNZWRT8=?= Message-ID: As you may know, there is a fantastic Lua game development engine called L?VE. There is also a way to integrate Lua and Python. So, is it possible to use L?VE and Python together? Thanks! From tjreedy at udel.edu Sat Sep 14 14:45:10 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 Sep 2013 14:45:10 -0400 Subject: Python + =?UTF-8?B?TMOWVkU/?= In-Reply-To: References: Message-ID: On 9/14/2013 1:39 PM, eamonnrea at gmail.com wrote: > As you may know, there is a fantastic Lua game development engine called L?VE. There is also a way to integrate Lua and Python. So, is it possible to use L?VE and Python together? Have you asked the L?VE folks? -- Terry Jan Reedy From tbaror at gmail.com Sat Sep 14 22:59:26 2013 From: tbaror at gmail.com (Tal Bar-Or) Date: Sat, 14 Sep 2013 19:59:26 -0700 (PDT) Subject: How to get time (milisecond) of a python IO execution Message-ID: <8baf5318-f82c-417d-9a1d-956bf9cb3856@googlegroups.com> Hi All i am trying to test measure some IO execution in milliseconds , but bit confuse about best method achive that under windows 7 i am using following code but not sure if its best or correct way since i have two different results, which one should i take as results and which is best way please advice Thanks code exec results 100000000 loops, best of 3: 0.00925 usec per loop 3.827947176762156 run code import timeit ,time import datetime import os def main(): os.path.getsize("c:/video-2011-09-09-09-32-29.mp4") if __name__ == '__main__': t = timeit.Timer('main()') print (t.timeit(1)) From skip at pobox.com Sun Sep 15 06:52:33 2013 From: skip at pobox.com (Skip Montanaro) Date: Sun, 15 Sep 2013 05:52:33 -0500 Subject: How to get time (milisecond) of a python IO execution In-Reply-To: <8baf5318-f82c-417d-9a1d-956bf9cb3856@googlegroups.com> References: <8baf5318-f82c-417d-9a1d-956bf9cb3856@googlegroups.com> Message-ID: I'm not familiar with how Windows works, but I wouldn't be surprised if it caches directory information. (Unix systems certainly would.) You probably aren't really doing much actual I/O to get the size of a file after the first run. Also, you probably want to subtract the time it takes to execute a no-op function: def noop(): pass to eliminate the overhead of calling your main function. Skip From davea at davea.name Sun Sep 15 07:31:43 2013 From: davea at davea.name (Dave Angel) Date: Sun, 15 Sep 2013 11:31:43 +0000 (UTC) Subject: How to get time (milisecond) of a python IO execution References: <8baf5318-f82c-417d-9a1d-956bf9cb3856@googlegroups.com> Message-ID: On 14/9/2013 22:59, Tal Bar-Or wrote: > Hi All > > i am trying to test measure some IO execution in milliseconds , but bit confuse about best method achive that under windows 7 Measuring any performance can be tricky, and I/O in particular. Windows will cache the recently used file information, at a few levels. So if you do the same thing repeatedly, you'll get an unnaturally low average time. if you really need to measure how long it takes to get a file size, you would need to write your own, very controlled, test code. For example, there is an APi call that tells Windows to flush its disk caching logic. However, it doesn't necessarily flush the buffers that the drive itself keeps. Worse, in order to run your program, you have to do some disk I/O, and if that happens to use some of the same sectors as the thing you're timing, you're biasing the results. If you have multiple partitions, you could arrange that the file in question is the only thing your system uses on that partition, to minimize the likelihood that something else has primed the pump. But realize also that once you're measuring the real thing, speed of exeution will vary enormously depending on the speed of the drive, the layout of the directories, and the fragmentation of the disk. -- DaveA From mohsen at pahlevanzadeh.org Sun Sep 15 03:34:43 2013 From: mohsen at pahlevanzadeh.org (Mohsen Pahlevanzadeh) Date: Sun, 15 Sep 2013 12:04:43 +0430 Subject: How to differ between checked and unckecked Message-ID: <1379230483.9698.28.camel@debian> Dear all, My program have a set of checkbox, When user check a checkbox, i should call slot1() and when user uncheck checkbox, i should call slot2(),But i can't understand when user checks and unchecked. My questions is, How can i find out user check and unchecked checkbox? It's very important that i differ between check and unckeck. Yours, Mohsen From vincent.vandevyvre at swing.be Sun Sep 15 03:56:33 2013 From: vincent.vandevyvre at swing.be (Vincent Vande Vyvre) Date: Sun, 15 Sep 2013 09:56:33 +0200 Subject: How to differ between checked and unckecked In-Reply-To: <1379230483.9698.28.camel@debian> References: <1379230483.9698.28.camel@debian> Message-ID: <52356831.9010101@swing.be> Le 15/09/2013 09:34, Mohsen Pahlevanzadeh a ?crit : > Dear all, > > > My program have a set of checkbox, > When user check a checkbox, i should > call slot1() and when user uncheck > checkbox, i should call slot2(),But > i can't understand when user checks > and unchecked. > > My questions is, How can i find out > user check and unchecked checkbox? > It's very important that i differ > between check and unckeck. > > Yours, > Mohsen > > In my crystal ball I see your are using PyQt. So, there's no different signal for each state of the QCheckBox, create one slot that will call the good function in accordance with the state wich is the argument of the signal `stateChanged`. -- Vincent V.V. Oqapy . Qarte . PaQager From nikos.gr33k at gmail.com Sun Sep 15 11:54:48 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Sun, 15 Sep 2013 08:54:48 -0700 (PDT) Subject: Tryign to send mail via a python script by using the local MTA Message-ID: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> try: # prepare mail data FROM = random_char(10) + '@' + random_char(10) + '.com' TO = "nikos.gr33k at gmail.com" SUBJECT = random_char( 50 ) MESSAGE = random_char( 500 ) os.system( "echo %s | mailx -v -r %s -s %s %s" % (MESSAGE, FROM, SUBJECT, TO) ) print( "

%s? ???????? ???? %s ?????????!

" % (times, TO) ) except Exception as e: print( "sendmail => ", date, repr( sys.exc_info() ) ) sys.exit(0) ======================================== ======================================== I'am still trying to send successfulyl a mail through my local host by using the local MTA, trying to avoid using GMail's SMTP server but the mail never gets send this is the error message: [code] nikos at superhost.gr [~/www/cgi-bin]# python mail.py LOG: MAIN cwd=/home/nikos/public_html/cgi-bin 6 args: send-mail -i -v -r ZYN1KGSCT9 at JRV0CEI7TX.com nikos.gr33k at gmail.com LOG: MAIN <= ZYN1KGSCT9 at JRV0CEI7TX.com U=nikos P=local S=1052 id=5235d7f5.bzP0TUy4ZQEOp7Dh%ZYN1KGSCT9 at JRV0CEI7TX.com T="QOU0ULMZBF7RGG7B260YERPPXXLTVQ9WKJ93ZXYABQNNA0XB9I" Content-type: text/html; charset=utf-8

0? ???????? ???? nikos.gr33k at gmail.com ?????????!

LOG: MAIN cwd=/var/spool/exim 4 args: /usr/sbin/exim -v -Mc 1VLEdZ-0001Xg-6b delivering 1VLEdZ-0001Xg-6b nikos at superhost.gr [~/www/cgi-bin]# LOG: MAIN SMTP connection outbound 1379260405 1VLEdZ-0001Xg-6b superhost.gr nikos.gr33k at gmail.com Connecting to gmail-smtp-in.l.google.com [173.194.70.26]:25 ... connected SMTP<< 220 mx.google.com ESMTP e49si15825947eep.141 - gsmtp SMTP>> EHLO secure.superhost.gr SMTP<< 250-mx.google.com at your service, [84.200.17.58] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250 CHUNKING SMTP>> STARTTLS SMTP<< 220 2.0.0 Ready to start TLS SMTP>> EHLO secure.superhost.gr SMTP<< 250-mx.google.com at your service, [84.200.17.58] 250-SIZE 35882577 250-8BITMIME 250-ENHANCEDSTATUSCODES 250 CHUNKING SMTP>> MAIL FROM: SIZE=2090 SMTP<< 250 2.1.0 OK e49si15825947eep.141 - gsmtp SMTP>> RCPT TO: SMTP<< 250 2.1.5 OK e49si15825947eep.141 - gsmtp SMTP>> DATA SMTP<< 354 Go ahead e49si15825947eep.141 - gsmtp SMTP>> writing message and terminating "." SMTP<< 250 2.0.0 OK 1379260407 e49si15825947eep.141 - gsmtp SMTP>> QUIT LOG: MAIN => nikos.gr33k at gmail.com R=lookuphost T=remote_smtp H=gmail-smtp-in.l.google.com [173.194.70.26] X=TLSv1:RC4-SHA:128 LOG: MAIN Completed [/code] Since all looks okey why the mail never gets delivered? From j.j.molenaar at gmail.com Sun Sep 15 14:59:52 2013 From: j.j.molenaar at gmail.com (Joost Molenaar) Date: Sun, 15 Sep 2013 20:59:52 +0200 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> Message-ID: Since the From address is random, it most likely doesn't exist, which could be reason for Google's smtp server to reject the message or to deliver it to spam. Also, the reverse DNS for 84.200.17.58 does not resolve to secure.superhost.gr, which could also be reason to reject the message. On Sun, Sep 15, 2013 at 5:54 PM, Ferrous Cranus wrote: > try: > # prepare mail data > FROM = random_char(10) + '@' + random_char(10) + '.com' > TO = "nikos.gr33k at gmail.com" > > SUBJECT = random_char( 50 ) > MESSAGE = random_char( 500 ) > > os.system( "echo %s | mailx -v -r %s -s %s %s" % (MESSAGE, FROM, SUBJECT, TO) ) > > print( "

%s? ???????? ???? %s ?????????!

" % (times, TO) ) > except Exception as e: > print( "sendmail => ", date, repr( sys.exc_info() ) ) > > sys.exit(0) > > ======================================== > ======================================== > > I'am still trying to send successfulyl a mail through my local host by using the local MTA, trying to avoid using GMail's SMTP server but the mail never gets send > > this is the error message: > > [code] > nikos at superhost.gr [~/www/cgi-bin]# python mail.py > LOG: MAIN > cwd=/home/nikos/public_html/cgi-bin 6 args: send-mail -i -v -r ZYN1KGSCT9 at JRV0CEI7TX.com nikos.gr33k at gmail.com > LOG: MAIN > <= ZYN1KGSCT9 at JRV0CEI7TX.com U=nikos P=local S=1052 id=5235d7f5.bzP0TUy4ZQEOp7Dh%ZYN1KGSCT9 at JRV0CEI7TX.com T="QOU0ULMZBF7RGG7B260YERPPXXLTVQ9WKJ93ZXYABQNNA0XB9I" > Content-type: text/html; charset=utf-8 > >

0? ???????? ???? nikos.gr33k at gmail.com ?????????!

> LOG: MAIN > cwd=/var/spool/exim 4 args: /usr/sbin/exim -v -Mc 1VLEdZ-0001Xg-6b > delivering 1VLEdZ-0001Xg-6b > nikos at superhost.gr [~/www/cgi-bin]# LOG: MAIN > SMTP connection outbound 1379260405 1VLEdZ-0001Xg-6b superhost.gr nikos.gr33k at gmail.com > Connecting to gmail-smtp-in.l.google.com [173.194.70.26]:25 ... connected > SMTP<< 220 mx.google.com ESMTP e49si15825947eep.141 - gsmtp > SMTP>> EHLO secure.superhost.gr > SMTP<< 250-mx.google.com at your service, [84.200.17.58] > 250-SIZE 35882577 > 250-8BITMIME > 250-STARTTLS > 250-ENHANCEDSTATUSCODES > 250 CHUNKING > SMTP>> STARTTLS > SMTP<< 220 2.0.0 Ready to start TLS > SMTP>> EHLO secure.superhost.gr > SMTP<< 250-mx.google.com at your service, [84.200.17.58] > 250-SIZE 35882577 > 250-8BITMIME > 250-ENHANCEDSTATUSCODES > 250 CHUNKING > SMTP>> MAIL FROM: SIZE=2090 > SMTP<< 250 2.1.0 OK e49si15825947eep.141 - gsmtp > SMTP>> RCPT TO: > SMTP<< 250 2.1.5 OK e49si15825947eep.141 - gsmtp > SMTP>> DATA > SMTP<< 354 Go ahead e49si15825947eep.141 - gsmtp > SMTP>> writing message and terminating "." > SMTP<< 250 2.0.0 OK 1379260407 e49si15825947eep.141 - gsmtp > SMTP>> QUIT > LOG: MAIN > => nikos.gr33k at gmail.com R=lookuphost T=remote_smtp H=gmail-smtp-in.l.google.com [173.194.70.26] X=TLSv1:RC4-SHA:128 > LOG: MAIN > Completed > [/code] > > > Since all looks okey why the mail never gets delivered? > -- > https://mail.python.org/mailman/listinfo/python-list From nikos at superhost.gr Sun Sep 15 16:56:08 2013 From: nikos at superhost.gr (SuperHost - Nikos) Date: Sun, 15 Sep 2013 23:56:08 +0300 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> Message-ID: ???? 15/9/2013 9:59 ??, ?/? Joost Molenaar ??????: > Also, the reverse DNS for 84.200.17.58 does not resolve to > secure.superhost.gr, which could also be reason to reject the message. How can i fix this please? From rosuav at gmail.com Sun Sep 15 17:31:49 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 16 Sep 2013 07:31:49 +1000 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> Message-ID: On Mon, Sep 16, 2013 at 1:54 AM, Ferrous Cranus wrote: > Since all looks okey why the mail never gets delivered? This is not a Python question. If it were, I would be asking how you're getting _anywhere_ with that code, which appears to have IndentationErrors in it. You're also using os.system() with interpolated content. What _exactly_ is random_char() able to return? Is it possible for it to do the wrong thing there? ChrisA From joel.goldstick at gmail.com Sun Sep 15 17:57:54 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sun, 15 Sep 2013 17:57:54 -0400 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> Message-ID: On Sun, Sep 15, 2013 at 5:31 PM, Chris Angelico wrote: > On Mon, Sep 16, 2013 at 1:54 AM, Ferrous Cranus > wrote: > > Since all looks okey why the mail never gets delivered? > > This is not a Python question. If it were, I would be asking how > you're getting _anywhere_ with that code, which appears to have > IndentationErrors in it. > > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > This questions sounds like it should be asked of your hosting company. They may not allow there servers to be used this way. What have they told you? -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Sun Sep 15 21:52:38 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Sep 2013 01:52:38 GMT Subject: Tryign to send mail via a python script by using the local MTA References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> Message-ID: <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> Hi Nikos, I'm now going to put as much care and attention into my answer as you put into your question. Have uy tryed imprting os first? u nmeed to do improt os first or it wont work., When you give evidence of caring about the questions you ask, I'll start caring about the answers I give you. On Sun, 15 Sep 2013 08:54:48 -0700, Ferrous Cranus wrote: > try: > # prepare mail data > FROM = random_char(10) + '@' + random_char(10) + '.com' TO = > "nikos.gr33k at gmail.com" > > SUBJECT = random_char( 50 ) > MESSAGE = random_char( 500 ) > > os.system( "echo %s | mailx -v -r %s -s %s %s" % (MESSAGE, FROM, > SUBJECT, TO) ) > > print( "

%s? ???????? ???? %s > ?????????!

" % (times, TO) ) > except Exception as e: > print( "sendmail => ", date, repr( sys.exc_info() ) ) > > sys.exit(0) -- Steven From nikos.gr33k at gmail.com Mon Sep 16 02:44:07 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Mon, 16 Sep 2013 09:44:07 +0300 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: ???? 16/9/2013 4:52 ??, ?/? Steven D'Aprano ??????: > Hi Nikos, > > I'm now going to put as much care and attention into my answer as you put > into your question. > > Have uy tryed imprting os first? u nmeed to do > > improt os > > first or it wont work., > > > When you give evidence of caring about the questions you ask, I'll start > caring about the answers I give you. > > > > On Sun, 15 Sep 2013 08:54:48 -0700, Ferrous Cranus wrote: > >> try: >> # prepare mail data >> FROM = random_char(10) + '@' + random_char(10) + '.com' TO = >> "nikos.gr33k at gmail.com" >> >> SUBJECT = random_char( 50 ) >> MESSAGE = random_char( 500 ) >> >> os.system( "echo %s | mailx -v -r %s -s %s %s" % (MESSAGE, FROM, >> SUBJECT, TO) ) >> >> print( "

%s? ???????? ???? %s >> ?????????!

" % (times, TO) ) >> except Exception as e: >> print( "sendmail => ", date, repr( sys.exc_info() ) ) >> >> sys.exit(0) > > > > Steven of course i have imported the 'os' module. I try to send mail from different FROM filed just like as a visitor guest will use the webform to compete his own email. but since you ask here is the whole code with the function displayed too. #================================================================================================================= # if html form is submitted then send user mail #================================================================================================================= def random_char( y, chars=string.ascii_uppercase + string.digits ): return ''.join( random.choice(chars) for x in range(y) ) for times in range(0, 1): try: # prepare mail data FROM = random_char(10) + '@' + random_char(10) + '.com' TO = "nikos.gr33k at gmail.com" SUBJECT = random_char( 50 ) MESSAGE = random_char( 500 ) os.system( "echo %s | mailx -v -r %s -s %s %s" % (MESSAGE, FROM, SUBJECT, TO) ) print( "

%s? ???????? ???? %s ?????????!

" % (times, TO) ) except Exception as e: print( "sendmail => ", date, repr( sys.exc_info() ) ) sys.exit(0) ================================================================================================================== Is there a way to avoid the hostname and the ip address from being revealed when i'am sending an email? Because the mails finally got delivered to my gmail account after many hours of delay, and in the headers they are detailes like hostname and ip address of my server which i dont want to be revealed. i can alter FROM, TO, subject, message can i also alter the hostname fo the server the the mail derived from? From antoon.pardon at rece.vub.ac.be Mon Sep 16 03:29:26 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 16 Sep 2013 09:29:26 +0200 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5236B356.7030308@rece.vub.ac.be> Op 16-09-13 03:52, Steven D'Aprano schreef: > Hi Nikos, > > I'm now going to put as much care and attention into my answer as you put > into your question. > > Have uy tryed imprting os first? u nmeed to do > > improt os > > first or it wont work., > > > When you give evidence of caring about the questions you ask, I'll start > caring about the answers I give you. And why do you find it necessary to impart your careless answer on the list? If you find he doesn't show enough care about the questions he asks, why don't you just ignore him, instead of showing us all that you too can contribute in a careless manner? -- Antoon Pardon From rosuav at gmail.com Mon Sep 16 03:44:16 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 16 Sep 2013 17:44:16 +1000 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: <5236B356.7030308@rece.vub.ac.be> References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> Message-ID: On Mon, Sep 16, 2013 at 5:29 PM, Antoon Pardon wrote: > Op 16-09-13 03:52, Steven D'Aprano schreef: >> Hi Nikos, >> >> I'm now going to put as much care and attention into my answer as you put >> into your question. >> >> Have uy tryed imprting os first? u nmeed to do >> >> improt os >> >> first or it wont work., >> >> >> When you give evidence of caring about the questions you ask, I'll start >> caring about the answers I give you. > > And why do you find it necessary to impart your careless answer on the > list? If you find he doesn't show enough care about the questions he > asks, why don't you just ignore him, instead of showing us all that you > too can contribute in a careless manner? bceause its funnyer that way? Also, how will other people learn that they should put some effort into their questions? If people are only ever corrected privately, nobody will learn from anyone else. Orders of magnitude more people will read this than just the OP, which is why I still respond to jmf about Unicode even though I know he isn't listening. It's worth it for the hundreds (thousands? millions? Maybe even more?) of other people who'll read and learn. ChrisA From antoon.pardon at rece.vub.ac.be Mon Sep 16 04:07:02 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 16 Sep 2013 10:07:02 +0200 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> Message-ID: <5236BC26.6010001@rece.vub.ac.be> Op 16-09-13 09:44, Chris Angelico schreef: > On Mon, Sep 16, 2013 at 5:29 PM, Antoon Pardon > wrote: >> Op 16-09-13 03:52, Steven D'Aprano schreef: >>> Hi Nikos, >>> >>> I'm now going to put as much care and attention into my answer as you put >>> into your question. >>> >>> Have uy tryed imprting os first? u nmeed to do >>> >>> improt os >>> >>> first or it wont work., >>> >>> >>> When you give evidence of caring about the questions you ask, I'll start >>> caring about the answers I give you. >> >> And why do you find it necessary to impart your careless answer on the >> list? If you find he doesn't show enough care about the questions he >> asks, why don't you just ignore him, instead of showing us all that you >> too can contribute in a careless manner? > > bceause its funnyer that way? Funny for who? Personnaly I was rather amused by some of the reactions that Nikos received and that were ill received by some people here. So why should your of steve's fun trump my amusment? > Also, how will other people learn that they should put some effort > into their questions? If people are only ever corrected privately, > nobody will learn from anyone else. Orders of magnitude more people > will read this than just the OP, I didn't complain about his respons being public. -- Antoon Pardon From rosuav at gmail.com Mon Sep 16 04:12:11 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 16 Sep 2013 18:12:11 +1000 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: <5236BC26.6010001@rece.vub.ac.be> References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BC26.6010001@rece.vub.ac.be> Message-ID: On Mon, Sep 16, 2013 at 6:07 PM, Antoon Pardon wrote: >> Also, how will other people learn that they should put some effort >> into their questions? If people are only ever corrected privately, >> nobody will learn from anyone else. Orders of magnitude more people >> will read this than just the OP, > > I didn't complain about his respons being public. http://www.catb.org/esr/faqs/smart-questions.html#not_losing Sometimes, things are better said than not-said. In fact, that's *often* true. Maybe it's unpleasant for the person the jab is aimed at; maybe it feels awkward for you, as an onlooker. But for the good of python-list, Nikos has to be told that putting minimal effort into his questions is a bad thing, and if you're going to say that, may as well say it in a funny way. Plus, Steven was making a solid point, too. So if you want Nikos to be ignored by anyone who can't be completely "friendly", what you'll end up with is materially less content on the list. ChrisA From rosuav at gmail.com Mon Sep 16 03:46:11 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 16 Sep 2013 17:46:11 +1000 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: <5236B356.7030308@rece.vub.ac.be> References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> Message-ID: On Mon, Sep 16, 2013 at 5:29 PM, Antoon Pardon wrote: > instead of showing us all that you > too can contribute in a careless manner? Also: It takes effort to contribute usefully in a way that looks careless :) It's not saving effort, it's making a point. ChrisA From antoon.pardon at rece.vub.ac.be Mon Sep 16 04:12:37 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 16 Sep 2013 10:12:37 +0200 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> Message-ID: <5236BD75.5080904@rece.vub.ac.be> Op 16-09-13 09:46, Chris Angelico schreef: > On Mon, Sep 16, 2013 at 5:29 PM, Antoon Pardon > wrote: >> instead of showing us all that you >> too can contribute in a careless manner? > > Also: It takes effort to contribute usefully in a way that looks > careless :) It's not saving effort, it's making a point. So what? The end result is still a contribution that looks like it was carelessly written. Do you think making a point is an end that justifies any kind of means? If not why do you argue in a way that suggest just that. If yes, does that mean baiting Nikos is all right if it makes a point, or responding somewhat obnoxious to him? -- Antoon Pardon From rosuav at gmail.com Mon Sep 16 04:19:45 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 16 Sep 2013 18:19:45 +1000 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: <5236BD75.5080904@rece.vub.ac.be> References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> Message-ID: On Mon, Sep 16, 2013 at 6:12 PM, Antoon Pardon wrote: > Op 16-09-13 09:46, Chris Angelico schreef: >> On Mon, Sep 16, 2013 at 5:29 PM, Antoon Pardon >> wrote: >>> instead of showing us all that you >>> too can contribute in a careless manner? >> >> Also: It takes effort to contribute usefully in a way that looks >> careless :) It's not saving effort, it's making a point. > > So what? The end result is still a contribution that looks like > it was carelessly written. It's a contribution that SAYS that it looks carelessly written. I think most people here are intelligent enough to know that that's different from actual carelessness. > Do you think making a point is an end that justifies any kind of > means? If not why do you argue in a way that suggest just that. > If yes, does that mean baiting Nikos is all right if it makes > a point, or responding somewhat obnoxious to him? In a debate, you make points and counterpoints. In most debates, you also gain (or lose) "points for style". Steven scored plenty of the latter IMO. You're here making a straw-man and a false dichotomy; I believe that "making a point" is sufficient justification for what Steven and I did, but I don't think it justifies "any kind of means". I would not, for instance, destroy Nikos's server, data, or access to either, to make a point; and history will confirm this. ChrisA From antoon.pardon at rece.vub.ac.be Mon Sep 16 04:43:35 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 16 Sep 2013 10:43:35 +0200 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> Message-ID: <5236C4B7.3070601@rece.vub.ac.be> Op 16-09-13 10:19, Chris Angelico schreef: > On Mon, Sep 16, 2013 at 6:12 PM, Antoon Pardon > wrote: >> Op 16-09-13 09:46, Chris Angelico schreef: >>> On Mon, Sep 16, 2013 at 5:29 PM, Antoon Pardon >>> wrote: >>>> instead of showing us all that you >>>> too can contribute in a careless manner? >>> >>> Also: It takes effort to contribute usefully in a way that looks >>> careless :) It's not saving effort, it's making a point. >> >> So what? The end result is still a contribution that looks like >> it was carelessly written. > > It's a contribution that SAYS that it looks carelessly written. I > think most people here are intelligent enough to know that that's > different from actual carelessness. The question is, should they care about that difference. The end result is a contribution that is just as hard to read. >> Do you think making a point is an end that justifies any kind of >> means? If not why do you argue in a way that suggest just that. >> If yes, does that mean baiting Nikos is all right if it makes >> a point, or responding somewhat obnoxious to him? > > In a debate, you make points and counterpoints. In most debates, you > also gain (or lose) "points for style". Steven scored plenty of the > latter IMO. And why should we accept you as the arbiter for this? > You're here making a straw-man and a false dichotomy; I > believe that "making a point" is sufficient justification for what > Steven and I did, but I don't think it justifies "any kind of means". Then your argument was incomplete, because it just mentioned making a point as if that in itself was sufficient. > I would not, for instance, destroy Nikos's server, data, or access to > either, to make a point; and history will confirm this. No it doesn't. -- Antoon Pardon From rosuav at gmail.com Mon Sep 16 04:48:41 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 16 Sep 2013 18:48:41 +1000 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: <5236C4B7.3070601@rece.vub.ac.be> References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> Message-ID: On Mon, Sep 16, 2013 at 6:43 PM, Antoon Pardon wrote: > Op 16-09-13 10:19, Chris Angelico schreef: >> It's a contribution that SAYS that it looks carelessly written. I >> think most people here are intelligent enough to know that that's >> different from actual carelessness. > > The question is, should they care about that difference. The end > result is a contribution that is just as hard to read. Is it, really? I throw the question open: Is it really just as difficult to read a deliberately-pointed-out sloppiness as an actual one? And is it as much of a problem to the list? >> In a debate, you make points and counterpoints. In most debates, you >> also gain (or lose) "points for style". Steven scored plenty of the >> latter IMO. > > And why should we accept you as the arbiter for this? "We" shouldn't. Style points are per-listener. In my eyes he did well. You may well disagree. >> You're here making a straw-man and a false dichotomy; I >> believe that "making a point" is sufficient justification for what >> Steven and I did, but I don't think it justifies "any kind of means". > > Then your argument was incomplete, because it just mentioned making > a point as if that in itself was sufficient. Context. Context. Context. Sufficient justification for what it was used for. You do not seriously believe that that needs to be spelled out? >> I would not, for instance, destroy Nikos's server, data, or access to >> either, to make a point; and history will confirm this. > > No it doesn't. No? He gave me his root password - check the list archives. I did none of the above three destructive actions (nor any other destructive action), even though it would have made my point much stronger to do so. ChrisA From antoon.pardon at rece.vub.ac.be Mon Sep 16 05:40:44 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 16 Sep 2013 11:40:44 +0200 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> Message-ID: <5236D21C.5080900@rece.vub.ac.be> Op 16-09-13 10:48, Chris Angelico schreef: > On Mon, Sep 16, 2013 at 6:43 PM, Antoon Pardon > wrote: >> Op 16-09-13 10:19, Chris Angelico schreef: >>> It's a contribution that SAYS that it looks carelessly written. I >>> think most people here are intelligent enough to know that that's >>> different from actual carelessness. >> >> The question is, should they care about that difference. The end >> result is a contribution that is just as hard to read. > > Is it, really? I throw the question open: Is it really just as > difficult to read a deliberately-pointed-out sloppiness as an actual > one? And is it as much of a problem to the list? Do you think "improt" is easier to read when written so deliberatly instead of out of carelessness? >>> In a debate, you make points and counterpoints. In most debates, you >>> also gain (or lose) "points for style". Steven scored plenty of the >>> latter IMO. >> >> And why should we accept you as the arbiter for this? > > "We" shouldn't. Style points are per-listener. In my eyes he did well. > You may well disagree. Why do you keep introducing your personal appreciations while at the same time you admit they don't carry much weight. >>> You're here making a straw-man and a false dichotomy; I >>> believe that "making a point" is sufficient justification for what >>> Steven and I did, but I don't think it justifies "any kind of means". >> >> Then your argument was incomplete, because it just mentioned making >> a point as if that in itself was sufficient. > > Context. Context. Context. Sufficient justification for what it was > used for. You do not seriously believe that that needs to be spelled > out? Your context adds nothing. The only thing that the context would add, is that in this specific case you think that the end justifies the means but it doesn't explain in any way on what grounds you think so. Those that took Nikos to task earlier for his behaviour probably though their end justified the means too. So yes, if you don't want to give the impression that you are simply ad hoccing what you personnally don't have a problem with, you'd better spell a few things out. >>> I would not, for instance, destroy Nikos's server, data, or access to >>> either, to make a point; and history will confirm this. >> >> No it doesn't. > > No? He gave me his root password - check the list archives. I did none > of the above three destructive actions (nor any other destructive > action), even though it would have made my point much stronger to do > so. You behaved in a way some people clearly thought of a questionable. So for those people you have established you are prepared to exhibit questionable behaviour to make your point. So I think there are a number of people who will think of you as not trustable enough to withhold the behaviour in question here, when you think it would be necessary to make your point. -- Antoon Pardon From nikos.gr33k at gmail.com Mon Sep 16 05:45:25 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Mon, 16 Sep 2013 12:45:25 +0300 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> Message-ID: ???? 16/9/2013 12:40 ??, ?/? Antoon Pardon ??????: > Op 16-09-13 10:48, Chris Angelico schreef: >> On Mon, Sep 16, 2013 at 6:43 PM, Antoon Pardon >> wrote: >>> Op 16-09-13 10:19, Chris Angelico schreef: >>>> It's a contribution that SAYS that it looks carelessly written. I >>>> think most people here are intelligent enough to know that that's >>>> different from actual carelessness. >>> >>> The question is, should they care about that difference. The end >>> result is a contribution that is just as hard to read. >> >> Is it, really? I throw the question open: Is it really just as >> difficult to read a deliberately-pointed-out sloppiness as an actual >> one? And is it as much of a problem to the list? > > Do you think "improt" is easier to read when written so deliberatly > instead of out of carelessness? > >>>> In a debate, you make points and counterpoints. In most debates, you >>>> also gain (or lose) "points for style". Steven scored plenty of the >>>> latter IMO. >>> >>> And why should we accept you as the arbiter for this? >> >> "We" shouldn't. Style points are per-listener. In my eyes he did well. >> You may well disagree. > > Why do you keep introducing your personal appreciations while at the > same time you admit they don't carry much weight. > >>>> You're here making a straw-man and a false dichotomy; I >>>> believe that "making a point" is sufficient justification for what >>>> Steven and I did, but I don't think it justifies "any kind of means". >>> >>> Then your argument was incomplete, because it just mentioned making >>> a point as if that in itself was sufficient. >> >> Context. Context. Context. Sufficient justification for what it was >> used for. You do not seriously believe that that needs to be spelled >> out? > > Your context adds nothing. The only thing that the context would add, > is that in this specific case you think that the end justifies the means > but it doesn't explain in any way on what grounds you think so. Those > that took Nikos to task earlier for his behaviour probably though their > end justified the means too. > > So yes, if you don't want to give the impression that you are simply > ad hoccing what you personnally don't have a problem with, you'd > better spell a few things out. > >>>> I would not, for instance, destroy Nikos's server, data, or access to >>>> either, to make a point; and history will confirm this. >>> >>> No it doesn't. >> >> No? He gave me his root password - check the list archives. I did none >> of the above three destructive actions (nor any other destructive >> action), even though it would have made my point much stronger to do >> so. > > You behaved in a way some people clearly thought of a questionable. So > for those people you have established you are prepared to exhibit > questionable behaviour to make your point. So I think there are a > number of people who will think of you as not trustable enough to > withhold the behaviour in question here, when you think it would be > necessary to make your point. > Look, i want this to stop. Open your own thread and discuss this if you like. This is a thread i opened for a specific question and all i see its irrelevant answers. From j.j.molenaar at gmail.com Mon Sep 16 06:06:06 2013 From: j.j.molenaar at gmail.com (Joost Molenaar) Date: Mon, 16 Sep 2013 12:06:06 +0200 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> Message-ID: > Look, > > i want this to stop. > Open your own thread and discuss this if you like. > This is a thread i opened for a specific question and all i see its > irrelevant answers. Hi Ferrous, The problem is not in your Python code. You can debug it from the command line by typing the 'echo ... | mailx' command your Python code is executing. Somewhere on your local SMTP or on Google's SMTP, your message is not being processed the way you want it. There are many things that could cause this -- SPF, DKIM, reverse DNS not being correct, the From address being 'faked', or one of about a hunderd other factors. It's most likely an issue in your local SMTP server's configuration. You'll have to dive into the logs and do some research on how SMTP works nowadays to find out what's happening. But think about this: if I could send mail as nikos.gr33k at gmail.com, just by typing a shell command, how could we ever trust e-mail to be from who it really is? What if I send mail as barack.obama at whitehouse.gov? What you're doing may look like spam from Google's point of view, and that's why I think you're not receiving the message. From denismfmcmahon at gmail.com Mon Sep 16 07:21:56 2013 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Mon, 16 Sep 2013 11:21:56 +0000 (UTC) Subject: Tryign to send mail via a python script by using the local MTA References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> Message-ID: On Mon, 16 Sep 2013 12:06:06 +0200, Joost Molenaar wrote: > It's most likely an issue in your local SMTP server's configuration. I'm not convinced about that. All the evidence is that OPs local mta delivers the message to google. I think the issue is that google are deciding the message is junk and dropping it in the bit recycling bin. This is just as likely to be a feature of the random_char(50) subject and random_char(500) message text as it is any local mta settings. I have no idea what OPs random_char(x) does, but I also see no proof it doesn't insert data that's illegal in subject or body. Even if it creates a wholly valid message subject and body, it might look like something spammy to google. starttls suggests that whatever his mta is, it's using some form of auth to communicate with gmail. It looks like his mail is delivered to the google servers. If he's trying to prove communication works, he might be better off using a message subject of "test" and a message body of "this is a test message". -- Denis McMahon, denismfmcmahon at gmail.com From nikos.gr33k at gmail.com Mon Sep 16 07:37:48 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Mon, 16 Sep 2013 14:37:48 +0300 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> Message-ID: ???? 16/9/2013 2:21 ??, ?/? Denis McMahon ??????: > On Mon, 16 Sep 2013 12:06:06 +0200, Joost Molenaar wrote: > >> It's most likely an issue in your local SMTP server's configuration. > > I'm not convinced about that. All the evidence is that OPs local mta > delivers the message to google. I think the issue is that google are > deciding the message is junk and dropping it in the bit recycling bin. > > This is just as likely to be a feature of the random_char(50) subject and > random_char(500) message text as it is any local mta settings. I have no > idea what OPs random_char(x) does, but I also see no proof it doesn't > insert data that's illegal in subject or body. Even if it creates a > wholly valid message subject and body, it might look like something spammy > to google. > > starttls suggests that whatever his mta is, it's using some form of auth > to communicate with gmail. It looks like his mail is delivered to the > google servers. > > If he's trying to prove communication works, he might be better off using > a message subject of "test" and a message body of "this is a test > message". > Hello Denis and thanks for dropping into the conversation. here is the code again with the random function definition: # ================================================================================================================= # if html form is submitted then send user mail # ================================================================================================================= def random_char( y, chars=string.ascii_uppercase + string.digits ): return ''.join( random.choice(chars) for x in range(y) ) for times in range(0, 10): try: # prepare mail data FROM = random_char(8) + '@' + random_char(5) + '.com' TO = "nkouras at ath.forthnet.gr" SUBJECT = random_char( 50 ) MESSAGE = random_char( 500 ) os.system( "echo %s | mailx -v -r %s -s %s %s" % (MESSAGE, FROM, SUBJECT, TO) ) print( "

%s? ???????? ???? %s ?????????!

" % (times, TO) ) except Exception as e: print( "sendmail => ", date, repr( sys.exc_info() ) ) sys.exit(0) ================================================================= i have sent 10 mails to my personal Google account and i though they were never get delivered but it seems that every half an hour or so, one-by-one come into appearance into my GMail account which i access via Thunderbird! I don't know whats delaying them so long but they do come. What i want now is to be able to alter the hostname of my server so the mails wont indicate that they derive from superhost.gr as they aare now sen in the mail headers. I will show you an example when one more mail arrive into my gmail account. From modelnine at modelnine.org Mon Sep 16 07:44:27 2013 From: modelnine at modelnine.org (Heiko Wundram) Date: Mon, 16 Sep 2013 13:44:27 +0200 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> Message-ID: <5236EF1B.5000800@modelnine.org> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Am 16.09.2013 13:37, schrieb Ferrous Cranus: > What i want now is to be able to alter the hostname of my server so > the mails wont indicate that they derive from superhost.gr as they > aare now sen in the mail headers. There is no way to do that, as the Received:-header which you complain about is inserted by Google mail servers. - -- - --- Heiko. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.20 (MingW32) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJSNu8bAAoJEDMqpHf921/SFjwH/RXH79ynaWTkdeYWc3koAPvv wQJKaiYy0FMJgV0JoZqWcg6xc/gEfoyBVvMlxTjSI9Jq44Ay6p3xYl4mCV9Oxplc nx3SD8XKE6HV8H8cdUE+MAVxcI4mhz43so6yG7vWFJskuKZMC4zCwnP3F2Wt3zNK EpgYyyKSCG+5KOhnOryw3lVQ0qlsqp02/cEQbn3iWtoe5ojh8qFr+bHL1vs02gtK 16YgKXre+69ne1hs4Hcyj1OKzYHU+YJmP6WTbdIXFXv1ujS3pf0vjpPWLX8f02Y1 n0HHBL0hWvm9+rbxYXera75jQUqY0v042fDjajhKNa/Sq36OBeoW6vt5hysDBxc= =4HLT -----END PGP SIGNATURE----- From nikos.gr33k at gmail.com Mon Sep 16 08:11:57 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Mon, 16 Sep 2013 15:11:57 +0300 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> Message-ID: ???? 16/9/2013 2:44 ??, ?/? Heiko Wundram ??????: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Am 16.09.2013 13:37, schrieb Ferrous Cranus: >> What i want now is to be able to alter the hostname of my server so >> the mails wont indicate that they derive from superhost.gr as they >> aare now sen in the mail headers. > > There is no way to do that, as the Received:-header which you complain > about is inserted by Google mail servers. true. Even if now i have stopped using Google's SMTP Server as a means for sending out mails and i have decided to use my local MTA instead, at the very moment Google's POP servers receive the mail they still add a RECEIVE header revealing the hostname of the server that initiated the contact. Correct? But even so, if we alter for example the hostname of our server to a different name then wouldn't Google use that to identify the server thus protecting the real identity(hostname that is) of the server that initiated the connection? From modelnine at modelnine.org Mon Sep 16 08:17:23 2013 From: modelnine at modelnine.org (Heiko Wundram) Date: Mon, 16 Sep 2013 14:17:23 +0200 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> Message-ID: <5236F6D3.8020304@modelnine.org> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Am 16.09.2013 14:11, schrieb Ferrous Cranus: > But even so, if we alter for example the hostname of our server to > a different name then wouldn't Google use that to identify the > server thus protecting the real identity(hostname that is) of the > server that initiated the connection? Why on earth would you want to do that? Mail routing headers are there for a reason. - -- - --- Heiko. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.20 (MingW32) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJSNvbTAAoJEDMqpHf921/SUMoH/2iX9pw0DiOWqHzAj1igbswY tlQVigpz8eprFpsl84JW0+NAOFcpy65VdmwynJ57+qhHvChpdygGoNYjtStP37nF oYbMNHs2gRA+dbhl3xxjedGgIzQinGM7aiy+7ZGU/KIGHorMykV0eUDQaObklFNb oepbNMu1yo2U2PWyBHxlH8iehyECFdeKfLRJX6YrkT5jSS7EKKn6UuaCLKRMYJNN sClGe4J5x5GnIsPtPSWK73rdmYtY/vLmM9P4tDKCBAJvdW5nU52EXLlMNzWu8lPS wvg6bor1/meYPxfzIcmIvKTiYZ+omkmQ8iPkOGEupPCKp8SRB9J2iq8nQA0mYo4= =1cDc -----END PGP SIGNATURE----- From antoon.pardon at rece.vub.ac.be Mon Sep 16 08:56:18 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 16 Sep 2013 14:56:18 +0200 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> Message-ID: <5236FFF2.5050706@rece.vub.ac.be> Op 16-09-13 14:11, Ferrous Cranus schreef: > ???? 16/9/2013 2:44 ??, ?/? Heiko Wundram ??????: >> -----BEGIN PGP SIGNED MESSAGE----- >> Hash: SHA1 >> >> Am 16.09.2013 13:37, schrieb Ferrous Cranus: >>> What i want now is to be able to alter the hostname of my server so >>> the mails wont indicate that they derive from superhost.gr as they >>> aare now sen in the mail headers. >> >> There is no way to do that, as the Received:-header which you complain >> about is inserted by Google mail servers. > > true. > Even if now i have stopped using Google's SMTP Server as a means for > sending out mails and i have decided to use my local MTA instead, at the > very moment Google's POP servers receive the mail they still add a > RECEIVE header revealing the hostname of the server that initiated the > contact. Correct? > > But even so, if we alter for example the hostname of our server to a > different name then wouldn't Google use that to identify the server thus > protecting the real identity(hostname that is) of the server that > initiated the connection? No, google will probably find out that the name your server identifies with, will not correspond with the IP address it is connected to and will write a receive line that will reflect that fact, using reverse DNS to report the real hostname of your computer. -- Antoon Pardon From nikos.gr33k at gmail.com Mon Sep 16 11:02:20 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Mon, 16 Sep 2013 18:02:20 +0300 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> Message-ID: ???? 16/9/2013 3:56 ??, ?/? Antoon Pardon ??????: > Op 16-09-13 14:11, Ferrous Cranus schreef: >> ???? 16/9/2013 2:44 ??, ?/? Heiko Wundram ??????: >>> -----BEGIN PGP SIGNED MESSAGE----- >>> Hash: SHA1 >>> >>> Am 16.09.2013 13:37, schrieb Ferrous Cranus: >>>> What i want now is to be able to alter the hostname of my server so >>>> the mails wont indicate that they derive from superhost.gr as they >>>> aare now sen in the mail headers. >>> >>> There is no way to do that, as the Received:-header which you complain >>> about is inserted by Google mail servers. >> >> true. >> Even if now i have stopped using Google's SMTP Server as a means for >> sending out mails and i have decided to use my local MTA instead, at the >> very moment Google's POP servers receive the mail they still add a >> RECEIVE header revealing the hostname of the server that initiated the >> contact. Correct? >> >> But even so, if we alter for example the hostname of our server to a >> different name then wouldn't Google use that to identify the server thus >> protecting the real identity(hostname that is) of the server that >> initiated the connection? > > No, google will probably find out that the name your server identifies > with, will not correspond with the IP address it is connected to and > will write a receive line that will reflect that fact, using reverse > DNS to report the real hostname of your computer. We need to try it to see if it will work, or perhaps we can alter both the hostname and ip address variables on the server to some other values so that google will use them too. It will not detect the real hostname or the real ip this way since both values will be not true. From denismfmcmahon at gmail.com Mon Sep 16 15:09:54 2013 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Mon, 16 Sep 2013 19:09:54 +0000 (UTC) Subject: Tryign to send mail via a python script by using the local MTA References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> Message-ID: On Mon, 16 Sep 2013 18:02:20 +0300, Ferrous Cranus wrote: > We need to try it to see if it will work, or perhaps we can alter both > the hostname and ip address variables on the server to some other values > so that google will use them too. > > It will not detect the real hostname or the real ip this way since both > values will be not true. It may however detect that your are presenting an ip and or hostname that does not match the host you are connecting with, and increase the spf score on the messages to the point that the messages get rejected either in the google mta or downstream due to their spf score. -- Denis McMahon, denismfmcmahon at gmail.com From joel.goldstick at gmail.com Mon Sep 16 17:07:34 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 16 Sep 2013 17:07:34 -0400 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> Message-ID: On Mon, Sep 16, 2013 at 3:09 PM, Denis McMahon wrote: > On Mon, 16 Sep 2013 18:02:20 +0300, Ferrous Cranus wrote: > > > We need to try it to see if it will work, or perhaps we can alter both > > the hostname and ip address variables on the server to some other values > > so that google will use them too. > > > > It will not detect the real hostname or the real ip this way since both > > values will be not true. > > It may however detect that your are presenting an ip and or hostname that > does not match the host you are connecting with, and increase the spf > score on the messages to the point that the messages get rejected either > in the google mta or downstream due to their spf score. > > -- > Denis McMahon, denismfmcmahon at gmail.com > -- > https://mail.python.org/mailman/listinfo/python-list > Nikos, You have to start with a historical perspective. Email was very open in the beginning of the internet. Before there were bad actors. Since that time, email has become the internet service most used for bad purposes, to deliver bad payloads, spoof people into visiting fake websites to induce them to give away private information, etc. So, the email services have gotten more particular about what they deem safe email in lots of different ways. If you want to do these various odd and misleading things to the emails you send out, you will have to understand how to 'beat the systems' that have been employed to stop that stuff. Having read your questions here for the last year(s) I don't believe this is an area in which you excel. You always want quick answers to questions that often show your complete lack basic understanding of the question domain. If you really want to plod along with this email spoofing, why not take a couple of weeks to read all about how email works on the internet, how email has been used to deliver viruses and spoofing schemes. After you understand that stuff well enough to show your competence in a forum where there are other email experts, as your questions there. As has been pointed out by several people here, your questions are not python language issues, they are issues relating to how email protocols work. So, study up and go to an email experts group and good luck! -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From nikos.gr33k at gmail.com Mon Sep 16 17:18:18 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 17 Sep 2013 00:18:18 +0300 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> Message-ID: ???? 16/9/2013 10:09 ??, ?/? Denis McMahon ??????: > On Mon, 16 Sep 2013 18:02:20 +0300, Ferrous Cranus wrote: > >> We need to try it to see if it will work, or perhaps we can alter both >> the hostname and ip address variables on the server to some other values >> so that google will use them too. >> >> It will not detect the real hostname or the real ip this way since both >> values will be not true. > > It may however detect that your are presenting an ip and or hostname that > does not match the host you are connecting with, and increase the spf > score on the messages to the point that the messages get rejected either > in the google mta or downstream due to their spf score. > We have to try it to know for sure. For example do ou know how can a later the hostname the MTA uses to identify the server? From steve+comp.lang.python at pearwood.info Mon Sep 16 19:41:12 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Sep 2013 23:41:12 GMT Subject: Tryign to send mail via a python script by using the local MTA References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> Message-ID: <52379718$0$29988$c3e8da3$5496439d@news.astraweb.com> On Mon, 16 Sep 2013 18:02:20 +0300, Ferrous Cranus wrote: > We need to try it to see if it will work, or perhaps we can alter both > the hostname and ip address variables on the server to some other values > so that google will use them too. > > It will not detect the real hostname or the real ip this way since both > values will be not true. Are you planning on sending spam? Or some other criminal activity? I cannot fathom for the life of me a legitimate reason for your website to use a fake IP address and hostname when sending email. -- Steven From modelnine at modelnine.org Tue Sep 17 06:46:39 2013 From: modelnine at modelnine.org (Heiko Wundram) Date: Tue, 17 Sep 2013 12:46:39 +0200 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: <52379718$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> <52379718$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5238330F.2060200@modelnine.org> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Am 17.09.2013 01:41, schrieb Steven D'Aprano: > I cannot fathom for the life of me a legitimate reason for your > website to use a fake IP address and hostname when sending email. In addition to that: it's amazing that Nikos thinks TCP will still work in the presence of spoofed IP addresses. Email without TCP is a challenge, at the least. - -- - --- Heiko. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.20 (MingW32) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJSODMPAAoJEDMqpHf921/SC0YH/3rCWDcX+rzJKonfeJXUYNxz nbrBPDsoZf6xPh0socOn88TrzgbZewhWf2l3dHAPOKxTAwUWjRjygatTccBmZur9 6B+t410Nq7axz5+0jg4OwBSOQVt3jr0YInK3vWzq4nd0V0cHchvZzfrdSmnEloDU V3wIPhBM7MEavyuvrxhutIM8DxA/0z6L/cLhwnpHfE6AxVMeGh/dHhGK9eaxJ03C pfPWgb2fuCRHrOd3+cLUx3ZFF6YkK00PZzICFhkx236K8iaTvBgqIsod2tpyP6+t H9qlXCfxit1d6nEzTJavx4suBGStcbhDr1C6VlDaPjfVH+w8842h/0QLhTsMXjY= =K/XL -----END PGP SIGNATURE----- From joel.goldstick at gmail.com Tue Sep 17 07:55:13 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 17 Sep 2013 07:55:13 -0400 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: <5238330F.2060200@modelnine.org> References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> <52379718$0$29988$c3e8da3$5496439d@news.astraweb.com> <5238330F.2060200@modelnine.org> Message-ID: In honour of the value of mailing lists in general lets stop this thread since once again the troll pattern repeats ad infinitum. At least if you want to add to this nonsense, read each of the (several?) dozen entries. 1. a seemingly earnest question is asked with something to do with python. The question looks like it is from an very anxious novice 2. errors are pointed out in the sloppiness of the code and as an aside, the value of code in general is questioned since it is based on assumptions that are completely muddled, misunderstood 3. people start to laugh and grouse "here we go again" 4. The troll whines back that he asked a good and question and people are being mean to him 5. He draws more people into the thread who feel bad he was maligned. 6. the thread seems to go on with some (faux) value as people probe the the basis of the discussion further 7. The troll, ignores every single bit of useful information provided that doesn't serve his interest in keeping this going by slightly altering the questions, or posing new variants, or raising hair-brain notions. In other words he is not discussion his own question, he is TROLLING to keep the thread alive. 8. Someone notices the cycle is complete. Go back for a year to every question asked by the troll who goes by Nikos or Ferrous, or 2 or three other email address (in the same thread!) and see if any of them don't follow this pattern. If you are new here and think this guy is worth your time, you are wasting everyone's time and memory space or disk space to add to these threads Ok, I won't do it again. On Tue, Sep 17, 2013 at 6:46 AM, Heiko Wundram wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Am 17.09.2013 01:41, schrieb Steven D'Aprano: > > I cannot fathom for the life of me a legitimate reason for your > > website to use a fake IP address and hostname when sending email. > > In addition to that: it's amazing that Nikos thinks TCP will still > work in the presence of spoofed IP addresses. Email without TCP is a > challenge, at the least. > > - -- > - --- Heiko. > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v2.0.20 (MingW32) > Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ > > iQEcBAEBAgAGBQJSODMPAAoJEDMqpHf921/SC0YH/3rCWDcX+rzJKonfeJXUYNxz > nbrBPDsoZf6xPh0socOn88TrzgbZewhWf2l3dHAPOKxTAwUWjRjygatTccBmZur9 > 6B+t410Nq7axz5+0jg4OwBSOQVt3jr0YInK3vWzq4nd0V0cHchvZzfrdSmnEloDU > V3wIPhBM7MEavyuvrxhutIM8DxA/0z6L/cLhwnpHfE6AxVMeGh/dHhGK9eaxJ03C > pfPWgb2fuCRHrOd3+cLUx3ZFF6YkK00PZzICFhkx236K8iaTvBgqIsod2tpyP6+t > H9qlXCfxit1d6nEzTJavx4suBGStcbhDr1C6VlDaPjfVH+w8842h/0QLhTsMXjY= > =K/XL > -----END PGP SIGNATURE----- > -- > https://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From modelnine at modelnine.org Tue Sep 17 08:22:23 2013 From: modelnine at modelnine.org (Heiko Wundram) Date: Tue, 17 Sep 2013 14:22:23 +0200 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> <52379718$0$29988$c3e8da3$5496439d@news.astraweb.com> <5238330F.2060200@modelnine.org> Message-ID: <5238497F.2090807@modelnine.org> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Am 17.09.2013 13:55, schrieb Joel Goldstick: > At least if you want to add to this nonsense, read each of the > (several?) dozen entries. Actually, I have read each of the troll cycles (just as I read much of clp, although I haven't participated much for the last five years), and found most of them to be rather interesting reads (in their digression from the original topic). And: I actually find it rather valuable answering indirectly to things noticed "along the ride" (or reading what other people answer indirectly in the same manner) - see my post in this thread where I pointed out that the original code actually does not sanitize inputs to a shell command to send mail. But, again, your impression may differ, and I can respect that. - -- - --- Heiko. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.20 (MingW32) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJSOEl/AAoJEDMqpHf921/SAJQIAI48Kzz0js1QqMDkotmMZfdE XJYwsWlRXtaPhRy1VEGKHiSgCEd71/IVDUOPEv5TuJMy9zfsW1McexrYMW0NW63J RiAlDmLSITfdPRYqPgmOTA4MqgJ3V2/oAzOpYXwPqs8Qdt92AX5Tr5itDFgua18T TSdsD4gNudtIMUBkACzMjJKGyxrHvFFhGpUHlFh5swrZhflaGm1TuCWwz3ojTSbG yoQRPe1ylSjcxkJesaKXR8mIaUMq4mrUaChBe+FwoCJXXs8kkX/EO3KULvKCxQGU lzsom+b/eTaxB/ttyHwbt7QSsYq1ko2fIeqqDD/jmhTpg5gshOC+JHLs3bUkmMw= =sTJq -----END PGP SIGNATURE----- From nikos.gr33k at gmail.com Tue Sep 17 08:11:59 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 17 Sep 2013 15:11:59 +0300 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> <52379718$0$29988$c3e8da3$5496439d@news.astraweb.com> <5238330F.2060200@modelnine.org> Message-ID: ???? 17/9/2013 2:55 ??, ?/? Joel Goldstick ??????: > In honour of the value of mailing lists in general lets stop this thread > since once again the troll pattern repeats ad infinitum. > > At least if you want to add to this nonsense, read each of the > (several?) dozen entries. > > 1. a seemingly earnest question is asked with something to do with > python. The question looks like it is from an very anxious novice > 2. errors are pointed out in the sloppiness of the code and as an aside, > the value of code in general is questioned since it is based on > assumptions that are completely muddled, misunderstood > 3. people start to laugh and grouse "here we go again" > 4. The troll whines back that he asked a good and question and people > are being mean to him > 5. He draws more people into the thread who feel bad he was maligned. > 6. the thread seems to go on with some (faux) value as people probe the > the basis of the discussion further > 7. The troll, ignores every single bit of useful information provided > that doesn't serve his interest in keeping this going by slightly > altering the questions, or posing new variants, or raising hair-brain > notions. In other words he is not discussion his own question, he is > TROLLING to keep the thread alive. > 8. Someone notices the cycle is complete. > > Go back for a year to every question asked by the troll who goes by > Nikos or Ferrous, or 2 or three other email address (in the same > thread!) and see if any of them don't follow this pattern. If you are > new here and think this guy is worth your time, you are wasting > everyone's time and memory space or disk space to add to these threads > > Ok, I won't do it again. Yes you are doing it. I'm not trolling but trying to solve a specific question and i have provided code i wrote to do that and explained the reason of why i want it to work like this. I wouldn't waste my time trying code so many days until i make it work. If you want to think i'm trolling go ahead and do it but please do it in your own thread not messing up mines. There are members here like Tim Chase who said that they find it interesting to be able to do what i proposed. It's ok if you dont want to help, but spamming my thread with your trolling assumptions towards me is tiresome and if you gonna do it open do it at least in your own thread. From robert.kern at gmail.com Tue Sep 17 08:51:29 2013 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 17 Sep 2013 13:51:29 +0100 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> <52379718$0$29988$c3e8da3$5496439d@news.astraweb.com> <5238330F.2060200@modelnine.org> Message-ID: On 2013-09-17 13:11, Ferrous Cranus wrote: > There are members here like Tim Chase who said that they find it interesting to > be able to do what i proposed. No, he didn't. He was using sarcasm in a vain attempt to inspire you to search the Python documentation where you could easily find the standard SMTP library. http://docs.python.org/2/library/smtplib -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From jake.angulo at gmail.com Thu Sep 19 23:56:57 2013 From: jake.angulo at gmail.com (Jake Angulo) Date: Fri, 20 Sep 2013 13:56:57 +1000 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> <52379718$0$29988$c3e8da3$5496439d@news.astraweb.com> <5238330F.2060200@modelnine.org> Message-ID: Up Robert Kern's reply! I was waiting for smtplib to be mentioned... finally! Instead people simply answer philosophically. I dont want to judge whether OP is a troll or not - but i found a lot of arrogant replies here. I have also worked on an antispam project before, and see through the intents of the OP, but I do not pretend to be a moralist. I was hoping we would strictly discuss code or software architecture here, not morality. Simple question, simple answer pls, in the interest of the Python list. To the OP: You might want to google smtplib, and use that instead of os calling a system command. Smtplib takes care of all the operating system's quirks for you, and still uses the os native sendmail program. On the other hand, the way you are sending email is highly suspect, trying to spoof a domain, random email address, etc. It is not easy to fool most modern email servers nowadays - especially gmail's. They verify first that the sending domain matches the IP of the sender. And if you are trying to do this - it is neither Python's nor the OS fault. Happy coding! On Tue, Sep 17, 2013 at 10:51 PM, Robert Kern wrote: > On 2013-09-17 13:11, Ferrous Cranus wrote: > > There are members here like Tim Chase who said that they find it >> interesting to >> be able to do what i proposed. >> > > No, he didn't. He was using sarcasm in a vain attempt to inspire you to > search the Python documentation where you could easily find the standard > SMTP library. > > http://docs.python.org/2/**library/smtplib > > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless > enigma > that is made terrible by our own mad attempt to interpret it as though it > had > an underlying truth." > -- Umberto Eco > > -- > https://mail.python.org/**mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From antoon.pardon at rece.vub.ac.be Fri Sep 20 02:48:26 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Fri, 20 Sep 2013 08:48:26 +0200 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> <52379718$0$29988$c3e8da3$5496439d@news.astraweb.com> <5238330F.2060200@modelnine.org> Message-ID: <523BEFBA.1070603@rece.vub.ac.be> Op 20-09-13 05:56, Jake Angulo schreef: > Up Robert Kern's reply! > > I was waiting for smtplib to > be mentioned... finally! Instead people simply answer philosophically. > I dont want to judge whether OP is a troll or not - but i found a lot > of arrogant replies here. That is nice. You don't like to judge the OP but you seem to have no trouble judging others > I have also worked on an antispam project > before, and see through the intents of the OP, but I do not pretend to > be a moralist. That doesn't sound right after you judged other replies to be arrogant. > I was hoping we would strictly discuss code or software > architecture here, not morality. Simple question, simple answer pls, in > the interest of the Python list. Well I was hoping, we wouldn't be plagued by trolls or help-vampires or at least that other wouldn't (spoon) feed them. I guess we can always hope. > To the OP: > > You might want to google smtplib, and use that instead of os calling a > system command. Smtplib takes care of all the operating system's quirks > for you, and still uses the os native sendmail program. But that won't help in eliminating all the headers Nikos would like to avoid. Like the receive line that will identify his host. -- Antoon Pardon From robert.kern at gmail.com Fri Sep 20 05:26:00 2013 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 20 Sep 2013 10:26:00 +0100 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> <52379718$0$29988$c3e8da3$5496439d@news.astraweb.com> <5238330F.2060200@modelnine.org> Message-ID: On 2013-09-20 04:56, Jake Angulo wrote: > Up Robert Kern's reply! > > I was waiting for smtplib to be > mentioned... finally! Instead people simply answer philosophically. I dont > want to judge whether OP is a troll or not - but i found a lot of arrogant > replies here. I have also worked on an antispam project before, and see through > the intents of the OP, but I do not pretend to be a moralist. I was hoping we > would strictly discuss code or software architecture here, not morality. Simple > question, simple answer pls, in the interest of the Python list. Please don't valorize my message. I did neither Nikos nor the group any favors. I can only plead dizziness from the whooshing of Tim's sarcasm flying over Nikos' head. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From feedthetroll at gmx.de Fri Sep 20 07:05:30 2013 From: feedthetroll at gmx.de (feedthetroll at gmx.de) Date: Fri, 20 Sep 2013 04:05:30 -0700 (PDT) Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> <52379718$0$29988$c3e8da3$5496439d@news.astraweb.com> <5238330F.2060200@modelnine.org> Message-ID: Hi Jake! Am Freitag, 20. September 2013 05:56:57 UTC+2 schrieb Jake Angulo: > ... > I was waiting for?smtplib?to be mentioned... finally! ?Instead people simply > answer philosophically. ?I dont want to judge whether OP is a troll or not - As you do not seem to know the histrory of this topic I will try to summarize (you can find the plethora of posts in the archive): * Nikos tried to send mails using smtplib via gmail * gmail did not allow him to use arbitrary FROM adresses (whatever FROM-header he used, gmail changed it to the e-mail of his account). evil, evil gmail ;-) * He got many, many hints not to send via gmail but use his own MTA * Nikos configured sendmail to relay mail VIA GMAIL (unfortunately that did not change anything) * while using arbitrary things to find the reason (when you browse the archive you will learn, that nikos does not read postings or docs but uses some sort of artistic or random or just chaotic "trial and error" to solve his problems) * ... he found some other headers he wants to falsify * the only reference to python is, that he wants to use his python-cgi-scripts to change the mailheaders AFTER the mail left his relaying MTA and even after the mail arrives in the inbox of the recipient (received-by-headers, IP-Adresses, ...). The hints to read some docs about TCP/IP, SMTP, ... he ignores as he has to do see http://www.politicsforum.org/images/flame_warriors/flame_62.php (the original by mreed is not reachable today) hth From antoon.pardon at rece.vub.ac.be Tue Sep 17 08:52:51 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 17 Sep 2013 14:52:51 +0200 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> <52379718$0$29988$c3e8da3$5496439d@news.astraweb.com> <5238330F.2060200@modelnine.org> Message-ID: <523850A3.5020709@rece.vub.ac.be> Op 17-09-13 14:11, Ferrous Cranus schreef: > Yes you are doing it. > I'm not trolling but trying to solve a specific question and i have > provided code i wrote to do that and explained the reason of why i want > it to work like this. No you haven't. You have given no explanation at all for why you want to eliminate those headers. Since those headers are added to ease finding the source of email abuse I really am curious to know your motivation for wanting them removed. > I wouldn't waste my time trying code so many days until i make it work. > > If you want to think i'm trolling go ahead and do it but please do it in > your own thread not messing up mines. You are incosiderate by messing up the python list with non python questions. Yet you demand others to be considerate by not messing up your thread. Well you can hope I guess. > There are members here like Tim Chase who said that they find it > interesting to be able to do what i proposed. Tim Chase said no such thing. > It's ok if you dont want to help, but spamming my thread with your > trolling assumptions towards me is tiresome and if you gonna do it open > do it at least in your own thread. We find it tiresome that you keep coming here with non-python questions. That doesn't seem to stop you. So why do you think it should stop others? From invalid at invalid.invalid Tue Sep 17 10:37:44 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 17 Sep 2013 14:37:44 +0000 (UTC) Subject: Tryign to send mail via a python script by using the local MTA References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> <52379718$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-09-17, Heiko Wundram wrote: > > Am 17.09.2013 01:41, schrieb Steven D'Aprano: >> I cannot fathom for the life of me a legitimate reason for your >> website to use a fake IP address and hostname when sending email. > > In addition to that: it's amazing that Nikos thinks TCP will still > work in the presence of spoofed IP addresses. Email without TCP is a > challenge, at the least. Somehow I doubt Nikos is up to the task of settup up UUCP and a bank of dial-up modems. Even if he could manage it, there probably isn't anybody to dial-up... -- Grant Edwards grant.b.edwards Yow! Where's SANDY DUNCAN? at gmail.com From nikos.gr33k at gmail.com Tue Sep 17 11:17:43 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 17 Sep 2013 18:17:43 +0300 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> <52379718$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 17/9/2013 1:46 ??, Heiko Wundram wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Am 17.09.2013 01:41, schrieb Steven D'Aprano: >> I cannot fathom for the life of me a legitimate reason for your >> website to use a fake IP address and hostname when sending email. > > In addition to that: it's amazing that Nikos thinks TCP will still > work in the presence of spoofed IP addresses. Email without TCP is a > challenge, at the least. > > - -- > - --- Heiko. > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v2.0.20 (MingW32) > Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ > > iQEcBAEBAgAGBQJSODMPAAoJEDMqpHf921/SC0YH/3rCWDcX+rzJKonfeJXUYNxz > nbrBPDsoZf6xPh0socOn88TrzgbZewhWf2l3dHAPOKxTAwUWjRjygatTccBmZur9 > 6B+t410Nq7axz5+0jg4OwBSOQVt3jr0YInK3vWzq4nd0V0cHchvZzfrdSmnEloDU > V3wIPhBM7MEavyuvrxhutIM8DxA/0z6L/cLhwnpHfE6AxVMeGh/dHhGK9eaxJ03C > pfPWgb2fuCRHrOd3+cLUx3ZFF6YkK00PZzICFhkx236K8iaTvBgqIsod2tpyP6+t > H9qlXCfxit1d6nEzTJavx4suBGStcbhDr1C6VlDaPjfVH+w8842h/0QLhTsMXjY= > =K/XL > -----END PGP SIGNATURE----- > So cant this be done in python or not? or is a mtetr of configuring the MTA? conf file? From denismfmcmahon at gmail.com Tue Sep 17 12:30:36 2013 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Tue, 17 Sep 2013 16:30:36 +0000 (UTC) Subject: Tryign to send mail via a python script by using the local MTA References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> <52379718$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, 17 Sep 2013 18:17:43 +0300, Ferrous Cranus wrote: > So cant this be done in python or not? > or is a mtetr of configuring the MTA? conf file? Python can not control data that is added to the message after it has left the python program. If you want to retain maximum possible control of the mail process from within python, you need to use a python module that handles the smtp exchange with the destination mta, however even then you can not control the content of header lines added by that destination mta, which will invariably include the real[1] ip address of your system. [1] The ip address that it is sending ack packets to as part of the smtp session, so unless you're using a proxy somewhere, this will be your system's ip address. Can't fake it. If the other system doesn't know your ip address, it can't send acks, and the tcp session fails. -- Denis McMahon, denismfmcmahon at gmail.com From nikos.gr33k at gmail.com Tue Sep 17 17:42:22 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Wed, 18 Sep 2013 00:42:22 +0300 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> <52379718$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 17/9/2013 7:30 ??, Denis McMahon wrote: > On Tue, 17 Sep 2013 18:17:43 +0300, Ferrous Cranus wrote: > >> So cant this be done in python or not? >> or is a mtetr of configuring the MTA? conf file? > > Python can not control data that is added to the message after it has > left the python program. If you want to retain maximum possible control > of the mail process from within python, you need to use a python module > that handles the smtp exchange with the destination mta, however even > then you can not control the content of header lines added by that > destination mta, which will invariably include the real[1] ip address of > your system. > > [1] The ip address that it is sending ack packets to as part of the smtp > session, so unless you're using a proxy somewhere, this will be your > system's ip address. Can't fake it. If the other system doesn't know your > ip address, it can't send acks, and the tcp session fails. > Ah, now we are getting somewhere. So the foreign MTA tests for real time connectivity with the local MTA and it tries to detect a working host and ip address. So even if we alter the hostname and the ip address of our localhost then the smtp procedure will fail correct? From rosuav at gmail.com Tue Sep 17 17:47:46 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 18 Sep 2013 07:47:46 +1000 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> <52379718$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Sep 18, 2013 at 7:42 AM, Ferrous Cranus wrote: > So the foreign MTA tests for real time connectivity with the local MTA and > it tries to detect a working host and ip address. No, the local MTA connects to the foreign MTA. ChrisA From wrw at mac.com Tue Sep 17 18:34:50 2013 From: wrw at mac.com (William Ray Wing) Date: Tue, 17 Sep 2013 18:34:50 -0400 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> <52379718$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sep 17, 2013, at 5:42 PM, Ferrous Cranus wrote: > On 17/9/2013 7:30 ??, Denis McMahon wrote: >> On Tue, 17 Sep 2013 18:17:43 +0300, Ferrous Cranus wrote: >> >>> So cant this be done in python or not? >>> or is a mtetr of configuring the MTA? conf file? >> >> Python can not control data that is added to the message after it has >> left the python program. If you want to retain maximum possible control >> of the mail process from within python, you need to use a python module >> that handles the smtp exchange with the destination mta, however even >> then you can not control the content of header lines added by that >> destination mta, which will invariably include the real[1] ip address of >> your system. >> >> [1] The ip address that it is sending ack packets to as part of the smtp >> session, so unless you're using a proxy somewhere, this will be your >> system's ip address. Can't fake it. If the other system doesn't know your >> ip address, it can't send acks, and the tcp session fails. >> > Ah, now we are getting somewhere. > > So the foreign MTA tests for real time connectivity with the local MTA and it tries to detect a working host and ip address. > > So even if we alter the hostname and the ip address of our localhost then the smtp procedure will fail correct? > -- > https://mail.python.org/mailman/listinfo/python-list I think you need to read up on some of the most basic fundamentals of tcp/ip networking, i.e., the basis of the global internet. EVERY network packet (and I do mean every) packet in an IP network carries both a source and a destination address in its header. These are fundamentally necessary in order to allow the gateway router at the originating site to direct an outgoing packet to its destination, and allow the receiving host at the destination site to craft reply packets. -Bill From davea at davea.name Wed Sep 18 19:55:17 2013 From: davea at davea.name (Dave Angel) Date: Wed, 18 Sep 2013 23:55:17 +0000 (UTC) Subject: Tryign to send mail via a python script by using the local MTA References: <52379718$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 18/9/2013 18:31, Dennis Lee Bieber wrote: > On Tue, 17 Sep 2013 18:34:50 -0400, William Ray Wing > declaimed the following: > > >> >>I think you need to read up on some of the most basic fundamentals of tcp/ip networking, i.e., the basis of the global internet. EVERY network packet (and I do mean every) packet in an IP network carries both a source and a destination address in its header. These are fundamentally necessary in order to allow the gateway router at the originating site to direct an outgoing packet to its destination, and allow the receiving host at the destination site to craft reply packets. >> > > Even worse -- IP packets are wrapped by Ethernet packets which use MAC > addresses for direct routing between nodes... Granted, those MAC addresses > may not propagate beyond the next defined gateway IP host, but they do > (theoretically) identify the exact NIC that sent the packet. Noting reliable about the MAC adress. Many systems permit or even encourage spoofing. And it gets overwritten at each hop, so the other end cannot easily determine the number a client may have made up. The first time I added a router to my cable modem, I had to tell it to use (spoof) the old MAC address so that the cable modem didn't have to be reprogrammed. -- DaveA From denismfmcmahon at gmail.com Wed Sep 18 01:20:19 2013 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Wed, 18 Sep 2013 05:20:19 +0000 (UTC) Subject: Tryign to send mail via a python script by using the local MTA References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> <52379718$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, 18 Sep 2013 00:42:22 +0300, Ferrous Cranus wrote: > So the foreign MTA tests for real time connectivity with the local MTA > and it tries to detect a working host and ip address. No. I strongly suggest that you stop trying to write software that transmits data across tcp/ip networks until you understand how tcp/ip networks function. This NG is not a networking for dummies course. -- Denis McMahon, denismfmcmahon at gmail.com From piet at vanoostrum.org Tue Sep 17 22:58:35 2013 From: piet at vanoostrum.org (Piet van Oostrum) Date: Tue, 17 Sep 2013 22:58:35 -0400 Subject: Tryign to send mail via a python script by using the local MTA References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> <52379718$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: Ferrous Cranus writes: > So cant this be done in python or not? > or is a mtetr of configuring the MTA? conf file? You could write a python program that uses Gmail's web interface. But it is tricky, and if Gmail would change its inyterface you get stuck, and have to do it again, risking that temporarily your email cannot be delivered. I think you should give up this unholy idea, and just stick with the standard. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From nikos.gr33k at gmail.com Sat Sep 21 05:21:12 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Sat, 21 Sep 2013 12:21:12 +0300 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <52379718$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 18/9/2013 2:29 ??, Dennis Lee Bieber wrote: > On Tue, 17 Sep 2013 18:17:43 +0300, Ferrous Cranus > declaimed the following: > >> So cant this be done in python or not? >> or is a mtetr of configuring the MTA? conf file? > > You can't... Those headers get added by the ISP and any other host the > mail passes through. > > The more you fake the originator IP/user the more the subsequent > servers will add flags that they can't confirm who sent the mail... And > eventually some filter may drop it as spam. > ?es Denis every foreign MTA adds headers as mail passes over it ( as proved to be done at least from the gmail's smtp) But if we set up our local MTA to modify the headers, hostname, ip address, user) to our own likign then the local MTA will connect to the foreign MTA and passes it out modifed data , not the real one. ?sn't this possible? that is to fake our hostname and ip address? From wrw at mac.com Sat Sep 21 09:29:26 2013 From: wrw at mac.com (William Ray Wing) Date: Sat, 21 Sep 2013 09:29:26 -0400 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <52379718$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sep 21, 2013, at 5:21 AM, ????? wrote: > On 18/9/2013 2:29 ??, Dennis Lee Bieber wrote: >> On Tue, 17 Sep 2013 18:17:43 +0300, Ferrous Cranus >> declaimed the following: >> >>> So cant this be done in python or not? >>> or is a mtetr of configuring the MTA? conf file? >> >> You can't... Those headers get added by the ISP and any other host the >> mail passes through. >> >> The more you fake the originator IP/user the more the subsequent >> servers will add flags that they can't confirm who sent the mail... And >> eventually some filter may drop it as spam. >> > ?es Denis every foreign MTA adds headers as mail passes over it ( as proved to be done at least from the gmail's smtp) > > But if we set up our local MTA to modify the headers, hostname, ip address, user) to our own likign then the local MTA will connect to the foreign MTA and passes it out modifed data , not the real one. > > ?sn't this possible? that is to fake our hostname and ip address? > -- > https://mail.python.org/mailman/listinfo/python-list ????? , You CLEARLY don't understand. Please. There are Mail headers and there are IP packet network headers. They have to agree with each other or spam/malware alarms go off. Even if you fake the mail headers, there is no way you can use fake IP packet headers, they are necessary for the underlying network hardware to work. -Bill From wuwei23 at gmail.com Sun Sep 22 21:17:43 2013 From: wuwei23 at gmail.com (alex23) Date: Mon, 23 Sep 2013 11:17:43 +1000 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <52379718$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 21/09/2013 11:29 PM, William Ray Wing wrote: > ????? , > You CLEARLY don't understand. Just a public service reminder that Nikos' behaviour is _consistently_ that of his prefered nom de plume: "Ferrous Cranus is utterly impervious to reason, persuasion and new ideas, and when engaged in battle he will not yield an inch in his position regardless of its hopelessness" http://www.politicsforum.org/images/flame_warriors/flame_62.php From nikos.gr33k at gmail.com Mon Sep 16 12:15:22 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Mon, 16 Sep 2013 19:15:22 +0300 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> Message-ID: ???? 16/9/2013 3:56 ??, ?/? Antoon Pardon ??????: > Op 16-09-13 14:11, Ferrous Cranus schreef: >> ???? 16/9/2013 2:44 ??, ?/? Heiko Wundram ??????: >>> -----BEGIN PGP SIGNED MESSAGE----- >>> Hash: SHA1 >>> >>> Am 16.09.2013 13:37, schrieb Ferrous Cranus: >>>> What i want now is to be able to alter the hostname of my server so >>>> the mails wont indicate that they derive from superhost.gr as they >>>> aare now sen in the mail headers. >>> >>> There is no way to do that, as the Received:-header which you complain >>> about is inserted by Google mail servers. >> >> true. >> Even if now i have stopped using Google's SMTP Server as a means for >> sending out mails and i have decided to use my local MTA instead, at the >> very moment Google's POP servers receive the mail they still add a >> RECEIVE header revealing the hostname of the server that initiated the >> contact. Correct? >> >> But even so, if we alter for example the hostname of our server to a >> different name then wouldn't Google use that to identify the server thus >> protecting the real identity(hostname that is) of the server that >> initiated the connection? > > No, google will probably find out that the name your server identifies > with, will not correspond with the IP address it is connected to and > will write a receive line that will reflect that fact, using reverse > DNS to report the real hostname of your computer. > ?his si the headers i would like to delete because i dont want them to be used when sending mail: X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - my.superhost.gr X-AntiAbuse: Original Domain - superhost.gr X-AntiAbuse: Originator/Caller UID/GID - [500 501] / [47 12] X-AntiAbuse: Sender Address Domain - mail.org X-Get-Message-Sender-Via: my.superhost.gr: authenticated_id: nikos/only user confirmed/virtual account not confirmed Can these be remoevd when i send mail? From nikos.gr33k at gmail.com Mon Sep 16 12:23:15 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Mon, 16 Sep 2013 19:23:15 +0300 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> Message-ID: ???? 16/9/2013 7:15 ??, ?/? Ferrous Cranus ??????: > ???? 16/9/2013 3:56 ??, ?/? Antoon Pardon ??????: >> Op 16-09-13 14:11, Ferrous Cranus schreef: >>> ???? 16/9/2013 2:44 ??, ?/? Heiko Wundram ??????: >>>> -----BEGIN PGP SIGNED MESSAGE----- >>>> Hash: SHA1 >>>> >>>> Am 16.09.2013 13:37, schrieb Ferrous Cranus: >>>>> What i want now is to be able to alter the hostname of my server so >>>>> the mails wont indicate that they derive from superhost.gr as they >>>>> aare now sen in the mail headers. >>>> >>>> There is no way to do that, as the Received:-header which you complain >>>> about is inserted by Google mail servers. >>> >>> true. >>> Even if now i have stopped using Google's SMTP Server as a means for >>> sending out mails and i have decided to use my local MTA instead, at the >>> very moment Google's POP servers receive the mail they still add a >>> RECEIVE header revealing the hostname of the server that initiated the >>> contact. Correct? >>> >>> But even so, if we alter for example the hostname of our server to a >>> different name then wouldn't Google use that to identify the server thus >>> protecting the real identity(hostname that is) of the server that >>> initiated the connection? >> >> No, google will probably find out that the name your server identifies >> with, will not correspond with the IP address it is connected to and >> will write a receive line that will reflect that fact, using reverse >> DNS to report the real hostname of your computer. >> > ?his si the headers i would like to delete because i dont want them to > be used when sending mail: > > X-AntiAbuse: This header was added to track abuse, please include it > with any abuse report > X-AntiAbuse: Primary Hostname - my.superhost.gr > X-AntiAbuse: Original Domain - superhost.gr > X-AntiAbuse: Originator/Caller UID/GID - [500 501] / [47 12] > X-AntiAbuse: Sender Address Domain - mail.org > X-Get-Message-Sender-Via: my.superhost.gr: authenticated_id: nikos/only > user confirmed/virtual account not confirmed > > Can these be remoevd when i send mail? and this too: Received: from nikos by my.superhost.gr with local (Exim 4.80.1) (envelope-from ) id 1VLam4-0004nG-TJ I wish this not to be displayed. From denismfmcmahon at gmail.com Mon Sep 16 15:07:50 2013 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Mon, 16 Sep 2013 19:07:50 +0000 (UTC) Subject: Tryign to send mail via a python script by using the local MTA References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> Message-ID: On Mon, 16 Sep 2013 19:23:15 +0300, Ferrous Cranus wrote: >> ?his si the headers i would like to delete because i dont want them to >> be used when sending mail: >> X-AntiAbuse: ....... > and this too: > Received: ...... This is probably your mta, not python, see your mta config. OFF TOPIC IN comp.lang.python -- Denis McMahon, denismfmcmahon at gmail.com From wrw at mac.com Mon Sep 16 13:53:09 2013 From: wrw at mac.com (William Ray Wing) Date: Mon, 16 Sep 2013 13:53:09 -0400 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> Message-ID: <953642AC-D0A6-40BB-801F-C1A8E98BA899@mac.com> On Sep 16, 2013, at 12:15 PM, Ferrous Cranus wrote: > ???? 16/9/2013 3:56 ??, ?/? Antoon Pardon ??????: >> Op 16-09-13 14:11, Ferrous Cranus schreef: >>> ???? 16/9/2013 2:44 ??, ?/? Heiko Wundram ??????: >>>> -----BEGIN PGP SIGNED MESSAGE----- >>>> Hash: SHA1 >>>> >>>> Am 16.09.2013 13:37, schrieb Ferrous Cranus: >>>>> What i want now is to be able to alter the hostname of my server so >>>>> the mails wont indicate that they derive from superhost.gr as they >>>>> aare now sen in the mail headers. >>>> >>>> There is no way to do that, as the Received:-header which you complain >>>> about is inserted by Google mail servers. >>> >>> true. >>> Even if now i have stopped using Google's SMTP Server as a means for >>> sending out mails and i have decided to use my local MTA instead, at the >>> very moment Google's POP servers receive the mail they still add a >>> RECEIVE header revealing the hostname of the server that initiated the >>> contact. Correct? >>> >>> But even so, if we alter for example the hostname of our server to a >>> different name then wouldn't Google use that to identify the server thus >>> protecting the real identity(hostname that is) of the server that >>> initiated the connection? >> >> No, google will probably find out that the name your server identifies >> with, will not correspond with the IP address it is connected to and >> will write a receive line that will reflect that fact, using reverse >> DNS to report the real hostname of your computer. >> > ?his si the headers i would like to delete because i dont want them to be used when sending mail: > > X-AntiAbuse: This header was added to track abuse, please include it with any abuse report > X-AntiAbuse: Primary Hostname - my.superhost.gr > X-AntiAbuse: Original Domain - superhost.gr > X-AntiAbuse: Originator/Caller UID/GID - [500 501] / [47 12] > X-AntiAbuse: Sender Address Domain - mail.org > X-Get-Message-Sender-Via: my.superhost.gr: authenticated_id: nikos/only user confirmed/virtual account not confirmed > > Can these be remoevd when i send mail? > -- > https://mail.python.org/mailman/listinfo/python-list You realize that removing those headers will, in all likelihood, make Google reject your mail and refuse to either forward or deliver it. They have been added to reduce spam, and the more you attempt to obfuscate your header information, the more you make your mail look exactly like spam. -Bill From nikos.gr33k at gmail.com Mon Sep 16 17:15:22 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 17 Sep 2013 00:15:22 +0300 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> Message-ID: ???? 16/9/2013 8:53 ??, ?/? William Ray Wing ??????: > On Sep 16, 2013, at 12:15 PM, Ferrous Cranus wrote: > >> ???? 16/9/2013 3:56 ??, ?/? Antoon Pardon ??????: >>> Op 16-09-13 14:11, Ferrous Cranus schreef: >>>> ???? 16/9/2013 2:44 ??, ?/? Heiko Wundram ??????: >>>>> -----BEGIN PGP SIGNED MESSAGE----- >>>>> Hash: SHA1 >>>>> >>>>> Am 16.09.2013 13:37, schrieb Ferrous Cranus: >>>>>> What i want now is to be able to alter the hostname of my server so >>>>>> the mails wont indicate that they derive from superhost.gr as they >>>>>> aare now sen in the mail headers. >>>>> >>>>> There is no way to do that, as the Received:-header which you complain >>>>> about is inserted by Google mail servers. >>>> >>>> true. >>>> Even if now i have stopped using Google's SMTP Server as a means for >>>> sending out mails and i have decided to use my local MTA instead, at the >>>> very moment Google's POP servers receive the mail they still add a >>>> RECEIVE header revealing the hostname of the server that initiated the >>>> contact. Correct? >>>> >>>> But even so, if we alter for example the hostname of our server to a >>>> different name then wouldn't Google use that to identify the server thus >>>> protecting the real identity(hostname that is) of the server that >>>> initiated the connection? >>> >>> No, google will probably find out that the name your server identifies >>> with, will not correspond with the IP address it is connected to and >>> will write a receive line that will reflect that fact, using reverse >>> DNS to report the real hostname of your computer. >>> >> ?his si the headers i would like to delete because i dont want them to be used when sending mail: >> >> X-AntiAbuse: This header was added to track abuse, please include it with any abuse report >> X-AntiAbuse: Primary Hostname - my.superhost.gr >> X-AntiAbuse: Original Domain - superhost.gr >> X-AntiAbuse: Originator/Caller UID/GID - [500 501] / [47 12] >> X-AntiAbuse: Sender Address Domain - mail.org >> X-Get-Message-Sender-Via: my.superhost.gr: authenticated_id: nikos/only user confirmed/virtual account not confirmed >> >> Can these be remoevd when i send mail? >> -- >> https://mail.python.org/mailman/listinfo/python-list > > You realize that removing those headers will, in all likelihood, make Google reject your mail and refuse to either forward or deliver it. They have been added to reduce spam, and the more you attempt to obfuscate your header information, the more you make your mail look exactly like spam. > > -Bill > But i wish to try it, is there a way to try to remove them? For starters, does my MTA add them as additional headers to my mail or Google adds them by default ? From python.list at tim.thechases.com Mon Sep 16 21:40:06 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 16 Sep 2013 20:40:06 -0500 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> Message-ID: <20130916204006.0355b078@bigbox.christie.dr> On 2013-09-17 00:15, Ferrous Cranus wrote: >>> X-AntiAbuse: This header was added to track abuse, please include >>> it with any abuse report X-AntiAbuse: Primary Hostname - >>> my.superhost.gr >>> X-AntiAbuse: Original Domain - superhost.gr >>> X-AntiAbuse: Originator/Caller UID/GID - [500 501] / [47 12] >>> X-AntiAbuse: Sender Address Domain - mail.org >>> X-Get-Message-Sender-Via: my.superhost.gr: authenticated_id: >>> nikos/only user confirmed/virtual account not confirmed > > For starters, does my MTA add them as additional headers to my mail > or Google adds them by default ? Given that there are headers in there that know about your UID/GID, it has to be a locally-running process that adds them. No remote server (even as powerful as Gmail is) should/can know this legitimately without being told. Thus, it's clearly your local MTA. > But i wish to try it, is there a way to try to remove them? You could manage your own SMTP connection. If only Python had some built in library that handled SMTP, that would be great! Then you would be able to instantiate some SMTP object, connect to another server, optionally authenticating, then send mail, and close the connection. That would be so awesome! :-D -tkc From feedthetroll at gmx.de Tue Sep 17 02:15:12 2013 From: feedthetroll at gmx.de (feedthetroll at gmx.de) Date: Mon, 16 Sep 2013 23:15:12 -0700 (PDT) Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> Message-ID: Am Dienstag, 17. September 2013 03:40:06 UTC+2 schrieb Tim Chase: > On 2013-09-17 00:15, Ferrous Cranus wrote: >... >> But i wish to try it, is there a way to try to remove them? > > You could manage your own SMTP connection. If only Python had some > built in library that handled SMTP, that would be great! Then you > would be able to instantiate some SMTP object, connect to another > server, optionally authenticating, then send mail, and close the > connection. That would be so awesome! :-D Cool idea! But bad, bad GMail won't let me fake the FROM-Header. Bad, bad GMail. WHINE! ;-) (Hey, we reached the start of the thread. Infinite loops are sooooooo cool ;-) ) > ... From modelnine at modelnine.org Mon Sep 16 07:32:35 2013 From: modelnine at modelnine.org (Heiko Wundram) Date: Mon, 16 Sep 2013 13:32:35 +0200 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> <5236B356.7030308@rece.vub.ac.be> <5236BD75.5080904@rece.vub.ac.be> <5236C4B7.3070601@rece.vub.ac.be> Message-ID: <5236EC53.4080609@modelnine.org> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Am 16.09.2013 13:21, schrieb Denis McMahon: > If he's trying to prove communication works, he might be better off > using a message subject of "test" and a message body of "this is a > test message". Generally, he might be best off if he didn't use os.system() with string-interpolated (without escaping or any such) and user-specified (!) parameters to send out the mail using mailx though a sub-shell. This begs of using his mailer script for code injection as his web-server user, and I'm amazed that nobody has commented on that so far. - -- - --- Heiko. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.20 (MingW32) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJSNuxTAAoJEDMqpHf921/Sd8IH/2BcapK/dNqbs/PDz3LZLiUS JYYmNaWSjui7KYJsA/A8R3XVaM0eyHkYI8dr8Jx6hPdPJyeE27MCKddF3GlYs17Z iO1AydR2J8kYjXgVLrCWtfH3taB6ryUko6sOe1j/u0hYbQOATxuBPvxTVK4Wmi85 1m8unw9NvlTelAREg6WLudqpE9i115dns87+FTNcgNd3ieppJw+Cv2Mp6z3Yn3he y0W9yMqH1LV4oW/6arZVVIcaWDHCb1I0L++aC8JLnOHYz1osf+34BbHHBcY6Qkty reon+sWKwrlJ56o8Zi1Lx97ymxXxuvUtJS/5WGpRh/XLWYVBGCX3XA42DKqscQk= =xENG -----END PGP SIGNATURE----- From nikos.gr33k at gmail.com Mon Sep 16 04:04:52 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Mon, 16 Sep 2013 11:04:52 +0300 Subject: Tryign to send mail via a python script by using the local MTA In-Reply-To: References: <305a2044-a13e-47f8-9cc1-9e3482424616@googlegroups.com> <52366466$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: ???? 16/9/2013 10:29 ??, ?/? Antoon Pardon ??????: > Op 16-09-13 03:52, Steven D'Aprano schreef: >> Hi Nikos, >> >> I'm now going to put as much care and attention into my answer as you put >> into your question. >> >> Have uy tryed imprting os first? u nmeed to do >> >> improt os >> >> first or it wont work., >> >> >> When you give evidence of caring about the questions you ask, I'll start >> caring about the answers I give you. > > And why do you find it necessary to impart your careless answer on the > list? If you find he doesn't show enough care about the questions he > asks, why don't you just ignore him, instead of showing us all that you > too can contribute in a careless manner? > My question is not careless. I have stated exactly the problem and shown relevant code of what i'm trying to accomplish. 1 have almost 10 responses and not even one of them is being a proper answer to my initial question. My question is clear. From 0x7f494e at gmail.com Sun Sep 15 19:35:50 2013 From: 0x7f494e at gmail.com (0x7f494e at gmail.com) Date: Sun, 15 Sep 2013 16:35:50 -0700 (PDT) Subject: Easiest way to get exit code from os.popen()? In-Reply-To: References: <1193252864.957914.305300@t8g2000prg.googlegroups.com> Message-ID: ???????, 25 ??????? 2007??., 1:12:31 UTC+5 ???????????? Jean-Paul Calderone ???????: > On Wed, 24 Oct 2007 19:07:44 -0000, mrstephengross wrote: > >Hi folks. I'm using os.popen() to run a command; according to the > >documentation, the filehandle.close() oepration is suppsoed to return > >the exit code. However, when I execute something like "exit 5", > >close() returns 1280. Here's the code: > > > > pipe = os.popen("exit 5") > > print pipe.close() # prints 1280 > > > >Am I doing something wrong? Is there an easier way to get the exit > >code? > > >>> import os > >>> os.WEXITSTATUS(1280) > 5 > >>> > > Jean-Paul Big Thanks! :)) From mohsen at pahlevanzadeh.org Sun Sep 15 22:23:26 2013 From: mohsen at pahlevanzadeh.org (Mohsen Pahlevanzadeh) Date: Mon, 16 Sep 2013 06:53:26 +0430 Subject: import problem Message-ID: <1379298206.9698.72.camel@debian> Dear all, i have the following two line codes: ############################ import ui.interface.interface obj = ui.interface.interface.InterfaceCodes() ###########################333 I have same code in another package and work fine. but i get the : #####################################################3 Traceback (most recent call last): File "./main.py", line 31, in from materials.materials import * File "/home/mohsen/codes/amlak/amlak/src/materials/materials.py", line 40, in from ui.interface.interface import * File "/home/mohsen/codes/amlak/amlak/src/ui/interface/interface.py", line 32, in from ui.materialsFrame import * File "/home/mohsen/codes/amlak/amlak/src/ui/materialsFrame.py", line 24, in from ui.materialsFindFrame import * File "/home/mohsen/codes/amlak/amlak/src/ui/materialsFindFrame.py", line 14, in from common.objects.objects import * File "/home/mohsen/codes/amlak/amlak/src/common/objects/objects.py", line 28, in obj = ui.interface.interface.InterfaceCodes() AttributeError: 'module' object has no attribute 'interface' ########################################### When i changed the my code to: #################################################33 from ui.interface.interface import * obj = ui.interface.interface.InterfaceCodes() ##############################################3 I get the : #################################333 raceback (most recent call last): File "./main.py", line 31, in from materials.materials import * File "/home/mohsen/codes/amlak/amlak/src/materials/materials.py", line 40, in from ui.interface.interface import * File "/home/mohsen/codes/amlak/amlak/src/ui/interface/interface.py", line 32, in from ui.materialsFrame import * File "/home/mohsen/codes/amlak/amlak/src/ui/materialsFrame.py", line 24, in from ui.materialsFindFrame import * File "/home/mohsen/codes/amlak/amlak/src/ui/materialsFindFrame.py", line 14, in from common.objects.objects import * File "/home/mohsen/codes/amlak/amlak/src/common/objects/objects.py", line 28, in Obj = ui.interface.interface.InterfaceCodes() NameError: name 'ui' is not defined ############################### Also if i delete "ui.interface.interface" i get the : ########################3333 Traceback (most recent call last): File "./main.py", line 31, in from materials.materials import * File "/home/mohsen/codes/amlak/amlak/src/materials/materials.py", line 40, in from ui.interface.interface import * File "/home/mohsen/codes/amlak/amlak/src/ui/interface/interface.py", line 32, in from ui.materialsFrame import * File "/home/mohsen/codes/amlak/amlak/src/ui/materialsFrame.py", line 24, in from ui.materialsFindFrame import * File "/home/mohsen/codes/amlak/amlak/src/ui/materialsFindFrame.py", line 14, in from common.objects.objects import * File "/home/mohsen/codes/amlak/amlak/src/common/objects/objects.py", line 28, in Obj = InterfaceCodes() NameError: name 'InterfaceCodes' is not defined ############################ You make mme happy if help me.... Yours, Mohsen From steve+comp.lang.python at pearwood.info Sun Sep 15 22:56:31 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Sep 2013 02:56:31 GMT Subject: import problem References: Message-ID: <5236735f$0$29988$c3e8da3$5496439d@news.astraweb.com> On Mon, 16 Sep 2013 06:53:26 +0430, Mohsen Pahlevanzadeh wrote: > Dear all, > > i have the following two line codes: > ############################ > import ui.interface.interface > obj = ui.interface.interface.InterfaceCodes() > ###########################333 > I have same code in another package and work fine. but i get the : > > #####################################################3 This traceback following suggests that your package is a complete tangled mess of wild card imports. Perhaps I am misreading something, but the following suggests that your package is highly coupled, with strong dependencies between different modules. This is a poor design and will give you many, many problems. As you are already having. Do you understand what I mean when I talk about modules being "highly coupled"? Are you a Java or C++ developer learning Python? Your code suggests to me that you might be. If you are, you should read these to get some ideas of how your Java intuitions will lead you astray in Python: http://dirtsimple.org/2004/12/python-is-not-java.html http://dirtsimple.org/2004/12/java-is-not-python-either.html I assume that everything under the "amlak" directory is your code. Is that correct? Here's the traceback again: > Traceback (most > recent call last): > File "./main.py", line 31, in > from materials.materials import * > File "/home/mohsen/codes/amlak/amlak/src/materials/materials.py", line > 40, in > from ui.interface.interface import * > File "/home/mohsen/codes/amlak/amlak/src/ui/interface/interface.py", > line 32, in > from ui.materialsFrame import * > File "/home/mohsen/codes/amlak/amlak/src/ui/materialsFrame.py", line > 24, in > from ui.materialsFindFrame import * > File "/home/mohsen/codes/amlak/amlak/src/ui/materialsFindFrame.py", > line 14, in > from common.objects.objects import * > File "/home/mohsen/codes/amlak/amlak/src/common/objects/objects.py", > line 28, in > obj = ui.interface.interface.InterfaceCodes() > AttributeError: 'module' object has no attribute 'interface' > ########################################### So your main module does a wild-card import from materials.materials, which does a wild-card import from ui.interface.interface, which does a wild-card import from ui.materialsFrame, which does a wild-card import from ui.materialsFindFrame, which does a wild-card import from common.objects.objects, which requires ui.interface.interface to have already been loaded and imported. But it hasn't been, because it is still being imported. The *immediate* problem is that, in effect, before you can import ui.interface.interface, you need to import ui.interface.interface. Obviously this is going to cause you problems. Google on "recursive imports" to learn about the sorts of problems and how to avoid them. The second problem is that, in general, you should try to avoid wild-card imports. They're not always bad, but they were really invented for use in the interactive interpreter so you can do things like this: from math import * sqrt(42) sin(1.5) Using them inside non-interactive code is not forbidden exactly, but it is frowned upon since it makes understanding your code harder. The third problem is that your code layout looks like you are fighting Python, trying to force it to be something it is not. For starters, if you're writing packages that look like this: ui.interface.interface that's simply poor design for Python. My guess is that you might be following the Java convention of putting exactly one class per source file. That is not the way Python code should be written. Modules should contain all the related classes and functions, at least up to the point that the module becomes so large that it is painful to work with. How large is that? In my opinion, this is getting close to the maximum I personally would be comfortable with: http://hg.python.org/cpython/file/3.3/Lib/decimal.py although some people might be happy with large files. But what is important is that related code should be together in the one file, not split across multiple modules and multiple packages. If you are trying to "future proof" your code, and thinking "today it is small, but one day it will be big and will need to be a package with dozens of modules", that doesn't matter. Don't write the code you think you will need in five years. Write the code you need now. Google "YAGNI" for more. I am sorry that I cannot just give you a simple one-line fix for your error. As far as I can see, the fix is to re-design the package so that it is flatter, with fewer imports, and avoid the recursive import. Good luck! -- Steven From mohsen at pahlevanzadeh.org Mon Sep 16 00:05:04 2013 From: mohsen at pahlevanzadeh.org (Mohsen Pahlevanzadeh) Date: Mon, 16 Sep 2013 08:35:04 +0430 Subject: import problem In-Reply-To: <5236735f$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <5236735f$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1379304304.24093.1.camel@debian> thank you, you gave me "how to get fish" instead of "fish", it's very better. On Mon, 2013-09-16 at 02:56 +0000, Steven D'Aprano wrote: > On Mon, 16 Sep 2013 06:53:26 +0430, Mohsen Pahlevanzadeh wrote: > > > Dear all, > > > > i have the following two line codes: > > ############################ > > import ui.interface.interface > > obj = ui.interface.interface.InterfaceCodes() > > ###########################333 > > I have same code in another package and work fine. but i get the : > > > > #####################################################3 > > This traceback following suggests that your package is a complete tangled > mess of wild card imports. Perhaps I am misreading something, but the > following suggests that your package is highly coupled, with strong > dependencies between different modules. This is a poor design and will > give you many, many problems. As you are already having. > > Do you understand what I mean when I talk about modules being "highly > coupled"? > > Are you a Java or C++ developer learning Python? Your code suggests to me > that you might be. If you are, you should read these to get some ideas of > how your Java intuitions will lead you astray in Python: > > http://dirtsimple.org/2004/12/python-is-not-java.html > http://dirtsimple.org/2004/12/java-is-not-python-either.html > > > I assume that everything under the "amlak" directory is your code. Is > that correct? > > Here's the traceback again: > > > Traceback (most > > recent call last): > > File "./main.py", line 31, in > > from materials.materials import * > > File "/home/mohsen/codes/amlak/amlak/src/materials/materials.py", line > > 40, in > > from ui.interface.interface import * > > File "/home/mohsen/codes/amlak/amlak/src/ui/interface/interface.py", > > line 32, in > > from ui.materialsFrame import * > > File "/home/mohsen/codes/amlak/amlak/src/ui/materialsFrame.py", line > > 24, in > > from ui.materialsFindFrame import * > > File "/home/mohsen/codes/amlak/amlak/src/ui/materialsFindFrame.py", > > line 14, in > > from common.objects.objects import * > > File "/home/mohsen/codes/amlak/amlak/src/common/objects/objects.py", > > line 28, in > > obj = ui.interface.interface.InterfaceCodes() > > AttributeError: 'module' object has no attribute 'interface' > > ########################################### > > > So your main module does a wild-card import from materials.materials, > which does a wild-card import from ui.interface.interface, which does a > wild-card import from ui.materialsFrame, which does a wild-card import > from ui.materialsFindFrame, which does a wild-card import from > common.objects.objects, which requires ui.interface.interface to have > already been loaded and imported. But it hasn't been, because it is still > being imported. > > The *immediate* problem is that, in effect, before you can import > ui.interface.interface, you need to import ui.interface.interface. > Obviously this is going to cause you problems. Google on "recursive > imports" to learn about the sorts of problems and how to avoid them. > > The second problem is that, in general, you should try to avoid wild-card > imports. They're not always bad, but they were really invented for use in > the interactive interpreter so you can do things like this: > > from math import * > sqrt(42) > sin(1.5) > > > Using them inside non-interactive code is not forbidden exactly, but it > is frowned upon since it makes understanding your code harder. > > The third problem is that your code layout looks like you are fighting > Python, trying to force it to be something it is not. For starters, if > you're writing packages that look like this: > > ui.interface.interface > > that's simply poor design for Python. My guess is that you might be > following the Java convention of putting exactly one class per source > file. That is not the way Python code should be written. Modules should > contain all the related classes and functions, at least up to the point > that the module becomes so large that it is painful to work with. How > large is that? In my opinion, this is getting close to the maximum I > personally would be comfortable with: > > http://hg.python.org/cpython/file/3.3/Lib/decimal.py > > > although some people might be happy with large files. > > But what is important is that related code should be together in the one > file, not split across multiple modules and multiple packages. > > If you are trying to "future proof" your code, and thinking "today it is > small, but one day it will be big and will need to be a package with > dozens of modules", that doesn't matter. Don't write the code you think > you will need in five years. Write the code you need now. Google "YAGNI" > for more. > > I am sorry that I cannot just give you a simple one-line fix for your > error. As far as I can see, the fix is to re-design the package so that > it is flatter, with fewer imports, and avoid the recursive import. > > Good luck! > > > > -- > Steven From davea at davea.name Mon Sep 16 10:08:18 2013 From: davea at davea.name (Dave Angel) Date: Mon, 16 Sep 2013 14:08:18 +0000 (UTC) Subject: import problem References: <5236735f$0$29988$c3e8da3$5496439d@news.astraweb.com> <1379304304.24093.1.camel@debian> Message-ID: On 16/9/2013 00:05, Mohsen Pahlevanzadeh wrote: > thank you, you gave me "how to get fish" instead of "fish", it's very > better. I'd suggest you make a diagram showing each file and indicate what files it imports by an arrow. If any arrows form a circle, you (may) have recursive imports. You should try to organize your code so you don't have any loops in the above diagram. In reasonable designs, you can do that by factoring out some of the code into new bubbles. But if you have too many bubbles already, that just makes it harder to keep track of. The recursion can sometimes be debugged more easily by eliminating the "from xxx import *" forms., which really hides what things you get. You'll only get those symbols already defined in the particular loop, (which is generaly the ones defined before its import statment) and you won't find out about the missing one till you try to use it later. It can sometimes be mitigated by using from xxx import y1, y2 where you explicitly define those things before the import statement. However, both of these require you to have the imports somewhere NOT at the top of the file. And that can cause other problems. Best is to avoid any loops in the diagram. -- DaveA From mohsen at pahlevanzadeh.org Mon Sep 16 02:44:12 2013 From: mohsen at pahlevanzadeh.org (Mohsen Pahlevanzadeh) Date: Mon, 16 Sep 2013 11:14:12 +0430 Subject: import problem In-Reply-To: <5236735f$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <5236735f$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1379313852.24093.7.camel@debian> On Mon, 2013-09-16 at 02:56 +0000, Steven D'Aprano wrote: > On Mon, 16 Sep 2013 06:53:26 +0430, Mohsen Pahlevanzadeh wrote: > > > Dear all, > > > > i have the following two line codes: > > ############################ > > import ui.interface.interface > > obj = ui.interface.interface.InterfaceCodes() > > ###########################333 > > I have same code in another package and work fine. but i get the : > > > > #####################################################3 > > This traceback following suggests that your package is a complete tangled > mess of wild card imports. Perhaps I am misreading something, but the > following suggests that your package is highly coupled, with strong > dependencies between different modules. This is a poor design and will > give you many, many problems. As you are already having. > > Do you understand what I mean when I talk about modules being "highly > coupled"? > > Are you a Java or C++ developer learning Python? Your code suggests to me > that you might be. If you are, you should read these to get some ideas of > how your Java intuitions will lead you astray in Python: > > http://dirtsimple.org/2004/12/python-is-not-java.html > http://dirtsimple.org/2004/12/java-is-not-python-either.html > > > I assume that everything under the "amlak" directory is your code. Is > that correct? > > Here's the traceback again: > > > Traceback (most > > recent call last): > > File "./main.py", line 31, in > > from materials.materials import * > > File "/home/mohsen/codes/amlak/amlak/src/materials/materials.py", line > > 40, in > > from ui.interface.interface import * > > File "/home/mohsen/codes/amlak/amlak/src/ui/interface/interface.py", > > line 32, in > > from ui.materialsFrame import * > > File "/home/mohsen/codes/amlak/amlak/src/ui/materialsFrame.py", line > > 24, in > > from ui.materialsFindFrame import * > > File "/home/mohsen/codes/amlak/amlak/src/ui/materialsFindFrame.py", > > line 14, in > > from common.objects.objects import * > > File "/home/mohsen/codes/amlak/amlak/src/common/objects/objects.py", > > line 28, in > > obj = ui.interface.interface.InterfaceCodes() > > AttributeError: 'module' object has no attribute 'interface' > > ########################################### > > > So your main module does a wild-card import from materials.materials, > which does a wild-card import from ui.interface.interface, which does a > wild-card import from ui.materialsFrame, which does a wild-card import > from ui.materialsFindFrame, which does a wild-card import from > common.objects.objects, which requires ui.interface.interface to have > already been loaded and imported. But it hasn't been, because it is still > being imported. > > The *immediate* problem is that, in effect, before you can import > ui.interface.interface, you need to import ui.interface.interface. > Obviously this is going to cause you problems. Google on "recursive > imports" to learn about the sorts of problems and how to avoid them. > > The second problem is that, in general, you should try to avoid wild-card > imports. They're not always bad, but they were really invented for use in > the interactive interpreter so you can do things like this: > > from math import * > sqrt(42) > sin(1.5) > > > Using them inside non-interactive code is not forbidden exactly, but it > is frowned upon since it makes understanding your code harder. > > The third problem is that your code layout looks like you are fighting > Python, trying to force it to be something it is not. For starters, if > you're writing packages that look like this: > > ui.interface.interface > > that's simply poor design for Python. My guess is that you might be > following the Java convention of putting exactly one class per source > file. That is not the way Python code should be written. Modules should > contain all the related classes and functions, at least up to the point > that the module becomes so large that it is painful to work with. How > large is that? In my opinion, this is getting close to the maximum I > personally would be comfortable with: > > http://hg.python.org/cpython/file/3.3/Lib/decimal.py > > > although some people might be happy with large files. > > But what is important is that related code should be together in the one > file, not split across multiple modules and multiple packages. > > If you are trying to "future proof" your code, and thinking "today it is > small, but one day it will be big and will need to be a package with > dozens of modules", that doesn't matter. Don't write the code you think > you will need in five years. Write the code you need now. Google "YAGNI" > for more. > > I am sorry that I cannot just give you a simple one-line fix for your > error. As far as I can see, the fix is to re-design the package so that > it is flatter, with fewer imports, and avoid the recursive import. > > Good luck! > > > > -- > Steven Dear Steven, I moved all of files to root of source directory, And create an put my constructor to objects.py file : ################################# interfaceCodesObj = interface.InterfaceCodes() #############################333 And in another files that i import object such as: ###################### from objects import * ###################### i get the the folloiwing traceback: ####################################3 Traceback (most recent call last): File "/home/mohsen/codes/amlak/amlak/src/materialsFindFrame.py", line 187, in QtCore.QObject.connect(self.checkBox, QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda: interfaceCodesObj.unSetFilterDict("name")) NameError: global name 'interfaceCodesObj' is not defined Traceback (most recent call last): File "/home/mohsen/codes/amlak/amlak/src/materialsFindFrame.py", line 192, in QtCore.QObject.connect(self.checkBox, QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda: interfaceCodesObj.setFilterDict(self,self.checkBox,"name",self.lineEdit.text())) NameError: global name 'interfaceCodesObj' is not defined Traceback (most recent call last): File "/home/mohsen/codes/amlak/amlak/src/materialsFindFrame.py", line 198, in QtCore.QObject.connect(self.checkBox, QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda: interfaceCodesObj.responseToRequestForData(self)) NameError: global name 'interfaceCodesObj' is not defined ####################################################### I'm forced to used wildcard such as from~import syntax. you said correctly, i was C++ developer. Yours, Mohsen From mohsen at pahlevanzadeh.org Mon Sep 16 02:56:57 2013 From: mohsen at pahlevanzadeh.org (Mohsen Pahlevanzadeh) Date: Mon, 16 Sep 2013 11:26:57 +0430 Subject: import problem In-Reply-To: <1379313852.24093.7.camel@debian> References: <5236735f$0$29988$c3e8da3$5496439d@news.astraweb.com> <1379313852.24093.7.camel@debian> Message-ID: <1379314617.24093.10.camel@debian> On Mon, 2013-09-16 at 11:14 +0430, Mohsen Pahlevanzadeh wrote: > On Mon, 2013-09-16 at 02:56 +0000, Steven D'Aprano wrote: > > On Mon, 16 Sep 2013 06:53:26 +0430, Mohsen Pahlevanzadeh wrote: > > > > > Dear all, > > > > > > i have the following two line codes: > > > ############################ > > > import ui.interface.interface > > > obj = ui.interface.interface.InterfaceCodes() > > > ###########################333 > > > I have same code in another package and work fine. but i get the : > > > > > > #####################################################3 > > > > This traceback following suggests that your package is a complete tangled > > mess of wild card imports. Perhaps I am misreading something, but the > > following suggests that your package is highly coupled, with strong > > dependencies between different modules. This is a poor design and will > > give you many, many problems. As you are already having. > > > > Do you understand what I mean when I talk about modules being "highly > > coupled"? > > > > Are you a Java or C++ developer learning Python? Your code suggests to me > > that you might be. If you are, you should read these to get some ideas of > > how your Java intuitions will lead you astray in Python: > > > > http://dirtsimple.org/2004/12/python-is-not-java.html > > http://dirtsimple.org/2004/12/java-is-not-python-either.html > > > > > > I assume that everything under the "amlak" directory is your code. Is > > that correct? > > > > Here's the traceback again: > > > > > Traceback (most > > > recent call last): > > > File "./main.py", line 31, in > > > from materials.materials import * > > > File "/home/mohsen/codes/amlak/amlak/src/materials/materials.py", line > > > 40, in > > > from ui.interface.interface import * > > > File "/home/mohsen/codes/amlak/amlak/src/ui/interface/interface.py", > > > line 32, in > > > from ui.materialsFrame import * > > > File "/home/mohsen/codes/amlak/amlak/src/ui/materialsFrame.py", line > > > 24, in > > > from ui.materialsFindFrame import * > > > File "/home/mohsen/codes/amlak/amlak/src/ui/materialsFindFrame.py", > > > line 14, in > > > from common.objects.objects import * > > > File "/home/mohsen/codes/amlak/amlak/src/common/objects/objects.py", > > > line 28, in > > > obj = ui.interface.interface.InterfaceCodes() > > > AttributeError: 'module' object has no attribute 'interface' > > > ########################################### > > > > > > So your main module does a wild-card import from materials.materials, > > which does a wild-card import from ui.interface.interface, which does a > > wild-card import from ui.materialsFrame, which does a wild-card import > > from ui.materialsFindFrame, which does a wild-card import from > > common.objects.objects, which requires ui.interface.interface to have > > already been loaded and imported. But it hasn't been, because it is still > > being imported. > > > > The *immediate* problem is that, in effect, before you can import > > ui.interface.interface, you need to import ui.interface.interface. > > Obviously this is going to cause you problems. Google on "recursive > > imports" to learn about the sorts of problems and how to avoid them. > > > > The second problem is that, in general, you should try to avoid wild-card > > imports. They're not always bad, but they were really invented for use in > > the interactive interpreter so you can do things like this: > > > > from math import * > > sqrt(42) > > sin(1.5) > > > > > > Using them inside non-interactive code is not forbidden exactly, but it > > is frowned upon since it makes understanding your code harder. > > > > The third problem is that your code layout looks like you are fighting > > Python, trying to force it to be something it is not. For starters, if > > you're writing packages that look like this: > > > > ui.interface.interface > > > > that's simply poor design for Python. My guess is that you might be > > following the Java convention of putting exactly one class per source > > file. That is not the way Python code should be written. Modules should > > contain all the related classes and functions, at least up to the point > > that the module becomes so large that it is painful to work with. How > > large is that? In my opinion, this is getting close to the maximum I > > personally would be comfortable with: > > > > http://hg.python.org/cpython/file/3.3/Lib/decimal.py > > > > > > although some people might be happy with large files. > > > > But what is important is that related code should be together in the one > > file, not split across multiple modules and multiple packages. > > > > If you are trying to "future proof" your code, and thinking "today it is > > small, but one day it will be big and will need to be a package with > > dozens of modules", that doesn't matter. Don't write the code you think > > you will need in five years. Write the code you need now. Google "YAGNI" > > for more. > > > > I am sorry that I cannot just give you a simple one-line fix for your > > error. As far as I can see, the fix is to re-design the package so that > > it is flatter, with fewer imports, and avoid the recursive import. > > > > Good luck! > > > > > > > > -- > > Steven > Dear Steven, > > I moved all of files to root of source directory, And create an put my > constructor to objects.py file : > ################################# > interfaceCodesObj = interface.InterfaceCodes() > #############################333 > And in another files that i import object such as: > ###################### > from objects import * > ###################### > i get the the folloiwing traceback: > ####################################3 > Traceback (most recent call last): > File "/home/mohsen/codes/amlak/amlak/src/materialsFindFrame.py", line > 187, in > QtCore.QObject.connect(self.checkBox, > QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda: > interfaceCodesObj.unSetFilterDict("name")) > NameError: global name 'interfaceCodesObj' is not defined > Traceback (most recent call last): > File "/home/mohsen/codes/amlak/amlak/src/materialsFindFrame.py", line > 192, in > QtCore.QObject.connect(self.checkBox, > QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda: > interfaceCodesObj.setFilterDict(self,self.checkBox,"name",self.lineEdit.text())) > NameError: global name 'interfaceCodesObj' is not defined > Traceback (most recent call last): > File "/home/mohsen/codes/amlak/amlak/src/materialsFindFrame.py", line > 198, in > QtCore.QObject.connect(self.checkBox, > QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda: > interfaceCodesObj.responseToRequestForData(self)) > NameError: global name 'interfaceCodesObj' is not defined > ####################################################### > > I'm forced to used wildcard such as from~import syntax. > you said correctly, i was C++ developer. > > Yours, > Mohsen > I solved with alias : import foo as bar From malhar.v.ntech at gmail.com Mon Sep 16 03:10:55 2013 From: malhar.v.ntech at gmail.com (malhar vora) Date: Mon, 16 Sep 2013 00:10:55 -0700 (PDT) Subject: Help regarding python facepy library Message-ID: Hello all, I am using python facepy library to fetch data from facebook. It was running fine. The problem now is I just changed my system and now getting error that says "certificate verify failed". Here my code and exception log both are given below. The library that I have used is https://pypi.python.org/pypi/facepy Code is given below. ################################################################################# import facepy from facepy import GraphAPI,exceptions import json graph = GraphAPI('my fb access token') fb_dump = open('D:\\Malhar Data\\Projects\\Social Media Web Project\\TestGround\\temp\\Output\\output.txt', 'w') try: pages = graph.get('AhmedabadUniversity/posts', page=True) all_pages = [] for page in pages: all_pages = all_pages + page["data"] except exceptions.OAuthError, error: if error.code == 2: print "Unexpected error occured" elif error.code == 803: print "Alias or Page does not exist" for d in all_pages: fb_dump.write("Message : " + d.get('message','None').encode("UTF-8", "ignore")) fb_dump.close() ########################################################################## Exception log is given below. D:\Malhar Data\Projects\Social Media Web Project\TestGround\temp>python fbgrabbe r.py C:\Python26\lib\site-packages\facepy\graph_api.py:199: DeprecationWarning: BaseE xception.message has been deprecated as of Python 2.6 raise HTTPError(exception.message) Traceback (most recent call last): File "fbgrabber.py", line 14, in for page in pages: File "C:\Python26\Lib\site-packages\facepy\graph_api.py", line 212, in paginat e result, url = load(method, url, data) File "C:\Python26\Lib\site-packages\facepy\graph_api.py", line 199, in load raise HTTPError(exception.message) facepy.exceptions.HTTPError: [Errno 1] _ssl.c:480: error:14090086:SSL routines:S SL3_GET_SERVER_CERTIFICATE:certificate verify failed ============================================================================ I tried generating new token and run the script but got same error. I didn't find any solution of this problem. If anybody is able to figure out the problem, please help me. Thank you, Malhar Vora From michi.schwarz at gmail.com Mon Sep 16 09:15:22 2013 From: michi.schwarz at gmail.com (Michael Schwarz) Date: Mon, 16 Sep 2013 15:15:22 +0200 Subject: Is %z broken for return values of time.gmtime()? Message-ID: <3C2755B3-2478-45E1-88F5-9FD961F2B1BD@gmail.com> I?m wondering whether this is expected: Python 3.3.2 (default, May 21 2013, 11:50:47) [GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import time >>> time.strftime("%F %T %z", time.gmtime(40 * 365 * 86400)) '2009-12-22 00:00:00 +0100? According to the documentation of time.gmtime(), it returns a struct_time in UTC, but %z is replaced by +0100, which is the UTC offset of my OS?s time zone without DST, but DST is currently in effect here (but was not at the timestamp passed to gmtime()). 40 * 365 * 86400 seconds is a bit less than 40 Years. I?m using a date near to today to rule out any peculiarities with dates that are long in the past. Using a date at which DST was active yields the same result: >>> time.strftime("%F %T %z", time.gmtime(40.5 * 365 * 86400)) '2010-06-22 12:00:00 +0100' Why is my OS?s time zone used for formatting a struct_time with the UTC time zone? I?m running OS X 10.8.4, my OS?s time zone is set to CET/CEST. Regards Michael -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2227 bytes Desc: not available URL: From random832 at fastmail.us Mon Sep 16 13:56:01 2013 From: random832 at fastmail.us (random832 at fastmail.us) Date: Mon, 16 Sep 2013 13:56:01 -0400 Subject: Is %z broken for return values of time.gmtime()? In-Reply-To: <3C2755B3-2478-45E1-88F5-9FD961F2B1BD@gmail.com> References: <3C2755B3-2478-45E1-88F5-9FD961F2B1BD@gmail.com> Message-ID: <1379354161.1707.22675889.2647208B@webmail.messagingengine.com> On Mon, Sep 16, 2013, at 9:15, Michael Schwarz wrote: > According to the documentation of time.gmtime(), it returns a struct_time > in UTC, but %z is replaced by +0100, which is the UTC offset of my OS?s > time zone without DST, but DST is currently in effect here (but was not > at the timestamp passed to gmtime()). The struct_time type does not include information about what timezone it is in. You can use datetime.datetime (e.g. datetime.datetime.fromtimestamp(40 * 365 * 86400,datetime.timezone.utc) - the datetime.datetime class has a strftime method. You should be aware that %F and %T are not portable and won't work on windows for example. From michi.schwarz at gmail.com Mon Sep 16 16:55:33 2013 From: michi.schwarz at gmail.com (Michael Schwarz) Date: Mon, 16 Sep 2013 22:55:33 +0200 Subject: Is %z broken for return values of time.gmtime()? In-Reply-To: <1379354161.1707.22675889.2647208B@webmail.messagingengine.com> References: <3C2755B3-2478-45E1-88F5-9FD961F2B1BD@gmail.com> <1379354161.1707.22675889.2647208B@webmail.messagingengine.com> Message-ID: On 2013-W38-1, at 19:56, random832 at fastmail.us wrote: > On Mon, Sep 16, 2013, at 9:15, Michael Schwarz wrote: >> According to the documentation of time.gmtime(), it returns a struct_time >> in UTC, but %z is replaced by +0100, which is the UTC offset of my OS?s >> time zone without DST, but DST is currently in effect here (but was not >> at the timestamp passed to gmtime()). > > The struct_time type does not include information about what timezone it > is in. Uhm ? Python 3.3 introduced the tm_gmtoff member of struct_time, which contains the offset to UTC. I thought, %z was also introduced in Python 3.3 and so I thought it would use that field. What time zone does it use then? Does it always use the system's time zone? > You can use datetime.datetime (e.g. datetime.datetime.fromtimestamp(40 * > 365 * 86400,datetime.timezone.utc) - the datetime.datetime class has a > strftime method. I do use that, but I was using time.localtime() to convert a POSIX timestamp to a date using the system's timezone and saw that while a struct_time produced by time.localtime() and formatted using time.strftime() shows the correct time zone (+0100 and +0200 here), it does not for a struct_time produced by time.gmtime(). I think that's strange. > You should be aware that %F and %T are not portable and won't work on > windows for example. I?m aware of that, but thanks. I was toying around and just needed to print the rest of the date. Regards Michael -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2227 bytes Desc: not available URL: From random832 at fastmail.us Tue Sep 17 08:48:04 2013 From: random832 at fastmail.us (random832 at fastmail.us) Date: Tue, 17 Sep 2013 08:48:04 -0400 Subject: Is %z broken for return values of time.gmtime()? In-Reply-To: References: <3C2755B3-2478-45E1-88F5-9FD961F2B1BD@gmail.com> <1379354161.1707.22675889.2647208B@webmail.messagingengine.com> Message-ID: <1379422084.9208.23014833.04A16CED@webmail.messagingengine.com> On Mon, Sep 16, 2013, at 16:55, Michael Schwarz wrote: > On 2013-W38-1, at 19:56, random832 at fastmail.us wrote: > > > On Mon, Sep 16, 2013, at 9:15, Michael Schwarz wrote: > >> According to the documentation of time.gmtime(), it returns a struct_time > >> in UTC, but %z is replaced by +0100, which is the UTC offset of my OS?s > >> time zone without DST, but DST is currently in effect here (but was not > >> at the timestamp passed to gmtime()). > > > > The struct_time type does not include information about what timezone it > > is in. > > Uhm ? Python 3.3 introduced the tm_gmtoff member of struct_time, which > contains the offset to UTC. I don't see it. Maybe it is not available on platforms that do not provide it? Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64 bit (AMD64)] on win32) I would argue that it _should_ be, and that it should populate it with 0 in gmtime or either with timezone/altzone or by some sort of reverse calculation in localtime, but it is not. Another problem to add to my list of reasons for my recent python-ideas proposal. From as at sci.fi Wed Sep 18 08:01:02 2013 From: as at sci.fi (Anssi Saari) Date: Wed, 18 Sep 2013 15:01:02 +0300 Subject: Is %z broken for return values of time.gmtime()? References: <3C2755B3-2478-45E1-88F5-9FD961F2B1BD@gmail.com> <1379354161.1707.22675889.2647208B@webmail.messagingengine.com> Message-ID: random832 at fastmail.us writes: > I would argue that it _should_ be, and that it should populate it with 0 > in gmtime or either with timezone/altzone or by some sort of reverse > calculation in localtime, but it is not. Another problem to add to my > list of reasons for my recent python-ideas proposal. Docs say that tm_gmtoff and tm_zone are available if the struct tm in the underlying C library has it. Based on that I kinda expected Cygwin to have it but apparently not. From a7xrturodev at gmail.com Mon Sep 16 09:43:52 2013 From: a7xrturodev at gmail.com (Arturo B) Date: Mon, 16 Sep 2013 06:43:52 -0700 (PDT) Subject: How is this list comprehension evaluated? Message-ID: Hello, I'm making Python mini-projects and now I'm making a Latin Square (Latin Square: http://en.wikipedia.org/wiki/Latin_square) So, I started watching example code and I found this question on Stackoverflow: http://stackoverflow.com/questions/5313900/generating-cyclic-permutations-reduced-latin-squares-in-python It uses a list comprenhension to generate the Latin Square, I'm am a newbie to Python, and I've tried to figure out how this is evaluated: a = [1, 2, 3, 4] n = len(a) [[a[i - j] for i in range(n)] for j in range(n)] I don't understand how the "i" and the "j" changes. On my way of thought it is evaluated like this: [[a[0 - 0] for 0 in range(4)] for 0 in range(4)] [[a[1 - 1] for 1 in range(4)] for 1 in range(4)] [[a[2 - 2] for 2 in range(4)] for 2 in range(4)] [[a[3 - 3] for 3 in range(4)] for 3 in range(4)] But I think I'm wrong... So, could you explain me as above? It would help me a lot. Thanks for reading! From antoon.pardon at rece.vub.ac.be Mon Sep 16 09:53:33 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 16 Sep 2013 15:53:33 +0200 Subject: How is this list comprehension evaluated? In-Reply-To: References: Message-ID: <52370D5D.108@rece.vub.ac.be> Op 16-09-13 15:43, Arturo B schreef: > Hello, I'm making Python mini-projects and now I'm making a Latin Square > > (Latin Square: http://en.wikipedia.org/wiki/Latin_square) > > So, I started watching example code and I found this question on Stackoverflow: > > http://stackoverflow.com/questions/5313900/generating-cyclic-permutations-reduced-latin-squares-in-python > > It uses a list comprenhension to generate the Latin Square, I'm am a newbie to Python, and I've tried to figure out how this is evaluated: > > a = [1, 2, 3, 4] > n = len(a) > [[a[i - j] for i in range(n)] for j in range(n)] > > I don't understand how the "i" and the "j" changes. > On my way of thought it is evaluated like this: > > [[a[0 - 0] for 0 in range(4)] for 0 in range(4)] > [[a[1 - 1] for 1 in range(4)] for 1 in range(4)] > [[a[2 - 2] for 2 in range(4)] for 2 in range(4)] > [[a[3 - 3] for 3 in range(4)] for 3 in range(4)] > > But I think I'm wrong... So, could you explain me as above? It would help me a lot. > > Thanks for reading! Just start your python interpreter and type the following >>> [[(i,j) for i in range(3)] for j in range(3)] That should give you a clue. -- Antoon Pardon From torriem at gmail.com Mon Sep 16 10:20:44 2013 From: torriem at gmail.com (Michael Torrie) Date: Mon, 16 Sep 2013 08:20:44 -0600 Subject: How is this list comprehension evaluated? In-Reply-To: References: Message-ID: <523713BC.7010009@gmail.com> On 09/16/2013 07:43 AM, Arturo B wrote: > It uses a list comprenhension to generate the Latin Square, I'm am a newbie to Python, and I've tried to figure out how this is evaluated: > > a = [1, 2, 3, 4] > n = len(a) > [[a[i - j] for i in range(n)] for j in range(n)] > > I don't understand how the "i" and the "j" changes. > On my way of thought it is evaluated like this: It helps to convert it to a conventional for loop to see how it works: a = [1, 2, 3, 4] n = len(a) resultj = [] for j in range(n): resulti = [] for i in range(n): resulti.append(a[i-j]) resultj.append(resulti) From roy at panix.com Mon Sep 16 20:04:32 2013 From: roy at panix.com (Roy Smith) Date: Mon, 16 Sep 2013 20:04:32 -0400 Subject: How is this list comprehension evaluated? References: Message-ID: In article , Arturo B wrote: > Hello, I'm making Python mini-projects and now I'm making a Latin Square > > (Latin Square: http://en.wikipedia.org/wiki/Latin_square) > > So, I started watching example code and I found this question on > Stackoverflow: > > http://stackoverflow.com/questions/5313900/generating-cyclic-permutations-redu > ced-latin-squares-in-python > > It uses a list comprenhension to generate the Latin Square, I'm am a newbie > to Python, and I've tried to figure out how this is evaluated: > > a = [1, 2, 3, 4] > n = len(a) > [[a[i - j] for i in range(n)] for j in range(n)] You can re-write any list comprehension as a for loop. In this case you have to un-wrap this one layer at a time. First step: a = [1, 2, 3, 4] n = len(a) temp1 = [] for j in range(n): temp2 = [a[i - j] for i in range(n)] temp1.append(item) then, unwrap the next layer: a = [1, 2, 3, 4] n = len(a) temp1 = [] for j in range(n): temp2 = [] for i in range(n): temp3 = a[i - j] temp2.append(temp3) temp1.append(item) Does that make it any easier to understand? From davide.dalmasso at gmail.com Mon Sep 16 11:37:58 2013 From: davide.dalmasso at gmail.com (Davide Dalmasso) Date: Mon, 16 Sep 2013 08:37:58 -0700 (PDT) Subject: statsmodels.api Message-ID: Hi, I intalled an executable version of statsmodels library for Windows 32-bit. When I import it in my Python Shell no problem occurs buy when I write: import statsmodels.api as sm the following error arises: Traceback (most recent call last): File "", line 1, in import statsmodels.api File "C:\Python33\lib\site-packages\statsmodels\api.py", line 1, in from . import iolib, datasets, tools File "C:\Python33\lib\site-packages\statsmodels\iolib\__init__.py", line 1, in from .foreign import StataReader, genfromdta, savetxt File "C:\Python33\lib\site-packages\statsmodels\iolib\foreign.py", line 20, in import statsmodels.tools.data as data_util File "C:\Python33\lib\site-packages\statsmodels\tools\__init__.py", line 1, in from .tools import add_constant, categorical File "C:\Python33\lib\site-packages\statsmodels\tools\tools.py", line 8, in from scipy.interpolate import interp1d File "C:\Python33\lib\site-packages\scipy\interpolate\__init__.py", line 150, in from .interpolate import * File "C:\Python33\lib\site-packages\scipy\interpolate\interpolate.py", line 12, in import scipy.special as spec File "C:\Python33\lib\site-packages\scipy\special\__init__.py", line 529, in from ._ufuncs import * Why? Thanks for any help you will want to give me! Davide From gordon at panix.com Mon Sep 16 12:30:37 2013 From: gordon at panix.com (John Gordon) Date: Mon, 16 Sep 2013 16:30:37 +0000 (UTC) Subject: statsmodels.api References: Message-ID: In Davide Dalmasso writes: > Hi, > I intalled an executable version of statsmodels library for Windows 32-bit. > When I import it in my Python Shell no problem occurs buy when I write: > import statsmodels.api as sm > the following error arises: > Traceback (most recent call last): > File "", line 1, in > import statsmodels.api > File "C:\Python33\lib\site-packages\statsmodels\api.py", line 1, in > from . import iolib, datasets, tools > File "C:\Python33\lib\site-packages\statsmodels\iolib\__init__.py", line 1, in > from .foreign import StataReader, genfromdta, savetxt > File "C:\Python33\lib\site-packages\statsmodels\iolib\foreign.py", line 20, in > import statsmodels.tools.data as data_util > File "C:\Python33\lib\site-packages\statsmodels\tools\__init__.py", line 1, in > from .tools import add_constant, categorical > File "C:\Python33\lib\site-packages\statsmodels\tools\tools.py", line 8, in > from scipy.interpolate import interp1d > File "C:\Python33\lib\site-packages\scipy\interpolate\__init__.py", line 150, in > from .interpolate import * > File "C:\Python33\lib\site-packages\scipy\interpolate\interpolate.py", line 12, in > import scipy.special as spec > File "C:\Python33\lib\site-packages\scipy\special\__init__.py", line 529, in > from ._ufuncs import * This error traceback appears incomplete. Did you paste the whole thing? -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From ethan at stoneleaf.us Mon Sep 16 11:47:55 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 16 Sep 2013 08:47:55 -0700 Subject: statsmodels.api In-Reply-To: References: Message-ID: <5237282B.1000203@stoneleaf.us> On 09/16/2013 08:37 AM, Davide Dalmasso wrote: > Hi, > > I intalled an executable version of statsmodels library for Windows 32-bit. > When I import it in my Python Shell no problem occurs buy when I write: > > import statsmodels.api as sm > > the following error arises: > > Traceback (most recent call last): > File "", line 1, in > import statsmodels.api > File "C:\Python33\lib\site-packages\statsmodels\api.py", line 1, in > from . import iolib, datasets, tools > File "C:\Python33\lib\site-packages\statsmodels\iolib\__init__.py", line 1, in > from .foreign import StataReader, genfromdta, savetxt > File "C:\Python33\lib\site-packages\statsmodels\iolib\foreign.py", line 20, in > import statsmodels.tools.data as data_util > File "C:\Python33\lib\site-packages\statsmodels\tools\__init__.py", line 1, in > from .tools import add_constant, categorical > File "C:\Python33\lib\site-packages\statsmodels\tools\tools.py", line 8, in > from scipy.interpolate import interp1d > File "C:\Python33\lib\site-packages\scipy\interpolate\__init__.py", line 150, in > from .interpolate import * > File "C:\Python33\lib\site-packages\scipy\interpolate\interpolate.py", line 12, in > import scipy.special as spec > File "C:\Python33\lib\site-packages\scipy\special\__init__.py", line 529, in > from ._ufuncs import * We'll need the rest of the traceback, as it will have the actual error. -- ~Ethan~ From davide.dalmasso at gmail.com Tue Sep 17 06:10:20 2013 From: davide.dalmasso at gmail.com (Davide Dalmasso) Date: Tue, 17 Sep 2013 03:10:20 -0700 (PDT) Subject: statsmodels.api In-Reply-To: References: Message-ID: Il giorno luned? 16 settembre 2013 17:47:55 UTC+2, Ethan Furman ha scritto: > On 09/16/2013 08:37 AM, Davide Dalmasso wrote: > > > Hi, > > > > > > I intalled an executable version of statsmodels library for Windows 32-bit. > > > When I import it in my Python Shell no problem occurs buy when I write: > > > > > > import statsmodels.api as sm > > > > > > the following error arises: > > > > > > Traceback (most recent call last): > > > File "", line 1, in > > > import statsmodels.api > > > File "C:\Python33\lib\site-packages\statsmodels\api.py", line 1, in > > > from . import iolib, datasets, tools > > > File "C:\Python33\lib\site-packages\statsmodels\iolib\__init__.py", line 1, in > > > from .foreign import StataReader, genfromdta, savetxt > > > File "C:\Python33\lib\site-packages\statsmodels\iolib\foreign.py", line 20, in > > > import statsmodels.tools.data as data_util > > > File "C:\Python33\lib\site-packages\statsmodels\tools\__init__.py", line 1, in > > > from .tools import add_constant, categorical > > > File "C:\Python33\lib\site-packages\statsmodels\tools\tools.py", line 8, in > > > from scipy.interpolate import interp1d > > > File "C:\Python33\lib\site-packages\scipy\interpolate\__init__.py", line 150, in > > > from .interpolate import * > > > File "C:\Python33\lib\site-packages\scipy\interpolate\interpolate.py", line 12, in > > > import scipy.special as spec > > > File "C:\Python33\lib\site-packages\scipy\special\__init__.py", line 529, in > > > from ._ufuncs import * > > > > We'll need the rest of the traceback, as it will have the actual error. > > > > -- > > ~Ethan~ Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> import statsmodels.api as sm Traceback (most recent call last): File "", line 1, in import statsmodels.api as sm File "C:\Python33\lib\site-packages\statsmodels\api.py", line 1, in from . import iolib, datasets, tools File "C:\Python33\lib\site-packages\statsmodels\iolib\__init__.py", line 1, in from .foreign import StataReader, genfromdta, savetxt File "C:\Python33\lib\site-packages\statsmodels\iolib\foreign.py", line 20, in import statsmodels.tools.data as data_util File "C:\Python33\lib\site-packages\statsmodels\tools\__init__.py", line 1, in from .tools import add_constant, categorical File "C:\Python33\lib\site-packages\statsmodels\tools\tools.py", line 8, in from scipy.interpolate import interp1d File "C:\Python33\lib\site-packages\scipy\interpolate\__init__.py", line 150, in from .interpolate import * File "C:\Python33\lib\site-packages\scipy\interpolate\interpolate.py", line 12, in import scipy.special as spec File "C:\Python33\lib\site-packages\scipy\special\__init__.py", line 529, in from ._ufuncs import * ImportError: DLL load failed: Impossibile trovare il modulo specificato. >>> From oscar.j.benjamin at gmail.com Tue Sep 17 07:55:57 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 17 Sep 2013 12:55:57 +0100 Subject: statsmodels.api In-Reply-To: References: Message-ID: On 17 September 2013 11:10, Davide Dalmasso wrote: > Il giorno luned? 16 settembre 2013 17:47:55 UTC+2, Ethan Furman ha scritto: >> >> We'll need the rest of the traceback, as it will have the actual error. >> > Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32 bit (Intel)] on win32 > Type "copyright", "credits" or "license()" for more information. >>>> import statsmodels.api as sm > Traceback (most recent call last): > File "", line 1, in > import statsmodels.api as sm > File "C:\Python33\lib\site-packages\statsmodels\api.py", line 1, in > from . import iolib, datasets, tools > File "C:\Python33\lib\site-packages\statsmodels\iolib\__init__.py", line 1, in > from .foreign import StataReader, genfromdta, savetxt > File "C:\Python33\lib\site-packages\statsmodels\iolib\foreign.py", line 20, in > import statsmodels.tools.data as data_util > File "C:\Python33\lib\site-packages\statsmodels\tools\__init__.py", line 1, in > from .tools import add_constant, categorical > File "C:\Python33\lib\site-packages\statsmodels\tools\tools.py", line 8, in > from scipy.interpolate import interp1d > File "C:\Python33\lib\site-packages\scipy\interpolate\__init__.py", line 150, in > from .interpolate import * > File "C:\Python33\lib\site-packages\scipy\interpolate\interpolate.py", line 12, in > import scipy.special as spec > File "C:\Python33\lib\site-packages\scipy\special\__init__.py", line 529, in > from ._ufuncs import * > ImportError: DLL load failed: Impossibile trovare il modulo specificato. >>>> This looks like a bug in your scipy installation. What happens if you try the following in an interactive session: >>> import scipy >>> from scipy.interpolate import interp1d Also how did you install scipy? I didn't think that Windows binaries for Python 3.3 were available yet. Oscar From davide.dalmasso at gmail.com Tue Sep 17 08:13:27 2013 From: davide.dalmasso at gmail.com (Davide Dalmasso) Date: Tue, 17 Sep 2013 05:13:27 -0700 (PDT) Subject: statsmodels.api In-Reply-To: References: Message-ID: <477a0f61-87d6-4937-8467-743fc053ecec@googlegroups.com> You are right... there is a problem with scipy intallation because this error arise... >>> from scipy.interpolate import interp1d Traceback (most recent call last): File "", line 1, in from scipy.interpolate import interp1d File "C:\Python33\lib\site-packages\scipy\interpolate\__init__.py", line 150, in from .interpolate import * File "C:\Python33\lib\site-packages\scipy\interpolate\interpolate.py", line 12, in import scipy.special as spec File "C:\Python33\lib\site-packages\scipy\special\__init__.py", line 529, in from ._ufuncs import * ImportError: DLL load failed: Impossibile trovare il modulo specificato. I tryed to re-install the scipy executable that I downloaded from http://www.lfd.uci.edu/~gohlke/pythonlibs/ but the problem persists From josef.pktd at gmail.com Tue Sep 17 09:02:43 2013 From: josef.pktd at gmail.com (Josef Pktd) Date: Tue, 17 Sep 2013 06:02:43 -0700 (PDT) Subject: statsmodels.api In-Reply-To: <477a0f61-87d6-4937-8467-743fc053ecec@googlegroups.com> References: <477a0f61-87d6-4937-8467-743fc053ecec@googlegroups.com> Message-ID: <8dc86b4d-4c0e-4db5-9f6c-ea3dac65452a@googlegroups.com> On Tuesday, September 17, 2013 8:13:27 AM UTC-4, Davide Dalmasso wrote: > You are right... there is a problem with scipy intallation because this error arise... > > > > >>> from scipy.interpolate import interp1d > > Traceback (most recent call last): > > File "", line 1, in > > from scipy.interpolate import interp1d > > File "C:\Python33\lib\site-packages\scipy\interpolate\__init__.py", line 150, in > > from .interpolate import * > > File "C:\Python33\lib\site-packages\scipy\interpolate\interpolate.py", line 12, in > > import scipy.special as spec > > File "C:\Python33\lib\site-packages\scipy\special\__init__.py", line 529, in > > from ._ufuncs import * > > ImportError: DLL load failed: Impossibile trovare il modulo specificato. > > > > I tryed to re-install the scipy executable that I downloaded from http://www.lfd.uci.edu/~gohlke/pythonlibs/ > > but the problem persists Did you also install numpy from gohlke? My guess would be binary incompatibility if numpy is not the MKL version. Josef From oscar.j.benjamin at gmail.com Tue Sep 17 09:06:59 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 17 Sep 2013 14:06:59 +0100 Subject: statsmodels.api In-Reply-To: <477a0f61-87d6-4937-8467-743fc053ecec@googlegroups.com> References: <477a0f61-87d6-4937-8467-743fc053ecec@googlegroups.com> Message-ID: On 17 September 2013 13:13, Davide Dalmasso wrote: > > You are right... there is a problem with scipy intallation because this error arise... > >>>> from scipy.interpolate import interp1d > Traceback (most recent call last): > File "", line 1, in > from scipy.interpolate import interp1d > File "C:\Python33\lib\site-packages\scipy\interpolate\__init__.py", line 150, in > from .interpolate import * > File "C:\Python33\lib\site-packages\scipy\interpolate\interpolate.py", line 12, in > import scipy.special as spec > File "C:\Python33\lib\site-packages\scipy\special\__init__.py", line 529, in > from ._ufuncs import * > ImportError: DLL load failed: Impossibile trovare il modulo specificato. > > I tryed to re-install the scipy executable that I downloaded from http://www.lfd.uci.edu/~gohlke/pythonlibs/ > but the problem persists There are potential compatibility problems with the binaries from there as described at the top of the page. One thing is that you need to use Christopher's own numpy build to go with scipy: http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy If you installed numpy from somewhere else then that could be your problem. Essentially scipy isn't quite ported to Python 3.3 yet so my general advice is to use Python 3.2 and to use the official numpy/scipy binaries from sourceforge (they don't yet provide binaries for 3.3). Alternatively an easier approach might be to use Python(x, y) (which is free) or the Enthought Python Distribution (which is free for academic users). These are distributions that bundle Python with numpy/scipy and lots of other packages. I think they both still use Python 2.7 though. (As an aside, this is all much simpler if you're using Ubuntu or some other Linux distro rather than Windows.) Oscar From josef.pktd at gmail.com Tue Sep 17 09:35:23 2013 From: josef.pktd at gmail.com (Josef Pktd) Date: Tue, 17 Sep 2013 06:35:23 -0700 (PDT) Subject: statsmodels.api In-Reply-To: References: <477a0f61-87d6-4937-8467-743fc053ecec@googlegroups.com> Message-ID: <41a1e4b3-e497-43eb-8095-c2254afa2407@googlegroups.com> On Tuesday, September 17, 2013 9:06:59 AM UTC-4, Oscar Benjamin wrote: > On 17 September 2013 13:13, Davide Dalmasso wrote: > > > > > > You are right... there is a problem with scipy intallation because this error arise... > > > > > >>>> from scipy.interpolate import interp1d > > > Traceback (most recent call last): > > > File "", line 1, in > > > from scipy.interpolate import interp1d > > > File "C:\Python33\lib\site-packages\scipy\interpolate\__init__.py", line 150, in > > > from .interpolate import * > > > File "C:\Python33\lib\site-packages\scipy\interpolate\interpolate.py", line 12, in > > > import scipy.special as spec > > > File "C:\Python33\lib\site-packages\scipy\special\__init__.py", line 529, in > > > from ._ufuncs import * > > > ImportError: DLL load failed: Impossibile trovare il modulo specificato. > > > > > > I tryed to re-install the scipy executable that I downloaded from http://www.lfd.uci.edu/~gohlke/pythonlibs/ > > > but the problem persists > > > > There are potential compatibility problems with the binaries from > > there as described at the top of the page. One thing is that you need > > to use Christopher's own numpy build to go with scipy: > > http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy > > If you installed numpy from somewhere else then that could be your problem. > > > > Essentially scipy isn't quite ported to Python 3.3 yet so my general > > advice is to use Python 3.2 and to use the official numpy/scipy > > binaries from sourceforge (they don't yet provide binaries for 3.3). > > > > Alternatively an easier approach might be to use Python(x, y) (which > > is free) or the Enthought Python Distribution (which is free for > > academic users). These are distributions that bundle Python with > > numpy/scipy and lots of other packages. I think they both still use > > Python 2.7 though. > > > > (As an aside, this is all much simpler if you're using Ubuntu or some > > other Linux distro rather than Windows.) scientific python on a stick https://code.google.com/p/winpython/wiki/PackageIndex_33 I haven't seen any problems so far on python 3.3 The statsmodels test suite passes without problems on python 3.3 also, as far as I remember. (and no problems using Windows. just use the right binaries.) Josef > > > > > > Oscar From oscar.j.benjamin at gmail.com Tue Sep 17 10:10:46 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 17 Sep 2013 15:10:46 +0100 Subject: statsmodels.api In-Reply-To: <41a1e4b3-e497-43eb-8095-c2254afa2407@googlegroups.com> References: <477a0f61-87d6-4937-8467-743fc053ecec@googlegroups.com> <41a1e4b3-e497-43eb-8095-c2254afa2407@googlegroups.com> Message-ID: On 17 September 2013 14:35, Josef Pktd wrote: >> (As an aside, this is all much simpler if you're using Ubuntu or some >> other Linux distro rather than Windows.) > > scientific python on a stick > > https://code.google.com/p/winpython/wiki/PackageIndex_33 Thanks, I've just installed that and I'll try it out later. > I haven't seen any problems so far on python 3.3 > The statsmodels test suite passes without problems on python 3.3 also, as far as I remember. > (and no problems using Windows. just use the right binaries.) Well that's exactly my point. On a Linux distro you would have the right binaries first time. No need to search through project webpages or documentation, weigh up different installers, or download 750MB of software that you mostly won't use. Similarly on a Linux distro it's a lot easier to get all of the build tools set up to build these things from source if you'd prefer. Windows users are often dependent on inconsistent sources of binaries. In this case I imagine that the OP installed numpy from sourceforge since it has 3.3 binaries but it doesn't have the same for scipy at which point googling would easily lead to Cristoph's page. Oscar From josef.pktd at gmail.com Tue Sep 17 10:52:53 2013 From: josef.pktd at gmail.com (Josef Perktold) Date: Tue, 17 Sep 2013 14:52:53 +0000 (UTC) Subject: statsmodels.api References: <477a0f61-87d6-4937-8467-743fc053ecec@googlegroups.com> <41a1e4b3-e497-43eb-8095-c2254afa2407@googlegroups.com> Message-ID: Oscar Benjamin gmail.com> writes: > > On 17 September 2013 14:35, Josef Pktd gmail.com> wrote: > >> (As an aside, this is all much simpler if you're using Ubuntu or some > >> other Linux distro rather than Windows.) > > > > scientific python on a stick > > > > https://code.google.com/p/winpython/wiki/PackageIndex_33 > > Thanks, I've just installed that and I'll try it out later. > > > I haven't seen any problems so far on python 3.3 > > The statsmodels test suite passes without problems on python 3.3 also, as far as I remember. > > (and no problems using Windows. just use the right binaries.) > > Well that's exactly my point. On a Linux distro you would have the > right binaries first time. No need to search through project webpages > or documentation, weigh up different installers, or download 750MB of > software that you mostly won't use. Similarly on a Linux distro it's a > lot easier to get all of the build tools set up to build these things > from source if you'd prefer. This might be true for many Linux users. However, the last time I tried to install something in a virtual Linux OS that was not in the standard repository, I was completely lost. (I'm a Windows user.) > > Windows users are often dependent on inconsistent sources of binaries. > In this case I imagine that the OP installed numpy from sourceforge > since it has 3.3 binaries but it doesn't have the same for scipy at > which point googling would easily lead to Cristoph's page. Another problem with relying on binaries on Windows is when the matching binaries are not available. For example, the Windows binaries on pypi of pandas and statsmodels are compiled against the latest numpy release and will not work with older numpy versions. ( http://stackoverflow.com/questions/17709641/valueerror-numpy-dtype-has-the-wrong-size-try-recompiling/18369312 ) On the other hand, python-xy comes with MingW, and I never had any problems compiling pandas and statsmodels for any version combination of python and numpy that I tested (although 32 bit only so far, I never set up the Microsoft sdk). (latest news: moving to MingW-64 for numpy and scipy, and related packages, might be on the way.) Josef > > Oscar > From oscar.j.benjamin at gmail.com Tue Sep 17 11:41:10 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 17 Sep 2013 16:41:10 +0100 Subject: statsmodels.api In-Reply-To: References: <477a0f61-87d6-4937-8467-743fc053ecec@googlegroups.com> <41a1e4b3-e497-43eb-8095-c2254afa2407@googlegroups.com> Message-ID: On 17 September 2013 15:52, Josef Perktold wrote: > > On the other hand, python-xy comes with MingW, and I never had any problems > compiling pandas and statsmodels for any version combination of python and > numpy that I tested (although 32 bit only so far, I never set up the > Microsoft sdk). Just out of interest: out of the box Python.org distutils is incompatible with recent versions of MinGW. If Python-xy distributes MinGW (and it works) then they're either creating a special patched MinGW set up or patching distutils. I don't want to install Python-xy myself since it'll clobber my existing Python installation but could you answer the following for me: 1) What gcc version did Python-xy install for you? 2) Does the distutils.cygwincompiler module it installs contain the following lines (around about line 300) specifically with the '-mno-cygwin' option? self.set_executables(compiler='gcc -mno-cygwin -O -Wall', compiler_so='gcc -mno-cygwin -mdll -O -Wall', compiler_cxx='g++ -mno-cygwin -O -Wall', linker_exe='gcc -mno-cygwin', linker_so='%s -mno-cygwin %s %s' Oscar From josef.pktd at gmail.com Tue Sep 17 12:15:05 2013 From: josef.pktd at gmail.com (Josef Perktold) Date: Tue, 17 Sep 2013 16:15:05 +0000 (UTC) Subject: statsmodels.api References: <477a0f61-87d6-4937-8467-743fc053ecec@googlegroups.com> <41a1e4b3-e497-43eb-8095-c2254afa2407@googlegroups.com> Message-ID: Oscar Benjamin gmail.com> writes: > > On 17 September 2013 15:52, Josef Perktold gmail.com> wrote: > > > > On the other hand, python-xy comes with MingW, and I never had any problems > > compiling pandas and statsmodels for any version combination of python and > > numpy that I tested (although 32 bit only so far, I never set up the > > Microsoft sdk). > > Just out of interest: out of the box Python.org distutils is > incompatible with recent versions of MinGW. If Python-xy distributes > MinGW (and it works) then they're either creating a special patched > MinGW set up or patching distutils. I don't want to install Python-xy > myself since it'll clobber my existing Python installation but could > you answer the following for me: > > 1) What gcc version did Python-xy install for you? > > 2) Does the distutils.cygwincompiler module it installs contain the > following lines (around about line 300) specifically with the > '-mno-cygwin' option? > > self.set_executables(compiler='gcc -mno-cygwin -O -Wall', > compiler_so='gcc -mno-cygwin -mdll -O -Wall', > compiler_cxx='g++ -mno-cygwin -O -Wall', > linker_exe='gcc -mno-cygwin', > linker_so='%s -mno-cygwin %s %s' I installed python-xy 2 years ago with python 2.6 and didn't update, so my information is not up-to-date It looks like my MingW version uses mingw32-gcc-4.4.0.exe for python 2.6 which came with python-xy: self.set_executables(compiler='gcc -mno-cygwin -O -Wall', compiler_so='gcc -mno-cygwin -mdll -O -Wall', compiler_cxx='g++ -mno-cygwin -O -Wall', linker_exe='gcc -mno-cygwin', linker_so='%s -mno-cygwin %s %s' % (self.linker_dll, shared_option, entry_point)) However, I'm running python 2.5, 2.7, 3.2 and 3.3 additionally. And they are all python.org versions without any changes (except IDLE bugs :). I don't have any compilation problems with any of them. Until recently statsmodels used distutils from numpy which adds some patches AFAIK. The current statsmodels setup.py just uses plain distutils and setuptools. (The setup.py is largely copied from pandas which has a lot more C extensions than statsmodels.) numpy scipy binaries for Windows are still compiled against MingW 3.x, but David Cournapeau is looking into upgrading to the latest MingW(-64) right now. also (from some comments about problems a long time ago): I don't have cygwin installed, so there is no confusion between cygwin and msys/mingw paths possible. Josef > > Oscar > From josef.pktd at gmail.com Tue Sep 17 20:03:21 2013 From: josef.pktd at gmail.com (Josef Perktold) Date: Wed, 18 Sep 2013 00:03:21 +0000 (UTC) Subject: statsmodels.api References: <477a0f61-87d6-4937-8467-743fc053ecec@googlegroups.com> <41a1e4b3-e497-43eb-8095-c2254afa2407@googlegroups.com> Message-ID: Josef Perktold gmail.com> writes: > > Oscar Benjamin gmail.com> writes: > > > > > On 17 September 2013 15:52, Josef Perktold gmail.com> wrote: > > > > > > On the other hand, python-xy comes with MingW, and I never had any problems > > > compiling pandas and statsmodels for any version combination of python and > > > numpy that I tested (although 32 bit only so far, I never set up the > > > Microsoft sdk). > > > > Just out of interest: out of the box Python.org distutils is > > incompatible with recent versions of MinGW. If Python-xy distributes > > MinGW (and it works) then they're either creating a special patched > > MinGW set up or patching distutils. I don't want to install Python-xy > > myself since it'll clobber my existing Python installation but could > > you answer the following for me: > > > > 1) What gcc version did Python-xy install for you? I did a bit of homework. I didn't know about the -mno-cygwin issue since it didn't affect me yet. python-xy is staying below 4.6: GCC Core, G77, G++ 4.5.2 ; MingW 4.5.2.3 https://code.google.com/p/pythonxy/wiki/StandardPlugins and has open issue on it pandas has an open issue where a user reported problems with --mno-cygwin. Josef > > Josef > > > > > Oscar > > > > From davide.dalmasso at gmail.com Tue Sep 17 10:46:55 2013 From: davide.dalmasso at gmail.com (Davide Dalmasso) Date: Tue, 17 Sep 2013 07:46:55 -0700 (PDT) Subject: statsmodels.api In-Reply-To: References: <477a0f61-87d6-4937-8467-743fc053ecec@googlegroups.com> <41a1e4b3-e497-43eb-8095-c2254afa2407@googlegroups.com> Message-ID: <8c264a36-47ed-4ecc-bf06-23ea52dc5680@googlegroups.com> Oscar you are right! The problem was Numpy! I re-installed it using an executable that I downloaded from: http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy I don't remember if previously I installed it using another source. However the problem now is disappeared! Many thanks! Davide From davide.dalmasso at gmail.com Tue Sep 17 08:15:13 2013 From: davide.dalmasso at gmail.com (Davide Dalmasso) Date: Tue, 17 Sep 2013 05:15:13 -0700 (PDT) Subject: statsmodels.api In-Reply-To: References: Message-ID: On Monday, 16 September 2013 17:37:58 UTC+2, Davide Dalmasso wrote: > Hi, > > > > I intalled an executable version of statsmodels library for Windows 32-bit. > > When I import it in my Python Shell no problem occurs buy when I write: > > > > import statsmodels.api as sm > > > > the following error arises: > > > > Traceback (most recent call last): > > File "", line 1, in > > import statsmodels.api > > File "C:\Python33\lib\site-packages\statsmodels\api.py", line 1, in > > from . import iolib, datasets, tools > > File "C:\Python33\lib\site-packages\statsmodels\iolib\__init__.py", line 1, in > > from .foreign import StataReader, genfromdta, savetxt > > File "C:\Python33\lib\site-packages\statsmodels\iolib\foreign.py", line 20, in > > import statsmodels.tools.data as data_util > > File "C:\Python33\lib\site-packages\statsmodels\tools\__init__.py", line 1, in > > from .tools import add_constant, categorical > > File "C:\Python33\lib\site-packages\statsmodels\tools\tools.py", line 8, in > > from scipy.interpolate import interp1d > > File "C:\Python33\lib\site-packages\scipy\interpolate\__init__.py", line 150, in > > from .interpolate import * > > File "C:\Python33\lib\site-packages\scipy\interpolate\interpolate.py", line 12, in > > import scipy.special as spec > > File "C:\Python33\lib\site-packages\scipy\special\__init__.py", line 529, in > > from ._ufuncs import * > > > > Why? > > > > Thanks for any help you will want to give me! > > > > Davide From sg552 at hotmail.co.uk Mon Sep 16 12:28:24 2013 From: sg552 at hotmail.co.uk (Rotwang) Date: Mon, 16 Sep 2013 17:28:24 +0100 Subject: Weird ttk behaviour Message-ID: Hi all, I've just started trying to learn how to use ttk, and I've discovered something that I don't understand. I'm using Python 3.3.0 in Linux Mint 15. Suppose I create the following module: # begin tkderp.py import tkinter as tk import tkinter.messagebox as _ from tkinter import ttk from imp import reload _root = tk.Tk() _root.withdraw() def f(): style = ttk.Style(_root) style.theme_create('newtheme', parent = 'default') tk.messagebox.showwarning('test', 'test') style.theme_use('newtheme') tk.messagebox.showwarning('test', 'test') # end tkderp.py The function f() is supposed to spawn two warning dialogs. AIUI, the "style.theme.use('newtheme')" line shouldn't make any difference - it would refresh any existing ttk widgets and alter the appearance of any subsequently created ones if I had changed any of the new theme's settings, but in the above context nothing it does should be discernible to the user. If I try to call f() the first warning gets shown, but the second one causes an exception: Python 3.3.1 (default, Apr 17 2013, 22:30:32) [GCC 4.7.3] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import tkderp >>> tkderp.f() Traceback (most recent call last): File "", line 1, in File "/home/phil/Python/tkderp.py", line 17, in f tk.messagebox.showwarning('test', 'test') File "/usr/lib/python3.3/tkinter/messagebox.py", line 87, in showwarning return _show(title, message, WARNING, OK, **options) File "/usr/lib/python3.3/tkinter/messagebox.py", line 72, in _show res = Message(**options).show() File "/usr/lib/python3.3/tkinter/commondialog.py", line 48, in show s = w.tk.call(self.command, *w._options(self.options)) _tkinter.TclError: unknown color name "" If I try reloading the module and calling the function again, this time the first of the two warnings raises the exception. Since I don't really understand how the ttk.Style class works, I can't say whether this behaviour is expected or not. But here's what's weird. Suppose that I comment out the last two lines in the definition of f(), like so: # begin modified tkderp.py import tkinter as tk import tkinter.messagebox as _ from tkinter import ttk from imp import reload _root = tk.Tk() _root.withdraw() def f(): style = ttk.Style(_root) style.theme_create('newtheme', parent = 'default') tk.messagebox.showwarning('test', 'test') #style.theme_use('newtheme') #tk.messagebox.showwarning('test', 'test') # end modified tkderp.py Unsurprisingly, importing the module and calling f() displays a single warning dialog and raises no exception. If I then uncomment those two lines, reload the module and call f() again (by entering tkderp.reload(tkderp).f()), the function works like it was supposed to in the first place: two warnings, no exceptions. I can reload the module as many times as I like and f() will continue to work without any problems. On Windows 7 (sys.version is '3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:57:17) [MSC v.1600 64 bit (AMD64)]') there's no problem; f() works fine in the first place. Does anybody know what's going on? From storchaka at gmail.com Mon Sep 16 14:43:37 2013 From: storchaka at gmail.com (Serhiy Storchaka) Date: Mon, 16 Sep 2013 21:43:37 +0300 Subject: Weird ttk behaviour In-Reply-To: References: Message-ID: 16.09.13 19:28, Rotwang ???????(??): > On Windows 7 (sys.version is '3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, > 10:57:17) [MSC v.1600 64 bit (AMD64)]') there's no problem; f() works > fine in the first place. Does anybody know what's going on? What _root.wantobjects() returns? From rosuav at gmail.com Mon Sep 16 18:34:08 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 Sep 2013 08:34:08 +1000 Subject: Weird ttk behaviour In-Reply-To: References: Message-ID: On Tue, Sep 17, 2013 at 2:28 AM, Rotwang wrote: > If I then uncomment those two lines, reload the module and call f() again > (by entering tkderp.reload(tkderp).f()), the function works like it was > supposed to in the first place: two warnings, no exceptions. I can reload > the module as many times as I like and f() will continue to work without any > problems. Reloading modules in Python is a bit messy. Are you able to tinker with it and make it work in some way without reloading? It'd be easier to figure out what's going on that way. ChrisA From sg552 at hotmail.co.uk Tue Sep 17 07:15:20 2013 From: sg552 at hotmail.co.uk (Rotwang) Date: Tue, 17 Sep 2013 12:15:20 +0100 Subject: Weird ttk behaviour In-Reply-To: References: Message-ID: On 16/09/2013 19:43, Serhiy Storchaka wrote: > 16.09.13 19:28, Rotwang ???????(??): >> On Windows 7 (sys.version is '3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, >> 10:57:17) [MSC v.1600 64 bit (AMD64)]') there's no problem; f() works >> fine in the first place. Does anybody know what's going on? > > What _root.wantobjects() returns? It returns True, both before and after the call to style.theme_use('newtheme'). Why do you ask? I've no idea what Tk.wantobjects is supposed to do (I tried help() and some web searches with no luck). From sg552 at hotmail.co.uk Tue Sep 17 07:27:47 2013 From: sg552 at hotmail.co.uk (Rotwang) Date: Tue, 17 Sep 2013 12:27:47 +0100 Subject: Weird ttk behaviour In-Reply-To: References: Message-ID: On 16/09/2013 23:34, Chris Angelico wrote: > On Tue, Sep 17, 2013 at 2:28 AM, Rotwang wrote: >> If I then uncomment those two lines, reload the module and call f() again >> (by entering tkderp.reload(tkderp).f()), the function works like it was >> supposed to in the first place: two warnings, no exceptions. I can reload >> the module as many times as I like and f() will continue to work without any >> problems. > > Reloading modules in Python is a bit messy. Are you able to tinker > with it and make it work in some way without reloading? It'd be easier > to figure out what's going on that way. I can't think what else I could try, do you have any suggestions? The problem first appeared in a much larger module (I was trying to replace some tkinter widgets that looked bad on Linux with their ttk equivalents); the only reason I noticed the thing about reloading is that I was trying to reproduce the error in a short module by repeatedly making changes and reloading. From rosuav at gmail.com Tue Sep 17 07:32:55 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 Sep 2013 21:32:55 +1000 Subject: Weird ttk behaviour In-Reply-To: References: Message-ID: On Tue, Sep 17, 2013 at 9:27 PM, Rotwang wrote: > On 16/09/2013 23:34, Chris Angelico wrote: >> >> On Tue, Sep 17, 2013 at 2:28 AM, Rotwang wrote: >>> >>> If I then uncomment those two lines, reload the module and call f() again >>> (by entering tkderp.reload(tkderp).f()), the function works like it was >>> supposed to in the first place: two warnings, no exceptions. I can reload >>> the module as many times as I like and f() will continue to work without >>> any >>> problems. >> >> >> Reloading modules in Python is a bit messy. Are you able to tinker >> with it and make it work in some way without reloading? It'd be easier >> to figure out what's going on that way. > > > I can't think what else I could try, do you have any suggestions? The > problem first appeared in a much larger module (I was trying to replace some > tkinter widgets that looked bad on Linux with their ttk equivalents); the > only reason I noticed the thing about reloading is that I was trying to > reproduce the error in a short module by repeatedly making changes and > reloading. If reloading and doing it again makes things different, what happens if you simply trigger your code twice without reloading? I've no idea if it'll help, it just seems like an attack vector on the problem, so to speak. ChrisA From sg552 at hotmail.co.uk Tue Sep 17 10:25:43 2013 From: sg552 at hotmail.co.uk (Rotwang) Date: Tue, 17 Sep 2013 15:25:43 +0100 Subject: Weird ttk behaviour In-Reply-To: References: Message-ID: On 17/09/2013 12:32, Chris Angelico wrote: > [...] > > If reloading and doing it again makes things different, what happens > if you simply trigger your code twice without reloading? > > I've no idea if it'll help, it just seems like an attack vector on the > problem, so to speak. Thanks for the suggestion, here's what I've found with some more testing. If I rewrite the function f() like this: def f(fail): style = ttk.Style(_root) style.theme_create('newtheme', parent = 'default') tk.messagebox.showwarning('test', 'test') if fail: style.theme_use('newtheme') tk.messagebox.showwarning('test', 'test') then I import the module and call f(False) followed by f(True), the second call raises an exception just like the original function. I've tried variations of the above, such as defining a module-level global style instead of having one created during the function call, and the end result is always the same. However, suppose instead I define two modules, tkderp and tkderp2; both have a function f as defined in my OP, but the first has the last two lines of f commented out, and the second doesn't (i.e. tkderp is the modified tkderp from before, and tkderp2 is the original). Then I do this: >>> import tkderp >>> tkderp.f() >>> import tkderp2 >>> tkderp2.f() In that case the second call to f() works fine - two warnings, no exception. In fact, if I replace tkderp with this: # begin tkderp.py import tkinter as tk _root = tk.Tk() _root.withdraw() # end tkderp.py then simply importing tkderp before tkderp2 is enough to make the latter work properly - this >>> import tkderp2 >>> tkderp2.f() raises an exception, but this >>> import tkderp >>> import tkderp2 >>> tkderp2.f() doesn't. Any ideas what may be going on? From rosuav at gmail.com Tue Sep 17 10:35:58 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 18 Sep 2013 00:35:58 +1000 Subject: Weird ttk behaviour In-Reply-To: References: Message-ID: On Wed, Sep 18, 2013 at 12:25 AM, Rotwang wrote: > In fact, if I replace tkderp with this: > > > # begin tkderp.py > > import tkinter as tk > > _root = tk.Tk() > _root.withdraw() > > # end tkderp.py > > > then simply importing tkderp before tkderp2 is enough to make the latter > work properly Nice piece of detective work! Alas, I don't know tkinter well enough to help with the details, but this is exactly what I'd like to hear if I were trying to pick this up and debug it :) Tkinter experts, anywhere? Where's Ranting Rick when you need him... ChrisA From sg552 at hotmail.co.uk Tue Sep 17 12:11:28 2013 From: sg552 at hotmail.co.uk (Rotwang) Date: Tue, 17 Sep 2013 17:11:28 +0100 Subject: Weird ttk behaviour In-Reply-To: References: Message-ID: On 17/09/2013 15:35, Chris Angelico wrote: > On Wed, Sep 18, 2013 at 12:25 AM, Rotwang wrote: >> In fact, if I replace tkderp with this: >> >> >> # begin tkderp.py >> >> import tkinter as tk >> >> _root = tk.Tk() >> _root.withdraw() >> >> # end tkderp.py >> >> >> then simply importing tkderp before tkderp2 is enough to make the latter >> work properly > > Nice piece of detective work! Alas, I don't know tkinter well enough > to help with the details, but this is exactly what I'd like to hear if > I were trying to pick this up and debug it :) I don't know tkinter well enough either, but the fact that it behaves differently on Linux and Windows suggests to me that at least one version is bugging out. Do you think this is worth raising on bugs.python.org? > Tkinter experts, anywhere? Where's Ranting Rick when you need him... Last time I saw him was in this thread: https://mail.python.org/pipermail/python-list/2013-June/650257.html From rosuav at gmail.com Tue Sep 17 12:20:50 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 18 Sep 2013 02:20:50 +1000 Subject: Weird ttk behaviour In-Reply-To: References: Message-ID: On Wed, Sep 18, 2013 at 2:11 AM, Rotwang wrote: > I don't know tkinter well enough either, but the fact that it behaves > differently on Linux and Windows suggests to me that at least one version is > bugging out. Do you think this is worth raising on bugs.python.org? Possibly, but I'd keep it here on python-list for the moment; it may be you're actually using undefined behaviour somewhere, in which case the solution is to change your code. Once someone else (someone who actually knows what he's talking about, for preference) can confirm what's going on, it'll be bug report time, I think. ChrisA From ibscofield at gmail.com Mon Sep 16 18:27:53 2013 From: ibscofield at gmail.com (Ibrahima Barry) Date: Mon, 16 Sep 2013 15:27:53 -0700 (PDT) Subject: New on python Message-ID: hello everyone, I am a beginner in python programming language, so I need help with the basics, the synthaxes, functions, please help me From rosuav at gmail.com Mon Sep 16 18:31:47 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 Sep 2013 08:31:47 +1000 Subject: New on python In-Reply-To: References: Message-ID: On Tue, Sep 17, 2013 at 8:27 AM, Ibrahima Barry wrote: > hello everyone, I am a beginner in python programming language, so I need help with the basics, the synthaxes, functions, please help me Welcome! Python tutorials can be found all over the internet. Here's one good one: http://docs.python.org/3/tutorial/ Have fun! ChrisA From ben+python at benfinney.id.au Mon Sep 16 18:55:45 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 17 Sep 2013 08:55:45 +1000 Subject: New on python References: Message-ID: <7weh8oz89a.fsf@benfinney.id.au> Ibrahima Barry writes: > hello everyone, I am a beginner in python programming language Welcome, and congratulations on finding Python. > so I need help with the basics, the synthaxes, functions, please help > me At the Python website you can find a page linking to other documentation , especially the Python tutorial . The Python Wiki has a page specially for beginners guides . Good hunting! -- \ ?There's a certain part of the contented majority who love | `\ anybody who is worth a billion dollars.? ?John Kenneth | _o__) Galbraith, 1992-05-23 | Ben Finney From gogobebe2 at gmail.com Mon Sep 16 19:33:35 2013 From: gogobebe2 at gmail.com (William Bryant) Date: Mon, 16 Sep 2013 16:33:35 -0700 (PDT) Subject: How do I calculate a mean with python? Message-ID: <571f1251-17a5-44db-a859-17a6d8065151@googlegroups.com> Hey I am new to python so go easy, but I wanted to know how to make a program that calculates the maen. List = [15, 6, 6, 7, 8, 9, 40] def mean(): global themean, thesum for i in List: thecount = List.count(i) thesum = sum(List) themean = thesum / thecount Why doesn't this work? From jugurtha.hadjar at gmail.com Mon Sep 16 19:52:17 2013 From: jugurtha.hadjar at gmail.com (Jugurtha Hadjar) Date: Tue, 17 Sep 2013 00:52:17 +0100 Subject: How do I calculate a mean with python? In-Reply-To: <571f1251-17a5-44db-a859-17a6d8065151@googlegroups.com> References: <571f1251-17a5-44db-a859-17a6d8065151@googlegroups.com> Message-ID: <523799B1.8020805@gmail.com> On 09/17/2013 12:33 AM, William Bryant wrote: > Hey I am new to python so go easy, but I wanted to know how to make a program that calculates the maen. > > List = [15, 6, 6, 7, 8, 9, 40] > def mean(): > global themean, thesum > for i in List: > thecount = List.count(i) > thesum = sum(List) > themean = thesum / thecount > > Why doesn't this work? > Hello, William.. How about you try to execute one bit of your program, and if that works, try to add to it. Try list = [15, 6] list.count(1) And see if what it gives you back is what you expected. If not, why ? -- ~Jugurtha Hadjar, From steve+comp.lang.python at pearwood.info Mon Sep 16 19:55:07 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Sep 2013 23:55:07 GMT Subject: How do I calculate a mean with python? References: <571f1251-17a5-44db-a859-17a6d8065151@googlegroups.com> Message-ID: <52379a5b$0$29988$c3e8da3$5496439d@news.astraweb.com> On Mon, 16 Sep 2013 16:33:35 -0700, William Bryant wrote: > Hey I am new to python so go easy, but I wanted to know how to make a > program that calculates the maen. > > List = [15, 6, 6, 7, 8, 9, 40] > def mean(): > global themean, thesum > for i in List: > thecount = List.count(i) > thesum = sum(List) > themean = thesum / thecount > > Why doesn't this work? Let me start by saying that the above is not "best practice" for how to write functions, and I'll explain why later, but for now I'll just fix the problem with the calculation. You have List = [15, 6, 6, 7, 8, 9, 40] and then the mean function walks through each of the items 15, 6, 6, 7, ... counting how many times that item is found: for i in List: thecount = List.count(i) thesum = sum(List) So the first time, i gets the value 15, thecount calculates List.count(15) which is 1, thesum calculates sum(List) which is 91, and the end of the loop is reached. The second time around, i gets the value 6, then thecount calculates List.count(6) which is 2, thesum calculates sum(List) *again*, which is still 91, and the end of the loop is reached. Third time around, i gets the value 6 again, thecount again gets the value 2, thesum yet again sums up List which still hasn't changed, so yet again gets 91. And so on, and so on, until the last iteration, where i gets the value 40, thecount calculates List.count(40) which is 1, thesum re-calculates the sum yet again, still getting the exact same result 91, and finally the for-loop comes to an end. Now the final calculation occurs: themean = thesum/thecount which is 91/1 or just 91. What do you actually want? It's much simpler: you want to count the *total* number of items, 7, not by counting each item individually. The total number of items is given by the length of the list: len(List) returns 7. And you want to sum the list once, there's no need to sum it 7 times. So the first step is to get rid of the for-loop, just calculate thesum = sum(List) once, and thecount = len(List) once. Once you've done that, please write back with your new code, because I think there will be some more improvements to be made. -- Steven From python at mrabarnett.plus.com Mon Sep 16 20:01:50 2013 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 17 Sep 2013 01:01:50 +0100 Subject: How do I calculate a mean with python? In-Reply-To: <571f1251-17a5-44db-a859-17a6d8065151@googlegroups.com> References: <571f1251-17a5-44db-a859-17a6d8065151@googlegroups.com> Message-ID: <52379BEE.9050400@mrabarnett.plus.com> On 17/09/2013 00:33, William Bryant wrote: > Hey I am new to python so go easy, but I wanted to know how to make a program that calculates the maen. > > List = [15, 6, 6, 7, 8, 9, 40] > def mean(): > global themean, thesum You're iterating through every number in the list... > for i in List: counting how many times each number occurs in the list: > thecount = List.count(i) This line calculates the sum of the numbers on every iteration: > thesum = sum(List) This line divides the sum of the numbers by the last count: > themean = thesum / thecount > > Why doesn't this work? > It does work; it just doesn't calculate the mean! What you end up with is: themean = sum(List) / List.count(40) What you _really_ want is the sum of the numbers divided by the number of numbers (i.e. the length of the list). From jugurtha.hadjar at gmail.com Mon Sep 16 20:08:42 2013 From: jugurtha.hadjar at gmail.com (Jugurtha Hadjar) Date: Tue, 17 Sep 2013 01:08:42 +0100 Subject: How do I calculate a mean with python? In-Reply-To: <571f1251-17a5-44db-a859-17a6d8065151@googlegroups.com> References: <571f1251-17a5-44db-a859-17a6d8065151@googlegroups.com> Message-ID: <52379D8A.3020601@gmail.com> On 09/17/2013 12:33 AM, William Bryant wrote: > Hey I am new to python so go easy, but I wanted to know how to make a program that calculates the maen. > > List = [15, 6, 6, 7, 8, 9, 40] > def mean(): > global themean, thesum > for i in List: > thecount = List.count(i) > thesum = sum(List) > themean = thesum / thecount > > Why doesn't this work? > You want to compute the arithmetic mean, I suppose .. Which is the sum of all, divided by the number of samples. i.e: If you have n numbers or elements, your mean (arithmetic) would be mean = sum(elements)/n. Right ? And then, n also doesn't need to be in the loop and list.count(i) gives the occurrences of i in your list, which you don't need. list.count(15) gives 1. thesum/list.count(15) doesn't change. -- ~Jugurtha Hadjar, From cs at zip.com.au Mon Sep 16 19:59:45 2013 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 17 Sep 2013 09:59:45 +1000 Subject: How do I calculate a mean with python? In-Reply-To: <571f1251-17a5-44db-a859-17a6d8065151@googlegroups.com> References: <571f1251-17a5-44db-a859-17a6d8065151@googlegroups.com> Message-ID: <20130916235945.GA55728@cskk.homeip.net> On 16Sep2013 16:33, William Bryant wrote: | Hey I am new to python so go easy, but I wanted to know how to make a program that calculates the maen. | | List = [15, 6, 6, 7, 8, 9, 40] | def mean(): | global themean, thesum | for i in List: | thecount = List.count(i) | thesum = sum(List) | themean = thesum / thecount | | Why doesn't this work? Well: - always include the output you get from your program, and say why you think it is incorrect - just style: we tend to name variables in lower case in Python, and classes with an upper case letter; "List" is a bit odd (but "list" is taken; how about "values"?) - more than style: WHY are you using global variables; just return the mean from the function! - teh variable "List" inside the function is _local_; your function does not accept a parameter - sum(List) sums the whole list you run it many times why? - what do you think "count()" does? - you should print i, thecount and thesum on each iteration of the list; it will help you see what your function is doing, and therefore to figure out what it is doing wrong I would write a mean like this: def mean(values): return sum(values) / len(values) There are circumstances where that is simplistic, but it is the classic definition of the mean. Cheers, -- Cameron Simpson Microsoft Mail: as far from RFC-822 as you can get and still pretend to care. - Abby Franquemont-Guillory From davea at davea.name Mon Sep 16 20:50:06 2013 From: davea at davea.name (Dave Angel) Date: Tue, 17 Sep 2013 00:50:06 +0000 (UTC) Subject: How do I calculate a mean with python? References: <571f1251-17a5-44db-a859-17a6d8065151@googlegroups.com> Message-ID: On 16/9/2013 19:33, William Bryant wrote: > Hey I am new to python so go easy, but I wanted to know how to make a program that calculates the maen. > > List = [15, 6, 6, 7, 8, 9, 40] > def mean(): > global themean, thesum > for i in List: > thecount = List.count(i) > thesum = sum(List) > themean = thesum / thecount > > Why doesn't this work? Besides all the other comments, you also neglected calling this function. -- DaveA From travisgriggs at gmail.com Tue Sep 17 11:25:35 2013 From: travisgriggs at gmail.com (Travis Griggs) Date: Tue, 17 Sep 2013 08:25:35 -0700 Subject: How do I calculate a mean with python? In-Reply-To: <571f1251-17a5-44db-a859-17a6d8065151@googlegroups.com> References: <571f1251-17a5-44db-a859-17a6d8065151@googlegroups.com> Message-ID: <4A98B77A-A8D8-4290-96B9-7CD4517ACD06@gmail.com> On Sep 16, 2013, at 4:33 PM, William Bryant wrote: > Hey I am new to python so go easy, but I wanted to know how to make a program that calculates the maen. > > List = [15, 6, 6, 7, 8, 9, 40] > def mean(): > global themean, thesum > for i in List: > thecount = List.count(i) > thesum = sum(List) > themean = thesum / thecount > > Why doesn't this work? > -- > https://mail.python.org/mailman/listinfo/python-list You've had a number of interesting and good responses, some holding your hand quite a bit, and others differently. I think there's a different way to learn what's going wrong, that ISN'T mentioned here, and for some people it's a quite effective method of learning. I'm a relatively recent import from the Smalltalk community, where this approach is more prevalent, I wish it were more so in the Python community. The way I suggest is to use a debugger. The nice thing about a debugger, is that you add a call to mean() at the end, put a breakpoint right there, run, and then you can visually walk through what it's doing. This can help find your bug, but probably also clarify how Python works in the first place. I use pycharm (anyone can use it for free). And there are probably others for free as well. From gogobebe2 at gmail.com Tue Sep 17 15:44:47 2013 From: gogobebe2 at gmail.com (William Bryant) Date: Tue, 17 Sep 2013 12:44:47 -0700 (PDT) Subject: How do I calculate a mean with python? In-Reply-To: <571f1251-17a5-44db-a859-17a6d8065151@googlegroups.com> References: <571f1251-17a5-44db-a859-17a6d8065151@googlegroups.com> Message-ID: <91fe5a4b-45f6-4903-bd1a-ebf5c82ebb48@googlegroups.com> Sorry guys, I didn't read anything u said. Because I just figured it out on my own :) I'll read it now. But u can check out my program I have done so far (It works but I think it needs some tidying up.) :) Thanks! From gogobebe2 at gmail.com Tue Sep 17 15:45:07 2013 From: gogobebe2 at gmail.com (William Bryant) Date: Tue, 17 Sep 2013 12:45:07 -0700 (PDT) Subject: How do I calculate a mean with python? In-Reply-To: <571f1251-17a5-44db-a859-17a6d8065151@googlegroups.com> References: <571f1251-17a5-44db-a859-17a6d8065151@googlegroups.com> Message-ID: '''#*************************************************************************''' #* Name: Mode-Median-Mean Calculator *# #* *# #* Purpose: To calculate the mode, median and mean of a list of numbers *# #* and the mode of a list of strings because that is what we are *# #* learning in math atm in school :P *# #* *# #* Author: William Bryant *# #* *# #* Created: 11/09/2013 *# #* *# #* Copyright: (c) William 2013 *# #* *# #* Licence: IDK :3 *# '''**************************************************************************''' #-----# ~~Import things I am using~~ #-----# # | # | # \/ import time import itertools #-----# ~~Variables that I am using, including the list.~~ #-----# # | # | # \/ List = [] NumberOfXItems = [] themode = None themean = None count = None #-----# ~~Functions that I am using.~~ #-----# # | # | # \/ def HMNs(): global TheStr, user_inputHMNs, List_input, List user_inputHMNs = input("You picked string. This program cannot calculate the mean or median, but it can calculate the mode. :D How many strings are you using in your list? (Can not be a decimal number) \nEnter: ") user_inputHMNs time.sleep(1.5) TheStr = int(user_inputHMNs) for i in range(TheStr): List_input = input("Enter your strings. (One in each input field): ") List.append(List_input) print("Your list -> ", List) if List.count == int(user_inputHMNs): break mode() mean() print("\n*Mode*:", themode) print("*Median*:", "\n") print("*Mean*:", themean) def HMNn(): global TheNum, user_inputHMNn, List_input, List user_inputHMNn = input("You picked number. :D How many numbers are you using in your list? (Can not be a decimal number) \nEnter: ") user_inputHMNn time.sleep(1.5) TheNum = int(user_inputHMNn) for i in range(TheNum): List_input = input("Enter your numbers. (One in each input field): ") List_input = int(List_input) List.append(List_input) print("\nYour list -> ", List) if List.count == int(user_inputHMNn): break mode() mean() print("\n*Mode*:", themode) print("*Median*:", "") print("*Mean*:", themean) def NOS(): while True: # Loops forever (until the break) answer = input("Does your list contain a number or a string? \nEnter: ") answer = answer.lower() if answer in ("string", "str", "s"): HMNs() break elif answer in ("number", "num", "n", "int"): HMNn() break elif answer in ("quit", "q"): break # Exits the while loop else: print("You did not enter a valid field, :P Sorry. \nEnter: ") time.sleep(1.5) def mean(): global themean thecount = [] for i in List: thecount.append(List.count(i)) thesum = sum(List) thecount = sum(thecount) themean = thesum / thecount def mode(): global themode max_occurrences = 0 themode = None for i in List: thecount = List.count(i) if thecount > max_occurrences: max_occurrences = thecount themode = i #-----# ~~The functions which need calling~~ #-----# # | # | # \/ NOS() From gogobebe2 at gmail.com Tue Sep 17 16:10:07 2013 From: gogobebe2 at gmail.com (William Bryant) Date: Tue, 17 Sep 2013 13:10:07 -0700 (PDT) Subject: How do I calculate a mean with python? In-Reply-To: <571f1251-17a5-44db-a859-17a6d8065151@googlegroups.com> References: <571f1251-17a5-44db-a859-17a6d8065151@googlegroups.com> Message-ID: <1540971c-7868-4f01-be3b-98fd5dffa985@googlegroups.com> Ok I think I've fixed it thanks I read everything. '''**************************************************************************''' #* Name: Mode-Median-Mean Calculator *# #* *# #* Purpose: To calculate the mode, median and mean of a list of numbers *# #* and the mode of a list of strings because that is what we are *# #* learning in math atm in school :P *# #* *# #* Author: William Bryant *# #* *# #* Created: 11/09/2013 *# #* *# #* Copyright: (c) William 2013 *# #* *# #* Licence: IDK :3 *# '''**************************************************************************''' #-----# ~~Import things I am using~~ #-----# # | # | # \/ import time import itertools #-----# ~~Variables that I am using, including the list.~~ #-----# # | # | # \/ List = [] NumberOfXItems = [] #-----# ~~Functions that I am using.~~ #-----# # | # | # \/ def HMNs(): global TheStr, user_inputHMNs, List_input, List user_inputHMNs = input("You picked string. This program cannot calculate the mean or median, but it can calculate the mode. :D How many strings are you using in your list? (Can not be a decimal number) \nEnter: ") user_inputHMNs time.sleep(1.5) TheStr = int(user_inputHMNs) for i in range(TheStr): List_input = input("Enter your strings. (One in each input field): ") List.append(List_input) print("Your list -> ", List) if List.count == int(user_inputHMNs): break print("\n*Mode*:", mode()) print("*Median*:", "\n") print("*Mean*:", mean()) def HMNn(): global TheNum, user_inputHMNn, List_input, List user_inputHMNn = input("You picked number. :D How many numbers are you using in your list? (Can not be a decimal number) \nEnter: ") user_inputHMNn time.sleep(1.5) TheNum = int(user_inputHMNn) for i in range(TheNum): List_input = input("Enter your numbers. (One in each input field): ") List_input = int(List_input) List.append(List_input) print("\nYour list -> ", List) if List.count == int(user_inputHMNn): break print("\n*Mode*:", mode()) print("*Median*:", "") print("*Mean*:", mean()) def NOS(): while True: # Loops forever (until the break) answer = input("Does your list contain a number or a string? \nEnter: ") answer = answer.lower() if answer in ("string", "str", "s"): HMNs() break elif answer in ("number", "num", "n", "int"): HMNn() break elif answer in ("quit", "q"): break # Exits the while loop else: print("You did not enter a valid field, :P Sorry. \nEnter: ") time.sleep(1.5) def mean(): thesum = sum(List) amount = len(List) themean = thesum / amount return themean def mode(): max_occurrences = 0 themode = None for i in List: thecount = List.count(i) if thecount > max_occurrences: max_occurrences = thecount themode = i return themode #-----# ~~The functions which need calling~~ #-----# # | # | # \/ NOS() From joel.goldstick at gmail.com Tue Sep 17 17:02:16 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 17 Sep 2013 17:02:16 -0400 Subject: How do I calculate a mean with python? In-Reply-To: <1540971c-7868-4f01-be3b-98fd5dffa985@googlegroups.com> References: <571f1251-17a5-44db-a859-17a6d8065151@googlegroups.com> <1540971c-7868-4f01-be3b-98fd5dffa985@googlegroups.com> Message-ID: On Tue, Sep 17, 2013 at 4:10 PM, William Bryant wrote: > Ok I think I've fixed it thanks I read everything. > > > '''**************************************************************************''' > #* Name: Mode-Median-Mean Calculator > *# > #* > *# > #* Purpose: To calculate the mode, median and mean of a list of > numbers *# > #* and the mode of a list of strings because that is what we > are *# > #* learning in math atm in school :P > *# > #* > *# > #* Author: William Bryant > *# > #* > *# > #* Created: 11/09/2013 > *# > #* > *# > #* Copyright: (c) William 2013 > *# > #* > *# > #* Licence: IDK :3 > *# > > '''**************************************************************************''' > > The above comments are a mess. In python, use docstrings -- put 3 quotes > in front of all the documentation, and 3 at the end like: > """ > Name: Mode-Median-Mean Calculator Purpose: To calculate the mode, median and mean of a list of numbers *# """ There is a utility called pydoc that will pull all docstrings from a module and produce nice documentation. So better to learn this style early #-----# ~~Import things I am using~~ #-----# # | # | # \/ import time import itertools I don't think you use itertools, so remove the reference #-----# ~~Variables that I am using, including the list.~~ #-----# # | # | # \/ List = [] NumberOfXItems = [] Using global variables is a very bad idea. Since you seem to be a novice, I'm wondering where you even learned about global variables. If your instructor taught you, then (s)he should look for a new line of work. Using globals promotes lazy thought, makes debugging impossible in any reasonably large piece of code. Google about that. Its important #-----# ~~Functions that I am using.~~ > #-----# > > # | > # | > # \/ > > Use better names. What does HMNs mean? This function asks the user to input a list of strings or numbers. It is almost identical to HMNn to that point that they should be combined most likely. > def HMNs(): > """ Here you should write about the function -- what it does, what is needs passed to it, and what it returns. """ > global TheStr, user_inputHMNs, List_input, List > user_inputHMNs = input("You picked string. This program cannot > calculate the mean or median, but it can calculate the mode. :D How many > strings are you using in your list? (Can not be a decimal number) \nEnter: > ") > user_inputHMNs > time.sleep(1.5) > TheStr = int(user_inputHMNs) > for i in range(TheStr): > List_input = input("Enter your strings. (One in each input field): > ") > List.append(List_input) > print("Your list -> ", List) > if List.count == int(user_inputHMNs): > break > print("\n*Mode*:", mode()) > print("*Median*:", "\n") > print("*Mean*:", mean()) > > def HMNn(): > global TheNum, user_inputHMNn, List_input, List > user_inputHMNn = input("You picked number. :D How many numbers are you > using in your list? (Can not be a decimal number) \nEnter: ") > user_inputHMNn > time.sleep(1.5) > TheNum = int(user_inputHMNn) > for i in range(TheNum): > List_input = input("Enter your numbers. (One in each input field): > ") > List_input = int(List_input) > List.append(List_input) > print("\nYour list -> ", List) > if List.count == int(user_inputHMNn): > break > print("\n*Mode*:", mode()) > print("*Median*:", "") > print("*Mean*:", mean()) > > def NOS(): > while True: # Loops forever (until the break) > answer = input("Does your list contain a number or a string? > \nEnter: ") > answer = answer.lower() > if answer in ("string", "str", "s"): > HMNs() > break > elif answer in ("number", "num", "n", "int"): > HMNn() > break > elif answer in ("quit", "q"): > break # Exits the while loop > else: > print("You did not enter a valid field, :P Sorry. \nEnter: ") > time.sleep(1.5) > > def mean(): > thesum = sum(List) > amount = len(List) > themean = thesum / amount > return themean > > def mode(): > max_occurrences = 0 > themode = None > for i in List: > thecount = List.count(i) > if thecount > max_occurrences: > max_occurrences = thecount > themode = i > return themode > > > > #-----# ~~The functions which need calling~~ > #-----# > > # | > # | > # \/ > > NOS() > So, I just added a few criticisms earlier above. To sumarize: avoid global variables, document functions with docstrings, use really clear names for variables including function names. If you have code in two functions that is almost identical, figure out how to make them one function good luck > -- > https://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Tue Sep 17 17:26:58 2013 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 17 Sep 2013 22:26:58 +0100 Subject: How do I calculate a mean with python? In-Reply-To: <1540971c-7868-4f01-be3b-98fd5dffa985@googlegroups.com> References: <571f1251-17a5-44db-a859-17a6d8065151@googlegroups.com> <1540971c-7868-4f01-be3b-98fd5dffa985@googlegroups.com> Message-ID: <5238C922.2000103@mrabarnett.plus.com> On 17/09/2013 21:10, William Bryant wrote: > Ok I think I've fixed it thanks I read everything. > [snip] > > def HMNs(): > global TheStr, user_inputHMNs, List_input, List > user_inputHMNs = input("You picked string. This program cannot calculate the mean or median, but it can calculate the mode. :D How many strings are you using in your list? (Can not be a decimal number) \nEnter: ") This line doesn't do anything: > user_inputHMNs > time.sleep(1.5) > TheStr = int(user_inputHMNs) > for i in range(TheStr): > List_input = input("Enter your strings. (One in each input field): ") > List.append(List_input) > print("Your list -> ", List) List.count is a method; it will never equal an integer: > if List.count == int(user_inputHMNs): > break > print("\n*Mode*:", mode()) > print("*Median*:", "\n") > print("*Mean*:", mean()) > > def HMNn(): > global TheNum, user_inputHMNn, List_input, List > user_inputHMNn = input("You picked number. :D How many numbers are you using in your list? (Can not be a decimal number) \nEnter: ") This line doesn't do anything: > user_inputHMNn > time.sleep(1.5) > TheNum = int(user_inputHMNn) > for i in range(TheNum): > List_input = input("Enter your numbers. (One in each input field): ") > List_input = int(List_input) > List.append(List_input) > print("\nYour list -> ", List) List.count is a method; it will never equal an integer: > if List.count == int(user_inputHMNn): > break > print("\n*Mode*:", mode()) > print("*Median*:", "") > print("*Mean*:", mean()) > [snip] From gogobebe2 at gmail.com Tue Sep 17 17:31:43 2013 From: gogobebe2 at gmail.com (William Bryant) Date: Tue, 17 Sep 2013 14:31:43 -0700 (PDT) Subject: How do I calculate a mean with python? In-Reply-To: References: <571f1251-17a5-44db-a859-17a6d8065151@googlegroups.com> <1540971c-7868-4f01-be3b-98fd5dffa985@googlegroups.com> Message-ID: <2d53c19d-d923-4533-890a-af4aaf8ca794@googlegroups.com> Thanks to all and @Joel Goldstick, I am learning python through youtube. They explained Global and Local variables to me. :) Thanks for that critisism, it really helps. I am 13 years old and I am looking forward to studing programming in University! :DDDDDD From joel.goldstick at gmail.com Tue Sep 17 19:49:03 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 17 Sep 2013 19:49:03 -0400 Subject: How do I calculate a mean with python? In-Reply-To: <2d53c19d-d923-4533-890a-af4aaf8ca794@googlegroups.com> References: <571f1251-17a5-44db-a859-17a6d8065151@googlegroups.com> <1540971c-7868-4f01-be3b-98fd5dffa985@googlegroups.com> <2d53c19d-d923-4533-890a-af4aaf8ca794@googlegroups.com> Message-ID: On Tue, Sep 17, 2013 at 5:31 PM, William Bryant wrote: > Thanks to all and @Joel Goldstick, I am learning python through youtube. > They explained Global and Local variables to me. :) Thanks for that > critisism, it really helps. I am 13 years old and I am looking forward to > studing programming in University! :DDDDDD > > -- > https://mail.python.org/mailman/listinfo/python-list > Well, learn away. Try the python.org tutorial too. The best way to learn ( I think!) is to find all the tutorials you can and work through those that suit you. Look at python.org for pages that list many help sites, including those for beginners. Also, there is a python-tutor mailing list/newsgroup that may be better for you at your stage of learning. Keep coming back when you get stuck -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From britten.bryan at gmail.com Tue Sep 17 21:53:10 2013 From: britten.bryan at gmail.com (Bryan Britten) Date: Tue, 17 Sep 2013 18:53:10 -0700 (PDT) Subject: How do I calculate a mean with python? In-Reply-To: <571f1251-17a5-44db-a859-17a6d8065151@googlegroups.com> References: <571f1251-17a5-44db-a859-17a6d8065151@googlegroups.com> Message-ID: <58bf80a9-86b3-4f00-b5ac-c460c88203f5@googlegroups.com> William - I'm also self-teaching myself Python and get stuck quite often, so I understand both the thrill of programming and the frustration. Given your young age and presumably very little exposure to other programming languages, I would highly recommend you check out http://www.Codecademy.com and work through their Python tutorials. It will teach you about the different object types (lists, dicts, tuples, etc) and about things like functions, methods and classes. I think you'll have a MUCH better understanding of Python that will allow you to choose which YouTube videos to watch much more wisely. Good luck with your endeavors! From mohsen at pahlevanzadeh.org Tue Sep 17 00:12:35 2013 From: mohsen at pahlevanzadeh.org (Mohsen Pahlevanzadeh) Date: Tue, 17 Sep 2013 08:42:35 +0430 Subject: Qt connect and first connect or unicode Message-ID: <1379391155.24093.23.camel@debian> Dear all, Unfortunately, i confused and need help... the following code is: ################################################### ##CheckBox: QtCore.QObject.connect(self.checkBox, QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda: self.materialsInstance.setFilterDict("C",self,"name",self.lineEdit.text())) QtCore.QObject.connect(self.checkBox_2, QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda: self.materialsInstance.setFilterDict("C",self,"bought_price",persianToInteger(unicode(self.lineEdit_2.text())))) QtCore.QObject.connect(self.checkBox_4, QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda: self.materialsInstance.setFilterDict("C",self,"stock",persianToInteger(unicode(self.lineEdit_3.text())))) ##LineEdit QtCore.QObject.connect(self.lineEdit, QtCore.SIGNAL(_fromUtf8("editingFinished()")), lambda: self.materialsInstance.setFilterDict("L",self,"name",self.lineEdit.text())) QtCore.QObject.connect(self.lineEdit_2, QtCore.SIGNAL(_fromUtf8("editingFinished()")), lambda: self.materialsInstance.setFilterDict("L",self,"bought_price",persianToInteger(unicode(self.lineEdit_2.text())))) QtCore.QObject.connect(self.lineEdit_3, QtCore.SIGNAL(_fromUtf8("editingFinished()")), lambda: self.materialsInstance.setFilterDict("L",self,"stock",persianToInteger(unicode(self.lineEdit_3.text())))) QtCore.QObject.connect(self.lineEdit, QtCore.SIGNAL(_fromUtf8("editingFinished()")), lambda: self.materialsInstance.responseToRequestForData(self)) QtCore.QObject.connect(self.lineEdit_2, QtCore.SIGNAL(_fromUtf8("editingFinished()")), lambda: self.materialsInstance.responseToRequestForData(self)) QtCore.QObject.connect(self.lineEdit_3, QtCore.SIGNAL(_fromUtf8("editingFinished()")), lambda: self.materialsInstance.responseToRequestForData(self)) QtCore.QObject.connect(self.lineEdit, QtCore.SIGNAL(_fromUtf8("returnPressed()")), lambda: self.materialsInstance.responseToRequestForData(self)) QtCore.QObject.connect(self.lineEdit_2, QtCore.SIGNAL(_fromUtf8("returnPressed()")), lambda: self.materialsInstance.responseToRequestForData(self)) QtCore.QObject.connect(self.lineEdit_3, QtCore.SIGNAL(_fromUtf8("returnPressed()")), lambda: self.materialsInstance.responseToRequestForData(self)) ##PushButton: QtCore.QObject.connect(self.pushButtonSearch, QtCore.SIGNAL(_fromUtf8("clicked()")), lambda: self.materialsInstance.responseToRequestForData(self)) def setFilterDict(self,widget,obj,field,lineEditContent): if field not in obj.materialsInstance.filterNameDict.keys(): obj.materialsInstance.filterNameDict.update({field:lineEditContent}) #################################################### Description: I have 3 widget: 1. CheckBox: a. name b. bought_price c. stock 2. LineEdit : a. name b. bought_price c. stock 3. One PushButton i have three slot: 1. responseToRequestForData() 2.setFilterDict() 3.unSetFilterDict() responseToRequestForData(): start to search in DB setFilterDict(): fill a dict from my LineEdit Problem: My name is filled in dict but its value doesn't fill up. b and c don't have any problem. Yours, Mohsen From mohsen at pahlevanzadeh.org Tue Sep 17 00:20:00 2013 From: mohsen at pahlevanzadeh.org (Mohsen Pahlevanzadeh) Date: Tue, 17 Sep 2013 08:50:00 +0430 Subject: Qt connect and first connect or unicode In-Reply-To: <1379391155.24093.23.camel@debian> References: <1379391155.24093.23.camel@debian> Message-ID: <1379391600.24093.24.camel@debian> On Tue, 2013-09-17 at 08:42 +0430, Mohsen Pahlevanzadeh wrote: > Dear all, > > Unfortunately, i confused and need help... the following code is: > ################################################### > ##CheckBox: > QtCore.QObject.connect(self.checkBox, > QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda: > self.materialsInstance.setFilterDict("C",self,"name",self.lineEdit.text())) > > QtCore.QObject.connect(self.checkBox_2, > QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda: > self.materialsInstance.setFilterDict("C",self,"bought_price",persianToInteger(unicode(self.lineEdit_2.text())))) > > QtCore.QObject.connect(self.checkBox_4, > QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda: > self.materialsInstance.setFilterDict("C",self,"stock",persianToInteger(unicode(self.lineEdit_3.text())))) > > ##LineEdit > QtCore.QObject.connect(self.lineEdit, > QtCore.SIGNAL(_fromUtf8("editingFinished()")), lambda: > self.materialsInstance.setFilterDict("L",self,"name",self.lineEdit.text())) > > QtCore.QObject.connect(self.lineEdit_2, > QtCore.SIGNAL(_fromUtf8("editingFinished()")), lambda: > self.materialsInstance.setFilterDict("L",self,"bought_price",persianToInteger(unicode(self.lineEdit_2.text())))) > > QtCore.QObject.connect(self.lineEdit_3, > QtCore.SIGNAL(_fromUtf8("editingFinished()")), lambda: > self.materialsInstance.setFilterDict("L",self,"stock",persianToInteger(unicode(self.lineEdit_3.text())))) > > QtCore.QObject.connect(self.lineEdit, > QtCore.SIGNAL(_fromUtf8("editingFinished()")), lambda: > self.materialsInstance.responseToRequestForData(self)) > > QtCore.QObject.connect(self.lineEdit_2, > QtCore.SIGNAL(_fromUtf8("editingFinished()")), lambda: > self.materialsInstance.responseToRequestForData(self)) > > QtCore.QObject.connect(self.lineEdit_3, > QtCore.SIGNAL(_fromUtf8("editingFinished()")), lambda: > self.materialsInstance.responseToRequestForData(self)) > > QtCore.QObject.connect(self.lineEdit, > QtCore.SIGNAL(_fromUtf8("returnPressed()")), lambda: > self.materialsInstance.responseToRequestForData(self)) > > QtCore.QObject.connect(self.lineEdit_2, > QtCore.SIGNAL(_fromUtf8("returnPressed()")), lambda: > self.materialsInstance.responseToRequestForData(self)) > > QtCore.QObject.connect(self.lineEdit_3, > QtCore.SIGNAL(_fromUtf8("returnPressed()")), lambda: > self.materialsInstance.responseToRequestForData(self)) > > ##PushButton: > QtCore.QObject.connect(self.pushButtonSearch, > QtCore.SIGNAL(_fromUtf8("clicked()")), lambda: > self.materialsInstance.responseToRequestForData(self)) > > > > def setFilterDict(self,widget,obj,field,lineEditContent): > if field not in obj.materialsInstance.filterNameDict.keys(): > > obj.materialsInstance.filterNameDict.update({field:lineEditContent}) > > > #################################################### > Description: > I have 3 widget: > 1. CheckBox: a. name b. bought_price c. stock > 2. LineEdit : a. name b. bought_price c. stock > 3. One PushButton > > i have three slot: 1. responseToRequestForData() 2.setFilterDict() > 3.unSetFilterDict() > responseToRequestForData(): start to search in DB > setFilterDict(): fill a dict from my LineEdit > > Problem: > My name is filled in dict but its value doesn't fill up. b and c don't > have any problem. > > Yours, > Mohsen > I see same output in console: {'stock': 2, 'name': PyQt4.QtCore.QString(u''), 'bought_price': 23} From oscar.j.benjamin at gmail.com Tue Sep 17 04:05:57 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 17 Sep 2013 09:05:57 +0100 Subject: Qt connect and first connect or unicode In-Reply-To: <1379391155.24093.23.camel@debian> References: <1379391155.24093.23.camel@debian> Message-ID: On 17 September 2013 05:12, Mohsen Pahlevanzadeh wrote: > Dear all, > > Unfortunately, i confused and need help... the following code is: > ################################################### > ##CheckBox: > QtCore.QObject.connect(self.checkBox, > QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda: > self.materialsInstance.setFilterDict("C",self,"name",self.lineEdit.text())) > > QtCore.QObject.connect(self.checkBox_2, > QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda: > self.materialsInstance.setFilterDict("C",self,"bought_price",persianToInteger(unicode(self.lineEdit_2.text())))) > > QtCore.QObject.connect(self.checkBox_4, > QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda: > self.materialsInstance.setFilterDict("C",self,"stock",persianToInteger(unicode(self.lineEdit_3.text())))) > > ##LineEdit > QtCore.QObject.connect(self.lineEdit, > QtCore.SIGNAL(_fromUtf8("editingFinished()")), lambda: > self.materialsInstance.setFilterDict("L",self,"name",self.lineEdit.text())) > > QtCore.QObject.connect(self.lineEdit_2, > QtCore.SIGNAL(_fromUtf8("editingFinished()")), lambda: > self.materialsInstance.setFilterDict("L",self,"bought_price",persianToInteger(unicode(self.lineEdit_2.text())))) I don't really know what the problem you're having is but this code is very difficult to read. What's the point of the _fromUTF8 function? The strings you pass it are all ASCII, so if you're trying to create unicode strings you could just use the u prefix e.g. u"toggled(bool)". Also you can avoid referring to the same deeply nested attributes by importing them or assigning them to something first e.g.: from QtCore import SIGNAL from QtCore.QObject import connect # Not sure if QObject is a module... ## Checkbox: setfilter = self.materialsInstance.setFilterDict connect(self.checkBox, SIGNAL(u"toggled(bool)"), lambda: setfilter("C", self, "name", self.lineEdit.text())) Oscar From steve at pearwood.info Tue Sep 17 05:05:31 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 17 Sep 2013 09:05:31 GMT Subject: Qt connect and first connect or unicode References: Message-ID: <52381b5b$0$29869$c3e8da3$5496439d@news.astraweb.com> On Tue, 17 Sep 2013 08:42:35 +0430, Mohsen Pahlevanzadeh wrote: > Dear all, > > Unfortunately, i confused and need help... the following code is: > ################################################### > ##CheckBox: > QtCore.QObject.connect(self.checkBox, > QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda: > self.materialsInstance.setFilterDict("C", self, "name", > self.lineEdit.text())) I don't use Qt, but I'll try to help. First question, what does _fromUtf8 do? It appears to be a private function. Is that your function? If you want to create a string from UTF-8 bytes, use: some_bytes.decode('utf-8') I don't think there is a need for a dedicated _fromUtf8 function. If you are using Python 3, then "toggled(bool)" is already a Unicode string, and there is no need to convert from UTF-8. If you are using Python 2, then "toggled(bool)" is a byte string, and you can turn it into a Unicode string by just using the u prefix: u"toggled(bool)" Again, no need to convert from UTF-8. The only time you need to convert from UTF-8 is when you are reading data from a file, or other external source, that is encoded in UTF-8. Other than that, your first line of code seems like a straight-forward call to set a callback function. When the button is pressed, the instance's attribute materialsInstance calls the method setFilterDict. > QtCore.QObject.connect(self.checkBox_2, > QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda: > self.materialsInstance.setFilterDict("C", self, "bought_price", > persianToInteger(unicode(self.lineEdit_2.text())))) Again, the same method is called, only this time with different arguments. Hmmm, this strikes me as poor design. I think that a better design would be for the object to have a few methods: def toggle_checkbox(self, flag): # checkbox logic goes here, e.g. if flag: ... else: ... And then your callback is trivially lambda: self.toggle_checkbox(get_state) I'm not sure how to get the checkbox state from Qt, you will need to replace the "get_state" with the correct code. That, in my opinion, is easier to understand. > QtCore.QObject.connect(self.checkBox_4, > QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda: > self.materialsInstance.setFilterDict("C",self,"stock", > persianToInteger(unicode(self.lineEdit_3.text())))) And more callbacks. Most of your code is probably irrelevant to the problem you are having. You will help us to help you if you can read this website: http://sscce.org/ and simplify your code. [...many more callbacks...] > #################################################### > Description: > I have 3 widget: > 1. CheckBox: a. name b. bought_price c. stock 2. LineEdit : a. name b. > bought_price c. stock 3. One PushButton > > i have three slot: 1. responseToRequestForData() 2.setFilterDict() > 3.unSetFilterDict() > responseToRequestForData(): start to search in DB setFilterDict(): fill > a dict from my LineEdit > > Problem: > My name is filled in dict but its value doesn't fill up. b and c don't > have any problem. I'm afraid I don't understand this. Even your followup post doesn't really help: > I see same output in console: > {'stock': 2, 'name': PyQt4.QtCore.QString(u''), 'bought_price': 23} What result where you expecting? If I remember correctly, Qt strings are mutable unicode strings, so 'name' is associated with an empty Qt string. If they are mutable, that means that once the dict is set: {'name': QString(u'contents of text field'), ...} if the text field changes, so will the string. Is that what is happening? (Or perhaps I have mis-remembered about Qt strings.) You have two callbacks that appear to set the "name" key in the dict. Perhaps one of them is setting it to an empty value. -- Steven From vincent.vandevyvre at swing.be Tue Sep 17 06:32:44 2013 From: vincent.vandevyvre at swing.be (Vincent Vande Vyvre) Date: Tue, 17 Sep 2013 12:32:44 +0200 Subject: Qt connect and first connect or unicode In-Reply-To: <52381b5b$0$29869$c3e8da3$5496439d@news.astraweb.com> References: <52381b5b$0$29869$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52382FCC.50100@swing.be> Le 17/09/2013 11:05, Steven D'Aprano a ?crit : > On Tue, 17 Sep 2013 08:42:35 +0430, Mohsen Pahlevanzadeh wrote: > >> Dear all, >> >> Unfortunately, i confused and need help... the following code is: >> ################################################### >> ##CheckBox: >> QtCore.QObject.connect(self.checkBox, >> QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda: >> self.materialsInstance.setFilterDict("C", self, "name", >> self.lineEdit.text())) > > I don't use Qt, but I'll try to help. > > First question, what does _fromUtf8 do? It appears to be a private > function. Is that your function? If you want to create a string from UTF-8 > bytes, use: > > some_bytes.decode('utf-8') > > I don't think there is a need for a dedicated _fromUtf8 function. > > If you are using Python 3, then "toggled(bool)" is already a Unicode > string, and there is no need to convert from UTF-8. > > If you are using Python 2, then "toggled(bool)" is a byte string, and you > can turn it into a Unicode string by just using the u prefix: > > u"toggled(bool)" > > Again, no need to convert from UTF-8. > > The only time you need to convert from UTF-8 is when you are reading data > from a file, or other external source, that is encoded in UTF-8. > > Other than that, your first line of code seems like a straight-forward > call to set a callback function. When the button is pressed, the > instance's attribute materialsInstance calls the method setFilterDict. > > >> QtCore.QObject.connect(self.checkBox_2, >> QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda: >> self.materialsInstance.setFilterDict("C", self, "bought_price", >> persianToInteger(unicode(self.lineEdit_2.text())))) > Again, the same method is called, only this time with different > arguments. Hmmm, this strikes me as poor design. I think that a better > design would be for the object to have a few methods: > > def toggle_checkbox(self, flag): > # checkbox logic goes here, e.g. > if flag: > ... > else: > ... > > And then your callback is trivially > > lambda: self.toggle_checkbox(get_state) > > > I'm not sure how to get the checkbox state from Qt, you will need to > replace the "get_state" with the correct code. > > That, in my opinion, is easier to understand. > > >> QtCore.QObject.connect(self.checkBox_4, >> QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda: >> self.materialsInstance.setFilterDict("C",self,"stock", >> persianToInteger(unicode(self.lineEdit_3.text())))) > And more callbacks. Most of your code is probably irrelevant to the > problem you are having. You will help us to help you if you can read this > website: > > http://sscce.org/ > > > and simplify your code. > > > [...many more callbacks...] > > >> #################################################### >> Description: >> I have 3 widget: >> 1. CheckBox: a. name b. bought_price c. stock 2. LineEdit : a. name b. >> bought_price c. stock 3. One PushButton >> >> i have three slot: 1. responseToRequestForData() 2.setFilterDict() >> 3.unSetFilterDict() >> responseToRequestForData(): start to search in DB setFilterDict(): fill >> a dict from my LineEdit >> >> Problem: >> My name is filled in dict but its value doesn't fill up. b and c don't >> have any problem. > I'm afraid I don't understand this. Even your followup post doesn't > really help: > >> I see same output in console: >> {'stock': 2, 'name': PyQt4.QtCore.QString(u''), 'bought_price': 23} > > What result where you expecting? > > If I remember correctly, Qt strings are mutable unicode strings, so > 'name' is associated with an empty Qt string. If they are mutable, that > means that once the dict is set: > > {'name': QString(u'contents of text field'), ...} > > > if the text field changes, so will the string. Is that what is happening? > > (Or perhaps I have mis-remembered about Qt strings.) > > You have two callbacks that appear to set the "name" key in the dict. > Perhaps one of them is setting it to an empty value. > > > > _fromUtf8 is needed for the API compatibility, at the beginning of the code of Moshen it is these lines: try: _fromUtf8 = QtCore.QString.fromUtf8 except AttributeError: _fromUtf8 = lambda s: s Moshen, I thing if you pass the instance of your GUI at the class materialsInstance you'll can simplify your connections self.lineEdit.returnPressed.connect(self.materialsInstance.responseToRequestForData) self.lineEdit.editingFinnished.connect(self.materialsInstance.responseToRequestForData) For the checkBoxes, I'm not sure you need all these arguments but I don't know enough your code. -- Vincent V.V. Oqapy . Qarte . PaQager From mohsen at pahlevanzadeh.org Tue Sep 17 23:34:14 2013 From: mohsen at pahlevanzadeh.org (Mohsen Pahlevanzadeh) Date: Wed, 18 Sep 2013 08:04:14 +0430 Subject: Qt connect and first connect or unicode In-Reply-To: <52382FCC.50100@swing.be> References: <52381b5b$0$29869$c3e8da3$5496439d@news.astraweb.com> <52382FCC.50100@swing.be> Message-ID: <1379475254.6014.4.camel@debian> On Tue, 2013-09-17 at 12:32 +0200, Vincent Vande Vyvre wrote: > Le 17/09/2013 11:05, Steven D'Aprano a ?crit : > > On Tue, 17 Sep 2013 08:42:35 +0430, Mohsen Pahlevanzadeh wrote: > > > >> Dear all, > >> > >> Unfortunately, i confused and need help... the following code is: > >> ################################################### > >> ##CheckBox: > >> QtCore.QObject.connect(self.checkBox, > >> QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda: > >> self.materialsInstance.setFilterDict("C", self, "name", > >> self.lineEdit.text())) > > > > I don't use Qt, but I'll try to help. > > > > First question, what does _fromUtf8 do? It appears to be a private > > function. Is that your function? If you want to create a string from UTF-8 > > bytes, use: > > > > some_bytes.decode('utf-8') > > > > I don't think there is a need for a dedicated _fromUtf8 function. > > > > If you are using Python 3, then "toggled(bool)" is already a Unicode > > string, and there is no need to convert from UTF-8. > > > > If you are using Python 2, then "toggled(bool)" is a byte string, and you > > can turn it into a Unicode string by just using the u prefix: > > > > u"toggled(bool)" > > > > Again, no need to convert from UTF-8. > > > > The only time you need to convert from UTF-8 is when you are reading data > > from a file, or other external source, that is encoded in UTF-8. > > > > Other than that, your first line of code seems like a straight-forward > > call to set a callback function. When the button is pressed, the > > instance's attribute materialsInstance calls the method setFilterDict. > > > > > >> QtCore.QObject.connect(self.checkBox_2, > >> QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda: > >> self.materialsInstance.setFilterDict("C", self, "bought_price", > >> persianToInteger(unicode(self.lineEdit_2.text())))) > > Again, the same method is called, only this time with different > > arguments. Hmmm, this strikes me as poor design. I think that a better > > design would be for the object to have a few methods: > > > > def toggle_checkbox(self, flag): > > # checkbox logic goes here, e.g. > > if flag: > > ... > > else: > > ... > > > > And then your callback is trivially > > > > lambda: self.toggle_checkbox(get_state) > > > > > > I'm not sure how to get the checkbox state from Qt, you will need to > > replace the "get_state" with the correct code. > > > > That, in my opinion, is easier to understand. > > > > > >> QtCore.QObject.connect(self.checkBox_4, > >> QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda: > >> self.materialsInstance.setFilterDict("C",self,"stock", > >> persianToInteger(unicode(self.lineEdit_3.text())))) > > And more callbacks. Most of your code is probably irrelevant to the > > problem you are having. You will help us to help you if you can read this > > website: > > > > http://sscce.org/ > > > > > > and simplify your code. > > > > > > [...many more callbacks...] > > > > > >> #################################################### > >> Description: > >> I have 3 widget: > >> 1. CheckBox: a. name b. bought_price c. stock 2. LineEdit : a. name b. > >> bought_price c. stock 3. One PushButton > >> > >> i have three slot: 1. responseToRequestForData() 2.setFilterDict() > >> 3.unSetFilterDict() > >> responseToRequestForData(): start to search in DB setFilterDict(): fill > >> a dict from my LineEdit > >> > >> Problem: > >> My name is filled in dict but its value doesn't fill up. b and c don't > >> have any problem. > > I'm afraid I don't understand this. Even your followup post doesn't > > really help: > > > >> I see same output in console: > >> {'stock': 2, 'name': PyQt4.QtCore.QString(u''), 'bought_price': 23} > > > > What result where you expecting? > > > > If I remember correctly, Qt strings are mutable unicode strings, so > > 'name' is associated with an empty Qt string. If they are mutable, that > > means that once the dict is set: > > > > {'name': QString(u'contents of text field'), ...} > > > > > > if the text field changes, so will the string. Is that what is happening? > > > > (Or perhaps I have mis-remembered about Qt strings.) > > > > You have two callbacks that appear to set the "name" key in the dict. > > Perhaps one of them is setting it to an empty value. > > > > > > > > > > _fromUtf8 is needed for the API compatibility, at the beginning of the code of Moshen it is these lines: > > try: > _fromUtf8 = QtCore.QString.fromUtf8 > except AttributeError: > _fromUtf8 = lambda s: s > > > Moshen, I thing if you pass the instance of your GUI at the class materialsInstance you'll can simplify your connections > > self.lineEdit.returnPressed.connect(self.materialsInstance.responseToRequestForData) > self.lineEdit.editingFinnished.connect(self.materialsInstance.responseToRequestForData) > > For the checkBoxes, I'm not sure you need all these arguments but I don't know enough your code. > > > -- > Vincent V.V. > Oqapy . Qarte > . PaQager i solved, I didn't think Qt hard up.i change priority of connect in my script and every thing was OK. ohhhh day of hard code....Thanks GOD. From venkat.boffin at gmail.com Tue Sep 17 03:13:20 2013 From: venkat.boffin at gmail.com (Venkat Addala) Date: Tue, 17 Sep 2013 12:43:20 +0530 Subject: MySQLdb Help Message-ID: Hi all, I'm new to python, i am connecting mysql database with python. now i want to do sanitation on the database, like to remove "\n", extra spaces blah blah.. and update it back to mysql database. i was trying somthing, here is my code, can you please provide me solution for this.. #!/usr/bin/python import MySQLdb as mdb con = mdb.connect('localhost', 'root', 'pass at 123', 'workbench'); with con: cur = con.cursor() cur.execute("SELECT descrip FROM table LIMIT 1") rows = cur.fetchall() for row in rows: row_new = row[0].split("\n", " ") row = "".join(row_new) print row exit(0) -- Regards Boffin -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Tue Sep 17 03:35:30 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 17 Sep 2013 17:35:30 +1000 Subject: MySQLdb Help References: Message-ID: <7w1u4nzyrh.fsf@benfinney.id.au> Venkat Addala writes: > I'm new to python Welcome! Congratulations on choosing Python for programming. > i am connecting mysql database with python. now i want to do > sanitation on the database, like to remove "\n", extra spaces blah > blah.. and update it back to mysql database. > i was trying somthing, here is my code, can you please provide me > solution for this.. Thank you for providing a small, complete example. You should also describe what behaviour you expect, and what behaviour you're getting instead. What happens, and how are you expecting it to be different? > #!/usr/bin/python > import MySQLdb as mdb > > con = mdb.connect('localhost', 'root', 'pass at 123', 'workbench'); There's no need to end Python statements with a semicolon; it's only confusing to do it. > rows = cur.fetchall() > for row in rows: You never use ?rows? for anything else, so you may as well forget it and just iterate directly over the return value:: for row in cur.fetchall(): > row_new = row[0].split("\n", " ") Read the documentation for ?str.split? to see what is wrong with the above call. You might also be interested in the ?python-tutor? forum, specially designed for beginners with basic questions about Python . Good hunting to you! -- \ ?Sunday: A day given over by Americans to wishing that they | `\ themselves were dead and in Heaven, and that their neighbors | _o__) were dead and in Hell.? ?Henry L. Mencken | Ben Finney From venkat.boffin at gmail.com Tue Sep 17 04:27:40 2013 From: venkat.boffin at gmail.com (Venkat Addala) Date: Tue, 17 Sep 2013 13:57:40 +0530 Subject: MySQLdb Help In-Reply-To: <7w1u4nzyrh.fsf@benfinney.id.au> References: <7w1u4nzyrh.fsf@benfinney.id.au> Message-ID: hey Ben, Thanks for your solution, i am done with this before, now i'm having problem after deleting \n and extra spaces, i want to update it back it again to mysql db. For this i tried using regular expression check this code; # -*- coding: utf-8 -*- import re import MySQLdb pattern = re.compile('@(.*)@.*$') conn = MySQLdb.connect( host='localhost', user='root', passwd='pass123', db='workbench', charset='utf8') cursor = conn.cursor() cursor.execute(""" SELECT * FROM gene where gene_id=13 AND `descrip` regexp "^@.*@.*$" LIMIT 1""") rows = cursor.fetchall() for row in rows: rows_new = pattern.match(row[1]) if rows_new.group(1) is not None: cursor.execute(""" update gene set descrip = %s where descrip = %s""", (rows_new.group(1), row[0])) #cursor.execute(""" #update gene set descrip = %s where descrip = %s""", (rows_new.group(1), row[0])) conn.close() -- Regards Boffin On Tue, Sep 17, 2013 at 1:05 PM, Ben Finney wrote: > Venkat Addala writes: > > > I'm new to python > > Welcome! Congratulations on choosing Python for programming. > > > i am connecting mysql database with python. now i want to do > > sanitation on the database, like to remove "\n", extra spaces blah > > blah.. and update it back to mysql database. > > > > i was trying somthing, here is my code, can you please provide me > > solution for this.. > > Thank you for providing a small, complete example. > > You should also describe what behaviour you expect, and what behaviour > you're getting instead. What happens, and how are you expecting it to be > different? > > > #!/usr/bin/python > > import MySQLdb as mdb > > > > con = mdb.connect('localhost', 'root', 'pass at 123', 'workbench'); > > There's no need to end Python statements with a semicolon; it's only > confusing to do it. > > > rows = cur.fetchall() > > for row in rows: > > You never use ?rows? for anything else, so you may as well forget it and > just iterate directly over the return value:: > > for row in cur.fetchall(): > > > row_new = row[0].split("\n", " ") > > Read the documentation for ?str.split? to see what is wrong with the > above call. > > > You might also be interested in the ?python-tutor? forum, specially > designed for beginners with basic questions about Python > > . > > Good hunting to you! > > -- > \ ?Sunday: A day given over by Americans to wishing that they | > `\ themselves were dead and in Heaven, and that their neighbors | > _o__) were dead and in Hell.? ?Henry L. Mencken | > Ben Finney > > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From airween at gmail.com Tue Sep 17 04:46:57 2013 From: airween at gmail.com (Ervin =?utf-8?Q?Heged=C3=BCs?=) Date: Tue, 17 Sep 2013 10:46:57 +0200 Subject: MySQLdb Help In-Reply-To: <7w1u4nzyrh.fsf@benfinney.id.au> References: <7w1u4nzyrh.fsf@benfinney.id.au> Message-ID: <20130917084657.GB4565@arxnet.hu> Hello, On Tue, Sep 17, 2013 at 05:35:30PM +1000, Ben Finney wrote: > Venkat Addala writes: > > > rows = cur.fetchall() > > for row in rows: > > You never use ?rows? for anything else, so you may as well forget it and > just iterate directly over the return value:: > > for row in cur.fetchall(): and what if in body of iteration there is another fetchall()? :) I mean: for row in cur.fetchall(): do_domething() cur.execute("SELECT * FROM another_table") Cheers: Ervin From ben+python at benfinney.id.au Tue Sep 17 05:22:50 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 17 Sep 2013 19:22:50 +1000 Subject: MySQLdb Help References: <7w1u4nzyrh.fsf@benfinney.id.au> <20130917084657.GB4565@arxnet.hu> Message-ID: <7wvc1zyf85.fsf@benfinney.id.au> Ervin Heged?s writes: > Hello, > > On Tue, Sep 17, 2013 at 05:35:30PM +1000, Ben Finney wrote: > > for row in cur.fetchall(): > > and what if in body of iteration there is another fetchall()? :) Yes, what if? Each call to ?fetchall? returns a sequence of rows. I don't see your point. -- \ ?The most common way people give up their power is by thinking | `\ they don't have any.? ?Alice Walker | _o__) | Ben Finney From airween at gmail.com Tue Sep 17 06:05:41 2013 From: airween at gmail.com (Ervin =?utf-8?Q?Heged=C3=BCs?=) Date: Tue, 17 Sep 2013 12:05:41 +0200 Subject: MySQLdb Help In-Reply-To: <7wvc1zyf85.fsf@benfinney.id.au> References: <7w1u4nzyrh.fsf@benfinney.id.au> <20130917084657.GB4565@arxnet.hu> <7wvc1zyf85.fsf@benfinney.id.au> Message-ID: <20130917100540.GA5230@arxnet.hu> Hello, On Tue, Sep 17, 2013 at 07:22:50PM +1000, Ben Finney wrote: > Ervin Heged?s writes: > > > Hello, > > > > On Tue, Sep 17, 2013 at 05:35:30PM +1000, Ben Finney wrote: > > > for row in cur.fetchall(): > > > > and what if in body of iteration there is another fetchall()? :) > > Yes, what if? Each call to ?fetchall? returns a sequence of rows. I > don't see your point. yep', sorry, I'm confused. I just remember - maybe badly - once I used this form, and the 'row' continues the new sequence... But now I tried, and I see this presumtion is wrong. Sorry for disturbing, and thanks :) a. From airween at gmail.com Tue Sep 17 04:41:26 2013 From: airween at gmail.com (Ervin =?utf-8?Q?Heged=C3=BCs?=) Date: Tue, 17 Sep 2013 10:41:26 +0200 Subject: MySQLdb Help In-Reply-To: References: Message-ID: <20130917084125.GA4565@arxnet.hu> Hello, On Tue, Sep 17, 2013 at 12:43:20PM +0530, Venkat Addala wrote: > Hi all, > > > I'm new to python, i am connecting mysql database with python. now i want > to do sanitation on the database, like to remove "\n", extra spaces blah > blah.. and update it back to mysql database. i was trying somthing, here is > my code, can you please provide me solution for this.. > > #!/usr/bin/python > import MySQLdb as mdb > > con = mdb.connect('localhost', 'root', 'pass at 123', 'workbench'); a tip: you can pass the arguments to function as dictionary, so if you store the connection arguments anywhere, you use this form: conndsc = {'host': 'localhost', 'user': 'root', 'port': 3306, ....} con = mdb.connect(**conndsc) My personal opinion, but it's easyer to use the cursor if you have dictionary-like cursor: > with con: > cur = con.cursor() cur = con.cursor(mdb.cursors.DictCursor) In this case you can reference the name of the table column, instead of index of result, in your example: row['descrip'] > cur.execute("SELECT descrip FROM table LIMIT 1") > rows = cur.fetchall() if you want to fetch only one row, you can use cur.fetchrow(), which gives only one row, and you don't need to iterate that > for row in rows: > row_new = row[0].split("\n", " ") > row = "".join(row_new) as Benn Finney wrote, the use of split() above is wrong. I think you need some kinf of this: " ".join([f.strip() for f in row[0].replace("\n", " ").split()]) but it depends what you want. Cheers: Ervin From rapzak at gmail.com Tue Sep 17 05:44:14 2013 From: rapzak at gmail.com (Kasper Jepsen) Date: Tue, 17 Sep 2013 02:44:14 -0700 (PDT) Subject: HID Feature Raport, Linux Message-ID: Hi, I have been using pywinusb.hid for a hid unit, using only feature reports. I like to get this code to run on raspbian PI, but i can not fint a good library to support HID/feature reports? I am a USB newbie Can anyone help me, or point me in a direction to send/recieve feature reports without HID support? Br. Kasper From as at sci.fi Wed Sep 18 06:10:29 2013 From: as at sci.fi (Anssi Saari) Date: Wed, 18 Sep 2013 13:10:29 +0300 Subject: HID Feature Raport, Linux References: Message-ID: Kasper Jepsen writes: > Hi, > > I have been using pywinusb.hid for a hid unit, using only feature reports. > I like to get this code to run on raspbian PI, but i can not fint a good library to support HID/feature reports? > I am a USB newbie > Can anyone help me, or point me in a direction to send/recieve feature reports without HID support? I believe pyusb with libusb or libusbx would work. There's a summary of the alternatives at http://mcuee.blogspot.fi/2011/04/python-and-usb-hid-device.html if that helps. From rapzak at gmail.com Wed Sep 18 06:33:19 2013 From: rapzak at gmail.com (Kasper Jepsen) Date: Wed, 18 Sep 2013 03:33:19 -0700 (PDT) Subject: HID Feature Raport, Linux In-Reply-To: References: Message-ID: <691125b2-ca85-407d-8ff0-bf16d6bcdfe3@googlegroups.com> Den onsdag den 18. september 2013 12.10.29 UTC+2 skrev Anssi Saari: > > > > > Hi, > > > > > > I have been using pywinusb.hid for a hid unit, using only feature reports. > > > I like to get this code to run on raspbian PI, but i can not fint a good library to support HID/feature reports? > > > I am a USB newbie > > > Can anyone help me, or point me in a direction to send/recieve feature reports without HID support? > > > > I believe pyusb with libusb or libusbx would work. There's a summary of > > the alternatives at > > http://mcuee.blogspot.fi/2011/04/python-and-usb-hid-device.html if that > > helps. Hi, Thx, i have been looking at this... but could not fint the way to send feature reports, does anyone have an example? Kasper From asmbansal2 at gmail.com Tue Sep 17 07:22:45 2013 From: asmbansal2 at gmail.com (Aseem Bansal) Date: Tue, 17 Sep 2013 04:22:45 -0700 (PDT) Subject: Is this a bug in Python 3.3? Message-ID: <7787e84f-f863-437d-aeac-2be142ab5872@googlegroups.com> While using IDLE I used the license() function to see the license information. In it there was a list of all the versions and from which version they are derived is written. The list goes upto 3.3.1 but doesn't include 3.3.2. Is that a minor bug or is the current version not mentioned in that list? From tjreedy at udel.edu Tue Sep 17 11:28:10 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 17 Sep 2013 11:28:10 -0400 Subject: Is this a bug in Python 3.3? In-Reply-To: <7787e84f-f863-437d-aeac-2be142ab5872@googlegroups.com> References: <7787e84f-f863-437d-aeac-2be142ab5872@googlegroups.com> Message-ID: On 9/17/2013 7:22 AM, Aseem Bansal wrote: > While using IDLE I used the license() function to see the license information. In it there was a list of all the versions and from which version they are derived is written. The 2.7 list ends with 2.7. The 3.x does not even include 2.7. > The list goes upto 3.3.1 but doesn't include 3.3.2. Is that a minor bug or is the current version not mentioned in that list? I will ask on the python-dev list. -- Terry Jan Reedy From talr at talr.co.il Tue Sep 17 08:03:18 2013 From: talr at talr.co.il (Tal Raveh) Date: Tue, 17 Sep 2013 15:03:18 +0300 Subject: error python-gammu Message-ID: Hello, I just install gammu and try to : import gammu and i get error: Traceback (most recent call last): File "./pygammu.py", line 4, in import gammu File "/usr/lib64/python2.6/site-packages/gammu/__init__.py", line 65, in from gammu._gammu import * ImportError: /usr/lib64/python2.6/site-packages/gammu/_gammu.so: undefined symbol: DivertCallTypeFromString some one know whats wrong ? Best Regards, Tal -------------- next part -------------- An HTML attachment was scrubbed... URL: From nikos.gr33k at gmail.com Tue Sep 17 08:02:56 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 17 Sep 2013 15:02:56 +0300 Subject: Having both if() and for() statements in one liner Message-ID: o want to avoid having to type somehting like this: if person="George": times in range(0, 5): Why it gives me an error when i'm trying to write it like this: if person="George" for times in range(0, 5): Can't i ahve both if and for in a one liner? From robert.kern at gmail.com Tue Sep 17 08:52:35 2013 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 17 Sep 2013 13:52:35 +0100 Subject: Having both if() and for() statements in one liner In-Reply-To: References: Message-ID: On 2013-09-17 13:02, Ferrous Cranus wrote: > o want to avoid having to type somehting like this: > > if person="George": > times in range(0, 5): > > > Why it gives me an error when i'm trying to write it like this: > > > if person="George" for times in range(0, 5): > > Can't i ahve both if and for in a one liner? Not in Python, no. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From roy at panix.com Tue Sep 17 09:00:34 2013 From: roy at panix.com (Roy Smith) Date: Tue, 17 Sep 2013 09:00:34 -0400 Subject: Having both if() and for() statements in one liner References: Message-ID: In article , Ferrous Cranus wrote: > o want to avoid having to type somehting like this: > > if person="George": > times in range(0, 5): > > > Why it gives me an error when i'm trying to write it like this: > > > if person="George" for times in range(0, 5): Step One when reporting a problem is don't just tell us you got an error. Tell us what the error is. Cut and paste the exact text of the full error message. Although, in this case, it's pretty easy to guess that it was a syntax error :-) I'm not sure where to start. First, the '=' in 'person="George"' should be '=='. In Python, '=' is used for assignment, '==' is used for equality testing. Next, if you want to use the 1-line version of 'if', you need a ':' after the condition. Something like: if person == 'George': print 'foo' but it's generally considered poor style to use 1-line if statements. Just write it on two lines: if person == 'George': print 'foo' They just discovered a huge newline vein in Montana and they're mining the things like crazy. There's no shortage of them so feel free to use as many as you like. They even get recycled. But, I'm not even sure you can put a 'for' statement as the body of a 1-line 'if'. I've never tried it before, and my one experiment now got me a syntax error. Even if it turns out to be legal and I just haven't got the details right, it's just The Wrong Thing To Do. From nikos.gr33k at gmail.com Tue Sep 17 09:21:01 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Tue, 17 Sep 2013 16:21:01 +0300 Subject: Having both if() and for() statements in one liner In-Reply-To: References: Message-ID: ???? 17/9/2013 4:00 ??, ?/? Roy Smith ??????: > In article , > Ferrous Cranus wrote: > >> o want to avoid having to type somehting like this: >> >> if person="George": >> times in range(0, 5): >> >> >> Why it gives me an error when i'm trying to write it like this: >> >> >> if person="George" for times in range(0, 5): > > Step One when reporting a problem is don't just tell us you got an > error. Tell us what the error is. Cut and paste the exact text of the > full error message. > > Although, in this case, it's pretty easy to guess that it was a syntax > error :-) > > I'm not sure where to start. First, the '=' in 'person="George"' should > be '=='. In Python, '=' is used for assignment, '==' is used for > equality testing. > > Next, if you want to use the 1-line version of 'if', you need a ':' > after the condition. Something like: > > if person == 'George': print 'foo' > > but it's generally considered poor style to use 1-line if statements. > Just write it on two lines: > > if person == 'George': > print 'foo' > > They just discovered a huge newline vein in Montana and they're mining > the things like crazy. There's no shortage of them so feel free to use > as many as you like. They even get recycled. > > But, I'm not even sure you can put a 'for' statement as the body of a > 1-line 'if'. I've never tried it before, and my one experiment now got > me a syntax error. Even if it turns out to be legal and I just haven't > got the details right, it's just The Wrong Thing To Do. > I just want to say tot he program that that only run the for statement if and only if person=='George' I dont see nay reason as to why this fails perhaps like: for times in range(0, 5) if person=='George': but that fails too... there must be written on soem way. From modelnine at modelnine.org Tue Sep 17 09:46:08 2013 From: modelnine at modelnine.org (Heiko Wundram) Date: Tue, 17 Sep 2013 15:46:08 +0200 Subject: Having both if() and for() statements in one liner In-Reply-To: References: Message-ID: <52385D20.2040303@modelnine.org> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Am 17.09.2013 15:21, schrieb Ferrous Cranus: > ... there must be written on soem way. You've already given yourself the answer in the initial post. The Python way to write this is: if person == "George": for times in range(5): ... Why not just use what works and get some actual work done? - -- - --- Heiko. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.20 (MingW32) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJSOF0gAAoJEDMqpHf921/Sv0oH/AyuaOk5sFlx4j7CKzv4Bb9i +REyAtLJXpgcziviFXjIbnPsNLtGqMU6yOgp9OV7LGwfn0mnZtmI+SoYp08t7G9U 3WSMC6BOCugg419EEMmf+Gkf4fWvv/aZYWBTd8MhyiJLsQ9R7Sg9LlGYheDQ6m+S RwWpYSHYCaJu3iy2xBJ+8AqQjOqACcMREtW1Rt1uHiydO93Dn2Abm0XLq11psYeR OV3sftEJ2EpMEcR4I/HLx95KWIh7wvQcZywTF9y+pe1uOnLrKW/1NdkUxNdkMofy RBNOjYJjT9JAnB2UHI1wVtbipwSi4A4zIIYsE6exv4s1IjnInrVERdDOOlqjwzQ= =rxPO -----END PGP SIGNATURE----- From python.list at tim.thechases.com Tue Sep 17 10:17:44 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 17 Sep 2013 09:17:44 -0500 Subject: Having both if() and for() statements in one liner In-Reply-To: References: Message-ID: <20130917091744.0aa6c577@bigbox.christie.dr> On 2013-09-17 16:21, Ferrous Cranus wrote: > I just want to say tot he program that > > that only run the for statement if and only if person=='George' > > I dont see nay reason as to why this fails > > perhaps like: > > for times in range(0, 5) if person=='George': > > but that fails too... > there must be written on soem way. The canonical way to do this is the obvious: if person == "George": for times in range(0, 5): ... That said, you can do stupid things to abstract the logic like def iterate_if(condition, iterable): if condition: for item in iterable: yield item which you can use something like for times in iterate_if(person == "George", range(0,5)): ... but I don't advise it. Mainly, because the iterable will be evaluated when passed as an argument, which incurs the runtime cost. In the canonical form, if the test isn't passed, the range(n,m) is never even evaluated. -tkc From joel.goldstick at gmail.com Tue Sep 17 10:32:20 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 17 Sep 2013 10:32:20 -0400 Subject: Having both if() and for() statements in one liner In-Reply-To: <20130917091744.0aa6c577@bigbox.christie.dr> References: <20130917091744.0aa6c577@bigbox.christie.dr> Message-ID: On Tue, Sep 17, 2013 at 10:17 AM, Tim Chase wrote: > On 2013-09-17 16:21, Ferrous Cranus wrote: > > I just want to say tot he program that > > > > that only run the for statement if and only if person=='George' > > > > I dont see nay reason as to why this fails > > > > perhaps like: > > > > for times in range(0, 5) if person=='George': > > > > but that fails too... > > there must be written on soem way. > > The canonical way to do this is the obvious: > > if person == "George": > for times in range(0, 5): > ... > > That said, you can do stupid things to abstract the logic like > > def iterate_if(condition, iterable): > if condition: > for item in iterable: > yield item > > which you can use something like > > for times in iterate_if(person == "George", range(0,5)): > ... > > but I don't advise it. Mainly, because the iterable will be > evaluated when passed as an argument, which incurs the runtime cost. > In the canonical form, if the test isn't passed, the range(n,m) is > never even evaluated. > > -tkc > > > Tim, that's great! or in the wonderful world of Onslow, "Oh nice" http://en.wikipedia.org/wiki/Onslow_(Keeping_Up_Appearances) > > > -- > https://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at davea.name Tue Sep 17 14:54:51 2013 From: davea at davea.name (Dave Angel) Date: Tue, 17 Sep 2013 18:54:51 +0000 (UTC) Subject: Having both if() and for() statements in one liner References: Message-ID: On 17/9/2013 09:21, Ferrous Cranus wrote: > I just want to say tot he program that > > that only run the for statement if and only if person=='George' > > I dont see nay reason as to why this fails > > perhaps like: > > for times in range(0, 5) if person=='George': > > but that fails too... > there must be written on soem way. > > untested: for times in range(0, 5 if person=="George" else 0): But i also greately prefer the canonical version. -- DaveA From steve at pearwood.info Tue Sep 17 22:10:56 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 18 Sep 2013 02:10:56 GMT Subject: Having both if() and for() statements in one liner References: Message-ID: <52390bb0$0$29869$c3e8da3$5496439d@news.astraweb.com> On Tue, 17 Sep 2013 18:54:51 +0000, Dave Angel wrote: > for times in range(0, 5 if person=="George" else 0): Oh that is evil. Truly evil. Thank you, I will treasure that piece of code forever. -- Steven From joshua at landau.ws Wed Sep 18 01:55:42 2013 From: joshua at landau.ws (Joshua Landau) Date: Wed, 18 Sep 2013 06:55:42 +0100 Subject: Having both if() and for() statements in one liner In-Reply-To: <52390bb0$0$29869$c3e8da3$5496439d@news.astraweb.com> References: <52390bb0$0$29869$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 18 September 2013 03:10, Steven D'Aprano wrote: > On Tue, 17 Sep 2013 18:54:51 +0000, Dave Angel wrote: > >> for times in range(0, 5 if person=="George" else 0): > > > Oh that is evil. Truly evil. > > Thank you, I will treasure that piece of code forever. range(person == "simon" and 5) From rosuav at gmail.com Wed Sep 18 03:00:07 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 18 Sep 2013 17:00:07 +1000 Subject: Having both if() and for() statements in one liner In-Reply-To: References: <52390bb0$0$29869$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Sep 18, 2013 at 3:55 PM, Joshua Landau wrote: > range(person == "simon" and 5) +1 for the BOFH reference. ChrisA From rosuav at gmail.com Tue Sep 17 11:04:31 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 18 Sep 2013 01:04:31 +1000 Subject: Having both if() and for() statements in one liner In-Reply-To: References: Message-ID: On Tue, Sep 17, 2013 at 11:00 PM, Roy Smith wrote: > They just discovered a huge newline vein in Montana and they're mining > the things like crazy. There's no shortage of them so feel free to use > as many as you like. They even get recycled. Can they keep up with the considerable demand even from Whitespace? http://en.wikipedia.org/wiki/Whitespace_(programming_language) I hope the Montanan newlines aren't on silly US export restrictions. That would be so annoying. ChrisA From joel.goldstick at gmail.com Tue Sep 17 11:15:54 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 17 Sep 2013 11:15:54 -0400 Subject: Having both if() and for() statements in one liner In-Reply-To: References: Message-ID: On Tue, Sep 17, 2013 at 11:04 AM, Chris Angelico wrote: > On Tue, Sep 17, 2013 at 11:00 PM, Roy Smith wrote: > > They just discovered a huge newline vein in Montana and they're mining > > the things like crazy. There's no shortage of them so feel free to use > > as many as you like. They even get recycled. > > Can they keep up with the considerable demand even from Whitespace? > > http://en.wikipedia.org/wiki/Whitespace_(programming_language) > > I hope the Montanan newlines aren't on silly US export restrictions. > That would be so annoying. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > You can get them all over the Mediterranean as well! I think they are like air -- -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From klurz at meridiantechnologies.net Tue Sep 17 11:12:00 2013 From: klurz at meridiantechnologies.net (Kelly Lurz) Date: Tue, 17 Sep 2013 15:12:00 +0000 Subject: Python Developers Message-ID: <5abbf020f6714f828c5dbf3bc82a2255@BL2PR08MB147.namprd08.prod.outlook.com> List - I am currently searching for W-2 candidates for several Python Developer positions in Mountain View, CA for a high-profile client. The positions are contract-to-perm at a starting rate of $80 an hour. Below is some additional information. Thank you for sending to your members if you find suitable. **Requirements** * 5+ years of experience programming in Python * 3+ years professional MySQL experience * Experience in Unix and Linux **What Python is used for**: You will be responsible for the design, implementation, testing, and release of a centralized data store for metrics related to the software development life cycle, with a focus on testing. This data will then be used to automate and aid in the analysis of failures, provide reports and trending we can utilize to identify areas of improvement, and automate manual processes and release decisions. You will interact with other members of the tools team to demonstrate designs, integrate with our existing tool chain, and iterate based on team feedback. The tool will be used throughout the engineering organization. **Contact Info:** * **Contact**: Kelly Lurz - Technical Recruiter * **E-mail contact**: klurz at meridiantechnologies.net * **Other Contact Info**: 904-332-7000 ext 110 * **Web**: * **No telecommuting** [Description: Description: Meridian_RGB_signature] Kelly Lurz Recruiter 5210 Belfort Road, Suite 400 Jacksonville, Florida 32256 O 904 332 7000 ext. 110 C 904 994 0959 F 904 332 0660 klurz at meridiantechnologies.net www.meridiantechnologies.net www.meridianstaffing.net http://www.linkedin.com/pub/kelly-lurz/a/95b/576 -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image001.jpg Type: image/jpeg Size: 2098 bytes Desc: image001.jpg URL: From ben+python at benfinney.id.au Wed Sep 18 03:57:04 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 18 Sep 2013 17:57:04 +1000 Subject: Please use the Python Job Board for recruiting (was: Python Developers) References: <5abbf020f6714f828c5dbf3bc82a2255@BL2PR08MB147.namprd08.prod.outlook.com> Message-ID: <7weh8my33j.fsf@benfinney.id.au> Kelly Lurz writes: > List Please do not use this discussion forum for job advertisements. Instead, please use the Python Job Board designed for this purpose . -- \ ?I don't know half of you half as well as I should like, and I | `\ like less than half of you half as well as you deserve.? ?Bilbo | _o__) Baggins | Ben Finney From skip at pobox.com Wed Sep 18 10:48:26 2013 From: skip at pobox.com (Skip Montanaro) Date: Wed, 18 Sep 2013 09:48:26 -0500 Subject: Please use the Python Job Board for recruiting (was: Python Developers) In-Reply-To: <7weh8my33j.fsf@benfinney.id.au> References: <5abbf020f6714f828c5dbf3bc82a2255@BL2PR08MB147.namprd08.prod.outlook.com> <7weh8my33j.fsf@benfinney.id.au> Message-ID: On Wed, Sep 18, 2013 at 2:57 AM, Ben Finney wrote: > Kelly Lurz writes: > >> List > > Please do not use this discussion forum for job advertisements. > > Instead, please use the Python Job Board designed for this purpose > . Agreed. This recruiter also spammed the Chicago Python list. Although the post was clearly Python-related, and he/she also used the template we ask for on the job board (thus not completely clueless), I consider these posts spam as said recruiter isn't considering the focus of the various mailing lists before posting to them. Skip From gslindstrom at gmail.com Tue Sep 17 13:51:24 2013 From: gslindstrom at gmail.com (Greg Lindstrom) Date: Tue, 17 Sep 2013 12:51:24 -0500 Subject: Suds and Complex Sequences Message-ID: Hello Everyone - I am trying to use Suds, the very fine library allowing me to use SOAP, to query a service over the net. Part of the data structure defined be the WSDL calls for a sequence of SubscriberDataTypes (this application is used to test an insurance companys' rating service). (SubscriberDataType){ SubscriberID = None SubscriberBirthDate = None Zip = None DependentData[] = } Which goes into (MedicalRatingRequest){ MessageHeader = (MessageHeaderType){ MessageName = None MessageID = None } RequestHeader = (RequestHeaderType){ RequestType = (RequestTypeEnum){ value = None } } SubscriberData[] = } Note that the Subscriber Data is a sequence of SubscriberDataType. I have not been able to find any documentation showing me how to do this. Does anyone out there know how I can generate the request? Thanks for your time, Greg Lindstrom -------------- next part -------------- An HTML attachment was scrubbed... URL: From gordon at panix.com Tue Sep 17 14:39:21 2013 From: gordon at panix.com (John Gordon) Date: Tue, 17 Sep 2013 18:39:21 +0000 (UTC) Subject: Suds and Complex Sequences References: Message-ID: In Greg Lindstrom writes: > --089e0122976c27f48b04e697f887 > Content-Type: text/plain; charset=ISO-8859-1 > Hello Everyone - > I am trying to use Suds, the very fine library allowing me to use SOAP, to > query a service over the net. Part of the data structure defined be the > WSDL calls for a sequence of SubscriberDataTypes (this application is used > to test an insurance companys' rating service). Contact whomever is providing this data and ask them for documentation. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From dieter at handshake.de Wed Sep 18 02:16:07 2013 From: dieter at handshake.de (dieter) Date: Wed, 18 Sep 2013 08:16:07 +0200 Subject: Suds and Complex Sequences References: Message-ID: <8761tyd594.fsf@handshake.de> Greg Lindstrom writes: > I am trying to use Suds, the very fine library allowing me to use SOAP, to > query a service over the net. Part of the data structure defined be the > WSDL calls for a sequence of SubscriberDataTypes (this application is used > to test an insurance companys' rating service). > > (SubscriberDataType){ > SubscriberID = None > SubscriberBirthDate = None > Zip = None > > DependentData[] = > } > > Which goes into > > (MedicalRatingRequest){ > MessageHeader = > (MessageHeaderType){ > MessageName = None > MessageID = None > > } > RequestHeader = > (RequestHeaderType){ > RequestType = > (RequestTypeEnum){ > value = None > } > > } > > SubscriberData[] = > } > > Note that the Subscriber Data is a sequence of SubscriberDataType. I have > not been able to find any documentation showing me how to do this. Does > anyone out there know how I can generate the request? A suds client as two major components: the "service" itself, and the so called "factory". You can use the "factory" to create Python objects corresponding to a type defined in the WSDL. To pass a list of complex type, you use the factory to create Python objects for the list components, set these objects' attributes in any way appropriate and build of Python list of them and assign the list or "append" them directly to the list values attribute. In your case, it may look somehow like: sd = client.factory("SubscriberDataType") # create a SubscriberDataType Python object sd.SubscriberID = ... # assign values for its attributes .... mrr = client.factory("MedicalRatingRequest") mrr.SubscriberData.append(sd) # append our "sd" or mrr.SubscriberData = [sd] # assign a list From mcepl at redhat.com Tue Sep 17 18:01:50 2013 From: mcepl at redhat.com (=?UTF-8?Q?Mat=C4=9Bj?= Cepl) Date: Wed, 18 Sep 2013 00:01:50 +0200 Subject: BDD behave support for vim Message-ID: Hi, I know that vim has native support for cucumber (the original BDD framework for Ruby). I have also found https://github.com/veloce/vim-behat for BDD with PHP (frightening idea!), but I haven't found a module supporting BDD with vim and Python. Especially I envy to our Ruby friends ability to jump from the particular line in the .feature file to the definition of step in the appropriate Ruby file. Does anybody know about any project which would do the same with behave what vim does for Ruby? Thank you, Mat?j From lubrs at comcast.net Tue Sep 17 20:06:44 2013 From: lubrs at comcast.net (Susan Lubbers) Date: Tue, 17 Sep 2013 20:06:44 -0400 Subject: scipy 11 and scipy 12 Message-ID: <47614298-AF6C-4868-973F-9C8F15FE5E6A@comcast.net> Our group is a python 2.7 which is installed in a shared area. We have scipy 11 installed in site-packages. How would I install scipy 12 so that I used the shared install of python but scipy 12 instead of 11? From steve at pearwood.info Tue Sep 17 22:48:08 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 18 Sep 2013 02:48:08 GMT Subject: scipy 11 and scipy 12 References: Message-ID: <52391468$0$29869$c3e8da3$5496439d@news.astraweb.com> On Tue, 17 Sep 2013 20:06:44 -0400, Susan Lubbers wrote: > Our group is a python 2.7 which is installed in a shared area. We have > scipy 11 installed in site-packages. How would I install scipy 12 so > that I used the shared install of python but scipy 12 instead of 11? If you are using Python 2.6 or better, you should be able to include the option "--user" when installing Scipy using either pip or distutils. I haven't tried these, but: # using pip: pip install --install-option="--user" scipy If that fails, follow the advice given here to install from svn: http://stackoverflow.com/questions/2213551/installing-scipy-with-pip pip install --install-option="--user" git+http://github.com/scipy/scipy/ Otherwise, if you are installing from source using distutils, add the --user option directly: python setup.py install --user scipy Does this help? -- Steven From oscar.j.benjamin at gmail.com Wed Sep 18 08:28:44 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 18 Sep 2013 13:28:44 +0100 Subject: scipy 11 and scipy 12 In-Reply-To: <52391468$0$29869$c3e8da3$5496439d@news.astraweb.com> References: <52391468$0$29869$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 18 September 2013 03:48, Steven D'Aprano wrote: > On Tue, 17 Sep 2013 20:06:44 -0400, Susan Lubbers wrote: > >> Our group is a python 2.7 which is installed in a shared area. We have >> scipy 11 installed in site-packages. How would I install scipy 12 so >> that I used the shared install of python but scipy 12 instead of 11? > > If you are using Python 2.6 or better, you should be able to include the > option "--user" when installing Scipy using either pip or distutils. I > haven't tried these, but: > > # using pip: > pip install --install-option="--user" scipy Is there a difference between --install-option="--user" and just passing --user directly? > If that fails, follow the advice given here to install from svn: > http://stackoverflow.com/questions/2213551/installing-scipy-with-pip > > > pip install --install-option="--user" git+http://github.com/scipy/scipy/ > > > Otherwise, if you are installing from source using distutils, add the > --user option directly: > > python setup.py install --user scipy To be clear any of the above options are for building scipy from source which means you need a C compiler, a Fortran compiler and to separately build/install BLAS/LAPACK: http://stackoverflow.com/questions/7496547/python-scipy-needs-blas The best instructions for meeting these requirements depend on your OS (are you using Windows?). For Python 2.7 I think that easy_install will be able to install from the sourceforge binaries, e.g easy_install --user scipy but I may be wrong. You'll need to ensure that you don't have a mismatch between numpy/scipy versions and I don't know if easy_install will handle that for you. This may mean separately installing numpy as well. Oscar From steve+comp.lang.python at pearwood.info Wed Sep 18 22:42:19 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Sep 2013 02:42:19 GMT Subject: scipy 11 and scipy 12 References: <52391468$0$29869$c3e8da3$5496439d@news.astraweb.com> Message-ID: <523a648a$0$29988$c3e8da3$5496439d@news.astraweb.com> On Wed, 18 Sep 2013 13:28:44 +0100, Oscar Benjamin wrote: > On 18 September 2013 03:48, Steven D'Aprano wrote: >> On Tue, 17 Sep 2013 20:06:44 -0400, Susan Lubbers wrote: >> >>> Our group is a python 2.7 which is installed in a shared area. We >>> have scipy 11 installed in site-packages. How would I install scipy >>> 12 so that I used the shared install of python but scipy 12 instead of >>> 11? >> >> If you are using Python 2.6 or better, you should be able to include >> the option "--user" when installing Scipy using either pip or >> distutils. I haven't tried these, but: >> >> # using pip: >> pip install --install-option="--user" scipy > > Is there a difference between --install-option="--user" and just passing > --user directly? *shrug* I don't have any experience with pip, so I don't know. > For Python 2.7 I think that easy_install will be able to install from > the sourceforge binaries, e.g > > easy_install --user scipy > > but I may be wrong. If I recall correctly, and I may not, easy_install doesn't support per- user installs with the --user option. -- Steven From oscar.j.benjamin at gmail.com Thu Sep 19 08:34:39 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 19 Sep 2013 13:34:39 +0100 Subject: scipy 11 and scipy 12 In-Reply-To: <523a648a$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <52391468$0$29869$c3e8da3$5496439d@news.astraweb.com> <523a648a$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 19 September 2013 03:42, Steven D'Aprano wrote: >> For Python 2.7 I think that easy_install will be able to install from >> the sourceforge binaries, e.g >> >> easy_install --user scipy >> >> but I may be wrong. I should add that I meant the above as a suggestion for a Windows user. > If I recall correctly, and I may not, easy_install doesn't support per- > user installs with the --user option. It has the option: $ easy_install --help | grep -- --user --user install in user site-package 'C:\Documents and I just don't know if that works when easy_install works from a binary rather than an sdist. Oscar From travisgriggs at gmail.com Tue Sep 17 21:08:05 2013 From: travisgriggs at gmail.com (Travis Griggs) Date: Tue, 17 Sep 2013 18:08:05 -0700 Subject: Simple security between prototype iPhone app and SimpleHTTPServer REST service? Message-ID: <23487B84-131D-4685-81AB-EC62C8DBAC6D@gmail.com> I'm prototyping a simple data collection service. I've implemented a simple REST API implemented with python 3x stock HTTPServer. And a simple iPhone app that submits data via a json/POST. And it all works just great when my iPhone is on the same network as the server. But now I want to go the next step. I don't need to move beyond prototype/PoC yet, I just want to be able to do it outside of our internal network. Issues aside of getting access, name resolution, a port and that kind of stuff... what kind of security should I add to it? I might as well be a complete neophyte in this area. I've read a number of posts and such, and I get some of the pieces, at some level, but any confidence how to put that part of a web stack together elude me. I found a example of how to add SSL to my python service (https://gist.github.com/ubershmekel/6194556). If I can figure out how to get the right keys embedded into my iPhone app (it's just on my phone, not anyone else's), is that enough? Or should I include some sort of auth? If so, what kind? And any pointers to how to start that would be much appreciated. Some have blithely replied that I should be using Flask or Tornado. I get that I'm going to hit a wall with HTTPServer and that it's more of a "toy" implementation. But I don't want to get buried in learning a big framework either. If it was relatively easy to convert my simple REST service to one running on Tornado or Flask, without loading a bunch of other frameworks, and I got easy access to security services and good examples how to do them, that'd be fine with me. So far, my searches haven't turned up the simple recipe of "so, you've made a simple REST API with HttpServer, here's how to take it to the semi secure public level using a real web framework." Travis Griggs -- I multiple all estimates by pi to account from running around in circles. From dieter at handshake.de Wed Sep 18 02:49:44 2013 From: dieter at handshake.de (dieter) Date: Wed, 18 Sep 2013 08:49:44 +0200 Subject: Simple security between prototype iPhone app and SimpleHTTPServer REST service? References: <23487B84-131D-4685-81AB-EC62C8DBAC6D@gmail.com> Message-ID: <871u4md3p3.fsf@handshake.de> Travis Griggs writes: > ... > I found a example of how to add SSL to my python service (https://gist.github.com/ubershmekel/6194556). If I can figure out how to get the right keys embedded into my iPhone app (it's just on my phone, not anyone else's), is that enough? Or should I include some sort of auth? If so, what kind? And any pointers to how to start that would be much appreciated. This is less a Python question. What kind of authentication you need heavily depends on which data your HTTP server publishes. You need no authentication at all, if anyone can see this data. There are many standards related to HTTP authentication. Using a standard has the advantage that common components (e.g. the browser) may have support for it. HTTP itself defines two authentication standards - both based an a simple "login/password" scheme: "basic" (very simple, but prone to replay and monitoring attacks) and "digest" (more secure but rarely used). There is also HTTPS (that is HTTP over SSL). This is HTTP over an encrypted communication channel. As the data transmitted is encrypted, monitoring and replay attacks get far more difficult. Used this way, HTTP basic authentication gets much more secure. HTTPS is typically also used for server identification (typical browsers warn you, if it does not trust the (HTTPS) server certificate or the host name inside the certificate does not correspond to the host you try to contact). However, HTTPS can also be used with client certificates; this usage may be an alternative to HTTP authentication. There are a lot of further standards related to authentication: e.g. "OpenId", "SAML2", "OpenAuth", ... > Some have blithely replied that I should be using Flask or Tornado. I get that I'm going to hit a wall with HTTPServer and that it's more of a "toy" implementation. This may be the part of your question which relates to Python; more precisely to "HTTPServer". I do not have an authoritative answer for you. I suppose (!; I am not sure) that "HTTPServer" will somehow support basic authentication and maybe HTTPS, however, it may not support it alone. For "basic" authentication, you need some kind of user "database" which records the known users with their passwords and maybe the services those users may use. By itself "HTTPS" does not provide (client) authentication; for client authentication, you need again some kind of user "database" to determine which clients (identified by the client certificate) you want to grant any and which services. This user "database" may be quite simple (maybe, it contains just "you") - but Python's "HTTPServer" cannot know - and does not provide this piece of infrastructure. You must extend Python's "HTTPServer" to provide it. Authentication support is a fundamental task for web frameworks. Therefore, they contain infrastructure to facilitate this task. This include "modules" for the implementation of the "user database" mentioned above. My personal recommendation: if this is the only web application you plan to implement, you may stick with "HTTPServer". However, if you can imagine that in the future you will implement further web applications, then look for a web framework. True, you will have to learn quite a bit - but you get components that facilitate typical tasks related to web applications (e.g. authentication). This initial learning effort may amortise when you plan to implement more web applications in the future. From britten.bryan at gmail.com Tue Sep 17 21:42:21 2013 From: britten.bryan at gmail.com (Bryan Britten) Date: Tue, 17 Sep 2013 18:42:21 -0700 (PDT) Subject: *.csv to *.txt after adding columns Message-ID: <41edba54-31d3-48ad-a50f-41f87f32d251@googlegroups.com> Hey, gang, I've got a problem here that I'm sure a handful of you will know how to solve. I've got about 6 *.csv files that I am trying to open; change the header names (to get rid of spaces); add two new columns, which are just the results of a string.split() command; drop the column I just split; and then finally export to *.txt files. Here's the code I'm using: import os import csv fileHandle = 'Path/To/Data' varNames = 'ID\tCaseNum\tDate\tTime\tBlock\tIUCR\tPrimaryType\tDescription\tLocDesc\tArrest\tDomestic\tBeat\tDistrict\tWard\tCommArea\tFBICode\tXCoord\tYCoord\tYear\tUpdatedOn\tLat\tLong\tLoc\n' for csvFile in os.listdir(fileHandle): outFile = open(fileHandle + os.path.splitext(csvFile)[0] + '.txt', 'w') inFile = open(fileHandle + csvFile, 'rb') reader = csv.reader(inFile, delimiter=',') rowNum = 0 for row in reader: if rowNum == 0: outFile.write(varNames) rowNum += 1 else: date, time = row[2].split() row.insert(3, date) row.insert(4, time) row.remove(row[2]) outFile.write('\t'.join(row) + '\n') outFile.close() inFile.close() The issue I'm having is that the *.txt files I'm generating are empty. I assume some unraised error is being thrown, but I'm new to Python and am self taught, so I don't know where to look or how to troubleshoot. When I run the code on just one file and print the output instead of writing it, it looks exactly like what I'd want. So I'm at a loss for where the problem is. Any help is appreciated! From davea at davea.name Tue Sep 17 22:18:46 2013 From: davea at davea.name (Dave Angel) Date: Wed, 18 Sep 2013 02:18:46 +0000 (UTC) Subject: *.csv to *.txt after adding columns References: <41edba54-31d3-48ad-a50f-41f87f32d251@googlegroups.com> Message-ID: On 17/9/2013 21:42, Bryan Britten wrote: > Hey, gang, I've got a problem here that I'm sure a handful of you will know how to solve. I've got about 6 *.csv files that I am trying to open; change the header names (to get rid of spaces); add two new columns, which are just the results of a string.split() command; drop the column I just split; and then finally export to *.txt files. Here's the code I'm using: > > import os > import csv > > > fileHandle = 'Path/To/Data' > varNames = 'ID\tCaseNum\tDate\tTime\tBlock\tIUCR\tPrimaryType\tDescription\tLocDesc\tArrest\tDomestic\tBeat\tDistrict\tWard\tCommArea\tFBICode\tXCoord\tYCoord\tYear\tUpdatedOn\tLat\tLong\tLoc\n' > > for csvFile in os.listdir(fileHandle): > outFile = open(fileHandle + os.path.splitext(csvFile)[0] + '.txt', 'w') > inFile = open(fileHandle + csvFile, 'rb') > reader = csv.reader(inFile, delimiter=',') > rowNum = 0 > for row in reader: > if rowNum == 0: > outFile.write(varNames) > rowNum += 1 > else: > date, time = row[2].split() > row.insert(3, date) > row.insert(4, time) > row.remove(row[2]) > outFile.write('\t'.join(row) + '\n') > outFile.close() > inFile.close() > > > The issue I'm having is that the *.txt files I'm generating are empty. I assume some unraised error is being thrown, How can you NOT know if an exception is being raised? How are you running the code, in a terminal window? Can't you just see what gets printed (as stderr)? > but I'm new to Python and am self taught, so I don't know where to look > or how to troubleshoot. > > When I run the code on just one file and print the output instead of writing it, it looks exactly like what I'd want. So I'm at a loss for where the problem is. You describe two changes, but don't show them. How about you do them one at a time, or perhaps even better, add prints so it both does the file(s) AND prints the output? What I think is happening is that you're missing the path separator between the "Path/To/Data" and the basename. You should be combining those with os.path.join(), not with + For a quick & dirty check, add a trailing slash to the fileHandle. But that's not the right way to fix it. -- DaveA From britten.bryan at gmail.com Tue Sep 17 22:28:54 2013 From: britten.bryan at gmail.com (Bryan Britten) Date: Tue, 17 Sep 2013 19:28:54 -0700 (PDT) Subject: *.csv to *.txt after adding columns In-Reply-To: <41edba54-31d3-48ad-a50f-41f87f32d251@googlegroups.com> References: <41edba54-31d3-48ad-a50f-41f87f32d251@googlegroups.com> Message-ID: Dave - I can't print the output because there are close to 1,000,000 records. It would be extremely inefficient and resource intensive to look at every row. Like I said, when I take just one file and run the code over the first few records I get what I'd expect to see. Here's an example(non-redacted code): INPUT: import csv fileHandle = 'C:/Users/Bryan/Data Analysis/Crime Analysis/Data/' varNames = 'ID\tCaseNum\tDate\tTime\tBlock\tIUCR\tPrimaryType\tDescription\tLocDesc\tArrest\tDomestic\tBeat\tDistrict\tWard\tCommArea\tFBICode\tXCoord\tYCoord\tYear\tUpdatedOn\tLat\tLong\tLoc\n' outFile = open(fileHandle + 'ChiCrime01_02.txt', 'w') inFile = open(fileHandle + 'ChiCrime01_02.csv', 'rb') reader = csv.reader(inFile, delimiter=',') rowNum = 0 for row in reader: if rowNum < 5: if rowNum >= 1: date, time = row[2].split() row.insert(3, date) row.insert(4, time) row.remove(row[2]) print '\t'.join(row) rowNum+=1 else: print varNames rowNum+=1 OUTPUT: ID CaseNum Date Time Block IUCR PrimaryType Description LocDesc Arrest Domestic Beat District Ward CommArea FBICode XCoord YCoord Year UpdatedOn Lat Long Loc 2924745 HJ602602 12/31/2002 23:59 006XX W 117TH ST 841 THEFT FINANCIAL ID THEFT:$300 &UNDER RESIDENCE PORCH/HALLWAY FALSE FALSE 524 5 34 53 6 1173831 1827387 2002 3/30/2006 21:10 41.68175482 -87.63931351 (41.681754819160666, -87.63931350564216) 2523290 HJ101091 12/31/2002 23:59 002XX W 112TH PL 1310 CRIMINAL DAMAGE TO PROPERTY APARTMENT FALSE FALSE 522 34 49 14 1176848 1830383 2002 3/30/2006 21:10 41.68990907 -87.62817988 (41.689909072449474, -87.62817987594765) 2527332 HJ105139 12/31/2002 23:55 005XX E 89TH PL 486 BATTERY DOMESTIC BATTERY SIMPLE RESIDENCE FALSE TRUE 633 6 44 08B 1181369 1845794 2002 3/30/2006 21:10 41.73209609 -87.61115533 (41.732096089465905, -87.61115532670617) 2524251 HJ100175 12/31/2002 23:55 012XX S KARLOV AVE 041A BATTERY AGGRAVATED: HANDGUN SIDEWALK FALSE FALSE 1011 24 29 04B 1149196 1894387 2002 3/30/2006 21:10 41.86612296 -87.72776536 (41.86612295941429, -87.72776535755746) Like I said, the output is exactly what I want, but it doesn't seem to be writing to the file and I don't know why. I said I didn't know if it was raising an exception because I'm new to Python and I didn't know if there were some methods that included "silent" errors where it would continue the code but produce the wrong results, such as not writing my files. Lastly, why does everyone seem to push for os.path.join versus the method I have used? Is it just a 'standard' that people like to see? Thanks for your help From davea at davea.name Wed Sep 18 03:55:52 2013 From: davea at davea.name (Dave Angel) Date: Wed, 18 Sep 2013 07:55:52 +0000 (UTC) Subject: *.csv to *.txt after adding columns References: <41edba54-31d3-48ad-a50f-41f87f32d251@googlegroups.com> Message-ID: On 17/9/2013 22:28, Bryan Britten wrote: > Dave - > > I can't print the output because there are close to 1,000,000 records. It would be extremely inefficient and resource intensive to look at every row. Not if you made a sample directory with about 3 files, each containing half a dozen lines. > Like I said, when I take just one file and run the code over the first > few records I get what I'd expect to see. Here's an example(non-redacted code): > > INPUT: > > import csv > > fileHandle = 'C:/Users/Bryan/Data Analysis/Crime Analysis/Data/' Now, that directory specification ends with a slash. So "+" will work correctly. But your original did not. > > varNames = 'ID\tCaseNum\tDate\tTime\tBlock\tIUCR\tPrimaryType\tDescription\tLocDesc\tArrest\tDomestic\tBeat\tDistrict\tWard\tCommArea\tFBICode\tXCoord\tYCoord\tYear\tUpdatedOn\tLat\tLong\tLoc\n' > > outFile = open(fileHandle + 'ChiCrime01_02.txt', 'w') > inFile = open(fileHandle + 'ChiCrime01_02.csv', 'rb') Instead of changing this code, you could have switched to a directory containing only one file. > > Like I said, the output is exactly what I want, but it doesn't seem to be writing to the file and I don't know why. I said I didn't know if it was raising an exception because I'm new to Python and I didn't know if there were some methods that included "silent" errors where it would continue the code but produce the wrong results, such as not writing my files. > The only "silent" exception I know of is the one triggered by sys.exit(), used to terminate the process. > Lastly, why does everyone seem to push for os.path.join versus the method I have used? Is it just a 'standard' that people like to see? > Because os.path.join will be smart enough to add the slashes only if they are necessary. That can be useful, especially if the directory you're using as a prefix came from the user. I think Peter's suggestion is probably right on; you don't limit your infiles to *.csv, so you will be processing *.txt files the second time. Another useful debugging aid would have been to add print statements right after opening the files, perhaps something like: print "Reading :", infile.name print "Writing:", outfile.name If those names had been missing slashes, I would have been vindicated, while if they were the same, you'd know Peter had nailed it. -- DaveA From __peter__ at web.de Wed Sep 18 03:14:23 2013 From: __peter__ at web.de (Peter Otten) Date: Wed, 18 Sep 2013 09:14:23 +0200 Subject: *.csv to *.txt after adding columns References: <41edba54-31d3-48ad-a50f-41f87f32d251@googlegroups.com> Message-ID: Bryan Britten wrote: > Hey, gang, I've got a problem here that I'm sure a handful of you will > know how to solve. I've got about 6 *.csv files that I am trying to open; > change the header names (to get rid of spaces); add two new columns, which > are just the results of a string.split() command; drop the column I just > split; and then finally export to *.txt files. Here's the code I'm using: > > import os > import csv > > > fileHandle = 'Path/To/Data' > varNames = > 'ID\tCaseNum\tDate\tTime\tBlock\tIUCR\tPrimaryType\tDescription\tLocDesc\tArrest\tDomestic\tBeat\tDistrict\tWard\tCommArea\tFBICode\tXCoord\tYCoord\tYear\tUpdatedOn\tLat\tLong\tLoc\n' > You may be processing not just the .csv files, but also the .txt files from a previous run of your script. Remove them manually to verify my guess. If I'm right you can (in order of my preference) (1) write the output into another directory and also do (2) (2) filter the input files with glob.glob("/path/to/data/*.csv") (3) or just add the two lines below to your current code. > for csvFile in os.listdir(fileHandle): if not csvFile.endswith(".csv"): continue > outFile = open(fileHandle + os.path.splitext(csvFile)[0] + '.txt', > 'w') > inFile = open(fileHandle + csvFile, 'rb') > reader = csv.reader(inFile, delimiter=',') > rowNum = 0 > for row in reader: > if rowNum == 0: > outFile.write(varNames) > rowNum += 1 > else: > date, time = row[2].split() > row.insert(3, date) > row.insert(4, time) > row.remove(row[2]) > outFile.write('\t'.join(row) + '\n') > outFile.close() > inFile.close() > > > The issue I'm having is that the *.txt files I'm generating are empty. I > assume some unraised error is being thrown, but I'm new to Python and am > self taught, so I don't know where to look or how to troubleshoot. > > When I run the code on just one file and print the output instead of > writing it, it looks exactly like what I'd want. So I'm at a loss for > where the problem is. > > Any help is appreciated! From rustompmody at gmail.com Wed Sep 18 03:44:44 2013 From: rustompmody at gmail.com (rusi) Date: Wed, 18 Sep 2013 00:44:44 -0700 (PDT) Subject: *.csv to *.txt after adding columns In-Reply-To: <41edba54-31d3-48ad-a50f-41f87f32d251@googlegroups.com> References: <41edba54-31d3-48ad-a50f-41f87f32d251@googlegroups.com> Message-ID: <19f72b93-27c8-4426-9a97-25d88a9be702@googlegroups.com> On Wednesday, September 18, 2013 7:12:21 AM UTC+5:30, Bryan Britten wrote: > Hey, gang, I've got a problem here that I'm sure a handful of you will know how to solve. I've got about 6 *.csv files that I am trying to open; change the header names (to get rid of spaces); add two new columns, which are just the results of a string.split() command; drop the column I just split; and then finally export to *.txt files. Here's the code I'm using: Its generally a good idea in programming to separate separable problems. Since you say: > The issue I'm having is that the *.txt files I'm generating are empty. I > assume some unraised error is being thrown, but I'm new to Python and am self > taught, so I don't know where to look or how to troubleshoot. > When I run the code on just one file and print the output instead of writing > it, it looks exactly like what I'd want. So I'm at a loss for where the > problem is. you should probably write and have checked the code that handles one file. For example a function that takes as parameters the two: the input/output files (maybe names or handles), and then - check that that function works for one file - call it in your loop [BTW your code seems to mixup the variable-names for file-names and handles] From britten.bryan at gmail.com Wed Sep 18 07:42:11 2013 From: britten.bryan at gmail.com (Bryan Britten) Date: Wed, 18 Sep 2013 04:42:11 -0700 (PDT) Subject: *.csv to *.txt after adding columns In-Reply-To: <41edba54-31d3-48ad-a50f-41f87f32d251@googlegroups.com> References: <41edba54-31d3-48ad-a50f-41f87f32d251@googlegroups.com> Message-ID: Peter nailed it. Adding in the two lines of code to ensure I was just working with *.csv files fixed the problem. Thanks to everyone for the help and suggestions on best practices. From chitturk at uah.edu Tue Sep 17 22:34:39 2013 From: chitturk at uah.edu (Krishnan) Date: Tue, 17 Sep 2013 19:34:39 -0700 (PDT) Subject: linregress and polyfit Message-ID: <73ee6fa3-baa6-4178-8596-5f88bbd0bfa2@googlegroups.com> I created an xy pair y = slope*x + intercept then I added some noise to "y" using numpy.random.normal - call it z I could recover the slope, intercept from (x,y) using linregress BUT cannot calculate the slope, intercept from (x, z) What is puzzling is that for both pairs (x,y) and (x,z) the polyfit (order 1) works just fine (gives me the slope, intercept) ---------------------------------------------------------------------- import numpy as np import scipy # create a straight line, y= slope*x + intercept x = np.linspace(0.0,10.0,21) slope = 1.0 intercept = 3.0 y = [] for i in range(len(x)): y.append(slope*x[i] + intercept) # now create a data file with noise z= [] for i in range(len(x)): z.append(y[i] + 0.1*np.random.normal(0.0,1.0,1)) # now calculate the slope, intercept using linregress from scipy import stats # No error here this is OK, works for x, y cslope, cintercept, r_value, p_value, std_err = stats.linregress(x,y) print cslope, cintercept # I get an error here #ValueError: array dimensions must agree except for d_0 nslope, nintercept, nr_value, np_value, nstd_err = stats.linregress(x,z) print nslope, nintercept # BUT polyfit works fine, polynomial or order 1 with both data sets ncoeffs = scipy.polyfit(x,z,1) print ncoeffs coeffs = scipy.polyfit(x,y,1) print coeffs From josef.pktd at gmail.com Wed Sep 18 00:25:17 2013 From: josef.pktd at gmail.com (Josef Pktd) Date: Tue, 17 Sep 2013 21:25:17 -0700 (PDT) Subject: linregress and polyfit In-Reply-To: <73ee6fa3-baa6-4178-8596-5f88bbd0bfa2@googlegroups.com> References: <73ee6fa3-baa6-4178-8596-5f88bbd0bfa2@googlegroups.com> Message-ID: On Tuesday, September 17, 2013 10:34:39 PM UTC-4, Krishnan wrote: > I created an xy pair > > > > y = slope*x + intercept > > > > then I added some noise to "y" using > > > > numpy.random.normal - call it z > > > > I could recover the slope, intercept from (x,y) using linregress > > BUT cannot calculate the slope, intercept from (x, z) > > > > What is puzzling is that for both pairs (x,y) and (x,z) the > > polyfit (order 1) works just fine (gives me the slope, intercept) > > ---------------------------------------------------------------------- > > import numpy as np > > import scipy > > # create a straight line, y= slope*x + intercept > > x = np.linspace(0.0,10.0,21) > > slope = 1.0 > > intercept = 3.0 > > y = [] > > for i in range(len(x)): > > y.append(slope*x[i] + intercept) > > # now create a data file with noise > > z= [] > > for i in range(len(x)): > > z.append(y[i] + 0.1*np.random.normal(0.0,1.0,1)) When z is converted to a numpy array then it has an extra dimension that linregress cannot handle, because np.random.normal(0.0,1.0, 1) returns an array and not a scalar. much easier: use vectorized numpy instead of loop z = y + 0.1*np.random.normal(0.0,1.0, len(y)) which is a one dimensional array and works with linregress Josef > > # now calculate the slope, intercept using linregress > > from scipy import stats > > # No error here this is OK, works for x, y > > cslope, cintercept, r_value, p_value, std_err = stats.linregress(x,y) > > print cslope, cintercept > > # I get an error here > > #ValueError: array dimensions must agree except for d_0 > > nslope, nintercept, nr_value, np_value, nstd_err = stats.linregress(x,z) > > print nslope, nintercept > > # BUT polyfit works fine, polynomial or order 1 with both data sets > > ncoeffs = scipy.polyfit(x,z,1) > > print ncoeffs > > coeffs = scipy.polyfit(x,y,1) > > print coeffs From chitturk at uah.edu Wed Sep 18 09:38:33 2013 From: chitturk at uah.edu (chitturk at uah.edu) Date: Wed, 18 Sep 2013 06:38:33 -0700 (PDT) Subject: linregress and polyfit In-Reply-To: <73ee6fa3-baa6-4178-8596-5f88bbd0bfa2@googlegroups.com> References: <73ee6fa3-baa6-4178-8596-5f88bbd0bfa2@googlegroups.com> Message-ID: Thanks - that helps ... but it is puzzling because np.random.normal(0.0,1.0,1) returns exactly one and when I checked the length of "z", I get 21 (as before) ... On Tuesday, September 17, 2013 9:34:39 PM UTC-5, Krishnan wrote: > I created an xy pair > > > > y = slope*x + intercept > > > > then I added some noise to "y" using > > > > numpy.random.normal - call it z > > > > I could recover the slope, intercept from (x,y) using linregress > > BUT cannot calculate the slope, intercept from (x, z) > > > > What is puzzling is that for both pairs (x,y) and (x,z) the > > polyfit (order 1) works just fine (gives me the slope, intercept) > > ---------------------------------------------------------------------- > > import numpy as np > > import scipy > > # create a straight line, y= slope*x + intercept > > x = np.linspace(0.0,10.0,21) > > slope = 1.0 > > intercept = 3.0 > > y = [] > > for i in range(len(x)): > > y.append(slope*x[i] + intercept) > > # now create a data file with noise > > z= [] > > for i in range(len(x)): > > z.append(y[i] + 0.1*np.random.normal(0.0,1.0,1)) > > # now calculate the slope, intercept using linregress > > from scipy import stats > > # No error here this is OK, works for x, y > > cslope, cintercept, r_value, p_value, std_err = stats.linregress(x,y) > > print cslope, cintercept > > # I get an error here > > #ValueError: array dimensions must agree except for d_0 > > nslope, nintercept, nr_value, np_value, nstd_err = stats.linregress(x,z) > > print nslope, nintercept > > # BUT polyfit works fine, polynomial or order 1 with both data sets > > ncoeffs = scipy.polyfit(x,z,1) > > print ncoeffs > > coeffs = scipy.polyfit(x,y,1) > > print coeffs From davea at davea.name Wed Sep 18 15:57:26 2013 From: davea at davea.name (Dave Angel) Date: Wed, 18 Sep 2013 19:57:26 +0000 (UTC) Subject: linregress and polyfit References: <73ee6fa3-baa6-4178-8596-5f88bbd0bfa2@googlegroups.com> Message-ID: On 18/9/2013 09:38, chitturk at uah.edu wrote: > Thanks - that helps ... but it is puzzling because > > np.random.normal(0.0,1.0,1) returns exactly one > and when I checked the length of "z", I get 21 (as before) ... > > I don't use Numpy, so this is just a guess, plus reading one web page. According to: http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.normal.html the 3rd argument to normal should be a tuple. So if you want a single element, you should have made it (1,) As for checking the 'length of "z"' did you just use the len() function? That just tells you the first dimension. Have you tried simply printing out "z" ? -- DaveA From oscar.j.benjamin at gmail.com Thu Sep 19 10:37:09 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 19 Sep 2013 15:37:09 +0100 Subject: linregress and polyfit In-Reply-To: References: <73ee6fa3-baa6-4178-8596-5f88bbd0bfa2@googlegroups.com> Message-ID: On 18 September 2013 20:57, Dave Angel wrote: > On 18/9/2013 09:38, chitturk at uah.edu wrote: > >> Thanks - that helps ... but it is puzzling because >> >> np.random.normal(0.0,1.0,1) returns exactly one >> and when I checked the length of "z", I get 21 (as before) ... >> >> > > I don't use Numpy, so this is just a guess, plus reading one web page. > > According to: > http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.normal.html > > the 3rd argument to normal should be a tuple. So if you want a single > element, you should have made it (1,) Numpy accepts ints in place of shape tuples so this makes no difference. > As for checking the 'length of "z"' did you just use the len() function? > That just tells you the first dimension. Have you tried simply printing > out "z" ? Exactly. What you need to check is the shape attribute (converting to numpy array first if necessary): >>> import numpy as np >>> a = np.random.normal(0, 1, 1) >>> a array([-0.90292348]) >>> a.shape (1,) >>> a[0] -0.90292348393433797 >>> np.array(a[0]) array(-0.902923483934338) >>> np.array(a[0]).shape () >>> [a, a] [array([-0.90292348]), array([-0.90292348])] >>> np.array([a, a]) array([[-0.90292348], [-0.90292348]]) >>> np.array([a, a]).shape (2, 1) >>> np.random.normal(0, 1, 2).shape (2,) The square brackets in 'array([-0.90292348])' indicate that numpy considers this to be a 1-dimensional array of length 1 rather than a scalar value (which would have an empty shape tuple). Oscar From chitturk at uah.edu Thu Sep 19 07:32:36 2013 From: chitturk at uah.edu (chitturk at uah.edu) Date: Thu, 19 Sep 2013 04:32:36 -0700 (PDT) Subject: linregress and polyfit In-Reply-To: <73ee6fa3-baa6-4178-8596-5f88bbd0bfa2@googlegroups.com> References: <73ee6fa3-baa6-4178-8596-5f88bbd0bfa2@googlegroups.com> Message-ID: <3d938bae-bd60-4039-9571-2eaead5b8dad@googlegroups.com> tried (1,) - still same error ... printed "z" and looks right, len(z) OK (puzzling) From mohsen at pahlevanzadeh.org Tue Sep 17 23:41:13 2013 From: mohsen at pahlevanzadeh.org (Mohsen Pahlevanzadeh) Date: Wed, 18 Sep 2013 08:11:13 +0430 Subject: creating rectangle with qt-designer Message-ID: <1379475673.6014.8.camel@debian> Dear all, I need to draw a rectangle , according to attached picture , you see a rectangle in a form that enclosed with a text: "Rebuild Last Target". Question: How can i draw a same rectangle with qt-designer? Yours, Mohsen -------------- next part -------------- A non-text attachment was scrubbed... Name: rectantgle.png Type: image/png Size: 199898 bytes Desc: not available URL: From python at mrabarnett.plus.com Wed Sep 18 07:38:05 2013 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 18 Sep 2013 12:38:05 +0100 Subject: creating rectangle with qt-designer In-Reply-To: <1379475673.6014.8.camel@debian> References: <1379475673.6014.8.camel@debian> Message-ID: <5239909D.4070502@mrabarnett.plus.com> On 18/09/2013 04:41, Mohsen Pahlevanzadeh wrote: > Dear all, > > I need to draw a rectangle , according to attached picture , you see a > rectangle in a form that enclosed with a text: "Rebuild Last Target". > > Question: How can i draw a same rectangle with qt-designer? > That's a "groupbox". In Qt it's called "QGroupBox". From rhodri at wildebst.demon.co.uk Thu Sep 19 19:54:26 2013 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 20 Sep 2013 00:54:26 +0100 Subject: creating rectangle with qt-designer References: Message-ID: On Wed, 18 Sep 2013 04:41:13 +0100, Mohsen Pahlevanzadeh wrote: > Question: How can i draw a same rectangle with qt-designer? First, posting an image to a newsgroup is pretty damn unfriendly. Please don't do it again. Second, wouldn't this question be better answered by the Qt Designer manual? Which can be googled for trivially, by the way. -- Rhodri James *-* Wildebeest Herder to the Masses From vincent.vandevyvre at swing.be Thu Sep 19 21:41:22 2013 From: vincent.vandevyvre at swing.be (Vincent Vande Vyvre) Date: Fri, 20 Sep 2013 03:41:22 +0200 Subject: creating rectangle with qt-designer In-Reply-To: <1379475673.6014.8.camel@debian> References: <1379475673.6014.8.camel@debian> Message-ID: <523BA7C2.1090807@swing.be> Le 18/09/2013 05:41, Mohsen Pahlevanzadeh a ?crit : > Dear all, > > I need to draw a rectangle , according to attached picture , you see a > rectangle in a form that enclosed with a text: "Rebuild Last Target". > > Question: How can i draw a same rectangle with qt-designer? > > > Yours, > Mohsen > See : http://pyqt.sourceforge.net/Docs/PyQt4/qgroupbox.html -- Vincent V.V. Oqapy . Qarte . PaQager From venkat.boffin at gmail.com Wed Sep 18 01:12:18 2013 From: venkat.boffin at gmail.com (Venkat Addala) Date: Wed, 18 Sep 2013 10:42:18 +0530 Subject: Remove \n, " " from tuple. Message-ID: Hi all, I have a tuple in this format, which is retrived using MySQLdb, now i want to remove \n and extra spaces in this. 13L, 'ssDsC', 'CEs5s1, DsC', 'srylscetsmight\nghtscetylsse', '3', '3q25.1', 151531861L, 151546276L, '+', '1 kjafhkfhlad\fdfdsdf ghtscetylsse \ncontends the sctivity of dsfdk srylsmine N-scetyltrsnsfersse thst scts ss s cstslyst inbiotrsnsformstion fghjfg for srylsmine snd bvhghbh smine csrcinogens. Bgskjdg in ssDsC dfkdkdf in bresst snd prostrste csncer.', '', 'Msdhurs \nsgdfgssssvslingegowds', dstetime.dste(2013, 6, 14), None -- Regards Venkat Addala Computational Biologist O__ ---- _/ /`_ --- (*) \(*) -- -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at davea.name Wed Sep 18 05:03:29 2013 From: davea at davea.name (Dave Angel) Date: Wed, 18 Sep 2013 09:03:29 +0000 (UTC) Subject: Remove \n, " " from tuple. References: Message-ID: On 18/9/2013 01:12, Venkat Addala wrote: > Hi all, > > I have a tuple in this format, which is retrived using MySQLdb, now i want > to remove \n and extra spaces in this. > > 13L, 'ssDsC', 'CEs5s1, DsC', 'srylscetsmight\nghtscetylsse', '3', '3q25.1', > 151531861L, 151546276L, '+', '1 kjafhkfhlad\fdfdsdf ghtscetylsse \ncontends > the sctivity of dsfdk srylsmine N-scetyltrsnsfersse thst scts ss s cstslyst > inbiotrsnsformstion fghjfg for srylsmine snd bvhghbh smine csrcinogens. > Bgskjdg in ssDsC dfkdkdf in bresst snd prostrste csncer.', '', 'Msdhurs > \nsgdfgssssvslingegowds', dstetime.dste(2013, 6, 14), None > A tuple is immutable, so it cannot be done. However, you can create a new tuple. Easiest way is probably to convert it to a list, process any strings in the list, and convert it back. def convert(mylist): res = [] for item in mylist: if isinstance(item, str): item = ............ to be filled in res.append(item) return res mytuple = ..... temp = list(mytuple) mytuple = tuple(convert(temp)) -- DaveA From vlastimil.brom at gmail.com Wed Sep 18 05:50:49 2013 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Wed, 18 Sep 2013 11:50:49 +0200 Subject: Remove \n, " " from tuple. In-Reply-To: References: Message-ID: 2013/9/18 Venkat Addala > Hi all, > > I have a tuple in this format, which is retrived using MySQLdb, now i want > to remove \n and extra spaces in this. > > 13L, 'ssDsC', 'CEs5s1, DsC', 'srylscetsmight\nghtscetylsse', '3', > '3q25.1', 151531861L, 151546276L, '+', '1 kjafhkfhlad\fdfdsdf ghtscetylsse > \ncontends the sctivity of dsfdk srylsmine N-scetyltrsnsfersse thst scts ss > s cstslyst inbiotrsnsformstion fghjfg for srylsmine snd bvhghbh smine > csrcinogens. Bgskjdg in ssDsC dfkdkdf in bresst snd prostrste csncer.', '', > 'Msdhurs \nsgdfgssssvslingegowds', dstetime.dste(2013, 6, 14), None > > > > -- > Regards > Venkat Addala > Computational Biologist > O__ ---- > _/ /`_ --- > (*) \(*) -- > > > > -- > https://mail.python.org/mailman/listinfo/python-list > > Hi, you can create a new tuple with the converted elements from the original one using a list comprehension and the regular expression replacement, it could be e.g. >>> import re >>> tuple([re.sub(r"\s+", " ", element) if isinstance(element, str) else element for element in ("qw e", 1, 2, None, "U\nN IC", 'Q\tW E')]) ('qw e', 1, 2, None, 'U N IC', 'Q W E') >>> re.sub(...) replaces one or more whitespace characters (space, newline, tab ...) with a single space - the pattern can be tweaked as needed (e.g. the pattern r" *\n *| +" would only handle spaces and newlines explicitely). This replacement is only applied on string elements of the tuple, others are left unchanged if isinstance(element, str) is meant for python 3, for python 2 if isinstance(element, basestring) would be more appropriate the elements are collected in a list using this list comprehension and this intermediate list is finaly converted to a tuple if this immutable container is needed. hth, vbr -------------- next part -------------- An HTML attachment was scrubbed... URL: From mohsen at pahlevanzadeh.org Wed Sep 18 01:46:03 2013 From: mohsen at pahlevanzadeh.org (Mohsen Pahlevanzadeh) Date: Wed, 18 Sep 2013 10:16:03 +0430 Subject: QFrame and disable maximum attribute Message-ID: <1379483163.6014.17.camel@debian> Dear all, I need to disbale maximum attribute , and want to fix size of my QFrame, i set : sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) i attached my ui file , you can : pyuic4 -x myfile.ui -i output.py then see my attribute. Question: How can i disable for user to couldn't maximum and minimum attributes? Yours, Mohsen -------------- next part -------------- A non-text attachment was scrubbed... Name: materialsFindFrame.ui Type: application/x-designer Size: 15193 bytes Desc: not available URL: From nikhilpandey90 at gmail.com Wed Sep 18 07:12:05 2013 From: nikhilpandey90 at gmail.com (nikhil Pandey) Date: Wed, 18 Sep 2013 04:12:05 -0700 (PDT) Subject: iterating over a file with two pointers Message-ID: <3018b3d4-f914-4c89-9f26-cd4b2af32e73@googlegroups.com> hi, I want to iterate over the lines of a file and when i find certain lines, i need another loop starting from the next of that "CERTAIN" line till a few (say 20) lines later. so, basically i need two pointers to lines (one for outer loop(for each line in file)) and one for inner loop. How can i do that in python? please help. I am stuck up on this. From rosuav at gmail.com Wed Sep 18 07:21:51 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 18 Sep 2013 21:21:51 +1000 Subject: iterating over a file with two pointers In-Reply-To: <3018b3d4-f914-4c89-9f26-cd4b2af32e73@googlegroups.com> References: <3018b3d4-f914-4c89-9f26-cd4b2af32e73@googlegroups.com> Message-ID: On Wed, Sep 18, 2013 at 9:12 PM, nikhil Pandey wrote: > hi, > I want to iterate over the lines of a file and when i find certain lines, i need another loop starting from the next of that "CERTAIN" line till a few (say 20) lines later. > so, basically i need two pointers to lines (one for outer loop(for each line in file)) and one for inner loop. How can i do that in python? > please help. I am stuck up on this. After the inner loop finishes, do you want to go back to where the outer loop left off, or should the outer loop continue from the point where the inner loop stopped? In other words, do you want to locate overlapping sections, or not? Both are possible, but the solutions will look somewhat different. ChrisA From davea at davea.name Wed Sep 18 07:39:56 2013 From: davea at davea.name (Dave Angel) Date: Wed, 18 Sep 2013 11:39:56 +0000 (UTC) Subject: iterating over a file with two pointers References: <3018b3d4-f914-4c89-9f26-cd4b2af32e73@googlegroups.com> Message-ID: On 18/9/2013 07:21, Chris Angelico wrote: > On Wed, Sep 18, 2013 at 9:12 PM, nikhil Pandey wrote: >> hi, >> I want to iterate over the lines of a file and when i find certain lines, i need another loop starting from the next of that "CERTAIN" line till a few (say 20) lines later. >> so, basically i need two pointers to lines (one for outer loop(for each line in file)) and one for inner loop. How can i do that in python? >> please help. I am stuck up on this. > > After the inner loop finishes, do you want to go back to where the > outer loop left off, or should the outer loop continue from the point > where the inner loop stopped? In other words, do you want to locate > overlapping sections, or not? Both are possible, but the solutions > will look somewhat different. > In addition, is this really a text file? For binary files, you could use seek(), and manage things yourself. But that's not strictly legal in a text file, and may work on one system, not on another. I'd suggest you open the file twice, and get two file objects. Then you can iterate over them independently. Or if the file is under a few hundred meg, just do a readlines, and do the two iterators over that. That way, the inner loop could just iterate over a simple slice. infile = open(.... "rb") lines = infile.readlines() infile.close() for index, line in enumerate(lines): for inner in lines[index+1:20]: ... -- DaveA From roy at panix.com Wed Sep 18 08:56:18 2013 From: roy at panix.com (Roy Smith) Date: Wed, 18 Sep 2013 08:56:18 -0400 Subject: iterating over a file with two pointers References: <3018b3d4-f914-4c89-9f26-cd4b2af32e73@googlegroups.com> Message-ID: > > On Wed, Sep 18, 2013 at 9:12 PM, nikhil Pandey > > wrote: > >> hi, > >> I want to iterate over the lines of a file and when i find certain lines, > >> i need another loop starting from the next of that "CERTAIN" line till a > >> few (say 20) lines later. > >> so, basically i need two pointers to lines (one for outer loop(for each > >> line in file)) and one for inner loop. How can i do that in python? > >> please help. I am stuck up on this. > [...] In article , Dave Angel wrote: [I hope I unwound the multi-layer quoting right] > In addition, is this really a text file? For binary files, you could > use seek(), and manage things yourself. But that's not strictly legal > in a text file, and may work on one system, not on another. Why is seek() not legal on a text file? The only issue I'm aware of is the note at http://docs.python.org/2/library/stdtypes.html, which says: "On Windows, tell() can return illegal values (after an fgets()) when reading files with Unix-style line-endings. Use binary mode ('rb') to circumvent this problem." so, don't do that (i.e. read unix-line-terminated files on windows). But assuming you're not in that situation, it seems like something like this this should work: > I'd suggest you open the file twice, and get two file objects. Then you > can iterate over them independently. and use tell() to keep them in sync. Something along the lines of (not tested): f1 = open("my_file") f2 = open("my_file") while True: where = f1.tell() line = f1.readline() if not line: break if matches_pattern(line): f2.seek(where) for i in range(20): line = f2.readline() print line Except for the specific case noted above (i.e. reading a unix file on a windows box, so don't do that), it doesn't matter that seek() does funny things with windows line endings, because tell() does the same funny things. Doing f2.seek(f1.tell()) will get the two file pointers into the same place in both files. From oscar.j.benjamin at gmail.com Wed Sep 18 09:09:17 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 18 Sep 2013 14:09:17 +0100 Subject: iterating over a file with two pointers In-Reply-To: References: <3018b3d4-f914-4c89-9f26-cd4b2af32e73@googlegroups.com> Message-ID: On 18 September 2013 13:56, Roy Smith wrote: > >> > On Wed, Sep 18, 2013 at 9:12 PM, nikhil Pandey >> > wrote: >> >> hi, >> >> I want to iterate over the lines of a file and when i find certain lines, >> >> i need another loop starting from the next of that "CERTAIN" line till a >> >> few (say 20) lines later. >> >> so, basically i need two pointers to lines (one for outer loop(for each >> >> line in file)) and one for inner loop. How can i do that in python? >> >> please help. I am stuck up on this. >> [...] > > In article , > Dave Angel wrote: > [I hope I unwound the multi-layer quoting right] >> In addition, is this really a text file? For binary files, you could >> use seek(), and manage things yourself. But that's not strictly legal >> in a text file, and may work on one system, not on another. > > Why is seek() not legal on a text file? The only issue I'm aware of is > the note at http://docs.python.org/2/library/stdtypes.html, which says: > > "On Windows, tell() can return illegal values (after an fgets()) when > reading files with Unix-style line-endings. Use binary mode ('rb') to > circumvent this problem." > > so, don't do that (i.e. read unix-line-terminated files on windows). > But assuming you're not in that situation, it seems like something like > this this should work: > >> I'd suggest you open the file twice, and get two file objects. Then you >> can iterate over them independently. There's no need to use OS resources by opening the file twice or to screw up the IO caching with seek(). Peter's version holds just as many lines as is necessary in an internal Python buffer and performs the minimum possible amount of IO. I would expect this to be more efficient as well as less error-prone on Windows. Oscar From roy at panix.com Wed Sep 18 10:36:43 2013 From: roy at panix.com (Roy Smith) Date: Wed, 18 Sep 2013 10:36:43 -0400 Subject: iterating over a file with two pointers In-Reply-To: References: <3018b3d4-f914-4c89-9f26-cd4b2af32e73@googlegroups.com> Message-ID: <52B7F7EA-C7C4-4DB6-A93C-25F4C058EB58@panix.com> > Dave Angel wrote (and I agreed with): >> I'd suggest you open the file twice, and get two file objects. Then you >> can iterate over them independently. On Sep 18, 2013, at 9:09 AM, Oscar Benjamin wrote: > There's no need to use OS resources by opening the file twice or to > screw up the IO caching with seek(). There's no reason NOT to use OS resources. That's what the OS is there for; to make life easier on application programmers. Opening a file twice costs almost nothing. File descriptors are almost as cheap as whitespace. > Peter's version holds just as many lines as is necessary in an > internal Python buffer and performs the minimum possible > amount of IO. I believe by "Peter's version", you're talking about: > from itertools import islice, tee > > with open("tmp.txt") as f: > while True: > for outer in f: > print outer, > if "*" in outer: > f, g = tee(f) > for inner in islice(g, 3): > print " ", inner, > break > else: > break There's this note from http://docs.python.org/2.7/library/itertools.html#itertools.tee: > This itertool may require significant auxiliary storage (depending on how much temporary data needs to be stored). In general, if one iterator uses most or all of the data before another iterator starts, it is faster to use list() instead of tee(). I have no idea how that interacts with the pattern above where you call tee() serially. You're basically doing with open("my_file") as f: while True: f, g = tee(f) Are all of those g's just hanging around, eating up memory, while waiting to be garbage collected? I have no idea. But I do know that no such problems exist with the two file descriptor versions. > I would expect this to be more > efficient as well as less error-prone on Windows. > > > Oscar > --- Roy Smith roy at panix.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at davea.name Wed Sep 18 16:07:39 2013 From: davea at davea.name (Dave Angel) Date: Wed, 18 Sep 2013 20:07:39 +0000 (UTC) Subject: iterating over a file with two pointers References: <3018b3d4-f914-4c89-9f26-cd4b2af32e73@googlegroups.com> <52B7F7EA-C7C4-4DB6-A93C-25F4C058EB58@panix.com> Message-ID: On 18/9/2013 10:36, Roy Smith wrote: >> Dave Angel wrote (and I agreed with): >>> I'd suggest you open the file twice, and get two file objects. Then you >>> can iterate over them independently. > > > On Sep 18, 2013, at 9:09 AM, Oscar Benjamin wrote: >> There's no need to use OS resources by opening the file twice or to >> screw up the IO caching with seek(). > > There's no reason NOT to use OS resources. That's what the OS is there for; to make life easier on application programmers. Opening a file twice costs almost nothing. File descriptors are almost as cheap as whitespace. > >> Peter's version holds just as many lines as is necessary in an >> internal Python buffer and performs the minimum possible >> amount of IO. > > I believe by "Peter's version", you're talking about: > >> from itertools import islice, tee >> >> with open("tmp.txt") as f: >> while True: >> for outer in f: >> print outer, >> if "*" in outer: >> f, g = tee(f) >> for inner in islice(g, 3): >> print " ", inner, >> break >> else: >> break > > > There's this note from http://docs.python.org/2.7/library/itertools.html#itertools.tee: > >> This itertool may require significant auxiliary storage (depending on how much temporary data needs to be stored). In general, if one iterator uses most or all of the data before another iterator starts, it is faster to use list() instead of tee(). > > > I have no idea how that interacts with the pattern above where you call tee() serially. You're basically doing > > with open("my_file") as f: > while True: > f, g = tee(f) > > Are all of those g's just hanging around, eating up memory, while waiting to be garbage collected? I have no idea. But I do know that no such problems exist with the two file descriptor versions. > > > > > > >> I would expect this to be more >> efficient as well as less error-prone on Windows. >> >> >> Oscar >> > > > --- > Roy Smith > roy at panix.com > > > > > >
Dave Angel <davea at davea.name> wrote (and I agreed with):
I'd suggest you open the file twice, and get two file objects.  Then you
can iterate over them independently.

On Sep 18, 2013, at 9:09 AM, Oscar Benjamin wrote:
There's no need to use OS resources by opening the file twice or to
screw up the IO caching with seek().

There's no reason NOT to use OS resources.  That's what the OS is there for; to make life easier on application programmers.  Opening a file twice costs almost nothing.  File descriptors are almost as cheap as whitespace.

Peter's version holds just as many lines as is necessary in an
internal Python buffer and performs the minimum possible
amount of IO.

I believe by "Peter's version", you're talking about:

from itertools import islice, tee 

with open("tmp.txt") as f: 
    while True: 
        for outer in f: 
            print outer, 
            if "*" in outer: 
                f, g = tee(f) 
                for inner in islice(g, 3): 
                    print "   ", inner, 
                break 
        else: 
            break 


There's this note from http://docs.python.org/2.7/library/itertools.html#itertools.tee:

This itertool may require significant auxiliary storage (depending on how much temporary data needs to be stored). In general, if one iterator uses most or all of the data before another iterator starts, it is faster to use list() instead of tee().

I have no idea how that interacts with the pattern above where you call tee() serially.  You're basically doing

with open("my_file") as f:
while True:
f, g = tee(f)

Are all of those g's just hanging around, eating up memory, while waiting to be garbage collected?  I have no idea.  But I do know that no such problems exist with the two file descriptor versions.






I would expect this to be more
efficient as well as less error-prone on Windows.


Oscar


>

---
Roy Smith


>
>
> And if you're willing to ignore the possibility that the text file has unix line endings, I'm willing to ignore the possibility that the text file has a huge number of lines. Everything is MUCH simpler if one assumes readlines() will work. Most of these other approaches are much more complex than the OP probably needs, if he ever gets around to actually describing his requirements. BTW, please post in text, all that html is really annoying. -- DaveA From __peter__ at web.de Thu Sep 19 03:23:36 2013 From: __peter__ at web.de (Peter Otten) Date: Thu, 19 Sep 2013 09:23:36 +0200 Subject: iterating over a file with two pointers References: <3018b3d4-f914-4c89-9f26-cd4b2af32e73@googlegroups.com> <52B7F7EA-C7C4-4DB6-A93C-25F4C058EB58@panix.com> Message-ID: Roy Smith wrote: >> Dave Angel wrote (and I agreed with): >>> I'd suggest you open the file twice, and get two file objects. Then you >>> can iterate over them independently. > > > On Sep 18, 2013, at 9:09 AM, Oscar Benjamin wrote: >> There's no need to use OS resources by opening the file twice or to >> screw up the IO caching with seek(). > > There's no reason NOT to use OS resources. That's what the OS is there > for; to make life easier on application programmers. Opening a file twice > costs almost nothing. File descriptors are almost as cheap as whitespace. > >> Peter's version holds just as many lines as is necessary in an >> internal Python buffer and performs the minimum possible >> amount of IO. > > I believe by "Peter's version", you're talking about: > >> from itertools import islice, tee >> >> with open("tmp.txt") as f: >> while True: >> for outer in f: >> print outer, >> if "*" in outer: >> f, g = tee(f) >> for inner in islice(g, 3): >> print " ", inner, del g # a good idea in the general case >> break >> else: >> break > > > There's this note from > http://docs.python.org/2.7/library/itertools.html#itertools.tee: > >> This itertool may require significant auxiliary storage (depending on how >> much temporary data needs to be stored). In general, if one iterator uses >> most or all of the data before another iterator starts, it is faster to >> use list() instead of tee(). > > > I have no idea how that interacts with the pattern above where you call > tee() serially. As I understand it the above says that items = infinite() a, b = tee(items) for item in islice(a, 1000): pass for pair in izip(a, b): pass stores 1000 items and can go on forever, but items = infinite() a, b = tee(items) for item in a: pass will consume unbounded memory and that if items is finite using a list instead of tee is more efficient. The documentation says nothing about items = infinite() a, b = tee(items) del a for item in b: pass so you have to trust Mr Hettinger or come up with a test case... > You're basically doing > > with open("my_file") as f: > while True: > f, g = tee(f) > > Are all of those g's just hanging around, eating up memory, while waiting > to be garbage collected? I have no idea. I'd say you've just devised a nice test to find out ;) > But I do know that no such > problems exist with the two file descriptor versions. The trade-offs are different. My version works with arbitrary iterators (think stdin), but will consume unbounded amounts of memory when the inner loop doesn't stop. From oscar.j.benjamin at gmail.com Thu Sep 19 10:16:43 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 19 Sep 2013 15:16:43 +0100 Subject: iterating over a file with two pointers In-Reply-To: References: <3018b3d4-f914-4c89-9f26-cd4b2af32e73@googlegroups.com> <52B7F7EA-C7C4-4DB6-A93C-25F4C058EB58@panix.com> Message-ID: On 19 September 2013 08:23, Peter Otten <__peter__ at web.de> wrote: > Roy Smith wrote: >> >> I believe by "Peter's version", you're talking about: >> >>> from itertools import islice, tee >>> >>> with open("tmp.txt") as f: >>> while True: >>> for outer in f: >>> print outer, >>> if "*" in outer: >>> f, g = tee(f) >>> for inner in islice(g, 3): >>> print " ", inner, > del g # a good idea in the general case >>> break >>> else: >>> break >> >> There's this note from >> http://docs.python.org/2.7/library/itertools.html#itertools.tee: >> >>> This itertool may require significant auxiliary storage (depending on how >>> much temporary data needs to be stored). In general, if one iterator uses >>> most or all of the data before another iterator starts, it is faster to >>> use list() instead of tee(). This is referring to the case where your two iterators get out of sync by a long way. If you only consume 3 extra items it will just store those 3 items in a list. >> I have no idea how that interacts with the pattern above where you call >> tee() serially. Fair point. > > As I understand it the above says that > > items = infinite() > a, b = tee(items) > for item in islice(a, 1000): > pass > for pair in izip(a, b): > pass > > stores 1000 items and can go on forever, but > > items = infinite() > a, b = tee(items) > for item in a: > pass > > will consume unbounded memory and that if items is finite using a list > instead of tee is more efficient. The documentation says nothing about > > items = infinite() > a, b = tee(items) > del a > for item in b: > pass > > so you have to trust Mr Hettinger or come up with a test case... > >> You're basically doing >> >> with open("my_file") as f: >> while True: >> f, g = tee(f) >> >> Are all of those g's just hanging around, eating up memory, while waiting >> to be garbage collected? I have no idea. > > I'd say you've just devised a nice test to find out ;) $ cat tee.py #!/usr/bin/env python import sys from itertools import tee items = iter(range(int(sys.argv[1]))) while True: for x in items: items, discard = tee(items) break else: break print(x) $ time py -3.3 ./tee.py 100000000 99999999 real 1m47.711s user 0m0.015s sys 0m0.000s While running the above python.exe was using 6MB of memory (according to Task Manager). I believe this is because tee() works as follows (which I made up but it's how I imagine it). When you call tee(iterator) it creates two _tee objects and one _teelist object. The _teelist object stores all of the items that have been seen by only one of _tee1 and _tee2, a reference to iterator and a flag indicating which _tee object has seen more items. When say _tee2 is deallocated the _teelist becomes singly owned and no longer needs to ever accumulate items (so it doesn't). So the dereferenced discard will not cause an arbitrary growth in memory usage. There is a separate problem which is that if you call tee() multiple times then you end up with a chain of tees and each next call would go through each one of them. This would cause a linear growth in the time taken to call next() leading to quadratic time performance overall. However, this does not occur with the script I showed above. In principle it's possible for a _tee object to realise that there is a chain of singly owned _tee and _teelist objects and bypass them calling next() on the original iterator but I don't know if this is what happens. However, when I ran the above script on Python 2.7 it did consume massive amounts of memory (1.6GB) and ran slower so maybe this depends on optimisations that were introduced in 3.x. Here's an alternate iterator recipe that doesn't depend on these optimisations: from itertools import islice from collections import deque class Peekable(object): def __init__(self, iterable): self.iterator = iter(iterable) self.peeked = deque() def __iter__(self): while True: while self.peeked: yield self.peeked.popleft() yield next(self.iterator) def peek(self): for p in self.peeked: yield p for val in self.iterator: self.peeked.append(val) yield val with open("tmp.txt") as f: f = Peekable(f) for outer in f: print outer, if "*" in outer: for inner in islice(f.peek(), 3): print " ", inner, Oscar From __peter__ at web.de Thu Sep 19 10:38:08 2013 From: __peter__ at web.de (Peter Otten) Date: Thu, 19 Sep 2013 16:38:08 +0200 Subject: iterating over a file with two pointers References: <3018b3d4-f914-4c89-9f26-cd4b2af32e73@googlegroups.com> <52B7F7EA-C7C4-4DB6-A93C-25F4C058EB58@panix.com> Message-ID: Oscar Benjamin wrote: > $ cat tee.py > #!/usr/bin/env python > > import sys > from itertools import tee > > items = iter(range(int(sys.argv[1]))) > > while True: > for x in items: > items, discard = tee(items) > break > else: > break > > print(x) > > $ time py -3.3 ./tee.py 100000000 > 99999999 > > real 1m47.711s > user 0m0.015s > sys 0m0.000s > > While running the above python.exe was using 6MB of memory (according > to Task Manager). I believe this is because tee() works as follows > (which I made up but it's how I imagine it). [...] > However, when I ran the above script on Python 2.7 it did consume > massive amounts of memory (1.6GB) and ran slower so maybe this depends > on optimisations that were introduced in 3.x. Did you use xrange()? From oscar.j.benjamin at gmail.com Thu Sep 19 10:48:53 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 19 Sep 2013 15:48:53 +0100 Subject: iterating over a file with two pointers In-Reply-To: References: <3018b3d4-f914-4c89-9f26-cd4b2af32e73@googlegroups.com> <52B7F7EA-C7C4-4DB6-A93C-25F4C058EB58@panix.com> Message-ID: On 19 September 2013 15:38, Peter Otten <__peter__ at web.de> wrote: >> While running the above python.exe was using 6MB of memory (according >> to Task Manager). I believe this is because tee() works as follows >> (which I made up but it's how I imagine it). > > [...] > >> However, when I ran the above script on Python 2.7 it did consume >> massive amounts of memory (1.6GB) and ran slower so maybe this depends >> on optimisations that were introduced in 3.x. > > Did you use xrange()? No I didn't. :) Okay so it only uses 4.6MB of memory and it runs at the same speed: there's no problem with chaining tee objects as long as you discard them. If you don't discard them then a script like the one I wrote would quickly blow all the system memory. Oscar From __peter__ at web.de Wed Sep 18 07:44:10 2013 From: __peter__ at web.de (Peter Otten) Date: Wed, 18 Sep 2013 13:44:10 +0200 Subject: iterating over a file with two pointers References: <3018b3d4-f914-4c89-9f26-cd4b2af32e73@googlegroups.com> Message-ID: nikhil Pandey wrote: > hi, > I want to iterate over the lines of a file and when i find certain lines, > i need another loop starting from the next of that "CERTAIN" line till a > few (say 20) lines later. so, basically i need two pointers to lines (one > for outer loop(for each line in file)) and one for inner loop. How can i > do that in python? please help. I am stuck up on this. Here's an example that prints the three lines following a line containing a '*': Example data: $ cat tmp.txt alpha *beta *gamma delta epsilon zeta *eta The python script: $ cat tmp.py from itertools import islice, tee with open("tmp.txt") as f: while True: for outer in f: print outer, if "*" in outer: f, g = tee(f) for inner in islice(g, 3): print " ", inner, break else: break The script's output: $ python tmp.py alpha *beta *gamma delta epsilon *gamma delta epsilon zeta delta epsilon zeta *eta $ As you can see the general logic is relatively complex; it is likely that we can come up with a simpler solution if you describe your actual requirement in more detail. From nikhilpandey90 at gmail.com Wed Sep 18 08:07:58 2013 From: nikhilpandey90 at gmail.com (nikhil Pandey) Date: Wed, 18 Sep 2013 05:07:58 -0700 (PDT) Subject: iterating over a file with two pointers In-Reply-To: References: <3018b3d4-f914-4c89-9f26-cd4b2af32e73@googlegroups.com> Message-ID: On Wednesday, September 18, 2013 4:51:51 PM UTC+5:30, Chris Angelico wrote: > On Wed, Sep 18, 2013 at 9:12 PM, nikhil Pandey wrote: > > > hi, > > > I want to iterate over the lines of a file and when i find certain lines, i need another loop starting from the next of that "CERTAIN" line till a few (say 20) lines later. > > > so, basically i need two pointers to lines (one for outer loop(for each line in file)) and one for inner loop. How can i do that in python? > > > please help. I am stuck up on this. > > > > After the inner loop finishes, do you want to go back to where the > > outer loop left off, or should the outer loop continue from the point > > where the inner loop stopped? In other words, do you want to locate > > overlapping sections, or not? Both are possible, but the solutions > > will look somewhat different. > > > > ChrisA Hi Chris, After the inner loop finishes, I want to go back to the next line from where the outer loop was left i.e the lines of the inner loop will be traversed again in the outer loop. 1>>I iterate over lines of the file 2>> when i find a match in a certain line, i start another loop till some condition is met in the subsequent lines 3>> then i come back to where i left and repeat 1(ideally i want to delete that line in inner loop where that condition is met, but even if it is not deleted, its OK) From travisgriggs at gmail.com Wed Sep 18 12:18:54 2013 From: travisgriggs at gmail.com (Travis Griggs) Date: Wed, 18 Sep 2013 09:18:54 -0700 Subject: iterating over a file with two pointers In-Reply-To: References: <3018b3d4-f914-4c89-9f26-cd4b2af32e73@googlegroups.com> Message-ID: On Sep 18, 2013, at 5:07 AM, nikhil Pandey wrote: > On Wednesday, September 18, 2013 4:51:51 PM UTC+5:30, Chris Angelico wrote: >> On Wed, Sep 18, 2013 at 9:12 PM, nikhil Pandey wrote: >> >>> hi, >> >>> I want to iterate over the lines of a file and when i find certain lines, i need another loop starting from the next of that "CERTAIN" line till a few (say 20) lines later. >> >>> so, basically i need two pointers to lines (one for outer loop(for each line in file)) and one for inner loop. How can i do that in python? >> >>> please help. I am stuck up on this. >> >> >> >> After the inner loop finishes, do you want to go back to where the >> >> outer loop left off, or should the outer loop continue from the point >> >> where the inner loop stopped? In other words, do you want to locate >> >> overlapping sections, or not? Both are possible, but the solutions >> >> will look somewhat different. >> >> >> >> ChrisA > > Hi Chris, > After the inner loop finishes, I want to go back to the next line from where the outer loop was left i.e the lines of the inner loop will be traversed again in the outer loop. > 1>>I iterate over lines of the file > 2>> when i find a match in a certain line, i start another loop till some condition is met in the subsequent lines > 3>> then i come back to where i left and repeat 1(ideally i want to delete that line in inner loop where that condition is met, but even if it is not deleted, its OK) Just curious, do you really need two loops and file handles? Without better details about what you're really doing, but as you've provided more detail, it seems to me that just iterating the lines of the file, and using a latch boolean to indicate when you should do additional processing on lines might be easier. I modified Chris's example input to look like: alpha *beta gamma+ delta epsilon zeta *eta kappa tau pi+ omicron And then shot it with the following: #!/usr/bin/env python3 with open("samplein.txt") as file: reversing = False for line in (raw.strip() for raw in file): if reversing: print('____', line[::-1], '____') reversing = not line.endswith('+') else: print(line) reversing = line.startswith('*') Which begins reversing lines as its working through them, until a different condition is met. Travis Griggs From nikhilpandey90 at gmail.com Wed Sep 18 08:14:23 2013 From: nikhilpandey90 at gmail.com (nikhil Pandey) Date: Wed, 18 Sep 2013 05:14:23 -0700 (PDT) Subject: iterating over a file with two pointers In-Reply-To: References: <3018b3d4-f914-4c89-9f26-cd4b2af32e73@googlegroups.com> Message-ID: <0142cea2-e534-47d0-92fe-79a87068c497@googlegroups.com> On Wednesday, September 18, 2013 5:14:10 PM UTC+5:30, Peter Otten wrote: > nikhil Pandey wrote: > > > > > hi, > > > I want to iterate over the lines of a file and when i find certain lines, > > > i need another loop starting from the next of that "CERTAIN" line till a > > > few (say 20) lines later. so, basically i need two pointers to lines (one > > > for outer loop(for each line in file)) and one for inner loop. How can i > > > do that in python? please help. I am stuck up on this. > > > > Here's an example that prints the three lines following a line containing a > > '*': > > > > Example data: > > > > $ cat tmp.txt > > alpha > > *beta > > *gamma > > delta > > epsilon > > zeta > > *eta > > > > The python script: > > > > $ cat tmp.py > > from itertools import islice, tee > > > > with open("tmp.txt") as f: > > while True: > > for outer in f: > > print outer, > > if "*" in outer: > > f, g = tee(f) > > for inner in islice(g, 3): > > print " ", inner, > > break > > else: > > break > > > > The script's output: > > > > $ python tmp.py > > alpha > > *beta > > *gamma > > delta > > epsilon > > *gamma > > delta > > epsilon > > zeta > > delta > > epsilon > > zeta > > *eta > > $ > > > > As you can see the general logic is relatively complex; it is likely that we > > can come up with a simpler solution if you describe your actual requirement > > in more detail. hi, I want to iterate in the inner loop by reading each line till some condition is met.how can i do that. Thanks for this code. From __peter__ at web.de Wed Sep 18 08:54:42 2013 From: __peter__ at web.de (Peter Otten) Date: Wed, 18 Sep 2013 14:54:42 +0200 Subject: iterating over a file with two pointers References: <3018b3d4-f914-4c89-9f26-cd4b2af32e73@googlegroups.com> <0142cea2-e534-47d0-92fe-79a87068c497@googlegroups.com> Message-ID: nikhil Pandey wrote: > On Wednesday, September 18, 2013 5:14:10 PM UTC+5:30, Peter Otten wrote: > I want to iterate in the inner loop by reading each line till some > condition is met.how can i do that. Thanks for this code. That's not what I had in mind when I asked you to >> describe your actual requirement in more detail. Anyway, change [...] >> f, g = tee(f) >> for inner in islice(g, 3): >> print " ", inner, >> break [...] to f, g = tee(f) for inner in g: if some condition: break print " ", inner, break in my example. From steve+comp.lang.python at pearwood.info Wed Sep 18 22:40:23 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Sep 2013 02:40:23 GMT Subject: iterating over a file with two pointers References: <3018b3d4-f914-4c89-9f26-cd4b2af32e73@googlegroups.com> <0142cea2-e534-47d0-92fe-79a87068c497@googlegroups.com> Message-ID: <523a6417$0$29988$c3e8da3$5496439d@news.astraweb.com> On Wed, 18 Sep 2013 05:14:23 -0700, nikhil Pandey wrote: > I want to iterate in the inner loop by reading each line till some > condition is met.how can i do that. Thanks for this code. while not condition: read line Re-write using Python syntax, and you are done. -- Steven From steve+comp.lang.python at pearwood.info Wed Sep 18 22:56:04 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Sep 2013 02:56:04 GMT Subject: iterating over a file with two pointers References: <3018b3d4-f914-4c89-9f26-cd4b2af32e73@googlegroups.com> Message-ID: <523a67c3$0$29988$c3e8da3$5496439d@news.astraweb.com> On Wed, 18 Sep 2013 04:12:05 -0700, nikhil Pandey wrote: > hi, > I want to iterate over the lines of a file and when i find certain > lines, i need another loop starting from the next of that "CERTAIN" line > till a few (say 20) lines later. so, basically i need two pointers to > lines (one for outer loop(for each line in file)) and one for inner > loop. How can i do that in python? please help. I am stuck up on this. No, you don't "need" two pointers to lines. That is just one way to solve this problem. You can solve it many ways. One way, for small files (say, under one million lines), is to read the whole file into a list, then have two pointers to a line: lines = file.readlines() p = q = 0 while p < len(lines): print(lines[p]) p += 1 then advance the pointers p and q as needed. This is the most flexible way to do it: you can have as many pointers as needed, you can back- track, jump forward, jump back, and it is all high-speed random-access memory accesses. Except for the initial readlines, none of it is slow I/O processing. Another solution is to use a state-machine: for line in somefile: if state == SCANNING: do_something() elif state == PROCESSING: do_something_else() elif state == WOBBLING: wobble() state = adjust_state(line) You can combine the two, of course, and have a state machine with multiple pointers to a list of lines. Using itertools.tee, you can potentially combine these solutions with the straightforward for-loop over a list. The danger of itertools.tee is that it may use as much memory as reading the entire file into memory at once, but the benefit is that it may use much less. But personally, I find list- based processing with random-access by index much easier to understand that itertools.tee solutions. -- Steven From joshua at landau.ws Thu Sep 19 03:04:51 2013 From: joshua at landau.ws (Joshua Landau) Date: Thu, 19 Sep 2013 08:04:51 +0100 Subject: iterating over a file with two pointers In-Reply-To: <523a67c3$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <3018b3d4-f914-4c89-9f26-cd4b2af32e73@googlegroups.com> <523a67c3$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: Although "tee" is most certainly preferable because IO is far slower than the small amounts of memory "tee" will use, you do have this option: def iterate_file_lines(file): """ Iterate over lines in a file, unlike normal iteration this allows seeking. """ while True: line = thefile.readline() if not line: break yield line thefile = open("/tmp/thefile") thelines = iterate_file_lines(thefile) for line in thelines: print("Outer:", repr(line)) if is_start(line): outer_position = thefile.tell() for line in thelines: print("Inner:", repr(line)) if is_end(line): break thefile.seek(outer_position) It's simpler than having two files but probably not faster, "tee" will almost definitely be way better a choice (unless the subsections can't fit in memory) and it forfeits being able to change up the order of these things. If you want to change up the order to another defined order, you can think about storing the subsections, but if you want to support independent iteration you'll need to seek before every "readline" which is a bit silly. Basically, read it all into memory like Steven D'Aprano suggested. If you really don't want to, use "tee". If you can't handle non-constant memory usage (really? You're reading lines, man) I'd suggest my method. If you can't handle the inflexibility there, use multiple files. There, is that enough choices? From roy at panix.com Wed Sep 18 14:59:19 2013 From: roy at panix.com (Roy Smith) Date: Wed, 18 Sep 2013 14:59:19 -0400 Subject: lxml question -- creating an etree.Element attribute with ':' in the name Message-ID: I can create an Element with a 'foo' attribute by doing: etree.Element('my_node_name', foo="spam") But, how do I handle something like: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance", since "xmlns:xsi" isn't a valid python identifier? --- Roy Smith roy at panix.com From zachary.ware+pylist at gmail.com Wed Sep 18 15:07:33 2013 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Wed, 18 Sep 2013 14:07:33 -0500 Subject: lxml question -- creating an etree.Element attribute with ':' in the name In-Reply-To: References: Message-ID: On Wed, Sep 18, 2013 at 1:59 PM, Roy Smith wrote: > I can create an Element with a 'foo' attribute by doing: > > etree.Element('my_node_name', foo="spam") > > But, how do I handle something like: > > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance", since "xmlns:xsi" isn't a valid python identifier? > Try this: etree.Element('my_node_with_invalid_identifiers_name', **{'xmlns:xsi': 'spam'}) HTH, -- Zach From burak.arslan at arskom.com.tr Wed Sep 18 15:35:10 2013 From: burak.arslan at arskom.com.tr (Burak Arslan) Date: Wed, 18 Sep 2013 22:35:10 +0300 Subject: lxml question -- creating an etree.Element attribute with ':' in the name In-Reply-To: References: Message-ID: <523A006E.6050101@arskom.com.tr> On 09/18/13 21:59, Roy Smith wrote: > I can create an Element with a 'foo' attribute by doing: > > etree.Element('my_node_name', foo="spam") > > But, how do I handle something like: > > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance", since "xmlns:xsi" isn't a valid python identifier? > > xmlns: is a prefix with a special meaning: it defines an xml namespaces prefix. you should read about how they work. The following: Element('{http://www.w3.org/2001/XMLSchema-instance}my_node_name') will generate a proper xmlns declaration for you. It may not be the same every time, but it will do the job just as well. btw, if you need to generate xml schemas, have a look at spyne: http://spyne.io Specifically: https://github.com/arskom/spyne/blob/master/examples/xml/schema.py best, burak From stefan_ml at behnel.de Thu Sep 19 13:35:52 2013 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 19 Sep 2013 19:35:52 +0200 Subject: lxml question -- creating an etree.Element attribute with ':' in the name In-Reply-To: <523A006E.6050101@arskom.com.tr> References: <523A006E.6050101@arskom.com.tr> Message-ID: Burak Arslan, 18.09.2013 21:35: > On 09/18/13 21:59, Roy Smith wrote: >> I can create an Element with a 'foo' attribute by doing: >> >> etree.Element('my_node_name', foo="spam") >> >> But, how do I handle something like: >> >> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance", since "xmlns:xsi" isn't a valid python identifier? > > xmlns: is a prefix with a special meaning: it defines an xml namespaces > prefix. you should read about how they work. Absolutely. For the specific case of a namespaced attribute, one way to do it goes like this: el = etree.Element('my_node_name') el.set('{http://www.w3.org/2001/XMLSchema-instance}xsi', 'int') > The following: > > Element('{http://www.w3.org/2001/XMLSchema-instance}my_node_name') > > will generate a proper xmlns declaration for you. It may not be the same > every time, but it will do the job just as well. For this specific namespace, and also a couple of other well-known namespace URIs, lxml will use the "expected" prefix by default. Stefan From dieter at handshake.de Thu Sep 19 02:10:42 2013 From: dieter at handshake.de (dieter) Date: Thu, 19 Sep 2013 08:10:42 +0200 Subject: lxml question -- creating an etree.Element attribute with ':' in the name References: Message-ID: <871u4lpcil.fsf@handshake.de> Roy Smith writes: > But, how do I handle something like: > > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance", since "xmlns:xsi" isn't a valid python identifier? Read about "lxml"'s "namespace" support. From errol.anderson at gsds.co.nz Wed Sep 18 16:47:04 2013 From: errol.anderson at gsds.co.nz (Errol Anderson) Date: Thu, 19 Sep 2013 08:47:04 +1200 Subject: Python with Delphi Message-ID: <003d01ceb4b0$3d9c2490$b8d46db0$@gsds.co.nz> Is there anyone out there who uses Python with Delphi, or knows someone who uses Python with Delphi or who used to use Python with Delphi? The latest version of "Python for Delphi" (P4D) works fine with Python 2.5 and Delphi 2007, but not for Python 2.7. Any assistance gratefully received. Errol Anderson -------------- next part -------------- An HTML attachment was scrubbed... URL: From peter.cacioppi at gmail.com Wed Sep 18 19:54:00 2013 From: peter.cacioppi at gmail.com (Peter Cacioppi) Date: Wed, 18 Sep 2013 16:54:00 -0700 (PDT) Subject: mutlifile inheritance problem In-Reply-To: <9896e047.0203211303.741f695a@posting.google.com> References: <9896e047.0203211303.741f695a@posting.google.com> Message-ID: <9043161b-e193-482a-a90c-42e8dfae978c@googlegroups.com> This is a very old topic, but here is a trick for single inheritance. (The problem you allude to isn't restricted to multiple inheritance). Any class with a single parent simply defines this function. def mySuper(self) : return super(self.__class__, self) And then any parent function be referenced like self.mySuper().foo() This includes __init__. You can read more here. http://atlee.ca/blog/posts/blog20081121python-reload-danger-here-be-dragons.html On Thursday, March 21, 2002 2:03:23 PM UTC-7, Marc wrote: > I have classes defined in different files and would like to inherit > from a class in file A.py for a class in file B.py but am running into > problems. I'm using Python 1.5.2 on Windows NT > > Here's a specific example: > > ************************ > file cbase01.py: > > class CBase: > > def __init__(self): > self.cclass = None > print "cbase" > > class CImStream(CBase): > > def __init(self): > CBase.__init__(self) > print "CImStream" > > ************************* > in file wrappers_A01.py: > > import cbase01 > reload(cbase01) > > class ImStream_SavedBitmaps(cbase01.CImStream): > > def __init__(self): > cbase.CImStream.__init__(self) > print "SavedBitmaps" > > ************************** > in file sequencer01.py > > import cbase01 # the offending lines, program works > reload(cbase01) # if I comment these out. > > class Sequencer: > > def Append(self, item): > pass > > ***************************** > in test02.py > > import wrappers_A01 > reload(wrappers_A01) > > import sequencer01 > reload(sequencer01) > > x0 = wrappers_A01.ImStream_SavedBitmaps() > *************************************************************** > > If I run test02 I get the traceback > > Traceback (innermost last): > File "", line 1, in ? > File "D:\PythonCode\pna\eyeTracking\tests\test02.py", line 15, in ? > x0 = wrappers_A01.ImStream_SavedBitmaps() > File "D:\PythonCode\pna\eyeTracking\tests\wrappers_A01.py", line 21, > in __init__ > cbase.CImStream.__init__(self) > TypeError: unbound method must be called with class instance 1st > argument > > > Any ideas what I am doing wrong? > > Thanks, > Marc From peter.cacioppi at gmail.com Wed Sep 18 20:03:43 2013 From: peter.cacioppi at gmail.com (Peter Cacioppi) Date: Wed, 18 Sep 2013 17:03:43 -0700 (PDT) Subject: mutlifile inheritance problem In-Reply-To: <9043161b-e193-482a-a90c-42e8dfae978c@googlegroups.com> References: <9896e047.0203211303.741f695a@posting.google.com> <9043161b-e193-482a-a90c-42e8dfae978c@googlegroups.com> Message-ID: <6bea4bf3-d1a7-463a-8fca-0c90d4a28856@googlegroups.com> One more comment - my trick has some utility with multiple inheritance, but you really need to understand super() to and method resolution ordering in that case (as, I suppose, you ought to whenever you cross the Rubicon beyond single inheritance). So it's a nice trick but YMMV On Wednesday, September 18, 2013 4:54:00 PM UTC-7, Peter Cacioppi wrote: > This is a very old topic, but here is a trick for single inheritance. (The problem you allude to isn't restricted to multiple inheritance). > > > > Any class with a single parent simply defines this function. > > > > > > def mySuper(self) : > > return super(self.__class__, self) > > > > And then any parent function be referenced like > > self.mySuper().foo() > > > > This includes __init__. > > > > You can read more here. > > > > http://atlee.ca/blog/posts/blog20081121python-reload-danger-here-be-dragons.html > > > > > > On Thursday, March 21, 2002 2:03:23 PM UTC-7, Marc wrote: > > > I have classes defined in different files and would like to inherit > > > from a class in file A.py for a class in file B.py but am running into > > > problems. I'm using Python 1.5.2 on Windows NT > > > > > > Here's a specific example: > > > > > > ************************ > > > file cbase01.py: > > > > > > class CBase: > > > > > > def __init__(self): > > > self.cclass = None > > > print "cbase" > > > > > > class CImStream(CBase): > > > > > > def __init(self): > > > CBase.__init__(self) > > > print "CImStream" > > > > > > ************************* > > > in file wrappers_A01.py: > > > > > > import cbase01 > > > reload(cbase01) > > > > > > class ImStream_SavedBitmaps(cbase01.CImStream): > > > > > > def __init__(self): > > > cbase.CImStream.__init__(self) > > > print "SavedBitmaps" > > > > > > ************************** > > > in file sequencer01.py > > > > > > import cbase01 # the offending lines, program works > > > reload(cbase01) # if I comment these out. > > > > > > class Sequencer: > > > > > > def Append(self, item): > > > pass > > > > > > ***************************** > > > in test02.py > > > > > > import wrappers_A01 > > > reload(wrappers_A01) > > > > > > import sequencer01 > > > reload(sequencer01) > > > > > > x0 = wrappers_A01.ImStream_SavedBitmaps() > > > *************************************************************** > > > > > > If I run test02 I get the traceback > > > > > > Traceback (innermost last): > > > File "", line 1, in ? > > > File "D:\PythonCode\pna\eyeTracking\tests\test02.py", line 15, in ? > > > x0 = wrappers_A01.ImStream_SavedBitmaps() > > > File "D:\PythonCode\pna\eyeTracking\tests\wrappers_A01.py", line 21, > > > in __init__ > > > cbase.CImStream.__init__(self) > > > TypeError: unbound method must be called with class instance 1st > > > argument > > > > > > > > > Any ideas what I am doing wrong? > > > > > > Thanks, > > > Marc From ned at nedbatchelder.com Wed Sep 18 20:38:10 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 18 Sep 2013 20:38:10 -0400 Subject: mutlifile inheritance problem In-Reply-To: <9043161b-e193-482a-a90c-42e8dfae978c@googlegroups.com> References: <9896e047.0203211303.741f695a@posting.google.com> <9043161b-e193-482a-a90c-42e8dfae978c@googlegroups.com> Message-ID: <523A4772.8040903@nedbatchelder.com> On 9/18/13 7:54 PM, Peter Cacioppi wrote: > This is a very old topic, but here is a trick for single inheritance. (The problem you allude to isn't restricted to multiple inheritance). > > Any class with a single parent simply defines this function. > > > def mySuper(self) : > return super(self.__class__, self) > > And then any parent function be referenced like > self.mySuper().foo() You can't use self.__class__ for super, it won't give you the right class if you are using subclasses: class MyBase(object): def mySuper(self): return super(self.__class__, self) def say(self): print "This is MyBase!" class Thing(MyBase): def say_it(self): print "The parent:" self.mySuper().say() def say(self): print "this is Thing!" class SubThing(Thing): pass thing = Thing() thing.say_it() sub = SubThing() sub.say_it() This produces: The parent: This is MyBase! The parent: this is Thing! super() takes a class and an instance for a reason. If you could use self.__class__ for the class, then it would only take the instance. Super() needs to know the instance, but also needs to know the class it's being called from. --Ned. > This includes __init__. > > You can read more here. > > http://atlee.ca/blog/posts/blog20081121python-reload-danger-here-be-dragons.html > > > On Thursday, March 21, 2002 2:03:23 PM UTC-7, Marc wrote: >> I have classes defined in different files and would like to inherit >> from a class in file A.py for a class in file B.py but am running into >> problems. I'm using Python 1.5.2 on Windows NT >> >> Here's a specific example: >> >> ************************ >> file cbase01.py: >> >> class CBase: >> >> def __init__(self): >> self.cclass = None >> print "cbase" >> >> class CImStream(CBase): >> >> def __init(self): >> CBase.__init__(self) >> print "CImStream" >> >> ************************* >> in file wrappers_A01.py: >> >> import cbase01 >> reload(cbase01) >> >> class ImStream_SavedBitmaps(cbase01.CImStream): >> >> def __init__(self): >> cbase.CImStream.__init__(self) >> print "SavedBitmaps" >> >> ************************** >> in file sequencer01.py >> >> import cbase01 # the offending lines, program works >> reload(cbase01) # if I comment these out. >> >> class Sequencer: >> >> def Append(self, item): >> pass >> >> ***************************** >> in test02.py >> >> import wrappers_A01 >> reload(wrappers_A01) >> >> import sequencer01 >> reload(sequencer01) >> >> x0 = wrappers_A01.ImStream_SavedBitmaps() >> *************************************************************** >> >> If I run test02 I get the traceback >> >> Traceback (innermost last): >> File "", line 1, in ? >> File "D:\PythonCode\pna\eyeTracking\tests\test02.py", line 15, in ? >> x0 = wrappers_A01.ImStream_SavedBitmaps() >> File "D:\PythonCode\pna\eyeTracking\tests\wrappers_A01.py", line 21, >> in __init__ >> cbase.CImStream.__init__(self) >> TypeError: unbound method must be called with class instance 1st >> argument >> >> >> Any ideas what I am doing wrong? >> >> Thanks, >> Marc From steve+comp.lang.python at pearwood.info Wed Sep 18 22:05:26 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Sep 2013 02:05:26 GMT Subject: mutlifile inheritance problem References: <9896e047.0203211303.741f695a@posting.google.com> <9043161b-e193-482a-a90c-42e8dfae978c@googlegroups.com> Message-ID: <523a5be6$0$29988$c3e8da3$5496439d@news.astraweb.com> On Wed, 18 Sep 2013 20:38:10 -0400, Ned Batchelder wrote: > super() takes a class and an instance for a reason. If you could use > self.__class__ for the class, then it would only take the instance. > Super() needs to know the instance, but also needs to know the class > it's being called from. You're correct, of course, but I would word the reason why slightly differently. super needs to know which instance it is being called from, but it also needs to know which class the method is defined in. Hence, given: class Spam(Food): def method(self): print("Spam spam spam!") super(Spam, self).method() class PickledSpam(Spam): pass obj = PickledSpam() obj.method() super is being called from a PickledSpam instance, self, but the call is defined in the Spam class. super needs to know about both of them. Of course, this hinges on how one defines "called from". I think it is helpful to understand methods as being called from the instance doing the calling rather than the class where they are defined. -- Steven From peter.cacioppi at gmail.com Fri Sep 20 20:17:03 2013 From: peter.cacioppi at gmail.com (Peter Cacioppi) Date: Fri, 20 Sep 2013 17:17:03 -0700 (PDT) Subject: mutlifile inheritance problem In-Reply-To: <9896e047.0203211303.741f695a@posting.google.com> References: <9896e047.0203211303.741f695a@posting.google.com> Message-ID: On Thursday, March 21, 2002 2:03:23 PM UTC-7, Marc wrote: > I have classes defined in different files and would like to inherit > from a class in file A.py for a class in file B.py but am running into > problems. I'm using Python 1.5.2 on Windows NT > > Here's a specific example: > > ************************ > file cbase01.py: > > class CBase: > > def __init__(self): > self.cclass = None > print "cbase" > > class CImStream(CBase): > > def __init(self): > CBase.__init__(self) > print "CImStream" > > ************************* > in file wrappers_A01.py: > > import cbase01 > reload(cbase01) > > class ImStream_SavedBitmaps(cbase01.CImStream): > > def __init__(self): > cbase.CImStream.__init__(self) > print "SavedBitmaps" > > ************************** > in file sequencer01.py > > import cbase01 # the offending lines, program works > reload(cbase01) # if I comment these out. > > class Sequencer: > > def Append(self, item): > pass > > ***************************** > in test02.py > > import wrappers_A01 > reload(wrappers_A01) > > import sequencer01 > reload(sequencer01) > > x0 = wrappers_A01.ImStream_SavedBitmaps() > *************************************************************** > > If I run test02 I get the traceback > > Traceback (innermost last): > File "", line 1, in ? > File "D:\PythonCode\pna\eyeTracking\tests\test02.py", line 15, in ? > x0 = wrappers_A01.ImStream_SavedBitmaps() > File "D:\PythonCode\pna\eyeTracking\tests\wrappers_A01.py", line 21, > in __init__ > cbase.CImStream.__init__(self) > TypeError: unbound method must be called with class instance 1st > argument > > > Any ideas what I am doing wrong? > > Thanks, > Marc Yes my post has a mistake re: polymorphism. It seems self.__class__, whether called directly or indirectly, is always going to refer to the parent of the instance class. My code works only if there are no grandparents. Bummer, but glad to learn something new. It's too bad, I really lean on reload(). It appears to be incompatible with inheritance more than one level deep. From rosuav at gmail.com Fri Sep 20 23:28:40 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 21 Sep 2013 13:28:40 +1000 Subject: mutlifile inheritance problem In-Reply-To: References: <9896e047.0203211303.741f695a@posting.google.com> Message-ID: On Sat, Sep 21, 2013 at 10:17 AM, Peter Cacioppi wrote: > It's too bad, I really lean on reload(). It appears to be incompatible with inheritance more than one level deep. Python's really not designed for reload of this nature. You can easily make a nasty mess of things. If you're working in the interactive interpreter, it's probably easier to just run a stand-alone program and restart it every time; if you're actually trying to have an application that runs long-term and can reload code on the fly, you may want to consider a language that explicitly supports that (such as Pike). ChrisA From hbarvekar at ciphercloud.com Thu Sep 19 07:42:09 2013 From: hbarvekar at ciphercloud.com (harish.barvekar@gmail.com) Date: Thu, 19 Sep 2013 04:42:09 -0700 (PDT) Subject: subprocess call is not waiting. In-Reply-To: <505a018f$0$6946$e4fe514c@news2.news.xs4all.nl> References: <0b598d7f-7137-47cc-8eed-80ab450536c5@googlegroups.com> <0405db16-6a4c-4189-a32c-2311d45eead3@googlegroups.com> <28ih585cvob222k24v7ccfapgvav7nfgur@invalid.netcom.com> <5059c765$0$6952$e4fe514c@news2.news.xs4all.nl> <505a018f$0$6946$e4fe514c@news2.news.xs4all.nl> Message-ID: <6886842d-e89c-4ced-8502-fdaa250d1ac5@googlegroups.com> subprocess.call(tempFileName, shell=True).communicate() this process is not blocking. I want to make a blocking call to it. please help From tjreedy at udel.edu Thu Sep 19 15:58:44 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 19 Sep 2013 15:58:44 -0400 Subject: subprocess call is not waiting. In-Reply-To: <6886842d-e89c-4ced-8502-fdaa250d1ac5@googlegroups.com> References: <0b598d7f-7137-47cc-8eed-80ab450536c5@googlegroups.com> <0405db16-6a4c-4189-a32c-2311d45eead3@googlegroups.com> <28ih585cvob222k24v7ccfapgvav7nfgur@invalid.netcom.com> <5059c765$0$6952$e4fe514c@news2.news.xs4all.nl> <505a018f$0$6946$e4fe514c@news2.news.xs4all.nl> <6886842d-e89c-4ced-8502-fdaa250d1ac5@googlegroups.com> Message-ID: On 9/19/2013 7:42 AM, harish.barvekar at gmail.com wrote: > subprocess.call(tempFileName, shell=True).communicate() should raise an AttributeError as the int returned by subprocess.call does not have a .communicate method. > this process is not blocking. Why do you think that? All function calls block until the function returns, at which point blocking ceases. If you call Popen(someprog).communicate() and someprog runs quickly, you will hardly notice the blocking time. -- Terry Jan Reedy From asmbansal2 at gmail.com Thu Sep 19 11:28:26 2013 From: asmbansal2 at gmail.com (Aseem Bansal) Date: Thu, 19 Sep 2013 08:28:26 -0700 (PDT) Subject: A question about semantics from the standard library's documentation Message-ID: <5478c594-ef5b-4ebc-9d78-f8f12a3a6609@googlegroups.com> In Python 3.3.2 documentation on the Python Standard library's introduction these sentences are given "For these types, the Python language core defines the form of literals and places some constraints on their semantics, but does not fully define the semantics. (On the other hand, the language core does define syntactic properties like the spelling and priorities of operators.)" That got me confused. What is defined by the language and what is not? Can someone give me an example about what this means? From rosuav at gmail.com Thu Sep 19 11:55:09 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 20 Sep 2013 01:55:09 +1000 Subject: A question about semantics from the standard library's documentation In-Reply-To: <5478c594-ef5b-4ebc-9d78-f8f12a3a6609@googlegroups.com> References: <5478c594-ef5b-4ebc-9d78-f8f12a3a6609@googlegroups.com> Message-ID: On Fri, Sep 20, 2013 at 1:28 AM, Aseem Bansal wrote: > In Python 3.3.2 documentation on the Python Standard library's introduction these sentences are given > > "For these types, the Python language core defines the form of literals and places some constraints on their semantics, but does not fully define the semantics. (On the other hand, the language core does define syntactic properties like the spelling and priorities of operators.)" In future, a link would help :) http://docs.python.org/3/library/intro.html > That got me confused. What is defined by the language and what is not? > Can someone give me an example about what this means? The core language MUST be implemented in the "outer language" (C for CPython, Java for Jython... PyPy makes this a bit confusing, but there's still the same distinction). You can't write Python code to determine how to parse Python code. However, this core is actually quite small. It consists of everything necessary to actually parse your script (so, the indentation and tokenization rules, etc), plus enough classes to be able to handle literals (there needs to be a str to handle "Hello, world", for instance). Once the core is built, the rest of the language can be implemented in Python. That's the standard library. Quite a bit of CPython's stdlib is actually implemented in C, for performance; but huge slabs of it aren't, they're just Python code on par with the scripts you write yourself. They're part of the language ecosystem - if you claim you "know Python", you have to know at least something about the stdlib - but it's much more easily tinkered with, since you can just drop in a replacement bit of Python. Take the hex() built-in function as an example. I can replace it[1] by simply creating my own function with the same name: >>> def hex(x): return x+curse(x)-sanity() It's not hard to roll your own hex() if you want to (base conversion is easy enough). So hex() needn't be part of the core language, but can simply be provided by a bit of Python code that gets imported automatically. In contrast, the 'def' statement MUST be provided by the core language. You can't create a function that gives you the ability to create functions! You also can't create the + operator, although it's conceivable to have a language that grants user-level code that power; in Python, at least, all operators are language features. However, the exact behaviour of that + operator can be customized in Python, using magic methods. That's the main difference between the core language and the standard library - the stdlib could be, even if it isn't, implemented in the language itself. ChrisA [1] This example just shadows the name, but near enough. Fiddling with __builtins__ is a better "replacement", but it comes to the same thing. From tjreedy at udel.edu Thu Sep 19 16:27:33 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 19 Sep 2013 16:27:33 -0400 Subject: A question about semantics from the standard library's documentation In-Reply-To: <5478c594-ef5b-4ebc-9d78-f8f12a3a6609@googlegroups.com> References: <5478c594-ef5b-4ebc-9d78-f8f12a3a6609@googlegroups.com> Message-ID: On 9/19/2013 11:28 AM, Aseem Bansal wrote: > In Python 3.3.2 documentation on the Python Standard library's introduction these sentences are given > > "For these types, the Python language core defines the form of literals and places some constraints on their semantics, but does not fully define the semantics. (On the other hand, the language core does define syntactic properties like the spelling and priorities of operators.)" The two preceeding sentences are "The ?Python library? contains several different kinds of components. It contains data types that would normally be considered part of the ?core? of a language, such as numbers and lists." > That got me confused. What is defined by the language and what is not? > Can someone give me an example about what this means? Take ints. The language manual specific the form of int literals. It specifies the operations in general terms of 'integers'. It specifies the precedence of the operators. It does not actually specify the meaning (semantics) of m + n. You are safe in assuming that (int)2 + (int)2 = (int)4. However type(2**31) is different on 2.7- 32-bit builds (long) and 3.0+ (always int). Also note that the language reference does not specify the int methods other than the special methods needed to implement the operators. -- Terry Jan Reedy From gary719_list1 at verizon.net Thu Sep 19 12:04:57 2013 From: gary719_list1 at verizon.net (Gary Roach) Date: Thu, 19 Sep 2013 09:04:57 -0700 Subject: django admin.py error Message-ID: <523B20A9.6060207@verizon.net> Installation of the django admin.py package worked fine. But. when I tried to add my database to the admin page I get the following error: ImportError at /admin/ cannot import name membership Request Method: GET Request URL: http://127.0.0.1:8000/admin/ Django Version: 1.5.2 Exception Type: ImportError Exception Value: cannot import name membership Exception Location: /home/gary/ProgramFiles/mysite/mysite/admin.py in , line 4 Python Executable: /usr/bin/python Python Version: 2.7.3 Python Path: ['/home/gary/ProgramFiles/mysite/mysite', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PIL', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7', '/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode'] My admin.py file is: #Adding this app to the admin page. from django.contrib import admin from mysite.models import membership, address, status, audio, video, photos admin.site.register(membership) admin.site.register(address) admin.site.register(status) admin.site.register(audio) admin.site.register(video) admin.site.register(photos) I can't seem to locate the source of the problem. Everything seems to be installed properly. Any help will be sincerely appreciated. Gary R From gordon at panix.com Thu Sep 19 14:15:02 2013 From: gordon at panix.com (John Gordon) Date: Thu, 19 Sep 2013 18:15:02 +0000 (UTC) Subject: django admin.py error References: Message-ID: In Gary Roach writes: > Installation of the django admin.py package worked fine. But. when I > tried to add my database to the admin page I get the following error: > ImportError at /admin/ > cannot import name membership > ['/home/gary/ProgramFiles/mysite/mysite', > My admin.py file is: > #Adding this app to the admin page. > from django.contrib import admin > from mysite.models import membership, address, status, audio, video, > photos Does /home/gary/ProgramFiles/mysite/mysite/models.py define an object named 'membership'? -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From gary719_list1 at verizon.net Thu Sep 19 14:49:14 2013 From: gary719_list1 at verizon.net (Gary Roach) Date: Thu, 19 Sep 2013 11:49:14 -0700 Subject: django admin.py error In-Reply-To: References: Message-ID: <523B472A.8040604@verizon.net> On 09/19/2013 11:15 AM, John Gordon wrote: > In Gary Roach writes: > >> Installation of the django admin.py package worked fine. But. when I >> tried to add my database to the admin page I get the following error: > ImportError at /admin/ > Does /home/gary/ProgramFiles/mysite/mysite/models.py define an object > named 'membership'? > Yes. The following is the top part of the models.py file: q from __future__ import unicode_literals from django.db import models class Membership(models.Model): id_membership = models.IntegerField(unique=True, primary_key=True) first_name = models.CharField(max_length=20L, blank=True) middle_name = models.CharField(max_length=20L, blank=True) last_name = models.CharField(max_length=20L, blank=True) born = models.DateField(null=True, blank=True) born_date_accuracy = models.CharField(max_length=8L, blank=True) died = models.DateField(null=True, blank=True) died_date_accuracy = models.CharField(max_length=8L, blank=True) photo_url = models.CharField(max_length=200L, db_column='photo_URL', blank=True) # Field name made lowercase. class Meta: db_table = 'membership' class Address(models.Model): id_address = models.IntegerField(unique=True, primary_key=True) street = models.CharField(max_length=45L, blank=True) city = models.CharField(max_length=45L, blank=True) state = models.CharField(max_length=45L, blank=True) class Meta: db_table = 'address' class AddressHasMembership(models.Model): address_id_address = models.ForeignKey(Address, db_column='address_id_address') membership_id_membership = models.ForeignKey('Membership', db_column='membership_id_member ship') class Meta: db_table = 'address_has_membership' I hope this helps. Thanks for the reply Gary R -------------- next part -------------- An HTML attachment was scrubbed... URL: From gordon at panix.com Thu Sep 19 14:56:51 2013 From: gordon at panix.com (John Gordon) Date: Thu, 19 Sep 2013 18:56:51 +0000 (UTC) Subject: django admin.py error References: Message-ID: In Gary Roach writes: > On 09/19/2013 11:15 AM, John Gordon wrote: > > Does /home/gary/ProgramFiles/mysite/mysite/models.py define an object > > named 'membership'? > Yes. The following is the top part of the models.py file: q > class Membership(models.Model): > id_membership = models.IntegerField(unique=True, primary_key=True) I see something named 'Membership', but nothing named 'membership'. Python names are case-sensitive. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From gary719_list1 at verizon.net Thu Sep 19 15:33:26 2013 From: gary719_list1 at verizon.net (Gary Roach) Date: Thu, 19 Sep 2013 12:33:26 -0700 Subject: django admin.py error (solved) In-Reply-To: References: Message-ID: <523B5186.7020809@verizon.net> On 09/19/2013 11:56 AM, John Gordon wrote: > In Gary Roach writes: > >> On 09/19/2013 11:15 AM, John Gordon wrote: >>> Does /home/gary/ProgramFiles/mysite/mysite/models.py define an object >>> named 'membership'? >> Yes. The following is the top part of the models.py file: q >> class Membership(models.Model): >> id_membership = models.IntegerField(unique=True, primary_key=True) > I see something named 'Membership', but nothing named 'membership'. > Python names are case-sensitive. > Stupid stupid stupid. Thanks. You would think that after working with Linux for over 10 years that I wouldn't pull such a stunt. Thanks. Everything now working fine. Gary R From random832 at fastmail.us Thu Sep 19 12:33:53 2013 From: random832 at fastmail.us (random832 at fastmail.us) Date: Thu, 19 Sep 2013 12:33:53 -0400 Subject: Bug tracker breaks when given a username with an uppercase letter Message-ID: <1379608433.25549.24038441.43FFC905@webmail.messagingengine.com> Registration appears to succeed, but does not allow login, and I can't tell if email confirmation worked or not. I was able to register by changing it to lowercase, but I had to guess what was happening. From tjreedy at udel.edu Thu Sep 19 16:30:09 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 19 Sep 2013 16:30:09 -0400 Subject: Bug tracker breaks when given a username with an uppercase letter In-Reply-To: <1379608433.25549.24038441.43FFC905@webmail.messagingengine.com> References: <1379608433.25549.24038441.43FFC905@webmail.messagingengine.com> Message-ID: On 9/19/2013 12:33 PM, random832 at fastmail.us wrote: > Registration appears to succeed, but does not allow login, and I can't > tell if email confirmation worked or not. I was able to register by > changing it to lowercase, but I had to guess what was happening. Odd. There are existing usernames with uppercase. -- Terry Jan Reedy From gogobebe2 at gmail.com Thu Sep 19 14:46:22 2013 From: gogobebe2 at gmail.com (William Bryant) Date: Thu, 19 Sep 2013 11:46:22 -0700 (PDT) Subject: Why does it have red squiggly lines under it if it works perfectly fine and no errors happen when I run it? Message-ID: <22b99b0a-598f-4500-9de9-5041c2ce2c8f@googlegroups.com> the word 'def' has squiggily lines but the program works fine. It says: Syntax Error: expected an indented block. - why? def restart(): print(""" ~~~~~~~~~~~~~~~~ Cacluation DONE! ~~~~~~~~~~~~~~~~ """) restart = input("\nEnter yes if you want to make a new list and no if you want to close the program (yes/no): ") restart if restart == "yes" or restart == "y" or restart == "new list": print("You want make a new list...\n") time.sleep(1) NOS() elif restart == "no" or restart == "n" or restart == "close": print("Goodbye!") time.sleep(1) print("Goodbye!") time.sleep(1) print("Goodbye!") time.sleep(1) print("Goodbye!") time.sleep(1) print("Goodbye!") time.sleep(1) quit() else: print("type y or n") time.sleep(0.5) restart() From gordon at panix.com Thu Sep 19 14:51:59 2013 From: gordon at panix.com (John Gordon) Date: Thu, 19 Sep 2013 18:51:59 +0000 (UTC) Subject: Why does it have red squiggly lines under it if it works perfectly fine and no errors happen when I run it? References: <22b99b0a-598f-4500-9de9-5041c2ce2c8f@googlegroups.com> Message-ID: In <22b99b0a-598f-4500-9de9-5041c2ce2c8f at googlegroups.com> William Bryant writes: > the word 'def' has squiggily lines but the program works fine. It says: > Syntax Error: expected an indented block. - why? > def restart(): This may be caused by the code before 'def'. Post the whole program. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From patrick.vrijlandt at gmail.com Thu Sep 19 15:08:55 2013 From: patrick.vrijlandt at gmail.com (patrick vrijlandt) Date: 19 Sep 2013 19:08:55 GMT Subject: Why does it have red squiggly lines under it if it works perfectly fine and no errors happen when I run it? References: <22b99b0a-598f-4500-9de9-5041c2ce2c8f@googlegroups.com> Message-ID: <188912050401310416.716816patrick.vrijlandt-gmail.com@newszilla.xs4all.nl> John Gordon wrote: > In <22b99b0a-598f-4500-9de9-5041c2ce2c8f at googlegroups.com> William Bryant > writes: > >> the word 'def' has squiggily lines but the program works fine. It says: >> Syntax Error: expected an indented block. - why? > >> def restart(): > > This may be caused by the code before 'def'. Post the whole program. It may also have to do with having both tabs and spaces in one source file. Python cannot recognise the indentation if you do that. Replace al tabs by 4 spaces. -- patrick From ian.g.kelly at gmail.com Thu Sep 19 15:01:02 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 19 Sep 2013 13:01:02 -0600 Subject: Why does it have red squiggly lines under it if it works perfectly fine and no errors happen when I run it? In-Reply-To: <22b99b0a-598f-4500-9de9-5041c2ce2c8f@googlegroups.com> References: <22b99b0a-598f-4500-9de9-5041c2ce2c8f@googlegroups.com> Message-ID: Syntactically, it looks fine. I would guess the problem is with whatever editor you are using. Or as John noted, it could be caused by the code above it. I do see an unrelated bug in there, though. You are using the name "restart" both for a string entered by the user and for the name of the function, which is called recursively. The name for the string, which is local, shadows the name for the function, which is global. So if the program ever hits the third branch of the if statement you will get an error. Python doesn't optimize tail-recursion, so you would get a different error if the user hit that branch enough times (around 1000) consecutively, as the interpreter hits the stack limit. For example, if they just held down the Enter key for a while. So this looping would be better accomplished with a while True loop and break statements than with recursion. On Thu, Sep 19, 2013 at 12:46 PM, William Bryant wrote: > the word 'def' has squiggily lines but the program works fine. It says: Syntax Error: expected an indented block. - why? > > def restart(): > print(""" > > ~~~~~~~~~~~~~~~~ > > Cacluation DONE! > > ~~~~~~~~~~~~~~~~ > > """) > restart = input("\nEnter yes if you want to make a new list and no if you want to close the program (yes/no): ") > restart > if restart == "yes" or restart == "y" or restart == "new list": > print("You want make a new list...\n") > time.sleep(1) > NOS() > elif restart == "no" or restart == "n" or restart == "close": > print("Goodbye!") > time.sleep(1) > print("Goodbye!") > time.sleep(1) > print("Goodbye!") > time.sleep(1) > print("Goodbye!") > time.sleep(1) > print("Goodbye!") > time.sleep(1) > quit() > else: > print("type y or n") > time.sleep(0.5) > restart() > -- > https://mail.python.org/mailman/listinfo/python-list From ian.g.kelly at gmail.com Thu Sep 19 19:09:03 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 19 Sep 2013 17:09:03 -0600 Subject: Why does it have red squiggly lines under it if it works perfectly fine and no errors happen when I run it? In-Reply-To: References: <22b99b0a-598f-4500-9de9-5041c2ce2c8f@googlegroups.com> Message-ID: On Thu, Sep 19, 2013 at 1:22 PM, William Bryant wrote: > It was the other functions above it. Thanks. but I tried to do the while > loop - I don't think I did it right, I am novice in python and I am 13 years > old. It should be structured like this: while True: answer = input("Enter yes/no:") if answer in ('y', 'yes', 'new list'): do_yes_stuff() break elif answer in ('n', 'no', 'close'): do_no_stuff() break else: print("Please enter y or n.") If they answer 'yes' or 'no', then the break statement breaks out of the while loop. Otherwise the while loop continues from the top and asks them again. From gogobebe2 at gmail.com Fri Sep 20 03:01:20 2013 From: gogobebe2 at gmail.com (William Bryant) Date: Fri, 20 Sep 2013 00:01:20 -0700 (PDT) Subject: Why does it have red squiggly lines under it if it works perfectly fine and no errors happen when I run it? In-Reply-To: References: <22b99b0a-598f-4500-9de9-5041c2ce2c8f@googlegroups.com> Message-ID: <24104d3b-ad83-4c15-bb9e-77b61a0bac78@googlegroups.com> On Friday, September 20, 2013 11:09:03 AM UTC+12, Ian wrote: > On Thu, Sep 19, 2013 at 1:22 PM, William Bryant wrote: > > > It was the other functions above it. Thanks. but I tried to do the while > > > loop - I don't think I did it right, I am novice in python and I am 13 years > > > old. > > > > It should be structured like this: > > > > while True: > > answer = input("Enter yes/no:") > > if answer in ('y', 'yes', 'new list'): > > do_yes_stuff() > > break > > elif answer in ('n', 'no', 'close'): > > do_no_stuff() > > break > > else: > > print("Please enter y or n.") > > > > If they answer 'yes' or 'no', then the break statement breaks out of > > the while loop. Otherwise the while loop continues from the top and > > asks them again. Thanks a lot! I have one more question, is there any way I can make my program work on android tablets and ipads? Because I'd like to use it in school because we are learning statistics and we are allowed our devices in school. '''**************************************************************************''' #* Name: Mode-Median-Mean Calculator *# #* *# #* Purpose: To calculate the mode, median and mean of a list of numbers *# #* and the mode of a list of strings because that is what we are *# #* learning in math atm in school :P *# #* *# #* Author: William Bryant *# #* *# #* Created: 11/09/2013 *# #* *# #* Copyright: (c) William 2013 *# #* *# #* Licence: IDK :3 *# '''**************************************************************************''' #-----# ~~Import things I am using~~ #-----# # | # | # \/ import time import itertools #-----# ~~Variables that I am using, including the list.~~ #-----# # | # | # \/ List = [] NumberOfXItems = [] #-----# ~~Functions that I am using.~~ #-----# # | # | # \/ def HMNs(): global TheStr, user_inputHMNs, List_input, List user_inputHMNs = input("You picked string. This program cannot calculate the mean or median, but it can calculate the mode. :D How many strings are you using in your list? (Can not be a decimal number) \nEnter: ") if user_inputHMNs == "restart": NOS() time.sleep(1.5) TheStr = int(user_inputHMNs) for i in range(TheStr): List_input = input("Enter your strings. (One in each input field): \n") if List_input == "restart": NOS() List.append(List_input) print("############################################################################\nThis is the amount of strings you are using in your list:", user_inputHMNs) print("and this is how much space you have left in your list for strings:", int(user_inputHMNs) - len(List), "\n################################################################################\n") print("Your list -> ", List) print("(0 is the first number in your list)\n") for i in range(len(List)): print("number " + str(i) + ": " + str(List[i])) print("\n*Mode*:", mode()) print("*Median*:", "There is no median for a list of strings - Only mode") print("*Mean*:", "There is no mean for a list of strings - Only mode") if int(user_inputHMNs) - len(List) == 0: init() def HMNn(): global TheNum, user_inputHMNn, List_input, List user_inputHMNn = input("You picked number. :D How many numbers are you using in your list? (Can not be a decimal number) \nEnter: ") if user_inputHMNn == "restart": NOS() time.sleep(1.5) TheNum = int(user_inputHMNn) for i in range(TheNum): List_input = input("Enter your numbers. (One in each input field): \n") List_input = int(List_input) if List_input == "restart": NOS() List.append(List_input) print("############################################################################\nThis is the amount of numbers you are using in your list:", user_inputHMNn) print("and this is how much space you have left in your list for numbers:", int(user_inputHMNn) - len(List), "\n################################################################################\n") print("Your list -> ", List) print("(0 is the first number in your list)\n") for i in range(len(List)): print("number " + str(i) + ": " + str(List[i])) print("\n*Mode*:", mode()) print("*Median*:", "") print("*Mean*:", mean(), "\n") if int(user_inputHMNn) - len(List) == 0: init() def NOS(): print("Loading...\n") time.sleep(2.5) while True: # Loops forever (until the break) answer = input("Does your list contain a number or a string? \nEnter: ") answer = answer.lower() if answer in ("string", "str", "s"): HMNs() break elif answer in ("number", "num", "n", "int"): HMNn() break elif answer in ("quit", "q"): break # Exits the while loop else: print("You did not enter a valid field, :P Sorry. \nEnter: ") time.sleep(1.5) if answer == "restart": NOS() def mean(): thesum = sum(List) amount = len(List) themean = thesum / amount return themean def mode(): max_occurrences = 0 themode = None for i in List: thecount = List.count(i) if thecount > max_occurrences: max_occurrences = thecount themode = i return themode def median(): pass def init(): print(""" ~~~~~~~~~~~~~~~~ Cacluation DONE! ~~~~~~~~~~~~~~~~ """) while "lol" == "lol": restart = input("\nEnter yes if you want to make a new list and no if you want to close the program (yes/no): ") if restart in ('y', 'yes', 'new list'): print("You want make a new list...\n") time.sleep(1) NOS() break elif restart in ('n', 'no', 'close'): for i in range(6): print("""Goodbye! Thanks you for using my program! - William Bryant (AKA gogobebe2)""") time.sleep(1) quit() else: print("type y or n") time.sleep(0.5) init() #-----# ~~The functions which need calling~~ #-----# # | # | # \/ NOS() Thanks again - Will From wrw at mac.com Fri Sep 20 09:04:56 2013 From: wrw at mac.com (William Ray Wing) Date: Fri, 20 Sep 2013 09:04:56 -0400 Subject: Why does it have red squiggly lines under it if it works perfectly fine and no errors happen when I run it? In-Reply-To: <24104d3b-ad83-4c15-bb9e-77b61a0bac78@googlegroups.com> References: <22b99b0a-598f-4500-9de9-5041c2ce2c8f@googlegroups.com> <24104d3b-ad83-4c15-bb9e-77b61a0bac78@googlegroups.com> Message-ID: <63F85C58-0FF3-4AF0-AF76-A47183EBA0A9@mac.com> On Sep 20, 2013, at 3:01 AM, William Bryant wrote: [byte] > > Thanks a lot! I have one more question, is there any way I can make my program work on android tablets and ipads? Because I'd like to use it in school because we are learning statistics and we are allowed our devices in school. > > [byte] > > Thanks again - Will > Python doesn't come pre-installed on tablets the way it does on most computers. However, there are low-cost commercial python apps for tablets. The one I'm most familiar with is Pythonista, available for the iPad in the Apple App store. Last time I looked it was $6.95. Bill From duncan.booth at invalid.invalid Fri Sep 20 09:39:41 2013 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 20 Sep 2013 13:39:41 GMT Subject: Why does it have red squiggly lines under it if it works perfectly fine and no errors happen when I run it? References: <22b99b0a-598f-4500-9de9-5041c2ce2c8f@googlegroups.com> <24104d3b-ad83-4c15-bb9e-77b61a0bac78@googlegroups.com> Message-ID: William Bryant wrote: > Thanks a lot! I have one more question, is there any way I can make my > program work on android tablets and ipads? Because I'd like to use it > in school because we are learning statistics and we are allowed our > devices in school. > You can install SL4A on Android and that should let you run your script on an Android tablet. You may want to modify the script to work with the android UI, or it might be enough just to run it in a terminal window. I don't believe there is an ipad equivalent, but so long as you have a network connection, another option to consider (that would work on both android and ipad) would be to run the script on a server somewhere and connect to it through a web browser. Have a look at https://c9.io as that gives you a full development environment that can be accessed through a web browser: I don't know how well it works on a tablet but it would be worth trying. -- Duncan Booth http://kupuguy.blogspot.com From gogobebe2 at gmail.com Sat Sep 21 01:59:57 2013 From: gogobebe2 at gmail.com (William Bryant) Date: Fri, 20 Sep 2013 22:59:57 -0700 (PDT) Subject: Why does it have red squiggly lines under it if it works perfectly fine and no errors happen when I run it? In-Reply-To: References: <22b99b0a-598f-4500-9de9-5041c2ce2c8f@googlegroups.com> <24104d3b-ad83-4c15-bb9e-77b61a0bac78@googlegroups.com> Message-ID: <017a5d0b-1e76-4a0f-94ad-03c6e7a00d57@googlegroups.com> On Saturday, September 21, 2013 1:39:41 AM UTC+12, Duncan Booth wrote: > William Bryant wrote: > > > > > Thanks a lot! I have one more question, is there any way I can make my > > > program work on android tablets and ipads? Because I'd like to use it > > > in school because we are learning statistics and we are allowed our > > > devices in school. > > > > > > > You can install SL4A on Android and that should let you run your script on > > an Android tablet. You may want to modify the script to work with the > > android UI, or it might be enough just to run it in a terminal window. > > > > I don't believe there is an ipad equivalent, but so long as you have a > > network connection, another option to consider (that would work on both > > android and ipad) would be to run the script on a server somewhere and > > connect to it through a web browser. Have a look at https://c9.io as that > > gives you a full development environment that can be accessed through a web > > browser: I don't know how well it works on a tablet but it would be worth > > trying. > > > > > > -- > > Duncan Booth http://kupuguy.blogspot.com Ok thanks for that, I know I said 1 more question but I just made the median function, could u tell me how I could finish it? I can't think of a way: def median(): medlist = List medlist.sort() if len(List) % 2: while len(list) > 2: medlist.popleft() medlist.popright() if medlist[0] == medlist[1]: themedian = medlist elif medlist[0] != medlist[1]: #make an if statment to figure out the median if the last 2 left are not the same. Eg [1, 2] the middle value is 1.5 pass else: while len(medlist) > 1: medlist.popleft() medlist.popright() themedian = medlist return themedian From gogobebe2 at gmail.com Sat Sep 21 02:07:57 2013 From: gogobebe2 at gmail.com (William Bryant) Date: Fri, 20 Sep 2013 23:07:57 -0700 (PDT) Subject: Why does it have red squiggly lines under it if it works perfectly fine and no errors happen when I run it? In-Reply-To: References: <22b99b0a-598f-4500-9de9-5041c2ce2c8f@googlegroups.com> <24104d3b-ad83-4c15-bb9e-77b61a0bac78@googlegroups.com> Message-ID: <5398c4af-1692-4b7f-9f39-ea392d24199b@googlegroups.com> On Saturday, September 21, 2013 1:39:41 AM UTC+12, Duncan Booth wrote: > William Bryant wrote: > > > > > Thanks a lot! I have one more question, is there any way I can make my > > > program work on android tablets and ipads? Because I'd like to use it > > > in school because we are learning statistics and we are allowed our > > > devices in school. > > > > > > > You can install SL4A on Android and that should let you run your script on > > an Android tablet. You may want to modify the script to work with the > > android UI, or it might be enough just to run it in a terminal window. > > > > I don't believe there is an ipad equivalent, but so long as you have a > > network connection, another option to consider (that would work on both > > android and ipad) would be to run the script on a server somewhere and > > connect to it through a web browser. Have a look at https://c9.io as that > > gives you a full development environment that can be accessed through a web > > browser: I don't know how well it works on a tablet but it would be worth > > trying. > > > > > > -- > > Duncan Booth http://kupuguy.blogspot.com Ok thanks for that, I know I said one more question, but could you pleasse help me here: def median(): medlist = List medlist.sort() if len(medlist) % 2: while len(medlist) > 2: medlist.popleft() medlist.popright() if medlist[0] == medlist[1]: themedian = medlist elif medlist[0] != medlist[1]: #make an if statment to figure out the median if the last 2 left are not the same. Eg [1, 2] the middle value is 1.5 pass else: while len(medlist) > 1: medlist.popleft() medlist.popright() themedian = medlist return themedian It says out of range and i don't know how I am going to make an if statment to figure out the median if the last 2 left are not the same. Eg [1, 2] the middle value is 1.5. Thanks - I am 13 year old beginner in python and i am trying to finish the tutorial on code academy and read the docs. :) From steve+comp.lang.python at pearwood.info Sat Sep 21 06:25:29 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Sep 2013 10:25:29 GMT Subject: Why does it have red squiggly lines under it if it works perfectly fine and no errors happen when I run it? References: <22b99b0a-598f-4500-9de9-5041c2ce2c8f@googlegroups.com> <24104d3b-ad83-4c15-bb9e-77b61a0bac78@googlegroups.com> <5398c4af-1692-4b7f-9f39-ea392d24199b@googlegroups.com> Message-ID: <523d7419$0$29988$c3e8da3$5496439d@news.astraweb.com> On Fri, 20 Sep 2013 23:07:57 -0700, William Bryant wrote: > I am 13 year old beginner in > python and i am trying to finish the tutorial on code academy and read > the docs. :) Hi William, I think this is about the fifth or sixth time you've told us this. I'm really pleased that a youngster like you is learning to program, but you don't have to apologise for your youth in every second email, you're starting to make us oldies jealous :-) Perhaps when you start a new question, it's okay to remind us. But if you're a regular here, we'll soon learn your level of experience. > def median(): > medlist = List > medlist.sort() > if len(medlist) % 2: > while len(medlist) > 2: > medlist.popleft() > medlist.popright() > if medlist[0] == medlist[1]: > themedian = medlist > elif medlist[0] != medlist[1]: > #make an if statment to figure out the median if the last 2 > left are not the same. Eg [1, 2] the middle value is 1.5 > pass > else: > while len(medlist) > 1: > medlist.popleft() > medlist.popright() > themedian = medlist > return themedian > > It says out of range If you're going to be a coder, for fun or profit, there are some skills you need to learn. One of those skills is to copy and paste the whole traceback, not just paraphrase the error message at the end. In this case, I can guess what is going wrong without seeing the whole traceback, but in general it is best to copy everything from the line Traceback (most recent call last) to the end of the error message. In this case, there is a better approach to calculating the median. Start by thinking about how you would calculate it by hand: * sort the numbers; * if there is an odd number of items, pick the middle one; * otherwise pick the two middle ones and take the average. Python can do the same thing. There's no need to delete items one by one from the ends of the list until there are only one, or two left. If you have a million items, that would be terribly slow... So, here we go: def median(): # Relies on the global variable called List. List.sort() n = len(List) if n % 2 == 1: # Odd number of items. return List[n//2] else: a = List[n//2 - 1] b = List[n//2] return (a + b)/2.0 There's a couple of useful things to learn from this: 1) In a couple of places, you'll see n//2, which looks like division but with the / doubled. This is not a typo! It performs integer division, throwing away any remainder instead of giving you a fraction. So: 21//7 => 3 22//7 => 3 2) You'll also see a few places where I say List[...] with something inside the square brackets. This is looking into the list to grab whatever element is in the position. For example: >>> L = [100, 110, 120, 130] >>> L[0] # List indexes start from zero, not one 100 >>> L[1] 110 >>> L[2] 120 >>> L[3] 130 So you can look up the element at any position inside a list in a single operation, without needing to throw elements away first. Just remember to start counting at zero, not one! 3) Last but not least, the last line divides by 2.0 instead of 2. Why 2.0? Unfortunately, older versions of Python treat single-slash division / differently depending on whether the values have a decimal point or not. This was a bad design, and Python 3 has fixed that, but I don't know whether you have Python 2 or Python 3. So to be safe, I divide by 2.0 to ensure that it calculates the right answer no matter what version you are using. Regards, -- Steven From davea at davea.name Sat Sep 21 08:53:38 2013 From: davea at davea.name (Dave Angel) Date: Sat, 21 Sep 2013 12:53:38 +0000 (UTC) Subject: Why does it have red squiggly lines under it if it works perfectly fine and no errors happen when I run it? References: <22b99b0a-598f-4500-9de9-5041c2ce2c8f@googlegroups.com> <24104d3b-ad83-4c15-bb9e-77b61a0bac78@googlegroups.com> <5398c4af-1692-4b7f-9f39-ea392d24199b@googlegroups.com> Message-ID: On 21/9/2013 02:07, William Bryant wrote: In addition to Steven's comments: > > def median(): > medlist = List > medlist.sort() You have just altered the original list. Perhaps sorting it is harmless, but below you actually remove elements from it. One way to avoid that is to use the sorted() method, which creates a new list. > if len(medlist) % 2: This then is the "odd" size branch of code. I think you intended to do the reverse if-test. A comment would be in order. > while len(medlist) > 2: > medlist.popleft() > medlist.popright() At this point, there is exactly one item left in the list. So the code below is going to get into trouble. > if medlist[0] == medlist[1]: > themedian = medlist Is the return value of this function supposed to be a list, or a float? If a float, then you should be doing something like: themedian = medlist[0] > elif medlist[0] != medlist[1]: > #make an if statment to figure out the median if the last 2 left are not the same. Eg [1, 2] the middle value is 1.5 > pass > else: > while len(medlist) > 1: > medlist.popleft() > medlist.popright() > themedian = medlist > return themedian > > It says out of range and i don't know how I am going to make an if statment to figure out the median if the last 2 left are not the same. Eg [1, 2] the middle value is 1.5. Thanks - I am 13 year old beginner in python and i am trying to finish the tutorial on code academy and read the docs. :) Taking Steven's suggested code, and changing it so it uses a COPY of the global list; def median(): # Relies on the global variable called List. # assumes there is at least one number in that list numbers = List.sorted() n = len(numbers) if n % 2 == 1: # Odd number of items. return numbers[n//2] else: a = numbers[n//2 - 1] b = numbers[n//2] return (a + b)/2.0 -- DaveA From python at mrabarnett.plus.com Sat Sep 21 12:18:32 2013 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 21 Sep 2013 17:18:32 +0100 Subject: Why does it have red squiggly lines under it if it works perfectly fine and no errors happen when I run it? In-Reply-To: References: <22b99b0a-598f-4500-9de9-5041c2ce2c8f@googlegroups.com> <24104d3b-ad83-4c15-bb9e-77b61a0bac78@googlegroups.com> <5398c4af-1692-4b7f-9f39-ea392d24199b@googlegroups.com> Message-ID: <523DC6D8.1080301@mrabarnett.plus.com> On 21/09/2013 13:53, Dave Angel wrote: [snip] > Taking Steven's suggested code, and changing it so it uses a COPY of the > global list; > > def median(): > # Relies on the global variable called List. > # assumes there is at least one number in that list > numbers = List.sorted() That should be: numbers = sorted(List) > n = len(numbers) > if n % 2 == 1: > # Odd number of items. > return numbers[n//2] > else: > a = numbers[n//2 - 1] > b = numbers[n//2] > return (a + b)/2.0 > From davea at davea.name Sat Sep 21 14:09:24 2013 From: davea at davea.name (Dave Angel) Date: Sat, 21 Sep 2013 18:09:24 +0000 (UTC) Subject: Why does it have red squiggly lines under it if it works perfectly fine and no errors happen when I run it? References: <22b99b0a-598f-4500-9de9-5041c2ce2c8f@googlegroups.com> <24104d3b-ad83-4c15-bb9e-77b61a0bac78@googlegroups.com> <5398c4af-1692-4b7f-9f39-ea392d24199b@googlegroups.com> <523DC6D8.1080301@mrabarnett.plus.com> Message-ID: On 21/9/2013 12:18, MRAB wrote: > On 21/09/2013 13:53, Dave Angel wrote: > [snip] >> Taking Steven's suggested code, and changing it so it uses a COPY of the >> global list; >> >> def median(): >> # Relies on the global variable called List. >> # assumes there is at least one number in that list >> numbers = List.sorted() > > That should be: > > numbers = sorted(List) OOPS. Thanks, you're so right. -- DaveA From wuwei23 at gmail.com Sun Sep 22 20:39:10 2013 From: wuwei23 at gmail.com (alex23) Date: Mon, 23 Sep 2013 10:39:10 +1000 Subject: Why does it have red squiggly lines under it if it works perfectly fine and no errors happen when I run it? In-Reply-To: <24104d3b-ad83-4c15-bb9e-77b61a0bac78@googlegroups.com> References: <22b99b0a-598f-4500-9de9-5041c2ce2c8f@googlegroups.com> <24104d3b-ad83-4c15-bb9e-77b61a0bac78@googlegroups.com> Message-ID: On 20/09/2013 5:01 PM, William Bryant wrote: > I have one more question, is there any way I can make my program work on android tablets and ipads? Because I'd like to use it in school because we are learning statistics and we are allowed our devices in school. I'd recommend taking a look at kivy, it supports both Android & iOS (as well as Windows, Mac, Linux): http://kivy.org/ From davea at davea.name Thu Sep 19 16:18:36 2013 From: davea at davea.name (Dave Angel) Date: Thu, 19 Sep 2013 20:18:36 +0000 (UTC) Subject: Why does it have red squiggly lines under it if it works perfectly fine and no errors happen when I run it? References: <22b99b0a-598f-4500-9de9-5041c2ce2c8f@googlegroups.com> Message-ID: On 19/9/2013 14:46, William Bryant wrote: > the word 'def' has squiggily lines but the program works fine. It says: Syntax Error: expected an indented block. - why? > The direct answer is that your terminal program must be broken. it should not use "squiggly lines" for any purposes. But perhaps you're not seeing this in terminal, but in some text editor. Better specify what that is. As for the "Syntax Error..." Better supply the entire traceback. I can't see how you consider that error message as "working." > def restart(): Better give it a different name, since you're using this same name as a local within the function. > print(""" > > ~~~~~~~~~~~~~~~~ > > Cacluation DONE! > > ~~~~~~~~~~~~~~~~ > > """) > restart = input("\nEnter yes if you want to make a new list and no if you want to close the program (yes/no): ") > restart This line does nothing, as has been pointed out before in other messages. of yours. You're not printing it, assigning it to something, calling it, or whatever. > if restart == "yes" or restart == "y" or restart == "new list": > print("You want make a new list...\n") > time.sleep(1) > NOS() There's no such function. > elif restart == "no" or restart == "n" or restart == "close": > print("Goodbye!") > time.sleep(1) > print("Goodbye!") > time.sleep(1) > print("Goodbye!") > time.sleep(1) > print("Goodbye!") > time.sleep(1) > print("Goodbye!") > time.sleep(1) > quit() No such function. > else: > print("type y or n") > time.sleep(0.5) > restart() You're using recursion when a simple loop is called for. -- DaveA From cython at m.allo.ws Thu Sep 19 15:51:05 2013 From: cython at m.allo.ws (cython at m.allo.ws) Date: Thu, 19 Sep 2013 12:51:05 -0700 (PDT) Subject: Using the MSI installer on Windows: Setting PATH and Setuptools Message-ID: <567c7442-313f-4df3-8fc4-ff3256aabc46@googlegroups.com> Hello All, I really hate Windows, and I have only intermittent access to Windows machines right now. When I install Python 2.7 on Windows using the MSI installer, it definitely does not modify the PATH variable. So I modify the PATH variable myself as follows: setx PATH %PATH%;C:\Python27\ Question 1: The command above requires a reboot in order to take effect, at least on Windows 8. How do I make it take effect immediately? Maybe if I repeat the same command again with 'set' instead of 'setx'? Does 'set' affect the whole machine, or only the current CMD.EXE session? Question 2: python-guide.org suggests adding C:\Python27\Scripts\ to the PATH as well. When is that necessary or helpful? If I forget to do that and have problems later, how can I tell the cause of the problems? Question 3: Does the Windows MSI installer from Python.org include Setuptools? python-guide.org implies that it does not include Setuptools, but I have never needed to manually install Setuptools, I am always able to use easy_install right away. Is my memory warped, or perhaps tainted by old Python installs on the same machine? Question 4: If the Windows MSI installer indeed lacks Setuptools, what is the best way to install it from the command line in a future-proof manner (on Windows)? I am imagining something like this: wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py python ez_setup.py However, (1) wget is not a Windows command. What is the Windows command? And (2) is that URL the best possible URL? Or will that URL only download an old version, and there is a better URL for new versions? Thank you, Zak From skip at pobox.com Thu Sep 19 16:06:56 2013 From: skip at pobox.com (Skip Montanaro) Date: Thu, 19 Sep 2013 15:06:56 -0500 Subject: Using the MSI installer on Windows: Setting PATH and Setuptools In-Reply-To: <567c7442-313f-4df3-8fc4-ff3256aabc46@googlegroups.com> References: <567c7442-313f-4df3-8fc4-ff3256aabc46@googlegroups.com> Message-ID: > Question 4: If the Windows MSI installer indeed lacks Setuptools, what is the best way to install it from the command line in a future-proof manner (on Windows)? I am imagining something like this: > > wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py > python ez_setup.py > > However, (1) wget is not a Windows command. What is the Windows command? And (2) is that URL the best possible URL? Or will that URL only download an old version, and there is a better URL for new versions? I am not a Windows person, but wouldn't pip do the trick? https://pypi.python.org/pypi/pip/1.4.1 Skip From cython at m.allo.ws Thu Sep 19 16:31:43 2013 From: cython at m.allo.ws (cython at m.allo.ws) Date: Thu, 19 Sep 2013 13:31:43 -0700 (PDT) Subject: Using the MSI installer on Windows: Setting PATH and Setuptools In-Reply-To: References: <567c7442-313f-4df3-8fc4-ff3256aabc46@googlegroups.com> Message-ID: <3cc271c6-0f77-4d80-aa26-edd8ec6354a7@googlegroups.com> On Thursday, September 19, 2013 4:06:56 PM UTC-4, Skip Montanaro wrote: > > I am not a Windows person, but wouldn't pip do the trick? > PIP would definitely do the trick. Does the MSI include PIP? If it does not include PIP, then how can I easily install it from the command line? I am looking for something like this: wget https://pip.org/install/install_pip.py python install_pip.py This is totally theoretical. wget doesn't work, the URL is made up, and install_pip.py is a fantasy of mine. ez_setup.py DOES exist for Setuptools, which is why I am trying to use it. Thank you, Zak From skip at pobox.com Thu Sep 19 16:42:26 2013 From: skip at pobox.com (Skip Montanaro) Date: Thu, 19 Sep 2013 15:42:26 -0500 Subject: Using the MSI installer on Windows: Setting PATH and Setuptools In-Reply-To: <3cc271c6-0f77-4d80-aa26-edd8ec6354a7@googlegroups.com> References: <567c7442-313f-4df3-8fc4-ff3256aabc46@googlegroups.com> <3cc271c6-0f77-4d80-aa26-edd8ec6354a7@googlegroups.com> Message-ID: > PIP would definitely do the trick. Does the MSI include PIP? If it does not include PIP, then how can I easily install it from the command line? I am looking for something like this: Not yet, but I think just around the corner: http://www.python.org/dev/peps/pep-0453/ Unlike most enhancements, this is proposed for inclusion in the next micro releases of 2.7 and 3.3, not just in the next normal-new-features-allowed version, 3.4. Skip From ramit.prasad at jpmorgan.com.dmarc.invalid Thu Sep 19 18:22:42 2013 From: ramit.prasad at jpmorgan.com.dmarc.invalid (Prasad, Ramit) Date: Thu, 19 Sep 2013 22:22:42 +0000 Subject: Using the MSI installer on Windows: Setting PATH and Setuptools In-Reply-To: <567c7442-313f-4df3-8fc4-ff3256aabc46@googlegroups.com> References: <567c7442-313f-4df3-8fc4-ff3256aabc46@googlegroups.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF4741875A67E@SCACMX008.exchad.jpmchase.net> cython at m.allo.ws wrote: > Hello All, > > I really hate Windows, and I have only intermittent access to Windows machines right now. > > When I install Python 2.7 on Windows using the MSI installer, it definitely does not modify the PATH > variable. So I modify the PATH variable myself as follows: > > setx PATH %PATH%;C:\Python27\ > > Question 1: The command above requires a reboot in order to take effect, at least on Windows 8. How do > I make it take effect immediately? Maybe if I repeat the same command again with 'set' instead of > 'setx'? Does 'set' affect the whole machine, or only the current CMD.EXE session? Set affects current session only. """ Setx provides the only command-line or programmatic way to directly and permanently set system environment values. System environment variables are manually configurable through Control Panel or through a registry editor. The set command, which is internal to the command interpreter (Cmd.exe), sets user environment variables for the current console window only. """ ~ http://technet.microsoft.com/en-us/library/cc755104.aspx Setx should not require a reboot, but might require user to log out and back in (or restart CMD). Also, note that it modifies local environment by default and not system environment. [snip] > > Question 3: Does the Windows MSI installer from Python.org include Setuptools? python-guide.org > implies that it does not include Setuptools, but I have never needed to manually install Setuptools, I > am always able to use easy_install right away. Is my memory warped, or perhaps tainted by old Python > installs on the same machine? ActiveState's ActivePython MSI does include pip. FAQ says it also includes distribute which you could remove (I am guessing) but it will stop PyPM from working. I believe they also setup the PATH for you. I think ActivePython might be a slightly better installer for Windows users--at least that is what some people have recommended. I have not tried it myself, but it might be worth taking a look. > > Question 4: If the Windows MSI installer indeed lacks Setuptools, what is the best way to install it > from the command line in a future-proof manner (on Windows)? I am imagining something like this: > > wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py > python ez_setup.py > > However, (1) wget is not a Windows command. What is the Windows command? And (2) is that URL the best > possible URL? Or will that URL only download an old version, and there is a better URL for new > versions? The pip documentation uses the URL https://raw.github.com/pypa/pip/master/contrib/get-pip.py pip documentation: https://pip.readthedocs.org/en/latest/installing.html > > Thank you, > > Zak ~Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From sparctacus at gmail.com Thu Sep 19 18:12:10 2013 From: sparctacus at gmail.com (Bryan Irvine) Date: Thu, 19 Sep 2013 15:12:10 -0700 (PDT) Subject: python 2.7 SSL to fetch servers notAfter date Message-ID: <87a4bfdc-bfe9-413e-b735-a17d8f48db7e@googlegroups.com> I'm trying to connect to an SSL application using client certs to grab the remote certs notAfter time. When I connect using 'openssl s_client' and pass my client cert/key I can see it in the cert chain, but when I attempt to use get_peer_certificate() in python (2.7) I only get a blank dict and cannot pull the notAfter date. I think this means that Python is unable to validate the cert, but I'm not sure the next steps to fix it. -B From gheskett at wdtv.com Fri Sep 20 01:14:15 2013 From: gheskett at wdtv.com (Gene Heskett) Date: Fri, 20 Sep 2013 01:14:15 -0400 Subject: Missing py2exe, needed 4 a gcode generator to engrave text in fancy ttf fonts in steel Message-ID: <201309200114.15092.gheskett@wdtv.com> Greetings; Since the missing module is intended for making python stuff run standalone on a winderz box, I've no clue why it should be needed to build and make F- Engrave run on my 10.04.4 LTS box, but it insists on loading it in the setup.py script that starts it the first time. FWIW, cxfreeze is said, by synaptics search function to be the equ of the windows py2exe module. Can someone take a look at Then this is what I get: gene at coyote:~/src/F-Engrave-1.22_src$ python py2exe_setup.py Traceback (most recent call last): File "py2exe_setup.py", line 4, in import py2exe ImportError: No module named py2exe And tell me how to fix this so it runs on an older linux box? Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) My web page: should be up! Man is an animal that makes bargains: no other animal does this-- no dog exchanges bones with another. -- Adam Smith A pen in the hand of this president is far more dangerous than 200 million guns in the hands of law-abiding citizens. From rosuav at gmail.com Fri Sep 20 05:39:04 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 20 Sep 2013 19:39:04 +1000 Subject: Missing py2exe, needed 4 a gcode generator to engrave text in fancy ttf fonts in steel In-Reply-To: <201309200114.15092.gheskett@wdtv.com> References: <201309200114.15092.gheskett@wdtv.com> Message-ID: On Fri, Sep 20, 2013 at 3:14 PM, Gene Heskett wrote: > Can someone take a look at > > > > Then this is what I get: > gene at coyote:~/src/F-Engrave-1.22_src$ python py2exe_setup.py > Traceback (most recent call last): > File "py2exe_setup.py", line 4, in > import py2exe > ImportError: No module named py2exe > > And tell me how to fix this so it runs on an older linux box? The page you link to doesn't mention py2exe anywhere. Where did you get that you need to run that command? ChrisA From gheskett at wdtv.com Fri Sep 20 09:11:31 2013 From: gheskett at wdtv.com (Gene Heskett) Date: Fri, 20 Sep 2013 09:11:31 -0400 Subject: Missing py2exe, needed 4 a gcode generator to engrave text in fancy ttf fonts in steel In-Reply-To: References: <201309200114.15092.gheskett@wdtv.com> Message-ID: <201309200911.32021.gheskett@wdtv.com> On Friday 20 September 2013 08:48:44 Chris Angelico did opine: > On Fri, Sep 20, 2013 at 3:14 PM, Gene Heskett wrote: > > Can someone take a look at > > > > > e> > > > > Then this is what I get: > > gene at coyote:~/src/F-Engrave-1.22_src$ python py2exe_setup.py > > > > Traceback (most recent call last): > > File "py2exe_setup.py", line 4, in > > > > import py2exe > > > > ImportError: No module named py2exe > > > > And tell me how to fix this so it runs on an older linux box? > > The page you link to doesn't mention py2exe anywhere. Where did you > get that you need to run that command? > > ChrisA From the example command to run the setup, a short script: gene at coyote:~/src/F-Engrave-1.22_src$ cat py2exe_setup.py #run this from the command line: python py2exe_setup.py py2exe from distutils.core import setup import py2exe setup( options = {"py2exe": {"compressed": 1, "optimize": 0, } }, zipfile = None, console=[{"script":"f-engrave-122.py","icon_resources": [(0,"fengrave.ico"),(0,"fengrave.ico")]}] As shown on the setup page accompanying this , lower left of the list at the top of the page. Supposedly by using the src, I can build it with TTF support, which is missing from the file offered in the right most python only column. All the other checks and tests on the setup page work, and all the other dependencies appear to have been met. The setup file itself I find, shouldn't have been included in the zip without a README.linux that says to skip it. The shipped fengrave-122.py actually runs but is not finding any fonts. There s/b quite a few installed since I have used TrueTypeTracer extensively before. But I may have my machines mixed, and the computer running the milling machine is probably where I did all that. I haven't had my morning coffee yet, so I am ill equipt to do more ATM. Thank you. Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) My web page: should be up! Seize the day, put no trust in the morrow! -- Quintus Horatius Flaccus (Horace) A pen in the hand of this president is far more dangerous than 200 million guns in the hands of law-abiding citizens. From mohsen at pahlevanzadeh.org Fri Sep 20 02:50:26 2013 From: mohsen at pahlevanzadeh.org (Mohsen Pahlevanzadeh) Date: Fri, 20 Sep 2013 11:20:26 +0430 Subject: Can i run my python program under andriod? Message-ID: <1379659826.5815.1.camel@debian> Dear all, I need to binary with distutils, and run it under android OS, Do you have any experience? yours, Mohsen From josiah.carlson at gmail.com Fri Sep 20 03:18:32 2013 From: josiah.carlson at gmail.com (Josiah Carlson) Date: Fri, 20 Sep 2013 00:18:32 -0700 Subject: ANN: RPQueue 0.21 Message-ID: Hello everyone, For those of you who didn't know, if you are interested in a Redis-backed time and/or fifo-queue with priorities, retries, etc., to be used with Python, one exists and is mature: it's called RPQueue, and it seeks to simplify your life of task execution. The recent changelog entries are below my signature. The package has been around for two years next month, and does exactly what you expect it to do - no more, no less. You can find the package at: https://github.com/josiahcarlson/rpqueue/ https://pypi.python.org/pypi/rpqueue Please CC me on any replies if you have any questions or comments. Thank you, - Josiah #----------------------------------- 0.21 ------------------------------------ [changed] where available, rpqueue will now use Lua to move delayed tasks from the time-based priority queue to fifo queues. This should reduce overhead in all cases, and should drastically improve performance for those that use large numbers of delayed tasks. [changed] the version number is now PEP 386/440 compliant. [added] this changelog that will document updates/changes/improvements in an easily referenced location. [fixed] thanks to https://github.com/dmaust , rpqueue added a missing 'redis' requirement. -------------- next part -------------- An HTML attachment was scrubbed... URL: From asmbansal2 at gmail.com Fri Sep 20 05:58:00 2013 From: asmbansal2 at gmail.com (Aseem Bansal) Date: Fri, 20 Sep 2013 02:58:00 -0700 (PDT) Subject: What minimum should a person know before saying "I know Python" Message-ID: <31df03f7-2b81-483a-9242-b83ba4559b1a@googlegroups.com> I started Python 4 months ago. Largely self-study with use of Python documentation, stackoverflow and google. I was thinking what is the minimum that I must know before I can say that I know Python? I come from a C background which is comparatively smaller. But as Python is comparatively much larger what minimum should I know? Just a general question not for a specific purpose. From rustompmody at gmail.com Fri Sep 20 07:43:13 2013 From: rustompmody at gmail.com (rusi) Date: Fri, 20 Sep 2013 04:43:13 -0700 (PDT) Subject: What minimum should a person know before saying "I know Python" In-Reply-To: <31df03f7-2b81-483a-9242-b83ba4559b1a@googlegroups.com> References: <31df03f7-2b81-483a-9242-b83ba4559b1a@googlegroups.com> Message-ID: <97f90924-7690-442c-a1b3-4d7409e30d44@googlegroups.com> On Friday, September 20, 2013 3:28:00 PM UTC+5:30, Aseem Bansal wrote: > I started Python 4 months ago. Largely self-study with use of Python documentation, stackoverflow and google. I was thinking what is the minimum that I must know before I can say that I know Python? > > > > I come from a C background which is comparatively smaller. But as Python is comparatively much larger what minimum should I know? > > > > Just a general question not for a specific purpose. Stroustrup says he is still learning C++ and I know kids who have no qualms saying they know programming language L (for various values of L) after hardly an hour or two of mostly advertising and pep-talk exposure. So without knowing what you mean my 'knowing' I am not going to try answering q-1 I am just curious about q-2 -- C is small compared to python -- whats your measure for that? BTW 20 years ago I wrote about why C is very hard to learn and teach In these intervening years some things have changed, some have not See http://blog.languager.org/2013/02/c-in-education-and-software-engineering.html#relevate From robert.kern at gmail.com Fri Sep 20 09:39:13 2013 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 20 Sep 2013 14:39:13 +0100 Subject: What minimum should a person know before saying "I know Python" In-Reply-To: <97f90924-7690-442c-a1b3-4d7409e30d44@googlegroups.com> References: <31df03f7-2b81-483a-9242-b83ba4559b1a@googlegroups.com> <97f90924-7690-442c-a1b3-4d7409e30d44@googlegroups.com> Message-ID: On 2013-09-20 12:43, rusi wrote: > On Friday, September 20, 2013 3:28:00 PM UTC+5:30, Aseem Bansal wrote: >> I started Python 4 months ago. Largely self-study with use of Python documentation, stackoverflow and google. I was thinking what is the minimum that I must know before I can say that I know Python? >> >> I come from a C background which is comparatively smaller. But as Python is comparatively much larger what minimum should I know? >> >> Just a general question not for a specific purpose. > > Stroustrup says he is still learning C++ and I know kids who have no qualms saying they know programming language L (for various values of L) after hardly an hour or two of mostly advertising and pep-talk exposure. > So without knowing what you mean my 'knowing' I am not going to try answering q-1 I think that's his actual question: "What do *you* mean by 'I know Python'?" At what point in your Python career did you feel comfortable claiming that? -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From rustompmody at gmail.com Fri Sep 20 11:50:10 2013 From: rustompmody at gmail.com (rusi) Date: Fri, 20 Sep 2013 08:50:10 -0700 (PDT) Subject: What minimum should a person know before saying "I know Python" In-Reply-To: References: <31df03f7-2b81-483a-9242-b83ba4559b1a@googlegroups.com> <97f90924-7690-442c-a1b3-4d7409e30d44@googlegroups.com> Message-ID: <31648467-19e8-484c-995d-1e5ba48b5ea3@googlegroups.com> On Friday, September 20, 2013 7:09:13 PM UTC+5:30, Robert Kern wrote: > On 2013-09-20 12:43, rusi wrote: > > Stroustrup says he is still learning C++ and I know kids who have no qualms saying they know programming language L (for various values of L) after hardly an hour or two of mostly advertising and pep-talk exposure. > > > So without knowing what you mean my 'knowing' I am not going to try answering q-1 > > > I think that's his actual question: "What do *you* mean by 'I know Python'?" > At what point in your Python career did you feel comfortable claiming that? Hmm... Now you are putting me in a spot :-) Too many aspects to this to give a reasonably short answer :-) I'll try and collect my thoughts in due course... What I meant to say to the OP: Knowing a language can mean widely different things: 1. to crack interviews 2. as a junior programmer 3. as a tech-lead 4. for bug-fixing/maintaining others' code A big difference between 1 and 2 is the value of obfuscated/ting code For 1 knowing trick questions/answers is a big win; for 2 more likely a loss. Also for 1 a big breath-first knowledge is required; for 2 its ok to know a subset well and be able to use it with good taste. For 3 right emotions are more important than details -- to look at a significant piece of code and be accurate in exclaiming "Wonderful/Blechhh" 4 is really an important and much neglected mindset. Ive talked about it here http://blog.languager.org/2010/02/service-and-product-mindsets.html Ok... So trying to say (a little!) in answer to your (Robert's) question though tangentially. Ive spent 20 years in a university. Most of what goes on there may be called gaming. - The best students are not the one's who know or love to know most but who successfully game the system - The best teachers are not those who teach best but who are one-up on the students' gaming habits and tendencies - The best administrators are those who are cleverest at using academic (sounding) jargon to make lucrative institutions Sounds cynical? Well most of the students are not the 'best students' above and so its more important to gauge where (s)he is coming from, where going etc and to answer appropriately rather than giving to-the-point answers when the student may be too bewildered to ask exact/precise questions. Basically instruct him just enough on how to game the system so that he clears the course but not so much he loses his soul! From asmbansal2 at gmail.com Fri Sep 20 12:28:34 2013 From: asmbansal2 at gmail.com (Aseem Bansal) Date: Fri, 20 Sep 2013 09:28:34 -0700 (PDT) Subject: What minimum should a person know before saying "I know Python" In-Reply-To: <31648467-19e8-484c-995d-1e5ba48b5ea3@googlegroups.com> References: <31df03f7-2b81-483a-9242-b83ba4559b1a@googlegroups.com> <97f90924-7690-442c-a1b3-4d7409e30d44@googlegroups.com> <31648467-19e8-484c-995d-1e5ba48b5ea3@googlegroups.com> Message-ID: <771f2126-883f-40de-8df0-93c79061305f@googlegroups.com> By C being smaller than Python I did not mean the scope of C is lesser than Python. I simply meant that the standard libraries are less in number compared to Python. By knowing Python I didn't imply an expert-level understanding. Minimum that so someone cannot say "Hey, you said you knew Python but you don't know anything.". Something on these lines. You can say for cracking interviews and/or as a junior programmar and/or as a fresher getting into industry. I like to have test cases for my functions/scripts but that wasn't what I had in my mind. Also I am learning Python because it is faster to make things with it. Not because it is going to get me any marks or anything. @Tim Chase That list helped. I was looking for something like that. Questions which I can try to answer and see where I stand. I hope that cleared some confusion about what I wanted to ask. I wanted to gauge myself to find if I am progressing or not. From rosuav at gmail.com Fri Sep 20 12:34:32 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 21 Sep 2013 02:34:32 +1000 Subject: What minimum should a person know before saying "I know Python" In-Reply-To: <771f2126-883f-40de-8df0-93c79061305f@googlegroups.com> References: <31df03f7-2b81-483a-9242-b83ba4559b1a@googlegroups.com> <97f90924-7690-442c-a1b3-4d7409e30d44@googlegroups.com> <31648467-19e8-484c-995d-1e5ba48b5ea3@googlegroups.com> <771f2126-883f-40de-8df0-93c79061305f@googlegroups.com> Message-ID: On Sat, Sep 21, 2013 at 2:28 AM, Aseem Bansal wrote: > I hope that cleared some confusion about what I wanted to ask. I wanted to gauge myself to find if I am progressing or not. Well, based on my definition, that's easy to answer. Have you solved problems using Python? If you have a bunch of HTML pages and you need to get some info out of all of them by COB today, do you think "I can do that with Python", or do you think "I can do that with sed, awk, grep, and five levels of pipe"? The tools you use for an urgent job will be the ones you know. ChrisA From asmbansal2 at gmail.com Fri Sep 20 13:40:54 2013 From: asmbansal2 at gmail.com (Aseem Bansal) Date: Fri, 20 Sep 2013 10:40:54 -0700 (PDT) Subject: What minimum should a person know before saying "I know Python" In-Reply-To: References: <31df03f7-2b81-483a-9242-b83ba4559b1a@googlegroups.com> <97f90924-7690-442c-a1b3-4d7409e30d44@googlegroups.com> <31648467-19e8-484c-995d-1e5ba48b5ea3@googlegroups.com> <771f2126-883f-40de-8df0-93c79061305f@googlegroups.com> Message-ID: <3fa2d1ea-c873-43c3-b703-1e187e7bc6ce@googlegroups.com> On Friday, September 20, 2013 10:04:32 PM UTC+5:30, Chris Angelico wrote: > On Sat, Sep 21, 2013 at 2:28 AM, Aseem Bansal wrote: > > I hope that cleared some confusion about what I wanted to ask. I wanted to gauge myself to find if I am progressing or not. > > Well, based on my definition, that's easy to answer. Have you solved > problems using Python? If you have a bunch of HTML pages and you need > to get some info out of all of them by COB today, do you think "I can > do that with Python", or do you think "I can do that with sed, awk, > grep, and five levels of pipe"? The tools you use for an urgent job > will be the ones you know. > > ChrisA Yeah I have. I needed to get stats from the front page of a website. I wrote a script for that. I plotted the stats using matplotlib. I collected data manually and missed running the script one day so I took care of that problem using Python. Wrote a script that checked for internet connectivity and then ran the scripts that downloaded the stuff I needed and then placed this script in the Windows startup folder. That was a nice feeling. Because I can just customize that startup script if I ever wanted to change my computer's startup behaviour. But that was pure luck that I had done the random example that you had chosen. It would be difficult to find my overall progress by the one thing. I am currently unemployed so the sense of urgency isn't there normally. That's why I asked this question. But I got your point. From asmbansal2 at gmail.com Fri Sep 20 13:51:13 2013 From: asmbansal2 at gmail.com (Aseem Bansal) Date: Fri, 20 Sep 2013 10:51:13 -0700 (PDT) Subject: What minimum should a person know before saying "I know Python" In-Reply-To: <3fa2d1ea-c873-43c3-b703-1e187e7bc6ce@googlegroups.com> References: <31df03f7-2b81-483a-9242-b83ba4559b1a@googlegroups.com> <97f90924-7690-442c-a1b3-4d7409e30d44@googlegroups.com> <31648467-19e8-484c-995d-1e5ba48b5ea3@googlegroups.com> <771f2126-883f-40de-8df0-93c79061305f@googlegroups.com> <3fa2d1ea-c873-43c3-b703-1e187e7bc6ce@googlegroups.com> Message-ID: <92af2463-9b65-4bd6-a380-47208c529294@googlegroups.com> I understand that being able to solve problems and knowing when to use something is the final measure of knowing something properly. But I wanted to find something quantitative that I can use to measure myself. Like the interview questions that Tim Chase posted. Measuring myself based on the problems that I can think of is like a small child saying "I know that 1 + 1 = 2. So I know maths". That may be the toughest problem that he can think of. That isn't a correct evaluation of his math abilities. Similarly measuring myself on the basis of the problems that I can think of and solve doesn't actually measure anything. I don't want to be living in a fool's paradise based on solving the problems I can solve. It is not being able to solve a problem that will make me realize my limits. That's why I asked this question... I am kind of asking for advice. From rosuav at gmail.com Fri Sep 20 22:06:44 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 21 Sep 2013 12:06:44 +1000 Subject: What minimum should a person know before saying "I know Python" In-Reply-To: <3fa2d1ea-c873-43c3-b703-1e187e7bc6ce@googlegroups.com> References: <31df03f7-2b81-483a-9242-b83ba4559b1a@googlegroups.com> <97f90924-7690-442c-a1b3-4d7409e30d44@googlegroups.com> <31648467-19e8-484c-995d-1e5ba48b5ea3@googlegroups.com> <771f2126-883f-40de-8df0-93c79061305f@googlegroups.com> <3fa2d1ea-c873-43c3-b703-1e187e7bc6ce@googlegroups.com> Message-ID: On Sat, Sep 21, 2013 at 3:40 AM, Aseem Bansal wrote: > On Friday, September 20, 2013 10:04:32 PM UTC+5:30, Chris Angelico wrote: >> On Sat, Sep 21, 2013 at 2:28 AM, Aseem Bansal wrote: >> > I hope that cleared some confusion about what I wanted to ask. I wanted to gauge myself to find if I am progressing or not. >> >> Well, based on my definition, that's easy to answer. Have you solved >> problems using Python? If you have a bunch of HTML pages and you need >> to get some info out of all of them by COB today, do you think "I can >> do that with Python", or do you think "I can do that with sed, awk, >> grep, and five levels of pipe"? The tools you use for an urgent job >> will be the ones you know. >> >> ChrisA > > Yeah I have... > But that was pure luck that I had done the random example that you had chosen. It would be difficult to find my overall progress by the one thing. > > I am currently unemployed so the sense of urgency isn't there normally. That's why I asked this question. But I got your point. It wasn't exactly a random example; it's an extremely common task (maybe without the "must be done today" restriction), and one that Python happens to do fairly well. :) There was a time, back in the 1990s, when REXX was my primary language. (We were exclusively an OS/2 shop at the time, so it was a good choice.) If I needed to write a quick script, it would be in REXX. If I needed to parse text, I'd use REXX. If I wanted a GUI app, I'd write it in VX-REXX. Later on, when I needed to write Windows code, I tended to use C++. It wasn't till the late 2000s that I started using Python for those sorts of jobs - even though I'd met the language back in the 90s - indicating that that's when I actually knew the language. ChrisA From gheskett at wdtv.com Sat Sep 21 02:22:59 2013 From: gheskett at wdtv.com (Gene Heskett) Date: Sat, 21 Sep 2013 02:22:59 -0400 Subject: What minimum should a person know before saying "I know Python" In-Reply-To: References: <31df03f7-2b81-483a-9242-b83ba4559b1a@googlegroups.com> <3fa2d1ea-c873-43c3-b703-1e187e7bc6ce@googlegroups.com> Message-ID: <201309210222.59178.gheskett@wdtv.com> On Saturday 21 September 2013 01:34:50 Chris Angelico did opine: > On Sat, Sep 21, 2013 at 3:40 AM, Aseem Bansal wrote: > > On Friday, September 20, 2013 10:04:32 PM UTC+5:30, Chris Angelico wrote: > >> On Sat, Sep 21, 2013 at 2:28 AM, Aseem Bansal wrote: > >> > I hope that cleared some confusion about what I wanted to ask. I > >> > wanted to gauge myself to find if I am progressing or not. > >> > >> Well, based on my definition, that's easy to answer. Have you solved > >> problems using Python? If you have a bunch of HTML pages and you need > >> to get some info out of all of them by COB today, do you think "I can > >> do that with Python", or do you think "I can do that with sed, awk, > >> grep, and five levels of pipe"? The tools you use for an urgent job > >> will be the ones you know. > >> > >> ChrisA > > > > Yeah I have... > > But that was pure luck that I had done the random example that you had > > chosen. It would be difficult to find my overall progress by the one > > thing. > > > > I am currently unemployed so the sense of urgency isn't there > > normally. That's why I asked this question. But I got your point. > > It wasn't exactly a random example; it's an extremely common task > (maybe without the "must be done today" restriction), and one that > Python happens to do fairly well. :) > > There was a time, back in the 1990s, when REXX was my primary > language. (We were exclusively an OS/2 shop at the time, so it was a > good choice.) If I needed to write a quick script, it would be in > REXX. If I needed to parse text, I'd use REXX. If I wanted a GUI app, > I'd write it in VX-REXX. Later on, when I needed to write Windows > code, I tended to use C++. It wasn't till the late 2000s that I > started using Python for those sorts of jobs - even though I'd met the > language back in the 90s - indicating that that's when I actually knew > the language. > > ChrisA That also brings back fond memories of the days of the amiga, Chris. We had a huge superset of REXX called ARexx, which brought every system call that AmigaDOS had right into the script writers usage menu. Jim Hines and I wrote the only cron the amiga ever had that didn't busy wait, so cpu usage was minimal. Called it EzCron. Gave it away. Then since the x10 stuff for home automation was /the/ system back in the day, we wrote EzHome, which had an MUI driven gui, and sold that for a time. It, ARexx, was written by a William Hawes, and sold thru the commie dealer chains at the time. I've no clue whatever became of that gentleman after that, but it came to light much that he never got a dime for writing ARexx from those 2 crooks that bought commie and moved it to the Bahamas where he, nor anyone else, could sue to collect. I did note that for many years, there was a subdir on kernel.org for him to work in, but to my knowledge it was empty when I downloaded and built my first x86 based linux kernel in early 1998, and remained empty till whenever. I was quite pleased to see that there was a Rexx/Regina for linux, and for about 10 minutes thought I could make use of the library of ARexx code Jim & I had carved up and had running on the amiga, but was very disappointed to see that Regina wasn't coupled to the os itself in any way, causing our scripts to barf and exit within the first 3 or 4 lines of code. Our first web page at WDTV.com in the winter of 1999-2000 was served up on a dialup circuit, by an ARexx script we wrote, from an amiga 2000. Heady days, those, while the dosboxes were still struggling with trumpet, and choking on the all the amiga, pdp and VAX dust. But time marches on, while the amiga didn't. I've seen python doing some heady stuff in the last 5 years, but the learning curve is pretty steep for my now aging wet ram, which will be 79 years old in a few days, so the scripting language here at the Heskett Ranchette is bash, and there is quite a boatload of that running as background daemons right now. So I lurk, reading what goes by, hoping I'll learn enough python from osmosis to get comfortable with it. From all indications, it is todays "ARexx" of scripting languages. I'll get me coat now. :) Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) My web page: should be up! As pointed out in a followup, Real Perl Programmers prefer things to be visually distinct. -- Larry Wall in <199710161841.LAA13208 at wall.org> A pen in the hand of this president is far more dangerous than 200 million guns in the hands of law-abiding citizens. From gheskett at wdtv.com Sun Sep 22 14:55:24 2013 From: gheskett at wdtv.com (Gene Heskett) Date: Sun, 22 Sep 2013 14:55:24 -0400 Subject: What minimum should a person know before saying "I know Python" In-Reply-To: References: <31df03f7-2b81-483a-9242-b83ba4559b1a@googlegroups.com> <201309210222.59178.gheskett@wdtv.com> Message-ID: <201309221455.24880.gheskett@wdtv.com> On Sunday 22 September 2013 14:49:21 Dennis Lee Bieber did opine: > On Sat, 21 Sep 2013 02:22:59 -0400, Gene Heskett > > declaimed the following: > >I was quite pleased to see that there was a Rexx/Regina for linux, and > >for about 10 minutes thought I could make use of the library of ARexx > >code Jim & I had carved up and had running on the amiga, but was very > >disappointed to see that Regina wasn't coupled to the os itself in any > >way, causing our scripts to barf and exit within the first 3 or 4 > >lines of code. > > No surprise given the lack of real /interactive/ IPC in Windows and > Linux. A version of REXX running on (Open)VMS might have a chance -- as > VMS Mailboxes were a (protected memory equivalent) of Amiga message > ports... So a means of "address other_application" could be mapped to > opening "other_application_port". > > I vaguely recall once using the "advanced" calls from the back of the > manual, and having multiple ARexx scripts talking to each other via > "address other_script" We did that dozens of times a day on every machine we owned, which at the time was about just in the commercial production rooms. > >I've seen python doing some heady stuff in the last 5 years, but the > >learning curve is pretty steep for my now aging wet ram, which will be > >79 years old in a few days, so the scripting language here at the > >Heskett Ranchette is bash, and there is quite a boatload of that > >running as background daemons right now. So I lurk, reading what goes > >by, hoping I'll learn enough python from osmosis to get comfortable > >with it. From all indications, it is todays "ARexx" of scripting > >languages. > > Having been spoiled by ARexx myself... No... Python will never be > /that/... Even subprocess.popen() doesn't allow for the easy control of > other programs. One is stuck with M$ COM (the win32 extension library > or, more portable maybe [if the libraries are ported] ctypes to do what > "address ..." did in ARexx. Then it seems to me that work in the direction should be an active feature request. Unforch, as I've said before, I'm rowing this barge with a toothpick for an oar. :) I would be interesting to see if the "bait" is taken. :) Thanks Dennis. Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) My web page: should be up! Real programmers don't write in BASIC. Actually, no programmers write in BASIC after reaching puberty. A pen in the hand of this president is far more dangerous than 200 million guns in the hands of law-abiding citizens. From gheskett at wdtv.com Sun Sep 22 15:48:04 2013 From: gheskett at wdtv.com (Gene Heskett) Date: Sun, 22 Sep 2013 15:48:04 -0400 Subject: What minimum should a person know before saying "I know Python" In-Reply-To: <201309221455.24880.gheskett@wdtv.com> References: <31df03f7-2b81-483a-9242-b83ba4559b1a@googlegroups.com> <201309221455.24880.gheskett@wdtv.com> Message-ID: <201309221548.04891.gheskett@wdtv.com> On Sunday 22 September 2013 15:46:52 Gene Heskett did opine: > On Sunday 22 September 2013 14:49:21 Dennis Lee Bieber did opine: > > On Sat, 21 Sep 2013 02:22:59 -0400, Gene Heskett > > > > declaimed the following: > > >I was quite pleased to see that there was a Rexx/Regina for linux, > > >and for about 10 minutes thought I could make use of the library of > > >ARexx code Jim & I had carved up and had running on the amiga, but > > >was very disappointed to see that Regina wasn't coupled to the os > > >itself in any way, causing our scripts to barf and exit within the > > >first 3 or 4 lines of code. > > > > > No surprise given the lack of real /interactive/ IPC in Windows and > > > > Linux. A version of REXX running on (Open)VMS might have a chance -- > > as VMS Mailboxes were a (protected memory equivalent) of Amiga > > message ports... So a means of "address other_application" could be > > mapped to opening "other_application_port". > > > > I vaguely recall once using the "advanced" calls from the back of > > the > > > manual, and having multiple ARexx scripts talking to each other via > > "address other_script" > > We did that dozens of times a day on every machine we owned, which at > the time was about just in the commercial production rooms. s/about just/about 6 just/g > > >I've seen python doing some heady stuff in the last 5 years, but the > > >learning curve is pretty steep for my now aging wet ram, which will > > >be 79 years old in a few days, so the scripting language here at the > > >Heskett Ranchette is bash, and there is quite a boatload of that > > >running as background daemons right now. So I lurk, reading what > > >goes by, hoping I'll learn enough python from osmosis to get > > >comfortable with it. From all indications, it is todays "ARexx" of > > >scripting languages. > > > > > Having been spoiled by ARexx myself... No... Python will never be > > > > /that/... Even subprocess.popen() doesn't allow for the easy control > > of other programs. One is stuck with M$ COM (the win32 extension > > library or, more portable maybe [if the libraries are ported] ctypes > > to do what "address ..." did in ARexx. > > Then it seems to me that work in the direction should be an active > feature request. Unforch, as I've said before, I'm rowing this barge > with a toothpick for an oar. :) > > I would be interesting to see if the "bait" is taken. :) > > Thanks Dennis. > > Cheers, Gene Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) My web page: should be up! Hate is like acid. It can damage the vessel in which it is stored as well as destroy the object on which it is poured. A pen in the hand of this president is far more dangerous than 200 million guns in the hands of law-abiding citizens. From gheskett at wdtv.com Mon Sep 23 00:10:04 2013 From: gheskett at wdtv.com (Gene Heskett) Date: Mon, 23 Sep 2013 00:10:04 -0400 Subject: What minimum should a person know before saying "I know Python" In-Reply-To: References: <31df03f7-2b81-483a-9242-b83ba4559b1a@googlegroups.com> <201309221455.24880.gheskett@wdtv.com> Message-ID: <201309230010.04821.gheskett@wdtv.com> On Sunday 22 September 2013 23:41:10 Dennis Lee Bieber did opine: > On Sun, 22 Sep 2013 14:55:24 -0400, Gene Heskett > > declaimed the following: > >Then it seems to me that work in the direction should be an active > >feature request. Unforch, as I've said before, I'm rowing this barge > >with a toothpick for an oar. :) > > > >I would be interesting to see if the "bait" is taken. :) > > Unfortunately, I see that as a requiring a change at the OS level. Without knowing exactly how this was done on the Miggies, and the level of security we have here compared to zero on the amiga because of its flat, no mmu memory mapping, precludes my having a thought to argue about it in my wildest dreams. Re ARexx, its biggest Achilles heel was the Rexx.lib, which became so obvious that Joanne Dow and someone else whose name I've spaced in the ensuing 15 years, actually dissed it, found several buglets and one real whoodoozy and fixed them, which enhanced the amiga's long term stability such that even the web server only had to be rebooted at 2 to 3 week intervals. Yes, that Joanne Dow, you might remember the name from her bix days, is a friend of mine. Quite a Lady IMO. About as creative as anyone I've ever met in coming up with lady-like versions of screw you etc. ;-) Last I knew a year back up the log, she was still working, I don't have too many years on her, and my use by date has passed a long time ago Dennis, I'll be 79 on the next 4th. > Even on the OS that REXX was developed upon, my books give a strong > hint that the only application that was readily "address app" compatible > was a text editor. ARexx piggy-backed on the underlying linked list > messages on "findable" message ports. > > Until the OS supports a multiple writer IPC with return addressing in > an easy API, it's unlikely to be created. UDP/IP might be a way -- but > UDP has that nasty unreliability factor. Amiga message ports had > guaranteed delivery (as long as the receiving process read the queued > messages; and VMS mailboxes were similar). > > Multiple writer -- as any process could send messages to the single > receiving port; it wasn't a socket server style where connection > requests on a single port would be assigned a distinct port subsequent > usage. > > Then again, the Amiga auto-config for boards pre-dates the PCI- express > configuration system, which is very similar. And that, despite being mostly written in Lisp, worked very well. The fact that for every board initialized at boot time required a soft reboot that the user wasn't made obviously aware of, could get interesting though. Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) He only knew his iron spine held up the sky -- he didn't realize his brain had fallen to the ground. -- The Book of Serenity A pen in the hand of this president is far more dangerous than 200 million guns in the hands of law-abiding citizens. From roy at panix.com Fri Sep 20 22:31:04 2013 From: roy at panix.com (Roy Smith) Date: Fri, 20 Sep 2013 22:31:04 -0400 Subject: What minimum should a person know before saying "I know Python" References: <31df03f7-2b81-483a-9242-b83ba4559b1a@googlegroups.com> <97f90924-7690-442c-a1b3-4d7409e30d44@googlegroups.com> <31648467-19e8-484c-995d-1e5ba48b5ea3@googlegroups.com> <771f2126-883f-40de-8df0-93c79061305f@googlegroups.com> Message-ID: In article , Chris Angelico wrote: > On Sat, Sep 21, 2013 at 2:28 AM, Aseem Bansal wrote: > > I hope that cleared some confusion about what I wanted to ask. I wanted to > > gauge myself to find if I am progressing or not. > > Well, based on my definition, that's easy to answer. Have you solved > problems using Python? If you have a bunch of HTML pages and you need > to get some info out of all of them by COB today, do you think "I can > do that with Python", or do you think "I can do that with sed, awk, > grep, and five levels of pipe"? The tools you use for an urgent job > will be the ones you know. The fact that you reach for traditional command-line tools to parse HTML should not be taken as evidence that you don't know Python. It should be taken as evidence that you have a lot of tools in your quiver and know when to use the right one. I started with Python in the 1.4 days. I will reach for Python these days in preference to Perl, Tcl, C, C++, Java, or PHP for most things. But, for a lot of basic text processing, I can throw together a sed, awk, grep, sort, uniq, wc, tac, tail, etc pipeline faster than I can write a Python program to do the same thing. Oh, and by the way, the python.org home page has $ curl -s python.org | tr ' ' '\n' | grep ^href= | wc -l 124 124 links on it. You're still reading the BeautifulSoup docs :-) From rosuav at gmail.com Fri Sep 20 22:54:34 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 21 Sep 2013 12:54:34 +1000 Subject: What minimum should a person know before saying "I know Python" In-Reply-To: References: <31df03f7-2b81-483a-9242-b83ba4559b1a@googlegroups.com> <97f90924-7690-442c-a1b3-4d7409e30d44@googlegroups.com> <31648467-19e8-484c-995d-1e5ba48b5ea3@googlegroups.com> <771f2126-883f-40de-8df0-93c79061305f@googlegroups.com> Message-ID: On Sat, Sep 21, 2013 at 12:31 PM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> On Sat, Sep 21, 2013 at 2:28 AM, Aseem Bansal wrote: >> > I hope that cleared some confusion about what I wanted to ask. I wanted to >> > gauge myself to find if I am progressing or not. >> >> Well, based on my definition, that's easy to answer. Have you solved >> problems using Python? If you have a bunch of HTML pages and you need >> to get some info out of all of them by COB today, do you think "I can >> do that with Python", or do you think "I can do that with sed, awk, >> grep, and five levels of pipe"? The tools you use for an urgent job >> will be the ones you know. > > The fact that you reach for traditional command-line tools to parse HTML > should not be taken as evidence that you don't know Python. It should > be taken as evidence that you have a lot of tools in your quiver and > know when to use the right one. > > I started with Python in the 1.4 days. I will reach for Python these > days in preference to Perl, Tcl, C, C++, Java, or PHP for most things. > But, for a lot of basic text processing, I can throw together a sed, > awk, grep, sort, uniq, wc, tac, tail, etc pipeline faster than I can > write a Python program to do the same thing. Oh, absolutely! I never said that sed/awk/grep was a bad way to do things; my point is that, when there are dozens of viable solutions to a problem and you have to solve that problem *now*, you are going to reach for the one you know best. I use sed all the time (it's one of the easiest ways to edit a root-owned file from a non-root shell script - 'sudo sed -i'). ChrisA From python.list at tim.thechases.com Fri Sep 20 07:53:50 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 20 Sep 2013 06:53:50 -0500 Subject: What minimum should a person know before saying "I know Python" In-Reply-To: <31df03f7-2b81-483a-9242-b83ba4559b1a@googlegroups.com> References: <31df03f7-2b81-483a-9242-b83ba4559b1a@googlegroups.com> Message-ID: <20130920065350.5b181417@bigbox.christie.dr> On 2013-09-20 02:58, Aseem Bansal wrote: > I started Python 4 months ago. Largely self-study with use of > Python documentation, stackoverflow and google. I was thinking what > is the minimum that I must know before I can say that I know Python? It's a fuzzy line. A good while back, there was a thread regarding Python interview questions: http://www.mail-archive.com/python-list at python.org/msg168971.html to which I replied with a pretty large list. The idea was not to ensure that people knew everything on it, but as a way to take stock of somebody means by "I know Python", which can mean anything from "I wrote _Hello World_ in Python once" to "I'm Guido/Raymond/Effbot". Along with the "Basics" section of that email, I'd expect a reasonable understanding of commonly-used libraries offered out of the box (at least a breadth of what is there, even if you haven't used them much). Most of the "history" items in that list are somewhat moot unless you have to support older Python (I still have some 2.4 installs that don't let me use the "with" statement or sqlite by default). -tkc From rosuav at gmail.com Fri Sep 20 10:26:21 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 21 Sep 2013 00:26:21 +1000 Subject: What minimum should a person know before saying "I know Python" In-Reply-To: <31df03f7-2b81-483a-9242-b83ba4559b1a@googlegroups.com> References: <31df03f7-2b81-483a-9242-b83ba4559b1a@googlegroups.com> Message-ID: On Fri, Sep 20, 2013 at 7:58 PM, Aseem Bansal wrote: > I started Python 4 months ago. Largely self-study with use of Python documentation, stackoverflow and google. I was thinking what is the minimum that I must know before I can say that I know Python? > > I come from a C background which is comparatively smaller. But as Python is comparatively much larger what minimum should I know? > > Just a general question not for a specific purpose. Interesting. Everything's relative. I would say that I "know Python" at the point where I am comfortable using it to solve problems, as opposed to using it to learn Python. That is to say, when you choose Python (above bash, or above some other language, or whatever) because it will take you less time to achieve a goal in Python than in any other language, when it's the goal that's important. I'd also add, though it's somewhat tangential to the first, that "knowing Python" also requires knowing when/where Python is a good choice of language. I like to be able to make one-sentence summaries of the form "X is a good choice when you want to...": * Python: put something together NOW, with no boilerplate * Pike: run a server that reloads code without dropping connections * C: implement a high level language (or a module for one) * PHP: gouge your eyes out with a rusty fork, but aren't allowed to on work time * Haskell: code functionally rather than imperatively (I'm not familiar with a broad range of functional languages; someone who is would be distinguishing them from each other) * bash: execute a series of commands, with minimal processing in between * Lua: embed a tiny and secure scripting language in an application * JavaScript/ECMAScript: ditto, but less tiny * Brainf*: gouge your eyes out with a rusty fork, but aren't allowed to use PHP Etcetera. Familiarity with a language requires knowing both how to use it and when to use it. ChrisA From dreamingforward at gmail.com Fri Sep 20 12:23:36 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Fri, 20 Sep 2013 09:23:36 -0700 Subject: What minimum should a person know before saying "I know Python" In-Reply-To: <31df03f7-2b81-483a-9242-b83ba4559b1a@googlegroups.com> References: <31df03f7-2b81-483a-9242-b83ba4559b1a@googlegroups.com> Message-ID: > I started Python 4 months ago. Largely self-study with use of Python documentation, stackoverflow and google. I was thinking what is the minimum that I must know before I can say that I know Python? Interesting. I would say that you must know the keywords, how to make a Class, how to write a loop. That covers about 85% of it. -- MarkJ Tacoma, Washington From js at globe.de Thu Sep 26 06:16:41 2013 From: js at globe.de (Schneider) Date: Thu, 26 Sep 2013 12:16:41 +0200 Subject: What minimum should a person know before saying "I know Python" In-Reply-To: References: <31df03f7-2b81-483a-9242-b83ba4559b1a@googlegroups.com> Message-ID: <52440989.2070700@globe.de> I would say it's a little bit more: You have to know the keywords and (basic) concepts, e.g. you really have to understand what it means, that everything is a class. If you get foreign, you have to be able to understand it. And the other way round, given a problem, you should be able to write a working solution. bg Johannes On 09/20/2013 06:23 PM, Mark Janssen wrote: >> I started Python 4 months ago. Largely self-study with use of Python documentation, stackoverflow and google. I was thinking what is the minimum that I must know before I can say that I know Python? > Interesting. I would say that you must know the keywords, how to make > a Class, how to write a loop. That covers about 85% of it. -- GLOBE Development GmbH K?nigsberger Strasse 260 48157 M?nsterGLOBE Development GmbH K?nigsberger Strasse 260 48157 M?nster 0251/5205 390 From jugurtha.hadjar at gmail.com Fri Sep 20 13:07:34 2013 From: jugurtha.hadjar at gmail.com (Jugurtha Hadjar) Date: Fri, 20 Sep 2013 18:07:34 +0100 Subject: What minimum should a person know before saying "I know Python" In-Reply-To: <31df03f7-2b81-483a-9242-b83ba4559b1a@googlegroups.com> References: <31df03f7-2b81-483a-9242-b83ba4559b1a@googlegroups.com> Message-ID: <523C80D6.7000206@gmail.com> I think it is a philosophical question. It's like saying "I know maths", which is a ridiculous phrase I was surprised to hear, let alone surprised to hear often. Can someone know everything there is to know about something ? I doubt it. The point, at least for me, isn't to know everything .. But the ability to find out. I consider myself ignorant in almost everything, that's because I ask myself a lot of questions about a lot of things I ignore. The point is following up and looking things up so that you know them. I knew many things I wasn't even aware existed. What this (constant questions) does is that it gives a lot of information that is networked (and you make a lot of connections between seemingly unrelated topics). I'll give an example: I had a class in my second year in college about nuclear and atomic physics. There was a chapter about the Doppler effect. I was able to grasp it easily, because when I was a kid, it happened I took magazines in the bathroom to read, and I've read about it. Having a d?j?-vu impression in a lot of things and to be able to make analogies of concepts and principles has helped me tremendously. When I got into college and started programming PIC microcontrollers, having tinkered with Intel assembly language in high-school (disassembling executables and tinkering with them) was definitely a plus (Registers, operands, carry operations, hexadecimal, addresses). When in the first year we started Pascal, I already did things in Delphi when I was in high-school. But then again, I also did tinker with C in middle-school (really basic stuff) and BASIC as a child. Do I know Python ? No. I don't think I ever will. But I am confident I will be able to do what I cannot do right now, and the complexity of the things I will be able to do will increase, as will my ability to simplify complex things. It's a converging exponential, as a capacitor charging. The goal is to minimized the time constant so you get at about 63.2% fast. The incremental 1%s will take years and I don't think you'll ever hit 100%, not even after decades. Sorry :) -- ~Jugurtha Hadjar, From tjreedy at udel.edu Fri Sep 20 18:26:41 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 20 Sep 2013 18:26:41 -0400 Subject: What minimum should a person know before saying "I know Python" In-Reply-To: <31df03f7-2b81-483a-9242-b83ba4559b1a@googlegroups.com> References: <31df03f7-2b81-483a-9242-b83ba4559b1a@googlegroups.com> Message-ID: On 9/20/2013 5:58 AM, Aseem Bansal wrote: > I started Python 4 months ago. Largely self-study with use of Python > documentation, stackoverflow and google. I was thinking what is the > minimum that I must know before I can say that I know Python? > > I come from a C background which is comparatively smaller. But as > Python is comparatively much larger what minimum should I know? The C stdlib may be smaller than the Python stdlib, but I do not think the language itself is much smaller. Python3 is a bit smaller than Python2 due to removals. Python the language is defined in the Language Reference. So 'knowing Python' means knowing most of that. What I might leave out: the details of all the special method names; which bitwise operators do what; yield from (3.3+). From the library manual, I would include an overview of chapters 2 to 5. For instance, not memorize all the exceptions, but understand the hierarchy. -- Terry Jan Reedy From cmpython at gmail.com Mon Sep 23 22:34:26 2013 From: cmpython at gmail.com (CM) Date: Mon, 23 Sep 2013 19:34:26 -0700 (PDT) Subject: What minimum should a person know before saying "I know Python" In-Reply-To: <31df03f7-2b81-483a-9242-b83ba4559b1a@googlegroups.com> References: <31df03f7-2b81-483a-9242-b83ba4559b1a@googlegroups.com> Message-ID: <73925f58-cd5a-46b1-b996-3440d7388ab1@googlegroups.com> On Friday, September 20, 2013 5:58:00 AM UTC-4, Aseem Bansal wrote: > I started Python 4 months ago. Largely self-study with use of Python > documentation, stackoverflow and google. I was thinking what is the minimum > that I must know before I can say that I know Python? Seems to me a fuzzy boundary between "Not knowing" and "knowing". I prefer thinking in terms of a spectrum, from 0-10 or pick your scale. 0 - Person who has never heard of Python or has but that's the extent of it. 1 - Beginning installer / Hello Worlder! / clumsy dabbler / what is self? 2 - Underway in earnest, not yet making anything all that much 3 - Making stuff, but clunky 4 - Making stuff pretty well, but looking up 2/3rds of it on SE or equivalent. 5 - Making stuff pretty well, but looking up 1/3rds of it on SE or equivalent. 6 - Making stuff pretty well, occasionally consulting the Python.org docs 7 - Tim Chase's list level 8 - The guy who hired the guy at 7 (assuming he is even further on) 9 - Gurus of this list 10 - Uber-gurus 10^6 - Guido I feel like I'm about 5 maybe, with some embarrassing chinks in the armor? Draw the "know line" boundary wherever you want, but I'd think you'd probably want to be above 4. I know I'd feel more comfortable saying I know Python if I were at 7 (and thanks, Tim Chase; I saved that list a while back in my files to consult someday, maybe). That said, I've written 20k+ loc of (mostly?) working code in Python and have done some contracting work at my humble 5, so there's that. From stascrash at gmail.com Fri Sep 20 08:56:16 2013 From: stascrash at gmail.com (stas poritskiy) Date: Fri, 20 Sep 2013 05:56:16 -0700 (PDT) Subject: Making it a MultiThread! Message-ID: <49c2ddff-9b80-4c0f-9272-2691f5f752d0@googlegroups.com> Hello All! I have a general question, i was posting here earlier while trying to troubleshoot a few things while developing an application, i was able to hit all of my goals, and make things work! Thank you all who contributed to my research, and again, sorry for poor formatting of the threads, i am slowly learning;) I am working on integration of multiple GUI (Tkinter) elements, such a progress bar, label update, etc, and throughout my research i discovered that i need to have Threading modules used to distribute the calls for GUI update and processing of my main App. My Application is broken into multiple Classes(modules), and i wanted to hear your thought on the best practices to implement the Threading model. I was thinking to create a new py-module, and reference all other modules/class to it, and create thread.start() objects, that would execute the GUI part, other will handle GUI Updates, and other - will be doing the processing. Please share some of your thought on this approach, or maybe you may suggest a more effective way. thanks ! From stascrash at gmail.com Fri Sep 20 12:11:34 2013 From: stascrash at gmail.com (stas poritskiy) Date: Fri, 20 Sep 2013 09:11:34 -0700 (PDT) Subject: Making it a MultiThread! In-Reply-To: <49c2ddff-9b80-4c0f-9272-2691f5f752d0@googlegroups.com> References: <49c2ddff-9b80-4c0f-9272-2691f5f752d0@googlegroups.com> Message-ID: <19013711-d0c9-44a3-a8e2-b9d50eaea599@googlegroups.com> On Friday, September 20, 2013 7:56:16 AM UTC-5, stas poritskiy wrote: > Hello All! > > > > I have a general question, > > i was posting here earlier while trying to troubleshoot a few things while developing an application, i was able to hit all of my goals, and make things work! Thank you all who contributed to my research, and again, sorry for poor formatting of the threads, i am slowly learning;) > > > > I am working on integration of multiple GUI (Tkinter) elements, such a progress bar, label update, etc, and throughout my research i discovered that i need to have Threading modules used to distribute the calls for GUI update and processing of my main App. > > > > My Application is broken into multiple Classes(modules), and i wanted to hear your thought on the best practices to implement the Threading model. > > > > I was thinking to create a new py-module, and reference all other modules/class to it, and create thread.start() objects, that would execute the GUI part, other will handle GUI Updates, and other - will be doing the processing. > > > > Please share some of your thought on this approach, or maybe you may suggest a more effective way. > > thanks ! Here is some CODE that i wrote to present the working case. my main program is split in multiple modules, but this structure should represent what i am trying to get. module name: multiProcessLauncher.py import multiprocessing import gui def main(): jobs = [] p = multiprocessing.Process(target=gui.basicGui) jobs.append(p) p.start() if __name__ == '__main__': main() pass Module Name: gui.py from Tkinter import * import tkMessageBox import Tkinter import multiProcessLauncher import action def basicGui(): g = action.Action() print "GUI" processor = multiProcessLauncher name = processor.multiprocessing.current_process().name print name, "starting" print name, "exiting" top = Tk() button = Button(top, text = "Press Me", command = g.do_something) button.pack() top.mainloop() def main(): pass if __name__ == "__main__": main() Module Name: action.py class Action(object): def __init__(self): self.text = "Running Action" def do_something(self): print self.text i am trying to figure out how to make use of multiprocessing access the PRINT from the action.py using the GUI button. if you run the code and press the button, the console will read nothing, but as soon as you close the GUI, it spits out the text to console. I read about using Que, but i am not sure how to implement, could someone suggest how? thank you From piet at vanoostrum.org Sat Sep 21 21:00:29 2013 From: piet at vanoostrum.org (Piet van Oostrum) Date: Sat, 21 Sep 2013 21:00:29 -0400 Subject: Making it a MultiThread! References: <49c2ddff-9b80-4c0f-9272-2691f5f752d0@googlegroups.com> <19013711-d0c9-44a3-a8e2-b9d50eaea599@googlegroups.com> Message-ID: stas poritskiy writes: >> I am working on integration of multiple GUI (Tkinter) elements, such >> a progress bar, label update, etc, and throughout my research i >> discovered that i need to have Threading modules used to distribute >> the calls for GUI update and processing of my main App. In general your GUI should be in your main process/thread. For example your program doesn't run on Mac OS X because you cannot run the GUI in another process or thread. Now if your GUI actions are starting some actions that last more than a few tenths of a second, you should run these actions in another thread or process (usually a thread will work), otherwise the GUI becomes unresponsive. If you want to exchange some information between the GUI and that thread/process you can use a Queue object, or just give the information from the GUI at the start of the thread. >> My Application is broken into multiple Classes(modules), and i wanted >> to hear your thought on the best practices to implement the Threading >> model. The structure of you modules isn't good. There are circular imports, and that is a sign the the design needs to be simplified: multiProcessLauncher imports gui. gui imports multiProcessLauncher. The latter import isn't necessary. Instead of import multiProcessLauncher processor = multiProcessLauncher name = processor.multiprocessing.current_process().name you can just use: import multiprocessing name = multiprocessing.current_process().name My advice would be to just do the GUI in the main module, and if the Action needs more time, the create a new Thread or Process in the Action class. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From rosuav at gmail.com Sat Sep 21 21:18:25 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 22 Sep 2013 11:18:25 +1000 Subject: Making it a MultiThread! In-Reply-To: References: <49c2ddff-9b80-4c0f-9272-2691f5f752d0@googlegroups.com> <19013711-d0c9-44a3-a8e2-b9d50eaea599@googlegroups.com> Message-ID: On Sun, Sep 22, 2013 at 11:00 AM, Piet van Oostrum wrote: > Now if your GUI actions are starting some actions that last more than a > few tenths of a second, you should run these actions in another thread... Hmm. When I first learned GUI programming (on OS/2), the advice was one tenth of a second absolute maximum, or spin off a thread. But yes, the advice is the same. Keep your main thread REALLY responsive. ChrisA From stascrash at gmail.com Mon Sep 23 10:14:17 2013 From: stascrash at gmail.com (stas poritskiy) Date: Mon, 23 Sep 2013 07:14:17 -0700 (PDT) Subject: Making it a MultiThread! In-Reply-To: References: <49c2ddff-9b80-4c0f-9272-2691f5f752d0@googlegroups.com> <19013711-d0c9-44a3-a8e2-b9d50eaea599@googlegroups.com> Message-ID: <56a86018-a4f5-4df1-8372-f200902fd531@googlegroups.com> Thanks for getting back to me, so i assume it is OK to have a very very long file? The sample code i posted here is basically the barebones of the main app. so, combining the GUI-file(gui.py) with main code is acceptable? Separating them into modules was initially the attempt to keep things in order. On Saturday, September 21, 2013 8:00:29 PM UTC-5, Piet van Oostrum wrote: > stas poritskiy writes: > > > > >> I am working on integration of multiple GUI (Tkinter) elements, such > > >> a progress bar, label update, etc, and throughout my research i > > >> discovered that i need to have Threading modules used to distribute > > >> the calls for GUI update and processing of my main App. > > > > In general your GUI should be in your main process/thread. For example > > your program doesn't run on Mac OS X because you cannot run the GUI in > > another process or thread. > > > > Now if your GUI actions are starting some actions that last more than a > > few tenths of a second, you should run these actions in another thread > > or process (usually a thread will work), otherwise the GUI becomes > > unresponsive. If you want to exchange some information between the GUI > > and that thread/process you can use a Queue object, or just give the > > information from the GUI at the start of the thread. > > > > >> My Application is broken into multiple Classes(modules), and i wanted > > >> to hear your thought on the best practices to implement the Threading > > >> model. > > > > The structure of you modules isn't good. There are circular imports, and > > that is a sign the the design needs to be simplified: > > > > multiProcessLauncher imports gui. > > gui imports multiProcessLauncher. > > > > The latter import isn't necessary. > > > > Instead of > > > > import multiProcessLauncher > > processor = multiProcessLauncher > > name = processor.multiprocessing.current_process().name > > > > you can just use: > > > > import multiprocessing > > name = multiprocessing.current_process().name > > > > My advice would be to just do the GUI in the main module, and if the > > Action needs more time, the create a new Thread or Process in the Action > > class. > > > > -- > > Piet van Oostrum > > WWW: http://pietvanoostrum.com/ > > PGP key: [8DAE142BE17999C4] From piet at vanoostrum.org Tue Sep 24 07:28:11 2013 From: piet at vanoostrum.org (Piet van Oostrum) Date: Tue, 24 Sep 2013 07:28:11 -0400 Subject: Making it a MultiThread! References: <49c2ddff-9b80-4c0f-9272-2691f5f752d0@googlegroups.com> <19013711-d0c9-44a3-a8e2-b9d50eaea599@googlegroups.com> <56a86018-a4f5-4df1-8372-f200902fd531@googlegroups.com> Message-ID: stas poritskiy writes: > Thanks for getting back to me, so i assume it is OK to have a very > very long file? The sample code i posted here is basically the > barebones of the main app. > so, combining the GUI-file(gui.py) with main code is acceptable? > Separating them into modules was initially the attempt to keep things > in order. Keeping things in separate modules is still OK. Just don't use circular imports. Keeping the logic of your applcation and the GUI in separate files is usually a good idea. And make sure the dependencies between the modules are simple. Very, very long files usually are not a good idea. Also you imported multiprocessing through anothe module. This obscures the structure of the application, and is unnecesary. You should only access a module through another module if you add a layer of abstraction that makes it easier or more powerful. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From babmis307 at gmail.com Fri Sep 20 08:59:55 2013 From: babmis307 at gmail.com (bab mis) Date: Fri, 20 Sep 2013 05:59:55 -0700 (PDT) Subject: I want to print entry and exit message for functions , i have bunch of such function . How can i do it in decorator. Message-ID: <30bf5567-47ff-4b54-acc4-aebb0451e47d@googlegroups.com> def fun: print "entry" . . print "exit" From __peter__ at web.de Fri Sep 20 09:23:13 2013 From: __peter__ at web.de (Peter Otten) Date: Fri, 20 Sep 2013 15:23:13 +0200 Subject: I want to print entry and exit message for functions , i have bunch of such function . How can i do it in decorator. References: <30bf5567-47ff-4b54-acc4-aebb0451e47d@googlegroups.com> Message-ID: bab mis wrote: > def fun: > print "entry" > . > . > print "exit" >>> def log(f): ... def g(*args, **kw): ... print "enter", f.__name__ ... try: ... return f(*args, **kw) ... finally: ... print "exit", f.__name__ ... return g ... >>> @log ... def divide(a, b): ... return a / b ... >>> divide(4, 2) enter divide exit divide 2 >>> divide(4, 0) enter divide exit divide Traceback (most recent call last): File "", line 1, in File "", line 5, in g File "", line 3, in divide ZeroDivisionError: integer division or modulo by zero From babmis307 at gmail.com Sun Sep 22 14:57:30 2013 From: babmis307 at gmail.com (bab mis) Date: Sun, 22 Sep 2013 11:57:30 -0700 (PDT) Subject: I want to print entry and exit message for functions , i have bunch of such function . How can i do it in decorator. In-Reply-To: <30bf5567-47ff-4b54-acc4-aebb0451e47d@googlegroups.com> References: <30bf5567-47ff-4b54-acc4-aebb0451e47d@googlegroups.com> Message-ID: <8aaaf0ab-09e0-4772-a906-333572320228@googlegroups.com> On Friday, September 20, 2013 6:29:55 PM UTC+5:30, bab mis wrote: > def fun: > > print "entry" > > . > > . > > print " On Friday, September 20, 2013 6:29:55 PM UTC+5:30, bab mis wrote: > def fun: > > print "entry" > > . > > . > > print "exit" On Friday, September 20, 2013 6:29:55 PM UTC+5:30, bab mis wrote: > def fun: > > print "entry" > > . > > . > > print "exit" Peter couple of queries with following code : def funlog(f): def g(*args,**kw): print "enter", f.__name__ try: return f(*args, **kw) finally: print "exit", f.__name__ return g class Action: def __init__(self): pass @funlog def sret(self): pass @funlog def ping(self): pass def verifyerun(self): pass 1) funlog is called for the last function as well. 2) Is it a proper way to define decorator out of class and use it . From tjreedy at udel.edu Sun Sep 22 16:48:39 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 22 Sep 2013 16:48:39 -0400 Subject: I want to print entry and exit message for functions , i have bunch of such function . How can i do it in decorator. In-Reply-To: <8aaaf0ab-09e0-4772-a906-333572320228@googlegroups.com> References: <30bf5567-47ff-4b54-acc4-aebb0451e47d@googlegroups.com> <8aaaf0ab-09e0-4772-a906-333572320228@googlegroups.com> Message-ID: On 9/22/2013 2:57 PM, bab mis wrote: > def funlog(f): > def g(*args,**kw): > print "enter", f.__name__ > try: > return f(*args, **kw) > finally: > print "exit", f.__name__ > return g > > class Action: > def __init__(self): > pass > > @funlog > def sret(self): > pass > > @funlog > def ping(self): > pass > def verifyerun(self): > pass > > > 1) funlog is called for the last function as well. If this is a question, no, it is not called on verifyerun. > 2) Is it a proper way to define decorator out of class and use it . Yes. It is not an Action methods. If you use it in multiple files, define once in one file and import it. -- Terry Jan Reedy From jugurtha.hadjar at gmail.com Fri Sep 20 11:04:34 2013 From: jugurtha.hadjar at gmail.com (Jugurtha Hadjar) Date: Fri, 20 Sep 2013 16:04:34 +0100 Subject: Antispam measures circumventing Message-ID: <523C6402.7090501@gmail.com> Hello, # I posted this on the tutor list, but my message wasn't displayed I shared some assembly code (microcontrollers) and I had a comment wit my e-mail address for contact purposes. Supposing my name is John Doe and the e-mail is john.doe at hotmail.com, my e-mail was written like this: REMOVEMEjohn.doSPAMeSPAM at REMOVEMEhotmail.com' With a note saying to remove the capital letters. Now, I wrote this : for character in my_string: ... if (character == character.upper()) and (character !='@') and (character != '.'): ... my_string = my_string.replace(character,'') And the end result was john.doe at hotmail.com. Is there a better way to do that ? Without using regular expressions (Looked *really* ugly and it doesn't really make sense, unlike the few lines I've written, which are obvious even to a beginner like me). I obviously don't like SPAM, but I just thought "If I were a spammer, how would I go about it". Eventually, some algorithm of detecting the johndoehotmailcom must exist. Also, what would in your opinion make it *harder* for a non-human to retrieve the original e-mail address? Maybe a function with no inverse function ? Generating an image that can't be converted back to text, etc.. If this is off-topic, you can just answer the "what is a better way to do that" part. Thanks, -- ~Jugurtha Hadjar, -- ~Jugurtha Hadjar, From rosuav at gmail.com Fri Sep 20 11:44:17 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 21 Sep 2013 01:44:17 +1000 Subject: Antispam measures circumventing In-Reply-To: <523C6402.7090501@gmail.com> References: <523C6402.7090501@gmail.com> Message-ID: On Sat, Sep 21, 2013 at 1:04 AM, Jugurtha Hadjar wrote: > Supposing my name is John Doe and the e-mail is john.doe at hotmail.com, my > e-mail was written like this: > > REMOVEMEjohn.doSPAMeSPAM at REMOVEMEhotmail.com' > > With a note saying to remove the capital letters. > > Now, I wrote this : > > for character in my_string: > ... if (character == character.upper()) and (character !='@') and > (character != '.'): > ... my_string = my_string.replace(character,'') > > > And the end result was john.doe at hotmail.com. > > Is there a better way to do that ? Instead of matching the ones that are the same as their uppercase version, why not instead keep the ones that are the same as their lowercase? >>> email = 'REMOVEMEjohn.doSPAMeSPAM at REMOVEMEhotmail.com' >>> ''.join(filter(lambda x: x==x.lower(),email)) 'john.doe at hotmail.com' This could be a neat introduction to a functional style of code, if you haven't already met it; use of filter and lambda expressions can make for some beautifully expressive code. > Also, what would in your opinion make it *harder* for a non-human > to retrieve the original e-mail address? Maybe a function with no > inverse function ? Generating an image that can't be converted back > to text, etc.. Ah, now you're getting into the realm of CAPTCHAs. I'll be quite frank with you: Don't bother. Many MANY experts are already looking into it - with various levels of success. Spammers are getting better and better at harvesting addresses and solving CAPTCHAs, and your legit users aren't getting that benefit, so you make it harder for the humans while still possible for the bots. (And some CAPTCHAs are solved by simply farming the jobs off to actual human beings (in China, I think I heard) for a pittance each. There's fundamentally no way to prevent that.) So your options are: 1) Call on someone else's code. Search the internet for ways of concealing email addresses, pick one that isn't too much hassle to legit users, and use it. I've seen quite a few that put the email address in an image, one way or another; they tend to be a bit annoying, but some aren't too bad. 2) Give up on protecting your address, and protect your inbox instead. Get some good spam filtering, and let 'em send it all at you. I run a local mail server for a few domains, and even with the filter set conservatively enough to all but eliminate false positives, we see only a handful of false negatives (according to my logs, 182 emails reported as spam this week, across all domains and all accounts - most accounts see <10 a week, a couple of them see maybe 20-30). And again, you can call on someone else to do the work for you - sending all your mail to gmail lets you take advantage of their filtering, for instance. But hey. If you want to play around with text processing, Python's a good choice for it! ChrisA From vlastimil.brom at gmail.com Fri Sep 20 11:47:45 2013 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Fri, 20 Sep 2013 17:47:45 +0200 Subject: Antispam measures circumventing In-Reply-To: <523C6402.7090501@gmail.com> References: <523C6402.7090501@gmail.com> Message-ID: 2013/9/20 Jugurtha Hadjar : > Hello, > # I posted this on the tutor list, but my message wasn't displayed > I shared some assembly code (microcontrollers) and I had a comment wit my > e-mail address for contact purposes. > Supposing my name is John Doe and the e-mail is john.doe at hotmail.com, my > e-mail was written like this: > REMOVEMEjohn.doSPAMeSPAM at REMOVEMEhotmail.com' > With a note saying to remove the capital letters. > Now, I wrote this : > for character in my_string: > ... if (character == character.upper()) and (character !='@') and > (character != '.'): > ... my_string = my_string.replace(character,'') > And the end result was john.doe at hotmail.com. > Is there a better way to do that ? Without using regular expressions (Looked > *really* ugly and it doesn't really make sense, unlike the few lines I've > written, which are obvious even to a beginner like me). > I obviously don't like SPAM, but I just thought "If I were a spammer, how > would I go about it". > Eventually, some algorithm of detecting the johndoehotmailcom > must exist. > retrieve the original e-mail address? Maybe a function with no inverse > function ? Generating an image that can't be converted back to text, etc.. > If this is off-topic, you can just answer the "what is a better way to do > that" part. > > Thanks, > -- > ~Jugurtha Hadjar, > -- > https://mail.python.org/mailman/listinfo/python-list Hi, is the regex really that bad for such simple replacement? >>> re.sub(r"[A-Z]", "", "REMOVEMEjohn.doSPAMeSPAM at REMOVEMEhotmail.com") 'john.doe at hotmail.com' Alternatively, you can use a check with the string method isupper(): >>> "".join(char for char in "REMOVEMEjohn.doSPAMeSPAM at REMOVEMEhotmail.com" if not char.isupper()) 'john.doe at hotmail.com' or using a special form of str.translate() >>> "REMOVEMEjohn.doSPAMeSPAM at REMOVEMEhotmail.com".translate(None, "ABCDEFGHIJKLMNOPQRSTUVWXYZ") 'john.doe at hotmail.com' which is the same like: >>> import string >>> "REMOVEMEjohn.doSPAMeSPAM at REMOVEMEhotmail.com".translate(None, string.ascii_uppercase) 'john.doe at hotmail.com' Another possibility would be to utilise ord(...) >>> "".join(char for char in "REMOVEMEjohn.doSPAMeSPAM at REMOVEMEhotmail.com" if ord(char) not in range(65, 91)) 'john.doe at hotmail.com' >>> Well, maybe there are other possibilities, these above are listed roughly in the order of my personal preference. Of course, others may differ... hth, vbr From jpiitula at ling.helsinki.fi Fri Sep 20 12:23:29 2013 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 20 Sep 2013 19:23:29 +0300 Subject: Antispam measures circumventing References: Message-ID: Jugurtha Hadjar writes: > Supposing my name is John Doe and the e-mail is john.doe at hotmail.com, > my e-mail was written like this: > > REMOVEMEjohn.doSPAMeSPAM at REMOVEMEhotmail.com' > > With a note saying to remove the capital letters. > > Now, I wrote this : > > for character in my_string: > ... if (character == character.upper()) and (character !='@') and > (character != '.'): > ... my_string = my_string.replace(character,'') That does a lot of needless work, but I'll suggest other things instead of expanding on this remark. First, there's character.isupper() that will replace your entire condition. Second, there's ''.join(c for c in my_string if not c.isupper()). > And the end result was john.doe at hotmail.com. > > Is there a better way to do that ? Without using regular expressions > (Looked *really* ugly and it doesn't really make sense, unlike the few > lines I've written, which are obvious even to a beginner like me). I don't see how you get to consider '[A-Z]' ugly. (Python doesn't seem to have the named character classes like '[[:upper:]]' that would do more than ASCII in some regexp systems. I only looked very briefly.) Third, here's a way - try help(str.translate) and help(str.maketrans) or python.org for some details: >>> from string import ascii_uppercase >>> 'Ooh, CamelCase!'.translate(str.maketrans('', '', ascii_uppercase)) 'oh, amelase!' > I obviously don't like SPAM, but I just thought "If I were a spammer, > how would I go about it". > > Eventually, some algorithm of detecting the > johndoehotmailcom must exist. > > Also, what would in your opinion make it *harder* for a non-human to > retrieve the original e-mail address? Maybe a function with no > inverse function ? Generating an image that can't be converted back > to text, etc.. Something meaningful: make it john.doeray at hotmail.com with a note to "remove the female deer" for john.ray at hotmail.com, or "remove the drop of golden sun" for "john.doe at hotmail.com". You may get a cease and desist letter - much uglier than a simple regex - if you do literally this, but you get the idea. I've seen people using "remove the animal" or "remove the roman numeral". (Put .invalid at the end, maybe. But I wish spam was against the law, effectively.) From rosuav at gmail.com Fri Sep 20 12:30:07 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 21 Sep 2013 02:30:07 +1000 Subject: Antispam measures circumventing In-Reply-To: References: Message-ID: On Sat, Sep 21, 2013 at 2:23 AM, Jussi Piitulainen wrote: > (Put .invalid at the end, maybe. But I wish spam was against the law, > effectively.) Against what law, exactly? In what jurisdiction will you seek to charge spammers? And who will track them down? ChrisA From rosuav at gmail.com Fri Sep 20 12:31:32 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 21 Sep 2013 02:31:32 +1000 Subject: Antispam measures circumventing In-Reply-To: References: Message-ID: On Sat, Sep 21, 2013 at 2:23 AM, Jussi Piitulainen wrote: > Something meaningful: make it john.doeray at hotmail.com with a note to > "remove the female deer" for john.ray at hotmail.com, or "remove the drop > of golden sun" for "john.doe at hotmail.com". This method can be quite effective. In fact, of all the suggestions made so far, I'd say these are a few of my favorite techniques... *ducks the rotten tomatoes* ChrisA From jugurtha.hadjar at gmail.com Fri Sep 20 12:45:26 2013 From: jugurtha.hadjar at gmail.com (Jugurtha Hadjar) Date: Fri, 20 Sep 2013 17:45:26 +0100 Subject: Antispam measures circumventing In-Reply-To: <523C6402.7090501@gmail.com> References: <523C6402.7090501@gmail.com> Message-ID: <523C7BA6.20902@gmail.com> Chris, Vlastimil, great insights gentlemen! Thanks Chris Angelico wrote: >Instead of matching the ones that are the same as their uppercase >version, why not instead keep the ones that are the same as their >lowercase? That's why I started off doing, and then lost track a bit. It didn't cross my mind that '.' and '@' are uncased characters and I'm a bit ashamed of not thinking about that before running the code (i.e: '.'.lower() gives False '.'.upper() gives False And the same for '@'. So unless you specifically "spare" them, they'll be whacked if you exclude upper case characters, or only include lower case characters). >Ah, now you're getting into the realm of CAPTCHAs. I'll be quite frank >with you: Don't bother. Many MANY experts are already looking into it Yeah.. I thought of writing "My e-mail is my first name, dot, my last name at gmail dot com". Some "riddling" can be viable to a certain extent. Or if your e-mail is ba86rockstar at gm.bu ba, then 86, then rock, then star, at gm dot bu. Or the e-mail can be generated dynamically calling a script that assembles pieces and displays it. This way, it can escape scrapers and all and will make it hard to manually harvest e-mails.. Which brings us to your next point about e-mail harvesters and that kind of labor (which is astounding !). > email = 'REMOVEMEjohn.doSPAMeSPAM at REMOVEMEhotmail.com' > ''.join(filter(lambda x: x==x.lower(),email)) >'john.doe at hotmail.com' Nice ! As well as Vlastimil's suggestions. The things I found on the net weren't that well written. There were *way* too many lines that made me think "No way. There's gotta be a better way". -- ~Jugurtha Hadjar, From joel.goldstick at gmail.com Fri Sep 20 15:02:50 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 20 Sep 2013 15:02:50 -0400 Subject: Antispam measures circumventing In-Reply-To: <523C7BA6.20902@gmail.com> References: <523C6402.7090501@gmail.com> <523C7BA6.20902@gmail.com> Message-ID: On Fri, Sep 20, 2013 at 12:45 PM, Jugurtha Hadjar wrote: > Chris, Vlastimil, great insights gentlemen! Thanks > > > Chris Angelico wrote: > > >Instead of matching the ones that are the same as their uppercase > >version, why not instead keep the ones that are the same as their > >lowercase? > > > That's why I started off doing, and then lost track a bit. It didn't cross > my mind that '.' and '@' are uncased characters and I'm a bit ashamed of > not thinking about that before running the code > > (i.e: > > '.'.lower() gives False > '.'.upper() gives False > > And the same for '@'. So unless you specifically "spare" them, they'll be > whacked if you exclude upper case characters, or only include lower case > characters). > > > >Ah, now you're getting into the realm of CAPTCHAs. I'll be quite frank > >with you: Don't bother. Many MANY experts are already looking into it > > Yeah.. I thought of writing "My e-mail is my first name, dot, my last name > at gmail dot com". > > Some "riddling" can be viable to a certain extent. Or if your e-mail is > ba86rockstar at gm.bu > > ba, then 86, then rock, then star, at gm dot bu. > > Or the e-mail can be generated dynamically calling a script that assembles > pieces and displays it. This way, it can escape scrapers and all and will > make it hard to manually harvest e-mails.. Which brings us to your next > point about e-mail harvesters and that kind of labor (which is astounding > !). > > > > > > > email = 'REMOVEMEjohn.doSPAMeSPAM@**REMOVEMEhotmail.com' > > ''.join(filter(lambda x: x==x.lower(),email)) > >'john.doe at hotmail.com' > > Nice ! As well as Vlastimil's suggestions. The things I found on the net > weren't that well written. There were *way* too many lines that made me > think "No way. There's gotta be a better way". > > > > > > > > -- > ~Jugurtha Hadjar, > -- > https://mail.python.org/**mailman/listinfo/python-list > Last year I was playing around with django forms and wrote some code that required the user to add some numbers before the form was submitted. Here is the article: http://www.joelgoldstick.com/blog/2012/sep/30/django-forms/ This isn't exactly what you are asking, but it does give you a change to let someone send you mail without giving out your email address. With the onslaught of social media stuff, it feels like sites like linked in and anything that uses gmail want to get you to give away your email address, and perhaps give access to everyone in your lists. So, I'm suggesting its really a loosing battle. -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From jugurtha.hadjar at gmail.com Sun Sep 22 06:10:13 2013 From: jugurtha.hadjar at gmail.com (Jugurtha Hadjar) Date: Sun, 22 Sep 2013 11:10:13 +0100 Subject: Antispam measures circumventing In-Reply-To: References: <523C6402.7090501@gmail.com> <523C7BA6.20902@gmail.com> Message-ID: <523EC205.1030904@gmail.com> On 09/20/2013 08:02 PM, Joel Goldstick wrote: > > Last year I was playing around with django forms and wrote some code > that required the user to add some numbers before the form was > submitted. Here is the article: > http://www.joelgoldstick.com/blog/2012/sep/30/django-forms/ > > This isn't exactly what you are asking, but it does give you a change to > let someone send you mail without giving out your email address. > Still interesting. Anything to fight spam. I was thinking more about when your e-mail address is out there (in mailing lists, for example). Some lists do the effort to at least do the (dot) and (at) kung fu to hide your address to a certain degree. Others just put it as a low-hanging fruit, in ole' plain text, ready to harvest. I joined my e-mail address in the code comment, that's why I was thinking that way. > With the onslaught of social media stuff, it feels like sites like > linked in and anything that uses gmail want to get you to give away your > email address, and perhaps give access to everyone in your lists. So, > I'm suggesting its really a loosing battle. > You don't say! There's a Firefox add-on called "Collusion" that shows how websites exchange your data between them and let me tell you: It's not reassuring. > -- > Joel Goldstick > http://joelgoldstick.com -- ~Jugurtha Hadjar, From gmane at kalleguld.dk Fri Sep 20 11:21:20 2013 From: gmane at kalleguld.dk (Kasper Guldmann) Date: Fri, 20 Sep 2013 15:21:20 +0000 (UTC) Subject: lambda - strange behavior Message-ID: I was playing around with lambda functions, but I cannot seem to fully grasp them. I was running the script below in Python 2.7.5, and it doesn't do what I want it to. Are lambda functions really supposed to work that way. How do I make it work as I intend? f = [] for n in range(5): f.append( lambda x: x*n ) assert( f[4](2) == 8 ) assert( f[3](3) == 9 ) assert( f[2](2) == 4 ) assert( f[1](8) == 8 ) assert( f[0](2) == 0 ) From rosuav at gmail.com Fri Sep 20 11:47:50 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 21 Sep 2013 01:47:50 +1000 Subject: lambda - strange behavior In-Reply-To: References: Message-ID: On Sat, Sep 21, 2013 at 1:21 AM, Kasper Guldmann wrote: > f = [] > for n in range(5): > f.append( lambda x: x*n ) You're leaving n as a free variable here. The lambda function will happily look to an enclosing scope, so this doesn't work. But there is a neat trick you can do: f = [] for n in range(5): f.append( lambda x,n=n: x*n ) You declare n as a second parameter, with a default value of the current n. The two n's are technically completely separate, and one of them is bound within the lambda. BTW, any time you have a loop appending to a list, see if you can make it a comprehension instead: f = [lambda x,n=n: x*n for n in range(5)] Often reads better, may execute better too. ChrisA From sg552 at hotmail.co.uk Fri Sep 20 11:52:08 2013 From: sg552 at hotmail.co.uk (Rotwang) Date: Fri, 20 Sep 2013 16:52:08 +0100 Subject: lambda - strange behavior In-Reply-To: References: Message-ID: On 20/09/2013 16:21, Kasper Guldmann wrote: > I was playing around with lambda functions, but I cannot seem to fully grasp > them. I was running the script below in Python 2.7.5, and it doesn't do what > I want it to. Are lambda functions really supposed to work that way. How do > I make it work as I intend? > > f = [] > for n in range(5): > f.append( lambda x: x*n ) > > assert( f[4](2) == 8 ) > assert( f[3](3) == 9 ) > assert( f[2](2) == 4 ) > assert( f[1](8) == 8 ) > assert( f[0](2) == 0 ) This is a common gotcha. In the function "lambda x: x*n" n is a global variable, which means that when the function is called it searches globals() for the current value of n, which is 4 (since that was its value when the for loop ended). There are several ways to define functions that depend on the values bound to names at creation time, like you're trying to do. One is to use the fact that default function arguments are evaluated when the function is created. So this will work: f = [] for n in range(5): f.append(lambda x, n = n: x*n) Another is to use the fact that arguments passed in function calls are evaluated when the function is called. That means that you can define a function which takes a parameter as an argument and returns a function which depends on that parameter to get the desired behaviour, like this: f = [] for n in range(5): f.append((lambda n: lambda x: x*n)(n)) From rustompmody at gmail.com Fri Sep 20 12:25:08 2013 From: rustompmody at gmail.com (rusi) Date: Fri, 20 Sep 2013 09:25:08 -0700 (PDT) Subject: lambda - strange behavior In-Reply-To: References: Message-ID: <57ea049c-8b78-43ff-a14c-b9b4b3e5e2a4@googlegroups.com> On Friday, September 20, 2013 8:51:20 PM UTC+5:30, Kasper Guldmann wrote: > I was playing around with lambda functions, but I cannot seem to fully grasp > them. I was running the script below in Python 2.7.5, and it doesn't do what > I want it to. Are lambda functions really supposed to work that way. How do > I make it work as I intend? > > f = [] > for n in range(5): > f.append( lambda x: x*n ) > > assert( f[4](2) == 8 ) > assert( f[3](3) == 9 ) > assert( f[2](2) == 4 ) > assert( f[1](8) == 8 ) > assert( f[0](2) == 0 ) You are not wrong in being surprised. Here's the python rewritten in a more functional style And then the same in haskell. $ python3 Python 3.3.2+ (default, Jun 13 2013, 13:47:13) [GCC 4.8.1] on linux Type "help", "copyright", "credits" or "license" for more information. >>> fl= [lambda x: x + n for n in range(5)] >>> [f(1) for f in fl] [5, 5, 5, 5, 5] >>> -------haskell----- $ ghci GHCi, version 7.4.1: http://www.haskell.org/ghc/ :? for help Prelude> let fl = [\x-> x+n | n <- [0..4]] Prelude> [f 1 | f <- fl] [1,2,3,4,5] Prelude> From jpiitula at ling.helsinki.fi Fri Sep 20 12:30:05 2013 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 20 Sep 2013 19:30:05 +0300 Subject: lambda - strange behavior References: Message-ID: Kasper Guldmann writes: > I was playing around with lambda functions, but I cannot seem to > fully grasp them. I was running the script below in Python 2.7.5, > and it doesn't do what I want it to. Are lambda functions really > supposed to work that way. How do I make it work as I intend? > > f = [] > for n in range(5): > f.append( lambda x: x*n ) > > assert( f[4](2) == 8 ) > assert( f[3](3) == 9 ) > assert( f[2](2) == 4 ) > assert( f[1](8) == 8 ) > assert( f[0](2) == 0 ) It's not the lambda, it's the for. All five functions share the one n, whose value the for changes in each iteration so that the last value remains in force after the loop. There's a trick: f.append( lambda x, n=n: x*n ). Now the lambda gets to remember the value of the n of the for as the default value of its own local n. From babmis307 at gmail.com Fri Sep 20 11:51:46 2013 From: babmis307 at gmail.com (bab mis) Date: Fri, 20 Sep 2013 08:51:46 -0700 (PDT) Subject: dynamic function parameters for **kwargs Message-ID: Hi , I have a function as below: def func(**kwargs): ... ... ==== args="a='b',c='d'" i want to call func(args) so that my function call will take a var as an parameter. it fails with an error "typeError: fun() takes exactly 0 arguments (1 given)" . Is there any other way to get the same. From stascrash at gmail.com Fri Sep 20 12:04:25 2013 From: stascrash at gmail.com (stas poritskiy) Date: Fri, 20 Sep 2013 09:04:25 -0700 (PDT) Subject: dynamic function parameters for **kwargs In-Reply-To: References: Message-ID: <95bdc1d4-e4ff-45d9-bfc4-ae7ff4a2aea0@googlegroups.com> On Friday, September 20, 2013 10:51:46 AM UTC-5, bab mis wrote: > Hi , > > I have a function as below: > > > > def func(**kwargs): > > ... > > ... > > > > > > > > ==== > > args="a='b',c='d'" > > > > i want to call func(args) so that my function call will take a var as an parameter. > > > > it fails with an error "typeError: fun() takes exactly 0 arguments (1 given)" > > > > . Is there any other way to get the same. Hi, may be this will be useful to you: http://simeonfranklin.com/blog/2012/jul/1/python-decorators-in-12-steps/ Go to Section 11 in the document. From sg552 at hotmail.co.uk Fri Sep 20 12:08:13 2013 From: sg552 at hotmail.co.uk (Rotwang) Date: Fri, 20 Sep 2013 17:08:13 +0100 Subject: dynamic function parameters for **kwargs In-Reply-To: References: Message-ID: On 20/09/2013 16:51, bab mis wrote: > Hi , > I have a function as below: > > def func(**kwargs): > ... > ... > > > > ==== > args="a='b',c='d'" > > i want to call func(args) so that my function call will take a var as an parameter. > it fails with an error "typeError: fun() takes exactly 0 arguments (1 given)" > . Is there any other way to get the same. It fails because args is a string and func(args) is passing a single string as a positional argument to func, rather than passing the keyword arguments a and c. Not sure if I've understood your question, but args = {'a': 'b', 'c': 'd'} # or equivalently args = dict(a='b', c='d') func(**args) will work. If you need args to be a string like the one in your post then you could try eval('func(%s)' % args) or func(**eval('dict(%s)' % args)) but that's only something that should be done if you trust the user who will decide what args is (since malicious code passed to eval() can do pretty much anything). From rui.vapps at gmail.com Fri Sep 20 13:17:56 2013 From: rui.vapps at gmail.com (Ray) Date: Fri, 20 Sep 2013 10:17:56 -0700 (PDT) Subject: matplotlib question: OverflowError: Allocated too many blocks Message-ID: <863fd2f3-7855-4afd-a735-bda8e35bb91a@googlegroups.com> hi, i'm using matplotlib to generate chart from audio wave file, and I had a problem with it. test code as: from scipy.io import wavfile import matplotlib.pyplot as plt rate, x = wavfile.read('test2.wav') plt.plot(x) plt.savefig('test2.png') the len of x= 19531840 (as len(x) ) matplotlib give exception: OverflowError: Allocated too many blocks if I display it by: plt.draw() plt.show() everything works fine. it seems I just can't save the output to a file. I know if I reduce the figsize would make it work. [aka plt.subplots(figsize=(5,2)) ] but this is not what I need. I need to generate the large chart. (depends on size of input file) anyone know if there's another way to "save" big output file? From jabba.laci at gmail.com Fri Sep 20 13:28:54 2013 From: jabba.laci at gmail.com (Jabba Laci) Date: Fri, 20 Sep 2013 19:28:54 +0200 Subject: building an online judge to evaluate Python programs Message-ID: Hi, In our school I have an introductory Python course. I have collected a large list of exercises for the students and I would like them to be able to test their solutions with an online judge ( http://en.wikipedia.org/wiki/Online_judge ). At the moment I have a very simple web application that is similar to Project Euler: you provide the ID of the exercise and the output of the program, and it tells you if it's correct or not. However, it can only be used with programs that produce an output (usually a short string or a number). In the next step I would like to do the following. The user can upload his/her script, and the system tests it with various inputs and tells you if it's OK or not (like checkio.org for instance). How to get started with this? There are several questions: * What is someone sends an infinite loop? There should be a time limit. * What is someone sends a malicious code? The script should be run in a sandbox. All tips are appreciated. Thanks, Laszlo From asmbansal2 at gmail.com Fri Sep 20 13:57:38 2013 From: asmbansal2 at gmail.com (Aseem Bansal) Date: Fri, 20 Sep 2013 10:57:38 -0700 (PDT) Subject: building an online judge to evaluate Python programs In-Reply-To: References: Message-ID: >However, it can only be used with programs that produce an output Just interested, what else are you thinking of checking? From jabba.laci at gmail.com Fri Sep 20 14:30:12 2013 From: jabba.laci at gmail.com (Jabba Laci) Date: Fri, 20 Sep 2013 20:30:12 +0200 Subject: building an online judge to evaluate Python programs In-Reply-To: References: Message-ID: Let's take this simple exercise: "Write a function that receives a list and decides whether the list is sorted or not." Here the output of the function is either True or False, so I cannot test it with my current method. Laszlo On Fri, Sep 20, 2013 at 7:57 PM, Aseem Bansal wrote: >>However, it can only be used with programs that produce an output > > Just interested, what else are you thinking of checking? > -- > https://mail.python.org/mailman/listinfo/python-list From gordon at panix.com Fri Sep 20 15:34:02 2013 From: gordon at panix.com (John Gordon) Date: Fri, 20 Sep 2013 19:34:02 +0000 (UTC) Subject: building an online judge to evaluate Python programs References: Message-ID: In Jabba Laci writes: > Let's take this simple exercise: > "Write a function that receives a list and decides whether the list is > sorted or not." > Here the output of the function is either True or False, so I cannot > test it with my current method. Make a master input file and a master output file for each exercise. If the student program's output matches the master output when run from the master input, then it is correct. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From gordon at panix.com Fri Sep 20 16:08:23 2013 From: gordon at panix.com (John Gordon) Date: Fri, 20 Sep 2013 20:08:23 +0000 (UTC) Subject: building an online judge to evaluate Python programs References: Message-ID: In Jabba Laci writes: > There are several questions: > * What is someone sends an infinite loop? There should be a time limit. You could run the judge as a background process, and kill it after ten seconds if it hasn't finished. > * What is someone sends a malicious code? The script should be run in a > sandbox. You could run the judge from its own account that doesn't have access to anything else. For extra security, make the judge program itself owned by a separate account (but readable/executable by the judge account.) I suppose you'd have to disable mail access from the judge account too. Not sure how to easily do that. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From jabba.laci at gmail.com Fri Sep 20 18:26:40 2013 From: jabba.laci at gmail.com (Jabba Laci) Date: Sat, 21 Sep 2013 00:26:40 +0200 Subject: building an online judge to evaluate Python programs In-Reply-To: References: Message-ID: I just found Docker ( http://docs.docker.io/en/latest/faq/ ). It seems sandboxing could be done with this easily. Laszlo On Fri, Sep 20, 2013 at 10:08 PM, John Gordon wrote: > In Jabba Laci writes: > >> There are several questions: >> * What is someone sends an infinite loop? There should be a time limit. > > You could run the judge as a background process, and kill it after ten > seconds if it hasn't finished. > >> * What is someone sends a malicious code? The script should be run in a >> sandbox. > > You could run the judge from its own account that doesn't have access to > anything else. For extra security, make the judge program itself owned by > a separate account (but readable/executable by the judge account.) > > I suppose you'd have to disable mail access from the judge account too. > Not sure how to easily do that. > > -- > John Gordon A is for Amy, who fell down the stairs > gordon at panix.com B is for Basil, assaulted by bears > -- Edward Gorey, "The Gashlycrumb Tinies" > > -- > https://mail.python.org/mailman/listinfo/python-list From ned at nedbatchelder.com Fri Sep 20 18:46:10 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 20 Sep 2013 18:46:10 -0400 Subject: building an online judge to evaluate Python programs In-Reply-To: References: Message-ID: <523CD032.6000205@nedbatchelder.com> On 9/20/13 6:26 PM, Jabba Laci wrote: > I just found Docker ( http://docs.docker.io/en/latest/faq/ ). It seems > sandboxing could be done with this easily. At edX, I wrote CodeJail (https://github.com/edx/codejail) to use AppArmor to run Python securely. For grading Python programs, we use a unit-test like series of challenges. The student writes problems as functions (or classes), and we execute them with unit tests (not literally unittest, but a similar idea). We also tokenize the code to check for simple things like, did you use a while loop when the requirement was to write a recursive function. The grading code is not open-source, unfortunately, because it is part of the MIT courseware. --Ned. > Laszlo > > On Fri, Sep 20, 2013 at 10:08 PM, John Gordon wrote: >> In Jabba Laci writes: >> >>> There are several questions: >>> * What is someone sends an infinite loop? There should be a time limit. >> You could run the judge as a background process, and kill it after ten >> seconds if it hasn't finished. >> >>> * What is someone sends a malicious code? The script should be run in a >>> sandbox. >> You could run the judge from its own account that doesn't have access to >> anything else. For extra security, make the judge program itself owned by >> a separate account (but readable/executable by the judge account.) >> >> I suppose you'd have to disable mail access from the judge account too. >> Not sure how to easily do that. >> >> -- >> John Gordon A is for Amy, who fell down the stairs >> gordon at panix.com B is for Basil, assaulted by bears >> -- Edward Gorey, "The Gashlycrumb Tinies" >> >> -- >> https://mail.python.org/mailman/listinfo/python-list From jabba.laci at gmail.com Sat Sep 21 15:57:17 2013 From: jabba.laci at gmail.com (Jabba Laci) Date: Sat, 21 Sep 2013 21:57:17 +0200 Subject: building an online judge to evaluate Python programs In-Reply-To: <523CD032.6000205@nedbatchelder.com> References: <523CD032.6000205@nedbatchelder.com> Message-ID: Hi Ned, Could you please post here your AppArmor profile for restricted Python scripts? Thanks, Laszlo On Sat, Sep 21, 2013 at 12:46 AM, Ned Batchelder wrote: > On 9/20/13 6:26 PM, Jabba Laci wrote: >> >> I just found Docker ( http://docs.docker.io/en/latest/faq/ ). It seems >> sandboxing could be done with this easily. > > > At edX, I wrote CodeJail (https://github.com/edx/codejail) to use AppArmor > to run Python securely. > > For grading Python programs, we use a unit-test like series of challenges. > The student writes problems as functions (or classes), and we execute them > with unit tests (not literally unittest, but a similar idea). We also > tokenize the code to check for simple things like, did you use a while loop > when the requirement was to write a recursive function. The grading code is > not open-source, unfortunately, because it is part of the MIT courseware. > > --Ned. > >> Laszlo >> >> On Fri, Sep 20, 2013 at 10:08 PM, John Gordon wrote: >>> >>> In Jabba Laci >>> writes: >>> >>>> There are several questions: >>>> * What is someone sends an infinite loop? There should be a time limit. >>> >>> You could run the judge as a background process, and kill it after ten >>> seconds if it hasn't finished. >>> >>>> * What is someone sends a malicious code? The script should be run in a >>>> sandbox. >>> >>> You could run the judge from its own account that doesn't have access to >>> anything else. For extra security, make the judge program itself owned >>> by >>> a separate account (but readable/executable by the judge account.) >>> >>> I suppose you'd have to disable mail access from the judge account too. >>> Not sure how to easily do that. >>> >>> -- >>> John Gordon A is for Amy, who fell down the stairs >>> gordon at panix.com B is for Basil, assaulted by bears >>> -- Edward Gorey, "The Gashlycrumb >>> Tinies" >>> >>> -- >>> https://mail.python.org/mailman/listinfo/python-list > > From ned at nedbatchelder.com Sat Sep 21 16:29:08 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 21 Sep 2013 16:29:08 -0400 Subject: building an online judge to evaluate Python programs In-Reply-To: References: <523CD032.6000205@nedbatchelder.com> Message-ID: <523E0194.7060900@nedbatchelder.com> On 9/21/13 3:57 PM, Jabba Laci wrote: > Hi Ned, > > Could you please post here your AppArmor profile for restricted Python scripts? Laszlo, the instructions are in the README, including the AppArmor profile. It isn't much: #include /bin/python { #include #include /** mr, # If you have code that the sandbox must be able to access, add lines # pointing to those directories: /the/path/to/your/sandbox-packages/** r, /tmp/codejail-*/ rix, /tmp/codejail-*/** rix, } Note that there are other protections beyond AppArmor, setrlimits is also used to limit some resource use. --Ned. BTW: Top-posting makes it harder to follow threads of conversations, better form is to add your comments below the person you're replying to. > Thanks, > > Laszlo > > On Sat, Sep 21, 2013 at 12:46 AM, Ned Batchelder wrote: >> On 9/20/13 6:26 PM, Jabba Laci wrote: >>> I just found Docker ( http://docs.docker.io/en/latest/faq/ ). It seems >>> sandboxing could be done with this easily. >> >> At edX, I wrote CodeJail (https://github.com/edx/codejail) to use AppArmor >> to run Python securely. >> >> For grading Python programs, we use a unit-test like series of challenges. >> The student writes problems as functions (or classes), and we execute them >> with unit tests (not literally unittest, but a similar idea). We also >> tokenize the code to check for simple things like, did you use a while loop >> when the requirement was to write a recursive function. The grading code is >> not open-source, unfortunately, because it is part of the MIT courseware. >> >> --Ned. >> >>> Laszlo >>> >>> On Fri, Sep 20, 2013 at 10:08 PM, John Gordon wrote: >>>> In Jabba Laci >>>> writes: >>>> >>>>> There are several questions: >>>>> * What is someone sends an infinite loop? There should be a time limit. >>>> You could run the judge as a background process, and kill it after ten >>>> seconds if it hasn't finished. >>>> >>>>> * What is someone sends a malicious code? The script should be run in a >>>>> sandbox. >>>> You could run the judge from its own account that doesn't have access to >>>> anything else. For extra security, make the judge program itself owned >>>> by >>>> a separate account (but readable/executable by the judge account.) >>>> >>>> I suppose you'd have to disable mail access from the judge account too. >>>> Not sure how to easily do that. >>>> >>>> -- >>>> John Gordon A is for Amy, who fell down the stairs >>>> gordon at panix.com B is for Basil, assaulted by bears >>>> -- Edward Gorey, "The Gashlycrumb >>>> Tinies" >>>> >>>> -- >>>> https://mail.python.org/mailman/listinfo/python-list >> From davea at davea.name Fri Sep 20 15:55:24 2013 From: davea at davea.name (Dave Angel) Date: Fri, 20 Sep 2013 19:55:24 +0000 (UTC) Subject: building an online judge to evaluate Python programs References: Message-ID: On 20/9/2013 13:28, Jabba Laci wrote: > Hi, > > In our school I have an introductory Python course. I have collected a > large list of exercises for the students and I would like them to be > able to test their solutions with an online judge ( > http://en.wikipedia.org/wiki/Online_judge ). At the moment I have a > very simple web application that is similar to Project Euler: you > provide the ID of the exercise and the output of the program, and it > tells you if it's correct or not. However, it can only be used with > programs that produce an output (usually a short string or a number). > > In the next step I would like to do the following. The user can upload > his/her script, and the system tests it with various inputs and tells > you if it's OK or not (like checkio.org for instance). How to get > started with this? > > There are several questions: > * What is someone sends an infinite loop? There should be a time limit. > * What is someone sends a malicious code? The script should be run in a sandbox. > That last seems to me to be the biggie. Several times in the past few years, people in this mailing list have tried to build a safe sandbox. And each one was a big failure, for a hacker of sufficient interest. Some of them were spectacular failures. If you have to be safe from your user, Python may be the wrong language to give them. -- DaveA From jabba.laci at gmail.com Fri Sep 20 16:04:10 2013 From: jabba.laci at gmail.com (Jabba Laci) Date: Fri, 20 Sep 2013 22:04:10 +0200 Subject: building an online judge to evaluate Python programs In-Reply-To: References: Message-ID: > That last seems to me to be the biggie. Several times in the past few > years, people in this mailing list have tried to build a safe sandbox. > And each one was a big failure, for a hacker of sufficient interest. > Some of them were spectacular failures. > > If you have to be safe from your user, Python may be the wrong language > to give them. Well, the course is about Python and I want to test Python scripts... I've heard about "chroot jail" but I never used it. Wikipedia says: "A chroot on Unix operating systems is an operation that changes the apparent root directory for the current running process and its children. A program that is run in such a modified environment cannot name (and therefore normally not access) files outside the designated directory tree. The term "chroot" may refer to the chroot(2) system call or the chroot(8) wrapper program. The modified environment is called a "chroot jail"." I guess it could be used for sandboxing. Laszlo From tjreedy at udel.edu Fri Sep 20 18:43:04 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 20 Sep 2013 18:43:04 -0400 Subject: building an online judge to evaluate Python programs In-Reply-To: References: Message-ID: On 9/20/2013 4:04 PM, Jabba Laci wrote: >> That last seems to me to be the biggie. Several times in the past few >> years, people in this mailing list have tried to build a safe sandbox. >> And each one was a big failure, for a hacker of sufficient interest. >> Some of them were spectacular failures. >> >> If you have to be safe from your user, Python may be the wrong language >> to give them. > > Well, the course is about Python and I want to test Python scripts... > > I've heard about "chroot jail" but I never used it. Wikipedia says: > > "A chroot on Unix operating systems is an operation that changes the > apparent root directory for the current running process and its > children. A program that is run in such a modified environment cannot > name (and therefore normally not access) files outside the designated > directory tree. The term "chroot" may refer to the chroot(2) system > call or the chroot(8) wrapper program. The modified environment is > called a "chroot jail"." > > I guess it could be used for sandboxing. Perhaps running in a virtual environment helps. 3.3 comes with venv, which I believe is a version of virtualenv or something. -- Terry Jan Reedy From fabiosantosart at gmail.com Mon Sep 23 08:33:07 2013 From: fabiosantosart at gmail.com (=?ISO-8859-1?Q?F=E1bio_Santos?=) Date: Mon, 23 Sep 2013 12:33:07 +0000 Subject: building an online judge to evaluate Python programs In-Reply-To: References: Message-ID: On 20 Sep 2013 21:14, "Jabba Laci" wrote: > > > That last seems to me to be the biggie. Several times in the past few > > years, people in this mailing list have tried to build a safe sandbox. > > And each one was a big failure, for a hacker of sufficient interest. > > Some of them were spectacular failures. > > > > If you have to be safe from your user, Python may be the wrong language > > to give them. > > Well, the course is about Python and I want to test Python scripts... > > I've heard about "chroot jail" but I never used it. Wikipedia says: > > "A chroot on Unix operating systems is an operation that changes the > apparent root directory for the current running process and its > children. A program that is run in such a modified environment cannot > name (and therefore normally not access) files outside the designated > directory tree. The term "chroot" may refer to the chroot(2) system > call or the chroot(8) wrapper program. The modified environment is > called a "chroot jail"." > > I guess it could be used for sandboxing. > > Laszlo It may be a good start to whitelist the modules and builtins they are allowed to use. The ast module could be used to scan the source tree for import statements and run the imported modules through the whitelist. There should also be many ways to run a script with stripped-down builtins. Then you can control execution time and memory usage using an external tool. I'm quite sure this isn't all you need, but it can be a good place to start. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ned at nedbatchelder.com Mon Sep 23 09:20:06 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 23 Sep 2013 09:20:06 -0400 Subject: building an online judge to evaluate Python programs In-Reply-To: References: Message-ID: <52404006.1000801@nedbatchelder.com> On 9/23/13 8:33 AM, F?bio Santos wrote: > > > On 20 Sep 2013 21:14, "Jabba Laci" > wrote: > > > > > That last seems to me to be the biggie. Several times in the past few > > > years, people in this mailing list have tried to build a safe sandbox. > > > And each one was a big failure, for a hacker of sufficient interest. > > > Some of them were spectacular failures. > > > > > > If you have to be safe from your user, Python may be the wrong > language > > > to give them. > > > > Well, the course is about Python and I want to test Python scripts... > > > > I've heard about "chroot jail" but I never used it. Wikipedia says: > > > > "A chroot on Unix operating systems is an operation that changes the > > apparent root directory for the current running process and its > > children. A program that is run in such a modified environment cannot > > name (and therefore normally not access) files outside the designated > > directory tree. The term "chroot" may refer to the chroot(2) system > > call or the chroot(8) wrapper program. The modified environment is > > called a "chroot jail"." > > > > I guess it could be used for sandboxing. > > > > Laszlo > > It may be a good start to whitelist the modules and builtins they are > allowed to use. > > The ast module could be used to scan the source tree for import > statements and run the imported modules through the whitelist. > > There should also be many ways to run a script with stripped-down > builtins. > > Then you can control execution time and memory usage using an external > tool. > > I'm quite sure this isn't all you need, but it can be a good place to > start. > > Python really is too dynamic for any static analysis like this to help in the long run. It will stop people from doing the obvious things, but there will always be a way to circumvent it. Take a look here: Eval really is dangerous: http://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html If you want to run untrusted Python code and prevent malice (or stupidity) from harming you, you need OS-level protection. --Ned. -------------- next part -------------- An HTML attachment was scrubbed... URL: From modulok at gmail.com Mon Sep 23 13:32:08 2013 From: modulok at gmail.com (Modulok) Date: Mon, 23 Sep 2013 11:32:08 -0600 Subject: building an online judge to evaluate Python programs In-Reply-To: <52404006.1000801@nedbatchelder.com> References: <52404006.1000801@nedbatchelder.com> Message-ID: > > > If you want to run untrusted Python code and prevent malice (or stupidity) > from harming you, you need OS-level protection. > > Agreed. Just for fun here's a simple example of what could be an honest mistake that consumes all physical memory and swap. A well behaved kernel will kill the process eventually when it can no longer allocate memory, but not before bringing the machine to its knees: class Foo(object): def __init__(self): self.x = 1 def __iter__(self): return self def next(self): self.x += 1 # Oops. In a well behaved iterator this should eventually # raise 'StopIteration'. I knew I forgot something. a = Foo() b = list(a) -Modulok- -------------- next part -------------- An HTML attachment was scrubbed... URL: From orgnut at yahoo.com Mon Sep 23 23:04:55 2013 From: orgnut at yahoo.com (Larry Hudson) Date: Mon, 23 Sep 2013 20:04:55 -0700 Subject: building an online judge to evaluate Python programs In-Reply-To: References: Message-ID: On 09/23/2013 06:20 AM, Ned Batchelder wrote: > If you want to run untrusted Python code and prevent malice (or stupidity) from harming you, you > need OS-level protection. > > --Ned. > That reminds me of the quote from Albert Einstein, (paraphrased): "There are only two things that are infinite, the universe and human stupidity. And I'm not sure about the universe." -=- Larry -=- From modulok at gmail.com Sat Sep 21 07:50:07 2013 From: modulok at gmail.com (Modulok) Date: Sat, 21 Sep 2013 05:50:07 -0600 Subject: building an online judge to evaluate Python programs In-Reply-To: References: Message-ID: On Fri, Sep 20, 2013 at 11:28 AM, Jabba Laci wrote: > Hi, > > In our school I have an introductory Python course. I have collected a > large list of exercises for the students and I would like them to be > able to test their solutions with an online judge ( > http://en.wikipedia.org/wiki/Online_judge ). At the moment I have a > very simple web application that is similar to Project Euler: you > provide the ID of the exercise and the output of the program, and it > tells you if it's correct or not. However, it can only be used with > programs that produce an output (usually a short string or a number). > > In the next step I would like to do the following. The user can upload > his/her script, and the system tests it with various inputs and tells > you if it's OK or not (like checkio.org for instance). How to get > started with this? > > There are several questions: > * What is someone sends an infinite loop? There should be a time limit. > * What is someone sends a malicious code? The script should be run in a > sandbox. > > All tips are appreciated. > > Thanks, > > Laszlo > -- > https://mail.python.org/mailman/listinfo/python-list How much time is it worth? Here's some ideas: Build a server just for grading student work that contains no valuable data, probably a virtual server on another machine. Something like virtualBox, etc. The code they submit is executed as a less privileged operating system user. For added security, you could look into using something like FreeBSD process jails but there's a learning curve there. I would not be overly concerned with security - put out a bounty as extra credit: He who hacks the server through the judge program, and provides details on how they did it, wins something great, even if it's just class notoriety. What is someone sends an infinite loop? There should be a time limit: Run their code as a separate process. If the process or its children run too long, kill them. On similar grounds you can use operating system features to define limits on maximum memory, disk usage, maximum number of processes, etc. On FreeBSD this can done via the `limits` command, other operating systems have their own versions of the same thing. Limits are useful, they prevent things like exhausting physical memory. What is someone sends a malicious code? If the server contains no valuable data, there's not much damage they can do other than using it for email spam or perhaps shutting it down. You could prevent email spam by a few firewall rules. To protect the judge program itself from being hacked set its permission bits to read only. It is *extremely* difficult to create a sandbox without using operating system (kernel enforced) features and access controls i.e. permission bits, process jails, kernel enforced hardware resource limits, etc. Don't be tempted to try it without these or you will likely fail. So long as the student program is run in a process owned by another, less privileged system user account, it shouldn't be able to modify the judge process which started it. For extra security you could even put the judge program on its own file system mounted as read-only. The resulting grades themselves would have to be stored elsewhere obviously, perhaps another server that has strict check constraints on what constitutes valid input no different than any web service. You can have yet-another process or even a process on another server watchdog your judge system. Send it a few test programs every x minutes. If it fails to respond with the expected results in the expected time frame - kill it and restart it. Test again. If it still fails consider it hacked (or broken). Do any graduate students or teacher's assistants owe you favors? -Modulok- -------------- next part -------------- An HTML attachment was scrubbed... URL: From bingefeller at gmail.com Fri Sep 20 14:30:41 2013 From: bingefeller at gmail.com (bingefeller at gmail.com) Date: Fri, 20 Sep 2013 11:30:41 -0700 (PDT) Subject: pyGTK Help Needed Please Message-ID: <0951a583-c9d6-490f-806f-f8f07e805797@googlegroups.com> Hi folks, I'm trying to run a program called Nicotine+ on my Mac which is running 10.8.5. Nicotine+ requires GTK2, pyGTK2 and Python to run. I believe I have all of these installed via Macports (please see here - http://pastebin.com/nwmrpp2Y ) When I try to run Nicotine+ I get this message: '/Users/******/Downloads/nicotine+-1.2.16', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC', '/Library/Python/2.7/site-packages'] Exception: No module named pygtk If I run Python and type import pygtk I get this message: Traceback (most recent call last): File "", line 1, in ImportError: No module named pygtk can anyone help me please? From torriem at gmail.com Fri Sep 20 23:35:16 2013 From: torriem at gmail.com (Michael Torrie) Date: Fri, 20 Sep 2013 21:35:16 -0600 Subject: pyGTK Help Needed Please In-Reply-To: <0951a583-c9d6-490f-806f-f8f07e805797@googlegroups.com> References: <0951a583-c9d6-490f-806f-f8f07e805797@googlegroups.com> Message-ID: <523D13F4.8050000@gmail.com> On 09/20/2013 12:30 PM, bingefeller at gmail.com wrote: > Hi folks, > > I'm trying to run a program called Nicotine+ on my Mac which is running 10.8.5. Nicotine+ requires GTK2, pyGTK2 and Python to run. I believe I have all of these installed via Macports (please see here - http://pastebin.com/nwmrpp2Y ) > > When I try to run Nicotine+ I get this message: > > '/Users/******/Downloads/nicotine+-1.2.16', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC', '/Library/Python/2.7/site-packages'] > Exception: No module named pygtk > > > If I run Python and type import pygtk I get this message: > > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named pygtk > > > can anyone help me please? You probably need to run the program using the version of Python that's installed in MacPorts. Your system python does not know anything about MacPorts, so it obviously can't find pyGTK, since it's not in the system library location. I can't remember where MacPorts puts things, but presumably you'd have to do edit the nicotine+-1.2.16 file and change the first line to point to the MacPorts version of python. From spk265 at nyu.edu Fri Sep 20 17:32:12 2013 From: spk265 at nyu.edu (Shyam Parimal Katti) Date: Fri, 20 Sep 2013 17:32:12 -0400 Subject: Iterate through a list of tuples for processing Message-ID: I have a list of tuples where the number of rows in the list and the number of columns in tuples of the list will not be constant. i.e. list = [(a1,b1, ?z1), (a2,b2, ?, z2),?. ,(am,bm, ? , zm )]. It can be compared to the SQL results, as the number of columns change in the sql, the number of columns change in the list of tuples as well. I have to iterate through each element of each tuple in the list, perform some checks on the value, convert it and return the modified values as a new list of tuples. i.e. list_value = [(?name1?, 1234, ?address1? ), (?name2?, 5678, ?address2?), (?name3?, 1011, ?addre?ss3?)] I need to access each value to check if the value contains a double quote and enclose the string containing double quote with double quotes. The transformation should return list_value = [(?name1?, 1234, ?address1? ), (?name2?, 5678, ?address2?), (?name3?, 1011, ??addre?ss3??)] The simplest approach for me would be to do this: mod_val = [transform(row) for row in list_value] def transform(row): mod_list=[] while index < len(row): ... if isinstance(row[index],basestring): ... if '"' in row[index]: ... mod_list.append('"'+row[index]+'"') ... else: ... mod_list.append(row[index]) ... index = index+1 ... return mod_list Is there a way to make the code concise using list comprehension? -------------- next part -------------- An HTML attachment was scrubbed... URL: From vlastimil.brom at gmail.com Fri Sep 20 19:25:13 2013 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sat, 21 Sep 2013 01:25:13 +0200 Subject: Iterate through a list of tuples for processing In-Reply-To: References: Message-ID: 2013/9/20 Shyam Parimal Katti : > I have a list of tuples where the number of rows in the list and the number > of columns in tuples of the list will not be constant. i.e. > > ...> i.e. > > list_value = [(?name1?, 1234, ?address1? ), (?name2?, 5678, ?address2?), > (?name3?, 1011, ?addre?ss3?)] > > I need to access each value to check if the value contains a double quote > and enclose the string containing double quote with double quotes. The > transformation should return > > list_value = [(?name1?, 1234, ?address1? ), (?name2?, 5678, ?address2?), > (?name3?, 1011, ??addre?ss3??)] > > ...> > > > Is there a way to make the code concise using list comprehension? > > > -- > https://mail.python.org/mailman/listinfo/python-list > Hi, would the following do, what you want? >>> orig_list = [('name1', 1234, 'address1' ), ('name2', 5678, 'address2'), ('name3', 1011, 'addre"ss3')] >>> modif_list = [['"'+elem+'"' if isinstance(elem, basestring) and '"' in elem else elem for elem in row] for row in orig_list] >>> modif_list [['name1', 1234, 'address1'], ['name2', 5678, 'address2'], ['name3', 1011, '"addre"ss3"']] >>> I guess, you don't mind changing the inner tuples to lists, but the original structure could be retained as well: >>> [tuple(['"'+elem+'"' if isinstance(elem, basestring) and '"' in elem else elem for elem in row]) for row in orig_list] [('name1', 1234, 'address1'), ('name2', 5678, 'address2'), ('name3', 1011, '"addre"ss3"')] >>> Of course, you have to decide, whether the readability/conciseness suits your needs ... hth, vbr From anasdahany at gmail.com Fri Sep 20 17:57:30 2013 From: anasdahany at gmail.com (Sam) Date: Fri, 20 Sep 2013 14:57:30 -0700 (PDT) Subject: Print statement not printing as it suppose to Message-ID: <05bbf1a3-6480-48ee-8984-2482b90c79c0@googlegroups.com> hi everybody i am just starting to learn python, i was writing a simple i/o program but my print statement is acting weird. here is my code i want to know why it prints this way. thank you car=int(input("Lamborghini tune-up:")) rent=int(input('\nManhatan apartment: ')) gifts=int(input('\nRandom Gifts: ')) total=car+rent+gifts print("\nThe total amount required is ", total ) OUTPUT Lamborghini tune-up:1000 Manhatan apartment: 2300 Random Gifts: 234 ('\nThe total amount required is ', 3534) ===> the problem is obviously on the last print statement that is supposed to print the outut From timothy.c.delaney at gmail.com Fri Sep 20 18:11:26 2013 From: timothy.c.delaney at gmail.com (Tim Delaney) Date: Sat, 21 Sep 2013 08:11:26 +1000 Subject: Print statement not printing as it suppose to In-Reply-To: <05bbf1a3-6480-48ee-8984-2482b90c79c0@googlegroups.com> References: <05bbf1a3-6480-48ee-8984-2482b90c79c0@googlegroups.com> Message-ID: On 21 September 2013 07:57, Sam wrote: > hi everybody i am just starting to learn python, i was writing a simple > i/o program but my print statement is acting weird. here is my code i want > to know why it prints this way. thank you > > print("\nThe total amount required is ", total ) > > > OUTPUT > > ('\nThe total amount required is ', 3534) > > ===> the problem is obviously on the last print statement that is supposed > to print the outut > Check your version of Python. The output you have given says that you're using a Python 2 version, but the print syntax you're using is for Python 3. Unfortunately, you've hit one of the edge cases where they produce different output. As a general rule, either use % formatting or format()to produce a single string to print, rather than relying on print to output them correctly for you (or using string concatenation). Since you're only just starting you won't have got to them yet - the simplest way to to it is to just insert the string representation of all parameters. The above done using % formatting would be: print("\nThe total amount required is %s" % (total,)) which will produce the same output on both Python 2 and Python 3. Note the double space before %s - that matches your print statement (there would be soft-space inserted in your print statement, which is another reason not to rely on print for anything other than single strings). If you didn't want that extra space, it's easy to delete. Tim Delaney -------------- next part -------------- An HTML attachment was scrubbed... URL: From emiliano.firmino at gmail.com Fri Sep 20 18:11:28 2013 From: emiliano.firmino at gmail.com (Emiliano Carlos de Moraes Firmino) Date: Fri, 20 Sep 2013 18:11:28 -0400 Subject: Print statement not printing as it suppose to In-Reply-To: <05bbf1a3-6480-48ee-8984-2482b90c79c0@googlegroups.com> References: <05bbf1a3-6480-48ee-8984-2482b90c79c0@googlegroups.com> Message-ID: Remove both brackets in last line, You are creating a tuple in last statement not making a function call. 2013/9/20 Sam > hi everybody i am just starting to learn python, i was writing a simple > i/o program but my print statement is acting weird. here is my code i want > to know why it prints this way. thank you > > > car=int(input("Lamborghini tune-up:")) > > rent=int(input('\nManhatan apartment: ')) > > gifts=int(input('\nRandom Gifts: ')) > > total=car+rent+gifts > > print("\nThe total amount required is ", total ) > > > OUTPUT > > Lamborghini tune-up:1000 > > Manhatan apartment: 2300 > > Random Gifts: 234 > ('\nThe total amount required is ', 3534) > > > > ===> the problem is obviously on the last print statement that is supposed > to print the outut > -- > https://mail.python.org/mailman/listinfo/python-list > -- Emiliano Carlos de Moraes Firmino Desenvolvedor | PMT | INdT Universit?rio | Engenharia da Computa??o | UEA emiliano.firmino at gmail.com | (92) 9196-3922 -------------- next part -------------- An HTML attachment was scrubbed... URL: From gordon at panix.com Fri Sep 20 18:40:00 2013 From: gordon at panix.com (John Gordon) Date: Fri, 20 Sep 2013 22:40:00 +0000 (UTC) Subject: Print statement not printing as it suppose to References: <05bbf1a3-6480-48ee-8984-2482b90c79c0@googlegroups.com> Message-ID: In <05bbf1a3-6480-48ee-8984-2482b90c79c0 at googlegroups.com> Sam writes: > print("\nThe total amount required is ", total ) > OUTPUT > ('\nThe total amount required is ', 3534) In older versions of python (like the one you are using), 'print' is a statement instead of a function. In other words, it is used like this: name = "Bob" print "Hello ", name Because there are parentheses around the text to be printed, your version of python is interpreting it as a tuple. Remove the parentheses and you should be ok. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From rosuav at gmail.com Fri Sep 20 22:50:32 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 21 Sep 2013 12:50:32 +1000 Subject: Print statement not printing as it suppose to In-Reply-To: <05bbf1a3-6480-48ee-8984-2482b90c79c0@googlegroups.com> References: <05bbf1a3-6480-48ee-8984-2482b90c79c0@googlegroups.com> Message-ID: On Sat, Sep 21, 2013 at 7:57 AM, Sam wrote: > car=int(input("Lamborghini tune-up:")) > print("\nThe total amount required is ", total ) > OUTPUT > ('\nThe total amount required is ', 3534) As others have said, this output indicates that you're running under a Python 2.x interpreter. I strongly recommend you switch to running under Python 3.x - do not take the simple advice that might make it work in both, because you have other differences which will trip you up. In Python 2, the input function is extremely dangerous and should be avoided: it *evaluates* its argument. (If you really *want* to evaluate something, you can call the eval() function explicitly. You don't want it to be hidden behind the innocuously-named input().) Download Python 3.3 (or later) and start using that; you'll find it's by far the better interpreter - years of improvements on top of the version you're using there. ChrisA From davea at davea.name Sat Sep 21 00:40:04 2013 From: davea at davea.name (Dave Angel) Date: Sat, 21 Sep 2013 04:40:04 +0000 (UTC) Subject: Print statement not printing as it suppose to References: <05bbf1a3-6480-48ee-8984-2482b90c79c0@googlegroups.com> Message-ID: On 20/9/2013 17:57, Sam wrote: > > print("\nThe total amount required is ", total ) > > > ('\nThe total amount required is ', 3534) > > ===> the problem is obviously on the last print statement that is supposed to print the outut Others have pointed out the version discrepancy. But I'll also ask what you're learning Python from. If you've got a tutorial or book that uses Python 3.x, then forget 2.x and install 3.3 If you're learning it in a class, then the instructor should already have told you what version to use. It is possible to install both 2.7 and 3.3, but you probably don't need the confusion while you're learning. -- DaveA From dyeringamsa at gmail.com Fri Sep 20 22:45:29 2013 From: dyeringamsa at gmail.com (D.YAN ESCOLAR RAMBAL) Date: Fri, 20 Sep 2013 21:45:29 -0500 Subject: TypeError: only length-1 arrays can be converted to Python Message-ID: this the code, ______________________________________________________________ import math import numexpr as ne import matplotlib.pyplot as plt import numpy as np import numba as nb M = 10 A = 10 D = 0.1 xmin = -4 xmax = 4 n = 800 tfinal = 3 tinicial = 1 # GENERANDO VECTOR CON PUNTOS DE DISCRETIZACION X ESPACIADOS x= np.linspace(xmin, xmax, n) #GENERANDO FUNCION ANALITICA def Cdifuana(M,A,D,x,t): temp = A*math.sqrt(4*math.pi*D*t); Cdifuana = (M/temp)*math.exp(-x**2 /(4*D*t)) #GENERANDO CONDICION INICIAL C=(Cdifuana(M,A,D,x,tinicial)) ___________________________________________________________ In this code, I try obtain graph comparative the analytic and numerical solution for the diffusion equation in 1D, but whe I define the analytic function, run the phase, the compilator show me this message. Traceback (most recent call last): File "D:\Yan\Documents\Aptana Studio 3 Workspace\DIF1DMEDYER\SOLUCION NUMERICA PARA LA ECUACION DE LA DIFUSION EN 1D DYER", line 34, in C=(Cdifuana(M,A,D,x,tinicial)) File "D:\Yan\Documents\Aptana Studio 3 Workspace\DIF1DMEDYER\SOLUCION NUMERICA PARA LA ECUACION DE LA DIFUSION EN 1D DYER", line 32, in Cdifuana Cdifuana = (M/temp)*math.exp(-x**2 /(4*D*t)) TypeError: only length-1 arrays can be converted to Python -- *Gracias, cordialmente, * * * * * *ING. YANETH ESCOLAR RAMBAL* *HAFI Engineering & Consulting GmbH* *CEL: + 57 3166257245* *TEL: + 57 (1) 6508308* *TEL: ++43 5522 77924 0* *Fax: ++43 5522 74938* *Dir : Cll 72f no. 113-21 Torre 5 - 604 Bogot? Colombia* * Muehletorplatz 4-6, A-6800 Feldkirch, Austria* *www.hafi.cc/en/environ_en.htm* -------------- next part -------------- An HTML attachment was scrubbed... URL: From oscar.j.benjamin at gmail.com Sat Sep 21 07:02:15 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Sat, 21 Sep 2013 12:02:15 +0100 Subject: TypeError: only length-1 arrays can be converted to Python In-Reply-To: References: Message-ID: On Sep 21, 2013 7:40 AM, "D.YAN ESCOLAR RAMBAL" wrote: > > Traceback (most recent call last): > File "D:\Yan\Documents\Aptana Studio 3 Workspace\DIF1DMEDYER\SOLUCION NUMERICA PARA LA ECUACION DE LA DIFUSION EN 1D DYER", line 34, in > C=(Cdifuana(M,A,D,x,tinicial)) > File "D:\Yan\Documents\Aptana Studio 3 Workspace\DIF1DMEDYER\SOLUCION NUMERICA PARA LA ECUACION DE LA DIFUSION EN 1D DYER", line 32, in Cdifuana > Cdifuana = (M/temp)*math.exp(-x**2 /(4*D*t)) > TypeError: only length-1 arrays can be converted to Python > The math module doesn't work with numpy arrays. You should use numpy.exp() instead of math.exp(). Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From donsylvia95 at gmail.com Sat Sep 21 05:10:49 2013 From: donsylvia95 at gmail.com (Don Sylvia) Date: Sat, 21 Sep 2013 02:10:49 -0700 (PDT) Subject: In Python language, what is (void) referring to? Message-ID: <2e7e060c-c029-4e20-a0f4-6c7b312a8282@googlegroups.com> void...........? From kwpolska at gmail.com Sat Sep 21 05:21:20 2013 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Sat, 21 Sep 2013 11:21:20 +0200 Subject: In Python language, what is (void) referring to? In-Reply-To: <2e7e060c-c029-4e20-a0f4-6c7b312a8282@googlegroups.com> References: <2e7e060c-c029-4e20-a0f4-6c7b312a8282@googlegroups.com> Message-ID: On Sat, Sep 21, 2013 at 11:10 AM, Don Sylvia wrote: > void...........? > -- > https://mail.python.org/mailman/listinfo/python-list void does not exist in Python, unless you named a variable ?void?. In that case, it means whatever you set it to. -- Chris ?Kwpolska? Warrick PGP: 5EAAEA16 stop html mail | always bottom-post | only UTF-8 makes sense From rosuav at gmail.com Sat Sep 21 05:34:34 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 21 Sep 2013 19:34:34 +1000 Subject: In Python language, what is (void) referring to? In-Reply-To: <2e7e060c-c029-4e20-a0f4-6c7b312a8282@googlegroups.com> References: <2e7e060c-c029-4e20-a0f4-6c7b312a8282@googlegroups.com> Message-ID: On Sat, Sep 21, 2013 at 7:10 PM, Don Sylvia wrote: > void...........? > -- > https://mail.python.org/mailman/listinfo/python-list That looks like a C-style cast, though casting to void is unusual. If you're looking at the source code to CPython, you might find something like that. In C it usually means "I don't care about the return value of this function". ChrisA From steve+comp.lang.python at pearwood.info Sat Sep 21 05:59:11 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Sep 2013 09:59:11 GMT Subject: In Python language, what is (void) referring to? References: <2e7e060c-c029-4e20-a0f4-6c7b312a8282@googlegroups.com> Message-ID: <523d6def$0$29988$c3e8da3$5496439d@news.astraweb.com> On Sat, 21 Sep 2013 02:10:49 -0700, Don Sylvia wrote: > void...........? In Python, void doesn't mean anything. [steve at ando ~]$ python Python 2.7.2 (default, May 18 2012, 18:25:10) [GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> void Traceback (most recent call last): File "", line 1, in NameError: name 'void' is not defined What gave you the idea that void was part of Python? -- Steven From nikos.gr33k at gmail.com Sat Sep 21 05:58:21 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Sat, 21 Sep 2013 12:58:21 +0300 Subject: How to send an anonymous mail via Python script Message-ID: I'll have to ask this atgain because i got no proper reply: Here is the code i wrote to try tos end anonymous mail: # ================================================================================================================= # if html form is submitted then send user mail # ================================================================================================================= def random_char( y, chars=string.ascii_uppercase + string.digits ): return ''.join( random.choice(chars) for x in range(y) ) for times in range(0, 5): try: # prepare mail data FROM = random_char(8) + '@' + 'mail' + '.org' TO = "nikos.gr33k at gmail.com" SUBJECT = random_char( 50 ) MESSAGE = random_char( 500 ) os.system( "echo %s | mailx -v -r %s -s %s %s" % (MESSAGE, FROM, SUBJECT, TO) ) print( "

%s? ???????? ???? %s ?????????!

" % (times, TO) ) except Exception as e: print( "sendmail => ", date, repr( sys.exc_info() ) ) else: print( '''

??? ??????????? ? ????? ??? script ??? ?? ??????????????? ???????!''' ) sys.exit(0) ========================================================================================================================= Can you please tell me what alternation must be made in order to send this anonymously? that is my question. There must be a way. 1. either by python and its smtplib module 2. by configuring the local MTA 3. by using a remailer Please provide a solution with code if possible. I will only answer to serious replies. From rosuav at gmail.com Sat Sep 21 06:04:05 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 21 Sep 2013 20:04:05 +1000 Subject: How to send an anonymous mail via Python script In-Reply-To: References: Message-ID: On Sat, Sep 21, 2013 at 7:58 PM, ????? wrote: > Can you please tell me what alternation must be made in order to send this > anonymously? > > that is my question. There must be a way. No, there isn't. The nearest you could come to anonymous mail would be sending via a botnet (to hide your IP address) and forging the from address. So unless you *want* your mail to be flagged as spam and detested by the entire world, NO THERE IS NO WAY to send it anonymously. ChrisA From nikos.gr33k at gmail.com Sat Sep 21 06:15:58 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Sat, 21 Sep 2013 13:15:58 +0300 Subject: How to send an anonymous mail via Python script In-Reply-To: References: Message-ID: On 21/9/2013 1:04 ??, Chris Angelico wrote: > On Sat, Sep 21, 2013 at 7:58 PM, ????? wrote: >> Can you please tell me what alternation must be made in order to send this >> anonymously? >> >> that is my question. There must be a way. > > No, there isn't. The nearest you could come to anonymous mail would be > sending via a botnet (to hide your IP address) and forging the from > address. So unless you *want* your mail to be flagged as spam and > detested by the entire world, NO THERE IS NO WAY to send it > anonymously. > > ChrisA > How about an anonymous remailer then? From rosuav at gmail.com Sat Sep 21 06:41:25 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 21 Sep 2013 20:41:25 +1000 Subject: How to send an anonymous mail via Python script In-Reply-To: References: Message-ID: On Sat, Sep 21, 2013 at 8:15 PM, ????? wrote: > On 21/9/2013 1:04 ??, Chris Angelico wrote: >> >> On Sat, Sep 21, 2013 at 7:58 PM, ????? wrote: >>> >>> Can you please tell me what alternation must be made in order to send >>> this >>> anonymously? >>> >>> that is my question. There must be a way. >> >> >> No, there isn't. The nearest you could come to anonymous mail would be >> sending via a botnet (to hide your IP address) and forging the from >> address. So unless you *want* your mail to be flagged as spam and >> detested by the entire world, NO THERE IS NO WAY to send it >> anonymously. >> >> ChrisA >> > How about an anonymous remailer then? I'm going to spell this out for the benefit of anyone else who's reading this, because I know Nikos won't take any notice. This is a gross oversimplification, but I'm trying to condense everything into a single email. The internet can't be built on certainties, so it's built on trust. Especially with the detection of spam, it's mainly a matter of trust - trusting the sending computer, trusting the sending domain, and trusting that the email in question really was sent by that domain. Most anti-spam measures are aimed at one of those - for instance, SPF is all about demonstrating that the sending computer belongs to the sending domain, and DKIM is about matching the contents of the email to its domain. The receiving MTA has to decide: Do I trust this sender enough to accept this email, or will I reject it? As an example, my own mail server checks a lot of things, including: * How well the sender complies with the SMTP specification (if you can't get protocol right, I don't want to talk to you; if you deliberately violate protocol to try to conceal yourself, I definitely don't want to talk to you) * Whether the hostname and IP address match * Whether the reverse DNS for the IP address has four numbers in it (a common indication of home senders - c122-107-147-136.eburwd5.vic.optusnet.com.au looks like a home user); this doesn't prevent mail delivery, but it's marked down * The SPF record for the sending domain, if it has one * Certain source or destination addresses that have been blacklisted * Bayesian similarity to emails previously marked as spam * A few other details that I won't discuss in public, so you can't game the system and send me a pile of spam :) Some of these checks are "below the waterline" requirements - for instance, if you don't say HELO or EHLO at the beginning of your SMTP request, I'm not going to accept any mail from you. Others are "above the waterline" - I'll still take the mail, but it's more likely to go in the junk folder, because I don't trust you that much. Violating the internet's standards will often mean your mail gets rejected. There's a reason for that; trying to hide is usually a bad idea. Be honest; establish a domain and a (small) set of IP addresses that send its mail, and you can build up a record of trust ("Every message I've ever seen from foo.example.com (IP address 203.0.113.54 as per its SPF record) has been accepted by my users as legitimate, so I'm going to assume that this one, from the same domain and IP, is legit"). It's not even all that hard to do - just deploy one of the well-known mail servers like exim or Postfix, set up an SPF record (not actually necessary, but it's so easy and can help so much that I think everyone should do it), and let the rest take care of itself. ChrisA From joel.goldstick at gmail.com Sat Sep 21 12:09:53 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sat, 21 Sep 2013 12:09:53 -0400 Subject: How to send an anonymous mail via Python script In-Reply-To: References: Message-ID: On Sat, Sep 21, 2013 at 6:41 AM, Chris Angelico wrote: > On Sat, Sep 21, 2013 at 8:15 PM, ????? wrote: > > On 21/9/2013 1:04 ??, Chris Angelico wrote: > >> > >> On Sat, Sep 21, 2013 at 7:58 PM, ????? wrote: > >>> > >>> Can you please tell me what alternation must be made in order to send > >>> this > >>> anonymously? > >>> > >>> that is my question. There must be a way. > Nikos, stop! There very well may be a way to send spam. But you need to understand internet infrastructure, and be more clever than the many people who do understand the internet infrastructure and don't want to read spam. You can't do this because, as you have professed in other endless trolling threads, you don't like to read or study, you like people to give you answers. To me, that is the definition of laziness. The second reason you can't do this may be that you just don't want to do any of the things you ask here. Evidence of this would be that you repeat the same questions over and over, ignore the answers, quote other's as supporting your ruefully annoying wining, and then start a new thread just like the old thread with one of your many email aliases. That is the definition of a troll. This list is very informative when you disappear for a while. If your purpose is to single handedly degrade the experience of dozens of people with interesting questions, and volunteers who guide and teach others, well nice job. If by chance you are just an unfortunate soul with such large gaps in your self understanding of how rude your behavior here is, you should know that you are rude. So, stop it > >> > >> > >> No, there isn't. The nearest you could come to anonymous mail would be > >> sending via a botnet (to hide your IP address) and forging the from > >> address. So unless you *want* your mail to be flagged as spam and > >> detested by the entire world, NO THERE IS NO WAY to send it > >> anonymously. > >> > >> ChrisA > >> > > How about an anonymous remailer then? > > I'm going to spell this out for the benefit of anyone else who's > reading this, because I know Nikos won't take any notice. This is a > gross oversimplification, but I'm trying to condense everything into a > single email. > > The internet can't be built on certainties, so it's built on trust. > Especially with the detection of spam, it's mainly a matter of trust - > trusting the sending computer, trusting the sending domain, and > trusting that the email in question really was sent by that domain. > Most anti-spam measures are aimed at one of those - for instance, SPF > is all about demonstrating that the sending computer belongs to the > sending domain, and DKIM is about matching the contents of the email > to its domain. The receiving MTA has to decide: Do I trust this sender > enough to accept this email, or will I reject it? As an example, my > own mail server checks a lot of things, including: > * How well the sender complies with the SMTP specification (if you > can't get protocol right, I don't want to talk to you; if you > deliberately violate protocol to try to conceal yourself, I definitely > don't want to talk to you) > * Whether the hostname and IP address match > * Whether the reverse DNS for the IP address has four numbers in it (a > common indication of home senders - > c122-107-147-136.eburwd5.vic.optusnet.com.au looks like a home user); > this doesn't prevent mail delivery, but it's marked down > * The SPF record for the sending domain, if it has one > * Certain source or destination addresses that have been blacklisted > * Bayesian similarity to emails previously marked as spam > * A few other details that I won't discuss in public, so you can't > game the system and send me a pile of spam :) > > Some of these checks are "below the waterline" requirements - for > instance, if you don't say HELO or EHLO at the beginning of your SMTP > request, I'm not going to accept any mail from you. Others are "above > the waterline" - I'll still take the mail, but it's more likely to go > in the junk folder, because I don't trust you that much. > > Violating the internet's standards will often mean your mail gets > rejected. There's a reason for that; trying to hide is usually a bad > idea. Be honest; establish a domain and a (small) set of IP addresses > that send its mail, and you can build up a record of trust ("Every > message I've ever seen from foo.example.com (IP address 203.0.113.54 > as per its SPF record) has been accepted by my users as legitimate, so > I'm going to assume that this one, from the same domain and IP, is > legit"). It's not even all that hard to do - just deploy one of the > well-known mail servers like exim or Postfix, set up an SPF record > (not actually necessary, but it's so easy and can help so much that I > think everyone should do it), and let the rest take care of itself. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From alister.ware at ntlworld.com Tue Sep 24 07:36:16 2013 From: alister.ware at ntlworld.com (Alister) Date: Tue, 24 Sep 2013 11:36:16 GMT Subject: How to send an anonymous mail via Python script References: Message-ID: On Sat, 21 Sep 2013 20:41:25 +1000, Chris Angelico wrote: > On Sat, Sep 21, 2013 at 8:15 PM, ????? wrote: >> On 21/9/2013 1:04 ??, Chris Angelico wrote: >>> >>> On Sat, Sep 21, 2013 at 7:58 PM, ????? wrote: >>>> >>>> Can you please tell me what alternation must be made in order to send >>>> this anonymously? >>>> >>>> that is my question. There must be a way. >>> >>> >>> No, there isn't. The nearest you could come to anonymous mail would be >>> sending via a botnet (to hide your IP address) and forging the from >>> address. So unless you *want* your mail to be flagged as spam and >>> detested by the entire world, NO THERE IS NO WAY to send it >>> anonymously. >>> >>> ChrisA >>> >> How about an anonymous remailer then? > > I'm going to spell this out for the benefit of anyone else who's reading > this, because I know Nikos won't take any notice. This is a gross > oversimplification, but I'm trying to condense everything into a single > email. > To put it even more simply If you have a legitimate reason to send me emails then you have no legitimate reason to withhold your true Identity. if you do I will assume you are a crook. if you are asking for advise on how to achieve this I will assume you want to be a crook and will not provide any assistance. -- No man would listen to you talk if he didn't know it was his turn next. -- E.W. Howe From steve+comp.lang.python at pearwood.info Tue Sep 24 08:29:14 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 24 Sep 2013 12:29:14 GMT Subject: How to send an anonymous mail via Python script References: Message-ID: <5241859a$0$29992$c3e8da3$5496439d@news.astraweb.com> On Tue, 24 Sep 2013 11:36:16 +0000, Alister wrote: > To put it even more simply > If you have a legitimate reason to send me emails then you have no > legitimate reason to withhold your true Identity. "Dear Alister, Forgive this anonymous email, but I don't wish to get fired from my job and sued for breaking the confidentiality agreement I signed, but somebody needs to speak out about this matter. You need to know that the company I work for, Acme Ltd, is illegally dumping radioactive waste in the street where you live in the form of extremely fine powder which blows all over the street, into your home and garden. Attached is the evidence for this, proving that knowledge of this dumping goes all the way to the company board. I suggest you talk to your lawyer before your children develop mutant superpowers, or possibly cancer, whichever happens first." Whistleblower laws are useless. Sometimes people need to remain anonymous. Even when whistleblower laws have teeth, sometimes it's just better to keep your identity unknown. However, in the specific case of Nikos, I cannot imagine any legitimate reason for him to be sending anonymous emails to his website users. I've asked him to explain, but he hasn't. I can only conclude that he is intending to send spam, or otherwise act unethically or even criminally. Even if I knew how to write an anonymous mail server, I wouldn't help him. -- Steven From rosuav at gmail.com Tue Sep 24 08:42:56 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 24 Sep 2013 22:42:56 +1000 Subject: How to send an anonymous mail via Python script In-Reply-To: <5241859a$0$29992$c3e8da3$5496439d@news.astraweb.com> References: <5241859a$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Sep 24, 2013 at 10:29 PM, Steven D'Aprano wrote: > On Tue, 24 Sep 2013 11:36:16 +0000, Alister wrote: > >> To put it even more simply >> If you have a legitimate reason to send me emails then you have no >> legitimate reason to withhold your true Identity. > > "Dear Alister, > > Forgive this anonymous email, but I don't wish to get fired from my job > and sued for breaking the confidentiality agreement I signed, but > somebody needs to speak out about this matter. There are definitely the odd times when a person needs anonymity. I do not know of any times when an email-sending *computer* does. To send your whistleblower email, I would recommend an HTTPS connection to some free webmail service, or some sort of bouncer, or something - but that bouncer can identify itself honestly to the receiver. Same goes for other situations. I received your email, not from pearwood.info, but from python.org - courtesy of Mailman. It's not being sneaky about it, but the 'from' header is quite different from the mail's actual origin. What I want to know here, primarily, is the identity of the server who's giving me the message - ie python.org - and MTAs will be adding tracking headers that identify that server. (The concepts here are somewhat clouded by the c.l.py gateway, but pick any other mailing list as your example and it'll be correct.) ChrisA From alister.ware at ntlworld.com Tue Sep 24 10:55:33 2013 From: alister.ware at ntlworld.com (Alister) Date: Tue, 24 Sep 2013 14:55:33 GMT Subject: How to send an anonymous mail via Python script References: <5241859a$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, 24 Sep 2013 12:29:14 +0000, Steven D'Aprano wrote: > On Tue, 24 Sep 2013 11:36:16 +0000, Alister wrote: > >> To put it even more simply If you have a legitimate reason to send me >> emails then you have no legitimate reason to withhold your true >> Identity. > > "Dear Alister, > > Whistleblower laws are useless. Sometimes people need to remain > anonymous. Even when whistleblower laws have teeth, sometimes it's just > better to keep your identity unknown. That would be acceptable as an email to me as a company/gvt. officer. emails to me as an individual have no justification in remaining anonymous > > However, in the specific case of Nikos, I cannot imagine any legitimate > reason for him to be sending anonymous emails to his website users. I've > asked him to explain, but he hasn't. I can only conclude that he is > intending to send spam, or otherwise act unethically or even criminally. > Even if I knew how to write an anonymous mail server, I wouldn't help > him. indeed, I have given Nikos the benefit of the doubt & even tried to help him once when the question seemed within my limited abilities but without further information on the purpose I will not be helping with this one.# -- unfair competition, n.: Selling cheaper than we do. From luca.cerone at gmail.com Sat Sep 21 06:47:26 2013 From: luca.cerone at gmail.com (Luca Cerone) Date: Sat, 21 Sep 2013 03:47:26 -0700 (PDT) Subject: Sphinx Doctest: test the code without comparing the output. Message-ID: <6fbfa8a5-92ab-4821-92ea-7eb4efbe199d@googlegroups.com> Dear all, I am writing the documentation for a Python package using Sphinx. I have a problem when using doctest blocks in the documentation: I couldn't manage to get doctest to run a command but completely ignoring the output. For example, how can I get a doctest like the following to run correctly? .. doctest:: example_1 >>> import random >>> x = random.uniform(0,100) >>> print str(x) #some directive here to completely ignore the output Since I don't know the value of `x`, ideally in this doctest I only want to test that the various commands are correct, regardless of the output produced. I have tried using the ELLIPSIS directive, but the problem is that the `...` are interpreted as line continuation rather than `any text`: .. doctest:: example_2 >>> import random >>> x = random.uniform(0,100) >>> print str(x) # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE ... I don't know if there is a way to make Sphinx understand that I want to ignore the whole output. I think the easiest way to solve this, would be differentiating between the ellipsis sequence and the line continuation sequence, but I don't know how to do that. I know that I could skip the execution of print(str(x)) but this is not what I want; I really would like the command to be executed the output ignored. Can you point me to any solution for this issue? Thanks a lot in advance for your help, Cheers, Luca From steve+comp.lang.python at pearwood.info Sat Sep 21 08:27:31 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Sep 2013 12:27:31 GMT Subject: Sphinx Doctest: test the code without comparing the output. References: <6fbfa8a5-92ab-4821-92ea-7eb4efbe199d@googlegroups.com> Message-ID: <523d90b2$0$29988$c3e8da3$5496439d@news.astraweb.com> On Sat, 21 Sep 2013 03:47:26 -0700, Luca Cerone wrote: > Dear all, > I am writing the documentation for a Python package using Sphinx. > > I have a problem when using doctest blocks in the documentation: I > couldn't manage to get doctest to run a command but completely ignoring > the output. > > For example, how can I get a doctest like the following to run > correctly? > > .. doctest:: example_1 > > >>> import random > >>> x = random.uniform(0,100) > >>> print str(x) > #some directive here to completely ignore the output The Fine Manual says that the directive you want is #doctest:+SKIP. http://docs.python.org/2/library/doctest.html#doctest.SKIP Although it's not explicitly listed as a directive, every option flag corresponds to a directive. So your example becomes: >>> import random >>> x = random.uniform(0,100) >>> print x #doctest:+SKIP 42.012345678901234 (There's no need to convert things to str before printing them.) -- Steven From luca.cerone at gmail.com Sat Sep 21 08:44:09 2013 From: luca.cerone at gmail.com (Luca Cerone) Date: Sat, 21 Sep 2013 05:44:09 -0700 (PDT) Subject: Sphinx Doctest: test the code without comparing the output. In-Reply-To: <523d90b2$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <6fbfa8a5-92ab-4821-92ea-7eb4efbe199d@googlegroups.com> <523d90b2$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9de3b59f-6cd1-4357-a59e-b2ee028d59ab@googlegroups.com> Dear Steven, thanks for the help. I am aware that I might have used the SKIP directive (as I hinted in my mail). Even if the fine manual suggests to do so I don't agree with it, though. The reason is simple: SKIP as the name suggests causes the code not to be run at all, it doesn't ignore the output. If you use a SKIP directive on code that contains a typo, or maybe you changed the name of a keyword to make it more meaningful and forgot to update your docstring, then the error won't be caught. For example: .. doctest:: example >>> printt "Hello, World!" # doctest: +SKIP "Hello, World!" would pass the test. Since I am writing a tutorial for people that have even less experience than me with Python, I want be sure that the code in my examples runs just fine. > > (There's no need to convert things to str before printing them.) > You are right, I modified an example that uses x in one of my functions that requires a string in input, and didn't change that. Thanks again for the help anyway, Cheers, Luca From steve+comp.lang.python at pearwood.info Sat Sep 21 11:48:34 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Sep 2013 15:48:34 GMT Subject: Sphinx Doctest: test the code without comparing the output. References: <6fbfa8a5-92ab-4821-92ea-7eb4efbe199d@googlegroups.com> <523d90b2$0$29988$c3e8da3$5496439d@news.astraweb.com> <9de3b59f-6cd1-4357-a59e-b2ee028d59ab@googlegroups.com> Message-ID: <523dbfd2$0$29988$c3e8da3$5496439d@news.astraweb.com> On Sat, 21 Sep 2013 05:44:09 -0700, Luca Cerone wrote: > If you use a SKIP > directive on code that contains a typo, or maybe you changed the name of > a keyword to make it more meaningful and forgot to update your > docstring, then the error won't be caught. And if you ignore the output, the error won't be caught either. What's the difference? >>> 1 + 1 #doctest:+IGNORE_OUTPUT (not a real directive) 1000 Since doctest is ignoring the output, it won't catch the failure. Even if your code raises an exception, if you ignore the output, you'll never see the exception because it is ignored. So you simply can't do what you want. You can't both ignore the output of a doctest and have doctest report if the test fails. -- Steven From luca.cerone at gmail.com Sat Sep 21 12:25:26 2013 From: luca.cerone at gmail.com (Luca Cerone) Date: Sat, 21 Sep 2013 09:25:26 -0700 (PDT) Subject: Sphinx Doctest: test the code without comparing the output. In-Reply-To: <523dbfd2$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <6fbfa8a5-92ab-4821-92ea-7eb4efbe199d@googlegroups.com> <523d90b2$0$29988$c3e8da3$5496439d@news.astraweb.com> <9de3b59f-6cd1-4357-a59e-b2ee028d59ab@googlegroups.com> <523dbfd2$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0a3a0078-2d55-4cc8-bf8d-f7bede6af9f1@googlegroups.com> > And if you ignore the output, the error won't be caught either. What's > > the difference? > > >>> 1 + 1 #doctest:+IGNORE_OUTPUT (not a real directive) > > 1000 > > The difference is that in that case you want to check whether the result is correct or not, because you expect a certain result. In my case, I don't know what the output is, nor care for the purpose of the tutorial. What I care is being sure that the command in the tutorial is correct, and up to date with the code. If you try the following, the test will fail (because there is a typo in the code) .. doctest:: example >>> printt "hello, world" and not because the output doesn't match what you expected. Even if the command is correct: .. doctest:: example_2 >>> print "hello, world" this text will fail because doctest expects an output. I want to be able to test that the syntax is correct, the command can be run, and ignore whatever the output is. Don't think about the specific print example, I use this just to show what the problem is, which is not what I am writing a tutorial about! > > > So you simply can't do what you want. You can't both ignore the output of > > a doctest and have doctest report if the test fails. > OK, maybe it is not possible using doctest. Is there any other way to do what I want? For example using an other Sphinx extension?? From rosuav at gmail.com Sat Sep 21 21:33:24 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 22 Sep 2013 11:33:24 +1000 Subject: Sphinx Doctest: test the code without comparing the output. In-Reply-To: <0a3a0078-2d55-4cc8-bf8d-f7bede6af9f1@googlegroups.com> References: <6fbfa8a5-92ab-4821-92ea-7eb4efbe199d@googlegroups.com> <523d90b2$0$29988$c3e8da3$5496439d@news.astraweb.com> <9de3b59f-6cd1-4357-a59e-b2ee028d59ab@googlegroups.com> <523dbfd2$0$29988$c3e8da3$5496439d@news.astraweb.com> <0a3a0078-2d55-4cc8-bf8d-f7bede6af9f1@googlegroups.com> Message-ID: On Sun, Sep 22, 2013 at 2:25 AM, Luca Cerone wrote: > The difference is that in that case you want to check whether the result is correct or not, because you expect a certain result. > > In my case, I don't know what the output is, nor care for the purpose of the tutorial. What I care is being sure that the command in the tutorial is correct, and up to date with the code. I'd call that a smoke-test, rather than something a test harness/engine should be doing normally. All you do is see if the program crashes. This can be extremely useful (I smoke-test my scripts as part of my one-key "deploy to testbox" script, saving me the trouble of actually running anything - simple syntactic errors or misspelled function/variable names (in languages where that's a concept) get caught really early); but if you're using this for a tutorial, you risk creating a breed of novice programmers who believe their first priority is to stop the program crashing. Smoke testing is a tool that should be used by the expert, NOT a sole check given to a novice. ChrisA From steve+comp.lang.python at pearwood.info Sat Sep 21 22:38:49 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Sep 2013 02:38:49 GMT Subject: Sphinx Doctest: test the code without comparing the output. References: <6fbfa8a5-92ab-4821-92ea-7eb4efbe199d@googlegroups.com> <523d90b2$0$29988$c3e8da3$5496439d@news.astraweb.com> <9de3b59f-6cd1-4357-a59e-b2ee028d59ab@googlegroups.com> <523dbfd2$0$29988$c3e8da3$5496439d@news.astraweb.com> <0a3a0078-2d55-4cc8-bf8d-f7bede6af9f1@googlegroups.com> Message-ID: <523e5838$0$29988$c3e8da3$5496439d@news.astraweb.com> On Sat, 21 Sep 2013 09:25:26 -0700, Luca Cerone wrote: >> And if you ignore the output, the error won't be caught either. What's >> the difference? >> >> >>> 1 + 1 #doctest:+IGNORE_OUTPUT (not a real directive) >> 1000 >> >> > The difference is that in that case you want to check whether the result > is correct or not, because you expect a certain result. > > In my case, I don't know what the output is, nor care for the purpose of > the tutorial. What I care is being sure that the command in the tutorial > is correct, and up to date with the code. > > If you try the following, the test will fail (because there is a typo in > the code) > > .. doctest:: example > > >>> printt "hello, world" > > and not because the output doesn't match what you expected. That is not how doctest works. That test fails because its output is: SyntaxError: invalid syntax not because doctest recognises the syntax error as a failure. Exceptions, whether they are syntax errors or some other exception, can count as doctest *successes* rather than failures. Both of these count as passing doctests: >>> x++ # Python is not C! Traceback (most recent call last): .. SyntaxError: unexpected EOF while parsing >>> 1/0 Traceback (most recent call last): .. ZeroDivisionError: division by zero Consequently, doctest only recognises failures by their output, regardless of whether that output is a value or an exception. > Even if the command is correct: > > .. doctest:: example_2 > > >>> print "hello, world" > > this text will fail because doctest expects an output. I want to be able > to test that the syntax is correct, the command can be run, and ignore > whatever the output is. The only wild-card output that doctest recognises is ellipsis, and like all wild-cards, can match too much if you aren't careful. If ellipsis is not matching exactly what you want, add some scaffolding to ensure a match: >>> import random >>> x = random.uniform(0,100) >>> print "x =", x # doctest:+ELLIPSIS x = ... will work. But a better solution, I think, would be to pick a deterministic result: >>> import random >>> random.seed(100) >>> random.uniform(0, 100) 14.566925510413032 Alas, that only works reliably if you stick to a single Python version. Although the results of calling random.random are guaranteed to be stable across versions, random functions build on top of random.random like uniform are not and may need to be protected with a version check. -- Steven From luca.cerone at gmail.com Sun Sep 22 00:15:48 2013 From: luca.cerone at gmail.com (Luca Cerone) Date: Sat, 21 Sep 2013 21:15:48 -0700 (PDT) Subject: Sphinx Doctest: test the code without comparing the output. In-Reply-To: <523e5838$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <6fbfa8a5-92ab-4821-92ea-7eb4efbe199d@googlegroups.com> <523d90b2$0$29988$c3e8da3$5496439d@news.astraweb.com> <9de3b59f-6cd1-4357-a59e-b2ee028d59ab@googlegroups.com> <523dbfd2$0$29988$c3e8da3$5496439d@news.astraweb.com> <0a3a0078-2d55-4cc8-bf8d-f7bede6af9f1@googlegroups.com> <523e5838$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <48fb04f5-168e-4c91-83fe-f7a45efced25@googlegroups.com> > > That is not how doctest works. That test fails because its output is: ok.. is there a tool by which I can test if my code runs regardless the output? > > The only wild-card output that doctest recognises is ellipsis, and like > > all wild-cards, can match too much if you aren't careful. If ellipsis is > actually I want to match the whole output.. and you can't because ellipsis is the same as line continuation... > > > > will work. But a better solution, I think, would be to pick a I think you are sticking too much to the examples I posted, where I used functions that are part of Python, so that everybody could run the code and test the issues. I don't use random numbers, so I can't apply what you said. Really, I am looking for a way to test the code while ignoring the output. I don't know if usually it is a bad choice, but in my case is what I want/need. Thanks for the help, Luca From steve+comp.lang.python at pearwood.info Sun Sep 22 08:12:51 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Sep 2013 12:12:51 GMT Subject: Sphinx Doctest: test the code without comparing the output. References: <6fbfa8a5-92ab-4821-92ea-7eb4efbe199d@googlegroups.com> <523d90b2$0$29988$c3e8da3$5496439d@news.astraweb.com> <9de3b59f-6cd1-4357-a59e-b2ee028d59ab@googlegroups.com> <523dbfd2$0$29988$c3e8da3$5496439d@news.astraweb.com> <0a3a0078-2d55-4cc8-bf8d-f7bede6af9f1@googlegroups.com> <523e5838$0$29988$c3e8da3$5496439d@news.astraweb.com> <48fb04f5-168e-4c91-83fe-f7a45efced25@googlegroups.com> Message-ID: <523edec3$0$29988$c3e8da3$5496439d@news.astraweb.com> On Sat, 21 Sep 2013 21:15:48 -0700, Luca Cerone wrote: > I am looking for a way to test the code while ignoring the output. This makes no sense. If you ignore the output, the code could do ANYTHING and the test would still pass. Raise an exception? Pass. SyntaxError? Pass. Print "99 bottles of beer"? Pass. I have sometimes written unit tests that just check whether a function actually is callable: ignore = function(a, b, c) but I've come to the conclusion that is just a waste of time, since there are dozens of other tests that will fail if function isn't callable. But if you insist, you could always use that technique in your doctests: >>> ignore = function(a, b, c) If the function call raises, your doctest will fail, but if it returns something, anything, it will pass. -- Steven From luca.cerone at gmail.com Sun Sep 22 10:24:49 2013 From: luca.cerone at gmail.com (Luca Cerone) Date: Sun, 22 Sep 2013 07:24:49 -0700 (PDT) Subject: Sphinx Doctest: test the code without comparing the output. In-Reply-To: <523edec3$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <6fbfa8a5-92ab-4821-92ea-7eb4efbe199d@googlegroups.com> <523d90b2$0$29988$c3e8da3$5496439d@news.astraweb.com> <9de3b59f-6cd1-4357-a59e-b2ee028d59ab@googlegroups.com> <523dbfd2$0$29988$c3e8da3$5496439d@news.astraweb.com> <0a3a0078-2d55-4cc8-bf8d-f7bede6af9f1@googlegroups.com> <523e5838$0$29988$c3e8da3$5496439d@news.astraweb.com> <48fb04f5-168e-4c91-83fe-f7a45efced25@googlegroups.com> <523edec3$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: > This makes no sense. If you ignore the output, the code could do ANYTHING > > and the test would still pass. Raise an exception? Pass. SyntaxError? > > Pass. Print "99 bottles of beer"? Pass. > if you try the commands, you can see that the tests fail.. for example .. doctest:: >>> raise Exception("test") will fail with this message: File "utils.rst", line 5, in default Failed example: raise Exception("test") Exception raised: Traceback (most recent call last): File "/usr/lib/python2.7/doctest.py", line 1289, in __run compileflags, 1) in test.globs File "", line 1, in raise Exception("test") Exception: test So to me this seems OK.. "Print" will fail as well... > > > I have sometimes written unit tests that just check whether a function > > actually is callable: > > > > ignore = function(a, b, c) > > > > but I've come to the conclusion that is just a waste of time, since there > > are dozens of other tests that will fail if function isn't callable. But > > if you insist, you could always use that technique in your doctests: > > > > >>> ignore = function(a, b, c) > > > If the function call raises, your doctest will fail, but if it returns > > something, anything, it will pass. > > I understand your point, but now I am not writing unit tests to check the correctness of the code. I am only writing a tutorial and assuming that the code is correct. What I have to be sure is that the code in the tutorial can be executed correctly, and some commands print verbose output which can change. It is not enough to write >>> ignore = function(a,b,c) won't work because the function still prints messages on screen and this causes the failure of the test... From neilc at norwich.edu Mon Sep 23 09:42:13 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 23 Sep 2013 13:42:13 GMT Subject: Sphinx Doctest: test the code without comparing the output. References: <6fbfa8a5-92ab-4821-92ea-7eb4efbe199d@googlegroups.com> <523d90b2$0$29988$c3e8da3$5496439d@news.astraweb.com> <9de3b59f-6cd1-4357-a59e-b2ee028d59ab@googlegroups.com> <523dbfd2$0$29988$c3e8da3$5496439d@news.astraweb.com> <0a3a0078-2d55-4cc8-bf8d-f7bede6af9f1@googlegroups.com> <523e5838$0$29988$c3e8da3$5496439d@news.astraweb.com> <48fb04f5-168e-4c91-83fe-f7a45efced25@googlegroups.com> <523edec3$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-09-22, Luca Cerone wrote: > I understand your point, but now I am not writing unit tests to > check the correctness of the code. I am only writing a tutorial > and assuming that the code is correct. What I have to be sure > is that the code in the tutorial can be executed correctly, and > some commands print verbose output which can change. > > It is not enough to write >>> ignore = function(a,b,c) won't > work because the function still prints messages on screen and > this causes the failure of the test... It won't be very good documenation any more but nothing stops you from examining the result in the next doctest and making yourself happy about it. >>> x = input("indeterminate:") >>> result = "'{}'".format(x)) >>> result.startswith("'") and result.endswith("'") True -- Neil Cerutti From luca.cerone at gmail.com Mon Sep 23 10:45:43 2013 From: luca.cerone at gmail.com (Luca Cerone) Date: Mon, 23 Sep 2013 07:45:43 -0700 (PDT) Subject: Sphinx Doctest: test the code without comparing the output. In-Reply-To: References: <6fbfa8a5-92ab-4821-92ea-7eb4efbe199d@googlegroups.com> <523d90b2$0$29988$c3e8da3$5496439d@news.astraweb.com> <9de3b59f-6cd1-4357-a59e-b2ee028d59ab@googlegroups.com> <523dbfd2$0$29988$c3e8da3$5496439d@news.astraweb.com> <0a3a0078-2d55-4cc8-bf8d-f7bede6af9f1@googlegroups.com> <523e5838$0$29988$c3e8da3$5496439d@news.astraweb.com> <48fb04f5-168e-4c91-83fe-f7a45efced25@googlegroups.com> <523edec3$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: > It won't be very good documenation any more but nothing stops you > > from examining the result in the next doctest and making yourself > > happy about it. > > > > >>> x = input("indeterminate:") > > >>> result = "'{}'".format(x)) > > >>> result.startswith("'") and result.endswith("'") > > True > Hi Neil, thanks for the hint, but this won't work. The problem is that the function displays some output informing you of what steps are being performed (some of which are displayed by a 3rd party function that I don't control). This output "interferes" with the output that should be checked by doctest. For example, you can check that the following doctest would fail: .. doctest:: example_fake >>> def myfun(x,verbose): ... print "random output" ... return x >>> myfun(10) 10 When you run make doctest the test fails with this message: File "tutorial.rst", line 11, in example_fake Failed example: myfun(10) Expected: 10 Got: random output 10 In this case (imagine that "random output" is really random, therefore I can not easily filter it, if not ignoring several lines. This would be quite easy if ellipsis and line continuation wouldn't have the same sequence of characters, but unfortunately this is not the case. The method you proposed still is not applicable, because I have no way to use startswith() and endswith()... The following code could do what I want if I could ignore the output... >>> def myfun(x,verbose): ... print "random output" ... return x >>> result = myfun(10) #should ignore the output here! >>> print result 10 fails with this message: File "tutorial.rst", line 11, in example_fake Failed example: result = myfun(10) Expected nothing Got: random output (line 11 contains: >>> result = myfun(10)) A SKIP directive is not feasible either: .. doctest:: example_fake >>> def myfun(x): ... print "random output" ... return x >>> result = myfun(10) # doctest: +SKIP >>> result 10 fails with this error message: File "tutorial.rst", line 12, in example_fake Failed example: result Exception raised: Traceback (most recent call last): File "/usr/lib/python2.7/doctest.py", line 1289, in __run compileflags, 1) in test.globs File "", line 1, in result NameError: name 'result' is not defined As you can see is not that I want something too weird, is just that sometimes you can't control what the function display and ignoring the output is a reasonable way to implement a doctest. Hope these examples helped to understand better what my problem is. Thanks all of you guys for the hints, suggestions and best practices :) From luca.cerone at gmail.com Mon Sep 23 10:51:30 2013 From: luca.cerone at gmail.com (Luca Cerone) Date: Mon, 23 Sep 2013 07:51:30 -0700 (PDT) Subject: Sphinx Doctest: test the code without comparing the output. In-Reply-To: References: <6fbfa8a5-92ab-4821-92ea-7eb4efbe199d@googlegroups.com> <523d90b2$0$29988$c3e8da3$5496439d@news.astraweb.com> <9de3b59f-6cd1-4357-a59e-b2ee028d59ab@googlegroups.com> <523dbfd2$0$29988$c3e8da3$5496439d@news.astraweb.com> <0a3a0078-2d55-4cc8-bf8d-f7bede6af9f1@googlegroups.com> <523e5838$0$29988$c3e8da3$5496439d@news.astraweb.com> <48fb04f5-168e-4c91-83fe-f7a45efced25@googlegroups.com> <523edec3$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <600ad55e-2d37-4bfd-b79f-6c6283f9d5b4@googlegroups.com> I don't know why but it seems that google groups stripped the indentation from the code. I just wanted to ensure you that in the examples that I have run the definition of myfunc contained correctly indented code! On Monday, 23 September 2013 15:45:43 UTC+1, Luca Cerone wrote: > .. doctest:: example_fake > > > > >>> def myfun(x,verbose): > > ... print "random output" > > ... return x > > >>> myfun(10) > > 10 > > > > When you run make doctest the test fails with this message: > > > > File "tutorial.rst", line 11, in example_fake > > Failed example: > > myfun(10) > > Expected: > > 10 > > Got: > > random output > > 10 > > > > In this case (imagine that "random output" is really random, therefore I can not easily filter it, if not ignoring several lines. This would be quite easy if ellipsis and line continuation wouldn't have the same sequence of characters, but unfortunately this is not the case. > > > > The method you proposed still is not applicable, because I have no way to use startswith() and endswith()... > > > > The following code could do what I want if I could ignore the output... > > > > >>> def myfun(x,verbose): > > ... print "random output" > > ... return x > > >>> result = myfun(10) #should ignore the output here! > > >>> print result > > 10 > > > > fails with this message: > > > > File "tutorial.rst", line 11, in example_fake > > Failed example: > > result = myfun(10) > > Expected nothing > > Got: > > random output > > > > (line 11 contains: >>> result = myfun(10)) > > > > A SKIP directive is not feasible either: > > > > .. doctest:: example_fake > > > > >>> def myfun(x): > > ... print "random output" > > ... return x > > >>> result = myfun(10) # doctest: +SKIP > > >>> result > > 10 > > > > fails with this error message: > > File "tutorial.rst", line 12, in example_fake > > Failed example: > > result > > Exception raised: > > Traceback (most recent call last): > > File "/usr/lib/python2.7/doctest.py", line 1289, in __run > > compileflags, 1) in test.globs > > File "", line 1, in > > result > > NameError: name 'result' is not defined > > > > As you can see is not that I want something too weird, is just that sometimes you can't control what the function display and ignoring the output is a reasonable way to implement a doctest. > > > > Hope these examples helped to understand better what my problem is. > > > > Thanks all of you guys for the hints, suggestions and best practices :) From skip at pobox.com Mon Sep 23 11:14:48 2013 From: skip at pobox.com (Skip Montanaro) Date: Mon, 23 Sep 2013 10:14:48 -0500 Subject: Sphinx Doctest: test the code without comparing the output. In-Reply-To: <600ad55e-2d37-4bfd-b79f-6c6283f9d5b4@googlegroups.com> References: <6fbfa8a5-92ab-4821-92ea-7eb4efbe199d@googlegroups.com> <523d90b2$0$29988$c3e8da3$5496439d@news.astraweb.com> <9de3b59f-6cd1-4357-a59e-b2ee028d59ab@googlegroups.com> <523dbfd2$0$29988$c3e8da3$5496439d@news.astraweb.com> <0a3a0078-2d55-4cc8-bf8d-f7bede6af9f1@googlegroups.com> <523e5838$0$29988$c3e8da3$5496439d@news.astraweb.com> <48fb04f5-168e-4c91-83fe-f7a45efced25@googlegroups.com> <523edec3$0$29988$c3e8da3$5496439d@news.astraweb.com> <600ad55e-2d37-4bfd-b79f-6c6283f9d5b4@googlegroups.com> Message-ID: > I don't know why but it seems that google groups stripped the indentation from the code. Because it's Google Groups. :-) 800-pound gorillas tend to do pretty much whatever they want. Skip From neilc at norwich.edu Mon Sep 23 12:44:22 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 23 Sep 2013 16:44:22 GMT Subject: Sphinx Doctest: test the code without comparing the output. References: <6fbfa8a5-92ab-4821-92ea-7eb4efbe199d@googlegroups.com> <523d90b2$0$29988$c3e8da3$5496439d@news.astraweb.com> <9de3b59f-6cd1-4357-a59e-b2ee028d59ab@googlegroups.com> <523dbfd2$0$29988$c3e8da3$5496439d@news.astraweb.com> <0a3a0078-2d55-4cc8-bf8d-f7bede6af9f1@googlegroups.com> <523e5838$0$29988$c3e8da3$5496439d@news.astraweb.com> <48fb04f5-168e-4c91-83fe-f7a45efced25@googlegroups.com> <523edec3$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-09-23, Luca Cerone wrote: >> It won't be very good documenation any more but nothing stops you >> >> from examining the result in the next doctest and making yourself >> >> happy about it. >> >> >> >> >>> x = input("indeterminate:") >> >> >>> result = "'{}'".format(x)) >> >> >>> result.startswith("'") and result.endswith("'") >> >> True >> > > Hi Neil, thanks for the hint, but this won't work. > > The problem is that the function displays some output informing > you of what steps are being performed (some of which are > displayed by a 3rd party function that I don't control). > > This output "interferes" with the output that should be checked by doctest. > > For example, you can check that the following doctest would fail: > > .. doctest:: example_fake > > >>> def myfun(x,verbose): > ... print "random output" > ... return x > >>> myfun(10) > 10 > > When you run make doctest the test fails with this message: > > File "tutorial.rst", line 11, in example_fake > Failed example: > myfun(10) > Expected: > 10 > Got: > random output > 10 > > In this case (imagine that "random output" is really random, > therefore I can not easily filter it, if not ignoring several > lines. This would be quite easy if ellipsis and line > continuation wouldn't have the same sequence of characters, but > unfortunately this is not the case. Perhaps try the "advanced API" and define your oen OutputChecker to add the feature that you need. Figuring out how to best invoke doctest with your modified OutputChecker will take some digging in the source, probably looking at doctest.testmod. I don't see an example in the docs. > Hope these examples helped to understand better what my problem > is. Yes, I think it's well-defined now. -- Neil Cerutti From neilc at norwich.edu Mon Sep 23 12:53:53 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 23 Sep 2013 16:53:53 GMT Subject: Sphinx Doctest: test the code without comparing the output. References: <6fbfa8a5-92ab-4821-92ea-7eb4efbe199d@googlegroups.com> <523d90b2$0$29988$c3e8da3$5496439d@news.astraweb.com> <9de3b59f-6cd1-4357-a59e-b2ee028d59ab@googlegroups.com> <523dbfd2$0$29988$c3e8da3$5496439d@news.astraweb.com> <0a3a0078-2d55-4cc8-bf8d-f7bede6af9f1@googlegroups.com> <523e5838$0$29988$c3e8da3$5496439d@news.astraweb.com> <48fb04f5-168e-4c91-83fe-f7a45efced25@googlegroups.com> <523edec3$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-09-23, Neil Cerutti wrote: > Perhaps try the "advanced API" and define your oen > OutputChecker to add the feature that you need. > > Figuring out how to best invoke doctest with your modified > OutputChecker will take some digging in the source, probably > looking at doctest.testmod. I don't see an example in the docs. The docstring for doctest.DocTestRunner contains the example code I was looking for. -- Neil Cerutti From luca.cerone at gmail.com Mon Sep 23 14:54:10 2013 From: luca.cerone at gmail.com (Luca Cerone) Date: Mon, 23 Sep 2013 11:54:10 -0700 (PDT) Subject: Sphinx Doctest: test the code without comparing the output. In-Reply-To: References: <6fbfa8a5-92ab-4821-92ea-7eb4efbe199d@googlegroups.com> <523d90b2$0$29988$c3e8da3$5496439d@news.astraweb.com> <9de3b59f-6cd1-4357-a59e-b2ee028d59ab@googlegroups.com> <523dbfd2$0$29988$c3e8da3$5496439d@news.astraweb.com> <0a3a0078-2d55-4cc8-bf8d-f7bede6af9f1@googlegroups.com> <523e5838$0$29988$c3e8da3$5496439d@news.astraweb.com> <48fb04f5-168e-4c91-83fe-f7a45efced25@googlegroups.com> <523edec3$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <436c24fe-2a4b-4531-998b-ad23b1d313c4@googlegroups.com> > > The docstring for doctest.DocTestRunner contains the example code > > I was looking for. > > Thanks, I will give it a try! > > -- > > Neil Cerutti From luca.cerone at gmail.com Sun Sep 22 00:09:22 2013 From: luca.cerone at gmail.com (Luca Cerone) Date: Sat, 21 Sep 2013 21:09:22 -0700 (PDT) Subject: Sphinx Doctest: test the code without comparing the output. In-Reply-To: References: <6fbfa8a5-92ab-4821-92ea-7eb4efbe199d@googlegroups.com> <523d90b2$0$29988$c3e8da3$5496439d@news.astraweb.com> <9de3b59f-6cd1-4357-a59e-b2ee028d59ab@googlegroups.com> <523dbfd2$0$29988$c3e8da3$5496439d@news.astraweb.com> <0a3a0078-2d55-4cc8-bf8d-f7bede6af9f1@googlegroups.com> Message-ID: <5dd79e42-f1ef-4a90-b540-70f164771562@googlegroups.com> > but if you're using this for a > > tutorial, you risk creating a breed of novice programmers who believe > > their first priority is to stop the program crashing. Smoke testing is Hi Chris, actually my priority is to check that the code is correct. I changed the syntax during the development, and I want to be sure that my tutorial is up to date. The user will only see the examples that, after testing with doctest, will run. They won't know that I used doctests for the documentation.. How can I do what you call smoke tests in my Sphinx documentation? From rosuav at gmail.com Sun Sep 22 00:25:36 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 22 Sep 2013 14:25:36 +1000 Subject: Sphinx Doctest: test the code without comparing the output. In-Reply-To: <5dd79e42-f1ef-4a90-b540-70f164771562@googlegroups.com> References: <6fbfa8a5-92ab-4821-92ea-7eb4efbe199d@googlegroups.com> <523d90b2$0$29988$c3e8da3$5496439d@news.astraweb.com> <9de3b59f-6cd1-4357-a59e-b2ee028d59ab@googlegroups.com> <523dbfd2$0$29988$c3e8da3$5496439d@news.astraweb.com> <0a3a0078-2d55-4cc8-bf8d-f7bede6af9f1@googlegroups.com> <5dd79e42-f1ef-4a90-b540-70f164771562@googlegroups.com> Message-ID: On Sun, Sep 22, 2013 at 2:09 PM, Luca Cerone wrote: >> but if you're using this for a >> >> tutorial, you risk creating a breed of novice programmers who believe >> >> their first priority is to stop the program crashing. Smoke testing is > > Hi Chris, > actually my priority is to check that the code is correct. I changed the syntax > during the development, and I want to be sure that my tutorial is up to date. > > The user will only see the examples that, after testing with doctest, will > run. They won't know that I used doctests for the documentation.. > > How can I do what you call smoke tests in my Sphinx documentation? I don't know Sphinx, so I can't help there. But maybe you should just have a pile of .py files, and you import each one and see if you get an exception? ChrisA From ned at nedbatchelder.com Sun Sep 22 09:39:07 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sun, 22 Sep 2013 09:39:07 -0400 Subject: Sphinx Doctest: test the code without comparing the output. In-Reply-To: <5dd79e42-f1ef-4a90-b540-70f164771562@googlegroups.com> References: <6fbfa8a5-92ab-4821-92ea-7eb4efbe199d@googlegroups.com> <523d90b2$0$29988$c3e8da3$5496439d@news.astraweb.com> <9de3b59f-6cd1-4357-a59e-b2ee028d59ab@googlegroups.com> <523dbfd2$0$29988$c3e8da3$5496439d@news.astraweb.com> <0a3a0078-2d55-4cc8-bf8d-f7bede6af9f1@googlegroups.com> <5dd79e42-f1ef-4a90-b540-70f164771562@googlegroups.com> Message-ID: <523EF2FB.7070306@nedbatchelder.com> On 9/22/13 12:09 AM, Luca Cerone wrote: > Hi Chris, > actually my priority is to check that the code is correct. I changed the syntax > during the development, and I want to be sure that my tutorial is up to date. > If you do manage to ignore the output, how will you know that the syntax is correct? The output for an incorrect syntax line will be an exception, which you'll ignore. Maybe I don't know enough about the details of doctest. It's always seemed incredibly limited to me. Essentially, it's as if you used unittest but the only assertion you're allowed to make is self.assertEqual(str(X), "....") --Ned. From luca.cerone at gmail.com Sun Sep 22 10:26:41 2013 From: luca.cerone at gmail.com (Luca Cerone) Date: Sun, 22 Sep 2013 07:26:41 -0700 (PDT) Subject: Sphinx Doctest: test the code without comparing the output. In-Reply-To: References: <6fbfa8a5-92ab-4821-92ea-7eb4efbe199d@googlegroups.com> <523d90b2$0$29988$c3e8da3$5496439d@news.astraweb.com> <9de3b59f-6cd1-4357-a59e-b2ee028d59ab@googlegroups.com> <523dbfd2$0$29988$c3e8da3$5496439d@news.astraweb.com> <0a3a0078-2d55-4cc8-bf8d-f7bede6af9f1@googlegroups.com> <5dd79e42-f1ef-4a90-b540-70f164771562@googlegroups.com> Message-ID: On Sunday, 22 September 2013 14:39:07 UTC+1, Ned Batchelder wrote: > On 9/22/13 12:09 AM, Luca Cerone wrote: > > > Hi Chris, > > > actually my priority is to check that the code is correct. I changed the syntax > > > during the development, and I want to be sure that my tutorial is up to date. > > > > > > > If you do manage to ignore the output, how will you know that the syntax > > is correct? The output for an incorrect syntax line will be an > > exception, which you'll ignore. if the function raises an exception, the test fails, regardless of the output > Maybe I don't know enough about the > > details of doctest. It's always seemed incredibly limited to me. I agree that has some limitations > > Essentially, it's as if you used unittest but the only assertion you're > > allowed to make is self.assertEqual(str(X), "....") > > I don't know unittest, is it possible to use it within Sphinx? > > --Ned. From steve+comp.lang.python at pearwood.info Sun Sep 22 20:36:38 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Sep 2013 00:36:38 GMT Subject: Sphinx Doctest: test the code without comparing the output. References: <6fbfa8a5-92ab-4821-92ea-7eb4efbe199d@googlegroups.com> <523d90b2$0$29988$c3e8da3$5496439d@news.astraweb.com> <9de3b59f-6cd1-4357-a59e-b2ee028d59ab@googlegroups.com> <523dbfd2$0$29988$c3e8da3$5496439d@news.astraweb.com> <0a3a0078-2d55-4cc8-bf8d-f7bede6af9f1@googlegroups.com> <5dd79e42-f1ef-4a90-b540-70f164771562@googlegroups.com> Message-ID: <523f8d15$0$29988$c3e8da3$5496439d@news.astraweb.com> On Sun, 22 Sep 2013 09:39:07 -0400, Ned Batchelder wrote: > On 9/22/13 12:09 AM, Luca Cerone wrote: >> Hi Chris, >> actually my priority is to check that the code is correct. I changed >> the syntax during the development, and I want to be sure that my >> tutorial is up to date. >> >> > If you do manage to ignore the output, how will you know that the syntax > is correct? The output for an incorrect syntax line will be an > exception, which you'll ignore. Maybe I don't know enough about the > details of doctest. It's always seemed incredibly limited to me. > Essentially, it's as if you used unittest but the only assertion you're > allowed to make is self.assertEqual(str(X), "....") More or less :-) Doc tests really are documentation first and tests second. That's its strength. If you want unit tests, you know where to find them :-) -- Steven From benjamin at schollnick.net Sat Sep 21 10:00:06 2013 From: benjamin at schollnick.net (Benjamin Schollnick) Date: Sat, 21 Sep 2013 10:00:06 -0400 Subject: Code suggestions? Message-ID: <60E7ACFB-A952-4E43-AEA7-4C76D9057B44@schollnick.net> Folks, I am re-writing an image gallery application that I wrote in Twisted. As part of this rewrite, I am attempting to simplify the process of managing the directory listings. Would anyone have any suggestions on streamlining or optimizing this code? The raw version of this file, is available from dropbox. https://dl.dropboxusercontent.com/u/241415/unified.py If you are testing with RAR files, you'll need rarfile.py https://dl.dropboxusercontent.com/u/241415/rarfile.py If anyone knows a better built-in Python 2.66/2.75 solution, that would be helpful. I eventually expect to support caching, but I think that will be an application level feature, and not built-in to this module. The entire idea is to unify (thus unified.py) behavior better files, directories, and archives. Yes, there is differences in the data coming back, but the calling logic, is identical. So far, this rewrite has tremendously simplified the code for the image gallery. If there is any interest, I'm willing to github unified or the image gallery. - Benjamin import os import os.path from stat import * import time class Unified_Directory: """ An Attempt to unify directories, and archives into one single storage package. For example: gallery_listings = unified.Unified_Directory () gallery_listings.populate_file_data_from_filesystem ( filepathname = directory_path) print "files: ",gallery_listings.files,"/n/n" print "subdirectories: ",gallery_listings.subdirectories, "/n/n" print "Display Gallery for ", gallery_listings.root_path """ def __init__ ( self ): self.rar_file_types = ['cbr', 'rar'] self.zip_file_types = ['cbz', 'zip'] self.archive_file_types = self.rar_file_types + self.zip_file_types self.files_to_ignore = [] # File filter to ignore self.root_path = None # This is the path in the OS that is being examined (e.g. /Volumes/Users/username/ ) self.subdirectories = [] # This is the subdirectories that exist in that path (e.g. Desktop, Music, Videos, etc) self.files = [] # This is the list of files that are in the root_path. # Each file consists of a dictionary containing: # # * Filename # * st_mode - Unix chmod # * st_ino - inode number # * st_dev - Unix Device # * st_nlink - hard link count # * st_uid - User/Owner ID # * st_gid - Group ID of Owner # * st_size - File size # * st_atime - Last Access time # * st_mtime - Last Modified Time # * st_ctime - Last Metadata change # * dot_extension - File extension with . prefix (lower case) # * file_extension - File Extension without . prefix (lower case) def _get_directory_list ( self, directory_to_list ): """ Returns the directories, and files in separate lists. Low Level function, intended to be used by the populate function. """ directories = [] files = [] for fileobject in os.listdir ( directory_to_list): if fileobject.lower() in self.files_to_ignore: pass elif os.path.isdir ( directory_to_list + os.sep + fileobject ): directories.append ( fileobject ) else: files.append ( fileobject ) return (directories, files) def _return_directories_count ( self ): """ Return the number of directories that are in the root path """ return len(self.subdirectories) def _return_files_count ( self ): """ Return the number of files that are in the root path """ return len(files) def is_file_archive ( self, filepathname = None): """ Is the file that is being passed in, a file in the self.archive_types. """ if filepathname == None: return None else: extension = os.path.splitext ( filepathname )[1][1:] if extension.lower() in self.archive_file_types: return True else: return False def is_rar_file_archive ( self, filepathname = None): """ Is the file that is being passed in, a file in the self.rar_file_types list. """ if filepathname == None: return None else: extension = os.path.splitext ( filepathname )[1][1:] if extension.lower() in self.rar_file_types: return True else: return False def is_zip_file_archive ( self, filepathname = None): """ Is the file that is being passed in, a file in the self.zip_file_types list. """ if filepathname == None: return None else: extension = os.path.splitext ( filepathname )[1][1:] if extension.lower() in self.zip_file_types: return True else: return False def natural_sort(self, l): # # http://stackoverflow.com/questions/4836710/does-python-have-a-built-in-function-for-string-natural-sort # import re convert = lambda text: int(text) if text.isdigit() else text.lower() alphanum_key = lambda key: [ convert(c) for c in re.split('([0-9]+)', key) ] return sorted(l, key = alphanum_key) def return_file_index ( self, filename ): """ If the filename exists in the index, then return the 0 based index of the file. Else, return -1 on error. """ try: return self.files_index.index ( filename ) except: return -1 def populate_file_data_from_filesystem ( self, filepathname = None, sorted=False, expand_archives = False): """ Populates this node. Updates the self.files and self.subdirectories dictionaries in the class. sorted - if true, will naturally sort the filenames, and subdirectory names, ensuring that they are in a english friendly sorting. expand_archives - If true, will return the listing of the zip or rar archive type. """ # print "---",filepathname filedata = {} # Clear out old filedata # Set the root path, based off the filepathname information if filepathname == None: # # Invalid request for data. Return Empty data. # print "Returned due to None" return False self.root_path = os.path.split ( filepathname )[0] if os.path.isdir ( filepathname ): # # Is directory, return all data on the files within # self.subdirectories = [] # Since we are now invoking, to re-populate, clear out all subdirectory information self.subdirectory_index = [] self.files = [] # Since we are now invoking, to re-populate, clear out all file information self.files_index = [] raw_directories, raw_files = self._get_directory_list ( directory_to_list = filepathname ) for directory in raw_directories: directorydata = {} st = os.stat ( filepathname + directory) # print "is directory" # print st dir_subdirectories, dir_files = self._get_directory_list ( filepathname + directory ) directorydata [ "directoryname"] = directory directorydata [ "parentdirectory" ] = os.path.split (filepathname) directorydata [ "st_mode" ] = st[ST_MODE] directorydata [ "st_inode" ] = st[ST_INO] directorydata [ "st_dev" ] = st[ST_DEV] directorydata [ "st_nlink" ] = st[ST_NLINK] directorydata [ "st_uid" ] = st[ST_UID] directorydata [ "st_gid" ] = st[ST_GID] directorydata [ "compressed" ] = st[ST_SIZE] directorydata [ "st_size" ] = 0#os.path.getsize ( filepathname )#st[ST_SIZE] directorydata [ "st_atime" ] = st[ST_ATIME] directorydata [ "raw_st_mtime" ] = st[ST_MTIME] directorydata [ "st_mtime" ] = time.asctime(time.localtime(st[ST_MTIME])) #st[ST_MTIME] directorydata [ "st_ctime" ] = st[ST_CTIME] directorydata [ "dot_extension" ] = ".dir" directorydata [ "file_extension" ] = "dir" directorydata [ "number_files" ] = len(dir_files) directorydata [ "number_dirs" ] = len(dir_subdirectories) self.subdirectories.append ( directorydata) self.subdirectory_index.append ( directory ) for x in raw_files: # # Take each file in the directory, and add it to the files listing # self.populate_file_data_from_filesystem ( filepathname = filepathname + os.sep + x ) self.files_index.append ( x ) return if os.path.isfile ( filepathname ): if self.is_file_archive ( filepathname ) and expand_archives == True: # print "archive" if self.is_rar_file_archive ( filepathname ): # print "processing rar" rar_filepathname = filepathname import rarfile archivefile = rarfile.RarFile ( rar_filepathname, 'r') # print "processing zip" elif self.is_zip_file_archive ( filepathname ): zip_filepathname = filepathname import zipfile archivefile = zipfile.ZipFile ( zip_filepathname, 'r') # print "processing zip" infolist = archivefile.infolist () for info in infolist: filedata = {} filedata [ "filename" ] = info.filename filedata [ "archivefilename" ] = filepathname filedata [ "st_mode" ] = None filedata [ "st_inode" ] = None filedata [ "st_dev" ] = None filedata [ "st_nlink" ] = None filedata [ "st_uid" ] = None filedata [ "st_gid" ] = None filedata [ "st_size" ] = info.file_size filedata [ "compressed" ] = info.compress_size filedata [ "st_atime" ] = None filedata [ "raw_st_mtime" ] = st[ST_MTIME] filedata [ "st_mtime" ] = time.asctime(time.localtime(st[ST_MTIME])) #st[ST_MTIME] filedata [ "st_ctime" ] = st[ST_CTIME] filedata [ "st_ctime" ] = None filedata [ "dot_extension" ] = os.path.splitext ( info.filename )[1].lower() filedata [ "file_extension" ] = os.path.splitext ( info.filename )[1][1:].lower() self.files.append ( filedata ) else: # print "not archive" st = os.stat ( filepathname ) filedata [ "filename" ] = os.path.split (filepathname)[1] filedata [ "fq_filename" ] = filepathname filedata [ "st_mode" ] = st[ST_MODE] filedata [ "st_inode" ] = st[ST_INO] filedata [ "st_dev" ] = st[ST_DEV] filedata [ "st_nlink" ] = st[ST_NLINK] filedata [ "st_uid" ] = st[ST_UID] filedata [ "st_gid" ] = st[ST_GID] filedata [ "compressed" ] = st[ST_SIZE] filedata [ "st_size" ] = st[ST_SIZE] filedata [ "st_atime" ] = st[ST_ATIME] filedata [ "raw_st_mtime" ] = st[ST_MTIME] filedata [ "st_mtime" ] = time.asctime(time.localtime(st[ST_MTIME])) #st[ST_MTIME] filedata [ "st_ctime" ] = st[ST_CTIME] filedata [ "dot_extension" ] = os.path.splitext ( filepathname )[1].lower() filedata [ "file_extension" ] = os.path.splitext ( filepathname )[1][1:].lower() self.files.append ( filedata ) if sorted: self.natural_sort ( self.files_index ) self.natural_sort ( self.subdirectory_index ) return True -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Sat Sep 21 15:50:08 2013 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 21 Sep 2013 20:50:08 +0100 Subject: Code suggestions? In-Reply-To: <60E7ACFB-A952-4E43-AEA7-4C76D9057B44@schollnick.net> References: <60E7ACFB-A952-4E43-AEA7-4C76D9057B44@schollnick.net> Message-ID: <523DF870.8040809@mrabarnett.plus.com> On 21/09/2013 15:00, Benjamin Schollnick wrote: > Folks, > > I am re-writing an image gallery application that I wrote in Twisted. > > As part of this rewrite, I am attempting to simplify the process of > managing the directory listings. > > Would anyone have any suggestions on streamlining or optimizing this code? > > The raw version of this file, is available from dropbox. > > https://dl.dropboxusercontent.com/u/241415/unified.py > > If you are testing with RAR files, you'll need rarfile.py > > https://dl.dropboxusercontent.com/u/241415/rarfile.py > > If anyone knows a better built-in Python 2.66/2.75 solution, that would > be helpful. > > I eventually expect to support caching, but I think that will be an > application level feature, and not built-in to this module. > > The entire idea is to unify (thus unified.py) behavior better files, > directories, and archives. > > Yes, there is differences in the data coming back, but the calling > logic, is identical. > > So far, this rewrite has tremendously simplified the code for the image > gallery. If there is any interest, I'm willing to github unified or the > image gallery. > [snip] Some comments:- Using "import *" is generally regarded as a Bad Thing. Class names usually don't contain underscores, therefore "UnifiedDirectory" would be better. It's better to create file paths using os.path.join(...) instead of "manually" using "+". When checking for None, use "is" and "is not", not "==" and "!=". It's almost NEVER a good idea to use a bare except. Specify which exception you're trying to catch. The function "populate_file_data_from_filesystem" can return True, False (printing a message just before it does so, which makes it harder to use as part of a library), or None (because there's a bare return). It would be better if it raised an exception in the case of an error, returning None otherwise (a bare return). From bv4bv4bv4 at gmail.com Sat Sep 21 10:59:48 2013 From: bv4bv4bv4 at gmail.com (bv4bv4bv4 at gmail.com) Date: Sat, 21 Sep 2013 07:59:48 -0700 (PDT) Subject: THE MORAL SYSTEM IN ISLAM Message-ID: THE MORAL SYSTEM IN ISLAM Islam has laid down universal fundamental rights for humanity that are to be observed and respected under all circumstances. In order to realise these rights in one's everyday social life, Islam provides both legal safeguards and a very effective moral system. In brief, whatever improves the well-being of an individual or a society is morally good, and whatever harms this well-being is morally bad. Islam attaches great importance to the love of God and fellow human beings, and discourages excessive formalism. We read in the Quran (what means): ?It is not righteousness that you turn your faces towards East or West, but [true] righteousness is [in] one who believes in Allaah, the Last Day, the Angels, the Book, and the prophets and gives wealth, in spite of love for it, to relatives, orphans, the needy, the traveller, those who ask [for help], and for freeing slaves; [and who] establishes prayer and gives Zakaah; [those who] fulfil their promise when they promise; and [those who] are patient in poverty and hardship and during battle. Those are the ones who have been true, and it is those who are the righteous.? [Quran: 2:177] These verses give a beautiful description of the righteous and religiously committed individual. He should obey salutary regulations but fix his gaze on the love of God and the love of humanity. An individual's faith should be true and sincere and he must be prepared to show it in deeds of charity to other people and by living as a good citizen and supporter of social organisations. Finally, individual faith must remain firm and unshaken in all circumstances. This is the standard by which a particular mode of conduct can be classified as either good or bad. It also provides the nucleus around which an individual's and society?s moral code should revolve. Before laying down any moral injunctions, Islam seeks to implant firmly in man's heart the conviction that his dealings are with God, Who sees him at all times and in all places. While he may hide himself from others or deceive them, he cannot do so with God. Islam teaches that the objective of one's life is to live a life that is pleasing to God. To make such a goal possible, Islam has provided humankind with the highest possible standard of morality. This moral code, which is both straightforward and practical, provides the individual with innumerable ways to embark upon and then continue the path of moral evolution. By making Divine Revelation the primary source of knowledge, moral standards are made permanent and stable. However, this does not make them inflexible, for there is room for reasonable adjustment and adaptation when needed. The danger of moral relativism, now so widespread in many societies, is thereby avoided. Another benefit is the gradual internalisation of these moral standards, for one seeks to obey them voluntarily to please God, not because some government or people tell him to do so. An individual's belief in God, when added to his belief in the Day of Judgement, is a powerful motivating factor to live a highly moral life. Islam does not seek to minimise the importance of traditional and commonly accepted moral norms or give exaggerated importance to some and neglect others. The Islamic moral code incorporates all the commonly accepted moral virtues and then endows them with a sense of balance and proportion, by assigning each one a suitable place and function in the scheme of life. It widens the scope of man's individual and collective life by dealing with his domestic associations, civic conduct, and his activities in the political, economic, legal, educational and social realms. It covers his life from the home to the society, from the dining table to the battlefield and peace conferences. In short, from the cradle to the grave - for no sphere of life is exempt from the universal and comprehensive application of the moral principles of Islam. It makes morality reign supreme and ensures that the affairs of life are regulated by moral norms, and not dominated by selfish desires and petty interests. A major goal of Islam is to provide humankind with a practical and realistic system of life by which he can conduct his life. It calls upon humankind not only to practice virtue, but also to establish it and to eradicate all that is harmful. It seeks the supremacy of the conscience in all matters so that what is harmful cannot gain the upper hand either in an individual's life or in society. Those who respond to this call are known as Muslims, which literally means those who have submitted to God. The sole object of the resulting community of Muslims or Ummah is undertaking an organised effort to establish what is good and to fight and eradicate what is evil and harmful. Some of Islam's basic moral teachings are given below. They cover the broad spectrum of a Muslim's personal moral conduct as well as his social responsibilities. God-Consciousness The Quran mentions God-consciousness as the highest quality of a Muslim, saying (what means): ??The most noble of you in the sight of Allaah is the most righteous of you?? [Quran: 49:13] Humility, modesty, control of passions and desires, truthfulness, integrity, patience, steadfastness and fulfilling one's promises - all these moral values are mentioned many times in the Quran, such as (what means):?And God loves those who are firm and steadfast.? [Quran: 3:146] The Quran also tells Muslims (what means): ?And hasten to forgiveness from your Lord and a garden [i.e., Paradise] as wide as the heavens and the earth, prepared for the righteous. Who spend [in the cause of Allaah] during ease and hardship and who restrain anger and who pardon the people ? and Allaah loves the doers of good.? [Quran: 3:133-134] And: ??Establish prayer, enjoin what is right, forbid what is wrong, and be patient over what befalls you. Indeed, [all] that is of the matters [requiring] determination. And do not turn your cheek [in contempt] toward people [Rather, respect them by directing your face and attention to them.] And do not walk through the earth exultantly. Indeed, Allah does not like everyone self-deluded and boastful. And be moderate in your pace and lower your voice; indeed, the most disagreeable of sounds is the voice of donkeys.? [Quran: 31:17-19] The following statement of the Prophet sallallaahu alayhi wa sallam ( may Allaah exalt his mention ) summarises the moral behaviour of a committed Muslim: ?My Sustainer has given me nine commands: to remain conscious of God in private and in public; to speak justly whether angry or pleased; to show moderation when poor or rich; to rekindle friendship with those who have broken it off with me; to give to him who refuses me; that my silence should be occupied with thought; that my looking should be an admonition; and that I should command what is right.? Social Responsibilities The teachings of Islam regarding social responsibilities are based on kindness and consideration for others. Islam stresses specific acts of kindness and defines the responsibilities and rights that belong to various relationships. Our first obligation is to our immediate family - parents, spouse and children, then to other relatives, neighbours, friends and acquaintances, orphans and widows, the needy of the community, our fellow Muslims, our fellow human beings and animals. Parents Respect and care for parents is a very important part of a Muslim's expression of faith. The Quran says (what means): ?And your Lord has decreed that you not worship except Him, and to parents, good treatment. Whether one or both of them reach old age [while] with you, say not to them [so much as], 'uff' and do not repel them but speak to them a noble word. And lower to them the wing of humility out of mercy and say: 'My Lord! Have mercy upon them as they brought me up [when I was] small.'? [Quran: 17:23-24] Other Relatives The Quran says (what means): ?And give the relative his right, and [also] the poor and the traveller, and do not spend wastefully.? [Quran: 17:26] Neighbours The Prophet sallallaahu alayhi wa sallam ( may Allaah exalt his mention ) said: "He is not a believer who eats his fill while his neighbour is hungry" and: "He does not believe whose neighbours are not safe from his injurious conduct." According to the Quran and Sunnah (traditions and approved actions of the Prophet sallallaahu alayhi wa sallam ( may Allaah exalt his mention )), a Muslim has to discharge his moral responsibility not only to his parents, relatives, and neighbours but also to all humankind, animals, and useful trees and plants. For example, hunting birds and animals for sport is not permitted. Similarly, cutting down trees and plants that yield fruit is forbidden unless there is a very pressing need for one to do so. Thus, on the basic moral plane, Islam provides humankind with a higher system of morality that can be used by an individual to realise his greatest potential. Islam purifies the soul of self-seeking egotism, tyranny, wantonness, and lack of discipline. It creates God-fearing men who are devoted to their ideals, motivated by piety, abstinence and discipline, who do not make any compromise with falsehood. It creates moral responsibility and fosters the capacity for self-control. Islam generates kindness, generosity, mercy, sympathy, peace, selfless goodwill, scrupulous fairness, and truthfulness towards all creatures in all situations. It nourishes noble qualities from which only good may be expected. http://www.islamweb.net/emainpage/index.php?page=articles&id=134451 thank you From peter.cacioppi at gmail.com Sat Sep 21 17:43:13 2013 From: peter.cacioppi at gmail.com (Peter Cacioppi) Date: Sat, 21 Sep 2013 14:43:13 -0700 (PDT) Subject: reload and work flow suggestions Message-ID: <61d45045-187c-4be7-9da4-21a3124b753f@googlegroups.com> This is an idea brought over from another post. When I write Python code I generally have 2 or 3 windows open simultaneously. 1) An editor for the actual code. 2) The interactive interpreter. 3) An editor for the unit tests. (Sometimes skipped for quick one-off scripts) My work flow tends to involve using 2 to debug the issues that come up with 1 and 3. I'll write some new code in 1, play around with it in 2, then solidify the tests in 3. Or a test in 3 fails and I dig around with it using 2. My problem is that I tend to use reload() quite a bit. I want to call functions and construct objects that are inside the guts of 1 and pass them arguments that are stored as variables in 2. If I restart my session for 2 I lose these variables (iPython does mitigate the pain here somewhat). Hence, I reload() modules into 2 when they are changed. I use ipdb a lot in 2. I usually don't feel comfortable with virgin code or a debug fix that hasn't been stepped through with the debugger. Is there something wrong with this work flow? I understand most python experts avoid reload(). So what are they doing that I'm not? I love the ability of Python to quickly let you dive deep into your code and set up a difficult case with 2, it's hard to imagine giving this up, and it's hard to imagine using it without reload(). Thanks for any tips. From tjreedy at udel.edu Sat Sep 21 18:04:45 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 21 Sep 2013 18:04:45 -0400 Subject: reload and work flow suggestions In-Reply-To: <61d45045-187c-4be7-9da4-21a3124b753f@googlegroups.com> References: <61d45045-187c-4be7-9da4-21a3124b753f@googlegroups.com> Message-ID: On 9/21/2013 5:43 PM, Peter Cacioppi wrote: > This is an idea brought over from another post. > > When I write Python code I generally have 2 or 3 windows open simultaneously. > > 1) An editor for the actual code. > 2) The interactive interpreter. > 3) An editor for the unit tests. (Sometimes skipped for quick one-off scripts) At present, I use an Idle Shell and two editor windows. > My work flow tends to involve using 2 to debug the issues that come up with 1 and 3. I'll write some new code in 1, play around with it in 2, then solidify the tests in 3. Or a test in 3 fails and I dig around with it using 2. F5 in an editor window runs the code, puts the results in Shell, and leaves the objects loaded for interactive exploration in Shell. > My problem is that I tend to use reload() quite a bit. I want to call functions and construct objects that are inside the guts of 1 and pass them arguments that are stored as variables in 2. If I restart my session for 2 I lose these variables (iPython does mitigate the pain here somewhat). Hence, I reload() modules into 2 when they are changed. Since I work with files small enough to reload by rerunning, I have no use for reload(). > I use ipdb a lot in 2. I usually don't feel comfortable with virgin code or a debug fix that hasn't been stepped through with the debugger. I trust tests, formal and informal, and use occasional print to debug. > Is there something wrong with this work flow? I understand most python experts avoid reload(). So what are they doing that I'm not? I love the ability of Python to quickly let you dive deep into your code and set up a difficult case with 2, it's hard to imagine giving this up, and it's hard to imagine using it without reload(). Since 'experts do not use Idle', I must not be one ;-). I will let the real 'experts' explain what they do. -- Terry Jan Reedy From anikom15 at gmail.com Sun Sep 22 00:01:02 2013 From: anikom15 at gmail.com (=?ISO-8859-1?Q?Westley_Mart=EDnez?=) Date: Sat, 21 Sep 2013 21:01:02 -0700 (PDT) Subject: reload and work flow suggestions In-Reply-To: <61d45045-187c-4be7-9da4-21a3124b753f@googlegroups.com> References: <61d45045-187c-4be7-9da4-21a3124b753f@googlegroups.com> Message-ID: <1378bc23-5521-43e9-a6c0-8dde83ab7dfe@googlegroups.com> On Saturday, September 21, 2013 2:43:13 PM UTC-7, Peter Cacioppi wrote: > This is an idea brought over from another post. > > > > When I write Python code I generally have 2 or 3 windows open simultaneously. > > > > 1) An editor for the actual code. > > 2) The interactive interpreter. > > 3) An editor for the unit tests. (Sometimes skipped for quick one-off scripts) > > > > My work flow tends to involve using 2 to debug the issues that come up with 1 and 3. I'll write some new code in 1, play around with it in 2, then solidify the tests in 3. Or a test in 3 fails and I dig around with it using 2. > > > > My problem is that I tend to use reload() quite a bit. I want to call functions and construct objects that are inside the guts of 1 and pass them arguments that are stored as variables in 2. If I restart my session for 2 I lose these variables (iPython does mitigate the pain here somewhat). Hence, I reload() modules into 2 when they are changed. > > > > I use ipdb a lot in 2. I usually don't feel comfortable with virgin code or a debug fix that hasn't been stepped through with the debugger. > > > > Is there something wrong with this work flow? I understand most python experts avoid reload(). So what are they doing that I'm not? I love the ability of Python to quickly let you dive deep into your code and set up a difficult case with 2, it's hard to imagine giving this up, and it's hard to imagine using it without reload(). > > > > Thanks for any tips. In short, there's nothing wrong with any workflow so long as it works. From rustompmody at gmail.com Sun Sep 22 09:44:34 2013 From: rustompmody at gmail.com (rusi) Date: Sun, 22 Sep 2013 06:44:34 -0700 (PDT) Subject: reload and work flow suggestions In-Reply-To: <61d45045-187c-4be7-9da4-21a3124b753f@googlegroups.com> References: <61d45045-187c-4be7-9da4-21a3124b753f@googlegroups.com> Message-ID: <0f347cfc-153f-40c2-aca7-f637c7ac884c@googlegroups.com> On Sunday, September 22, 2013 3:13:13 AM UTC+5:30, Peter Cacioppi wrote: > This is an idea brought over from another post. > > When I write Python code I generally have 2 or 3 windows open simultaneously. > > > 1) An editor for the actual code. > 2) The interactive interpreter. > 3) An editor for the unit tests. (Sometimes skipped for quick one-off scripts) > > My work flow tends to involve using 2 to debug the issues that come up with 1 and 3. I'll write some new code in 1, play around with it in 2, then solidify the tests in 3. Or a test in 3 fails and I dig around with it using 2. > > > > My problem is that I tend to use reload() quite a bit. I want to call > functions and construct objects that are inside the guts of 1 and pass them > arguments that are stored as variables in 2. If I restart my session for 2 I > lose these variables (iPython does mitigate the pain here somewhat). Hence, I > reload() modules into 2 when they are changed. I (tend to) use emacs. Now before this becomes an editor-war, I need to say that its hardly a question of editor and mostly a question of workflow. For example I know some core emacs devs who use vi-mode in emacs and as the joke goes: Emacs is an excellent operating system; it only lacks a good editor. About workflow: Its important to get that 1. editor-inside-interpreter -- eg !vi in ipython 2. interpreter-and-editor side-by-side -- your workflow 3. interpreter-inside-editor -- natural for emacs and IDLE (I think) are significantly different And one important difference is that for 3. the burden of reload goes from python to the editor -- one hotkey and the buffer is reloaded into the interpreter. From peter.cacioppi at gmail.com Mon Sep 23 04:31:00 2013 From: peter.cacioppi at gmail.com (Peter Cacioppi) Date: Mon, 23 Sep 2013 01:31:00 -0700 (PDT) Subject: reload and work flow suggestions In-Reply-To: <61d45045-187c-4be7-9da4-21a3124b753f@googlegroups.com> References: <61d45045-187c-4be7-9da4-21a3124b753f@googlegroups.com> Message-ID: On Saturday, September 21, 2013 2:43:13 PM UTC-7, Peter Cacioppi wrote: > This is an idea brought over from another post. > > > > When I write Python code I generally have 2 or 3 windows open simultaneously. > > > > 1) An editor for the actual code. > > 2) The interactive interpreter. > > 3) An editor for the unit tests. (Sometimes skipped for quick one-off scripts) > > > > My work flow tends to involve using 2 to debug the issues that come up with 1 and 3. I'll write some new code in 1, play around with it in 2, then solidify the tests in 3. Or a test in 3 fails and I dig around with it using 2. > > > > My problem is that I tend to use reload() quite a bit. I want to call functions and construct objects that are inside the guts of 1 and pass them arguments that are stored as variables in 2. If I restart my session for 2 I lose these variables (iPython does mitigate the pain here somewhat). Hence, I reload() modules into 2 when they are changed. > > > > I use ipdb a lot in 2. I usually don't feel comfortable with virgin code or a debug fix that hasn't been stepped through with the debugger. > > > > Is there something wrong with this work flow? I understand most python experts avoid reload(). So what are they doing that I'm not? I love the ability of Python to quickly let you dive deep into your code and set up a difficult case with 2, it's hard to imagine giving this up, and it's hard to imagine using it without reload(). > > > > Thanks for any tips. Thanks for the tips guys. One thing re: editors and interactive environments. I'm not a huge emacs fan (ducking) and I really like iPython. In order to avoid calling reload, I've changed my workflow to the following. 1) The "real" code 2) The unit tests 3) A scratch script Then, I launch iPython, which can intellisense launch 3 easily. Then I make whatever changes I need to 1-3 to make a baby step forward, close iPython, and repeat. This seems to preserve the easy-to-dive-into, play-around-with-it fun that is Python without forcing me to call reload(). I suspect I'm now a bit more close to what the "experts" are doing. Thanks again, I love kibbutzing about work-flow, toys, etc. From rustompmody at gmail.com Mon Sep 23 05:35:09 2013 From: rustompmody at gmail.com (rusi) Date: Mon, 23 Sep 2013 02:35:09 -0700 (PDT) Subject: reload and work flow suggestions In-Reply-To: References: <61d45045-187c-4be7-9da4-21a3124b753f@googlegroups.com> Message-ID: On Monday, September 23, 2013 2:01:00 PM UTC+5:30, Peter Cacioppi wrote: > One thing re: editors and interactive environments. I'm not a huge emacs fan > (ducking) and I really like iPython. Heh! Yeah we are an endangered species G enerally N ot U sed E ditor for M iddle A ged C omputer S cientists > > > In order to avoid calling reload, I've changed my workflow to the following. > > > 1) The "real" code > 2) The unit tests > 3) A scratch script > > > > Then, I launch iPython, which can intellisense launch 3 easily. Then I make > whatever changes I need to 1-3 to make a baby step forward, close iPython, > and repeat. Hardly looks very ergonomic to me From oscar.j.benjamin at gmail.com Mon Sep 23 06:40:52 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 23 Sep 2013 11:40:52 +0100 Subject: reload and work flow suggestions In-Reply-To: References: <61d45045-187c-4be7-9da4-21a3124b753f@googlegroups.com> Message-ID: On 23 September 2013 10:35, rusi wrote: >> Then, I launch iPython, which can intellisense launch 3 easily. Then I make >> whatever changes I need to 1-3 to make a baby step forward, close iPython, >> and repeat. > > Hardly looks very ergonomic to me I'm not quite sure what's meant by intellisense here but using ipython with a scratch script works very well for me. Here's how a typical session works for writing a sqrt_floor() function that works for all positive integers: In [1]: import math In [2]: math.sqrt(16) Out[2]: 4.0 In [3]: math.sqrt(15) Out[3]: 3.872983346207417 In [4]: int(math.sqrt(15)) Out[4]: 3 In [5]: x = 10 ** 20 + 1 In [6]: int(math.sqrt(x ** 2)) == x Out[6]: False In [7]: edit tmp.py [At this point vim opens, I do some working on paper and write the following in vim: import math def sqrt_floor(y): x = int(y) while x ** 2 <= y < (x+1) ** 2: x = (x + y // x) // 2 return x ] done. Executing edited code... In [8]: sqrt_floor(100) Out[8]: 100 In [9]: sqrt_floor(101) Out[9]: 101 [Okay whoops! that's not what I wanted... Need to invert the condition in the while loop!] In [10]: edit tmp.py done. Executing edited code... In [11]: edit tmp.py done. Executing edited code... In [12]: sqrt_floor(101) Out[12]: 10 In [13]: sqrt_floor(100) Out[13]: 10 In [14]: x = 10 ** 20 + 1 In [15]: sqrt_floor(x ** 2) == x Out[15]: True [Okay that's better] In [16]: edit tmp.py [Now I'll test against a load of integers so the file looks like import math def sqrt_floor(y): x = int(y) while not (x ** 2 <= y < (x+1) ** 2): x = (x + y // x) // 2 return x for y in range(10 ** 6): x = sqrt_floor(y) assert x ** 2 <= y < (x+1) ** 2 ] done. Executing edited code... [All tests have passed but it took a little while so let's time this function] In [17]: timeit sqrt(10 ** 10) --------------------------------------------------------------------------- NameError Traceback (most recent call last) NameError: global name 'sqrt' is not defined In [18]: from math import sqrt In [19]: timeit sqrt(10 ** 10) 1000000 loops, best of 3: 393 ns per loop In [20]: timeit sqrt_floor(10 ** 10) 10000 loops, best of 3: 52.4 us per loop In [21]: edit tmp.py [Since sqrt is 100x faster we can use it internally to get an initial guess. Now the file looks like: import math def sqrt_floor(y): x = int(math.sqrt(y)) while not (x ** 2 <= y < (x+1) ** 2): x = (x + y // x) // 2 return x for y in range(10 ** 6): x = sqrt_floor(y) assert x ** 2 <= y < (x+1) ** 2 ] done. Executing edited code... In [22]: timeit sqrt_floor(10 ** 10) 100000 loops, best of 3: 4.58 us per loop [Great. That's 10x faster than before and probably as good as it gets for speed but this optimisation has problems...] In [23]: sqrt_floor(10 ** 1000) --------------------------------------------------------------------------- OverflowError Traceback (most recent call last) in () ----> 1 sqrt_floor(10 ** 1000) Q:\tmp.py in sqrt_floor(y) 2 3 def sqrt_floor(y): ----> 4 x = int(math.sqrt(y)) 5 while not (x ** 2 <= y < (x+1) ** 2): 6 x = (x + y // x) // 2 OverflowError: long int too large to convert to float In [24]: edit tmp.py [Now the file looks like import math def sqrt_floor(y): try: x = int(math.sqrt(y)) except OverflowError: x = y while not (x ** 2 <= y < (x+1) ** 2): x = (x + y // x) // 2 return x for y in range(10 ** 6): x = sqrt_floor(y) assert x ** 2 <= y < (x+1) ** 2 ] done. Executing edited code... [ This reruns the tests in the file; no AssertionError so all good ] In [25]: sqrt_floor(10 ** 1000) Out[25]: 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000L In [26]: timeit sqrt(10 ** 10) 1000000 loops, best of 3: 381 ns per loop And now we're basically done. Recheck the proof, think about how to handle negative numbers, write a docstring and move on. Oscar From peter.cacioppi at gmail.com Mon Sep 23 17:35:59 2013 From: peter.cacioppi at gmail.com (Peter Cacioppi) Date: Mon, 23 Sep 2013 14:35:59 -0700 (PDT) Subject: reload and work flow suggestions In-Reply-To: <61d45045-187c-4be7-9da4-21a3124b753f@googlegroups.com> References: <61d45045-187c-4be7-9da4-21a3124b753f@googlegroups.com> Message-ID: <30ffd428-183b-4672-b5d6-3f4ce5b0cede@googlegroups.com> On Saturday, September 21, 2013 2:43:13 PM UTC-7, Peter Cacioppi wrote: > This is an idea brought over from another post. > > > > When I write Python code I generally have 2 or 3 windows open simultaneously. > > > > 1) An editor for the actual code. > > 2) The interactive interpreter. > > 3) An editor for the unit tests. (Sometimes skipped for quick one-off scripts) > > > > My work flow tends to involve using 2 to debug the issues that come up with 1 and 3. I'll write some new code in 1, play around with it in 2, then solidify the tests in 3. Or a test in 3 fails and I dig around with it using 2. > > > > My problem is that I tend to use reload() quite a bit. I want to call functions and construct objects that are inside the guts of 1 and pass them arguments that are stored as variables in 2. If I restart my session for 2 I lose these variables (iPython does mitigate the pain here somewhat). Hence, I reload() modules into 2 when they are changed. > > > > I use ipdb a lot in 2. I usually don't feel comfortable with virgin code or a debug fix that hasn't been stepped through with the debugger. > > > > Is there something wrong with this work flow? I understand most python experts avoid reload(). So what are they doing that I'm not? I love the ability of Python to quickly let you dive deep into your code and set up a difficult case with 2, it's hard to imagine giving this up, and it's hard to imagine using it without reload(). > > > > Thanks for any tips. So when I say I exploit the intellisense of iPython, it's simply this. I have a "working on X" script that has some handy variables and runs whatever is currently of interest in the functional code or the units tests. It even launches into the ipdb debugger, if needed. The "working on X" is kept in the scripts directory of iPython. The older "working on Y" scripts are renamed to "not working on Y", so that there is only one script in that particular directory that starts with "wo". When iPython launches, I just type run wo [tab] and it completes the file name. So the whole "proxy for reload" process is actually pretty quick. For me it's faster than what I used to do with reload(), plus the "working on" script keeps a nice record of where I was in a debugging/experiment process. iPython makes it easy to create history dumps which can then be selectively copied over to the "working on" if I forget what was useful. At any rate, it sounds like emacs plays very well with python and iPython, not disparaging the utility of emacs kung fu. But if you want to use a different editor (I use idle for editing), and also use iPython for interactivity (which is very slick), this workflow works nice for me and might be helpful to you. Cheers From john_ladasky at sbcglobal.net Sun Sep 22 00:39:07 2013 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Sat, 21 Sep 2013 21:39:07 -0700 (PDT) Subject: Why do I have to use "global" so much when using Turtle? Message-ID: <0b028e65-37b2-492a-83c0-0d76d037c165@googlegroups.com> Hi, folks, Some of you may remember that I am teaching some high school students how to program. Because they all love graphics, I have been investigating the turtle module, which I gather is built on top of Tk. I can see that real-time applications are possible. I'm writing a classic "bouncing-balls" program to demonstrate to my students. In the main program code, I instantiate a turtle.Screen, named sc. I draw a bounding box, whose size is described by the variables edgew and edgeh. I have a list of Turtle objects, which I named balls. I have a timer interval stored in tick. In the main loop of my program, I bind a function to update the positions of the balls to a timer, thus: sc.ontimer(move_balls, tick) Inside my move_balls function, I could not get ANYTHING done without the following declaration: global balls, edgew, edgeh, tick For a while, I had a "quit" function that I bound to the q key: sc.onkeypress(quit, "q") The quit function simply printed a message, and then called sc.bye(). As with move_balls, quit wouldn't work unless I had a "global sc" declaration in it. (My shortened program skips my function and just binds sc.bye to the q key, avoiding the need for globals.) Once I use globals, everything works fine. However, I haven't taught my students a thing about the globals declaration. Furthermore, I was always taught that the need for global variables generally indicated that YOU were writing a SLOPPY program! However, neither Screen.ontimer() not Screen.onkeypress() appear to give me a way to pass arguments to functions of my own. Why don't they? Is this some limitation of Tk? I have worked with other GUI's before, and I don't remember having to jump through this particular hoop. I'm torn between proceeding with turtle, burdening my students with comprehending globals (they're young, they just barely grasp the idea of namespaces) -- or, abandoning turtle for another approach. Comments appreciated! From __peter__ at web.de Sun Sep 22 04:15:02 2013 From: __peter__ at web.de (Peter Otten) Date: Sun, 22 Sep 2013 10:15:02 +0200 Subject: Why do I have to use "global" so much when using Turtle? References: <0b028e65-37b2-492a-83c0-0d76d037c165@googlegroups.com> Message-ID: John Ladasky wrote: > Hi, folks, > > Some of you may remember that I am teaching some high school students how > to program. Because they all love graphics, I have been investigating the > turtle module, which I gather is built on top of Tk. I can see that > real-time applications are possible. I'm writing a classic > "bouncing-balls" program to demonstrate to my students. > > In the main program code, I instantiate a turtle.Screen, named sc. > > I draw a bounding box, whose size is described by the variables edgew and > edgeh. I have a list of Turtle objects, which I named balls. I have a > timer interval stored in tick. > > In the main loop of my program, I bind a function to update the positions > of the balls to a timer, thus: > > sc.ontimer(move_balls, tick) > > Inside my move_balls function, I could not get ANYTHING done without the > following declaration: > > global balls, edgew, edgeh, tick That's not limited to turtle, Python in general forces you to make shared state explicit. Simple alternatives to global would be a degenerate class class state: pass or a magic import import __main__ as state With both of these (pseudo-)globals can be set with state.some_global = some_value However, most of the names you list above look like their values need not be altered from within the function and thus the name not be declared global anyway. To be sure you'd have to show us the code... From steve+comp.lang.python at pearwood.info Sun Sep 22 06:43:20 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Sep 2013 10:43:20 GMT Subject: Why do I have to use "global" so much when using Turtle? References: <0b028e65-37b2-492a-83c0-0d76d037c165@googlegroups.com> Message-ID: <523ec9c8$0$29988$c3e8da3$5496439d@news.astraweb.com> On Sat, 21 Sep 2013 21:39:07 -0700, John Ladasky wrote: > Hi, folks, > > Some of you may remember that I am teaching some high school students > how to program. Because they all love graphics, I have been > investigating the turtle module, which I gather is built on top of Tk. > I can see that real-time applications are possible. I'm writing a > classic "bouncing-balls" program to demonstrate to my students. > > In the main program code, I instantiate a turtle.Screen, named sc. > > I draw a bounding box, whose size is described by the variables edgew > and edgeh. I have a list of Turtle objects, which I named balls. I > have a timer interval stored in tick. > > In the main loop of my program, I bind a function to update the > positions of the balls to a timer, thus: > > sc.ontimer(move_balls, tick) > > Inside my move_balls function, I could not get ANYTHING done without the > following declaration: > > global balls, edgew, edgeh, tick That doesn't sound right. You don't need to declare globals unless you are rebinding them (assigning to the name). So if you do something like this: def move_balls(): for ball in balls: do_something_with(ball) you're not assigning to global "balls" so no global declaration is needed. But if you do this: def move_balls(): balls = sorted(balls) # say for ball in balls: do_something_with(ball) then you need a global declaration since you're assigning to the global variable. Likewise for tick, edgew and edgeh -- if you're just *reading* their value, you don't need to declare them. > For a while, I had a "quit" function that I bound to the q key: > > sc.onkeypress(quit, "q") > > The quit function simply printed a message, and then called sc.bye(). > As with move_balls, quit wouldn't work unless I had a "global sc" > declaration in it. Again, that sounds wrong. This should work, since sc is not assigned to: def quit(): print("Bye now!") sc.bye() If that's not the case, there's something you're not telling us about your code. Actual working examples are appreciated. -- Steven From ned at nedbatchelder.com Sun Sep 22 06:56:02 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sun, 22 Sep 2013 06:56:02 -0400 Subject: Why do I have to use "global" so much when using Turtle? In-Reply-To: <0b028e65-37b2-492a-83c0-0d76d037c165@googlegroups.com> References: <0b028e65-37b2-492a-83c0-0d76d037c165@googlegroups.com> Message-ID: <523ECCC2.602@nedbatchelder.com> On 9/22/13 12:39 AM, John Ladasky wrote: > For a while, I had a "quit" function that I bound to the q key: > > sc.onkeypress(quit, "q") > > The quit function simply printed a message, and then called sc.bye(). As with move_balls, quit wouldn't work unless I had a "global sc" declaration in it. (My shortened program skips my function and just binds sc.bye to the q key, avoiding the need for globals.) It sounds like you didn't need as many global statements as you think. In particular, you only need to use "global" if you are assigning to a global name within a function. The quit function you describe didn't have a "sc = ..." statement in it, and so should not have needed a "global sc" statement. Can you show the code with the global statements? There's very likely a way to get rid of some of them. --Ned. From nobody at nowhere.com Sun Sep 22 09:48:58 2013 From: nobody at nowhere.com (Nobody) Date: Sun, 22 Sep 2013 14:48:58 +0100 Subject: Why do I have to use "global" so much when using Turtle? References: <0b028e65-37b2-492a-83c0-0d76d037c165@googlegroups.com> Message-ID: On Sat, 21 Sep 2013 21:39:07 -0700, John Ladasky wrote: > However, neither Screen.ontimer() not Screen.onkeypress() appear to give > me a way to pass arguments to functions of my own. Why don't they? Is > this some limitation of Tk? I have worked with other GUI's before, and I > don't remember having to jump through this particular hoop. The usual approach in Python is to pass a bound method of an object, and keep all of the data on that object. From john_ladasky at sbcglobal.net Sun Sep 22 14:57:50 2013 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Sun, 22 Sep 2013 11:57:50 -0700 (PDT) Subject: Why do I have to use "global" so much when using Turtle? In-Reply-To: <0b028e65-37b2-492a-83c0-0d76d037c165@googlegroups.com> References: <0b028e65-37b2-492a-83c0-0d76d037c165@googlegroups.com> Message-ID: All right, never mind! I hacked around this morning, making some changes to parts of my program that I thought were unrelated to my namespace issues. I was paring it down to a minimal example, to post here as Ned requested. As an experiment, I also commented out the global declaration line in move_balls... and everything worked this time. I'm baffled as to what necessitated the global declaration in the first place. But since the goal was to teach my students a graphical tool, I don't think that I will investigate this matter any further. From rustompmody at gmail.com Sun Sep 22 21:44:35 2013 From: rustompmody at gmail.com (rusi) Date: Sun, 22 Sep 2013 18:44:35 -0700 (PDT) Subject: Why do I have to use "global" so much when using Turtle? In-Reply-To: References: <0b028e65-37b2-492a-83c0-0d76d037c165@googlegroups.com> Message-ID: On Monday, September 23, 2013 12:27:50 AM UTC+5:30, John Ladasky wrote: > All right, never mind! > > > I hacked around this morning, making some changes to parts of my program that > I thought were unrelated to my namespace issues. I was paring it down to a > minimal example, to post here as Ned requested. As an experiment, I also > commented out the global declaration line in move_balls... and everything > worked this time. > > > I'm baffled as to what necessitated the global declaration in the first > place. But since the goal was to teach my students a graphical tool, I don't > think that I will investigate this matter any further. Not related to your question but to turtle graphics Have you seen this? http://code.google.com/p/pynguin/ From john_ladasky at sbcglobal.net Mon Sep 23 03:26:22 2013 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Mon, 23 Sep 2013 00:26:22 -0700 (PDT) Subject: Why do I have to use "global" so much when using Turtle? In-Reply-To: References: <0b028e65-37b2-492a-83c0-0d76d037c165@googlegroups.com> Message-ID: No, Rusi, I have never seen Pynguin before -- and it looks very cool! From rosuav at gmail.com Sun Sep 22 05:32:49 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 22 Sep 2013 19:32:49 +1000 Subject: [Savoynet] My sorrow, that I may share it with you In-Reply-To: References: <9bfbf302f8431a3b8675a9081131c68a@connexus.net.au> Message-ID: On Sun, Sep 22, 2013 at 7:02 PM, Derrick McCLURE wrote: > Seriously, folks - a performing group which calls itself a Gilbert and > Sullivan Society but doesn't perform Gilbert and Sullivan is in the same > category as a fool who doesn't follify or a cock who doesn't crow, and > should get the same treatment. I believe there are lots of nice rivers in > British Columbia? These Societies stand on a similar basis to Limited Liability Companies, though. You may wind them up, you cannot conveniently put concrete blocks on their feet, blow them up with dynamite, and have them land in The Canal... ChrisA From steve+comp.lang.python at pearwood.info Sun Sep 22 06:25:19 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Sep 2013 10:25:19 GMT Subject: [Savoynet] My sorrow, that I may share it with you References: <9bfbf302f8431a3b8675a9081131c68a@connexus.net.au> Message-ID: <523ec58e$0$29988$c3e8da3$5496439d@news.astraweb.com> On Sun, 22 Sep 2013 19:32:49 +1000, Chris Angelico wrote: > On Sun, Sep 22, 2013 at 7:02 PM, Derrick McCLURE > wrote: >> Seriously, folks - a performing group which calls itself a Gilbert and >> Sullivan Society but doesn't perform Gilbert and Sullivan is in the >> same category as a fool who doesn't follify or a cock who doesn't crow, >> and should get the same treatment. I believe there are lots of nice >> rivers in British Columbia? > > These Societies stand on a similar basis to Limited Liability Companies, > though. You may wind them up, you cannot conveniently put concrete > blocks on their feet, blow them up with dynamite, and have them land in > The Canal... Try this: import dirtydeeds muscle = dirtydeeds.hire() muscle.concrete_shoes(performance_group) muscle.dynamite.explode(performance_group) remains = muscle.collect(performance_group) muscle.dump(remains, "The Canal") It's not free software (free as in beer), but I'm told that it is dirt cheap... -- Steven From rosuav at gmail.com Sun Sep 22 06:56:44 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 22 Sep 2013 20:56:44 +1000 Subject: [Savoynet] My sorrow, that I may share it with you In-Reply-To: <523ec58e$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <9bfbf302f8431a3b8675a9081131c68a@connexus.net.au> <523ec58e$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Sep 22, 2013 at 8:25 PM, Steven D'Aprano wrote: > On Sun, 22 Sep 2013 19:32:49 +1000, Chris Angelico wrote: > >> On Sun, Sep 22, 2013 at 7:02 PM, Derrick McCLURE >> wrote: >>> Seriously, folks - a performing group which calls itself a Gilbert and >>> Sullivan Society but doesn't perform Gilbert and Sullivan is in the >>> same category as a fool who doesn't follify or a cock who doesn't crow, >>> and should get the same treatment. I believe there are lots of nice >>> rivers in British Columbia? >> >> These Societies stand on a similar basis to Limited Liability Companies, >> though. You may wind them up, you cannot conveniently put concrete >> blocks on their feet, blow them up with dynamite, and have them land in >> The Canal... > > Try this: > > import dirtydeeds > > muscle = dirtydeeds.hire() > muscle.concrete_shoes(performance_group) > muscle.dynamite.explode(performance_group) > remains = muscle.collect(performance_group) > muscle.dump(remains, "The Canal") > > > It's not free software (free as in beer), but I'm told that it is dirt > cheap... I would also recommend: del gmail except that I haven't gotten around to finding a replacement. So I managed instead to mix two different forms of humour (Gilbert & Sullivan, and the Goon Show), and post it to a place that shares a name with a third (Python)... ChrisA From andypu at zoho.com Sun Sep 22 13:09:21 2013 From: andypu at zoho.com (andypu at zoho.com) Date: Sun, 22 Sep 2013 10:09:21 -0700 (PDT) Subject: Animations and images with use for commercial license Message-ID: Hello all, I am designing a roleplay game, right now i think i might go into the anime direction and style it accordingly... how do i get animations and images to give it a nice feeling. Where do you get your graphics from for such kind of games do you paint them yourself? From tjreedy at udel.edu Sun Sep 22 13:47:33 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 22 Sep 2013 13:47:33 -0400 Subject: Animations and images with use for commercial license In-Reply-To: References: Message-ID: On 9/22/2013 1:09 PM, andypu at zoho.com wrote: > I am designing a roleplay game, right now i think i might go into the > anime direction and style it accordingly... how do i get animations > and images to give it a nice feeling. Where do you get your graphics > from for such kind of games do you paint them yourself? This is not really a Python question. You might do better on the pygame list or a more general game developer forum. -- Terry Jan Reedy From chitturk at uah.edu Sun Sep 22 16:26:06 2013 From: chitturk at uah.edu (chitturk at uah.edu) Date: Sun, 22 Sep 2013 13:26:06 -0700 (PDT) Subject: python, pythontex and plots Message-ID: <6ce735c9-dfd4-45df-8423-8eb909d4de34@googlegroups.com> \documentclass[12pt]{article} \usepackage{graphicx} \usepackage{wrapfig} % Allows in-line images \usepackage{pythontex} \setpythontexworkingdir{.} \begin{document} This is an example of using pythontex \begin{pycode} import pylab as p import numpy as np x = np.linspace(0.0,1.0,10) y = 2.0*x + 5.0 xmax = max(x) ymax = max(y) p.plot(x,y) outputfile = 'myplot.png' p.savefig(outputfile) p.clf() \end{pycode} % this works fine, I can print the name of the output file, variables The plot is named \py{outputfile}, the max in x was \py{xmax} and \py{ymax} % now I would like to plot it, this works \includegraphics[scale=0.75]{myplot.png} % but when I do this %\includegraphics[scale=0.75]{\py{outputfile}} % I get %! File ended while scanning definition of \filename at base. % % } % no pdf \end{document} From steve+comp.lang.python at pearwood.info Sun Sep 22 20:58:59 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Sep 2013 00:58:59 GMT Subject: python, pythontex and plots References: <6ce735c9-dfd4-45df-8423-8eb909d4de34@googlegroups.com> Message-ID: <523f9252$0$29988$c3e8da3$5496439d@news.astraweb.com> I don't usually top post, but for this I'll make an exception because I have *no idea* what any of your post means. Are you actually asking a question? I can't see a question mark in it, so there's no explicit question. Are you just sharing something interesting you have learned? Expecting us to read your mind and intuit what the question is? Why do nearly, but not quite all, the lines in your post start with % or \ or sometimes both? It looks like Postscript rather than Python. Perhaps you should try again, and this time don't assume that we're familiar with whatever it is you're doing. Remember to include natural language explaining what your problem is, what result you expected, what result you actually got. In this forum, use English please. This is *especially* critical if using an unusual technology that most people are not familiar with. I strongly recommend that first you read this: http://sscce.org/? Its written for Java developers, but the same basic principles apply for Python. Remember that the number one language you should be using for communication is natural language (English in this forum) and code only second. Thank you. Steve On Sun, 22 Sep 2013 13:26:06 -0700, chitturk wrote: > \documentclass[12pt]{article} > \usepackage{graphicx} > \usepackage{wrapfig} % Allows in-line images \usepackage{pythontex} > \setpythontexworkingdir{.} > \begin{document} > > This is an example of using pythontex > > \begin{pycode} > > import pylab as p > import numpy as np > x = np.linspace(0.0,1.0,10) > y = 2.0*x + 5.0 > xmax = max(x) > ymax = max(y) > p.plot(x,y) > outputfile = 'myplot.png' > p.savefig(outputfile) > p.clf() > > \end{pycode} > > % this works fine, I can print the name of the output file, variables > > The plot is named \py{outputfile}, the max in x was \py{xmax} and > \py{ymax} > > % now I would like to plot it, this works > > \includegraphics[scale=0.75]{myplot.png} > > % but when I do this > > %\includegraphics[scale=0.75]{\py{outputfile}} > > % I get > > %! File ended while scanning definition of \filename at base. % text> > % } > % no pdf > > > > \end{document} From chitturk at uah.edu Sun Sep 22 22:16:35 2013 From: chitturk at uah.edu (chitturk at uah.edu) Date: Sun, 22 Sep 2013 19:16:35 -0700 (PDT) Subject: python, pythontex and plots In-Reply-To: <523f9252$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <6ce735c9-dfd4-45df-8423-8eb909d4de34@googlegroups.com> <523f9252$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: 1) The file is LaTeX 2) the % means LaTeX will ignore it. 3) The question was about using pythontex with LaTeX 4) I included the file so you (OK, others) could see what I was trying 5) The problem had to do with accessing a file name within the python script using \py{outputfile} 6) pythontex is a terrific package that I enjoy using 7) I was looking for help on debugging this error. 8) I was trying to find out why I could not do \py{outfilename} On Sunday, September 22, 2013 7:58:59 PM UTC-5, Steven D'Aprano wrote: > I don't usually top post, but for this I'll make an exception because I > > have *no idea* what any of your post means. > > > > Are you actually asking a question? I can't see a question mark in it, so > > there's no explicit question. Are you just sharing something interesting > > you have learned? Expecting us to read your mind and intuit what the > > question is? > > > > Why do nearly, but not quite all, the lines in your post start with % or > > \ or sometimes both? It looks like Postscript rather than Python. > > > > Perhaps you should try again, and this time don't assume that we're > > familiar with whatever it is you're doing. Remember to include natural > > language explaining what your problem is, what result you expected, what > > result you actually got. In this forum, use English please. This is > > *especially* critical if using an unusual technology that most people are > > not familiar with. > > > > I strongly recommend that first you read this: > > > > http://sscce.org/ > > > > Its written for Java developers, but the same basic principles apply for > > Python. Remember that the number one language you should be using for > > communication is natural language (English in this forum) and code only > > second. > > > > Thank you. > > > > > > Steve > > > > On Sun, 22 Sep 2013 13:26:06 -0700, chitturk wrote: > > > > > \documentclass[12pt]{article} > > > \usepackage{graphicx} > > > \usepackage{wrapfig} % Allows in-line images \usepackage{pythontex} > > > \setpythontexworkingdir{.} > > > \begin{document} > > > > > > This is an example of using pythontex > > > > > > \begin{pycode} > > > > > > import pylab as p > > > import numpy as np > > > x = np.linspace(0.0,1.0,10) > > > y = 2.0*x + 5.0 > > > xmax = max(x) > > > ymax = max(y) > > > p.plot(x,y) > > > outputfile = 'myplot.png' > > > p.savefig(outputfile) > > > p.clf() > > > > > > \end{pycode} > > > > > > % this works fine, I can print the name of the output file, variables > > > > > > The plot is named \py{outputfile}, the max in x was \py{xmax} and > > > \py{ymax} > > > > > > % now I would like to plot it, this works > > > > > > \includegraphics[scale=0.75]{myplot.png} > > > > > > % but when I do this > > > > > > %\includegraphics[scale=0.75]{\py{outputfile}} > > > > > > % I get > > > > > > %! File ended while scanning definition of \filename at base. % > > text> > > > % } > > > % no pdf > > > > > > > > > > > > \end{document} From steve+comp.lang.python at pearwood.info Sun Sep 22 23:38:28 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Sep 2013 03:38:28 GMT Subject: python, pythontex and plots References: <6ce735c9-dfd4-45df-8423-8eb909d4de34@googlegroups.com> <523f9252$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <523fb7b3$0$29992$c3e8da3$5496439d@news.astraweb.com> chitturk, you will probably get better answers if you actually explain your question rather than writing as if we can read your mind. More comments below: On Sun, 22 Sep 2013 19:16:35 -0700, chitturk wrote: > 1) The file is LaTeX > 2) the % means LaTeX will ignore it. Shouldn't you ask this on a LaTeX forum then? How is your problem related to Python? If it is a Python error, you should explain how you know it is a Python error rather than a LaTeX error, because to me it looks like a LaTeX error. > 3) The question was about using pythontex with LaTeX And pythontex is what? An interface to Python via LaTeX? Are you getting a Python error or a LaTeX error? It seems to me that you are getting a LaTeX error, and that Python is irrelevant here. If you have information that suggests otherwise, you should share it with us. 4) I included the file so you (OK, others) could see what I was trying Problem is that it is not clear what parts are the file and what parts, if any, are your commentary on the file. You shouldn't assume that Python programmers will be experts on LaTeX syntax and be able to read your code. > 5) The problem had to do with accessing a file name within the python > script using \py{outputfile} If I am reading your file/comments correctly, the error you get is not a Python error, but a LaTeX error: %! File ended while scanning definition of \filename at base. % % } % no pdf If I am wrong, explain to me how you decided that this was a Python error rather than LaTeX. I've been using Python for over 15 years, and this is the first time I've seen anything even remotely like that. It is not clear to me whether "no pdf" is your comment, the output of pythontex, the output of LaTeX, or something else. It is also not clear whether % is literally part of the output, or just a placeholder for something you thought was irrelevant. > 6) pythontex is a terrific package that I enjoy using Glad to hear it. > 7) I was looking for help on debugging this error. > 8) I was trying to find out why I could not do \py{outfilename} \py{outputfilename} isn't Python code, so I'm not sure why you think a Python forum is the right place to ask about this. For us to help you, we'll probably need to know: - What is outputfilename? - Are you sure it corresponds to an actual file? A readable file? (Check the permissions.) Containing the right output? E.g. if you're expecting a PDF file, but giving it a PNG file, it probably won't work. - What Python code ends up being executed when you run \py {outputfilename}? - Can you run that code successfully from Python itself, bypassing pythontex? - If not, what result did you expect? What result did you get? - If you got an exception, what was the entire exception? - Any other relevant information that comes up while investigating. Help us to help you. Excessively concise questions written for an audience who already knows everything you know is not likely to get a lot of help. -- Steven From rustompmody at gmail.com Mon Sep 23 00:54:20 2013 From: rustompmody at gmail.com (rusi) Date: Sun, 22 Sep 2013 21:54:20 -0700 (PDT) Subject: python, pythontex and plots In-Reply-To: <523fb7b3$0$29992$c3e8da3$5496439d@news.astraweb.com> References: <6ce735c9-dfd4-45df-8423-8eb909d4de34@googlegroups.com> <523f9252$0$29988$c3e8da3$5496439d@news.astraweb.com> <523fb7b3$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0a4edbd9-8ed7-4967-9996-0b70c398859d@googlegroups.com> Take a look at babel http://www.cs.unm.edu/~eschulte/data/CISE-13-3-SciProg.pdf http://orgmode.org/worg/org-contrib/babel/intro.html Its my impression that babel supports everything and more that pylatex does ...the catch is that its under emacs...!! From chitturk at uah.edu Mon Sep 23 10:09:45 2013 From: chitturk at uah.edu (chitturk at uah.edu) Date: Mon, 23 Sep 2013 07:09:45 -0700 (PDT) Subject: python, pythontex and plots In-Reply-To: <0a4edbd9-8ed7-4967-9996-0b70c398859d@googlegroups.com> References: <6ce735c9-dfd4-45df-8423-8eb909d4de34@googlegroups.com> <523f9252$0$29988$c3e8da3$5496439d@news.astraweb.com> <523fb7b3$0$29992$c3e8da3$5496439d@news.astraweb.com> <0a4edbd9-8ed7-4967-9996-0b70c398859d@googlegroups.com> Message-ID: True, I did not explain what I was trying to do. pythontex is a package that allows the inclusion of python code within a LaTeX document - (sort of like python.sty, but IMO, better) - I use it along with noweb to create documents that contain documentation, code and output of the code - and pythontex allows me to access variables within the python code embedded in the LaTeX - except for the case I mentioned ... Within the python code (inside the LaTeX document) I had a "savefig(outputfile)" and I was trying to reference the outputfile using \py{outputfile} It may be that someone on the comp.text.tex group may have an answer (there may be users of pythontex on that newsgroup) On Sunday, September 22, 2013 11:54:20 PM UTC-5, rusi wrote: > Take a look at babel > > http://www.cs.unm.edu/~eschulte/data/CISE-13-3-SciProg.pdf > > http://orgmode.org/worg/org-contrib/babel/intro.html > > > > Its my impression that babel supports everything and more that pylatex does > > > > ...the catch is that its under emacs...!! From piet at vanoostrum.org Tue Sep 24 14:38:00 2013 From: piet at vanoostrum.org (Piet van Oostrum) Date: Tue, 24 Sep 2013 14:38:00 -0400 Subject: python, pythontex and plots References: <6ce735c9-dfd4-45df-8423-8eb909d4de34@googlegroups.com> <523f9252$0$29988$c3e8da3$5496439d@news.astraweb.com> <523fb7b3$0$29992$c3e8da3$5496439d@news.astraweb.com> <0a4edbd9-8ed7-4967-9996-0b70c398859d@googlegroups.com> Message-ID: chitturk at uah.edu writes: > True, I did not explain what I was trying to do. > > pythontex is a package that allows the inclusion of python code within a > LaTeX document - (sort of like python.sty, but IMO, better) - I use > it along with noweb to create documents that contain documentation, > code and output of the code - and pythontex allows me to access variables > within the python code embedded in the LaTeX - except for the case > I mentioned ... Within the python code (inside the LaTeX document) I had > a "savefig(outputfile)" and I was trying to reference the outputfile > using \py{outputfile} It could be that \includegraphics needs an expandable TeX form for its filename, and \py probably isn't. I haven't tried pythontex yet (I didn't know about it before your posting), so I can only guess. I am going to try it out later. But if I am correct then the following might work: \newcommand{\filename}{} \edef\filename{\py{outputfile}} \includegraphics[scale=0.75]{\filename} -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From worthingtonclinton at gmail.com Sun Sep 22 21:14:43 2013 From: worthingtonclinton at gmail.com (worthingtonclinton at gmail.com) Date: Sun, 22 Sep 2013 18:14:43 -0700 (PDT) Subject: Directory Web Site Message-ID: <9c1aee48-7d5e-49d3-ae8c-b5d422cecb9b@googlegroups.com> Was hoping to get some tips or advice on scripting a program that would sort through my many links on my directory website and print out to me the ones that are broken or no longer functioning so that I could fix or remove them from the site. Any help, ideas, advice will be greatly appreciated. From joel.goldstick at gmail.com Sun Sep 22 21:36:25 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sun, 22 Sep 2013 21:36:25 -0400 Subject: Directory Web Site In-Reply-To: <9c1aee48-7d5e-49d3-ae8c-b5d422cecb9b@googlegroups.com> References: <9c1aee48-7d5e-49d3-ae8c-b5d422cecb9b@googlegroups.com> Message-ID: On Sun, Sep 22, 2013 at 9:14 PM, wrote: > Was hoping to get some tips or advice on scripting a program that would > sort through my many links on my directory website and print out to me the > ones that are broken or no longer functioning so that I could fix or remove > them from the site. Any help, ideas, advice will be greatly appreciated. > -- > https://mail.python.org/mailman/listinfo/python-list > This is a python list. is this python related? what have you tried? Do you know about beautiful soup or requests? they can help you I think. You really need to provide more information for any useful help here -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at davea.name Sun Sep 22 21:59:14 2013 From: davea at davea.name (Dave Angel) Date: Mon, 23 Sep 2013 01:59:14 +0000 (UTC) Subject: Directory Web Site References: <9c1aee48-7d5e-49d3-ae8c-b5d422cecb9b@googlegroups.com> Message-ID: On 22/9/2013 21:14, worthingtonclinton at gmail.com wrote: > Was hoping to get some tips or advice on scripting a program that would sort through my many links on my directory website and print out to me the ones that are broken or no longer functioning so that I could fix or remove them from the site. Any help, ideas, advice will be greatly appreciated. Since it's your own website, the best answer is probably to process the source to that site. Was it written by a python script? Otherwise, if the site is reasonably correct (as most are not), then Beautiful Soup is probably the place to start. -- DaveA From worthingtonclinton at gmail.com Sun Sep 22 22:02:20 2013 From: worthingtonclinton at gmail.com (worthingtonclinton at gmail.com) Date: Sun, 22 Sep 2013 19:02:20 -0700 (PDT) Subject: Directory Web Site In-Reply-To: References: <9c1aee48-7d5e-49d3-ae8c-b5d422cecb9b@googlegroups.com> Message-ID: On Sunday, September 22, 2013 9:36:25 PM UTC-4, Joel Goldstick wrote: > On Sun, Sep 22, 2013 at 9:14 PM, wrote: > > Was hoping to get some tips or advice on scripting a program that would sort through my many links on my directory website and print out to me the ones that are broken or no longer functioning so that I could fix or remove them from the site. Any help, ideas, advice will be greatly appreciated. > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > > > This is a python list.? is this python related? what have you tried?? Do you know about beautiful soup or requests?? they can help you I think.? You really need to provide more information for any useful help here > > > > > -- > > > Joel Goldstick > http://joelgoldstick.com I'm trying to create a Python script that will search through the url links on my directory website and using a logic statement like, if: (how ever i would establish in python that the url is not broken) then return, elsif: (link is broken) then: print '%s is broken.' (%s being the name of the link). I want the program to perform this on all the links so that I can easily see which links are useless on my website so my page doesn't wind up functionally being difficult and clouded with broken links like every other crappy directory. From worthingtonclinton at gmail.com Sun Sep 22 22:04:30 2013 From: worthingtonclinton at gmail.com (worthingtonclinton at gmail.com) Date: Sun, 22 Sep 2013 19:04:30 -0700 (PDT) Subject: Directory Web Site In-Reply-To: References: <9c1aee48-7d5e-49d3-ae8c-b5d422cecb9b@googlegroups.com> Message-ID: <9a6970e2-c197-4c3d-8a5b-a898942a1652@googlegroups.com> On Sunday, September 22, 2013 9:59:14 PM UTC-4, Dave Angel wrote: > On 22/9/2013 21:14, worthingtonclinton at gmail.com wrote: > > > > > Was hoping to get some tips or advice on scripting a program that would sort through my many links on my directory website and print out to me the ones that are broken or no longer functioning so that I could fix or remove them from the site. Any help, ideas, advice will be greatly appreciated. > > > > Since it's your own website, the best answer is probably to process the > > source to that site. Was it written by a python script? > > > > Otherwise, if the site is reasonably correct (as most are not), then > > Beautiful Soup is probably the place to start. > > > > -- > > DaveA Web page is in HTML created using Dreamweaver. From rosuav at gmail.com Mon Sep 23 03:14:30 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 23 Sep 2013 17:14:30 +1000 Subject: Directory Web Site In-Reply-To: <9c1aee48-7d5e-49d3-ae8c-b5d422cecb9b@googlegroups.com> References: <9c1aee48-7d5e-49d3-ae8c-b5d422cecb9b@googlegroups.com> Message-ID: On Mon, Sep 23, 2013 at 11:14 AM, wrote: > Was hoping to get some tips or advice on scripting a program that would sort through my many links on my directory website and print out to me the ones that are broken or no longer functioning so that I could fix or remove them from the site. Any help, ideas, advice will be greatly appreciated. > -- > https://mail.python.org/mailman/listinfo/python-list The easiest solution is probably a non-Python tool like wget. Search the web for "link checker" or "href verifier" or words to that effect, see what you find. This is an extremely common task, and I don't think you need to write any code for it. ChrisA From elisha.java at gmail.com Sun Sep 22 23:58:30 2013 From: elisha.java at gmail.com (elisha.java at gmail.com) Date: Sun, 22 Sep 2013 20:58:30 -0700 (PDT) Subject: Python Interview Questions In-Reply-To: References: <1193768041.349129.26350@v3g2000hsg.googlegroups.com> Message-ID: On Tuesday, October 30, 2007 12:24:04 PM UTC-7, Tim Chase wrote: > > I have used Python for a couple of projects last year and > > I found it extremely useful. I could write two middle size > > projects in 2-3 months (part time). Right now I am a bit > > rusty and trying to catch up again with Python. > > > > I am now appearing for Job Interviews these days and I am > > wondering if anybody of you appeared for a Python > > Interview. Can you please share the questions you were > > asked. That will be great help to me. > > While I haven't interviewed precisely for Python, I've been > on the other (interviewing) end and can offer a few of the > sorts of things I ask. I don't expect perfect answers to > all of them, but they show me a range of what the > interviewee knows. I try and give a scattershot of > questions from the following areas to try and narrow down > where they fall in terms of pythonability, and then grill > more deeply around the edges that I find. > > Basic Python: > ============= > - do they know a tuple/list/dict when they see it? > > - when to use list vs. tuple vs. dict. vs. set > > - can they use list comprehensions (and know when not to > abuse them? :) > > - can they use tuple unpacking for assignment? > > - string building...do they use "+=" or do they build a list > and use .join() to recombine them efficiently > > - truth-value testing questions and observations (do they > write "if x == True" or do they just write "if x") > > - basic file-processing (iterating over a file's lines) > > - basic understanding of exception handling > > Broader Basic Python: > ===================== > - questions about the standard library ("do you know if > there's a standard library for doing X?", or "in which > library would you find [common functionality Y]?") Most > of these are related to the more common libraries such as > os/os.path/sys/re/itertools > > - questions about iterators/generators > > - questions about map/reduce/sum/etc family of functions > > - questions about "special" methods (____) > > More Advanced Python: > ===================== > - can they manipulate functions as first-class objects > (Python makes it easy, but do they know how) > > - more detailed questions about the std. libraries (such as > datetime/email/csv/zipfile/networking/optparse/unittest) > > - questions about testing (unittests/doctests) > > - questions about docstrings vs. comments, and the "Why" of > them > > - more detailed questions about regular expressions > > - questions about mutability > > - keyword/list parameters and unpacked kwd args > > - questions about popular 3rd-party toolkits (BeautifulSoup, > pyparsing...mostly if they know about them and when to use > them, not so much about implementation details) > > - questions about monkey-patching > > - questions about PDB > > - questions about properties vs. getters/setters > > - questions about classmethods > > - questions about scope/name-resolution > > - use of lambda > > Python History: > =============== > - decorators added in which version? > > - "batteries included" SQL-capible DB in which version? > > - the difference between "class Foo" and "class Foo(object)" > > - questions from "import this" about pythonic code > > Python Resources: > ================= > - what do they know about various Python web frameworks > (knowing a few names is usually good enough, though > knowledge about the frameworks is a nice plus) such as > Django, TurboGears, Zope, etc. > > - what do they know about various Python GUI frameworks and > the pros/cons of them (tkinter, wx, pykde, etc) > > - where do they go with Python related questions (c.l.p, > google, google-groups, etc) > > Other Process-releated things: > ============================== > - do they use revision control > (RCS/CVS/Subversion/Mercurial/Git...anything but VSS) and > know how to use it well > > - do they write automated tests for their code > > Touchy-feely things: > ==================== > - tabs vs. spaces, and their reasoning > > - reason for choosing Python > > - choice of editor/IDE > > Good luck with your interviewing and hope this helped, > > -tkc I appreciate all these. I thought I knew Python! From roy at panix.com Mon Sep 23 09:06:45 2013 From: roy at panix.com (Roy Smith) Date: Mon, 23 Sep 2013 09:06:45 -0400 Subject: Python Interview Questions References: <1193768041.349129.26350@v3g2000hsg.googlegroups.com> Message-ID: Somebody, whose identity has been lost in three-deep quoting, said: > > > I am now appearing for Job Interviews these days and I am > > > wondering if anybody of you appeared for a Python > > > Interview. Can you please share the questions you were > > > asked. That will be great help to me. We have a standard list of about 2 dozen screening questions we use that cover a broad but shallow swath of CS, Unix, and Python. I'm not going to share the exact questions, but here's some of the Python topics we cover: The ramifications of string immutability. How default function arguments work, especially how they interact with mutable objects. How booleans and various ways of testing for equality work. A question about subclassing a built-in type. List comprehensions vs. generator expressions. We don't expect everybody to get every question, but it gives us a quick first cut to evaluate applicants before we decide to bring them in for an interview or not. We also want to see that you understand some basic computer science. If nothing else, you need to understand, what O(n) means, and be able to give some examples of Python code which exhibit various orders of complexity. From wjw15129 at gmail.com Mon Sep 23 04:12:21 2013 From: wjw15129 at gmail.com (YetToCome) Date: Mon, 23 Sep 2013 01:12:21 -0700 (PDT) Subject: How To Build Scrapy Environment Message-ID: <1dad0f6e-0241-4892-ad32-afb2097f09a3@googlegroups.com> I have already install Twisted, zope.interface, w3lib, libxml2, etc,but it still can not be built,here is the error message: Traceback (most recent call last): File "C:\Python27\lib\runpy.py", line 162, in _run_module_as_main "__main__", fname, loader, pkg_name) File "C:\Python27\lib\runpy.py", line 72, in _run_code exec code in run_globals File "C:\Python27\lib\site-packages\scrapy\cmdline.py", line 167, in execute() File "C:\Python27\lib\site-packages\scrapy\cmdline.py", line 142, in execute _run_print_help(parser, _run_command, cmd, args, opts) File "C:\Python27\lib\site-packages\scrapy\cmdline.py", line 88, in _run_print _help func(*a, **kw) File "C:\Python27\lib\site-packages\scrapy\cmdline.py", line 149, in _run_comm and cmd.run(args, opts) File "C:\Python27\lib\site-packages\scrapy\commands\crawl.py", line 47, in run crawler = self.crawler_process.create_crawler() File "C:\Python27\lib\site-packages\scrapy\crawler.py", line 142, in create_cr awler self.crawlers[name] = Crawler(self.settings) File "C:\Python27\lib\site-packages\scrapy\crawler.py", line 23, in __init__ self.spiders = spman_cls.from_crawler(self) File "C:\Python27\lib\site-packages\scrapy\spidermanager.py", line 35, in from _crawler sm = cls.from_settings(crawler.settings) File "C:\Python27\lib\site-packages\scrapy\spidermanager.py", line 31, in from _settings return cls(settings.getlist('SPIDER_MODULES')) File "C:\Python27\lib\site-packages\scrapy\spidermanager.py", line 22, in __in it__ for module in walk_modules(name): File "C:\Python27\lib\site-packages\scrapy\utils\misc.py", line 66, in walk_mo dules submod = __import__(fullpath, {}, {}, ['']) File "blog_crawl\spiders\dmoz_spider.py", line 1, in class DmozSpider(BaseSpider): NameError: name 'BaseSpider' is not defined someone tells me why, pls From __peter__ at web.de Mon Sep 23 04:37:22 2013 From: __peter__ at web.de (Peter Otten) Date: Mon, 23 Sep 2013 10:37:22 +0200 Subject: How To Build Scrapy Environment References: <1dad0f6e-0241-4892-ad32-afb2097f09a3@googlegroups.com> Message-ID: YetToCome wrote: > I have already install Twisted, zope.interface, w3lib, libxml2, etc,but it > still can not be built,here is the error message: > > Traceback (most recent call last): > File "C:\Python27\lib\runpy.py", line 162, in _run_module_as_main > "__main__", fname, loader, pkg_name) > File "C:\Python27\lib\runpy.py", line 72, in _run_code > exec code in run_globals > File "C:\Python27\lib\site-packages\scrapy\cmdline.py", line 167, in > > execute() > File "C:\Python27\lib\site-packages\scrapy\cmdline.py", line 142, in > execute > _run_print_help(parser, _run_command, cmd, args, opts) > File "C:\Python27\lib\site-packages\scrapy\cmdline.py", line 88, in > _run_print > _help > func(*a, **kw) > File "C:\Python27\lib\site-packages\scrapy\cmdline.py", line 149, in > _run_comm > and > cmd.run(args, opts) > File "C:\Python27\lib\site-packages\scrapy\commands\crawl.py", line 47, > in run > crawler = self.crawler_process.create_crawler() > File "C:\Python27\lib\site-packages\scrapy\crawler.py", line 142, in > create_cr > awler > self.crawlers[name] = Crawler(self.settings) > File "C:\Python27\lib\site-packages\scrapy\crawler.py", line 23, in > __init__ > self.spiders = spman_cls.from_crawler(self) > File "C:\Python27\lib\site-packages\scrapy\spidermanager.py", line 35, > in from > _crawler > sm = cls.from_settings(crawler.settings) > File "C:\Python27\lib\site-packages\scrapy\spidermanager.py", line 31, > in from > _settings > return cls(settings.getlist('SPIDER_MODULES')) > File "C:\Python27\lib\site-packages\scrapy\spidermanager.py", line 22, > in __in > it__ > for module in walk_modules(name): > File "C:\Python27\lib\site-packages\scrapy\utils\misc.py", line 66, in > walk_mo > dules > submod = __import__(fullpath, {}, {}, ['']) > File "blog_crawl\spiders\dmoz_spider.py", line 1, in > class DmozSpider(BaseSpider): > NameError: name 'BaseSpider' is not defined > > someone tells me why, pls Assuming you are working your way through the tutorial at http://doc.scrapy.org/en/latest/intro/tutorial.html#our-first-spider you probably forgot to import the BaseSpider class with from scrapy.spider import BaseSpider as shown in the code snippet in the "Our first Spider" section of the tutorial. From wjw15129 at gmail.com Mon Sep 23 04:55:28 2013 From: wjw15129 at gmail.com (YetToCome) Date: Mon, 23 Sep 2013 01:55:28 -0700 (PDT) Subject: How To Build Scrapy Environment In-Reply-To: <1dad0f6e-0241-4892-ad32-afb2097f09a3@googlegroups.com> References: <1dad0f6e-0241-4892-ad32-afb2097f09a3@googlegroups.com> Message-ID: ? 2013?9?23????UTC+8??4?12?21??YetToCome??? > I have already install Twisted, zope.interface, w3lib, libxml2, etc,but it still can not be built,here is the error message: > > > > Traceback (most recent call last): > > File "C:\Python27\lib\runpy.py", line 162, in _run_module_as_main > > "__main__", fname, loader, pkg_name) > > File "C:\Python27\lib\runpy.py", line 72, in _run_code > > exec code in run_globals > > File "C:\Python27\lib\site-packages\scrapy\cmdline.py", line 167, in > > execute() > > File "C:\Python27\lib\site-packages\scrapy\cmdline.py", line 142, in execute > > _run_print_help(parser, _run_command, cmd, args, opts) > > File "C:\Python27\lib\site-packages\scrapy\cmdline.py", line 88, in _run_print > > _help > > func(*a, **kw) > > File "C:\Python27\lib\site-packages\scrapy\cmdline.py", line 149, in _run_comm > > and > > cmd.run(args, opts) > > File "C:\Python27\lib\site-packages\scrapy\commands\crawl.py", line 47, in run > > crawler = self.crawler_process.create_crawler() > > File "C:\Python27\lib\site-packages\scrapy\crawler.py", line 142, in create_cr > > awler > > self.crawlers[name] = Crawler(self.settings) > > File "C:\Python27\lib\site-packages\scrapy\crawler.py", line 23, in __init__ > > self.spiders = spman_cls.from_crawler(self) > > File "C:\Python27\lib\site-packages\scrapy\spidermanager.py", line 35, in from > > _crawler > > sm = cls.from_settings(crawler.settings) > > File "C:\Python27\lib\site-packages\scrapy\spidermanager.py", line 31, in from > > _settings > > return cls(settings.getlist('SPIDER_MODULES')) > > File "C:\Python27\lib\site-packages\scrapy\spidermanager.py", line 22, in __in > > it__ > > for module in walk_modules(name): > > File "C:\Python27\lib\site-packages\scrapy\utils\misc.py", line 66, in walk_mo > > dules > > submod = __import__(fullpath, {}, {}, ['']) > > File "blog_crawl\spiders\dmoz_spider.py", line 1, in > > class DmozSpider(BaseSpider): > > NameError: name 'BaseSpider' is not defined > > > > someone tells me why, pls ? 2013?9?23????UTC+8??4?12?21??YetToCome??? > I have already install Twisted, zope.interface, w3lib, libxml2, etc,but it still can not be built,here is the error message: > > > > Traceback (most recent call last): > > File "C:\Python27\lib\runpy.py", line 162, in _run_module_as_main > > "__main__", fname, loader, pkg_name) > > File "C:\Python27\lib\runpy.py", line 72, in _run_code > > exec code in run_globals > > File "C:\Python27\lib\site-packages\scrapy\cmdline.py", line 167, in > > execute() > > File "C:\Python27\lib\site-packages\scrapy\cmdline.py", line 142, in execute > > _run_print_help(parser, _run_command, cmd, args, opts) > > File "C:\Python27\lib\site-packages\scrapy\cmdline.py", line 88, in _run_print > > _help > > func(*a, **kw) > > File "C:\Python27\lib\site-packages\scrapy\cmdline.py", line 149, in _run_comm > > and > > cmd.run(args, opts) > > File "C:\Python27\lib\site-packages\scrapy\commands\crawl.py", line 47, in run > > crawler = self.crawler_process.create_crawler() > > File "C:\Python27\lib\site-packages\scrapy\crawler.py", line 142, in create_cr > > awler > > self.crawlers[name] = Crawler(self.settings) > > File "C:\Python27\lib\site-packages\scrapy\crawler.py", line 23, in __init__ > > self.spiders = spman_cls.from_crawler(self) > > File "C:\Python27\lib\site-packages\scrapy\spidermanager.py", line 35, in from > > _crawler > > sm = cls.from_settings(crawler.settings) > > File "C:\Python27\lib\site-packages\scrapy\spidermanager.py", line 31, in from > > _settings > > return cls(settings.getlist('SPIDER_MODULES')) > > File "C:\Python27\lib\site-packages\scrapy\spidermanager.py", line 22, in __in > > it__ > > for module in walk_modules(name): > > File "C:\Python27\lib\site-packages\scrapy\utils\misc.py", line 66, in walk_mo > > dules > > submod = __import__(fullpath, {}, {}, ['']) > > File "blog_crawl\spiders\dmoz_spider.py", line 1, in > > class DmozSpider(BaseSpider): > > NameError: name 'BaseSpider' is not defined > > > > someone tells me why, pls it had an another error: No module named queuelib, but i have installed all the libs mentioned in that passage... 2013-09-23 16:44:17+0800 [scrapy] INFO: Scrapy 0.18.2 started (bot: tutorial) 2013-09-23 16:44:17+0800 [scrapy] DEBUG: Optional features available: ssl, http1 1, libxml2 2013-09-23 16:44:17+0800 [scrapy] DEBUG: Overridden settings: {'NEWSPIDER_MODULE ': 'tutorial.spiders', 'SPIDER_MODULES': ['tutorial.spiders'], 'BOT_NAME': 'tuto rial'} 2013-09-23 16:44:17+0800 [scrapy] DEBUG: Enabled extensions: LogStats, TelnetCon sole, CloseSpider, WebService, CoreStats, SpiderState Traceback (most recent call last): File "C:\Python27\lib\runpy.py", line 162, in _run_module_as_main "__main__", fname, loader, pkg_name) File "C:\Python27\lib\runpy.py", line 72, in _run_code exec code in run_globals File "C:\Python27\lib\site-packages\scrapy\cmdline.py", line 167, in execute() File "C:\Python27\lib\site-packages\scrapy\cmdline.py", line 142, in execute _run_print_help(parser, _run_command, cmd, args, opts) File "C:\Python27\lib\site-packages\scrapy\cmdline.py", line 88, in _run_print _help func(*a, **kw) File "C:\Python27\lib\site-packages\scrapy\cmdline.py", line 149, in _run_comm and cmd.run(args, opts) File "C:\Python27\lib\site-packages\scrapy\commands\crawl.py", line 50, in run self.crawler_process.start() File "C:\Python27\lib\site-packages\scrapy\crawler.py", line 93, in start if self.start_crawling(): File "C:\Python27\lib\site-packages\scrapy\crawler.py", line 168, in start_cra wling return self.start_crawler() is not None File "C:\Python27\lib\site-packages\scrapy\crawler.py", line 151, in start_cra wler crawler.configure() File "C:\Python27\lib\site-packages\scrapy\crawler.py", line 45, in configure self.engine = ExecutionEngine(self, self._spider_closed) File "C:\Python27\lib\site-packages\scrapy\core\engine.py", line 61, in __init __ self.scheduler_cls = load_object(self.settings['SCHEDULER']) File "C:\Python27\lib\site-packages\scrapy\utils\misc.py", line 40, in load_ob ject raise ImportError, "Error loading object '%s': %s" % (path, e) ImportError: Error loading object 'scrapy.core.scheduler.Scheduler': No module n amed queuelib From wjw15129 at gmail.com Mon Sep 23 04:56:27 2013 From: wjw15129 at gmail.com (YetToCome) Date: Mon, 23 Sep 2013 01:56:27 -0700 (PDT) Subject: How To Build Scrapy Environment In-Reply-To: References: <1dad0f6e-0241-4892-ad32-afb2097f09a3@googlegroups.com> Message-ID: ? 2013?9?23????UTC+8??4?37?22??Peter Otten??? > YetToCome wrote: > > > > > I have already install Twisted, zope.interface, w3lib, libxml2, etc,but it > > > still can not be built,here is the error message: > > > > > > Traceback (most recent call last): > > > File "C:\Python27\lib\runpy.py", line 162, in _run_module_as_main > > > "__main__", fname, loader, pkg_name) > > > File "C:\Python27\lib\runpy.py", line 72, in _run_code > > > exec code in run_globals > > > File "C:\Python27\lib\site-packages\scrapy\cmdline.py", line 167, in > > > > > > execute() > > > File "C:\Python27\lib\site-packages\scrapy\cmdline.py", line 142, in > > > execute > > > _run_print_help(parser, _run_command, cmd, args, opts) > > > File "C:\Python27\lib\site-packages\scrapy\cmdline.py", line 88, in > > > _run_print > > > _help > > > func(*a, **kw) > > > File "C:\Python27\lib\site-packages\scrapy\cmdline.py", line 149, in > > > _run_comm > > > and > > > cmd.run(args, opts) > > > File "C:\Python27\lib\site-packages\scrapy\commands\crawl.py", line 47, > > > in run > > > crawler = self.crawler_process.create_crawler() > > > File "C:\Python27\lib\site-packages\scrapy\crawler.py", line 142, in > > > create_cr > > > awler > > > self.crawlers[name] = Crawler(self.settings) > > > File "C:\Python27\lib\site-packages\scrapy\crawler.py", line 23, in > > > __init__ > > > self.spiders = spman_cls.from_crawler(self) > > > File "C:\Python27\lib\site-packages\scrapy\spidermanager.py", line 35, > > > in from > > > _crawler > > > sm = cls.from_settings(crawler.settings) > > > File "C:\Python27\lib\site-packages\scrapy\spidermanager.py", line 31, > > > in from > > > _settings > > > return cls(settings.getlist('SPIDER_MODULES')) > > > File "C:\Python27\lib\site-packages\scrapy\spidermanager.py", line 22, > > > in __in > > > it__ > > > for module in walk_modules(name): > > > File "C:\Python27\lib\site-packages\scrapy\utils\misc.py", line 66, in > > > walk_mo > > > dules > > > submod = __import__(fullpath, {}, {}, ['']) > > > File "blog_crawl\spiders\dmoz_spider.py", line 1, in > > > class DmozSpider(BaseSpider): > > > NameError: name 'BaseSpider' is not defined > > > > > > someone tells me why, pls > > > > Assuming you are working your way through the tutorial at > > > > http://doc.scrapy.org/en/latest/intro/tutorial.html#our-first-spider > > > > you probably forgot to import the BaseSpider class with > > > > from scrapy.spider import BaseSpider > > > > as shown in the code snippet in the "Our first Spider" section of the > > tutorial. it had an another error: No module named queuelib, but i have installed all the libs mentioned in that passage... 2013-09-23 16:44:17+0800 [scrapy] INFO: Scrapy 0.18.2 started (bot: tutorial) 2013-09-23 16:44:17+0800 [scrapy] DEBUG: Optional features available: ssl, http1 1, libxml2 2013-09-23 16:44:17+0800 [scrapy] DEBUG: Overridden settings: {'NEWSPIDER_MODULE ': 'tutorial.spiders', 'SPIDER_MODULES': ['tutorial.spiders'], 'BOT_NAME': 'tuto rial'} 2013-09-23 16:44:17+0800 [scrapy] DEBUG: Enabled extensions: LogStats, TelnetCon sole, CloseSpider, WebService, CoreStats, SpiderState Traceback (most recent call last): File "C:\Python27\lib\runpy.py", line 162, in _run_module_as_main "__main__", fname, loader, pkg_name) File "C:\Python27\lib\runpy.py", line 72, in _run_code exec code in run_globals File "C:\Python27\lib\site-packages\scrapy\cmdline.py", line 167, in execute() File "C:\Python27\lib\site-packages\scrapy\cmdline.py", line 142, in execute _run_print_help(parser, _run_command, cmd, args, opts) File "C:\Python27\lib\site-packages\scrapy\cmdline.py", line 88, in _run_print _help func(*a, **kw) File "C:\Python27\lib\site-packages\scrapy\cmdline.py", line 149, in _run_comm and cmd.run(args, opts) File "C:\Python27\lib\site-packages\scrapy\commands\crawl.py", line 50, in run self.crawler_process.start() File "C:\Python27\lib\site-packages\scrapy\crawler.py", line 93, in start if self.start_crawling(): File "C:\Python27\lib\site-packages\scrapy\crawler.py", line 168, in start_cra wling return self.start_crawler() is not None File "C:\Python27\lib\site-packages\scrapy\crawler.py", line 151, in start_cra wler crawler.configure() File "C:\Python27\lib\site-packages\scrapy\crawler.py", line 45, in configure self.engine = ExecutionEngine(self, self._spider_closed) File "C:\Python27\lib\site-packages\scrapy\core\engine.py", line 61, in __init __ self.scheduler_cls = load_object(self.settings['SCHEDULER']) File "C:\Python27\lib\site-packages\scrapy\utils\misc.py", line 40, in load_ob ject raise ImportError, "Error loading object '%s': %s" % (path, e) ImportError: Error loading object 'scrapy.core.scheduler.Scheduler': No module n amed queuelib From __peter__ at web.de Mon Sep 23 05:25:25 2013 From: __peter__ at web.de (Peter Otten) Date: Mon, 23 Sep 2013 11:25:25 +0200 Subject: How To Build Scrapy Environment References: <1dad0f6e-0241-4892-ad32-afb2097f09a3@googlegroups.com> Message-ID: YetToCome wrote: [snip] No need to quote the whole turd -- just confirm that it worked... > it had an another error: No module named queuelib, but i have installed > all the libs mentioned in that passage... > ImportError: Error loading object 'scrapy.core.scheduler.Scheduler': No > module n amed queuelib Googling "queuelib site:scrapy.org" leads to http://doc.scrapy.org/en/latest/news.html containing """ 0.18.0 (released 2013-08-09)? [...] Moved persistent (on disk) queues to a separate project (queuelib) which scrapy now depends on """ which in turn leads to https://github.com/scrapy/queuelib From wjw15129 at gmail.com Mon Sep 23 06:11:04 2013 From: wjw15129 at gmail.com (YetToCome) Date: Mon, 23 Sep 2013 03:11:04 -0700 (PDT) Subject: How To Build Scrapy Environment In-Reply-To: References: <1dad0f6e-0241-4892-ad32-afb2097f09a3@googlegroups.com> Message-ID: <82583230-c40d-4916-9c7b-060f09a49906@googlegroups.com> ? 2013?9?23????UTC+8??5?25?25??Peter Otten??? > YetToCome wrote: > > > > [snip] > > > > No need to quote the whole turd -- just confirm that it worked... > > > > > it had an another error: No module named queuelib, but i have installed > > > all the libs mentioned in that passage... > > > > > ImportError: Error loading object 'scrapy.core.scheduler.Scheduler': No > > > module n amed queuelib > > > > Googling "queuelib site:scrapy.org" leads to > > > > http://doc.scrapy.org/en/latest/news.html > > > > containing > > > > """ > > 0.18.0 (released 2013-08-09)? > > [...] > > Moved persistent (on disk) queues to a separate project (queuelib) which > > scrapy now depends on > > """ > > > > which in turn leads to > > > > https://github.com/scrapy/queuelib it works, and i also add some mudules, thank you very much!!! From mmanns at gmx.net Sat Sep 21 14:18:42 2013 From: mmanns at gmx.net (Martin Manns) Date: Sat, 21 Sep 2013 20:18:42 +0200 Subject: [ANN] pyspread 0.2.5 Message-ID: ============== pyspread 0.2.5 ============== Pyspread 0.2.5 is released. This is mainly a bug fix release with some improvements in chart creation and CSV import. About pyspread ============== Pyspread is a non-traditional spreadsheet application that is based on and written in the programming language Python. The goal of pyspread is to be the most pythonic spreadsheet application. Pyspread is free software. It is released under the GPL v3. Project website: http://manns.github.com/pyspread/ What is new in 0.2.5 ==================== + Brazilian Portuguese localization added + Pyspread now displays dates with matplotlib 1.3.0 + CSV import now allows different file encodings + All unit tests now succeed in Windows + Chart grid lines are now separately selectable for each axis + Chart annotation texts are now treated as code instead of strings + Tooltip text for pie chart colors is extended + Chart padding fixed + Default font size for renderer is now set explicitly if 0 (OS X fix) + String representation method of S removed Known issues ============ + Selection mode is disabled in Windows. + Paste As... does not work if dates are present in the data structure. + Sometimes, pressing redo when there is nothing left to redo has undesired effects such as redoing an operation again. Enjoy Martin From andypu at zoho.com Mon Sep 23 08:53:41 2013 From: andypu at zoho.com (andypu at zoho.com) Date: Mon, 23 Sep 2013 05:53:41 -0700 (PDT) Subject: parse list recurisively Message-ID: <9b5d915b-3750-43ab-9691-1b1445332c43@googlegroups.com> Hello, i use a load of lists and often i dont know how deep it is, how can i parse that lists elegantly (without a bunch of for loops) From rosuav at gmail.com Mon Sep 23 09:00:06 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 23 Sep 2013 23:00:06 +1000 Subject: parse list recurisively In-Reply-To: <9b5d915b-3750-43ab-9691-1b1445332c43@googlegroups.com> References: <9b5d915b-3750-43ab-9691-1b1445332c43@googlegroups.com> Message-ID: On Mon, Sep 23, 2013 at 10:53 PM, wrote: > Hello, > > i use a load of lists and often i dont know how deep it is, how can i parse that lists elegantly (without a bunch of for loops) You can write a function that calls itself - that's what "recursive" usually means in programming. Start with the tutorial on functions, or just search the web for 'python recursive function'. Once you have a bit of code down, you'll be able to ask a more specific question. Have fun! ChrisA From andypu at zoho.com Mon Sep 23 10:07:04 2013 From: andypu at zoho.com (andypu at zoho.com) Date: Mon, 23 Sep 2013 07:07:04 -0700 (PDT) Subject: parse list recurisively In-Reply-To: References: <9b5d915b-3750-43ab-9691-1b1445332c43@googlegroups.com> Message-ID: <9f139899-334b-4885-bc5b-09860f511f82@googlegroups.com> thanks i was not able to figure it out some days before but now i think i can do it myself: a nice function that searches a string in a list. def parsesb(lis, string): print lis for num, nam in enumerate (lis): print num, nam if type(nam) == list: parsesb(lis[num],string) if type(nam) == str: # do something if nam == string: print 'hit!!!' From andypu at zoho.com Mon Sep 23 10:23:08 2013 From: andypu at zoho.com (andypu at zoho.com) Date: Mon, 23 Sep 2013 07:23:08 -0700 (PDT) Subject: parse list recurisively In-Reply-To: <9f139899-334b-4885-bc5b-09860f511f82@googlegroups.com> References: <9b5d915b-3750-43ab-9691-1b1445332c43@googlegroups.com> <9f139899-334b-4885-bc5b-09860f511f82@googlegroups.com> Message-ID: <0629f7b7-4416-4225-bf7b-9d53b02e9e8d@googlegroups.com> i have a list and i want to search for a certain string and replace it. i think i got it now... sbxe1 = list([['type','ter',[[[['lala']]]]],'name']) def parsesb(lis, string, replacement): for num, nam in enumerate (lis): if type(nam) == list: parsesb(lis[num],string,replacement) if type(nam) == str: # do something if nam == string: lis[num] = replacement parsesb(sbxe1 ,'name', 'booooogyman') print sbxe1 From oscar.j.benjamin at gmail.com Mon Sep 23 10:10:29 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 23 Sep 2013 15:10:29 +0100 Subject: parse list recurisively In-Reply-To: <9b5d915b-3750-43ab-9691-1b1445332c43@googlegroups.com> References: <9b5d915b-3750-43ab-9691-1b1445332c43@googlegroups.com> Message-ID: On 23 September 2013 13:53, wrote: > Hello, > > i use a load of lists and often i dont know how deep it is, how can i parse that lists elegantly (without a bunch of for loops) I don't really understand what you mean. Can you show some code that illustrates what you're doing? http://sscce.org/ Oscar From kjakupak at gmail.com Mon Sep 23 08:57:34 2013 From: kjakupak at gmail.com (kjakupak at gmail.com) Date: Mon, 23 Sep 2013 05:57:34 -0700 (PDT) Subject: Help with python functions? Message-ID: 1.a. Write a function temp(T, from_unit, to_unit) where from_unit and to_unit are temperature units, either 'F' (or 'f') for fahrenheit, or 'C' (or 'c') for celsius, or 'K' (or 'k') for kelvin; and T is a temperature number for the unit from_unit. The function should return the temperature number in the unit to to_unit; no unit is returned. [input(...) and print(...) are not allowed] 1.b. Write a function comp(T1, u1, T2, u2) where u1, u2 are temperature units as in 1.a., and T1, T2 are temperature numbers for these units. The function should return -1 if T1 in u1 is a lower temperature than T2 in u2; it should return 0 is the two express equal temperatures; and it should return 1 otherwise. 2. Write a function P(p_0, t, i) where t is a time in years *integer), is is a yearly interest (as a traditional percentage), and p_0 is the initial principal (at time 0). The function should return the principal at time t. Principals and interests are float numbers. Can anyone help me with any of these please? Much appreciated. I honestly don't even know how to start them From roy at panix.com Mon Sep 23 09:11:25 2013 From: roy at panix.com (Roy Smith) Date: Mon, 23 Sep 2013 09:11:25 -0400 Subject: Help with python functions? References: Message-ID: In article , kjakupak at gmail.com wrote: > 1.a. Write a function temp(T, from_unit, to_unit) where from_unit and to_unit > are temperature units, either 'F' (or 'f') for fahrenheit, or 'C' (or 'c') > for celsius, or 'K' (or 'k') for kelvin; and T is a temperature number for > the unit from_unit. The function should return the temperature number in the > unit to to_unit; no unit is returned. [input(...) and print(...) are not > allowed] We don't do people's homework for them. But, I'll give you a hint. Forget about doing this in python. Write down the steps you would take to do this problem with pencil and paper. That really is how you begin any programming problem; understanding the algorithm you need to execute. The rest is, as Mozart said, just scribbling. From steve+comp.lang.python at pearwood.info Mon Sep 23 09:56:45 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Sep 2013 13:56:45 GMT Subject: Help with python functions? References: Message-ID: <5240489d$0$29992$c3e8da3$5496439d@news.astraweb.com> On Mon, 23 Sep 2013 05:57:34 -0700, kjakupak wrote: > Can anyone help me with any of these please? Much appreciated. I > honestly don't even know how to start them Start by writing a function that does nothing: def nothing(): pass Now change it so that it takes three arguments: T, a temperature from_unit, the temperature scale to convert from to_unit, the temperature scale to convert to def nothing(T, from_unit, to_unit): pass Now change the name of the function to match the name you were told to use: def temp(T, from_unit, to_unit): pass Now you're a third of the way done! All you need do now is write the logic of the function, and make sure it works. What's the logic of the function? There are four cases: (1) If from_unit is "C", and to_unit is "F", you need to convert T from Celsius to Fahrenheit. I'm sure you can find the formula for that if you google it. (2) otherwise, if from_unit is "F", and to_unit is "C", you need to convert T from Fahrenheit to Celsius. Again, the formula to use is readily available in about a million reference books and web sites. (3) otherwise, if from_unit and to_unit are the same (both "C", or both "F"). In this case, there is no conversion needed and you can just return T unchanged. (4) otherwise, one or both of from_unit or to_unit must be something other than "C" or "F", e.g. "Z" or "Hello". In that case, you have to deal with the error. Have you learned about exceptions yet? It may be acceptable to ignore case #4 -- you'll have to ask your teacher. Then try it out and make sure it works! For example: 107.6?F == 42?C -15?C = 5?F Now you're done! On to the next function... -- Steven From kjakupak at gmail.com Mon Sep 23 18:32:37 2013 From: kjakupak at gmail.com (kjakupak at gmail.com) Date: Mon, 23 Sep 2013 15:32:37 -0700 (PDT) Subject: Help with python functions? In-Reply-To: <5240489d$0$29992$c3e8da3$5496439d@news.astraweb.com> References: <5240489d$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: <66aa7d75-a819-4b21-9f1e-7ad265996150@googlegroups.com> On Monday, September 23, 2013 9:56:45 AM UTC-4, Steven D'Aprano wrote: > On Mon, 23 Sep 2013 05:57:34 -0700, kjakupak wrote: > > Now you're done! On to the next function... > > > > -- > > Steven def temp(T, from_unit, to_unit): conversion_table = {('c', 'k'):lambda x: x + 273.15, ('c', 'f'):lambda x: (x * (9.0/5)) + 32, ('k', 'c'):lambda x: x - 273.15, ('k', 'f'):lambda x: (x * (9.0/5)) - 459.67, ('f', 'c'):lambda x: (x - 32) * (5.0/9), ('f', 'k'):lambda x: (x + 459.67) * (5.0/9)} f = conversion_table[(from_unit.lower(), to_unit.lower())] return f(T) Would this be correct? From tjreedy at udel.edu Mon Sep 23 18:48:20 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 23 Sep 2013 18:48:20 -0400 Subject: Help with python functions? In-Reply-To: <66aa7d75-a819-4b21-9f1e-7ad265996150@googlegroups.com> References: <5240489d$0$29992$c3e8da3$5496439d@news.astraweb.com> <66aa7d75-a819-4b21-9f1e-7ad265996150@googlegroups.com> Message-ID: On 9/23/2013 6:32 PM, kjakupak at gmail.com wrote: > On Monday, September 23, 2013 9:56:45 AM UTC-4, Steven D'Aprano wrote: >> On Mon, 23 Sep 2013 05:57:34 -0700, kjakupak wrote: >> >> Now you're done! On to the next function... >> >> >> >> -- >> >> Steven > > def temp(T, from_unit, to_unit): > conversion_table = {('c', 'k'):lambda x: x + 273.15, > ('c', 'f'):lambda x: (x * (9.0/5)) + 32, > ('k', 'c'):lambda x: x - 273.15, > ('k', 'f'):lambda x: (x * (9.0/5)) - 459.67, > ('f', 'c'):lambda x: (x - 32) * (5.0/9), > ('f', 'k'):lambda x: (x + 459.67) * (5.0/9)} > f = conversion_table[(from_unit.lower(), to_unit.lower())] > return f(T) What happens if you run some tests? If you use unittest, you can use the assertAlmostEqualMethod, or just write something similar yourself. Be careful with values near 0.. At minimum, how many tests do you need, 6 or 9? -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Mon Sep 23 23:08:21 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 24 Sep 2013 03:08:21 GMT Subject: Help with python functions? References: <5240489d$0$29992$c3e8da3$5496439d@news.astraweb.com> <66aa7d75-a819-4b21-9f1e-7ad265996150@googlegroups.com> Message-ID: <52410225$0$29992$c3e8da3$5496439d@news.astraweb.com> On Mon, 23 Sep 2013 15:32:37 -0700, kjakupak wrote: > On Monday, September 23, 2013 9:56:45 AM UTC-4, Steven D'Aprano wrote: >> On Mon, 23 Sep 2013 05:57:34 -0700, kjakupak wrote: >> >> Now you're done! On to the next function... >> >> >> >> -- >> >> Steven > > def temp(T, from_unit, to_unit): > conversion_table = {('c', 'k'):lambda x: x + 273.15, > ('c', 'f'):lambda x: (x * (9.0/5)) + 32, > ('k', 'c'):lambda x: x - 273.15, > ('k', 'f'):lambda x: (x * (9.0/5)) - 459.67, > ('f', 'c'):lambda x: (x - 32) * (5.0/9), > ('f', 'k'):lambda x: (x + 459.67) * (5.0/9)} > f = conversion_table[(from_unit.lower(), to_unit.lower())] > return f(T) Well, I'm impressed! From "I honestly don't even know how to start them" to a dispatch table containing first class functions made with lambda in under 9 hours. Well done! I expected you to start with a big block of if...elif statements, but a dispatch table is a much nicer solution. > Would this be correct? You tell us :-) Does it work? Are you confident that the conversion equations are correct? If you try converting various temperatures, do you get the right results? -- Steven From steve+comp.lang.python at pearwood.info Mon Sep 23 23:17:46 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 24 Sep 2013 03:17:46 GMT Subject: Help with python functions? References: <5240489d$0$29992$c3e8da3$5496439d@news.astraweb.com> <66aa7d75-a819-4b21-9f1e-7ad265996150@googlegroups.com> Message-ID: <5241045a$0$29992$c3e8da3$5496439d@news.astraweb.com> On Mon, 23 Sep 2013 15:32:37 -0700, kjakupak wrote: > def temp(T, from_unit, to_unit): > conversion_table = {('c', 'k'):lambda x: x + 273.15, > ('c', 'f'):lambda x: (x * (9.0/5)) + 32, ('k', > 'c'):lambda x: x - 273.15, > ('k', 'f'):lambda x: (x * (9.0/5)) - 459.67, > ('f', 'c'):lambda x: (x - 32) * (5.0/9), ('f', > 'k'):lambda x: (x + 459.67) * (5.0/9)} > f = conversion_table[(from_unit.lower(), to_unit.lower())] return > f(T) > > Would this be correct? Oh, I forgot... what happens if both units are the same? Hint: if both units are the same, no conversion is necessary. -- Steven From pecore at pascolo.net Tue Sep 24 12:53:36 2013 From: pecore at pascolo.net (giacomo boffi) Date: Tue, 24 Sep 2013 18:53:36 +0200 Subject: Help with python functions? References: <5240489d$0$29992$c3e8da3$5496439d@news.astraweb.com> <66aa7d75-a819-4b21-9f1e-7ad265996150@googlegroups.com> Message-ID: <87txhap3e7.fsf@pascolo.net> kjakupak at gmail.com writes: > def temp(T, from_unit, to_unit): > conversion_table = {('c', 'k'):lambda x: x + 273.15, > ('c', 'f'):lambda x: (x * (9.0/5)) + 32, > ('k', 'c'):lambda x: x - 273.15, > ('k', 'f'):lambda x: (x * (9.0/5)) - 459.67, > ('f', 'c'):lambda x: (x - 32) * (5.0/9), > ('f', 'k'):lambda x: (x + 459.67) * (5.0/9)} > f = conversion_table[(from_unit.lower(), to_unit.lower())] > return f(T) > > Would this be correct? not always: >>> temp(-300.0, 'c', 'k') -26.850000000000023 >>> -- le mie sacrosante questioni di principio VS gli sciocchi puntigli di quel cretino del mio vicino From python at mrabarnett.plus.com Tue Sep 24 13:18:04 2013 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 24 Sep 2013 18:18:04 +0100 Subject: Help with python functions? In-Reply-To: <87txhap3e7.fsf@pascolo.net> References: <5240489d$0$29992$c3e8da3$5496439d@news.astraweb.com> <66aa7d75-a819-4b21-9f1e-7ad265996150@googlegroups.com> <87txhap3e7.fsf@pascolo.net> Message-ID: <5241C94C.9090608@mrabarnett.plus.com> On 24/09/2013 17:53, giacomo boffi wrote: > kjakupak at gmail.com writes: > >> def temp(T, from_unit, to_unit): >> conversion_table = {('c', 'k'):lambda x: x + 273.15, >> ('c', 'f'):lambda x: (x * (9.0/5)) + 32, >> ('k', 'c'):lambda x: x - 273.15, >> ('k', 'f'):lambda x: (x * (9.0/5)) - 459.67, >> ('f', 'c'):lambda x: (x - 32) * (5.0/9), >> ('f', 'k'):lambda x: (x + 459.67) * (5.0/9)} >> f = conversion_table[(from_unit.lower(), to_unit.lower())] >> return f(T) >> >> Would this be correct? > > not always: > >>>> temp(-300.0, 'c', 'k') > -26.850000000000023 >>>> > In other words, it depends what you mean by 'correct'. Zero Kelvin ("Absolute Zero") is the lowest possible temperature; in reality there's no such temperature as -300?C. From kjakupak at gmail.com Mon Sep 23 18:55:53 2013 From: kjakupak at gmail.com (kjakupak at gmail.com) Date: Mon, 23 Sep 2013 15:55:53 -0700 (PDT) Subject: Help with python functions? In-Reply-To: <5240489d$0$29992$c3e8da3$5496439d@news.astraweb.com> References: <5240489d$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3af43a58-fc56-46d1-9e1e-cb69f8aa520b@googlegroups.com> On Monday, September 23, 2013 9:56:45 AM UTC-4, Steven D'Aprano wrote: > On Mon, 23 Sep 2013 05:57:34 -0700, kjakupak wrote: > > Now you're done! On to the next function... > > > > -- > > Steven def temp(T, from_unit, to_unit): conversion_table = {('c', 'k'):lambda x: x + 273.15, ('c', 'f'):lambda x: (x * (9.0/5)) + 32, ('k', 'c'):lambda x: x - 273.15, ('k', 'f'):lambda x: (x * (9.0/5)) - 459.67, ('f', 'c'):lambda x: (x - 32) * (5.0/9), ('f', 'k'):lambda x: (x + 459.67) * (5.0/9)} f = conversion_table[(from_unit.lower(), to_unit.lower())] return f(T) Would this be correct? Also, the temperature number had to be of type float so I feel like I did this wrong... As for the next one, so far I've gotten: def comp(T1, u1, T2, u2): if u1 > u2: return -1 elif u2 > u1: return 1 else: return 0 From davea at davea.name Mon Sep 23 20:07:44 2013 From: davea at davea.name (Dave Angel) Date: Tue, 24 Sep 2013 00:07:44 +0000 (UTC) Subject: Help with python functions? References: <5240489d$0$29992$c3e8da3$5496439d@news.astraweb.com> <3af43a58-fc56-46d1-9e1e-cb69f8aa520b@googlegroups.com> Message-ID: On 23/9/2013 18:55, kjakupak at gmail.com wrote: > On Monday, September 23, 2013 9:56:45 AM UTC-4, Steven D'Aprano wrote: >> On Mon, 23 Sep 2013 05:57:34 -0700, kjakupak wrote: >> >> Now you're done! On to the next function... >> >> >> >> -- >> >> Steven > > def temp(T, from_unit, to_unit): > conversion_table = {('c', 'k'):lambda x: x + 273.15, > ('c', 'f'):lambda x: (x * (9.0/5)) + 32, > ('k', 'c'):lambda x: x - 273.15, > ('k', 'f'):lambda x: (x * (9.0/5)) - 459.67, > ('f', 'c'):lambda x: (x - 32) * (5.0/9), > ('f', 'k'):lambda x: (x + 459.67) * (5.0/9)} > f = conversion_table[(from_unit.lower(), to_unit.lower())] > return f(T) > > Would this be correct? > Also, the temperature number had to be of type float so I feel like I did this wrong... > > As for the next one, so far I've gotten: > def comp(T1, u1, T2, u2): > if u1 > u2: > return -1 > elif u2 > u1: > return 1 > else: > return 0 I didn't see any spec that said Python 3.x. in version 2.x, this would be incorrect. -- DaveA From kjakupak at gmail.com Mon Sep 23 21:23:55 2013 From: kjakupak at gmail.com (kjakupak at gmail.com) Date: Mon, 23 Sep 2013 18:23:55 -0700 (PDT) Subject: Help with python functions? In-Reply-To: References: <5240489d$0$29992$c3e8da3$5496439d@news.astraweb.com> <3af43a58-fc56-46d1-9e1e-cb69f8aa520b@googlegroups.com> Message-ID: <2c20e376-8803-40e1-acae-e1b8a2b08ebf@googlegroups.com> On Monday, September 23, 2013 8:07:44 PM UTC-4, Dave Angel wrote: > > I didn't see any spec that said Python 3.x. in version 2.x, this would > > be incorrect. > > > > -- > > DaveA It's for Python 3.2 From davea at davea.name Mon Sep 23 23:52:01 2013 From: davea at davea.name (Dave Angel) Date: Tue, 24 Sep 2013 03:52:01 +0000 (UTC) Subject: Help with python functions? References: <5240489d$0$29992$c3e8da3$5496439d@news.astraweb.com> <3af43a58-fc56-46d1-9e1e-cb69f8aa520b@googlegroups.com> <2c20e376-8803-40e1-acae-e1b8a2b08ebf@googlegroups.com> Message-ID: On 23/9/2013 21:23, kjakupak at gmail.com wrote: > On Monday, September 23, 2013 8:07:44 PM UTC-4, Dave Angel wrote: >> >> I didn't see any spec that said Python 3.x. in version 2.x, this would >> >> be incorrect. >> >> >> >> -- >> >> DaveA > > It's for Python 3.2 Then I'd have a comment saying so, right at the top. Or use that for the shebang line. -- DaveA From denismfmcmahon at gmail.com Mon Sep 23 22:12:05 2013 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Tue, 24 Sep 2013 02:12:05 +0000 (UTC) Subject: Help with python functions? References: <5240489d$0$29992$c3e8da3$5496439d@news.astraweb.com> <3af43a58-fc56-46d1-9e1e-cb69f8aa520b@googlegroups.com> Message-ID: On Mon, 23 Sep 2013 15:55:53 -0700, kjakupak wrote: > As for the next one, so far I've gotten: > def comp(T1, u1, T2, u2): > if u1 > u2: > return -1 > elif u2 > u1: > return 1 > else: > return 0 If the first function you wrote allows you to convert temps in different scales to a common scale, then in the second function, you can call the first function to convert both temps to a common scale, and compare them. Adding "same scale" conversions in the first function might help. In a same scale conversion, the input and output units are the same, and the output value is the input value. Then to compare T1 in u1 and T2 in u2, convert them both to a common scale (which might be u1 or u2 or some other scale) using your temp function, and then compare the resulting values. -- Denis McMahon, denismfmcmahon at gmail.com From kjakupak at gmail.com Mon Sep 23 22:40:47 2013 From: kjakupak at gmail.com (kjakupak at gmail.com) Date: Mon, 23 Sep 2013 19:40:47 -0700 (PDT) Subject: Help with python functions? In-Reply-To: References: <5240489d$0$29992$c3e8da3$5496439d@news.astraweb.com> <3af43a58-fc56-46d1-9e1e-cb69f8aa520b@googlegroups.com> Message-ID: <5d5e5c4d-a79c-4b1a-b9da-ee2ad766ded8@googlegroups.com> On Monday, September 23, 2013 10:12:05 PM UTC-4, Denis McMahon wrote: > > > If the first function you wrote allows you to convert temps in different > > scales to a common scale, then in the second function, you can call the > > first function to convert both temps to a common scale, and compare them. > > > > Adding "same scale" conversions in the first function might help. In a > > same scale conversion, the input and output units are the same, and the > > output value is the input value. > > > > Then to compare T1 in u1 and T2 in u2, convert them both to a common > > scale (which might be u1 or u2 or some other scale) using your temp > > function, and then compare the resulting values. > > > > -- > > Denis McMahon, denismfmcmahon at gmail.com Not sure if we've gotten that far in class, considering I don't know how to go about doing that. For the third function, I'm actually kind of stumped: def P(p_0, t, i): Amount = P(1 + (i/100)) return P(1 + (t * i/12)) From denismfmcmahon at gmail.com Tue Sep 24 10:51:31 2013 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Tue, 24 Sep 2013 14:51:31 +0000 (UTC) Subject: Help with python functions? References: <5240489d$0$29992$c3e8da3$5496439d@news.astraweb.com> <3af43a58-fc56-46d1-9e1e-cb69f8aa520b@googlegroups.com> <5d5e5c4d-a79c-4b1a-b9da-ee2ad766ded8@googlegroups.com> Message-ID: On Mon, 23 Sep 2013 19:40:47 -0700, kjakupak wrote: > Not sure if we've gotten that far in class, considering I don't know how > to go about doing that. Which bit aren't you sure about? (a) adding a "same unit" conversion to the units conversion program? (Actually, this bit isn't needed after all, you can avoid it with a test in comp.) (b) calling temp from comp to establish a common unit? (c) comparing the returned value of the call to temp with the other temp in comp Question, given the original "temp" function as previously described by yourself, what does the following function "f" which takes the same params as "comp" do: def f( t1, u1, t2, u2 ): if u1 == u2: return t2 else: return temp( t2, u2, u1 ) -- Denis McMahon, denismfmcmahon at gmail.com From denismfmcmahon at gmail.com Tue Sep 24 15:42:10 2013 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Tue, 24 Sep 2013 19:42:10 +0000 (UTC) Subject: Help with python functions? References: <5240489d$0$29992$c3e8da3$5496439d@news.astraweb.com> <3af43a58-fc56-46d1-9e1e-cb69f8aa520b@googlegroups.com> <5d5e5c4d-a79c-4b1a-b9da-ee2ad766ded8@googlegroups.com> Message-ID: On Tue, 24 Sep 2013 14:51:31 +0000, Denis McMahon wrote: > Question, given the original "temp" function as previously described by > yourself, what does the following function "f" which takes the same > params as "comp" do: > > def f( t1, u1, t2, u2 ): > if u1 == u2: > return t2 > else: > return temp( t2, u2, u1 ) Hmm, maybe: if u1 == u2: should have been: if u1.lower() == u2.lower(): -- Denis McMahon, denismfmcmahon at gmail.com From steve+comp.lang.python at pearwood.info Mon Sep 23 23:15:23 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 24 Sep 2013 03:15:23 GMT Subject: Help with python functions? References: <5240489d$0$29992$c3e8da3$5496439d@news.astraweb.com> <3af43a58-fc56-46d1-9e1e-cb69f8aa520b@googlegroups.com> Message-ID: <524103cb$0$29992$c3e8da3$5496439d@news.astraweb.com> On Mon, 23 Sep 2013 15:55:53 -0700, kjakupak wrote: > As for the next one, so far I've gotten: def comp(T1, u1, T2, u2): > if u1 > u2: > return -1 > elif u2 > u1: > return 1 > else: > return 0 That is only comparing the units, not the temperatures. Since the units are characters, you're essentially saying that any temperature in Kelvin is always greater than any temperature in Celsius, since "K" > "C". Worse, you're saying that any two temperatures with the same unit are automatically equal, so that -50?F == 50000?F. Instead, you need to convert both temperatures into a common unit, say, Kelvin, then compare the two temperatures: * convert T1 from u1 to Kelvin; * convert T2 from u2 to Kelvin; * compare T1 and T2. You don't have to use Kelvin. You could use any temperature scale, so long as it is the same for both temperatures. -- Steven From denismfmcmahon at gmail.com Tue Sep 24 11:02:28 2013 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Tue, 24 Sep 2013 15:02:28 +0000 (UTC) Subject: Help with python functions? References: <5240489d$0$29992$c3e8da3$5496439d@news.astraweb.com> <3af43a58-fc56-46d1-9e1e-cb69f8aa520b@googlegroups.com> <524103cb$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, 24 Sep 2013 03:15:23 +0000, Steven D'Aprano wrote: > You don't have to use Kelvin. You could use any temperature scale, so > long as it is the same for both temperatures. Given that he already has a handy conversion function to call, he should be able to convert t2 into the units of t1 if they're in different units (2 lines), and then do his comparison (5 lines). -- Denis McMahon, denismfmcmahon at gmail.com From cbf123 at mail.usask.ca Mon Sep 23 11:06:35 2013 From: cbf123 at mail.usask.ca (Chris Friesen) Date: Mon, 23 Sep 2013 09:06:35 -0600 Subject: python IDE and function definition Message-ID: <524058FB.20005@mail.usask.ca> Hi all, I'm looking for a python IDE (for Linux) that can look at code like this: class ConductorManager(manager.Manager): def compute_recover(self, context, instance): self.compute_api.stop(context, instance, do_cast=False) where I could highlight the "stop" and ask it to go to the definition. (Where the definition is in a different file.) I'm running into issues where my current IDE (I'm playing with Komodo) can't seem to locate the definition, I suspect because it's too ambiguous. The fact that python is dynamically typed seems to mean that there could potentially be multiple answers, any class with a stop() method with the right signature could presumably be plausible, right? So rather than give up, I'd like to have my IDE suggest all possible answers. Chris From fabiofz at gmail.com Mon Sep 23 11:32:32 2013 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Mon, 23 Sep 2013 12:32:32 -0300 Subject: python IDE and function definition In-Reply-To: <524058FB.20005@mail.usask.ca> References: <524058FB.20005@mail.usask.ca> Message-ID: On Mon, Sep 23, 2013 at 12:06 PM, Chris Friesen wrote: > > Hi all, > > I'm looking for a python IDE (for Linux) that can look at code like this: > > class ConductorManager(manager.**Manager): > def compute_recover(self, context, instance): > self.compute_api.stop(context, instance, do_cast=False) > > where I could highlight the "stop" and ask it to go to the definition. > (Where the definition is in a different file.) > > I'm running into issues where my current IDE (I'm playing with Komodo) > can't seem to locate the definition, I suspect because it's too ambiguous. > > The fact that python is dynamically typed seems to mean that there could > potentially be multiple answers, any class with a stop() method with the > right signature could presumably be plausible, right? So rather than give > up, I'd like to have my IDE suggest all possible answers. PyDev (http://pydev.org/) is able to do that (i.e.: if the find definition doesn't find it directly, it shows a list with possible matches for you to choose the most appropriate one: http://pydev.org/manual_adv_gotodef.html) -- additionally, you can also search for methods/classes/attributes directly: http://pydev.org/manual_adv_open_decl_quick.html Cheers, Fabio > > > Chris > -- > https://mail.python.org/**mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From cbf123 at mail.usask.ca Mon Sep 23 13:29:00 2013 From: cbf123 at mail.usask.ca (Chris Friesen) Date: Mon, 23 Sep 2013 11:29:00 -0600 Subject: python IDE and function definition In-Reply-To: References: <524058FB.20005@mail.usask.ca> Message-ID: <52407A5C.90401@mail.usask.ca> On 09/23/2013 09:32 AM, Fabio Zadrozny wrote: > On Mon, Sep 23, 2013 at 12:06 PM, Chris Friesen > wrote: > > > Hi all, > > I'm looking for a python IDE (for Linux) that can look at code like > this: > > class ConductorManager(manager.__Manager): > def compute_recover(self, context, instance): > self.compute_api.stop(context, instance, do_cast=False) > > where I could highlight the "stop" and ask it to go to the > definition. (Where the definition is in a different file.) > > I'm running into issues where my current IDE (I'm playing with > Komodo) can't seem to locate the definition, I suspect because it's > too ambiguous. > > The fact that python is dynamically typed seems to mean that there > could potentially be multiple answers, any class with a stop() > method with the right signature could presumably be plausible, > right? So rather than give up, I'd like to have my IDE suggest all > possible answers. > > > > PyDev (http://pydev.org/) is able to do that (i.e.: if the find > definition doesn't find it directly, it shows a list with possible > matches for you to choose the most appropriate one: > http://pydev.org/manual_adv_gotodef.html) -- additionally, you can also > search for methods/classes/attributes directly: > http://pydev.org/manual_adv_open_decl_quick.html I've installed eclipse/pydev and tried it out. The problem that I'm seeing is that it will show me *all* stop() methods that it knows about, regardless of function signature. So in the above case, my function call looks like: self.compute_api.stop(context, instance, do_cast=False) but pydev will offer matches that look like: def stop(self): This runs into problems with commonly-named functions. I tried searching for the start() method in: self.compute_api.start(context, instance) and it complained that there were too many possible results. Basically, I'm looking for something smart enough to throw out methods with the same name but that don't match the signature. Chris From fabiofz at gmail.com Mon Sep 23 13:37:01 2013 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Mon, 23 Sep 2013 14:37:01 -0300 Subject: python IDE and function definition In-Reply-To: <52407A5C.90401@mail.usask.ca> References: <524058FB.20005@mail.usask.ca> <52407A5C.90401@mail.usask.ca> Message-ID: On Mon, Sep 23, 2013 at 2:29 PM, Chris Friesen wrote: > On 09/23/2013 09:32 AM, Fabio Zadrozny wrote: > >> On Mon, Sep 23, 2013 at 12:06 PM, Chris Friesen > > wrote: >> >> >> Hi all, >> >> I'm looking for a python IDE (for Linux) that can look at code like >> this: >> >> class ConductorManager(manager.__**Manager): >> >> def compute_recover(self, context, instance): >> self.compute_api.stop(context, instance, do_cast=False) >> >> where I could highlight the "stop" and ask it to go to the >> definition. (Where the definition is in a different file.) >> >> I'm running into issues where my current IDE (I'm playing with >> Komodo) can't seem to locate the definition, I suspect because it's >> too ambiguous. >> >> The fact that python is dynamically typed seems to mean that there >> could potentially be multiple answers, any class with a stop() >> method with the right signature could presumably be plausible, >> right? So rather than give up, I'd like to have my IDE suggest all >> possible answers. >> >> >> >> PyDev (http://pydev.org/) is able to do that (i.e.: if the find >> definition doesn't find it directly, it shows a list with possible >> matches for you to choose the most appropriate one: >> http://pydev.org/manual_adv_**gotodef.html) >> -- additionally, you can also >> search for methods/classes/attributes directly: >> http://pydev.org/manual_adv_**open_decl_quick.html >> > > I've installed eclipse/pydev and tried it out. The problem that I'm > seeing is that it will show me *all* stop() methods that it knows about, > regardless of function signature. > > So in the above case, my function call looks like: > self.compute_api.stop(context, instance, do_cast=False) > > but pydev will offer matches that look like: > def stop(self): > > This runs into problems with commonly-named functions. I tried searching > for the start() method in: > > self.compute_api.start(**context, instance) > > and it complained that there were too many possible results. > > Basically, I'm looking for something smart enough to throw out methods > with the same name but that don't match the signature. > > Chris > > Seems like a nice request... it'd be nice if you can report it as a feature request at the pydev tracker (at https://sw-brainwy.rhcloud.com/ -- note that you have to sign up to create an issue). Cheers, Fabio -------------- next part -------------- An HTML attachment was scrubbed... URL: From nhodgson at iinet.net.au Mon Sep 23 19:20:41 2013 From: nhodgson at iinet.net.au (Neil Hodgson) Date: Tue, 24 Sep 2013 09:20:41 +1000 Subject: python IDE and function definition In-Reply-To: References: Message-ID: Chris Friesen: > where I could highlight the "stop" and ask it to go to the definition. > (Where the definition is in a different file.) > > I'm running into issues where my current IDE (I'm playing with Komodo) > can't seem to locate the definition, I suspect because it's too ambiguous. Some IDEs allow you to help them understand the context by adding type information. Here's some documentation for Wing IDE that uses an isinstance assertion: http://www.wingware.com/doc/edit/helping-wing-analyze-code Neil From fabiofz at gmail.com Tue Sep 24 06:54:33 2013 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Tue, 24 Sep 2013 07:54:33 -0300 Subject: python IDE and function definition In-Reply-To: References: Message-ID: On Mon, Sep 23, 2013 at 8:20 PM, Neil Hodgson wrote: > Chris Friesen: > > > where I could highlight the "stop" and ask it to go to the definition. >> (Where the definition is in a different file.) >> >> I'm running into issues where my current IDE (I'm playing with Komodo) >> can't seem to locate the definition, I suspect because it's too ambiguous. >> > > Some IDEs allow you to help them understand the context by adding type > information. Here's some documentation for Wing IDE that uses an isinstance > assertion: > http://www.wingware.com/doc/**edit/helping-wing-analyze-code Just to note, PyDev can also use the assert isinstance as well as docstrings (http://pydev.org/manual_adv_type_hints.html) for type hinting. Cheers, Fabio -------------- next part -------------- An HTML attachment was scrubbed... URL: From travisgriggs at gmail.com Tue Sep 24 12:59:32 2013 From: travisgriggs at gmail.com (Travis Griggs) Date: Tue, 24 Sep 2013 09:59:32 -0700 Subject: python IDE and function definition In-Reply-To: <524058FB.20005@mail.usask.ca> References: <524058FB.20005@mail.usask.ca> Message-ID: <5C2E0079-2D00-458D-B1A7-0EECE5976EBC@gmail.com> On Sep 23, 2013, at 8:06 AM, Chris Friesen wrote: > > Hi all, > > I'm looking for a python IDE (for Linux) that can look at code like this: > > class ConductorManager(manager.Manager): > def compute_recover(self, context, instance): > self.compute_api.stop(context, instance, do_cast=False) > > where I could highlight the "stop" and ask it to go to the definition. (Where the definition is in a different file.) > > I'm running into issues where my current IDE (I'm playing with Komodo) can't seem to locate the definition, I suspect because it's too ambiguous. > > The fact that python is dynamically typed seems to mean that there could potentially be multiple answers, any class with a stop() method with the right signature could presumably be plausible, right? So rather than give up, I'd like to have my IDE suggest all possible answers. Hi Chris, Not sure if this reproduces what you want or not. I use PyCharm (free for free stuff, and very affordable/worthwhile otherwise) on Linux (as well as OSX/Windows). I made a new project, added two files: provider.py: class Provider(object): def stop(self): pass usage.py: class Conglomerate(object): def doSomething(self): self.provision.stop() I then highlight 'stop', hit Ctrl-B (menu option go to>>declarations) and it brings up all the stop() definitions it could find, the Provider one on the top, click it and I jump there. Ctrl-Alt-B (menu option for goto>>implementation(s)) does nothing? UNLESS? I add this method to Conglomerate: def __init__(self): super.__init__() self.provision = Provider() Then go to implementations takes me right there to the other file. HTH From ben+python at benfinney.id.au Thu Sep 26 03:02:35 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 26 Sep 2013 17:02:35 +1000 Subject: python IDE and function definition References: <524058FB.20005@mail.usask.ca> Message-ID: <7wa9j0uktw.fsf@benfinney.id.au> Chris Friesen writes: > I'm running into issues where my current IDE (I'm playing with Komodo) > can't seem to locate the definition, I suspect because it's too > ambiguous. The feature you're looking for ? to start from the statement where a function is called, then jump to the statement where that function is defined ? is implemented via ?tags? across many languages and tools. One very popular implementation is ?Exuberant Ctags?. You can choose from the tools that support that system, and continue using the same system when you switch to a different language or a different tool. > So rather than give up, I'd like to have my IDE suggest all possible > answers. Good luck to you in learning a development environment that is *not* tied to the particular programming language you're writing. -- \ ?? a Microsoft Certified System Engineer is to information | `\ technology as a McDonalds Certified Food Specialist is to the | _o__) culinary arts.? ?Michael Bacarella | Ben Finney From quarantinemiles at gmail.com Mon Sep 23 13:10:11 2013 From: quarantinemiles at gmail.com (quarantinemiles at gmail.com) Date: Mon, 23 Sep 2013 10:10:11 -0700 (PDT) Subject: What's the best way to extract 2 values from a CSV file from each row systematically? Message-ID: Hey guys, I'm a little new to Python, and am still learning! I'm test building a web scraper that extracts prices from a website, based on two values I want to extract from a CSV file. The CSV has at least 1000 rows, an example: 0,0,KGD,0,DME,0,,0,0 The values I want to extract are KGD and DME (columns 3 and 5). Each row in the CSV file contains values in columns 3 and 5 that I'd like to extract. What's the best way to extract these data, so I can insert them as inputs in two different fields in a form? A list, dictionary, or MySQL? I try not to do anything with MySQL as I'm not familiar with it at all. I'm thinking of dictionary because at least I can make it work as a key/value pair (for columns 3 and 5), but a dictionary is unordered. I'd like to automatically go through each row in the CSV file from beginning to end to extract the two values in columns 3 and 5 and insert them into fields in a form. I'd really appreciate any suggestions or help, thanks in advance! From neilc at norwich.edu Mon Sep 23 13:20:41 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 23 Sep 2013 17:20:41 GMT Subject: What's the best way to extract 2 values from a CSV file from each row systematically? References: Message-ID: On 2013-09-23, quarantinemiles at gmail.com wrote: > Hey guys, > > I'm a little new to Python, and am still learning! > > I'm test building a web scraper that extracts prices from a > website, based on two values I want to extract from a CSV file. > The CSV has at least 1000 rows, an example: > > 0,0,KGD,0,DME,0,,0,0 > > The values I want to extract are KGD and DME (columns 3 and 5). Use the csv module. http://docs.python.org/2/library/csv.html -- Neil Cerutti From joel.goldstick at gmail.com Mon Sep 23 13:25:51 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 23 Sep 2013 13:25:51 -0400 Subject: What's the best way to extract 2 values from a CSV file from each row systematically? In-Reply-To: References: Message-ID: On Mon, Sep 23, 2013 at 1:10 PM, wrote: > Hey guys, > > I'm a little new to Python, and am still learning! > > I'm test building a web scraper that extracts prices from a website, based > on two values I want to extract from a CSV file. The CSV has at least 1000 > rows, an example: > > 0,0,KGD,0,DME,0,,0,0 > > The values I want to extract are KGD and DME (columns 3 and 5). > > Each row in the CSV file contains values in columns 3 and 5 that I'd like > to extract. What's the best way to extract these data, so I can insert them > as inputs in two different fields in a form? A list, dictionary, or MySQL? > I try not to do anything with MySQL as I'm not familiar with it at all. > > I'm thinking of dictionary because at least I can make it work as a > key/value pair (for columns 3 and 5), but a dictionary is unordered. I'd > like to automatically go through each row in the CSV file from beginning to > end to extract the two values in columns 3 and 5 and insert them into > fields in a form. > > I'd really appreciate any suggestions or help, thanks in advance! > > > > -- > https://mail.python.org/mailman/listinfo/python-list > You should check out the csv module here: http://docs.python.org/2/library/csv.html#module-csv It will read your csv file into a list (the file rows) of lists (the columns). You can easily loop over the data to extract the columns you want using list indexing -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Mon Sep 23 13:47:11 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 23 Sep 2013 12:47:11 -0500 Subject: What's the best way to extract 2 values from a CSV file from each row systematically? In-Reply-To: References: Message-ID: <20130923124711.1e5595c9@bigbox.christie.dr> On 2013-09-23 10:10, quarantinemiles at gmail.com wrote: > based on two values I want to extract from a CSV file. The > CSV has at least 1000 rows, an example: > > 0,0,KGD,0,DME,0,,0,0 [snip] > I'd like to automatically go through each row in the CSV file from > beginning to end to extract the two values in columns 3 and 5 and > insert them into fields in a form. The csv module has several tools that make this easy to do. If there are column-headers, you can do import csv with file("myfile.csv", "rb") as f: for row in csv.DictReader(f) insert_fields_into_form( row["KGD"], row["DME"], ) which I like for clarity, ease of updating, and robustness (if for some reason, the columns get moved around, or columns get added/removed, as long as the headers remain the same, you can get the data). If it doesn't have headers, then you'd have to manually pick out the columns, either by tuple-unpacking: with file("myfile.csv", "rb") as f: for _, _, kgd, _, dme in csv.reader(f) insert_fields_into_form(kgd, dme) or by directly indexing: KGD_COL = 3 DME_COL = 5 with file("myfile.csv", "rb") as f: for row in csv.reader(f) insert_fields_into_form( row[KGD_COL], row[DME_COL], ) both of which are more fragile than DictReader when it comes to columns being added/removed. I leave the implementation of insert_fields_into_form() up to you :-) -tkc From quarantinemiles at gmail.com Tue Sep 24 10:04:58 2013 From: quarantinemiles at gmail.com (Alex Lee) Date: Tue, 24 Sep 2013 07:04:58 -0700 (PDT) Subject: What's the best way to extract 2 values from a CSV file from each row systematically? In-Reply-To: References: Message-ID: <037629ff-64cb-4b35-b61f-54df4d4d4603@googlegroups.com> Thanks for the help guys! I'll definitely read up on the csv module documentation. Tim, that's incredibly helpful, thanks a lot! :) My CSV file doesn't have headers, but I'm sure I can just as easily add it in manually. From roland.em0001 at googlemail.com Fri Sep 27 05:22:48 2013 From: roland.em0001 at googlemail.com (Roland Mueller) Date: Fri, 27 Sep 2013 12:22:48 +0300 Subject: What's the best way to extract 2 values from a CSV file from each row systematically? In-Reply-To: <037629ff-64cb-4b35-b61f-54df4d4d4603@googlegroups.com> References: <037629ff-64cb-4b35-b61f-54df4d4d4603@googlegroups.com> Message-ID: Hello, 2013/9/24 Alex Lee > Thanks for the help guys! I'll definitely read up on the csv module > documentation. > > Tim, that's incredibly helpful, thanks a lot! :) My CSV file doesn't have > headers, but I'm sure I can just as easily add it in manually. > a better way to provide column headers is to use the fieldname parameter when creating the CSV reader. fieldnames is a string array that should match the number of columns in the csv file: *class *csv.DictReader(*csvfile*, *fieldnames=None*, *restkey=None*, * restval=None*, *dialect='excel'*, **args*, ***kwds*) BR, Roland -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From luca.cerone at gmail.com Sat Sep 28 06:21:58 2013 From: luca.cerone at gmail.com (Luca Cerone) Date: Sat, 28 Sep 2013 03:21:58 -0700 (PDT) Subject: What's the best way to extract 2 values from a CSV file from each row systematically? In-Reply-To: References: Message-ID: <3cc3a7eb-4ff1-41b6-963d-edb85b927949@googlegroups.com> > I'd really appreciate any suggestions or help, thanks in advance! Hi Alex if you know that you want only columns 3 and 5, you could also use list comprehension to fetch the values: import csv with open('yourfile.csv','rU') as fo: #the rU means read using Universal newlines cr = csv.reader(fo) values_list = [(r[2],r[4]) for r in cr] #you have a list of tuples containing the values you need Cheers, Luca From i.sheeha at gmail.com Mon Sep 23 14:08:02 2013 From: i.sheeha at gmail.com (Ismar Sehic) Date: Mon, 23 Sep 2013 11:08:02 -0700 (PDT) Subject: help with SUDS Message-ID: <2d64fd62-0bad-4074-9e2f-7d59fa71934a@googlegroups.com> hello, i'm trying to make a wrapper for making xml requests to hotelbeds.com site. this is what i got: import logging from suds.xsd.doctor import ImportDoctor, Import from suds.plugin import Plugin logging.basicConfig(level = logging.INFO) logging.getLogger('suds.client').setLevel(logging.DEBUG) from suds.client import Client url = 'http://xxx.xxx.xxx.xx/appservices/ws/FrontendService?wsdl' imp = Import('http://schemas.xmlsoap.org/soap/encoding/') doctor = ImportDoctor(imp) client = Client(url, doctor = doctor) print client rw = client.service.getHotelValuedAvail() print rw) print client **************** which gives me following result : Suds ( https://fedorahosted.org/suds/ ) version: 0.4 GA build: R699-20100913 Service ( FrontendServiceService ) tns="http://www.hotelbeds.com/wsdl/2005/06" Prefixes (1) ns0 = "http://schemas.xmlsoap.org/soap/encoding/" Ports (1): (FrontendService) Methods (34): cancelProtectionAdd(xs:anyType cancelProtectionAdd, ) cancelProtectionRemove(xs:anyType cancelProtectionRemove, ) getCancelProtectionAvail(xs:anyType getCancelProtectionAvail, ) getCarCountryList(xs:anyType getCarCountryList, ) getCarInfoSet(xs:anyType getCarInfoSet, ) getCarValuedAvail(xs:anyType getCarValuedAvail, ) getCountryList(xs:anyType getCountryList, ) getDestinationGroupList(xs:anyType getDestinationGroupList, ) getHotelBoardGroupList(xs:anyType getHotelBoardGroupList, ) getHotelBoardList(xs:anyType getHotelBoardList, ) getHotelCategoryGroupList(xs:anyType getHotelCategoryGroupList, ) getHotelCategoryList(xs:anyType getHotelCategoryList, ) getHotelCountryList(xs:anyType getHotelCountryList, ) getHotelDetail(xs:anyType getHotelDetail, ) getHotelList(xs:anyType getHotelList, ) getHotelRoomTypeGroupList(xs:anyType getHotelRoomTypeGroupList, ) getHotelValuedAvail(xs:anyType getHotelValuedAvail, ) getIncomingOfficeDetail(xs:anyType getIncomingOfficeDetail, ) getIncomingOfficeList(xs:anyType getIncomingOfficeList, ) getPurchaseDetail(xs:anyType getPurchaseDetail, ) getPurchaseList(xs:anyType getPurchaseList, ) getTicketAvail(xs:anyType getTicketAvail, ) getTicketClassificationList(xs:anyType getTicketClassificationList, ) getTicketCountryList(xs:anyType getTicketCountryList, ) getTicketDetail(xs:anyType getTicketDetail, ) getTicketValuation(xs:anyType getTicketValuation, ) getTransferCountryList(xs:anyType getTransferCountryList, ) getTransferValuedAvail(xs:anyType getTransferValuedAvail, ) getZoneGroupList(xs:anyType getZoneGroupList, ) purchaseCancel(xs:anyType purchaseCancel, ) purchaseConfirm(xs:anyType purchaseConfirm, ) purchaseFlush(xs:anyType purchaseFlush, ) serviceAdd(xs:anyType serviceAdd, ) serviceRemove(xs:anyType serviceRemove, ) Types (48): ns0:Array ns0:ENTITIES ns0:ENTITY ns0:ID ns0:IDREF ns0:IDREFS ns0:NCName ns0:NMTOKEN ns0:NMTOKENS ns0:NOTATION ns0:Name ns0:QName ns0:Struct ns0:anyURI ns0:arrayCoordinate ns0:base64 ns0:base64Binary ns0:boolean ns0:byte ns0:date ns0:dateTime ns0:decimal ns0:double ns0:duration ns0:float ns0:gDay ns0:gMonth ns0:gMonthDay ns0:gYear ns0:gYearMonth ns0:hexBinary ns0:int ns0:integer ns0:language ns0:long ns0:negativeInteger ns0:nonNegativeInteger ns0:nonPositiveInteger ns0:normalizedString ns0:positiveInteger ns0:short ns0:string ns0:time ns0:token ns0:unsignedByte ns0:unsignedInt ns0:unsignedLong ns0:unsignedShort DEBUG:suds.client:sending to (http://212.170.239.71:9091/appservices /ws/FrontendService) message: DEBUG:suds.client:headers = {'SOAPAction': u'""', 'Content-Type': 'text/xml; charset=utf-8'} Traceback (most recent call last): File "soaptest.py", line 23, in rw = client.service.getHotelValuedAvail() File "/usr/local/lib/python2.6/dist-packages/suds-0.4-py2.6.egg/suds/client.py", line 542, in __call__ return client.invoke(args, kwargs) File "/usr/local/lib/python2.6/dist-packages/suds-0.4-py2.6.egg/suds/client.py", line 602, in invoke result = self.send(soapenv) File "/usr/local/lib/python2.6/dist-packages/suds-0.4-py2.6.egg/suds/client.py", line 637, in send reply = transport.send(request) File "/usr/local/lib/python2.6/dist-packages/suds-0.4-py2.6.egg/suds/transport/https.py", line 64, in send return HttpTransport.send(self, request) File "/usr/local/lib/python2.6/dist-packages/suds-0.4-py2.6.egg/suds/transport/http.py", line 77, in send fp = self.u2open(u2request) File "/usr/local/lib/python2.6/dist-packages/suds-0.4-py2.6.egg/suds/transport/http.py", line 118, in u2open return url.open(u2request, timeout=tm) File "/usr/lib/python2.6/urllib2.py", line 391, in open response = self._open(req, data) File "/usr/lib/python2.6/urllib2.py", line 409, in _open '_open', req) File "/usr/lib/python2.6/urllib2.py", line 369, in _call_chain result = func(*args) File "/usr/lib/python2.6/urllib2.py", line 1172, in http_open return self.do_open(httplib.HTTPConnection, req) File "/usr/lib/python2.6/urllib2.py", line 1147, in do_open raise URLError(err) urllib2.URLError: ********************************************************************** this is how the xml request should look like: ENG TEST TEST 1 2 0 i cannot use any of these methods with suds, i keep getting type not found errors.is it a problem with namespaces, or the wsdl file is corrupted?if you have any idea, i would really appreciate it.thanks. From dieter at handshake.de Tue Sep 24 02:13:38 2013 From: dieter at handshake.de (dieter) Date: Tue, 24 Sep 2013 08:13:38 +0200 Subject: help with SUDS References: <2d64fd62-0bad-4074-9e2f-7d59fa71934a@googlegroups.com> Message-ID: <87k3i64ui5.fsf@handshake.de> Ismar Sehic writes: > hello, i'm trying to make a wrapper for making xml requests to hotelbeds.com site. > ... > File "/usr/lib/python2.6/urllib2.py", line 1172, in http_open > return self.do_open(httplib.HTTPConnection, req) > File "/usr/lib/python2.6/urllib2.py", line 1147, in do_open > raise URLError(err) > urllib2.URLError: This indicates a problem of the service you are contacting: "suds" tries to open a connection to the service url defined in the WSDL, but it does not get a response within a reasonable time frame. The problem might be temporary (a temporary overload of the corresponding service) - or they may be some error in the WSDL - or some firewall may interfere with your request - or ... From soto_andres at yahoo.com Mon Sep 23 14:10:11 2013 From: soto_andres at yahoo.com (Andres Soto) Date: Mon, 23 Sep 2013 11:10:11 -0700 (PDT) Subject: how can I retrieve a particular tweet, having its tweet id? Message-ID: <1379959811.68614.YahooMailNeo@web122004.mail.ne1.yahoo.com> ?how can I retrieve a particular tweet, having its tweet id,?and the username, the date and the language? Regards Andr?s Soto -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Mon Sep 23 16:17:58 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 23 Sep 2013 16:17:58 -0400 Subject: how can I retrieve a particular tweet, having its tweet id? In-Reply-To: <1379959811.68614.YahooMailNeo@web122004.mail.ne1.yahoo.com> References: <1379959811.68614.YahooMailNeo@web122004.mail.ne1.yahoo.com> Message-ID: On 9/23/2013 2:10 PM, Andres Soto wrote: > how can I retrieve a particular tweet, having its tweet id, and the > username, the date and the language? What, if anything, have you done to try to solve this yourself? Like searching the web? ('Python twitter' for instance) -- Terry Jan Reedy From andypu at zoho.com Tue Sep 24 03:40:49 2013 From: andypu at zoho.com (andypu at zoho.com) Date: Tue, 24 Sep 2013 00:40:49 -0700 (PDT) Subject: combine pictures Message-ID: hello, i have a picture and i want to merge it with an other picture which is half transparent and the first picture will shine through it, has python the library's to do this? From tjreedy at udel.edu Tue Sep 24 06:01:47 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 24 Sep 2013 06:01:47 -0400 Subject: combine pictures In-Reply-To: References: Message-ID: On 9/24/2013 3:40 AM, andypu at zoho.com wrote: > hello, i have a picture and i want to merge it with an other picture which is half transparent and the first picture will shine through it, has python the library's to do this? Searching 'python image library' might lead one to https://pypi.python.org/pypi/Pillow/2.1.0 -- Terry Jan Reedy From roy at panix.com Tue Sep 24 07:40:26 2013 From: roy at panix.com (Roy Smith) Date: Tue, 24 Sep 2013 07:40:26 -0400 Subject: combine pictures References: Message-ID: In article , Terry Reedy wrote: > On 9/24/2013 3:40 AM, andypu at zoho.com wrote: > > hello, i have a picture and i want to merge it with an other picture which > > is half transparent and the first picture will shine through it, has python > > the library's to do this? > > Searching 'python image library' might lead one to > https://pypi.python.org/pypi/Pillow/2.1.0 It might also lead one to http://www.pythonware.com/products/pil/ That being said, I've had "Evaluate Pillow as possible PIL replacement" on my todo list for a while :-) From andypu at zoho.com Tue Sep 24 10:17:52 2013 From: andypu at zoho.com (andypu at zoho.com) Date: Tue, 24 Sep 2013 07:17:52 -0700 (PDT) Subject: combine pictures In-Reply-To: References: Message-ID: <2d8e957f-7fd0-474b-88f1-4b9b788c5f39@googlegroups.com> Oh i thaught maybe python comes with something native, bevore i install something new i think i might better look into if kivy can do the job - thats allready installed... From osumoclement at gmail.com Tue Sep 24 04:09:01 2013 From: osumoclement at gmail.com (Osumo Clement) Date: Tue, 24 Sep 2013 01:09:01 -0700 (PDT) Subject: How to login to a website using Python 3.x? Message-ID: <51fe830b-faa9-4a43-a247-9c4e25500430@googlegroups.com> Hi. I am new to Python. I am making a script where logging in to a website is the first step.. I am using Python 3.3 All of the help I have seen online uses urllib2 which in Python 3 aint there. I will greatly appreciate any help From breamoreboy at yahoo.co.uk Tue Sep 24 04:39:07 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 24 Sep 2013 09:39:07 +0100 Subject: How to login to a website using Python 3.x? In-Reply-To: <51fe830b-faa9-4a43-a247-9c4e25500430@googlegroups.com> References: <51fe830b-faa9-4a43-a247-9c4e25500430@googlegroups.com> Message-ID: On 24/09/2013 09:09, Osumo Clement wrote: > Hi. I am new to Python. I am making a script where logging in to a website is the first step.. I am using Python 3.3 All of the help I have seen online uses urllib2 which in Python 3 aint there. I will greatly appreciate any help > urllib2 has been renamed in Python 3 see http://www.python.org/dev/peps/pep-3108/#urllib-package -- Cheers. Mark Lawrence From kwpolska at gmail.com Wed Sep 25 09:59:16 2013 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Wed, 25 Sep 2013 15:59:16 +0200 Subject: How to login to a website using Python 3.x? In-Reply-To: <51fe830b-faa9-4a43-a247-9c4e25500430@googlegroups.com> References: <51fe830b-faa9-4a43-a247-9c4e25500430@googlegroups.com> Message-ID: On Tue, Sep 24, 2013 at 10:39 AM, Mark Lawrence wrote: > On 24/09/2013 09:09, Osumo Clement wrote: >> >> Hi. I am new to Python. I am making a script where logging in to a >> website is the first step.. I am using Python 3.3 All of the help I have >> seen online uses urllib2 which in Python 3 aint there. I will greatly >> appreciate any help >> > > urllib2 has been renamed in Python 3 see > http://www.python.org/dev/peps/pep-3108/#urllib-package Note that, for sanity, you should use (a third-party package) instead. -- Chris ?Kwpolska? Warrick PGP: 5EAAEA16 stop html mail | always bottom-post | only UTF-8 makes sense From j.bagg at kent.ac.uk Tue Sep 24 05:42:22 2013 From: j.bagg at kent.ac.uk (J. Bagg) Date: Tue, 24 Sep 2013 10:42:22 +0100 Subject: removing BOM prepended by codecs? Message-ID: <52415E7E.6010701@kent.ac.uk> I'm having trouble with the BOM that is now prepended to codecs files. The files have to be read by java servlets which expect a clean file without any BOM. Is there a way to stop the BOM being written? It is seriously messing up my work as the servlets do not expect it to be there. I could delete it but that means another delay in retrieving the data. My work is a bibliographic system and I'm writing a new search engine in Python to replace an ancient one in C. I'm working on Linux with a locale of en_GB.UTF8 -- Dr Janet Bagg CSAC, Dept of Anthropology, University of Kent, UK From steve at pearwood.info Tue Sep 24 06:56:21 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 24 Sep 2013 10:56:21 GMT Subject: removing BOM prepended by codecs? References: Message-ID: <52416fd5$0$29991$c3e8da3$5496439d@news.astraweb.com> On Tue, 24 Sep 2013 10:42:22 +0100, J. Bagg wrote: > I'm having trouble with the BOM that is now prepended to codecs files. > The files have to be read by java servlets which expect a clean file > without any BOM. > > Is there a way to stop the BOM being written? Of course there is :-) but first we need to know how you are writing it in the first place. If you are dealing with existing files, which already contain a BOM, you may need to open the files and re-save them without the BOM. If you are dealing with temporary files you're creating programmatically, it depends how you're creating them. My guess is that you're doing something like this: f = open("some file", "w", encoding="UTF-16") # or UTF-32 f.write(data) f.close() or similar. Both the UTF-16 and UTF-32 codecs write BOMs. To avoid that, you should use UTF-16-BE or UTF-16-LE (Big Endian or Little Endian), as appropriate to your platform. If you're getting a UTF-8 BOM, that's seriously weird. The standard UTF-8 codec doesn't write a BOM. (Strictly speaking, it's not a Byte Order Mark, but a Signature.) Unless you're using encoding='UTF-8-sig', I can't guess how you're getting a UTF-8 BOM. If you're doing something else, well, you'll have to explain what you're doing before we can tell you how to stop doing it :-) > I'm working on Linux with a locale of en_GB.UTF8 The locale only sets the default encoding used by the OS, not that used by Python. Python 2 defaults to ASCII; Python 3 defaults to UTF-8. -- Steven From wxjmfauth at gmail.com Tue Sep 24 14:43:41 2013 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Tue, 24 Sep 2013 11:43:41 -0700 (PDT) Subject: removing BOM prepended by codecs? In-Reply-To: References: Message-ID: <35d582cb-130d-484f-a434-554bb52175ac@googlegroups.com> Le mardi 24 septembre 2013 11:42:22 UTC+2, J. Bagg a ?crit?: > I'm having trouble with the BOM that is now prepended to codecs files. > > The files have to be read by java servlets which expect a clean file > > without any BOM. > > > > Is there a way to stop the BOM being written? > > > > It is seriously messing up my work as the servlets do not expect it to > > be there. I could delete it but that means another delay in retrieving > > the data. My work is a bibliographic system and I'm writing a new search > > engine in Python to replace an ancient one in C. > > > > I'm working on Linux with a locale of en_GB.UTF8 > > > > -- > > Dr Janet Bagg > > CSAC, Dept of Anthropology, > > University of Kent, UK --------- Some points. - The coding of a text file does not matter. What's count is the knowledge of the coding. - The *mark* (once the Unicode.org terminology in FAQ) indicating a unicode encoded raw text file is neither a byte order mark, nor a signature, it is an encoded code point, the encoded U+FEFF, 'ZERO WIDTH NO-BREAK SPACE', code point. (Note, a non breaking space at the start of a text is a non sense.) - When such a mark exists, it is always possible to work 100% safely. No possible error. - When such a mark does not exist, in many cases only guessing is a (the) valid solution. These are facts. Now to the question, should I use (put) such a mark, esp. in utf-8? I would say the following: It seems to me, one see more and more marked utf-8 files. (Windows is probably a reason.) More importantly, more and more tools and software are handling this utf-8 mark, or are corrected to support it, so it basicaly does not hurt too much. Eg. Python, golang 1.1 (was not the case in 1.0), LibreOffice, TeXWorks supports it now (was once not the case), the unicode TeX engines, ... If I had to work in "archiving", it would seriously think twice. PS Unicode encodes characters on a per *script* ("alphabet") basis, not per *language*. jmf From rosuav at gmail.com Tue Sep 24 18:20:51 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 Sep 2013 08:20:51 +1000 Subject: removing BOM prepended by codecs? In-Reply-To: <35d582cb-130d-484f-a434-554bb52175ac@googlegroups.com> References: <35d582cb-130d-484f-a434-554bb52175ac@googlegroups.com> Message-ID: On Wed, Sep 25, 2013 at 4:43 AM, wrote: > - The *mark* (once the Unicode.org terminology in FAQ) indicating > a unicode encoded raw text file is neither a byte order mark, > nor a signature, it is an encoded code point, the encoded > U+FEFF, 'ZERO WIDTH NO-BREAK SPACE', code point. (Note, a > non breaking space at the start of a text is a non sense.) > > - When such a mark exists, it is always possible to work > 100% safely. No possible error. I have a file encoded in Latin-1 which begins with LATIN SMALL LETTER Y WITH DIAERESIS followed by LATIN SMALL LETTER THORN. I also have a file encoded in EBCDIC (okay, I don't really, but let's pretend) that begins with the same bytes. But of course, when such a mark exists, there is no possible error - of that there is no manner of doubt, no possible, probable shadow of doubt, no possible doubt whatever. ("No possible doubt whatever.") ChrisA From __peter__ at web.de Tue Sep 24 07:06:46 2013 From: __peter__ at web.de (Peter Otten) Date: Tue, 24 Sep 2013 13:06:46 +0200 Subject: removing BOM prepended by codecs? References: <52415E7E.6010701@kent.ac.uk> Message-ID: J. Bagg wrote: > I'm having trouble with the BOM that is now prepended to codecs files. > The files have to be read by java servlets which expect a clean file > without any BOM. > > Is there a way to stop the BOM being written? I think if you specify the byte order explicitly with "UTF-16-LE" or "UTF-16-BE" no BOM is written. From piet at vanoostrum.org Tue Sep 24 23:34:04 2013 From: piet at vanoostrum.org (Piet van Oostrum) Date: Tue, 24 Sep 2013 23:34:04 -0400 Subject: removing BOM prepended by codecs? References: Message-ID: "J. Bagg" writes: > I've checked the original files using od and they don't have BOMs. > > I'll remove them in the servlet. The overhead is probably small enough > unless somebody is doing a massive search. We have a limit anyway to > prevent somebody stealing the entire set of data. > > I started writing the Python search because the ancient C search had > started putting out BOMs. I'm actually mystified because our home Linux > box does not add BOMs even though it runs 2.7 but my work one does even > though it has the same version. The only difference is Fedora 18 v > Fedora 17. > > The BOMs are certainly there: > > <86> %R 10C0203z-621 > %A Fran?ois-Xavier Le_Bourdonnec > > 0000000 206 255 373 % R 1 0 C 0 2 0 3 z - > That is not a BOM or SIG. It isn't even valid utf-8. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From j.bagg at kent.ac.uk Tue Sep 24 09:01:04 2013 From: j.bagg at kent.ac.uk (J. Bagg) Date: Tue, 24 Sep 2013 14:01:04 +0100 Subject: removing BOM prepended by codecs? Message-ID: <52418D10.9080508@kent.ac.uk> I'm using: outputfile = codecs.open (fn, 'w+', 'utf-8', errors='strict') to write as I know that the files are unicode compliant. I run the raw files that are delivered through a Python script to check the unicode and report problem characters which are then edited. The files use a whole variety of languages from Sanskrit to Cyrillic and more obscure ones too. I'll probably have to remove it in the servlet as we have standardised on utf-8. This was done some years ago when utf-16 was rare (apart from Macs). J From mail at timgolden.me.uk Tue Sep 24 09:33:10 2013 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 24 Sep 2013 14:33:10 +0100 Subject: removing BOM prepended by codecs? In-Reply-To: <52418D10.9080508@kent.ac.uk> References: <52418D10.9080508@kent.ac.uk> Message-ID: <52419496.30707@timgolden.me.uk> On 24/09/2013 14:01, J. Bagg wrote: > I'm using: > > outputfile = codecs.open (fn, 'w+', 'utf-8', errors='strict') Well for the life of me I can't make that produce a BOM on 2.7 or 3.4. In other words: import codecs with codecs.open("temp.txt", "w+", "utf-8", errors="strict") as f: f.write("abc") with open("temp.txt", "rb") as f: assert f.read()[:3] == b"abc" works without any assertion failures on 2.7 and 3.4, both running on Win7 and on 2.7 and 3.3 running on Linux. Have I misunderstood your situation? TJG From davea at davea.name Tue Sep 24 09:35:46 2013 From: davea at davea.name (Dave Angel) Date: Tue, 24 Sep 2013 13:35:46 +0000 (UTC) Subject: removing BOM prepended by codecs? References: <52418D10.9080508@kent.ac.uk> Message-ID: On 24/9/2013 09:01, J. Bagg wrote: Why would you start a new thread? just do a Reply-List (or Reply-All and remove the extra names) to the appropriate message on the existing thread. > I'm using: > > outputfile = codecs.open (fn, 'w+', 'utf-8', errors='strict') That won't be adding a BOM. It appends to an existing file, which already may have a BOM in it. Or conceivably you have a BOM in your unicode string that you're passing to write() method. > > to write as I know that the files are unicode compliant. I run the raw > files that are delivered through a Python script to check the unicode > and report problem characters which are then edited. The files use a > whole variety of languages from Sanskrit to Cyrillic and more obscure > ones too. > it'd be much nicere to remove it when writing the file. -- DaveA From babmis307 at gmail.com Tue Sep 24 09:22:53 2013 From: babmis307 at gmail.com (bab mis) Date: Tue, 24 Sep 2013 06:22:53 -0700 (PDT) Subject: xml parsing as YML parser does does Message-ID: <26dc29f8-45d4-4a97-bec6-658d9336b3ad@googlegroups.com> Hi , Here is an example how i do yml parsing and a proper pythonic object returns , is it possible in XML, tried lxml,dom, but there is no straight forward solution: [root at linux-source pyrun]# cat x.yml #Section for specifying test process information Test: commoninfo: buildhome : "/root/linuxbuilds" Project: default: test_parameters: svnuser : "vmbuild" suite : "sanity" username : "root" Commands : - name : generalcheck of destination action : generalcheck - name : retrieve source from svn action : retsource params : src=x,src1=y [root at linux-source pyrun] ================================ [root at linux-source pyrun]# cat a.py import yaml fd = open("x.yml") data = fd.read() fd.close() ydata = yaml.safe_load(data) import pprint pprint.pprint( ydata ) ======================= [root at linux-source pyrun]# python a.py {'Test': {'Project': {'default': {'Commands': [{'action': 'generalcheck', 'name': 'generalcheck of destination'}, {'action': 'retsource', 'name': 'retrieve source from svn', 'params': 'src=x,src1=y'}], 'test_parameters': { 'suite': 'sanity', 'svnuser': 'vmbuild', 'username': 'root'}}}, 'commoninfo': {'buildhome': '/root/linuxbuilds'}}} From j.bagg at kent.ac.uk Tue Sep 24 11:17:18 2013 From: j.bagg at kent.ac.uk (J. Bagg) Date: Tue, 24 Sep 2013 16:17:18 +0100 Subject: removing BOM prepended by codecs? Message-ID: <5241ACFE.8070801@kent.ac.uk> I've checked the original files using od and they don't have BOMs. I'll remove them in the servlet. The overhead is probably small enough unless somebody is doing a massive search. We have a limit anyway to prevent somebody stealing the entire set of data. I started writing the Python search because the ancient C search had started putting out BOMs. I'm actually mystified because our home Linux box does not add BOMs even though it runs 2.7 but my work one does even though it has the same version. The only difference is Fedora 18 v Fedora 17. The BOMs are certainly there: <86> %R 10C0203z-621 %A Fran?ois-Xavier Le_Bourdonnec 0000000 206 255 373 % R 1 0 C 0 2 0 3 z - J From __peter__ at web.de Tue Sep 24 11:59:21 2013 From: __peter__ at web.de (Peter Otten) Date: Tue, 24 Sep 2013 17:59:21 +0200 Subject: removing BOM prepended by codecs? References: <5241ACFE.8070801@kent.ac.uk> Message-ID: J. Bagg wrote: > I've checked the original files using od and they don't have BOMs. > > I'll remove them in the servlet. The overhead is probably small enough > unless somebody is doing a massive search. We have a limit anyway to > prevent somebody stealing the entire set of data. > > I started writing the Python search because the ancient C search had > started putting out BOMs. I'm actually mystified because our home Linux > box does not add BOMs even though it runs 2.7 but my work one does even > though it has the same version. The only difference is Fedora 18 v > Fedora 17. > > The BOMs are certainly there: > > <86> %R 10C0203z-621 > %A Fran?ois-Xavier Le_Bourdonnec > > 0000000 206 255 373 % R 1 0 C 0 2 0 3 z - > > J > Were these files edited with Notepad? According to http://docs.python.org/2/library/codecs.html#encodings-and-unicode """ To increase the reliability with which a UTF-8 encoding can be detected, Microsoft invented a variant of UTF-8 (that Python 2.5 calls "utf-8-sig") for its Notepad program: Before any of the Unicode characters is written to the file, a UTF-8 encoded BOM (which looks like this as a byte sequence: 0xef, 0xbb, 0xbf) is written. """ To strip off such a UTF-8 encoded BOM you can open the source file with "utf-8-sig" and write the output to a (different!) file with "utf-8" with codecs.open(source, "r", encoding="utf-8-sig") as instream: with codecs.open(dest, "w", encoding="utf-8") as outstream: shutil.copyfileobj(instream, outstream) From commons at tiac.net Tue Sep 24 14:03:48 2013 From: commons at tiac.net (Michael Lamport Commons) Date: Tue, 24 Sep 2013 14:03:48 -0400 (GMT-04:00) Subject: Possibilities of Building "Stacked Neural Networks" Message-ID: <28083292.1380045828640.JavaMail.root@wamui-haziran.atl.sa.earthlink.net> Dear Members of this list-serve: Would it be possible to build ?stacked neural networks? like the one shown in the attached document? You may have a few questions about the stacked neural network. For example, what is a stacked neural network? What is the difference between stacked neural networks and the existing neural network? A brief description is provided in the attached document. Based on this brief description, I would like to know how would one go about building such stacked neural networks cheaply and easily? Is there any software available that can do this? How much would it cost? Please feel free to contact me if you think that it would be possible or easier to apply stacked neural network into a more practical field? Suggestions are welcome as well. My best, Michael Lamport Commons, Ph.D. Assistant Clinical Professor Department of Psychiatry Harvard Medical School Beth Israel Deaconess Medical Center commons at tiac.net 617-497-5270 Telephone 617-491-5270 Fax http://www.dareassociation.org/ -------------- next part -------------- A non-text attachment was scrubbed... Name: Stacked Neural Nets Dr. Commons.pdf Type: application/pdf Size: 210552 bytes Desc: not available URL: From robert.kern at gmail.com Wed Sep 25 05:43:38 2013 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 25 Sep 2013 10:43:38 +0100 Subject: Possibilities of Building "Stacked Neural Networks" In-Reply-To: <28083292.1380045828640.JavaMail.root@wamui-haziran.atl.sa.earthlink.net> References: <28083292.1380045828640.JavaMail.root@wamui-haziran.atl.sa.earthlink.net> Message-ID: On 2013-09-24 19:03, Michael Lamport Commons wrote: > Dear Members of this list-serve: > > Would it be possible to build ?stacked neural networks? like the one shown in the attached document? > > You may have a few questions about the stacked neural network. For example, what is a stacked neural network? What is the difference between stacked neural networks and the existing neural network? A brief description is provided in the attached document. > > Based on this brief description, I would like to know how would one go about building such stacked neural networks cheaply and easily? Is there any software available that can do this? How much would it cost? > > Please feel free to contact me if you think that it would be possible or easier to apply stacked neural network into a more practical field? Suggestions are welcome as well. The term of art for these kind of architectures is "deep learning" (and associated terms like "deep architecture", "deep networks", etc.). It's an active field of research that is showing promising preliminary results, and we are beginning to see its limits as well. Google and other big machine learning players are putting a lot of resources into building these systems. http://arxiv.org/pdf/1112.6209v3.pdf A good resource would be the Deep Learning Tutorial which shows you how to build these systems using Theano, a Python package for computing with GPUs, one that is particularly well-suited to building deep neural networks. http://deeplearning.net/tutorial/ Unfortunately, there is nothing cheap or easy about deep networks. They are *very* computationally expensive. You will probably need a small cluster of GPUs to solve interesting problems, and training one will probably take a couple of days of computation (for the final run, *after* you have debugged your code and done the initial experiments to find all of the right hyperparameters for your problem). Good luck! -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From wrw at mac.com Wed Sep 25 08:29:56 2013 From: wrw at mac.com (William Ray Wing) Date: Wed, 25 Sep 2013 08:29:56 -0400 Subject: Possibilities of Building "Stacked Neural Networks" In-Reply-To: References: <28083292.1380045828640.JavaMail.root@wamui-haziran.atl.sa.earthlink.net> Message-ID: On Sep 25, 2013, at 5:43 AM, Robert Kern wrote: > On 2013-09-24 19:03, Michael Lamport Commons wrote: >> Dear Members of this list-serve: >> >> Would it be possible to build ?stacked neural networks? like the one shown in the attached document? >> >> You may have a few questions about the stacked neural network. For example, what is a stacked neural network? What is the difference between stacked neural networks and the existing neural network? A brief description is provided in the attached document. >> >> Based on this brief description, I would like to know how would one go about building such stacked neural networks cheaply and easily? Is there any software available that can do this? How much would it cost? >> >> Please feel free to contact me if you think that it would be possible or easier to apply stacked neural network into a more practical field? Suggestions are welcome as well. > > The term of art for these kind of architectures is "deep learning" (and associated terms like "deep architecture", "deep networks", etc.). It's an active field of research that is showing promising preliminary results, and we are beginning to see its limits as well. Google and other big machine learning players are putting a lot of resources into building these systems. > > http://arxiv.org/pdf/1112.6209v3.pdf > > A good resource would be the Deep Learning Tutorial which shows you how to build these systems using Theano, a Python package for computing with GPUs, one that is particularly well-suited to building deep neural networks. > > http://deeplearning.net/tutorial/ > > Unfortunately, there is nothing cheap or easy about deep networks. They are *very* computationally expensive. You will probably need a small cluster of GPUs to solve interesting problems, and training one will probably take a couple of days of computation (for the final run, *after* you have debugged your code and done the initial experiments to find all of the right hyperparameters for your problem). > > Good luck! > > -- > Robert Kern The OP might also want to look at Nvidia's CUDO units (which package GPUs into massive parallel accelerators - currently well over 2500 GPUs in a single fat card) and PyCUDA which makes the CUDA software available to python. -Bill From j.bagg at kent.ac.uk Tue Sep 24 13:32:53 2013 From: j.bagg at kent.ac.uk (J. Bagg) Date: Tue, 24 Sep 2013 18:32:53 +0100 Subject: removing BOM prepended by codecs? Message-ID: <5241CCC5.7080401@kent.ac.uk> My editor is JEdit. I use it on a Win 7 machine but have everything set up for *nix files as that is the machine I'm normally working on. The files are mailed to me as updates. The library where the indexers work do use MS computers but this is restricted to EndNote with an exporter into the old Bib-Refer format which we use. I then run them through a Python program to check the unicode for new characters that also creates an ascii transliteration of the main fields and checks for errors. The problem is occuring at the search stage. This stage creates a script with directives to search particular years and then puts the results into a file in /tmp. The process is left over from an old CGI version but is efficient and so has been kept. This has been done with a very old C program that a collegue wrote back in the 90s with more recent updates. I'm in the process of updating this to Python as it is getting too difficult to maintain. J From dwivedi.devika at gmail.com Wed Sep 25 04:41:38 2013 From: dwivedi.devika at gmail.com (dwivedi.devika at gmail.com) Date: Wed, 25 Sep 2013 01:41:38 -0700 (PDT) Subject: How to quickly search over a large number of files using python? Message-ID: <60f36178-b584-4fcb-8ad9-2dac6052e6d8@googlegroups.com> Hi all, I am a newbie to python. I have about 500 search queries, and about 52000 files in which I have to find all matches for each of the 500 queries. How should I approach this? Seems like the straightforward way to do it would be to loop through each of the files and go line by line comparing all the terms to the query, but this seems like it would take too long. Can someone give me a suggestion as to how to minimize the search time? Thanks! From oscar.j.benjamin at gmail.com Wed Sep 25 06:00:22 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 25 Sep 2013 11:00:22 +0100 Subject: How to quickly search over a large number of files using python? In-Reply-To: <60f36178-b584-4fcb-8ad9-2dac6052e6d8@googlegroups.com> References: <60f36178-b584-4fcb-8ad9-2dac6052e6d8@googlegroups.com> Message-ID: On 25 September 2013 09:41, wrote: > I am a newbie to python. > > I have about 500 search queries, and about 52000 files in which I have to find all matches for each of the 500 queries. > > How should I approach this? Seems like the straightforward way to do it would be to loop through each of the files and go line by line comparing all the terms to the query, but this seems like it would take too long. That would be the obvious way to do this. > Can someone give me a suggestion as to how to minimize the search time? What do you mean by a "query"? (Code indicating how a query would match would be helpful here.) Oscar From davea at davea.name Wed Sep 25 06:28:34 2013 From: davea at davea.name (Dave Angel) Date: Wed, 25 Sep 2013 10:28:34 +0000 (UTC) Subject: How to quickly search over a large number of files using python? References: <60f36178-b584-4fcb-8ad9-2dac6052e6d8@googlegroups.com> Message-ID: On 25/9/2013 04:41, dwivedi.devika at gmail.com wrote: > Hi all, > > I am a newbie to python. > > I have about 500 search queries, and about 52000 files in which I have to find all matches for each of the 500 queries. > > How should I approach this? Seems like the straightforward way to do it would be to loop through each of the files and go line by line comparing all the terms to the query, but this seems like it would take too long. > > Can someone give me a suggestion as to how to minimize the search time? > Are these files text or binary? Are they an 8bit character set or Unicode? Without more information about what these "queries" are, it's not even possible to say whether the above approach could work at all. Please specify the nature of these queries, and whether all the queries are of the same form. For example, it may be that each of the queries is a simple search string, not containing newline or wildcard. Or it may be that the queries are arbitrary regular expressions, with some of them potentially matching a multi-line block of text. Have you implemented the brute-force approach you describe, and is it indeed too slow? By what factor? Does it take 1000 times as long as desired, or 5 times? How about if you do one query for those 52000 files, is it still too slow? And by what factor? Assuming each of the queries is independent, and that none of them need more than one line to process, it might be possible to combine some or all of those queries into a siimpler filter or filters. Then one could speed up the process by applying the filter to each line, and only if it triggers, to check the line with the individual queries. You also don't indicate whether this is a one--time query, or whether the same files might need later to be searched for a different set of queries, or whether the queries might need to be applied to a different set of files. Or whether the same search may need to be repeated on a very similar set of files, or ... Even in the most ideally placed set of constraints, some queries may produce filters that are either harder to apply than the original queries, or filters that produce so many candidates that this process takes longer than just applying the queries brute-force. Many times, optimization efforts focus on the wrong problem, or ignore the relative costs of programmer time and machine time. Other times, the problem being optimized is simply intractiable with current technology. -- DaveA From roy at panix.com Wed Sep 25 08:41:12 2013 From: roy at panix.com (Roy Smith) Date: Wed, 25 Sep 2013 08:41:12 -0400 Subject: How to quickly search over a large number of files using python? References: <60f36178-b584-4fcb-8ad9-2dac6052e6d8@googlegroups.com> Message-ID: In article <60f36178-b584-4fcb-8ad9-2dac6052e6d8 at googlegroups.com>, dwivedi.devika at gmail.com wrote: > Hi all, > > I am a newbie to python. > > I have about 500 search queries, and about 52000 files in which I have to > find all matches for each of the 500 queries. Before anybody can even begin to answer this question, we need to know what you mean by "search query". Are you talking pattern matching, keyword matching, fuzzy hits OK, etc? Give us a couple of examples of the kind of searches you'd like to execute. Also, is this a one-off thing, or are you planning to do many searches over the same collection of files? If so, you will want to do some sort of pre-processing or indexing to speed up the search execution. It's extremely unlikely you want to reinvent the wheel here. There are tons of search packages out there that do this sort of thing. Just a few to check out include Apache Lucene, Apache Solr, and Xapian. From j.bagg at kent.ac.uk Wed Sep 25 06:38:38 2013 From: j.bagg at kent.ac.uk (J. Bagg) Date: Wed, 25 Sep 2013 11:38:38 +0100 Subject: removing BOM prepended by codecs? Message-ID: <5242BD2E.9000309@kent.ac.uk> So it is just a random sequence of "junk". It will be a matter of finding the real start of the record (in this case a %) and throwing the "junk" away. I was misled by the note in the codecs class that BOMs were being prepended. Should have looked more carefully. Mea culpa. From davea at davea.name Wed Sep 25 06:54:15 2013 From: davea at davea.name (Dave Angel) Date: Wed, 25 Sep 2013 10:54:15 +0000 (UTC) Subject: removing BOM prepended by codecs? References: <5242BD2E.9000309@kent.ac.uk> Message-ID: On 25/9/2013 06:38, J. Bagg wrote: > So it is just a random sequence of "junk". > > It will be a matter of finding the real start of the record (in this > case a %) and throwing the "junk" away. Please join the list. Your present habit of starting a new thread for each of your messages is getting old. You still need to find the source of the "junk" if you want anything approaching reliability. The open() call you showed in one of the other four threads had a "append" mode. Is it possible that you're "creating" a file without deleting pre-existing junk? -- DaveA From SumiTomohiko at neko-daisuki.ddo.jp Wed Sep 25 07:24:47 2013 From: SumiTomohiko at neko-daisuki.ddo.jp (Tomohiko Sumi) Date: Wed, 25 Sep 2013 20:24:47 +0900 (JST) Subject: nexec on Android is ready for Python. Message-ID: I announce that nexec[1] is ready for Python. nexec is a system to transfer system call requests. You can use applications in an nexec server as same as those in your local machine. nexec is ready for Python now. Furthermore, nexec client for Android is available. These mean that you can use Python on Android via nexec. The demo application[2] is good to start nexec on Android. The documentation includes the tutorial for Python[3]. [1] http://neko-daisuki.ddo.jp/~SumiTomohiko/nexec/index.html [2] http://neko-daisuki.ddo.jp/~SumiTomohiko/android-nexec-client-demo/index.html [3] http://neko-daisuki.ddo.jp/~SumiTomohiko/android-nexec-client-demo/tutorial/python/index.html -- Tomohiko Sumi SumiTomohiko at neko-daisuki.ddo.jp http://neko-daisuki.ddo.jp/~SumiTomohiko/index.html From nikos.gr33k at gmail.com Wed Sep 25 08:45:16 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Wed, 25 Sep 2013 15:45:16 +0300 Subject: Referrer key missing form os.environ dictionary? Message-ID: Hello, i decided am ong other os.environ variables to also grab the 'HTTP_REFERER' fiel but when i try to run my script i was seeing a KeyError complaining that 'HTTP_REFERER' didnt exist. So, to see what existed in the os.environ dictionary i issues a print( os.environ ) to see all available keys and their values: environ({'SERVER_PORT': '80', 'REQUEST_URI': '/', 'HTTP_ACCEPT_ENCODING': 'gzip,deflate,sdch', 'SERVER_ADDR': '84.200.17.58', 'DOCUMENT_ROOT': '/home/nikos/public_html', 'HTTP_CONNECTION': 'keep-alive', 'SCRIPT_FILENAME': '/home/nikos/public_html/cgi-bin/metrites.py', 'SERVER_NAME': 'superhost.gr', 'REMOTE_PORT': '58896', 'HTTP_ACCEPT': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'HTTP_USER_AGENT': 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.2 Safari/537.36', 'HTTP_ACCEPT_LANGUAGE': 'en-US,en;q=0.8,el;q=0.6', 'GATEWAY_INTERFACE': 'CGI/1.1', 'HTTP_HOST': 'superhost.gr', 'REDIRECT_URL': '/index.html', 'SERVER_PROTOCOL': 'HTTP/1.1', 'SERVER_SIGNATURE': ' Apache/2.2.25 (Unix) mod_ssl/2.2.25 OpenSSL/1.0.0-fips mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 Server at superhost.gr Port 80 \n', 'HTTP_DNT': '1', 'REQUEST_METHOD': 'GET', 'QUERY_STRING': 'file=/home/nikos/public_html/index.html', 'PATH': '/sbin:/usr/sbin:/bin:/usr/bin', 'HTTP_COOKIE': 'cf_use_ob=0; __cfduid=da37079bb377f13e9c50224189ab46ac71379783691866; __utma=210786583.1207352568.1379497319.1380099225.1380108255.32; __utmc=210786583; __utmz=210786583.1379497319.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)', 'REMOTE_ADDR': '176.92.73.41', 'REDIRECT_QUERY_STRING': 'file=/home/nikos/public_html/index.html', 'SERVER_SOFTWARE': 'Apache/2.2.25 (Unix) mod_ssl/2.2.25 OpenSSL/1.0.0-fips mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635', 'SERVER_ADMIN': 'webmaster at superhost.gr', 'SCRIPT_NAME': '/cgi-bin/metrites.py', 'REDIRECT_STATUS': '200'}) i dont see anywhere a refferer key so to catch it in a variable sting like this: referrer = os.environ['HTTP_REFERER'] Do i miss something? its a suprise to me that the environ dictioanry has almost anythign but a referrer key. I need your help please. From nikos.gr33k at gmail.com Wed Sep 25 09:14:08 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Wed, 25 Sep 2013 16:14:08 +0300 Subject: Referrer key missing form os.environ dictionary? In-Reply-To: References: Message-ID: ???? 25/9/2013 3:45 ??, ?/? ????? ??????: > Hello, i decided am ong other os.environ variables to also grab the > 'HTTP_REFERER' fiel but when i try to run my script i was seeing a > KeyError complaining that 'HTTP_REFERER' didnt exist. > > So, to see what existed in the os.environ dictionary i issues a print( > os.environ ) to see all available keys and their values: > > environ({'SERVER_PORT': '80', 'REQUEST_URI': '/', > 'HTTP_ACCEPT_ENCODING': 'gzip,deflate,sdch', 'SERVER_ADDR': > '84.200.17.58', 'DOCUMENT_ROOT': '/home/nikos/public_html', > 'HTTP_CONNECTION': 'keep-alive', 'SCRIPT_FILENAME': > '/home/nikos/public_html/cgi-bin/metrites.py', 'SERVER_NAME': > 'superhost.gr', 'REMOTE_PORT': '58896', 'HTTP_ACCEPT': > 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', > 'HTTP_USER_AGENT': 'Mozilla/5.0 (Windows NT 6.2; WOW64) > AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.2 > Safari/537.36', 'HTTP_ACCEPT_LANGUAGE': 'en-US,en;q=0.8,el;q=0.6', > 'GATEWAY_INTERFACE': 'CGI/1.1', 'HTTP_HOST': 'superhost.gr', > 'REDIRECT_URL': '/index.html', 'SERVER_PROTOCOL': 'HTTP/1.1', > 'SERVER_SIGNATURE': ' > Apache/2.2.25 (Unix) mod_ssl/2.2.25 OpenSSL/1.0.0-fips > mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 Server > at superhost.gr Port 80 > \n', 'HTTP_DNT': '1', 'REQUEST_METHOD': 'GET', 'QUERY_STRING': > 'file=/home/nikos/public_html/index.html', 'PATH': > '/sbin:/usr/sbin:/bin:/usr/bin', 'HTTP_COOKIE': 'cf_use_ob=0; > __cfduid=da37079bb377f13e9c50224189ab46ac71379783691866; > __utma=210786583.1207352568.1379497319.1380099225.1380108255.32; > __utmc=210786583; > __utmz=210786583.1379497319.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)', > 'REMOTE_ADDR': '176.92.73.41', 'REDIRECT_QUERY_STRING': > 'file=/home/nikos/public_html/index.html', 'SERVER_SOFTWARE': > 'Apache/2.2.25 (Unix) mod_ssl/2.2.25 OpenSSL/1.0.0-fips > mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635', > 'SERVER_ADMIN': 'webmaster at superhost.gr', 'SCRIPT_NAME': > '/cgi-bin/metrites.py', 'REDIRECT_STATUS': '200'}) > > > i dont see anywhere a refferer key so to catch it in a variable sting > like this: > > referrer = os.environ['HTTP_REFERER'] > > Do i miss something? its a suprise to me that the environ dictioanry has > almost anythign but a referrer key. > > I need your help please. I also tried this: referer = os.environ.get('HTTP_REFERER', 'UnknownRef') but that doesn't return anythign either. From kwpolska at gmail.com Wed Sep 25 10:01:34 2013 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Wed, 25 Sep 2013 16:01:34 +0200 Subject: Referrer key missing form os.environ dictionary? In-Reply-To: References: Message-ID: On Wed, Sep 25, 2013 at 2:45 PM, ????? wrote: > Hello, i decided am ong other os.environ variables to also grab the > 'HTTP_REFERER' fiel but when i try to run my script i was seeing a KeyError > complaining that 'HTTP_REFERER' didnt exist. > > So, to see what existed in the os.environ dictionary i issues a print( > os.environ ) to see all available keys and their values: The Referer header is not mandatory by any means. Your client probably does not send it. -- Chris ?Kwpolska? Warrick PGP: 5EAAEA16 stop html mail | always bottom-post | only UTF-8 makes sense From nikos.gr33k at gmail.com Wed Sep 25 10:04:55 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Wed, 25 Sep 2013 17:04:55 +0300 Subject: Referrer key missing form os.environ dictionary? In-Reply-To: References: Message-ID: ???? 25/9/2013 5:01 ??, ?/? Chris ?Kwpolska? Warrick ??????: > On Wed, Sep 25, 2013 at 2:45 PM, ????? wrote: >> Hello, i decided am ong other os.environ variables to also grab the >> 'HTTP_REFERER' fiel but when i try to run my script i was seeing a KeyError >> complaining that 'HTTP_REFERER' didnt exist. >> >> So, to see what existed in the os.environ dictionary i issues a print( >> os.environ ) to see all available keys and their values: > > The Referer header is not mandatory by any means. Your client > probably does not send it. > I would like to check for its existence and retrieve it if possible, if its not there then default to the string "UnKnown Ref". I try to do this with: referer = os.environ.get('HTTP_REFERER', 'UnknownRef') but that doesn't return anything either. Can you verify that its the correct way to grab the referral string? From gordon at panix.com Wed Sep 25 10:26:23 2013 From: gordon at panix.com (John Gordon) Date: Wed, 25 Sep 2013 14:26:23 +0000 (UTC) Subject: Referrer key missing form os.environ dictionary? References: Message-ID: In =?UTF-8?B?zp3Or866zr/Pgg==?= writes: > referer = os.environ.get('HTTP_REFERER', 'UnknownRef') > but that doesn't return anything either. When you say it "doesn't return anything", what exactly do you mean? Does it return None? Does it raise KeyError? Something else? In any case, I'm surprised that doesn't work. That should be the correct way to do it. You could try this: try: referer = os.environ.get('HTTP_REFERER', 'UnknownRef') except KeyError: referer = None if not referer: referer = 'UnknownRef' -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From steve+comp.lang.python at pearwood.info Wed Sep 25 11:04:46 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Sep 2013 15:04:46 GMT Subject: Referrer key missing form os.environ dictionary? References: Message-ID: <5242fb8d$0$30000$c3e8da3$5496439d@news.astraweb.com> On Wed, 25 Sep 2013 14:26:23 +0000, John Gordon wrote: > You could try this: > > try: > referer = os.environ.get('HTTP_REFERER', 'UnknownRef') > except KeyError: > referer = None > if not referer: > referer = 'UnknownRef' The get method will not raise KeyError. If the key is missing, 'UnknownRef' will be returned instead. So when Nikos reports that os.environ.get('HTTP_REFERER', 'UnknownRef') "doesn't return anything", he is mistaken. It returns 'UnknownRef'. -- Steven From nikos.gr33k at gmail.com Wed Sep 25 11:16:39 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Wed, 25 Sep 2013 18:16:39 +0300 Subject: Referrer key missing form os.environ dictionary? In-Reply-To: <5242fb8d$0$30000$c3e8da3$5496439d@news.astraweb.com> References: <5242fb8d$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: ???? 25/9/2013 6:04 ??, ?/? Steven D'Aprano ??????: > On Wed, 25 Sep 2013 14:26:23 +0000, John Gordon wrote: > >> You could try this: >> >> try: >> referer = os.environ.get('HTTP_REFERER', 'UnknownRef') >> except KeyError: >> referer = None >> if not referer: >> referer = 'UnknownRef' > > The get method will not raise KeyError. If the key is missing, > 'UnknownRef' will be returned instead. > > So when Nikos reports that os.environ.get('HTTP_REFERER', 'UnknownRef') > "doesn't return anything", he is mistaken. It returns 'UnknownRef'. > > Not actually Steven, the referer key works well but it was the simlutaneous "host" issues that was giving me false understanding. now it works ok? So you say if the key is missign the get method wotn return an error but the default string instead. That is nice to hear. But answer me plz this: how caom the http_referer thing works ok now but when i just print all the key listing of .os.environ ket the http_referer key isnt inside? From python.list at tim.thechases.com Wed Sep 25 11:42:45 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 25 Sep 2013 10:42:45 -0500 Subject: Referrer key missing form os.environ dictionary? In-Reply-To: References: <5242fb8d$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20130925104245.6274ff0a@bigbox.christie.dr> On 2013-09-25 18:16, ????? wrote: > how caom the http_referer thing works ok now but when i just print > all the key listing of .os.environ ket the http_referer key isnt > inside? Well, first off, it's entirely possible (based on reading that paragraph) that you typed something wrong. That said, it depends on whether you're looking in your local environment, or the CGI environment provided by the server. As a simple example of what the server-side has/puts in your environment, you can use this CGI script: #!/usr/bin/env python import cgitb; cgitb.enable() import cgi import os import sys print "Content-Type: text/html\n\n" print """ Test CGI
""" for k,v in sorted(os.environ.items()): print "
%s
" % cgi.escape(k) print "
%s
" % cgi.escape(v) print """
""" Note that, if you go directly to the page, you shouldn't have a refer[r]er header, while if you arrive at it from some previous page, you might (modulo the aforementioned chicanery that plugins can induce) -tkc From denismfmcmahon at gmail.com Wed Sep 25 17:17:53 2013 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Wed, 25 Sep 2013 21:17:53 +0000 (UTC) Subject: Referrer key missing form os.environ dictionary? References: <5242fb8d$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, 25 Sep 2013 18:16:39 +0300, ????? wrote: > how caom the http_referer thing works ok now but when i just print all > the key listing of .os.environ ket the http_referer key isnt inside? That you do not understand this is caused by your failure to understand the HTTP protocol. You have been told before, this NG is not networking and / or tcp/ip and / or internet protocols 101. Please go and learn about the network protocols you're trying to interact with before you start writing code that interacts with them. The issue you are raising here is not a python issue, it is a network protocols issue that has nothing whatsoever to do with python. -- Denis McMahon, denismfmcmahon at gmail.com From ned at nedbatchelder.com Wed Sep 25 11:09:02 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 25 Sep 2013 11:09:02 -0400 Subject: Referrer key missing form os.environ dictionary? In-Reply-To: References: Message-ID: <5242FC8E.4090800@nedbatchelder.com> On 9/25/13 10:26 AM, John Gordon wrote: > You could try this: > > try: > referer = os.environ.get('HTTP_REFERER', 'UnknownRef') > except KeyError: > referer = None > > if not referer: > referer = 'UnknownRef' There's no need for the "except KeyError" clause. dict.get never raises KeyError, this code will assign 'UnknownRef' in the case the environment variable is missing. --Ned. From steve+comp.lang.python at pearwood.info Wed Sep 25 10:52:45 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Sep 2013 14:52:45 GMT Subject: Referrer key missing form os.environ dictionary? References: Message-ID: <5242f8bc$0$30000$c3e8da3$5496439d@news.astraweb.com> On Wed, 25 Sep 2013 17:04:55 +0300, ????? wrote: > I would like to check for its existence and retrieve it if possible, if > its not there then default to the string "UnKnown Ref". > > I try to do this with: > > referer = os.environ.get('HTTP_REFERER', 'UnknownRef') > > but that doesn't return anything either. > > Can you verify that its the correct way to grab the referral string? The Referer is not an environment variable. How would your shell know what URL you were just browsing? Have you googled for HTTP Referer? Do you understand what it is? -- Steven From nikos.gr33k at gmail.com Wed Sep 25 11:02:45 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Wed, 25 Sep 2013 18:02:45 +0300 Subject: Referrer key missing form os.environ dictionary? In-Reply-To: <5242f8bc$0$30000$c3e8da3$5496439d@news.astraweb.com> References: <5242f8bc$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: ???? 25/9/2013 5:52 ??, ?/? Steven D'Aprano ??????: > On Wed, 25 Sep 2013 17:04:55 +0300, ????? wrote: > >> I would like to check for its existence and retrieve it if possible, if >> its not there then default to the string "UnKnown Ref". >> >> I try to do this with: >> >> referer = os.environ.get('HTTP_REFERER', 'UnknownRef') >> >> but that doesn't return anything either. >> >> Can you verify that its the correct way to grab the referral string? > > > The Referer is not an environment variable. How would your shell know > what URL you were just browsing? > > Have you googled for HTTP Referer? Do you understand what it is? > > Yes Steven googleign for 2 hours now. You were rigth about the carret it was a synatx error above which i missed and i was breakign my head to the wall to understand what was wot with the 'host' variable. why python doestn detect the exact synxtax error and ispoitnign to me to another line making me think the error is elsewhere? This indeed works now: ref = os.environ.get('HTTP_REFERER', '??????? Ref') but iam wondering why this doesnt work also: ref = os.environ('HTTP_REFERER') Shouldnt both work? From urtizvereaxaxa at gmail.com Wed Sep 25 11:09:50 2013 From: urtizvereaxaxa at gmail.com (Xaxa Urtiz) Date: Wed, 25 Sep 2013 08:09:50 -0700 (PDT) Subject: Referrer key missing form os.environ dictionary? In-Reply-To: References: <5242f8bc$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: Le mercredi 25 septembre 2013 17:02:45 UTC+2, Ferrous Cranus a ?crit?: > ???? 25/9/2013 5:52 ??, ?/? Steven D'Aprano ??????: > > > On Wed, 25 Sep 2013 17:04:55 +0300, ????? wrote: > > > > > >> I would like to check for its existence and retrieve it if possible, if > > >> its not there then default to the string "UnKnown Ref". > > >> > > >> I try to do this with: > > >> > > >> referer = os.environ.get('HTTP_REFERER', 'UnknownRef') > > >> > > >> but that doesn't return anything either. > > >> > > >> Can you verify that its the correct way to grab the referral string? > > > > > > > > > The Referer is not an environment variable. How would your shell know > > > what URL you were just browsing? > > > > > > Have you googled for HTTP Referer? Do you understand what it is? > > > > > > > > Yes Steven googleign for 2 hours now. > > > > You were rigth about the carret it was a synatx error above which i > > missed and i was breakign my head to the wall to understand what was wot > > with the 'host' variable. why python doestn detect the exact synxtax > > error and ispoitnign to me to another line making me think the error is > > elsewhere? > > > > This indeed works now: > > > > ref = os.environ.get('HTTP_REFERER', '??????? Ref') > > > > but iam wondering why this doesnt work also: > > > > ref = os.environ('HTTP_REFERER') > > > > Shouldnt both work? http://www.tutorialspoint.com/python/dictionary_get.htm From python.list at tim.thechases.com Wed Sep 25 11:14:50 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 25 Sep 2013 10:14:50 -0500 Subject: Referrer key missing form os.environ dictionary? In-Reply-To: References: <5242f8bc$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20130925101450.0a3fa16c@bigbox.christie.dr> On 2013-09-25 18:02, ????? wrote: > This indeed works now: > > ref = os.environ.get('HTTP_REFERER', '??????? Ref') > > but iam wondering why this doesnt work also: > > ref = os.environ('HTTP_REFERER') > > Shouldnt both work? No...that calls os.environ. You likely *mean* ref = os.environ['HTTP_REFERER'] using square brackets. However, as previously noted by multiple respondents, this header is not guaranteed to be sent by the browser for a variety of reasons, so it may not be in the environment dictionary at all. Thus you are likely to get KeyError exceptions if you don't use .get() unless you wrap it in a check: if "HTTP_REFERER" in os.environ: ref = os.environ["HTTP_REFERER"] else: deal_with_this_situation() -tkc From nikos.gr33k at gmail.com Wed Sep 25 11:35:03 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Wed, 25 Sep 2013 18:35:03 +0300 Subject: Referrer key missing form os.environ dictionary? In-Reply-To: References: <5242f8bc$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: ???? 25/9/2013 6:14 ??, ?/? Tim Chase ??????: > On 2013-09-25 18:02, ????? wrote: >> This indeed works now: >> >> ref = os.environ.get('HTTP_REFERER', '??????? Ref') >> >> but iam wondering why this doesnt work also: >> >> ref = os.environ('HTTP_REFERER') >> >> Shouldnt both work? > > No...that calls os.environ. You likely *mean* > > ref = os.environ['HTTP_REFERER'] > > using square brackets. However, as previously noted by multiple > respondents, this header is not guaranteed to be sent by the browser > for a variety of reasons, so it may not be in the environment > dictionary at all. Thus you are likely to get KeyError exceptions if > you don't use .get() unless you wrap it in a check: > > if "HTTP_REFERER" in os.environ: > ref = os.environ["HTTP_REFERER"] > else: > deal_with_this_situation() Thank you very much for the clarification. I just wanted to know the differecne between the 2 ways of using the HTTP_REFERER. From invalid at invalid.invalid Wed Sep 25 11:18:41 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 25 Sep 2013 15:18:41 +0000 (UTC) Subject: Referrer key missing form os.environ dictionary? References: <5242f8bc$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-09-25, Steven D'Aprano wrote: > On Wed, 25 Sep 2013 17:04:55 +0300, ?????????? wrote: > >> I would like to check for its existence and retrieve it if possible, if >> its not there then default to the string "UnKnown Ref". >> >> I try to do this with: >> >> referer = os.environ.get('HTTP_REFERER', 'UnknownRef') >> >> but that doesn't return anything either. And of course that's bolloks: Python 2.7.5 (default, Aug 29 2013, 15:13:35) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.environ.get('HTTP_REFERER','UnkownRef') 'UnkownRef' >>> Python 3.2.5 (default, Aug 29 2013, 15:19:46) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.environ.get('HTTP_REFERER','UnkownRef') 'UnkownRef' >>> >> Can you verify that its the correct way to grab the referral string? It is. > The Referer is not an environment variable. It is when you're writing a CGI app. > How would your shell know what URL you were just browsing? Because the HTTP server sets those environment variables before invoking the CGI app. -- Grant Edwards grant.b.edwards Yow! Boy, am I glad it's at only 1971... gmail.com From nikos.gr33k at gmail.com Wed Sep 25 11:41:37 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Wed, 25 Sep 2013 18:41:37 +0300 Subject: Referrer key missing form os.environ dictionary? In-Reply-To: References: <5242f8bc$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: ???? 25/9/2013 6:18 ??, ?/? Grant Edwards ??????: > On 2013-09-25, Steven D'Aprano wrote: >> On Wed, 25 Sep 2013 17:04:55 +0300, ?????????? wrote: >> >>> I would like to check for its existence and retrieve it if possible, if >>> its not there then default to the string "UnKnown Ref". >>> >>> I try to do this with: >>> >>> referer = os.environ.get('HTTP_REFERER', 'UnknownRef') >>> >>> but that doesn't return anything either. > > And of course that's bolloks: > > Python 2.7.5 (default, Aug 29 2013, 15:13:35) > [GCC 4.6.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import os > >>> os.environ.get('HTTP_REFERER','UnkownRef') > 'UnkownRef' > >>> > > Python 3.2.5 (default, Aug 29 2013, 15:19:46) > [GCC 4.6.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import os > >>> os.environ.get('HTTP_REFERER','UnkownRef') > 'UnkownRef' > >>> > >>> Can you verify that its the correct way to grab the referral string? > > It is. > >> The Referer is not an environment variable. > > It is when you're writing a CGI app. > >> How would your shell know what URL you were just browsing? > > Because the HTTP server sets those environment variables before > invoking the CGI app. > So you mean that even if i run it via shell this stement will also work because it happens to be in the same enviroment with the HTTP server? No need to run it via web browser and check the Apache's error log? From gordon at panix.com Wed Sep 25 12:27:23 2013 From: gordon at panix.com (John Gordon) Date: Wed, 25 Sep 2013 16:27:23 +0000 (UTC) Subject: Referrer key missing form os.environ dictionary? References: <5242f8bc$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: In =?UTF-8?B?zp3Or866zr/Pgg==?= writes: > So you mean that even if i run it via shell this stement will also work > because it happens to be in the same enviroment with the HTTP server? No. Each process has its own environment. Your shell's environment knows nothing about the web server's environment. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From invalid at invalid.invalid Wed Sep 25 14:37:27 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 25 Sep 2013 18:37:27 +0000 (UTC) Subject: Referrer key missing form os.environ dictionary? References: <5242f8bc$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-09-25, ?????????? wrote: > ???????? 25/9/2013 6:18 ????, ??/?? Grant Edwards ????????????: >>> The Referer is not an environment variable. >> >> It is when you're writing a CGI app. >> >>> How would your shell know what URL you were just browsing? >> >> Because the HTTP server sets those environment variables before >> invoking the CGI app. > > So you mean that even if i run it via shell this stement will also > work If the shell was started by the HTTP server, yes. If you logged in normally, no. > because it happens to be in the same enviroment with the HTTP server? The shell will only have that environment if the shell was run by the HTTP server. > No need to run it via web browser and check the Apache's error log? You can set the environemnt variables appropriately in the shell and then invoke a CGI application directly for testing purposes. -- Grant Edwards grant.b.edwards Yow! I was born in a at Hostess Cupcake factory gmail.com before the sexual revolution! From steve+comp.lang.python at pearwood.info Wed Sep 25 20:11:55 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Sep 2013 00:11:55 GMT Subject: Referrer key missing form os.environ dictionary? References: <5242f8bc$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52437bca$0$30000$c3e8da3$5496439d@news.astraweb.com> On Wed, 25 Sep 2013 15:18:41 +0000, Grant Edwards wrote: >> The Referer is not an environment variable. > > It is when you're writing a CGI app. > >> How would your shell know what URL you were just browsing? > > Because the HTTP server sets those environment variables before invoking > the CGI app. I stand corrected. That's a pretty shitty design though, isn't it? Communicating via environment variables. What is this, 1998? :-) Mind you, I'm not sure what other alternatives exist. -- Steven From tjreedy at udel.edu Wed Sep 25 21:32:49 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 25 Sep 2013 21:32:49 -0400 Subject: Referrer key missing form os.environ dictionary? In-Reply-To: <52437bca$0$30000$c3e8da3$5496439d@news.astraweb.com> References: <5242f8bc$0$30000$c3e8da3$5496439d@news.astraweb.com> <52437bca$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 9/25/2013 8:11 PM, Steven D'Aprano wrote: > On Wed, 25 Sep 2013 15:18:41 +0000, Grant Edwards wrote: > >>> The Referer is not an environment variable. >> >> It is when you're writing a CGI app. >> >>> How would your shell know what URL you were just browsing? >> >> Because the HTTP server sets those environment variables before invoking >> the CGI app. > > > I stand corrected. > > > That's a pretty shitty design though, isn't it? Communicating via > environment variables. What is this, 1998? :-) 1993 https://en.wikipedia.org/wiki/Common_Gateway_Interface > Mind you, I'm not sure what other alternatives exist. Send a series of lines with the same info over an input channel, as was done 3 years later for FastCGI. Since CGI uses stdout for the finished product, it could have used stdin for the input. Using a serial channel does put more burden on the page server to parse the input. But is allows it to be on a different machine. -- Terry Jan Reedy From rosuav at gmail.com Wed Sep 25 23:25:48 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 Sep 2013 13:25:48 +1000 Subject: Referrer key missing form os.environ dictionary? In-Reply-To: References: <5242f8bc$0$30000$c3e8da3$5496439d@news.astraweb.com> <52437bca$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Sep 26, 2013 at 11:32 AM, Terry Reedy wrote: > Since CGI uses stdout for the finished product, it could have used stdin for > the input. Haven't used CGI in years, but I thought POST data came on stdin? ChrisA From robert.kern at gmail.com Thu Sep 26 06:15:40 2013 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 26 Sep 2013 11:15:40 +0100 Subject: Referrer key missing form os.environ dictionary? In-Reply-To: References: <5242f8bc$0$30000$c3e8da3$5496439d@news.astraweb.com> <52437bca$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-09-26 04:25, Chris Angelico wrote: > On Thu, Sep 26, 2013 at 11:32 AM, Terry Reedy wrote: >> Since CGI uses stdout for the finished product, it could have used stdin for >> the input. > > Haven't used CGI in years, but I thought POST data came on stdin? You could just put the whole HTTP request, headers and body, through stdin and just make the program parse them apart. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From invalid at invalid.invalid Thu Sep 26 10:16:08 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 26 Sep 2013 14:16:08 +0000 (UTC) Subject: Referrer key missing form os.environ dictionary? References: <5242f8bc$0$30000$c3e8da3$5496439d@news.astraweb.com> <52437bca$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-09-26, Chris Angelico wrote: > On Thu, Sep 26, 2013 at 11:32 AM, Terry Reedy wrote: >> Since CGI uses stdout for the finished product, it could have used stdin for >> the input. > > Haven't used CGI in years, but I thought POST data came on stdin? Yes. The user data is read via stdin. The stuff passed via the environemnt "dictionary" is meta-data (stuff from the HTTP request headers, and stuff synthesized by the HTTP server). -- Grant Edwards grant.b.edwards Yow! ! Now I understand at advanced MICROBIOLOGY and gmail.com th' new TAX REFORM laws!! From invalid at invalid.invalid Thu Sep 26 10:11:57 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 26 Sep 2013 14:11:57 +0000 (UTC) Subject: Referrer key missing form os.environ dictionary? References: <5242f8bc$0$30000$c3e8da3$5496439d@news.astraweb.com> <52437bca$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-09-26, Steven D'Aprano wrote: > On Wed, 25 Sep 2013 15:18:41 +0000, Grant Edwards wrote: > >>> The Referer is not an environment variable. >> >> It is when you're writing a CGI app. >> >>> How would your shell know what URL you were just browsing? >> >> Because the HTTP server sets those environment variables before invoking >> the CGI app. > > I stand corrected. > > That's a pretty shitty design though, isn't it? On a Unix system when you invoke a program, you "pass" it four things: 1) A dictionary where keys/values are both strings [enviornment variables] 2) A list of strings [command line args] 3) A set of open file descriptors. 4) The current working directory. You can provide input values to the program through any of these. For interactive programs, 2 and 3 are the most convenient. For programs intended to be invoked non-interactively via another program the first option can be very elegent and versatile -- but it does make use of the program interactively rather awkward. Semantically, passing values to a program via environment variables is very similar to keyword arguments to a Python function, while command line arguments are like positional arguments to a Python function. > Communicating via environment variables. What is this, 1998? :-) > > Mind you, I'm not sure what other alternatives exist. Command line arguments, open file descriptors, or files in the CWD. All are more difficult to use programmatically than environment variables. -- Grant Edwards grant.b.edwards Yow! I guess you guys got at BIG MUSCLES from doing too gmail.com much STUDYING! From rosuav at gmail.com Thu Sep 26 11:17:14 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 27 Sep 2013 01:17:14 +1000 Subject: Referrer key missing form os.environ dictionary? In-Reply-To: References: <5242f8bc$0$30000$c3e8da3$5496439d@news.astraweb.com> <52437bca$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Sep 27, 2013 at 12:11 AM, Grant Edwards wrote: > On a Unix system when you invoke a program, you "pass" it four things: > > 1) A dictionary where keys/values are both strings [enviornment variables] > 2) A list of strings [command line args] > 3) A set of open file descriptors. > 4) The current working directory. > > You can provide input values to the program through any of these. > > For interactive programs, 2 and 3 are the most convenient. Hrm, not sure about #3 for interactive programs, unless you specifically mean the three standard streams. With most Unix shells, you should be able to set environment variables: PGUSER=fred PGPASSWORD=secret psql Not as convenient as #2, but far easier than passing an open file descriptor. Of course, passing file descriptors around is pretty easy programmatically, but when you say "interactive" I assume you're talking also about an interactive shell. GUI interactions of course follow their own rules completely. In most systems, it's really easy to invoke an application with one argument, a file name; it's generally much harder to customize the arguments at the keyboard. OS/2 had a facility for doing that. You just put square brackets into the configured args and it'd turn it into a prompt: --foo=bar --mode=[Choose mode, 1-3:] %* You'd get a nice little popup with the prompt you specified, and whatever you type gets put into the args. Haven't seen that in any other system - at least, not as conveniently. ChrisA From invalid at invalid.invalid Thu Sep 26 19:27:10 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 26 Sep 2013 23:27:10 +0000 (UTC) Subject: Referrer key missing form os.environ dictionary? References: <5242f8bc$0$30000$c3e8da3$5496439d@news.astraweb.com> <52437bca$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-09-26, Chris Angelico wrote: > On Fri, Sep 27, 2013 at 12:11 AM, Grant Edwards wrote: >> On a Unix system when you invoke a program, you "pass" it four things: >> >> 1) A dictionary where keys/values are both strings [enviornment variables] >> 2) A list of strings [command line args] >> 3) A set of open file descriptors. >> 4) The current working directory. >> >> You can provide input values to the program through any of these. >> >> For interactive programs, 2 and 3 are the most convenient. > > Hrm, not sure about #3 for interactive programs, unless you > specifically mean the three standard streams. Yes, that's what I mean: shell redirection/pipelines. Hooking stuff to stdin is pretty much the only example of this you'll ever see in the wild for input data: foo < inputdata bar | foo foo < With most Unix shells, you should be able to set environment > variables: > > PGUSER=fred PGPASSWORD=secret psql Yep, that's rather rarely used. The syntax/sematics for values passed that way is very limited compared to the syntax/semantics that can be used for command line arguments, so the latter is much more versatile. > Not as convenient as #2, but far easier than passing an open file > descriptor. Of course, passing file descriptors around is pretty easy > programmatically, but when you say "interactive" I assume you're > talking also about an interactive shell. I probably should have said "stdin", but in theory you can pass data in via multiple file descriptors. Nobody does that except people cooking up obscure examples for advanced shell scripting guides... > GUI interactions of course follow their own rules completely. In most > systems, it's really easy to invoke an application with one argument, > a file name; it's generally much harder to customize the arguments at > the keyboard. OS/2 had a facility for doing that. You just put square > brackets into the configured args and it'd turn it into a prompt: > > --foo=bar --mode=[Choose mode, 1-3:] %* > > You'd get a nice little popup with the prompt you specified, and > whatever you type gets put into the args. Haven't seen that in any > other system - at least, not as conveniently. -- Grant Edwards grant.b.edwards Yow! I request a weekend in at Havana with Phil Silvers! gmail.com From rosuav at gmail.com Fri Sep 27 02:01:52 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 27 Sep 2013 16:01:52 +1000 Subject: Referrer key missing form os.environ dictionary? In-Reply-To: References: <5242f8bc$0$30000$c3e8da3$5496439d@news.astraweb.com> <52437bca$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Sep 27, 2013 at 9:27 AM, Grant Edwards wrote: > I probably should have said "stdin", but in theory you can pass data > in via multiple file descriptors. Nobody does that except people > cooking up obscure examples for advanced shell scripting guides... Yep. With that variant, I agree that it's more common than env vars (apart from standard ones - *heaps* of programs are affected by stuff like LANG or HOME or PATH, but they're not passed at the command line); what your description put me in mind of, though, was the special handling sometimes done between two programs, like when the Unix program loader finds a #! and exec's an interpreter to process the script - for security, it has to pass the fd, not the file name, to the interpreter. But that's really esoteric! Of course, whenever you fork without execing (execking?), you can pass (or share) file descriptors easily. Very common, but not exactly command-line stuff. ChrisA From nikos.gr33k at gmail.com Wed Sep 25 10:07:38 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Wed, 25 Sep 2013 17:07:38 +0300 Subject: Referrer key missing form os.environ dictionary? In-Reply-To: References: Message-ID: ???? 25/9/2013 5:01 ??, ?/? Chris ?Kwpolska? Warrick ??????: > On Wed, Sep 25, 2013 at 2:45 PM, ????? wrote: >> Hello, i decided am ong other os.environ variables to also grab the >> 'HTTP_REFERER' fiel but when i try to run my script i was seeing a KeyError >> complaining that 'HTTP_REFERER' didnt exist. >> >> So, to see what existed in the os.environ dictionary i issues a print( >> os.environ ) to see all available keys and their values: > > The Referer header is not mandatory by any means. Your client > probably does not send it. > But one other problem appeared too: nikos at superhost.gr [~/www/cgi-bin]# python metrites.py File "metrites.py", line 27 host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or 'UnKnown Host' ^ SyntaxError: invalid syntax i dont see anything wrong with that line, and the carret is actually pointing to the "host". From robert.kern at gmail.com Wed Sep 25 10:26:50 2013 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 25 Sep 2013 15:26:50 +0100 Subject: Referrer key missing form os.environ dictionary? In-Reply-To: References: Message-ID: On 2013-09-25 15:07, ????? wrote: > ???? 25/9/2013 5:01 ??, ?/? Chris ?Kwpolska? Warrick ??????: >> On Wed, Sep 25, 2013 at 2:45 PM, ????? wrote: >>> Hello, i decided am ong other os.environ variables to also grab the >>> 'HTTP_REFERER' fiel but when i try to run my script i was seeing a KeyError >>> complaining that 'HTTP_REFERER' didnt exist. >>> >>> So, to see what existed in the os.environ dictionary i issues a print( >>> os.environ ) to see all available keys and their values: >> >> The Referer header is not mandatory by any means. Your client >> probably does not send it. >> > But one other problem appeared too: > > nikos at superhost.gr [~/www/cgi-bin]# python metrites.py > File "metrites.py", line 27 > host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or 'UnKnown Host' > ^ > SyntaxError: invalid syntax > > > i dont see anything wrong with that line, and the carret is actually pointing to > the "host". As has been explained to you before, SyntaxErrors just point to the place where the parser saw something unexpected, not the exact point where you made the error. It is not omniscient. If you don't see the problem on the reported line, you have probably left off a closing bracket or something similar in a previous line. Look back a few lines. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From gordon at panix.com Wed Sep 25 10:30:59 2013 From: gordon at panix.com (John Gordon) Date: Wed, 25 Sep 2013 14:30:59 +0000 (UTC) Subject: Referrer key missing form os.environ dictionary? References: Message-ID: In =?UTF-8?B?zp3Or866zr/Pgg==?= writes: > But one other problem appeared too: > nikos at superhost.gr [~/www/cgi-bin]# python metrites.py > File "metrites.py", line 27 > host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or > 'UnKnown Host' > ^ > SyntaxError: invalid syntax > i dont see anything wrong with that line, and the carret is actually > pointing to the "host". Your post has the code broken up into two separate lines. Is that how the code actually appears? If so, then that's the problem. You can't arbitrarily break a statement into separate lines. If not, then you'll have to post more of the code; the problem isn't on this line. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From steve+comp.lang.python at pearwood.info Wed Sep 25 10:46:15 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Sep 2013 14:46:15 GMT Subject: Referrer key missing form os.environ dictionary? References: Message-ID: <5242f736$0$30000$c3e8da3$5496439d@news.astraweb.com> On Wed, 25 Sep 2013 17:07:38 +0300, ????? wrote: > nikos at superhost.gr [~/www/cgi-bin]# python metrites.py > File "metrites.py", line 27 > host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or > 'UnKnown Host' > ^ > SyntaxError: invalid syntax > > > i dont see anything wrong with that line, and the carret is actually > pointing to the "host". If the caret is pointing to "host", then the syntax error isn't discovered until that point. That means the actual syntax error occurs before that point, probably on the previous line. How long have you been doing web development with Python? Six months? A year? You're not a beginner any more. If you can't solve syntax errors by yourself by now, it's probably time to give up and find a job more suited to your skills. -- Steven From piet at vanoostrum.org Wed Sep 25 15:59:56 2013 From: piet at vanoostrum.org (Piet van Oostrum) Date: Wed, 25 Sep 2013 15:59:56 -0400 Subject: Referrer key missing form os.environ dictionary? References: Message-ID: ????? writes: > ???? 25/9/2013 5:01 ??, ?/? Chris ?Kwpolska? Warrick ??????: >> On Wed, Sep 25, 2013 at 2:45 PM, ????? wrote: >>> Hello, i decided am ong other os.environ variables to also grab the >>> 'HTTP_REFERER' fiel but when i try to run my script i was seeing a KeyError >>> complaining that 'HTTP_REFERER' didnt exist. >>> >>> So, to see what existed in the os.environ dictionary i issues a print( >>> os.environ ) to see all available keys and their values: >> >> The Referer header is not mandatory by any means. Your client >> probably does not send it. >> > But one other problem appeared too: > > nikos at superhost.gr [~/www/cgi-bin]# python metrites.py > File "metrites.py", line 27 > host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or > UnKnown Host' > ^ > SyntaxError: invalid syntax > > > i dont see anything wrong with that line, and the carret is actually > pointing to the "host". There is an apostrophe (') missing before UnKnown. host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or 'UnKnown Host' -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From gordon at panix.com Wed Sep 25 10:18:24 2013 From: gordon at panix.com (John Gordon) Date: Wed, 25 Sep 2013 14:18:24 +0000 (UTC) Subject: Referrer key missing form os.environ dictionary? References: Message-ID: In =?UTF-8?B?zp3Or866zr/Pgg==?= writes: > referrer = os.environ['HTTP_REFERER'] > Do i miss something? its a suprise to me that the environ dictioanry has > almost anythign but a referrer key. HTTP_REFERER is used to indicate the URL containing the link that led the user to the current URL. So for example if the user is viewing foo.html and then clicks a link on that page which leads to bar.html, the HTTP_REFERER for that request would be foo.html. However, if the user did not arrive from another page, then HTTP_REFERER will be missing. This happens when the user types the web address directly into their browser, or clicks on a bookmark, or many other ways. Also, obviously, it's up to the browser to truthfully report HTTP_REFERER; the server itself has no idea what page you were on previously. What browser are you using? -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From python.list at tim.thechases.com Wed Sep 25 10:58:07 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 25 Sep 2013 09:58:07 -0500 Subject: Referrer key missing form os.environ dictionary? In-Reply-To: References: Message-ID: <20130925095807.749d64a5@bigbox.christie.dr> On 2013-09-25 14:18, John Gordon wrote: > However, if the user did not arrive from another page, then > HTTP_REFERER will be missing. This happens when the user types the > web address directly into their browser, or clicks on a bookmark, > or many other ways. > > Also, obviously, it's up to the browser to truthfully report > HTTP_REFERER; There are browser plugins that allow blocking or manually-overriding the outbound refer[r]er header which help mitigate data leakage such as search-engine query strings or work around website limitations. So server-side code should always assume that the HTTP_REFERER header can be absent or easily be spoofed, treating it as a hint, not absolute truth. -tkc From nilsbunger at gmail.com Wed Sep 25 12:38:17 2013 From: nilsbunger at gmail.com (nilsbunger at gmail.com) Date: Wed, 25 Sep 2013 09:38:17 -0700 (PDT) Subject: Newline interpretation issue with MIMEApplication with binary data, Python 3.3.2 Message-ID: <14063249-6159-48ff-bfe2-8e8d6e3cd7a4@googlegroups.com> Hi, I'm having trouble encoding a MIME message with a binary file. Newline characters are being interpreted even though the content is supposed to be binary. This is using Python 3.3.2 Small test case: app = MIMEApplication(b'Q\x0dQ', _encoder=encode_noop) b = io.BytesIO() g = BytesGenerator(b) g.flatten(app) for i in b.getvalue()[-3:]: print ("%02x " % i, end="") print () This prints 51 0a 51, meaning the 0x0d character got reinterpreted as a newline. I've tried setting an email policy of HTTP policy, but that goes even further, converting \r to \r\n This is for HTTP transport, so binary encoding is normal. Any thoughts how I can do this properly? From rosuav at gmail.com Thu Sep 26 00:11:31 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 Sep 2013 14:11:31 +1000 Subject: Newline interpretation issue with MIMEApplication with binary data, Python 3.3.2 In-Reply-To: <14063249-6159-48ff-bfe2-8e8d6e3cd7a4@googlegroups.com> References: <14063249-6159-48ff-bfe2-8e8d6e3cd7a4@googlegroups.com> Message-ID: On Thu, Sep 26, 2013 at 2:38 AM, wrote: > app = MIMEApplication(b'Q\x0dQ', _encoder=encode_noop) What is MIMEApplication? It's not a builtin, so your test case is missing an import, at least. Is this email.mime.MIMEApplication? ChrisA From nilsbunger at gmail.com Thu Sep 26 00:23:21 2013 From: nilsbunger at gmail.com (Nils Bunger) Date: Wed, 25 Sep 2013 21:23:21 -0700 (PDT) Subject: Newline interpretation issue with MIMEApplication with binary data, Python 3.3.2 In-Reply-To: References: <14063249-6159-48ff-bfe2-8e8d6e3cd7a4@googlegroups.com> Message-ID: <870d6a97-613d-401f-ad03-0bbd3b088538@googlegroups.com> Chris, Thanks for answering. Yes, it's email.mime.MIMEApplication. I've pasted a snippet with the imports below. I'm trying to use this to build a multi-part MIME message, with this as one part. I really can't figure out any way to attach a binary part like this to a multi-part MIME message without the encoding issue... any help would be greatly appreciate! Nils --------- import io from email.mime.application import MIMEApplication from email.generator import BytesGenerator from email.encoders import encode_noop app = MIMEApplication(b'Q\x0dQ', _encoder=encode_noop) b = io.BytesIO() g = BytesGenerator(b) g.flatten(app) for i in b.getvalue()[-3:]: print("%02x " % i, end="") print() On Wednesday, September 25, 2013 9:11:31 PM UTC-7, Chris Angelico wrote: > On Thu, Sep 26, 2013 at 2:38 AM, wrote: > > > app = MIMEApplication(b'Q\x0dQ', _encoder=encode_noop) > > > > What is MIMEApplication? It's not a builtin, so your test case is > > missing an import, at least. Is this email.mime.MIMEApplication? > > > > ChrisA From rosuav at gmail.com Thu Sep 26 00:32:21 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 Sep 2013 14:32:21 +1000 Subject: Newline interpretation issue with MIMEApplication with binary data, Python 3.3.2 In-Reply-To: <870d6a97-613d-401f-ad03-0bbd3b088538@googlegroups.com> References: <14063249-6159-48ff-bfe2-8e8d6e3cd7a4@googlegroups.com> <870d6a97-613d-401f-ad03-0bbd3b088538@googlegroups.com> Message-ID: On Thu, Sep 26, 2013 at 2:23 PM, Nils Bunger wrote: > Yes, it's email.mime.MIMEApplication. I've pasted a snippet with the imports below. > > I'm trying to use this to build a multi-part MIME message, with this as one part. > > I really can't figure out any way to attach a binary part like this to a multi-part MIME message without the encoding issue... any help would be greatly appreciate! I partly responded just to ping your thread, as I'm not particularly familiar with the email.mime module. But a glance at the docs suggests that MIMEApplication is a "subclass of MIMENonMultipart", so might it be a problem to use that for multipart?? It's designed to handle text, so you may want to use an encoder (like the default base64 one) rather than trying to push binary data through it. Random ideas, hopefully someone who actually knows the module can respond. ChrisA From neilc at norwich.edu Thu Sep 26 09:41:52 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 26 Sep 2013 13:41:52 GMT Subject: Newline interpretation issue with MIMEApplication with binary data, Python 3.3.2 References: <14063249-6159-48ff-bfe2-8e8d6e3cd7a4@googlegroups.com> <870d6a97-613d-401f-ad03-0bbd3b088538@googlegroups.com> Message-ID: On 2013-09-26, Chris Angelico wrote: > On Thu, Sep 26, 2013 at 2:23 PM, Nils Bunger wrote: >> Yes, it's email.mime.MIMEApplication. I've pasted a snippet >> with the imports below. >> >> I'm trying to use this to build a multi-part MIME message, >> with this as one part. >> >> I really can't figure out any way to attach a binary part like >> this to a multi-part MIME message without the encoding >> issue... any help would be greatly appreciate! > > I partly responded just to ping your thread, as I'm not > particularly familiar with the email.mime module. But a glance > at the docs suggests that MIMEApplication is a "subclass of > MIMENonMultipart", so might it be a problem to use that for > multipart?? > > It's designed to handle text, so you may want to use an encoder > (like the default base64 one) rather than trying to push binary > data through it. > > Random ideas, hopefully someone who actually knows the module > can respond. I got interested in it since I have never used any of the modules. So I played with it enough to discover that the part of the code above that converts the \r to \n is the flatten call. I got to here and RFC 2049 and gave up. The following guidelines may be useful to anyone devising a data format (media type) that is supposed to survive the widest range of networking technologies and known broken MTAs unscathed. Note that anything encoded in the base64 encoding will satisfy these rules, but that some well-known mechanisms, notably the UNIX uuencode facility, will not. Note also that anything encoded in the Quoted-Printable encoding will survive most gateways intact, but possibly not some gateways to systems that use the EBCDIC character set. (1) Under some circumstances the encoding used for data may change as part of normal gateway or user agent operation. In particular, conversion from base64 to quoted-printable and vice versa may be necessary. This may result in the confusion of CRLF sequences with line breaks in text bodies. As such, the persistence of CRLF as something other than a line break must not be relied on. (2) Many systems may elect to represent and store text data using local newline conventions. Local newline conventions may not match the RFC822 CRLF convention -- systems are known that use plain CR, plain LF, CRLF, or counted records. The result is that isolated CR and LF characters are not well tolerated in general; they may be lost or converted to delimiters on some systems, and hence must not be relied on. So putting a raw CR in a binary chunk maybe be intolerable, and you need to use a different encoder. But I'm out of my element. -- Neil Cerutti From nilsbunger at gmail.com Thu Sep 26 11:56:38 2013 From: nilsbunger at gmail.com (Nils Bunger) Date: Thu, 26 Sep 2013 08:56:38 -0700 (PDT) Subject: Newline interpretation issue with MIMEApplication with binary data, Python 3.3.2 In-Reply-To: References: <14063249-6159-48ff-bfe2-8e8d6e3cd7a4@googlegroups.com> <870d6a97-613d-401f-ad03-0bbd3b088538@googlegroups.com> Message-ID: Hi Neil, Thanks for looking at this. I'm trying to create a multipart MIME for an HTTP POST request, not an email. This is for a third-party API that requires a multipart POST with a binary file, so I don't have the option to just use a different encoding. Multipart HTTP is standardized in HTTP 1.0 and supports binary parts. Also, no one will re-interpret contents of HTTP on the wire, as binary is quite normal in HTTP. The issue seems to be some parts of the python MIME encoder still assume it's for email only, where everything would be b64 encoded. Maybe I have to roll my own to create a multipart msg with a binary file? I was hoping to avoid that. Nils ps. You probably know this, but in case anyone else reads this thread, HTTP requires all headers to have CRLF, not native line endings. The python MIME modules can do that properly as of python 3.2 (fixed as of this bug http://hg.python.org/cpython/rev/ebf6741a8d6e/) > > I got interested in it since I have never used any of the > > modules. So I played with it enough to discover that the part of > > the code above that converts the \r to \n is the flatten call. > > > > I got to here and RFC 2049 and gave up. > > > > The following guidelines may be useful to anyone devising a data > > format (media type) that is supposed to survive the widest range of > > networking technologies and known broken MTAs unscathed. Note that > > anything encoded in the base64 encoding will satisfy these rules, but > > that some well-known mechanisms, notably the UNIX uuencode facility, > > will not. Note also that anything encoded in the Quoted-Printable > > encoding will survive most gateways intact, but possibly not some > > gateways to systems that use the EBCDIC character set. > > > > (1) Under some circumstances the encoding used for data may > > change as part of normal gateway or user agent > > operation. In particular, conversion from base64 to > > quoted-printable and vice versa may be necessary. This > > may result in the confusion of CRLF sequences with line > > breaks in text bodies. As such, the persistence of > > CRLF as something other than a line break must not be > > relied on. > > > > (2) Many systems may elect to represent and store text data > > using local newline conventions. Local newline > > conventions may not match the RFC822 CRLF convention -- > > systems are known that use plain CR, plain LF, CRLF, or > > counted records. The result is that isolated CR and LF > > characters are not well tolerated in general; they may > > be lost or converted to delimiters on some systems, and > > hence must not be relied on. > > > > So putting a raw CR in a binary chunk maybe be intolerable, and > > you need to use a different encoder. But I'm out of my element. > > > > -- > > Neil Cerutti From piet at vanoostrum.org Thu Sep 26 14:44:30 2013 From: piet at vanoostrum.org (Piet van Oostrum) Date: Thu, 26 Sep 2013 14:44:30 -0400 Subject: Newline interpretation issue with MIMEApplication with binary data, Python 3.3.2 References: <14063249-6159-48ff-bfe2-8e8d6e3cd7a4@googlegroups.com> <870d6a97-613d-401f-ad03-0bbd3b088538@googlegroups.com> Message-ID: Nils Bunger writes: > Hi Neil, > > Thanks for looking at this. > > I'm trying to create a multipart MIME for an HTTP POST request, not an > email. This is for a third-party API that requires a multipart POST > with a binary file, so I don't have the option to just use a different > encoding. > > Multipart HTTP is standardized in HTTP 1.0 and supports binary parts. > Also, no one will re-interpret contents of HTTP on the wire, as binary > is quite normal in HTTP. > > The issue seems to be some parts of the python MIME encoder still > assume it's for email only, where everything would be b64 encoded. > > Maybe I have to roll my own to create a multipart msg with a binary > file? I was hoping to avoid that. The email MIME stuff is not really adapted for HTTP. I would advise to use the Requests package (http://docs.python-requests.org/en/latest/) or the Uploading Files part from Doug Hellmann's page (http://doughellmann.com/2009/07/pymotw-urllib2-library-for-opening-urls.html). This is for Python2; I can send you a Python3 version if you want. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From nilsbunger at gmail.com Thu Sep 26 12:35:25 2013 From: nilsbunger at gmail.com (Nils Bunger) Date: Thu, 26 Sep 2013 09:35:25 -0700 (PDT) Subject: Newline interpretation issue with MIMEApplication with binary data, Python 3.3.2 In-Reply-To: <14063249-6159-48ff-bfe2-8e8d6e3cd7a4@googlegroups.com> References: <14063249-6159-48ff-bfe2-8e8d6e3cd7a4@googlegroups.com> Message-ID: Hi all, I was able to workaround this problem by encoding a unique 'marker' in the binary part, then replacing the marker with the actual binary content after generating the MIME message. See my answer on Stack Overflow http://stackoverflow.com/a/19033750/526098 for the code. Thanks, your suggestions helped me think of this. Nils On Wednesday, September 25, 2013 9:38:17 AM UTC-7, Nils Bunger wrote: > Hi, > > > > I'm having trouble encoding a MIME message with a binary file. Newline characters are being interpreted even though the content is supposed to be binary. This is using Python 3.3.2 > > > > Small test case: > > > > app = MIMEApplication(b'Q\x0dQ', _encoder=encode_noop) > > b = io.BytesIO() > > g = BytesGenerator(b) > > g.flatten(app) > > for i in b.getvalue()[-3:]: > > print ("%02x " % i, end="") > > print () > > > > This prints 51 0a 51, meaning the 0x0d character got reinterpreted as a newline. > > > > I've tried setting an email policy of HTTP policy, but that goes even further, converting \r to \r\n > > > > This is for HTTP transport, so binary encoding is normal. > > > > Any thoughts how I can do this properly? From madmaxthc at yahoo.it Wed Sep 25 16:06:07 2013 From: madmaxthc at yahoo.it (mstagliamonte) Date: Wed, 25 Sep 2013 13:06:07 -0700 (PDT) Subject: Extracting lines from text files - script with a couple of 'side effects' Message-ID: Dear All, Here I am, with another newbie question. I am trying to extract some lines from a fasta (text) file which match the headers in another file. i.e: Fasta file: >header1|info1:info2_info3 general text >header2|info1:info2_info3 general text headers file: header1|info1:info2_info3 header2|info1:info2_info3 I want to create a third file, similar to the first one, but only containing headers and text of what is listed in the second file. Also, I want to print out how many headers were actually found from the second file to match the first. I have done a script which seems to work, but with a couple of 'side effects' Here is my script: ------------------------------------------------------------------- import re class Extractor(): def __init__(self,headers_file, fasta_file,output_file): with open(headers_file,'r') as inp0: counter0=0 container='' inp0_bis=inp0.read().split('\n') for x in inp0_bis: container+=x.replace(':','_').replace('|','_') with open(fasta_file,'r') as inp1: inp1_bis=inp1.read().split('>') for i in inp1_bis: i_bis= i.split('\n') match = re.search(i_bis[0].replace(':','_').replace('|','_'),container) if match: counter0+=1 with open(output_file,'at') as out0: out0.write('>'+i) print '{} sequences were found'.format(counter0) ------------------------------------------------------------------- Side effects: 1) The very first header is written as >>header1 rather than >header1 2) the number of sequences found is 1 more than the ones actually found! Have you got any thoughts about causes/solutions? Thanks for your time! P.S.: I think I have removed the double posting... not sure... Max From davea at davea.name Wed Sep 25 17:02:07 2013 From: davea at davea.name (Dave Angel) Date: Wed, 25 Sep 2013 21:02:07 +0000 (UTC) Subject: Extracting lines from text files - script with a couple of 'side effects' References: Message-ID: On 25/9/2013 16:06, mstagliamonte wrote: > Dear All, > > Here I am, with another newbie question. I am trying to extract some lines from a fasta (text) file which match the headers in another file. i.e: > Fasta file: >>header1|info1:info2_info3 > general text >>header2|info1:info2_info3 > general text > > headers file: > header1|info1:info2_info3 > header2|info1:info2_info3 > > I want to create a third file, similar to the first one, but only containing headers and text of what is listed in the second file. Also, I want to print out how many headers were actually found from the second file to match the first. > > I have done a script which seems to work, but with a couple of 'side effects' > Here is my script: > ------------------------------------------------------------------- > import re > class Extractor(): > > def __init__(self,headers_file, fasta_file,output_file): > with open(headers_file,'r') as inp0: > counter0=0 > container='' > inp0_bis=inp0.read().split('\n') > for x in inp0_bis: > container+=x.replace(':','_').replace('|','_') > with open(fasta_file,'r') as inp1: > inp1_bis=inp1.read().split('>') > for i in inp1_bis: > i_bis= i.split('\n') > match = re.search(i_bis[0].replace(':','_').replace('|','_'),container) > if match: > counter0+=1 > with open(output_file,'at') as out0: > out0.write('>'+i) > print '{} sequences were found'.format(counter0) > > ------------------------------------------------------------------- > Side effects: > 1) The very first header is written as >>header1 rather than >header1 > 2) the number of sequences found is 1 more than the ones actually found! > > Have you got any thoughts about causes/solutions? > The cause is the same. The first line in the file starts with a "<", and you're splitting on the same. So the first item of inp1_bis is the empty string. That string is certainly contained within container, so it matches, and produces a result of ">" You can "fix" this by adding a line after the "for i in inp1_bis" line if not i: continue But it also seems to me you're doing the search backwards. if the Fasta file has a line like: >der it would be considered a match! Seems to me you'd want to only match lines which contain an entire header. -- DaveA From python at mrabarnett.plus.com Wed Sep 25 17:53:52 2013 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 25 Sep 2013 22:53:52 +0100 Subject: Extracting lines from text files - script with a couple of 'side effects' In-Reply-To: References: Message-ID: <52435B70.4020102@mrabarnett.plus.com> On 25/09/2013 21:06, mstagliamonte wrote: > Dear All, > > Here I am, with another newbie question. I am trying to extract some lines from a fasta (text) file which match the headers in another file. i.e: > Fasta file: >>header1|info1:info2_info3 > general text >>header2|info1:info2_info3 > general text > > headers file: > header1|info1:info2_info3 > header2|info1:info2_info3 > > I want to create a third file, similar to the first one, but only containing headers and text of what is listed in the second file. Also, I want to print out how many headers were actually found from the second file to match the first. > > I have done a script which seems to work, but with a couple of 'side effects' > Here is my script: > ------------------------------------------------------------------- > import re > class Extractor(): > > def __init__(self,headers_file, fasta_file,output_file): > with open(headers_file,'r') as inp0: > counter0=0 > container='' > inp0_bis=inp0.read().split('\n') > for x in inp0_bis: > container+=x.replace(':','_').replace('|','_') > with open(fasta_file,'r') as inp1: > inp1_bis=inp1.read().split('>') > for i in inp1_bis: > i_bis= i.split('\n') > match = re.search(i_bis[0].replace(':','_').replace('|','_'),container) > if match: > counter0+=1 > with open(output_file,'at') as out0: > out0.write('>'+i) > print '{} sequences were found'.format(counter0) > > ------------------------------------------------------------------- > Side effects: > 1) The very first header is written as >>header1 rather than >header1 > 2) the number of sequences found is 1 more than the ones actually found! > > Have you got any thoughts about causes/solutions? > > Thanks for your time! > Here's my version: class Extractor(): def __init__(self, headers_file, fasta_file, output_file): with open(headers_file) as inp: headers = set('>' + line for line in inp) counter = 0 accept = False with open(fasta_file) as inp, open(output_file, 'w') as out: for line in inp: if line.startswith('>'): accept = line in headers if accept: counter += 1 if accept: out.write(line) print '{} sequences were found'.format(counter) From madmaxthc at yahoo.it Thu Sep 26 08:44:42 2013 From: madmaxthc at yahoo.it (mstagliamonte) Date: Thu, 26 Sep 2013 05:44:42 -0700 (PDT) Subject: Extracting lines from text files - script with a couple of 'side effects' In-Reply-To: References: Message-ID: <9b2df692-a229-401c-b129-3b8905d46f6b@googlegroups.com> Hi, Thanks for the answers! And Dave, thanks for explaining the cause of the problem I will keep that in mind for the future. You're right, I am doing the search backward, it just seemed easier for me to do it in that way. Looks like I need to keep practising... Both your suggestions work, I will try and learn from them. Have a nice day Max From tripsvt at gmail.com Wed Sep 25 18:45:49 2013 From: tripsvt at gmail.com (tripsvt at gmail.com) Date: Wed, 25 Sep 2013 15:45:49 -0700 (PDT) Subject: Convert namedtuple to dictionary Message-ID: <635a3b46-3150-409f-8a9d-002af18fb734@googlegroups.com> Need suggestions. Say, I have a namedtuple like this: {'a': brucelee(x=123, y=321), 'b': brucelee('x'=123, 'y'=321) I need to convert it to: {'a': {'x':123, 'y': 321},'b': {'x':123, 'y': 321}} Follow-up question -- Which would be easier to work with if I had to later extract/manipulate the 'x', 'y' values? The format (dicts) above or a list of values like this: {'a': ['x':123, 'y': 321],'b': ['x':123, 'y': 321]} From python.list at tim.thechases.com Wed Sep 25 19:41:25 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 25 Sep 2013 18:41:25 -0500 Subject: Convert namedtuple to dictionary In-Reply-To: <635a3b46-3150-409f-8a9d-002af18fb734@googlegroups.com> References: <635a3b46-3150-409f-8a9d-002af18fb734@googlegroups.com> Message-ID: <20130925184125.12dba1e9@bigbox.christie.dr> On 2013-09-25 15:45, tripsvt at gmail.com wrote: > Say, I have a namedtuple like this: > > {'a': brucelee(x=123, y=321), 'b': brucelee('x'=123, 'y'=321) > > I need to convert it to: > > {'a': {'x':123, 'y': 321},'b': {'x':123, 'y': 321}} While it uses the "private" member-variable "_fields", you can do >>> brucelee = namedtuple("brucelee", "x y") >>> d = {'a': brucelee(x=123,y=321), 'b': brucelee(x=234,y=432)} >>> dict((k, dict((s, getattr(v, s)) for s in v._fields)) for k,v in >>> d.iteritems()) {'a': {'y': 321, 'x': 123}, 'b': {'y': 432, 'x': 234}} which can be made a bit more readable with a helper function: >>> def dictify(some_named_tuple): ... return dict((s, getattr(some_named_tuple, s)) for s in some_named_tuple._fields) ... >>> dict((k, dictify(v)) for k,v in d.iteritems()) {'a': {'y': 321, 'x': 123}, 'b': {'y': 432, 'x': 234}} This would also make it easier to change/choose in the event "_fields" ever changes. -tkc From python at mrabarnett.plus.com Wed Sep 25 19:52:32 2013 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 26 Sep 2013 00:52:32 +0100 Subject: Convert namedtuple to dictionary In-Reply-To: <635a3b46-3150-409f-8a9d-002af18fb734@googlegroups.com> References: <635a3b46-3150-409f-8a9d-002af18fb734@googlegroups.com> Message-ID: <52437740.5060704@mrabarnett.plus.com> On 25/09/2013 23:45, tripsvt at gmail.com wrote: > Need suggestions. > > Say, I have a namedtuple like this: > > {'a': brucelee(x=123, y=321), 'b': brucelee('x'=123, 'y'=321) I assume you mean: {'a': brucelee(x=123, y=321), 'b': brucelee(x=123, y=321)} > > I need to convert it to: > > {'a': {'x':123, 'y': 321},'b': {'x':123, 'y': 321}} > You can get the field names using ._fields and the values by using list(...): >>> n = brucelee(x=123, y=321) >>> n._fields ('x', 'y') >>> list(n) [123, 321] Zip then together and pass the result to dict: >>> dict(zip(n._fields, list(n))) {'x': 123, 'y': 321} And, finally, putting that in a dict comprehension: >>> n = {'a': brucelee(x=123, y=321), 'b': brucelee(x=123, y=321)} >>> {k: dict(zip(v._fields, list(v))) for k, v in n.items()} {'a': {'x': 123, 'y': 321}, 'b': {'x': 123, 'y': 321}} > Follow-up question -- > > Which would be easier to work with if I had to later extract/manipulate the 'x', 'y' values? The format (dicts) above or a list of values like this: > > {'a': ['x':123, 'y': 321],'b': ['x':123, 'y': 321]} > That's not valid Python! From ned at nedbatchelder.com Wed Sep 25 20:15:45 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 25 Sep 2013 20:15:45 -0400 Subject: Convert namedtuple to dictionary In-Reply-To: <635a3b46-3150-409f-8a9d-002af18fb734@googlegroups.com> References: <635a3b46-3150-409f-8a9d-002af18fb734@googlegroups.com> Message-ID: <52437CB1.4090807@nedbatchelder.com> On 9/25/13 6:45 PM, tripsvt at gmail.com wrote: > Need suggestions. > > Say, I have a namedtuple like this: > > {'a': brucelee(x=123, y=321), 'b': brucelee('x'=123, 'y'=321) > > I need to convert it to: > > {'a': {'x':123, 'y': 321},'b': {'x':123, 'y': 321}} Namedtuples have a ._asdict() method. You can convert your dictionary of namedtuples (let's call it tupledict) like this: dictdict = { k: nt._asdict() for k, nt in tupledict } --Ned. > Follow-up question -- > > Which would be easier to work with if I had to later extract/manipulate the 'x', 'y' values? The format (dicts) above or a list of values like this: > > {'a': ['x':123, 'y': 321],'b': ['x':123, 'y': 321]} From steve+comp.lang.python at pearwood.info Wed Sep 25 21:08:52 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Sep 2013 01:08:52 GMT Subject: Convert namedtuple to dictionary References: <635a3b46-3150-409f-8a9d-002af18fb734@googlegroups.com> Message-ID: <52438924$0$30000$c3e8da3$5496439d@news.astraweb.com> On Wed, 25 Sep 2013 18:41:25 -0500, Tim Chase wrote about namedtuple: > While it uses the "private" member-variable "_fields", you can do It's not actually private! namedtuple is documented as an exception to the rule that methods starting with a single leading underscore are private. Named tuples define three public methods and one data attribute. In order to avoid clashing with field names, they start with a single underscore, but they are documented as public: _make _asdict _replace _fields http://docs.python.org/2/library/collections.html#namedtuple-factory-function-for-tuples-with-named-fields -- Steven From python at mrabarnett.plus.com Wed Sep 25 21:15:50 2013 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 26 Sep 2013 02:15:50 +0100 Subject: Convert namedtuple to dictionary In-Reply-To: <52438924$0$30000$c3e8da3$5496439d@news.astraweb.com> References: <635a3b46-3150-409f-8a9d-002af18fb734@googlegroups.com> <52438924$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52438AC6.9060206@mrabarnett.plus.com> On 26/09/2013 02:08, Steven D'Aprano wrote: > On Wed, 25 Sep 2013 18:41:25 -0500, Tim Chase wrote about namedtuple: > >> While it uses the "private" member-variable "_fields", you can do > > It's not actually private! > > namedtuple is documented as an exception to the rule that methods > starting with a single leading underscore are private. Named tuples > define three public methods and one data attribute. In order to avoid > clashing with field names, they start with a single underscore, but they > are documented as public: > > _make > _asdict > _replace > _fields > > > http://docs.python.org/2/library/collections.html#namedtuple-factory-function-for-tuples-with-named-fields > Wouldn't it have made more sense to have a trailing underscore instead? From tjreedy at udel.edu Wed Sep 25 21:45:31 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 25 Sep 2013 21:45:31 -0400 Subject: Convert namedtuple to dictionary In-Reply-To: <52438AC6.9060206@mrabarnett.plus.com> References: <635a3b46-3150-409f-8a9d-002af18fb734@googlegroups.com> <52438924$0$30000$c3e8da3$5496439d@news.astraweb.com> <52438AC6.9060206@mrabarnett.plus.com> Message-ID: On 9/25/2013 9:15 PM, MRAB wrote: > On 26/09/2013 02:08, Steven D'Aprano wrote: >> On Wed, 25 Sep 2013 18:41:25 -0500, Tim Chase wrote about namedtuple: >> >>> While it uses the "private" member-variable "_fields", you can do >> >> It's not actually private! >> >> namedtuple is documented as an exception to the rule that methods >> starting with a single leading underscore are private. Named tuples >> define three public methods and one data attribute. In order to avoid >> clashing with field names, they start with a single underscore, but they >> are documented as public: >> >> _make >> _asdict >> _replace >> _fields >> >> >> http://docs.python.org/2/library/collections.html#namedtuple-factory-function-for-tuples-with-named-fields >> >> > Wouldn't it have made more sense to have a trailing underscore instead? Users might use such to avoid clashes with keywords and builtins: 'print_', 'id_', 'as_', and will certainly sometimes use embedded _. -- Terry Jan Reedy From python.list at tim.thechases.com Thu Sep 26 07:51:41 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 26 Sep 2013 06:51:41 -0500 Subject: Convert namedtuple to dictionary In-Reply-To: <52438924$0$30000$c3e8da3$5496439d@news.astraweb.com> References: <635a3b46-3150-409f-8a9d-002af18fb734@googlegroups.com> <52438924$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20130926065141.1f9d3a52@bigbox.christie.dr> On 2013-09-26 01:08, Steven D'Aprano wrote: > On Wed, 25 Sep 2013 18:41:25 -0500, Tim Chase wrote about > namedtuple: > > > While it uses the "private" member-variable "_fields", you can do > > It's not actually private! > > namedtuple is documented as an exception to the rule that methods > starting with a single leading underscore are private. Named tuples > define three public methods and one data attribute. In order to > avoid clashing with field names, they start with a single > underscore, but they are documented as public: > > _make > _asdict > _replace > _fields Well dang if "leading underscore suggests private/internal use" convention got tossed out the window here :) But indeed, they are in the docs, so (to the OP), use _asdict() and make life easy. -tkc From steve at pearwood.info Wed Sep 25 23:48:05 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 26 Sep 2013 03:48:05 GMT Subject: Convert namedtuple to dictionary References: <635a3b46-3150-409f-8a9d-002af18fb734@googlegroups.com> Message-ID: <5243ae75$0$2833$c3e8da3$76491128@news.astraweb.com> On Wed, 25 Sep 2013 15:45:49 -0700, tripsvt wrote: > Need suggestions. > > Say, I have a namedtuple like this: > > {'a': brucelee(x=123, y=321), 'b': brucelee('x'=123, 'y'=321) That's not a namedtuple, that's a dict containing two namedtuples. > I need to convert it to: > > {'a': {'x':123, 'y': 321},'b': {'x':123, 'y': 321}} Why bother? But if you must: for key, value in some_dict.items(): some_dict[key] = value._asdict() ought to work. > Follow-up question -- > > Which would be easier to work with if I had to later extract/manipulate > the 'x', 'y' values? The format (dicts) above or a list of values like > this: > > {'a': ['x':123, 'y': 321],'b': ['x':123, 'y': 321]} That's not legal Python. The answer depends on what you mean by "extract/manipulate" the x and y fields. If all you are doing is looking them up, then a namedtuple is easiest, since that's what you've already got: for value in some_dict.values(): print(value.x) print(value.y) But if you need to change those values, then a namedtuple is no good because it is immutable. In that case, you can either create a new namedtuple, or just use the dict-of-dicts version. # Untested for key, value in some_dict.items(): kind = type(value) # what sort of namedtuple is it? new = kind(value.x+1, value.y+2) some_dict[key] = new -- Steven From __peter__ at web.de Thu Sep 26 02:47:35 2013 From: __peter__ at web.de (Peter Otten) Date: Thu, 26 Sep 2013 08:47:35 +0200 Subject: Convert namedtuple to dictionary References: <635a3b46-3150-409f-8a9d-002af18fb734@googlegroups.com> Message-ID: tripsvt at gmail.com wrote: > Need suggestions. > > Say, I have a namedtuple like this: > > {'a': brucelee(x=123, y=321), 'b': brucelee('x'=123, 'y'=321) > > I need to convert it to: > > {'a': {'x':123, 'y': 321},'b': {'x':123, 'y': 321}} > > Follow-up question -- > > Which would be easier to work with if I had to later extract/manipulate > the 'x', 'y' values? The format (dicts) above or a list of values like > this: > > {'a': ['x':123, 'y': 321],'b': ['x':123, 'y': 321]} One more: >>> from collections import namedtuple >>> brucelee = namedtuple("brucelee", "x y") >>> def to_dict(n): ... return dict(zip(n._fields, n)) ... >>> data = {'a': brucelee(x=123, y=321), 'b': brucelee(x=123, y=321)} >>> {k: to_dict(v) for k, v in data.items()} {'a': {'y': 321, 'x': 123}, 'b': {'y': 321, 'x': 123}} From virendra.tripathi at maansystems.com Thu Sep 26 12:42:50 2013 From: virendra.tripathi at maansystems.com (Virendra Tripathi) Date: Thu, 26 Sep 2013 16:42:50 +0000 Subject: Convert namedtuple to dictionary Message-ID: Thx Tim. Your solution works. I am, as you can probably tell, a newbie at Python. From python.list at tim.thechases.com Thu Sep 26 13:22:49 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 26 Sep 2013 12:22:49 -0500 Subject: Convert namedtuple to dictionary In-Reply-To: References: Message-ID: <20130926122249.06e8653e@bigbox.christie.dr> On 2013-09-26 16:42, Virendra Tripathi wrote: > Thx Tim. Your solution works. After Steven's reply, I recommend dict((k,v._asdict()) for k,v in d.iteritems()) which simplifies matters. -tkc From virendra.tripathi at maansystems.com Thu Sep 26 13:13:47 2013 From: virendra.tripathi at maansystems.com (Virendra Tripathi) Date: Thu, 26 Sep 2013 17:13:47 +0000 Subject: Convert namedtuple to dictionary Message-ID: Hi MRAB, Thanks. Learning a lot thanks to you guys. I should have mentioned that the data is dynamic, in the sense that 'brucelee' could be 'jackiechan' , the number of named tuples - i.e., 'brucelee(?)', could change as well, the next time data is pulled in. The format of the data would however remain the same. I am using @Tim Chase's solution for now. Your solution will also work but I think I'll need to create a fn to pull out the " n " values as in: ">>> n = brucelee(x=123, y=321)" Thanks, Virendra From virendra.tripathi at maansystems.com Thu Sep 26 13:17:22 2013 From: virendra.tripathi at maansystems.com (Virendra Tripathi) Date: Thu, 26 Sep 2013 17:17:22 +0000 Subject: Convert namedtuple to dictionary Message-ID: <6962B501-781B-4D05-93C6-50E3FFBAE9A4@maansystems.com> Hi Ned, Thanks. Wouldn't I have to first create a function to pull out the 'dictdict' from the data? I assume 'dictdict' refers to the 'brucelee' named tuple in the example. That's where I was getting stuck-trying to pull out the named tuples from the dict and operate on it. Thanks, Virendra From ned at nedbatchelder.com Thu Sep 26 13:42:59 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Thu, 26 Sep 2013 13:42:59 -0400 Subject: Convert namedtuple to dictionary In-Reply-To: <6962B501-781B-4D05-93C6-50E3FFBAE9A4@maansystems.com> References: <6962B501-781B-4D05-93C6-50E3FFBAE9A4@maansystems.com> Message-ID: <52447223.2080908@nedbatchelder.com> On 9/26/13 1:17 PM, Virendra Tripathi wrote: > Hi Ned, > > Thanks. Wouldn't I have to first create a function to pull out the 'dictdict' from the data? I assume 'dictdict' refers to the 'brucelee' named tuple in the example. That's where I was getting stuck-trying to pull out the named tuples from the dict and operate on it. I assumed you already had the data you showed. This is tupledict: {'a': brucelee(x=123, y=321), 'b': brucelee('x'=123, 'y'=321) Given that, you create dictdict with the line I showed: dictdict = { k: nt._asdict() for k, nt in tupledict } > Thanks, > > Virendra From ned at nedbatchelder.com Thu Sep 26 14:38:26 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Thu, 26 Sep 2013 14:38:26 -0400 Subject: Convert namedtuple to dictionary In-Reply-To: <52447223.2080908@nedbatchelder.com> References: <6962B501-781B-4D05-93C6-50E3FFBAE9A4@maansystems.com> <52447223.2080908@nedbatchelder.com> Message-ID: <52447F22.4030202@nedbatchelder.com> On 9/26/13 1:42 PM, Ned Batchelder wrote: > On 9/26/13 1:17 PM, Virendra Tripathi wrote: >> Hi Ned, >> >> Thanks. Wouldn't I have to first create a function to pull out the >> 'dictdict' from the data? I assume 'dictdict' refers to the >> 'brucelee' named tuple in the example. That's where I was getting >> stuck-trying to pull out the named tuples from the dict and operate >> on it. > I assumed you already had the data you showed. This is tupledict: > > {'a': brucelee(x=123, y=321), 'b': brucelee('x'=123, 'y'=321) > > Given that, you create dictdict with the line I showed: > > dictdict = { k: nt._asdict() for k, nt in tupledict } > Oops: dictdict = { k: nt._asdict() for k, nt in tupledict.iteritems() } (sorry!) --Ned. >> Thanks, >> >> Virendra > From virendra.tripathi at maansystems.com Thu Sep 26 15:10:38 2013 From: virendra.tripathi at maansystems.com (Virendra Tripathi) Date: Thu, 26 Sep 2013 19:10:38 +0000 Subject: Convert namedtuple to dictionary Message-ID: <3623D9C4-43FE-4DB1-9CCF-318CB2C161BB@maansystems.com> Thanks guys! BTW, please ignore the follow-up question there. I had written a script earlier which had a dict like: {'a':[x=10, y=23,..], 'b': [x=10, y=23,?],?..} I was thinking about that and therefore the error. Apologies. From a7xrturodev at gmail.com Wed Sep 25 19:24:22 2013 From: a7xrturodev at gmail.com (Arturo B) Date: Wed, 25 Sep 2013 16:24:22 -0700 (PDT) Subject: Understanding how is a function evaluated using recursion Message-ID: <231e5958-97c9-489c-9cfa-0f4451f6520c@googlegroups.com> Hi, I'm doing Python exercises and I need to write a function to flat nested lists as this one: [[1,2,3],4,5,[6,[7,8]]] To the result: [1,2,3,4,5,6,7,8] So I searched for example code and I found this one that uses recursion (that I don't understand): def flatten(l): ret = [] for i in l: if isinstance(i, list) or isinstance(i, tuple): ret.extend(flatten(i)) #How is flatten(i) evaluated? else: ret.append(i) return ret So I know what recursion is, but I don't know how is flatten(i) evaluated, what value does it returns? Thank you From Joshua.R.English at gmail.com Wed Sep 25 19:59:25 2013 From: Joshua.R.English at gmail.com (Josh English) Date: Wed, 25 Sep 2013 16:59:25 -0700 (PDT) Subject: Understanding how is a function evaluated using recursion In-Reply-To: <231e5958-97c9-489c-9cfa-0f4451f6520c@googlegroups.com> References: <231e5958-97c9-489c-9cfa-0f4451f6520c@googlegroups.com> Message-ID: On Wednesday, September 25, 2013 4:24:22 PM UTC-7, Arturo B wrote: > Hi, I'm doing Python exercises and I need to write a function to flat nested lists > So I know what recursion is, but I don't know how is > > flatten(i) > > evaluated, what value does it returns? > In this case, flatten always returns a list. When it hits the recursion, it calls itself to get another list, that it uses to extend the current list. Josh From python at mrabarnett.plus.com Wed Sep 25 20:07:01 2013 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 26 Sep 2013 01:07:01 +0100 Subject: Understanding how is a function evaluated using recursion In-Reply-To: <231e5958-97c9-489c-9cfa-0f4451f6520c@googlegroups.com> References: <231e5958-97c9-489c-9cfa-0f4451f6520c@googlegroups.com> Message-ID: <52437AA5.6050804@mrabarnett.plus.com> On 26/09/2013 00:24, Arturo B wrote: > Hi, I'm doing Python exercises and I need to write a function to flat nested lists > as this one: > > [[1,2,3],4,5,[6,[7,8]]] > > To the result: > > [1,2,3,4,5,6,7,8] > > So I searched for example code and I found this one that uses recursion (that I don't understand): > > def flatten(l): > ret = [] > for i in l: > if isinstance(i, list) or isinstance(i, tuple): > ret.extend(flatten(i)) #How is flatten(i) evaluated? > else: > ret.append(i) > return ret > > So I know what recursion is, but I don't know how is > > flatten(i) > > evaluated, what value does it returns? > Try a simpler version first: def flatten(l): ret = [] for i in l: if isinstance(i, list) or isinstance(i, tuple): # Append the contents of the item. ret.extend(i) else: # Append the item itself. ret.append(i) return ret In this example, flatten([[1,2,3],4,5,[6,[7,8]]]) returns [1,2,3,4,5,6, [7,8]]. The problem here is that a sublist can itself contain a list. It would be nice if there were a function which, when given [6,[7,8]], would return [6,7,8] so that you could append those items. But that's exactly what flatten does! Try adding prints to tell you what was passed in and what is returned. From steve+comp.lang.python at pearwood.info Wed Sep 25 20:10:43 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Sep 2013 00:10:43 GMT Subject: Understanding how is a function evaluated using recursion References: <231e5958-97c9-489c-9cfa-0f4451f6520c@googlegroups.com> Message-ID: <52437b82$0$30000$c3e8da3$5496439d@news.astraweb.com> On Wed, 25 Sep 2013 16:24:22 -0700, Arturo B wrote: > Hi, I'm doing Python exercises and I need to write a function to flat > nested lists as this one: > > [[1,2,3],4,5,[6,[7,8]]] > > To the result: > > [1,2,3,4,5,6,7,8] > > So I searched for example code and I found this one that uses recursion > (that I don't understand): > > def flatten(l): > ret = [] > for i in l: > if isinstance(i, list) or isinstance(i, tuple): > ret.extend(flatten(i)) #How is flatten(i) evaluated? > else: > ret.append(i) > return ret > > So I know what recursion is, but I don't know how is > > flatten(i) > > evaluated, what value does it returns? You have the source code to flatten right there in front of you. The very last line says: return ret The first line of the function sets: ret = [] and it is a list which accumulates all the items seen. If you follow the code with a simple non-nested list: flatten([1, 2, 3]) flatten sets the return result "ret" to the empty list, then walks the argument list extracting each item in turn, which results in this sequence of calls: ret = [] ret.append(1) ret.append(2) ret.append(3) return ret # [1, 2, 3, 4] Now if we do the same thing with a nested list: flatten([1, [2, 3], 4]) the call to flatten does the same thing, walks the input list, only this time it has a recursive call: # outer call ret = [] ret.append(1) At this point, the item found is a list, so flatten([2, 3]) is called, so Python drops into into a new call, building a new list called "ret", leaving the old one untouched: # inner call ret = [] ret.append(2) ret.append(3) return ret # [2, 3] At this point Python drops back to the first call again: # outer call ret.extend([2, 3]) ret.append(4) return ret # [1, 2, 3, 4] But it all together in one chunk, without the commentary: flatten([1, [2, 3], 4]) => # outer call ret = [] ret.append(1) flatten([2, 3]) => # inner call ret = [] ret.append(2) ret.append(3) return ret # [2, 3] # outer call ret.extend([2, 3]) ret.append(4) return ret # [1, 2, 3, 4] In principle, you can nest as many function calls as needed. In practice, Python will stop after 1000 nested calls by default, although you can tune it up and down. -- Steven From davea at davea.name Wed Sep 25 20:26:23 2013 From: davea at davea.name (Dave Angel) Date: Thu, 26 Sep 2013 00:26:23 +0000 (UTC) Subject: Understanding how is a function evaluated using recursion References: <231e5958-97c9-489c-9cfa-0f4451f6520c@googlegroups.com> Message-ID: On 25/9/2013 19:24, Arturo B wrote: > Hi, I'm doing Python exercises and I need to write a function to flat nested lists > as this one: > > [[1,2,3],4,5,[6,[7,8]]] > > To the result: > > [1,2,3,4,5,6,7,8] > > So I searched for example code and I found this one that uses recursion (that I don't understand): > > def flatten(l): > ret = [] > for i in l: I can't imagine why you'd use either i or l in this context, but especially use them both when they look so much alike. > if isinstance(i, list) or isinstance(i, tuple): > ret.extend(flatten(i)) #How is flatten(i) evaluated? > else: > ret.append(i) > return ret > > So I know what recursion is, but I don't know how is > > flatten(i) > > evaluated, what value does it returns? > flatten() returns a list, of course. The value of 'ret' in the inner function. What don't you understand about recursion? You write a function that's valid for the simple case (a simple list, with none of the elements being lists or tuples). Then you use that function inside itself to handle the more complex cases. -- DaveA From tjreedy at udel.edu Wed Sep 25 21:12:02 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 25 Sep 2013 21:12:02 -0400 Subject: Understanding how is a function evaluated using recursion In-Reply-To: <231e5958-97c9-489c-9cfa-0f4451f6520c@googlegroups.com> References: <231e5958-97c9-489c-9cfa-0f4451f6520c@googlegroups.com> Message-ID: On 9/25/2013 7:24 PM, Arturo B wrote: > Hi, I'm doing Python exercises and I need to write a function to flat nested lists > as this one: > > [[1,2,3],4,5,[6,[7,8]]] > > To the result: > > [1,2,3,4,5,6,7,8] > > So I searched for example code and I found this one that uses recursion (that I don't understand): > > def flatten(l): > ret = [] > for i in l: > if isinstance(i, list) or isinstance(i, tuple): > ret.extend(flatten(i)) #How is flatten(i) evaluated? > else: > ret.append(i) > return ret > > So I know what recursion is, but I don't know how is > > flatten(i) > > evaluated, what value does it returns? It is not clear what part of 'how' you do not understand this. Perhaps that fact that a new execution frame with a new set of locals is created for each call. So calling flatten from flatten is no different than call flatten from anywhere else. If a language creates just one execution frame for the function, attached to the function (as with original Fortran, for instance), then recursion is not allowed as a 2nd call would interfere with the use of the locals by the 1st call, etc. -- Terry Jan Reedy From rustompmody at gmail.com Thu Sep 26 00:04:04 2013 From: rustompmody at gmail.com (rusi) Date: Wed, 25 Sep 2013 21:04:04 -0700 (PDT) Subject: Understanding how is a function evaluated using recursion In-Reply-To: <231e5958-97c9-489c-9cfa-0f4451f6520c@googlegroups.com> References: <231e5958-97c9-489c-9cfa-0f4451f6520c@googlegroups.com> Message-ID: On Thursday, September 26, 2013 4:54:22 AM UTC+5:30, Arturo B wrote: > So I know what recursion is, but I don't know how is > > flatten(i) > > evaluated, what value does it returns? When you are a noob, who do you ask? The gurus. When you are a guru who do you ask? The computer! And its really quite easy to ask the computer directly. Here's your code with a extra prints def flatten(l): print ("Received: %s" % l) ret = [] for i in l: if isinstance(i, list) or isinstance(i, tuple): ret.extend(flatten(i)) #How is flatten(i) evaluated? else: ret.append(i) print ("Returning: %s" % ret) return ret Now run it with a couple of different inputs (not neglecting the trivial cases) and see if it does not self-explain. If still confusing, come back and ask! From neilc at norwich.edu Thu Sep 26 10:18:29 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 26 Sep 2013 14:18:29 GMT Subject: Understanding how is a function evaluated using recursion References: <231e5958-97c9-489c-9cfa-0f4451f6520c@googlegroups.com> Message-ID: On 2013-09-25, Arturo B wrote: > Hi, I'm doing Python exercises and I need to write a function > to flat nested lists as this one: > > [[1,2,3],4,5,[6,[7,8]]] > > To the result: > > [1,2,3,4,5,6,7,8] > > So I searched for example code and I found this one that uses > recursion (that I don't understand): > > def flatten(l): > ret = [] > for i in l: > if isinstance(i, list) or isinstance(i, tuple): > ret.extend(flatten(i)) #How is flatten(i) evaluated? > else: > ret.append(i) > return ret > > So I know what recursion is, but I don't know how is > > flatten(i) > > evaluated, what value does it returns? It only *looks* like magic, as others have explained. I keep a file callled bikeshed.py for these occasions. The flatten function has been to the bike shed a lot [1]. Here's a non-recursive version of flatten for comparison: from collections import Sequence def flatten(seq): stack = [] i = 0 result = [] while True: if i >= len(seq): if stack: seq, i = stack.pop() else: return result elif isinstance(seq[i], Sequence): stack.append((seq, i+1)) # Store the continue point seq = seq[i] i = 0 else: result.append(seq[i]) i += 1 When this version encounters a nested list, it keeps a stack of sequences and indices to continue on with after processing the nested list. The code at the start of the while loop, when a sequence is exhausted, pops the continue points fromt he stack, returning if the stack is empty. It's simpler and cleaner to call flatten on itself, as in the recursive version, because the stack frames do all the bookkeeping for you. CPython has a limited number of stack frames though, so the version above might be preferable for certain levels of nesting. [1] http://en.wiktionary.org/wiki/bikeshed -- Neil Cerutti From neilc at norwich.edu Thu Sep 26 10:23:47 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 26 Sep 2013 14:23:47 GMT Subject: Understanding how is a function evaluated using recursion References: <231e5958-97c9-489c-9cfa-0f4451f6520c@googlegroups.com> Message-ID: On 2013-09-26, Neil Cerutti wrote: > def flatten(seq): > > [1] http://en.wiktionary.org/wiki/bikeshed In that spirit, it occurs to me that given current Python nomenclature, 'flattened' would be a better name. -- Neil Cerutti From peter.cacioppi at gmail.com Sat Sep 28 16:24:28 2013 From: peter.cacioppi at gmail.com (Peter Cacioppi) Date: Sat, 28 Sep 2013 13:24:28 -0700 (PDT) Subject: Understanding how is a function evaluated using recursion In-Reply-To: References: <231e5958-97c9-489c-9cfa-0f4451f6520c@googlegroups.com> Message-ID: <90f464bb-961e-4d3c-ab51-583779845438@googlegroups.com> On Thursday, September 26, 2013 7:23:47 AM UTC-7, Neil Cerutti wrote: > On 2013-09-26, Neil Cerutti wrote: > > > def flatten(seq): > > > > > > [1] http://en.wiktionary.org/wiki/bikeshed > > > > In that spirit, it occurs to me that given current Python > > nomenclature, 'flattened' would be a better name. > > > > -- > > Neil Cerutti The example presented here is simple enough for someone who is confident with recursion and somewhat new to Python. So perhaps a refresher on recursion would help. The way to grok recursion for the first time is (a) to read some general info about it (Wikipedia has some decent stuff here, but there are many other sources) and (b) find a simple recursion example and play around with it in the debugger. Python has some decent debugger solutions - I like using ipdb with iPython. The factorial function is a good one to play around with if you're new to recursion. The Fibonacci sequence is also good. Find a .py example, or, better yet, write your own based on psuedo code. If you're a recursion expert already, then I don't know what to tell you other than Python seems to have implemented recursion faithfully and there are no gotchas that I can see. From rustompmody at gmail.com Sun Sep 29 23:41:41 2013 From: rustompmody at gmail.com (rusi) Date: Sun, 29 Sep 2013 20:41:41 -0700 (PDT) Subject: Understanding how is a function evaluated using recursion In-Reply-To: <231e5958-97c9-489c-9cfa-0f4451f6520c@googlegroups.com> References: <231e5958-97c9-489c-9cfa-0f4451f6520c@googlegroups.com> Message-ID: On Thursday, September 26, 2013 4:54:22 AM UTC+5:30, Arturo B wrote: > So I know what recursion is, but I don't know how is > > flatten(i) > > evaluated, what value does it returns? There is a folklore in CS that recursion is hard [To iterate is human, to recurse divine -- Peter Deutsch] This is unfortunate and inaccurate as students brought up on functional programming dont seem to find it hard. What is hard is mixing imperative programming and recursion. So here are some non-imperative versions of flatten # At first pull out the recursion-checking predicate def isrec(x): return isinstance(x, list) or isinstance(x, tuple) # And we need a cutdown version of flatten -- concat. # concat flattens exactly one level. More it does not go into, less and it errors out def concat(l): return [y for x in l for y in x] # Version 0 def flat0(l): if not isrec(l): return [l] else: return concat([flat0(i) for i in l]) # Push the if into the return -- more functional def flat1(l): return ([l] if not isrec(l) else concat([flat1(i) for i in l])) # push the if expression into the comprehension def flat2(l): return concat([flat2(i) if isrec(i) else [i] for i in l]) ### Lisp-y solution def hd(l) : return l[0] def tl(l) : return l[1:] def null(l): return l==[] def flat4(l): return ( [] if null(l) else [l] if not isrec(l) else flat4(hd(l)) + flat4(tl(l))) From melwin9 at gmail.com Wed Sep 25 23:14:41 2013 From: melwin9 at gmail.com (melwin9 at gmail.com) Date: Wed, 25 Sep 2013 20:14:41 -0700 (PDT) Subject: Nosetests Message-ID: <32f7bdcb-97e5-4a1c-a2c8-ab91e40527a8@googlegroups.com> Hello, I am trying to write a few tests for a random input number game but not too sure how to proceed on. I am following the Python Game from http://inventwithpython.com/chapter4.html Started the tests with a file test_guess.py from unittest import TestCase import pexpect as pe import guess as g class GuessTest(TestCase): def setUp(self): self.intro = 'I have chosen a number from 1-10' self.request = 'Guess a number: ' self.responseHigh = "That's too high." self.responseLow = "That's too low." self.responseCorrect = "That's right!" self.goodbye = 'Goodbye and thanks for playing!' def test_main(self): #cannot execute main now because it will #require user input from guess import main def test_guessing_hi_low_4(self): # Conversation assuming number is 4 child = pe.spawn('python guess.py') child.expect(self.intro,timeout=5) child.expect(self.request,timeout=5) child.sendline('5') child.expect(self.responseHigh,timeout=5) child.sendline('3') child.expect(self.responseLow,timeout=5) child.sendline('4') child.expect(self.responseCorrect,timeout=5) child.expect(self.goodbye,timeout=5) def test_guessing_low_hi_4(self): # Conversation assuming number is 4 child = pe.spawn('python guess.py') child.expect(self.intro,timeout=5) child.expect(self.request,timeout=5) child.sendline('3') child.expect(self.responseLow,timeout=5) child.sendline('5') child.expect(self.responseHigh,timeout=5) child.sendline('4') child.expect(self.responseCorrect,timeout=5) child.expect(self.goodbye,timeout=5) and the guess.py file with intro = 'I have chosen a number from 1-10' request = 'Guess a number: ' responseHigh = "That's too high." responseLow = "That's too low." responseCorrect = "That's right!" goodbye = 'Goodbye and thanks for playing!' def main(): print(intro) user_input = raw_input(request) print(responseHigh) print(request) user_input = raw_input(request) print(responseLow) user_input = raw_input(request) print(responseCorrect) print(goodbye) if __name__ == '__main__': main() Not sure How to proceed on with writing a few more tests with if statement to test if the value is low or high. I was told to try a command line switch like optparse to pass the number but not sure how to do that either. Somewhat of a new person with Python, any guidance or assistance would be appreciated. From roy at panix.com Wed Sep 25 23:48:59 2013 From: roy at panix.com (Roy Smith) Date: Wed, 25 Sep 2013 23:48:59 -0400 Subject: Nosetests References: <32f7bdcb-97e5-4a1c-a2c8-ab91e40527a8@googlegroups.com> Message-ID: In article <32f7bdcb-97e5-4a1c-a2c8-ab91e40527a8 at googlegroups.com>, melwin9 at gmail.com wrote: > Not sure How to proceed on with writing a few more tests with if statement to > test if the value is low or high. I was told to try a command line switch > like optparse to pass the number but not sure how to do that either. One thing I would recommend is refactoring your game to keep the game logic distinct from the I/O. If I was designing this, I would have some sort of game engine class, which stores all the state for a game. I imagine the first thing you need to do is pick a random number and remember it. Then, you'll need a function to take a guess and tell you if it's too high, too low, or correct. Something like: class NumberGuessingGame: def __init__(self): self.number = random.randint(0, 10) HIGH = 1 LOW = 2 OK = 3 def guess(self, number): if number > self.number: return self.HIGH if number < self.number: return self.LOW return self.OK Now you've got something that's easy to test without all this pexpect crud getting in the way. Then, your game application can create an instance of NumberGuessingGame and wrap the required I/O operations around that. I'd also probably add some way to bypass the random number generator and set the number you're trying to guess directly. This will make it a lot easier to test edge cases. From melwin9 at gmail.com Thu Sep 26 20:55:30 2013 From: melwin9 at gmail.com (melwin9 at gmail.com) Date: Thu, 26 Sep 2013 17:55:30 -0700 (PDT) Subject: Nosetests In-Reply-To: References: <32f7bdcb-97e5-4a1c-a2c8-ab91e40527a8@googlegroups.com> Message-ID: Initially I was shown pexpect, leaving that there, Can i make up 5 tests? I tried tests two different ways and no luck. What am I supposed to be writing up when I do a test and is there a particular way I can/should be referencing it back to its main file? THis is what I have for the test_guess.py from unittest import TestCase import pexpect as pe import guess as g import random random_number = random.randrange(1, 10) correct = False class GuessTest(TestCase): def setUp(self): self.intro = 'I have chosen a number from 1-10' self.request = 'Guess a number: ' self.responseHigh = "That's too high." self.responseLow = "That's too low." self.responseCorrect = "That's right!" self.goodbye = 'Goodbye and thanks for playing!' def test_main(self): #cannot execute main now because it will #require user input from guess import main def test_guessing_hi_low_4(self): # Conversation assuming number is 4 child = pe.spawn('python guess.py') child.expect(self.intro,timeout=5) child.expect(self.request,timeout=5) child.sendline('5') child.expect(self.responseHigh,timeout=5) child.sendline('3') child.expect(self.responseLow,timeout=5) child.sendline('4') child.expect(self.responseCorrect,timeout=5) child.expect(self.goodbye,timeout=5) def __init__(self): self.number = random.randint(0,10) HIGH = 1 LOW = 2 OK = 3 def guess(self, number): if number > self.number: return self.HIGH if number < self.number: return self.LOW return self.OK def test_guesstoolow(self): while not correct: guess = input("What could it be?") if guess == random_number: print "Congrats You Got It" correct = True elif guess > random_number: print "To High" elif guess < random_number: print "To Low" else: print "Try Again" and the guess.py file is intro = 'I have chosen a number from 1-10' request = 'Guess a number: ' responseHigh = "That's too high." responseLow = "That's too low." responseCorrect = "That's right!" goodbye = 'Goodbye and thanks for playing!' def main(): print(intro) user_input = raw_input(request) print(responseHigh) print(request) user_input = raw_input(request) print(responseLow) user_input = raw_input(request) print(responseCorrect) print(goodbye) if __name__ == '__main__': main() On Wednesday, September 25, 2013 11:48:59 PM UTC-4, Roy Smith wrote: > In article > > wrote: > > > > > Not sure How to proceed on with writing a few more tests with if statement to > > > test if the value is low or high. I was told to try a command line switch > > > like optparse to pass the number but not sure how to do that either. > > > > One thing I would recommend is refactoring your game to keep the game > > logic distinct from the I/O. > > > > If I was designing this, I would have some sort of game engine class, > > which stores all the state for a game. I imagine the first thing you > > need to do is pick a random number and remember it. Then, you'll need a > > function to take a guess and tell you if it's too high, too low, or > > correct. Something like: > > > > class NumberGuessingGame: > > def __init__(self): > > self.number = random.randint(0, 10) > > > > HIGH = 1 > > LOW = 2 > > OK = 3 > > > > def guess(self, number): > > if number > self.number: > > return self.HIGH > > if number < self.number: > > return self.LOW > > return self.OK > > > > Now you've got something that's easy to test without all this pexpect > > crud getting in the way. Then, your game application can create an > > instance of NumberGuessingGame and wrap the required I/O operations > > around that. > > > > I'd also probably add some way to bypass the random number generator and > > set the number you're trying to guess directly. This will make it a lot > > easier to test edge cases. From roy at panix.com Thu Sep 26 21:16:32 2013 From: roy at panix.com (Roy Smith) Date: Thu, 26 Sep 2013 21:16:32 -0400 Subject: Nosetests References: <32f7bdcb-97e5-4a1c-a2c8-ab91e40527a8@googlegroups.com> Message-ID: In article , melwin9 at gmail.com wrote: > Initially I was shown pexpect, leaving that there, Can i make up 5 tests? I > tried tests two different ways and no luck. What am I supposed to be writing > up when I do a test and is there a particular way I can/should be referencing > it back to its main file? I'm not sure I understand your question. Are you asking: Q1: "What tests should I be writing?" or Q2: "Once I know what I want to test, how do I implement those tests?" I'm guessing Q1, so that's what I'm going to base the rest of this post on. Before you cat write a test, you have to understand what your code is supposed to do. So, for example, let's say the specification for your program runs something like this: When you run the program, it will print, "I have chosen a number from 1-10", and then it will print, "Guess a number: ". It will then wait for input. When you type an integer, it will print either, "That's too high.", "That's too low.", or "That's right!". Now, let's look at one of your tests: def test_guessing_hi_low_4(self): # Conversation assuming number is 4 child = pe.spawn('python guess.py') child.expect(self.intro,timeout=5) child.expect(self.request,timeout=5) child.sendline('5') child.expect(self.responseHigh,timeout=5) child.sendline('3') child.expect(self.responseLow,timeout=5) child.sendline('4') child.expect(self.responseCorrect,timeout=5) child.expect(self.goodbye,timeout=5) It looks pretty reasonable up to the point where you do: child.sendline('5') child.expect(self.responseHigh,timeout=5) The problem is, you don't know what number it picked, so you can't predict what response it will have to an input of 5. This goes back to what I was saying earlier. You need some way to set the game to a known state, so you can test its responses, in that state, to various inputs. If you're going to stick with the pexpect interface, then maybe you need a command line argument to override the random number generator and set the game to a specific number. So, you can run: $ python guess.py --test 4 and now you know the number it has picked is 4. If you send it 5, it should tell you too high. If you send it 3, it should tell you too low. And so on. This is standard procedure in all kinds of testing. You need some way to set the system being tested to a known state. Then (and only then) can you apply various inputs and observe what outputs you get. This is true of hardware was well. Integrated circuits often have a "test mode", where you can set the internal state of the chip to some known configuration before you perform a test. From melwin9 at gmail.com Thu Sep 26 21:37:39 2013 From: melwin9 at gmail.com (melwin9 at gmail.com) Date: Thu, 26 Sep 2013 18:37:39 -0700 (PDT) Subject: Nosetests In-Reply-To: References: <32f7bdcb-97e5-4a1c-a2c8-ab91e40527a8@googlegroups.com> Message-ID: <8f34f1ad-656e-4d13-96a9-35abbe8c9a66@googlegroups.com> The question was more like what tests should I be writing, fine if I remove the pexpect test I tried the test_guess & test_guesstoolow and still unable to get it to work. So if i Want to ask for a number and typed a number which is at random indicated by the top of the code, how do I proceed on with my tests? On Thursday, September 26, 2013 9:16:32 PM UTC-4, Roy Smith wrote: > In article , > > wrote: > > > > > Initially I was shown pexpect, leaving that there, Can i make up 5 tests? I > > > tried tests two different ways and no luck. What am I supposed to be writing > > > up when I do a test and is there a particular way I can/should be referencing > > > it back to its main file? > > > > I'm not sure I understand your question. Are you asking: > > > > Q1: "What tests should I be writing?" > > > > or > > > > Q2: "Once I know what I want to test, how do I implement those tests?" > > > > I'm guessing Q1, so that's what I'm going to base the rest of this post > > on. Before you cat write a test, you have to understand what your code > > is supposed to do. So, for example, let's say the specification for > > your program runs something like this: > > > > When you run the program, it will print, "I have chosen a number from > > 1-10", and then it will print, "Guess a number: ". It will then wait > > for input. When you type an integer, it will print either, "That's too > > high.", "That's too low.", or "That's right!". > > > > Now, let's look at one of your tests: > > > > def test_guessing_hi_low_4(self): > > > > # Conversation assuming number is 4 > > child = pe.spawn('python guess.py') > > child.expect(self.intro,timeout=5) > > child.expect(self.request,timeout=5) > > child.sendline('5') > > child.expect(self.responseHigh,timeout=5) > > child.sendline('3') > > child.expect(self.responseLow,timeout=5) > > child.sendline('4') > > child.expect(self.responseCorrect,timeout=5) > > child.expect(self.goodbye,timeout=5) > > > > It looks pretty reasonable up to the point where you do: > > > > child.sendline('5') > > child.expect(self.responseHigh,timeout=5) > > > > The problem is, you don't know what number it picked, so you can't > > predict what response it will have to an input of 5. This goes back to > > what I was saying earlier. You need some way to set the game to a known > > state, so you can test its responses, in that state, to various inputs. > > > > If you're going to stick with the pexpect interface, then maybe you need > > a command line argument to override the random number generator and set > > the game to a specific number. So, you can run: > > > > $ python guess.py --test 4 > > > > and now you know the number it has picked is 4. If you send it 5, it > > should tell you too high. If you send it 3, it should tell you too low. > > And so on. > > > > This is standard procedure in all kinds of testing. You need some way > > to set the system being tested to a known state. Then (and only then) > > can you apply various inputs and observe what outputs you get. This is > > true of hardware was well. Integrated circuits often have a "test > > mode", where you can set the internal state of the chip to some known > > configuration before you perform a test. From melwin9 at gmail.com Fri Sep 27 00:20:52 2013 From: melwin9 at gmail.com (melwin9 at gmail.com) Date: Thu, 26 Sep 2013 21:20:52 -0700 (PDT) Subject: Nosetests In-Reply-To: <8f34f1ad-656e-4d13-96a9-35abbe8c9a66@googlegroups.com> References: <32f7bdcb-97e5-4a1c-a2c8-ab91e40527a8@googlegroups.com> <8f34f1ad-656e-4d13-96a9-35abbe8c9a66@googlegroups.com> Message-ID: I modified the guess.py file but am unable to run it, how do I go about writing tests for this. import random guessesTaken = 0 number = random.randint(1, 10) intro = 'I have chosen a number from 1-10' request = 'Guess a number: ' responseHigh = "That's too high." responseLow = "That's too low." responseCorrect = "That's right!" goodbye = 'Goodbye and thanks for playing!' print(intro) def main(): while guessesTaken < 5: print(request) guess = input() guess = int(guess) guessesTaken = guessesTaken + 1 if guess < number: print(responseLow) if guess > number: print(responseHigh) if guess == number: break if guess == number: guessesTaken = str(guessesTaken) print(responseCorrect + '! You guessed my number in ' + guessesTaken + ' guesses!') if guess != number: number = str(number) print(goodbye + ' The number I was thinking of was ' + number) ##def main(): # print(intro) # user_input = raw_input(request) # print(responseHigh) # print(request) # user_input = raw_input(request) # print(responseLow) # user_input = raw_input(request) # print(responseCorrect) # print(goodbye) if __name__ == '__main__': main() On Thursday, September 26, 2013 9:37:39 PM UTC-4, wrote: > The question was more like what tests should I be writing, fine if I remove the pexpect test I tried the test_guess & test_guesstoolow and still unable to get it to work. So if i Want to ask for a number and typed a number which is at random indicated by the top of the code, how do I proceed on with my tests? > > > > On Thursday, September 26, 2013 9:16:32 PM UTC-4, Roy Smith wrote: > > > In article , > > > > > > wrote: > > > > > > > > > > > > > Initially I was shown pexpect, leaving that there, Can i make up 5 tests? I > > > > > > > tried tests two different ways and no luck. What am I supposed to be writing > > > > > > > up when I do a test and is there a particular way I can/should be referencing > > > > > > > it back to its main file? > > > > > > > > > > > > I'm not sure I understand your question. Are you asking: > > > > > > > > > > > > Q1: "What tests should I be writing?" > > > > > > > > > > > > or > > > > > > > > > > > > Q2: "Once I know what I want to test, how do I implement those tests?" > > > > > > > > > > > > I'm guessing Q1, so that's what I'm going to base the rest of this post > > > > > > on. Before you cat write a test, you have to understand what your code > > > > > > is supposed to do. So, for example, let's say the specification for > > > > > > your program runs something like this: > > > > > > > > > > > > When you run the program, it will print, "I have chosen a number from > > > > > > 1-10", and then it will print, "Guess a number: ". It will then wait > > > > > > for input. When you type an integer, it will print either, "That's too > > > > > > high.", "That's too low.", or "That's right!". > > > > > > > > > > > > Now, let's look at one of your tests: > > > > > > > > > > > > def test_guessing_hi_low_4(self): > > > > > > > > > > > > # Conversation assuming number is 4 > > > > > > child = pe.spawn('python guess.py') > > > > > > child.expect(self.intro,timeout=5) > > > > > > child.expect(self.request,timeout=5) > > > > > > child.sendline('5') > > > > > > child.expect(self.responseHigh,timeout=5) > > > > > > child.sendline('3') > > > > > > child.expect(self.responseLow,timeout=5) > > > > > > child.sendline('4') > > > > > > child.expect(self.responseCorrect,timeout=5) > > > > > > child.expect(self.goodbye,timeout=5) > > > > > > > > > > > > It looks pretty reasonable up to the point where you do: > > > > > > > > > > > > child.sendline('5') > > > > > > child.expect(self.responseHigh,timeout=5) > > > > > > > > > > > > The problem is, you don't know what number it picked, so you can't > > > > > > predict what response it will have to an input of 5. This goes back to > > > > > > what I was saying earlier. You need some way to set the game to a known > > > > > > state, so you can test its responses, in that state, to various inputs. > > > > > > > > > > > > If you're going to stick with the pexpect interface, then maybe you need > > > > > > a command line argument to override the random number generator and set > > > > > > the game to a specific number. So, you can run: > > > > > > > > > > > > $ python guess.py --test 4 > > > > > > > > > > > > and now you know the number it has picked is 4. If you send it 5, it > > > > > > should tell you too high. If you send it 3, it should tell you too low. > > > > > > And so on. > > > > > > > > > > > > This is standard procedure in all kinds of testing. You need some way > > > > > > to set the system being tested to a known state. Then (and only then) > > > > > > can you apply various inputs and observe what outputs you get. This is > > > > > > true of hardware was well. Integrated circuits often have a "test > > > > > > mode", where you can set the internal state of the chip to some known > > > > > > configuration before you perform a test. From steve+comp.lang.python at pearwood.info Fri Sep 27 00:46:01 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Sep 2013 04:46:01 GMT Subject: Nosetests References: <32f7bdcb-97e5-4a1c-a2c8-ab91e40527a8@googlegroups.com> <8f34f1ad-656e-4d13-96a9-35abbe8c9a66@googlegroups.com> Message-ID: <52450d89$0$30000$c3e8da3$5496439d@news.astraweb.com> On Thu, 26 Sep 2013 21:20:52 -0700, melwin9 wrote: > I modified the guess.py file but am unable to run it, What does that mean? How do you try to run it? What happens when you do? -- Steven From melwin9 at gmail.com Sun Sep 29 17:28:12 2013 From: melwin9 at gmail.com (melwin9 at gmail.com) Date: Sun, 29 Sep 2013 14:28:12 -0700 (PDT) Subject: Nosetests In-Reply-To: <52450d89$0$30000$c3e8da3$5496439d@news.astraweb.com> References: <32f7bdcb-97e5-4a1c-a2c8-ab91e40527a8@googlegroups.com> <8f34f1ad-656e-4d13-96a9-35abbe8c9a66@googlegroups.com> <52450d89$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: I was actually able to fix the code and run it, now i need to run tests but idk what tests to write or how to even write it. [code] import random intro = 'I have chosen a number from 1-10' request = 'Guess a number: ' responseHigh = "That's too high." responseLow = "That's too low." responseCorrect = "That's right!" goodbye = 'Goodbye and thanks for playing!' print(intro) def main(): guessesTaken = 0 number = random.randint(1, 10) while guessesTaken < 5: print(request) guess = input() guess = int(guess) guessesTaken = guessesTaken + 1 if guess < number: print(responseLow) if guess > number: print(responseHigh) if guess == number: break if guess == number: guessesTaken = str(guessesTaken) print(responseCorrect + '! You guessed my number in ' + guessesTaken + ' guesses!') if guess != number: number = str(number) print(goodbye + ' The number I was thinking of was ' + number) ##def main(): # print(intro) # user_input = raw_input(request) # print(responseHigh) # print(request) # user_input = raw_input(request) # print(responseLow) # user_input = raw_input(request) # print(responseCorrect) # print(goodbye) if __name__ == '__main__': main() [/code] On Friday, September 27, 2013 12:46:01 AM UTC-4, Steven D'Aprano wrote: > On Thu, 26 Sep 2013 21:20:52 -0700, melwin9 wrote: > > > > > I modified the guess.py file but am unable to run it, > > > > What does that mean? > > > > How do you try to run it? > > > > What happens when you do? > > > > > > > > -- > > Steven From tjreedy at udel.edu Sun Sep 29 17:45:46 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 29 Sep 2013 17:45:46 -0400 Subject: Nosetests In-Reply-To: References: <32f7bdcb-97e5-4a1c-a2c8-ab91e40527a8@googlegroups.com> <8f34f1ad-656e-4d13-96a9-35abbe8c9a66@googlegroups.com> <52450d89$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 9/29/2013 5:28 PM, melwin9 at gmail.com wrote: > I was actually able to fix the code and run it, now i need to run tests but idk what tests to write or how to even write it. Two of us already gave you suggestions. I gave you a detailed re-write. [snip hard to test code] -- Terry Jan Reedy From nikos.gr33k at gmail.com Thu Sep 26 03:26:48 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Thu, 26 Sep 2013 10:26:48 +0300 Subject: Handling 3 operands in an expression without raising an exception Message-ID: Hello, How can i wrote the two following lines so for NOT to throw out KeyErrors when a key is missing? city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) or gi.time_zone_by_addr( os.environ['REMOTE_ADDR'] ) or "??????? ????" host = socket.gethostbyaddr( os.environ['HTTP_CF_CONNECTING_IP'] )[0] or socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or "??????? ?????????" I was under the impression that the 'or' operator was handling this in case one operand was failing but its not the case here. I believe in a KeyError is missing the expression cannot even be evaluates as Truthy or Falsy. Then i thought of os.environ.get() to default to something but then again we have 3 operand in the expression. From jpiitula at ling.helsinki.fi Thu Sep 26 03:48:10 2013 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 26 Sep 2013 10:48:10 +0300 Subject: Handling 3 operands in an expression without raising an exception References: Message-ID: ????? writes: > How can i wrote the two following lines so for NOT to throw out > KeyErrors when a key is missing? > > city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) or ... > I was under the impression that the 'or' operator was handling this > in case one operand was failing but its not the case here. "f(x) or g(x)" raises an exception if "f(x)" raises an exception, or if "f(x)" returns a false value and "g(x)" raises an exception. > Then i thought of os.environ.get() to default to something but then > again we have 3 operand in the expression. Adapt this: >>> {}.get('foo') or {'empty':''}.get('empty') or 'catchall' 'catchall' Or nest the calls this way if an empty string is a valid value: >>> {}.get('foo', {'empty':''}.get('empty', 'catchall')) '' This will compute the default values even when they are not used. From nikos.gr33k at gmail.com Thu Sep 26 03:51:59 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Thu, 26 Sep 2013 10:51:59 +0300 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: ???? 26/9/2013 10:48 ??, ?/? Jussi Piitulainen ??????: > ????? writes: > >> How can i wrote the two following lines so for NOT to throw out >> KeyErrors when a key is missing? >> >> city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) or > ... >> I was under the impression that the 'or' operator was handling this >> in case one operand was failing but its not the case here. > > "f(x) or g(x)" raises an exception if "f(x)" raises an exception, or > if "f(x)" returns a false value and "g(x)" raises an exception. > >> Then i thought of os.environ.get() to default to something but then >> again we have 3 operand in the expression. > > Adapt this: > > >>> {}.get('foo') or {'empty':''}.get('empty') or 'catchall' > 'catchall' > > Or nest the calls this way if an empty string is a valid value: > > >>> {}.get('foo', {'empty':''}.get('empty', 'catchall')) > '' > > This will compute the default values even when they are not used. > I'am sorry but i do not understand the last statements at all so i can have chnace to adapt them. From jpiitula at ling.helsinki.fi Thu Sep 26 04:12:10 2013 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 26 Sep 2013 11:12:10 +0300 Subject: Handling 3 operands in an expression without raising an exception References: Message-ID: ?????????? writes: > ??????? 26/9/2013 10:48 ????, ??/?? Jussi Piitulainen > ??????????: > ??????? writes: > > > >> How can i wrote the two following lines so for NOT to throw out > >> KeyErrors when a key is missing? > >> > >> city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) or > > ... > >> I was under the impression that the 'or' operator was handling this > >> in case one operand was failing but its not the case here. > > > > "f(x) or g(x)" raises an exception if "f(x)" raises an exception, or > > if "f(x)" returns a false value and "g(x)" raises an exception. > > > >> Then i thought of os.environ.get() to default to something but then > >> again we have 3 operand in the expression. > > > > Adapt this: > > > > >>> {}.get('foo') or {'empty':''}.get('empty') or 'catchall' > > 'catchall' > > > > Or nest the calls this way if an empty string is a valid value: > > > > >>> {}.get('foo', {'empty':''}.get('empty', 'catchall')) > > '' > > > > This will compute the default values even when they are not used. > > I'am sorry but i do not understand the last statements at all so i > can have chnace to adapt them. Do you know what {} is? Do you know what {}.get('foo') is? Do you know what x.get('foo') is if x is {}? Do you know what {'empty':''}.get('empty') is? Do you know what {'empty':''}.get('fruit') is? Do you know what (None or '' or 'catchall') is? Do you know what {}.get('foo', 'bar') is? Do you know what {}.get('foo', {}.get('bar', 'huh')) is? Do you know what ('foo'[3] or 'else') does? Do you know what ('foo' or 'else'[5]) does? Do you know how to launch an interactive Python session where you can play with such expressions until you get the hang of it? There is no substitute for that experience. Do you know that you can ask for help({}.get) or help(dict.get) or even help(os.environ.get) during such an interactive Python session, and Python (unlike Macbeth's spirits from the vasty deep) will answer? From nikos.gr33k at gmail.com Thu Sep 26 04:39:17 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Thu, 26 Sep 2013 11:39:17 +0300 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: ???? 26/9/2013 11:12 ??, ?/? Jussi Piitulainen ??????: > ????? writes: > >> ???? 26/9/2013 10:48 ??, ?/? Jussi Piitulainen >> ??????: > ???? writes: >>> >>>> How can i wrote the two following lines so for NOT to throw out >>>> KeyErrors when a key is missing? >>>> >>>> city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) or >>> ... >>>> I was under the impression that the 'or' operator was handling this >>>> in case one operand was failing but its not the case here. >>> >>> "f(x) or g(x)" raises an exception if "f(x)" raises an exception, or >>> if "f(x)" returns a false value and "g(x)" raises an exception. >>> >>>> Then i thought of os.environ.get() to default to something but then >>>> again we have 3 operand in the expression. >>> >>> Adapt this: >>> >>> >>> {}.get('foo') or {'empty':''}.get('empty') or 'catchall' >>> 'catchall' >>> >>> Or nest the calls this way if an empty string is a valid value: >>> >>> >>> {}.get('foo', {'empty':''}.get('empty', 'catchall')) >>> '' >>> >>> This will compute the default values even when they are not used. >> >> I'am sorry but i do not understand the last statements at all so i >> can have chnace to adapt them. > > Do you know what {} is? > > Do you know what {}.get('foo') is? > > Do you know what x.get('foo') is if x is {}? > > Do you know what {'empty':''}.get('empty') is? > > Do you know what {'empty':''}.get('fruit') is? > > Do you know what (None or '' or 'catchall') is? > > Do you know what {}.get('foo', 'bar') is? > > Do you know what {}.get('foo', {}.get('bar', 'huh')) is? > > Do you know what ('foo'[3] or 'else') does? > > Do you know what ('foo' or 'else'[5]) does? > > Do you know how to launch an interactive Python session where you can > play with such expressions until you get the hang of it? There is no > substitute for that experience. > > Do you know that you can ask for help({}.get) or help(dict.get) or > even help(os.environ.get) during such an interactive Python session, > and Python (unlike Macbeth's spirits from the vasty deep) will answer? > You dont have to be ironic. I dont have the experience you do. Up until now i have this: city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) or gi.time_zone_by_addr( os.environ['REMOTE_ADDR'] ) or "??????? ????" can this be written as: city = gi.time_zone_by_addr( os.environ.get('HTTP_CF_CONNECTING_IP', os.environ['REMOTE_ADDR'] )) or "??????? ????" It makes it more easily for me to understand this way. From nikos.gr33k at gmail.com Thu Sep 26 04:46:18 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Thu, 26 Sep 2013 11:46:18 +0300 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: ???? 26/9/2013 11:39 ??, ?/? ????? ??????: > ???? 26/9/2013 11:12 ??, ?/? Jussi Piitulainen ??????: >> ????? writes: >> >>> ???? 26/9/2013 10:48 ??, ?/? Jussi Piitulainen >>> ??????: > ???? writes: >>>> >>>>> How can i wrote the two following lines so for NOT to throw out >>>>> KeyErrors when a key is missing? >>>>> >>>>> city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) or >>>> ... >>>>> I was under the impression that the 'or' operator was handling this >>>>> in case one operand was failing but its not the case here. >>>> >>>> "f(x) or g(x)" raises an exception if "f(x)" raises an exception, or >>>> if "f(x)" returns a false value and "g(x)" raises an exception. >>>> >>>>> Then i thought of os.environ.get() to default to something but then >>>>> again we have 3 operand in the expression. >>>> >>>> Adapt this: >>>> >>>> >>> {}.get('foo') or {'empty':''}.get('empty') or 'catchall' >>>> 'catchall' >>>> >>>> Or nest the calls this way if an empty string is a valid value: >>>> >>>> >>> {}.get('foo', {'empty':''}.get('empty', 'catchall')) >>>> '' >>>> >>>> This will compute the default values even when they are not used. >>> >>> I'am sorry but i do not understand the last statements at all so i >>> can have chnace to adapt them. >> >> Do you know what {} is? >> >> Do you know what {}.get('foo') is? >> >> Do you know what x.get('foo') is if x is {}? >> >> Do you know what {'empty':''}.get('empty') is? >> >> Do you know what {'empty':''}.get('fruit') is? >> >> Do you know what (None or '' or 'catchall') is? >> >> Do you know what {}.get('foo', 'bar') is? >> >> Do you know what {}.get('foo', {}.get('bar', 'huh')) is? >> >> Do you know what ('foo'[3] or 'else') does? >> >> Do you know what ('foo' or 'else'[5]) does? >> >> Do you know how to launch an interactive Python session where you can >> play with such expressions until you get the hang of it? There is no >> substitute for that experience. >> >> Do you know that you can ask for help({}.get) or help(dict.get) or >> even help(os.environ.get) during such an interactive Python session, >> and Python (unlike Macbeth's spirits from the vasty deep) will answer? >> > You dont have to be ironic. I dont have the experience you do. > > Up until now i have this: > > city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) or > gi.time_zone_by_addr( os.environ['REMOTE_ADDR'] ) or "??????? ????" > > > can this be written as: > > city = gi.time_zone_by_addr( os.environ.get('HTTP_CF_CONNECTING_IP', > os.environ['REMOTE_ADDR'] )) or "??????? ????" > > It makes it more easily for me to understand this way. Let me try be more specific: i want to switch this: city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) or gi.time_zone_by_addr( os.environ['REMOTE_ADDR'] ) or "??????? ????" host = socket.gethostbyaddr( os.environ['HTTP_CF_CONNECTING_IP'] )[0] or socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or "??????? ?????????" because it raises KeyError exceptions to this: city = gi.time_zone_by_addr( os.environ.get('HTTP_CF_CONNECTING_IP', 'REMOTE_ADDR') ) or "??????? ????" host = socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP', 'REMOTE_ADDR') )[0] or "??????? ?????????" But that doesnt seem to also work. I want to use the get method because i know if it doesnt does detect a dictionary key item than default back what we give it. From nikos.gr33k at gmail.com Thu Sep 26 04:50:25 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Thu, 26 Sep 2013 11:50:25 +0300 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: ???? 26/9/2013 11:46 ??, ?/? ????? ??????: > ???? 26/9/2013 11:39 ??, ?/? ????? ??????: >> ???? 26/9/2013 11:12 ??, ?/? Jussi Piitulainen ??????: >>> ????? writes: >>> >>>> ???? 26/9/2013 10:48 ??, ?/? Jussi Piitulainen >>>> ??????: > ???? writes: >>>>> >>>>>> How can i wrote the two following lines so for NOT to throw out >>>>>> KeyErrors when a key is missing? >>>>>> >>>>>> city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) or >>>>> ... >>>>>> I was under the impression that the 'or' operator was handling this >>>>>> in case one operand was failing but its not the case here. >>>>> >>>>> "f(x) or g(x)" raises an exception if "f(x)" raises an exception, or >>>>> if "f(x)" returns a false value and "g(x)" raises an exception. >>>>> >>>>>> Then i thought of os.environ.get() to default to something but then >>>>>> again we have 3 operand in the expression. >>>>> >>>>> Adapt this: >>>>> >>>>> >>> {}.get('foo') or {'empty':''}.get('empty') or 'catchall' >>>>> 'catchall' >>>>> >>>>> Or nest the calls this way if an empty string is a valid value: >>>>> >>>>> >>> {}.get('foo', {'empty':''}.get('empty', 'catchall')) >>>>> '' >>>>> >>>>> This will compute the default values even when they are not used. >>>> >>>> I'am sorry but i do not understand the last statements at all so i >>>> can have chnace to adapt them. >>> >>> Do you know what {} is? >>> >>> Do you know what {}.get('foo') is? >>> >>> Do you know what x.get('foo') is if x is {}? >>> >>> Do you know what {'empty':''}.get('empty') is? >>> >>> Do you know what {'empty':''}.get('fruit') is? >>> >>> Do you know what (None or '' or 'catchall') is? >>> >>> Do you know what {}.get('foo', 'bar') is? >>> >>> Do you know what {}.get('foo', {}.get('bar', 'huh')) is? >>> >>> Do you know what ('foo'[3] or 'else') does? >>> >>> Do you know what ('foo' or 'else'[5]) does? >>> >>> Do you know how to launch an interactive Python session where you can >>> play with such expressions until you get the hang of it? There is no >>> substitute for that experience. >>> >>> Do you know that you can ask for help({}.get) or help(dict.get) or >>> even help(os.environ.get) during such an interactive Python session, >>> and Python (unlike Macbeth's spirits from the vasty deep) will answer? >>> >> You dont have to be ironic. I dont have the experience you do. >> >> Up until now i have this: >> >> city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) or >> gi.time_zone_by_addr( os.environ['REMOTE_ADDR'] ) or "??????? ????" >> >> >> can this be written as: >> >> city = gi.time_zone_by_addr( os.environ.get('HTTP_CF_CONNECTING_IP', >> os.environ['REMOTE_ADDR'] )) or "??????? ????" >> >> It makes it more easily for me to understand this way. > > Let me try be more specific: > > i want to switch this: > > city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) or > gi.time_zone_by_addr( os.environ['REMOTE_ADDR'] ) or "??????? ????" > > host = socket.gethostbyaddr( os.environ['HTTP_CF_CONNECTING_IP'] )[0] or > socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or "??????? ?????????" > > because it raises KeyError exceptions to this: > > city = gi.time_zone_by_addr( os.environ.get('HTTP_CF_CONNECTING_IP', > 'REMOTE_ADDR') ) or "??????? ????" > > host = socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP', > 'REMOTE_ADDR') )[0] or "??????? ?????????" > > But that doesnt seem to also work. > I want to use the get method because i know if it doesnt does detect a > dictionary key item than default back what we give it. Can you please tell me why my alternative fails to work although i'am using the .get method to default to something? From jpiitula at ling.helsinki.fi Thu Sep 26 05:20:30 2013 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 26 Sep 2013 12:20:30 +0300 Subject: Handling 3 operands in an expression without raising an exception References: Message-ID: ?????????? writes: > > because it raises KeyError exceptions to this: > > > > city = gi.time_zone_by_addr( os.environ.get('HTTP_CF_CONNECTING_IP', > > 'REMOTE_ADDR') ) or "?????????? ???????" > > > > host = socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP', > > 'REMOTE_ADDR') )[0] or "?????????? ????????????????" > > > > But that doesnt seem to also work. > > I want to use the get method because i know if it doesnt does detect a > > dictionary key item than default back what we give it. > > Can you please tell me why my alternative fails to work although i'am > using the .get method to default to something? I lost connection. Absent HTTP_CF_CONNECTING_IP in os.environ, these reduce to city = ( gi.time_zone_by_addr('REMOTE_ADDR') or "?????????? ???????" ) host = ( socket.gethostbyaddr('REMOTE_ADDR')[0] or "?????????? ????????????????" ) so maybe 'REMOTE_ADDR' is not meant to be the actual argument in those calls. Earlier versions tried to get 'REMOTE_ADDR' from os.environ, I think. Try Nobody's piecemeal approach, maybe. From jpiitula at ling.helsinki.fi Thu Sep 26 05:04:13 2013 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 26 Sep 2013 12:04:13 +0300 Subject: Handling 3 operands in an expression without raising an exception References: Message-ID: ?????????? writes: > ??????? 26/9/2013 11:12 ????, ??/?? Jussi Piitulainen > ??????????: > ??????? writes: > > > >> ????????? 26/9/2013 10:48 ????, ??/?? Jussi Piitulainen > >> ??????????????: > ????????? writes: > >>> > >>>> How can i wrote the two following lines so for NOT to throw out > >>>> KeyErrors when a key is missing? > >>>> > >>>> city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) or > >>> ... > >>>> I was under the impression that the 'or' operator was handling this > >>>> in case one operand was failing but its not the case here. > >>> > >>> "f(x) or g(x)" raises an exception if "f(x)" raises an exception, or > >>> if "f(x)" returns a false value and "g(x)" raises an exception. > >>> > >>>> Then i thought of os.environ.get() to default to something but then > >>>> again we have 3 operand in the expression. > >>> > >>> Adapt this: > >>> > >>> >>> {}.get('foo') or {'empty':''}.get('empty') or 'catchall' > >>> 'catchall' > >>> > >>> Or nest the calls this way if an empty string is a valid value: > >>> > >>> >>> {}.get('foo', {'empty':''}.get('empty', 'catchall')) > >>> '' > >>> > >>> This will compute the default values even when they are not used. > >> > >> I'am sorry but i do not understand the last statements at all so i > >> can have chnace to adapt them. > > > > Do you know what {} is? > > > > Do you know what {}.get('foo') is? > > > > Do you know what x.get('foo') is if x is {}? > > > > Do you know what {'empty':''}.get('empty') is? > > > > Do you know what {'empty':''}.get('fruit') is? > > > > Do you know what (None or '' or 'catchall') is? > > > > Do you know what {}.get('foo', 'bar') is? > > > > Do you know what {}.get('foo', {}.get('bar', 'huh')) is? > > > > Do you know what ('foo'[3] or 'else') does? > > > > Do you know what ('foo' or 'else'[5]) does? > > > > Do you know how to launch an interactive Python session where you can > > play with such expressions until you get the hang of it? There is no > > substitute for that experience. > > > > Do you know that you can ask for help({}.get) or help(dict.get) or > > even help(os.environ.get) during such an interactive Python session, > > and Python (unlike Macbeth's spirits from the vasty deep) will answer? > > You dont have to be ironic. I dont have the experience you do. Not ironic. Such questions really are how I learn and test my own understanding, and all of the questions above are tailored to your current specific problem. They are meant to help you. But you should know the answers to such questions, even if you learn them in some altogether different way. This is basic stuff. > Up until now i have this: > > city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) or > gi.time_zone_by_addr( os.environ['REMOTE_ADDR'] ) or > "?????????? ???????" > > > can this be written as: > > city = gi.time_zone_by_addr( os.environ.get('HTTP_CF_CONNECTING_IP', > os.environ['REMOTE_ADDR'] )) or "?????????? > ???????" > > It makes it more easily for me to understand this way. That will always get os.environ['REMOTE_ADDR'] and raise exception if it doesn't exist. Maybe you want this: city = gi.time_zone_by_addr(os.environ.get('HTTP_CF_CONNECTING_IP') or os.environ.get('REMOTE_ADDR') or "??????????????????") Though I would prefer a narrower layout this way: something = ( os.environ.get('HTTP_CF_CONNECTING_IP') or os.environ.get('REMOTE_ADDR') or "??????????????????" ) city = gi.time_zone_by_addr(something) From nikos.gr33k at gmail.com Thu Sep 26 05:45:54 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Thu, 26 Sep 2013 12:45:54 +0300 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: ???? 26/9/2013 12:04 ??, ?/? Jussi Piitulainen ??????: >> Up until now i have this: >> >> city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) or >> gi.time_zone_by_addr( os.environ['REMOTE_ADDR'] ) or >> "??????? ????" >> >> >> can this be written as: >> >> city = gi.time_zone_by_addr( os.environ.get('HTTP_CF_CONNECTING_IP', >> os.environ['REMOTE_ADDR'] )) or "??????? >> ????" >> >> It makes it more easily for me to understand this way. > > That will always get os.environ['REMOTE_ADDR'] and raise exception if > it doesn't exist. > > Maybe you want this: > > city = gi.time_zone_by_addr(os.environ.get('HTTP_CF_CONNECTING_IP') or > os.environ.get('REMOTE_ADDR') or > "????????????") Okey that indeed doesn't hit on that lines. Now my statements are as follows: city = gi.time_zone_by_addr( os.environ.get('HTTP_CF_CONNECTING_IP') or os.environ.get('REMOTE_ADDR') or "??????? ????" ) host = socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or os.environ.get('REMOTE_ADDR') or "??????? ?????????" ) So you include everything in aprenthseis with a get method that you know beforehand it will not raise an exception but continue to check the next operand and the next until it default to the string. Its more clear this way: but look. this way now produced a weird error few line slater when 'host' is tryign to be identefied by 're'. [Thu Sep 26 09:44:39 2013] [error] [client 108.162.250.63] File "/home/nikos/public_html/cgi-bin/metrites.py", line 181, in [Thu Sep 26 09:44:39 2013] [error] [client 108.162.250.63] if not vip and re.search( r'(msn|gator|amazon|yandex|reverse|who|cloudflare|fetch|barracuda|spider|google|crawl|pingdom)', host ) is None: [Thu Sep 26 09:44:39 2013] [error] [client 108.162.250.63] File "/usr/local/bin/python/lib/python3.3/re.py", line 161, in search [Thu Sep 26 09:44:39 2013] [error] [client 108.162.250.63] return _compile(pattern, flags).search(string) [Thu Sep 26 09:44:39 2013] [error] [client 108.162.250.63] TypeError: expected string or buffer From antoon.pardon at rece.vub.ac.be Thu Sep 26 05:07:29 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 26 Sep 2013 11:07:29 +0200 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: <5243F951.3060400@rece.vub.ac.be> Op 26-09-13 10:39, ????? schreef: > ???? 26/9/2013 11:12 ??, ?/? Jussi Piitulainen ??????: >> ????? writes: >> >>> ???? 26/9/2013 10:48 ??, ?/? Jussi Piitulainen >>> ??????: > ???? writes: >>>> >>>>> How can i wrote the two following lines so for NOT to throw out >>>>> KeyErrors when a key is missing? >>>>> >>>>> city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) or >>>> ... >>>>> I was under the impression that the 'or' operator was handling this >>>>> in case one operand was failing but its not the case here. >>>> >>>> "f(x) or g(x)" raises an exception if "f(x)" raises an exception, or >>>> if "f(x)" returns a false value and "g(x)" raises an exception. >>>> >>>>> Then i thought of os.environ.get() to default to something but then >>>>> again we have 3 operand in the expression. >>>> >>>> Adapt this: >>>> >>>> >>> {}.get('foo') or {'empty':''}.get('empty') or 'catchall' >>>> 'catchall' >>>> >>>> Or nest the calls this way if an empty string is a valid value: >>>> >>>> >>> {}.get('foo', {'empty':''}.get('empty', 'catchall')) >>>> '' >>>> >>>> This will compute the default values even when they are not used. >>> >>> I'am sorry but i do not understand the last statements at all so i >>> can have chnace to adapt them. >> >> Do you know what {} is? >> >> Do you know what {}.get('foo') is? >> >> Do you know what x.get('foo') is if x is {}? >> >> Do you know what {'empty':''}.get('empty') is? >> >> Do you know what {'empty':''}.get('fruit') is? >> >> Do you know what (None or '' or 'catchall') is? >> >> Do you know what {}.get('foo', 'bar') is? >> >> Do you know what {}.get('foo', {}.get('bar', 'huh')) is? >> >> Do you know what ('foo'[3] or 'else') does? >> >> Do you know what ('foo' or 'else'[5]) does? >> >> Do you know how to launch an interactive Python session where you can >> play with such expressions until you get the hang of it? There is no >> substitute for that experience. >> >> Do you know that you can ask for help({}.get) or help(dict.get) or >> even help(os.environ.get) during such an interactive Python session, >> and Python (unlike Macbeth's spirits from the vasty deep) will answer? >> > You dont have to be ironic. I dont have the experience you do. That is irrelevant. For the responsibility you have taken upon yourself, it seems you should have experience enough to figure this out. If you can't, you just are not up for the job. > Up until now i have this: > > city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) or > gi.time_zone_by_addr( os.environ['REMOTE_ADDR'] ) or "??????? ????" > > > can this be written as: > > city = gi.time_zone_by_addr( os.environ.get('HTTP_CF_CONNECTING_IP', > os.environ['REMOTE_ADDR'] )) or "??????? ????" > > It makes it more easily for me to understand this way. Experiment and find out for yourself. That is the only way you will acquire the experience and understanding you need. Sure we could spoon feed you the line you need, but that will only result in you using that line without any understanding of what you are doing so that if in a few months time something goes wrong, you again will have no understanding of what goes on and still will have no clue on how to handle a problem. -- Antoon Pardon From nikos.gr33k at gmail.com Thu Sep 26 05:31:29 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Thu, 26 Sep 2013 12:31:29 +0300 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: ???? 26/9/2013 12:07 ??, ?/? Antoon Pardon ??????: > Experiment and find out for yourself. That is the only way you will > acquire the experience and understanding you need. Sure we could > spoon feed you the line you need, but that will only result in you > using that line without any understanding of what you are doing so > that if in a few months time something goes wrong, you again will > have no understanding of what goes on and still will have no clue > on how to handle a problem. I have tried code and also provided alternative code to solve my problem which also doesn't solve it. So, you cannot accuse me that i'm not trying, that would be the case to just ask for a line without trying anything for myself, which i did twice. Then i got entirely stuck and i had to ask to get unstuck. Also when a solution is being provided to me i do not only want to use it but want to understand too, so if something similar comes up i will be in a position to solve it that time. From maarten.sneep at knmi.nl Thu Sep 26 05:52:49 2013 From: maarten.sneep at knmi.nl (Maarten) Date: Thu, 26 Sep 2013 02:52:49 -0700 (PDT) Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: On Thursday, September 26, 2013 11:31:29 AM UTC+2, Ferrous Cranus wrote: > I have tried code and also provided alternative code to solve my problem > which also doesn't solve it. > > So, you cannot accuse me that i'm not trying, that would be the case to > just ask for a line without trying anything for myself, which i did twice. I'll accuse you of being a dimwit. The questions you ask do not show you trying. The code that _is_ posted is not straightforward or geared towards readability. > Also when a solution is being provided to me i do not only want to use > it but want to understand too, so if something similar comes up i will > be in a position to solve it that time. If you really want to do that, then why do you insist on one-liners? Write out the logic with a sequence of if statements. That is easy to understand, gives clearer error messages. The solution by Nobody is fairly foolproof, and the logic is clear. What's not to like? Maarten From antoon.pardon at rece.vub.ac.be Thu Sep 26 06:01:28 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 26 Sep 2013 12:01:28 +0200 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: <524405F8.6080409@rece.vub.ac.be> Op 26-09-13 11:31, ????? schreef: > ???? 26/9/2013 12:07 ??, ?/? Antoon Pardon ??????: >> Experiment and find out for yourself. That is the only way you will >> acquire the experience and understanding you need. Sure we could >> spoon feed you the line you need, but that will only result in you >> using that line without any understanding of what you are doing so >> that if in a few months time something goes wrong, you again will >> have no understanding of what goes on and still will have no clue >> on how to handle a problem. > > I have tried code and also provided alternative code to solve my problem > which also doesn't solve it. Have you tried with some kind of understanding of what you are doing or did you just tried variations of examples you saw somewhere? > So, you cannot accuse me that i'm not trying, that would be the case to > just ask for a line without trying anything for myself, which i did twice. That seems totally insufficient. > Then i got entirely stuck and i had to ask to get unstuck. That is your problem. You are putting all your energy in trying to get unstuck instead of in learning so that you gain enough understanding to get yourself unstuck. > Also when a solution is being provided to me i do not only want to use > it but want to understand too, so if something similar comes up i will > be in a position to solve it that time. You have shown no evidence that this is how you operate in reality. You like to paint yourself like this, but in reality people still have to explain to you that when you encouter a syntax error, you may have to look at previous lines, while that was already explained to you a number of times. You have a history of coming with the same kind of problem than previous once that were solved and explained to you. -- Antoon Pardon From james.harris.1 at gmail.com Thu Sep 26 06:53:03 2013 From: james.harris.1 at gmail.com (James Harris) Date: Thu, 26 Sep 2013 11:53:03 +0100 Subject: Handling 3 operands in an expression without raising an exception References: Message-ID: "?????" wrote in message news:l20utg$278$1 at dont-email.me... > ???? 26/9/2013 12:07 ??, ?/? Antoon Pardon ??????: >> Experiment and find out for yourself. That is the only way you will >> acquire the experience and understanding you need. Sure we could >> spoon feed you the line you need, but that will only result in you >> using that line without any understanding of what you are doing so >> that if in a few months time something goes wrong, you again will >> have no understanding of what goes on and still will have no clue >> on how to handle a problem. > > I have tried code and also provided alternative code to solve my problem > which also doesn't solve it. > > So, you cannot accuse me that i'm not trying, that would be the case to > just ask for a line without trying anything for myself, which i did twice. Agreed. You did post the work you had already done which seems reasonable to me. For your first example, because you are worried about key errors maybe you could code something like the following. try: city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) except KeyError: try: city = gi.time_zone_by_addr( os.environ['REMOTE_ADDR'] ) except KeyError: city = "??????? ????" Does that help? James From wuwei23 at gmail.com Thu Sep 26 20:05:53 2013 From: wuwei23 at gmail.com (alex23) Date: Fri, 27 Sep 2013 10:05:53 +1000 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: On 26/09/2013 6:39 PM, ????? wrote: > You dont have to be ironic. I dont have the experience you do. This is bulshytt. You only just a few days ago started a thread in which handling lookups in dictionaries with potentially non-existent keys was dealt with. At length. And now you're restructuring pretty much the exact same question to troll the list. Again. You're either not reading what people are saying, not trying to understand things by working with simpler examples at the interpreter, or just flat out lying. In any case, you're not acting in good faith. From rosuav at gmail.com Thu Sep 26 04:41:31 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 Sep 2013 18:41:31 +1000 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: On Thu, Sep 26, 2013 at 6:12 PM, Jussi Piitulainen wrote: > Do you know that you can ask for help({}.get) or help(dict.get) or > even help(os.environ.get) during such an interactive Python session, > and Python (unlike Macbeth's spirits from the vasty deep) will answer? Speak, Python, speak! We're all attention. The news we seek This moment mention! ChrisA From mail at timgolden.me.uk Thu Sep 26 04:47:59 2013 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 26 Sep 2013 09:47:59 +0100 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: <5243F4BF.2060205@timgolden.me.uk> On 26/09/2013 09:41, Chris Angelico wrote: > On Thu, Sep 26, 2013 at 6:12 PM, Jussi Piitulainen > wrote: >> Do you know that you can ask for help({}.get) or help(dict.get) or >> even help(os.environ.get) during such an interactive Python session, >> and Python (unlike Macbeth's spirits from the vasty deep) will answer? > > Speak, Python, speak! > We're all attention. > The news we seek > This moment mention! I remember when I saw that in a production in Altrincham, the Prince threw off his cloak dramatically to step forward-- and the clasp caught on some part of his costume, reducing the effect somewhat as the cloak dragged along behind. (In the end some other cast member came forward and just ripped it free). [G&S The Gondoliers, for those who weren't following along] TJG From nobody at nowhere.com Thu Sep 26 04:55:29 2013 From: nobody at nowhere.com (Nobody) Date: Thu, 26 Sep 2013 09:55:29 +0100 Subject: Handling 3 operands in an expression without raising an exception References: Message-ID: On Thu, 26 Sep 2013 10:26:48 +0300, ????? wrote: > How can i wrote the two following lines so for NOT to throw out > KeyErrors when a key is missing? > > city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) or > gi.time_zone_by_addr( os.environ['REMOTE_ADDR'] ) or > "?????????????? ? ??????" tz = None ip = os.environ.get('HTTP_CF_CONNECTING_IP') if ip: tz = gi.time_zone_by_addr(ip) if not tz: ip = os.environ.get('REMOTE_ADDR') if ip: tz = gi.time_zone_by_addr(ip) if not tz: tz = "?????????? ? ?????" Likewise for the hostname. From nikos.gr33k at gmail.com Thu Sep 26 05:56:19 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Thu, 26 Sep 2013 12:56:19 +0300 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: ???? 26/9/2013 11:55 ??, ?/? Nobody ??????: > On Thu, 26 Sep 2013 10:26:48 +0300, ????? wrote: > >> How can i wrote the two following lines so for NOT to throw out >> KeyErrors when a key is missing? >> >> city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) or >> gi.time_zone_by_addr( os.environ['REMOTE_ADDR'] ) or >> "?????????????? ? ??????" > > tz = None > ip = os.environ.get('HTTP_CF_CONNECTING_IP') > if ip: > tz = gi.time_zone_by_addr(ip) > if not tz: > ip = os.environ.get('REMOTE_ADDR') > if ip: > tz = gi.time_zone_by_addr(ip) > if not tz: > tz = "?????????? ? ?????" > > Likewise for the hostname. > Its logic is simple and straightforward but too many lines: host = socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or os.environ.get('REMOTE_ADDR') or "??????? ?????????" ) this is much better in my opinion and straighforward also and more clear to read: it doens't work though: ima thinkin that the [0] is missign at the end so i cna grab the first item of the returnign tuple: host = socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or os.environ.get('REMOTE_ADDR') or "??????? ?????????" )[0] for the first two element if they are beign return i cna understand the [0] at the end but what about if the string is being return wouldnt that return just the 'A' of the string? Is it correct to write it liek this? From antoon.pardon at rece.vub.ac.be Thu Sep 26 06:12:23 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 26 Sep 2013 12:12:23 +0200 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: <52440887.8090902@rece.vub.ac.be> Op 26-09-13 11:56, ????? schreef: > ???? 26/9/2013 11:55 ??, ?/? Nobody ??????: >> On Thu, 26 Sep 2013 10:26:48 +0300, ????? wrote: >> >>> How can i wrote the two following lines so for NOT to throw out >>> KeyErrors when a key is missing? >>> >>> city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) or >>> gi.time_zone_by_addr( os.environ['REMOTE_ADDR'] ) or >>> "?????????????? ? ??????" >> >> tz = None >> ip = os.environ.get('HTTP_CF_CONNECTING_IP') >> if ip: >> tz = gi.time_zone_by_addr(ip) >> if not tz: >> ip = os.environ.get('REMOTE_ADDR') >> if ip: >> tz = gi.time_zone_by_addr(ip) >> if not tz: >> tz = "?????????? ? ?????" >> >> Likewise for the hostname. >> > > Its logic is simple and straightforward but too many lines: > > host = socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or > os.environ.get('REMOTE_ADDR') or "??????? ?????????" ) > > this is much better in my opinion and straighforward also and more clear > to read: No it is not and you prove that in the very next line. > it doens't work though: If it doesn't do what you think it should do then it is not straight forward or clear, at least not to you. -- Antoon Pardon From nikos.gr33k at gmail.com Thu Sep 26 06:18:41 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Thu, 26 Sep 2013 13:18:41 +0300 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: ???? 26/9/2013 1:12 ??, ?/? Antoon Pardon ??????: > Op 26-09-13 11:56, ????? schreef: >> ???? 26/9/2013 11:55 ??, ?/? Nobody ??????: >>> On Thu, 26 Sep 2013 10:26:48 +0300, ????? wrote: >>> >>>> How can i wrote the two following lines so for NOT to throw out >>>> KeyErrors when a key is missing? >>>> >>>> city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) or >>>> gi.time_zone_by_addr( os.environ['REMOTE_ADDR'] ) or >>>> "?????????????? ? ??????" >>> >>> tz = None >>> ip = os.environ.get('HTTP_CF_CONNECTING_IP') >>> if ip: >>> tz = gi.time_zone_by_addr(ip) >>> if not tz: >>> ip = os.environ.get('REMOTE_ADDR') >>> if ip: >>> tz = gi.time_zone_by_addr(ip) >>> if not tz: >>> tz = "?????????? ? ?????" >>> >>> Likewise for the hostname. >>> >> >> Its logic is simple and straightforward but too many lines: >> >> host = socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or >> os.environ.get('REMOTE_ADDR') or "??????? ?????????" ) >> >> this is much better in my opinion and straighforward also and more clear >> to read: > > No it is not and you prove that in the very next line. > >> it doens't work though: > > If it doesn't do what you think it should do then it is not straight > forward or clear, at least not to you. It is far better than the ifs, even easier to read, i was just missing a [0] at the end. host = socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or os.environ.get('REMOTE_ADDR') or "??????? ?????????" )[0] From antoon.pardon at rece.vub.ac.be Thu Sep 26 06:41:16 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 26 Sep 2013 12:41:16 +0200 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: <52440F4C.5000707@rece.vub.ac.be> Op 26-09-13 12:18, ????? schreef: > ???? 26/9/2013 1:12 ??, ?/? Antoon Pardon ??????: >> Op 26-09-13 11:56, ????? schreef: >>> ???? 26/9/2013 11:55 ??, ?/? Nobody ??????: >>>> On Thu, 26 Sep 2013 10:26:48 +0300, ????? wrote: >>>> >>>>> How can i wrote the two following lines so for NOT to throw out >>>>> KeyErrors when a key is missing? >>>>> >>>>> city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) or >>>>> gi.time_zone_by_addr( os.environ['REMOTE_ADDR'] ) or >>>>> "?????????????? ? ??????" >>>> >>>> tz = None >>>> ip = os.environ.get('HTTP_CF_CONNECTING_IP') >>>> if ip: >>>> tz = gi.time_zone_by_addr(ip) >>>> if not tz: >>>> ip = os.environ.get('REMOTE_ADDR') >>>> if ip: >>>> tz = gi.time_zone_by_addr(ip) >>>> if not tz: >>>> tz = "?????????? ? ?????" >>>> >>>> Likewise for the hostname. >>>> >>> >>> Its logic is simple and straightforward but too many lines: >>> >>> host = socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or >>> os.environ.get('REMOTE_ADDR') or "??????? ?????????" ) >>> >>> this is much better in my opinion and straighforward also and more clear >>> to read: >> >> No it is not and you prove that in the very next line. >> >>> it doens't work though: >> >> If it doesn't do what you think it should do then it is not straight >> forward or clear, at least not to you. > > It is far better than the ifs, even easier to read, i was just missing a > [0] at the end. > > host = socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or > os.environ.get('REMOTE_ADDR') or "??????? ?????????" )[0] No it is not. Your purpose was to have a line that wouldn't throw an exception even if some environ variables were not available. That means it shouldn't throw an exception when I execute the code. Guess what happens: >>> socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or os.environ.get('REMOTE_ADDR') or "??????? ?????????" )[0] Traceback (most recent call last): File "", line 1, in socket.gaierror: [Errno -2] Name or service not known You are just illustrating your lack of basic understaning. -- Antoon Pardon From nikos.gr33k at gmail.com Thu Sep 26 06:51:39 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Thu, 26 Sep 2013 13:51:39 +0300 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: ???? 26/9/2013 1:41 ??, ?/? Antoon Pardon ??????: > Op 26-09-13 12:18, ????? schreef: >> ???? 26/9/2013 1:12 ??, ?/? Antoon Pardon ??????: >>> Op 26-09-13 11:56, ????? schreef: >>>> ???? 26/9/2013 11:55 ??, ?/? Nobody ??????: >>>>> On Thu, 26 Sep 2013 10:26:48 +0300, ????? wrote: >>>>> >>>>>> How can i wrote the two following lines so for NOT to throw out >>>>>> KeyErrors when a key is missing? >>>>>> >>>>>> city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) or >>>>>> gi.time_zone_by_addr( os.environ['REMOTE_ADDR'] ) or >>>>>> "?????????????? ? ??????" >>>>> >>>>> tz = None >>>>> ip = os.environ.get('HTTP_CF_CONNECTING_IP') >>>>> if ip: >>>>> tz = gi.time_zone_by_addr(ip) >>>>> if not tz: >>>>> ip = os.environ.get('REMOTE_ADDR') >>>>> if ip: >>>>> tz = gi.time_zone_by_addr(ip) >>>>> if not tz: >>>>> tz = "?????????? ? ?????" >>>>> >>>>> Likewise for the hostname. >>>>> >>>> >>>> Its logic is simple and straightforward but too many lines: >>>> >>>> host = socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or >>>> os.environ.get('REMOTE_ADDR') or "??????? ?????????" ) >>>> >>>> this is much better in my opinion and straighforward also and more clear >>>> to read: >>> >>> No it is not and you prove that in the very next line. >>> >>>> it doens't work though: >>> >>> If it doesn't do what you think it should do then it is not straight >>> forward or clear, at least not to you. >> >> It is far better than the ifs, even easier to read, i was just missing a >> [0] at the end. >> >> host = socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or >> os.environ.get('REMOTE_ADDR') or "??????? ?????????" )[0] > > No it is not. Your purpose was to have a line that wouldn't throw an > exception even if some environ variables were not available. That > means it shouldn't throw an exception when I execute the code. Guess > what happens: > >>>> socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or > os.environ.get('REMOTE_ADDR') or "??????? ?????????" )[0] > Traceback (most recent call last): > File "", line 1, in > socket.gaierror: [Errno -2] Name or service not known > > You are just illustrating your lack of basic understaning. I'm surepirsed, becaus eon my domain [superhost.gr] the same lien of code works withnout an error and it display the 'host' fileds properly. Perhaps its failing via shell or you do not have a web server installed to prepare the enviromental variables or i dont know what else to hink. But in my website this code runs at the probelm with no problem. From antoon.pardon at rece.vub.ac.be Thu Sep 26 07:07:51 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 26 Sep 2013 13:07:51 +0200 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: <52441587.5060001@rece.vub.ac.be> Op 26-09-13 12:51, ????? schreef: > ???? 26/9/2013 1:41 ??, ?/? Antoon Pardon ??????: >> Op 26-09-13 12:18, ????? schreef: >>> ???? 26/9/2013 1:12 ??, ?/? Antoon Pardon ??????: >>>> Op 26-09-13 11:56, ????? schreef: >>> >>> It is far better than the ifs, even easier to read, i was just missing a >>> [0] at the end. >>> >>> host = socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or >>> os.environ.get('REMOTE_ADDR') or "??????? ?????????" )[0] >> >> No it is not. Your purpose was to have a line that wouldn't throw an >> exception even if some environ variables were not available. That >> means it shouldn't throw an exception when I execute the code. Guess >> what happens: >> >>>>> socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or >> os.environ.get('REMOTE_ADDR') or "??????? ?????????" )[0] >> Traceback (most recent call last): >> File "", line 1, in >> socket.gaierror: [Errno -2] Name or service not known >> >> You are just illustrating your lack of basic understaning. > > I'm surepirsed, becaus eon my domain [superhost.gr] the same lien of > code works withnout an error and it display the 'host' fileds properly. You shoudn't be. This illustrates beautifully the difference between understanding what one is doing and dabbling around until one stumbles on something that currently works but that will stop working in other circumstances. > Perhaps its failing via shell or you do not have a web server installed > to prepare the enviromental variables or i dont know what else to hink. Yes it is failing via shell, but that doesn't matter. If your purpose was to have that line working even if the environ variables were not available, then the line should work from a shell too. > But in my website this code runs at the probelm with no problem. So? That just means that your website is not a good test environment for checking whether the code works under all circumstances you want it to work. -- Antoon Pardon From davea at davea.name Thu Sep 26 07:24:57 2013 From: davea at davea.name (Dave Angel) Date: Thu, 26 Sep 2013 11:24:57 +0000 (UTC) Subject: Handling 3 operands in an expression without raising an exception References: Message-ID: On 26/9/2013 06:51, ????? wrote: >>>>> socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or >> os.environ.get('REMOTE_ADDR') or "??????? ?????????" )[0] >> Traceback (most recent call last): >> File "", line 1, in >> socket.gaierror: [Errno -2] Name or service not known >> >> You are just illustrating your lack of basic understaning. > > I'm surepirsed, becaus eon my domain [superhost.gr] the same lien of > code works withnout an error and it display the 'host' fileds properly. > > Perhaps its failing via shell or you do not have a web server installed > to prepare the enviromental variables or i dont know what else to hink. > > But in my website this code runs at the probelm with no problem. > In Python 3.3, but not on a web server, I get: >>> import socket >>> socket.gethostbyaddr("unknown")[0] Traceback (most recent call last): File "", line 1, in socket.gaierror: [Errno -2] Name or service not known >>> Question, do you get the same result on your server? (You can put the Greek string in place of "unknown" of course) If so, then the default value makes no sense; it'll cause an exception if it's ever used. If you insist on sticking to expressions (no try/catch, no if statements), then perhaps you should default to a string representing a domain which will always exist. -- DaveA From nikos.gr33k at gmail.com Thu Sep 26 07:25:55 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Thu, 26 Sep 2013 14:25:55 +0300 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: ???? 26/9/2013 2:07 ??, ?/? Antoon Pardon ??????: > Op 26-09-13 12:51, ????? schreef: >> ???? 26/9/2013 1:41 ??, ?/? Antoon Pardon ??????: >>> Op 26-09-13 12:18, ????? schreef: >>>> ???? 26/9/2013 1:12 ??, ?/? Antoon Pardon ??????: >>>>> Op 26-09-13 11:56, ????? schreef: >>>> >>>> It is far better than the ifs, even easier to read, i was just missing a >>>> [0] at the end. >>>> >>>> host = socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or >>>> os.environ.get('REMOTE_ADDR') or "??????? ?????????" )[0] >>> >>> No it is not. Your purpose was to have a line that wouldn't throw an >>> exception even if some environ variables were not available. That >>> means it shouldn't throw an exception when I execute the code. Guess >>> what happens: >>> >>>>>> socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or >>> os.environ.get('REMOTE_ADDR') or "??????? ?????????" )[0] >>> Traceback (most recent call last): >>> File "", line 1, in >>> socket.gaierror: [Errno -2] Name or service not known >>> >>> You are just illustrating your lack of basic understaning. >> >> I'm surepirsed, becaus eon my domain [superhost.gr] the same lien of >> code works withnout an error and it display the 'host' fileds properly. > > You shoudn't be. This illustrates beautifully the difference between > understanding what one is doing and dabbling around until one stumbles > on something that currently works but that will stop working in other > circumstances. > >> Perhaps its failing via shell or you do not have a web server installed >> to prepare the enviromental variables or i dont know what else to hink. > > Yes it is failing via shell, but that doesn't matter. If your purpose > was to have that line working even if the environ variables were not > available, then the line should work from a shell too. > >> But in my website this code runs at the probelm with no problem. > > So? That just means that your website is not a good test environment > for checking whether the code works under all circumstances you want > it to work. > Okey then please tell me, what do you see wrong in it: socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or os.environ.get('REMOTE_ADDR') or "??????? ?????????" )[0] the [0] at then end in case the statemnt default to the string? please tell me in details what might go wrong with it so i cna understand it. From antoon.pardon at rece.vub.ac.be Thu Sep 26 07:47:23 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 26 Sep 2013 13:47:23 +0200 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: <52441ECB.8060404@rece.vub.ac.be> Op 26-09-13 13:25, ????? schreef: >> > Okey then please tell me, what do you see wrong in it: > > socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or > os.environ.get('REMOTE_ADDR') or "??????? ?????????" )[0] > > the [0] at then end in case the statemnt default to the string? > please tell me in details what might go wrong with it so i cna > understand it. Startup python and try to figure it out yourself. Show us you can really learn something. -- Antoon Pardon From denismfmcmahon at gmail.com Thu Sep 26 10:42:55 2013 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Thu, 26 Sep 2013 14:42:55 +0000 (UTC) Subject: Handling 3 operands in an expression without raising an exception References: Message-ID: On Thu, 26 Sep 2013 14:25:55 +0300, ????? wrote: > Okey then please tell me, what do you see wrong in it: > > socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') If os.environ.get('HTTP_CF_CONNECTING_IP') is false > or os.environ.get('REMOTE_ADDR') and os.environ.get('REMOTE_ADDR') is false > or "??????? ?????????" )[0] The you try and get the host name from the ip address "??????? ?????????", but "??????? ?????????" is not an ip address, so you get an error. -- Denis McMahon, denismfmcmahon at gmail.com From nikos.gr33k at gmail.com Thu Sep 26 08:39:22 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Thu, 26 Sep 2013 15:39:22 +0300 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: ???? 26/9/2013 2:24 ??, ?/? Dave Angel ??????: > On 26/9/2013 06:51, ????? wrote: > > >>>>>> socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or >>> os.environ.get('REMOTE_ADDR') or "??????? ?????????" )[0] >>> Traceback (most recent call last): >>> File "", line 1, in >>> socket.gaierror: [Errno -2] Name or service not known >>> >>> You are just illustrating your lack of basic understaning. >> >> I'm surepirsed, becaus eon my domain [superhost.gr] the same lien of >> code works withnout an error and it display the 'host' fileds properly. >> >> Perhaps its failing via shell or you do not have a web server installed >> to prepare the enviromental variables or i dont know what else to hink. >> >> But in my website this code runs at the probelm with no problem. >> > In Python 3.3, but not on a web server, I get: > > >>>> import socket >>>> socket.gethostbyaddr("unknown")[0] > Traceback (most recent call last): > File "", line 1, in > socket.gaierror: [Errno -2] Name or service not known >>>> > > Question, do you get the same result on your server? (You can put the > Greek string in place of "unknown" of course) > > If so, then the default value makes no sense; it'll cause an exception > if it's ever used. If you insist on sticking to expressions (no > try/catch, no if statements), then perhaps you should default to a > string representing a domain which will always exist. Yes, you are right, in my shell it fails too givign the same error message as yours, while on the other had in the websste is working. Can you explain this please? why doesnt it fail to both enviroments? From antoon.pardon at rece.vub.ac.be Thu Sep 26 08:53:39 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 26 Sep 2013 14:53:39 +0200 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: <52442E53.3050508@rece.vub.ac.be> Op 26-09-13 14:39, ????? schreef: > Yes, you are right, in my shell it fails too givign the same error > message as yours, while on the other had in the websste is working. > > Can you explain this please? > why doesnt it fail to both enviroments? Your site and your shell are two different environments. The state of the website environment lets your code succeed while the state of the shell environment, doesn't. -- Antoon Pardon From nikos.gr33k at gmail.com Thu Sep 26 09:34:55 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Thu, 26 Sep 2013 16:34:55 +0300 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: ???? 26/9/2013 3:53 ??, ?/? Antoon Pardon ??????: > Op 26-09-13 14:39, ????? schreef: >> Yes, you are right, in my shell it fails too givign the same error >> message as yours, while on the other had in the websste is working. >> >> Can you explain this please? >> why doesnt it fail to both enviroments? > > Your site and your shell are two different environments. The state > of the website environment lets your code succeed while the state > of the shell environment, doesn't. > What modification does it need to also work in the shell environmentthe [0] at the end is what complicates things. From davea at davea.name Thu Sep 26 10:22:29 2013 From: davea at davea.name (Dave Angel) Date: Thu, 26 Sep 2013 14:22:29 +0000 (UTC) Subject: Handling 3 operands in an expression without raising an exception References: Message-ID: On 26/9/2013 09:34, ????? wrote: > ???? 26/9/2013 3:53 ??, ?/? Antoon Pardon ??????: >> Op 26-09-13 14:39, ????? schreef: >>> Yes, you are right, in my shell it fails too givign the same error >>> message as yours, while on the other had in the websste is working. >>> >>> Can you explain this please? >>> why doesnt it fail to both enviroments? >> >> Your site and your shell are two different environments. The state >> of the website environment lets your code succeed while the state >> of the shell environment, doesn't. >> > What modification does it need to also work in the shell environmentthe > [0] at the end is what complicates things. Not at all. What complicates/confuses things is trying to do too much in one line. The line is trying to solve two separate things. You might now understand the first of them; the fetching of multiple environment variables that may or may not exist. The second thing is the function call to gethostbyname(). If fed invalid data, this call will throw an exception. So you need to either put it in a try/catch or somehow pretend that you can know what constitutes invalid data. One example of invalid data is your default string. Another might be if one of those environment variables exists, but isn't reasonable. And a third might be if the domain server temporarily refuses to recognize a valid hostname. I'd say you need to put the gethostbyname() in a try/catch, and then supply some reasonable bogus string for host. Only you will know what to use there; depending on what you're going to use it for. ipval = (os.environ.get('HTTP_CF_CONNECTING_IP') or os.environ.get('REMOTE_ADDR', "Please throw a gaierror exception") try: host = socket.gethostbyaddr(ipval) [0] except socket.gaierror as exc; host = "Unknown host" I don't know the gethostbyaddr(), so i don't know if there are other exceptions you should also try to catch. -- DaveA From nikos.gr33k at gmail.com Thu Sep 26 12:58:02 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Thu, 26 Sep 2013 19:58:02 +0300 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: ???? 26/9/2013 5:22 ??, ?/? Dave Angel ??????: > On 26/9/2013 09:34, ????? wrote: > >> ???? 26/9/2013 3:53 ??, ?/? Antoon Pardon ??????: >>> Op 26-09-13 14:39, ????? schreef: >>>> Yes, you are right, in my shell it fails too givign the same error >>>> message as yours, while on the other had in the websste is working. >>>> >>>> Can you explain this please? >>>> why doesnt it fail to both enviroments? >>> >>> Your site and your shell are two different environments. The state >>> of the website environment lets your code succeed while the state >>> of the shell environment, doesn't. >>> >> What modification does it need to also work in the shell environmentthe >> [0] at the end is what complicates things. > > Not at all. What complicates/confuses things is trying to do too much > in one line. > > The line is trying to solve two separate things. You might now > understand the first of them; the fetching of multiple environment > variables that may or may not exist. > > The second thing is the function call to gethostbyname(). If fed > invalid data, this call will throw an exception. So you need to either > put it in a try/catch or somehow pretend that you can know what > constitutes invalid data. One example of invalid data is your default > string. Another might be if one of those environment variables exists, > but isn't reasonable. And a third might be if the domain server > temporarily refuses to recognize a valid hostname. > > I'd say you need to put the gethostbyname() in a try/catch, and then > supply some reasonable bogus string for host. Only you will know what > to use there; depending on what you're going to use it for. > > > ipval = (os.environ.get('HTTP_CF_CONNECTING_IP') or > os.environ.get('REMOTE_ADDR', "Please throw a gaierror exception") > try: > host = socket.gethostbyaddr(ipval) [0] > except socket.gaierror as exc; > host = "Unknown host" > > I don't know the gethostbyaddr(), so i don't know if there are other > exceptions you should also try to catch. > Indeed this logic you follow is hethe best i have seen so far. But actually i have 2 variables that relay on a proper ip address. ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or os.environ.get('REMOTE_ADDR', "UnKnown Origin") ) try: gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') city = gi.time_zone_by_addr( ipval ) host = socket.gethostbyaddr( ipval ) [0] except socket.gaierror as e: city = host = "UnKnown Origin" But then what if in case of an error i needed different string set to be assigned on city and host respectively? As i ahve it know in case of n address related error i get the smae sting for both of them. From denismfmcmahon at gmail.com Thu Sep 26 16:16:38 2013 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Thu, 26 Sep 2013 20:16:38 +0000 (UTC) Subject: Handling 3 operands in an expression without raising an exception References: Message-ID: On Thu, 26 Sep 2013 19:58:02 +0300, ????? wrote: > except socket.gaierror as e: > city = host = "UnKnown Origin" > > But then what if in case of an error i needed different string set to be > assigned on city and host respectively? Oh FFS Are you serious when you ask this? Simply change: except socket.gaierror as e: city = host = "UnKnown Origin" To: except socket.gaierror as e: city = "Unknown City" host = "Unknown Host" -- Denis McMahon, denismfmcmahon at gmail.com From nikos.gr33k at gmail.com Thu Sep 26 18:14:45 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Fri, 27 Sep 2013 01:14:45 +0300 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: ???? 26/9/2013 11:16 ??, ?/? Denis McMahon ??????: > On Thu, 26 Sep 2013 19:58:02 +0300, ????? wrote: > >> except socket.gaierror as e: >> city = host = "UnKnown Origin" >> >> But then what if in case of an error i needed different string set to be >> assigned on city and host respectively? > > Oh FFS > > Are you serious when you ask this? > > Simply change: > > except socket.gaierror as e: > city = host = "UnKnown Origin" > > To: > > except socket.gaierror as e: > city = "Unknown City" > host = "Unknown Host" Yes indeed that was an idiotic question made by me, but i was somehow feeling again that i should handle it in one-liner, avoid wanting to use 2 statements. I wonder if there is a way to assign the string "Unknown Origin" to the variable that failed in the try block to get a value. Can i describe that somehow inside the except block? I mean like: except socket.gaierror as e: what_ever_var_failed = "Unknown Origin" From davea at davea.name Thu Sep 26 18:55:41 2013 From: davea at davea.name (Dave Angel) Date: Thu, 26 Sep 2013 22:55:41 +0000 (UTC) Subject: Handling 3 operands in an expression without raising an exception References: Message-ID: On 26/9/2013 18:14, ????? wrote: > ???? 26/9/2013 11:16 ??, ?/? Denis McMahon ??????: >> On Thu, 26 Sep 2013 19:58:02 +0300, ????? wrote: >> >>> except socket.gaierror as e: >>> city = host = "UnKnown Origin" >>> >>> But then what if in case of an error i needed different string set to be >>> assigned on city and host respectively? >> >> Oh FFS >> >> Are you serious when you ask this? >> >> Simply change: >> >> except socket.gaierror as e: >> city = host = "UnKnown Origin" >> >> To: >> >> except socket.gaierror as e: >> city = "Unknown City" >> host = "Unknown Host" > > Yes indeed that was an idiotic question made by me, but i was somehow > feeling again that i should handle it in one-liner, avoid wanting to use > 2 statements. newlines are still cheap. And they can really help readability. > I wonder if there is a way to assign the string "Unknown Origin" to the > variable that failed in the try block to get a value. > > Can i describe that somehow inside the except block? > > I mean like: > > except socket.gaierror as e: > what_ever_var_failed = "Unknown Origin" Simply assign the default values BEFORE the try block, and use pass as the except block. That still doesn't get around the inadvisability of putting those 3 lines in the try block. You still haven't dealt with the gt assignment and its possible exception. -- DaveA From nikos.gr33k at gmail.com Fri Sep 27 05:19:53 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Fri, 27 Sep 2013 12:19:53 +0300 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: ???? 27/9/2013 1:55 ??, ?/? Dave Angel ??????: > On 26/9/2013 18:14, ????? wrote: > >> ???? 26/9/2013 11:16 ??, ?/? Denis McMahon ??????: >>> On Thu, 26 Sep 2013 19:58:02 +0300, ????? wrote: >>> >>>> except socket.gaierror as e: >>>> city = host = "UnKnown Origin" >>>> >>>> But then what if in case of an error i needed different string set to be >>>> assigned on city and host respectively? >>> >>> Oh FFS >>> >>> Are you serious when you ask this? >>> >>> Simply change: >>> >>> except socket.gaierror as e: >>> city = host = "UnKnown Origin" >>> >>> To: >>> >>> except socket.gaierror as e: >>> city = "Unknown City" >>> host = "Unknown Host" >> >> Yes indeed that was an idiotic question made by me, but i was somehow >> feeling again that i should handle it in one-liner, avoid wanting to use >> 2 statements. > > newlines are still cheap. And they can really help readability. > >> I wonder if there is a way to assign the string "Unknown Origin" to the >> variable that failed in the try block to get a value. >> >> Can i describe that somehow inside the except block? >> >> I mean like: >> >> except socket.gaierror as e: >> what_ever_var_failed = "Unknown Origin" > > Simply assign the default values BEFORE the try block, and use pass as > the except block. > > That still doesn't get around the inadvisability of putting those 3 > lines in the try block. > > You still haven't dealt with the gt assignment and its possible > exception. > Yes gi must be removed form within the try block because iam tesign it for failure. I'am not sure what you mean though when you say: > Simply assign the default values BEFORE the try block, and use pass as > the except block. Can you please make it more clear for me? This is my code as i have it at the moment: ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) try: gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') city = gi.time_zone_by_addr( ipval ) host = socket.gethostbyaddr( ipval ) [0] except socket.gaierror as e: city = "??????? ????" host = "??????? ?????????" Or even better since i actually use 3 vars inside the try block it would be really neat to be able to detect which far failed and assign a specific value variable failed depended. IF it can also be written in one-line afteer the excpect would be even better. Call me persistent but when i can write somethign in 1-line i wou;d prefer it over 3-lines. From steve+comp.lang.python at pearwood.info Fri Sep 27 05:26:31 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Sep 2013 09:26:31 GMT Subject: Handling 3 operands in an expression without raising an exception References: Message-ID: <52454f46$0$30000$c3e8da3$5496439d@news.astraweb.com> On Fri, 27 Sep 2013 12:19:53 +0300, ????? wrote: > I'am not sure what you mean though when you say: > >> Simply assign the default values BEFORE the try block, and use pass as >> the except block. > > Can you please make it more clear for me? variable = "default value" try: variable = something_that_might_fail() except SomeException: pass -- Steven From nikos.gr33k at gmail.com Fri Sep 27 06:04:02 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Fri, 27 Sep 2013 13:04:02 +0300 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: <52454f46$0$30000$c3e8da3$5496439d@news.astraweb.com> References: <52454f46$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: ???? 27/9/2013 12:26 ??, ?/? Steven D'Aprano ??????: > On Fri, 27 Sep 2013 12:19:53 +0300, ????? wrote: > >> I'am not sure what you mean though when you say: >> >>> Simply assign the default values BEFORE the try block, and use pass as >>> the except block. >> >> Can you please make it more clear for me? > > > variable = "default value" > try: > variable = something_that_might_fail() > except SomeException: > pass Thanks Steven but this way i still have to declare the default string sfor the variables: Its no different than: except socket.gaierror as e: city = "??????? ????" host = "??????? ?????????" Your way set the vars on top, the other way set the vars inside the except block. From davea at davea.name Fri Sep 27 06:43:52 2013 From: davea at davea.name (Dave Angel) Date: Fri, 27 Sep 2013 10:43:52 +0000 (UTC) Subject: Handling 3 operands in an expression without raising an exception References: Message-ID: On 27/9/2013 05:19, ????? wrote: > ???? 27/9/2013 1:55 ??, ?/? Dave Angel ??????: >> >> Simply assign the default values BEFORE the try block, and use pass as >> the except block. >> >> That still doesn't get around the inadvisability of putting those 3 >> lines in the try block. >> >> You still haven't dealt with the gt assignment and its possible >> exception. >> > Yes gi must be removed form within the try block because iam tesign it > for failure. Then why don't you do it below? > > I'am not sure what you mean though when you say: > >> Simply assign the default values BEFORE the try block, and use pass as >> the except block. > > Can you please make it more clear for me? > > This is my code as i have it at the moment: > > ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or > os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) > try: > gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') > city = gi.time_zone_by_addr( ipval ) > host = socket.gethostbyaddr( ipval ) [0] > except socket.gaierror as e: > city = "??????? ????" > host = "??????? ?????????" ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) city = "??????? ????" host = "??????? ?????????" try: city = gi.time_zone_by_addr( ipval ) host = socket.gethostbyaddr( ipval ) [0] except socket.gaierror as e: pass > > Or even better since i actually use 3 vars inside the try block it would > be really neat to be able to detect which far failed and assign a > specific value variable failed depended. ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) city = None host = None try: city = gi.time_zone_by_addr( ipval ) host = socket.gethostbyaddr( ipval ) [0] except socket.gaierror as e: if not city: city = "??????? ????" if not host: host = "??????? ?????????" or: ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) city = None host = None try: city = gi.time_zone_by_addr( ipval ) host = socket.gethostbyaddr( ipval ) [0] except socket.gaierror as e: if not host: host = "??????? ?????????" if not city: city = "??????? ????" Note that in that last case, I tested the variables in the reverse order. Note also on both of these that I assumed that None is not a reasonable value for either of those. In fact, I also assume that an empty string is not a reasonable value. If I didn't like the latter assumption, I'd have used tests like if host is None: > > IF it can also be written in one-line afteer the excpect would be even > better. Call me persistent but when i can write somethign in 1-line i > wou;d prefer it over 3-lines. Ridiculous. But if you like code golf, you can always do: city, host = "??????? ????", "??????? ?????????" You should study APL. Many functions were written in one line, with twenty lines of explanation. The function itself was considered unreadable nonsense. And if a function stopped working, general wisdom was to throw it out, and re-implement the explanation. I studied it briefly in class in 1970, and have no idea if there are current implementations. -- DaveA From robert.kern at gmail.com Sat Sep 28 07:18:13 2013 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 28 Sep 2013 12:18:13 +0100 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: On 2013-09-27 11:43, Dave Angel wrote: > You should study APL. Many functions were written in one line, with > twenty lines of explanation. The function itself was considered > unreadable nonsense. And if a function stopped working, general wisdom > was to throw it out, and re-implement the explanation. I studied it > briefly in class in 1970, and have no idea if there are current > implementations. You are in luck! GNU APL 1.0 was just released! http://www.gnu.org/software/apl/ -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From nikos.gr33k at gmail.com Fri Sep 27 07:15:19 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Fri, 27 Sep 2013 14:15:19 +0300 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: ???? 27/9/2013 1:43 ??, ?/? Dave Angel ??????: >> ???? 27/9/2013 1:55 ??, ?/? Dave Angel ??????: >>> Simply assign the default values BEFORE the try block, and use pass as >>> the except block. >>> >>> That still doesn't get around the inadvisability of putting those 3 >>> lines in the try block. >>> >>> You still haven't dealt with the gt assignment and its possible >>> exception. >> Yes gi must be removed form within the try block because iam tesign it >> for failure. > Then why don't you do it below? >> I'am not sure what you mean though when you say: >>> Simply assign the default values BEFORE the try block, and use pass as >>> the except block. >> Can you please make it more clear for me? >> >> This is my code as i have it at the moment: >> >> ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or >> os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) >> try: >> gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') >> city = gi.time_zone_by_addr( ipval ) >> host = socket.gethostbyaddr( ipval ) [0] >> except socket.gaierror as e: >> city = "??????? ????" >> host = "??????? ?????????" > ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or > os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) > city = "??????? ????" > host = "??????? ?????????" > try: > city = gi.time_zone_by_addr( ipval ) > host = socket.gethostbyaddr( ipval ) [0] > except socket.gaierror as e: > pass Thanks for taking the time to expain this: In the exact above solution of yours opposed to the top of mines is that you code has the benefit of actually identifying the variable that failed to have been assigned a value while in my code no matter what variable failes in the try block i assign string to both 'city' and 'host' hence i dont really know which one of them is failing? Di i understood it correctly? From davea at davea.name Fri Sep 27 08:17:12 2013 From: davea at davea.name (Dave Angel) Date: Fri, 27 Sep 2013 12:17:12 +0000 (UTC) Subject: Handling 3 operands in an expression without raising an exception References: Message-ID: On 27/9/2013 07:15, ????? wrote: > ???? 27/9/2013 1:43 ??, ?/? Dave Angel ??????: > >> ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or >> os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) >> city = "??????? ????" >> host = "??????? ?????????" >> try: >> city = gi.time_zone_by_addr( ipval ) >> host = socket.gethostbyaddr( ipval ) [0] >> except socket.gaierror as e: >> pass > > Thanks for taking the time to expain this: > > In the exact above solution of yours opposed to the top of mines is that No idea what you mean here. I'll assume you're talking about the version you DON'T quote here, the one with the if statements in the except clause. > you code has the benefit of actually identifying the variable that > failed to have been assigned a value while in my code no matter what > variable failes in the try block i assign string to both 'city' and > 'host' hence i dont really know which one of them is failing? Yes, it has that advantage. Of course it doesn't USE that advantage for anything so I'd go back to the pass version quoted immediately above. Or I'd have two separate try/except clauses, one for each function call. After all, the implication of the failure is different for each. > > Di i understood it correctly? I think so. -- DaveA From nikos.gr33k at gmail.com Fri Sep 27 08:51:02 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Fri, 27 Sep 2013 15:51:02 +0300 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: ???? 27/9/2013 3:17 ??, ?/? Dave Angel ??????: > On 27/9/2013 07:15, ????? wrote: > >> ???? 27/9/2013 1:43 ??, ?/? Dave Angel ??????: > > >> >>> ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or >>> os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) >>> city = "??????? ????" >>> host = "??????? ?????????" >>> try: >>> city = gi.time_zone_by_addr( ipval ) >>> host = socket.gethostbyaddr( ipval ) [0] >>> except socket.gaierror as e: >>> pass >> >> Thanks for taking the time to expain this: >> >> In the exact above solution of yours opposed to the top of mines is that > > No idea what you mean here. I'll assume you're talking about the > version you DON'T quote here, the one with the if statements in the > except clause. > >> you code has the benefit of actually identifying the variable that >> failed to have been assigned a value while in my code no matter what >> variable failes in the try block i assign string to both 'city' and >> 'host' hence i dont really know which one of them is failing? > > Yes, it has that advantage. Of course it doesn't USE that advantage for > anything so I'd go back to the pass version quoted immediately above. > Or I'd have two separate try/except clauses, one for each function call. > After all, the implication of the failure is different for each. > > >> >> Di i understood it correctly? > > I think so. > Thank you for everything, i appreciate your time and effort to help me understand. From rustompmody at gmail.com Sat Sep 28 13:29:17 2013 From: rustompmody at gmail.com (rusi) Date: Sat, 28 Sep 2013 10:29:17 -0700 (PDT) Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: <27c9b4bf-4a7d-4be5-b2d8-2051ab7e398c@googlegroups.com> On Friday, September 27, 2013 4:13:52 PM UTC+5:30, Dave Angel wrote: > You should study APL. Many functions were written in one line, with > twenty lines of explanation. The function itself was considered > unreadable nonsense. And if a function stopped working, general wisdom > was to throw it out, and re-implement the explanation. I studied it > briefly in class in 1970, and have no idea if there are current > implementations. >From a certain pov both python and APL have a similar/analogous weakness -- inadequate 'intermediate' structuring constructs. APL tries to be superman at the expression ie micro level Likewise what packages and modules are to python, workspaces are to APL (not used myself but I know that APLers swear by them) -- call that the macro level The intermediate level is the issue. Functional languages have the let/where clause to convert a block of defs into a single value. Even gcc extends C similarly: http://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html#Statement-Exprs I do occasionally miss something like that in python From denismfmcmahon at gmail.com Fri Sep 27 11:16:21 2013 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Fri, 27 Sep 2013 15:16:21 +0000 (UTC) Subject: Handling 3 operands in an expression without raising an exception References: Message-ID: On Fri, 27 Sep 2013 12:19:53 +0300, ????? wrote: > This is my code as i have it at the moment: > > ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or > os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) try: > gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') > city = gi.time_zone_by_addr( ipval ) > host = socket.gethostbyaddr( ipval ) [0] > except socket.gaierror as e: > city = "??????? ????" > host = "??????? ?????????" Here is the basic problem: You're trying to do too many things at once in a language you don't understand and without any understanding of the fundamental underlying concepts of the systems that you're interfacing with. Break the task down into simpler steps and do the steps one at a time: Calculate ipval Calculate gi If ipval is valid, calculate city, else give city a default value If ipval is valid, calculate host, else give host a default value Then consider which of the above needs to be contained within a try / catch. Finally, code them as 4 separate units of code, eg: # instantiate geolocation by ip gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') # calculate ipval try: ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) except ( KeyError, TypeError ): ipval = some_default # try and obtain time zone from ip try: city = gi.time_zone_by_addr( ipval ) except (error type[s]): city = "Unknown City" # try and obtain hostname from ip try: host = socket.gethostbyaddr( ipval ) [0] except ( socket.gaierror ): host = "Unknown Host" Note that there is nothing special about writing it in as few lines as code as possible. Writing it out in a way that is easy to understand and follow helps make sure it actually works, and makes it a lot easier to maintain in future. -- Denis McMahon, denismfmcmahon at gmail.com From invalid at invalid.invalid Fri Sep 27 12:04:04 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 27 Sep 2013 16:04:04 +0000 (UTC) Subject: Handling 3 operands in an expression without raising an exception References: Message-ID: On 2013-09-27, Denis McMahon wrote: > Note that there is nothing special about writing it in as few lines as > code as possible. Hah! That's what they _want_ you to think. First they get you hooked on newlines, then the newline mine owners form a cartel and start jacking up the prices. Then you'll wish you'd spent more time learning to write Perl one-liners... -- Grant Edwards grant.b.edwards Yow! What GOOD is a at CARDBOARD suitcase ANYWAY? gmail.com From nikos.gr33k at gmail.com Fri Sep 27 12:47:45 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Fri, 27 Sep 2013 19:47:45 +0300 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: ???? 27/9/2013 6:16 ??, ?/? Denis McMahon ??????: > On Fri, 27 Sep 2013 12:19:53 +0300, ????? wrote: > >> This is my code as i have it at the moment: >> >> ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or >> os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) try: >> gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') >> city = gi.time_zone_by_addr( ipval ) >> host = socket.gethostbyaddr( ipval ) [0] >> except socket.gaierror as e: >> city = "??????? ????" >> host = "??????? ?????????" > > Here is the basic problem: You're trying to do too many things at once in > a language you don't understand and without any understanding of the > fundamental underlying concepts of the systems that you're interfacing > with. > > Break the task down into simpler steps and do the steps one at a time: > > Calculate ipval > > Calculate gi > > If ipval is valid, calculate city, else give city a default value > > If ipval is valid, calculate host, else give host a default value > > Then consider which of the above needs to be contained within a try / > catch. > > Finally, code them as 4 separate units of code, eg: > > # instantiate geolocation by ip > gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') > > # calculate ipval > try: > ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or > os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) > except ( KeyError, TypeError ): > ipval = some_default > > # try and obtain time zone from ip > try: > city = gi.time_zone_by_addr( ipval ) > except (error type[s]): > city = "Unknown City" > > # try and obtain hostname from ip > try: > host = socket.gethostbyaddr( ipval ) [0] > except ( socket.gaierror ): > host = "Unknown Host" > > Note that there is nothing special about writing it in as few lines as > code as possible. Writing it out in a way that is easy to understand and > follow helps make sure it actually works, and makes it a lot easier to > maintain in future. > Sure your method follows the the logic in a straighforward way step-by-step but i just dont want to spent almost 20 lines of code just to calculate 2 variables(city and host). ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) city = "??????? ????" host = "??????? ?????????" try: gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') city = gi.time_zone_by_addr( ipval ) host = socket.gethostbyaddr( ipval ) [0] except socket.gaierror as e: print( "metrites.py => (%s): " % lastvisit, repr( sys.exc_info() ), file=open('/tmp/err.out', 'w') ) The above code works in less lines of codes and because the assignment of the vars happen before the try:/except: block, if something fails during try: we can tell by looking at the values of city or host. Also its being logged at the err.out too. Only problem is that iam handlign address related issues and not the case of when gi fails. But i dont know how to do that. except (error type[s]): i saw in your code but iam not sure what exactly this is supposed to handle. From neilc at norwich.edu Fri Sep 27 12:56:40 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 27 Sep 2013 16:56:40 GMT Subject: Handling 3 operands in an expression without raising an exception References: Message-ID: On 2013-09-27, ?????????? wrote: > Sure your method follows the the logic in a straighforward way > step-by-step but i just dont want to spent almost 20 lines of > code just to calculate 2 variables(city and host). Sure, eating with my mouth is straightforward and step-by-step, but I just want to shove the food directly into my stomach. -- Neil Cerutti From invalid at invalid.invalid Fri Sep 27 13:00:59 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 27 Sep 2013 17:00:59 +0000 (UTC) Subject: Handling 3 operands in an expression without raising an exception References: Message-ID: On 2013-09-27, ?????????? wrote: > Sure your method follows the the logic in a straighforward way > step-by-step but i just dont want to spent almost 20 lines of code just > to calculate 2 variables(city and host). Does your provider charge you per line of code? If all that matters is the number of lines of code then use this: city,host = 0,0 Only _1_ nice short line of code. Happy? -- Grant Edwards grant.b.edwards Yow! If Robert Di Niro at assassinates Walter Slezak, gmail.com will Jodie Foster marry Bonzo?? From joel.goldstick at gmail.com Fri Sep 27 13:19:50 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 27 Sep 2013 13:19:50 -0400 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: On Fri, Sep 27, 2013 at 1:00 PM, Grant Edwards wrote: > On 2013-09-27, ?????????? wrote: > > > Sure your method follows the the logic in a straighforward way > > step-by-step but i just dont want to spent almost 20 lines of code just > > to calculate 2 variables(city and host). > > Does your provider charge you per line of code? > > If all that matters is the number of lines of code then use this: > > city,host = 0,0 > > Only _1_ nice short line of code. > > Happy? > > -- > Grant Edwards grant.b.edwards Yow! If Robert Di Niro > at assassinates Walter > Slezak, > gmail.com will Jodie Foster marry > Bonzo?? > -- > https://mail.python.org/mailman/listinfo/python-list > Better yet, don't write the program. Zero lines of code, and every line works perfectly. It runs extremely fast too! ... or Nikos the annoyance, write it in apl -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Fri Sep 27 13:32:23 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 27 Sep 2013 18:32:23 +0100 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: On 27/09/2013 18:00, Grant Edwards wrote: > On 2013-09-27, ?????????? wrote: > >> Sure your method follows the the logic in a straighforward way >> step-by-step but i just dont want to spent almost 20 lines of code just >> to calculate 2 variables(city and host). > > Does your provider charge you per line of code? > > If all that matters is the number of lines of code then use this: > > city,host = 0,0 > > Only _1_ nice short line of code. > > Happy? > Classic overengineering, fancy wasting two whole spaces and having such long names. Surely c,h=0,0 is vastly superior? -- Cheers. Mark Lawrence From denismfmcmahon at gmail.com Fri Sep 27 14:49:08 2013 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Fri, 27 Sep 2013 18:49:08 +0000 (UTC) Subject: Handling 3 operands in an expression without raising an exception References: Message-ID: On Fri, 27 Sep 2013 18:32:23 +0100, Mark Lawrence wrote: > On 27/09/2013 18:00, Grant Edwards wrote: >> On 2013-09-27, ?????????? wrote: >> >>> Sure your method follows the the logic in a straighforward way >>> step-by-step but i just dont want to spent almost 20 lines of code >>> just to calculate 2 variables(city and host). >> >> Does your provider charge you per line of code? >> >> If all that matters is the number of lines of code then use this: >> >> city,host = 0,0 >> >> Only _1_ nice short line of code. >> >> Happy? >> >> > Classic overengineering, fancy wasting two whole spaces and having such > long names. Surely c,h=0,0 is vastly superior? Why not c=h=0 2 characters (28%) shorter! -- Denis McMahon, denismfmcmahon at gmail.com From invalid at invalid.invalid Fri Sep 27 14:54:59 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 27 Sep 2013 18:54:59 +0000 (UTC) Subject: Handling 3 operands in an expression without raising an exception References: Message-ID: On 2013-09-27, Denis McMahon wrote: > On Fri, 27 Sep 2013 18:32:23 +0100, Mark Lawrence wrote: > >> On 27/09/2013 18:00, Grant Edwards wrote: >>> On 2013-09-27, ?????????? wrote: >>> >>>> Sure your method follows the the logic in a straighforward way >>>> step-by-step but i just dont want to spent almost 20 lines of code >>>> just to calculate 2 variables(city and host). >>> >>> Does your provider charge you per line of code? >>> >>> If all that matters is the number of lines of code then use this: >>> >>> city,host = 0,0 >>> >>> Only _1_ nice short line of code. >>> >>> Happy? >>> >>> >> Classic overengineering, fancy wasting two whole spaces and having such >> long names. Surely c,h=0,0 is vastly superior? > > Why not c=h=0 > > 2 characters (28%) shorter! And 47% more opaque! -- Grant Edwards grant.b.edwards Yow! ... he dominates the at DECADENT SUBWAY SCENE. gmail.com From joel.goldstick at gmail.com Fri Sep 27 15:21:24 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 27 Sep 2013 15:21:24 -0400 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: On Fri, Sep 27, 2013 at 2:54 PM, Grant Edwards wrote: > On 2013-09-27, Denis McMahon wrote: > > On Fri, 27 Sep 2013 18:32:23 +0100, Mark Lawrence wrote: > > > >> On 27/09/2013 18:00, Grant Edwards wrote: > >>> On 2013-09-27, ?????????? wrote: > >>> > >>>> Sure your method follows the the logic in a straighforward way > >>>> step-by-step but i just dont want to spent almost 20 lines of code > >>>> just to calculate 2 variables(city and host). > >>> > >>> Does your provider charge you per line of code? > >>> > >>> If all that matters is the number of lines of code then use this: > >>> > >>> city,host = 0,0 > >>> > >>> Only _1_ nice short line of code. > >>> > >>> Happy? > >>> > >>> > >> Classic overengineering, fancy wasting two whole spaces and having such > >> long names. Surely c,h=0,0 is vastly superior? > > > > Why not c=h=0 > > > > 2 characters (28%) shorter! > > And 47% more opaque! > > -- > Grant Edwards grant.b.edwards Yow! ... he dominates > the > at DECADENT SUBWAY SCENE. > gmail.com > -- > https://mail.python.org/mailman/listinfo/python-list > better yet: i=l=0 The names have even less meaning, and they are thin -- less space -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From nikos.gr33k at gmail.com Fri Sep 27 18:06:50 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Sat, 28 Sep 2013 01:06:50 +0300 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: ???? 27/9/2013 8:00 ??, ?/? Grant Edwards ??????: > On 2013-09-27, ?????????? wrote: > >> Sure your method follows the the logic in a straighforward way >> step-by-step but i just dont want to spent almost 20 lines of code just >> to calculate 2 variables(city and host). > > Does your provider charge you per line of code? > > If all that matters is the number of lines of code then use this: > > city,host = 0,0 > > Only _1_ nice short line of code. > > Happy? > Well to tell the truth no matter what you say to me if something can be written in less lines than another implementation but still retain its simplicity and straightforward logic behind it i would prefer it! I don't know why you think otherwise, especially people who are used to write Perl code(me being one of them) would agree with me! But in this case i cant use your examples even if i wanted too and thats because the strings needed to be assigned to the 2 vars respectively are different. city = "??????? ????" host = "??????? ?????????" If they were to have the same string assigned to them it should be okey but they do not. Or perhaps you can even still think of writing the above into 1-liner whatsoever! I wouldn't be surprised if you can! :-) From davea at davea.name Fri Sep 27 18:26:46 2013 From: davea at davea.name (Dave Angel) Date: Fri, 27 Sep 2013 22:26:46 +0000 (UTC) Subject: Handling 3 operands in an expression without raising an exception References: Message-ID: On 27/9/2013 18:06, ????? wrote: > > city = "??????? ????" > host = "??????? ?????????" > > If they were to have the same string assigned to them it should be okey > but they do not. > > Or perhaps you can even still think of writing the above into 1-liner > whatsoever! I already did earlier in this thread. And you must have read the message, because you replied to other parts of it. it's the one where I referred to code golf, and to APL. About 12 hours ago, at 6:43 my time. city, host = "??????? ????", "??????? ?????????" I still think it's foolish, but be my guest. -- DaveA From rosuav at gmail.com Fri Sep 27 21:59:42 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 28 Sep 2013 11:59:42 +1000 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: On Sat, Sep 28, 2013 at 8:06 AM, ????? wrote: > Well to tell the truth no matter what you say to me if something can be > written in less lines than another implementation but still retain its > simplicity and straightforward logic behind it i would prefer it! > I don't know why you think otherwise, especially people who are used to > write Perl code(me being one of them) would agree with me! It's high time you stopped trying to write Perl code that runs under the Python interpreter, and started writing Python code that runs under the Python interpreter. There are rules. You first learn the rules and learn to code within them; then later, once you actually achieve some measure of competence, you begin learning when to break the rules. ChrisA From nikos.gr33k at gmail.com Sat Sep 28 05:14:08 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Sat, 28 Sep 2013 12:14:08 +0300 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: ???? 28/9/2013 4:59 ??, ?/? Chris Angelico ??????: > On Sat, Sep 28, 2013 at 8:06 AM, ????? wrote: >> Well to tell the truth no matter what you say to me if something can be >> written in less lines than another implementation but still retain its >> simplicity and straightforward logic behind it i would prefer it! >> I don't know why you think otherwise, especially people who are used to >> write Perl code(me being one of them) would agree with me! > > It's high time you stopped trying to write Perl code that runs under > the Python interpreter, and started writing Python code that runs > under the Python interpreter. > > There are rules. You first learn the rules and learn to code within > them; then later, once you actually achieve some measure of > competence, you begin learning when to break the rules. > > ChrisA > ????f I agree with everything you say, but i also have to say that even writing compact code which still retain its simplicity and understanding its preferred to me and to other coders too. For example i wouldn't change this line for anything in my code no matter how simple you can get it look.. #check if date entered as intented, format it properly for MySQL lastvisit = datetime.strptime(lastvisit, '%d %m %Y').strftime('%Y-%m-%d') why write it in 2-3 lines when you cna have it written in 1-liner? Isn't it clear as it is now? From nikos.gr33k at gmail.com Sat Sep 28 05:33:56 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Sat, 28 Sep 2013 12:33:56 +0300 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: ???? 28/9/2013 1:26 ??, ?/? Dave Angel ??????: > On 27/9/2013 18:06, ????? wrote: > > >> >> city = "??????? ????" >> host = "??????? ?????????" >> >> If they were to have the same string assigned to them it should be okey >> but they do not. >> >> Or perhaps you can even still think of writing the above into 1-liner >> whatsoever! > > I already did earlier in this thread. And you must have read the > message, because you replied to other parts of it. it's the one where I > referred to code golf, and to APL. About 12 hours ago, at 6:43 my time. > > city, host = "??????? ????", "??????? ?????????" > > I still think it's foolish, but be my guest. Perhaps i wasn't clear when i expresses my self. Sure the 1-liner you provided assign different strings to each variable respectively, which is nice, but i was referring to have 1-liner that had the ability to assign the appropriate string to the variable that failed to get a value. ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) try: gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') city = gi.time_zone_by_addr( ipval ) host = socket.gethostbyaddr( ipval ) [0] except socket.gaierror as e: city = "??????? ????" host = "??????? ?????????" In the above code no matter which variable fails to grab a value(gi excluded in check) we assign city and host 2 differnt values, while we want to assign a value only to the varibale that failed in the try block. Is there a way to write the except block in 1-liner? That woudl require that we actually identify which variable failed in try: This could work: ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) city = "??????? ????" host = "??????? ?????????" try: gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') city = gi.time_zone_by_addr( ipval ) host = socket.gethostbyaddr( ipval ) [0] except: pass but in this case we assign values to the variables BEFORE the try: It woould be nice if we could write it as: ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) try: gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') city = gi.time_zone_by_addr( ipval ) host = socket.gethostbyaddr( ipval ) [0] except socket.gaierror as e: if city failed assign to it "??????? ????" while if host failed assign it "??????? ?????????" but without an if statement and in 1 single line. From rosuav at gmail.com Sat Sep 28 06:19:54 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 28 Sep 2013 20:19:54 +1000 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: On Sat, Sep 28, 2013 at 7:33 PM, ????? wrote: > It woould be nice if we could write it as: > > > ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or > os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) > try: > gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') > city = gi.time_zone_by_addr( ipval ) > host = socket.gethostbyaddr( ipval ) [0] > except socket.gaierror as e: > if city failed assign to it "??????? ????" while if host failed > assign it "??????? ?????????" > > but without an if statement and in 1 single line. [ROLL] Rosuav rolls his eyes: 1, 1, totalling 2. Then split your try blocks! You've already been told this. ChrisA From nikos.gr33k at gmail.com Sat Sep 28 09:23:53 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Sat, 28 Sep 2013 16:23:53 +0300 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: ???? 28/9/2013 1:19 ??, ?/? Chris Angelico ??????: > On Sat, Sep 28, 2013 at 7:33 PM, ????? wrote: >> It woould be nice if we could write it as: >> >> >> ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or >> os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) >> try: >> gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') >> city = gi.time_zone_by_addr( ipval ) >> host = socket.gethostbyaddr( ipval ) [0] >> except socket.gaierror as e: >> if city failed assign to it "??????? ????" while if host failed >> assign it "??????? ?????????" >> >> but without an if statement and in 1 single line. > > [ROLL] Rosuav rolls his eyes: 1, 1, totalling 2. > > Then split your try blocks! You've already been told this. > > ChrisA > No we didn't have said this. if you are referring to this: ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) city = "??????? ????" host = "??????? ?????????" try: gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') city = gi.time_zone_by_addr( ipval ) host = socket.gethostbyaddr( ipval ) [0] except socket.gaierror as e: print( "metrites.py => (%s): " % lastvisit, repr( sys.exc_info() ), file=open('/tmp/err.out', 'w') ) this is not the case, because we want the string to beassigned to the variables in the except clause not before the try/except block. And in 1-liner after the except: too, and value must take only which var has failed to be assigned one from within try. From andipersti at gmail.com Sat Sep 28 11:02:15 2013 From: andipersti at gmail.com (Andreas Perstinger) Date: Sat, 28 Sep 2013 17:02:15 +0200 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: <20130928170215.5e939267@Hof> ????? wrote: >???? 28/9/2013 1:19 ??, ?/? Chris Angelico ??????: >> [ROLL] Rosuav rolls his eyes: 1, 1, totalling 2. >> >> Then split your try blocks! You've already been told this. >> >No we didn't have said this. if you are referring to this: At least Denis told you about 24 hours ago: https://mail.python.org/pipermail/python-list/2013-September/656318.html So either do it like that (which is the reasonable way) or look for another programming language. Bye, Andreas From nikos.gr33k at gmail.com Sat Sep 28 12:14:18 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Sat, 28 Sep 2013 19:14:18 +0300 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: ???? 28/9/2013 6:02 ??, ?/? Andreas Perstinger ??????: > ????? wrote: > >> ???? 28/9/2013 1:19 ??, ?/? Chris Angelico ??????: >>> [ROLL] Rosuav rolls his eyes: 1, 1, totalling 2. >>> >>> Then split your try blocks! You've already been told this. >>> >> No we didn't have said this. if you are referring to this: > > At least Denis told you about 24 hours ago: > https://mail.python.org/pipermail/python-list/2013-September/656318.html > > So either do it like that (which is the reasonable way) or look for > another programming language. > > Bye, Andreas > I know what he has said bit this is now what i need. From breamoreboy at yahoo.co.uk Sat Sep 28 13:53:54 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 28 Sep 2013 18:53:54 +0100 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: On 28/09/2013 17:14, ????? wrote: > I know what he has said bit this is now what i need. You actually need the tool that was used on King Edward II. -- Cheers. Mark Lawrence From joel.goldstick at gmail.com Sat Sep 28 14:21:55 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sat, 28 Sep 2013 14:21:55 -0400 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: On Sat, Sep 28, 2013 at 1:53 PM, Mark Lawrence wrote: > On 28/09/2013 17:14, ????? wrote: > > I know what he has said bit this is now what i need. >> > > You actually need the tool that was used on King Edward II. > > > -- > Cheers. > > Mark Lawrence > > -- > https://mail.python.org/**mailman/listinfo/python-list > Here's an old chestnut from June: > BTW both scripts at > http://superhost.gr/~dauwin/metrites.py > and at > http://superhost.gr/~dauwin/cgi-bin/metrites.py > show the world the passwords to your databases in plain text. He said he was working on it! Maybe as soon as that one liner gets revealed. -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From z at etiol.net Sat Sep 28 14:38:33 2013 From: z at etiol.net (Zero Piraeus) Date: Sat, 28 Sep 2013 15:38:33 -0300 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: <20130928183833.GA13630@piedra> : > On Sat, Sep 28, 2013 at 1:53 PM, Mark Lawrence wrote: > > You actually need the tool that was used on King Edward II. To be clear, Mark, you are calling for ????? to be tortured to death with a red hot poker, yes? I'm going to go out on a limb and suggest that such a suggestion is outside what people generally consider acceptable on this list. -[]z. From breamoreboy at yahoo.co.uk Sat Sep 28 14:45:40 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 28 Sep 2013 19:45:40 +0100 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: <20130928183833.GA13630@piedra> References: <20130928183833.GA13630@piedra> Message-ID: On 28/09/2013 19:38, Zero Piraeus wrote: > : > >> On Sat, Sep 28, 2013 at 1:53 PM, Mark Lawrence wrote: >>> You actually need the tool that was used on King Edward II. > > To be clear, Mark, you are calling for ????? to be tortured to death > with a red hot poker, yes? > > I'm going to go out on a limb and suggest that such a suggestion is > outside what people generally consider acceptable on this list. > > -[]z. > Not tortured, simply murdered so we don't have to put up with his completely unacceptable behaviour, which sadly is thriving owing to so many people ignoring the "do not feed this moron" signs. -- Cheers. Mark Lawrence From rosuav at gmail.com Sat Sep 28 19:04:57 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 29 Sep 2013 09:04:57 +1000 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: <20130928183833.GA13630@piedra> Message-ID: On Sun, Sep 29, 2013 at 4:45 AM, Mark Lawrence wrote: > Not tortured, simply murdered so we don't have to put up with his completely > unacceptable behaviour, which sadly is thriving owing to so many people > ignoring the "do not feed this moron" signs. You miss one important factor in these discussions: the silent majority of readers. We have a few people here who are not "worth" responding to, as they're highly unlikely to listen (the most noteworthy other example being jmf on Unicode), but that doesn't mean the threads can't be useful to someone else. And sometimes there can be some extremely entertaining conversation, too. That's also why I don't plonk anyone :) ChrisA From ben+python at benfinney.id.au Sat Sep 28 21:35:36 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 29 Sep 2013 11:35:36 +1000 Subject: Handling 3 operands in an expression without raising an exception References: <20130928183833.GA13630@piedra> Message-ID: <7wmwmwtno7.fsf@benfinney.id.au> Mark Lawrence writes: > On 28/09/2013 19:38, Zero Piraeus wrote: > > To be clear, Mark, you are calling for ????? to be tortured to death > > with a red hot poker, yes? > > Not tortured, simply murdered so we don't have to put up with his > completely unacceptable behaviour Regardless of the behaviour of anyone else, threatening them (with calls for their murder) is completely unacceptable in this forum. Please don't do it, ever. -- \ ?Religious faith is the one species of human ignorance that | `\ will not admit of even the *possibility* of correction.? ?Sam | _o__) Harris, _The End of Faith_, 2004 | Ben Finney From nikos.gr33k at gmail.com Sun Sep 29 03:35:37 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Sun, 29 Sep 2013 10:35:37 +0300 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: <20130928183833.GA13630@piedra> Message-ID: ???? 29/9/2013 2:04 ??, ?/? Chris Angelico ??????: > On Sun, Sep 29, 2013 at 4:45 AM, Mark Lawrence wrote: >> Not tortured, simply murdered so we don't have to put up with his completely >> unacceptable behaviour, which sadly is thriving owing to so many people >> ignoring the "do not feed this moron" signs. > > You miss one important factor in these discussions: the silent > majority of readers. We have a few people here who are not "worth" > responding to, as they're highly unlikely to listen (the most > noteworthy other example being jmf on Unicode), but that doesn't mean > the threads can't be useful to someone else. And sometimes there can > be some extremely entertaining conversation, too. > > That's also why I don't plonk anyone :) Its not that i don't listen, its that i want something to be implemented in a specific way. ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) try: gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') city = gi.time_zone_by_addr( ipval ) host = socket.gethostbyaddr( ipval ) [0] except socket.gaierror as e: city = "??????? ????" host = "??????? ?????????" My question was if the above code, in the except clause, can be written in 1-line while identifying which one of the two variables have failed to be assigned a value in the try: clause and assign to it respectively. And i don't mean like this: if not city: city ="blabla" if not host: host="blablabla" Can thes be witten without and if perhaps with the use of 'or' operator in 1-line within the except clause? From jpiitula at ling.helsinki.fi Sun Sep 29 05:35:17 2013 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 29 Sep 2013 12:35:17 +0300 Subject: Handling 3 operands in an expression without raising an exception References: <20130928183833.GA13630@piedra> Message-ID: ????? writes: > And i don't mean like this: > > if not city: > city ="blabla" > if not host: > host="blablabla" > > > Can thes be witten without and if perhaps with the use of 'or' > operator in 1-line within the except clause? try: ... except socket.gaierror as e: # watch out, a composition of bad advice (on demand) city, host = ( ('city' in locals() or "blabla"), ('host' in locals() or "blablabla") ) From steve+comp.lang.python at pearwood.info Sun Sep 29 05:48:16 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 Sep 2013 09:48:16 GMT Subject: Handling 3 operands in an expression without raising an exception References: <20130928183833.GA13630@piedra> Message-ID: <5247f760$0$29988$c3e8da3$5496439d@news.astraweb.com> On Sun, 29 Sep 2013 12:35:17 +0300, Jussi Piitulainen wrote: > try: > ... > except socket.gaierror as e: > # watch out, a composition of bad advice (on demand) city, host = ( > ('city' in locals() or "blabla"), > ('host' in locals() or "blablabla") ) Bad advice, and buggy as well. py> city = "New New York" py> ('city' in locals() or "Blah blah") True Oh man, can you imagine Nikos trying to debug that? -- Steven From jpiitula at ling.helsinki.fi Sun Sep 29 07:04:35 2013 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 29 Sep 2013 14:04:35 +0300 Subject: Handling 3 operands in an expression without raising an exception References: <20130928183833.GA13630@piedra> <5247f760$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano writes: > On Sun, 29 Sep 2013 12:35:17 +0300, Jussi Piitulainen wrote: > > > try: > > ... > > except socket.gaierror as e: > > # watch out, a composition of bad advice (on demand) city, host = ( > > ('city' in locals() or "blabla"), > > ('host' in locals() or "blablabla") ) > > Bad advice, and buggy as well. > > py> city = "New New York" > py> ('city' in locals() or "Blah blah") > True > > Oh man, can you imagine Nikos trying to debug that? Thanks. Sorry. This hurts. I didn't mean it to be buggy. Let's see. The task is to assign a default value to city and host, if they haven't a value yet; on one line (which I take to mean one statement); in an "except" block where we may not know which assignment failed in the "try" block; without "if"; but "or" is allowed. But the logic I was trying to implement is city, host = ( (city if 'city' in locals() else "default city"), (host if 'host' in locals() else "default host") ) which uses an "if". The old tricks of using "or" and stuff for this would surely go too far. I know! city, host = ( locals().get('city', "default city"), locals().get('host', "default host") ) Testing if the variables only exists when actually assigned: >>> def foo(x, y): ... if x: foo = None ... if y: bar = "bar" ... return locals() ... >>> foo(False, False) {'y': False, 'x': False} >>> foo(False, True) {'y': True, 'x': False, 'bar': 'bar'} Seems so. What a monster, though. I don't even want to know if this, too, is buggy in some way. It looks fragile. Nikos, don't do this. The way to test if an assignment failed is to use a try-catch. The way to know which one failed is to put each in its own try-catch. From nikos.gr33k at gmail.com Sun Sep 29 07:14:24 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Sun, 29 Sep 2013 14:14:24 +0300 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: <20130928183833.GA13630@piedra> <5247f760$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: ???? 29/9/2013 2:04 ??, ?/? Jussi Piitulainen ??????: > Steven D'Aprano writes: > >> On Sun, 29 Sep 2013 12:35:17 +0300, Jussi Piitulainen wrote: >> >>> try: >>> ... >>> except socket.gaierror as e: >>> # watch out, a composition of bad advice (on demand) city, host = ( >>> ('city' in locals() or "blabla"), >>> ('host' in locals() or "blablabla") ) >> >> Bad advice, and buggy as well. >> >> py> city = "New New York" >> py> ('city' in locals() or "Blah blah") >> True >> >> Oh man, can you imagine Nikos trying to debug that? > > Thanks. Sorry. This hurts. I didn't mean it to be buggy. > > Let's see. The task is to assign a default value to city and host, if > they haven't a value yet; on one line (which I take to mean one > statement); in an "except" block where we may not know which > assignment failed in the "try" block; without "if"; but "or" is > allowed. > > But the logic I was trying to implement is > > city, host = ( (city if 'city' in locals() else "default city"), > (host if 'host' in locals() else "default host") ) > > which uses an "if". The old tricks of using "or" and stuff for this > would surely go too far. > > I know! > > city, host = ( locals().get('city', "default city"), > locals().get('host', "default host") ) I tend to like this: I might use it because it is a clear way to tell what var failed in the try clause and default it to soemthing. > Testing if the variables only exists when actually assigned: > > >>> def foo(x, y): > ... if x: foo = None > ... if y: bar = "bar" > ... return locals() > ... > >>> foo(False, False) > {'y': False, 'x': False} > >>> foo(False, True) > {'y': True, 'x': False, 'bar': 'bar'} > > Seems so. > > What a monster, though. I don't even want to know if this, too, is > buggy in some way. It looks fragile. > > Nikos, don't do this. The way to test if an assignment failed is to > use a try-catch. The way to know which one failed is to put each in > its own try-catch. Dave's way though seems better. Assign the vars default string and if they get re-assinged correctly that would be ideal, otherwise we have already given them the defaults. ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) city = "??????? ????" host = "??????? ?????????" try: gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') city = gi.time_zone_by_addr( ipval ) host = socket.gethostbyaddr( ipval ) [0] except Exception as e: print( "metrites.py => (%s): " % lastvisit, repr( sys.exc_info() ), file=open('/tmp/err.out', 'w') ) I'll think i'll stick to this solution. From davea at davea.name Sun Sep 29 07:27:57 2013 From: davea at davea.name (Dave Angel) Date: Sun, 29 Sep 2013 11:27:57 +0000 (UTC) Subject: Handling 3 operands in an expression without raising an exception References: <20130928183833.GA13630@piedra> <5247f760$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 29/9/2013 07:14, ????? wrote: > Dave's way though seems better. > Assign the vars default string and if they get re-assinged correctly > that would be ideal, otherwise we have already given them the defaults. > > ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or > os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) > city = "??????? ????" > host = "??????? ?????????" > try: > gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') > city = gi.time_zone_by_addr( ipval ) > host = socket.gethostbyaddr( ipval ) [0] > except Exception as e: > print( "metrites.py => (%s): " % lastvisit, repr( sys.exc_info() ), > file=open('/tmp/err.out', 'w') ) > > I'll think i'll stick to this solution. > But you've put gi back in to the try-block. If it really belongs there, then you'd better give it a default value as well. On the other hand, if it can't get an exception, you should move it out. -- DaveA From nikos.gr33k at gmail.com Sun Sep 29 07:34:02 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Sun, 29 Sep 2013 14:34:02 +0300 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: <20130928183833.GA13630@piedra> <5247f760$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: ???? 29/9/2013 2:27 ??, ?/? Dave Angel ??????: > On 29/9/2013 07:14, ????? wrote: > > >> Dave's way though seems better. >> Assign the vars default string and if they get re-assinged correctly >> that would be ideal, otherwise we have already given them the defaults. >> >> ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or >> os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) >> city = "??????? ????" >> host = "??????? ?????????" >> try: >> gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') >> city = gi.time_zone_by_addr( ipval ) >> host = socket.gethostbyaddr( ipval ) [0] >> except Exception as e: >> print( "metrites.py => (%s): " % lastvisit, repr( sys.exc_info() ), >> file=open('/tmp/err.out', 'w') ) >> >> I'll think i'll stick to this solution. >> > > But you've put gi back in to the try-block. If it really belongs there, > then you'd better give it a default value as well. On the other hand, > if it can't get an exception, you should move it out. You are right i just put it there because its being relevant to the whole geoip things. Givign it a default value will not really help much because i'am not printing it later on it just is necessay to poitn to an existing geopip file in plcace. If it fails to be assinged then i will just cat /etc/err/out and see that it erred out and then take action to fix it. From denismfmcmahon at gmail.com Sun Sep 29 17:15:44 2013 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Sun, 29 Sep 2013 21:15:44 +0000 (UTC) Subject: Handling 3 operands in an expression without raising an exception References: <20130928183833.GA13630@piedra> <5247f760$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, 29 Sep 2013 14:34:02 +0300, ????? wrote: > ???? 29/9/2013 2:27 ??, ?/? Dave Angel ??????: >> On 29/9/2013 07:14, ????? wrote: >> >> >>> Dave's way though seems better. >>> Assign the vars default string and if they get re-assinged correctly >>> that would be ideal, otherwise we have already given them the >>> defaults. >>> >>> ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or >>> os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) >>> city = "??????? ????" >>> host = "??????? ?????????" >>> try: >>> gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') >>> city = gi.time_zone_by_addr( ipval ) >>> host = socket.gethostbyaddr( ipval ) [0] >>> except Exception as e: >>> print( "metrites.py => (%s): " % lastvisit, repr( sys.exc_info() ), >>> file=open('/tmp/err.out', 'w') ) >>> >>> I'll think i'll stick to this solution. >>> >>> >> But you've put gi back in to the try-block. If it really belongs >> there, >> then you'd better give it a default value as well. On the other hand, >> if it can't get an exception, you should move it out. > > You are right i just put it there because its being relevant to the > whole geoip things. Givign it a default value will not really help much > because i'am not printing it later on it just is necessay to poitn to an > existing geopip file in plcace. > > If it fails to be assinged then i will just cat /etc/err/out and see > that it erred out and then take action to fix it. Nick, you have now spent 4 days arguing over a minor coding problem that you were given solutions to on the first day, primarily because you feel that the solutions you are being offend some programming aesthetic you have. I suggest that it's time for you to re-evaluate what you want from this ng, and indeed what language you want to code in if your perl "minimal code possible" aesthetic is so important to you. If you want good python code, then stop telling everyone here that their working solutions are wrong and should be more like your dysfunctional code, and use the solutions you are given. If you want to write minimalist perl code, then stop using python and use perl. In either case, you need to stop arguing with people who are offering you solutions to your problems solely based on the fact that you don't like their coding styles. You are the one who comes here asking for solutions. Either accept the solutions you are offered, or stop asking for them. -- Denis McMahon, denismfmcmahon at gmail.com From breamoreboy at yahoo.co.uk Mon Sep 30 11:07:41 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 30 Sep 2013 16:07:41 +0100 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: <20130928183833.GA13630@piedra> <5247f760$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 29/09/2013 22:15, Denis McMahon wrote: > > Nick, you have now spent 4 days arguing over a minor coding problem that > you were given solutions to on the first day, primarily because you feel > that the solutions you are being offend some programming aesthetic you > have. > > I suggest that it's time for you to re-evaluate what you want from this > ng, and indeed what language you want to code in if your perl "minimal > code possible" aesthetic is so important to you. > > If you want good python code, then stop telling everyone here that their > working solutions are wrong and should be more like your dysfunctional > code, and use the solutions you are given. > > If you want to write minimalist perl code, then stop using python and use > perl. > > In either case, you need to stop arguing with people who are offering you > solutions to your problems solely based on the fact that you don't like > their coding styles. > > You are the one who comes here asking for solutions. Either accept the > solutions you are offered, or stop asking for them. > +googol -- Cheers. Mark Lawrence From jpiitula at ling.helsinki.fi Sun Sep 29 08:24:59 2013 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 29 Sep 2013 15:24:59 +0300 Subject: Handling 3 operands in an expression without raising an exception References: <20130928183833.GA13630@piedra> <5247f760$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: ?????????? writes: > ??????? 29/9/2013 2:04 ????, ??/?? Jussi Piitulainen > ??????????: > > > Let's see. The task is to assign a default value to city and host, > > if they haven't a value yet; on one line (which I take to mean one > > statement); in an "except" block where we may not know which > > assignment failed in the "try" block; without "if"; but "or" is > > allowed. > > > > But the logic I was trying to implement is > > > > city, host = ( (city if 'city' in locals() else "default city"), > > (host if 'host' in locals() else "default host") ) > > > > which uses an "if". The old tricks of using "or" and stuff for > > this would surely go too far. > > > > I know! > > > > city, host = ( locals().get('city', "default city"), > > locals().get('host', "default host") ) > > I tend to like this: I might use it because it is a clear way to > tell what var failed in the try clause and default it to soemthing. Well, I think it's as close to what you asked as I can get. Seeing it in a real program would make me nervous, though. I shouldn't have brought it up at all. [...] > Dave's way though seems better. > Assign the vars default string and if they get re-assinged correctly > that would be ideal, otherwise we have already given them the defaults. > > ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or > os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) > city = "?????????? ???????" > host = "?????????? ????????????????" > try: > gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') > city = gi.time_zone_by_addr( ipval ) > host = socket.gethostbyaddr( ipval ) [0] > except Exception as e: > print( "metrites.py => (%s): " % lastvisit, repr( > sys.exc_info() ), file=open('/tmp/err.out', 'w') ) > > I'll think i'll stick to this solution. Yes, that's a serious way to do it. (Except the destination of the error message probably isn't.) From davea at davea.name Sun Sep 29 05:50:08 2013 From: davea at davea.name (Dave Angel) Date: Sun, 29 Sep 2013 09:50:08 +0000 (UTC) Subject: Handling 3 operands in an expression without raising an exception References: <20130928183833.GA13630@piedra> Message-ID: On 29/9/2013 03:35, ????? wrote: > > ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or > os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) > > try: > gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') > city = gi.time_zone_by_addr( ipval ) > host = socket.gethostbyaddr( ipval ) [0] > except socket.gaierror as e: > city = "??????? ????" > host = "??????? ?????????" ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) gi = city=host=None try: gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') city = gi.time_zone_by_addr( ipval ) host = socket.gethostbyaddr( ipval ) [0] except socket.gaierror as e: gi,city,host=gi if gi is not None else "who knows", city if city is not None else"??????? ????", host if host is not None else "??????? ?????????" That's one line. And if you now want to eliminate the gi=city=host=None line, let me attempt that. But this probably will have some serious typo in it, as I'm not testing any of these. And it assumes that the code is at top-level, and that none of these variables already exists. ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) try: gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') city = gi.time_zone_by_addr( ipval ) host = socket.gethostbyaddr( ipval ) [0] except socket.gaierror as e: gi,city,host=globals().get("gi", "who knows"), globals().get("city", "??????? ????"), globals().get("host", "??????? ?????????") Or perhaps even, assuming this is the main script, and not a loaded module: import __main__ as qq ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) try: gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') city = gi.time_zone_by_addr( ipval ) host = socket.gethostbyaddr( ipval ) [0] except socket.gaierror as e: gi,city,host=getattr(qq,"gi", "who knows"), getattr(qq,"city","??????? ????"),getattr(qq, "host", "??????? ?????????") -- DaveA From nikos.gr33k at gmail.com Sun Sep 29 06:17:36 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Sun, 29 Sep 2013 13:17:36 +0300 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: <20130928183833.GA13630@piedra> Message-ID: ???? 29/9/2013 12:50 ??, ?/? Dave Angel ??????: > ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or > os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) > try: > gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') > city = gi.time_zone_by_addr( ipval ) > host = socket.gethostbyaddr( ipval ) [0] > except socket.gaierror as e: > gi,city,host=globals().get("gi", "who knows"), globals().get("city", > "??????? ????"), globals().get("host", "??????? > ?????????") Hello Dave, By looking at your code i think that you are tellign the progrma to try to gri don't know what the function globals() is supposed to do but i was thinking more of: ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) try: city = gi.time_zone_by_addr( ipval ) host = socket.gethostbyaddr( ipval ) [0] except socket.gaierror as e: # We need something here to identify which one of the 2 above variables or even both of them went wrong, and then assign the appropriate value to each one of them but i don't know how to write it. Is there a function that can tell us which variable failed to be assigned a value that we can use in order to decide to which variable we will From davea at davea.name Sun Sep 29 06:57:30 2013 From: davea at davea.name (Dave Angel) Date: Sun, 29 Sep 2013 10:57:30 +0000 (UTC) Subject: Handling 3 operands in an expression without raising an exception References: <20130928183833.GA13630@piedra> Message-ID: On 29/9/2013 06:17, ????? wrote: > ???? 29/9/2013 12:50 ??, ?/? Dave Angel ??????: >> ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or >> os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) >> try: >> gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') >> city = gi.time_zone_by_addr( ipval ) >> host = socket.gethostbyaddr( ipval ) [0] >> except socket.gaierror as e: >> gi,city,host=globals().get("gi", "who knows"), globals().get("city", >> "??????? ????"), globals().get("host", "??????? >> ?????????") > > Hello Dave, > > By looking at your code i think that you are tellign the progrma to try > to gri don't know what the function globals() is supposed to do Try help(globals()) at the interpreter prompt. Help on built-in function globals in module builtins: globals(...) globals() -> dictionary Return the dictionary containing the current scope's global variables. So once you have a dictionary, you can use get() to fetch values which might or not be present, and supply the default in case they aren't. > > but i was thinking more of: > > ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or > os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) > try: > city = gi.time_zone_by_addr( ipval ) > host = socket.gethostbyaddr( ipval ) [0] > except socket.gaierror as e: > # We need something here to identify which one of the 2 above variables > or even both of them went wrong, and then assign the appropriate value > to each one of them but i don't know how to write it. > > Is there a function that can tell us which variable failed to be > assigned a value that we can use in order to decide to which variable we > will > I showed you the only 3 ways I know of, and none of them is as readable as just setting the defaults in the standard way. I only showed you those in order to show you how unreadable it would be. -- DaveA From rosuav at gmail.com Sun Sep 29 09:58:01 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 29 Sep 2013 23:58:01 +1000 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: <20130928183833.GA13630@piedra> Message-ID: On Sun, Sep 29, 2013 at 8:57 PM, Dave Angel wrote: > Try help(globals()) at the interpreter prompt. > > Help on built-in function globals in module builtins: > > globals(...) > globals() -> dictionary > > Return the dictionary containing the current scope's global variables. Insignificant quibble: help(globals()) will give you help on the dict type. What you actually want here is help(globals). Otherwise agreed. ChrisA From denismfmcmahon at gmail.com Sun Sep 29 17:01:28 2013 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Sun, 29 Sep 2013 21:01:28 +0000 (UTC) Subject: Handling 3 operands in an expression without raising an exception References: <20130928183833.GA13630@piedra> Message-ID: On Sun, 29 Sep 2013 13:17:36 +0300, ????? wrote: > ???? 29/9/2013 12:50 ??, ?/? Dave Angel ??????: >> ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or >> os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) >> try: >> gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') >> city = gi.time_zone_by_addr( ipval ) >> host = socket.gethostbyaddr( ipval ) [0] >> except socket.gaierror as e: >> gi,city,host=globals().get("gi", "who knows"), globals().get ("city", >> "??????? ????"), globals().get("host", "??????? ?????????") > > Hello Dave, > > By looking at your code i think that you are tellign the progrma to try > to gri don't know what the function globals() is supposed to do > > but i was thinking more of: > > ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or > os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) > try: > city = gi.time_zone_by_addr( ipval ) > host = socket.gethostbyaddr( ipval ) [0] > except socket.gaierror as e: > # We need something here to identify which one of the 2 above variables > or even both of them went wrong, and then assign the appropriate value > to each one of them but i don't know how to write it. > > Is there a function that can tell us which variable failed to be > assigned a value that we can use in order to decide to which variable we > will Yes, set the default values first, and overwrite them with the successful values when the values are successfully calculated. This is a very common method used in many programming languages. -- Denis McMahon, denismfmcmahon at gmail.com From nikos.gr33k at gmail.com Sun Sep 29 07:06:39 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Sun, 29 Sep 2013 14:06:39 +0300 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: <20130928183833.GA13630@piedra> Message-ID: ???? 29/9/2013 12:50 ??, ?/? Dave Angel ??????: > ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or > os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) > try: > gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') > city = gi.time_zone_by_addr( ipval ) > host = socket.gethostbyaddr( ipval ) [0] > except socket.gaierror as e: > gi,city,host=globals().get("gi", "who knows"), globals().get("city", > "??????? ????"), globals().get("host", "??????? > ?????????") Hello Dave, By looking at your code i think that you are tellign the progrma to try to gri don't know what the function globals() is supposed to do but i was thinking more of: ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) try: city = gi.time_zone_by_addr( ipval ) host = socket.gethostbyaddr( ipval ) [0] except socket.gaierror as e: # We need something here to identify which one of the 2 above variables or even both of them went wrong, and then assign the appropriate value to each one of them but i don't know how to write it. Is there a function that can tell us which variable failed to be assigned a value that we can use in order to decide to which string we weill be defaulting to? From antoon.pardon at rece.vub.ac.be Sun Sep 29 06:48:59 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Sun, 29 Sep 2013 12:48:59 +0200 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: <20130928183833.GA13630@piedra> Message-ID: <5248059B.6050504@rece.vub.ac.be> Op 29-09-13 09:35, ????? schreef: > ???? 29/9/2013 2:04 ??, ?/? Chris Angelico ??????: >> On Sun, Sep 29, 2013 at 4:45 AM, Mark Lawrence >> wrote: >>> Not tortured, simply murdered so we don't have to put up with his >>> completely >>> unacceptable behaviour, which sadly is thriving owing to so many people >>> ignoring the "do not feed this moron" signs. >> >> You miss one important factor in these discussions: the silent >> majority of readers. We have a few people here who are not "worth" >> responding to, as they're highly unlikely to listen (the most >> noteworthy other example being jmf on Unicode), but that doesn't mean >> the threads can't be useful to someone else. And sometimes there can >> be some extremely entertaining conversation, too. >> >> That's also why I don't plonk anyone :) > > Its not that i don't listen, its that i want something to be implemented > in a specific way. Why? What is so important about this particular way, that you are willing to spend/waste so much time on it? You act like someone who want to get from Brussels to London and when asked how to do that gets advise on how to take the boat or plane at which point you react that you want to get to Londen without boat or plane but just by bicycle. And in further exchange make it clear that using a bike is more important than arriving in London. So please why do you make it your priority to implement it in a specific way, over it working correctly? -- Antoon Pardon From piet at vanoostrum.org Sun Sep 29 13:24:55 2013 From: piet at vanoostrum.org (Piet van Oostrum) Date: Sun, 29 Sep 2013 13:24:55 -0400 Subject: Handling 3 operands in an expression without raising an exception References: <20130928183833.GA13630@piedra> Message-ID: Antoon Pardon writes: > Why? What is so important about this particular way, that you are > willing to spend/waste so much time on it? You act like someone > who want to get from Brussels to London and when asked how to > do that gets advise on how to take the boat or plane at which > point you react that you want to get to Londen without boat > or plane but just by bicycle. And in further exchange make it > clear that using a bike is more important than arriving in London. And then the easiests would be to put your bicycle in the train. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From python at mrabarnett.plus.com Sun Sep 29 13:44:13 2013 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 29 Sep 2013 18:44:13 +0100 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: <20130928183833.GA13630@piedra> Message-ID: <524866ED.80400@mrabarnett.plus.com> On 29/09/2013 18:24, Piet van Oostrum wrote: > Antoon Pardon writes: > >> Why? What is so important about this particular way, that you are >> willing to spend/waste so much time on it? You act like someone >> who want to get from Brussels to London and when asked how to >> do that gets advise on how to take the boat or plane at which >> point you react that you want to get to Londen without boat >> or plane but just by bicycle. And in further exchange make it >> clear that using a bike is more important than arriving in London. > > And then the easiests would be to put your bicycle in the train. > But what if you don't want to use the train, but cycle all the way? There _must_ be a way of cycling through the tunnel... From joel.goldstick at gmail.com Sun Sep 29 14:45:21 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sun, 29 Sep 2013 14:45:21 -0400 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: <524866ED.80400@mrabarnett.plus.com> References: <20130928183833.GA13630@piedra> <524866ED.80400@mrabarnett.plus.com> Message-ID: On Sun, Sep 29, 2013 at 1:44 PM, MRAB wrote: > On 29/09/2013 18:24, Piet van Oostrum wrote: > >> Antoon Pardon writes: >> >> Why? What is so important about this particular way, that you are >>> willing to spend/waste so much time on it? You act like someone >>> who want to get from Brussels to London and when asked how to >>> do that gets advise on how to take the boat or plane at which >>> point you react that you want to get to Londen without boat >>> or plane but just by bicycle. And in further exchange make it >>> clear that using a bike is more important than arriving in London. >>> >> >> And then the easiests would be to put your bicycle in the train. >> >> But what if you don't want to use the train, but cycle all the way? > There _must_ be a way of cycling through the tunnel... > wlle thats fien bit i doont wnt to go thru the tunnel. Perhaps you can suggest my sloulution > -- > https://mail.python.org/**mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Mon Sep 30 11:05:28 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 30 Sep 2013 16:05:28 +0100 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: <524866ED.80400@mrabarnett.plus.com> References: <20130928183833.GA13630@piedra> <524866ED.80400@mrabarnett.plus.com> Message-ID: On 29/09/2013 18:44, MRAB wrote: > On 29/09/2013 18:24, Piet van Oostrum wrote: >> Antoon Pardon writes: >> >>> Why? What is so important about this particular way, that you are >>> willing to spend/waste so much time on it? You act like someone >>> who want to get from Brussels to London and when asked how to >>> do that gets advise on how to take the boat or plane at which >>> point you react that you want to get to Londen without boat >>> or plane but just by bicycle. And in further exchange make it >>> clear that using a bike is more important than arriving in London. >> >> And then the easiests would be to put your bicycle in the train. >> > But what if you don't want to use the train, but cycle all the way? > There _must_ be a way of cycling through the tunnel... There is but all the illegal immigrants who use it won't tell us about it :) -- Cheers. Mark Lawrence From steve+comp.lang.python at pearwood.info Sat Sep 28 15:20:23 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Sep 2013 19:20:23 GMT Subject: Handling 3 operands in an expression without raising an exception References: <20130928183833.GA13630@piedra> Message-ID: <52472bf6$0$30000$c3e8da3$5496439d@news.astraweb.com> On Sat, 28 Sep 2013 19:45:40 +0100, Mark Lawrence wrote: > Not tortured, simply murdered If your aim was to prove that you're a waste of space than Nikos, you've admirably succeeded. *plonk* -- Steven From neilc at norwich.edu Mon Sep 30 07:32:37 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 30 Sep 2013 11:32:37 GMT Subject: Handling 3 operands in an expression without raising an exception References: Message-ID: On 2013-09-28, Zero Piraeus wrote: >: > >> On Sat, Sep 28, 2013 at 1:53 PM, Mark Lawrence wrote: >> > You actually need the tool that was used on King Edward II. > > To be clear, Mark, you are calling for ?????????? to be tortured to death > with a red hot poker, yes? > > I'm going to go out on a limb and suggest that such a suggestion is > outside what people generally consider acceptable on this list. It's reassuring that even a guy like Nikos has his White Knights. -- Neil Cerutti From rosuav at gmail.com Mon Sep 30 07:53:38 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 Sep 2013 21:53:38 +1000 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: On Mon, Sep 30, 2013 at 9:32 PM, Neil Cerutti wrote: > On 2013-09-28, Zero Piraeus wrote: >>: >> >>> On Sat, Sep 28, 2013 at 1:53 PM, Mark Lawrence wrote: >>> > You actually need the tool that was used on King Edward II. >> >> To be clear, Mark, you are calling for ?????????? to be tortured to death >> with a red hot poker, yes? >> >> I'm going to go out on a limb and suggest that such a suggestion is >> outside what people generally consider acceptable on this list. > > It's reassuring that even a guy like Nikos has his White Knights. Ahoy! Ahoy! Check! Actually, it's more that even those of us who will put him down verbally don't actually want to see him tortured to death. I've strongly recommended that he either shape up or ship out (learn to code or get out of programming as a business), but that doesn't in any way mean I would rejoice at his death. But he is annoying. Very annoying. And I completely understand the frustration that leads people to want him to suffer great pain. ChrisA From neilc at norwich.edu Mon Sep 30 08:56:44 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 30 Sep 2013 12:56:44 GMT Subject: Handling 3 operands in an expression without raising an exception References: Message-ID: On 2013-09-30, Chris Angelico wrote: >>>> > You actually need the tool that was used on King Edward >>>> > II. >>> >>> To be clear, Mark, you are calling for ?????????? to be >>> tortured to death with a red hot poker, yes? >>> >>> I'm going to go out on a limb and suggest that such a >>> suggestion is outside what people generally consider >>> acceptable on this list. >> >> It's reassuring that even a guy like Nikos has his White >> Knights. > > Ahoy! Ahoy! Check! > > Actually, it's more that even those of us who will put him down > verbally don't actually want to see him tortured to death. I've > strongly recommended that he either shape up or ship out (learn to > code or get out of programming as a business), but that doesn't in any > way mean I would rejoice at his death. This makes perfect sense. It's be sort of like being one of the police in Dallas protecting Oswald; it's from a sense of duty, rather than a generally sincere love. > But he is annoying. Very annoying. And I completely understand > the frustration that leads people to want him to suffer great > pain. I don't want him to suffer great pain, but it would please me if it were possible to annoy him in some way. Like maybe with the sound of a mosquito. BZZZZ! BzzzzzZZZZZ! -- Neil Cerutti From antoon.pardon at rece.vub.ac.be Sat Sep 28 09:53:13 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Sat, 28 Sep 2013 15:53:13 +0200 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: <5246DF49.5040508@rece.vub.ac.be> Op 28-09-13 00:06, ????? schreef: > ???? 27/9/2013 8:00 ??, ?/? Grant Edwards ??????: >> On 2013-09-27, ?????????? wrote: >> >>> Sure your method follows the the logic in a straighforward way >>> step-by-step but i just dont want to spent almost 20 lines of code just >>> to calculate 2 variables(city and host). >> >> Does your provider charge you per line of code? >> >> If all that matters is the number of lines of code then use this: >> >> city,host = 0,0 >> >> Only _1_ nice short line of code. >> >> Happy? >> > > Well to tell the truth no matter what you say to me if something can be > written in less lines than another implementation but still retain its > simplicity and straightforward logic behind it i would prefer it! > I don't know why you think otherwise, especially people who are used to > write Perl code(me being one of them) would agree with me! The problem is, as it stands you seem to make it a priority to write compact code over correct code, wasting everybody's time. If you hadn't been insisting on trying to reduce the number of lines of the various given proposals, you might already have a working solution and be working on something else. As it is all your attempts to reduce the number of lines while retaining its simplicity and straightforward logic behind it have only resulted in you producing code that didn't work. People like you who judge code in one language by how much it resembles code in an other language are like people who used to work with glue but need to work with hammer and nails for some reason and are surprised they just can't subtituted nails for glue and fail to see they may have to rethink the design. So they just keep trying glue solutions with nails and every nail solution that is offered by people who have experience with nails, they will adapt until it looks like it could be a glue solution. In the mean time all these glue solutions fail and much time is wasted. -- Antoon Pardon From joel.goldstick at gmail.com Sat Sep 28 12:15:52 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sat, 28 Sep 2013 12:15:52 -0400 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: <5246DF49.5040508@rece.vub.ac.be> References: <5246DF49.5040508@rece.vub.ac.be> Message-ID: On Sat, Sep 28, 2013 at 9:53 AM, Antoon Pardon wrote: > Op 28-09-13 00:06, ????? schreef: > > ???? 27/9/2013 8:00 ??, ?/? Grant Edwards ??????: >> >>> On 2013-09-27, ?????????? wrote: >>> >>> Sure your method follows the the logic in a straighforward way >>>> step-by-step but i just dont want to spent almost 20 lines of code just >>>> to calculate 2 variables(city and host). >>>> >>> >>> Does your provider charge you per line of code? >>> >>> If all that matters is the number of lines of code then use this: >>> >>> city,host = 0,0 >>> >>> Only _1_ nice short line of code. >>> >>> Happy? >>> >>> >> Well to tell the truth no matter what you say to me if something can be >> written in less lines than another implementation but still retain its >> simplicity and straightforward logic behind it i would prefer it! >> I don't know why you think otherwise, especially people who are used to >> write Perl code(me being one of them) would agree with me! >> > > The problem is, as it stands you seem to make it a priority to write > compact code over correct code, wasting everybody's time. > > If you hadn't been insisting on trying to reduce the number of lines > of the various given proposals, you might already have a working > solution and be working on something else. > > As it is all your attempts to reduce the number of lines while retaining > its simplicity and straightforward logic behind it have only resulted in > you producing code that didn't work. > > People like you who judge code in one language by how much it resembles > code in an other language are like people who used to work with glue but > need to work with hammer and nails for some reason and are surprised > they just can't subtituted nails for glue and fail to see they may have > to rethink the design. So they just keep trying glue solutions with > nails and every nail solution that is offered by people who have > experience with nails, they will adapt until it looks like it could be > a glue solution. In the mean time all these glue solutions fail and > much time is wasted. > > > -- > Antoon Pardon > > -- > https://mail.python.org/**mailman/listinfo/python-list > Its funny how the guy who wants the one line of code has the longest threads that meander endlessly in the mailing list. He's a write only machine -- don't think he reads or understands or has any interest in understanding what people here explain to him. This whole goofy exercise is to try to figure out where the visitor to the website come from -- the geo ip stuff, etc. Now back last month there was another endless thread where is was pointed out that you can't really be sure where someone is reading from. Next we'll get more questions about how to screw up unicode, and how to write code that deals with apache and linux shell with the caveat that the OP has no interesting in learning how those things work. He just wants the one line. Troll is maybe too respectable a label to put on this guy. -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From pecore at pascolo.net Sun Sep 29 11:28:26 2013 From: pecore at pascolo.net (giacomo boffi) Date: Sun, 29 Sep 2013 17:28:26 +0200 Subject: Handling 3 operands in an expression without raising an exception References: Message-ID: <87eh87ir51.fsf@pascolo.net> ????? writes: > IF it can also be written in one-line def f(x,n,w):return(lambda y=f(x[::2],n/2,w[::2]),z=f(x[1::2],n/2,w[::2]):reduce(lambda x,y:x+y,zip(*[(y[k]+w[k]*z[k],y[k]-w[k]*z[k]) for k in range(n/2)])))()if n>1 else x -- anch'io la penso come me, ma -- SteO153, in IHC From joel.goldstick at gmail.com Sun Sep 29 12:07:39 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sun, 29 Sep 2013 12:07:39 -0400 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: <87eh87ir51.fsf@pascolo.net> References: <87eh87ir51.fsf@pascolo.net> Message-ID: On Sun, Sep 29, 2013 at 11:28 AM, giacomo boffi wrote: > ????? writes: > > > IF it can also be written in one-line > > def f(x,n,w):return(lambda > y=f(x[::2],n/2,w[::2]),z=f(x[1::2],n/2,w[::2]):reduce(lambda > x,y:x+y,zip(*[(y[k]+w[k]*z[k],y[k]-w[k]*z[k]) for k in range(n/2)])))()if > n>1 else x > > -- > anch'io la penso come me, ma -- SteO153, in IHC > -- > https://mail.python.org/mailman/listinfo/python-list > I've been reading along and learning some really obscure coding patterns. The missing part is the why. Antoon asks: Why? What is so important about this particular way, that you are willing to spend/waste so much time on it? This question goes completely unnoticed. In the big picture this seems to be the pattern. Nikos asks a question that shows fundamental flaws in his understanding of a problem. People probe to understand what he really wants. He ignores everything except little coding snippets, and requests different choices on and on. Its like a fussy shopper wanting to see endless dresses, and in the end choosing none. I don't think any of Nikos questions have anything to do with finding an answer, because if you dig deeper into the questions they end up being only red herrings. As I pointed out yesterday he still hasn't fixed the fact that his python files on his server are set with permissions to read the code which contains passwords in plain text. That was the big drama from June So, Antoon, I think the question is why are 'we' wasting so much time. Nikos is just the orchestrator. He isn't wasting any time. He isn't doing anything. Here's my question: I wonder if Nikos has ever been employed to write software. If so, I wonder how long he lasted before he was let go. And I feel bad for the guy who had to support his code! -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sun Sep 29 12:18:59 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 Sep 2013 02:18:59 +1000 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: <87eh87ir51.fsf@pascolo.net> Message-ID: On Mon, Sep 30, 2013 at 2:07 AM, Joel Goldstick wrote: > Here's my question: I wonder if Nikos has ever been employed to write > software. If so, I wonder how long he lasted before he was let go. Unfortunately that proves nothing. My boss used to have another employee besides me - he lasted for several years before he finally quit (wasn't fired). In retrospect, my boss wishes he'd fired him a lot sooner, but hindsight is 20/20, they say. We've since ripped out every line of code this guy wrote and rewritten from scratch. No, merely holding down a job doesn't prove anything more than that your boss hasn't gone through and evaluated your code. In my example, it was because the boss was too busy (he knew stuff was taking a long time to get written and debugged, he didn't know it was because the code was trash); in other cases, I have no doubt, it's because the boss has no clue what makes good code. That's why he hired a programmer, after all - to do what he can't do himself. It's unfortunately not difficult for someone to be employed to do something he's utterly incompetent to do. ChrisA From gheskett at wdtv.com Sun Sep 29 13:32:02 2013 From: gheskett at wdtv.com (Gene Heskett) Date: Sun, 29 Sep 2013 13:32:02 -0400 Subject: Handling 3 operands in an expression without raising an exception In-Reply-To: References: Message-ID: <201309291332.02130.gheskett@wdtv.com> On Sunday 29 September 2013 13:03:17 Chris Angelico did opine: > On Mon, Sep 30, 2013 at 2:07 AM, Joel Goldstick > > wrote: > > Here's my question: I wonder if Nikos has ever been employed to write > > software. If so, I wonder how long he lasted before he was let go. > > Unfortunately that proves nothing. My boss used to have another > employee besides me - he lasted for several years before he finally > quit (wasn't fired). In retrospect, my boss wishes he'd fired him a > lot sooner, but hindsight is 20/20, they say. We've since ripped out > every line of code this guy wrote and rewritten from scratch. No, > merely holding down a job doesn't prove anything more than that your > boss hasn't gone through and evaluated your code. In my example, it > was because the boss was too busy (he knew stuff was taking a long > time to get written and debugged, he didn't know it was because the > code was trash); in other cases, I have no doubt, it's because the > boss has no clue what makes good code. That's why he hired a > programmer, after all - to do what he can't do himself. It's > unfortunately not difficult for someone to be employed to do something > he's utterly incompetent to do. > > ChrisA +1000 or more Chris. That should be printed, and dye transfered to the paint on every coders cubicle wall, with a wall sconce above it for illumination. I have a similar story but it occurred in the broadcast engineering arena, back in the middle of the last decade. I had been to this facility with orders to see if I could clean up the technical mess once before. A year later I was back out there, and found one of my fixes undone, with disastrous results on the video quality. So I fixed it again, then, when the person nominally in charge of those things wandered in a couple of hours later I took him to an out of the traffic and tried to educate him. Mind you, he's the one with the degree. The more I talked the more upset I got and I even questioned his family tree. I figured I was in for a good scrap the way I laid into him, but when I finally ran down, he floored me by saying that "no one had ever explained cause and effect to him that clearly, and why the hell wasn't I teaching someplace?, as I was better by far than any prof he ever had in school." He did I think, finally understand that he was in over his head a wee bit trying to keep 4 television stations and a cable channel on the air. So he left for a radio station in NC I was told, because I got sent back a third time to keep it running while the commission was cogitating on the license transfers to another media group. Now of course I'm retired, we've since converted to digital broadcasting, and much of my knowledge in analog studio stuff is largely moot. Time marches on. And it gives me time to lurk here, hoping I'll learn a bit of python by osmosis. Please, do carry on. The comments, often pithy but just as often over my now ancient head, are certainly worth the admission. Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) There are no great men, only great challenges that ordinary men are forced by circumstances to meet. -- Admiral William Halsey A pen in the hand of this president is far more dangerous than 200 million guns in the hands of law-abiding citizens. From pecore at pascolo.net Sun Sep 29 17:39:03 2013 From: pecore at pascolo.net (giacomo boffi) Date: Sun, 29 Sep 2013 23:39:03 +0200 Subject: Handling 3 operands in an expression without raising an exception References: <87eh87ir51.fsf@pascolo.net> Message-ID: <87a9ivi9zc.fsf@pascolo.net> Joel Goldstick writes: > On Sun, Sep 29, 2013 at 11:28 AM, giacomo boffi wrote: > > ????? writes: > > > IF it can also be written in one-line > > def f(x,n,w):return(lambda y=f(x[::2],n/2,w[::2]),z=f(x[1::2],n/2,w > [::2]):reduce(lambda x,y:x+y,zip(*[(y[k]+w[k]*z[k],y[k]-w[k]*z[k]) for k in > range(n/2)])))()if n>1 else x > > I've been reading along and learning some really obscure coding > patterns. well, the obscure patterns aren't mine, they were contributed by some it.comp.python regulars, to which credit is due if credit is due (please ask google groups for the individual contributions) > why? to show a recreational one liner from which ????? could learn something, one way or another -- X = f(x,n,[exp(-2*pi*1j*k/n) for k in range(n/2)]) From pecore at pascolo.net Sun Sep 29 17:49:27 2013 From: pecore at pascolo.net (giacomo boffi) Date: Sun, 29 Sep 2013 23:49:27 +0200 Subject: Handling 3 operands in an expression without raising an exception References: <87eh87ir51.fsf@pascolo.net> <87a9ivi9zc.fsf@pascolo.net> Message-ID: <8761tji9i0.fsf@pascolo.net> giacomo boffi writes: > it.comp.python oops, it.comp.LANG.python -- I do desire we may be better strangers. From davea at davea.name Thu Sep 26 16:37:40 2013 From: davea at davea.name (Dave Angel) Date: Thu, 26 Sep 2013 20:37:40 +0000 (UTC) Subject: Handling 3 operands in an expression without raising an exception References: Message-ID: On 26/9/2013 12:58, ????? wrote: > But actually i have 2 variables that relay on a proper ip address. > > ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or > os.environ.get('REMOTE_ADDR', "UnKnown Origin") ) > try: > gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') > city = gi.time_zone_by_addr( ipval ) > host = socket.gethostbyaddr( ipval ) [0] > except socket.gaierror as e: > city = host = "UnKnown Origin" First concept: A try/except should wrap one conceptual calculation. In this case, you have three. So if the host lookup fails, you'll overwrite the city you already presumably figured out. You also don't do anything about an exception that might occur calculating gi. If one isn't possible, or if it's unrelated to the other two, then that line should come OUT of the try-block. What is city? The function name implies it's a time zone, which is presumably a float, -12 < x < +12. If this is the case, then a string is a lousy default value. > > But then what if in case of an error i needed different string set to be > assigned on city and host respectively? Nothing limits the except clause to a single line. > > As i ahve it know in case of n address related error i get the smae > sting for both of them. > No idea what this is trying to say. -- DaveA From denismfmcmahon at gmail.com Thu Sep 26 10:38:16 2013 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Thu, 26 Sep 2013 14:38:16 +0000 (UTC) Subject: Handling 3 operands in an expression without raising an exception References: Message-ID: On Thu, 26 Sep 2013 12:56:19 +0300, ????? wrote: > host = socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or > os.environ.get('REMOTE_ADDR') or "??????? ?????????" ) Perhaps you need something that looks more like: some_value = some_function_of( some_value ) or some_function_of ( some_value ) if some_value: host = some_function_of( some_value ) else: host = some_value or even: try: host = some_function_of( some_function_of( some_value ) or some_function_of( some_value ) ) except some_error_type [ or some_error_type .... ]: host = some_value -- Denis McMahon, denismfmcmahon at gmail.com From denismfmcmahon at gmail.com Thu Sep 26 10:38:43 2013 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Thu, 26 Sep 2013 14:38:43 +0000 (UTC) Subject: Handling 3 operands in an expression without raising an exception References: Message-ID: On Thu, 26 Sep 2013 12:56:19 +0300, ????? wrote: > Its logic is simple and straightforward but too many lines: There is no "too many lines." > this is much better in my opinion and straighforward also and more clear > to read ... it doens't work though: This is just a stupid attitude for a coder to have. -- Denis McMahon, denismfmcmahon at gmail.com From gamathonhr at gmail.com Thu Sep 26 05:27:19 2013 From: gamathonhr at gmail.com (Hacker Rank) Date: Thu, 26 Sep 2013 02:27:19 -0700 (PDT) Subject: Gamathon By HackerRank Message-ID: <296a97ac-58a2-4353-99cf-360373390f6d@googlegroups.com> This is HackerRank's second Gamathon. Every month, participants get to code a bot for a new game and get to compete against other bots! The winner takes the title of being the ultimate game programmer. Are you ready for the clash? For more details checkout: https://www.hackerrank.com/contests From wwang at capquest.co.uk Thu Sep 26 05:38:07 2013 From: wwang at capquest.co.uk (Wenlong Wang) Date: Thu, 26 Sep 2013 10:38:07 +0100 Subject: Problem when installing Boost.Python Message-ID: <8DA74782FAF6D849841E502314978B79D3974F@CQFLMAIL01.fleet.dns> Hi, All I'm not sure if am asking in the right place, but since this is Python related, I'd like to try it out. My setup is Windows7 64-bit, Python 2.7 64bit, Boost 1.54, Visual Studio 2012 Express Version 64bit. I am a beginner of Python, and am trying to bridge Python and C++. Thus I download the Boost library. I followed the instruction here: http://www.boost.org/doc/libs/1_54_0/more/getting_started/windows.html And successfully installed the Basic Boost. Then I found that Boost.Python requires a separately installation, according to another instruction here: http://www.boost.org/doc/libs/1_54_0/libs/python/doc/building.html I am stuck at step 3.1.4 where the instruction says to run a example: 4. Invoke bjam. Replace the "stage" argument from the example invocation from section 5 of the Getting Started Guide with "test," to build all the test targets. Also add the argument "--verbose-test" to see the output generated by the tests when they are run. On Windows, your bjam invocation might look something like: C:\boost_1_34_0\...\quickstart> bjam toolset=msvc --verbose-test test When I input the command line above, I have 135 unresolved external errors! One of them is like follows: exec.obj : error LNK2019: unresolved external symbol __imp__PyEval_GetGlobals referenced in function "class boost::python::api::object __cdecl boost::python::eval(class boost::python::str,class boost::python::api::object, class boost::python::api::object)"(?eval at python@boost@@YA?AVobject at api@12 at Vstr @12 at V3412@1 at Z) ..\..\..\..\bin.v2\libs\python\build\msvc-11.0\debug\boost_python-vc110- gd-1_54.dll I know this is more C++, however, I guess someone in this mailing list may have experienced with Boost.Python. My apologies if this mail bothers you. Can anyone help me to work around this? Thank you! Regards Long ? Wenlong Wang Risk Analyst, Capquest Group Ltd Email: wwang at capquest.co.uk Fleet 27, Rye Close, Fleet, GU51 2QQ. Website: http://www.capquest.co.uk/ ? This e-mail is intended solely for the addressee, is strictly confidential and may also be legally privileged. If you are not the addressee please do not read, print, re-transmit, store or act in reliance on it or any attachments. Instead, please email it back to the sender and then immediately permanently delete it. E-mail communications cannot be guaranteed to be secure or error free, as information could be intercepted, corrupted, amended, lost, destroyed, arrive late or incomplete, or contain viruses. We do not accept liability for any such matters or their consequences. Anyone who communicates with us by e-mail is taken to accept the risks in doing so. Opinions, conclusions and other information in this e-mail and any attachments are solely those of the author and do not represent those of Capquest Group Limited or any of its subsidiaries unless otherwise stated. Capquest Group Limited (registered number 4936030), Capquest Debt Recovery Limited (registered number 3772278), Capquest Investments Limited (registered number 5245825), Capquest Asset Management Limited (registered number 5245829) and Capquest Mortgage Servicing Limited (registered number 05821008) are all limited companies registered in England and Wales with their registered offices at Fleet 27, Rye Close, Fleet, Hampshire, GU51 2QQ. Each company is a separate and independent legal entity. None of the companies have any liability for each other's acts or omissions. Group VAT registration number 844281719. Members of the Capquest group are regulated under the Consumer Credit Act 1974 and are members of the Credit Services Association. This communication is from the company named in the sender's details above.? -------------- next part -------------- An HTML attachment was scrubbed... URL: From thebalancepro at gmail.com Thu Sep 26 10:39:30 2013 From: thebalancepro at gmail.com (Nick Mellor) Date: Thu, 26 Sep 2013 07:39:30 -0700 (PDT) Subject: Proposal: [... for ... while cond(x)] In-Reply-To: <1155070666.951023.161280@b28g2000cwb.googlegroups.com> References: <1154879331.903490.106020@m73g2000cwd.googlegroups.com> <1155064682.499991.246170@h48g2000cwc.googlegroups.com> <1155070666.951023.161280@b28g2000cwb.googlegroups.com> Message-ID: <99048467-e7eb-461a-aa9b-e30cf5f6f1c7@googlegroups.com> Hi all, It might be a risk that we create some hairy or subtle semantics, but perhaps this idea has legs. The 'pythonic' syntax is very attractive. # skip the silence at the start data = (amp for amp in signal from abs(amp) > 0.05) # drop files that are less than 600 bytes # (already sorted into ascending order of size) files = (file for file in filelist from os.stat(file).st_size > 600) # Analyse bunch of log lines up to a certain timestamp cutoff = datetime.datetime.now() - datetime.timedelta(hours=1) checklogs = (entry for entry in log while entry.timestamp <= cutoff) In use it feels along the same lines as else: clauses in try/finally and for loops, both of which I like-- it seems natural in Python, keeps the meaning clear and consistent, avoids complicated, iterative, inexpressive code. Terry Reedy wrote: > You're right. The syntax is ambiguous. I agree it's not a good idea, now. :) When while, if and from are made mutually exclusive, not mixed, on a comprehension clause, it looks to me like the ambiguity disappears: > x for x in xs while cond(x) if blah(x) not legal Python-- if and while are mutually exclusive on the same comprehension clause. On the one hand it's like writing x for x in xs if f(x) < 10 if g(x) > 100, the illegality of which no-one is complaining about. Just write: x for x in xs while cond(x) and cond2(x) or x for x in xs if cond(x) and cond2(x) If there is a need to filter using if as well as while, then use two comprehensions: intermediate = [x for x in xs while cond(x)] final = [x for x in intermediate if cond2(x)] or the same comprehension applied to itself: y for y in x for x in xs if cond(x) while cond2(y) The if and the while operation *should* be kept separate-- they're different stages of processing the data. > > x*y for x in xs while cond(x) for y in ys if cond(y) legal Python-- the 'if cond(y)' unambiguously refers to the inner comprehension. > x for x in xs if blah(x) while cond(x) not legal Python-- if and while are mutually exclusive in the same comprehension clause. The objection to "while" as an abbreviation: > e(x) for x in xs if cond(x) > > is an abbreviation of > > for x in xs: > if cond(x) > yield e(x) > > and similarly with more for and if clauses, > whereas the analogous expansion of your proposal > > for x in xs: > while cond(x): > yield e(x) > > is an infinite loop and not at all what you mean. That's because while is being used here with a different semantic to the while loop. It actually means: for x in xs: if not cond(x): break yield e(x) and for 'from': emit = False for x in xs: if not emit: if cond(x): emit = True else: yield e(x) Cheers, Nick From thebalancepro at gmail.com Thu Sep 26 10:50:36 2013 From: thebalancepro at gmail.com (Nick Mellor) Date: Thu, 26 Sep 2013 07:50:36 -0700 (PDT) Subject: Proposal: [... for ... while cond(x)] In-Reply-To: <99048467-e7eb-461a-aa9b-e30cf5f6f1c7@googlegroups.com> References: <1154879331.903490.106020@m73g2000cwd.googlegroups.com> <1155064682.499991.246170@h48g2000cwc.googlegroups.com> <1155070666.951023.161280@b28g2000cwb.googlegroups.com> <99048467-e7eb-461a-aa9b-e30cf5f6f1c7@googlegroups.com> Message-ID: On Friday, 27 September 2013 00:39:30 UTC+10, Nick Mellor wrote: [snip] > for x in xs: > if not emit: > if cond(x): > emit = True > else: > yield e(x) > Oops! for x in xs: if not emit: if cond(x): emit = True yield e(x) else: yield e(x) From Bill at bill.com Thu Sep 26 11:13:35 2013 From: Bill at bill.com (Bill) Date: Thu, 26 Sep 2013 16:13:35 +0100 Subject: Download all youtube favorites with youtube-dl script Message-ID: I have been using the script youtube-dl http://rg3.github.io/youtube-dl/ And I was wondering if there is a way to download all of a user's favorites or uploads. The script has a functionality to download all videos in a txt file. So if there is a way using the youtube API or JSON (none of which I am familiar with) to bring up a list of all these videos then it'd be a simple case putting these urls into a file. The problem is youtube displays favorites or user uploads in pages or infinite scroll. So it is difficult to access them by the BeautifulSoup module. What do you suggest? From joel.goldstick at gmail.com Thu Sep 26 11:21:12 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Thu, 26 Sep 2013 11:21:12 -0400 Subject: Download all youtube favorites with youtube-dl script In-Reply-To: References: Message-ID: On Thu, Sep 26, 2013 at 11:13 AM, Bill wrote: > I have been using the script youtube-dl http://rg3.github.io/youtube-**dl/ > > And I was wondering if there is a way to download all of a user's > favorites or uploads. > > The script has a functionality to download all videos in a txt file. So if > there is a way using the youtube API or JSON (none of which I am familiar > with) to bring up a list of all these videos then it'd be a simple case > putting these urls into a file. > > The problem is youtube displays favorites or user uploads in pages or > infinite scroll. So it is difficult to access them by the BeautifulSoup > module. > > > What do you suggest? > -- > https://mail.python.org/**mailman/listinfo/python-list > Have you looked at the youtube API? That would be better than screen scraping. https://developers.google.com/youtube/getting_started -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From phihag at phihag.de Thu Sep 26 11:35:02 2013 From: phihag at phihag.de (Philipp Hagemeister) Date: Thu, 26 Sep 2013 17:35:02 +0200 Subject: Download all youtube favorites with youtube-dl script In-Reply-To: References: Message-ID: <52445426.70109@phihag.de> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512 Hi Bill, the best way to ask for features or file bugs on youtube-dl is asking us at http://github.com/rg3/youtube-dl/issues . Luckily, I this list from time to time ;) Simply use youtube-dl --username user at gmail.com --password secret :ytfav Best, Philipp On 09/26/2013 05:13 PM, Bill wrote: > I have been using the script youtube-dl > http://rg3.github.io/youtube-dl/ > > And I was wondering if there is a way to download all of a user's > favorites or uploads. > > The script has a functionality to download all videos in a txt > file. So if there is a way using the youtube API or JSON (none of > which I am familiar with) to bring up a list of all these videos > then it'd be a simple case putting these urls into a file. > > The problem is youtube displays favorites or user uploads in pages > or infinite scroll. So it is difficult to access them by the > BeautifulSoup module. > > > What do you suggest? -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.14 (GNU/Linux) iQIcBAEBCgAGBQJSRFQmAAoJENtLVMukgmoYaz0P/ifoPqcx4dpShXyigwGxzhsa ht8sjIP8n3bNJ+J7Jvx0uM6Sv/Hu/U1CC09G1pT9nquHDYYvmko+MoBkXbc8JmlC R0qPhX0I2xGH9G1EL+83J4zzte3K7p5ErLY1V1S9cWuBKot16eKtrxhIgWxTMfE1 l93az4Uz4YLzUPYEXSO7pNX9cvxyrEjsqSJE3Jftn5ZqbUO46M+7gMKG2g46C/W4 IQtg2v9cHE3xKV5c+wCFjjIHtOGg+leOTMFdiD6oIa/uNfV/3tzpiyQ1e2QgyrvU UK4zz3TxqxWswDTrxRdc7fFNAGoNSrxU2hwyvjc/CGehORv7ktBjJJbtt3PfvHsi nov+OEIToDFTO1nCzQ39qQP0Ibl0LpNbvJGWyJqubFsZd0uiU1EwONXFchNwHeil Yce4DT8Tzf4zv6y3YNJCz1RCM1G308vQav539w6D7vfIUc5F28gnWKkd5NIcCpyu URVWp0HxV7d+kCekbxhnd+Ah/XvsrHhkI3cxOHvc1QjGwToRWawJQT0LD72E6PqW MmnOUTZhrxebyAx1HEt45l19fuW/TfwCWWzAtRscr8uFLFf0/Hwm41tSo8FjxqK2 OVZAckmVYIKP0F+u6hcSg/INl6rs6R+Co4/S8aFdKh2N16wmwQ7hevoTIpXIFwwK hkpwAUdlQxIWzSe8uJMV =nRz7 -----END PGP SIGNATURE----- From bill at bill.com Thu Sep 26 14:14:33 2013 From: bill at bill.com (Bill) Date: Thu, 26 Sep 2013 19:14:33 +0100 Subject: Download all youtube favorites with youtube-dl script In-Reply-To: References: Message-ID: Joel Goldstick wrote: > > > > On Thu, Sep 26, 2013 at 11:13 AM, Bill > wrote: > > I have been using the script youtube-dl > http://rg3.github.io/youtube-__dl/ > > And I was wondering if there is a way to download all of a user's > favorites or uploads. > > The script has a functionality to download all videos in a txt file. > So if there is a way using the youtube API or JSON (none of which I > am familiar with) to bring up a list of all these videos then it'd > be a simple case putting these urls into a file. > > The problem is youtube displays favorites or user uploads in pages > or infinite scroll. So it is difficult to access them by the > BeautifulSoup module. > > > What do you suggest? > -- > https://mail.python.org/__mailman/listinfo/python-list > > > > Have you looked at the youtube API? That would be better than screen > scraping. https://developers.google.com/youtube/getting_started > > > -- > Joel Goldstick > http://joelgoldstick.com I remember looking at this a while ago. These are the relevant sections of the API: https://developers.google.com/youtube/2.0/developers_guide_protocol?hl=en#User_Uploaded_Videos https://developers.google.com/youtube/2.0/developers_guide_protocol?hl=en#Favorite_Videos The problem with the API is that with both of these, it only brings up 25 videos e.g. https://gdata.youtube.com/feeds/api/users/scooby1961/uploads Unless I'm missing something? There must be a way to bring up all of them on one page right? Or at least cycle through the rest of them. Same problem with favorties: https://gdata.youtube.com/feeds/api/users/adambuxton/favorites/ From python at mrabarnett.plus.com Thu Sep 26 14:33:35 2013 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 26 Sep 2013 19:33:35 +0100 Subject: Download all youtube favorites with youtube-dl script In-Reply-To: References: Message-ID: <52447DFF.9030405@mrabarnett.plus.com> On 26/09/2013 19:14, Bill wrote: > Joel Goldstick wrote: >> >> >> >> On Thu, Sep 26, 2013 at 11:13 AM, Bill > > wrote: >> >> I have been using the script youtube-dl >> http://rg3.github.io/youtube-__dl/ >> >> And I was wondering if there is a way to download all of a user's >> favorites or uploads. >> >> The script has a functionality to download all videos in a txt file. >> So if there is a way using the youtube API or JSON (none of which I >> am familiar with) to bring up a list of all these videos then it'd >> be a simple case putting these urls into a file. >> >> The problem is youtube displays favorites or user uploads in pages >> or infinite scroll. So it is difficult to access them by the >> BeautifulSoup module. >> >> >> What do you suggest? >> -- >> https://mail.python.org/__mailman/listinfo/python-list >> >> >> >> Have you looked at the youtube API? That would be better than screen >> scraping. https://developers.google.com/youtube/getting_started >> >> >> -- >> Joel Goldstick >> http://joelgoldstick.com > > I remember looking at this a while ago. These are the relevant sections > of the API: > > https://developers.google.com/youtube/2.0/developers_guide_protocol?hl=en#User_Uploaded_Videos > > https://developers.google.com/youtube/2.0/developers_guide_protocol?hl=en#Favorite_Videos > > The problem with the API is that with both of these, it only brings up > 25 videos e.g. https://gdata.youtube.com/feeds/api/users/scooby1961/uploads > > Unless I'm missing something? There must be a way to bring up all of > them on one page right? Or at least cycle through the rest of them. > You _are_ missing something. That section of "#User_Uploaded_Videos" mentions the parameters "start-index" and "max-results". > Same problem with favorties: > https://gdata.youtube.com/feeds/api/users/adambuxton/favorites/ > From hallo at thomaskandler.net Fri Sep 27 03:27:55 2013 From: hallo at thomaskandler.net (Thomas Kandler) Date: Fri, 27 Sep 2013 09:27:55 +0200 Subject: Download all youtube favorites with youtube-dl script In-Reply-To: References: Message-ID: On 26.09.2013 17:13, Bill wrote: > I have been using the script youtube-dl http://rg3.github.io/youtube-dl/ > > And I was wondering if there is a way to download all of a user's > favorites or uploads. > > The script has a functionality to download all videos in a txt file. So > if there is a way using the youtube API or JSON (none of which I am > familiar with) to bring up a list of all these videos then it'd be a > simple case putting these urls into a file. > > The problem is youtube displays favorites or user uploads in pages or > infinite scroll. So it is difficult to access them by the BeautifulSoup > module. > > > What do you suggest? Regarding the uploads: most profiles do have something called 'Popular Uploads' or 'Recent Uploads'. Hover with the mouse over the link, a 'play'-Button appears, click it, copy the URL (should have a &list parameter), paste the URL in youtube-dl (or a txt-file) and it will fetch all videos. I am not sure if this works for favorites, too, but that's the way I do it. From bill at bill.com Fri Sep 27 15:50:30 2013 From: bill at bill.com (Bill) Date: Fri, 27 Sep 2013 20:50:30 +0100 Subject: Download all youtube favorites with youtube-dl script In-Reply-To: References: Message-ID: Thomas Kandler wrote: > On 26.09.2013 17:13, Bill wrote: >> I have been using the script youtube-dl http://rg3.github.io/youtube-dl/ >> >> And I was wondering if there is a way to download all of a user's >> favorites or uploads. >> >> The script has a functionality to download all videos in a txt file. So >> if there is a way using the youtube API or JSON (none of which I am >> familiar with) to bring up a list of all these videos then it'd be a >> simple case putting these urls into a file. >> >> The problem is youtube displays favorites or user uploads in pages or >> infinite scroll. So it is difficult to access them by the BeautifulSoup >> module. >> >> >> What do you suggest? > > Regarding the uploads: most profiles do have something called 'Popular > Uploads' or 'Recent Uploads'. Hover with the mouse over the link, a > 'play'-Button appears, click it, copy the URL (should have a &list > parameter), paste the URL in youtube-dl (or a txt-file) and it will > fetch all videos. > > I am not sure if this works for favorites, too, but that's the way I do it. > Hi. A screenshot would help me locate it. Cheers From hallo at thomaskandler.net Fri Sep 27 16:19:45 2013 From: hallo at thomaskandler.net (Thomas Kandler) Date: Fri, 27 Sep 2013 22:19:45 +0200 Subject: Download all youtube favorites with youtube-dl script In-Reply-To: References: Message-ID: On 27.09.2013 21:50, Bill wrote: > Hi. > > A screenshot would help me locate it. > > Cheers Sure. http://i.imgur.com/LvrNZYO.png I don't thing *every* profile has this, but as I said, I use youtube-dl quite often this way. Best From g.rodola at gmail.com Thu Sep 26 11:39:56 2013 From: g.rodola at gmail.com (Giampaolo Rodola') Date: Thu, 26 Sep 2013 17:39:56 +0200 Subject: Upload Windows binaries on pypi from Linux Message-ID: I have a Python extension module (psutil) written in C which I compile for different Python versions (from 2.4 to 3.3) and want to upload them on pypi. The Windows machine is not connected to internet so after I generate the Windows binaries (via setup.py bdist_wininst) I move the .exe files from Windows to Linux. From there I want to upload all the *.exe files on pypi. Apparently I can automatically do this only from Windows via "setup.py upload bdist_wininst" but as I said I have no internet connection on that box. Is there a way to tell setup.py to upload those *.exe file on pypi from Linux or some tool which can do that via HTTP POST or something? Thanks in advance, --- Giampaolo https://code.google.com/p/pyftpdlib/ https://code.google.com/p/psutil/ https://code.google.com/p/pysendfile/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From dyeringamsa at gmail.com Thu Sep 26 15:13:51 2013 From: dyeringamsa at gmail.com (D.YAN ESCOLAR RAMBAL) Date: Thu, 26 Sep 2013 14:13:51 -0500 Subject: work develope matrix of difusive concentration Message-ID: Good morning all thanks for your help. Now I`ve a question, if I need create a matrix, method of thomas, ghost nodes, etc.. for developed one aplicative for the ecuation of difusion in 1d, 2d, 3d, 4d. It`s better use phyton 3.3 or 2.7?, if the answer is phyton 3.3 that interpreter is similar to aptana o better, for start, and which, libraries are necesary for this, I think I need numpy, numba, math, mathexpretion, matiplot, but I don`t know which is the library similar to matlab. All best for you, nice day or nigth and nice week -- *Gracias, cordialmente, * * * * * *ING. YANETH ESCOLAR RAMBAL* *HAFI Engineering & Consulting GmbH* *CEL: + 57 3166257245* *TEL: + 57 (1) 6508308* *TEL: ++43 5522 77924 0* *Fax: ++43 5522 74938* *Dir : Cll 72f no. 113-21 Torre 5 - 604 Bogot? Colombia* * Muehletorplatz 4-6, A-6800 Feldkirch, Austria* *www.hafi.cc/en/environ_en.htm* -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Thu Sep 26 20:40:13 2013 From: rustompmody at gmail.com (rusi) Date: Thu, 26 Sep 2013 17:40:13 -0700 (PDT) Subject: work develope matrix of difusive concentration In-Reply-To: References: Message-ID: <54e89e61-e9a3-4a78-95d7-60a83371f25f@googlegroups.com> On Friday, September 27, 2013 12:43:51 AM UTC+5:30, D.YAN ESCOLAR RAMBAL wrote: > Good morning all > > thanks for your help. Now I`ve a question, if I need create a matrix, method > of thomas, ghost nodes, etc.. for developed one aplicative for the ecuation > of difusion in 1d, 2d, 3d, 4d. It`s better use phyton 3.3 or 2.7?, if the > answer is phyton 3.3 that interpreter is similar to aptana o better, for > start, and which, libraries are necesary for this, ?I think I need numpy, > numba, math, mathexpretion, matiplot, but ?I don`t know which is the library > similar to matlab. Sage?? http://en.wikipedia.org/wiki/Sage_%28mathematics_software%29 [I dont know this area myself] From kandalkar.a87 at gmail.com Fri Sep 27 02:55:16 2013 From: kandalkar.a87 at gmail.com (Anup Kandalkar) Date: Thu, 26 Sep 2013 23:55:16 -0700 (PDT) Subject: Method not found: 'ServiceSettingSave' in Suds package Message-ID: <21ab0bd0-adbc-4682-95f3-0152b8e5c558@googlegroups.com> I am trying to create service for the url: wsdl_url = https://avatax.avalara.net/Account/Accountsvc.wsdl But some error is coming: svc = suds.client.Client(url=wsdl_url) File "/usr/lib/python2.7/dist-packages/suds/client.py", line 114, in __init__ self.wsdl = reader.open(url) File "/usr/lib/python2.7/dist-packages/suds/reader.py", line 152, in open d = self.fn(url, self.options) File "/usr/lib/python2.7/dist-packages/suds/wsdl.py", line 158, in __init__ self.resolve() File "/usr/lib/python2.7/dist-packages/suds/wsdl.py", line 207, in resolve c.resolve(self) File "/usr/lib/python2.7/dist-packages/suds/wsdl.py", line 660, in resolve self.resolvesoapbody(definitions, op) File "/usr/lib/python2.7/dist-packages/suds/wsdl.py", line 686, in resolvesoapbody ptop = self.type.operation(op.name) File "/usr/lib/python2.7/dist-packages/suds/wsdl.py", line 525, in operation raise MethodNotFound(name) MethodNotFound: Method not found: 'ServiceSettingSave' please help me to solve this issues, for this need to update python packages or any other way. Thanks From dieter at handshake.de Sat Sep 28 01:54:21 2013 From: dieter at handshake.de (dieter) Date: Sat, 28 Sep 2013 07:54:21 +0200 Subject: Method not found: 'ServiceSettingSave' in Suds package References: <21ab0bd0-adbc-4682-95f3-0152b8e5c558@googlegroups.com> Message-ID: <871u49lcdu.fsf@handshake.de> Anup Kandalkar writes: > I am trying to create service for the url: > > wsdl_url = https://avatax.avalara.net/Account/Accountsvc.wsdl > > But some error is coming: > > svc = suds.client.Client(url=wsdl_url) > File "/usr/lib/python2.7/dist-packages/suds/client.py", line 114, in __init__ > self.wsdl = reader.open(url) > File "/usr/lib/python2.7/dist-packages/suds/reader.py", line 152, in open > d = self.fn(url, self.options) > File "/usr/lib/python2.7/dist-packages/suds/wsdl.py", line 158, in __init__ > self.resolve() > File "/usr/lib/python2.7/dist-packages/suds/wsdl.py", line 207, in resolve > c.resolve(self) > File "/usr/lib/python2.7/dist-packages/suds/wsdl.py", line 660, in resolve > self.resolvesoapbody(definitions, op) > File "/usr/lib/python2.7/dist-packages/suds/wsdl.py", line 686, in resolvesoapbody > ptop = self.type.operation(op.name) > File "/usr/lib/python2.7/dist-packages/suds/wsdl.py", line 525, in operation > raise MethodNotFound(name) > MethodNotFound: Method not found: 'ServiceSettingSave' This looks to be a bug in the "wsdl". Somewhere, it refers to "ServiceSettingSave" but there is no definition for it. To analyse, I would download the WSDL description (recursively, if necessary to get the full description) and search there for "ServiceSettingSave". From markotaht at gmail.com Fri Sep 27 06:24:28 2013 From: markotaht at gmail.com (markotaht at gmail.com) Date: Fri, 27 Sep 2013 03:24:28 -0700 (PDT) Subject: card dealer Message-ID: <0617088e-5aa3-4c5d-b660-22040ee858a1@googlegroups.com> from random import * from math import floor kaarte_alles = 52 kaart_t?mmatud = [False for i in range(52)] mast = ["?rtu", "ruutu", "poti", "risti"] aste = ["?ss", "kaks", "kolm", "neli","viis", "kuus", \ "seitse", "kaheksa", "?heksa", "k?mme", "soldat",\ "emand", "kuningas"] def t?mba_kaart(): global kaarte_alles if kaarte_alles == 0: print("Segan pakki") kaarte_alles = 52 for i in range(52): kaart_t?mmatud[i] = False kaarte_alles -= 1 n = random(kaarte_alles) kaart = vali_j?rgmine_vaba(n) m = kaart % 13 a = kaart / 13 print(mast[int(a)] + " " + aste[int(m)]) def vali_j?rgmine_vaba(n): i = -1 while(n > 0): n -= 1 i = i + 1 while kaart_t?mmatud[i]: i = i + 1 kaart_t?mmatud[i] = True return i def random(n): return randint(0, n) while True: n = int(input("Mitu kaarti t?mmata(0 et v?ljuda): ")) if(n==0): break for i in range(n): t?mba_kaart() HI im trying to make a card dealer, but this code doesent work correctly. It deasl cards, but the cards to repeat. when i type in 52 ten i might get 3 the same cards. This is a translation from my c++ code. In c++ it works correctly. From davea at davea.name Fri Sep 27 07:26:21 2013 From: davea at davea.name (Dave Angel) Date: Fri, 27 Sep 2013 11:26:21 +0000 (UTC) Subject: card dealer References: <0617088e-5aa3-4c5d-b660-22040ee858a1@googlegroups.com> Message-ID: On 27/9/2013 06:24, markotaht at gmail.com wrote: > from random import * > from math import floor > > > kaarte_alles = 52 > kaart_t?mmatud = [False for i in range(52)] > > > mast = ["?rtu", "ruutu", "poti", "risti"] > aste = ["?ss", "kaks", "kolm", "neli","viis", "kuus", \ > "seitse", "kaheksa", "?heksa", "k?mme", "soldat",\ > "emand", "kuningas"] > > def t?mba_kaart(): > global kaarte_alles > if kaarte_alles == 0: > print("Segan pakki") > kaarte_alles = 52 > for i in range(52): > kaart_t?mmatud[i] = False > kaarte_alles -= 1 > n = random(kaarte_alles) > kaart = vali_j?rgmine_vaba(n) > m = kaart % 13 > a = kaart / 13 > print(mast[int(a)] + " " + aste[int(m)]) > > def vali_j?rgmine_vaba(n): > i = -1 > > while(n > 0): > n -= 1 > i = i + 1 > while kaart_t?mmatud[i]: > i = i + 1 > kaart_t?mmatud[i] = True > return i > > def random(n): > return randint(0, n) > > while True: > n = int(input("Mitu kaarti t?mmata(0 et v?ljuda): ")) > if(n==0): > break > > for i in range(n): > t?mba_kaart() > > > HI im trying to make a card dealer, but this code doesent work correctly. It deasl cards, but the cards to repeat. when i type in 52 ten i might get 3 the same cards. This is a translation from my c++ code. In c++ it works correctly. If you had created your global list containing list(range(52)), then you could do nearly your entire program with one call to random.sample. http://docs.python.org/3.3/library/random.html#random.sample -- DaveA From davea at davea.name Fri Sep 27 08:08:33 2013 From: davea at davea.name (Dave Angel) Date: Fri, 27 Sep 2013 12:08:33 +0000 (UTC) Subject: card dealer References: <0617088e-5aa3-4c5d-b660-22040ee858a1@googlegroups.com> Message-ID: On 27/9/2013 07:26, Dave Angel wrote: > On 27/9/2013 06:24, markotaht at gmail.com wrote: > I sent the previous message long before I had finished. > > If you had created your global list containing list(range(52)), then you > could do nearly your entire program with one call to random.sample. > > http://docs.python.org/3.3/library/random.html#random.sample > What is your goal? Are you trying to make the logic match your C++ code? Are you just trying to solve the problem, or are you trying to figure out where the bug is in your present code. If it were my problem, I'd build a deck as a list, shuffle it with random.shuffle(), then deal the cards out in order. I might also use list.pop() to take items off, so I wouldn't need any separate counter. If i were trying to figure out why the existing code fails, I'd start with an assert right before setting the flags. assert(not kaart_t?mmatud[i]) kaart_t?mmatud[i] = True Once you do that, and it fires, you know explicitly that you have a bug. i believe the code may be fixed by changing the function vali_j?rgmine_vaba() to begin as follows: def vali_j?rgmine_vaba(n): i = 0 while kaart_t?mmatud[i]: i = i + 1 while(n > 0): But I would point out that this is a horribly unreadable way to do it. It's possibly appropriate for C, which is mostly unreadable anyway. But even there, there are much better approaches. For example, i recall writing a shuffle function in C decades ago, which took an array of (52) unique items and put them in random order. For an array of size 52, it did it with exactly 51 swaps, without any searching like you're doing in the above function. -- daveA From denismfmcmahon at gmail.com Fri Sep 27 12:10:47 2013 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Fri, 27 Sep 2013 16:10:47 +0000 (UTC) Subject: card dealer References: <0617088e-5aa3-4c5d-b660-22040ee858a1@googlegroups.com> Message-ID: On Fri, 27 Sep 2013 12:08:33 +0000, Dave Angel wrote: > i recall > writing a shuffle function in C decades ago, which took an array of (52) > unique items and put them in random order. Whenever I tried to write shuffles I came up against a fairly fundamental limit: 52! > prng states Granted prngs seem to be better on the importing entropy from elsewhere front these days. -- Denis McMahon, denismfmcmahon at gmail.com From davea at davea.name Fri Sep 27 17:00:52 2013 From: davea at davea.name (Dave Angel) Date: Fri, 27 Sep 2013 21:00:52 +0000 (UTC) Subject: card dealer References: <0617088e-5aa3-4c5d-b660-22040ee858a1@googlegroups.com> Message-ID: On 27/9/2013 12:10, Denis McMahon wrote: > On Fri, 27 Sep 2013 12:08:33 +0000, Dave Angel wrote: > >> i recall >> writing a shuffle function in C decades ago, which took an array of (52) >> unique items and put them in random order. > > Whenever I tried to write shuffles I came up against a fairly fundamental > limit: > > 52! > prng states > > Granted prngs seem to be better on the importing entropy from elsewhere > front these days. > in 1978, I implemented a random number generator that the OS sequenced through between scheduling processes, so that any individual process would be relatively safe from that phenomenon. Of course I was limited to the precision of the math package - 10**13 -- DaveA From ned at nedbatchelder.com Fri Sep 27 17:40:46 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 27 Sep 2013 17:40:46 -0400 Subject: card dealer In-Reply-To: References: <0617088e-5aa3-4c5d-b660-22040ee858a1@googlegroups.com> Message-ID: <5245FB5E.7070107@nedbatchelder.com> On 9/27/13 12:10 PM, Denis McMahon wrote: > On Fri, 27 Sep 2013 12:08:33 +0000, Dave Angel wrote: > >> i recall >> writing a shuffle function in C decades ago, which took an array of (52) >> unique items and put them in random order. > Whenever I tried to write shuffles I came up against a fairly fundamental > limit: > > 52! > prng states > > Granted prngs seem to be better on the importing entropy from elsewhere > front these days. > Python's PRNG holds plenty of state to handle card shuffling. Python's random number generator has a period of 2**19337-1, so it has that many states. That is much larger than 52!, about 10**5933 times larger. (Unless I've botched the math...) The other variable is how many states the initial seed can have. If os.urandom is available, then it seeds with 16 bytes of OS-supplied randomness. But 52! is about 2**226, so the 128 bits of seed isn't enough to make all shuffles possible. You could seed a Random yourself with more bits if you really wanted to. --Ned. From steve+comp.lang.python at pearwood.info Sat Sep 28 02:01:34 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Sep 2013 06:01:34 GMT Subject: card dealer References: <0617088e-5aa3-4c5d-b660-22040ee858a1@googlegroups.com> Message-ID: <524670be$0$30000$c3e8da3$5496439d@news.astraweb.com> On Fri, 27 Sep 2013 17:40:46 -0400, Ned Batchelder wrote: > On 9/27/13 12:10 PM, Denis McMahon wrote: >> On Fri, 27 Sep 2013 12:08:33 +0000, Dave Angel wrote: >> >>> i recall >>> writing a shuffle function in C decades ago, which took an array of >>> (52) unique items and put them in random order. >> Whenever I tried to write shuffles I came up against a fairly >> fundamental limit: >> >> 52! > prng states >> >> Granted prngs seem to be better on the importing entropy from elsewhere >> front these days. >> >> > Python's PRNG holds plenty of state to handle card shuffling. Python's > random number generator has a period of 2**19337-1, so it has that many > states. That is much larger than 52!, about 10**5933 times larger. > (Unless I've botched the math...) There's a warning about that in the docs: http://docs.python.org/3/library/random.html#random.shuffle [quote] Note that for even rather small len(x), the total number of permutations of x is larger than the period of most random number generators; this implies that most permutations of a long sequence can never be generated. [end quote] If I've done that maths right, it turns out that 2025 is the largest number of items that a list can have for Python's default PRNG to generate every possible shuffle. But does it really matter? For most purposes, I'd say No. Even if you generated one trillion shuffles per second, you would have to keep shuffling for more than a trillion years before repeating yourself. To be pedantic: a *lot* more than a trillion years. Approximately 10**5789 trillion years. That's about a: trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion ... and so on for 57 more lines ... years. So in practice it's not really relevant that some shuffles won't be generated. They'll be randomly distributed throughout the space of all possible shuffles, which is so large that you really won't notice the missing ones. -- Steven From ned at nedbatchelder.com Sat Sep 28 06:31:25 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 28 Sep 2013 06:31:25 -0400 Subject: card dealer In-Reply-To: <524670be$0$30000$c3e8da3$5496439d@news.astraweb.com> References: <0617088e-5aa3-4c5d-b660-22040ee858a1@googlegroups.com> <524670be$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5246AFFD.9090401@nedbatchelder.com> On 9/28/13 2:01 AM, Steven D'Aprano wrote: > On Fri, 27 Sep 2013 17:40:46 -0400, Ned Batchelder wrote: > >> On 9/27/13 12:10 PM, Denis McMahon wrote: >>> On Fri, 27 Sep 2013 12:08:33 +0000, Dave Angel wrote: >>> >>>> i recall >>>> writing a shuffle function in C decades ago, which took an array of >>>> (52) unique items and put them in random order. >>> Whenever I tried to write shuffles I came up against a fairly >>> fundamental limit: >>> >>> 52! > prng states >>> >>> Granted prngs seem to be better on the importing entropy from elsewhere >>> front these days. >>> >>> >> Python's PRNG holds plenty of state to handle card shuffling. Python's >> random number generator has a period of 2**19337-1, so it has that many >> states. That is much larger than 52!, about 10**5933 times larger. >> (Unless I've botched the math...) > There's a warning about that in the docs: > > http://docs.python.org/3/library/random.html#random.shuffle > > [quote] > Note that for even rather small len(x), the total number of permutations > of x is larger than the period of most random number generators; this > implies that most permutations of a long sequence can never be generated. > [end quote] > > If I've done that maths right, it turns out that 2025 is the largest > number of items that a list can have for Python's default PRNG to > generate every possible shuffle. But does it really matter? For most > purposes, I'd say No. Even if you generated one trillion shuffles per > second, you would have to keep shuffling for more than a trillion years > before repeating yourself. > > To be pedantic: a *lot* more than a trillion years. Approximately > 10**5789 trillion years. That's about a: > > trillion trillion trillion trillion trillion trillion trillion trillion > trillion trillion trillion trillion trillion trillion trillion trillion > trillion trillion trillion trillion trillion trillion trillion trillion > ... and so on for 57 more lines ... years. > > > So in practice it's not really relevant that some shuffles won't be > generated. They'll be randomly distributed throughout the space of all > possible shuffles, which is so large that you really won't notice the > missing ones. > > I've thought that way about it too: there are so many shuffles any way, it won't be a problem. But think about it like this: if you shuffle a deck of 52 cards with a default Python random object, then once you have dealt out only 28 cards, the entire rest of the deck is completely determined. That is, given the sequence of the first 28 cards, there's only one choice for how the remaining 24 will be dealt. Depending on what you need from your deck of cards, that could be a complete disaster. Is it a problem for a card game simulation? No. Is it a problem for a program that analyze correlations between the start of the deck and the end of the deck? Maybe. --Ned. From davea at davea.name Sat Sep 28 08:56:15 2013 From: davea at davea.name (Dave Angel) Date: Sat, 28 Sep 2013 12:56:15 +0000 (UTC) Subject: card dealer References: <0617088e-5aa3-4c5d-b660-22040ee858a1@googlegroups.com> <524670be$0$30000$c3e8da3$5496439d@news.astraweb.com> <5246AFFD.9090401@nedbatchelder.com> Message-ID: On 28/9/2013 06:31, Ned Batchelder wrote: > > I've thought that way about it too: there are so many shuffles any way, > it won't be a problem. But think about it like this: if you shuffle a > deck of 52 cards with a default Python random object, then once you have > dealt out only 28 cards, the entire rest of the deck is completely > determined. That is, given the sequence of the first 28 cards, there's > only one choice for how the remaining 24 will be dealt. Depending on > what you need from your deck of cards, that could be a complete disaster. > > Is it a problem for a card game simulation? No. Is it a problem for a > program that analyze correlations between the start of the deck and the > end of the deck? Maybe. > Only if there is some correlation between the random number algorithm and whatever properties you're checking between start and end of deck. And if there is, then you've just struck one of the limitations of a *pseudo* random gen. I have no idea what sheme is actually used in Python's generator, but one approach that helps avoid such troubles is to keep a pool of the "next" P random numbers (where P might be a few hundred). Then use an *independent* random number generator (which could be very simple) to select which item of the pool to use next (followed by replacement from the first). it's kind of a local-shuffle of the very long stream of numbers. Even fairly poor random number generators, if they generate close to 2**n values (for a int size of n) generally become very good when shuffled this way. -- DaveA From antoon.pardon at rece.vub.ac.be Sat Sep 28 10:49:38 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Sat, 28 Sep 2013 16:49:38 +0200 Subject: card dealer In-Reply-To: <5246AFFD.9090401@nedbatchelder.com> References: <0617088e-5aa3-4c5d-b660-22040ee858a1@googlegroups.com> <524670be$0$30000$c3e8da3$5496439d@news.astraweb.com> <5246AFFD.9090401@nedbatchelder.com> Message-ID: <5246EC82.1020300@rece.vub.ac.be> Op 28-09-13 12:31, Ned Batchelder schreef: > On 9/28/13 2:01 AM, Steven D'Aprano wrote: >> On Fri, 27 Sep 2013 17:40:46 -0400, Ned Batchelder wrote: >> >>> On 9/27/13 12:10 PM, Denis McMahon wrote: >>>> On Fri, 27 Sep 2013 12:08:33 +0000, Dave Angel wrote: >>>> >>>>> i recall >>>>> writing a shuffle function in C decades ago, which took an array of >>>>> (52) unique items and put them in random order. >>>> Whenever I tried to write shuffles I came up against a fairly >>>> fundamental limit: >>>> >>>> 52! > prng states >>>> >>>> Granted prngs seem to be better on the importing entropy from elsewhere >>>> front these days. >>>> >>>> >>> Python's PRNG holds plenty of state to handle card shuffling. Python's >>> random number generator has a period of 2**19337-1, so it has that many >>> states. That is much larger than 52!, about 10**5933 times larger. >>> (Unless I've botched the math...) >> There's a warning about that in the docs: >> >> http://docs.python.org/3/library/random.html#random.shuffle >> >> [quote] >> Note that for even rather small len(x), the total number of permutations >> of x is larger than the period of most random number generators; this >> implies that most permutations of a long sequence can never be generated. >> [end quote] >> >> If I've done that maths right, it turns out that 2025 is the largest >> number of items that a list can have for Python's default PRNG to >> generate every possible shuffle. But does it really matter? For most >> purposes, I'd say No. Even if you generated one trillion shuffles per >> second, you would have to keep shuffling for more than a trillion years >> before repeating yourself. >> >> To be pedantic: a *lot* more than a trillion years. Approximately >> 10**5789 trillion years. That's about a: >> >> trillion trillion trillion trillion trillion trillion trillion trillion >> trillion trillion trillion trillion trillion trillion trillion trillion >> trillion trillion trillion trillion trillion trillion trillion trillion >> ... and so on for 57 more lines ... years. >> >> >> So in practice it's not really relevant that some shuffles won't be >> generated. They'll be randomly distributed throughout the space of all >> possible shuffles, which is so large that you really won't notice the >> missing ones. >> >> > > I've thought that way about it too: there are so many shuffles any way, > it won't be a problem. But think about it like this: if you shuffle a > deck of 52 cards with a default Python random object, then once you have > dealt out only 28 cards, the entire rest of the deck is completely > determined. That is, given the sequence of the first 28 cards, there's > only one choice for how the remaining 24 will be dealt. Depending on > what you need from your deck of cards, that could be a complete disaster. I don't see it. Unless given those 28 cards you can actually predict those 24 other cards or at least can devise some betting strategy that will allow you to beat the odds I don't see how this could lead to a disaster. > Is it a problem for a card game simulation? No. Is it a problem for a > program that analyze correlations between the start of the deck and the > end of the deck? Maybe. Well if a program would actually find a correlation between the start of the deck and the end, that may indeed be a cause for worry. But what evidence is there for that possibility? -- Antoon Pardon From timr at probo.com Sat Sep 28 20:04:50 2013 From: timr at probo.com (Tim Roberts) Date: Sat, 28 Sep 2013 17:04:50 -0700 Subject: card dealer References: <0617088e-5aa3-4c5d-b660-22040ee858a1@googlegroups.com> <524670be$0$30000$c3e8da3$5496439d@news.astraweb.com> <5246AFFD.9090401@nedbatchelder.com> Message-ID: Antoon Pardon wrote: > >Op 28-09-13 12:31, Ned Batchelder schreef: >> >> I've thought that way about it too: there are so many shuffles any way, >> it won't be a problem. But think about it like this: if you shuffle a >> deck of 52 cards with a default Python random object, then once you have >> dealt out only 28 cards, the entire rest of the deck is completely >> determined. That is, given the sequence of the first 28 cards, there's >> only one choice for how the remaining 24 will be dealt. Depending on >> what you need from your deck of cards, that could be a complete disaster. > >I don't see it. Unless given those 28 cards you can actually predict >those 24 other cards or at least can devise some betting strategy that >will allow you to beat the odds I don't see how this could lead to a >disaster. That's exactly the problem. Because the number of permutations is limited, once you know the first 28 cards, you can uniquely identify the permutation you started with, and that's enough to get the entire sequence. Now, it's going to take a hell of a lot of memory to store that information, so I'm not sure it is a disaster in a practical sense. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From python at mrabarnett.plus.com Fri Sep 27 07:27:57 2013 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 27 Sep 2013 12:27:57 +0100 Subject: card dealer In-Reply-To: <0617088e-5aa3-4c5d-b660-22040ee858a1@googlegroups.com> References: <0617088e-5aa3-4c5d-b660-22040ee858a1@googlegroups.com> Message-ID: <52456BBD.6070206@mrabarnett.plus.com> On 27/09/2013 11:24, markotaht at gmail.com wrote: > from random import * > from math import floor > > > kaarte_alles = 52 > kaart_t?mmatud = [False for i in range(52)] > > > mast = ["?rtu", "ruutu", "poti", "risti"] > aste = ["?ss", "kaks", "kolm", "neli","viis", "kuus", \ > "seitse", "kaheksa", "?heksa", "k?mme", "soldat",\ > "emand", "kuningas"] > > def t?mba_kaart(): > global kaarte_alles > if kaarte_alles == 0: > print("Segan pakki") > kaarte_alles = 52 > for i in range(52): > kaart_t?mmatud[i] = False > kaarte_alles -= 1 > n = random(kaarte_alles) > kaart = vali_j?rgmine_vaba(n) > m = kaart % 13 > a = kaart / 13 > print(mast[int(a)] + " " + aste[int(m)]) > > def vali_j?rgmine_vaba(n): > i = -1 > > while(n > 0): > n -= 1 > i = i + 1 > while kaart_t?mmatud[i]: > i = i + 1 > kaart_t?mmatud[i] = True > return i > > def random(n): > return randint(0, n) > > while True: > n = int(input("Mitu kaarti t?mmata(0 et v?ljuda): ")) > if(n==0): > break > > for i in range(n): > t?mba_kaart() > > > HI im trying to make a card dealer, but this code doesent work correctly. It deasl cards, but the cards to repeat. when i type in 52 ten i might get 3 the same cards. This is a translation from my c++ code. In c++ it works correctly. > Suppose random(...) returns 0. In 'vali_j?rgmine_vaba', n == 0, so it won't run anything in the 'while' loop, therefore i == -1, therefore: kaart_t?mmatud[-1] = True (which sets the last item in the list). If random(...) returns 0 again (which is possible), 'vali_j?rgmine_vaba' will do exactly the same thing. From alister.ware at ntlworld.com Fri Sep 27 07:41:55 2013 From: alister.ware at ntlworld.com (Alister) Date: Fri, 27 Sep 2013 11:41:55 GMT Subject: card dealer References: <0617088e-5aa3-4c5d-b660-22040ee858a1@googlegroups.com> Message-ID: <7ae1u.2$1W6.0@fx05.am4> On Fri, 27 Sep 2013 03:24:28 -0700, markotaht wrote: > from random import * > from math import floor > > > kaarte_alles = 52 kaart_t?mmatud = [False for i in range(52)] > > > mast = ["?rtu", "ruutu", "poti", "risti"] > aste = ["?ss", "kaks", "kolm", "neli","viis", "kuus", \ > "seitse", "kaheksa", "?heksa", "k?mme", "soldat",\ > "emand", "kuningas"] > > def t?mba_kaart(): > global kaarte_alles if kaarte_alles == 0: > print("Segan pakki") > kaarte_alles = 52 for i in range(52): > kaart_t?mmatud[i] = False > kaarte_alles -= 1 n = random(kaarte_alles) > kaart = vali_j?rgmine_vaba(n) > m = kaart % 13 a = kaart / 13 print(mast[int(a)] + " " + > aste[int(m)]) > > def vali_j?rgmine_vaba(n): > i = -1 > > while(n > 0): > n -= 1 i = i + 1 while kaart_t?mmatud[i]: > i = i + 1 > kaart_t?mmatud[i] = True return i > > def random(n): > return randint(0, n) > > while True: > n = int(input("Mitu kaarti t?mmata(0 et v?ljuda): ")) > if(n==0): > break > > for i in range(n): > t?mba_kaart() > > > HI im trying to make a card dealer, but this code doesent work > correctly. It deasl cards, but the cards to repeat. when i type in 52 > ten i might get 3 the same cards. This is a translation from my c++ > code. In c++ it works correctly. It looks like you a simply selecting a random entry in the deck i would suggest you try the following 1) build the deck as a list (i think you are already doing this) 2) shuffle the list (random.shuffle would be good here) 3) pop the cards of the list as required this resemble the real world & should be easy to break down into various classes & expand for multiple decks if req. -- Passionate hatred can give meaning and purpose to an empty life. -- Eric Hoffer From oisin.mulvihill at gmail.com Fri Sep 27 07:37:13 2013 From: oisin.mulvihill at gmail.com (Oisin Mulvihill) Date: Fri, 27 Sep 2013 12:37:13 +0100 Subject: nozama-cloudsearch-service 1.1.2: a local Amazon CloudSearch using ElasticSearch as its backend. Message-ID: Hello, Have you ever wanted to test your app against a dev version of your production CloudSearch? Is management saying budget constraints won't allow this? Then Nozama CloudSearch is for you. It is a light weight implementation of Amazon's CloudSearch service you can run locally. Its has additional REST API features which allow inspection of data in a way not available via Amazon CloudSearch. Nozama is also a way to migrate from Amazon CloudSearch to ElasticSearch. Version 1.1.2 This now supports text searching and uses ElasticSearch as it backend. Facets are not yet supported. I use MongoDB to store the results of batch upload runs. This will change in future as I believe I can use ElasticSearch for this too. It is BSD licensed and available now from pypi https://pypi.python.org/pypi/ nozama-cloudsearch-service: easy_install nozama-cloudsearch-service Contributions are always welcome. Just fork me on github: * https://github.com/oisinmulvihill/nozama-cloudsearch It also has documentation which it self hosts or can be seen on readthedocs: * https://nozama-cloudsearch.readthedocs.org/en/latest/index.html All the best, Oisin -------------- next part -------------- An HTML attachment was scrubbed... URL: From someshg2 at gmail.com Fri Sep 27 08:48:41 2013 From: someshg2 at gmail.com (someshg2 at gmail.com) Date: Fri, 27 Sep 2013 05:48:41 -0700 (PDT) Subject: How to write in to already opened excel file by using openpyxl Message-ID: <276eb8a6-f326-412f-accf-53bb4677c8c7@googlegroups.com> Hi..there, I have opened a excel file by using the following code from openpyxl import load_workbook wb = load_workbook('path of the file') DriverTableSheet = wb.get_sheet_by_name(name = 'name of the sheet') after that i have to append some values in that excel file.. for that i used the following code DriverTableSheet.cell(row=1, column=2).value="value" but it is not responsive..can u guys please guide how to write / append a data in that excel file and save that excel file From neilc at norwich.edu Fri Sep 27 09:37:09 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 27 Sep 2013 13:37:09 GMT Subject: How to write in to already opened excel file by using openpyxl References: <276eb8a6-f326-412f-accf-53bb4677c8c7@googlegroups.com> Message-ID: On 2013-09-27, someshg2 at gmail.com wrote: > Hi..there, > > I have opened a excel file by using the following code > from openpyxl import load_workbook > > wb = load_workbook('path of the file') > DriverTableSheet = wb.get_sheet_by_name(name = 'name of the sheet') > after that i have to append some values in that excel file.. > > for that i used the following code > > DriverTableSheet.cell(row=1, column=2).value="value" > > but it is not responsive..can u guys please guide how to write > / append a data in that excel file and save that excel file Show more code, please. And please describe the error more fully. What did you hope to happen, and what happened instead? What have you tried so far? -- Neil Cerutti From joel.goldstick at gmail.com Fri Sep 27 10:13:37 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 27 Sep 2013 10:13:37 -0400 Subject: How to write in to already opened excel file by using openpyxl In-Reply-To: References: <276eb8a6-f326-412f-accf-53bb4677c8c7@googlegroups.com> Message-ID: On Fri, Sep 27, 2013 at 9:37 AM, Neil Cerutti wrote: > On 2013-09-27, someshg2 at gmail.com wrote: > > Hi..there, > > > > I have opened a excel file by using the following code > > from openpyxl import load_workbook > > > > wb = load_workbook('path of the file') > > DriverTableSheet = wb.get_sheet_by_name(name = 'name of the sheet') > > after that i have to append some values in that excel file.. > > > > for that i used the following code > > > > DriverTableSheet.cell(row=1, column=2).value="value" > > > > but it is not responsive..can u guys please guide how to write > > / append a data in that excel file and save that excel file > > https://mail.python.org/mailman/listinfo/python-list > You need to read the documentation: http://openpyxl.readthedocs.org/en/latest/tutorial.html#saving-to-a-file The code you show doesn't have any save method being called. -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From someshg2 at gmail.com Fri Sep 27 10:33:03 2013 From: someshg2 at gmail.com (somesh g) Date: Fri, 27 Sep 2013 07:33:03 -0700 (PDT) Subject: How to write in to already opened excel file by using openpyxl In-Reply-To: <276eb8a6-f326-412f-accf-53bb4677c8c7@googlegroups.com> References: <276eb8a6-f326-412f-accf-53bb4677c8c7@googlegroups.com> Message-ID: <28306f3f-0bb8-480a-b7b0-a6517c81658b@googlegroups.com> hi..Neil yes i dint saved that time and i added the save option and it saved Thanks for the response From someshg2 at gmail.com Fri Sep 27 10:33:52 2013 From: someshg2 at gmail.com (somesh g) Date: Fri, 27 Sep 2013 07:33:52 -0700 (PDT) Subject: How to write in to already opened excel file by using openpyxl In-Reply-To: <276eb8a6-f326-412f-accf-53bb4677c8c7@googlegroups.com> References: <276eb8a6-f326-412f-accf-53bb4677c8c7@googlegroups.com> Message-ID: <6ccea909-43e7-48f7-bef1-60aec1f8bc07@googlegroups.com> Hi..joel what is said is correct i dint added save to that after adding its working perfect thanks From someshg2 at gmail.com Fri Sep 27 10:36:26 2013 From: someshg2 at gmail.com (somesh g) Date: Fri, 27 Sep 2013 07:36:26 -0700 (PDT) Subject: unable to read combo boxes in excel by xlrd package in python Message-ID: <6e38b68a-0fa7-47c4-8e36-308b5b89bbdd@googlegroups.com> Hi..there I want to read the combo box in excel by using "xlrd" but in the output it is showing empty message, its not reading the combo box can u guys help me how to read the combo box in excel by "xlrd" code written like this workbook = xlrd.open_workbook('path of the file') worksheet = workbook.sheet_by_name('sheetname') TargetSystem = worksheet.cell_value(4, 2) From neilc at norwich.edu Fri Sep 27 11:04:22 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 27 Sep 2013 15:04:22 GMT Subject: unable to read combo boxes in excel by xlrd package in python References: <6e38b68a-0fa7-47c4-8e36-308b5b89bbdd@googlegroups.com> Message-ID: On 2013-09-27, somesh g wrote: > Hi..there > > I want to read the combo box in excel by using "xlrd" but in > the output it is showing empty message, its not reading the > combo box can u guys help me how to read the combo box in excel > by "xlrd" > > code written like this > > workbook = xlrd.open_workbook('path of the file') > worksheet = workbook.sheet_by_name('sheetname') > TargetSystem = worksheet.cell_value(4, 2) It depends on what kind of combo-box it is. The Excel-native combo-box sucks (no auto-completion, no multi-select, etc.), and so it's possible a Visual Basic widget was used instead. That would leave the cell contents blank when read, as above. You will need to retrieve the value from the combo-box object directly somehow. -- Neil Cerutti From neilc at norwich.edu Fri Sep 27 11:26:23 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 27 Sep 2013 15:26:23 GMT Subject: unable to read combo boxes in excel by xlrd package in python References: <6e38b68a-0fa7-47c4-8e36-308b5b89bbdd@googlegroups.com> Message-ID: On 2013-09-27, Neil Cerutti wrote: > On 2013-09-27, somesh g wrote: >> Hi..there >> >> I want to read the combo box in excel by using "xlrd" but in >> the output it is showing empty message, its not reading the >> combo box can u guys help me how to read the combo box in excel >> by "xlrd" >> >> code written like this >> >> workbook = xlrd.open_workbook('path of the file') >> worksheet = workbook.sheet_by_name('sheetname') >> TargetSystem = worksheet.cell_value(4, 2) > > It depends on what kind of combo-box it is. The Excel-native > combo-box sucks (no auto-completion, no multi-select, etc.), and > so it's possible a Visual Basic widget was used instead. That > would leave the cell contents blank when read, as above. > > You will need to retrieve the value from the combo-box object > directly somehow. If it's an Active-X ListBox or ComboBox, there's probably be a CellLink defined. This will be the cell you need to read with xlrd to get the value. -- Neil Cerutti From hossamalagmy at gmail.com Fri Sep 27 10:44:49 2013 From: hossamalagmy at gmail.com (23alagmy) Date: Fri, 27 Sep 2013 07:44:49 -0700 (PDT) Subject: Free Proxy site 2014 Message-ID: Free Proxy site 2014 search is the first proxy supports proxy access blocked sites, browsing, and downloads without restrictions and also conceal your identity Pencah by 100% from the sites you visit http://natigaas7ab.net/wp/?p=14556 From davea at davea.name Fri Sep 27 17:11:49 2013 From: davea at davea.name (Dave Angel) Date: Fri, 27 Sep 2013 21:11:49 +0000 (UTC) Subject: Free Proxy site 2014 References: Message-ID: On 27/9/2013 10:44, 23alagmy wrote: > Free Proxy site 2014 > search is the first proxy supports proxy access blocked sites, browsing, and downloads without restrictions and also conceal your identity Pencah by 100% from the sites you visit > > Sure, I'm going to trust going to a site recommended by a spammer who doesn't know the language he's posting in. Right. -- DaveA From denismfmcmahon at gmail.com Fri Sep 27 12:19:45 2013 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Fri, 27 Sep 2013 16:19:45 +0000 (UTC) Subject: what is wrong in my code?? (python 3.3) References: Message-ID: On Fri, 27 Sep 2013 06:54:48 -0700, dream4soul wrote: > #!c:/Python33/python.exe -u > import os, sys > print("Content-type: text/html; charset=utf-8\n\n") > print ('Hello, world!
') > print('????? ????????????????? ???????? ?????.') > I see only first print, second it just question marks in my browser(code > edited in notepad++ with UTF-8 encode). what is wrong?? Sounds like your browser is ignoring the charset. Can you force the browser to utf-8? What happens if you create a plain html file with the same content and send it to your browser? eg: test.html: ----------------- Hello, world!
????? ????????????????? ???????? ?????. ----------------- This really doesn't look like a python issue (again). -- Denis McMahon, denismfmcmahon at gmail.com From dream4soul at gmail.com Mon Sep 30 10:17:11 2013 From: dream4soul at gmail.com (dream4soul at gmail.com) Date: Mon, 30 Sep 2013 07:17:11 -0700 (PDT) Subject: what is wrong in my code?? (python 3.3) In-Reply-To: References: Message-ID: On Friday, September 27, 2013 7:19:45 PM UTC+3, Denis McMahon wrote: > On Fri, 27 Sep 2013 06:54:48 -0700, dream4soul wrote: > > > > > #!c:/Python33/python.exe -u > > > import os, sys > > > print("Content-type: text/html; charset=utf-8\n\n") > > > print ('Hello, world!
') > > > print('????? ????????????????? ???????? ?????.') > > > > > I see only first print, second it just question marks in my browser(code > > > edited in notepad++ with UTF-8 encode). what is wrong?? > > > > Sounds like your browser is ignoring the charset. Can you force the > > browser to utf-8? > > > > What happens if you create a plain html file with the same content and > > send it to your browser? > > > > eg: test.html: > > ----------------- > > Hello, world!
> > ????? ????????????????? ???????? ?????. > > ----------------- > > > > This really doesn't look like a python issue (again). > > > > -- > > Denis McMahon, denismfmcmahon at gmail.com I rename file from test.py in test.txt and all works fine. So clearly problem it is not in file coding or browser. ANY IDEAS?? From piet at vanoostrum.org Mon Sep 30 14:00:14 2013 From: piet at vanoostrum.org (Piet van Oostrum) Date: Mon, 30 Sep 2013 14:00:14 -0400 Subject: what is wrong in my code?? (python 3.3) References: Message-ID: dream4soul at gmail.com writes: > I rename file from test.py in test.txt and all works fine. So clearly problem it is not in file coding or browser. ANY IDEAS?? It looks like the encoding of stdout is not utf-8 in the CGI script. Check it with import sys print(sys.stdout.encoding) If it's not utf-8, you must force your output to be utf-8, as that is what the browser expects, because of your Content-type. You could use: sys.stdout.buffer.write('????? ????????????????? ???????? ?????.'.encode('utf-8')) Or to change stdout into utf-8 encoding: import codecs sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach()) [Note: I haven't tested this] -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From sam at giraffetech.biz Fri Sep 27 11:32:26 2013 From: sam at giraffetech.biz (Sam Giraffe) Date: Fri, 27 Sep 2013 08:32:26 -0700 Subject: Hostrange expansion Message-ID: Hi, I need some help in expanding a hostrange as in: h[1-100].domain.com should get expanded into a list containing h1.domain.com to h100.domain.com. Is there a library that can do this for me? I also need to valid the range before I expand it, i.e., h[1*100].domain.com should not be accept, or other formats should not be accepted. Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From joel.goldstick at gmail.com Fri Sep 27 13:26:37 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 27 Sep 2013 13:26:37 -0400 Subject: Hostrange expansion In-Reply-To: References: Message-ID: On Fri, Sep 27, 2013 at 11:32 AM, Sam Giraffe wrote: > Hi, > > I need some help in expanding a hostrange as in: h[1-100].domain.comshould get expanded into a list containing > h1.domain.com to h100.domain.com. Is there a library that can do this for > me? I also need to valid the range before I expand it, i.e., h[1*100]. > domain.com should not be accept, or other formats should not be accepted. > You can loop on the range and create the list by appending strings created with the range using string substitution. No library involved, just basic python language features. As to the validation problem, I don't think you have defined it well enough to advise you on coding. Why don't you specify exaction what is legal or not legal for your range, write the code, show us what you have, and someone can help you further. My guess is the code can all be written in maybe 20 lines or so. > > Thanks > > -- > https://mail.python.org/mailman/listinfo/python-list > > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Fri Sep 27 13:45:16 2013 From: __peter__ at web.de (Peter Otten) Date: Fri, 27 Sep 2013 19:45:16 +0200 Subject: Hostrange expansion References: Message-ID: Sam Giraffe wrote: > I need some help in expanding a hostrange as in: h[1-100].domain.com > should get expanded into a list containing h1.domain.com to > h100.domain.com. Is there a library that can do this for me? I also need > to valid the range before I expand it, i.e., h[1*100].domain.com should > not be accept, or other formats should not be accepted. To get you started: import re import itertools def to_range(s, sep="-"): """ >>> to_range("9-11") ['9', '10', '11'] """ lo, hi = s.split(sep) return [str(i) for i in range(int(lo), int(hi)+1)] def explode(s): """ >>> list(explode("h[3-5].com")) ['h3.com', 'h4.com', 'h5.com'] """ parts = re.compile(r"(\[\d+-\d+\])").split(s) parts[0::2] = [[p] for p in parts[0::2]] parts[1::2] = [to_range(p[1:-1]) for p in parts[1::2]] return ("".join(p) for p in itertools.product(*parts)) if __name__ == "__main__": dom = "h[1-3]x[9-11].com" print(dom) for name in explode(dom): print(" {}".format(name)) From jonathan.corriveau at gmail.com Fri Sep 27 15:45:35 2013 From: jonathan.corriveau at gmail.com (jonathan.corriveau at gmail.com) Date: Fri, 27 Sep 2013 12:45:35 -0700 (PDT) Subject: =?ISO-8859-1?Q?Aide_pour_bien_d=E9marrer_en_Python?= Message-ID: <0d6b5b97-c5fc-496f-8cfd-07631de3a61b@googlegroups.com> Je sais qu'il y a plein d'information ? lire un peu partout, mais j'ai vraiment du mal ? voir pourquoi Python est si fantastique... Je m'explique.... Pour moi python c'est un langage de script tr?s cryptique avec des noms de m?thodes courts, pas claire, dans une identation pas toujours facile ? lire et qui me rappel (mauvais souvenir) le positionnement obligatoire des instructions en COBOL... Je viens d'un monde .Net o? les noms de m?thodes disent exactement, tr?s pr?cisemment ce que fait le code (quite ? avoir un nom de 30 caract?res)... Dans les standards PEP-8, il y a beaucoup de standards qui vont de soit, c'est facile de comprendre pourquoi c'est comme ?a. Mais, il y a plein de cas o?, personnelement et pour probablement plusieurs d?veloppeurs qui viennent du monde JAVA ou .Net, c'est tr?s illisible et m?me contre-intuitif... Outre l'aspect visuel, je trouve des codes d'exemples, prit dans un pain et dans un seul fichier, tr?s mal d?coup?s et ?a devient tr?s difficile de se retrouver pour savoir qui fait quoi... On voit partout Python est orient? objet, tout le tralala, mais dans ma t?te, j'ai bien du mal ? voir du code Python qui suit certaine r?gle ? la Clean Code avec des patterns bien ?tablient (IoC, DI, Repository, UnitOfWork)... J'ai plus souvent l'impression de voir des SmartUI (anti-pattern) qui d?pendent de la terre enti?re avec aucune r??l separation of concern... Ceci dit, j'essaie vraiment d'apprendre le python et j'aimerais bien le faire... Pourriez-vous m'indiquer des bonnes ressources, documentation qui pourrait r?pondre ? mes int?rogations ? Merci! From joel.goldstick at gmail.com Fri Sep 27 15:57:03 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 27 Sep 2013 15:57:03 -0400 Subject: =?UTF-8?Q?Re=3A_Aide_pour_bien_d=C3=A9marrer_en_Python?= In-Reply-To: <0d6b5b97-c5fc-496f-8cfd-07631de3a61b@googlegroups.com> References: <0d6b5b97-c5fc-496f-8cfd-07631de3a61b@googlegroups.com> Message-ID: 2013/9/27 > Je sais qu'il y a plein d'information ? lire un peu partout, mais j'ai > vraiment du mal ? voir pourquoi Python est si fantastique... > > Je m'explique.... > > Pour moi python c'est un langage de script tr?s cryptique avec des noms de > m?thodes courts, pas claire, dans une identation pas toujours facile ? lire > et qui me rappel (mauvais souvenir) le positionnement obligatoire des > instructions en COBOL... Je viens d'un monde .Net o? les noms de m?thodes > disent exactement, tr?s pr?cisemment ce que fait le code (quite ? avoir un > nom de 30 caract?res)... > > Dans les standards PEP-8, il y a beaucoup de standards qui vont de soit, > c'est facile de comprendre pourquoi c'est comme ?a. Mais, il y a plein de > cas o?, personnelement et pour probablement plusieurs d?veloppeurs qui > viennent du monde JAVA ou .Net, c'est tr?s illisible et m?me > contre-intuitif... > > Outre l'aspect visuel, je trouve des codes d'exemples, prit dans un pain > et dans un seul fichier, tr?s mal d?coup?s et ?a devient tr?s difficile de > se retrouver pour savoir qui fait quoi... > > On voit partout Python est orient? objet, tout le tralala, mais dans ma > t?te, j'ai bien du mal ? voir du code Python qui suit certaine r?gle ? la > Clean Code avec des patterns bien ?tablient (IoC, DI, Repository, > UnitOfWork)... > > J'ai plus souvent l'impression de voir des SmartUI (anti-pattern) qui > d?pendent de la terre enti?re avec aucune r??l separation of concern... > > Ceci dit, j'essaie vraiment d'apprendre le python et j'aimerais bien le > faire... > Pourriez-vous m'indiquer des bonnes ressources, documentation qui pourrait > r?pondre ? mes int?rogations ? > > Merci! > -- > https://mail.python.org/mailman/listinfo/python-list > It seems that people in the .NET world don't seem to like python. Maybe the reverse is true. All the things that .net or java people hate about python, python people view as the best parts of the language. But, if you need to use python you can start with python.org. There are many links to documentation suitable for different skill levels. Some of it is available in French: https://wiki.python.org/moin/FrenchLanguage good luck to you -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From vincent.vandevyvre at swing.be Fri Sep 27 16:24:29 2013 From: vincent.vandevyvre at swing.be (Vincent Vande Vyvre) Date: Fri, 27 Sep 2013 22:24:29 +0200 Subject: Aide pour bien =?ISO-8859-1?Q?d=E9marrer_en_Python?= In-Reply-To: References: <0d6b5b97-c5fc-496f-8cfd-07631de3a61b@googlegroups.com> Message-ID: <5245E97D.5030001@swing.be> Le 27/09/2013 21:57, Joel Goldstick a ?crit : > > > > 2013/9/27 > > > Je sais qu'il y a plein d'information ? lire un peu partout, mais > j'ai vraiment du mal ? voir pourquoi Python est si fantastique... > > Je m'explique.... > > Pour moi python c'est un langage de script tr?s cryptique avec des > noms de m?thodes courts, pas claire, dans une identation pas > toujours facile ? lire et qui me rappel (mauvais souvenir) le > positionnement obligatoire des instructions en COBOL... Je viens > d'un monde .Net o? les noms de m?thodes disent exactement, tr?s > pr?cisemment ce que fait le code (quite ? avoir un nom de 30 > caract?res)... > > Dans les standards PEP-8, il y a beaucoup de standards qui vont de > soit, c'est facile de comprendre pourquoi c'est comme ?a. Mais, il > y a plein de cas o?, personnelement et pour probablement plusieurs > d?veloppeurs qui viennent du monde JAVA ou .Net, c'est tr?s > illisible et m?me contre-intuitif... > > Outre l'aspect visuel, je trouve des codes d'exemples, prit dans > un pain et dans un seul fichier, tr?s mal d?coup?s et ?a devient > tr?s difficile de se retrouver pour savoir qui fait quoi... > > On voit partout Python est orient? objet, tout le tralala, mais > dans ma t?te, j'ai bien du mal ? voir du code Python qui suit > certaine r?gle ? la Clean Code avec des patterns bien ?tablient > (IoC, DI, Repository, UnitOfWork)... > > J'ai plus souvent l'impression de voir des SmartUI (anti-pattern) > qui d?pendent de la terre enti?re avec aucune r??l separation of > concern... > > Ceci dit, j'essaie vraiment d'apprendre le python et j'aimerais > bien le faire... > Pourriez-vous m'indiquer des bonnes ressources, documentation qui > pourrait r?pondre ? mes int?rogations ? > > Merci! > -- > https://mail.python.org/mailman/listinfo/python-list > > > It seems that people in the .NET world don't seem to like python. > Maybe the reverse is true. All the things that .net or java people > hate about python, python people view as the best parts of the > language. But, if you need to use python you can start with > python.org . There are many links to documentation > suitable for different skill levels. Some of it is available in > French: https://wiki.python.org/moin/FrenchLanguage > > good luck to you > > -- > Joel Goldstick > http://joelgoldstick.com > > Je te recommande : http://python.developpez.com/cours/apprendre-python3/ -- Vincent V.V. Oqapy . Qarte . PaQager From laurent.pointal at free.fr Sun Sep 29 08:04:40 2013 From: laurent.pointal at free.fr (Laurent Pointal) Date: Sun, 29 Sep 2013 14:04:40 +0200 Subject: Aide pour bien =?UTF-8?B?ZMOpbWFycmVy?= en Python References: <0d6b5b97-c5fc-496f-8cfd-07631de3a61b@googlegroups.com> Message-ID: <52481758$0$2139$426a74cc@news.free.fr> note pour les francophones il existe le newsgroup fr.comp.lang.python ainsi que la liste Python de l'AFUL https://listes.aful.org/wws/info/python et l'AFPY... jonathan.corriveau at gmail.com wrote: > Je sais qu'il y a plein d'information ? lire un peu partout, mais j'ai > vraiment du mal ? voir pourquoi Python est si fantastique... > > Je m'explique.... > > Pour moi python c'est un langage de script tr?s cryptique avec des noms de > m?thodes courts, pas claire, dans une identation pas toujours facile ? > lire et qui me rappel (mauvais souvenir) le positionnement obligatoire des > instructions en COBOL... L'indentation remplace les {} ou begin/end & Co - et se trouve ?tre ce que font la pluspart des d?veloppeurs: placer le code graphiquement pour savoir au premier coup d'?il o? ?a commence et o? ?a s'arr?te. Bon, faut utiliser un ?diteur bien configur? pour s'assurer de ne plus avoir de caract?re tabulation (ou que ?a, mais c'est difficile). > Je viens d'un monde .Net o? les noms de m?thodes > disent exactement, tr?s pr?cisemment ce que fait le code (quite ? avoir un > nom de 30 caract?res)... Question de go?t. L? je trouve que ?a fait un peu long. > Dans les standards PEP-8, il y a beaucoup de standards qui vont de soit, > c'est facile de comprendre pourquoi c'est comme ?a. Mais, il y a plein de > cas o?, personnelement et pour probablement plusieurs d?veloppeurs qui > viennent du monde JAVA ou .Net, c'est tr?s illisible et m?me > contre-intuitif... Ne t'inqui?tes pas, c'est la m?me chose pour les programmeurs Python qui ont a faire du Java ou .Net, ils trouvent ?a lourd et contre-intuitif. Et le PEP8 n'est pas une obligation, juste des conseils de bonnes pratiques. > Outre l'aspect visuel, je trouve des codes d'exemples, prit dans un pain > et dans un seul fichier, tr?s mal d?coup?s et ?a devient tr?s difficile de > se retrouver pour savoir qui fait quoi... Rien n'oblige ? tout mettre dans un fichier, mais pour juste un exemple c'est souvent plus facile. > On voit partout Python est orient? objet, tout le tralala, mais dans ma > t?te, j'ai bien du mal ? voir du code Python qui suit certaine r?gle ? la > Clean Code avec des patterns bien ?tablient (IoC, DI, Repository, > UnitOfWork)... Le fait de pouvoir faire de la POO n'oblige en rien ? utiliser certains patterns - que l'on trouve parfois pour contourner les contraintes des langages. Et Python permet la POO mais ne l'oblige pas. > J'ai plus souvent l'impression de voir des SmartUI (anti-pattern) qui > d?pendent de la terre enti?re avec aucune r??l separation of concern... > > Ceci dit, j'essaie vraiment d'apprendre le python et j'aimerais bien le > faire... Pourriez-vous m'indiquer des bonnes ressources, documentation qui > pourrait r?pondre ? mes int?rogations ? http://w2.syronex.com/jmr/python-paradox http://dirtsimple.org/2004/12/python-is-not-java.html Et deux textes dont on a l'impression qu'ils r?sultent d'un traducteur automatique: http://fr.softuses.com/231303 http://fr.softuses.com/144363 Et si ?a peut servir: Le m?mento (fr / en) http://perso.limsi.fr/pointal/python:memento L'abr?g? (fr / en) http://perso.limsi.fr/pointal/python:abrege > > Merci! -- Laurent POINTAL - laurent.pointal at laposte.net From python.list at tim.thechases.com Fri Sep 27 18:22:14 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 27 Sep 2013 17:22:14 -0500 Subject: walking a heapq nondestructively without duplicating? Message-ID: <20130927172214.1d9be803@bigbox.christie.dr> I've got a large heapq'ified list and want to walk it in-order without altering it. I get the "unsorted" heap'ish results if I just do from heapq import heappush, heappop, nlargest, nsmallest my_heap = [] for thing in lots_of_items(): heappush(thing) for item in my_heap: ... To get them in-order, I can do something like while my_heap: item = heappop(my_heap) do_something(item) to iterate over the items in order, but that destroys the original heap. I can also do for item in nlargest(len(my_heap), my_heap): # or nsmallest() do_something(item) but this duplicates a potentially large list according to my reading of the description for nlargest/nsmallest[1]. Is there a handy way to non-destructively walk the heap (either in-order or reversed) without duplicating its contents? -tkc [1] http://docs.python.org/2/library/heapq.html#heapq.nlargest From ned at nedbatchelder.com Fri Sep 27 19:08:02 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 27 Sep 2013 19:08:02 -0400 Subject: walking a heapq nondestructively without duplicating? In-Reply-To: <20130927172214.1d9be803@bigbox.christie.dr> References: <20130927172214.1d9be803@bigbox.christie.dr> Message-ID: <52460FD2.9080806@nedbatchelder.com> On 9/27/13 6:22 PM, Tim Chase wrote: > I've got a large heapq'ified list and want to walk it in-order > without altering it. I get the "unsorted" heap'ish results if I just > do > > from heapq import heappush, heappop, nlargest, nsmallest > my_heap = [] > for thing in lots_of_items(): > heappush(thing) > for item in my_heap: > ... > > To get them in-order, I can do something like > > while my_heap: > item = heappop(my_heap) > do_something(item) > > to iterate over the items in order, but that destroys the original > heap. I can also do > > for item in nlargest(len(my_heap), my_heap): # or nsmallest() > do_something(item) > > but this duplicates a potentially large list according to my > reading of the description for nlargest/nsmallest[1]. Is there a > handy way to non-destructively walk the heap (either in-order or > reversed) without duplicating its contents? If you add all your items at once, and then you want to walk over all the items, then don't use a heap. Just put all your items in a list, and then sort it. The advantage of a heap is that you can add items to it with little effort, delaying some of the work until when you need to get the items out. It maintains a partially-sorted list that's good for insertion and popping. You have different needs. Use a sorted list. --Ned. > -tkc > > [1] http://docs.python.org/2/library/heapq.html#heapq.nlargest > > > > > > > From jae655 at gmail.com Fri Sep 27 20:43:42 2013 From: jae655 at gmail.com (jae655 at gmail.com) Date: Fri, 27 Sep 2013 17:43:42 -0700 (PDT) Subject: Help me with Python please (picture) Message-ID: <7eb1cc5a-a25c-448e-9131-2f8b3ee60f96@googlegroups.com> http://imgur.com/E6vrNs4 Can't seem to be getting an output. From gary.herron at islandtraining.com Fri Sep 27 21:11:05 2013 From: gary.herron at islandtraining.com (Gary Herron) Date: Fri, 27 Sep 2013 18:11:05 -0700 Subject: Help me with Python please (picture) In-Reply-To: <7eb1cc5a-a25c-448e-9131-2f8b3ee60f96@googlegroups.com> References: <7eb1cc5a-a25c-448e-9131-2f8b3ee60f96@googlegroups.com> Message-ID: <52462CA9.3000100@islandtraining.com> On 09/27/2013 05:43 PM, jae655 at gmail.com wrote: > http://imgur.com/E6vrNs4 > > > Can't seem to be getting an output. Please find a way to include the code in the email. Also what evidence do you provide that it does not work? What happened when you ran it? What did you expect to happen? What were you trying to achieve? Since you are asking volunteers to help, it would be polite to take the time to explain things carefully. Gary Herron From davea at davea.name Fri Sep 27 21:18:20 2013 From: davea at davea.name (Dave Angel) Date: Sat, 28 Sep 2013 01:18:20 +0000 (UTC) Subject: Help me with Python please (picture) References: <7eb1cc5a-a25c-448e-9131-2f8b3ee60f96@googlegroups.com> Message-ID: On 27/9/2013 20:43, jae655 at gmail.com wrote: > http://imgur.com/E6vrNs4 > > > Can't seem to be getting an output. Please compose a text message containing a description of the environment, the (small) code, and the expected results. This is a text mailing list, and posting transient images on untrusted websites is not likely to get you much help. And when copying the code and the output, please use cut and paste; don't paraphrase or retype anything. if you don't know how to capture the text, describe your environment, and somebody will probably be able to help you. -- DaveA From denismfmcmahon at gmail.com Fri Sep 27 22:18:43 2013 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Sat, 28 Sep 2013 02:18:43 +0000 (UTC) Subject: Help me with Python please (picture) References: <7eb1cc5a-a25c-448e-9131-2f8b3ee60f96@googlegroups.com> Message-ID: On Fri, 27 Sep 2013 17:43:42 -0700, jae655 wrote: > http://imgur.com/E6vrNs4 > Can't seem to be getting an output. I can't see where your output statements are. With no output statements, there is no output. perhaps you want to assign the result of the function call to a variable, and then print the variable? Or perhaps not, perhaps you were going to do the output some other way? -- Denis McMahon, denismfmcmahon at gmail.com From john_ladasky at sbcglobal.net Sat Sep 28 00:03:33 2013 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Fri, 27 Sep 2013 21:03:33 -0700 (PDT) Subject: Help me with Python please (picture) In-Reply-To: <7eb1cc5a-a25c-448e-9131-2f8b3ee60f96@googlegroups.com> References: <7eb1cc5a-a25c-448e-9131-2f8b3ee60f96@googlegroups.com> Message-ID: On Friday, September 27, 2013 5:43:42 PM UTC-7, jae... at gmail.com wrote: > http://imgur.com/E6vrNs4 > > Can't seem to be getting an output. Because you aren't printing anything! One possible way to fix that is to change the line which reads... random_characters(8) to read... print(random_characters(8)) instead. From steve+comp.lang.python at pearwood.info Sat Sep 28 01:18:06 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Sep 2013 05:18:06 GMT Subject: Help me with Python please (picture) References: <7eb1cc5a-a25c-448e-9131-2f8b3ee60f96@googlegroups.com> Message-ID: <5246668d$0$30000$c3e8da3$5496439d@news.astraweb.com> On Fri, 27 Sep 2013 17:43:42 -0700, jae655 wrote: > http://imgur.com/E6vrNs4 > > > Can't seem to be getting an output. The problem with your code has to do with the code between pixel coordinates (29, 234) and (175, 249) approximately. If you open your image in a pixel editor, copy and paste that part out, run it through some OCR software, and then add "print " (including the space) before it, you will probably get the result you are after. By the way, posting a picture of your code is thoughtless and rude to those contributors and programmers who are blind or partially sighted. If you post text, they can contribute using a screen-reader. If you post a picture, they're screwed. Even if you don't give two hoots for the blind, at least consider that maybe they can answer your question when nobody else can. Why would we want to follow a link to look at your code, when we could read it right here in your message? We might not have access to imgur (many places block it). We cannot copy and paste your code to run it to see what it does, or make edits to it. If we want to describe parts of your code we have to re-type it, possibly introducing our own typos. I really don't understand why you would take program code, which is text, and take a screenshot of it, then spend time blanking out parts of the screenshot. Text is *much* more useful for a programmer. It astonishes me that there is an entire subreddit on imgur dedicated to people who take screenshots of their code. What's wrong with them? Could be worse -- at least you didn't take a photo of the screen with your phone, them email the picture to yourself, then take a screenshot of the photo in your mail client, then upload that screenshot to imgur, then take a screenshot of the picture on imgur, then post that screenshot here. -- Steven From rosuav at gmail.com Sat Sep 28 01:46:12 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 28 Sep 2013 15:46:12 +1000 Subject: Help me with Python please (picture) In-Reply-To: <5246668d$0$30000$c3e8da3$5496439d@news.astraweb.com> References: <7eb1cc5a-a25c-448e-9131-2f8b3ee60f96@googlegroups.com> <5246668d$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Sep 28, 2013 at 3:18 PM, Steven D'Aprano wrote: > Could be worse -- at least you didn't take a photo of the screen with > your phone, them email the picture to yourself, then take a screenshot of > the photo in your mail client, then upload that screenshot to imgur, then > take a screenshot of the picture on imgur, then post that screenshot here. http://xkcd.com/763/ ChrisA From dvghana at gmail.com Sat Sep 28 12:17:54 2013 From: dvghana at gmail.com (dvghana at gmail.com) Date: Sat, 28 Sep 2013 09:17:54 -0700 (PDT) Subject: Help me with Python please (picture) In-Reply-To: <7eb1cc5a-a25c-448e-9131-2f8b3ee60f96@googlegroups.com> References: <7eb1cc5a-a25c-448e-9131-2f8b3ee60f96@googlegroups.com> Message-ID: <1f5d2dd8-877d-4d80-b3c3-d5a048556061@googlegroups.com> On Saturday, September 28, 2013 12:43:42 AM UTC, jae... at gmail.com wrote: > http://imgur.com/E6vrNs4 > > > > > > Can't seem to be getting an output. All the comments about using an image to ask for help over here is extremely valid so I hope you accept it in good faith. I am a noob like you so I can tolerate it and see if I can help you. So here we go: 1. random.randit will only return an integer but it sounds to me like you are trying to return one of the elements in "chars" If my understanding is correct try using random.choice instead. To return a random character from the alphabets you can try: >> import string >> char = random.choice(string.ascii_lowercase) #string.ascii_uppercase for uppercace 2. you may not need the main() function. and you didn't have any 'print' statement so when you run the code you won't see anything. You are simply generating random characters and throwing them away try: print (random_characters(8)) 3. but if you run the code as it stands it won't generate 8 random charaters so you'll actually have to be appending it on a list. So instead of: new_string = '' try: new_string = [] 4. Finally, join the elements in the list once they are generated like this: return "".join(new_string) but don't forget to append each character anytime the loop runs this way: new_string.append(random.choice(string.ascii_lowercase)) Overall I wrote my own version of the code and this is what I got: ****************** import string import random def random_characters(number): i = 0 new_string = [] while (i < number) : new_string.append(random.choice(string.ascii_lowercase)) i = i + 1 return "".join(new_string) print(random_characters(3)) ******* From joel.goldstick at gmail.com Sat Sep 28 12:50:17 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sat, 28 Sep 2013 12:50:17 -0400 Subject: Help me with Python please (picture) In-Reply-To: <1f5d2dd8-877d-4d80-b3c3-d5a048556061@googlegroups.com> References: <7eb1cc5a-a25c-448e-9131-2f8b3ee60f96@googlegroups.com> <1f5d2dd8-877d-4d80-b3c3-d5a048556061@googlegroups.com> Message-ID: On Sat, Sep 28, 2013 at 12:17 PM, wrote: > On Saturday, September 28, 2013 12:43:42 AM UTC, jae... at gmail.com wrote: > > http://imgur.com/E6vrNs4 > > > > > > > > > > > > Can't seem to be getting an output. > > All the comments about using an image to ask for help over here is > extremely valid so I hope you accept it in good faith. I am a noob like you > so I can tolerate it and see if I can help you. > > So here we go: > 1. random.randit will only return an integer but it sounds to me like you > are trying to return one of the elements in "chars" > > If my understanding is correct try using random.choice instead. > > To return a random character from the alphabets you can try: > > >> import string > >> char = random.choice(string.ascii_lowercase) > #string.ascii_uppercase for uppercace > > 2. you may not need the main() function. > and you didn't have any 'print' statement so when you run the code you > won't see anything. You are simply generating random characters and > throwing them away > > try: > print (random_characters(8)) > > 3. but if you run the code as it stands it won't generate 8 random > charaters so you'll actually have to be appending it on a list. > > So instead of: > new_string = '' > try: > new_string = [] > > 4. Finally, join the elements in the list once they are generated like > this: > return "".join(new_string) > but don't forget to append each character anytime the loop runs this way: > new_string.append(random.choice(string.ascii_lowercase)) > > Overall I wrote my own version of the code and this is what I got: > > > ****************** > import string > import random > > def random_characters(number): > i = 0 > new_string = [] > > while (i < number) : > new_string.append(random.choice(string.ascii_lowercase)) > i = i + 1 > return "".join(new_string) > > > print(random_characters(3)) > ******* > -- > https://mail.python.org/mailman/listinfo/python-list > I'm guessing this is homework since its kind of a contrived exercise. If you do any reading of python tutorials or books for beginners I don't think you will see this sort of loop used in python: while i < number: do_something ... i += 1 This is even weirder: while (i < number): Its not that you can't do that. But it is much more common to see in other languages (like C or maybe PHP, others ?). So either the instructor is promoting this kind of loop because he knows a little about another language and not so much about python, or the student has some knowledge of another language. I prefer: for i in range(number): do_something... and finally plus + on the calling out of using images to post code. I'm guessing the OP is a computer user in the sense of running word, or watching you-tube videos, etc. Most non-programmers never used a plain text editor. If you want to learn how to write code, and you are a beginner, use the simplest text editor on your computer, learn to open a shell and run python interactively and run programs that you saved with your text editors. Be glad for simplicity. And happy you don't write code on these: http://en.wikipedia.org/wiki/Hollerith_cards -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at davea.name Sat Sep 28 13:16:57 2013 From: davea at davea.name (Dave Angel) Date: Sat, 28 Sep 2013 17:16:57 +0000 (UTC) Subject: Help me with Python please (picture) References: <7eb1cc5a-a25c-448e-9131-2f8b3ee60f96@googlegroups.com> <1f5d2dd8-877d-4d80-b3c3-d5a048556061@googlegroups.com> Message-ID: On 28/9/2013 12:17, dvghana at gmail.com wrote: > On Saturday, September 28, 2013 12:43:42 AM UTC, jae... at gmail.com wrote: >> >> >> >> Can't seem to be getting an output. > Overall I wrote my own version of the code and this is what I got: > > > ****************** > import string > import random > > def random_characters(number): > i = 0 > new_string = [] > > while (i < number) : > new_string.append(random.choice(string.ascii_lowercase)) > i = i + 1 > return "".join(new_string) > > > print(random_characters(3)) > ******* First, I'd clean up the variable name, and use a for loop instead of a while loop. import string import random def random_characters(number): new_list = [] for i in range(number): new_list.append(random.choice(string.ascii_lowercase)) return "".join(new_list) print(random_characters(8)) Then I'd probably replace the function body with: def random_characters(number): return "".join([random.choice(string.ascii_lowercase) for i in range(number)]) -- DaveA From bob.martin at excite.com Sun Sep 29 08:07:56 2013 From: bob.martin at excite.com (Bob Martin) Date: Sun, 29 Sep 2013 08:07:56 BST Subject: Help me with Python please (picture) References: <7eb1cc5a-a25c-448e-9131-2f8b3ee60f96@googlegroups.com> Message-ID: in 706312 20130928 175017 Joel Goldstick wrote: >--047d7bf0f67adc8dbc04e7746532 >Content-Type: text/plain; charset=UTF-8 > Please don't post HTML. From melwin9 at gmail.com Sat Sep 28 00:52:26 2013 From: melwin9 at gmail.com (melwin9 at gmail.com) Date: Fri, 27 Sep 2013 21:52:26 -0700 (PDT) Subject: Python Unit Tests Message-ID: Hey, How do i go about coming up/coding tests for this program below. Not sure how to even approach writing about 5 tests for it. Initially I had this for the test but its not working well. Test was name test_guess.py (Code Below) [code] from unittest import TestCase import pexpect as pe import guess as g import random random_number = random.randrange(1, 10) correct = False class GuessTest(TestCase): def setUp(self): self.intro = 'I have chosen a number from 1-10' self.request = 'Guess a number: ' self.responseHigh = "That's too high." self.responseLow = "That's too low." self.responseCorrect = "That's right!" self.goodbye = 'Goodbye and thanks for playing!' def test_main(self): #cannot execute main now because it will #require user input from guess import main def test_guessing_hi_low_4(self): # Conversation assuming number is 4 child = pe.spawn('python guess.py') child.expect(self.intro,timeout=5) child.expect(self.request,timeout=5) child.sendline('5') child.expect(self.responseHigh,timeout=5) child.sendline('3') child.expect(self.responseLow,timeout=5) child.sendline('4') child.expect(self.responseCorrect,timeout=5) child.expect(self.goodbye,timeout=5) def __init__(self): self.number = random.randint(0,10) HIGH = 1 LOW = 2 OK = 3 def guess(self, number): if number > self.number: return self.HIGH if number < self.number: return self.LOW return self.OK def test_guesstoolow(self): while not correct: guess = input("What could it be?") if guess == random_number: print "Congrats You Got It" correct = True elif guess > random_number: print "To High" elif guess < random_number: print "To Low" else: print "Try Again" [/code] Python code for game below [code] import random intro = 'I have chosen a number from 1-10' request = 'Guess a number: ' responseHigh = "That's too high." responseLow = "That's too low." responseCorrect = "That's right!" goodbye = 'Goodbye and thanks for playing!' print(intro) def main(): guessesTaken = 0 number = random.randint(1, 10) while guessesTaken < 5: print(request) guess = input() guess = int(guess) guessesTaken = guessesTaken + 1 if guess < number: print(responseLow) if guess > number: print(responseHigh) if guess == number: break if guess == number: guessesTaken = str(guessesTaken) print(responseCorrect + '! You guessed my number in ' + guessesTaken + ' guesses!') if guess != number: number = str(number) print(goodbye + ' The number I was thinking of was ' + number) ##def main(): # print(intro) # user_input = raw_input(request) # print(responseHigh) # print(request) # user_input = raw_input(request) # print(responseLow) # user_input = raw_input(request) # print(responseCorrect) # print(goodbye) if __name__ == '__main__': main()[/code] From davea at davea.name Sat Sep 28 02:11:59 2013 From: davea at davea.name (Dave Angel) Date: Sat, 28 Sep 2013 06:11:59 +0000 (UTC) Subject: Python Unit Tests References: Message-ID: On 28/9/2013 00:52, melwin9 at gmail.com wrote: > Hey, > What version of Python are you using? I'll assume 2.7, but you really should specify it (and any other meaningful environment dependencies) in your original query, the beginning of your thread. For 2.7, the docs for unittest are at: http://docs.python.org/2/library/unittest.html > How do i go about coming up/coding tests for this program below. Not sure how to even approach writing about 5 tests for it. > > Initially I had this for the test but its not working well. > > Test was name test_guess.py (Code Below) > > [code] > from unittest import TestCase > import pexpect as pe > > import guess as g > import random > > random_number = random.randrange(1, 10) > correct = False > > class GuessTest(TestCase): > def setUp(self): > self.intro = 'I have chosen a number from 1-10' > self.request = 'Guess a number: ' > self.responseHigh = "That's too high." > self.responseLow = "That's too low." > self.responseCorrect = "That's right!" > self.goodbye = 'Goodbye and thanks for playing!' These strings don't change from one test to another. Thus they could be set in the __init__() method, and indeed could just be globals. Or even (horrors) imported from the guess module. So in your tests, you might refer to g.intro, rather than self.intro Or you might decide that the content of the strings is not what you're testing, but rather the flow of the logic. > > def test_main(self): > #cannot execute main now because it will > #require user input > from guess import main No need for an import here. Assuming you will be adding a call to main(), you can just call it as g.main(), since you imported g already as a global. > > def test_guessing_hi_low_4(self): > # Conversation assuming number is 4 > child = pe.spawn('python guess.py') > child.expect(self.intro,timeout=5) > child.expect(self.request,timeout=5) > child.sendline('5') > child.expect(self.responseHigh,timeout=5) > child.sendline('3') > child.expect(self.responseLow,timeout=5) > child.sendline('4') > child.expect(self.responseCorrect,timeout=5) > child.expect(self.goodbye,timeout=5) > > > def __init__(self): > self.number = random.randint(0,10) > HIGH = 1 > LOW = 2 > OK = 3 Those 3 statements do nothing useful. They set 3 local variables which are then immediately forgotten. Presumably you meant: self.HIGH = 1 self.LOW = 2 self.OK = 3 > > def guess(self, number): > if number > self.number: > return self.HIGH > if number < self.number: > return self.LOW > return self.OK > > def test_guesstoolow(self): Nothing in this method tests any of the actual program > while not correct: > guess = input("What could it be?") > if guess == random_number: > print "Congrats You Got It" > correct = True > elif guess > random_number: > print "To High" > elif guess < random_number: > print "To Low" > else: > print "Try Again" [/code] > > Python code for game below > > [code] > import random > > intro = 'I have chosen a number from 1-10' > request = 'Guess a number: ' > responseHigh = "That's too high." > responseLow = "That's too low." > responseCorrect = "That's right!" > goodbye = 'Goodbye and thanks for playing!' > > print(intro) > > def main(): > guessesTaken = 0 > number = random.randint(1, 10) > while guessesTaken < 5: > print(request) > guess = input() > guess = int(guess) > > guessesTaken = guessesTaken + 1 > > if guess < number: > print(responseLow) > > if guess > number: > print(responseHigh) > > if guess == number: > break > > if guess == number: > guessesTaken = str(guessesTaken) > print(responseCorrect + '! You guessed my number in ' + guessesTaken + ' guesses!') > > if guess != number: > number = str(number) > print(goodbye + ' The number I was thinking of was ' + number) > > ##def main(): > # print(intro) > # user_input = raw_input(request) > # print(responseHigh) > # print(request) > # user_input = raw_input(request) > # print(responseLow) > # user_input = raw_input(request) > # print(responseCorrect) > # print(goodbye) > > if __name__ == '__main__': > main()[/code] According to https://en.wikipedia.org/wiki/Unit_testing: "...one can view a unit as the smallest testable part of an application" This is frequently a function, but certainly nothing smaller. So your program is too monolithic to write multiple unit tests for. You need to refactor your program to make it more testable. 1) have a way to eliminate the calls to random.randint(). 2) separate out the calculation from the input and output There has to be a better way to do this than pexpect. One way (probably still not the best) is to replace the print statement and the input calls with function calls to something that the test overrides. Now the question of what could you possibly do in 6 tests. Once the code has been refactored into several functions, one of those functions probably picks the original random number. So you can test that function by repeatedly calling it and making sure that every return value is a number within the specified range. A second test might be to make sure that you get exactly 5 wrong guesses. A third test might be to make sure that several pre-selected sequences of guesses elicit the right responses. So the test might be driven from a tuple consisting of the number, then a series of tuples where each of the subtuples is a guess and an expected response. A fourth test might be to stuff invalid data into the simulated input, and make sure the program behaves as expected. Probably throwing an exception like it does now isn't the expected behavior. I've run out of ideas. But several of these could be considered multiple tests anyway. -- DaveA From tjreedy at udel.edu Sat Sep 28 14:47:20 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 28 Sep 2013 14:47:20 -0400 Subject: Python Unit Tests In-Reply-To: References: Message-ID: On 9/28/2013 12:52 AM, melwin9 at gmail.com wrote: [How can I test...] > import random > > intro = 'I have chosen a number from 1-10' > request = 'Guess a number: ' > responseHigh = "That's too high." > responseLow = "That's too low." > responseCorrect = "That's right!" > goodbye = 'Goodbye and thanks for playing!' > > print(intro) > > def main(): > guessesTaken = 0 > number = random.randint(1, 10) > while guessesTaken < 5: > print(request) > guess = input() > guess = int(guess) > > guessesTaken = guessesTaken + 1 > > if guess < number: > print(responseLow) > > if guess > number: > print(responseHigh) > > if guess == number: > break > > if guess == number: > guessesTaken = str(guessesTaken) > print(responseCorrect + '! You guessed my number in ' + guessesTaken + ' guesses!') > > if guess != number: > number = str(number) > print(goodbye + ' The number I was thinking of was ' + number) > if __name__ == '__main__': > main() To expand on Dave's answer, I would refactor main() as below. Note 1. I add 'allowed' so you can easily change the number or let the user decide the difficulty. One can always guess right in at most 4 tries. Note 2. I am presuming that you are using 3.x. allowed = 5 def getguess(target, allowed): tries = 0 while tries < allowed: tries += 1 guess = int(input(request)) if guess < target: print(response_low) elif guess > target: print(response_high) else: return guess, tries def main(target) guess, tries = getguess(target, allowed) if guess == number: print(responseCorrect + '! You guessed my number in ' + tries + ' guesses!') else: print(goodbye + ' The number I was thinking of was ' + number) if __name__ == '__main__': main(random.randint(1, 10)) To test a function, you must be able to control inputs and access outputs. Unfortunately, this makes testing simple beginner programs that turn user input and random numbers input into screen output harder, in a way, than testing complicated math functions, such as one that approximates the derivative of a function as a point. One way to control user input for getguess is to put something like the following (untested) in your test module. (Ignore print for the moment.) class IntInput: "Replace input() that should return int as string." def __init__(self, ints, print=None) "Ints must be a sequence of ints" self.i = -1 # so 0 after first increment self.ints = ints self.print = print def input(prompt): "Maybe save prompt, return str(int)." if self.print: self.print(prompt) i = self.i + 1 self.i = i return str(self.ints[i]) In test methods, inject a mock input into the tested module with something like g.input = IntInput((5,3,2,1)).input where the sequence passed is appropriate for the target and the response you want. This will be sufficient to test most of the operation of getguess. (I am aware that some would say that IntInput should be a context manager with an exit method that restores g.input. I do not think that this complication is needed for this post.) To test the getguess prompts and main output, collect output lines with something like class Screen: def __init__(self): self.lines = [] def print(self, line): self.lines.append(line) screen = Screen() g.input = IntInput((5,3,2,1), screen.print).input # Test that screen.lines is as it should be. # Be careful that actual and expected both have # or both do not have terminal \n. For testing main, in test_xxx methods, screen = Screen g.print = screen.print # test screen.lines in Another approach is to replace sys.stdin/out as is done in test.support.capture_stdin/out, but the latter are considered internal functions not for general use, and this method seems more complicated. random and random.randint could be mocked, but this in not needed for this program with the randint call moved out of main(). --- Terry Jan Reedy From melwin9 at gmail.com Sun Sep 29 21:46:30 2013 From: melwin9 at gmail.com (melwin9 at gmail.com) Date: Sun, 29 Sep 2013 18:46:30 -0700 (PDT) Subject: Python Unit Tests In-Reply-To: References: Message-ID: <0dfb1b91-766c-47d5-9708-84b88838d247@googlegroups.com> Hi Terry & Dave, Thanks for the suggestions. I am running Python 2.7 and when I tried the code above it said def main(target) <- invalid syntax. I was told to use pexpect by my professor which is why I started to use that for the tests. As for the test suggestions, I will try to come up wit those tests with my current code but again idk how to do it in pexpect which was asked of me. On Saturday, September 28, 2013 2:47:20 PM UTC-4, Terry Reedy wrote: > On 9/28/2013 12:52 AM, mel wrote: > > [How can I test...] > > > > > import random > > > > > > intro = 'I have chosen a number from 1-10' > > > request = 'Guess a number: ' > > > responseHigh = "That's too high." > > > responseLow = "That's too low." > > > responseCorrect = "That's right!" > > > goodbye = 'Goodbye and thanks for playing!' > > > > > > print(intro) > > > > > > def main(): > > > guessesTaken = 0 > > > number = random.randint(1, 10) > > > while guessesTaken < 5: > > > print(request) > > > guess = input() > > > guess = int(guess) > > > > > > guessesTaken = guessesTaken + 1 > > > > > > if guess < number: > > > print(responseLow) > > > > > > if guess > number: > > > print(responseHigh) > > > > > > if guess == number: > > > break > > > > > > if guess == number: > > > guessesTaken = str(guessesTaken) > > > print(responseCorrect + '! You guessed my number in ' + guessesTaken + ' guesses!') > > > > > > if guess != number: > > > number = str(number) > > > print(goodbye + ' The number I was thinking of was ' + number) > > > > > if __name__ == '__main__': > > > main() > > > > To expand on Dave's answer, I would refactor main() as below. > > > > Note 1. I add 'allowed' so you can easily change the number or let the > > user decide the difficulty. One can always guess right in at most 4 tries. > > > > Note 2. I am presuming that you are using 3.x. > > > > allowed = 5 > > > > def getguess(target, allowed): > > tries = 0 > > while tries < allowed: > > tries += 1 > > guess = int(input(request)) > > if guess < target: > > print(response_low) > > elif guess > target: > > print(response_high) > > else: > > return guess, tries > > > > def main(target) > > guess, tries = getguess(target, allowed) > > if guess == number: > > print(responseCorrect + '! You guessed my number in ' + tries + ' > > guesses!') > > else: > > print(goodbye + ' The number I was thinking of was ' + number) > > > > if __name__ == '__main__': > > main(random.randint(1, 10)) > > > > To test a function, you must be able to control inputs and access > > outputs. Unfortunately, this makes testing simple beginner programs that > > turn user input and random numbers input into screen output harder, in a > > way, than testing complicated math functions, such as one that > > approximates the derivative of a function as a point. > > > > One way to control user input for getguess is to put something like the > > following (untested) in your test module. (Ignore print for the moment.) > > > > class IntInput: > > "Replace input() that should return int as string." > > def __init__(self, ints, print=None) > > "Ints must be a sequence of ints" > > self.i = -1 # so 0 after first increment > > self.ints = ints > > self.print = print > > def input(prompt): > > "Maybe save prompt, return str(int)." > > if self.print: > > self.print(prompt) > > i = self.i + 1 > > self.i = i > > return str(self.ints[i]) > > > > In test methods, inject a mock input into the tested module with > > something like > > g.input = IntInput((5,3,2,1)).input > > where the sequence passed is appropriate for the target and the response > > you want. This will be sufficient to test most of the operation of getguess. > > > > (I am aware that some would say that IntInput should be a context > > manager with an exit method that restores g.input. I do not think that > > this complication is needed for this post.) > > > > To test the getguess prompts and main output, collect output lines with > > something like > > > > class Screen: > > def __init__(self): > > self.lines = [] > > def print(self, line): > > self.lines.append(line) > > > > screen = Screen() > > g.input = IntInput((5,3,2,1), screen.print).input > > # Test that screen.lines is as it should be. > > # Be careful that actual and expected both have > > # or both do not have terminal \n. > > > > For testing main, in test_xxx methods, > > screen = Screen > > g.print = screen.print > > # test screen.lines in > > > > Another approach is to replace sys.stdin/out as is done in > > test.support.capture_stdin/out, but the latter are considered internal > > functions not for general use, and this method seems more complicated. > > > > random and random.randint could be mocked, but this in not needed for > > this program with the randint call moved out of main(). > > > > --- > > Terry Jan Reedy From steve at pearwood.info Sun Sep 29 22:55:19 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 30 Sep 2013 02:55:19 GMT Subject: Python Unit Tests References: <0dfb1b91-766c-47d5-9708-84b88838d247@googlegroups.com> Message-ID: <5248e816$0$2865$c3e8da3$76491128@news.astraweb.com> On Sun, 29 Sep 2013 18:46:30 -0700, melwin9 wrote: > Hi Terry & Dave, > > Thanks for the suggestions. I am running Python 2.7 and when I tried the > code above it said def main(target) <- invalid syntax. Did you fix the invalid syntax? Until you fix it, you're blocked. As a programmer, it is completely normal to occasionally make a typo or other trivial mistake that leads to invalid syntax. It's not worth mentioning. You just fix it and move on. It's a bit like being a cook. The recipe says, "add one tablespoon of sugar", and you say "well I tried, but the spoon bangs on the lid of the jar." The solution is to take the lid off first. The recipe doesn't mention this, just like the recipe doesn't say "take the spoon out of the cutlery drawer". You just do it. If you don't understand the syntax error you got, firstly try to compare the bad syntax def main(target) blah blah blah with working functions that don't give syntax errors def function(arg): blah blah blah Can you spot the difference? Hint: the syntax error will show an arrow ^ pointing at the spot where it notices a problem. Can you fix the problem? If so, great, move on! If not, ask for help, but remember to COPY AND PASTE the entire traceback, starting with the line Traceback (most recent call last) all the way to the end of the error message. -- Steven From melwin9 at gmail.com Mon Sep 30 00:19:26 2013 From: melwin9 at gmail.com (melwin9 at gmail.com) Date: Sun, 29 Sep 2013 21:19:26 -0700 (PDT) Subject: Python Unit Tests In-Reply-To: <5248e816$0$2865$c3e8da3$76491128@news.astraweb.com> References: <0dfb1b91-766c-47d5-9708-84b88838d247@googlegroups.com> <5248e816$0$2865$c3e8da3$76491128@news.astraweb.com> Message-ID: Hi Dave, Yeah I found the silly mistake lol thanks for that. making progress. Guess a number: 5 That's too high. Guess a number: 4 That's too high. Guess a number: 3 Traceback (most recent call last): File "guess.py", line 34, in main(random.randint(1, 10)) File "guess.py", line 29, in main print(responseCorrect + '! You guessed my number in ' + tries + 'guesses!') TypeError: cannot concatenate 'str' and 'int' objects [code]import random intro = 'I have chosen a number from 1-10' request = 'Guess a number: ' responseHigh = "That's too high." responseLow = "That's too low." responseCorrect = "That's correct!" responseWrong = "Wrong, The correct number is " guessTaken = "Your number of guesses were " goodbye = ' Goodbye and thanks for playing!' allowed = 5 def getguess(target, allowed): tries = 0 while tries < allowed: tries += 1 guess = int(input(request)) if guess < target: print(responseLow) elif guess > target: print(responseHigh) else: return guess, tries def main(target): guess, tries = getguess(target, allowed) if guess == target: print(responseCorrect + '! You guessed my number in ' + tries + 'guesses!') else: print(goodbye + ' The number I was thinking of was ' + number) if __name__ == '__main__': main(random.randint(1, 10)) [/code] On Sunday, September 29, 2013 10:55:19 PM UTC-4, Steven D'Aprano wrote: > On Sun, 29 Sep 2013 18:46:30 -0700, melwin9 wrote: > > > > > Hi Terry & Dave, > > > > > > Thanks for the suggestions. I am running Python 2.7 and when I tried the > > > code above it said def main(target) <- invalid syntax. > > > > > > Did you fix the invalid syntax? Until you fix it, you're blocked. > > > > As a programmer, it is completely normal to occasionally make a typo or > > other trivial mistake that leads to invalid syntax. It's not worth > > mentioning. You just fix it and move on. > > > > It's a bit like being a cook. The recipe says, "add one tablespoon of > > sugar", and you say "well I tried, but the spoon bangs on the lid of the > > jar." The solution is to take the lid off first. The recipe doesn't > > mention this, just like the recipe doesn't say "take the spoon out of the > > cutlery drawer". You just do it. > > > > If you don't understand the syntax error you got, firstly try to compare > > the bad syntax > > > > def main(target) > > blah blah blah > > > > > > with working functions that don't give syntax errors > > > > def function(arg): > > blah blah blah > > > > > > Can you spot the difference? Hint: the syntax error will show an arrow ^ > > pointing at the spot where it notices a problem. Can you fix the problem? > > If so, great, move on! If not, ask for help, but remember to COPY AND > > PASTE the entire traceback, starting with the line > > > > Traceback (most recent call last) > > > > all the way to the end of the error message. > > > > > > > > -- > > Steven From tjreedy at udel.edu Mon Sep 30 02:08:17 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 Sep 2013 02:08:17 -0400 Subject: Python Unit Tests In-Reply-To: References: <0dfb1b91-766c-47d5-9708-84b88838d247@googlegroups.com> <5248e816$0$2865$c3e8da3$76491128@news.astraweb.com> Message-ID: On 9/30/2013 12:19 AM, melwin9 at gmail.com wrote: > Hi Dave, > > Yeah I found the silly mistake lol thanks for that. making progress. > > > Guess a number: 5 > That's too high. > Guess a number: 4 > That's too high. > Guess a number: 3 > Traceback (most recent call last): > File "guess.py", line 34, in > main(random.randint(1, 10)) > File "guess.py", line 29, in main > print(responseCorrect + '! You guessed my number in ' + tries + 'guesses!') > TypeError: cannot concatenate 'str' and 'int' objects This is what 'untested' means ;-) > [code]import random > > intro = 'I have chosen a number from 1-10' > request = 'Guess a number: ' > responseHigh = "That's too high." > responseLow = "That's too low." > responseCorrect = "That's correct!" > responseWrong = "Wrong, The correct number is " > guessTaken = "Your number of guesses were " > goodbye = ' Goodbye and thanks for playing!' > > allowed = 5 > > def getguess(target, allowed): > tries = 0 > while tries < allowed: > tries += 1 > guess = int(input(request)) > if guess < target: > print(responseLow) > elif guess > target: > print(responseHigh) > else: > return guess, tries > > def main(target): > guess, tries = getguess(target, allowed) > if guess == target: > print(responseCorrect + '! You guessed my number in ' + tries + 'guesses!') Either change 'tries' to 'str(tries)' or replace the statement with print(responseCorrect, 'You guessed my number in', tries, 'guesses!') There is no need to create a single string before the print. > else: > print(goodbye + ' The number I was thinking of was ' + number) ditto > > if __name__ == '__main__': > main(random.randint(1, 10)) [/code] -- Terry Jan Reedy From melwin9 at gmail.com Mon Sep 30 15:54:08 2013 From: melwin9 at gmail.com (melwin9 at gmail.com) Date: Mon, 30 Sep 2013 12:54:08 -0700 (PDT) Subject: Python Unit Tests In-Reply-To: References: Message-ID: <64c1fa97-ace1-4fee-83b0-cf5fd7230e82@googlegroups.com> Lol, im starting to get the hang out of, onto the next hurdle, i looked up the error and it says the data is none? Traceback (most recent call last): File "guess.py", line 34, in main(random.randint(1, 10)) File "guess.py", line 27, in main guess, tries = getguess(target, allowed) TypeError: 'NoneType' object is not iterable On Saturday, September 28, 2013 12:52:26 AM UTC-4, mel... at gmail.com wrote: > Hey, > > > > How do i go about coming up/coding tests for this program below. Not sure how to even approach writing about 5 tests for it. > > > > Initially I had this for the test but its not working well. > > > > Test was name test_guess.py (Code Below) > > > > [code] > > from unittest import TestCase > > import pexpect as pe > > > > import guess as g > > import random > > > > random_number = random.randrange(1, 10) > > correct = False > > > > class GuessTest(TestCase): > > def setUp(self): > > self.intro = 'I have chosen a number from 1-10' > > self.request = 'Guess a number: ' > > self.responseHigh = "That's too high." > > self.responseLow = "That's too low." > > self.responseCorrect = "That's right!" > > self.goodbye = 'Goodbye and thanks for playing!' > > > > def test_main(self): > > #cannot execute main now because it will > > #require user input > > from guess import main > > > > def test_guessing_hi_low_4(self): > > # Conversation assuming number is 4 > > child = pe.spawn('python guess.py') > > child.expect(self.intro,timeout=5) > > child.expect(self.request,timeout=5) > > child.sendline('5') > > child.expect(self.responseHigh,timeout=5) > > child.sendline('3') > > child.expect(self.responseLow,timeout=5) > > child.sendline('4') > > child.expect(self.responseCorrect,timeout=5) > > child.expect(self.goodbye,timeout=5) > > > > > > def __init__(self): > > self.number = random.randint(0,10) > > HIGH = 1 > > LOW = 2 > > OK = 3 > > > > def guess(self, number): > > if number > self.number: > > return self.HIGH > > if number < self.number: > > return self.LOW > > return self.OK > > > > def test_guesstoolow(self): > > while not correct: > > guess = input("What could it be?") > > if guess == random_number: > > print "Congrats You Got It" > > correct = True > > elif guess > random_number: > > print "To High" > > elif guess < random_number: > > print "To Low" > > else: > > print "Try Again" [/code] > > > > Python code for game below > > > > [code] > > import random > > > > intro = 'I have chosen a number from 1-10' > > request = 'Guess a number: ' > > responseHigh = "That's too high." > > responseLow = "That's too low." > > responseCorrect = "That's right!" > > goodbye = 'Goodbye and thanks for playing!' > > > > print(intro) > > > > def main(): > > guessesTaken = 0 > > number = random.randint(1, 10) > > while guessesTaken < 5: > > print(request) > > guess = input() > > guess = int(guess) > > > > guessesTaken = guessesTaken + 1 > > > > if guess < number: > > print(responseLow) > > > > if guess > number: > > print(responseHigh) > > > > if guess == number: > > break > > > > if guess == number: > > guessesTaken = str(guessesTaken) > > print(responseCorrect + '! You guessed my number in ' + guessesTaken + ' guesses!') > > > > if guess != number: > > number = str(number) > > print(goodbye + ' The number I was thinking of was ' + number) > > > > ##def main(): > > # print(intro) > > # user_input = raw_input(request) > > # print(responseHigh) > > # print(request) > > # user_input = raw_input(request) > > # print(responseLow) > > # user_input = raw_input(request) > > # print(responseCorrect) > > # print(goodbye) > > > > if __name__ == '__main__': > > main()[/code] From python at mrabarnett.plus.com Mon Sep 30 16:08:16 2013 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 30 Sep 2013 21:08:16 +0100 Subject: Python Unit Tests In-Reply-To: <64c1fa97-ace1-4fee-83b0-cf5fd7230e82@googlegroups.com> References: <64c1fa97-ace1-4fee-83b0-cf5fd7230e82@googlegroups.com> Message-ID: <5249DA30.9090705@mrabarnett.plus.com> On 30/09/2013 20:54, melwin9 at gmail.com wrote: > Lol, im starting to get the hang out of, onto the next hurdle, i looked up the error and it says the data is none? > > Traceback (most recent call last): > File "guess.py", line 34, in > main(random.randint(1, 10)) > File "guess.py", line 27, in main > guess, tries = getguess(target, allowed) > TypeError: 'NoneType' object is not iterable > [snip] Look at 'getguess'. If the user guess correctly within the number of allowed attempts, the function returns (guess, tries), but what if the user runs out of attempts? From davea at davea.name Mon Sep 30 16:20:24 2013 From: davea at davea.name (Dave Angel) Date: Mon, 30 Sep 2013 20:20:24 +0000 (UTC) Subject: Python Unit Tests References: <64c1fa97-ace1-4fee-83b0-cf5fd7230e82@googlegroups.com> Message-ID: On 30/9/2013 15:54, melwin9 at gmail.com wrote: > Lol, im starting to get the hang out of, onto the next hurdle, i looked up the error and it says the data is none? > > Traceback (most recent call last): > File "guess.py", line 34, in > main(random.randint(1, 10)) > File "guess.py", line 27, in main > guess, tries = getguess(target, allowed) > TypeError: 'NoneType' object is not iterable > > Please don't top-post. Further, if you insist on using a buggy app like googlegroups, at least remove all the stupid double-spacing. Do you know how to interpret this error message? The line that fails is guess, tries = getguess(target, allowed) So can you tell what the None data is? You're doing a tuple-unpack on the left side of the equals, so the right side needs to be a tuple, list, or equivalent. In specific, an iterable. Now you reread the error, and realize that the getguess() function is returning None. If I were a novice, I'd start by splitting up the line with the error: temp = getguess(target, allowed) guess, tries = temp Then when the error complains about the second line, I'd add a print statement: temp = getguess(target, allowed) print(repr(temp)) guess, tries = temp Lacking the source code, I'm going to guess that some path through your code is missing a return expression. For example, you might have def getguess(a, b): if a < b: return a, a*b So it'll return a tuple of two items in the if body, but without an else clause, it simply falls off the end, and returns None. (All functions return something, so if you don't provide a value, None is used) -- DaveA From tjreedy at udel.edu Mon Sep 30 20:06:26 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 Sep 2013 20:06:26 -0400 Subject: Python Unit Tests In-Reply-To: <64c1fa97-ace1-4fee-83b0-cf5fd7230e82@googlegroups.com> References: <64c1fa97-ace1-4fee-83b0-cf5fd7230e82@googlegroups.com> Message-ID: On 9/30/2013 3:54 PM, melwin9 at gmail.com wrote: > Lol, im starting to get the hang out of, onto the next hurdle, i looked up the error and it says the data is none? > > Traceback (most recent call last): > File "guess.py", line 34, in > main(random.randint(1, 10)) > File "guess.py", line 27, in main > guess, tries = getguess(target, allowed) > TypeError: 'NoneType' object is not iterable If you have not figured it out yet, add a copy of the return within the while loop, return guess, tries after the while loop also, so it does not return the default of None. -- Terry Jan Reedy From daniel.stjnv at gmail.com Sat Sep 28 02:26:24 2013 From: daniel.stjnv at gmail.com (Daniel Stojanov) Date: Sat, 28 Sep 2013 16:26:24 +1000 Subject: Weird bahaviour from shlex - line no Message-ID: Can somebody explain this. The line number reported by shlex depends on the previous token. I want to be able to tell if I have just popped the last token on a line. import shlex first = shlex.shlex("word1 word2\nword3") print first.get_token() print first.get_token() print "line no", first.lineno, "\n" second = shlex.shlex("word1 word2,\nword3") print second.get_token() print second.get_token() print second.get_token() print "line no", second.lineno, "\n" OUTPUT: word1 word2 line no 2 word1 word2 , line no 1 From andipersti at gmail.com Sat Sep 28 07:02:37 2013 From: andipersti at gmail.com (Andreas Perstinger) Date: Sat, 28 Sep 2013 13:02:37 +0200 Subject: Weird bahaviour from shlex - line no In-Reply-To: References: Message-ID: <5246B74D.1010802@gmail.com> On 28.09.2013 08:26, Daniel Stojanov wrote: > Can somebody explain this. The line number reported by shlex depends > on the previous token. I want to be able to tell if I have just popped > the last token on a line. > [SNIP] > > second = shlex.shlex("word1 word2,\nword3") Punctuation characters like the comma are not considered as word characters by default and thus are seen as different tokens (consisting of only a single character): >>> lexer = shlex.shlex("foo, bar, ...") >>> token = lexer.get_token() >>> while token != lexer.eof: ... print token ... token = lexer.get_token() ... foo , bar , . . . If you want to treat them as "word" characters you need to add them to the string "wordchars" (a public attribute of the "shlex" instance): >>> lexer = shlex.shlex("foo.bar, baz") >>> lexer.wordchar += '.,' >>> print lexer.get_token() foo.bar, >>> print lexer.get_token() baz There is also a "debug" attribute (with three different levels: 1, 2, 3; default value 0 means no debug output): >>> lexer = shlex.shlex("foo, bar, ...") >>> lexer.debug = 1 >>> print lexer.get_token() shlex: token='foo' foo >>> print lexer.get_token() shlex: popping token ',' , Bye, Andreas From davea at davea.name Sat Sep 28 09:29:19 2013 From: davea at davea.name (Dave Angel) Date: Sat, 28 Sep 2013 13:29:19 +0000 (UTC) Subject: Weird bahaviour from shlex - line no References: Message-ID: On 28/9/2013 02:26, Daniel Stojanov wrote: > Can somebody explain this. The line number reported by shlex depends > on the previous token. I want to be able to tell if I have just popped > the last token on a line. > I agree that it seems weird. However, I don't think you have made clear why it's not what you (and I) expect. import shlex def parseit(string): print print "Parsing -", string first = shlex.shlex(string) token = "dummy" while token: token = first.get_token() print token, " -- line", first.lineno parseit("word1 word2\nword3") #first parseit("word1 word2,\nword3") #second parseit("word1 word2,word3\nword4") parseit("word1 word2+,?\nword3") This will display the lineno attribute for every token. shlex is documented at: http://docs.python.org/2/library/shlex.html And lineno is documented on that page as: """shlex.lineno Source line number (count of newlines seen so far plus one). """ It's not at all clear what "seen so far" is intended to mean, but in practice, the line number is incremented for the last token on the line. Thus your first example Parsing - word1 word2 word3 word1 -- line 1 word2 -- line 2 word3 -- line 2 -- line 2 word2 has the incremented line number. But when the token is neither whitespace nor ASCII letters, then it doesn't increment lineno. Thus second example: Parsing - word1 word2, word3 word1 -- line 1 word2 -- line 1 , -- line 1 #we would expect this to be "line 2" word3 -- line 2 -- line 2 Anybody else have some explanation or advice for Daniel, other than preprocessing the string by stripping any non letters off the end of the line? -- DaveA From __peter__ at web.de Sat Sep 28 10:52:34 2013 From: __peter__ at web.de (Peter Otten) Date: Sat, 28 Sep 2013 16:52:34 +0200 Subject: Weird bahaviour from shlex - line no References: Message-ID: Dave Angel wrote: > On 28/9/2013 02:26, Daniel Stojanov wrote: > >> Can somebody explain this. The line number reported by shlex depends >> on the previous token. I want to be able to tell if I have just popped >> the last token on a line. >> > > I agree that it seems weird. However, I don't think you have made > clear why it's not what you (and I) expect. > > import shlex > > def parseit(string): > print > print "Parsing -", string > first = shlex.shlex(string) > token = "dummy" > while token: > token = first.get_token() > print token, " -- line", first.lineno > > parseit("word1 word2\nword3") #first > parseit("word1 word2,\nword3") #second > parseit("word1 word2,word3\nword4") > parseit("word1 word2+,?\nword3") > > This will display the lineno attribute for every token. > > shlex is documented at: > > http://docs.python.org/2/library/shlex.html > > And lineno is documented on that page as: > > """shlex.lineno > Source line number (count of newlines seen so far plus one). > """ > > It's not at all clear what "seen so far" is intended to mean, but in > practice, the line number is incremented for the last token on the > line. Thus your first example > > Parsing - word1 word2 > word3 > word1 -- line 1 > word2 -- line 2 > word3 -- line 2 > -- line 2 > > word2 has the incremented line number. > > But when the token is neither whitespace nor ASCII letters, then it > doesn't increment lineno. Thus second example: > > Parsing - word1 word2, > word3 > word1 -- line 1 > word2 -- line 1 > , -- line 1 #we would expect this to be "line 2" > word3 -- line 2 -- line 2 > > Anybody else have some explanation The explanation seems obvious: a word may be continued by the next character if that is in wordchars, so the parser has to look at that character. If it happens to be '\n' the lineno is immediately incremented. Non-wordchars are returned as single characters, so there is no need to peek ahead and the lineno is not altered. In short: this looks like an implementation accident. OP: I don't see a usecase for the current behaviour -- I suggest that you file a bug report. > or advice for Daniel, other than > preprocessing the string by stripping any non letters off the end of the > line? The following gives the tokens' starting line for your examples def shlexiter(s): p = shlex.shlex(s) p.whitespace = p.whitespace.replace("\n", "") while True: lineno = p.lineno token = p.get_token() if not token: break if token == "\n": continue yield lineno, token def parseit(string): print("Parsing - {!r}".format(string)) for lineno, token in shlexiter(string): print("{:3} {!r}".format(lineno, token)) print("") but I have no idea about the implications for more complex input. From piet at vanoostrum.org Sat Sep 28 16:59:58 2013 From: piet at vanoostrum.org (Piet van Oostrum) Date: Sat, 28 Sep 2013 16:59:58 -0400 Subject: Weird bahaviour from shlex - line no References: Message-ID: Peter Otten <__peter__ at web.de> writes: > Dave Angel wrote: > >> On 28/9/2013 02:26, Daniel Stojanov wrote: >> >>> Can somebody explain this. The line number reported by shlex depends >>> on the previous token. I want to be able to tell if I have just popped >>> the last token on a line. [...] > The explanation seems obvious: a word may be continued by the next character > if that is in wordchars, so the parser has to look at that character. If it > happens to be '\n' the lineno is immediately incremented. Non-wordchars are > returned as single characters, so there is no need to peek ahead and the > lineno is not altered. > > In short: this looks like an implementation accident. I think shlex should be changed to give the line number of the start of the token in self.lineno. It isn't hard. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From g.rodola at gmail.com Sat Sep 28 07:00:41 2013 From: g.rodola at gmail.com (Giampaolo Rodola') Date: Sat, 28 Sep 2013 13:00:41 +0200 Subject: ANN: psutil 1.1.0 released Message-ID: Hi there folks, I'm pleased to announce the 1.1.0 release of psutil: http://code.google.com/p/psutil/ === About === psutil is a module providing an interface for retrieving information on all running processes and system utilization (CPU, memory, disks, network, users) in a portable way by using Python, implementing many functionalities offered by command line tools such as ps, top, free, netstat, lsof and others. It supports Linux, Windows, OSX, FreeBSD and Solaris with Python versions from 2.4 to 3.4. === New features === The main addition included in this new release is the possibility to set process resource limits on Linux (see "man prlimit"). This functionality is similar to what you can already do with stdlib resource module (http://docs.python.org/2/library/resource.html) but it is extended to all processes. For example, you might limit the number of files which may be opened by a process: >>> p = psutil.Process(pid) >>> p.set_rlimit(psutil.RLIMIT_NOFILE, (128, 128)) >>> files = [] >>> for x in range(200): ... files.append(open('/tmp/foo')) ... Traceback (most recent call last): File "", line 2, in IOError: [Errno 24] Too many open files: '/tmp/foo' ...or the maximum size of files that the process may create: >>> p.set_rlimit(psutil.RLIMIT_FSIZE, (1024, 1024)) >>> f = open('/tmp/foo', 'w') >>> f.write('x' * 1024) >>> f.flush() >>> f.write('x') >>> f.flush() Traceback (most recent call last): File "", line 1, in IOError: [Errno 27] File too large >>> === Main bugfixes === * Process.as_dict() return value couldn't be serialized to JSON. * [Windows] fixed a pretty serious memory leak in Process.get_memory_info(). * [Windows] Process get_children() and "name" property are an order of magnitude faster. === Other changes === * STATUS_* and CONN_* constants (returned by Process' status() and get_connections() methods respectively) have been turned from constant objects to plain Python strings. * source and Windows binary files are now hosted on PyPi Complete list of bugfixes and enhancements is here: https://psutil.googlecode.com/hg/HISTORY === Links === * Home page: http://code.google.com/p/psutil * Downloads: https://pypi.python.org/pypi?:action=display&name=psutil#downloads * API Reference: http://code.google.com/p/psutil/wiki/Documentation Please try out this new release and let me know if you experience any problem by filing issues on the bug tracker. All the best, --- Giampaolo Rodola' http://code.google.com/p/pyftpdlib/ http://code.google.com/p/psutil/ http://code.google.com/p/pysendfile/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From lilithsolved at gmail.com Sat Sep 28 10:55:54 2013 From: lilithsolved at gmail.com (FiveHydroxy Tryptamine) Date: Sat, 28 Sep 2013 07:55:54 -0700 (PDT) Subject: Neurolab // "No module named .." Message-ID: Hiya A word of warning, I am a complete beginner. My problem goes like this:: I've been trying to "import neurolab as nl"(a neural network library)and I keep getting the "No module named.." error in my Python 2.7.3 shell. There is definitely something wrong with my Python path, although everything looks fine (to me). I also appended the sys.path with "C:/Python27/neurolab-0.2.3/neurolab" and I still get that error. What am I missing? Thanks. From joel.goldstick at gmail.com Sat Sep 28 12:04:30 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sat, 28 Sep 2013 12:04:30 -0400 Subject: Neurolab // "No module named .." In-Reply-To: References: Message-ID: On Sat, Sep 28, 2013 at 10:55 AM, FiveHydroxy Tryptamine < lilithsolved at gmail.com> wrote: > Hiya > A word of warning, I am a complete beginner. > My problem goes like this:: I've been trying to "import neurolab as nl"(a > neural network library)and I keep getting the "No module named.." error in > my Python 2.7.3 shell. There is definitely something wrong with my Python > path, although everything looks fine (to me). I also appended the sys.path > with "C:/Python27/neurolab-0.2.3/neurolab" and I still get that error. What > am I missing? > Thanks. > -- > https://mail.python.org/mailman/listinfo/python-list > How exactly did you install python? And how did you install neurolab? Also, its best to actually cut and paste the traceback rather than paraphrase it. Since you don't know what is wrong, you may not be providing the information necessary to solve the problem -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at davea.name Sat Sep 28 12:23:51 2013 From: davea at davea.name (Dave Angel) Date: Sat, 28 Sep 2013 16:23:51 +0000 (UTC) Subject: Neurolab // "No module named .." References: Message-ID: On 28/9/2013 10:55, FiveHydroxy Tryptamine wrote: > Hiya > A word of warning, I am a complete beginner. > My problem goes like this:: I've been trying to "import neurolab as nl"(a neural network library)and I keep getting the "No module named.." error in my Python 2.7.3 shell. There is definitely something wrong with my Python path, although everything looks fine (to me). I also appended the sys.path with "C:/Python27/neurolab-0.2.3/neurolab" and I still get that error. What am I missing? > Thanks. Welcome to the forum, and to Python. First point: when you have a problem, especially an import problem, in some (unnamed) shell, make sure the same symptoms happen at a command line or the Python interpreter, whichever is appropriate. If the problem only occurs in the shell, it's a shell problem, or probably a configuration one. Second point: Include the source file you use, hopefully stripped to the essential minimum. Third point: include a transcript of all, or the significant portions of the session (using cut and paste, not paraphrasing). The error (exception) message is a minimum of 3 lines long, You show part of the last line. The full error message starts with "Traceback" and ends with some textual summary error message. Fourth: indicate how you may have customized your system. At a minimum, you must think you installed the neurolab module. Whatever that is, whereever you found it. You should supply the link. But perhaps you downloaded it and copied it, without actually running any install program. The directory you specify is NOT the conventional place for foreign modules. For example: davea at think2:~/temppython$ python Python 2.7.3 (default, Apr 10 2013, 06:20:15) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import unknown Traceback (most recent call last): File "", line 1, in ImportError: No module named unknown >>> -- DaveA From tjreedy at udel.edu Sat Sep 28 14:58:22 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 28 Sep 2013 14:58:22 -0400 Subject: Neurolab // "No module named .." In-Reply-To: References: Message-ID: On 9/28/2013 10:55 AM, FiveHydroxy Tryptamine wrote: > Hiya A word of warning, I am a complete beginner. My problem goes > like this:: I've been trying to "import neurolab as nl"(a neural > network library)and I keep getting the "No module named.." error in > my Python 2.7.3 shell. There is definitely something wrong with my > Python path, although everything looks fine (to me). I also appended > the sys.path with "C:/Python27/neurolab-0.2.3/neurolab" and I still > get that error. What am I missing? Thanks. Perhaps that sys.path should contain directory paths but not module paths. I suspect that "C:/Python27/neurolab-0.2.3" is the directory you should append. Import will then find the neurolab module it contains. -- Terry Jan Reedy From breamoreboy at yahoo.co.uk Sat Sep 28 15:06:51 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 28 Sep 2013 20:06:51 +0100 Subject: Neurolab // "No module named .." In-Reply-To: References: Message-ID: On 28/09/2013 15:55, FiveHydroxy Tryptamine wrote: > Hiya > A word of warning, I am a complete beginner. > My problem goes like this:: I've been trying to "import neurolab as nl"(a neural network library)and I keep getting the "No module named.." error in my Python 2.7.3 shell. There is definitely something wrong with my Python path, although everything looks fine (to me). I also appended the sys.path with "C:/Python27/neurolab-0.2.3/neurolab" and I still get that error. What am I missing? > Thanks. > Are you sure that path is correct? I'd expect to see something like "C:/Python27/lib/site-packages/neurolab-0.2.3/neurolab" -- Cheers. Mark Lawrence From python at mrabarnett.plus.com Sat Sep 28 15:45:24 2013 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 28 Sep 2013 20:45:24 +0100 Subject: Neurolab // "No module named .." In-Reply-To: References: Message-ID: <524731D4.8060908@mrabarnett.plus.com> On 28/09/2013 20:06, Mark Lawrence wrote: > On 28/09/2013 15:55, FiveHydroxy Tryptamine wrote: >> Hiya >> A word of warning, I am a complete beginner. >> My problem goes like this:: I've been trying to "import neurolab as nl"(a neural network library)and I keep getting the "No module named.." error in my Python 2.7.3 shell. There is definitely something wrong with my Python path, although everything looks fine (to me). I also appended the sys.path with "C:/Python27/neurolab-0.2.3/neurolab" and I still get that error. What am I missing? >> Thanks. >> > > Are you sure that path is correct? I'd expect to see something like > "C:/Python27/lib/site-packages/neurolab-0.2.3/neurolab" > +1 That's very true. If it's meant to be in the Python folder, then I'd expected it to be in the "Lib\site-packages" subfolder. From ron.eggler at gmail.com Sat Sep 28 12:11:18 2013 From: ron.eggler at gmail.com (cerr) Date: Sat, 28 Sep 2013 09:11:18 -0700 (PDT) Subject: replace only full words Message-ID: Hi, I have a list of sentences and a list of words. Every full word that appears within sentence shall be extended by i.e. "I drink in the house." Would become "I in the ." (and not "I in the .")I have attempted it like this: for sentence in sentences: for noun in nouns: if " "+noun+" " in sentence or " "+noun+"?" in sentence or " "+noun+"!" in sentence or " "+noun+"." in sentence: sentence = sentence.replace(noun, '<' + noun + '>') print(sentence) but what if The word is in the beginning of a sentence and I also don't like the approach using defined word terminations. Also, is there a way to make it faster? Thanks From python.list at tim.thechases.com Sat Sep 28 12:54:35 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 28 Sep 2013 11:54:35 -0500 Subject: replace only full words In-Reply-To: References: Message-ID: <20130928115435.67554a11@bigbox.christie.dr> On 2013-09-28 09:11, cerr wrote: > I have a list of sentences and a list of words. Every full word > that appears within sentence shall be extended by i.e. "I > drink in the house." Would become "I in the ." (and > not "I in the .") This is a good place to reach for regular expressions. It comes with a "ensure there is a word-boundary here" token, so you can do something like the code at the (way) bottom of this email. I've pushed it off the bottom in the event you want to try and use regexps on your own first. Or if this is homework, at least make you work a *little* :-) > Also, is there a way to make it faster? The code below should do the processing in roughly O(n) time as it only makes one pass through the data and does O(1) lookups into your set of nouns. I included code in the regexp to roughly find contractions and hyphenated words. Your original code grows slower as your list of nouns grows bigger and also suffers from multiple-replacement issues (if you have the noun-list of ["drink", "rink"], you'll get results that you don't likely want. My code hasn't considered case differences, but you should be able to normalize both the list of nouns and the word you're testing in the "modify()" function so that it would find "Drink" as well as "drink" Also, note that some words serve both as nouns and other parts of speech, e.g. "It's kind of you to house me for the weekend and drink tea with me." -tkc import re r = re.compile(r""" \b # assert a word boundary \w+ # 1+ word characters (?: # a group [-'] # a dash or apostrophe \w+ # followed by 1+ word characters )? # make the group optional (0 or 1 instances) \b # assert a word boundary here """, re.VERBOSE) nouns = set([ "drink", "house", ]) def modify(matchobj): word = matchobj.group(0) if word in nouns: return "<%s>" % word else: return word print r.sub(modify, "I drink in the house") From python at mrabarnett.plus.com Sat Sep 28 13:00:29 2013 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 28 Sep 2013 18:00:29 +0100 Subject: replace only full words In-Reply-To: References: Message-ID: <52470B2D.5030205@mrabarnett.plus.com> On 28/09/2013 17:11, cerr wrote: > Hi, > > I have a list of sentences and a list of words. Every full word that appears within sentence shall be extended by i.e. "I drink in the house." Would become "I in the ." (and not "I in the .")I have attempted it like this: > for sentence in sentences: > for noun in nouns: > if " "+noun+" " in sentence or " "+noun+"?" in sentence or " "+noun+"!" in sentence or " "+noun+"." in sentence: > sentence = sentence.replace(noun, '<' + noun + '>') > > print(sentence) > > but what if The word is in the beginning of a sentence and I also don't like the approach using defined word terminations. Also, is there a way to make it faster? > It sounds like a regex problem to me: import re nouns = ["drink", "house"] pattern = re.compile(r"\b(" + "|".join(nouns) + r")\b") for sentence in sentences: sentence = pattern.sub(r"<\g<0>>", sentence) print(sentence) From jpiitula at ling.helsinki.fi Sat Sep 28 13:37:49 2013 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 28 Sep 2013 20:37:49 +0300 Subject: replace only full words References: Message-ID: MRAB writes: > On 28/09/2013 17:11, cerr wrote: > > Hi, > > > > I have a list of sentences and a list of words. Every full word > > that appears within sentence shall be extended by i.e. "I > > drink in the house." Would become "I in the ." (and > > not "I in the .")I have attempted it like this: > > > for sentence in sentences: > > for noun in nouns: > > if " "+noun+" " in sentence or " "+noun+"?" in sentence or " "+noun+"!" in sentence or " "+noun+"." in sentence: > > sentence = sentence.replace(noun, '<' + noun + '>') > > > > print(sentence) > > > > but what if The word is in the beginning of a sentence and I also > > don't like the approach using defined word terminations. Also, is > > there a way to make it faster? > > > It sounds like a regex problem to me: > > import re > > nouns = ["drink", "house"] > > pattern = re.compile(r"\b(" + "|".join(nouns) + r")\b") > > for sentence in sentences: > sentence = pattern.sub(r"<\g<0>>", sentence) > print(sentence) Maybe tokenize by a regex and then join the replacements of all tokens: import re def substitute(token): if isfullword(token.lower()): return '<{}>'.format(token) else: return token def tokenize(sentence): return re.split(r'(\W)', sentence) sentence = 'This is, like, a test.' tokens = map(substitute, tokenize(sentence)) sentence = ''.join(tokens) For better results, both tokenization and substitution need to depend on context. Doing some of that should be an interesting exercise. From ron.eggler at gmail.com Sat Sep 28 13:43:33 2013 From: ron.eggler at gmail.com (cerr) Date: Sat, 28 Sep 2013 10:43:33 -0700 (PDT) Subject: replace only full words In-Reply-To: References: Message-ID: On Saturday, September 28, 2013 4:54:35 PM UTC, Tim Chase wrote: > On 2013-09-28 09:11, cerr wrote: > > > I have a list of sentences and a list of words. Every full word > > > that appears within sentence shall be extended by i.e. "I > > > drink in the house." Would become "I in the ." (and > > > not "I in the .") > > > > This is a good place to reach for regular expressions. It comes with > > a "ensure there is a word-boundary here" token, so you can do > > something like the code at the (way) bottom of this email. I've > > pushed it off the bottom in the event you want to try and use regexps > > on your own first. Or if this is homework, at least make you work a > > *little* :-) > > > > > Also, is there a way to make it faster? > > > > The code below should do the processing in roughly O(n) time as it > > only makes one pass through the data and does O(1) lookups into your > > set of nouns. I included code in the regexp to roughly find > > contractions and hyphenated words. Your original code grows slower > > as your list of nouns grows bigger and also suffers from > > multiple-replacement issues (if you have the noun-list of ["drink", > > "rink"], you'll get results that you don't likely want. > > > > My code hasn't considered case differences, but you should be able to > > normalize both the list of nouns and the word you're testing in the > > "modify()" function so that it would find "Drink" as well as "drink" > > > > Also, note that some words serve both as nouns and other parts of > > speech, e.g. "It's kind of you to house me for the weekend and drink > > tea with me." > > > > -tkc > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > import re > > > > r = re.compile(r""" > > \b # assert a word boundary > > \w+ # 1+ word characters > > (?: # a group > > [-'] # a dash or apostrophe > > \w+ # followed by 1+ word characters > > )? # make the group optional (0 or 1 instances) > > \b # assert a word boundary here > > """, re.VERBOSE) > > > > nouns = set([ > > "drink", > > "house", > > ]) > > > > def modify(matchobj): > > word = matchobj.group(0) > > if word in nouns: > > return "<%s>" % word > > else: > > return word > > > > print r.sub(modify, "I drink in the house") Great, only I don't have the re module on my system.... :( From python at mrabarnett.plus.com Sat Sep 28 14:07:11 2013 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 28 Sep 2013 19:07:11 +0100 Subject: replace only full words In-Reply-To: References: Message-ID: <52471ACF.3040104@mrabarnett.plus.com> On 28/09/2013 18:43, cerr wrote: [snip] > Great, only I don't have the re module on my system.... :( > Really? It's part of Python's standard distribution. From python.list at tim.thechases.com Sat Sep 28 14:17:19 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 28 Sep 2013 13:17:19 -0500 Subject: replace only full words In-Reply-To: References: Message-ID: <20130928131719.4c81d688@bigbox.christie.dr> [mercy, you could have trimmed down that reply] On 2013-09-28 10:43, cerr wrote: > On Saturday, September 28, 2013 4:54:35 PM UTC, Tim Chase wrote: >> import re > > Great, only I don't have the re module on my system.... :( Um, it's a standard Python library. You sure about that? http://docs.python.org/2/library/re.html -tkc From ron.eggler at gmail.com Sat Sep 28 14:25:15 2013 From: ron.eggler at gmail.com (cerr) Date: Sat, 28 Sep 2013 11:25:15 -0700 (PDT) Subject: replace only full words In-Reply-To: References: Message-ID: <59a2f7d2-0966-4406-83c7-9cf8af563893@googlegroups.com> On Saturday, September 28, 2013 11:07:11 AM UTC-7, MRAB wrote: > On 28/09/2013 18:43, cerr wrote: > > [snip] > > > Great, only I don't have the re module on my system.... :( > > > > > Really? It's part of Python's standard distribution. Oh no, sorry, mis-nformation, i DO have module re available!!! All good! From ron.eggler at gmail.com Sat Sep 28 14:25:55 2013 From: ron.eggler at gmail.com (cerr) Date: Sat, 28 Sep 2013 11:25:55 -0700 (PDT) Subject: replace only full words In-Reply-To: References: Message-ID: On Saturday, September 28, 2013 11:17:19 AM UTC-7, Tim Chase wrote: > [mercy, you could have trimmed down that reply] > > > > On 2013-09-28 10:43, cerr wrote: > > > On Saturday, September 28, 2013 4:54:35 PM UTC, Tim Chase wrote: > > >> import re > > > > > > Great, only I don't have the re module on my system.... :( > > > > Um, it's a standard Python library. You sure about that? > > > > http://docs.python.org/2/library/re.html > Oh no, sorry, mis-nformation, i DO have module re available!!! All good! From harry.andrei at gmail.com Sat Sep 28 12:20:21 2013 From: harry.andrei at gmail.com (harry.andrei at gmail.com) Date: Sat, 28 Sep 2013 09:20:21 -0700 (PDT) Subject: Which Python Framework for REST API and Facebook Wrapper? Message-ID: I will be designing a REST based API for a cross-platform back end that will serve both desktop Facebook users as well as mobile users. It will handle operations such as user creation, retrieval of user and other data, payment verification and in the case of the desktop side, handle the html/css template customization. The database back end is MySQL and I do need a cache system. Currently we were using Codeigniter (PHP) for our codebase but as CI seems on the way out, I do not wish to start a new project based on it. I was looking at Laravel for PHP, but, Python is very attractive to me as a language and since the introduction of WSGI, I am confident it can make a difference in performance and code maintainability over PHP while being able to plug in to our dedicated server infrastructure. Since I am not experienced with Python frameworks (though learning curve is not much of an issue for me) I look to the community to understand which Python framework can rival or surpass Codeigniter in terms of performance in heavy traffic backend solutions (over 1M requests per day, with up to 100 req/sec at peak). I really want to make the switch from PHP to Python as I believe that Python can solve more problems with less code and faster execution time, not to mention freedom from brackets and semicolons. From joel.goldstick at gmail.com Sat Sep 28 12:35:08 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sat, 28 Sep 2013 12:35:08 -0400 Subject: Which Python Framework for REST API and Facebook Wrapper? In-Reply-To: References: Message-ID: On Sat, Sep 28, 2013 at 12:20 PM, wrote: > I will be designing a REST based API for a cross-platform back end that > will serve both desktop Facebook users as well as mobile users. It will > handle operations such as user creation, retrieval of user and other data, > payment verification and in the case of the desktop side, handle the > html/css template customization. The database back end is MySQL and I do > need a cache system. > > Currently we were using Codeigniter (PHP) for our codebase but as CI seems > on the way out, I do not wish to start a new project based on it. I was > looking at Laravel for PHP, but, Python is very attractive to me as a > language and since the introduction of WSGI, I am confident it can make a > difference in performance and code maintainability over PHP while being > able to plug in to our dedicated server infrastructure. > > Since I am not experienced with Python frameworks (though learning curve > is not much of an issue for me) I look to the community to understand which > Python framework can rival or surpass Codeigniter in terms of performance > in heavy traffic backend solutions (over 1M requests per day, with up to > 100 req/sec at peak). I really want to make the switch from PHP to Python > as I believe that Python can solve more problems with less code and faster > execution time, not to mention freedom from brackets and semicolons. > -- > https://mail.python.org/mailman/listinfo/python-list > While there several others with smaller footprint, django is probably the elephant in the room -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From waynejwerner at gmail.com Mon Sep 30 15:24:35 2013 From: waynejwerner at gmail.com (waynejwerner at gmail.com) Date: Mon, 30 Sep 2013 12:24:35 -0700 (PDT) Subject: Which Python Framework for REST API and Facebook Wrapper? In-Reply-To: References: Message-ID: <0780a1b5-3e72-4f90-bcba-87e0c6f539b6@googlegroups.com> On Saturday, September 28, 2013 11:20:21 AM UTC-5, harry.... at gmail.com wrote: > I will be designing a REST based API for a cross-platform back end that will serve both desktop Facebook users as well as mobile users. It will handle operations such as user creation, retrieval of user and other data, payment verification and in the case of the desktop side, handle the html/css template customization. The database back end is MySQL and I do need a cache system. > > > > Currently we were using Codeigniter (PHP) for our codebase but as CI seems on the way out, I do not wish to start a new project based on it. I was looking at Laravel for PHP, but, Python is very attractive to me as a language and since the introduction of WSGI, I am confident it can make a difference in performance and code maintainability over PHP while being able to plug in to our dedicated server infrastructure. > > > > Since I am not experienced with Python frameworks (though learning curve is not much of an issue for me) I look to the community to understand which Python framework can rival or surpass Codeigniter in terms of performance in heavy traffic backend solutions (over 1M requests per day, with up to 100 req/sec at peak). I really want to make the switch from PHP to Python as I believe that Python can solve more problems with less code and faster execution time, not to mention freedom from brackets and semicolons. If you're looking for something simple, there are solutions like Flask (my favourite), CherryPy, Bottle, and web2py. (I only know the names of the last 3) I recommend taking a look into the likes of Flask, if only to familiarize yourself with some of the techniques of Python frameworks. Here's a basic Flask app: from flask import Flask app = Flask(__name__) @app.route('/') def main(): return "Hey, I'm in a Flask!" if __name__ == "__main__": app.run('0.0.0.0', port=5000, debug=True) If you're looking for performance, Tornado (http://www.tornadoweb.org/en/stable/) I've heard is pretty awesome - though I've not put it through the paces myself. HTH, -W From skunkwerk at gmail.com Sat Sep 28 13:12:48 2013 From: skunkwerk at gmail.com (skunkwerk) Date: Sat, 28 Sep 2013 10:12:48 -0700 (PDT) Subject: automated unit test generation Message-ID: <2d5fdac0-5145-428b-908e-98be65ba7bab@googlegroups.com> Hi, I've been working on an open source project to auto-generate unit tests for web apps based on traces collected from the web server and static code analysis. I've got an alpha version online at www.splintera.com, and the source is at https://github.com/splintera/python-django-client. I'd love to get some feedback from the community and extend it to work with other languages as well. I wrote it originally because I was sick of coming into companies where I had to inherit tens of thousands of lines of code without any tests, and never had time to write them manually - being careful to mock out dependencies, specify the correct inputs and outputs, and figure out which path it was taking through the code. I'd like to get some sense of: - how difficult/tedious is writing unit tests, and why? - do you wish you had better code coverage? - how important is testing to you? thanks, imran From no.email at nospam.invalid Sat Sep 28 14:07:01 2013 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 28 Sep 2013 11:07:01 -0700 Subject: automated unit test generation References: <2d5fdac0-5145-428b-908e-98be65ba7bab@googlegroups.com> Message-ID: <7x4n94vn0a.fsf@ruckus.brouhaha.com> skunkwerk writes: > - how difficult/tedious is writing unit tests, and why? The important thing is to write the tests at the same time as the code. If you do that, it's not too bad. It means the code is then organized around the tests and vice versa. Keeping tests in sync with changes to code can be annoying and it's easy to let that slip under schedule pressure. After that happens enough, you've got a non-TDD program. Writing tests for code that's already been written without automated testing in mind is much more difficult and tedious. Automatically generating tests for already-written code also seems dubious. Also, unit tests themselves are fairly easy, but often you also have to write mock objects to run the tests on and interpret the results. That's actually taken more thought when I've done it. I haven't used the new Python framework for it yet though. > - do you wish you had better code coverage? Sure, we could all use that. On the other hand it slows down development if you overdo it. It's a trade-off like anything else. > - how important is testing to you? If you mean TDD and automated testing, it's very helpful if you're doing something intricate, or if it needs frequent changes and redeployment, etc. For more straightforward tasks, manually testing while you code is ok, especially if it's the type of code for which smoke testing is enough to tell whether the code works. So like anything else, it's a trade-off based on the features and priorities of the task at hand. From nikos.gr33k at gmail.com Sun Sep 29 03:49:27 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Sun, 29 Sep 2013 10:49:27 +0300 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Message-ID: Hello although my code is correct just today i saw this in the error_log [Sun Sep 29 07:44:43 2013] [error] [client 173.245.49.126] Traceback (most recent call last): [Sun Sep 29 07:44:43 2013] [error] [client 173.245.49.126] File "/home/nikos/public_html/cgi-bin/metrites.py", line 30, in [Sun Sep 29 07:44:43 2013] [error] [client 173.245.49.126] host = socket.gethostbyaddr( ipval ) [0] [Sun Sep 29 07:44:43 2013] [error] [client 173.245.49.126] UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte [Sun Sep 29 07:44:43 2013] [error] [client 173.245.49.126] Premature end of script headers: metrites.py Which should never had happened since i use the following code: ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) city = "??????? ????" host = "??????? ?????????" try: gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') city = gi.time_zone_by_addr( ipval ) host = socket.gethostbyaddr( ipval ) [0] except socket.gaierror as e: print( "metrites.py => (%s): " % lastvisit, repr( sys.exc_info() ), file=open('/tmp/err.out', 'w') ) So vene if somethign might have gone wrong with the 'host' assignment, 'host' should have defaulted to "??????? ?????????" why the utf-8 error? From rosuav at gmail.com Sun Sep 29 03:53:44 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 29 Sep 2013 17:53:44 +1000 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: Message-ID: On Sun, Sep 29, 2013 at 5:49 PM, ????? wrote: > Hello although my code is correct just today i saw this in the error_log You retain this ridiculous arrogance that your code is somehow "correct", despite the problems you continually face. Do not these problems prove that your code is NOT correct? ChrisA From nikos.gr33k at gmail.com Sun Sep 29 03:53:36 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Sun, 29 Sep 2013 10:53:36 +0300 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: Message-ID: ???? 29/9/2013 10:49 ??, ?/? ????? ??????: > Hello although my code is correct just today i saw this in the error_log > > [Sun Sep 29 07:44:43 2013] [error] [client 173.245.49.126] Traceback > (most recent call last): > [Sun Sep 29 07:44:43 2013] [error] [client 173.245.49.126] File > "/home/nikos/public_html/cgi-bin/metrites.py", line 30, in > [Sun Sep 29 07:44:43 2013] [error] [client 173.245.49.126] host = > socket.gethostbyaddr( ipval ) [0] > [Sun Sep 29 07:44:43 2013] [error] [client 173.245.49.126] > UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: > invalid start byte > [Sun Sep 29 07:44:43 2013] [error] [client 173.245.49.126] Premature end > of script headers: metrites.py > > > Which should never had happened since i use the following code: > > > ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or > os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) > city = "??????? ????" > host = "??????? ?????????" > try: > gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') > city = gi.time_zone_by_addr( ipval ) > host = socket.gethostbyaddr( ipval ) [0] > except socket.gaierror as e: > print( "metrites.py => (%s): " % lastvisit, repr( sys.exc_info() ), > file=open('/tmp/err.out', 'w') ) > > So vene if somethign might have gone wrong with the 'host' assignment, > 'host' should have defaulted to "??????? ?????????" > > why the utf-8 error? Since this is not a socket.gaierror it wants: except Exception as e: ? i just tried it and now it works. but then agian why the Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte when it comes to dtermine the 'host' ? From rosuav at gmail.com Sun Sep 29 04:00:16 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 29 Sep 2013 18:00:16 +1000 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: Message-ID: On Sun, Sep 29, 2013 at 5:53 PM, ????? wrote: > Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: > invalid start byte Something's trying to decode a stream of bytes as UTF-8, and it's not UTF-8. Work out what in your code is bytes and what is strings, and do your own conversions. http://www.joelonsoftware.com/articles/Unicode.html READ IT. Do not write another line of code until you actually understand what he's saying there. ChrisA From nikos.gr33k at gmail.com Sun Sep 29 04:04:16 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Sun, 29 Sep 2013 11:04:16 +0300 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: Message-ID: ???? 29/9/2013 11:00 ??, ?/? Chris Angelico ??????: > On Sun, Sep 29, 2013 at 5:53 PM, ????? wrote: >> Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: >> invalid start byte > > Something's trying to decode a stream of bytes as UTF-8, and it's not > UTF-8. Work out what in your code is bytes and what is strings, and do > your own conversions. > > http://www.joelonsoftware.com/articles/Unicode.html > > READ IT. Do not write another line of code until you actually > understand what he's saying there. > > ChrisA > okey i will, but isnt this just weird: How come all these daysthe followinf line work as expected: host = socket.gethostbyaddr( ipval ) [0] and only just today just happened to output: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte erros? Nothign got added in my script. This is the only line that tried to determine the host. From rosuav at gmail.com Sun Sep 29 04:07:11 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 29 Sep 2013 18:07:11 +1000 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: Message-ID: On Sun, Sep 29, 2013 at 6:04 PM, ????? wrote: > How come all these daysthe followinf line work as expected: > > > host = socket.gethostbyaddr( ipval ) [0] > > and only just today just happened to output: Maybe the ipval is different. Maybe something else is causing the error. I wonder how, in Python, you would find out which one it is? Wouldn't it be nice if Python had a function - statement in Python 2 - that told you what something was. ChrisA From nikos.gr33k at gmail.com Sun Sep 29 04:19:08 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Sun, 29 Sep 2013 11:19:08 +0300 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: Message-ID: ???? 29/9/2013 11:07 ??, ?/? Chris Angelico ??????: > On Sun, Sep 29, 2013 at 6:04 PM, ????? wrote: >> How come all these daysthe followinf line work as expected: >> >> >> host = socket.gethostbyaddr( ipval ) [0] >> >> and only just today just happened to output: > > Maybe the ipval is different. Maybe something else is causing the > error. I wonder how, in Python, you would find out which one it is? > Wouldn't it be nice if Python had a function - statement in Python 2 - > that told you what something was. The snippet is this: ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) city = "??????? ????" host = "??????? ?????????" try: gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') city = gi.time_zone_by_addr( ipval ) host = socket.gethostbyaddr( ipval ) [0] except Exception as e: print( "metrites.py => (%s): " % lastvisit, repr( sys.exc_info() ), file=open('/tmp/err.out', 'w') ) ipval is suposed to get just an ip address. ip addresses doesnt change its just number seperated by dots. the same provider i uses yesterday i continue to use today, i just restrated the router and got a new ip address and after the new address got assignes to me. unicode decore error related to host started to happen. Can someone explain this or have a way to troubleshoot it because this error is bugging me for several months now but not all the time just in cases liek miens today. From rosuav at gmail.com Sun Sep 29 04:23:35 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 29 Sep 2013 18:23:35 +1000 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: Message-ID: On Sun, Sep 29, 2013 at 6:19 PM, ????? wrote: > ipval is suposed to get just an ip address. > ip addresses doesnt change its just number seperated by dots. That's one way an IP address can be rendered. It's not the only one. There's an entire category of IP addresses that's usually written with colons rather than dots. However, I reiterate: How do you KNOW what's in ipval? I wonder if there's an easy way for you to find out... ChrisA From nikos.gr33k at gmail.com Sun Sep 29 04:30:34 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Sun, 29 Sep 2013 11:30:34 +0300 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: Message-ID: ???? 29/9/2013 11:23 ??, ?/? Chris Angelico ??????: > On Sun, Sep 29, 2013 at 6:19 PM, ????? wrote: >> ipval is suposed to get just an ip address. >> ip addresses doesnt change its just number seperated by dots. > > That's one way an IP address can be rendered. It's not the only one. > There's an entire category of IP addresses that's usually written with > colons rather than dots. However, I reiterate: How do you KNOW what's > in ipval? I wonder if there's an easy way for you to find out... > > ChrisA > yes it is, i take it you mean to just print the damn varibale to see what on eath is actually outputs back.... From nikos.gr33k at gmail.com Sun Sep 29 04:37:14 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Sun, 29 Sep 2013 11:37:14 +0300 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: Message-ID: ???? 29/9/2013 11:30 ??, ?/? ????? ??????: > ???? 29/9/2013 11:23 ??, ?/? Chris Angelico ??????: >> On Sun, Sep 29, 2013 at 6:19 PM, ????? wrote: >>> ipval is suposed to get just an ip address. >>> ip addresses doesnt change its just number seperated by dots. >> >> That's one way an IP address can be rendered. It's not the only one. >> There's an entire category of IP addresses that's usually written with >> colons rather than dots. However, I reiterate: How do you KNOW what's >> in ipval? I wonder if there's an easy way for you to find out... >> >> ChrisA >> > yes it is, i take it you mean to just print the damn varibale to see > what on eath is actually outputs back.... Here, as exactly as i though of it: print( ipval ) returned 46.198.177.249 just a noirmal IPv4 ip address. which leaved the questions of: [Sun Sep 29 07:44:43 2013] [error] [client 173.245.49.126] Traceback (most recent call last): [Sun Sep 29 07:44:43 2013] [error] [client 173.245.49.126] File "/home/nikos/public_html/cgi-bin/metrites.py", line 30, in [Sun Sep 29 07:44:43 2013] [error] [client 173.245.49.126] host = socket.gethostbyaddr( ipval ) [0] [Sun Sep 29 07:44:43 2013] [error] [client 173.245.49.126] UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte [Sun Sep 29 07:44:43 2013] [error] [client 173.245.49.126] Premature end of script headers: metrites.py What on earth it cant decode? From steve+comp.lang.python at pearwood.info Sun Sep 29 05:45:32 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 Sep 2013 09:45:32 GMT Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte References: Message-ID: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> On Sun, 29 Sep 2013 11:37:14 +0300, ????? wrote: > ???? 29/9/2013 11:30 ??, ?/? ????? ??????: >> ???? 29/9/2013 11:23 ??, ?/? Chris Angelico ??????: >>> On Sun, Sep 29, 2013 at 6:19 PM, ????? wrote: >>>> ipval is suposed to get just an ip address. ip addresses doesnt >>>> change its just number seperated by dots. >>> >>> That's one way an IP address can be rendered. It's not the only one. >>> There's an entire category of IP addresses that's usually written with >>> colons rather than dots. However, I reiterate: How do you KNOW what's >>> in ipval? I wonder if there's an easy way for you to find out... >>> >>> ChrisA >>> >> yes it is, i take it you mean to just print the damn varibale to see >> what on eath is actually outputs back.... > > > Here, as exactly as i though of it: > > print( ipval ) returned 46.198.177.249 ............................^^^^^^^^^^^^^^ But the error comes from: > [Sun Sep 29 07:44:43 2013] [error] [client 173.245.49.126] .............................................^^^^^^^^^^^^^^ Given that the error occurred hours ago, I don't think you'll be able to diagnose why it happened unless it happens again. Another thought comes to mind... unless you have changed your habits, I recall that you edit the source code live. If that is the case, it is possible that the error actually occurred in a completely unrelated line, if you happened to be editing the file at the moment the error occurred. -- Steven From nikos.gr33k at gmail.com Sun Sep 29 06:24:53 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Sun, 29 Sep 2013 13:24:53 +0300 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: ???? 29/9/2013 12:45 ??, ?/? Steven D'Aprano ??????: > On Sun, 29 Sep 2013 11:37:14 +0300, ????? wrote: > >> ???? 29/9/2013 11:30 ??, ?/? ????? ??????: >>> ???? 29/9/2013 11:23 ??, ?/? Chris Angelico ??????: >>>> On Sun, Sep 29, 2013 at 6:19 PM, ????? wrote: >>>>> ipval is suposed to get just an ip address. ip addresses doesnt >>>>> change its just number seperated by dots. >>>> >>>> That's one way an IP address can be rendered. It's not the only one. >>>> There's an entire category of IP addresses that's usually written with >>>> colons rather than dots. However, I reiterate: How do you KNOW what's >>>> in ipval? I wonder if there's an easy way for you to find out... >>>> >>>> ChrisA >>>> >>> yes it is, i take it you mean to just print the damn varibale to see >>> what on eath is actually outputs back.... >> >> >> Here, as exactly as i though of it: >> >> print( ipval ) returned 46.198.177.249 > ............................^^^^^^^^^^^^^^ > > But the error comes from: > >> [Sun Sep 29 07:44:43 2013] [error] [client 173.245.49.126] > .............................................^^^^^^^^^^^^^^ > > > Given that the error occurred hours ago, I don't think you'll be able to > diagnose why it happened unless it happens again. > > > Another thought comes to mind... unless you have changed your habits, I > recall that you edit the source code live. If that is the case, it is > possible that the error actually occurred in a completely unrelated line, > if you happened to be editing the file at the moment the error occurred. You remembr correctly, i'am still editing the source code live to reflect instant changes. But....at that moment and all mornign long i wasnt altering the code at all when this error occured and i just tried it at the moment as iam typing it this by alterting the except Exception as e: ===> except socket.gaierror as e: which cannot handle unicore realted errors and the exact same error appeared with my ip address involved at the error log. so, the question that arises again and reamins is how come 'host' vars gets a values most of the times and sometimes it just outputs back unicode related erros. I must tell you that i had this problem also months ago, but since i couldnt able to solve it i left it as it was, but it just started to make things more and more hectic. From davea at davea.name Sun Sep 29 07:11:23 2013 From: davea at davea.name (Dave Angel) Date: Sun, 29 Sep 2013 11:11:23 +0000 (UTC) Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte References: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 29/9/2013 06:24, ????? wrote: > > except Exception as e: ===> except socket.gaierror as e: > which cannot handle unicore realted errors and the exact same error > appeared with my ip address involved at the error log. > > so, the question that arises again and reamins is how come 'host' vars > gets a values most of the times and sometimes it just outputs back > unicode related erros. > > I must tell you that i had this problem also months ago, but since i > couldnt able to solve it i left it as it was, but it just started to > make things more and more hectic. > it would be interesting to see a more complete stack trace. But I'd guess that in the process of looking up the ip address at the dns servers, somebody is producing a non-ascii byte string that isn't encoded in utf-8. It might conceivably be in your /etc/hosts file as well, assuming gethostbyname() looks there when the internet query fails. -- DaveA From nikos.gr33k at gmail.com Sun Sep 29 07:25:21 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Sun, 29 Sep 2013 14:25:21 +0300 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: ???? 29/9/2013 2:11 ??, ?/? Dave Angel ??????: > On 29/9/2013 06:24, ????? wrote: > > > >> >> except Exception as e: ===> except socket.gaierror as e: >> which cannot handle unicore realted errors and the exact same error >> appeared with my ip address involved at the error log. >> >> so, the question that arises again and reamins is how come 'host' vars >> gets a values most of the times and sometimes it just outputs back >> unicode related erros. >> >> I must tell you that i had this problem also months ago, but since i >> couldnt able to solve it i left it as it was, but it just started to >> make things more and more hectic. >> > > it would be interesting to see a more complete stack trace. But I'd > guess that in the process of looking up the ip address at the dns > servers, somebody is producing a non-ascii byte string that isn't > encoded in utf-8. It might conceivably be in your /etc/hosts file as > well, assuming gethostbyname() looks there when the internet query > fails. Thank you for being willing to look this further. root at secure [~]# cat /etc/hosts 127.0.0.1 localhost.localdomain localhost 84.200.17.58 secure.superhost.gr secure root at secure [~]# Just tell me what else file contents or error_log output you want me to show you from my server and i will. Here is my domain's DNS Zone Entry in case it will helpo with something: let me show you how superhost.gr entry appears via WHM in the Zoen section. Code: ; cPanel first:11.38.2.7 (update_time):1380448502 Cpanel::ZoneFile::VERSION:1.3 hostname:secure.superhost.gr latest:11.38.2.7 ; Zone file for superhost.gr $TTL 14400 superhost.gr. 86400 IN SOA ns1.superhost.gr. nikos.gr33k.gmail.com. ( 2013092903 ;Serial Number 86400 ;refresh 7200 ;retry 3600000 ;expire 86400 ) superhost.gr. 86400 IN NS ns1.superhost.gr. superhost.gr. 86400 IN NS ns2.superhost.gr. superhost.gr. 14400 IN A 84.200.17.58 localhost 14400 IN A 127.0.0.1 superhost.gr. 14400 IN MX 0 superhost.gr. mail 14400 IN CNAME superhost.gr. www 14400 IN CNAME superhost.gr. ftp 14400 IN CNAME superhost.gr. As for the mail iam afrid it outputs this: Code: Warning MX CNAME Check WARNING: CNAME was returned for the following MX records: mail.superhost.gr The CNAME(s) that were returned are listed above. This is not ok per the RFCs and can cause problems including mail being lost! Error MX A request returns CNAME WARNING: MX records points to a CNAME. CNAMEs are not allowed in MX records, according to RFC974, RFC1034 3.6.2, RFC1912 2.4, and RFC2181 10.3. The problem MX record(s) are: mail.superhost.gr points to ['superhost.gr'] This can cause problems Do i need to chnage the mx record in cloudflare so mx records point to somethign else being ??????? Also my webpage works as www.superhost.gr but not as superhost.gr I have removed my webiste from cloulflare to make thigns simpler and now in order to viw mywebiste i must give http://www.superhost.gr if i give plain http://superhost.gr it doesnt load at all. The only way is http://www.superhost.gr but no link on my webpage works when clicked upon. iam getting this: http://superhost.gr/cgi-sys/defaultwebpage.cgi Clearly these are DNS and Mail issues. i have asked PaulVPS which is my provider and they dont f***** care to help resolve those issues, and i have paid them upo until May 2014. I just dotn want to lsoe other customers :( From davea at davea.name Sun Sep 29 07:46:12 2013 From: davea at davea.name (Dave Angel) Date: Sun, 29 Sep 2013 11:46:12 +0000 (UTC) Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte References: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 29/9/2013 07:25, ????? wrote: > > Thank you for being willing to look this further. Willing, but probably not able. I think I know a lot about the language, and less about the libraries. I know very little about the administration side of internet use. The reference to /etc/hosts is only a guess, as I said. -- DaveA From nikos.gr33k at gmail.com Sun Sep 29 07:51:47 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Sun, 29 Sep 2013 14:51:47 +0300 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: ???? 29/9/2013 2:46 ??, ?/? Dave Angel ??????: > On 29/9/2013 07:25, ????? wrote: > > >> >> Thank you for being willing to look this further. > > Willing, but probably not able. I think I know a lot about the > language, and less about the libraries. I know very little about the > administration side of internet use. The reference to /etc/hosts is > only a guess, as I said. > > > > Can you please point me to a direction that someone will be able to help me with this since the provider doesn't care to do so? From kwpolska at gmail.com Sun Sep 29 08:38:55 2013 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Sun, 29 Sep 2013 14:38:55 +0200 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Sep 29, 2013 at 1:51 PM, ????? wrote: > ???? 29/9/2013 2:46 ??, ?/? Dave Angel ??????: >> >> On 29/9/2013 07:25, ????? wrote: >> >> >>> >>> Thank you for being willing to look this further. >> >> >> Willing, but probably not able. I think I know a lot about the >> language, and less about the libraries. I know very little about the >> administration side of internet use. The reference to /etc/hosts is >> only a guess, as I said. >> >> >> >> > Can you please point me to a direction that someone will be able to help me > with this since the provider doesn't care to do so? I can point you to ?find a sysadmin that will work for you and fix your problems for money?. Where can you find one? That?s not a question for me. I suggest looking around Greek websites, as someone speaking the same language as you could help you better. -- Chris ?Kwpolska? Warrick PGP: 5EAAEA16 stop html mail | always bottom-post | only UTF-8 makes sense From rosuav at gmail.com Sun Sep 29 10:01:58 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 Sep 2013 00:01:58 +1000 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Sep 29, 2013 at 10:38 PM, Chris ?Kwpolska? Warrick wrote: > I can point you to ?find a sysadmin that will work for you and fix > your problems for money?. Where can you find one? That?s not a > question for me. I suggest looking around Greek websites, as someone > speaking the same language as you could help you better. To be more specific: Greek job-posting web sites. Or maybe general job-posting web sites will let you search specifically for people who speak Greek. Either way, you're looking for someone to hire, here. Maybe you want a contract position, or maybe salaried, but either way, that's what you're needing. ChrisA From rosuav at gmail.com Sun Sep 29 10:19:49 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 Sep 2013 00:19:49 +1000 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Sep 29, 2013 at 9:25 PM, ????? wrote: > superhost.gr. 14400 IN MX 0 superhost.gr. > > mail 14400 IN CNAME superhost.gr. > > As for the mail iam afrid it outputs this: > Code: > Warning MX CNAME Check WARNING: CNAME was returned for the following MX > records: > mail.superhost.gr > The CNAME(s) that were returned are listed above. This is not ok per the > RFCs and can cause problems including mail being lost! > Error MX A request returns CNAME WARNING: MX records points to a > CNAME. CNAMEs are not allowed in MX records, according to RFC974, RFC1034 > 3.6.2, RFC1912 2.4, and RFC2181 10.3. The problem MX record(s) are: > mail.superhost.gr points to ['superhost.gr'] Once again, you are posting code and errors that don't go with each other. Your MX record does not point to mail.superhost.gr but to superhost.gr itself. This makes it extremely difficult to help you. EXTREMELY. Two options: Either edit your bind file manually OR use some other tool for viewing and editing it. If the latter, the bindfile is utterly meaningless - look at the other tool. If the former, I would rewrite your zone file like this: -- cut -- $TTL 14400 @ 86400 IN SOA ns1.superhost.gr. nikosgr33k.gmail.com. ( 2013092903 ;Serial Number 86400 ;refresh 7200 ;retry 3600000 ;expire 86400 ) @ 86400 IN NS ns1 @ 86400 IN NS ns2 @ IN A 84.200.17.58 @ IN MX 0 @ mail IN CNAME @ www IN CNAME @ ftp IN CNAME @ -- cut -- The changes I've made are: 1) Remove the massive duplication of your domain name, mainly by using the shorthand "@". (There are other shorthands you can use, too.) 2) Remove the dot from your email address. Currently your official address is nikos at gr33k.gmail.com which is flat-out wrong. Fortunately for you, Gmail will accept nikosgr33k at gmail.com no problem. 3) Eliding the TTLs where they're the same as your default 4) Removing the entry for localhost.superhost.gr which you shouldn't really be using - it'll only confuse matters. Use localhost as a TLD - that's how it's set up. Aside from #2 and #4, this shouldn't actually change your DNS records, but it'll make your bindfile that much easier to read and work with. Of course, if you're editing the file with some other program, don't do this at all. Just use that other program. ChrisA From nikos.gr33k at gmail.com Sun Sep 29 12:06:29 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Sun, 29 Sep 2013 19:06:29 +0300 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: ???? 29/9/2013 5:19 ??, ?/? Chris Angelico ??????: > On Sun, Sep 29, 2013 at 9:25 PM, ????? wrote: >> superhost.gr. 14400 IN MX 0 superhost.gr. >> >> mail 14400 IN CNAME superhost.gr. >> >> As for the mail iam afrid it outputs this: >> Code: >> Warning MX CNAME Check WARNING: CNAME was returned for the following MX >> records: >> mail.superhost.gr >> The CNAME(s) that were returned are listed above. This is not ok per the >> RFCs and can cause problems including mail being lost! >> Error MX A request returns CNAME WARNING: MX records points to a >> CNAME. CNAMEs are not allowed in MX records, according to RFC974, RFC1034 >> 3.6.2, RFC1912 2.4, and RFC2181 10.3. The problem MX record(s) are: >> mail.superhost.gr points to ['superhost.gr'] > > Once again, you are posting code and errors that don't go with each > other. Your MX record does not point to mail.superhost.gr but to > superhost.gr itself. This makes it extremely difficult to help you. > EXTREMELY. > > Two options: Either edit your bind file manually OR use some other > tool for viewing and editing it. If the latter, the bindfile is > utterly meaningless - look at the other tool. If the former, I would > rewrite your zone file like this: > > -- cut -- > $TTL 14400 > @ 86400 IN SOA ns1.superhost.gr. nikosgr33k.gmail.com. ( > 2013092903 ;Serial Number > 86400 ;refresh > 7200 ;retry > 3600000 ;expire > 86400 ) > > @ 86400 IN NS ns1 > @ 86400 IN NS ns2 > > @ IN A 84.200.17.58 > > @ IN MX 0 @ > > mail IN CNAME @ > www IN CNAME @ > ftp IN CNAME @ > -- cut -- > > The changes I've made are: > 1) Remove the massive duplication of your domain name, mainly by using > the shorthand "@". (There are other shorthands you can use, too.) > 2) Remove the dot from your email address. Currently your official > address is nikos at gr33k.gmail.com which is flat-out wrong. Fortunately > for you, Gmail will accept nikosgr33k at gmail.com no problem. > 3) Eliding the TTLs where they're the same as your default > 4) Removing the entry for localhost.superhost.gr which you shouldn't > really be using - it'll only confuse matters. Use localhost as a TLD - > that's how it's set up. > > Aside from #2 and #4, this shouldn't actually change your DNS records, > but it'll make your bindfile that much easier to read and work with. > > Of course, if you're editing the file with some other program, don't > do this at all. Just use that other program. > > ChrisA > I have tried your setup and still my webpage http://superhost.gr is not loading at all i dont ebven have access to cPanel and WHM any more by hostname. The via WHM i have reset the DNS Zone for superhost.gr and let it recreate it as WHM wants it by default. Still same error. No website appearing anymore no access to cPanel & WHM and no ability to send or receive mail. From joel.goldstick at gmail.com Sun Sep 29 12:14:39 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sun, 29 Sep 2013 12:14:39 -0400 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: asked and answered. Move on -------------- next part -------------- An HTML attachment was scrubbed... URL: From nikos.gr33k at gmail.com Sun Sep 29 12:19:23 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Sun, 29 Sep 2013 19:19:23 +0300 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: ???? 29/9/2013 7:14 ??, ?/? Joel Goldstick ??????: > asked and answered. Move on shut up. you are nothign but annoyance here. From orgnut at yahoo.com Sun Sep 29 23:16:24 2013 From: orgnut at yahoo.com (Larry Hudson) Date: Sun, 29 Sep 2013 20:16:24 -0700 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 09/29/2013 09:19 AM, ????? wrote: > ???? 29/9/2013 7:14 ??, ?/? Joel Goldstick ??????: >> asked and answered. Move on > > shut up. you are nothign but annoyance here. Thanks for the laugh. Absolutely the most hilarious thing you've ever posted!!! :-) (Ever hear about the pot and the kettle?) From breamoreboy at yahoo.co.uk Mon Sep 30 10:45:55 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 30 Sep 2013 15:45:55 +0100 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 29/09/2013 17:19, ????? wrote: > ???? 29/9/2013 7:14 ??, ?/? Joel Goldstick ??????: >> asked and answered. Move on > > shut up. you are nothign but annoyance here. Absolutely hilarious. Please give up your web work and Python and get a job writing scripts for comedians, you'd make a large fortune. -- Cheers. Mark Lawrence From nikos.gr33k at gmail.com Mon Sep 30 14:03:32 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Mon, 30 Sep 2013 21:03:32 +0300 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: ???? 30/9/2013 5:45 ??, ?/? Mark Lawrence ??????: > On 29/09/2013 17:19, ????? wrote: >> ???? 29/9/2013 7:14 ??, ?/? Joel Goldstick ??????: >>> asked and answered. Move on >> >> shut up. you are nothign but annoyance here. > > Absolutely hilarious. Please give up your web work and Python and get a > job writing scripts for comedians, you'd make a large fortune. I learn Python for personal pleasure because i like programming. Perhaps it would be even better if you quit spamming my thread with your "funny" quotes. From antoon.pardon at rece.vub.ac.be Mon Sep 30 14:18:26 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 30 Sep 2013 20:18:26 +0200 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5249C072.9080209@rece.vub.ac.be> Op 30-09-13 20:03, ????? schreef: > ???? 30/9/2013 5:45 ??, ?/? Mark Lawrence ??????: >> On 29/09/2013 17:19, ????? wrote: >>> ???? 29/9/2013 7:14 ??, ?/? Joel Goldstick ??????: >>>> asked and answered. Move on >>> >>> shut up. you are nothign but annoyance here. >> >> Absolutely hilarious. Please give up your web work and Python and get a >> job writing scripts for comedians, you'd make a large fortune. > > I learn Python for personal pleasure because i like programming. You may like porgramming, but it is rather obvious you don't like the python style of programming. So maybe you should chose a laguage whose style is more to your liking. > Perhaps it would be even better if you quit spamming my thread with your > "funny" quotes. You have no authority over what people contribute in your thread. Since you don't seem very considerate about the effect your contributions have on others, you can hardly expect others to be considerate of you. -- Antoon Pardon From breamoreboy at yahoo.co.uk Mon Sep 30 14:42:36 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 30 Sep 2013 19:42:36 +0100 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 30/09/2013 19:03, ????? wrote: > ???? 30/9/2013 5:45 ??, ?/? Mark Lawrence ??????: >> On 29/09/2013 17:19, ????? wrote: >>> ???? 29/9/2013 7:14 ??, ?/? Joel Goldstick ??????: >>>> asked and answered. Move on >>> >>> shut up. you are nothign but annoyance here. >> >> Absolutely hilarious. Please give up your web work and Python and get a >> job writing scripts for comedians, you'd make a large fortune. > > I learn Python for personal pleasure because i like programming. > Perhaps it would be even better if you quit spamming my thread with your > "funny" quotes. Your approach as given in the pseudocode given below is taking up what, 50% of the bandwidth here? What a waste of a resource. while "answer_isn't_what_I_want": keep_asking_question() You are to this mailing list what King Herod was to baby sitting. Please drop dead and the sooner the better. Your arrogant attitide to the numerous people who've tried so hard to help you is disgraceful. -- Cheers. Mark Lawrence From ned at nedbatchelder.com Mon Sep 30 14:54:19 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 30 Sep 2013 14:54:19 -0400 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5249C8DB.8000102@nedbatchelder.com> On 9/30/13 2:42 PM, Mark Lawrence wrote: > Please drop dead and the sooner the better. Your arrogant attitide to > the numerous people who've tried so hard to help you is disgraceful. Mark, I'm as frustrated as anyone by Nikos' threads, but there's really no call for "Please drop dead." We can do better than that. --Ned. From antoon.pardon at rece.vub.ac.be Mon Sep 30 16:51:47 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 30 Sep 2013 22:51:47 +0200 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: <5249C8DB.8000102@nedbatchelder.com> References: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> <5249C8DB.8000102@nedbatchelder.com> Message-ID: <5249E463.6080807@rece.vub.ac.be> Op 30-09-13 20:54, Ned Batchelder schreef: > On 9/30/13 2:42 PM, Mark Lawrence wrote: >> Please drop dead and the sooner the better. Your arrogant attitide to >> the numerous people who've tried so hard to help you is disgraceful. > > Mark, I'm as frustrated as anyone by Nikos' threads, but there's really > no call for "Please drop dead." We can do better than that. I disagree. The "Please drop dead" seems well deserved to me. You may think it better if people could put themselves above it, but that doesn't make the remark less deserved. -- Antoon Pardon From nikos.gr33k at gmail.com Mon Sep 30 16:13:02 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Mon, 30 Sep 2013 23:13:02 +0300 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: ???? 30/9/2013 9:42 ??, ?/? Mark Lawrence ??????: > On 30/09/2013 19:03, ????? wrote: >> ???? 30/9/2013 5:45 ??, ?/? Mark Lawrence ??????: >>> On 29/09/2013 17:19, ????? wrote: >>>> ???? 29/9/2013 7:14 ??, ?/? Joel Goldstick ??????: >>>>> asked and answered. Move on >>>> >>>> shut up. you are nothign but annoyance here. >>> >>> Absolutely hilarious. Please give up your web work and Python and get a >>> job writing scripts for comedians, you'd make a large fortune. >> >> I learn Python for personal pleasure because i like programming. >> Perhaps it would be even better if you quit spamming my thread with your >> "funny" quotes. > > Your approach as given in the pseudocode given below is taking up what, > 50% of the bandwidth here? What a waste of a resource. > > while "answer_isn't_what_I_want": > keep_asking_question() I was thankfull to the people that tried to help me(excluding you) Several method have been given to solve the problem. Other newbies reading this will help them better understand why its written the way it is if they compare all the solutions. And yes, i won't rest until i have it working as i think its clearer and more compact. > You are to this mailing list what King Herod was to baby sitting. And you are a major asshole leading this list, who is doing nothing else than critizizing others people's posts, spamming all he way along while contributing negatively only. > Please drop dead and the sooner the better. After you please. > Your arrogant attitide to > the numerous people who've tried so hard to help you is disgraceful. Your ironic attitude on the other hand is what characterizes you. Triing out various solutions and picking the one that better meets one's style and needs, is hardly considered as arrogance. From breamoreboy at yahoo.co.uk Mon Sep 30 16:44:52 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 30 Sep 2013 21:44:52 +0100 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 30/09/2013 21:13, ????? wrote: > And you are a major asshole leading this list, who is doing nothing else > than critizizing others people's posts, spamming all he way along while > contributing negatively only. > Really? http://code.activestate.com/lists/python-list/651611/ -- Cheers. Mark Lawrence From nikos.gr33k at gmail.com Mon Sep 30 17:34:09 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Tue, 01 Oct 2013 00:34:09 +0300 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: ???? 30/9/2013 11:44 ??, ?/? Mark Lawrence ??????: > On 30/09/2013 21:13, ????? wrote: >> And you are a major asshole leading this list, who is doing nothing else >> than critizizing others people's posts, spamming all he way along while >> contributing negatively only. >> > > Really? http://code.activestate.com/lists/python-list/651611/ One positive comment in the history opposes 10^2 negative ones. From joel.goldstick at gmail.com Mon Sep 30 17:44:05 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 30 Sep 2013 17:44:05 -0400 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Sep 30, 2013 at 5:34 PM, ????? wrote: > ???? 30/9/2013 11:44 ??, ?/? Mark Lawrence ??????: > >> On 30/09/2013 21:13, ????? wrote: >> >>> And you are a major asshole leading this list, who is doing nothing else >>> than critizizing others people's posts, spamming all he way along while >>> contributing negatively only. >>> >>> >> Really? http://code.activestate.com/**lists/python-list/651611/ >> > > One positive comment in the history opposes 10^2 negative ones. > > -- > https://mail.python.org/**mailman/listinfo/python-list > well, actually no. one positive comment (and I'm sorry your reference didn't reveal one!) is 10^2-1 times as 10^2 negative comments. Look in a mirror dude. You are lazy, you charge people for code that you don't even have under source control, you have no interest in understanding and studying how your servers work, how python works. You bitch and whine at people who come along to help you. You are to slothful to look at a traceback. Your hosting company ignores you apparently because you are such an sob they don't even want your business. You pick a nickname that is the defininition of an asshole: http://www.politicsforum.org/images/flame_warriors/flame_62.php and yet you return again and again to be rude to all who first try to help you out, then realize you are such a total jerk that they even wish you an awful demise without even having met you.. Take a look in the mirror dude. I don't care if you want to tell me to shut up. It seemed amusing to others here. -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Mon Sep 30 17:47:29 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 30 Sep 2013 22:47:29 +0100 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 30/09/2013 22:34, ????? wrote: > ???? 30/9/2013 11:44 ??, ?/? Mark Lawrence ??????: >> On 30/09/2013 21:13, ????? wrote: >>> And you are a major asshole leading this list, who is doing nothing else >>> than critizizing others people's posts, spamming all he way along while >>> contributing negatively only. >>> >> >> Really? http://code.activestate.com/lists/python-list/651611/ > > One positive comment in the history opposes 10^2 negative ones. > Yet more sheer unadulterated rubbish from an imbecile who clearly hasn't got the faintest idea what he's talking about. Would you please be kind enough to stand up, your voice is rather muffled. That is after you've done a proper statistical analysis of the number of positive posts I've made over the years. You are actually one of the very few people who has managed to get quite so far up my nose, that's quite an achievement as by nature I'm actually extremely tolerant. -- Cheers. Mark Lawrence From nikos.gr33k at gmail.com Mon Sep 30 18:08:41 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Tue, 01 Oct 2013 01:08:41 +0300 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: ???? 1/10/2013 12:44 ??, ?/? Joel Goldstick ??????: > > > > On Mon, Sep 30, 2013 at 5:34 PM, ????? > wrote: > > ???? 30/9/2013 11:44 ??, ?/? Mark Lawrence ??????: > > On 30/09/2013 21:13, ????? wrote: > > And you are a major asshole leading this list, who is doing > nothing else > than critizizing others people's posts, spamming all he way > along while > contributing negatively only. > > > Really? http://code.activestate.com/__lists/python-list/651611/ > > > > One positive comment in the history opposes 10^2 negative ones. > > -- > https://mail.python.org/__mailman/listinfo/python-list > > > > well, actually no. one positive comment (and I'm sorry your reference > didn't reveal one!) is 10^2-1 times as 10^2 negative comments. Look in > a mirror dude. You are lazy, you charge people for code that you don't > even have under source control, you have no interest in understanding > and studying how your servers work, how python works. You bitch and > whine at people who come along to help you. You are to slothful to look > at a traceback. Your hosting company ignores you apparently because you > are such an sob they don't even want your business. You pick a nickname > that is the defininition of an asshole: > http://www.politicsforum.org/images/flame_warriors/flame_62.php and yet > you return again and again to be rude to all who first try to help you > out, then realize you are such a total jerk that they even wish you an > awful demise without even having met you.. > > Take a look in the mirror dude. > > I don't care if you want to tell me to shut up. It seemed amusing to > others here. > > -- > Joel Goldstick > http://joelgoldstick.com stfu dickhead. From joel.goldstick at gmail.com Mon Sep 30 18:13:21 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 30 Sep 2013 18:13:21 -0400 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Sep 30, 2013 at 6:08 PM, ????? wrote: > ???? 1/10/2013 12:44 ??, ?/? Joel Goldstick ??????: > >> >> >> >> On Mon, Sep 30, 2013 at 5:34 PM, ????? > **> wrote: >> >> ???? 30/9/2013 11:44 ??, ?/? Mark Lawrence ??????: >> >> On 30/09/2013 21:13, ????? wrote: >> >> And you are a major asshole leading this list, who is doing >> nothing else >> than critizizing others people's posts, spamming all he way >> along while >> contributing negatively only. >> >> >> Really? http://code.activestate.com/__**lists/python-list/651611/ >> >> >> > >> >> >> One positive comment in the history opposes 10^2 negative ones. >> >> -- >> https://mail.python.org/__**mailman/listinfo/python-list >> >> >> > >> >> >> well, actually no. one positive comment (and I'm sorry your reference >> didn't reveal one!) is 10^2-1 times as 10^2 negative comments. Look in >> a mirror dude. You are lazy, you charge people for code that you don't >> even have under source control, you have no interest in understanding >> and studying how your servers work, how python works. You bitch and >> whine at people who come along to help you. You are to slothful to look >> at a traceback. Your hosting company ignores you apparently because you >> are such an sob they don't even want your business. You pick a nickname >> that is the defininition of an asshole: >> http://www.politicsforum.org/**images/flame_warriors/flame_**62.php and yet >> you return again and again to be rude to all who first try to help you >> out, then realize you are such a total jerk that they even wish you an >> awful demise without even having met you.. >> >> Take a look in the mirror dude. >> >> I don't care if you want to tell me to shut up. It seemed amusing to >> others here. >> >> -- >> Joel Goldstick >> http://joelgoldstick.com >> > > stfu dickhead. > -- > https://mail.python.org/**mailman/listinfo/python-list > that was responsive! You should join your local debating club! anyway, out! -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Mon Sep 30 18:14:42 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 30 Sep 2013 23:14:42 +0100 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 30/09/2013 23:08, ????? wrote: > ???? 1/10/2013 12:44 ??, ?/? Joel Goldstick ??????: >> >> >> >> On Mon, Sep 30, 2013 at 5:34 PM, ????? > > wrote: >> >> ???? 30/9/2013 11:44 ??, ?/? Mark Lawrence ??????: >> >> On 30/09/2013 21:13, ????? wrote: >> >> And you are a major asshole leading this list, who is doing >> nothing else >> than critizizing others people's posts, spamming all he way >> along while >> contributing negatively only. >> >> >> Really? http://code.activestate.com/__lists/python-list/651611/ >> >> >> >> One positive comment in the history opposes 10^2 negative ones. >> >> -- >> https://mail.python.org/__mailman/listinfo/python-list >> >> >> >> well, actually no. one positive comment (and I'm sorry your reference >> didn't reveal one!) is 10^2-1 times as 10^2 negative comments. Look in >> a mirror dude. You are lazy, you charge people for code that you don't >> even have under source control, you have no interest in understanding >> and studying how your servers work, how python works. You bitch and >> whine at people who come along to help you. You are to slothful to look >> at a traceback. Your hosting company ignores you apparently because you >> are such an sob they don't even want your business. You pick a nickname >> that is the defininition of an asshole: >> http://www.politicsforum.org/images/flame_warriors/flame_62.php and yet >> you return again and again to be rude to all who first try to help you >> out, then realize you are such a total jerk that they even wish you an >> awful demise without even having met you.. >> >> Take a look in the mirror dude. >> >> I don't care if you want to tell me to shut up. It seemed amusing to >> others here. >> >> -- >> Joel Goldstick >> http://joelgoldstick.com > > stfu dickhead. To quote from The A-Team, "I love it when a plan comes together". -- Cheers. Mark Lawrence From nikos.gr33k at gmail.com Mon Sep 30 18:19:54 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Tue, 01 Oct 2013 01:19:54 +0300 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: ???? 1/10/2013 1:14 ??, ?/? Mark Lawrence ??????: > On 30/09/2013 23:08, ????? wrote: >> ???? 1/10/2013 12:44 ??, ?/? Joel Goldstick ??????: >>> >>> >>> >>> On Mon, Sep 30, 2013 at 5:34 PM, ????? >> > wrote: >>> >>> ???? 30/9/2013 11:44 ??, ?/? Mark Lawrence ??????: >>> >>> On 30/09/2013 21:13, ????? wrote: >>> >>> And you are a major asshole leading this list, who is doing >>> nothing else >>> than critizizing others people's posts, spamming all he way >>> along while >>> contributing negatively only. >>> >>> >>> Really? http://code.activestate.com/__lists/python-list/651611/ >>> >>> >>> >>> One positive comment in the history opposes 10^2 negative ones. >>> >>> -- >>> https://mail.python.org/__mailman/listinfo/python-list >>> >>> >>> >>> well, actually no. one positive comment (and I'm sorry your reference >>> didn't reveal one!) is 10^2-1 times as 10^2 negative comments. Look in >>> a mirror dude. You are lazy, you charge people for code that you don't >>> even have under source control, you have no interest in understanding >>> and studying how your servers work, how python works. You bitch and >>> whine at people who come along to help you. You are to slothful to look >>> at a traceback. Your hosting company ignores you apparently because you >>> are such an sob they don't even want your business. You pick a nickname >>> that is the defininition of an asshole: >>> http://www.politicsforum.org/images/flame_warriors/flame_62.php and yet >>> you return again and again to be rude to all who first try to help you >>> out, then realize you are such a total jerk that they even wish you an >>> awful demise without even having met you.. >>> >>> Take a look in the mirror dude. >>> >>> I don't care if you want to tell me to shut up. It seemed amusing to >>> others here. >>> >>> -- >>> Joel Goldstick >>> http://joelgoldstick.com >> >> stfu dickhead. > > To quote from The A-Team, "I love it when a plan comes together". 2 dickheads names Joe & Mark work together to achieve total bullshit! Well done Beavis & Butthead! rofl... From breamoreboy at yahoo.co.uk Mon Sep 30 18:28:38 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 30 Sep 2013 23:28:38 +0100 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 30/09/2013 23:19, ????? wrote: > > 2 dickheads names Joe & Mark work together to achieve total bullshit! > Well done Beavis & Butthead! > rofl... > Well aside from the fact that you've maintained your record by being inaccurate with 50% of the names that you've quoted, it appears that we've something that has very much in common with your website. Which reminds me, is it still possible to access your users' names and passwords in plain text or is that something that you've actually bothered to fix? -- Cheers. Mark Lawrence From nikos.gr33k at gmail.com Mon Sep 30 18:30:45 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Tue, 01 Oct 2013 01:30:45 +0300 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: ???? 1/10/2013 1:28 ??, ?/? Mark Lawrence ??????: > On 30/09/2013 23:19, ????? wrote: >> >> 2 dickheads names Joe & Mark work together to achieve total bullshit! >> Well done Beavis & Butthead! >> rofl... >> > > Well aside from the fact that you've maintained your record by being > inaccurate with 50% of the names that you've quoted, it appears that > we've something that has very much in common with your website. Which > reminds me, is it still possible to access your users' names and > passwords in plain text or is that something that you've actually > bothered to fix? Nope, it isn't. I have fixed it. From rosuav at gmail.com Mon Sep 30 18:43:08 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 1 Oct 2013 08:43:08 +1000 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Oct 1, 2013 at 8:30 AM, ????? wrote: > ???? 1/10/2013 1:28 ??, ?/? Mark Lawrence ??????: >> >> On 30/09/2013 23:19, ????? wrote: >>> >>> >>> 2 dickheads names Joe & Mark work together to achieve total bullshit! >>> Well done Beavis & Butthead! >>> rofl... >>> >> >> Well aside from the fact that you've maintained your record by being >> inaccurate with 50% of the names that you've quoted, it appears that >> we've something that has very much in common with your website. Which >> reminds me, is it still possible to access your users' names and >> passwords in plain text or is that something that you've actually >> bothered to fix? > > > Nope, it isn't. I have fixed it. And this doesn't bother you???!? Nikos, industry best practice is to make sure people can't steal all your users' passwords *even if they get access to your hard drive*. Passwords should be stored like this: "92e25cf5beefd4982cedd2f28b430e0e9d23e0966ee3f20c74f825ebeeee9842" That's the password "qwer", on an account named "asdf", on a mythical system. Even knowing that, you can't work out what another password means. Storing people's passwords in plain text is a HORRIBLE HORRIBLE idea - and having them accessible to the world is a sign of a complete and utter lack of any semblance of security. I understand that bugs happen. But bugs of this criticality should be your very highest priority... unless you're not actually in business here, and you're just scamming a bunch of people by pretending you run a legit enterprise. ChrisA From nikos.gr33k at gmail.com Mon Sep 30 18:48:24 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Tue, 01 Oct 2013 01:48:24 +0300 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: ???? 1/10/2013 1:43 ??, ?/? Chris Angelico ??????: > On Tue, Oct 1, 2013 at 8:30 AM, ????? wrote: >> ???? 1/10/2013 1:28 ??, ?/? Mark Lawrence ??????: >>> >>> On 30/09/2013 23:19, ????? wrote: >>>> >>>> >>>> 2 dickheads names Joe & Mark work together to achieve total bullshit! >>>> Well done Beavis & Butthead! >>>> rofl... >>>> >>> >>> Well aside from the fact that you've maintained your record by being >>> inaccurate with 50% of the names that you've quoted, it appears that >>> we've something that has very much in common with your website. Which >>> reminds me, is it still possible to access your users' names and >>> passwords in plain text or is that something that you've actually >>> bothered to fix? >> >> >> Nope, it isn't. I have fixed it. > > And this doesn't bother you???!? > > Nikos, industry best practice is to make sure people can't steal all > your users' passwords *even if they get access to your hard drive*. > Passwords should be stored like this: > > "92e25cf5beefd4982cedd2f28b430e0e9d23e0966ee3f20c74f825ebeeee9842" > > That's the password "qwer", on an account named "asdf", on a mythical > system. Even knowing that, you can't work out what another password > means. Storing people's passwords in plain text is a HORRIBLE HORRIBLE > idea - and having them accessible to the world is a sign of a complete > and utter lack of any semblance of security. > > I understand that bugs happen. But bugs of this criticality should be > your very highest priority... unless you're not actually in business > here, and you're just scamming a bunch of people by pretending you run > a legit enterprise. > > ChrisA > I don't have the security awareness you have, but i'am learnign at the process. What maked you think i store peoples password in plain text? All the user account passwords i set i do it via cPanel or via WHM. How those services store the password in the linux server its up to them. From steve+comp.lang.python at pearwood.info Mon Sep 30 19:50:09 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Sep 2013 23:50:09 GMT Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte References: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <524a0e31$0$29974$c3e8da3$5496439d@news.astraweb.com> On Tue, 01 Oct 2013 01:08:41 +0300, ????? wrote: > stfu dickhead. And you're back in the kill-file. *plonk* -- Steven From rosuav at gmail.com Mon Sep 30 18:29:31 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 1 Oct 2013 08:29:31 +1000 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Oct 1, 2013 at 4:03 AM, ????? wrote: > ???? 30/9/2013 5:45 ??, ?/? Mark Lawrence ??????: >> Absolutely hilarious. Please give up your web work and Python and get a >> job writing scripts for comedians, you'd make a large fortune. > > > I learn Python for personal pleasure because i like programming. > Perhaps it would be even better if you quit spamming my thread with your > "funny" quotes. Then maybe you should keep to programming for personal pleasure and stop trying to make it part of your business. Most of your problems stem from a perceived urgency - you panic, because you have stupidly edited your live code again, and come to this list begging for help. If you were coding purely for pleasure, your problems would not lose you customers, and you could deal with issues calmly. To be quite frank, I think you SHOULD lose customers. Suppose you buy a piece of furniture from some small-time carpenter, and the moving parts are stuck, it wobbles on its legs, and if anyone uses it who isn't American, it crashes to the floor (which is how your Unicode issues make you look). You go and complain, loudly, in front of people who were looking at his wares and considering buying. He might lose customers because of your complaint - but if he's selling a dodgy product, he *should* lose customers. Carpentry for pleasure, or programming for pleasure, is a fine thing to do, but it should not be considered business. Nikos, I sincerely hope that all these problems cause you to go out of business. Preferably right now, with just enough maintenance to last till the end of your contracts with people. Then start programming purely as a hobby, until you actually master the craft. ChrisA From ben+python at benfinney.id.au Mon Sep 30 18:42:30 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 01 Oct 2013 08:42:30 +1000 Subject: Mutual respect, tolerance, encouragement (was: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte) References: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7wmwmurkx5.fsf_-_@benfinney.id.au> Chris Angelico writes: > Nikos, I sincerely hope that all these problems cause you to go out of > business. Preferably right now, with just enough maintenance to last > till the end of your contracts with people. Then start programming > purely as a hobby, until you actually master the craft. This is a sentiment I can heartily endorse. Far better than puerile jeers and hostile desires for violence. Please, everyone in this thread needs to keep in mind our host's Diversity Statement: The Python Software Foundation and the global Python community welcome and encourage participation by everyone. Our community is based on mutual respect, tolerance, and encouragement, and we are working to help each other live up to these principles. We want our community to be more diverse: whoever you are, and whatever your background, we welcome you. Let's keep all discussions here close to those principles. -- \ ?The trouble with the rat race is that even if you win, you're | `\ still a rat.? ?Jane Wagner, via Lily Tomlin | _o__) | Ben Finney From nikos.gr33k at gmail.com Mon Sep 30 18:36:42 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Tue, 01 Oct 2013 01:36:42 +0300 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: ???? 1/10/2013 1:29 ??, ?/? Chris Angelico ??????: > On Tue, Oct 1, 2013 at 4:03 AM, ????? wrote: >> ???? 30/9/2013 5:45 ??, ?/? Mark Lawrence ??????: >>> Absolutely hilarious. Please give up your web work and Python and get a >>> job writing scripts for comedians, you'd make a large fortune. >> >> >> I learn Python for personal pleasure because i like programming. >> Perhaps it would be even better if you quit spamming my thread with your >> "funny" quotes. > > Then maybe you should keep to programming for personal pleasure and > stop trying to make it part of your business. Most of your problems > stem from a perceived urgency - you panic, because you have stupidly > edited your live code again, and come to this list begging for help. > If you were coding purely for pleasure, your problems would not lose > you customers, and you could deal with issues calmly. > > To be quite frank, I think you SHOULD lose customers. Suppose you buy > a piece of furniture from some small-time carpenter, and the moving > parts are stuck, it wobbles on its legs, and if anyone uses it who > isn't American, it crashes to the floor (which is how your Unicode > issues make you look). You go and complain, loudly, in front of people > who were looking at his wares and considering buying. He might lose > customers because of your complaint - but if he's selling a dodgy > product, he *should* lose customers. Carpentry for pleasure, or > programming for pleasure, is a fine thing to do, but it should not be > considered business. > > Nikos, I sincerely hope that all these problems cause you to go out of > business. Preferably right now, with just enough maintenance to last > till the end of your contracts with people. Then start programming > purely as a hobby, until you actually master the craft. I learn during the process. That's how i deal with the situation. I challedge my self and then try to confront the given situation _live_. It's not wise to do so, but that how i operate. Apart form that my customer's webistes have no problems, everyhting i do its domain specific, my domain, DNS and Mail issues for my domain, i don't play with customer's settings and data. I have a good sense _not_ to fiddle with their accounts(except from the time that i have taken the risk to give you root access to helo me with a python issue, and you've "helped" me appropiately). From rosuav at gmail.com Mon Sep 30 18:56:42 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 1 Oct 2013 08:56:42 +1000 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Oct 1, 2013 at 8:36 AM, ????? wrote: > I learn during the process. > That's how i deal with the situation. > I challedge my self and then try to confront the given situation _live_. > > It's not wise to do so, but that how i operate. Everyone's learning on the job. (I learned this week that it's possible to play fast and loose with ARP and routing, to make one computer look like two and two look like one. That was fun. When I came up with the concept, I gave my boss a 95% confidence that it'd work; and so far it's not caused any trouble.) But what you're doing is charging your customers while you learn the very basics. You can't sell "Hello, world". Most people expect to go to university to learn a trade; some spend two decades playing with something before earning a single dollar (or Euro, or yen). Learn to code, THEN try to make money at it. Or even leave off the 'then' clause - plenty of people never earn anything from code, and stay as happy amateurs. There's nothing wrong with that. ChrisA From nikos.gr33k at gmail.com Mon Sep 30 19:14:48 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Tue, 01 Oct 2013 02:14:48 +0300 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: <5247f6bb$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: ???? 1/10/2013 1:56 ??, ?/? Chris Angelico ??????: > But what you're doing > is charging your customers while you learn the very basics. I designed their websites and they are up and running. Yes i have charged some money, but they gain what they paid for, a running website, all of them. So, its not like i'm ripping off someone here. > You can't sell "Hello, world". I hope i was in the position to sell python code but i'am not. I learn Python because i like programming. My reseller site should have been made probably in wordpress or joomla cms but i decided to code it in Python instead because i like the language and want it to learn it better and better. It has secret functions as well. When i problem occurs i just ask and thats how i progress. Sometimes i do a little reading too :) From ned at nedbatchelder.com Sun Sep 29 06:53:27 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sun, 29 Sep 2013 06:53:27 -0400 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: Message-ID: <524806A7.1050000@nedbatchelder.com> On 9/29/13 4:04 AM, ????? wrote: > ???? 29/9/2013 11:00 ??, ?/? Chris Angelico ??????: >> On Sun, Sep 29, 2013 at 5:53 PM, ????? wrote: >>> Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in >>> position 0: >>> invalid start byte >> >> Something's trying to decode a stream of bytes as UTF-8, and it's not >> UTF-8. Work out what in your code is bytes and what is strings, and do >> your own conversions. >> >> http://www.joelonsoftware.com/articles/Unicode.html >> >> READ IT. Do not write another line of code until you actually >> understand what he's saying there. >> >> ChrisA >> > okey i will, but isnt this just weird: > > How come all these daysthe followinf line work as expected: > > host = socket.gethostbyaddr( ipval ) [0] > > and only just today just happened to output: > UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: > invalid start byte erros? > > Nothign got added in my script. This is the only line that tried to > determine the host. This is the nature of Unicode pain in Python 2 (Python 3 has a different kind!). This may help you understand what's going on: http://nedbatchelder.com/text/unipain.html --Ned. From tjreedy at udel.edu Sun Sep 29 13:30:48 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 29 Sep 2013 13:30:48 -0400 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: <524806A7.1050000@nedbatchelder.com> References: <524806A7.1050000@nedbatchelder.com> Message-ID: On 9/29/2013 6:53 AM, Ned Batchelder wrote: > This is the nature of Unicode pain in Python 2 (Python 3 has a different > kind!). This may help you understand what's going on: > http://nedbatchelder.com/text/unipain.html This is really excellent and I bookmarked it. There is one minor error: "the conversion from int to float can't fail," >>> float(10**1000) Traceback (most recent call last): File "", line 1, in float(10**1000) OverflowError: long int too large to convert to float Even when it succeeds, it can fail in the sense of losing information. >>> int(float(12345678901234567890)) 12345678901234567168 >>> float(int(1.55)) 1.0 This is somewhat analogous to a combination of errors='ignore' and errors='replace' (with random garbage). I think the presentation would be strengthened with the correction, as it shows that the problems of conversion are *not* unique to bytes and unicode. -- Terry Jan Reedy From ned at nedbatchelder.com Sun Sep 29 15:08:28 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sun, 29 Sep 2013 15:08:28 -0400 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: <524806A7.1050000@nedbatchelder.com> Message-ID: <52487AAC.2000207@nedbatchelder.com> On 9/29/13 1:30 PM, Terry Reedy wrote: > On 9/29/2013 6:53 AM, Ned Batchelder wrote: > >> This is the nature of Unicode pain in Python 2 (Python 3 has a different >> kind!). This may help you understand what's going on: >> http://nedbatchelder.com/text/unipain.html > > This is really excellent and I bookmarked it. > > There is one minor error: "the conversion from int to float can't fail," > > >>> float(10**1000) > Traceback (most recent call last): > File "", line 1, in > float(10**1000) > OverflowError: long int too large to convert to float > > Even when it succeeds, it can fail in the sense of losing information. > >>> int(float(12345678901234567890)) > 12345678901234567168 > >>> float(int(1.55)) > 1.0 > > This is somewhat analogous to a combination of errors='ignore' and > errors='replace' (with random garbage). > > I think the presentation would be strengthened with the correction, as > it shows that the problems of conversion are *not* unique to bytes and > unicode. > Thanks, these are excellent points. --Ned. From steve+comp.lang.python at pearwood.info Sun Sep 29 10:08:49 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 Sep 2013 14:08:49 GMT Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte References: Message-ID: <52483470$0$29988$c3e8da3$5496439d@news.astraweb.com> On Sun, 29 Sep 2013 06:53:27 -0400, Ned Batchelder wrote: > This is the nature of Unicode pain in Python 2 (Python 3 has a different > kind!). This may help you understand what's going on: > http://nedbatchelder.com/text/unipain.html That's a fantastic explanation, and I have pointed Nikos at that before, but he is running Python 3, not 2, so the obvious problem is not likely to be the actual problem. -- Steven From nikos.gr33k at gmail.com Sun Sep 29 03:59:50 2013 From: nikos.gr33k at gmail.com (=?UTF-8?B?zp3Or866zr/Pgg==?=) Date: Sun, 29 Sep 2013 10:59:50 +0300 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: Message-ID: ???? 29/9/2013 10:53 ??, ?/? Chris Angelico ??????: > On Sun, Sep 29, 2013 at 5:49 PM, ????? wrote: >> Hello although my code is correct just today i saw this in the error_log > > You retain this ridiculous arrogance that your code is somehow > "correct", despite the problems you continually face. Do not these > problems prove that your code is NOT correct? > > ChrisA > You fail to understand that these code i now use was written with the help of regulars here and yes its correct. As i said in my previous post i already identified that the problem was at the error handling. Since this is not a socket.gaierror it wants: except Exception as e: ? i just tried it and now it works. but then again why the: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte when it comes to determine the 'host' ? From invalid at invalid.invalid Mon Sep 30 09:51:14 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 30 Sep 2013 13:51:14 +0000 (UTC) Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte References: Message-ID: On 2013-09-29, ?????????? wrote: > ???????? 29/9/2013 10:53 ????, ??/?? Chris Angelico ????????????: > > You fail to understand that these code i now use was written with the > help of regulars here and yes its correct. If you're code is correct, then use it and be happy. There's no need to bother us if your code is correct. -- Grant Edwards grant.b.edwards Yow! Can I have an IMPULSE at ITEM instead? gmail.com From breamoreboy at yahoo.co.uk Mon Sep 30 10:51:39 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 30 Sep 2013 15:51:39 +0100 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: Message-ID: On 30/09/2013 14:51, Grant Edwards wrote: > On 2013-09-29, ?????????? wrote: >> ???????? 29/9/2013 10:53 ????, ??/?? Chris Angelico ????????????: >> >> You fail to understand that these code i now use was written with the >> help of regulars here and yes its correct. > > If you're code is correct, then use it and be happy. > > There's no need to bother us if your code is correct. > Could this be an extremely rare case whereby the original code is 100% correct but the problems have been exacerbated by the many suggested patches given here being 100% incorrect? -- Cheers. Mark Lawrence From rosuav at gmail.com Mon Sep 30 11:06:20 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 1 Oct 2013 01:06:20 +1000 Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte In-Reply-To: References: Message-ID: On Tue, Oct 1, 2013 at 12:51 AM, Mark Lawrence wrote: > On 30/09/2013 14:51, Grant Edwards wrote: >> >> On 2013-09-29, ?????????? wrote: >>> >>> ???????? 29/9/2013 10:53 ????, ??/?? Chris Angelico ????????????: >>> >>> You fail to understand that these code i now use was written with the >>> help of regulars here and yes its correct. >> >> >> If you're code is correct, then use it and be happy. >> >> There's no need to bother us if your code is correct. >> > > Could this be an extremely rare case whereby the original code is 100% > correct but the problems have been exacerbated by the many suggested patches > given here being 100% incorrect? Jests and barbs left aside, I believe his definition of "correct" is "wasn't crashing". Earlier in this thread there was a hint that he'd tightened a bare except to one specific exception. My guess is his code wasn't correct, but one bug (overly-broad try/except) masked another. ChrisA From denismfmcmahon at gmail.com Mon Sep 30 18:09:18 2013 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Mon, 30 Sep 2013 22:09:18 +0000 (UTC) Subject: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte References: Message-ID: On Mon, 30 Sep 2013 15:51:39 +0100, Mark Lawrence wrote: > On 30/09/2013 14:51, Grant Edwards wrote: >> On 2013-09-29, ?????????? wrote: >>> ???????? 29/9/2013 10:53 ????, ??/?? Chris Angelico ????????????: >>> You fail to understand that these code i now use was written with the >>> help of regulars here and yes its correct. >> If you're code is correct, then use it and be happy. >> There's no need to bother us if your code is correct. > Could this be an extremely rare case whereby the original code is 100% > correct but the problems have been exacerbated by the many suggested > patches given here being 100% incorrect? I'm sending you the bill for hospital admission. I laughed so hard I fell off of my chair and banged my head! -- Denis McMahon, denismfmcmahon at gmail.com From sschwarzer at sschwarzer.net Sun Sep 29 14:00:36 2013 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Sun, 29 Sep 2013 20:00:36 +0200 Subject: [ANN] ftputil 3.0a1 released In-Reply-To: <524867A4.6090902@sschwarzer.net> References: <524867A4.6090902@sschwarzer.net> Message-ID: <52486AC4.3020905@sschwarzer.net> ftputil 3.0a1 is now available from http://ftputil.sschwarzer.net/download . Changes since version 2.8 ------------------------- Note: This version of ftputil is _not_ backward-compatible with earlier versions.See the links below for information on adapting existing client code. - This version adds Python 3 compatibility! :-) The same source is used for Python 2.x and Python 3.x. I had to change the API to find a good compromise for both Python versions. - ftputil now requires at least Python 2.6. - Remote file-like objects use the same semantics as Python's `io` module. (This is the same as for the built-in `open` function in Python 3.) - `ftputil.ftp_error` was renamed to `ftputil.error`. - For custom parsers, import `ftputil.parser` instead of `ftputil.stat`. For more information please read http://ftputil.sschwarzer.net/trac/wiki/WhatsNewInFtputil3.0 http://ftputil.sschwarzer.net/trac/wiki/PreReleaseDocumentation What is ftputil? ---------------- ftputil is a high-level FTP client library for the Python programming language. ftputil implements a virtual file system for accessing FTP servers, that is, it can generate file-like objects for remote files. The library supports many functions similar to those in the os, os.path and shutil modules. ftputil has convenience functions for conditional uploads and downloads, and handles FTP clients and servers in different timezones. License ------- ftputil is Open Source software, released under the revised BSD license (see http://opensource.org/licenses/BSD-3-Clause ). Stefan From g.rodola at gmail.com Mon Sep 30 04:39:05 2013 From: g.rodola at gmail.com (Giampaolo Rodola') Date: Mon, 30 Sep 2013 10:39:05 +0200 Subject: [ANN] ftputil 3.0a1 released In-Reply-To: <52486AC4.3020905@sschwarzer.net> References: <524867A4.6090902@sschwarzer.net> <52486AC4.3020905@sschwarzer.net> Message-ID: Glad to hear there's someone else other than me who still cares about the almost forgotten FTP protocol! =) --- Giampaolo https://code.google.com/p/pyftpdlib/ https://code.google.com/p/psutil/ https://code.google.com/p/pysendfile/ On Sun, Sep 29, 2013 at 8:00 PM, Stefan Schwarzer wrote: > ftputil 3.0a1 is now available from > http://ftputil.sschwarzer.net/download . > > Changes since version 2.8 > ------------------------- > > Note: This version of ftputil is _not_ backward-compatible > with earlier versions.See the links below for information > on adapting existing client code. > > - This version adds Python 3 compatibility! :-) > > The same source is used for Python 2.x and Python 3.x. > > I had to change the API to find a good compromise for > both Python versions. > > - ftputil now requires at least Python 2.6. > > - Remote file-like objects use the same semantics as Python's > `io` module. (This is the same as for the built-in `open` > function in Python 3.) > > - `ftputil.ftp_error` was renamed to `ftputil.error`. > > - For custom parsers, import `ftputil.parser` instead of > `ftputil.stat`. > > For more information please read > http://ftputil.sschwarzer.net/trac/wiki/WhatsNewInFtputil3.0 > http://ftputil.sschwarzer.net/trac/wiki/PreReleaseDocumentation > > What is ftputil? > ---------------- > > ftputil is a high-level FTP client library for the Python programming > language. ftputil implements a virtual file system for accessing FTP > servers, that is, it can generate file-like objects for remote files. > The library supports many functions similar to those in the os, > os.path and shutil modules. ftputil has convenience functions for > conditional uploads and downloads, and handles FTP clients and servers > in different timezones. > > License > ------- > > ftputil is Open Source software, released under the revised BSD > license (see http://opensource.org/licenses/BSD-3-Clause ). > > Stefan > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jcasale at activenetwerx.com Sun Sep 29 17:54:04 2013 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Sun, 29 Sep 2013 21:54:04 +0000 Subject: Barcode printing Message-ID: I need to convert a proprietary MS Access based printing solution into something I can maintain. Seems there is plenty available for generating barcodes in Python, so for the persons who have been down this road I was hoping to get a pointer or two. I need to create some type of output, preferably pdf, which is an array of 2 across by 8 long of one custom barcode label with some other text components oriented around the barcode. Anyone know the best approach for this? Generating the barcode looks trivial, I am just not sure which package might offer the remaining functionality easily. Thanks for any pointers! jlc From gary.herron at islandtraining.com Sun Sep 29 18:56:58 2013 From: gary.herron at islandtraining.com (Gary Herron) Date: Sun, 29 Sep 2013 15:56:58 -0700 Subject: Barcode printing In-Reply-To: References: Message-ID: <5248B03A.4000906@islandtraining.com> On 09/29/2013 02:54 PM, Joseph L. Casale wrote: > I need to convert a proprietary MS Access based printing solution into something I can > maintain. Seems there is plenty available for generating barcodes in Python, so for the > persons who have been down this road I was hoping to get a pointer or two. > > I need to create some type of output, preferably pdf, which is an array of 2 across by 8 long > of one custom barcode label with some other text components oriented around the barcode. > > Anyone know the best approach for this? Generating the barcode looks trivial, I am just not > sure which package might offer the remaining functionality easily. > > Thanks for any pointers! > jlc For creating PDFs from Python, consider: ReportLab: Open Source Python Libraries for PDF creation at http://www.reportlab.com/software/opensource/ I've used it successfully. Gary Herron From ben+python at benfinney.id.au Sun Sep 29 20:47:19 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 30 Sep 2013 10:47:19 +1000 Subject: Barcode printing References: Message-ID: <7w7gdzt9t4.fsf@benfinney.id.au> "Joseph L. Casale" writes: > I need to create some type of output, preferably pdf, which is an > array of 2 across by 8 long of one custom barcode label with some > other text components oriented around the barcode. The Reportlab library is a powerful PDF-creation library for Python . It has a library for creating barcodes in various formats and rendering them along with the PDF document. Here is an article describing this . -- \ ?With Lisp or Forth, a master programmer has unlimited power | `\ and expressiveness. With Python, even a regular guy can reach | _o__) for the stars.? ?Raymond Hettinger | Ben Finney From ben+python at benfinney.id.au Sun Sep 29 23:41:15 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 30 Sep 2013 13:41:15 +1000 Subject: Barcode printing References: <7w7gdzt9t4.fsf@benfinney.id.au> Message-ID: <7w38ont1r8.fsf@benfinney.id.au> Ben Finney writes: > "Joseph L. Casale" writes: > > > I need to create some type of output, preferably pdf, which is an > > array of 2 across by 8 long of one custom barcode label with some > > other text components oriented around the barcode. > > The Reportlab library is a powerful PDF-creation library for Python > . If that's a bit heavyweight (and confusing; it's not all free software, since some of it is under non-free license terms), there are other options. pyBarcode says it's a pure-Python library that takes a barcode type and the value, and generates an SVG of the barcode. -- \ ?[W]e are still the first generation of users, and for all that | `\ we may have invented the net, we still don't really get it.? | _o__) ?Douglas Adams | Ben Finney From jcasale at activenetwerx.com Mon Sep 30 10:48:05 2013 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Mon, 30 Sep 2013 14:48:05 +0000 Subject: Barcode printing In-Reply-To: <7w38ont1r8.fsf@benfinney.id.au> References: <4c66ecc9063e4baab20440392b6ce439@exch.activenetwerx.com> <7w7gdzt9t4.fsf@benfinney.id.au>,<7w38ont1r8.fsf@benfinney.id.au> Message-ID: >If that's a bit heavyweight (and confusing; it's not all free software, >since some of it is under non-free license terms), there are other >options. > >pyBarcode says it's a >pure-Python library that takes a barcode type and the value, and >generates an SVG of the barcode. Actually, The canvas concept is exactly what I need and this is perfect! Thanks Gary and Ben, jlc From larry at hastings.org Sun Sep 29 20:04:45 2013 From: larry at hastings.org (Larry Hastings) Date: Mon, 30 Sep 2013 01:04:45 +0100 Subject: [RELEASED] Python 3.4.0a3 Message-ID: <5248C01D.7060701@hastings.org> On behalf of the Python development team, I'm pleased to announce the third alpha release of Python 3.4. This is a preview release, and its use is not recommended for production settings. Python 3.4 includes a range of improvements of the 3.x series, including hundreds of small improvements and bug fixes. Major new features and changes in the 3.4 release series so far include: * PEP 435, a standardized "enum" module * PEP 442, improved semantics for object finalization * PEP 443, adding single-dispatch generic functions to the standard library * PEP 445, a new C API for implementing custom memory allocators * PEP 446, changing file descriptors to not be inherited by default in subprocesses To download Python 3.4.0a3 visit: http://www.python.org/download/releases/3.4.0/ Please consider trying Python 3.4.0a3 with your code and reporting any issues you notice to: http://bugs.python.org/ Enjoy! -- Larry Hastings, Release Manager larry at hastings.org (on behalf of the entire python-dev team and 3.4's contributors) From steve at pearwood.info Mon Sep 30 01:38:03 2013 From: steve at pearwood.info (Steven D'Aprano) Date: 30 Sep 2013 05:38:03 GMT Subject: Tab completion in Python3.4 Message-ID: <52490e3a$0$2865$c3e8da3$76491128@news.astraweb.com> By default, Python 3.4 will ship with tab completion turned on. When you hit the tab key, Python will try to complete the current function, method, variable or other name, if necessary displaying the alternatives is there are more than one: py> d = {} py> d.pop d.pop( d.popitem( This is a great feature, and very welcome to become on by default. Many thanks to Antoine Pitrou for finally making this happen! I've been using tab completion using a custom startup file for a few years, and of course anyone familiar with the common Linux shells will also be familiar with it. But there is one sting in the tail: the current 3.4 implementation makes it impossible to use the tab key to indent code. Pressing TAB at the start of the line tries to complete on *everything*, instead of indenting: py> for x in range(3): ... Display all 195 possibilities? (y or n) This is a problem: it means you either have to indent using multiple spaces, which is a pain, or a single space, which is ugly and hard to read: py> for x in range(3): ... print(x) ... 0 1 2 I don't consider either of these solutions to be satisfactory. If you agree, I urge you to try it out for yourself, and then leave a comment on the bug tracker asking for tab completion to still insert tabs at the beginning of the line: http://bugs.python.org/issue5845 For anyone wanting to see my version of tab completion and history: https://code.google.com/p/my-startup-file/source/browse/completer.py https://code.google.com/p/my-startup-file/source/browse/history.py Usage is simple: in my startup file, or just do it manually: try: import history except ImportError: print('*** warning: command line history not available ***') else: history = history.History() try: import completer except ImportError: print('*** warning: command line completion not available ***') else: completer = completer.Completer( bindings=(r'"\C-xo": overwrite-mode', r'"\C-xd": dump-functions', ) ) -- Steven From antoine at python.org Mon Sep 30 04:50:01 2013 From: antoine at python.org (Antoine Pitrou) Date: Mon, 30 Sep 2013 08:50:01 +0000 (UTC) Subject: Tab completion in Python3.4 References: <52490e3a$0$2865$c3e8da3$76491128@news.astraweb.com> Message-ID: Steven D'Aprano pearwood.info> writes: > > I don't consider either of these solutions to be satisfactory. If you > agree, I urge you to try it out for yourself, and then leave a comment on > the bug tracker asking for tab completion to still insert tabs at the > beginning of the line: Such a change is much more likely to happen if someone actually proposes a patch for it, rather than merely "ask for it". I don't think anyone is ideologically opposed to it. Regards Antoine. From steve+comp.lang.python at pearwood.info Mon Sep 30 20:10:49 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Oct 2013 00:10:49 GMT Subject: Tab completion in Python3.4 References: <52490e3a$0$2865$c3e8da3$76491128@news.astraweb.com> Message-ID: <524a1309$0$29974$c3e8da3$5496439d@news.astraweb.com> On Mon, 30 Sep 2013 08:50:01 +0000, Antoine Pitrou wrote: > Steven D'Aprano pearwood.info> writes: >> >> I don't consider either of these solutions to be satisfactory. If you >> agree, I urge you to try it out for yourself, and then leave a comment >> on the bug tracker asking for tab completion to still insert tabs at >> the beginning of the line: > > Such a change is much more likely to happen if someone actually proposes > a patch for it, rather than merely "ask for it". I don't think anyone is > ideologically opposed to it. I thought you were and am glad to hear you aren't :-) -- Steven From someshg2 at gmail.com Mon Sep 30 03:26:33 2013 From: someshg2 at gmail.com (somesh g) Date: Mon, 30 Sep 2013 00:26:33 -0700 (PDT) Subject: How to read a particular cell by using "wb = load_workbook('path', True)" in openpyxl Message-ID: Hi..there I have written code for reading the large excel files but my requirement is to read a particular cell in a excel file when i kept "True" in "wb = load_workbook('Path', True)" any body please help me... CODE: ==== from openpyxl import load_workbook wb = load_workbook('Path', True) sheet_ranges = wb.get_sheet_by_name(name = 'Global') for row in sheet_ranges.iter_rows(): for cell in row: print cell.internal_value Regards, G.Someswara Rao From markotaht at gmail.com Mon Sep 30 04:43:19 2013 From: markotaht at gmail.com (markotaht at gmail.com) Date: Mon, 30 Sep 2013 01:43:19 -0700 (PDT) Subject: class implementation Message-ID: <6e338858-b9e6-4745-9959-35d7c0c7724e@googlegroups.com> Is there a way to give a class extra functions whidout editing the .py file where the class is located? From __peter__ at web.de Mon Sep 30 05:03:10 2013 From: __peter__ at web.de (Peter Otten) Date: Mon, 30 Sep 2013 11:03:10 +0200 Subject: class implementation References: <6e338858-b9e6-4745-9959-35d7c0c7724e@googlegroups.com> Message-ID: markotaht at gmail.com wrote: > Is there a way to give a class extra functions whidout editing the .py > file where the class is located? A clean way is subclassing: import vehicles class FlyingCar(vehicles.Car): def lift_off(self): pass flying_car = FlyingCar() flying_car.lift_off() From markotaht at gmail.com Mon Sep 30 05:10:38 2013 From: markotaht at gmail.com (markotaht at gmail.com) Date: Mon, 30 Sep 2013 02:10:38 -0700 (PDT) Subject: class implementation In-Reply-To: <6e338858-b9e6-4745-9959-35d7c0c7724e@googlegroups.com> References: <6e338858-b9e6-4745-9959-35d7c0c7724e@googlegroups.com> Message-ID: <2068fe39-3f52-4724-974a-97a4f8074ed4@googlegroups.com> esmasp?ev, 30. september 2013 11:43.19 UTC+3 kirjutas mark... at gmail.com: > Is there a way to give a class extra functions whidout editing the .py file where the class is located? But does it have all the variables that the main class have? From __peter__ at web.de Mon Sep 30 05:27:34 2013 From: __peter__ at web.de (Peter Otten) Date: Mon, 30 Sep 2013 11:27:34 +0200 Subject: class implementation References: <6e338858-b9e6-4745-9959-35d7c0c7724e@googlegroups.com> <2068fe39-3f52-4724-974a-97a4f8074ed4@googlegroups.com> Message-ID: markotaht at gmail.com wrote: > esmasp?ev, 30. september 2013 11:43.19 UTC+3 kirjutas mark... at gmail.com: >> Is there a way to give a class extra functions whidout editing the .py >> file where the class is located? > > But does it have all the variables that the main class have? Yes. You can invoke all methods of Car on a FlyingCar instance. If you don't define an __init__() method in FlyingCar the initializer of the parent class will be invoked which typically sets a few attributes (I think this is what you mean by variables; if not: please clarify). So just try it out. If you don't get your code to work you can post it here and ask for help on an actual piece of Python. From markotaht at gmail.com Mon Sep 30 08:41:16 2013 From: markotaht at gmail.com (markotaht at gmail.com) Date: Mon, 30 Sep 2013 05:41:16 -0700 (PDT) Subject: class implementation In-Reply-To: <6e338858-b9e6-4745-9959-35d7c0c7724e@googlegroups.com> References: <6e338858-b9e6-4745-9959-35d7c0c7724e@googlegroups.com> Message-ID: <02724244-c924-4cf0-9656-71ade6e435c2@googlegroups.com> under variables, i mean, the int's and lists and strings and floats that the parent class uses. IF in parent class there is variable called location, then can i use the same variable in my sub class. From __peter__ at web.de Mon Sep 30 09:02:18 2013 From: __peter__ at web.de (Peter Otten) Date: Mon, 30 Sep 2013 15:02:18 +0200 Subject: class implementation References: <6e338858-b9e6-4745-9959-35d7c0c7724e@googlegroups.com> <02724244-c924-4cf0-9656-71ade6e435c2@googlegroups.com> Message-ID: markotaht at gmail.com wrote: > under variables, i mean, the int's and lists and strings and floats that > the parent class uses. IF in parent class there is variable called > location, then can i use the same variable in my sub class. Please show us some code. Thankyou. From joel.goldstick at gmail.com Mon Sep 30 09:21:50 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 30 Sep 2013 09:21:50 -0400 Subject: class implementation In-Reply-To: References: <6e338858-b9e6-4745-9959-35d7c0c7724e@googlegroups.com> <02724244-c924-4cf0-9656-71ade6e435c2@googlegroups.com> Message-ID: On Mon, Sep 30, 2013 at 9:02 AM, Peter Otten <__peter__ at web.de> wrote: > markotaht at gmail.com wrote: > > > under variables, i mean, the int's and lists and strings and floats that > > the parent class uses. IF in parent class there is variable called > > location, then can i use the same variable in my sub class. > > Please show us some code. Thankyou. > > -- > https://mail.python.org/mailman/listinfo/python-list > You should start by learning about classes -- perhaps here: http://docs.python.org/2/tutorial/classes.html#classes Then, try writing some code using classes or extending a class. Then come back when something doesn't work as expected -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From piet at vanoostrum.org Mon Sep 30 13:32:14 2013 From: piet at vanoostrum.org (Piet van Oostrum) Date: Mon, 30 Sep 2013 13:32:14 -0400 Subject: class implementation References: <6e338858-b9e6-4745-9959-35d7c0c7724e@googlegroups.com> <02724244-c924-4cf0-9656-71ade6e435c2@googlegroups.com> Message-ID: markotaht at gmail.com writes: > under variables, i mean, the int's and lists and strings and floats that the parent class uses. IF in parent class there is variable called location, then can i use the same variable in my sub class. Do you mean class variables or instance variables? -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From davea at davea.name Mon Sep 30 15:34:08 2013 From: davea at davea.name (Dave Angel) Date: Mon, 30 Sep 2013 19:34:08 +0000 (UTC) Subject: class implementation References: <6e338858-b9e6-4745-9959-35d7c0c7724e@googlegroups.com> <02724244-c924-4cf0-9656-71ade6e435c2@googlegroups.com> Message-ID: On 30/9/2013 08:41, markotaht at gmail.com wrote: > under variables, i mean, the int's and lists and strings and floats that the parent class uses. IF in parent class there is variable called location, then can i use the same variable in my sub class. Python doesn't actually have variables, but the things it documents as variables are local names within a method. Those are not visible outside of the method, regardless of whether you're in a class or a subclass. But perhaps you mean attributes. There are both class attributes and instance attributes, and the behavior is quite different. Roughly speaking a class attribute occurs only once per class, and all code can read its value with either Class.my_attrib or instance.my_attrib. It can be written with Class.my_attrib. On the other hand, instance attributes are usable by instance.my_attrib, regardless of whether the instance is a base class or a child class. Each instance of the class gets a separate copy of such an attribute. They are normally defined in the __init__() method. If you don't happen to know the difference between a class an an instance of that class, then all the above will look like gibberish, and you need to do some studying first. -- DaveA From ned at nedbatchelder.com Mon Sep 30 17:28:30 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 30 Sep 2013 17:28:30 -0400 Subject: class implementation In-Reply-To: References: <6e338858-b9e6-4745-9959-35d7c0c7724e@googlegroups.com> <02724244-c924-4cf0-9656-71ade6e435c2@googlegroups.com> Message-ID: <5249ECFE.2050402@nedbatchelder.com> On 9/30/13 3:34 PM, Dave Angel wrote: > Python doesn't actually have variables, but the things it documents as > variables are local names within a method. Those are not visible > outside of the method, regardless of whether you're in a class or a > subclass. Why does this meme persist!? Of course Python has variables, they just don't work like C variables do. If you'd like to know the details: http://nedbatchelder.com/text/names.html --Ned. From random832 at fastmail.us Mon Sep 30 17:49:15 2013 From: random832 at fastmail.us (random832 at fastmail.us) Date: Mon, 30 Sep 2013 17:49:15 -0400 Subject: class implementation In-Reply-To: <5249ECFE.2050402@nedbatchelder.com> References: <6e338858-b9e6-4745-9959-35d7c0c7724e@googlegroups.com> <02724244-c924-4cf0-9656-71ade6e435c2@googlegroups.com> <5249ECFE.2050402@nedbatchelder.com> Message-ID: <1380577755.27707.28361301.13E24052@webmail.messagingengine.com> On Mon, Sep 30, 2013, at 17:28, Ned Batchelder wrote: > On 9/30/13 3:34 PM, Dave Angel wrote: > > Python doesn't actually have variables, but the things it documents as > > variables are local names within a method. Those are not visible > > outside of the method, regardless of whether you're in a class or a > > subclass. > > Why does this meme persist!? Of course Python has variables, they just > don't work like C variables do. If you'd like to know the details: > http://nedbatchelder.com/text/names.html Wait a minute, how exactly are C variables supposed to be different from this? From ethan at stoneleaf.us Mon Sep 30 18:02:22 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 30 Sep 2013 15:02:22 -0700 Subject: Python variables? [was Re: class implementation] In-Reply-To: <5249ECFE.2050402@nedbatchelder.com> References: <6e338858-b9e6-4745-9959-35d7c0c7724e@googlegroups.com> <02724244-c924-4cf0-9656-71ade6e435c2@googlegroups.com> <5249ECFE.2050402@nedbatchelder.com> Message-ID: <5249F4EE.60604@stoneleaf.us> On 09/30/2013 02:28 PM, Ned Batchelder wrote: > On 9/30/13 3:34 PM, Dave Angel wrote: >> Python doesn't actually have variables, but the things it documents as >> variables are local names within a method. Those are not visible >> outside of the method, regardless of whether you're in a class or a >> subclass. > > Why does this meme persist!? Of course Python has variables, they just don't work like C variables do. If you'd like > to know the details: http://nedbatchelder.com/text/names.html Because Python's model is different enough that it usually makes thinking about it simpler to stay away from the word 'variable'; in every other language I have used a variable is a box, but in Python it's a label for a box. From your blog: > > Names are Python's variables: they refer to values, and > those values can change (vary) over the course of your > program. This is partially incorrect. If the value referred to by the name is immutable, then it cannot change; perhaps you meant to say that which object the name points to can vary over time? -- ~Ethan~ From ben+python at benfinney.id.au Mon Sep 30 18:37:01 2013 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 01 Oct 2013 08:37:01 +1000 Subject: Python variables? References: <6e338858-b9e6-4745-9959-35d7c0c7724e@googlegroups.com> <02724244-c924-4cf0-9656-71ade6e435c2@googlegroups.com> <5249ECFE.2050402@nedbatchelder.com> <5249F4EE.60604@stoneleaf.us> Message-ID: <7wr4c6rl6a.fsf@benfinney.id.au> Ethan Furman writes: > From [Ned Batchelder]'s blog: > > Names are Python's variables: they refer to values, and > > those values can change (vary) over the course of your > > program. > > This is partially incorrect. If the value referred to by the name is > immutable, then it cannot change; perhaps you meant to say that which > object the name points to can vary over time? I agree. Names are not Python's variables. If anything in Python is a ?variable? as generally understood, it is not a name. It is a *binding*, from a reference (a name, or some other reference like a list item) to a value. It is the binding which can change over the course of the program, so that is the variable. -- \ ?Good judgement comes from experience. Experience comes from | `\ bad judgement.? ?Frederick P. Brooks | _o__) | Ben Finney From ned at nedbatchelder.com Mon Sep 30 19:47:49 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 30 Sep 2013 19:47:49 -0400 Subject: Python variables? In-Reply-To: <7wr4c6rl6a.fsf@benfinney.id.au> References: <6e338858-b9e6-4745-9959-35d7c0c7724e@googlegroups.com> <02724244-c924-4cf0-9656-71ade6e435c2@googlegroups.com> <5249ECFE.2050402@nedbatchelder.com> <5249F4EE.60604@stoneleaf.us> <7wr4c6rl6a.fsf@benfinney.id.au> Message-ID: <524A0DA5.70706@nedbatchelder.com> On 9/30/13 6:37 PM, Ben Finney wrote: > Ethan Furman writes: > >> From [Ned Batchelder]'s blog: >>> Names are Python's variables: they refer to values, and >>> those values can change (vary) over the course of your >>> program. >> This is partially incorrect. If the value referred to by the name is >> immutable, then it cannot change; perhaps you meant to say that which >> object the name points to can vary over time? > I agree. Names are not Python's variables. > > If anything in Python is a ?variable? as generally understood, it is not > a name. It is a *binding*, from a reference (a name, or some other > reference like a list item) to a value. > > It is the binding which can change over the course of the program, so > that is the variable. > True, but no one calls the binding the variable. Here is a program: x = 4 Every one of us is perfectly comfortable talking about the variable x. Don't get hung up on implementation pedantry. The name x here refers to 4. Later it could refer to "four". The value associated with the name x changed. x is a variable. --Ned. From steve+comp.lang.python at pearwood.info Mon Sep 30 21:03:25 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Oct 2013 01:03:25 GMT Subject: Python variables? References: <6e338858-b9e6-4745-9959-35d7c0c7724e@googlegroups.com> <02724244-c924-4cf0-9656-71ade6e435c2@googlegroups.com> <5249ECFE.2050402@nedbatchelder.com> <5249F4EE.60604@stoneleaf.us> <7wr4c6rl6a.fsf@benfinney.id.au> Message-ID: <524a1f5c$0$29974$c3e8da3$5496439d@news.astraweb.com> On Mon, 30 Sep 2013 19:47:49 -0400, Ned Batchelder wrote: > On 9/30/13 6:37 PM, Ben Finney wrote: >> Ethan Furman writes: >> >>> From [Ned Batchelder]'s blog: >>>> Names are Python's variables: they refer to values, and >>>> those values can change (vary) over the course of your program. >>> This is partially incorrect. If the value referred to by the name is >>> immutable, then it cannot change; perhaps you meant to say that which >>> object the name points to can vary over time? >> I agree. Names are not Python's variables. >> >> If anything in Python is a ?variable? as generally understood, it is >> not a name. It is a *binding*, from a reference (a name, or some other >> reference like a list item) to a value. >> >> It is the binding which can change over the course of the program, so >> that is the variable. >> >> > True, but no one calls the binding the variable. Here is a program: > > x = 4 > > Every one of us is perfectly comfortable talking about the variable x. > Don't get hung up on implementation pedantry. The name x here refers to > 4. Later it could refer to "four". The value associated with the name > x changed. x is a variable. Your statement is ambiguous -- do you mean the *association* between value (object) and name changed, or the value which is associated with the name changed? In the first case, "the value associated with the name x changed" is no different from saying "the name binding changed", only longer and more ambiguous. In the second case, if you mean that the association remains the same, but the value itself changed, that's demonstrably untrue since 4 is immutable. But you know that :-) I straddle the fence on this dispute... I'll often refer to Python variables when, in my option, it doesn't confuse the issue or introduce ambiguity, but I feel guilty doing so :-) And I always look for the opportunity to introduce the concept of name binding into the discussion. I'm just not religious about it. -- Steven From ned at nedbatchelder.com Mon Sep 30 21:28:36 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 30 Sep 2013 21:28:36 -0400 Subject: Python variables? In-Reply-To: <524a1f5c$0$29974$c3e8da3$5496439d@news.astraweb.com> References: <6e338858-b9e6-4745-9959-35d7c0c7724e@googlegroups.com> <02724244-c924-4cf0-9656-71ade6e435c2@googlegroups.com> <5249ECFE.2050402@nedbatchelder.com> <5249F4EE.60604@stoneleaf.us> <7wr4c6rl6a.fsf@benfinney.id.au> <524a1f5c$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <524A2544.6050506@nedbatchelder.com> On 9/30/13 9:03 PM, Steven D'Aprano wrote: > On Mon, 30 Sep 2013 19:47:49 -0400, Ned Batchelder wrote: > >> On 9/30/13 6:37 PM, Ben Finney wrote: >>> Ethan Furman writes: >>> >>>> From [Ned Batchelder]'s blog: >>>>> Names are Python's variables: they refer to values, and >>>>> those values can change (vary) over the course of your program. >>>> This is partially incorrect. If the value referred to by the name is >>>> immutable, then it cannot change; perhaps you meant to say that which >>>> object the name points to can vary over time? >>> I agree. Names are not Python's variables. >>> >>> If anything in Python is a ?variable? as generally understood, it is >>> not a name. It is a *binding*, from a reference (a name, or some other >>> reference like a list item) to a value. >>> >>> It is the binding which can change over the course of the program, so >>> that is the variable. >>> >>> >> True, but no one calls the binding the variable. Here is a program: >> >> x = 4 >> >> Every one of us is perfectly comfortable talking about the variable x. >> Don't get hung up on implementation pedantry. The name x here refers to >> 4. Later it could refer to "four". The value associated with the name >> x changed. x is a variable. > Your statement is ambiguous -- do you mean the *association* between > value (object) and name changed, or the value which is associated with > the name changed? Yes, my statement was ambiguous. The value of x at time t1 can be different than the value of x at time t2, and there are two different ways it can differ. None of that changes the fact that the value associated with the name varies over the course of a program, giving rise to "variables." I prefer to say that Python has variables, and they work by a mechanism of names referring to values. I don't find that beginners get it by being told that Python has no variables. It seems to be something that experts sometimes find helpful, though. --Ned. > > In the first case, "the value associated with the name x changed" is no > different from saying "the name binding changed", only longer and more > ambiguous. > > In the second case, if you mean that the association remains the same, > but the value itself changed, that's demonstrably untrue since 4 is > immutable. But you know that :-) > > I straddle the fence on this dispute... I'll often refer to Python > variables when, in my option, it doesn't confuse the issue or introduce > ambiguity, but I feel guilty doing so :-) And I always look for the > opportunity to introduce the concept of name binding into the discussion. > I'm just not religious about it. > > From ned at nedbatchelder.com Mon Sep 30 19:45:06 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 30 Sep 2013 19:45:06 -0400 Subject: Python variables? [was Re: class implementation] In-Reply-To: <5249F4EE.60604@stoneleaf.us> References: <6e338858-b9e6-4745-9959-35d7c0c7724e@googlegroups.com> <02724244-c924-4cf0-9656-71ade6e435c2@googlegroups.com> <5249ECFE.2050402@nedbatchelder.com> <5249F4EE.60604@stoneleaf.us> Message-ID: <524A0D02.60002@nedbatchelder.com> On 9/30/13 6:02 PM, Ethan Furman wrote: > On 09/30/2013 02:28 PM, Ned Batchelder wrote: >> On 9/30/13 3:34 PM, Dave Angel wrote: >>> Python doesn't actually have variables, but the things it documents as >>> variables are local names within a method. Those are not visible >>> outside of the method, regardless of whether you're in a class or a >>> subclass. >> >> Why does this meme persist!? Of course Python has variables, they >> just don't work like C variables do. If you'd like >> to know the details: http://nedbatchelder.com/text/names.html > > Because Python's model is different enough that it usually makes > thinking about it simpler to stay away from the word 'variable'; in > every other language I have used a variable is a box, but in Python > it's a label for a box. > It might help C programmers to stay away from "variable," but some people claim we should avoid the word so as not to confuse beginners. That's just silly. Beginners have no holdover concepts from C. Lots of languages use the same names and values model that Python does: Javascript, Java, Ruby, Lisp, etc. > From your blog: >> >> Names are Python's variables: they refer to values, and >> those values can change (vary) over the course of your >> program. > > This is partially incorrect. If the value referred to by the name is > immutable, then it cannot change; perhaps you meant to say that which > object the name points to can vary over time? Yes, I meant that 1) names refer to values, and 2) a name can refer to different values over the course of a program. Hence, the value varies, hence, a variable. In fact, it's more accurate to say that Python has no constants! :) --Ned. > > -- > ~Ethan~ From rhodri at wildebst.demon.co.uk Mon Sep 30 20:29:16 2013 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 01 Oct 2013 01:29:16 +0100 Subject: Python variables? [was Re: class implementation] References: <6e338858-b9e6-4745-9959-35d7c0c7724e@googlegroups.com> <02724244-c924-4cf0-9656-71ade6e435c2@googlegroups.com> <5249ECFE.2050402@nedbatchelder.com> <5249F4EE.60604@stoneleaf.us> Message-ID: On Tue, 01 Oct 2013 00:45:06 +0100, Ned Batchelder wrote: > > On 9/30/13 6:02 PM, Ethan Furman wrote: >> From your blog: >>> >>> Names are Python's variables: they refer to values, and >>> those values can change (vary) over the course of your >>> program. >> >> This is partially incorrect. If the value referred to by the name is >> immutable, then it cannot change; perhaps you meant to say that which >> object the name points to can vary over time? > > Yes, I meant that 1) names refer to values, and 2) a name can refer to > different values over the course of a program. Hence, the value varies, > hence, a variable. Yes, except no. The problem is that word "value", which I can practically see morphing its meaning through that paragraph. Names refer to objects, which have values or interpretations or however you choose to say it. Some (mutable) objects can change their value, some (immutable) can't. Independently, names can refer to different objects, which may or may not have different values (or indeed concepts of value). When you say "The value varies", it begs the question "Which 'the value'?" > In fact, it's more accurate to say that Python has no constants! :) Or, alternatively, that Python has many constants, such as all those immutable integers cached around the place :-) What it doesn't have is fixed bindings. -- Rhodri James *-* Wildebeest Herder to the Masses From steve+comp.lang.python at pearwood.info Mon Sep 30 19:45:48 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Sep 2013 23:45:48 GMT Subject: class implementation References: <6e338858-b9e6-4745-9959-35d7c0c7724e@googlegroups.com> <02724244-c924-4cf0-9656-71ade6e435c2@googlegroups.com> Message-ID: <524a0d2c$0$29974$c3e8da3$5496439d@news.astraweb.com> On Mon, 30 Sep 2013 17:28:30 -0400, Ned Batchelder wrote: > On 9/30/13 3:34 PM, Dave Angel wrote: >> Python doesn't actually have variables, but the things it documents as >> variables are local names within a method. Those are not visible >> outside of the method, regardless of whether you're in a class or a >> subclass. > > Why does this meme persist!? Of course Python has variables, they just > don't work like C variables do. If you'd like to know the details: > http://nedbatchelder.com/text/names.html I'm not convinced that "Python variables are different from C variables" is a better way to get through to people than "Python doesn't have variables, it has name bindings". Of course, *technically* the first statement is accurate, and the second relies on a definition of variable that is not universal. The question is which is more effective at getting the differences between the two programming models through to the reader. I can't speak for others, but in my own experience, I never *quite* understood the semantic differences between Python name bindings and Pascal variables until I came across the meme "Python has no variables". -- Steven From ethan at stoneleaf.us Mon Sep 30 20:31:20 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 30 Sep 2013 17:31:20 -0700 Subject: class implementation In-Reply-To: <524a0d2c$0$29974$c3e8da3$5496439d@news.astraweb.com> References: <6e338858-b9e6-4745-9959-35d7c0c7724e@googlegroups.com> <02724244-c924-4cf0-9656-71ade6e435c2@googlegroups.com> <524a0d2c$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <524A17D8.5060705@stoneleaf.us> On 09/30/2013 04:45 PM, Steven D'Aprano wrote: > > I can't speak for others, but in my own experience, I never *quite* > understood the semantic differences between Python name bindings and > Pascal variables until I came across the meme "Python has no variables". +1 From steve+comp.lang.python at pearwood.info Mon Sep 30 20:19:30 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Oct 2013 00:19:30 GMT Subject: class implementation References: <6e338858-b9e6-4745-9959-35d7c0c7724e@googlegroups.com> <02724244-c924-4cf0-9656-71ade6e435c2@googlegroups.com> Message-ID: <524a1512$0$29974$c3e8da3$5496439d@news.astraweb.com> On Mon, 30 Sep 2013 05:41:16 -0700, markotaht wrote: > under variables, i mean, the int's and lists and strings and floats that > the parent class uses. IF in parent class there is variable called > location, then can i use the same variable in my sub class. Firstly, in Python circles we prefer to call them "attributes" rather than variables. Since this is Python, it is trivially easy to test this for yourself. Start an interactive Python interpreter, and then in under a dozen lines you can test it: py> class Test: ... attr = "Hello World!" # Shared class attribute. ... py> class MyTest(Test): ... pass ... py> x = MyTest() py> x.attr 'Hello World!' Works perfectly! (It would be a funny programming language where it didn't, since this is one of the most fundamental parts of inheritance. A language that didn't do something equivalent to this couldn't really claim to be object-oriented.) -- Steven From adamkalinski at gmail.com Mon Sep 30 06:14:28 2013 From: adamkalinski at gmail.com (AdamKal) Date: Mon, 30 Sep 2013 03:14:28 -0700 (PDT) Subject: CRUD library Message-ID: Hi, Do you know any library or framework that unifies CRUD somehow. Maybe I'll describe my problem: I have a application that uses many external services and processes them together. This are things like web services and DB and so on. In the REST era we usually operate on object and collections of objects (like in django's ORM) but have different source behind them. My idea was that there might be somewhere a unified abstraction layer that would require from programmers to write the CRUD methods and handle object creation and management (maybe even relations?) by itself. I've started to work on my own library for that but I wouldn't like to do something that someone has done already. Do you know any such library/framework? Do you think that it makes any sense at all? regards, Adam From memilanuk at gmail.com Mon Sep 30 08:06:07 2013 From: memilanuk at gmail.com (memilanuk) Date: Mon, 30 Sep 2013 05:06:07 -0700 Subject: CRUD library In-Reply-To: References: Message-ID: On 09/30/2013 03:14 AM, AdamKal wrote: > Hi, > > Do you know any library or framework that unifies CRUD somehow. > Sounds kind of like the DAL (Data Abstaction Layer/Language) from web2py, perhaps? I think I've heard of it being able to be used outside a regular web2py install... not sure, haven't tried it myself. HTH, Monte From waynejwerner at gmail.com Mon Sep 30 15:33:01 2013 From: waynejwerner at gmail.com (waynejwerner at gmail.com) Date: Mon, 30 Sep 2013 12:33:01 -0700 (PDT) Subject: CRUD library In-Reply-To: References: Message-ID: <1ef8a7ed-04a2-49ac-968e-2d3966f536b5@googlegroups.com> On Monday, September 30, 2013 5:14:28 AM UTC-5, AdamKal wrote: > Hi, > > > > Do you know any library or framework that unifies CRUD somehow. > > Maybe I'll describe my problem: > > > > I have a application that uses many external services and processes them together. This are things like web services and DB and so on. In the REST era we usually operate on object and collections of objects (like in django's ORM) but have different source behind them. My idea was that there might be somewhere a unified abstraction layer that would require from programmers to write the CRUD methods and handle object creation and management (maybe even relations?) by itself. > > I've started to work on my own library for that but I wouldn't like to do something that someone has done already. > > Do you know any such library/framework? > > Do you think that it makes any sense at all? Does http://python-eve.org/ look anything like what you mean? Or perhaps http://www.sqlalchemy.org/ ? HTH, W From exhuma at gmail.com Mon Sep 30 07:42:29 2013 From: exhuma at gmail.com (Michel Albert) Date: Mon, 30 Sep 2013 04:42:29 -0700 (PDT) Subject: DNS query against a specific server. Message-ID: <634fa158-1d15-4a7e-ac0f-7a3f57f55cc7@googlegroups.com> Hi, ``socket.gethostbyname`` sends the DNS resolution query to the DNS server specified by the OS. Is there an easy way to send a query to a *different* server? I see that twisted.names allows you to do this, but, having all of twisted as dependency to my project when all I need to do is a simple DNS query seems a bit extreme. I also found pydns, but that looks fairly outdated and unmaintained. Is there not an actively maintained lightweight solution? If not, I will go with twisted. Cheers, Mich. From wrw at mac.com Mon Sep 30 08:36:34 2013 From: wrw at mac.com (William Ray Wing) Date: Mon, 30 Sep 2013 08:36:34 -0400 Subject: DNS query against a specific server. In-Reply-To: <634fa158-1d15-4a7e-ac0f-7a3f57f55cc7@googlegroups.com> References: <634fa158-1d15-4a7e-ac0f-7a3f57f55cc7@googlegroups.com> Message-ID: <6DE89D29-19D3-46BF-ACB4-DCA77450E0BB@mac.com> On Sep 30, 2013, at 7:42 AM, Michel Albert wrote: > Hi, > > ``socket.gethostbyname`` sends the DNS resolution query to the DNS server specified by the OS. Is there an easy way to send a query to a *different* server? > > I see that twisted.names allows you to do this, but, having all of twisted as dependency to my project when all I need to do is a simple DNS query seems a bit extreme. I also found pydns, but that looks fairly outdated and unmaintained. > > Is there not an actively maintained lightweight solution? If not, I will go with twisted. > > > Cheers, > Mich. > -- > https://mail.python.org/mailman/listinfo/python-list It isn't pure python, but you would be pretty much guaranteed a maintained solution if you use the name server lookup in your OS. Something like: import subprocess nsl_reslt = subprocess.Popen(['nslookup', '' ],stderr = subprocess.PIPE, stdout = subprocess.PIPE).communicate()[0] Hope this helps, Bill From exhuma at gmail.com Mon Sep 30 08:45:34 2013 From: exhuma at gmail.com (Michel Albert) Date: Mon, 30 Sep 2013 05:45:34 -0700 (PDT) Subject: DNS query against a specific server. In-Reply-To: References: <634fa158-1d15-4a7e-ac0f-7a3f57f55cc7@googlegroups.com> Message-ID: On Monday, 30 September 2013 14:36:34 UTC+2, William Ray Wing wrote: > On Sep 30, 2013, at 7:42 AM, Michel Albert <***> wrote: > > > > > Hi, > > > > > > ``socket.gethostbyname`` sends the DNS resolution query to the DNS server specified by the OS. Is there an easy way to send a query to a *different* server? > > > > > > I see that twisted.names allows you to do this, but, having all of twisted as dependency to my project when all I need to do is a simple DNS query seems a bit extreme. I also found pydns, but that looks fairly outdated and unmaintained. > > > > > > Is there not an actively maintained lightweight solution? If not, I will go with twisted. > > > > > > > > > Cheers, > > > Mich. > > > -- > > > https://mail.python.org/mailman/listinfo/python-list > > > > It isn't pure python, but you would be pretty much guaranteed a maintained solution if you use the name server lookup in your OS. Something like: > > > > import subprocess > > nsl_reslt = subprocess.Popen(['nslookup', '' ],stderr = subprocess.PIPE, stdout = subprocess.PIPE).communicate()[0] > > > > > > Hope this helps, > > Bill Hmm... I had this option in mind, but opening a subprocess for something as small as this seemed a bit error-prone. If something on the system changes, nslookup replaced by dig or nslookup output changes for example your application will bug out. Granted, the chance of this happening is slim, but using a fixed-version dependency in your setup script gives you a much safer solution IMO. I know I may be splitting hairs. Any of the mentioned solutions are fine. But I am curious to see if something like this is not yet implemented in a more standard way. I was surprised to see that ``gethostbyname`` does not take an optional parameter for this task. From rosuav at gmail.com Mon Sep 30 08:56:40 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 Sep 2013 22:56:40 +1000 Subject: DNS query against a specific server. In-Reply-To: References: <634fa158-1d15-4a7e-ac0f-7a3f57f55cc7@googlegroups.com> Message-ID: On Mon, Sep 30, 2013 at 10:45 PM, Michel Albert wrote: > I know I may be splitting hairs. Any of the mentioned solutions are fine. But I am curious to see if something like this is not yet implemented in a more standard way. I was surprised to see that ``gethostbyname`` does not take an optional parameter for this task. gethostbyname is a simple function with not much flexibility. (You can't, for instance, look up a TXT record.) For anything more complex, you want a proper DNS implementation. There are a few Python DNS modules. It means adding another dependency, but perhaps not as large as twisted. And of course, you could always manually send UDP packets and listen for responses, but that seems a little unnecessary :) ChrisA From gvanem at yahoo.no Mon Sep 30 09:35:15 2013 From: gvanem at yahoo.no (Gisle Vanem) Date: Mon, 30 Sep 2013 15:35:15 +0200 Subject: DNS query against a specific server. References: <634fa158-1d15-4a7e-ac0f-7a3f57f55cc7@googlegroups.com> Message-ID: "Chris Angelico" wrote: > There are a few Python DNS modules. It means adding another > dependency, but perhaps not as large as twisted. And of course, you > could always manually send UDP packets and listen for responses, but > that seems a little unnecessary :) Then there is pycares; "a Python module which provides an interface to c-ares.... c-ares is a C library that performs DNS requests and name resolves asynchronously.". I have good experience wih C-ares and it can set specific nameservers. Ref: https://pypi.python.org/pypi/pycares/0.3.0 --gv From airween at gmail.com Mon Sep 30 08:54:41 2013 From: airween at gmail.com (Ervin =?utf-8?Q?Heged=C3=BCs?=) Date: Mon, 30 Sep 2013 14:54:41 +0200 Subject: DNS query against a specific server. In-Reply-To: <634fa158-1d15-4a7e-ac0f-7a3f57f55cc7@googlegroups.com> References: <634fa158-1d15-4a7e-ac0f-7a3f57f55cc7@googlegroups.com> Message-ID: <20130930125440.GA32116@arxnet.hu> Hello, On Mon, Sep 30, 2013 at 04:42:29AM -0700, Michel Albert wrote: > Hi, > > ``socket.gethostbyname`` sends the DNS resolution query to the DNS server specified by the OS. Is there an easy way to send a query to a *different* server? > > I see that twisted.names allows you to do this, but, having all of twisted as dependency to my project when all I need to do is a simple DNS query seems a bit extreme. I also found pydns, but that looks fairly outdated and unmaintained. > > Is there not an actively maintained lightweight solution? If not, I will go with twisted. > there is a dns modul for Python (I don't know is it part of standard Python library or not), on most Linux distribution you can find it, eg. in Debian it's called python-dnspython. It can handle different nameserver, than OS knows - here is a sample code: import dns.resolver r = dns.resolver.Resolver() r.namerservers = ['127.0.0.1'] # or any other IP, in my case I'm using PDNS, which have two # parts: a recursor and a resolver; recursor allows requests only # on localhost mxservers = r.query("python.org", 'MX').response hth, a. From exhuma at gmail.com Mon Sep 30 09:04:31 2013 From: exhuma at gmail.com (Michel Albert) Date: Mon, 30 Sep 2013 06:04:31 -0700 (PDT) Subject: DNS query against a specific server. In-Reply-To: References: <634fa158-1d15-4a7e-ac0f-7a3f57f55cc7@googlegroups.com> Message-ID: On Monday, 30 September 2013 14:54:41 UTC+2, Ervin Heged?s wrote: > Hello, > > > > On Mon, Sep 30, 2013 at 04:42:29AM -0700, Michel Albert wrote: > > > Hi, > > > > > > ``socket.gethostbyname`` sends the DNS resolution query to the DNS server specified by the OS. Is there an easy way to send a query to a *different* server? > > > > > > I see that twisted.names allows you to do this, but, having all of twisted as dependency to my project when all I need to do is a simple DNS query seems a bit extreme. I also found pydns, but that looks fairly outdated and unmaintained. > > > > > > Is there not an actively maintained lightweight solution? If not, I will go with twisted. > > > > > > > there is a dns modul for Python (I don't know is it part of > > standard Python library or not), on most Linux distribution you > > can find it, eg. in Debian it's called python-dnspython. > > > > It can handle different nameserver, than OS knows - here is a > > sample code: > > > > > > import dns.resolver > > > > r = dns.resolver.Resolver() > > r.namerservers = ['127.0.0.1'] > > # or any other IP, in my case I'm using PDNS, which have two > > # parts: a recursor and a resolver; recursor allows requests only > > # on localhost > > > > mxservers = r.query("python.org", 'MX').response > > > > > > > > > > hth, > > > > > > a. Indeed, this looks much nicer than both twisted or pydns. I think I'll go with that one. Thanks a lot! From skip at pobox.com Mon Sep 30 10:40:20 2013 From: skip at pobox.com (Skip Montanaro) Date: Mon, 30 Sep 2013 09:40:20 -0500 Subject: Using GNU libc mtrace/muntrace via ctypes? Message-ID: I'm getting an error in certain situations which leads to this message: *** glibc detected *** /opt/TWWfsw/bin/python: corrupted double-linked list: 0x0000000007952420 *** Valgrind hasn't been any help. I'd really like to avoid recompiling Python, as that might just move or obscure the error. Might it be possible to enable the GNU libc malloc tracing via ctypes? Thanks, Skip From christensen.jerome at gmail.com Mon Sep 30 10:58:25 2013 From: christensen.jerome at gmail.com (christensen.jerome at gmail.com) Date: Mon, 30 Sep 2013 07:58:25 -0700 (PDT) Subject: fetchall to python lists Message-ID: <812b0b0b-fa73-4fc3-b8d0-ac0a9c93207e@googlegroups.com> Hi - I have some basic programming experience and new to Python. I have connected to SQL Server as follows: import pyodbc conn = pyodbc.connect('DSN=DBC') cursor = conn.cursor() cursor.execute("select measure,fin_year_no,fin_week_no,location_no,value from actual") result=cursor.fetchall() result looks like this: result[0] - ('2013', 2014, 7, 242, 96064.35) result[1] - ('2013', 2014, 7, 502, 18444.2) .... approximately 2m records Is there a way to assign the values of result to 5 lists without doing 5 select statments one for each of the colums and then assigning it to a list so that: list1[0] = '2013' list1[1] = 2014 list1[2] = 7 list1[3] = 242 list1[4] = 96064.35 list2[0] = '2013' list2[1] = 2014 list2[2] = 7 list2[3] = 502 list2[4] = 18444.2 and so on ... Hope someone can help. Regards Jerome From joel.goldstick at gmail.com Mon Sep 30 11:10:29 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 30 Sep 2013 11:10:29 -0400 Subject: fetchall to python lists In-Reply-To: <812b0b0b-fa73-4fc3-b8d0-ac0a9c93207e@googlegroups.com> References: <812b0b0b-fa73-4fc3-b8d0-ac0a9c93207e@googlegroups.com> Message-ID: On Mon, Sep 30, 2013 at 10:58 AM, wrote: > Hi - I have some basic programming experience and new to Python. I have > connected to SQL Server as follows: > > import pyodbc > conn = pyodbc.connect('DSN=DBC') > cursor = conn.cursor() > cursor.execute("select measure,fin_year_no,fin_week_no,location_no,value > from actual") > result=cursor.fetchall() > > result looks like this: > > > > result[0] - ('2013', 2014, 7, 242, 96064.35) > result[1] - ('2013', 2014, 7, 502, 18444.2) > .... approximately 2m records > > Is there a way to assign the values of result to 5 lists without doing 5 > select statments one for each of the colums and then assigning it to a list > so that: > > What you have below is just result[0][0], result[0][1], etc. list1[0] = '2013' > list1[1] = 2014 > list1[2] = 7 > list1[3] = 242 > list1[4] = 96064.35 > > list2[0] = '2013' > list2[1] = 2014 > list2[2] = 7 > list2[3] = 502 > list2[4] = 18444.2 > > and so on ... > > Hope someone can help. Regards Jerome > So what I'm trying to say is that you already have what you want. each tuple is contained in the out list of all of the tuples. For brevity sake, I am acting as if the data set contained only a single row: >>> result = (('2013', 2014, 7, 242, 96064.35),) >>> result (('2013', 2014, 7, 242, 96064.35),) >>> result[0] ('2013', 2014, 7, 242, 96064.35) >>> result[0][0] '2013' >>> result[0][1] 2014 -- > https://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From christensen.jerome at gmail.com Mon Sep 30 11:16:41 2013 From: christensen.jerome at gmail.com (christensen.jerome at gmail.com) Date: Mon, 30 Sep 2013 08:16:41 -0700 (PDT) Subject: fetchall to python lists In-Reply-To: <812b0b0b-fa73-4fc3-b8d0-ac0a9c93207e@googlegroups.com> References: <812b0b0b-fa73-4fc3-b8d0-ac0a9c93207e@googlegroups.com> Message-ID: <96293b0a-3a98-4f23-a4cd-0229a15328ab@googlegroups.com> On Monday, September 30, 2013 4:58:25 PM UTC+2, christens... at gmail.com wrote: > Hi - I have some basic programming experience and new to Python. I have connected to SQL Server as follows: > > > > import pyodbc > > conn = pyodbc.connect('DSN=DBC') > > cursor = conn.cursor() > > cursor.execute("select measure,fin_year_no,fin_week_no,location_no,value from actual") > > result=cursor.fetchall() > > > > result looks like this: > > > > > > > > result[0] - ('2013', 2014, 7, 242, 96064.35) > > result[1] - ('2013', 2014, 7, 502, 18444.2) > > .... approximately 2m records > > > > Is there a way to assign the values of result to 5 lists without doing 5 select statments one for each of the colums and then assigning it to a list so that: > > > > list1[0] = '2013' > > list1[1] = 2014 > > list1[2] = 7 > > list1[3] = 242 > > list1[4] = 96064.35 > > > > list2[0] = '2013' > > list2[1] = 2014 > > list2[2] = 7 > > list2[3] = 502 > > list2[4] = 18444.2 > > > > and so on ... > > > > Hope someone can help. Regards Jerome Thanks Joel did not think it could be so simple!!! From gumbeto at gmail.com Mon Sep 30 12:45:07 2013 From: gumbeto at gmail.com (Ricardo Abreu) Date: Mon, 30 Sep 2013 09:45:07 -0700 (PDT) Subject: Restart the interactive python shell like in IDLE In-Reply-To: References: <1cac668a0906101201g3de1d3a4w8842678398dcb236@mail.gmail.com> Message-ID: <80889ac7-8bdc-4b81-861b-b4833440d181@googlegroups.com> On Thursday, June 11, 2009 1:48:42 AM UTC+2, Chris Rebert wrote: > On Wed, Jun 10, 2009 at 12:01 PM, Matt Burson wrote: > > Is there a way to reproduce the behavior of IDLE's restart shell ability by > > using a function? I thought there would be since you can exit python by > > executing the simple quit() function I thought there would be an equally > > simple function name something like restart(). I'd prefer something like > > this as opposed to having to exit the shell and then start it up again to > > refresh it. > > I believe IDLE itself implements the "restart" capability by killing > and re-launching its Python interpreter subprocess, so it's not like > it's using some hidden capability of Python to accomplish this. > Is doing Ctrl+D, up-arrow, Enter really that hard? It's even fewer > keystrokes than "restart()"... > > Cheers, > Chris > -- > http://blog.rebertia.com You might be launching python from something else other than a shell and it might be harder to re-launch it from there From vignesh.harikrishna at gmail.com Mon Sep 30 12:55:43 2013 From: vignesh.harikrishna at gmail.com (vignesh.harikrishna at gmail.com) Date: Mon, 30 Sep 2013 09:55:43 -0700 (PDT) Subject: VERY BASIC HELP Message-ID: <380132bc-bc9c-4d57-95d8-dc01f26f47a5@googlegroups.com> c=int(raw_input("How many numbers do you want to work? (Min. 2 Max. 3)")) if c==2: x=int(raw_input("Enter the first number to be worked")) y=int(raw_input("Enter the second number to be worked")) elif c==3: x=int(raw_input("Enter the first number to be worked")) y=int(raw_input("Enter the second number to be worked")) z=int(raw_input("Enter the third number to be worked")) else: print "Invalid input.";raw_input("Press to close this window");exit p=int(raw_input("Do you want to divide, subtract, add or multiply these numbers? (1=divide, 2=subtract, 3=add, 4=multiply)")) if p==1 and c==2: print "The result is : ";x/y elif p==1 and c==3: print "The result is :";x/y/z elif p==2 and c==2: print "The result is :";x-y elif p==2 and c==3: print "The result is :";x-y-z elif p==3 and c==2: print "The result is :";x+y elif p==3 and c==3: print "The result is :";x+y+z elif p==4 and c==2: print "The result is :";x*y elif p==4 and c==3: print "The result is :";x*y*z else: print "Invalid Input.";raw_input("Press to close this window") That is my program. These are the problems I am having : 1. Even if c is not 2 or 3, the program continues, as if it received a valid input, it does not exit as I have tried to code it to. 2. If all values are entered correctly, the result does not display. It shows up as "The result is :" and just blank. PLEASE HELP From rosuav at gmail.com Mon Sep 30 13:07:36 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 1 Oct 2013 03:07:36 +1000 Subject: VERY BASIC HELP In-Reply-To: <380132bc-bc9c-4d57-95d8-dc01f26f47a5@googlegroups.com> References: <380132bc-bc9c-4d57-95d8-dc01f26f47a5@googlegroups.com> Message-ID: On Tue, Oct 1, 2013 at 2:55 AM, wrote: > print "Invalid input.";raw_input("Press to close this window");exit > 1. Even if c is not 2 or 3, the program continues, as if it received a valid input, it does not exit as I have tried to code it to. In Python, exit isn't a statement, it's a function. So you need to write: exit() to actually terminate. > elif p==3 and c==3: > print "The result is :";x+y+z > 2. If all values are entered correctly, the result does not display. It shows up as "The result is :" and just blank. The semicolon ends the print statement, and then you simply evaluate and do nothing with the sum. Try a comma instead - that'll make it a second argument to print, so it'll be printed out as you expect. Thank you for making your problem so clear. You've given your code, and you've said exactly what it's doing that you don't expect. I really appreciate that! But one thing I would ask: Next time, please consider your subject line. That's the first chance you have to grab someone's attention - "VERY BASIC HELP" doesn't say _what_ you need help with. :) Your post makes a nice change from some I've seen, though... Have fun, happy Pythoning! ChrisA From gordon at panix.com Mon Sep 30 13:25:46 2013 From: gordon at panix.com (John Gordon) Date: Mon, 30 Sep 2013 17:25:46 +0000 (UTC) Subject: VERY BASIC HELP References: <380132bc-bc9c-4d57-95d8-dc01f26f47a5@googlegroups.com> Message-ID: In <380132bc-bc9c-4d57-95d8-dc01f26f47a5 at googlegroups.com> vignesh.harikrishna at gmail.com writes: > c=int(raw_input("How many numbers do you want to work? (Min. 2 Max. 3)")) > if c==2: > x=int(raw_input("Enter the first number to be worked")) > y=int(raw_input("Enter the second number to be worked")) > elif c==3: > x=int(raw_input("Enter the first number to be worked")) > y=int(raw_input("Enter the second number to be worked")) > z=int(raw_input("Enter the third number to be worked")) > else: > print "Invalid input.";raw_input("Press to close this window");exit > p=int(raw_input("Do you want to divide, subtract, add or multiply these numbers? (1=divide, 2=subtract, 3=add, 4=multiply)")) > if p==1 and c==2: > print "The result is : ";x/y > elif p==1 and c==3: > print "The result is :";x/y/z > elif p==2 and c==2: > print "The result is :";x-y > elif p==2 and c==3: > print "The result is :";x-y-z > elif p==3 and c==2: > print "The result is :";x+y > elif p==3 and c==3: > print "The result is :";x+y+z > elif p==4 and c==2: > print "The result is :";x*y > elif p==4 and c==3: > print "The result is :";x*y*z > else: > print "Invalid Input.";raw_input("Press to close this window") > That is my program. These are the problems I am having : > 1. Even if c is not 2 or 3, the program continues, as if it received a > valid input, it does not exit as I have tried to code it to. That's because your code is this: exit instead of this: exit() In other words, you're referring to the exit function, but not actually calling it. > 2. If all values are entered correctly, the result does not display. It > shows up as "The result is :" and just blank. That's because you're using a semicolon after the print statement. This code is really two completely separate statements: print "The result is : ";x/y It prints the message and then, as a separate action, it calculates the value of x/y (and then throws that value away, because it isn't assigned anywhere.) Use a comma instead of a semicolon, like this: print "The result is : ", x/y -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From vignesh.harikrishna at gmail.com Mon Sep 30 13:50:16 2013 From: vignesh.harikrishna at gmail.com (vignesh.harikrishna at gmail.com) Date: Mon, 30 Sep 2013 10:50:16 -0700 (PDT) Subject: VERY BASIC HELP In-Reply-To: <380132bc-bc9c-4d57-95d8-dc01f26f47a5@googlegroups.com> References: <380132bc-bc9c-4d57-95d8-dc01f26f47a5@googlegroups.com> Message-ID: <62dfe971-f28a-4b01-a696-b2099dacd91b@googlegroups.com> Thank you both so much! I'll be sure to make more pertinent subject lines now :) Thanks for the detailed explanations! Clearly, I've just started learning this language ~20 minutes before I made this post, and am still learning the basics. Do you guys know of any guides for a beginner? I am definitely willing to take the time to learn in depth :) From joel.goldstick at gmail.com Mon Sep 30 15:02:20 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 30 Sep 2013 15:02:20 -0400 Subject: VERY BASIC HELP In-Reply-To: <62dfe971-f28a-4b01-a696-b2099dacd91b@googlegroups.com> References: <380132bc-bc9c-4d57-95d8-dc01f26f47a5@googlegroups.com> <62dfe971-f28a-4b01-a696-b2099dacd91b@googlegroups.com> Message-ID: On Mon, Sep 30, 2013 at 1:50 PM, wrote: > Thank you both so much! I'll be sure to make more pertinent subject lines > now :) Thanks for the detailed explanations! Clearly, I've just started > learning this language ~20 minutes before I made this post, and am still > learning the basics. Do you guys know of any guides for a beginner? I am > definitely willing to take the time to learn in depth :) > check out the documentation links on python.org to start > -- > https://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From dufriz at gmail.com Mon Sep 30 15:57:08 2013 From: dufriz at gmail.com (dufriz at gmail.com) Date: Mon, 30 Sep 2013 12:57:08 -0700 (PDT) Subject: Do I really need a web framework? Message-ID: I want to set up a very simple website, and I need to know if it is necessary to use a web framework (e.g. Django) to do basic interactive operations such as receiving input from the user, looking up a database and returning some data to the user. I know that this is exactly the purpose of web frameworks, and that they work fine. However, I read somewhere that for small projects such operations can be managed without a web framework, just by using Python with mod_python or with the CGI module. Is this correct? What do you suggest, keeping in mind that I am a newbie and that my website project would be very simple and very small? Thanks From timothy.c.delaney at gmail.com Mon Sep 30 16:39:36 2013 From: timothy.c.delaney at gmail.com (Tim Delaney) Date: Tue, 1 Oct 2013 06:39:36 +1000 Subject: Do I really need a web framework? In-Reply-To: References: Message-ID: On 1 October 2013 05:57, wrote: > I want to set up a very simple website, and I need to know if it is > necessary to use a web framework (e.g. Django) to do basic interactive > operations such as receiving input from the user, looking up a database and > returning some data to the user. > I know that this is exactly the purpose of web frameworks, and that they > work fine. > However, I read somewhere that for small projects such operations can be > managed without a web framework, just by using Python with mod_python or > with the CGI module. Is this correct? > > What do you suggest, keeping in mind that I am a newbie and that my > website project would be very simple and very small? > There is no *need* to use a web framework. But a web framework can make things a lot easier for you. Have a look at webapp2: http://webapp-improved.appspot.com/ Tim Delaney -------------- next part -------------- An HTML attachment was scrubbed... URL: From gordon at panix.com Mon Sep 30 17:53:27 2013 From: gordon at panix.com (John Gordon) Date: Mon, 30 Sep 2013 21:53:27 +0000 (UTC) Subject: Do I really need a web framework? References: Message-ID: In dufriz at gmail.com writes: > I want to set up a very simple website, and I need to know if it is > necessary to use a web framework (e.g. Django) to do basic interactive > operations such as receiving input from the user, looking up a database > and returning some data to the user. No, it's not necessary. But depending on how large your website is, using a framework can end up being a lot less work than doing it from scratch. > What do you suggest, keeping in mind that I am a newbie and that my > website project would be very simple and very small? That depends on how you define "very simple" and "very small". For example, how many different pages will your website have? A login page? A search entry page? A search results page? A help page? An error page? A logout page? Any other pages? I worked on a project that did its own web handling from scratch, and frankly it was a nightmare. But it wasn't a small project, so yours might be doable. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From waynejwerner at gmail.com Mon Sep 30 18:16:12 2013 From: waynejwerner at gmail.com (waynejwerner at gmail.com) Date: Mon, 30 Sep 2013 15:16:12 -0700 (PDT) Subject: Do I really need a web framework? In-Reply-To: References: Message-ID: On Monday, September 30, 2013 2:57:08 PM UTC-5, duf... at gmail.com wrote: > I want to set up a very simple website, and I need to know if it is necessary to use a web framework (e.g. Django) to do basic interactive operations such as receiving input from the user, looking up a database and returning some data to the user. > > I know that this is exactly the purpose of web frameworks, and that they work fine. > > However, I read somewhere that for small projects such operations can be managed without a web framework, just by using Python with mod_python or with the CGI module. Is this correct? > > > > What do you suggest, keeping in mind that I am a newbie and that my website project would be very simple and very small? If it's small you want, Flask has worked quite well for me. Here's an example: from flask import Flask, render_template, redirect, request from import save_data, get_data app = Flask(__name__) @app.route('/') def main(): return render_template('index.html') @app.route('/data', methods=['GET', 'POST']) def data(): if request.method == 'POST': save_data(request.form.get('data')) else: return render_template('data.html', data=get_data()) It doesn't take much to tack SQLAlchemy on top of that for data access, and a couple hundred lines will give you quite a lot of power. HTH, W From roy at panix.com Mon Sep 30 21:00:47 2013 From: roy at panix.com (Roy Smith) Date: Mon, 30 Sep 2013 21:00:47 -0400 Subject: Do I really need a web framework? References: Message-ID: In article , dufriz at gmail.com wrote: > I want to set up a very simple website, and I need to know if it is necessary > to use a web framework (e.g. Django) to do basic interactive operations such > as receiving input from the user, looking up a database and returning some > data to the user. > I know that this is exactly the purpose of web frameworks, and that they work > fine. > However, I read somewhere that for small projects such operations can be > managed without a web framework, just by using Python with mod_python or with > the CGI module. Is this correct? > > What do you suggest, keeping in mind that I am a newbie and that my website > project would be very simple and very small? > > Thanks "Need" is a very difficult concept to pin down. At one level, no you don't need a framework. There's nothing that a framework does that you can't do yourself. On the other hand, there's a lot that frameworks do for you that if you didn't get for free, you'd be forced to do yourself. Something needs to accept connections on a socket, talk some HTTP to the thing on the other end, parse the presented URL, talk to your database, generate some HTML, etc. I'm sure you *can* do all that, but my guess is most of it has little or nothing to do with your core application, so it's just extra work you need to do to get where you want to be. There's lots of different frameworks. Django is certainly one of the major ones. It's very powerful, but it also has a bit of a steep learning curve (despite its excellent tutorial). I've used Tornado as well; it seemed quite a bit simpler and probably a better place to start for a first project. I'm sure other people will suggest some others. My recommendation is to read a bunch, pick one, and go with it. Don't try to roll everything yourself. There's a good (but, perhaps, outdated) list at https://wiki.python.org/moin/WebFrameworks. Of the ones listed, the only one I would really argue against is Zoap. As the wiki says, it is the granddaddy of all python web frameworks, but the world has figured out better ways to do things since then. From dmitrey15 at gmail.com Mon Sep 30 16:37:46 2013 From: dmitrey15 at gmail.com (dmitrey15 at gmail.com) Date: Mon, 30 Sep 2013 13:37:46 -0700 (PDT) Subject: [ANN] MATLAB fmincon now available in Python Message-ID: Hi all, current state of Python <-> MATLAB connection soft doesn't allow passing of function handlers, however, a walkaround has been implemented via some tricks, so now MATLAB function fmincon is available in Python-written OpenOpt and FuncDesigner frameworks (with possibility of automatic differentiation, example ). Future plans include MATLAB fsolve, ode23, ode45 (unlike scipy fsolve and ode they can handle sparse matrices), fgoalattain, maybe global optimization toolbox solvers. I intend to post the message to several forums, so to keep discussion in a single place use OpenOpt forum thread http://forum.openopt.org/viewtopic.php?id=769 Regards, D. From nikos at secure.superhost.gr Mon Sep 30 19:59:14 2013 From: nikos at secure.superhost.gr (nikos at secure.superhost.gr) Date: Mon, 30 Sep 2013 23:59:14 +0000 Subject: I haev fixed it Message-ID: <20130930235914.GB13553@secure.superhost.gr> http://superhost.gr/warning.html From barry at python.org Mon Sep 30 22:12:03 2013 From: barry at python.org (Barry Warsaw) Date: Mon, 30 Sep 2013 22:12:03 -0400 Subject: Released: Python 2.6.9 release candidate 1 Message-ID: <20130930221203.6eed7479@anarchist> Hello Pythoneers and Pythonistas, I'm happy to announce the availability of Python 2.6.9 release candidate 1. Python 2.6.9rc1 is a security-fix source-only release for Python 2.6. This means that general bug maintenance has ended, and only critical security issues are being fixed. It also means that no installers for Windows or Mac OS X will be provided. The last binary release of Python 2.6 was 2.6.6. Python 2.6.9 final is currently scheduled for Monday, October 28, 2013. Five years after the original release of Python 2.6, the 2.6.9 final release will be the last release of the Python 2.6 series. After this, all official maintenance of any kind for Python 2.6 will cease and the series will be retired. For ongoing maintenance, please see Python 2.7. Since 2.6.9 will be the last Python 2.6 release ever, I ask that you please download Python 2.6.9rc1, build it on your favorite platforms, and test it with your favorite code. You can report bugs to the Python bug tracker: http://bugs.python.org The source can be download from: http://www.python.org/download/releases/2.6.9/ You can also see what's changed since Python 2.6.8: http://www.python.org/download/releases/2.6.9/NEWS.txt Many thanks go out to the entire Python community for their contributions and help in making Python 2.6.9 available, especially Jyrki Pulliainen for his patch contributions. Enjoy, -Barry (on behalf of the Python development community) -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: not available URL: From yanxiaopei199 at gmail.com Mon Sep 30 22:25:58 2013 From: yanxiaopei199 at gmail.com (Thanatos xiao) Date: Tue, 1 Oct 2013 10:25:58 +0800 Subject: [Python-Dev] Released: Python 2.6.9 release candidate 1 In-Reply-To: <20130930221203.6eed7479@anarchist> References: <20130930221203.6eed7479@anarchist> Message-ID: Ooooooooooooooooooh?ths! 2013/10/1 Barry Warsaw > Hello Pythoneers and Pythonistas, > > I'm happy to announce the availability of Python 2.6.9 release candidate 1. > > Python 2.6.9rc1 is a security-fix source-only release for Python 2.6. This > means that general bug maintenance has ended, and only critical security > issues are being fixed. It also means that no installers for Windows or > Mac > OS X will be provided. The last binary release of Python 2.6 was 2.6.6. > > Python 2.6.9 final is currently scheduled for Monday, October 28, 2013. > Five > years after the original release of Python 2.6, the 2.6.9 final release > will > be the last release of the Python 2.6 series. After this, all official > maintenance of any kind for Python 2.6 will cease and the series will be > retired. > > For ongoing maintenance, please see Python 2.7. > > Since 2.6.9 will be the last Python 2.6 release ever, I ask that you please > download Python 2.6.9rc1, build it on your favorite platforms, and test it > with your favorite code. You can report bugs to the Python bug tracker: > > http://bugs.python.org > > The source can be download from: > > http://www.python.org/download/releases/2.6.9/ > > You can also see what's changed since Python 2.6.8: > > http://www.python.org/download/releases/2.6.9/NEWS.txt > > Many thanks go out to the entire Python community for their contributions > and > help in making Python 2.6.9 available, especially Jyrki Pulliainen for his > patch contributions. > > Enjoy, > -Barry > (on behalf of the Python development community) > > _______________________________________________ > Python-Dev mailing list > Python-Dev at python.org > https://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: > https://mail.python.org/mailman/options/python-dev/yanxiaopei199%40gmail.com > > -------------- next part -------------- An HTML attachment was scrubbed... URL: