From usernet at ilthio.net Wed Dec 1 01:15:12 2010 From: usernet at ilthio.net (Tim Harig) Date: Wed, 1 Dec 2010 06:15:12 +0000 (UTC) Subject: Reading by positions plain text files References: <39a07597-02b9-4ef8-9ca9-93e2d2425e66@p7g2000prb.googlegroups.com> Message-ID: On 2010-12-01, javivd wrote: > On Nov 30, 11:43?pm, Tim Harig wrote: >> On 2010-11-30, javivd wrote: >> >> > I have a case now in wich another file has been provided (besides the >> > database) that tells me in wich column of the file is every variable, >> > because there isn't any blank or tab character that separates the >> > variables, they are stick together. This second file specify the >> > variable name and his position: >> >> > VARIABLE NAME ? ? ?POSITION (COLUMN) IN FILE >> > var_name_1 ? ? ? ? ? ? ? ? 123-123 >> > var_name_2 ? ? ? ? ? ? ? ? 124-125 >> > var_name_3 ? ? ? ? ? ? ? ? 126-126 >> > .. >> > .. >> > var_name_N ? ? ? ? ? ? ? ? 512-513 (last positions) >> >> I am unclear on the format of these positions. ?They do not look like >> what I would expect from absolute references in the data. ?For instance, >> 123-123 may only contain one byte??? which could change for different >> encodings and how you mark line endings. ?Frankly, the use of the >> world columns in the header suggests that the data *is* separated by >> line endings rather then absolute position and the position refers to >> the line number. In which case, you can use splitlines() to break up >> the data and then address the proper line by index. ?Nevertheless, >> you can use file.seek() to move to an absolute offset in the file, >> if that really is what you are looking for. > > I work in a survey research firm. the data im talking about has a lot > of 0-1 variables, meaning yes or no of a lot of questions. so only one > position of a character is needed (not byte), explaining the 123-123 > kind of positions of a lot of variables. Then file.seek() is what you are looking for; but, you need to be aware of line endings and encodings as indicated. Make sure that you open the file using whatever encoding was used when it was generated or you could have problems with multibyte characters affecting the offsets. From jelari at gmail.com Wed Dec 1 02:07:03 2010 From: jelari at gmail.com (Ramprakash Jelari thinakaran) Date: Wed, 1 Dec 2010 12:37:03 +0530 Subject: Regarding searching directory and to delete it with specific pattern. Message-ID: Hi all, Would like to search list of directories with specific pattern and delete it?.. How can i do it?. Example: in /home/jpr/ i have the following list of directories. 1.2.3-2, 1.2.3-10, 1.2.3-8, i would like to delete the directories other than 1.2.3-10 which is the higher value?.. Regards, JPR. -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin at v.loewis.de Wed Dec 1 02:23:54 2010 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 01 Dec 2010 08:23:54 +0100 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename In-Reply-To: References: <4CF554ED.9050706@v.loewis.de> Message-ID: <4CF5F80A.8060804@v.loewis.de> > It'd be great if all programs used the same encoding on a given OS, > but at least on Linux, I believe historically filenames have been > created with different encodings. IOW, if I pick one encoding and go > with it, filenames written in some other encoding are likely to cause > problems. So I need something for which a filename is just a blob > that shouldn't be monkeyed with. In that case, you should use byte strings as file names, not character strings. Regards, Martin From martin at v.loewis.de Wed Dec 1 02:30:52 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Wed, 01 Dec 2010 08:30:52 +0100 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename In-Reply-To: References: <1291124813.414884.22.camel@WOPR> <4CF5AF71.3090705@mrabarnett.plus.com> Message-ID: <4CF5F9AC.7000203@v.loewis.de> > The world does not revolve around Python. Unix filenames have been > encoding-agnostic long before Python was around. If Python3 does not > support this then it's a regression on Python's part. Fortunately, Python 3 does support that. Regards, Martin From martin at v.loewis.de Wed Dec 1 02:33:23 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Wed, 01 Dec 2010 08:33:23 +0100 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename In-Reply-To: References: <1291124813.414884.22.camel@WOPR> Message-ID: <4CF5FA43.7020209@v.loewis.de> > This sounds like a strong prospect for how to get things working (I > didn't realize open would accept a bytes argument for the filename), > but I'm also interested in whether reading filenames from stdin and > subsequently opening them is supposed to "just work" given a suitable > encoding - like with Java which also uses unicode strings. In Java, > I'm told that ISO-8859-1 is supposed to "guarantee a roundtrip > conversion". It's the same in Python. However, as in Java, Python will *not* necessarily use ISO-8859-1 when you pass a (Unicode) string to open; instead, it will (as will Java) use your locale's encoding. Regards, Martin From smallpox911 at gmail.com Wed Dec 1 02:47:46 2010 From: smallpox911 at gmail.com (small Pox) Date: Tue, 30 Nov 2010 23:47:46 -0800 (PST) Subject: Watch the YANK CIA BUSTARDS Censorship live delete this post on KEY WIKILEAK REVELATIONS - RARE Message-ID: http://www.telegraph.co.uk/news/worldnews/northamerica/usa/8152326/WikiLeaks-release-Timeline-of-the-key-WikiLeaks-revelations.html WikiLeaks release: Timeline of the key WikiLeaks revelations By Jon Swaine in New York 6:53PM GMT 22 Nov 2010 December 2007: Guantanamo Bay operating procedures A US Army manual for soldiers at Camp Delta discloses that prisoners were denied access to the Red Cross for up to four weeks and that inmates could earn ?special rewards?, including a roll of lavatory paper, for good behaviour and co-operation. September 2008: Sarah Palin's email account Emails taken from the then-Republican Vice-Presidential candidate's personal account suggest that she has been using it for official business as Governor of Alaska. Doing so could have helped her avoid having her communications subjected to state laws on the disclosure of public records. November 2008: BNP membership list The names, addresses and occupations of more than 13,000 members of the far-Right British party are released in one file. The list shows that members include police officers, senior members of the military, doctors and other professionals. October 2009: Trafigura report An internal study about the effects of dumping waste by the energy trading company discloses that it used amateurish processes while dumping gasoline on the Ivory Coast and probably would have left dangerous sulphur compounds untreated November 2009: Climategate emails More than 1,000 emails sent between staff at the University of East Anglia's Climate Research Unit appeared to show that scientists distorted research to boost their argument that global warming was man- made, causing an international media storm. November 2009: September 11 pager messages About half a million pager messages sent in New York City on September 11, 2001, tell the story of the 9/11 terrorist attacks through individuals. Personal messages from people caught up in the carnage emerge, prompting criticism from commentators who claim the leak is an invasion of privacy. April 2010: Apache helicopter attack on journalists Video footage shows 15 people, including two people working for the Reuters news agency, being gunned down by a US Army helicopter in Iraq. The crew, who were not disciplined, mistook their targets' camera equipment for weapons. July 2010: Afghanistan war logs Tens of thousands of classified US military documents tell of the daily events of war in Afghanistan. The logs disclose that the Taliban is receiving greater assistance from the Pakistani intelligence services than was previously known and that the US runs a secret assassination squad. They also raise questions over potential crimes committed by coalition troops. October 2010: Iraq war logs Almost 400,000 classified US military documents recording the Iraq war suggest that evidence of the torture of Iraqis by coalition troops was ignored and record civilian deaths in more detail than was previously known. More than 66,000 civilians suffered ?violent deaths? between 2004 and the end of 2009, they show. From stefan_ml at behnel.de Wed Dec 1 02:55:14 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 01 Dec 2010 08:55:14 +0100 Subject: SAX unicode and ascii parsing problem In-Reply-To: References: <7fd52fd8-c6e0-48fa-bc50-1cff3354c3a3@u9g2000pra.googlegroups.com> Message-ID: goldtech, 30.11.2010 22:15: > Think I found it, for example: > > line = 'my big string' > line.encode('ascii', 'ignore') > > I processed the problem strings during parsing with this and it works > now. That's not the right way of dealing with encodings, though. You should open the file with a well defined encoding (using codecs.open() or io.open() in Python >= 2.6), and then write the unicode strings into it just as you get them. Stefan From smallpox911 at gmail.com Wed Dec 1 03:00:51 2010 From: smallpox911 at gmail.com (small Pox) Date: Wed, 1 Dec 2010 00:00:51 -0800 (PST) Subject: Iran slams Wiki-release as US psywar - WIKILEAKS is replacing those BIN LADEN communiques of CIA (the global ELITE) intended to threaten MASSES References: Message-ID: <2671169d-14b8-469d-bc56-d03bbefe807b@w2g2000yqb.googlegroups.com> Iran slams Wiki-release as US psywar - WIKILEAKS is replacing those BIN LADEN communiques of CIA (the global ELITE) intended to threaten MASSES CIA is the criminal agency of the global elite. They want to destroy the middle class from the planet and also create a global tyranny of a police state. http://presstv.ir/detail/153128.html http://presstv.ir/detail/153128.html http://presstv.ir/detail/153128.html Iran slams Wiki-release as US psywar Mon Nov 29, 2010 12:56PM Share | Email | Print Iran's President Mahmoud Ahmadinejad has questioned the recent 'leaked' documents published by Wikileaks website, describing them as part of a US "psychological warfare." In response to a question by Press TV on Monday over the whistleblower website's "leaks," President Mahmoud Ahmadinejad said "let me first correct you. The material was not leaked, but rather released in an organized effort." "The US administration releases documents and makes a judgment based on them. They are mostly like a psychological warfare and lack legal basis," President Ahmadinejad told reporters on Monday. "The documents will certainly have no political effects. Nations are vigilant today and such moves will have no impact on international relations," the Iranian chief executive added at the press briefing in Tehran. President Ahmadinejad stressed that the Wikileaks "game" is "not even worth a discussion and that no one would waste their time analysing them." "The countries in the region are like friends and brothers and these acts of mischief will not affect their relations," he concluded. Talks with the West The president announced that aside from Brazil and Turkey a number of other countries may take part in the new round of talks between Iran and the P5+1 -- Britain, China, France, Russia, the US, plus Germany. Human rights "They (Western powers) trample on the dignity of man, their identity and real freedom. They infringe all of these and then they call it human rights," Ahmadinejad said. Earlier this month, the UN General Assembly's Third Committee accused Iran of violating human rights regulations. The 118-member Non-Aligned Movement and the 57-member Organization of the Islamic Conference have condemned the resolution against the Islamic Republic. "In 2005, the human rights [issue] got a new mechanism in the United Nations ... human rights was pushed away and human rights was used for political manipulation," Secretary General of Iran's High Council for Human Rights Mohammed Javad Larijani told Press TV following the vote on the resolution. This is while the United Nations Human Rights Council reviewed the US human rights record for the first time in its history. The council then issued a document making 228 suggestions to the US to improve its rights record. IAEA 'leak' The president said that Iran has always had a positive relationship with the International Atomic Energy Agency but criticized the UN nuclear agency for caving under pressure from the "masters of power and wealth." The president said due to this pressure the IAEA has at times adopted "unfair and illegal stances" against the Islamic Republic. "Their recent one (IAEA report) is better than the previous ones and is closer to the truth but still all the facts are not reflected," he added. "Of course the latest report also has shortcomings, for example all [of Iran's nuclear] information has been released and these are secret and confidential documents belonging to the country." Ahmadinejad said since Iran was following a policy of nuclear transparency, it did not care about the leaks, but called the move 'illegal." New world order "The world needs order ? an order in which different people form different walks of life enjoy equal rights and proper dignity," the president said in his opening speech before taking questions form Iranian and foreign journalist. The president added that the world was already on the path to setting up this order. Iran isolation When asked to comment on the US and Western media claims that Iran has become highly isolated in the region despite an active diplomacy with Persian Gulf littoral states, the president said the remarks were part of the "discourse of hegemony." "In the hegemonic discourse, it seems that concepts and words take on different meanings than those offered by dictionaries," Ahmadinejad said. "When they say they have isolated Iran, it means that they themselves are isolated and when they say Iran is economically weak, it means that it has strengthened," the president reasoned. When they say there is a dictatorship somewhere, it means that country is really chosen by the people and vise a versa, the president further noted, adding, "I do not want to name names." ZHD/HGH/SF/MMN/MB Comments Add Comment Click Here Note: The views expressed and the links provided on our comment pages are the personal views of individual contributors and do not necessarily reflect the views of Press TV. check this out 11/30/2010 9:18:05 AMit is a coincidence that ?documents regarding Israel, their spying, influence peddling, suspicions of complicity in terrorism, Yemen, Iraq, Pakistan, Somalia, across Europe and even the Detroit bombing, those reports are there, they are classified but you will never see one on Wikileaks. In fact, they are the only classified information that never gets out to the news.? Ali 11/30/2010 7:47:47 AM"The world needs order ? an order in which different people form different walks of life enjoy equal rights and proper dignity,"very true! JHK 11/30/2010 7:37:09 AMIran should offer support to Western Media which is trying to portray the Truth. Moving these outlets outside the United States may help with this. Everyday American Citizens are at a loss as to what to do, and they need our support, some of them are Muslims. It's time4Africa 11/30/2010 7:19:25 AMDefinitely a zionist plot. All her enemies were bashed, and it was the only country to be praised in these 'leaks'. People are wiser and smarter now. "Fool me ones, shame on you. Fool me twice, shame on me!" SMARTI 11/30/2010 7:04:09 AMLOOK AT THE WESTERN MANIPULATING MEDIA, LIKE CNN FOX NEWS.FRONTPAGE HEADLINES LIKE; 'HOSTILITY TOWARDS IRAN BY NEIGHBORS'.BUT THIS LIE MEDIA ALWAYS FAILS TO MENTION THE ARAB PUBLIC OPINION TOWARDS IRAN! THEIR PROPAGANDA DON'T DISTINGUISH BETWEEN ARAB PEOPLE AND THEIR LEADERS! REASON?!: DIVIDE AND RULE!. THIS PRINCIPLE NEVER CHANGES!. IRAN BE CAREFULL, REMEMBER WHAT HIZBOLLAH LEADER ONCE SAID:THEY HAVE FAILED ON ALL THEIR PLOTS, THEY WILL TRY THEIR LAST ATTEMPT BY CREATING SUNNI-SHIA DIVISIONS 11/30/2010 6:49:48 AMI ask Sunni brothers to view Shiite not as a different religion but as a different school of thought. For example we have Hanafi, Hanbaly, etc... within Sunni Islam, why not view Shia also as such? The differences are not in the paradigm, therefore unity can be maintained. IRAN IS TOO WISE FOR CIA 11/30/2010 6:27:35 AMTHE USA IS USING WIKILEAKS TO CO-ORDINATE AND RELEASE MATERIAL WITH ALL THE OTHER STUFF TO MAKE IT LOOK LIKE IT WAS WIKILEAKS BUT IT ISNT IT IS THE CIA AND IN THIS WAY THEY CAN CAUSE PROBLEMS FOR IRAN AND NEIGHBOURING COUNTRIES. IRAN rules 11/30/2010 5:54:27 AMWIKILEAKS, IS AMERICA NEW PUBLIC RELATION TOOLS.WIKILEAKS IS HEAVELY INFLUENCED BY AMERICAN DOLLARS.AS USUAL AMERICA HIDE ITS CRIMES BY THIS TYPE OF MISINFORMATION. ify1979 11/30/2010 5:21:30 AMwiki leaks is just a proppganda game its playing wih iran! The Open Conspiracy 11/30/2010 4:36:52 AMThis is a plan that Winston Churchill had predicted would be the policy for the New World Order. Tony Blair was a typical "spill the beans" kind of speaker and the new ones are copying his style, sometimes chuckling as they make their statements. mumbo 11/30/2010 4:32:13 AMI almost think that there has never been a military coup in the US cause the military always gets (almost) all the money it wants. So the head of state has to take care of the military apparatus sustain their need for growing budgets and ongoing conflicts whether it was the red indians, french, spanish of the 19th century or the germans, vietnamese, arabs, soviets etc of the 20th and 21st century and beyond 11/30/2010 2:59:05 AMWhat many seem to have forgotten is that the so- called anti-Iranian sentiments of all the Arab PG states have been constantly touted by Western media for quite a while, long before these "leaks". Such news were also reported by PressTV and you don't think Iranians know what's going on? @ Political Game 11/30/2010 2:55:16 AMThe media is a great tool if one knows how to use it, and one of the oldest tricks in the game is a controlled leak. This is the case here. Sure, you can fool a few ignorant westerners with this trick, but Iran is an old and civilized country. Your tricks won't work here. The game is up. 11/30/2010 2:39:42 AMDamage Control by Iran's President who is rushing in, I would recommend him to be on "wait and see" mode rather than making any comments. Wikileaks may be RIGHT and maybe NOT. Political Game 11/30/2010 2:25:14 AMPresident Ahmadinejad is in denial, He knows that Wikileaks files are based on FACTS & TRUETH, however to show the world and assure the neighbouring countries(Saudis, UAE, Bahrain,etc) that Iran won't buy those facts. Just a little Political Game going on here. PEACE 11/30/2010 2:12:46 AMIt is a fabrication, how come 1/4 millions documents leak and some must br fake. @european 11/30/2010 2:07:23 AMThese are also not leaks because there are strategic elements in the contents to achieve certain agenda as with Iran and certain other countries only. Well said John Ellis 11/30/2010 1:56:06 AMThe Western media is owned by builderbergs who sees the public as dispensable items that can be best served at the lowest level of cognitive recall of events without inference, deduction, analysis, and any form of reasoning. The truth is the public may be ahead of the builderbergs in at least not tuning in as predicted. No body is in charge. So, the builderbergs have opted for offshore investments and outsourcing for the last couple of decades. The dynamics continue to indicate a bizarre future. Ranim Kalif 11/30/2010 1:46:55 AMRumour has it... That wikileaks is nothing but a CIA propaganda/counter propaganda program. The proof lies with The head honcho Julian Asange. Apparently Mr. Asange believes that 9/11 was done by fanatics from a cave in afghanistan, but anyone with half a brain can tell you that 3 steel framed building cannot collapse due to fire, its just not mathematically possible. And math does not lie, but people do. @Anti-bully 11/30/2010 12:54:13 AMAfter this week, you can retrospectively analyse and find more clues from the so-called WL documents that can be told now based on extrapolation using systemic hypocrisy templates. The West is so easy to read in either way. But, stay on the objective track. Anti-bully 11/30/2010 12:22:43 AM(Cont.) After the "Second Wikileaks" a month ago I said: "The answer to the Western idiocy is simple: Iran, Iraq & Afghanistan are neighbours, and you [[]the West INCL. Israel] DON'T BELONG THERE! SHOO!" Those neighbours of course include: Pakistan, Turkey, Azerbaijan, Syria, Lebanon, Central Asia, .... Revenge and Blessing 11/30/2010 12:12:39 AMRevenge is like Hurricane Katrina, California forest fire, American soldiers' suicides, Gulf of Mexico Spills, US rescue helicopters colliding and falling in an Iranian desert ....Blessings come with gentle earthquakes as wake-up calls to improve construction of buildings, wisdom to take technological leaps, intelligence to see the Wikileak psychological warfare,.... John Ellis 11/30/2010 12:06:17 AMWikiLeaks is doing to the public what Western corporate media does each and every day -- keep society locked in darkness by not saying a word about the root cause or solution to a problem, disclosing only the confusion, controversy, blood and guts of a problem, until finally the people in disgust back away and let the corporate rich to be enriched by the problem. Iranians know from their history 11/29/2010 11:57:39 PMthat when their leaders are liked by the West the country is in trouble and vice versa when the leaders are criticized by the West they must be very good leaders! New World Order = Slavery For All 11/29/2010 11:47:02 PMIt is already evident in the West through the public disenchantment and the authority's unwillingness to serve the public as before. The governments are not doing their usual services as if they are preparing to run slave camps soon. There are lots of telltales like trampling on constitutional rights that are bothersome. Saul 11/29/2010 11:36:33 PMI hear that the President Of Iran will soon be impeached. Is this true. Iran helps because Iran believes in God 11/29/2010 11:32:12 PM...and helps even those who have attacked Iran in the past. Because Iran does not believe in revenge like the West that is for ever occupying Germany, Japan, South Korea, etc. Iran knows better that revenge is best left to God. european 11/29/2010 10:51:03 PMThese are not leaks at all. They never compliment or give more attention to such things... just like 9/11, nobody could suggest a possiblity of an inside job. Nobody. So how come, Assange comes in and publish leaks and he becomes an idol of masses?This is one big joke.The US behaves like a shaitan, then issues a represantative to openly admit that their country belongs to the devil. AB 11/29/2010 10:49:56 PMToday popularity contest is base on economic liberty not on propaganda policy. If Iran didn?t help Lebanon or Iraq to back on their feet, today had no popularity the same as Egypt. Abd 11/29/2010 10:02:12 PMThe enemies of humanity who think they have saved a face behind addiction, corruption and oppression of even their citizens are actually at an ideological dead end. The US demons and their Salary worshiper pupits in the almost expired UN should cry their heart out and get drunk before lying about Iran. Sincerely.www.criesofdarwinism.com Iranian 11/29/2010 10:00:35 PMAnd some people criticize his foreign policy. this announcement is something that every Iranian can be proud of, proud of their president, unfortunately it is fashionable to criticize or insult Ahmadinejad without any reason thanks to zionist media. To Anti-Bully 11/29/2010 10:00:00 PMEven when there is a physical court, it is inconspicuously hollowed out in favour of the Western dictatorships that pretend to be democratic. scott68 11/29/2010 9:53:56 PMcertain comments that were leaked to the western media from Wikileaks is being used by western media to create a hostile climate on the subject of say for example Iran's nuclear program by using the names of certain key leaders in the middle east who have said the US should attack Iran to prevent them obtaining nuclear weapons it seems as though the western media want to create a hostile reaction towards Iran with this information Anti-bully 11/29/2010 9:51:10 PMThe 3-step Wikileaks (WL) rocket. First WL: US army atrocities. 2nd WL: People in ME kill and bribe each other (which according to West's fascist "logic" makes it OK if US/UK/NATO/Israel do it as well). 3rd WL: The big fish panjandrums are in on it. IOW: 1) "We, WEST, have the muscles", 2) "You, ME, deserve what's coming to you" 3) "WE-HAVE-THE-POWER". Conclusion: "You, the "REST", can do ZIT!". @Anti-bully 11/29/2010 9:38:54 PMAffirmative! Took me more than 45 years in the West to research the systemic anatomy of hypocricy. You have come a long way, and so have most of those who have commented here. Anti-bully 11/29/2010 9:18:07 PMWest, when it deems convenient, shows evidences of it's atrocities (Vietnam files, Wikileaks, Abu Ghraib pics) and boohoos "look how TERRIBLE we are", but you wouldn't SEE the smirk. Of course, some evidences could hold in a court of law, but what if there is NO court? This makes the Anglo-American psycho-West grin even wider. IOW, West gets off flaunting how disgusting it can be. You think Iran was joking when calling them "Great Satan"? PIONEER 11/29/2010 8:58:05 PMso it's true (and quoted by iran) when it's about the u.s. and the west, but untrue when it's about iran? EB 11/29/2010 8:30:55 PMSo when something bad about the US is released by wikileaks, Iran agrees with them, but when something bad about Iran comes out, they say it's not true and planned by the west.. Wonderful double standards. PressTV is a joke, and it's just like FoxNews, completely biased. Katifa 11/29/2010 8:22:24 PMI wish Ahmadinejad would go into more detail as to why he feels the US benefits from this leak. I don't understand his point of view and usually I do! mumbo 11/29/2010 7:52:07 PMsome of the statements by Bahraini, UAE or Saudi Arab leaders would have never been made, even in private if it weren't for certain imperialist powers constantly dabbling in this region. Now that they do dabble, it should be treated as private thoughts - nothing more nothing less. However let s remember that it was superpower support of Saddam Hussein that got many arab leaders to dole money to Saddam fighting the Persians. hussain mehdi 11/29/2010 7:33:06 PMthis is leak??? first they announce and then they publish leak!!! this is leak??? is this leak??? 11/29/2010 7:13:06 PMYhere was time Muslims were divided in Shia and Sunni but the Ediots of West have helped us to get rid of the prejudices and now Thanks God we are one. Iran was always Great Shia Nation and Turkey Great Sinni Nation. Now they Mashallah are Great Islamic Nation. subhan Allah. The enemy has cut its own throat. fred Kay 11/29/2010 6:15:06 PMALL ARAB COUNTRIES HAVE PUPPET GOVERNMENTS PUT IN POWER BY THE MASTERS IN THE WEST.MUSLIM BROTHERHOOD WITH ARABS?!MY FOOT,WHAT POSITIVE STEPS HAVE THEY TAKEN TOWARDS IRAN?,NONE.IRAN MUST PAY THEM IN KIND AND SHAKE THEIR GLASS HOUSES.ISRAEL IS RIGHT TO GIVE THEM A BLOW EVERY TIME THEY OPEN THEIR BRAINLESS MOUTHS. Pak 11/29/2010 6:12:52 PMHis Excellency Mr. AhamdiNejad is a great leader of Muslim nation.And the arrogant powers are scared from this thing.For Non Muslims nations there is nothing Shia or Sunni only Muslims.And these Non Muslims nations always try their best to use all resources to make difference between Muslims. RESON 11/29/2010 5:51:43 PMWEST HAVE BIG SOCIAL PROBLEM & THAT IS THRUST BETWEEN ITS PEAPOL V GOVT TO BUILD THAT THRUST NEED TO PROVE DOMACRECY EXCICT. IRAQ WAR PRODUCE BIG MASS OF SOCIAL UNREST INWEST IN TOTAL. THE LEAK WORKS LIKE PRESUR COOKER.HAVE RELISE AIR OUT Abu bukk 11/29/2010 5:34:50 PMVery well said asgar I'm a Muslim Sunni aswell and I agree that all Muslims are brothers wa Salam Albert Hakim 11/29/2010 4:56:39 PMWhat if this is a real leak?! Then what? I think if Iranians are smart, they should give it a possibility. I believe, Iranians should not trust Arabs who have proven to be America's servants in the Middle East. Truth seeker 11/29/2010 4:42:26 PMThe Council on Foreign Relations (most influential foreign-policy think tank), are the secret rulers of every country and they can knock out anyone who doesn't obey their rules. Make for Public 11/29/2010 4:27:41 PMWikileaks is an Zionist Agent Provocateur, Period. sana 11/29/2010 4:09:26 PMThis is a cheap game and will not work at all. if they think people in the ME are stupid; they prove themselves to be stupid. At the end of the day, they will be the losing party. We consider themselves brothers and sisters and will remains so. Days of colonialism and imperialism are over. You cannot rule the whole China with a bunch of colonial thiefs anymore. ASGAR 11/29/2010 3:43:47 PMIM a Sunni if the west or Arab Leaders are trying to divide shia and Sunni they will fail with me, my friends and people i talk to. We all see the Good Iran is doing and i hope it will bring us closer and end the man made divied of sunni /shia for good. south african 11/29/2010 3:39:24 PMAgreed. America would have stopped this if they were not behind it. They are a super power and should be able to stop some man from stealing their top secret documents, which are probably hidden inside a thick vault with 10 CIA agents guarding it. James 11/29/2010 3:38:07 PMIran has not fallen for childish Amreican tricks. Congratulations. Iran knows Wiki and other such attempts are ploys of its enemies. Every child can see throught them. Ernest in USA 11/29/2010 3:37:56 PMSince our government has lost all its credibility with us Americans due to its lies to get us in a war against Iraq, it has to release propaganda through other sources, like wikileaks. These are not leaks, but deliberate propaganda attempts to incite hatred against Iran, and division between Muslim governments. We Americans are not falling for it! Former US Marine 11/29/2010 3:27:28 PMWikileaks spreads the OFFICIAL 9/11 propaganda and even says Bin Laden is still alive. So funny. Anyone with half a brain knows that 9/11 was a DEMOLITION done by Israel and Zionist Traitors. Wikileaks is 100[[]%] Zionist approved propaganda. Wikileaks = controlled opposition NY 11/29/2010 3:22:45 PMPresident Ahmadinejad is absolutely correct in what he says. It is so nice to read facts and not the lies and deceptions in the US media that even a baby can see through. Long live Iran! Londoner 11/29/2010 3:20:37 PMThe leaks said Netanyahu is "a charming man." Most other leaders were insulted. Guess who is behind these "leaks." KIKI 11/29/2010 3:06:24 PMLOOK ONLY TO THE MEDIA THAT WIKILEAKS HAVE CHOSEN TO GIVE THEM THE SO/CALLED LEAKS, DER SPIEGEL AND LE MONDE ARE THE SAME MEDIA THAT PUBLISHED THE SO/CALLED ACCUSATIONS OF HIZBOLLAH ON THE HARIRI CASE. I WONDER WHY THE ISRAELI MEDIA LOOKS SOO HAPPY ABOUT ALL THIS. WHY THEIR IS SOO FEW THINGS ABOUT ISRAEL IN THE SO/CALLED LEAKS. IT DOESNT SEEM RATIONAL THAT ONE MAN CAN LEAK SOOO MUCH OF THE SO/CALLED SECRET DOC. bob 11/29/2010 3:03:01 PMWikileaks is israel!!!! Its so obvious!! truthseeker 11/29/2010 2:59:23 PMJulian Assange works for the cia and is also funded by George Soros. Do you really think that this guy would still be walking around as freely as he does if they did not want this info out. This guy is well known in the alternative media for being funded by soros and why does he release the info first to state controlled newspapers, why not alternative news, which is getting bigger by the day. CD 11/29/2010 2:58:04 PMYes, President Mahmoud Ahmadinejad is right and we should all come together united against western imperialisme. Unity and Tolerance amongst the people is the "Leitmotive" and a new equale world order,permetting us to secure the future of the humanity and making this world a better place to live for our children. Nick 11/29/2010 2:57:03 PMThe US government controls our finances eg. wall street derivatives... They control our business, eg. government motors (GM)... and they control our press, along with all these so-called 'Wiki leaks' ! To All Iranians 11/29/2010 2:22:30 PMAlways ask yourselve what is the consequence of what you say in reacting to hearsay accounts like WikiLeak stories. Your enemies live in hypocricy. They force international commissions like IAEA to act and report in hypocricy. They demonstrate in their own courts to judge as hypocrites. They blame you and find you guilty with hypocricy. Do not fall for it. Demand facts and proofs. Rely on the verified public statements of leaders. Show your enemies that they are the stupid ones. Iranian 11/29/2010 2:12:43 PMWell, it's quite obvious. lots of was about Iran and how Iran hated by american puppets in the middle east. and also some ridiculous useless about some other things that we already knew about them, just to make the whole thing acceptable. I really thought that they would prepare the material much better than the first time. but it was even more obvious who leaked those. Seems they are getting sloppy and desperate. Common Sense 11/29/2010 1:51:01 PMChances leak ever to survive World of Zionis regime that include US. Agent will be assassinate period (even their President). Infomation need to be filted carefully and wisely. To good to be true for sure. Pakistani 11/29/2010 1:49:44 PMAhmadinejad is very wise to ignore wikileaks revelations by branding it a propagenda.Although you have to be very naive to actually believe this is a propaganda but Ahmadinejad is right to call it a propaganda in public. I would have done the exact same thing. Disagreement between iran and saudiarabia should never turn into a war between sunni and shias. Mona Montgomery 11/29/2010 1:40:45 PMMohammed, thank you for explaing that. Mohammed 11/29/2010 1:16:40 PMYes, very smart man. I think the same thing. There is something not quite right about the Wikileaks. Maybe the this whole 'leak' thing is a controlled dissent by the Western powers. The real juicy stuff will stay in storage for the next 100 years. From nobody at nowhere.com Wed Dec 1 03:43:51 2010 From: nobody at nowhere.com (Nobody) Date: Wed, 01 Dec 2010 08:43:51 +0000 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename References: <1291124813.414884.22.camel@WOPR> Message-ID: On Wed, 01 Dec 2010 02:14:09 +0000, MRAB wrote: > If the filenames are to be shown to a user then there needs to be a > mapping between bytes and glyphs. That's an encoding. If different > users use different encodings then exchange of textual data becomes > difficult. OTOH, the exchange of binary data is unaffected. In the worst case, users see a few wrong glyphs, but the software doesn't care. > That's where encodings which can be used globally come in. > By the time Python 4 is released I'd be surprised if Unix hadn't > standardised on a single encoding like UTF-8. That's probably not a serious option in parts of the world which don't use a latin-based alphabet, i.e. outside western Europe and its former colonies. In countries with non-latin alphabets, existing encodings are often too heavily entrenched. There's also a lot of legacy software which can only handle unibyte encodings, and not much incentive to fix it if 98% of your market can get by with an ISO-8859- locale (making software work in e.g. CJK locales often requires a lot more work than just dealing with encodings). And it doesn't help that Windows has negligible support for UTF-8. It's either UTF-16-LE (i.e. the in-memory format dumped directly to file) or one of Microsoft's non-standard encodings. At least the latter are mostly compatible with the corresponding ISO-8859-* encoding. Finally, ISO-8859-* encoding/decoding can't fail. The result might be complete gibberish, but converting to gibberish then back to bytes won't lose information. From mail at timgolden.me.uk Wed Dec 1 03:48:45 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 01 Dec 2010 08:48:45 +0000 Subject: Catching user switching and getting current active user from root on linux In-Reply-To: <1a9bdbd4-2997-4e0f-a24f-cd148247e312@r40g2000prh.googlegroups.com> References: <1a9bdbd4-2997-4e0f-a24f-cd148247e312@r40g2000prh.googlegroups.com> Message-ID: <4CF60BED.8020904@timgolden.me.uk> On 30/11/2010 22:47, mpnordland wrote: > I have situation where I need to be able to get the current active > user, and catch user switching eg user1 locks screen, leaves computer, > user2 comes, and logs on. > basically, when there is any type of user switch my script needs to > know. If it's Windows you're on, have a look at this: http://timgolden.me.uk/python/win32_how_do_i/track-session-events.html TJG From steve+comp.lang.python at pearwood.info Wed Dec 1 03:54:49 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Dec 2010 08:54:49 GMT Subject: Change one list item in place References: <17175f49-087f-4d05-ada2-7e8c7e7e86dd@z17g2000prz.googlegroups.com> Message-ID: <4cf60d59$0$30003$c3e8da3$5496439d@news.astraweb.com> On Tue, 30 Nov 2010 17:08:57 -0800, Gnarlodious wrote: > This works for me: > > def sendList(): > return ["item0", "item1"] > > def query(): > l=sendList() > return ["Formatting only {0} into a string".format(l[0]), l[1]] For the record, you're not actually changing a list in place, you're creating a new list. I would prefer: def query(): l = sendList() l[0] = "Formatting only {0} into a string".format(l[0]) return l which will continue to work even if sendlist() gets changed to return 47 items instead of 2. An alternative would be: -- Steven From ulrich.eckhardt at dominolaser.com Wed Dec 1 03:57:54 2010 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Wed, 01 Dec 2010 09:57:54 +0100 Subject: SAX unicode and ascii parsing problem References: <7fd52fd8-c6e0-48fa-bc50-1cff3354c3a3@u9g2000pra.googlegroups.com> Message-ID: <19fhs7-sac.ln1@satorlaser.homedns.org> goldtech wrote: > I tried this but nothing changed, I thought this might convert it and > then I'd paerse the new file - didn't work: > > uc = open(r'E:\sc\ppb4.xml').read().decode('utf8') > ascii = uc.decode('ascii') > mex9 = open( r'E:\scrapes\ppb5.xml', 'w' ) > mex9.write(ascii) This doesn't make sense either. decode() will convert bytes into (Unicode) characters. After the first decode('utf8'), you have those already. Calling decode('ascii') on that doesn't make sense. If you want ASCII, as the assignee suggests, you need to _encode_ the string. Be aware that not all characters can be represented as ASCII though, and the presence of such a character seems to have caused your initial problem. BTW: - XML is not necessarily UTF-8, but that's a different issue. - I would suggest you open files with 'rb' or 'wb' in order to suppress any conversions on line endings. Especially writing UTF-16 would fail if that is active. Good luck! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From solipsis at pitrou.net Wed Dec 1 04:12:51 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Wed, 1 Dec 2010 10:12:51 +0100 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename In-Reply-To: References: <339421.80548.qm@web54205.mail.re2.yahoo.com> <20101130161919.693a1d78@pitrou.net> Message-ID: <20101201101251.51c83197@pitrou.net> On Tue, 30 Nov 2010 16:57:57 -0800 Dan Stromberg wrote: > >> --- On Tue, 11/30/10, Dan Stromberg wrote: > >> > In Python 3, I'm finding that I have encoding issues with > >> > characters > >> > with their high bit set.? Things are fine with strictly > >> > ASCII > >> > filenames.? With high-bit-set characters, even if I > >> > change stdin's > >> > encoding with: > >> [...] > > I have the same problem using 3.2alpha4: the word man~ana (6 > characters long) in a filename causes problems (I'm catching the > exception and skipping the file for now) despite using what I believe > is an 8-bit, all 256-bytes-are-characters encoding: iso-8859-1. 'not > sure if you wanted both of us to try this, or Yingjie alone though. What do sys.stdin.encoding and sys.getfilesystemencoding() return? If they are different, then it's the cause of the problem, since sys.getfilesystemencoding() is used by open() to encode filenames. In this case, the solution is to encode filenames yourself using sys.stdin.encoding, or read them as bytes directly from sys.stdin.buffer (which is the binary non-unicode counterpart of sys.stdin). If they are the same, then I guess you can open an issue, provided you give enough indications for people to reproduce :) Regards Antoine. From steve+comp.lang.python at pearwood.info Wed Dec 1 04:14:35 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Dec 2010 09:14:35 GMT Subject: Change one list item in place References: <17175f49-087f-4d05-ada2-7e8c7e7e86dd@z17g2000prz.googlegroups.com> <4cf60d59$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cf611fb$0$30004$c3e8da3$5496439d@news.astraweb.com> On Wed, 01 Dec 2010 08:54:49 +0000, Steven D'Aprano wrote: > An alternative would be: > Please ignore. That was an accidental Send mid-edit. -- Steven From solipsis at pitrou.net Wed Dec 1 04:15:41 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Wed, 1 Dec 2010 10:15:41 +0100 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename References: <1291124813.414884.22.camel@WOPR> <4CF5AF71.3090705@mrabarnett.plus.com> <1291173721.687410.18.camel@WOPR> Message-ID: <20101201101541.7d2adaa9@pitrou.net> On Tue, 30 Nov 2010 22:22:01 -0500 Albert Hopkins wrote: > And I can freely copy > these "invalid" files across different (Unix) systems, because the OS > doesn't care about encoding. And so can Python, thanks to PEP 383. > > That's where encodings which can be used globally come in. > > By the time Python 4 is released I'd be surprised if Unix hadn't > > standardised on a single encoding like UTF-8. > > I have serious doubts about that. At least in the Linux world the > kernel wants to stay out of encoding debates (except where it has to > like Window filesystems). That doesn't matter. Vendors (Linux distributions) have to make a choice and that choice will probably standardize on UTF-8 in most situations. The kernel won't have a say, since it doesn't care about encodings anyway. > The world does not revolve around Python. Unix filenames have been > encoding-agnostic long before Python was around. If Python3 does not > support this then it's a regression on Python's part. Python 3 does support it, see other messages about using bytes filenames. Regards Antoine. From solipsis at pitrou.net Wed Dec 1 04:24:09 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Wed, 1 Dec 2010 10:24:09 +0100 Subject: To Thread or not to Thread....? References: Message-ID: <20101201102409.686e016f@pitrou.net> On Wed, 1 Dec 2010 02:45:50 +0000 Jack Keegan wrote: > Hi there, > > I'm currently writing an application to control and take measurements during > an experiments. This is to be done on an embedded computer running XPe so I > am happy to have python available, although I am pretty new to it. > The application basically runs as a state machine, which transitions through > it's states based on inputs read in from a set of general purpose > input/output (GPIO) lines. So when a certain line is pulled low/high, do > something and move to another state. All good so far and since I get through > main loop pretty quickly, I can just do a read of the GPIO lines on each > pass through the loop and respond accordingly. > However, in one of the states I have to start reading in, and storing frames > from a camera. In another, I have to start reading accelerometer data from > an I2C bus (which operates at 400kHz). I haven't implemented either yet but > I would imagine that, in the case of the camera data, reading a frame would > take a large amount of time as compared to other operations. Therefore, if I > just tried to read one (or one set of) frames on each pass through the loop > then I would hold up the rest of the application. Conversely, as the I2C bus > will need to be read at such a high rate, I may not be able to get the > required data rate I need even without the camera data. This naturally leads > me to think I need to use threads. > As I am no expert in either I2C, cameras, python or threading I thought I > would chance asking for some advice on the subject. Do you think I need > threads here or would I be better off using some other method. I was > previously toying with the idea of using generators to create weightless > threads (as detailed in > http://www.ibm.com/developerworks/library/l-pythrd.html) for reading the > GPIOs. Do you think this would work in this situation? The main question IMO: the I2C bus operates at 400kHz, but how much received data can it buffer? That will give you a hint as to how much latency you can tolerate. I don't think soft threads would work at all, since they wouldn't allow overlapping between frame reading and other ops. If frame reading releases the GIL (as any properly implemented IO primitive in Python should), then at least you can try using OS threads. Then, depending on the tolerable latency for I2C operation, you can try to run it as an OS thread, or a separate process (if running as a separate process, make sure it cannot block while sending IO to the master process). Regards Antoine. From steve+comp.lang.python at pearwood.info Wed Dec 1 04:26:05 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Dec 2010 09:26:05 GMT Subject: Programming games in historical linguistics with Python References: Message-ID: <4cf614ad$0$30003$c3e8da3$5496439d@news.astraweb.com> On Tue, 30 Nov 2010 07:03:28 -0800, Dax Bloom wrote: > Is there a way to refer to vowels and consonants as a subcategory of > text? Is there a function to remove all vowels? How should one create > and order the dictionary file for the rules? How to chain several > transformations automatically from multiple rules? Finally can anyone > show me what existing python program or phonological software can do > this? Have you looked at NLTK? http://www.nltk.org/ The questions you are asking are awfully specific for a general programming forum like this. You might have better luck asking on a NLTK forum, or possibly if you could pose your questions in ways that don't assume extensive familiarity in linguistics ("word nucleus"? "codas"?). Is there a function to remove vowels -- not specifically, but provided you can tell us what characters you wish to treat as vowels, and provided you are satisfied with a fairly simple search-and-replace, this will do it: # For Python 2.x def disemvowel(s): """Quick and dirty disemvoweller.""" tbl = string.maketrans('', '') return string.translate(s, tbl, "aeiouAEIOU") If you want a function that can distinguish between Y being used as a vowel from Y being used as a consonant, you'll need something much more sophisticated -- try the NLTK. -- Steven From __peter__ at web.de Wed Dec 1 04:34:24 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 01 Dec 2010 10:34:24 +0100 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename References: <1291124813.414884.22.camel@WOPR> Message-ID: Nobody wrote: > Python 3.x's decision to treat filenames (and environment variables) as > text even on Unix is, in short, a bug. One which, IMNSHO, will mean that > Python 2.x is still around when Python 4 is released. For filenames in Python 3 the user has the choice between "text" (str) and bytes. If the user chooses text that will be converted to bytes using a default encoding that hopefully matches that of the other tools on the machine that manipulate filenames. I see that you may run into problems with the text approach when you encounter byte sequences that are illegal in the chosen encoding. I therefore expect that lowlevel tools will use bytes to manipulate filenames while end user scripts will choose text. I don't see how a dogmatic bytes only restriction can improve the situation. Also, you can already provide unicode filenames in Python 2.x (and a script containing constant filenames becomes more portable if you do), so IMHO the situation in Python 2 and 3 is similar enough as to not hinder adoption of 3.x. Peter From vithyam6 at gmail.com Wed Dec 1 04:37:16 2010 From: vithyam6 at gmail.com (cinema) Date: Wed, 1 Dec 2010 01:37:16 -0800 (PST) Subject: HOW TO EARN MONEY FROM FOREX TRADING ONLINE? Message-ID: <276e0e3e-c43f-4f63-9840-941ac1d03223@e16g2000pri.googlegroups.com> http://forextradingonlinetoday.blogspot.com http://forextradingonlinetoday.blogspot.com http://forextradingonlinetoday.blogspot.com http://forextradingonlinetoday.blogspot.com http://forextradingonlinetoday.blogspot.com From dudeja.rajat at gmail.com Wed Dec 1 04:53:59 2010 From: dudeja.rajat at gmail.com (dudeja.rajat at gmail.com) Date: Wed, 1 Dec 2010 15:23:59 +0530 Subject: Login using usrllib2 Message-ID: Hi All, I'm using urllib2 module to login to an https server. However I'm unable to login as the password is not getting accepted. Here is the code: import urllib2, urllib values={'Username': 'admin', 'Password': 'admin123'} url='https://172.25.17.20:9443' data = urllib.urlencode(values) data = urllib.urlencode(values) req = urllib2.Request(url, data) response = urllib2.urlopen(req) the_page = response.read() print the_page The error message I get in the_page output is the same as I get when I access this site using a browser and supply a wrong password. It appears password is not accepting. I'm new to web programming. The aim is to automate user clicks on a web server which can be replicated using python and http. Please suggest / help. Regards, Rajat -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Wed Dec 1 05:16:46 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 1 Dec 2010 02:16:46 -0800 Subject: Login using usrllib2 In-Reply-To: References: Message-ID: On Wed, Dec 1, 2010 at 1:53 AM, wrote: > Hi All, > > > I'm using urllib2 module to login to an https server. However I'm unable to > login as the password is not getting accepted. > > Here is the code: > > import urllib2, urllib > values={'Username': 'admin', 'Password': 'admin123'} > url='https://172.25.17.20:9443' > data = urllib.urlencode(values) > > > data = urllib.urlencode(values) > req = urllib2.Request(url, data) > response = urllib2.urlopen(req) > the_page = response.read() > print the_page > > The error message I get in the_page output is the same as I get when I > access this site using a browser and supply a wrong password. It appears > password is not accepting. > > I'm new to web programming. The aim is to automate user clicks on a web > server which can be replicated using python and http. Please suggest / help. You should probably use something like Firefox's "Live HTTP Headers" extension to see what exactly the web browser is doing when you normally login to the site, so that you can correctly replicate the browser's actions in your script. The site may be using HTTP Basic or HTTP Digest authentication, in which case you'll need to use urllib2.HTTPBasicAuthHandler or urllib2.HTTPDigestAuthHandler. Cheers, Chris -- http://blog.rebertia.com From whatsjacksemail at gmail.com Wed Dec 1 06:50:46 2010 From: whatsjacksemail at gmail.com (Jack Keegan) Date: Wed, 1 Dec 2010 11:50:46 +0000 Subject: To Thread or not to Thread....? In-Reply-To: <20101201102409.686e016f@pitrou.net> References: <20101201102409.686e016f@pitrou.net> Message-ID: Hi Antoine, On Wed, Dec 1, 2010 at 9:24 AM, Antoine Pitrou wrote: > > > The main question IMO: the I2C bus operates at 400kHz, but how much > received data can it buffer? That will give you a hint as to how much > latency you can tolerate. > I'm not sure on buffering, but I have to ask the device on the I2C bus for a sample each time I want one. This is done by sending out the address of the device on the I2C bus, waiting for a reply, then addressing the registers I want to read data from, then read the data. Therefore, I would need to make the request at the rate I require. > > I don't think soft threads would work at all, since they wouldn't allow > overlapping between frame reading and other ops. If frame reading > releases the GIL (as any properly implemented IO primitive in Python > should), then at least you can try using OS threads. > It's actually a separate piece of hardware that does the frame reading/encoding. I then interface to this via a DLL so I'm not sure how it handles things in the background. Unless I am mistaken, I have to allocate a chunk of memory for it to read the frames into, while I read from there. It's probably some sort of ring buffer implementation so I'd have to read the frames out and store them to disk before the next run through the buffer overwrites the old frames. How does that sound, process/thread wise? Thanks, Jack -- The earth is a very small stage in a vast cosmic arena. Think of the rivers of blood spilled by all those generals and emperors so that in glory and in triumph they could become the momentary masters of a fraction of a dot. - Carl Sagan [Pale Blue Dot] -------------- next part -------------- An HTML attachment was scrubbed... URL: From solipsis at pitrou.net Wed Dec 1 07:04:03 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Wed, 1 Dec 2010 13:04:03 +0100 Subject: To Thread or not to Thread....? In-Reply-To: References: <20101201102409.686e016f@pitrou.net> Message-ID: <20101201130403.41c270c1@pitrou.net> On Wed, 1 Dec 2010 11:50:46 +0000 Jack Keegan wrote: > Hi Antoine, > > On Wed, Dec 1, 2010 at 9:24 AM, Antoine Pitrou wrote: > > > > > > The main question IMO: the I2C bus operates at 400kHz, but how much > > received data can it buffer? That will give you a hint as to how much > > latency you can tolerate. > > > I'm not sure on buffering, but I have to ask the device on the I2C bus for a > sample each time I want one. This is done by sending out the address of the > device on the I2C bus, waiting for a reply, then addressing the registers I > want to read data from, then read the data. Therefore, I would need to make > the request at the rate I require. Sounds like you want to do this part in raw C and in a separate process, IMO. > > I don't think soft threads would work at all, since they wouldn't allow > > overlapping between frame reading and other ops. If frame reading > > releases the GIL (as any properly implemented IO primitive in Python > > should), then at least you can try using OS threads. > > > It's actually a separate piece of hardware that does the frame > reading/encoding. I then interface to this via a DLL so I'm not sure how it > handles things in the background. Unless I am mistaken, I have to allocate a > chunk of memory for it to read the frames into, while I read from there. Well, if you are the one writing the CPython interface against the DLL, you are responsible for releasing the GIL properly. > It's probably some sort of ring buffer implementation so I'd have to read > the frames out and store them to disk before the next run through the buffer > overwrites the old frames. You have to evaluate the latency requirements there too. I have to point out that I have no experience on embedded software, so the advice I'm giving is out of pure common sense :) Regards Antoine. From dario.beraldi at ed.ac.uk Wed Dec 1 07:23:09 2010 From: dario.beraldi at ed.ac.uk (Dario Beraldi) Date: Wed, 01 Dec 2010 12:23:09 +0000 Subject: SFTP: max bytes to be transferred Message-ID: <20101201122309.77330rdwews4egc0@www.staffmail.ed.ac.uk> Hello, I'm using the module paramiko to transfer files via sftp (see code below). I would like to specify the maximum amount of bytes to be transferred (say 10MB, if the file is bigger just transfer up to these many bytes). From the docs of paramiko (http://www.lag.net/paramiko/docs/paramiko.SFTPClient-class.html#get) I see that the method get() can take an optional callback parameter which is a "function that accepts the bytes transferred so far and the total bytes to be transferred". This seems to do what I need but I don't know how to specify such callback function. Any idea? This is my code: ------------[ Cut here ]------------- import paramiko host = "my.host" port = 22 transport = paramiko.Transport((host, port)) password = "mypassword" username = "myname" transport.connect(username = username, password = password) sftp = paramiko.SFTPClient.from_transport(transport) filepath = 'file/to/myfile.txt' localpath = 'D:/Tritume/myfile.txt' sftp.get(filepath, localpath) ## <-- Calback function should go here ------------[ cut here]----------- Many thanks Dario -- Dr. Dario Beraldi Institute of Evolutionary Biology University of Edinburgh West Mains Road Edinburgh EH9 3JT Scotland, UK -- Dr. Dario Beraldi Institute of Evolutionary Biology University of Edinburgh West Mains Road Edinburgh EH9 3JT Scotland, UK -- The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336. From javivd319 at hotmail.com Wed Dec 1 07:40:38 2010 From: javivd319 at hotmail.com (Javier Van Dam) Date: Wed, 1 Dec 2010 09:40:38 -0300 Subject: Reading by positions plain text files In-Reply-To: <4CF5B3D8.3030206@tim.thechases.com> References: <39a07597-02b9-4ef8-9ca9-93e2d2425e66@p7g2000prb.googlegroups.com> , <4CF5B3D8.3030206@tim.thechases.com> Message-ID: Ok. I will try it and let you know. Thanks a lot!! J > Date: Tue, 30 Nov 2010 20:32:56 -0600 > From: python.list at tim.thechases.com > To: javiervandam at gmail.com > CC: python-list at python.org > Subject: Re: Reading by positions plain text files > > On 11/30/2010 08:03 PM, javivd wrote: > > On Nov 30, 11:43 pm, Tim Harig wrote: > >>> VARIABLE NAME POSITION (COLUMN) IN FILE > >>> var_name_1 123-123 > >>> var_name_2 124-125 > >>> var_name_3 126-126 > >>> .. > >>> .. > >>> var_name_N 512-513 (last positions) > >> > > and no, MRAB, it's not the similar problem (at least what i understood > > of it). I have to associate the position this file give me with the > > variable name this file give me for those positions. > > MRAB may be referring to my reply in that thread where you can do > something like > > OFFSETS = 'offsets.txt' > offsets = {} > f = file(OFFSETS) > f.next() # throw away the headers > for row in f: > varname, rest = row.split()[:2] > # sanity check > if varname in offsets: > print "[%s] in %s twice?!" % (varname, OFFSETS) > if '-' not in rest: continue > start, stop = map(int, rest.split('-')) > offsets[varname] = slice(start, stop+1) # 0-based offsets > #offsets[varname] = slice(start+1, stop+2) # 1-based offsets > f.close() > > def do_something_with(data): > # your real code goes here > print data['var_name_2'] > > for row in file('data.txt'): > data = dict((name, row[offsets[name]]) for name in offsets) > do_something_with(data) > > There's additional robustness-checks I'd include if your > offsets-file isn't controlled by you (people send me daft data). > > -tkc > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Wed Dec 1 08:23:59 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 01 Dec 2010 14:23:59 +0100 Subject: Change one list item in place In-Reply-To: <17175f49-087f-4d05-ada2-7e8c7e7e86dd@z17g2000prz.googlegroups.com> References: <17175f49-087f-4d05-ada2-7e8c7e7e86dd@z17g2000prz.googlegroups.com> Message-ID: <4CF64C6F.2080809@sequans.com> Gnarlodious wrote: > This works for me: > > def sendList(): > return ["item0", "item1"] > > def query(): > l=sendList() > return ["Formatting only {0} into a string".format(l[0]), l[1]] > > query() > > > However, is there a way to bypass the > > l=sendList() > > and change one list item in-place? Possibly a list comprehension > operating on a numbered item? > > -- Gnarlie > what about def query(): return ["Formating only {0} into a string".format(sendList()[0])] + sendList()[1:] JM From awilliam at whitemice.org Wed Dec 1 08:33:28 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Wed, 01 Dec 2010 08:33:28 -0500 Subject: SAX unicode and ascii parsing problem In-Reply-To: References: Message-ID: <1291210408.7712.2.camel@linux-yu4c.site> On Tue, 2010-11-30 at 12:28 -0800, goldtech wrote: > I'm trying to parse an xml file using SAX. About half-way through a > file I get this error: > Traceback (most recent call last): > File "C:\Python26\Lib\site-packages\pythonwin\pywin\framework > \scriptutils.py", line 325, in RunScript > exec codeObject in __main__.__dict__ > File "E:\sc\b2.py", line 58, in > parser.parse(open(r'ppb5.xml')) > File "C:\Python26\Lib\xml\sax\expatreader.py", line 107, in parse > xmlreader.IncrementalParser.parse(self, source) > File "C:\Python26\Lib\xml\sax\xmlreader.py", line 123, in parse > self.feed(buffer) > File "C:\Python26\Lib\xml\sax\expatreader.py", line 207, in feed > self._parser.Parse(data, isFinal) > File "C:\Python26\Lib\xml\sax\expatreader.py", line 304, in > end_element > self._cont_handler.endElement(name) > File "E:\sc\b2.py", line 51, in endElement > d.write(csv+"\n") > UnicodeEncodeError: 'ascii' codec can't encode characters in position > 146-147: ordinal not in range(128) Catch the UnicodeEncodeError exception and display the value of csv. Are you certain the error isn't actually in your data? What encoding is the source data? What is "d"? A file object? Is it in binary mode, or is it StringIO, or a codec? > I'm using ActivePython 2.6. I trying to figure out the simplest fix. > If there's a Python way to just take the source XML file and covert/ > process it so this will not happen - that would be best. Or should I > just update to Python 3 ? > I tried this but nothing changed, I thought this might convert it and > then I'd paerse the new file - didn't work: > u = open(r'E:\sc\ppb4.xml').read().decode('utf8') > ascii = uc.decode('ascii') > mex9 = open( r'E:\scrapes\ppb5.xml', 'w' ) > mex9.write(ascii) > Again I'm looking for something simple even it's a few more lines of > codes...or upgrade(?) If the input data contains characters that cannot be represented in ASCII simply decoding the stream (a) won't fix it and (b) should raise an exception. From gnarlodious at gmail.com Wed Dec 1 08:33:55 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Wed, 1 Dec 2010 05:33:55 -0800 (PST) Subject: Change one list item in place References: <17175f49-087f-4d05-ada2-7e8c7e7e86dd@z17g2000prz.googlegroups.com> Message-ID: On Dec 1, 6:23?am, Jean-Michel Pichavant wrote: > what about > > def query(): > ? ? return ["Formating only {0} into a string".format(sendList()[0])] + > sendList()[1:] However this solution calls sendList() twice, which is too processor intensive. Thanks for all the ideas, I've resigned myself to unpacking a tuple and reassembling it. -- Gnarlie http://Sectrum.com From nelson1977 at gmail.com Wed Dec 1 08:48:24 2010 From: nelson1977 at gmail.com (nelson) Date: Wed, 1 Dec 2010 05:48:24 -0800 (PST) Subject: strange TypeError exception in function compiled from a string Message-ID: Hi all, I have this function, defined in a string and ecetuted through ad exec call def cell1(d): x=d.get('x') print x import y return y.add(y.add(self.adf0(x),self.adf0(x)),self.adf0(x)) d is a dict of this kind {'x':2} I receive the following exception, that i find very strange... File "", line 7, in cell1 TypeError: 'dict' object is not callable I have tested all the function al line 7, and none of them raise any exception. Have anyone some suggestion on how to solve this? thanks! From prologic at shortcircuit.net.au Wed Dec 1 08:48:38 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 1 Dec 2010 23:48:38 +1000 Subject: To Thread or not to Thread....? In-Reply-To: <20101201102409.686e016f@pitrou.net> References: <20101201102409.686e016f@pitrou.net> Message-ID: Surely I2C is just a serial-like interface and one should be able to do async I/O on it ? The use of threads is not necessary here and the GIL doesn't become a problem in async I/O anyway. I only use threads for operating that might block (not for I/O). cheers James On Wed, Dec 1, 2010 at 7:24 PM, Antoine Pitrou wrote: > On Wed, 1 Dec 2010 02:45:50 +0000 > Jack Keegan wrote: > >> Hi there, >> >> I'm currently writing an application to control and take measurements during >> an experiments. This is to be done on an embedded computer running XPe so I >> am happy to have python available, although I am pretty new to it. >> The application basically runs as a state machine, which transitions through >> it's states based on inputs read in from a set of general purpose >> input/output (GPIO) lines. So when a certain line is pulled low/high, do >> something and move to another state. All good so far and since I get through >> main loop pretty quickly, I can just do a read of the GPIO lines on each >> pass through the loop and respond accordingly. > >> However, in one of the states I have to start reading in, and storing frames >> from a camera. In another, I have to start reading accelerometer data from >> an I2C bus (which operates at 400kHz). I haven't implemented either yet but >> I would imagine that, in the case of the camera data, reading a frame would >> take a large amount of time as compared to other operations. Therefore, if I >> just tried to read one (or one set of) frames on each pass through the loop >> then I would hold up the rest of the application. Conversely, as the I2C bus >> will need to be read at such a high rate, I may not be able to get the >> required data rate I need even without the camera data. This naturally leads >> me to think I need to use threads. >> As I am no expert in either I2C, cameras, python or threading I thought I >> would chance asking for some advice on the subject. Do you think I need >> threads here or would I be better off using some other method. I was >> previously toying with the idea of using generators to create weightless >> threads (as detailed in >> http://www.ibm.com/developerworks/library/l-pythrd.html) for reading the >> GPIOs. Do you think this would work in this situation? > > The main question IMO: the I2C bus operates at 400kHz, but how much > received data can it buffer? That will give you a hint as to how much > latency you can tolerate. > > I don't think soft threads would work at all, since they wouldn't allow > overlapping between frame reading and other ops. If frame reading > releases the GIL (as any properly implemented IO primitive in Python > should), then at least you can try using OS threads. > > Then, depending on the tolerable latency for I2C operation, you can try > to run it as an OS thread, or a separate process (if running as a > separate process, make sure it cannot block while sending IO to the > master process). > > Regards > > Antoine. > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- -- James Mills -- -- "Problems are solved by method" From khamenya at gmail.com Wed Dec 1 08:52:30 2010 From: khamenya at gmail.com (Valery Khamenya) Date: Wed, 1 Dec 2010 14:52:30 +0100 Subject: How to initialize each multithreading Pool worker with an individual value? In-Reply-To: References: Message-ID: Hi Dan, > If you create in the parent a queue in shared memory (multiprocessing > facilitates this nicely), and fill that queue with the values in your > ports tuple, then you could have each child in the worker pool extract > a single value from this queue so each worker can have its own, unique > port value. this port number is supposed to be used once, namely during initialization. Quite usual situation with conections is so, that it is a bit expensive to initiate it each time the connection is about to be used. So, it is often initialized once and dropped only when all communication is done. In contrast, your case looks for me that you rather propose to initiate the connection each time a new job comes from queue for an execution. Regards, Valery From jeanmichel at sequans.com Wed Dec 1 08:59:37 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 01 Dec 2010 14:59:37 +0100 Subject: Change one list item in place In-Reply-To: References: <17175f49-087f-4d05-ada2-7e8c7e7e86dd@z17g2000prz.googlegroups.com> Message-ID: <4CF654C9.8060203@sequans.com> Gnarlodious wrote: > On Dec 1, 6:23 am, Jean-Michel Pichavant > wrote: > >> what about >> >> def query(): >> return ["Formating only {0} into a string".format(sendList()[0])] + >> sendList()[1:] >> > > However this solution calls sendList() twice, which is too processor > intensive. > > You got to get rid of those nerd habits of unecessary optimization. To put it simple, you just don't give a [put whatever suitable word] to the overhead of 2 calls of sendList instead of one. Until query is called a million time a second, there's no need to sacrifice anything on the optimization altar, because no one will never ever see the difference. You can find my solution not that readable, that would be a proper reason for not using it. It's up to you. JM From bruno.desthuilliers at gmail.com Wed Dec 1 09:17:57 2010 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Wed, 1 Dec 2010 06:17:57 -0800 (PST) Subject: strange TypeError exception in function compiled from a string References: Message-ID: On 1 d?c, 14:48, nelson wrote: > Hi all, > ? I have this function, defined in a string and ecetuted through ad > exec call > > def cell1(d): > > ? ? x=d.get('x') > ? ? print x > > ? ? import y > ? ? return y.add(y.add(self.adf0(x),self.adf0(x)),self.adf0(x)) > > d is a dict of this kind {'x':2} > > I receive the following exception, that i find very strange... > > ? File "", line 7, in cell1 > TypeError: 'dict' object is not callable > > I have tested all the function al line 7, and none of them raise any > exception. > Have anyone some suggestion on how to solve this? > Not without the minimal executable code reproducing your error. From tw55413 at gmail.com Wed Dec 1 09:18:25 2010 From: tw55413 at gmail.com (erikj) Date: Wed, 1 Dec 2010 06:18:25 -0800 (PST) Subject: position independent build of python Message-ID: Hi, If my understanding is correct, the sys.prefix variable holds the root directory python uses to find related files, and eg its site-packages. the value of sys.prefix is specified at compile time. it seems that on windows, when I build/install python at one location, and later move it to another location, python will find all its needs relative to the new location. however, when I do the same on linux, python keeps looking for its dependencies in the build location. is there a possibility to have it always look at a position relative to the location of the executable ? the goal is to be able to build python on one machine, and then simply copy the build tree to other machines at other locations. Thank you and regards, Erik From werner at thieprojects.ch Wed Dec 1 09:28:15 2010 From: werner at thieprojects.ch (Werner Thie) Date: Wed, 01 Dec 2010 15:28:15 +0100 Subject: To Thread or not to Thread....? In-Reply-To: References: <20101201102409.686e016f@pitrou.net> Message-ID: <4CF65B7F.90806@thieprojects.ch> Hi I see quite a few alleys to go down when stuck with such types of problems, but instead of listing and discussing them have a look at a quite complete discussion and comparison of the various async programming options available at http://syncless.googlecode.com Also have a look at the presentation at http://syncless.googlecode.com/svn/trunk/doc/slides_2010-11-29/pts_coro_2010-11-29.html If I were in your shoes I would solve the problem in stackless, if exchanging the python interpreter is not possible then Twisted would be my second choice, having done a lot of work with it (see the NMEA classes for serial ports). I don't know if syncless handles other types of fd's like serial ports, I've never played with it. The monkey patching of syncless might pose other problems in your case. HTH, Werner Am 01.12.2010 14:48, schrieb James Mills: > Surely I2C is just a serial-like interface > and one should be able to do async I/O on it ? > > The use of threads is not necessary here and the GIL > doesn't become a problem in async I/O anyway. > > I only use threads for operating that might block (not for I/O). > > cheers > James > > On Wed, Dec 1, 2010 at 7:24 PM, Antoine Pitrou wrote: >> On Wed, 1 Dec 2010 02:45:50 +0000 >> Jack Keegan wrote: >> >>> Hi there, >>> >>> I'm currently writing an application to control and take measurements during >>> an experiments. This is to be done on an embedded computer running XPe so I >>> am happy to have python available, although I am pretty new to it. >>> The application basically runs as a state machine, which transitions through >>> it's states based on inputs read in from a set of general purpose >>> input/output (GPIO) lines. So when a certain line is pulled low/high, do >>> something and move to another state. All good so far and since I get through >>> main loop pretty quickly, I can just do a read of the GPIO lines on each >>> pass through the loop and respond accordingly. >> >>> However, in one of the states I have to start reading in, and storing frames >>> from a camera. In another, I have to start reading accelerometer data from >>> an I2C bus (which operates at 400kHz). I haven't implemented either yet but >>> I would imagine that, in the case of the camera data, reading a frame would >>> take a large amount of time as compared to other operations. Therefore, if I >>> just tried to read one (or one set of) frames on each pass through the loop >>> then I would hold up the rest of the application. Conversely, as the I2C bus >>> will need to be read at such a high rate, I may not be able to get the >>> required data rate I need even without the camera data. This naturally leads >>> me to think I need to use threads. >>> As I am no expert in either I2C, cameras, python or threading I thought I >>> would chance asking for some advice on the subject. Do you think I need >>> threads here or would I be better off using some other method. I was >>> previously toying with the idea of using generators to create weightless >>> threads (as detailed in >>> http://www.ibm.com/developerworks/library/l-pythrd.html) for reading the >>> GPIOs. Do you think this would work in this situation? >> >> The main question IMO: the I2C bus operates at 400kHz, but how much >> received data can it buffer? That will give you a hint as to how much >> latency you can tolerate. >> >> I don't think soft threads would work at all, since they wouldn't allow >> overlapping between frame reading and other ops. If frame reading >> releases the GIL (as any properly implemented IO primitive in Python >> should), then at least you can try using OS threads. >> >> Then, depending on the tolerable latency for I2C operation, you can try >> to run it as an OS thread, or a separate process (if running as a >> separate process, make sure it cannot block while sending IO to the >> master process). >> >> Regards >> >> Antoine. >> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > -------------- next part -------------- A non-text attachment was scrubbed... Name: werner.vcf Type: text/x-vcard Size: 297 bytes Desc: not available URL: From python at bdurham.com Wed Dec 1 09:55:01 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 01 Dec 2010 09:55:01 -0500 Subject: When to use codecs vs. io module (Python 2.7 and higher) Message-ID: <1291215301.9144.1408094187@webmail.messagingengine.com> Python 2.7 or higher: Looking for reasons/scenarios where one should use the codecs vs. io module. Are there use cases that favor one specific module over the other module? My understanding is that the io module is much faster than the codecs module (and can be used interchangably), but the codecs module provides backward compatibility if you need to target versions of Python less than 2.6. Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From solipsis at pitrou.net Wed Dec 1 10:04:55 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Wed, 1 Dec 2010 16:04:55 +0100 Subject: To Thread or not to Thread....? In-Reply-To: References: <20101201102409.686e016f@pitrou.net> Message-ID: <20101201160455.0e9aa70e@pitrou.net> On Wed, 1 Dec 2010 23:48:38 +1000 James Mills wrote: > Surely I2C is just a serial-like interface > and one should be able to do async I/O on it ? > > The use of threads is not necessary here and the GIL > doesn't become a problem in async I/O anyway. Well, you are missing the point. The OP wants to do operations that have certain latency requirements while doing other operations "in parallel". Using several preemptively-switching threads (or processes) is the simplest way of achieving that; you can do cooperative multithreading (which is conceptually the same as single-threaded async programming), but you'll have to insert as many explicit synchronization points as necessary to achieve the latency objectives. Not very practical obviously. (and, yes, the GIL amounts to some bastardized, fine-grained form of cooperative multithreading, which is why separate processes might be a better answer if the latency requirements are tight - especially on Python 2.x-3.1 where the GIL is badly implemented) Regards Antoine. From solipsis at pitrou.net Wed Dec 1 10:06:53 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Wed, 1 Dec 2010 16:06:53 +0100 Subject: When to use codecs vs. io module (Python 2.7 and higher) References: <1291215301.9144.1408094187@webmail.messagingengine.com> Message-ID: <20101201160653.280fa90c@pitrou.net> On Wed, 01 Dec 2010 09:55:01 -0500 python at bdurham.com wrote: > Python 2.7 or higher: Looking for reasons/scenarios where one > should use the codecs vs. io module. > > Are there use cases that favor one specific module over the other > module? > > My understanding is that the io module is much faster than the > codecs module (and can be used interchangably), but the codecs > module provides backward compatibility if you need to target > versions of Python less than 2.6. That's a good summary, although I'm not sure codecs and io are interchangeable. They will certainly have slightly different behaviour in corner cases. The io module is much more tested since it's the official way to do I/O in Python 3, so its own corner cases are probably better than those in the codecs module :) Regards Antoine. From invalid at invalid.invalid Wed Dec 1 10:23:21 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 1 Dec 2010 15:23:21 +0000 (UTC) Subject: Catching user switching and getting current active user from root on linux References: <1a9bdbd4-2997-4e0f-a24f-cd148247e312@r40g2000prh.googlegroups.com> Message-ID: On 2010-11-30, mpnordland wrote: > I have situation where I need to be able to get the current active > user, How do you define "current active user"? > and catch user switching eg user1 locks screen, leaves computer, > user2 comes, and logs on. basically, when there is any type of user > switch my script needs to know. What do you do when there are multiple users logged in? -- Grant Edwards grant.b.edwards Yow! How's the wife? at Is she at home enjoying gmail.com capitalism? From prog at vtr.net Wed Dec 1 10:48:41 2010 From: prog at vtr.net (craf) Date: Wed, 01 Dec 2010 12:48:41 -0300 Subject: Decorate un Frame with window managers title bar, etc en Tkinter 8.5 Message-ID: <1291218521.4983.24.camel@cristian-desktop> Hi. I use python 3.1 and Tkinter 8.5 in Ubuntu 9.10 I would like to turn a frame into a toolbox, ,and for that I read that you can use the command wm manage (window) The information can be found at: http://www.tcl.tk/man/tcl8.5/TkCmd/wm.htm#M39 the explanation says: wm manage widget: The widget specified will become a stand alone top-level window. The window will be decorated with the window managers title bar, etc. Only frame, labelframe and toplevel widgets can be used with this command. Attempting to pass any other widget type will raise an error. Attempting to manage a toplevel widget is benign and achieves nothing. See also GEOMETRY MANAGEMENT. I have tried to use it in Tkinter but I can not know how is its structure. In Tkinter should be: ---TEST CODE------------------- from Tkinter import master = Tk() frame = Frame(master) wm_manager(Frame) master.mainloop() -------------------------------- But this does not work. I appreciate any of this item Regards. Cristian Abarz?a From info at wingware.com Wed Dec 1 10:59:46 2010 From: info at wingware.com (Wingware) Date: Wed, 01 Dec 2010 10:59:46 -0500 Subject: Wing IDE 3.2.12 released Message-ID: <4CF670F2.4060908@wingware.com> Hi, Wingware has released version 3.2.12 of Wing IDE, an integrated development environment designed specifically for the Python programming language. This release includes the following improvements: * Support for Stackless version 2.7 * Correctly ignore exceptions in debugger for logged exceptions * Fix indent conversion when file had inconsistent eol characters * Change Mako block commenting to use ## * Fix testing tool result display when re-running similarly named tests * 8 other minor bug fixes See http://wingware.com/pub/wingide/3.2.12/CHANGELOG.txt for details. *Downloads* Wing IDE Professional http://wingware.com/downloads/wingide/3.2 Wing IDE Personal http://wingware.com/downloads/wingide-personal/3.2 Wing IDE 101 http://wingware.com/downloads/wingide-101/3.2 *About Wing IDE* Wing IDE is an integrated development environment designed specifically for the Python programming language. It provides powerful editing, testing, and debugging features that help reduce development and debugging time, cut down on coding errors, and make it easier to understand and navigate Python code. Wing IDE can be used to develop Python code for web, GUI, and embedded scripting applications. Wing IDE is available in three product levels: Wing IDE Professional is the full-featured Python IDE, Wing IDE Personal offers a reduced feature set at a low price, and Wing IDE 101 is a free simplified version designed for teaching entry level programming courses with Python. Version 3.2 of Wing IDE Professional includes the following major features: * Professional quality code editor with vi, emacs, and other keyboard personalities * Code intelligence for Python: Auto-completion, call tips, goto-definition, error indicators, smart indent and re-wrapping, and source navigation * Advanced multi-threaded debugger with graphical UI, command line interaction, conditional breakpoints, data value tool tips over code, watch tool, and externally launched and remote debugging * Powerful search and replace options including keyboard driven and graphical UIs, multi-file, wild card, and regular expression search and replace * Version control integration for Subversion, CVS, Bazaar, git, Mercurial, and Perforce * Integrated unit testing for the unittest, nose, and doctest frameworks * Many other features including project manager, bookmarks, code snippets, OS command integration, indentation manager, PyLint integration, and perspectives * Extremely configurable and may be extended with Python scripts Please refer to the feature list at http://wingware.com/wingide/features for a detailed listing of features by product level. System requirements are Windows 2000 or later, OS X 10.3.9 or later for PPC or Intel (requires X11 Server), or a recent Linux system (either 32 or 64 bit). Wing IDE supports Python versions 2.0.x through 3.1.x and Stackless Python. For more information, see http://wingware.com/products *Purchasing and Upgrading* Wing 3.2 is a free upgrade for all Wing IDE 3.0 and 3.1 users. Version 2.x licenses cost 1/2 the normal price to upgrade. Upgrade a license: https://wingware.com/store/upgrade Purchase a license: https://wingware.com/store/purchase -- Wingware | Python IDE The Intelligent Development Environment for Python Programmers www.wingware.com From goldtech at worldpost.com Wed Dec 1 11:16:28 2010 From: goldtech at worldpost.com (goldtech) Date: Wed, 1 Dec 2010 08:16:28 -0800 (PST) Subject: Python's equivalent to Main calling program and subprograms Message-ID: Hi, Could someone link me to info - I'm sure this is commonly done: "Long ago" with Fortran and Pascal there was a pattern used a lot. It was like: Start Main Global Var Subprogram1 Subprogram2 Subprogram3 End of Main End The global var was a var that all the subprograms could access. I wanted a container for several scripts that run in succession one after dhere other. This has to be newbie stuff - sorry to ask. If you could give me some keywords or link me or provide a simple example I would be grateful. Thanks From usernet at ilthio.net Wed Dec 1 11:28:56 2010 From: usernet at ilthio.net (Tim Harig) Date: Wed, 1 Dec 2010 16:28:56 +0000 (UTC) Subject: Python's equivalent to Main calling program and subprograms References: Message-ID: On 2010-12-01, goldtech wrote: > Start > Main > Global Var > Subprogram1 > Subprogram2 > Subprogram3 > End of Main > End module_wide_var = value def Subprogram1: # code def Subprogram2: # code def Subprogram3: # code def main: Subprogram1() Subprogram2() Subprogram3() if __name__ == "__main__": main() From jeanmichel at sequans.com Wed Dec 1 11:42:28 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 01 Dec 2010 17:42:28 +0100 Subject: Python's equivalent to Main calling program and subprograms In-Reply-To: References: Message-ID: <4CF67AF4.7040201@sequans.com> Tim Harig wrote: > On 2010-12-01, goldtech wrote: > >> Start >> Main >> Global Var >> Subprogram1 >> Subprogram2 >> Subprogram3 >> End of Main >> End >> > > module_wide_var = value > > def Subprogram1: > # code > > def Subprogram2: > # code > > def Subprogram3: > # code > > def main: > Subprogram1() > Subprogram2() > Subprogram3() > > if __name__ == "__main__": > main() > "def main:" raises a syntax error. "def main():" does not (python 2.5) JM From joncle at googlemail.com Wed Dec 1 12:02:41 2010 From: joncle at googlemail.com (Jon Clements) Date: Wed, 1 Dec 2010 09:02:41 -0800 (PST) Subject: Login using usrllib2 References: Message-ID: <5873559c-edd5-44c0-aae3-81d41e77948b@fj16g2000vbb.googlegroups.com> On Dec 1, 10:16?am, Chris Rebert wrote: > On Wed, Dec 1, 2010 at 1:53 AM, ? wrote: > > Hi All, > > > I'm using urllib2 module to login to an https server. However I'm unable to > > login as the password is not getting accepted. > > > Here is the code: > > > import urllib2, urllib > > values={'Username': 'admin', 'Password': 'admin123'} > > url='https://172.25.17.20:9443' > > data = urllib.urlencode(values) > > > data = urllib.urlencode(values) > > req = urllib2.Request(url, data) > > response = urllib2.urlopen(req) > > the_page = response.read() > > print the_page > > > The error message I get in the_page output is the same as I get when I > > access this site using a browser and supply a wrong password. It appears > > password is not accepting. > > > I'm new to web programming. The aim is to automate user clicks on a web > > server which can be replicated using python and http. Please suggest / help. > > You should probably use something like Firefox's "Live HTTP Headers" > extension to see what exactly the web browser is doing when you > normally login to the site, so that you can correctly replicate the > browser's actions in your script. > The site may be using HTTP Basic or HTTP Digest authentication, in > which case you'll need to use urllib2.HTTPBasicAuthHandler or > urllib2.HTTPDigestAuthHandler. > > Cheers, > Chris > --http://blog.rebertia.com If the OP is doing this a lot I would suggest installing FF's Firebug extension. Then use the Net tab to monitor activity. Also the OP might want to look at the urllib2.HTTPSHandler. Jon From snert at hotmail.se Wed Dec 1 12:08:14 2010 From: snert at hotmail.se (m b) Date: Wed, 1 Dec 2010 18:08:14 +0100 Subject: Python's equivalent to Main calling program and subprograms In-Reply-To: <4CF67AF4.7040201@sequans.com> References: , , <4CF67AF4.7040201@sequans.com> Message-ID: > > > > if __name__ == "__main__": > > main() What does this mean? /Mikael -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Wed Dec 1 12:13:39 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 01 Dec 2010 17:13:39 +0000 Subject: strange TypeError exception in function compiled from a string In-Reply-To: References: Message-ID: <4CF68243.7030709@mrabarnett.plus.com> On 01/12/2010 13:48, nelson wrote: > Hi all, > I have this function, defined in a string and ecetuted through ad > exec call > > def cell1(d): > > x=d.get('x') > print x > > import y > return y.add(y.add(self.adf0(x),self.adf0(x)),self.adf0(x)) > > > d is a dict of this kind {'x':2} > > I receive the following exception, that i find very strange... > > File "", line 7, in cell1 > TypeError: 'dict' object is not callable > > I have tested all the function al line 7, and none of them raise any > exception. > Have anyone some suggestion on how to solve this? > A call looks like foo(), so probably either y.add or self.adf0 is a dict. Print both of them to check. From clp2 at rebertia.com Wed Dec 1 12:18:48 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 1 Dec 2010 09:18:48 -0800 Subject: Python's equivalent to Main calling program and subprograms In-Reply-To: References: <4CF67AF4.7040201@sequans.com> Message-ID: On Wed, Dec 1, 2010 at 9:08 AM, m b wrote: >> > >> > if __name__ == "__main__": >> > main() > > What does this mean? See http://effbot.org/pyfaq/tutor-what-is-if-name-main-for.htm (which is the 3rd Google hit for "__main__") Cheers, Chris From jeanmichel at sequans.com Wed Dec 1 12:20:01 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 01 Dec 2010 18:20:01 +0100 Subject: Python's equivalent to Main calling program and subprograms In-Reply-To: References: , , <4CF67AF4.7040201@sequans.com> Message-ID: <4CF683C1.7010709@sequans.com> m b wrote: > > > > > > > > if __name__ == "__main__": > > > main() > > What does this mean? > > /Mikael __name__ is an attribute of the module. Usually it is set to the module name, except when the module is acutally executed as the entry point, in that case __name__ is set to '__main__'. foo.py: print __name__ > python foo.py '__main__' > python -c "import foo" 'foo' This is a very basic concept, you should read the python tutorial. JM From benjamin.kaplan at case.edu Wed Dec 1 12:24:18 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 1 Dec 2010 12:24:18 -0500 Subject: Python's equivalent to Main calling program and subprograms In-Reply-To: References: <4CF67AF4.7040201@sequans.com> Message-ID: On Wed, Dec 1, 2010 at 12:08 PM, m b wrote: > > >> > >> > if __name__ == "__main__": >> > main() > > What does this mean? > > /Mikael > Every module has an attribute called __name__. Normally, it's the name of the module itself. However, the module being run as a script (rather than imported) is called __main__. You can use if __name__ == "__main__" to have certain things only run if the file is executed directly. ---- a.py ---- print "I'm A" if __name__ == '__main__' : print "I'm the main script" --- b.py --- import a $ python a.py I'm A I'm the main script $ python b.py I'm A From hanif_1989 at btinternet.com Wed Dec 1 12:25:30 2010 From: hanif_1989 at btinternet.com (Hanif Jameel) Date: Wed, 01 Dec 2010 17:25:30 +0000 Subject: Python's equivalent to Main calling program and subprograms In-Reply-To: References: , , <4CF67AF4.7040201@sequans.com> Message-ID: <4CF6850A.1020708@btinternet.com> On 01/12/2010 17:08, m b wrote: > > > > > > > > if __name__ == "__main__": > > > main() > > What does this mean? > > /Mikael > Python will not cause the main() function to run automatically when you execute the script, it has to be called. __name__ is a special variable which is set by the python interpreter when it runs a source file. If the source file is run directly(as opposed to being imported), then the value of __name__ will be set to __main__. so if __name__ == "__main__": main() checks to see if the source file be being directly executed, and if it is, calls the main() function. From python at mrabarnett.plus.com Wed Dec 1 12:35:53 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 01 Dec 2010 17:35:53 +0000 Subject: Regarding searching directory and to delete it with specific pattern. In-Reply-To: References: Message-ID: <4CF68779.60902@mrabarnett.plus.com> On 01/12/2010 07:07, Ramprakash Jelari thinakaran wrote: > Hi all, > Would like to search list of directories with specific pattern and > delete it?.. How can i do it?. > Example: in /home/jpr/ i have the following list of directories. > 1.2.3-2, 1.2.3-10, 1.2.3-8, i would like to delete the directories > other than 1.2.3-10 which is the higher value?.. > Use os.listdir to get a list of the names in the directory. Use os.path.isdir to identify those which are subdirectories. Identify the names which match the pattern, eg: name.startswith("1.2.3-") and name[6 : ].isdigit() Identify the 'highest' name (it's the one with the maximum value of int(name[6 : ])). Remove each of the unwanted subdirectories with shutil.rmtree. It's also a good idea if initially it doesn't actually remove the unwanted directories, but just prints out the paths of them, because you really don't want to discover that you've made a mistake and it has deleted something important! :-) From carlo at somewhere.com Wed Dec 1 12:36:42 2010 From: carlo at somewhere.com (Carlo) Date: 01 Dec 2010 17:36:42 GMT Subject: string find/replace Message-ID: <4cf687aa$0$5000$e4fe514c@dreader19.news.xs4all.nl> Hello, I want the Python equivalent of the Perl expression: s/([a-z])([A-Z])/\1 \2/g In plain language: place a space between a lowercase and uppercase letter. I get lost in the RE module. Can someone help me? Thanks! From steve at holdenweb.com Wed Dec 1 12:38:15 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 01 Dec 2010 12:38:15 -0500 Subject: Python's equivalent to Main calling program and subprograms In-Reply-To: References: , , <4CF67AF4.7040201@sequans.com> Message-ID: On 12/1/2010 12:08 PM, m b wrote: > > >> > >> > if __name__ == "__main__": >> > main() > > What does this mean? > > /Mikael > It's a standard way of allowing programs to test themselves. When a module is imported its __name__ attribute us bound to the name of the module. When the module is run as a main program (from the command line) its __name__ attribute is set to "__main__". The main() call just calls a function that (presumably) tests the functions the module provides. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From __peter__ at web.de Wed Dec 1 12:42:43 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 01 Dec 2010 18:42:43 +0100 Subject: string find/replace References: <4cf687aa$0$5000$e4fe514c@dreader19.news.xs4all.nl> Message-ID: Carlo wrote: > I want the Python equivalent of the Perl expression: > s/([a-z])([A-Z])/\1 \2/g > In plain language: place a space between a lowercase and uppercase > letter. I get lost in the RE module. Can someone help me? >>> import re >>> re.compile("([a-z])([A-Z])").sub(r"\1 \2", "camelCase") 'camel Case' or >>> re.sub("([a-z])([A-Z])", r"\1 \2", "camelCase") 'camel Case' From donnieodonnell at gmail.com Wed Dec 1 12:46:03 2010 From: donnieodonnell at gmail.com (Donald O'Donnell) Date: Wed, 1 Dec 2010 09:46:03 -0800 (PST) Subject: string find/replace References: <4cf687aa$0$5000$e4fe514c@dreader19.news.xs4all.nl> Message-ID: <710c0436-58b1-49d7-a54d-bff0c0504604@j29g2000yqm.googlegroups.com> On Dec 1, 12:36?pm, Carlo wrote: > Hello, > > I want the Python equivalent of the Perl expression: > s/([a-z])([A-Z])/\1 \2/g > In plain language: place a space between a lowercase and uppercase > letter. I get lost in the RE module. Can someone help me? > > Thanks! This will also replace '_' with space:: recamelsub = re.compile(r"([a-z])([A-Z])").sub def spacify(string): """ Replace '_' with space & insert space between lower & upper case letters """ return recamelsub(r"\1 \2", string.replace('_',' ')) From carlo at somewhere.com Wed Dec 1 12:59:04 2010 From: carlo at somewhere.com (Carlo) Date: 01 Dec 2010 17:59:04 GMT Subject: string find/replace References: <4cf687aa$0$5000$e4fe514c@dreader19.news.xs4all.nl> Message-ID: <4cf68ce8$0$12821$e4fe514c@dreader19.news.xs4all.nl> On 2010-12-01, Peter Otten <__peter__ at web.de> wrote: >>>> import re >>>> re.compile("([a-z])([A-Z])").sub(r"\1 \2", "camelCase") > 'camel Case' Very simple if you know it. Thank you! From python at mrabarnett.plus.com Wed Dec 1 13:07:03 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 01 Dec 2010 18:07:03 +0000 Subject: string find/replace In-Reply-To: <4cf687aa$0$5000$e4fe514c@dreader19.news.xs4all.nl> References: <4cf687aa$0$5000$e4fe514c@dreader19.news.xs4all.nl> Message-ID: <4CF68EC7.8090803@mrabarnett.plus.com> On 01/12/2010 17:36, Carlo wrote: > Hello, > > I want the Python equivalent of the Perl expression: > s/([a-z])([A-Z])/\1 \2/g > In plain language: place a space between a lowercase and uppercase > letter. I get lost in the RE module. Can someone help me? > That's easy: new_text = re.sub(r'([a-z])([A-Z])', r'\1 \2', old_text) From mdw at distorted.org.uk Wed Dec 1 13:19:20 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 01 Dec 2010 18:19:20 +0000 Subject: Catching user switching and getting current active user from root on linux References: <1a9bdbd4-2997-4e0f-a24f-cd148247e312@r40g2000prh.googlegroups.com> Message-ID: <8739qhs6dz.fsf.mdw@metalzone.distorted.org.uk> Grant Edwards writes: > On 2010-11-30, mpnordland wrote: > > and catch user switching eg user1 locks screen, leaves computer, > > user2 comes, and logs on. basically, when there is any type of user > > switch my script needs to know. > > What do you do when there are multiple users logged in? In case it's not clear: this situation doesn't just occur on `exotic' systems like Unix servers. Even Windows systems can have several people logged into the console (with one active, using `fast user switching') and another one or two connected using terminal services. -- [mdw] From usernet at ilthio.net Wed Dec 1 14:13:54 2010 From: usernet at ilthio.net (Tim Harig) Date: Wed, 1 Dec 2010 19:13:54 +0000 (UTC) Subject: Python's equivalent to Main calling program and subprograms References: <4CF67AF4.7040201@sequans.com> Message-ID: > On Wed, Dec 1, 2010 at 9:08 AM, m b wrote: >>> > if __name__ == "__main__": >>> > main() >> >> What does this mean? It is a Python idiom and a good practice. Strictly speaking it is unnecessary. Python doesn't recognize any functional initialization vector other then the start of the file. When Python loads a module, it executes anything it finds in the module scope (Anything not in the body of a class or function declaration). Using a main function is just a convention. You could just place all of your main level code in the module scope: def Subprogram1(): # code def Subprogram2(): # code def Subprogram3(): # code # main code or equivilantly, always execute main(): def Subprogram1(): # code def Subprogram2(): # code def Subprogram3(): # code def main(): # main code main() Both are valid from Python's point of view. The 'if __name__ == "__main__":' idiom is used, because it allows the module to be loaded without running main(). This is useful if you wanted to use Subprogram2() from another program. Even if you don't forsee using any of the subprograms (functions to Python), this can be useful when writing test code as you can import the program as a module to test its classes or functions separately. From kirby.urner at gmail.com Wed Dec 1 15:38:34 2010 From: kirby.urner at gmail.com (kirby.urner at gmail.com) Date: Wed, 1 Dec 2010 12:38:34 -0800 (PST) Subject: Packages at Python.org Message-ID: <084f9299-b2b3-440f-b83f-9fbe42220221@j19g2000prh.googlegroups.com> With Microsoft abandoning Visual FoxPro come 2015, we have 100K developers jumping ship (rough guess), perhaps to dot NET, but not necessarily.** This page is potentially getting a lot of hits (I'm not privy to the analytics): http://packages.python.org/dbf/ So how *do* you get source code from such a web place? I'm not finding a tar ball or installer. Sorry if I'm missing something obvious, like a link to Sourceforge. Kirby ** Unconfirmed rumors about IronPython leave me blog searching this afternoon. Still part of Codeplex? From ian.g.kelly at gmail.com Wed Dec 1 15:48:33 2010 From: ian.g.kelly at gmail.com (Ian) Date: Wed, 1 Dec 2010 12:48:33 -0800 (PST) Subject: Packages at Python.org References: <084f9299-b2b3-440f-b83f-9fbe42220221@j19g2000prh.googlegroups.com> Message-ID: <1f034df4-bb14-4996-8185-e75976bf320c@i25g2000prd.googlegroups.com> On Dec 1, 1:38?pm, "kirby.ur... at gmail.com" wrote: > http://packages.python.org/dbf/ > > So how *do* you get source code from such a web place? ?I'm not > finding > a tar ball or installer. ?Sorry if I'm missing something obvious, like > a link > to Sourceforge. That site only contains documentation. Try this page instead: http://pypi.python.org/pypi/dbf/ From clp2 at rebertia.com Wed Dec 1 15:49:03 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 1 Dec 2010 12:49:03 -0800 Subject: Packages at Python.org In-Reply-To: <084f9299-b2b3-440f-b83f-9fbe42220221@j19g2000prh.googlegroups.com> References: <084f9299-b2b3-440f-b83f-9fbe42220221@j19g2000prh.googlegroups.com> Message-ID: On Wed, Dec 1, 2010 at 12:38 PM, kirby.urner at gmail.com wrote: > With Microsoft abandoning Visual FoxPro come 2015, we have 100K > developers > jumping ship (rough guess), perhaps to dot NET, but not necessarily.** > > This page is potentially getting a lot of hits (I'm not privy to the > analytics): > > http://packages.python.org/dbf/ > > So how *do* you get source code from such a web place? You don't; that's only a docs page. You instead want the index entry page: http://pypi.python.org/pypi/dbf which has nice obvious download links. Cheers, Chris From dinov at microsoft.com Wed Dec 1 15:52:41 2010 From: dinov at microsoft.com (Dino Viehland) Date: Wed, 1 Dec 2010 20:52:41 +0000 Subject: Packages at Python.org In-Reply-To: <084f9299-b2b3-440f-b83f-9fbe42220221@j19g2000prh.googlegroups.com> References: <084f9299-b2b3-440f-b83f-9fbe42220221@j19g2000prh.googlegroups.com> Message-ID: <6C7ABA8B4E309440B857D74348836F2EFDD778@TK5EX14MBXC135.redmond.corp.microsoft.com> Kirby wrote: > ** Unconfirmed rumors about IronPython leave me blog searching this > afternoon. Still part of Codeplex? IronPython is still using CodePlex for bug tracking and posting releases but active development is now on GitHub w/ a Mercurial mirror. Jeff's blog has more info: http://jdhardy.blogspot.com/ From kirby.urner at gmail.com Wed Dec 1 15:56:59 2010 From: kirby.urner at gmail.com (kirby.urner at gmail.com) Date: Wed, 1 Dec 2010 12:56:59 -0800 (PST) Subject: Packages at Python.org References: <084f9299-b2b3-440f-b83f-9fbe42220221@j19g2000prh.googlegroups.com> Message-ID: > http://packages.python.org/dbf/ > > So how *do* you get source code from such a web place? ?I'm not > finding > a tar ball or installer. ?Sorry if I'm missing something obvious, like > a link > to Sourceforge. > Thanks to very quick replies with pointers to http://pypi.python.org/pypi/dbf/ instead of to packages.python.org/dbf So this packages.python.org subdomain is perhaps unaware of its pypi.python.org competition, which has a brighter and more open look and feel? What's the story there I wonder? Quite an archeology (reminds me of the Vaults of Parnassus). Thanks again, for restoring me to productivity (was dead in the water for a minute there). Kirby From clp2 at rebertia.com Wed Dec 1 16:07:37 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 1 Dec 2010 13:07:37 -0800 Subject: Packages at Python.org In-Reply-To: References: <084f9299-b2b3-440f-b83f-9fbe42220221@j19g2000prh.googlegroups.com> Message-ID: On Wed, Dec 1, 2010 at 12:56 PM, kirby.urner at gmail.com wrote: >> http://packages.python.org/dbf/ >> >> So how *do* you get source code from such a web place? ?I'm not >> finding >> a tar ball or installer. ?Sorry if I'm missing something obvious, like >> a link >> to Sourceforge. >> > > Thanks to very quick replies with pointers to > > http://pypi.python.org/pypi/dbf/ > > instead of to packages.python.org/dbf > > So this packages.python.org subdomain is perhaps > unaware of its pypi.python.org competition, which > has a brighter and more open look and feel? > > What's the story there I wonder? It's quite simple actually. http://packages.python.org/ : """ This site hosts documentation uploaded by authors of packages in the Python Package Index (http://pypi.python.org). """ One is the actual package index, the other holds docs for packages in the index. Cheers, Chris From robert.kern at gmail.com Wed Dec 1 16:11:52 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 01 Dec 2010 15:11:52 -0600 Subject: Packages at Python.org In-Reply-To: References: <084f9299-b2b3-440f-b83f-9fbe42220221@j19g2000prh.googlegroups.com> Message-ID: On 12/1/10 2:56 PM, kirby.urner at gmail.com wrote: > >> http://packages.python.org/dbf/ >> >> So how *do* you get source code from such a web place? I'm not >> finding >> a tar ball or installer. Sorry if I'm missing something obvious, like >> a link >> to Sourceforge. >> > > Thanks to very quick replies with pointers to > > http://pypi.python.org/pypi/dbf/ > > instead of to packages.python.org/dbf > > So this packages.python.org subdomain is perhaps > unaware of its pypi.python.org competition, which > has a brighter and more open look and feel? > > What's the story there I wonder? pypi.python.org is the Python Package Index (PyPI). packages.python.org is a service for packages on PyPI to host their documentation if they have no other host. They are complementary services, not competition. -- 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 joncle at googlemail.com Wed Dec 1 16:35:47 2010 From: joncle at googlemail.com (Jon Clements) Date: Wed, 1 Dec 2010 13:35:47 -0800 (PST) Subject: Packages at Python.org References: <084f9299-b2b3-440f-b83f-9fbe42220221@j19g2000prh.googlegroups.com> Message-ID: On Dec 1, 8:56?pm, "kirby.ur... at gmail.com" wrote: > >http://packages.python.org/dbf/ > > > So how *do* you get source code from such a web place? ?I'm not > > finding > > a tar ball or installer. ?Sorry if I'm missing something obvious, like > > a link > > to Sourceforge. > > Thanks to very quick replies with pointers to > > http://pypi.python.org/pypi/dbf/ > > instead of to packages.python.org/dbf [snip] > > Kirby I've only had a quick play with it, however, you may want to take a look at Dabo on http://dabodev.com/ Jon. From python at bdurham.com Wed Dec 1 16:55:32 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 01 Dec 2010 16:55:32 -0500 Subject: Packages at Python.org In-Reply-To: References: <084f9299-b2b3-440f-b83f-9fbe42220221@j19g2000prh.googlegroups.com> Message-ID: <1291240532.10840.1408171861@webmail.messagingengine.com> > You may want to take a look at Dabo > http://dabodev.com/ +1 Malcolm From eric.frederich at gmail.com Wed Dec 1 17:12:07 2010 From: eric.frederich at gmail.com (Eric Frederich) Date: Wed, 1 Dec 2010 17:12:07 -0500 Subject: multiple modules from single c extension Message-ID: I have an extension to some C library that I created using the guide found here... http://docs.python.org/extending/extending.html I am starting to have A LOT of functions being wrapped. The library that I'm creating bindings for is organized into modules. In fact, all of their function calls start with a prefix like ABC_do_something, XYZ_something_else. I'd like to start putting the bindings for each module into a separate C file and have each set of bindings end up in its own Python module as well. Is this possible to do using a single .dll / .pyd file so that I can use a single Visual Studio project for these bindings? Is it just a matter of initializing more than one module in the initspam function? PyMODINIT_FUNC initspam(void) { (void) Py_InitModule("spam", SpamMethods); // can I do this? (void) Py_InitModule("spam.ABC", SpamABCMethods); } Would this even work? How would I get a hold of SpamABCMethods now that its in a different file? I tried creating a .h file for the ABC functions which had the prototypes defined as well as the static PyMethodDef SpamABCMethods[] array. This way I could include SpamABC.h which had the array. When I try doing that though, I get link errors saying things like functions are declared but not defined. The example online has everything in a single C file. If I split things up into a .h and a .c file... what should be declared as staic?, should anything be declared as extern? This is where I'm stuck. Thanks, ~Eric From steve+comp.lang.python at pearwood.info Wed Dec 1 17:26:40 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Dec 2010 22:26:40 GMT Subject: Change one list item in place References: <17175f49-087f-4d05-ada2-7e8c7e7e86dd@z17g2000prz.googlegroups.com> Message-ID: <4cf6cba0$0$30003$c3e8da3$5496439d@news.astraweb.com> On Wed, 01 Dec 2010 05:33:55 -0800, Gnarlodious wrote: > Thanks for all the ideas, I've resigned myself to unpacking a tuple and > reassembling it. You make it sound like that's an onerous task. -- Steven From ethan at stoneleaf.us Wed Dec 1 17:32:23 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 01 Dec 2010 14:32:23 -0800 Subject: Packages at Python.org In-Reply-To: <084f9299-b2b3-440f-b83f-9fbe42220221@j19g2000prh.googlegroups.com> References: <084f9299-b2b3-440f-b83f-9fbe42220221@j19g2000prh.googlegroups.com> Message-ID: <4CF6CCF7.3000304@stoneleaf.us> kirby.urner at gmail.com wrote: > > With Microsoft abandoning Visual FoxPro come 2015, we have 100K > developers > jumping ship (rough guess), perhaps to dot NET, but not necessarily.** > > This page is potentially getting a lot of hits (I'm not privy to the > analytics): > > http://packages.python.org/dbf/ The dbf package does not yet support index files. Normal indexes won't be too hard to add in, but I have been unable to find the algorithms used to create/work with compact index files. Does anybody know where I might find those? ~Ethan~ (author of said package) From nobody at nowhere.com Wed Dec 1 17:45:53 2010 From: nobody at nowhere.com (Nobody) Date: Wed, 01 Dec 2010 22:45:53 +0000 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename References: <1291124813.414884.22.camel@WOPR> Message-ID: On Wed, 01 Dec 2010 10:34:24 +0100, Peter Otten wrote: >> Python 3.x's decision to treat filenames (and environment variables) as >> text even on Unix is, in short, a bug. One which, IMNSHO, will mean that >> Python 2.x is still around when Python 4 is released. > > For filenames in Python 3 the user has the choice between "text" (str) and > bytes. If the user chooses text that will be converted to bytes using a > default encoding that hopefully matches that of the other tools on the > machine that manipulate filenames. However, sys.argv and os.environ are automatically converted to text. If you want bytes, you have to convert them back explicitly. Also, I'm unsure as to how far the choice between bytes and str will extend beyond the core modules. > I see that you may run into problems with the text approach when you > encounter byte sequences that are illegal in the chosen encoding. This was actually a critical flaw in Python 3.0, as it meant that filenames which weren't valid in the locale's encoding simply couldn't be passed via argv or environ. 3.1 fixed this using the "surrogateescape" encoding, so now it's only an annoyance (i.e. you can recover the original bytes once you've spent enough time digging through the documentation). There could be a problem with encodings which aren't invertable (e.g. ISO-2022), but those tend to be quite rare and Python flat-out doesn't support those as system encodings anyhow. From joncle at googlemail.com Wed Dec 1 17:51:21 2010 From: joncle at googlemail.com (Jon Clements) Date: Wed, 1 Dec 2010 14:51:21 -0800 (PST) Subject: Packages at Python.org References: <084f9299-b2b3-440f-b83f-9fbe42220221@j19g2000prh.googlegroups.com> Message-ID: On Dec 1, 10:32?pm, Ethan Furman wrote: > kirby.ur... at gmail.com wrote: > > > With Microsoft abandoning Visual FoxPro come 2015, we have 100K > > developers > > jumping ship (rough guess), perhaps to dot NET, but not necessarily.** > > > This page is potentially getting a lot of hits (I'm not privy to the > > analytics): > > >http://packages.python.org/dbf/ > > The dbf package does not yet support index files. ?Normal indexes won't > be too hard to add in, but I have been unable to find the algorithms > used to create/work with compact index files. > > Does anybody know where I might find those? > > ~Ethan~ ?(author of said package) I think John Machin has done work on this, or at least mentioned it in a post somewhere. I could be wrong though - apologies to both you and John, if I'm imagining things. Jon. From lambdadmitry at gmail.com Wed Dec 1 18:18:32 2010 From: lambdadmitry at gmail.com (Dmitry Groshev) Date: Wed, 1 Dec 2010 15:18:32 -0800 (PST) Subject: Some syntactic sugar proposals References: <1290424902.6446.5.camel@laptop> Message-ID: On Nov 22, 2:21?pm, Andreas L?scher wrote: > > ? ? if x in range(a, b): #wrong! > > it feels so natural to check it that way, but we have to write > > ? ? if a <= x <= b > > I understand that it's not a big deal, but it would be awesome to have > > some optimisations - it's clearly possible to detect things like that > > "wrong" one and fix it in a bytecode. > > You can implement it yourself: > > class between(object): > ? ? ? ? def __init__(self, a,b): > ? ? ? ? ? ? ? ? super(crang, self).__init__() > ? ? ? ? ? ? ? ? self.a=a > ? ? ? ? ? ? ? ? self.b=b > ? ? ? ? def __contains__(self, value): > ? ? ? ? ? ? ? ? return self.a <= value <= self.b > > >>> 12.45 in between(-100,100) > > true > > But do you need > > a < ?x < ?b > a <= x < ?b > a <= x <= b or > a < ?x <= b ? > > Sure, you could set a new parameter for this, but the normal way is not > broken at all. > > Best Of course there are better ways to do this. Your "between", standart comparisons and so, but expressing this as "i in range(a, b)" is just intuitive and declarative. Here is a fresh example of what I meant by my first proposal. You need to build a matrix like this: 2 1 0 ... 1 2 1 ... 0 1 2 ... ... ... 1 2 1 ... 0 1 2 You could do this by one-liner: [[(2 - abs(x - y)) if it > 0 else 0 for x in xrange(8)] for y in xrange(8)] ...but in reality you should write something like this: [[(lambda t: t if t > 0 else 0)(2 - abs(x - y)) for x in xrange(8)] for y in xrange(8)] or this [[(2 - abs(x - y)) if (2 - abs(x - y)) > 0 else 0 for x in xrange(8)] for y in xrange(8)] or even this def foo(x, y): if abs(x - y) == 0: return 2 elif abs(x - y) == 1: return 1 else: return 0 [[foo(x, y) for x in xrange(8)] for y in xrange(8)] It's not THAT matter, but it's just about readability and shortness in some cases. From cdalten at gmail.com Wed Dec 1 19:45:34 2010 From: cdalten at gmail.com (chad) Date: Wed, 1 Dec 2010 16:45:34 -0800 (PST) Subject: I can't seem to change the timeout value on pexpect Message-ID: <0387d0dd-9af5-49e6-a0c2-159f016fd319@r31g2000prg.googlegroups.com> I tried to change the timeout value from 30 to 90 for pexpect in the following script... #!/usr/bin/python import telnetlib import time import pexpect def get_name(): user = raw_input("\nUsername: ") password = raw_input("Password: ") idle(user, password) def idle(user, password): child = pexpect.spawn('telnet game.mortalrealms.com 4321') child.expect("Who art thou:", timeout=90) child.sendline(user) print "\nEntered username.." child.expect("Password:",timeout=90) child.sendline(password) print "Entered pass.." child.expect('Press return to continue:', timeout=90) child.sendline('\n') if child == 2: print "Connection timeout" elif child == 3: print "Another timeout" #while 1: child.expect('Druidess Supi burps loudly.') child.sendline('say oh my aching back') #time.sleep(15) #time.sleep(5) #now.write("\n") #while 1: # now.write("wc") # time.sleep(15) if __name__ == "__main__": get_name() However, when I run it, the timeout still shows 30 seconds... Entered username.. Entered pass.. TrFAvAvaricest): File "./mort.py", line 42, in ? FAvAvarice File "./mort.py", line 10, in get_name idle(user, password) File "./mort.py", line 31, in idle child.expect('Druidess Supi burps loudly.') File "/usr/lib/python2.4/site-packages/pexpect.py", line 1311, in expect return self.expect_list(compiled_pattern_list, timeout, searchwindowsize) File "/usr/lib/python2.4/site-packages/pexpect.py", line 1325, in expect_list return self.expect_loop(searcher_re(pattern_list), timeout, searchwindowsize) File "/usr/lib/python2.4/site-packages/pexpect.py", line 1409, in expect_loop raise TIMEOUT (str(e) + '\n' + str(self)) pexpect.TIMEOUT: Timeout exceeded in read_nonblocking(). version: 2.3 ($Revision: 399 $) command: /usr/kerberos/bin/telnet args: ['/usr/kerberos/bin/telnet', 'game.mortalrealms.com', '4321'] searcher: searcher_re: 0: re.compile("Druidess Supi burps loudly.") buffer (last 100 chars): all. before (last 100 chars): all. after: pexpect.TIMEOUT match: None match_index: None exitstatus: None flag_eof: False pid: 23652 child_fd: 3 closed: False timeout: 30 delimiter: pexpect.EOF logfile: None logfile_read: None logfile_send: None maxread: 2000 ignorecase: False searchwindowsize: None delaybeforesend: 0.05 delayafterclose: 0.1 delayafterterminate: 0.1 What am I doing wrong? From dmlb2000 at gmail.com Wed Dec 1 19:49:30 2010 From: dmlb2000 at gmail.com (David Brown) Date: Wed, 1 Dec 2010 16:49:30 -0800 Subject: odd runtime error Message-ID: So I'm not subscribed to python-list but would like to get an answer to my question. I've made a small test program that dumps a RuntimeError and I'd like to know why. $ python test2.py doing stuff Traceback (most recent call last): File "test2.py", line 3, in import test RuntimeError: not holding the import lock child 3693 exited with 256 $ Here's the setup, there's two files test.py and test2.py $ cat test.py #!/usr/bin/python import os, sys if os.fork() == 0: print "doing stuff" sys.exit() print "child %d exited with %d" % os.wait() $ cat test2.py #!/usr/bin/python import test $ I understand that sys.exit() is really just doing a `raise SystemExit(0)' and the RuntimeError shows up with that as well. If you change out sys.exit with os._exit(0) then it doesn't show dump the RuntimeError. Also, this seems to be a python2.6 and python2.7 issue. Python3 doesn't have this issue. I haven't checked with python2.5 or before yet. I was more curious about what this behavior is and why python is doing things this way. I've scoured the python documentation and can't seem to figure out why. Thanks, - David Brown From clp2 at rebertia.com Wed Dec 1 19:59:19 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 1 Dec 2010 16:59:19 -0800 Subject: odd runtime error In-Reply-To: References: Message-ID: On Wed, Dec 1, 2010 at 4:49 PM, David Brown wrote: > So I'm not subscribed to python-list but would like to get an answer > to my question. I've made a small test program that dumps a > RuntimeError and I'd like to know why. > > $ python test2.py > doing stuff > Traceback (most recent call last): > ?File "test2.py", line 3, in > ? ?import test > RuntimeError: not holding the import lock > child 3693 exited with 256 > $ > > Here's the setup, there's two files test.py and test2.py > > $ cat test.py > #!/usr/bin/python > > import os, sys > > if os.fork() == 0: > ? ? ? ?print "doing stuff" > ? ? ? ?sys.exit() > > print "child %d exited with %d" % os.wait() It's *quite* strange for a module that's being imported to execute a fork() in its body; this is almost assuredly the cause of the RuntimeError. Why are you fork()ing in an importable module in the first place? Cheers, Chris -- http://blog.rebertia.com From dmlb2000 at gmail.com Wed Dec 1 20:04:33 2010 From: dmlb2000 at gmail.com (David Brown) Date: Wed, 1 Dec 2010 17:04:33 -0800 Subject: odd runtime error In-Reply-To: References: Message-ID: On Wed, Dec 1, 2010 at 4:59 PM, Chris Rebert wrote: > On Wed, Dec 1, 2010 at 4:49 PM, David Brown wrote: >> So I'm not subscribed to python-list but would like to get an answer >> to my question. I've made a small test program that dumps a >> RuntimeError and I'd like to know why. >> >> $ python test2.py >> doing stuff >> Traceback (most recent call last): >> ?File "test2.py", line 3, in >> ? ?import test >> RuntimeError: not holding the import lock >> child 3693 exited with 256 >> $ >> >> Here's the setup, there's two files test.py and test2.py >> >> $ cat test.py >> #!/usr/bin/python >> >> import os, sys >> >> if os.fork() == 0: >> ? ? ? ?print "doing stuff" >> ? ? ? ?sys.exit() >> >> print "child %d exited with %d" % os.wait() > > It's *quite* strange for a module that's being imported to execute a > fork() in its body; this is almost assuredly the cause of the > RuntimeError. Why are you fork()ing in an importable module in the > first place? Well, to be specific the fork isn't the cause of the RuntimeError, the sys.exit() causes the runtime error. I agree that forking in a module is bad coding practice and I'm working with the developer to help him understand why that's bad. If that makes sense. However, knowing why sys.exit() is producing a RuntimeError on some versions of python and not others also more interesting a question. Thanks, - David Brown > Cheers, > Chris > -- > http://blog.rebertia.com > From prologic at shortcircuit.net.au Wed Dec 1 20:12:17 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 2 Dec 2010 11:12:17 +1000 Subject: odd runtime error In-Reply-To: References: Message-ID: On Thu, Dec 2, 2010 at 10:59 AM, Chris Rebert wrote: > On Wed, Dec 1, 2010 at 4:49 PM, David Brown wrote: >> So I'm not subscribed to python-list but would like to get an answer >> to my question. I've made a small test program that dumps a >> RuntimeError and I'd like to know why. >> >> $ python test2.py >> doing stuff >> Traceback (most recent call last): >> ?File "test2.py", line 3, in >> ? ?import test >> RuntimeError: not holding the import lock >> child 3693 exited with 256 >> $ >> >> Here's the setup, there's two files test.py and test2.py >> >> $ cat test.py >> #!/usr/bin/python >> >> import os, sys >> >> if os.fork() == 0: >> ? ? ? ?print "doing stuff" >> ? ? ? ?sys.exit() >> >> print "child %d exited with %d" % os.wait() Assuming you actually want to fork and do something inside the forked child process, the correct implementation is this: $ cat test.py #!/usr/bin/env python import os from time import sleep def main(): print "parent %d started" % os.getpid() if os.fork() == 0: print "doing stuff" sleep(5) print "done" raise SystemExit, 0 print "child %d exited with %d" % os.wait() if __name__ == "__main__": main() cheers James -- -- James Mills -- -- "Problems are solved by method" From cs at zip.com.au Wed Dec 1 20:19:05 2010 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 2 Dec 2010 12:19:05 +1100 Subject: odd runtime error In-Reply-To: References: Message-ID: <20101202011905.GA14396@cskk.homeip.net> On 01Dec2010 16:49, David Brown wrote: | So I'm not subscribed to python-list but would like to get an answer | to my question. I've made a small test program that dumps a | RuntimeError and I'd like to know why. | | $ python test2.py | doing stuff | Traceback (most recent call last): | File "test2.py", line 3, in | import test | RuntimeError: not holding the import lock | child 3693 exited with 256 | $ | | Here's the setup, there's two files test.py and test2.py | | $ cat test.py | #!/usr/bin/python | | import os, sys | | if os.fork() == 0: | print "doing stuff" | sys.exit() | | print "child %d exited with %d" % os.wait() | $ cat test2.py | #!/usr/bin/python | | import test | $ | | I understand that sys.exit() is really just doing a `raise | SystemExit(0)' and the RuntimeError shows up with that as well. If you | change out sys.exit with os._exit(0) then it doesn't show dump the | RuntimeError. Also, this seems to be a python2.6 and python2.7 issue. | Python3 doesn't have this issue. I haven't checked with python2.5 or | before yet. | | I was more curious about what this behavior is and why python is doing | things this way. I've scoured the python documentation and can't seem | to figure out why. So, test2.py imports "test", which is in "test.py". And the test module forks _during_ the import. Python takes a lock during imports - this stops multiple threads from importing the same module at the same time (avoiding multiple instantiation etc) and other racy fribbing with the in-memory module data structures. So: import test test.py... fork... At this point two programs exist, each in the midst of the import of test.py. It would seem the import lock breaks over the fork, so that the child process doesn't hold the lock. But because it is a fork, it does not know this! (Being identical to its parent.) So you raise SystemExit, and during the stack unwind the child tries to release the lock. Which it doesn't have, thus the breakage. Does that clarify the sequence of events? -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ "I think not," said Descartes, and promptly disappeared. From dmlb2000 at gmail.com Wed Dec 1 20:27:05 2010 From: dmlb2000 at gmail.com (David Brown) Date: Wed, 1 Dec 2010 17:27:05 -0800 Subject: odd runtime error In-Reply-To: <20101202011905.GA14396@cskk.homeip.net> References: <20101202011905.GA14396@cskk.homeip.net> Message-ID: On Wed, Dec 1, 2010 at 5:19 PM, Cameron Simpson wrote: > On 01Dec2010 16:49, David Brown wrote: > | So I'm not subscribed to python-list but would like to get an answer > | to my question. I've made a small test program that dumps a > | RuntimeError and I'd like to know why. > | > | $ python test2.py > | doing stuff > | Traceback (most recent call last): > | ? File "test2.py", line 3, in > | ? ? import test > | RuntimeError: not holding the import lock > | child 3693 exited with 256 > | $ > | > | Here's the setup, there's two files test.py and test2.py > | > | $ cat test.py > | #!/usr/bin/python > | > | import os, sys > | > | if os.fork() == 0: > | ? ? ? print "doing stuff" > | ? ? ? sys.exit() > | > | print "child %d exited with %d" % os.wait() > | $ cat test2.py > | #!/usr/bin/python > | > | import test > | $ > | > | I understand that sys.exit() is really just doing a `raise > | SystemExit(0)' and the RuntimeError shows up with that as well. If you > | change out sys.exit with os._exit(0) then it doesn't show dump the > | RuntimeError. Also, this seems to be a python2.6 and python2.7 issue. > | Python3 doesn't have this issue. I haven't checked with python2.5 or > | before yet. > | > | I was more curious about what this behavior is and why python is doing > | things this way. I've scoured the python documentation and can't seem > | to figure out why. > > So, test2.py imports "test", which is in "test.py". > And the test module forks _during_ the import. > > Python takes a lock during imports - this stops multiple threads > from importing the same module at the same time (avoiding multiple > instantiation etc) and other racy fribbing with the in-memory module > data structures. > > So: > ?import test > ? ?test.py... > ? ? ?fork... > > At this point two programs exist, each in the midst of the import of > test.py. It would seem the import lock breaks over the fork, so that the > child process doesn't hold the lock. But because it is a fork, it does > not know this! (Being identical to its parent.) So you raise SystemExit, > and during the stack unwind the child tries to release the lock. Which > it doesn't have, thus the breakage. > > Does that clarify the sequence of events? Thanks for the clarification I like the idea of wrapping all the primary code in the script to a main function then calling it if its being called by main. I think I got a better handle on things. Thanks, - David Brown > Cameron Simpson DoD#743 > http://www.cskk.ezoshosting.com/cs/ > > "I think not," said Descartes, and promptly disappeared. > From robert.kern at gmail.com Wed Dec 1 20:39:14 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 01 Dec 2010 19:39:14 -0600 Subject: multiple modules from single c extension In-Reply-To: References: Message-ID: On 12/1/10 4:12 PM, Eric Frederich wrote: > I have an extension to some C library that I created using the guide > found here... > > http://docs.python.org/extending/extending.html > > I am starting to have A LOT of functions being wrapped. > > The library that I'm creating bindings for is organized into modules. > In fact, all of their function calls start with a prefix like > ABC_do_something, XYZ_something_else. > > I'd like to start putting the bindings for each module into a separate > C file and have each set of bindings end up in its own Python module > as well. > > Is this possible to do using a single .dll / .pyd file so that I can > use a single Visual Studio project for these bindings? No, I don't think so. The Python import mechanism will be looking for an appropriately-named .pyd file for each module. In any case, you shouldn't be using Visual Studio directly to build the .pyd. Instead, use distutils. -- 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 kirby.urner at gmail.com Wed Dec 1 21:29:01 2010 From: kirby.urner at gmail.com (kirby urner) Date: Wed, 1 Dec 2010 18:29:01 -0800 Subject: Packages at Python.org In-Reply-To: <4CF6CCF7.3000304@stoneleaf.us> References: <084f9299-b2b3-440f-b83f-9fbe42220221@j19g2000prh.googlegroups.com> <4CF6CCF7.3000304@stoneleaf.us> Message-ID: Good to hear from you sir. I've enjoying working with your modules and am getting some good results. I sent you a note off-list wondering how actively you might be supporting this valuable utility. Encouraging to find you here so quickly. Kirby On Wed, Dec 1, 2010 at 2:32 PM, Ethan Furman wrote: > kirby.urner at gmail.com wrote: > >> >> With Microsoft abandoning Visual FoxPro come 2015, we have 100K >> developers >> jumping ship (rough guess), perhaps to dot NET, but not necessarily.** >> >> This page is potentially getting a lot of hits (I'm not privy to the >> analytics): >> >> http://packages.python.org/dbf/ >> > > The dbf package does not yet support index files. Normal indexes won't be > too hard to add in, but I have been unable to find the algorithms used to > create/work with compact index files. > > Does anybody know where I might find those? > > ~Ethan~ (author of said package) > -------------- next part -------------- An HTML attachment was scrubbed... URL: From hugh.seckerwalker at gmail.com Wed Dec 1 21:49:28 2010 From: hugh.seckerwalker at gmail.com (HughSW) Date: Wed, 1 Dec 2010 18:49:28 -0800 (PST) Subject: docstring inheritance Message-ID: <0037b3b8-36f7-4568-a5a6-22020e7e5b2d@a17g2000yql.googlegroups.com> We've been trying to find an easy way to inherit docstrings when overriding methods in subclasses, e.g. so that Sphinx does a nice job. We used Shai's DocInherit code from this post: http://groups.google.com/group/comp.lang.python/tree/browse_frm/thread/1e4075ba10dcbdd9/f63651cd9e76df63?rnum=1&_done=%2Fgroup%2Fcomp.lang.python%2Fbrowse_frm%2Fthread%2F1e4075ba10dcbdd9%2F%3F#doc_5f5963372b951d79 of this thread http://groups.google.com/group/comp.lang.python/browse_frm/thread/1e4075ba10dcbdd9/ The DocInherit property works fine, except that all the logic for adding the docstring to the method is evaluated every single time the method is looked up. I experimented with a simple caching scheme but abandoned it. I've tried a new approach -- it uses the same property mechanism as Shai's code to delay doing anything until the class exists and the method is used -- but it does its work only once, the first time the method is looked up; it adds the docstring from the first mro parent, and then the property *replaces itself* in the class's namespace with the method that now has a docstring. It appears to work in a large project with extensive testing. My question concerns whether it is risky to replace a class property attribute to a method attribute after the class has been created, and perhaps after the class has been used? Does this kind of change violate some subtle or internal expectations of the interpreter runtime? Thanks. -Hugh Here's the code and doctests: class InheritDoc(object): """ Docstring inheriting method descriptor The class itself is used as a decorator that creates a class property for the method; the first time the property is used it installs the method's doc and then replaces itself as a class attribute with the method! Usage: >>> class Foo(object): ... def foo(self, x): ... 'Frobber' ... print 'Foo.foo()', x Correct usage for overridden method foo(), incorrect usage for method bar() >>> class Bar(Foo): ... @inherit_doc ... def foo(self, x): ... print 'Bar.foo()', x ... @inherit_doc ... def bar(self): ... print 'Bar.bar()' >>> Bar.foo.__doc__ == Bar().foo.__doc__ == Foo.foo.__doc__ == 'Frobber' True >>> Foo.foo >>> Foo().foo(10) Foo.foo() 10 >>> Bar.foo >>> Bar().foo(11) Bar.foo() 11 >>> Bar.bar Traceback (most recent call last): ... NameError: inherit_doc cannot find method 'bar' in parents of '__main__.Bar' >>> Bar().bar Traceback (most recent call last): ... NameError: inherit_doc cannot find method 'bar' in parents of '__main__.Bar' """ __slots__ = 'inherit_doc_unbound_method' def __init__(self, unbound_method): self.inherit_doc_unbound_method = unbound_method def __get__(self, obj, cls): # a self-destructing descriptor/ property: # the first and only time it's used, it fixes the method's doc and then # replaces itself with the method # find the overridden method in mro sequence, skipping the class itself method_name = self.inherit_doc_unbound_method.__name__ mro_iter = iter(cls.__mro__) mro_iter.next() for parent in mro_iter: overridden = getattr(parent, method_name, None) if overridden is not None: break if overridden is None: raise NameError('inherit_doc cannot find method %r in parents of %r' % (method_name, '%s.%s'%(cls.__module__, cls.__name__))) # XXX next steps are not threadsafe, maybe not safe at all! # set the doc self.inherit_doc_unbound_method.__doc__ = overridden.__doc__ # replace the property with the function setattr(cls, method_name, self.inherit_doc_unbound_method) # use the replacement return getattr(obj if obj is not None else cls, method_name) inherit_doc = InheritDoc From hugh.seckerwalker at gmail.com Wed Dec 1 21:56:31 2010 From: hugh.seckerwalker at gmail.com (HughSW) Date: Wed, 1 Dec 2010 18:56:31 -0800 (PST) Subject: docstring inheritance References: <0037b3b8-36f7-4568-a5a6-22020e7e5b2d@a17g2000yql.googlegroups.com> Message-ID: Grrrr, sorry about the line wrapping horror; trying again. class InheritDoc(object): """ Docstring inheriting method descriptor The class itself is used as a decorator that creates a class property for the method; the first time the property is used it installs the method's doc and then replaces itself as a class attribute with the method! Usage: >>> class Foo(object): ... def foo(self, x): ... 'Frobber' ... print 'Foo.foo()', x Correct usage for overridden method foo(), incorrect usage for method bar() >>> class Bar(Foo): ... @inherit_doc ... def foo(self, x): ... print 'Bar.foo()', x ... @inherit_doc ... def bar(self): ... print 'Bar.bar()' >>> Bar.foo.__doc__ == Bar().foo.__doc__ == Foo.foo.__doc__ == 'Frobber' True >>> Foo.foo >>> Foo().foo(10) Foo.foo() 10 >>> Bar.foo >>> Bar().foo(11) Bar.foo() 11 >>> Bar.bar Traceback (most recent call last): ... NameError: inherit_doc cannot find method 'bar' in parents of '__main__.Bar' >>> Bar().bar Traceback (most recent call last): ... NameError: inherit_doc cannot find method 'bar' in parents of '__main__.Bar' """ __slots__ = 'inherit_doc_unbound_method' def __init__(self, unbound_method): self.inherit_doc_unbound_method = unbound_method def __get__(self, obj, cls): # a self-destructing descriptor/property: # the first and only time it's used, it fixes the method's doc and then # replaces itself with the method # find the overridden method in mro sequence, skipping the class itself method_name = self.inherit_doc_unbound_method.__name__ mro_iter = iter(cls.__mro__) mro_iter.next() for parent in mro_iter: overridden = getattr(parent, method_name, None) if overridden is not None: break if overridden is None: raise NameError('inherit_doc cannot find method %r in parents of %r' % (method_name, '%s.%s'%(cls.__module__, cls.__name__))) # XXX next steps are not threadsafe, maybe not safe at all! # set the doc self.inherit_doc_unbound_method.__doc__ = overridden.__doc__ # replace the property with the function setattr(cls, method_name, self.inherit_doc_unbound_method) # use the replacement return getattr(obj if obj is not None else cls, method_name) inherit_doc = InheritDoc From wallenpb at gmail.com Wed Dec 1 22:39:01 2010 From: wallenpb at gmail.com (Bill Allen) Date: Wed, 1 Dec 2010 21:39:01 -0600 Subject: Python's equivalent to Main calling program and subprograms In-Reply-To: References: <4CF67AF4.7040201@sequans.com> Message-ID: Thanks for the explanation of "main". Some tutorials mention it, some don't. I have written some not trial Python programs and have never had a real need to use that convention, but at least I understand it now. --Bill On Wed, Dec 1, 2010 at 1:13 PM, Tim Harig wrote: > > On Wed, Dec 1, 2010 at 9:08 AM, m b wrote: > >>> > if __name__ == "__main__": > >>> > main() > >> > >> What does this mean? > > It is a Python idiom and a good practice. Strictly speaking it is > unnecessary. Python doesn't recognize any functional initialization > vector other then the start of the file. When Python loads a module, > it executes anything it finds in the module scope (Anything not in the > body of a class or function declaration). Using a main function is just > a convention. You could just place all of your main level code in the > module scope: > > def Subprogram1(): > # code > def Subprogram2(): > # code > def Subprogram3(): > # code > > # main code > > or equivilantly, always execute main(): > > def Subprogram1(): > # code > def Subprogram2(): > # code > def Subprogram3(): > # code > def main(): > # main code > main() > > Both are valid from Python's point of view. > > The 'if __name__ == "__main__":' idiom is used, because it allows the > module to be loaded without running main(). This is useful if you wanted > to use Subprogram2() from another program. Even if you don't forsee using > any of the subprograms (functions to Python), this can be useful when > writing test code as you can import the program as a module to test its > classes or functions separately. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From cs at zip.com.au Wed Dec 1 23:16:43 2010 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 2 Dec 2010 15:16:43 +1100 Subject: odd runtime error In-Reply-To: References: Message-ID: <20101202041643.GA5381@cskk.homeip.net> On 01Dec2010 17:27, David Brown wrote: | Thanks for the clarification No worries. | I like the idea of wrapping all the | primary code in the script to a main function then calling it if its | being called by main. I find that useful too. I've got a few modules-that-implement-commands that look like this: def main(argv): ... parse args, do stuff ... return exit_status ... functions, classes etc ... if __name__ == '__main__': sys.exit(main(sys.argv)) It seems fairly effective for keeping the top level logic up the top. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ It's better, when you're riding with someone you don't know so well, to stick to the inside line - it's easier to avoid the bits... - Barry Sheene From jlconlin at gmail.com Thu Dec 2 00:36:32 2010 From: jlconlin at gmail.com (Jeremy) Date: Wed, 1 Dec 2010 21:36:32 -0800 (PST) Subject: How can I define class methods outside of the class? Message-ID: I have some methods that I need (would like) to define outside of the class. I know this can be done by defining the function and then setting it equal to some member of an instance of the class. But, because of the complexity of what I'm doing (I have to set many functions as class methods) I would rather not do this. Can someone show me how to do this? Is it even possible? Can decorators be used here? Thanks, Jeremy From prologic at shortcircuit.net.au Thu Dec 2 00:47:35 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 2 Dec 2010 15:47:35 +1000 Subject: How can I define class methods outside of the class? In-Reply-To: References: Message-ID: On Thu, Dec 2, 2010 at 3:36 PM, Jeremy wrote: > I have some methods that I need (would like) to define outside of the > class. ?I know this can be done by defining the function and then > setting it equal to some member of an instance of the class. ?But, > because of the complexity of what I'm doing (I have to set many > functions as class methods) I would rather not do this. ?Can someone > show me how to do this? ?Is it even possible? ?Can decorators be used > here? Do you mean something like this ? @classmethod def foo(cls): print "I am the foo classmethod on %r" % cls class Foo(object): pass Foo.foo = foo cheers James -- -- James Mills -- -- "Problems are solved by method" From steve+comp.lang.python at pearwood.info Thu Dec 2 01:14:14 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 Dec 2010 06:14:14 GMT Subject: Some syntactic sugar proposals References: <1290424902.6446.5.camel@laptop> Message-ID: <4cf73935$0$30004$c3e8da3$5496439d@news.astraweb.com> On Wed, 01 Dec 2010 15:18:32 -0800, Dmitry Groshev wrote: > Here is a fresh example of what I meant by my first proposal. You need > to build a matrix like this: > 2 1 0 ... > 1 2 1 ... > 0 1 2 ... > ... > ... 1 2 1 > ... 0 1 2 > You could do this by one-liner: > [[(2 - abs(x - y)) if it > 0 else 0 for x in xrange(8)] for y in > xrange(8)] > ...but in reality you should write something like this: [[(lambda t: t > if t > 0 else 0)(2 - abs(x - y)) for x in xrange(8)] for y in xrange(8)] > or this > [[(2 - abs(x - y)) if (2 - abs(x - y)) > 0 else 0 for x in xrange(8)] > for y in xrange(8)] > or even this > def foo(x, y): > if abs(x - y) == 0: > return 2 > elif abs(x - y) == 1: > return 1 > else: > return 0 > [[foo(x, y) for x in xrange(8)] for y in xrange(8)] All those one-liners give me a headache. At least your "foo" solution is understandable. But I'd do it like this: >>> array = [[0]*8 for _ in range(8)] >>> for i in range(8): ... array[i][i] = 2 ... if i > 0: array[i][i-1] = 1 ... if i < 7: array[i][i+1] = 1 ... >>> pprint.pprint(array) [[2, 1, 0, 0, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0, 0, 0], [0, 1, 2, 1, 0, 0, 0, 0], [0, 0, 1, 2, 1, 0, 0, 0], [0, 0, 0, 1, 2, 1, 0, 0], [0, 0, 0, 0, 1, 2, 1, 0], [0, 0, 0, 0, 0, 1, 2, 1], [0, 0, 0, 0, 0, 0, 1, 2]] When you stop trying to make everything a one-liner, it's amazing how readable you can make code :) -- Steven From drsalists at gmail.com Thu Dec 2 01:14:19 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 1 Dec 2010 22:14:19 -0800 Subject: Unicode thing that causes a traceback in 2.6 and 2.7 but not in 2.5, and only when writing to a pipe, not to the terminal Message-ID: What is this about? It's another n~ thing, but this time in 2.x. All I'm doing is printing a str containing a character > 127. It works fine in 2.5, to a terminal or to a pipe. In 2.6 and 2.7, it fails when writing to a pipe but works fine writing to my terminal - an mrxvt.\ I really kind of want octets to just be octets, since I'm on a Linux system - it probably should be up to the user and their related software to decide how those octets are interpreted. I'm assuming that the bytes() workarounds I'm using in 3.x aren't going to work in 2.x - it looks like bytes() is just an alias for str() in 2.6 and 2.7. BTW, the print(line) in the traceback looks like Python 3 syntax, and it is I guess, but it's also Python 2 compatible. In 3.x, it's a function with a single argument, in 2.x it's a statement with a parenthesized expression. Thanks! benchbox-dstromberg:~/src/home-svn/readline0/trunk i686-pc-linux-gnu 17932 - above cmd done 2010 Wed Dec 01 09:40 PM $ find /usr/share/jpilot -print0 | /usr/local/cpython-2.5/bin/python ./test-readline0 2>&1 | cat /usr/share/jpilot /usr/share/jpilot/CalendarDB-PDat.pdb /usr/share/jpilot/Ma?anaDB.pdb /usr/share/jpilot/jpilotrc.green /usr/share/jpilot/jpilotrc.purple /usr/share/jpilot/ContactsDB-PAdd.pdb /usr/share/jpilot/MemoDB.pdb /usr/share/jpilot/jpilotrc.blue /usr/share/jpilot/ExpenseDB.pdb /usr/share/jpilot/jpilotrc.default /usr/share/jpilot/AddressDB.pdb /usr/share/jpilot/ToDoDB.pdb /usr/share/jpilot/TasksDB-PTod.pdb /usr/share/jpilot/DatebookDB.pdb /usr/share/jpilot/Memo32DB.pdb /usr/share/jpilot/MemosDB-PMem.pdb /usr/share/jpilot/jpilotrc.steel benchbox-dstromberg:~/src/home-svn/readline0/trunk i686-pc-linux-gnu 17932 - above cmd done 2010 Wed Dec 01 09:40 PM $ find /usr/share/jpilot -print0 | /usr/local/cpython-2.6/bin/python ./test-readline0 2>&1 | cat /usr/share/jpilot /usr/share/jpilot/CalendarDB-PDat.pdb Traceback (most recent call last): File "./test-readline0", line 22, in print(line) UnicodeEncodeError: 'ascii' codec can't encode character u'\xf1' in position 20: ordinal not in range(128) benchbox-dstromberg:~/src/home-svn/readline0/trunk i686-pc-linux-gnu 17932 - above cmd done 2010 Wed Dec 01 09:40 PM $ find /usr/share/jpilot -print0 | /usr/local/cpython-2.6/bin/python ./test-readline0 2>&1 /usr/share/jpilot /usr/share/jpilot/CalendarDB-PDat.pdb /usr/share/jpilot/Ma??anaDB.pdb /usr/share/jpilot/jpilotrc.green /usr/share/jpilot/jpilotrc.purple /usr/share/jpilot/ContactsDB-PAdd.pdb /usr/share/jpilot/MemoDB.pdb /usr/share/jpilot/jpilotrc.blue /usr/share/jpilot/ExpenseDB.pdb /usr/share/jpilot/jpilotrc.default /usr/share/jpilot/AddressDB.pdb /usr/share/jpilot/ToDoDB.pdb /usr/share/jpilot/TasksDB-PTod.pdb /usr/share/jpilot/DatebookDB.pdb /usr/share/jpilot/Memo32DB.pdb /usr/share/jpilot/MemosDB-PMem.pdb /usr/share/jpilot/jpilotrc.steel benchbox-dstromberg:~/src/home-svn/readline0/trunk i686-pc-linux-gnu 17932 - above cmd done 2010 Wed Dec 01 09:41 PM $ From kirby.urner at gmail.com Thu Dec 2 01:28:09 2010 From: kirby.urner at gmail.com (kirby.urner at gmail.com) Date: Wed, 1 Dec 2010 22:28:09 -0800 (PST) Subject: DBF (VFP) to XLS (Excel) in pure Python References: <084f9299-b2b3-440f-b83f-9fbe42220221@j19g2000prh.googlegroups.com> Message-ID: <5ddf7758-754f-4649-be1e-85cdee7860e5@y23g2000yqd.googlegroups.com> Playing around with arcane tools to read those pesky DBF files (with memo fields), like floating wine barrels cast off the sinking VFP ship. http://pypi.python.org/pypi/dbf http://packages.python.org/dbf/dbf-module.html Me threading on comp.lang.python: http://bit.ly/e547Za xlwt and xlrt for reading and writing Excel data, without needing Excel, are also making Python attractive Here's a code fragment giving the idea: from os import path from time import time import dbf def test2(): thepath = path.normpath(<< file path >>) thefile = "shiptemp.dbf" pathfile = path.join(thepath, thefile) thedbf = dbf.VfpTable(pathfile) header_style = easyxf('font: name Arial, bold True, height 200;') book = Workbook() sheet1 = book.add_sheet('Sheet 1') for (i, name) in enumerate(thedbf.field_names): sheet1.write(0, i, name, header_style) for (i, thecol) in enumerate(thedbf.structure()): name, thetype = str(thecol).split() thelen, thedec = 0,0 if "(" in thetype: if "," in thetype: thelen, thedec = [int(k) for k in thetype[2:-1].split(",")] else: thelen, thedec = int(thetype[2:-1]), 0 thetype = thetype[0] if thetype == "M": thelen = 100 elif thelen == 0: thelen = 1 colwidth = max(len(name), int(thelen)) # print colwidth sheet1.col(i).width = colwidth * 310 thedbf.top() messages = [] for row in range(1, len(thedbf)): record = thedbf.next() for col in range(len(thedbf.field_names)): try: sheet1.row(row).write(col, record[col]) except Exception: pass book.save("C:\\Documents and Settings\\HP_Administrator\\My Documents\\Visual FoxPro Projects\\shiptemp.xls") thedbf.close() if __name__ == "__main__": start = time() test2() end = time() print end - start At the moment I'm unable to get the 1500 record x 156 column table (with memos) to stay in memory even with the disk file closed, which I understand is a feature of this package http://pypi.python.org/pypi/dbf/ >>> thetable = dbf.VfpTable(thefile) >>> thetable[1] << data dump >> >>> thetable.close(keep_table=True, keep_memos=True) Traceback (most recent call last): File "", line 1, in thetable.close(keep_table=True, keep_memos=True) File "C:/Python26/Lib/site-packages\dbf\tables.py", line 1141, in close for record in yo: File "C:/Python26/Lib/site-packages\dbf\tables.py", line 676, in next record = yo._table[yo._index] File "C:/Python26/Lib/site-packages\dbf\tables.py", line 817, in __getitem__ return yo._table[yo._index[value]] File "C:/Python26/Lib/site-packages\dbf\tables.py", line 655, in __getitem__ yo._meta.dfd.seek(location) AttributeError: 'NoneType' object has no attribute 'seek' Same error with: >>> thetable = dbf.VfpTable(thefile) >>> thetable.close(keep_memos=True) Python 2.6 / Win7 Kirby From v.harishankar at gmail.com Thu Dec 2 02:28:30 2010 From: v.harishankar at gmail.com (Harishankar) Date: Thu, 2 Dec 2010 07:28:30 +0000 (UTC) Subject: Comparison with False - something I don't understand Message-ID: When I run pychecker through my modules I get the message that comparisons with "False" is not necessary and that it might yield unexpected results. Yet in some situations I need to specifically check whether False was returned or None was returned. Why is comparison with False so bad? # example code which matches both False and None if not var: # do something # specifically check if False is returned # I don't want None if var == False: # do something So how do you get around this? My functions return False and None under different circumstances. Should I raise exceptions instead? I feel it's unnecessary clutter to use exceptions unless absolutely no other solution is available and yet I have doubts about the "False" value. -- Harishankar (http://harishankar.org http://lawstudentscommunity.com) From ian.g.kelly at gmail.com Thu Dec 2 02:32:07 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 02 Dec 2010 00:32:07 -0700 Subject: How can I define class methods outside of the class? In-Reply-To: References: Message-ID: On 12/1/2010 10:47 PM, James Mills wrote: > On Thu, Dec 2, 2010 at 3:36 PM, Jeremy wrote: >> I have some methods that I need (would like) to define outside of the >> class. I know this can be done by defining the function and then >> setting it equal to some member of an instance of the class. But, >> because of the complexity of what I'm doing (I have to set many >> functions as class methods) I would rather not do this. Can someone >> show me how to do this? Is it even possible? Can decorators be used >> here? > > Do you mean something like this ? > > @classmethod > def foo(cls): > print "I am the foo classmethod on %r" % cls > > class Foo(object): > pass > > Foo.foo = foo Slightly better: def foo(cls): # Do something class Foo(object): pass Foo.foo = classmethod(foo) This way the unbound foo is callable as well. Cheers, Ian From alice at gothcandy.com Thu Dec 2 03:15:42 2010 From: alice at gothcandy.com (=?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=) Date: Thu, 2 Dec 2010 00:15:42 -0800 Subject: Comparison with False - something I don't understand References: Message-ID: Howdy! > When I run pychecker through my modules I get the message that > comparisons with "False" is not necessary and that it might yield > unexpected results. Comparisons against False -are- dangerous, demonstrated below. > Yet in some situations I need to specifically check whether False was > returned or None was returned. Why is comparison with False so bad? (False == 0) is True (True == 1) is True The bool type is a subclass of int! (Run those lines in a Python interpreter to see. ;) > if var == False: if var is False: ? > So how do you get around this? My functions return False and None under > different circumstances. Should I raise exceptions instead? I feel it's > unnecessary clutter to use exceptions unless absolutely no other > solution is available and yet I have doubts about the "False" value. If you want to check not just for value equivelance (False == 0) but literal type, use the "is" comparator. "is" checks, and others correct me if I'm wrong, the literal memory address of an object against another. E.g. False, being a singleton, will always have the same memory address. (This is true of CPython, possibly not of Python implementations like Jython or IronPython.) Using "is" will be effective for checking for literal None as well. When ever I need to test for None, I always use the "is" comparator. It's also more English-like. (None, evaluating to False when using '==', is useful when all you care about is having a blank default value, for example.) ? Alice. From eric.brunel at pragmadev.nospam.com Thu Dec 2 04:21:49 2010 From: eric.brunel at pragmadev.nospam.com (Eric Brunel) Date: Thu, 02 Dec 2010 10:21:49 +0100 Subject: Decorate un Frame with window managers title bar, etc en Tkinter 8.5 References: Message-ID: In article , craf wrote: > Hi. > > I use python 3.1 and Tkinter 8.5 in Ubuntu 9.10 > > I would like to turn a frame into a toolbox, > ,and for that I read that you can use the command wm manage (window) > > The information can be found at: > http://www.tcl.tk/man/tcl8.5/TkCmd/wm.htm#M39 > > the explanation says: > > wm manage widget: > The widget specified will become a stand alone top-level window. > The window will be decorated with the window managers title bar, > etc. Only frame, labelframe and toplevel widgets can be used > with this command. Attempting to pass any other widget type will > raise an error. Attempting to manage a toplevel widget is benign > and achieves nothing. See also GEOMETRY MANAGEMENT. > > I have tried to use it in Tkinter but I can not know how is its > structure. > > In Tkinter should be: > > ---TEST CODE------------------- > > from Tkinter import > > master = Tk() > frame = Frame(master) > wm_manager(Frame) > master.mainloop() > > -------------------------------- > > But this does not work. If your version of Tkinter supports it, then the correct syntax is: frame.wm_manage() Please note you have to call it on the Frame instance (the one you named frame), and not on Frame with a big F which is the class. If it says the method doesn't exist (AttributeError raised on the line frame.wm_manage()), you can also try to do it at tcl/tk level with the line: master.tk.call('wm', 'manage', frame) > I appreciate any of this item HTH - Eric - From nobody at nowhere.com Thu Dec 2 04:58:18 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 02 Dec 2010 09:58:18 +0000 Subject: Comparison with False - something I don't understand References: Message-ID: On Thu, 02 Dec 2010 07:28:30 +0000, Harishankar wrote: > When I run pychecker through my modules I get the message that > comparisons with "False" is not necessary and that it might yield > unexpected results. > > Yet in some situations I need to specifically check whether False was > returned or None was returned. Why is comparison with False so bad? The behaviour may be counterintuitive. One might expect that "x == False" is equivalent to "not x". Sometimes it is, sometimes it isn't. E.g. 0 and 0.0 are equal to False and are equivalent to False when converted to booleans: > 0 == False True > not 0 True > 0.0 == False True > not 0.0 True [], "" and None aren't equal to False but are equivalent to False when converted to booleans: > [] == False False > not [] True > "" == False False > not "" True > None == False False > not None True The boolean conversions are what's relevant for "if x ...", "while x ...", etc. If you want to test specifically for True, False or None, use "is" rather than an equality check. This eliminates the warning and doesn't risk misleading someone reading the code. From v.harishankar at gmail.com Thu Dec 2 05:02:03 2010 From: v.harishankar at gmail.com (Harishankar) Date: Thu, 2 Dec 2010 10:02:03 +0000 (UTC) Subject: Comparison with False - something I don't understand References: Message-ID: On Thu, 02 Dec 2010 00:15:42 -0800, Alice Bevan?McGregor wrote: > Howdy! Good day to you! > (False == 0) is True > (True == 1) is True I see. Thanks for this. I suspected this, but wasn't sure. > The bool type is a subclass of int! (Run those lines in a Python > interpreter to see. ;) > >> if var == False: > > if var is False: ? So "var is False" is safer to use when I want to specifically check whether var is set to False and not 0 or None? > If you want to check not just for value equivelance (False == 0) but > literal type, use the "is" comparator. "is" checks, and others correct > me if I'm wrong, the literal memory address of an object against > another. E.g. False, being a singleton, will always have the same > memory address. (This is true of CPython, possibly not of Python > implementations like Jython or IronPython.) Using "is" will be > effective for checking for literal None as well. Thanks, it makes sense to me now. Literal equivalence is what I was looking for. I didn't quite understand whether == achieved this or not. Now I guess I know. > > When ever I need to test for None, I always use the "is" comparator. > It's also more English-like. (None, evaluating to False when using > '==', is useful when all you care about is having a blank default value, > for example.) Yes, but in my function I don't want to confuse False with 0 or anything else except False. Thanks again for explaining this clearly. -- Harishankar (http://harishankar.org http://lawstudentscommunity.com) From v.harishankar at gmail.com Thu Dec 2 05:04:11 2010 From: v.harishankar at gmail.com (Harishankar) Date: Thu, 2 Dec 2010 10:04:11 +0000 (UTC) Subject: Comparison with False - something I don't understand References: Message-ID: On Thu, 02 Dec 2010 09:58:18 +0000, Nobody wrote: > If you want to test specifically for True, False or None, use "is" > rather than an equality check. This eliminates the warning and doesn't > risk misleading someone reading the code. Thanks so much for this very specific answer. I guess "is" is what I am looking for. :-) -- Harishankar (http://harishankar.org http://lawstudentscommunity.com) From me+list/python at ixokai.io Thu Dec 2 05:49:50 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 02 Dec 2010 02:49:50 -0800 Subject: Comparison with False - something I don't understand In-Reply-To: References: Message-ID: <4CF779CE.3040209@ixokai.io> On 12/2/10 2:02 AM, Harishankar wrote: > On Thu, 02 Dec 2010 00:15:42 -0800, Alice Bevan?McGregor wrote: >> The bool type is a subclass of int! (Run those lines in a Python >> interpreter to see. ;) >> >>> if var == False: >> >> if var is False: ? > > So "var is False" is safer to use when I want to specifically check > whether var is set to False and not 0 or None? Equality is a somewhat fuzzy concept. By convention and habit, its usually fine and clear: but its still fuzzy and up to each individual object involved to answer the question of equality. Now, its generally suggested in Python to do fairly vague truth testing: "if x" and "if not x" as opposed to concepts like "if x == True" and "if x == False" because the former is broad but usually more correct, and the latter can lead to some unexpected semantics. But that doesn't mean you must never check if something is False or True: there are times when you really do want or need to see if _False_ is what's being returned, or _True_, or _None_. In this case, use "is", yes, indeed. The "is" operator checks absolute object identity, and so is how you should do that check in cases where you want to test the distinction between "Is it /False/, or just something false-ish or not-true or nothing-ish?" Generally speaking in Python, you usually want to do tests as "if x" or "if not x". But sometimes you need to know if "x" is a specific singleton value: True, False or None. In that case, its okay to do "if x is True", "if x is False" or "if x is None". But you should only do that after the simple test is deemed inappropriate in your API or situation. And-- here's the rub-- while "is" is absolutely OK and right for you to use to test if an object is one of those singletons, its *probably* NOT what you want to do in any other situation*. Outside of the True/False/None singletons, and places where you're doing some special OOP-stuff, you almost certainly don't want to use 'is', but use equality checking (even if its fuzzy, because its fuzzy) instead. This demonstrates why "is" should be avoided except when in those singleton situations (except when you need to, of course): >>> a = 2 >>> b = 2 >>> a is b True >>> a == b True >>> a = 20000 >>> b = 20000 >>> a is b False >>> a == b True (If you're wondering why that's happening: Python makes very little in the way of promises with regard to object identity. It may choose to make a whole new int object of value 2 every time you type 2, or use the same old int object each time: sure, presently it tends to only share "small" integers for re-use, but that's not a promise, not a documented feature, but a function of the current implementation. It could happen tomorrow, in theory, that where a = 10000; b = 10000; become the same object as far as "is" is concerned even though today they are different... "is" should only be used in situations where you care about absolute object identity, not *value*.) -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ * P.S. I'm not saying its never right to use "is" outside of The Singletons. Just that its probably not, for most people, what they actually should do in most code. There are numerous counter-examples, of course. Its just a general guideline to follow. Until a need arises that demonstrates otherwise. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From yegorov.p at gmail.com Thu Dec 2 06:12:42 2010 From: yegorov.p at gmail.com (yegorov-p) Date: Thu, 2 Dec 2010 03:12:42 -0800 (PST) Subject: How to send an IP packet in Python? Message-ID: <6800bc0a-14f5-4262-ab0b-fb3f175e7a25@y23g2000yqd.googlegroups.com> Hello. I have sniffed some packet and now I would like to send it with the help of python. It's some simple IGMP packet with VLAN tag. (01 00 5E 00 43 67 00 02 B3 C8 7F 44 81 00 00 DE 08 00 46 00 00 20 00 01 00 00 01 02 36 4C C0 A8 00 7B EA 00 43 67 94 04 00 00 16 00 BC 97 EA 00 43 67) At first I wrote that: dst = '234.0.67.103' # Open a raw socket. s = socket.socket(socket.AF_INET, socket.SOCK_RAW,2) res='' temp='01 00 5E 00 43 67 00 02 B3 C8 7F 44 81 00 00 DE 08 00 46 00 00 20 00 01 00 00 01 02 36 4C C0 A8 00 7B EA 00 43 67 94 04 00 00 16 00 BC 97 EA 00 43 67' for i in temp.split(' '): res+=chr(int(i, 16)) print res s.sendto(res, (dst, 0)) But for some reason python send that: 0x0000 01 00 5E 00 43 67 00 02-B3 C8 7F 44 08 00 45 00 ..^.Cg..??D..E. 0x0010 00 46 07 06 00 00 01 02-C4 25 C0 A8 00 7B EA 00 .F......? %??.{?. 0x0020 43 67 01 00 5E 00 43 67-00 02 B3 C8 7F 44 81 00 Cg..^.Cg..??D?. 0x0030 00 DE 08 00 46 00 00 20-00 01 00 00 01 02 36 4C .?..F.. ......6L 0x0040 C0 A8 00 7B EA 00 43 67-94 04 00 00 16 00 BC 97 ??. {?.Cg?.....?? 0x0050 EA 00 43 67 ?.Cg As you can see, python ignores my headers and creates its own. I discussed that problem on stackoverflow.com and one user told me to try that: import socket s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, 0x8100) s.bind(('eth0', 0x8100)) res='' temp='01 00 5E 00 43 67 00 02 B3 C8 7F 44 81 00 00 DE 08 00 46 00 00 20 00 01 00 00 01 02 36 4C C0 A8 00 7B EA 00 43 67 94 04 00 00 16 00 BC 97 EA 00 43 67' for i in temp.split(' '): res+=chr(int(i, 16)) s.send(res) But under Windows, AF_PACKET is said to be undefined. =( I tried to replace it with AF_INET, but now python tells me that that protocol (0x8100) is not supported. 0x8100 is IEEE 802.1Q and I just don't understand, why it isn't supported. I can generate packet with VLAN tag inside and send it with the help of pierf, for example. In fact, I can generate and send the packet from my example with pierf and it runs just fine. =) I've found a topic with the same problem (http:// www.computing.net/answers/programming/python-windows-sockets/11884.html) So, is there any way to somehow send a packet with ready headers and data under Windows with the help of python? From __peter__ at web.de Thu Dec 2 06:17:53 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 02 Dec 2010 12:17:53 +0100 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename References: <1291124813.414884.22.camel@WOPR> Message-ID: Nobody wrote: > This was actually a critical flaw in Python 3.0, as it meant that > filenames which weren't valid in the locale's encoding simply couldn't be > passed via argv or environ. 3.1 fixed this using the "surrogateescape" > encoding, so now it's only an annoyance (i.e. you can recover the original > bytes once you've spent enough time digging through the documentation). Is it just that you need to harden your scripts against these byte sequences or do you actually encounter them? If the latter, can you give some examples? From ben+python at benfinney.id.au Thu Dec 2 06:19:25 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 02 Dec 2010 22:19:25 +1100 Subject: Comparison with False - something I don't understand References: Message-ID: <877hfs2zia.fsf@benfinney.id.au> Harishankar writes: > When I run pychecker through my modules I get the message that > comparisons with "False" is not necessary and that it might yield > unexpected results. Good advice. > Yet in some situations I need to specifically check whether False was > returned or None was returned. Why is comparison with False so bad? Because it's almost always unnecessary and can yield unexpected results :-) In other words, the only purpose of the ?bool? type is to have values explicitly designed for testing in Boolean conditions. Comparing them to the literals is a code smell ? indicating a poor design. > # example code which matches both False and None > if not var: > # do something Can you give a specific real-world example of why this is not good enough? It's likely we can suggest better ways of achieving the broader purpose. > So how do you get around this? My functions return False and None > under different circumstances. Usually it is None that will be the special case, so it's usually better to write something like:: result = foo() if result is None: # do special things But that's just one possibility, and might not apply in your use case. > Should I raise exceptions instead? I feel it's unnecessary clutter to > use exceptions unless absolutely no other solution is available and > yet I have doubts about the "False" value. More details of the problem you're trying to solve would help with giving specific advice. -- \ ?I was sad because I had no shoes, until I met a man who had no | `\ feet. So I said, ?Got any shoes you're not using??? ?Steven | _o__) Wright | Ben Finney From prog at vtr.net Thu Dec 2 07:54:50 2010 From: prog at vtr.net (craf) Date: Thu, 02 Dec 2010 09:54:50 -0300 Subject: [Fwd: Re: Decorate un Frame with window managers title bar, etc en Tkinter 8.5] Message-ID: <1291294490.2473.0.camel@cristian-desktop> --------- Mensaje reenviado -------- > De: Eric Brunel > Para: python-list at python.org > Asunto: Re: Decorate un Frame with window managers title bar, etc en > Tkinter 8.5 > Fecha: Thu, 02 Dec 2010 10:21:49 +0100 > Grupos de noticias: comp.lang.python > > In article , > craf wrote: > > > Hi. > > > > I use python 3.1 and Tkinter 8.5 in Ubuntu 9.10 > > > > I would like to turn a frame into a toolbox, > > ,and for that I read that you can use the command wm manage (window) > > > > The information can be found at: > > http://www.tcl.tk/man/tcl8.5/TkCmd/wm.htm#M39 > > > > the explanation says: > > > > wm manage widget: > > The widget specified will become a stand alone top-level window. > > The window will be decorated with the window managers title bar, > > etc. Only frame, labelframe and toplevel widgets can be used > > with this command. Attempting to pass any other widget type will > > raise an error. Attempting to manage a toplevel widget is benign > > and achieves nothing. See also GEOMETRY MANAGEMENT. > > > > I have tried to use it in Tkinter but I can not know how is its > > structure. > > > > In Tkinter should be: > > > > ---TEST CODE------------------- > > > > from Tkinter import > > > > master = Tk() > > frame = Frame(master) > > wm_manager(Frame) > > master.mainloop() > > > > -------------------------------- > > > > But this does not work. > > If your version of Tkinter supports it, then the correct syntax is: > frame.wm_manage() > Please note you have to call it on the Frame instance (the one you named > frame), and not on Frame with a big F which is the class. > > If it says the method doesn't exist (AttributeError raised on the line > frame.wm_manage()), you can also try to do it at tcl/tk level with the > line: > master.tk.call('wm', 'manage', frame) > > > I appreciate any of this item > > HTH > - Eric - Thank you very much Eric! Regards. Cristian. From v.harishankar at gmail.com Thu Dec 2 09:13:05 2010 From: v.harishankar at gmail.com (Harishankar) Date: Thu, 2 Dec 2010 14:13:05 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> Message-ID: On Thu, 02 Dec 2010 22:19:25 +1100, Ben Finney wrote: > More details of the problem you're trying to solve would help with > giving specific advice. I'm writing functions with multiple points of failure exits. I use return False as a way to flag the error condition rather than raising exceptions. But under certain circumstances, the function can also return empty lists which equate to false when using the condition like: # myfunction () can return a list of tuples, but can also return an empty # list under certain conditions since it's query a database and the result # can be empty also result = myfunction (vars) if not result: # error condition Now above I first realized that the function can also return an empty list under some conditions and so changed it to if result == False: # error condition But now I realize that it's better to use "is" if result is False: # error condition That is how my problem arose. - Harishankar (http://harishankar.org http://lawstudentscommunity.com) From v.harishankar at gmail.com Thu Dec 2 09:18:25 2010 From: v.harishankar at gmail.com (Harishankar) Date: Thu, 2 Dec 2010 14:18:25 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> Message-ID: On Thu, 02 Dec 2010 02:49:50 -0800, Stephen Hansen wrote: >... >... >... > * P.S. I'm not saying its never right to use "is" outside of The > Singletons. Just that its probably not, for most people, what they > actually should do in most code. There are numerous counter-examples, of > course. Its just a general guideline to follow. Until a need arises that > demonstrates otherwise. Here I'm using it to compare the result of a function where I specifically return False on error condition, so I think it's better I check it against the literal False rather than the fuzzy False produced by the boolean operation. I wouldn't do this in most situations though, but I did need to distinguish between the the empty list and False and using the broader form as in "if not a" did not work as expected. -- Harishankar (http://harishankar.org http://lawstudentscommunity.com) From khamenya at gmail.com Thu Dec 2 09:43:27 2010 From: khamenya at gmail.com (Valery) Date: Thu, 2 Dec 2010 06:43:27 -0800 (PST) Subject: How to initialize each multithreading Pool worker with an individual value? References: Message-ID: On Dec 1, 3:24?am, James Mills wrote: > I assume you are talking about multiprocessing > despite you mentioning "multithreading" in the mix. yes, sorry. > Have a look at the source code for multiprocessing.pool > and how the Pool object works and what it does > with the initializer argument. I'm not entirely sure it > does what you expect and yes documentation on this > is lacking... I see I found my way "to seed" each member of Pool with own data. I do it right after after initialization: port = None def port_seeder(port_val) from time import sleep sleep(1) # or less... global port port = port_val if __name__ == '__main__': pool = Pool(3) pool.map(port_seeder, range(3), chunksize=1) # now child processes are initialized with individual values. Another (a bit more heavier) approach would be via shared resource. P.S. sorry, I found your answer only now. reagrds -- Valery From python.list at tim.thechases.com Thu Dec 2 09:44:11 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 02 Dec 2010 08:44:11 -0600 Subject: Comparison with False - something I don't understand In-Reply-To: References: <4CF779CE.3040209@ixokai.io> Message-ID: <4CF7B0BB.7080008@tim.thechases.com> On 12/02/2010 08:18 AM, Harishankar wrote: > Here I'm using it to compare the result of a function where I > specifically return False on error condition, This sounds exactly like the reason to use exceptions...you have an exceptional error condition. -tkc From jlconlin at gmail.com Thu Dec 2 09:45:46 2010 From: jlconlin at gmail.com (Jeremy) Date: Thu, 2 Dec 2010 06:45:46 -0800 (PST) Subject: How can I define class methods outside of the class? References: Message-ID: <5007196a-0366-41ed-ae8d-8a1633a22dff@r31g2000prg.googlegroups.com> On Dec 1, 10:47?pm, James Mills wrote: > On Thu, Dec 2, 2010 at 3:36 PM, Jeremy wrote: > > I have some methods that I need (would like) to define outside of the > > class. ?I know this can be done by defining the function and then > > setting it equal to some member of an instance of the class. ?But, > > because of the complexity of what I'm doing (I have to set many > > functions as class methods) I would rather not do this. ?Can someone > > show me how to do this? ?Is it even possible? ?Can decorators be used > > here? > > Do you mean something like this ? > > @classmethod > def foo(cls): > ? ? print "I am the foo classmethod on %r" % cls > > class Foo(object): > ? ? pass > > Foo.foo = foo > > cheers > James Thanks, James. That is almost exactly what I want. However, I want to avoid doing Foo.foo = foo Is this going to be possible? I'm trying to understand how decorators are used. Are they really necessary in this example? Thanks, Jeremy From milan.petrasek at gmail.com Thu Dec 2 09:51:24 2010 From: milan.petrasek at gmail.com (Milan Petrasek) Date: Thu, 2 Dec 2010 15:51:24 +0100 Subject: m2crypto, base64, quoted-printable, xml Message-ID: Hi, I have encrypted signed smime message with xml file. Messages are constructed: 1) xml file is embedded to MIME message as attacment (Content-Disposition: attachment;). 2) over whole content MIME message is signed by PKCS#7 and encoded Base64. 3) This message is encrypted by public key. I use M2crypto to decrypt: from M2Crypto import BIO, SMIME, X509 import os output = open("c://decrypted.txt", 'w') s = SMIME.SMIME() s.load_key('test.pem', 'test.pem') p7, data = SMIME.smime_load_pkcs7('input.txt') out = s.decrypt(p7) output.write(out) output.close() this part works properly. I try to verify the signed data, but without success. File decrypted.txt contains base64 encoded data. ( I tried to decode through from M2Crypto import BIO, SMIME, X509 import base64 import os input = open("C://decrypted.txt", 'r') output= open("C://decoded.txt", 'w') base64.decode(input,output) output.close input.close Decoded.txt contains quoted printable data, but if I try decode these data: import os import quopri input = open("c://decoded.txt", 'r') output= open("c://output.xml", 'w') quopri.decode(input, output) output.close input.close I obtain invalid and incomplete data. Data contains for example "s ? ?plitting" instead of "splitting". Do you have any idea, what do I do wrong? Thanks you very much Best regards Milan -------------- next part -------------- 0? *?H?? ??0?1 0 +0? *?H?? ??$???Content-Type: application/octet-stream; name=60000000809820.XML Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename=60000000809820.XML <= Trade acceptance=3D"N" id=3D"84953" market=3D"VDT" trade-day=3D"2010-11-20"= trade-order=3D"1" trade-type=3D"P" version=3D"0"><= ProfileData profile-role=3D"P72"><= /ProfileData>= = 8YHs/sxfgB3k0UzVK008AA4GHO4=3D zf+U2XLnE14YWQdeJ0apGPQBVviiQ1JJqCKZGFWcQ1ljwgG61f9JnALZsBYZP+6G2p9aAsyto2+= D at78MnNiuENXwzBnKdCMUU9wOYsnVdKXnfCCUQzJeP7yQgaev4QL8fSXpaziI52AH1caXPM4e7V= 3 bcpQKXBwUrZq+hhJfyFSLm/R31APWqlujPk9gwSSiDWZ6aFLFob4jKj1FWQBTQzi0fnC/N50dA7= 7 C4V/X5XsbqlRxA4G83GneryrOEa0l1UXggFGlFQ5xNFwAMFOHnAz55HXQ9llRnm4safqvl4HNAX= x mZIqoiF7caWYe2WfGsQ+Soy3MCwltlemK4/FHQ=3D=3D MIIDyTCCArGgAwIBAgIKL7h+8AAFAAAV8DANBgkqhkiG9w0BAQUFADBCMQswCQYDVQQGEwJDWjE= P MA0GA1??UEChMGTG9naWNhMRIwEAYDVQQLEwlQS0kgR3JvdXAxDjAMBgNVBAMTBU9URUNBMB4XDTE= w MDIxNjEzNDM0MloXDTEyMDIxNjEzNTM0MlowZTEkMCIGCSqGSIb3DQEJARYVY3NvdGVAY3NvdGU= u b3RlLWNyLmN6MQswCQYDVQQGEwJDWjESMBAGA1UEChMJT1RFLCBhLnMuMQwwCgYDVQQLEwNQS0k= x DjAMBgNVBAMTBUNTT1RFMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA9mo6AupquHb= e Q26caDIOgOIchGVpv7DV0QjqqixFNPSkg+POqDSB8txUKjcRmV0HKWT1o46SzpIVaUod1eaESTR= o KiEp10v7EFC+InYBRk7HzHoBau1kyYaGHrECdeOddFN1LhFsZXcdWQLGE5AWW9A5hmyksQK8aoJ= o ZNWXYzBSrNIHRQpQi7x3rEg80o/UhezBbU1KZXhg0LSCzayzixjzw++TR6l3YwdkO2wHUpBzKwd= U 46rWPMdN3NcWbocrVDUWkyLnNHWlO6olKVWV+751ZjszjjgNI+E+Wc2kxRUqKJRR9Ren5PYLvPP= v +oCnZaxvkKQDd30fyPSnyvVoxQIDAQABo4GdMIGaMB0GA1UdDgQWBBThBbCUiVlEPsXoCMOg7cd= f /wOyAjB5BgNVHSMEcjBwgBT08Vf3iDofXlR27DvrxE+H5diP0aFGpEQwQjELMAkGA1UEBhMCQ1o= x DzANBgNVBAoTBkxvZ2ljYTESMBAGA1UECxMJUEtJIEdyb3VwMQ4wDAYDVQQDEwVPVEVDQYIQeYN= C Xj6Lf6NNexTEztftfDANBgkqhkiG9w0BAQUFAAOCAQEAgq5DSjn0uZsjIBpaff+Y/gGgXAhpD7L= b IbPEJTIxc6vb4uSSssht5SapXKfyek2bG0?uYuDkv3Cubv1Gf77qrOcyNsmMzbpXpYMCRiJ2oZ9FZ= 4 +NuQK68jK5MAT8GH3GiJ/ikphTTknSpLm/9JRjnjX9pbGbKpIFPYiRBzdQI28Y7wqOuzvRPcknI= X LGWh+QYymRTGHQDaJts5mOzgsl2WbvdFMgt3wocAp35HyK9QHH9NrnT0+x+VxvW8sTJ5zQYQyhq= 5 mXmQwgKSAJUnM3y2NHEjOiYwNf2iwoAwHgM8/GNymaLLHbgeaK7GoTqiBsmuUKcFSGC9lRJhGZq= L EufT1A=3D=3D 9mo6AupquHbeQ26caDIOgOIchGVpv7DV0QjqqixFNPSkg+POqDSB8txUKjcRmV0HKWT1o46SzpI= V aUod1eaESTRoKiEp10v7EFC+InYBRk7HzHoBau1kyYaGHrECdeOddFN1LhFsZXcdWQLGE5AWW9A= 5 hmyksQK8aoJoZNWXYzBSrNIHRQpQi7x3rEg80o/UhezBbU1KZXhg0LSCzayzixjzw++TR6l3Ywd= k O2wHUpBzKwdU46rWPMdN3NcWbocrVDUWkyLnNHWlO6olKVWV+751ZjszjjgNI+E+Wc2kxRUqKJR= R 9Ren5PYLvPPv+oCnZaxvkKQDd30fyPSnyvVoxQ=3D=3D AQAB ??0??0??? /?~??0  *?H?? 0B1 0 UCZ10 U Logica10U  PKI Group10 UOTECA0  100216134342Z 120216135342Z0e1$0" *?H??  csote at csote.ote-cr.cz1 0 UCZ10U  OTE, a.s.1 0 U PKI10 UCSOTE0?"0  *?H?? ?0? ??j:?j?v?Cn?h2?? ?ei??????,E4??????4???T*7?])d??????iJ ???I4h*!)?K?P?"vFN??zj?d??? ?u??tSu.lew Y??[?9?l???j?hd??c0R??E P??w?HY???*(?Q???? ??????e?o??w}?????h????0??0 U ????YD>??????_??0yU #r0p???W??:^Tv?;??O??????F?D0B1 0 UCZ10 U Logica10U  PKI Group10 UOTECA?y?B^>??M{????|0  *?H?? ???CJ9???# Z}????\i??!??%21s???????m?&?\??zM?F.K? ???g????s#l????zX0$b'j?Vx???+?#+?O???h??))?4??*K??IF9?_?[?? S??su6?????????r,e??2?? ?&?9????]?n?E2 w???~G??P M?t???????2y????y????'3|?4q#:&05????0  <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> Message-ID: On Thu, 02 Dec 2010 08:44:11 -0600, Tim Chase wrote: > On 12/02/2010 08:18 AM, Harishankar wrote: >> Here I'm using it to compare the result of a function where I >> specifically return False on error condition, > > This sounds exactly like the reason to use exceptions...you have an > exceptional error condition. > > -tkc There are some reasons why I hate exceptions but that is a different topic. However, in short I can say that personally: 1. I hate try blocks which add complexity to the code when none is needed. Try blocks make code much more unreadable in my view and I use it only for the built-in exceptions when absolutely needed. 2. I prefer the less irksome True or False to do error checking. Exceptions seem too heavyweight for simple problems. 3. Philosophically I think exception handling is the wrong approach to error management. I have never grown up programming with exceptions in C and I couldn't pick up the habit with python either. Did I mention that I detest try blocks? try blocks seem ugly and destroy code clarity at least in my view. And enclosing single statements under separate try blocks seem to add a lot of clutter. -- Harishankar (http://harishankar.org http://lawstudentscommunity.com) From steve at holdenweb.com Thu Dec 2 10:19:35 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 02 Dec 2010 10:19:35 -0500 Subject: Comparison with False - something I don't understand In-Reply-To: References: <877hfs2zia.fsf@benfinney.id.au> Message-ID: On 12/2/2010 9:13 AM, Harishankar wrote: > On Thu, 02 Dec 2010 22:19:25 +1100, Ben Finney wrote: > >> More details of the problem you're trying to solve would help with >> giving specific advice. > > I'm writing functions with multiple points of failure exits. I use return > False as a way to flag the error condition rather than raising > exceptions. But under certain circumstances, the function can also return > empty lists which equate to false when using the condition like: > > # myfunction () can return a list of tuples, but can also return an empty > # list under certain conditions since it's query a database and the result > # can be empty also > > result = myfunction (vars) > > if not result: > # error condition > > Now above I first realized that the function can also return an empty > list under some conditions and so changed it to > > if result == False: > # error condition > > > But now I realize that it's better to use "is" > > if result is False: > # error condition > > That is how my problem arose. > Did you think about using exceptions to handle exceptional conditions? If you are new to Python it may not be the obvious soltuion, but it can greatly simplify program logic. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Thu Dec 2 10:21:53 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 02 Dec 2010 10:21:53 -0500 Subject: Comparison with False - something I don't understand In-Reply-To: References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> Message-ID: On 12/2/2010 9:56 AM, Harishankar wrote: > 3. Philosophically I think exception handling is the wrong approach to > error management. I have never grown up programming with exceptions in C > and I couldn't pick up the habit with python either. Did I mention that I > detest try blocks? try blocks seem ugly and destroy code clarity at least > in my view. And enclosing single statements under separate try blocks > seem to add a lot of clutter. Whereas lots of nested if statements to test that multiple errors have all not occurred is a model of clarity? This sounds to me like a prejudice that will harm your Python development. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From usernet at ilthio.net Thu Dec 2 10:25:55 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 2 Dec 2010 15:25:55 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> Message-ID: On 2010-12-02, Harishankar wrote: > There are some reasons why I hate exceptions but that is a different > topic. However, in short I can say that personally: > > 1. I hate try blocks which add complexity to the code when none is > needed. Try blocks make code much more unreadable in my view and I use it > only for the built-in exceptions when absolutely needed. Actually, exceptions remove a ton of complexity and almost universally remove a ton of redundant error checking code. Second, they aleviate a ton of design complexity about designing a clean and unified method of error handling throughout the program. Using exceptions, the only real questions are where to handle various errors. It is a godsend for having to clean up intermediary results when an error occurs as part of a complex set of dependant sequential operations. > 2. I prefer the less irksome True or False to do error checking. > Exceptions seem too heavyweight for simple problems. Error handling in C huge source of bugs. First, error handling code is scattered throughout the codebase and second it is hard to test the error handling code for a number of failures. Being able to raise exceptions within your test code makes it much easier to write tests capable of detecting error handling bugs. > 3. Philosophically I think exception handling is the wrong approach to > error management. I have never grown up programming with exceptions in C > and I couldn't pick up the habit with python either. Did I mention that I > detest try blocks? try blocks seem ugly and destroy code clarity at least > in my view. And enclosing single statements under separate try blocks > seem to add a lot of clutter. Perhaps you should take a look at how Erlang appoaches exception handling. Being message passing and concurrency oriented, Erlang encourages ignoring error conditions within worker processes. Errors instead cause the worker processes to be killed and a supervisory process is notified, by message, so that it can handle the error and respawn the worker process. Since it doesn't use try/exept blocks, maybe that will be more to your liking. From invalid at invalid.invalid Thu Dec 2 10:31:47 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 2 Dec 2010 15:31:47 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> Message-ID: On 2010-12-02, Steve Holden wrote: > On 12/2/2010 9:13 AM, Harishankar wrote: >> >> if not result: >> # error condition >> >> Now above I first realized that the function can also return an empty >> list under some conditions and so changed it to >> >> if result == False: >> # error condition >> >> >> But now I realize that it's better to use "is" >> >> if result is False: >> # error condition >> >> That is how my problem arose. > > Did you think about using exceptions to handle exceptional conditions? > If you are new to Python it may not be the obvious soltuion, but it can > greatly simplify program logic. If you're not used to using exceptions it may at first seem like they take extra effort to use. But usually, in the end, they end up being less work (and more importantly easier to read and less bugs). -- Grant Edwards grant.b.edwards Yow! He is the MELBA-BEING at ... the ANGEL CAKE gmail.com ... XEROX him ... XEROX him -- From v.harishankar at gmail.com Thu Dec 2 10:34:31 2010 From: v.harishankar at gmail.com (Harishankar) Date: Thu, 2 Dec 2010 15:34:31 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> Message-ID: On Thu, 02 Dec 2010 10:19:35 -0500, Steve Holden wrote: > On 12/2/2010 9:13 AM, Harishankar wrote: >> On Thu, 02 Dec 2010 22:19:25 +1100, Ben Finney wrote: >> >>> More details of the problem you're trying to solve would help with >>> giving specific advice. >> >> I'm writing functions with multiple points of failure exits. I use >> return False as a way to flag the error condition rather than raising >> exceptions. But under certain circumstances, the function can also >> return empty lists which equate to false when using the condition like: >> >> # myfunction () can return a list of tuples, but can also return an >> empty # list under certain conditions since it's query a database and >> the result # can be empty also >> >> result = myfunction (vars) >> >> if not result: >> # error condition >> >> Now above I first realized that the function can also return an empty >> list under some conditions and so changed it to >> >> if result == False: >> # error condition >> >> >> But now I realize that it's better to use "is" >> >> if result is False: >> # error condition >> >> That is how my problem arose. >> > Did you think about using exceptions to handle exceptional conditions? > If you are new to Python it may not be the obvious soltuion, but it can > greatly simplify program logic. > > regards > Steve I am not new to Python but I am not a fan of exceptions either. I prefer to avoid writing my own exceptions because it feels too heavy and clunky for simple error checking. Most times I find simple error checking ample for my purposes. Of course, I use the built-in exception objects when I have no choice, but I hate try blocks. They add clunkiness to code and besides exception objects seem to be fairly heavy-duty for simple error conditions where a true/false flag would probably suffice. I am also wary of using larger catch-all try blocks or try blocks with multiple exception exits (which seem to make tracking subtle bugs harder). I prefer the philosophy of dealing with errors immediately as they arise, rather than delegate them to exception mechanism. Of course, I could wrap single statements in try blocks, but that makes the code even messier without any significant benefits. -- Harishankar (http://harishankar.org http://lawstudentscommunity.com) From me+list/python at ixokai.io Thu Dec 2 10:35:18 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 02 Dec 2010 07:35:18 -0800 Subject: Comparison with False - something I don't understand In-Reply-To: References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> Message-ID: <4CF7BCB6.1080501@ixokai.io> On 12/2/10 6:56 AM, Harishankar wrote: > On Thu, 02 Dec 2010 08:44:11 -0600, Tim Chase wrote: > >> On 12/02/2010 08:18 AM, Harishankar wrote: >>> Here I'm using it to compare the result of a function where I >>> specifically return False on error condition, >> >> This sounds exactly like the reason to use exceptions...you have an >> exceptional error condition. >> >> -tkc > > There are some reasons why I hate exceptions but that is a different > topic. However, in short I can say that personally: To each his/her own, of course; but -- > 3. Philosophically I think exception handling is the wrong approach to > error management. Exceptions aren't about "error management"; they are about exceptional conditions: some are errors, others are entirely normal situations you know are going to happen (such as reaching the end of a sequence as you iterate over it: that's not an error, but it is special). To be philosophically opposed to them seems to me to be philosophically in favor of race conditions. > I have never grown up programming with exceptions in C > and I couldn't pick up the habit with python either. Did I mention that I > detest try blocks? try blocks seem ugly and destroy code clarity at least > in my view. And enclosing single statements under separate try blocks > seem to add a lot of clutter. ? How do they destroy clarity or add clutter, since presumably you have to deal with that "False" in some way with logical structure -- which always does whitespace in Python. If not immediately, then up the call stack (which seems to imply you should just not use a try/except and let the exception unwind the stack to wherever in your code someone wants to deal with it). if is_correct(): result = do_thing() else: do_error_handling() try: result = do_thing() except KeyError: do_error_handling() And as an aside, the more statements one puts into a try/except block: and the more complicated a statement at that-- the more likely it is they are going to mess up and do something Wrong. Now, all that said: sure, in some situations I do prefer the "check first" style of programming where exceptions don't end up being used. Its not *wrong* to return False on an "error condition": its going against the grain, though, and makes your code harder to deal with long-term if only because now there's two separate mechanisms that "errors" happen in it. You can't totally do away with exceptions in Python, even if you try very hard. So with that in mind, IMHO, the best approach is to just... get over it, and learn to appreciate them :) But, to each his or her own. :) -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From v.jagan201 at gmail.com Thu Dec 2 10:41:57 2010 From: v.jagan201 at gmail.com (kameni) Date: Thu, 2 Dec 2010 07:41:57 -0800 (PST) Subject: thousand of application for you Message-ID: <48acc4c3-6552-45fd-a49e-cef7a543f475@i32g2000pri.googlegroups.com> http://123maza.com/28/come123/ From v.harishankar at gmail.com Thu Dec 2 10:44:00 2010 From: v.harishankar at gmail.com (Harishankar) Date: Thu, 2 Dec 2010 15:44:00 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> Message-ID: On Thu, 02 Dec 2010 15:25:55 +0000, Tim Harig wrote: >... >... > > Perhaps you should take a look at how Erlang appoaches exception > handling. Being message passing and concurrency oriented, Erlang > encourages ignoring error conditions within worker processes. Errors > instead cause the worker processes to be killed and a supervisory > process is notified, by message, so that it can handle the error and > respawn the worker process. Since it doesn't use try/exept blocks, > maybe that will be more to your liking. Thanks for the reply. I understand that the error vs exception debate is quite a big one in the programming community as a whole and I don't consider myself very knowledgeable in these issues. However, I will try to approach this with an open mind and see whether I can work with exceptions comfortably in Python. I do understand both sides of the issue. Exceptions seem to be generally more reliable but I feel they add a lot of complexity particular when a lot of code is placed in a try block. -- Harishankar (http://harishankar.org http://lawstudentscommunity.com) From usernet at ilthio.net Thu Dec 2 10:53:49 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 2 Dec 2010 15:53:49 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> Message-ID: On 2010-12-02, Harishankar wrote: > I am also wary of using larger catch-all try blocks or try blocks with > multiple exception exits (which seem to make tracking subtle bugs > harder). I prefer the philosophy of dealing with errors immediately as If you are using exceptions to try to catch bug then you are using them improperly. Exceptions (with the exception (no pun intended) of AssertionError) are designed to catch error conditions, not bugs. > harder). I prefer the philosophy of dealing with errors immediately as > they arise, rather than delegate them to exception mechanism. Of course, > I could wrap single statements in try blocks, but that makes the code > even messier without any significant benefits. Actually, finer grained error handling commonly covers up bugs. If you want to find bugs, you want to make the program prone to crashing if a bug is present. It is all too easy to accidently mistake the return value of a function as error condition and handle it rather the letting the program crash. By separating the results from the transmission of error conditions (in effect taking error conditions out of band) then you make it much harder to make such a mistake because you have to explicity indicate which error conditions your code is capable of generating. From v.harishankar at gmail.com Thu Dec 2 10:58:39 2010 From: v.harishankar at gmail.com (Harishankar) Date: Thu, 2 Dec 2010 15:58:39 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <4CF7BCB6.1080501@ixokai.io> Message-ID: On Thu, 02 Dec 2010 07:35:18 -0800, Stephen Hansen wrote: > Exceptions aren't about "error management"; they are about exceptional > conditions: some are errors, others are entirely normal situations you > know are going to happen (such as reaching the end of a sequence as you > iterate over it: that's not an error, but it is special). To be > philosophically opposed to them seems to me to be philosophically in > favor of race conditions. Maybe I worded that part wrongly. Of course I get that error handling is only a part of exception mechanism. I agree that the built-in exceptions are useful but I prefer most times not to catch them. :-) > ? How do they destroy clarity or add clutter, since presumably you have > to deal with that "False" in some way with logical structure -- which > always does whitespace in Python. If not immediately, then up the call > stack (which seems to imply you should just not use a try/except and let > the exception unwind the stack to wherever in your code someone wants to > deal with it). The reason why I said they remove clarity is because it's not always obvious at which point the exception may be raised. In other words, within a try block there may be multiple statements that generate the exception. Of course, as I said before, one way would be to wrap single statements with the try block and avoid this issue. > > if is_correct(): > result = do_thing() > else: > do_error_handling() > > try: > result = do_thing() > except KeyError: > do_error_handling() Of course, to me the if statement would make more sense because I immediately figure out the exact condition being tested against while the exception object is not always so clear and maybe ambiguous in some cases. Also if that same type of exception is raised by another statement within a function that is called within the try block then it would be handled by the same except block right? This is where it gets a bit confusing to me and the flow of code is not always obvious. That's why I prefer atomic error handling where I know exactly which part of the code led to the result. > And as an aside, the more statements one puts into a try/except block: > and the more complicated a statement at that-- the more likely it is > they are going to mess up and do something Wrong. > > Now, all that said: sure, in some situations I do prefer the "check > first" style of programming where exceptions don't end up being used. > Its not *wrong* to return False on an "error condition": its going > against the grain, though, and makes your code harder to deal with > long-term if only because now there's two separate mechanisms that > "errors" happen in it. I realize that it is impossible for me to avoid exception mechanism myself. So I restrict it only to situations where I cannot avoid it (e.g. inbuilt exceptions in some cases where I want to handle it myself) > > You can't totally do away with exceptions in Python, even if you try > very hard. So with that in mind, IMHO, the best approach is to just... > get over it, and learn to appreciate them :) Finding it hard to appreciate exceptions myself. But I am used to thinking linearly. A piece of code which does not explain itself in the most obvious way even if I wrote it always worries me. -- Harishankar (http://harishankar.org http://lawstudentscommunity.com) From piet at vanoostrum.org Thu Dec 2 11:09:25 2010 From: piet at vanoostrum.org (Piet van Oostrum) Date: Thu, 02 Dec 2010 12:09:25 -0400 Subject: strange TypeError exception in function compiled from a string References: Message-ID: nelson writes: > Hi all, > I have this function, defined in a string and ecetuted through ad > exec call > > def cell1(d): > > x=d.get('x') > print x > > import y > return y.add(y.add(self.adf0(x),self.adf0(x)),self.adf0(x)) > What is self in line 7? -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] Nu Fair Trade woonartikelen op http://www.zylja.com From usernet at ilthio.net Thu Dec 2 11:12:39 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 2 Dec 2010 16:12:39 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> Message-ID: On 2010-12-02, Harishankar wrote: > I understand that the error vs exception debate is quite a big one in the > programming community as a whole and I don't consider myself very Actually, I thought that debate was resolved years ago. I cannot think of a single recently developed programming language that does not provide exception handling mechanisms because they have been proven more reliable. > Python. I do understand both sides of the issue. Exceptions seem to be > generally more reliable but I feel they add a lot of complexity > particular when a lot of code is placed in a try block. Lines of code is one measure of complexity. Each line of code has a small chance of containing a bug. The more lines of code that you have, then the more likely that one of them contains a bug. Exceptions, by placing error handling code in fewer places, requires much fewer lines of code then requiring error handling code after each call that might produce an error condition. The operations of propogating an error up to the higher level logic of the program is another measure. In languages without exception handling, careful planning is needed to pass error conditions up through the call stack until they reach a high enough level in the logic that decisions can be made about how to handle them. Even further planning must be taken so that when the error condition reaches level where it needs to be handled, that enough information about the error is present to know exactly what went wrong so that it can figure out what to do about it. This usually involves using globals like errorno to pass out of band information about the error. Sometimes you even need to know about how the error affect intermediate levels, did the intermediate code attempt to handle the condtion and fail? The Openssl error handling system, that creates an error logging chain is an example of just how complex this can become. You gain all of this functionality automatically through exception mechanisms; without all of the complexity. From v.harishankar at gmail.com Thu Dec 2 11:15:30 2010 From: v.harishankar at gmail.com (Harishankar) Date: Thu, 2 Dec 2010 16:15:30 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> Message-ID: On Thu, 02 Dec 2010 15:53:49 +0000, Tim Harig wrote: > If you are using exceptions to try to catch bug then you are using them > improperly. Exceptions (with the exception (no pun intended) of > AssertionError) are designed to catch error conditions, not bugs. I agree. But more specifically some exceptions seem too broad to catch specific errors that occur in MY code rather than in a system call or a library call. Also writing my own exception objects and raising exceptions seem to add too much of complexity to what is essentially a simple problem. This is what I was trying to explain. > Actually, finer grained error handling commonly covers up bugs. If you > want to find bugs, you want to make the program prone to crashing if a > bug is present. It is all too easy to accidently mistake the return > value of a function as error condition and handle it rather the letting > the program crash. By separating the results from the transmission of > error conditions (in effect taking error conditions out of band) then > you make it much harder to make such a mistake because you have to > explicity indicate which error conditions your code is capable of > generating. Doesn't the same finer grained exception mechanism make it prone to the same problems? Actually return values of functions which I write myself can be as specific and to the point. I could make it as fuzzy or as precise as I like. This is no doubt, something that I could emulate with an exception as well, but only make it slightly more complex with no obvious benefit. As I said before, the way exceptions are caught seem to me to be the most confusing bit. Non-atomic operations always worry me. What if my function which is wrapped inside a try block has two different statements that raised the same exception but for different reasons? With error handling I could probably handle it right below the statement which was called and thus reduce the problem??? -- Harishankar (http://harishankar.org http://lawstudentscommunity.com) From piet at vanoostrum.org Thu Dec 2 11:17:18 2010 From: piet at vanoostrum.org (Piet van Oostrum) Date: Thu, 02 Dec 2010 12:17:18 -0400 Subject: string find/replace References: <4cf687aa$0$5000$e4fe514c@dreader19.news.xs4all.nl> <4cf68ce8$0$12821$e4fe514c@dreader19.news.xs4all.nl> Message-ID: Carlo writes: > On 2010-12-01, Peter Otten <__peter__ at web.de> wrote: >>>>> import re >>>>> re.compile("([a-z])([A-Z])").sub(r"\1 \2", "camelCase") >> 'camel Case' > > Very simple if you know it. Thank you! And almost as cryptic as Perl!! -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] Nu Fair Trade woonartikelen op http://www.zylja.com From kirby.urner at gmail.com Thu Dec 2 11:30:24 2010 From: kirby.urner at gmail.com (kirby.urner at gmail.com) Date: Thu, 2 Dec 2010 08:30:24 -0800 (PST) Subject: DBF (VFP) to XLS (Excel) in pure Python References: <084f9299-b2b3-440f-b83f-9fbe42220221@j19g2000prh.googlegroups.com> <5ddf7758-754f-4649-be1e-85cdee7860e5@y23g2000yqd.googlegroups.com> Message-ID: On Dec 1, 10:28?pm, "kirby.ur... at gmail.com" wrote: > Playing around with arcane tools to read those pesky DBF files (with > memo fields), like floating wine barrels cast off the sinking VFP > ship. > Although it's true I don't know that I'm getting "in memory" DBF reads, the bulk of the time in the code I just shared is in the "writing to XLS" inner loop. Looking to a different solution for writing, perhaps a DLL available for $ (one time). Been reading more about VFP, Silverlight and HTML5. Python seems in a good position. All caught up on IronPython now too. Kirby From mdw at distorted.org.uk Thu Dec 2 11:35:08 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 02 Dec 2010 16:35:08 +0000 Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> Message-ID: <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> Harishankar writes: > There are some reasons why I hate exceptions but that is a different > topic. However, in short I can say that personally: > > 1. I hate try blocks which add complexity to the code when none is > needed. Try blocks make code much more unreadable in my view and I use it > only for the built-in exceptions when absolutely needed. Very little code actually needs `try' blocks. > 2. I prefer the less irksome True or False to do error checking. > Exceptions seem too heavyweight for simple problems. Just write simple programs as if errors never happen; if an exception is raised, the program prints a vaguely useful message and exits. Besides, this complaint is incoherent. One needs at least as much structure to check an error code as to catch an exception. > 3. Philosophically I think exception handling is the wrong approach to > error management. There are better ways to handle errors than Python's exception system. Passing error codes around manually is most definitely not one of them. (One of the main reasons I ditched Perl in favour of Python is the former's insistence on returning error codes for I/O and system calls.) -- [mdw] From eric.frederich at gmail.com Thu Dec 2 11:39:23 2010 From: eric.frederich at gmail.com (Eric Frederich) Date: Thu, 2 Dec 2010 11:39:23 -0500 Subject: multiple modules from single c extension In-Reply-To: References: Message-ID: Can you explain how to do this with distutils then? Would I need a separate setup.py for SpamABC and SpamXYZ? How would I get them included in the parent module Spam? Could you explain what you mean when you say "The Python import mechanism will be looking for an appropriately-named .pyd file for each module"? Are you saying that in python when I say from "Spam.ABC import *" I need a file called "Spam.ABC.[so|pyd]"? On Wed, Dec 1, 2010 at 8:39 PM, Robert Kern wrote: > On 12/1/10 4:12 PM, Eric Frederich wrote: >> >> I have an extension to some C library that I created using the guide >> found here... >> >> ? ? http://docs.python.org/extending/extending.html >> >> I am starting to have A LOT of functions being wrapped. >> >> The library that I'm creating bindings for is organized into modules. >> In fact, all of their function calls start with a prefix like >> ABC_do_something, XYZ_something_else. >> >> I'd like to start putting the bindings for each module into a separate >> C file and have each set of bindings end up in its own Python module >> as well. >> >> Is this possible to do using a single .dll / .pyd file so that I can >> use a single Visual Studio project for these bindings? > > No, I don't think so. The Python import mechanism will be looking for an > appropriately-named .pyd file for each module. In any case, you shouldn't be > using Visual Studio directly to build the .pyd. Instead, use distutils. > > -- > 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 > > -- > http://mail.python.org/mailman/listinfo/python-list > From dickinsm at gmail.com Thu Dec 2 11:39:41 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Thu, 2 Dec 2010 08:39:41 -0800 (PST) Subject: Some syntactic sugar proposals References: Message-ID: <215bc600-d3aa-4c39-adfd-d46ea2843ee7@i32g2000pri.googlegroups.com> On Nov 15, 12:46?pm, Tim Chase wrote: > On 11/15/2010 12:39 AM, Dmitry Groshev wrote: > > > x in range optimisation > > I've often thought this would make a nice O(1)-test lookup on an > xrange() generator. An O(1) test for 'x in ' is implemented in Python 3.2, at least provided that x has type 'int', 'long' or 'bool'. (If x is an instance of a subclass of int or long, then there's a risk that the semantics of the membership test have been changed by an explicitly overridden __eq__, so Python wimps out and falls back to the O(n) algorithm in that case.) Python 3.2a4+ (py3k:86635:86636M, Nov 21 2010, 19:22:18) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> -1 in range(10**9) False >>> 5 in range(0, 10**100, 2) False >>> 10**99 in range(0, 10**100, 2) True IIRC, there wasn't sufficient interest to get it backported to Python 2.7 in time for its release. Though as a pure optimization, one could argue that it would still be possible to get this into Python 2.7.2. Mark From robert.kern at gmail.com Thu Dec 2 11:49:25 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 02 Dec 2010 10:49:25 -0600 Subject: multiple modules from single c extension In-Reply-To: References: Message-ID: On 12/2/10 10:39 AM, Eric Frederich wrote: > Can you explain how to do this with distutils then? > Would I need a separate setup.py for SpamABC and SpamXYZ? > How would I get them included in the parent module Spam? Please consult the distutils documentation. http://docs.python.org/distutils/index.html In short, you only need one setup.py file. from distutils.core import setup, Extension setup( ... ext_modules=[ Extension('Spam.ABC', sources=['src/spam_abc.c']), Extension('Spam.XYZ', sources=['src/spam_xyz.c']), ], packages=['Spam'], ... ) > Could you explain what you mean when you say "The Python import > mechanism will be looking for an appropriately-named .pyd file for > each module"? > > Are you saying that in python when I say from "Spam.ABC import *" I > need a file called "Spam.ABC.[so|pyd]"? No, it will be looking for Spam/ABC.pyd where Spam/ is your package directory (i.e. it should have an __init__.py file, like any other Python package). -- 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 usernet at ilthio.net Thu Dec 2 11:52:57 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 2 Dec 2010 16:52:57 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> Message-ID: On 2010-12-02, Harishankar wrote: >> Actually, finer grained error handling commonly covers up bugs. If you >> want to find bugs, you want to make the program prone to crashing if a >> bug is present. It is all too easy to accidently mistake the return >> value of a function as error condition and handle it rather the letting >> the program crash. By separating the results from the transmission of >> error conditions (in effect taking error conditions out of band) then >> you make it much harder to make such a mistake because you have to >> explicity indicate which error conditions your code is capable of >> generating. > > Doesn't the same finer grained exception mechanism make it prone to the > same problems? Exception handling is a move away from fine grained handling. If in IOError is raised by a parser, I don't need to know at exactly which line the error occured. All I need to know is that the file is somehow unreadable; and that is why the parser failed. Therefore, none of the parser code should be handling IOError because it is being handled higher up in the stack. Since I expected that the parser might have problemes reading files, for problems that have nothing to do with my code, I explicity catch that error if it occurs. I am not expecting an IndexError from the parser and I don't bother to catch it. If the parser code does raise an IndexError, then my program crashes and I know that I have a bug in the parsing code. The call trace will tell me where that error occurs. I can watch that section of code in debugger to find out exactly what went wrong. > Actually return values of functions which I write myself can be as > specific and to the point. I could make it as fuzzy or as precise as I > like. This is no doubt, something that I could emulate with an exception > as well, but only make it slightly more complex with no obvious benefit. You seem to be making it complex because you are still trying to be too fine grained in handling each exception where it occurs as opposed to handing where the logic makes sense that it should be handled and because you are trying to code too defensively against your own code. Exception handling does require a different focus from handling errors from return values alone. > As I said before, the way exceptions are caught seem to me to be the most > confusing bit. Non-atomic operations always worry me. What if my function > which is wrapped inside a try block has two different statements that > raised the same exception but for different reasons? With error handling > I could probably handle it right below the statement which was called and > thus reduce the problem??? If you are having that issue, then you are likely placing the try blocks at too low of a level in your code. In general you will find that most systems have a gateway function as an entry point to the system. If there is not one already, then create such a function in you code. The parse function in my code above would be an example of such a gateway function. Beneath that function, you don't need to know exactly where the error occured, you just need to know the nature of the error and have general error handling procedures for each kind of error that you expect might occur. From piet at vanoostrum.org Thu Dec 2 12:03:58 2010 From: piet at vanoostrum.org (Piet van Oostrum) Date: Thu, 02 Dec 2010 13:03:58 -0400 Subject: Unicode thing that causes a traceback in 2.6 and 2.7 but not in 2.5, and only when writing to a pipe, not to the terminal References: Message-ID: Dan Stromberg writes: > What is this about? It's another n~ thing, but this time in 2.x. > All I'm doing is printing a str containing a character > 127. > > It works fine in 2.5, to a terminal or to a pipe. In 2.6 and 2.7, it > fails when writing to a pipe but works fine writing to my terminal - > an mrxvt.\ > > I really kind of want octets to just be octets, since I'm on a Linux > system - it probably should be up to the user and their related > software to decide how those octets are interpreted. I'm assuming > that the bytes() workarounds I'm using in 3.x aren't going to work in > 2.x - it looks like bytes() is just an alias for str() in 2.6 and 2.7. Strings are indeed byte strings (or octet strings if you prefer) in Python 2.x. > Traceback (most recent call last): > File "./test-readline0", line 22, in > print(line) > UnicodeEncodeError: 'ascii' codec can't encode character u'\xf1' in > position 20: ordinal not in range(128) This message shows that line is not a byte string but a unicode string. If you want to output a unicode string it has to be converted to bytes first, and Python must know which encoding to use. For output to the terminal it can usually get that information from the system, but not for a pipe. You will have to supply it. By the way, if you just want to work with octets, why is the variable line in unicode? If you keep everything in byte strings your problem may disappear. In Python 3 you have to do this explicitely as the default is unicode. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] Nu Fair Trade woonartikelen op http://www.zylja.com From xahlee at gmail.com Thu Dec 2 12:06:23 2010 From: xahlee at gmail.com (Xah Lee) Date: Thu, 2 Dec 2010 09:06:23 -0800 (PST) Subject: Google AI challenge: planet war. Lisp won. Message-ID: <44a8f48f-e291-463e-a042-d0cbc31a2a4e@z17g2000prz.googlegroups.com> discovered this rather late. Google has a AI Challenge: planet wars. http://ai-contest.com/index.php it started sometimes 2 months ago and ended first this month. the winner is G?bor Melis, with his code written in lisp. Congrats lispers! G?bor wrote a blog about it here http://quotenil.com/Planet-Wars-Post-Mortem.html (not sure if this has been mentioned here but quick search didn't find it) Xah ? http://xahlee.org/ ? From love_ram2040 at yahoo.com Thu Dec 2 12:12:28 2010 From: love_ram2040 at yahoo.com (porxy) Date: Thu, 2 Dec 2010 09:12:28 -0800 (PST) Subject: Site to forbidden sites, and blocked Message-ID: Site to forbidden sites, and blocked http://essam.zxq.net From ronsoule at gmail.com Thu Dec 2 12:18:06 2010 From: ronsoule at gmail.com (Ron) Date: Thu, 2 Dec 2010 09:18:06 -0800 (PST) Subject: pyOpenGL Error unable to detect undefined names Message-ID: <3a4317e6-a511-42ff-aff5-fffcedcd6b33@c13g2000prc.googlegroups.com> Hello, I am trying to use pyOpenGL and I keep getting the following errors: Traceback (most recent call last): File "C:\Temp\Python\OpenGL_Test.py", line 10, in from OpenGL.GLU import * File "C:\Python26\lib\site-packages\OpenGL\GLU\__init__.py", line 4, in from OpenGL.raw.GLU import * File "C:\Python26\lib\site-packages\OpenGL\raw\GLU\__init__.py", line 6, in from OpenGL.raw.GLU.constants import * File "C:\Python26\lib\site-packages\OpenGL\raw\GLU\constants.py", line 7, in from OpenGL import platform, arrays File "C:\Python26\lib\site-packages\OpenGL\arrays\__init__.py", line 22, in formathandler.FormatHandler.loadAll() File "C:\Python26\lib\site-packages\OpenGL\arrays\formathandler.py", line 37, in loadAll cls.loadPlugin( entrypoint ) File "C:\Python26\lib\site-packages\OpenGL\arrays\formathandler.py", line 44, in loadPlugin plugin_class = entrypoint.load() File "C:\Python26\lib\site-packages\OpenGL\plugins.py", line 14, in load return importByName( self.import_path ) File "C:\Python26\lib\site-packages\OpenGL\plugins.py", line 28, in importByName module = __import__( ".".join(moduleName), {}, {}, moduleName) File "C:\Python26\lib\site-packages\OpenGL\arrays\numpymodule.py", line 25, in from OpenGL_accelerate.numpy_formathandler import NumpyHandler File "numpy.pxd", line 30, in OpenGL_accelerate.numpy_formathandler (src\numpy_formathandler.c:3543) ValueError: numpy.dtype does not appear to be the correct type object The code is very simple all I have is two import statements: from OpenGL.GLU import * from OpenGL.GL import * The code analysis says that it is "unable to detect undefined names". What does that mean and how do I fix it? Is it an installation error? Thanks for the help, Ron From bruno.desthuilliers at gmail.com Thu Dec 2 12:19:53 2010 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Thu, 2 Dec 2010 09:19:53 -0800 (PST) Subject: How can I define class methods outside of the class? References: Message-ID: On 2 d?c, 06:36, Jeremy wrote: > I have some methods that I need (would like) to define outside of the > class. ?I know this can be done by defining the function and then > setting it equal to some member "assignement" or "binding" might be the terms you were looking for here ;) Also in Python we talk about "attributes", not "members" > of an instance of the class. What you describe here will not "define class methods", nor even instance methods FWIW - it will only make the function an attribute of the instance, but won't turn the function into a method (IOW: the function won't get the instance as first argument). Also and while we're at it, a Python "classmethod" is something special - it's a method that can be called on either an instance or the class itself, and takes the class - not the instance - as first argument. >?But, > because of the complexity of what I'm doing (I have to set many > functions as class methods) I would rather not do this. ?Can someone > show me how to do this? ?Is it even possible? To "no do this" ? Yes, certainly More seriously: if your problem is to dynamically add a bunch of methods to an existing *class*, it's quite easy - just import the class and assign your functions to it, ie: from otherlib import OtherClass def foo(self): print "%s.foo" % self OtherClass.foo = foo And voila, The "foo" method is now available to all (even already existing) instances of OtherClass. If this doesn't answer your question, please provide more context. > ?Can decorators be used > here? What for ? From kavalapooja at gmail.com Thu Dec 2 12:24:25 2010 From: kavalapooja at gmail.com (pooja kavala) Date: Thu, 2 Dec 2010 09:24:25 -0800 (PST) Subject: Simple hack To Get $5999 To Your Paypal Message-ID: <7a93aea6-845f-4a8a-b883-95493504ee52@j19g2000prh.googlegroups.com> Simple hack To Get $5999 To Your Paypal At http://freegiftvideos.co.c Due to High Security Risk I have Hidden the Videos In an Image In that Website On Right Side Below Search Box Click On Image And Watch Videos From bruno.desthuilliers at gmail.com Thu Dec 2 12:26:53 2010 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Thu, 2 Dec 2010 09:26:53 -0800 (PST) Subject: How can I define class methods outside of the class? References: <5007196a-0366-41ed-ae8d-8a1633a22dff@r31g2000prg.googlegroups.com> Message-ID: <87b6efa0-0d24-4858-a37c-d104c3b2c12d@c13g2000prc.googlegroups.com> On 2 d?c, 15:45, Jeremy wrote: > On Dec 1, 10:47?pm, James Mills wrote: > > > > > On Thu, Dec 2, 2010 at 3:36 PM, Jeremy wrote: > > > I have some methods that I need (would like) to define outside of the > > > class. ?I know this can be done by defining the function and then > > > setting it equal to some member of an instance of the class. ?But, > > > because of the complexity of what I'm doing (I have to set many > > > functions as class methods) I would rather not do this. ?Can someone > > > show me how to do this? ?Is it even possible? ?Can decorators be used > > > here? > > > Do you mean something like this ? > > > @classmethod > > def foo(cls): > > ? ? print "I am the foo classmethod on %r" % cls > > > class Foo(object): > > ? ? pass > > > Foo.foo = foo > > > cheers > > James > > Thanks, James. ?That is almost exactly what I want. ?However, I want to avoid doing > > Foo.foo = foo > > Is this going to be possible? ? def patch(cls): def _patch(func): setattr(cls, func.__name__, func) return func return _patch class Foo(object): pass @patch(Foo) def bar(self): print self f = Foo() f.bar() > I'm trying to understand how decorators > are used. ?Are they really necessary in this example? In the above example, the classmethod type was used as a decorator to turn the function into, well, a classmethod (read my other answer in this thread if you don't know what a classmethod is). From jeanmichel at sequans.com Thu Dec 2 12:42:46 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 02 Dec 2010 18:42:46 +0100 Subject: Comparison with False - something I don't understand In-Reply-To: References: <877hfs2zia.fsf@benfinney.id.au> Message-ID: <4CF7DA96.2030608@sequans.com> Harishankar wrote: > As I said before, the way exceptions are caught seem to me to be the most > confusing bit. Non-atomic operations always worry me. What if my function > which is wrapped inside a try block has two different statements that > raised the same exception but for different reasons? With error handling > I could probably handle it right below the statement which was called and > thus reduce the problem??? > > Exception actually are the solution as you can give an unlimitted quantity of information: def myfunction(self): error = myfuncException('a meaninful message') # error 1 error.blame = whateverobjectresponsibleoftheerror # error 2 error.blame = anotherobject_anothercause raise error try: myfunction() except myfuncException, exception: cause = exception.blame # you can inspect the 'cause' for specific handling In a more general and simple manner, you can tune the error feedback of exceptions by changing the message of the exception. Using different exception classes is also an obvious way to do it. But my point was that you can also set attributes to the exception you're raising with reference to almost anything at the time the exception occurs. And that is a very cool way to give precise feedback to exception handlers. JM From aahz at pythoncraft.com Thu Dec 2 12:43:28 2010 From: aahz at pythoncraft.com (Aahz) Date: 2 Dec 2010 09:43:28 -0800 Subject: Get frame object of last called function References: Message-ID: In article , moerchendiser2k3 wrote: > >Hi, is there any chance to get the frame object of the previous called >function? sys._current_frames(), sys._getframe() -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Think of it as evolution in action." --Tony Rand From python at mrabarnett.plus.com Thu Dec 2 12:57:33 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 02 Dec 2010 17:57:33 +0000 Subject: Comparison with False - something I don't understand In-Reply-To: References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> Message-ID: <4CF7DE0D.3030709@mrabarnett.plus.com> On 02/12/2010 16:12, Tim Harig wrote: > On 2010-12-02, Harishankar wrote: >> I understand that the error vs exception debate is quite a big one in the >> programming community as a whole and I don't consider myself very > > Actually, I thought that debate was resolved years ago. I cannot think of > a single recently developed programming language that does not provide > exception handling mechanisms because they have been proven more reliable. > >> Python. I do understand both sides of the issue. Exceptions seem to be >> generally more reliable but I feel they add a lot of complexity >> particular when a lot of code is placed in a try block. > > Lines of code is one measure of complexity. Each line of code has a small > chance of containing a bug. The more lines of code that you have, then the > more likely that one of them contains a bug. Exceptions, by placing error > handling code in fewer places, requires much fewer lines of code then > requiring error handling code after each call that might produce an error > condition. > > The operations of propogating an error up to the higher level logic of > the program is another measure. In languages without exception handling, > careful planning is needed to pass error conditions up through the call > stack until they reach a high enough level in the logic that decisions > can be made about how to handle them. Even further planning must be > taken so that when the error condition reaches level where it needs to > be handled, that enough information about the error is present to know > exactly what went wrong so that it can figure out what to do about it. > This usually involves using globals like errorno to pass out of band > information about the error. Sometimes you even need to know about how > the error affect intermediate levels, did the intermediate code attempt > to handle the condtion and fail? The Openssl error handling system, > that creates an error logging chain is an example of just how complex > this can become. You gain all of this functionality automatically > through exception mechanisms; without all of the complexity. When writing the C code for the new regex module I thought that it would've been easier if I could've used exceptions to propagate errors and unwind the stack, instead of having to return an error code which had to be checked by the caller, and then have the caller explicitly return an error code to /its/ caller. Automatic garbage collection would also have been nice. You don't realise how nice it is to have such things until you have to go without them. From no.email at nospam.invalid Thu Dec 2 13:09:30 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 02 Dec 2010 10:09:30 -0800 Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> Message-ID: <7xvd3crqqt.fsf@ruckus.brouhaha.com> MRAB writes: > When writing the C code for the new regex module I thought that it > would've been easier if I could've used exceptions to propagate errors > and unwind the stack, instead of having to return an error code which > had to be checked by the caller, and then have the caller explicitly > return an error code to /its/ caller. That's called longjmp. > Automatic garbage collection would also have been nice. alloca might help. From tjreedy at udel.edu Thu Dec 2 13:13:10 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 02 Dec 2010 13:13:10 -0500 Subject: Comparison with False - something I don't understand In-Reply-To: References: Message-ID: Aside from the other issues raised, I will just note that is more common to return None when there is no answer (for whatever reason) rather than False and explicitly compare 'is None' than 'is False'. -- Terry Jan Reedy From usernet at ilthio.net Thu Dec 2 13:16:03 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 2 Dec 2010 18:16:03 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <7xvd3crqqt.fsf@ruckus.brouhaha.com> Message-ID: On 2010-12-02, Paul Rubin wrote: > MRAB writes: >> When writing the C code for the new regex module I thought that it >> would've been easier if I could've used exceptions to propagate errors >> and unwind the stack, instead of having to return an error code which >> had to be checked by the caller, and then have the caller explicitly >> return an error code to /its/ caller. > > That's called longjmp. The problem is that you might have partially allocated data structures that you need to free before you can go anywhere. Jumping up several levels, without letting the intermediate levels do their cleanup could easily lead to a memory leak or worse. From python.list at tim.thechases.com Thu Dec 2 13:18:42 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 02 Dec 2010 12:18:42 -0600 Subject: Some syntactic sugar proposals In-Reply-To: <215bc600-d3aa-4c39-adfd-d46ea2843ee7@i32g2000pri.googlegroups.com> References: <215bc600-d3aa-4c39-adfd-d46ea2843ee7@i32g2000pri.googlegroups.com> Message-ID: <4CF7E302.8070103@tim.thechases.com> On 12/02/2010 10:39 AM, Mark Dickinson wrote: > On Nov 15, 12:46 pm, Tim Chase wrote: >> On 11/15/2010 12:39 AM, Dmitry Groshev wrote: >> >>> x in range optimisation >> >> I've often thought this would make a nice O(1)-test lookup on an >> xrange() generator. > > An O(1) test for 'x in' is implemented in Python 3.2, > at least provided that x has type 'int', 'long' or 'bool'. (If x is > an instance of a subclass of int or long, then there's a risk that the > semantics of the membership test have been changed by an explicitly > overridden __eq__, so Python wimps out and falls back to the O(n) > algorithm in that case.) Drat, bested again by the python time-machine. Thanks for bringing that to my attention. -tkc From jlconlin at gmail.com Thu Dec 2 13:22:48 2010 From: jlconlin at gmail.com (Jeremy) Date: Thu, 2 Dec 2010 10:22:48 -0800 (PST) Subject: How can I define class methods outside of the class? References: <5007196a-0366-41ed-ae8d-8a1633a22dff@r31g2000prg.googlegroups.com> <87b6efa0-0d24-4858-a37c-d104c3b2c12d@c13g2000prc.googlegroups.com> Message-ID: <6eb1baa2-3553-4315-b7e9-02d0b2688c92@f20g2000prn.googlegroups.com> On Dec 2, 10:26?am, "bruno.desthuilli... at gmail.com" wrote: > On 2 d?c, 15:45, Jeremy wrote: > > > > > > > On Dec 1, 10:47?pm, James Mills wrote: > > > > On Thu, Dec 2, 2010 at 3:36 PM, Jeremy wrote: > > > > I have some methods that I need (would like) to define outside of the > > > > class. ?I know this can be done by defining the function and then > > > > setting it equal to some member of an instance of the class. ?But, > > > > because of the complexity of what I'm doing (I have to set many > > > > functions as class methods) I would rather not do this. ?Can someone > > > > show me how to do this? ?Is it even possible? ?Can decorators be used > > > > here? > > > > Do you mean something like this ? > > > > @classmethod > > > def foo(cls): > > > ? ? print "I am the foo classmethod on %r" % cls > > > > class Foo(object): > > > ? ? pass > > > > Foo.foo = foo > > > > cheers > > > James > > > Thanks, James. ?That is almost exactly what I want. ?However, I want to avoid doing > > > Foo.foo = foo > > > Is this going to be possible? ? > > def patch(cls): > ? ?def _patch(func): > ? ? ? ?setattr(cls, func.__name__, func) > ? ? ? ?return func > ? ?return _patch > > class Foo(object): pass > > @patch(Foo) > def bar(self): > ? ? print self > > f = Foo() > f.bar() Yes! This is what I was looking for. Thanks! Jeremy From tjreedy at udel.edu Thu Dec 2 13:31:30 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 02 Dec 2010 13:31:30 -0500 Subject: Comparison with False - something I don't understand In-Reply-To: References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> Message-ID: On 12/2/2010 9:56 AM, Harishankar wrote: > There are some reasons why I hate exceptions but that is a different > topic. However, in short I can say that personally: > > 1. I hate try blocks which add complexity to the code when none is > needed. Try blocks make code much more unreadable in my view and I use it > only for the built-in exceptions when absolutely needed. > > 2. I prefer the less irksome True or False to do error checking. > Exceptions seem too heavyweight for simple problems. It turns out that try block are computationally lighter weight (faster) for normal execution ;-) > 3. Philosophically I think exception handling is the wrong approach to > error management. I have never grown up programming with exceptions in C > and I couldn't pick up the habit with python either. Did I mention that I > detest try blocks? try blocks seem ugly and destroy code clarity at least > in my view. And enclosing single statements under separate try blocks > seem to add a lot of clutter. Having also come to Python directly from C, I can sympathize. It took me a while to adjust. -- Terry Jan Reedy From no.email at nospam.invalid Thu Dec 2 13:33:40 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 02 Dec 2010 10:33:40 -0800 Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <7xvd3crqqt.fsf@ruckus.brouhaha.com> Message-ID: <7xr5e0rpmj.fsf@ruckus.brouhaha.com> Tim Harig writes: >> That's called longjmp. > > The problem is that you might have partially allocated data structures > that you need to free before you can go anywhere. Alloca can help with that since the stack stuff gets released by the longjmp. Alternatively you can have an auxiliary stack of cleanup records that the longjmp handler walks through. Of course if you do that, you're halfway towards reinventing exceptions. From invalid at invalid.invalid Thu Dec 2 13:36:58 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 2 Dec 2010 18:36:58 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <7xvd3crqqt.fsf@ruckus.brouhaha.com> Message-ID: On 2010-12-02, Paul Rubin wrote: > MRAB writes: >> When writing the C code for the new regex module I thought that it >> would've been easier if I could've used exceptions to propagate errors >> and unwind the stack, instead of having to return an error code which >> had to be checked by the caller, and then have the caller explicitly >> return an error code to /its/ caller. > > That's called longjmp. In theory. In practice, using longjump for that without blowing your foot off isn't easy. >> Automatic garbage collection would also have been nice. > > alloca might help. And that's almost as easy to screw up. :) -- Grant Edwards grant.b.edwards Yow! I want EARS! I want at two ROUND BLACK EARS gmail.com to make me feel warm 'n secure!! From python at mrabarnett.plus.com Thu Dec 2 13:41:13 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 02 Dec 2010 18:41:13 +0000 Subject: Comparison with False - something I don't understand In-Reply-To: <7xvd3crqqt.fsf@ruckus.brouhaha.com> References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <7xvd3crqqt.fsf@ruckus.brouhaha.com> Message-ID: <4CF7E849.8040902@mrabarnett.plus.com> On 02/12/2010 18:09, Paul Rubin wrote: > MRAB writes: >> When writing the C code for the new regex module I thought that it >> would've been easier if I could've used exceptions to propagate errors >> and unwind the stack, instead of having to return an error code which >> had to be checked by the caller, and then have the caller explicitly >> return an error code to /its/ caller. > > That's called longjmp. > The problem with that is that the caller might have to do some tidying up, such as deallocation. Exceptions give the caller the chance of catching it (ideally in a 'finally' block), tidying up, and then propagating. >> Automatic garbage collection would also have been nice. > > alloca might help. I didn't know about that. It looks like that's allocated on the stack, and the allocation I'm talking must be on the heap, so it's not suitable anyway. From iamforufriends at gmail.com Thu Dec 2 13:44:46 2010 From: iamforufriends at gmail.com (kate for free dating) Date: Thu, 2 Dec 2010 10:44:46 -0800 (PST) Subject: hai this is kate, im staing near u, date with me for free... girls and boyz... Message-ID: hai this is kate, im staing near u, date with me for free... girls and boyz... http://x2c.eu/5i http://x2c.eu/5i http://x2c.eu/5i http://x2c.eu/5i From ethan at stoneleaf.us Thu Dec 2 13:51:18 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 02 Dec 2010 10:51:18 -0800 Subject: DBF (VFP) to XLS (Excel) in pure Python In-Reply-To: <5ddf7758-754f-4649-be1e-85cdee7860e5@y23g2000yqd.googlegroups.com> References: <084f9299-b2b3-440f-b83f-9fbe42220221@j19g2000prh.googlegroups.com> <5ddf7758-754f-4649-be1e-85cdee7860e5@y23g2000yqd.googlegroups.com> Message-ID: <4CF7EAA6.1050906@stoneleaf.us> kirby.urner at gmail.com wrote: Some ideas: for (i, name) in enumerate(thedbf.field_names): sheet1.write(0, i, name, header_style) thetype = thedbf.type(name) thelen, thedec = thedbf.size(name) if thetype == "M": thelen = 100 elif thelen == 0: thelen = 1 colwidth = max(len(name), int(thelen)) sheet1.col(i).width = colwidth * 310 messages = [] for row, record in enumerate(thedbf): . . . > Same error with: > >>>> thetable = dbf.VfpTable(thefile) >>>> thetable.close(keep_memos=True) Does this still happen with the latest code? (Not yet on PyPI for those following along -- hope to get a new package released this week.) ~Ethan~ From usernet at ilthio.net Thu Dec 2 13:51:48 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 2 Dec 2010 18:51:48 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <7xvd3crqqt.fsf@ruckus.brouhaha.com> <7xr5e0rpmj.fsf@ruckus.brouhaha.com> Message-ID: On 2010-12-02, Paul Rubin wrote: > Tim Harig writes: >>> That's called longjmp. >> >> The problem is that you might have partially allocated data structures >> that you need to free before you can go anywhere. > > Alloca can help with that since the stack stuff gets released by the > longjmp. Alternatively you can have an auxiliary stack of cleanup alloca() only helps if you actually *want* the data stored on the stack. There are many reasons one might prefer or need that the data in the heap. > longjmp. Alternatively you can have an auxiliary stack of cleanup > records that the longjmp handler walks through. Of course if you do Only if you already have pointers to *all* of the data structures at the point where you put your setjmp(). This approach is error prone. > records that the longjmp handler walks through. Of course if you do > that, you're halfway towards reinventing exceptions. Exactly. From ozric at web.de Thu Dec 2 14:01:05 2010 From: ozric at web.de (chris) Date: Thu, 2 Dec 2010 11:01:05 -0800 (PST) Subject: aggregation for a nested dict Message-ID: Hi, i would like to parse many thousand files and aggregate the counts for the field entries related to every id. extract_field grep the identifier for the fields with regex. result = [ { extract_field("id", line) : [extract_field("field1", line),extract_field("field2", line)]} for line in FILE ] result gives me. {'a: ['0', '84']}, {'a': ['0', '84']}, {'b': ['1000', '83']}, {'b': ['0', '84']}, i like to aggregate them for every line or maybe file and get after the complete parsing procedure the possibility to count the amount of ids having > 0 entries in '83'. {'a: {'0':2, '84':2}} {'b': {'1000':1,'83':1,'84':1} } My current solution with mysql is really slow. Many thanks for advance. Christian From no.email at nospam.invalid Thu Dec 2 14:04:07 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 02 Dec 2010 11:04:07 -0800 Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <7xvd3crqqt.fsf@ruckus.brouhaha.com> <7xr5e0rpmj.fsf@ruckus.brouhaha.com> Message-ID: <7xmxooro7s.fsf@ruckus.brouhaha.com> Tim Harig writes: >> longjmp. Alternatively you can have an auxiliary stack of cleanup >> records that the longjmp handler walks through. Of course if you do > > Only if you already have pointers to *all* of the data structures at > the point where you put your setjmp(). The setjmp point only has to know where the aux stack is and its depth when the longjmp happens. The cleanup records contain any necessary pointers to data structures that need freeing. That is basically how try/finally would do it too. This is pretty standard stuff. From usernet at ilthio.net Thu Dec 2 14:15:50 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 2 Dec 2010 19:15:50 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <7xvd3crqqt.fsf@ruckus.brouhaha.com> <7xr5e0rpmj.fsf@ruckus.brouhaha.com> <7xmxooro7s.fsf@ruckus.brouhaha.com> Message-ID: On 2010-12-02, Paul Rubin wrote: > Tim Harig writes: >>> longjmp. Alternatively you can have an auxiliary stack of cleanup >>> records that the longjmp handler walks through. Of course if you do >> >> Only if you already have pointers to *all* of the data structures at >> the point where you put your setjmp(). > > The setjmp point only has to know where the aux stack is and its depth > when the longjmp happens. The cleanup records contain any necessary > pointers to data structures that need freeing. That is basically how > try/finally would do it too. This is pretty standard stuff. I am not talking about what setjmp() has to do, I am talking about what *you* have to do after setjmp() returns. If you have allocated memory in intermediate functions and you don't have a reference to them outside of the functions that longjmp() bypasses from returning properly (and thus either not clearning data structures or returning a reference to those data structures as it normally would) then you have potential memory leaks, dangling pointers, etc. I am not saying that this cannot be done. What I am saying is that it is inherently error prone. From python at mrabarnett.plus.com Thu Dec 2 14:49:20 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 02 Dec 2010 19:49:20 +0000 Subject: aggregation for a nested dict In-Reply-To: References: Message-ID: <4CF7F840.9060000@mrabarnett.plus.com> On 02/12/2010 19:01, chris wrote: > Hi, > > i would like to parse many thousand files and aggregate the counts for > the field entries related to every id. > > extract_field grep the identifier for the fields with regex. > > result = [ { extract_field("id", line) : [extract_field("field1", > line),extract_field("field2", line)]} for line in FILE ] > > result gives me. > {'a: ['0', '84']}, > {'a': ['0', '84']}, > {'b': ['1000', '83']}, > {'b': ['0', '84']}, > > i like to aggregate them for every line or maybe file and get after > the complete parsing procedure > the possibility to count the amount of ids having> 0 entries in > '83'. > > {'a: {'0':2, '84':2}} > {'b': {'1000':1,'83':1,'84':1} } > > My current solution with mysql is really slow. > result = [ {'a': ['0', '84']}, {'a': ['0', '84']}, {'b': ['1000', '83']}, {'b': ['0', '84']}, ] from collections import defaultdict aggregates = defaultdict(lambda: defaultdict(int)) for entry in result: for key, values in entry.items(): for v in values: aggregates[key][v] += 1 print(aggregates) From steve at holdenweb.com Thu Dec 2 14:50:08 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 02 Dec 2010 14:50:08 -0500 Subject: Comparison with False - something I don't understand In-Reply-To: References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> Message-ID: On 12/2/2010 1:31 PM, Terry Reedy wrote: > It turns out that try block are computationally lighter weight (faster) > for normal execution ;-) Though that alone would hardly be sufficient reason to use them. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From python at mrabarnett.plus.com Thu Dec 2 14:54:33 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 02 Dec 2010 19:54:33 +0000 Subject: Comparison with False - something I don't understand In-Reply-To: References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <7xvd3crqqt.fsf@ruckus.brouhaha.com> <7xr5e0rpmj.fsf@ruckus.brouhaha.com> <7xmxooro7s.fsf@ruckus.brouhaha.com> Message-ID: <4CF7F979.1080108@mrabarnett.plus.com> On 02/12/2010 19:15, Tim Harig wrote: > On 2010-12-02, Paul Rubin wrote: >> Tim Harig writes: >>>> longjmp. Alternatively you can have an auxiliary stack of cleanup >>>> records that the longjmp handler walks through. Of course if you do >>> >>> Only if you already have pointers to *all* of the data structures at >>> the point where you put your setjmp(). >> >> The setjmp point only has to know where the aux stack is and its depth >> when the longjmp happens. The cleanup records contain any necessary >> pointers to data structures that need freeing. That is basically how >> try/finally would do it too. This is pretty standard stuff. > > I am not talking about what setjmp() has to do, I am talking about what > *you* have to do after setjmp() returns. If you have allocated memory in > intermediate functions and you don't have a reference to them outside of > the functions that longjmp() bypasses from returning properly (and thus > either not clearning data structures or returning a reference to those data > structures as it normally would) then you have potential memory leaks, > dangling pointers, etc. > > I am not saying that this cannot be done. What I am saying is that it > is inherently error prone. Automatic garbage collection is nice to have when using exceptions precisely because it's automatic, so unwinding the stack is much safer. From clp2 at rebertia.com Thu Dec 2 15:07:35 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 2 Dec 2010 12:07:35 -0800 Subject: aggregation for a nested dict In-Reply-To: References: Message-ID: On Thu, Dec 2, 2010 at 11:01 AM, chris wrote: > Hi, > > i would like to parse many thousand files and aggregate the counts for > the field entries related to every id. > > extract_field grep the identifier for the fields with regex. > > result = [ { extract_field("id", line) : [extract_field("field1", > line),extract_field("field2", line)]} ?for line ?in FILE ] > > result gives me. > {'a: ['0', '84']}, > {'a': ['0', '84']}, > {'b': ['1000', '83']}, > {'b': ['0', '84']}, > > i like to aggregate them for every line or maybe file and get after > the complete parsing procedure > the possibility to count the amount of ids ?having > 0 entries in > '83'. > > {'a: {'0':2, '84':2}} > {'b': {'1000':1,'83':1,'84':1} } Er, what happened to the '0' for 'b'? > My current solution with mysql is really slow. Untested: # requires Python 2.7+ due to Counter from collections import defaultdict, Counter FIELDS = ["field1", "field2"] id2counter = defaultdict(Counter) for line in FILE: identifier = extract_field("id", line) counter = id2counter[identifier] for field_name in FIELDS: field_val = int(extract_field(field_name, line)) counter[field_val] += 1 print(id2counter) print(sum(1 for counter in id2counter.values() if counter[83])) Cheers, Chris -- http://blog.rebertia.com From __peter__ at web.de Thu Dec 2 15:15:06 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 02 Dec 2010 21:15:06 +0100 Subject: aggregation for a nested dict References: Message-ID: chris wrote: > Hi, > > i would like to parse many thousand files and aggregate the counts for > the field entries related to every id. > > extract_field grep the identifier for the fields with regex. > > result = [ { extract_field("id", line) : [extract_field("field1", > line),extract_field("field2", line)]} for line in FILE ] > > result gives me. > {'a: ['0', '84']}, > {'a': ['0', '84']}, > {'b': ['1000', '83']}, > {'b': ['0', '84']}, > > i like to aggregate them for every line or maybe file and get after > the complete parsing procedure > the possibility to count the amount of ids having > 0 entries in > '83'. > > {'a: {'0':2, '84':2}} > {'b': {'1000':1,'83':1,'84':1} } > > My current solution with mysql is really slow. >>> def rows(lines): ... for line in lines: ... yield extract_field("id", line), [extract_field(name, line) for name in "field1", "field2"] ... >>> for row in rows(lines): ... print row ... ('a', ['0', '84']) ('b', ['1000', '83']) ('a', ['0', '84']) ('b', ['0', '84']) >>> from collections import defaultdict >>> class defaultdict(defaultdict): # omit that in your real code ... def __repr__(self): return repr(dict(self)) ... >>> outer = defaultdict(lambda: defaultdict(int)) >>> for key, values in rows(lines): ... inner = outer[key] ... for v in values: ... inner[v] += 1 ... >>> outer {'a': {'0': 2, '84': 2}, 'b': {'83': 1, '1000': 1, '84': 1, '0': 1}} From no.email at nospam.invalid Thu Dec 2 15:21:28 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 02 Dec 2010 12:21:28 -0800 Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <7xvd3crqqt.fsf@ruckus.brouhaha.com> <7xr5e0rpmj.fsf@ruckus.brouhaha.com> <7xmxooro7s.fsf@ruckus.brouhaha.com> Message-ID: <7xipzcrkmv.fsf@ruckus.brouhaha.com> Tim Harig writes: > I am not talking about what setjmp() has to do, I am talking about what > *you* have to do after setjmp() returns. If you have allocated memory in > intermediate functions and you don't have a reference to them outside of > the functions that longjmp() bypasses from returning properly (and thus > either not clearning data structures or returning a reference to those data > structures as it normally would) then you have potential memory leaks, > dangling pointers, etc. Sure, that's what the aux stack is for--you put any such references into it, for the setjmp handler to find later. You do that BEFORE setjmp returns, of course. > I am not saying that this cannot be done. What I am saying is that it > is inherently error prone. I suppose so, but so is everything else in C. On the overall scale of C-related hazards, this particular one isn't so bad if you code in a consistent style and are disciplined about recording the cleanups. You could also use something like an obstack, which is a stack allocated on the heap, so it persists after the control stack returns, but you can release the whole thing in one operation. From usernet at ilthio.net Thu Dec 2 15:32:47 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 2 Dec 2010 20:32:47 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <7xvd3crqqt.fsf@ruckus.brouhaha.com> <7xr5e0rpmj.fsf@ruckus.brouhaha.com> <7xmxooro7s.fsf@ruckus.brouhaha.com> Message-ID: On 2010-12-02, MRAB wrote: > On 02/12/2010 19:15, Tim Harig wrote: >> On 2010-12-02, Paul Rubin wrote: >>> Tim Harig writes: >>>>> longjmp. Alternatively you can have an auxiliary stack of cleanup >>>>> records that the longjmp handler walks through. Of course if you do >>>> >>>> Only if you already have pointers to *all* of the data structures at >>>> the point where you put your setjmp(). >>> >>> The setjmp point only has to know where the aux stack is and its depth >>> when the longjmp happens. The cleanup records contain any necessary >>> pointers to data structures that need freeing. That is basically how >>> try/finally would do it too. This is pretty standard stuff. >> >> I am not talking about what setjmp() has to do, I am talking about what >> *you* have to do after setjmp() returns. If you have allocated memory in >> intermediate functions and you don't have a reference to them outside of >> the functions that longjmp() bypasses from returning properly (and thus >> either not clearning data structures or returning a reference to those data >> structures as it normally would) then you have potential memory leaks, >> dangling pointers, etc. >> >> I am not saying that this cannot be done. What I am saying is that it >> is inherently error prone. > > Automatic garbage collection is nice to have when using exceptions > precisely because it's automatic, so unwinding the stack is much safer. Indeed. From python.list at tim.thechases.com Thu Dec 2 15:40:17 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 02 Dec 2010 14:40:17 -0600 Subject: aggregation for a nested dict In-Reply-To: <4CF7F840.9060000@mrabarnett.plus.com> References: <4CF7F840.9060000@mrabarnett.plus.com> Message-ID: <4CF80431.3050605@tim.thechases.com> On 12/02/2010 01:49 PM, MRAB wrote: > On 02/12/2010 19:01, chris wrote: >> i would like to parse many thousand files and aggregate the counts for >> the field entries related to every id. >> >> extract_field grep the identifier for the fields with regex. >> >> result = [ { extract_field("id", line) : [extract_field("field1", >> line),extract_field("field2", line)]} for line in FILE ] >> >> i like to aggregate them for every line or maybe file and get after >> the complete parsing procedure >> >> {'a: {'0':2, '84':2}} >> {'b': {'1000':1,'83':1,'84':1} } I'm not sure what happened to b['0'] based on your initial data, but assuming that was an oversight... > from collections import defaultdict > > aggregates = defaultdict(lambda: defaultdict(int)) > for entry in result: > for key, values in entry.items(): > for v in values: > aggregates[key][v] += 1 Or, if you don't need the intermediate result, you can tweak MRAB's solution and just iterate over the file(s): aggregates = defaultdict(lambda: defaultdict(int)) for line in FILE: key = extract_field("id", line) aggregates[key][extract_field("field1", line)] += 1 aggregates[key][extract_field("field2", line)] += 1 or, if you're using an older version (<2.5) that doesn't provide defaultdict, you could do something like aggregates = {} for line in FILE: key = extract_field("id", line) d = aggregates.setdefault(key, {}) for fieldname in ('field1', 'field2'): value = extract_field(fieldname, line) d[value] = d.get(value, 0) + 1 -tkc From usernet at ilthio.net Thu Dec 2 15:51:15 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 2 Dec 2010 20:51:15 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <7xvd3crqqt.fsf@ruckus.brouhaha.com> <7xr5e0rpmj.fsf@ruckus.brouhaha.com> <7xmxooro7s.fsf@ruckus.brouhaha.com> <7xipzcrkmv.fsf@ruckus.brouhaha.com> Message-ID: On 2010-12-02, Paul Rubin wrote: > Tim Harig writes: >> I am not talking about what setjmp() has to do, I am talking about what >> *you* have to do after setjmp() returns. If you have allocated memory in >> intermediate functions and you don't have a reference to them outside of >> the functions that longjmp() bypasses from returning properly (and thus >> either not clearning data structures or returning a reference to those data >> structures as it normally would) then you have potential memory leaks, >> dangling pointers, etc. > > Sure, that's what the aux stack is for--you put any such references into > it, for the setjmp handler to find later. You do that BEFORE setjmp > returns, of course. If you miss something, you are in trouble. There is a concept of variable life that is measured by how many lines separate the use of variable from its first use to its last. By using setjmp/longjmp, you effectively extend the life of these variables, potentially through several files, to at least as long as the jump. If there are several function calls in depth, there may be quite a lot of space that you have to check to make sure that you have not missed anything. >> I am not saying that this cannot be done. What I am saying is that it >> is inherently error prone. > > I suppose so, but so is everything else in C. On the overall scale of > C-related hazards, this particular one isn't so bad if you code in a > consistent style and are disciplined about recording the cleanups. > > You could also use something like an obstack, which is a stack allocated > on the heap, so it persists after the control stack returns, but you can > release the whole thing in one operation. By working the error back up through the call stack, you can keep track of the variables and allocations in each function isolated to that function. The smaller each function is, the easier and less error prone it will be to theck it is to check. That makes it much easier to make sure that you have not missed anything. Essentially, you can validate that each function correctly handles is allocations rather then having to validate the setjmp/longjmp structure as a whole. To use Joe Armstrong's phrase, "it makes the impossible merely difficult." Back to the topic, by using Python with its exceptions and garbage collection, all of this is a moot point. From ben+python at benfinney.id.au Thu Dec 2 16:06:35 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 03 Dec 2010 08:06:35 +1100 Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> Message-ID: <8739qf3mw4.fsf@benfinney.id.au> Harishankar writes: > On Thu, 02 Dec 2010 22:19:25 +1100, Ben Finney wrote: > > > More details of the problem you're trying to solve would help with > > giving specific advice. > > I'm writing functions with multiple points of failure exits. I use > return False as a way to flag the error condition rather than raising > exceptions. That's not much detail. Based only on that, I would say you should be raising an exception at each ?point of failure?, preferably of a type defined for the purpose, instead of returning False. > But under certain circumstances, the function can also return empty > lists The function returns boolean, list, and None types? That's very much a case where the function is trying to do too many things with the return value. Raise exceptions for exceptional cases, and define the function interface so that it's doing one clear job only. Often that involves breaking a complicated function into several collaborating functions with simpler interfaces. -- \ ?Pinky, are you pondering what I'm pondering?? ?Umm, I think | `\ so, Brain, but three men in a tub? Ooh, that's unsanitary!? | _o__) ?_Pinky and The Brain_ | Ben Finney From prog at vtr.net Thu Dec 2 16:45:44 2010 From: prog at vtr.net (craf) Date: Thu, 02 Dec 2010 18:45:44 -0300 Subject: Uso de variable Global Message-ID: <1291326344.4743.5.camel@cristian-desktop> Hola. Estoy probando Tkinter y escrib? este peque?o c?digo el cual crea un formulario con un textbox y un bot?n. Al ingresar un dato en el textbox y presionar el bot?n, se imprime en la consola el valor. ---CODE-------------------- from Tkinter import * def muestra(): print(valor.get()) class App: def __init__(self,master): global valor valor = StringVar() e = Entry(master,textvariable=valor).pack() b = Button(master,text='Mostrar',command=muestra).pack() master = Tk() app = App(master) master.mainloop() ----------------------------- Funciona, pero tuve que hacer uso de una variable Global. Pregunta: ?Es valida esta forma?, ?Se puede hacer de otra forma, sin ocuparla?. Saludos. Cristian From pau.cervera at gmail.com Thu Dec 2 17:04:24 2010 From: pau.cervera at gmail.com (Pau Cervera) Date: Thu, 2 Dec 2010 23:04:24 +0100 Subject: [Python-es] Uso de variable Global In-Reply-To: <1291326344.4743.5.camel@cristian-desktop> References: <1291326344.4743.5.camel@cristian-desktop> Message-ID: Ni idea de Tkinter, pero ?no puedes almacenar *valor* en una variable de instancia de App y convertir la funci?n *muestra* en un m?todo de la classe App que teng aceso a las variables de instancia de App? ----- Pau Python..., what else? 2010/12/2 craf > Hola. > > > Estoy probando Tkinter y escrib? este peque?o c?digo el cual crea un > formulario con un textbox y un bot?n. Al ingresar un dato en el textbox > y presionar el bot?n, se imprime en la consola el valor. > > > ---CODE-------------------- > > from Tkinter import * > > def muestra(): > print(valor.get()) > > class App: > def __init__(self,master): > global valor > valor = StringVar() > e = Entry(master,textvariable=valor).pack() > b = Button(master,text='Mostrar',command=muestra).pack() > > > master = Tk() > app = App(master) > master.mainloop() > > ----------------------------- > > Funciona, pero tuve que hacer uso de una variable Global. > > Pregunta: ?Es valida esta forma?, ?Se puede hacer de otra forma, sin > ocuparla?. > > Saludos. > > Cristian > > > > _______________________________________________ > Python-es mailing list > Python-es at python.org > http://mail.python.org/mailman/listinfo/python-es > FAQ: http://python-es-faq.wikidot.com/ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Thu Dec 2 17:06:25 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 02 Dec 2010 23:06:25 +0100 Subject: Uso de variable Global References: Message-ID: craf wrote: > Hola. > > > Estoy probando Tkinter y escrib? este peque?o c?digo el cual crea un > formulario con un textbox y un bot?n. Al ingresar un dato en el textbox > y presionar el bot?n, se imprime en la consola el valor. > > > ---CODE-------------------- > > from Tkinter import * > > def muestra(): > print(valor.get()) > > class App: > def __init__(self,master): > global valor > valor = StringVar() > e = Entry(master,textvariable=valor).pack() > b = Button(master,text='Mostrar',command=muestra).pack() pack() returns None so both e and b set to None here. In this case it doesn't matter because you don't do anything with e and b. > master = Tk() > app = App(master) > master.mainloop() > > ----------------------------- > > Funciona, pero tuve que hacer uso de una variable Global. > > Pregunta: ?Es valida esta forma?, ?Se puede hacer de otra forma, sin > ocuparla?. I'd prefer to make valor an attribute and muestra() a method: from Tkinter import * class App: def __init__(self, master): self.valor = StringVar() Entry(master, textvariable=self.valor).pack() Button(master, text='Mostrar', command=self.muestra).pack() def muestra(self): print self.valor.get() master = Tk() app = App(master) master.mainloop() From nagle at animats.com Thu Dec 2 17:11:05 2010 From: nagle at animats.com (John Nagle) Date: Thu, 02 Dec 2010 14:11:05 -0800 Subject: Comparison with False - something I don't understand In-Reply-To: References: Message-ID: <4cf81999$0$1625$742ec2ed@news.sonic.net> On 12/2/2010 10:13 AM, Terry Reedy wrote: > Aside from the other issues raised, I will just note that is more common > to return None when there is no answer (for whatever reason) rather than > False and explicitly compare 'is None' than 'is False'. The basic problem is that the original design of Python lacked a "bool" type. Classic language design error. It seems reasonable to people not familiar with programming language history to let True be equivalent to 1 and False be equivalent to 0, but it doesn't work out well. Retrofitting a "bool" type never quite works right. C/C++ went through this decades ago. The semantics of integers are clear, and the semantics of booleans are clear, but the semantics of mixed booleans and integers are not. You get questions like the one in this thread. Related questions include the semantics of x = True + True What's the value of "x"? "True"? 2? Is "+" between two "Bool" items addition, logical OR, or an error? The same problem applies to "*". The arguments on either side can be seen in PEP 285, but they gloss over the fact that the original design was botched. Similar design errors show up in other places in Python. Using "+" for concatenation seemed reasonable, but didn't scale out well, especially after NumPy's "array" type was introduced. [1,2,3] + [4,5,6] and array([1,2,3]) + array([4,5,6]) produce quite different results. Worse, what should array([1,2,3]) + [4,5,6] do? It doesn't raise an exception. I went to a talk by Alexander Stepanov at Stanford recently, where he talked about problems in the fundamentals of programming. This is one of the issues that came up. Defining addition in a way that is not associative and commutative leads to problems, and breaks generic algorithms. If the basic operators follow the expected rules, generic algorithms will work on them. That was botched in Python. John Nagle From draeath.spamtrap at gmail.com Thu Dec 2 17:44:01 2010 From: draeath.spamtrap at gmail.com (draeath) Date: Thu, 02 Dec 2010 22:44:01 GMT Subject: three column dataset - additions and deletions Message-ID: I'm going to be writing a utility that will be pulling three fields from a MySQL table. I've already got a sample dataset - there's a long int (which is a db key), a short string, and a looong string. Many rows. As it is, receive this data from the DB interface as a rather large tuple of tuples. I plan on hashing the long string field (both for convenience and security) and storing the set in a pickle. The idea is that this script will run periodically, pulling the table, and comparing the data gathered at that run to that stored by the previous, acting on changes made, and storing the current data back (to be referenced against in the next invocation) I figure it will be easy enough to determine changed hashes for a given key. What I'm unclear on is what the best type of structure to keep this data in, given that I need to modify the data after it comes in (replacing that long string with, say, an MD5 from hashlib) and both need to act on "new" rows (rows that don't exist in the 'old' data) and deleted rows (rows that only exist in the 'old' data). Keeping in mind that I'm a newbie here, and I'm probably not aware of most of the different ways to store such things. I shouldn't have any problems with the logic itself - I just know enough to know I don't know the best ways of doing things :) Any suggestions? I'm not asking for code or handholding, but some objects or datatypes to look into would be very helpful at this early stage. Thanks! From usernet at ilthio.net Thu Dec 2 17:55:53 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 2 Dec 2010 22:55:53 +0000 (UTC) Subject: three column dataset - additions and deletions References: Message-ID: On 2010-12-02, draeath wrote: > The idea is that this script will run periodically, pulling the table, > and comparing the data gathered at that run to that stored by the > previous, acting on changes made, and storing the current data back (to > be referenced against in the next invocation) So, basically, you want to store a local copy of the data and sync it to the original. > I figure it will be easy enough to determine changed hashes for a given > key. What I'm unclear on is what the best type of structure to keep this > data in, given that I need to modify the data after it comes in > (replacing that long string with, say, an MD5 from hashlib) and both need > to act on "new" rows (rows that don't exist in the 'old' data) and > deleted rows (rows that only exist in the 'old' data). You need to differentiate between the in memory data model and the storage model. Since this data comes from a database in the first place, I would dump it to an sqlite3 database from the beginning. You can use this to store, modify, and change the values as you receive them from the database. If you are looking for in-memory structures, then you haven't really provided us with enough information on the significance and organization of the data. From abarzua at vtr.net Thu Dec 2 17:57:11 2010 From: abarzua at vtr.net (cristian =?ISO-8859-1?Q?abarz=FAa?=) Date: Thu, 02 Dec 2010 19:57:11 -0300 Subject: [Fwd: Re: Uso de variable Global] Message-ID: <1291330631.2048.1.camel@cristian-desktop> --------- Mensaje reenviado -------- > De: Peter Otten <__peter__ at web.de> > Para: python-list at python.org > Asunto: Re: Uso de variable Global > Fecha: Thu, 02 Dec 2010 23:06:25 +0100 > Grupos de noticias: comp.lang.python > > craf wrote: > > > Hola. > > > > > > Estoy probando Tkinter y escrib? este peque?o c?digo el cual crea un > > formulario con un textbox y un bot?n. Al ingresar un dato en el textbox > > y presionar el bot?n, se imprime en la consola el valor. > > > > > > ---CODE-------------------- > > > > from Tkinter import * > > > > def muestra(): > > print(valor.get()) > > > > class App: > > def __init__(self,master): > > global valor > > valor = StringVar() > > e = Entry(master,textvariable=valor).pack() > > b = Button(master,text='Mostrar',command=muestra).pack() > > pack() returns None so both e and b set to None here. In this case it > doesn't matter because you don't do anything with e and b. > > > master = Tk() > > app = App(master) > > master.mainloop() > > > > ----------------------------- > > > > Funciona, pero tuve que hacer uso de una variable Global. > > > > Pregunta: ?Es valida esta forma?, ?Se puede hacer de otra forma, sin > > ocuparla?. > > I'd prefer to make valor an attribute and muestra() a method: > > from Tkinter import * > > class App: > def __init__(self, master): > self.valor = StringVar() > Entry(master, textvariable=self.valor).pack() > Button(master, text='Mostrar', command=self.muestra).pack() > def muestra(self): > print self.valor.get() > > master = Tk() > app = App(master) > master.mainloop() Thanks!, Sorry for the Spanish mail. Regards Cristian From prog at vtr.net Thu Dec 2 17:58:36 2010 From: prog at vtr.net (craf) Date: Thu, 02 Dec 2010 19:58:36 -0300 Subject: [Fwd: Re: Uso de variable Global] Message-ID: <1291330716.2048.2.camel@cristian-desktop> --------- Mensaje reenviado -------- > De: Peter Otten <__peter__ at web.de> > Para: python-list at python.org > Asunto: Re: Uso de variable Global > Fecha: Thu, 02 Dec 2010 23:06:25 +0100 > Grupos de noticias: comp.lang.python > > craf wrote: > > > Hola. > > > > > > Estoy probando Tkinter y escrib? este peque?o c?digo el cual crea un > > formulario con un textbox y un bot?n. Al ingresar un dato en el textbox > > y presionar el bot?n, se imprime en la consola el valor. > > > > > > ---CODE-------------------- > > > > from Tkinter import * > > > > def muestra(): > > print(valor.get()) > > > > class App: > > def __init__(self,master): > > global valor > > valor = StringVar() > > e = Entry(master,textvariable=valor).pack() > > b = Button(master,text='Mostrar',command=muestra).pack() > > pack() returns None so both e and b set to None here. In this case it > doesn't matter because you don't do anything with e and b. > > > master = Tk() > > app = App(master) > > master.mainloop() > > > > ----------------------------- > > > > Funciona, pero tuve que hacer uso de una variable Global. > > > > Pregunta: ?Es valida esta forma?, ?Se puede hacer de otra forma, sin > > ocuparla?. > > I'd prefer to make valor an attribute and muestra() a method: > > from Tkinter import * > > class App: > def __init__(self, master): > self.valor = StringVar() > Entry(master, textvariable=self.valor).pack() > Button(master, text='Mostrar', command=self.muestra).pack() > def muestra(self): > print self.valor.get() > > master = Tk() > app = App(master) > master.mainloop() > Thanks!, Sorry for the Spanish mail. Regards Cristian From burton at userful.com Thu Dec 2 18:06:59 2010 From: burton at userful.com (Burton Samograd) Date: Thu, 02 Dec 2010 16:06:59 -0700 Subject: Changing ' to " in printed representation of dictionaries Message-ID: Hello, I was wondering if there was a way to change the quote character for keys in string representation of dictionaries, so that they will be JSON equivalent. For example: >>> x = { 'x': 1, 'y': 2 } { 'x': 1, 'y': 2 } >>> `x` "{ 'x': 1, 'y': 2 }" # close but not quite a JSON string >>> `x`.replace("'", '"') '{ "x": 1, "y": 2 }' # JSON and python compatible So the question is, is there an automatic way to tell python to use " instead of ' when doing a repr of lists? Thanks. -- Burton Samograd From nobody at nowhere.com Thu Dec 2 18:12:27 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 02 Dec 2010 23:12:27 +0000 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename References: <1291124813.414884.22.camel@WOPR> Message-ID: On Thu, 02 Dec 2010 12:17:53 +0100, Peter Otten wrote: >> This was actually a critical flaw in Python 3.0, as it meant that >> filenames which weren't valid in the locale's encoding simply couldn't be >> passed via argv or environ. 3.1 fixed this using the "surrogateescape" >> encoding, so now it's only an annoyance (i.e. you can recover the original >> bytes once you've spent enough time digging through the documentation). > > Is it just that you need to harden your scripts against these byte sequences > or do you actually encounter them? If the latter, can you give some > examples? Assume that you have a Python3 script which takes filenames on the command-line. If any of the filenames contain byte sequences which aren't valid in the locale's encoding, the bytes will be decoded to characters in the range U+DC00 to U+DCFF. To recover the original bytes, you need to use 'surrogateescape' as the error handling method when decoding, e.g.: enc = sys.getfilesystemencoding() argv_bytes = [arg.encode(enc, 'surrogateescape') for arg in sys.argv] Otherwise, it will complain about not being able to encode the surrogate characters. Similarly for os.environ. For anything else, you can just use sys.setfilesystemencoding('iso-8859-1') at the beginning of the script. Decoding as ISO-8859-1 will never fail, and encoding as ISO-8859-1 will give you the original bytes. But argv and environ are decoded before your script can change the encoding, so you need to know the "trick" to undo them if you want to write a robust Python 3 script which works with byte strings in an encoding-agnostic manner (i.e. a traditional Unix script). From nobody at nowhere.com Thu Dec 2 18:32:04 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 02 Dec 2010 23:32:04 +0000 Subject: How to send an IP packet in Python? References: <6800bc0a-14f5-4262-ab0b-fb3f175e7a25@y23g2000yqd.googlegroups.com> Message-ID: On Thu, 02 Dec 2010 03:12:42 -0800, yegorov-p wrote: > I have sniffed some packet and now I would like to send it with the > help of python. > But for some reason python send that: > As you can see, python ignores my headers and creates its own. It isn't Python doing that, but the OS. At least on Unix, you need setsockopt(IP_HDRINCL) to tell the OS that the packet includes a header. It appears that Windows supports the same option: http://msdn.microsoft.com/en-us/library/ms738586%28v=VS.85%29.aspx From emile at fenx.com Thu Dec 2 18:33:05 2010 From: emile at fenx.com (Emile van Sebille) Date: Thu, 02 Dec 2010 15:33:05 -0800 Subject: Changing ' to " in printed representation of dictionaries In-Reply-To: References: Message-ID: On 12/2/2010 3:06 PM Burton Samograd said... > Hello, > > I was wondering if there was a way to change the quote character for > keys in string representation of dictionaries, so that they will be JSON > equivalent. For example: > >>>> x = { 'x': 1, 'y': 2 } > { 'x': 1, 'y': 2 } >>>> `x` > "{ 'x': 1, 'y': 2 }" # close but not quite a JSON string >>>> `x`.replace("'", '"') > '{ "x": 1, "y": 2 }' # JSON and python compatible > > So the question is, is there an automatic way to tell python to use " > instead of ' when doing a repr of lists? import json json.dumps(x) Emile From tjreedy at udel.edu Thu Dec 2 18:37:00 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 02 Dec 2010 18:37:00 -0500 Subject: Changing ' to " in printed representation of dictionaries In-Reply-To: References: Message-ID: On 12/2/2010 6:06 PM, Burton Samograd wrote: > Hello, > > I was wondering if there was a way to change the quote character for > keys in string representation of dictionaries, so that they will be JSON > equivalent. For example: > >>>> x = { 'x': 1, 'y': 2 } > { 'x': 1, 'y': 2 } >>>> `x` > "{ 'x': 1, 'y': 2 }" # close but not quite a JSON string >>>> `x`.replace("'", '"') > '{ "x": 1, "y": 2 }' # JSON and python compatible > > So the question is, is there an automatic way to tell python to use " > instead of ' when doing a repr of lists? You meant dicts rather than lists, but the issue is repr of strings. And no, there is no control of that (without subclassing strings). Note that dicts are not limited to string keys, or even keys prepresentable in json. If you want the json representation, when you know it is possible, use the json module! -- Terry Jan Reedy From python at mrabarnett.plus.com Thu Dec 2 18:54:56 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 02 Dec 2010 23:54:56 +0000 Subject: Changing ' to " in printed representation of dictionaries In-Reply-To: References: Message-ID: <4CF831D0.3090805@mrabarnett.plus.com> On 02/12/2010 23:06, Burton Samograd wrote: > Hello, > > I was wondering if there was a way to change the quote character for > keys in string representation of dictionaries, so that they will be JSON > equivalent. For example: > >>>> x = { 'x': 1, 'y': 2 } > { 'x': 1, 'y': 2 } >>>> `x` > "{ 'x': 1, 'y': 2 }" # close but not quite a JSON string >>>> `x`.replace("'", '"') > '{ "x": 1, "y": 2 }' # JSON and python compatible > > So the question is, is there an automatic way to tell python to use " > instead of ' when doing a repr of lists? > Try the "json" module. From lescoutinhovr at gmail.com Thu Dec 2 19:59:19 2010 From: lescoutinhovr at gmail.com (tivrfoa) Date: Thu, 2 Dec 2010 16:59:19 -0800 (PST) Subject: Google AI challenge: planet war. Lisp won. References: <44a8f48f-e291-463e-a042-d0cbc31a2a4e@z17g2000prz.googlegroups.com> Message-ID: On Dec 2, 3:06?pm, Xah Lee wrote: > discovered this rather late. > > Google has a AI Challenge: planet wars.http://ai-contest.com/index.php > > it started sometimes 2 months ago and ended first this month. > > the winner is G?bor Melis, with his code written in lisp. > > Congrats lispers! > > G?bor wrote a blog about it herehttp://quotenil.com/Planet-Wars-Post-Mortem.html > > (not sure if this has been mentioned here but quick search didn't find > it) > > ?Xah ?http://xahlee.org/? this game is very cool and it's hard .. argh http://www.galcon.com/flash/play.php From ozric at web.de Thu Dec 2 20:00:33 2010 From: ozric at web.de (chris) Date: Thu, 2 Dec 2010 17:00:33 -0800 (PST) Subject: aggregation for a nested dict References: <4CF7F840.9060000@mrabarnett.plus.com> Message-ID: I very appreciate all responses. It's incredible how fast it is! Cheers Christian From draeath.spamtrap at gmail.com Thu Dec 2 20:06:58 2010 From: draeath.spamtrap at gmail.com (draeath) Date: Fri, 03 Dec 2010 01:06:58 GMT Subject: three column dataset - additions and deletions References: Message-ID: On Thu, 02 Dec 2010 22:55:53 +0000, Tim Harig wrote: Thanks for taking the time to check in on this, Tim! > So, basically, you want to store a local copy of the data and sync it to > the original. In a way. I only need to store one copy of the data, and make note of changes between it and the current data. > You need to differentiate between the in memory data model and the > storage model. Since this data comes from a database in the first > place, I would dump it to an sqlite3 database from the beginning. You > can use this to store, modify, and change the values as you receive them > from the database. I thought of doing that, but given that I only need to store a single instance of the data, a simple pickle will do the job nicely (am I correct in reading that it can save/load any python object?) > If you are looking for in-memory structures, then you haven't really > provided us with enough information on the significance and organization > of the data. The data columns: Long Int, String (under 30 chars), String (over 100 chars) The rows can scale up to hundreds, perhaps thousands. The integer is the database key, the shorter string is a user name, and the longer string is an access control definition. The whole idea of this script is to check, daily, for any added or removed users - or any altered access control definition. I realize this could likely all be done from inside the database itself - but altering the DB itself is not an option (as the product vendor is very touchy about that, and altering it can null our support agreement) From ian.g.kelly at gmail.com Thu Dec 2 20:11:17 2010 From: ian.g.kelly at gmail.com (Ian) Date: Thu, 2 Dec 2010 17:11:17 -0800 (PST) Subject: Google AI challenge: planet war. Lisp won. References: <44a8f48f-e291-463e-a042-d0cbc31a2a4e@z17g2000prz.googlegroups.com> Message-ID: <83aba984-15a8-485b-b630-7d7456aab080@i41g2000vbn.googlegroups.com> On Dec 2, 5:59?pm, tivrfoa wrote: > On Dec 2, 3:06?pm, Xah Lee wrote: > > > > > discovered this rather late. > > > Google has a AI Challenge: planet wars.http://ai-contest.com/index.php > > > it started sometimes 2 months ago and ended first this month. > > > the winner is G?bor Melis, with his code written in lisp. > > > Congrats lispers! > > > G?bor wrote a blog about it herehttp://quotenil.com/Planet-Wars-Post-Mortem.html > > > (not sure if this has been mentioned here but quick search didn't find > > it) > > > ?Xah ?http://xahlee.org/? > > this game is very cool and it's hard .. arghhttp://www.galcon.com/flash/play.php For what it's worth, I recollect that the original GalCon was written in Python as part of one of the PyWeek competitions. ;-) Cheers, Ian From aahz at pythoncraft.com Thu Dec 2 20:33:47 2010 From: aahz at pythoncraft.com (Aahz) Date: 2 Dec 2010 17:33:47 -0800 Subject: Comparison with False - something I don't understand References: <4CF7B0BB.7080008@tim.thechases.com> Message-ID: In article , Harishankar wrote: > >There are some reasons why I hate exceptions but that is a different >topic. However, in short I can say that personally: > >1. I hate try blocks which add complexity to the code when none is >needed. Try blocks make code much more unreadable in my view and I use it >only for the built-in exceptions when absolutely needed. > >2. I prefer the less irksome True or False to do error checking. >Exceptions seem too heavyweight for simple problems. Please demonstrate that using ``if`` blocks for True/False is impler and cleaner than using ``try`` blocks to handle exceptions. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Think of it as evolution in action." --Tony Rand From usernet at ilthio.net Thu Dec 2 20:42:33 2010 From: usernet at ilthio.net (Tim Harig) Date: Fri, 3 Dec 2010 01:42:33 +0000 (UTC) Subject: three column dataset - additions and deletions References: Message-ID: On 2010-12-03, draeath wrote: > On Thu, 02 Dec 2010 22:55:53 +0000, Tim Harig wrote: > > Thanks for taking the time to check in on this, Tim! > >> So, basically, you want to store a local copy of the data and sync it to >> the original. > In a way. I only need to store one copy of the data, and make note of > changes between it and the current data. Perhaps I am missing a sublty that makes those statements different. >> You need to differentiate between the in memory data model and the >> storage model. Since this data comes from a database in the first >> place, I would dump it to an sqlite3 database from the beginning. You >> can use this to store, modify, and change the values as you receive them >> from the database. > I thought of doing that, but given that I only need to store a single > instance of the data, a simple pickle will do the job nicely (am I > correct in reading that it can save/load any python object?) So, you start by dumping the data from the remote server into an sqlite3 database table. What you end up with is a record=record copy of the original query (plus any other meta data that you want to add). Then, when the data changes, you apply those same changes to your local table (or just regenerate it since you seem to be pulling all of the information from the server anyway. The result is a *single instance of the data*. Why you would want to replace this with a pickle of a nested set up tuples or a homebrew on disk data structure is beyond me. Using sqlite3 is almost certainly faster and more functional then anything you are going to create without some serious work. >> If you are looking for in-memory structures, then you haven't really >> provided us with enough information on the significance and organization >> of the data. > The data columns: > Long Int, String (under 30 chars), String (over 100 chars) > The rows can scale up to hundreds, perhaps thousands. Then those are the columns that you create for your local table. > The integer is the database key, the shorter string is a user name, and > the longer string is an access control definition. The whole idea of this > script is to check, daily, for any added or removed users - or any > altered access control definition. The question is how are you going to use this information once you have mirroed it locally. Most likely, from you description, you just need to access it as a local read only data store. Now compare the differences in how you would acces the data: pickle method: 1. You have to load the entire pickle into memory. 2. Unless you add some kind of tree or indexing mechanism, you will have to walk through an average of 1/2 of the records to find the matching id. If you do use an advanced mechanism you have to create the code that inserts and locates the data. sqlite3 method: 1. You open the file using the sqlite3 connector which does not have to read all of the data into memory. 2. You use a select query to get just the record for the id that you are looking for. sqlite3 has already provided you with optimized lookup and indexing capability, as well as modification operations, etc (most likely written in C). As an added bonus, you don't have to worry about locking issues, to keep the clients from accesses the datastore and receiving an inconsistant copy, while you are making your periodic updates to the database Summary: the pickle method is reinventing the wheel. You can do what has already been done for you with the sqlite3 module (and library) that has already been written for you; but, getting anything near the same functionality is going to require considerable effort on your part; and you are probably going to have to write C to get the equivilant performance. Which seems like a better option to you? > I realize this could likely all be done from inside the database itself - > but altering the DB itself is not an option (as the product vendor is > very touchy about that, and altering it can null our support agreement) Altering the remote database is not an option; but, I am talking about modifying only your local copy. If you can rewrite your pickle file, then you can modify the sqlite3 file. From python at mrabarnett.plus.com Thu Dec 2 21:01:24 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 03 Dec 2010 02:01:24 +0000 Subject: three column dataset - additions and deletions In-Reply-To: References: Message-ID: <4CF84F74.4090807@mrabarnett.plus.com> On 03/12/2010 01:42, Tim Harig wrote: > On 2010-12-03, draeath wrote: >> On Thu, 02 Dec 2010 22:55:53 +0000, Tim Harig wrote: >> >> Thanks for taking the time to check in on this, Tim! >> >>> So, basically, you want to store a local copy of the data and sync it to >>> the original. >> In a way. I only need to store one copy of the data, and make note of >> changes between it and the current data. > > Perhaps I am missing a sublty that makes those statements different. > [snip] I take the difference to be this: The first statement says there are 2 copies, the local one and the original one, with the local one kept in synch with the original one. The second statement says there's 1 copy, plus the changes which have been made to it. From usernet at ilthio.net Thu Dec 2 21:19:54 2010 From: usernet at ilthio.net (Tim Harig) Date: Fri, 3 Dec 2010 02:19:54 +0000 (UTC) Subject: three column dataset - additions and deletions References: Message-ID: On 2010-12-03, MRAB wrote: > On 03/12/2010 01:42, Tim Harig wrote: >> On 2010-12-03, draeath wrote: >>> On Thu, 02 Dec 2010 22:55:53 +0000, Tim Harig wrote: >>> >>> Thanks for taking the time to check in on this, Tim! >>> >>>> So, basically, you want to store a local copy of the data and sync it to >>>> the original. >>> In a way. I only need to store one copy of the data, and make note of >>> changes between it and the current data. >> >> Perhaps I am missing a sublty that makes those statements different. >> > [snip] > I take the difference to be this: > > The first statement says there are 2 copies, the local one and the > original one, with the local one kept in synch with the original one. > > The second statement says there's 1 copy, plus the changes which have > been made to it. Okay, so you keep one local copy of the data pristine with what is on the server, then you want to keep what is effectively a set of local changes from the what is on the server like a patch so that when you want to access the data locally, you can generate return a local copy by applying the patch to the pristine server data. Then you want to be able to pull down and incorporate changes from the server, something like what you would do with "update" on an SCM. The informated is still changed on a record by record basis. Does that sound correct? In that case, I would use the same basic scheme that I suggested before but adding a row in the table to track the changes for each field that might be locally modified. Null would of course mark fields that have not changed. You could store the changes literaly or using some kind of diff style delta that could be applied against the pristine copy. Updating from the server works as before; but, you need to decide what happens if there is a conflict between what changes on the server and local changes. From draeath.spamtrap at gmail.com Thu Dec 2 21:36:45 2010 From: draeath.spamtrap at gmail.com (draeath) Date: Fri, 03 Dec 2010 02:36:45 GMT Subject: three column dataset - additions and deletions References: Message-ID: <1JYJo.114482$ZM.81155@en-nntp-02.dc1.easynews.com> On Fri, 03 Dec 2010 02:19:54 +0000, Tim Harig wrote: > a whole bunch of useful stuff Certainly some good points for me to chew on... thanks! From v.harishankar at gmail.com Thu Dec 2 23:36:50 2010 From: v.harishankar at gmail.com (Harishankar) Date: Fri, 3 Dec 2010 04:36:50 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> <8739qf3mw4.fsf@benfinney.id.au> Message-ID: On Fri, 03 Dec 2010 08:06:35 +1100, Ben Finney wrote: > Raise exceptions for exceptional cases, and define the function > interface so that it's doing one clear job only. Often that involves > breaking a complicated function into several collaborating functions > with simpler interfaces. This is probably what I should try to do. Of course my function returns only a list in most circumstances. Only in error does it return False. I mis-represented the None type for the empty list in my previous post, my apologies. -- Harishankar (http://harishankar.org http://lawstudentscommunity.com) From v.harishankar at gmail.com Thu Dec 2 23:42:21 2010 From: v.harishankar at gmail.com (Harishankar) Date: Fri, 3 Dec 2010 04:42:21 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> Message-ID: On Thu, 02 Dec 2010 16:52:57 +0000, Tim Harig wrote: > If you are having that issue, then you are likely placing the try blocks > at too low of a level in your code. In general you will find that most > systems have a gateway function as an entry point to the system. If > there is not one already, then create such a function in you code. The > parse function in my code above would be an example of such a gateway > function. Beneath that function, you don't need to know exactly where > the error occured, you just need to know the nature of the error and > have general error handling procedures for each kind of error that you > expect might occur. I think I might very well by using try blocks rather defensively rather than letting the code reach its logical conclusion in normal circumstances. This is why I think I find it a bit clunky. I think I understand the general trend of what you're saying. It definitely requires a mindset change. I still feel that user-defined exception classes might not be the way, but maybe I should allow the built-in exceptions which are thrown by library functions to follow its natural path upwards till it reaches the top level where it could be handled. Maybe I should handle the error only at the highest level (UI level) rather than returning False to flag errors. One of the reasons why I feared to do this is because I need to know each and every exception that might be thrown by the function and litter my top-level code with too many exception handlers. -- Harishankar (http://harishankar.org http://lawstudentscommunity.com) From nagle at animats.com Thu Dec 2 23:44:47 2010 From: nagle at animats.com (John Nagle) Date: Thu, 02 Dec 2010 20:44:47 -0800 Subject: To Thread or not to Thread....? In-Reply-To: References: Message-ID: <4cf875df$0$1586$742ec2ed@news.sonic.net> On 12/1/2010 1:24 AM, Antoine Pitrou wrote: > On Wed, 1 Dec 2010 02:45:50 +0000 > Jack Keegan wrote: > >> Hi there, >> >> I'm currently writing an application to control and take measurements during >> an experiments. This is to be done on an embedded computer running XPe so I >> am happy to have python available, although I am pretty new to it. >> The application basically runs as a state machine, which transitions through >> it's states based on inputs read in from a set of general purpose >> input/output (GPIO) lines. So when a certain line is pulled low/high, do >> something and move to another state. All good so far and since I get through >> main loop pretty quickly, I can just do a read of the GPIO lines on each >> pass through the loop and respond accordingly. > >> However, in one of the states I have to start reading in, and storing frames >> from a camera. In another, I have to start reading accelerometer data from >> an I2C bus (which operates at 400kHz). I haven't implemented either yet but >> I would imagine that, in the case of the camera data, reading a frame would >> take a large amount of time as compared to other operations. Therefore, if I >> just tried to read one (or one set of) frames on each pass through the loop >> then I would hold up the rest of the application. Conversely, as the I2C bus >> will need to be read at such a high rate, I may not be able to get the >> required data rate I need even without the camera data. This naturally leads >> me to think I need to use threads. >> As I am no expert in either I2C, cameras, python or threading I thought I >> would chance asking for some advice on the subject. Do you think I need >> threads here or would I be better off using some other method. I was >> previously toying with the idea of using generators to create weightless >> threads (as detailed in >> http://www.ibm.com/developerworks/library/l-pythrd.html) for reading the >> GPIOs. Do you think this would work in this situation? > > The main question IMO: the I2C bus operates at 400kHz, but how much > received data can it buffer? That will give you a hint as to how much > latency you can tolerate. Right. Neither Windows XPe nor Python is designed for hard real time work. Unless your peripheral devices have considerable buffering, don't expect this to work without missing a measurement once in a while. If you have to talk to the I2C interface for each bus transaction before you get another reading, so that you have to respond to the device within 2ms every time, this probably won't work. If you were writing this in C++ on QNX, which is intended for hard real-time work, you could easily meet those time requirements. I've done that, and just reading the devices took maybe 3% of a Pentium 4. Python on Windows XPe, maybe not. You'll need to test. XPe is just XP with some stuff taken out; it's not a real-time OS. A good test is to hook up a square wave generator to some I2C device you can read, and try to read it in real time, measuring the time in microseconds between each pulse. Turn up the frequency until you start missing events. That will give you a handle on how good your real time capabilities are. Note that the machine you're using matters. Some computers have stuff going on in system management mode that results in long interrupt lockout latencies. One option may be to put something like an Arduno on a USB port, and let it talk to the I2C device. See http://www.arduino.cc/playground/Learning/I2C Let it queue up and timestamp the accelerometer data, which can then be read in blocks from the USB port. If both the accelerometer data and video frames are buffered, then you can do your processing in Python without trying to meet hard real-time constraints. This is the usual approach in Windows land. John Nagle From nagle at animats.com Fri Dec 3 00:02:29 2010 From: nagle at animats.com (John Nagle) Date: Thu, 02 Dec 2010 21:02:29 -0800 Subject: three column dataset - additions and deletions In-Reply-To: References: Message-ID: <4cf87a05$0$1625$742ec2ed@news.sonic.net> On 12/2/2010 5:06 PM, draeath wrote: > On Thu, 02 Dec 2010 22:55:53 +0000, Tim Harig wrote: > > Thanks for taking the time to check in on this, Tim! > I realize this could likely all be done from inside the database itself - > but altering the DB itself is not an option (as the product vendor is > very touchy about that, and altering it can null our support agreement) A local database is probably the way to go. You're already using MySQL, so you know how to do that. You can use MySQL or SQlite on a local machine machine for your local database, while also talking to the remote MySQL database. Locally, you probably want to store the key, the short string, the MD5 of the long string, and the long string. When you get an update, put it in a temporary table, then compare that table with your permanent table. (The comparison is one line of SQL.) What you do with the differences is your problem. I have a system running which does something like this. Every three hours, it fetches PhishTank's database of a few hundred thousand phishign sites, and compares it to my local copy. Another system of mine reads the daily updates to SEC filings and updates my local database. This is all routine database stuff. If you have to work with big, persistent data sets, use a real database. That's what they are for, and they already have good algorithms for the hard stuff. Storing some local data structure with "pickle" is probably not the right approach. John Nagle From usernet at ilthio.net Fri Dec 3 00:48:57 2010 From: usernet at ilthio.net (Tim Harig) Date: Fri, 3 Dec 2010 05:48:57 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> Message-ID: On 2010-12-03, Harishankar wrote: > On Thu, 02 Dec 2010 16:52:57 +0000, Tim Harig wrote: > >> If you are having that issue, then you are likely placing the try blocks >> at too low of a level in your code. In general you will find that most >> systems have a gateway function as an entry point to the system. If >> there is not one already, then create such a function in you code. The >> parse function in my code above would be an example of such a gateway >> function. Beneath that function, you don't need to know exactly where >> the error occured, you just need to know the nature of the error and >> have general error handling procedures for each kind of error that you >> expect might occur. > > I think I might very well by using try blocks rather defensively rather > than letting the code reach its logical conclusion in normal > circumstances. This is why I think I find it a bit clunky. That was the conclusion I was coming to. > I think I understand the general trend of what you're saying. It > definitely requires a mindset change. I still feel that user-defined > exception classes might not be the way, but maybe I should allow the > built-in exceptions which are thrown by library functions to follow its > natural path upwards till it reaches the top level where it could be > handled. Look at it this way, in C you were constrained to place your error handling code around ever function that might fail. Now you are free to place the error handling code wherever it makes sense to do so. As a general rule, if, in C, your function would handle the error by passing an error return value to the calling function, then the error handling code should be higher up. > Maybe I should handle the error only at the highest level (UI level) > rather than returning False to flag errors. I don't write many UIs; but, I normally consider the UI code to be yet another subsystem. In general, I find the best place to place error handling code in the high level business logic of your application (which might be what you actually meant by UI, to me the UI code is the code that actually draws the interface), in the high level logic of the systems, and in the bounderies between subsystems. The exceptions caught at each level depend on where the logic to handle the error is best applied. > One of the reasons why I feared to do this is because I need to know each > and every exception that might be thrown by the function and litter my > top-level code with too many exception handlers. Each exception has a place where it is better handled. Wherever you find boundaries between subsystems, think about what error conditions that subsystem might encounter. Subsystems dealing with are likely to encounter io related errors, network subsystems network errors, parsers validation errors etc. Logic exceptions that indicate errors in your code should be left alone entirely so that they may be easily found. Look at the exceptions pertaining to these subsystems. For each error reaching the boundery, think about whether you have enough information within the module to handle the error in a constructive manner or whether the error handling would benefit from information further up in the program. If you have all of the information that you need then handle it in the main logic of that subsystem. If not, pass it up to the error handlers on top of the boundry. When you get there, make the same decision. In general you only need to catch a handful of exceptions at each level. The easy excpetions will be handled at lower levels. The most difficult exceptions will rise towards the top of the program until only the terminal exceptions, that cannot be resolved are left with the inevitable result that you should notify the user and exit, will remain. From steve+comp.lang.python at pearwood.info Fri Dec 3 01:46:22 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Dec 2010 06:46:22 GMT Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> On Thu, 02 Dec 2010 16:35:08 +0000, Mark Wooding wrote: >> 3. Philosophically I think exception handling is the wrong approach to >> error management. > > There are better ways to handle errors than Python's exception system. I'm curious -- what ways would they be? I'm aware of three general exception handling techniques: 1. return a sentinel value or error code to indicate an exceptional case (e.g. str.find returns -1); 2. raise an exception (e.g. nearly everything else in Python); 3. set an error code somewhere (often a global variable) and hope the caller remembers to check it; plus some de facto techniques sadly in common use: 4. dump core; 5. do nothing and produce garbage output. What else is there? -- Steven From draeath.spamtrap at gmail.com Fri Dec 3 02:15:45 2010 From: draeath.spamtrap at gmail.com (draeath) Date: Fri, 03 Dec 2010 07:15:45 GMT Subject: three column dataset - additions and deletions References: Message-ID: The only reason I want the hash is that I don't want a copy of this string laying around. I also don't need to know what it is, I just need to know if it's different. Think of this as a tripwire - if someone's user access level is changed, we find out. I still think using a separate database (sqlite or not) is entirely unnecessary. The task simply isn't large enough of a scale to justify going to that extreme. That's like cutting a string with a chainsaw. Granted, the next time I'm at my workstation I'll just give it a go and just stick with whatever turns out "best" The alternatives are what I was looking for, and you all did provide them :) So here's the goal, since it seems it's still unclear: Cron will call my script on an interval (probably once a day... so yea). The script will determine if users were added, removed, or changed. If so, an email will be constructed with generic details "users bjoe, jdoe created; user mwallace deleted; user psouter access level changed" and sent to the MUA/MTA/whatever for delivery to myself and the other admins. From no.email at nospam.invalid Fri Dec 3 02:25:15 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 02 Dec 2010 23:25:15 -0800 Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7xsjyfl3ms.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: >> There are better ways to handle errors than Python's exception system. > I'm curious -- what ways would they be? > I'm aware of three general exception handling techniques: ... > What else is there? The Erlang approach is to chop the application into a lot of very lightweight processes, and let any process that encounters an error simply crash. A monitoring process notices the crashed process and restarts it. There is a "supervision tree" of uber-monitor processes that restart crashed monitor proceses. I haven't programmed in that style myself and I'm not persuaded that it's better than what Python does, but I think it's different from the stuff on your list, which is an answer to your "what else is there". I do know that they write some complex, very high reliability systems (phone switches) in Erlang. From usernet at ilthio.net Fri Dec 3 03:43:18 2010 From: usernet at ilthio.net (Tim Harig) Date: Fri, 3 Dec 2010 08:43:18 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> <7xsjyfl3ms.fsf@ruckus.brouhaha.com> Message-ID: On 2010-12-03, Paul Rubin wrote: > Steven D'Aprano writes: >>> There are better ways to handle errors than Python's exception system. >> I'm curious -- what ways would they be? >> I'm aware of three general exception handling techniques: ... >> What else is there? > > The Erlang approach is to chop the application into a lot of very > lightweight processes, and let any process that encounters an error > simply crash. A monitoring process notices the crashed process and > restarts it. There is a "supervision tree" of uber-monitor processes > that restart crashed monitor proceses. I haven't programmed in that > style myself and I'm not persuaded that it's better than what Python > does, but I think it's different from the stuff on your list, which is Erlang also offers an exception syntax almost identical to Python's for use within a single process. What makes Erlang's supervisor mode of error handling superior is that it works for more then just the current vm. If a process throws an exception, the supervisor catches and handles it. If a vm dies, a supervisor from another vm takes over. If an entire computer dies, a supervisor on another computer takes over. OTP provides some extremely advanced support for supervisory structures. > an answer to your "what else is there". I do know that they write some > complex, very high reliability systems (phone switches) in Erlang. Erlang isn't what I would call a very general purpose programming language like Python; but, if you want to build highly scalable and/or highly available systemes, there really isn't anything else that comes close to it. I am not really a huge fan of the purely functional nature of the language; but, light weight processes using the actor model is the way to go for concurrent processing. The BEAM virtual machine is also a powerful system with its ability to patch systems on the fly. It has start to become the target for other languages. I know of two that are in current developement. I wouldn't mind seeing a version of Python that could leverage the power of the BEAM vm. From mwilson at the-wire.com Fri Dec 3 04:10:24 2010 From: mwilson at the-wire.com (Mel) Date: Fri, 03 Dec 2010 04:10:24 -0500 Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> Message-ID: Harishankar wrote: > I think I understand the general trend of what you're saying. It > definitely requires a mindset change. I still feel that user-defined > exception classes might not be the way, but maybe I should allow the > built-in exceptions which are thrown by library functions to follow its > natural path upwards till it reaches the top level where it could be > handled. User-defined exception classes are no big deal, and I think they're helpful. At the minimum, they're just a few lines in a module, e.g.: class SumpError (StandardError): '''Errors raised by the SUMP client.''' class SumpIdError (SumpError): '''The wrong string was returned by an ID request.''' class SumpFlagsError (SumpError): '''Illegal combination of flags.''' class SumpStageError (SumpError): '''Illegal trigger stage setting.''' This is from a module to drive some special hardware through a serial connection. At this stage in development, I don't even have try/except statements for these. It's enough that some typo will not silently put the hardware into an illegal state, and instead will report Traceback (most recent call last): File "logic_sniffer.py", line 184, in OnDeviceCapture set_sump_options (grabber) File "logic_sniffer.py", line 21, in set_sump_options sump.set_flags (demux=True, filter=True, channel_groups=0x0, external=False, inverted=False) # only 1 channel group File "/home/mwilson/sandbox/sump-analyzer/sump.py", line 160, in set_flags raise SumpFlagsError sump.SumpFlagsError Because these are subclasses of StandardError, they'll be caught by any `except StandardError`, which may or may not turn out to be a mistake. Once development is done, try/except for these will be in some window methods as part of a wxPython GUI, several call levels above the code that would raise the exceptions, up where a human user would take steps to change the way things are being done, or submit a bug report (more likely), or something. > Maybe I should handle the error only at the highest level (UI level) > rather than returning False to flag errors. > > One of the reasons why I feared to do this is because I need to know each > and every exception that might be thrown by the function and litter my > top-level code with too many exception handlers. The advantage to the exceptions, is that they only need to be recognized and caught and handled at the UI level. They don't have to be recognized and passed back up the call chain from level to level till they get to the right place -- the way out-of-band error returns have to be. Mel. From steve+comp.lang.python at pearwood.info Fri Dec 3 08:04:26 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Dec 2010 13:04:26 GMT Subject: Exception handling in Python 3.x Message-ID: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> Consider the following common exception handling idiom: def func(iterable): it = iter(iterable) try: x = next(it) except StopIteration: raise ValueError("can't process empty iterable") print(x) The intention is: * detect an empty iterator by catching StopIteration; * if the iterator is empty, raise a ValueError; * otherwise process the iterator. Note that StopIteration is an internal detail of no relevance whatsoever to the caller. Expose this is unnecessary at best and confusing at worst. In Python 2.6 this idiom works as intended: >>> func([]) Traceback (most recent call last): File "", line 1, in File "", line 6, in func ValueError: can't process empty iterable There is no sign of the StopIteration, and nor should there be. But Python 3.1 changes this behaviour, exposing the unimportant StopIteration and leading to a more complicated and confusing traceback: >>> func([]) Traceback (most recent call last): File "", line 4, in func StopIteration During handling of the above exception, another exception occurred: Traceback (most recent call last): File "", line 1, in File "", line 6, in func ValueError: can't process empty iterable I understand the rational of this approach -- it is to assist in debugging code where the except block is buggy and raises an error. But a deliberate and explicit call to raise is not a buggy except block. It is terribly inappropriate for the common use-case of catching one exception and substituting another. I note that the PEP explicitly notes this use-case, but merely sweeps it under the carpet: Open Issue: Suppressing Context As written, this PEP makes it impossible to suppress '__context__', since setting exc.__context__ to None in an 'except' or 'finally' clause will only result in it being set again when exc is raised. http://www.python.org/dev/peps/pep-3134/ Apart from this horrible idiom: def func(iterable): it = iter(iterable) failed = False try: x = next(it) except StopIteration: failed = True if failed: raise ValueError("can't process empty iterable") print(x) or similar, is there really no way to avoid these chained exceptions? -- Steven From javiervandam at gmail.com Fri Dec 3 08:12:29 2010 From: javiervandam at gmail.com (javivd) Date: Fri, 3 Dec 2010 05:12:29 -0800 (PST) Subject: Reading by positions plain text files References: <39a07597-02b9-4ef8-9ca9-93e2d2425e66@p7g2000prb.googlegroups.com> Message-ID: On Dec 1, 3:15?am, Tim Harig wrote: > On 2010-12-01, javivd wrote: > > > > > On Nov 30, 11:43?pm, Tim Harig wrote: > >> On 2010-11-30, javivd wrote: > > >> > I have a case now in wich another file has been provided (besides the > >> > database) that tells me in wich column of the file is every variable, > >> > because there isn't any blank or tab character that separates the > >> > variables, they are stick together. This second file specify the > >> > variable name and his position: > > >> > VARIABLE NAME ? ? ?POSITION (COLUMN) IN FILE > >> > var_name_1 ? ? ? ? ? ? ? ? 123-123 > >> > var_name_2 ? ? ? ? ? ? ? ? 124-125 > >> > var_name_3 ? ? ? ? ? ? ? ? 126-126 > >> > .. > >> > .. > >> > var_name_N ? ? ? ? ? ? ? ? 512-513 (last positions) > > >> I am unclear on the format of these positions. ?They do not look like > >> what I would expect from absolute references in the data. ?For instance, > >> 123-123 may only contain one byte??? which could change for different > >> encodings and how you mark line endings. ?Frankly, the use of the > >> world columns in the header suggests that the data *is* separated by > >> line endings rather then absolute position and the position refers to > >> the line number. In which case, you can use splitlines() to break up > >> the data and then address the proper line by index. ?Nevertheless, > >> you can use file.seek() to move to an absolute offset in the file, > >> if that really is what you are looking for. > > > I work in a survey research firm. the data im talking about has a lot > > of 0-1 variables, meaning yes or no of a lot of questions. so only one > > position of a character is needed (not byte), explaining the 123-123 > > kind of positions of a lot of variables. > > Then file.seek() is what you are looking for; but, you need to be aware of > line endings and encodings as indicated. ?Make sure that you open the file > using whatever encoding was used when it was generated or you could have > problems with multibyte characters affecting the offsets. Ok, I will try it and let you know. Thanks all!! From jeanmichel at sequans.com Fri Dec 3 08:44:40 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 03 Dec 2010 14:44:40 +0100 Subject: is id(self) constant over an object lifetime ? Message-ID: <4CF8F448.4030008@sequans.com> Hello fellows, I would need a unique internal identifier to an object. Can I use the object python id ? class Foo: def getUniqueIdentifier(): return id(self) This id needs to be unique and constant over the python process lifetime. JM From jeanmichel at sequans.com Fri Dec 3 08:47:48 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 03 Dec 2010 14:47:48 +0100 Subject: is id(self) constant over an object lifetime ? In-Reply-To: <4CF8F448.4030008@sequans.com> References: <4CF8F448.4030008@sequans.com> Message-ID: <4CF8F504.2000803@sequans.com> Jean-Michel Pichavant wrote: > Hello fellows, > > I would need a unique internal identifier to an object. Can I use the > object python id ? > > class Foo: > def getUniqueIdentifier(): > return id(self) > > > This id needs to be unique and constant over the python process lifetime. > > JM > erratum python process lifetime => object lifetime From sn at sncs.se Fri Dec 3 08:50:40 2010 From: sn at sncs.se (Sverker Nilsson) Date: Fri, 3 Dec 2010 05:50:40 -0800 (PST) Subject: Python assignments Message-ID: Dear friends, This is Sverker from Sweden. You probably know me better as the guy who made Guppy/Heapy: http://guppy-pe.sf.net I am currently in the process of preparing version 0.1.10 with support for Python 2.7. I will let you know when it is updated. For those who don?t know, I work as a consultant and I am looking for new assignments and I really wish to work with Heapy/Python instead of regular programming in eg Java or C++. Therefore I was wondering if any of you know any companies in the States or anywhere else that need my services. Further information about who I am and what I can do you can find on my website: http://sncs.se I appreciate all advice and information you can provide me with. So long my friends, Sverker From awilliam at whitemice.org Fri Dec 3 08:52:20 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Fri, 03 Dec 2010 08:52:20 -0500 Subject: is id(self) constant over an object lifetime ? In-Reply-To: <4CF8F448.4030008@sequans.com> References: <4CF8F448.4030008@sequans.com> Message-ID: <1291384340.3790.16.camel@linux-yu4c.site> On Fri, 2010-12-03 at 14:44 +0100, Jean-Michel Pichavant wrote: > Hello fellows, > I would need a unique internal identifier to an object. Can I use the > object python id ? > class Foo: > def getUniqueIdentifier(): > return id(self) > This id needs to be unique and constant over the python process lifetime. Return the ?identity? of an object. This is an integer (or long integer) which is guaranteed to be unique and constant for this object during its lifetime. Two objects with non-overlapping lifetimes may have the same id() value. Of course, "lifetime" is an interesting concept. If an object is serializable then this id cannot be used as an idempotent value. Personally I would never use this; if an object needs an idempotent value - create one. "import uuid" From jeanmichel at sequans.com Fri Dec 3 08:53:38 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 03 Dec 2010 14:53:38 +0100 Subject: is id(self) constant over an object lifetime ? In-Reply-To: <4CF8F448.4030008@sequans.com> References: <4CF8F448.4030008@sequans.com> Message-ID: <4CF8F662.7050603@sequans.com> Jean-Michel Pichavant wrote: > Hello fellows, > > I would need a unique internal identifier to an object. Can I use the > object python id ? > > class Foo: > def getUniqueIdentifier(): > return id(self) > > > This id needs to be unique and constant over the python process lifetime. > > JM > sorry guys " id(/object/)? Return the ?identity? of an object. This is an integer (or long integer) which is guaranteed to be unique and constant for this object during its lifetime. Two objects with non-overlapping lifetimes may have the same id() value. " Next time I promise to look at the doc before actually asking the question here :) JM From dobedani at gmx.net Fri Dec 3 09:03:41 2010 From: dobedani at gmx.net (Dobedani) Date: Fri, 3 Dec 2010 06:03:41 -0800 (PST) Subject: New to Jython - how to install setuptools? Message-ID: Hi folks, I'm new to Jython - not to Python. The good thing about Python is that there are many packages available which can be installed easily by means of setuptools. Today I installed Jython, because I'm thinking of integrating some Python code into a web application which will be hosted on a web server with Tomcat behind it plus Jython. I found this webpage and followed the instructions about installing setuptools: http://www.jython.org/jythonbook/en/1.0/appendixA.html Unfortunately, it did not work for me. These are the errors I got: C:\TEMP\jython>java -jar D:\usr\lib\jython25\jython.jar ez_setup.py Downloading http://pypi.python.org/packages/2.5/s/setuptools/setuptools-0.6c11-py2.5.egg Traceback (most recent call last): File "ez_setup.py", line 278, in main(sys.argv[1:]) File "ez_setup.py", line 212, in main from setuptools.command.easy_install import main File "C:\TEMP\jython\setuptools-0.6c11-py2.5.egg\setuptools \__init__.py", line 2, in File "C:\TEMP\jython\setuptools-0.6c11-py2.5.egg\setuptools \extension.py", line 2, in File "C:\TEMP\jython\setuptools-0.6c11-py2.5.egg\setuptools \dist.py", line 5, in File "C:\TEMP\jython\setuptools-0.6c11-py2.5.egg\setuptools\command \install.py", line 2, in File "D:\usr\lib\jython25\Lib\distutils\command\install.py", line 15, in from distutils.sysconfig import get_config_vars File "D:\usr\lib\jython25\Lib\distutils\sysconfig.py", line 29, in argv0_path = os.path.dirname(os.path.abspath(sys.executable)) File "D:\usr\lib\jython25\Lib\ntpath.py", line 492, in abspath if not isabs(path): File "D:\usr\lib\jython25\Lib\ntpath.py", line 55, in isabs s = splitdrive(s)[1] File "D:\usr\lib\jython25\Lib\ntpath.py", line 121, in splitdrive if p[1:2] == ':': TypeError: 'NoneType' object is unsubscriptable I'm suspecting the installation failed because I did not apply certain settings, but I don't even know how to go about that! Any help will be appreciated. As you'll understand I'm using Windows XP ;-) Kind regards ... From jeanmichel at sequans.com Fri Dec 3 09:04:47 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 03 Dec 2010 15:04:47 +0100 Subject: is id(self) constant over an object lifetime ? In-Reply-To: <1291384340.3790.16.camel@linux-yu4c.site> References: <4CF8F448.4030008@sequans.com> <1291384340.3790.16.camel@linux-yu4c.site> Message-ID: <4CF8F8FF.3010901@sequans.com> Adam Tauno Williams wrote: > On Fri, 2010-12-03 at 14:44 +0100, Jean-Michel Pichavant wrote: > >> Hello fellows, >> I would need a unique internal identifier to an object. Can I use the >> object python id ? >> class Foo: >> def getUniqueIdentifier(): >> return id(self) >> This id needs to be unique and constant over the python process lifetime. >> > > > > > Return the ?identity? of an object. This is an integer (or long integer) > which is guaranteed to be unique and constant for this object during its > lifetime. Two objects with non-overlapping lifetimes may have the same > id() value. > > > Of course, "lifetime" is an interesting concept. If an object is > serializable then this id cannot be used as an idempotent value. > > Personally I would never use this; if an object needs an idempotent > value - create one. "import uuid" > > Yep I saw that on the doc sorry for asking here before checking it. Anyway your uuid is an awesome suggestion. However since I'll need to send the id over xmlrpc, it needs to be marshallable, so I would need to send uuid1().hex, or something liek that. JM From hniksic at xemacs.org Fri Dec 3 09:15:46 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Fri, 03 Dec 2010 15:15:46 +0100 Subject: Exception handling in Python 3.x References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87sjyfx7ql.fsf@xemacs.org> Steven D'Aprano writes: > Consider the following common exception handling idiom: > > def func(iterable): > it = iter(iterable) > try: > x = next(it) > except StopIteration: > raise ValueError("can't process empty iterable") > print(x) Not exactly what you're looking for, but another way to express the above is: def func(iterable): for x in iterable: break else: raise ValueError("can't process empty iterable") print(x) Otherwise, I completely agree that being unable to completely replace the original exception is an annoyance at best. From data.2 at rediff.com Fri Dec 3 09:31:07 2010 From: data.2 at rediff.com (gaurav) Date: Fri, 3 Dec 2010 06:31:07 -0800 (PST) Subject: Great chance for Management work. Message-ID: <8828a40e-4a0c-4495-9429-eb56066b8896@y19g2000prb.googlegroups.com> Best site for management careers. Career in Management. http://jobscore.webs.com/executivemanager.htm http://topcareer.webs.com/businessmanagement.htm Chances for banking career listing to all over cites person can get work as bank employee. http://rojgars1.webs.com/gov.htm http://printmediajobs.webs.com/fl.htm From mdw at distorted.org.uk Fri Dec 3 09:31:43 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 03 Dec 2010 14:31:43 +0000 Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > On Thu, 02 Dec 2010 16:35:08 +0000, Mark Wooding wrote: > > There are better ways to handle errors than Python's exception system. > > I'm curious -- what ways would they be? The most obvious improvement is resumable exceptions. In general, recovering from an exceptional condition requires three activities: * doing something about the condition so that the program can continue running; * identifying some way of rejoining the program's main (unexceptional) flow of control; and * actually performing that transfer, ensuring that any necessary invariants are restored. Python's `try ... finally' helps with the last; but Python intertwines the first two, implementing both with `try ... except'. The most important consequence of this is that the logic which contains knowledge about how to fix the condition must be closer to the code that encountered the condition than the resume point is. It's therefore hard to factor out high-level policy about fixing conditions from the relatively tedious business of providing safe points at which to resume main execution. (Effectively, each section of your program which wants to avail itself of some high-level condition-fixing policy has to provide its own protocol for expressing and implementing them.) Phew. That was abstract. Can I come up with some examples? I've been writing a (sort of) compiler recently. When it encounters errors, it reports a message to the user containing the position it had reached in the source, updates a counter so that it can report a summary at the end of the run and produce a sensible exit status, and then attempts to carry on compiling as best it can. The last bit -- attempting to carry on as best it can -- needs local knowledge of what the compiler's doing and what actually went wrong. If the parser expected to find a delimiter, maybe it should pretend that it found one, for example. The other stuff, printing messages, updating counters, and so on, is all done with some condition handlers wrapped around the meat of the compiler. That's written only once. Everything that signals errors, including standard I/O functions like open-a-file, gets the same treatment. (The remaining missing ingredient is a fluid variable which tracks the current position in the source and is updated by the scanner; bits of the compiler's semantic analysis machinery will temporarily focus attention on other parts of the source using locations they saved during the parse. Implementing fluids in Python can be done with a context manager: if you don't care about concurrency then you can use simple variables; otherwise it's little fiddly and the syntax isn't very comfortable, but it's still possible.) A more familiar example, maybe, is the good old DOS `abort/retry/fail' query. Implementing such a thing in Python, as a general policy for handling I/O errors, isn't possible. Viewed narrowly, this is probably a good thing: the old DOS query was very annoying. But the difficulty of implementing this policy illustrates the missing functionality. And, of course, if DOS had a proper resumable exception system, programs could have overridden the annoying query. In general, the code which discovers an exceptional condition may have several options for how to resume. It might be possible to ignore the situation entirely and carry on regardless (`false alarm!'). It might be possible to try again (`transient failure'). Alas, the logic which is capable of implementing these options is usually too low-level and too close to the action to be able to decide among them sensibly. (Maybe a human user should be consulted -- but that can drag in user interface baggage into a low-level networking library or whatever.) Resumable exceptions provide a way out of this mess by separating the mechanics of resumption from policy of which resumption option to choose. It's easy to show that a resumable exception system can do everything that a nonresumable system (like Python's) can do (simply put all of the recovery logic at the resume point); but the converse is not true. There are some other fringe benefits to resumable exceptions. * It's usual to report a stack backtrace or similar if an exception occurs but nothing manages to resume execution. If unwinding the stack is intertwined with working out how to resume execution, then whenever you /try/ to run an applicable handler, you have to reify the stack context and stash it somewhere in case the handler doesn't complete the job. This makes raising exceptions more expensive than they need to be. * You can use the same mechanism for other kinds of communication with surrounding context. For example, Python occasionally emits `warnings', which have their own rather simple management system (using global state, so it's hard to say `don't issue MumbleWarnings while we frob the widgets' in a concurrent program). A resumable exceptions system could easily integrate warnings fully with other kinds of conditions (and avoid the concurrency problems). You could also use it for reporting progress indications, for example. Of course, there's a downside. Resumable exceptions aren't the usual kind, so people aren't used to them. I'm not sure whether resumable exceptions are actually more complicated to understand: there are more named concepts involved, but they do less and their various roles are clearer and less tangled. (The `handler' for an exceptional condition can be called just like a function. Python doesn't have nonlocal flow control distinct from its exception system, but a nonlocal transfer to a resumption point isn't conceptually very complicated.) > 1. return a sentinel value or error code to indicate an exceptional case > (e.g. str.find returns -1); This works fine if you consider failure as being unexceptional. If you're not actually expecting to find that substring, and have something sensible to do if it wasn't there, a report that it wasn't there isn't really exceptional. (I think I use str.find more frequently than str.index, so it's nice that there are both.) > 2. raise an exception (e.g. nearly everything else in Python); Raising exceptions is a more complicated business than this suggests. Python made some specific design decisions regarding its exception system; they're pretty common choices, but not, I think, the best ones. > 3. set an error code somewhere (often a global variable) and hope the > caller remembers to check it; That's less common than you might think. Usually there's some sentinel value to tell you to look at the global error code. (Obvious examples where there isn't a clear sentinel: strtol and friends, math.h.) I think we can agree that this sucks. Someone else mentioned Erlang. An Erlang system is structured as a collection of `processes' (they don't have any shared state, so they aren't really `threads') which communicate by sending messages to each other. If an Erlang process encounters a problem, it dies, and a message is sent to report its demise. Erlang processes are very cheap, it's not unusual for a system to have tens of thousands of them. > plus some de facto techniques sadly in common use: > > 4. dump core; > > 5. do nothing and produce garbage output. > > What else is there? You missed `6. assume that erroneous input is actually executable code and transfer control to it', which is a popular approach in C. -- [mdw] From __peter__ at web.de Fri Dec 3 09:42:33 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 03 Dec 2010 15:42:33 +0100 Subject: Exception handling in Python 3.x References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Consider the following common exception handling idiom: > > def func(iterable): > it = iter(iterable) > try: > x = next(it) > except StopIteration: > raise ValueError("can't process empty iterable") > print(x) > > The intention is: > > * detect an empty iterator by catching StopIteration; > * if the iterator is empty, raise a ValueError; > * otherwise process the iterator. > > Note that StopIteration is an internal detail of no relevance whatsoever > to the caller. Expose this is unnecessary at best and confusing at worst. http://mail.python.org/pipermail/python-list/2010-October/1258606.html http://mail.python.org/pipermail/python-list/2010-October/1259024.html From namekuseijin at gmail.com Fri Dec 3 09:51:44 2010 From: namekuseijin at gmail.com (namekuseijin) Date: Fri, 3 Dec 2010 06:51:44 -0800 (PST) Subject: Google AI challenge: planet war. Lisp won. References: <44a8f48f-e291-463e-a042-d0cbc31a2a4e@z17g2000prz.googlegroups.com> Message-ID: On 2 dez, 15:06, Xah Lee wrote: > discovered this rather late. > > Google has a AI Challenge: planet wars.http://ai-contest.com/index.php > > it started sometimes 2 months ago and ended first this month. > > the winner is G?bor Melis, with his code written in lisp. > > Congrats lispers! > > G?bor wrote a blog about it herehttp://quotenil.com/Planet-Wars-Post-Mortem.html > > (not sure if this has been mentioned here but quick search didn't find > it) > > ?Xah ?http://xahlee.org/? definitely cool! From lists at cheimes.de Fri Dec 3 09:58:05 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 03 Dec 2010 15:58:05 +0100 Subject: is id(self) constant over an object lifetime ? In-Reply-To: <4CF8F662.7050603@sequans.com> References: <4CF8F448.4030008@sequans.com> <4CF8F662.7050603@sequans.com> Message-ID: Am 03.12.2010 14:53, schrieb Jean-Michel Pichavant: > Next time I promise to look at the doc before actually asking the > question here :) You are misinterpreting the excerpt. You are right that the id of an object doesn't change during the lifetime of a Python process and as long as it stays inside a single process. However if you use some sort of persistence layer like pickles or an IPC mechanism like multiprocessing the id is definitely not constant. If you need something stable, I suggest you look at the uuid module. Christian From pasxal.antix at gmail.com Fri Dec 3 10:16:49 2010 From: pasxal.antix at gmail.com (Kechagias Apostolos) Date: Fri, 3 Dec 2010 17:16:49 +0200 Subject: Using python for web IM? Message-ID: Hello, We are currently working on a project which needs video and audio streaming(peer to peer). We need to know if there are any available open source libraries to embed video,audio,p2p transfer in our client OR if there is any available framework which could help us with our project. It would bereally helpful if you could also provide us some feedback on what we can use as XMPP server. -------------- next part -------------- An HTML attachment was scrubbed... URL: From hniksic at xemacs.org Fri Dec 3 10:26:19 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Fri, 03 Dec 2010 16:26:19 +0100 Subject: Exception handling in Python 3.x References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87hbeuyj1g.fsf@xemacs.org> Peter Otten <__peter__ at web.de> writes: >> Note that StopIteration is an internal detail of no relevance whatsoever >> to the caller. Expose this is unnecessary at best and confusing at worst. > > http://mail.python.org/pipermail/python-list/2010-October/1258606.html > http://mail.python.org/pipermail/python-list/2010-October/1259024.html Both of these involve suppressing the chaining at the wrong place, namely in the outer handler or, worse yet, in the exception display mechanism. Steven, on the other hand, wants his *inner* handler to express that the original exception was an implementation detail, a business exception such as StopIteration, that is completely irrelevant to the actual exception being raised. The outer handler is the wrong place to suppress the chaining because it has no way of distinguishing Steven's case from a genuine case of a new exception unexpectedly occurring during handling of the original exception. One solution would be for "raise" inside except to not use the context. For example: try: {}[1] except KeyError: 1/0 would behave as before, but: But: try: {}[1] except KeyError: raise Exception("my error") ...would raise the custom error forgetting the KeyError. From deets at web.de Fri Dec 3 11:05:20 2010 From: deets at web.de (Diez B. Roggisch) Date: Fri, 03 Dec 2010 17:05:20 +0100 Subject: position independent build of python References: Message-ID: erikj writes: > If my understanding is correct, the sys.prefix variable holds the root > directory python uses to find related files, and eg its site-packages. > > the value of sys.prefix is specified at compile time. > > it seems that on windows, when I build/install python at one location, > and > later move it to another location, python will find all its needs > relative to the new location. > > however, when I do the same on linux, python keeps looking for > its dependencies in the build location. > > is there a possibility to have it always look at a position relative > to the location of the executable ? the goal is to be able to build > python on one machine, and then simply copy the build tree to > other machines at other locations. Maybe looking at virtualenv, especially with the --no-site-packages variable set gives you a hint. AFAIK there are some hard-coded paths involved, but not inside compiled code. Maybe you can remedy that somehow. Diez From __peter__ at web.de Fri Dec 3 11:08:38 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 03 Dec 2010 17:08:38 +0100 Subject: Exception handling in Python 3.x References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> <87hbeuyj1g.fsf@xemacs.org> Message-ID: Hrvoje Niksic wrote: > Peter Otten <__peter__ at web.de> writes: > >>> Note that StopIteration is an internal detail of no relevance whatsoever >>> to the caller. Expose this is unnecessary at best and confusing at >>> worst. >> >> http://mail.python.org/pipermail/python-list/2010-October/1258606.html >> http://mail.python.org/pipermail/python-list/2010-October/1259024.html > > Both of these involve suppressing the chaining at the wrong place, > namely in the outer handler or, worse yet, in the exception display > mechanism. Steven, on the other hand, wants his *inner* handler to > express that the original exception was an implementation detail, a > business exception such as StopIteration, that is completely irrelevant > to the actual exception being raised. The outer handler is the wrong > place to suppress the chaining because it has no way of distinguishing > Steven's case from a genuine case of a new exception unexpectedly > occurring during handling of the original exception. To quote the Rolling Stones: You can't always get what you want. After rereading the original post I still don't get why the workarounds provided in those links aren't worth considering. Peter From prog at vtr.net Fri Dec 3 12:04:27 2010 From: prog at vtr.net (craf) Date: Fri, 03 Dec 2010 14:04:27 -0300 Subject: Using a window style in a Toplevel window Message-ID: <1291395867.4604.13.camel@cristian-desktop> Hi. I use Python 3.1 and Tkinter.ttk 8.5 on Ubuntu 9.10. CODE:---------------------------------------------------- module:FMain.py from tkinter import ttk from FSecondWindow import * class App: def __init__(self,master): button1 = ttk.Button(master,text='Show TopLevel',command=lambda:window()) button1.pack() master = Tk() app = App(master) style = ttk.Style() style.theme_use('clam') master.mainloop() module:FSecondWindow.py from tkinter import * from tkinter import ttk def window(): t = Toplevel() button2 = Button(t,text='Hello').pack() CODE EXPLANATION:------------------------------------------- 1. From the main module FMain.py call the window function that is located in FSecondWindow module and create a toplevel window. 2.I apply a theme called 'clam' to the master window to improve the appearance of their widgets. QUERY:-------------------------------------------------- How I can make the toplevel window also take the theme 'clam'? Thanks in advance. Regards. Cristian Abarz?a. From v.harishankar at gmail.com Fri Dec 3 12:16:58 2010 From: v.harishankar at gmail.com (Harishankar) Date: Fri, 3 Dec 2010 17:16:58 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On Fri, 03 Dec 2010 14:31:43 +0000, Mark Wooding wrote: > The most obvious improvement is resumable exceptions. This is probably what I had in mind but I just couldn't explain it the way you did below. > > In general, recovering from an exceptional condition requires three > activities: > > * doing something about the condition so that the program can continue > running; > > * identifying some way of rejoining the program's main (unexceptional) > flow of control; and > > * actually performing that transfer, ensuring that any necessary > invariants are restored. This really sums up my thoughts about exceptions better than I could have explained! I just felt instinctively that I had missed something, but it appears to be a break in logic of the code somewhere which I thought was my fault. Seems that exception handling requires a lot of forethought since the control of program execution breaks at the point of exception with no obvious way to rejoin it seamlessly whereas with an error, a simple if condition could handle the error state and resume execution from that point forward. This is the main reason why I think I used simple error codes to handle certain recoverable conditions and avoided exceptions. I quite enjoyed your post. Thank you for explaining a lot of issues which I probably could not have figured out on my own. -- Harishankar (http://harishankar.org http://lawstudentscommunity.com) From noydb00 at gmail.com Fri Dec 3 12:21:52 2010 From: noydb00 at gmail.com (noydb) Date: Fri, 3 Dec 2010 09:21:52 -0800 (PST) Subject: How to add data into exisitng Excel file at next open row? Message-ID: <2acc7858-e55b-4cfe-8e10-1c0d716a10d4@o4g2000yqd.googlegroups.com> How can you determine the next open row in an existing Excel file such that you can start adding data to the cells in that row? As in below, I want a variable in place of the 6 (row 6 in the four ws1.Cells(x,1) lines), but have no other way of knowing what row I am on besides looking to the first free cell in column A. How to do? Examples I see make it seem really complicated - this can't be that hard. Thanks for any help. worksheet = "C:\\Excel_Reports\\ea" + ea + "report"# + ".xls" xlApp = win32com.client.Dispatch("Excel.Application") xlApp.Visible = 1 xlApp.Workbooks.Open(worksheet) ## for existing file ##xlApp.SheetsInNewWorkbook = 1 ##wb = xlApp.Workbooks() ws1 = xlApp.Worksheets(1) ws1.Cells(6,1).Value = "selection" ws1.Cells(6,2).Value = count ws1.Cells(6,3).Value = epcFloat ws1.Cells(6,8).Value = currentGMT wb.SaveAs(worksheet) wb.Close(False) ## False/1 From v.harishankar at gmail.com Fri Dec 3 12:32:12 2010 From: v.harishankar at gmail.com (Harishankar) Date: Fri, 3 Dec 2010 17:32:12 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <4CF7B0BB.7080008@tim.thechases.com> Message-ID: On Thu, 02 Dec 2010 17:33:47 -0800, Aahz wrote: > Please demonstrate that using ``if`` blocks for True/False is impler and > cleaner than using ``try`` blocks to handle exceptions. It is my personal preference and coding style for certain situations I encounter in my own programs and not something that I could prove to anybody else by theory. But anyway, in certain circumstances, exceptions create a break in flow of the execution of a program that makes it non-obvious as to how to resume flow at the point of disruption especially when the exception handling mechanism is at a higher level. While an error flag can simply set an alarm and allow other code to continue and allow the calling higher-level code to handle the alarm/flag as it sees fit. -- Harishankar (http://harishankar.org http://lawstudentscommunity.com) From no.email at nospam.invalid Fri Dec 3 13:15:58 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 03 Dec 2010 10:15:58 -0800 Subject: Exception handling in Python 3.x References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7xlj46vi1t.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > def func(iterable): > it = iter(iterable) > failed = False > try: > x = next(it) > except StopIteration: > failed = True > if failed: > raise ValueError("can't process empty iterable") > print(x) Untested: from itertools import islice def func(iterable): xs = list(islice(iter(iterable), 1)) if len(xs) == 0: raise ValueError(...) print xs[0] From emile at fenx.com Fri Dec 3 13:53:08 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 03 Dec 2010 10:53:08 -0800 Subject: Comparison with False - something I don't understand In-Reply-To: <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 12/3/2010 6:31 AM Mark Wooding said... > It's easy to show that a resumable exception system can do everything > that a nonresumable system (like Python's) can do (simply put all of the > recovery logic at the resume point); but the converse is not true. > > There are some other fringe benefits to resumable exceptions. I do a lot of work in a variant of Business Basic that has always offered resumable exceptions. The closest I get in python is using import pdb;pdb.set_trace(). I wonder what it would take to allow for any exceptions occurring outside a try/except context to dump the traceback, then invoke pdb.set_trace() before bailing to allow for both investigation and possible recovery and continuance? Emile From user at compgroups.net/ Fri Dec 3 13:55:43 2010 From: user at compgroups.net/ (jaime) Date: Fri, 03 Dec 2010 12:55:43 -0600 Subject: Twisted and txJSON-RPC References: <53e3097c-edc8-4d09-8651-ec220758016f@n31g2000vbd.googlegroups.com> Message-ID: did you fix it? I have the same problem From no.email at please.post Fri Dec 3 14:28:00 2010 From: no.email at please.post (kj) Date: Fri, 3 Dec 2010 19:28:00 +0000 (UTC) Subject: Assigning to __class__ attribute Message-ID: I have a couple of questions regarding assigning to an instance's __class__ attribute. The first is illustrated by the following interaction. First I define an empty class: >>> class Spam(object): pass ... Now I define an instance of Spam and an instance of Spam's superclass: >>> x = Spam() >>> y = Spam.__mro__[1]() # (btw, is there a less uncouth way to do this???) >>> [z.__class__.__name__ for z in x, y] ['Spam', 'object'] Now I define a second empty class: >>> class Ham(object): pass ... Next, I attempt to assign the value Ham to x.__class__: >>> x.__class__ = Ham >>> [isinstance(x, z) for z in Spam, Ham] [False, True] This was the first surprise for me: assigning to the __class__ attribute not only isn't vetoed, but in fact changes the instances class: Oh-kaaaay... First question: how kosher is this sort of class transmutation through assignment to __class__? I've never seen it done. Is this because it considered something to do only as a last resort, or is it simply because the technique is not needed often, but it is otherwise perfectly ok? The second, and much bigger, surprise comes when I attempt to do the same class-switching with y: >>> y.__class__ = Ham Traceback (most recent call last): File "", line 1, in TypeError: __class__ assignment: only for heap types (If you recall, y's class is object, the superclass of x.) Apparently Spam is a "heap type" (whatever that is) but its superclass, object, isn't. This definitely rattles my notions of inheritance: since the definition of Spam was empty, I didn't expect it to have any significant properties that are not already present in its superclass. What's going on here? Is this a bug, or a feature? I can see no logical justification for allowing such class switching for only some class and not others. One last question: as the questions above make clear, I have a colossal muddle inside my head regarding Python's model of classes and inheritance. This is not for lack of trying to understand it, but, rather, for exactly the opposite reason: in my zeal to gain the fullest understanding of this topic, I think I have read too much that is incorrect, or obsolete, or incomplete... What is the most complete, definitive, excruciatingly detailed exposition of Python's class and inheritance model? I'm expressly avoiding Google to answer this question, and instead asking it here, because I suspect that there's some connection between my state of utter confusion on this topic and the ease with which the complete/definitive/highest-quality information can get lost among a huge number of Google hits to popular-but-only-partially-correct sources of information. (In fact, I *may* have already read the source I'm seeking, but subsequent readings of incorrect stuff may have overwritten the correct information in my brain.) TIA! ~kj From ethan at stoneleaf.us Fri Dec 3 15:15:36 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 03 Dec 2010 12:15:36 -0800 Subject: Exception handling in Python 3.x In-Reply-To: References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4CF94FE8.3010405@stoneleaf.us> Peter Otten wrote: > http://mail.python.org/pipermail/python-list/2010-October/1258606.html > http://mail.python.org/pipermail/python-list/2010-October/1259024.html I found #6210 on bugs.python.org -- does anyone know if there are any others regarding this issue? Or any progress on MRAB's idea? MRAB wrote: > Suggestion: an explicit 'raise' in the exception handler excludes the > context, but if you want to include it then 'raise with'. For example: > > # Exclude the context > try: > command_dict[command]() > except KeyError: > raise CommandError("Unknown command") > > # Include the context > try: > command_dict[command]() > except KeyError: > raise with CommandError("Unknown command") ~Ethan~ From goldtech at worldpost.com Fri Dec 3 15:27:04 2010 From: goldtech at worldpost.com (goldtech) Date: Fri, 3 Dec 2010 12:27:04 -0800 (PST) Subject: import module doesn't work for new package Message-ID: <1e9b4955-d60d-44f0-9b62-2ce50be35fdf@u9g2000pra.googlegroups.com> I tried install a Python - would the word be "package"? - on Ubuntu 10.10. Could you tell me how to fix? I would be grateful, is it a path problem? Thanks. Lee giga1 at giga1:~/Desktop/pykhtml-0.2$ sudo python setup.py install [sudo] password for giga1: running install running build running build_py creating build creating build/lib.linux-i686-2.6 creating build/lib.linux-i686-2.6/pykhtml copying pykhtml/dom.py -> build/lib.linux-i686-2.6/pykhtml copying pykhtml/__init__.py -> build/lib.linux-i686-2.6/pykhtml running install_lib running install_egg_info Removing /usr/local/lib/python2.6/dist-packages/PyKHTML-0.2.egg-info Writing /usr/local/lib/python2.6/dist-packages/PyKHTML-0.2.egg-info then: >>> import pykhtml Traceback (most recent call last): File "", line 1, in File "pykhtml/__init__.py", line 3, in import khtml, kdecore, kdeui, kio, dcopext ImportError: No module named khtml From ethan at stoneleaf.us Fri Dec 3 15:27:09 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 03 Dec 2010 12:27:09 -0800 Subject: Exception handling in Python 3.x In-Reply-To: References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> <87hbeuyj1g.fsf@xemacs.org> Message-ID: <4CF9529D.4050808@stoneleaf.us> Peter Otten wrote: > Hrvoje Niksic wrote: > >> Peter Otten <__peter__ at web.de> writes: >> >>>> Note that StopIteration is an internal detail of no relevance whatsoever >>>> to the caller. Expose this is unnecessary at best and confusing at >>>> worst. >>> http://mail.python.org/pipermail/python-list/2010-October/1258606.html >>> http://mail.python.org/pipermail/python-list/2010-October/1259024.html >> Both of these involve suppressing the chaining at the wrong place, >> namely in the outer handler or, worse yet, in the exception display >> mechanism. Steven, on the other hand, wants his *inner* handler to >> express that the original exception was an implementation detail, a >> business exception such as StopIteration, that is completely irrelevant >> to the actual exception being raised. The outer handler is the wrong >> place to suppress the chaining because it has no way of distinguishing >> Steven's case from a genuine case of a new exception unexpectedly >> occurring during handling of the original exception. > > To quote the Rolling Stones: You can't always get what you want. > > After rereading the original post I still don't get why the workarounds > provided in those links aren't worth considering. For me at least it's a matter of simplicity, clarity, and the Way of the Python ;) The workarounds are boiler-plate for a fairly common situation, and one of the things i _love_ about python is the *lack* of boilerplate. I think the real question is is there any progress on dealing with the Open Issue in the PEP? Open Issue: Suppressing Context As written, this PEP makes it impossible to suppress '__context__', since setting exc.__context__ to None in an 'except' or 'finally' clause will only result in it being set again when exc is raised. http://www.python.org/dev/peps/pep-3134/ ~Ethan~ From robert.kern at gmail.com Fri Dec 3 15:57:56 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 03 Dec 2010 14:57:56 -0600 Subject: Assigning to __class__ attribute In-Reply-To: References: Message-ID: On 12/3/10 1:28 PM, kj wrote: > > > I have a couple of questions regarding assigning to an instance's > __class__ attribute. > > The first is illustrated by the following interaction. First I > define an empty class: > >>>> class Spam(object): pass > ... > > Now I define an instance of Spam and an instance of Spam's superclass: >>>> x = Spam() >>>> y = Spam.__mro__[1]() # (btw, is there a less uncouth way to do this???) >>>> [z.__class__.__name__ for z in x, y] > ['Spam', 'object'] > > Now I define a second empty class: >>>> class Ham(object): pass > ... > > Next, I attempt to assign the value Ham to x.__class__: > >>>> x.__class__ = Ham >>>> [isinstance(x, z) for z in Spam, Ham] > [False, True] > > This was the first surprise for me: assigning to the __class__ > attribute not only isn't vetoed, but in fact changes the instances > class: > > Oh-kaaaay... > > First question: how kosher is this sort of class transmutation > through assignment to __class__? I've never seen it done. Is this > because it considered something to do only as a last resort, or is > it simply because the technique is not needed often, but it is > otherwise perfectly ok? Last resort for very special purposes, and only extremely rarely in production. > The second, and much bigger, surprise comes when I attempt to do > the same class-switching with y: > >>>> y.__class__ = Ham > Traceback (most recent call last): > File "", line 1, in > TypeError: __class__ assignment: only for heap types > > (If you recall, y's class is object, the superclass of x.) Apparently > Spam is a "heap type" (whatever that is) but its superclass, object, > isn't. This definitely rattles my notions of inheritance: since > the definition of Spam was empty, I didn't expect it to have any > significant properties that are not already present in its superclass. > What's going on here? Is this a bug, or a feature? I can see no > logical justification for allowing such class switching for only > some class and not others. Feature. When you have C-implemented types, you cannot safely swap out their instance's __class__. There are memory issues involved. Only subclasses of object made by the class statement (or the equivalent type(...) call), i.e. "heap types", permit this modification. object is a C-implemented type. Importantly, as for most other C-implemented types, plain object instances have no __dict__. Types and classes were unified a long time ago in Python 2.2, but there are still relevant distinctions between C-implemented types and Python-implemented types. > One last question: as the questions above make clear, I have a > colossal muddle inside my head regarding Python's model of classes > and inheritance. This is not for lack of trying to understand it, > but, rather, for exactly the opposite reason: in my zeal to gain > the fullest understanding of this topic, I think I have read too > much that is incorrect, or obsolete, or incomplete... > > What is the most complete, definitive, excruciatingly detailed > exposition of Python's class and inheritance model? I'm expressly > avoiding Google to answer this question, and instead asking it > here, because I suspect that there's some connection between my > state of utter confusion on this topic and the ease with which the > complete/definitive/highest-quality information can get lost among > a huge number of Google hits to popular-but-only-partially-correct > sources of information. (In fact, I *may* have already read the > source I'm seeking, but subsequent readings of incorrect stuff may > have overwritten the correct information in my brain.) http://www.python.org/download/releases/2.2.3/descrintro/ -- 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 arnodel at gmail.com Fri Dec 3 16:11:11 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Fri, 03 Dec 2010 21:11:11 +0000 Subject: Assigning to __class__ attribute References: Message-ID: <87oc92d0k0.fsf@gmail.com> kj writes: > I have a couple of questions regarding assigning to an instance's > __class__ attribute. > > The first is illustrated by the following interaction. First I > define an empty class: > >>>> class Spam(object): pass > ... > > Now I define an instance of Spam and an instance of Spam's superclass: >>>> x = Spam() >>>> y = Spam.__mro__[1]() # (btw, is there a less uncouth way to do this???) Yes: y = object() >>>> [z.__class__.__name__ for z in x, y] > ['Spam', 'object'] > > Now I define a second empty class: >>>> class Ham(object): pass > ... > > Next, I attempt to assign the value Ham to x.__class__: > >>>> x.__class__ = Ham >>>> [isinstance(x, z) for z in Spam, Ham] > [False, True] > > This was the first surprise for me: assigning to the __class__ > attribute not only isn't vetoed, but in fact changes the instances > class: > > Oh-kaaaay... > > First question: how kosher is this sort of class transmutation > through assignment to __class__? I've never seen it done. Is this > because it considered something to do only as a last resort, or is > it simply because the technique is not needed often, but it is > otherwise perfectly ok? It's OK as long as the slots defined in the classes are the same (using Python 3 below so no need for specifying that classes derive from object): >>> class Foo: pass ... >>> class Bar: __slots__ = 'x', 'y' ... >>> foo = Foo() >>> foo.__class__ = Bar Traceback (most recent call last): File "", line 1, in TypeError: __class__ assignment: 'Foo' object layout differs from 'Bar' >>> class Baz: __slots__ = 'x', 'y' ... >>> bar = Bar() >>> bar.__class__ = Baz > The second, and much bigger, surprise comes when I attempt to do > the same class-switching with y: > >>>> y.__class__ = Ham > Traceback (most recent call last): > File "", line 1, in > TypeError: __class__ assignment: only for heap types y is of type object, which is a builtin type. You can only switch the __class__ of an instance of a user-defined class. > (If you recall, y's class is object, the superclass of x.) Apparently > Spam is a "heap type" (whatever that is) but its superclass, object, > isn't. This definitely rattles my notions of inheritance: since > the definition of Spam was empty, I didn't expect it to have any > significant properties that are not already present in its superclass. > What's going on here? Is this a bug, or a feature? I can see no > logical justification for allowing such class switching for only > some class and not others. There is a big difference: >>> class Foo: pass >>> x, y = Foo(), object() >>> x.__dict__ {} >>> y.__dict__ Traceback (most recent call last): File "", line 1, in AttributeError: 'object' object has no attribute '__dict__' This means that you can have instance attributes for x but not for y: >>> x.myattr = 123 >>> y.myattr = 123 Traceback (most recent call last): File "", line 1, in AttributeError: 'object' object has no attribute 'myattr' This reflects the fact that x and y are a different kind of object, with a different layout so you can't hotswap their types. I imagine that the term "heap type" is used to types which are objects that live on the heap (in practice they are types defined in Python, by using a "class" statement or calling type(name, bases, attrs)) as opposed to builtin types such as object, int, str, etc... which don't live on the heap. > One last question: as the questions above make clear, I have a > colossal muddle inside my head regarding Python's model of classes > and inheritance. This is not for lack of trying to understand it, > but, rather, for exactly the opposite reason: in my zeal to gain > the fullest understanding of this topic, I think I have read too > much that is incorrect, or obsolete, or incomplete... > What is the most complete, definitive, excruciatingly detailed > exposition of Python's class and inheritance model? I learnt by reading Guido's "Unifying types and classes in Python 2.2", available here: http://www.python.org/download/releases/2.2.3/descrintro/ -- Arnaud From aahz at pythoncraft.com Fri Dec 3 16:41:58 2010 From: aahz at pythoncraft.com (Aahz) Date: 3 Dec 2010 13:41:58 -0800 Subject: Comparison with False - something I don't understand References: Message-ID: In article , Harishankar wrote: >On Thu, 02 Dec 2010 17:33:47 -0800, Aahz wrote: >> >> Please demonstrate that using ``if`` blocks for True/False is impler and >> cleaner than using ``try`` blocks to handle exceptions. > >It is my personal preference and coding style for certain situations I >encounter in my own programs and not something that I could prove to >anybody else by theory. Note carefully that I said "demonstrate", not "prove". If using ``if`` is so clearly better in some situations, you should be able to provide an example. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Think of it as evolution in action." --Tony Rand From programming at toomuchcookies.net Fri Dec 3 16:54:19 2010 From: programming at toomuchcookies.net (OAN) Date: Fri, 03 Dec 2010 22:54:19 +0100 Subject: class attribute confusion Message-ID: <4CF9670B.5020209@toomuchcookies.net> Hi, i was having a problem with class attributes initiated outside of __init__. This code is a demonstration of what i mean: class A(): mylist = [] def __init__(self): self.mylist.append(1) pass class B(A): def __init__(self): A.__init__(self) self.mylist.append(2) v = A() print 'v:',v.mylist x = B() print 'x:',x.mylist y = B() print 'y:',y.mylist z = A() print 'z:',z.mylist print 'v:',v.mylist I would expect the following result: v: [1] x: [1, 2] y: [1, 2] z: [1] v: [1] Who wouldn't, right? But actually python 2.6(.6) gives me the following result: v: [1] x: [1, 1, 2] y: [1, 1, 2, 1, 2] z: [1, 1, 2, 1, 2, 1] v: [1, 1, 2, 1, 2, 1] The four variables v,x,y and z now actually share the same 'mylist'!! To get the correct results, i have to initialize 'mylist' inside of the __init__ method! I think this behaviour is totally wrong, since it seems A.__init__(self) is changing the value inside of A() not inside of the object variable 'self' (that should be x or y)!! Could someone explain this to me, please? regards. From arnodel at gmail.com Fri Dec 3 17:11:09 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Fri, 03 Dec 2010 22:11:09 +0000 Subject: class attribute confusion References: Message-ID: <87k4jqcxs2.fsf@gmail.com> OAN writes: > Hi, > > i was having a problem with class attributes initiated outside of > __init__. This code is a demonstration of what i mean: > > class A(): > mylist = [] > def __init__(self): > self.mylist.append(1) > pass > > class B(A): > def __init__(self): > A.__init__(self) > self.mylist.append(2) > > v = A() > print 'v:',v.mylist > x = B() > print 'x:',x.mylist > y = B() > print 'y:',y.mylist > z = A() > print 'z:',z.mylist > print 'v:',v.mylist > > I would expect the following result: > > v: [1] > x: [1, 2] > y: [1, 2] > z: [1] > v: [1] > > Who wouldn't, right? But actually python 2.6(.6) gives me the > following result: > > v: [1] > x: [1, 1, 2] > y: [1, 1, 2, 1, 2] > z: [1, 1, 2, 1, 2, 1] > v: [1, 1, 2, 1, 2, 1] > > The four variables v,x,y and z now actually share the same 'mylist'!! > To get the correct results, i have to initialize 'mylist' inside of > the __init__ method! Yes. See below. > I think this behaviour is totally wrong, since it seems > A.__init__(self) is changing the value inside of A() not inside of the > object variable 'self' (that should be x or y)!! It's not wrong at all. You expect "mylist" to behave as an instance attribute, but you defined it as a class attribute. Instance attributes are naturally initialised in the __init__() method. -- Arnaud From mdw at distorted.org.uk Fri Dec 3 17:15:54 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 03 Dec 2010 22:15:54 +0000 Subject: Assigning to __class__ attribute References: Message-ID: <878w06o63p.fsf.mdw@metalzone.distorted.org.uk> kj writes: > >>> class Spam(object): pass > > Now I define an instance of Spam and an instance of Spam's superclass: > >>> x = Spam() > >>> y = Spam.__mro__[1]() # (btw, is there a less uncouth way to do this???) There's the `__bases__' attribute, which is simply a tuple of the class's direct superclasses in order. Spam.__bases__[0] will always be equal to Spam.__mro__[1] because of the way the linearization works. There's also `__base__' attribute, which seems to correspond to a PyTypeObject's `tp_base' slot; this /isn't/ always the first direct superclass; I'm not quite sure what the rules are, and it doesn't seem to be documented anywhere. > >>> [z.__class__.__name__ for z in x, y] > ['Spam', 'object'] > > >>> class Ham(object): pass > ... > > >>> x.__class__ = Ham > >>> [isinstance(x, z) for z in Spam, Ham] > [False, True] > > First question: how kosher is this sort of class transmutation > through assignment to __class__? Yep. That's allowed, and useful. Consider something like a red/black tree: red and black nodes behave differently from one another, and it would be convenient to make use of method dispatch rather than writing a bunch of conditional code; unfortunately, nodes change between being red and black occasionally. Swizzling classes lets you do this. Various other languages have similar features. The scariest is probably Smalltalk's `become: anObject' method, which actually swaps two objects. Python `__class__' assignment is similarly low-level: all it does is tweak a pointer, and it's entirely up to the program to make sure that the object's attributes are valid according to the rules for the new class. The Common Lisp Object System has CHANGE-CLASS, which is a rather more heavyweight and hairy procedure which tries to understand and cope with the differences between the two classes. > I've never seen it done. Is this because it considered something to > do only as a last resort, or is it simply because the technique is not > needed often, but it is otherwise perfectly ok? It's not needed very often, and can be surprising to readers who aren't familiar with other highly dynamic object systems, so I don't think it's particularly encouraged; but it seems like it might be the best approach in some cases. I think it's one of those things where you'll just /know/ when it's the right answer, and if you don't know that it's the right answer, it isn't. > >>> y.__class__ = Ham > Traceback (most recent call last): > File "", line 1, in > TypeError: __class__ assignment: only for heap types `Heap types' are types which are allocated dynamically. Non-heap types are ones which are dreamt up by C extensions or built into Python. I suspect that the logic here is that non-heap types in general are magical and weird, and their instances might have special C stuff attached to them, so changing their classes is a Bad Idea, though there's an extra check which catches most problems: In [1]: class foo (str): pass In [2]: class bar (object): pass In [3]: x = foo() In [4]: x.__class__ = bar TypeError: __class__ assignment: 'foo' object layout differs from 'bar' Anyway, I'd guess it's just a bug that `object' is caught this way, but it doesn't seem an especially important one. > This definitely rattles my notions of inheritance: since the > definition of Spam was empty, I didn't expect it to have any > significant properties that are not already present in its superclass. Yes, sorry. I think this is a bit poor, really, but it's hard to do a much better job. Pure Python objects are pretty simple things, really: they have a pointer to their class, and a bunch of attributes stored in a dictionary. What other languages call instance variables or methods are found using attribute lookup, which just searches the object, and then its class and its superclasses in the method resolution order. If you fiddle with `__class__', then attribute lookup searches a different bunch of classes. Nothing else needs to change -- or, at least, if it does, then you'd better do it yourself. Types implemented in C work by extending the underlying Python object structure. The magical type-specific stuff is stored in the extra space. Unfortunately, changing classes is now hard, because Python code can't even see the magic C stuff -- and, besides, a different special C type may require a different amount of space, and the CPython implementation can't cope with the idea that objects might move around in memory. Similar complications occur if one of the classes has a `__slots__' attribute: in this case, both the original and new class must have a `__slots__' attribute and they must be the same length and have the same names. > What is the most complete, definitive, excruciatingly detailed > exposition of Python's class and inheritance model? It's kind of scattered. The language reference sections 3.3 and 3.4 contain some useful information, but it's rather detailed and it's a (mostly) comprehensive list of what a bunch of strangely shaped things do rather than a presentation of a coherent model. Guido's essay `Unifying types and classes in Python 2.2' is pretty good (http://www.python.org/download/releases/2.2.3/descrintro/) and provides some of the background. Unsurprisingly, Python's object system takes (mostly good) ideas from other languages, particularly dynamic ones. Python's object system is /very/ different from what you might expect from C++, Ada and Eiffel, for example; but coming from Smalltalk, Flavors or Dylan, you might not be particularly surprised. Some knowledge of these other languages will help fill in the gaps. > I'm expressly avoiding Google to answer this question, I'd say this was sensible, except for the fact that you seem to expect a more reliable answer from Usenet. ;-) -- [mdw] From steve+comp.lang.python at pearwood.info Fri Dec 3 17:58:46 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Dec 2010 22:58:46 GMT Subject: class attribute confusion References: Message-ID: <4cf97626$0$30003$c3e8da3$5496439d@news.astraweb.com> On Fri, 03 Dec 2010 22:54:19 +0100, OAN wrote: > Hi, > > i was having a problem with class attributes initiated outside of > __init__. This code is a demonstration of what i mean: [...] > I would expect the following result: > > v: [1] > x: [1, 2] > y: [1, 2] > z: [1] > v: [1] > > Who wouldn't, right? Everybody who actually understands Python's object model. > The four variables v,x,y and z now actually share the same 'mylist'!! To > get the correct results, i have to initialize 'mylist' inside of the > __init__ method! Right. If you define a *class* attribute, it lives in the class, not the instance, and so all instances share the same value. > I think this behaviour is totally wrong, since it seems A.__init__(self) > is changing the value inside of A() not inside of the object variable > 'self' (that should be x or y)!! A.__init__(self) calls A's init method with self (either x or y) as the self parameter, but A's init method merely modifies the class attribute mylist in place. It doesn't create a new list. The behaviour you're seeing is no different from this: shared = [] a = {"spam": shared, "ham": 23} b = {"spam": shared, "ham": 42} a["spam"].append("parrot") What would you expect the value of b["spam"] to be? -- Steven From steve+comp.lang.python at pearwood.info Fri Dec 3 18:26:12 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Dec 2010 23:26:12 GMT Subject: Assigning to __class__ attribute References: Message-ID: <4cf97c94$0$30003$c3e8da3$5496439d@news.astraweb.com> On Fri, 03 Dec 2010 19:28:00 +0000, kj wrote: > This was the first surprise for me: assigning to the __class__ attribute > not only isn't vetoed, but in fact changes the instances class: > > Oh-kaaaay... > > First question: how kosher is this sort of class transmutation through > assignment to __class__? I've never seen it done. Is this because it > considered something to do only as a last resort, or is it simply > because the technique is not needed often, but it is otherwise perfectly > ok? While not exactly encouraged, it is a deliberate feature. It's not a good idea to go around randomly monkey-patching instances with a new class, and in fact Python makes some attempts to protect you from the most egregious errors, but the technique has its uses. Especially if you're swapping between two classes which you have designed to be swapped between. For instance, if you have an object that needs to display two distinct behaviours during different times of its life, then a good technique is to write two classes, one for each set of behaviours, and automatically switch between them as needed. A ring buffer is a common example: http://code.activestate.com/recipes/68429-ring-buffer/ This made it into the Python Cookbook, so it comes with the approval of Alex Martelli, which is nearly as good as the approval of Guido :) > The second, and much bigger, surprise comes when I attempt to do the > same class-switching with y: > >>>> y.__class__ = Ham > Traceback (most recent call last): > File "", line 1, in > TypeError: __class__ assignment: only for heap types > > (If you recall, y's class is object, the superclass of x.) Apparently > Spam is a "heap type" (whatever that is) but its superclass, object, > isn't. This definitely rattles my notions of inheritance: since the > definition of Spam was empty, I didn't expect it to have any significant > properties that are not already present in its superclass. What's going > on here? Is this a bug, or a feature? I can see no logical justification > for allowing such class switching for only some class and not others. That is more of a design compromise than a feature... it is unsafe to change the class of types implemented in C, for various implementation- related reasons, and so Python prohibits it. Heap types are dynamically allocated types that you create using the class statement (or the type function). They're so-called because they live in the heap. The builtin types defined in C presumably aren't dynamically allocated, but statically. Presumably they have a fixed layout in memory and don't live in the heap. Not being a C programmer, I've never cared about the implementation, only that you can't sensibly turn a str instance into an int instance by assigning to __class__ and so Python prohibits it. > One last question: as the questions above make clear, I have a colossal > muddle inside my head regarding Python's model of classes and > inheritance. This is not for lack of trying to understand it, but, > rather, for exactly the opposite reason: in my zeal to gain the fullest > understanding of this topic, I think I have read too much that is > incorrect, or obsolete, or incomplete... I suspect you're trying to make this more complicated than it actually is. You keep finding little corner cases that expose implementation details (such as the heap-types issue above) and leaping to the erroneous conclusion that because you didn't understand this tiny little corner of Python's class model, you didn't understand any of it. Python's object model is relatively simple, but it does occasionally expose a few messy corners. > What is the most complete, definitive, excruciatingly detailed > exposition of Python's class and inheritance model? That would be the source code. -- Steven From steve+comp.lang.python at pearwood.info Fri Dec 3 18:28:22 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Dec 2010 23:28:22 GMT Subject: Exception handling in Python 3.x References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> <7xlj46vi1t.fsf@ruckus.brouhaha.com> Message-ID: <4cf97d15$0$30003$c3e8da3$5496439d@news.astraweb.com> On Fri, 03 Dec 2010 10:15:58 -0800, Paul Rubin wrote: > Steven D'Aprano writes: >> def func(iterable): >> it = iter(iterable) >> failed = False >> try: >> x = next(it) >> except StopIteration: >> failed = True >> if failed: >> raise ValueError("can't process empty iterable") >> print(x) > > Untested: > > from itertools import islice > > def func(iterable): > xs = list(islice(iter(iterable), 1)) > if len(xs) == 0: > raise ValueError(...) > print xs[0] If you're intention was to make me feel better about the version above that sets a flag, you succeeded admirably! :) -- Steven From g.candia at vtr.net Fri Dec 3 19:31:21 2010 From: g.candia at vtr.net (Guillermo Candia Huerta) Date: Fri, 03 Dec 2010 21:31:21 -0300 Subject: [Python-es] Uso de variable Global In-Reply-To: References: <1291326344.4743.5.camel@cristian-desktop> Message-ID: <4CF98BD9.3030707@vtr.net> El 02/12/10 19:04, Pau Cervera escribi?: > Ni idea de Tkinter, pero ?no puedes almacenar *valor* en una variable de > instancia de App y convertir la funci?n *muestra* en un m?todo de la classe > App que teng aceso a las variables de instancia de App? > > ----- > Pau > > Python..., what else? > > > 2010/12/2 craf > >> Hola. >> >> >> Estoy probando Tkinter y escrib? este peque?o c?digo el cual crea un >> formulario con un textbox y un bot?n. Al ingresar un dato en el textbox >> y presionar el bot?n, se imprime en la consola el valor. >> >> >> ---CODE-------------------- >> >> from Tkinter import * >> >> def muestra(): >> print(valor.get()) >> >> class App: >> def __init__(self,master): >> global valor >> valor = StringVar() >> e = Entry(master,textvariable=valor).pack() >> b = Button(master,text='Mostrar',command=muestra).pack() >> >> >> master = Tk() >> app = App(master) >> master.mainloop() >> >> ----------------------------- >> >> Funciona, pero tuve que hacer uso de una variable Global. >> >> Pregunta: ?Es valida esta forma?, ?Se puede hacer de otra forma, sin >> ocuparla?. >> >> Saludos. >> >> Cristian >> >> >> >> _______________________________________________ >> Python-es mailing list >> Python-es at python.org >> http://mail.python.org/mailman/listinfo/python-es >> FAQ: http://python-es-faq.wikidot.com/ >> > puede heredar el bot?n y agregas los atributos y m?todos que necesites, en el constructor le pasas las variables que necesitas From steve+comp.lang.python at pearwood.info Fri Dec 3 19:42:42 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Dec 2010 00:42:42 GMT Subject: Exception handling in Python 3.x References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> <87hbeuyj1g.fsf@xemacs.org> Message-ID: <4cf98e82$0$30003$c3e8da3$5496439d@news.astraweb.com> On Fri, 03 Dec 2010 16:26:19 +0100, Hrvoje Niksic wrote: > Peter Otten <__peter__ at web.de> writes: > >>> Note that StopIteration is an internal detail of no relevance >>> whatsoever to the caller. Expose this is unnecessary at best and >>> confusing at worst. >> >> http://mail.python.org/pipermail/python-list/2010-October/1258606.html >> http://mail.python.org/pipermail/python-list/2010-October/1259024.html Thanks for the links Peter. > Both of these involve suppressing the chaining at the wrong place, > namely in the outer handler or, worse yet, in the exception display > mechanism. Steven, on the other hand, wants his *inner* handler to > express that the original exception was an implementation detail, a > business exception such as StopIteration, that is completely irrelevant > to the actual exception being raised. Yes, exactly! Python 3.x exposes completely irrelevant and internal details in the traceback. > The outer handler is the wrong > place to suppress the chaining because it has no way of distinguishing > Steven's case from a genuine case of a new exception unexpectedly > occurring during handling of the original exception. > > One solution would be for "raise" inside except to not use the context. I would have thought that was such an obvious solution that I was gobsmacked to discover the PEP 3134 hadn't already considered it. If you *explicitly* raise an exception inside an exception handler, surely it's because you want to suppress the previous exception as an internal detail? If not, and you want to chain it with the previous exception, the solution is simple, obvious and straight-forward: explicit chaining. try: something() except SomeException as exc: raise MyException from exc > For example: > > try: > {}[1] > except KeyError: > 1/0 > > would behave as before, but: Yes, that presumably would be a bug and should chain exceptions. > But: > > try: > {}[1] > except KeyError: > raise Exception("my error") > > ...would raise the custom error forgetting the KeyError. That's exactly the behaviour I would expect and I'm surprised that this feature was put into production without some simple way to support this idiom. -- Steven From steve+comp.lang.python at pearwood.info Fri Dec 3 19:52:22 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Dec 2010 00:52:22 GMT Subject: Exception handling in Python 3.x References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> <87hbeuyj1g.fsf@xemacs.org> Message-ID: <4cf990c6$0$30003$c3e8da3$5496439d@news.astraweb.com> On Fri, 03 Dec 2010 17:08:38 +0100, Peter Otten wrote: > After rereading the original post I still don't get why the workarounds > provided in those links aren't worth considering. The first work-around: http://mail.python.org/pipermail/python-list/2010-October/1258606.html is unsuitable because it requires the caller to install a custom excepthook. It would be rude and unacceptable for arbitrary functions to install hooks, possibly stomping all over the caller's own custom excepthook. And even if I did, or the caller did, it has the unfortunate side-effect of suppressing the display of *all* chained exceptions, including those that come from the bugs in exception handlers. The second work-around might be worth considering: http://mail.python.org/pipermail/python-list/2010-October/1259024.html however it adds unnecessary boilerplate to what should be a simple try...except...raise block, it obscures the intention of the code. As a work-around, it might be worth considering, but it's hardly elegant and it could very well be a fluke of the implementation rather than a guaranteed promise of the language. In the absence of a supported way to suppress exception chaining, I'm leaning towards my original work-around: set a flag in the except block, then raise the exception once I leave the block. But thanks again for the links. -- Steven From steve+comp.lang.python at pearwood.info Fri Dec 3 20:53:12 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Dec 2010 01:53:12 GMT Subject: import module doesn't work for new package References: <1e9b4955-d60d-44f0-9b62-2ce50be35fdf@u9g2000pra.googlegroups.com> Message-ID: <4cf99f07$0$30003$c3e8da3$5496439d@news.astraweb.com> On Fri, 03 Dec 2010 12:27:04 -0800, goldtech wrote: > I tried install a Python - would the word be "package"? - on Ubuntu > 10.10. Could you tell me how to fix? I would be grateful, is it a path > problem? Thanks. Lee That looks to me like either a missing dependency, or a bug in the package. It could be that package pykhtml depends on another package khtml, which isn't installed, or it could simply be a bug in pykhtml. It might help if you look at the MANIFEST file that came with the pykhtml package, and see what files it lists. -- Steven From wuwei23 at gmail.com Fri Dec 3 21:10:34 2010 From: wuwei23 at gmail.com (alex23) Date: Fri, 3 Dec 2010 18:10:34 -0800 (PST) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> Message-ID: <12f46102-0d2b-44eb-abf4-e4f1c3606c79@e16g2000pri.googlegroups.com> On Dec 3, 2:12?am, Tim Harig wrote: > Actually, I thought that debate was resolved years ago. ?I cannot think of > a single recently developed programming language that does not provide > exception handling mechanisms because they have been proven more reliable. Google's Go lacks exceptions and I believe that was a deliberate design choice. From mirko.vukovic at gmail.com Fri Dec 3 21:45:02 2010 From: mirko.vukovic at gmail.com (Mirko) Date: Fri, 3 Dec 2010 18:45:02 -0800 (PST) Subject: Google AI challenge: planet war. Lisp won. References: <44a8f48f-e291-463e-a042-d0cbc31a2a4e@z17g2000prz.googlegroups.com> Message-ID: <2a853d74-09d7-4910-8f52-3b42f9c275ae@w21g2000vby.googlegroups.com> On Dec 2, 12:06?pm, Xah Lee wrote: > discovered this rather late. > > Google has a AI Challenge: planet wars.http://ai-contest.com/index.php > > it started sometimes 2 months ago and ended first this month. > > the winner is G?bor Melis, with his code written in lisp. > > Congrats lispers! > > G?bor wrote a blog about it herehttp://quotenil.com/Planet-Wars-Post-Mortem.html > > (not sure if this has been mentioned here but quick search didn't find > it) > > ?Xah ?http://xahlee.org/? Thanks for letting us know and congratulations to Gabor. From usernet at ilthio.net Fri Dec 3 23:14:00 2010 From: usernet at ilthio.net (Tim Harig) Date: Sat, 4 Dec 2010 04:14:00 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <12f46102-0d2b-44eb-abf4-e4f1c3606c79@e16g2000pri.googlegroups.com> Message-ID: On 2010-12-04, alex23 wrote: > On Dec 3, 2:12?am, Tim Harig wrote: >> Actually, I thought that debate was resolved years ago. ?I cannot think of >> a single recently developed programming language that does not provide >> exception handling mechanisms because they have been proven more reliable. > > Google's Go lacks exceptions and I believe that was a deliberate > design choice. 1. The debate that I was referring to was between simple function checking vs. everything else. I didn't mean to automatically proclude any newer methodologies of which I might not even be aware. 2. I would consider the defer/panic/recovery mechanism functionally similar to exceptions in most ways. It allows the error handling code to be placed at a higher level and panics tranverse the stack until they are handled by a recovery. This is basically equivilent to how exceptions work using different names. The change is basically the defer function which solves the problem of any cleanup work that the function needs to do before the panic is raised. I like it, its nice. It formalizes the pattern of cleaning up within an exception block and re-raising the exception. I do have to wonder what patterns will emerge in the object given to panic(). Since it takes anything, and since Go doesn't have an object hierarchy, much less an exception hierarchy, the panic value raised may or may not contain the kind of detailed information that can be obtained about the error that we are able to get from the Exception objects in Python. From usernet at ilthio.net Fri Dec 3 23:25:37 2010 From: usernet at ilthio.net (Tim Harig) Date: Sat, 4 Dec 2010 04:25:37 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 2010-12-03, Harishankar wrote: > On Fri, 03 Dec 2010 14:31:43 +0000, Mark Wooding wrote: >> In general, recovering from an exceptional condition requires three >> activities: >> >> * doing something about the condition so that the program can continue >> running; >> >> * identifying some way of rejoining the program's main (unexceptional) >> flow of control; and >> >> * actually performing that transfer, ensuring that any necessary >> invariants are restored. > > my fault. Seems that exception handling requires a lot of forethought > since the control of program execution breaks at the point of exception > with no obvious way to rejoin it seamlessly whereas with an error, a > simple if condition could handle the error state and resume execution > from that point forward. This is the main reason why I think I used > simple error codes to handle certain recoverable conditions and avoided > exceptions. If you are returning an error code to the above function, then there is nothing that you cannot do with with the exception. Basically, you resolve the issue in your except block just as you would in the block of your if statement after returning the error code. If you try and fail to handle the exception or just needed to do some cleanup before allowing the exception to continue, then you just re-raise the exception. From smallpox911 at gmail.com Fri Dec 3 23:56:12 2010 From: smallpox911 at gmail.com (small Pox) Date: Fri, 3 Dec 2010 20:56:12 -0800 (PST) Subject: Google AI challenge: planet war. Lisp won. References: <44a8f48f-e291-463e-a042-d0cbc31a2a4e@z17g2000prz.googlegroups.com> <2a853d74-09d7-4910-8f52-3b42f9c275ae@w21g2000vby.googlegroups.com> Message-ID: <42634615-6233-4082-a7a8-22dff724c7bd@o9g2000pre.googlegroups.com> > > G?bor wrote a blog about it herehttp://quotenil.com/Planet-Wars-Post-Mortem.html http://presstv.ir/detail/153770.html It is said in the protocols to corrupt the minds of the GOYIM by alcohol gambling games <------------- pornography adulteries sex Watch the photo and proof of israel in LEBANON. these are vicious murderous criminals and spies. All the intellectual property of the planet has been stolen by them. betah.co.il was operational for a long time and just the tip of the iceberg. then these criminals helped saudis and other kuwaitis set some forums. arabic software was developed by them to help the foulish saudis. some desperate saudis, koreans, vietnam and other were baited and given the ebooks to spread. look how viciously they go for extradition of WIKILEAKS guy Julian Assange (on false rape charges), but ROMAN POLANSKY is a TRUE RAPIST of 13 year old innocent German girl in USA. Now, it should be somehow made kosher that what the jew has stolen should me made available to everyone otherwise as historically they convert black into white. which means all those "cubs" going back to israel for the annual kibbutz from europe,US,Australia etc, are taught lying, deception, hacking and all the top level mossad skills. This is infact happening. Bernard Madoff is not the only one. They will convert the knowledge into war material and money as they are clamoring for iran. How do you explain all the zionist jews buying all the software and hardware companies and setting up the worlds biggest monopolies. Watch the israeli espionage photos http://presstv.ir/detail/153770.html http://presstv.ir/detail/153770.html http://presstv.ir/detail/153770.html From smallpox911 at gmail.com Fri Dec 3 23:59:41 2010 From: smallpox911 at gmail.com (small Pox) Date: Fri, 3 Dec 2010 20:59:41 -0800 (PST) Subject: Google AI challenge: planet war. Lisp won. References: <44a8f48f-e291-463e-a042-d0cbc31a2a4e@z17g2000prz.googlegroups.com> <2a853d74-09d7-4910-8f52-3b42f9c275ae@w21g2000vby.googlegroups.com> <42634615-6233-4082-a7a8-22dff724c7bd@o9g2000pre.googlegroups.com> Message-ID: <38101daf-9cde-4cb8-a26a-5c0e4437b5e5@n32g2000pre.googlegroups.com> On Dec 3, 8:56?pm, small Pox wrote: > > > G?bor wrote a blog about it herehttp://quotenil.com/Planet-Wars-Post-Mortem.html > > http://presstv.ir/detail/153770.html > > It is said in the protocols to corrupt the minds of the GOYIM by > > alcohol > gambling > games ? ? ?<------------- > pornography > adulteries > sex > > Watch the photo and proof of israel in LEBANON. these are vicious > murderous criminals and spies. All the intellectual property of the > planet has been stolen by them. betah.co.il was operational for a long > time and just the tip of the iceberg. > > then these criminals helped saudis and other kuwaitis set some forums. > arabic software was developed by them to help the foulish saudis. some > desperate saudis, koreans, vietnam and other were baited and given the > ebooks to spread. > > look how viciously they go for extradition of WIKILEAKS guy Julian > Assange (on false rape charges), but ROMAN POLANSKY is a TRUE RAPIST > of 13 year old innocent German girl in USA. > > Now, it should be somehow made kosher that what the jew has stolen > should me made available to everyone otherwise as historically they > convert black into white. which means all those "cubs" going back to > israel for the annual kibbutz from europe,US,Australia etc, are taught > lying, deception, hacking and all the top level mossad skills. This is > infact happening. > > Bernard Madoff is not the only one. > > They will convert the knowledge into war material and money as they > are clamoring for iran. > > How do you explain all the zionist jews buying all the software and > hardware companies and setting up the worlds biggest monopolies. > > Watch the israeli espionage photos > > http://presstv.ir/detail/153770.htmlhttp://presstv.ir/detail/153770.htmlhttp://presstv.ir/detail/153770.html The whole narrative that lying bitch judith miller on lying NY times made up about arabs and alqaeda of sleeper agents and terrorists infact applied to israel and zionists. that is why there are all the airlines alerts not sparing whites coz they know but dont open their mouth that israelis could stage terror attacks and blame on arabs but dead are the innocent. like the 911 they did. and the anthrax From smallpox911 at gmail.com Sat Dec 4 00:02:40 2010 From: smallpox911 at gmail.com (small Pox) Date: Fri, 3 Dec 2010 21:02:40 -0800 (PST) Subject: Google AI challenge: planet war. Lisp won. References: <44a8f48f-e291-463e-a042-d0cbc31a2a4e@z17g2000prz.googlegroups.com> <2a853d74-09d7-4910-8f52-3b42f9c275ae@w21g2000vby.googlegroups.com> <42634615-6233-4082-a7a8-22dff724c7bd@o9g2000pre.googlegroups.com> Message-ID: On Dec 3, 8:56?pm, small Pox wrote: > > > G?bor wrote a blog about it herehttp://quotenil.com/Planet-Wars-Post-Mortem.html > > http://presstv.ir/detail/153770.html > > It is said in the protocols to corrupt the minds of the GOYIM by > > alcohol > gambling > games ? ? ?<------------- > pornography > adulteries > sex > > Watch the photo and proof of israel in LEBANON. these are vicious > murderous criminals and spies. All the intellectual property of the > planet has been stolen by them. betah.co.il was operational for a long > time and just the tip of the iceberg. > > then these criminals helped saudis and other kuwaitis set some forums. > arabic software was developed by them to help the foulish saudis. some > desperate saudis, koreans, vietnam and other were baited and given the > ebooks to spread. > > look how viciously they go for extradition of WIKILEAKS guy Julian > Assange (on false rape charges), but ROMAN POLANSKY is a TRUE RAPIST > of 13 year old innocent German girl in USA. > > Now, it should be somehow made kosher that what the jew has stolen > should me made available to everyone otherwise as historically they > convert black into white. which means all those "cubs" going back to > israel for the annual kibbutz from europe,US,Australia etc, are taught > lying, deception, hacking and all the top level mossad skills. This is > infact happening. > > Bernard Madoff is not the only one. > > They will convert the knowledge into war material and money as they > are clamoring for iran. > > How do you explain all the zionist jews buying all the software and > hardware companies and setting up the worlds biggest monopolies. > > Watch the israeli espionage photos > > http://presstv.ir/detail/153770.htmlhttp://presstv.ir/detail/153770.htmlhttp://presstv.ir/detail/153770.html Hezbollah discovers Israeli spy devices Fri Dec 3, 2010 8:5PM Share | Email | Print Israel has remotely detonated two of its spying devices in southern Lebanon after they were discovered by the Hezbollah resistance movement. At least two Lebanese were injured after the espionage devises were detonated remotely in Wadi al-Qaysiyya outside of Majdal Selem near the southern coastal city of Tyre on Friday. "Telecom technicians of the resistance (Hezbollah) managed to discover a spying device the enemy had planted in Wadi al-Qaysiyya. The enemy detonated its devices as a result of the discovery," said a statement released by the Hezbollah media relations department. "This technical espionage by the enemy is part of the persistent Israeli violations of the national telecom network with the aim of infiltrating and controlling it, which represents a breach of sovereignty and an attempt at violating the security and safety of the Lebanese," the statement added. No other details were immediately available. Friday's incident came just two days after Israeli troops opened fire on Lebanon from two border posts near Shebaa Farms. HM/HGH/MMN Related Stories: 'Israeli troops open fire on Lebanon' Ten Israeli warplanes fly over Lebanon Israeli planes enter Lebanon airspace Comments Add Comment Click Here Note: The views expressed and the links provided on our comment pages are the personal views of individual contributors and do not necessarily reflect the views of Press TV. Damon 12/3/2010 10:17:48 PMUh.... the last I heard, Lebaon and Israel are still in a state of beliggerancy, so why is the presence of spy devices a surprise? From smallpox911 at gmail.com Sat Dec 4 01:57:59 2010 From: smallpox911 at gmail.com (small Pox) Date: Fri, 3 Dec 2010 22:57:59 -0800 (PST) Subject: Unknown function operation deciphering, exercise in readability by program reasoning Message-ID: <46365e1d-42d8-4b3b-8e69-941472467472@u25g2000pra.googlegroups.com> Rules : @1@ No execution of the function, only checking syntax @2@ No profiling using a debugger or profiler @3@ Editing allowed to make simpler variables (defun unknown-function (nano-thermite-911-FBI-fat-per-diem-bustards- kept-their-odious-mouth-shut-on-anthrax-and-911-lie) (let (BERNARD-MADOFF-PHILIP-MARKOFF-MIKHAIL-KHODORKOVSKY-NEOCONS- PAUL-WOLFOWITZ-LEWIS-SCOOTER-LIBBY-MOSHE-KATSEV-MOSSAD-DUBAI-MURDERERS I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN-SPEECH-ON-KHAZARS) (while (or I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN- SPEECH-ON-KHAZARS nano-thermite-911-FBI-fat-per-diem-bustards-kept- their-odious-mouth-shut-on-anthrax-and-911-lie) (if nano-thermite-911-FBI-fat-per-diem-bustards-kept-their- odious-mouth-shut-on-anthrax-and-911-lie (if (consp nano-thermite-911-FBI-fat-per-diem-bustards-kept- their-odious-mouth-shut-on-anthrax-and-911-lie) (setq I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN- SPEECH-ON-KHAZARS (cons (cdr nano-thermite-911-FBI-fat-per-diem- bustards-kept-their-odious-mouth-shut-on-anthrax-and-911-lie) I-AM-THE-WITNESS-DOT-COM-has-MR- BENJAMIN-FREEDMAN-SPEECH-ON-KHAZARS) nano-thermite-911-FBI-fat-per-diem-bustards-kept- their-odious-mouth-shut-on-anthrax-and-911-lie (car nano-thermite-911- FBI-fat-per-diem-bustards-kept-their-odious-mouth-shut-on-anthrax- and-911-lie)) (setq BERNARD-MADOFF-PHILIP-MARKOFF-MIKHAIL-KHODORKOVSKY- NEOCONS-PAUL-WOLFOWITZ-LEWIS-SCOOTER-LIBBY-MOSHE-KATSEV-MOSSAD-DUBAI- MURDERERS (cons nano-thermite-911-FBI-fat-per-diem-bustards-kept-their- odious-mouth-shut-on-anthrax-and-911-lie BERNARD-MADOFF-PHILIP-MARKOFF- MIKHAIL-KHODORKOVSKY-NEOCONS-PAUL-WOLFOWITZ-LEWIS-SCOOTER-LIBBY-MOSHE- KATSEV-MOSSAD-DUBAI-MURDERERS) nano-thermite-911-FBI-fat-per-diem-bustards-kept- their-odious-mouth-shut-on-anthrax-and-911-lie nil)) (setq nano-thermite-911-FBI-fat-per-diem-bustards-kept-their- odious-mouth-shut-on-anthrax-and-911-lie (car I-AM-THE-WITNESS-DOT-COM- has-MR-BENJAMIN-FREEDMAN-SPEECH-ON-KHAZARS) I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN-SPEECH- ON-KHAZARS (cdr I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN- SPEECH-ON-KHAZARS)))) BERNARD-MADOFF-PHILIP-MARKOFF-MIKHAIL-KHODORKOVSKY-NEOCONS-PAUL- WOLFOWITZ-LEWIS-SCOOTER-LIBBY-MOSHE-KATSEV-MOSSAD-DUBAI-MURDERERS)) From tw55413 at gmail.com Sat Dec 4 03:22:01 2010 From: tw55413 at gmail.com (erikj) Date: Sat, 4 Dec 2010 00:22:01 -0800 (PST) Subject: position independent build of python References: Message-ID: On Dec 3, 5:05?pm, de... at web.de (Diez B. Roggisch) wrote: > erikj writes: > > If my understanding is correct, the sys.prefix variable holds the root > > directory python uses to find related files, and eg its site-packages. > > > the value of sys.prefix is specified at compile time. > > > it seems that on windows, when I build/install python at one location, > > and > > later move it to another location, python will find all its needs > > relative to the new location. That's indeed a good idea, I will investigate it. But if this works, I still need some kind of wrapper around python itself... > > > however, when I do the same on linux, python keeps looking for > > its dependencies in the build location. > > > is there a possibility to have it always look at a position relative > > to the location of the executable ? ?the goal is to be able to build > > python on one machine, and then simply copy the build tree to > > other machines at other locations. > > Maybe looking at virtualenv, especially with the --no-site-packages > variable set gives you a hint. AFAIK there are some hard-coded paths > involved, but not inside compiled code. Maybe you can remedy that somehow. > > Diez From progreo at gmail.com Sat Dec 4 04:48:14 2010 From: progreo at gmail.com (robos85) Date: Sat, 4 Dec 2010 01:48:14 -0800 (PST) Subject: PIL how to enlarge image Message-ID: <365f5ebd-8e77-4741-b4ee-36d81f8da279@v17g2000prc.googlegroups.com> Hi, I try to enlarge original image. I have image in size: 100x100 and I want to make it 120x120. But resize() doesn't make it bigger. Is there any method for that? From __peter__ at web.de Sat Dec 4 05:36:03 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 04 Dec 2010 11:36:03 +0100 Subject: import module doesn't work for new package References: <1e9b4955-d60d-44f0-9b62-2ce50be35fdf@u9g2000pra.googlegroups.com> Message-ID: goldtech wrote: > I tried install a Python - would the word be "package"? - on Ubuntu > 10.10. Could you tell me how to fix? I would be grateful, is it a path > problem? Thanks. Lee If you are talking about http://paul.giannaros.org/pykhtml/ , this package requires kde3 while you are /probably/ running kde4. > giga1 at giga1:~/Desktop/pykhtml-0.2$ sudo python setup.py install > [sudo] password for giga1: > running install > running build > running build_py > creating build > creating build/lib.linux-i686-2.6 > creating build/lib.linux-i686-2.6/pykhtml > copying pykhtml/dom.py -> build/lib.linux-i686-2.6/pykhtml > copying pykhtml/__init__.py -> build/lib.linux-i686-2.6/pykhtml > running install_lib > running install_egg_info > Removing /usr/local/lib/python2.6/dist-packages/PyKHTML-0.2.egg-info > Writing /usr/local/lib/python2.6/dist-packages/PyKHTML-0.2.egg-info > > then: > >>>> import pykhtml > Traceback (most recent call last): > File "", line 1, in > File "pykhtml/__init__.py", line 3, in > import khtml, kdecore, kdeui, kio, dcopext > ImportError: No module named khtml This would become from PyKDE4 import khtml, kdecore, kdeui, kio in KDE4, but there are /probably/ API changes. DCOP which is /probably/ what dcopext provides has been replaced with dbus. Given these changes and the fact that pykhtml development has stopped in early 2008 you'd /probably/ have to put in a lot of effort to make it work with your current desktop environment. From alain at dpt-info.u-strasbg.fr Sat Dec 4 05:58:16 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Sat, 04 Dec 2010 11:58:16 +0100 Subject: PIL how to enlarge image References: <365f5ebd-8e77-4741-b4ee-36d81f8da279@v17g2000prc.googlegroups.com> Message-ID: <87sjydst2v.fsf@dpt-info.u-strasbg.fr> robos85 writes: > Hi, I try to enlarge original image. > I have image in size: 100x100 and I want to make it 120x120. > But resize() doesn't make it bigger. Is there any method for that? You have to use i.transform() -- Alain. From vs at it.uu.se Sat Dec 4 08:32:53 2010 From: vs at it.uu.se (Virgil Stokes) Date: Sat, 04 Dec 2010 14:32:53 +0100 Subject: A web site using Python Message-ID: <4CFA4305.10004@it.uu.se> I would like to design a web site that can be used to help people to find a cat that they can adopt. Note, this is a non-profit project, but one that I believe to be quite important. Here are some of my initial thoughts on this project. /Site purpose:/ *To provide a web site for anyone to look at information on cats at this home, and how they can adopt one or more of these homeless cats.* /Some features of the site:/ 1. A cat database that I as the web site designer would create. This database would contain an entry for each cat available for adoption. It would include such things as the name, sex, age, paths to image(s) and/or video(s) of the cat, health status, etc (see below). 2. Anyone accessing this site should be able to easily navigate around it and to examine entries in this database. The client (designated person at the home where the cats are kept for adoption) would be given privileges to modify the database (add, delete, and modify entries). The user interface for the client to update the database should be very easy to use. This GUI provided to the client for modification of the database would be written in Python. 3. There would be no inputs to this web site. There would be an embedded link for a potential customer to send an email to the responsible person (bringing up their email client). 4. Track number of visitors to the site. /Preliminary notes on the database/ Fields: - ID code (key) - Name - Sex (M / F) - Neutered / Not neutered - Age (estimated) - Type (breed) - Tagged (chip or ear marking)/ Not tagged - Checked In date (yy/mm/dd) - Checked Out date (yy/mm/dd) - Status (needs home / has home) - Social state (1,2,3,4,5) - Health state (1,2,3,4,5) - Companion state (1,2,3,4,5) - Image (file name) % multiple files allowed - Video (file name) % multiple files allowed - Medical/vet data (text on vaccinations, etc.) - General information (text on cat that includes comments, observations, etc.) ------------------------------------------------------------------------------- Notes on database: * state = 1, Best 5, Worst Examples: Social state = 5, very unfriendly, afraid, etc. 3, can touch if careful 1, very friendly, unafraid Health state = 5, not in good health (e.g. infection) 3, only minor health problems 1, in very good health Companion state = 5, must have another cat or cats as company 3, could be with other cat(s) company 1, does not need the company of another cat Now, with this initial information (granted this is very rough), my question: *How, armed with Python 2.6 (or 2.7) and all of the Python packages available, should I attack the problem of getting this web site up and running on a Windows platform?* Please keep in mind that do have some experience with Python and HTML; but, this would be my first web site project using Python. Any suggestions, study plan, references, etc. would be welcomed. --V -------------- next part -------------- An HTML attachment was scrubbed... URL: From kontakt at toomuchcookies.net Sat Dec 4 09:00:43 2010 From: kontakt at toomuchcookies.net (Omar Abo-Namous) Date: Sat, 04 Dec 2010 15:00:43 +0100 Subject: class attribute confusion In-Reply-To: <87k4jqcxs2.fsf@gmail.com> References: <87k4jqcxs2.fsf@gmail.com> Message-ID: <4CFA498B.7070905@toomuchcookies.net> Am 03.12.2010 23:11, schrieb Arnaud Delobelle: > OAN writes: > >> Hi, >> >> i was having a problem with class attributes initiated outside of >> __init__. This code is a demonstration of what i mean: >> >> class A(): >> mylist = [] >> def __init__(self): >> self.mylist.append(1) >> pass >> >> class B(A): >> def __init__(self): >> A.__init__(self) >> self.mylist.append(2) >> >> v = A() >> print 'v:',v.mylist >> x = B() >> print 'x:',x.mylist >> y = B() >> print 'y:',y.mylist >> z = A() >> print 'z:',z.mylist >> print 'v:',v.mylist >> >> I would expect the following result: >> >> v: [1] >> x: [1, 2] >> y: [1, 2] >> z: [1] >> v: [1] >> >> Who wouldn't, right? But actually python 2.6(.6) gives me the >> following result: >> >> v: [1] >> x: [1, 1, 2] >> y: [1, 1, 2, 1, 2] >> z: [1, 1, 2, 1, 2, 1] >> v: [1, 1, 2, 1, 2, 1] >> >> The four variables v,x,y and z now actually share the same 'mylist'!! >> To get the correct results, i have to initialize 'mylist' inside of >> the __init__ method! > Yes. See below. > >> I think this behaviour is totally wrong, since it seems >> A.__init__(self) is changing the value inside of A() not inside of the >> object variable 'self' (that should be x or y)!! > It's not wrong at all. You expect "mylist" to behave as an instance > attribute, but you defined it as a class attribute. Instance attributes > are naturally initialised in the __init__() method. > Could you please point me to a reference in the doc?? Thanks in advance. From steve+comp.lang.python at pearwood.info Sat Dec 4 09:34:38 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Dec 2010 14:34:38 GMT Subject: class attribute confusion References: <87k4jqcxs2.fsf@gmail.com> Message-ID: <4cfa517e$0$30003$c3e8da3$5496439d@news.astraweb.com> On Sat, 04 Dec 2010 15:00:43 +0100, Omar Abo-Namous wrote: >>> I think this behaviour is totally wrong, since it seems >>> A.__init__(self) is changing the value inside of A() not inside of the >>> object variable 'self' (that should be x or y)!! >> It's not wrong at all. You expect "mylist" to behave as an instance >> attribute, but you defined it as a class attribute. Instance >> attributes are naturally initialised in the __init__() method. >> > Could you please point me to a reference in the doc?? http://docs.python.org/reference/datamodel.html In the section about classes: "Class attribute assignments update the class?s dictionary ..." and in the section about class instances: "Attribute assignments and deletions update the instance?s dictionary, never a class?s dictionary." In this specific example, you also have to realise that mylist.append() mutates the list in place, and doesn't create a new list. It doesn't matter whether the list comes from a global variable, a local variable, an instance attribute or a class attribute, append is always an inplace operation. -- Steven From hidura at gmail.com Sat Dec 4 09:54:44 2010 From: hidura at gmail.com (hidura at gmail.com) Date: Sat, 04 Dec 2010 14:54:44 +0000 Subject: A web site using Python In-Reply-To: <4CFA4305.10004@it.uu.se> Message-ID: <0014853d0112e94116049696d504@google.com> I am working on a tool that can create an application like that without write server code, but the system is write in Python3.1 On Dec 4, 2010 9:32am, Virgil Stokes wrote: > I would like to design a web site that can be used to help > people to find a cat > that they can adopt. Note, this is a non-profit project, but one > that I > believe to be quite important. Here are some of my initial > thoughts on this > project. > Site purpose: > To provide a web site for anyone to look at information on cats > at this home, and how > they can adopt one or more of these homeless cats. > Some features of the site: > 1. A cat database that I as the web site designer would create. > This database would > contain an entry for each cat available for adoption. It would > include such things > as the name, sex, age, paths to image(s) and/or video(s) of the > cat, health status, > etc (see below). > 2. Anyone accessing this site should be able to easily navigate > around it and to > examine entries in this database. The client (designated person > at the home > where the cats are kept for adoption) would be given privileges > to modify the > database (add, delete, and modify entries). The user interface > for the client > to update the database should be very easy to use. This GUI > provided to the > client for modification of the database would be written in > Python. > 3. There would be no inputs to this web site. There would be an > embedded link for a > potential customer to send an email to the responsible person > (bringing up > their email client). > 4. Track number of visitors to the site. > Preliminary notes on the database > Fields: > - ID code (key) > - Name > - Sex (M / F) > - Neutered / Not neutered > - Age (estimated) > - Type (breed) > - Tagged (chip or ear marking)/ Not tagged > - Checked In date (yy/mm/dd) > - Checked Out date (yy/mm/dd) > - Status (needs home / has home) > - Social state (1,2,3,4,5) > - Health state (1,2,3,4,5) > - Companion state (1,2,3,4,5) > - Image (file name) % multiple files allowed > - Video (file name) % multiple files allowed > - Medical/vet data (text on vaccinations, etc.) > - General information (text on cat that includes comments, > observations, etc.) > ------------------------------------------------------------------------------- > Notes on database: > * state = 1, Best > 5, Worst > Examples: > Social state = 5, very unfriendly, afraid, etc. > 3, can touch if careful > 1, very friendly, unafraid > Health state = 5, not in good health (eg infection) > 3, only minor health problems > 1, in very good health > Companion state = 5, must have another cat or cats as company > 3, could be with other cat(s) company > 1, does not need the company of another cat > Now, with this initial information (granted this is very > rough), my question: > How, armed with Python 2.6 (or 2.7) and all of the Python > packages available, > should I attack the problem of getting this web site up and > running on a Windows > platform? > Please keep in mind that do have some experience with Python and > HTML; but, this > would be my first web site project using Python. > Any suggestions, study plan, references, etc. would be welcomed. > --V -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Sat Dec 4 11:40:54 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 04 Dec 2010 11:40:54 -0500 Subject: Comparison with False - something I don't understand In-Reply-To: References: <877hfs2zia.fsf@benfinney.id.au> Message-ID: <4CFA6F16.2060001@holdenweb.com> On 12/2/2010 11:42 PM, Harishankar wrote: > One of the reasons why I feared to do this is because I need to know each > and every exception that might be thrown by the function and litter my > top-level code with too many exception handlers. > You appear to be suffering from the delusion that all exceptions must be caught and handled. This is far from being the case. But still, better to have your top-level code "littered with exception handlers" than to have your functions "littered with if statements". Quite often it's impossible for the function to know what needs to be done when a specific conditions arises, in which case (presumably) you have to return some error code and test for that ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sat Dec 4 11:40:54 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 04 Dec 2010 11:40:54 -0500 Subject: Comparison with False - something I don't understand In-Reply-To: References: <877hfs2zia.fsf@benfinney.id.au> Message-ID: <4CFA6F16.2060001@holdenweb.com> On 12/2/2010 11:42 PM, Harishankar wrote: > One of the reasons why I feared to do this is because I need to know each > and every exception that might be thrown by the function and litter my > top-level code with too many exception handlers. > You appear to be suffering from the delusion that all exceptions must be caught and handled. This is far from being the case. But still, better to have your top-level code "littered with exception handlers" than to have your functions "littered with if statements". Quite often it's impossible for the function to know what needs to be done when a specific conditions arises, in which case (presumably) you have to return some error code and test for that ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From v.harishankar at gmail.com Sat Dec 4 12:07:45 2010 From: v.harishankar at gmail.com (Harishankar) Date: Sat, 4 Dec 2010 17:07:45 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> <4CFA6F16.2060001@holdenweb.com> Message-ID: > You appear to be suffering from the delusion that all exceptions must be > caught and handled. This is far from being the case. But still, better > to have your top-level code "littered with exception handlers" than to > have your functions "littered with if statements". Of course not. But going by the replies here, it appears that Python has made exceptions as the "norm" for error handling which is ironical considering the meaning of the word "exception". I find a bit cumbersome that exceptions are advocated for certain conditions which can be sanely worked around in the application's logic and even avoided, rather than waiting for them to get caught and providing an unsatisfactory result. > > Quite often it's impossible for the function to know what needs to be > done when a specific conditions arises, in which case (presumably) you > have to return some error code and test for that ... Not necessarily. I wasn't talking about low-level or built-in exceptions. I was talking about using exceptions in my programming where often the function is reasonably confident of the kind of errors it is likely to incur. I did not start this as a criticism of Python's exceptions as such. I just expressed my personal aversion to using them in my own code. However, in my next project I have started using exceptions and will keep an open mind on how it turns out. So far it doesn't seem too bad. > > regards > Steve -- Harishankar (http://harishankar.org http://lawstudentscommunity.com) From darcy at druid.net Sat Dec 4 12:41:15 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sat, 4 Dec 2010 12:41:15 -0500 Subject: Comparison with False - something I don't understand In-Reply-To: References: <877hfs2zia.fsf@benfinney.id.au> <4CFA6F16.2060001@holdenweb.com> Message-ID: <20101204124115.712e6983.darcy@druid.net> On Sat, 4 Dec 2010 17:07:45 +0000 (UTC) Harishankar wrote: > Of course not. But going by the replies here, it appears that Python has > made exceptions as the "norm" for error handling which is ironical > considering the meaning of the word "exception". I find a bit cumbersome > that exceptions are advocated for certain conditions which can be sanely > worked around in the application's logic and even avoided, rather than > waiting for them to get caught and providing an unsatisfactory result. It just seems to me that you have a semantic issue rather than a technical one. If the word "exception" was replaced by "check" or something else would that make the process easier to swallow? try: somefunc() check ValueError: handle_error() Whatever it's called it's just flow control. > > Quite often it's impossible for the function to know what needs to be > > done when a specific conditions arises, in which case (presumably) you > > have to return some error code and test for that ... > > Not necessarily. I wasn't talking about low-level or built-in exceptions. > I was talking about using exceptions in my programming where often the > function is reasonably confident of the kind of errors it is likely to > incur. I did not start this as a criticism of Python's exceptions as > such. I just expressed my personal aversion to using them in my own code. > > However, in my next project I have started using exceptions and will keep > an open mind on how it turns out. So far it doesn't seem too bad. Open minds are good. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From gnarlodious at gmail.com Sat Dec 4 13:33:01 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Sat, 4 Dec 2010 10:33:01 -0800 (PST) Subject: Print recent CGI error Message-ID: <98b43d3b-01aa-4a6a-8288-71b65435d3c2@k38g2000vbc.googlegroups.com> I have a serious error that causes the process to crash. Apache refuses to log the error and it only happens on the server, not on the dev machine. Problem is, I can't figure out how to get the most recent error. I can find all sorts of pages telling how to print a specific error, but how to get an unknown error: Here is where I am: NowCookie.load(savedCookie) try: savedCookie=NowCookie['Sectrum'].value # PROCESS CRASHES HERE except: print("Content-type:text/html\n\n") print("???") # PRINT WHATEVER ERROR OCCURRED quit() There must be something so simple I am missing... This is Python 3. -- Gnarlie From DekuDekuplex at Yahoo.com Sat Dec 4 13:49:45 2010 From: DekuDekuplex at Yahoo.com (Benjamin L. Russell) Date: Sun, 05 Dec 2010 03:49:45 +0900 Subject: Google AI challenge: planet war. Lisp won. References: <44a8f48f-e291-463e-a042-d0cbc31a2a4e@z17g2000prz.googlegroups.com> <2a853d74-09d7-4910-8f52-3b42f9c275ae@w21g2000vby.googlegroups.com> <42634615-6233-4082-a7a8-22dff724c7bd@o9g2000pre.googlegroups.com> Message-ID: small Pox writes: >> > G?bor wrote a blog about it herehttp://quotenil.com/Planet-Wars-Post-Mortem.html > > http://presstv.ir/detail/153770.html > > It is said in the protocols to corrupt the minds of the GOYIM by > > alcohol > gambling > games <------------- > pornography > adulteries > sex Yeah, riiight. So it's a crime to have any fun in life, right? Go get a life. -- Benjamin L. Russell From starglider.dev at gmail.com Sat Dec 4 14:12:08 2010 From: starglider.dev at gmail.com (starglider develop) Date: Sat, 4 Dec 2010 19:12:08 +0000 Subject: Backup postgresql database from python Message-ID: Hi, I need to backup a postgresql database from python withour using pg_dump! Is any way of doing that? Thank you in advance for your help. Zorze -------------- next part -------------- An HTML attachment was scrubbed... URL: From darcy at druid.net Sat Dec 4 14:32:18 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sat, 4 Dec 2010 14:32:18 -0500 Subject: Backup postgresql database from python In-Reply-To: References: Message-ID: <20101204143218.bbe3d2ed.darcy@druid.net> On Sat, 4 Dec 2010 19:12:08 +0000 starglider develop wrote: > I need to backup a postgresql database from python withour using pg_dump! > Is any way of doing that? Probably. I guess the first question is why can't you use pg_dump? That might give us a clue as to the requirements. Any other details would be good too. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From drsalists at gmail.com Sat Dec 4 14:33:46 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 4 Dec 2010 11:33:46 -0800 Subject: Print recent CGI error In-Reply-To: <98b43d3b-01aa-4a6a-8288-71b65435d3c2@k38g2000vbc.googlegroups.com> References: <98b43d3b-01aa-4a6a-8288-71b65435d3c2@k38g2000vbc.googlegroups.com> Message-ID: I've sometimes got similar situations in CGI, that turned out to be because of a syntax error that kept apache from being able to run the script. What if you just run the script at the command line? It should either error out due to lack of a CGI environment/arguments, but hopefully it'll give you an error message that'll be useful. Also, you might be able to get some mileage out of finding out what env vars and command line options are being passed, and running from the command line with those. On Sat, Dec 4, 2010 at 10:33 AM, Gnarlodious wrote: > I have a serious error that causes the process to crash. Apache > refuses to log the error and it only happens on the server, not on the > dev machine. Problem is, I can't figure out how to get the most recent > error. I can find all sorts of pages telling how to print a specific > error, but how to get an unknown error: > > Here is where I am: > > NowCookie.load(savedCookie) > try: > ? ?savedCookie=NowCookie['Sectrum'].value ?# PROCESS CRASHES HERE > except: > ? ?print("Content-type:text/html\n\n") > ? ?print("???") ?# PRINT WHATEVER ERROR OCCURRED > ? ?quit() > > There must be something so simple I am missing... > > This is Python 3. > > -- Gnarlie > -- > http://mail.python.org/mailman/listinfo/python-list > From philip at semanchuk.com Sat Dec 4 14:52:37 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Sat, 4 Dec 2010 14:52:37 -0500 Subject: Backup postgresql database from python In-Reply-To: <20101204143218.bbe3d2ed.darcy@druid.net> References: <20101204143218.bbe3d2ed.darcy@druid.net> Message-ID: On Dec 4, 2010, at 2:32 PM, D'Arcy J.M. Cain wrote: > On Sat, 4 Dec 2010 19:12:08 +0000 > starglider develop wrote: >> I need to backup a postgresql database from python withour using pg_dump! >> Is any way of doing that? > > Probably. I guess the first question is why can't you use pg_dump? > That might give us a clue as to the requirements. Excellent point. No offense to the OP, but this isn't really a Python question. You could re-implement pg_dump in Python, Javascript, or any language you like and you'd have your solution. That's probably not what you were looking for though. As D'Arcy said, the first thing to establish is why you want to avoid pg_dump. Another important question is whether or not you expect the database to be in use while you're doing backups. bye Philip From python at mrabarnett.plus.com Sat Dec 4 15:01:10 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 04 Dec 2010 20:01:10 +0000 Subject: Print recent CGI error In-Reply-To: <98b43d3b-01aa-4a6a-8288-71b65435d3c2@k38g2000vbc.googlegroups.com> References: <98b43d3b-01aa-4a6a-8288-71b65435d3c2@k38g2000vbc.googlegroups.com> Message-ID: <4CFA9E06.6000802@mrabarnett.plus.com> On 04/12/2010 18:33, Gnarlodious wrote: > I have a serious error that causes the process to crash. Apache > refuses to log the error and it only happens on the server, not on the > dev machine. Problem is, I can't figure out how to get the most recent > error. I can find all sorts of pages telling how to print a specific > error, but how to get an unknown error: > > Here is where I am: > > NowCookie.load(savedCookie) > try: > savedCookie=NowCookie['Sectrum'].value # PROCESS CRASHES HERE > except: > print("Content-type:text/html\n\n") > print("???") # PRINT WHATEVER ERROR OCCURRED > quit() > > There must be something so simple I am missing... > > This is Python 3. > You could try something like: import traceback NowCookie.load(savedCookie) try: savedCookie=NowCookie['Sectrum'].value # PROCESS CRASHES HERE except: print("Content-type:text/html\n\n") traceback.print_exception(*sys.exc_info()) # PRINT WHATEVER ERROR OCCURRED quit() From redjohn367 at gmail.com Sat Dec 4 15:32:33 2010 From: redjohn367 at gmail.com (Red John) Date: Sat, 4 Dec 2010 12:32:33 -0800 (PST) Subject: Google AI challenge: planet war. Lisp won. References: <44a8f48f-e291-463e-a042-d0cbc31a2a4e@z17g2000prz.googlegroups.com> <2a853d74-09d7-4910-8f52-3b42f9c275ae@w21g2000vby.googlegroups.com> <42634615-6233-4082-a7a8-22dff724c7bd@o9g2000pre.googlegroups.com> Message-ID: > > Yeah, riiight. ?So it's a crime to have any fun in life, right? ?Go get > a life. > > -- Benjamin L. Russell +1 From gnarlodious at gmail.com Sat Dec 4 16:13:35 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Sat, 4 Dec 2010 13:13:35 -0800 (PST) Subject: Print recent CGI error References: mailman.208.1291492876.2649.python-list@python.org Message-ID: What you posted doesn't work, I don't know why. All I get is a blank page and no Apache error report. There are two problems with this. I am really trying to figure out how to trap an error on the server without exposing my innards to the world, which import cgitb; cgitb.enable() does. The other problem is that no traceback seems to play well with a try-except block. I guess I am forced to use one or the other, but not both. What I really wanted to do is display any error in a simple error statement. This is probably a KeyError, but how am I to know? There must be some way to print a dump of the current thread before it deallocates. -- Gnarlie From python at mrabarnett.plus.com Sat Dec 4 16:48:52 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 04 Dec 2010 21:48:52 +0000 Subject: Print recent CGI error In-Reply-To: References: mailman.208.1291492876.2649.python-list@python.org Message-ID: <4CFAB744.6070204@mrabarnett.plus.com> On 04/12/2010 21:13, Gnarlodious wrote: > What you posted doesn't work, I don't know why. All I get is a blank > page and no Apache error report. > > There are two problems with this. I am really trying to figure out how > to trap an error on the server without exposing my innards to the > world, which import cgitb; cgitb.enable() does. The other problem is > that no traceback seems to play well with a try-except block. I guess > I am forced to use one or the other, but not both. > > What I really wanted to do is display any error in a simple error > statement. This is probably a KeyError, but how am I to know? There > must be some way to print a dump of the current thread before it > deallocates. > Double-check what version of Python is on the server. See if you can write the traceback to a file on the server which you can then download. From see at sig.below Sat Dec 4 16:49:20 2010 From: see at sig.below (Barb Knox) Date: Sun, 05 Dec 2010 10:49:20 +1300 Subject: Unknown function operation deciphering, exercise in readability by program reasoning References: <46365e1d-42d8-4b3b-8e69-941472467472@u25g2000pra.googlegroups.com> Message-ID: In article <46365e1d-42d8-4b3b-8e69-941472467472 at u25g2000pra.googlegroups.com>, small Pox wrote: > Rules : No need to add any additional hurdles -- the code as presented is thoroughly unreadable by humans. > @1@ No execution of the function, only checking syntax What about "desk checking" (a lost art from the oldene dayes)? > @2@ No profiling using a debugger or profiler > > @3@ Editing allowed to make simpler variables Maybe if you had done that yourself before posting it then I would have tried to understand it. As it is, no way. > (defun unknown-function (nano-thermite-911-FBI-fat-per-diem-bustards- > kept-their-odious-mouth-shut-on-anthrax-and-911-lie) > (let (BERNARD-MADOFF-PHILIP-MARKOFF-MIKHAIL-KHODORKOVSKY-NEOCONS- > PAUL-WOLFOWITZ-LEWIS-SCOOTER-LIBBY-MOSHE-KATSEV-MOSSAD-DUBAI-MURDERERS > I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN-SPEECH-ON-KHAZARS) > (while (or I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN- > SPEECH-ON-KHAZARS nano-thermite-911-FBI-fat-per-diem-bustards-kept- > their-odious-mouth-shut-on-anthrax-and-911-lie) > (if nano-thermite-911-FBI-fat-per-diem-bustards-kept-their- > odious-mouth-shut-on-anthrax-and-911-lie > (if (consp nano-thermite-911-FBI-fat-per-diem-bustards-kept- > their-odious-mouth-shut-on-anthrax-and-911-lie) > (setq I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN- > SPEECH-ON-KHAZARS (cons (cdr nano-thermite-911-FBI-fat-per-diem- > bustards-kept-their-odious-mouth-shut-on-anthrax-and-911-lie) > I-AM-THE-WITNESS-DOT-COM-has-MR- > BENJAMIN-FREEDMAN-SPEECH-ON-KHAZARS) > nano-thermite-911-FBI-fat-per-diem-bustards-kept- > their-odious-mouth-shut-on-anthrax-and-911-lie (car nano-thermite-911- > FBI-fat-per-diem-bustards-kept-their-odious-mouth-shut-on-anthrax- > and-911-lie)) > (setq BERNARD-MADOFF-PHILIP-MARKOFF-MIKHAIL-KHODORKOVSKY- > NEOCONS-PAUL-WOLFOWITZ-LEWIS-SCOOTER-LIBBY-MOSHE-KATSEV-MOSSAD-DUBAI- > MURDERERS (cons nano-thermite-911-FBI-fat-per-diem-bustards-kept-their- > odious-mouth-shut-on-anthrax-and-911-lie BERNARD-MADOFF-PHILIP-MARKOFF- > MIKHAIL-KHODORKOVSKY-NEOCONS-PAUL-WOLFOWITZ-LEWIS-SCOOTER-LIBBY-MOSHE- > KATSEV-MOSSAD-DUBAI-MURDERERS) > nano-thermite-911-FBI-fat-per-diem-bustards-kept- > their-odious-mouth-shut-on-anthrax-and-911-lie nil)) > (setq nano-thermite-911-FBI-fat-per-diem-bustards-kept-their- > odious-mouth-shut-on-anthrax-and-911-lie (car I-AM-THE-WITNESS-DOT-COM- > has-MR-BENJAMIN-FREEDMAN-SPEECH-ON-KHAZARS) > I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN-SPEECH- > ON-KHAZARS (cdr I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN- > SPEECH-ON-KHAZARS)))) > BERNARD-MADOFF-PHILIP-MARKOFF-MIKHAIL-KHODORKOVSKY-NEOCONS-PAUL- > WOLFOWITZ-LEWIS-SCOOTER-LIBBY-MOSHE-KATSEV-MOSSAD-DUBAI-MURDERERS)) -- --------------------------- | BBB b \ Barbara at LivingHistory stop co stop uk | B B aa rrr b | | BBB a a r bbb | Quidquid latine dictum sit, | B B a a r b b | altum videtur. | BBB aa a r bbb | ----------------------------- From bavlakes at gmail.com Sat Dec 4 17:34:50 2010 From: bavlakes at gmail.com (Biglakes) Date: Sat, 4 Dec 2010 14:34:50 -0800 (PST) Subject: 3 Sr. Mac OS X Developer Position - West End Toronto, ON (Urgently needed) Message-ID: <4bd1d780-3d1f-4112-8692-165d2fee0928@29g2000prb.googlegroups.com> Here?s the details of a job opportunity I may have for any of you or someone you may know. Below is the job description. Please send me a copy of your resume in word format and state the best time I can give you a call. Please feel free to pass it on to anyone whom you think may fit in the profile as there are currently three (3) openings for this position. It is a full time permanent position with an attractive compensation package. Email me at: lakeside at mtmstaffing.com SENIOR MAC OS X DEVELOPER Our client is an innovative software & consumer products company with advanced media mobility solutions; allowing users to view their content incomparably & experience seamless media mobility. Job Summary: As a Senior MAC OS X Developer, you are an integral member of a team of talented software and systems engineers committed to developing world-class embedded STB software solutions for the digital-TV, consumer electronics, IPTV, cable and broadcasting industries. Job Responsibilities: ? Design and development of iOS application software, with the further goal of using core technologies from the iOS application in a Mac OS X application. ? User interface design and development ? Coordination with human interface specialists ? Re-factoring components to insure proper Cocoa design patterns ? Working with Quality Assurance team on issue identification and resolution ? Testing & implementing multimedia/networking products with a primary focus iPhone ? Writes & debugs multi-threaded applications ? Works closely with team members to quickly diagnose and resolve problems Requirements: ? Bachelors degree or higher in a technical discipline, (e.g.: Computer Science or Electrical Engineering etc) ? Established MAC OS, iPhone & iPad development Experience ? Experience in digital video, audio, cable and/or broadcasting industry ? Minimum 5 Years experience in Objective-C, Cocoa, XCode, Interface Builder, C/C++ on Mac OS X systems (iPhone OS development alone does not qualify) ? Detail oriented, with strong analytical, problem solving and troubleshooting skills ? Networking Experience ? Excellent verbal and written communication From jbiquez at icsmx.com Sat Dec 4 17:42:36 2010 From: jbiquez at icsmx.com (Jorge Biquez) Date: Sat, 04 Dec 2010 16:42:36 -0600 Subject: Which non SQL Database ? Message-ID: <201012042241.oB4Mfcfi079977@krusty.intranet.com.mx> Hello all. Newbie question. Sorry. As part of my process to learn python I am working on two personal applications. Both will do it fine with a simple structure of data stored in files. I now there are lot of databases around I can use but I would like to know yoor advice on what other options you would consider for the job (it is training so no pressure on performance). One application will run as a desktop one,under Windows, Linux, Macintosh, being able to update data, not much, not complex, not many records. The second application, running behind web pages, will do the same, I mean, process simple data, updating showing data. not much info, not complex. As an excersice it is more than enough I guess and will let me learn what I need for now. Talking with a friend about what he will do (he use C only) he suggest to take a look on dBase format file since it is a stable format, fast and the index structure will be fine or maybe go with BD (Berkley) database file format (I hope I understood this one correctly) . Plain files it is not an option since I would like to have option to do rapid searches. What would do you suggest to take a look? If possible available under the 3 plattforms. Thanks in advance for your comments. Jorge Biquez From arnodel at gmail.com Sat Dec 4 18:02:31 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sat, 04 Dec 2010 23:02:31 +0000 Subject: Which non SQL Database ? References: Message-ID: <87d3phcfaw.fsf@gmail.com> Jorge Biquez writes: > Hello all. > > Newbie question. Sorry. > > As part of my process to learn python I am working on two personal > applications. Both will do it fine with a simple structure of data > stored in files. I now there are lot of databases around I can use but > I would like to know yoor advice on what other options you would > consider for the job (it is training so no pressure on > performance). One application will run as a desktop one,under Windows, > Linux, Macintosh, being able to update data, not much, not complex, > not many records. The second application, running behind web pages, > will do the same, I mean, process simple data, updating showing > data. not much info, not complex. As an excersice it is more than > enough I guess and will let me learn what I need for now. > Talking with a friend about what he will do (he use C only) he suggest > to take a look on dBase format file since it is a stable format, fast > and the index structure will be fine or maybe go with BD (Berkley) > database file format (I hope I understood this one correctly) . Plain > files it is not an option since I would like to have option to do > rapid searches. > > What would do you suggest to take a look? If possible available under > the 3 plattforms. Have you considered sqlite3? It is part of the Python standard library. It'll work under GNU/Linux, Windows and Mac OSX. For more details see: http://docs.python.org/library/sqlite3.html -- Arnaud From gnarlodious at gmail.com Sat Dec 4 18:09:13 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Sat, 4 Dec 2010 15:09:13 -0800 (PST) Subject: Which non SQL Database ? References: <87d3phcfaw.fsf@gmail.com> Message-ID: I use sqlite3, it is fairly simple, fast and not too strict. -- Gnarlie From swiftone at swiftone.org Sat Dec 4 18:27:59 2010 From: swiftone at swiftone.org (Brett Ritter) Date: Sat, 4 Dec 2010 18:27:59 -0500 Subject: [Tutor] Which non SQL Database ? In-Reply-To: <201012042241.oB4Mfcfi079977@krusty.intranet.com.mx> References: <201012042241.oB4Mfcfi079977@krusty.intranet.com.mx> Message-ID: On Sat, Dec 4, 2010 at 5:42 PM, Jorge Biquez wrote: > Newbie question. Sorry. If it isn't you're on the wrong list :) > training so no pressure on performance). One application will run as a > desktop one,under Windows, Linux, Macintosh, being able to update data, not > much, not complex, not many records. The important details here are: simple data, low-volume. I'm assuming this is single-user (as in, each instance of your application has it's own DB) > The second application, running behind > ?web pages, will do the same, Is this multiple users, each accessing the same DB? That really changes what you are looking for. If you are dealing with single-user, or only a few users, I'd say look into SQLite - It uses SQL syntax but doesn't run as a server and stores the database as a single file. It's great to use in small projects because the syntax is the same as larger projects, and you can replace with a full-blown multi-user SQL DB if you ever need to without having to rework everything. It's also very simple to use. I believe SQLite (sqlite3) is part of the core library in recent Python versions, or available as a package for older pythons. Berkeley DB is pretty much interchangeable with SQLite in terms of functionality. I much prefer SQLite. If your web application intends to have multiple users interacting with the same data, neither is probably a good fit. -- Brett Ritter / SwiftOne swiftone at swiftone.org From jbiquez at icsmx.com Sat Dec 4 18:43:48 2010 From: jbiquez at icsmx.com (Jorge Biquez) Date: Sat, 04 Dec 2010 17:43:48 -0600 Subject: Which non SQL Database ? In-Reply-To: <87d3phcfaw.fsf@gmail.com> References: <87d3phcfaw.fsf@gmail.com> Message-ID: <201012042343.oB4Nh18D084173@krusty.intranet.com.mx> At 05:02 p.m. 04/12/2010, you wrote: >Jorge Biquez writes: > > > Hello all. > > > > Newbie question. Sorry. > > > > As part of my process to learn python I am working on two personal > > applications. Both will do it fine with a simple structure of data > > stored in files. I now there are lot of databases around I can use but > > I would like to know yoor advice on what other options you would > > consider for the job (it is training so no pressure on > > performance). One application will run as a desktop one,under Windows, > > Linux, Macintosh, being able to update data, not much, not complex, > > not many records. The second application, running behind web pages, > > will do the same, I mean, process simple data, updating showing > > data. not much info, not complex. As an excersice it is more than > > enough I guess and will let me learn what I need for now. > > Talking with a friend about what he will do (he use C only) he suggest > > to take a look on dBase format file since it is a stable format, fast > > and the index structure will be fine or maybe go with BD (Berkley) > > database file format (I hope I understood this one correctly) . Plain > > files it is not an option since I would like to have option to do > > rapid searches. > > > > What would do you suggest to take a look? If possible available under > > the 3 plattforms. > >Have you considered sqlite3? It is part of the Python standard library. >It'll work under GNU/Linux, Windows and Mac OSX. For more details see: > > http://docs.python.org/library/sqlite3.html > >-- >Arnaud >-- Hello all. Ok. sqlite3 seems like it is the best option since it is part of python already.... you are right of course. I do not see a good reason for not using Sqlite3 BUT if for some reason would not be an option.... what plain schema of files would you use? I am sorry to insist. I do not know much about the size tha using Sqlite adds to the application but the idea is that the , application, single user for desktop yes, will be the smallest it can be since the idea is to distribute the executable only. (all this is to have a prototype I have done in other language) For the web part, yes, of course would be multiple users. Thanks to all. Jorge Biquez From cmpython at gmail.com Sat Dec 4 18:59:31 2010 From: cmpython at gmail.com (CM) Date: Sat, 4 Dec 2010 15:59:31 -0800 (PST) Subject: Which non SQL Database ? References: <87d3phcfaw.fsf@gmail.com> Message-ID: <1ae2b7eb-0ccc-420e-8e62-92aafebd827e@p38g2000vbn.googlegroups.com> On Dec 4, 6:43?pm, Jorge Biquez wrote: > At 05:02 p.m. 04/12/2010, you wrote: > > > > >Jorge Biquez writes: > > > > Hello all. > > > > Newbie question. Sorry. > > > > As part of my process to learn python I am working on two personal > > > applications. Both will do it fine with a simple structure of data > > > stored in files. I now there are lot of databases around I can use but > > > I would like to know yoor advice on what other options you would > > > consider for the job (it is training so no pressure on > > > performance). One application will run as a desktop one,under Windows, > > > Linux, Macintosh, being able to update data, not much, not complex, > > > not many records. The second application, running behind ?web pages, > > > will do the same, I mean, process simple data, updating showing > > > data. not much info, not complex. As an excersice it is more than > > > enough I guess and will let me learn what I need for now. > > > Talking with a friend about what he will do (he use C only) he suggest > > > to take a look on dBase format file since it is a stable format, fast > > > and the index structure will be fine or maybe go with BD (Berkley) > > > database file format (I hope I understood this one correctly) . Plain > > > files it is not an option since I would like to have option to do > > > rapid searches. > > > > What would do you suggest to take a look? If possible available under > > > the 3 plattforms. > > >Have you considered sqlite3? It is part of the Python standard library. > >It'll work under GNU/Linux, Windows and Mac OSX. ?For more details see: > > > ? ?http://docs.python.org/library/sqlite3.html > > >-- > >Arnaud > >-- > > Hello all. > > Ok. sqlite3 seems like it is the best option since it is part of > python already.... you are right of course. > > I do not see a good reason for not using Sqlite3 BUT if for some > reason would not be an option.... what plain schema of files would > you use? I am sorry to insist. I do not know much about the size tha > using Sqlite adds to the application but the idea is that the , > application, single user for desktop yes, will be the smallest it can > be since the idea is to distribute the executable only. (all this is > to have a prototype I have done in other language) SQlite itself is around 300 kilobytes. That's negligible. It is also already in Python, so you'd have to purposefully exclude it in creating your executable to save those 300 kb and thus the 1/13th of a second additional time it would take average (3.9 MB/s) users to download your app if it were included. From gnarlodious at gmail.com Sat Dec 4 19:00:25 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Sat, 4 Dec 2010 16:00:25 -0800 (PST) Subject: Print recent CGI error References: mailman.208.1291492876.2649.python-list@python.org Message-ID: <9856eb02-672c-4483-91fd-51095ce2b6d5@d24g2000prj.googlegroups.com> After many curse words I figured it out. A two-stage filter was needed. The 5th line solves the problem of colliding domain cookies: NowCookie=http.cookies.SimpleCookie() # Instantiate a SimpleCookie object savedCookie=os.environ.get('HTTP_COOKIE') # get the cookie string if savedCookie: # Already is a domain cookie NowCookie.load(savedCookie) # Could be any domain cookie if CookieName in NowCookie: # Look for a specific cookie savedCookie=NowCookie[CookieName].value # Load the cookie string into a dict self.List=list(savedCookie.split('~')) # Parse the payload string delimited at tilde return self.List=[hashlib.sha1(repr(time.time()).encode()).hexdigest(), '', ''] # Else default payload self.Write() # Tell the client to remember -- Gnarlie From ben+python at benfinney.id.au Sat Dec 4 19:01:32 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 05 Dec 2010 11:01:32 +1100 Subject: Which non SQL Database ? References: <87d3phcfaw.fsf@gmail.com> Message-ID: <87mxol140z.fsf@benfinney.id.au> Jorge Biquez writes: > I do not see a good reason for not using Sqlite3 BUT if for some > reason would not be an option.... what plain schema of files would you > use? I am sorry to insist. SQLite stores the entire database in a single file. Does that answer the question? I'm not sure I understand. Preferably, check SQLite's own site for answers, since it seems your concerns are not specific to Python. If you have Python-specific concerns about SQLite you'll need to make them more explicit for us to answer them. > I do not know much about the size tha using Sqlite adds to the > application As you noted, SQLite is already in the Python standard library. > For the web part, yes, of course would be multiple users. Systems like Berkeley DB, SQLite, dBase, et cetera achieve their simplicity at the expense of concurrent access to the database. If you want concurrent access to the database by many connections, that's where you need to look at a more sophisticated solution. For efficient concurrent access, a DBMS such as PostgreSQL is the best choice. -- \ ?When I was little, my grandfather used to make me stand in a | `\ closet for five minutes without moving. He said it was elevator | _o__) practice.? ?Steven Wright | Ben Finney From azeynel1 at gmail.com Sat Dec 4 19:15:22 2010 From: azeynel1 at gmail.com (Zeynel) Date: Sat, 4 Dec 2010 16:15:22 -0800 (PST) Subject: How do I get the email address of the person who clicked the link in the email? Message-ID: <63971a7c-8366-471b-ac7f-812f7dab81ba@n10g2000yqd.googlegroups.com> Hello, I am working with Google App Engine python version. The app sends an email to the user with a link to a page to upload an image as an avatar. It would be nice to have the email so that I can associate the avatar with that email. How can I do this? Thank you. From kentilton at gmail.com Sat Dec 4 19:21:52 2010 From: kentilton at gmail.com (kenny) Date: Sat, 4 Dec 2010 16:21:52 -0800 (PST) Subject: SunLisp: A new Lisp drinking society in Ft Lauderdale, FL debuting 7PM, Pearl Harbor Day Message-ID: <57fd943c-eeb5-408a-a249-9ad3cb33013d@e16g2000pri.googlegroups.com> In case you missed it, SunLisp is debuting on Pearl Harbor Day (December 7th) at 7PM. It's been added to the Lisp Meetings Calendar as well. Who: His Kennyness, his CIO Dan (can you say "Lisp jobs"? Sher ya can) and a notable group of Lispers doing a nice project in FL and anyone who cares to join them. When: First Tuesday of the month, 7PM, starting with Pearl Harbor Day, 2010 Where: http://www.thefrogandtoadpub.com/ That is just a couple of blocks below West Cypress Creek aka 62nd on the east side of Powerline. What: They serve beer, wine, and a substantial menu of great food. Why: So we can flame each other in person over beer about the right number of namespaces. Why else? RSVP for this first meet so we know if we should ask them to tidy up the back room which is smashing but lacks tellys. HK (Someone want to pass this along to the yobbos on #lisp?) From contact at xavierho.com Sat Dec 4 19:49:40 2010 From: contact at xavierho.com (Xavier Ho) Date: Sun, 5 Dec 2010 08:49:40 +0800 Subject: How do I get the email address of the person who clicked the link in the email? In-Reply-To: <63971a7c-8366-471b-ac7f-812f7dab81ba@n10g2000yqd.googlegroups.com> References: <63971a7c-8366-471b-ac7f-812f7dab81ba@n10g2000yqd.googlegroups.com> Message-ID: As a suggestion, you can auto-format your email link so that the email of the user is sent as part of the URL GET argument. Cheers, Xav On 5 December 2010 08:15, Zeynel wrote: > Hello, > > I am working with Google App Engine python version. The app sends an > email to the user with a link to a page to upload an image as an > avatar. It would be nice to have the email so that I can associate the > avatar with that email. How can I do this? Thank you. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Sat Dec 4 19:53:00 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 04 Dec 2010 19:53:00 -0500 Subject: Comparison with False - something I don't understand In-Reply-To: References: <877hfs2zia.fsf@benfinney.id.au> <4CFA6F16.2060001@holdenweb.com> Message-ID: On 12/4/2010 12:07 PM, Harishankar wrote: > Of course not. But going by the replies here, it appears that Python has > made exceptions as the "norm" for error handling which is ironical > considering the meaning of the word "exception". In communications parlance, 'exception' = out-of-band signal or return value, while 'return'ed value = in-band signal. A fake in-band return value, like returning None (ok) or False (worse) to *signal* 'I cannot return a list' is still an exception signal, even if 'in-band'. The advantage of out-of-band signals is that they cannot be mistaken for valid in-band signals (return values). If a caller neglects to catch an exception, the process stops, as it should. If a caller neglects to check return values, the process goes on (at least for a while) under the pretense that error codes (in-band exception signals) are valid return values. Neglecting to check return values for error codes is a common bug in C code. At worst, the process eventually return a bad value or performs a bad action. At best, it crashes sometime later, making the bug hard to find. Or a function is called without even storing, let alone checking the return value. This is common for i/o functions. A program may 'finish' without any indication that it failed. If one does the same with Python functions (equally common), any exceptions *will* be passed up until either caught or displayed on the screen with an informative traceback (assuming that the screen is the not source of the error). -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Sat Dec 4 20:59:27 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Dec 2010 01:59:27 GMT Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> <4CFA6F16.2060001@holdenweb.com> Message-ID: <4cfaf1ff$0$30003$c3e8da3$5496439d@news.astraweb.com> On Sat, 04 Dec 2010 17:07:45 +0000, Harishankar wrote: > I find a bit cumbersome > that exceptions are advocated for certain conditions which can be sanely > worked around in the application's logic and even avoided, rather than > waiting for them to get caught and providing an unsatisfactory result. That's surprisingly rare in Python. In fact, I'd go so far as to say that in Python there is *nothing* that you can test for and then have a *guarantee* that it will succeed. Of course, this is mainly of theoretical concern. In practice, "Look Before You Leap" (test first, then process) is often fine. But there are traps to look out for. For example, unless you are running a single- process machine, the following code is subject to race conditions and is not safe: if os.exists(pathname): fp = open(pathname) else: handle_missing_file() Just because the file is there when os.exists() looks for it, doesn't mean it still exists a microsecond later when you try opening it. Or consider this code: if y != 0: result = x/y else: handle_division_by_zero() This is also unsafe unless you know the type of y. Suppose y is an interval quantity that straddles zero, then division by y may fail even though y != 0. -- Steven From jbiquez at icsmx.com Sat Dec 4 21:39:47 2010 From: jbiquez at icsmx.com (Jorge Biquez) Date: Sat, 04 Dec 2010 20:39:47 -0600 Subject: Which non SQL Database ? In-Reply-To: <87mxol140z.fsf@benfinney.id.au> References: <87d3phcfaw.fsf@gmail.com> <87mxol140z.fsf@benfinney.id.au> Message-ID: <201012050238.oB52cpgc098631@krusty.intranet.com.mx> Hello all. Understood perfectly. Will forget other alternatives. Sqlite3 is the best option. Thanks for the explanation and time. Sqlite for single user and Postgresql will be the choice. Thanks all. Take care Jorge Biquez At 06:01 p.m. 04/12/2010, you wrote: >Jorge Biquez writes: > > > I do not see a good reason for not using Sqlite3 BUT if for some > > reason would not be an option.... what plain schema of files would you > > use? I am sorry to insist. > >SQLite stores the entire database in a single file. Does that answer the >question? I'm not sure I understand. > >Preferably, check SQLite's own site for >answers, since it seems your concerns are not specific to Python. If you >have Python-specific concerns about SQLite you'll need to make them more >explicit for us to answer them. > > > I do not know much about the size tha using Sqlite adds to the > > application > >As you noted, SQLite is already in the Python standard library. > > > For the web part, yes, of course would be multiple users. > >Systems like Berkeley DB, SQLite, dBase, et cetera achieve their >simplicity at the expense of concurrent access to the database. > >If you want concurrent access to the database by many connections, >that's where you need to look at a more sophisticated solution. For >efficient concurrent access, a DBMS such as PostgreSQL is the best >choice. > >-- > \ ???When I was little, my grandfather used to make me stand in a | > `\ closet for five minutes without moving. He said it was elevator | >_o__) practice.??? ?Steven Wright | >Ben Finney >-- >http://mail.python.org/mailman/listinfo/python-list From v.harishankar at gmail.com Sat Dec 4 22:26:21 2010 From: v.harishankar at gmail.com (Harishankar) Date: Sun, 5 Dec 2010 03:26:21 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> <4CFA6F16.2060001@holdenweb.com> <4cfaf1ff$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, 05 Dec 2010 01:59:27 +0000, Steven D'Aprano wrote: > Of course, this is mainly of theoretical concern. In practice, "Look > Before You Leap" (test first, then process) is often fine. But there are > traps to look out for. For example, unless you are running a single- > process machine, the following code is subject to race conditions and is > not safe: > > if os.exists(pathname): > fp = open(pathname) > else: > handle_missing_file() > > Just because the file is there when os.exists() looks for it, doesn't > mean it still exists a microsecond later when you try opening it. I understand this line of thinking. And it makes sense to see why it would matter to leave the exception handling mechanism deal with such issues. > > Or consider this code: > > if y != 0: > result = x/y > else: > handle_division_by_zero() > > > This is also unsafe unless you know the type of y. Suppose y is an > interval quantity that straddles zero, then division by y may fail even > though y != 0. Of course in each of these cases the in-built exceptions are used to verify the result of certain system level or lower level operations. My object was not to deprecate the system-level or other low level exceptions thrown by Python, but to consider whether such a mechanism would be a preferable method of handling your own programs error- conditions. The issue to be considered by every programmer is to define what can be defined as the exceptional condition and what is a condition that merits merely different treatment without causing disruption of the normal flow of the program. -- Harishankar (http://harishankar.org http://lawstudentscommunity.com) From vincent.toups at gmail.com Sat Dec 4 22:34:53 2010 From: vincent.toups at gmail.com (jvt) Date: Sat, 4 Dec 2010 19:34:53 -0800 (PST) Subject: Unknown function operation deciphering, exercise in readability by program reasoning References: <46365e1d-42d8-4b3b-8e69-941472467472@u25g2000pra.googlegroups.com> Message-ID: <5e1f79ab-5432-4f18-b896-362b7406c75c@i18g2000yqn.googlegroups.com> On Dec 4, 4:49?pm, Barb Knox wrote: > In article > <46365e1d-42d8-4b3b-8e69-941472467... at u25g2000pra.googlegroups.com>, > ?small Pox wrote: > > > Rules : > > No need to add any additional hurdles -- the code as presented is > thoroughly unreadable by humans. > > > @1@ ?No execution of the function, only checking syntax > > What about "desk checking" (a lost art from the oldene dayes)? > > > @2@ ?No profiling using a debugger or profiler > > > @3@ ?Editing allowed to make simpler variables > > Maybe if you had done that yourself before posting it then I would have > tried to understand it. ?As it is, no way. > > > > > > > > > > > (defun unknown-function (nano-thermite-911-FBI-fat-per-diem-bustards- > > kept-their-odious-mouth-shut-on-anthrax-and-911-lie) > > ? (let (BERNARD-MADOFF-PHILIP-MARKOFF-MIKHAIL-KHODORKOVSKY-NEOCONS- > > PAUL-WOLFOWITZ-LEWIS-SCOOTER-LIBBY-MOSHE-KATSEV-MOSSAD-DUBAI-MURDERERS > > I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN-SPEECH-ON-KHAZARS) > > ? ? (while (or I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN- > > SPEECH-ON-KHAZARS nano-thermite-911-FBI-fat-per-diem-bustards-kept- > > their-odious-mouth-shut-on-anthrax-and-911-lie) > > ? ? ? (if nano-thermite-911-FBI-fat-per-diem-bustards-kept-their- > > odious-mouth-shut-on-anthrax-and-911-lie > > ? ? ? ? ? (if (consp nano-thermite-911-FBI-fat-per-diem-bustards-kept- > > their-odious-mouth-shut-on-anthrax-and-911-lie) > > ? ? ? ? ? ? ? (setq I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN- > > SPEECH-ON-KHAZARS (cons (cdr nano-thermite-911-FBI-fat-per-diem- > > bustards-kept-their-odious-mouth-shut-on-anthrax-and-911-lie) > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? I-AM-THE-WITNESS-DOT-COM-has-MR- > > BENJAMIN-FREEDMAN-SPEECH-ON-KHAZARS) > > ? ? ? ? ? ? ? ? ? ? nano-thermite-911-FBI-fat-per-diem-bustards-kept- > > their-odious-mouth-shut-on-anthrax-and-911-lie (car nano-thermite-911- > > FBI-fat-per-diem-bustards-kept-their-odious-mouth-shut-on-anthrax- > > and-911-lie)) > > ? ? ? ? ? ? (setq BERNARD-MADOFF-PHILIP-MARKOFF-MIKHAIL-KHODORKOVSKY- > > NEOCONS-PAUL-WOLFOWITZ-LEWIS-SCOOTER-LIBBY-MOSHE-KATSEV-MOSSAD-DUBAI- > > MURDERERS (cons nano-thermite-911-FBI-fat-per-diem-bustards-kept-their- > > odious-mouth-shut-on-anthrax-and-911-lie BERNARD-MADOFF-PHILIP-MARKOFF- > > MIKHAIL-KHODORKOVSKY-NEOCONS-PAUL-WOLFOWITZ-LEWIS-SCOOTER-LIBBY-MOSHE- > > KATSEV-MOSSAD-DUBAI-MURDERERS) > > ? ? ? ? ? ? ? ? ? nano-thermite-911-FBI-fat-per-diem-bustards-kept- > > their-odious-mouth-shut-on-anthrax-and-911-lie nil)) > > ? ? ? ? (setq nano-thermite-911-FBI-fat-per-diem-bustards-kept-their- > > odious-mouth-shut-on-anthrax-and-911-lie (car I-AM-THE-WITNESS-DOT-COM- > > has-MR-BENJAMIN-FREEDMAN-SPEECH-ON-KHAZARS) > > ? ? ? ? ? ? ? I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN-SPEECH- > > ON-KHAZARS (cdr I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN- > > SPEECH-ON-KHAZARS)))) > > ? ? BERNARD-MADOFF-PHILIP-MARKOFF-MIKHAIL-KHODORKOVSKY-NEOCONS-PAUL- > > WOLFOWITZ-LEWIS-SCOOTER-LIBBY-MOSHE-KATSEV-MOSSAD-DUBAI-MURDERERS)) > > -- > --------------------------- > | ?BBB ? ? ? ? ? ? ? ?b ? ?\ ? ? Barbara at LivingHistory stop co stop uk > | ?B ?B ? aa ? ? rrr ?b ? ? | > | ?BBB ? a ?a ? r ? ? bbb ? | ? ?Quidquid latine dictum sit, > | ?B ?B ?a ?a ? r ? ? b ?b ?| ? ?altum videtur. > | ?BBB ? ?aa a ?r ? ? bbb ? | ? > ----------------------------- I think this is correct: (defun unknown-function (sym0) (let (sym1 sym2) (while (or sym2 sym0) (if sym0 (if (consp sym0) (setq sym2 (cons (cdr sym0) sym2) sym0 (car sym0)) (setq sym3 sym4 (cons sym0 sym1) sym0 nil)) (setq sym0 (car sym2) sym2 (cdr sym2)))) sym1)) Thank emacs, not me. From aysegul.ozz11 at gmail.com Sat Dec 4 22:52:24 2010 From: aysegul.ozz11 at gmail.com (=?ISO-8859-1?B?R/xsINZncmV0bWVuIC4uLg==?=) Date: Sat, 4 Dec 2010 19:52:24 -0800 (PST) Subject: INVITATION TO AN INFORMATION FOR GROUP (...) Message-ID: <4e3301a4-7f86-4405-ae04-9cf078d6c3db@y23g2000yqd.googlegroups.com> INVITATION TO AN INFORMATION FOR GROUP (...) BUSINESS ADS (ANNOUNCEMENTS) http://nettengelir.blogspot.com/ ___________ ONLINE NEWS SYSTEMS THAT'S REPLY ... http://nettengelir.blogspot.com/ From timr at probo.com Sat Dec 4 23:11:34 2010 From: timr at probo.com (Tim Roberts) Date: Sat, 04 Dec 2010 20:11:34 -0800 Subject: PIL how to enlarge image References: <365f5ebd-8e77-4741-b4ee-36d81f8da279@v17g2000prc.googlegroups.com> Message-ID: <034mf69odlbjn8cflh38aftsmu7o8e381s@4ax.com> robos85 wrote: > >Hi, I try to enlarge original image. >I have image in size: 100x100 and I want to make it 120x120. >But resize() doesn't make it bigger. Is there any method for that? "resize" does not change the image. Instead, it returns the resized image. If you don't need the original any more: img = img.resize((120,120)) -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From usernet at ilthio.net Sat Dec 4 23:13:02 2010 From: usernet at ilthio.net (Tim Harig) Date: Sun, 5 Dec 2010 04:13:02 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> <4CFA6F16.2060001@holdenweb.com> <4cfaf1ff$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-12-05, Harishankar wrote: >> Or consider this code: >> >> if y != 0: >> result = x/y >> else: >> handle_division_by_zero() >> >> >> This is also unsafe unless you know the type of y. Suppose y is an >> interval quantity that straddles zero, then division by y may fail even >> though y != 0. > > Of course in each of these cases the in-built exceptions are used to > verify the result of certain system level or lower level operations. My > object was not to deprecate the system-level or other low level > exceptions thrown by Python, but to consider whether such a mechanism > would be a preferable method of handling your own programs error- > conditions. Whether you happen to like the exception mechanism and syntax or not, it is the idiomatic way of handling errors in Python. Using two different conventions in your code will lead to confusion. I come from a long C background as well. I have come to appreciate the power the Python's exception handling provides. It does everything that you need to do with passing values in C and more. > The issue to be considered by every programmer is to define what can be > defined as the exceptional condition and what is a condition that merits > merely different treatment without causing disruption of the normal flow > of the program. That is an issue much harder to define. Anything it is an obvious error *should* throw an exception. Invalid input is an error. Unusable hardware states are errors. Any invalid request to an object, is an error. Essentially anything that deviates from a normal flow of a program, to handle an exceptional condition, is an error Where it becomes less obvious is when you start using exceptions as part normal control flow. An example is a try it and see methodology. You might for instance have a group of file objects which might or might not support a particular method attribute. You might have a preference for using the attribute; but, have a fallback plan if it does not. One way to handle this is to try to use the attribute and catch the exception raised if it is not present to execute your backup method. I have found this *essential* in some marsaling enviroments where you might not have access to the meta-data of the object that you are working with. Another, questionable but useful use, is to ignore the complex accounting of your position inside of a complex data structure. You can continue moving through the structure until an exception is raised indicating that you have reached a boundary of the structure. Whether you accept uses of exceptions like these is more of a personal quesion. Like many good tools, they can be useful in ways that they were never really designed to be and I would hate to proclude some of these really useful features. This can, of course, be easily abused. I was once writing code, involving complex object marshaling like I described above, with a partner who wasn't totally familiar with Python. We came to a situation where it was impossible to know ahead of time what kind of object (one of two possiblities) we would receive from another marshalled object and had no meta-data to be able to figure out before attempting to access the object. I used a try/except clause to resolve the problem. The next day, I found several poorly conceived try/except blocks in the codebase that my partner had used for control structures using dictionaries because he didn't know of dict.has_key(). I was not so pleased. From memilanuk at gmail.com Sat Dec 4 23:44:47 2010 From: memilanuk at gmail.com (Monte Milanuk) Date: Sat, 04 Dec 2010 20:44:47 -0800 Subject: Which non SQL Database ? In-Reply-To: <201012042343.oB4Nh18D084173@krusty.intranet.com.mx> References: <87d3phcfaw.fsf@gmail.com> <201012042343.oB4Nh18D084173@krusty.intranet.com.mx> Message-ID: <4CFB18BF.5040407@gmail.com> On 12/4/10 3:43 PM, Jorge Biquez wrote: > I do not see a good reason for not using Sqlite3 BUT if for some reason > would not be an option.... what plain schema of files would you use? Would shelve work? From memilanuk at gmail.com Sat Dec 4 23:44:47 2010 From: memilanuk at gmail.com (Monte Milanuk) Date: Sat, 04 Dec 2010 20:44:47 -0800 Subject: Which non SQL Database ? In-Reply-To: <201012042343.oB4Nh18D084173@krusty.intranet.com.mx> References: <87d3phcfaw.fsf@gmail.com> <201012042343.oB4Nh18D084173@krusty.intranet.com.mx> Message-ID: <4CFB18BF.5040407@gmail.com> On 12/4/10 3:43 PM, Jorge Biquez wrote: > I do not see a good reason for not using Sqlite3 BUT if for some reason > would not be an option.... what plain schema of files would you use? Would shelve work? From usernet at ilthio.net Sat Dec 4 23:52:29 2010 From: usernet at ilthio.net (Tim Harig) Date: Sun, 5 Dec 2010 04:52:29 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> <4CFA6F16.2060001@holdenweb.com> <4cfaf1ff$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-12-05, Tim Harig wrote: > Another, questionable but useful use, is to ignore the complex accounting > of your position inside of a complex data structure. You can continue > moving through the structure until an exception is raised indicating > that you have reached a boundary of the structure. Here is another example in this vein. A friend was trying to derive a mathematical formula for determining the possibly distribution of results from rolling arbitrariy numbers of m n-sided dice and needed several sets of data in different directions from which to draw conclusions. I created objects for dice and roles which contained and manipulated multiple dice. To generate a listing of all (non-uniq) possible roles, I would call the first dices increment method read and read the dice faces into a log until the first dice threw an exception that it could not be further incremented. Then I would call reset() on the first dice and increment the second and so on much like the odometer of a car. By using exceptions rather then checking the return value of increment, the state information of the dice was completely isolated to the dice and did not polute into the role structure; the logic for incrementing the dice, logging the role state, and rolling over the dice where all completely seperated and independent of any state; and therefore reseting multiple previous dice as the higher values on the odometer were incremented functioned automatically as each dice threw its own exception recursively rather then requiring logic to handle these multiple rollovers. From no.email at nospam.invalid Sun Dec 5 00:37:22 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 04 Dec 2010 21:37:22 -0800 Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> <4CFA6F16.2060001@holdenweb.com> <4cfaf1ff$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7xfwucye3x.fsf@ruckus.brouhaha.com> Tim Harig writes: > A friend was trying to derive a mathematical formula for determining > the possibly distribution of results from rolling arbitrariy numbers > of m n-sided dice http://en.wikipedia.org/wiki/Multinomial_distribution > To generate a listing of all (non-uniq) possible roles, I would call > the first dices increment method read and read the dice faces into a > log until the first dice threw an exception that it could not be > further incremented. Then I would call reset() on the first dice and > increment the second and so on much like the odometer of a car. from itertools import product m, n = 5, 2 for roll in product(*(xrange(1,m+1) for i in xrange(n))): print roll From steve+comp.lang.python at pearwood.info Sun Dec 5 00:42:18 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Dec 2010 05:42:18 GMT Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> <4CFA6F16.2060001@holdenweb.com> <4cfaf1ff$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cfb263a$0$30003$c3e8da3$5496439d@news.astraweb.com> On Sun, 05 Dec 2010 04:13:02 +0000, Tim Harig wrote: > Anything it is an obvious > error *should* throw an exception. Well, maybe... there are good use-cases for returning a sentinel. E.g. str.find, or the use of quiet NANs in IEEE floating point and decimal maths. NANs and INFs in floating point maths are a good example of the right way to do it. If you forget to check for a NAN, it will propagate through your calculation. INF will, under some circumstances where it is mathematically valid to do so, will disappear leaving a normal result. This means you only need to check your result at the very end of the calculation, not after every step. str.find is more troublesome, because the sentinel -1 doesn't propagate and is a common source of errors: result = string[string.find(delim):] will return a plausible-looking but incorrect result if delim is missing from string. But the convenience and familiarity of str.find means it will probably be around forever. -- Steven From usernet at ilthio.net Sun Dec 5 01:56:59 2010 From: usernet at ilthio.net (Tim Harig) Date: Sun, 5 Dec 2010 06:56:59 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> <4CFA6F16.2060001@holdenweb.com> <4cfaf1ff$0$30003$c3e8da3$5496439d@news.astraweb.com> <7xfwucye3x.fsf@ruckus.brouhaha.com> Message-ID: On 2010-12-05, Paul Rubin wrote: > Tim Harig writes: >> A friend was trying to derive a mathematical formula for determining >> the possibly distribution of results from rolling arbitrariy numbers >> of m n-sided dice > > http://en.wikipedia.org/wiki/Multinomial_distribution I sure he rediscovered much of that. Working that out for himeself was probably far more educational then simply reading an article on the solution. >> To generate a listing of all (non-uniq) possible roles, I would call >> the first dices increment method read and read the dice faces into a >> log until the first dice threw an exception that it could not be >> further incremented. Then I would call reset() on the first dice and >> increment the second and so on much like the odometer of a car. > > from itertools import product > m, n = 5, 2 > for roll in product(*(xrange(1,m+1) for i in xrange(n))): > print roll The fact that I bothered to create classes for the dice and roles, rather then simply iterating over a list of numbers, should tell you that I produced was of a far more flexible nature; including the support for roles with dice having different numbers of sides. I basically created a DSL that he could use to generate and automatically calculate the properties of series of roles defined by one or more varying property. I merely posted a simplied description of the dice-role objects because I thought that it demonstrated how exceptions can provide eligance of control for situations that don't involve what would traditionally be defined as an error. From nagle at animats.com Sun Dec 5 03:01:58 2010 From: nagle at animats.com (John Nagle) Date: Sun, 05 Dec 2010 00:01:58 -0800 Subject: Which non SQL Database ? In-Reply-To: References: <87d3phcfaw.fsf@gmail.com> <201012042343.oB4Nh18D084173@krusty.intranet.com.mx> Message-ID: <4cfb4714$0$1594$742ec2ed@news.sonic.net> On 12/4/2010 8:44 PM, Monte Milanuk wrote: > On 12/4/10 3:43 PM, Jorge Biquez wrote: > >> I do not see a good reason for not using Sqlite3 BUT if for some reason >> would not be an option.... what plain schema of files would you use? > > Would shelve work? There are some systems for storing key-value pairs in files. Underneath "shelve" is some primitive database, dbm, gdbm or bsddb. "bsddb" is deprecated and was removed from Python 3.x. "dbm" has some classic problems. "gdbm" is an improved version of "dbm". None of these handle access from multiple processes, or crash recovery. We're looking at 1979 technology here. SQLite works right when accessed from multiple processes. SQLite is the entry-level database technology for Python today. It handles the hard cases, like undoing transactions after a crash and locking against multiple accesses. Lookup performance is good; simultaneous update by multiple processes, though, is not so good. When you have a web site that has many processes hitting the same database, it's time to move up to MySQL or Postgres. There's a lot of interest in "non-SQL" databases for very large distributed systems. You worry about this if you're Facebook or Google, or are running a big game server farm. John Nagle From borisb0ri5 at gmail.com Sun Dec 5 03:31:43 2010 From: borisb0ri5 at gmail.com (Greg) Date: Sun, 5 Dec 2010 00:31:43 -0800 (PST) Subject: Perceived inconsistency in py3k documentation Message-ID: <724b26b4-8233-4d57-b76f-cd781cf0cd03@z17g2000prz.googlegroups.com> Hello, This is my first post here, so if this is not the correct place to ask this, please direct me to the best place. In looking at the py3k documentation for comparing two classes, two different view points are expressed (at least it seems so to me). 1) At http://docs.python.org/py3k/reference/datamodel.html: "There are no implied relationships among the comparison operators. The truth of x==y does not imply that x!=y is false. Accordingly, when defining __eq__(), one should also define __ne__()..." -- This seems to support the view that if in our code, we would like to use comparison operators <, >, =, !=, etc. then we should define a __lt__(), __gt__(), __eq__(), __ne__(), etc. for each comparison operator we would like. This appears to contrast 2) At http://docs.python.org/py3k/library/stdtypes.html: "Instances of a class cannot be ordered with respect to other instances of the same class, or other types of object, unless the class defines enough of the methods __lt__(), __le__(), __gt__(), and __ge__() (in general, __lt__() and __eq__() are sufficient, if you want the conventional meanings of the comparison operators)." -- This seems to imply that to get all of the operators, only __lt__() and __eq__() need to be defined (just __lt__() should suffice though I thought). So, which is it supposed to be? Or am I reading the documentation wrong? Thanks! -Greg- From no.email at nospam.invalid Sun Dec 5 04:18:22 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 05 Dec 2010 01:18:22 -0800 Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> <4CFA6F16.2060001@holdenweb.com> <4cfaf1ff$0$30003$c3e8da3$5496439d@news.astraweb.com> <7xfwucye3x.fsf@ruckus.brouhaha.com> Message-ID: <7xwrnomvc1.fsf@ruckus.brouhaha.com> Tim Harig writes: > The fact that I bothered to create classes for the dice and roles, rather > then simply iterating over a list of numbers, should tell you that I > produced was of a far more flexible nature; including the support for > roles with dice having different numbers of sides. from itertools import product def n_sided_die(n): return xrange(1, n+1) # make one 3-sided die, one 4-sided die, and one 5-sided die dice = (n_sided_die(3), n_sided_die(4), n_sided_die(5)) for roll in product(*dice): print roll > I merely posted a simplied description of the dice-role objects > because I thought that it demonstrated how exceptions can provide > eligance of control for situations that don't involve what would > traditionally be defined as an error. Exceptions (though sometimes necessary) are messy and I'm having a hard time trying to envision that code being cleaner with them than without them. If you post the actual code maybe that will help me understand. From darragh.ssa at gmail.com Sun Dec 5 04:48:04 2010 From: darragh.ssa at gmail.com (Kruptein) Date: Sun, 5 Dec 2010 01:48:04 -0800 (PST) Subject: Deditor 0.2.3 Message-ID: A new version of the python dedicated linux text-editor has been released! This editor is python specific offering some features to python users like code analyzing, code inspecting, syntax highlighting, ... Information about this project: http://launchpad.net/deditor Information about the latest release: http://kruptein.alwaysdata.net/blag From naseqmohiuddin at gmail.com Sun Dec 5 05:27:08 2010 From: naseqmohiuddin at gmail.com (hollyood) Date: Sun, 5 Dec 2010 02:27:08 -0800 (PST) Subject: s;hlhdlhlah Message-ID: lhdglfhglshglhash From __peter__ at web.de Sun Dec 5 05:37:23 2010 From: __peter__ at web.de (Peter Otten) Date: Sun, 05 Dec 2010 11:37:23 +0100 Subject: Perceived inconsistency in py3k documentation References: <724b26b4-8233-4d57-b76f-cd781cf0cd03@z17g2000prz.googlegroups.com> Message-ID: Greg wrote: > This is my first post here, so if this is not the correct place to ask > this, please direct me to the best place. This is a good place to get general advice and to discuss potential bugs when you are unsure whether they actually are bugs. If you are sure that you ran into a bug in python or want to suggest an improvement of the documentation where it is wrong or unclear or hard to understand you can report to http://bugs.python.org . > In looking at the py3k documentation for comparing two classes, two > different view points are expressed (at least it seems so to me). > 1) At http://docs.python.org/py3k/reference/datamodel.html: > "There are no implied relationships among the comparison operators. > The truth of x==y does not imply that x!=y is false. Accordingly, when > defining __eq__(), one should also define __ne__()..." > -- This seems to support the view that if in our code, we would like > to use comparison operators <, >, =, !=, etc. then we should define a > __lt__(), __gt__(), __eq__(), __ne__(), etc. for each comparison > operator we would like. > > This appears to contrast > 2) At http://docs.python.org/py3k/library/stdtypes.html: > "Instances of a class cannot be ordered with respect to other > instances of the same class, or other types of object, unless the > class defines enough of the methods __lt__(), __le__(), __gt__(), and > __ge__() (in general, __lt__() and __eq__() are sufficient, if you > want the conventional meanings of the comparison operators)." > -- This seems to imply that to get all of the operators, only > __lt__() and __eq__() need to be defined (just __lt__() should suffice > though I thought). > > So, which is it supposed to be? Or am I reading the documentation > wrong? I agree with you that the documentation is at least unclear. The following experiment suggests that list.sort() works correctly if only __lt__() and __eq__() are implemented which in my reading is what your second quote intends to convey. But "enough of the methods..." is a fuzzy statement. The other finding: (1) a != b is emulated with not (a == b) (2) a > b is emulated with b < a is not something I'd expect after reading your first quote, but technically (2) is covered by """... __lt__() and __gt__() are each other?s reflection ...""" $ cat py3compare.py report = True class A: def __init__(self, key, side="A"): self.key = key self.side = side def __eq__(self, other): result = self.key == other.key if report: print(self, "__eq__", other, "-->", result) return result def __lt__(self, other): result = self.key < other.key if report: print(self, "__lt__", other, "-->", result) return result def __str__(self): return "{}({})".format(self.side, self.key) def __repr__(self): return str(self.key) a = A(1, "L") for k in range(3): b = A(k, "R") print("{} != {}: {}\n".format(a, b, a != b)) print("{} > {}: {}\n".format(a, b, a > b)) print() import random items = [] for n in 10, 20: items.extend(map(A, range(n))) random.shuffle(items) report = False items.sort() print(items) print(a <= b) $ python3 py3compare.py L(1) __eq__ R(0) --> False L(1) != R(0): True R(0) __lt__ L(1) --> True L(1) > R(0): True L(1) __eq__ R(1) --> True L(1) != R(1): False R(1) __lt__ L(1) --> False L(1) > R(1): False L(1) __eq__ R(2) --> False L(1) != R(2): True R(2) __lt__ L(1) --> False L(1) > R(2): False [0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] Traceback (most recent call last): File "py3compare.py", line 39, in print(a <= b) TypeError: unorderable types: A() <= A() $ Conclusion: If you can come up with a text that is both correct and clear, don't hesitate to tell us, here or on the bug tracker. Peter PS: The painless way out: always use @functools.total_ordering or the equivalent cookbok recipe. From xdegaye at gmail.com Sun Dec 5 06:15:02 2010 From: xdegaye at gmail.com (Xavier de Gaye) Date: Sun, 5 Dec 2010 12:15:02 +0100 Subject: [ANN] Pyclewn: Vim as a front end to pdb Message-ID: Pyclewn 1.5 has been released at http://pyclewn.sourceforge.net/ Pyclewn is a python program that allows the use of Vim as a front end to gdb and pdb. This release adds support for ``pdb``, the python debugger. + A python script may be run under the control of ``pdb``. For example the current vim buffer may be started and debugged with the vim command ``:Pyclewn pdb %:p`` + One may also attach to a running python process, interrupt the process, manage a debugging session and terminate the debugging session by detaching from the process. A new debugging session may be conducted later on this same process, possibly from another Vim instance. + All the ``pdb`` commands are supported except ``list`` and ``commands``. This includes alias expansion and executing a python statement in the context of the current frame. The new command ``threadstack`` prints the instantaneous backtrace of all the threads, including those that are stuck in a deadlock. * Pdb is currently supported on unix platforms and requires the latest Vim version: Vim 7.3. Python3 is not supported yet. -- Xavier Les Chemins de Lokoti: http://lokoti.alwaysdata.net From usernet at ilthio.net Sun Dec 5 06:21:52 2010 From: usernet at ilthio.net (Tim Harig) Date: Sun, 5 Dec 2010 11:21:52 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> <4CFA6F16.2060001@holdenweb.com> <4cfaf1ff$0$30003$c3e8da3$5496439d@news.astraweb.com> <7xfwucye3x.fsf@ruckus.brouhaha.com> <7xwrnomvc1.fsf@ruckus.brouhaha.com> Message-ID: On 2010-12-05, Paul Rubin wrote: > Tim Harig writes: >> The fact that I bothered to create classes for the dice and roles, rather >> then simply iterating over a list of numbers, should tell you that I >> produced was of a far more flexible nature; including the support for >> roles with dice having different numbers of sides. > > from itertools import product > def n_sided_die(n): return xrange(1, n+1) > > # make one 3-sided die, one 4-sided die, and one 5-sided die > dice = (n_sided_die(3), n_sided_die(4), n_sided_die(5)) > for roll in product(*dice): > print roll Notice that you had to change the structure of your program to accomodate the new possiblity; and, if I throw further requirements at you, you will have to change them again. I didn't want that. What the dice returned may or may not have returned an easy to compute sequence. In fact, for all of the rest of the logic cared, the dice could have computed their value from a previous role of another dice. All of the logic of about what the dice may have returned when asked for their value and how they derived, was encapsilated in the dice themselves. It did not need to be known anywhere else in the program logic. The DSL effectively provided a way do define how the dice decided how to increment themselves, how to choose the value that they returned for their face, and how to know when they could no longer be incremented. The DSL parser generated the dice set from the description given. Creating new dice objects was much easier then attempting to change the logic of how they were rolled. >> I merely posted a simplied description of the dice-role objects >> because I thought that it demonstrated how exceptions can provide >> eligance of control for situations that don't involve what would >> traditionally be defined as an error. > > Exceptions (though sometimes necessary) are messy and I'm having a hard > time trying to envision that code being cleaner with them than without > them. If you post the actual code maybe that will help me understand. Let me get this straight, the same person that was trying to tell me setjmp/longjmp weren't messy thinks exceptions are messy? I have used both. I much prefer the exceptions. I not have to code here to post. The cleanliness of using the exception and calling the dice increments recursively, was that there was no need to figure out which dice needed to be incremented whenever the first die needed to be reset. When a dice needed to be reset, it would raise an exception. This exception would rise through the recursion stack, and thus through the dice, resetting each along the way until it found the one which needed to be incremented or raised past the top call indicating that all of the combinations has been exhausted. There, once the reset condition for the previous dice had been effectively handled, it would be supprested. Had this been done using in band data: 1. The roll object would have needed logic to determine when a reset condition needed to take place, effectively leaking some of the logic from the dice object to the role object. 2. The roll object would have needed logic to determine how to follow the dice which needed to be reset until it found which one needed incrementing. Once again, this logic was better left to the dice walking the resets was automatically handled by the progression of the exception. Even if it wasn't an error, the resets were effectively a exceptional condition from the normal flow of the role object (the primary flow simply being to increment the first die). By using exceptions, I effectively isolated each into its own separate independent flow; and, because they where called separatly, neither needed to have control conditions to detect which was needed. They simply allowed the dice object to decide. From usernet at ilthio.net Sun Dec 5 06:53:24 2010 From: usernet at ilthio.net (Tim Harig) Date: Sun, 5 Dec 2010 11:53:24 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> <4CFA6F16.2060001@holdenweb.com> <4cfaf1ff$0$30003$c3e8da3$5496439d@news.astraweb.com> <7xfwucye3x.fsf@ruckus.brouhaha.com> <7xwrnomvc1.fsf@ruckus.brouhaha.com> Message-ID: On 2010-12-05, Tim Harig wrote: > On 2010-12-05, Paul Rubin wrote: >> Tim Harig writes: >>> The fact that I bothered to create classes for the dice and roles, rather >>> then simply iterating over a list of numbers, should tell you that I >>> produced was of a far more flexible nature; including the support for >>> roles with dice having different numbers of sides. >> >> from itertools import product >> def n_sided_die(n): return xrange(1, n+1) >> >> # make one 3-sided die, one 4-sided die, and one 5-sided die >> dice = (n_sided_die(3), n_sided_die(4), n_sided_die(5)) >> for roll in product(*dice): >> print roll > > Notice that you had to change the structure of your program to accomodate > the new possiblity; and, if I throw further requirements at you, you > will have to change them again. I didn't want that. What the dice > returned may or may not have returned an easy to compute sequence. > In fact, for all of the rest of the logic cared, the dice could have > computed their value from a previous role of another dice. All of the > logic of about what the dice may have returned when asked for their > value and how they derived, was encapsilated in the dice themselves. > It did not need to be known anywhere else in the program logic. > > The DSL effectively provided a way do define how the dice decided how > to increment themselves, how to choose the value that they returned for > their face, and how to know when they could no longer be incremented. > The DSL parser generated the dice set from the description given. > Creating new dice objects was much easier then attempting to change the > logic of how they were rolled. > >>> I merely posted a simplied description of the dice-role objects >>> because I thought that it demonstrated how exceptions can provide >>> eligance of control for situations that don't involve what would >>> traditionally be defined as an error. >> >> Exceptions (though sometimes necessary) are messy and I'm having a hard >> time trying to envision that code being cleaner with them than without >> them. If you post the actual code maybe that will help me understand. > > Let me get this straight, the same person that was trying to tell me > setjmp/longjmp weren't messy thinks exceptions are messy? I have used > both. I much prefer the exceptions. I not have to code here to post. > > The cleanliness of using the exception and calling the dice increments > recursively, was that there was no need to figure out which dice needed > to be incremented whenever the first die needed to be reset. When a dice > needed to be reset, it would raise an exception. This exception would > rise through the recursion stack, and thus through the dice, resetting > each along the way until it found the one which needed to be incremented > or raised past the top call indicating that all of the combinations has > been exhausted. There, once the reset condition for the previous dice > had been effectively handled, it would be supprested. > > Had this been done using in band data: > > 1. The roll object would have needed logic to determine when > a reset condition needed to take place, effectively > leaking some of the logic from the dice object to the > role object. > > 2. The roll object would have needed logic to determine how to > follow the dice which needed to be reset until it found > which one needed incrementing. Once again, this logic > was better left to the dice walking the resets was > automatically handled by the progression of the exception. > > Even if it wasn't an error, the resets were effectively a exceptional > condition from the normal flow of the role object (the primary flow simply > being to increment the first die). By using exceptions, I effectively > isolated each into its own separate independent flow; and, because they > where called separatly, neither needed to have control conditions to detect > which was needed. They simply allowed the dice object to decide. Okay, it occures to me that you don't really need to see much to know what was going on, here is the basic idea of how the role function of the object would have looked like: def role(self, dice): try: self.role(dice.previous()) except diceReset: dice.increment() except endOfDice: raise diceReset From lie.1296 at gmail.com Sun Dec 5 07:08:47 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 05 Dec 2010 23:08:47 +1100 Subject: Which non SQL Database ? In-Reply-To: References: <87d3phcfaw.fsf@gmail.com> Message-ID: <4cfb8021$1@dnews.tpgi.com.au> On 12/05/10 10:43, Jorge Biquez wrote: > I do not see a good reason for not using Sqlite3 BUT if for some reason > would not be an option.... what plain schema of files would you use? Assuming you don't want SQL, you can use filesystem-based database. Most people doesn't realize that a filesystem is essentially a database (of files) and a file explorer is a (sort of) DBMS. It is relatively easy to create a robust (as robust as the filesystem) and fast (as fast as the filesystem) database system by using folders and files (and optionally hard and symbolic links) to store data in hierarchical topology. From python.list at tim.thechases.com Sun Dec 5 08:00:17 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 05 Dec 2010 07:00:17 -0600 Subject: Comparison with False - something I don't understand In-Reply-To: <4cfb263a$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <877hfs2zia.fsf@benfinney.id.au> <4CFA6F16.2060001@holdenweb.com> <4cfaf1ff$0$30003$c3e8da3$5496439d@news.astraweb.com> <4cfb263a$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4CFB8CE1.9000807@tim.thechases.com> On 12/04/2010 11:42 PM, Steven D'Aprano wrote: > On Sun, 05 Dec 2010 04:13:02 +0000, Tim Harig wrote: > str.find is more troublesome, because the sentinel -1 doesn't propagate > and is a common source of errors: > > result = string[string.find(delim):] > > will return a plausible-looking but incorrect result if delim is missing > from string. But the convenience and familiarity of str.find means it > will probably be around forever. Fortunately, string objects offer both .find() and .index() so you can choose whether you want sentinels or exceptions according to your use-case. -tkc From python.list at tim.thechases.com Sun Dec 5 08:03:52 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 05 Dec 2010 07:03:52 -0600 Subject: Which non SQL Database ? In-Reply-To: References: <201012042241.oB4Mfcfi079977@krusty.intranet.com.mx> Message-ID: <4CFB8DB8.3070101@tim.thechases.com> On 12/05/2010 03:41 AM, Alan Gauld wrote: > Why not use SQL? > SQLlite comes with Python, is small, easy to use and if necessary > can be used in-memory and as such fast. The only reason I could see using something other than sqlite3 for such a use-case would be if the OP has to support Python before version 2.5 and can't add/install the sqlite libraries to his deployment platform(s). I've got a couple targets still running 2.4 and regularly mutter under my breath when I reach for sqlite to find it's not there. -tkc From steve at holdenweb.com Sun Dec 5 08:42:47 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 05 Dec 2010 14:42:47 +0100 Subject: How to add data into exisitng Excel file at next open row? In-Reply-To: <2acc7858-e55b-4cfe-8e10-1c0d716a10d4@o4g2000yqd.googlegroups.com> References: <2acc7858-e55b-4cfe-8e10-1c0d716a10d4@o4g2000yqd.googlegroups.com> Message-ID: On 12/3/2010 6:21 PM, noydb wrote: > How can you determine the next open row in an existing Excel file such > that you can start adding data to the cells in that row? As in below, > I want a variable in place of the 6 (row 6 in the four ws1.Cells(x,1) > lines), but have no other way of knowing what row I am on besides > looking to the first free cell in column A. How to do? Examples I > see make it seem really complicated - this can't be that hard. > > Thanks for any help. > > worksheet = "C:\\Excel_Reports\\ea" + ea + "report"# + ".xls" > xlApp = win32com.client.Dispatch("Excel.Application") > xlApp.Visible = 1 > xlApp.Workbooks.Open(worksheet) ## for existing file > ##xlApp.SheetsInNewWorkbook = 1 > ##wb = xlApp.Workbooks() > ws1 = xlApp.Worksheets(1) > > ws1.Cells(6,1).Value = "selection" > ws1.Cells(6,2).Value = count > ws1.Cells(6,3).Value = epcFloat > ws1.Cells(6,8).Value = currentGMT > > wb.SaveAs(worksheet) > wb.Close(False) ## False/1 You might want to take a look at the xlrd library. This lets you read Excel spreadsheets even on Unix platforms and without the use of COM magic. There's also an xlwt module for writing spreadsheets. However I understand that the two together may not be as convenient as modifying a spreadsheet in place. In particular, if sh is a spreadsheet then sh.nrows gives you the number of rows currently used in the sheet. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From roy at panix.com Sun Dec 5 09:22:13 2010 From: roy at panix.com (Roy Smith) Date: Sun, 05 Dec 2010 09:22:13 -0500 Subject: Which non SQL Database ? References: <87d3phcfaw.fsf@gmail.com> <4cfb8021$1@dnews.tpgi.com.au> Message-ID: In article <4cfb8021$1 at dnews.tpgi.com.au>, Lie Ryan wrote: > On 12/05/10 10:43, Jorge Biquez wrote: > > I do not see a good reason for not using Sqlite3 BUT if for some reason > > would not be an option.... what plain schema of files would you use? > > Assuming you don't want SQL, you can use filesystem-based database. Most > people doesn't realize that a filesystem is essentially a database (of > files) and a file explorer is a (sort of) DBMS. It is relatively easy to > create a robust (as robust as the filesystem) and fast (as fast as the > filesystem) database system by using folders and files (and optionally > hard and symbolic links) to store data in hierarchical topology. Another possibility is one of the new breed of non-relational databases. We've been using MongoDB (http://www.mongodb.org/) and so far are happy with it. You can find a bunch of other alternatives in Wikipedia's NoSQL article. From rupertlssmith at googlemail.com Sun Dec 5 12:13:22 2010 From: rupertlssmith at googlemail.com (rupertlssmith at googlemail.com) Date: Sun, 5 Dec 2010 09:13:22 -0800 (PST) Subject: Unknown function operation deciphering, exercise in readability by program reasoning References: <46365e1d-42d8-4b3b-8e69-941472467472@u25g2000pra.googlegroups.com> <5e1f79ab-5432-4f18-b896-362b7406c75c@i18g2000yqn.googlegroups.com> Message-ID: <7a4bf118-1068-432b-ae3f-3a31d1489865@q18g2000vbk.googlegroups.com> On Dec 5, 3:34?am, jvt wrote: > On Dec 4, 4:49?pm, Barb Knox wrote: > > > > > > > In article > > <46365e1d-42d8-4b3b-8e69-941472467... at u25g2000pra.googlegroups.com>, > > ?small Pox wrote: > > > > Rules : > > > No need to add any additional hurdles -- the code as presented is > > thoroughly unreadable by humans. > > > > @1@ ?No execution of the function, only checking syntax > > > What about "desk checking" (a lost art from the oldene dayes)? > > > > @2@ ?No profiling using a debugger or profiler > > > > @3@ ?Editing allowed to make simpler variables > > > Maybe if you had done that yourself before posting it then I would have > > tried to understand it. ?As it is, no way. > > > > (defun unknown-function (nano-thermite-911-FBI-fat-per-diem-bustards- > > > kept-their-odious-mouth-shut-on-anthrax-and-911-lie) > > > ? (let (BERNARD-MADOFF-PHILIP-MARKOFF-MIKHAIL-KHODORKOVSKY-NEOCONS- > > > PAUL-WOLFOWITZ-LEWIS-SCOOTER-LIBBY-MOSHE-KATSEV-MOSSAD-DUBAI-MURDERERS > > > I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN-SPEECH-ON-KHAZARS) > > > ? ? (while (or I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN- > > > SPEECH-ON-KHAZARS nano-thermite-911-FBI-fat-per-diem-bustards-kept- > > > their-odious-mouth-shut-on-anthrax-and-911-lie) > > > ? ? ? (if nano-thermite-911-FBI-fat-per-diem-bustards-kept-their- > > > odious-mouth-shut-on-anthrax-and-911-lie > > > ? ? ? ? ? (if (consp nano-thermite-911-FBI-fat-per-diem-bustards-kept- > > > their-odious-mouth-shut-on-anthrax-and-911-lie) > > > ? ? ? ? ? ? ? (setq I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN- > > > SPEECH-ON-KHAZARS (cons (cdr nano-thermite-911-FBI-fat-per-diem- > > > bustards-kept-their-odious-mouth-shut-on-anthrax-and-911-lie) > > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? I-AM-THE-WITNESS-DOT-COM-has-MR- > > > BENJAMIN-FREEDMAN-SPEECH-ON-KHAZARS) > > > ? ? ? ? ? ? ? ? ? ? nano-thermite-911-FBI-fat-per-diem-bustards-kept- > > > their-odious-mouth-shut-on-anthrax-and-911-lie (car nano-thermite-911- > > > FBI-fat-per-diem-bustards-kept-their-odious-mouth-shut-on-anthrax- > > > and-911-lie)) > > > ? ? ? ? ? ? (setq BERNARD-MADOFF-PHILIP-MARKOFF-MIKHAIL-KHODORKOVSKY- > > > NEOCONS-PAUL-WOLFOWITZ-LEWIS-SCOOTER-LIBBY-MOSHE-KATSEV-MOSSAD-DUBAI- > > > MURDERERS (cons nano-thermite-911-FBI-fat-per-diem-bustards-kept-their- > > > odious-mouth-shut-on-anthrax-and-911-lie BERNARD-MADOFF-PHILIP-MARKOFF- > > > MIKHAIL-KHODORKOVSKY-NEOCONS-PAUL-WOLFOWITZ-LEWIS-SCOOTER-LIBBY-MOSHE- > > > KATSEV-MOSSAD-DUBAI-MURDERERS) > > > ? ? ? ? ? ? ? ? ? nano-thermite-911-FBI-fat-per-diem-bustards-kept- > > > their-odious-mouth-shut-on-anthrax-and-911-lie nil)) > > > ? ? ? ? (setq nano-thermite-911-FBI-fat-per-diem-bustards-kept-their- > > > odious-mouth-shut-on-anthrax-and-911-lie (car I-AM-THE-WITNESS-DOT-COM- > > > has-MR-BENJAMIN-FREEDMAN-SPEECH-ON-KHAZARS) > > > ? ? ? ? ? ? ? I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN-SPEECH- > > > ON-KHAZARS (cdr I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN- > > > SPEECH-ON-KHAZARS)))) > > > ? ? BERNARD-MADOFF-PHILIP-MARKOFF-MIKHAIL-KHODORKOVSKY-NEOCONS-PAUL- > > > WOLFOWITZ-LEWIS-SCOOTER-LIBBY-MOSHE-KATSEV-MOSSAD-DUBAI-MURDERERS)) > > > -- > > --------------------------- > > | ?BBB ? ? ? ? ? ? ? ?b ? ?\ ? ? Barbara at LivingHistory stop co stop uk > > | ?B ?B ? aa ? ? rrr ?b ? ? | > > | ?BBB ? a ?a ? r ? ? bbb ? | ? ?Quidquid latine dictum sit, > > | ?B ?B ?a ?a ? r ? ? b ?b ?| ? ?altum videtur. > > | ?BBB ? ?aa a ?r ? ? bbb ? | ? > > ----------------------------- > > I think this is correct: > > (defun unknown-function (sym0) > ? (let (sym1 sym2) > ? ? ? ? (while (or sym2 sym0) > ? ? ? ? ? (if sym0 > ? ? ? ? ? ? ? ? ? (if (consp sym0) > ? ? ? ? ? ? ? ? ? ? ? ? ? (setq sym2 (cons (cdr sym0) sym2) sym0 (car sym0)) > ? ? ? ? ? ? ? ? ? ? ? ? (setq sym3 sym4 (cons sym0 sym1) sym0 nil)) > ? ? ? ? ? ? ? ? (setq sym0 (car sym2) sym2 (cdr sym2)))) > ? ? ? ? sym1)) > Thank emacs, not me. Lisp? Still can't read it... ;-) From smallpox911 at gmail.com Sun Dec 5 12:57:12 2010 From: smallpox911 at gmail.com (small Pox) Date: Sun, 5 Dec 2010 09:57:12 -0800 (PST) Subject: Unknown function operation deciphering, exercise in readability by program reasoning References: <46365e1d-42d8-4b3b-8e69-941472467472@u25g2000pra.googlegroups.com> <5e1f79ab-5432-4f18-b896-362b7406c75c@i18g2000yqn.googlegroups.com> <7a4bf118-1068-432b-ae3f-3a31d1489865@q18g2000vbk.googlegroups.com> Message-ID: <8105915f-e5c3-48c8-9f25-3cbe7ba332d4@i25g2000prd.googlegroups.com> On Dec 5, 9:13?am, "rupertlssm... at googlemail.com" wrote: > On Dec 5, 3:34?am, jvt wrote: > > > I think this is correct: > > > (defun unknown-function (sym0) > > ? (let (sym1 sym2) > > ? ? ? ? (while (or sym2 sym0) > > ? ? ? ? ? (if sym0 > > ? ? ? ? ? ? ? ? ? (if (consp sym0) > > ? ? ? ? ? ? ? ? ? ? ? ? ? (setq sym2 (cons (cdr sym0) sym2) sym0 (car sym0)) > > ? ? ? ? ? ? ? ? ? ? ? ? (setq sym3 sym4 (cons sym0 sym1) sym0 nil)) > > ? ? ? ? ? ? ? ? (setq sym0 (car sym2) sym2 (cdr sym2)))) > > ? ? ? ? sym1)) > > Thank emacs, not me. > > Lisp? Still can't read it... ;-)- Hide quoted text - > This is because madhu did not explain how he reasoned. Does it appear to you that she broke first two rules. its a list flattener that also reverses the operation. it appears that she took the consp predicate and/or flatten and started googling ... naughty girl. From smallpox911 at gmail.com Sun Dec 5 13:03:33 2010 From: smallpox911 at gmail.com (small Pox) Date: Sun, 5 Dec 2010 10:03:33 -0800 (PST) Subject: Unknown function operation deciphering, exercise in readability by program reasoning References: <46365e1d-42d8-4b3b-8e69-941472467472@u25g2000pra.googlegroups.com> <5e1f79ab-5432-4f18-b896-362b7406c75c@i18g2000yqn.googlegroups.com> Message-ID: On Dec 4, 11:37?pm, Madhu wrote: > * jvt <5e1f79ab-5432-4f18-b896-362b7406c... at i18g2000yqn.googlegroups.com> : > Wrote on Sat, 4 Dec 2010 19:34:53 -0800 (PST): > > | > | I think this is correct: > | > | > | (defun unknown-function (sym0) > | ? (let (sym1 sym2) > | ? ? ? (while (or sym2 sym0) > | ? ? ? ? (if sym0 > | ? ? ? ? ? ? ? ? (if (consp sym0) > | ? ? ? ? ? ? ? ? ? ? ? ? (setq sym2 (cons (cdr sym0) sym2) sym0 (car sym0)) > | ? ? ? ? ? ? ? ? ? ? ? (setq sym3 sym4 (cons sym0 sym1) sym0 nil)) > | ? ? ? ? ? ? ? (setq sym0 (car sym2) sym2 (cdr sym2)))) > | ? ? ? sym1)) > | Thank emacs, not me. > > Not quite. You didn't account for the original poster's go- > ogle masters mangling his message. ? But your function appears to be a > list flattener: explanation > (defun unknown-function (list) > ? (let (stack ret) > ? ? (while (or ret list) > ? ? ? (if list > ? ? ? ? ? (if (consp list) > ? ? ? ? ? ? ? (setq ret (cons (cdr list) ret) ;; hint: this is a push followed by list (car list)) ;; pop > ? ? ? ? ? ? (setq stack (cons list stack) ;; and so is this list nil)) > ? ? ? ? (setq list (car ret) ret (cdr ret)))) > ? ? stack)) > > --- > Madhu I will post an explanation in a few days if no one does this before since its not urgent for anyone and i have some job assignments to finish. From aharrisreid at googlemail.com Sun Dec 5 13:20:17 2010 From: aharrisreid at googlemail.com (Alan Harris-Reid) Date: Sun, 05 Dec 2010 18:20:17 +0000 Subject: Framework design question Message-ID: <4CFBD7E1.9030908@googlemail.com> Hi, When committing data that has originally come from a webpage, sometimes data has to be converted to a data type or format which is suitable for the back-end database. For instance, a date in 'dd/mm/yyyy' format needs to be converted to a Python date-object or 'yyyy-mm-dd' in order to be stored in a SQLite date column (SQLite will accept 'dd/mm/yy', but that can cause problems when data is retrieved). Question - at what point should the data be converted? a) As part of a generic web_page_save() method (immediately after data validation, but before a row.table_update() method is called). b) As part of row.table_update() (a data-object method called from web- or non-web-based applications, and includes construction of a field-value parameter list prior to executing the UPDATE command). In other words, from a framework point-of-view, does the data-conversion belong to page-object processing or data-object processing? Any opinions would be appreciated. Alan From python at mrabarnett.plus.com Sun Dec 5 14:09:24 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 05 Dec 2010 19:09:24 +0000 Subject: Framework design question In-Reply-To: <4CFBD7E1.9030908@googlemail.com> References: <4CFBD7E1.9030908@googlemail.com> Message-ID: <4CFBE364.6040400@mrabarnett.plus.com> On 05/12/2010 18:20, Alan Harris-Reid wrote: > > Hi, > > When committing data that has originally come from a webpage, sometimes > data has to be converted to a data type or format which is suitable for > the back-end database. For instance, a date in 'dd/mm/yyyy' format needs > to be converted to a Python date-object or 'yyyy-mm-dd' in order to be > stored in a SQLite date column (SQLite will accept 'dd/mm/yy', but that > can cause problems when data is retrieved). > > Question - at what point should the data be converted? > a) As part of a generic web_page_save() method (immediately after data > validation, but before a row.table_update() method is called). > b) As part of row.table_update() (a data-object method called from web- > or non-web-based applications, and includes construction of a > field-value parameter list prior to executing the UPDATE command). > > In other words, from a framework point-of-view, does the data-conversion > belong to page-object processing or data-object processing? > > Any opinions would be appreciated. > I would use a standardised 'international' form as much as possible, converting to it as early as possible and from it as late as possible. This applies to dates, text (using Unicode internally), etc. From noydb00 at gmail.com Sun Dec 5 14:26:41 2010 From: noydb00 at gmail.com (noydb) Date: Sun, 5 Dec 2010 11:26:41 -0800 (PST) Subject: How to add data into exisitng Excel file at next open row? References: <2acc7858-e55b-4cfe-8e10-1c0d716a10d4@o4g2000yqd.googlegroups.com> Message-ID: <73cd31ad-f9bf-4767-8a25-0884a9f072a5@h22g2000vbr.googlegroups.com> On Dec 5, 8:42?am, Steve Holden wrote: > On 12/3/2010 6:21 PM, noydb wrote: > > > > > > > How can you determine the next open row in an existing Excel file such > > that you can start adding data to the cells in that row? ?As in below, > > I want a variable in place of the 6 (row 6 in the four ws1.Cells(x,1) > > lines), but have no other way of knowing what row I am on besides > > looking to the first free cell in column A. ?How to do? ?Examples I > > see make it seem really complicated - this can't be that hard. > > > Thanks for any help. > > > worksheet = "C:\\Excel_Reports\\ea" + ea + "report"# + ".xls" > > xlApp = win32com.client.Dispatch("Excel.Application") > > xlApp.Visible = 1 > > xlApp.Workbooks.Open(worksheet) ## for existing file > > ##xlApp.SheetsInNewWorkbook = 1 > > ##wb = xlApp.Workbooks() > > ws1 = xlApp.Worksheets(1) > > > ws1.Cells(6,1).Value = "selection" > > ws1.Cells(6,2).Value = count > > ws1.Cells(6,3).Value = epcFloat > > ws1.Cells(6,8).Value = currentGMT > > > wb.SaveAs(worksheet) > > wb.Close(False) ## False/1 > > You might want to take a look at the xlrd library. This lets you read > Excel spreadsheets even on Unix platforms and without the use of COM > magic. There's also an xlwt module for writing spreadsheets. However I > understand that the two together may not be as convenient as modifying a > spreadsheet in place. > > In particular, if sh is a spreadsheet then sh.nrows gives you the number > of rows currently used in the sheet. > > regards > ?Steve > -- > Steve Holden ? ? ? ? ? +1 571 484 6266 ? +1 800 494 3119 > PyCon 2011 Atlanta March 9-17 ? ? ?http://us.pycon.org/ > See Python Video! ? ? ?http://python.mirocommunity.org/ > Holden Web LLC ? ? ? ? ? ? ? ?http://www.holdenweb.com/- Hide quoted text - > > - Show quoted text - Thanks, good to keep in mind. I have used xlrd before in cases where i'm not sure if excel is installed on a user's machine. Someone else helped, provided this> NextRow = ws1.Range("A1").SpecialCells(xlLastCell).Row + 1 Although to get it to work for me, I have to use the number code for some reason, like > NextRow = ws1.Range("A1").SpecialCells(11).Row + 1 From tjreedy at udel.edu Sun Dec 5 14:47:38 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 05 Dec 2010 14:47:38 -0500 Subject: Perceived inconsistency in py3k documentation In-Reply-To: <724b26b4-8233-4d57-b76f-cd781cf0cd03@z17g2000prz.googlegroups.com> References: <724b26b4-8233-4d57-b76f-cd781cf0cd03@z17g2000prz.googlegroups.com> Message-ID: On 12/5/2010 3:31 AM, Greg wrote: For future reference, > 1) At http://docs.python.org/py3k/reference/datamodel.html: > 2) At http://docs.python.org/py3k/library/stdtypes.html: do not work because of the trailing :s, at least not with FireFox. > 1) At http://docs.python.org/py3k/reference/datamodel.html : > 2) At http://docs.python.org/py3k/library/stdtypes.html : These, with space after the url, should. Other puctuation can be a problem too, so it is best to always follow urls with whitespace. -- Terry Jan Reedy From stef.mientki at gmail.com Sun Dec 5 15:11:20 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 05 Dec 2010 21:11:20 +0100 Subject: Which non SQL Database ? In-Reply-To: <201012042241.oB4Mfcfi079977@krusty.intranet.com.mx> References: <201012042241.oB4Mfcfi079977@krusty.intranet.com.mx> Message-ID: <4CFBF1E8.9070505@gmail.com> On 04-12-2010 23:42, Jorge Biquez wrote: > Hello all. > > Newbie question. Sorry. > > As part of my process to learn python I am working on two personal applications. Both will do it > fine with a simple structure of data stored in files. I now there are lot of databases around I > can use but I would like to know yoor advice on what other options you would consider for the job > (it is training so no pressure on performance). One application will run as a desktop one,under > Windows, Linux, Macintosh, being able to update data, not much, not complex, not many records. The > second application, running behind web pages, will do the same, I mean, process simple data, > updating showing data. not much info, not complex. As an excersice it is more than enough I guess > and will let me learn what I need for now. > Talking with a friend about what he will do (he use C only) he suggest to take a look on dBase > format file since it is a stable format, fast and the index structure will be fine or maybe go > with BD (Berkley) database file format (I hope I understood this one correctly) . Plain files it > is not an option since I would like to have option to do rapid searches. > > What would do you suggest to take a look? If possible available under the 3 plattforms. > > Thanks in advance for your comments. > > Jorge Biquez > You should take a look at one of the database wrappers. I use the DAL of Web2Py, the main advantages are - easy use of database (more easy than SQL) - easy migration of database structure (is done automatically) - same interface on desktop and in web applications - all major database (including SQLite and Postgres) supported and can be switched easily cheers, Stef From martin at v.loewis.de Sun Dec 5 16:01:27 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sun, 05 Dec 2010 22:01:27 +0100 Subject: Comparison with False - something I don't understand In-Reply-To: References: <877hfs2zia.fsf@benfinney.id.au> Message-ID: <4CFBFDA7.4000907@v.loewis.de> > result = myfunction (vars) > > if not result: > # error condition > > Now above I first realized that the function can also return an empty > list under some conditions and so changed it to If your function returns a list when successful, it should not return False in the error case. Instead, it should return None (indicating that there is no list). Then the condition changes to result = myfunction() if result is None: # error condition Using None for "no result available" is very common in Python. Using False for the same purpose (i.e. returning either a list or False) is not. If you return False from a function, the only other possible result should be True. Regards, Martin From drsalists at gmail.com Sun Dec 5 16:55:35 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 5 Dec 2010 13:55:35 -0800 Subject: Which non SQL Database ? In-Reply-To: <4cfb4714$0$1594$742ec2ed@news.sonic.net> References: <87d3phcfaw.fsf@gmail.com> <201012042343.oB4Nh18D084173@krusty.intranet.com.mx> <4cfb4714$0$1594$742ec2ed@news.sonic.net> Message-ID: On Sun, Dec 5, 2010 at 12:01 AM, John Nagle wrote: > On 12/4/2010 8:44 PM, Monte Milanuk wrote: >> >> On 12/4/10 3:43 PM, Jorge Biquez wrote: >> >>> I do not see a good reason for not using Sqlite3 BUT if for some reason >>> would not be an option.... what plain schema of files would you use? >> >> Would shelve work? > > ? ?There are some systems for storing key-value pairs in files. > > ? ?Underneath "shelve" is some primitive database, dbm, gdbm or bsddb. > "bsddb" is deprecated and was removed from Python 3.x. ?"dbm" has > some classic problems. ?"gdbm" is an improved version of "dbm". > None of these handle access from multiple processes, or crash > recovery. ?We're looking at 1979 technology here. > > ? SQLite works right when accessed from multiple processes. ?SQLite > is the entry-level database technology for Python today. ?It handles > the hard cases, like undoing transactions after a crash and > locking against multiple accesses. ?Lookup performance is good; > simultaneous update by multiple processes, though, is not so > good. ?When you have a web site that has many processes hitting > the same database, it's time to move up to MySQL or Postgres. > > ? There's a lot of interest in "non-SQL" databases for very > large distributed systems. ?You worry about this if you're Facebook > or Google, or are running a big game server farm. SQLite isn't exactly no SQL. I've used the bsddb and gdbm modules quite a bit. I've found that bsddb tables tend to get corrupted (whether used from CPython or C), EG when a filesystem fills up. I quite like the gdbm module though, and have been using it in my current project. If you find that converting your database keys and values to/from strings is expensive, you could check out http://stromberg.dnsalias.org/~dstromberg/cachedb.html which is a caching wrapper around gdbm and other single-table database interfaces supporting the same API. As far as multiple processes, IINM, gdbm supports a single writer and multiple readers. From mmanns at gmx.net Sun Dec 5 17:49:36 2010 From: mmanns at gmx.net (Martin Manns) Date: Sun, 5 Dec 2010 23:49:36 +0100 Subject: Collision of rotated rectangles without pygame Message-ID: <20101205234936.39dc1a4e@Knock> Hello, I am looking for a Python library for 2D collision checks of rotated rectangles. Currently, I have found vizier 0.5b that is based on pygame. Since I do not want to add a pygame dependency to my app, I replaced the pygame.rect.Rect by a wxPython wx.Rect (see code below). However, collision checks do not work correctly, i. e. identical rects are not found to be colliding: $ python Python 2.6.6 (r266:84292, Nov 28 2010, 18:42:58) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import xrect >>> r=xrect.RotoRect(10,10,30,20,angle=34) >>> s=xrect.RotoRect(10,10,30,20,angle=34) >>> r.rotocollide(s) False >>> Is my replacement of the rectangle object wrong or is vizier not working correctly with pygame as well? Do you know of any other pure Python library for rotated rectangle collision checks? Cheers Martin ---------------------------------------- from __future__ import division import math import wx ############################################################################## cos_table = dict([(deg, math.cos(math.radians(deg))) for deg in xrange(360)]) sin_table = dict([(deg, math.sin(math.radians(deg))) for deg in xrange(360)]) class RotoRect(wx.Rect): def __init__(self, *a, **kw): self.deg = kw.pop('angle') wx.Rect.__init__(self, *a, **kw) # pygame rect compatibility for wx.Rect def get_center(self): return self.centerx, self.centery def set_center(self, center): self.centerx, self.centery = center def get_centerx(self): return self.x + self.width / 2 def set_centerx(self, centerx): self.SetX(centerx - self.width / 2) def get_centery(self): return self.y + self.height / 2 def set_centery(self, centery): self.SetY(centery - self.height / 2) def get_topleft(self): return self.GetTopLeft() def set_topleft(self, p): self.SetTopLeft(p) def get_topright(self): return self.GetTopRight() def set_topright(self, p): self.SetTopRight(p) center = property(get_center, set_center) centerx = property(get_centerx, set_centerx) centery = property(get_centery, set_centery) topleft = property(get_topleft, set_topleft) topright = property(get_topright, set_topright) # Now for the vizier code def rotate(self, point, origin = 0): """Returns coords of point p rotated self.theta radians with the rectangle around its center """ if not origin: origin = self.center p_x = point[0] p_y = point[1] o_x = origin[0] o_y = origin[1] costheta = cos_table[self.deg] sintheta = sin_table[self.deg] return ((o_x + costheta * (p_x - o_x)) - (sintheta * (p_y - o_y)), (o_y + sintheta * (p_x - o_x)) + (costheta * (p_y - o_y))) def rotoxt(self, a, b): """Returns the y extremity xt of rect between self.rect""" a_x = a[0] a_y = a[1] b_x = b[0] b_y = b[1] #calculate difference between self.left and b_x dxl = self.left - b_x #calculate difference between self.right and b_x dxr = self.right - b_x #if b_x isn't between self.left and self.right if (dxl * dxr) > 0: #if dxl < 1, b_x is on the right if (dxl < 0): #xt = (m * dxr) + b_y xt = ((((b_y - (-a_y)) / (b_x - (-a_x))) * dxr) + b_y) else: #else b_x is on the left #xt = (m * dxl) + b_y xt = ((((b_y - a_y) / (b_x - a_x)) * dxl) + b_y) return xt else: #else b_x is between self.left and self.right, and xt = b_y return b_y def rotocollide(self, rect): """Check for collision between self.rect and rect""" #initialize collision to False col = False #transforming the plane to set rect's center to the origin transplane = rect.center #set rect's center to the origin rect.center = (0, 0) #transform self.rect's center by the transplane amount self.center = (self.centerx - transplane[0], self.centery - transplane[1]) #transforming the plane to set self.rect's theta to 0 transdeg = self.deg #set self.rect's theta to 0 self.deg = 0 #transform rect's theta by the transtheta amount rect.deg -= transdeg #determine which vertice is min/max x/y NOTE: # a = left/right, b = top/bottom if (sin_table[rect.deg] * cos_table[rect.deg]) > 0: #a = extreme left/right, b = extreme top/bottom a, b = rect.topright, rect.topleft else: a, b = rect.topleft, rect.topright #determine if a.x is min/max if sin_table[rect.deg] < 0: #ensure a is always max a = -a[0], -a[1] a_x = a[0] negb = -b[0], -b[1] #check that range of rect (-a.x, a.x) overlaps range of #self.rect (self.left, self.right) if (a_x >= self.left) and (self.right >= -a_x): #get the first extremity xt1 = self.rotoxt(a, b) #get the other extermity xt2 = self.rotoxt(a, negb) #check for an intersection between the two extremities and #self.rect's top/bottom col = (((xt1 >= self.top) and (self.bottom >= xt2)) or ((xt2 >= self.top) and (self.bottom >= xt1))) #retransform rect.center rect.center = transplane #retransform self.rect.center self.center = (self.centerx + transplane[0], self.centery + transplane[1]) #retransform self.theta self.deg = transdeg #retransform rect.theta rect.deg += transdeg #return results of collision test return col @property def rotox(self): return self.rotate(self.topleft)[0] @property def rotoy(self): return self.rotate(self.topleft)[1] @property def rotoleft(self): return self.rotate(self.left) @property def rotoright(self): return self.rotate(self.right) @property def rototop(self): return self.rotate(self.top) @property def rotobottom(self): return self.rotate(self.bottom) @property def rototopleft(self): return self.rotate(self.topleft) @property def rototopright(self): return self.rotate(self.topright) @property def rotobottomright(self): return self.rotate(self.bottomright) @property def rotobottomleft(self): return self.rotate(self.bottomleft) @property def rotomidleft(self): return self.rotate(self.midleft) @property def rotomidright(self): return self.rotate(self.midright) @property def rotomidtop(self): return self.rotate(self.midtop) @property def rotomidbottom(self): return self.rotate(self.midbottom) From mmanns at gmx.net Sun Dec 5 17:56:03 2010 From: mmanns at gmx.net (Martin Manns) Date: Sun, 5 Dec 2010 23:56:03 +0100 Subject: Collision of rotated rectangles without pygame References: <20101205234936.39dc1a4e@Knock> Message-ID: <20101205235603.16fdce09@Knock> On Sun, 5 Dec 2010 23:49:36 +0100 Martin Manns wrote: > Is my replacement of the rectangle object wrong or is vizier not > working correctly with pygame as well? Answering my first question: Vizier works O.K. with pygame. I am unsure what I did wrong in the rect replacement though. Cheers Martin From python at mrabarnett.plus.com Sun Dec 5 21:01:24 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 06 Dec 2010 02:01:24 +0000 Subject: Comparison with False - something I don't understand In-Reply-To: <4CFBFDA7.4000907@v.loewis.de> References: <877hfs2zia.fsf@benfinney.id.au> <4CFBFDA7.4000907@v.loewis.de> Message-ID: <4CFC43F4.2090705@mrabarnett.plus.com> On 05/12/2010 21:01, Martin v. Loewis wrote: >> result = myfunction (vars) >> >> if not result: >> # error condition >> >> Now above I first realized that the function can also return an empty >> list under some conditions and so changed it to > > If your function returns a list when successful, it should not return > False in the error case. Instead, it should return None (indicating that > there is no list). > > Then the condition changes to > > result = myfunction() > if result is None: > # error condition > > Using None for "no result available" is very common in Python. Using > False for the same purpose (i.e. returning either a list or False) > is not. If you return False from a function, the only other possible > result should be True. > As an example, the re module uses both two approaches. If you ask it to compile a regex: rgx = re.compile(regex) it either returns a PatternObject (if the regex is valid) or raises an exception (if the regex isn't valid). If you ask it to search a string: rgx.search(string) it returns either a MatchObject (if the match is successful) or None (if the match isn't successful). From wuwei23 at gmail.com Sun Dec 5 21:26:05 2010 From: wuwei23 at gmail.com (alex23) Date: Sun, 5 Dec 2010 18:26:05 -0800 (PST) Subject: How do I get the email address of the person who clicked the link in the email? References: <63971a7c-8366-471b-ac7f-812f7dab81ba@n10g2000yqd.googlegroups.com> Message-ID: <19d3af43-13d8-4ed2-a63f-0df86b9e602a@o14g2000prn.googlegroups.com> On Dec 5, 10:15?am, Zeynel wrote: > I am working with Google App Engine python version. The app sends an > email to the user with a link to a page to upload an image as an > avatar. It would be nice to have the email so that I can associate the > avatar with that email. How can I do this? Thank you. One approach would be to assign a unique identifier to the email address, then include that identifier as a parameter in the link that allows for image uploading: http://your.site.tld/avatar/upload/ (for eg) Then the upload process can get the ID from the path and identify the email address with which the image is associated. From shearichard at gmail.com Sun Dec 5 22:40:47 2010 From: shearichard at gmail.com (shearichard) Date: Sun, 5 Dec 2010 19:40:47 -0800 (PST) Subject: PEP8 compliance and exception messages ? Message-ID: <63cab97f-4e46-4c30-83ce-dc531a900d40@u25g2000pra.googlegroups.com> Hi - PEP8 says lines should not exceed 79 characters in length ( http://www.python.org/dev/peps/pep-0008/ ). So if you've got some code that looks like this : raise fooMod.fooException("Some message which is quite long") ... and assuming a certain amount of indenting you're going to break that guideline. However there's a way around that ! You can do this ... raise fooMod.fooException("\ Some message \ which is quite long") ... but the trouble is when that Exception is raised the message is displayed as : "Some message which is quite long" I'm aware that a foolish consistency is the hobgoblin of something or the other so maybe I should just let the PEP8 verifier complain but otherwise does anyone have any ideas for how to get around this ? Thanks richard From clp2 at rebertia.com Sun Dec 5 22:52:54 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 5 Dec 2010 19:52:54 -0800 Subject: PEP8 compliance and exception messages ? In-Reply-To: <63cab97f-4e46-4c30-83ce-dc531a900d40@u25g2000pra.googlegroups.com> References: <63cab97f-4e46-4c30-83ce-dc531a900d40@u25g2000pra.googlegroups.com> Message-ID: On Sun, Dec 5, 2010 at 7:40 PM, shearichard wrote: > Hi - PEP8 says lines should not exceed 79 characters in length > ( http://www.python.org/dev/peps/pep-0008/ ). > > So if you've got some code that looks like this : > > raise fooMod.fooException("Some message which is quite long") > > ... and assuming a certain amount of indenting you're going to break > that guideline. > > However there's a way around that ! You can do this ... > > raise fooMod.fooException("\ > ? ? ? ?Some message \ > ? ? ? ?which is quite long") > > ... but the trouble is when that Exception is raised the message is > displayed as : > > "Some message ? ? ? ? ? ? ? ? ? ? which is quite long" > > > I'm aware that a foolish consistency is the hobgoblin of something or > the other so maybe I should just let the PEP8 verifier complain but > otherwise does anyone have any ideas for how to get around this ? Use implicit string literal concatenation: raise fooMod.fooException( "Some message " "which is quite long") #) # you could also put the closing paren here instead Alternatively, you could disregard PEP 8 on this point on the grounds that the 79/80 characters per line limit is outdated. Cheers, Chris -- http://blog.rebertia.com From python at mrabarnett.plus.com Sun Dec 5 22:54:51 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 06 Dec 2010 03:54:51 +0000 Subject: PEP8 compliance and exception messages ? In-Reply-To: <63cab97f-4e46-4c30-83ce-dc531a900d40@u25g2000pra.googlegroups.com> References: <63cab97f-4e46-4c30-83ce-dc531a900d40@u25g2000pra.googlegroups.com> Message-ID: <4CFC5E8B.5080200@mrabarnett.plus.com> On 06/12/2010 03:40, shearichard wrote: > Hi - PEP8 says lines should not exceed 79 characters in length > ( http://www.python.org/dev/peps/pep-0008/ ). > > So if you've got some code that looks like this : > > raise fooMod.fooException("Some message which is quite long") > > ... and assuming a certain amount of indenting you're going to break > that guideline. > > However there's a way around that ! You can do this ... > > raise fooMod.fooException("\ > Some message \ > which is quite long") > > ... but the trouble is when that Exception is raised the message is > displayed as : > > "Some message which is quite long" > > > I'm aware that a foolish consistency is the hobgoblin of something or > the other so maybe I should just let the PEP8 verifier complain but > otherwise does anyone have any ideas for how to get around this ? > You can use implied string concatenation: >>> "abc" "def" 'abcdef' so: raise fooMod.fooException( "Some message " "which is quite long") From python at mrabarnett.plus.com Sun Dec 5 23:08:16 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 06 Dec 2010 04:08:16 +0000 Subject: Wanted: slow regexes Message-ID: <4CFC61B0.8000109@mrabarnett.plus.com> I'm looking for examples of regexes which are slow (especially those which seem never to finish) but whose results are known. I already have those reported in the bug tracker, but further ones will be welcome. This is for testing additional modifications to the new regex implementation (available on PyPI). From drsalists at gmail.com Mon Dec 6 00:01:58 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 5 Dec 2010 21:01:58 -0800 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename In-Reply-To: References: Message-ID: Ultimately I switched to reading the filenames from file descriptor 0 using os.read(); this gave back bytes in 3.x, strings of single-byte characters in 2.x - which are similar enough for my purposes, and eliminated the filesystem encoding(s) question nicely. I rewrote readline0 (http://stromberg.dnsalias.org/cgi-bin/viewvc.cgi/readline0/trunk/?root=svn) for 2.x and 3.x to facilitate reading null-terminated strings from stdin. It's in better shape now anyway - more OOP than functional, and with a bunch of unit tests. The module now works on CPython 2.x, CPython 3.x and PyPy 1.4 from the same code. On Mon, Nov 29, 2010 at 9:26 PM, Dan Stromberg wrote: > I've got a couple of programs that read filenames from stdin, and then > open those files and do things with them. ?These programs sort of do > the *ix xargs thing, without requiring xargs. > > In Python 2, these work well. ?Irrespective of how filenames are > encoded, things are opened OK, because it's all just a stream of > single byte characters. > > In Python 3, I'm finding that I have encoding issues with characters > with their high bit set.? Things are fine with strictly ASCII > filenames. ?With high-bit-set characters, even if I change stdin's > encoding with: > > ? ? ? import io > ? ? ? STDIN = io.open(sys.stdin.fileno(), 'r', encoding='ISO-8859-1') > > ...even with that, when I read a filename from stdin with a > single-character Spanish n~, the program cannot open that filename > because the n~ is apparently internally converted to two bytes, but > remains one byte in the filesystem. ?I decided to try ISO-8859-1 with > Python 3, because I have a Java program that encountered a similar > problem until I used en_US.ISO-8859-1 in an environment variable to > set the JVM's encoding for stdin. > > Python 2 shows the n~ as 0xf1 in an os.listdir('.'). ?Python 3 with an > encoding of ISO-8859-1 wants it to be 0xc3 followed by 0xb1. > > Does anyone know what I need to do to read filenames from stdin with > Python 3.1 and subsequently open them, when some of those filenames > include characters with their high bit set? > > TIA! > From ben+python at benfinney.id.au Mon Dec 6 00:21:26 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 06 Dec 2010 16:21:26 +1100 Subject: PEP8 compliance and exception messages ? References: <63cab97f-4e46-4c30-83ce-dc531a900d40@u25g2000pra.googlegroups.com> Message-ID: <87ei9v1nop.fsf@benfinney.id.au> shearichard writes: > Hi - PEP8 says lines should not exceed 79 characters in length > ( http://www.python.org/dev/peps/pep-0008/ ). > > So if you've got some code that looks like this : > > raise fooMod.fooException("Some message which is quite long") PEP 8 also says those names are poorly chosen. Better: raise foomod.FooException("Some message which is quite long") > raise fooMod.fooException("\ > Some message \ > which is quite long") Take advantage of the parsing of string literals and parenthesis: raise foomod.FooException( "Some message" " which is quite long") and for the sake of my eyes, avoid camelCase. From usenot at geekmail.INVALID Mon Dec 6 00:22:49 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Mon, 6 Dec 2010 00:22:49 -0500 Subject: PEP8 compliance and exception messages ? References: <63cab97f-4e46-4c30-83ce-dc531a900d40@u25g2000pra.googlegroups.com> Message-ID: <20101206002249.2d804250@wldmr> On Sun, 5 Dec 2010 19:52:54 -0800 Chris Rebert wrote: > On Sun, Dec 5, 2010 at 7:40 PM, shearichard > wrote: > > Hi - PEP8 says lines should not exceed 79 characters in length > > ( http://www.python.org/dev/peps/pep-0008/ ). > > > > So if you've got some code that looks like this : > > > > raise fooMod.fooException("Some message which is quite long") > > > > ... and assuming a certain amount of indenting you're going to break > > that guideline. > > > > [etc.] > > Use implicit string literal concatenation: > > [...] > But isn't explicit string literal concatenation better than implicit string literal concatenation? ... sorry ... On a more serious note: > Alternatively, you could disregard PEP 8 on this point on the grounds > that the 79/80 characters per line limit is outdated. > Maybe, but it's not outmoded. /W -- To reach me via email, replace INVALID with the country code of my home country. But if you spam me, I'll be one sour Kraut. From usernet at ilthio.net Mon Dec 6 01:15:06 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 6 Dec 2010 06:15:06 +0000 (UTC) Subject: PEP8 compliance and exception messages ? References: <63cab97f-4e46-4c30-83ce-dc531a900d40@u25g2000pra.googlegroups.com> <20101206002249.2d804250@wldmr> Message-ID: On 2010-12-06, Andreas Waldenburger wrote: > On Sun, 5 Dec 2010 19:52:54 -0800 Chris Rebert wrote: > >> On Sun, Dec 5, 2010 at 7:40 PM, shearichard >> wrote: >> > Hi - PEP8 says lines should not exceed 79 characters in length >> > ( http://www.python.org/dev/peps/pep-0008/ ). >> > >> > So if you've got some code that looks like this : >> > >> > raise fooMod.fooException("Some message which is quite long") >> > >> > ... and assuming a certain amount of indenting you're going to break >> > that guideline. >> > >> > [etc.] >> >> Use implicit string literal concatenation: >> >> [...] >> > But isn't explicit string literal concatenation better than implicit > string literal concatenation? So add the "+", it really doesn't change it much. >> Alternatively, you could disregard PEP 8 on this point on the grounds >> that the 79/80 characters per line limit is outdated. >> > Maybe, but it's not outmoded. I would say that it is not even outdated. Just because you happen to enjoy longer lines doesn't mean that everybody does. Not all progammers have 20/10 vision and even those who have hardware to handled it don't necessarily like having a single piece of code take up their entire display just to be readable. Many of us like the extra ability that wider screen technology gives us to actually be able to view more of the file at once by splitting the display into a couple of columns. From steve+comp.lang.python at pearwood.info Mon Dec 6 01:52:53 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Dec 2010 06:52:53 GMT Subject: PEP8 compliance and exception messages ? References: <63cab97f-4e46-4c30-83ce-dc531a900d40@u25g2000pra.googlegroups.com> <20101206002249.2d804250@wldmr> Message-ID: <4cfc8845$0$29998$c3e8da3$5496439d@news.astraweb.com> On Mon, 06 Dec 2010 06:15:06 +0000, Tim Harig wrote: >> But isn't explicit string literal concatenation better than implicit >> string literal concatenation? > > So add the "+", it really doesn't change it much. Perhaps not *much*, but it *may* change it a bit. Implicit concatenation of literals is promised to be handled by the compiler, at compile time: >>> from dis import dis >>> dis(compile("s = 'hello' 'world'", "", "single")) 1 0 LOAD_CONST 0 ('helloworld') 3 STORE_NAME 0 (s) 6 LOAD_CONST 1 (None) 9 RETURN_VALUE This holds all the way back to Python 1.5 and probably older. But explicit concatenation may occur at run-time, depending on the implementation and the presence or absence of a keyhole optimizer. E.g. in Python 2.4: >>> dis(compile("s = 'hello' + 'world'", "", "single")) 1 0 LOAD_CONST 0 ('hello') 3 LOAD_CONST 1 ('world') 6 BINARY_ADD 7 STORE_NAME 0 (s) 10 LOAD_CONST 2 (None) 13 RETURN_VALUE A small difference, but a real one. -- Steven From steve at holdenweb.com Mon Dec 6 01:58:29 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 06 Dec 2010 07:58:29 +0100 Subject: class attribute confusion In-Reply-To: <4cf97626$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <4cf97626$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 12/3/2010 11:58 PM, Steven D'Aprano wrote: > Right. If you define a *class* attribute, it lives in the class, not the > instance, and so all instances share the same value. Unless, of course, an instance binds the same name in its namespace, in which case it will (usually) mask the class attribute for that instance. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Mon Dec 6 02:17:55 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 06 Dec 2010 08:17:55 +0100 Subject: Which non SQL Database ? In-Reply-To: <1ae2b7eb-0ccc-420e-8e62-92aafebd827e@p38g2000vbn.googlegroups.com> References: <87d3phcfaw.fsf@gmail.com> <1ae2b7eb-0ccc-420e-8e62-92aafebd827e@p38g2000vbn.googlegroups.com> Message-ID: On 12/5/2010 12:59 AM, CM wrote: > SQlite itself is around 300 kilobytes. That's negligible. It is also > already in Python, so you'd have to purposefully exclude it in > creating your executable to save those 300 kb and thus the 1/13th of a > second additional time it would take average (3.9 MB/s) users to > download your app if it were included. Just as a matter of interest where do you get the information that the average user has a 3.9 MB/s path to the Internet? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From no.email at nospam.invalid Mon Dec 6 03:14:11 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 06 Dec 2010 00:14:11 -0800 Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <7x39qbfhd8.fsf@ruckus.brouhaha.com> mdw at distorted.org.uk (Mark Wooding) writes: > The most obvious improvement is resumable exceptions. You know, I've heard the story from language designers several times over, that they tried putting resumable exceptions into their languages and it turned out to be a big mess, so they went to termination exceptions that fixed the issue. Are there any languages out there with resumable exceptions? Escaping to a debugger doesn't really count as that. I guess one way to do it would be call a coroutine to handle the exception, and either continue or unwind after the continue returns, but doing it in a single-threaded system just seems full of hazards. From steve at holdenweb.com Mon Dec 6 03:40:53 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 06 Dec 2010 09:40:53 +0100 Subject: Comparison with False - something I don't understand In-Reply-To: <7x39qbfhd8.fsf@ruckus.brouhaha.com> References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> <7x39qbfhd8.fsf@ruckus.brouhaha.com> Message-ID: <4CFCA195.4020003@holdenweb.com> On 12/6/2010 9:14 AM, Paul Rubin wrote: > mdw at distorted.org.uk (Mark Wooding) writes: >> The most obvious improvement is resumable exceptions. > > You know, I've heard the story from language designers several times > over, that they tried putting resumable exceptions into their languages > and it turned out to be a big mess, so they went to termination > exceptions that fixed the issue. Are there any languages out there with > resumable exceptions? Escaping to a debugger doesn't really count as > that. I guess one way to do it would be call a coroutine to handle the > exception, and either continue or unwind after the continue returns, but > doing it in a single-threaded system just seems full of hazards. I seem to remember PL/1 has resumable exceptions, but I don't ever remember finding a real use for them. And it's so long since I used PL/1 I may be mistaken. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From drygalski at googlemail.com Mon Dec 6 04:07:11 2010 From: drygalski at googlemail.com (drygal) Date: Mon, 6 Dec 2010 01:07:11 -0800 (PST) Subject: Which non SQL Database ? References: Message-ID: <8015839c-9400-4ccd-ae5d-db34f68dbee4@22g2000prx.googlegroups.com> On Dec 4, 10:42?pm, Jorge Biquez wrote: > Hello all. > > Newbie question. Sorry. > > As part of my process to learn python I am working on two personal > applications. Both will do it fine with a simple structure of data > stored in files. I now there are lot of databases around I can use > but I would like to know yoor advice on what other options you would > consider for the job (it is training so no pressure on performance). > One application will run as a desktop one,under Windows, Linux, > Macintosh, being able to update data, not much, not complex, not many > records. The second application, running behind ?web pages, will do > the same, I mean, process simple data, updating showing data. not > much info, not complex. As an excersice it is more than enough I > guess and will let me learn what I need for now. > Talking with a friend about what he will do (he use C only) he > suggest to take a look on dBase format file since it is a stable > format, fast and the index structure will be fine or maybe go with BD > (Berkley) database file format (I hope I understood this one > correctly) . Plain files it is not an option since I would like to > have option to do rapid searches. > > What would do you suggest to take a look? If possible available under > the 3 plattforms. > > Thanks in advance for your comments. > > Jorge Biquez Pickle dictionary object perhaps? http://docs.python.org/library/pickle.html From stef.mientki at gmail.com Mon Dec 6 04:40:48 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Mon, 06 Dec 2010 10:40:48 +0100 Subject: is it possible to see if a class has a decorator ? Message-ID: <4CFCAFA0.1090906@gmail.com> hello, I would like to know if a class definition has a decorator, is that possible ? And if so, is it possible to determine the name of these decorator(s) ? thanks, Stef Mientki From ben+python at benfinney.id.au Mon Dec 6 06:08:33 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 06 Dec 2010 22:08:33 +1100 Subject: is it possible to see if a class has a decorator ? References: Message-ID: <87aakj17m6.fsf@benfinney.id.au> Stef Mientki writes: > I would like to know if a class definition has a decorator, I'm not sure what this question means. Applying a decorator to a class definition produces a normal class. Classes don't ?have? decorators; classes can be returned by a decorator function, but AFAIK the resulting class doesn't ?have? the decorator in any sense. > is that possible ? The return value of a decorator isn't special in any way, AFAIK. Any function can return a class object or a function object, and any function can be used as a decorator. The only thing that makes a function a decorator is how it is used in the code; but it doesn't leave a trace that I know of. Now, what is it you're trying to do? Perhaps there's a better solution we can come up with. -- \ ?Pinky, are you pondering what I'm pondering?? ?I think so, | `\ Brain, but there's still a bug stuck in here from last time.? | _o__) ?_Pinky and The Brain_ | Ben Finney From stef.mientki at gmail.com Mon Dec 6 06:29:32 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Mon, 06 Dec 2010 12:29:32 +0100 Subject: is it possible to see if a class has a decorator ? In-Reply-To: <87aakj17m6.fsf@benfinney.id.au> References: <87aakj17m6.fsf@benfinney.id.au> Message-ID: <4CFCC91C.3060102@gmail.com> On 06-12-2010 12:08, Ben Finney wrote: > Stef Mientki writes: > >> I would like to know if a class definition has a decorator, > I'm not sure what this question means. > > Applying a decorator to a class definition produces a normal class. > > Classes don't ?have? decorators; classes can be returned by a decorator > function, but AFAIK the resulting class doesn't ?have? the decorator in > any sense. > >> is that possible ? > The return value of a decorator isn't special in any way, AFAIK. > > Any function can return a class object or a function object, and any > function can be used as a decorator. > > The only thing that makes a function a decorator is how it is used in > the code; but it doesn't leave a trace that I know of. > > Now, what is it you're trying to do? Perhaps there's a better solution > we can come up with. > Thanks Ben, here some more explanation. I've a number of (dynamic) applications, launched from a central wrapper. All these modules have a class "Start", which launches the application and embeds them in the wrapper application. Module 1: class Start (): .... Module 2: @auth class Start (): ... When the wrapper application is started, it looks for all dynamic modules (without importing them), and list these application in a hierarchical tree. In the above axmple, I would like to know that the class "Start" in Module 2 has the decorator "Auth", *without importing the module*, (so depending on the user logged in, I can decide to add or not add the module to the hierarchical tree). thanks, Stef Mientki -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Mon Dec 6 06:32:50 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Dec 2010 11:32:50 GMT Subject: is it possible to see if a class has a decorator ? References: <87aakj17m6.fsf@benfinney.id.au> Message-ID: <4cfcc9e2$0$29997$c3e8da3$5496439d@news.astraweb.com> On Mon, 06 Dec 2010 22:08:33 +1100, Ben Finney wrote: > Stef Mientki writes: > >> I would like to know if a class definition has a decorator, > > I'm not sure what this question means. > > Applying a decorator to a class definition produces a normal class. > > Classes don't ?have? decorators; classes can be returned by a decorator > function, but AFAIK the resulting class doesn't ?have? the decorator in > any sense. It seems to me that a class decorator is (usually) like a class factory, in that it returns a class; the difference being that it takes a pre- existing class as argument, and (probably) modifies it in place, rather than creates a new class from scratch. I say "usually" and "probably" because, of course, a class decorator can do *anything*. Even something pointless: >>> def decorator(cls): ... return 1 ... >>> @decorator ... class K: ... pass ... >>> K 1 >> is that possible ? > > The return value of a decorator isn't special in any way, AFAIK. > > Any function can return a class object or a function object, and any > function can be used as a decorator. [pedant] Any callable can be a decorator, provided it has an appropriate calling signature. But you knew that :) [/pedant] > The only thing that makes a function a decorator is how it is used in > the code; but it doesn't leave a trace that I know of. Function decorators can, because they usually wrap the input function in a closure, which is detectable: >>> def decorator(func): ... def inner(): ... return func("spam") ... return inner ... >>> >>> @decorator ... def ham(s): ... return s.upper() ... >>> ham.__closure__ (,) >>> >>> def cheese(s): # no decorator ... return s.upper() ... >>> cheese.__closure__ >>> But this is only a common practice, not a guarantee, because the decorating function can do anything. I think that the only way to find out what was used to decorate a class, or a function, is for the decorator itself to leave some sort of mark on the wrapped class/function. Perhaps by adding itself to the wrapped object as an attribute: def decorate(cls): cls._decorated_by = decorate -- Steven From lie.1296 at gmail.com Mon Dec 6 06:42:31 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 06 Dec 2010 22:42:31 +1100 Subject: Comparison with False - something I don't understand In-Reply-To: References: <877hfs2zia.fsf@benfinney.id.au> <4CFA6F16.2060001@holdenweb.com> <4cfaf1ff$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cfccb7e$1@dnews.tpgi.com.au> On 12/05/10 15:52, Tim Harig wrote: > On 2010-12-05, Tim Harig wrote: >> Another, questionable but useful use, is to ignore the complex accounting >> of your position inside of a complex data structure. You can continue >> moving through the structure until an exception is raised indicating >> that you have reached a boundary of the structure. > > Here is another example in this vein. I had another example where using Exception as a control structure proves to be the most elegant solution. The problem was a logic puzzle solver (e.g. for Sudoku, Einstein's Logic problem, etc). The algorithm used is recursive backtracking solver (yes, I know there are more efficient constraint-based solver, but that's besides the point). The function modifies the `puzzle` list in-place such that after the call `puzzle` list will contain the solution to the puzzle (if any exists). The solving "in-place" is important since this solver thread runs in a "solver thread" and there is another "drawing thread" that draws the currently tested board asynchronously. This means we do not make a copy of the game board. No locking is done, since it is fine for the drawing thread to draw malformed board, and we do not want to compromise the solver's thread's speed. The two versions of using return value and exception: def solve_return(puzzle, index): """ return True when puzzle is solved, return False when backtracking or when no solution exists """ # recursion base case if all cells are filled and puzzle does not violate game rules: return True # solution found if puzzle violates game rules: return False # backtrack if puzzle[index] is unfilled: for i in possible_candidates(puzzle, index): puzzle[index] = i if solve(puzzle, index+1): # solution already found, unwinding the stack return True # all candidates failed, backtrack puzzle[r][c] = unfilled return False else: # the current cell is part of the base clue return solve(puzzle, index+1) # skip it def main_return(): puzzle = [...] if solve_return(puzzle, 0): print('solution found') else: print('no solution found') def solve_raise(puzzle, index): """ no return value throws SolutionFound when solution is found """ # recursion base case if all cells are filled and puzzle does not violate game rules: raise SolutionFound if puzzle[index] is unfilled: for i in possible_candidates(puzzle, index): puzzle[index] = i if puzzle does not violate game rules: solve(puzzle, index+1) # all candidates failed, backtrack puzzle[r][c] = unfilled else: # the current cell is part of the base clue solve(puzzle, index+1) # skip it def main_raise(): puzzle = [...] try: solve_raise(puzzle, 0) except SolutionFound: print('solution found') else: print('no solution found') Personally, I've found the logic in the exception version clearer than the return version. Also, the exception version is easier to extend, if I wanted to add a smarter algorithm that can deterministically infer certain cell's value (this creates indirect recursion, solve() may call either infer() or solve() which may call either infer() or solve()), it can work beside the existing mechanism without explicitly handling the return flag when a solution is found. If we suppose that end-of-line (e.g. the semicolon, in C-like language) is a single-step forward control structure, the if-statement is a n-step forward control structure, and looping is a n-step backward control structure. Now, if we suppose function call as a single-step downward control structure, and function return as a single-step upward control structure, then exception is a n-step upward control structure. It throws control upwards of the function call stack, while doing cleanup along its way up. From lnenov at mm-sol.com Mon Dec 6 07:36:41 2010 From: lnenov at mm-sol.com (lnenov) Date: Mon, 06 Dec 2010 14:36:41 +0200 Subject: simple threading.Thread and Semaphores hang Message-ID: <4CFCD8D9.4000805@mm-sol.com> Hi, My application hangs on exit. I have isoleted this piece of code that reproduces the error: (the time module is extra and not needed to reproduce) import threading import time def func(): b = threading.Semaphore(value=0) b.acquire() a = threading.Thread(target=func) a.start() time.sleep(2) quit() When SystemExit is raised, nothing happens. Python hangs. pdb does seem to have problem with this code too: pdb smth.py ... (Pdb) Traceback (most recent call last): File "/usr/bin/pdb", line 1319, in pdb.main() File "/usr/lib/python2.6/pdb.py", line 1312, in main pdb.interaction(None, t) File "/usr/lib/python2.6/pdb.py", line 198, in interaction self.cmdloop() File "/usr/lib/python2.6/cmd.py", line 130, in cmdloop line = raw_input(self.prompt) ValueError: I/O operation on closed file Any help would be appreciated, Lyudmil From python.list at tim.thechases.com Mon Dec 6 07:53:46 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 06 Dec 2010 06:53:46 -0600 Subject: Wanted: slow regexes In-Reply-To: <4CFC61B0.8000109@mrabarnett.plus.com> References: <4CFC61B0.8000109@mrabarnett.plus.com> Message-ID: <4CFCDCDA.1030400@tim.thechases.com> On 12/05/2010 10:08 PM, MRAB wrote: > I'm looking for examples of regexes which are slow (especially those > which seem never to finish) but whose results are known. I already have > those reported in the bug tracker, but further ones will be welcome. > > This is for testing additional modifications to the new regex > implementation (available on PyPI). There was a DOS security issue in Django about a year back (fixed the day it came to light in changeset 11603), triggered by a regexp with a lot of back-tracking: http://code.djangoproject.com/changeset/11603 which tried to match email_re = re.compile( r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*" # dot-atom r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*"' # quoted-string r')@(?:[A-Z0-9]+(?:-*[A-Z0-9]+)*\.)+[A-Z]{2,6}$', re.IGNORECASE) # domain against 'viewx3dtextx26qx3d at yahoo.comx26latlngx3d15854521645943074058' (should return None rather than a MatchObject). Folks were reporting that it was taking >20min to run. -tkc From alain at dpt-info.u-strasbg.fr Mon Dec 6 08:15:04 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Mon, 06 Dec 2010 14:15:04 +0100 Subject: simple threading.Thread and Semaphores hang References: Message-ID: <87bp4zt547.fsf@dpt-info.u-strasbg.fr> lnenov writes: > My application hangs on exit. > I have isoleted this piece of code that reproduces the error: (the > time module is extra and not needed to reproduce) > > import threading > import time > > def func(): > b = threading.Semaphore(value=0) > b.acquire() This waits for the semaphore to have a positive value. This thread is blocked (apparently forever, since no other thread has access to the semaphore). > a = threading.Thread(target=func) > a.start() > > time.sleep(2) > quit() > > When SystemExit is raised, nothing happens. Python hangs. Your blocked thread is still around, still waiting for the semaphore. Your program won't exit while there are non-daemon threads alive. -- Alain. From mwilson at the-wire.com Mon Dec 6 08:32:18 2010 From: mwilson at the-wire.com (Mel) Date: Mon, 06 Dec 2010 08:32:18 -0500 Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> <7x39qbfhd8.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > mdw at distorted.org.uk (Mark Wooding) writes: >> The most obvious improvement is resumable exceptions. > > You know, I've heard the story from language designers several times > over, that they tried putting resumable exceptions into their languages > and it turned out to be a big mess, so they went to termination > exceptions that fixed the issue. Are there any languages out there with > resumable exceptions? Escaping to a debugger doesn't really count as > that. I guess one way to do it would be call a coroutine to handle the > exception, and either continue or unwind after the continue returns, but > doing it in a single-threaded system just seems full of hazards. Apparently, at the end of his research, Alan Turing was trying out the idea of 'oracles', where a computable process would have access to an uncomputable process to get particular results. I would imagine that the idea here was to clarify what this would do to the computable process. If he had lived, I doubt that Turing would have built an oracle, but the idea does live on in interactive debuggers. It would seem if some situation has arisen that can be fixed by code, then you can just run that code there and then. Then 'resumable exceptions' just become a kind of subroutine call, perhaps like the triggers in SQL. Mel. From jeanmichel at sequans.com Mon Dec 6 09:39:10 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 06 Dec 2010 15:39:10 +0100 Subject: [ANN] Pyclewn: Vim as a front end to pdb In-Reply-To: References: Message-ID: <4CFCF58E.9070603@sequans.com> Xavier de Gaye wrote: > Pyclewn 1.5 has been released at http://pyclewn.sourceforge.net/ > > Pyclewn is a python program that allows the use of Vim as a front end > to gdb and pdb. > > This release adds support for ``pdb``, the python debugger. > > + A python script may be run under the control of ``pdb``. For > example the current vim buffer may be started and debugged with > the vim command ``:Pyclewn pdb %:p`` > > + One may also attach to a running python process, interrupt the > process, manage a debugging session and terminate the debugging > session by detaching from the process. A new debugging session may > be conducted later on this same process, possibly from another Vim > instance. > > + All the ``pdb`` commands are supported except ``list`` and > ``commands``. This includes alias expansion and executing a > python statement in the context of the current frame. The new > command ``threadstack`` prints the instantaneous backtrace of all > the threads, including those that are stuck in a deadlock. > > * Pdb is currently supported on unix platforms and requires the latest > Vim version: Vim 7.3. Python3 is not supported yet. > > The installation fails miserabily if the environment var EDITOR is set to something different than vim (or empty). (I had it set to 'jed'). I had a quick look and I'm not sured it's mentioned anywhere in the help files. By the way I had a quick look at this frontend, it's pretty neat. JM From dan at catfolks.net Mon Dec 6 10:03:48 2010 From: dan at catfolks.net (Dan M) Date: Mon, 06 Dec 2010 09:03:48 -0600 Subject: Newbie needs regex help Message-ID: I'm getting bogged down with backslash escaping. I have some text files containing characters with the 8th bit set. These characters are encoded one of two ways: either "=hh" or "\xhh", where "h" represents a hex digit, and "\x" is a literal backslash followed by a lower-case x. Catching the first case with a regex is simple. But when I try to write a regex to catch the second case, I mess up the escaping. I took at look at http://docs.python.org/howto/regex.html, especially the section titled "The Backslash Plague". I started out trying : dan at dan:~/personal/usenet$ python Python 2.7 (r27:82500, Nov 15 2010, 12:10:23) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import re >>> r = re.compile('\\\\x([0-9a-fA-F]{2})') >>> a = "This \xef file \xef has \x20 a bunch \xa0 of \xb0 crap \xc0 characters \xefn \xeft." >>> m = r.search(a) >>> m No match. I then followed the advice of the above-mentioned document, and expressed the regex as a raw string: >>> r = re.compile(r'\\x([0-9a-fA-F]{2})') >>> r.search(a) Still no match. I'm obviously missing something. I spent a fair bit of time playing with this over the weekend, and I got nowhere. Now it's time to ask for help. What am I doing wrong here? From jeanmichel at sequans.com Mon Dec 6 10:04:24 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 06 Dec 2010 16:04:24 +0100 Subject: is it possible to see if a class has a decorator ? In-Reply-To: <4CFCC91C.3060102@gmail.com> References: <87aakj17m6.fsf@benfinney.id.au> <4CFCC91C.3060102@gmail.com> Message-ID: <4CFCFB78.1020200@sequans.com> Stef Mientki wrote: > On 06-12-2010 12:08, Ben Finney wrote: >> Stef Mientki writes: >> >> >>> I would like to know if a class definition has a decorator, >>> >> I'm not sure what this question means. >> >> Applying a decorator to a class definition produces a normal class. >> >> Classes don't ?have? decorators; classes can be returned by a decorator >> function, but AFAIK the resulting class doesn't ?have? the decorator in >> any sense. >> >> >>> is that possible ? >>> >> The return value of a decorator isn't special in any way, AFAIK. >> >> Any function can return a class object or a function object, and any >> function can be used as a decorator. >> >> The only thing that makes a function a decorator is how it is used in >> the code; but it doesn't leave a trace that I know of. >> >> Now, what is it you're trying to do? Perhaps there's a better solution >> we can come up with. >> >> > Thanks Ben, > here some more explanation. > > I've a number of (dynamic) applications, > launched from a central wrapper. > All these modules have a class "Start", which launches the application > and embeds them in the wrapper application. > > Module 1: > class Start (): > .... > > Module 2: > @auth > class Start (): > ... > > When the wrapper application is started, it looks for all dynamic > modules (without importing them), > and list these application in a hierarchical tree. > In the above axmple, > I would like to know that the class "Start" in Module 2 has the > decorator "Auth", *without importing the module*, > (so depending on the user logged in, I can decide to add or not add > the module to the hierarchical tree). > > thanks, > Stef Mientki > > > > You best bet is to parse the source file. JM From reshma.kerla at gmail.com Mon Dec 6 10:09:37 2010 From: reshma.kerla at gmail.com (Raksha R) Date: Mon, 6 Dec 2010 07:09:37 -0800 (PST) Subject: Anushka Hot still More Message-ID: http://dattinggirls.hpage.us/linklist_75279.html From stef.mientki at gmail.com Mon Dec 6 10:21:35 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Mon, 06 Dec 2010 16:21:35 +0100 Subject: is it possible to see if a class has a decorator ? In-Reply-To: <4CFCFB78.1020200@sequans.com> References: <87aakj17m6.fsf@benfinney.id.au> <4CFCC91C.3060102@gmail.com> <4CFCFB78.1020200@sequans.com> Message-ID: <4CFCFF7F.9030208@gmail.com> On 06-12-2010 16:04, Jean-Michel Pichavant wrote: > Stef Mientki wrote: >> On 06-12-2010 12:08, Ben Finney wrote: >>> Stef Mientki writes: >>> >>> >>>> I would like to know if a class definition has a decorator, >>>> >>> I'm not sure what this question means. >>> >>> Applying a decorator to a class definition produces a normal class. >>> >>> Classes don't ?have? decorators; classes can be returned by a decorator >>> function, but AFAIK the resulting class doesn't ?have? the decorator in >>> any sense. >>> >>> >>>> is that possible ? >>>> >>> The return value of a decorator isn't special in any way, AFAIK. >>> >>> Any function can return a class object or a function object, and any >>> function can be used as a decorator. >>> >>> The only thing that makes a function a decorator is how it is used in >>> the code; but it doesn't leave a trace that I know of. >>> >>> Now, what is it you're trying to do? Perhaps there's a better solution >>> we can come up with. >>> >>> >> Thanks Ben, >> here some more explanation. >> >> I've a number of (dynamic) applications, >> launched from a central wrapper. >> All these modules have a class "Start", which launches the application and embeds them in the >> wrapper application. >> >> Module 1: >> class Start (): >> .... >> >> Module 2: >> @auth >> class Start (): >> ... >> >> When the wrapper application is started, it looks for all dynamic modules (without importing them), >> and list these application in a hierarchical tree. >> In the above axmple, >> I would like to know that the class "Start" in Module 2 has the decorator "Auth", *without >> importing the module*, >> (so depending on the user logged in, I can decide to add or not add the module to the >> hierarchical tree). >> >> thanks, >> Stef Mientki >> >> >> >> > You best bet is to parse the source file. thanks, I was afraid of that. cheers, Stef > > JM From mwilson at the-wire.com Mon Dec 6 10:29:41 2010 From: mwilson at the-wire.com (Mel) Date: Mon, 06 Dec 2010 10:29:41 -0500 Subject: Newbie needs regex help References: Message-ID: Dan M wrote: > I'm getting bogged down with backslash escaping. > > I have some text files containing characters with the 8th bit set. These > characters are encoded one of two ways: either "=hh" or "\xhh", where "h" > represents a hex digit, and "\x" is a literal backslash followed by a > lower-case x. > > Catching the first case with a regex is simple. But when I try to write a > regex to catch the second case, I mess up the escaping. > > I took at look at http://docs.python.org/howto/regex.html, especially the > section titled "The Backslash Plague". I started out trying : > > dan at dan:~/personal/usenet$ python > Python 2.7 (r27:82500, Nov 15 2010, 12:10:23) > [GCC 4.3.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import re >>>> r = re.compile('\\\\x([0-9a-fA-F]{2})') >>>> a = "This \xef file \xef has \x20 a bunch \xa0 of \xb0 crap \xc0 > characters \xefn \xeft." >>>> m = r.search(a) >>>> m > > No match. > > I then followed the advice of the above-mentioned document, and expressed > the regex as a raw string: > >>>> r = re.compile(r'\\x([0-9a-fA-F]{2})') >>>> r.search(a) > > Still no match. > > I'm obviously missing something. I spent a fair bit of time playing with > this over the weekend, and I got nowhere. Now it's time to ask for help. > What am I doing wrong here? What you're missing is that string `a` doesn't actually contain four- character sequences like '\', 'x', 'a', 'a' . It contains single characters that you encode in string literals as '\xaa' and so on. You might do better with p1 = r'([\x80-\xff])' r1 = re.compile (p1) m = r1.search (a) I get at least an <_sre.SRE_Match object at 0xb749a6e0> when I try this. Mel. From alain at dpt-info.u-strasbg.fr Mon Dec 6 10:34:56 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Mon, 06 Dec 2010 16:34:56 +0100 Subject: Newbie needs regex help References: Message-ID: <8739qaud7j.fsf@dpt-info.u-strasbg.fr> Dan M writes: > I took at look at http://docs.python.org/howto/regex.html, especially the > section titled "The Backslash Plague". I started out trying : >>>> import re >>>> r = re.compile('\\\\x([0-9a-fA-F]{2})') >>>> a = "This \xef file \xef has \x20 a bunch \xa0 of \xb0 crap \xc0 The backslash trickery applies to string literals also, not only regexps. Your string does not have the value you think it has. Double each backslash (or make your string raw) and you'll get what you expect. -- Alain. From astan.chee at gmail.com Mon Dec 6 10:37:30 2010 From: astan.chee at gmail.com (Astan Chee) Date: Tue, 7 Dec 2010 02:37:30 +1100 Subject: RCX using python serial help Message-ID: Hi, I've got a lego mindstorm RCX 1.0 (but firmware is 2.0) that uses one of those old serial IR towers to control the microcontroller. I've had a look around at python's serial documentation as well as the RCX's documentation and I'm trying to write something to control the RCX directly using python. Several examples from of doing this in python include using lnp (i think) and that doesn't quite run well in windows. I've had a look at the C++ code and some protocol documentation here: http://www.generation5.org/content/2001/rob08.asp and converted it to python. I've attached it at the end of the email. So now I've figured out how to check for the battery level and it seems to work (I've tested it on my RCX) but I'm confused with the other documentation (e.g. http://graphics.stanford.edu/~kekoa/rcx/ ) about how to do this in python or what this all means. I was wondering if anyone can help me complete these? or maybe help me do it step-by-step? Thanks for any help. Below is the python code I've been working on: import time import serial import struct import binascii def tcbin(x, y=8): """ This function returns the padded, two's complement representation of x, in y-bits. It is conventional for y to be 8, 16, 32 or 64, though y can have any non-zero positive value. """ if x >= 0: binstr = bin(x) # pad with leading zeros while len(binstr) < y + 2: binstr = "0b0" + binstr[2:] return binstr return bin((2**y) + x) # x is negative def bitcompliment(hex_code): return hex(int(tcbin(~(ord(hex_code))),2)) def processOutput(raw_data,output): outputStatus = True pos = 0 for i in range(3): if raw_data[i] != output[i]: outputStatus = False pos+=1 if outputStatus: print "output OK" else: print "problem with output" outputCompliment = True while outputCompliment: if hex(ord(output[pos])) == bitcompliment(output[pos+1]): print "output compliment OK" else: print "problem with output compliment" pos+=2 if hex(ord(output[pos])) == '0x55' and hex(ord(output[pos+1])) == '0xff' and hex(ord(output[pos+2])) == '0x0': pos+=3 outputCompliment = False if hex(ord(output[pos])) == '0xcf' or hex(ord(output[pos])) == '0xc7': #battery checker pos+=2 if hex(ord(output[pos])) == bitcompliment(output[pos+1]) and hex(ord(output[pos+2])) == bitcompliment(output[pos+3]): s = ((ord(output[pos+2]) * 256) + ord(output[pos])) / 1000.0 print "Battery is at " + str(s) + " Volts" else: for i in range(len(output[pos:]),len(output),2): print hex(ord(output[i])) if i+1 < len(output): if hex(ord(output[i])) == bitcompliment(output[i+1]): print "message OK. contents: " + hex(ord(output[i])) # configure the serial connections (the parameters differs on the device you are connecting to) ser = serial.Serial( port='COM1', baudrate=2400, parity=serial.PARITY_ODD, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS ) raw_data = '\x55\xff\x00\x38\xc7\x38\xc7' result = ser.write(raw_data) out = '' time.sleep(1) #pause for a second while ser.inWaiting() > 0: out+=ser.read(1) processOutput(raw_data,out) -------------- next part -------------- An HTML attachment was scrubbed... URL: From dan at catfolks.net Mon Dec 6 10:44:39 2010 From: dan at catfolks.net (Dan M) Date: Mon, 06 Dec 2010 09:44:39 -0600 Subject: Newbie needs regex help References: Message-ID: On Mon, 06 Dec 2010 10:29:41 -0500, Mel wrote: > What you're missing is that string `a` doesn't actually contain four- > character sequences like '\', 'x', 'a', 'a' . It contains single > characters that you encode in string literals as '\xaa' and so on. You > might do better with > > p1 = r'([\x80-\xff])' > r1 = re.compile (p1) > m = r1.search (a) > > I get at least an <_sre.SRE_Match object at 0xb749a6e0> when I try this. > > Mel. That's what I had initially assumed was the case, but looking at the data files with a hex editor showed me that I do indeed have four-character sequences. That's what makes this such as interesting task! From phd at phd.pp.ru Mon Dec 6 10:47:14 2010 From: phd at phd.pp.ru (Oleg Broytman) Date: Mon, 6 Dec 2010 18:47:14 +0300 Subject: SQLObject 0.15.0 Message-ID: <20101206154714.GB12211@phd.pp.ru> Hello! I'm pleased to announce version 0.15.0, the first stable release of branch 0.15 of SQLObject. What is SQLObject ================= SQLObject is an object-relational mapper. Your database tables are described as classes, and rows are instances of those classes. SQLObject is meant to be easy to use and quick to get started with. SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite, Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB). Where is SQLObject ================== Site: http://sqlobject.org Development: http://sqlobject.org/devel/ Mailing list: https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss Archives: http://news.gmane.org/gmane.comp.python.sqlobject Download: http://cheeseshop.python.org/pypi/SQLObject/0.15.0 News and changes: http://sqlobject.org/News.html What's New ========== * Major API change: all signals are sent with the instance (or the class) as the first parameter. The following signals were changed: RowCreateSignal, RowCreatedSignal, DeleteColumnSignal. * Major API change: post-processing functions for all signals are called with the instance as the first parameter. The following signals were changed: RowUpdatedSignal, RowDestroySignal, RowDestroyedSignal. For a more complete list, please see the news: http://sqlobject.org/News.html Oleg. -- Oleg Broytman http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From dan at catfolks.net Mon Dec 6 10:48:50 2010 From: dan at catfolks.net (Dan M) Date: Mon, 06 Dec 2010 09:48:50 -0600 Subject: Newbie needs regex help References: <8739qaud7j.fsf@dpt-info.u-strasbg.fr> Message-ID: On Mon, 06 Dec 2010 16:34:56 +0100, Alain Ketterlin wrote: > Dan M writes: > >> I took at look at http://docs.python.org/howto/regex.html, especially >> the section titled "The Backslash Plague". I started out trying : > >>>>> import re >>>>> r = re.compile('\\\\x([0-9a-fA-F]{2})') a = "This \xef file \xef has >>>>> \x20 a bunch \xa0 of \xb0 crap \xc0 > > The backslash trickery applies to string literals also, not only > regexps. > > Your string does not have the value you think it has. Double each > backslash (or make your string raw) and you'll get what you expect. > > -- Alain. D'oh! I hadn't thought of that. If I read my data file in from disk, use the raw string version of the regex, and do the search that way I do indeed get the results I'm looking for. Thanks for pointing that out. I guess I need to think a little deeper into what I'm doing when I escape stuff. From iamforufriends at gmail.com Mon Dec 6 11:25:14 2010 From: iamforufriends at gmail.com (kate for free dating) Date: Mon, 6 Dec 2010 08:25:14 -0800 (PST) Subject: hay... this is kate, we r staying near by u, wanna dating with me... Message-ID: hay... this is kate, we r staying near by u, wanna dating with me... http://x2c.eu/57 http://x2c.eu/57 http://x2c.eu/57 http://x2c.eu/57 From cmpython at gmail.com Mon Dec 6 11:35:39 2010 From: cmpython at gmail.com (CM) Date: Mon, 6 Dec 2010 08:35:39 -0800 (PST) Subject: Which non SQL Database ? References: <87d3phcfaw.fsf@gmail.com> <1ae2b7eb-0ccc-420e-8e62-92aafebd827e@p38g2000vbn.googlegroups.com> Message-ID: <90914734-4fa5-4a2e-8d14-079b87ba3d73@n32g2000pre.googlegroups.com> On Dec 6, 2:17?am, Steve Holden wrote: > On 12/5/2010 12:59 AM, CM wrote: > > > SQlite itself is around 300 kilobytes. ?That's negligible. ?It is also > > already in Python, so you'd have to purposefully exclude it in > > creating your executable to save those 300 kb and thus the 1/13th of a > > second additional time it would take average (3.9 MB/s) users to > > download your app if it were included. > > Just as a matter of interest where do you get the information that the > average user has a 3.9 MB/s path to the Internet? First, I should have specified the average *U.S.* user, and in so doing realized how dumbly "own-nation-centric" that was. My apologies. But I got it from this: http://arstechnica.com/telecom/news/2010/01/us-broadband-still-lagging-in-speed-and-penetration.ars No idea how accurate that is, and I didn't break that into download vs. upload speeds. It puts the U.S. 18th in the world rankings of average connection speed. Also, for what it's worth, I noticed in making an .exe yesterday that sqlite3.dll is listed as 843 kB. That may be because it includes pysqlite as well, I don't know. In any case, that is at least appreciably higher than the 300 kb I listed above, though not too bad. If someone is trying to squeak out every last bit of savings in making their .exe small, then sqlite.dll is something they could consider excluding, if they can. But for most cases, no user will care about the extra size. Che > regards > ?Steve > -- > Steve Holden ? ? ? ? ? +1 571 484 6266 ? +1 800 494 3119 > PyCon 2011 Atlanta March 9-17 ? ? ?http://us.pycon.org/ > See Python Video! ? ? ?http://python.mirocommunity.org/ > Holden Web LLC ? ? ? ? ? ? ? ?http://www.holdenweb.com/ From bigblueswope at gmail.com Mon Dec 6 11:40:21 2010 From: bigblueswope at gmail.com (BJ Swope) Date: Mon, 6 Dec 2010 11:40:21 -0500 Subject: Passing Variable(s) as kwargs Message-ID: Hello All. I am trying to use values, retrieved from a config file, as kwargs and not having any luck. Well at least I think that's what I'm trying to do ;) Any suggestions would be most appreciated. Here's the exception: Traceback (most recent call last): File "c:\dev\LogServerMonitor\LogServerMonitor.py", line 246, in sched.add_cron_job(check_logging_db, minute = '*/run_interval_quantity') File "c:\Python26\lib\site-packages\apscheduler\scheduler.py", line 249, in add_cron_job second) File "c:\Python26\lib\site-packages\apscheduler\triggers.py", line 22, in __init__ self._compile_expressions(minutes, 'minute') File "c:\Python26\lib\site-packages\apscheduler\triggers.py", line 43, in _compile_expressions compiled_expr_list = [compile_single(expr) for expr in expr_list] File "c:\Python26\lib\site-packages\apscheduler\triggers.py", line 36, in compile_single (expr, fieldname)) ValueError: Unrecognized expression "*/run_interval_quantity" for field "minute" An example of what I am doing is: ###################################################################################### Config File Contents: [RunInterval] #How often the application queries the DB to look for the date of #the last entry (Default every 1 Minute). #Valid RunInterval Quantities are integers > 0 RunIntervalQuantity: 1 #Valid RunInterval Types are S=Seconds, M=Minutes, H=Hours, D=Days RunIntervalType: M ############################################################################################## My Code config = ConfigParser.ConfigParser() try: config.readfp(open(config_file)) except: sys.stderr.write('Config file, "%s", is missing or unreadable. Exiting.' % config_file) sys.stderr.write('ERROR: %s\r\n' % str(err)) sys.exit(1) def getOption(section, option): try: opt_value = config.get(section, option) return opt_value except (ConfigParser.NoOptionError), err: sys.stderr.write( "Application requires \"%s\" be defined in the [%s] section of the config file %s\r\n" % (option, section, config_file)) sys.stderr.write('ERROR: %s\r\n' % str(err)) sys.exit(1) def getOptionInt(section, option): try: opt_value = config.getint(section, option) return opt_value except (ValueError, ConfigParser.NoOptionError), err: sys.stderr.write("Application requires \"%s\" be defined as an Integer in the \"[%s]\" section of the config file %s" % (option, section, config_file)) sys.stderr.write('ERROR: %s\r\n' % str(err)) sys.exit(1) # Start the scheduler sched = Scheduler() sched.start() run_interval_quantity = getOptionInt('RunInterval', 'RunIntervalQuantity') run_interval_type = getOption('RunInterval', 'RunIntervalType') if run_interval_type in ['S', 's']: sched.add_cron_job(check_logging_db, second = '*/run_interval_quantity') elif run_interval_type in ['M', 'm']: sched.add_cron_job(check_logging_db, minute = '*/run_interval_quantity') elif run_interval_type in ['H', 'h']: sched.add_cron_job(check_logging_db, hour = '*/run_interval_quantity') elif run_interval_type in ['D', 'd']: sched.add_cron_job(check_logging_db, day = '*/run_interval_quantity') else: my_logger.warning('The value of RunIntervalType in the configuration file section RunInterval was not one of "S, M, H or D". Running LogServerMonitor application once per minute by default.') sched.add_cron_job(check_logging_db, minute = '*') -------------- next part -------------- An HTML attachment was scrubbed... URL: From tomf.sessile at gmail.com Mon Dec 6 11:59:12 2010 From: tomf.sessile at gmail.com (TomF) Date: Mon, 6 Dec 2010 08:59:12 -0800 Subject: Comparisons of incompatible types Message-ID: <2010120608591221344-tomfsessile@gmailcom> I'm aggravated by this behavior in python: x = "4" print x < 7 # prints False The issue, of course, is comparisons of incompatible types. In most languages this throws an error (in Perl the types are converted silently). In Python this comparison fails silently. The documentation says: "objects of different types *always* compare unequal, and are ordered consistently but arbitrarily." I can't imagine why this design decision was made. I've been bitten by this several times (reading data from a file and not converting the numbers before comparison). Can I get this to throw an error instead of failing silently? Thanks, -Tom From dan at catfolks.net Mon Dec 6 12:02:11 2010 From: dan at catfolks.net (Dan M) Date: Mon, 06 Dec 2010 11:02:11 -0600 Subject: Newbie needs regex help References: Message-ID: On Mon, 06 Dec 2010 09:44:39 -0600, Dan M wrote: > That's what I had initially assumed was the case, but looking at the > data files with a hex editor showed me that I do indeed have > four-character sequences. That's what makes this such as interesting > task! Sorry, I misunderstood the first time I read your reply. You're right, the string I showed did indeed contain single-byte characters, not four-character sequences. The data file I work with, though, does contain four-character sequences. From __peter__ at web.de Mon Dec 6 12:04:00 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 06 Dec 2010 18:04 +0100 Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> Message-ID: TomF wrote: > I'm aggravated by this behavior in python: > > x = "4" > print x < 7 # prints False > > The issue, of course, is comparisons of incompatible types. In most > languages this throws an error (in Perl the types are converted > silently). In Python this comparison fails silently. The > documentation says: "objects of different types *always* compare > unequal, and are ordered consistently but arbitrarily." > > I can't imagine why this design decision was made. I've been bitten by > this several times (reading data from a file and not converting the > numbers before comparison). Can I get this to throw an error instead > of failing silently? This change would break a lot of code, so it could not be made within the 2.x series. However: Python 3.1.1+ (r311:74480, Nov 2 2009, 15:45:00) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> "4" < 7 Traceback (most recent call last): File "", line 1, in TypeError: unorderable types: str() < int() Peter From mail at timgolden.me.uk Mon Dec 6 12:04:39 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 06 Dec 2010 17:04:39 +0000 Subject: Comparisons of incompatible types In-Reply-To: <2010120608591221344-tomfsessile@gmailcom> References: <2010120608591221344-tomfsessile@gmailcom> Message-ID: <4CFD17A7.2010805@timgolden.me.uk> On 06/12/2010 16:59, TomF wrote: > I'm aggravated by this behavior in python: > > x = "4" > print x < 7 # prints False > > The issue, of course, is comparisons of incompatible types. In most > languages this throws an error (in Perl the types are converted > silently). In Python this comparison fails silently. The documentation > says: "objects of different types *always* compare unequal, and are > ordered consistently but arbitrarily." > > I can't imagine why this design decision was made. I've been bitten by > this several times (reading data from a file and not converting the > numbers before comparison). Can I get this to throw an error instead of > failing silently? Yes: switch to python 3 where this does throw an exception: Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52 Type "help", "copyright", "credits" or "license >>> 7 < "eight" Traceback (most recent call last): File "", line 1, in TypeError: unorderable types: int() < str() >>> TJG From python at mrabarnett.plus.com Mon Dec 6 12:11:30 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 06 Dec 2010 17:11:30 +0000 Subject: Which non SQL Database ? In-Reply-To: <90914734-4fa5-4a2e-8d14-079b87ba3d73@n32g2000pre.googlegroups.com> References: <87d3phcfaw.fsf@gmail.com> <1ae2b7eb-0ccc-420e-8e62-92aafebd827e@p38g2000vbn.googlegroups.com> <90914734-4fa5-4a2e-8d14-079b87ba3d73@n32g2000pre.googlegroups.com> Message-ID: <4CFD1942.7060102@mrabarnett.plus.com> On 06/12/2010 16:35, CM wrote: > On Dec 6, 2:17 am, Steve Holden wrote: >> On 12/5/2010 12:59 AM, CM wrote: >> >>> SQlite itself is around 300 kilobytes. That's negligible. It is also >>> already in Python, so you'd have to purposefully exclude it in >>> creating your executable to save those 300 kb and thus the 1/13th of a >>> second additional time it would take average (3.9 MB/s) users to >>> download your app if it were included. >> >> Just as a matter of interest where do you get the information that the >> average user has a 3.9 MB/s path to the Internet? > > First, I should have specified the average *U.S.* user, and in so > doing realized how dumbly "own-nation-centric" that was. My > apologies. But I got it from this: > http://arstechnica.com/telecom/news/2010/01/us-broadband-still-lagging-in-speed-and-penetration.ars > [snip] You're also confusing MB/s (bytes) with Mb/s (bits). From __peter__ at web.de Mon Dec 6 12:12:33 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 06 Dec 2010 18:12:33 +0100 Subject: Newbie needs regex help References: Message-ID: Dan M wrote: > I'm getting bogged down with backslash escaping. > > I have some text files containing characters with the 8th bit set. These > characters are encoded one of two ways: either "=hh" or "\xhh", where "h" > represents a hex digit, and "\x" is a literal backslash followed by a > lower-case x. By the way: >>> print quopri.decodestring("=E4=F6=FC").decode("iso-8859-1") ??? >>> print r"\xe4\xf6\xfc".decode("string-escape").decode("iso-8859-1") ??? From tomf.sessile at gmail.com Mon Dec 6 12:16:10 2010 From: tomf.sessile at gmail.com (TomF) Date: Mon, 6 Dec 2010 09:16:10 -0800 Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> Message-ID: <2010120609161055524-tomfsessile@gmailcom> On 2010-12-06 09:04:00 -0800, Peter Otten said: > TomF wrote: > >> I'm aggravated by this behavior in python: >> >> x = "4" >> print x < 7 # prints False >> >> The issue, of course, is comparisons of incompatible types. In most >> languages this throws an error (in Perl the types are converted >> silently). In Python this comparison fails silently. The >> documentation says: "objects of different types *always* compare >> unequal, and are ordered consistently but arbitrarily." >> >> I can't imagine why this design decision was made. I've been bitten by >> this several times (reading data from a file and not converting the >> numbers before comparison). Can I get this to throw an error instead >> of failing silently? > > This change would break a lot of code, so it could not be made within the > 2.x series. However: > > Python 3.1.1+ (r311:74480, Nov 2 2009, 15:45:00) > [GCC 4.4.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> "4" < 7 > Traceback (most recent call last): > File "", line 1, in > TypeError: unorderable types: str() < int() Thanks. I was hoping there was something I could do for 2.x but I suppose this will have to do. But I'm mystified by your statement, "this change would break a lot of code". Given that the semantics are virtually random, how could code depend on this? -Tom From python at mrabarnett.plus.com Mon Dec 6 12:23:42 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 06 Dec 2010 17:23:42 +0000 Subject: Passing Variable(s) as kwargs In-Reply-To: References: Message-ID: <4CFD1C1E.8040500@mrabarnett.plus.com> On 06/12/2010 16:40, BJ Swope wrote: > Hello All. > > I am trying to use values, retrieved from a config file, as kwargs and > not having any luck. Well at least I think that's what I'm trying to do ;) > > Any suggestions would be most appreciated. > > Here's the exception: > > Traceback (most recent call last): > File "c:\dev\LogServerMonitor\LogServerMonitor.py", line 246, in > sched.add_cron_job(check_logging_db, minute = > '*/run_interval_quantity') > File "c:\Python26\lib\site-packages\apscheduler\scheduler.py", line > 249, in add_cron_job > second) > File "c:\Python26\lib\site-packages\apscheduler\triggers.py", line > 22, in __init__ > self._compile_expressions(minutes, 'minute') > File "c:\Python26\lib\site-packages\apscheduler\triggers.py", line > 43, in _compile_expressions > compiled_expr_list = [compile_single(expr) for expr in expr_list] > File "c:\Python26\lib\site-packages\apscheduler\triggers.py", line > 36, in compile_single > (expr, fieldname)) > ValueError: Unrecognized expression "*/run_interval_quantity" for field > "minute" > > > > An example of what I am doing is: > ###################################################################################### > Config File Contents: > [RunInterval] > #How often the application queries the DB to look for the date of > #the last entry (Default every 1 Minute). > > #Valid RunInterval Quantities are integers > 0 > RunIntervalQuantity: 1 > > #Valid RunInterval Types are S=Seconds, M=Minutes, H=Hours, D=Days > RunIntervalType: M > > ############################################################################################## > > My Code > > > config = ConfigParser.ConfigParser() > try: > config.readfp(open(config_file)) > except: > sys.stderr.write('Config file, "%s", is missing or unreadable. > Exiting.' % config_file) > sys.stderr.write('ERROR: %s\r\n' % str(err)) > sys.exit(1) > > > def getOption(section, option): > try: > opt_value = config.get(section, option) > return opt_value > except (ConfigParser.NoOptionError), err: > sys.stderr.write( "Application requires \"%s\" be defined in > the [%s] section of the config file %s\r\n" % (option, section, > config_file)) > sys.stderr.write('ERROR: %s\r\n' % str(err)) > sys.exit(1) > > def getOptionInt(section, option): > try: > opt_value = config.getint(section, option) > return opt_value > except (ValueError, ConfigParser.NoOptionError), err: > sys.stderr.write("Application requires \"%s\" be defined as an > Integer in the \"[%s]\" section of the config file %s" % (option, > section, config_file)) > sys.stderr.write('ERROR: %s\r\n' % str(err)) > sys.exit(1) > > > > # Start the scheduler > sched = Scheduler() > sched.start() > run_interval_quantity = getOptionInt('RunInterval', 'RunIntervalQuantity') > run_interval_type = getOption('RunInterval', 'RunIntervalType') > > if run_interval_type in ['S', 's']: > sched.add_cron_job(check_logging_db, second = > '*/run_interval_quantity') > elif run_interval_type in ['M', 'm']: > sched.add_cron_job(check_logging_db, minute = > '*/run_interval_quantity') > elif run_interval_type in ['H', 'h']: > sched.add_cron_job(check_logging_db, hour = '*/run_interval_quantity') > elif run_interval_type in ['D', 'd']: > sched.add_cron_job(check_logging_db, day = '*/run_interval_quantity') > else: > my_logger.warning('The value of RunIntervalType in the > configuration file section RunInterval was not one of "S, M, H or D". > Running LogServerMonitor application once per minute by default.') > sched.add_cron_job(check_logging_db, minute = '*') > It's complaining that the 'minute' argument which you're passing to 'add_cron_job' is '*/run_interval_quantity', which the scheduler doesn't understand. From davea at ieee.org Mon Dec 6 12:39:23 2010 From: davea at ieee.org (Dave Angel) Date: Mon, 06 Dec 2010 12:39:23 -0500 Subject: Which non SQL Database ? In-Reply-To: <90914734-4fa5-4a2e-8d14-079b87ba3d73@n32g2000pre.googlegroups.com> References: <87d3phcfaw.fsf@gmail.com> <1ae2b7eb-0ccc-420e-8e62-92aafebd827e@p38g2000vbn.googlegroups.com> <90914734-4fa5-4a2e-8d14-079b87ba3d73@n32g2000pre.googlegroups.com> Message-ID: <4CFD1FCB.40009@ieee.org> On 01/-10/-28163 02:59 PM, CM wrote: > On Dec 6, 2:17 am, Steve Holden wrote: >> Just as a matter of interest where do you get the information that the >> average user has a 3.9 MB/s path to the Internet? > > First, I should have specified the average *U.S.* user, and in so > doing realized how dumbly "own-nation-centric" that was. My > apologies. But I got it from this: > http://arstechnica.com/telecom/news/2010/01/us-broadband-still-lagging-in-speed-and-penetration.ars > You're confusing megabits with megabytes. The article says the average in the US is 3.9Mb/s, which is only 0.41MB/s. Still seems high to me, but I have no statistics. DaveA From robert.kern at gmail.com Mon Dec 6 12:46:21 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 06 Dec 2010 11:46:21 -0600 Subject: Comparisons of incompatible types In-Reply-To: <2010120609161055524-tomfsessile@gmailcom> References: <2010120608591221344-tomfsessile@gmailcom> <2010120609161055524-tomfsessile@gmailcom> Message-ID: On 12/6/10 11:16 AM, TomF wrote: > > On 2010-12-06 09:04:00 -0800, Peter Otten said: >> This change would break a lot of code, so it could not be made within the >> 2.x series. However: >> >> Python 3.1.1+ (r311:74480, Nov 2 2009, 15:45:00) >> [GCC 4.4.1] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >>>>> "4" < 7 >> Traceback (most recent call last): >> File "", line 1, in >> TypeError: unorderable types: str() < int() > > Thanks. I was hoping there was something I could do for 2.x but I suppose this > will have to do. > > But I'm mystified by your statement, "this change would break a lot of code". > Given that the semantics are virtually random, how could code depend on this? There are cases where you don't particularly care *what* order is given as long as it is consistent. Let's say you want to make sure that two lists have the same contents (which may mix types), but you don't care about the order. You could just sort each list and then compare the sorted lists. Before sets were added to the language, this was a fairly common approach. -- 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 bigblueswope at gmail.com Mon Dec 6 12:47:27 2010 From: bigblueswope at gmail.com (BJ Swope) Date: Mon, 6 Dec 2010 12:47:27 -0500 Subject: Passing Variable(s) as kwargs In-Reply-To: <4CFD1C1E.8040500@mrabarnett.plus.com> References: <4CFD1C1E.8040500@mrabarnett.plus.com> Message-ID: > > It's complaining that the 'minute' argument which you're passing to > 'add_cron_job' is '*/run_interval_quantity', which the scheduler > doesn't understand. > -- > Hey, what do you know, there's a forest amongst all those trees... key_words = '*/%d' % (run_interval_quantity) sched.add_cron_job(check_logging_db, minute = key_words) Works! -------------- next part -------------- An HTML attachment was scrubbed... URL: From dan at catfolks.net Mon Dec 6 12:58:05 2010 From: dan at catfolks.net (Dan M) Date: Mon, 06 Dec 2010 11:58:05 -0600 Subject: Newbie needs regex help References: Message-ID: On Mon, 06 Dec 2010 18:12:33 +0100, Peter Otten wrote: > By the way: > >>>> print quopri.decodestring("=E4=F6=FC").decode("iso-8859-1") > ??? >>>> print r"\xe4\xf6\xfc".decode("string-escape").decode("iso-8859-1") > ??? Ah - better than a regex. Thanks! From cmpython at gmail.com Mon Dec 6 13:46:26 2010 From: cmpython at gmail.com (CM) Date: Mon, 6 Dec 2010 10:46:26 -0800 (PST) Subject: Which non SQL Database ? References: <87d3phcfaw.fsf@gmail.com> <1ae2b7eb-0ccc-420e-8e62-92aafebd827e@p38g2000vbn.googlegroups.com> <90914734-4fa5-4a2e-8d14-079b87ba3d73@n32g2000pre.googlegroups.com> Message-ID: <9531285a-ae41-4149-b8ef-969aee5d19a4@n32g2000pre.googlegroups.com> > You're also confusing MB/s (bytes) with Mb/s (bits). Yes I am. I think I will now recuse myself from the proceedings... From nagle at animats.com Mon Dec 6 13:50:51 2010 From: nagle at animats.com (John Nagle) Date: Mon, 06 Dec 2010 10:50:51 -0800 Subject: Comparison with False - something I don't understand In-Reply-To: <7xvd3crqqt.fsf@ruckus.brouhaha.com> References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <7xvd3crqqt.fsf@ruckus.brouhaha.com> Message-ID: <4cfd308a$0$1605$742ec2ed@news.sonic.net> On 12/2/2010 10:09 AM, Paul Rubin wrote: > MRAB writes: >> When writing the C code for the new regex module I thought that it >> would've been easier if I could've used exceptions to propagate errors >> and unwind the stack, instead of having to return an error code which >> had to be checked by the caller, and then have the caller explicitly >> return an error code to /its/ caller. > > That's called longjmp. > >> Automatic garbage collection would also have been nice. > > alloca might help. If you want proper exception unwinding, use C++, which has it. "longjmp" is a hack from the PDP-11 era. John Nagle From martin at address-in-sig.invalid Mon Dec 6 13:59:21 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Mon, 6 Dec 2010 18:59:21 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> <7x39qbfhd8.fsf@ruckus.brouhaha.com> Message-ID: On Mon, 06 Dec 2010 09:54:46 -0800, Dennis Lee Bieber wrote: > On Mon, 06 Dec 2010 00:14:11 -0800, Paul Rubin > declaimed the following in gmane.comp.python.general: > > >> exceptions that fixed the issue. Are there any languages out there >> with resumable exceptions? Escaping to a debugger doesn't really count >> as > > Visual BASIC 6 > > -=-=-=-=- > On Error GoTo line > 9999 REM Actions to sort out the error RESUME > Enables the error-handling routine that starts at line > specified in the required line argument. The line argument is any line > label or line number. If a run-time error occurs, control branches to > line, making the error handler active. The specified line must be in the > same procedure as the On Error statement; otherwise, a compile-time > error occurs. > Any BASIC that implements ON ERROR (i.e. just about all of them) will do this, not just VB. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From solipsis at pitrou.net Mon Dec 6 14:00:17 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 6 Dec 2010 20:00:17 +0100 Subject: Perceived inconsistency in py3k documentation References: <724b26b4-8233-4d57-b76f-cd781cf0cd03@z17g2000prz.googlegroups.com> Message-ID: <20101206200017.0c5fc63f@pitrou.net> On Sun, 05 Dec 2010 14:47:38 -0500 Terry Reedy wrote: > On 12/5/2010 3:31 AM, Greg wrote: > > For future reference, > > > 1) At http://docs.python.org/py3k/reference/datamodel.html: > > 2) At http://docs.python.org/py3k/library/stdtypes.html: > > do not work because of the trailing :s, at least not with FireFox. Work fine here. The problem isn't Firefox, it is your e-mail or news client. Antoine. From nagle at animats.com Mon Dec 6 14:23:15 2010 From: nagle at animats.com (John Nagle) Date: Mon, 06 Dec 2010 11:23:15 -0800 Subject: Resumable exceptions bad: (was Re: Comparison with False - something I don't understand) In-Reply-To: References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> <7x39qbfhd8.fsf@ruckus.brouhaha.com> Message-ID: <4cfd3822$0$1629$742ec2ed@news.sonic.net> On 12/6/2010 12:40 AM, Steve Holden wrote: > On 12/6/2010 9:14 AM, Paul Rubin wrote: >> mdw at distorted.org.uk (Mark Wooding) writes: >>> The most obvious improvement is resumable exceptions. >> >> You know, I've heard the story from language designers several times >> over, that they tried putting resumable exceptions into their languages >> and it turned out to be a big mess, so they went to termination >> exceptions that fixed the issue. Are there any languages out there with >> resumable exceptions? Escaping to a debugger doesn't really count as >> that. I guess one way to do it would be call a coroutine to handle the >> exception, and either continue or unwind after the continue returns, but >> doing it in a single-threaded system just seems full of hazards. > > I seem to remember PL/1 has resumable exceptions, but I don't ever > remember finding a real use for them. And it's so long since I used PL/1 > I may be mistaken. Resumable exceptions were a popular idea in the early days of programming. LISP, PL/I, and early COBOL had constructs which could be considered resumable exceptions. They didn't work out well, because the exception handler gets control in an ambiguous situation, perhaps in the middle of an expression. Changing the state of the execution, then returning, can leave the program in an invalid state. Signal handling has many of the same problems. A POSIX signal is a forced subroutine call while something else is going on, which is in itself a weird concept. That's what a resumable exception looks like. CPython has a terrible time with signal handling. See "http://www.dabeaz.com/python/UnderstandingGIL.pdf" for the whole ugly mess. That's why control-C won't terminate multi-thread programs, among other things. Unwinding cleanly from a signal is difficult, but possible with proper CPU and compiler design. It's done right in Ada, and in Visual C++ for x86 on Windows. Only some CPUs support "exact" floating point exceptions, where you're guaranteed that the exception comes in at the point where the problem occurred. In modern superscalar CPUs, the exception comes in several instructions after the problem was detected. In x86 type CPUs, the CPU hardware in the "retirement unit" backs up the CPU state to the point at which the exception was detected. PowerPC and SPARC CPUs do not do this; if you need exactness in exception position on them, you have to put in "fence" instructions to stop lookahead. This costs performance. As a result, C code which unwinds from signals via "longjmp" is not portable. See "https://www.securecoding.cert.org/confluence/display/seccode/SIG32-C.+Do+not+call+longjmp%28%29+from+inside+a+signal+handler" Nor is changing the program state from inside a signal handler. You're not entirely sure, on many CPUs, where control is at the point the signal came in. (In a physics simulator, I once had to handle floating point overflow, which indicated that the computation had to be backed up and rerun with a smaller time step. It's possible to do this safely under Windows on x86 if you read all the appropriate documents. It's not portable. That's why I'm aware of this mess.) So that's why resumable exceptions are a bad idea. John Nagle From tjreedy at udel.edu Mon Dec 6 14:34:42 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 06 Dec 2010 14:34:42 -0500 Subject: Comparisons of incompatible types In-Reply-To: References: <2010120608591221344-tomfsessile@gmailcom> <2010120609161055524-tomfsessile@gmailcom> Message-ID: On 12/6/2010 12:46 PM, Robert Kern wrote: > On 12/6/10 11:16 AM, TomF wrote: >> Given that the semantics are virtually random, how could code depend >> on this? > > There are cases where you don't particularly care *what* order is given > as long as it is consistent. Let's say you want to make sure that two > lists have the same contents (which may mix types), but you don't care > about the order. You could just sort each list and then compare the > sorted lists. Before sets were added to the language, this was a fairly > common approach. And indeed, code like this that has not been updated does break in 3.x. to some people's annoyance. We really really cannot please everyone ;-). -- Terry Jan Reedy From zooko at zooko.com Mon Dec 6 14:50:33 2010 From: zooko at zooko.com (Zooko O'Whielacronx) Date: Mon, 6 Dec 2010 11:50:33 -0800 Subject: announcing pyutil-1.8.0 Message-ID: Folks: pyutil is a collection of modules and functions that we've found useful over the years. Peter Westlake and Ravi Pinjala (who found pyutil through the Tahoe-LAFS project) contributed some documentation about what each module in pyutil does, and SimpleGeo (my employer) is using one small part of pyutil (the jsonutil [1] module) in an upcoming new product, so I packaged up version 1.8.0. The main differences from previous versions are better docs, a very simple declaration of permissive open source licensing [2], and several of the modules have been marked as deprecated. read me: http://tahoe-lafs.org/trac/pyutil/browser/trunk/README.rst download: http://pypi.python.org/pypi/pyutil Regards, Zooko [1] http://tahoe-lafs.org/trac/pyutil/browser/trunk/pyutil/jsonutil.py [2] http://tahoe-lafs.org/trac/pyutil/browser/trunk/COPYING.SPL.txt From usenot at geekmail.INVALID Mon Dec 6 15:17:21 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Mon, 6 Dec 2010 15:17:21 -0500 Subject: PEP8 compliance and exception messages ? References: <63cab97f-4e46-4c30-83ce-dc531a900d40@u25g2000pra.googlegroups.com> <20101206002249.2d804250@wldmr> Message-ID: <20101206151721.4446d722@wldmr> On Mon, 6 Dec 2010 00:22:49 -0500 Andreas Waldenburger wrote: > On Sun, 5 Dec 2010 19:52:54 -0800 Chris Rebert > wrote: > > > On Sun, Dec 5, 2010 at 7:40 PM, shearichard > > wrote: > > > Hi - PEP8 says lines should not exceed 79 characters in length > > > ( http://www.python.org/dev/peps/pep-0008/ ). > > > > > > So if you've got some code that looks like this : > > > > > > raise fooMod.fooException("Some message which is quite long") > > > > > > ... and assuming a certain amount of indenting you're going to > > > break that guideline. > > > > > > [etc.] > > > > [...] > > Alternatively, you could disregard PEP 8 on this point on the > > grounds that the 79/80 characters per line limit is outdated. > > > Maybe, but it's not outmoded. > As a more useful (I hope) reply, my opinion in this case is to just make the line a little longer. Even if you can't read it all at once, it is pretty obvious what comes next: The rest of the error message. There is no additional functionality hidden there, and you don't need to see it all at once to grasp the meaning of the code. /W -- To reach me via email, replace INVALID with the country code of my home country. But if you spam me, I'll be one sour Kraut. From nagle at animats.com Mon Dec 6 15:53:47 2010 From: nagle at animats.com (John Nagle) Date: Mon, 06 Dec 2010 12:53:47 -0800 Subject: Exception handling in Python 3.x In-Reply-To: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cfd4d5a$0$1662$742ec2ed@news.sonic.net> On 12/3/2010 5:04 AM, Steven D'Aprano wrote: > Consider the following common exception handling idiom: > > def func(iterable): > it = iter(iterable) > try: > x = next(it) > except StopIteration: > raise ValueError("can't process empty iterable") > print(x) > > The intention is: > > * detect an empty iterator by catching StopIteration; > * if the iterator is empty, raise a ValueError; > * otherwise process the iterator. > > Note that StopIteration is an internal detail of no relevance whatsoever > to the caller. Expose this is unnecessary at best and confusing at worst. Right. You're not entitled to assume that StopIteration is how a generator exits. That's a CPyton thing; generators were a retrofit, and that's how they were hacked in. Other implementations may do generators differently. John Nagle From mdw at distorted.org.uk Mon Dec 6 15:58:13 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Mon, 06 Dec 2010 20:58:13 +0000 Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> <7x39qbfhd8.fsf@ruckus.brouhaha.com> Message-ID: <87lj42liu2.fsf.mdw@metalzone.distorted.org.uk> Paul Rubin writes: > You know, I've heard the story from language designers several times > over, that they tried putting resumable exceptions into their languages > and it turned out to be a big mess, so they went to termination > exceptions that fixed the issue. That seems very surprising to me. > Are there any languages out there with resumable exceptions? Common Lisp and Smalltalk spring to mind. It's fairly straightforward to write one in Scheme. (Actually, implementing the Common Lisp one in terms of fluids, closures and blocks isn't especially difficult.) > Escaping to a debugger doesn't really count as that. Indeed not. > I guess one way to do it would be call a coroutine to handle the > exception, and either continue or unwind after the continue returns, > but doing it in a single-threaded system just seems full of hazards. It seems pretty straightforward to me. Handlers are simply closures; the registered handlers are part of the prevailing dynamic context. When an exception occurs, you invoke the handlers, most-recently registered first. A handler that returns normally can be thought of as `declining' to handle the exception; a handler that explicitly transfers control elsewhere can be thought of as having handled it. To make this work, all you need is: * a fluid list (i.e., one which is part of the dynamic context) of handlers, which you can build in pure Python if you try hard enough (see below); * closures to represent handlers, which Python has already, and; * a nonlocal transfer mechanism, and a mechanism like try ... finally to allow functions to clean up if they're unwound. We can actually come up with a nonlocal transfer if we try, by abusing exceptions. [The code in this article is lightly tested, but probably contains stupid bugs. Be careful.] class block (object): """ Context manager for escapable blocks. Write with block() as escape: ... Invoking the `escape' function causes the context body to exit immediately. Invoking the `escape' function outside of the block's dynamic context raises a ValueError. """ def __init__(me): me._tag = None def _escape(me, value = None): if me._tag is None: raise ValueError, 'defunct block' me.result = value raise me._tag def __enter__(me, value = None): if me._tag: raise ValueError, 'block already active' me._tag = type('block tag', (BaseException,), {}) me.result = value return me._escape def __exit__(me, ty, val, tb): tag, me._tag = me._tag, None return ty is tag This is somewhat brittle, since some intervening context might capture the custom exception we're using, but I don't think we can do significantly better. Implementing fluids badly is easy. Effectively what we'd do to bind a fluid dynamically is try: old, fluid = fluid, new ... finally: fluid = old but this is visible in other threads. The following will do the job in a multithreaded environment. import threading as T import weakref as W class FluidBinding (object): """Context object for fluid bindings.""" def __init__(me, fluid, value): me.fluid = fluid me.value = value def __enter__(me): me.fluid._bind(me.value) def __exit__(me, ty, val, tb): me.fluid._unbind() class Fluid (object): """ Represents a fluid variable, i.e., one whose binding respects the dynamic context rather than the lexical context. Read and write the Fluid through the `value' property. The global value is shared by all threads. To dynamically bind the fluid, use the context manager `binding': with myfluid.binding(NEWVALUE): ... The binding is visible in functions called MAP within the context body, but not in other threads. """ _TLS = T.local() _UNBOUND = ['fluid unbound'] _OMIT = ['fluid omitted'] def __init__(me, value = _UNBOUND): """ Iinitialze a fluid, optionally setting the global value. """ me._value = value @property def value(me): """ Return the current value of the fluid. Raises AttributeError if the fluid is currently unbound. """ try: value, _ = me._TLS.map[me] except (AttributeError, KeyError): value = me._value if value == me._UNBOUND: raise AttributeError, 'unbound fluid' return value @value.setter def value(me, value): try: map = me._TLS.map _, stack = map[me] map[me] = value, stack except (AttributeError, KeyError): me._value = value @value.deleter def value(me): me.value = me._UNBOUND def binding(me, value = _OMIT, unbound = False): """ Bind the fluid dynamically. If UNBOUND is true then make the fluid be `unbound', i.e., not associated with a value. Otherwise, if VALUE is unset, then preserve the current value. Otherwise, set it to VALUE. The fluid can be modified and deleted. This will not affect the value outside of the dynamic extent of the context (e.g., in other threads, or when the context is unwound). """ if unbound: value = me._UNBOUND elif value == me._OMIT: value = me.value return _FluidBinding(me, value) def _bind(me, value): try: map = me._TLS.map except AttributeError: me._TLS.map = map = W.WeakKeyDictionary() try: old, stack = map[me] stack.append(old) map[me] = value, stack except KeyError: map[me] = value, [] def _unbind(me): map = me._TLS.map _, stack = map[me] if stack: map[me] = stack.pop(), stack else: del map[me] Now we can say with fluid.binding(new): ... and all is well. So, how do we piece all of this together to make a resumable exception system? We're going to need to keep a list of handlers. We're going to be adding and removing stuff a lot; and we want to make use of the fluid mechanism we've already built, which will restore old values automatically when we leave a dynamic context. So maintaining a linked list seems like a good idea. The nodes in the list will look somewhat like this. class Link (object): def __init__(me, item, next): me.item = item me.next = next Our handlers are going to be simple functions which take exception objects as arguments. A more advanced handler might filter exceptions based on their classes. That's not especially difficult to do badly, but it's fiddly to do well and it doesn't shed much light on the overall mechanism, so I'll omit that complication. We'll want a fluid for the handler list. HANDLERS = Fluid(None) Now we want to run a chunk of code with a handler attached. This seems like another good use for a context manager. class handler (object): def __init__(me, func): me._func = func def __enter__(me): me._bind = FluidBinding(HANDLERS, Link(me.func, HANDLERS.value) me._bind.__enter__() def __exit__(me, ty, val, tb): return me._bind.__exit__(ty, val, tb) (Context managers don't compose very nicely. It'd be prettier with the contextmanager decorator.) Let's say that we `signal' resumable exceptions rather than `raising' them. How do we do that? def signal(exc): with HANDLERS.binding(): while HANDLERS.value: h = HANDLERS.value HANDLERS.value = h.next h.item(exc) Yes, if all of the handlers decline, we just return. This is Bad for errors, but good for other kinds of situations, so `signal' is a convenient substrate to build on. def error(exc): signal(exc) raise RuntimeError, 'unhandled resumable exception' def warning(exc): signal(exc) ## Crank up python's usual warning stuff Note also that handlers are invoked in a dynamic environment which doesn't include them or any handlers added since. Obviously they can install their own handlers just fine. Cool. Now how about recovery? This is where nonlocal transfer comes in. If a handler wants to take responsibility for the exception, it has to make a nonlocal transfer. Where should it go? Let's maintain a table of restart points. Again, it'll be a linked list. RESTARTS = Fluid(None) class restart (block): def __init__(me, name): me.name = name super(restart, me).__init__(me) def invoke(me, value = None): me._escape(value) def __enter__(me): me._bind = FluidBinding(RESTARTS, Link(me, RESTARTS.value)) me._bind.__enter__() return super(restart, me).__enter__() def __exit__(me, ty, val, tb): ## Poor man's PROG1. try: return super(restart, me).__exit__(ty, val, tb) finally: me._bind.__exit__(ty, val, tb) def find_restart(name): r = RESTARTS.value while r: if r.item.name == name: return r.item r = r.next return None Using all of this is rather cumbersome, and Python doesn't allow syntactic abstraction so there isn't really much we can do to sweeten the pill. But I ought to provide an example of this machinery in action. def toy(x, y): r = restart('use-value') with r: if y == 0: error(ZeroDivisionError()) r.result = x/y return r.result def example(): def zd(exc): if not isinstance(exc, ZeroDivisionError): return r = find_restart('use-value') if not r: return r.invoke(42) print toy(5, 2) with handler(zd): print toy(1, 0) Does any of that help? -- [mdw] From no.email at nospam.invalid Mon Dec 6 16:13:40 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 06 Dec 2010 13:13:40 -0800 Subject: Exception handling in Python 3.x References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7xmxoi8v0b.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > Apart from this horrible idiom: > > def func(iterable): > it = iter(iterable) > failed = False > try: > x = next(it) > except StopIteration: > failed = True > if failed: > raise ValueError("can't process empty iterable") > print(x) > > > or similar, is there really no way to avoid these chained exceptions? Seems like yet another example of people doing messy things with exceptions that can easily be done with iterators and itertools: from itertools import islice def func(iterable): xs = list(islice(iter(iterable), 1)) if len(xs) == 0: raise ValueError(...) print xs[0] It's really unfortunate, though, that Python 3 didn't offer a way to peek at the next element of an iterable and test emptiness directly. From mdw at distorted.org.uk Mon Dec 6 16:23:06 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Mon, 06 Dec 2010 21:23:06 +0000 Subject: Resumable exceptions bad: References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> <7x39qbfhd8.fsf@ruckus.brouhaha.com> <4cfd3822$0$1629$742ec2ed@news.sonic.net> Message-ID: <87hbeqlhol.fsf.mdw@metalzone.distorted.org.uk> John Nagle writes: > Resumable exceptions were a popular idea in the early days of > programming. LISP, PL/I, and early COBOL had constructs which could > be considered resumable exceptions. They didn't work out well, > because the exception handler gets control in an ambiguous situation, > perhaps in the middle of an expression. Changing the state of the > execution, then returning, can leave the program in an invalid state. Right, but that's not the important really important trick. The important bit is separating out the `how should I fix this?' logic from the point where execution should resume. There's no good reason why the former should have to come from a dynamic context smaller than the latter: it's just an unnecessary conflation. [Snip stuff about signals. I agree that Unix signals are a disaster.] > So that's why resumable exceptions are a bad idea. That's why a primitive resumable exception system, used naively, is a bad idea. Now look at the good ones. -- [mdw] From mdw at distorted.org.uk Mon Dec 6 16:31:09 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Mon, 06 Dec 2010 21:31:09 +0000 Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> <2010120609161055524-tomfsessile@gmailcom> Message-ID: <87d3pelhb6.fsf.mdw@metalzone.distorted.org.uk> Terry Reedy writes: > And indeed, code like this that has not been updated does break in > 3.x. to some people's annoyance. We really really cannot please > everyone ;-). The problem is that there are too many useful properties that one might expect from comparison operators. For example, it's frequently nice to have a total ordering on all objects. For real numbers, it's nice that the ordering obey the usual ordered-field axioms; but the complex numbers don't have an ordering compatible with the field operators, and imposing a default ordering (e.g., degree-lexicographic) is probably asking for trouble. I agree that the Python 3 behaviour is an improvement, by the way. -- [mdw] From georg at python.org Mon Dec 6 16:46:48 2010 From: georg at python.org (Georg Brandl) Date: Mon, 06 Dec 2010 22:46:48 +0100 Subject: [RELEASED] Python 3.2 beta 1 Message-ID: <4CFD59C8.4070006@python.org> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On behalf of the Python development team, I'm happy to announce the first of two beta preview releases of Python 3.2. Python 3.2 is a continuation of the efforts to improve and stabilize the Python 3.x line. Since the final release of Python 2.7, the 2.x line will only receive bugfixes, and new features are developed for 3.x only. Since PEP 3003, the Moratorium on Language Changes, is in effect, there are no changes in Python's syntax and built-in types in Python 3.2. Development efforts concentrated on the standard library and support for porting code to Python 3. Highlights are: * numerous improvements to the unittest module * PEP 3147, support for .pyc repository directories * PEP 3149, support for version tagged dynamic libraries * PEP 3148, a new futures library for concurrent programming * PEP 384, a stable ABI for extension modules * PEP 391, dictionary-based logging configuration * an overhauled GIL implementation that reduces contention * an extended email package that handles bytes messages * countless fixes regarding bytes/string issues; among them full support for a bytes environment (filenames, environment variables) * many consistency and behavior fixes for numeric operations * a sysconfig module to access configuration information * a pure-Python implementation of the datetime module * additions to the shutil module, among them archive file support * improvements to pdb, the Python debugger For a more extensive list of changes in 3.2, see http://docs.python.org/3.2/whatsnew/3.2.html To download Python 3.2 visit: http://www.python.org/download/releases/3.2/ Please consider trying Python 3.2 with your code and reporting any bugs you may notice to: http://bugs.python.org/ Enjoy! - -- Georg Brandl, Release Manager georg at python.org (on behalf of the entire python-dev team and 3.2's contributors) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.16 (GNU/Linux) iEYEARECAAYFAkz9WcgACgkQN9GcIYhpnLBRYwCeMmH1GMmKOx9fVk8a/F0/TOzj Vp0AoIHYBNcxV/U0AXIwMGWFHi1bAB+a =KBam -----END PGP SIGNATURE----- From mdw at distorted.org.uk Mon Dec 6 17:24:10 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Mon, 06 Dec 2010 22:24:10 +0000 Subject: Exception handling in Python 3.x References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> <4cfd4d5a$0$1662$742ec2ed@news.sonic.net> Message-ID: <878w02leut.fsf.mdw@metalzone.distorted.org.uk> John Nagle writes: > Right. You're not entitled to assume that StopIteration is how a > generator exits. That's a CPyton thing; generators were a retrofit, > and that's how they were hacked in. Other implementations may do > generators differently. This is simply wrong. The StopIteration exception is a clear part of the generator protocol as described in 5.2.8 of the language reference; the language reference also refers to 3.5 of the library reference, which describes the iterator protocol (note, not the generator implementation -- all iterators work the same way), and explicitly mentions StopIteration as part of the protocol. -- [mdw] From chris at simplistix.co.uk Mon Dec 6 17:38:48 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 06 Dec 2010 22:38:48 +0000 Subject: TDD in python In-Reply-To: References: <0906c010-709d-41d9-8b29-2f42afb87f94@32g2000yqz.googlegroups.com> <58fe3680-21f5-42f8-9341-e069cbb88975@r19g2000prm.googlegroups.com> Message-ID: <4CFD65F8.7020908@simplistix.co.uk> On 30/11/2010 13:33, Roy Smith wrote: > In article > <58fe3680-21f5-42f8-9341-e069cbb88975 at r19g2000prm.googlegroups.com>, > rustom wrote: > >> Looking around I found this: >> http://bytes.com/topic/python/answers/43330-unittest-vs-py-test >> where Raymond Hettinger no less says quite unequivocally that he >> prefers test.py to builtin unittest >> because it is not so heavy-weight >> >> Is this the general consensus nowadays among pythonistas? >> [Note I tend to agree but Ive no experience so asking] > > Both frameworks have their fans; I doubt you'll find any consensus. > > Pick one, learn it, and use it. What's important is that you write > tests, write lots of tests, and write good tests. Which framework you > use is a detail. For a great mailing lists that covers all of these types of issues, see here: http://lists.idyll.org/listinfo/testing-in-python cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From pavlovevidence at gmail.com Mon Dec 6 17:42:15 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 6 Dec 2010 14:42:15 -0800 (PST) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> <7x39qbfhd8.fsf@ruckus.brouhaha.com> <87lj42liu2.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <7491b308-0e41-416b-84e9-1ed5ff3408be@n32g2000pre.googlegroups.com> On Dec 6, 12:58?pm, m... at distorted.org.uk (Mark Wooding) wrote: > Paul Rubin writes: > > You know, I've heard the story from language designers several times > > over, that they tried putting resumable exceptions into their languages > > and it turned out to be a big mess, so they went to termination > > exceptions that fixed the issue. > > That seems very surprising to me. > > > Are there any languages out there with resumable exceptions? > > Common Lisp and Smalltalk spring to mind. ?It's fairly straightforward > to write one in Scheme. ?(Actually, implementing the Common Lisp one in > terms of fluids, closures and blocks isn't especially difficult.) > > > Escaping to a debugger doesn't really count as that. > > Indeed not. > > > I guess one way to do it would be call a coroutine to handle the > > exception, and either continue or unwind after the continue returns, > > but doing it in a single-threaded system just seems full of hazards. > > It seems pretty straightforward to me. ?Handlers are simply closures; > the registered handlers are part of the prevailing dynamic context. > When an exception occurs, you invoke the handlers, most-recently > registered first. ?A handler that returns normally can be thought of as > `declining' to handle the exception; a handler that explicitly transfers > control elsewhere can be thought of as having handled it. > > To make this work, all you need is: > > ? * a fluid list (i.e., one which is part of the dynamic context) of > ? ? handlers, which you can build in pure Python if you try hard enough > ? ? (see below); > > ? * closures to represent handlers, which Python has already, and; > > ? * a nonlocal transfer mechanism, and a mechanism like try ... finally > ? ? to allow functions to clean up if they're unwound. > > We can actually come up with a nonlocal transfer if we try, by abusing > exceptions. > > [The code in this article is lightly tested, but probably contains > stupid bugs. ?Be careful.] > > ? ? ? ? class block (object): > ? ? ? ? ? """ > ? ? ? ? ? Context manager for escapable blocks. > > ? ? ? ? ? Write > > ? ? ? ? ? ? ? ? with block() as escape: > ? ? ? ? ? ? ? ? ? ... > > ? ? ? ? ? Invoking the `escape' function causes the context body to exit > ? ? ? ? ? immediately. ?Invoking the `escape' function outside of the > ? ? ? ? ? block's dynamic context raises a ValueError. > ? ? ? ? ? """ > ? ? ? ? ? def __init__(me): > ? ? ? ? ? ? me._tag = None > ? ? ? ? ? def _escape(me, value = None): > ? ? ? ? ? ? if me._tag is None: > ? ? ? ? ? ? ? raise ValueError, 'defunct block' > ? ? ? ? ? ? me.result = value > ? ? ? ? ? ? raise me._tag > ? ? ? ? ? def __enter__(me, value = None): > ? ? ? ? ? ? if me._tag: > ? ? ? ? ? ? ? raise ValueError, 'block already active' > ? ? ? ? ? ? me._tag = type('block tag', (BaseException,), {}) > ? ? ? ? ? ? me.result = value > ? ? ? ? ? ? return me._escape > ? ? ? ? ? def __exit__(me, ty, val, tb): > ? ? ? ? ? ? tag, me._tag = me._tag, None > ? ? ? ? ? ? return ty is tag > > This is somewhat brittle, since some intervening context might capture > the custom exception we're using, but I don't think we can do > significantly better. > > Implementing fluids badly is easy. ?Effectively what we'd do to bind a > fluid dynamically is > > ? ? ? ? try: > ? ? ? ? ? old, fluid = fluid, new > ? ? ? ? ? ... > ? ? ? ? finally: > ? ? ? ? ? fluid = old > > but this is visible in other threads. ?The following will do the job in > a multithreaded environment. > > ? ? ? ? import threading as T > ? ? ? ? import weakref as W > > ? ? ? ? class FluidBinding (object): > ? ? ? ? ? """Context object for fluid bindings.""" > ? ? ? ? ? def __init__(me, fluid, value): > ? ? ? ? ? ? me.fluid = fluid > ? ? ? ? ? ? me.value = value > ? ? ? ? ? def __enter__(me): > ? ? ? ? ? ? me.fluid._bind(me.value) > ? ? ? ? ? def __exit__(me, ty, val, tb): > ? ? ? ? ? ? me.fluid._unbind() > > ? ? ? ? class Fluid (object): > ? ? ? ? ? """ > ? ? ? ? ? Represents a fluid variable, i.e., one whose binding respects > ? ? ? ? ? the dynamic context rather than the lexical context. > > ? ? ? ? ? Read and write the Fluid through the `value' property. > > ? ? ? ? ? The global value is shared by all threads. ?To dynamically > ? ? ? ? ? bind the fluid, use the context manager `binding': > > ? ? ? ? ? ? ? ? ? with myfluid.binding(NEWVALUE): > ? ? ? ? ? ? ? ? ? ? ... > > ? ? ? ? ? The binding is visible in functions called MAP within the > ? ? ? ? ? context body, but not in other threads. > ? ? ? ? ? """ > > ? ? ? ? ? _TLS = T.local() > ? ? ? ? ? _UNBOUND = ['fluid unbound'] > ? ? ? ? ? _OMIT = ['fluid omitted'] > > ? ? ? ? ? def __init__(me, value = _UNBOUND): > ? ? ? ? ? ? """ > ? ? ? ? ? ? Iinitialze a fluid, optionally setting the global value. > ? ? ? ? ? ? """ > ? ? ? ? ? ? me._value = value > > ? ? ? ? ? @property > ? ? ? ? ? def value(me): > ? ? ? ? ? ? """ > ? ? ? ? ? ? Return the current value of the fluid. > > ? ? ? ? ? ? Raises AttributeError if the fluid is currently unbound. > ? ? ? ? ? ? """ > ? ? ? ? ? ? try: > ? ? ? ? ? ? ? value, _ = me._TLS.map[me] > ? ? ? ? ? ? except (AttributeError, KeyError): > ? ? ? ? ? ? ? value = me._value > ? ? ? ? ? ? if value == me._UNBOUND: > ? ? ? ? ? ? ? raise AttributeError, 'unbound fluid' > ? ? ? ? ? ? return value > ? ? ? ? ? @value.setter > ? ? ? ? ? def value(me, value): > ? ? ? ? ? ? try: > ? ? ? ? ? ? ? map = me._TLS.map > ? ? ? ? ? ? ? _, stack = map[me] > ? ? ? ? ? ? ? map[me] = value, stack > ? ? ? ? ? ? except (AttributeError, KeyError): > ? ? ? ? ? ? ? me._value = value > ? ? ? ? ? @value.deleter > ? ? ? ? ? def value(me): > ? ? ? ? ? ? me.value = me._UNBOUND > > ? ? ? ? ? def binding(me, value = _OMIT, unbound = False): > ? ? ? ? ? ? """ > ? ? ? ? ? ? Bind the fluid dynamically. > > ? ? ? ? ? ? If UNBOUND is true then make the fluid be `unbound', i.e., > ? ? ? ? ? ? not associated with a value. ?Otherwise, if VALUE is unset, > ? ? ? ? ? ? then preserve the current value. ?Otherwise, set it to > ? ? ? ? ? ? VALUE. > > ? ? ? ? ? ? The fluid can be modified and deleted. ?This will not affect > ? ? ? ? ? ? the value outside of the dynamic extent of the context > ? ? ? ? ? ? (e.g., in other threads, or when the context is unwound). > ? ? ? ? ? ? """ > ? ? ? ? ? ? if unbound: > ? ? ? ? ? ? ? value = me._UNBOUND > ? ? ? ? ? ? elif value == me._OMIT: > ? ? ? ? ? ? ? value = me.value > ? ? ? ? ? ? return _FluidBinding(me, value) > > ? ? ? ? ? def _bind(me, value): > ? ? ? ? ? ? try: > ? ? ? ? ? ? ? map = me._TLS.map > ? ? ? ? ? ? except AttributeError: > ? ? ? ? ? ? ? me._TLS.map = map = W.WeakKeyDictionary() > ? ? ? ? ? ? try: > ? ? ? ? ? ? ? old, stack = map[me] > ? ? ? ? ? ? ? stack.append(old) > ? ? ? ? ? ? ? map[me] = value, stack > ? ? ? ? ? ? except KeyError: > ? ? ? ? ? ? ? map[me] = value, [] > > ? ? ? ? ? def _unbind(me): > ? ? ? ? ? ? map = me._TLS.map > ? ? ? ? ? ? _, stack = map[me] > ? ? ? ? ? ? if stack: > ? ? ? ? ? ? ? map[me] = stack.pop(), stack > ? ? ? ? ? ? else: > ? ? ? ? ? ? ? del map[me] > > Now we can say > > ? ? ? ? with fluid.binding(new): > ? ? ? ? ? ... > > and all is well. > > So, how do we piece all of this together to make a resumable exception > system? > > We're going to need to keep a list of handlers. ?We're going to be > adding and removing stuff a lot; and we want to make use of the fluid > mechanism we've already built, which will restore old values > automatically when we leave a dynamic context. ?So maintaining a linked > list seems like a good idea. ?The nodes in the list will look somewhat > like this. > > ? ? ? ? class Link (object): > ? ? ? ? ? def __init__(me, item, next): > ? ? ? ? ? ? me.item = item > ? ? ? ? ? ? me.next = next > > Our handlers are going to be simple functions which take exception > objects as arguments. ?A more advanced handler might filter exceptions > based on their classes. ?That's not especially difficult to do badly, > but it's fiddly to do well and it doesn't shed much light on the overall > mechanism, so I'll omit that complication. > > We'll want a fluid for the handler list. > > ? ? ? ? HANDLERS = Fluid(None) > > Now we want to run a chunk of code with a handler attached. ?This seems > like another good use for a context manager. > > ? ? ? ? class handler (object): > ? ? ? ? ? def __init__(me, func): > ? ? ? ? ? ? me._func = func > ? ? ? ? ? def __enter__(me): > ? ? ? ? ? ? me._bind = FluidBinding(HANDLERS, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Link(me.func, HANDLERS.value) > ? ? ? ? ? ? me._bind.__enter__() > ? ? ? ? ? def __exit__(me, ty, val, tb): > ? ? ? ? ? ? return me._bind.__exit__(ty, val, tb) > > (Context managers don't compose very nicely. ?It'd be prettier with the > contextmanager decorator.) > > Let's say that we `signal' resumable exceptions rather than `raising' > them. ?How do we do that? > > ? ? ? ? def signal(exc): > ? ? ? ? ? with HANDLERS.binding(): > ? ? ? ? ? ? while HANDLERS.value: > ? ? ? ? ? ? ? h = HANDLERS.value > ? ? ? ? ? ? ? HANDLERS.value = h.next > ? ? ? ? ? ? ? h.item(exc) > > Yes, if all of the handlers decline, we just return. ?This is Bad for > errors, but good for other kinds of situations, so `signal' is a > convenient substrate to build on. > > ? ? ? ? def error(exc): > ? ? ? ? ? signal(exc) > ? ? ? ? ? raise RuntimeError, 'unhandled resumable exception' > > ? ? ? ? def warning(exc): > ? ? ? ? ? signal(exc) > ? ? ? ? ? ## Crank up python's usual warning stuff > > Note also that handlers are invoked in a dynamic environment which > doesn't include them or any handlers added since. ?Obviously they can > install their own handlers just fine. > > Cool. ?Now how about recovery? ?This is where nonlocal transfer comes > in. ?If a handler wants to take responsibility for the exception, it has > to make a nonlocal transfer. ?Where should it go? ?Let's maintain a > table of restart points. ?Again, it'll be a linked list. > > ? ? ? ? RESTARTS = Fluid(None) > > ? ? ? ? class restart (block): > ? ? ? ? ? def __init__(me, name): > ? ? ? ? ? ? me.name = name > ? ? ? ? ? ? super(restart, me).__init__(me) > ? ? ? ? ? def invoke(me, value = None): > ? ? ? ? ? ? me._escape(value) > ? ? ? ? ? def __enter__(me): > ? ? ? ? ? ? me._bind = FluidBinding(RESTARTS, Link(me, RESTARTS.value)) > ? ? ? ? ? ? me._bind.__enter__() > ? ? ? ? ? ? return super(restart, me).__enter__() > ? ? ? ? ? def __exit__(me, ty, val, tb): > ? ? ? ? ? ? ## Poor man's PROG1. > ? ? ? ? ? ? try: > ? ? ? ? ? ? ? return super(restart, me).__exit__(ty, val, tb) > ? ? ? ? ? ? finally: > ? ? ? ? ? ? ? me._bind.__exit__(ty, val, tb) > > ? ? ? ? def find_restart(name): > ? ? ? ? ? r = RESTARTS.value > ? ? ? ? ? while r: > ? ? ? ? ? ? if r.item.name == name: > ? ? ? ? ? ? ? return r.item > ? ? ? ? ? ? r = r.next > ? ? ? ? ? return None > > Using all of this is rather cumbersome, and Python doesn't allow > syntactic abstraction so there isn't really much we can do to sweeten > the pill. ?But I ought to provide an example of this machinery in > action. > > ? ? ? ? def toy(x, y): > ? ? ? ? ? r = restart('use-value') > ? ? ? ? ? with r: > ? ? ? ? ? ? if y == 0: > ? ? ? ? ? ? ? error(ZeroDivisionError()) > ? ? ? ? ? ? r.result = x/y > ? ? ? ? ? return r.result > > ? ? ? ? def example(): > ? ? ? ? ? def zd(exc): > ? ? ? ? ? ? if not isinstance(exc, ZeroDivisionError): > ? ? ? ? ? ? ? return > ? ? ? ? ? ? r = find_restart('use-value') > ? ? ? ? ? ? if not r: return > ? ? ? ? ? ? r.invoke(42) > ? ? ? ? ? print toy(5, 2) > ? ? ? ? ? with handler(zd): > ? ? ? ? ? ? print toy(1, 0) > > Does any of that help? You could do that. Or, you could just put your try...finally inside a loop. Carl Banks From pavlovevidence at gmail.com Mon Dec 6 17:43:16 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 6 Dec 2010 14:43:16 -0800 (PST) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> <7x39qbfhd8.fsf@ruckus.brouhaha.com> <87lj42liu2.fsf.mdw@metalzone.distorted.org.uk> <7491b308-0e41-416b-84e9-1ed5ff3408be@n32g2000pre.googlegroups.com> Message-ID: <67307449-5ab0-4368-9268-811b712a1a8d@a28g2000prb.googlegroups.com> On Dec 6, 2:42?pm, Carl Banks wrote: > Or, you could just put your try...finally inside a loop. er, try...except Carl Banks From chris at simplistix.co.uk Mon Dec 6 17:45:09 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 06 Dec 2010 22:45:09 +0000 Subject: Python assignments In-Reply-To: References: Message-ID: <4CFD6775.3060701@simplistix.co.uk> Try here: http://www.python.org/community/jobs/ Chris On 03/12/2010 13:50, Sverker Nilsson wrote: > Dear friends, > > This is Sverker from Sweden. You probably know me better as the guy > who made Guppy/Heapy: http://guppy-pe.sf.net > > I am currently in the process of preparing version 0.1.10 with support > for Python 2.7. I will let you know when it is updated. > > For those who don?t know, I work as a consultant and I am looking for > new assignments and I really wish to work with Heapy/Python instead of > regular programming in eg Java or C++. > > Therefore I was wondering if any of you know any companies in the > States or anywhere else that need my services. > > Further information about who I am and what I can do you can find on > my website: > > http://sncs.se > > I appreciate all advice and information you can provide me with. > > So long my friends, > > Sverker -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From chris at simplistix.co.uk Mon Dec 6 17:48:05 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 06 Dec 2010 22:48:05 +0000 Subject: A web site using Python In-Reply-To: <4CFA4305.10004@it.uu.se> References: <4CFA4305.10004@it.uu.se> Message-ID: <4CFD6825.9020200@simplistix.co.uk> On 04/12/2010 13:32, Virgil Stokes wrote: > *How, armed with Python 2.6 (or 2.7) and all of the Python packages > available, > should I attack the problem of getting this web site up and running on a > Windows > platform?* 1. Pick a web framework, I'd suggest looking at: Django (http://www.djangoproject.com/) Pyramid (http://docs.pylonshq.com/pyramid/dev/) 2. Use it to develop your site. cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From mdw at distorted.org.uk Mon Dec 6 18:03:44 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Mon, 06 Dec 2010 23:03:44 +0000 Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> <7x39qbfhd8.fsf@ruckus.brouhaha.com> <87lj42liu2.fsf.mdw@metalzone.distorted.org.uk> <7491b308-0e41-416b-84e9-1ed5ff3408be@n32g2000pre.googlegroups.com> Message-ID: <874oaqld0v.fsf.mdw@metalzone.distorted.org.uk> Carl Banks writes: > On Dec 6, 12:58?pm, m... at distorted.org.uk (Mark Wooding) wrote: > > ? ? ? ? def toy(x, y): > > ? ? ? ? ? r = restart('use-value') > > ? ? ? ? ? with r: > > ? ? ? ? ? ? if y == 0: > > ? ? ? ? ? ? ? error(ZeroDivisionError()) > > ? ? ? ? ? ? r.result = x/y > > ? ? ? ? ? return r.result > > > > ? ? ? ? def example(): > > ? ? ? ? ? def zd(exc): > > ? ? ? ? ? ? if not isinstance(exc, ZeroDivisionError): > > ? ? ? ? ? ? ? return > > ? ? ? ? ? ? r = find_restart('use-value') > > ? ? ? ? ? ? if not r: return > > ? ? ? ? ? ? r.invoke(42) > > ? ? ? ? ? print toy(5, 2) > > ? ? ? ? ? with handler(zd): > > ? ? ? ? ? ? print toy(1, 0) > > You could do that. > > Or, you could just put your try...finally inside a loop. [You correct `finally' to `except' in a follow-up.] I think you've missed the point almost entirely. Any code called from within the `with handler' context will (unless overridden) cause a call `toy(x, 0)' to return 42. Even if the `with handler' block calls other functions and so on. Note also that the expression of this is dynamically further from where the error is signalled than the resume point (which is within the same function). You can't do this with `try' ... `except'. Which was, of course, the point. -- [mdw] From shearern at gmail.com Mon Dec 6 18:11:44 2010 From: shearern at gmail.com (Nate) Date: Mon, 6 Dec 2010 15:11:44 -0800 (PST) Subject: Task Engine Framework? Message-ID: Hello, I'm in the process of developing a task engine / workflow module for my Python application and I'm wondering if anyone knows of existing code that could be used or adapted. Since I know that's far too generic a question, let me share my goals: 1) Support long running operations (think backing up millions of files) where: - The operation can be paused (application closed) and the operation resumed later. - Individual tasks can be chained, run in parallel, or looped over (the workflow part) 2) Would like to graph each defined operation (task A starts task B with parameters... ) for documenting algorithms in Software Design Document 3) Each individual task in the operation would a self-contained class. I'd imagine implementing its action by defining a doTask() method. Hopefully that's clear. I just feel like someone must have already solved this elegantly. I greatly enjoy Python and I look forward to proving its use as a valuable language for a Masters student even though everyone thinks I should use C# :-). Thanks! -Nate Masters Student at Eastern Washington University From bthate at gmail.com Mon Dec 6 18:29:08 2010 From: bthate at gmail.com (Bart Thate) Date: Mon, 6 Dec 2010 15:29:08 -0800 (PST) Subject: JSONBOT 0.5 RELEASED Message-ID: <251c8455-9693-46fa-a28f-15c315018e01@q12g2000yqe.googlegroups.com> Hello world ;] I'm back with another release of JSONBOT, this time it is version 0.5 so we are half way through making this a 1.0 release. Lot of changes to the core as well as other bug fixes, let me sum it up: * this version requires an upgrade of your 0.4 JSONBOT if you run already a JSONBOT see UPGRADE for more details on this. * code is adapted to use the Channel API, you need google_appengine version 1.4.0 for this. * website has gotten a brand new look and feel. * JSONBOT now uses ~/.jsonbot as its default datadir. * the RSS plugin was rewritten to work on any feed instead of only feed that support the pubDate token. * shell bots now log to ~/.jsonbot/botlogs by default, rotating the logs every day. * lots and lots of bug fixes. pointers: * source code: http://jsonbot.googlecode.com * web demo: http://jsonbot.appspot.com * jabber demo: jsonbot at appspot.com * documentation: http://jsonbot.appspot.com/docs * bugs: http://code.google.com/p/jsonbot/issues/list * twitter: http://twitter.com/#!jsonbot I consider JSONBOT to be of BETA quality now, i think it has become quite usable ;] Any feedback would be very much appreciated. As always ... HF ! Bart about JSONBOT: JSONBOT is a remote event-driven framework for building bots that talk JSON to each other over XMPP. This distribution provides bots built on this framework for console, IRC, XMPP for the shell and WWW and XMPP for the Google Application engine. JSONBOT is all of the following: * a shell console bot * a shell IRC bot * a shell XMPP bot * a Web bot running on Google Application Engine * a XMPP bot running on Google Application Engine * a Google Wave bot running op Google Application Engine * the XMPP bots are used to communicate between bots * plugin infrastructure to write your own functionality * event driven framework by the use of callbacks From stef.mientki at gmail.com Mon Dec 6 18:36:25 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 07 Dec 2010 00:36:25 +0100 Subject: A web site using Python In-Reply-To: <0014853d0112e94116049696d504@google.com> References: <0014853d0112e94116049696d504@google.com> Message-ID: <4CFD7379.8060804@gmail.com> On 04-12-2010 15:54, hidura at gmail.com wrote: > I am working on a tool that can create an application like that without write server code, but the > system is write in Python3.1 very interesting, could you give us some more information about the project for the OP: with web2py, your site could be up within an hour. cheers, Stef From steve+comp.lang.python at pearwood.info Mon Dec 6 19:17:11 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Dec 2010 00:17:11 GMT Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> Message-ID: <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> On Mon, 06 Dec 2010 08:59:12 -0800, TomF wrote: > I'm aggravated by this behavior in python: > > x = "4" > print x < 7 # prints False > I can't imagine why this design decision was made. You've never needed to deal with an heterogeneous list? data = ["Fred", "Barney", 2, 1, None] data.sort() Nevertheless, I agree that in hindsight, the ability to sort such lists is not as important as the consistency of comparisons. -- Steven From steve+comp.lang.python at pearwood.info Mon Dec 6 19:23:06 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Dec 2010 00:23:06 GMT Subject: Exception handling in Python 3.x References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> <7xmxoi8v0b.fsf@ruckus.brouhaha.com> Message-ID: <4cfd7e6a$0$29993$c3e8da3$5496439d@news.astraweb.com> On Mon, 06 Dec 2010 13:13:40 -0800, Paul Rubin wrote: > It's really unfortunate, though, that Python 3 didn't offer a way to > peek at the next element of an iterable and test emptiness directly. This idea of peekable iterables just won't die, despite the obvious flaws in the idea. There's no general way of telling whether or not a lazy sequence is done except to actually generate the next value, and caching that value is not appropriate for all such sequences since it could depend on factors which have changed between the call to peek and the call to next. If you want to implement a peek method in your own iterables, go right ahead. But you can't make arbitrary iterables peekable without making a significant class of them buggy. -- Steven From alice at gothcandy.com Mon Dec 6 19:42:27 2010 From: alice at gothcandy.com (=?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=) Date: Mon, 6 Dec 2010 16:42:27 -0800 Subject: A web site using Python References: <4CFA4305.10004@it.uu.se> <4CFD6825.9020200@simplistix.co.uk> Message-ID: > 1. Pick a web framework, I'd suggest looking at: > > Django (http://www.djangoproject.com/) > > Pyramid (http://docs.pylonshq.com/pyramid/dev/) I'm biased, but I can highly recommend WebCore (http://www.web-core.org/) as it more easily supports small to mid-sized applications and actively encourages the use of standard Python idioms. A reasonable example (though it was hurried) would be the codebase behind tsatimeline.org: https://github.com/GothAlice/TSA-Timeline The important files are application.py (controllers), model.py (data model), and the templates (views) folder. (The public folder is where CSS/JS/images go.) Similar to Stef's comment on web2py, development with WebCore (or web2py, or WebPy, or? basically any micro-framework) is extremely rapid. ? Alice. From python at mrabarnett.plus.com Mon Dec 6 19:48:30 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 07 Dec 2010 00:48:30 +0000 Subject: Exception handling in Python 3.x In-Reply-To: <4cfd7e6a$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> <7xmxoi8v0b.fsf@ruckus.brouhaha.com> <4cfd7e6a$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4CFD845E.90007@mrabarnett.plus.com> On 07/12/2010 00:23, Steven D'Aprano wrote: > On Mon, 06 Dec 2010 13:13:40 -0800, Paul Rubin wrote: > >> It's really unfortunate, though, that Python 3 didn't offer a way to >> peek at the next element of an iterable and test emptiness directly. > > This idea of peekable iterables just won't die, despite the obvious flaws > in the idea. > > There's no general way of telling whether or not a lazy sequence is done > except to actually generate the next value, and caching that value is not > appropriate for all such sequences since it could depend on factors which > have changed between the call to peek and the call to next. > > If you want to implement a peek method in your own iterables, go right > ahead. But you can't make arbitrary iterables peekable without making a > significant class of them buggy. > Perhaps Python could use Guido's time machine to check whether the sequence will yield another object in the future. :-) From hidura at gmail.com Mon Dec 6 19:57:55 2010 From: hidura at gmail.com (Hidura) Date: Mon, 6 Dec 2010 20:57:55 -0400 Subject: A web site using Python In-Reply-To: <4CFD7379.8060804@gmail.com> References: <0014853d0112e94116049696d504@google.com> <4CFD7379.8060804@gmail.com> Message-ID: KarinApp will allow you to create an application without writing code, eg: you want to insert the information of a person in the DB, with all the current framework you will write a code that takes the data, and after you will write the insert, and if you want to send a response you will have to write it too. KarinApp is a framework that comes with several libraries inside-all writes on Pythn- and like Python is extensible, so you can create a page and save it-KarinApp has a hosting service so you can create pages like in DW but highly appended to the standard of the W3C- and on the page you put a all the inputs with the form, and create a batute-that is the function on KarinApp- and design the model of the response, and with it you just call in some cases to a javascript function named 'catcher' that will collect the data and send it to the server. The server will run the batute-calling the libraries on KarinApp- and the result will be sent to the client as HTML element(s) and will be appended on the area that you want. If you need more detailed information, please let me know. On Mon, Dec 6, 2010 at 7:36 PM, Stef Mientki wrote: > On 04-12-2010 15:54, hidura at gmail.com wrote: > > I am working on a tool that can create an application like that without > write server code, but the > > system is write in Python3.1 > > very interesting, could you give us some more information about the project > > for the OP: > with web2py, your site could be up within an hour. > > cheers, > Stef > -- > http://mail.python.org/mailman/listinfo/python-list > -- Diego I. Hidalgo D. -------------- next part -------------- An HTML attachment was scrubbed... URL: From greno at verizon.net Mon Dec 6 20:17:29 2010 From: greno at verizon.net (Gerry Reno) Date: Mon, 06 Dec 2010 20:17:29 -0500 Subject: A web site using Python In-Reply-To: References: <4CFA4305.10004@it.uu.se> <4CFD6825.9020200@simplistix.co.uk> Message-ID: <4CFD8B29.3020006@verizon.net> If you have any need of a portable LAMP stack, I just finished writing some How-To's for getting Python, VirtualEnv and WSGI frameworks running with XAMPP: How-To: Add VirtualEnv and Pylons (WSGI framework) to XAMPP How-To: Add VirtualEnv and Django (WSGI framework) to XAMPP How-To: Add Python and mod_wsgi to XAMPP -Gerry On 12/06/2010 07:42 PM, Alice Bevan?McGregor wrote: >> 1. Pick a web framework, I'd suggest looking at: >> >> Django (http://www.djangoproject.com/) >> >> Pyramid (http://docs.pylonshq.com/pyramid/dev/) > > I'm biased, but I can highly recommend WebCore > (http://www.web-core.org/) as it more easily supports small to > mid-sized applications and actively encourages the use of standard > Python idioms. > > A reasonable example (though it was hurried) would be the codebase > behind tsatimeline.org: > > https://github.com/GothAlice/TSA-Timeline > > The important files are application.py (controllers), model.py (data > model), and the templates (views) folder. (The public folder is where > CSS/JS/images go.) Similar to Stef's comment on web2py, development > with WebCore (or web2py, or WebPy, or? basically any micro-framework) > is extremely rapid. > > ? Alice. > > From ax003d at gmail.com Mon Dec 6 20:22:50 2010 From: ax003d at gmail.com (ax003d) Date: Tue, 7 Dec 2010 09:22:50 +0800 Subject: TDD in python In-Reply-To: <4CFD65F8.7020908@simplistix.co.uk> References: <0906c010-709d-41d9-8b29-2f42afb87f94@32g2000yqz.googlegroups.com> <58fe3680-21f5-42f8-9341-e069cbb88975@r19g2000prm.googlegroups.com> <4CFD65F8.7020908@simplistix.co.uk> Message-ID: This book may help you: http://www.apress.com/book/view/9781590599815 2010/12/7 Chris Withers > On 30/11/2010 13:33, Roy Smith wrote: > >> In article >> <58fe3680-21f5-42f8-9341-e069cbb88975 at r19g2000prm.googlegroups.com>, >> rustom wrote: >> >> Looking around I found this: >>> http://bytes.com/topic/python/answers/43330-unittest-vs-py-test >>> where Raymond Hettinger no less says quite unequivocally that he >>> prefers test.py to builtin unittest >>> because it is not so heavy-weight >>> >>> Is this the general consensus nowadays among pythonistas? >>> [Note I tend to agree but Ive no experience so asking] >>> >> >> Both frameworks have their fans; I doubt you'll find any consensus. >> >> Pick one, learn it, and use it. What's important is that you write >> tests, write lots of tests, and write good tests. Which framework you >> use is a detail. >> > > For a great mailing lists that covers all of these types of issues, see > here: > > http://lists.idyll.org/listinfo/testing-in-python > > cheers, > > Chris > > -- > Simplistix - Content Management, Batch Processing & Python Consulting > - http://www.simplistix.co.uk > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nobody at nowhere.com Mon Dec 6 21:26:02 2010 From: nobody at nowhere.com (Nobody) Date: Tue, 07 Dec 2010 02:26:02 +0000 Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> <7x39qbfhd8.fsf@ruckus.brouhaha.com> Message-ID: On Mon, 06 Dec 2010 08:32:18 -0500, Mel wrote: > Apparently, at the end of his research, Alan Turing was trying out the idea > of 'oracles', where a computable process would have access to an > uncomputable process to get particular results. I would imagine that the > idea here was to clarify what this would do to the computable process. If > he had lived, I doubt that Turing would have built an oracle, but the idea > does live on in interactive debuggers. The "oracle" concept was introduced quite early on in Turing's work, late 1930s. The idea is to examine the complexity of problems relative to other problems. E.g. if you have a Turing machine with access to an oracle which can solve some NP-complete problem, you can analyse the complexity of solving other NP-complete problems in that context. From nagle at animats.com Mon Dec 6 23:58:48 2010 From: nagle at animats.com (John Nagle) Date: Mon, 06 Dec 2010 20:58:48 -0800 Subject: Exception handling in Python 3.x In-Reply-To: <878w02leut.fsf.mdw@metalzone.distorted.org.uk> References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> <4cfd4d5a$0$1662$742ec2ed@news.sonic.net> <878w02leut.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4cfdbf06$0$1629$742ec2ed@news.sonic.net> On 12/6/2010 2:24 PM, Mark Wooding wrote: > John Nagle writes: > >> Right. You're not entitled to assume that StopIteration is how a >> generator exits. That's a CPyton thing; generators were a retrofit, >> and that's how they were hacked in. Other implementations may do >> generators differently. > > This is simply wrong. The StopIteration exception is a clear part of > the generator protocol as described in 5.2.8 of the language reference; > the language reference also refers to 3.5 of the library reference, > which describes the iterator protocol (note, not the generator > implementation -- all iterators work the same way), and explicitly > mentions StopIteration as part of the protocol. > > -- [mdw] PEP 255, like too much Python literature, doesn't distinguish clearly between the language definition and implementation detail. It says "The mechanics of StopIteration are low-level details, much like the mechanics of IndexError in Python 2.1". Applications shouldn't be explicitly using StopIteration. IronPython doesn't do StopIteration the same way CPython does. http://ironpython.codeplex.com/wikipage?title=IPy1.0.xCPyDifferences Neither does Shed Skin. John Nagle From nagle at animats.com Tue Dec 7 00:05:34 2010 From: nagle at animats.com (John Nagle) Date: Mon, 06 Dec 2010 21:05:34 -0800 Subject: Exception handling in Python 3.x In-Reply-To: <4cfd7e6a$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> <7xmxoi8v0b.fsf@ruckus.brouhaha.com> <4cfd7e6a$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cfdc09d$0$1643$742ec2ed@news.sonic.net> On 12/6/2010 4:23 PM, Steven D'Aprano wrote: > On Mon, 06 Dec 2010 13:13:40 -0800, Paul Rubin wrote: > >> It's really unfortunate, though, that Python 3 didn't offer a way to >> peek at the next element of an iterable and test emptiness directly. > > This idea of peekable iterables just won't die, despite the obvious flaws > in the idea. > > There's no general way of telling whether or not a lazy sequence is done > except to actually generate the next value, and caching that value is not > appropriate for all such sequences since it could depend on factors which > have changed between the call to peek and the call to next. Right. Pascal had the predicates "eoln(file)" and "eof(file)", which were tests for end of line and end of file made before reading. This caused much grief with interactive input, because the test would stall waiting for the user to type something. Wirth originally intended Pascal for batch jobs, and his version didn't translate well to interactive use. (Wirth fell in love with his original recursive-descent compiler, which was simple but limited. He hated to have language features that didn't fit his compiler model well. This held the language back and eventually killed it.) C I/O returned a unique value on EOF, but there was no way to test for it before reading. Works much better. The same issues apply to pipes, sockets, qeueues, interprocess communication, etc. John Nagle From lukasz at langa.pl Tue Dec 7 03:24:37 2010 From: lukasz at langa.pl (=?utf-8?Q?=C5=81ukasz_Langa?=) Date: Tue, 7 Dec 2010 09:24:37 +0100 Subject: [Python-Dev] [RELEASED] Python 3.2 beta 1 In-Reply-To: <4CFD59C8.4070006@python.org> References: <4CFD59C8.4070006@python.org> Message-ID: <433FCEE2-CD6C-48BD-90DF-2990B27E4EED@langa.pl> Wiadomo?? napisana przez Georg Brandl w dniu 2010-12-06, o godz. 22:46: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On behalf of the Python development team, I'm happy to announce the > first of two beta preview releases of Python 3.2. > > Python 3.2 is a continuation of the efforts to improve and stabilize the > Python 3.x line. Since the final release of Python 2.7, the 2.x line > will only receive bugfixes, and new features are developed for 3.x only. > > Since PEP 3003, the Moratorium on Language Changes, is in effect, there > are no changes in Python's syntax and built-in types in Python 3.2. > Development efforts concentrated on the standard library and support for > porting code to Python 3. Highlights are: > > [snip] * configparser 1.1: new API using the mapping protocol access, support for pluggable interpolation handlers, additional interpolation handler (ExtendedInterpolation) which supports the zc.buildout syntax, support for alternative option/value delimiters, support for customization of accepted INI file structure (e.g. comment prefixes, name of the DEFAULT section, indentation, empty lines in multiline values, etc.), support for specifying encoding for read operations, ConfigParser class deprecated in favor of SafeConfigParser, lots of other small changes. -- Best regards, ?ukasz Langa tel. +48 791 080 144 WWW http://lukasz.langa.pl/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From nagle at animats.com Tue Dec 7 03:53:27 2010 From: nagle at animats.com (John Nagle) Date: Tue, 07 Dec 2010 00:53:27 -0800 Subject: Collision of rotated rectangles without pygame In-Reply-To: <20101205234936.39dc1a4e@Knock> References: <20101205234936.39dc1a4e@Knock> Message-ID: <4cfdf605$0$1639$742ec2ed@news.sonic.net> On 12/5/2010 2:49 PM, Martin Manns wrote: > Hello, > > I am looking for a Python library for 2D collision checks of rotated > rectangles. Currently, I have found vizier 0.5b that is based on pygame. > > Since I do not want to add a pygame dependency to my app, I replaced the > pygame.rect.Rect by a wxPython wx.Rect (see code below). > > However, collision checks do not work correctly, i. e. identical rects > are not found to be colliding: Probably because you seem to be trying to compute the intersection point for coincident lines, which is not well-defined. I don't have time to debug this, but you might want to get some basic books on game programming and graphics. Incidentally, a dictionary lookup in Python is far more expensive than computing trig functions. If you need to speed this up for large numbers of rectangles, there are algorithms that are several orders of magnitude faster. Realistically, though, this is the kind of problem that runs slow in CPython. This is why you don't write your own collision library. (I once did, for 3D, but that was in 1996, when it was cutting-edge technology.) John Nagle From dheeraj.gupta4 at gmail.com Tue Dec 7 04:16:56 2010 From: dheeraj.gupta4 at gmail.com (RedBaron) Date: Tue, 7 Dec 2010 01:16:56 -0800 (PST) Subject: Using logging module to log either to screen or a file Message-ID: <3b9112c2-7a63-40ef-a0f6-f64a090acb59@j18g2000prn.googlegroups.com> Hi, I am beginner to python and i am writing a program that does a lot of things. One of the requirements is that the program shud generate a log file. I came across python loggging module and found it very useful. But I have a few problems Suppose by giving option '-v' along with the program the user can turn off logging to a file and instead display log on the screen. Since I am using a config file for logging, how do I accomplish this. I tried to define two handlers (fil and screen) and added it to my logger. But that logs data to both screen and the file. I need to log it to only one. How do I dynamically remove one of the handler from the logger based on user option. As a precursor how do i reference the handlers defined in config file in the code?? From mdw at distorted.org.uk Tue Dec 7 05:00:30 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 07 Dec 2010 10:00:30 +0000 Subject: Exception handling in Python 3.x References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> <4cfd4d5a$0$1662$742ec2ed@news.sonic.net> <878w02leut.fsf.mdw@metalzone.distorted.org.uk> <4cfdbf06$0$1629$742ec2ed@news.sonic.net> Message-ID: <87zkshkim9.fsf.mdw@metalzone.distorted.org.uk> John Nagle writes: > PEP 255, like too much Python literature, doesn't distinguish > clearly between the language definition and implementation detail. It > says "The mechanics of StopIteration are low-level details, much like > the mechanics of IndexError in Python 2.1". Applications shouldn't be > explicitly using StopIteration. You've twisted the words by quoting them out of context, and have attempted to force a misinterpretation of `low-level details' as `implementation detail'. That text comes from a question-and-answer section, in response to the question `why not force termination to be spelled "StopIteration"?'. This is a fine answer to the question: the details of the (preexisting -- see PEP 234) iteration protocol are abstracted by the generator syntax. But it doesn't at all mean that the StopIteration exception isn't an official, use-visible part of Python. > IronPython doesn't do StopIteration the same way CPython does. > > http://ironpython.codeplex.com/wikipage?title=IPy1.0.xCPyDifferences IronPython's behaviour when you try to fetch items from a spent generator is different. It still implements the same iterator protocol, and raises StopIteration when it has no more items to yield. You're not stupid, but you'd have to be in order to think that these references support your claim that > >> You're not entitled to assume that StopIteration is how a generator > >> exits. That's a CPyton thing; generators were a retrofit, and > >> that's how they were hacked in. Other implementations may do > >> generators differently. I don't want to conclude that you're not arguing in good faith but I'm not seeing many other possibilities. -- [mdw] From shearichard at gmail.com Tue Dec 7 05:49:00 2010 From: shearichard at gmail.com (shearichard) Date: Tue, 7 Dec 2010 02:49:00 -0800 (PST) Subject: PEP8 compliance and exception messages ? References: <63cab97f-4e46-4c30-83ce-dc531a900d40@u25g2000pra.googlegroups.com> <87ei9v1nop.fsf@benfinney.id.au> Message-ID: <0f8ab582-97e2-4027-b59d-0fa37708a9d3@n2g2000pre.googlegroups.com> On Dec 6, 6:21?pm, Ben Finney wrote: > shearichard writes: > > Hi - PEP8 says lines should not exceed 79 characters in length > > (http://www.python.org/dev/peps/pep-0008/). > > > So if you've got some code that looks like this : > > > raise fooMod.fooException("Some message which is quite long") > > PEP 8 also says those names are poorly chosen. Better: > > ? ? raise foomod.FooException("Some message which is quite long") > > > raise fooMod.fooException("\ > > ? ? ? ? Some message \ > > ? ? ? ? which is quite long") > > Take advantage of the parsing of string literals and parenthesis: > > ? ? raise foomod.FooException( > ? ? ? ? "Some message" > ? ? ? ? " which is quite long") > > and for the sake of my eyes, avoid camelCase. OK you got me ! Thanks for pointing this out, I will take a look at the relevant section From shearichard at gmail.com Tue Dec 7 05:53:44 2010 From: shearichard at gmail.com (shearichard) Date: Tue, 7 Dec 2010 02:53:44 -0800 (PST) Subject: PEP8 compliance and exception messages ? References: <63cab97f-4e46-4c30-83ce-dc531a900d40@u25g2000pra.googlegroups.com> <20101206002249.2d804250@wldmr> <20101206151721.4446d722@wldmr> Message-ID: <61321d11-76ad-4355-958f-e70f7c58ab7d@n2g2000pre.googlegroups.com> On Dec 7, 9:17?am, Andreas Waldenburger wrote: > On Mon, 6 Dec 2010 00:22:49 -0500 Andreas Waldenburger wrote: > > > > > On Sun, 5 Dec 2010 19:52:54 -0800 Chris Rebert > > wrote: > > > > On Sun, Dec 5, 2010 at 7:40 PM, shearichard > > > wrote: > > > > Hi - PEP8 says lines should not exceed 79 characters in length > > > > (http://www.python.org/dev/peps/pep-0008/). > > > > > So if you've got some code that looks like this : > > > > > raise fooMod.fooException("Some message which is quite long") > > > > > ... and assuming a certain amount of indenting you're going to > > > > break that guideline. > > > > > [etc.] > > > > [...] > > > Alternatively, you could disregard PEP 8 on this point on the > > > grounds that the 79/80 characters per line limit is outdated. > > > Maybe, but it's not outmoded. > > As a more useful (I hope) reply, my opinion in this case is to just make the line a little longer. Even if you can't read it all at once, it is pretty obvious what comes next: The rest of the error message. There is no additional functionality hidden there, and you don't need to see it all at once to grasp the meaning of the code. > > /W > > -- > To reach me via email, replace INVALID with the country code of my home > country. ?But if you spam me, I'll be one sour Kraut. Thanks to everyone for their helpful replies. Thanks for the pointers towards implicit (or explicit) string concatenation - just what was needed. I appreciate everyone has different opinions by I'm happy to try to stick with 79 character lines for the meantime - largely for the 'may have a wide screen but like to have lots of files open in slim windows' reason. regards Richard. From steve.gnulinux at gmail.com Tue Dec 7 06:05:06 2010 From: steve.gnulinux at gmail.com (Steve) Date: Tue, 7 Dec 2010 03:05:06 -0800 (PST) Subject: v = vte.Terminal() AttributeError: 'module' object has no attribute 'Terminal' Message-ID: Hi, I try to run a terminal emulation using Python+Gtk+Vte. Before develop my own sources, i'm testing some examples like this ; http://www.eurion.net/python-snippets/snippet/Embed%20a%20VTE%20terminal.html But when i try to run, i get this message error; v = vte.Terminal() AttributeError: 'module' object has no attribute 'Terminal' I'm using ubuntu 9.10 karmic. I've installed (apt-get) python-gtk, /2, -dev, libvte... Anyone know if there's a bug on this using karmic, or i must to download and compile gtk/vte from sources? thanks, Steve, From zdoor at xs4all.nl Tue Dec 7 06:11:44 2010 From: zdoor at xs4all.nl (Alex van der Spek) Date: Tue, 7 Dec 2010 12:11:44 +0100 Subject: Calling FORTAN dll functions from Python Message-ID: <4cfe167a$0$81476$e4fe514c@news.xs4all.nl> Does anyone know how to call functions from FORTRAN dlls in Python? Is it even possible? I browsed the documentation for Python 2.6.1 and the Python/C API comes close to what I would like to do but it is strictly limited to C. Unfortunately the passing of arguments in C and FORTRAN is very different, not to mention the differences with strings where FORTRAN expects a hidden length argument. It could call the FORTRAN dll from C and call the C functions from Python but is that my only option? For reference: I am using Python 2.6.1 FORTRAN powerstation 4.0. It is not an option to translate the FORTRAN code to C (using f2c) as the source code is the official ASME version of calculating steam tables. I am interested in a solution that will work on Windows (XP and Vista) as well as Linux (Ubuntu 10.4) although the latter would not use dlls but code resources. I am a beginner in Python. The fact that I still use and can use FORTRAN gives away my age. Mixed language programming is not an issue for me (C/VB, VB/FORTRAN, C/FORTRAN) but Python is new. Just pointing me to relevant documentation would be helpful in its own right. Thank you in advance, Alex van der Spek From stefan_ml at behnel.de Tue Dec 7 06:52:54 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 07 Dec 2010 12:52:54 +0100 Subject: Calling FORTAN dll functions from Python In-Reply-To: <4cfe167a$0$81476$e4fe514c@news.xs4all.nl> References: <4cfe167a$0$81476$e4fe514c@news.xs4all.nl> Message-ID: Alex van der Spek, 07.12.2010 12:11: > Does anyone know how to call functions from FORTRAN dlls in Python? Is > it even possible? Sure, have a look at fwrap and Cython. Stefan From anders.u.persson at gmail.com Tue Dec 7 08:23:06 2010 From: anders.u.persson at gmail.com (Anders Persson) Date: Tue, 7 Dec 2010 05:23:06 -0800 (PST) Subject: is py2exe still active ? Message-ID: <5f32249f-50d4-440e-9005-04f954572894@32g2000yqz.googlegroups.com> Hi! When a look att py2exe homepage it is not looking like mutch happen, as a beginner i was thinking to start with Python 3, but i like to now if py2exe will be for 3 too. Is any one have any info ? From orasnita at gmail.com Tue Dec 7 08:39:18 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Tue, 7 Dec 2010 15:39:18 +0200 Subject: Books recommendation Message-ID: Hello, Do you have, or can I find elsewhere a recommendation for books,tutorials and sites appropriate for beginners? I have a lot of experience in Perl but I am interested to also learn Python for: - web development (with frameworks similar with Catalyst and Ruby on Rails, good templating systems, good ORMS and form processors) - Desktop apps with WxPython - Create MS Windows apps, executables, dlls, ActiveX, OS interaction... - Text parsing, regular expressions... I am also interested to find where I can get Python modules from and how... similar tools and sites with cpan and ppm for Perl. Thank you. Octavian From anders.u.persson at gmail.com Tue Dec 7 09:14:21 2010 From: anders.u.persson at gmail.com (Anders Persson) Date: Tue, 7 Dec 2010 06:14:21 -0800 (PST) Subject: Books recommendation References: Message-ID: <4eeb8e48-93b7-42aa-8d0a-43b4fdd5fef0@z9g2000yqz.googlegroups.com> You can't compile Python to exe files, but there is program packing your script to a exe files, look att www.py2exe.org Beware that you must have py2exe version match your pythonversion and att current time the highest version is 2.7. /A On Dec 7, 2:39?pm, "Octavian Rasnita" wrote: > Hello, > > Do you have, or can I find elsewhere a recommendation for books,tutorials and sites appropriate for beginners? > > I have a lot of experience in Perl but I am interested to also learn Python for: > - web development (with frameworks similar with Catalyst and Ruby on Rails, good templating systems, good ORMS and form processors) > - Desktop apps with WxPython > - Create MS Windows apps, executables, dlls, ActiveX, OS interaction... > - Text parsing, regular expressions... > > I am also interested to find where I can get Python modules from and how... similar tools and sites with cpan and ppm for Perl. > > Thank you. > > Octavian From data.2 at rediff.com Tue Dec 7 09:16:01 2010 From: data.2 at rediff.com (gaurav) Date: Tue, 7 Dec 2010 06:16:01 -0800 (PST) Subject: Fresher career in Management work. Message-ID: Recent recruitment you can reach your goal. Careers recruitment. http://managementjobs.webs.com/itm.htm http://topcareer.webs.com/businessmanagement.htm Latest government works to earn money, other vacancies in office jobs. http://printmediajobs.webs.com/index.htm http://rojgars1.webs.com/gov.htm From jeanmichel at sequans.com Tue Dec 7 09:33:14 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 07 Dec 2010 15:33:14 +0100 Subject: Using logging module to log either to screen or a file In-Reply-To: <3b9112c2-7a63-40ef-a0f6-f64a090acb59@j18g2000prn.googlegroups.com> References: <3b9112c2-7a63-40ef-a0f6-f64a090acb59@j18g2000prn.googlegroups.com> Message-ID: <4CFE45AA.5010405@sequans.com> RedBaron wrote: > Hi, > I am beginner to python and i am writing a program that does a lot of > things. One of the requirements is that the program shud generate a > log file. I came across python loggging module and found it very > useful. But I have a few problems > Suppose by giving option '-v' along with the program the user can turn > off logging to a file and instead display log on the screen. Since I > am using a config file for logging, how do I accomplish this. > I tried to define two handlers (fil and screen) and added it to my > logger. But that logs data to both screen and the file. I need to log > it to only one. How do I dynamically remove one of the handler from > the logger based on user option. As a precursor how do i reference the > handlers defined in config file in the code?? > your logger has a public 'handlers' attribute. consoleHandlers = [h for h in logger.handlers if h.__class__ is logging.StreamHandler] # the list of handlers logging to the console (assuming they are instances of the StreamHandler class) if consoleHandlers: h1 = consoleHandlers[0] h1.filter = lambda x:True # enable the handler h1.filter = lambda x:False # disable the handler JM From sebastien.frigon at gmail.com Tue Dec 7 10:00:12 2010 From: sebastien.frigon at gmail.com (Cbast) Date: Tue, 7 Dec 2010 07:00:12 -0800 (PST) Subject: is py2exe still active ? References: <5f32249f-50d4-440e-9005-04f954572894@32g2000yqz.googlegroups.com> Message-ID: <89dd2092-d6e9-4d5c-b966-54df3f48f065@g19g2000yqg.googlegroups.com> On Dec 7, 8:23?am, Anders Persson wrote: > Hi! > When a look att py2exe homepage it is not looking like mutch happen, > as a beginner i was thinking to start with Python 3, but i like to now > if py2exe will be for 3 too. > > Is any one have any info ? I don't have the answer about py2exe, but I'm using cxFreeze to create executables with Python 3.1, if it's what you're looking for. http://cx-freeze.sourceforge.net/ From grappale at hotmail.it Tue Dec 7 10:26:04 2010 From: grappale at hotmail.it (Ale Ghelfi) Date: Tue, 07 Dec 2010 16:26:04 +0100 Subject: sqlite3 and UTF-8 Message-ID: I try to connect a database sqlite by sqlite3, but return an error. >>> rowset = cur.fetchall() Traceback (most recent call last): File "", line 1, in rowset = cur.fetchall() OperationalError: Could not decode to UTF-8 column 'DATO' with text 'Document n?10' What's happend? thank you From grappale at hotmail.it Tue Dec 7 10:35:02 2010 From: grappale at hotmail.it (Ale Ghelfi) Date: Tue, 07 Dec 2010 16:35:02 +0100 Subject: kinterbasdb error connection Message-ID: (i'm under Ubuntu 10.10 amd64 and python 2.6 and kinterbasdb 3.2 ) I try to connect my database of firebird 2.5 by kinterbasdb. But python return this error : >>> c = kinterbasdb.connect(dsn="/media/VINACCIA.FDB",user="user",password="password",charset="UTF-8") Traceback (most recent call last): File "", line 1, in c = kinterbasdb.connect(dsn="/media/VINACCIA.FDB",user="user",password="password",charset="UTF-8") File "/usr/lib/pymodules/python2.6/kinterbasdb/__init__.py", line 435, in connect return Connection(*args, **keywords_args) File "/usr/lib/pymodules/python2.6/kinterbasdb/__init__.py", line 612, in __init__ b.dsn, b.dpb, b.dialect, timeout OperationalError: (-902, 'isc_attach_database: \n I/O error during "open" operation for file "/media/VINACCIA.FDB"\n Error while trying to open file\n Permission denied') By terminal of Ubuntu this is the permission of database: $ls -l /media/VINACCIA.FDB -rw-r--r-- 1 grappale grappale 1720320 2010-12-06 17:33 /media/VINACCIA.FDB Where am i wrong? Please. Thank you! From orasnita at gmail.com Tue Dec 7 10:47:32 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Tue, 7 Dec 2010 17:47:32 +0200 Subject: Books recommendation References: <4eeb8e48-93b7-42aa-8d0a-43b4fdd5fef0@z9g2000yqz.googlegroups.com> Message-ID: <4F36CB2A698F48AB8F613C4E12B18C47@teddy> Thank you for your help. I have succeeded to create a Windows executable with py2exe. I've seen that the source code of the sample script is hidden. Do you know if it happens the same if the script uses other Python modules I will make? (Will py2exe hide the source code of those modules also?) Thanks. Octavian ----- Original Message ----- From: "Anders Persson" Newsgroups: comp.lang.python To: Sent: Tuesday, December 07, 2010 4:14 PM Subject: Re: Books recommendation You can't compile Python to exe files, but there is program packing your script to a exe files, look att www.py2exe.org Beware that you must have py2exe version match your pythonversion and att current time the highest version is 2.7. /A On Dec 7, 2:39 pm, "Octavian Rasnita" wrote: > Hello, > > Do you have, or can I find elsewhere a recommendation for books,tutorials and sites appropriate for beginners? > > I have a lot of experience in Perl but I am interested to also learn Python for: > - web development (with frameworks similar with Catalyst and Ruby on Rails, good templating systems, good ORMS and form processors) > - Desktop apps with WxPython > - Create MS Windows apps, executables, dlls, ActiveX, OS interaction... > - Text parsing, regular expressions... > > I am also interested to find where I can get Python modules from and how... similar tools and sites with cpan and ppm for Perl. > > Thank you. > > Octavian -- http://mail.python.org/mailman/listinfo/python-list From g.starck at gmail.com Tue Dec 7 10:52:06 2010 From: g.starck at gmail.com (gst) Date: Tue, 7 Dec 2010 07:52:06 -0800 (PST) Subject: use of __new__ to permit "dynamic" completion within (any?) IDE ? Message-ID: <0b90e80b-8b9b-412d-bfff-9a9ec4b172d2@h22g2000vbr.googlegroups.com> Hi, I met a situation where I was passing an object created in/with an upper level module class to a lower level module class' instance in one of its __init__ argument and saving a ref of the upper object in that lower level class' new instance. But in my IDE I want the completion to also work from within the lower level module when it's refering to the object passed from the upper level: Well, I'm sure I'm not very clear in my terms (and probably a bit long in the sentence) so here it is in code: files: module1.py subpackage/module2.py file module1.py: from subpackage.module2 import class2 class class1(object): def __new__(cls, _self=None, *args, **kwargs): if _self: ## we've been passed an instance already initialyzed ## so directly return it instead of creating a new object. return _self return object.__new__(cls) def __init__(self, _self=None, *args, **kwargs): if _self: ## we've been passed an instance already initialyzed ## so directly returns ## assert(self is _self) ? return self.object2 = class2(object1=self, "blip", "blop") # others init file module2.py: class class2(object): def __init__(self, object1, *args, **kwargs): from ..module1 import class1 self.object1 = class1(_self=object1) ## instead of: self.object1 = object1 ## others functions and/or init.. ## where now I've completion working on self.object1 : ## if I add(or remove) fields/methods in module1 (and save) then ## I have them available(or disappeared) in the completion when executed from this submodule. ## This ofcourse permits to save me of remembering all of the class1 attributes/methods when I'm working with self.object1 from within one of class2 methods. What do you think of this ? I guess there can be others ways of doing this.. ? Thanks, Regards, Greg. note: I'm using Eclipse 3.5.2 with pydev so (I don't really know how others IDE can handle this case) . From __peter__ at web.de Tue Dec 7 10:55:29 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 07 Dec 2010 16:55:29 +0100 Subject: sqlite3 and UTF-8 References: Message-ID: Ale Ghelfi wrote: > I try to connect a database sqlite by sqlite3, but return an error. > > >>> rowset = cur.fetchall() > Traceback (most recent call last): > File "", line 1, in > rowset = cur.fetchall() > OperationalError: Could not decode to UTF-8 column 'DATO' with text > 'Document n?10' > > What's happend? thank you How did you enter the data into the database? If it was with a script under your control modify it to feed unicode instead of str to the database. Otherwise, if you know the encoding used in the database maybe setting Connection.text_factory actual_encoding = ... # whatever def decode(s): return s.decode(actual_encoding) db = sqlite3.connect(...) db.text_factory = decode helps (untested). See also http://docs.python.org/library/sqlite3.html#sqlite3.Connection.text_factory Peter From lists at cheimes.de Tue Dec 7 10:55:47 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 07 Dec 2010 16:55:47 +0100 Subject: kinterbasdb error connection In-Reply-To: References: Message-ID: Am 07.12.2010 16:35, schrieb Ale Ghelfi: > (i'm under Ubuntu 10.10 amd64 and python 2.6 and kinterbasdb 3.2 ) > I try to connect my database of firebird 2.5 by kinterbasdb. > But python return this error : > > >>> c = > kinterbasdb.connect(dsn="/media/VINACCIA.FDB",user="user",password="password",charset="UTF-8") > Traceback (most recent call last): > File "", line 1, in > c = > kinterbasdb.connect(dsn="/media/VINACCIA.FDB",user="user",password="password",charset="UTF-8") > File "/usr/lib/pymodules/python2.6/kinterbasdb/__init__.py", line > 435, in connect > return Connection(*args, **keywords_args) > File "/usr/lib/pymodules/python2.6/kinterbasdb/__init__.py", line > 612, in __init__ > b.dsn, b.dpb, b.dialect, timeout > OperationalError: (-902, 'isc_attach_database: \n I/O error during > "open" operation for file "/media/VINACCIA.FDB"\n Error while trying to > open file\n Permission denied') > > By terminal of Ubuntu this is the permission of database: > $ls -l /media/VINACCIA.FDB > -rw-r--r-- 1 grappale grappale 1720320 2010-12-06 17:33 /media/VINACCIA.FDB > > Where am i wrong? Please. Thank you! Are you using classic mode or super mode? I have no experience with classic mode but for super mode, the firebird user or group needs permission to enter the directory (rx for / and /media) and to alter the file (rw for media/VINACCIA.FDB). I suggest that you change the permission to 664 and the group of the file to firebird. Christian From awilliam at whitemice.org Tue Dec 7 11:32:30 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Tue, 07 Dec 2010 11:32:30 -0500 Subject: Task Engine Framework? In-Reply-To: References: Message-ID: <1291739550.12904.6.camel@linux-yu4c.site> On Mon, 2010-12-06 at 15:11 -0800, Nate wrote: > Hello, > I'm in the process of developing a task engine / workflow module for > my Python application and I'm wondering if anyone knows of existing > code that could be used or adapted. Since I know that's far too > generic a question, let me share my goals: > 1) Support long running operations (think backing up millions of > files) where: > - The operation can be paused (application closed) and the > operation resumed later. > - Individual tasks can be chained, run in parallel, or looped over > (the workflow part) We have something like that in OIE (OpenGroupware Integration Engine). . These things tend to turn out to be quite specific [and thus not generic]. But if you have any questions feel free to ask. The focus in OIE was the ability to describe processes in BPML and facilitate process management [creating, queuing, parking (stopping for later resume) of business / ETL tasks. Parts of the code aren't especially elegant but it does move a fairly large amount of data every day. > 2) Would like to graph each defined operation (task A starts task B > with parameters... ) for documenting algorithms in Software Design > Document > 3) Each individual task in the operation would a self-contained > class. I'd imagine implementing its action by defining a doTask() > method > Hopefully that's clear. I just feel like someone must have already > solved this elegantly. I greatly enjoy Python and I look forward to > proving its use as a valuable language for a Masters student even > though everyone thinks I should use C# :-). From bruno.desthuilliers at gmail.com Tue Dec 7 11:34:08 2010 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Tue, 7 Dec 2010 08:34:08 -0800 (PST) Subject: v = vte.Terminal() AttributeError: 'module' object has no attribute 'Terminal' References: Message-ID: On 7 d?c, 12:05, Steve wrote: > Hi, > > I try to run a terminal emulation using Python+Gtk+Vte. Before develop > my own sources, i'm testing some examples like this ;http://www.eurion.net/python-snippets/snippet/Embed%20a%20VTE%20termi... > > But when i try to run, i get this message error; > > ? ? v = vte.Terminal() > AttributeError: 'module' object has no attribute 'Terminal' Before any other thing, make sure the "vte" module you imported is the expected one. Edit your script that way: # import vte try: import vte except: error = gtk.MessageDialog (None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, 'You need to install python bindings for libvte') error.run() sys.exit (1) else: print "using wte module : %s" % vte and check the module path this prints to your stdout. From grappale at hotmail.it Tue Dec 7 11:37:37 2010 From: grappale at hotmail.it (Ale Ghelfi) Date: Tue, 07 Dec 2010 17:37:37 +0100 Subject: sqlite3 and UTF-8 References: Message-ID: i try this : > actual_encoding = ... # whatever > def decode(s): > return s.decode(actual_encoding) > > db = sqlite3.connect(...) > db.text_factory = decode but now the error is : >>> rowset = cur.fetchall() Traceback (most recent call last): File "", line 1, in rowset = cur.fetchall() File "", line 2, in decode return s.decode(enc) File "/usr/lib/python2.6/encodings/utf_8.py", line 16, in decode return codecs.utf_8_decode(input, errors, True) UnicodeDecodeError: 'utf8' codec can't decode byte 0xb0 in position 33: invalid start byte From pythonmarco at gmail.com Tue Dec 7 11:51:05 2010 From: pythonmarco at gmail.com (Marco Hornung) Date: Tue, 7 Dec 2010 11:51:05 -0500 Subject: find memory leaks in running program Message-ID: <391F8BF8-8FF5-42B8-8F10-C6F0428CA27B@gmail.com> Hey, ------------------------------------------------------------------------------------------ questions ------------------------------------------------------------------------------------------ 1. What are the best tools to analyze pythons memory stack, while it is running? 2. Is there a possibility to analyze the memory stack of a program with external programs? (without to change the source code - I am only interested in the object size) 3. Can I sort of "break" into the memory to see what objects consume how much memory? ------------------------------------------------------------------------------------------ my scenario ------------------------------------------------------------------------------------------ I have to debug a multithreaded server, which is written in the twisted-framework. One of the processes has some sort of memory leak - After one of our jobs is finished the main process has still over 59% of the entire memory allocated. I will probably have to recreate our scenario and equip our server with some memory sensors - but it takes 12h to reproduce the scenario and I will have to change the source code(at least I do not know of other options). Therefore I am looking for quicker possibilities to look into what causes our memory leak. Regards, Marco From __peter__ at web.de Tue Dec 7 11:52:00 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 07 Dec 2010 17:52 +0100 Subject: sqlite3 and UTF-8 References: Message-ID: Ale Ghelfi wrote: > i try this : > >> actual_encoding = ... # whatever >> def decode(s): >> return s.decode(actual_encoding) >> >> db = sqlite3.connect(...) >> db.text_factory = decode > > but now the error is : > > >>> rowset = cur.fetchall() > Traceback (most recent call last): > File "", line 1, in > rowset = cur.fetchall() > File "", line 2, in decode > return s.decode(enc) > File "/usr/lib/python2.6/encodings/utf_8.py", line 16, in decode > return codecs.utf_8_decode(input, errors, True) > UnicodeDecodeError: 'utf8' codec can't decode byte 0xb0 in position 33: > invalid start byte So you specified actual_encoding = "UTF-8" ? That's pointless because UTF-8 is the default, and you've already seen that failing. You can set db.text_factory = str but you'll probably run into problems with that later, e. g. when you try to display the retrieved data. So again, what data do you expect to find in the column(s) you can't decode properly? Peter From shearern at gmail.com Tue Dec 7 11:56:49 2010 From: shearern at gmail.com (Nate) Date: Tue, 7 Dec 2010 08:56:49 -0800 (PST) Subject: Task Engine Framework? References: Message-ID: <4a482ab5-2096-45d5-ae76-1af5ccc971da@c13g2000prc.googlegroups.com> On Dec 7, 8:32?am, Adam Tauno Williams wrote: > On Mon, 2010-12-06 at 15:11 -0800, Nate wrote: > > Hello, > > I'm in the process of developing a task engine / workflow module for > > my Python application and I'm wondering if anyone knows of existing > > code that could be used or adapted. ?Since I know that's far too > > generic a question, let me share my goals: > > 1) Support long running operations (think backing up millions of > > files) where: > > ? ?- The operation can be paused (application closed) and the > > operation resumed later. > > ? ?- Individual tasks can be chained, run in parallel, or looped over > > (the workflow part) > > We have something like that in OIE (OpenGroupware Integration Engine). > . ?These things tend to turn out > to be quite specific [and thus not generic]. ?But if you have any > questions feel free to ask. ?The focus in OIE was the ability to > describe processes in BPML and facilitate process management [creating, > queuing, parking (stopping for later resume) of business / ETL tasks. > Parts of the code aren't especially elegant but it does move a fairly > large amount of data every day. > > > > > > > > > 2) Would like to graph each defined operation (task A starts task B > > with parameters... ) for documenting algorithms in Software Design > > Document > > 3) Each individual task in the operation would a self-contained > > class. ?I'd imagine implementing its action by defining a doTask() > > method > > Hopefully that's clear. ?I just feel like someone must have already > > solved this elegantly. ?I greatly enjoy Python and I look forward to > > proving its use as a valuable language for a Masters student even > > though everyone thinks I should use C# :-). Thank you, I'll take a look at the project. At the very least, seeing someone else's solution would be helpful. I'm trying desperately hard to keep the code simple :-) -Nate From mauro.caceres at gmail.com Tue Dec 7 12:13:34 2010 From: mauro.caceres at gmail.com (Mauro Caceres) Date: Tue, 7 Dec 2010 14:13:34 -0300 Subject: Books recommendation In-Reply-To: References: Message-ID: > > > I am also interested to find where I can get Python modules from and how... > similar tools and sites with cpan and ppm for Perl. > > You should look at http://pypi.python.org/pypi, for modules. pip (http://pip.openplans.org/) is a tool used to install python modules. enjoy -- Mauro C?ceres -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomas.burdick at gmail.com Tue Dec 7 12:37:41 2010 From: thomas.burdick at gmail.com (Thomas Burdick) Date: Tue, 7 Dec 2010 11:37:41 -0600 Subject: select on multiprocessing Listener class Message-ID: The multiprocessing module has some wrappers for sockets and while the Client object is selectable the Listener is not, I'm wondering if that could be changed or if there's a way to do it already that I'm not seeing? -Tom From edicionsdigitals at gmail.com Tue Dec 7 12:48:17 2010 From: edicionsdigitals at gmail.com (edicionsdigitals.com edicions digitals xarxa social slu) Date: Tue, 7 Dec 2010 09:48:17 -0800 (PST) Subject: v = vte.Terminal() AttributeError: 'module' object has no attribute 'Terminal' References: Message-ID: Solved! A really dummy error: I've a vte.py file in the same folder, so import vte found this first than the needed! Thanks! (and sorry) Steve, On 7 Des, 17:34, "bruno.desthuilli... at gmail.com" wrote: > On 7 d?c, 12:05, Steve wrote: > > > Hi, > > > I try to run a terminal emulation using Python+Gtk+Vte. Before develop > > my own sources, i'm testing some examples like this ;http://www.eurion.net/python-snippets/snippet/Embed%20a%20VTE%20termi... > > > But when i try to run, i get this message error; > > > ? ? v = vte.Terminal() > > AttributeError: 'module' object has no attribute 'Terminal' > > Before any other thing, make sure the "vte" module you imported is the > expected one. Edit your script that way: > > # import vte > try: > ? ? import vte > except: > ? ? error = gtk.MessageDialog (None, gtk.DIALOG_MODAL, > gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, > ? ? ? ? 'You need to install python bindings for libvte') > ? ? error.run() > ? ? sys.exit (1) > else: > ? ? print "using wte module : %s" % vte > > and check the module path this prints to your stdout. From orasnita at gmail.com Tue Dec 7 12:49:54 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Tue, 7 Dec 2010 19:49:54 +0200 Subject: is py2exe still active ? References: <5f32249f-50d4-440e-9005-04f954572894@32g2000yqz.googlegroups.com> <89dd2092-d6e9-4d5c-b966-54df3f48f065@g19g2000yqg.googlegroups.com> Message-ID: <2DEA78DF996B485E8B52F3B29B1124A1@teddy> This packager is also nice. If someone cares, I've discovered a small bug in it. If Python is installed on another drive than C under Windows, the cxfreeze.bat file still calls Python on the drive C and it doesn't work until it is corrected. Octavian ----- Original Message ----- From: "Cbast" Newsgroups: comp.lang.python To: Sent: Tuesday, December 07, 2010 5:00 PM Subject: Re: is py2exe still active ? On Dec 7, 8:23 am, Anders Persson wrote: > Hi! > When a look att py2exe homepage it is not looking like mutch happen, > as a beginner i was thinking to start with Python 3, but i like to now > if py2exe will be for 3 too. > > Is any one have any info ? I don't have the answer about py2exe, but I'm using cxFreeze to create executables with Python 3.1, if it's what you're looking for. http://cx-freeze.sourceforge.net/ -- http://mail.python.org/mailman/listinfo/python-list From harijay at gmail.com Tue Dec 7 13:02:53 2010 From: harijay at gmail.com (harijay) Date: Tue, 7 Dec 2010 10:02:53 -0800 (PST) Subject: win32com pythonwin extensions part of stdlib? Message-ID: Hi I am using Python 2.6.5 on Windows. I wanted to start using the win32com extensions which I understand are "essentially part of the stdlib" ( quoted in http://tgolden.sc.sabren.com/python/win32_how_do_i.html) Since I didnt have the extensions as standard I went to sourceforge to get the module. However when I tried to do a distutils install of the python extensions for windows downloaded from sourceforge , I found out I need some proprietary components from Microsoft visual studio 7)."vcsvarsall.bat" needed. My question is : Can I use the win32com extensions on a licensed windows setup without having access to Visual Studio components. I did see some places where they suggested compiling with mingw32 , but the compilation didnt work. Any help in getting the module running would be greatly appreciated From python.list at tim.thechases.com Tue Dec 7 13:20:40 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 07 Dec 2010 12:20:40 -0600 Subject: Task Engine Framework? In-Reply-To: <4a482ab5-2096-45d5-ae76-1af5ccc971da@c13g2000prc.googlegroups.com> References: <4a482ab5-2096-45d5-ae76-1af5ccc971da@c13g2000prc.googlegroups.com> Message-ID: <4CFE7AF8.2080302@tim.thechases.com> On 12/07/2010 10:56 AM, Nate wrote: > On Dec 7, 8:32 am, Adam Tauno Williams wrote: >>> I'm in the process of developing a task engine / workflow module for >>> my Python application and I'm wondering if anyone knows of existing >>> code that could be used or adapted. Since I know that's far too >>> generic a question, let me share my goals: >>> 1) Support long running operations (think backing up millions of >>> files) where: >>> - The operation can be paused (application closed) and the >>> operation resumed later. >>> - Individual tasks can be chained, run in parallel, or looped over >>> (the workflow part) >> >> We have something like that in OIE (OpenGroupware Integration Engine). >> . > > I'll take a look at the project. At the very least, seeing someone > else's solution would be helpful. I'm trying desperately hard to keep > the code simple :-) You might also want to look at Celery[1] which may do some (if not all) of what you're looking for. -tkc [1] http://celeryproject.org From godson.g at gmail.com Tue Dec 7 13:25:32 2010 From: godson.g at gmail.com (Godson Gera) Date: Tue, 7 Dec 2010 23:55:32 +0530 Subject: win32com pythonwin extensions part of stdlib? In-Reply-To: References: Message-ID: Not sure what you are trying to do but you can get a standalone binaries from http://sourceforge.net/projects/pywin32/ which gets installed without any issues. If for some reason you are still having issues, you can try ActiveState Python which come bundled with pywin32 packages. On Tue, Dec 7, 2010 at 11:32 PM, harijay wrote: > Hi I am using Python 2.6.5 on Windows. > > I wanted to start using the win32com extensions which I understand are > "essentially part of the stdlib" ( quoted in > http://tgolden.sc.sabren.com/python/win32_how_do_i.html) > Since I didnt have the extensions as standard I went to sourceforge > to get the module. > > However when I tried to do a distutils install of the python > extensions for windows downloaded from sourceforge , I found out I > need some proprietary components from Microsoft visual studio > 7)."vcsvarsall.bat" needed. > > My question is : Can I use the win32com extensions on a licensed > windows setup without having access to Visual Studio components. > > I did see some places where they suggested compiling with mingw32 , > but the compilation didnt work. > > Any help in getting the module running would be greatly appreciated > -- > http://mail.python.org/mailman/listinfo/python-list > -- Python Consultant India -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Tue Dec 7 13:27:38 2010 From: ian.g.kelly at gmail.com (Ian) Date: Tue, 7 Dec 2010 10:27:38 -0800 (PST) Subject: win32com pythonwin extensions part of stdlib? References: Message-ID: On Dec 7, 11:02?am, harijay wrote: > Hi I am using Python 2.6.5 on Windows. > > I wanted to start using the win32com extensions which I understand are > "essentially part of the stdlib" ( quoted inhttp://tgolden.sc.sabren.com/python/win32_how_do_i.html) > Since I didnt have the extensions as standard ?I went to sourceforge > to get the module. > > However when I tried to do a distutils install of the python > extensions for windows downloaded from sourceforge , I found out I > need some proprietary components from Microsoft visual studio > 7)."vcsvarsall.bat" needed. > > My question is : Can I use the win32com extensions on a licensed > windows setup without having access to Visual Studio components. > > I did see some places where they suggested compiling with mingw32 , > but the compilation didnt work. > > Any help in getting the module running would be greatly appreciated There are pre-built binary distributions available on sourceforge. Why not just use one of those? From kee at kagi.com Tue Dec 7 14:00:35 2010 From: kee at kagi.com (Kee Nethery) Date: Tue, 7 Dec 2010 11:00:35 -0800 Subject: Books recommendation In-Reply-To: References: Message-ID: <237490BE-143B-4474-940E-48421488BEDC@kagi.com> On Dec 7, 2010, at 5:39 AM, Octavian Rasnita wrote: > Do you have, or can I find elsewhere a recommendation for books,tutorials and sites appropriate for beginners? I have found that Python for Dummies is the book I use the most. It has lots of examples that work and that I can build upon. The O'Reilly books talk about the language but are scarce on actual code. Kee Nethery From invalid at invalid.invalid Tue Dec 7 14:44:17 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 7 Dec 2010 19:44:17 +0000 (UTC) Subject: is py2exe still active ? References: <5f32249f-50d4-440e-9005-04f954572894@32g2000yqz.googlegroups.com> Message-ID: On 2010-12-07, Anders Persson wrote: > When a look att py2exe homepage it is not looking like mutch happen, Why do you say that? The homepage was update last month. If you click on "recent changes" the last wiki page edit was less than two weeks ago, and there ahve been 19 posts to four different threads on the mailing list so far this month. > as a beginner i was thinking to start with Python 3, but i like to > now if py2exe will be for 3 too. > > Is any one have any info ? Probably. https://lists.sourceforge.net/lists/listinfo/py2exe-users -- Grant Edwards grant.b.edwards Yow! Don't SANFORIZE me!! at gmail.com From harijay at gmail.com Tue Dec 7 15:14:26 2010 From: harijay at gmail.com (harijay) Date: Tue, 7 Dec 2010 12:14:26 -0800 (PST) Subject: win32com pythonwin extensions part of stdlib? References: Message-ID: <357d284b-ef2d-4404-a811-59f5f3a148df@o14g2000prn.googlegroups.com> Using the "binary" offered on sourceforge and calling "python setup.py install" Has the install asking for "vcsvarsall.bat" . So this does not seem to be a binary build On Dec 7, 1:27?pm, Ian wrote: > On Dec 7, 11:02?am, harijay wrote: > > > > > > > > > > > Hi I am using Python 2.6.5 on Windows. > > > I wanted to start using the win32com extensions which I understand are > > "essentially part of the stdlib" ( quoted inhttp://tgolden.sc.sabren.com/python/win32_how_do_i.html) > > Since I didnt have the extensions as standard ?I went to sourceforge > > to get the module. > > > However when I tried to do a distutils install of the python > > extensions for windows downloaded from sourceforge , I found out I > > need some proprietary components from Microsoft visual studio > > 7)."vcsvarsall.bat" needed. > > > My question is : Can I use the win32com extensions on a licensed > > windows setup without having access to Visual Studio components. > > > I did see some places where they suggested compiling with mingw32 , > > but the compilation didnt work. > > > Any help in getting the module running would be greatly appreciated > > There are pre-built binary distributions available on sourceforge. > Why not just use one of those? From mail at timgolden.me.uk Tue Dec 7 15:22:49 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 07 Dec 2010 20:22:49 +0000 Subject: win32com pythonwin extensions part of stdlib? In-Reply-To: <357d284b-ef2d-4404-a811-59f5f3a148df@o14g2000prn.googlegroups.com> References: <357d284b-ef2d-4404-a811-59f5f3a148df@o14g2000prn.googlegroups.com> Message-ID: <4CFE9799.9080106@timgolden.me.uk> You want something from here: http://sourceforge.net/projects/pywin32/files/pywin32/Build%20214/ Which one you need will depend on your architecture and the version of Python you're running TJG From python at mrabarnett.plus.com Tue Dec 7 15:42:11 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 07 Dec 2010 20:42:11 +0000 Subject: RCX using python serial help In-Reply-To: References: Message-ID: <4CFE9C23.2060703@mrabarnett.plus.com> On 06/12/2010 15:37, Astan Chee wrote: > Hi, > I've got a lego mindstorm RCX 1.0 (but firmware is 2.0) that uses one of > those old serial IR towers to control the microcontroller. I've had a > look around at python's serial documentation as well as the RCX's > documentation and I'm trying to write something to control the RCX > directly using python. Several examples from of doing this in python > include using lnp (i think) and that doesn't quite run well in windows. > I've had a look at the C++ code and some protocol documentation here: > http://www.generation5.org/content/2001/rob08.asp and converted it to > python. I've attached it at the end of the email. So now I've figured > out how to check for the battery level and it seems to work (I've tested > it on my RCX) but I'm confused with the other documentation (e.g. > http://graphics.stanford.edu/~kekoa/rcx/ ) about how to do this in > python or what this all means. I was wondering if anyone can help me > complete these? or maybe help me do it step-by-step? > Thanks for any help. > Below is the python code I've been working on: > import time > import serial > import struct > import binascii > def tcbin(x, y=8): > """ > This function returns the padded, two's complement representation > of x, in y-bits. > It is conventional for y to be 8, 16, 32 or 64, though y can have > any non-zero positive value. > """ > if x >= 0: > binstr = bin(x) > # pad with leading zeros > while len(binstr) < y + 2: > binstr = "0b0" + binstr[2:] > return binstr > return bin((2**y) + x) # x is negative > def bitcompliment(hex_code): > return hex(int(tcbin(~(ord(hex_code))),2)) > > def processOutput(raw_data,output): > outputStatus = True > pos = 0 > for i in range(3): > if raw_data[i] != output[i]: > outputStatus = False > pos+=1 > if outputStatus: > print "output OK" > else: > print "problem with output" > outputCompliment = True > while outputCompliment: > if hex(ord(output[pos])) == bitcompliment(output[pos+1]): > print "output compliment OK" > else: > print "problem with output compliment" > pos+=2 > if hex(ord(output[pos])) == '0x55' and hex(ord(output[pos+1])) > == '0xff' and hex(ord(output[pos+2])) == '0x0': > pos+=3 > outputCompliment = False > if hex(ord(output[pos])) == '0xcf' or hex(ord(output[pos])) == '0xc7': > #battery checker > pos+=2 > if hex(ord(output[pos])) == bitcompliment(output[pos+1]) and > hex(ord(output[pos+2])) == bitcompliment(output[pos+3]): > s = ((ord(output[pos+2]) * 256) + ord(output[pos])) / 1000.0 > print "Battery is at " + str(s) + " Volts" > else: > for i in range(len(output[pos:]),len(output),2): > print hex(ord(output[i])) > if i+1 < len(output): > if hex(ord(output[i])) == bitcompliment(output[i+1]): > print "message OK. contents: " + hex(ord(output[i])) > > # configure the serial connections (the parameters differs on the device > you are connecting to) > ser = serial.Serial( > port='COM1', > baudrate=2400, > parity=serial.PARITY_ODD, > stopbits=serial.STOPBITS_ONE, > bytesize=serial.EIGHTBITS > ) > raw_data = '\x55\xff\x00\x38\xc7\x38\xc7' > result = ser.write(raw_data) > out = '' > time.sleep(1) #pause for a second > while ser.inWaiting() > 0: > out+=ser.read(1) > processOutput(raw_data,out) > Here's my version of your code: import time import serial import struct import binascii # not needed! def tcbin(x, y=8): """ This function returns the padded, two's complement representation of x, in y-bits. It is conventional for y to be 8, 16, 32 or 64, though y can have any non-zero positive value. """ return "0b" + bin((2 ** y) + x)[-y : ] def byte_complement(hex_code): return (~ord(hex_code)) & 0xff def process_output(raw_data, output): output_status = raw_data[ : 3] == output[ : 3] if output_status: print "output OK" else: print "problem with output" pos = 3 output_complement = True while output_complement: if ord(output[pos]) == byte_complement(output[pos + 1]): print "output complement OK" else: print "problem with output complement" pos += 2 if ord(output[pos]) == 0x55 and ord(output[pos + 1]) == 0xff and ord(output[pos + 2]) == 0x00: pos += 3 output_complement = False if ord(output[pos]) == 0xcf or ord(output[pos]) == 0xc7: # battery checker pos += 2 if ord(output[pos]) == byte_complement(output[pos + 1]) and ord(output[pos + 2]) == byte_complement(output[pos + 3]): s = ((ord(output[pos + 2]) * 256) + ord(output[pos])) / 1000.0 print "Battery is at %s Volts" % s else: for i in range(len(output[pos : ]), len(output), 2): print hex(ord(output[i])) if i + 1 < len(output): if ord(output[i]) == byte_complement(output[i + 1]): print "message OK. contents: %s" % hex(ord(output[i])) # configure the serial connections (the parameters differs on the device you are connecting to) ser = serial.Serial( port='COM1', baudrate=2400, parity=serial.PARITY_ODD, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS ) raw_data = '\x55\xff\x00\x38\xc7\x38\xc7' result = ser.write(raw_data) out = '' time.sleep(1) # pause for a second while ser.inWaiting() > 0: out += ser.read(1) process_output(raw_data, out) From harijay at gmail.com Tue Dec 7 15:59:31 2010 From: harijay at gmail.com (harijay) Date: Tue, 7 Dec 2010 12:59:31 -0800 (PST) Subject: win32com pythonwin extensions part of stdlib? References: <357d284b-ef2d-4404-a811-59f5f3a148df@o14g2000prn.googlegroups.com> Message-ID: <6f9358ed-dd54-435f-aa65-0eab84dbf147@h17g2000pre.googlegroups.com> Thanks Ian for your reply. I downloaded the zip file linked by the "Download Binaries/View All files link" . All that gave me was a zip file which unpacked to the source and documentation implying I had to use distutils. If instead I looked at the Build 214 link on sourceforge which corresponds to the latest build ( same time stamp as the link labeled "Download Binaries / View all Files") There was an exe file corresponding to my python version. Which came with an installer that installed the binaries Thanks for your help I looked in the right place. Hari On Dec 7, 3:14?pm, harijay wrote: > Using the "binary" offered on sourceforge and calling > "python setup.py install" > > Has the install asking for "vcsvarsall.bat" . So this does not seem to > be a binary build > > On Dec 7, 1:27?pm, Ian wrote: > > > > > > > > > On Dec 7, 11:02?am, harijay wrote: > > > > Hi I am using Python 2.6.5 on Windows. > > > > I wanted to start using the win32com extensions which I understand are > > > "essentially part of the stdlib" ( quoted inhttp://tgolden.sc.sabren.com/python/win32_how_do_i.html) > > > Since I didnt have the extensions as standard ?I went to sourceforge > > > to get the module. > > > > However when I tried to do a distutils install of the python > > > extensions for windows downloaded from sourceforge , I found out I > > > need some proprietary components from Microsoft visual studio > > > 7)."vcsvarsall.bat" needed. > > > > My question is : Can I use the win32com extensions on a licensed > > > windows setup without having access to Visual Studio components. > > > > I did see some places where they suggested compiling with mingw32 , > > > but the compilation didnt work. > > > > Any help in getting the module running would be greatly appreciated > > > There are pre-built binary distributions available on sourceforge. > > Why not just use one of those? From harijay at gmail.com Tue Dec 7 16:01:52 2010 From: harijay at gmail.com (harijay) Date: Tue, 7 Dec 2010 13:01:52 -0800 (PST) Subject: win32com pythonwin extensions part of stdlib? References: <357d284b-ef2d-4404-a811-59f5f3a148df@o14g2000prn.googlegroups.com> Message-ID: Thanks Tim for your reply. I did get that build . Also thanks for the examples. Looking forward to using the module Hari On Dec 7, 3:22?pm, Tim Golden wrote: > You want something from here: > > ? ?http://sourceforge.net/projects/pywin32/files/pywin32/Build%20214/ > > Which one you need will depend on your architecture > and the version of Python you're running > > TJG From utabintarbo at gmail.com Tue Dec 7 16:03:40 2010 From: utabintarbo at gmail.com (utabintarbo) Date: Tue, 7 Dec 2010 13:03:40 -0800 (PST) Subject: Python creates "locked" temp dir Message-ID: <0c30c818-f73b-4b09-b707-64ea457c757d@z26g2000prf.googlegroups.com> I am using tempfile.mkdtemp() to create a working directory on a remote *nix system through a Samba share. When I use this on a Windows box, it works, and I have full access to the created dir. When used on a Linux box (through the same Samba share), the created directory shows as "locked", and I am unable to access. Obviously, I need access. Any clues? Background/environment: Python 2.6.5 on Red Hat Enterprise Linux 5.3 TIA From shearichard at gmail.com Tue Dec 7 16:45:23 2010 From: shearichard at gmail.com (shearichard) Date: Tue, 7 Dec 2010 13:45:23 -0800 (PST) Subject: find memory leaks in running program References: Message-ID: <6b8a92f4-5de9-47e1-90ce-a79d994e0664@y19g2000prb.googlegroups.com> On Dec 8, 5:51?am, Marco Hornung wrote: > Hey, > > ------------------------------------------------------------------------------------------ > questions > ------------------------------------------------------------------------------------------ > 1. What are the best tools to analyze pythons memory stack, while it is running? > 2. Is there a possibility to analyze the memory stack of a program with external programs? (without to change the source code - I am only interested in the object size) > 3. Can I sort of "break" into the memory to see what objects consume how much memory? > > ------------------------------------------------------------------------------------------ > my scenario > ------------------------------------------------------------------------------------------ > I have to debug a multithreaded server, which is written in the twisted-framework. One of the processes has some sort of memory leak - After one of our jobs is finished the main process has still over 59% of the entire memory allocated. I will probably have to recreate our scenario and equip our server with some memory sensors - but ?it takes 12h to reproduce the scenario and I will have to change the source code(at least I do not know of other options). > Therefore I am looking for quicker possibilities to look into what causes our memory leak. > > Regards, > Marco I haven't used this myself but sometime ago I bookmarked yappi which may go some way towards helping you ... http://code.google.com/p/yappi/ http://code.google.com/p/yappi/wiki/apiyappi ... also sometime ago I was at presentation (Pycon NZ 2009) where the twisted.manhole functionality was used to hook a remote console up to a running twisted task and examine the interior of the target task. Can't remember the details but someone else here may be able to help. This touches upon the idea ... http://stackoverflow.com/questions/1721699/is-there-any-remote-console-for-twisted-server ... and in turn references Heapy which I'd forgotten about but may also be useful in your circs ... http://guppy-pe.sourceforge.net/ regards Richard. From horos11 at gmail.com Tue Dec 7 17:21:18 2010 From: horos11 at gmail.com (Edward Peschko) Date: Tue, 7 Dec 2010 14:21:18 -0800 Subject: using trace to do 'in place' evaluation of variables Message-ID: All, I've been using the trace module for python (as per http://www.dalkescientific.com/writings/diary/archive/2005/04/20/tracing_python_code.html), and would very much like to have a feature there that I've implemented for perl already. Namely, I would like output in the format as described on that page, but with the ability to have the running window partitioned into 2, like: /tmp/file.py:13: yy = 12 | = 12 /tmp/file.py14: xx = yy | = 12 where the window on the left shows the actual source code, and the right shows how that code eval's (ie: how the scalars resolve based on their current scope.) Is this possible given the current trace functionality? I've found it an *incredible* time saver with my perl code, especially for hard to find data bugs - to debug I simply look for a pattern which is associated with a given bug, and then backtrack that pattern to where it first appeared in my code. Also, is there a good archive searcher for the python-list archives? Short of doing a complete download of http://mail.python.org/pipermail/python-list/ and indexing it, I don't see how I can do a decent pattern search on previous archive entries.. Thanks much, Ed From mmanns at gmx.net Tue Dec 7 17:47:16 2010 From: mmanns at gmx.net (Martin Manns) Date: Tue, 7 Dec 2010 23:47:16 +0100 Subject: Collision of rotated rectangles without pygame References: <20101205234936.39dc1a4e@Knock> <4cfdf605$0$1639$742ec2ed@news.sonic.net> Message-ID: <20101207234716.4587ef12@Knock> On Tue, 07 Dec 2010 00:53:27 -0800 John Nagle wrote: > On 12/5/2010 2:49 PM, Martin Manns wrote: > Probably because you seem to be trying to compute the intersection > point for coincident lines, which is not well-defined. I found the problem: pygame returns one pixel more for the right border than wx. > Incidentally, a dictionary lookup in Python is far more expensive > than computing trig functions. If you need to speed this up > for large numbers of rectangles, there are algorithms that are > several orders of magnitude faster. Realistically, though, > this is the kind of problem that runs slow in CPython. This was taken from the vizier code. I fixed it. > This is why you don't write your own collision library. > (I once did, for 3D, but that was in 1996, when it was > cutting-edge technology.) Is there a pure Python collision library other than vizier? Martin From steve at holdenweb.com Tue Dec 7 17:56:46 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 07 Dec 2010 23:56:46 +0100 Subject: is py2exe still active ? In-Reply-To: <2DEA78DF996B485E8B52F3B29B1124A1@teddy> References: <5f32249f-50d4-440e-9005-04f954572894@32g2000yqz.googlegroups.com> <89dd2092-d6e9-4d5c-b966-54df3f48f065@g19g2000yqg.googlegroups.com> <2DEA78DF996B485E8B52F3B29B1124A1@teddy> Message-ID: <4CFEBBAE.2060400@holdenweb.com> Octavian: It's great that you want to let people know about bugs. Put yourself in the position of the package maintainer, however. She or he doesn't spend all day working on cxFreeze, and probably doesn't even do a Google search on cxFreeze very often. So they are unlikely to find out about this problem form your well-intentioned note. It's just possible nobody does care, as I can't find a link to an issue tracker - the best I could advise in this case would be to join the mailing list by visiting https://lists.sourceforge.net/lists/listinfo/cx-freeze-users regards Steve On 12/7/2010 6:49 PM, Octavian Rasnita wrote: > This packager is also nice. > > If someone cares, I've discovered a small bug in it. > If Python is installed on another drive than C under Windows, the cxfreeze.bat file still calls Python on the drive C and it doesn't work until it is corrected. > > Octavian > > ----- Original Message ----- > From: "Cbast" > Newsgroups: comp.lang.python > To: > Sent: Tuesday, December 07, 2010 5:00 PM > Subject: Re: is py2exe still active ? > > > On Dec 7, 8:23 am, Anders Persson wrote: >> Hi! >> When a look att py2exe homepage it is not looking like mutch happen, >> as a beginner i was thinking to start with Python 3, but i like to now >> if py2exe will be for 3 too. >> >> Is any one have any info ? > > I don't have the answer about py2exe, but I'm using cxFreeze to create > executables with Python 3.1, if it's what you're looking for. > > http://cx-freeze.sourceforge.net/ -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Tue Dec 7 17:56:46 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 07 Dec 2010 23:56:46 +0100 Subject: is py2exe still active ? In-Reply-To: <2DEA78DF996B485E8B52F3B29B1124A1@teddy> References: <5f32249f-50d4-440e-9005-04f954572894@32g2000yqz.googlegroups.com> <89dd2092-d6e9-4d5c-b966-54df3f48f065@g19g2000yqg.googlegroups.com> <2DEA78DF996B485E8B52F3B29B1124A1@teddy> Message-ID: <4CFEBBAE.2060400@holdenweb.com> Octavian: It's great that you want to let people know about bugs. Put yourself in the position of the package maintainer, however. She or he doesn't spend all day working on cxFreeze, and probably doesn't even do a Google search on cxFreeze very often. So they are unlikely to find out about this problem form your well-intentioned note. It's just possible nobody does care, as I can't find a link to an issue tracker - the best I could advise in this case would be to join the mailing list by visiting https://lists.sourceforge.net/lists/listinfo/cx-freeze-users regards Steve On 12/7/2010 6:49 PM, Octavian Rasnita wrote: > This packager is also nice. > > If someone cares, I've discovered a small bug in it. > If Python is installed on another drive than C under Windows, the cxfreeze.bat file still calls Python on the drive C and it doesn't work until it is corrected. > > Octavian > > ----- Original Message ----- > From: "Cbast" > Newsgroups: comp.lang.python > To: > Sent: Tuesday, December 07, 2010 5:00 PM > Subject: Re: is py2exe still active ? > > > On Dec 7, 8:23 am, Anders Persson wrote: >> Hi! >> When a look att py2exe homepage it is not looking like mutch happen, >> as a beginner i was thinking to start with Python 3, but i like to now >> if py2exe will be for 3 too. >> >> Is any one have any info ? > > I don't have the answer about py2exe, but I'm using cxFreeze to create > executables with Python 3.1, if it's what you're looking for. > > http://cx-freeze.sourceforge.net/ -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From nagle at animats.com Tue Dec 7 18:08:23 2010 From: nagle at animats.com (John Nagle) Date: Tue, 07 Dec 2010 15:08:23 -0800 Subject: Comparisons of incompatible types In-Reply-To: <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cfebe65$0$1590$742ec2ed@news.sonic.net> On 12/6/2010 4:17 PM, Steven D'Aprano wrote: > On Mon, 06 Dec 2010 08:59:12 -0800, TomF wrote: > >> I'm aggravated by this behavior in python: >> >> x = "4" >> print x< 7 # prints False > >> I can't imagine why this design decision was made. > > You've never needed to deal with an heterogeneous list? > > data = ["Fred", "Barney", 2, 1, None] > data.sort() > > Nevertheless, I agree that in hindsight, the ability to sort such lists > is not as important as the consistency of comparisons. If you're thinking hard about this, I recommend viewing Alexander Stepanov's talk at Stanford last month: http://www.stanford.edu/class/ee380/Abstracts/101103.html He makes the point that, for generic programs to work right, the basic operations must have certain well-defined semantics. Then the same algorithms will work right across a wide variety of objects. This is consistent with Python's "duck typing", but inconsistent with the current semantics of some operators. For example, "+" as concatenation makes "+" non-commutative. In other words, a + b is not always equal to b + a which is not good. Important properties to have across all types: a + b == b + a Exactly one of a > b a = b a < b is true, or an type exception must be raised. The basic Boolean identities (a or b) == (b or a) not (a or b) == (not a) and (not b) not (not a) == a should all hold, or an type exception should be raised. With Python accepting both "True" and "1" as sort of equivalent, there are cases where those don't hold. John Nagle From steve at holdenweb.com Tue Dec 7 18:11:09 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 08 Dec 2010 00:11:09 +0100 Subject: Collision of rotated rectangles without pygame In-Reply-To: <4cfdf605$0$1639$742ec2ed@news.sonic.net> References: <20101205234936.39dc1a4e@Knock> <4cfdf605$0$1639$742ec2ed@news.sonic.net> Message-ID: On 12/7/2010 9:53 AM, John Nagle wrote: > On 12/5/2010 2:49 PM, Martin Manns wrote: >> Hello, >> >> I am looking for a Python library for 2D collision checks of rotated >> rectangles. Currently, I have found vizier 0.5b that is based on pygame. >> >> Since I do not want to add a pygame dependency to my app, I replaced the >> pygame.rect.Rect by a wxPython wx.Rect (see code below). >> >> However, collision checks do not work correctly, i. e. identical rects >> are not found to be colliding: > > Probably because you seem to be trying to compute the intersection > point for coincident lines, which is not well-defined. > > I don't have time to debug this, but you might want to get some > basic books on game programming and graphics. > > Incidentally, a dictionary lookup in Python is far more expensive > than computing trig functions. If you need to speed this up > for large numbers of rectangles, there are algorithms that are > several orders of magnitude faster. Realistically, though, > this is the kind of problem that runs slow in CPython. > That appears to be (from a rather limited investigation) a wild-assed assertion unjustified by anything other than preconceptions. With d as a dict containing 100 random numbers from (0,1) I see this: >>> def fm(): ... x = random.random() ... return math.sin(x) ... >>> def fd(): ... x = random.random() ... return x in d ... >>> timeit.timeit(fm) 0.58099985122680664 >>> timeit.timeit(fd) 0.55200004577636719 >>> Of course it's possible that the random number generation is dominating, but I'd still like to see some proof. I know for a fact that dict lookup has been extensively optimized, and while I am no longer involved in numerical computing it seems to me there's still a lot to do to compute a sin unless your CPU will do it for you. regards Steve > This is why you don't write your own collision library. > (I once did, for 3D, but that was in 1996, when it was > cutting-edge technology.) > > John Nagle -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From pavlovevidence at gmail.com Tue Dec 7 18:20:01 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 7 Dec 2010 15:20:01 -0800 (PST) Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Dec 6, 4:17?pm, Steven D'Aprano wrote: > On Mon, 06 Dec 2010 08:59:12 -0800, TomF wrote: > > I'm aggravated by this behavior in python: > > > x = "4" > > print x < 7 ? ?# prints False > > I can't imagine why this design decision was made. > > You've never needed to deal with an heterogeneous list? > > data = ["Fred", "Barney", 2, 1, None] > data.sort() Not once, ever. > Nevertheless, I agree that in hindsight, the ability to sort such lists > is not as important as the consistency of comparisons. I think that feeling the need to sort non-homogenous lists is indictative of bad design. If the order of the items doesn't matter, then there must be some small bit of homogeneity to exploit to use as a sort criterion. In that case you should use key= parameter or DSU. Carl Banks From pavlovevidence at gmail.com Tue Dec 7 18:31:53 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 7 Dec 2010 15:31:53 -0800 (PST) Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <4cfebe65$0$1590$742ec2ed@news.sonic.net> Message-ID: On Dec 7, 3:08?pm, John Nagle wrote: > The basic Boolean identities > > ? ? ? ? (a or b) == (b or a) > ? ? ? ? not (a or b) == (not a) and (not b) > ? ? ? ? not (not a) == a > > should all hold, or an type exception should be raised. > With Python accepting both "True" and "1" as sort of > equivalent, there are cases where those don't hold. For better or worse (and I say worse, but YMMV) "and" and "or" are not boolean operators in Python but special-form expressions that resemble boolean semantics in some instances, but not (as you mention above) in others. Likewise, the comparison operators <, >, >=, and <= aren't well- ordered; sets use these operators to indicate topological ordering. IMO having the operators adhere to defined properties would be a good thing. It would improve code reusability since the operators could be expected to act in consistent ways, but Python isn't that language. So you might as well use the operators for whatever seems like it works, + for concatenation, > for superset, and so on. Carl Banks From python at mrabarnett.plus.com Tue Dec 7 18:46:51 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 07 Dec 2010 23:46:51 +0000 Subject: RCX using python serial help In-Reply-To: References: Message-ID: <4CFEC76B.9080503@mrabarnett.plus.com> On 06/12/2010 15:37, Astan Chee wrote: > Hi, > I've got a lego mindstorm RCX 1.0 (but firmware is 2.0) that uses one of > those old serial IR towers to control the microcontroller. I've had a > look around at python's serial documentation as well as the RCX's > documentation and I'm trying to write something to control the RCX > directly using python. Several examples from of doing this in python > include using lnp (i think) and that doesn't quite run well in windows. > I've had a look at the C++ code and some protocol documentation here: > http://www.generation5.org/content/2001/rob08.asp and converted it to > python. I've attached it at the end of the email. So now I've figured > out how to check for the battery level and it seems to work (I've tested > it on my RCX) but I'm confused with the other documentation (e.g. > http://graphics.stanford.edu/~kekoa/rcx/ ) about how to do this in > python or what this all means. I was wondering if anyone can help me > complete these? or maybe help me do it step-by-step? > Thanks for any help. [snip] Here's a brief summary of the protocol: A command or request to the microcontroller is a packet consisting of a header, an opcode, arguments, and a checksum. The header used in the documentation is 0x55, 0xFF, 0x00. The opcode is 1 byte, followed by its one's complement. The argument is 0 or more bytes, each followed by its one's complement. The checksum is the sum of the opcode and the arguments, modulo 256, followed by its one's complement. A reply from the microcontroller is also a packet consisting of a header, an opcode, arguments, and a checksum. The header is the same as the original command or request. The opcode is the one's complement of the original opcode, followed by its one's complement (ie, the original opcode). The argument is 0 or more bytes, each followed by its one's complement. The checksum is the sum of the opcode and the arguments, modulo 256, followed by its one's complement. The microcontroller will ignore a packet whose opcode is the same as the previous one; this is to prevent unintended duplicates due to communication errors. Each opcode has 2 alternatives, one with bit 3 clear and the other with bit 3 set (bitwise-ored with 0x08), so if you do want to send a command or request with the same opcode as the previous packet you can just use the alternative form. From steve at holdenweb.com Tue Dec 7 18:47:37 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 08 Dec 2010 00:47:37 +0100 Subject: Perceived inconsistency in py3k documentation In-Reply-To: <20101206200017.0c5fc63f@pitrou.net> References: <724b26b4-8233-4d57-b76f-cd781cf0cd03@z17g2000prz.googlegroups.com> <20101206200017.0c5fc63f@pitrou.net> Message-ID: <4CFEC799.50102@holdenweb.com> On 12/6/2010 8:00 PM, Antoine Pitrou wrote: > On Sun, 05 Dec 2010 14:47:38 -0500 > Terry Reedy wrote: >> On 12/5/2010 3:31 AM, Greg wrote: >> >> For future reference, >> >>> 1) At http://docs.python.org/py3k/reference/datamodel.html: >>> 2) At http://docs.python.org/py3k/library/stdtypes.html: >> >> do not work because of the trailing :s, at least not with FireFox. > > Work fine here. The problem isn't Firefox, it is your e-mail or news > client. > > Antoine. > > In my case also the links don't work, because my newsreader (Thunderbird) makes the assumption that the colons are part of the URLs. This behavior is common enough that people need to be aware of it. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Tue Dec 7 18:47:37 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 08 Dec 2010 00:47:37 +0100 Subject: Perceived inconsistency in py3k documentation In-Reply-To: <20101206200017.0c5fc63f@pitrou.net> References: <724b26b4-8233-4d57-b76f-cd781cf0cd03@z17g2000prz.googlegroups.com> <20101206200017.0c5fc63f@pitrou.net> Message-ID: <4CFEC799.50102@holdenweb.com> On 12/6/2010 8:00 PM, Antoine Pitrou wrote: > On Sun, 05 Dec 2010 14:47:38 -0500 > Terry Reedy wrote: >> On 12/5/2010 3:31 AM, Greg wrote: >> >> For future reference, >> >>> 1) At http://docs.python.org/py3k/reference/datamodel.html: >>> 2) At http://docs.python.org/py3k/library/stdtypes.html: >> >> do not work because of the trailing :s, at least not with FireFox. > > Work fine here. The problem isn't Firefox, it is your e-mail or news > client. > > Antoine. > > In my case also the links don't work, because my newsreader (Thunderbird) makes the assumption that the colons are part of the URLs. This behavior is common enough that people need to be aware of it. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Tue Dec 7 18:56:29 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 08 Dec 2010 00:56:29 +0100 Subject: Exception handling in Python 3.x In-Reply-To: <4cfdbf06$0$1629$742ec2ed@news.sonic.net> References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> <4cfd4d5a$0$1662$742ec2ed@news.sonic.net> <878w02leut.fsf.mdw@metalzone.distorted.org.uk> <4cfdbf06$0$1629$742ec2ed@news.sonic.net> Message-ID: On 12/7/2010 5:58 AM, John Nagle wrote: > PEP 255, like too much Python literature, doesn't distinguish clearly > between the language definition and implementation detail. It says > "The mechanics of StopIteration are low-level details, much like the > mechanics of IndexError in Python 2.1". Applications shouldn't be > explicitly using StopIteration. > So you don't think that we should rely on iterables with no __iter__() method to raise IndexError to terminate iterations when their __getitem__() is called with an invalid index? The IndexError mechanism was, to the best of my less-than-complete knowledge, used by all pre-2.2 implementations. The quoted paragraph appears to be intended to reassure the applications programmer that there is no normal need to handle StopIteration specially - just as there was no need to handle IndexError specially. > IronPython doesn't do StopIteration the same way CPython does. > > http://ironpython.codeplex.com/wikipage?title=IPy1.0.xCPyDifferences > Perhaps not, but the only difference is what happens on repeated calls to next() after the iterator is exhausted. The iterator still terminates by raising a StopIteration error. I have no idea what Shed Skin does, but to the extent that iterators don't raise StopIteration on exhaustion I'd say it is in error. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Tue Dec 7 18:58:06 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 08 Dec 2010 00:58:06 +0100 Subject: Exception handling in Python 3.x In-Reply-To: <4CFD845E.90007@mrabarnett.plus.com> References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> <7xmxoi8v0b.fsf@ruckus.brouhaha.com> <4cfd7e6a$0$29993$c3e8da3$5496439d@news.astraweb.com> <4CFD845E.90007@mrabarnett.plus.com> Message-ID: <4CFECA0E.4050105@holdenweb.com> On 12/7/2010 1:48 AM, MRAB wrote: > Perhaps Python could use Guido's time machine to check whether the > sequence will yield another object in the future. :-) Since there's only one time machine that would effectively be a lock across all Python interpreters. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Tue Dec 7 18:58:06 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 08 Dec 2010 00:58:06 +0100 Subject: Exception handling in Python 3.x In-Reply-To: <4CFD845E.90007@mrabarnett.plus.com> References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> <7xmxoi8v0b.fsf@ruckus.brouhaha.com> <4cfd7e6a$0$29993$c3e8da3$5496439d@news.astraweb.com> <4CFD845E.90007@mrabarnett.plus.com> Message-ID: <4CFECA0E.4050105@holdenweb.com> On 12/7/2010 1:48 AM, MRAB wrote: > Perhaps Python could use Guido's time machine to check whether the > sequence will yield another object in the future. :-) Since there's only one time machine that would effectively be a lock across all Python interpreters. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From mdw at distorted.org.uk Tue Dec 7 18:59:54 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 07 Dec 2010 23:59:54 +0000 Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <4cfebe65$0$1590$742ec2ed@news.sonic.net> Message-ID: <87ipz5jfr9.fsf.mdw@metalzone.distorted.org.uk> John Nagle writes: [Stepanov] > makes the point that, for generic programs to work right, the basic > operations must have certain well-defined semantics. Then the same > algorithms will work right across a wide variety of objects. > > This is consistent with Python's "duck typing", but inconsistent with > the current semantics of some operators. This isn't a disaster. You should check that the arguments define the necessary operations and obey the necessary axioms. Python is already dynamically typed: this kind of proof-obligation is already endemic in Python programming, so you've not lost anything significant. > For example, "+" as concatenation makes "+" non-commutative. In other > words, > > a + b > > is not always equal to > > b + a > > which is not good. I think I probably agree with this. Concatenation yields a nonabelian monoid (usually with identity); `+' is pretty much universally an abelian group operator (exception: natural numbers, where it's used in an abelian monoid which extends to a group in a relatively obvious way). But then we'd need another operator symbol for concatenation. Nonnegative integers act on strings properly, but the action doesn't distribute over concatenation, which is also a shame. i.e., n*(a + b) != n*a + n*b But it's a familiar notation, by no means peculiar to Python, and changing it would be difficult. > Exactly one of > > a > b > a = b > a < b > > is true, or an type exception must be raised. This will get the numerical people screaming. Non-signalling NaNs are useful, and they don't obey these axioms. I think, more generally, that requiring a full total order (rather than either a preorder or a partial order) is unnecessarily proscriptive. Sorting only requires a preorder, for example, i.e., { (a, b) | a <= b <= a } is an equivalence relation, and the preorder naturally induces a total order on the equivalence classes. Topological sorting requires only a partial order, and makes good use of the notation. As an example, sets use `<=' to denote subsetness, which is well known to be a partial order. (I presume you weren't going to deny a <= b iff a < b or a == b or a < b iff b > a because that really would be bad.) > The basic Boolean identities > > (a or b) == (b or a) > not (a or b) == (not a) and (not b) > not (not a) == a > > should all hold, or an type exception should be raised. The first of these contradicts the axiom x => x or _|_ == x which is probably more useful. The last can't usefully be true since `not' is lossy. But I think that, for all values a, b, not (a or b) == not (b or a) == (not a) and (not b) not (not (not a)) == not a which is probably good enough. (The application of `not' applies a boolean coercion, which canonifies adequately.) -- [mdw] From mdw at distorted.org.uk Tue Dec 7 19:09:17 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 08 Dec 2010 00:09:17 +0000 Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87ei9tjfbm.fsf.mdw@metalzone.distorted.org.uk> Carl Banks writes: > I think that feeling the need to sort non-homogenous lists is > indictative of bad design. Here's a reason you might want to. You're given an object, and you want to compute a hash of it. (Maybe you want to see whether someone else's object is the same as yours, but don't want to disclose the actual object, say.) To hash it, you'll need to serialize it somehow. But here's a problem: objects like dictionaries and sets don't impose an ordering on their elements. For example, the set { 1, 'two' } is the same as the set { 'two', 1 } -- but iterating the two might well yield the elements in a different order. (The internal details of a hash table tend to reflect the history of operations on the hash table as well as its current contents.) The obvious answer is to apply a canonical ordering to unordered objects like sets and dictionaries. A set can be serialized with its elements in ascending order; a dictionary can be serialized as key/value pairs with the keys in ascending order. But to do this, you need an (arbitrary, total) order on all objects which might be set elements or dictionary keys. The order also needs to be dependent only on the objects' serializable values, and not on any incidental facts such as memory addresses or whatever. -- [mdw] From ben+python at benfinney.id.au Tue Dec 7 19:58:03 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 08 Dec 2010 11:58:03 +1100 Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <871v5t13ok.fsf@benfinney.id.au> Carl Banks writes: > On Dec 6, 4:17?pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: > > Nevertheless, I agree that in hindsight, the ability to sort such > > lists is not as important as the consistency of comparisons. > > I think that feeling the need to sort non-homogenous lists is > indictative of bad design. It can also be indicative of code written for a Python that doesn't have sets. Comparing two list objects to see whether they have the same items in any sequence can be done with:: set(foolist) == set(barlist) but, if there is no ?set? type, it's fine to write:: sorted(foolist) == sorted(barlist) So there's no design error in wanting heterogenerous sequences to sort; it can be quite Pythonic (until the advent of the ?set? type). And, of course, that code needs to continue to work in Python 2.x; hence, the comparison of incompatible types cannot be fixed without breaking backward compatibility. Hence it's not fixed until Python 3.x. -- \ ?All opinions are not equal. Some are a very great deal more | `\ robust, sophisticated and well supported in logic and argument | _o__) than others.? ?Douglas Adams | Ben Finney From no.email at nospam.invalid Tue Dec 7 20:04:28 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 07 Dec 2010 17:04:28 -0800 Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <871v5t13ok.fsf@benfinney.id.au> Message-ID: <7xpqtdrs6b.fsf@ruckus.brouhaha.com> Ben Finney writes: > but, if there is no ?set? type, it's fine to write:: > sorted(foolist) == sorted(barlist) what about dictionaries? From ben+python at benfinney.id.au Tue Dec 7 20:11:33 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 08 Dec 2010 12:11:33 +1100 Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <871v5t13ok.fsf@benfinney.id.au> <7xpqtdrs6b.fsf@ruckus.brouhaha.com> Message-ID: <87wrnlysoq.fsf@benfinney.id.au> Paul Rubin writes: > Ben Finney writes: > > but, if there is no ?set? type, it's fine to write:: > > sorted(foolist) == sorted(barlist) > > what about dictionaries? Creating a needless dict for each list would make the code even less clear, I'd think. (We're talking here about design, which is why clarity of communicating semantic intent is a concern.) Of course, the ?set? type is an even clearer way of communicating the intent; so, the above doesn't need to work in Python 3, which can break code written before the advent of the ?set? type. -- \ ?But Marge, what if we chose the wrong religion? Each week we | `\ just make God madder and madder.? ?Homer, _The Simpsons_ | _o__) | Ben Finney From bc at freeuk.com Tue Dec 7 20:24:48 2010 From: bc at freeuk.com (BartC) Date: Wed, 8 Dec 2010 01:24:48 -0000 Subject: Comparisons of incompatible types In-Reply-To: References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: "Carl Banks" wrote in message news:bf4be9a7-a079-4454-9969-60e9be305a03 at k14g2000pre.googlegroups.com... > On Dec 6, 4:17 pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> On Mon, 06 Dec 2010 08:59:12 -0800, TomF wrote: >> > I'm aggravated by this behavior in python: >> >> > x = "4" >> > print x < 7 # prints False >> > I can't imagine why this design decision was made. >> >> You've never needed to deal with an heterogeneous list? >> >> data = ["Fred", "Barney", 2, 1, None] >> data.sort() > > Not once, ever. > > >> Nevertheless, I agree that in hindsight, the ability to sort such lists >> is not as important as the consistency of comparisons. > > I think that feeling the need to sort non-homogenous lists is > indictative of bad design. Using a simple "<" comparison, perhaps. But can't a list be sorted by other criteria? For example, by comparing the string representations of each element. So some sorts will make sense, and others (such as "<" or ">") won't. -- Bartc From horos11 at gmail.com Tue Dec 7 20:49:59 2010 From: horos11 at gmail.com (Edward Peschko) Date: Tue, 7 Dec 2010 17:49:59 -0800 Subject: completely implicit interpolation based on a frame object Message-ID: All, Ok, it looks like in order to implement a tracer that does interpolation, I'm going to have to hack around with frames. Perl's interpolation is fairly straightforward, to do interpolation of $a == 1 all you need to do is put quotes around "$a == 1" to have $a evaluated. So, I'd like to do the same thing with python. It looks like I can do the same thing with frames, ie: interpolate_frame(frame, "if not wx.Platform == '__WXMAC' ") would interpolate wx based off of the frame that you passed to interpolate_frame, because wx is in the f_locals or f_globals dictionary. Hence, this would become: loc_wx = _first_defined(frame.f_locals["wx"], frame.f_globals["wx"]) return "if not ", loc_wx.Platform , " == \"__WXMAC\"" which would then do the interpolation. I guess my question is - has something like this been released? I see some close hits, namely Evan Forsmark's http://www.evanfosmark.com/2008/06/string-interpolation-in-python/ but I don't see anything exact, and getting this right would be fairly tricky, so I was hoping for canned solution. Any ideas would be great on this, including pitfalls that people see in implementing it. Ed From lanyjie at yahoo.com Tue Dec 7 21:23:10 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Tue, 7 Dec 2010 18:23:10 -0800 (PST) Subject: group 0 in the re module Message-ID: <194828.16515.qm@web54205.mail.re2.yahoo.com> Hi, According to the doc, group(0) is the entire match. >>> m = re.match(r"(\w+) (\w+)", "Isaac Newton, physicist") >>> m.group(0) # The entire match 'Isaac Newton' But if you do this: >>> import re >>> re.sub(r'(\d{3})(\d{3})', r'\0 to \1-\2', '757234') '\x00 to 757-234' where I expected '757234 to 757-234' Then I found that in python re '\0' is considered an octal number. So, is there anyway to refer to the entire match by an escaped notation? Thanks, Yingjie From tobias.koeck at gmail.com Tue Dec 7 21:36:25 2010 From: tobias.koeck at gmail.com (joblack) Date: Tue, 7 Dec 2010 18:36:25 -0800 (PST) Subject: convert assembly data (double words and bytes) in two tupple Message-ID: <1d2585a4-a023-4676-8743-a4998eacb41f@c17g2000prm.googlegroups.com> I have two assembly data txt files, one has the structure: 0E1459D1Fh, 0AB58FAAEh, 4303E35Bh, 55FA3020h, 0E66D76ADh, 0EF434544h, ... and the other has the structure: 53h, 6, 6Bh, 0D4h, 40h, 35h, 0B5h, 33h, 0AFh, 30h, 0B3h, 66h, ... (I removed the dd and db with awk) Now I want both of them in a tupple (like map1 = ( ... ) and map2 = ( ...) in my source code so I can index them.. Any idea how to give python a hint that the h at the end of the number means it's a hex number? Or do I have to torture myself with regex to get it right? From python at mrabarnett.plus.com Tue Dec 7 21:45:30 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 08 Dec 2010 02:45:30 +0000 Subject: group 0 in the re module In-Reply-To: <194828.16515.qm@web54205.mail.re2.yahoo.com> References: <194828.16515.qm@web54205.mail.re2.yahoo.com> Message-ID: <4CFEF14A.4080004@mrabarnett.plus.com> On 08/12/2010 02:23, Yingjie Lan wrote: > Hi, > > According to the doc, group(0) is the entire match. > >>>> m = re.match(r"(\w+) (\w+)", "Isaac Newton, physicist") >>>> m.group(0) # The entire match 'Isaac Newton' > > But if you do this: >>>> import re >>>> re.sub(r'(\d{3})(\d{3})', r'\0 to \1-\2', '757234') > '\x00 to 757-234' > > where I expected > '757234 to 757-234' > > Then I found that in python re '\0' is considered an octal number. > So, is there anyway to refer to the entire match by an escaped > notation? > Use \g<0>. This notation works in the replacement template for both named and numbered groups: >>> re.sub(r'(\d{3})(\d{3})', r'\g<0> to \g<1>-\g<2>', '757234') '757234 to 757-234' >>> re.sub(r'(?P\d{3})(?P\d{3})', r'\g<0> to \g-\g', '757234') '757234 to 757-234' From clp2 at rebertia.com Tue Dec 7 21:46:57 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 7 Dec 2010 18:46:57 -0800 Subject: convert assembly data (double words and bytes) in two tupple In-Reply-To: <1d2585a4-a023-4676-8743-a4998eacb41f@c17g2000prm.googlegroups.com> References: <1d2585a4-a023-4676-8743-a4998eacb41f@c17g2000prm.googlegroups.com> Message-ID: On Tue, Dec 7, 2010 at 6:36 PM, joblack wrote: > I have two assembly data txt files, one has the structure: > > 0E1459D1Fh, 0AB58FAAEh, 4303E35Bh, 55FA3020h, 0E66D76ADh, > 0EF434544h, ... > > and the other has the structure: > > 53h, 6, 6Bh, 0D4h, 40h, 35h, 0B5h, 33h, 0AFh, 30h, 0B3h, > 66h, ... > > (I removed the dd and db with awk) > > Now I want both of them in a tupple (like map1 = ( ... ) and map2 = > ( ...) in my source code so I can index them.. > > Any idea how to give python a hint that the h at the end of the number > means it's a hex number? Or do I have to torture myself with regex to > get it right? No regex necessary whatsoever: # will be inefficient if file is huge f = open("path/to/assembly/file/1") content = f.read() f.close() map1 = [int(hexnum[:-1], 16) for hexnum content.split(", ")] # do same thing for 2nd file Cheers, Chris -- http://blog.rebertia.com From ian.g.kelly at gmail.com Tue Dec 7 21:51:01 2010 From: ian.g.kelly at gmail.com (Ian) Date: Tue, 7 Dec 2010 18:51:01 -0800 (PST) Subject: Collision of rotated rectangles without pygame References: <20101205234936.39dc1a4e@Knock> <4cfdf605$0$1639$742ec2ed@news.sonic.net> Message-ID: <48036888-7df2-44fb-924c-7b2d86a4d16c@c39g2000yqi.googlegroups.com> On Dec 7, 4:11?pm, Steve Holden wrote: > >>> timeit.timeit(fm) > 0.58099985122680664 > >>> timeit.timeit(fd) > 0.55200004577636719 > > Of course it's possible that the random number generation is dominating, I think that it is. Moving the random number generation out into setup: >>> t1 = timeit.Timer("sin(x.next())", "from math import sin, radians; import random; x = iter([random.random() for i in xrange(1000000)])") >>> t1.timeit(1000000) 0.45154733352978838 >>> t2 = timeit.Timer("d[x.next()]", "import math, random; x = iter([random.randrange(360) for i in xrange(1000000)]); d = dict((i, math.sin(math.radians(i))) for i in xrange(360))") >>> t2.timeit(1000000) 0.21765364033694823 Of course, the dict approach assumes that all angles will be an integer number of degrees. One could add precision, but looking up specific float values in a dict is dicey, so then one has to switch to decimal math, and that's going to add extra overhead -- probably enough to tip the scales in favor of math.sin. Cheers, Ian From python at mrabarnett.plus.com Tue Dec 7 21:58:17 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 08 Dec 2010 02:58:17 +0000 Subject: convert assembly data (double words and bytes) in two tupple In-Reply-To: <1d2585a4-a023-4676-8743-a4998eacb41f@c17g2000prm.googlegroups.com> References: <1d2585a4-a023-4676-8743-a4998eacb41f@c17g2000prm.googlegroups.com> Message-ID: <4CFEF449.6070705@mrabarnett.plus.com> On 08/12/2010 02:36, joblack wrote: > I have two assembly data txt files, one has the structure: > > 0E1459D1Fh, 0AB58FAAEh, 4303E35Bh, 55FA3020h, 0E66D76ADh, > 0EF434544h, ... > > and the other has the structure: > > 53h, 6, 6Bh, 0D4h, 40h, 35h, 0B5h, 33h, 0AFh, 30h, 0B3h, > 66h, ... > > (I removed the dd and db with awk) > > Now I want both of them in a tupple (like map1 = ( ... ) and map2 = > ( ...) in my source code so I can index them.. > > Any idea how to give python a hint that the h at the end of the number > means it's a hex number? Or do I have to torture myself with regex to > get it right? If you insist on not using regex (:-)) then: >>> text = "53h, 6, 6Bh, 0D4h, 40h, 35h, 0B5h, 33h, 0AFh, 30h, 0B3h, 66h" >>> data = [t.strip() for t in text.split(",")] >>> data ['53h', '6', '6Bh', '0D4h', '40h', '35h', '0B5h', '33h', '0AFh', '30h', '0B3h', '66h'] >>> data = [int(d[ : -1], 16) if d[-1] == "h" else int(d) for d in data] >>> data [83, 6, 107, 212, 64, 53, 181, 51, 175, 48, 179, 102] From lanyjie at yahoo.com Tue Dec 7 22:24:59 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Tue, 7 Dec 2010 19:24:59 -0800 (PST) Subject: group 0 in the re module In-Reply-To: <4CFEF14A.4080004@mrabarnett.plus.com> References: <194828.16515.qm@web54205.mail.re2.yahoo.com> <4CFEF14A.4080004@mrabarnett.plus.com> Message-ID: <108409.24308.qm@web54206.mail.re2.yahoo.com> : Use \g<0>. Thanks! Though I wish all \1, \2, ..., should also be forbidden. Such a mixture of things looks like a patch work. No offense meant. Yingjie From tomf.sessile at gmail.com Tue Dec 7 22:39:29 2010 From: tomf.sessile at gmail.com (TomF) Date: Tue, 7 Dec 2010 19:39:29 -0800 Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <87ei9tjfbm.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <2010120719392986644-tomfsessile@gmailcom> On 2010-12-07 16:09:17 -0800, Mark Wooding said: > Carl Banks writes: > >> I think that feeling the need to sort non-homogenous lists is >> indictative of bad design. > > Here's a reason you might want to. > > You're given an object, and you want to compute a hash of it. (Maybe > you want to see whether someone else's object is the same as yours, but > don't want to disclose the actual object, say.) To hash it, you'll need > to serialize it somehow. But here's a problem: objects like > dictionaries and sets don't impose an ordering on their elements. For > example, the set { 1, 'two' } is the same as the set { 'two', 1 } -- but > iterating the two might well yield the elements in a different order. > (The internal details of a hash table tend to reflect the history of > operations on the hash table as well as its current contents.) > > The obvious answer is to apply a canonical ordering to unordered objects > like sets and dictionaries. A set can be serialized with its elements > in ascending order; a dictionary can be serialized as key/value pairs > with the keys in ascending order. But to do this, you need an > (arbitrary, total) order on all objects which might be set elements or > dictionary keys. The order also needs to be dependent only on the > objects' serializable values, and not on any incidental facts such as > memory addresses or whatever. I have no argument that there might be an extra-logical use for such an ordering which you might find convenient. This is the point you're making. sort() and sorted() both take a cmp argument for this sort of thing. My complaint is with Python adopting nonsensical semantics ("shoe" < 7) to accomodate it. By analogy, I often find it convenient to have division by zero return 0 to the caller for use in calculations. But if Python defined 0/0==0 I'd consider it broken. -Tom From piet at vanoostrum.org Tue Dec 7 23:04:36 2010 From: piet at vanoostrum.org (Piet van Oostrum) Date: Wed, 08 Dec 2010 00:04:36 -0400 Subject: default behavior References: <0272074b-8508-4b7a-a11e-3f004506f522@v41g2000yqv.googlegroups.com> <4c64dd6b$0$28668$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano writes: > You don't need the space between strings and the attribute access: > "1".zfill(2) is fine. You only need it for numbers, due to the ambiguity > between the decimal point and dotted attribute access. Personally I prefer parentheses: (1).conjugate -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] Nu Fair Trade woonartikelen op http://www.zylja.com From ozizlk at gmail.com Tue Dec 7 23:40:23 2010 From: ozizlk at gmail.com (Oshan) Date: Wed, 8 Dec 2010 10:10:23 +0530 Subject: Books recommendation In-Reply-To: <237490BE-143B-4474-940E-48421488BEDC@kagi.com> References: <237490BE-143B-4474-940E-48421488BEDC@kagi.com> Message-ID: hi kee, i'm a beginner too.. when i asked the same question, some python gurus recommended these books and videos. in fact it worked.. so now i'm forwarding the same to you... 1. Core Python Programming by Wesley J. Chun 2. python quick reference guide - *http://rgruet.free.fr/#QuickRef.* 3. Python Phrasebook: Essential Code and Commands by Brad Dayley 4. Python pocket reference by mark luts (O'reilly) 5. PYTHON FOR SOFTWARE DESIGN - How to Think Like a Computer Scientist by allen B Downey 6. Thenewboston video tutorials - * http://www.thenewboston.com/?cat=40&pOpen=tutorial* 7. Showmedo video tutorials - *http://showmedo.com/videotutorials/python* there are so many resources on internet for python. i have mentioned only few, which i used to read. all the best !!! oshan. On Wed, Dec 8, 2010 at 12:30 AM, Kee Nethery wrote: > > On Dec 7, 2010, at 5:39 AM, Octavian Rasnita wrote: > > > Do you have, or can I find elsewhere a recommendation for books,tutorials > and sites appropriate for beginners? > > I have found that Python for Dummies is the book I use the most. It has > lots of examples that work and that I can build upon. The O'Reilly books > talk about the language but are scarce on actual code. > > Kee Nethery > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dheeraj.gupta4 at gmail.com Tue Dec 7 23:52:07 2010 From: dheeraj.gupta4 at gmail.com (RedBaron) Date: Tue, 7 Dec 2010 20:52:07 -0800 (PST) Subject: Using logging module to log either to screen or a file References: <3b9112c2-7a63-40ef-a0f6-f64a090acb59@j18g2000prn.googlegroups.com> Message-ID: <60982d41-6fff-472d-aad4-cd32a3e90d44@h17g2000pre.googlegroups.com> On Dec 7, 7:33?pm, Jean-Michel Pichavant wrote: > RedBaron wrote: > > Hi, > > I am beginner to python and i am writing a program that does a lot of > > things. One of the requirements is that the program shud generate a > > log file. I came across python loggging module and found it very > > useful. But I have a few problems > > Suppose by giving option '-v' along with the program the user can turn > > off logging to a file and instead display log on the screen. Since I > > am using a config file for logging, how do I accomplish this. > > I tried to define two handlers (fil and screen) and added it to my > > logger. But that logs data to both screen and the file. I need to log > > it to only one. How do I dynamically remove one of the handler from > > the logger based on user option. As a precursor how do i reference the > > handlers defined in config file in the code?? > > your logger has a public 'handlers' attribute. > > consoleHandlers = [h for h in logger.handlers if h.__class__ is > logging.StreamHandler] # the list of handlers logging to the console > (assuming they are instances of the StreamHandler class) > > if consoleHandlers: > ? ? h1 = consoleHandlers[0] > ? ? h1.filter = lambda x:True # enable the handler > ? ? h1.filter = lambda x:False # disable the handler > > JM Thanks JM, This works like charm. I had also though on similar lines bt I was using isinstance(). I have two handlers - logging.RotatingFIleHandler and StreamHandler. isinstance() was weird in the sense that no matter which handle I checked for being 'StreamHandler' I always got true. Also instead of setting filter to false, I was popping from the handlers list...Silly me Thanks a ton From steve at holdenweb.com Wed Dec 8 01:40:16 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 08 Dec 2010 07:40:16 +0100 Subject: completely implicit interpolation based on a frame object In-Reply-To: References: Message-ID: On 12/8/2010 2:49 AM, Edward Peschko wrote: > All, > > Ok, it looks like in order to implement a tracer that does > interpolation, I'm going to have to hack around with frames. > > Perl's interpolation is fairly straightforward, to do interpolation of > $a == 1 all you need to do is put quotes around "$a == 1" to have $a > evaluated. > > So, I'd like to do the same thing with python. It looks like I can do > the same thing with frames, ie: > > interpolate_frame(frame, "if not wx.Platform == '__WXMAC' ") > > would interpolate wx based off of the frame that you passed to > interpolate_frame, because wx is in the f_locals or f_globals > dictionary. > > Hence, this would become: > > loc_wx = _first_defined(frame.f_locals["wx"], frame.f_globals["wx"]) > return "if not ", loc_wx.Platform , " == \"__WXMAC\"" > > which would then do the interpolation. > > I guess my question is - has something like this been released? I see > some close hits, namely Evan Forsmark's > http://www.evanfosmark.com/2008/06/string-interpolation-in-python/ > > but I don't see anything exact, and getting this right would be fairly > tricky, so I was hoping for canned solution. > > Any ideas would be great on this, including pitfalls that people see > in implementing it. > http://docs.python.org/library/string.html#template-strings regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From rustompmody at gmail.com Wed Dec 8 02:48:39 2010 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 8 Dec 2010 13:18:39 +0530 Subject: class browser Message-ID: If I have a medium to large python code base to browse/study, what are the class browsers available? -------------- next part -------------- An HTML attachment was scrubbed... URL: From ddasilva at umd.edu Wed Dec 8 03:08:00 2010 From: ddasilva at umd.edu (Daniel da Silva) Date: Wed, 8 Dec 2010 00:08:00 -0800 Subject: Calling FORTAN dll functions from Python In-Reply-To: References: <4cfe167a$0$81476$e4fe514c@news.xs4all.nl> Message-ID: I don't know much about fortran+python, but I work with someone who does, and he absolutely loves this tool: http://cens.ioc.ee/projects/f2py2e/ Daniel On Tue, Dec 7, 2010 at 10:19 PM, Dennis Lee Bieber wrote: > On Tue, 07 Dec 2010 12:52:54 +0100, Stefan Behnel > declaimed the following in gmane.comp.python.general: > > > Alex van der Spek, 07.12.2010 12:11: > > > Does anyone know how to call functions from FORTRAN dlls in Python? Is > > > it even possible? > > > > Sure, have a look at fwrap and Cython. > > > > Stefan > > Possibly ctypes too... > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From alex at moreati.org.uk Wed Dec 8 04:31:49 2010 From: alex at moreati.org.uk (Alex Willmer) Date: Wed, 8 Dec 2010 01:31:49 -0800 (PST) Subject: Python creates "locked" temp dir References: <0c30c818-f73b-4b09-b707-64ea457c757d@z26g2000prf.googlegroups.com> Message-ID: <91dca7c4-00c7-44ad-8902-54221534107c@o9g2000pre.googlegroups.com> On Dec 7, 9:03?pm, utabintarbo wrote: > I am using tempfile.mkdtemp() to create a working directory on a > remote *nix system through a Samba share. When I use this on a Windows > box, it works, and I have full access to the created dir. When used on > a Linux box (through the same Samba share), the created directory > shows as "locked", and I am unable to access. Obviously, I need > access. Any clues? You haven't provided enough details to go on. 1. Please post the actual code, and the trace back (if any). 2. When you say "I am unable to access". Do you mean another script/ process is unable to access? If so, that is the point of mkdtemp() - to make a temporary directory that _only_ the creating process can access. If you want to share it then tempfile is not the right module for you. Regards, Alex From steve+comp.lang.python at pearwood.info Wed Dec 8 04:47:21 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 Dec 2010 09:47:21 GMT Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <871v5t13ok.fsf@benfinney.id.au> Message-ID: <4cff5429$0$30002$c3e8da3$5496439d@news.astraweb.com> On Wed, 08 Dec 2010 11:58:03 +1100, Ben Finney wrote: > Carl Banks writes: > >> On Dec 6, 4:17?pm, Steven D'Aprano > +comp.lang.pyt... at pearwood.info> wrote: >> > Nevertheless, I agree that in hindsight, the ability to sort such >> > lists is not as important as the consistency of comparisons. >> >> I think that feeling the need to sort non-homogenous lists is >> indictative of bad design. > > It can also be indicative of code written for a Python that doesn't have > sets. Or a list that contains unhashable objects. Or a list that needs to be presented to a human reader in some arbitrary but consistent order. Or a doctest that needs to show the keys in a dict: >>> d = myfunction() >>> sorted(d.keys()) ['ham', 'spam', 42, None] (although that case is probably the weakest of the three). > So there's no design error in wanting heterogenerous sequences to sort; > it can be quite Pythonic (until the advent of the ?set? type). Agreed, but in hindsight I think it would be better if there was a separate lexicographic sort function, that guaranteed to sort anything (including such unorderable values as complex numbers!), without relying on the vagaries of the standard comparison operators. Or at least anything printable, in which case sorted() with a key function of lambda obj: (repr(type(obj)), repr(obj)) might work, I suppose... Then at least we could limit our arguments to how this hypothetical lexicographic sort function was broken, instead of how all comparison operators are broken :) -- Steven From steve+comp.lang.python at pearwood.info Wed Dec 8 04:48:05 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 Dec 2010 09:48:05 GMT Subject: Perceived inconsistency in py3k documentation References: <724b26b4-8233-4d57-b76f-cd781cf0cd03@z17g2000prz.googlegroups.com> <20101206200017.0c5fc63f@pitrou.net> Message-ID: <4cff5455$0$30002$c3e8da3$5496439d@news.astraweb.com> On Wed, 08 Dec 2010 00:47:37 +0100, Steve Holden wrote: > On 12/6/2010 8:00 PM, Antoine Pitrou wrote: >> On Sun, 05 Dec 2010 14:47:38 -0500 >> Terry Reedy wrote: >>> On 12/5/2010 3:31 AM, Greg wrote: >>> >>> For future reference, >>> >>>> 1) At http://docs.python.org/py3k/reference/datamodel.html: 2) At >>>> http://docs.python.org/py3k/library/stdtypes.html: >>> >>> do not work because of the trailing :s, at least not with FireFox. >> >> Work fine here. The problem isn't Firefox, it is your e-mail or news >> client. >> >> Antoine. >> >> > In my case also the links don't work, because my newsreader > (Thunderbird) makes the assumption that the colons are part of the URLs. > This behavior is common enough that people need to be aware of it. It seems to me that colons are legal inside URIs and don't need to be escaped. If that is the case, then Thunderbird is correct to treat the colon as part of the URL, and whatever client Antoine is using is wrong to exclude it. See this thread here for a discussion which concluded that colons are legal and don't need to be escaped: http://markmail.org/message/juowogoeiff44qc4 Personally, I never let any character except whitespace or < > delimiters touch a URL. I never know how applications will interpret it. -- Steven From orasnita at gmail.com Wed Dec 8 05:09:02 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Wed, 8 Dec 2010 12:09:02 +0200 Subject: is py2exe still active ? References: <5f32249f-50d4-440e-9005-04f954572894@32g2000yqz.googlegroups.com> <89dd2092-d6e9-4d5c-b966-54df3f48f065@g19g2000yqg.googlegroups.com> <2DEA78DF996B485E8B52F3B29B1124A1@teddy> <4CFEBBAE.2060400@holdenweb.com> Message-ID: <0053AA37CC664343BD6FC2E75627821C@teddy> Hi Steve, I may put some stupid questions because I am very new to Python, but... I heard about pypi/pip. Aren't all these Python libraries (like cxFreeze) provided on a central archive where we can get them and also report the bugs using a single request/issue tracker? Octavian ----- Original Message ----- From: "Steve Holden" Newsgroups: gmane.comp.python.general To: "Octavian Rasnita" Cc: Sent: Wednesday, December 08, 2010 12:56 AM Subject: Re: is py2exe still active ? > Octavian: > > It's great that you want to let people know about bugs. Put yourself in > the position of the package maintainer, however. She or he doesn't spend > all day working on cxFreeze, and probably doesn't even do a Google > search on cxFreeze very often. So they are unlikely to find out about > this problem form your well-intentioned note. > > It's just possible nobody does care, as I can't find a link to an issue > tracker - the best I could advise in this case would be to join the > mailing list by visiting > > https://lists.sourceforge.net/lists/listinfo/cx-freeze-users > > regards > Steve > > On 12/7/2010 6:49 PM, Octavian Rasnita wrote: >> This packager is also nice. >> >> If someone cares, I've discovered a small bug in it. >> If Python is installed on another drive than C under Windows, the cxfreeze.bat file still calls Python on the drive C and it doesn't work until it is corrected. >> >> Octavian >> >> ----- Original Message ----- >> From: "Cbast" >> Newsgroups: comp.lang.python >> To: >> Sent: Tuesday, December 07, 2010 5:00 PM >> Subject: Re: is py2exe still active ? >> >> >> On Dec 7, 8:23 am, Anders Persson wrote: >>> Hi! >>> When a look att py2exe homepage it is not looking like mutch happen, >>> as a beginner i was thinking to start with Python 3, but i like to now >>> if py2exe will be for 3 too. >>> >>> Is any one have any info ? >> >> I don't have the answer about py2exe, but I'm using cxFreeze to create >> executables with Python 3.1, if it's what you're looking for. >> >> http://cx-freeze.sourceforge.net/ > > > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ > See Python Video! http://python.mirocommunity.org/ > Holden Web LLC http://www.holdenweb.com/ From gerlach_joerg at web.de Wed Dec 8 05:12:35 2010 From: gerlach_joerg at web.de (J. Gerlach) Date: Wed, 08 Dec 2010 11:12:35 +0100 Subject: group 0 in the re module In-Reply-To: References: Message-ID: Am 08.12.2010 03:23, schrieb Yingjie Lan: > Hi, > > According to the doc, group(0) is the entire match. > >>>> m = re.match(r"(\w+) (\w+)", "Isaac Newton, physicist") >>>> m.group(0) # The entire match 'Isaac Newton' > > But if you do this: >>>> import re >>>> re.sub(r'(\d{3})(\d{3})', r'\0 to \1-\2', '757234') > '\x00 to 757-234' > > where I expected > '757234 to 757-234' > > Then I found that in python re '\0' is considered an octal number. > So, is there anyway to refer to the entire match by an escaped > notation? > > Thanks, > > Yingjie > the documentation of the re module says: > \g uses the corresponding group number; \g<2> is > therefore equivalent to \2, but isn?t ambiguous in a replacement such > as \g<2>0. \20 would be interpreted as a reference to group 20, not a > reference to group 2 followed by the literal character '0'. The > backreference \g<0> substitutes in the entire substring matched by > the RE. .. so you're looking for r"\g<0> to \1-\2" From steve+comp.lang.python at pearwood.info Wed Dec 8 05:29:35 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 Dec 2010 10:29:35 GMT Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <4cfebe65$0$1590$742ec2ed@news.sonic.net> Message-ID: <4cff5e0e$0$30002$c3e8da3$5496439d@news.astraweb.com> On Tue, 07 Dec 2010 15:08:23 -0800, John Nagle wrote: > If you're thinking hard about this, I recommend viewing Alexander > Stepanov's talk at Stanford last month: > > http://www.stanford.edu/class/ee380/Abstracts/101103.html > > He makes the point that, for generic programs to work right, the basic > operations must have certain well-defined semantics. Then the same > algorithms will work right across a wide variety of objects. But they already work right across a wide variety of objects, so long as you limit yourself to the subset of objects where the basic operations have the same semantics. I think that insisting that all operators must always have the same semantics is as impractical and unnecessary as insisting that all functions and methods with the same name must always have the same semantics. We wouldn't expect pencil.draw six_shooter.draw game.draw to all have the same semantics, or math.sin priest.sin despite the inconvenience it makes to duck-typing. Why should we expect more from operators than we expect from named functions, when there are so many more named functions and so few useful symbols for operators? To my mind, it is foolish for us to expect x*y to always have the same semantics when even mathematicians don't expect that. In pure mathematics, x*y != y*x for any of the following: matrices quaternions octonions and probably many others I don't know about. > This is consistent with Python's "duck typing", but inconsistent > with the current semantics of some operators. > > For example, "+" as concatenation makes "+" non-commutative. No, it only makes + non-commutative for those types where + is non- commutative. > In other words, > > a + b > > is not always equal to > > b + a > > which is not good. I don't see why. It seems to me that it's only a bad thing if you hope to reason about the meaning of a+b without knowing what a and b actually are. Personally, I don't consider that a particularly useful trait. > Important properties to have across all types: > > a + b == b + a > > Exactly one of > > a > b > a = b > a < b > > is true, or an type exception must be raised. As Mark Wooding has already pointed out, that would make numeric programmers mad, as it eliminates NANs, which are far more important to them. And me. It also would make it impossible to use > and < to talk about rankings in natural hierarchies, such as (say) pecking orders. Using > to mean "out- ranks", you might have a pecking order among five hens like this: A > B > C > D > E but D > B Not all comparisons are equivalence relations, and it would be a crying shame to lose the ability to use > and < to discuss (e.g.) non-transitive comparisons. -- Steven From dheeraj.gupta4 at gmail.com Wed Dec 8 05:32:17 2010 From: dheeraj.gupta4 at gmail.com (RedBaron) Date: Wed, 8 Dec 2010 02:32:17 -0800 (PST) Subject: Case Sensitive Section names configparser Message-ID: Is there any way by which configParser's get() function can be made case insensitive? From pavlovevidence at gmail.com Wed Dec 8 05:33:46 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 8 Dec 2010 02:33:46 -0800 (PST) Subject: Calling FORTAN dll functions from Python References: <4cfe167a$0$81476$e4fe514c@news.xs4all.nl> Message-ID: On Dec 7, 3:11?am, "Alex van der Spek" wrote: > Does anyone know how to call functions from FORTRAN dlls in Python? Is it > even possible? I browsed the documentation for Python 2.6.1 and the Python/C > API comes close to what I would like to do but it is strictly limited to C. > > Unfortunately the passing of arguments in C and FORTRAN is very different, > not to mention the differences with strings where FORTRAN expects a hidden > length argument. It could call the FORTRAN dll from C and call the C > functions from Python but is that my only option? I'd recommend f2py, which is part of the numpy package. Carl Banks From tartley at tartley.com Wed Dec 8 05:40:12 2010 From: tartley at tartley.com (Jonathan Hartley) Date: Wed, 8 Dec 2010 02:40:12 -0800 (PST) Subject: is py2exe still active ? References: <5f32249f-50d4-440e-9005-04f954572894@32g2000yqz.googlegroups.com> <89dd2092-d6e9-4d5c-b966-54df3f48f065@g19g2000yqg.googlegroups.com> <2DEA78DF996B485E8B52F3B29B1124A1@teddy> <4CFEBBAE.2060400@holdenweb.com> Message-ID: <5b8bb079-6000-45a8-b21e-aee78baaa678@p26g2000pra.googlegroups.com> On Dec 8, 10:09?am, "Octavian Rasnita" wrote: > Hi Steve, > > I may put some stupid questions because I am very new to Python, but... I heard about pypi/pip. Aren't all these Python libraries (like cxFreeze) provided on a central archive where we can get them and also report the bugs using a single request/issue tracker? > > Octavian > > > > ----- Original Message ----- > From: "Steve Holden" > > Newsgroups: gmane.comp.python.general > To: "Octavian Rasnita" > Cc: > Sent: Wednesday, December 08, 2010 12:56 AM > Subject: Re: is py2exe still active ? > > > Octavian: > > > It's great that you want to let people know about bugs. Put yourself in > > the position of the package maintainer, however. She or he doesn't spend > > all day working on cxFreeze, and probably doesn't even do a Google > > search on cxFreeze very often. So they are unlikely to find out about > > this problem form your well-intentioned note. > > > It's just possible nobody does care, as I can't find a link to an issue > > tracker - the best I could advise in this case would be to join the > > mailing list by visiting > > > ?https://lists.sourceforge.net/lists/listinfo/cx-freeze-users > > > regards > > Steve > > > On 12/7/2010 6:49 PM, Octavian Rasnita wrote: > >> This packager is also nice. > > >> If someone cares, I've discovered a small bug in it. > >> If Python is installed on another drive than C under Windows, the cxfreeze.bat file still calls Python on the drive C and it doesn't work until it is corrected. > > >> Octavian > > >> ----- Original Message ----- > >> From: "Cbast" > >> Newsgroups: comp.lang.python > >> To: > >> Sent: Tuesday, December 07, 2010 5:00 PM > >> Subject: Re: is py2exe still active ? > > >> On Dec 7, 8:23 am, Anders Persson wrote: > >>> Hi! > >>> When a look att py2exe homepage it is not looking like mutch happen, > >>> as a beginner i was thinking to start with Python 3, but i like to now > >>> if py2exe will be for 3 too. > > >>> Is any one have any info ? > > >> I don't have the answer about py2exe, but I'm using cxFreeze to create > >> executables with Python 3.1, if it's what you're looking for. > > >>http://cx-freeze.sourceforge.net/ > > > -- > > Steve Holden ? ? ? ? ? +1 571 484 6266 ? +1 800 494 3119 > > PyCon 2011 Atlanta March 9-17 ? ? ?http://us.pycon.org/ > > See Python Video! ? ? ?http://python.mirocommunity.org/ > > Holden Web LLC ? ? ? ? ? ? ? ?http://www.holdenweb.com/ Hey, Yes, they are all Python packages or applications, and yes, PyPI aka The Cheese Shop is a single repository for them. However, they do not share mailing lists or issue trackers. Each project maintains its own bug tracking, etc. Best regards, Jonathan From tartley at tartley.com Wed Dec 8 05:40:13 2010 From: tartley at tartley.com (Jonathan Hartley) Date: Wed, 8 Dec 2010 02:40:13 -0800 (PST) Subject: is py2exe still active ? References: <5f32249f-50d4-440e-9005-04f954572894@32g2000yqz.googlegroups.com> <89dd2092-d6e9-4d5c-b966-54df3f48f065@g19g2000yqg.googlegroups.com> <2DEA78DF996B485E8B52F3B29B1124A1@teddy> <4CFEBBAE.2060400@holdenweb.com> Message-ID: On Dec 8, 10:09?am, "Octavian Rasnita" wrote: > Hi Steve, > > I may put some stupid questions because I am very new to Python, but... I heard about pypi/pip. Aren't all these Python libraries (like cxFreeze) provided on a central archive where we can get them and also report the bugs using a single request/issue tracker? > > Octavian > > > > ----- Original Message ----- > From: "Steve Holden" > > Newsgroups: gmane.comp.python.general > To: "Octavian Rasnita" > Cc: > Sent: Wednesday, December 08, 2010 12:56 AM > Subject: Re: is py2exe still active ? > > > Octavian: > > > It's great that you want to let people know about bugs. Put yourself in > > the position of the package maintainer, however. She or he doesn't spend > > all day working on cxFreeze, and probably doesn't even do a Google > > search on cxFreeze very often. So they are unlikely to find out about > > this problem form your well-intentioned note. > > > It's just possible nobody does care, as I can't find a link to an issue > > tracker - the best I could advise in this case would be to join the > > mailing list by visiting > > > ?https://lists.sourceforge.net/lists/listinfo/cx-freeze-users > > > regards > > Steve > > > On 12/7/2010 6:49 PM, Octavian Rasnita wrote: > >> This packager is also nice. > > >> If someone cares, I've discovered a small bug in it. > >> If Python is installed on another drive than C under Windows, the cxfreeze.bat file still calls Python on the drive C and it doesn't work until it is corrected. > > >> Octavian > > >> ----- Original Message ----- > >> From: "Cbast" > >> Newsgroups: comp.lang.python > >> To: > >> Sent: Tuesday, December 07, 2010 5:00 PM > >> Subject: Re: is py2exe still active ? > > >> On Dec 7, 8:23 am, Anders Persson wrote: > >>> Hi! > >>> When a look att py2exe homepage it is not looking like mutch happen, > >>> as a beginner i was thinking to start with Python 3, but i like to now > >>> if py2exe will be for 3 too. > > >>> Is any one have any info ? > > >> I don't have the answer about py2exe, but I'm using cxFreeze to create > >> executables with Python 3.1, if it's what you're looking for. > > >>http://cx-freeze.sourceforge.net/ > > > -- > > Steve Holden ? ? ? ? ? +1 571 484 6266 ? +1 800 494 3119 > > PyCon 2011 Atlanta March 9-17 ? ? ?http://us.pycon.org/ > > See Python Video! ? ? ?http://python.mirocommunity.org/ > > Holden Web LLC ? ? ? ? ? ? ? ?http://www.holdenweb.com/ Hey, Yes, they are all Python packages or applications, and yes, PyPI aka The Cheese Shop is a single repository for them. However, they do not share mailing lists or issue trackers. Each project maintains its own bug tracking, etc. Best regards, Jonathan From steve+comp.lang.python at pearwood.info Wed Dec 8 05:45:55 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 Dec 2010 10:45:55 GMT Subject: use of __new__ to permit "dynamic" completion within (any?) IDE ? References: <0b90e80b-8b9b-412d-bfff-9a9ec4b172d2@h22g2000vbr.googlegroups.com> Message-ID: <4cff61e3$0$30002$c3e8da3$5496439d@news.astraweb.com> On Tue, 07 Dec 2010 07:52:06 -0800, gst wrote: > Hi, > > I met a situation where I was passing an object created in/with an upper > level module class to a lower level module class' instance in one of its > __init__ argument and saving a ref of the upper object in that lower > level class' new instance. > > But in my IDE I want the completion to also work from within the lower > level module when it's refering to the object passed from the upper > level: "The completion"? What do you mean? > Well, I'm sure I'm not very clear in my terms (and probably a bit long > in the sentence) so here it is in code: I'm afraid I have to agree with your, your description is not clear to me. Unfortunately, neither is your code, because I don't understand *why* you do the things you do. > files: > module1.py > subpackage/module2.py > > > file module1.py: > > from subpackage.module2 import class2 Is it relevant that class2 comes from another module? Would your concept work if class1 and class2 were defined in the same file? By the way, it's conventional (but not compulsory) to name classes with an initial capital letter, and instances in all lowercase. > class class1(object): > > def __new__(cls, _self=None, *args, **kwargs): > if _self: ## we've been passed an instance already > initialyzed > ## so directly return it instead of creating a > new object. > return _self > return object.__new__(cls) Depending on your application, this may be an unsafe assumption. If the caller says class1("spam"), your class will return "spam". This may or may not be what you want. > def __init__(self, _self=None, *args, **kwargs): > if _self: ## we've been passed an instance already > initialyzed > ## so directly returns > ## assert(self is _self) ? > return > self.object2 = class2(object1=self, "blip", "blop") # others > init Okay, this seems like a fairly straightforward case of adding an attribute to your instance that includes a reference to itself. No big deal... there's nothing wrong with this, although you are creating a reference cycle, which is somewhat of a (mild) code-smell. > file module2.py: > > class class2(object): > > def __init__(self, object1, *args, **kwargs): > > from ..module1 import class1 Now you have a circular import, and that's a pretty major code smell. That's dangerous. Try to avoid it. Perhaps the easiest way to avoid it is to place class1 and class2 in the same module, and stop writing Java :) > self.object1 = class1(_self=object1) ## instead of: > self.object1 = object1 > > ## others functions and/or init.. > ## where now I've completion working on self.object1 : ## if I > add(or remove) fields/methods in module1 (and save) then ## I have > them available(or disappeared) in the completion when > executed from this submodule. > ## This ofcourse permits to save me of remembering all of the > class1 attributes/methods when I'm working with self.object1 from within > one of class2 methods. I'm afraid I don't understand what you mean here in these comments. What do you mean, "save me of (from?) remembering all the class1 attributes/ methods..." -- how does it save you from knowing the methods? Whether you write this: instance = class1() instance.method() or this: instance = class1() another_instance = class2(instance) another_instance.object1.method() you still need to know the name "method". It seems to me that this scheme is unnecessarily complex, convoluted and confusing, for very little gain. Perhaps you could try explaining what you hope to accomplish, giving examples? -- Steven From bieffe62 at gmail.com Wed Dec 8 05:53:30 2010 From: bieffe62 at gmail.com (Francesco Bochicchio) Date: Wed, 8 Dec 2010 02:53:30 -0800 (PST) Subject: Case Sensitive Section names configparser References: Message-ID: <4c2179f5-fa90-4fd7-9cd8-808fb8d54468@u9g2000pra.googlegroups.com> On 8 Dic, 11:32, RedBaron wrote: > Is there any way by which configParser's get() function can be made > case insensitive? If you don't care about the case of the config parameter values, you could pre-convert the input to configParser all in UPPER or lower letter with a file-like object like this (NOT TESTED): class AllUpperFile(object): def __init__(self, fname): self.fp = file(fname) def readline(self): return self.fp.readline().upper() and the use configParser.readfp method to feed the file-like object to the config parser myConfigparser.readfp( AllUpperFile("myconnfigfile.cfg") HTH Ciao ---- FB From jeanmichel at sequans.com Wed Dec 8 06:05:41 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 08 Dec 2010 12:05:41 +0100 Subject: class browser In-Reply-To: References: Message-ID: <4CFF6685.3070900@sequans.com> Rustom Mody wrote: > If I have a medium to large python code base to browse/study, what are > the class browsers available? vim + ctags is one of them. JM From joncle at googlemail.com Wed Dec 8 06:11:51 2010 From: joncle at googlemail.com (Jon Clements) Date: Wed, 8 Dec 2010 03:11:51 -0800 (PST) Subject: Case Sensitive Section names configparser References: Message-ID: On Dec 8, 10:32?am, RedBaron wrote: > Is there any way by which configParser's get() function can be made > case insensitive? I would probably subclass dict to create a string specific, case insensitive version, and supply it as the dict_type. See http://docs.python.org/library/configparser.html#ConfigParser.RawConfigParser That way your values would remain cased correctly, but lookups would be insensitive. hth Jon. From g.starck at gmail.com Wed Dec 8 07:01:38 2010 From: g.starck at gmail.com (gst) Date: Wed, 8 Dec 2010 04:01:38 -0800 (PST) Subject: use of __new__ to permit "dynamic" completion within (any?) IDE ? References: <0b90e80b-8b9b-412d-bfff-9a9ec4b172d2@h22g2000vbr.googlegroups.com> <4cff61e3$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8ec4f0a5-a7d7-46ef-91d2-2427f696cb11@y3g2000vbm.googlegroups.com> On 8 d?c, 11:45, Steven D'Aprano wrote: > On Tue, 07 Dec 2010 07:52:06 -0800, gst wrote: > > Hi, > > > But in my IDE I want the completion to also work from within the lower > > level module when it's refering to the object passed from the upper > > level: > > "The completion"? What do you mean? Hi, I mean the autocompletion feature of my IDE : when I type "object." then on the "." it shows me possible members/ methods of the 'object'. depending on what my IDE can guess about the object possible type(s) ; in the worst case it can't guess nothing about it and that's my point below.. > > Well, I'm sure I'm not very clear in my terms (and probably a bit long > > in the sentence) so here it is in code: > > I'm afraid I have to agree with your, your description is not clear to me. I hope I'm now ;) > Unfortunately, neither is your code, because I don't understand *why* you > do the things you do. damn. ok let's go.. > > file module1.py: > > > from subpackage.module2 import class2 > > Is it relevant that class2 comes from another module? yes. hmmm or maybe not completely.. I think it only highly depends on what the IDE can guess on an object type used inside some methods depending on the files hierarchy.. > Would your concept work if class1 and class2 were defined in the same file? I guess yes also. > > class class1(object): > > > ? ? def __new__(cls, _self=None, *args, **kwargs): > > ? ? ? ? if _self: ?## we've been passed an instance already > > initialyzed > > ? ? ? ? ? ? ? ? ? ? ?## so directly return it instead of creating a > > new object. > > ? ? ? ? ? ? return _self > > ? ? ? ? return object.__new__(cls) > > Depending on your application, this may be an unsafe assumption. If the > caller says class1("spam"), your class will return "spam". This may or > may not be what you want. I'm always passing the good object type when I do this. > > ? ? def __init__(self, _self=None, *args, **kwargs): > > ? ? ? ? if _self: ?## we've been passed an instance already > > initialyzed > > ? ? ? ? ? ? ? ? ? ? ?## so directly returns > > ? ? ? ? ? ? ## assert(self is _self) ? > > ? ? ? ? ? ? return > > ? ? ? ? self.object2 = class2(object1=self, "blip", "blop") # others > > ? ? ? ? init > > Okay, this seems like a fairly straightforward case of adding an > attribute to your instance that includes a reference to itself. No big > deal... there's nothing wrong with this, although you are creating a > reference cycle, which is somewhat of a (mild) code-smell. that is a worry effectively. (hmm when you say it's a case of adding an attribute that includes a ref to itself it's not really that (or i badly understand) : it's adding an attribute to a lower level class instance that contains a ref to an upper level class instance (which also contains a ref to the lower level class' instance and that's the cycle (and that's a bit my worry)) > > file module2.py: > > > class class2(object): > > > ? ? def __init__(self, object1, *args, **kwargs): > > > ? ? ? ? from ..module1 import class1 > > Now you have a circular import, and that's a pretty major code smell. > That's dangerous. Try to avoid it. Perhaps the easiest way to avoid it is > to place class1 and class2 in the same module, and stop writing Java :) damn if this looks like Java it's really not my will ; I've not made Java anymore for probably 10 years ! I'll try by putting class1 and class2 in same module (or at same directory level first) and see if that can do it.. > > > ? ? ? ? self.object1 = class1(_self=object1) ? ?## instead of: > > self.object1 = object1 > > > ? ? ## others functions and/or init.. > > ? ? ## where ?now I've completion working on self.object1 : ## if I > > ? ? add(or remove) fields/methods in module1 (and save) then ## I have > > ? ? them available(or disappeared) in the completion when > > executed from this submodule. > > ? ? ## This ofcourse permits to save me of remembering all of the > > class1 attributes/methods when I'm working with self.object1 from within > > one of class2 methods. > > I'm afraid I don't understand what you mean here in these comments. What > do you mean, "save me of (from?) remembering all the class1 attributes/ > methods..." -- how does it save you from knowing the methods? Whether you > write this: > > instance = class1() > instance.method() > > or this: > > instance = class1() > another_instance = class2(instance) > another_instance.object1.method() > > you still need to know the name "method". > > It seems to me that this scheme is unnecessarily complex, convoluted and > confusing, for very little gain. Perhaps you could try explaining what > you hope to accomplish, giving examples? Effectively I recognise that this seems like a bit silly/odd .. but as it's working I wanted some advises so ;) As I told I try to have some kind of "ultimate" autocompletion, always working for this kind of case (I know exactly that a certain member of a certain class' instance will always have the same type but my IDE doesn't seem to guess/know it.. ; I guess the best answer would be : bad IDE, change IDE but I'm guessing that others IDE can't do a lot better in this case. Anyway many thanks for your reply ; I'll do some further tests with your comments already.. regards, greg. nb: so this "hack" is only relevant during dev ; once the project would be finished the "hack" could be removed (i.e : in class2 init I would directly do : self.object1 = object1) From python.list at tim.thechases.com Wed Dec 8 07:29:57 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 08 Dec 2010 06:29:57 -0600 Subject: Comparisons of incompatible types In-Reply-To: <4cff5429$0$30002$c3e8da3$5496439d@news.astraweb.com> References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <871v5t13ok.fsf@benfinney.id.au> <4cff5429$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4CFF7A45.7060000@tim.thechases.com> On 12/08/2010 03:47 AM, Steven D'Aprano wrote: > Or a list that needs to be presented to a human reader in some arbitrary > but consistent order. > > Or a doctest that needs to show the keys in a dict: > > >>> d = myfunction() > >>> sorted(d.keys()) > ['ham', 'spam', 42, None] > [snip] > > Agreed, but in hindsight I think it would be better if there was a > separate lexicographic sort function, that guaranteed to sort anything > (including such unorderable values as complex numbers!), without relying > on the vagaries of the standard comparison operators. wouldn't that be something like sorted(mixedstuff, key=str) or if all you need is a stable order regardless of what that order is, one could even get away with: sorted(mixedstuff, key=id) -tkc From xrgtn at yandex.ru Wed Dec 8 07:42:25 2010 From: xrgtn at yandex.ru (Alexander Gattin) Date: Wed, 8 Dec 2010 14:42:25 +0200 Subject: Wanted: slow regexes In-Reply-To: <4CFC61B0.8000109@mrabarnett.plus.com> References: <4CFC61B0.8000109@mrabarnett.plus.com> Message-ID: <20101208124225.GA4846@xrgtn-q40> Hello, On Mon, Dec 06, 2010 at 04:08:16AM +0000, MRAB wrote: > I'm looking for examples of regexes which are > slow (especially those which seem never to > finish) but whose results are known. does it have anything to do with http://swtch.com/~rsc/regexp/regexp1.html? -- With best regards, xrgtn From jonathan.slenders at gmail.com Wed Dec 8 08:01:04 2010 From: jonathan.slenders at gmail.com (Jonathan S) Date: Wed, 8 Dec 2010 05:01:04 -0800 (PST) Subject: Replacing globals in exec by custom class Message-ID: Hi all, I wonder if anyone can explain some weird behaviour in Python. What I'm trying to do is to execute a string of python code through the 'exec' statement. I pass an instance of my Global class, which acts like a dict. By overriding the __getitem__ method, the Global should pretend that a global variable, named 'xx' does exist. This does work for the outermost scope in the executed code, but inside the nested function, 'q', the Global instance seems never to be accessed, 'xx' is not found, while the globals() built-in still returns the custom Global instance. According to python's executing model [1], the interpreter is supposed to look into globals(), if a variable has not been assigned in the inner scope. What am I missing here? [1] http://docs.python.org/reference/executionmodel.html {{{ class Global(dict): def __init__(self): pass def __getitem__(self, key): import __builtin__ if key == 'xx': return 'xx' if hasattr(__builtin__, key): return getattr(__builtin__, key) else key in self.__dict__: return self.__dict__[key] def __setitem__(self, key, value): self.__dict__[key] = value def __str__(self): return ' ' + unicode(self.__dict__) code=""" print globals() print xx # Does work, prints 'xx' def q(): print globals().__getitem__('xx') # Does work, prints 'xx' print globals()['xx'] # Does work, prints 'xx' print xx # Does not work, cannot find xx q() """ g = Global() exec(compile(code, 'my code', 'exec'), g, g) }}} From utabintarbo at gmail.com Wed Dec 8 08:09:06 2010 From: utabintarbo at gmail.com (utabintarbo) Date: Wed, 8 Dec 2010 05:09:06 -0800 (PST) Subject: Python creates "locked" temp dir References: <0c30c818-f73b-4b09-b707-64ea457c757d@z26g2000prf.googlegroups.com> <91dca7c4-00c7-44ad-8902-54221534107c@o9g2000pre.googlegroups.com> Message-ID: <51e4ed46-41dd-46db-b3c4-0fdb475be97f@o14g2000prn.googlegroups.com> Thanks for the reply. The relevant function (in a module) is as follows: def createWorkDir(pathdir="k:\\"): import tempfile, os if os.name == 'posix': pathdir = os.path.join(config.get('paths', 'MOUNTPOINT'), 'subdir1') else: pathdir = os.path.normpath(r"\\windowsmount\subdir1") if not os.path.exists(os.path.join(pathdir,'tmp','program')): os.makedirs(os.path.join(pathdir,'tmp','program')) return os.path.normpath(tempfile.mkdtemp("", "", os.path.join(pathdir,'tmp','program'))) The calling program calls the function as such: updateWorkDir = createWorkDir() I then attempt to copy a file (using shutil.move) into updateWorkDir and get an: IOError: [Errno 13] Permission denied: '/MOUNTPOINT/subdir1/tmp/ program/y-Z0h3/file.ext' I also tried to create a similar dir under 'tmp' using os.mkdir and while the dir was not locked such that only the owner could do anything in it, it was not writeable by anything other than the owner, even when mode 0777 was specified explicitly. Thanks for the help. On Dec 8, 4:31?am, Alex Willmer wrote: > On Dec 7, 9:03?pm, utabintarbo wrote: > > > I am using tempfile.mkdtemp() to create a working directory on a > > remote *nix system through a Samba share. When I use this on a Windows > > box, it works, and I have full access to the created dir. When used on > > a Linux box (through the same Samba share), the created directory > > shows as "locked", and I am unable to access. Obviously, I need > > access. Any clues? > > You haven't provided enough details to go on. > 1. Please post the actual code, and the trace back (if any). > 2. When you say "I am unable to access". Do you mean another script/ > process is unable to access? If so, that is the point of mkdtemp() - > to make a temporary directory that _only_ the creating process can > access. If you want to share it then tempfile is not the right module > for you. > > Regards, Alex From steve at holdenweb.com Wed Dec 8 08:09:42 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 08 Dec 2010 14:09:42 +0100 Subject: use of __new__ to permit "dynamic" completion within (any?) IDE ? In-Reply-To: <8ec4f0a5-a7d7-46ef-91d2-2427f696cb11@y3g2000vbm.googlegroups.com> References: <0b90e80b-8b9b-412d-bfff-9a9ec4b172d2@h22g2000vbr.googlegroups.com> <4cff61e3$0$30002$c3e8da3$5496439d@news.astraweb.com> <8ec4f0a5-a7d7-46ef-91d2-2427f696cb11@y3g2000vbm.googlegroups.com> Message-ID: On 12/8/2010 1:01 PM, gst wrote: > As I told I try to have some kind of "ultimate" autocompletion, always > working for this kind of case (I know exactly that a certain member of > a certain class' instance will always have the same type but my IDE > doesn't seem to guess/know it.. ; I guess the best answer would be : > bad IDE, change IDE but I'm guessing that others IDE can't do a lot > better in this case. > If you'd told us which IDE you were using we might have offered better advice, but you seem to want to keep that a secret ("my IDE" tells us nothing). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From g.starck at gmail.com Wed Dec 8 09:21:18 2010 From: g.starck at gmail.com (gst) Date: Wed, 8 Dec 2010 06:21:18 -0800 (PST) Subject: use of __new__ to permit "dynamic" completion within (any?) IDE ? References: <0b90e80b-8b9b-412d-bfff-9a9ec4b172d2@h22g2000vbr.googlegroups.com> <4cff61e3$0$30002$c3e8da3$5496439d@news.astraweb.com> <8ec4f0a5-a7d7-46ef-91d2-2427f696cb11@y3g2000vbm.googlegroups.com> Message-ID: On 8 d?c, 14:09, Steve Holden wrote: > > If you'd told us which IDE you were using we might have offered better > advice, but you seem to want to keep that a secret ("my IDE" tells us > nothing). > sorry it was totally bottom of my first message : > note: I'm using Eclipse 3.5.2 with pydev so (I don't really know how others IDE can handle this case) . now I realyze that my question has not a lot to do with python language itself and I should resubmit that probably on pydev forums/.. but as I told I wanted to have some advises on the "good" (or not) use of this "way of doing" with python itself. You already explained me it's not the best so far.. and I agree although during (my) dev it helps ;) (but I do this only with very few classes that have lot of attributes/methods ofcourse). regards, greg. From rob.randall2 at gmail.com Wed Dec 8 09:44:30 2010 From: rob.randall2 at gmail.com (Rob Randall) Date: Wed, 8 Dec 2010 14:44:30 +0000 Subject: 64 bit memory usage Message-ID: I am trying to understand how much memory is available to a 64 bit python process running under Windows XP 64 bit. When I run tests just creating a series of large dictionaries containing string keys and float values I do not seem to be able to grow the process beyond the amount of RAM present. For example, on a box with 2GB RAM and 3 GB pagefile the process stalls at around 2GB. On another machine with 16GB RAM and 24GB pagefile the process stalls at 16GB. In other tests where a C++ program loads and runs the python DLL, if C++ based operations are performed the memory usage will grow to 40GB, but if python is used to grab the memory it can still only grow to 16GB. With this program if the memory usage is grown to over 16GB on the C++ side, attempting to grab any from python crashes the process. I was under the impression that python could grab as much memory as other programs. Can anyone tell me what is happening or where I may be going wrong? Thanks, Rob Randall -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Wed Dec 8 09:51:10 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 08 Dec 2010 15:51:10 +0100 Subject: use of __new__ to permit "dynamic" completion within (any?) IDE ? In-Reply-To: <8ec4f0a5-a7d7-46ef-91d2-2427f696cb11@y3g2000vbm.googlegroups.com> References: <0b90e80b-8b9b-412d-bfff-9a9ec4b172d2@h22g2000vbr.googlegroups.com> <4cff61e3$0$30002$c3e8da3$5496439d@news.astraweb.com> <8ec4f0a5-a7d7-46ef-91d2-2427f696cb11@y3g2000vbm.googlegroups.com> Message-ID: <4CFF9B5E.5060702@sequans.com> gst wrote: > greg. > > nb: so this "hack" is only relevant during dev ; once the project > would be finished the "hack" could be removed (i.e : in class2 init I > would directly do : self.object1 = object1) > Expect some bugs then on the 'release' version. I'm not sure I understood everything you mentioned in your OP, however writing python code on class creation to make Eclipse completion 'work' is ... a very bad idea IMO. Just don't do it. quoting eclipse page: "Pydev [...] uses advanced type inference techniques to provide features such code completion and code analysis" I don't know exactly what's hidden behind this marketing stuff. Did you try to document your method with a markup language supported by Eclipse (if there is any)? class class2(object): def __init__(self, object1, *args, **kwargs): """blablabla @param object1: a L{class1} reference """ self.object1 = object1 The docstring would be the only way for an IDE to infer a argument type. Note that I used the epydoc markup language because it's the only one I know but it's unlikely supported by Eclipse. You better try reStructuredText. JM From g.starck at gmail.com Wed Dec 8 10:20:25 2010 From: g.starck at gmail.com (gst) Date: Wed, 8 Dec 2010 07:20:25 -0800 (PST) Subject: use of __new__ to permit "dynamic" completion within (any?) IDE ? References: <0b90e80b-8b9b-412d-bfff-9a9ec4b172d2@h22g2000vbr.googlegroups.com> <4cff61e3$0$30002$c3e8da3$5496439d@news.astraweb.com> <8ec4f0a5-a7d7-46ef-91d2-2427f696cb11@y3g2000vbm.googlegroups.com> Message-ID: On 8 d?c, 15:51, Jean-Michel Pichavant wrote: Hi, > gst wrote: > > nb: so this "hack" is only relevant during dev ; once the project > > would be finished the "hack" could be removed (i.e : in class2 init I > > would directly do : self.object1 = object1) > > Expect some bugs then on the 'release' version. even with the "assert(self is _self)" in the "if _self:" condition in the new and/or init methods of the class1 ? > I'm not sure I understood everything you mentioned in your OP, however > writing python code on class creation to make Eclipse completion 'work' > is ... a very bad idea IMO. > Just don't do it. yes I'm trying to find better ways for having completion works out of the box in this case.. (that would be a high help to my opinion). > quoting eclipse page: > > "Pydev [...] uses advanced type inference techniques to provide features > such code completion and code analysis" > > I don't know exactly what's hidden behind this marketing stuff. Did you > try to document your method with a markup language supported by Eclipse > (if there is any)? pydev completion apparently is restricted (as far as i see) to some very specific cases (basically it works when you import a module at top of another one and that you instantiate objects from the imported module within the init methods of the classes of the module which is importing the other one (but so "circular" references created on some objects from the first module (the one imported) in the second one won't have the completion working for them (that's what I see)). > class class2(object): > ? ? def __init__(self, object1, *args, **kwargs): > ? ? """blablabla > > ? ? @param object1: a L{class1} reference > ? ? """ > ? ? self.object1 = object1 > > The docstring would be the only way for an IDE to infer a argument type. > Note that I used the epydoc markup language because it's the only one I > know but it's unlikely supported by Eclipse. You better try > reStructuredText. > > JM well, I'm not very used to docstrings in fact but it's effectively a way to achieve this ; well certainly better than doing this kind of "ugly" hack so. I'll have a try at that. Thanks for your reply, regards, greg. From g.starck at gmail.com Wed Dec 8 10:23:45 2010 From: g.starck at gmail.com (gst) Date: Wed, 8 Dec 2010 07:23:45 -0800 (PST) Subject: use of __new__ to permit "dynamic" completion within (any?) IDE ? References: <0b90e80b-8b9b-412d-bfff-9a9ec4b172d2@h22g2000vbr.googlegroups.com> <4cff61e3$0$30002$c3e8da3$5496439d@news.astraweb.com> <8ec4f0a5-a7d7-46ef-91d2-2427f696cb11@y3g2000vbm.googlegroups.com> Message-ID: <070fc00b-fa60-4b10-8629-7dc836ef8d99@p11g2000vbn.googlegroups.com> On 8 d?c, 16:20, gst wrote: > On 8 d?c, 15:51, Jean-Michel Pichavant wrote: > > Hi, > > > gst wrote: > > > nb: so this "hack" is only relevant during dev ; once the project > > > would be finished the "hack" could be removed (i.e : in class2 init I > > > would directly do : self.object1 = object1) > > > Expect some bugs then on the 'release' version. > > even with the "assert(self is _self)" in the "if _self:" condition in > the new and/or ?init methods of the class1 ? note: I don't know if that matters but I'm using __slots__ in this class1 .. greg. From g.starck at gmail.com Wed Dec 8 10:40:18 2010 From: g.starck at gmail.com (gst) Date: Wed, 8 Dec 2010 07:40:18 -0800 (PST) Subject: use of __new__ to permit "dynamic" completion within (any?) IDE ? References: <0b90e80b-8b9b-412d-bfff-9a9ec4b172d2@h22g2000vbr.googlegroups.com> <4cff61e3$0$30002$c3e8da3$5496439d@news.astraweb.com> <8ec4f0a5-a7d7-46ef-91d2-2427f696cb11@y3g2000vbm.googlegroups.com> Message-ID: <58605a3b-6572-449c-8dd9-87156af140b8@u9g2000pra.googlegroups.com> On 8 d?c, 16:20, gst wrote: > even with the "assert(self is _self)" in the "if _self:" condition in > the new and/or ?init methods of the class1 ? damn : in the init method only of course.. From jeanmichel at sequans.com Wed Dec 8 10:55:37 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 08 Dec 2010 16:55:37 +0100 Subject: use of __new__ to permit "dynamic" completion within (any?) IDE ? In-Reply-To: References: <0b90e80b-8b9b-412d-bfff-9a9ec4b172d2@h22g2000vbr.googlegroups.com> <4cff61e3$0$30002$c3e8da3$5496439d@news.astraweb.com> <8ec4f0a5-a7d7-46ef-91d2-2427f696cb11@y3g2000vbm.googlegroups.com> Message-ID: <4CFFAA79.3050106@sequans.com> >> quoting eclipse page: >> >> "Pydev [...] uses advanced type inference techniques to provide features >> such code completion and code analysis" >> >> I don't know exactly what's hidden behind this marketing stuff. Did you >> try to document your method with a markup language supported by Eclipse >> (if there is any)? >> > > pydev completion apparently is restricted (as far as i see) to some > very specific cases (basically it works when you import a module at > top of another one and that you instantiate objects from the imported > module within the init methods of the classes of the module which is > importing the other one (but so "circular" references created on some > objects from the first module (the one imported) in the second one > won't have the completion working for them (that's what I see)). > To understand what is possible and what is not, you simply need to think like a completion feature. case 1: self.object = MyClass() self.object is a MyClass instance, easy stuff I need to parse MyClass and get the list of attributes/method case 2: self.object = object1 There may be simply no way to know the type/class of object1, object1 could be even of an inconsistent type, sometimes None, int, MyClass, who knows ? Your trick worked because you found a way to write self.object = MyClass(object1) and getting barely the same effect than self.object = object1. I'm still thinking that's it's a bad idea. In any case your IDE can still be fooled by the dynamic of python (like pylint is) How to write python code then ? Well I guess most people either knows all the attributes by heart, have the documentation, or a split screen to the class definition, possibly folded using advanced text editor feature. You need to forget about code completion with any dynamic language. I also sometimes use an ipython shell to instanciate objects and inspect their attributes. JM From pruebauno at latinmail.com Wed Dec 8 10:56:42 2010 From: pruebauno at latinmail.com (nn) Date: Wed, 8 Dec 2010 07:56:42 -0800 (PST) Subject: use of __new__ to permit "dynamic" completion within (any?) IDE ? References: <0b90e80b-8b9b-412d-bfff-9a9ec4b172d2@h22g2000vbr.googlegroups.com> Message-ID: <713b9cdc-7ff2-45ba-8e68-ed341b7b6ea2@32g2000yqz.googlegroups.com> On Dec 7, 10:52?am, gst wrote: > Hi, > > I met a situation where I was passing an object created in/with an > upper level module class to a lower level module class' instance in > one of its __init__ argument and saving a ref of the upper object in > that lower level class' new instance. > > But in my IDE I want the completion to also work from within the lower > level module when it's refering to the object passed from the upper > level: > > Well, I'm sure I'm not very clear in my terms (and probably a bit long > in the sentence) so here it is in code: > > files: > module1.py > subpackage/module2.py > > file module1.py: > > from subpackage.module2 import class2 > > class class1(object): > > ? ? def __new__(cls, _self=None, *args, **kwargs): > ? ? ? ? if _self: ?## we've been passed an instance already > initialyzed > ? ? ? ? ? ? ? ? ? ? ?## so directly return it instead of creating a > new object. > ? ? ? ? ? ? return _self > ? ? ? ? return object.__new__(cls) > > ? ? def __init__(self, _self=None, *args, **kwargs): > ? ? ? ? if _self: ?## we've been passed an instance already > initialyzed > ? ? ? ? ? ? ? ? ? ? ?## so directly returns > ? ? ? ? ? ? ## assert(self is _self) ? > ? ? ? ? ? ? return > ? ? ? ? self.object2 = class2(object1=self, "blip", "blop") > ? ? ? ? # others init > > file module2.py: > > class class2(object): > > ? ? def __init__(self, object1, *args, **kwargs): > > ? ? ? ? from ..module1 import class1 > > ? ? ? ? self.object1 = class1(_self=object1) ? ?## instead of: > self.object1 = object1 > > ? ? ## others functions and/or init.. > ? ? ## where ?now I've completion working on self.object1 : > ? ? ## if I add(or remove) fields/methods in module1 (and save) then > ? ? ## I have them available(or disappeared) in the completion when > executed from this submodule. > ? ? ## This ofcourse permits to save me of remembering all of the > class1 attributes/methods when I'm working with self.object1 from > within one of class2 methods. > > What do you think of this ? > > I guess there can be others ways of doing this.. ?? > > Thanks, > > Regards, > > Greg. > > note: I'm using Eclipse 3.5.2 with pydev so (I don't really know how > others IDE can handle this case) . You might want to test with Wing IDE http://wingware.com/ using the 10 day trial version to see if that works just for kicks. I've heard it has the best autocomplete of all IDEs out there. From python at mrabarnett.plus.com Wed Dec 8 11:24:02 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 08 Dec 2010 16:24:02 +0000 Subject: Wanted: slow regexes In-Reply-To: <20101208124225.GA4846@xrgtn-q40> References: <4CFC61B0.8000109@mrabarnett.plus.com> <20101208124225.GA4846@xrgtn-q40> Message-ID: <4CFFB122.5040504@mrabarnett.plus.com> On 08/12/2010 12:42, Alexander Gattin wrote: > Hello, > > On Mon, Dec 06, 2010 at 04:08:16AM +0000, MRAB wrote: >> I'm looking for examples of regexes which are >> slow (especially those which seem never to >> finish) but whose results are known. > > does it have anything to do with > http://swtch.com/~rsc/regexp/regexp1.html? > The new regex still uses backtracking. Interestingly, that webpage says that: ("a" x 100000) =~ /^(ab?)*$/ caused Perl to segfault. I tried it and it didn't segfault, but it didn't match either, although: ("a" x 10000) =~ /^(ab?)*$/ did match. Neither the re nor regex modules had any problem with it! From katie at coderstack.co.uk Wed Dec 8 12:28:34 2010 From: katie at coderstack.co.uk (Katie T) Date: Wed, 8 Dec 2010 17:28:34 +0000 Subject: Calling FORTAN dll functions from Python In-Reply-To: <4cfe167a$0$81476$e4fe514c@news.xs4all.nl> References: <4cfe167a$0$81476$e4fe514c@news.xs4all.nl> Message-ID: On Tue, Dec 7, 2010 at 11:11 AM, Alex van der Spek wrote: > Does anyone know how to call functions from FORTRAN dlls in Python? Is it > even possible? I browsed the documentation for Python 2.6.1 and the Python/C > API comes close to what I would like to do but it is strictly limited to C. > > Unfortunately the passing of arguments in C and FORTRAN is very different, > not to mention the differences with strings where FORTRAN expects a hidden > length argument. It could call the FORTRAN dll from C and call the C > functions from Python but is that my only option? > > For reference: I am using Python 2.6.1 FORTRAN powerstation 4.0. It is not > an option to translate the FORTRAN code to C (using f2c) as the source code > is the official ASME version of calculating steam tables. > > I've done it before by creating C wrapper function and it was relatively painless, using C wrappers means that it's much easier to integrate into other languages as well if you need to do more integration down the line. Katie -- CoderStack http://www.coderstack.co.uk The Software Developer Job Board -------------- next part -------------- An HTML attachment was scrubbed... URL: From devplayer at gmail.com Wed Dec 8 12:32:58 2010 From: devplayer at gmail.com (DevPlayer) Date: Wed, 8 Dec 2010 09:32:58 -0800 (PST) Subject: Replacing globals in exec by custom class References: Message-ID: Couple of things: I don't think this is what you want: def __getitem__(self, key): import __builtin__ if key == 'xx': return 'xx' I won't return a KeyError for any string you give g[] It will return 'xx' only if you supply key='xx' and ignore every other key=??? With the above code you can do g['yyy'] and you would get None For your example code to work, line 14 in your example needs to be: elif key in self.__dict__: # (change else to elif) for your dict (or globalscl) to act like other dicts() add an else: raise KeyError( 'Key not found: %s' % (key,)) __dict__ of a dict I believe is not the namespace of dict. I thought dict[key] and dict.__dict__[key] where not the same place __dict__ of dict in Python 2.5 and prior was rumored to be buggy and unused. Don't know about Python 2.6 + I thought __getitem__() did not look in __dict__ of dict(). If I copy your code into a module globalcl.py and comment out "print xx" in the string, and in PyCrust I "import globalcl" I too get the results and errors you claim. If I then do: >>>globalcl.g.keys() I get: ['__builtins__'] >>>globalcl.g['__builtins__'] I get: nothing (or None) >>>globalcl.g['__builtin__'] I get: nothing (or None) # ------------------------- # interesting part >>>globalcl.g['xx'] I get: 'xx' >>>if 'xx' in globalcl.g: ... print True ...else: ... print False I get: False # ------------------------- >>>globalcl.g.__builtins__ AttributeError: 'Global' object has no attribute __builtins__' >>>globalcl.g.__builtins__ AttributeError: 'Global' object has no attribute '__builtin__' >>>globalcl.g.__dict__ {'q': } From devplayer at gmail.com Wed Dec 8 12:36:39 2010 From: devplayer at gmail.com (DevPlayer) Date: Wed, 8 Dec 2010 09:36:39 -0800 (PST) Subject: Replacing globals in exec by custom class References: Message-ID: <331b53be-f6d3-4f12-8ec5-9547c09c8001@h17g2000pre.googlegroups.com> Shouldn't return 'xx' be return self['xx'] From devplayer at gmail.com Wed Dec 8 12:47:30 2010 From: devplayer at gmail.com (DevPlayer) Date: Wed, 8 Dec 2010 09:47:30 -0800 (PST) Subject: Replacing globals in exec by custom class References: Message-ID: Shouldn't return 'xx' be return self['xx' I don't know why precisely you're using a class as a global namespace, not that I personally find fault with it. But here are some other things you can do. Idea one: ====================================================== class NS(object): """place to put junk""" ns = NS() ns.global_var1 = "SPAM and eggs" ns.global_var2 = "use as you like just prefix with ns." del ns.global_var # because I'm fickle dir(ns) Idea two: ====================================================== Instead of a class as a global namespace, use a module ns.py ------ """My global namespace""" # do not import anything or make # classes or run functions here, just a place to have varibles ns_var = "var defined in ns.py" ignore = ['__builtins__', '__class__', '__delattr__', '__dict__', '__doc__', '__file__', '__format__', '__getattribute__', '__hash__', '__init__', '__name__', '__new__', '__package__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__'] main.py -------- import ns import mod1 import mod2 import mod3 ns.main_var = "this is main var" ns.mod3_var = mod3.mod3_var ns.mod3_somefunc_var = mod3.somefunc.somefunc_var mod3.show( "ns.ns_var", ns.ns_var) mod3.show( "ns.main_var", ns.main_var) mod3.show( "ns.mod1_var", ns.mod1_var) mod3.show( "ns.mod2_var", ns.mod2_var) mod3.show( "ns.somefunc_var", ns.somefunc_var) mod3.show( "ns.mod3_var", ns.mod3_var) mod3.show( "ns.mod3_somefunc_var", ns.mod3_somefunc_var) mod3.show( "dir(ns)", dir(ns)) mod3.list_globals() mod1.py ------- import ns # good usage; var not in mod1 global namespace and value is not copied # from one namespace to another but just put in it. ns.mod1_var = "this is text in mod1" # therefore by doing this your code in mod1 is likely to use # ns.mod1_var and not just mod1_var -is- not ns.mod1_var mod2.py ------- import ns ns.mod2_var = "text in mod2" def somefunc(): # good app globals ns.somefunc_var = "make a var not in the global namespace of the mod2" ns.renamed_var = "rename this" somefunc() mod3.py ------- # mod3_var is misleading; because you might use it but mod3.mod3_var # would not be the same value as the ns.mod3_var mod3_var = "not assigned to ns from in mod3.py but from main.py" def somefunc(): # bad globals somefunc.somefunc_var = "make a var not in the global namespace of the mod3" somefunc.renamed_var = "rename this" somefunc() # instinate somefunc_var def show(astring, avalue): print astring print ' ', str(avalue) def list_globals(): print 'ns variable list' import ns print ' [', for item in dir(ns): if not item in ns.ignore: print "'" + item.strip() + "', ", print ']' From astar at spamcop.net Wed Dec 8 13:05:22 2010 From: astar at spamcop.net (astar) Date: Wed, 8 Dec 2010 10:05:22 -0800 (PST) Subject: Python creates "locked" temp dir References: <0c30c818-f73b-4b09-b707-64ea457c757d@z26g2000prf.googlegroups.com> <91dca7c4-00c7-44ad-8902-54221534107c@o9g2000pre.googlegroups.com> <51e4ed46-41dd-46db-b3c4-0fdb475be97f@o14g2000prn.googlegroups.com> Message-ID: Hi, I recently got caught on tempfiles with respect to urllib.urlretrieve, which can create a tmpfile. Ah, but the file simply could not be found on the file system, even as root. But within the program that created the tmpfile, you could do useful things with the tmpfile. So the discussion in this thread is useful to me in understanding the rules. But having been given a clue by someone else, I never did find any python library documentation that was at all informative, even to the level of discourse in this thread. But here is a relevant question: I wonder if a child process is the *same* process as the parent for these purposes? Thanks. max From alust at alust.homeunix.com Wed Dec 8 13:06:01 2010 From: alust at alust.homeunix.com (alust) Date: Wed, 8 Dec 2010 10:06:01 -0800 (PST) Subject: del operator and global namespace Message-ID: Hello, Can somebody explain this strange (to me) effect please. In this program it is impossible to access a global variable within a function: $ cat /tmp/test.py x='xxx' def f(): print x del x f() $ python /tmp/test.py Traceback (most recent call last): File "/tmp/test.py", line 6, in f() File "/tmp/test.py", line 3, in f print x UnboundLocalError: local variable 'x' referenced before assignment But if we comment the del operator the program will work: $ cat /tmp/test.py x='xxx' def f(): print x #del x f() $ python /tmp/test.py xxx So why in this example the print operator is influenced by del operator that should be executed after it? -- Thanks, Alexei From affdfsdfdsfsd at b.com Wed Dec 8 13:23:05 2010 From: affdfsdfdsfsd at b.com (Tracubik) Date: 08 Dec 2010 18:23:05 GMT Subject: email discovering code Message-ID: <4cffcd09$0$6546$4fafbaef@reader4.news.tin.it> Hi all, i remember i've found somewhere (i think here but i'm not sure) a signature of a user with a strange python code that, if runned on terminal, reveal the email of the contact Can anyone help me finding it? thanks Nico From lists at cheimes.de Wed Dec 8 13:23:57 2010 From: lists at cheimes.de (Christian Heimes) Date: Wed, 08 Dec 2010 19:23:57 +0100 Subject: Python creates "locked" temp dir In-Reply-To: References: <0c30c818-f73b-4b09-b707-64ea457c757d@z26g2000prf.googlegroups.com> <91dca7c4-00c7-44ad-8902-54221534107c@o9g2000pre.googlegroups.com> <51e4ed46-41dd-46db-b3c4-0fdb475be97f@o14g2000prn.googlegroups.com> Message-ID: Am 08.12.2010 19:05, schrieb astar: > Hi, > > I recently got caught on tempfiles with respect to > urllib.urlretrieve, which can create a tmpfile. Ah, but the file > simply could not be found on the file system, even as root. But > within the program that created the tmpfile, you could do useful > things with the tmpfile. So the discussion in this thread is useful > to me in understanding the rules. But having been given a clue by > someone else, I never did find any python library documentation that > was at all informative, even to the level of discourse in this > thread. By default the tempfile module creates anonymous temporary files. The files are created with O_CREAT | O_EXCL and unlinked ASAP. As a result the temporary file no longer has a filename on the file system, just an open file descriptor in the current process. If you need a file with a name, use the NamedTemporaryFile feature of the tempfile module. Christian From awilliam at whitemice.org Wed Dec 8 13:24:53 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Wed, 08 Dec 2010 13:24:53 -0500 Subject: class browser In-Reply-To: References: Message-ID: <1291832693.3706.0.camel@linux-yu4c.site> On Wed, 2010-12-08 at 13:18 +0530, Rustom Mody wrote: > If I have a medium to large python code base to browse/study, what are > the class browsers available? Monodevelop has good Python support which includes a working Python class browser for Python projects & solutions. From lists at cheimes.de Wed Dec 8 13:26:59 2010 From: lists at cheimes.de (Christian Heimes) Date: Wed, 08 Dec 2010 19:26:59 +0100 Subject: Python creates "locked" temp dir In-Reply-To: <91dca7c4-00c7-44ad-8902-54221534107c@o9g2000pre.googlegroups.com> References: <0c30c818-f73b-4b09-b707-64ea457c757d@z26g2000prf.googlegroups.com> <91dca7c4-00c7-44ad-8902-54221534107c@o9g2000pre.googlegroups.com> Message-ID: Am 08.12.2010 10:31, schrieb Alex Willmer: > 2. When you say "I am unable to access". Do you mean another script/ > process is unable to access? If so, that is the point of mkdtemp() - > to make a temporary directory that _only_ the creating process can > access. If you want to share it then tempfile is not the right module > for you. There isn't a way to limit access to a single process. mkdtemp creates the directory with mode 0700 and thus limits it to the (effective) user of the current process. Any process of the same user is able to access the directory. Christian From python at mrabarnett.plus.com Wed Dec 8 13:32:14 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 08 Dec 2010 18:32:14 +0000 Subject: del operator and global namespace In-Reply-To: References: Message-ID: <4CFFCF2E.6080506@mrabarnett.plus.com> On 08/12/2010 18:06, alust wrote: > Hello, > > Can somebody explain this strange (to me) effect please. > > In this program it is impossible to access a global variable within a > function: > > $ cat /tmp/test.py > x='xxx' > def f(): > print x > del x > > f() > > $ python /tmp/test.py > Traceback (most recent call last): > File "/tmp/test.py", line 6, in > f() > File "/tmp/test.py", line 3, in f > print x > UnboundLocalError: local variable 'x' referenced before assignment > > But if we comment the del operator the program will work: > > $ cat /tmp/test.py > x='xxx' > def f(): > print x > #del x > > f() > > $ python /tmp/test.py > xxx > > So why in this example the print operator is influenced by del > operator > that should be executed after it? > The Python source code is compiled to bytecodes which are then interpreted. It's during the compilation stage that it determines whether a name is local. If you bind to a name: x = 0 or del a name: del x anywhere in the function, it takes that name to be local. When it actually interprets the bytecode at the print statement it tries to reference the name, but nothing has been bound to it yet, so it raises an exception. From gerald.britton at gmail.com Wed Dec 8 13:39:45 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Wed, 8 Dec 2010 13:39:45 -0500 Subject: PEP8 compliance and exception messages ? Message-ID: I'm a bit late to the discussion, but remembering that raise takes an expression, I can break it up like this: >>> raise ( ... Exception ( ... "Long " ... "exception " ... "text." ... ) ... ) Traceback (most recent call last): File "", line 3, in Exception: Long exception text Then, you can indent the individual lines any way you like. -- Gerald Britton From drsalists at gmail.com Wed Dec 8 13:52:00 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 8 Dec 2010 10:52:00 -0800 Subject: del operator and global namespace In-Reply-To: References: Message-ID: Please try adding "global x" to the beginning of f(). On Wed, Dec 8, 2010 at 10:06 AM, alust wrote: > Hello, > > Can somebody explain this strange (to me) effect please. > > In this program it is impossible to access a global variable within a > function: > > $ cat /tmp/test.py > x='xxx' > def f(): > ? ? print x > ? ? del x > > f() > > $ python /tmp/test.py > Traceback (most recent call last): > ? File "/tmp/test.py", line 6, in > ? ? f() > ? File "/tmp/test.py", line 3, in f > ? ? print x > UnboundLocalError: local variable 'x' referenced before assignment > > But if we comment the del operator the program will work: > > $ cat /tmp/test.py > x='xxx' > def f(): > ? ? print x > ? ? #del x > > f() > > $ python /tmp/test.py > xxx > > So why in this example the print operator is influenced by del > operator > that should be executed after it? > > -- > Thanks, Alexei > -- > http://mail.python.org/mailman/listinfo/python-list > From sudheer.s at sudheer.net Wed Dec 8 14:11:00 2010 From: sudheer.s at sudheer.net (Sudheer Satyanarayana) Date: Thu, 09 Dec 2010 00:41:00 +0530 Subject: email discovering code In-Reply-To: <4cffcd09$0$6546$4fafbaef@reader4.news.tin.it> References: <4cffcd09$0$6546$4fafbaef@reader4.news.tin.it> Message-ID: <4CFFD844.2000104@sudheer.net> On 12/08/2010 11:53 PM, Tracubik wrote: > Hi all, > i remember i've found somewhere (i think here but i'm not sure) a > signature of a user with a strange python code that, if runned on > terminal, reveal the email of the contact > > Can anyone help me finding it? > > thanks > Nico > import base64 encoded = base64.b64encode('my at email.address') print base64.b64decode(encoded) -- With warm regards, Sudheer. S Personal home page - http://sudheer.net | Tech Chorus - http://techchorus.net Web and IT services - http://binaryvibes.co.in From daniel.goertzen at gmail.com Wed Dec 8 14:42:00 2010 From: daniel.goertzen at gmail.com (Dan) Date: Wed, 8 Dec 2010 11:42:00 -0800 (PST) Subject: Can't deepcopy bytes-derived class Message-ID: <69dc1506-be6f-443c-95b8-7f214510f0ed@p7g2000prb.googlegroups.com> I have a simple type derived from bytes... class atom(bytes): pass ... that I cannot deepcopy(). The session below demonstrates how deepcopy() of "bytes" works fine, but deepcopy() of "atom" does not. What's going wrong? Thanks, Dan. Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit (Intel)] Type "help", "copyright", "credits" or "license" for more information. >>> import copy >>> class atom(bytes): ... pass ... >>> copy.deepcopy(b'abc') b'abc' >>> copy.deepcopy(atom(b'abc')) Traceback (most recent call last): File "C:\Program Files (x86)\Wing IDE 3.2\src\debug\tserver \_sandbox.py", line 1, in # Used internally for debug sandbox under external interpreter File "C:\Python31\Lib\copy.py", line 173, in deepcopy y = _reconstruct(x, rv, 1, memo) File "C:\Python31\Lib\copy.py", line 280, in _reconstruct y = callable(*args) File "C:\Python31\Lib\copyreg.py", line 88, in __newobj__ return cls.__new__(cls, *args) builtins.TypeError: string argument without an encoding >>> From tjreedy at udel.edu Wed Dec 8 15:00:12 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 08 Dec 2010 15:00:12 -0500 Subject: Replacing globals in exec by custom class In-Reply-To: References: Message-ID: On 12/8/2010 8:01 AM, Jonathan S wrote: > class Global(dict): > def __init__(self): > pass > def __getitem__(self, key): > import __builtin__ > if key == 'xx': > return 'xx' > > if hasattr(__builtin__, key): > return getattr(__builtin__, key) > > else key in self.__dict__: > return self.__dict__[key] syntax error > def __setitem__(self, key, value): > self.__dict__[key] = value > > def __str__(self): > return ' ' + unicode(self.__dict__) > > > code=""" > print globals() > print xx # Does work, prints 'xx' > > def q(): > print globals().__getitem__('xx') # Does work, prints 'xx' > print globals()['xx'] # Does work, prints 'xx' > print xx # Does not work, cannot find xx > q() > """ > g = Global() > > exec(compile(code, 'my code', 'exec'), g, g) > }}} When asking such questions, paste both the actual code that compiled and ran and the actual traceback you got in response. -- Terry Jan Reedy From brenNOSPAMbarn at NObrenSPAMbarn.net Wed Dec 8 15:09:19 2010 From: brenNOSPAMbarn at NObrenSPAMbarn.net (OKB (not okblacke)) Date: Wed, 8 Dec 2010 20:09:19 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> <7x39qbfhd8.fsf@ruckus.brouhaha.com> <87lj42liu2.fsf.mdw@metalzone.distorted.org.uk> <7491b308-0e41-416b-84e9-1ed5ff3408be@n32g2000pre.googlegroups.com> <874oaqld0v.fsf.mdw@metalzone.distorted.org.uk> Message-ID: Mark Wooding wrote: > Any code called from within the `with handler' context will (unless > overridden) cause a call `toy(x, 0)' to return 42. Even if the `with > handler' block calls other functions and so on. Note also that the > expression of this is dynamically further from where the error is > signalled than the resume point (which is within the same function). > You can't do this with `try' ... `except'. Which was, of course, the > point. This is an interesting setup, but I'm not sure I see why you need it. If you know that, in a particular context, you want toy(x, 0) to result in 42 instead of ZeroDivisionError, why not just define safeToy(x, y): try: retVal = toy(x, y) except ZeroDivisionError: retVal = 42 return retVal . . . and then call safeToy instead of toy in those contexts? -- --OKB (not okblacke) Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown From mdw at distorted.org.uk Wed Dec 8 15:48:57 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 08 Dec 2010 20:48:57 +0000 Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> <7x39qbfhd8.fsf@ruckus.brouhaha.com> <87lj42liu2.fsf.mdw@metalzone.distorted.org.uk> <7491b308-0e41-416b-84e9-1ed5ff3408be@n32g2000pre.googlegroups.com> <874oaqld0v.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87zksghtxi.fsf.mdw@metalzone.distorted.org.uk> "OKB (not okblacke)" writes: > This is an interesting setup, but I'm not sure I see why you need > it. If you know that, in a particular context, you want toy(x, 0) to > result in 42 instead of ZeroDivisionError, ... and that's the point. You don't know whether you'll need it at the call site. Something further up has decided that, in its context, 42 shall be the magic value returned. In some other context, there shouldn't be a magic value, and the exception should terminate the program. My toy example was just that: a minimal example showing the machinery in action. The value of separating out exception handling like this is only apparent if there's a fair amount of code in between the policy (`return 42') and the site where the exception is signalled. Small examples of powerful abstractions aren't very convincing: a small example trivially doesn't require powerful abstraction. Sorry. -- [mdw] From nagle at animats.com Wed Dec 8 16:01:28 2010 From: nagle at animats.com (John Nagle) Date: Wed, 08 Dec 2010 13:01:28 -0800 Subject: Comparisons of incompatible types In-Reply-To: <87ipz5jfr9.fsf.mdw@metalzone.distorted.org.uk> References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <4cfebe65$0$1590$742ec2ed@news.sonic.net> <87ipz5jfr9.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4cfff225$0$1650$742ec2ed@news.sonic.net> On 12/7/2010 3:59 PM, Mark Wooding wrote: >> Exactly one of >> > >> > a> b >> > a = b >> > a< b >> > >> > is true, or an type exception must be raised. > This will get the numerical people screaming. Non-signalling NaNs are > useful, and they don't obey these axioms. As a sometime numerical person, I've been screaming at this from the other side. The problem with comparing non-signalling NaNs is that eventually, the program has to make a control flow decision, and it may not make it correctly. I used to do dynamic simulation engines for animation. I was probably the first person to get ragdoll physics to work right, back in 1996-1997. In hard collisions, the program would get floating point overflows, and I had to abort the interation, back up, cut the time step down, and go forward again, until the time step was small enough to allow stable integration. This was under Windows on x86, where it's possible, in a Windows-dependent way, to catch signalling NaNs and turn the hardware exception into a C++ exception. If the computation just plowed ahead with non-signalling NaNs, with a check at the end, it could go wrong and produce bad results, because incorrect branches would be taken and the final bogus results might not contain NaNs. I personally think that comparing NaN with numbers or other NaNs should raise an exception. There's no valid result for such comparisons. John Nagle From tjreedy at udel.edu Wed Dec 8 16:16:11 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 08 Dec 2010 16:16:11 -0500 Subject: Can't deepcopy bytes-derived class In-Reply-To: <69dc1506-be6f-443c-95b8-7f214510f0ed@p7g2000prb.googlegroups.com> References: <69dc1506-be6f-443c-95b8-7f214510f0ed@p7g2000prb.googlegroups.com> Message-ID: On 12/8/2010 2:42 PM, Dan wrote: > I have a simple type derived from bytes... > > class atom(bytes): > pass > > ... that I cannot deepcopy(). The session below demonstrates how > deepcopy() of "bytes" works fine, but deepcopy() of "atom" does not. > What's going wrong? > > Thanks, > Dan. > > > Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit > (Intel)] > Type "help", "copyright", "credits" or "license" for more information. >>>> import copy >>>> class atom(bytes): > ... pass > ... >>>> copy.deepcopy(b'abc') > b'abc' >>>> copy.deepcopy(atom(b'abc')) > Traceback (most recent call last): > File "C:\Program Files (x86)\Wing IDE 3.2\src\debug\tserver > \_sandbox.py", line 1, in > # Used internally for debug sandbox under external interpreter > File "C:\Python31\Lib\copy.py", line 173, in deepcopy > y = _reconstruct(x, rv, 1, memo) > File "C:\Python31\Lib\copy.py", line 280, in _reconstruct > y = callable(*args) > File "C:\Python31\Lib\copyreg.py", line 88, in __newobj__ > return cls.__new__(cls, *args) > builtins.TypeError: string argument without an encoding You could trace through copy.py and copyreg.py to see where bytes and atom get treated differently. This might be a bug that should be reported on the tracker, but I do not know. Let see what anyone else says. -- Terry Jan Reedy From nagle at animats.com Wed Dec 8 17:49:55 2010 From: nagle at animats.com (John Nagle) Date: Wed, 08 Dec 2010 14:49:55 -0800 Subject: Comparisons of incompatible types In-Reply-To: <4cff5429$0$30002$c3e8da3$5496439d@news.astraweb.com> References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <871v5t13ok.fsf@benfinney.id.au> <4cff5429$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4d000b8f$0$1640$742ec2ed@news.sonic.net> On 12/8/2010 1:47 AM, Steven D'Aprano wrote: > On Wed, 08 Dec 2010 11:58:03 +1100, Ben Finney wrote: > >> Carl Banks writes: >> >>> On Dec 6, 4:17 pm, Steven D'Aprano>> +comp.lang.pyt... at pearwood.info> wrote: >>>> Nevertheless, I agree that in hindsight, the ability to sort such >>>> lists is not as important as the consistency of comparisons. >>> >>> I think that feeling the need to sort non-homogenous lists is >>> indicative of bad design. >> >> It can also be indicative of code written for a Python that doesn't have >> sets. > > Or a list that contains unhashable objects. If you can't hash it, and it doesn't have some definition of comparison associated with the object, you probably can't order it properly, either. "<" can't be some random function. For sorting to work, a < b and b < c implies a < c must hold. John Nagle From nad at acm.org Wed Dec 8 19:11:14 2010 From: nad at acm.org (Ned Deily) Date: Wed, 08 Dec 2010 16:11:14 -0800 Subject: Can't deepcopy bytes-derived class References: <69dc1506-be6f-443c-95b8-7f214510f0ed@p7g2000prb.googlegroups.com> Message-ID: In article , Terry Reedy wrote: > On 12/8/2010 2:42 PM, Dan wrote: > > I have a simple type derived from bytes... > > > > class atom(bytes): > > pass > > > > ... that I cannot deepcopy(). The session below demonstrates how > > deepcopy() of "bytes" works fine, but deepcopy() of "atom" does not. [...] > > Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit > > (Intel)] > > Type "help", "copyright", "credits" or "license" for more information. > >>>> import copy > >>>> class atom(bytes): > > ... pass > > ... > >>>> copy.deepcopy(b'abc') > > b'abc' > >>>> copy.deepcopy(atom(b'abc')) > > Traceback (most recent call last): > > File "C:\Program Files (x86)\Wing IDE 3.2\src\debug\tserver > > \_sandbox.py", line 1, in > > # Used internally for debug sandbox under external interpreter > > File "C:\Python31\Lib\copy.py", line 173, in deepcopy > > y = _reconstruct(x, rv, 1, memo) > > File "C:\Python31\Lib\copy.py", line 280, in _reconstruct > > y = callable(*args) > > File "C:\Python31\Lib\copyreg.py", line 88, in __newobj__ > > return cls.__new__(cls, *args) > > builtins.TypeError: string argument without an encoding > > You could trace through copy.py and copyreg.py to see where bytes and > atom get treated differently. > > This might be a bug that should be reported on the tracker, but I do not > know. Let see what anyone else says. FWIW, the example still fails with Python 3.1.3 but seems to work OK with a recent alpha build of Python 3.2. What specific change might have fixed it doesn't come immediately to mind. -- Ned Deily, nad at acm.org From philip at semanchuk.com Wed Dec 8 20:55:33 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 8 Dec 2010 20:55:33 -0500 Subject: is py2exe still active ? In-Reply-To: <0053AA37CC664343BD6FC2E75627821C@teddy> References: <5f32249f-50d4-440e-9005-04f954572894@32g2000yqz.googlegroups.com> <89dd2092-d6e9-4d5c-b966-54df3f48f065@g19g2000yqg.googlegroups.com> <2DEA78DF996B485E8B52F3B29B1124A1@teddy> <4CFEBBAE.2060400@holdenweb.com> <0053AA37CC664343BD6FC2E75627821C@teddy> Message-ID: On Dec 8, 2010, at 5:09 AM, Octavian Rasnita wrote: > Hi Steve, > > I may put some stupid questions because I am very new to Python, but... I heard about pypi/pip. Aren't all these Python libraries (like cxFreeze) provided on a central archive where we can get them and also report the bugs using a single request/issue tracker? Hi Octavian, I didn't see anyone reply to you on the list... The short answer to your question is "no". PyPI stands for the Python Package Index. The key word there is "Index". It's a catalog of packages but many of those packages are hosted elsewhere. The places where those packages are hosted may or may not have an issue tracker, etc. For instance, one the packages that I offer through PyPI (posix_ipc) is hosted on my personal Web site. Hope this helps Philip > ----- Original Message ----- > From: "Steve Holden" > Newsgroups: gmane.comp.python.general > To: "Octavian Rasnita" > Cc: > Sent: Wednesday, December 08, 2010 12:56 AM > Subject: Re: is py2exe still active ? > > >> Octavian: >> >> It's great that you want to let people know about bugs. Put yourself in >> the position of the package maintainer, however. She or he doesn't spend >> all day working on cxFreeze, and probably doesn't even do a Google >> search on cxFreeze very often. So they are unlikely to find out about >> this problem form your well-intentioned note. >> >> It's just possible nobody does care, as I can't find a link to an issue >> tracker - the best I could advise in this case would be to join the >> mailing list by visiting >> >> https://lists.sourceforge.net/lists/listinfo/cx-freeze-users >> >> regards >> Steve >> >> On 12/7/2010 6:49 PM, Octavian Rasnita wrote: >>> This packager is also nice. >>> >>> If someone cares, I've discovered a small bug in it. >>> If Python is installed on another drive than C under Windows, the cxfreeze.bat file still calls Python on the drive C and it doesn't work until it is corrected. >>> >>> Octavian >>> >>> ----- Original Message ----- >>> From: "Cbast" >>> Newsgroups: comp.lang.python >>> To: >>> Sent: Tuesday, December 07, 2010 5:00 PM >>> Subject: Re: is py2exe still active ? >>> >>> >>> On Dec 7, 8:23 am, Anders Persson wrote: >>>> Hi! >>>> When a look att py2exe homepage it is not looking like mutch happen, >>>> as a beginner i was thinking to start with Python 3, but i like to now >>>> if py2exe will be for 3 too. >>>> >>>> Is any one have any info ? >>> >>> I don't have the answer about py2exe, but I'm using cxFreeze to create >>> executables with Python 3.1, if it's what you're looking for. >>> >>> http://cx-freeze.sourceforge.net/ >> >> >> -- >> Steve Holden +1 571 484 6266 +1 800 494 3119 >> PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ >> See Python Video! http://python.mirocommunity.org/ >> Holden Web LLC http://www.holdenweb.com/ > -- > http://mail.python.org/mailman/listinfo/python-list From cdalten at gmail.com Wed Dec 8 21:00:43 2010 From: cdalten at gmail.com (chad) Date: Wed, 8 Dec 2010 18:00:43 -0800 (PST) Subject: Automating a shell session question Message-ID: <50fb4385-f8b7-4754-a8a5-e63820fee3b4@a28g2000prb.googlegroups.com> I manually log into a remote shell and so some stuff. After I do some stuff, I want the rest of the session to be automated. I've tried pexpect using the interact() function. However, I don't see any way to go into non-interactive mode going this route. Ideas? From tjreedy at udel.edu Wed Dec 8 22:05:26 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 08 Dec 2010 22:05:26 -0500 Subject: Can't deepcopy bytes-derived class In-Reply-To: References: <69dc1506-be6f-443c-95b8-7f214510f0ed@p7g2000prb.googlegroups.com> Message-ID: On 12/8/2010 7:11 PM, Ned Deily wrote: > In article, Terry > Reedy wrote: >> On 12/8/2010 2:42 PM, Dan wrote: >>> I have a simple type derived from bytes... >>> >>> class atom(bytes): pass >>> >>> ... that I cannot deepcopy(). The session below demonstrates >>> how deepcopy() of "bytes" works fine, but deepcopy() of "atom" >>> does not. > [...] >>> Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 >>> bit (Intel)] Type "help", "copyright", "credits" or "license" for >>> more information. >>>>>> import copy class atom(bytes): >>> ... pass ... >>>>>> copy.deepcopy(b'abc') >>> b'abc' >>>>>> copy.deepcopy(atom(b'abc')) >>> Traceback (most recent call last): File "C:\Program Files >>> (x86)\Wing IDE 3.2\src\debug\tserver \_sandbox.py", line 1, >>> in # Used internally for debug sandbox under external >>> interpreter File "C:\Python31\Lib\copy.py", line 173, in >>> deepcopy y = _reconstruct(x, rv, 1, memo) File >>> "C:\Python31\Lib\copy.py", line 280, in _reconstruct y = >>> callable(*args) File "C:\Python31\Lib\copyreg.py", line 88, in >>> __newobj__ return cls.__new__(cls, *args) builtins.TypeError: >>> string argument without an encoding >> >> You could trace through copy.py and copyreg.py to see where bytes >> and atom get treated differently. >> >> This might be a bug that should be reported on the tracker, but I >> do not know. Let see what anyone else says. > > FWIW, the example still fails with Python 3.1.3 but seems to work OK > with a recent alpha build of Python 3.2. What specific change might > have fixed it doesn't come immediately to mind. According to difflib.unified_diff, the only difference between Lib/copy.py from 3.1 to 3.2 is 4 lines: + +def _deepcopy_method(x, memo): # Copy instance methods + return type(x)(x.__func__, deepcopy(x.__self__, memo)) +_deepcopy_dispatch[types.MethodType] = _deepcopy_method (and none in copyreg.py) These were added in rev76572 as part of http://bugs.python.org/issue1515 Guido decreed this to be a new feature rather than bugfix, so the change went into future 2.7 and 3.2 and not existing 2.6 and 3.1. Tto verify that these cause the change, comment out in 3.2 or add to 3.1. I have not read through the issue to understand it or why it would affect the OP's code case. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Wed Dec 8 22:30:39 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Dec 2010 03:30:39 GMT Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <4cfebe65$0$1590$742ec2ed@news.sonic.net> <87ipz5jfr9.fsf.mdw@metalzone.distorted.org.uk> <4cfff225$0$1650$742ec2ed@news.sonic.net> Message-ID: <4d004d5f$0$29985$c3e8da3$5496439d@news.astraweb.com> On Wed, 08 Dec 2010 13:01:28 -0800, John Nagle wrote: > On 12/7/2010 3:59 PM, Mark Wooding wrote: >>> Exactly one of >>> > >>> > a> b >>> > a = b >>> > a< b >>> > >>> > is true, or an type exception must be raised. >> This will get the numerical people screaming. Non-signalling NaNs are >> useful, and they don't obey these axioms. > > As a sometime numerical person, I've been screaming at this from > the other side. The problem with comparing non-signalling NaNs is that > eventually, the program has to make a control flow decision, and it may > not make it correctly. Then use signalling NANs. Nobody is suggesting that quiet NANs should be compulsory, or are the solution for all problems. But they're a solution for some problems, which is why people use them. [...] > I personally think that comparing NaN with numbers or other > NaNs should raise an exception. There's no valid result for such > comparisons. If NAN and 1 are unordered, then NAN is not less or equal to 1, nor is it larger than 1. Hence both NAN <= 1 and NAN >= 1 are false. The problem only comes when the caller mistakenly thinks that floats are real numbers, and tries to reason about floats like they would reason about real numbers. -- Steven From debatem1 at gmail.com Wed Dec 8 22:56:43 2010 From: debatem1 at gmail.com (geremy condra) Date: Wed, 8 Dec 2010 19:56:43 -0800 Subject: Comparisons of incompatible types In-Reply-To: <4cfff225$0$1650$742ec2ed@news.sonic.net> References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <4cfebe65$0$1590$742ec2ed@news.sonic.net> <87ipz5jfr9.fsf.mdw@metalzone.distorted.org.uk> <4cfff225$0$1650$742ec2ed@news.sonic.net> Message-ID: On Wed, Dec 8, 2010 at 1:01 PM, John Nagle wrote: > On 12/7/2010 3:59 PM, Mark Wooding wrote: >>> >>> Exactly one of >>> > >>> > ? ? ? a> ?b >>> > ? ? ? a = b >>> > ? ? ? a< ?b >>> > >>> > ?is true, or an type exception must be raised. >> >> This will get the numerical people screaming. ?Non-signalling NaNs are >> useful, and they don't obey these axioms. > > ? As a sometime numerical person, I've been screaming at this from > the other side. ? The problem with comparing non-signalling NaNs is that > eventually, the program has to make a control flow decision, and it > may not make it correctly. > > ? I used to do dynamic simulation engines for animation. ?I was > probably the first person to get ragdoll physics to work right, > back in 1996-1997. ?In hard collisions, the program would get > floating point overflows, and I had to abort the interation, back > up, cut the time step down, and go forward again, until the time > step was small enough to allow stable integration. ?This was > under Windows on x86, where it's possible, in a Windows-dependent > way, to catch signalling NaNs and turn the hardware exception into > a C++ exception. ?If the computation just plowed ahead with > non-signalling NaNs, with a check at the end, it could go wrong > and produce bad results, because incorrect branches would be taken > and the final bogus results might not contain NaNs. > > ? I personally think that comparing NaN with numbers or other > NaNs should raise an exception. ?There's no valid result for > such comparisons. This, in big letters. Geremy Condra From kirby.urner at gmail.com Wed Dec 8 23:03:05 2010 From: kirby.urner at gmail.com (kirby.urner at gmail.com) Date: Wed, 8 Dec 2010 20:03:05 -0800 (PST) Subject: win32 design pattern: COM localserver? Message-ID: <92573244-ab87-4143-9e87-26f851b6a3a1@w17g2000yqh.googlegroups.com> Greetings gurus. I'm faced with the challenge of having a single-threaded proprietary Win32 language wanting to do multiple calls against a Python COM object. Something like... loObj = CREATEOBJECT("map_maker") loObj.report( params, filename) do while .True. yadda yadda enddo RETURN I.e. the client program continues execution while loObj churns away somewhere doing work in Python, say accessing a MySQL database and building a map, embedding it in a PDF. Am I right that the COM object will need to "serve forever" i.e. be built around some non-terminating loop? Will the client's call then spawn a process or thread that continues until finished? All it has to do is leave a file on disk somewhere, then die. But the client can't be kept on the hook until that's all done. I've had good luck doing an InProcess COM object the generates a PDF from ReportLab. But this "stay alive while returning control to the client" challenge looks like it might be a job for sockets? Gee I hope not. Quick links to favorite blog articles will give me a sense of the ballpark... Any clues welcome. Yes, I have the Win32 book from O'Reilly. Kirby PS: my thanks to Ethan Furman for performing maintenance and upgrades on his dbf module on PyPI. The FoxPro gods thank you. http://pypi.python.org/pypi/dbf/0.88.16 PPS: some thoughts about IronPython filed here, after trying to catch up some, sorry about my formatting, here too. http://mail.python.org/pipermail/edu-sig/2010-December/010138.html From nagle at animats.com Wed Dec 8 23:16:57 2010 From: nagle at animats.com (John Nagle) Date: Wed, 08 Dec 2010 20:16:57 -0800 Subject: Comparisons of incompatible types In-Reply-To: References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <4cfebe65$0$1590$742ec2ed@news.sonic.net> <87ipz5jfr9.fsf.mdw@metalzone.distorted.org.uk> <4cfff225$0$1650$742ec2ed@news.sonic.net> Message-ID: <4d005835$0$1597$742ec2ed@news.sonic.net> On 12/8/2010 7:56 PM, geremy condra wrote: > On Wed, Dec 8, 2010 at 1:01 PM, John Nagle wrote: >> On 12/7/2010 3:59 PM, Mark Wooding wrote: >>>> >>>> Exactly one of >>>>> >>>>> a > b >>>>> a = b >>>>> a < b >>>>> >>>>> is true, or an type exception must be raised. Here's an example where this issue produces invalid results in Python. >>> NaN = float("nan") >>> arr = [1.0, 4.0, 3.0, 2.0, 5.0, NaN, 6.0, 3.0, NaN, 0.0, 1.0, 4.0, 3.0, 2.0, 5.0, NaN, 6.0, 3.0, NaN, 0.0] >>> sorted(arr) [0.0, 0.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 3.0, 3.0, 4.0, 5.0, nan, 5.0, 6.0, nan, 4.0, nan, 6.0, nan] The sorted numerical values aren't in order. Note the 4.0 near the end, after the 6.0. "sort" has failed because it assumes that a < b and b < c implies a < c. But that's not a valid assumption here. It's not good to break trichotomy. John Nagle From astan.chee at gmail.com Thu Dec 9 00:17:27 2010 From: astan.chee at gmail.com (Astan Chee) Date: Thu, 9 Dec 2010 16:17:27 +1100 Subject: RCX using python serial help In-Reply-To: <4CFEC76B.9080503@mrabarnett.plus.com> References: <4CFEC76B.9080503@mrabarnett.plus.com> Message-ID: Thanks for that help. I really appriciate it. My next question is how do I code or what is the checksum? The sum of opcode and arguments in hex and then mod 256? Does it include the compliment opcode and arguments as well? Is the checksum compliment equal to the sum of the opcode (and arguments) compliment? Thanks again for the clarification On 12/8/10, MRAB wrote: > On 06/12/2010 15:37, Astan Chee wrote: >> Hi, >> I've got a lego mindstorm RCX 1.0 (but firmware is 2.0) that uses one of >> those old serial IR towers to control the microcontroller. I've had a >> look around at python's serial documentation as well as the RCX's >> documentation and I'm trying to write something to control the RCX >> directly using python. Several examples from of doing this in python >> include using lnp (i think) and that doesn't quite run well in windows. >> I've had a look at the C++ code and some protocol documentation here: >> http://www.generation5.org/content/2001/rob08.asp and converted it to >> python. I've attached it at the end of the email. So now I've figured >> out how to check for the battery level and it seems to work (I've tested >> it on my RCX) but I'm confused with the other documentation (e.g. >> http://graphics.stanford.edu/~kekoa/rcx/ ) about how to do this in >> python or what this all means. I was wondering if anyone can help me >> complete these? or maybe help me do it step-by-step? >> Thanks for any help. > [snip] > Here's a brief summary of the protocol: > > A command or request to the microcontroller is a packet consisting of a > header, an opcode, arguments, and a checksum. > > The header used in the documentation is 0x55, 0xFF, 0x00. > > The opcode is 1 byte, followed by its one's complement. > > The argument is 0 or more bytes, each followed by its one's complement. > > The checksum is the sum of the opcode and the arguments, modulo 256, > followed by its one's complement. > > A reply from the microcontroller is also a packet consisting of a > header, an opcode, arguments, and a checksum. > > The header is the same as the original command or request. > > The opcode is the one's complement of the original opcode, followed by > its one's complement (ie, the original opcode). > > The argument is 0 or more bytes, each followed by its one's complement. > > The checksum is the sum of the opcode and the arguments, modulo 256, > followed by its one's complement. > > The microcontroller will ignore a packet whose opcode is the same as the > previous one; this is to prevent unintended duplicates due to > communication errors. > > Each opcode has 2 alternatives, one with bit 3 clear and the other with > bit 3 set (bitwise-ored with 0x08), so if you do want to send a command > or request with the same opcode as the previous packet you can just use > the alternative form. > -- > http://mail.python.org/mailman/listinfo/python-list > From rustompmody at gmail.com Thu Dec 9 01:10:42 2010 From: rustompmody at gmail.com (rusi) Date: Wed, 8 Dec 2010 22:10:42 -0800 (PST) Subject: trace cmd line args Message-ID: <37243f10-91f5-4a18-959f-fed96c145b36@29g2000prb.googlegroups.com> I am unable to get trace to not trace system modules. I tried: $ python -m trace --listfuncs tt.py --ignore-module 'bdb' > tracefile $ python -m trace --listfuncs --ignore-dir /usr/lib/python2.6 tt.py > tracefile and many other combinations But anyhow my tracefile contains lines like this: filename: /usr/lib/python2.6/bdb.py, modulename: bdb, funcname: filename: /usr/lib/python2.6/bdb.py, modulename: bdb, funcname: Bdb filename: /usr/lib/python2.6/bdb.py, modulename: bdb, funcname: BdbQuit filename: /usr/lib/python2.6/bdb.py, modulename: bdb, funcname: Breakpoint filename: /usr/lib/python2.6/bdb.py, modulename: bdb, funcname: Tdb filename: /usr/lib/python2.6/cmd.py, modulename: cmd, funcname: filename: /usr/lib/python2.6/cmd.py, modulename: cmd, funcname: Cmd filename: /usr/lib/python2.6/collections.py, modulename: collections, funcname: filename: /usr/lib/python2.6/collections.py, modulename: collections, funcname: namedtuple filename: /usr/lib/python2.6/dis.py, modulename: dis, funcname: filename: /usr/lib/python2.6/inspect.py, modulename: inspect, funcname: filename: /usr/lib/python2.6/inspect.py, modulename: inspect, funcname: BlockFinder filename: /usr/lib/python2.6/inspect.py, modulename: inspect, funcname: EndOfBlock filename: /usr/lib/python2.6/opcode.py, modulename: opcode, funcname: filename: /usr/lib/python2.6/opcode.py, modulename: opcode, funcname: def_op filename: /usr/lib/python2.6/opcode.py, modulename: opcode, funcname: jabs_op filename: /usr/lib/python2.6/opcode.py, modulename: opcode, funcname: jrel_op filename: /usr/lib/python2.6/opcode.py, modulename: opcode, funcname: name_op filename: /usr/lib/python2.6/pdb.py, modulename: pdb, funcname: filename: /usr/lib/python2.6/pdb.py, modulename: pdb, funcname: Pdb filename: /usr/lib/python2.6/pdb.py, modulename: pdb, funcname: Restart filename: /usr/lib/python2.6/pprint.py, modulename: pprint, funcname: From horos11 at gmail.com Thu Dec 9 02:29:52 2010 From: horos11 at gmail.com (Edward Peschko) Date: Wed, 8 Dec 2010 23:29:52 -0800 Subject: completely implicit interpolation based on a frame object Message-ID: >> Any ideas would be great on this, including pitfalls that people see >> in implementing it. >> > http://docs.python.org/library/string.html#template-strings > > regards > ?Steve Steve, Thanks for the tip, I did look at templates and decided that they weren't quite completely what I was looking for, although they could be part of the solution. 1. they require ${ } around the variables in question that you want to interpolate. When run through the trace hook, normal code doesn't do that. 2. they don't provide (AFAICT) a complete interpolation solution. Suppose I want to define custom interpolations in my tracer, like say, expanding out lists and dicts, or fleshing out objects using their stringification method. Does template do this? Formats may be a bit closer here, but I'm not sure if they are workable (or usable) with 2.5... which is where I need to work. Ed From ian.g.kelly at gmail.com Thu Dec 9 02:40:57 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 09 Dec 2010 00:40:57 -0700 Subject: 64 bit memory usage In-Reply-To: References: Message-ID: On 12/8/2010 11:42 PM, Dennis Lee Bieber wrote: > The page file can be larger than physical memory because it contains > memory "images" for multiple processes. However, all those "images" have > to map into the physically addressable memory -- so a process is likely > limited to physical memory, but you can have multiple processes adding > up to physical + pagefile in total. Only those pages that are currently paged in need be mapped to physical memory. The rest are not mapped to anything at all (other than a location in the page file) -- once a page is paged out, it need not be put back in its original page frame when it is paged in again. Since a process need not have all its pages in physical memory simultaneously, there is no reason to suppose that a single process could not consume the entirety of the available virtual memory (minus what is used by the operating system) on a 64-bit system (the same cannot be said of a 32-bit system, where the total virtual memory available may well be larger than the addressable space). From steve+comp.lang.python at pearwood.info Thu Dec 9 02:58:29 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Dec 2010 07:58:29 GMT Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <4cfebe65$0$1590$742ec2ed@news.sonic.net> <87ipz5jfr9.fsf.mdw@metalzone.distorted.org.uk> <4cfff225$0$1650$742ec2ed@news.sonic.net> <4d005835$0$1597$742ec2ed@news.sonic.net> Message-ID: <4d008c25$0$29987$c3e8da3$5496439d@news.astraweb.com> On Wed, 08 Dec 2010 20:16:57 -0800, John Nagle wrote: > Here's an example where this issue produces invalid results in > Python. > > >>> NaN = float("nan") > >>> arr = [1.0, 4.0, 3.0, 2.0, 5.0, NaN, 6.0, 3.0, NaN, 0.0, 1.0, 4.0, > 3.0, 2.0, 5.0, NaN, 6.0, 3.0, NaN, 0.0] > >>> sorted(arr) > [0.0, 0.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 3.0, 3.0, 4.0, 5.0, nan, 5.0, > 6.0, nan, 4.0, nan, 6.0, nan] > > The sorted numerical values aren't in order. Note the 4.0 near the end, > after the 6.0. "sort" has failed because it assumes that a < b and b < > c implies a < c. But that's not a valid assumption here. > > It's not good to break trichotomy. It's perfectly fine to break trichotomy. People do it all the time -- they prefer chicken to pizza, pizza to steak, but prefer steak to chicken. (Modulo whatever foods you prefer. Or sports, or politicians, or any one of many things which don't make up an equivalence relationship.) Equivalence relationships make up only a tiny portion of relationships, and it is both useful and conventional to use the same operators in both situations. What's not good is to assume trichotomy when it doesn't apply, but that's no different from any other faulty assumption, e.g. a coder who assumes multiplication is always commutative may be puzzled why his matrix calculations are frequently wrong. Python's sort assumes trichotomy, even when sorting floats. Perhaps it shouldn't. But one way or another, that's an issue with sort, not with the idea that there are data types where trichotomy doesn't apply. And like it or not, floats are one of those data types, just as neither commutativity nor associativity applies to floats -- even excluding NANs and INFs. -- Steven From orasnita at gmail.com Thu Dec 9 03:31:49 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Thu, 9 Dec 2010 10:31:49 +0200 Subject: is py2exe still active ? References: <5f32249f-50d4-440e-9005-04f954572894@32g2000yqz.googlegroups.com> <89dd2092-d6e9-4d5c-b966-54df3f48f065@g19g2000yqg.googlegroups.com><2DEA78DF996B485E8B52F3B29B1124A1@teddy><4CFEBBAE.2060400@holdenweb.com><0053AA37CC664343BD6FC2E75627821C@teddy> Message-ID: Hi Philip, I thought that pypi works like cpan for Perl, but now I understand. Thank you for clarifications. -- Octavian --- From: "Philip Semanchuk" > > On Dec 8, 2010, at 5:09 AM, Octavian Rasnita wrote: > >> Hi Steve, >> >> I may put some stupid questions because I am very new to Python, but... I heard about pypi/pip. Aren't all these Python libraries (like cxFreeze) provided on a central archive where we can get them and also report the bugs using a single request/issue tracker? > > Hi Octavian, > I didn't see anyone reply to you on the list... > > The short answer to your question is "no". PyPI stands for the Python Package Index. The key word there is "Index". It's a catalog of packages but many of those packages are hosted elsewhere. The places where those packages are hosted may or may not have an issue tracker, etc. > > For instance, one the packages that I offer through PyPI (posix_ipc) is hosted on my personal Web site. > > Hope this helps > Philip > > >> ----- Original Message ----- >> From: "Steve Holden" >> Newsgroups: gmane.comp.python.general >> To: "Octavian Rasnita" >> Cc: >> Sent: Wednesday, December 08, 2010 12:56 AM >> Subject: Re: is py2exe still active ? >> >> >>> Octavian: >>> >>> It's great that you want to let people know about bugs. Put yourself in >>> the position of the package maintainer, however. She or he doesn't spend >>> all day working on cxFreeze, and probably doesn't even do a Google >>> search on cxFreeze very often. So they are unlikely to find out about >>> this problem form your well-intentioned note. >>> >>> It's just possible nobody does care, as I can't find a link to an issue >>> tracker - the best I could advise in this case would be to join the >>> mailing list by visiting >>> >>> https://lists.sourceforge.net/lists/listinfo/cx-freeze-users >>> >>> regards >>> Steve >>> >>> On 12/7/2010 6:49 PM, Octavian Rasnita wrote: >>>> This packager is also nice. >>>> >>>> If someone cares, I've discovered a small bug in it. >>>> If Python is installed on another drive than C under Windows, the cxfreeze.bat file still calls Python on the drive C and it doesn't work until it is corrected. >>>> >>>> Octavian >>>> >>>> ----- Original Message ----- >>>> From: "Cbast" >>>> Newsgroups: comp.lang.python >>>> To: >>>> Sent: Tuesday, December 07, 2010 5:00 PM >>>> Subject: Re: is py2exe still active ? >>>> >>>> >>>> On Dec 7, 8:23 am, Anders Persson wrote: >>>>> Hi! >>>>> When a look att py2exe homepage it is not looking like mutch happen, >>>>> as a beginner i was thinking to start with Python 3, but i like to now >>>>> if py2exe will be for 3 too. >>>>> >>>>> Is any one have any info ? >>>> >>>> I don't have the answer about py2exe, but I'm using cxFreeze to create >>>> executables with Python 3.1, if it's what you're looking for. >>>> >>>> http://cx-freeze.sourceforge.net/ >>> >>> >>> -- >>> Steve Holden +1 571 484 6266 +1 800 494 3119 >>> PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ >>> See Python Video! http://python.mirocommunity.org/ >>> Holden Web LLC http://www.holdenweb.com/ >> -- >> http://mail.python.org/mailman/listinfo/python-list > > -- > http://mail.python.org/mailman/listinfo/python-list From tjreedy at udel.edu Thu Dec 9 03:36:53 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 09 Dec 2010 03:36:53 -0500 Subject: Comparisons of incompatible types In-Reply-To: <4d008c25$0$29987$c3e8da3$5496439d@news.astraweb.com> References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <4cfebe65$0$1590$742ec2ed@news.sonic.net> <87ipz5jfr9.fsf.mdw@metalzone.distorted.org.uk> <4cfff225$0$1650$742ec2ed@news.sonic.net> <4d005835$0$1597$742ec2ed@news.sonic.net> <4d008c25$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 12/9/2010 2:58 AM, Steven D'Aprano wrote: > On Wed, 08 Dec 2010 20:16:57 -0800, John Nagle wrote: > >> Here's an example where this issue produces invalid results in >> Python. >> >> >>> NaN = float("nan") >> >>> arr = [1.0, 4.0, 3.0, 2.0, 5.0, NaN, 6.0, 3.0, NaN, 0.0, 1.0, 4.0, >> 3.0, 2.0, 5.0, NaN, 6.0, 3.0, NaN, 0.0] >> >>> sorted(arr) >> [0.0, 0.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 3.0, 3.0, 4.0, 5.0, nan, 5.0, >> 6.0, nan, 4.0, nan, 6.0, nan] >> >> The sorted numerical values aren't in order. Note the 4.0 near the end, >> after the 6.0. "sort" has failed because it assumes that a< b and b< >> c implies a< c. But that's not a valid assumption here. This is transitivity. >> It's not good to break trichotomy. I believe that is that exactly one of <,=.> are true. -- Terry Jan Reedy From tjreedy at udel.edu Thu Dec 9 03:39:23 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 09 Dec 2010 03:39:23 -0500 Subject: trace cmd line args In-Reply-To: <37243f10-91f5-4a18-959f-fed96c145b36@29g2000prb.googlegroups.com> References: <37243f10-91f5-4a18-959f-fed96c145b36@29g2000prb.googlegroups.com> Message-ID: On 12/9/2010 1:10 AM, rusi wrote: > I am unable to get trace to not trace system modules. Try it with 3.2b1, just released. Multiple bugs were fixed in trace. Some fixes might also be in recent 2.7.1 and 3.1.3. Not sure. -- Terry Jan Reedy From eric.brunel at pragmadev.nospam.com Thu Dec 9 04:00:39 2010 From: eric.brunel at pragmadev.nospam.com (Eric Brunel) Date: Thu, 09 Dec 2010 10:00:39 +0100 Subject: Using a window style in a Toplevel window References: Message-ID: In article , craf wrote: > Hi. > > I use Python 3.1 and Tkinter.ttk 8.5 on Ubuntu 9.10. > > CODE:---------------------------------------------------- > > module:FMain.py > > from tkinter import ttk > from FSecondWindow import * > > class App: > def __init__(self,master): > > button1 = ttk.Button(master,text='Show > TopLevel',command=lambda:window()) > button1.pack() > > > master = Tk() > app = App(master) > style = ttk.Style() > style.theme_use('clam') > master.mainloop() > > > module:FSecondWindow.py > > from tkinter import * > from tkinter import ttk > > def window(): > t = Toplevel() > button2 = Button(t,text='Hello').pack() > > > CODE EXPLANATION:------------------------------------------- > > 1. From the main module FMain.py call the window function that is > located in FSecondWindow module and create a toplevel window. > > 2.I apply a theme called 'clam' to the master window to improve the > appearance of their widgets. > > QUERY:-------------------------------------------------- > > How I can make the toplevel window also take the theme 'clam'? Short answer: you can't. No directly anyway. Long answer: As you might be aware, there are 2 widget sets in tk/tkinter, the "old" one for which classes are directly in the tkinter module, and the new one that are in the ttk submodule. Only the second set supports theming, not the first one. Unfortunately, there are a few widgets that exist only in the first set, and Toplevel is one of those. So no theming is directly available for toplevels, and you can change whatever you want via style.theme_use, it won't be reflected on toplevels. By the way, as you wrote the code above, it won't be reflected on your button either, since you used the Button class, which is taken in tkinter directly, so it is the "old" Button class, not the new one. To get the new one, use ttk.Button, not Button. For your toplevel, there is however a simple workaround: Since there is a Frame widget in the new widget set, you can simply insert such a frame in your toplevel, make sure it will take the whole space, and then insert your widgets in this frame rather than in the toplevel directly. The code for your 'window' function would then become: def window() t = Toplevel() frm = ttk.Frame(t) frm.pack(fill=BOTH, expand=True) button2 = ttk.Button(frm, text='Hello') button2.pack() (Note also that I have put the creation of the button and its packing in 2 lines. You should never do variable = widget.pack(???) since pack does not return the widget. It always returns None, so doing so won't put your widget in the variable). The code above should do what you're after. > Thanks in advance. HTH - Eric - From astan.chee at gmail.com Thu Dec 9 04:54:22 2010 From: astan.chee at gmail.com (Astan Chee) Date: Thu, 9 Dec 2010 20:54:22 +1100 Subject: run a function in another processor in python Message-ID: Hi, I've got a python script that calls a function many times with various arguments and returns a result. What I'm trying to do is run this function each on different processors and compile the result at the end based on the function result. The script looks something like this: import time def functionTester(num): return ((num+2)/(num-2))**2 num_args = [1,2,3,7,12,16,19,35,36,37,38,55,56,57,63,44,71,81,91] max_result = 0 start = time.time() for n in num_args: result = functionTester(n) if result > max_result: max_result = result print "Result " + str(max_result) end = time.time() elapsed= end - start print "Took", elapsed, "seconds to execute" What I'm trying to do is run each function on a processor and when its done, move on to the next function-argument specifically on windows 7 x64 using python 2.6. How do I do this? Thanks for any help From jeanmichel at sequans.com Thu Dec 9 05:48:54 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 09 Dec 2010 11:48:54 +0100 Subject: run a function in another processor in python In-Reply-To: References: Message-ID: <4D00B416.5090509@sequans.com> Astan Chee wrote: > Hi, > I've got a python script that calls a function many times with various > arguments and returns a result. What I'm trying to do is run this > function each on different processors and compile the result at the > end based on the function result. The script looks something like > this: > > > import time > > def functionTester(num): > return ((num+2)/(num-2))**2 > > num_args = [1,2,3,7,12,16,19,35,36,37,38,55,56,57,63,44,71,81,91] > > max_result = 0 > > start = time.time() > > for n in num_args: > result = functionTester(n) > if result > max_result: > max_result = result > > print "Result " + str(max_result) > end = time.time() > elapsed= end - start > print "Took", elapsed, "seconds to execute" > > > What I'm trying to do is run each function on a processor and when its > done, move on to the next function-argument specifically on windows 7 > x64 using python 2.6. How do I do this? > Thanks for any help > If I'm not wrong, CPU management is handled by your system, meaning there's no way to 'force' anything to run on a specific CPU. However, you may try to execute your fonction in a subprocess, so that the system will use different CPUs (hopefully). You then just need to limit the number of subprocess alive at the same time. Have a look here http://docs.python.org/library/multiprocessing.html JM From markjason72 at gmail.com Thu Dec 9 06:32:04 2010 From: markjason72 at gmail.com (mark jason) Date: Thu, 9 Dec 2010 03:32:04 -0800 (PST) Subject: packaging python code in zip file Message-ID: <0119a6ea-7352-41f1-b8bf-46144d160d5d@i32g2000pri.googlegroups.com> hi, I have created a python app in eclipse pydev .The app is structured as below.. mypackage |______ __init__.py |______ driver.py |______ helper.py |______ utils.py The driver.py has the main program.I have added if __name__=="__main__" block in the driver.py and pydev's run configuration has the following values, Project : myproject Main Module :${workspace_loc:myproject/src/mypackage/driver.py} So,the app runs in pydev without any problems. Then I thought of providing the modules as a zip file.So I created a zip file containing mypackage directory.The user should be able to unzip the zip file and run the application from command line . What bothers me is that ,the user will have to cd to mypackage folder and run python driver.py.. This doesn't look like the proper way.. I also thought of putting the driver,helper,utils modules in a folder called mycode and zipping it without the __init__.py file . I am not sure which is the correct way. Can somebody advise me as to how I can package it better? thanks, mark From nitinpawar432 at gmail.com Thu Dec 9 06:49:23 2010 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Thu, 9 Dec 2010 17:19:23 +0530 Subject: packaging python code in zip file In-Reply-To: <0119a6ea-7352-41f1-b8bf-46144d160d5d@i32g2000pri.googlegroups.com> References: <0119a6ea-7352-41f1-b8bf-46144d160d5d@i32g2000pri.googlegroups.com> Message-ID: have u tried using setuptools and distutils they are used for python package distributions On Thu, Dec 9, 2010 at 5:02 PM, mark jason wrote: > hi, > I have created a python app in eclipse pydev .The app is structured as > below.. > > mypackage > |______ __init__.py > |______ driver.py > |______ helper.py > |______ utils.py > > The driver.py has the main program.I have added if > __name__=="__main__" block in the > > driver.py and pydev's run configuration has the following values, > Project : myproject > Main Module :${workspace_loc:myproject/src/mypackage/driver.py} > So,the app runs in pydev without any problems. > > Then I thought of providing the modules as a zip file.So I created a > zip file containing > mypackage directory.The user should be able to unzip the zip file and > run the application from command line . > > What bothers me is that ,the user will have to cd to mypackage folder > and run python driver.py.. > This doesn't look like the proper way.. > I also thought of putting the driver,helper,utils modules in a folder > called mycode and zipping it without the __init__.py file . > I am not sure which is the correct way. > Can somebody advise me as to how I can package it better? > > thanks, > > mark > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From prog at vtr.net Thu Dec 9 07:12:09 2010 From: prog at vtr.net (craf) Date: Thu, 09 Dec 2010 09:12:09 -0300 Subject: [Fwd: Re: Using a window style in a Toplevel window] Message-ID: <1291896729.2069.1.camel@cristian-desktop> --------- Mensaje reenviado -------- > De: Eric Brunel > Para: python-list at python.org > Asunto: Re: Using a window style in a Toplevel window > Fecha: Thu, 09 Dec 2010 10:00:39 +0100 > Grupos de noticias: comp.lang.python > > In article , > craf wrote: > > > Hi. > > > > I use Python 3.1 and Tkinter.ttk 8.5 on Ubuntu 9.10. > > > > CODE:---------------------------------------------------- > > > > module:FMain.py > > > > from tkinter import ttk > > from FSecondWindow import * > > > > class App: > > def __init__(self,master): > > > > button1 = ttk.Button(master,text='Show > > TopLevel',command=lambda:window()) > > button1.pack() > > > > > > master = Tk() > > app = App(master) > > style = ttk.Style() > > style.theme_use('clam') > > master.mainloop() > > > > > > module:FSecondWindow.py > > > > from tkinter import * > > from tkinter import ttk > > > > def window(): > > t = Toplevel() > > button2 = Button(t,text='Hello').pack() > > > > > > CODE EXPLANATION:------------------------------------------- > > > > 1. From the main module FMain.py call the window function that is > > located in FSecondWindow module and create a toplevel window. > > > > 2.I apply a theme called 'clam' to the master window to improve the > > appearance of their widgets. > > > > QUERY:-------------------------------------------------- > > > > How I can make the toplevel window also take the theme 'clam'? > > Short answer: you can't. No directly anyway. > > Long answer: As you might be aware, there are 2 widget sets in > tk/tkinter, the "old" one for which classes are directly in the tkinter > module, and the new one that are in the ttk submodule. Only the second > set supports theming, not the first one. Unfortunately, there are a few > widgets that exist only in the first set, and Toplevel is one of those. > So no theming is directly available for toplevels, and you can change > whatever you want via style.theme_use, it won't be reflected on > toplevels. > > By the way, as you wrote the code above, it won't be reflected on your > button either, since you used the Button class, which is taken in > tkinter directly, so it is the "old" Button class, not the new one. To > get the new one, use ttk.Button, not Button. > > For your toplevel, there is however a simple workaround: Since there is > a Frame widget in the new widget set, you can simply insert such a frame > in your toplevel, make sure it will take the whole space, and then > insert your widgets in this frame rather than in the toplevel directly. > The code for your 'window' function would then become: > > def window() > t = Toplevel() > frm = ttk.Frame(t) > frm.pack(fill=BOTH, expand=True) > button2 = ttk.Button(frm, text='Hello') > button2.pack() > > (Note also that I have put the creation of the button and its packing in > 2 lines. You should never do variable = widget.pack(?) since pack does > not return the widget. It always returns None, so doing so won't put > your widget in the variable). > > The code above should do what you're after. > > > Thanks in advance. > > HTH > - Eric - Hi Eric. ?Thank you very much, for the answer.! Regards Cristian Abarz?a F From rustompmody at gmail.com Thu Dec 9 07:12:25 2010 From: rustompmody at gmail.com (rusi) Date: Thu, 9 Dec 2010 04:12:25 -0800 (PST) Subject: trace cmd line args References: <37243f10-91f5-4a18-959f-fed96c145b36@29g2000prb.googlegroups.com> Message-ID: <41e52394-3a5a-409b-a9f1-ed0209ea38ef@p7g2000prb.googlegroups.com> On Dec 9, 1:39?pm, Terry Reedy wrote: > On 12/9/2010 1:10 AM, rusi wrote: > > > I am unable to get trace to not trace system modules. > > Try it with 3.2b1, just released. Multiple bugs were fixed in trace. > Some fixes might also be in recent 2.7.1 and 3.1.3. Not sure. > > -- > Terry Jan Reedy I am doing this to port a 2.x app to 3 which is giving me a hell of a time! :-; From python at bdurham.com Thu Dec 9 07:19:30 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 09 Dec 2010 07:19:30 -0500 Subject: Using a window style in a Toplevel window In-Reply-To: References: Message-ID: <1291897170.24466.1409471291@webmail.messagingengine.com> Eric, Besides style support, what are the advantages of ttk.Frame vs. Tkinter.Frame? Thanks, Malcolm From mdw at distorted.org.uk Thu Dec 9 07:21:45 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 09 Dec 2010 12:21:45 +0000 Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <4cfebe65$0$1590$742ec2ed@news.sonic.net> <87ipz5jfr9.fsf.mdw@metalzone.distorted.org.uk> <4cfff225$0$1650$742ec2ed@news.sonic.net> <4d005835$0$1597$742ec2ed@news.sonic.net> Message-ID: <87vd33i1ba.fsf.mdw@metalzone.distorted.org.uk> John Nagle writes: > >>> NaN = float("nan") > >>> arr = [1.0, 4.0, 3.0, 2.0, 5.0, NaN, 6.0, 3.0, NaN, 0.0, 1.0, 4.0, > 3.0, 2.0, 5.0, NaN, 6.0, 3.0, NaN, 0.0] > >>> sorted(arr) > [0.0, 0.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 3.0, 3.0, 4.0, 5.0, nan, 5.0, 6.0, > nan, 4.0, nan, 6.0, nan] > > The sorted numerical values aren't in order. Indeed. You failed to provide a valid ordering to `sorted'. By failing to satisfy its precondition, you relieved it of its obligation to satisfy its postcondition. > "sort" has failed because it assumes that a < b and b < c implies a < > c. But that's not a valid assumption here. > > It's not good to break trichotomy. You're confused. The property a < b and b < c => a < c is called `transitivity'. But the `float' ordering /is/ transitive. Note that a < b implies that neither a nor b is a NaN. Also, trichotomy is unnecessary for sorting, and Python's `sort' method doesn't require it; it does require a total preorder, though. What properties does a total preorder require? 1. Transitivity: a <= b and b <= c => a <= c 2. Totality: a <= b or b <= a The above list sorting goes wrong because the `float' ordering isn't total. In particular, x References: <4CFA4305.10004@it.uu.se> Message-ID: > 1. Pick a web framework, I'd suggest looking at: web2py: http://web2py.com - probably the easiest to install (no configuration needed) and learn. Suitable for both small and big projects. No worries when upgrading to a newer version as backward compatibility is an explicit design goal. From __peter__ at web.de Thu Dec 9 08:02:09 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 09 Dec 2010 14:02:09 +0100 Subject: packaging python code in zip file References: <0119a6ea-7352-41f1-b8bf-46144d160d5d@i32g2000pri.googlegroups.com> Message-ID: mark jason wrote: > hi, > I have created a python app in eclipse pydev .The app is structured as > below.. > > mypackage > |______ __init__.py > |______ driver.py > |______ helper.py > |______ utils.py > > The driver.py has the main program.I have added if > __name__=="__main__" block in the > > driver.py and pydev's run configuration has the following values, > Project : myproject > Main Module :${workspace_loc:myproject/src/mypackage/driver.py} > So,the app runs in pydev without any problems. > > Then I thought of providing the modules as a zip file.So I created a > zip file containing > mypackage directory.The user should be able to unzip the zip file and > run the application from command line . > > What bothers me is that ,the user will have to cd to mypackage folder > and run python driver.py.. > This doesn't look like the proper way.. > I also thought of putting the driver,helper,utils modules in a folder > called mycode and zipping it without the __init__.py file . > I am not sure which is the correct way. > Can somebody advise me as to how I can package it better? If you put a __main__.py file at the top level you can run the zip archive directly (requires Python 2.6): $ echo 'import alpha > print "main"' > __main__.py $ mkdir alpha $ echo 'print "init alpha"' > alpha/__init__.py $ zip -r demo . adding: alpha/ (stored 0%) adding: alpha/__init__.py (stored 0%) adding: __main__.py (stored 0%) $ rm -rf __main__.py alpha/ $ ls demo.zip $ python demo.zip init alpha main Peter From astan.chee at gmail.com Thu Dec 9 08:03:40 2010 From: astan.chee at gmail.com (Astan Chee) Date: Fri, 10 Dec 2010 00:03:40 +1100 Subject: run a function in another processor in python In-Reply-To: <4D00B416.5090509@sequans.com> References: <4D00B416.5090509@sequans.com> Message-ID: Thanks but I'm having trouble with that module too. Currently what I have is something like this: import sys import os import multiprocessing import time def functionTester(num): return ((num+2)/(num-2))**2 num_args = [61,62,33,7,12,16,19,35,36,37,38,55,56,57,63] max_result = 0 start = time.time() num_processes = multiprocessing.cpu_count() threads = [] len_stas = len(num_args) for list_item in num_args: if len(threads) < num_processes: p = multiprocessing.Process(target=functionTester,args=[list_item]) p.start() print p, p.is_alive() threads.append(p) else: for thread in threads: if not thread.is_alive(): threads.remove(thread) print "Result " + str(max_result) end = time.time() elapsed= end - start print "Took", elapsed, "seconds to execute" But it doesn't give me any return data. It also spawns an infinite number of (sub)processes that crashes my machine. What am I doing wrong here? On 12/9/10, Jean-Michel Pichavant wrote: > Astan Chee wrote: >> Hi, >> I've got a python script that calls a function many times with various >> arguments and returns a result. What I'm trying to do is run this >> function each on different processors and compile the result at the >> end based on the function result. The script looks something like >> this: >> >> >> import time >> >> def functionTester(num): >> return ((num+2)/(num-2))**2 >> >> num_args = [1,2,3,7,12,16,19,35,36,37,38,55,56,57,63,44,71,81,91] >> >> max_result = 0 >> >> start = time.time() >> >> for n in num_args: >> result = functionTester(n) >> if result > max_result: >> max_result = result >> >> print "Result " + str(max_result) >> end = time.time() >> elapsed= end - start >> print "Took", elapsed, "seconds to execute" >> >> >> What I'm trying to do is run each function on a processor and when its >> done, move on to the next function-argument specifically on windows 7 >> x64 using python 2.6. How do I do this? >> Thanks for any help >> > If I'm not wrong, CPU management is handled by your system, meaning > there's no way to 'force' anything to run on a specific CPU. However, > you may try to execute your fonction in a subprocess, so that the system > will use different CPUs (hopefully). You then just need to limit the > number of subprocess alive at the same time. > > Have a look here > http://docs.python.org/library/multiprocessing.html > > JM > From heather at dejaviewphoto.com Thu Dec 9 08:18:25 2010 From: heather at dejaviewphoto.com (Heather Brown) Date: Thu, 09 Dec 2010 08:18:25 -0500 Subject: 64 bit memory usage In-Reply-To: References: Message-ID: <4D00D721.4000306@dejaviewphoto.com> On 01/-10/-28163 02:59 PM, Dennis Lee Bieber wrote: > On Wed, 8 Dec 2010 14:44:30 +0000, Rob Randall > declaimed the following in gmane.comp.python.general: > >> I am trying to understand how much memory is available to a 64 bit python >> process running under Windows XP 64 bit. >> >> When I run tests just creating a series of large dictionaries containing >> string keys and float values I do not seem to be able to grow the process >> beyond the amount of RAM present. >> >> For example, on a box with 2GB RAM and 3 GB pagefile the process stalls at >> around 2GB. >> >> On another machine with 16GB RAM and 24GB pagefile the process stalls at >> 16GB. >> > > Probably need to ask M$, but I can understand this behavior as a > hypothetical... > > The page file can be larger than physical memory because it contains > memory "images" for multiple processes. However, all those "images" have > to map into the physically addressable memory -- so a process is likely > limited to physical memory, but you can have multiple processes adding > up to physical + pagefile in total. It's plausible that MS did that, but it's not reasonable. An application's entire data space is never in physical memory, except for trivial applications. When new pages are needed, old ones are swapped out, in an LRU manner. If the application is the only thing "running," it'll eventually be mapped into most of physical memory, but even then, the swapper keeps some back. The limit in 32bit world was 4gb, not whatever RAM happened to be in the machine. That limit came from the address space (or linear space, as MS calls it), not from the amount of RAM. It's only in recent years that those numbers have tended to be close. DaveA From jonathan.slenders at gmail.com Thu Dec 9 08:28:25 2010 From: jonathan.slenders at gmail.com (Jonathan S) Date: Thu, 9 Dec 2010 05:28:25 -0800 (PST) Subject: Replacing globals in exec by custom class References: Message-ID: <6f371eb9-8486-4598-b87d-97d74505c9cf@l17g2000yqe.googlegroups.com> Thanks for your response! (And sorry about the syntax error, I forgot to test my code after cleaning up some debug statements before posting, the else should have been elif indeed.) It's very interesing, how Python works internally. According to a thread on the Python mailing list in 2002, it seems that the implementation of CPython bypasses __getitem__ of the dict object, when it is used as Global namespace. (For performance reasons.) http://mail.python.org/pipermail/python-dev/2002-October/029753.html From ugnews at onlinehome.de Thu Dec 9 09:17:57 2010 From: ugnews at onlinehome.de (Uwe Grauer) Date: Thu, 09 Dec 2010 15:17:57 +0100 Subject: kinterbasdb error connection In-Reply-To: References: Message-ID: On 12/07/2010 04:35 PM, Ale Ghelfi wrote: > (i'm under Ubuntu 10.10 amd64 and python 2.6 and kinterbasdb 3.2 ) > I try to connect my database of firebird 2.5 by kinterbasdb. > But python return this error : You are not using the current kinterbasdb version. See: http://firebirdsql.org/index.php?op=devel&sub=python Uwe From daniel.goertzen at gmail.com Thu Dec 9 09:19:38 2010 From: daniel.goertzen at gmail.com (Dan) Date: Thu, 9 Dec 2010 06:19:38 -0800 (PST) Subject: Can't deepcopy bytes-derived class References: <69dc1506-be6f-443c-95b8-7f214510f0ed@p7g2000prb.googlegroups.com> Message-ID: <9946739d-fcd1-4c25-9a9d-f3a6b41aacb8@e20g2000vbn.googlegroups.com> On Dec 8, 9:05?pm, Terry Reedy wrote: > On 12/8/2010 7:11 PM, Ned Deily wrote: > > > > > > > > > > > In article, Terry > > Reedy ?wrote: > >> On 12/8/2010 2:42 PM, Dan wrote: > >>> I have a simple type derived from bytes... > > >>> class atom(bytes): pass > > >>> ... that I cannot deepcopy(). ?The session below demonstrates > >>> how deepcopy() of "bytes" works fine, but deepcopy() of "atom" > >>> does not. > > [...] > >>> Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 > >>> bit (Intel)] Type "help", "copyright", "credits" or "license" for > >>> more information. > >>>>>> import copy class atom(bytes): > >>> ... ? ? ? ?pass ... > >>>>>> copy.deepcopy(b'abc') > >>> b'abc' > >>>>>> copy.deepcopy(atom(b'abc')) > >>> Traceback (most recent call last): File "C:\Program Files > >>> (x86)\Wing IDE 3.2\src\debug\tserver \_sandbox.py", line 1, > >>> in # Used internally for debug sandbox under external > >>> interpreter File "C:\Python31\Lib\copy.py", line 173, in > >>> deepcopy y = _reconstruct(x, rv, 1, memo) File > >>> "C:\Python31\Lib\copy.py", line 280, in _reconstruct y = > >>> callable(*args) File "C:\Python31\Lib\copyreg.py", line 88, in > >>> __newobj__ return cls.__new__(cls, *args) builtins.TypeError: > >>> string argument without an encoding > > >> You could trace through copy.py and copyreg.py to see where bytes > >> and atom get treated differently. > > >> This might be a bug that should be reported on the tracker, but I > >> do not know. Let see what anyone else says. > > > FWIW, the example still fails with Python 3.1.3 but seems to work OK > > with a recent alpha build of Python 3.2. ?What specific change might > > have fixed it doesn't come immediately to mind. > > According to difflib.unified_diff, the only difference between > Lib/copy.py from 3.1 to 3.2 is 4 lines: > + > +def _deepcopy_method(x, memo): # Copy instance methods > + ? ?return type(x)(x.__func__, deepcopy(x.__self__, memo)) > +_deepcopy_dispatch[types.MethodType] = _deepcopy_method > > (and none in copyreg.py) > > These were added in rev76572 as part ofhttp://bugs.python.org/issue1515 > > Guido decreed this to be a new feature rather than bugfix, so the change > went into future 2.7 and 3.2 and not existing 2.6 and 3.1. > > Tto verify that these cause the change, comment out in 3.2 or add to > 3.1. I have not read through the issue to understand it or why it would > affect the OP's code case. > > -- > Terry Jan Reedy Thank you everyone. Knowing that it works in 3.2 is good enough for me. I tested the 4 line change anyway...removing it from 3.2 had no detrimental effect, adding it to 3.1 had no effect. It must be something else. Regards, Dan. From __peter__ at web.de Thu Dec 9 09:37:27 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 09 Dec 2010 15:37:27 +0100 Subject: run a function in another processor in python References: <4D00B416.5090509@sequans.com> Message-ID: Astan Chee wrote: > Thanks but I'm having trouble with that module too. Currently what I > have is something like this: > > import sys > import os > import multiprocessing > > import time > > def functionTester(num): > return ((num+2)/(num-2))**2 > > num_args = [61,62,33,7,12,16,19,35,36,37,38,55,56,57,63] > > max_result = 0 > > start = time.time() > > num_processes = multiprocessing.cpu_count() > > threads = [] > len_stas = len(num_args) > > for list_item in num_args: > if len(threads) < num_processes: > p = > multiprocessing.Process(target=functionTester,args=[list_item]) > p.start() print p, p.is_alive() > threads.append(p) > else: > for thread in threads: > if not thread.is_alive(): > threads.remove(thread) > > print "Result " + str(max_result) > end = time.time() > elapsed= end - start > print "Took", elapsed, "seconds to execute" > > But it doesn't give me any return data. It also spawns an infinite > number of (sub)processes that crashes my machine. What am I doing > wrong here? I can't replicate the crash. However, your problem looks like there is a ready-to-use solution: http://docs.python.org/library/multiprocessing.html#using-a-pool-of-workers From pruebauno at latinmail.com Thu Dec 9 10:49:37 2010 From: pruebauno at latinmail.com (nn) Date: Thu, 9 Dec 2010 07:49:37 -0800 (PST) Subject: completely implicit interpolation based on a frame object References: Message-ID: On Dec 9, 2:29?am, Edward Peschko wrote: > >> Any ideas would be great on this, including pitfalls that people see > >> in implementing it. > > >http://docs.python.org/library/string.html#template-strings > > > regards > > ?Steve > > Steve, > > Thanks for the tip, I did look at templates and decided that they > weren't quite completely what I was looking for, although they could > be part of the solution. > > 1. they require ${ } around the variables in question that you want to > interpolate. When run through the trace hook, normal code doesn't do > that. > 2. they don't provide (AFAICT) a complete interpolation solution. > Suppose I want to define custom interpolations in my tracer, like say, > expanding out lists and dicts, or fleshing out objects using their > stringification method. Does template do this? > > Formats may be a bit closer here, but I'm not sure if they are > workable (or usable) with 2.5... which is where I need to work. > > Ed One of the solutions from here might work for you: http://wiki.python.org/moin/Templating From tjreedy at udel.edu Thu Dec 9 10:50:16 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 09 Dec 2010 10:50:16 -0500 Subject: Can't deepcopy bytes-derived class In-Reply-To: <9946739d-fcd1-4c25-9a9d-f3a6b41aacb8@e20g2000vbn.googlegroups.com> References: <69dc1506-be6f-443c-95b8-7f214510f0ed@p7g2000prb.googlegroups.com> <9946739d-fcd1-4c25-9a9d-f3a6b41aacb8@e20g2000vbn.googlegroups.com> Message-ID: On 12/9/2010 9:19 AM, Dan wrote: > I tested the 4 line change anyway...removing it from 3.2 had no > detrimental effect, adding it to 3.1 had no effect. It must be > something else. Then there must have been a change in the bytes object, which is deeper than I want to go. 3.2 has a LOT of little improvements. When it comes out, just about all 3.1 users should upgrade unless one has production code disabled by a bugfix. -- Terry Jan Reedy From tjreedy at udel.edu Thu Dec 9 11:03:27 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 09 Dec 2010 11:03:27 -0500 Subject: trace cmd line args In-Reply-To: <41e52394-3a5a-409b-a9f1-ed0209ea38ef@p7g2000prb.googlegroups.com> References: <37243f10-91f5-4a18-959f-fed96c145b36@29g2000prb.googlegroups.com> <41e52394-3a5a-409b-a9f1-ed0209ea38ef@p7g2000prb.googlegroups.com> Message-ID: On 12/9/2010 7:12 AM, rusi wrote: > On Dec 9, 1:39 pm, Terry Reedy wrote: >> On 12/9/2010 1:10 AM, rusi wrote: >> >>> I am unable to get trace to not trace system modules. >> >> Try it with 3.2b1, just released. Multiple bugs were fixed in trace. >> Some fixes might also be in recent 2.7.1 and 3.1.3. Not sure. >> >> -- >> Terry Jan Reedy > > I am doing this to port a 2.x app to 3 which is giving me a hell of a > time! :-; I would get it to run on 2.7 first, with out getting any DeprecationWarnings when they are turned on. They are off by default and I am not sure how to turn on but presume the warnings module doc says how. -- Terry Jan Reedy From nobody at nowhere.com Thu Dec 9 11:17:06 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 09 Dec 2010 16:17:06 +0000 Subject: 64 bit memory usage References: Message-ID: Rob Randall wrote: > I am trying to understand how much memory is available to a 64 bit python > process running under Windows XP 64 bit. > > When I run tests just creating a series of large dictionaries containing > string keys and float values I do not seem to be able to grow the process > beyond the amount of RAM present. > > For example, on a box with 2GB RAM and 3 GB pagefile the process stalls at > around 2GB. What do you mean by "stalls"? Do you get an exception, or does the program just slow to a crawl? From eric.brunel at pragmadev.nospam.com Thu Dec 9 11:50:36 2010 From: eric.brunel at pragmadev.nospam.com (Eric Brunel) Date: Thu, 09 Dec 2010 17:50:36 +0100 Subject: Using a window style in a Toplevel window References: Message-ID: In article , python at bdurham.com wrote: > Eric, > > Besides style support, what are the advantages of ttk.Frame vs. > Tkinter.Frame? I'd say none. They are both just containers for other widgets, support the same layout managers, and so on. For me, using a ttk.Frame is really just for getting the correct theme, nothing else... > Thanks, > Malcolm From solipsis at pitrou.net Thu Dec 9 11:54:39 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Thu, 9 Dec 2010 17:54:39 +0100 Subject: 64 bit memory usage References: Message-ID: <20101209175439.3f0ffa35@pitrou.net> On Wed, 8 Dec 2010 14:44:30 +0000 Rob Randall wrote: > I am trying to understand how much memory is available to a 64 bit python > process running under Windows XP 64 bit. > > When I run tests just creating a series of large dictionaries containing > string keys and float values I do not seem to be able to grow the process > beyond the amount of RAM present. > > For example, on a box with 2GB RAM and 3 GB pagefile the process stalls at > around 2GB. > > On another machine with 16GB RAM and 24GB pagefile the process stalls at > 16GB. How is it surprising? When you go past the available RAM, your process starts swapping and everything becomes incredibly slower. Regards Antoine. From debatem1 at gmail.com Thu Dec 9 12:16:09 2010 From: debatem1 at gmail.com (geremy condra) Date: Thu, 9 Dec 2010 09:16:09 -0800 Subject: run a function in another processor in python In-Reply-To: References: <4D00B416.5090509@sequans.com> Message-ID: On Thu, Dec 9, 2010 at 5:03 AM, Astan Chee wrote: > Thanks but I'm having trouble with that module too. Currently what I > have is something like this: > > import sys > import os > import multiprocessing > > import time > > def functionTester(num): > ? ?return ((num+2)/(num-2))**2 > > num_args = [61,62,33,7,12,16,19,35,36,37,38,55,56,57,63] > > max_result = 0 > > start = time.time() > > num_processes = multiprocessing.cpu_count() > > threads = [] > len_stas = len(num_args) > > for list_item in num_args: > ? ?if len(threads) < num_processes: > ? ? ? ?p = multiprocessing.Process(target=functionTester,args=[list_item]) > ? ? ? ?p.start() > ? ? ? ?print p, p.is_alive() > ? ? ? ?threads.append(p) > ? ?else: > ? ? ? ?for thread in threads: > ? ? ? ? ? ?if not thread.is_alive(): > ? ? ? ? ? ? ? ?threads.remove(thread) > > print "Result " + str(max_result) > end = time.time() > elapsed= end - start > print "Took", elapsed, "seconds to execute" > > But it doesn't give me any return data. It also spawns an infinite > number of (sub)processes that crashes my machine. What am I doing > wrong here? > > On 12/9/10, Jean-Michel Pichavant wrote: >> Astan Chee wrote: >>> Hi, >>> I've got a python script that calls a function many times with various >>> arguments and returns a result. What I'm trying to do is run this >>> function each on different processors and compile the result at the >>> end based on the function result. The script looks something like >>> this: >>> >>> >>> import time >>> >>> def functionTester(num): >>> ? ? return ((num+2)/(num-2))**2 >>> >>> num_args = [1,2,3,7,12,16,19,35,36,37,38,55,56,57,63,44,71,81,91] >>> >>> max_result = 0 >>> >>> start = time.time() >>> >>> for n in num_args: >>> ? ? result = functionTester(n) >>> ? ? if result > max_result: >>> ? ? ? ? max_result = result >>> >>> print "Result " + str(max_result) >>> end = time.time() >>> elapsed= end - start >>> print "Took", elapsed, "seconds to execute" >>> >>> >>> What I'm trying to do is run each function on a processor and when its >>> done, move on to the next function-argument specifically on windows 7 >>> x64 using python 2.6. How do I do this? >>> Thanks for any help >>> >> If I'm not wrong, CPU management is handled by your system, meaning >> there's no way to 'force' anything to run on a specific CPU. However, >> you may try to execute your fonction in a subprocess, so that the system >> will use different CPUs (hopefully). You then just need to limit the >> number of subprocess alive at the same time. >> >> Have a look here >> http://docs.python.org/library/multiprocessing.html >> >> JM >> > -- > http://mail.python.org/mailman/listinfo/python-list > Here's a way of doing what I think you mean to do. I assume that max_result should be the maximum value returned by a run of functionTester. Also, just a note, usually function names like this are spelled function_tester rather than functionTester in python. If you need to de-python3ify it just change the line at the top and cast your nums to floats, otherwise you'll get integer division (which I again assume you don't want). #! /usr/bin/env python3 import time import multiprocessing def functionTester(num): return ((num+2)/(num-2))**2 num_args = [61,62,33,7,12,16,19,35,36,37,38,55,56,57,63] num_processes = multiprocessing.cpu_count() pool = multiprocessing.Pool(num_processes) start = time.time() results = pool.map(functionTester, num_args) end = time.time() # is this what you meant to do with the results? max_result = max(results) print("Result " + str(max_result)) elapsed = end - start print("Took", elapsed, "seconds to execute") Geremy Condra From rob.randall2 at gmail.com Thu Dec 9 12:18:19 2010 From: rob.randall2 at gmail.com (Rob Randall) Date: Thu, 9 Dec 2010 17:18:19 +0000 Subject: 64 bit memory usage In-Reply-To: <20101209175439.3f0ffa35@pitrou.net> References: <20101209175439.3f0ffa35@pitrou.net> Message-ID: But the C++ program using up memory does not slow up. It has gone to 40GB without much trouble. Does anyone have a 64 bit python application that uses more the 2GB? On 9 December 2010 16:54, Antoine Pitrou wrote: > On Wed, 8 Dec 2010 14:44:30 +0000 > Rob Randall wrote: > > I am trying to understand how much memory is available to a 64 bit python > > process running under Windows XP 64 bit. > > > > When I run tests just creating a series of large dictionaries containing > > string keys and float values I do not seem to be able to grow the process > > beyond the amount of RAM present. > > > > For example, on a box with 2GB RAM and 3 GB pagefile the process stalls > at > > around 2GB. > > > > On another machine with 16GB RAM and 24GB pagefile the process stalls at > > 16GB. > > How is it surprising? When you go past the available RAM, your process > starts swapping and everything becomes incredibly slower. > > Regards > > Antoine. > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rob.randall2 at gmail.com Thu Dec 9 12:18:58 2010 From: rob.randall2 at gmail.com (Rob Randall) Date: Thu, 9 Dec 2010 17:18:58 +0000 Subject: 64 bit memory usage In-Reply-To: <20101209175439.3f0ffa35@pitrou.net> References: <20101209175439.3f0ffa35@pitrou.net> Message-ID: Basically the process runs at around 1% and it never seems to grow in size again. When running the C++ with python app the process slows when a new 'page' is required but then goes back to 'full' speed. It does this until basically all the virtual memory is used. I have had memory exceptions when running the same sort of stuff on 32 bit, but never 64 bit. On 9 December 2010 16:54, Antoine Pitrou wrote: > On Wed, 8 Dec 2010 14:44:30 +0000 > Rob Randall wrote: > > I am trying to understand how much memory is available to a 64 bit python > > process running under Windows XP 64 bit. > > > > When I run tests just creating a series of large dictionaries containing > > string keys and float values I do not seem to be able to grow the process > > beyond the amount of RAM present. > > > > For example, on a box with 2GB RAM and 3 GB pagefile the process stalls > at > > around 2GB. > > > > On another machine with 16GB RAM and 24GB pagefile the process stalls at > > 16GB. > > How is it surprising? When you go past the available RAM, your process > starts swapping and everything becomes incredibly slower. > > Regards > > Antoine. > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nagle at animats.com Thu Dec 9 12:23:54 2010 From: nagle at animats.com (John Nagle) Date: Thu, 09 Dec 2010 09:23:54 -0800 Subject: 64 bit memory usage In-Reply-To: References: Message-ID: <4d0110a6$0$1607$742ec2ed@news.sonic.net> On 12/8/2010 11:40 PM, Ian Kelly wrote: > Since a process need not have all its pages in physical memory > simultaneously, there is no reason to suppose that a single process > could not consume the entirety of the available virtual memory (minus > what is used by the operating system) on a 64-bit system (the same > cannot be said of a 32-bit system, where the total virtual memory > available may well be larger than the addressable space). Actually, the "32-bit" x86 machines since the Pentium Pro are really 36 to 48-bit machines. They only offer 32-bit flat address spaces to user programs, but the MMU and memory interface support a larger address space. The page table design supports 64-bit physical memory, but most of the bits beyond 36 usually aren't implemented. Linux fully supported this; Windows tried, but older drivers were a problem. That's why there are 32 bit machines with more than 4GB of RAM. None of the real 64-bit architectures, from AMD64 to SPARC to Itanium, need this hack. John Nagle From benjamin.kaplan at case.edu Thu Dec 9 12:29:51 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 9 Dec 2010 12:29:51 -0500 Subject: 64 bit memory usage In-Reply-To: References: <20101209175439.3f0ffa35@pitrou.net> Message-ID: On Thursday, December 9, 2010, Rob Randall wrote: > But the C++ program using up memory does not slow up. > It has gone to 40GB without much trouble. > Your C++ program probably doesn't have a garbage collector traversing the entire allocated memory looking for reference cycles. > Does anyone have a 64 bit python application that uses more the 2GB? > > On 9 December 2010 16:54, Antoine Pitrou wrote: > On Wed, 8 Dec 2010 14:44:30 +0000 > Rob Randall wrote: >> I am trying to understand how much memory is available to a 64 bit python >> process running under Windows XP 64 bit. >> >> When I run tests just creating a series of large dictionaries containing >> string keys and float values I do not seem to be able to grow the process >> beyond the amount of RAM present. >> >> For example, on a box with 2GB RAM and 3 GB pagefile the process stalls at >> around 2GB. >> >> On another machine with 16GB RAM and 24GB pagefile the process stalls at >> 16GB. > > How is it surprising? When you go past the available RAM, your process > starts swapping and everything becomes incredibly slower. > > Regards > > Antoine. > > > -- > http://mail.python.org/mailman/listinfo/python-list > > From nagle at animats.com Thu Dec 9 12:34:19 2010 From: nagle at animats.com (John Nagle) Date: Thu, 09 Dec 2010 09:34:19 -0800 Subject: Comparisons of incompatible types In-Reply-To: References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <4cfebe65$0$1590$742ec2ed@news.sonic.net> <87ipz5jfr9.fsf.mdw@metalzone.distorted.org.uk> <4cfff225$0$1650$742ec2ed@news.sonic.net> <4d005835$0$1597$742ec2ed@news.sonic.net> <4d008c25$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4d011317$0$1664$742ec2ed@news.sonic.net> On 12/9/2010 12:36 AM, Terry Reedy wrote: > On 12/9/2010 2:58 AM, Steven D'Aprano wrote: >> On Wed, 08 Dec 2010 20:16:57 -0800, John Nagle wrote: > I believe that is that exactly one of <,=.> are true. Not for NaNs. >>> NaN = float('nan') >>> NaN == NaN False >>> NaN > NaN False >>> NaN < NaN False That's IEEE 754 compliant. NaN is not equal to NaN. That's by design. But it really messes up sorting. Python "dict" types, however, treat "NaN" as a unique value, because they're hash based on the underlying representation. (The best coverage of this whole topic was the Apple Numerics Manual for the original Mac. Apple hired the floating point expert from Berkeley to get this right. Then Apple went from the M68xxx series to the IBM PowerPC, and 80-bit floats to 64-bit floats, breaking all the engineering applications, most of which were never ported to the PowerPC.) John Nagle From rustompmody at gmail.com Thu Dec 9 12:37:27 2010 From: rustompmody at gmail.com (rusi) Date: Thu, 9 Dec 2010 09:37:27 -0800 (PST) Subject: trace cmd line args References: <37243f10-91f5-4a18-959f-fed96c145b36@29g2000prb.googlegroups.com> <41e52394-3a5a-409b-a9f1-ed0209ea38ef@p7g2000prb.googlegroups.com> Message-ID: <4587947a-e82a-43fb-9ef5-46ada0db8ee3@35g2000prt.googlegroups.com> On Dec 9, 9:03?pm, Terry Reedy wrote: > On 12/9/2010 7:12 AM, rusi wrote: > > > On Dec 9, 1:39 pm, Terry Reedy ?wrote: > >> On 12/9/2010 1:10 AM, rusi wrote: > > >>> I am unable to get trace to not trace system modules. > > >> Try it with 3.2b1, just released. Multiple bugs were fixed in trace. > >> Some fixes might also be in recent 2.7.1 and 3.1.3. Not sure. > > >> -- > >> Terry Jan Reedy > > > I am doing this to port a 2.x app to 3 which is giving me a hell of a > > time! :-; > > I would get it to run on 2.7 first, with out getting any > DeprecationWarnings when they are turned on. They are off by default and > I am not sure how to turn on but presume the warnings module doc says how. > > -- > Terry Jan Reedy This is a bit of a headache... Am on debian unstable but no 2.7 in the repos so I'll have to compile it... Ok can do that but first I'd like to check that this trace 'bug' has been cleared Where do I look? From rustompmody at gmail.com Thu Dec 9 12:47:35 2010 From: rustompmody at gmail.com (rusi) Date: Thu, 9 Dec 2010 09:47:35 -0800 (PST) Subject: trace cmd line args References: <37243f10-91f5-4a18-959f-fed96c145b36@29g2000prb.googlegroups.com> <41e52394-3a5a-409b-a9f1-ed0209ea38ef@p7g2000prb.googlegroups.com> <4587947a-e82a-43fb-9ef5-46ada0db8ee3@35g2000prt.googlegroups.com> Message-ID: On Dec 9, 10:37?pm, rusi wrote: > On Dec 9, 9:03?pm, Terry Reedy wrote: > > > > > On 12/9/2010 7:12 AM, rusi wrote: > > > > On Dec 9, 1:39 pm, Terry Reedy ?wrote: > > >> On 12/9/2010 1:10 AM, rusi wrote: > > > >>> I am unable to get trace to not trace system modules. > > > >> Try it with 3.2b1, just released. Multiple bugs were fixed in trace. > > >> Some fixes might also be in recent 2.7.1 and 3.1.3. Not sure. > > > >> -- > > >> Terry Jan Reedy > > > > I am doing this to port a 2.x app to 3 which is giving me a hell of a > > > time! :-; > > > I would get it to run on 2.7 first, with out getting any > > DeprecationWarnings when they are turned on. They are off by default and > > I am not sure how to turn on but presume the warnings module doc says how. > > > -- > > Terry Jan Reedy > > This is a bit of a headache... > Am on debian unstable but no 2.7 in the repos so I'll have to compile > it... > Ok can do that but first I'd like to check that this trace 'bug' has > been cleared > Where do I look? Ok Ive got 2.7 from 'experimental' without any (apparent) glitches From tlikonen at iki.fi Thu Dec 9 12:54:51 2010 From: tlikonen at iki.fi (Teemu Likonen) Date: Thu, 09 Dec 2010 19:54:51 +0200 Subject: Condition signals and restarts, resumable exceptions (was: Comparison with False - something I don't understand) References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> <7x39qbfhd8.fsf@ruckus.brouhaha.com> Message-ID: <87aakej0gk.fsf_-_@mithlond.arda> * 2010-12-06 00:14 (-0800), Paul Rubin wrote: > You know, I've heard the story from language designers several times > over, that they tried putting resumable exceptions into their > languages and it turned out to be a big mess, so they went to > termination exceptions that fixed the issue. Are there any languages > out there with resumable exceptions? As some people have pointer out Common Lisp is one of those languages. I don't know anything about language design, I'm just a hobbyist programmer, but I think Common Lisp's condition system and its restarts are straight-forward and easy to understand from programmer's point of view. Here's the relevant chapter in Peter Seibel's Practical Common Lisp: http://www.gigamonkeys.com/book/beyond-exception-handling-conditions-and-restarts.html From rob.randall2 at gmail.com Thu Dec 9 12:56:25 2010 From: rob.randall2 at gmail.com (Rob Randall) Date: Thu, 9 Dec 2010 17:56:25 +0000 Subject: 64 bit memory usage In-Reply-To: References: <20101209175439.3f0ffa35@pitrou.net> Message-ID: I will give it a try with the garbage collector disabled. On 9 December 2010 17:29, Benjamin Kaplan wrote: > On Thursday, December 9, 2010, Rob Randall wrote: > > But the C++ program using up memory does not slow up. > > It has gone to 40GB without much trouble. > > > > Your C++ program probably doesn't have a garbage collector traversing > the entire allocated memory looking for reference cycles. > > > Does anyone have a 64 bit python application that uses more the 2GB? > > > > On 9 December 2010 16:54, Antoine Pitrou wrote: > > On Wed, 8 Dec 2010 14:44:30 +0000 > > Rob Randall wrote: > >> I am trying to understand how much memory is available to a 64 bit > python > >> process running under Windows XP 64 bit. > >> > >> When I run tests just creating a series of large dictionaries containing > >> string keys and float values I do not seem to be able to grow the > process > >> beyond the amount of RAM present. > >> > >> For example, on a box with 2GB RAM and 3 GB pagefile the process stalls > at > >> around 2GB. > >> > >> On another machine with 16GB RAM and 24GB pagefile the process stalls at > >> 16GB. > > > > How is it surprising? When you go past the available RAM, your process > > starts swapping and everything becomes incredibly slower. > > > > Regards > > > > Antoine. > > > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From solipsis at pitrou.net Thu Dec 9 15:01:26 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Thu, 9 Dec 2010 21:01:26 +0100 Subject: 64 bit memory usage References: <20101209175439.3f0ffa35@pitrou.net> Message-ID: <20101209210126.5c85a7c7@pitrou.net> On Thu, 9 Dec 2010 17:18:58 +0000 Rob Randall wrote: > Basically the process runs at around 1% and it never seems to grow in size > again. > When running the C++ with python app the process slows when a new 'page' is > required but then goes back to 'full' speed. It does this until basically > all the virtual memory is used. Intuitively, Benjamin Kaplan had the right answer: Python will periodically walk the heap of objects to look for dead reference cycles to collect; if your working set is larger than the available RAM, then this will thrash the pagefile to death. So try gc.disable() before doing your tests. I would stress that, of course, you will still have performance problems as soon as you start using all those areas you are allocating. And if you don't use them, I guess there's no point allocating them either. So I don't know what exactly you're trying to do (is this an actual application? or just some random test you're doing?), but relying on the pagefile to have more available memory than the system RAM is a very bad idea IMO. Regards Antoine. From eric.frederich at gmail.com Thu Dec 9 15:23:40 2010 From: eric.frederich at gmail.com (Eric Frederich) Date: Thu, 9 Dec 2010 15:23:40 -0500 Subject: Reference counting problems? Message-ID: I am attempting to automate the building of binding for a 3rd party library. The functions I'm wrapping all return an integer of whether they failed and output are passed as pointers. There can be multiple return values. So the code that I generate has a PyObject* called python__return_val that I use for returning. In the 'wrapped_foo' function below you see I build the return value with Py_BuildValue and "OO" as the format. For every output I have I do a C to Python conversion and add another 'O' to the format. What I'm wondering is if I can use the same logic when wrapping functions that only return one value like the wrapped_bar function below. So for multiples, I wind up doing this which is fine. python__x = Py_BuildValue("s", x) python__y = Py_BuildValue("s", y) python__return_val = Py_BuildValue("OO", python__x, python__y); But for single returns I do something like this.... I realize that the 2 lines below are pointless, but are they causing a memory leak or problems with reference counting? python__x = Py_BuildValue("s", x) python__return_val = Py_BuildValue("O", python__x); Are python__x and python__return_val the same object, a copy of the object? Would python__x ever get garbage collected? Should my code generator detect when there is only one output and not go through the extra step? Thanks, ~Eric static PyObject * wrapped_foo(PyObject *self, PyObject *args) { int wrapp_fail; // C types int x; const char* some_str; int* y; char** abc; // Python types PyObject* python__return_val; PyObject* python__y; PyObject* python__abc; // Get Python args if (!PyArg_ParseTuple(args, "is", &x, &some_str)) return NULL; // Wrapped Call wrapp_fail = foo(x, some_str, &y, &abc); if(wrapp_fail != 0){ return NULL; } // Convert output to Python types python__y = Py_BuildValue("i", y) python__abc = Py_BuildValue("s", abc) // Build Python return value python__return_val = Py_BuildValue("OO", python__y, python__abc); // Memory free's MEM_free(abc) return python__return_val; } static PyObject * wrapped_bar(PyObject *self, PyObject *args) { int wrapp_fail; // C types int a; const char* b; char** c; // Python types PyObject* python__return_val; PyObject* python__c; // Get Python args if (!PyArg_ParseTuple(args, "is", &a, &b)) return NULL; // Wrapped Call wrapp_fail = bar(a, b, &c); if(wrapp_fail != 0){ return NULL; } // Convert output to Python types python__c = Py_BuildValue("s", c) // Build Python return value python__return_val = Py_BuildValue("O", python__c); // Memory free's MEM_free(c) return python__return_val; } From greno at verizon.net Thu Dec 9 16:29:33 2010 From: greno at verizon.net (Gerry Reno) Date: Thu, 09 Dec 2010 16:29:33 -0500 Subject: Added Python, WSGI to XAMPP In-Reply-To: <4CFD8B29.3020006@verizon.net> References: <4CFA4305.10004@it.uu.se> <4CFD6825.9020200@simplistix.co.uk> <4CFD8B29.3020006@verizon.net> Message-ID: <4D014A3D.7020101@verizon.net> If you have any need of a portable LAMP stack, I just finished writing some How-To's for getting Python, VirtualEnv and WSGI frameworks running with XAMPP: How-To: Add VirtualEnv and Pylons (WSGI framework) to XAMPP How-To: Add VirtualEnv and Django (WSGI framework) to XAMPP How-To: Add Python and mod_wsgi to XAMPP -Gerry From horos11 at gmail.com Thu Dec 9 16:37:40 2010 From: horos11 at gmail.com (Edward Peschko) Date: Thu, 9 Dec 2010 13:37:40 -0800 Subject: completely implicit interpolation based on a frame object (nn) Message-ID: >> a bit closer here, but I'm not sure if they are >> workable (or usable) with 2.5... which is where I need to work. >> >> Ed > > One of the solutions from here might work for you: > > http://wiki.python.org/moin/Templating > Ok, cool. A couple of followups - I'd be interested in knowing which of the solutions listed there was: 1. lightweight 2. usable with 2.5 (and if possible 2.3,2.2, and 2.1) 3. able to do inplace expansion of arrays and/or hashes, using arbitrary functions, in a simplistic way (perhaps like formats and the {var!func} syntax) I'll read up on them, but as it is with perl, you can spend a lot of time fiddling around with a module to find out that the implementation doesn't support the featureset that you are looking for, or otherwise is just plain junk, so pointers are definitely welcome on which one to use. -- Anyways, the problem isn't completely solved here. Since it is a free-flowing string that needs to be interpolated, there needs to be some way of picking out the identifiers that are to be evaluated and turning them into a template. In the following code: person="mary" print "then along came a person named ", person this has to evaluate to print "then along came a person named ", mary There's also subtleties here - if foo.somesuch is an attribute, there is no chance of a side effect, but if foo.somesuch is a property, then it could inadvertently cause side effects, and only one side effect can totally ruin your day (that was the bulk of the complexity in the perl version of this, ensuring no side effects in the expanded vars) Likewise, if a line of code spans multiple lines, you may have identifiers that span these multiple lines which means you may miss some substitutions. So, again, I'm interested in ways of getting around these problems. In perl its very easy to do this because of sigils, would very much like to know how to do the same thing in python. thanks much, Ed (ps - this is what I've got so far, which is basically cobbled together from stuff on stackoverflow. Works ok, but lines #15-#16 AFAICT are the one that needs to be bulletproofed: 1 import sys 2 import linecache 3 import random 4 5 def traceit(frame, event, arg): 6 if event == "line": 7 lineno = frame.f_lineno 8 filename = frame.f_globals["__file__"] 9 if filename == "": 10 filename = "traceit.py" 11 if (filename.endswith(".pyc") or 12 filename.endswith(".pyo")): 13 filename = filename[:-1] 14 name = frame.f_globals["__name__"] 15 line = linecache.getline(filename, lineno) 16 print "%s:%s:%s: %s" % (name, lineno,frame.f_code.co_name,line.rstrip()) 17 return traceit 18 20 sys.settrace(traceit) 21 main() ) ( pps - is there a collection of tracers somewhere? This seems definitely the thing that you'd want to collect in a library somewhere, and switch tracers as you see fit depending on what you are looking for.. ) From anurag.chourasia at gmail.com Thu Dec 9 17:31:04 2010 From: anurag.chourasia at gmail.com (Anurag Chourasia) Date: Fri, 10 Dec 2010 04:01:04 +0530 Subject: ***locale.Error: unsupported locale setting*** Message-ID: Hi All, When i try to set a locale manually, i get this error. >>> import locale >>> locale.setlocale(locale.LC_ALL, 'es_cl.iso88591') Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/locale.py", line 531, in setlocale return _setlocale(category, locale) locale.Error: unsupported locale setting On my OS, when i run the locale -a command, i get this output ------------------------- *locale -a* C POSIX en_US en_US.8859-15 en_US.ISO8859-1 ------------------------- Does this means that on my machine, Python will be able to make use of above listed locales? *If yes then how can i possibly use the locale.setformat (or anything else for that matter) to group numbers using '.' as the thousands separator?* If i use the locale en_US then ',' is the thousands separator. >>> import locale >>> locale.setlocale(locale.LC_ALL, 'en_US') 'en_US' >>> locale.format("%d", 1255000, grouping=True) '1,255,000' Regards, Anurag -------------- next part -------------- An HTML attachment was scrubbed... URL: From nagle at animats.com Thu Dec 9 17:44:59 2010 From: nagle at animats.com (John Nagle) Date: Thu, 09 Dec 2010 14:44:59 -0800 Subject: 64 bit memory usage In-Reply-To: References: Message-ID: <4d015be7$0$1670$742ec2ed@news.sonic.net> On 12/8/2010 10:42 PM, Dennis Lee Bieber wrote: > On Wed, 8 Dec 2010 14:44:30 +0000, Rob Randall > declaimed the following in gmane.comp.python.general: > >> I am trying to understand how much memory is available to a 64 bit python >> process running under Windows XP 64 bit. >> >> When I run tests just creating a series of large dictionaries containing >> string keys and float values I do not seem to be able to grow the process >> beyond the amount of RAM present. If you get to the point where you need multi-gigabyte Python dictionaries, you may be using the wrong tool for the job. If it's simply that you need to manage a large amount of data, that's what databases are for. If this is some super high performance application that needs to keep a big database in memory for performance reasons, CPython is probably too slow. For that, something like Google's BigTable may be more appropriate, and will scale to terabytes if necessary. John Nagle From steve+comp.lang.python at pearwood.info Thu Dec 9 18:11:28 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Dec 2010 23:11:28 GMT Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <4cfebe65$0$1590$742ec2ed@news.sonic.net> <87ipz5jfr9.fsf.mdw@metalzone.distorted.org.uk> <4cfff225$0$1650$742ec2ed@news.sonic.net> <4d005835$0$1597$742ec2ed@news.sonic.net> <87vd33i1ba.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4d016220$0$30002$c3e8da3$5496439d@news.astraweb.com> On Thu, 09 Dec 2010 12:21:45 +0000, Mark Wooding wrote: > John Nagle writes: >> "sort" has failed because it assumes that a < b and b < c implies a < >> c. But that's not a valid assumption here. >> >> It's not good to break trichotomy. > > You're confused. The property > > a < b and b < c => a < c > > is called `transitivity'. Yes, but I believe that John is referring to the trichotomy (like a dichotomy, only there are three options instead of two) that exactly one of these relations are true: a < b a == b a > b It is true for real numbers, but not for IEEE floats, since none of the three are true if either a or b are a NAN. (Non-IEEE floats could do anything...) [...] > 2. Totality: a <= b or b <= a > > The above list sorting goes wrong because the `float' ordering isn't > total. In particular, x NaN!). I believe this is equivalent to trichotomy. > So, your last remark is in the right direction (though strict trichotomy > is unnecessary, as I've mentioned), but apparently only by accident > since the preceding discussion is completely wrong. "Completely" is surely a tad strong -- John might not be using the exact same terminology as you, but he's clearly talking about the equivalent concepts. He wants and expects all data types to either meet a total order, or raise an exception to any of the < > <= and >= operators. -- Steven From steve+comp.lang.python at pearwood.info Thu Dec 9 18:23:03 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Dec 2010 23:23:03 GMT Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <4cfebe65$0$1590$742ec2ed@news.sonic.net> <87ipz5jfr9.fsf.mdw@metalzone.distorted.org.uk> <4cfff225$0$1650$742ec2ed@news.sonic.net> <4d005835$0$1597$742ec2ed@news.sonic.net> <4d008c25$0$29987$c3e8da3$5496439d@news.astraweb.com> <4d011317$0$1664$742ec2ed@news.sonic.net> Message-ID: <4d0164d7$0$30002$c3e8da3$5496439d@news.astraweb.com> On Thu, 09 Dec 2010 09:34:19 -0800, John Nagle wrote: > (The best coverage of this whole topic was the Apple Numerics Manual > for the original Mac. Apple hired the floating point expert from > Berkeley to get this right. Then Apple went from the M68xxx series to > the IBM PowerPC, and 80-bit floats to 64-bit floats, breaking all the > engineering applications, most of which were never ported to the > PowerPC.) I second John's recommendation re the Apple Numerics Manual. Even if the Apple specific stuff is obsolete, it's a great resource for understanding floating point issues. -- Steven From steve+comp.lang.python at pearwood.info Thu Dec 9 18:44:35 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Dec 2010 23:44:35 GMT Subject: Request for feedback on API design Message-ID: <4d0169e2$0$30002$c3e8da3$5496439d@news.astraweb.com> I am soliciting feedback regarding the API of my statistics module: http://code.google.com/p/pycalcstats/ Specifically the following couple of issues: (1) Multivariate statistics such as covariance have two obvious APIs: A pass the X and Y values as two separate iterable arguments, e.g.: cov([1, 2, 3], [4, 5, 6]) B pass the X and Y values as a single iterable of tuples, e.g.: cov([(1, 4), (2, 5), (3, 6)] I currently support both APIs. Do people prefer one, or the other, or both? If there is a clear preference for one over the other, I may drop support for the other. (2) Statistics text books often give formulae in terms of sums and differences such as Sxx = n*?(x**2) - (?x)**2 There are quite a few of these: I count at least six common ones, all closely related and confusing named: Sxx, Syy, Sxy, SSx, SSy, SPxy (the x and y should all be subscript). Are they useful, or would they just add unnecessary complexity? Would people would like to see these included in the package? Thank you for your feedback. -- Steven From python at mrabarnett.plus.com Thu Dec 9 18:50:31 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 09 Dec 2010 23:50:31 +0000 Subject: Reference counting problems? In-Reply-To: References: Message-ID: <4D016B47.30206@mrabarnett.plus.com> On 09/12/2010 20:23, Eric Frederich wrote: > I am attempting to automate the building of binding for a 3rd party library. > The functions I'm wrapping all return an integer of whether they > failed and output are passed as pointers. > There can be multiple return values. > So the code that I generate has a PyObject* called python__return_val > that I use for returning. > In the 'wrapped_foo' function below you see I build the return value > with Py_BuildValue and "OO" as the format. > For every output I have I do a C to Python conversion and add another > 'O' to the format. > What I'm wondering is if I can use the same logic when wrapping > functions that only return one value like the wrapped_bar function > below. > > So for multiples, I wind up doing this which is fine. > > python__x = Py_BuildValue("s", x) The object at python__x has a refcount of 1. > python__y = Py_BuildValue("s", y) The object at python__y has a refcount of 1. > python__return_val = Py_BuildValue("OO", python__x, python__y); The object at python__return_val (a tuple) has a refcount of 1. This object refers to the objects at python__x and python__y, so both of their refcounts will have been incremented to 2. You will need to DECREF the objects at python__x and python__y before the C variables python__x and python__y go out of scope. > > But for single returns I do something like this.... > I realize that the 2 lines below are pointless, but are they causing a > memory leak or problems with reference counting? > > python__x = Py_BuildValue("s", x) The object at python__x has a refcount of 1. > python__return_val = Py_BuildValue("O", python__x); In this case Py_BuildValue returns its argument python__x, but will have incremented its refcount to 2. This means that you still need to DECREF the object at python__x before the C variable python__x goes out of scope. This is probably just for consistency, because it's easier to remember that /every time/ you pass an object to Py_BuildValue its refcount will be incremented, than if it was sometimes yes, sometimes no. > > > Are python__x and python__return_val the same object, a copy of the object? > Would python__x ever get garbage collected? > Should my code generator detect when there is only one output and not > go through the extra step? > [snip] From vlastimil.brom at gmail.com Thu Dec 9 18:52:15 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Fri, 10 Dec 2010 00:52:15 +0100 Subject: ***locale.Error: unsupported locale setting*** In-Reply-To: References: Message-ID: 2010/12/9 Anurag Chourasia : > Hi All, > When i try to set a locale manually, i get this error. >>>> import locale >>>> locale.setlocale(locale.LC_ALL, 'es_cl.iso88591') > Traceback (most recent call last): > ??File "", line 1, in > ??File "/usr/local/lib/python2.7/locale.py", line 531, in setlocale > ?? ?return _setlocale(category, locale) > locale.Error: unsupported locale setting > On my OS, when i run the locale -a command, i get this output > ------------------------- > locale -a > C > POSIX > en_US > en_US.8859-15 > en_US.ISO8859-1 > ------------------------- > Does this means that on my machine, Python will be able to make use of above > listed locales? > If yes then how can i possibly use the locale.setformat (or anything else > for that matter) to group numbers using '.' as the thousands separator? > If i use the locale en_US then ',' is the thousands separator. >>>> import locale >>>> locale.setlocale(locale.LC_ALL, 'en_US') > 'en_US' >>>> locale.format("%d", 1255000, grouping=True) > '1,255,000' > Regards, > Anurag > -- > http://mail.python.org/mailman/listinfo/python-list > > Hi, I am not sure, it helps in your case, but the simple locale aliases (like "Spanish") seem to work for me (py 2.7.1, win 7) >>> locale.getlocale() ('Czech_Czech Republic', '1250') >>> locale.localeconv()['thousands_sep'] '\xa0' >>> locale.setlocale(locale.LC_ALL, "Spanish") 'Spanish_Spain.1252' >>> locale.localeconv()['thousands_sep'] '.' >>> locale.format("%d", 1255000, grouping=True) '1.255.000' >>> hth, vbr From vinay_sajip at yahoo.co.uk Thu Dec 9 19:12:13 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Thu, 9 Dec 2010 16:12:13 -0800 (PST) Subject: Proposed changes to logging defaults Message-ID: <3763d355-9074-485c-a694-031d600d5b84@m11g2000vbs.googlegroups.com> Some changes are being proposed to how logging works in default configurations. Briefly - when a logging event occurs which needs to be output to some log, the behaviour of the logging package when no explicit logging configuration is provided will change, most likely to log those events to sys.stderr with a default format. Since this proposed change to behaviour is backwards-incompatible (and scheduled to come in to Python 3.2 - earlier Pythons, including 2.X, are unaffected), you may be interested in seeing if the changes affect you. More details are available here: http://plumberjack.blogspot.com/2010/12/proposed-changes-to-logging-defaults.html Please feel free to add comments to the linked blog post. Regards, Vinay Sajip From python.list at tim.thechases.com Thu Dec 9 19:48:10 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 09 Dec 2010 18:48:10 -0600 Subject: Request for feedback on API design In-Reply-To: <4d0169e2$0$30002$c3e8da3$5496439d@news.astraweb.com> References: <4d0169e2$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4D0178CA.1060200@tim.thechases.com> On 12/09/2010 05:44 PM, Steven D'Aprano wrote: > (1) Multivariate statistics such as covariance have two obvious APIs: > > A pass the X and Y values as two separate iterable arguments, e.g.: > cov([1, 2, 3], [4, 5, 6]) > > B pass the X and Y values as a single iterable of tuples, e.g.: > cov([(1, 4), (2, 5), (3, 6)] > > I currently support both APIs. Do people prefer one, or the other, or > both? If there is a clear preference for one over the other, I may drop > support for the other. I'm partial to the "B" form (iterable of 2-tuples) -- it indicates that the two data-sets (x_n and y_n) should be of the same length and paired. The "A" form leaves this less obvious that len(param1) should equal len(param2). I haven't poked at your code sufficiently to determine whether all the functions within can handle streamed data, or whether they keep the entire dataset internally, but handing off an iterable-of-pairs tends to be a little more straight-forward: cov(humongous_dataset_iter) or cov(izip(humongous_dataset_iter1, humongous_dataset_iter2)) The "A" form makes doing this a little less obvious than the "B" form. > (2) Statistics text books often give formulae in terms of sums and > differences such as > > Sxx = n*?(x**2) - (?x)**2 > > There are quite a few of these: I count at least six common ones, When you take this count, is it across multiple text-books, or are they common in just a small sampling of texts? (I confess it's been a decade and a half since I last suffered a stats class) > all closely related and confusing named: > > Sxx, Syy, Sxy, SSx, SSy, SPxy > > (the x and y should all be subscript). > > Are they useful, or would they just add unnecessary complexity? I think it depends on your audience: amateur statisticians or pros? I suspect that pros wouldn't blink at the distinctions while weekenders like myself would get a little bleary-eyed without at least a module docstring to clearly spell out the distinctions and the forumlae used for determining them. Just my from-the-hip thoughts for whatever little they may be worth. -tkc From ethan at stoneleaf.us Thu Dec 9 19:48:47 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 09 Dec 2010 16:48:47 -0800 Subject: Proposed changes to logging defaults In-Reply-To: <3763d355-9074-485c-a694-031d600d5b84@m11g2000vbs.googlegroups.com> References: <3763d355-9074-485c-a694-031d600d5b84@m11g2000vbs.googlegroups.com> Message-ID: <4D0178EF.9040407@stoneleaf.us> Vinay Sajip wrote: > Some changes are being proposed to how logging works in default > configurations. I like the changes proposed. Question about the "handler of last resort": is there only one of them, or will each library have its own so it can decide what the minimum severity should be for itself? (My apologies if this question only reveals my own ignorance.) ~Ethan~ From skippy.hammond at gmail.com Thu Dec 9 19:59:49 2010 From: skippy.hammond at gmail.com (Mark Hammond) Date: Thu, 09 Dec 2010 16:59:49 -0800 Subject: win32 design pattern: COM localserver? In-Reply-To: <92573244-ab87-4143-9e87-26f851b6a3a1@w17g2000yqh.googlegroups.com> References: <92573244-ab87-4143-9e87-26f851b6a3a1@w17g2000yqh.googlegroups.com> Message-ID: <4D017B85.9060301@gmail.com> If you are implementing a COM object using win32com, then Python will never be unloaded from the host process, which works in your favour. Just have the COM object use a thread and a queue for this processing. The 'report' method would just stick the params and filenames in the queue and return immediately - your thread should stay alive and working away so long as the host process remains alive. You probably need to deal with the face the thread will be unexpectedly terminated when the host process terminates or add a new method designed explicitly to block the host process until everything is complete - the host program would then call this method just before it terminates. Also note there is a python-win32 at python.org mailing list where you might get better or more advice... Cheers, Mark On 8/12/2010 8:03 PM, kirby.urner at gmail.com wrote: > Greetings gurus. > > I'm faced with the challenge of having a single-threaded proprietary > Win32 > language wanting to do multiple calls against a Python COM object. > > Something like... > > loObj = CREATEOBJECT("map_maker") > loObj.report( params, filename) > > do while .True. > yadda yadda > enddo > > RETURN > > I.e. the client program continues execution while loObj churns away > somewhere doing work in Python, say accessing a MySQL database > and building a map, embedding it in a PDF. > > Am I right that the COM object will need to "serve forever" i.e. be > built around some non-terminating loop? Will the client's call then > spawn a process or thread that continues until finished? > > All it has to do is leave a file on disk somewhere, then die. But > the client can't be kept on the hook until that's all done. > > I've had good luck doing an InProcess COM object the generates > a PDF from ReportLab. But this "stay alive while returning control > to the client" challenge looks like it might be a job for sockets? > > Gee I hope not. > > Quick links to favorite blog articles will give me a sense of the > ballpark... Any clues welcome. Yes, I have the Win32 book from > O'Reilly. > > Kirby > > PS: my thanks to Ethan Furman for performing maintenance and > upgrades on his dbf module on PyPI. The FoxPro gods thank you. > http://pypi.python.org/pypi/dbf/0.88.16 > > PPS: some thoughts about IronPython filed here, after trying to > catch up some, sorry about my formatting, here too. > http://mail.python.org/pipermail/edu-sig/2010-December/010138.html > From psdasilva.nospam at netcabonospam.pt Thu Dec 9 20:15:37 2010 From: psdasilva.nospam at netcabonospam.pt (Paulo da Silva) Date: Fri, 10 Dec 2010 01:15:37 +0000 Subject: dns library Message-ID: <4d017f39$0$30503$a729d347@news.telepac.pt> Hi. Is there a python library/module to handle both the server and client sides of dns protocol? I have googled for it but I only found client side ones (at least from the superficial readings I did). Thanks. From vinay_sajip at yahoo.co.uk Thu Dec 9 21:49:31 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Thu, 9 Dec 2010 18:49:31 -0800 (PST) Subject: Proposed changes to logging defaults References: <3763d355-9074-485c-a694-031d600d5b84@m11g2000vbs.googlegroups.com> Message-ID: <06eff2d7-bdd1-4750-b07f-9d95752c8b0b@j1g2000vbl.googlegroups.com> On Dec 10, 12:48?am, Ethan Furman wrote: > > I like the changes proposed. > > Question about the "handler of last resort": ?is there only one of them, > or will each library have its own so it can decide what the minimum > severity should be for itself? Libraries decide their severities differently, by setting a level on their top level logger. There's only one handler of last resort (else it wouldn't be a last resort). Generally, application developers determine the level for each logger they're interested; if no explicit levels are set, the default is the level of the root logger (WARNING by default). Thanks for the feedback, Vinay Sajip From calderone.jeanpaul at gmail.com Thu Dec 9 21:59:59 2010 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Thu, 9 Dec 2010 18:59:59 -0800 (PST) Subject: dns library References: <4d017f39$0$30503$a729d347@news.telepac.pt> Message-ID: On Dec 9, 8:15?pm, Paulo da Silva wrote: > Hi. > > Is there a python library/module to handle both the server and client > sides of dns protocol? > > I have googled for it but I only found client side ones (at least from > the superficial readings I did). > > Thanks. Twisted Names is one such library: http://twistedmatrix.com/trac/wiki/TwistedNames From rustompmody at gmail.com Thu Dec 9 22:15:11 2010 From: rustompmody at gmail.com (rusi) Date: Thu, 9 Dec 2010 19:15:11 -0800 (PST) Subject: Deprecation warnings (2.7 -> 3 ) Message-ID: <44caabf0-7f83-42b8-abf9-eb40ea6b63a8@i32g2000pri.googlegroups.com> In trying to get from 2.x to 3 Terry suggested I use 2.7 with deprecation warnings Heres the (first) set DeprecationWarning: Overriding __eq__ blocks inheritance of __hash__ in 3.x DeprecationWarning: callable() not supported in 3.x; use isinstance(x, collections.Callable) Is there one place/site I can go to for understanding all these and trying to clear them? From smallpox911 at gmail.com Thu Dec 9 22:32:23 2010 From: smallpox911 at gmail.com (small Pox) Date: Thu, 9 Dec 2010 19:32:23 -0800 (PST) Subject: little emacs lisp tutorial on turning a url into a link References: <8aa7d0e9-4263-4083-b1a9-2013a83a0f81@z20g2000pra.googlegroups.com> <9431e600-5930-4964-908e-2ed5a3f2f2db@o23g2000prh.googlegroups.com> <84f8e44e-af70-430b-b498-e1482aa7d0fc@t8g2000prh.googlegroups.com> Message-ID: On Dec 4, 1:38 am, Xah Lee wrote: > > On Dec 3, 8:20 pm, duckblue wrote: > > > why is xah lee posting this information? > > > > sites with more external links pointing to them are given a higher > > > ranking by search engines such as google. as a result they appear > > > closer to the top of the search engine results pages ('SERPs' in SEO > > > lingo). > > > xah's posting here is part of active an SEO campaign that he is > > > carrying out in order bring traffic to his site.- Hide quoted text - > > On Dec 3, 9:16 pm, small Pox wrote: > > > Xah Lee writes good articles. She has a helpful attitude. Do you want > > her to become so financially dependent like that innocent looking > > rabbit teeth Adelyn Lee so she become a prostitute of Larry Ellis > > Islander who has gobbled up Sun, mysql, cray and so many software and > > hardware companies to make the largest and possibly going to be a most > > evil monopoly on earth ? > > thanks. > > interesting mention about Adelyn Lee. > > I looked up, > > ?Woman Who Accused Oracle Chief Guilty of Perjury? January 29, 1997, > By Benjamin Pimentel, Chronicle Peninsula Bureau. SFGate Articles. > ?http://articles.sfgate.com/1997-01-29/news/17741019_1_mr-ellison-adel... > ? > > Quote: > > ?A San Mateo woman accused of forging e-mail to sue Oracle Corp. was > found guilty yesterday of perjury and falsification of evidence.? > > ?Adelyn Lee, a 33-year-old former girlfriend of Oracle Chief Executive > Officer Larry Ellison, was convicted by a San Mateo County jury, > ending a Silicon Valley soap opera that revealed some of the inner > workings of the world's second-largest software company. ? > > ?In 1995, Lee won a $100,000 settlement of a wrongful termination suit > in which she claimed that she was fired from her job as an executive > assistant after she refused to have sex with Ellison. ? > > interesting. Yeah, the 1990s, everything is sexual harassment. > > it so happpens, i have a story to tell as well. I was officially > accused of sexual harassment in around 2000 while working at Netopia. I dont know about your story, but I know about many stories http://www.orafraud.info/terminator_4.0.html To dig them you have to search hard enough. The one you found was skewed by SEO type work. The khazars are very tight-knit. Also rasputin has lots of money to get people to write fiction on him and his current wife is a fiction writer as well. The Kourts are cangaroo. Lies are as common as roman polansky fleed to europe after raping a 13years old. Your attempt to flatter is amateurish. It shows through that you are trying to flatter the money. Dont be cannibalizing that innocent girl. He baited her by a car which is worthless. Her virginity was stolen - priceless. She expected to be married and everyone knows that this is what any woman's price of sex is. Like your own mother. The guy is from anonymous father so he tries to put every decent woman down ... perhaps. He fired her to escape her vengeance. His sycophants then altered database records. She could not fight in the court. American courts are filled with false lawsuits. They did this to germany and now doing to USA. Orwell understood them one century before us. In 1984 he describes them as the guy O?Brien who "treated" Winston. You should thoroughly read the protocols of the learned elders of zion at the atzlan site and archive all of their versions and commentaries. Flattery wont get you anywhere ... better apply your brain power to create a rival to database before they gobble up all the hardware companies to make computers with builtin trojans in hardware like the telescreen of 1984. > The whole case is ridiculous. The woman who accused me, was > romantically interested in me. She's got some personal psychological > problems. We both are sys admins (but i also do dev). She lives and > work at the Kansas branch, while i work in California. Once or twice a > year, the company has her flew over for business, typically lasting > just a day. I'm not her superior or vice versa. Our relationship > started when she started to IM me and got me to use AOL. The AOL chat > is kinda used for business discussions as well, since it's just > convenient, and apparantly it became popular in the company. > (remember, this is 1999.) When she came over, i think the second time, > then later, she filed a sexual harassment to Netopia. (i didn't even > know before) We did not sleep together. The closest physical contact > might be holding hands, which, i don't remember we actually did. All i > know after the whole thing is that she's got some kinda love hang- > over. > > At the end, they (the human resource woman who handles this) ask me to > sign a paper, which, if i recall correctly, basically want me to admit > some wrong doing or something like that. I do not agree to it, i > refused to sign. And that basically is the end of it. She quit or was > fired sometimes later on (don't think it has anything to do with > this). I was laid off in 2002. (Netopia got bought by Motorola in > ~2005) > > I may write up a blog, with full disclosure of all documents of the > case and emails sometimes later. > > Xah From smallpox911 at gmail.com Thu Dec 9 22:51:33 2010 From: smallpox911 at gmail.com (small Pox) Date: Thu, 9 Dec 2010 19:51:33 -0800 (PST) Subject: little emacs lisp tutorial on turning a url into a link References: <8aa7d0e9-4263-4083-b1a9-2013a83a0f81@z20g2000pra.googlegroups.com> <9431e600-5930-4964-908e-2ed5a3f2f2db@o23g2000prh.googlegroups.com> <84f8e44e-af70-430b-b498-e1482aa7d0fc@t8g2000prh.googlegroups.com> Message-ID: <8861922a-88e7-4fc5-a877-5b852273da56@30g2000yql.googlegroups.com> On Dec 9, 7:32?pm, small Pox wrote: > On Dec 4, 1:38 am, Xah Lee wrote: > > > > > > > > On Dec 3, 8:20 pm, duckblue wrote: > > > > why is xah lee posting this information? > > > > > sites with more external links pointing to them are given a higher > > > > ranking by search engines such as google. as a result they appear > > > > closer to the top of the search engine results pages ('SERPs' in SEO > > > > lingo). > > > > xah's posting here is part of active an SEO campaign that he is > > > > carrying out in order bring traffic to his site.- Hide quoted text - > > > On Dec 3, 9:16 pm, small Pox wrote: > > > > Xah Lee writes good articles. She has a helpful attitude. Do you want > > > her to become so financially dependent like that innocent looking > > > rabbit teeth Adelyn Lee so she become a prostitute of Larry Ellis > > > Islander who has gobbled up Sun, mysql, cray and so many software and > > > hardware companies to make the largest and possibly going to be a most > > > evil monopoly on earth ? > > > thanks. > > > interesting mention about Adelyn Lee. > > > I looked up, > > > ?Woman Who Accused Oracle Chief Guilty of Perjury? January 29, 1997, > > By Benjamin Pimentel, Chronicle Peninsula Bureau. SFGate Articles. > > ?http://articles.sfgate.com/1997-01-29/news/17741019_1_mr-ellison-adel... > > ? > > > Quote: > > > ?A San Mateo woman accused of forging e-mail to sue Oracle Corp. was > > found guilty yesterday of perjury and falsification of evidence.? > > > ?Adelyn Lee, a 33-year-old former girlfriend of Oracle Chief Executive > > Officer Larry Ellison, was convicted by a San Mateo County jury, > > ending a Silicon Valley soap opera that revealed some of the inner > > workings of the world's second-largest software company. ? > > > ?In 1995, Lee won a $100,000 settlement of a wrongful termination suit > > in which she claimed that she was fired from her job as an executive > > assistant after she refused to have sex with Ellison. ? > > > interesting. Yeah, the 1990s, everything is sexual harassment. > > > it so happpens, i have a story to tell as well. I was officially > > accused of sexual harassment in around 2000 while working at Netopia. > > I dont know about your story, but I know about many stories > > http://www.orafraud.info/terminator_4.0.html > > To dig them you have to search hard enough. > > The one you found was skewed by SEO type work. The khazars are very > tight-knit. > > Also rasputin has lots of money to get people to write fiction on him > and his current wife is a fiction writer as well. The Kourts are > cangaroo. Lies are as common as roman polansky fleed to europe after > raping a 13years old. > > Your attempt to flatter is amateurish. It shows through that you are > trying to flatter the money. > > Dont be cannibalizing that innocent girl. He baited her by a car which > is worthless. Her virginity was stolen - priceless. She expected to be > married and everyone knows that this is what any woman's price of sex > is. > > Like your own mother. > > The guy is from anonymous father so he tries to put every decent woman > down ... perhaps. > > He fired her to escape her vengeance. > > His sycophants then altered database records. > > She could not fight in the court. American courts are filled with > false lawsuits. > > They did this to germany and now doing to USA. > > Orwell understood them one century before us. In 1984 he describes > them as the guy O?Brien who "treated" Winston. You should thoroughly > read the protocols of the learned elders of zion at the atzlan site > and archive all of their versions and commentaries. > > Flattery wont get you anywhere ?... better apply your brain power to > create a rival to database before they gobble up all the hardware > companies to make computers with builtin trojans in hardware like the > telescreen of 1984. > > > > > The whole case is ridiculous. The woman who accused me, was > > romantically interested in me. She's got some personal psychological > > problems. We both are sys admins (but i also do dev). She lives and > > work at the Kansas branch, while i work in California. Once or twice a > > year, the company has her flew over for business, typically lasting > > just a day. I'm not her superior or vice versa. Our relationship > > started when she started to IM me and got me to use AOL. ?The AOL chat > > is kinda used for business discussions as well, since it's just > > convenient, and apparantly it became popular in the company. > > (remember, this is 1999.) When she came over, i think the second time, > > then later, she filed a sexual harassment to Netopia. (i didn't even > > know before) We did not sleep together. The closest physical contact > > might be holding hands, which, i don't remember we actually did. All i > > know after the whole thing is that she's got some kinda love hang- > > over. > > > At the end, they (the human resource woman who handles this) ask me to > > sign a paper, which, if i recall correctly, basically want me to admit > > some wrong doing or something like that. I do not agree to it, i > > refused to sign. And that basically is the end of it. She quit or was > > fired sometimes later on (don't think it has anything to do with > > this). I was laid off in 2002. (Netopia got bought by Motorola in > > ~2005) > > > I may write up a blog, with full disclosure of all documents of the > > case and emails sometimes later. > > > ?Xah- Hide quoted text - > > - Show quoted text -- Hide quoted text - > > - Show quoted text - I advocate neither anti semitism nor pro semitism. just the rule of law that treats people equally and fairly and where money does not count. this cannot be achieved without demolishing fractional reserve lending, and not without making the courts free and preventing knowledge monopolies. If a certain group is going up disproportionately, then there is something to look at. I see everyone work as hard as anyone else. From smallpox911 at gmail.com Thu Dec 9 22:52:12 2010 From: smallpox911 at gmail.com (small Pox) Date: Thu, 9 Dec 2010 19:52:12 -0800 (PST) Subject: little emacs lisp tutorial on turning a url into a link References: <8aa7d0e9-4263-4083-b1a9-2013a83a0f81@z20g2000pra.googlegroups.com> <9431e600-5930-4964-908e-2ed5a3f2f2db@o23g2000prh.googlegroups.com> <84f8e44e-af70-430b-b498-e1482aa7d0fc@t8g2000prh.googlegroups.com> Message-ID: <4ecd60b8-7366-4bc6-b7dc-1e5cf2aa874f@t35g2000yqj.googlegroups.com> On Dec 9, 7:32 pm, small Pox wrote: > On Dec 4, 1:38 am, Xah Lee wrote: > > > > > > > > On Dec 3, 8:20 pm, duckblue wrote: > > > > why is xah lee posting this information? > > > > > sites with more external links pointing to them are given a higher > > > > ranking by search engines such as google. as a result they appear > > > > closer to the top of the search engine results pages ('SERPs' in SEO > > > > lingo). > > > > xah's posting here is part of active an SEO campaign that he is > > > > carrying out in order bring traffic to his site.- Hide quoted text - > > > On Dec 3, 9:16 pm, small Pox wrote: > > > > Xah Lee writes good articles. She has a helpful attitude. Do you want > > > her to become so financially dependent like that innocent looking > > > rabbit teeth Adelyn Lee so she become a prostitute of Larry Ellis > > > Islander who has gobbled up Sun, mysql, cray and so many software and > > > hardware companies to make the largest and possibly going to be a most > > > evil monopoly on earth ? > > > thanks. > > > interesting mention about Adelyn Lee. > > > I looked up, > > > ?Woman Who Accused Oracle Chief Guilty of Perjury? January 29, 1997, > > By Benjamin Pimentel, Chronicle Peninsula Bureau. SFGate Articles. > > ?http://articles.sfgate.com/1997-01-29/news/17741019_1_mr-ellison-adel... > > ? > > > Quote: > > > ?A San Mateo woman accused of forging e-mail to sue Oracle Corp. was > > found guilty yesterday of perjury and falsification of evidence.? > > > ?Adelyn Lee, a 33-year-old former girlfriend of Oracle Chief Executive > > Officer Larry Ellison, was convicted by a San Mateo County jury, > > ending a Silicon Valley soap opera that revealed some of the inner > > workings of the world's second-largest software company. ? > > > ?In 1995, Lee won a $100,000 settlement of a wrongful termination suit > > in which she claimed that she was fired from her job as an executive > > assistant after she refused to have sex with Ellison. ? > > > interesting. Yeah, the 1990s, everything is sexual harassment. > > > it so happpens, i have a story to tell as well. I was officially > > accused of sexual harassment in around 2000 while working at Netopia. > > I dont know about your story, but I know about many stories > > http://www.orafraud.info/terminator_4.0.html > > To dig them you have to search hard enough. > > The one you found was skewed by SEO type work. The khazars are very > tight-knit. > > Also rasputin has lots of money to get people to write fiction on him > and his current wife is a fiction writer as well. The Kourts are > cangaroo. Lies are as common as roman polansky fleed to europe after > raping a 13years old. > > Your attempt to flatter is amateurish. It shows through that you are > trying to flatter the money. > > Dont be cannibalizing that innocent girl. He baited her by a car which > is worthless. Her virginity was stolen - priceless. She expected to be > married and everyone knows that this is what any woman's price of sex > is. > > Like your own mother. > > The guy is from anonymous father so he tries to put every decent woman > down ... perhaps. > > He fired her to escape her vengeance. > > His sycophants then altered database records. > > She could not fight in the court. American courts are filled with > false lawsuits. > > They did this to germany and now doing to USA. > > Orwell understood them one century before us. In 1984 he describes > them as the guy O?Brien who "treated" Winston. You should thoroughly > read the protocols of the learned elders of zion at the atzlan site > and archive all of their versions and commentaries. > > Flattery wont get you anywhere ... better apply your brain power to > create a rival to database before they gobble up all the hardware > companies to make computers with builtin trojans in hardware like the > telescreen of 1984. > > > > > The whole case is ridiculous. The woman who accused me, was > > romantically interested in me. She's got some personal psychological > > problems. We both are sys admins (but i also do dev). She lives and > > work at the Kansas branch, while i work in California. Once or twice a > > year, the company has her flew over for business, typically lasting > > just a day. I'm not her superior or vice versa. Our relationship > > started when she started to IM me and got me to use AOL. The AOL chat > > is kinda used for business discussions as well, since it's just > > convenient, and apparantly it became popular in the company. > > (remember, this is 1999.) When she came over, i think the second time, > > then later, she filed a sexual harassment to Netopia. (i didn't even > > know before) We did not sleep together. The closest physical contact > > might be holding hands, which, i don't remember we actually did. All i > > know after the whole thing is that she's got some kinda love hang- > > over. > > > At the end, they (the human resource woman who handles this) ask me to > > sign a paper, which, if i recall correctly, basically want me to admit > > some wrong doing or something like that. I do not agree to it, i > > refused to sign. And that basically is the end of it. She quit or was > > fired sometimes later on (don't think it has anything to do with > > this). I was laid off in 2002. (Netopia got bought by Motorola in > > ~2005) > > > I may write up a blog, with full disclosure of all documents of the > > case and emails sometimes later. > > > Xah- Hide quoted text - > > - Show quoted text -- Hide quoted text - > > - Show quoted text - I advocate neither anti semitism nor pro semitism. just the rule of law that treats people equally and fairly and where money does not count. this cannot be achieved without demolishing fractional reserve lending, and not without making the courts free and preventing knowledge monopolies. If a certain group is going up disproportionately, then there is something to look at. I see everyone work as hard as anyone else. From tjreedy at udel.edu Thu Dec 9 23:21:47 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 09 Dec 2010 23:21:47 -0500 Subject: Deprecation warnings (2.7 -> 3 ) In-Reply-To: <44caabf0-7f83-42b8-abf9-eb40ea6b63a8@i32g2000pri.googlegroups.com> References: <44caabf0-7f83-42b8-abf9-eb40ea6b63a8@i32g2000pri.googlegroups.com> Message-ID: On 12/9/2010 10:15 PM, rusi wrote: > In trying to get from 2.x to 3 Terry suggested I use 2.7 with > deprecation warnings > > > Heres the (first) set > > DeprecationWarning: Overriding __eq__ blocks inheritance of __hash__ > in 3.x > DeprecationWarning: callable() not supported in 3.x; use isinstance(x, > collections.Callable) > > Is there one place/site I can go to for understanding all these and > trying to clear them? Not that I know of, but it would be a good idea. You could suggest on the tracker the addition of HOW TO Clear Deprecation Warnings, 2.7. There would need to be a new one for each release, based on grepping the codebase. -- Terry Jan Reedy From rustompmody at gmail.com Fri Dec 10 00:53:39 2010 From: rustompmody at gmail.com (rusi) Date: Thu, 9 Dec 2010 21:53:39 -0800 (PST) Subject: trace cmd line args in 2.7 Message-ID: Ive installed python 2.7 And trace still ignores my ignore-module etc requests From psdasilva.nospam at netcabonospam.pt Fri Dec 10 01:12:31 2010 From: psdasilva.nospam at netcabonospam.pt (Paulo da Silva) Date: Fri, 10 Dec 2010 06:12:31 +0000 Subject: dns library In-Reply-To: References: <4d017f39$0$30503$a729d347@news.telepac.pt> Message-ID: <4d01c4ce$0$30506$a729d347@news.telepac.pt> Em 10-12-2010 02:59, Jean-Paul Calderone escreveu: > On Dec 9, 8:15 pm, Paulo da Silva > wrote: >> Hi. >> >> Is there a python library/module to handle both the server and client >> sides of dns protocol? >> >> I have googled for it but I only found client side ones (at least from >> the superficial readings I did). >> >> Thanks. > > Twisted Names is one such library: http://twistedmatrix.com/trac/wiki/TwistedNames I've just looked at its home page and it seems to be what I need. Thank you very much. From markjason72 at gmail.com Fri Dec 10 01:16:17 2010 From: markjason72 at gmail.com (mark jason) Date: Thu, 9 Dec 2010 22:16:17 -0800 (PST) Subject: printing error message from an Exception Message-ID: <2c9af3ec-294c-4cd4-aca3-cbc62dba09b6@u9g2000pra.googlegroups.com> hi I was trying out some file operations and was trying to open a non existing file as below def do_work(filename): try: f = open(filename,"r"); print 'opened' except IOError, e: print 'failed',e.message finally: f.close() print 'closed' if __name__=='__main__': do_work("C:\code\misc.txt") # there is no such file I am getting an error and a warning DeprecationWarning: BaseException.message has been deprecated as of Python 2.6 print 'failed',e.message UnboundLocalError: local variable 'f' referenced before assignment Is there a way to overcome the DeprecationWarning? I wanted to print the error message from the IOError.How do I do this? Also ,what should I do about the UnboundLocalError? thanks and regards , mark From steve+comp.lang.python at pearwood.info Fri Dec 10 01:55:27 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Dec 2010 06:55:27 GMT Subject: printing error message from an Exception References: <2c9af3ec-294c-4cd4-aca3-cbc62dba09b6@u9g2000pra.googlegroups.com> Message-ID: <4d01cede$0$30002$c3e8da3$5496439d@news.astraweb.com> On Thu, 09 Dec 2010 22:16:17 -0800, mark jason wrote: > hi > I was trying out some file operations and was trying to open a non > existing file as below > > def do_work(filename): > try: > f = open(filename,"r"); > print 'opened' > except IOError, e: > print 'failed',e.message > finally: > f.close() > print 'closed' The problem is, you try to close a file that not only hasn't been opened, but the name f isn't bound to a value: >>> do_work('no such file') failed Traceback (most recent call last): File "", line 1, in File "", line 8, in do_work UnboundLocalError: local variable 'f' referenced before assignment > if __name__=='__main__': > do_work("C:\code\misc.txt") # there is no such file > > I am getting an error and a warning > > DeprecationWarning: BaseException.message has been deprecated as of > Python 2.6 > print 'failed',e.message > > UnboundLocalError: local variable 'f' referenced before assignment > > Is there a way to overcome the DeprecationWarning? I wanted to print the > error message from the IOError.How do I do this? Generally, the best way to print error messages is to print the *entire* error message, including the traceback. You do that by just not catching the exception at all. But for the times you do need to do something else with the exception, instead of exception.message, look at exception.args. This will be a tuple of one or more items, the first item should be the error message. > Also ,what should I do about the UnboundLocalError? Use finally for things which must be done regardless of whether or not the previous operation succeeded, not for things that should only be done if the previous operation succeeded but not if it failed. def do_work(filename): try: f = open(filename,"r"); print 'opened' except IOError, e: # By the way, IOError is not the only exception you could see. print 'failed', e.args else: f.close() print 'closed' Or, slightly more useful: def do_work(filename): s = '' try: f = open(filename,"r"); print 'opened' except IOError, e: # By the way, IOError is not the only exception you could see. print 'failed', e.args else: try: s = f.read() finally: f.close() print 'closed' print s -- Steven From steve+comp.lang.python at pearwood.info Fri Dec 10 02:51:54 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Dec 2010 07:51:54 GMT Subject: Request for feedback on API design References: <4d0169e2$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4d01dc19$0$30002$c3e8da3$5496439d@news.astraweb.com> On Thu, 09 Dec 2010 18:48:10 -0600, Tim Chase wrote: > On 12/09/2010 05:44 PM, Steven D'Aprano wrote: >> (1) Multivariate statistics such as covariance have two obvious APIs: >> >> A pass the X and Y values as two separate iterable arguments, >> e.g.: >> cov([1, 2, 3], [4, 5, 6]) >> >> B pass the X and Y values as a single iterable of tuples, e.g.: >> cov([(1, 4), (2, 5), (3, 6)] >> >> I currently support both APIs. Do people prefer one, or the other, or >> both? If there is a clear preference for one over the other, I may drop >> support for the other. > > I'm partial to the "B" form (iterable of 2-tuples) -- it indicates that > the two data-sets (x_n and y_n) should be of the same length and paired. > The "A" form leaves this less obvious that len(param1) should equal > len(param2). Thanks for the comments Tim. To answer your questions: > I haven't poked at your code sufficiently to determine whether all the > functions within can handle streamed data, or whether they keep the > entire dataset internally, Where possible, the functions don't keep the entire dataset internally. Some functions have to (e.g. order statistics need to see the entire data sequence at once), but the rest are capable of dealing with streamed data. Also, there are a few functions such as standard deviation that have a single-pass algorithm, and a more accurate multiple-pass algorithm. >> (2) Statistics text books often give formulae in terms of sums and >> differences such as >> >> Sxx = n*?(x**2) - (?x)**2 >> >> There are quite a few of these: I count at least six common ones, > > When you take this count, is it across multiple text-books, or are they > common in just a small sampling of texts? (I confess it's been a decade > and a half since I last suffered a stats class) I admit that I haven't done an exhaustive search of the literature, but it does seen quite common to extract common expressions from various stats formulae and give them names. The only use-case I can imagine for them is checking hand-calculations or doing schoolwork. -- Steven From steve at holdenweb.com Fri Dec 10 03:49:01 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 10 Dec 2010 09:49:01 +0100 Subject: little emacs lisp tutorial on turning a url into a link In-Reply-To: <4ecd60b8-7366-4bc6-b7dc-1e5cf2aa874f@t35g2000yqj.googlegroups.com> References: <8aa7d0e9-4263-4083-b1a9-2013a83a0f81@z20g2000pra.googlegroups.com> <9431e600-5930-4964-908e-2ed5a3f2f2db@o23g2000prh.googlegroups.com> <84f8e44e-af70-430b-b498-e1482aa7d0fc@t8g2000prh.googlegroups.com> <4ecd60b8-7366-4bc6-b7dc-1e5cf2aa874f@t35g2000yqj.googlegroups.com> Message-ID: <4D01E97D.5040009@holdenweb.com> On 12/10/2010 4:52 AM, small Pox wrote: [... irrelevant stuff...] > I advocate neither anti semitism nor pro semitism. just the rule of > law that treats people equally and fairly and where money does not > count. this cannot be achieved without demolishing fractional reserve > lending, and not without making the courts free and preventing > knowledge monopolies. If a certain group is going up > disproportionately, then there is something to look at. I see everyone > work as hard as anyone else. This is completely off-topic for c.l.py. Kindly bugger off. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Fri Dec 10 03:49:01 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 10 Dec 2010 09:49:01 +0100 Subject: little emacs lisp tutorial on turning a url into a link In-Reply-To: <4ecd60b8-7366-4bc6-b7dc-1e5cf2aa874f@t35g2000yqj.googlegroups.com> References: <8aa7d0e9-4263-4083-b1a9-2013a83a0f81@z20g2000pra.googlegroups.com> <9431e600-5930-4964-908e-2ed5a3f2f2db@o23g2000prh.googlegroups.com> <84f8e44e-af70-430b-b498-e1482aa7d0fc@t8g2000prh.googlegroups.com> <4ecd60b8-7366-4bc6-b7dc-1e5cf2aa874f@t35g2000yqj.googlegroups.com> Message-ID: <4D01E97D.5040009@holdenweb.com> On 12/10/2010 4:52 AM, small Pox wrote: [... irrelevant stuff...] > I advocate neither anti semitism nor pro semitism. just the rule of > law that treats people equally and fairly and where money does not > count. this cannot be achieved without demolishing fractional reserve > lending, and not without making the courts free and preventing > knowledge monopolies. If a certain group is going up > disproportionately, then there is something to look at. I see everyone > work as hard as anyone else. This is completely off-topic for c.l.py. Kindly bugger off. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From markjason72 at gmail.com Fri Dec 10 04:12:51 2010 From: markjason72 at gmail.com (mark jason) Date: Fri, 10 Dec 2010 01:12:51 -0800 (PST) Subject: printing error message from an Exception References: <2c9af3ec-294c-4cd4-aca3-cbc62dba09b6@u9g2000pra.googlegroups.com> <4d01cede$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <47a48cbd-146b-4cf5-a7bb-546572c4ef0e@k14g2000pre.googlegroups.com> On Dec 10, 11:55?am, Steven D'Aprano wrote: > ? ? # By the way, IOError is not the only exception you could see. thanks for the help Steven. Is it OK to catch Exception instead of IOError ? In some operation which can cause many errors ,can I use the following? try: do_something() except Exception,e: display_message(e.args) handle_exception(e) thanks, mark From __peter__ at web.de Fri Dec 10 04:15:05 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 10 Dec 2010 10:15:05 +0100 Subject: printing error message from an Exception References: <2c9af3ec-294c-4cd4-aca3-cbc62dba09b6@u9g2000pra.googlegroups.com> Message-ID: mark jason wrote: > hi > I was trying out some file operations and was trying to open a non > existing file as below > > def do_work(filename): > try: > f = open(filename,"r"); > print 'opened' > except IOError, e: > print 'failed',e.message > finally: > f.close() > print 'closed' > > if __name__=='__main__': > do_work("C:\code\misc.txt") # there is no such file > > I am getting an error and a warning > > DeprecationWarning: BaseException.message has been deprecated as of > Python 2.6 > print 'failed',e.message > > UnboundLocalError: local variable 'f' referenced before assignment > > Is there a way to overcome the DeprecationWarning? I wanted to print > the error message from the IOError.How do I do this? > Also ,what should I do about the UnboundLocalError? You are mixing two things here: (1) print an error message when the file cannot be opened (2) ensure that the file will always be closed If you attack both aspects separately they become simpler: # 1 try: f = open(...) except IOError as e: print "Failed", e # 2a f = open(...) try: print "opened" finally: f.close() which can be simplified to # 2b with open(...) as f: print "opened" Putting 1 and 2b together: try: with open(...) as f: print "opened" except IOError as e: print "Failed", e There is a disadvantage though: an IOError that is raised in the with-suite will also be caught. If you're concerned about that you can use: try: f = open(...) except IOError as e: print "Failed", e else: with contextlib.closing(f): print "opened" From jeanmichel at sequans.com Fri Dec 10 05:17:33 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 10 Dec 2010 11:17:33 +0100 Subject: Proposed changes to logging defaults In-Reply-To: <3763d355-9074-485c-a694-031d600d5b84@m11g2000vbs.googlegroups.com> References: <3763d355-9074-485c-a694-031d600d5b84@m11g2000vbs.googlegroups.com> Message-ID: <4D01FE3D.2020103@sequans.com> Vinay Sajip wrote: > Some changes are being proposed to how logging works in default > configurations. > > Briefly - when a logging event occurs which needs to be output to some > log, the behaviour of the logging package when no explicit logging > configuration is provided will change, most likely to log those events > to sys.stderr with a default format. > > Since this proposed change to behaviour is backwards-incompatible (and > scheduled to come in to Python 3.2 - earlier Pythons, including 2.X, > are unaffected), you may be interested in seeing if the changes affect > you. More details are available here: > > http://plumberjack.blogspot.com/2010/12/proposed-changes-to-logging-defaults.html > > Please feel free to add comments to the linked blog post. > > Regards, > > Vinay Sajip > Why would you log informative messages to stderr ? (debug, info, warning) How stderr is a better choice than stdout ? A naive approach would rather send errors to stderr & everything else on stdout (including warnings ?). IMO, the StreamHandler(sys.stderr) level should be set to logging.ERROR by default. Because nobody can answer the question 'is a warning an error', endless debate, there's a risk to log warnings to stderr. I also think that if someone did'nt care about configuring the logging machine for 3rd party libraries, this guy just don't care about those library warnings. Last question, if no handler is found, why not simply drop the log event, doing nothing ? It sounds pretty reasonable and less intrusive. JM From frankcui24 at gmail.com Fri Dec 10 05:20:53 2010 From: frankcui24 at gmail.com (frank cui) Date: Fri, 10 Dec 2010 18:20:53 +0800 Subject: instance has no __call__ method Message-ID: Hi all, I'm a novice learner of python and get caught in the following trouble and hope experienced users can help me solve it:) Code: ----------------------------------------------------------------------- $ cat Muffle_ZeroDivision.py #!/usr/bin/env python class MuffledCalculator: muffled = False def clac(self,expr): try: return eval(expr) except: if self.muffled: print 'Division by zero is illegal' else: raise -------------------------------------------------------------------------- $ python Python 2.7 (r27:82500, Sep 16 2010, 18:03:06) [GCC 4.5.1 20100907 (Red Hat 4.5.1-3)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import Muffle_ZeroDivision >>> calc = Muffle_ZeroDivision.MuffledCalculator() >>> calc = ('10/2') >>> calc = Muffle_ZeroDivision.MuffledCalculator() >>> calc('10/2') Traceback (most recent call last): File "", line 1, in AttributeError: MuffledCalculator instance has no __call__ method ---------------------------------------------------------------------------- There is an AttributeError that this instance doesn't have the __call__ method, so how to add this kind of method to my instance? Thanks a lot in advance. Regards Frank.Cui -------------- next part -------------- An HTML attachment was scrubbed... URL: From kala32kolo at gmail.com Fri Dec 10 05:31:13 2010 From: kala32kolo at gmail.com (kolo 32) Date: Fri, 10 Dec 2010 02:31:13 -0800 (PST) Subject: Python critique Message-ID: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> Hi, all, Python critique from strchr.com: http://www.strchr.com/python_critique From jeanmichel at sequans.com Fri Dec 10 05:33:13 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 10 Dec 2010 11:33:13 +0100 Subject: printing error message from an Exception In-Reply-To: <47a48cbd-146b-4cf5-a7bb-546572c4ef0e@k14g2000pre.googlegroups.com> References: <2c9af3ec-294c-4cd4-aca3-cbc62dba09b6@u9g2000pra.googlegroups.com> <4d01cede$0$30002$c3e8da3$5496439d@news.astraweb.com> <47a48cbd-146b-4cf5-a7bb-546572c4ef0e@k14g2000pre.googlegroups.com> Message-ID: <4D0201E9.8090305@sequans.com> mark jason wrote: > On Dec 10, 11:55 am, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: > >> # By the way, IOError is not the only exception you could see. >> > > > thanks for the help Steven. Is it OK to catch Exception instead of > IOError ? > In some operation which can cause many errors ,can I use the > following? > > try: > do_something() > except Exception,e: > display_message(e.args) > handle_exception(e) > > > thanks, > mark > You shouldn't. If you want to handle an exception, you need to know about it. What if your handle_exception meets some exception it does not know how to handle ? People are sometimes using bare try except clause to say 'look ! my function never crash !'. True but it usually has an unpredictable behavior upon exception being raised, and that is much worse that a clean uncought exception. What you can do : try: do_something() except IOError: # handler IOerror except KeyboardInterrupt: print 'stopping...' sys.exit(0) except NotImplementedError: # handler missing implementation Everything else should be kept uncought. JM From davea at ieee.org Fri Dec 10 06:28:39 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 10 Dec 2010 06:28:39 -0500 Subject: instance has no __call__ method In-Reply-To: References: Message-ID: <4D020EE7.9010508@ieee.org> On 01/-10/-28163 02:59 PM, frank cui wrote: > Hi all, > > I'm a novice learner of python and get caught in the following trouble and > hope experienced users can help me solve it:) > > Code: > ----------------------------------------------------------------------- > $ cat Muffle_ZeroDivision.py > #!/usr/bin/env python > > class MuffledCalculator: > muffled = False > def clac(self,expr): > try: > return eval(expr) > except: > if self.muffled: > print 'Division by zero is illegal' > else: > raise > -------------------------------------------------------------------------- > > $ python > Python 2.7 (r27:82500, Sep 16 2010, 18:03:06) > [GCC 4.5.1 20100907 (Red Hat 4.5.1-3)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import Muffle_ZeroDivision >>>> calc = Muffle_ZeroDivision.MuffledCalculator() >>>> calc = ('10/2') >>>> calc = Muffle_ZeroDivision.MuffledCalculator() >>>> calc('10/2') > Traceback (most recent call last): > File "", line 1, in > AttributeError: MuffledCalculator instance has no __call__ method > > ---------------------------------------------------------------------------- > > There is an AttributeError that this instance doesn't have the __call__ > method, so how to add this kind of method to my instance? > Your problem is that you defined a clac() method, but never call it. So instead of calc('10/2') you need calc.clac("10/2") I'm not sure why you have such a confusing name, however. DaveA From solipsis at pitrou.net Fri Dec 10 06:57:02 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Fri, 10 Dec 2010 12:57:02 +0100 Subject: Proposed changes to logging defaults References: <3763d355-9074-485c-a694-031d600d5b84@m11g2000vbs.googlegroups.com> <4D01FE3D.2020103@sequans.com> Message-ID: <20101210125702.18262cd5@pitrou.net> On Fri, 10 Dec 2010 11:17:33 +0100 Jean-Michel Pichavant wrote: > Why would you log informative messages to stderr ? (debug, info, warning) > How stderr is a better choice than stdout ? By construction really. stderr is initially for errors, but it is generally used for "out of band" messages such as warnings and various optional information. stdout is used to output whatever data the user asked for (which generally isn't errors and warnings). If you redirect said data to a file, you don't want out of band information to end up mingled with it. Regards Antoine. From astan.chee at gmail.com Fri Dec 10 07:02:24 2010 From: astan.chee at gmail.com (Astan Chee) Date: Fri, 10 Dec 2010 23:02:24 +1100 Subject: run a function in another processor in python In-Reply-To: References: <4D00B416.5090509@sequans.com> Message-ID: Thanks for that. I'll try and see if it makes any difference but I'm using python 2.6 not 3 Are the multiprocessing modules different? That code (or whatever is using the multiprocessing module) seems to cause infinite python processes on my machine and eventually kills it. I'm running python 2.6 on windows 7 x64 ....is it the ammount of memory/cpu speed/number of cpu that is the issue? Thanks for any clarification On Fri, Dec 10, 2010 at 4:16 AM, geremy condra wrote: > On Thu, Dec 9, 2010 at 5:03 AM, Astan Chee wrote: > > Thanks but I'm having trouble with that module too. Currently what I > > have is something like this: > > > > import sys > > import os > > import multiprocessing > > > > import time > > > > def functionTester(num): > > return ((num+2)/(num-2))**2 > > > > num_args = [61,62,33,7,12,16,19,35,36,37,38,55,56,57,63] > > > > max_result = 0 > > > > start = time.time() > > > > num_processes = multiprocessing.cpu_count() > > > > threads = [] > > len_stas = len(num_args) > > > > for list_item in num_args: > > if len(threads) < num_processes: > > p = > multiprocessing.Process(target=functionTester,args=[list_item]) > > p.start() > > print p, p.is_alive() > > threads.append(p) > > else: > > for thread in threads: > > if not thread.is_alive(): > > threads.remove(thread) > > > > print "Result " + str(max_result) > > end = time.time() > > elapsed= end - start > > print "Took", elapsed, "seconds to execute" > > > > But it doesn't give me any return data. It also spawns an infinite > > number of (sub)processes that crashes my machine. What am I doing > > wrong here? > > > > On 12/9/10, Jean-Michel Pichavant wrote: > >> Astan Chee wrote: > >>> Hi, > >>> I've got a python script that calls a function many times with various > >>> arguments and returns a result. What I'm trying to do is run this > >>> function each on different processors and compile the result at the > >>> end based on the function result. The script looks something like > >>> this: > >>> > >>> > >>> import time > >>> > >>> def functionTester(num): > >>> return ((num+2)/(num-2))**2 > >>> > >>> num_args = [1,2,3,7,12,16,19,35,36,37,38,55,56,57,63,44,71,81,91] > >>> > >>> max_result = 0 > >>> > >>> start = time.time() > >>> > >>> for n in num_args: > >>> result = functionTester(n) > >>> if result > max_result: > >>> max_result = result > >>> > >>> print "Result " + str(max_result) > >>> end = time.time() > >>> elapsed= end - start > >>> print "Took", elapsed, "seconds to execute" > >>> > >>> > >>> What I'm trying to do is run each function on a processor and when its > >>> done, move on to the next function-argument specifically on windows 7 > >>> x64 using python 2.6. How do I do this? > >>> Thanks for any help > >>> > >> If I'm not wrong, CPU management is handled by your system, meaning > >> there's no way to 'force' anything to run on a specific CPU. However, > >> you may try to execute your fonction in a subprocess, so that the system > >> will use different CPUs (hopefully). You then just need to limit the > >> number of subprocess alive at the same time. > >> > >> Have a look here > >> http://docs.python.org/library/multiprocessing.html > >> > >> JM > >> > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > Here's a way of doing what I think you mean to do. I assume that > max_result should be the maximum value returned by a run of > functionTester. > > Also, just a note, usually function names like this are spelled > function_tester rather than functionTester in python. > > If you need to de-python3ify it just change the line at the top and > cast your nums to floats, otherwise you'll get integer division (which > I again assume you don't want). > > #! /usr/bin/env python3 > > import time > import multiprocessing > > > def functionTester(num): > return ((num+2)/(num-2))**2 > > num_args = [61,62,33,7,12,16,19,35,36,37,38,55,56,57,63] > > num_processes = multiprocessing.cpu_count() > pool = multiprocessing.Pool(num_processes) > > start = time.time() > results = pool.map(functionTester, num_args) > end = time.time() > > # is this what you meant to do with the results? > max_result = max(results) > print("Result " + str(max_result)) > > elapsed = end - start > print("Took", elapsed, "seconds to execute") > > Geremy Condra > -------------- next part -------------- An HTML attachment was scrubbed... URL: From astan.chee at gmail.com Fri Dec 10 07:08:06 2010 From: astan.chee at gmail.com (Astan Chee) Date: Fri, 10 Dec 2010 23:08:06 +1100 Subject: run a function in another processor in python In-Reply-To: References: <4D00B416.5090509@sequans.com> Message-ID: I just saw this: http://bugs.python.org/issue8094 which seem to be similar to what I'm having. Does anyone know if there is a fix for it? Thanks again On Fri, Dec 10, 2010 at 11:02 PM, Astan Chee wrote: > Thanks for that. I'll try and see if it makes any difference but I'm using > python 2.6 not 3 > Are the multiprocessing modules different? That code (or whatever is using > the multiprocessing module) seems to cause infinite python processes on my > machine and eventually kills it. > I'm running python 2.6 on windows 7 x64 ....is it the ammount of memory/cpu > speed/number of cpu that is the issue? > Thanks for any clarification > > > > On Fri, Dec 10, 2010 at 4:16 AM, geremy condra wrote: > >> On Thu, Dec 9, 2010 at 5:03 AM, Astan Chee wrote: >> > Thanks but I'm having trouble with that module too. Currently what I >> > have is something like this: >> > >> > import sys >> > import os >> > import multiprocessing >> > >> > import time >> > >> > def functionTester(num): >> > return ((num+2)/(num-2))**2 >> > >> > num_args = [61,62,33,7,12,16,19,35,36,37,38,55,56,57,63] >> > >> > max_result = 0 >> > >> > start = time.time() >> > >> > num_processes = multiprocessing.cpu_count() >> > >> > threads = [] >> > len_stas = len(num_args) >> > >> > for list_item in num_args: >> > if len(threads) < num_processes: >> > p = >> multiprocessing.Process(target=functionTester,args=[list_item]) >> > p.start() >> > print p, p.is_alive() >> > threads.append(p) >> > else: >> > for thread in threads: >> > if not thread.is_alive(): >> > threads.remove(thread) >> > >> > print "Result " + str(max_result) >> > end = time.time() >> > elapsed= end - start >> > print "Took", elapsed, "seconds to execute" >> > >> > But it doesn't give me any return data. It also spawns an infinite >> > number of (sub)processes that crashes my machine. What am I doing >> > wrong here? >> > >> > On 12/9/10, Jean-Michel Pichavant wrote: >> >> Astan Chee wrote: >> >>> Hi, >> >>> I've got a python script that calls a function many times with various >> >>> arguments and returns a result. What I'm trying to do is run this >> >>> function each on different processors and compile the result at the >> >>> end based on the function result. The script looks something like >> >>> this: >> >>> >> >>> >> >>> import time >> >>> >> >>> def functionTester(num): >> >>> return ((num+2)/(num-2))**2 >> >>> >> >>> num_args = [1,2,3,7,12,16,19,35,36,37,38,55,56,57,63,44,71,81,91] >> >>> >> >>> max_result = 0 >> >>> >> >>> start = time.time() >> >>> >> >>> for n in num_args: >> >>> result = functionTester(n) >> >>> if result > max_result: >> >>> max_result = result >> >>> >> >>> print "Result " + str(max_result) >> >>> end = time.time() >> >>> elapsed= end - start >> >>> print "Took", elapsed, "seconds to execute" >> >>> >> >>> >> >>> What I'm trying to do is run each function on a processor and when its >> >>> done, move on to the next function-argument specifically on windows 7 >> >>> x64 using python 2.6. How do I do this? >> >>> Thanks for any help >> >>> >> >> If I'm not wrong, CPU management is handled by your system, meaning >> >> there's no way to 'force' anything to run on a specific CPU. However, >> >> you may try to execute your fonction in a subprocess, so that the >> system >> >> will use different CPUs (hopefully). You then just need to limit the >> >> number of subprocess alive at the same time. >> >> >> >> Have a look here >> >> http://docs.python.org/library/multiprocessing.html >> >> >> >> JM >> >> >> > -- >> > http://mail.python.org/mailman/listinfo/python-list >> > >> >> Here's a way of doing what I think you mean to do. I assume that >> max_result should be the maximum value returned by a run of >> functionTester. >> >> Also, just a note, usually function names like this are spelled >> function_tester rather than functionTester in python. >> >> If you need to de-python3ify it just change the line at the top and >> cast your nums to floats, otherwise you'll get integer division (which >> I again assume you don't want). >> >> #! /usr/bin/env python3 >> >> import time >> import multiprocessing >> >> >> def functionTester(num): >> return ((num+2)/(num-2))**2 >> >> num_args = [61,62,33,7,12,16,19,35,36,37,38,55,56,57,63] >> >> num_processes = multiprocessing.cpu_count() >> pool = multiprocessing.Pool(num_processes) >> >> start = time.time() >> results = pool.map(functionTester, num_args) >> end = time.time() >> >> # is this what you meant to do with the results? >> max_result = max(results) >> print("Result " + str(max_result)) >> >> elapsed = end - start >> print("Took", elapsed, "seconds to execute") >> >> Geremy Condra >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From astan.chee at gmail.com Fri Dec 10 07:42:04 2010 From: astan.chee at gmail.com (Astan Chee) Date: Fri, 10 Dec 2010 23:42:04 +1100 Subject: run a function in another processor in python In-Reply-To: References: <4D00B416.5090509@sequans.com> Message-ID: On Fri, Dec 10, 2010 at 1:37 AM, Peter Otten <__peter__ at web.de> wrote: > I can't replicate the crash. However, your problem looks like there is a > ready-to-use solution: > > http://docs.python.org/library/multiprocessing.html#using-a-pool-of-workers > > -- > http://mail.python.org/mailman/listinfo/python-list > Pool.map doesn't seem to be able to support multiple argument functions which is what I'm trying to do here. Any other suggestions? Thanks again -------------- next part -------------- An HTML attachment was scrubbed... URL: From orasnita at gmail.com Fri Dec 10 08:39:34 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Fri, 10 Dec 2010 15:39:34 +0200 Subject: Python critique References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> Message-ID: It is true that Python doesn't use scope limitations for variables? Octavian ----- Original Message ----- From: "kolo 32" Newsgroups: comp.lang.python To: Sent: Friday, December 10, 2010 12:31 PM Subject: Python critique > Hi, all, > > Python critique from strchr.com: > > http://www.strchr.com/python_critique > -- > http://mail.python.org/mailman/listinfo/python-list From dirknbr at gmail.com Fri Dec 10 08:48:32 2010 From: dirknbr at gmail.com (Dirk Nachbar) Date: Fri, 10 Dec 2010 05:48:32 -0800 (PST) Subject: decouple copy of a list Message-ID: <9a8681fb-0c8b-42ae-aa2b-9200ca92bd2b@k11g2000vbf.googlegroups.com> I want to take a copy of a list a b=a and then do things with b which don't affect a. How can I do this? Dirk From rob.randall2 at gmail.com Fri Dec 10 08:54:42 2010 From: rob.randall2 at gmail.com (Rob Randall) Date: Fri, 10 Dec 2010 13:54:42 +0000 Subject: 64 bit memory usage In-Reply-To: <4d015be7$0$1670$742ec2ed@news.sonic.net> References: <4d015be7$0$1670$742ec2ed@news.sonic.net> Message-ID: You guys are right. If I disable the gc it will use all the virtual RAM in my test. The application I have been running these tests for is a port of a program written in a LISP-based tool running on Unix. It does a mass of stress calculations. The port has been written using a python-based toolkit I am responsible for. This toolkit offers much of the same functionlity as the LISP tool. It is based around the use of demand-driven/declarative programming. When the porting project started no one realised just how much memory the heaviest of the test cases used. It uses 40+ GB on an HP Unix machine. It is easy to see now that the port should have been written differently, but it is essentially complete now. This has lead me to see if a hardware solution can be found using 64 bit windows machnes. I will try running one the tests next to see what impact disabling the gc will have. Thanks, Rob. On 9 December 2010 22:44, John Nagle wrote: > On 12/8/2010 10:42 PM, Dennis Lee Bieber wrote: > >> On Wed, 8 Dec 2010 14:44:30 +0000, Rob Randall >> declaimed the following in gmane.comp.python.general: >> >> I am trying to understand how much memory is available to a 64 bit python >>> process running under Windows XP 64 bit. >>> >>> When I run tests just creating a series of large dictionaries containing >>> string keys and float values I do not seem to be able to grow the process >>> beyond the amount of RAM present. >>> >> > If you get to the point where you need multi-gigabyte Python > dictionaries, you may be using the wrong tool for the job. > If it's simply that you need to manage a large amount of data, > that's what databases are for. > > If this is some super high performance application that needs to keep a > big database in memory for performance reasons, CPython > is probably too slow. For that, something like Google's BigTable > may be more appropriate, and will scale to terabytes if necessary. > > John Nagle > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kushal.kumaran+python at gmail.com Fri Dec 10 08:54:51 2010 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Fri, 10 Dec 2010 19:24:51 +0530 Subject: decouple copy of a list In-Reply-To: <9a8681fb-0c8b-42ae-aa2b-9200ca92bd2b@k11g2000vbf.googlegroups.com> References: <9a8681fb-0c8b-42ae-aa2b-9200ca92bd2b@k11g2000vbf.googlegroups.com> Message-ID: On Fri, Dec 10, 2010 at 7:18 PM, Dirk Nachbar wrote: > I want to take a copy of a list a > > b=a > > and then do things with b which don't affect a. > > How can I do this? > b = a[:] will create a copy of the list. If the elements of the list are references to mutable objects (objects of your own classes, for example), you might take a look at copy.deepcopy. -- regards, kushal From urban.dani at gmail.com Fri Dec 10 08:55:25 2010 From: urban.dani at gmail.com (Daniel Urban) Date: Fri, 10 Dec 2010 14:55:25 +0100 Subject: decouple copy of a list In-Reply-To: <9a8681fb-0c8b-42ae-aa2b-9200ca92bd2b@k11g2000vbf.googlegroups.com> References: <9a8681fb-0c8b-42ae-aa2b-9200ca92bd2b@k11g2000vbf.googlegroups.com> Message-ID: b = list(a) or b = a[:] From mdw at distorted.org.uk Fri Dec 10 08:55:57 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 10 Dec 2010 13:55:57 +0000 Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <4cfebe65$0$1590$742ec2ed@news.sonic.net> <87ipz5jfr9.fsf.mdw@metalzone.distorted.org.uk> <4cfff225$0$1650$742ec2ed@news.sonic.net> <4d005835$0$1597$742ec2ed@news.sonic.net> <87vd33i1ba.fsf.mdw@metalzone.distorted.org.uk> <4d016220$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <871v5pivf6.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > On Thu, 09 Dec 2010 12:21:45 +0000, Mark Wooding wrote: > > > John Nagle writes: > > >> "sort" has failed because it assumes that a < b and b < c implies a < > >> c. But that's not a valid assumption here. > >> > >> It's not good to break trichotomy. > > > > You're confused. The property > > > > a < b and b < c => a < c > > > > is called `transitivity'. > > Yes, but I believe that John is referring to the trichotomy (like a > dichotomy, Then why did he say `it assumes that a < b and b < c implies a < c'? This assumption is transitivity, not trichotomy. > > 2. Totality: a <= b or b <= a > > > > The above list sorting goes wrong because the `float' ordering isn't > > total. In particular, x > NaN!). > > I believe this is equivalent to trichotomy. No, it isn't. In particular, the definition of totality I gave above allows a <= b and b <= a and a /= b. You gave a perfectly good definition of trichotomy, which I have moved out of its original order: > exactly one of these relations are true: > > a < b > a == b > a > b A total preorder (as defined above) doesn't exhibit this property -- but can be described in terms of a total order (which /does/ exhibit proper trichotomy) applied to a set of equivalence classes. > > So, your last remark is in the right direction (though strict trichotomy > > is unnecessary, as I've mentioned), but apparently only by accident > > since the preceding discussion is completely wrong. > > "Completely" is surely a tad strong -- John might not be using the > exact same terminology as you, but he's clearly talking about the > equivalent concepts. He wants and expects all data types to either > meet a total order, or raise an exception to any of the < > <= and >= > operators. No. He was hopelessly confused, describing the problem in terms of a failure of transitivity (which doesn't, in fact, fail), but using the word `trichotomy', apparently more by luck than judgement. I don't want to insist on a total order. Efficient sorting requires a total preorder, and that's all I want. -- [mdw] From wolfgang at rohdewald.de Fri Dec 10 08:56:47 2010 From: wolfgang at rohdewald.de (Wolfgang Rohdewald) Date: Fri, 10 Dec 2010 14:56:47 +0100 Subject: decouple copy of a list In-Reply-To: <9a8681fb-0c8b-42ae-aa2b-9200ca92bd2b@k11g2000vbf.googlegroups.com> References: <9a8681fb-0c8b-42ae-aa2b-9200ca92bd2b@k11g2000vbf.googlegroups.com> Message-ID: <201012101456.48062.wolfgang@rohdewald.de> On Freitag 10 Dezember 2010, Dirk Nachbar wrote: > I want to take a copy of a list a > > b=a > > and then do things with b which don't affect a. > > How can I do this? > > Dirk b=a[:] -- Wolfgang From jeanmichel at sequans.com Fri Dec 10 09:02:50 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 10 Dec 2010 15:02:50 +0100 Subject: Python critique In-Reply-To: References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> Message-ID: <4D02330A.5000305@sequans.com> Octavian Rasnita wrote: > It is true that Python doesn't use scope limitations for variables? > > Octavian > Python does have scope. The problem is not the lack of scope, to problem is the shadow declaration of some python construct in the current scope. print x # raise NameError [x for x in range(10)] # shadow declaration of x print x # will print 9 it can become a problem if you write such code: index = 1 myNewList = [index*2 for index in [1,2,3,4,5]] print myNewList(index) # here most new commer would want to use index=1. To compare to some C construct, python declares the variable in the current scope while the C construct will create a new scope for the following block. IMO, i don't see this one as an issue, because even when coding in C, you do NOT use the same name for 2 different things. Python shadow declarations would be a problem for someone used to take "advantage" of the C construct. The author states that this is bug prone, I did write a lot of python lines, never happened to me. JM PS : pylint reports such shadow declaration, W0631: 4: Using possibly undefined loop variable 'x' From jeanmichel at sequans.com Fri Dec 10 09:06:18 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 10 Dec 2010 15:06:18 +0100 Subject: decouple copy of a list In-Reply-To: <9a8681fb-0c8b-42ae-aa2b-9200ca92bd2b@k11g2000vbf.googlegroups.com> References: <9a8681fb-0c8b-42ae-aa2b-9200ca92bd2b@k11g2000vbf.googlegroups.com> Message-ID: <4D0233DA.2060809@sequans.com> Dirk Nachbar wrote: > I want to take a copy of a list a > > b=a > > and then do things with b which don't affect a. > > How can I do this? > > Dirk > In [1]: a = [1,2,3] In [2]: b = a[:] In [3]: b[0] = 5 In [4]: a Out[4]: [1, 2, 3] In [5]: b Out[5]: [5, 2, 3] Alternatively, you can write import copy a = [1,2,3] b = a.copy() if the list a contains mutable objects, use copy.deepcopy (http://docs.python.org/library/copy.html) JM From dirknbr at gmail.com Fri Dec 10 09:06:42 2010 From: dirknbr at gmail.com (Dirk Nachbar) Date: Fri, 10 Dec 2010 06:06:42 -0800 (PST) Subject: decouple copy of a list References: <9a8681fb-0c8b-42ae-aa2b-9200ca92bd2b@k11g2000vbf.googlegroups.com> Message-ID: On Dec 10, 1:56?pm, Wolfgang Rohdewald wrote: > On Freitag 10 Dezember 2010, Dirk Nachbar wrote: > > > I want to take a copy of a list a > > > b=a > > > and then do things with b which don't affect a. > > > How can I do this? > > > Dirk > > b=a[:] > > -- > Wolfgang I did that but then some things I do with b happen to a as well. From stefan_ml at behnel.de Fri Dec 10 09:30:56 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 10 Dec 2010 15:30:56 +0100 Subject: Python critique In-Reply-To: <4D02330A.5000305@sequans.com> References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> <4D02330A.5000305@sequans.com> Message-ID: Jean-Michel Pichavant, 10.12.2010 15:02: > the shadow declaration of some python construct in the current scope. > > print x # raise NameError > [x for x in range(10)] # shadow declaration of x > print x # will print 9 Note that this is rarely a problem in practice, and that this has been fixed in Python 3. Stefan From wolfgang at rohdewald.de Fri Dec 10 09:36:01 2010 From: wolfgang at rohdewald.de (Wolfgang Rohdewald) Date: Fri, 10 Dec 2010 15:36:01 +0100 Subject: decouple copy of a list In-Reply-To: References: <9a8681fb-0c8b-42ae-aa2b-9200ca92bd2b@k11g2000vbf.googlegroups.com> Message-ID: <201012101536.01207.wolfgang@rohdewald.de> On Freitag 10 Dezember 2010, Dirk Nachbar wrote: > > b=a[:] > > > > -- > > Wolfgang > > I did that but then some things I do with b happen to a as > well. as others said, this is no deep copy. So if you do something to an element in b, and if the same element is in a, both are changed as they are still the same objects: >>> x,y=5,6 >>> a=[x,y] >>> b=a[:] >>> id(a),id(b) (140695481867368, 140695481867512) >>> id(a[0]),id(b[0]) (33530584, 33530584) >>> a=b >>> id(a),id(b) (140695481867512, 140695481867512) -- Wolfgang From raespi at uci.cu Fri Dec 10 09:38:28 2010 From: raespi at uci.cu (Teratux) Date: Fri, 10 Dec 2010 09:38:28 -0500 Subject: about module import .. Message-ID: <4D023B64.5010103@uci.cu> Hello ... I'm using buildbot to build some of my projects. I'm having problems when I configure it and I think it might be with the python configuration on my pc: I'm getting this error: Traceback (most recent call last): File "/usr/bin/buildbot", line 3, in from buildbot.scripts import runner File "/usr/lib/python2.5/site-packages/buildbot/scripts/runner.py", line 7, in from twisted.python import usage, util, runtime ImportError: No module named twisted.python Ok, so I assumed it might be that the python-twisted module wasn't installed. I opened up a python console and wrote: import twisted.python And it doesn't complain. I have the twisted.python module installed on my pc but for some reason buildbot isn't loading it. Is there some way to know if there's a misconfiguration in my computer? I'm using Debian Lenny 5.0 and python 2.5.2. Thanks ... -------------- next part -------------- An HTML attachment was scrubbed... URL: From orasnita at gmail.com Fri Dec 10 10:27:25 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Fri, 10 Dec 2010 17:27:25 +0200 Subject: Python critique References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> <4D02330A.5000305@sequans.com> Message-ID: <1FDA7F3970EA4D79B4BD52BA8EBC28D2@teddy> From: "Jean-Michel Pichavant" > > Octavian Rasnita wrote: >> It is true that Python doesn't use scope limitations for variables? >> >> Octavian >> > Python does have scope. The problem is not the lack of scope, to > problem is the shadow declaration of some python construct in the > current scope. It's OK then. > print x # raise NameError > [x for x in range(10)] # shadow declaration of x > print x # will print 9 > > it can become a problem if you write such code: > > index = 1 > myNewList = [index*2 for index in [1,2,3,4,5]] > print myNewList(index) # here most new commer would want to use index=1. Yes, it is not such a big deal. Octavian From pruebauno at latinmail.com Fri Dec 10 11:17:19 2010 From: pruebauno at latinmail.com (nn) Date: Fri, 10 Dec 2010 08:17:19 -0800 (PST) Subject: Deprecation warnings (2.7 -> 3 ) References: <44caabf0-7f83-42b8-abf9-eb40ea6b63a8@i32g2000pri.googlegroups.com> Message-ID: On Dec 9, 10:15?pm, rusi wrote: > In trying to get from 2.x to 3 Terry suggested I use 2.7 with > deprecation warnings > > Heres the (first) set > > DeprecationWarning: Overriding __eq__ blocks inheritance of __hash__ > in 3.x > DeprecationWarning: callable() not supported in 3.x; use isinstance(x, > collections.Callable) > > Is there one place/site I can go to for understanding all these and > trying to clear them? I don't know any place that explains those. But the second is a pretty straightforward: replace "callable(x)" by "isinstance(x, collections.Callable)" The first one is more tricky. You have to find the class with a __eq__ method in it and copy and paste the __hash__ method from its superclass into itself. From fpm at u.washington.edu Fri Dec 10 11:18:36 2010 From: fpm at u.washington.edu (cassiope) Date: Fri, 10 Dec 2010 08:18:36 -0800 (PST) Subject: decouple copy of a list References: <9a8681fb-0c8b-42ae-aa2b-9200ca92bd2b@k11g2000vbf.googlegroups.com> Message-ID: <1a0f8988-e206-46c4-babb-c02738792740@f21g2000prn.googlegroups.com> On Dec 10, 6:06?am, Jean-Michel Pichavant wrote: > Dirk Nachbar wrote: > > I want to take a copy of a list a > > > b=a > > > and then do things with b which don't affect a. > > > How can I do this? > > > Dirk > > In [1]: a = [1,2,3] > > In [2]: b = a[:] > > In [3]: b[0] = 5 > > In [4]: a > Out[4]: [1, 2, 3] > > In [5]: b > Out[5]: [5, 2, 3] > > Alternatively, you can write > > import copy > a = [1,2,3] > b = a.copy() > > if the list a contains mutable objects, use copy.deepcopy > (http://docs.python.org/library/copy.html) > > JM I'm not a pyguru, but... you didn't use copy quite right. Try instead: b= copy.copy(a) The other issue that the original person has noticed is that a list may include a reference to something. When a list is copied - if the reference is copied (not "deepcopied"], changes to the referred object will be visible in both lists, even if they are different lists. For more information, refer to the docs in the module. HTH... From pruebauno at latinmail.com Fri Dec 10 11:24:08 2010 From: pruebauno at latinmail.com (nn) Date: Fri, 10 Dec 2010 08:24:08 -0800 (PST) Subject: Deprecation warnings (2.7 -> 3 ) References: <44caabf0-7f83-42b8-abf9-eb40ea6b63a8@i32g2000pri.googlegroups.com> Message-ID: On Dec 10, 11:17?am, nn wrote: > On Dec 9, 10:15?pm, rusi wrote: > > > In trying to get from 2.x to 3 Terry suggested I use 2.7 with > > deprecation warnings > > > Heres the (first) set > > > DeprecationWarning: Overriding __eq__ blocks inheritance of __hash__ > > in 3.x > > DeprecationWarning: callable() not supported in 3.x; use isinstance(x, > > collections.Callable) > > > Is there one place/site I can go to for understanding all these and > > trying to clear them? > > I don't know any place that explains those. But the second is a pretty > straightforward: replace "callable(x)" by "isinstance(x, > collections.Callable)" > > The first one is more tricky. You have to find the class with a __eq__ > method in it and copy and paste the __hash__ method from its > superclass into itself. And BTW callable was deprecated in 3.0 and then added back in for 3.2. So if you decide to not support 3.0 and 3.1 you would be fine just leaving it as is. From mail at timgolden.me.uk Fri Dec 10 11:25:37 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 10 Dec 2010 16:25:37 +0000 Subject: Deprecation warnings (2.7 -> 3 ) In-Reply-To: References: <44caabf0-7f83-42b8-abf9-eb40ea6b63a8@i32g2000pri.googlegroups.com> Message-ID: <4D025481.3090808@timgolden.me.uk> On 10/12/2010 16:17, nn wrote: > On Dec 9, 10:15 pm, rusi wrote: >> In trying to get from 2.x to 3 Terry suggested I use 2.7 with >> deprecation warnings >> >> Heres the (first) set >> >> DeprecationWarning: Overriding __eq__ blocks inheritance of __hash__ >> in 3.x >> DeprecationWarning: callable() not supported in 3.x; use isinstance(x, >> collections.Callable) >> >> Is there one place/site I can go to for understanding all these and >> trying to clear them? Not quite an answer, but: http://docs.python.org/dev/py3k/whatsnew/3.0.html TJG From rustompmody at gmail.com Fri Dec 10 11:25:43 2010 From: rustompmody at gmail.com (rusi) Date: Fri, 10 Dec 2010 08:25:43 -0800 (PST) Subject: Deprecation warnings (2.7 -> 3 ) References: <44caabf0-7f83-42b8-abf9-eb40ea6b63a8@i32g2000pri.googlegroups.com> Message-ID: <139e14a8-2ba9-429f-984f-7b7e6c277efb@r16g2000prh.googlegroups.com> On Dec 10, 9:17?pm, nn wrote: > On Dec 9, 10:15?pm, rusi wrote: > > > In trying to get from 2.x to 3 Terry suggested I use 2.7 with > > deprecation warnings > > > Heres the (first) set > > > DeprecationWarning: Overriding __eq__ blocks inheritance of __hash__ > > in 3.x > > DeprecationWarning: callable() not supported in 3.x; use isinstance(x, > > collections.Callable) > > > Is there one place/site I can go to for understanding all these and > > trying to clear them? > > I don't know any place that explains those. But the second is a pretty > straightforward: replace "callable(x)" by "isinstance(x, > collections.Callable)" Of course. I was asking for more generic instructions/suggestions on porting like what you've given below [Say I get 25 more such warnings... And then moving to 3.2 I get errors...] > > The first one is more tricky. You have to find the class with a __eq__ > method in it and copy and paste the __hash__ method from its > superclass into itself. From rustompmody at gmail.com Fri Dec 10 11:28:01 2010 From: rustompmody at gmail.com (rusi) Date: Fri, 10 Dec 2010 08:28:01 -0800 (PST) Subject: trace cmd line args in 2.7 References: Message-ID: <3c56b207-2e65-4505-a337-afe2c4ec8650@m20g2000prc.googlegroups.com> On Dec 10, 10:53?am, rusi wrote: > Ive installed python 2.7 > And trace still ignores my ignore-module etc requests Is this a know bug with the trace module? I find it hard to believe that as traces naturally tend to get huge unless carefully trimmed From pruebauno at latinmail.com Fri Dec 10 11:29:38 2010 From: pruebauno at latinmail.com (nn) Date: Fri, 10 Dec 2010 08:29:38 -0800 (PST) Subject: decouple copy of a list References: <9a8681fb-0c8b-42ae-aa2b-9200ca92bd2b@k11g2000vbf.googlegroups.com> Message-ID: <22718b65-8da7-4076-a8fd-2314d70a0e04@29g2000yqq.googlegroups.com> On Dec 10, 8:48?am, Dirk Nachbar wrote: > I want to take a copy of a list a > > b=a > > and then do things with b which don't affect a. > > How can I do this? > > Dirk Not knowing the particulars, you may have to use: import copy b=copy.deepcopy(a) From samwyse at gmail.com Fri Dec 10 11:36:13 2010 From: samwyse at gmail.com (samwyse) Date: Fri, 10 Dec 2010 08:36:13 -0800 (PST) Subject: optparse/argparse for cgi/wsgi? Message-ID: Has anyone ever built some sort of optparse/argparse module for cgi/ wsgi programs? I can see why a straight port wouldn't work, but a module that can organize parameter handling for web pages seems like a good idea, especially if it provided a standard collection of both client- and server-side validation processes, easy internationalization, and a way to create customizable help pages. From hoesley at gmail.com Fri Dec 10 11:57:49 2010 From: hoesley at gmail.com (hoesley) Date: Fri, 10 Dec 2010 08:57:49 -0800 (PST) Subject: continuing development on modules after they're installed Message-ID: <2a700607-78ee-4186-bf80-da02920daceb@m7g2000vbn.googlegroups.com> I just started using distutils to install the modules I'm working on to site-packages. Now, however, if I make changes in my development directory, then import the modules into python, it always loads up the installed version. Thus, I can't continue development without first uninstalling the modules I'm working on, so that the interpreter finds them in the local directory instead of site-packages. Is there any simple way around this? I figure this must be a very common thing to encounter. Thanks! From sohel807 at gmail.com Fri Dec 10 12:11:55 2010 From: sohel807 at gmail.com (Akand Islam) Date: Fri, 10 Dec 2010 09:11:55 -0800 (PST) Subject: Sage's Python Message-ID: In my system (Ubuntu 10.04) there are sage-4.6, python 2.6.5, tk8.5- dev installed. When I give command from terminal "sage -f python-2.6.5.p8" to get sage's python it shows following message: No command 'sage' found, did you mean: Command 'save' from package 'atfs' (universe) Command 'page' from package 'tcllib' (universe) sage: command not found How can I get Sage's python to be worked so that I can import sage.all in python shell? Thanks in advance. --Akand From ian.g.kelly at gmail.com Fri Dec 10 12:32:05 2010 From: ian.g.kelly at gmail.com (Ian) Date: Fri, 10 Dec 2010 09:32:05 -0800 (PST) Subject: continuing development on modules after they're installed References: <2a700607-78ee-4186-bf80-da02920daceb@m7g2000vbn.googlegroups.com> Message-ID: On Dec 10, 9:57?am, hoesley wrote: > I just started using distutils to install the modules I'm working on > to site-packages. Now, however, if I make changes in my development > directory, then import the modules into python, it always loads up the > installed version. Thus, I can't continue development without first > uninstalling the modules I'm working on, so that the interpreter finds > them in the local directory instead of site-packages. Is there any > simple way around this? I figure this must be a very common thing to > encounter. Thanks! Do you need the installed version to be distinct from the development version? If not, you can "install" the module using a simple soft link (on Unix) or a .pth file (on Windows) that points to your development directory. If you do need them to be distinct, a simple way to preferentially get the development version is to add it to the *beginning* of sys.path: sys.path.insert(0, '/path/to/development/directory/') This process can be simplified further by putting it in a PYTHONSTARTUP script. HTH, Ian From jeanmichel at sequans.com Fri Dec 10 13:23:15 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 10 Dec 2010 19:23:15 +0100 Subject: decouple copy of a list In-Reply-To: <1a0f8988-e206-46c4-babb-c02738792740@f21g2000prn.googlegroups.com> References: <9a8681fb-0c8b-42ae-aa2b-9200ca92bd2b@k11g2000vbf.googlegroups.com> <1a0f8988-e206-46c4-babb-c02738792740@f21g2000prn.googlegroups.com> Message-ID: <4D027013.9070405@sequans.com> cassiope wrote: >> Alternatively, you can write >> >> import copy >> a = [1,2,3] >> b = a.copy() >> >> >> JM >> > > I'm not a pyguru, but... you didn't use copy quite right. > Try instead: b= copy.copy(a) > > You're right, you're not a python guru so don't even try to contradict me ever again. ... :D of course I did it completly wrong. I don't know what happened in my brain at that time, maybe nothing and that's the point. JM From vinay_sajip at yahoo.co.uk Fri Dec 10 13:44:33 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Fri, 10 Dec 2010 10:44:33 -0800 (PST) Subject: Proposed changes to logging defaults References: <3763d355-9074-485c-a694-031d600d5b84@m11g2000vbs.googlegroups.com> Message-ID: <9a8c49a6-d24f-4e27-b2e7-2ba654f8236a@t8g2000prh.googlegroups.com> On Dec 10, 10:17?am, Jean-Michel Pichavant wrote: Hi Jean-Michel, I think Antoine answered your other points, so I'll address the last one: > Last question, if no handler is found, why not simply drop the log > event, doing nothing ? It sounds pretty reasonable and less intrusive. That is what happens at the moment if configured for production (logging.raiseExceptions is False) - nothing happens, and the event is discarded. For development (logging.raiseExceptions is True), the "No handlers were found for logger XXX" is printed once, to assist developers to detect misconfiguration. However, the original logged event is still discarded. The original philosophy (when logging was added to Python) was that logging is an adjunct to the operation of the program using it - the program should work the same way whether or not logging is configured. However, the consensus on Python-dev is that the logging package should do useful work, and not just act as an adjunct, i.e. notify the user on warning and error conditions by default if no logging configuration is set up. A program will now work differently depending on whether logging is configured, but if it is not configured, the default should be to display warnings and errors, unless explicitly silenced (as per the Zen of Python). These two approaches (original vs. proposed) are of course quite different, and there's no way of satisfying both proponents of both approaches, nor any easy way of measuring how many of each there are. The proposed change moves logging closer to the current Python-dev consensus, and means that messages currently written to sys.stderr by stdlib modules could be logged instead, with the stdlib maintainers writing those messages knowing that unless explicitly silenced, those messages will appear to the user as they would via a sys.stderr.write(). It will be good if this happens, so that application writers will have better control over what messages are displayed (when they need it), by configuring logging. Remember - no changes to behaviour will occur if this change is implemented and an application configures logging. It's only the no- configuration case that will change. To get the current behaviour after the proposed changes are implemented, an application developer would have to do logging.lastResort = None, which is a small price to pay (and more or less equivalent in difficulty with what users who want verbosity by default have to do, e.g. call basicConfig(). Regards, Vinay Sajip From aviral.nit at gmail.com Fri Dec 10 13:47:42 2010 From: aviral.nit at gmail.com (aviral gupta) Date: Fri, 10 Dec 2010 10:47:42 -0800 (PST) Subject: Interview Programming puzzles Message-ID: <4c87194d-c5a7-4a97-aa10-b7b7b997ce6f@h17g2000pre.googlegroups.com> For Programming puzzles visit the blog http://coders-stop.blogspot.com/ From rob.randall2 at gmail.com Fri Dec 10 14:03:19 2010 From: rob.randall2 at gmail.com (Rob Randall) Date: Fri, 10 Dec 2010 19:03:19 +0000 Subject: 64 bit memory usage In-Reply-To: References: <4d015be7$0$1670$742ec2ed@news.sonic.net> Message-ID: I manged to get my python app past 3GB on a smaller 64 bit machine. On a test to check memory usage with gc disabled only an extra 6MB was used. The figures were 1693MB to 1687MB. This is great. Thanks again for the help. On 10 December 2010 13:54, Rob Randall wrote: > You guys are right. If I disable the gc it will use all the virtual RAM in > my test. > > The application I have been running these tests for is a port of a program > written in a LISP-based tool running on Unix. > It does a mass of stress calculations. > > The port has been written using a python-based toolkit I am responsible > for. This toolkit offers much of the same functionlity as the LISP tool. > It is based around the use of demand-driven/declarative programming. > > When the porting project started no one realised just how much memory the > heaviest of the test cases used. > It uses 40+ GB on an HP Unix machine. > > It is easy to see now that the port should have been written differently, > but it is essentially complete now. > > This has lead me to see if a hardware solution can be found using 64 bit > windows machnes. > > I will try running one the tests next to see what impact disabling the gc > will have. > > Thanks, > Rob. > > > > On 9 December 2010 22:44, John Nagle wrote: > >> On 12/8/2010 10:42 PM, Dennis Lee Bieber wrote: >> >>> On Wed, 8 Dec 2010 14:44:30 +0000, Rob Randall >>> declaimed the following in gmane.comp.python.general: >>> >>> I am trying to understand how much memory is available to a 64 bit >>>> python >>>> process running under Windows XP 64 bit. >>>> >>>> When I run tests just creating a series of large dictionaries containing >>>> string keys and float values I do not seem to be able to grow the >>>> process >>>> beyond the amount of RAM present. >>>> >>> >> If you get to the point where you need multi-gigabyte Python >> dictionaries, you may be using the wrong tool for the job. >> If it's simply that you need to manage a large amount of data, >> that's what databases are for. >> >> If this is some super high performance application that needs to keep a >> big database in memory for performance reasons, CPython >> is probably too slow. For that, something like Google's BigTable >> may be more appropriate, and will scale to terabytes if necessary. >> >> John Nagle >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jgardner at jonathangardner.net Fri Dec 10 14:08:46 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Fri, 10 Dec 2010 11:08:46 -0800 Subject: continuing development on modules after they're installed In-Reply-To: References: <2a700607-78ee-4186-bf80-da02920daceb@m7g2000vbn.googlegroups.com> Message-ID: On Fri, Dec 10, 2010 at 9:32 AM, Ian wrote: > On Dec 10, 9:57?am, hoesley wrote: >> I just started using distutils to install the modules I'm working on >> to site-packages. Now, however, if I make changes in my development >> directory, then import the modules into python, it always loads up the >> installed version. Thus, I can't continue development without first >> uninstalling the modules I'm working on, so that the interpreter finds >> them in the local directory instead of site-packages. Is there any >> simple way around this? I figure this must be a very common thing to >> encounter. Thanks! > > Do you need the installed version to be distinct from the development > version? ?If not, you can "install" the module using a simple soft > link (on Unix) or a .pth file (on Windows) that points to your > development directory. > > If you do need them to be distinct, a simple way to preferentially get > the development version is to add it to the *beginning* of sys.path: > > sys.path.insert(0, '/path/to/development/directory/') > > This process can be simplified further by putting it in a > PYTHONSTARTUP script. > A simpler way to do this is to use virtualenv. $ virtualenv --no-site-packages YourEnv $ . YourEnv/bin/activate $ cd YourProject $ python setup.py develop (I'm not sure on the Windows commands, although I assume they exist and are just as trivial as the Unix ones.) Now, there is a link from the lib/python2.6/site-packages files to YourProject. (Or Python2.7 or whatever version you are using.) I'd also look at using Paster to create the package. It gives you a pretty decent setup for straight up Python packages. -- Jonathan Gardner jgardner at jonathangardner.net From python at mrabarnett.plus.com Fri Dec 10 14:18:41 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 10 Dec 2010 19:18:41 +0000 Subject: run a function in another processor in python In-Reply-To: References: <4D00B416.5090509@sequans.com> Message-ID: <4D027D11.9090400@mrabarnett.plus.com> On 10/12/2010 17:52, Dennis Lee Bieber wrote: > On Fri, 10 Dec 2010 23:02:24 +1100, Astan Chee > declaimed the following in gmane.comp.python.general: > >>>> for thread in threads: >>>> if not thread.is_alive(): >>>> threads.remove(thread) >>>> > > I can see a potential flaw just in that... You are changing the > length of the list you are iterating over, which is never recommended. > > Consider this simplistic attempt at removing the even numbers from a > list: > >>>> tlist = [1, 1, 0, 0, 2, 2, 3, 4, 3, 4, 5, 6, 7, 8] >>>> for t in tlist: > ... if t % 2 == 0: > ... tlist.remove(t) > ... >>>> tlist > [1, 1, 0, 2, 3, 3, 5, 7] >>>> > > Doesn't work if a pair of even numbers are adjacent. In your case, > adjacent "dead" threads will not be removed. > > Something like the following may be safer: > > dead = [] > for t in threads: > if not t.is_alive(): > dead.append(t) > for dt in dead: > threads.remove(dt) I think this will be more efficient: threads = [t for t in threads if t.is_alive()] From rossgk at gmail.com Fri Dec 10 14:51:44 2010 From: rossgk at gmail.com (Ross) Date: Fri, 10 Dec 2010 11:51:44 -0800 (PST) Subject: unicode compare errors Message-ID: <549e0020-e21e-49c5-bc89-21122f9ce0a9@35g2000prb.googlegroups.com> I've a character encoding issue that has stumped me (not that hard to do). I am parsing a small text file with some possibility of various currencies being involved, and want to handle them without messing up. Initially I was simply doing: currs = [u'$', u'?', u'?', u'?'] aFile = open(thisFile, 'r') for mline in aFile: # mline might be "?5.50" if item[0] in currs: item = item[1:] But the problem was: SyntaxError: Non-ASCII character '\xa3' in file The remedy was of course to declare the file encoding for my Python module, at the start of the file I used: # -*- coding: UTF-8 -*- That allowed me to progress. But now when I come to line item that is a non $ currency, I get this error: views.py:3364: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal. ?which I think means Python's unable to convert the char's in the file I'm reading from into unicode to compare to the items in the list currs. I think this is saying that u'?' == '?' is false. (I hope those chars show up okay in my post here) Since I can't control the encoding of the input file that users submit, how to I get past this? How do I make such comparisons be True? Thanks in advance for any suggestions Ross. From alex at moreati.org.uk Fri Dec 10 14:57:56 2010 From: alex at moreati.org.uk (Alex Willmer) Date: Fri, 10 Dec 2010 11:57:56 -0800 (PST) Subject: Python creates "locked" temp dir References: <0c30c818-f73b-4b09-b707-64ea457c757d@z26g2000prf.googlegroups.com> <91dca7c4-00c7-44ad-8902-54221534107c@o9g2000pre.googlegroups.com> Message-ID: <753d0b5b-867b-456c-b3e9-2662ce1df1f8@f20g2000vbc.googlegroups.com> On Dec 8, 6:26?pm, Christian Heimes wrote: > There isn't a way to limit access to a single process. mkdtemp creates > the directory with mode 0700 and thus limits it to the (effective) user > of the current process. Any process of the same user is able to access > the directory. > > Christian Quite right. My apologies for confusing temporary file creation, for which exclusive access is used and temporary directory creation for which there is no such mode. From smallpox911 at gmail.com Fri Dec 10 15:01:51 2010 From: smallpox911 at gmail.com (small Pox) Date: Fri, 10 Dec 2010 12:01:51 -0800 (PST) Subject: Biography, Dr Michel Chossudovsky, Dr.Evgeny Chossudovsky: Writer with a distinguished UN career Message-ID: <1007de6e-544d-4d9f-8b66-615566a1fb29@e16g2000pri.googlegroups.com> http://www.globalresearch.ca/index.php?context=viewArticle&code=20060212&articleId=1955 Evgeny Chossudovsky: Writer with a distinguished UN career Global Research, February 12, 2006 The Irish Times - 2006-01-18 Throughout his UN career and until his death, Evgeny Chossudovsky expressed his firm support for the Palestinian cause. He supported the Centre for Research on Globalization from the outset. Global Research will continue in his footsteps to support the causes of social justice and World peace. (Michel Chossudovsky) The Irish Times January 28, 2006 Saturday OBITUARY Dr Evgeny Chossudovsky, who has died aged 91, was a Russian Jewish ?migr? who had a distinguished career with the United Nations following the second World War. In Dublin, in the late 1970s, he continued another role as a prestigious writer on international relations. He was a trenchant, knowledgeable and dogged participant in internationalist discussions at the Royal Irish Academy and in many publications, including The Irish Times. "Chossy" to his friends, he was well known too for a fine sense of humour. His family had been displaced by the civil war that followed the 1917 Russian Revolution and by the first World War. The Irish connection was made in the 1930s when, as a student, he met his wife Rachel Sullivan, then studying at Queen's University Belfast, at a Geneva summer school. She was from a Co Antrim Protestant family. In 1939 they were married in a Belfast registry office. In the late 1970s they settled in Baily, Howth. Chossudovsky "decided he wanted to be in the UN before it even existed", his son Michel, professor of economics at the University of Ottawa, said at his funeral. In 1947 he became one of three special assistants to the distinguished Swedish economist, and later Nobel laureate, Gunnar Myrdal, director of the UN's Economic Commission for Europe (ECE). As the Cold War deepened, Myrdal and his "ECE trinity" pushed the concept of East-West co-operation and peaceful coexistence between conflicting economic systems, in which Chossudovsky believed passionately. He served the UN Conference on Trade and Development (Unctad) under the Argentinian former central banker, Ra?l Prebisch. Intended to embrace the aspirations of poor countries, Unctad was a Non-Aligned Movement initiative. Chossudovsky was secretary of its Trade and Development Board and his considerable diplomatic skills as a consensus-maker emerged at international conferences. He worked behind the scenes, often into the small hours, agreeing resolutions with delegations in a determination to achieve global social justice. But as the toothless Unctad became undermined by the "neo-liberal" agenda and the later Uruguay Round and General Agreement on Tariffs and Trade (Gatt), Chossudovsky moved to become director of the UN Institute for Training and Research (Unitar) in Geneva. Later, in semi- retirement, he became a special fellow of the institute. All his life Chossudovsky retained a patriotic attachment to Russia and a sympathy for socialist ideas. But at the end he expressed disappointment that the spirit of the UN was being undermined, saying only weeks ago to his son that the world was now "in an awful situation". He was born in 1914 into an affluent Jewish merchant family in Rostov- on-Don near the Sea of Azov. His grandfather traded in wheat. The family went to Berlin in 1921 during the civil war. Their property had been confiscated. His father was a gifted actor who had trained as a lawyer but as a Jew was unable to practise. In Rostov-on-Don he ran a Shakespearean theatre and in Berlin various jobs included selling ice-cream on the street. But Chossudovsky's beloved rich maternal uncle, Moses Gorfman, stepped in to "look after" the family, particularly as it became dispersed. In Berlin Chossudovsky resumed school, and studied Goethe. He became equally fluent in German and Russian - and later English and French. After school, he applied to universities abroad. As a Jew, there was little question of studying in Nazi Germany. He was accepted by the University of Edinburgh, where he studied economics and earned a PhD. As Chossudovsky's studies started in 1934 his uncle Moses, a businessman who traded in the stock market, was living in London. He later left for Paris, where Evgeny's parents joined him. During the war, on the night French police came to take uncle Moses away for extermination at Auschwitz, his parents were overlooked. Chossudovsky received no news of them until after the war. He worked for the Co-operative Movement, first in Wales as an adult education officer for miners giving evening courses in international affairs, and then in London. Highly committed to its ideals, he worked for the movement until 1947. A year earlier, he had applied to the UN. He had a Soviet passport and the UN wanted Russians. After a brief stint in New York (which he judged no place to bring up children) he transferred to the Europe office of the UN in Geneva. Ever since falling in love in Geneva he had wanted to live there. Chossudovsky was author and co-author of several books including The Helsinki Final Act Viewed in the United Nations Perspective. He co- edited The United Nations System at Geneva - A Working Guide and contributed to the International Herald Tribune, Le Monde Diplomatique and the journal Foreign Affairs. He was also a frequent participant at disarmament conferences of the Pugwash group. His Irish Times contributions were on a wide range of issues, including the North. He also contributed to the Royal Irish Academy's Irish Studies in International Affairs. Dr Ronan Fanning, professor of history at UCD, said Chossudovsky was "an outside voice" at the academy who "played a role broadening our perspectives" at a time when objective discussion was difficult in Ireland. He loved Wilde, Beckett and Joyce. He was predeceased by his wife Rachel in 1996; is survived by his daughter, Eugenia, son Michel and his wife Micheline; and two grandchildren, Natacha and Maya. Dr Evgeny Michel Chossudovsky: born August 15th, 1914; died January 4th, 2006 P.S. Google is mischieving with my posts ? If there are duplicate, they are because sometimes I post and it does not and if I repeat it dups at other times. It only happens from this account ... so its targetted. Google mischief or censorship to put me in disrepute as spammer ????!!!! From nagle at animats.com Fri Dec 10 15:02:21 2010 From: nagle at animats.com (John Nagle) Date: Fri, 10 Dec 2010 12:02:21 -0800 Subject: Python critique In-Reply-To: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> Message-ID: <4d028748$0$1621$742ec2ed@news.sonic.net> On 12/10/2010 2:31 AM, kolo 32 wrote: > Hi, all, > > Python critique from strchr.com: > > http://www.strchr.com/python_critique I have criticisms of Python, but those aren't them. Probably the biggest practical problem with CPython is that C modules have to be closely matched to the version of CPython. There's no well-defined API that doesn't change. This make life easier for Guido and tough on everybody else. That's the real cause of Python's "version hell". On the scope front, given the lack of declarations, Python has done reasonably well. Scopes in Python aren't as narrow as one might like, but this isn't a major headache. Python has been more successful with the "no declarations" rule than most other languages. Others that started with no declarations, from FORTRAN to JavaScript, eventually had to retrofit them. Interestingly, some of the motivation for "functional programming" in Python, with lambdas and list comprehensions, is to get a very local scope for a very local variable. John Nagle From rossgk at gmail.com Fri Dec 10 15:07:19 2010 From: rossgk at gmail.com (Ross) Date: Fri, 10 Dec 2010 12:07:19 -0800 (PST) Subject: unicode compare errors References: <549e0020-e21e-49c5-bc89-21122f9ce0a9@35g2000prb.googlegroups.com> Message-ID: On Dec 10, 2:51?pm, Ross wrote: > Initially I was simply doing: > > ? currs = [u'$', u'?', u'?', u'?'] > ? aFile = open(thisFile, 'r') > ? for mline in aFile: ? ? ? ? ? ? ?# mline might be "?5.50" > ? ? ?if item[0] in currs: > ? ? ? ? ? item = item[1:] > Don't you love it when someone solves their own problem? Posting a reply here so that other poor chumps like me can get around this... I found I could import codecs that allow me to read the file with my desired encoding. Huzzah! Instead of opening the file with a standard aFile = open(thisFile, 'r') I instead ensure I've imported the codecs: import codecs ... and then I used a specific encoding on the file read: aFile = codecs.open(thisFile, encoding='utf-8') Then all my compares seem to work fine. If I'm off-base and kludgey here and should be doing something differently please give me a poke. Regards, Ross. From ben+python at benfinney.id.au Fri Dec 10 15:23:49 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 11 Dec 2010 07:23:49 +1100 Subject: decouple copy of a list References: <9a8681fb-0c8b-42ae-aa2b-9200ca92bd2b@k11g2000vbf.googlegroups.com> Message-ID: <87k4jhz8a2.fsf@benfinney.id.au> Dirk Nachbar writes: > I want to take a copy of a list a > > b=a In addition to the other good replies you've received: To take a copy of an object, the answer is never ?b = a?. That binds a reference ?b? to the same object referenced by ?a?. The assignment operator ?=? never copies; it binds a reference to an existing object. To create a copy, you always need to do something other than assignment. Hope that keeps it clear for you. -- \ ?Computer perspective on Moore's Law: Human effort becomes | `\ twice as expensive roughly every two years.? ?anonymous | _o__) | Ben Finney From nobody at nowhere.com Fri Dec 10 16:09:05 2010 From: nobody at nowhere.com (Nobody) Date: Fri, 10 Dec 2010 21:09:05 +0000 Subject: unicode compare errors References: <549e0020-e21e-49c5-bc89-21122f9ce0a9@35g2000prb.googlegroups.com> Message-ID: On Fri, 10 Dec 2010 11:51:44 -0800, Ross wrote: > Since I can't control the encoding of the input file that users > submit, how to I get past this? How do I make such comparisons be > True? On Fri, 10 Dec 2010 12:07:19 -0800, Ross wrote: > I found I could import codecs that allow me to read the file with my > desired encoding. Huzzah! > If I'm off-base and kludgey here and should be doing something Er, do you know the file's encoding or don't you? Using: aFile = codecs.open(thisFile, encoding='utf-8') is telling Python that the file /is/ in utf-8. If it isn't in utf-8, you'll get decoding errors. If you are given a file with no known encoding, then you can't reliably determine what /characters/ it contains, and thus can't reliably compare the contents of the file against strings of characters, only against strings of bytes. About the best you can do is to use an autodetection library such as: http://chardet.feedparser.org/ From debatem1 at gmail.com Fri Dec 10 17:04:12 2010 From: debatem1 at gmail.com (geremy condra) Date: Fri, 10 Dec 2010 14:04:12 -0800 Subject: run a function in another processor in python In-Reply-To: References: <4D00B416.5090509@sequans.com> Message-ID: On Fri, Dec 10, 2010 at 4:42 AM, Astan Chee wrote: > On Fri, Dec 10, 2010 at 1:37 AM, Peter Otten <__peter__ at web.de> wrote: >> >> I can't replicate the crash. However, your problem looks like there is a >> ready-to-use solution: >> >> >> http://docs.python.org/library/multiprocessing.html#using-a-pool-of-workers >> >> -- >> http://mail.python.org/mailman/listinfo/python-list > > > Pool.map doesn't seem to be able to support multiple argument functions > which is what I'm trying to do here. Any other suggestions? > Thanks again 1. Post the real code you're using, and 2. Put the arguments you want in a tuple and pass that. As an example, let's say I have the following function: def my_func(x, y, z): return x + y * z you could rewrite this as: def my_func(*args): return args[0] + args[1] * args[2] Here's a worked-out example: #! /usr/bin/env python3 import multiprocessing def my_func(x, y, z): return x + y * z def my_func_wrapper(t): return my_func(*t) # assume we can get an iterable over each argument xs = [1, 2, 3, 4] ys = [5, 6, 7, 8] zs = [9, 1, 2, 3] # set up the pool to match the number of CPUs num_processes = multiprocessing.cpu_count() pool = multiprocessing.Pool(num_processes) #will call my_func(1, 5, 9), my_func(2, 6, 1), etc. results = pool.map(my_func_wrapper, zip(xs, ys, zs)) print(results) Interesting factoid: you can't seem to use lambda or a decorator to do this, which would have been my first instinct. Pickle apparently chokes, although marshall wouldn't. Geremy Condra From stefaan.himpe at gmail.com Fri Dec 10 17:06:43 2010 From: stefaan.himpe at gmail.com (Stefaan Himpe) Date: Fri, 10 Dec 2010 23:06:43 +0100 Subject: surprised by import in python 2.6 Message-ID: Hello list, Recently someone asked me this question, to which I could not give an answer. I'm hoping for some insight, or a manual page. What follows is python 2.6. The problem is with the difference between from test import * and import test First things first. Here's the code to test.py: a = 3 def f(): global a return a Now, in the interactive interpreter: >>> from test import * >>> a 3 >>> f() 3 >>> a = 4 >>> f() 3 in a second session: >>> import test >>> test.a 3 >>> test.f() 3 >>> test.a = 4 >>> test.f() 4 Somehow, in the first session I cannot modify the global variable a returned from f, but in the second session I can. To my eye, the only difference seems to be a namespace. Can anyone shine some light on this matter? Thanks, Stefaan. From ian.g.kelly at gmail.com Fri Dec 10 17:22:54 2010 From: ian.g.kelly at gmail.com (Ian) Date: Fri, 10 Dec 2010 14:22:54 -0800 (PST) Subject: surprised by import in python 2.6 References: Message-ID: On Dec 10, 3:06?pm, Stefaan Himpe wrote: > Somehow, in the first session I cannot modify the global variable a > returned from f, but in the second session I can. To my eye, the only > difference seems to be a namespace. Can anyone shine some light on this > matter? It's not the same global variable. In the second session, you import the module test and bind it to the name "test" in the main namespace. "test.a" and "test.f" refer to the objects named "a" and "f" in the test namespace. In the first session, you import all the variables exported by the module test and bind them using the same names in the main namespace. Thus "a" and "test.a" refer to the same int; and "f" and "test.f" refer to the same function, but they are not the same variables. When you rebind the name "a", it does not also magically rebind "test.a", and vice versa. Cheers, Ian From emile at fenx.com Fri Dec 10 17:40:01 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 10 Dec 2010 14:40:01 -0800 Subject: surprised by import in python 2.6 In-Reply-To: References: Message-ID: On 12/10/2010 2:22 PM Ian said... > On Dec 10, 3:06 pm, Stefaan Himpe wrote: >> Somehow, in the first session I cannot modify the global variable a >> returned from f, but in the second session I can. To my eye, the only >> difference seems to be a namespace. Can anyone shine some light on this >> matter? > > It's not the same global variable. In the second session, you import > the module test and bind it to the name "test" in the main namespace. > "test.a" and "test.f" refer to the objects named "a" and "f" in the > test namespace. > > In the first session, you import all the variables exported by the > module test and bind them using the same names in the main namespace. > Thus "a" and "test.a" refer to the same int; and "f" and "test.f" > refer to the same function, but they are not the same variables. When > you rebind the name "a", it does not also magically rebind "test.a", > and vice versa. > Here's an example of what Ian's explained showing that f's global namespace is the test module: emile at paj39:~$ cat > test.py a = 3 def f(): global a return a emile at paj39:~$ python Python 2.6.4rc2 (r264rc2:75497, Oct 20 2009, 02:55:11) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from test import * >>> import test >>> a 3 >>> a = 4 >>> f() 3 >>> test.a = 5 >>> f() 5 >>> From orasnita at gmail.com Fri Dec 10 17:46:41 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Sat, 11 Dec 2010 00:46:41 +0200 Subject: Python critique References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> <4d028748$0$1621$742ec2ed@news.sonic.net> Message-ID: <499F3F3D16A34734B5D195F91EB58520@teddy> From: "John Nagle" > On 12/10/2010 2:31 AM, kolo 32 wrote: >> Hi, all, >> >> Python critique from strchr.com: >> >> http://www.strchr.com/python_critique > > I have criticisms of Python, but those aren't them. > > Probably the biggest practical problem with CPython is > that C modules have to be closely matched to the version of > CPython. There's no well-defined API that doesn't change. > This make life easier for Guido and tough on everybody else. > That's the real cause of Python's "version hell". > > On the scope front, given the lack of declarations, Python > has done reasonably well. Scopes in Python aren't as narrow > as one might like, but this isn't a major headache. How narrow are the scopes in Python? Is each block (each level of indentation) a scope? If it is, then I think it is very enough because the other cases can be detected easier or it might not appear at all in a well-written program. If it is not, then yes, it is a problem. Can you please tell me how to write the following program in Python? my $n = 1; { my $n = 2; print "$n\n"; } print "$n\n"; If this program if ran in Perl, it prints: 2 1 I have tried to write it, but I don't know how I can create that block because it tells that there is an unexpected indent. Thanks. Octavian From sridharr at activestate.com Fri Dec 10 17:47:50 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Fri, 10 Dec 2010 14:47:50 -0800 Subject: ANN: ActivePython 3.1.3.5 is now available Message-ID: ActiveState is pleased to announce ActivePython 3.1.3.5, a complete, ready-to-install binary distribution of Python 3.1. http://www.activestate.com/activepython/downloads What's New in ActivePython-3.1.3.5 ================================== *Release date: 6-Dec-2010* New Features & Upgrades ----------------------- - Upgrade to Python 3.1.3 (`release notes `__) - Upgrade to Tcl/Tk 8.5.9 (`changes `_) - Security upgrade to openssl-0.9.8q - [MacOSX] Tkinter now requires ActiveTcl 8.5 64-bit (not Apple's Tcl/Tk 8.5 on OSX) - Upgrade to PyPM 1.2.6; noteworthy changes: - New command 'pypm log' to view log entries for last operation - Upgraded the following packages: - SQLAlchemy-0.6.5 - virtualenv5-1.3.4.5 Noteworthy Changes & Bug Fixes ------------------------------ - [MacOSX] Include missing architecture binaries - Bug #88876 - PyPM bug fixes: - depgraph: Fix a bug with missing extra in install_requires - Bug #88825 - depgraph: Fix a bug with double-marking a package for upgrade - Bug #88664: handle cyclic dependencies in the depgraph algorithm - Ignore comments (starting with #) in the requirements file - Fix: ignore empty lines in requirements.txt - Bug #88882: Fix pickle incompatability (sqlite) on Python 3.x What is ActivePython? ===================== ActivePython is ActiveState's binary distribution of Python. Builds for Windows, Mac OS X, Linux are made freely available. Solaris, HP-UX and AIX builds, and access to older versions are available in ActivePython Business, Enterprise and OEM editions: http://www.activestate.com/python ActivePython includes the Python core and the many core extensions: zlib and bzip2 for data compression, the Berkeley DB (bsddb) and SQLite (sqlite3) database libraries, OpenSSL bindings for HTTPS support, the Tix GUI widgets for Tkinter, ElementTree for XML processing, ctypes (on supported platforms) for low-level library access, and others. The Windows distribution ships with PyWin32 -- a suite of Windows tools developed by Mark Hammond, including bindings to the Win32 API and Windows COM. ActivePython 2.6, 2.7 and 3.1 also include a binary package manager for Python (PyPM) that can be used to install packages much easily. For example: C:\>pypm install mysql-python [...] C:\>python >>> import MySQLdb >>> See this page for full details: http://docs.activestate.com/activepython/3.1/whatsincluded.html As well, ActivePython ships with a wealth of documentation for both new and experienced Python programmers. In addition to the core Python docs, ActivePython includes the "What's New in Python" series, "Dive into Python", the Python FAQs & HOWTOs, and the Python Enhancement Proposals (PEPs). An online version of the docs can be found here: http://docs.activestate.com/activepython/3.1/ We would welcome any and all feedback to: activepython-feedback at activestate.com Please file bugs against ActivePython at: http://bugs.activestate.com/enter_bug.cgi?product=ActivePython Supported Platforms =================== ActivePython is available for the following platforms: - Windows (x86 and x64) - Mac OS X (x86 and x86_64; 10.5+) - Linux (x86 and x86_64) - Solaris/SPARC (32-bit and 64-bit) (Business, Enterprise or OEM edition only) - Solaris/x86 (32-bit) (Business, Enterprise or OEM edition only) - HP-UX/PA-RISC (32-bit) (Business, Enterprise or OEM edition only) - HP-UX/IA-64 (32-bit and 64-bit) (Enterprise or OEM edition only) - AIX/PowerPC (32-bit and 64-bit) (Business, Enterprise or OEM edition only) More information about the Business Edition can be found here: http://www.activestate.com/business-edition Custom builds are available in the Enterprise Edition: http://www.activestate.com/enterprise-edition Thanks, and enjoy! The Python Team -- Sridhar Ratnakumar Python Developer ActiveState, The Dynamic Language Experts sridharr at activestate.com http://www.activestate.com Get insights on Open Source and Dynamic Languages at www.activestate.com/blog From solipsis at pitrou.net Fri Dec 10 18:09:33 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Sat, 11 Dec 2010 00:09:33 +0100 Subject: Python critique References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> <4d028748$0$1621$742ec2ed@news.sonic.net> Message-ID: <20101211000933.43833327@pitrou.net> On Fri, 10 Dec 2010 12:02:21 -0800 John Nagle wrote: > > Probably the biggest practical problem with CPython is > that C modules have to be closely matched to the version of > CPython. There's no well-defined API that doesn't change. Please stop spreading FUD: http://docs.python.org/c-api/index.html Thank you Antoine. From benjamin.kaplan at case.edu Fri Dec 10 18:13:48 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 10 Dec 2010 18:13:48 -0500 Subject: Python critique In-Reply-To: <499F3F3D16A34734B5D195F91EB58520@teddy> References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> <4d028748$0$1621$742ec2ed@news.sonic.net> <499F3F3D16A34734B5D195F91EB58520@teddy> Message-ID: On Fri, Dec 10, 2010 at 5:46 PM, Octavian Rasnita wrote: > From: "John Nagle" >> On 12/10/2010 2:31 AM, kolo 32 wrote: >>> Hi, all, >>> >>> Python critique from strchr.com: >>> >>> http://www.strchr.com/python_critique >> >> ? ?I have criticisms of Python, but those aren't them. >> >> ? ?Probably the biggest practical problem with CPython is >> that C modules have to be closely matched to the version of >> CPython. ?There's no well-defined API that doesn't change. >> This make life easier for Guido and tough on everybody else. >> That's the real cause of Python's "version hell". >> >> ? ?On the scope front, given the lack of declarations, Python >> has done reasonably well. ?Scopes in Python aren't as narrow >> as one might like, but this isn't a major headache. > > How narrow are the scopes in Python? > Is each block (each level of indentation) a scope? > If it is, then I think it is very enough because the other cases can be detected easier or it might not appear at all in a well-written program. > If it is not, then yes, it is a problem. > > Can you please tell me how to write the following program in Python? > > my $n = 1; > > { > ?my $n = 2; > ?print "$n\n"; > } > > print "$n\n"; > > If this program if ran in Perl, it prints: > 2 > 1 > > I have tried to write it, but I don't know how I can create that block because it tells that there is an unexpected indent. > > Thanks. > > Octavian The only scopes Python has are module and function. Python doesn't have declarations like Perl (or most other languages), so there's no way to specify that you want a different variable within the block. From steve+comp.lang.python at pearwood.info Fri Dec 10 18:15:07 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Dec 2010 23:15:07 GMT Subject: Python critique References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> <4d028748$0$1621$742ec2ed@news.sonic.net> Message-ID: <4d02b47b$0$30000$c3e8da3$5496439d@news.astraweb.com> On Sat, 11 Dec 2010 00:46:41 +0200, Octavian Rasnita wrote: > How narrow are the scopes in Python? > Is each block (each level of indentation) a scope? Thankfully, no. > If it is, then I > think it is very enough because the other cases can be detected easier > or it might not appear at all in a well-written program. I don't understand what this means. > If it is not, then yes, it is a problem. Why is it a problem? > Can you please tell me how to write the following program in Python? > > my $n = 1; > > { > my $n = 2; > print "$n\n"; > } > > print "$n\n"; > > If this program if ran in Perl, it prints: > 2 > 1 Lots of ways. Here's one: n = 1 class Scope: n = 2 print n print n Here's another: n = 1 print (lambda n=2: n)() print n Here's a third: n = 1 def scope(): n = 2 print n scope() print n Here's a fourth: import sys n = 1 (sys.stdout.write("%d\n" % n) for n in (2,)).next() print n In Python 3, this can be written more simply: n = 1 [print(n) for n in (2,)] print n > I have tried to write it, but I don't know how I can create that block > because it tells that there is an unexpected indent. Functions, closures, classes and modules are scopes in Python. If you want a new scope, create one of those. -- Steven From stefan_ml at behnel.de Fri Dec 10 18:18:27 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 11 Dec 2010 00:18:27 +0100 Subject: Python critique In-Reply-To: <4d028748$0$1621$742ec2ed@news.sonic.net> References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> <4d028748$0$1621$742ec2ed@news.sonic.net> Message-ID: John Nagle, 10.12.2010 21:02: > Probably the biggest practical problem with CPython is > that C modules have to be closely matched to the version of > CPython. There's no well-defined API that doesn't change. Well, there are no huge differences between CPython versions (apart from the Py_ssize_t change back in 2.5), and porting isn't as hard as you seem to suggest here. > This make life easier for Guido and tough on everybody else. > That's the real cause of Python's "version hell". If you write your code in Cython instead of C, it's a lot easier to keep it portable across CPython versions (and C compilers). It's also a lot easier to write it in the first place. Note also that Py3.2 introduces a stable ABI for extension modules. This implies a stable API as well. Stefan From stefan_ml at behnel.de Fri Dec 10 18:25:47 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 11 Dec 2010 00:25:47 +0100 Subject: Python critique In-Reply-To: References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> <4d028748$0$1621$742ec2ed@news.sonic.net> <499F3F3D16A34734B5D195F91EB58520@teddy> Message-ID: Benjamin Kaplan, 11.12.2010 00:13: > On Fri, Dec 10, 2010 at 5:46 PM, Octavian Rasnita wrote: >> How narrow are the scopes in Python? >> Is each block (each level of indentation) a scope? >> If it is, then I think it is very enough because the other cases can be detected easier or it might not appear at all in a well-written program. >> If it is not, then yes, it is a problem. Why would it? >> Can you please tell me how to write the following program in Python? >> >> my $n = 1; >> >> { >> my $n = 2; >> print "$n\n"; >> } >> >> print "$n\n"; >> >> If this program if ran in Perl, it prints: >> 2 >> 1 >> >> I have tried to write it, but I don't know how I can create that block because it tells that there is an unexpected indent. > > The only scopes Python has are module and function. Python doesn't > have declarations like Perl (or most other languages), so there's no > way to specify that you want a different variable within the block. Yep, keeps you from writing bad style code like the above. Stefan From newswombat at gmail.com Fri Dec 10 18:32:30 2010 From: newswombat at gmail.com (News Wombat) Date: Fri, 10 Dec 2010 15:32:30 -0800 (PST) Subject: ctypes question Message-ID: <2abdd9b3-66ec-4125-a5f8-41315008cccc@l17g2000yqe.googlegroups.com> Hi everyone, I've been experimenting with the ctypes module and think it's great. I'm hitting a few snags though with seg faults. I attached two links that holds the code. The line i'm having problems with is this, sn=clibsmi.smiGetNextNode(pointer(sno),SMI_NODEKIND_ANY) It will work one time, and if I call it again with the result of the previous, even though the result (a c struct) looks ok, it will segfault. I think it's a problem with pointers or maybe the function in the c library trying to change a string that python won't let it change. I'm stuck, any tips would be appreciated. Thanks, and Merry Christmas! constants.py: http://pastebin.com/HvngjzZN libsmi.py: http://pastebin.com/19C9kYEa From nagle at animats.com Fri Dec 10 18:51:19 2010 From: nagle at animats.com (John Nagle) Date: Fri, 10 Dec 2010 15:51:19 -0800 Subject: Python critique In-Reply-To: References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> <4d028748$0$1621$742ec2ed@news.sonic.net> <499F3F3D16A34734B5D195F91EB58520@teddy> Message-ID: <4d02bcf2$0$1624$742ec2ed@news.sonic.net> On 12/10/2010 3:25 PM, Stefan Behnel wrote: > Benjamin Kaplan, 11.12.2010 00:13: >> On Fri, Dec 10, 2010 at 5:46 PM, Octavian Rasnita wrote: >> The only scopes Python has are module and function. There's more. Both a lambda, and in Python 3.x, list comprehensions, introduce a new scope. John Nagle From drsalists at gmail.com Fri Dec 10 19:37:29 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 10 Dec 2010 16:37:29 -0800 Subject: Python critique In-Reply-To: <4d02bcf2$0$1624$742ec2ed@news.sonic.net> References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> <4d028748$0$1621$742ec2ed@news.sonic.net> <499F3F3D16A34734B5D195F91EB58520@teddy> <4d02bcf2$0$1624$742ec2ed@news.sonic.net> Message-ID: On Fri, Dec 10, 2010 at 3:51 PM, John Nagle wrote: > On 12/10/2010 3:25 PM, Stefan Behnel wrote: >> >> Benjamin Kaplan, 11.12.2010 00:13: >>> >>> On Fri, Dec 10, 2010 at 5:46 PM, Octavian Rasnita wrote: > >>> The only scopes Python has are module and function. > > ? There's more. ?Both a lambda, and in Python 3.x, > list comprehensions, introduce a new scope. > > ? ? ? ? ? ? ? ? ? ? ? ?John Nagle > -- > http://mail.python.org/mailman/listinfo/python-list > And classes and methods. Also, I like to draw a distinction between "code scopes" and "data scopes". We've been talking about data scopes. Code scopes are pretty much indents and dedents in Python - they define what code is operated on by something code-flow-related. To the OP: Python doesn't need a "my" or "local" - it has more rational defaults. From stefan_ml at behnel.de Fri Dec 10 19:49:44 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 11 Dec 2010 01:49:44 +0100 Subject: Python critique In-Reply-To: <4d02bcf2$0$1624$742ec2ed@news.sonic.net> References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> <4d028748$0$1621$742ec2ed@news.sonic.net> <499F3F3D16A34734B5D195F91EB58520@teddy> <4d02bcf2$0$1624$742ec2ed@news.sonic.net> Message-ID: John Nagle, 11.12.2010 00:51: > On 12/10/2010 3:25 PM, Stefan Behnel wrote: >> Benjamin Kaplan, 11.12.2010 00:13: >>> On Fri, Dec 10, 2010 at 5:46 PM, Octavian Rasnita wrote: > >>> The only scopes Python has are module and function. > > There's more. Both a lambda, and in Python 3.x, > list comprehensions, introduce a new scope. To be a little more precise: in Py3, list comprehensions use the same kind of scope that generator expressions, set comprehensions and dict comprehensions always had. Stefan From __peter__ at web.de Fri Dec 10 19:58:10 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 11 Dec 2010 01:58:10 +0100 Subject: run a function in another processor in python References: <4D00B416.5090509@sequans.com> Message-ID: geremy condra wrote: > On Fri, Dec 10, 2010 at 4:42 AM, Astan Chee wrote: >> On Fri, Dec 10, 2010 at 1:37 AM, Peter Otten <__peter__ at web.de> wrote: >>> >>> I can't replicate the crash. However, your problem looks like there is a >>> ready-to-use solution: >>> >>> >>> http://docs.python.org/library/multiprocessing.html#using-a-pool-of- workers >>> >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >> >> >> Pool.map doesn't seem to be able to support multiple argument functions >> which is what I'm trying to do here. Any other suggestions? >> Thanks again > > 1. Post the real code you're using, and > 2. Put the arguments you want in a tuple and pass that. As an example, > let's say I have the following function: > > def my_func(x, y, z): > return x + y * z > > you could rewrite this as: > > def my_func(*args): > return args[0] + args[1] * args[2] > > > Here's a worked-out example: > > #! /usr/bin/env python3 > > import multiprocessing > > def my_func(x, y, z): > return x + y * z > > def my_func_wrapper(t): > return my_func(*t) > > # assume we can get an iterable over each argument > xs = [1, 2, 3, 4] > ys = [5, 6, 7, 8] > zs = [9, 1, 2, 3] > > # set up the pool to match the number of CPUs > num_processes = multiprocessing.cpu_count() > pool = multiprocessing.Pool(num_processes) > > #will call my_func(1, 5, 9), my_func(2, 6, 1), etc. > results = pool.map(my_func_wrapper, zip(xs, ys, zs)) > print(results) > > > Interesting factoid: you can't seem to use lambda or a decorator to do > this, which would have been my first instinct. Pickle apparently > chokes, although marshall wouldn't. You basically have to ensure that the resulting function is found under its __name__ in the global namespace of its __module__. This can be done with functools.wraps(): #! /usr/bin/env python3 import multiprocessing import functools def starcall(f): @functools.wraps(f) def g(args): return f(*args) return g @starcall def my_func(x, y, z): return x + y * z xs = [1, 2, 3, 4] ys = [5, 6, 7, 8] zs = [9, 1, 2, 3] num_processes = multiprocessing.cpu_count() pool = multiprocessing.Pool(num_processes) results = pool.map(my_func, zip(xs, ys, zs)) print(results) From bavishi.darshak at gmail.com Sat Dec 11 01:02:01 2010 From: bavishi.darshak at gmail.com (Darshak Bavishi) Date: Sat, 11 Dec 2010 11:32:01 +0530 Subject: stuck with Pexpect script need help!! Message-ID: Hi Experts, got ready made code for ssh to unix using python host machine is windows now when i run this its gives following error : * Traceback (most recent call last): File "C:\Python26\pexpect-2.1\pexpect-2.1\pxssh.py", line 1, in from pexpect import * File "C:\Python26\pexpect-2.1\pexpect-2.1\pexpect.py", line 83, in Pexpect is intended for UNIX-like operating systems.""") ImportError: No module named resource A critical module was not found. Probably this operating system does not support it. Pexpect is intended for UNIX-like operating systems. >>> ================================ RESTART ================================ >>> Traceback (most recent call last): File "C:\Python26\ssh_session.py", line 7, in from pexpect import * ImportError: No module named pexpect >>> * Can we use pexpect from windows host machine ?! -- BR Darshak Bavishi -------------- next part -------------- An HTML attachment was scrubbed... URL: From metolone+gmane at gmail.com Sat Dec 11 01:23:23 2010 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Fri, 10 Dec 2010 22:23:23 -0800 Subject: ctypes question References: <2abdd9b3-66ec-4125-a5f8-41315008cccc@l17g2000yqe.googlegroups.com> Message-ID: "News Wombat" wrote in message news:2abdd9b3-66ec-4125-a5f8-41315008cccc at l17g2000yqe.googlegroups.com... > Hi everyone, > > I've been experimenting with the ctypes module and think it's great. > I'm hitting a few snags though with seg faults. I attached two links > that holds the code. The line i'm having problems with is this, > > sn=clibsmi.smiGetNextNode(pointer(sno),SMI_NODEKIND_ANY) > > It will work one time, and if I call it again with the result of the > previous, even though the result (a c struct) looks ok, it will > segfault. I think it's a problem with pointers or maybe the function > in the c library trying to change a string that python won't let it > change. I'm stuck, any tips would be appreciated. Thanks, and Merry > Christmas! > > constants.py: http://pastebin.com/HvngjzZN > libsmi.py: http://pastebin.com/19C9kYEa Well, I can't run your code, but I think you should pass the original "sn" pointer from smiGetNode() and not a pointer(sno). The values are not the same and the library probably relies on passing the original pointer back into smiGetNextNode. sn.contents returns a new SmiNode object so its pointer will be different. -Mark From astan.chee at gmail.com Sat Dec 11 01:35:38 2010 From: astan.chee at gmail.com (Astan Chee) Date: Sat, 11 Dec 2010 17:35:38 +1100 Subject: run a function in another processor in python In-Reply-To: References: <4D00B416.5090509@sequans.com> Message-ID: Sorry about that, here is a summary of my complete code. I haven't cleaned it up much or anything, but this is what it does: import time import multiprocessing test_constx =0 test_consty =0 def functionTester(x): global test_constx global test_consty print "constx " + str(test_constx) print "consty " + str(test_consty) return (test_constx*x[0]-x[1]+test_consty*x[0]+x[2]) def functionTesterMain(constx,consty): global test_constx global test_consty test_constx = constx test_consty = consty num_args = [(61,12,1),(61,12,2),(61,12,3),(61,11,4),(61,12,4),(62,33,4),(7,12,4),(16,19,4),(35,36,4),(37,38,3),(55,56,3),(57,63,3)] num_processes = multiprocessing.cpu_count() pool = multiprocessing.Pool(num_processes) rs = [] start = time.time() rs = pool.map(functionTester,num_args) end = time.time() elapsed= end - start min = elapsed/60 print "Took", elapsed, "seconds to run, which is the same as", min, "minutes" pos = 0 high = 0 n = None for r in rs: if r > high: n = num_args[pos] high = r pos+=1 print "high " + str(high) print "n " + str(n) return high,n if __name__ == '__main__': for i in range(1,4): a,b = functionTesterMain(i,7) print "-----------" print "a " + str(a) print "b " + str(a) Which doesn't seem to work because the functionTester() needs to be simpler and not use global variables. I'm using global variables because I'm also trying to pass a few other variables and I tried using a class but that just gave me a unpickleable error. I tried using zip but I'm confused with how I can get to pass the data. I know I can probably combine the data into tuples but that means that there is alot of data duplication, especially if the constx and consty are large dictionaries (or even custom objects), which might happen later. So it seems that map doesn't quite like functions like these. Anyway, I'll try and see if threads or something can substitute. I'd appriciate any help. Thanks On Sat, Dec 11, 2010 at 9:04 AM, geremy condra wrote: > On Fri, Dec 10, 2010 at 4:42 AM, Astan Chee wrote: > > On Fri, Dec 10, 2010 at 1:37 AM, Peter Otten <__peter__ at web.de> wrote: > >> > >> I can't replicate the crash. However, your problem looks like there is a > >> ready-to-use solution: > >> > >> > >> > http://docs.python.org/library/multiprocessing.html#using-a-pool-of-workers > >> > >> -- > >> http://mail.python.org/mailman/listinfo/python-list > > > > > > Pool.map doesn't seem to be able to support multiple argument functions > > which is what I'm trying to do here. Any other suggestions? > > Thanks again > > 1. Post the real code you're using, and > 2. Put the arguments you want in a tuple and pass that. As an example, > let's say I have the following function: > > def my_func(x, y, z): > return x + y * z > > you could rewrite this as: > > def my_func(*args): > return args[0] + args[1] * args[2] > > > Here's a worked-out example: > > #! /usr/bin/env python3 > > import multiprocessing > > def my_func(x, y, z): > return x + y * z > > def my_func_wrapper(t): > return my_func(*t) > > # assume we can get an iterable over each argument > xs = [1, 2, 3, 4] > ys = [5, 6, 7, 8] > zs = [9, 1, 2, 3] > > # set up the pool to match the number of CPUs > num_processes = multiprocessing.cpu_count() > pool = multiprocessing.Pool(num_processes) > > #will call my_func(1, 5, 9), my_func(2, 6, 1), etc. > results = pool.map(my_func_wrapper, zip(xs, ys, zs)) > print(results) > > > Interesting factoid: you can't seem to use lambda or a decorator to do > this, which would have been my first instinct. Pickle apparently > chokes, although marshall wouldn't. > > Geremy Condra > -------------- next part -------------- An HTML attachment was scrubbed... URL: From orasnita at gmail.com Sat Dec 11 04:17:53 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Sat, 11 Dec 2010 11:17:53 +0200 Subject: Python critique References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com><4d028748$0$1621$742ec2ed@news.sonic.net> <4d02b47b$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52430F724D9B40DFB856FCDD172C28C8@teddy> From: "Steven D'Aprano" ... >> Can you please tell me how to write the following program in Python? >> >> my $n = 1; >> >> { >> my $n = 2; >> print "$n\n"; >> } >> >> print "$n\n"; >> >> If this program if ran in Perl, it prints: >> 2 >> 1 > > Lots of ways. Here's one: > > > n = 1 > > class Scope: > n = 2 > print n > > print n > > > > Here's another: > > n = 1 > print (lambda n=2: n)() > print n > > > > Here's a third: > > n = 1 > > def scope(): > n = 2 > print n > > scope() > print n > > > Here's a fourth: > > import sys > n = 1 > (sys.stdout.write("%d\n" % n) for n in (2,)).next() > print n > > > In Python 3, this can be written more simply: > > n = 1 > [print(n) for n in (2,)] > print n > > > >> I have tried to write it, but I don't know how I can create that block >> because it tells that there is an unexpected indent. > > Functions, closures, classes and modules are scopes in Python. If you > want a new scope, create one of those. > > > > -- > Steven Hi Steven, Thank you for your message. It is very helpful for me. I don't fully understand the syntax of all these variants yet, but I can see that there are more scopes in Python than I thought, and this is very good. Octavian From __peter__ at web.de Sat Dec 11 05:33:34 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 11 Dec 2010 11:33:34 +0100 Subject: run a function in another processor in python References: <4D00B416.5090509@sequans.com> Message-ID: Astan Chee wrote: > Sorry about that, here is a summary of my complete code. I haven't cleaned > it up much or anything, but this is what it does: > > import time > import multiprocessing > > test_constx =0 > test_consty =0 > > def functionTester(x): > global test_constx You don't need to declare a variable as global unless you want to rebind (assign to) it. > global test_consty > print "constx " + str(test_constx) > print "consty " + str(test_consty) > return (test_constx*x[0]-x[1]+test_consty*x[0]+x[2]) > > def functionTesterMain(constx,consty): > global test_constx > global test_consty > test_constx = constx > test_consty = consty > num_args = > [(61,12,1),(61,12,2),(61,12,3),(61,11,4),(61,12,4),(62,33,4),(7,12,4), (16,19,4),(35,36,4),(37,38,3),(55,56,3),(57,63,3)] > num_processes = multiprocessing.cpu_count() > pool = multiprocessing.Pool(num_processes) I think you need to create the pool outside the function; in the current configuration you get three not one Pool instance. > rs = [] > start = time.time() > rs = pool.map(functionTester,num_args) > end = time.time() > elapsed= end - start > min = elapsed/60 > print "Took", elapsed, "seconds to run, which is the same as", min, > "minutes" > pos = 0 > high = 0 > n = None > for r in rs: > if r > high: > n = num_args[pos] > high = r > pos+=1 > print "high " + str(high) > print "n " + str(n) > > return high,n > > if __name__ == '__main__': > for i in range(1,4): > a,b = functionTesterMain(i,7) > print "-----------" > print "a " + str(a) > print "b " + str(a) > > > Which doesn't seem to work because the functionTester() needs to be > simpler and not use global variables. > I'm using global variables because I'm also trying to pass a few other > variables and I tried using a class but that just gave me a unpickleable > error. I tried using zip but I'm confused with how I can get to pass the > data. A simple approach would be to pass an index into a list const_data = zip(range(1, 4), [7]*3) > I know I can probably combine the data into tuples but that means that > there is alot of data duplication, especially if the constx and consty are > large dictionaries (or even custom objects), which might happen later. > So it seems that map doesn't quite like functions like these. Anyway, I'll > try and see if threads or something can substitute. I'd appriciate any help. Thanks Your code, slightly modified and cleaned up (yes, four-space indent improves readability): import time import multiprocessing const_data = zip(range(1, 4), [7]*3) num_args = [(61, 12, 1), (61, 12, 2), (61, 12, 3), (61, 11, 4), (61, 12, 4), (62, 33, 4), (7, 12, 4), (16, 19, 4), (35, 36, 4), (37, 38, 3), (55, 56, 3), (57, 63, 3)] def functionTester(args): i, x, y, z = args constx, consty = const_data[i] print "constx", constx print "consty", consty return constx*x - y + consty*x + z def functionTesterMain(pool, index): start = time.time() rs = pool.map(functionTester, (((index, ) + x) for x in num_args)) end = time.time() elapsed = end - start min = elapsed/60 print "Took", elapsed, print "seconds to run, which is the same as", min, "minutes" return max(zip(rs, num_args)) if __name__ == '__main__': num_processes = multiprocessing.cpu_count() pool = multiprocessing.Pool(num_processes) for i, _ in enumerate(const_data): a, b = functionTesterMain(pool, i) print "-----------" print "a", a print "b", b From bavishi.darshak at gmail.com Sat Dec 11 06:20:35 2010 From: bavishi.darshak at gmail.com (Darshak Bavishi) Date: Sat, 11 Dec 2010 16:50:35 +0530 Subject: how to read o/p of telenet (python) ?! Message-ID: hi experts , i have code to telnet remote machine (unix) i am using port 5400 to telnet but o/p is not in visible format when i run random commands or run when i give as read_some() it displays some lines but in case of read_all() it gets hang !! In actual i want to get some string from o/p and process pls help [code] import getpass import sys import telnetlib import time HOST = "hostname" #user = raw_input("Enter your remote account: ") #password = getpass.getpass() user = "hostname" password = "ABC" tn = telnetlib.Telnet(HOST , 5400) print "1" print "2" tn.write(user + "\n") print "3" if password: tn.read_until("Password: ") tn.write(password + "\n") print "4" tn.write("set alarm = off" + "\n") tn.write("set event = off" + "\n") print "5" tn.write("Cd /Office-Parameters/" + "\n") print "6" tn.write("\n") tn.write("\n") tn.write("vlrsubquery msisdn=*******" + "\n") tn.write("\n") print tn.read_all() tn.write("exit" + "\n") tn.close() -- BR Darshak Bavishi -------------- next part -------------- An HTML attachment was scrubbed... URL: From lie.1296 at gmail.com Sat Dec 11 06:46:16 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 11 Dec 2010 22:46:16 +1100 Subject: Python critique In-Reply-To: References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> <4d028748$0$1621$742ec2ed@news.sonic.net> <499F3F3D16A34734B5D195F91EB58520@teddy> <4d02bcf2$0$1624$742ec2ed@news.sonic.net> Message-ID: <4d036383$1@dnews.tpgi.com.au> On 12/11/10 11:37, Dan Stromberg wrote: > On Fri, Dec 10, 2010 at 3:51 PM, John Nagle wrote: >> On 12/10/2010 3:25 PM, Stefan Behnel wrote: >>> Benjamin Kaplan, 11.12.2010 00:13: >>>> On Fri, Dec 10, 2010 at 5:46 PM, Octavian Rasnita wrote: >>>> The only scopes Python has are module and function. >> >> There's more. Both a lambda, and in Python 3.x, >> list comprehensions, introduce a new scope. > > And classes and methods. Also, class scope and instance scope, though similar, are distinct scopes. Python also have the hidden interpreter-level scope (the __builtins__). From orasnita at gmail.com Sat Dec 11 07:43:33 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Sat, 11 Dec 2010 14:43:33 +0200 Subject: Python distribution recommendation? Message-ID: Hi, Is there a "recommended" Python distribution for Windows XP? I know about the one that can be downloaded from python.org (which I am using for the moment) and the one offered by ActiveState but I don't know which one is better for a beginner nor if there are other distributions available. I am especially interested in creating MS Windows apps with Python. Thanks. Octavian From katie at coderstack.co.uk Sat Dec 11 08:08:53 2010 From: katie at coderstack.co.uk (Katie T) Date: Sat, 11 Dec 2010 13:08:53 +0000 Subject: Python distribution recommendation? In-Reply-To: References: Message-ID: On Sat, Dec 11, 2010 at 12:43 PM, Octavian Rasnita wrote: > Hi, > > Is there a "recommended" Python distribution for Windows XP? Either will work, although the python.org one is the more popular and is likely the one used by most tutorials and beginners guides. The ActiveState one bundles PyQT if you want to build apps with GUIs using QT (although it's fairly trivial to install with the regular Python as well). Katie -- CoderStack http://www.coderstack.co.uk The Software Developer Job Board From lie.1296 at gmail.com Sat Dec 11 08:59:46 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 12 Dec 2010 00:59:46 +1100 Subject: Python distribution recommendation? In-Reply-To: References: Message-ID: <4d0382cd$1@dnews.tpgi.com.au> On 12/11/10 23:43, Octavian Rasnita wrote: > Hi, > > Is there a "recommended" Python distribution for Windows XP? > > I know about the one that can be downloaded from python.org (which I am using for the moment) and the one offered by ActiveState but I don't know which one is better for a beginner nor if there are other distributions available. > > I am especially interested in creating MS Windows apps with Python. > ActiveState comes with more third party libraries, if you're developing python and do not want to install those libraries yourself, they're the way to go to. However, if you only need to use standard libraries, or want to target the broadest possible platforms with very little dependencies, then you should use python.org's version. From godson.g at gmail.com Sat Dec 11 09:02:21 2010 From: godson.g at gmail.com (Godson Gera) Date: Sat, 11 Dec 2010 19:32:21 +0530 Subject: Python distribution recommendation? In-Reply-To: References: Message-ID: On Sat, Dec 11, 2010 at 6:13 PM, Octavian Rasnita wrote: > > > I am especially interested in creating MS Windows apps with Python. > If you want to access win32api and do some COM programming then ActiveState comes bundled with pywin32. Where in vanilla python distro you have to install those packages separately by downloading them. ActiveState is the same python with additional batteries included. -- Python Consultant India -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Sat Dec 11 09:24:54 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 11 Dec 2010 09:24:54 -0500 Subject: instance has no __call__ method In-Reply-To: References: Message-ID: <4D0389B6.3020405@holdenweb.com> On 12/10/2010 5:20 AM, frank cui wrote: > Hi all, > > I'm a novice learner of python and get caught in the following trouble > and hope experienced users can help me solve it:) > > Code: > ----------------------------------------------------------------------- > $ cat Muffle_ZeroDivision.py > #!/usr/bin/env python > > class MuffledCalculator: > muffled = False > def clac(self,expr): > try: > return eval(expr) > except: > if self.muffled: > print 'Division by zero is illegal' > else: > raise > -------------------------------------------------------------------------- > > $ python > Python 2.7 (r27:82500, Sep 16 2010, 18:03:06) > [GCC 4.5.1 20100907 (Red Hat 4.5.1-3)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import Muffle_ZeroDivision >>>> calc = Muffle_ZeroDivision.MuffledCalculator() >>>> calc = ('10/2') >>>> calc = Muffle_ZeroDivision.MuffledCalculator() >>>> calc('10/2') > Traceback (most recent call last): > File "", line 1, in > AttributeError: MuffledCalculator instance has no __call__ method > > ---------------------------------------------------------------------------- > > There is an AttributeError that this instance doesn't have the __call__ > method, so how to add this kind of method to my instance? > > Thanks a lot in advance. > > Regards > Frank.Cui > Try renaming your .calc() method to .__call__(). That way the method will be called when you perform a function call on an instance. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sat Dec 11 09:24:54 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 11 Dec 2010 09:24:54 -0500 Subject: instance has no __call__ method In-Reply-To: References: Message-ID: <4D0389B6.3020405@holdenweb.com> On 12/10/2010 5:20 AM, frank cui wrote: > Hi all, > > I'm a novice learner of python and get caught in the following trouble > and hope experienced users can help me solve it:) > > Code: > ----------------------------------------------------------------------- > $ cat Muffle_ZeroDivision.py > #!/usr/bin/env python > > class MuffledCalculator: > muffled = False > def clac(self,expr): > try: > return eval(expr) > except: > if self.muffled: > print 'Division by zero is illegal' > else: > raise > -------------------------------------------------------------------------- > > $ python > Python 2.7 (r27:82500, Sep 16 2010, 18:03:06) > [GCC 4.5.1 20100907 (Red Hat 4.5.1-3)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import Muffle_ZeroDivision >>>> calc = Muffle_ZeroDivision.MuffledCalculator() >>>> calc = ('10/2') >>>> calc = Muffle_ZeroDivision.MuffledCalculator() >>>> calc('10/2') > Traceback (most recent call last): > File "", line 1, in > AttributeError: MuffledCalculator instance has no __call__ method > > ---------------------------------------------------------------------------- > > There is an AttributeError that this instance doesn't have the __call__ > method, so how to add this kind of method to my instance? > > Thanks a lot in advance. > > Regards > Frank.Cui > Try renaming your .calc() method to .__call__(). That way the method will be called when you perform a function call on an instance. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From orasnita at gmail.com Sat Dec 11 09:31:04 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Sat, 11 Dec 2010 16:31:04 +0200 Subject: Python distribution recommendation? References: Message-ID: <16E90EF945B946F39CF1EA5836F024DA@teddy> Ok, thank you all for your recommendations. I think I will install ActivePython because it seems that it offers more features for Windows programming than the other distro (by default, which is important for a beginner). I will use WxPython and not other GUIS like QT, Tk or GTK because they are not accessible for screen readers, so I will also need to install WxPython if ActiveState's Python doesn't include it. Octavian ----- Original Message ----- From: "Godson Gera" To: "Octavian Rasnita" Cc: Sent: Saturday, December 11, 2010 4:02 PM Subject: Re: Python distribution recommendation? > On Sat, Dec 11, 2010 at 6:13 PM, Octavian Rasnita wrote: > >> >> >> I am especially interested in creating MS Windows apps with Python. >> > > If you want to access win32api and do some COM programming then ActiveState > comes bundled with pywin32. Where in vanilla python distro you have to > install those packages separately by downloading them. ActiveState is the > same python with additional batteries included. > > -- > Python Consultant India > From steve+comp.lang.python at pearwood.info Sat Dec 11 09:32:03 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Dec 2010 14:32:03 GMT Subject: Integrating doctest with unittest Message-ID: <4d038b63$0$30000$c3e8da3$5496439d@news.astraweb.com> I have a module with doctests, and a module that performs unit testing for it. The test module looks like this: import doctest import unittest import module_to_test # ... # many test suites # ... if __name__ == '__main__': doctest.testmod(module_to_test) unittest.main() but now I'd like to integrate the doctests with the unittests. I thought I could follow the instructions here: http://docs.python.org/py3k/library/doctest.html#unittest-api so I added a line: doc_test_suite = doctest.DocTestSuite(module=module_to_test) expecting that it would be found by unittest.main(), but it is not. I imagine this is because DocTestSuite returns a TestSuite instance, while the unittest test finder only looks for classes. I realise that I could manually run the doc_test_suite with this: unittest.TextTestRunner().run(doc_test_suite) but this leads to two test outputs: Ran 100 tests in 3.037s OK Ran 10 tests in 0.012s OK instead of combining them: Ran 110 tests in 3.049s OK Is there a way to have unittest.main() find and run doc_test_suite together with the other test suites? -- Steven From steve at holdenweb.com Sat Dec 11 09:32:39 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 11 Dec 2010 09:32:39 -0500 Subject: 64 bit memory usage In-Reply-To: References: <4d015be7$0$1670$742ec2ed@news.sonic.net> Message-ID: <4D038B87.7050601@holdenweb.com> On 12/10/2010 2:03 PM, Rob Randall wrote: > I manged to get my python app past 3GB on a smaller 64 bit machine. > On a test to check memory usage with gc disabled only an extra 6MB was > used. > The figures were 1693MB to 1687MB. > > This is great. > > Thanks again for the help. Do remember, though, that with the GC turned off you will "lose" memory if you accidentally create cyclic data structures, since they will never be reclaimed. It doesn't sound like this is an issue, but I wanted this to act as a warning to others who might come across your solution but have programmed less carefully. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sat Dec 11 09:32:39 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 11 Dec 2010 09:32:39 -0500 Subject: 64 bit memory usage In-Reply-To: References: <4d015be7$0$1670$742ec2ed@news.sonic.net> Message-ID: <4D038B87.7050601@holdenweb.com> On 12/10/2010 2:03 PM, Rob Randall wrote: > I manged to get my python app past 3GB on a smaller 64 bit machine. > On a test to check memory usage with gc disabled only an extra 6MB was > used. > The figures were 1693MB to 1687MB. > > This is great. > > Thanks again for the help. Do remember, though, that with the GC turned off you will "lose" memory if you accidentally create cyclic data structures, since they will never be reclaimed. It doesn't sound like this is an issue, but I wanted this to act as a warning to others who might come across your solution but have programmed less carefully. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From martin.kaspar at campus-24.com Sat Dec 11 11:24:26 2010 From: martin.kaspar at campus-24.com (Martin Kaspar) Date: Sat, 11 Dec 2010 08:24:26 -0800 (PST) Subject: python-parser running Beautiful Soup needs to be reviewed Message-ID: <3dcf2ff3-1b23-4dd8-a719-d1647a1a051e@o4g2000yqd.googlegroups.com> Hello commnity i am new to Python and to Beatiful Soup also! It is told to be a great tool to parse and extract content. So here i am...: I want to take the content of a -tag of a table in a html document. For example, i have this table
This is a sample text This is the second sample text
How can i use beautifulsoup to take the text "This is a sample text"? Should i make use soup.findAll('table' ,attrs={'class':'bp_ergebnis_tab_info'}) to get the whole table. See the target http://www.schulministerium.nrw.de/BP/SchuleSuchen?action=799.601437941842&SchulAdresseMapDO=142323 Well - what have we to do first: The first thing is t o find the table: i do this with Using find rather than findall returns the first item in the list (rather than returning a list of all finds - in which case we'd have to add an extra [0] to take the first element of the list): table = soup.find('table' ,attrs={'class':'bp_ergebnis_tab_info'}) Then use find again to find the first td: first_td = soup.find('td') Then we have to use renderContents() to extract the textual contents: text = first_td.renderContents() ... and the job is done (though we may also want to use strip() to remove leading and trailing spaces: trimmed_text = text.strip() This should give us: print trimmed_text This is a sample text as desired. What do you think about the code? I love to hear from you!? greetings matze From nitinpawar432 at gmail.com Sat Dec 11 11:31:09 2010 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Sat, 11 Dec 2010 11:31:09 -0500 Subject: python-parser running Beautiful Soup needs to be reviewed In-Reply-To: <3dcf2ff3-1b23-4dd8-a719-d1647a1a051e@o4g2000yqd.googlegroups.com> References: <3dcf2ff3-1b23-4dd8-a719-d1647a1a051e@o4g2000yqd.googlegroups.com> Message-ID: try using lxml ... its very useful On Sat, Dec 11, 2010 at 11:24 AM, Martin Kaspar wrote: > Hello commnity > > i am new to Python and to Beatiful Soup also! > It is told to be a great tool to parse and extract content. So here i > am...: > > I want to take the content of a -tag of a table in a html > document. For example, i have this table > > > > > > > >
> This is a sample text > > This is the second sample text >
> > How can i use beautifulsoup to take the text "This is a sample text"? > > Should i make use > soup.findAll('table' ,attrs={'class':'bp_ergebnis_tab_info'}) to get > the whole table. > > See the target > http://www.schulministerium.nrw.de/BP/SchuleSuchen?action=799.601437941842&SchulAdresseMapDO=142323 > > Well - what have we to do first: > > The first thing is t o find the table: > > i do this with Using find rather than findall returns the first item > in the list > (rather than returning a list of all finds - in which case we'd have > to add an extra [0] > to take the first element of the list): > > > table = soup.find('table' ,attrs={'class':'bp_ergebnis_tab_info'}) > > Then use find again to find the first td: > > first_td = soup.find('td') > > Then we have to use renderContents() to extract the textual contents: > > text = first_td.renderContents() > > ... and the job is done (though we may also want to use strip() to > remove leading and trailing spaces: > > trimmed_text = text.strip() > > This should give us: > > > print trimmed_text > This is a sample text > > as desired. > > > What do you think about the code? I love to hear from you!? > > greetings > matze > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From roy at panix.com Sat Dec 11 12:04:01 2010 From: roy at panix.com (Roy Smith) Date: Sat, 11 Dec 2010 12:04:01 -0500 Subject: Making os.unlink() act like "rm -f" Message-ID: I just wrote an annoying little piece of code: try: os.unlink("file") except OSError: pass The point being I want to make sure the file is gone, but am not sure if it exists currently. Essentially, I want to do what "rm -f" does in the unix shell. In fact, what I did doesn't even do that. By catching OSError, I catch "No such file or directory" (which is what I want), but I also catch lots of things I want to know about, like "Permission denied". I could do: if os.access("file", os.F_OK): os.unlink("file") but that's annoying too. What would people think about a patch to os.unlink() to add an optional second parameter which says to ignore attempts to remove non-existent files (just like "rm -f")? Then you could do: os.unlink("file", ignore=True) From lists at cheimes.de Sat Dec 11 12:25:14 2010 From: lists at cheimes.de (Christian Heimes) Date: Sat, 11 Dec 2010 18:25:14 +0100 Subject: Making os.unlink() act like "rm -f" In-Reply-To: References: Message-ID: Am 11.12.2010 18:04, schrieb Roy Smith: > if os.access("file", os.F_OK): > os.unlink("file") > > but that's annoying too. What would people think about a patch to > os.unlink() to add an optional second parameter which says to ignore > attempts to remove non-existent files (just like "rm -f")? Then you > could do: -1 os.unlink is a small wrapper around the unlink(2) function. You want to ignore the ENOENT error number and re-raise the exception for other errors: try: os.unlink("file") except OSError, e: if e.errno != errno.ENOENT: raise You may be interested in EISDIR, too. unlink() doesn't remove directories. Christian From nobody at nowhere.com Sat Dec 11 12:25:20 2010 From: nobody at nowhere.com (Nobody) Date: Sat, 11 Dec 2010 17:25:20 +0000 Subject: Making os.unlink() act like "rm -f" References: Message-ID: On Sat, 11 Dec 2010 12:04:01 -0500, Roy Smith wrote: > I just wrote an annoying little piece of code: > > try: > os.unlink("file") > except OSError: > pass > > The point being I want to make sure the file is gone, but am not sure if > it exists currently. Essentially, I want to do what "rm -f" does in the > unix shell. > > In fact, what I did doesn't even do that. By catching OSError, I catch > "No such file or directory" (which is what I want), but I also catch lots > of things I want to know about, like "Permission denied". import errno try: os.unlink("file") except OSError as e: if e.errno != errno.ENOENT: raise > I could do: > > if os.access("file", os.F_OK): > os.unlink("file") > > but that's annoying too. It also has a race condition. EAFP is the right approach here. From godson.g at gmail.com Sat Dec 11 12:31:11 2010 From: godson.g at gmail.com (Godson Gera) Date: Sat, 11 Dec 2010 23:01:11 +0530 Subject: Making os.unlink() act like "rm -f" In-Reply-To: References: Message-ID: On Sat, Dec 11, 2010 at 10:34 PM, Roy Smith wrote: > os.unlink("file", ignore=True) > -- > http://mail.python.org/mailman/listinfo/python-list > Take a look at shutil.rmtree http://docs.python.org/library/shutil.html?highlight=shutil#shutil.rmtree -- Thanks & Regards, Godson Gera Python Consultant India -------------- next part -------------- An HTML attachment was scrubbed... URL: From perry at nomail.net.invalid Sat Dec 11 12:33:15 2010 From: perry at nomail.net.invalid (Perry Johnson) Date: Sat, 11 Dec 2010 17:33:15 +0000 (UTC) Subject: Enabling the use of POSIX character classes in Python Message-ID: Python's re module does not support POSIX character classes, for example [:alpha:]. It is, of course, trivial to simulate them using character ranges when the text to be matched uses the ASCII character set. Sadly, my problem is that I need to process Unicode text. The re module has its own character classes that do support Unicode, however they are not sufficient. I would find it extremely useful if there was information on the Unicode code points that map to each of the POSIX character classes. From ian.g.kelly at gmail.com Sat Dec 11 12:44:04 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 11 Dec 2010 10:44:04 -0700 Subject: how to read o/p of telenet (python) ?! In-Reply-To: References: Message-ID: On 12/11/2010 4:20 AM, Darshak Bavishi wrote: > i have code to telnet remote machine (unix) > i am using port 5400 to telnet but o/p is not in visible format when i > run random commands or run What is "o/p"? > when i give as read_some() it displays some lines but in case of > read_all() it gets hang !! read_all() blocks until the server closes the connection. If the server is waiting for a command, then it will be blocking for a long time. Try sending the "exit" command before you call read_all(). The server should finish processing the previous command before exiting, so you will still receive all of the requested data. Cheers, Ian From martin at v.loewis.de Sat Dec 11 12:55:42 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sat, 11 Dec 2010 18:55:42 +0100 Subject: Enabling the use of POSIX character classes in Python In-Reply-To: References: Message-ID: Am 11.12.2010 18:33, schrieb Perry Johnson: > Python's re module does not support POSIX character classes, for > example [:alpha:]. It is, of course, trivial to simulate them using > character ranges when the text to be matched uses the ASCII character > set. Sadly, my problem is that I need to process Unicode text. The re > module has its own character classes that do support Unicode, however > they are not sufficient. > > I would find it extremely useful if there was information on the > Unicode code points that map to each of the POSIX character classes. By definition, this is not possible. The POSIX character classes are locale-dependent, whereas the recommendation for Unicode regular expressions is that they are not (i.e. a Unicode regex character class should refer to the same characters independent from the locale). If you want to construct locale-dependent Unicode character classes, you should use this procedure: - iterate over all byte values (0..255) - perform the relevant locale-specific tests - decode each byte into Unicode, using the locale's encoding - construct a character class out of that Unfortunately, that will work only for single-byte encodings. I'm not aware of a procedure that does that for multi-byte strings. But perhaps you didn't mean "POSIX character class" in this literal way. Regards, Martin From python at mrabarnett.plus.com Sat Dec 11 12:58:06 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 11 Dec 2010 17:58:06 +0000 Subject: Enabling the use of POSIX character classes in Python In-Reply-To: References: Message-ID: <4D03BBAE.9080106@mrabarnett.plus.com> On 11/12/2010 17:33, Perry Johnson wrote: > Python's re module does not support POSIX character classes, for > example [:alpha:]. It is, of course, trivial to simulate them using > character ranges when the text to be matched uses the ASCII character > set. Sadly, my problem is that I need to process Unicode text. The re > module has its own character classes that do support Unicode, however > they are not sufficient. > > I would find it extremely useful if there was information on the > Unicode code points that map to each of the POSIX character classes. Have a look at the new regex implementation on PyPI: http://pypi.python.org/pypi/regex From python at mrabarnett.plus.com Sat Dec 11 13:01:56 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 11 Dec 2010 18:01:56 +0000 Subject: how to read o/p of telenet (python) ?! In-Reply-To: References: Message-ID: <4D03BC94.2090402@mrabarnett.plus.com> On 11/12/2010 17:44, Ian Kelly wrote: > On 12/11/2010 4:20 AM, Darshak Bavishi wrote: >> i have code to telnet remote machine (unix) >> i am using port 5400 to telnet but o/p is not in visible format when i >> run random commands or run > > What is "o/p"? > [snip] "o/p" is an abbreviation for "output" (and "i/p" is abbreviation for "input"). From mrjean1 at gmail.com Sat Dec 11 13:59:14 2010 From: mrjean1 at gmail.com (MrJean1) Date: Sat, 11 Dec 2010 10:59:14 -0800 (PST) Subject: ctypes question References: <2abdd9b3-66ec-4125-a5f8-41315008cccc@l17g2000yqe.googlegroups.com> Message-ID: <7e4306de-b95a-40c8-9c9c-10745d8dc793@z19g2000yqb.googlegroups.com> It is not entirely clear what the functions and especially what their signatures are in that C library clibsmi. In general, for shared libraries, you need to define those first as prototype using ctypes.CFUNCTYPE() and then instantiate each prototype once supplying the necessary parameter flags using prototype(func_spec, tuple_of_param_flags). See sections 15.16.2.3 and 4 of the ctypes docs*. Take a look the Python bindings** for the VLC library, the file called vlc.py***. The function _Cfunction is used to create the Python callable for each C function in that VLC library. All the Python callables are in the second half of the vlc.py file, starting at line 2600. Hope this helps, /Jean *) **) ***) On Dec 10, 3:32?pm, News Wombat wrote: > Hi everyone, > > I've been experimenting with the ctypes module and think it's great. > I'm hitting a few snags though with seg faults. ?I attached two links > that holds the code. ?The line i'm having problems with is this, > > sn=clibsmi.smiGetNextNode(pointer(sno),SMI_NODEKIND_ANY) > > It will work one time, and if I call it again with the result of the > previous, even though the result (a c struct) looks ok, it will > segfault. ?I think it's a problem with pointers or maybe the function > in the c library trying to change a string that python won't let it > change. ?I'm stuck, any tips would be appreciated. ?Thanks, and Merry > Christmas! > > constants.py:http://pastebin.com/HvngjzZN > libsmi.py:http://pastebin.com/19C9kYEa From mpnordland at gmail.com Sat Dec 11 14:43:13 2010 From: mpnordland at gmail.com (mpnordland) Date: Sat, 11 Dec 2010 11:43:13 -0800 (PST) Subject: Catching user switching and getting current active user from root on linux References: <1a9bdbd4-2997-4e0f-a24f-cd148247e312@r40g2000prh.googlegroups.com> <8739qhs6dz.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <797ba948-c608-4ed5-b2eb-25177932da91@o4g2000yqd.googlegroups.com> sorry, I've been busy, it's on linux, and current active user is the user currently using the computer. My program needs to switch log files when a different user starts using the computer. From mpnordland at gmail.com Sat Dec 11 14:51:18 2010 From: mpnordland at gmail.com (mpnordland) Date: Sat, 11 Dec 2010 11:51:18 -0800 (PST) Subject: Catching user switching and getting current active user from root on linux References: <1a9bdbd4-2997-4e0f-a24f-cd148247e312@r40g2000prh.googlegroups.com> <8739qhs6dz.fsf.mdw@metalzone.distorted.org.uk> <797ba948-c608-4ed5-b2eb-25177932da91@o4g2000yqd.googlegroups.com> Message-ID: about the pyutmp, is the most recent entry at the top or bottom of the file? From steve at holdenweb.com Sat Dec 11 15:21:53 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 11 Dec 2010 15:21:53 -0500 Subject: Python critique In-Reply-To: <4d036383$1@dnews.tpgi.com.au> References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> <4d028748$0$1621$742ec2ed@news.sonic.net> <499F3F3D16A34734B5D195F91EB58520@teddy> <4d02bcf2$0$1624$742ec2ed@news.sonic.net> <4d036383$1@dnews.tpgi.com.au> Message-ID: On 12/11/2010 6:46 AM, Lie Ryan wrote: > On 12/11/10 11:37, Dan Stromberg wrote: >> On Fri, Dec 10, 2010 at 3:51 PM, John Nagle wrote: >>> On 12/10/2010 3:25 PM, Stefan Behnel wrote: >>>> Benjamin Kaplan, 11.12.2010 00:13: >>>>> On Fri, Dec 10, 2010 at 5:46 PM, Octavian Rasnita wrote: >>>>> The only scopes Python has are module and function. >>> >>> There's more. Both a lambda, and in Python 3.x, >>> list comprehensions, introduce a new scope. >> >> And classes and methods. > > Also, class scope and instance scope, though similar, are distinct > scopes. Python also have the hidden interpreter-level scope (the > __builtins__). But classes and instances don't have scopes. They have namespaces. That is, if we are talking about lexical scoping. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sat Dec 11 15:23:51 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 11 Dec 2010 15:23:51 -0500 Subject: Python critique In-Reply-To: <4d036383$1@dnews.tpgi.com.au> References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> <4d028748$0$1621$742ec2ed@news.sonic.net> <499F3F3D16A34734B5D195F91EB58520@teddy> <4d02bcf2$0$1624$742ec2ed@news.sonic.net> <4d036383$1@dnews.tpgi.com.au> Message-ID: On 12/11/2010 6:46 AM, Lie Ryan wrote: > Also, class scope and instance scope, though similar, are distinct > scopes. Python also have the hidden interpreter-level scope (the > __builtins__). Kindly ignore my last post. Class scopes are lexical, instance scopes are not. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sat Dec 11 15:31:58 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 11 Dec 2010 15:31:58 -0500 Subject: Python distribution recommendation? In-Reply-To: <16E90EF945B946F39CF1EA5836F024DA@teddy> References: <16E90EF945B946F39CF1EA5836F024DA@teddy> Message-ID: On 12/11/2010 9:31 AM, Octavian Rasnita wrote: > Ok, thank you all for your recommendations. > > I think I will install ActivePython because it seems that it offers more features for Windows programming than the other distro (by default, which is important for a beginner). > > I will use WxPython and not other GUIS like QT, Tk or GTK because they are not accessible for screen readers, so I will also need to install WxPython if ActiveState's Python doesn't include it. > I must say that wxPython has been one of the most consistently easy packages to install over the last ten years. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From roy at panix.com Sat Dec 11 15:47:09 2010 From: roy at panix.com (Roy Smith) Date: Sat, 11 Dec 2010 15:47:09 -0500 Subject: Making os.unlink() act like "rm -f" References: Message-ID: In article , Christian Heimes wrote: > Am 11.12.2010 18:04, schrieb Roy Smith: > > if os.access("file", os.F_OK): > > os.unlink("file") > > > > but that's annoying too. What would people think about a patch to > > os.unlink() to add an optional second parameter which says to ignore > > attempts to remove non-existent files (just like "rm -f")? Then you > > could do: > > -1 > > os.unlink is a small wrapper around the unlink(2) function. OK, fair enough. Perhaps a better place would be in a higher level module like shutil. It was suggested I look at shutil.rmtree(), but that only works of path is a directory. Also, the meaning of the ignore_errors flag is not quite what I'm looking for. I don't want to ignore errors, I just want "if it doesn't exist, this is a no-op". In short, exactly what "rm -r" does in the unix shell. So, maybe a new function is shutils? shutils.rm(path, force=False) Delete the file at path. If force is True, this is a no-op if path does not exist. Raises OSError if the operation fails. From python.list at tim.thechases.com Sat Dec 11 16:01:52 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 11 Dec 2010 15:01:52 -0600 Subject: Catching user switching and getting current active user from root on linux In-Reply-To: <797ba948-c608-4ed5-b2eb-25177932da91@o4g2000yqd.googlegroups.com> References: <1a9bdbd4-2997-4e0f-a24f-cd148247e312@r40g2000prh.googlegroups.com> <8739qhs6dz.fsf.mdw@metalzone.distorted.org.uk> <797ba948-c608-4ed5-b2eb-25177932da91@o4g2000yqd.googlegroups.com> Message-ID: <4D03E6C0.3000904@tim.thechases.com> On 12/11/2010 01:43 PM, mpnordland wrote: > it's on linux, and current active user is the user currently > using the computer. My program needs to switch log files when > a different user starts using the computer. The problem is that multiple users can be logged on at the same time. You might be able to come up with a solution that works for a small set of use-cases, but I admin several Linux boxes where multiple people can be logged-in at the same time. There are also some multi-head arrangements (multiple keyboards/mice/monitors and sometimes even sound-cards attached to the same motherboard) and people can log into each "terminal" (if you will) concurrently, all on the same box. So if I'm using the computer, and a co-worker logs in, I'm still using it at the same time you might catch the "new user logged in" event. Watching wtmp (or possibly /var/log/auth) can capture the "hey, somebody logged in" event, but that doesn't mean that other previous users are done with their sessions. -tkc From stef.mientki at gmail.com Sat Dec 11 16:38:43 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Sat, 11 Dec 2010 22:38:43 +0100 Subject: python-parser running Beautiful Soup needs to be reviewed In-Reply-To: <3dcf2ff3-1b23-4dd8-a719-d1647a1a051e@o4g2000yqd.googlegroups.com> References: <3dcf2ff3-1b23-4dd8-a719-d1647a1a051e@o4g2000yqd.googlegroups.com> Message-ID: <4D03EF63.4040306@gmail.com> On 11-12-2010 17:24, Martin Kaspar wrote: > Hello commnity > > i am new to Python and to Beatiful Soup also! > It is told to be a great tool to parse and extract content. So here i > am...: > > I want to take the content of a -tag of a table in a html > document. For example, i have this table > > > > > > > >
> This is a sample text > > This is the second sample text >
> > How can i use beautifulsoup to take the text "This is a sample text"? > > Should i make use > soup.findAll('table' ,attrs={'class':'bp_ergebnis_tab_info'}) to get > the whole table. > > See the target http://www.schulministerium.nrw.de/BP/SchuleSuchen?action=799.601437941842&SchulAdresseMapDO=142323 > > Well - what have we to do first: > > The first thing is t o find the table: > > i do this with Using find rather than findall returns the first item > in the list > (rather than returning a list of all finds - in which case we'd have > to add an extra [0] > to take the first element of the list): > > > table = soup.find('table' ,attrs={'class':'bp_ergebnis_tab_info'}) > > Then use find again to find the first td: > > first_td = soup.find('td') > > Then we have to use renderContents() to extract the textual contents: > > text = first_td.renderContents() > > ... and the job is done (though we may also want to use strip() to > remove leading and trailing spaces: > > trimmed_text = text.strip() > > This should give us: > > > print trimmed_text > This is a sample text > > as desired. > > > What do you think about the code? I love to hear from you!? I've no opinion. I'm just struggling with BeautifulSoup myself, finding it one of the toughest libs I've seen ;-) So the simplest solution I came up with: Text = """
This is a sample text This is the second sample text
""" Content = BeautifulSoup ( Text ) print Content.find('td').contents[0].strip() >>> This is a sample text And now I wonder how to get the next contents !! cheers, Stef > greetings > matze From ppearson at nowhere.invalid Sat Dec 11 17:13:09 2010 From: ppearson at nowhere.invalid (Peter Pearson) Date: 11 Dec 2010 22:13:09 GMT Subject: python-parser running Beautiful Soup needs to be reviewed References: <3dcf2ff3-1b23-4dd8-a719-d1647a1a051e@o4g2000yqd.googlegroups.com> Message-ID: <8mibblFbk1U1@mid.individual.net> On Sat, 11 Dec 2010 22:38:43 +0100, Stef Mientki wrote: [snip] > So the simplest solution I came up with: > > Text = """ > > > > > > >
> This is a sample text > > This is the second sample text >
> """ > Content = BeautifulSoup ( Text ) > print Content.find('td').contents[0].strip() >>>> This is a sample text > > And now I wonder how to get the next contents !! Here's a suggestion: peter at eleodes:~$ python Python 2.5.2 (r252:60911, Jul 22 2009, 15:35:03) [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from BeautifulSoup import BeautifulSoup >>> Text = """ ... ... ... ... ... ... ...
... This is a sample text ... ... This is the second sample text ...
... """ >>> Content = BeautifulSoup ( Text ) >>> for xx in Content.findAll('td'): ... print xx.contents[0].strip() ... This is a sample text This is the second sample text >>> -- To email me, substitute nowhere->spamcop, invalid->net. From alex.kapps at web.de Sat Dec 11 17:26:12 2010 From: alex.kapps at web.de (Alexander Kapps) Date: Sat, 11 Dec 2010 23:26:12 +0100 Subject: python-parser running Beautiful Soup needs to be reviewed In-Reply-To: <4D03EF63.4040306@gmail.com> References: <3dcf2ff3-1b23-4dd8-a719-d1647a1a051e@o4g2000yqd.googlegroups.com> <4D03EF63.4040306@gmail.com> Message-ID: <4D03FA84.6040605@web.de> On 11.12.2010 22:38, Stef Mientki wrote: > On 11-12-2010 17:24, Martin Kaspar wrote: >> Hello commnity >> >> i am new to Python and to Beatiful Soup also! >> It is told to be a great tool to parse and extract content. So here i >> am...: >> >> I want to take the content of a-tag of a table in a html >> document. For example, i have this table >> >> >> >> >> >> >> >>
>> This is a sample text >> >> This is the second sample text >>
>> >> How can i use beautifulsoup to take the text "This is a sample text"? >> >> Should i make use >> soup.findAll('table' ,attrs={'class':'bp_ergebnis_tab_info'}) to get >> the whole table. >> >> See the target http://www.schulministerium.nrw.de/BP/SchuleSuchen?action=799.601437941842&SchulAdresseMapDO=142323 >> >> Well - what have we to do first: >> >> The first thing is t o find the table: >> >> i do this with Using find rather than findall returns the first item >> in the list >> (rather than returning a list of all finds - in which case we'd have >> to add an extra [0] >> to take the first element of the list): >> >> >> table = soup.find('table' ,attrs={'class':'bp_ergebnis_tab_info'}) >> >> Then use find again to find the first td: >> >> first_td = soup.find('td') >> >> Then we have to use renderContents() to extract the textual contents: >> >> text = first_td.renderContents() >> >> ... and the job is done (though we may also want to use strip() to >> remove leading and trailing spaces: >> >> trimmed_text = text.strip() >> >> This should give us: >> >> >> print trimmed_text >> This is a sample text >> >> as desired. >> >> >> What do you think about the code? I love to hear from you!? > I've no opinion. > I'm just struggling with BeautifulSoup myself, finding it one of the toughest libs I've seen ;-) Really? While I'm by no means an expert, I find it very easy to work with. It's very well structured IMHO. > So the simplest solution I came up with: > > Text = """ > > > > > > >
> This is a sample text > > This is the second sample text >
> """ > Content = BeautifulSoup ( Text ) > print Content.find('td').contents[0].strip() >>>> This is a sample text > > And now I wonder how to get the next contents !! Content = BeautifulSoup ( Text ) for td in Content.findAll('td'): print td.string.strip() # or td.renderContents().strip() From usernet at ilthio.net Sat Dec 11 17:32:23 2010 From: usernet at ilthio.net (Tim Harig) Date: Sat, 11 Dec 2010 22:32:23 +0000 (UTC) Subject: Catching user switching and getting current active user from root on linux References: <1a9bdbd4-2997-4e0f-a24f-cd148247e312@r40g2000prh.googlegroups.com> <8739qhs6dz.fsf.mdw@metalzone.distorted.org.uk> <797ba948-c608-4ed5-b2eb-25177932da91@o4g2000yqd.googlegroups.com> Message-ID: Mr. Chase, I really wouldn't even bother wasting my time on this one. He asked an incomplete question to start with; so, the replies that he received were insufficient to solve his problem. He still has not provided enough information to know how to answer his question propery. He doesn't understand a sacastic reply when he hears one, he doesn't understand the concept of a multi-user operating system, and he doesn't understand the concept of how usenet threads work. Until he demonstrates some intelligence, I would say that he has flunked the Turing test. From th3flyboy at gmail.com Sat Dec 11 17:41:00 2010 From: th3flyboy at gmail.com (Peter C.) Date: Sat, 11 Dec 2010 14:41:00 -0800 (PST) Subject: Bind C++ program for use with both Python 2.x and 3.x Message-ID: Hello, I am looking at the possibility of making a program in C++. The catch is it will require the ability to work with binding for use with scripting in both Python 2.x and 3.x for various tool plugins. Is there any way to bind a C++ app to work with both Python 2.x and 3.x using the Python C API? Note if I could I'd just do Python 3, however I need Python 2 support to allow for the use of this application as a plugin in apps that use Python 2 as well. From martin at v.loewis.de Sat Dec 11 18:03:31 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sun, 12 Dec 2010 00:03:31 +0100 Subject: Bind C++ program for use with both Python 2.x and 3.x In-Reply-To: References: Message-ID: <4D040343.6040600@v.loewis.de> Am 11.12.2010 23:41, schrieb Peter C.: > Hello, I am looking at the possibility of making a program in C++. The > catch is it will require the ability to work with binding for use with > scripting in both Python 2.x and 3.x for various tool plugins. Is > there any way to bind a C++ app to work with both Python 2.x and 3.x > using the Python C API? Note if I could I'd just do Python 3, however > I need Python 2 support to allow for the use of this application as a > plugin in apps that use Python 2 as well. Notice that binding to Python 2 may not be enough: you also need to specify the Python 2 version (i.e. different bindings for 2.5, 2.6, and 2.7, say). You will have to ship different copies of the binding. Of course, you can ship them in a single distribution (zip file, or whatever your distribution format is). If you are creating different copies of the binding, supporting both 2.x and 3.x simultaneously will be straight-forward. Regards, Martin From perry at nomail.net.invalid Sat Dec 11 18:23:43 2010 From: perry at nomail.net.invalid (Perry Johnson) Date: Sat, 11 Dec 2010 23:23:43 +0000 (UTC) Subject: Enabling the use of POSIX character classes in Python References: Message-ID: On 2010-12-11, MRAB wrote: > On 11/12/2010 17:33, Perry Johnson wrote: >> Python's re module does not support POSIX character classes, for >> example [:alpha:]. It is, of course, trivial to simulate them using >> character ranges when the text to be matched uses the ASCII character >> set. Sadly, my problem is that I need to process Unicode text. The re >> module has its own character classes that do support Unicode, however >> they are not sufficient. >> >> I would find it extremely useful if there was information on the >> Unicode code points that map to each of the POSIX character classes. > > Have a look at the new regex implementation on PyPI: > > http://pypi.python.org/pypi/regex This is exactly what I needed! Thanks! From martin.schoon at gmail.com Sat Dec 11 18:32:14 2010 From: martin.schoon at gmail.com (Martin Schoeoen) Date: 11 Dec 2010 23:32:14 GMT Subject: Ways of accessing this mailing list? References: <871v7050b0.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <8mifvuF424U1@mid.individual.net> On 2010-11-04, Mark Wooding wrote: > John Bond writes: > >> Hope this isn't too O/T - I was just wondering how people read/send to >> this mailing list, eg. normal email client, gmane, some other software >> or online service? >> >> My normal inbox is getting unmanageable, and I think I need to find a >> new way of following this and other lists. > > I read and post to it as comp.lang.python. I maintain a local NNTP > server, which interacts with my ISP's news server. I read and post news > (and mail) using GNU Emacs and Gnus. > > (Interestingly, if enormous folders are your problem, Gnus can apply > news-like expiry rules to email folders.) > Same here: comp.lang.python and gnus. Well, right now I am actually trying out slrn -- a bit of a dejavu experience since I used slrn a bit in the early 1990s (and I have not used vi in many, many years). I have tried out other programs such as traditional email clients and mainstream gui programs such as Pan but find that user interface paradigm does not work well for usenet news and me. /Martin From steve+comp.lang.python at pearwood.info Sat Dec 11 19:04:11 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 Dec 2010 00:04:11 GMT Subject: Catching user switching and getting current active user from root on linux References: <1a9bdbd4-2997-4e0f-a24f-cd148247e312@r40g2000prh.googlegroups.com> <8739qhs6dz.fsf.mdw@metalzone.distorted.org.uk> <797ba948-c608-4ed5-b2eb-25177932da91@o4g2000yqd.googlegroups.com> Message-ID: <4d04117b$0$30000$c3e8da3$5496439d@news.astraweb.com> On Sat, 11 Dec 2010 11:43:13 -0800, mpnordland wrote: > sorry, I've been busy, it's on linux, and current active user is the > user currently using the computer. My program needs to switch log files > when a different user starts using the computer. I think you have missed what people are trying to tell you: if you're running Linux, you may have more than one human being logged into and using the computer AT THE SAME TIME. You can also have a single human being logged into the computer as more than one user, and one user being used by multiple human beings. As we speak, I am logged into my Linux computer eight times, five times as myself (two GUI sessions, just to prove I can do it, plus three terminals), two times as root, and one time as another user; my wife's computer has two people logged in simultaneously (me and her); I'm also logged into a server at work, which currently lists eight people logged in twenty-one times between them. Perhaps you should explain what problem you are trying to solve, rather than how you think you should solve it ("catch the user switching"). -- Steven From wander.lairson at gmail.com Sat Dec 11 20:32:20 2010 From: wander.lairson at gmail.com (wander.lairson) Date: Sat, 11 Dec 2010 23:32:20 -0200 Subject: array and strings in Python 3 Message-ID: Hello, This is my first post on python mailing list. I've working in code which must run on python 2 and python 3. I am using array.array as data buffers. I am stuck with the following code line, which works on Python 2, but not on Python 3.1.2: >>> import array >>> array.array('B', 'test') Traceback (most recent call last): File "", line 1, in TypeError: an integer is required According to Python 3 documentation (as far as I understood it), it should work. Again, no problem on Python 2. I've googled for people with similar problems, but got nothing. Does anyone have an idea what could I be doing wrong? Thanks in advance. -- Best Regards, Wander Lairson Costa LCoN - Laborat?rio de Computa??o Natural - Natural Computing Laboratory (http://www.mackenzie.com.br/lcon.html) Programa de P?s-Gradua??o em Engenharia El?trica (PPGEE) Faculdade de Computa??o e Inform?tica (FCI) Universidade Presbiteriana Mackenzie - SP - Brazil From clp2 at rebertia.com Sat Dec 11 20:48:27 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 11 Dec 2010 17:48:27 -0800 Subject: array and strings in Python 3 In-Reply-To: References: Message-ID: On Sat, Dec 11, 2010 at 5:32 PM, wander.lairson wrote: > Hello, > > This is my first post on python mailing list. I've working in code > which must run on python 2 and python 3. I am using array.array as > data buffers. I am stuck with the following code line, which works on > Python 2, but not on Python 3.1.2: > >>>> import array >>>> array.array('B', 'test') > Traceback (most recent call last): > ?File "", line 1, in > TypeError: an integer is required > > According to Python 3 documentation (as far as I understood it), it > should work. I think you forgot to keep in mind the changes in bytes vs. unicode in Python 3 when reading the docs. > Again, no problem on Python 2. I've googled for people > with similar problems, but got nothing. Does anyone have an idea what > could I be doing wrong? Recall that string handling changed incompatibly between Python 2 and Python 3. Your 'test' was a bytestring in Python 2 but is now a *Unicode string* in Python 3. The `array` module's handling of strings changed as well. Reading the Python 3 docs @ http://docs.python.org/dev/library/array.html , we find (all emphases added): class array.array(typecode[, initializer]) [...] If given a list or string, the initializer is passed to the new array?s fromlist(), frombytes(), or **fromunicode()** method (see below) to add initial items to the array. Otherwise, the iterable initializer is passed to the extend() method. [...] array.fromunicode(s) Extends this array with data from the given unicode string. The array **must be a type 'u' array**; **otherwise a ValueError is raised**. Use array.frombytes(unicodestring.encode(enc)) to append Unicode data to an array of some other type. Since your array's typecode is not 'u', you're getting a ValueError just like the docs say. Try using a bytestring instead: array.array('B', b"test") # Note the b prefix Incidentally, if you ran 2to3 over your code and weren't warned about this change in the array module, then that's probably a bug in 2to3 which ought to be reported: http://bugs.python.org Cheers, Chris -- http://blog.rebertia.com From wander.lairson at gmail.com Sat Dec 11 21:09:40 2010 From: wander.lairson at gmail.com (wander.lairson) Date: Sun, 12 Dec 2010 00:09:40 -0200 Subject: array and strings in Python 3 In-Reply-To: References: Message-ID: > The `array` module's handling of strings changed as well. Reading the > Python 3 docs @ http://docs.python.org/dev/library/array.html , we > find (all emphases added): > class array.array(typecode[, initializer]) > ? ?[...] > ? ?If given a list or string, the initializer is passed to the new > array?s fromlist(), frombytes(), or **fromunicode()** method (see > below) to add initial items to the array. Otherwise, the iterable > initializer is passed to the extend() method. > [...] > array.fromunicode(s) > ? ?Extends this array with data from the given unicode string. The > array **must be a type 'u' array**; **otherwise a ValueError is > raised**. Use array.frombytes(unicodestring.encode(enc)) to append > Unicode data to an array of some other type. > Actually I was using the 3.1 docs as reference, as it is the stable one. After your comments, I dug a bit more in the documentation and in the code, and I figured out that for unicode strings, you must pass 'u' as the first constructor parameter. > Incidentally, if you ran 2to3 over your code and weren't warned about > this change in the array module, then that's probably a bug in 2to3 > which ought to be reported: http://bugs.python.org > I am not using 2to3 because I am not converting Python 2 code to Python 3, I am writing code that must run on Python 2 and Python 3. Thank you for your help :) -- Best Regards, Wander Lairson Costa LCoN - Laborat?rio de Computa??o Natural - Natural Computing Laboratory (http://www.mackenzie.com.br/lcon.html) Programa de P?s-Gradua??o em Engenharia El?trica (PPGEE) Faculdade de Computa??o e Inform?tica (FCI) Universidade Presbiteriana Mackenzie - SP - Brazil From memilanuk at gmail.com Sun Dec 12 00:15:13 2010 From: memilanuk at gmail.com (Monte Milanuk) Date: Sat, 11 Dec 2010 21:15:13 -0800 Subject: Ways of accessing this mailing list? In-Reply-To: <8mifvuF424U1@mid.individual.net> References: <871v7050b0.fsf.mdw@metalzone.distorted.org.uk> <8mifvuF424U1@mid.individual.net> Message-ID: On 12/11/10 3:32 PM, Martin Schoeoen wrote: > On 2010-11-04, Mark Wooding wrote: >> John Bond writes: >> >>> Hope this isn't too O/T - I was just wondering how people read/send to >>> this mailing list, eg. normal email client, gmane, some other software >>> or online service? Thunderbird + gmane works for me. From v.harishankar at gmail.com Sun Dec 12 01:50:51 2010 From: v.harishankar at gmail.com (Harishankar) Date: Sun, 12 Dec 2010 06:50:51 +0000 (UTC) Subject: Ways of accessing this mailing list? References: <871v7050b0.fsf.mdw@metalzone.distorted.org.uk> <8mifvuF424U1@mid.individual.net> Message-ID: On Sat, 11 Dec 2010 21:15:13 -0800, Monte Milanuk wrote: > Thunderbird + gmane works for me. I myself post using Pan Usenet client accessing this mailing list from gmane. The advantage of a proper newsreader software is that it quotes correctly (i.e. quote at top, reply below). Many Usenet and mailing list users get angry if you top post (i.e. quote below the reply) -- Harishankar (http://harishankar.org http://lawstudentscommunity.com) From ben+python at benfinney.id.au Sun Dec 12 03:18:52 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 12 Dec 2010 19:18:52 +1100 Subject: Ways of accessing this mailing list? References: <871v7050b0.fsf.mdw@metalzone.distorted.org.uk> <8mifvuF424U1@mid.individual.net> Message-ID: <87sjy3xv2r.fsf@benfinney.id.au> Harishankar writes: > The advantage of a proper newsreader [program] is that it quotes > correctly (i.e. quote at top, reply below). That's a function of the person typing into it, not of the program. Placing the cursor at the top of the message allows the person to trim the superfluous parts of the quoted material, replying in-line to each point as they work their way down. -- \ ?No matter how far down the wrong road you've gone, turn back.? | `\ ?Turkish proverb | _o__) | Ben Finney From v.harishankar at gmail.com Sun Dec 12 05:07:11 2010 From: v.harishankar at gmail.com (Harishankar) Date: Sun, 12 Dec 2010 10:07:11 +0000 (UTC) Subject: Ways of accessing this mailing list? References: <871v7050b0.fsf.mdw@metalzone.distorted.org.uk> <8mifvuF424U1@mid.individual.net> <87sjy3xv2r.fsf@benfinney.id.au> Message-ID: On Sun, 12 Dec 2010 19:18:52 +1100, Ben Finney wrote: > That's a function of the person typing into it, not of the program. I was talking about the default program behaviour. Yes, you can move the cursor up or down, but I was talking about the way regular e-mail clients generally handle quoted blocks. -- Harishankar (http://harishankar.org http://lawstudentscommunity.com) From stefan_ml at behnel.de Sun Dec 12 06:06:28 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 12 Dec 2010 12:06:28 +0100 Subject: Bind C++ program for use with both Python 2.x and 3.x In-Reply-To: References: Message-ID: Peter C., 11.12.2010 23:41: > Hello, I am looking at the possibility of making a program in C++. The > catch is it will require the ability to work with binding for use with > scripting in both Python 2.x and 3.x for various tool plugins. Do I read this right that you want your program to be written in C++, and use an embedded Python interpreter to provide scripting capabilities? Is there a reason you'd want to write the application itself in C++ in the first place? If it's new code, it's likely faster to write it Python directly. Usually, that also leads to a lot less code, which helps in keeping the code more maintainable. > Is > there any way to bind a C++ app to work with both Python 2.x and 3.x > using the Python C API? Note if I could I'd just do Python 3, however > I need Python 2 support to allow for the use of this application as a > plugin in apps that use Python 2 as well. The easiest (and fastest etc.) way to do that is to write the glue code in Cython. It generates portable C/C++ code that supports Python 2.3 to 3.2. However, if you ship binaries, you will still need to provide them for the different Python versions (even for different Py2.x versions), as the runtimes are not binary compatible. Stefan From nfdisco at gmail.com Sun Dec 12 06:35:22 2010 From: nfdisco at gmail.com (ernest) Date: Sun, 12 Dec 2010 03:35:22 -0800 (PST) Subject: default argument in method Message-ID: Hi, I'd like to have a reference to an instance attribute as default argument in a method. It doesn't work because "self" is not defined at the time the method signature is evaluated. For example: class C(object): def __init__(self): self.foo = 5 def m(self, val=self.foo): return val Raises NameError because 'self' is not defined. The obvious solution is put val=None in the signature and set val to the appropriate value inside the method (if val is None: ...), but I wonder if there's another way. Cheers, Ernest From clp2 at rebertia.com Sun Dec 12 06:49:41 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 12 Dec 2010 03:49:41 -0800 Subject: default argument in method In-Reply-To: References: Message-ID: On Sun, Dec 12, 2010 at 3:35 AM, ernest wrote: > Hi, > > I'd like to have a reference to an instance attribute as > default argument in a method. It doesn't work because > "self" is not defined at the time the method signature is > evaluated. For example: > > class C(object): > ? ?def __init__(self): > ? ? ? ?self.foo = 5 > ? ?def m(self, val=self.foo): > ? ? ? ?return val > > Raises NameError because 'self' is not defined. > The obvious solution is put val=None in the signature > and set val to the appropriate value inside the method > (if val is None: ...), but I wonder if there's another way. Nope, not really. There are some more complicated slight variations on the same theme (e.g. hoisting the idiom into a decorator), but they're of fairly dubious merit; just use the straightforward idiom you already outlined. Cheers, Chris -- http://blog.rebertia.com From data.2 at rediff.com Sun Dec 12 07:40:12 2010 From: data.2 at rediff.com (gaurav) Date: Sun, 12 Dec 2010 04:40:12 -0800 (PST) Subject: Get careers in Management stage. Message-ID: Great careers in Management work. Institutional careers in Management http://topcareer.webs.com/humanresourcemgmt.htm & http://rojgars.webs.com/bankingjobs.htm Full ranges of Banking and insurance banking jobs, railway jobs opportunities to make career. http://rojgars.webs.com/bankingjobs.htm From rustompmody at gmail.com Sun Dec 12 08:01:24 2010 From: rustompmody at gmail.com (rusi) Date: Sun, 12 Dec 2010 05:01:24 -0800 (PST) Subject: class browser References: Message-ID: <0c5c92c8-6a51-4ed3-aa29-cc6a2a40fa77@37g2000prx.googlegroups.com> On Dec 8, 11:24?pm, Adam Tauno Williams wrote: > On Wed, 2010-12-08 at 13:18 +0530, Rustom Mody wrote: > > If I have a medium to large python code base to browse/study, what are > > the class browsers available? > > Monodevelop has good Python support which includes a working Python > class browser for Python projects & solutions. > Ok downloaded mono. How do I import an existing project? From stef.mientki at gmail.com Sun Dec 12 08:29:47 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 12 Dec 2010 14:29:47 +0100 Subject: python-parser running Beautiful Soup needs to be reviewed In-Reply-To: <4D03FA84.6040605@web.de> References: <3dcf2ff3-1b23-4dd8-a719-d1647a1a051e@o4g2000yqd.googlegroups.com> <4D03EF63.4040306@gmail.com> <4D03FA84.6040605@web.de> Message-ID: <4D04CE4B.2020607@gmail.com> I've no opinion. >> I'm just struggling with BeautifulSoup myself, finding it one of the toughest libs I've seen ;-) > > Really? While I'm by no means an expert, I find it very easy to work with. It's very well > structured IMHO. I think the cause lies in the documentation. The PySide documentation is much easier to understand (at least for me) http://www.pyside.org/docs/pyside/PySide/QtWebKit/QWebElement.html cheers, Stef From maxc at me.com Sun Dec 12 09:14:16 2010 From: maxc at me.com (Max Countryman) Date: Sun, 12 Dec 2010 09:14:16 -0500 Subject: while True or while 1 In-Reply-To: References: Message-ID: I'm sure this has been brought up many times, but a quick Googling didn't yield the decisive results I was hoping for, so I apologize if this has already been addressed in great detail somewhere else. I am wondering what the rationale is behind preferring while True over while 1? For me, it seems that using True provides more clarity, but is that the only benefit? Is while 1 more prone to errors? Thanks! From python at lists.fastmail.net Sun Dec 12 09:28:29 2010 From: python at lists.fastmail.net (python at lists.fastmail.net) Date: Sun, 12 Dec 2010 15:28:29 +0100 Subject: Objects and validation Message-ID: <1292164109.18709.1409927215@webmail.messagingengine.com> I have a routine in Python which is extracting information from a website. This information is read and inserted into objects. I currently have all the validations and checks implemented in the routines which are reading the HTML and creating the objects. It is however also possible to move all the validations into the class itself. What is considered the best practice for this: validation in the functions which read the information and creates the objects or in the class itself? Thijs From javiervandam at gmail.com Sun Dec 12 10:02:13 2010 From: javiervandam at gmail.com (javivd) Date: Sun, 12 Dec 2010 07:02:13 -0800 (PST) Subject: Reading by positions plain text files References: <39a07597-02b9-4ef8-9ca9-93e2d2425e66@p7g2000prb.googlegroups.com> Message-ID: On Dec 1, 7:15?am, Tim Harig wrote: > On 2010-12-01, javivd wrote: > > > > > > > > > > > On Nov 30, 11:43?pm, Tim Harig wrote: > >> On 2010-11-30, javivd wrote: > > >> > I have a case now in wich anotherfilehas been provided (besides the > >> > database) that tells me in wich column of thefileis every variable, > >> > because there isn't any blank or tab character that separates the > >> > variables, they are stick together. This secondfilespecify the > >> > variable name and his position: > > >> > VARIABLE NAME ? ? ?POSITION (COLUMN) INFILE > >> > var_name_1 ? ? ? ? ? ? ? ? 123-123 > >> > var_name_2 ? ? ? ? ? ? ? ? 124-125 > >> > var_name_3 ? ? ? ? ? ? ? ? 126-126 > >> > .. > >> > .. > >> > var_name_N ? ? ? ? ? ? ? ? 512-513 (last positions) > > >> I am unclear on the format of these positions. ?They do not look like > >> what I would expect from absolute references in the data. ?For instance, > >> 123-123 may only contain one byte??? which could change for different > >> encodings and how you mark line endings. ?Frankly, the use of the > >> world columns in the header suggests that the data *is* separated by > >> line endings rather then absolute position and the position refers to > >> the line number. In which case, you can use splitlines() to break up > >> the data and then address the proper line by index. ?Nevertheless, > >> you can usefile.seek() to move to an absolute offset in thefile, > >> if that really is what you are looking for. > > > I work in a survey research firm. the data im talking about has a lot > > of 0-1 variables, meaning yes or no of a lot of questions. so only one > > position of a character is needed (not byte), explaining the 123-123 > > kind of positions of a lot of variables. > > Thenfile.seek() is what you are looking for; but, you need to be aware of > line endings and encodings as indicated. ?Make sure that you open thefile > using whatever encoding was used when it was generated or you could have > problems with multibyte characters affecting the offsets. I've tried your advice and something is wrong. Here is my code, f = open(r'c:c:\somefile.txt', 'w') f.write('0123456789\n0123456789\n0123456789') f.close() f = open(r'c:\somefile.txt', 'r') for line in f: f.seek(3,0) print f.read(1) #just to know if its printing the rigth column I used .seek() in this manner, but is not working. Let me put the problem in another way. I have .txt file with NO headers, and NO blanks between any columns. But i know that from columns, say 13 to 15, is variable VARNAME_1 (of course, a three digit var). How can extract that column in a list call VARNAME_1?? Obviously, this should extend to all the positions and variables i have to extract from the file. Thanks! J From lists at cheimes.de Sun Dec 12 10:30:38 2010 From: lists at cheimes.de (Christian Heimes) Date: Sun, 12 Dec 2010 16:30:38 +0100 Subject: while True or while 1 In-Reply-To: References: Message-ID: Am 12.12.2010 15:14, schrieb Max Countryman: > I'm sure this has been brought up many times, but a quick Googling didn't yield the decisive results I was hoping for, so I apologize if this has already been addressed in great detail somewhere else. > > I am wondering what the rationale is behind preferring while True over while 1? For me, it seems that using True provides more clarity, but is that the only benefit? Is while 1 more prone to errors? In Python 2.x, "while 1" is slightly faster than "while True". The interpreter can't optimize "while True" because the name "True" can be bind to another value. In Python 3.x it's no longer possible to rebind the names True and False just like None in Python 2.x Christian From krister.svanlund at gmail.com Sun Dec 12 10:33:41 2010 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Sun, 12 Dec 2010 16:33:41 +0100 Subject: while True or while 1 In-Reply-To: References: Message-ID: On Sun, Dec 12, 2010 at 3:14 PM, Max Countryman wrote: > I'm sure this has been brought up many times, but a quick Googling didn't yield the decisive results I was hoping for, so I apologize if this has already been addressed in great detail somewhere else. > > I am wondering what the rationale is behind preferring while True over while 1? For me, it seems that using True provides more clarity, but is that the only benefit? Is while 1 more prone to errors? It's just silly to use 1 since it will evaluate to True either way. From pakalk at gmail.com Sun Dec 12 11:03:32 2010 From: pakalk at gmail.com (pakalk) Date: Sun, 12 Dec 2010 08:03:32 -0800 (PST) Subject: Objects and validation References: Message-ID: <33c2de8c-f7dd-445d-b0c8-27ae89870e44@o9g2000pre.googlegroups.com> On 12 Gru, 15:28, pyt... at lists.fastmail.net wrote: > I have a routine in Python which is extracting information from a > website. This information is read and inserted into objects. > > I currently have all the validations and checks implemented in the > routines which are reading the HTML and creating the objects. It is > however also possible to move all the validations into the class itself. > What is considered the best practice for this: validation in the > functions which read the information and creates the objects or in the > class itself? setter Data sources may differ, and may be used for many reasons, so validating data there is not a good idea. Object has to keep correct data, so it should validate it. If you want to have object created no matter what, you can add validate() method, but you may also use setters for this - error will be raised every try to set wrong data. From emile at fenx.com Sun Dec 12 11:06:17 2010 From: emile at fenx.com (Emile van Sebille) Date: Sun, 12 Dec 2010 08:06:17 -0800 Subject: stuck with Pexpect script need help!! In-Reply-To: References: Message-ID: On 12/10/2010 10:02 PM Darshak Bavishi said... > Pexpect is intended for UNIX-like operating systems.""") > > Can we use pexpect from windows host machine ?! > I expect not... Emile From emile at fenx.com Sun Dec 12 11:22:12 2010 From: emile at fenx.com (Emile van Sebille) Date: Sun, 12 Dec 2010 08:22:12 -0800 Subject: Ways of accessing this mailing list? In-Reply-To: References: <871v7050b0.fsf.mdw@metalzone.distorted.org.uk> <8mifvuF424U1@mid.individual.net> <87sjy3xv2r.fsf@benfinney.id.au> Message-ID: On 12/12/2010 2:07 AM Harishankar said... > On Sun, 12 Dec 2010 19:18:52 +1100, Ben Finney wrote: > >> That's a function of the person typing into it, not of the program. > > I was talking about the default program behaviour. Yes, you can move the > cursor up or down, but I was talking about the way regular e-mail clients > generally handle quoted blocks. > http://web.archive.org/web/20041224190115/lists.suse.com/archive/suse-linux-e/2002-Oct/1698.html Emile From alex.kapps at web.de Sun Dec 12 11:31:32 2010 From: alex.kapps at web.de (Alexander Kapps) Date: Sun, 12 Dec 2010 17:31:32 +0100 Subject: stuck with Pexpect script need help!! In-Reply-To: References: Message-ID: <4D04F8E4.1040208@web.de> On 12.12.2010 17:06, Emile van Sebille wrote: > On 12/10/2010 10:02 PM Darshak Bavishi said... > >> Pexpect is intended for UNIX-like operating systems.""") > >> >> Can we use pexpect from windows host machine ?! >> > > I expect not... > > Emile > According to [1] you might get it working with the Cygwin port of Python. Alternatively try WinPexpect [2] [1] http://www.noah.org/wiki/Pexpect#Python [2] http://bitbucket.org/geertj/winpexpect/wiki/Home From steve at holdenweb.com Sun Dec 12 13:31:34 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 12 Dec 2010 13:31:34 -0500 Subject: while True or while 1 In-Reply-To: References: Message-ID: <4D051506.2060403@holdenweb.com> On 12/12/2010 10:30 AM, Christian Heimes wrote: > Am 12.12.2010 15:14, schrieb Max Countryman: >> I'm sure this has been brought up many times, but a quick Googling didn't yield the decisive results I was hoping for, so I apologize if this has already been addressed in great detail somewhere else. >> >> I am wondering what the rationale is behind preferring while True over while 1? For me, it seems that using True provides more clarity, but is that the only benefit? Is while 1 more prone to errors? > > In Python 2.x, "while 1" is slightly faster than "while True". The > interpreter can't optimize "while True" because the name "True" can be > bind to another value. In Python 3.x it's no longer possible to rebind > the names True and False just like None in Python 2.x > Would you care to quantify how much CPU time that optimization will typically save for a loop of fair magnitude (say, a billion iterations)? Python is designed to provide readable code. Writing while True: ... is much more legible than its pre-True couterpart while 1: ... and is, I'd say, therefore to be preferred (except in a code base intended to compile on 2.2 and before). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From usernet at ilthio.net Sun Dec 12 14:09:56 2010 From: usernet at ilthio.net (Tim Harig) Date: Sun, 12 Dec 2010 19:09:56 +0000 (UTC) Subject: Reading by positions plain text files References: <39a07597-02b9-4ef8-9ca9-93e2d2425e66@p7g2000prb.googlegroups.com> Message-ID: On 2010-12-12, javivd wrote: > On Dec 1, 7:15?am, Tim Harig wrote: >> On 2010-12-01, javivd wrote: >> > On Nov 30, 11:43?pm, Tim Harig wrote: >> >> encodings and how you mark line endings. ?Frankly, the use of the >> >> world columns in the header suggests that the data *is* separated by >> >> line endings rather then absolute position and the position refers to >> >> the line number. In which case, you can use splitlines() to break up >> >> the data and then address the proper line by index. ?Nevertheless, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Note that I specifically questioned the use of absolute file position vs. postion within a column. These are two different things. You use different methods to extract each. >> > I work in a survey research firm. the data im talking about has a lot >> > of 0-1 variables, meaning yes or no of a lot of questions. so only one >> > position of a character is needed (not byte), explaining the 123-123 >> > kind of positions of a lot of variables. >> >> Thenfile.seek() is what you are looking for; but, you need to be aware of >> line endings and encodings as indicated. ?Make sure that you open thefile >> using whatever encoding was used when it was generated or you could have >> problems with multibyte characters affecting the offsets. > > f = open(r'c:c:\somefile.txt', 'w') I suspect you don't need to use the c: twice. > f.write('0123456789\n0123456789\n0123456789') Note that the file you a writing contains three lines. Is the data that you are looking for located at an absolute position in the file or on a position within a individual line? If the latter, not that line endings may be composed of more then a single character. > f.write('0123456789\n0123456789\n0123456789') ^ postion 3 using fseek() > for line in f: Perhaps you meant: for character in f.read(): or for line in f.read().splitlines() > f.seek(3,0) This will always take you back to the exact fourth position in the file (indicated above). > I used .seek() in this manner, but is not working. It is working the way it is supposed to. If you want the absolution position 3 in a file then: f = open('somefile.txt', 'r') f.seek(3) variable = f.read(1) If you want the absolute position in a column: f = open('somefile.txt', 'r').read().splitlines() for column in f: variable = column[3] From urban.dani at gmail.com Sun Dec 12 14:10:48 2010 From: urban.dani at gmail.com (Daniel Urban) Date: Sun, 12 Dec 2010 20:10:48 +0100 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance In-Reply-To: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> Message-ID: > So far, the only situation I can find where method names necessarily > overlap is for the basics like __init__(), close(), flush(), and > save() where multiple parents need to have their own initialization > and finalization. One other possibility is subclasses of the JSONEncoder class. For example the writer of class X provides a class, XJSONEncoder, which is able to serialize X instances (by extending the default method). Similarly there is a YJSONEncoder class, which can serialize Y instances. Those classes implement the default method like this: def default(self, o): if isinstance(o, X): ... # serialize the X instance else: return super().default(o) # let the next in the MRO try to handle it If YJSONEncoder encodes Y instances similarly, one can create an encoder class, which can encode both X and Y instances: class XYJSONEncoder(XJSONEncoder, YJSONEncoder): pass It is usable this way: json.dumps([X(), Y()], cls=XYJSONEncoder) Regards, Daniel From usernet at ilthio.net Sun Dec 12 14:27:51 2010 From: usernet at ilthio.net (Tim Harig) Date: Sun, 12 Dec 2010 19:27:51 +0000 (UTC) Subject: Reading by positions plain text files References: <39a07597-02b9-4ef8-9ca9-93e2d2425e66@p7g2000prb.googlegroups.com> Message-ID: On 2010-12-12, Tim Harig wrote: >> I used .seek() in this manner, but is not working. > > It is working the way it is supposed to. > If you want the absolute position in a column: > > f = open('somefile.txt', 'r').read().splitlines() > for column in f: > variable = column[3] or: f = open('somefile.txt', 'r') for column in f.readlines(): variable = column[3] From lists at cheimes.de Sun Dec 12 14:32:00 2010 From: lists at cheimes.de (Christian Heimes) Date: Sun, 12 Dec 2010 20:32:00 +0100 Subject: while True or while 1 In-Reply-To: <4D051506.2060403@holdenweb.com> References: <4D051506.2060403@holdenweb.com> Message-ID: Am 12.12.2010 19:31, schrieb Steve Holden: > Would you care to quantify how much CPU time that optimization will > typically save for a loop of fair magnitude (say, a billion iterations)? The difference is minimal but measurable for very tight loops. $ python -m timeit -n20 -- "i = 0" "while 1:" " i+=1" " if i == 1000000: break" 20 loops, best of 3: 89.7 msec per loop $ python -m timeit -n20 -- "i = 0" "while True:" " i+=1" " if i == 1000000: break" 20 loops, best of 3: 117 msec per loop In Python 2.x the peep hole optimizer can't remove the global lookup and check for trueness for "while True". >>> def while1(): ... while 1: ... pass ... >>> import dis >>> dis.dis(while1) 2 0 SETUP_LOOP 3 (to 6) 3 >> 3 JUMP_ABSOLUTE 3 >> 6 LOAD_CONST 0 (None) 9 RETURN_VALUE >>> def whiletrue(): ... while True: ... pass ... >>> dis.dis(whiletrue) 2 0 SETUP_LOOP 12 (to 15) >> 3 LOAD_GLOBAL 0 (True) 6 JUMP_IF_FALSE 4 (to 13) 9 POP_TOP 3 10 JUMP_ABSOLUTE 3 >> 13 POP_TOP 14 POP_BLOCK >> 15 LOAD_CONST 0 (None) 18 RETURN_VALUE > Python is designed to provide readable code. Writing > > while True: > ... > > is much more legible than its pre-True couterpart > > while 1: > ... No argue with that! I was merely making a point that "while 1" executes different byte code than "while True". Readability is important but sometimes speed is of the essence. "while 1" is one of the few tricks to speed up tight loops a bit. Christian From xrgtn at yandex.ru Sun Dec 12 15:04:22 2010 From: xrgtn at yandex.ru (Alexander Gattin) Date: Sun, 12 Dec 2010 22:04:22 +0200 Subject: Wanted: slow regexes In-Reply-To: <4CFFB122.5040504@mrabarnett.plus.com> References: <4CFC61B0.8000109@mrabarnett.plus.com> <20101208124225.GA4846@xrgtn-q40> <4CFFB122.5040504@mrabarnett.plus.com> Message-ID: <20101212200422.GA8060@xrgtn-q40> Hello, On Wed, Dec 08, 2010 at 04:24:02PM +0000, MRAB wrote: > Interestingly, that webpage says that: > > ("a" x 100000) =~ /^(ab?)*$/ > > caused Perl to segfault. I tried it and it didn't segfault, but it > didn't match either It doesn't segfault but produces a warning with -w: xrgtn at xrgtn-q40:~$ perl -wse 'print(("a" x 100000) =~ /^(ab?)*$/)' Complex regular subexpression recursion limit (32766) exceeded at -e line 1. xrgtn at xrgtn-q40:~$ -- With best regards, xrgtn From martin at v.loewis.de Sun Dec 12 16:01:06 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sun, 12 Dec 2010 22:01:06 +0100 Subject: while True or while 1 In-Reply-To: References: <4D051506.2060403@holdenweb.com> Message-ID: <4D053812.5000305@v.loewis.de> >> Python is designed to provide readable code. Writing >> >> while True: >> ... >> >> is much more legible than its pre-True couterpart >> >> while 1: >> ... > > No argue with that! I actually want to argue with that: I find "while 1" more legible. That's probably because a) I'm use to it, and b) the English words "while" and "True" don't mean much to me, I need recognize them, and recognizing "True" is slightly more difficult than recognizing "1". In the end, in any project, there should be coding conventions, and authors should follow them. What is legible is IMO much more determined by convention than "intuition", at least to experienced programmers (i.e. those that have been following the convention for a long time). Regards, Martin From chambon.pascal at wanadoo.fr Sun Dec 12 16:15:43 2010 From: chambon.pascal at wanadoo.fr (Pascal Chambon) Date: Sun, 12 Dec 2010 22:15:43 +0100 Subject: Directly calling python's function arguments dispatcher Message-ID: <4D053B7F.1080202@wanadoo.fr> Hello I've encountered several times, when dealing with adaptation of function signatures, the need for explicitly resolving complex argument sets into a simple variable mapping. Explanations. Consider that function: def foo(a1, a2, *args, **kwargs): pass calling foo(1, a2=2, a3=3) will map these arguments to local variables like these: { 'a1': 1, 'a2': 2, 'args': tuple(), 'kwarg's: {'a3': 3} } That's a quite complex resolution mechanism, which must handle positional and keyword arguments, and deal with both collision and missing argument cases. Normally, the simplest way to invoke this mechanism is to define a function with the proper signature, and then call it (like, here, foo()). But there are cases where a more "meta" approach would suit me well. For example when adapting xmlrpc methods : due to the limitations of xmlrpc (no keyword arguments), we use a trick, i.e our xmlrpc functions only accept a single argument, a "struct" (python dict) which gets unpacked on arrival, when calling the real functions exposed by the xmlrpc server. But on client side, I'd like to offer a more native interface (allowing both positional and keyword arguments), without having to manually define an adapter function for each xmlrpc method. To summarize, I'd like to implement a magic method like this one (please don't care about performance isues for now): class XmlrpcAdapter: def __getattr__(self, funcname): # we create an on-the-fly adapter def adapter(*args, **kwargs): xmlrpc_kwargs = _resolve_func_signature(funcname, *args, **kwargs) # we call the remote function with an unique dict argument self.xmlrpc_server.call(funcname, xmlrpc_kwargs) return adapter As you see, all I need is _resolve_func_signature(), which is actually the routine (internal to the python runtime) which transforms complex function calls in a simple mapping of variables to be added to the function local namespace. Of course this routine would need information about the target functions' signature, but I have that info available (for example, via a set of functions that are a mockup of the real xmlrpc API). Is that routine exposed to python, somewhere ? Does anybody know a working implementation here or there ? Thanks for the help, regards, Pakal From devplayer at gmail.com Sun Dec 12 16:21:43 2010 From: devplayer at gmail.com (DevPlayer) Date: Sun, 12 Dec 2010 13:21:43 -0800 (PST) Subject: Python on wikipedia Message-ID: Snapshot in time, hey look at that; someone used Python as THE example of what a programming language is on Wikipedia. http://en.wikipedia.org/wiki/Programming_language From pakalk at gmail.com Sun Dec 12 16:38:28 2010 From: pakalk at gmail.com (pakalk) Date: Sun, 12 Dec 2010 13:38:28 -0800 (PST) Subject: Python on wikipedia References: Message-ID: On 12 Gru, 22:21, DevPlayer wrote: > Snapshot in time, hey look at that; someone used Python as THE example > of what a programming language is on Wikipedia.http://en.wikipedia.org/wiki/Programming_language aaaaaaaaaaaaaand? what is the catch? From steve+comp.lang.python at pearwood.info Sun Dec 12 16:49:02 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 Dec 2010 21:49:02 GMT Subject: while True or while 1 References: Message-ID: <4d05434e$0$29970$c3e8da3$5496439d@news.astraweb.com> On Sun, 12 Dec 2010 16:33:41 +0100, Krister Svanlund wrote: > On Sun, Dec 12, 2010 at 3:14 PM, Max Countryman wrote: >> I'm sure this has been brought up many times, but a quick Googling >> didn't yield the decisive results I was hoping for, so I apologize if >> this has already been addressed in great detail somewhere else. >> >> I am wondering what the rationale is behind preferring while True over >> while 1? For me, it seems that using True provides more clarity, but is >> that the only benefit? Is while 1 more prone to errors? > > It's just silly to use 1 since it will evaluate to True either way. With the "while True" idiom in Python 2.x, you can easily exit out of an infinite loop without using break: >>> while True: ... print "Looping" ... True = 0 ... Looping >>> >>> while True: # Execute an infinite loop in 0 seconds. ... print "Looping" ... >>> *wink* -- Steven From john at nmt.edu Sun Dec 12 16:56:27 2010 From: john at nmt.edu (JohnWShipman) Date: Sun, 12 Dec 2010 13:56:27 -0800 (PST) Subject: Tkinter polling example: file copy with progress bar Message-ID: Attached below is a Tkinter script that demonstrates polling, that is, performing a long-running process in parallel with the GUI. The script asks for an input file name and an output file name and copies the input file to the output file. The copy operation is done in a child process managed with pexpect, and the GUI reports the progress of the file copy using a Scale widget as a progress bar. Cordially, John W. Shipman, NM Tech Computer Center, Socorro, NM; john at nmt.edu ================ #!/usr/bin/env python #================================================================ # copyprogress: File copy with a progress bar for Tkinter 8.4. # - Demonstrates Tkinter .after() and the pexpect module. # Written by John W. Shipman (john at nmt.edu), New Mexico Tech # Computer Center, Socorro, NM 87801 USA. This script is in # the public domain. #---------------------------------------------------------------- # - - - - - I m p o r t s import sys, os, stat import Tkinter as tk import tkFileDialog, tkMessageBox import pexpect # - - - - - M a n i f e s t c o n s t a n t s BUTTON_FONT = ("Helvetica", 17) LABEL_FONT = ("Helvetica", 14) ENTRY_FONT = ("DejaVu Sans Mono", 12) POLL_TIME = 50 # Polling frequency in milliseconds # - - - - - m a i n def main(): """ """ app = App() app.master.title("Copy with progress bar") app.mainloop() # - - - - - c l a s s A p p class App(tk.Frame): '''Copies a file with a progress bar. Widgets: .fromFileVar: StringVar for source file name .fromFileEntry: Entry for source file name .fromFileBrowse: Browse button for source file name .fromFileLabel: Label for above .toFileVar: StringVar for destination file name .toFileEntry: Entry for destination file name .toFileBrowse: Browse button for destination file name .toFileLabel: Label for above .copyButton: Button to start copying .progressVar: DoubleVar for progress scale .progressScale: Scale to show progress Grid plan: 0 1 2 +----------------+-----------------+----------------+ 0 | .fromFileEntry | .fromFileBrowse | .fromFileLabel | +----------------+-----------------+----------------+ 1 | .toFileEntry | .toFileBrowse | .toFileLabel | +----------------+-----------------+----------------+ 2 | .progress | .copyButton | .quitButton | +----------------+-----------------+----------------+ Internal state: .fromFileSize: Source file size in bytes .child: pexpect child process to do the copy ''' # - - - A p p . _ _ i n i t _ _ def __init__(self, master=None): tk.Frame.__init__(self, master) self.grid() self.__createWidgets() # - - - A p p . _ _ c r e a t e w i d g e t s def __createWidgets(self): '''Create all widgets and associated variables. ''' self.fromFileVar = tk.StringVar() self.fromFileEntry = tk.Entry ( self, textvariable=self.fromFileVar, font=ENTRY_FONT, width=50 ) rowx, colx = 0, 0 self.fromFileEntry.grid(row=rowx, column=colx, sticky=tk.E) self.fromFileBrowse = tk.Button ( self, command=self.__browseFrom, font=BUTTON_FONT, text="Browse" ) colx += 1 self.fromFileBrowse.grid(row=rowx, column=colx) self.fromFileLabel = tk.Label ( self, font=LABEL_FONT, text="Source file" ) colx += 1 self.fromFileLabel.grid(row=rowx, column=colx, sticky=tk.W) self.toFileVar = tk.StringVar() self.toFileEntry = tk.Entry ( self, textvariable=self.toFileVar, font=ENTRY_FONT, width=50 ) rowx, colx = rowx+1, 0 self.toFileEntry.grid(row=rowx, column=colx, sticky=tk.E) self.toFileBrowse = tk.Button ( self, command=self.__browseTo, font=BUTTON_FONT, text="Browse" ) colx += 1 self.toFileBrowse.grid(row=rowx, column=colx) self.toFileLabel = tk.Label ( self, font=LABEL_FONT, text="Destination file") colx += 1 self.toFileLabel.grid(row=rowx, column=colx, sticky=tk.W) self.progressVar = tk.DoubleVar() self.progressScale = tk.Scale ( self, length=400, orient=tk.HORIZONTAL, from_=0.0, to=100.0, resolution=0.1, tickinterval=20.0, variable=self.progressVar, label="Percent completion", font=LABEL_FONT ) rowx, colx = rowx+1, 0 self.progressScale.grid(row=rowx, column=colx, sticky=tk.E) self.copyButton = tk.Button ( self, command=self.__copyHandler, font=BUTTON_FONT, text="Copy" ) colx += 1 self.copyButton.grid(row=rowx, column=colx ) self.quitButton = tk.Button ( self, command=self.quit, font=BUTTON_FONT, text="Quit" ) colx += 1 self.quitButton.grid(row=rowx, column=colx, sticky=tk.W) # - - - A p p . _ _ b r o w s e F r o m def __browseFrom(self): '''Handler for Browse button for the source file. ''' # [ if the user enters an existing file name in a popup -> # self.fromFileVar := that name # else -> # f := an empty string ] f = tkFileDialog.askopenfilename(title="Source file name") if len(f) == 0: return else: self.fromFileVar.set(f) # - - - A p p . _ _ b r o w s e T o def __browseTo(self): '''Handler for Browse button for the source file. ''' # [ if the user enters a nonexistent existing file name in # a popup, or enters an existing name and then says it's # okay to overwrite it -> # self.toFileVar := that name # else -> # f := an empty string ] f = tkFileDialog.asksaveasfilename(title="Destination file name") if len(f) == 0: return else: self.toFileVar.set(f) # - - - A p p . _ _ c o p y H a n d l e r def __copyHandler(self): '''Start the file copy process. ''' # [ if the source file name is empty -> # display a popup error message # return # else -> I ] if len(self.fromFileVar.get()) == 0: tkMessageBox.showerror("Error", "Please enter a source file name." ) return # [ if the destination file name is empty -> # show an error popup # return # else if the destination file exists and the user's reply # to a popup indicates they do not want to proceed -> # return # else -> I ] toFileName = self.toFileVar.get() if len(toFileName) == 0: tkMessageBox.showerror("Error", "Please enter a destination file name." ) return elif os.path.exists(toFileName): message = ( "File '%s' exists.\nDo you want to overwrite " "it?" % toFileName ) answer = tkMessageBox.askokcancel("Destination file exists", message, default=tkMessageBox.CANCEL) if not answer: return # [ if the source file exists -> # self.fromFileSize := that file's size in bytes # else -> # display a popup and return ] if not self.__copySetup(): return # [ self.child := a pexpect.spawn child process that copies # the source file to the destination file with -f # self := self with a callback to self.__poll after # POLL_TIME ] self.__startCopy() # - - - A p p . _ _ c o p y S e t u p def __copySetup(self): '''Operations done before the copy is started. [ if the source file exists -> self.fromFileSize := that file's size in bytes return True else -> display an error popup return False ] ''' fromFileName = self.fromFileVar.get() try: self.fromFileSize = self.__measureFile(fromFileName) except OSError, details: tkMessageBox.showerror ( "Source file error", "File %s: %s" % (fromFileName, str(details)) ) return False return True # - - - A p p . _ _ s t a r t C o p y def __startCopy ( self ): '''Start up a file copy operation. [ (self.fromFileVar contains the name of a readable file) and (self.toFileVar contains the name of a writeable file) -> self.child := a pexpect.spawn child process that copies the source file to the destination file with -f self := self with a callback to self.__poll after POLL_TIME ] ''' # [ command := a copy command from the source file to the # destination file, with a force option ] command = ( "cp -f %s %s" % (self.fromFileVar.get(), self.toFileVar.get()) ) # [ self.progressVar := 0 # self := self with a callback after POLL_TIME to # self.__poll ] self.progressVar.set(0.0) self.after(POLL_TIME, self.__poll) # [ self.child := a pexpect.spawn process to run command ] self.child = pexpect.spawn(command) # - - - A p p . _ _ m e a s u r e F i l e def __measureFile(self, fileName): '''Determine the current length of a file, if it exists. [ if fileName can be statted -> return the current length of that file else -> raise OSError ] ''' status = os.stat ( fileName ) return status[stat.ST_SIZE] # - - - A p p . _ _ p o l l def __poll(self): '''Periodic check of the copy progress. [ if self.child has terminated -> self.progressVar := 100.0 self.child := (closed) show a status popup else if we can stat the output file -> self.progressVar := (destination file size / self.fromFileSize) as a percentage self := self with a callback to self.__poll after POLL_TIME ] ''' # [ if self.child has terminated -> # self.progressVar := 100.0 # return # else -> I ] if not self.child.isalive(): self.child.close() self.progressVar.set(100.0) tkMessageBox.showinfo ( "Success", "File %s has been copied to %s, size %s." % (self.fromFileVar.get(), self.toFileVar.get(), self.fromFileSize) ) return # [ if we can stat the output file -> # outFileSize := its size in bytes # else -> # display an error popup # return ] toFileName = self.toFileVar.get() try: toFileSize = self.__measureFile ( toFileName ) except OSError, details: tkMessageBox.showerror ( "Destination file error", "File %s: %s" % (toFileName, str(details)) ) return # [ self.progressVar := toFileSize / self.fromFileSize # as a percentage # self := self with a callback to self.__poll after # POLL_TIME ] self.progressVar.set ( 100.0 * float(toFileSize) / float(self.fromFileSize) ) self.after(POLL_TIME, self.__poll) # - - - - - E p i l o g u e if __name__ == "__main__": main() From tjreedy at udel.edu Sun Dec 12 17:41:45 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 12 Dec 2010 17:41:45 -0500 Subject: Python on wikipedia In-Reply-To: References: Message-ID: On 12/12/2010 4:38 PM, pakalk wrote: > On 12 Gru, 22:21, DevPlayer wrote: >> Snapshot in time, hey look at that; someone used Python as THE example >> of what a programming language is on Wikipedia.http://en.wikipedia.org/wiki/Programming_language > > aaaaaaaaaaaaaand? what is the catch? Wikipedia entries can be edited. -- Terry Jan Reedy From __peter__ at web.de Sun Dec 12 17:41:47 2010 From: __peter__ at web.de (Peter Otten) Date: Sun, 12 Dec 2010 23:41:47 +0100 Subject: Directly calling python's function arguments dispatcher References: Message-ID: Pascal Chambon wrote: > I've encountered several times, when dealing with adaptation of function > signatures, the need for explicitly resolving complex argument sets into > a simple variable mapping. Explanations. > > > Consider that function: > > def foo(a1, a2, *args, **kwargs): > pass > > calling foo(1, a2=2, a3=3) > > will map these arguments to local variables like these: > { > 'a1': 1, > 'a2': 2, > 'args': tuple(), > 'kwarg's: {'a3': 3} > } > > That's a quite complex resolution mechanism, which must handle > positional and keyword arguments, and deal with both collision and > missing argument cases. > Is that routine exposed to python, somewhere ? Does anybody know a > working implementation here or there ? http://docs.python.org/library/inspect.html#inspect.getcallargs From wallenpb at gmail.com Sun Dec 12 21:15:01 2010 From: wallenpb at gmail.com (Bill Allen) Date: Sun, 12 Dec 2010 20:15:01 -0600 Subject: Python on wikipedia In-Reply-To: References: Message-ID: Yeah, I noticed that a while back too. Kinda cool. --Bill On Sun, Dec 12, 2010 at 3:21 PM, DevPlayer wrote: > Snapshot in time, hey look at that; someone used Python as THE example > of what a programming language is on Wikipedia. > http://en.wikipedia.org/wiki/Programming_language > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Sun Dec 12 23:20:40 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 12 Dec 2010 23:20:40 -0500 Subject: while True or while 1 In-Reply-To: References: <4D051506.2060403@holdenweb.com> Message-ID: On 12/12/2010 2:32 PM, Christian Heimes wrote: > Am 12.12.2010 19:31, schrieb Steve Holden: >> > Would you care to quantify how much CPU time that optimization will >> > typically save for a loop of fair magnitude (say, a billion iterations)? > The difference is minimal but measurable for very tight loops. > > $ python -m timeit -n20 -- "i = 0" "while 1:" " i+=1" " if i == > 1000000: break" > 20 loops, best of 3: 89.7 msec per loop > $ python -m timeit -n20 -- "i = 0" "while True:" " i+=1" " if i == > 1000000: break" > 20 loops, best of 3: 117 msec per loop > > In Python 2.x the peep hole optimizer can't remove the global lookup and > check for trueness for "while True". > Yes, you said that already and I certainly didn't disagree. [...] >> Python is designed to provide readable code. Writing >> > >> > while True: >> > ... >> > >> > is much more legible than its pre-True couterpart >> > >> > while 1: >> > ... > No argue with that! I was merely making a point that "while 1" executes > different byte code than "while True". Readability is important but > sometimes speed is of the essence. "while 1" is one of the few tricks to > speed up tight loops a bit. OK, but the figures you quote save you 27.3 ms per million iterations, for a grand total saving of 27.3 ns per iteration. So "a bit" is hardly worth considering for most programs, is it? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From bavishi.darshak at gmail.com Mon Dec 13 00:03:07 2010 From: bavishi.darshak at gmail.com (Darshak Bavishi) Date: Mon, 13 Dec 2010 10:33:07 +0530 Subject: Is there any way to SSH from Python ?! Message-ID: Hi Experts, I need to know that is there any way to SSH (From Windows Host) to Unix machine ?! If Yes than How ? Because when i use telenet it not showing the no result !! As earlier it was suggested that i should try with exit first and than read_all() but still issue persist and getting hang import getpass import sys import telnetlib import time HOST = "*.*.*.*" #user = raw_input("Enter your remote account: ") #password = getpass.getpass() user = "Darshak2" password = "****" tn = telnetlib.Telnet(HOST , 5400) print "1" tn.read_until("login:" , 5) print "2" tn.write(user + "\n") print "3" if password: tn.read_until("Password: ") tn.write(password + "\n") print "4" tn.write("set alarm = off" + "\n") tn.write("set event = off" + "\n") print "5" tn.write("Cd /Office-Parameters/Mobility-Config-Parameters/Subscriber-Query-by-IMSI-MSISDN-or-IMEI" + "\n") print "6" tn.write("\n") tn.write("\n") tn.write("vlrsubquery msisdn=***" + "\n") tn.write("\n") tn.write("exit" + "\n") print tn.read_all() tn.close() -- BR Darshak Bavishi -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Mon Dec 13 00:09:00 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 12 Dec 2010 21:09:00 -0800 Subject: Is there any way to SSH from Python ?! In-Reply-To: References: Message-ID: On Sun, Dec 12, 2010 at 9:03 PM, Darshak Bavishi wrote: > Hi Experts, > I need to know that is there any way to SSH (From Windows Host) to Unix > machine ?! > If Yes than How ? http://www.lag.net/paramiko/ Did you try googling "ssh python"? Cheers, Chris -- http://blog.rebertia.com From bavishi.darshak at gmail.com Mon Dec 13 00:11:20 2010 From: bavishi.darshak at gmail.com (Darshak Bavishi) Date: Mon, 13 Dec 2010 10:41:20 +0530 Subject: Is there any way to SSH from Python ?! In-Reply-To: References: Message-ID: i am trying from last week but no luck !! one thing only found that pexpect it not useful in windows pls help out of this On Mon, Dec 13, 2010 at 10:39 AM, Chris Rebert wrote: > On Sun, Dec 12, 2010 at 9:03 PM, Darshak Bavishi > wrote: > > Hi Experts, > > I need to know that is there any way to SSH (From Windows Host) to Unix > > machine ?! > > If Yes than How ? > > http://www.lag.net/paramiko/ > > Did you try googling "ssh python"? > > Cheers, > Chris > -- > http://blog.rebertia.com > -- BR Darshak Bavishi -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Mon Dec 13 02:29:56 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 Dec 2010 07:29:56 GMT Subject: while True or while 1 References: <4D051506.2060403@holdenweb.com> Message-ID: <4d05cb74$0$30003$c3e8da3$5496439d@news.astraweb.com> On Sun, 12 Dec 2010 23:20:40 -0500, Steve Holden wrote: > On 12/12/2010 2:32 PM, Christian Heimes wrote: [...] >> No argue with that! I was merely making a point that "while 1" executes >> different byte code than "while True". Readability is important but >> sometimes speed is of the essence. "while 1" is one of the few tricks >> to speed up tight loops a bit. > > OK, but the figures you quote save you 27.3 ms per million iterations, > for a grand total saving of 27.3 ns per iteration. So "a bit" is hardly > worth considering for most programs, is it? I don't think anyone is saying that people should routinely use "while 1" for loops because they're faster than the alternatives. But it is a real, if small, optimization for a particular class of tight loops. Using the figures shown by Christian, it could be a 20-25% speed up on extremely tight loops. You're right though, it's hardly worth the effort for large, expensive loops though -- but then on the other hand, "while 1" is not so unreadable that it should be avoided. I'm actually quite fond of the look of "while 1:", and sometimes use it, not because it's faster, but just because I like it. -- Steven From no.email at nospam.invalid Mon Dec 13 02:48:04 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 12 Dec 2010 23:48:04 -0800 Subject: while True or while 1 References: <4D051506.2060403@holdenweb.com> <4d05cb74$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7xbp4q5d1n.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > I'm actually quite fond of the look of "while 1:", and sometimes use it, > not because it's faster, but just because I like it. for v in itertools.repeat(True): ... ;-) From bruno.desthuilliers at gmail.com Mon Dec 13 03:51:57 2010 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Mon, 13 Dec 2010 00:51:57 -0800 (PST) Subject: Objects and validation References: Message-ID: <2435365b-5aea-4561-933b-d5242d0729ab@d8g2000yqf.googlegroups.com> On 12 d?c, 15:28, pyt... at lists.fastmail.net wrote: > I have a routine in Python which is extracting information from a > website. This information is read and inserted into objects. > > I currently have all the validations and checks implemented in the > routines which are reading the HTML and creating the objects. It is > however also possible to move all the validations into the class itself. > What is considered the best practice for this: validation in the > functions which read the information and creates the objects or in the > class itself? > There's no one-size-fits-all answer to this question. Part of the work really belongs to the layer that accepts data from the outside world, part of it belong to the 'model' object itself. In any case, the 'model' object shouldn't have to worry about data conversion etc - like, if one of the attribute is supposed to be a datetime, it's the client code's responsability to provide a proper datetime object, not a string that may (or not) be the textual representation of a date and time. From jeanmichel at sequans.com Mon Dec 13 05:19:35 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 13 Dec 2010 11:19:35 +0100 Subject: Proposed changes to logging defaults In-Reply-To: <9a8c49a6-d24f-4e27-b2e7-2ba654f8236a@t8g2000prh.googlegroups.com> References: <3763d355-9074-485c-a694-031d600d5b84@m11g2000vbs.googlegroups.com> <9a8c49a6-d24f-4e27-b2e7-2ba654f8236a@t8g2000prh.googlegroups.com> Message-ID: <4D05F337.1010402@sequans.com> Vinay Sajip wrote: > On Dec 10, 10:17 am, Jean-Michel Pichavant > wrote: > > Hi Jean-Michel, > > I think Antoine answered your other points, so I'll address the last > one: > > >> Last question, if no handler is found, why not simply drop the log >> event, doing nothing ? It sounds pretty reasonable and less intrusive. >> > > That is what happens at the moment if configured for production > (logging.raiseExceptions is False) - nothing happens, and the event is > discarded. For development (logging.raiseExceptions is True), the "No > handlers were found for logger XXX" is printed once, to assist > developers to detect misconfiguration. However, the original logged > event is still discarded. > > The original philosophy (when logging was added to Python) was that > logging is an adjunct to the operation of the program using it - the > program should work the same way whether or not logging is configured. > However, the consensus on Python-dev is that the logging package > should do useful work, and not just act as an adjunct, i.e. notify the > user on warning and error conditions by default if no logging > configuration is set up. A program will now work differently depending > on whether logging is configured, but if it is not configured, the > default should be to display warnings and errors, unless explicitly > silenced (as per the Zen of Python). > > These two approaches (original vs. proposed) are of course quite > different, and there's no way of satisfying both proponents of both > approaches, nor any easy way of measuring how many of each there are. > The proposed change moves logging closer to the current Python-dev > consensus, and means that messages currently written to sys.stderr by > stdlib modules could be logged instead, with the stdlib maintainers > writing those messages knowing that unless explicitly silenced, those > messages will appear to the user as they would via a > sys.stderr.write(). It will be good if this happens, so that > application writers will have better control over what messages are > displayed (when they need it), by configuring logging. > > Remember - no changes to behaviour will occur if this change is > implemented and an application configures logging. It's only the no- > configuration case that will change. > > To get the current behaviour after the proposed changes are > implemented, an application developer would have to do > logging.lastResort = None, which is a small price to pay (and more or > less equivalent in difficulty with what users who want verbosity by > default have to do, e.g. call basicConfig(). > > Regards, > > Vinay Sajip > Thanks for the explanation. JM From bavishi.darshak at gmail.com Mon Dec 13 05:20:29 2010 From: bavishi.darshak at gmail.com (Darshak Bavishi) Date: Mon, 13 Dec 2010 15:50:29 +0530 Subject: How to install pycrypto mode in windows ?! Message-ID: Hi Experts , I am using python 2.6 and i had installed paramiko module which needs pycrypto but , when i am installing pycrypto in windows its giving error as follows: creating build\lib.win32-2.6\Crypto\PublicKey copying .\PublicKey\DSA.py -> build\lib.win32-2.6\Crypto\PublicKey copying .\PublicKey\ElGamal.py -> build\lib.win32-2.6\Crypto\PublicKey copying .\PublicKey\pubkey.py -> build\lib.win32-2.6\Crypto\PublicKey copying .\PublicKey\qNEW.py -> build\lib.win32-2.6\Crypto\PublicKey copying .\PublicKey\RSA.py -> build\lib.win32-2.6\Crypto\PublicKey copying .\PublicKey\__init__.py -> build\lib.win32-2.6\Crypto\PublicKey running build_ext building 'Crypto.Hash.MD2' extension error: Unable to find vcvarsall.bat can u suggest any source to get pycrypto to avoid such events?! -- BR Darshak Bavishi -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at cheimes.de Mon Dec 13 05:33:03 2010 From: lists at cheimes.de (Christian Heimes) Date: Mon, 13 Dec 2010 11:33:03 +0100 Subject: How to install pycrypto mode in windows ?! In-Reply-To: References: Message-ID: Am 13.12.2010 11:20, schrieb Darshak Bavishi: > Hi Experts , > > I am using python 2.6 and i had installed paramiko module which needs > pycrypto but , > when i am installing pycrypto in windows its giving error as follows: > [...] > can u suggest any source to get pycrypto to avoid such events?! Well, your problem is that you are using the sources of pycrypto. vcvarsall.bat is a part of MS Visual Studio. You need either VS2008 or MinGW32 to compile the sources of Windows. Better look for precompiled binaries. Michael offers prebuild binaries on his site [1]. There are fine, I'm using them on Windows, too. Christian [1] http://www.voidspace.org.uk/python/modules.shtml#pycrypto From jeanmichel at sequans.com Mon Dec 13 05:40:20 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 13 Dec 2010 11:40:20 +0100 Subject: Python critique In-Reply-To: <52430F724D9B40DFB856FCDD172C28C8@teddy> References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com><4d028748$0$1621$742ec2ed@news.sonic.net> <4d02b47b$0$30000$c3e8da3$5496439d@news.astraweb.com> <52430F724D9B40DFB856FCDD172C28C8@teddy> Message-ID: <4D05F814.70505@sequans.com> Octavian Rasnita wrote: > From: "Steven D'Aprano" > ... > >>> Can you please tell me how to write the following program in Python? >>> >>> my $n = 1; >>> >>> { >>> my $n = 2; >>> print "$n\n"; >>> } >>> >>> print "$n\n"; >>> >>> If this program if ran in Perl, it prints: >>> 2 >>> 1 >>> >> Lots of ways. Here's one: >> >> >> n = 1 >> >> class Scope: >> n = 2 >> print n >> >> print n >> >> >> >> Here's another: >> >> n = 1 >> print (lambda n=2: n)() >> print n >> >> >> >> Here's a third: >> >> n = 1 >> >> def scope(): >> n = 2 >> print n >> >> scope() >> print n >> >> >> Here's a fourth: >> >> import sys >> n = 1 >> (sys.stdout.write("%d\n" % n) for n in (2,)).next() >> print n >> >> >> In Python 3, this can be written more simply: >> >> n = 1 >> [print(n) for n in (2,)] >> print n >> >> >> >> >>> I have tried to write it, but I don't know how I can create that block >>> because it tells that there is an unexpected indent. >>> >> Functions, closures, classes and modules are scopes in Python. If you >> want a new scope, create one of those. >> >> >> >> -- >> Steven >> > > > Hi Steven, > > Thank you for your message. It is very helpful for me. > I don't fully understand the syntax of all these variants yet, but I can see that there are more scopes in Python than I thought, and this is very good. > > Octavian > > Local scopes like described above by Steven are not constructs that are used that often, not to solve any scoping issue (except for the first example maybe). It's more a demonstration that you can do it with python. The reason is that Python developpers will not put themself in the situation where they need to use a variable 'orange' line 32 and use the same variable 'orange' line 33 to refer to something else. JM From jeanmichel at sequans.com Mon Dec 13 05:51:38 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 13 Dec 2010 11:51:38 +0100 Subject: default argument in method In-Reply-To: References: Message-ID: <4D05FABA.6090302@sequans.com> ernest wrote: > Hi, > > I'd like to have a reference to an instance attribute as > default argument in a method. It doesn't work because > "self" is not defined at the time the method signature is > evaluated. For example: > > class C(object): > def __init__(self): > self.foo = 5 > def m(self, val=self.foo): > return val > > Raises NameError because 'self' is not defined. > The obvious solution is put val=None in the signature > and set val to the appropriate value inside the method > (if val is None: ...), but I wonder if there's another way. > > Cheers, > Ernest > your 'val=None' is jus fine. JM From jeanmichel at sequans.com Mon Dec 13 06:04:57 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 13 Dec 2010 12:04:57 +0100 Subject: while True or while 1 In-Reply-To: <7xbp4q5d1n.fsf@ruckus.brouhaha.com> References: <4D051506.2060403@holdenweb.com> <4d05cb74$0$30003$c3e8da3$5496439d@news.astraweb.com> <7xbp4q5d1n.fsf@ruckus.brouhaha.com> Message-ID: <4D05FDD9.7010004@sequans.com> Paul Rubin wrote: > Steven D'Aprano writes: > >> I'm actually quite fond of the look of "while 1:", and sometimes use it, >> not because it's faster, but just because I like it. >> > > for v in itertools.repeat(True): > ... > > ;-) while '__For_ever___' not in ['nit-picking']: :) JM From felipe.vinturini at gmail.com Mon Dec 13 06:34:00 2010 From: felipe.vinturini at gmail.com (Felipe Vinturini) Date: Mon, 13 Dec 2010 09:34:00 -0200 Subject: Is there any way to SSH from Python ?! In-Reply-To: References: Message-ID: On Mon, Dec 13, 2010 at 3:11 AM, Darshak Bavishi wrote: > > i am trying from last week but no luck !! > > one thing only found that pexpect it not useful in windows > > pls help out of this > > On Mon, Dec 13, 2010 at 10:39 AM, Chris Rebert wrote: > >> On Sun, Dec 12, 2010 at 9:03 PM, Darshak Bavishi >> wrote: >> > Hi Experts, >> > I need to know that is there any way to SSH (From Windows Host) to Unix >> > machine ?! >> > If Yes than How ? >> >> http://www.lag.net/paramiko/ >> >> Did you try googling "ssh python"? >> >> Cheers, >> Chris >> -- >> http://blog.rebertia.com >> > > > > -- > BR > Darshak Bavishi > > -- > http://mail.python.org/mailman/listinfo/python-list > > Hi! Here is a good link about SSH and paramiko: http://jessenoller.com/2009/02/05/ssh-programming-with-paramiko-completely-different/ Regards, Felipe. -------------- next part -------------- An HTML attachment was scrubbed... URL: From bavishi.darshak at gmail.com Mon Dec 13 06:41:45 2010 From: bavishi.darshak at gmail.com (Darshak Bavishi) Date: Mon, 13 Dec 2010 17:11:45 +0530 Subject: Is there any way to SSH from Python ?! In-Reply-To: References: Message-ID: Hi, I have downloaded paramiko and installed it now it needs Pycrypto . So i tried to install pycrypto but its giving error of vcvarsall.bat so from christian suggestion i downloaded MinGW . But i have no idea how to install it in windows machine pls help me out of this!! On Mon, Dec 13, 2010 at 5:04 PM, Felipe Vinturini < felipe.vinturini at gmail.com> wrote: > > > On Mon, Dec 13, 2010 at 3:11 AM, Darshak Bavishi < > bavishi.darshak at gmail.com> wrote: > >> >> i am trying from last week but no luck !! >> >> one thing only found that pexpect it not useful in windows >> >> pls help out of this >> >> On Mon, Dec 13, 2010 at 10:39 AM, Chris Rebert wrote: >> >>> On Sun, Dec 12, 2010 at 9:03 PM, Darshak Bavishi >>> wrote: >>> > Hi Experts, >>> > I need to know that is there any way to SSH (From Windows Host) to Unix >>> > machine ?! >>> > If Yes than How ? >>> >>> http://www.lag.net/paramiko/ >>> >>> Did you try googling "ssh python"? >>> >>> Cheers, >>> Chris >>> -- >>> http://blog.rebertia.com >>> >> >> >> >> -- >> BR >> Darshak Bavishi >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > Hi! > > Here is a good link about SSH and paramiko: > http://jessenoller.com/2009/02/05/ssh-programming-with-paramiko-completely-different/ > > Regards, > Felipe. > -- BR Darshak Bavishi -------------- next part -------------- An HTML attachment was scrubbed... URL: From jnoller at gmail.com Mon Dec 13 06:51:46 2010 From: jnoller at gmail.com (Jesse Noller) Date: Mon, 13 Dec 2010 06:51:46 -0500 Subject: PyCon 2011 Registration and Financial aid open and available! Message-ID: Just q From jnoller at gmail.com Mon Dec 13 07:01:23 2010 From: jnoller at gmail.com (Jesse Noller) Date: Mon, 13 Dec 2010 07:01:23 -0500 Subject: PyCon 2011 Registration and Financial aid open and available! Message-ID: [Sorry for that last partial email] I wanted to take a moment and let everyone know that the PyCon 2011 Registration system is now online and accepting registrations for the conference! http://us.pycon.org/2011/tickets/ PyCon 2011 is looking to be the biggest, and most impressive PyCon yet, we've already booked one fantastic keynote speaker, and the program committee is hard at work selecting the talks for the conference - over 200 proposals were submitted! We're filling up the poster sessions, a stunning number of tutorials are being reviewed - this really does look like it's going to be huge. Financial aid is also open and available: http://us.pycon.org/2011/registration/financialaid/ Feel free to reach out to anyone on the PyCon 2011 team to ask any questions you might have. We look forward to seeing you in Atlanta. Jesse Noller PyCon 2011 From lists at cheimes.de Mon Dec 13 07:18:55 2010 From: lists at cheimes.de (Christian Heimes) Date: Mon, 13 Dec 2010 13:18:55 +0100 Subject: Is there any way to SSH from Python ?! In-Reply-To: References: Message-ID: Am 13.12.2010 12:41, schrieb Darshak Bavishi: > Hi, > > I have downloaded paramiko and installed it now it needs Pycrypto . So i > tried to install pycrypto but its giving error of vcvarsall.bat > so from christian suggestion i downloaded MinGW . But i have no idea how to > install it in windows machine Please use the prebuild Windows binaries from Michael Foord. Christian From awilliam at whitemice.org Mon Dec 13 09:04:38 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Mon, 13 Dec 2010 09:04:38 -0500 Subject: class browser In-Reply-To: <0c5c92c8-6a51-4ed3-aa29-cc6a2a40fa77@37g2000prx.googlegroups.com> References: <0c5c92c8-6a51-4ed3-aa29-cc6a2a40fa77@37g2000prx.googlegroups.com> Message-ID: <1292249078.7399.30.camel@linux-yu4c.site> On Sun, 2010-12-12 at 05:01 -0800, rusi wrote: > On Dec 8, 11:24 pm, Adam Tauno Williams > wrote: > > On Wed, 2010-12-08 at 13:18 +0530, Rustom Mody wrote: > > > If I have a medium to large python code base to browse/study, what are > > > the class browsers available? > > Monodevelop has good Python support which includes a working Python > > class browser for Python projects & solutions. > > > Ok downloaded mono. > How do I import an existing project? Just create a new Python project with the root of the project being the root of your existing project; then add the files [because you aren't really importing an existing project - there is no existing project - just a bunch of files and folders]. Monodevelop will create the required solution files for the advanced features. From bavishi.darshak at gmail.com Mon Dec 13 09:14:30 2010 From: bavishi.darshak at gmail.com (Darshak Bavishi) Date: Mon, 13 Dec 2010 19:44:30 +0530 Subject: AttributeError while running ssh (from windows) paramiko need help Message-ID: Hi Experts , while i am running following demo ssh script of paramiko --> *import base64* *import getpass* *import os* *import socket* *import sys* *import traceback* * * *import paramiko* *import interactive* * * * * *# setup logging* *paramiko.util.log_to_file('demo_simple.log')* * * *# get hostname* *username = ''* *if len(sys.argv) > 1:* * hostname = sys.argv[1]* * if hostname.find('@') >= 0:* * username, hostname = hostname.split('@')* *else:* * hostname = raw_input('Hostname: ')* *if len(hostname) == 0:* * print '*** Hostname required.'* * sys.exit(1)* *port = 22* *if hostname.find(':') >= 0:* * hostname, portstr = hostname.split(':')* * port = int(portstr)* * * * * *# get username* *if username == '':* * default_username = getpass.getuser()* * username = raw_input('Username [%s]: ' % default_username)* * if len(username) == 0:* * username = default_username* *password = getpass.getpass('Password for %s@%s: ' % (username, hostname))* * * * * *# get host key, if we know one* *hostkeytype = None* *hostkey = None* *try:* * host_keys = paramiko.util.load_host_keys(os.path.expanduser('~/.ssh/known_hosts'))* *except IOError:* * try:* * # try ~/ssh/ too, because windows can't have a folder named ~/.ssh/ * * host_keys = paramiko.util.load_host_keys(os.path.expanduser('~/ssh/known_hosts'))* * except IOError:* * print '*** Unable to open host keys file'* * host_keys = {}* * * *if host_keys.has_key(hostname):* * hostkeytype = host_keys[hostname].keys()[0]* * hostkey = host_keys[hostname][hostkeytype]* * print 'Using host key of type %s' % hostkeytype* * * * * *# now, connect and use paramiko Transport to negotiate SSH2 across the connection* *try:* * t = paramiko.Transport((hostname, port))* * t.connect(username=username, password=password, hostkey=hostkey)* * chan = t.open_session()* * chan.get_pty()* * chan.invoke_shell()* * print '*** Here we go!'* * print* * interactive.interactive_shell(chan)* * chan.close()* * t.close()* * * *except Exception, e:* * print '*** Caught exception: %s: %s' % (e.__class__, e)* * traceback.print_exc()* * try:* * t.close()* * except:* * pass* * sys.exit(1)* It gives error as follows : *Warning (from warnings module):* * File "C:\Python26\lib\site-packages\Crypto\Hash\SHA.py", line 6* * from sha import ** *DeprecationWarning: the sha module is deprecated; use the hashlib module instead* * * *Warning (from warnings module):* * File "C:\Python26\lib\site-packages\Crypto\Hash\MD5.py", line 6* * from md5 import ** *DeprecationWarning: the md5 module is deprecated; use hashlib instead* *Hostname: 10.135.15.41* *Username [admin]: root* * * *Warning (from warnings module):* * File "C:\Python26\lib\getpass.py", line 88* * return fallback_getpass(prompt, stream)* *GetPassWarning: Can not control echo on the terminal.* *Warning: Password input may be echoed.* *Password for root at 10.135.15.41: alcatel* **** Unable to open host keys file* **** Here we go!* * * *Line-buffered terminal emulation. Press F6 or ^Z to send EOF.* * * * * * * *Last login: Mon Dec 13 19:38:31 2010 from 10.135.19.50* * * * * **** Caught exception: : read* *Traceback (most recent call last):* * File "C:\Python26\paramiko-1.7.4\demos\demo_simple.py", line 90, in * * interactive.interactive_shell(chan)* * File "C:\Python26\paramiko-1.7.4\demos\interactive.py", line 36, in interactive_shell* * windows_shell(chan)* * File "C:\Python26\paramiko-1.7.4\demos\interactive.py", line 91, in windows_shell* * d = sys.stdin.read(1)* * File "C:\Python26\lib\idlelib\rpc.py", line 560, in __getattr__* * raise AttributeError, name* *AttributeError: read* * * * * **** EOF **** * * *Traceback (most recent call last):* * File "C:\Python26\paramiko-1.7.4\demos\demo_simple.py", line 101, in * * sys.exit(1)* *SystemExit: 1* * * *can you tell me what is use of Hostkey and how to overcome this issue?!* -- BR Darshak Bavishi -------------- next part -------------- An HTML attachment was scrubbed... URL: From ss.datics at gmail.com Mon Dec 13 09:44:55 2010 From: ss.datics at gmail.com (SS DATICS) Date: Mon, 13 Dec 2010 22:44:55 +0800 Subject: International Workshop: DATICS-ISPA'11 (EI Indexed) Message-ID: Dear authors, ===================================================================== International Workshop: DATICS-ISPA'11 CALL FOR PAPERS http://datics.nesea-conference.org/datics-ispa2011 Busan, Korea, 26-28 May, 2011. ===================================================================== Aims and Scope of DATICS-ISPA?11 Workshop: DATICS Workshops were initially created by a network of researchers and engineers both from academia and industry in the areas of Design, Analysis and Tools for Integrated Circuits and Systems. Recently, DATICS has been extended to the fields of Communication, Computer Science, Software Engineering and Information Technology. The main target of DATICS-ISPA?11 is to bring together software/hardware engineering researchers, computer scientists, practitioners and people from industry to exchange theories, ideas, techniques and experiences related to all aspects of DATICS. Topics of interest include, but are not limited to, the following: Circuits, Systems and Communications: digital, analog, mixed-signal, VLSI, asynchronous and RF design processor and memory DSP and FPGA/ASIC-based design synthesis and physical design embedded system hardware/software co-design CAD/EDA methodologies and tools statistical timing analysis and low power design methodologies network/system on-a-chip and applications hardware description languages, SystemC and SystemVerilog simulation, verification and test technology semiconductor devices and solid-state circuits fuzzy and neural networks communication signal processing mobile and wireless communications peer-to-peer video streaming and multimedia communications communication channel modeling antenna radio-wave propagation Computer Science, Software Engineering and Information Technology: equivalence checking, model checking, SAT-based methods, compositional methods and probabilistic methods graph theory, process algebras, petri-nets, automaton theory, BDDs and UML formal methods distributed, real-time and hybrid systems reversible computing and biocomputing software architecture and design software testing and analysis software dependability, safety and reliability programming languages, tools and environments face detection and recognition database and data mining image and video processing watermarking artificial intelligence average-case analysis and worst-case analysis design and programming methodologies for network protocols and applications coding, cryptography algorithms and security protocols evolutionary computation numerical algorithms e-commerce Please note that all accepted papers will be included in IEEE Xplore and indexed by EI Compendex. After workshop, several special issues of international journals such as IJDATICS and IJCECS will be arranged for selected papers. For more details about DATICS-ISPA'11, please visit http://datics.nesea-conference.org/datics-ispa2011 From rossgk at gmail.com Mon Dec 13 10:33:07 2010 From: rossgk at gmail.com (Ross) Date: Mon, 13 Dec 2010 07:33:07 -0800 (PST) Subject: unicode compare errors References: <549e0020-e21e-49c5-bc89-21122f9ce0a9@35g2000prb.googlegroups.com> Message-ID: <01f62ebd-f8c6-4765-a363-96da52ccd6d5@y19g2000prb.googlegroups.com> On Dec 10, 4:09?pm, Nobody wrote: > On Fri, 10 Dec 2010 11:51:44 -0800, Ross wrote: > > Since I can't control the encoding of the input file that users > > submit, how to I get past this? ?How do I make such comparisons be > > True? > On Fri, 10 Dec 2010 12:07:19 -0800, Ross wrote: > > I found I could import codecs that allow me to read the file with my > > desired encoding. Huzzah! > > If I'm off-base and kludgey here and should be doing something > > Er, do you know the file's encoding or don't you? Using: > > ? ? aFile = codecs.open(thisFile, encoding='utf-8') > > is telling Python that the file /is/ in utf-8. If it isn't in utf-8, > you'll get decoding errors. > > If you are given a file with no known encoding, then you can't reliably > determine what /characters/ it contains, and thus can't reliably compare > the contents of the file against strings of characters, only against > strings of bytes. > > About the best you can do is to use an autodetection library such as: > > ? ? ? ?http://chardet.feedparser.org/ That's right I don't know what encoding the user will have used. The use of autodetection sounds good - I'll look into that. Thx. R. From invalid at invalid.invalid Mon Dec 13 10:49:12 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 13 Dec 2010 15:49:12 +0000 (UTC) Subject: while True or while 1 References: <4d05434e$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-12-12, Steven D'Aprano wrote: > With the "while True" idiom in Python 2.x, you can easily exit out of an > infinite loop without using break: > >>>> while True: > ... print "Looping" > ... True = 0 > ... > Looping >>>> >>>> while True: # Execute an infinite loop in 0 seconds. > ... print "Looping" > ... >>>> > > *wink* Sadly, I've seen people do stuff like that in real programs... -- Grant Edwards grant.b.edwards Yow! I was making donuts at and now I'm on a bus! gmail.com From godson.g at gmail.com Mon Dec 13 12:14:27 2010 From: godson.g at gmail.com (Godson Gera) Date: Mon, 13 Dec 2010 22:44:27 +0530 Subject: default argument in method In-Reply-To: References: Message-ID: On Sun, Dec 12, 2010 at 5:05 PM, ernest wrote: > Hi, > > I'd like to have a reference to an instance attribute as > default argument in a method. It doesn't work because > "self" is not defined at the time the method signature is > evaluated. For example: > > class C(object): > def __init__(self): > self.foo = 5 > def m(self, val=self.foo): > return val > > Raises NameError because 'self' is not defined. > You can defined foo outside the __init__ and can access it inside methods using self.foo class C(object): foo=5 def __init__(self): print self.foo def m(self,val=foo): return val class attributes can be accessed with out self before them in method signatures. However, becareful if you change the value of foo inside any method, the method signature will still hold on to old value. -- Thanks & Regards, Godson Gera Python Consultant India -------------- next part -------------- An HTML attachment was scrubbed... URL: From bblais at bryant.edu Mon Dec 13 12:16:49 2010 From: bblais at bryant.edu (Brian Blais) Date: Mon, 13 Dec 2010 12:16:49 -0500 Subject: packaging and installing Message-ID: <50410C1D-2234-400A-8E1B-F78C4C3AA9D3@bryant.edu> Hello, I was wondering if there is any standard or suggested way of installing packages *without* going to the commandline. I often have students who, from there experience in Windows, have never looked at the commandline before and it is a bit of a challenge to get them to install something (i.e. go to the commandline, cd over to the proper folder, type python setup.py install, etc...). I've never seen a package with something like a "compileme.bat", but was wondering if there is some suggested way of doing this or some reasons *not* to do this. I can always write my own (1-line) .bat file, but I didn't want to reinvent the wheel. Perhaps there is a better way for me to do this, ideally in a platform independent way. thanks, Brian Blais -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais http://bblais.blogspot.com/ From godson.g at gmail.com Mon Dec 13 12:30:25 2010 From: godson.g at gmail.com (Godson Gera) Date: Mon, 13 Dec 2010 23:00:25 +0530 Subject: packaging and installing In-Reply-To: <50410C1D-2234-400A-8E1B-F78C4C3AA9D3@bryant.edu> References: <50410C1D-2234-400A-8E1B-F78C4C3AA9D3@bryant.edu> Message-ID: On Mon, Dec 13, 2010 at 10:46 PM, Brian Blais wrote: > Hello, > > I was wondering if there is any standard or suggested way of installing > packages *without* going to the commandline. I often have students who, > from there experience in Windows, have never looked at the commandline > before and it is a bit of a challenge to get them to install something (i.e. > go to the commandline, cd over to the proper folder, type python setup.py > install, etc...). I've never seen a package with something like a > "compileme.bat", but was wondering if there is some suggested way of doing > this or some reasons *not* to do this. I can always write my own (1-line) > .bat file, but I didn't want to reinvent the wheel. Perhaps there is a > better way for me to do this, ideally in a platform independent way. > You don't even have to write a bat file. Python's distutils package allows you to build exe file which creates generic windows wizard window for installing packages. Take a look at distutils package http://docs.python.org/distutils/builtdist.html -- Thanks & Regards, Godson Gera Asterisk consultant India -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Mon Dec 13 12:45:43 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 13 Dec 2010 12:45:43 -0500 Subject: default argument in method In-Reply-To: References: Message-ID: On 12/13/2010 12:14 PM, Godson Gera wrote: > > > On Sun, Dec 12, 2010 at 5:05 PM, ernest > wrote: > > Hi, > > I'd like to have a reference to an instance attribute as > default argument in a method. It doesn't work because > "self" is not defined at the time the method signature is > evaluated. For example: > > class C(object): > def __init__(self): > self.foo = 5 > def m(self, val=self.foo): > return val > > Raises NameError because 'self' is not defined. > > > You can defined foo outside the __init__ and can access it inside > methods using self.foo > > class C(object): > foo=5 > def __init__(self): > print self.foo > def m(self,val=foo): > return val > > class attributes can be accessed with out self before them in method > signatures. However, becareful if you change the value of foo inside any > method, the method signature will still hold on to old value. > You are, of course, correct. It might be more accurate to say that if C.foo is rebound this does not change the binding of the val default value. "Change the value of foo" could be though to include "mutate a mutable value", but in that case both C.foo and the method's val parameter would still be bound to the same object. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From sridharr at activestate.com Mon Dec 13 13:08:48 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Mon, 13 Dec 2010 10:08:48 -0800 Subject: ANN: ActivePython 2.7.1.3 is now available Message-ID: ActiveState is pleased to announce ActivePython 2.7.1.3, a complete, ready-to-install binary distribution of Python 2.7. http://www.activestate.com/activepython/downloads What's New in ActivePython-2.7.1.3 ================================== *Release date: 6-Dec-2010* New Features & Upgrades ----------------------- - Upgrade to Python 2.7.1 (`release notes `__) - Upgrade to Tcl/Tk 8.5.9 (`changes `_) - Security upgrade to openssl-0.9.8q - [MacOSX] Tkinter now requires ActiveTcl 8.5 64-bit (not Apple's Tcl/Tk 8.5 on OSX) - Upgrade to PyPM 1.2.6; noteworthy changes: - New command 'pypm log' to view log entries for last operation - Faster startup (performance) especially on Windows. - Rewrite of an improved dependency algorithm (#88038) - install/uninstall now accepts the --nodeps option - 'pypm install ' to directly download and install a .pypm file - 'pypm show' improvements - 'pypm show' shows other installed packages depending on the shown package - 'pypm show' accepts --rdepends to show the list of dependents - 'pypm show' shows extra dependencies (for use in the 'install' cmd) - 'pypm show' lists all available versions in the repository - 'pypm freeze' to dump installed packages as requirements (like 'pip freeze') - Support for pip-stye requirements file ('pypm install -r requirements.txt') - Upgraded the following packages: - Distribute-0.6.14 - pip-0.8.2 - SQLAlchemy-0.6.5 - virtualenv-1.5.1 Noteworthy Changes & Bug Fixes ------------------------------ - Bug #87951: Exclude PyPM install db to prevent overwriting user's database. - Bug #87600: create a `idleX.Y` script on unix - [Windows] Installer upgrade: automatically uninstall previous versions - Bug #87783 - [Windows] Renamed "python27.exe" to "python2.7.exe" (Unix like) - [Windows] Include "python2.exe" - PyPM bug fixes: - Bug #88882: Fix pickle incompatability (sqlite) on Python 3.x - Bug #87764: 'pypm upgrade' will not error out for missing packages - Bug #87902: fix infinite loops with cyclic package dependencies (eg: plone) - Bug #88370: Handle file-overwrite conflicts (implement --force) What is ActivePython? ===================== ActivePython is ActiveState's binary distribution of Python. Builds for Windows, Mac OS X, Linux are made freely available. Solaris, HP-UX and AIX builds, and access to older versions are available in ActivePython Business, Enterprise and OEM editions: http://www.activestate.com/python ActivePython includes the Python core and the many core extensions: zlib and bzip2 for data compression, the Berkeley DB (bsddb) and SQLite (sqlite3) database libraries, OpenSSL bindings for HTTPS support, the Tix GUI widgets for Tkinter, ElementTree for XML processing, ctypes (on supported platforms) for low-level library access, and others. The Windows distribution ships with PyWin32 -- a suite of Windows tools developed by Mark Hammond, including bindings to the Win32 API and Windows COM. ActivePython 2.6, 2.7 and 3.1 also include a binary package manager for Python (PyPM) that can be used to install packages much easily. For example: C:\>pypm install mysql-python [...] C:\>python >>> import MySQLdb >>> See this page for full details: http://docs.activestate.com/activepython/2.7/whatsincluded.html As well, ActivePython ships with a wealth of documentation for both new and experienced Python programmers. In addition to the core Python docs, ActivePython includes the "What's New in Python" series, "Dive into Python", the Python FAQs & HOWTOs, and the Python Enhancement Proposals (PEPs). An online version of the docs can be found here: http://docs.activestate.com/activepython/2.7/ We would welcome any and all feedback to: activepython-feedback at activestate.com Please file bugs against ActivePython at: http://bugs.activestate.com/enter_bug.cgi?product=ActivePython Supported Platforms =================== ActivePython is available for the following platforms: - Windows (x86 and x64) - Mac OS X (x86 and x86_64; 10.5+) - Linux (x86 and x86_64) - Solaris/SPARC (32-bit and 64-bit) (Business, Enterprise or OEM edition only) - Solaris/x86 (32-bit) (Business, Enterprise or OEM edition only) - HP-UX/PA-RISC (32-bit) (Business, Enterprise or OEM edition only) - HP-UX/IA-64 (32-bit and 64-bit) (Enterprise or OEM edition only) - AIX/PowerPC (32-bit and 64-bit) (Business, Enterprise or OEM edition only) More information about the Business Edition can be found here: http://www.activestate.com/business-edition Custom builds are available in the Enterprise Edition: http://www.activestate.com/enterprise-edition Thanks, and enjoy! The Python Team -- Sridhar Ratnakumar Python Developer ActiveState, The Dynamic Language Experts sridharr at activestate.com http://www.activestate.com Get insights on Open Source and Dynamic Languages at www.activestate.com/blog From python at bdurham.com Mon Dec 13 13:38:59 2010 From: python at bdurham.com (python at bdurham.com) Date: Mon, 13 Dec 2010 13:38:59 -0500 Subject: ANN: ActivePython 2.7.1.3 is now available In-Reply-To: References: Message-ID: <1292265539.4906.1410124185@webmail.messagingengine.com> Sridhar, Do the Windows versions of ActivePython 2.7.1.3 have different versions of Tcl/Tk, sqlite3(.dll), and/or openssl (_ssl.pyd?) than the python.org builds of Python 2.7.1? Thank you, Malcolm From sridharr at activestate.com Mon Dec 13 13:48:27 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Mon, 13 Dec 2010 10:48:27 -0800 Subject: ANN: ActivePython 2.7.1.3 is now available In-Reply-To: <1292265539.4906.1410124185@webmail.messagingengine.com> References: <1292265539.4906.1410124185@webmail.messagingengine.com> Message-ID: On 2010-12-13, at 10:38 AM, python at bdurham.com wrote: > [SRID] Release notes for 2.7.1.3 [...] > [SRID] - Upgrade to Tcl/Tk 8.5.9 (`changes `_) > Do the Windows versions of ActivePython 2.7.1.3 have different versions > of Tcl/Tk, sqlite3(.dll), and/or openssl (_ssl.pyd?) than the python.org > builds of Python 2.7.1? You can find the versions used in ActivePython here, http://docs.activestate.com/activepython/2.7/whatsincluded.html We generally build with the latest compatible version of extensions (except for Tcl/Tk on 2.5/2.6/3.1 as python.org still uses 8.4) ... but that should not be an issue with 2.7 as I believe that the python.org MSI installer is now using Tcl/Tk 8.5 (albeit with an older patch-level version?) to support the new `ttk` module in 2.7+. Does that answer your query? -srid From chambon.pascal at wanadoo.fr Mon Dec 13 13:53:31 2010 From: chambon.pascal at wanadoo.fr (Pascal Chambon) Date: Mon, 13 Dec 2010 19:53:31 +0100 Subject: Directly calling python's function arguments dispatcher In-Reply-To: References: Message-ID: <4D066BAB.6020707@wanadoo.fr> Le 12/12/2010 23:41, Peter Otten a ?crit : > Pascal Chambon wrote: > > > >> I've encountered several times, when dealing with adaptation of function >> signatures, the need for explicitly resolving complex argument sets into >> a simple variable mapping. Explanations. >> >> >> Consider that function: >> >> def foo(a1, a2, *args, **kwargs): >> pass >> >> calling foo(1, a2=2, a3=3) >> >> will map these arguments to local variables like these: >> { >> 'a1': 1, >> 'a2': 2, >> 'args': tuple(), >> 'kwarg's: {'a3': 3} >> } >> >> That's a quite complex resolution mechanism, which must handle >> positional and keyword arguments, and deal with both collision and >> missing argument cases. >> > >> Is that routine exposed to python, somewhere ? Does anybody know a >> working implementation here or there ? >> > http://docs.python.org/library/inspect.html#inspect.getcallargs > > Too sweeeeeeeeeet \o/ Thanks a lot, regards, Pakal From arnodel at gmail.com Mon Dec 13 14:09:22 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Mon, 13 Dec 2010 19:09:22 +0000 Subject: Exception handling in Python 3.x References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> <7xmxoi8v0b.fsf@ruckus.brouhaha.com> Message-ID: <87wrnd7an1.fsf@gmail.com> Paul Rubin writes: > Steven D'Aprano writes: >> Apart from this horrible idiom: >> >> def func(iterable): >> it = iter(iterable) >> failed = False >> try: >> x = next(it) >> except StopIteration: >> failed = True >> if failed: >> raise ValueError("can't process empty iterable") >> print(x) >> >> >> or similar, is there really no way to avoid these chained exceptions? > > Seems like yet another example of people doing messy things with > exceptions that can easily be done with iterators and itertools: > > from itertools import islice > > def func(iterable): > xs = list(islice(iter(iterable), 1)) > if len(xs) == 0: > raise ValueError(...) > print xs[0] > > It's really unfortunate, though, that Python 3 didn't offer a way to > peek at the next element of an iterable and test emptiness directly. I missed the start of this discussion but there are two simpler ways: def func(iterable): for x in iterable: print(x) return raise ValueError("... empty iterable") Or using 3.x's next's optional second argument: _nonext=object() def func(iterable): x = next(iter(iterable), _nonext) if x is _nonext: raise ValueError("... empty iterable") print(x) -- Arnaud From python at bdurham.com Mon Dec 13 14:16:33 2010 From: python at bdurham.com (python at bdurham.com) Date: Mon, 13 Dec 2010 14:16:33 -0500 Subject: ANN: ActivePython 2.7.1.3 is now available In-Reply-To: References: <1292265539.4906.1410124185@webmail.messagingengine.com> Message-ID: <1292267793.18518.1410132979@webmail.messagingengine.com> Sridhar, > You can find the versions used in ActivePython here, > http://docs.activestate.com/activepython/2.7/whatsincluded.html Thank you - that page answered my questions. Malcolm From tjreedy at udel.edu Mon Dec 13 14:50:05 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 13 Dec 2010 14:50:05 -0500 Subject: ANN: ActivePython 2.7.1.3 is now available In-Reply-To: References: <1292265539.4906.1410124185@webmail.messagingengine.com> Message-ID: On 12/13/2010 1:48 PM, Sridhar Ratnakumar wrote: > We generally build with the latest compatible version of extensions > (except for Tcl/Tk on 2.5/2.6/3.1 as python.org still uses 8.4) ... The PSF 3.1 Windows installer ships with tcl/tk 8.5 and ttk support. You ought to too. > but that should not be an issue with 2.7 as I believe that the > python.org MSI installer is now using Tcl/Tk 8.5 (albeit with an > older patch-level version?) to support the new `ttk` module in 2.7+. For 3.1.3 and 3.2, the tcl/tk85.libs are dated 8/28/2010. Don't know what that means though. Terry Jan Reedy From Rob.Richardson at rad-con.com Mon Dec 13 14:56:02 2010 From: Rob.Richardson at rad-con.com (Rob Richardson) Date: Mon, 13 Dec 2010 14:56:02 -0500 Subject: Exception handling in Python 3.x In-Reply-To: <87wrnd7an1.fsf@gmail.com> Message-ID: <04A6DB42D2BA534FAC77B90562A6A03D01689233@server.rad-con.local> Arnaud, Wouldn't your first suggestion exit after the first element in iterable? And would your second suggestion throw an exception after normal processing of all elements in the interator? RobR -----Original Message----- I missed the start of this discussion but there are two simpler ways: def func(iterable): for x in iterable: print(x) return raise ValueError("... empty iterable") Or using 3.x's next's optional second argument: _nonext=object() def func(iterable): x = next(iter(iterable), _nonext) if x is _nonext: raise ValueError("... empty iterable") print(x) -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list From arnodel at gmail.com Mon Dec 13 15:19:27 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Mon, 13 Dec 2010 20:19:27 +0000 Subject: Request for feedback on API design References: <4d0169e2$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87sjy177e8.fsf@gmail.com> Steven D'Aprano writes: > I am soliciting feedback regarding the API of my statistics module: > > http://code.google.com/p/pycalcstats/ > > > Specifically the following couple of issues: > > (1) Multivariate statistics such as covariance have two obvious APIs: > > A pass the X and Y values as two separate iterable arguments, e.g.: > cov([1, 2, 3], [4, 5, 6]) > > B pass the X and Y values as a single iterable of tuples, e.g.: > cov([(1, 4), (2, 5), (3, 6)] > > I currently support both APIs. Do people prefer one, or the other, or > both? If there is a clear preference for one over the other, I may drop > support for the other. > I don't have an informed opinion on this. > (2) Statistics text books often give formulae in terms of sums and > differences such as > > Sxx = n*?(x**2) - (?x)**2 Interestingly, your Sxx is closely related to the variance: if x is a list of n numbers then Sxx == (n**2)*var(x) And more generally if x and y have the same length n, then Sxy (*) is related to the covariance Sxy == (n**2)*cov(x, y) So if you have a variance and covariance function, it would be redundant to include Sxx and Sxy. Another argument against including Sxx & co is that their definition is not universally agreed upon. For example, I have seen Sxx = ?(x**2) - (?x)**2/n HTH -- Arnaud (*) Here I take Sxy to be n*?(xy) - (?x)(?y), generalising from your definition of Sxx. From arnodel at gmail.com Mon Dec 13 15:39:19 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Mon, 13 Dec 2010 20:39:19 +0000 Subject: Exception handling in Python 3.x References: Message-ID: <87oc8p76h4.fsf@gmail.com> "Rob Richardson" writes: You shouldn't top-post! > Arnaud, > > Wouldn't your first suggestion exit after the first element in iterable? Yes, after printing that element, which is what the code I quoted did. > And would your second suggestion throw an exception after normal > processing of all elements in the interator? No. It would have the same behaviour as the first one. > RobR > > -----Original Message----- > > > I missed the start of this discussion but there are two simpler ways: > > def func(iterable): > for x in iterable: > print(x) > return > raise ValueError("... empty iterable") > > Or using 3.x's next's optional second argument: > > _nonext=object() > def func(iterable): > x = next(iter(iterable), _nonext) > if x is _nonext: > raise ValueError("... empty iterable") > print(x) > > -- > Arnaud -- Arnaud From ethan at stoneleaf.us Mon Dec 13 15:44:28 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 13 Dec 2010 12:44:28 -0800 Subject: Exception handling in Python 3.x In-Reply-To: <04A6DB42D2BA534FAC77B90562A6A03D01689233@server.rad-con.local> References: <04A6DB42D2BA534FAC77B90562A6A03D01689233@server.rad-con.local> Message-ID: <4D0685AC.6070907@stoneleaf.us> Please don't top-post. Rob Richardson wrote: >> -----Original Message----- >> >> >> I missed the start of this discussion but there are two simpler ways: >> >> def func(iterable): >> for x in iterable: >> print(x) >> return >> raise ValueError("... empty iterable") >> >> Or using 3.x's next's optional second argument: >> >> _nonext=object() >> def func(iterable): >> x = next(iter(iterable), _nonext) >> if x is _nonext: >> raise ValueError("... empty iterable") >> print(x) > Arnaud, > > Wouldn't your first suggestion exit after the first element in > iterable? No, it hit's return instead. > And would your second suggestion throw an exception after normal > processing of all elements in the interator? Looks like the second solution doesn't process the entire iterable, just it's first element. ~Ethan~ From ethan at stoneleaf.us Mon Dec 13 15:46:31 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 13 Dec 2010 12:46:31 -0800 Subject: Exception handling in Python 3.x In-Reply-To: <87wrnd7an1.fsf@gmail.com> References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> <7xmxoi8v0b.fsf@ruckus.brouhaha.com> <87wrnd7an1.fsf@gmail.com> Message-ID: <4D068627.3030705@stoneleaf.us> Arnaud Delobelle wrote: > > I missed the start of this discussion but there are two simpler ways: > > def func(iterable): > for x in iterable: > print(x) > return > raise ValueError("... empty iterable") For the immediate case this is a cool solution. Unfortunately, it doesn't fix the unwanted nesting of exceptions problem. ~Ethan~ From ethan at stoneleaf.us Mon Dec 13 16:19:44 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 13 Dec 2010 13:19:44 -0800 Subject: Exception handling in Python 3.x In-Reply-To: <4D0685AC.6070907@stoneleaf.us> References: <04A6DB42D2BA534FAC77B90562A6A03D01689233@server.rad-con.local> <4D0685AC.6070907@stoneleaf.us> Message-ID: <4D068DF0.3000806@stoneleaf.us> Ethan Furman wrote: > Please don't top-post. > > Rob Richardson wrote: > >>> -----Original Message----- >>> >>> >>> I missed the start of this discussion but there are two simpler ways: >>> >>> def func(iterable): >>> for x in iterable: >>> print(x) >>> return >>> raise ValueError("... empty iterable") >>> >>> Or using 3.x's next's optional second argument: >>> >>> _nonext=object() >>> def func(iterable): >>> x = next(iter(iterable), _nonext) >>> if x is _nonext: >>> raise ValueError("... empty iterable") >>> print(x) > > > > Arnaud, > > > > Wouldn't your first suggestion exit after the first element in > > iterable? > > No, it hit's return instead. Doh -- Yes, it does. It seems both solutions only get the first element, not all elements in the iterator... Maybe this instead: def func(iterable): for x in iterable: break else: raise ValueError("... empty iterable") for xx in chain((x, ), iterable): process(xx) Can't say as I care for this -- better to fix the unwanted nesting in the tracebacks from raise. ~Ethan~ From godson.g at gmail.com Mon Dec 13 16:20:40 2010 From: godson.g at gmail.com (Godson Gera) Date: Tue, 14 Dec 2010 02:50:40 +0530 Subject: Is there any way to SSH from Python ?! In-Reply-To: References: Message-ID: On Mon, Dec 13, 2010 at 10:33 AM, Darshak Bavishi wrote: > Hi Experts, > > I need to know that is there any way to SSH (From Windows Host) to Unix > machine ?! > > If Yes than How ? > > Because when i use telenet it not showing the no result !! As earlier it > was suggested that i should try with exit first and than read_all() > but still issue persist and getting hang > > import getpass > import sys > import telnetlib > import time > HOST = "*.*.*.*" > #user = raw_input("Enter your remote account: ") > #password = getpass.getpass() > user = "Darshak2" > password = "****" > tn = telnetlib.Telnet(HOST , 5400) > print "1" > tn.read_until("login:" , 5) > print "2" > tn.write(user + "\n") > print "3" > if password: > tn.read_until("Password: ") > tn.write(password + "\n") > > print "4" > tn.write("set alarm = off" + "\n") > tn.write("set event = off" + "\n") > print "5" > tn.write("Cd > /Office-Parameters/Mobility-Config-Parameters/Subscriber-Query-by-IMSI-MSISDN-or-IMEI" > + "\n") > print "6" > tn.write("\n") > tn.write("\n") > tn.write("vlrsubquery msisdn=***" + "\n") > tn.write("\n") > tn.write("exit" + "\n") > print tn.read_all() > tn.close() > > -- > BR > Darshak Bavishi > > -- > http://mail.python.org/mailman/listinfo/python-list > > you can try read_very_eager() which won't block. Twisted has complete support for SSH check it out http://twistedmatrix.com -- Thanks & Regards, Godson Gera Asterisk Consultant India -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Mon Dec 13 16:23:09 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 13 Dec 2010 13:23:09 -0800 Subject: Exception handling in Python 3.x In-Reply-To: <4D068627.3030705@stoneleaf.us> References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> <7xmxoi8v0b.fsf@ruckus.brouhaha.com> <87wrnd7an1.fsf@gmail.com> <4D068627.3030705@stoneleaf.us> Message-ID: <4D068EBD.2040102@stoneleaf.us> Ethan Furman wrote: > Arnaud Delobelle wrote: >> >> I missed the start of this discussion but there are two simpler ways: >> >> def func(iterable): >> for x in iterable: >> print(x) >> return >> raise ValueError("... empty iterable") > > > For the immediate case this is a cool solution. Drat -- I have to take that back -- the OP stated: > The intention is: > > * detect an empty iterator by catching StopIteration; > * if the iterator is empty, raise a ValueError; > * otherwise process the iterator. Presumably, the print(x) would be replaced with code that processed the entire iterable (including x, of course), and not just its first element. ~Ethan~ From sridharr at activestate.com Mon Dec 13 16:23:59 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Mon, 13 Dec 2010 13:23:59 -0800 Subject: ANN: ActivePython 2.7.1.3 is now available In-Reply-To: References: <1292265539.4906.1410124185@webmail.messagingengine.com> Message-ID: <8D0BABA0-44C4-45C9-BAC6-28F9BD06B340@activestate.com> On 2010-12-13, at 11:50 AM, Terry Reedy wrote: > On 12/13/2010 1:48 PM, Sridhar Ratnakumar wrote: > >> We generally build with the latest compatible version of extensions >> (except for Tcl/Tk on 2.5/2.6/3.1 as python.org still uses 8.4) ... > > The PSF 3.1 Windows installer ships with tcl/tk 8.5 and ttk support. > You ought to too. ActivePython (APy) 2.5+/3.1+ already use Tcl/Tk 8.5 ... I was referring to the PSF installers (hence the mismatch in versions between APy and PSF). Maybe that was changed in 3.1.3. >> but that should not be an issue with 2.7 as I believe that the >> python.org MSI installer is now using Tcl/Tk 8.5 (albeit with an >> older patch-level version?) to support the new `ttk` module in 2.7+. > > For 3.1.3 and 3.2, the tcl/tk85.libs are dated 8/28/2010. Don't know what that means though. I did this for ActivePython 2.7, >>> import Tkinter >>> root = Tkinter.Tk() >>> root.tk.eval('info patchlevel') '8.5.9' >>> -srid From arnodel at gmail.com Mon Dec 13 16:43:31 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Mon, 13 Dec 2010 21:43:31 +0000 Subject: Exception handling in Python 3.x References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> <7xmxoi8v0b.fsf@ruckus.brouhaha.com> <87wrnd7an1.fsf@gmail.com> <4D068627.3030705@stoneleaf.us> Message-ID: <87k4jd73i4.fsf@gmail.com> Ethan Furman writes: > Ethan Furman wrote: >> Arnaud Delobelle wrote: >>> >>> I missed the start of this discussion but there are two simpler ways: >>> >>> def func(iterable): >>> for x in iterable: >>> print(x) >>> return >>> raise ValueError("... empty iterable") >> >> >> For the immediate case this is a cool solution. > > > Drat -- I have to take that back -- the OP stated: > >> The intention is: >> >> * detect an empty iterator by catching StopIteration; >> * if the iterator is empty, raise a ValueError; >> * otherwise process the iterator. > > > Presumably, the print(x) would be replaced with code that processed > the entire iterable (including x, of course), and not just its first > element. As I had stated before, I didn't where the discussion started from. I replied to code posted by Steven D'Aprano and Paul Rubin. My code snippet was equivalent in functionality to theirs, only a little simpler. Now if one wants to raise an exception if an iterator is empty, else process it somehow, it must mean that the iterator needs to have at least one element for the processing to be meaningful and so it can be thought of as a function of one element and of one iterator: process(first, others) which never needs to raise an exception (at least related to the number of items in the iterator). Therefore you can write your function as follows: def func(iterable): iterator = iter(iterable) for first in iterable: return process(first, iterator) else: raise ValueError("need non-empty iterable") -- Arnaud From ethan at stoneleaf.us Mon Dec 13 16:44:00 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 13 Dec 2010 13:44:00 -0800 Subject: Request for feedback on API design In-Reply-To: <4d0169e2$0$30002$c3e8da3$5496439d@news.astraweb.com> References: <4d0169e2$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4D0693A0.3030707@stoneleaf.us> Steven D'Aprano wrote: > I am soliciting feedback regarding the API of my statistics module: > > http://code.google.com/p/pycalcstats/ > > > Specifically the following couple of issues: > > (1) Multivariate statistics such as covariance have two obvious APIs: > > A pass the X and Y values as two separate iterable arguments, e.g.: > cov([1, 2, 3], [4, 5, 6]) > > B pass the X and Y values as a single iterable of tuples, e.g.: > cov([(1, 4), (2, 5), (3, 6)] > > I currently support both APIs. Do people prefer one, or the other, or > both? If there is a clear preference for one over the other, I may drop > support for the other. > Don't currently need/use stats, but B seems clearer to me. ~Ethan~ From news1234 at free.fr Mon Dec 13 16:51:35 2010 From: news1234 at free.fr (News123) Date: Mon, 13 Dec 2010 22:51:35 +0100 Subject: run a function in another processor in python In-Reply-To: References: Message-ID: <4d069567$0$28575$426a34cc@news.free.fr> On 12/09/2010 10:54 AM, Astan Chee wrote: > Hi, > I've got a python script that calls a function many times with various > arguments and returns a result. What I'm trying to do is run this > function each on different processors and compile the result at the > end based on the function result. The script looks something like > this: > > You could look at the multiprocessing module of pythonhttp://docs.python.org/library/multiprocessing.html From rhodri at wildebst.demon.co.uk Mon Dec 13 17:33:42 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Mon, 13 Dec 2010 22:33:42 -0000 Subject: Sage's Python References: Message-ID: On Fri, 10 Dec 2010 17:11:55 -0000, Akand Islam wrote: > In my system (Ubuntu 10.04) there are sage-4.6, python 2.6.5, tk8.5- > dev installed. When I give command from terminal "sage -f > python-2.6.5.p8" to get sage's python it shows following message: > > No command 'sage' found, did you mean: > Command 'save' from package 'atfs' (universe) > Command 'page' from package 'tcllib' (universe) > sage: command not found > > How can I get Sage's python to be worked so that I can import sage.all > in python shell? The fact that you have no executable called "sage" suggests that you haven't actually installed it yet. Check the Sage website, which has plenty of documentation, and try to figure out where you left the path on whichever method you used. -- Rhodri James *-* Wildebeest Herder to the Masses From kikkocristian at gmail.com Mon Dec 13 17:38:07 2010 From: kikkocristian at gmail.com (Cristian Consonni) Date: Mon, 13 Dec 2010 23:38:07 +0100 Subject: "Download/windows" site page Message-ID: Dear all, I'm not sure this is the right place to point this out, but on this page: http://www.python.org/download/windows/ It is not mentioned "Windows 7". Is there some problem with 7 or it is simply an omission? A friend of mine is refusing to install python on his machine because "it does not say it is compatible with Windows 7" (sic). So, may somebody fix that? Thanks in advance. Cristian From martin at v.loewis.de Mon Dec 13 17:56:23 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Mon, 13 Dec 2010 23:56:23 +0100 Subject: "Download/windows" site page In-Reply-To: References: Message-ID: <4D06A497.2040704@v.loewis.de> Am 13.12.2010 23:38, schrieb Cristian Consonni: > Dear all, > > I'm not sure this is the right place to point this out, but on this page: > > http://www.python.org/download/windows/ > > It is not mentioned "Windows 7". > > Is there some problem with 7 or it is simply an omission? It's simply an omission. You'll notice that Windows 2003 and Windows 2008, as well as Windows 2003 R2 and Windows 2008R2 are omitted as well. Likely, Python also works on Windows Media Center Edition, which is also omitted. > So, may somebody fix that? I'd rather not fix it by adding all product names that Microsoft has used for Windows. How about "Microsoft Windows (XP and later releases)"? Regards, Martin From martin at v.loewis.de Mon Dec 13 17:56:23 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Mon, 13 Dec 2010 23:56:23 +0100 Subject: "Download/windows" site page In-Reply-To: References: Message-ID: <4D06A497.2040704@v.loewis.de> Am 13.12.2010 23:38, schrieb Cristian Consonni: > Dear all, > > I'm not sure this is the right place to point this out, but on this page: > > http://www.python.org/download/windows/ > > It is not mentioned "Windows 7". > > Is there some problem with 7 or it is simply an omission? It's simply an omission. You'll notice that Windows 2003 and Windows 2008, as well as Windows 2003 R2 and Windows 2008R2 are omitted as well. Likely, Python also works on Windows Media Center Edition, which is also omitted. > So, may somebody fix that? I'd rather not fix it by adding all product names that Microsoft has used for Windows. How about "Microsoft Windows (XP and later releases)"? Regards, Martin From mpnordland at gmail.com Mon Dec 13 18:04:22 2010 From: mpnordland at gmail.com (mpnordland) Date: Mon, 13 Dec 2010 15:04:22 -0800 (PST) Subject: Catching user switching and getting current active user from root on linux References: <1a9bdbd4-2997-4e0f-a24f-cd148247e312@r40g2000prh.googlegroups.com> <8739qhs6dz.fsf.mdw@metalzone.distorted.org.uk> <797ba948-c608-4ed5-b2eb-25177932da91@o4g2000yqd.googlegroups.com> <4d04117b$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: <51d9390d-be72-49fe-a63b-5a05832c53e8@fu15g2000vbb.googlegroups.com> I think I do understand multiuser systems, although I'm sorry I did not make my self clear. Yes, I understand that there can be multiple people logged in, and yes if you really wanted to, you could login as yourself as many times as you want. This is not a server based program, it is intended for use in a normal environment. The people using it will probably not be logging in multiple times as themselves, or someone else. The problem I have is I want monitor what sites the user visits, I need to know what sites were accessed by which user. So, a way to find which user is requesting what url is what I want. Have I passed the Turing test? From emekamicro at gmail.com Mon Dec 13 18:06:05 2010 From: emekamicro at gmail.com (Emeka) Date: Tue, 14 Dec 2010 00:06:05 +0100 Subject: Tkinter's unbind method Message-ID: Hello All I have an uncompleted version of a game http://pastebin.com/gkhTaYPZ I am trying to code.... I have struggled to make method unbind work. But it has refused to listen to me. Could someone come to my help? Regards, Emeka http://pastebin.com/gkhTaYPZ -- *Satajanus Nig. Ltd * -------------- next part -------------- An HTML attachment was scrubbed... URL: From kikkocristian at gmail.com Mon Dec 13 18:15:33 2010 From: kikkocristian at gmail.com (Cristian Consonni) Date: Tue, 14 Dec 2010 00:15:33 +0100 Subject: "Download/windows" site page In-Reply-To: <4D06A497.2040704@v.loewis.de> References: <4D06A497.2040704@v.loewis.de> Message-ID: 2010/12/13 Martin v. Loewis : [...] >> It is not mentioned "Windows 7". >> >> Is there some problem with 7 or it is simply an omission? > > It's simply an omission. You'll notice that Windows 2003 and Windows > 2008, as well as Windows 2003 R2 and Windows 2008R2 are omitted as > well. Likely, Python also works on Windows Media Center Edition, which > is also omitted. > >> So, may somebody fix that? > > I'd rather not fix it by adding all product names that Microsoft has > used for Windows. How about "Microsoft Windows (XP and later releases)"? Sounds as a reasonable solution to me. Thank you. Cristian From javiervandam at gmail.com Mon Dec 13 18:29:52 2010 From: javiervandam at gmail.com (javivd) Date: Mon, 13 Dec 2010 15:29:52 -0800 (PST) Subject: Reading by positions plain text files References: <39a07597-02b9-4ef8-9ca9-93e2d2425e66@p7g2000prb.googlegroups.com> Message-ID: <35a7413f-47c3-439d-b480-4cc905e49c40@fu15g2000vbb.googlegroups.com> On Dec 12, 11:21?pm, Dennis Lee Bieber wrote: > On Sun, 12 Dec 2010 07:02:13 -0800 (PST), javivd > declaimed the following in > gmane.comp.python.general: > > > > > f = open(r'c:c:\somefile.txt', 'w') > > > f.write('0123456789\n0123456789\n0123456789') > > ? ? ? ? Not the most explanatory sample data... It would be better if the > records had different contents. > > > f.close() > > > f = open(r'c:\somefile.txt', 'r') > > > for line in f: > > ? ? ? ? Here you extract one "line" from the file > > > ? ? f.seek(3,0) > > ? ? print f.read(1) #just to know if its printing the rigth column > > ? ? ? ? And here you ignored the entire line you read, seeking to the fourth > byte from the beginning of the file, andreadingjust one byte from it. > > ? ? ? ? I have no idea of how seek()/read() behaves relative to line > iteration in the for loop... Given the small size of the test data set > it is quite likely that the first "for line in f" resulted in the entire > file being read into a buffer, and that buffer scanned to find the line > ending and return the data preceding it; then the buffer position is set > to after that line ending so the next "for line" continues from that > point. > > ? ? ? ? But in a situation with a large data set, or an unbuffered I/O > system, the seek()/read() could easily result in resetting the file > position used by the "for line", so that the second call returns > "456789\n"... And all subsequent calls too, resulting in an infinite > loop. > > ? ? ? ? Presuming the assignment requires pulling multiple selected fields > from individual records, where each record is of the same > format/spacing, AND that the field selection can not be preprogrammed... > > Sample data file (use fixed width font to view): > -=-=-=-=-=- > Wulfraed ? ? ? 09Ranger ?1915 > Bask Euren ? ? 13Cleric ?1511 > Aethelwulf ? ? 07Mage ? ?0908 > Cwiculf ? ? ? ?08Mage ? ?1008 > -=-=-=-=-=- > > Sample format definition file: > -=-=-=-=-=- > Name ? ?0-14 > Level ? 15-16 > Class ? 17-24 > THAC0 ? 25-26 > Armor ? 27-28 > -=-=-=-=-=- > > Code to process (Python 2.5, with minimal error handling): > -=-=-=-=-=- > > class Extractor(object): > ? ? def __init__(self, formatFile): > ? ? ? ? ff = open(formatFile, "r") > ? ? ? ? self._format = {} > ? ? ? ? self._length = 0 > ? ? ? ? for line in ff: > ? ? ? ? ? ? form = line.split("\t") #file must be tab separated > ? ? ? ? ? ? if len(form) != 2: > ? ? ? ? ? ? ? ? print "Invalid file format definition: %s" % line > ? ? ? ? ? ? ? ? continue > ? ? ? ? ? ? name = form[0] > ? ? ? ? ? ? columns = form[1].split("-") > ? ? ? ? ? ? if len(columns) == 1: ? #single column definition > ? ? ? ? ? ? ? ? start = int(columns[0]) > ? ? ? ? ? ? ? ? end = start > ? ? ? ? ? ? elif len(columns) == 2: > ? ? ? ? ? ? ? ? start = int(columns[0]) > ? ? ? ? ? ? ? ? end = int(columns[1]) > ? ? ? ? ? ? else: > ? ? ? ? ? ? ? ? print "Invalid column definition: %s" % form[1] > ? ? ? ? ? ? ? ? continue > ? ? ? ? ? ? self._format[name] = (start, end) > ? ? ? ? ? ? self._length = max(self._length, end) > ? ? ? ? ff.close() > > ? ? def __call__(self, line): > ? ? ? ? data = {} > ? ? ? ? if len(line) < self._length: > ? ? ? ? ? ? print "Data line is too short for required format: ignored" > ? ? ? ? else: > ? ? ? ? ? ? for (name, (start, end)) in self._format.items(): > ? ? ? ? ? ? ? ? data[name] = line[start:end+1] > ? ? ? ? return data > > if __name__ == "__main__": > ? ? FORMATFILE = "SampleFormat.tsv" > ? ? DATAFILE = "SampleData.txt" > > ? ? characterExtractor = Extractor(FORMATFILE) > > ? ? df = open(DATAFILE, "r") > ? ? for line in df: > ? ? ? ? fields = characterExtractor(line) > ? ? ? ? for (name, value) in fields.items(): > ? ? ? ? ? ? print "Field name: '%s'\t\tvalue: '%s'" % (name, value) > ? ? ? ? print > > ? ? df.close() > -=-=-=-=-=- > > Output from running above code: > -=-=-=-=-=- > Field name: 'Armor' ? ? ? ? ? ? value: '15' > Field name: 'THAC0' ? ? ? ? ? ? value: '19' > Field name: 'Level' ? ? ? ? ? ? value: '09' > Field name: 'Class' ? ? ? ? ? ? value: 'Ranger ?' > Field name: 'Name' ? ? ? ? ? ? ?value: 'Wulfraed ? ? ? ' > > Field name: 'Armor' ? ? ? ? ? ? value: '11' > Field name: 'THAC0' ? ? ? ? ? ? value: '15' > Field name: 'Level' ? ? ? ? ? ? value: '13' > Field name: 'Class' ? ? ? ? ? ? value: 'Cleric ?' > Field name: 'Name' ? ? ? ? ? ? ?value: 'Bask Euren ? ? ' > > Field name: 'Armor' ? ? ? ? ? ? value: '08' > Field name: 'THAC0' ? ? ? ? ? ? value: '09' > Field name: 'Level' ? ? ? ? ? ? value: '07' > Field name: 'Class' ? ? ? ? ? ? value: 'Mage ? ?' > Field name: 'Name' ? ? ? ? ? ? ?value: 'Aethelwulf ? ? ' > > Field name: 'Armor' ? ? ? ? ? ? value: '08' > Field name: 'THAC0' ? ? ? ? ? ? value: '10' > Field name: 'Level' ? ? ? ? ? ? value: '08' > Field name: 'Class' ? ? ? ? ? ? value: 'Mage ? ?' > Field name: 'Name' ? ? ? ? ? ? ?value: 'Cwiculf ? ? ? ?' > -=-=-=-=-=- > > ? ? ? ? Note that string fields have not been trimmed, also numeric fields > are still intextformat... The format definition file would need to be > expanded to include a "string", "integer", "float" (and "Boolean"?) code > in order for the extractor to do proper type conversions. > > -- > ? ? ? ? Wulfraed ? ? ? ? ? ? ? ? Dennis Lee Bieber ? ? ? ? AF6VN > ? ? ? ? wlfr... at ix.netcom.com ? ?HTTP://wlfraed.home.netcom.com/ Clearly it's working. Altough, this code is beyond my python knowledge (i don't get along with classes, maybe it's a good moment to learn about them...) but i'll dig into it. Thanks a lot! It really helps... J From chris at simplistix.co.uk Mon Dec 13 18:30:17 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 13 Dec 2010 23:30:17 +0000 Subject: find memory leaks in running program In-Reply-To: <391F8BF8-8FF5-42B8-8F10-C6F0428CA27B@gmail.com> References: <391F8BF8-8FF5-42B8-8F10-C6F0428CA27B@gmail.com> Message-ID: <4D06AC89.1020903@simplistix.co.uk> On 07/12/2010 16:51, Marco Hornung wrote: > 1. What are the best tools to analyze pythons memory stack, while it is running? Look for the heapy stuff in the guppy package. > 2. Is there a possibility to analyze the memory stack of a program with external programs? (without to change the source code - I am only interested in the object size) heapy is your best bet. > 3. Can I sort of "break" into the memory to see what objects consume how much memory? The GC module might help here too, but really, heapy is what you want. cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From chris at simplistix.co.uk Mon Dec 13 18:34:01 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 13 Dec 2010 23:34:01 +0000 Subject: Added Python, WSGI to XAMPP In-Reply-To: <4D014A3D.7020101@verizon.net> References: <4CFA4305.10004@it.uu.se> <4CFD6825.9020200@simplistix.co.uk> <4CFD8B29.3020006@verizon.net> <4D014A3D.7020101@verizon.net> Message-ID: <4D06AD69.4030302@simplistix.co.uk> On 09/12/2010 21:29, Gerry Reno wrote: > How-To: Add VirtualEnv and Pylons (WSGI framework) to XAMPP > You mean Pyramid, right? ;-) Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From pavlovevidence at gmail.com Mon Dec 13 18:40:47 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 13 Dec 2010 15:40:47 -0800 (PST) Subject: Catching user switching and getting current active user from root on linux References: <1a9bdbd4-2997-4e0f-a24f-cd148247e312@r40g2000prh.googlegroups.com> <8739qhs6dz.fsf.mdw@metalzone.distorted.org.uk> <797ba948-c608-4ed5-b2eb-25177932da91@o4g2000yqd.googlegroups.com> <4d04117b$0$30000$c3e8da3$5496439d@news.astraweb.com> <51d9390d-be72-49fe-a63b-5a05832c53e8@fu15g2000vbb.googlegroups.com> Message-ID: On Dec 13, 3:04?pm, mpnordland wrote: > I think I do understand multiuser systems, although I'm sorry I did > not make my self clear. Yes, I understand that there can be multiple > people logged in, and yes if you really wanted to, you could login as > yourself as many times as you want. This is not a server based > program, it is intended for use in a normal environment. The people > using it will probably not be logging in multiple times as themselves, > or someone else. The problem I have is I want monitor what sites the > user visits, I need to know what sites were accessed by which user. > So, a way to find which user is requesting what url is what I want. > Have I passed the Turing test? Install a web proxy. In a pinch you can stat /dev/console to see who the owner is, which I think was what they did last time I looked. If you're ambitious there's some stuff you can do with netfilter to attach user ids to network packets which you might be able to read with your logging software. How are you logging web site accesses anyway? That would be helpful to know. Carl Banks From chris at simplistix.co.uk Mon Dec 13 19:12:33 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Tue, 14 Dec 2010 00:12:33 +0000 Subject: Added Python, WSGI to XAMPP In-Reply-To: <4D06B6D1.6080208@verizon.net> References: <4CFA4305.10004@it.uu.se> <4CFD6825.9020200@simplistix.co.uk> <4CFD8B29.3020006@verizon.net> <4D014A3D.7020101@verizon.net> <4D06AD69.4030302@simplistix.co.uk> <4D06B6D1.6080208@verizon.net> Message-ID: <4D06B671.5020601@simplistix.co.uk> On 14/12/2010 00:14, Gerry Reno wrote: > On 12/13/2010 06:34 PM, Chris Withers wrote: >> On 09/12/2010 21:29, Gerry Reno wrote: >>> How-To: Add VirtualEnv and Pylons (WSGI framework) to XAMPP >>> > > Maybe, if there's no Zope. Or we'll run away screaming... That is rather pathetically true... Ah well, each to their own... Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From greno at verizon.net Mon Dec 13 19:14:09 2010 From: greno at verizon.net (Gerry Reno) Date: Mon, 13 Dec 2010 19:14:09 -0500 Subject: Added Python, WSGI to XAMPP In-Reply-To: <4D06AD69.4030302@simplistix.co.uk> References: <4CFA4305.10004@it.uu.se> <4CFD6825.9020200@simplistix.co.uk> <4CFD8B29.3020006@verizon.net> <4D014A3D.7020101@verizon.net> <4D06AD69.4030302@simplistix.co.uk> Message-ID: <4D06B6D1.6080208@verizon.net> On 12/13/2010 06:34 PM, Chris Withers wrote: > On 09/12/2010 21:29, Gerry Reno wrote: >> How-To: Add VirtualEnv and Pylons (WSGI framework) to XAMPP >> > > You mean Pyramid, right? ;-) > > Chris > Maybe, if there's no Zope. Or we'll run away screaming... Anyway, Pyramid is still only alpha. But if it is a true WSGI framework then as my technique shows it can certainly be made to work with XAMPP. -Gerry From tjreedy at udel.edu Mon Dec 13 19:21:50 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 13 Dec 2010 19:21:50 -0500 Subject: ANN: ActivePython 2.7.1.3 is now available In-Reply-To: <8D0BABA0-44C4-45C9-BAC6-28F9BD06B340@activestate.com> References: <1292265539.4906.1410124185@webmail.messagingengine.com> <8D0BABA0-44C4-45C9-BAC6-28F9BD06B340@activestate.com> Message-ID: On 12/13/2010 4:23 PM, Sridhar Ratnakumar wrote: >> The PSF 3.1 Windows installer ships with tcl/tk 8.5 and ttk support. > Maybe that was changed in 3.1.3. No, 3.1 (not sure of 3.0) has always used 8.5 on windows and included tkinter.ttk module. > I did this for ActivePython 2.7, > >>>> import Tkinter >>>> root = Tkinter.Tk() >>>> root.tk.eval('info patchlevel') > '8.5.9' 8.5.2 here. Are there noticeable improvements? -- Terry Jan Reedy From sridharr at activestate.com Mon Dec 13 19:35:05 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Mon, 13 Dec 2010 16:35:05 -0800 Subject: ANN: ActivePython 2.7.1.3 is now available In-Reply-To: References: <1292265539.4906.1410124185@webmail.messagingengine.com> <8D0BABA0-44C4-45C9-BAC6-28F9BD06B340@activestate.com> Message-ID: <99D047E5-871C-4405-AA66-6A71BFF2B738@activestate.com> On 2010-12-13, at 4:21 PM, Terry Reedy wrote: > On 12/13/2010 4:23 PM, Sridhar Ratnakumar wrote: > >>> The PSF 3.1 Windows installer ships with tcl/tk 8.5 and ttk support. > >> Maybe that was changed in 3.1.3. > > No, 3.1 (not sure of 3.0) has always used 8.5 on windows and included > tkinter.ttk module. Ok, good to know. >> I did this for ActivePython 2.7, >> >>>>> import Tkinter >>>>> root = Tkinter.Tk() >>>>> root.tk.eval('info patchlevel') >> '8.5.9' > > 8.5.2 here. Are there noticeable improvements? Nothing I can think of except module updates and bug fixes[1], http://wiki.tcl.tk/405 I don't know how dependencies are managed when building PSF installers. From my experience, updating to newer tcl/tk patchlevel releases never broke the ActivePython build. -srid [1] David wanted to use >=8.5.8 due to a specific bug fix, http://community.activestate.com/forum/version-859-under-mac-os-x-am-i-getting-it From nospam at panda.com Mon Dec 13 19:50:21 2010 From: nospam at panda.com (Mark Crispin) Date: Mon, 13 Dec 2010 16:50:21 -0800 Subject: PyArg_ParseTuple question Message-ID: In a C module, I want to pick up the arguments for a Python call like: module.call("string1",["string2a", "string2b", "string2c"], "string3") and stash these into: char *arg1; char *arg2[]; char *arg3; All arguments are required, and we can assume that the arg2 vector is terminated with a null pointer. It doesn't look like PyArg_ParseTuple will do this easily; and that instead I have to use either the "O!" format with a PyList prototype, or use "O&" and write a converter. If I use "O!", at what level does it check? In particular, does it just check that the argument is a list, so I can get away with something like: static PyObject *call(PyObject *self, PyObject *args) { char *arg1, **arg2, *arg3; PyObject *arg2obj; PyObject *list = PyList_New(0); PyObject *ret = NULL; if(PyArg_ParseTuple(args, "sO!s", &arg1, list, &arg2obj, &arg3) { // grovel over arg2obj to get the number of members and make // sure they are all strings // allocate a big enough arg2 // copy the string pointers. ret = doMyThing(arg1, arg2, arg3); } PyObject_del(list); return ret; } By the way,... Python has tossed me a couple of curve balls, but all in all it's been quite reasonable. I still haven't read though the Python tutorial (I really do need to get up to speed on all the data types), but I've been able to get a tremendous amount of work done in a very short period of time. Oh, I've made it SEGV a few times, but these were all blunders in my C module, such as a C method returning self to indicate success (oops!). Python is the best development environment since LISP and SmallTalk nearly 20 years ago. Coming from me, that's quite high praise. -- Mark -- http://panda.com/mrc Democracy is two wolves and a sheep deciding what to eat for lunch. Liberty is a well-armed sheep contesting the vote. From greno at verizon.net Mon Dec 13 19:58:24 2010 From: greno at verizon.net (Gerry Reno) Date: Mon, 13 Dec 2010 19:58:24 -0500 Subject: Added Python, WSGI to XAMPP In-Reply-To: <4D06B671.5020601@simplistix.co.uk> References: <4CFA4305.10004@it.uu.se> <4CFD6825.9020200@simplistix.co.uk> <4CFD8B29.3020006@verizon.net> <4D014A3D.7020101@verizon.net> <4D06AD69.4030302@simplistix.co.uk> <4D06B6D1.6080208@verizon.net> <4D06B671.5020601@simplistix.co.uk> Message-ID: <4D06C130.9040506@verizon.net> On 12/13/2010 07:12 PM, Chris Withers wrote: > On 14/12/2010 00:14, Gerry Reno wrote: >> On 12/13/2010 06:34 PM, Chris Withers wrote: >>> On 09/12/2010 21:29, Gerry Reno wrote: >>>> How-To: Add VirtualEnv and Pylons (WSGI framework) to XAMPP >>>> >> >> Maybe, if there's no Zope. Or we'll run away screaming... > > That is rather pathetically true... > > Ah well, each to their own... > > Chris > What I really don't like right off is that Pyramid is contorting the MVC model just as Django did with their MTV model. They are both making the controller be the view and this confuses the hell out of people who come from true MVC based projects. The VIEW is the bits that stream out of the webserver back to the users browser. The CONTROLLER is the code that gathers all the pieces from the model and constructs the python code that is then fed to the engine that then creates the view. And just because the controller navigates the logic to dynamically contruct/render a view, that does not make 'it' the view. -Gerry From georgeryoung at gmail.com Mon Dec 13 21:50:38 2010 From: georgeryoung at gmail.com (gry) Date: Mon, 13 Dec 2010 18:50:38 -0800 (PST) Subject: performance of tight loop Message-ID: <51729934-2560-4ff7-b998-53a242a74729@j25g2000vbs.googlegroups.com> [python-2.4.3, rh CentOS release 5.5 linux, 24 xeon cpu's, 24GB ram] I have a little data generator that I'd like to go faster... any suggestions? maxint is usually 9223372036854775808(max 64bit int), but could occasionally be 99. width is usually 500 or 1600, rows ~ 5000. from random import randint def row(i, wd, mx): first = ['%d' % i] rest = ['%d' % randint(1, mx) for i in range(wd - 1)] return first + rest ... while True: print "copy %s from stdin direct delimiter ',';" % table_name for i in range(i,i+rows): print ','.join(row(i, width, maxint)) print '\.' From usernet at ilthio.net Mon Dec 13 21:53:29 2010 From: usernet at ilthio.net (Tim Harig) Date: Tue, 14 Dec 2010 02:53:29 +0000 (UTC) Subject: Catching user switching and getting current active user from root on linux References: <1a9bdbd4-2997-4e0f-a24f-cd148247e312@r40g2000prh.googlegroups.com> <8739qhs6dz.fsf.mdw@metalzone.distorted.org.uk> <797ba948-c608-4ed5-b2eb-25177932da91@o4g2000yqd.googlegroups.com> <4d04117b$0$30000$c3e8da3$5496439d@news.astraweb.com> <51d9390d-be72-49fe-a63b-5a05832c53e8@fu15g2000vbb.googlegroups.com> Message-ID: On 2010-12-13, mpnordland wrote: > I think I do understand multiuser systems, although I'm sorry I did > not make my self clear. Yes, I understand that there can be multiple > people logged in, and yes if you really wanted to, you could login as Apparantly you do not. There is nothing that prevents me from downloading from the web when I am not even at the computer. The point people are making is that there is no such thing as a single active user. Any user that has a running process is active. Somebody is not going to appreciate getting fired because somebody else scheduled a porn download at a time when they happened to be flagged as the current user. > yourself as many times as you want. This is not a server based > program, it is intended for use in a normal environment. The people There is nothing definitive about a so-called "normal" enviroment and since you didn't really specify anything, we had go make assumtpions for ourselves. Note also that a server is a piece of software, it need not be running on server class hardware. There are probably several local servers running on your system right now. As is commonly the case, the reason that you are having trouble with this problem is that you are trying to solve it wrong in the first place. You told us how you thought you should solve it which meant that we couldn't help you because we didn't know what problem you were trying to solve in the first place. For future reference, always give a 10,000ft explanation of the problem that you are actually trying to solve rather then just the microcosm of the problem that you feel is relevant. > or someone else. The problem I have is I want monitor what sites the > user visits, I need to know what sites were accessed by which user. > So, a way to find which user is requesting what url is what I want. As Carl has already pointed out, an authenticated proxy is the proper way to get the individualized logging that you are looking for. It is capable of logging each connection (including software from which you might not have anticipated) with its own identified user of origin. Even when several users are accessing the network at once, the network connections can be tied directly to the person who initated the connection. Users cannot use somebody elses connection without their authentication credentials. With a little bit of scripting, the browser can be configured to automatically use the user's credentials whenever the user account is created so that the user never needs to enter their credentials manually after logging in to their account. All connections that attempt to bypass the proxy should be firewalled. > Have I passed the Turing test? You still don't seem to understand how to use threads. Heres a clue: find a decent usenet client that actually displays them by default. Or, if you can't manage to get rid of that junky interface that is Google Groups, at least select the option to view as a tree. Then you might be able to actually post your replies in the proper thread rather then just appending on the the person who last posted. From steve+comp.lang.python at pearwood.info Mon Dec 13 22:29:38 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Dec 2010 03:29:38 GMT Subject: performance of tight loop References: <51729934-2560-4ff7-b998-53a242a74729@j25g2000vbs.googlegroups.com> Message-ID: <4d06e4a1$0$29971$c3e8da3$5496439d@news.astraweb.com> On Mon, 13 Dec 2010 18:50:38 -0800, gry wrote: > [python-2.4.3, rh CentOS release 5.5 linux, 24 xeon cpu's, 24GB ram] I > have a little data generator that I'd like to go faster... any > suggestions? > maxint is usually 9223372036854775808(max 64bit int), but could > occasionally be 99. > width is usually 500 or 1600, rows ~ 5000. > > from random import randint > > def row(i, wd, mx): > first = ['%d' % i] > rest = ['%d' % randint(1, mx) for i in range(wd - 1)] > return first + rest > ... > while True: > print "copy %s from stdin direct delimiter ',';" % table_name > for i in range(i,i+rows): > print ','.join(row(i, width, maxint)) > print '\.' This isn't entirely clear to me. Why is the while loop indented? I assume it's part of some other function that you haven't shown us, rather than part of the function row(). Assuming this, I would say that the overhead of I/O (the print commands) will likely be tens or hundreds of times greater than the overhead of the loop, so you're probably not likely to see much appreciable benefit. You might save off a few seconds from something that runs for many minutes. I don't see the point, really. If the print statements are informative rather than necessary, I would print every tenth (say) line rather than every line. That should save *lots* of time. Replacing "while True" with "while 1" may save a tiny bit of overhead. Whether it is significant or not is another thing. Replacing range with xrange should also make a difference, especially if rows is a large number. Moving the code from row() inline, replacing string interpolation with calls to str(), may also help. Making local variables of any globals may also help a tiny bit. But as I said, you're shaving microseconds of overhead and spending millseconds printing -- the difference will be tiny. But for what it's worth, I'd try this: # Avoid globals in favour of locals. from random import randint _maxint = maxint loop = xrange(i, i+rows) # Where does i come from? inner_loop = xrange(width) # Note 1 more than before. while 1: print "copy %s from stdin direct delimiter ',';" % table_name for i in loop: row = [str(randint(1, _maxint)) for _ in inner_loop] row[0] = str(i) # replace in place print ','.join(row) print '\.' Hope it helps. -- Steven From rustompmody at gmail.com Mon Dec 13 23:13:21 2010 From: rustompmody at gmail.com (rusi) Date: Mon, 13 Dec 2010 20:13:21 -0800 (PST) Subject: Added Python, WSGI to XAMPP References: <4CFA4305.10004@it.uu.se> <4CFD6825.9020200@simplistix.co.uk> <4CFD8B29.3020006@verizon.net> Message-ID: On Dec 10, 2:29?am, Gerry Reno wrote: > If you have any need of a portable LAMP stack, I just finished writing > some How-To's for getting Python, VirtualEnv and WSGI frameworks running > with XAMPP: > > How-To: Add VirtualEnv and Pylons (WSGI framework) to XAMPP > > > How-To: Add VirtualEnv and Django (WSGI framework) to XAMPP > > > How-To: Add Python and mod_wsgi to XAMPP > > > -Gerry What does XAMPP give (on linux) that the distro apache,mysql dont? From greno at verizon.net Mon Dec 13 23:28:48 2010 From: greno at verizon.net (Gerry Reno) Date: Mon, 13 Dec 2010 23:28:48 -0500 Subject: Added Python, WSGI to XAMPP In-Reply-To: References: <4CFA4305.10004@it.uu.se> <4CFD6825.9020200@simplistix.co.uk> <4CFD8B29.3020006@verizon.net> Message-ID: <4D06F280.5070609@verizon.net> On 12/13/2010 11:13 PM, rusi wrote: > On Dec 10, 2:29 am, Gerry Reno wrote: > >> If you have any need of a portable LAMP stack, I just finished writing >> some How-To's for getting Python, VirtualEnv and WSGI frameworks running >> with XAMPP: >> >> How-To: Add VirtualEnv and Pylons (WSGI framework) to XAMPP >> >> >> How-To: Add VirtualEnv and Django (WSGI framework) to XAMPP >> >> >> How-To: Add Python and mod_wsgi to XAMPP >> >> >> -Gerry >> > What does XAMPP give (on linux) that the distro apache,mysql dont? > It is a portable LAMP stack that is basically independent of your distro. If you want to upgrade PHP or Apache or whatever without disturbing your distro PHP or Apache you can do this. If you want to try out cutting edge releases of things you can do this on XAMPP without bothering your distro. It's an environment and what you can do with it is only limited by your imagination. -Gerry From ulrich.eckhardt at dominolaser.com Tue Dec 14 02:05:11 2010 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Tue, 14 Dec 2010 08:05:11 +0100 Subject: performance of tight loop References: <51729934-2560-4ff7-b998-53a242a74729@j25g2000vbs.googlegroups.com> Message-ID: gry wrote: > I have a little data generator that I'd like to go faster... any > suggestions? > maxint is usually 9223372036854775808(max 64bit int), but could > occasionally be 99. > width is usually 500 or 1600, rows ~ 5000. > > from random import randint > > def row(i, wd, mx): > first = ['%d' % i] > rest = ['%d' % randint(1, mx) for i in range(wd - 1)] > return first + rest A few things here: * If you can, don't convert the ints to strings. I'm not 100% sure about Python 2.4, but newer versions will automatically yield long instead of int if the range exceeds that of an int, so even with large numbers that should be safe. * Replace range with xrange. * Instead of creating and appending lists, you could also use a generator expression. > print ','.join(row(i, width, maxint)) All you do here is take a list of strings, build a single string from them and then print the string. Why not iterate over the list (or, as suggested, the generator) and print the elements? Summary: Avoid unnecessary conversions. This includes int to string, but also logical sequences into arrays. Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From ulrich.eckhardt at dominolaser.com Tue Dec 14 02:08:14 2010 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Tue, 14 Dec 2010 08:08:14 +0100 Subject: performance of tight loop References: <51729934-2560-4ff7-b998-53a242a74729@j25g2000vbs.googlegroups.com> <4d06e4a1$0$29971$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2nhjt7-pei.ln1@satorlaser.homedns.org> Steven D'Aprano wrote: > Replacing "while True" with "while 1" may save a tiny bit of overhead. > Whether it is significant or not is another thing. Is this the price for an intentional complexity or just a well-known optimizer deficiency? Just curious... Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From ryan at rfk.id.au Tue Dec 14 02:56:21 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Tue, 14 Dec 2010 18:56:21 +1100 Subject: performance of tight loop In-Reply-To: <2nhjt7-pei.ln1@satorlaser.homedns.org> References: <51729934-2560-4ff7-b998-53a242a74729@j25g2000vbs.googlegroups.com> <4d06e4a1$0$29971$c3e8da3$5496439d@news.astraweb.com> <2nhjt7-pei.ln1@satorlaser.homedns.org> Message-ID: <1292313381.20208.47.camel@durian> On Tue, 2010-12-14 at 08:08 +0100, Ulrich Eckhardt wrote: > Steven D'Aprano wrote: > > Replacing "while True" with "while 1" may save a tiny bit of overhead. > > Whether it is significant or not is another thing. > > Is this the price for an intentional complexity or just a well-known > optimizer deficiency? At least on older pythons, you can assign to the name "True" so it's not possible to optimize that loop - you must look up the name "True" on each iteration. For example, in python 2.6 this loop will exit after one iteration: >>> while True: ... True = False ... >>> To see the difference, take a look at the bytecode python generators for the type types of loop: >>> import dis >>> def while1(): ... while 1: ... pass ... >>> def whileTrue(): ... while True: ... pass ... >>> dis.dis(while1) 2 0 SETUP_LOOP 3 (to 6) 3 >> 3 JUMP_ABSOLUTE 3 >> 6 LOAD_CONST 0 (None) 9 RETURN_VALUE >>> >>> dis.dis(whileTrue) 2 0 SETUP_LOOP 12 (to 15) >> 3 LOAD_GLOBAL 0 (True) 6 JUMP_IF_FALSE 4 (to 13) 9 POP_TOP 3 10 JUMP_ABSOLUTE 3 >> 13 POP_TOP 14 POP_BLOCK >> 15 LOAD_CONST 0 (None) 18 RETURN_VALUE >>> Still, I just can't bring myself to write "while 1" in favour of "while True" in code. Python 3 does away with this madness entirely: >>> while True: ... True = False ... File "", line 2 SyntaxError: assignment to keyword >>> Looking at the bytecode shows that in Python 3, "while 1" and "while True" are indeed identical. Cheers, Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit ryan at rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part URL: From ulrich.eckhardt at dominolaser.com Tue Dec 14 03:20:07 2010 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Tue, 14 Dec 2010 09:20:07 +0100 Subject: performance of tight loop References: <51729934-2560-4ff7-b998-53a242a74729@j25g2000vbs.googlegroups.com> <4d06e4a1$0$29971$c3e8da3$5496439d@news.astraweb.com> <2nhjt7-pei.ln1@satorlaser.homedns.org> Message-ID: Thank you for the explanation, Ryan! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From mhv at dmu.dk Tue Dec 14 03:43:11 2010 From: mhv at dmu.dk (Hvidberg, Martin) Date: Tue, 14 Dec 2010 09:43:11 +0100 Subject: Fail import with SWIG generated imp.load_module ? Message-ID: I'm trying to load a module GDAL into a Python script. The loader/binder that is then called, seems to be generated by SWIG, a project with which I'm unfortunately not familiar. The part of the SWIG generated code that fails on me is as follow: ------ start code snip 1 ------------- # This file was automatically generated by SWIG (http://www.swig.org). # Version 1.3.39 # # Do not make changes to this file unless you know what you are doing--modify # the SWIG interface file instead. from sys import version_info if version_info >= (2,6,0): def swig_import_helper(): from os.path import dirname import imp fp = None try: fp, pathname, description = imp.find_module('_gdal', [dirname(__file__)]) except ImportError: import _gdal return _gdal if fp is not None: print "fp:",fp # <- My code ... print "pn:",pathname # <- My code ... print "de:",description # <- My code ... try: _mod = imp.load_module('_gdal', fp, pathname, description) finally: fp.close() return _mod _gdal = swig_import_helper() del swig_import_helper else: import _gdal del version_info ... ------ end code snip 1 ------------- I had to redo the indents manually in this mail, I hope I didn't make any mistakes. When I run the script that activates this code, it returns the following: ------ start code snip 2 ------------- fp: pn: C:\gdal\bin\gdal\python\osgeo\_gdal.pyd de: ('.pyd', 'rb', 3) Traceback (most recent call last): File "C:\Martin\Work_Eclipse\Hilfe\src\check_GDAL.py", line 8, in import gdal File "C:\gdal\bin\gdal\python\osgeo\gdal.py", line 27, in _gdal = swig_import_helper() File "C:\gdal\bin\gdal\python\osgeo\gdal.py", line 26, in swig_import_helper return _mod UnboundLocalError: local variable '_mod' referenced before assignment ------ end code snip 2 ------------- It appears to me that the objects returned by imp.find_module, and printed out as fp:, pn: and de:, are valid. So why is mp.load_module returning what appears to be some flavour of NULL ? I'm using Python version 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] The GDAL lib is from http://download.osgeo.org/gdal/win32/1.6/gdalwin32exe160.zip All suggestions appreciated ... Best Regards Martin -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at nospam.invalid Tue Dec 14 04:02:06 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 14 Dec 2010 01:02:06 -0800 Subject: performance of tight loop References: <51729934-2560-4ff7-b998-53a242a74729@j25g2000vbs.googlegroups.com> Message-ID: <7xzks8u3qp.fsf@ruckus.brouhaha.com> gry writes: ... > rest = ['%d' % randint(1, mx) for i in range(wd - 1)] > for i in range(i,i+rows): ... One thing that immediately comes to mind is use xrange instead of range. Also, instead of first = ['%d' % i] rest = ['%d' % randint(1, mx) for i in range(wd - 1)] return first + rest you might save some copying with: rest = ['%d' % randint(1, mx) for i in xrange(wd)] rest[0] = '%d'%i return rest That's uglier than the old-fashioned rest = ['%d'%i] for i in xrange(wd-1): rest.append('%d' % randint(1, mx)) I think a generator would be cleanest, but maybe slowest: def row(i, wd, mx): yield '%d' % i for j in xrange(wd-1): yield ('%d' % randint(1, mx)) From greg.ewing at canterbury.ac.nz Tue Dec 14 04:19:04 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 14 Dec 2010 22:19:04 +1300 Subject: while True or while 1 In-Reply-To: <4d05434e$0$29970$c3e8da3$5496439d@news.astraweb.com> References: <4d05434e$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8mor4bFl3oU1@mid.individual.net> Steven D'Aprano wrote: >>>>while True: > > ... print "Looping" > ... True = 0 Just remember that if you use that inside a function, you'll have to initialise True to True before... er, wait a moment, that won't work... ah, I know: def f(true = True): True = true while True: ... True = False -- Greg From hpj at urpla.net Tue Dec 14 05:33:34 2010 From: hpj at urpla.net (Hans-Peter Jansen) Date: Tue, 14 Dec 2010 11:33:34 +0100 Subject: while True or while 1 In-Reply-To: <8mor4bFl3oU1@mid.individual.net> References: <4d05434e$0$29970$c3e8da3$5496439d@news.astraweb.com> <8mor4bFl3oU1@mid.individual.net> Message-ID: <201012141133.35082.hpj@urpla.net> On Tuesday 14 December 2010, 10:19:04 Gregory Ewing wrote: > Steven D'Aprano wrote: > >>>>while True: > > > > ... print "Looping" > > ... True = 0 > > Just remember that if you use that inside a function, you'll > have to initialise True to True before... er, wait a moment, > that won't work... ah, I know: > > def f(true = True): > True = true > while True: > ... > True = False Thankfully, with Python 3 this code falls flat on its face. If I would have to _consume_ code like that more often, it would require me to also use a vomit resistant keyboard cover.. Pete From j.j.molenaar at gmail.com Tue Dec 14 06:19:12 2010 From: j.j.molenaar at gmail.com (Joost Molenaar) Date: Tue, 14 Dec 2010 12:19:12 +0100 Subject: optparse/argparse for cgi/wsgi? In-Reply-To: References: Message-ID: Many people have. :-) In the context of WSGI you're basically talking about routing middleware, which solves the problem: "given a request, which application should be called to construct a response?" In my case, it turned out as simple as a list of (regex, resource) tuples, where regex is a regular expression that looks at the request URI and resource is an object that may or may not implement GET, POST, PUT, DELETE methods. In the regex I can capture any arguments that the resource needs. If the request method is GET and the method GET exists on the matched resource, it is called, else a 'Method Not Allowed' response code is returned. HTH Joost On 10 December 2010 17:36, samwyse wrote: > Has anyone ever built some sort of optparse/argparse module for cgi/ > wsgi programs? I can see why a straight port wouldn't work, but a > module that can organize parameter handling for web pages seems like a > good idea, especially if it provided a standard collection of both > client- and server-side validation processes, easy > internationalization, and a way to create customizable help pages. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From j.j.molenaar at gmail.com Tue Dec 14 06:23:58 2010 From: j.j.molenaar at gmail.com (Joost Molenaar) Date: Tue, 14 Dec 2010 12:23:58 +0100 Subject: optparse/argparse for cgi/wsgi? In-Reply-To: References: Message-ID: To aid your googling, the problem is also commonly called 'Dispatching' instead of 'Routing'. Joost On 14 December 2010 12:19, Joost Molenaar wrote: > Many people have. :-) > > In the context of WSGI you're basically talking about routing > middleware, which solves the problem: "given a request, which > application should be called to construct a response?" > > In my case, it turned out as simple as a list of (regex, resource) > tuples, where regex is a regular expression that looks at the > request URI and resource is an object that may or may not > implement GET, POST, PUT, DELETE methods. In the regex > I can capture any arguments that the resource needs. If the > request method is GET and the method GET exists on the > matched resource, it is called, else a 'Method Not Allowed' > response code is returned. > > HTH > > Joost > > > On 10 December 2010 17:36, samwyse wrote: > >> Has anyone ever built some sort of optparse/argparse module for cgi/ >> wsgi programs? I can see why a straight port wouldn't work, but a >> module that can organize parameter handling for web pages seems like a >> good idea, especially if it provided a standard collection of both >> client- and server-side validation processes, easy >> internationalization, and a way to create customizable help pages. >> > -- Joost Molenaar +31 644 015 510 -------------- next part -------------- An HTML attachment was scrubbed... URL: From kurt.alfred.mueller at gmail.com Tue Dec 14 06:37:29 2010 From: kurt.alfred.mueller at gmail.com (Kurt Mueller) Date: Tue, 14 Dec 2010 12:37:29 +0100 Subject: while True or while 1 In-Reply-To: <201012141133.35082.hpj@urpla.net> References: <4d05434e$0$29970$c3e8da3$5496439d@news.astraweb.com> <8mor4bFl3oU1@mid.individual.net> <201012141133.35082.hpj@urpla.net> Message-ID: <4D0756F9.9040501@gmail.com> Am 14.12.2010 11:33, schrieb Hans-Peter Jansen: > On Tuesday 14 December 2010, 10:19:04 Gregory Ewing wrote: >> Steven D'Aprano wrote: >>>>>> while True: >>> >>> ... print "Looping" >>> ... True = 0 >> >> Just remember that if you use that inside a function, you'll >> have to initialise True to True before... er, wait a moment, >> that won't work... ah, I know: >> >> def f(true = True): >> True = true >> while True: >> ... >> True = False > > Thankfully, with Python 3 this code falls flat on its face. > > If I would have to _consume_ code like that more often, > it would require me to also use a vomit resistant keyboard cover.. > > Pete True yesterday, today and in the future: Yesterday: "Pilate said to him, True? what is true? Having said this he went out again to the Jews and said to them, I see no wrong in him." Today: We are so thankful that today we are free to define "True" ourselves using Python 2.x. Future: Be warned, the future gets darker! ;-) Gr?essli -- Kurt Mueller From __peter__ at web.de Tue Dec 14 06:48:37 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 14 Dec 2010 12:48:37 +0100 Subject: performance of tight loop References: <51729934-2560-4ff7-b998-53a242a74729@j25g2000vbs.googlegroups.com> Message-ID: gry wrote: > [python-2.4.3, rh CentOS release 5.5 linux, 24 xeon cpu's, 24GB ram] > I have a little data generator that I'd like to go faster... any > suggestions? > maxint is usually 9223372036854775808(max 64bit int), but could > occasionally be 99. > width is usually 500 or 1600, rows ~ 5000. > > from random import randint > > def row(i, wd, mx): > first = ['%d' % i] > rest = ['%d' % randint(1, mx) for i in range(wd - 1)] > return first + rest > ... > while True: > print "copy %s from stdin direct delimiter ',';" % table_name > for i in range(i,i+rows): > print ','.join(row(i, width, maxint)) > print '\.' I see the biggest potential in inlining randint. Unfortunately you did not provide an executable script and I had to make it up: $ cat gry.py from random import randint import sys def row(i, wd, mx): first = ['%d' % i] rest = ['%d' % randint(1, mx) for i in range(wd - 1)] return first + rest def main(): table_name = "unknown" maxint = sys.maxint width = 500 rows = 1000 offset = 0 print "copy %s from stdin direct delimiter ',';" % table_name for i in range(offset, offset+rows): print ','.join(row(i, width, maxint)) print '\.' if __name__ == "__main__": main() $ time python gry.py > /dev/null real 0m5.280s user 0m5.230s sys 0m0.050s $ $ cat gry_inline.py import random import math import sys def make_rand(n): if n < 1 << random.BPF: def rand(random=random.random): return int(n*random())+1 else: k = int(1.00001 + math.log(n-1, 2.0)) def rand(getrandbits=random.getrandbits): r = getrandbits(k) while r >= n: r = getrandbits(k) return r+1 return rand def row(i, wd, rand): first = ['%d' % i] rest = ['%d' % rand() for i in range(wd - 1)] return first + rest def main(): table_name = "unknown" maxint = sys.maxint width = 500 rows = 1000 offset = 0 rand = make_rand(maxint) print "copy %s from stdin direct delimiter ',';" % table_name for i in range(offset, offset+rows): print ','.join(row(i, width, rand)) print '\.' if __name__ == "__main__": main() $ time python gry_inline.py > /dev/null real 0m2.004s user 0m2.000s sys 0m0.000s $ Disclaimer: the code in random.py is complex enough that I cannot guarantee I snatched the right pieces. Peter From __peter__ at web.de Tue Dec 14 06:59:01 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 14 Dec 2010 12:59:01 +0100 Subject: performance of tight loop References: <51729934-2560-4ff7-b998-53a242a74729@j25g2000vbs.googlegroups.com> Message-ID: Peter Otten wrote: > gry wrote: > >> [python-2.4.3, rh CentOS release 5.5 linux, 24 xeon cpu's, 24GB ram] >> I have a little data generator that I'd like to go faster... any >> suggestions? >> maxint is usually 9223372036854775808(max 64bit int), but could >> occasionally be 99. >> width is usually 500 or 1600, rows ~ 5000. >> >> from random import randint >> >> def row(i, wd, mx): >> first = ['%d' % i] >> rest = ['%d' % randint(1, mx) for i in range(wd - 1)] >> return first + rest >> ... >> while True: >> print "copy %s from stdin direct delimiter ',';" % table_name >> for i in range(i,i+rows): >> print ','.join(row(i, width, maxint)) >> print '\.' > > I see the biggest potential in inlining randint. Unfortunately you did not > provide an executable script and I had to make it up: > $ time python gry_inline.py > /dev/null > > real 0m2.004s > user 0m2.000s > sys 0m0.000s On second thought, if you have numpy available: $ cat gry_numpy.py from numpy.random import randint import sys def row(i, wd, mx): first = ['%d' % i] rest = ['%d' % i for i in randint(1, mx, wd - 1)] return first + rest def main(): table_name = "unknown" maxint = sys.maxint width = 500 rows = 1000 offset = 0 print "copy %s from stdin direct delimiter ',';" % table_name for i in range(offset, offset+rows): print ','.join(row(i, width, maxint)) print '\.' if __name__ == "__main__": main() $ time python gry_numpy.py > /dev/null real 0m1.024s user 0m1.010s sys 0m0.010s $ Argh Peter From bblais at bryant.edu Tue Dec 14 08:29:04 2010 From: bblais at bryant.edu (Brian Blais) Date: Tue, 14 Dec 2010 08:29:04 -0500 Subject: packaging and installing In-Reply-To: References: <50410C1D-2234-400A-8E1B-F78C4C3AA9D3@bryant.edu> Message-ID: <747D9C66-1B22-4EE4-9A31-2B51CA4DB517@bryant.edu> On Dec 13, 2010, at 12:30 PM, Godson Gera wrote: > > > On Mon, Dec 13, 2010 at 10:46 PM, Brian Blais wrote: >> Hello, >> >> I was wondering if there is any standard or suggested way of installing packages *without* going to the commandline. I often have students who, from there experience in Windows, have never looked at the commandline before and it is a bit of a challenge to get them to install something (i.e. go to the commandline, cd over to the proper folder, type python setup.py install, etc...). I've never seen a package with something like a "compileme.bat", but was wondering if there is some suggested way of doing this or some reasons *not* to do this. I can always write my own (1-line) .bat file, but I didn't want to reinvent the wheel. Perhaps there is a better way for me to do this, ideally in a platform independent way. >> > You don't even have to write a bat file. Python's distutils package allows you to build exe file which creates generic windows wizard window for installing packages. > > Take a look at distutils package http://docs.python.org/distutils/builtdist.html > that's very interesting, and I didn't realize that. it may be useful, and solves part of my problem, but the other part is that I am not on a windows machine and have to distribute to windows users. Or perhaps I am on windows, and need to distribute to Mac. It's great that python itself is so cross-platform, but the installation process for packages seems a lot less so. thanks, bb -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais http://bblais.blogspot.com/ From godson.g at gmail.com Tue Dec 14 10:12:06 2010 From: godson.g at gmail.com (Godson Gera) Date: Tue, 14 Dec 2010 20:42:06 +0530 Subject: packaging and installing In-Reply-To: <747D9C66-1B22-4EE4-9A31-2B51CA4DB517@bryant.edu> References: <50410C1D-2234-400A-8E1B-F78C4C3AA9D3@bryant.edu> <747D9C66-1B22-4EE4-9A31-2B51CA4DB517@bryant.edu> Message-ID: On Tue, Dec 14, 2010 at 6:59 PM, Brian Blais wrote: > On Dec 13, 2010, at 12:30 PM, Godson Gera wrote: > > > > > > > On Mon, Dec 13, 2010 at 10:46 PM, Brian Blais wrote: > >> Hello, > >> > >> I was wondering if there is any standard or suggested way of installing > packages *without* going to the commandline. I often have students who, > from there experience in Windows, have never looked at the commandline > before and it is a bit of a challenge to get them to install something (i.e. > go to the commandline, cd over to the proper folder, type python setup.py > install, etc...). I've never seen a package with something like a > "compileme.bat", but was wondering if there is some suggested way of doing > this or some reasons *not* to do this. I can always write my own (1-line) > .bat file, but I didn't want to reinvent the wheel. Perhaps there is a > better way for me to do this, ideally in a platform independent way. > >> > > You don't even have to write a bat file. Python's distutils package > allows you to build exe file which creates generic windows wizard window for > installing packages. > > > > Take a look at distutils package > http://docs.python.org/distutils/builtdist.html > > > > that's very interesting, and I didn't realize that. it may be useful, and > solves part of my problem, but the other part is that I am not on a windows > machine and have to distribute to windows users. Or perhaps I am on > windows, and need to distribute to Mac. It's great that python itself is so > cross-platform, but the installation process for packages seems a lot less > so. > > Don't blame python for that. command line is least command denominator across all platforms and you don't wanted your audience to visit command line. As of 2010 you have to be on specific platform to make distributions for that platform. This kind of asking for toomuch from a few MB sized python. You need to make your own python distro to support all platform specific(exe, msi, ELF, app, rpm, deb etc etc ) packaing in one installation whose size may swell over many MBs or resort back to wiriting batch file on windows and bash and sh scripts on *nix platforms. -- Thanks & Regards, Godson Gera Asterisk Consultant India -------------- next part -------------- An HTML attachment was scrubbed... URL: From baloand at googlemail.com Tue Dec 14 10:35:45 2010 From: baloand at googlemail.com (baloan) Date: Tue, 14 Dec 2010 07:35:45 -0800 (PST) Subject: Tkinter polling example: file copy with progress bar References: Message-ID: <80524fc1-fcb7-4279-89f0-f04fd7018106@m7g2000vbn.googlegroups.com> Unfortunately you use command('cp...') to copy the file instead of Pythons portable library methods. This choice effectively makes your program work on Unix only (not Windows). See http://modcopy.sourceforge.net for a more portable version. Regards, baloan at gmail.com From darcy at druid.net Tue Dec 14 10:57:40 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 14 Dec 2010 10:57:40 -0500 Subject: Tkinter polling example: file copy with progress bar In-Reply-To: <80524fc1-fcb7-4279-89f0-f04fd7018106@m7g2000vbn.googlegroups.com> References: <80524fc1-fcb7-4279-89f0-f04fd7018106@m7g2000vbn.googlegroups.com> Message-ID: <20101214105740.2b155473.darcy@druid.net> On Tue, 14 Dec 2010 07:35:45 -0800 (PST) baloan wrote: > Unfortunately you use command('cp...') to copy the file instead of > Pythons portable library methods. This choice > effectively makes your program work on Unix only (not Windows). > > See http://modcopy.sourceforge.net for a more portable version. I guess I missed the beginning of this thread but can someone tell me why one needs to download a whole other program in order to do this? open(out_fn, 'w').write(open(in_fn).read()) -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From rboehne at gmail.com Tue Dec 14 11:15:26 2010 From: rboehne at gmail.com (Robert Boehne) Date: Tue, 14 Dec 2010 10:15:26 -0600 Subject: Sybase module 0.40pre1 released Message-ID: WHAT IS IT: The Sybase module provides a Python interface to the Sybase relational database system. It supports all of the Python Database API, version 2.0 with extensions. ** This version is a pre-release not intended for production use ** The module is available here: http://downloads.sourceforge.net/python-sybase/python-sybase-0.40pre1.tar.gz The module home page is here: http://python-sybase.sourceforge.net/ MAJOR CHANGES SINCE 0.39: Modify the DateTimeAsPython output conversion to return None when NULL is output support for Python without threads Ignore additional non-error codes from Sybase (1918 and 11932) Use outputmap in bulkcopy mode (thanks to patch by Cyrille Froehlich) Raise exception when opening a cursor on a closed connection Added unit tests Added new exception DeadLockError when Sybase is in a deadlock situation Add command properties CS_STICKY_BINDS and CS_HAVE_BINDS Added support for inputmap in bulkcopy reuse command and cursor when calling cursor.execute with same request Use ct_setparam to define ct_cursor parameters types instead of ct_param implicit conversion for CS_DATE_TYPE in CS_DATETIME_TYPE DataBuf Adding ct_cmd_props wrapper Increase DataBuf maxlength for params of a request when using CS_CHAR_TYPE params so that the buf can be reused BUGS CORRECTED SINCE 0.39: Corrected money type when using CS_MONEY4 (close bug 2615821) Corrected thread locking in ct_cmd_props (thanks to patch by Cyrille Froehlich) Corrected bug in type mapping in callproc (thanks to report by Skip Montanaro) Correct passing None in a DataBuf (thanks to patch by Bram Kuijvenhoven) The full ChangeLog is here: https://python-sybase.svn.sourceforge.net/svnroot/python-sybase/tags/r0_40pre1/ChangeLog -------------- next part -------------- An HTML attachment was scrubbed... URL: From v.harishankar at gmail.com Tue Dec 14 11:25:54 2010 From: v.harishankar at gmail.com (Harishankar) Date: Tue, 14 Dec 2010 16:25:54 +0000 (UTC) Subject: Tkinter polling example: file copy with progress bar References: <80524fc1-fcb7-4279-89f0-f04fd7018106@m7g2000vbn.googlegroups.com> <20101214105740.2b155473.darcy@druid.net> Message-ID: On Tue, 14 Dec 2010 10:57:40 -0500, D'Arcy J.M. Cain wrote: > I guess I missed the beginning of this thread but can someone tell me > why one needs to download a whole other program in order to do this? > > open(out_fn, 'w').write(open(in_fn).read()) Or what about shutil? Isn't that the higher level file operation module? -- Harishankar (http://harishankar.org http://lawstudentscommunity.com) From darcy at druid.net Tue Dec 14 11:33:00 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 14 Dec 2010 11:33:00 -0500 Subject: Tkinter polling example: file copy with progress bar In-Reply-To: References: <80524fc1-fcb7-4279-89f0-f04fd7018106@m7g2000vbn.googlegroups.com> <20101214105740.2b155473.darcy@druid.net> Message-ID: <20101214113300.29ee9021.darcy@druid.net> On Tue, 14 Dec 2010 16:25:54 +0000 (UTC) Harishankar wrote: > On Tue, 14 Dec 2010 10:57:40 -0500, D'Arcy J.M. Cain wrote: > > open(out_fn, 'w').write(open(in_fn).read()) > Or what about shutil? Isn't that the higher level file operation module? At least that's in the standard library but even then it can be overkill for a simple copy. It does do some error checking that the above doesn't do if you need that. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From arnodel at gmail.com Tue Dec 14 11:52:38 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Tue, 14 Dec 2010 16:52:38 +0000 Subject: while True or while 1 References: <4d05434e$0$29970$c3e8da3$5496439d@news.astraweb.com> <8mor4bFl3oU1@mid.individual.net> Message-ID: <87lj3sb8kp.fsf@gmail.com> Gregory Ewing writes: > Steven D'Aprano wrote: > >>>>>while True: >> >> ... print "Looping" >> ... True = 0 > > Just remember that if you use that inside a function, you'll > have to initialise True to True before... er, wait a moment, > that won't work... ah, I know: > > def f(true = True): > True = true > while True: > ... > True = False You also need to initialise False to False for it to be really robust. So something like this will do. True = not 0 False = not True while True: ... True = False :) -- Arnaud From python at mrabarnett.plus.com Tue Dec 14 13:10:50 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 14 Dec 2010 18:10:50 +0000 Subject: Fail import with SWIG generated imp.load_module ? In-Reply-To: References: Message-ID: <4D07B32A.2010308@mrabarnett.plus.com> On 14/12/2010 08:43, Hvidberg, Martin wrote: > I'm trying to load a module GDAL into a Python script. > > The loader/binderthat is then called, seems to be generated by SWIG, a > project with which I'm unfortunately not familiar. > > The part of the SWIG generated code that fails on me is as follow: > [snip] It _might_ be that imp.load_module(...) is raising an exception, so it doesn't assign to '_mod', and then it tries to run the 'finally' block and return _mod. This raises the exception you see and hides the original cause. From sohel807 at gmail.com Tue Dec 14 13:27:24 2010 From: sohel807 at gmail.com (Akand Islam) Date: Tue, 14 Dec 2010 10:27:24 -0800 (PST) Subject: Sage's Python References: Message-ID: <46480720-4334-47ce-a35c-4895472b351b@29g2000prb.googlegroups.com> On Dec 13, 4:33?pm, "Rhodri James" wrote: > On Fri, 10 Dec 2010 17:11:55 -0000, Akand Islam wrote: > > In my system (Ubuntu 10.04) there are sage-4.6, python 2.6.5, tk8.5- > > dev installed. When I give command from terminal "sage -f > > python-2.6.5.p8" to get sage's python it shows following message: > > > ?No command 'sage' found, did you mean: > > ?Command 'save' from package 'atfs' (universe) > > ?Command 'page' from package 'tcllib' (universe) > > ?sage: command not found > > > How can I get Sage's python to be worked so that I can import sage.all > > in python shell? > > The fact that you have no executable called "sage" suggests that you ? > haven't actually installed it yet. ?Check the Sage website, which has ? > plenty of documentation, and try to figure out where you left the path on ? > whichever method you used. > > -- > Rhodri James *-* Wildebeest Herder to the Masses Dear Rhodri James, Thanks for your response. But I have installed sage-4.6 as per instructions. Sage-4.6 folder is in my ~/Desktop, therefore, from ~/ Desktop/sage-4.6 I can initiate ./sage and can work with sage. -- Akand From newswombat at gmail.com Tue Dec 14 13:36:26 2010 From: newswombat at gmail.com (News Wombat) Date: Tue, 14 Dec 2010 10:36:26 -0800 (PST) Subject: ctypes question References: <2abdd9b3-66ec-4125-a5f8-41315008cccc@l17g2000yqe.googlegroups.com> <7e4306de-b95a-40c8-9c9c-10745d8dc793@z19g2000yqb.googlegroups.com> Message-ID: <413f5a8f-69a0-4351-acc2-18d7edda8149@j3g2000vbp.googlegroups.com> On Dec 11, 12:59?pm, MrJean1 wrote: > In general, for shared libraries, you need to define those first as > prototype using ctypes.CFUNCTYPE() and then instantiate each prototype > once supplying the necessary parameter flags using > prototype(func_spec, tuple_of_param_flags). ?See sections 15.16.2.3 > and 4 of the ctypes docs*. I tried the cfuntype and proto steps, and it's not crashing now (that's good), but now i'm just left with null pointers as a return object. I'm still working through all of the examples you sent. They were extremely helpful. Here's where I'm at now... What is strange is I can actually get smiGetNode to work if I don't cfunctype/proto it. If i do, nada. however, the smiGetNextNode fails no matter what, usually with a segfault, but depending on how i construct it, sometimes a null pointer. constants.py: http://pastebin.com/f3b4Wbf0 libsmi.py: http://pastebin.com/XgtpG6gr smi.c (the actual function): http://pastebin.com/Pu2vabWM From lists at cheimes.de Tue Dec 14 13:38:59 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 14 Dec 2010 19:38:59 +0100 Subject: while True or while 1 In-Reply-To: <87lj3sb8kp.fsf@gmail.com> References: <4d05434e$0$29970$c3e8da3$5496439d@news.astraweb.com> <8mor4bFl3oU1@mid.individual.net> <87lj3sb8kp.fsf@gmail.com> Message-ID: Am 14.12.2010 17:52, schrieb Arnaud Delobelle: > You also need to initialise False to False for it to be really > robust. So something like this will do. > > True = not 0 > False = not True > while True: > ... > True = False Tres Seavers once told me a joke like this: True = not not "Who's at the door?" # say it out loud! This was back in the old days of Zope 2.5 and Python 2.1, which didn't have True and False. Christian From python at bdurham.com Tue Dec 14 14:27:07 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 14 Dec 2010 14:27:07 -0500 Subject: Map Linux locale codes to Windows locale codes? Message-ID: <1292354827.12980.1410327469@webmail.messagingengine.com> Is there a way to map Linux locale codes to Windows locale codes? Windows has locale codes like 'Spanish_Mexico'. We would like to use the more ISO compliant 'es_MX' locale format under Windows. Is there a resource or API that might help us with this mapping? Babel is not an option for us since we're using Python 2.7. Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From jjjaime at gmail.com Tue Dec 14 14:50:41 2010 From: jjjaime at gmail.com (=?ISO-8859-1?Q?Jaime_Fern=E1ndez?=) Date: Tue, 14 Dec 2010 20:50:41 +0100 Subject: Concatenate a string as binary bytes Message-ID: Hi To build a binary packet (for SMPP protocol), we have to concatenate different types of data: integers, floats, strings. We are using struct.pack to generate the binary representation of each integer and float of the packet, and then they are concatenated with the + operand. However, for strings we directly concatenate the string with +, without using struct. Everything works with python 2 except when string encoding is introduced. Whenever, a non ASCII char appears in the string, an exception is launched. In python 3, it's not possible to do this trick because all the strings are unicode. What would be the best approach to: - Support non-ascii chars (we just want to concatenate the binary representation of the string without any modification) - Compatibility between python 2 and python 3. Thanks, Jaime -------------- next part -------------- An HTML attachment was scrubbed... URL: From emile at fenx.com Tue Dec 14 14:51:35 2010 From: emile at fenx.com (Emile van Sebille) Date: Tue, 14 Dec 2010 11:51:35 -0800 Subject: Sage's Python In-Reply-To: <46480720-4334-47ce-a35c-4895472b351b@29g2000prb.googlegroups.com> References: <46480720-4334-47ce-a35c-4895472b351b@29g2000prb.googlegroups.com> Message-ID: On 12/14/2010 10:27 AM Akand Islam said... > On Dec 13, 4:33 pm, "Rhodri James" > wrote: >> On Fri, 10 Dec 2010 17:11:55 -0000, Akand Islam wrote: >>> In my system (Ubuntu 10.04) there are sage-4.6, python 2.6.5, tk8.5- >>> dev installed. When I give command from terminal "sage -f >>> python-2.6.5.p8" to get sage's python it shows following message: >> >>> No command 'sage' found, did you mean: This means that no sage command was found on your path. Check to be sure that ~/Desktop is in your path. Emile >>> Command 'save' from package 'atfs' (universe) >>> Command 'page' from package 'tcllib' (universe) >>> sage: command not found >> >>> How can I get Sage's python to be worked so that I can import sage.all >>> in python shell? >> >> The fact that you have no executable called "sage" suggests that you >> haven't actually installed it yet. Check the Sage website, which has >> plenty of documentation, and try to figure out where you left the path on >> whichever method you used. >> >> -- >> Rhodri James *-* Wildebeest Herder to the Masses > > Dear Rhodri James, > Thanks for your response. But I have installed sage-4.6 as per > instructions. Sage-4.6 folder is in my ~/Desktop, therefore, from ~/ > Desktop/sage-4.6 I can initiate ./sage and can work with sage. > > -- Akand From python at mrabarnett.plus.com Tue Dec 14 15:02:49 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 14 Dec 2010 20:02:49 +0000 Subject: Concatenate a string as binary bytes In-Reply-To: References: Message-ID: <4D07CD69.9080003@mrabarnett.plus.com> On 14/12/2010 19:50, Jaime Fern?ndez wrote: > Hi > > To build a binary packet (for SMPP protocol), we have to concatenate > different types of data: integers, floats, strings. > > We are using struct.pack to generate the binary representation of each > integer and float of the packet, and then they are concatenated with the > + operand. > However, for strings we directly concatenate the string with +, without > using struct. > > Everything works with python 2 except when string encoding is > introduced. Whenever, a non ASCII char appears in the string, an > exception is launched. In python 3, it's not possible to do this trick > because all the strings are unicode. > > What would be the best approach to: > - Support non-ascii chars (we just want to concatenate the binary > representation of the string without any modification) > - Compatibility between python 2 and python 3. > I'd say encode to UTF-8. From benjamin.kaplan at case.edu Tue Dec 14 15:06:04 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 14 Dec 2010 15:06:04 -0500 Subject: Concatenate a string as binary bytes In-Reply-To: References: Message-ID: 2010/12/14 Jaime Fern?ndez : > Hi > To build a binary packet (for SMPP protocol), we have to concatenate > different types of data: integers, floats, strings. > We are using struct.pack to generate the binary representation of each > integer and float of the packet, and then they are concatenated with the + > operand. > However, for strings we directly concatenate the string with +, without > using struct. > Everything works with python 2 except when string encoding is introduced. > Whenever, a non ASCII char appears in the string, an exception is launched. > In python 3, it's not possible to do this trick because all the strings are > unicode. > What would be the best approach to: > ?- Support non-ascii chars (we just want to concatenate the binary > representation of the string without any modification) > ?- Compatibility between python 2 and python 3. > Thanks, > Jaime > -- I don't think you quite understand how encodings and unicode work.You have two similar, but distinct data types involved: a byte string ("" in python 2.x, b"" in Python 3.x) which is a sequence of bytes, and a unicode String (u"" in Python 2.x and "" in Python 3.x) which is a sequence of characters. Neither type of strings has an encoding associated with it- an encoding is just a function for converting between these two data types. You only get those non-ascii character problems when you try concatenating Unicode strings with byte strings, because Python defaults to using ASCII as the encoding when you don't specify the encoding yourself. If you want to avoid those errors (in both Python 2.x and Python 3.x), use the unicode string's encode method to turn the characters into a sequence of bytes before you concat them. From arnodel at gmail.com Tue Dec 14 15:38:47 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Tue, 14 Dec 2010 20:38:47 +0000 Subject: while True or while 1 References: <4d05434e$0$29970$c3e8da3$5496439d@news.astraweb.com> <8mor4bFl3oU1@mid.individual.net> <87lj3sb8kp.fsf@gmail.com> Message-ID: <87hbegay3s.fsf@gmail.com> Christian Heimes writes: [...] > Tres Seavers once told me a joke like this: > > True = not not "Who's at the door?" # say it out loud! > > This was back in the old days of Zope 2.5 and Python 2.1, which didn't > have True and False. I almost used: True = "to be" or not "to be" # that is the question but didn't dare! -- Arnaud From mdw at distorted.org.uk Tue Dec 14 15:42:49 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 14 Dec 2010 20:42:49 +0000 Subject: PyArg_ParseTuple question References: Message-ID: <87wrncf5me.fsf.mdw@metalzone.distorted.org.uk> Mark Crispin writes: > In a C module, I want to pick up the arguments for a Python call like: > module.call("string1",["string2a", "string2b", "string2c"], "string3") > and stash these into: > char *arg1; > char *arg2[]; > char *arg3; > All arguments are required, and we can assume that the arg2 vector is > terminated with a null pointer. > > It doesn't look like PyArg_ParseTuple will do this easily; and that > instead I have to use either the "O!" format with a PyList prototype, > or use "O&" and write a converter. I think the latter is probably your best bet. > If I use "O!", at what level does it check? In particular, does it > just check that the argument is a list, so I can get away with > something like: It does the equivalent of `isinstance', so you'll accept a `list' or an instance of any subclass of `list'. The `O&' converter is pretty straightforward. Something like this ought to do. static int convertlist(PyObject *o, void *p) { PyObject **v; Py_ssize_t i, n; /* Could allow general sequences using PySequence_Fast */ if (!PyList_Check(o)) return (0); /* Copy stuff */ n = PyList_GET_SIZE(o); if ((v = PyMem_New(PyObject *, n + 1)) == 0) return (0); for (i = 0; i < n; i++) { v[i] = PyList_GET_ITEM(o, n); Py_INCREF(v[i]); } v[n] = 0; return (1); } If you want to do a more complex conversion (e.g., to the individual items) there's more work to be done. I could have used PySequence_* functions to read the size and items, but that makes error handling more complicated. One could also borrow the references from the underlying list, which would leave the underlying storage for the vector as the only thing to free. I ended up writing a lot of conversion functions when I was doing Python library bindings (for a crypto library); they're generally a good thing. I found that the trickiest thing about PyArg_ParseTuple is in making sure that you can clean everything up even if it goes wrong half way through. -- [mdw] From flisboa.costa at gmail.com Tue Dec 14 16:00:36 2010 From: flisboa.costa at gmail.com (=?UTF-8?B?RmzDoXZpbyBMaXNiw7Rh?=) Date: Tue, 14 Dec 2010 19:00:36 -0200 Subject: Map Linux locale codes to Windows locale codes? In-Reply-To: <1292354827.12980.1410327469@webmail.messagingengine.com> References: <1292354827.12980.1410327469@webmail.messagingengine.com> Message-ID: You could look into the windows registry, the key "HKLM\SYSTEM\CurrentControlSet\Control\Nls" has all the supported LCID's listed. If not, you could simply get the codepage provided by locale.setlocale(), e.g.: import locale print(locale.setlocale(locale.LC_ALL, "")) prints "Portuguese_Brazil.1252" for me. That codepage part is actually a LCID, that you can then cross-reference with any LCID list on the net. I guess there may be a way to look that up entirely from the registry, including getting a short reference or ANSI codepage from the LCID, but i doubt it'd be portable at all. Maybe what you should do is to make up a dict with known LCID's and their corresponding language codes. I don't know of any way to do this automatically in python... Take a look at http://msdn.microsoft.com/en-us/goglobal/bb896001.aspx 2010/12/14 > Is there a way to map Linux locale codes to Windows locale codes? > > Windows has locale codes like 'Spanish_Mexico'. We would like to use the > more ISO compliant 'es_MX' locale format under Windows. > > Is there a resource or API that might help us with this mapping? > > Babel is not an option for us since we're using Python 2.7. > > Thank you, > Malcolm > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at please.post Tue Dec 14 16:14:35 2010 From: no.email at please.post (kj) Date: Tue, 14 Dec 2010 21:14:35 +0000 (UTC) Subject: How to pop the interpreter's stack? Message-ID: Consider this code: def spam(*args, **kwargs): args, kwargs = __pre_spam(*args, **kwargs) # args & kwargs are OK: proceed # ... def __pre_spam(*args, **kwargs): # validate args & kwargs; # return canonicalized versions of args & kwargs; # on failure, raise some *informative* exception # ... return canonicalized_args, canonicalized_kwargs I write functions like __pre_spam for one reason only: to remove clutter from a corresponding spam function that has a particularly complex argument-validation/canonicalization stage. In effect, spam "outsources" to __pre_spam the messy business of checking and conditioning its arguments. The one thing I don't like about this strategy is that the tracebacks of exceptions raised during the execution of __pre_spam include one unwanted stack level (namely, the one corresponding to __pre_spam itself). __pre_spam should be completely invisible and unobtrusive, as if it had been textually "inlined" into spam prior to the code's interpretation. And I want to achieve this without in any way cluttering spam with try/catches, decorators, and whatnot. (After all, the whole point of introducing __pre_spam is to declutter spam.) It occurs to me, in my innocence (since I don't know the first thing about the Python internals), that one way to achieve this would be to have __pre_spam trap any exceptions (with a try/catch around its entire body), and somehow pop its frame from the interpreter stack before re-raising the exception. (Or some clueful/non-oxymoronic version of this.) How feasible is this? And, if it is quite unfeasible, is there some other way to achieve the same overall design goals described above? TIA! ~kj From prog at vtr.net Tue Dec 14 18:17:48 2010 From: prog at vtr.net (craf) Date: Tue, 14 Dec 2010 20:17:48 -0300 Subject: Alternative to PIL in Python 3.1 Message-ID: <1292368668.4959.1.camel@cristian-desktop> Hi. I wonder if anyone knows any alternative to PIL library, as this does not work with Python 3.1. Thanks in advance Regards. Cristian From stonesnake at kol.co.nz Tue Dec 14 18:30:36 2010 From: stonesnake at kol.co.nz (stateslave) Date: Wed, 15 Dec 2010 12:30:36 +1300 Subject: How to experience python on a handheld, tablet, etc on linux? Message-ID: Without buying first? I'd like to run the front end of all these new devices, on my PC and program in python, to assess which is the best on for me. pre-test python scripts before cross loading onto the device I finally buy. Is that possible? It would also be nice to have some of the look and feel on a PC of these devices anyway, with python of course. Has that be done yet? Any hints? Cheers in advance. From kirby.urner at gmail.com Tue Dec 14 18:34:11 2010 From: kirby.urner at gmail.com (kirby.urner at gmail.com) Date: Tue, 14 Dec 2010 15:34:11 -0800 (PST) Subject: Combing Medusa's Hair... (Design Pattern) Message-ID: <39a583d2-f5a1-4632-848c-c9205fbaa2d0@l24g2000vby.googlegroups.com> This is an idea I got thinking about COM objects, and getting some support from Mark Hammond, Python's Win32 wizard. The goal is to have a host language (not Python) instantiate an object that runs against the Python interpreter, which lives as its own process. The VMs have various ways of implementing this. Mono isn't that different right? In this design pattern, you have something like a dry cleaner's, where people submit jobs at the counter, and go away right away with a ticket (Python returns -- but keeps running). When they come back is more up to them. Work has been done in the meantime (or not, if the queue is backed up). So Python needs a queue in the front, to accept these job orders, a facility for issuing tickets, and a way to catalog what tasks are completed in some urn or receptacle (given this is Python, we might call it a "holy grail"). The host process has a method from querying the Python object as to whether such-and-such a job is complete or not. More primitively, it could just check an output bin (folder) for the expected file (perhaps each "hair" creates a PDF in roughly 1 to 4 seconds). The reason "Medusa" is useful wordplay is it reminds us of the asynchronous server embedded in early Zope. How Medusa relates to Twisted is lore for others to recount. However, given we're spawning strands, hairs or threads each time a host process calls into our object, we're looking at a multi-snaked environment, so the image could hardly be more apt. The act of "combing" suggests some synchronization / communication between threads, but that's not a requirement. More on tap here: http://mail.python.org/pipermail/edu-sig/2010-December/010141.html Kirby From emile at fenx.com Tue Dec 14 19:39:19 2010 From: emile at fenx.com (Emile van Sebille) Date: Tue, 14 Dec 2010 16:39:19 -0800 Subject: Alternative to PIL in Python 3.1 In-Reply-To: <1292368668.4959.1.camel@cristian-desktop> References: <1292368668.4959.1.camel@cristian-desktop> Message-ID: On 12/14/2010 3:17 PM craf said... > Hi. > > I wonder if anyone knows any alternative to PIL library, as this does > not work with Python 3.1. > > Thanks in advance > > Regards. > > Cristian > You might try the 1.1.6 port referenced here: http://www.mail-archive.com/image-sig at python.org/msg02404.html Emile From mrjean1 at gmail.com Tue Dec 14 19:47:05 2010 From: mrjean1 at gmail.com (MrJean1) Date: Tue, 14 Dec 2010 16:47:05 -0800 (PST) Subject: ctypes question References: <2abdd9b3-66ec-4125-a5f8-41315008cccc@l17g2000yqe.googlegroups.com> <7e4306de-b95a-40c8-9c9c-10745d8dc793@z19g2000yqb.googlegroups.com> <413f5a8f-69a0-4351-acc2-18d7edda8149@j3g2000vbp.googlegroups.com> Message-ID: Try again after changing line 16 to sn = SmiGetNode(None, "1.3.6.1.2.1.2.2") Because, SmiGetNode is a Python function which accepts Python objects as arguments. Passing is a ctypes object oid is incorrect. /Jean On Dec 14, 10:36?am, News Wombat wrote: > On Dec 11, 12:59?pm, MrJean1 wrote: > > > In general, for shared libraries, you need to define those first as > > prototype using ctypes.CFUNCTYPE() and then instantiate each prototype > > once supplying the necessary parameter flags using > > prototype(func_spec, tuple_of_param_flags). ?See sections 15.16.2.3 > > and 4 of the ctypes docs*. > > I tried the cfuntype and proto steps, and it's not crashing now > (that's good), but now i'm just left with null pointers as a return > object. ?I'm still working through all of the examples you sent. ?They > were extremely helpful. ?Here's where I'm at now... > > What is strange is I can actually get smiGetNode to work if I don't > cfunctype/proto it. ?If i do, nada. ?however, the smiGetNextNode fails > no matter what, usually with a segfault, but depending on how i > construct it, sometimes a null pointer. > > constants.py:http://pastebin.com/f3b4Wbf0 > libsmi.py:http://pastebin.com/XgtpG6gr > smi.c (the actual function):http://pastebin.com/Pu2vabWM From prog at vtr.net Tue Dec 14 20:15:59 2010 From: prog at vtr.net (craf) Date: Tue, 14 Dec 2010 22:15:59 -0300 Subject: [Fwd: Re: Alternative to PIL in Python 3.1] Message-ID: <1292375759.6322.6.camel@cristian-desktop> --------- Mensaje reenviado -------- > De: Emile van Sebille > Para: python-list at python.org > Asunto: Re: Alternative to PIL in Python 3.1 > Fecha: Tue, 14 Dec 2010 16:39:19 -0800 > > On 12/14/2010 3:17 PM craf said... > > Hi. > > > > I wonder if anyone knows any alternative to PIL library, as this does > > not work with Python 3.1. > > > > Thanks in advance > > > > Regards. > > > > Cristian > > > > > You might try the 1.1.6 port referenced here: > > http://www.mail-archive.com/image-sig at python.org/msg02404.html > > Emile > Hi Emile. Thanks for the info. I'll try it. Regards. Cristian From benjamin.kaplan at case.edu Tue Dec 14 21:06:34 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 14 Dec 2010 21:06:34 -0500 Subject: How to experience python on a handheld, tablet, etc on linux? In-Reply-To: References: Message-ID: On Tue, Dec 14, 2010 at 6:30 PM, stateslave wrote: > > Without buying first? > > I'd like to run the front end of all these new devices, > on my PC and program in python, to assess which is the > best on for me. pre-test python scripts before cross > loading onto the device I finally buy. > > Is that possible? It would also be nice to have some of > the look and feel on a PC of these devices anyway, with > python of course. > > Has that be done yet? > > Any hints? Cheers in advance. > -- Python on Linux is Python on Linux. Whether you have Ubuntu running on a tablet or on a desktop, it's going to behave the same. There are going to be two important things different between running Linux on your PC and running it on a tablet: the processor and the UI. And there's really no good way to simulate either one of those. From ethan at stoneleaf.us Tue Dec 14 21:31:48 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 14 Dec 2010 18:31:48 -0800 Subject: How to pop the interpreter's stack? In-Reply-To: References: Message-ID: <4D082894.6070203@stoneleaf.us> kj wrote: > The one thing I don't like about this strategy is that the tracebacks > of exceptions raised during the execution of __pre_spam include one > unwanted stack level (namely, the one corresponding to __pre_spam > itself). > > __pre_spam should be completely invisible and unobtrusive I am unaware of any way to accomplish what you desire. I also think this is one of those things that's not worth fighting -- how often are you going to see such a traceback? When somebody makes a coding mistake? I would say change the name (assuming yours was a real example) to something more meaningful like _spam_arg_verifier and call it good. Alternatively, perhaps you could make a more general arg_verifier that could be used for all such needs, and then your traceback would have: caller spam arg_verifier and that seems useful to me (it is, in fact, how I have mine set up). Hope this helps! ~Ethan~ From samwyse at gmail.com Tue Dec 14 22:51:21 2010 From: samwyse at gmail.com (samwyse) Date: Tue, 14 Dec 2010 19:51:21 -0800 (PST) Subject: Proposed changes to logging defaults References: <3763d355-9074-485c-a694-031d600d5b84@m11g2000vbs.googlegroups.com> Message-ID: <0d23a9b8-544c-4dfe-81ce-653909ea2385@g26g2000vbi.googlegroups.com> On Dec 9, 6:12?pm, Vinay Sajip wrote: > Some changes are being proposed to how logging works in default > configurations. > > Briefly - when a logging event occurs which needs to be output to some > log, the behaviour of the logging package when no explicit logging > configuration is provided will change, most likely to log those events > to sys.stderr with a default format. I'm in favor of this change. I've long wished that I could just add lots of warning/error/info logging to a script and have it just work without having to spend time configuring the logging system. From kushal.kumaran+python at gmail.com Tue Dec 14 23:10:05 2010 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Wed, 15 Dec 2010 09:40:05 +0530 Subject: Combing Medusa's Hair... (Design Pattern) In-Reply-To: <39a583d2-f5a1-4632-848c-c9205fbaa2d0@l24g2000vby.googlegroups.com> References: <39a583d2-f5a1-4632-848c-c9205fbaa2d0@l24g2000vby.googlegroups.com> Message-ID: On Wed, Dec 15, 2010 at 5:04 AM, kirby.urner at gmail.com wrote: > > This is an idea I got thinking about COM objects, and getting > some support from Mark Hammond, Python's Win32 wizard. > > The goal is to have a host language (not Python) instantiate > an object that runs against the Python interpreter, which lives > as its own process. ?The VMs have various ways of implementing > this. ?Mono isn't that different right? > > In this design pattern, you have something like a dry cleaner's, > where people submit jobs at the counter, and go away right > away with a ticket (Python returns -- but keeps running). ?When > they come back is more up to them. ?Work has been done in > the meantime (or not, if the queue is backed up). > Isn't this the way people use queuing systems (ActiveMQ and the like)? Or simply multiprocessing + Queue. -- regards, kushal From john at nmt.edu Tue Dec 14 23:52:52 2010 From: john at nmt.edu (JohnWShipman) Date: Tue, 14 Dec 2010 20:52:52 -0800 (PST) Subject: Tkinter polling example: file copy with progress bar References: <80524fc1-fcb7-4279-89f0-f04fd7018106@m7g2000vbn.googlegroups.com> Message-ID: <632a3b9e-626c-4bd7-bc81-574f90569c4a@21g2000prv.googlegroups.com> On Dec 14, 8:57?am, "D'Arcy J.M. Cain" wrote: > On Tue, 14 Dec 2010 07:35:45 -0800 (PST) > > baloan wrote: > > Unfortunately you use command('cp...') to copy the file instead of > > Pythons portable library methods. This choice > > effectively makes your program work on Unix only (not Windows). > > > Seehttp://modcopy.sourceforge.netfor a more portable version. > > I guess I missed the beginning of this thread but can someone tell me > why one needs to download a whole other program in order to do this? > > ? open(out_fn, 'w').write(open(in_fn).read()) I posted this example because I got several queries on how to do polling in Tkinter, specifically how to use the .after() universal widget method. The points about using the portable library methods are all well taken. I used file copy as the example long-running process because a reader wanted to know how to do that specifically. Please forgive me for not thinking about portability and stuff; you know how us ancient Unix weenies are. From john at nmt.edu Tue Dec 14 23:53:10 2010 From: john at nmt.edu (JohnWShipman) Date: Tue, 14 Dec 2010 20:53:10 -0800 (PST) Subject: Tkinter polling example: file copy with progress bar References: <80524fc1-fcb7-4279-89f0-f04fd7018106@m7g2000vbn.googlegroups.com> Message-ID: On Dec 14, 8:57?am, "D'Arcy J.M. Cain" wrote: > On Tue, 14 Dec 2010 07:35:45 -0800 (PST) > > baloan wrote: > > Unfortunately you use command('cp...') to copy the file instead of > > Pythons portable library methods. This choice > > effectively makes your program work on Unix only (not Windows). > > > Seehttp://modcopy.sourceforge.netfor a more portable version. > > I guess I missed the beginning of this thread but can someone tell me > why one needs to download a whole other program in order to do this? > > ? open(out_fn, 'w').write(open(in_fn).read()) I posted this example because I got several queries on how to do polling in Tkinter, specifically how to use the .after() universal widget method. The points about using the portable library methods are all well taken. I used file copy as the example long-running process because a reader wanted to know how to do that specifically. Please forgive me for not thinking about portability and stuff; you know how us ancient Unix weenies are. From kirby.urner at gmail.com Wed Dec 15 00:01:55 2010 From: kirby.urner at gmail.com (kirby urner) Date: Tue, 14 Dec 2010 21:01:55 -0800 Subject: Combing Medusa's Hair... (Design Pattern) In-Reply-To: References: <39a583d2-f5a1-4632-848c-c9205fbaa2d0@l24g2000vby.googlegroups.com> Message-ID: On Tue, Dec 14, 2010 at 8:10 PM, Kushal Kumaran wrote: << snip >> >> >> In this design pattern, you have something like a dry cleaner's, >> where people submit jobs at the counter, and go away right >> away with a ticket (Python returns -- but keeps running). ?When >> they come back is more up to them. ?Work has been done in >> the meantime (or not, if the queue is backed up). >> > > Isn't this the way people use queuing systems (ActiveMQ and the like)? > ?Or simply multiprocessing + Queue. > > -- > regards, > kushal > Yeah, that's probably right. This is more like a pedagogical metaphor, a mnemonic. As the name for a design pattern, it should probably be confined to Python examples, as that's where the wordplay on Medusa makes some sense, and not just because her hair was all snakes. http://bytes.com/topic/python/answers/26771-twisted-medusa-zope Kirby From metolone+gmane at gmail.com Wed Dec 15 00:53:36 2010 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Tue, 14 Dec 2010 21:53:36 -0800 Subject: ctypes question References: <2abdd9b3-66ec-4125-a5f8-41315008cccc@l17g2000yqe.googlegroups.com><7e4306de-b95a-40c8-9c9c-10745d8dc793@z19g2000yqb.googlegroups.com> <413f5a8f-69a0-4351-acc2-18d7edda8149@j3g2000vbp.googlegroups.com> Message-ID: > "News Wombat" wrote in message > news:413f5a8f-69a0-4351-acc2-18d7edda8149 at j3g2000vbp.googlegroups.com... > On Dec 11, 12:59 pm, MrJean1 wrote: > > > In general, for shared libraries, you need to define those first as > > prototype using ctypes.CFUNCTYPE() and then instantiate each prototype > > once supplying the necessary parameter flags using > > prototype(func_spec, tuple_of_param_flags). See sections 15.16.2.3 > > and 4 of the ctypes docs*. > > I tried the cfuntype and proto steps, and it's not crashing now > (that's good), but now i'm just left with null pointers as a return > object. I'm still working through all of the examples you sent. They > were extremely helpful. Here's where I'm at now... > > What is strange is I can actually get smiGetNode to work if I don't > cfunctype/proto it. If i do, nada. however, the smiGetNextNode fails > no matter what, usually with a segfault, but depending on how i > construct it, sometimes a null pointer. > > constants.py: http://pastebin.com/f3b4Wbf0 > libsmi.py: http://pastebin.com/XgtpG6gr > smi.c (the actual function): http://pastebin.com/Pu2vabWM > -- > http://mail.python.org/mailman/listinfo/python-list constants.py, in SmiNode and SmiModule definitions: - Any field defined "char*" in C should be "c_char_p" not "POINTER(c_char_p)" (which is char**). The function definition can be simplified, and 2nd argument corrected (c_char_p not POINTER(c_char_p)). Python strings can be passed directly to c_char_p arguments. SmiGetNode = clibsmi.smiGetNode SmiGetNode.argtypes = [POINTER(SmiModule),c_char_p] SmiGetNode.restype = POINTER(SmiNode) oid = "1.3.6.1.2.1.2.2" sn=SmiGetNode(None,oid) Give these fixes a try... -Mark From bavishi.darshak at gmail.com Wed Dec 15 02:12:36 2010 From: bavishi.darshak at gmail.com (Darshak Bavishi) Date: Wed, 15 Dec 2010 12:42:36 +0530 Subject: how tohandling output generated after execution of command/script on host unix machine? Message-ID: Hi Experts, I am still struggling with handling output generated after execution of command/script on host unix machine using windows client machine ssh code : import sys import datetime import time # setup logging paramiko.util.log_to_file('darshak_simple.log') ssh=paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect("*****",username="****",password="****") try: stdin,stdout,stderr=ssh.exec_command("BsPlSMProbe -f node -d > /var/log/Darshak/3.txt ") // output of this command will be store in /var/log/Darshak/ in remote machine except: {Issue is files are generating but remaining blank pls pls help me out of this} print "check" time.sleep(10) print stdout.readlines() a=stdout.readlines() print 1 ssh.close() #print stdout.readlines() Issue is files are generating but remaining blank pls pls help me out of this -- BR Darshak Bavishi -------------- next part -------------- An HTML attachment was scrubbed... URL: From vinay_sajip at yahoo.co.uk Wed Dec 15 03:13:55 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Wed, 15 Dec 2010 00:13:55 -0800 (PST) Subject: Proposed changes to logging defaults References: 0d23a9b8-544c-4dfe-81ce-653909ea2385@g26g2000vbi.googlegroups.com Message-ID: <5af6dffb-ddb7-4563-aef4-7996d78da5b0@p38g2000vbn.googlegroups.com> On Dec 15, 3:51?am, samwyse wrote: > I'm in favor of this change. ?I've long wished that I could just add > lots of warning/error/infologgingto a script and have it just work > without having to spend time configuring theloggingsystem. Note that INFO logging will still not be sent to sys.stderr. Only events of severity WARNING and above will be logged to sys.stderr. If you need INFO logging as well, it's easy enough to configure for a simple script (to get the same effect): basicConfig(level=logging.INFO, format='%(message)s') # or whatever level/format you need So I'm not sure how much time you really have to spend on configuring logging. Regards, Vinay Sajip From nagle at animats.com Wed Dec 15 03:46:57 2010 From: nagle at animats.com (John Nagle) Date: Wed, 15 Dec 2010 00:46:57 -0800 Subject: Proposed changes to logging defaults In-Reply-To: <3763d355-9074-485c-a694-031d600d5b84@m11g2000vbs.googlegroups.com> References: <3763d355-9074-485c-a694-031d600d5b84@m11g2000vbs.googlegroups.com> Message-ID: <4d088078$0$44007$742ec2ed@news.sonic.net> On 12/9/2010 4:12 PM, Vinay Sajip wrote: > Some changes are being proposed to how logging works in default > configurations. > > Briefly - when a logging event occurs which needs to be output to some > log, the behaviour of the logging package when no explicit logging > configuration is provided will change, most likely to log those events > to sys.stderr with a default format. Bad idea. You're assuming that the logging package has the right to blither on the default sys.stderr. There are many cases in which it should not. The program could be running in a web server, and output would end up in the output HTML. The program could be running as a subprocess, and the output could end up in the pipe back to the the parent. "sys.stderr" might be connected to a dead pipe, and writing to it would then kill the program. So this change could break existing programs in subtle ways. John Nagle From stefan_ml at behnel.de Wed Dec 15 04:19:59 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 15 Dec 2010 10:19:59 +0100 Subject: PyArg_ParseTuple question In-Reply-To: <87wrncf5me.fsf.mdw@metalzone.distorted.org.uk> References: <87wrncf5me.fsf.mdw@metalzone.distorted.org.uk> Message-ID: Mark Wooding, 14.12.2010 21:42: > I could have used PySequence_* functions to read the size and items, but > that makes error handling more complicated. One could also borrow the > references from the underlying list, which would leave the underlying > storage for the vector as the only thing to free. > > I ended up writing a lot of conversion functions when I was doing Python > library bindings (for a crypto library); they're generally a good thing. > I found that the trickiest thing about PyArg_ParseTuple is in making > sure that you can clean everything up even if it goes wrong half way > through. I think it's worth mentioning here that the Cython compiler generates tightly tailored code for argument unpacking and type conversion. So unless you really want (or need) to write your code directly against Python's C-API, Cython will do a substantially better job with much less coding. Even if you have already written a major part of your code in C, it's worth considering to (re-)write the Python API wrapper parts in Cython if you need better performance. Stefan From bruno.desthuilliers at gmail.com Wed Dec 15 04:31:04 2010 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Wed, 15 Dec 2010 01:31:04 -0800 (PST) Subject: while True or while 1 References: <4d05434e$0$29970$c3e8da3$5496439d@news.astraweb.com> <8mor4bFl3oU1@mid.individual.net> <87lj3sb8kp.fsf@gmail.com> <87hbegay3s.fsf@gmail.com> Message-ID: On 14 d?c, 21:38, Arnaud Delobelle wrote: > I almost used: > > ? ? True = "to be" or not "to be" # that is the question KEYBOARD !-) From vinay_sajip at yahoo.co.uk Wed Dec 15 05:03:40 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Wed, 15 Dec 2010 02:03:40 -0800 (PST) Subject: Proposed changes to logging defaults References: <3763d355-9074-485c-a694-031d600d5b84@m11g2000vbs.googlegroups.com> <4d088078$0$44007$742ec2ed@news.sonic.net> Message-ID: On Dec 15, 8:46?am, John Nagle wrote: > ? ? You're assuming that theloggingpackage has the right to blither > on the default sys.stderr. ?There are many cases in which it > should not. ?The program could be running in a web server, and > output would end up in the output HTML. ?The program could be > running as a subprocess, and the output could end up in the > pipe back to the the parent. ?"sys.stderr" might be connected > to a dead pipe, and writing to it would then kill the program. > > ? ? So this change could break existing programs in subtle ways. I'm not assuming anything, and the rationale for the change is described in detail in the linked-to post. The reason for posting the link on this list is to give people advance warning of the changes, so they can see if they're affected and take the appropriate action. Note that since this change only affects the user who is using Python 3.2 and has not configured logging. Since the necessary configuration is easy to do, I'm assuming people who might be affected can easily update their code in time for the 3.2 release. Regards, Vinay Sajip From steve+comp.lang.python at pearwood.info Wed Dec 15 05:16:14 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Dec 2010 10:16:14 GMT Subject: How to pop the interpreter's stack? References: Message-ID: <4d08956e$0$29997$c3e8da3$5496439d@news.astraweb.com> On Tue, 14 Dec 2010 21:14:35 +0000, kj wrote: > Consider this code: > > > def spam(*args, **kwargs): > args, kwargs = __pre_spam(*args, **kwargs) > > # args & kwargs are OK: proceed > # ... > > > def __pre_spam(*args, **kwargs): > # validate args & kwargs; > # return canonicalized versions of args & kwargs; # on failure, > raise some *informative* exception # ... > return canonicalized_args, canonicalized_kwargs Double leading underscores don't have any special meaning in the global scope. Save yourself an underscore and call it _pre_spam instead :) In fact, even if spam and __pre_spam are methods, it's probably a good idea to avoid the double-underscore name mangling. It's usually more trouble than it's worth. > I write functions like __pre_spam for one reason only: to remove clutter > from a corresponding spam function that has a particularly complex > argument-validation/canonicalization stage. In effect, spam > "outsources" to __pre_spam the messy business of checking and > conditioning its arguments. A perfectly sensible arrangement. > The one thing I don't like about this strategy is that the tracebacks of > exceptions raised during the execution of __pre_spam include one > unwanted stack level (namely, the one corresponding to __pre_spam > itself). But why is it unwanted? The traceback shows where the error occurs -- it occurs in __pre_spam, not spam, or __post_spam, or spam_caller, or anywhere else. Even if it's possible, having the traceback *lie* about where it occurs is a bad idea which will cause confusion to anyone trying to maintain the software in the future. I can't think of any way to do it, but frankly I haven't thought too hard about it. I'm glad I can't think of any way of doing it, because the thought of having tracebacks lie about where they come from gives me the shivers. Imagine debugging when you've edited the source but are still running the old version, and now the reported line numbers don't match up with the source file -- it would be like that, only worse. -- Steven From rde at audaxis.com Wed Dec 15 06:34:21 2010 From: rde at audaxis.com (Romaric DEFAUX) Date: Wed, 15 Dec 2010 12:34:21 +0100 Subject: Encoding trouble Message-ID: <4D08A7BD.7080206@audaxis.com> Hi all, Since yesterday I'm working on an encoding problem, I become crazy now :) Could you please help me ? Here's the description of the problem : I've got two table in a MysqlDB : history_website and website The important column in them are : history_website.message (varchar(255), encoding = utf8_general_ci) website.client_name (varchar(255), encoding = utf8_general_ci) Why : 1? ) INSERT INTO history_website (time, ip, servername, message) VALUES ('1292411324.22', '192.168.2.15', 'system_server_test.audaxis.com', 'client_name UPDATED from Romariqu to Romariqu? Admin\n') is working perfectly when 2?) UPDATE website SET client_name='Romariqu? Admin\n' WHERE ip='192.168.2.15' is producing error : Warning: Incorrect string value: '\xE9 Admi...' for column 'client_name' at row 1 ??? To create these query, I do this : query = "UPDATE website SET client_name='%s' WHERE ip='%s'" % (self.client_name, self.ip) then self.cursor.execute(query) query = "INSERT INTO history_website (time, ip, servername, message) VALUES ('%s', '%s', '%s', '%s')" % (now, self.ip, self.servername, message)" where message = "client_name UPDATED from %s to %s" % (old_website.client_name, self.client_name) They're both string : type(message) = type(client_name) = My default encoding is sys.setdefaultencoding('utf-8') In my opinion, it should not work for both or work for both, no ? This is strange that it's working only for one... Romaric -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 5361 bytes Desc: S/MIME Cryptographic Signature URL: From hnsri49 at gmail.com Wed Dec 15 07:38:04 2010 From: hnsri49 at gmail.com (srinivas hn) Date: Wed, 15 Dec 2010 18:08:04 +0530 Subject: Links and pointers to basics of soap and suds Message-ID: Hi All, I am very new to the soap and its python client suds.Can anyone tell me how the actual will happens i nthe webservices including suds and soap API. Thanks in advance CHEERS CNA 9986229891 -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Wed Dec 15 07:55:04 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 15 Dec 2010 07:55:04 -0500 Subject: Tkinter polling example: file copy with progress bar In-Reply-To: <632a3b9e-626c-4bd7-bc81-574f90569c4a@21g2000prv.googlegroups.com> References: <80524fc1-fcb7-4279-89f0-f04fd7018106@m7g2000vbn.googlegroups.com> <632a3b9e-626c-4bd7-bc81-574f90569c4a@21g2000prv.googlegroups.com> Message-ID: On 12/14/2010 11:52 PM, JohnWShipman wrote: > you > know how us ancient Unix weenies are. Indeed we do ... ;-) regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From benedict.verheyen at gmail.com Wed Dec 15 07:58:49 2010 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Wed, 15 Dec 2010 13:58:49 +0100 Subject: Dealing with pywin32 on Linux Message-ID: Hi, I'm moving my development environment (python, Django, virtualenv) from Windows to Linux (Debian more specific). However, on one app (uses Django), i have a log on module that uses AD to authenticate users. It's based on the active_directory wrapper of Tim Golden. That needs the win32 module but installation of pywin32 fails on importing: import _winreg ImportError: No module named _winreg Kind of logical in hindsight :) However, this makes programming and testing under Linux a bit of a pain if you're dealing with Windows specific stuff. What is the correct way to proceed (i want to keep my development environment in Linux)? I could adjust my software modules to use the Linux counterparts of the AD functions that i have to authenticate. Or is there another way to deal with this? Thanks for any insight, Cheers, Benedict From steve at holdenweb.com Wed Dec 15 08:06:12 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 15 Dec 2010 08:06:12 -0500 Subject: Proposed changes to logging defaults In-Reply-To: References: <3763d355-9074-485c-a694-031d600d5b84@m11g2000vbs.googlegroups.com> <4d088078$0$44007$742ec2ed@news.sonic.net> Message-ID: On 12/15/2010 5:03 AM, Vinay Sajip wrote: > On Dec 15, 8:46 am, John Nagle wrote: >> You're assuming that theloggingpackage has the right to blither >> on the default sys.stderr. There are many cases in which it >> should not. The program could be running in a web server, and >> output would end up in the output HTML. The program could be >> running as a subprocess, and the output could end up in the >> pipe back to the the parent. "sys.stderr" might be connected >> to a dead pipe, and writing to it would then kill the program. >> >> So this change could break existing programs in subtle ways. > > I'm not assuming anything, and the rationale for the change is > described in detail in the linked-to post. The reason for posting the > link on this list is to give people advance warning of the changes, so > they can see if they're affected and take the appropriate action. > > Note that since this change only affects the user who is using Python > 3.2 and has not configured logging. Since the necessary configuration > is easy to do, I'm assuming people who might be affected can easily > update their code in time for the 3.2 release. > I might add that any web server that sends sys.stderr to the HTTP output stream is not likely to be professionally managed. It's far preferable, in the general case, to ensure that logging messages do not enter the stdout-stdin pipelines carrying information between coordinating processes. If a current task is assuming the prior logging package's behavior and analysing a process's stdout for messages it arguably needs fixing anyway, though I agree that breakage of any kind is unfortunate. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From hpj at urpla.net Wed Dec 15 08:10:43 2010 From: hpj at urpla.net (Hans-Peter Jansen) Date: Wed, 15 Dec 2010 14:10:43 +0100 Subject: while True or while 1 In-Reply-To: <87hbegay3s.fsf@gmail.com> References: <87hbegay3s.fsf@gmail.com> Message-ID: <201012151410.43852.hpj@urpla.net> On Tuesday 14 December 2010, 21:38:47 Arnaud Delobelle wrote: > Christian Heimes writes: > [...] > > > Tres Seavers once told me a joke like this: > > > > True = not not "Who's at the door?" # say it out loud! > > > > This was back in the old days of Zope 2.5 and Python 2.1, which > > didn't have True and False. > > I almost used: > > True = "to be" or not "to be" # that is the question That's wrong: >>> "to be" or not "to be" 'to be' You need to wrap it with bool() at least (even without interpreting Pythons answer to the duality contradiction of consciousness for now ;-)) > but didn't dare! Pete From steve at holdenweb.com Wed Dec 15 08:14:39 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 15 Dec 2010 08:14:39 -0500 Subject: Links and pointers to basics of soap and suds In-Reply-To: References: Message-ID: On 12/15/2010 7:38 AM, srinivas hn wrote: > Hi All, > > I am very new to the soap and its python client suds.Can anyone tell me > how the actual will happens i nthe webservices including suds and soap API. > That's a bit like saying "I need to go around the corner. Would you mind teaching me to drive?". Google for phrases like "web services architecture" and "SOAP WSDL" to get some idea of how these technologies are put together. This assumes, of course, that you already possess a fair idea of how the web is put together. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From benedict.verheyen at gmail.com Wed Dec 15 08:16:36 2010 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Wed, 15 Dec 2010 14:16:36 +0100 Subject: Encoding trouble In-Reply-To: <4D08A7BD.7080206@audaxis.com> References: <4D08A7BD.7080206@audaxis.com> Message-ID: On 15/12/2010 12:34, Romaric DEFAUX wrote: > To create these query, I do this : > query = "UPDATE website SET client_name='%s' WHERE ip='%s'" % (self.client_name, self.ip) > then self.cursor.execute(query) > Unicode can be tricky. Don't you have to encode the string again? I tested this in the interpreter: a = ("UPDATE website SET client_name='%s'" % "Romariqu? Admin").decode("iso-8859-15") print "Query %s " % a.encode("iso-8859-15") produces UPDATE website SET client_name='Romariqu? Admin' So i would try to encode the query before issuing the self.cursor.execute(query) Cheers, Benedict From rde at audaxis.com Wed Dec 15 08:28:07 2010 From: rde at audaxis.com (Romaric DEFAUX) Date: Wed, 15 Dec 2010 14:28:07 +0100 Subject: Encoding trouble In-Reply-To: References: <4D08A7BD.7080206@audaxis.com> Message-ID: <4D08C267.30305@audaxis.com> Le 15/12/2010 14:16, Benedict Verheyen a ?crit : > On 15/12/2010 12:34, Romaric DEFAUX wrote: > >> To create these query, I do this : >> query = "UPDATE website SET client_name='%s' WHERE ip='%s'" % (self.client_name, self.ip) >> then self.cursor.execute(query) >> > Unicode can be tricky. > Don't you have to encode the string again? > I tested this in the interpreter: > > a = ("UPDATE website SET client_name='%s'" % "Romariqu? Admin").decode("iso-8859-15") > > print "Query %s " % a.encode("iso-8859-15") > produces UPDATE website SET client_name='Romariqu? Admin' > > So i would try to encode the query before issuing the self.cursor.execute(query) > > Cheers, > Benedict > Thanks for your answer :) I finally found the solution, I removed the following line from my db connection : # con.cursor().execute('SET NAMES \'utf8\';') # con.cursor().execute('SET CHARACTER SET utf8;') # con.cursor().execute('SET character_set_connection=utf8;') And now it's working fine ! Thanks for your help ! Romaric -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 5361 bytes Desc: S/MIME Cryptographic Signature URL: From mail at timgolden.me.uk Wed Dec 15 08:37:30 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 15 Dec 2010 13:37:30 +0000 Subject: Dealing with pywin32 on Linux In-Reply-To: References: Message-ID: <4D08C49A.90107@timgolden.me.uk> On 15/12/2010 12:58, Benedict Verheyen wrote: > I'm moving my development environment (python, Django, virtualenv) from Windows > to Linux (Debian more specific). However, on one app (uses Django), i have a log on > module that uses AD to authenticate users. > It's based on the active_directory wrapper of Tim Golden. > That needs the win32 module but installation of pywin32 fails on importing: > > import _winreg > ImportError: No module named _winreg > > Kind of logical in hindsight :) > > However, this makes programming and testing under Linux a bit of a pain if you're > dealing with Windows specific stuff. > What is the correct way to proceed (i want to keep my development environment in Linux)? > > I could adjust my software modules to use the Linux counterparts of the AD functions > that i have to authenticate. > Or is there another way to deal with this? Well I'm not sure how far something like WINE would take you, but I suggest that trying to develop Windows-specific code in a Linux Dev environment is creating a rod for your own back. For the specific case you mention, you should be able to switch, lock, stock & barrel to python-ldap or other LDAP modules. But that means a fairly major rewrite, plus that's only one issue. None of the Windows-specific stuff will work: registry, win32api calls, whatever you're pulling out of the pywin32 packages. TJG From benedict.verheyen at gmail.com Wed Dec 15 08:51:38 2010 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Wed, 15 Dec 2010 14:51:38 +0100 Subject: Dealing with pywin32 on Linux In-Reply-To: <4D08C49A.90107@timgolden.me.uk> References: <4D08C49A.90107@timgolden.me.uk> Message-ID: On 15/12/2010 14:37, Tim Golden wrote: > Well I'm not sure how far something like WINE would take you, > but I suggest that trying to develop Windows-specific code in > a Linux Dev environment is creating a rod for your own back. > > For the specific case you mention, you should be able to switch, > lock, stock & barrel to python-ldap or other LDAP modules. But > that means a fairly major rewrite, plus that's only one issue. > None of the Windows-specific stuff will work: registry, win32api > calls, whatever you're pulling out of the pywin32 packages. > > TJG Hi, thanks for your answer. For the moment, i only need to connect to AD to authenticate. But you raise a good point that if I need more functionality, I will encounter problems. Regards, Benedict From steve at holdenweb.com Wed Dec 15 09:17:13 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 15 Dec 2010 09:17:13 -0500 Subject: Dealing with pywin32 on Linux In-Reply-To: References: <4D08C49A.90107@timgolden.me.uk> Message-ID: <4D08CDE9.1060201@holdenweb.com> On 12/15/2010 8:51 AM, Benedict Verheyen wrote: > On 15/12/2010 14:37, Tim Golden wrote: > >> Well I'm not sure how far something like WINE would take you, >> but I suggest that trying to develop Windows-specific code in >> a Linux Dev environment is creating a rod for your own back. >> >> For the specific case you mention, you should be able to switch, >> lock, stock & barrel to python-ldap or other LDAP modules. But >> that means a fairly major rewrite, plus that's only one issue. >> None of the Windows-specific stuff will work: registry, win32api >> calls, whatever you're pulling out of the pywin32 packages. >> >> TJG > > Hi, > > thanks for your answer. > For the moment, i only need to connect to AD to authenticate. > But you raise a good point that if I need more functionality, I will encounter problems. > Benedict: Have you considered running a virtual Windows machine to handle the specific issues that really require a Windows environment? If the loading isn't at brutal levels VirtualBox is a very adequate solution, and of course Python user VMWare has a full range of industrial-grade solutions for virtualization. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Wed Dec 15 09:17:18 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 15 Dec 2010 09:17:18 -0500 Subject: while True or while 1 In-Reply-To: <201012151410.43852.hpj@urpla.net> References: <87hbegay3s.fsf@gmail.com> <201012151410.43852.hpj@urpla.net> Message-ID: On 12/15/2010 8:10 AM, Hans-Peter Jansen wrote: > On Tuesday 14 December 2010, 21:38:47 Arnaud Delobelle wrote: >> Christian Heimes writes: >> [...] >> >>> Tres Seavers once told me a joke like this: >>> >>> True = not not "Who's at the door?" # say it out loud! >>> >>> This was back in the old days of Zope 2.5 and Python 2.1, which >>> didn't have True and False. >> >> I almost used: >> >> True = "to be" or not "to be" # that is the question > > That's wrong: > >>>> "to be" or not "to be" > 'to be' > > You need to wrap it with bool() at least (even without interpreting > Pythons answer to the duality contradiction of consciousness for > now ;-)) > >> but didn't dare! > Yeah, if Hamlet had been a Python programmer that play would have been a light comedy. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From benedict.verheyen at gmail.com Wed Dec 15 09:25:11 2010 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Wed, 15 Dec 2010 15:25:11 +0100 Subject: Dealing with pywin32 on Linux In-Reply-To: <4D08CDE9.1060201@holdenweb.com> References: <4D08C49A.90107@timgolden.me.uk> <4D08CDE9.1060201@holdenweb.com> Message-ID: On 15/12/2010 15:17, Steve Holden wrote: >> >> Hi, >> >> thanks for your answer. >> For the moment, i only need to connect to AD to authenticate. >> But you raise a good point that if I need more functionality, I will encounter problems. >> > Benedict: > > Have you considered running a virtual Windows machine to handle the > specific issues that really require a Windows environment? If the > loading isn't at brutal levels VirtualBox is a very adequate solution, > and of course Python user VMWare has a full range of industrial-grade > solutions for virtualization. > > regards > Steve Hi Steve, good suggestion. I use VirtualBox for other needs so it's not a lot of hassle to set one up. Thanks ! Regards, Benedict From tjreedy at udel.edu Wed Dec 15 10:01:15 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 15 Dec 2010 10:01:15 -0500 Subject: Proposed changes to logging defaults In-Reply-To: <4d088078$0$44007$742ec2ed@news.sonic.net> References: <3763d355-9074-485c-a694-031d600d5b84@m11g2000vbs.googlegroups.com> <4d088078$0$44007$742ec2ed@news.sonic.net> Message-ID: On 12/15/2010 3:46 AM, John Nagle wrote: > You're assuming that the logging package has the right to blither > on the default sys.stderr. The Python stdlib *already* assumes that it can write to stderr. Using logging instead will make it easier for app writers to do something else. -- Terry Jan Reedy From dmitrey.kroshko at scipy.org Wed Dec 15 10:29:50 2010 From: dmitrey.kroshko at scipy.org (dmitrey) Date: Wed, 15 Dec 2010 07:29:50 -0800 (PST) Subject: New OpenOpt/FuncDesigner release 0.32 Message-ID: <631ec423-9cac-4d77-ba8d-b40d7ae7b354@j3g2000vbi.googlegroups.com> Hi all, I'm glad to inform you about new quarterly OpenOpt/FuncDesigner release (0.32): OpenOpt: * New class: LCP (and related solver) * New QP solver: qlcp * New NLP solver: sqlcp * New large-scale NSP (nonsmooth) solver gsubg. Currently it still requires lots of improvements (especially for constraints - their handling is very premature yet and often fails), but since the solver sometimes already works better than ipopt, algencan and other competitors it was tried with, I decided to include the one into the release. * Now SOCP can handle Ax <= b constraints (and bugfix for handling lb <= x <= ub has been committed) * Some other fixes and improvements FuncDesigner: * Add new function removeAttachedConstraints * Add new oofuns min and max (their capabilities are quite restricted yet) * Systems of nonlinear equations: possibility to assign personal tolerance for an equation * Some fixes and improvements For more details see our forum entry http://forum.openopt.org/viewtopic.php?id=325 Regards, D. From stefan.sonnenberg at pythonmeister.com Wed Dec 15 10:54:24 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Wed, 15 Dec 2010 16:54:24 +0100 Subject: Dealing with pywin32 on Linux In-Reply-To: References: Message-ID: <4D08E4B0.1080007@pythonmeister.com> Am 15.12.2010 13:58, schrieb Benedict Verheyen: > Hi, > > > I'm moving my development environment (python, Django, virtualenv) from Windows > to Linux (Debian more specific). However, on one app (uses Django), i have a log on > module that uses AD to authenticate users. > It's based on the active_directory wrapper of Tim Golden. > That needs the win32 module but installation of pywin32 fails on importing: > > import _winreg > ImportError: No module named _winreg > > Kind of logical in hindsight :) > > However, this makes programming and testing under Linux a bit of a pain if you're > dealing with Windows specific stuff. > What is the correct way to proceed (i want to keep my development environment in Linux)? > > I could adjust my software modules to use the Linux counterparts of the AD functions > that i have to authenticate. > Or is there another way to deal with this? > > Thanks for any insight, > > Cheers, > Benedict > Just change to LDAP as authentication method. Even Active Directory offers LDAP (w/o SSL), and there are modules to interact with LDAP using python. And, it is platform indipendent. See here: http://www.python-ldap.org/ I've done this quite often to auth users in an AD with apache/ldap-auth. From tim.arnold at sas.com Wed Dec 15 12:38:50 2010 From: tim.arnold at sas.com (Tim Arnold) Date: Wed, 15 Dec 2010 12:38:50 -0500 Subject: How to pop the interpreter's stack? References: Message-ID: "Ethan Furman" wrote in message news:mailman.4.1292379995.6505.python-list at python.org... > kj wrote: >> The one thing I don't like about this strategy is that the tracebacks >> of exceptions raised during the execution of __pre_spam include one >> unwanted stack level (namely, the one corresponding to __pre_spam >> itself). >> >> __pre_spam should be completely invisible and unobtrusive > > I am unaware of any way to accomplish what you desire. I also think this > is one of those things that's not worth fighting -- how often are you > going to see such a traceback? When somebody makes a coding mistake? I > would say change the name (assuming yours was a real example) to something > more meaningful like _spam_arg_verifier and call it good. > > Alternatively, perhaps you could make a more general arg_verifier that > could be used for all such needs, and then your traceback would have: > > caller > > spam > > arg_verifier > > and that seems useful to me (it is, in fact, how I have mine set up). > > Hope this helps! > > ~Ethan~ I thought people would advise using a decorator for this one. Wouldn't that work? thanks, --Tim From ethan at stoneleaf.us Wed Dec 15 12:54:27 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 15 Dec 2010 09:54:27 -0800 Subject: O'Reilly Python Certification Message-ID: <4D0900D3.10000@stoneleaf.us> So I just got an e-mail from O'Reilly and their School of Technology about a Python Certification course... anybody have any experience with this? It also says Steve Holden is involved -- is this True? (Steve?) ~Ethan~ PS Can you tell I've been programming? ;) From steve at holdenweb.com Wed Dec 15 13:14:26 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 15 Dec 2010 13:14:26 -0500 Subject: O'Reilly Python Certification In-Reply-To: <4D0900D3.10000@stoneleaf.us> References: <4D0900D3.10000@stoneleaf.us> Message-ID: <4D090582.5020906@holdenweb.com> On 12/15/2010 12:54 PM, Ethan Furman wrote: > So I just got an e-mail from O'Reilly and their School of Technology > about a Python Certification course... anybody have any experience with > this? > > It also says Steve Holden is involved -- is this True? (Steve?) > Well, it's not not not False. You think O'Reilly would publish lies on their web site? :-) I am a little more that involved. In ham and eggs the chicken is involved. I am committed, like the pig, having got three of the four classes into production after almost two years' work. So for those of you who may have wondered why I have been on c.l.py only sporadically lately, now you know. The certificate will come from the University of Illinois after approximately 160 hours of study. By the end of the series you should have a substantial corpus of Python code that you have typed in yourself, understand and can discuss with potential employers and others. You will have a fair knowledge of Python and you will be accustomed to test-driven development. > ~Ethan~ > > PS > > Can you tell I've been programming? ;) I would really like to hear from anyone who takes the class. I would like to ensure that it is kept up to date and relevant with continuous improvements, and feedback will be invaluable in helping me to achieve this goal. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From sohel807 at gmail.com Wed Dec 15 13:22:47 2010 From: sohel807 at gmail.com (Akand Islam) Date: Wed, 15 Dec 2010 10:22:47 -0800 (PST) Subject: Sage's Python References: <46480720-4334-47ce-a35c-4895472b351b@29g2000prb.googlegroups.com> Message-ID: <93700dc9-2c7e-434e-af46-60a7a9ef90cc@j13g2000vbp.googlegroups.com> On Dec 14, 1:51?pm, Emile van Sebille wrote: > On 12/14/2010 10:27 AM Akand Islam said... > > > On Dec 13, 4:33 pm, "Rhodri James" > > wrote: > >> On Fri, 10 Dec 2010 17:11:55 -0000, Akand Islam ?wrote: > >>> In my system (Ubuntu 10.04) there are sage-4.6, python 2.6.5, tk8.5- > >>> dev installed. When I give command from terminal "sage -f > >>> python-2.6.5.p8" to get sage's python it shows following message: > > >>> ? No command 'sage' found, did you mean: > > This means that no sage command was found on your path. ?Check to be > sure that ~/Desktop is in your path. > > Emile Thanks Emile. -- Akand. From hpj at urpla.net Wed Dec 15 15:10:05 2010 From: hpj at urpla.net (Hans-Peter Jansen) Date: Wed, 15 Dec 2010 21:10:05 +0100 Subject: default argument in method In-Reply-To: References: Message-ID: <201012152110.05744.hpj@urpla.net> On Monday 13 December 2010, 18:14:27 Godson Gera wrote: > On Sun, Dec 12, 2010 at 5:05 PM, ernest wrote: > > Hi, > > > > I'd like to have a reference to an instance attribute as > > default argument in a method. It doesn't work because > > "self" is not defined at the time the method signature is > > evaluated. For example: > > > > class C(object): > > def __init__(self): > > self.foo = 5 > > def m(self, val=self.foo): > > return val > > > > Raises NameError because 'self' is not defined. > > You can defined foo outside the __init__ and can access it inside > methods using self.foo > > class C(object): > foo=5 > def __init__(self): > print self.foo > def m(self,val=foo): > return val > > class attributes can be accessed with out self before them in method > signatures. However, becareful if you change the value of foo inside > any method, the method signature will still hold on to old value. Since this is a major pitfall, it might be worth mentioning, that mutable default arguments are generally a bad idea, as the default arguments are evaluated just once, hence e.g. using an empty list might contain the items, that were appended in earlier calls of this method.. Code, that _relies_ on such behavior should be yanked instantaneous and the producer of such code should be punished with coding APL? on a dubeolsik hangul keyboard? for a year at least.. Pete ?) Not, that APL is a bad language per se, but even one liners tend to be rather cryptic for usual brains. Let's say it with Dijkstra: "APL is a mistake, carried out through perfection..." but given the second constraint, it's going to be a, hmm, challenge. http://en.wikipedia.org/wiki/APL_(programming_language) ?) http://en.wikipedia.org/wiki/Keyboard_layout#Dubeolsik From python.list at tim.thechases.com Wed Dec 15 15:40:33 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 15 Dec 2010 14:40:33 -0600 Subject: O'Reilly Python Certification In-Reply-To: <4D0900D3.10000@stoneleaf.us> References: <4D0900D3.10000@stoneleaf.us> Message-ID: <4D0927C1.5080209@tim.thechases.com> On 12/15/2010 11:54 AM, Ethan Furman wrote: > So I just got an e-mail from O'Reilly and their School of Technology > about a Python Certification course... anybody have any experience with > this? > > It also says Steve Holden is involved -- is this True? you should just test for the truthiness without comparing to True: if is_involved(steve_holden): your_code() rather than asking if is_involved(steve_holden) is True: your_code() ;-) On a more serious note, it would be interesting to know if it's possible to test out of the certification for those of us that have been using Python for a long time. -tkc From steve at holdenweb.com Wed Dec 15 16:11:38 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 15 Dec 2010 16:11:38 -0500 Subject: O'Reilly Python Certification In-Reply-To: <4D0927C1.5080209@tim.thechases.com> References: <4D0900D3.10000@stoneleaf.us> <4D0927C1.5080209@tim.thechases.com> Message-ID: On 12/15/2010 3:40 PM, Tim Chase wrote: > On a more serious note, it would be interesting to know if it's possible > to test out of the certification for those of us that have been using > Python for a long time. That's an interesting idea - let a bunch of experienced Python users tell me what a lousy job I have done of explaining the language. :) Seriously, I would be interested, and it's a terrific idea. I can't do anything before January, but if anyone is interested in taking part in such a review of the materials I'd be grateful if they would contact me privately by email on a "no promises" basis. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From anil.jupiter9 at gmail.com Wed Dec 15 16:21:26 2010 From: anil.jupiter9 at gmail.com (jupiter) Date: Wed, 15 Dec 2010 13:21:26 -0800 (PST) Subject: Help regarding pattern matching Message-ID: Hi People, I need some ideas on how to find pattern in random data series like stock chart. What I want is to be able to find Head & Shoulder pattern in chart. Thanx Anil From stefan.sonnenberg at pythonmeister.com Wed Dec 15 16:21:58 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Wed, 15 Dec 2010 22:21:58 +0100 Subject: O'Reilly Python Certification In-Reply-To: References: <4D0900D3.10000@stoneleaf.us> <4D0927C1.5080209@tim.thechases.com> Message-ID: <4D093176.3010109@pythonmeister.com> Am 15.12.2010 22:11, schrieb Steve Holden: > On 12/15/2010 3:40 PM, Tim Chase wrote: >> On a more serious note, it would be interesting to know if it's possible >> to test out of the certification for those of us that have been using >> Python for a long time. > That's an interesting idea - let a bunch of experienced Python users > tell me what a lousy job I have done of explaining the language. :) > > Seriously, I would be interested, and it's a terrific idea. I can't do > anything before January, but if anyone is interested in taking part in > such a review of the materials I'd be grateful if they would contact me > privately by email on a "no promises" basis. > > regards > Steve I think he meant: take the test without study first. I'd be interested in both, though. From van.lindberg at gmail.com Wed Dec 15 16:46:40 2010 From: van.lindberg at gmail.com (VanL) Date: Wed, 15 Dec 2010 15:46:40 -0600 Subject: Help influence which tutorials are given at PyCon 2011 Message-ID: PyCon is made up of a number of different parts, each with its own goals. For the talks presented during the conference portion of PyCon, we go for both breadth and quality. There are enough different sessions and different tracks that each person can customize their PyCon experience according to their interests. For tutorials, the goal is slightly different. We want to present tutorials that help developers deal effectively with their most common day-to-day challenges. We categorized the various tutorial proposals into a number of broad buckets. You can vote on which topics you would like to see at PyCon 2011! We will take this information into account when deciding which tutorials will be presented. You can view the poll at . From greg.ewing at canterbury.ac.nz Wed Dec 15 16:50:19 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 16 Dec 2010 10:50:19 +1300 Subject: Proposed changes to logging defaults In-Reply-To: References: <3763d355-9074-485c-a694-031d600d5b84@m11g2000vbs.googlegroups.com> <4d088078$0$44007$742ec2ed@news.sonic.net> Message-ID: <8msrgrFeo3U1@mid.individual.net> Terry Reedy wrote: > On 12/15/2010 3:46 AM, John Nagle wrote: > >> You're assuming that the logging package has the right to blither >> on the default sys.stderr. > > The Python stdlib *already* assumes that it can write to stderr. Also ISTM that any program relying on nothing it calls ever writing to stderr would be rather fragile. -- Greg From python.list at tim.thechases.com Wed Dec 15 17:01:04 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 15 Dec 2010 16:01:04 -0600 Subject: O'Reilly Python Certification In-Reply-To: References: <4D0900D3.10000@stoneleaf.us> <4D0927C1.5080209@tim.thechases.com> Message-ID: <4D093AA0.1050803@tim.thechases.com> On 12/15/2010 03:11 PM, Steve Holden wrote: > On 12/15/2010 3:40 PM, Tim Chase wrote: >> On a more serious note, it would be interesting to know if it's possible >> to test out of the certification for those of us that have been using >> Python for a long time. > > That's an interesting idea - let a bunch of experienced Python users > tell me what a lousy job I have done of explaining the language. :) Actually Stephan read what I intended -- a way to take the final test (and receive the cert) without belaboring the taker or you with the actual course-work. I did that with several classes back in college where I needed a prereq. for a class but was able to ace the final for that prereq to show the prof(s) that I knew the material. Saved me a semester-long class in each case, and saved the professor the time spent grading my stuff. That said, having peer-review of your course material can (well, *should*) only improve it. -tkc From chris at simplistix.co.uk Wed Dec 15 17:03:45 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Wed, 15 Dec 2010 22:03:45 +0000 Subject: Added Python, WSGI to XAMPP In-Reply-To: <4D06C130.9040506@verizon.net> References: <4CFA4305.10004@it.uu.se> <4CFD6825.9020200@simplistix.co.uk> <4CFD8B29.3020006@verizon.net> <4D014A3D.7020101@verizon.net> <4D06AD69.4030302@simplistix.co.uk> <4D06B6D1.6080208@verizon.net> <4D06B671.5020601@simplistix.co.uk> <4D06C130.9040506@verizon.net> Message-ID: <4D093B41.2050707@simplistix.co.uk> On 14/12/2010 00:58, Gerry Reno wrote: > What I really don't like right off is that Pyramid is contorting the MVC > model That specific pattern, I'm afraid, is a little antiquated nowadays, particularly when it comes to web apps... > The VIEW is the bits that stream out of the webserver back to the users > browser. Yep, and in Pyramid I guess this would be the template renderer, which is usually a decorator on the view function or class. The view's job is to process a request and turn it into a response dictionary. That sounds a lot like your controller to me ;-) > The CONTROLLER is the code that gathers all the pieces from > the model and constructs the python code Slightly scared as to what "constructed the python code" might mean :-S > that is then fed to the engine > that then creates the view. And just because the controller navigates > the logic to dynamically contruct/render a view, that does not make 'it' > the view. Well, for me, the MVC isn't really what happens anymore, here's my take: - the model nowadays has all the "business logic" in it, rather than just the data. The model is now a collection of objects that can be interacted on through many/any UIs needed, some of which may be web apps. - web apps are *always* a collection of request/response transactions. As such, the "control" layer does just become a "view" that does that. - singleton objects and other stuff that used to live in a "control" are now factored out into utilities and services (of which zope.component provides a pretty good abstraction, and doesn't really have anything to do with Zope, other than the fact that Zope makes use of it). Welcome to the 2nd decade in the new millenium ;-) Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From greno at verizon.net Wed Dec 15 17:28:56 2010 From: greno at verizon.net (Gerry Reno) Date: Wed, 15 Dec 2010 17:28:56 -0500 Subject: Pyramid and MVC (split from: Re: Added Python, WSGI to XAMPP) In-Reply-To: <4D093B41.2050707@simplistix.co.uk> References: <4CFA4305.10004@it.uu.se> <4CFD6825.9020200@simplistix.co.uk> <4CFD8B29.3020006@verizon.net> <4D014A3D.7020101@verizon.net> <4D06AD69.4030302@simplistix.co.uk> <4D06B6D1.6080208@verizon.net> <4D06B671.5020601@simplistix.co.uk> <4D06C130.9040506@verizon.net> <4D093B41.2050707@simplistix.co.uk> Message-ID: <4D094128.3010807@verizon.net> On 12/15/2010 05:03 PM, Chris Withers wrote: > On 14/12/2010 00:58, Gerry Reno wrote: >> What I really don't like right off is that Pyramid is contorting the MVC >> model > > That specific pattern, I'm afraid, is a little antiquated nowadays, > particularly when it comes to web apps... > >> The VIEW is the bits that stream out of the webserver back to the users >> browser. > > Yep, and in Pyramid I guess this would be the template renderer, which > is usually a decorator on the view function or class. The view's job > is to process a request and turn it into a response dictionary. That > sounds a lot like your controller to me ;-) > >> The CONTROLLER is the code that gathers all the pieces from >> the model and constructs the python code > > Slightly scared as to what "constructed the python code" might mean :-S > >> that is then fed to the engine >> that then creates the view. And just because the controller navigates >> the logic to dynamically contruct/render a view, that does not make 'it' >> the view. > > Well, for me, the MVC isn't really what happens anymore, here's my take: > > - the model nowadays has all the "business logic" in it, rather than > just the data. The model is now a collection of objects that can be > interacted on through many/any UIs needed, some of which may be web apps. > > - web apps are *always* a collection of request/response transactions. > As such, the "control" layer does just become a "view" that does that. > > - singleton objects and other stuff that used to live in a "control" > are now factored out into utilities and services (of which > zope.component provides a pretty good abstraction, and doesn't really > have anything to do with Zope, other than the fact that Zope makes use > of it). > > Welcome to the 2nd decade in the new millenium ;-) > > Chris > It doesn't matter whether you are building a desktop app or a webapp. MVC still applies. And that includes when things like Ajax are added to the mix because Ajax just performs a mini-MVC transaction. The problems arise when people start rigidly thinking that M only meant database. M means model, model means any source that emits data. A database, another webapp, whatever, that is M. The view as I said before is just the bits streaming out of the webserver back to the client device. There should be NOTHING on the server call view-anything. The view only exists on the clients. The view is the result of what the controllers(servers) in conjunction with renderers emit as their work product. -Gerry From steve+comp.lang.python at pearwood.info Wed Dec 15 18:56:31 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Dec 2010 23:56:31 GMT Subject: default argument in method References: Message-ID: <4d0955ae$0$29997$c3e8da3$5496439d@news.astraweb.com> On Wed, 15 Dec 2010 21:10:05 +0100, Hans-Peter Jansen wrote: > Since this is a major pitfall, it might be worth mentioning, that > mutable default arguments are generally a bad idea, as the default > arguments are evaluated just once, hence e.g. using an empty list might > contain the items, that were appended in earlier calls of this method.. It's only a pitfall for users who expect that default arguments are re- created every time you call the function; it's only a bad idea for code which relies on the default arguments being re-created each time. If you hold misunderstandings about the behaviour of a language, you'll have trouble understanding what code does. Default arguments are no different from any other feature. > Code, that _relies_ on such behavior should be yanked instantaneous and > the producer of such code should be punished with coding APL? on a > dubeolsik hangul keyboard? for a year at least.. Python code that relies on default arguments to *not* be re-created on each function call is no worse than (say) Ruby code that relies on default arguments *to* be re-created each time. I don't mean to be elitist (ah, who am I fooling, of course I do), but when coders of the skill and experience of the Effbot and Guido use mutable defaults, who are you to say they shouldn't? http://effbot.org/zone/default-values.htm http://www.python.org/doc/essays/graphs/ -- Steven From ian.g.kelly at gmail.com Wed Dec 15 19:36:10 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 15 Dec 2010 17:36:10 -0700 Subject: Added Python, WSGI to XAMPP In-Reply-To: <4D06C130.9040506@verizon.net> References: <4CFA4305.10004@it.uu.se> <4CFD6825.9020200@simplistix.co.uk> <4CFD8B29.3020006@verizon.net> <4D014A3D.7020101@verizon.net> <4D06AD69.4030302@simplistix.co.uk> <4D06B6D1.6080208@verizon.net> <4D06B671.5020601@simplistix.co.uk> <4D06C130.9040506@verizon.net> Message-ID: On Mon, Dec 13, 2010 at 5:58 PM, Gerry Reno wrote: > The VIEW is the bits that stream out of the webserver back to the users > browser. ?The CONTROLLER is the code that gathers all the pieces from > the model and constructs the python code that is then fed to the engine > that then creates the view. ?And just because the controller navigates > the logic to dynamically contruct/render a view, that does not make 'it' > the view. In traditional MVC, the controller is the part that receives the user input, decides how to react to it, and instructs the model to update itself accordingly. It is not supposed to be some sort of intermediary between the model and the view, as many people seem to make it; the view is supposed to gather the data it needs to render itself directly from the model. In that light, I think that this quote from the Django FAQ is defensible: > In our interpretation of MVC, the ?view? describes the data that gets presented to the user. It?s not necessarily how the data looks, but which data is presented. The view describes which data you see, not how you see it. It?s a subtle distinction. Traditionally, the view would describe both of these things, but since "how you see it" is ultimately decided by the user's browser, they are fundamentally separated in the context of the web. The Django template-view split is in recognition of this fact. As for where the controller went, there are basically two decisions that need to be made when input is received: how to update the model as a result, and what data should be displayed next. The former decision belongs to the controller, the latter to the view. But in a web app, these two things tend to be highly correlated, and there seems to be little reason to separate them out into distinct components. This part then is both controller and view, and which word we use for it is not terribly important. I suppose that "view" tends to prevail since there are other components, such as URL dispatch, that are controllerish in nature. For these reasons, I find that in practice traditional MVC does not lend itself well to the HTTP request/response cycle, where the "view" as you define it has no access to the model and lacks any continuity whatsoever from one request to the next; but the Django MTV approach works just fine once you're willing to accept that it's not the same thing. Cheers, Ian From prog at vtr.net Wed Dec 15 19:46:38 2010 From: prog at vtr.net (craf) Date: Wed, 15 Dec 2010 21:46:38 -0300 Subject: Calling function from another module Message-ID: <1292460398.2086.11.camel@cristian-desktop> Hi. The query code is as follows: ------------------------------------------------------ import Tkinter import tkMessageBox class App: def __init__(self, master): master.protocol("WM_DELETE_WINDOW",quit) def quit(): if tkMessageBox.askyesno('','Exit'): master.quit() master =Tkinter.Tk() app = App(master) master.mainloop() ------------------------------------------------------- As you can see, when I run and close the main window displays a text box asking if you want to quit, if so, closes application. Question: Is it possible to define the quit() function in another separate module?. I tried it, but it throws the error that the global name 'master' is not defined. Thanks in advance. Regards Cristian Abarz?a From hpj at urpla.net Wed Dec 15 20:09:33 2010 From: hpj at urpla.net (Hans-Peter Jansen) Date: Thu, 16 Dec 2010 02:09:33 +0100 Subject: default argument in method In-Reply-To: <4d0955ae$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <4d0955ae$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <201012160209.34049.hpj@urpla.net> On Thursday 16 December 2010, 00:56:31 Steven D'Aprano wrote: > On Wed, 15 Dec 2010 21:10:05 +0100, Hans-Peter Jansen wrote: > > Since this is a major pitfall, it might be worth mentioning, that > > mutable default arguments are generally a bad idea, as the default > > arguments are evaluated just once, hence e.g. using an empty list > > might contain the items, that were appended in earlier calls of > > this method.. > > It's only a pitfall for users who expect that default arguments are > re- created every time you call the function; it's only a bad idea > for code which relies on the default arguments being re-created each > time. > > If you hold misunderstandings about the behaviour of a language, > you'll have trouble understanding what code does. Default arguments > are no different from any other feature. > > > Code, that _relies_ on such behavior should be yanked instantaneous > > and the producer of such code should be punished with coding APL? > > on a dubeolsik hangul keyboard? for a year at least.. > > Python code that relies on default arguments to *not* be re-created > on each function call is no worse than (say) Ruby code that relies on > default arguments *to* be re-created each time. > > I don't mean to be elitist (ah, who am I fooling, of course I do), > but when coders of the skill and experience of the Effbot and Guido > use mutable defaults, who are you to say they shouldn't? > > http://effbot.org/zone/default-values.htm > http://www.python.org/doc/essays/graphs/ Hmm, thanks for the pointers, Steven. I stand corrected, as I won't argue with taste.. I like the part about the disastrous results specially. If such code would be used in any collaborations, I would expect an explicit comment at least. Pete From greno at verizon.net Wed Dec 15 20:46:46 2010 From: greno at verizon.net (Gerry Reno) Date: Wed, 15 Dec 2010 20:46:46 -0500 Subject: Added Python, WSGI to XAMPP In-Reply-To: References: <4CFA4305.10004@it.uu.se> <4CFD6825.9020200@simplistix.co.uk> <4CFD8B29.3020006@verizon.net> <4D014A3D.7020101@verizon.net> <4D06AD69.4030302@simplistix.co.uk> <4D06B6D1.6080208@verizon.net> <4D06B671.5020601@simplistix.co.uk> <4D06C130.9040506@verizon.net> Message-ID: <4D096F86.80806@verizon.net> On 12/15/2010 07:36 PM, Ian Kelly wrote: > On Mon, Dec 13, 2010 at 5:58 PM, Gerry Reno wrote: > >> The VIEW is the bits that stream out of the webserver back to the users >> browser. The CONTROLLER is the code that gathers all the pieces from >> the model and constructs the python code that is then fed to the engine >> that then creates the view. And just because the controller navigates >> the logic to dynamically contruct/render a view, that does not make 'it' >> the view. >> > In traditional MVC, the controller is the part that receives the user > input, decides how to react to it, and instructs the model to update > itself accordingly. It is not supposed to be some sort of > intermediary between the model and the view, as many people seem to > make it; the view is supposed to gather the data it needs to render > itself directly from the model. In that light, I think that this > quote from the Django FAQ is defensible: > > >> In our interpretation of MVC, the ?view? describes the data that gets presented to the user. It?s not necessarily how the data looks, but which data is presented. The view describes which data you see, not how you see it. It?s a subtle distinction. >> > Traditionally, the view would describe both of these things, but since > "how you see it" is ultimately decided by the user's browser, they are > fundamentally separated in the context of the web. The Django > template-view split is in recognition of this fact. > > As for where the controller went, there are basically two decisions > that need to be made when input is received: how to update the model > as a result, and what data should be displayed next. The former > decision belongs to the controller, the latter to the view. But in a > web app, these two things tend to be highly correlated, and there > seems to be little reason to separate them out into distinct > components. This part then is both controller and view, and which > word we use for it is not terribly important. I suppose that "view" > tends to prevail since there are other components, such as URL > dispatch, that are controllerish in nature. > > For these reasons, I find that in practice traditional MVC does not > lend itself well to the HTTP request/response cycle, where the "view" > as you define it has no access to the model and lacks any continuity > whatsoever from one request to the next; but the Django MTV approach > works just fine once you're willing to accept that it's not the same > thing. > > Cheers, > Ian > > Django can use whatever approach they like. But don't call it an MVC framework and that is what they did initially at least. MTV is a contorted MVC. And it does not correlate very well with other MVC documentation which is very confusing to people. No doubt, the web is constraining. Request/response makes it difficult to have the Model independently notify the View that it needs to update itself because some state in the model has changed. That is why many of the diagrams about MVC on the web show the Controller interceding between the View and the Model. That doesn't mean MVC does not work on the web. It just means that there is a constraint imposed by the nature of the request/response stateless architecture. Maybe it's splitting hairs, but having things named 'View' on the server implies especially to newbies that the View exists on the server. The View exists on the client. And then later they discover that it's not really View but Controller and that Templates are View. I guess if we were screen-scraping we could actually have a server-side View. But normal MVC has the View on the client, and the Model and Controller in server capacities. And I don't see the value in naming things View on the server when for the most part the View (or view parts in the case of Ajax) are merely the output of render processes. -Gerry From katie at coderstack.co.uk Wed Dec 15 21:22:47 2010 From: katie at coderstack.co.uk (Katie T) Date: Thu, 16 Dec 2010 02:22:47 +0000 Subject: Help regarding pattern matching In-Reply-To: References: Message-ID: On Wed, Dec 15, 2010 at 9:21 PM, jupiter wrote: > Hi People, > > > I need some ideas on how to find pattern in random data series like stock chart. > > > What I want is to be able to find Head & Shoulder pattern in chart. Have a look at the references in: http://www.dpem.tuc.gr/fel/fm2009/Papers/Tsinaslanidis.pdf They cover a variety of algorithms for detecting such patterns. Katie -- CoderStack http://www.coderstack.co.uk/python-jobs The Software Developer Job Board From clp2 at rebertia.com Wed Dec 15 21:34:12 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 15 Dec 2010 18:34:12 -0800 Subject: Help regarding pattern matching In-Reply-To: References: Message-ID: On Wed, Dec 15, 2010 at 6:22 PM, Katie T wrote: > On Wed, Dec 15, 2010 at 9:21 PM, jupiter wrote: >> Hi People, >> >> I need some ideas on how to find pattern in random data series like stock chart. >> >> What I want is to be able to find Head & Shoulder pattern in chart. > > Have a look at the references in: > > http://www.dpem.tuc.gr/fel/fm2009/Papers/Tsinaslanidis.pdf Dead link! Cheers, Chris From katie at coderstack.co.uk Wed Dec 15 21:55:36 2010 From: katie at coderstack.co.uk (Katie T) Date: Thu, 16 Dec 2010 02:55:36 +0000 Subject: Help regarding pattern matching In-Reply-To: References: Message-ID: On Thu, Dec 16, 2010 at 2:34 AM, Chris Rebert wrote: > On Wed, Dec 15, 2010 at 6:22 PM, Katie T wrote: >> On Wed, Dec 15, 2010 at 9:21 PM, jupiter wrote: >>> Hi People, >>> >>> I need some ideas on how to find pattern in random data series like stock chart. >>> >>> What I want is to be able to find Head & Shoulder pattern in chart. >> >> Have a look at the references in: >> >> http://www.dpem.tuc.gr/fel/fm2009/Papers/Tsinaslanidis.pdf > http://uom-gr.academia.edu/ProdromosTsinaslanidis/Papers/281823/An_Examination_of_the_Head_and_Shoulders_Technical_Pattern_A_Support_of_the_Technical_Analysiss_Subjective_Nature Katie -- CoderStack http://www.coderstack.co.uk/python-jobs The Software Developer Job Board From rantingrick at gmail.com Thu Dec 16 00:06:02 2010 From: rantingrick at gmail.com (rantingrick) Date: Wed, 15 Dec 2010 21:06:02 -0800 (PST) Subject: Calling function from another module References: Message-ID: On Dec 15, 6:46?pm, craf wrote: > Hi. > > The query code is as follows: > > ------------------------------------------------------ > import Tkinter > import tkMessageBox > > class App: > ? ? def __init__(self, master): > ? ? ? ? master.protocol("WM_DELETE_WINDOW",quit) > > def quit(): > ? ? if tkMessageBox.askyesno('','Exit'): > ? ? ? ? master.quit() > > master =Tkinter.Tk() > app = App(master) > master.mainloop() > ------------------------------------------------------- > > As you can see, when I run and close the main window displays > a text box asking if you want to quit, if so, closes > application. > > Question: > > Is it possible to define the quit() function in another separate > module?. > I tried it, but it throws the error that the global name > 'master' is not defined. Please explain in detail what the "other module" is doing. And as written this class "app" looks pretty useless to me. Why subclass Tk (well it appears you "tried" to subclass it anyway) just to override capabilities that are already available within Tk? Also i see many mistakes in this very small code sample. Using my deductive logic leads me to believe that many mistakes in a small code sample translates to enormous mistakes in a larger code base. So feel free to ramble incessantly about the intricate workings of this jewel of Python scripting you are soon to drop on this malnourished group of coders. From greg.ewing at canterbury.ac.nz Thu Dec 16 01:09:32 2010 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Thu, 16 Dec 2010 19:09:32 +1300 Subject: ANN: PyGUI 2.3.2 Message-ID: PyGUI 2.3.2 is available: http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ This version fixes a problem in Cocoa whereby the coordinate system for drawing in a Pixmap was upside down, and corrects a slight mistake in the Canvas documentation. What is PyGUI? -------------- PyGUI is a cross-platform GUI toolkit designed to be lightweight and have a highly Pythonic API. -- Gregory Ewing greg.ewing at canterbury.ac.nz http://www.cosc.canterbury.ac.nz/greg.ewing/ From steve at holdenweb.com Thu Dec 16 01:48:46 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 16 Dec 2010 01:48:46 -0500 Subject: O'Reilly Python Certification In-Reply-To: <4D093176.3010109@pythonmeister.com> References: <4D0900D3.10000@stoneleaf.us> <4D0927C1.5080209@tim.thechases.com> <4D093176.3010109@pythonmeister.com> Message-ID: On 12/15/2010 4:21 PM, Stefan Sonnenberg-Carstens wrote: > Am 15.12.2010 22:11, schrieb Steve Holden: >> On 12/15/2010 3:40 PM, Tim Chase wrote: >>> On a more serious note, it would be interesting to know if it's possible >>> to test out of the certification for those of us that have been using >>> Python for a long time. >> That's an interesting idea - let a bunch of experienced Python users >> tell me what a lousy job I have done of explaining the language. :) >> >> Seriously, I would be interested, and it's a terrific idea. I can't do >> anything before January, but if anyone is interested in taking part in >> such a review of the materials I'd be grateful if they would contact me >> privately by email on a "no promises" basis. >> >> regards >> Steve > I think he meant: take the test without study first. > I'd be interested in both, though. > There isn't a test. The award of the certificate is based on providing working solutions to projects at the end of each lesson. Bear in mind I have not spoken to my O'Reilly contacts about whether they would be OK with such a scheme, hence the "no promises". regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From nagle at animats.com Thu Dec 16 02:21:27 2010 From: nagle at animats.com (John Nagle) Date: Wed, 15 Dec 2010 23:21:27 -0800 Subject: Links and pointers to basics of soap and suds In-Reply-To: References: Message-ID: <4d09be05$0$43998$742ec2ed@news.sonic.net> On 12/15/2010 5:14 AM, Steve Holden wrote: > On 12/15/2010 7:38 AM, srinivas hn wrote: >> Hi All, >> >> I am very new to the soap and its python client suds. Can anyone tell me >> how the actual will happens i nthe webservices including suds and soap API. >> > That's a bit like saying "I need to go around the corner. Would you mind > teaching me to drive?". > > Google for phrases like "web services architecture" and "SOAP WSDL" to > get some idea of how these technologies are put together. This assumes, > of course, that you already possess a fair idea of how the web is put > together. > > regards > Steve The "suds" module is a quite good client for well-written SOAP servers. Basically, it's a system for making a remote procedure call to a service on another machine. The "suds" module is quite easy to use if the service you're calling already exists, has a correct WSDL file describing the interface, and the documentation for users of the interface is correct. I use it to talk to Dun and Bradstreet's business database, for which it works quite well. Most simpler web services today tend to just encode queries in the URL and send back not-too-strict XML or JSON. This is called a "REST" interface. John Nagle From benedict.verheyen at gmail.com Thu Dec 16 03:09:55 2010 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Thu, 16 Dec 2010 09:09:55 +0100 Subject: Dealing with pywin32 on Linux In-Reply-To: <4D08E4B0.1080007@pythonmeister.com> References: <4D08E4B0.1080007@pythonmeister.com> Message-ID: On 15/12/2010 16:54, Stefan Sonnenberg-Carstens wrote: > Just change to LDAP as authentication method. > Even Active Directory offers LDAP (w/o SSL), and there > are modules to interact with LDAP using python. > And, it is platform indipendent. > > See here: http://www.python-ldap.org/ > > I've done this quite often to auth users in an AD with apache/ldap-auth. I've already ported some code yesterday with python-ldap. It works so it's fine for now, Regards, Benedict From nitinpawar432 at gmail.com Thu Dec 16 03:11:05 2010 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Thu, 16 Dec 2010 13:41:05 +0530 Subject: O'Reilly Python Certification In-Reply-To: References: <4D0900D3.10000@stoneleaf.us> <4D0927C1.5080209@tim.thechases.com> <4D093176.3010109@pythonmeister.com> Message-ID: Can someone provide any links or any starting points on how to apply and what are the prerequisites Thanks, Nitin On Thu, Dec 16, 2010 at 12:18 PM, Steve Holden wrote: > On 12/15/2010 4:21 PM, Stefan Sonnenberg-Carstens wrote: > > Am 15.12.2010 22:11, schrieb Steve Holden: > >> On 12/15/2010 3:40 PM, Tim Chase wrote: > >>> On a more serious note, it would be interesting to know if it's > possible > >>> to test out of the certification for those of us that have been using > >>> Python for a long time. > >> That's an interesting idea - let a bunch of experienced Python users > >> tell me what a lousy job I have done of explaining the language. :) > >> > >> Seriously, I would be interested, and it's a terrific idea. I can't do > >> anything before January, but if anyone is interested in taking part in > >> such a review of the materials I'd be grateful if they would contact me > >> privately by email on a "no promises" basis. > >> > >> regards > >> Steve > > I think he meant: take the test without study first. > > I'd be interested in both, though. > > > There isn't a test. The award of the certificate is based on providing > working solutions to projects at the end of each lesson. > > Bear in mind I have not spoken to my O'Reilly contacts about whether > they would be OK with such a scheme, hence the "no promises". > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ > See Python Video! http://python.mirocommunity.org/ > Holden Web LLC http://www.holdenweb.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From orasnita at gmail.com Thu Dec 16 04:36:30 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Thu, 16 Dec 2010 11:36:30 +0200 Subject: Added Python, WSGI to XAMPP References: <4CFA4305.10004@it.uu.se> <4CFD6825.9020200@simplistix.co.uk> <4CFD8B29.3020006@verizon.net><4D014A3D.7020101@verizon.net> <4D06AD69.4030302@simplistix.co.uk><4D06B6D1.6080208@verizon.net> <4D06B671.5020601@simplistix.co.uk><4D06C130.9040506@verizon.net> Message-ID: <08B25692CE8542B386238F7E02D317DD@teddy> From: "Ian Kelly" On Mon, Dec 13, 2010 at 5:58 PM, Gerry Reno wrote: > The VIEW is the bits that stream out of the webserver back to the users > browser. Why only to the user's browser? A web app could also offer the results in formats that can be accessed with something else than a browser. The view just offer the results, no matter what way. > The CONTROLLER is the code that gathers all the pieces from > the model and constructs the python code that is then fed to the engine > that then creates the view. And just because the controller navigates > the logic to dynamically contruct/render a view, that does not make 'it' > the view. > In traditional MVC, the controller is the part that receives the user > input, decides how to react to it, and instructs the model to update > itself accordingly. It is not supposed to be some sort of > intermediary between the model and the view, as many people seem to > make it; the view is supposed to gather the data it needs to render > itself directly from the model. How can the view know what data it should render if the controller doesn't inform it about it? It is less important if the view uses a smart templating system that doesn't need to ask the controller for data but can access the model directly, but the view or that templating system need to be informed by the controller what data need to ask from the model, so we can say that the intermediary is still the controller. And accessing the model directly from the view/templating system is not a good idea, because MVC is also prefered because it decouples the programming code and the web design, and in some cases it can be a security issue if the web designer that might not know programming would be able to change by mistake or with intention the code from the view/templating system that access the model. > In that light, I think that this quote from the Django FAQ is defensible: > > In our interpretation of MVC, the ?view? describes the data that gets presented to the user. It?s not necessarily how the data looks, but which > data is presented. The view describes which data you see, not how you see it. It?s a subtle distinction. But if the view doesn't decide how the data looks, who decide it? :-) > Traditionally, the view would describe both of these things, but since > "how you see it" is ultimately decided by the user's browser, they are > fundamentally separated in the context of the web. The Django > template-view split is in recognition of this fact. The same data can have any format that's not decided by the user browser. For example it can be displayed in .csv format, or .xls, or .xlsx, or .pdf, or .html, or it can be submitted by email, or sent to Twitter or another web site... > As for where the controller went, there are basically two decisions > that need to be made when input is received: how to update the model > as a result, and what data should be displayed next. The former > decision belongs to the controller, the latter to the view. The update of the model depends on the model and the display of results depends on the view. But the decision is controlled by the... controller. That's why it has that name, because it controls these things. Of course, the frontiers between the M and V and C might be subtle in some cases, but it is a good idea to push as much logic to the base. It is not a good idea to make the controller do the job of the model and imply in the business logic or make the view do the job of the controller and do something else than just present the data it receives. > But in a > web app, these two things tend to be highly correlated, and there > seems to be little reason to separate them out into distinct > components. This part then is both controller and view, and which > word we use for it is not terribly important. Yes, but in that case such a program wouldn't use the MVC model. And as I exemplified above, there are reasons why the view should only present the data it receives and don't access the model directly. Some web developers aren't even alowed to offer the ORM objects to the templates, although the coding would be much easier that way, but need to generate other objects in the controller that don't allow the web designers to change some things in the templates and access more data from the database than it is needed. > For these reasons, I find that in practice traditional MVC does not > lend itself well to the HTTP request/response cycle, where the "view" > as you define it has no access to the model and lacks any continuity > whatsoever from one request to the next; but the Django MTV approach > works just fine once you're willing to accept that it's not the same > thing. > > Cheers, Ian There is no "traditional MVC". There is just MVC or not MVC. The view shouldn't have any kind of continuity. The view should just present the data. HTTP is a stateless protocol and the controller that handles the requests, does URL dispatching, uses cookies or URL-based ways for maintaining that continuity, not the view. The so called "non-traditional" MVC idea appeared because many web apps use a lot of Javascript these days, and because of this thing Javascript gained a much bigger importance, and the Javascript programmers would like to happen everything in the view if possible because they don't like to depend so much on the server-side code. Octavian From bc at freeuk.com Thu Dec 16 05:44:28 2010 From: bc at freeuk.com (BartC) Date: Thu, 16 Dec 2010 10:44:28 -0000 Subject: while True or while 1 In-Reply-To: References: <4D051506.2060403@holdenweb.com> Message-ID: "Steve Holden" wrote in message news:mailman.462.1292214062.2649.python-list at python.org... > On 12/12/2010 2:32 PM, Christian Heimes wrote: >> Am 12.12.2010 19:31, schrieb Steve Holden: >> $ python -m timeit -n20 -- "i = 0" "while 1:" " i+=1" " if i == >> 1000000: break" >> 20 loops, best of 3: 89.7 msec per loop >> $ python -m timeit -n20 -- "i = 0" "while True:" " i+=1" " if i == >> 1000000: break" >> 20 loops, best of 3: 117 msec per loop >> No argue with that! I was merely making a point that "while 1" executes >> different byte code than "while True". Readability is important but >> sometimes speed is of the essence. "while 1" is one of the few tricks to >> speed up tight loops a bit. > > OK, but the figures you quote save you 27.3 ms per million iterations, > for a grand total saving of 27.3 ns per iteration. So "a bit" is hardly > worth considering for most programs, is it? One these is 30% faster than the other. That's an appreciable difference, which you can't really just dismiss. And you can't tell what the overall effect on a program will be: perhaps the loop will be in a library function , which might be called billions of times. -- Bartc From jeanmichel at sequans.com Thu Dec 16 06:55:20 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 16 Dec 2010 12:55:20 +0100 Subject: string identity and comparison Message-ID: <4D09FE28.4080907@sequans.com> Fellows, I'd like to illutrate the fact that comparing strings using identity is, most of the time, a bad idea. However I'm searching a short example of code that yields 2 differents object for the same string content. id('foo') 3082385472L id('foo') 3082385472L Anyone has that kind of code ? JM From bruno.desthuilliers at gmail.com Thu Dec 16 07:06:12 2010 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Thu, 16 Dec 2010 04:06:12 -0800 (PST) Subject: string identity and comparison References: Message-ID: <080f1a8f-8152-492b-8982-989a810278df@y3g2000vbm.googlegroups.com> On 16 d?c, 12:55, Jean-Michel Pichavant wrote: > Fellows, > > I'd like to illutrate the fact that comparing strings using identity is, > most of the time, a bad idea. However I'm searching a short example of > code that yields 2 differents object for the same string content. > > id('foo') > 3082385472L > id('foo') > 3082385472L > > Anyone has that kind of code ? 2 points: 1- an id is only valid for the lifetime of a given object - when the object has been collected, the id can be reused for another object. 2- in CPython, strings that would be valid Python identifiers are interned. Try using a string that would not be a valid Python identifier Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> id("Not a valid python identifier") 3076522016L >>> id("Not a valid python identifier") 3076522016L >>> s1 = "Not a valid python identifier" >>> s2 = "Not a valid python identifier" >>> s1 is s2 False >>> s1 == s2 True >>> HTH From andre.roberge at gmail.com Thu Dec 16 07:07:06 2010 From: andre.roberge at gmail.com (=?ISO-8859-1?Q?Andr=E9?=) Date: Thu, 16 Dec 2010 04:07:06 -0800 (PST) Subject: string identity and comparison In-Reply-To: Message-ID: On Thursday, December 16, 2010 7:55:20 AM UTC-4, jeanmichel wrote: > Fellows, > > I'd like to illutrate the fact that comparing strings using identity is, > most of the time, a bad idea. However I'm searching a short example of > code that yields 2 differents object for the same string content. > > id('foo') > 3082385472L > id('foo') > 3082385472L > > Anyone has that kind of code ? > > JM How about this: Python 2.6 (trunk:66714:66715M, Oct 1 2008, 18:36:04) [GCC 4.0.1 (Apple Computer, Inc. build 5370)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> a = 'spam' >>> b = 'spa' >>> c = a[:-1] >>> c 'spa' >>> id(c) 548256 >>> id(b) 548224 Or, even more simply, this: Jython 2.5.0 (Release_2_5_0:6476, Jun 16 2009, 13:33:26) [Java HotSpot(TM) Client VM (Apple Inc.)] on java1.5.0_26 Type "help", "copyright", "credits" or "license" for more information. >>> a = 'foo' >>> b = 'foo' >>> id(a) 1 >>> id(b) 2 Reusing immutable objects, for the sake of efficiency, is an implementation details which should not be relied upon (as you know since you ask for examples). Andr? From andre.roberge at gmail.com Thu Dec 16 07:07:06 2010 From: andre.roberge at gmail.com (=?ISO-8859-1?Q?Andr=E9?=) Date: Thu, 16 Dec 2010 04:07:06 -0800 (PST) Subject: string identity and comparison In-Reply-To: Message-ID: On Thursday, December 16, 2010 7:55:20 AM UTC-4, jeanmichel wrote: > Fellows, > > I'd like to illutrate the fact that comparing strings using identity is, > most of the time, a bad idea. However I'm searching a short example of > code that yields 2 differents object for the same string content. > > id('foo') > 3082385472L > id('foo') > 3082385472L > > Anyone has that kind of code ? > > JM How about this: Python 2.6 (trunk:66714:66715M, Oct 1 2008, 18:36:04) [GCC 4.0.1 (Apple Computer, Inc. build 5370)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> a = 'spam' >>> b = 'spa' >>> c = a[:-1] >>> c 'spa' >>> id(c) 548256 >>> id(b) 548224 Or, even more simply, this: Jython 2.5.0 (Release_2_5_0:6476, Jun 16 2009, 13:33:26) [Java HotSpot(TM) Client VM (Apple Inc.)] on java1.5.0_26 Type "help", "copyright", "credits" or "license" for more information. >>> a = 'foo' >>> b = 'foo' >>> id(a) 1 >>> id(b) 2 Reusing immutable objects, for the sake of efficiency, is an implementation details which should not be relied upon (as you know since you ask for examples). Andr? From __peter__ at web.de Thu Dec 16 07:16:30 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 16 Dec 2010 13:16:30 +0100 Subject: Calling function from another module References: Message-ID: craf wrote: > Hi. > > The query code is as follows: > > ------------------------------------------------------ > import Tkinter > import tkMessageBox > > > class App: > def __init__(self, master): > master.protocol("WM_DELETE_WINDOW",quit) > > > def quit(): > if tkMessageBox.askyesno('','Exit'): > master.quit() > > > master =Tkinter.Tk() > app = App(master) > master.mainloop() > ------------------------------------------------------- > > As you can see, when I run and close the main window displays > a text box asking if you want to quit, if so, closes > application. > > Question: > > Is it possible to define the quit() function in another separate > module?. > I tried it, but it throws the error that the global name > 'master' is not defined. You can have the modules import each other and then access the master as .master where you'd have to replace with the actual name of the module, but that's a bad design because (1) you create an import circle (2) functions relying on global variables already are a bad idea Your other option is to pass 'master' explicitly and then wrap it into a lambda function (or functools.partial): $ cat tkquitlib.py import tkMessageBox def quit(master): if tkMessageBox.askyesno('','Exit'): master.quit() $ cat tkquit_main.py import Tkinter import tkquitlib class App: def __init__(self, master): master.protocol("WM_DELETE_WINDOW", lambda: tkquitlib.quit(master)) master = Tkinter.Tk() app = App(master) master.mainloop() Peter From steve at holdenweb.com Thu Dec 16 07:23:40 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 16 Dec 2010 07:23:40 -0500 Subject: while True or while 1 In-Reply-To: References: <4D051506.2060403@holdenweb.com> Message-ID: On 12/16/2010 5:44 AM, BartC wrote: >> On 12/12/2010 2:32 PM, Christian Heimes wrote: >>> Am 12.12.2010 19:31, schrieb Steve Holden: >>> $ python -m timeit -n20 -- "i = 0" "while 1:" " i+=1" " if i == >>> 1000000: break" >>> 20 loops, best of 3: 89.7 msec per loop >>> $ python -m timeit -n20 -- "i = 0" "while True:" " i+=1" " if i == >>> 1000000: break" >>> 20 loops, best of 3: 117 msec per loop > >>> No argue with that! I was merely making a point that "while 1" executes >>> different byte code than "while True". Readability is important but >>> sometimes speed is of the essence. "while 1" is one of the few tricks to >>> speed up tight loops a bit. >> >> OK, but the figures you quote save you 27.3 ms per million iterations, >> for a grand total saving of 27.3 ns per iteration. So "a bit" is hardly >> worth considering for most programs, is it? > > One these is 30% faster than the other. That's an appreciable > difference, which you can't really just dismiss. > > And you can't tell what the overall effect on a program will be: perhaps > the loop will be in a library function , which might be called billions > of times. It might. But if the code it is calling does *anything* at all significant I can promise you that spending an extra 30% purely on the looping construct will still make a negligible difference to a program's execution time, and there are almost certainly going to be many other aspects of performance that will yield greater benefits from tuning. I realise that there are going to be some people who just flatly say "since 'while 1:' is quicker I am going to use it every time", and that their programs will still work. And I still maintain that (for English speakers) "while True:" is to be preferred. sholden at lifeboy ~ $ python -m timeit -- "i = 1" "while True:" " i += 1" " if i == 1000000: break" 10 loops, best of 3: 157 msec per loop sholden at lifeboy ~ $ python -m timeit -- "i = 1" "while True:" " i += 1" " if i == 1000000: break" " x = i+1" 10 loops, best of 3: 238 msec per loop sholden at lifeboy ~ $ python -m timeit -- "i = 1" "while 1:" " i += 1" " if i == 1000000: break" 10 loops, best of 3: 116 msec per loop sholden at lifeboy ~ $ python -m timeit -- "i = 1" "while 1:" " i += 1" " if i == 1000000: break" " x = i+1" 10 loops, best of 3: 195 msec per loop If binding a simple arithmetic expression adds more to the loop than the difference between "while 1:" and "while True:" you are wasting your time thinking about the savings under all but the most rigorous circumstances. Fortunately there is no penalty for ignoring my advice. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Thu Dec 16 07:28:15 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 16 Dec 2010 07:28:15 -0500 Subject: string identity and comparison In-Reply-To: <4D09FE28.4080907@sequans.com> References: <4D09FE28.4080907@sequans.com> Message-ID: On 12/16/2010 6:55 AM, Jean-Michel Pichavant wrote: > Fellows, > > I'd like to illutrate the fact that comparing strings using identity is, > most of the time, a bad idea. However I'm searching a short example of > code that yields 2 differents object for the same string content. > > id('foo') > 3082385472L > id('foo') > 3082385472L > > Anyone has that kind of code ? > > JM > >>> id("foo") 2146743808 >>> id ("f"+"o"+"o") 2146744096 >>> regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From prog at vtr.net Thu Dec 16 07:33:16 2010 From: prog at vtr.net (craf) Date: Thu, 16 Dec 2010 09:33:16 -0300 Subject: [Fwd: Re: Calling function from another module] Message-ID: <1292502796.2616.1.camel@cristian-desktop> --------- Mensaje reenviado -------- > De: Peter Otten <__peter__ at web.de> > Para: python-list at python.org > Asunto: Re: Calling function from another module > Fecha: Thu, 16 Dec 2010 13:16:30 +0100 > Grupos de noticias: comp.lang.python > > craf wrote: > > > Hi. > > > > The query code is as follows: > > > > ------------------------------------------------------ > > import Tkinter > > import tkMessageBox > > > > > > class App: > > def __init__(self, master): > > master.protocol("WM_DELETE_WINDOW",quit) > > > > > > def quit(): > > if tkMessageBox.askyesno('','Exit'): > > master.quit() > > > > > > master =Tkinter.Tk() > > app = App(master) > > master.mainloop() > > ------------------------------------------------------- > > > > As you can see, when I run and close the main window displays > > a text box asking if you want to quit, if so, closes > > application. > > > > Question: > > > > Is it possible to define the quit() function in another separate > > module?. > > I tried it, but it throws the error that the global name > > 'master' is not defined. > > You can have the modules import each other and then access the master as > .master where you'd have to replace with the actual name of > the module, but that's a bad design because > > (1) you create an import circle > (2) functions relying on global variables already are a bad idea > > Your other option is to pass 'master' explicitly and then wrap it into a > lambda function (or functools.partial): > > $ cat tkquitlib.py > import tkMessageBox > > def quit(master): > if tkMessageBox.askyesno('','Exit'): > master.quit() > > > $ cat tkquit_main.py > import Tkinter > > import tkquitlib > > class App: > def __init__(self, master): > master.protocol("WM_DELETE_WINDOW", lambda: tkquitlib.quit(master)) > > master = Tkinter.Tk() > app = App(master) > master.mainloop() > > Peter Hi Peter. ?Right!. Your example can separate the creation of the interface to the code execution. Thanks for your time. Regards Cristian From __peter__ at web.de Thu Dec 16 07:50:45 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 16 Dec 2010 13:50:45 +0100 Subject: string identity and comparison References: <4D09FE28.4080907@sequans.com> Message-ID: Steve Holden wrote: > On 12/16/2010 6:55 AM, Jean-Michel Pichavant wrote: >> Fellows, >> >> I'd like to illutrate the fact that comparing strings using identity is, >> most of the time, a bad idea. However I'm searching a short example of >> code that yields 2 differents object for the same string content. >> >> id('foo') >> 3082385472L >> id('foo') >> 3082385472L >> >> Anyone has that kind of code ? >> >> JM >> >>>> id("foo") > 2146743808 >>>> id ("f"+"o"+"o") > 2146744096 Note that the concatenation may be misleading because it's not the direct reason that the ids differ; the first string doesn't exist anymore when the second is built, but the memory location of the first "foo" is occupied (perhaps by an intermediate string) when the second "foo" is created. To illustrate: >>> id("foo") 140394722220912 >>> id("bar") 140394722220912 >>> id("foo") 140394722220912 >>> x = 1234 >>> id("foo") 140394722221008 From mark.dufour at gmail.com Thu Dec 16 07:54:37 2010 From: mark.dufour at gmail.com (Mark Dufour) Date: Thu, 16 Dec 2010 13:54:37 +0100 Subject: ANN: Shed Skin 0.7 Message-ID: Hi all, I have just released Shed Skin 0.7, an optimizing (restricted-)Python-to-C++ compiler. It comes with lots of minor fixes and some optimizations, a new Windows package (which includes GCC 4.5), and two nice new examples, for a total of 52 examples at around 14,000 lines (sloccount). Please see my blog for the full announcement: http://shed-skin.blogspot.com Or go straight to the homepage: http://shedskin.googlecode.com Please have a look at the tutorial, try it out, and report issues at the homepage. Thanks, Mark Dufour -- http://www.youtube.com/watch?v=E6LsfnBmdnk -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Thu Dec 16 07:58:06 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 16 Dec 2010 13:58:06 +0100 Subject: string identity and comparison References: <4D09FE28.4080907@sequans.com> Message-ID: Peter Otten wrote: > Steve Holden wrote: > >> On 12/16/2010 6:55 AM, Jean-Michel Pichavant wrote: >>> Fellows, >>> >>> I'd like to illutrate the fact that comparing strings using identity is, >>> most of the time, a bad idea. However I'm searching a short example of >>> code that yields 2 differents object for the same string content. >>> >>> id('foo') >>> 3082385472L >>> id('foo') >>> 3082385472L >>> >>> Anyone has that kind of code ? >>> >>> JM >>> >>>>> id("foo") >> 2146743808 >>>>> id ("f"+"o"+"o") >> 2146744096 > > Note that the concatenation may be misleading because it's not the direct > reason that the ids differ; the first string doesn't exist anymore when > the second is built, but the memory location of the first "foo" is > occupied (perhaps by an intermediate string) when the second "foo" is > created. To illustrate: > >>>> id("foo") > 140394722220912 >>>> id("bar") > 140394722220912 > >>>> id("foo") > 140394722220912 >>>> x = 1234 >>>> id("foo") > 140394722221008 Or less convoluted: >>> foo = "f" + "o" + "o" >>> foo is "foo" True From jiangsuwu88 at gmail.com Thu Dec 16 08:13:28 2010 From: jiangsuwu88 at gmail.com (brandseller) Date: Thu, 16 Dec 2010 05:13:28 -0800 (PST) Subject: Cheap Wholesale Adidas Running (paypal payment) (http://www.brandtrade66.com/ Message-ID: <6042073c-8f09-42b3-a648-82e48cc11815@q8g2000prm.googlegroups.com> Cheap Wholesale UGG Shoes (paypal payment) (http://www.brandtrade66.com/) Cheap Wholesale Ugg Boots (paypal payment) Cheap Wholesale Gucci Shoes (paypal payment) (http://www.brandtrade66.com/) Cheap Wholesale GUCCI Boots Cheap Wholesale Lacoste Shoes Cheap Wholesale LV Shoes (paypal payment) (http://www.brandtrade66.com/ ) Cheap Wholesale LV Boots Cheap Wholesale Prada Shoes (paypal payment) (http://www.brandtrade66.com/) Cheap Wholesale Timberland Shoes Cheap Wholesale D&G Shoes (paypal payment) (http://www.brandtrade66.com/) Cheap Wholesale D&G Boots Cheap Wholesale Puma Shoes Cheap Wholesale Puma AAA (paypal payment) (http://www.brandtrade66.com/) Cheap Wholesale UGG Boots Shoes Cheap Wholesale Bikkem Bergs Shoes (free shipping) Cheap Wholesale Mauri Shoes Man Cheap Wholesale Versace Shoes (paypal payment) (http://www.brandtrade66.com/) Cheap Wholesale Versace Boots Cheap Wholesale Paul Smith Shoes (free shipping) Cheap Wholesale BOSS Shoes Cheap Wholesale Burberry Shoes (paypal payment) (http://www.brandtrade66.com/ ) Cheap Wholesale Dsquared shoes Cheap Wholesale Dior Shoes (free shipping) Cheap Wholesale Dior Boots Cheap Wholesale ED Hardy Shoes (paypal payment) (http://www.brandtrade66.com/ ) Cheap Wholesale ED Hardy Boots Cheap Wholesale ED Hardy Shoes Man (paypal payment) (http://www.brandtrade66.com/ ) Cheap Wholesale Fendi Shoes (paypal payment) (http://www.brandtrade66.com/ ) Cheap Wholesale Fendi Boots Cheap Wholesale AFF Shoes (paypal payment) (http://www.brandtrade66.com/ ) Cheap Wholesale Evisu Shoes (free shipping) Cheap Wholesale 4US Shoes Cheap Wholesale Sebago Shoes (paypal payment) (http://www.brandtrade66.com/ ) Cheap Wholesale Supra Shoes Cheap Wholesale Hight Converse Shoes (paypal payment) (http://www.brandtrade66.com/ ) Cheap Wholesale Coach Boots Cheap Wholesale Coach Shoes Women Christian Louboutin (paypal payment) (http://www.brandtrade66.com/ ) Cheap Wholesale Chanel Shoes Cheap Wholesale Chanel Boots (free shipping) Cheap Wholesale Bape Shoes Cheap Wholesale Adidas Shoes (paypal payment) (http://www.brandtrade66.com/ ) Cheap Wholesale Adicolor (free shipping) Cheap Wholesale Adidas 35TH (paypal payment) (http://www.brandtrade66.com/ ) Cheap Wholesale Adidas NBA Cheap Wholesale Adidas Running (paypal payment) (http://www.brandtrade66.com/ ) Cheap Wholesale Adidas Y3 Cheap Wholesale Soccer Shoes (paypal payment) (http://www.brandtrade66.com/ ) From as at sci.fi Thu Dec 16 08:20:47 2010 From: as at sci.fi (Anssi Saari) Date: Thu, 16 Dec 2010 15:20:47 +0200 Subject: Extending Thunderbird mail client with Python References: Message-ID: John Bond writes: > Anyone have any experience with this, ideally using Python 3? I don't but there is a great need to have a working SyncML client for Thunderbird. Funambol used to have one available, but it has crashing problems with Thunderbird 3 for some people. The existing extension was done in C++. From mwilson at the-wire.com Thu Dec 16 08:50:36 2010 From: mwilson at the-wire.com (Mel) Date: Thu, 16 Dec 2010 08:50:36 -0500 Subject: string identity and comparison References: Message-ID: Jean-Michel Pichavant wrote: > Fellows, > > I'd like to illutrate the fact that comparing strings using identity is, > most of the time, a bad idea. However I'm searching a short example of > code that yields 2 differents object for the same string content. > > id('foo') > 3082385472L > id('foo') > 3082385472L > > Anyone has that kind of code ? Currently, CPython interns strings that look like identifiers. Any strings that don't look like identifiers are on their own: mwilson at tecumseth:~/sandbox/candlekit/stringlight-1$ python Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> a = 'x(3)' >>> id(a) 3075373248L >>> c='x(3)' >>> id(c) 3075373856L >>> a==c True Mel. From jeanmichel at sequans.com Thu Dec 16 08:58:46 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 16 Dec 2010 14:58:46 +0100 Subject: string identity and comparison In-Reply-To: <4D09FE28.4080907@sequans.com> References: <4D09FE28.4080907@sequans.com> Message-ID: <4D0A1B16.7040702@sequans.com> Jean-Michel Pichavant wrote: > Fellows, > > I'd like to illutrate the fact that comparing strings using identity > is, most of the time, a bad idea. However I'm searching a short > example of code that yields 2 differents object for the same string > content. > > id('foo') > 3082385472L > id('foo') > 3082385472L > > Anyone has that kind of code ? > > JM > a = 'foo' b = '%s' % a a is b >>> False Yet another Auto replied thread from myself :-/ JM From python at bdurham.com Thu Dec 16 09:20:58 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 16 Dec 2010 09:20:58 -0500 Subject: ANN: Shed Skin 0.7 In-Reply-To: References: Message-ID: <1292509258.10819.1410661291@webmail.messagingengine.com> Mark, Congratulations on your latest release! How well do python extension modules created with ShedSkin work with applications that expose a GUI, eg. Tkinter or wxPython apps? Can ShedSkin code be run in a thread and communicate with the main interpreter thread through a Queue or Lock? (Or should one use the multiprocessing module?) Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Thu Dec 16 09:52:50 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 16 Dec 2010 15:52:50 +0100 Subject: string identity and comparison In-Reply-To: <080f1a8f-8152-492b-8982-989a810278df@y3g2000vbm.googlegroups.com> References: <080f1a8f-8152-492b-8982-989a810278df@y3g2000vbm.googlegroups.com> Message-ID: <4D0A27C2.6080805@sequans.com> bruno.desthuilliers at gmail.com wrote: > On 16 d?c, 12:55, Jean-Michel Pichavant > wrote: > >> id('foo') >> 3082385472L >> id('foo') >> 3082385472L >> >> Anyone has that kind of code ? >> > > 2 points: > > > 1- an id is only valid for the lifetime of a given object - when the > object has been collected, the id can be reused for another object. > > that's exactly what happened in my example, the 2 'foo' are not the same object actually, the fact that the 2 successive id() calls return the same value is implementation specific. Thanks for pointing that out, I didn't realize in the first place. JM From jeanmichel at sequans.com Thu Dec 16 09:53:19 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 16 Dec 2010 15:53:19 +0100 Subject: string identity and comparison In-Reply-To: References: Message-ID: <4D0A27DF.7060108@sequans.com> Mel wrote: > Jean-Michel Pichavant wrote: > > >> Fellows, >> >> I'd like to illutrate the fact that comparing strings using identity is, >> most of the time, a bad idea. However I'm searching a short example of >> code that yields 2 differents object for the same string content. >> >> id('foo') >> 3082385472L >> id('foo') >> 3082385472L >> >> Anyone has that kind of code ? >> > > Currently, CPython interns strings that look like identifiers. Any strings > that don't look like identifiers are on their own: > > mwilson at tecumseth:~/sandbox/candlekit/stringlight-1$ python > Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) > [GCC 4.4.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>>> a = 'x(3)' >>>> id(a) >>>> > 3075373248L > >>>> c='x(3)' >>>> id(c) >>>> > 3075373856L > >>>> a==c >>>> > True > > > Mel. > thanks to all who replied. It looks like there are some differences between python 2.5 & 2.6, I tested all the possibilities I've been given in this thread and did not always get the same result. Anyway I found what I was looking for. JM From ethan at stoneleaf.us Thu Dec 16 10:29:25 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 16 Dec 2010 07:29:25 -0800 Subject: How to pop the interpreter's stack? In-Reply-To: References: Message-ID: <4D0A3055.7030308@stoneleaf.us> Tim Arnold wrote: > "Ethan Furman" wrote in message > news:mailman.4.1292379995.6505.python-list at python.org... >> kj wrote: >>> The one thing I don't like about this strategy is that the tracebacks >>> of exceptions raised during the execution of __pre_spam include one >>> unwanted stack level (namely, the one corresponding to __pre_spam >>> itself). >>> >>> __pre_spam should be completely invisible and unobtrusive >> I am unaware of any way to accomplish what you desire. I also think this >> is one of those things that's not worth fighting -- how often are you >> going to see such a traceback? When somebody makes a coding mistake? I >> would say change the name (assuming yours was a real example) to something >> more meaningful like _spam_arg_verifier and call it good. >> >> Alternatively, perhaps you could make a more general arg_verifier that >> could be used for all such needs, and then your traceback would have: >> >> caller >> >> spam >> >> arg_verifier >> >> and that seems useful to me (it is, in fact, how I have mine set up). >> >> Hope this helps! >> >> ~Ethan~ > > I thought people would advise using a decorator for this one. Wouldn't that > work? > thanks, > --Tim A decorator was one of the items kj explicity didn't want. Also, while it would have a shallower traceback for exceptions raised during the __pre_spam portion, any exceptions raised during spam itself would then be one level deeper than desired... while that could be masked by catching and (re-?)raising the exception in the decorator, Steven had a very good point about why that is a bad idea -- namely, tracebacks shouldn't lie about where the error is. ~Ethan~ From ethan at stoneleaf.us Thu Dec 16 10:36:10 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 16 Dec 2010 07:36:10 -0800 Subject: while True or while 1 In-Reply-To: References: <4D051506.2060403@holdenweb.com> Message-ID: <4D0A31EA.10203@stoneleaf.us> BartC wrote: > "Steve Holden" wrote in message > news:mailman.462.1292214062.2649.python-list at python.org... >> On 12/12/2010 2:32 PM, Christian Heimes wrote: >>> Am 12.12.2010 19:31, schrieb Steve Holden: >>> $ python -m timeit -n20 -- "i = 0" "while 1:" " i+=1" " if i == >>> 1000000: break" >>> 20 loops, best of 3: 89.7 msec per loop >>> $ python -m timeit -n20 -- "i = 0" "while True:" " i+=1" " if i == >>> 1000000: break" >>> 20 loops, best of 3: 117 msec per loop > >>> No argue with that! I was merely making a point that "while 1" executes >>> different byte code than "while True". Readability is important but >>> sometimes speed is of the essence. "while 1" is one of the few tricks to >>> speed up tight loops a bit. >> >> OK, but the figures you quote save you 27.3 ms per million iterations, >> for a grand total saving of 27.3 ns per iteration. So "a bit" is hardly >> worth considering for most programs, is it? > > One these is 30% faster than the other. That's an appreciable > difference, which you can't really just dismiss. Anecdotal evidence says it is easily dismissed: I had a routine that processed records from a table using custom, on the fly, code. I could either use exec for each record to do the work, or create a function that would then be called. I timed exec vs function, and found the function style to be about 200% faster... Eureka!, I thought. After putting the functional method in place, a run that took about 16 minutes using the old exec method ran two (2!) seconds faster. Great learning experience, for both the function method (which I prefer), and the need for profiling. ~Ethan~ From ethan at stoneleaf.us Thu Dec 16 10:40:54 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 16 Dec 2010 07:40:54 -0800 Subject: O'Reilly Python Certification In-Reply-To: References: <4D0900D3.10000@stoneleaf.us> <4D0927C1.5080209@tim.thechases.com> <4D093176.3010109@pythonmeister.com> Message-ID: <4D0A3306.3090100@stoneleaf.us> Please don't top-post. :) Nitin Pawar wrote: > Can someone provide any links or any starting points on how to apply and > what are the prerequisites http://www.oreillyschool.com/certificates/python-programming.php No prerequisites that I could see, and currently they are running a 25% discount promotional. ~Ethan~ From bruno.desthuilliers at gmail.com Thu Dec 16 10:41:39 2010 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Thu, 16 Dec 2010 07:41:39 -0800 (PST) Subject: string identity and comparison References: <080f1a8f-8152-492b-8982-989a810278df@y3g2000vbm.googlegroups.com> Message-ID: <00a175d6-a8ea-4d81-b6bf-296b3202f269@c13g2000prc.googlegroups.com> On 16 d?c, 15:52, Jean-Michel Pichavant wrote: > bruno.desthuilli... at gmail.com wrote: > > On 16 d c, 12:55, Jean-Michel Pichavant > > wrote: > > >> id('foo') > >> 3082385472L > >> id('foo') > >> 3082385472L > > >> Anyone has that kind of code ? > > > 2 points: > > > 1- an id is only valid for the lifetime of a given object - when the > > object has been collected, the id can be reused for another object. > > that's exactly what happened in my example, the 2 'foo' are not the same > object actually, the fact that the 2 successive id() calls return the > same value is implementation specific. > Thanks for pointing that out, I didn't realize in the first place. > been here, done that :-/ From bruno.desthuilliers at gmail.com Thu Dec 16 10:43:41 2010 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Thu, 16 Dec 2010 07:43:41 -0800 (PST) Subject: string identity and comparison References: Message-ID: <63f18a8e-1ef7-456e-895f-6347a7d732e2@a28g2000prb.googlegroups.com> On 16 d?c, 15:53, Jean-Michel Pichavant wrote: > Mel wrote: > > Jean-Michel Pichavant wrote: > > >> Fellows, > > >> I'd like to illutrate the fact that comparing strings using identity is, > >> most of the time, a bad idea. However I'm searching a short example of > >> code that yields 2 differents object for the same string content. > > >> id('foo') > >> 3082385472L > >> id('foo') > >> 3082385472L > > >> Anyone has that kind of code ? > > > Currently, CPython interns strings that look like identifiers. ?Any strings > > that don't look like identifiers are on their own: > > > mwilson at tecumseth:~/sandbox/candlekit/stringlight-1$ python > > Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) > > [GCC 4.4.3] on linux2 > > Type "help", "copyright", "credits" or "license" for more information. > > >>>> a = 'x(3)' > >>>> id(a) > > > 3075373248L > > >>>> c='x(3)' > >>>> id(c) > > > 3075373856L > > >>>> a==c > > > True > > > ? ?Mel. > > thanks to all who replied. > > It looks like there are some differences between python 2.5 & 2.6, I > tested all the possibilities I've been given in this thread and did not > always get the same result. Which FWIW is one more reason to avoid identity testing on strings - too much implementation specific stuff happening here. From steve+comp.lang.python at pearwood.info Thu Dec 16 11:23:36 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Dec 2010 16:23:36 GMT Subject: How to pop the interpreter's stack? References: Message-ID: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> On Thu, 16 Dec 2010 07:29:25 -0800, Ethan Furman wrote: > Tim Arnold wrote: >> "Ethan Furman" wrote in message >> news:mailman.4.1292379995.6505.python-list at python.org... >>> kj wrote: >>>> The one thing I don't like about this strategy is that the tracebacks >>>> of exceptions raised during the execution of __pre_spam include one >>>> unwanted stack level (namely, the one corresponding to __pre_spam >>>> itself). [...] > A decorator was one of the items kj explicity didn't want. Also, while > it would have a shallower traceback for exceptions raised during the > __pre_spam portion, any exceptions raised during spam itself would then > be one level deeper than desired... while that could be masked by > catching and (re-?)raising the exception in the decorator, Steven had a > very good point about why that is a bad idea -- namely, tracebacks > shouldn't lie about where the error is. True, very true... but many hours later, it suddenly hit me that what KJ was asking for wasn't *necessarily* such a bad idea. My thought is, suppose you have a function spam(x) which raises an exception. If it's a *bug*, then absolutely you need to see exactly where the error occurred, without the traceback being mangled or changed in any way. But what if the exception is deliberate, part of the function's documented behaviour? Then you might want the exception to appear to come from the function spam even if it was actually generated inside some private sub-routine. So, with qualifications, I have half changed my mind. -- Steven From robert.kern at gmail.com Thu Dec 16 11:39:34 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 16 Dec 2010 10:39:34 -0600 Subject: How to pop the interpreter's stack? In-Reply-To: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 12/16/10 10:23 AM, Steven D'Aprano wrote: > On Thu, 16 Dec 2010 07:29:25 -0800, Ethan Furman wrote: > >> Tim Arnold wrote: >>> "Ethan Furman" wrote in message >>> news:mailman.4.1292379995.6505.python-list at python.org... >>>> kj wrote: >>>>> The one thing I don't like about this strategy is that the tracebacks >>>>> of exceptions raised during the execution of __pre_spam include one >>>>> unwanted stack level (namely, the one corresponding to __pre_spam >>>>> itself). > [...] >> A decorator was one of the items kj explicity didn't want. Also, while >> it would have a shallower traceback for exceptions raised during the >> __pre_spam portion, any exceptions raised during spam itself would then >> be one level deeper than desired... while that could be masked by >> catching and (re-?)raising the exception in the decorator, Steven had a >> very good point about why that is a bad idea -- namely, tracebacks >> shouldn't lie about where the error is. > > True, very true... but many hours later, it suddenly hit me that what KJ > was asking for wasn't *necessarily* such a bad idea. My thought is, > suppose you have a function spam(x) which raises an exception. If it's a > *bug*, then absolutely you need to see exactly where the error occurred, > without the traceback being mangled or changed in any way. > > But what if the exception is deliberate, part of the function's > documented behaviour? Then you might want the exception to appear to come > from the function spam even if it was actually generated inside some > private sub-routine. Obfuscating the location that an exception gets raised prevents a lot of debugging (by inspection or by pdb), even if the exception is deliberately raised with an informative error message. Not least, the code that decides to raise that exception may be buggy. But even if the actual error is outside of the function (e.g. the caller is passing bad arguments), you want to at least see what tests the __pre_spam function is doing in order to decide to raise that exception. Tracebacks are inherently over-verbose. This is necessarily true because no algorithm (or clever programmer) can know all the pieces of information that the person debugging may want to know a priori. Most customizations of tracebacks *add* more verbosity rather than reduce it. Removing one stack level from the traceback barely makes the traceback more readable and removes some of the most relevant 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 mixedpuppy at gmail.com Thu Dec 16 12:03:49 2010 From: mixedpuppy at gmail.com (mixedpuppy) Date: Thu, 16 Dec 2010 09:03:49 -0800 (PST) Subject: Extending Thunderbird mail client with Python References: Message-ID: <110411fa-26da-4023-b955-f1dfff13665c@z26g2000prf.googlegroups.com> On Nov 11, 11:48?pm, John Bond wrote: > Anyone have any experience with this, ideally using Python 3? > > I'd like to sync my Thunderbird contacts with various things including > my mobile phone. Of course, I want to do it with Python! I've seen some > stuff around, eg. an XPI that provides Python bindings to the Mozilla > XPCOM APIs (through which I imagine you can access Thunderbird data like > its contacts database), but it doesn't seem maintained or ported to > Python 3. > > Cheers, JB While this doesn't provide a solution right now...look at https://mozillalabs.com/messaging/thunderbird-contacts/ and the highly experimental-working-but-not-yet-right sync addon for thunderbird (weave-ext and weaver repos) at https://bitbucket.org/mixedpuppy The sync addon is Firefox sync for thunderbird, not an ability to sync to your phone (yet). however, this is all js. shane From msarro at gmail.com Thu Dec 16 12:12:42 2010 From: msarro at gmail.com (Matty Sarro) Date: Thu, 16 Dec 2010 12:12:42 -0500 Subject: O'Reilly Python Certification In-Reply-To: <4D0A3306.3090100@stoneleaf.us> References: <4D0900D3.10000@stoneleaf.us> <4D0927C1.5080209@tim.thechases.com> <4D093176.3010109@pythonmeister.com> <4D0A3306.3090100@stoneleaf.us> Message-ID: So how exactly does the class work? Is it like an elementary CS class where you have a teacher, assignments, etc. Or is it more like a guided tour through the O'Reilly Python book/cookbook? On Thu, Dec 16, 2010 at 10:40 AM, Ethan Furman wrote: > Please don't top-post. ?:) > > Nitin Pawar wrote: >> >> Can someone provide any links or any starting points on how to apply and >> what are the prerequisites > > http://www.oreillyschool.com/certificates/python-programming.php > > No prerequisites that I could see, and currently they are running a 25% > discount promotional. > > ~Ethan~ > -- > http://mail.python.org/mailman/listinfo/python-list > From steve at holdenweb.com Thu Dec 16 13:27:23 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 16 Dec 2010 13:27:23 -0500 Subject: O'Reilly Python Certification In-Reply-To: References: <4D0900D3.10000@stoneleaf.us> <4D0927C1.5080209@tim.thechases.com> <4D093176.3010109@pythonmeister.com> <4D0A3306.3090100@stoneleaf.us> Message-ID: <4D0A5A0B.3040709@holdenweb.com> Each lesson required you to complete a practical assignment. You submit these assignments for evaluation, and do not proceed to the next lesson until your assignment reaches a satisfactory standard. Thus, less experienced students will tend to have more interaction with their tutors. A class will typically have between twelve and sixteen lessons. There are also quizzes and a final practical project. regards Steve On 12/16/2010 12:12 PM, Matty Sarro wrote: > So how exactly does the class work? Is it like an elementary CS class > where you have a teacher, assignments, etc. Or is it more like a > guided tour through the O'Reilly Python book/cookbook? > > On Thu, Dec 16, 2010 at 10:40 AM, Ethan Furman wrote: >> Please don't top-post. :) >> >> Nitin Pawar wrote: >>> >>> Can someone provide any links or any starting points on how to apply and >>> what are the prerequisites >> >> http://www.oreillyschool.com/certificates/python-programming.php >> >> No prerequisites that I could see, and currently they are running a 25% >> discount promotional. >> >> ~Ethan~ >> -- >> http://mail.python.org/mailman/listinfo/python-list >> -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From utabintarbo at gmail.com Thu Dec 16 13:33:53 2010 From: utabintarbo at gmail.com (utabintarbo) Date: Thu, 16 Dec 2010 10:33:53 -0800 (PST) Subject: Python creates "locked" temp dir References: <0c30c818-f73b-4b09-b707-64ea457c757d@z26g2000prf.googlegroups.com> <91dca7c4-00c7-44ad-8902-54221534107c@o9g2000pre.googlegroups.com> <753d0b5b-867b-456c-b3e9-2662ce1df1f8@f20g2000vbc.googlegroups.com> Message-ID: FWIW, I got around the issue with some samba mount options. They still show as 0700, but I, or anybody elsefor that matter, can still access them. Computers are weird. :P Thanks to all who responded. :) On Dec 10, 2:57?pm, Alex Willmer wrote: > On Dec 8, 6:26?pm, Christian Heimes wrote: > > > There isn't a way to limit access to a single process. mkdtemp creates > > the directory with mode 0700 and thus limits it to the (effective) user > > of the current process. Any process of the same user is able to access > > the directory. > > > Christian > > Quite right. My apologies for confusing temporary file creation, for > which exclusive access is used and temporary directory creation for > which there is no such mode. From python at bdurham.com Thu Dec 16 15:03:13 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 16 Dec 2010 15:03:13 -0500 Subject: Is text processing with dicts a good use case for Python cross-compilers like Cython/Pyrex or ShedSkin? Message-ID: <1292529793.31067.1410717477@webmail.messagingengine.com> Is text processing with dicts a good use case for Python cross-compilers like Cython/Pyrex or ShedSkin? (I've read the cross compiler claims about massive increases in pure numeric performance). I have 3 use cases I'm considering for Python-to-C++ cross-compilers for generating 32-bit Python extension modules for Python 2.7 for Windows. 1. Parsing UTF-8 files (basic Python with lots of string processing and dict lookups) 2. Generating UTF-8 files from nested list/dict structures 3. Parsing large ASCII "CSV-like" files and using dict's to calculate simple statistics like running totals, min, max, etc. Are any of these text processing scenarios good use cases for tools like Cython, Pyrex, or ShedSkin? Are any of these specifically bad use cases for these tools? We've tried Psyco and it has sped up some of our parsing utilities by 200%. But Psyco doesn't support Python 2.7 yet and we're committed to using Python 2.7 moving forward. Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From arnodel at gmail.com Thu Dec 16 15:27:36 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Thu, 16 Dec 2010 20:27:36 +0000 Subject: while True or while 1 References: <4D051506.2060403@holdenweb.com> Message-ID: <87d3p1bgzr.fsf@gmail.com> Ethan Furman writes: > ...I timed exec vs function, and found the function style to be about > 200% faster... So it finished before it started? -- Arnaud From tjreedy at udel.edu Thu Dec 16 15:32:31 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 16 Dec 2010 15:32:31 -0500 Subject: while True or while 1 In-Reply-To: References: <4D051506.2060403@holdenweb.com> Message-ID: On 12/16/2010 7:23 AM, Steve Holden wrote: > On 12/16/2010 5:44 AM, BartC wrote: >> One these is 30% faster than the other. That's an appreciable >> difference, which you can't really just dismiss. >> >> And you can't tell what the overall effect on a program will be: perhaps >> the loop will be in a library function , which might be called billions >> of times. > > It might. But if the code it is calling does *anything* at all > significant I can promise you that spending an extra 30% purely on the > looping construct will still make a negligible difference to a program's > execution time, and there are almost certainly going to be many other > aspects of performance that will yield greater benefits from tuning. > > I realise that there are going to be some people who just flatly say > "since 'while 1:' is quicker I am going to use it every time", and that > their programs will still work. And I still maintain that (for English > speakers) "while True:" is to be preferred. > > sholden at lifeboy ~ > $ python -m timeit -- "i = 1" "while True:" " i += 1" " if i == > 1000000: break" > 10 loops, best of 3: 157 msec per loop > > sholden at lifeboy ~ > $ python -m timeit -- "i = 1" "while True:" " i += 1" " if i == > 1000000: break" " x = i+1" > 10 loops, best of 3: 238 msec per loop > > sholden at lifeboy ~ > $ python -m timeit -- "i = 1" "while 1:" " i += 1" " if i == > 1000000: break" > 10 loops, best of 3: 116 msec per loop > > sholden at lifeboy ~ > $ python -m timeit -- "i = 1" "while 1:" " i += 1" " if i == > 1000000: break" " x = i+1" > 10 loops, best of 3: 195 msec per loop This are all Python2 timings. > If binding a simple arithmetic expression adds more to the loop than the > difference between "while 1:" and "while True:" you are wasting your > time thinking about the savings under all but the most rigorous > circumstances. *Especially* when the 'problem' has been fixed in Python 3. -- Terry Jan Reedy From greno at verizon.net Thu Dec 16 15:40:55 2010 From: greno at verizon.net (Gerry Reno) Date: Thu, 16 Dec 2010 15:40:55 -0500 Subject: Added Python, WSGI to XAMPP In-Reply-To: <08B25692CE8542B386238F7E02D317DD@teddy> References: <4CFA4305.10004@it.uu.se> <4CFD6825.9020200@simplistix.co.uk> <4CFD8B29.3020006@verizon.net><4D014A3D.7020101@verizon.net> <4D06AD69.4030302@simplistix.co.uk><4D06B6D1.6080208@verizon.net> <4D06B671.5020601@simplistix.co.uk><4D06C130.9040506@verizon.net> <08B25692CE8542B386238F7E02D317DD@teddy> Message-ID: <4D0A7957.4000306@verizon.net> On 12/16/2010 04:36 AM, Octavian Rasnita wrote: > From: "Ian Kelly" > > On Mon, Dec 13, 2010 at 5:58 PM, Gerry Reno wrote: > >> The VIEW is the bits that stream out of the webserver back to the users >> browser. >> > Why only to the user's browser? A web app could also offer the results in formats that can be accessed with something else than a browser. The view just offer the results, no matter what way. > > >> The CONTROLLER is the code that gathers all the pieces from >> the model and constructs the python code that is then fed to the engine >> that then creates the view. And just because the controller navigates >> the logic to dynamically contruct/render a view, that does not make 'it' >> the view. >> > >> In traditional MVC, the controller is the part that receives the user >> input, decides how to react to it, and instructs the model to update >> itself accordingly. It is not supposed to be some sort of >> intermediary between the model and the view, as many people seem to >> make it; the view is supposed to gather the data it needs to render >> itself directly from the model. >> > How can the view know what data it should render if the controller doesn't inform it about it? > It is less important if the view uses a smart templating system that doesn't need to ask the controller for data but can access the model directly, but the view or that templating system need to be informed by the controller what data need to ask from the model, so we can say that the intermediary is still the controller. > > And accessing the model directly from the view/templating system is not a good idea, because MVC is also prefered because it decouples the programming code and the web design, and in some cases it can be a security issue if the web designer that might not know programming would be able to change by mistake or with intention the code from the view/templating system that access the model. > > >> In that light, I think that this >> > quote from the Django FAQ is defensible: > > >>> In our interpretation of MVC, the ?view? describes the data that gets presented to the user. It?s not necessarily how the data looks, but which > data is presented. The view describes which data you see, not how you see it. It?s a subtle distinction. >>> > But if the view doesn't decide how the data looks, who decide it? :-) > > >> Traditionally, the view would describe both of these things, but since >> "how you see it" is ultimately decided by the user's browser, they are >> fundamentally separated in the context of the web. The Django >> template-view split is in recognition of this fact. >> > The same data can have any format that's not decided by the user browser. For example it can be displayed in .csv format, or .xls, or .xlsx, or .pdf, or .html, or it can be submitted by email, or sent to Twitter or another web site... > > > >> As for where the controller went, there are basically two decisions >> that need to be made when input is received: how to update the model >> as a result, and what data should be displayed next. The former >> decision belongs to the controller, the latter to the view. >> > The update of the model depends on the model and the display of results depends on the view. But the decision is controlled by the... controller. That's why it has that name, because it controls these things. > Of course, the frontiers between the M and V and C might be subtle in some cases, but it is a good idea to push as much logic to the base. It is not a good idea to make the controller do the job of the model and imply in the business logic or make the view do the job of the controller and do something else than just present the data it receives. > > >> But in a >> web app, these two things tend to be highly correlated, and there >> seems to be little reason to separate them out into distinct >> components. This part then is both controller and view, and which >> word we use for it is not terribly important. >> > Yes, but in that case such a program wouldn't use the MVC model. And as I exemplified above, there are reasons why the view should only present the data it receives and don't access the model directly. Some web developers aren't even alowed to offer the ORM objects to the templates, although the coding would be much easier that way, but need to generate other objects in the controller that don't allow the web designers to change some things in the templates and access more data from the database than it is needed. > > >> For these reasons, I find that in practice traditional MVC does not >> lend itself well to the HTTP request/response cycle, where the "view" >> as you define it has no access to the model and lacks any continuity >> whatsoever from one request to the next; but the Django MTV approach >> works just fine once you're willing to accept that it's not the same >> thing. >> >> Cheers, >> > Ian > > There is no "traditional MVC". There is just MVC or not MVC. > The view shouldn't have any kind of continuity. The view should just present the data. HTTP is a stateless protocol and the controller that handles the requests, does URL dispatching, uses cookies or URL-based ways for maintaining that continuity, not the view. > > The so called "non-traditional" MVC idea appeared because many web apps use a lot of Javascript these days, and because of this thing Javascript gained a much bigger importance, and the Javascript programmers would like to happen everything in the view if possible because they don't like to depend so much on the server-side code. > > Octavian > > > Javascript is like Ajax only it is client-side. Javascript acts as Controller and does mini-MVC based on bits of 'local' Model and sometimes uses Ajax in the background to perform other mini-MVC transactions back to the server to retrieve data or View parts. All of this, webapp, Ajax, Javascript is doing MVC only at different levels and scopes. -Gerry From ethan at stoneleaf.us Thu Dec 16 15:58:36 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 16 Dec 2010 12:58:36 -0800 Subject: while True or while 1 In-Reply-To: <87d3p1bgzr.fsf@gmail.com> References: <4D051506.2060403@holdenweb.com> <87d3p1bgzr.fsf@gmail.com> Message-ID: <4D0A7D7C.2010006@stoneleaf.us> Arnaud Delobelle wrote: > Ethan Furman writes: > >> ...I timed exec vs function, and found the function style to be about >> 200% faster... > > So it finished before it started? Hmmm.... Let me check my calculator... . . . Ah! Okay, that was 200x faster. :) I think -- it was a few months ago now, and my numbers might be off a bit, but I was definitely impressed with A) how much faster the function style was, and B), how very little time it saved me. ~Ethan~ From arnodel at gmail.com Thu Dec 16 16:15:28 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Thu, 16 Dec 2010 21:15:28 +0000 Subject: string identity and comparison References: Message-ID: <878vzpberz.fsf@gmail.com> Jean-Michel Pichavant writes: > Fellows, > > I'd like to illutrate the fact that comparing strings using identity > is, most of the time, a bad idea. However I'm searching a short > example of code that yields 2 differents object for the same string > content. > > id('foo') > 3082385472L > id('foo') > 3082385472L > > Anyone has that kind of code ? > > JM Have you tried this? >>> id("foo") 3078219968L >>> id("bar") 3078219968L >>> And this? >>> id("foo") 3077306560L >>> n = 42 >>> id("foo") 3077306720L And this? >>> "a"*2 is "a"*2 True >>> "a"*30 is "a"*30 False >>> n = 2 >>> "a"*n is "a"*n False -- Arnaud From shearichard at gmail.com Thu Dec 16 16:16:41 2010 From: shearichard at gmail.com (shearichard) Date: Thu, 16 Dec 2010 13:16:41 -0800 (PST) Subject: pudb on windows (dependent upon unix only termios ?) Message-ID: <0ea7ba67-a410-4f59-bc2c-f80a03b7fab5@21g2000prv.googlegroups.com> Hi - I was just trying to install the Python debugger pudb (http:// pypi.python.org/pypi/pudb) and easy install fell over saying it couldn't find a module termios. It turns out termios is only for Unix (http://docs.python.org/library/ termios.html). Does anyone know of way around this ? Is there an equivalent to termios which would run on windows and which could be hacked into pudb ? Alternatively suggestions for a pudb workalike ? (I like the console/ keyboard centric aspect of pudb). Thanks Richard. From stefan_ml at behnel.de Thu Dec 16 16:45:14 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 16 Dec 2010 22:45:14 +0100 Subject: Is text processing with dicts a good use case for Python cross-compilers like Cython/Pyrex or ShedSkin? In-Reply-To: <1292529793.31067.1410717477@webmail.messagingengine.com> References: <1292529793.31067.1410717477@webmail.messagingengine.com> Message-ID: python at bdurham.com, 16.12.2010 21:03: > Is text processing with dicts a good use case for Python > cross-compilers like Cython/Pyrex or ShedSkin? (I've read the > cross compiler claims about massive increases in pure numeric > performance). Cython is generally a good choice for string processing, simply because it can drop a lot of code into plain C, such as character iteration and comparison. Depending on what kind of operations you do, you can get speed-ups of 100x or more for that. http://docs.cython.org/src/tutorial/strings.html However, when it comes to dict lookups, it uses CPython's own dicts which are heavily optimised for string lookups already. So the speedup in that area will likely stay below 30%. Similarly, encoding and decoding use Python's codecs, so don't expect a major difference there. > I have 3 use cases I'm considering for Python-to-C++ > cross-compilers for generating 32-bit Python extension modules > for Python 2.7 for Windows. > > 1. Parsing UTF-8 files (basic Python with lots of string > processing and dict lookups) "Parsing" sounds like something that could easily benefit from Cython compilation. > 2. Generating UTF-8 files from nested list/dict structures That should be much faster in Cython, too, simply because iteration on builtin types is much faster than in Python. > 3. Parsing large ASCII "CSV-like" files and using dict's to > calculate simple statistics like running totals, min, max, etc. Again, parsing will be much faster, especially when reading from raw C files (which would also enable freeing the GIL, in case you want to use multi-threading). The rest may not win that much. A nice feature of Cython is that you do not have to go low-level right away. You can use all the niceness of Python, and only push the code closer to C level where your benchmarks point you. And if you really have to go all the way down to C, it's just a declaration away. > Are any of these text processing scenarios good use cases for > tools like Cython, Pyrex, or ShedSkin? Are any of these > specifically bad use cases for these tools? Pyrex isn't worth trying here, simply because you'd have to invest a lot more work to make it as fast as what Cython gives you anyway. ShedSkin may be worth a try, depending on how well you get your ShedSkin module integrated with CPython. (It seems that it has support for building extension modules by now, but I have no idea how well that is fleshed out). > We've tried Psyco and it has sped up some of our parsing > utilities by 200%. But Psyco doesn't support Python 2.7 yet and > we're committed to using Python 2.7 moving forward. If 3x is not enough for you, I strongly suggest you try Cython. The C code that it generates compiles nicely in all major Python versions, currently from 2.3 to 3.2. Stefan From gordon at panix.com Thu Dec 16 16:49:07 2010 From: gordon at panix.com (John Gordon) Date: Thu, 16 Dec 2010 21:49:07 +0000 (UTC) Subject: If/then style question Message-ID: (This is mostly a style question, and perhaps one that has already been discussed elsewhere. If so, a pointer to that discussion will be appreciated!) When I started learning Python, I wrote a lot of methods that looked like this: def myMethod(self, arg1, arg2): if some_good_condition: if some_other_good_condition: if yet_another_good_condition: do_some_useful_stuff() exitCode = good1 else: exitCode = bad3 else: exitCode = bad2 else: exitCode = bad1 return exitCode But lately I've been preferring this style: def myMethod(self, arg1, arg2): if some_bad_condition: return bad1 elif some_other_bad_condition: return bad2 elif yet_another_bad_condition: return bad3 do_some_useful_stuff() return good1 I like this style more, mostly because it eliminates a lot of indentation. However I recall one of my college CS courses stating that "one entry, one exit" was a good way to write code, and this style has lots of exits. Are there any concrete advantages of one style over the other? Thanks. -- 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 usernet at ilthio.net Thu Dec 16 17:05:52 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 16 Dec 2010 22:05:52 +0000 (UTC) Subject: If/then style question References: Message-ID: On 2010-12-16, John Gordon wrote: > I like this style more, mostly because it eliminates a lot of indentation. > > However I recall one of my college CS courses stating that "one entry, > one exit" was a good way to write code, and this style has lots of exits. So, take the good intentation from one and the single exit from the other: def myMethod(self, arg1, arg2): if some_bad_condition: exitCode = bad1 elif some_other_bad_condition: exitCode = bad2 elif yet_another_bad_condition: exitCode = bad3 else: exitCode = do_some_useful_stuff() # possible common cleanup code here return exitCode Or, raise an exception on bad condtions rather then passing an error code. From ethan at stoneleaf.us Thu Dec 16 17:11:51 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 16 Dec 2010 14:11:51 -0800 Subject: If/then style question In-Reply-To: References: Message-ID: <4D0A8EA7.7080104@stoneleaf.us> John Gordon wrote: > (This is mostly a style question, and perhaps one that has already been > discussed elsewhere. If so, a pointer to that discussion will be > appreciated!) > > When I started learning Python, I wrote a lot of methods that looked like > this: > > > def myMethod(self, arg1, arg2): > if some_good_condition: > if some_other_good_condition: > if yet_another_good_condition: > do_some_useful_stuff() > exitCode = good1 > else: > exitCode = bad3 > else: > exitCode = bad2 > else: > exitCode = bad1 > return exitCode > > > But lately I've been preferring this style: > > def myMethod(self, arg1, arg2): > if some_bad_condition: > return bad1 > elif some_other_bad_condition: > return bad2 > elif yet_another_bad_condition: > return bad3 > do_some_useful_stuff() > return good1 > > I like this style more, mostly because it eliminates a lot of indentation. As far as if/else goes, I prefer the second style also. As far as returning bad codes, you are better off raising exceptions: def myMethod(self, arg1, arg2): if some_bad_condition: raise Bad1() elif some_other_bad_condition: raise Bad2() elif yet_another_bad_condition: raise Bad3() do_some_useful_stuff # no need to return 'good' code -- success means no problems ~Ethan~ From invalid at invalid.invalid Thu Dec 16 17:13:40 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 16 Dec 2010 22:13:40 +0000 (UTC) Subject: If/then style question References: Message-ID: On 2010-12-16, John Gordon wrote: > (This is mostly a style question, and perhaps one that has already been > discussed elsewhere. If so, a pointer to that discussion will be > appreciated!) > > When I started learning Python, I wrote a lot of methods that looked like > this: > > > def myMethod(self, arg1, arg2): > if some_good_condition: > if some_other_good_condition: > if yet_another_good_condition: > do_some_useful_stuff() > exitCode = good1 > else: > exitCode = bad3 > else: > exitCode = bad2 > else: > exitCode = bad1 > return exitCode > > > But lately I've been preferring this style: > > > def myMethod(self, arg1, arg2): > > if some_bad_condition: > return bad1 > > elif some_other_bad_condition: > return bad2 > > elif yet_another_bad_condition: > return bad3 > > do_some_useful_stuff() > return good1 > > I like this style more, mostly because it eliminates a lot of > indentation. There's nothing inherently wrong with indentation, but in this case the latter style is a _lot_ easier to read (and modify without breaking). > However I recall one of my college CS courses stating that "one > entry, one exit" was a good way to write code, and this style has > lots of exits. > > Are there any concrete advantages of one style over the other? I think the check/exit style is far more readable. It can trip you up if there is cleanup stuff that needs to happen before you return from the function. In that case putting the whole function in a try statement and raising exceptions for the "bad conditions" works nicely. Then you get the more readable style of the check/exit style, plus the advantage of a single exit (it's easy to verify visually that all the required cleanup is happening). -- Grant Edwards grant.b.edwards Yow! I want a WESSON OIL at lease!! gmail.com From stefan.sonnenberg at pythonmeister.com Thu Dec 16 17:41:41 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Thu, 16 Dec 2010 23:41:41 +0100 Subject: If/then style question In-Reply-To: References: Message-ID: <4D0A95A5.4070103@pythonmeister.com> Am 16.12.2010 22:49, schrieb John Gordon: > (This is mostly a style question, and perhaps one that has already been > discussed elsewhere. If so, a pointer to that discussion will be > appreciated!) > > When I started learning Python, I wrote a lot of methods that looked like > this: > > > def myMethod(self, arg1, arg2): > > if some_good_condition: > > if some_other_good_condition: > > if yet_another_good_condition: > > do_some_useful_stuff() > exitCode = good1 > > else: > exitCode = bad3 > > else: > exitCode = bad2 > > else: > exitCode = bad1 > > return exitCode > > > But lately I've been preferring this style: > > > def myMethod(self, arg1, arg2): > > if some_bad_condition: > return bad1 > > elif some_other_bad_condition: > return bad2 > > elif yet_another_bad_condition: > return bad3 > else: > do_some_useful_stuff() > return good1 > > I like this style more, mostly because it eliminates a lot of indentation. > > However I recall one of my college CS courses stating that "one entry, > one exit" was a good way to write code, and this style has lots of exits. > > Are there any concrete advantages of one style over the other? > > Thanks. > The advantage in latter case is fewer operations, because you can skip the assignments, and it is more readable. The "one entry, one exit" is an advice. Not a law. Your code is OK. As long as it works ;-) P.S.: Sorry, I could not resist: return bad1 if some_bad_condition else bad2 if some_other_bad_condition else bad3 if yet_another_bad_condition else good1 if do_some_useful_stuff() else good1 Or consider this: return [x for x,y in ((bad1,some_bad_condition),(bad2,some_other_bad_condition),(bad3,yet_another_bad_condition),(good1,do_some_useful_stuff() or True)) if x][0] Neither self explanatory nor readable :-( From ryan at rfk.id.au Thu Dec 16 17:56:37 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Fri, 17 Dec 2010 09:56:37 +1100 Subject: If/then style question In-Reply-To: References: Message-ID: <1292540197.27568.22.camel@durian> On Thu, 2010-12-16 at 21:49 +0000, John Gordon wrote: > (This is mostly a style question, and perhaps one that has already been > discussed elsewhere. If so, a pointer to that discussion will be > appreciated!) > > When I started learning Python, I wrote a lot of methods that looked like > this: > > > def myMethod(self, arg1, arg2): > if some_good_condition: > if some_other_good_condition: > if yet_another_good_condition: > do_some_useful_stuff() > exitCode = good1 > else: > exitCode = bad3 > else: > exitCode = bad2 > else: > exitCode = bad1 > return exitCode > > > But lately I've been preferring this style: > > > def myMethod(self, arg1, arg2): > if some_bad_condition: > return bad1 > elif some_other_bad_condition: > return bad2 > elif yet_another_bad_condition: > return bad3 > do_some_useful_stuff() > return good1 > > I like this style more, mostly because it eliminates a lot of indentation. > > However I recall one of my college CS courses stating that "one entry, > one exit" was a good way to write code, and this style has lots of exits. > > Are there any concrete advantages of one style over the other? "one entry, one exit" has its good points, but it's *way* overquoted and overused. Do you raise any exceptions? Do you call any functions that might raise exceptions? If so, you've got multiple exit points already. I think this style a lot more important in a language like C where you have to be super-careful about cleaning up after yourself. The single exit point makes it easier to verify that all cleanup tasks have been performed. Assuming you're using "with" or "try-finally" then you just don't need such guarantees in python. I'm not a PEP-8 pedant by any means, but I think that the first section of PEP-8 contains the best advice I've ever read about programming language style. In fact, I'm going to quote it right here: A Foolish Consistency is the Hobgoblin of Little Minds ====================================================== One of Guido's key insights is that code is read much more often than it is written. The guidelines provided here are intended to improve the readability of code and make it consistent across the wide spectrum of Python code. As PEP 20 says, "Readability counts". ...snip... But most importantly: know when to be inconsistent -- sometimes the style guide just doesn't apply. When in doubt, use your best judgment. Look at other examples and decide what looks best. And don't hesitate to ask! In your example, the first style is difficult to read wile the second style is easy to read. You don't need any further justification for preferring the latter. Cheers, Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit ryan at rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part URL: From ian.g.kelly at gmail.com Thu Dec 16 18:02:38 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 16 Dec 2010 16:02:38 -0700 Subject: If/then style question In-Reply-To: <4D0A95A5.4070103@pythonmeister.com> References: <4D0A95A5.4070103@pythonmeister.com> Message-ID: On Thu, Dec 16, 2010 at 3:41 PM, Stefan Sonnenberg-Carstens wrote: > return [x for x,y in > ((bad1,some_bad_condition),(bad2,some_other_bad_condition),(bad3,yet_another_bad_condition),(good1,do_some_useful_stuff() > or True)) if x][0] This doesn't work. do_some_usefull_stuff() gets called during the tuple construction regardless of the conditions, not during the list comprehension execution as you would want. Here's my take on an unreadable one-liner: return reduce(lambda x, y: (x or (y[0]() and y[1])), [(some_bad_condition, bad1), (some_other_bad_condition, bad2), (yet_another_bad_condition, bad3), (lambda: (do_some_useful_stuff() or True), good1)], None) This of course assumes that bad1, bad2, and bad3 all evaluate as true. Cheers, Ian From bc at freeuk.com Thu Dec 16 18:34:21 2010 From: bc at freeuk.com (BartC) Date: Thu, 16 Dec 2010 23:34:21 -0000 Subject: while True or while 1 In-Reply-To: References: <4D051506.2060403@holdenweb.com> Message-ID: "Steve Holden" wrote in message news:mailman.54.1292502247.6505.python-list at python.org... > On 12/16/2010 5:44 AM, BartC wrote: >> One these is 30% faster than the other. That's an appreciable >> difference, which you can't really just dismiss. > sholden at lifeboy ~ > $ python -m timeit -- "i = 1" "while True:" " i += 1" " if i == > 1000000: break" > 10 loops, best of 3: 157 msec per loop > $ python -m timeit -- "i = 1" "while 1:" " i += 1" " if i == > 1000000: break" > 10 loops, best of 3: 116 msec per loop I used a single loop counting to 10 million, and the timings were roughly 2.5xx and 1.8xx seconds, on Python 2.5 (1.35 and 1.05 seconds inside a function). In terms of a more realistic function (admittedly still a little contrived, as the loop would be written differently), I tried this: def p2(n): p=1 while True: if n<=p: return p p<<=1 return 0 for i in xrange(1000000): x=p2(i) p2() calculates the smallest power of 2 >= it's operand. Using while True as shown, it took 3.4 seconds. Using While 1, it took 2.6 seconds (Python 2.5). -- Bartc From steve+comp.lang.python at pearwood.info Thu Dec 16 18:51:04 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Dec 2010 23:51:04 GMT Subject: If/then style question References: Message-ID: <4d0aa5e7$0$29997$c3e8da3$5496439d@news.astraweb.com> On Thu, 16 Dec 2010 21:49:07 +0000, John Gordon wrote: > (This is mostly a style question, and perhaps one that has already been > discussed elsewhere. If so, a pointer to that discussion will be > appreciated!) > > When I started learning Python, I wrote a lot of methods that looked > like this: > > def myMethod(self, arg1, arg2): > if some_good_condition: > if some_other_good_condition: > if yet_another_good_condition: > do_some_useful_stuff() > exitCode = good1 > else: > exitCode = bad3 > else: > exitCode = bad2 > else: > exitCode = bad1 > return exitCode It doesn't look like you were learning Python. It looks like you were learning C with Python syntax :( The above would be more Pythonically written as: def myMethod(self, arg1, arg2): if not some_good_condition: raise SomeException("message") if not some_other_good_condition: raise SomeOtherException("another message") if yet_another_good_condition: do_some_useful_stuff() else: raise SomeThirdException("whatever") using exceptions to communicate errors out-of-band. Since no return result is needed, no explicit return is used and the method is the closest thing to a procedure that Python can offer. The problem with in-band transmission of errors is that they invite the anti-pattern of this: result = obj.myMethod(arg1, arg2) if result == good1: do_something_good() elif result == bad1: handle_error1() elif result == bad2: handle_error2() elif result == bad3(): handle_error3() else: print "This can't ever happen, but if it does..." which all too often becomes: result = obj.myMethod(arg1, arg2) if result == good1: do_something_good() else: # assume result is bad1 handle_error1() or even: who_cares = obj.myMethod(arg1, arg2) do_something_good() > But lately I've been preferring this style: > > def myMethod(self, arg1, arg2): > if some_bad_condition: > return bad1 > elif some_other_bad_condition: > return bad2 > elif yet_another_bad_condition: > return bad3 > do_some_useful_stuff() > return good1 > > I like this style more, mostly because it eliminates a lot of > indentation. Well, that's better, but still more like C rather than Python. Avoid the anti-pattern of returning in-band error codes. In some languages, either exceptions aren't available at all, or the overhead of them is so great that for performance you have to avoid them, but Python is not one of those languages. In Python, exceptions are *the* primary way of communicating exceptional cases such as (but not limited to) errors. I can only think of two, er, exceptions to this rule: str.find() and some of the regular expression methods. > However I recall one of my college CS courses stating that "one entry, > one exit" was a good way to write code, and this style has lots of > exits. Functions always have one entry. The only way to have multiple entry points is if the language allows you to GOTO into the middle of a function, and Python sensibly does not allow this. The "one entry, one exit" rule comes from the days when people would routinely write spaghetti code, jumping into and out of blocks of code without using functions at all. If "one entry" is pointless (all functions have one entry!) then "one exit" is actively harmful. It leads to adding unnecessary complexity to functions, purely to meet the requirements of a rule invented to discourage spaghetti code. This hides bugs and increases the maintenance burden. Don't get me wrong... spaghetti code is *bad*. But there are other ways of writing bad code too, and hanging around inside a function long after you've finished is also bad: def function(arg): done = False do_something() if some_condition: result = "finished" done = True if not done: do_something_else() if another_condition: result = "now we're finished" done = True if not done: do_yet_more_work() if third_condition: result = "finished this time for sure" done = True if not done: for i in range(1000000): if not done: do_something_small() if yet_another_condition: result = "finally done!" done = True return result It's far more complicated than it need be, and does *lots* of unnecessary work. This can be written more simply and efficiently as: def function(arg): do_something() if some_condition: return "finished" do_something_else() if another_condition: return "now we're finished" do_yet_more_work() if third_condition: return "finished this time for sure" for i in range(1000000): do_something_small() if yet_another_condition: return "finally done!" Over 40% of the code in the first version is scaffolding to support skipping the rest of the function body once you have a result. It needlessly performs all one million iterations of the loop, even if the final result was calculated on the first iteration (loops also should have "one entry, one exit"). There's not one good thing that can be said about it except that it has "one exit", and that is only a good thing compared to the Bad Old Days of writing spaghetti code with GOTO. -- Steven From ian.g.kelly at gmail.com Thu Dec 16 19:00:39 2010 From: ian.g.kelly at gmail.com (Ian) Date: Thu, 16 Dec 2010 16:00:39 -0800 (PST) Subject: while True or while 1 References: <4D051506.2060403@holdenweb.com> Message-ID: On Dec 16, 4:34?pm, "BartC" wrote: > def p2(n): > ? p=1 > ?whileTrue: > ? ? if n<=p: return p > ? ? p<<=1 > ? return 0 > > for i in xrange(1000000): > ? x=p2(i) > > p2() calculates the smallest power of 2 >= it's operand. def p2(n): return 1 << n.bit_length() From wuwei23 at gmail.com Thu Dec 16 19:18:07 2010 From: wuwei23 at gmail.com (alex23) Date: Thu, 16 Dec 2010 16:18:07 -0800 (PST) Subject: If/then style question References: Message-ID: <32e2b64f-c400-4fe5-b1ae-f3d75329291c@l34g2000pro.googlegroups.com> John Gordon wrote: > But lately I've been preferring this style: > > ? def myMethod(self, arg1, arg2): > > ? ? if some_bad_condition: > ? ? ? return bad1 > > ? ? elif some_other_bad_condition: > ? ? ? return bad2 > > ? ? elif yet_another_bad_condition: > ? ? ? return bad3 > > ? ? do_some_useful_stuff() > ? ? return good1 For more than 2 tests in a function like this, I'd probably use dictionary dispatch: def myMethod(self, arg1, arg2): branches = dict( cond1: bad1, cond2: bad2, cond3: bad3 ) cond = if cond == cond_good: do_some_useful_stuff() exitCode = good1 else: exitCode = branches[cond] return exitCode From steve+comp.lang.python at pearwood.info Thu Dec 16 19:33:32 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Dec 2010 00:33:32 GMT Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4d0aafdb$0$29997$c3e8da3$5496439d@news.astraweb.com> On Thu, 16 Dec 2010 10:39:34 -0600, Robert Kern wrote: > On 12/16/10 10:23 AM, Steven D'Aprano wrote: >> On Thu, 16 Dec 2010 07:29:25 -0800, Ethan Furman wrote: >> >>> Tim Arnold wrote: >>>> "Ethan Furman" wrote in message >>>> news:mailman.4.1292379995.6505.python-list at python.org... >>>>> kj wrote: >>>>>> The one thing I don't like about this strategy is that the >>>>>> tracebacks of exceptions raised during the execution of __pre_spam >>>>>> include one unwanted stack level (namely, the one corresponding to >>>>>> __pre_spam itself). >> [...] >>> A decorator was one of the items kj explicity didn't want. Also, >>> while it would have a shallower traceback for exceptions raised during >>> the __pre_spam portion, any exceptions raised during spam itself would >>> then be one level deeper than desired... while that could be masked by >>> catching and (re-?)raising the exception in the decorator, Steven had >>> a very good point about why that is a bad idea -- namely, tracebacks >>> shouldn't lie about where the error is. >> >> True, very true... but many hours later, it suddenly hit me that what >> KJ was asking for wasn't *necessarily* such a bad idea. My thought is, >> suppose you have a function spam(x) which raises an exception. If it's >> a *bug*, then absolutely you need to see exactly where the error >> occurred, without the traceback being mangled or changed in any way. >> >> But what if the exception is deliberate, part of the function's >> documented behaviour? Then you might want the exception to appear to >> come from the function spam even if it was actually generated inside >> some private sub-routine. > > Obfuscating the location that an exception gets raised prevents a lot of > debugging (by inspection or by pdb), even if the exception is > deliberately raised with an informative error message. Not least, the > code that decides to raise that exception may be buggy. But even if the > actual error is outside of the function (e.g. the caller is passing bad > arguments), you want to at least see what tests the __pre_spam function > is doing in order to decide to raise that exception. And how do you think you see that from the traceback? The traceback prints the line which actually raises the exception (and sometimes not even that!), which is likely to be a raise statement: >>> import example >>> example.func(42) Traceback (most recent call last): File "", line 1, in File "example.py", line 3, in func raise ValueError('bad value for x') ValueError: bad value for x The actual test is: def func(x): if x > 10 and x%2 == 0: raise ValueError('bad value for x') but you can't get that information from the traceback. Python's exception system has to handle two different situations: buggy code, and bad data. It's not even clear whether there is a general distinction to be made between the two, but even if there's not a general distinction, there's certainly a distinction which we can *sometimes* make. If a function contains a bug, we need all the information we can get, including the exact line that causes the fault. But if the function deliberately raises an exception due to bad input, we don't need any information regarding the internals of the function (assuming that the exception is sufficiently detailed, a big assumption I grant you!). If I re-wrote the above func() like this: def func(x): if !(x <= 10): if x%2 != 0: pass else: raise ValueError('bad value for x') return I would have got the same traceback, except the location of the exception would have been different (line 6, in a nested if-block). To the caller, whether I had written the first version of func() or the second is irrelevant. If I had passed the input validation off to a second function, that too would be irrelevant. I don't expect Python to magically know whether an exception is a bug or not, but there's something to be said for the ability to turn Python functions into black boxes with their internals invisible, like C functions already are. If (say) math.atan2(y, x) raises an exception, you have no way of knowing whether atan2 is a single monolithic function, or whether it is split into multiple pieces. The location of the exception is invisible to the caller: all you can see is that atan2 raised an exception. > Tracebacks are inherently over-verbose. This is necessarily true because > no algorithm (or clever programmer) can know all the pieces of > information that the person debugging may want to know a priori. Most > customizations of tracebacks *add* more verbosity rather than reduce it. > Removing one stack level from the traceback barely makes the traceback > more readable and removes some of the most relevant information. Right. But I have thought of a clever trick to get the result KJ was asking for, with the minimum of boilerplate code. Instead of this: def _pre_spam(args): if condition(args): raise SomeException("message") if another_condition(args): raise AnotherException("message") if third_condition(args): raise ThirdException("message") def spam(args): _pre_spam(args) do_useful_work() you can return the exceptions instead of raising them (exceptions are just objects, like everything else!), and then add one small piece of boilerplate to the spam() function: def _pre_spam(args): if condition(args): return SomeException("message") if another_condition(args): return AnotherException("message") if third_condition(args): return ThirdException("message") def spam(args): exc = _pre_spam(args) if exc: raise exc do_useful_work() -- Steven From wuwei23 at gmail.com Thu Dec 16 19:56:12 2010 From: wuwei23 at gmail.com (alex23) Date: Thu, 16 Dec 2010 16:56:12 -0800 (PST) Subject: string identity and comparison References: Message-ID: <8fcdad15-e378-4bad-848c-75f0bac8ca49@a28g2000prb.googlegroups.com> On Dec 16, 9:55?pm, Jean-Michel Pichavant wrote: > I'd like to illutrate the fact that comparing strings using identity is, > most of the time, a bad idea. However I'm searching a short example of > code that yields 2 differents object for the same string content. > > Anyone has that kind of code ? It's quite obvious when they come from different contexts: >>> def f(): return 'some string' ... >>> def g(): return 'some string' ... >>> f() == g() True >>> f() is g() False From steve+comp.lang.python at pearwood.info Thu Dec 16 20:01:19 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Dec 2010 01:01:19 GMT Subject: while True or while 1 References: <4D051506.2060403@holdenweb.com> Message-ID: <4d0ab65f$0$29997$c3e8da3$5496439d@news.astraweb.com> On Thu, 16 Dec 2010 23:34:21 +0000, BartC wrote: > In terms of a more realistic function (admittedly still a little > contrived, as the loop would be written differently), I tried this: > > def p2(n): > p=1 > while True: > if n<=p: return p > p<<=1 > return 0 > > for i in xrange(1000000): > x=p2(i) > > p2() calculates the smallest power of 2 >= it's operand. > > Using while True as shown, it took 3.4 seconds. Using While 1, it took > 2.6 seconds (Python 2.5). Right. And a saving of 0.8 microseconds per iteration is a micro- optimization which is likely to be invisible in any real situation. I mean, yes, you saved almost an entire second. Wow. Save another 179 of them and you'll almost have enough time to make yourself a coffee. Bart, we get it. Nobody denies that the optimization is real, only that it is generally meaningful. Who cares whether it takes 2 seconds or 4 seconds to generate one million results if the rest of the application takes 3 minutes to run? *If* your application is such that saving 0.8 microseconds per iteration actually is useful, AND your loop has to be written as a while True loop, then this *may* be a useful micro-optimization to save 0.8 microseconds per iteration. That's a vanishingly tiny proportion of all code written. If your code happens to meet those conditions, then by all means use "while 1". Or move to Python 3, where "while True" has the same optimization performed. But in general, such micro-optimizations are not terribly useful. If you shave off 1 second off a program that runs in 3 seconds, chances are nobody is even going to notice. Two seconds or three, who cares? Either way, it's too short to do anything else, and not long enough to matter. If you shave off an hour off a program that takes 20 hours, who is going to care? But so long as it doesn't introduce bugs, or make maintenance harder, or add complexity, such micro-optimizations don't harm either. -- Steven From tmohr at s.netic.de Thu Dec 16 20:07:07 2010 From: tmohr at s.netic.de (Torsten Mohr) Date: Fri, 17 Dec 2010 02:07:07 +0100 Subject: Read / Write OpenOffice SpreadSheet ? Message-ID: Hi, i search for a possibility to access OpenOffoce SpreadSheets from Python with a reasonably new version of Python. Can anybody point me to a package that can do this? Best regards, Torsten. From emile at fenx.com Thu Dec 16 20:21:31 2010 From: emile at fenx.com (Emile van Sebille) Date: Thu, 16 Dec 2010 17:21:31 -0800 Subject: Read / Write OpenOffice SpreadSheet ? In-Reply-To: References: Message-ID: On 12/16/2010 5:07 PM Torsten Mohr said... > Hi, > > i search for a possibility to access OpenOffoce SpreadSheets from Python > with a reasonably new version of Python. > > Can anybody point me to a package that can do this? > > If you're open to 'saving as xls' then xlrd/xlwt works well. Otherwise, when I last checked in on this about 18 months ago, it appeared that python support in OO never quite got the traction I hoped it might... Emile From zapwireDASHgroups at yahoo.com Thu Dec 16 20:39:30 2010 From: zapwireDASHgroups at yahoo.com (Joel Koltner) Date: Thu, 16 Dec 2010 17:39:30 -0800 Subject: If/then style question References: <4d0aa5e7$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: "Steven D'Aprano" wrote in message news:4d0aa5e7$0$29997$c3e8da3$5496439d at news.astraweb.com... > It doesn't look like you were learning Python. It looks like you were > learning C with Python syntax :( True, although in many cases one has to interface to legacy C code where it'd be rather more code to start throwing exceptions left or right... since sooner or later those exceptions would still have to be turned into a single status (error) code! > which all too often becomes: > > result = obj.myMethod(arg1, arg2) > if result == good1: > do_something_good() > else: # assume result is bad1 > handle_error1() This really isn't a bad way to go *if you weren't planning on spending the time to really, fully flesh out the individual error cases anyway.* I see this pretty often: Peple put in sophisticated exception handling infrastructure, but when an error actually occurs, all six dozen cases handled individually end up just printing some generic message and exiting the program anyway. In an ideal world all the error cases would do something "smart," but pragmatically one has to balance how likely an error is to occur and how much damage it does with how much time you want to spend making a really smart error handler. > or even: > > who_cares = obj.myMethod(arg1, arg2) > do_something_good() Even this can be OK if do_something_good() behaves in a relatively benign fashion when feed gibberish. I mean, how many people actually check to see whether or not printf() succeeded, you know? But I would agree that often you see... who_care = obj.myMethod(arg1, arg2) do_something_really_dangerous_that_depends_on_the_success_of_myMethod() :-) > Well, that's better, but still more like C rather than Python. Avoid the > anti-pattern of returning in-band error codes. The main sticky point here is that what's an "error" vs. a "warning" or "note" (but not "success") is often rather a grey area. E.g., Pyhton's open() raises an IOError is the file can't be opened, but in my mind that's still a common enough/expected occurrence that elevating its behavior to an exception is more a judgement call than something everyone would agree on. (On the other hand, trying to read or write to an un-opened file is now clearly in the realm of an error and deserves an exception.) ---Joel From usernet at ilthio.net Thu Dec 16 20:53:20 2010 From: usernet at ilthio.net (Tim Harig) Date: Fri, 17 Dec 2010 01:53:20 +0000 (UTC) Subject: Read / Write OpenOffice SpreadSheet ? References: Message-ID: On 2010-12-17, Torsten Mohr wrote: > i search for a possibility to access OpenOffoce SpreadSheets from Python > with a reasonably new version of Python. > > Can anybody point me to a package that can do this? There is no package needed to read or write the new open document files. The files are merely a jar archive containing XML files. You can open and update them using jar as a subprocess and manipulate the XML files using your favorite XML libraries DOM/SAX/XPath/Etree/etc. If that doesn't suit you, you can manipulate them using OO.org through its UNO interface; but, I find that much more involved then simply accessing the files directly. From python.list at tim.thechases.com Thu Dec 16 21:08:27 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 16 Dec 2010 20:08:27 -0600 Subject: Read / Write OpenOffice SpreadSheet ? In-Reply-To: References: Message-ID: <4D0AC61B.6040903@tim.thechases.com> On 12/16/2010 07:53 PM, Tim Harig wrote: > On 2010-12-17, Torsten Mohr wrote: >> i search for a possibility to access OpenOffoce SpreadSheets from Python >> with a reasonably new version of Python. >> >> Can anybody point me to a package that can do this? > > There is no package needed to read or write the new open document files. > The files are merely a jar archive containing XML files. You can open > and update them using jar as a subprocess and manipulate the XML files > using your favorite XML libraries DOM/SAX/XPath/Etree/etc. To make that even easier (no need for a subprocess launching a JAR tool), JAR files are just ZIP files (IIRC, they may have some particularly-named files for metadata purposes, but it's all just a big zip-blob), so you can use Python's native zipfile module to crack into it. Then, as TimH suggests, wander around in the XML (and other files) inside. -tkc From joychenqi at qq.com Thu Dec 16 21:46:54 2010 From: joychenqi at qq.com (joymanchen) Date: Fri, 17 Dec 2010 10:46:54 +0800 Subject: Read / Write OpenOffice SpreadSheet ? In-Reply-To: References: Message-ID: "Torsten Mohr" ???? news:ieed6o$iqd$1 at news.LF.net... Hi, i search for a possibility to access OpenOffoce SpreadSheets from Python with a reasonably new version of Python. Can anybody point me to a package that can do this? Best regards, Torsten. --- news://freenews.netfront.net/ - complaints: news at netfront.net --- From cronoklee at gmail.com Thu Dec 16 22:42:48 2010 From: cronoklee at gmail.com (cronoklee) Date: Thu, 16 Dec 2010 19:42:48 -0800 (PST) Subject: Newbie question about importing modules. Message-ID: Hi I'm starting my first python project but I'm having trouble getting off the ground. I've read all I can find about relative and absolute import paths but it's just not making sense to me... There seems to be around ten different ways to import a script. I need my project to be portable so I can copy the whole folder to run on any PC that has python installed. Is it always possible to simply include modules in the project directory and reference them without installing into the main python directory? I've managed this with small classes through trial and error but when I try it with anything larger (like PIL module for example) I get errors. Do I need to actually install anything or is it enough just to include the relevant scripts? All the modules I've found come with tonnes of files and subdirectories. Do I need all these files or should I just choose the scripts/folders I need? Thanks, cronoklee From pavlovevidence at gmail.com Thu Dec 16 23:32:29 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 16 Dec 2010 20:32:29 -0800 (PST) Subject: If/then style question References: Message-ID: On Dec 16, 2:56?pm, Ryan Kelly wrote: > On Thu, 2010-12-16 at 21:49 +0000, John Gordon wrote: > > (This is mostly a style question, and perhaps one that has already been > > discussed elsewhere. ?If so, a pointer to that discussion will be > > appreciated!) > > > When I started learning Python, I wrote a lot of methods that looked like > > this: > > > ? def myMethod(self, arg1, arg2): > > ? ? if some_good_condition: > > ? ? ? if some_other_good_condition: > > ? ? ? ? if yet_another_good_condition: > > ? ? ? ? ? do_some_useful_stuff() > > ? ? ? ? ? exitCode = good1 > > ? ? ? ? else: > > ? ? ? ? ? exitCode = bad3 > > ? ? ? else: > > ? ? ? ? exitCode = bad2 > > ? ? else: > > ? ? ? exitCode = bad1 > > ? ? return exitCode > > > But lately I've been preferring this style: > > > ? def myMethod(self, arg1, arg2): > > ? ? if some_bad_condition: > > ? ? ? return bad1 > > ? ? elif some_other_bad_condition: > > ? ? ? return bad2 > > ? ? elif yet_another_bad_condition: > > ? ? ? return bad3 > > ? ? do_some_useful_stuff() > > ? ? return good1 > > > I like this style more, mostly because it eliminates a lot of indentation. > > > However I recall one of my college CS courses stating that "one entry, > > one exit" was a good way to write code, and this style has lots of exits. > > > Are there any concrete advantages of one style over the other? > > "one entry, one exit" has its good points, but it's *way* overquoted and > overused. > > Do you raise any exceptions? Do you call any functions that might raise > exceptions? ?If so, you've got multiple exit points already. > > I think this style a lot more important in a language like C where you > have to be super-careful about cleaning up after yourself. ?The single > exit point makes it easier to verify that all cleanup tasks have been > performed. ?Assuming you're using "with" or "try-finally" then you just > don't need such guarantees in python. Even without the cleanup issue, sometimes you want to edit a function to affect all return values somehow. If you have a single exit point you just make the change there; if you have mulitple you have to hunt them down and change all of them--if you remember to. I just got bit by that one. It's a trade-off. Readability and/or conciseness versus error robustness. I tend to go for the former but mileage varies. Carl Banks From jonyzhu at 163.com Thu Dec 16 23:36:01 2010 From: jonyzhu at 163.com (Jony Zhu) Date: Fri, 17 Dec 2010 12:36:01 +0800 Subject: Newbie question about importing modules. In-Reply-To: References: Message-ID: Hi, cronoklee maybe you should check every module directory you want to import to see if there is a __init__.py in it? missing a __init__.py file would cause error when you try to import the directory as a module. ? Fri, 17 Dec 2010 11:42:48 +0800?cronoklee ??: > Hi > I'm starting my first python project but I'm having trouble getting > off the ground. > I've read all I can find about relative and absolute import paths but > it's just not making sense to me... There seems to be around ten > different ways to import a script. > > I need my project to be portable so I can copy the whole folder to run > on any PC that has python installed. Is it always possible to simply > include modules in the project directory and reference them without > installing into the main python directory? I've managed this with > small classes through trial and error but when I try it with anything > larger (like PIL module for example) I get errors. Do I need to > actually install anything or is it enough just to include the relevant > scripts? > > All the modules I've found come with tonnes of files and > subdirectories. Do I need all these files or should I just choose the > scripts/folders I need? > > Thanks, > cronoklee -- ?? Opera ????????????: http://www.opera.com/mail/ From steve at holdenweb.com Fri Dec 17 00:19:42 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 17 Dec 2010 00:19:42 -0500 Subject: If/then style question In-Reply-To: References: Message-ID: On 12/16/2010 11:32 PM, Carl Banks wrote: > On Dec 16, 2:56 pm, Ryan Kelly wrote: >> On Thu, 2010-12-16 at 21:49 +0000, John Gordon wrote: >>> (This is mostly a style question, and perhaps one that has already been >>> discussed elsewhere. If so, a pointer to that discussion will be >>> appreciated!) >> >>> When I started learning Python, I wrote a lot of methods that looked like >>> this: >> >>> def myMethod(self, arg1, arg2): >>> if some_good_condition: >>> if some_other_good_condition: >>> if yet_another_good_condition: >>> do_some_useful_stuff() >>> exitCode = good1 >>> else: >>> exitCode = bad3 >>> else: >>> exitCode = bad2 >>> else: >>> exitCode = bad1 >>> return exitCode >> >>> But lately I've been preferring this style: >> >>> def myMethod(self, arg1, arg2): >>> if some_bad_condition: >>> return bad1 >>> elif some_other_bad_condition: >>> return bad2 >>> elif yet_another_bad_condition: >>> return bad3 >>> do_some_useful_stuff() >>> return good1 >> >>> I like this style more, mostly because it eliminates a lot of indentation. >> >>> However I recall one of my college CS courses stating that "one entry, >>> one exit" was a good way to write code, and this style has lots of exits. >> >>> Are there any concrete advantages of one style over the other? >> >> "one entry, one exit" has its good points, but it's *way* overquoted and >> overused. >> >> Do you raise any exceptions? Do you call any functions that might raise >> exceptions? If so, you've got multiple exit points already. >> >> I think this style a lot more important in a language like C where you >> have to be super-careful about cleaning up after yourself. The single >> exit point makes it easier to verify that all cleanup tasks have been >> performed. Assuming you're using "with" or "try-finally" then you just >> don't need such guarantees in python. > > Even without the cleanup issue, sometimes you want to edit a function > to affect all return values somehow. If you have a single exit point > you just make the change there; if you have mulitple you have to hunt > them down and change all of them--if you remember to. I just got bit > by that one. > > It's a trade-off. Readability and/or conciseness versus error > robustness. I tend to go for the former but mileage varies. > Heaven forfend you should just wrap the existing function inside another one which takes its name, if all its returns need to be altered. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From pavlovevidence at gmail.com Fri Dec 17 00:25:21 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 16 Dec 2010 21:25:21 -0800 (PST) Subject: How to pop the interpreter's stack? References: <4d08956e$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Dec 15, 2:16?am, Steven D'Aprano wrote: > On Tue, 14 Dec 2010 21:14:35 +0000, kj wrote: > > Consider this code: > > > def spam(*args, **kwargs): > > ? ? args, kwargs = __pre_spam(*args, **kwargs) > > > ? ? # args & kwargs are OK: proceed > > ? ? # ... > > > def __pre_spam(*args, **kwargs): > > ? ? # validate args & kwargs; > > ? ? # return canonicalized versions of args & kwargs; # on failure, > > ? ? raise some *informative* exception # ... > > ? ? return canonicalized_args, canonicalized_kwargs > > Double leading underscores don't have any special meaning in the global > scope. Save yourself an underscore and call it _pre_spam instead :) > > In fact, even if spam and __pre_spam are methods, it's probably a good > idea to avoid the double-underscore name mangling. It's usually more > trouble than it's worth. > > > I write functions like __pre_spam for one reason only: to remove clutter > > from a corresponding spam function that has a particularly complex > > argument-validation/canonicalization stage. ?In effect, spam > > "outsources" to __pre_spam the messy business of checking and > > conditioning its arguments. > > A perfectly sensible arrangement. > > > The one thing I don't like about this strategy is that the tracebacks of > > exceptions raised during the execution of __pre_spam include one > > unwanted stack level (namely, the one corresponding to __pre_spam > > itself). > > But why is it unwanted? The traceback shows where the error occurs -- it > occurs in __pre_spam, not spam, or __post_spam, or spam_caller, or > anywhere else. Even if it's possible, having the traceback *lie* about > where it occurs is a bad idea which will cause confusion to anyone trying > to maintain the software in the future. I don't agree with kj's usage, but I have customized the traceback to remove items before. In my case it was to remove lines for endemic wrapper functions. The traceback lines showing the wrapper functions in the stack were useless, and since pretty much every function was wrapped it meant half the lines in that traceback were useless. (Really. I was scanning the loaded modules and adding wrappers to every function found. Never mind why.) I only printed the wrapper line if it was the very top of the stack. > I can't think of any way to do it, You override sys.excepthook to print lines from the traceback selectively. Carl Banks From nagle at animats.com Fri Dec 17 02:07:44 2010 From: nagle at animats.com (John Nagle) Date: Thu, 16 Dec 2010 23:07:44 -0800 Subject: How to pop the interpreter's stack? In-Reply-To: References: Message-ID: <4d0b0c4c$0$44018$742ec2ed@news.sonic.net> On 12/14/2010 6:31 PM, Ethan Furman wrote: > kj wrote: >> The one thing I don't like about this strategy is that the tracebacks >> of exceptions raised during the execution of __pre_spam include one >> unwanted stack level (namely, the one corresponding to __pre_spam >> itself). >> >> __pre_spam should be completely invisible and unobtrusive > > I am unaware of any way to accomplish what you desire. I also think this > is one of those things that's not worth fighting -- how often are you > going to see such a traceback? When somebody makes a coding mistake? Right. If you are worried about what the user sees in a traceback, you are doing it wrong. Consider reporting detailed error information via the logging module, for example. John Nagle From tjreedy at udel.edu Fri Dec 17 02:22:31 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 17 Dec 2010 02:22:31 -0500 Subject: How to pop the interpreter's stack? In-Reply-To: <4d0aafdb$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <4d0aafdb$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 12/16/2010 7:33 PM, Steven D'Aprano wrote: > Python's exception system has to handle two different situations: buggy > code, and bad data. It's not even clear whether there is a general > distinction to be made between the two, but even if there's not a general > distinction, there's certainly a distinction which we can *sometimes* > make. The two are intertwined. Production code that passes bad data to a function without catching the exception is buggy. > def func(x): > if !(x<= 10): > if x%2 != 0: > pass > else: > raise ValueError('bad value for x') > return > > I would have got the same traceback, A traceback is printed only if the code passes bad data and does not catch the exception. Tracebacks are for developers, not for users. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Fri Dec 17 03:23:11 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Dec 2010 08:23:11 GMT Subject: If/then style question References: Message-ID: <4d0b1def$0$29997$c3e8da3$5496439d@news.astraweb.com> On Thu, 16 Dec 2010 20:32:29 -0800, Carl Banks wrote: > Even without the cleanup issue, sometimes you want to edit a function to > affect all return values somehow. If you have a single exit point you > just make the change there; if you have mulitple you have to hunt them > down and change all of them--if you remember to. I just got bit by that > one. If your function has so many exit points that you can miss some of them while editing, your function is too big, does too much, or both. Refactor and simplify. Or wrap the function in a decorator: def affect_all_return_values(func): @functools.wraps(func) def inner(*args, **kwargs): result = func(*args, **kwargs) do_something_to(result) return result return inner @affect_all_return_values def my_big_complicated_function(args): do_something_with_many_exit_points() -- Steven From timr at probo.com Fri Dec 17 03:59:34 2010 From: timr at probo.com (Tim Roberts) Date: Fri, 17 Dec 2010 00:59:34 -0800 Subject: Newbie question about importing modules. References: Message-ID: cronoklee wrote: > >I'm starting my first python project but I'm having trouble getting >off the ground. >I've read all I can find about relative and absolute import paths but >it's just not making sense to me... There seems to be around ten >different ways to import a script. That's not really true. >I need my project to be portable so I can copy the whole folder to run >on any PC that has python installed. Is it always possible to simply >include modules in the project directory and reference them without >installing into the main python directory? Absolutely. >I've managed this with >small classes through trial and error but when I try it with anything >larger (like PIL module for example) I get errors. Do I need to >actually install anything or is it enough just to include the relevant >scripts? PIL requires DLLs as well as other Python files. You can't just copy the top-level PIL files to your own private directory. >All the modules I've found come with tonnes of files and >subdirectories. Do I need all these files or should I just choose the >scripts/folders I need? If you are delivering a program to clients, then you should look at something like py2exe, which will examine your code and produce a zip file that includes all of the files your application will need. If you are delivering a script for someone that will definitely have Python installed, then you just need to identify the dependencies. Let that person install PIL. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From tmohr at s.netic.de Fri Dec 17 04:19:53 2010 From: tmohr at s.netic.de (Torsten Mohr) Date: Fri, 17 Dec 2010 10:19:53 +0100 Subject: Read / Write OpenOffice SpreadSheet ? References: Message-ID: Hello, > There is no package needed to read or write the new open document files. > The files are merely a jar archive containing XML files. You can open > and update them using jar as a subprocess and manipulate the XML files > using your favorite XML libraries DOM/SAX/XPath/Etree/etc. thanks for your hint. I was aware of that, OO files are a bunch of zipped XML files. But, i searh for something more comfortable/highlevel that lets me just do things like doc.Cell(1, 3) = 'abc' or so. > If that doesn't suit you, you can manipulate them using OO.org through its > UNO interface; but, I find that much more involved then simply accessing > the files directly. Thanks, i read about it but as i understood it, UNO needs Python 2.3.x and i'd like to base on something actual. Best regards, Torsten. From shearichard at gmail.com Fri Dec 17 06:30:15 2010 From: shearichard at gmail.com (shearichard) Date: Fri, 17 Dec 2010 03:30:15 -0800 (PST) Subject: Newbie question about importing modules. References: Message-ID: <24e3fd89-79d9-4329-bdb7-a050597c09ab@o9g2000pre.googlegroups.com> On Dec 17, 4:42?pm, cronoklee wrote: > Hi > I'm starting my first python project but I'm having trouble getting > off the ground. > I've read all I can find about relative and absolute import paths but > it's just not making sense to me... There seems to be around ten > different ways to import a script. > > I need my project to be portable so I can copy the whole folder to run > on any PC that has python installed. Is it always possible to simply > include modules in the project directory and reference them without > installing into the main python directory? I've managed this with > small classes through trial and error but when I try it with anything > larger (like PIL module for example) I get errors. Do I need to > actually install anything or is it enough just to include the relevant > scripts? > > All the modules I've found come with tonnes of files and > subdirectories. Do I need all these files or should I just choose the > scripts/folders I need? > > Thanks, > cronoklee You may find this useful as an overview of importing ... http://effbot.org/zone/import-confusion.htm ... also this ... http://diveintopython.org/object_oriented_framework/importing_modules.html I may be stating the obvious but here's an example of using the Image object offered by PIL ... from PIL import Image ... as documented here ... http://www.pythonware.com/library/pil/handbook/image.htm Regarding bundling PIL with an app I'd second what Tim Roberts has to say regarding py2Exe regards Richard. From jeanmichel at sequans.com Fri Dec 17 08:22:35 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 17 Dec 2010 14:22:35 +0100 Subject: If/then style question In-Reply-To: References: Message-ID: <4D0B641B.1020701@sequans.com> John Gordon wrote: > (This is mostly a style question, and perhaps one that has already been > discussed elsewhere. If so, a pointer to that discussion will be > appreciated!) > > When I started learning Python, I wrote a lot of methods that looked like > this: > > > def myMethod(self, arg1, arg2): > > if some_good_condition: > > if some_other_good_condition: > > if yet_another_good_condition: > > do_some_useful_stuff() > exitCode = good1 > > else: > exitCode = bad3 > > else: > exitCode = bad2 > > else: > exitCode = bad1 > > return exitCode > > > But lately I've been preferring this style: > > > def myMethod(self, arg1, arg2): > > if some_bad_condition: > return bad1 > > elif some_other_bad_condition: > return bad2 > > elif yet_another_bad_condition: > return bad3 > > do_some_useful_stuff() > return good1 > > I like this style more, mostly because it eliminates a lot of indentation. > > However I recall one of my college CS courses stating that "one entry, > one exit" was a good way to write code, and this style has lots of exits. > > Are there any concrete advantages of one style over the other? > > Thanks. > > What about, def myMethod(): for condition, exitCode in [ (cond1, 'error1'), (cond2, 'very bad error'), ]: if not condition: break else: do_some_usefull_stuff() # executed only if the we never hit the break statement. exitCode = good1 return exitCode This version uses the 'for ... else' statement. You can easily add conditions by simply adding a line in the list, that's it. Note that this code uses a shadow declaration of exitCode in the for loop. If you're not comfortable with that, you'll have to use a properly 'declared' variable retCode and write retCode = exitCode before breaking. Actually I would advise to do so. JM From Rob.Richardson at rad-con.com Fri Dec 17 09:09:49 2010 From: Rob.Richardson at rad-con.com (Rob Richardson) Date: Fri, 17 Dec 2010 09:09:49 -0500 Subject: If/then style question In-Reply-To: <4D0B641B.1020701@sequans.com> Message-ID: <04A6DB42D2BA534FAC77B90562A6A03D016894CB@server.rad-con.local> -----Original Message----- What about, def myMethod(): for condition, exitCode in [ (cond1, 'error1'), (cond2, 'very bad error'), ]: if not condition: break else: do_some_usefull_stuff() # executed only if the we never hit the break statement. exitCode = good1 return exitCode ---- I reply ----- This is interesting, but I don't understand it (which speaks volumes about the level of my understanding of Python). First, just to clarify, I don't think the indentation I saw was what was originally posted. The "else" must be indented to match the "if", and the two statements under "else" are in the else block. The return statement is indented at the same level as the for statement, so that it will be executed after the for loop exits. Correct? Now, the for loop will set condition to cond1 and exitCode to 'error1'. Then it checks the contents of the condition variable. But what does "not " by itself mean? I'm guessing that it checks that the variable refers to an object. So, the first time through, condition refers to cond1, the if condition is false, and the else block gets executed, and exitCode is changed to refer to good1. The next time through the loop, condition is set to refer to cond2 and exitCode is set to refer to 'very bad error'. Again, condition is refering to something, so the else block is executed and we do useful stuff again, which is probably not helpful and could well be harmful. exitCode is set to good1, we're finished with the loop, and we return exitCode. What happens if we try to do useful stuff, and we can't? Where does the error indication get set? And once it does get set, the only way we can exit the for loop is for condition to not refer to anything. How can that happen? Thank you very much for your explanation and your patience with one who only uses Python in very simplistic ways. RobR From steve+comp.lang.python at pearwood.info Fri Dec 17 09:38:11 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Dec 2010 14:38:11 GMT Subject: If/then style question References: Message-ID: <4d0b75d2$0$29997$c3e8da3$5496439d@news.astraweb.com> On Fri, 17 Dec 2010 09:09:49 -0500, Rob Richardson wrote: > First, just to clarify, I don't think the indentation I saw was what was > originally posted. The "else" must be indented to match the "if", and > the two statements under "else" are in the else block. The return > statement is indented at the same level as the for statement, so that it > will be executed after the for loop exits. Correct? I think that what you are missing is that for-loops can include an else clause too, like this: >>> for x in (1,2,3): ... print(x) ... else: ... print("finished") ... 1 2 3 finished >>> The else block runs after the for block, unless you exit the entire block by returning, raising an exception, or using break: >>> for x in (1,2,3): ... print(x) ... if x == 3: break ... else: ... print("finished") ... 1 2 3 >>> Does that clear up what is going on? -- Steven From jeanmichel at sequans.com Fri Dec 17 09:41:09 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 17 Dec 2010 15:41:09 +0100 Subject: If/then style question In-Reply-To: <04A6DB42D2BA534FAC77B90562A6A03D016894CB@server.rad-con.local> References: <04A6DB42D2BA534FAC77B90562A6A03D016894CB@server.rad-con.local> Message-ID: <4D0B7685.8080009@sequans.com> Rob Richardson wrote: > -----Original Message----- > What about, > > > def myMethod(): > for condition, exitCode in [ > (cond1, 'error1'), > (cond2, 'very bad error'), > ]: > if not condition: > break > else: > do_some_usefull_stuff() # executed only if the we never hit the > break statement. > exitCode = good1 > > return exitCode > > ---- I reply ----- > > This is interesting, but I don't understand it (which speaks volumes > about the level of my understanding of Python). > > First, just to clarify, I don't think the indentation I saw was what was > originally posted. The "else" must be indented to match the "if", and > the two statements under "else" are in the else block. No, the else is indented to the for loop. for ... else is a python statement, the else block is executed only if the loop did never break. http://docs.python.org/reference/compound_stmts.html#for > The return > statement is indented at the same level as the for statement, so that it > will be executed after the for loop exits. Correct? > > Now, the for loop will set condition to cond1 and exitCode to 'error1'. > Then it checks the contents of the condition variable. But what does > "not " by itself mean? condition is a bool value. if not condition is evaluated to True, if the condition is False. condition = False not condition => True condition = ('Foo' == 'Foo') not condition => False [snip] > RobR > > My mail client could have messed up with the indentation. Here is the code: http://paste-it.net/public/t8a4acd/python/ JM From drobinow at gmail.com Fri Dec 17 09:47:43 2010 From: drobinow at gmail.com (David Robinow) Date: Fri, 17 Dec 2010 09:47:43 -0500 Subject: If/then style question In-Reply-To: <4d0aa5e7$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <4d0aa5e7$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Dec 16, 2010 at 6:51 PM, Steven D'Aprano wrote: ... > Functions always have one entry. The only way to have multiple entry > points is if the language allows you to GOTO into the middle of a > function, and Python sensibly does not allow this. The "one entry, one > exit" rule comes from the days when people would routinely write > spaghetti code, jumping into and out of blocks of code without using > functions at all. Only 99.7% true. Fortran still allows the appalling ENTRY statement. From cronoklee at gmail.com Fri Dec 17 10:30:40 2010 From: cronoklee at gmail.com (cronoklee) Date: Fri, 17 Dec 2010 07:30:40 -0800 (PST) Subject: Newbie question about importing modules. In-Reply-To: <24e3fd89-79d9-4329-bdb7-a050597c09ab@o9g2000pre.googlegroups.com> Message-ID: <7f998afc-1406-4055-b00d-4107c7fcb0af@glegroupsg2000goo.googlegroups.com> Hey thanks for the help fellas. The links were helpful and the pyExe program looks great. I might well end up using this. I'm still a little confused as to how the directory structure works. PIL (http://www.pythonware.com/products/pil/#pil117), for example comes packed in a folder called Imaging-1.1.7 which contains a bunch of other directories, one of which is PIL. Now, what I've done is move this subfolder PIL into the same directory as my python test script and used: from PIL import Image I assume this instructs python to look in the PIL folder for Image.py. Am I wrong? I feel like I'm wrong. If I need to put the whole Imaging-1.1.7 folder somewhere else, how do I reference the specific Image module that I need? Sorry for the stupidity - I'm coming from PHP where you just include path/to/script.php so this is a bit alien to me. Thanks a lot, cronoklee From robert.kern at gmail.com Fri Dec 17 10:47:01 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 17 Dec 2010 09:47:01 -0600 Subject: How to pop the interpreter's stack? In-Reply-To: <4d0aafdb$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <4d0aafdb$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 12/16/10 6:33 PM, Steven D'Aprano wrote: > On Thu, 16 Dec 2010 10:39:34 -0600, Robert Kern wrote: > >> On 12/16/10 10:23 AM, Steven D'Aprano wrote: >>> On Thu, 16 Dec 2010 07:29:25 -0800, Ethan Furman wrote: >>> >>>> Tim Arnold wrote: >>>>> "Ethan Furman" wrote in message >>>>> news:mailman.4.1292379995.6505.python-list at python.org... >>>>>> kj wrote: >>>>>>> The one thing I don't like about this strategy is that the >>>>>>> tracebacks of exceptions raised during the execution of __pre_spam >>>>>>> include one unwanted stack level (namely, the one corresponding to >>>>>>> __pre_spam itself). >>> [...] >>>> A decorator was one of the items kj explicity didn't want. Also, >>>> while it would have a shallower traceback for exceptions raised during >>>> the __pre_spam portion, any exceptions raised during spam itself would >>>> then be one level deeper than desired... while that could be masked by >>>> catching and (re-?)raising the exception in the decorator, Steven had >>>> a very good point about why that is a bad idea -- namely, tracebacks >>>> shouldn't lie about where the error is. >>> >>> True, very true... but many hours later, it suddenly hit me that what >>> KJ was asking for wasn't *necessarily* such a bad idea. My thought is, >>> suppose you have a function spam(x) which raises an exception. If it's >>> a *bug*, then absolutely you need to see exactly where the error >>> occurred, without the traceback being mangled or changed in any way. >>> >>> But what if the exception is deliberate, part of the function's >>> documented behaviour? Then you might want the exception to appear to >>> come from the function spam even if it was actually generated inside >>> some private sub-routine. >> >> Obfuscating the location that an exception gets raised prevents a lot of >> debugging (by inspection or by pdb), even if the exception is >> deliberately raised with an informative error message. Not least, the >> code that decides to raise that exception may be buggy. But even if the >> actual error is outside of the function (e.g. the caller is passing bad >> arguments), you want to at least see what tests the __pre_spam function >> is doing in order to decide to raise that exception. > > And how do you think you see that from the traceback? The traceback > prints the line which actually raises the exception (and sometimes not > even that!), which is likely to be a raise statement: > >>>> import example >>>> example.func(42) > Traceback (most recent call last): > File "", line 1, in > File "example.py", line 3, in func > raise ValueError('bad value for x') > ValueError: bad value for x > > The actual test is: > > def func(x): > if x> 10 and x%2 == 0: > raise ValueError('bad value for x') > > but you can't get that information from the traceback. But I can get the line number and trivially go look it up. If we elide that stack frame, I have to go hunting and possibly make some guesses. Depending on the organization of the code, I may have to make some guesses anyways, but if I keep the decision to raise an exception close to the actual raising of the exception, it makes things a lot easier. > Python's exception system has to handle two different situations: buggy > code, and bad data. It's not even clear whether there is a general > distinction to be made between the two, but even if there's not a general > distinction, there's certainly a distinction which we can *sometimes* > make. If a function contains a bug, we need all the information we can > get, including the exact line that causes the fault. But if the function > deliberately raises an exception due to bad input, we don't need any > information regarding the internals of the function (assuming that the > exception is sufficiently detailed, a big assumption I grant you!). If I > re-wrote the above func() like this: > > def func(x): > if !(x<= 10): > if x%2 != 0: > pass > else: > raise ValueError('bad value for x') > return > > I would have got the same traceback, except the location of the exception > would have been different (line 6, in a nested if-block). To the caller, > whether I had written the first version of func() or the second is > irrelevant. If I had passed the input validation off to a second > function, that too would be irrelevant. The caller doesn't care about tracebacks one way or the other, either. Only someone *viewing* the traceback cares as well as debuggers like pdb. Eliding the stack frame neither helps nor harms the caller, but it does substantially harm the developer viewing tracebacks or using a debugger. > I don't expect Python to magically know whether an exception is a bug or > not, but there's something to be said for the ability to turn Python > functions into black boxes with their internals invisible, like C > functions already are. If (say) math.atan2(y, x) raises an exception, you > have no way of knowing whether atan2 is a single monolithic function, or > whether it is split into multiple pieces. The location of the exception > is invisible to the caller: all you can see is that atan2 raised an > exception. And that has frustrated my debugging efforts more often than I can count. I would dearly love to have a debugger that can traverse both Python and C stack frames. This is a deficiency, not a benefit to be extended to pure Python functions. >> Tracebacks are inherently over-verbose. This is necessarily true because >> no algorithm (or clever programmer) can know all the pieces of >> information that the person debugging may want to know a priori. Most >> customizations of tracebacks *add* more verbosity rather than reduce it. >> Removing one stack level from the traceback barely makes the traceback >> more readable and removes some of the most relevant information. > > Right. But I have thought of a clever trick to get the result KJ was > asking for, with the minimum of boilerplate code. Instead of this: > > > def _pre_spam(args): > if condition(args): > raise SomeException("message") > if another_condition(args): > raise AnotherException("message") > if third_condition(args): > raise ThirdException("message") > > def spam(args): > _pre_spam(args) > do_useful_work() > > > you can return the exceptions instead of raising them (exceptions are > just objects, like everything else!), and then add one small piece of > boilerplate to the spam() function: > > > def _pre_spam(args): > if condition(args): > return SomeException("message") > if another_condition(args): > return AnotherException("message") > if third_condition(args): > return ThirdException("message") > > def spam(args): > exc = _pre_spam(args) > if exc: raise exc > do_useful_work() And that makes post-mortem pdb debugging into _pre_spam impossible. Like I said, whether the bug is inside _pre_spam or is in the code that is passing the bad argument, being able to navigate stack frames to where the code is deciding that there is an exceptional condition is important. Kern's First Maxim: Raise exceptions close to the code that decides to raise an exception. -- 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 stefan_ml at behnel.de Fri Dec 17 10:48:34 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 17 Dec 2010 16:48:34 +0100 Subject: Read / Write OpenOffice SpreadSheet ? In-Reply-To: References: Message-ID: Torsten Mohr, 17.12.2010 02:07: > i search for a possibility to access OpenOffoce SpreadSheets from Python > with a reasonably new version of Python. > > Can anybody point me to a package that can do this? Have you looked through the relevant PyPI packages? http://pypi.python.org/pypi?%3Aaction=search&term=openoffice Stefan From steve at holdenweb.com Fri Dec 17 10:53:45 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 17 Dec 2010 10:53:45 -0500 Subject: If/then style question In-Reply-To: <4d0b75d2$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <4d0b75d2$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 12/17/2010 9:38 AM, Steven D'Aprano wrote: > On Fri, 17 Dec 2010 09:09:49 -0500, Rob Richardson wrote: > > >> First, just to clarify, I don't think the indentation I saw was what was >> originally posted. The "else" must be indented to match the "if", and >> the two statements under "else" are in the else block. The return >> statement is indented at the same level as the for statement, so that it >> will be executed after the for loop exits. Correct? > > I think that what you are missing is that for-loops can include an else > clause too, like this: > > >>>> for x in (1,2,3): > ... print(x) > ... else: > ... print("finished") > ... > 1 > 2 > 3 > finished >>>> > > > The else block runs after the for block, unless you exit the entire block > by returning, raising an exception, or using break: > > >>>> for x in (1,2,3): > ... print(x) > ... if x == 3: break > ... else: > ... print("finished") > ... > 1 > 2 > 3 >>>> > > > Does that clear up what is going on? > > This construct appears to be unpopular in actual use, and when it comes up in classes and seminars there is always interesting debate as people discuss potential uses and realise there are useful applications. I think the choice of keyword is probably not Guido's crowning language achievement, but then since the English keywords don't make natural sense to those who speak other languages it's at least fair that there should be one that isn't totally natural to English speakers. A small price to pay for all the other keywords not being Dutch. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From awilliam at whitemice.org Fri Dec 17 11:02:27 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Fri, 17 Dec 2010 11:02:27 -0500 Subject: PyUNO [Was: Read / Write OpenOffice SpreadSheet ?] In-Reply-To: References: Message-ID: <1292601747.15765.1.camel@linux-yu4c.site> On Fri, 2010-12-17 at 10:19 +0100, Torsten Mohr wrote: > Thanks, i read about it but as i understood it, UNO needs Python 2.3.x and > i'd like to base on something actual. I do not *believe* this is true. for instance is Python 2.6 and uses PyUNO. I would strongly recommend against floundering about in OOo's very complex XML files - it is trivially easy to render a document unusable. From Rob.Richardson at rad-con.com Fri Dec 17 11:06:30 2010 From: Rob.Richardson at rad-con.com (Rob Richardson) Date: Fri, 17 Dec 2010 11:06:30 -0500 Subject: If/then style question In-Reply-To: <4D0B7685.8080009@sequans.com> Message-ID: <04A6DB42D2BA534FAC77B90562A6A03D016894F8@server.rad-con.local> My thanks for pointing out the existence of the else: suite in the for statement. However, I remain confused. For reference, here's the original code: > def myMethod(): > for condition, exitCode in [ > (cond1, 'error1'), > (cond2, 'very bad error'), > ]: > if not condition: > break > else: > do_some_usefull_stuff() # executed only if the we never hit the > break statement. > exitCode = good1 > > return exitCode What do we know about cond1 and cond2? Do they have to be assigned before this for statement is executed? The sample code doesn't show it. The loop is going to to execute once for condition = cond1 and exitCode = 'error1'. The only thing it's going to do is check to see what condition is. Since we can assume (I hope) that cond1 is not false, then the for loop continues. Now condition = cond2 and exitCode = 'very bad error'. The if condition is still false, so the loop continues. We've come to the end now, and the else: suite is executed. We finally do some useful stuff and exitCode = good1. (Should that have been in quotes, or doesn't it matter?) But now the for loop's job is done and we return the exitCode, which at this point is good1. But I still don't understand what happens if we can't do useful stuff. Where does an error code get set, and where is that error code checked? We don't have a chance to check it in the for loop, because once we're in the else: suite the loop condition is never rechecked. Or is it? Thanks again! RobR From mail at timgolden.me.uk Fri Dec 17 11:13:38 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 17 Dec 2010 16:13:38 +0000 Subject: If/then style question In-Reply-To: References: <4d0b75d2$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4D0B8C32.7050307@timgolden.me.uk> On 17/12/2010 15:53, Steve Holden wrote: [... snip example of for-else ...] > This construct appears to be unpopular in actual use, and when it comes > up in classes and seminars there is always interesting debate as people > discuss potential uses and realise there are useful applications. I use this not infrequently, and I like it when it seems to be an elegant way to express the code path. But I still misremember from time to time and assume that the "else" clause fires when the for loop is empty. TJG From mark.dufour at gmail.com Fri Dec 17 11:34:04 2010 From: mark.dufour at gmail.com (Mark Dufour) Date: Fri, 17 Dec 2010 17:34:04 +0100 Subject: ANN: Shed Skin 0.7 In-Reply-To: References: <1292509258.10819.1410661291@webmail.messagingengine.com> Message-ID: hi malcolm, Congratulations on your latest release! > thanks! :D > > How well do python extension modules created with ShedSkin work with > applications that expose a GUI, eg. Tkinter or wxPython apps? > quite well I think, but there are some limitations you probably want to be aware of. these are described in the tutorial. > Can ShedSkin code be run in a thread and communicate with the main > interpreter thread through a Queue or Lock? (Or should one use the > multiprocessing module?) > I'm sure things are not thread safe, so you probably want to use the multiprocessing module. how to do this is also described in the tutorial (it's very simple). you probably don't want to use threading anyway for computationally intensive code (because of the GIL). several of the shedskin examples have a GUI, and the new 'pylot' example both has a GUI and uses the multiprocessing module in combination with a shedskin-generated extension module. thanks, mark. -- http://www.youtube.com/watch?v=E6LsfnBmdnk -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at nospam.invalid Fri Dec 17 11:34:23 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 17 Dec 2010 08:34:23 -0800 Subject: If/then style question References: Message-ID: <7xei9gpddc.fsf@ruckus.brouhaha.com> Jean-Michel Pichavant writes: > What about, > > def myMethod(): > for condition, exitCode in [ > (cond1, 'error1'), > (cond2, 'very bad error'), > ]: > if not condition: > break > else: > do_some_usefull_stuff() # executed only if the we never hit the > break statement. > exitCode = good1 > > return exitCode > > This version uses the 'for ... else' statement. For..else always has seemed ugly and confusing to me, as does that thing of using the captured loop indexes after the loop finishes. I'd prefer a more functional style (untested): def myMethod(): def success(): do_some_usefull_stuff() return good1 cond_table = [ (cond1, lambda: 'error1'), (cond2, lambda: 'very bad error'), (True, success) ] func = next(f for c,f in cond_table if c) return func() This uses the next() builtin from Python 2.6. You could make it more concise: def myMethod(): cond_table = [ (cond1, lambda: 'error1'), (cond2, lambda: 'very bad error'), (True, lambda: (do_some_usefull_stuff(), good1)[1]) ] return next(f for c,f in cond_table if c)() From stefan_ml at behnel.de Fri Dec 17 11:35:52 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 17 Dec 2010 17:35:52 +0100 Subject: PyUNO [Was: Read / Write OpenOffice SpreadSheet ?] In-Reply-To: <1292601747.15765.1.camel@linux-yu4c.site> References: <1292601747.15765.1.camel@linux-yu4c.site> Message-ID: Adam Tauno Williams, 17.12.2010 17:02: > On Fri, 2010-12-17 at 10:19 +0100, Torsten Mohr wrote: >> Thanks, i read about it but as i understood it, UNO needs Python 2.3.x and >> i'd like to base on something actual. > > I do not *believe* this is true. > > for instance is Python 2.6 > and uses PyUNO. The Python installation can be replaced. Last I heard, many Linux distros used the platform Python, for example, instead of shipping an embedded one with OOo. > I would strongly recommend against floundering about in OOo's very > complex XML files - it is trivially easy to render a document unusable. True. It's not so much of a problem to read them, but writing a correct document can be tricky. What works relatively well is to write a template document in OOo and do programmatic replacements in it. But that's not guaranteed to work, either. Stefan From ethan at stoneleaf.us Fri Dec 17 11:43:46 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 17 Dec 2010 08:43:46 -0800 Subject: If/then style question In-Reply-To: <04A6DB42D2BA534FAC77B90562A6A03D016894F8@server.rad-con.local> References: <04A6DB42D2BA534FAC77B90562A6A03D016894F8@server.rad-con.local> Message-ID: <4D0B9342.80606@stoneleaf.us> Rob Richardson wrote: > My thanks for pointing out the existence of the else: suite in the for > statement. However, I remain confused. For reference, here's the > original code: > >> def myMethod(): >> for condition, exitCode in [ >> (cond1, 'error1'), >> (cond2, 'very bad error'), >> ]: >> if not condition: >> break >> else: >> do_some_usefull_stuff() # executed only if the we never hit the > >> break statement. >> exitCode = good1 >> >> return exitCode > > What do we know about cond1 and cond2? Do they have to be assigned > before this for statement is executed? The sample code doesn't show it. cond1 and cond2 should be expressions of some sort, e.g. check_files() or feedback (feedback being a variable of some sort). > The loop is going to to execute once for condition = cond1 and exitCode > = 'error1'. The only thing it's going to do is check to see what > condition is. Since we can assume (I hope) that cond1 is not false, > then the for loop continues. Now condition = cond2 and exitCode = 'very > bad error'. The if condition is still false, so the loop continues. > We've come to the end now, and the else: suite is executed. We finally > do some useful stuff and exitCode = good1. (Should that have been in > quotes, or doesn't it matter?) But now the for loop's job is done and > we return the exitCode, which at this point is good1. > > But I still don't understand what happens if we can't do useful stuff. > Where does an error code get set, and where is that error code checked? > We don't have a chance to check it in the for loop, because once we're > in the else: suite the loop condition is never rechecked. Or is it? You have outlined what happens when cond1 and cond2 both evaluate to True -- what happens if, say, cond2 evaluates to False? . . . . . if not cond2 becomes True, we hit the break, do not do do_some_usefull_stuff(), but proceed to return exitCode -- and exitCode was set in the for loop to 'very bad error' when condition was set to cond2. The exitCode no longer needs to be checked inside the function, because there is no chance of do_some_useful_stuff running if any of the conditions are False. Hope this helps. ~Ethan~ From mdw at distorted.org.uk Fri Dec 17 11:45:01 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 17 Dec 2010 16:45:01 +0000 Subject: If/then style question References: <4d0b75d2$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87ei9gz6uq.fsf.mdw@metalzone.distorted.org.uk> Steve Holden writes: > I think the choice of keyword is probably not Guido's crowning > language achievement, I remember the behaviour by considering a typical application: for thing in things: if shinyp(thing): break else: raise DullError, 'nothing shiny found' In this kind of search loop, `break' signifies a kind of successful completion: the `for' loop can be considered to be a test acting over an iterable, and `else' therefore denotes the action if the test fails. I don't know whether that's the official intuition, or even if there is an official intuition, but it works well enough for me. I'm quite fond of Python's extra `else' clauses in `for' and (particularly) `try'. -- [mdw] From steve at holdenweb.com Fri Dec 17 11:46:56 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 17 Dec 2010 11:46:56 -0500 Subject: If/then style question In-Reply-To: <4D0B8C32.7050307@timgolden.me.uk> References: <4d0b75d2$0$29997$c3e8da3$5496439d@news.astraweb.com> <4D0B8C32.7050307@timgolden.me.uk> Message-ID: On 12/17/2010 11:13 AM, Tim Golden wrote: > On 17/12/2010 15:53, Steve Holden wrote: > > [... snip example of for-else ...] > >> This construct appears to be unpopular in actual use, and when it comes >> up in classes and seminars there is always interesting debate as people >> discuss potential uses and realise there are useful applications. > > I use this not infrequently, and I like it when it seems to be an > elegant way to express the code path. But I still misremember from > time to time and assume that the "else" clause fires when the for > loop is empty. > Yes, that's a common misconception. The classical use is something like for item in possibilities: if item == target: break else: raise NotFound("Didn't find it") Though of course arguably that logic might be expressed in other ways, such as if target not in possibilities: raise NotFound("Didn't find it") regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From arnodel at gmail.com Fri Dec 17 11:59:37 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Fri, 17 Dec 2010 16:59:37 +0000 Subject: If/then style question References: <4d0b75d2$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <874oacbaiu.fsf@gmail.com> Tim Golden writes: > On 17/12/2010 15:53, Steve Holden wrote: > > [... snip example of for-else ...] > >> This construct appears to be unpopular in actual use, and when it comes >> up in classes and seminars there is always interesting debate as people >> discuss potential uses and realise there are useful applications. > > I use this not infrequently, and I like it when it seems to be an > elegant way to express the code path. But I still misremember from > time to time and assume that the "else" clause fires when the for > loop is empty. I use it from time to time, even though, like you, I used to always be unsure when the "else:" suite would be executed. I now remember this idiom as the "break else" construct: either the loop breaks, or the "else:" suite is executed. -- Arnaud From python at bdurham.com Fri Dec 17 12:13:07 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 17 Dec 2010 12:13:07 -0500 Subject: If/then style question In-Reply-To: <874oacbaiu.fsf@gmail.com> References: <4d0b75d2$0$29997$c3e8da3$5496439d@news.astraweb.com> <874oacbaiu.fsf@gmail.com> Message-ID: <1292605987.20936.1410872247@webmail.messagingengine.com> > I now remember this idiom as the "break else" construct: either the loop breaks, or the "else:" suite is executed. A perfect description. Malcolm From invalid at invalid.invalid Fri Dec 17 12:26:08 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 17 Dec 2010 17:26:08 +0000 (UTC) Subject: If/then style question References: Message-ID: On 2010-12-16, Stefan Sonnenberg-Carstens wrote: > The advantage in latter case is fewer operations, because you can > skip the assignments, and it is more readable. > > The "one entry, one exit" is an advice. Not a law. > Your code is OK. > > As long as it works ;-) Even that last bit isn't that important. Give me code that's easy-to-read and doesn't work rather code that works and can't be read any day. -- Grant Edwards grant.b.edwards Yow! What's the MATTER at Sid? ... Is your BEVERAGE gmail.com unsatisfactory? From invalid at invalid.invalid Fri Dec 17 12:31:17 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 17 Dec 2010 17:31:17 +0000 (UTC) Subject: If/then style question References: <4d0aa5e7$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-12-16, Steven D'Aprano wrote: > On Thu, 16 Dec 2010 21:49:07 +0000, John Gordon wrote: > >> (This is mostly a style question, and perhaps one that has already been >> discussed elsewhere. If so, a pointer to that discussion will be >> appreciated!) >> >> When I started learning Python, I wrote a lot of methods that looked >> like this: >> >> def myMethod(self, arg1, arg2): >> if some_good_condition: >> if some_other_good_condition: >> if yet_another_good_condition: >> do_some_useful_stuff() >> exitCode = good1 >> else: >> exitCode = bad3 >> else: >> exitCode = bad2 >> else: >> exitCode = bad1 >> return exitCode > > > It doesn't look like you were learning Python. It looks like you were > learning C with Python syntax :( Let's not blame C for bad program structure. No good C programmer would use that construct either. One choice in C would look like this: if (some_condition) return code1; if (other_condition) return code2; if (condition3) return code3; //do whatever work really needs to be done here. return successCode; Or, if there's cleanup that needs to be done, then you "raise a an exception": if (condition1) { ret = code1; goto errexit; } if (condition2) { ret = code2; goto errexit; } if (condition3) { ret = code3; goto errexit; } // do the normal bit of work errexit: //cleanup return ret; -- Grant Edwards grant.b.edwards Yow! Awright, which one of at you hid my PENIS ENVY? gmail.com From Rob.Richardson at rad-con.com Fri Dec 17 12:44:31 2010 From: Rob.Richardson at rad-con.com (Rob Richardson) Date: Fri, 17 Dec 2010 12:44:31 -0500 Subject: If/then style question In-Reply-To: <4D0B9342.80606@stoneleaf.us> Message-ID: <04A6DB42D2BA534FAC77B90562A6A03D01689508@server.rad-con.local> -----Original Message----- You have outlined what happens when cond1 and cond2 both evaluate to True -- what happens if, say, cond2 evaluates to False? ----- I reply ------------ And the light goes on! (And palm strikes forehead.) I was thinking that the error we were processing was raised by the do_some_useful_stuff() function. But the whole purpose of this thread was to evaluate error conditions that might have been set before we do useful stuff! Which, of course, was what the original poster was asking. My thanks again for your patience. RobR From usernet at ilthio.net Fri Dec 17 13:31:53 2010 From: usernet at ilthio.net (Tim Harig) Date: Fri, 17 Dec 2010 18:31:53 +0000 (UTC) Subject: PyUNO [Was: Read / Write OpenOffice SpreadSheet ?] References: Message-ID: On 2010-12-17, Adam Tauno Williams wrote: > I would strongly recommend against floundering about in OOo's very > complex XML files - it is trivially easy to render a document unusable. I do it all the time and have never had a problem. I don't generate the documents from scratch; I generate a template that contains everything that don't need to dynamically generate. Then I use one of two methods to to update the content.xml: 1. In the simplest cases, I only need to change a single data field. I replace the literal data in the content.xml file with: Then, using a DOM implementation, I can use getElementsByTagName() to get all of the replace tags and send the variable name to a distpach that generates the text used to replace the tag. 2. For collections of data (spreadsheet cells, table cells/rows, etc, I leave one piece of sample data in place. I then clone the DOM element that I can use as a template and delete the origional. Entering the data is then a simple matter of cloning the template element, updating the information that it contains, and adding it to the childNodes of the parent. Since tags all come from the file that OO.org/LibreOffice generated, the resulting markup will be valid. Once the content.xml file has been updated, I simply run jar as a subprocess to update the content.xml file in the ods/odt file. From stef.mientki at gmail.com Fri Dec 17 14:02:57 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Fri, 17 Dec 2010 20:02:57 +0100 Subject: PyUNO [Was: Read / Write OpenOffice SpreadSheet ?] In-Reply-To: <1292601747.15765.1.camel@linux-yu4c.site> References: <1292601747.15765.1.camel@linux-yu4c.site> Message-ID: <4D0BB3E1.8040603@gmail.com> On 17-12-2010 17:02, Adam Tauno Williams wrote: > On Fri, 2010-12-17 at 10:19 +0100, Torsten Mohr wrote: >> Thanks, i read about it but as i understood it, UNO needs Python 2.3.x and >> i'd like to base on something actual. > I do not *believe* this is true. > > for instance is Python 2.6 > and uses PyUNO. > > I would strongly recommend against floundering about in OOo's very > complex XML files - it is trivially easy to render a document unusable. > looks great, but is there something alike for Windows ? thanks, Stef Mientki From kevin.p.dwyer at gmail.com Fri Dec 17 14:18:43 2010 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Fri, 17 Dec 2010 19:18:43 +0000 (UTC) Subject: If/then style question References: Message-ID: On Thu, 16 Dec 2010 21:49:07 +0000, John Gordon wrote: > (This is mostly a style question, and perhaps one that has already been > discussed elsewhere. If so, a pointer to that discussion will be > appreciated!) > > When I started learning Python, I wrote a lot of methods that looked > like this: > > > def myMethod(self, arg1, arg2): > > if some_good_condition: > > if some_other_good_condition: > > if yet_another_good_condition: > > do_some_useful_stuff() > exitCode = good1 > > else: > exitCode = bad3 > > else: > exitCode = bad2 > > else: > exitCode = bad1 > > return exitCode > > Another way to look at this is as question of object-oriented style, as you are using a method in your example... Arguably, rather than branching your code based on the arguments being passed to your method, you can embody the required behaviour in subclasses of your class, and at runtime just use an object that "does the right thing". Of course, you end up writing the same branching in some factory object instead, but at least it isn't cluttering up your business logic any longer. Trying to write an OO-style program without using any if statements in the business logic can be an interesting exercise, albeit not a terribly realistic one. Apologies if your choice of a method for your example was entirely incidental to your question :) Kev From fetchinson at googlemail.com Fri Dec 17 14:36:25 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Fri, 17 Dec 2010 20:36:25 +0100 Subject: Added Python, WSGI to XAMPP In-Reply-To: <4D06C130.9040506@verizon.net> References: <4CFA4305.10004@it.uu.se> <4CFD6825.9020200@simplistix.co.uk> <4CFD8B29.3020006@verizon.net> <4D014A3D.7020101@verizon.net> <4D06AD69.4030302@simplistix.co.uk> <4D06B6D1.6080208@verizon.net> <4D06B671.5020601@simplistix.co.uk> <4D06C130.9040506@verizon.net> Message-ID: >>>>> How-To: Add VirtualEnv and Pylons (WSGI framework) to XAMPP >>>>> >>> >>> Maybe, if there's no Zope. Or we'll run away screaming... >> >> That is rather pathetically true... >> >> Ah well, each to their own... >> >> Chris >> > What I really don't like right off is that Pyramid is contorting the MVC > model just as Django did with their MTV model. They are both making the > controller be the view and this confuses the hell out of people who come > from true MVC based projects. > > The VIEW is the bits that stream out of the webserver back to the users > browser. The CONTROLLER is the code that gathers all the pieces from > the model and constructs the python code that is then fed to the engine > that then creates the view. And just because the controller navigates > the logic to dynamically contruct/render a view, that does not make 'it' > the view. In turbogears that is exactly what happens. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From jafo at tummy.com Fri Dec 17 16:23:46 2010 From: jafo at tummy.com (Sean Reifschneider) Date: Fri, 17 Dec 2010 14:23:46 -0700 Subject: Help with threading.local use in python-memcache module. Message-ID: <4D0BD4E2.2030906@tummy.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Some time ago I accepted a patch to base the memcache client module on the threading.local class. Now I've got some reports of issues with this that I'm not sure what the best way to resolve is. Bug #530229: https://bugs.launchpad.net/python-memcached/+bug/530229 says: Client is derived from threading.local presumably at some misguided sense of working across multiple threads. However this doesn't work if the same Client is used across threads serially. For instance if I create a client in one thread and then call set_servers and then use the Client in another thread the set_servers call would have had no effect since the servers and buckets are per-thread due to threading.local. and that the set_servers call only impacts one thread rather than them all. I'm a bit reluctant to just remove threading.local, in case anyone is relying on it now that it's in there. But I'd like to offer a solution for the cases where it doesn't work. Any suggestions on the solution for this? Thanks, Sean -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/ iD8DBQFNC9TixUhyMYEjVX0RAnOWAJwKZnmE/6cKR4I4tl4Km//gtkxo1QCgvK1Y ULmOdWnAViTzAS4sMts97ZA= =7qXJ -----END PGP SIGNATURE----- From jlundell at pobox.com Fri Dec 17 17:19:54 2010 From: jlundell at pobox.com (JLundell) Date: Fri, 17 Dec 2010 14:19:54 -0800 (PST) Subject: class inheritance In-Reply-To: <3db38a5b-4ede-4a14-954e-f5c9be1008ee@a10g2000pri.googlegroups.com> Message-ID: On Saturday, March 13, 2010 9:03:36 AM UTC-8, Jonathan Lundell wrote: > I've got a subclass of fractions.Fraction called Value; it's a mostly > trivial class, except that it overrides __eq__ to mean 'nearly equal'. > However, since Fraction's operations result in a Fraction, not a > Value, I end up with stuff like this: > > x = Value(1) + Value(2) > > where x is now a Fraction, not a Value, and x == y uses > Fraction.__eq__ rather than Value.__eq__. > > This appears to be standard Python behavior (int does the same thing). > I've worked around it by overriding __add__, etc, with functions that > invoke Fraction but coerce the result. But that's tedious; there are a > lot of methods to override. > > So I'm wondering: is there a more efficient way to accomplish what I'm > after? I recently implemented a different approach to this. I've got: class Rational(fractions.Fraction): ... and some methods of my own, including my own __new__ and __str__ (which is one of the reasons I need the class). Then after (outside) the class definition, this code that was inspired by something similar I noticed in Python Cookbook. There are two things going on here. One is, of course, the automation at import time. The other is that the wrapper gets a Fraction instance and simply overrides __class__, rather than creating yet another Rational and unbinding the interim Fraction. Seems to work quite well. # create wrappers for Rational methods that return Rational (not Fraction) objects # def _wrap_method(method): "wrap a Fraction method in Rational" fraction_method = getattr(Fraction, method) def x(*args): "call Fraction and change result to Rational" v = fraction_method(*args) v.__class__ = Rational return v x.func_name = method setattr(Rational, method, x) for name in "pos neg abs trunc".split(): _wrap_method("__%s__" % name) # wrap method, eg __pos__ for name in "add sub mul div truediv floordiv mod pow".split(): _wrap_method("__%s__" % name) # wrap method, eg __add__ _wrap_method("__r%s__" % name) # wrap reversed-argument method, eg __radd__ del _wrap_method From alon.sebastian at gmail.com Fri Dec 17 17:57:28 2010 From: alon.sebastian at gmail.com (Sebastian Alonso) Date: Fri, 17 Dec 2010 19:57:28 -0300 Subject: subprocess.Popen() and a .msi installer Message-ID: Hey everyone, I'm working on a script which uses subprocess to launch a bunch of installers, but I'm getting problems with .msi installers although .exe ones work fine. The output I get is this: >>> import subprocess >>> p = subprocess.Popen('python.msi') Traceback (most recent call last): File "", line 1, in p = subprocess.Popen('python.msi') File "C:\Python25\lib\subprocess.py", line 593, in __init__ errread, errwrite) File "C:\Python25\lib\subprocess.py", line 793, in _execute_child startupinfo) WindowsError: [Error 8] %1 no es una aplicaci?n Win32 v?lida >>> Has this ever happen to any of you? The idea is to get this running, make it an exe (with py2exe) and use it whenever I need to install my whole development environment in the right order. Thanks in advance to all of you. Alonso Sebastian. -------------- next part -------------- An HTML attachment was scrubbed... URL: From eric.frederich at gmail.com Fri Dec 17 17:58:54 2010 From: eric.frederich at gmail.com (Eric Frederich) Date: Fri, 17 Dec 2010 17:58:54 -0500 Subject: Creating custom types from C code Message-ID: Hello, I have an extension module for a 3rd party library in which I am wrapping some structures. My initial attempt worked okay on Windows but failed on Linux. I was doing it in two parts. The first part on the C side of things I was turning the entire structure into a char array. The second part in Python code I would unpack the structure. Anyway, I decided I should be doing things a little cleaner so I read up on "Defining New Types" http://docs.python.org/extending/newtypes.html I got it to work but I'm not sure how to create these new objects from C. My setup is almost exactly like the example on that page except instead of 2 strings and an integer I have 5 unsigned ints. I do not expect to ever be creating these objects in Python. They will only be created as return values from my wrapper functions to the 3rd party library. I could return a tuple from those functions but I want to use dot notation (e.g. somestruct.var1). So, question number 1: Is defining my own type like that overkill just to have an object to access using dots? I'll never create those objects from Python. Is there a shortcut to creating objects and setting attributes from within C? In any case, I was able to create my own custom object from C code like so... PyObject *foo(SomeCStruct bar){ PyObject *ret; ret = _PyObject_New(&mymodule_SomeStructType); PyObject_SetAttrString(ret, "var1" , Py_BuildValue("I", bar.var1 )); PyObject_SetAttrString(ret, "var2" , Py_BuildValue("I", bar.var2 )); PyObject_SetAttrString(ret, "var3" , Py_BuildValue("I", bar.var3 )); PyObject_SetAttrString(ret, "var4" , Py_BuildValue("I", bar.var4 )); PyObject_SetAttrString(ret, "var5" , Py_BuildValue("I", bar.var5 )); return ret; } When using _PyObject_New I notice that neither my new or init function are ever called. I verified that they are getting called when creating the object from Python (which I would never do anyway). Question number 2: Do I need to be calling PyObject_SetAttrString or is there a way to set the unsigned ints on the structure direcly? It seems overkill to create a Python object for an unsigned int just to set it as an attribute on a custom defined type. Question number 3: In the above code, is there a memory leak? Should I be Py_DECREF'ing the return value from Py_BuildValue after I'm done using it. From emile at fenx.com Fri Dec 17 18:08:44 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 17 Dec 2010 15:08:44 -0800 Subject: Odd listcomp behaviour Message-ID: Does anyone else consider this a bug? Python 2.6.2 (r262:71600, Jun 16 2009, 11:09:39) [GCC 3.4.6 20060404 (Red Hat 3.4.6-10)] on linux2 Type "help", "copyright", "credits" or "license" for more information. ---1--- >>> skippedords = '1,2,3,4,5' >>> ['10%s' % ii for ii in skippedords.split(',')] ['101', '102', '103', '104', '105'] ---2--- >>> skippedords = '' >>> ['10%s' % ii for ii in skippedords.split(',')] ['10'] ---3--- >>> test = '' >>> ['%s' % ii for ii in test.split() ] [] I got stung because I expected ---2--- to do what ---3--- did. Emile From emile at fenx.com Fri Dec 17 18:17:10 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 17 Dec 2010 15:17:10 -0800 Subject: Odd listcomp behaviour In-Reply-To: References: Message-ID: On 12/17/2010 3:08 PM Emile van Sebille said... > Does anyone else consider this a bug? Hmmm... looks like it's split that I've got the issue with... >>> "this is a test".split() ['this', 'is', 'a', 'test'] >>> "this is a test".split(' ') ['this', 'is', 'a', 'test'] >>> "".split(' ') [''] >>> "".split() [] Emile From emile at fenx.com Fri Dec 17 18:20:46 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 17 Dec 2010 15:20:46 -0800 Subject: Odd listcomp behaviour In-Reply-To: References: Message-ID: On 12/17/2010 3:17 PM Emile van Sebille said... > On 12/17/2010 3:08 PM Emile van Sebille said... >> Does anyone else consider this a bug? > > Hmmm... looks like it's split that I've got the issue with... > Nevermind... if it's documented it's not a bug, right? Hrrmph. Emile str.split([sep[, maxsplit]])? Return a list of the words in the string, using sep as the delimiter string. If maxsplit is given, at most maxsplit splits are done (thus, the list will have at most maxsplit+1 elements). If maxsplit is not specified, then there is no limit on the number of splits (all possible splits are made). If sep is given, consecutive delimiters are not grouped together and are deemed to delimit empty strings (for example, '1,,2'.split(',') returns ['1', '', '2']). The sep argument may consist of multiple characters (for example, '1<>2<>3'.split('<>') returns ['1', '2', '3']). Splitting an empty string with a specified separator returns ['']. If sep is not specified or is None, a different splitting algorithm is applied: runs of consecutive whitespace are regarded as a single separator, and the result will contain no empty strings at the start or end if the string has leading or trailing whitespace. Consequently, splitting an empty string or a string consisting of just whitespace with a None separator returns []. For example, ' 1 2 3 '.split() returns ['1', '2', '3'], and ' 1 2 3 '.split(None, 1) returns ['1', '2 3 ']. From benjamin.kaplan at case.edu Fri Dec 17 18:27:36 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 17 Dec 2010 18:27:36 -0500 Subject: subprocess.Popen() and a .msi installer In-Reply-To: References: Message-ID: On Fri, Dec 17, 2010 at 5:57 PM, Sebastian Alonso wrote: > Hey everyone, I'm working on a script which uses subprocess to launch a > bunch of installers, but I'm getting problems with .msi installers although > .exe ones work fine. The output I get is this: > >>>> import subprocess >>>> p = subprocess.Popen('python.msi') > Traceback (most recent call last): > File "", line 1, in > p = subprocess.Popen('python.msi') > File "C:\Python25\lib\subprocess.py", line 593, in __init__ > errread, errwrite) > File "C:\Python25\lib\subprocess.py", line 793, in _execute_child > startupinfo) > WindowsError: [Error 8] %1 no es una aplicaci?n Win32 v?lida >>>> > > Has this ever happen to any of you? The idea is to get this running, make it > an exe (with py2exe) and use it whenever I need to install my whole > development environment in the right order. > > Thanks in advance to all of you. > > > Alonso Sebastian. > msi files are not executables. You need to use msiexec to run them. From ethan at stoneleaf.us Fri Dec 17 18:28:33 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 17 Dec 2010 15:28:33 -0800 Subject: Odd listcomp behaviour In-Reply-To: References: Message-ID: <4D0BF221.8080505@stoneleaf.us> Emile van Sebille wrote: > Does anyone else consider this a bug? > > Python 2.6.2 (r262:71600, Jun 16 2009, 11:09:39) > [GCC 3.4.6 20060404 (Red Hat 3.4.6-10)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > > ---1--- > >>> skippedords = '1,2,3,4,5' > >>> ['10%s' % ii for ii in skippedords.split(',')] > ['101', '102', '103', '104', '105'] > > ---2--- > >>> skippedords = '' > >>> ['10%s' % ii for ii in skippedords.split(',')] > ['10'] > > ---3--- > >>> test = '' > >>> ['%s' % ii for ii in test.split() ] > [] > > > I got stung because I expected ---2--- to do what ---3--- did. It's stung me too (more times than I care to admit! ;), but it's not a bug. 2.5 docs: split( [sep [,maxsplit]]) Return a list of the words in the string, using sep as the delimiter string. ... Splitting an empty string with a specified separator returns "['']". If sep is not specified or is None, a different splitting algorithm is applied. ... Splitting an empty string or a string consisting of just whitespace returns an empty list. Note the bit in the second paragraph. Here's my code snippet: Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. --> test = '' --> test.split() [] --> test.split(' ') [''] --> test.split(',') [''] --> test.split(None) [] Hope this helps! ~Ethan~ From python at mrabarnett.plus.com Fri Dec 17 18:29:45 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 17 Dec 2010 23:29:45 +0000 Subject: Odd listcomp behaviour In-Reply-To: References: Message-ID: <4D0BF269.2020203@mrabarnett.plus.com> On 17/12/2010 23:08, Emile van Sebille wrote: > Does anyone else consider this a bug? > > Python 2.6.2 (r262:71600, Jun 16 2009, 11:09:39) > [GCC 3.4.6 20060404 (Red Hat 3.4.6-10)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > > ---1--- > >>> skippedords = '1,2,3,4,5' > >>> ['10%s' % ii for ii in skippedords.split(',')] > ['101', '102', '103', '104', '105'] > > ---2--- > >>> skippedords = '' > >>> ['10%s' % ii for ii in skippedords.split(',')] > ['10'] > > ---3--- > >>> test = '' > >>> ['%s' % ii for ii in test.split() ] > [] > > > I got stung because I expected ---2--- to do what ---3--- did. > It's not a bug. The third example is the odd one out because it splits on a sequence of one or more (whitespace) characters and discards empty strings. For example: >>> ',,1,,2,,'.split(',') ['', '', '1', '', '2', '', ''] >>> ' 1 2 '.split(' ') ['', '', '1', '', '2', '', ''] >>> # But... >>> ' 1 2 '.split() ['1', '2'] From tjreedy at udel.edu Fri Dec 17 18:56:57 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 17 Dec 2010 18:56:57 -0500 Subject: Read / Write OpenOffice SpreadSheet ? In-Reply-To: References: Message-ID: On 12/17/2010 4:19 AM, Torsten Mohr wrote: > Hello, > >> There is no package needed to read or write the new open document files. >> The files are merely a jar archive containing XML files. You can open >> and update them using jar as a subprocess and manipulate the XML files >> using your favorite XML libraries DOM/SAX/XPath/Etree/etc. > > thanks for your hint. I was aware of that, OO files are a bunch of zipped > XML files. But, i searh for something more comfortable/highlevel that lets > me just do things like doc.Cell(1, 3) = 'abc' or so. http://opendocumentfellowship.com/projects/odfpy -- Terry Jan Reedy From matti.p.airas at nokia.com Fri Dec 17 19:04:33 2010 From: matti.p.airas at nokia.com (Matti Airas) Date: Fri, 17 Dec 2010 21:04:33 -0300 Subject: PySide: Python for Qt version 1.0.0~beta2 "Mineshaft gap" released Message-ID: <4D0BFA91.9010203@nokia.com> The PySide team is happy to announce the second beta release of PySide: Python for Qt. New versions of some of the PySide toolchain components (API Extractor and Shiboken) have been released as well. This is a source code release only; we hope our community packagers will be providing provide binary packages shortly. To acquire the source code packages, refer to our download wiki page [1] or pull the relevant tagged versions from our git repositories [2]. Major changes since 1.0.0~beta1 =============================== PySide now supports exposing list-like properties to QML using QDeclarativeListProperty. Documentation is still rather sparse, but refer to the example to see a how it works [3]. Other than the QML work, we have been working on fixing outstanding bugs. Since beta1, a total of 16 high-priority bugs have been fixed. See the list of fixed bugs at the end of this message. Note for Windows users ====================== While preparing the release, we noticed at the last minute a regression that only occurs on Windows (bug 554) [4]. Due to insufficient time for fixing the bug, we decided to move forward with the release nevertheless. We will provide a separate patch for fixing the Windows regression within the next few days. Path towards 1.0 release ======================== There are still plenty of outstanding bugs in our Bugzilla [5]. To improve our quality in a controlled fashion, we plan to do probably a couple more beta releases after the current one. Due to the holiday season, the next release will be three weeks from now, but after that we'll return to two-week release cadence until 1.0. About PySide ============ PySide is the Nokia-sponsored Python Qt bindings project, providing access to not only the complete Qt 4.7 framework but also Qt Mobility, as well as to generator tools for rapidly generating bindings for any Qt-based libraries. The PySide project is developed in the open, with all facilities you'd expect from any modern OSS project such as all code in a git repository [2], an open Bugzilla [5] for reporting bugs, and an open design process [6]. We welcome any contribution without requring a transfer of copyright. List of bugs fixed ================== 383 qelapsedtimer_wrapper.cpp: No such file or directory 415 phonon bindings does not build 468 Segfaults, segfaults and more segfaults 489 PySide.QtGui.QImage with string buffer argument 491 pyside doesn't respect BUILD_TESTS 500 If an instance of QPrintDialog is created a deadlock happens on shutdown. 505 CppObject was destroyed before __del__ be called 508 qmltopy1 crashes when setContextProperty is called twice without keeping a reference 512 QGridLayout::getItemPosition() is not available 513 Hardcoded bool return type for operator overloads 517 Documentation for QtDeclarative is not linked in contents.html, modules.html 518 The file "genindex.html" is not found (linked from contents.html) 524 Debugging errors during work of createpackage.js on windows is hard 527 Two different PySide Wikis 542 New style signals/slots + curried functions: unexpected argument during call 543 Regression: Signals with default values broken References ========== [1] http://developer.qt.nokia.com/wiki/PySideDownloads [2] http://qt.gitorious.org/pyside [3] http://qt.gitorious.org/pyside/pyside-examples/trees/master/examples/declarative/extending/chapter5-listproperties [4] http://bugs.openbossa.org/show_bug.cgi?id=554 [5] http://bugs.openbossa.org/ [6] http://www.pyside.org/docs/pseps/psep-0001.html From hpj at urpla.net Fri Dec 17 19:19:14 2010 From: hpj at urpla.net (Hans-Peter Jansen) Date: Sat, 18 Dec 2010 01:19:14 +0100 Subject: Read / Write OpenOffice SpreadSheet ? In-Reply-To: References: Message-ID: <201012180119.14801.hpj@urpla.net> On Friday 17 December 2010, 02:07:07 Torsten Mohr wrote: > Hi, > > i search for a possibility to access OpenOffoce SpreadSheets from > Python with a reasonably new version of Python. > > Can anybody point me to a package that can do this? http://ooopy.sourceforge.net/ Pete From steve+comp.lang.python at pearwood.info Sat Dec 18 00:50:46 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Dec 2010 05:50:46 GMT Subject: If/then style question References: <4d0b75d2$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4d0c4bb6$0$29997$c3e8da3$5496439d@news.astraweb.com> On Fri, 17 Dec 2010 10:53:45 -0500, Steve Holden wrote about for...else: > This construct appears to be unpopular in actual use, and when it comes > up in classes and seminars there is always interesting debate as people > discuss potential uses and realise there are useful applications. Yes, I find I don't need it often, but it is useful from time to time. I wonder whether it would have been more useful to reverse the sense of the else, and have it run only if the for loop *didn't* run to completion. That seemed more intuitive to me, and I've wanted to do this more than once. Here's a toy example: for x in sequence: if x == "spam": print("exiting early") break elif x == "ham": print("exiting early") break do_something(x) would become: for x in sequence: if x == "spam": break elif x == "ham": break do_something(x) else: print("exiting early") > I think the choice of keyword is probably not Guido's crowning language > achievement, but then since the English keywords don't make natural > sense to those who speak other languages it's at least fair that there > should be one that isn't totally natural to English speakers. A small > price to pay for all the other keywords not being Dutch. Indeed :) -- Steven From steve+comp.lang.python at pearwood.info Sat Dec 18 01:02:39 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Dec 2010 06:02:39 GMT Subject: If/then style question References: Message-ID: <4d0c4e7f$0$29997$c3e8da3$5496439d@news.astraweb.com> On Fri, 17 Dec 2010 17:26:08 +0000, Grant Edwards wrote: > Give me code that's easy-to-read and doesn't work rather code that works > and can't be read any day. Well, in that case, you'll love my new operating system, written in 100% pure Python: [start code] print("this is an operating system") [end code] I expect it to rapidly make Windows, Linux and OS-X all obsolete. Bill Gates and Steve Jobs, look out! *grin* Surely your attitude towards usefulness vs. readability will depend strongly on whether you are intending to *use* the code, or *maintain* the code? -- Steven From stefan_ml at behnel.de Sat Dec 18 01:18:35 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 18 Dec 2010 07:18:35 +0100 Subject: Creating custom types from C code In-Reply-To: References: Message-ID: Eric Frederich, 17.12.2010 23:58: > I have an extension module for a 3rd party library in which I am > wrapping some structures. > My initial attempt worked okay on Windows but failed on Linux. > I was doing it in two parts. > The first part on the C side of things I was turning the entire > structure into a char array. > The second part in Python code I would unpack the structure. > > Anyway, I decided I should be doing things a little cleaner so I read > up on "Defining New Types" > http://docs.python.org/extending/newtypes.html > > I got it to work but I'm not sure how to create these new objects from C. You may want to take a look at Cython. It makes writing C extensions easy. For one, it will do all sorts of type conversions for you, and do them efficiently and safely (you get an exception on overflow, for example). It's basically Python, so creating classes and instantiating them is trivial. Also note that it's generally not too much work to rewrite an existing C wrapper in Cython, but it's almost always worth it. You immediately get more maintainable code that's much easier to extend and work on. It's also often faster than hand written code. http://cython.org > My setup is almost exactly like the example on that page except > instead of 2 strings and an integer I have 5 unsigned ints. > > I do not expect to ever be creating these objects in Python. They > will only be created as return values from my wrapper functions to the > 3rd party library. In Cython 0.14, you can declare classes as "final" and "internal" using a decorator, meaning that they cannot be subtyped from Python and do not show up in the module dict. However, note that there is no way to prevent users from getting their hands at the type once you give them an instance. > I could return a tuple from those functions but I want to use dot > notation (e.g. somestruct.var1). Then __getattr__ or properties are your friend. > So, question number 1: > Is defining my own type like that overkill just to have an object > to access using dots? Creating wrapper objects is totally normal. Also note that recent Python versions have named tuples, BTW. > I'll never create those objects from Python. > Is there a shortcut to creating objects and setting attributes > from within C? The Cython code for instantiating classes is identical to Python. > In any case, I was able to create my own custom object from C code like so... > > PyObject *foo(SomeCStruct bar){ > PyObject *ret; > ret = _PyObject_New(&mymodule_SomeStructType); > PyObject_SetAttrString(ret, "var1" , Py_BuildValue("I", bar.var1 )); > PyObject_SetAttrString(ret, "var2" , Py_BuildValue("I", bar.var2 )); > PyObject_SetAttrString(ret, "var3" , Py_BuildValue("I", bar.var3 )); > PyObject_SetAttrString(ret, "var4" , Py_BuildValue("I", bar.var4 )); > PyObject_SetAttrString(ret, "var5" , Py_BuildValue("I", bar.var5 )); > return ret; > } > > When using _PyObject_New I notice that neither my new or init function > are ever called. > I verified that they are getting called when creating the object from > Python Things often work a little different in Python and C. Directly calling _PyObject_New() is a lot less than what Python does internally. The canonical way is to PyObject_Call() the type (or to use one of the other call functions, depending on what your arguments are). > (which I would never do anyway). Your users could do it, though, so you should make sure that won't crash the interpreter that way by leaving internal data fields uninitialised. > Question number 2: > Do I need to be calling PyObject_SetAttrString or is there a way > to set the unsigned ints on the structure direcly? > It seems overkill to create a Python object for an unsigned int > just to set it as an attribute on a custom defined type. You will have to do it at some point, though, either at instantiation time or at Python access time. Depending on the expected usage, either of the two can be more wasteful. > Question number 3: > In the above code, is there a memory leak? Should I be > Py_DECREF'ing the return value from Py_BuildValue after I'm done using > it. You can look that up in the C-API docs. If a function doesn't say that it "steals" a reference, you still own the reference when it returns and have to manually decref it (again, a thing that you won't usually have to care about in Cython). So, yes, the above leaks one reference for each call to Py_BuildValue(). Stefan From shearichard at gmail.com Sat Dec 18 05:06:44 2010 From: shearichard at gmail.com (shearichard) Date: Sat, 18 Dec 2010 02:06:44 -0800 (PST) Subject: Serialize my class as JSON causes "__init__() got an unexpected keyword argument 'indent'" ? Message-ID: <9bf689d5-6099-4d79-8b71-0bbe4e5203d3@m20g2000prc.googlegroups.com> Hi - I've got a straightforward class I want to serialize as JSON (actually I want to a serialize a list of them but I believe that's irrelevant). I've subclassed JSONEncoder and defined my own version of the 'default' method ( based upon what I read at http://docs.python.org/library/json.html ) but when I then try to serialize the class I get the (fairly weird) error message : "TypeError: __init__() got an unexpected keyword argument 'indent'". I suspect I'm doing something pretty fundamentally wrong but I don't know what - can anyone tell me what's wrong (or alternatively tell me how to log this as a bug ;-) Here's my test case : import json class SuperPeople(object): pass class People(SuperPeople, json.JSONEncoder): def __init__(self, name, age): self.__name = name self.__age = age def default(self, obj): if isinstance(obj, People): return [obj.__name, obj.__age] else: return json.JSONEncoder.default(self, obj) def main(): lstPeople = [] lstPeople.append(People("Mary", 50)) lstPeople.append(People("Joe", 40)) lstPeople.append(People("Sue", 30)) print json.dumps(lstPeople, cls=People) if __name__ == "__main__": main() ... and this is what the stacktrace looks like .... Traceback (most recent call last): File "testJSON.py", line 24, in main() File "testJSON.py", line 20, in main json.dumps(lstPeople, cls=People) File "C:\bin\installed\Python2.6\lib\json\__init__.py", line 237, in dumps **kw).encode(obj) TypeError: __init__() got an unexpected keyword argument 'indent' ... I'm running Python 2.6 on Win32. All suggestions welcomed . Richard. From __peter__ at web.de Sat Dec 18 05:30:13 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 18 Dec 2010 11:30:13 +0100 Subject: Serialize my class as JSON causes "__init__() got an unexpected keyword argument 'indent'" ? References: <9bf689d5-6099-4d79-8b71-0bbe4e5203d3@m20g2000prc.googlegroups.com> Message-ID: shearichard wrote: > Hi - I've got a straightforward class I want to serialize as JSON > (actually I want to a serialize a list of them but I believe that's > irrelevant). > > I've subclassed JSONEncoder and defined my own version of the > 'default' method ( based upon what I read at > http://docs.python.org/library/json.html ) but when I then try to > serialize the class I get the (fairly weird) error message : "TypeError: > __init__() got an unexpected keyword argument 'indent'". > > I suspect I'm doing something pretty fundamentally wrong but I don't > know what - can anyone tell me what's wrong (or alternatively tell me > how to log this as a bug ;-) > > Here's my test case : > > import json > class SuperPeople(object): > pass > class People(SuperPeople, json.JSONEncoder): > def __init__(self, name, age): > self.__name = name > self.__age = age > def default(self, obj): > if isinstance(obj, People): > return [obj.__name, obj.__age] > else: > return json.JSONEncoder.default(self, obj) > > def main(): > lstPeople = [] > lstPeople.append(People("Mary", 50)) > lstPeople.append(People("Joe", 40)) > lstPeople.append(People("Sue", 30)) > > print json.dumps(lstPeople, cls=People) > > > if __name__ == "__main__": > main() > > > ... and this is what the stacktrace looks like .... > > Traceback (most recent call last): > File "testJSON.py", line 24, in > main() > File "testJSON.py", line 20, in main > json.dumps(lstPeople, cls=People) > File "C:\bin\installed\Python2.6\lib\json\__init__.py", line 237, in > dumps > **kw).encode(obj) > TypeError: __init__() got an unexpected keyword argument 'indent' > > > ... I'm running Python 2.6 on Win32. > > All suggestions welcomed . You pass the encoder *class* to json.dumps(), so the function has to instantiate it. It does that with the arguments that an encoder class must accept. There's no way for it to expect that an encoder requires a name and an age. The solution is to separate the encoder and the class that shall be encoded. Here's one way: import json class People(object): def __init__(self, name, age): self.__name = name self.__age = age def get_json_state(self): return [self.__name, self.__age] class PeopleEncoder(json.JSONEncoder): def default(self, obj): if isinstance(obj, People): return obj.get_json_state() else: return json.JSONEncoder.default(self, obj) def main(): lstPeople = [] lstPeople.append(People("Mary", 50)) lstPeople.append(People("Joe", 40)) lstPeople.append(People("Sue", 30)) print json.dumps(lstPeople, cls=PeopleEncoder) if __name__ == "__main__": main() From fal at togliquesto.fastwebnet.it Sat Dec 18 06:29:31 2010 From: fal at togliquesto.fastwebnet.it (Francesco) Date: Sat, 18 Dec 2010 12:29:31 +0100 Subject: If/then style question In-Reply-To: <4d0aa5e7$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <4d0aa5e7$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4D0C9B1B.2030605@togliquesto.fastwebnet.it> On 17/12/2010 0.51, Steven D'Aprano wrote: > Don't get me wrong... spaghetti code is*bad*. But there are other ways > of writing bad code too, and hanging around inside a function long after > you've finished is also bad: > > def function(arg): > done = False > do_something() > if some_condition: > result = "finished" > done = True > if not done: > do_something_else() > if another_condition: > result = "now we're finished" > done = True > if not done: > do_yet_more_work() > if third_condition: > result = "finished this time for sure" > done = True > if not done: > for i in range(1000000): > if not done: > do_something_small() > if yet_another_condition: > result = "finally done!" > done = True > return result > > It's far more complicated than it need be, and does*lots* of unnecessary > work. This can be written more simply and efficiently as: > > def function(arg): > do_something() > if some_condition: > return "finished" > do_something_else() > if another_condition: > return "now we're finished" > do_yet_more_work() > if third_condition: > return "finished this time for sure" > for i in range(1000000): > do_something_small() > if yet_another_condition: > return "finally done!" I agree to your point, but I'm afraid you chose a wrong example (AFAIK, and that's not much). Sure, the second version of function(arg) is much more readable, but why do you think the first one would do "*lots* of unnecessary work"? All the overhead in that function would be: if some_condition, three IF tests, and you know that's NOT a lot! if no conditions were met, (worst case) the first version would return an exception (unless result was globally defined) while the second would happily return None. Apart from this, the overhead in the first one would amount to one million IF tests, again not a lot these days. I don't think I would rewrite that function, if I found it written in the first way... I don't mean that the fist example is better, just I'm sure you could imagine a more compelling proof of your concept. Maybe there's something I don't know... in that case, please enlighten me! Francesco From shearichard at gmail.com Sat Dec 18 06:32:29 2010 From: shearichard at gmail.com (shearichard) Date: Sat, 18 Dec 2010 03:32:29 -0800 (PST) Subject: Serialize my class as JSON causes "__init__() got an unexpected keyword argument 'indent'" ? References: <9bf689d5-6099-4d79-8b71-0bbe4e5203d3@m20g2000prc.googlegroups.com> Message-ID: On Dec 18, 11:30?pm, Peter Otten <__pete... at web.de> wrote: > shearichard wrote: > > Hi - I've got a straightforward class I want to serialize as JSON > > (actually I want to a serialize a list of them but I believe that's > > irrelevant). > > > I've subclassed JSONEncoder and defined my own version of the > > 'default' method ( based upon what I read at > >http://docs.python.org/library/json.html) but when I then try to > > serialize the class I get the (fairly weird) error message : "TypeError: > > __init__() got an unexpected keyword argument 'indent'". > > > I suspect I'm doing something pretty fundamentally wrong but I don't > > know what - can anyone tell me what's wrong (or alternatively tell me > > how to log this as a bug ;-) > > > Here's my test case : > > > import json > > class SuperPeople(object): > > ? ? pass > > class People(SuperPeople, json.JSONEncoder): > > ? ? def __init__(self, name, age): > > ? ? ? ? self.__name = name > > ? ? ? ? self.__age = age > > ? ? def default(self, obj): > > ? ? ? ? if isinstance(obj, People): > > ? ? ? ? ? ? return [obj.__name, obj.__age] > > ? ? ? ? else: > > ? ? ? ? ? ? return json.JSONEncoder.default(self, obj) > > > def main(): > > ? ? lstPeople = [] > > ? ? lstPeople.append(People("Mary", 50)) > > ? ? lstPeople.append(People("Joe", 40)) > > ? ? lstPeople.append(People("Sue", 30)) > > > ? ? print json.dumps(lstPeople, cls=People) > > > if __name__ == "__main__": > > ? ? main() > > > ... and this is what the stacktrace looks like ?.... > > > Traceback (most recent call last): > > ? File "testJSON.py", line 24, in > > ? ? main() > > ? File "testJSON.py", line 20, in main > > ? ? json.dumps(lstPeople, cls=People) > > ? File "C:\bin\installed\Python2.6\lib\json\__init__.py", line 237, in > > dumps > > ? ? **kw).encode(obj) > > TypeError: __init__() got an unexpected keyword argument 'indent' > > > ... I'm running Python 2.6 on Win32. > > > All suggestions welcomed . > > You pass the encoder *class* to json.dumps(), so the function has to > instantiate it. It does that with the arguments that an encoder class must > accept. There's no way for it to expect that an encoder requires a name and > an age. > > The solution is to separate the encoder and the class that shall be encoded. > Here's one way: > > import json > > class People(object): > ? ? def __init__(self, name, age): > ? ? ? ? self.__name = name > ? ? ? ? self.__age = age > ? ? def get_json_state(self): > ? ? ? ? return [self.__name, self.__age] > > class PeopleEncoder(json.JSONEncoder): > ? ? def default(self, obj): > ? ? ? ? if isinstance(obj, People): > ? ? ? ? ? ? return obj.get_json_state() > ? ? ? ? else: > ? ? ? ? ? ? return json.JSONEncoder.default(self, obj) > > def main(): > ? ? lstPeople = [] > ? ? lstPeople.append(People("Mary", 50)) > ? ? lstPeople.append(People("Joe", 40)) > ? ? lstPeople.append(People("Sue", 30)) > > ? ? print json.dumps(lstPeople, cls=PeopleEncoder) > > if __name__ == "__main__": > ? ? main() Brilliant - thank you very much. Now that you've explained it I can see why the documentation is written the way it is ! Before I saw your example I thought the documentation was a bit strange but I can see now what it was trying to tell me ! Your help is much appreciated. Richard. From nobody at nowhere.com Sat Dec 18 10:04:33 2010 From: nobody at nowhere.com (Nobody) Date: Sat, 18 Dec 2010 15:04:33 +0000 Subject: subprocess.Popen() and a .msi installer References: Message-ID: On Fri, Dec 17, 2010 at 17:57, Sebastian Alonso wrote: > Hey everyone, I'm working on a script which uses subprocess to launch a > bunch of installers, but I'm getting problems with .msi installers > although .exe ones work fine. The output I get is this: > >>>> import subprocess >>>> p = subprocess.Popen('python.msi') You need to add shell=True to "execute" anything which isn't a binary executable (EXE). From timr at probo.com Sat Dec 18 14:20:53 2010 From: timr at probo.com (Tim Roberts) Date: Sat, 18 Dec 2010 11:20:53 -0800 Subject: Newbie question about importing modules. References: <24e3fd89-79d9-4329-bdb7-a050597c09ab@o9g2000pre.googlegroups.com> <7f998afc-1406-4055-b00d-4107c7fcb0af@glegroupsg2000goo.googlegroups.com> Message-ID: cronoklee wrote: > >Hey thanks for the help fellas. The links were helpful and the pyExe >program looks great. I might well end up using this. > >I'm still a little confused as to how the directory structure works. PIL >(http://www.pythonware.com/products/pil/#pil117), for example comes packed >in a folder called Imaging-1.1.7 which contains a bunch of other >directories, one of which is PIL. That is a source distribution. It is not intended to be used as is -- it must be installed first. The installation process will build whatever shared libraries might be required, and then move the directories and folders into the site-packages directory of your Python installation. In this case, it will create a subdirectory called site-packages/PIL. The "site-packages" directory is already on your Python path, so when you say from PIL import Image the interpreter will scan through all of the directories in the path, notice that one of them contains a folder called PIL that has the right format for a module (meaning it has __init__.py), and will bring in Image.py from that directory. The PIL installer also creates a file called site-packages/PIL.pth which contains the name "PIL". Python looks for .pth files and adds those directories to the module path at startup. So, this would ALSO work: import Image >Sorry for the stupidity - I'm coming from PHP where you just include path/to/script.php so this is a bit alien to me. That certainly works for individual scripts, but even with PHP there are customary central locations where complicated packages are installed. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From greno at verizon.net Sat Dec 18 14:51:55 2010 From: greno at verizon.net (Gerry Reno) Date: Sat, 18 Dec 2010 14:51:55 -0500 Subject: Added Python, WSGI to XAMPP In-Reply-To: References: <4CFA4305.10004@it.uu.se> <4CFD6825.9020200@simplistix.co.uk> <4CFD8B29.3020006@verizon.net> <4D014A3D.7020101@verizon.net> <4D06AD69.4030302@simplistix.co.uk> <4D06B6D1.6080208@verizon.net> <4D06B671.5020601@simplistix.co.uk> <4D06C130.9040506@verizon.net> Message-ID: <4D0D10DB.4070102@verizon.net> On 12/17/2010 02:36 PM, Daniel Fetchinson wrote: >>>>>> How-To: Add VirtualEnv and Pylons (WSGI framework) to XAMPP >>>>>> >>>> >>>> Maybe, if there's no Zope. Or we'll run away screaming... >>> >>> That is rather pathetically true... >>> >>> Ah well, each to their own... >>> >>> Chris >>> >> What I really don't like right off is that Pyramid is contorting the MVC >> model just as Django did with their MTV model. They are both making the >> controller be the view and this confuses the hell out of people who come >> from true MVC based projects. >> >> The VIEW is the bits that stream out of the webserver back to the users >> browser. The CONTROLLER is the code that gathers all the pieces from >> the model and constructs the python code that is then fed to the engine >> that then creates the view. And just because the controller navigates >> the logic to dynamically contruct/render a view, that does not make 'it' >> the view. > > In turbogears that is exactly what happens. > > Cheers, > Daniel > > > How-To: Add VirtualEnv and TurboGears2 (WSGI frmwk) to XAMPP http://www.apachefriends.org/f/viewtopic.php?f=17&t=43207 -Gerry From greg.ewing at canterbury.ac.nz Sat Dec 18 18:27:44 2010 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sun, 19 Dec 2010 12:27:44 +1300 Subject: ANN: PyGUI 2.3.3 Message-ID: PyGUI 2.3.3 is available: http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ Minor update to fix a problem with the previous release on some versions of MacOSX. What is PyGUI? -------------- PyGUI is a cross-platform GUI toolkit designed to be lightweight and have a highly Pythonic API. -- Gregory Ewing greg.ewing at canterbury.ac.nz http://www.cosc.canterbury.ac.nz/greg.ewing/ From tjreedy at udel.edu Sat Dec 18 18:28:48 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 18 Dec 2010 18:28:48 -0500 Subject: Serialize my class as JSON causes "__init__() got an unexpected keyword argument 'indent'" ? In-Reply-To: References: <9bf689d5-6099-4d79-8b71-0bbe4e5203d3@m20g2000prc.googlegroups.com> Message-ID: On 12/18/2010 6:32 AM, shearichard wrote: > Brilliant - thank you very much. > > Now that you've explained it I can see why the documentation is > written the way it is ! Before I saw your example I thought the > documentation was a bit strange but I can see now what it was trying > to tell me ! If you have any idea who to improve that part of the doc so you would have understood it without Peter's nice explanation and example here, please open a doc issue on the tracker. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Sat Dec 18 19:05:22 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Dec 2010 00:05:22 GMT Subject: If/then style question References: <4d0aa5e7$0$29997$c3e8da3$5496439d@news.astraweb.com> <4D0C9B1B.2030605@togliquesto.fastwebnet.it> Message-ID: <4d0d4c42$0$29997$c3e8da3$5496439d@news.astraweb.com> On Sat, 18 Dec 2010 12:29:31 +0100, Francesco wrote: [...] > I agree to your point, but I'm afraid you chose a wrong example (AFAIK, > and that's not much). Sure, the second version of function(arg) is much > more readable, but why do you think the first one would do "*lots* of > unnecessary work"? > All the overhead in that function would be: > if some_condition, three IF tests, and you know that's NOT a lot! Well, let's try it with a working (albeit contrived) example. This is just an example -- obviously I wouldn't write the function like this in real life, I'd use a while loop, but to illustrate the issue it will do. def func1(n): result = -1 done = False n = (n+1)//2 if n%2 == 1: result = n done = True if not done: n = (n+1)//2 if n%2 == 1: result = n done = True if not done: n = (n+1)//2 if n%2 == 1: result = n done = True if not done: for i in range(1000000): if not done: n = (n+1)//2 if n%2 == 1: result = n done = True return result def func2(n): n = (n+1)//2 if n%2 == 1: return n n = (n+1)//2 if n%2 == 1: return n n = (n+1)//2 if n%2 == 1: return n for i in range(1000000): n = (n+1)//2 if n%2 == 1: return n return -1 Not only is the second far more readable that the first, but it's also significantly faster: >>> from timeit import Timer >>> t1 = Timer('for i in range(20): x = func1(i)', ... 'from __main__ import func1') >>> t2 = Timer('for i in range(20): x = func2(i)', ... 'from __main__ import func2') >>> min(t1.repeat(number=10, repeat=5)) 7.3219029903411865 >>> min(t2.repeat(number=10, repeat=5)) 4.530779838562012 The first function does approximately 60% more work than the first, all of it unnecessary overhead. -- Steven From zhangqi88686 at yahoo.cn Sat Dec 18 22:44:59 2010 From: zhangqi88686 at yahoo.cn (shoesbuy) Date: Sat, 18 Dec 2010 19:44:59 -0800 (PST) Subject: moncler balck cap vest Moncler Jackets Kids Black <4d0b1def$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <60aff542-c760-48af-b683-c1749bb67435@n10g2000yqd.googlegroups.com> On Dec 17, 12:23?am, Steven D'Aprano wrote: > On Thu, 16 Dec 2010 20:32:29 -0800, Carl Banks wrote: > > Even without the cleanup issue, sometimes you want to edit a function to > > affect all return values somehow. ?If you have a single exit point you > > just make the change there; if you have mulitple you have to hunt them > > down and change all of them--if you remember to. ?I just got bit by that > > one. > > If your function has so many exit points that you can miss some of them > while editing, your function is too big, does too much, or both. Sanctimonious much? In the real world, people "miss things" and "make mistakes" and not necessarily because they are working on something too complex to handle. It happens. Carl Banks From lambdadmitry at gmail.com Sun Dec 19 01:18:07 2010 From: lambdadmitry at gmail.com (Dmitry Groshev) Date: Sat, 18 Dec 2010 22:18:07 -0800 (PST) Subject: True lists in python? Message-ID: Is there any way to use a true lists (with O(c) insertion/deletion and O(n) search) in python? For example, to make things like reversing part of the list with a constant time. From lambdadmitry at gmail.com Sun Dec 19 01:41:57 2010 From: lambdadmitry at gmail.com (Dmitry Groshev) Date: Sat, 18 Dec 2010 22:41:57 -0800 (PST) Subject: True lists in python? References: Message-ID: <97c3f195-3a56-47ca-892e-bf724bdd1601@l32g2000yqc.googlegroups.com> On Dec 19, 9:18?am, Dmitry Groshev wrote: > Is there any way to use a true lists (with O(c) insertion/deletion and > O(n) search) in python? For example, to make things like reversing > part of the list with a constant time. I forgot to mention that I mean *fast* lists. It's trivial to do things like this with objects, but it will be sloooow. From zak.mc.kraken at libero.it Sun Dec 19 01:48:54 2010 From: zak.mc.kraken at libero.it (Vito 'ZeD' De Tullio) Date: Sun, 19 Dec 2010 07:48:54 +0100 Subject: True lists in python? References: Message-ID: Dmitry Groshev wrote: > Is there any way to use a true lists (with O(c) insertion/deletion and > O(n) search) in python? For example, to make things like reversing > part of the list with a constant time. if you're interested just in "reverse" a collection maybe you can take a look at the deque[0] module. If you want "true lists" (um... "linked list"?) there are is this recipe[1] you might look. [0] http://docs.python.org/library/collections.html#collections.deque [1] http://code.activestate.com/recipes/577355-python-27-linked-list-vs- list/ -- By ZeD From lambdadmitry at gmail.com Sun Dec 19 02:12:43 2010 From: lambdadmitry at gmail.com (Dmitry Groshev) Date: Sat, 18 Dec 2010 23:12:43 -0800 (PST) Subject: True lists in python? References: Message-ID: <35a132b9-ab6b-45d9-9dd4-0a9decf078b3@d8g2000yqf.googlegroups.com> On Dec 19, 9:48?am, Vito 'ZeD' De Tullio wrote: > Dmitry Groshev wrote: > > Is there any way to use a true lists (with O(c) insertion/deletion and > > O(n) search) in python? For example, to make things like reversing > > part of the list with a constant time. > > if you're interested just in "reverse" a collection maybe you can take a > look at the deque[0] module. > > If you want "true lists" (um... "linked list"?) there are is this recipe[1] > you might look. > > [0]http://docs.python.org/library/collections.html#collections.deque > [1]http://code.activestate.com/recipes/577355-python-27-linked-list-vs- > list/ > > -- > By ZeD -I can't find any information about reverse's complexity in python docs, but it seems that deque is a linked list. Maybe this is the one I need. -Yes, I meant linked list - sorry for misunderstanding. -Linked list on objects is too slow. It must be a C-extension for a proper speed. From no.email at nospam.invalid Sun Dec 19 03:24:48 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 19 Dec 2010 00:24:48 -0800 Subject: True lists in python? References: <35a132b9-ab6b-45d9-9dd4-0a9decf078b3@d8g2000yqf.googlegroups.com> Message-ID: <7x1v5e186n.fsf@ruckus.brouhaha.com> Dmitry Groshev writes: > -I can't find any information about reverse's complexity in python > docs, but it seems that deque is a linked list. Maybe this is the one > I need. Deques are not linked lists. They're just like regular Python lists (i.e. resizeable arrays) except they can grow and shrink at both ends rather than just one. The amortized complexity of an append or pop operation (at either end) is O(1) but occasionally the list has to be reallocated, which is O(N). From steve+comp.lang.python at pearwood.info Sun Dec 19 03:33:51 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Dec 2010 08:33:51 GMT Subject: If/then style question References: <4d0b1def$0$29997$c3e8da3$5496439d@news.astraweb.com> <60aff542-c760-48af-b683-c1749bb67435@n10g2000yqd.googlegroups.com> Message-ID: <4d0dc36e$0$29997$c3e8da3$5496439d@news.astraweb.com> On Sat, 18 Dec 2010 19:59:45 -0800, Carl Banks wrote: > On Dec 17, 12:23?am, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> On Thu, 16 Dec 2010 20:32:29 -0800, Carl Banks wrote: >> > Even without the cleanup issue, sometimes you want to edit a function >> > to affect all return values somehow. ?If you have a single exit point >> > you just make the change there; if you have mulitple you have to hunt >> > them down and change all of them--if you remember to. ?I just got bit >> > by that one. >> >> If your function has so many exit points that you can miss some of them >> while editing, your function is too big, does too much, or both. > > Sanctimonious much? In the real world, people "miss things" and "make > mistakes" and not necessarily because they are working on something too > complex to handle. It happens. Really? I had no idea. I've never made a misteak, I asumed evrybody else was equally brilliant. No, wait, there was that one time... *wink* Of course people make mistakes. So what's your point? The point I was trying to make is that rather than encouraging an idiom (only one return statement, even if the algorithm is more clearly written with multiple exists) that leads to more complex, less efficient code just in case you might someday need to modify the return result, there are simple alternatives that avoid the need for anti-patterns like copy- and-paste coding or enforced single exit point. I gave two: - refactor the complex code so that it's less complex (e.g. instead of 20 exit points, which makes it easy to miss one or two, refactor it so there are two or three exit points); or if that's not practical: - wrap it in a decorator that performs the post-processing you need. Both can be simple, effective and Pythonic. Neither require the coder to use an artificial idiom just in case of some future need. The decorator solution works even if you don't have access to the source code, or if the function is a complex black box that nobody understands well enough to touch. -- Steven From steve+comp.lang.python at pearwood.info Sun Dec 19 03:49:17 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Dec 2010 08:49:17 GMT Subject: True lists in python? References: Message-ID: <4d0dc70d$0$29997$c3e8da3$5496439d@news.astraweb.com> On Sat, 18 Dec 2010 22:18:07 -0800, Dmitry Groshev wrote: > Is there any way to use a true lists (with O(c) insertion/deletion and > O(n) search) in python? Python lists have amortized constant time insertion and deletion at the end of the list, O(N) insertion and deletion at the beginning of the list, and O(N) search. > For example, to make things like reversing part > of the list with a constant time. It's been many years since I've had to worry about rolling my own low- level linked lists, but I don't think that reversing a list can be done in constant time. I can't see any way to go from this linked list: node1 -> node2 -> node3 -> node4 -> node5 -> node6 -> node7 to this: node1 -> node6 -> node5 -> node4 -> node3 -> node2 -> node7 in constant time. You have to touch each of the nodes being reversed. Others have already suggested you look at deques, but I'm curious as to what application you have where regular lists are too slow. (I assume you have actually profiled your application, and are trying to solve an actual speed issue, not just assuming it is slow.) I would normally reverse a portion of a list like this: mylist[23:42] = mylist[23:42][::-1] So long as the section you are reversing is small enough to fit in memory without paging, this should be quite quick. -- Steven From lists at cheimes.de Sun Dec 19 03:58:55 2010 From: lists at cheimes.de (Christian Heimes) Date: Sun, 19 Dec 2010 09:58:55 +0100 Subject: True lists in python? In-Reply-To: <7x1v5e186n.fsf@ruckus.brouhaha.com> References: <35a132b9-ab6b-45d9-9dd4-0a9decf078b3@d8g2000yqf.googlegroups.com> <7x1v5e186n.fsf@ruckus.brouhaha.com> Message-ID: Am 19.12.2010 09:24, schrieb Paul Rubin: > Deques are not linked lists. They're just like regular Python lists > (i.e. resizeable arrays) except they can grow and shrink at both ends > rather than just one. The amortized complexity of an append or pop > operation (at either end) is O(1) but occasionally the list has to > be reallocated, which is O(N). You are both right and both wrong at the same time. Python's deques are neither linked lists nor ordinary lists. They are combination of both techniques. Deques are made of double linked blocks where each block can contain up the 62 Python objects. The type is optimized for push and pop on both sides but not for iteration or search. Christian From user at compgroups.net/ Sun Dec 19 05:39:51 2010 From: user at compgroups.net/ (plz) Date: Sun, 19 Dec 2010 04:39:51 -0600 Subject: how to measure TCP congestion windows using python ?? Message-ID: hi! i'm newbie about python and i want to measure the value of cwnd in TCP socket. I have searched from an internet and got that we could handle it from SOL_TCP, TCP_INFO...since unix had #include and we could refer to tcp_info for getting the information of TCP by using this method but i don't know how to declare the tcp_info in Python.. does anyone know how to handle this? please suggest me Thanks in advance From stefan.sonnenberg at pythonmeister.com Sun Dec 19 07:02:13 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Sun, 19 Dec 2010 13:02:13 +0100 Subject: how to measure TCP congestion windows using python ?? In-Reply-To: References: Message-ID: <4D0DF445.20206@pythonmeister.com> Am 19.12.2010 11:39, schrieb plz: > hi! i'm newbie about python and i want to measure the value of cwnd in TCP socket. > > I have searched from an internet and got that we could handle it from SOL_TCP, TCP_INFO...since unix had #include and we could refer to tcp_info > for getting the information of TCP by using this method > > but i don't know how to declare the tcp_info in Python.. > does anyone know how to handle this? please suggest me > > Thanks in advance > > Which OS ? I remember these parts not being really paltform indepentend. From zak.mc.kraken at libero.it Sun Dec 19 07:59:12 2010 From: zak.mc.kraken at libero.it (Vito 'ZeD' De Tullio) Date: Sun, 19 Dec 2010 13:59:12 +0100 Subject: True lists in python? References: <4d0dc70d$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > I can't see any way to go from this linked list: > > node1 -> node2 -> node3 -> node4 -> node5 -> node6 -> node7 > > to this: > > node1 -> node6 -> node5 -> node4 -> node3 -> node2 -> node7 > > in constant time. You have to touch each of the nodes being reversed. very crude example: class Node(object): def __init__(self, value, list): self.value = value self.next = self.previous = None self.list = list def nextNode(self): if not self.list.reversed: return self.next else: return self.previous class LinkedList(object): def __init__(self): self.head = None self.reversed = False def insertAsHead(self, value): n = Node(value, self) n.next = self.head if self.head is not None: self.head.previous = n self.head = n def main(): ll = LinkedList() ll.insertAsHead(4) ll.insertAsHead(3) ll.insertAsHead(2) n = ll.head while n is not None: n_previous = n print n.value n = n.nextNode() print 'reversed' ll.reversed = True n = n_previous while n is not None: print n.value n = n.nextNode() if __name__ == '__main__': main() -- By ZeD From stefan.sonnenberg at pythonmeister.com Sun Dec 19 08:56:27 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Sun, 19 Dec 2010 14:56:27 +0100 Subject: how to measure TCP congestion windows using python ?? In-Reply-To: References: Message-ID: <4D0E0F0B.5060601@pythonmeister.com> Am 19.12.2010 11:39, schrieb plz: > hi! i'm newbie about python and i want to measure the value of cwnd in TCP socket. > > I have searched from an internet and got that we could handle it from SOL_TCP, TCP_INFO...since unix had #include and we could refer to tcp_info > for getting the information of TCP by using this method > > but i don't know how to declare the tcp_info in Python.. > does anyone know how to handle this? please suggest me > > Thanks in advance > > Here is non-portable way to get the data under Linux: import socket from ctypes import * cdll.LoadLibrary('libc.so.6') libc = CDLL('libc.so.6') class tcp_info(Structure): _fields_ = [ ('tcpi_state',c_uint8), ('tcpi_ca_state',c_uint8), ('tcpi_retransmits',c_uint8), ('tcpi_probes',c_uint8), ('tcpi_backoff',c_uint8), ('tcpi_options',c_uint8), ('tcpi_snd_wscale',c_uint8,4), ('tcpi_rcv_wscale',c_uint8,4), ('tcpi_rto',c_uint32), ('tcpi_ato',c_uint32), ('tcpi_snd_mss',c_uint32), ('tcpi_rcv_mss',c_uint32), ('tcpi_unacked',c_uint32), ('tcpi_sacked',c_uint32), ('tcpi_lost',c_uint32), ('tcpi_retrans',c_uint32), ('tcpi_fackets',c_uint32), ('tcpi_last_data_sent',c_uint32), ('tcpi_last_ack_sent',c_uint32), ('tcpi_last_data_recv',c_uint32), ('tcpi_last_ack_recv',c_uint32), ('tcpi_pmtu',c_uint32), ('tcpi_rcv_ssthresh',c_uint32), ('tcpi_rtt',c_uint32), ('tcpi_rttvar',c_uint32), ('tcpi_snd_ssthresh',c_uint32), ('tcpi_snd_cwnd',c_uint32), ('tcpi_advmss',c_uint32), ('tcpi_reordering',c_uint32), ('tcpi_rcv_rtt',c_uint32), ('tcpi_rcv_space',c_uint32), ('tcpi_total_retrans',c_uint32) ] sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM,socket.IPPROTO_TCP) info = tcp_info() pinfo = pointer(info) len_info = c_uint32(sizeof(tcp_info)) plen_info = pointer(len_info) res = libc.getsockopt(sock.fileno(),socket.SOL_TCP,socket.TCP_INFO,pinfo,plen_info) if res == 0: for n in (x[0] for x in tcp_info._fields_): print n,getattr(info,n) else: print 'getsockopt() failed. (%i)' % res Tested under Ubuntu 10.10 and Python 2.6.6. From doomster at knuut.de Sun Dec 19 10:41:18 2010 From: doomster at knuut.de (Ulrich Eckhardt) Date: Sun, 19 Dec 2010 16:41:18 +0100 Subject: True lists in python? References: Message-ID: <8n6nd0FqpuU1@mid.uni-berlin.de> Dmitry Groshev wrote: > Is there any way to use a true lists (with O(c) insertion/deletion > and O(n) search) in python? Inserting/deleting in the middle requires shuffling elements around, since Python's list is an array/vector. If you don't rely on the ordering, insert or delete at the end instead, possibly swapping the last element with the one you want to delete first: class x(list): def pop(self, index=None): if index is None: return list.pop(self) res = self[index] self[index] = self[-1] self.pop() return res > For example, to make things like reversing > part of the list with a constant time. a) This doesn't work in constant time but O(n) time. b) You can have the same complexity with a Python list, too. Cheers! Uli From stefan.sonnenberg at pythonmeister.com Sun Dec 19 14:45:55 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Sun, 19 Dec 2010 20:45:55 +0100 Subject: True lists in python? In-Reply-To: References: Message-ID: <4D0E60F3.7070205@pythonmeister.com> Am 19.12.2010 07:18, schrieb Dmitry Groshev: > Is there any way to use a true lists (with O(c) insertion/deletion and > O(n) search) in python? For example, to make things like reversing > part of the list with a constant time. reversing part of the list could also be interpreted as reading it in the opposite direction from a given starting point to a known end. Perhaps you want to look into the array module, but you have to sacrifice the typelessness of a true python list: it can only contain numerical data (also char, byte). But don't know the timing pattern of array objects, only that they are *way* faster then lists. From nagle at animats.com Sun Dec 19 14:58:11 2010 From: nagle at animats.com (John Nagle) Date: Sun, 19 Dec 2010 11:58:11 -0800 Subject: True lists in python? In-Reply-To: <97c3f195-3a56-47ca-892e-bf724bdd1601@l32g2000yqc.googlegroups.com> References: <97c3f195-3a56-47ca-892e-bf724bdd1601@l32g2000yqc.googlegroups.com> Message-ID: <4d0e63d2$0$43987$742ec2ed@news.sonic.net> On 12/18/2010 10:41 PM, Dmitry Groshev wrote: > On Dec 19, 9:18 am, Dmitry Groshev wrote: >> Is there any way to use a true lists (with O(c) insertion/deletion and >> O(n) search) in python? For example, to make things like reversing >> part of the list with a constant time. > > I forgot to mention that I mean *fast* lists. It's trivial to do > things like this with objects, but it will be sloooow. Try using objects with "slots". If you have a large number of small objects, and are doing many very simple operations on them, the attribute lookup time will dominate. A nice example of when you might need real lists is for the Traveling Salesman Problem. The usual way to solve that is: 1. Link up all the nodes in a random order. 2. Pick two links at random, and cut the list into three lists. 3. Try all possible ways to arrange the three lists (there are 6*4*2/2 = 24 ways) and compute the path length for each. 4. Pick the shortest path. 5. Repeat steps 2-5 until no improvement is observed for a while. The cut-and-reassemble steps are constant time for real lists, but require expensive copying with arrays. If you're really worried about low-level performance issues, CPython is probably the wrong tool for the job. John Nagle From tomf.sessile at gmail.com Sun Dec 19 16:35:34 2010 From: tomf.sessile at gmail.com (TomF) Date: Sun, 19 Dec 2010 13:35:34 -0800 Subject: True lists in python? References: Message-ID: <2010121913353464730-tomfsessile@gmailcom> On 2010-12-18 22:18:07 -0800, Dmitry Groshev said: > Is there any way to use a true lists (with O(c) insertion/deletion and > O(n) search) in python? For example, to make things like reversing > part of the list with a constant time. I assume you mean a C extension that implements doubly linked lists (reversing part of a list is only constant time if the list is doubly-linked). I'm not aware of one. A longer answer is that many high level languages (Python, Perl, Ruby) don't bother implementing simple linked lists because they're not very useful. Instead they use hybrid data structures that can operate as lists and arrays with flexibility and acceptable costs. And if you need greater speed you usually go to special purpose arrays (for constant time access) rather than lists. -Tom From Martin at Hvidberg.net Sun Dec 19 16:41:58 2010 From: Martin at Hvidberg.net (Martin Hvidberg) Date: Sun, 19 Dec 2010 22:41:58 +0100 Subject: Reading special Danish letters in Python Message-ID: <4D0E7C26.8070204@Hvidberg.net> Dear list I have to read some data from an ASCII text file, filter it, and then export it to a .dbf file. Basically a straight forward task... My problem is that the input files contains some special national (Danish) characters, and it appears that I have to do something special to handle these in Python. The Danish language contains three letters not in the English alphabet: ?, ? and ?. E.g. the Danish city name 'SOLR?D' is red by Python as 'SOLR\xc3\x98D' The three letters, in lower and upper case, seems to get translated as follow: ? = \xc3\xa6 ? = \xc3\xb8 ? = \xc3\xa5 ? = \xc3\x86 ? = \xc3\x98 ? = \xc3\x85 Question: What is this, how do I get my Danish letters back? Best Regards Martin -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Sun Dec 19 16:42:27 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 19 Dec 2010 14:42:27 -0700 Subject: True lists in python? In-Reply-To: References: <4d0dc70d$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Dec 19, 2010 at 5:59 AM, Vito 'ZeD' De Tullio wrote: > Steven D'Aprano wrote: > >> I can't see any way to go from this linked list: >> >> node1 -> node2 -> node3 -> node4 -> node5 -> node6 -> node7 >> >> to this: >> >> node1 -> node6 -> node5 -> node4 -> node3 -> node2 -> node7 >> >> in constant time. You have to touch each of the nodes being reversed. > > very crude example: [SNIPPED] That reverses the whole list. How does it help with reversing only part of the list, as in Steven's example? From solipsis at pitrou.net Sun Dec 19 16:54:55 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Sun, 19 Dec 2010 22:54:55 +0100 Subject: True lists in python? References: <4D0E60F3.7070205@pythonmeister.com> Message-ID: <20101219225455.367a79c2@pitrou.net> On Sun, 19 Dec 2010 20:45:55 +0100 Stefan Sonnenberg-Carstens wrote: > Am 19.12.2010 07:18, schrieb Dmitry Groshev: > > Is there any way to use a true lists (with O(c) insertion/deletion and > > O(n) search) in python? For example, to make things like reversing > > part of the list with a constant time. > reversing part of the list could also be interpreted as reading it > in the opposite direction from a given starting point to a known end. > > Perhaps you want to look into the array module, but you > have to sacrifice the typelessness of a true python list: > it can only contain numerical data (also char, byte). > > But don't know the timing pattern of array objects, only that they are *way* > faster then lists. Why do you say there're much faster? Regards Antoine. From vlastimil.brom at gmail.com Sun Dec 19 17:53:48 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sun, 19 Dec 2010 23:53:48 +0100 Subject: Reading special Danish letters in Python In-Reply-To: <4D0E7C26.8070204@Hvidberg.net> References: <4D0E7C26.8070204@Hvidberg.net> Message-ID: 2010/12/19 Martin Hvidberg : > Dear list > > I have to read some data from an ASCII text file, filter it, and then export > it to a .dbf file. Basically a straight forward task... > My problem is that the input files contains some special national (Danish) > characters, and it appears that I have to do something special to handle > these in Python. > The Danish language contains three letters not in the English alphabet: ?, ? > and ?. > E.g. the Danish city name 'SOLR?D' is red by Python as 'SOLR\xc3\x98D' > The three letters, in lower and upper case, seems to get translated as > follow: > > ? = \xc3\xa6 > ? = \xc3\xb8 > ? = \xc3\xa5 > ? = \xc3\x86 > ? = \xc3\x98 > ? = \xc3\x85 > > Question: > What is this, how do I get my Danish letters back? > > Best Regards > Martin > > -- > http://mail.python.org/mailman/listinfo/python-list > > Hi, it seems, your data is utf-8 encoded text cf. >>> u"?".encode("utf-8") '\xc3\xa6' >>> u"?".encode("utf-8") '\xc3\xb8' you can decode the file content using this encoding if it is already read somewhere or use codecs.open with the same encoding >>> print '\xc3\xa6'.decode("utf-8") ? >>> hth, vbr From user at compgroups.net/ Sun Dec 19 19:45:49 2010 From: user at compgroups.net/ (plz) Date: Sun, 19 Dec 2010 18:45:49 -0600 Subject: how to measure TCP congestion windows using python ?? References: Message-ID: hi many thanks for helping me i also tried to manipulate it last night here is my code... import socket import struct sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM) tcp_info = sock.getsockopt(socket.SOL_TCP, socket.TCP_INFO, struct.calcsize('BBBBBBBLLLLLLLLLLLLLLLLLLLLLLLL')) print struct.unpack('BBBBBBBLLLLLLLLLLLLLLLLLLLLLLLL', tcp_info) the result of struct.unpack of tcp_info is following in /usr/include/linux/tcp.h used Linux Redhat and Python 2.7 anyway your code is very useful Thxs again ;) From nad at acm.org Sun Dec 19 19:52:14 2010 From: nad at acm.org (Ned Deily) Date: Sun, 19 Dec 2010 16:52:14 -0800 Subject: get python bit version as in (32 or 64) References: <4CBE0FC2.6060604@gmx.net> <6C3DD9D7-A1D6-49EA-97C2-4A6F9630758A@semanchuk.com> Message-ID: In article , Ned Deily wrote: > In article > , > Vincent Davis wrote: > > On Tue, Oct 19, 2010 at 3:55 PM, Philip Semanchuk > > wrote: > > > On Oct 19, 2010, at 5:38 PM, Hexamorph wrote: > > >> On 19.10.2010 23:18, Vincent Davis wrote: > > >>> How do I get the bit version of the installed python. In my case, osx > > >>> python2.7 binary installed. I know it runs 64 bt as I can see it in > > >>> activity monitor. but how do I ask python? > > >>> sys.version > > >>> '2.7 (r27:82508, Jul ?3 2010, 21:12:11) \n[GCC 4.0.1 (Apple Inc. build > > >>> 5493)]' > > >>> > > >> > > >> In [1]: import platform > > >> > > >> In [2]: platform.architecture() > > >> Out[2]: ('32bit', 'ELF') > > >> > > >> In [3]: > > > > > > > > > Looks a lot better than my suggestion! > > It looks better but, unfortunately, it doesn't work correctly on OS X > where a universal build can have both 32-bit and 64-bit executables in > the same file. > > $ arch -x86_64 /usr/local/bin/python2.7 -c 'import sys,platform; > print(sys.maxint,platform.architecture())' > (9223372036854775807, ('64bit', '')) > $ arch -i386 /usr/local/bin/python2.7 -c 'import sys,platform; > print(sys.maxint,platform.architecture())' > (2147483647, ('64bit', '')) > > At the moment, the sys.maxint trick is the simplest reliable test for > Python 2 on OS X. For Python 3, substitute sys.maxsize. For the record, I've supplied a patch to fix platform.architecture() for OS X universal builds: http://bugs.python.org/issue10735 The sys.maxsize (or sys.maxint prior to Python 2.6) test is still a better cross-platform choice. -- Ned Deily, nad at acm.org From bavishi.darshak at gmail.com Mon Dec 20 02:38:40 2010 From: bavishi.darshak at gmail.com (Darshak Bavishi) Date: Mon, 20 Dec 2010 13:08:40 +0530 Subject: how to handle output generated after execution of command/script on host unix machine? Message-ID: Hi Experts, I am still struggling with handling output generated after execution of command/script on host unix machine using windows client machine ssh code : import sys import datetime import time # setup logging paramiko.util.log_to_file('darshak_simple.log') ssh=paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect("*****",username="****",password="****") try: stdin,stdout,stderr=ssh.exec_command("BsPlSMProbe -f node -d > /var/log/Darshak/3.txt ") // output of this command will be store in /var/log/Darshak/ in remote machine except: {Issue is files are generating but remaining blank pls pls help me out of this} print "check" time.sleep(10) print stdout.readlines() a=stdout.readlines() print 1 ssh.close() #print stdout.readlines() Issue is files are generating but remaining blank pls pls help me out of this -- BR Darshak Bavishi -- BR Darshak Bavishi -------------- next part -------------- An HTML attachment was scrubbed... URL: From mechtheist at gmail.com Mon Dec 20 03:45:18 2010 From: mechtheist at gmail.com (mechtheist) Date: Mon, 20 Dec 2010 02:45:18 -0600 Subject: How can I intentionally crash my lappy? Message-ID: <4D0F179E.4050704@gmail.com> I am no programmer, but know the rudiments [the rudi'est of rudiments] of working with Python. I have a simple need, to have a simple script/app I can run that will crash my PC. On my desktops, I can always hit the reset, but that is not an option with my laptop. Can anyone tell me of an easy way to guarantee a program will instantly kill/BSOD my windows7/64bit laptop? Any help is much appreciated. From stefan.sonnenberg at pythonmeister.com Mon Dec 20 04:31:05 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Mon, 20 Dec 2010 10:31:05 +0100 Subject: How can I intentionally crash my lappy? In-Reply-To: <4D0F179E.4050704@gmail.com> References: <4D0F179E.4050704@gmail.com> Message-ID: <55d991ae7a5068ee10a3637b2330b5c4-EhVcX1lJRApWRxoDCzpQCEFddQZLVF5dQUBFCzBYWENGU1kWXlpwH1RcWzBeQ0wAV1leRF5Q-webmailer1@server02.webmailer.hosteurope.de> http://pcsupport.about.com/od/tipstricks/ht/makebsodxp.htm Am Mo, 20.12.2010, 09:45 schrieb mechtheist: > I am no programmer, but know the rudiments [the rudi'est of rudiments] > of working with Python. I have a simple need, to have a simple > script/app I can run that will crash my PC. On my desktops, I can > always hit the reset, but that is not an option with my laptop. Can > anyone tell me of an easy way to guarantee a program will instantly > kill/BSOD my windows7/64bit laptop? > > Any help is much appreciated. > -- > http://mail.python.org/mailman/listinfo/python-list From marc.sedda at gmail.com Mon Dec 20 05:08:57 2010 From: marc.sedda at gmail.com (MarcoS) Date: Mon, 20 Dec 2010 02:08:57 -0800 (PST) Subject: Dynamic list name from a string Message-ID: <48c5eb62-b011-4ff6-ad1e-be92abe2e2eb@o4g2000yqd.googlegroups.com> Hi, I need to create a list with a dynamic name, something like this: '%s_list' %my_dynamic list = [] It's this possible? From steve+comp.lang.python at pearwood.info Mon Dec 20 05:22:33 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Dec 2010 10:22:33 GMT Subject: How can I intentionally crash my lappy? References: Message-ID: <4d0f2e69$0$29966$c3e8da3$5496439d@news.astraweb.com> On Mon, 20 Dec 2010 02:45:18 -0600, mechtheist wrote: > I am no programmer, but know the rudiments [the rudi'est of rudiments] > of working with Python. I have a simple need, to have a simple > script/app I can run that will crash my PC. On my desktops, I can > always hit the reset, but that is not an option with my laptop. Can > anyone tell me of an easy way to guarantee a program will instantly > kill/BSOD my windows7/64bit laptop? > > Any help is much appreciated. You realise that the operating system (yes, even Windows!) is designed to *not* crash no matter what the application does? (The OS may live up to that requirement imperfectly, but still, it tries.) You'll probably find that task easier from C than from Python. But if I were to attempt such a strange thing, I'd try to shut down some critical processes used by the OS. I'm not much of a Windows person, but if you call up the task manager (ctrl-alt-del) and inspect the process list, then find one that causes the machine to crash if you shut it down, you can probably do the same thing from a script. -- Steven From steve+comp.lang.python at pearwood.info Mon Dec 20 05:32:13 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Dec 2010 10:32:13 GMT Subject: Dynamic list name from a string References: <48c5eb62-b011-4ff6-ad1e-be92abe2e2eb@o4g2000yqd.googlegroups.com> Message-ID: <4d0f30ad$0$29966$c3e8da3$5496439d@news.astraweb.com> On Mon, 20 Dec 2010 02:08:57 -0800, MarcoS wrote: > Hi, I need to create a list with a dynamic name, something like this: > > '%s_list' %my_dynamic list = [] > > It's this possible? I'm pretty sure you don't *need* to, you just think you do. It is highly unlikely that there is anything you can do with such a variable-variable- name that you can't do by a more sensible technique. But since you ask: >>> name = 'variable' >>> variable Traceback (most recent call last): File "", line 1, in NameError: name 'variable' is not defined >>> globals()[name] = "this is a bad idea, don't do it" >>> variable "this is a bad idea, don't do it" Here's another way: >>> del variable >>> exec("%s = 'this is an even worse idea, be careful with this'" % name) >>> variable 'this is an even worse idea, be careful with this' Seriously, you probably shouldn't do this. The first is harmful because it leads to confusing, complicated, unclear code that is hard to maintain; the second is harmful for the same reasons, *plus* it is slower, AND could lead to serious security bugs. Google on "code injection attack" for more information. (There are uses for these techniques, or at least similar techniques, but they are rare, fairly advanced, and quite specialised.) -- Steven From post at andre-bell.de Mon Dec 20 05:33:56 2010 From: post at andre-bell.de (Andre Alexander Bell) Date: Mon, 20 Dec 2010 11:33:56 +0100 Subject: Dynamic list name from a string In-Reply-To: <48c5eb62-b011-4ff6-ad1e-be92abe2e2eb@o4g2000yqd.googlegroups.com> References: <48c5eb62-b011-4ff6-ad1e-be92abe2e2eb@o4g2000yqd.googlegroups.com> Message-ID: <4D0F3114.5030107@andre-bell.de> Hello, On 12/20/2010 11:08 AM, MarcoS wrote: > Hi, I need to create a list with a dynamic name, something like this: > > '%s_list' %my_dynamic list = [] > > It's this possible? I would suggest you use a dictionary to store your lists like this: lists = {} lists[my_dynamic_list] = [] Maybe you tell us some more what you want to achieve... Regards Andre From pscott at uwc.ac.za Mon Dec 20 05:39:04 2010 From: pscott at uwc.ac.za (Paul Scott) Date: Mon, 20 Dec 2010 12:39:04 +0200 Subject: How can I intentionally crash my lappy? In-Reply-To: <4D0F179E.4050704@gmail.com> References: <4D0F179E.4050704@gmail.com> Message-ID: <4D0F3248.3010901@uwc.ac.za> On 20/12/2010 10:45, mechtheist wrote: > I am no programmer, but know the rudiments [the rudi'est of rudiments] > of working with Python. I have a simple need, to have a simple > script/app I can run that will crash my PC. On my desktops, I can > always hit the reset, but that is not an option with my laptop. Can > anyone tell me of an easy way to guarantee a program will instantly > kill/BSOD my windows7/64bit laptop? You could try a forkbomb and execute that via a system call. Not sure why anyone would want to do such a thing, but there you go... -- -- Paul http://www.paulscott.za.net http://twitter.com/paulscott56 http://avoir.uwc.ac.za -------------- next part -------------- All Email originating from UWC is covered by disclaimer http://www.uwc.ac.za/portal From hniksic at xemacs.org Mon Dec 20 05:57:43 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Mon, 20 Dec 2010 11:57:43 +0100 Subject: "encoding" attribute codecs.getwriter-produced streams Message-ID: <87ei9cd848.fsf@xemacs.org> Try this code: # foo.py import sys, codecs stream = codecs.getwriter('utf-8')(sys.stdout) print stream.encoding $ python foo.py | cat None I expected the `encoding' attribute to be "UTF-8", since the stream otherwise correctly functions as a utf-8 encoding stream. Is this a bug in the stream factory returned by codecs.getwriter(...)? If not, is there another way to determine a stream's output encoding that would work for both default and codecs-created streams? From marc.sedda at gmail.com Mon Dec 20 06:38:31 2010 From: marc.sedda at gmail.com (MarcoS) Date: Mon, 20 Dec 2010 03:38:31 -0800 (PST) Subject: Dynamic list name from a string References: <48c5eb62-b011-4ff6-ad1e-be92abe2e2eb@o4g2000yqd.googlegroups.com> Message-ID: <87ec1487-e42d-4f9b-8d70-cb615e123007@k25g2000vbl.googlegroups.com> Ok, thanks Steven and Andre for yours reply. This is my situation: I've a list of objects of differents classes, with a common attribute name Something like this: class Object1: obj1_name .... other fields date class Object2: obj2_name .... other fields date ... class ObjectN: objN_name .... other fields date the lists are created dynamically at runtime, depending or not if there one or more correspondig Objects, ex. list_object1 = [object1_1, object1_2 ... object1_n] ... list_objectN = [object2_1, object2_2 ... object2_n] Then i need to include all into one global list sorting the various objects by date ex global_list = [object1_1, object2_n, object1_2 ... etc] I think that Andre solution it's the best way to solve my dynamics lists problem, now I'll verify how to create the global list and sort it From rob at beyondyourken.com Mon Dec 20 06:56:35 2010 From: rob at beyondyourken.com (rob) Date: Mon, 20 Dec 2010 05:56:35 -0600 Subject: How can I intentionally crash my lappy? In-Reply-To: <55d991ae7a5068ee10a3637b2330b5c4-EhVcX1lJRApWRxoDCzpQCEFddQZLVF5dQUBFCzBYWENGU1kWXlpwH1RcWzBeQ0wAV1leRF5Q-webmailer1@server02.webmailer.hosteurope.de> References: <4D0F179E.4050704@gmail.com> <55d991ae7a5068ee10a3637b2330b5c4-EhVcX1lJRApWRxoDCzpQCEFddQZLVF5dQUBFCzBYWENGU1kWXlpwH1RcWzBeQ0wAV1leRF5Q-webmailer1@server02.webmailer.hosteurope.de> Message-ID: <4D0F4473.9070703@beyondyourken.com> Thanks, that is exactly what I was looking for. Unfortunately, it is only for /non/-USB keyboards, I may be able to figure something out from there with hotkey or something. On 12/20/2010 3:31 AM, Stefan Sonnenberg-Carstens wrote: > http://pcsupport.about.com/od/tipstricks/ht/makebsodxp.htm > Am Mo, 20.12.2010, 09:45 schrieb mechtheist: >> I am no programmer, but know the rudiments [the rudi'est of rudiments] >> of working with Python. I have a simple need, to have a simple >> script/app I can run that will crash my PC. On my desktops, I can >> always hit the reset, but that is not an option with my laptop. Can >> anyone tell me of an easy way to guarantee a program will instantly >> kill/BSOD my windows7/64bit laptop? >> >> Any help is much appreciated. >> -- >> http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From rob at beyondyourken.com Mon Dec 20 07:15:10 2010 From: rob at beyondyourken.com (rob) Date: Mon, 20 Dec 2010 06:15:10 -0600 Subject: How can I intentionally crash my lappy? In-Reply-To: <4d0f2e69$0$29966$c3e8da3$5496439d@news.astraweb.com> References: <4d0f2e69$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4D0F48CE.8010608@beyondyourken.com> On 12/20/2010 4:22 AM, Steven D'Aprano wrote: > On Mon, 20 Dec 2010 02:45:18 -0600, mechtheist wrote: > >> I am no programmer, but know the rudiments [the rudi'est of rudiments] >> of working with Python. I have a simple need, to have a simple >> script/app I can run that will crash my PC. On my desktops, I can >> always hit the reset, but that is not an option with my laptop. Can >> anyone tell me of an easy way to guarantee a program will instantly >> kill/BSOD my windows7/64bit laptop? >> >> Any help is much appreciated. > You realise that the operating system (yes, even Windows!) is designed to > *not* crash no matter what the application does? > > (The OS may live up to that requirement imperfectly, but still, it tries.) > > > You'll probably find that task easier from C than from Python. But if I > were to attempt such a strange thing, I'd try to shut down some critical > processes used by the OS. I'm not much of a Windows person, but if you > call up the task manager (ctrl-alt-del) and inspect the process list, > then find one that causes the machine to crash if you shut it down, you > can probably do the same thing from a script. Thank you, good approach ideas there. Windows has gotten a lot better about crashing, but it is definitely still way the f 'imperfect'. Now I just have to figure a way to make it imperfecter. From duncan.booth at invalid.invalid Mon Dec 20 07:58:43 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 20 Dec 2010 12:58:43 GMT Subject: True lists in python? References: <4d0dc70d$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: Vito 'ZeD' De Tullio wrote: > Steven D'Aprano wrote: > >> I can't see any way to go from this linked list: >> >> node1 -> node2 -> node3 -> node4 -> node5 -> node6 -> node7 >> >> to this: >> >> node1 -> node6 -> node5 -> node4 -> node3 -> node2 -> node7 >> >> in constant time. You have to touch each of the nodes being reversed. > > very crude example: > No, you just showed how you can reverse an entire list in constant time. The original question and Steven's example were asking to reverse just part of the list. I guess you might be able to do it with a double-linked list provided that when traversing the list you always keep two nodes around to determine the direction. e.g. instead of asking for node6.nextNode() you ask for node6.nextNode(previous=node1) and then the code can return whichever sibling wasn't given. That would make reversal (assuming you have both nodes) O(1), but would make traversing the list slower. Also, I don't think it would help if you wanted to implement John Nagle's algorithm for the travelling salesman problem: you could hold a separate (array based) list of nodes in order to make the random selection O(1), but you wouldn't know which direction to follow from each node when it comes to cutting the list into 3. -- Duncan Booth http://kupuguy.blogspot.com From lists at cheimes.de Mon Dec 20 09:09:58 2010 From: lists at cheimes.de (Christian Heimes) Date: Mon, 20 Dec 2010 15:09:58 +0100 Subject: How can I intentionally crash my lappy? In-Reply-To: <4D0F179E.4050704@gmail.com> References: <4D0F179E.4050704@gmail.com> Message-ID: Am 20.12.2010 09:45, schrieb mechtheist: > I am no programmer, but know the rudiments [the rudi'est of rudiments] > of working with Python. I have a simple need, to have a simple > script/app I can run that will crash my PC. On my desktops, I can > always hit the reset, but that is not an option with my laptop. Can > anyone tell me of an easy way to guarantee a program will instantly > kill/BSOD my windows7/64bit laptop? Do you want to crash it or are you looking for a way to restart Windows? Every modern operating system tries very hard (and successful) to prevent users from messing with the system. You have two choices. Either you ask the OS politely to restart (e.g. shutdown -r -f -t 1) or you need some sort of STONITH device (e.g. IPMI card, watchdog, other node fencing device, multi-plug with network interface). Christian From eric.frederich at gmail.com Mon Dec 20 10:23:02 2010 From: eric.frederich at gmail.com (Eric Frederich) Date: Mon, 20 Dec 2010 10:23:02 -0500 Subject: Creating custom types from C code In-Reply-To: References: Message-ID: Thanks for the reply. I remember reading about named tuples when they were back-ported to the 2.X series but I never played with them. Is there a way to instantiate a named tuple from C code? Maybe I'm over-thinking this whole thing. Is there a simple way that I can define a class in Python and instantiate that type from C? On Sat, Dec 18, 2010 at 1:18 AM, Stefan Behnel wrote: > Eric Frederich, 17.12.2010 23:58: >> >> I have an extension module for a 3rd party library in which I am >> wrapping some structures. >> My initial attempt worked okay on Windows but failed on Linux. >> I was doing it in two parts. >> The first part on the C side of things I was turning the entire >> structure into a char array. >> The second part in Python code I would unpack the structure. >> >> Anyway, I decided I should be doing things a little cleaner so I read >> up on "Defining New Types" >> http://docs.python.org/extending/newtypes.html >> >> I got it to work but I'm not sure how to create these new objects from C. > > You may want to take a look at Cython. It makes writing C extensions easy. > For one, it will do all sorts of type conversions for you, and do them > efficiently and safely (you get an exception on overflow, for example). It's > basically Python, so creating classes and instantiating them is trivial. > > Also note that it's generally not too much work to rewrite an existing C > wrapper in Cython, but it's almost always worth it. You immediately get more > maintainable code that's much easier to extend and work on. It's also often > faster than hand written code. > > http://cython.org > > >> My setup is almost exactly like the example on that page except >> instead of 2 strings and an integer I have 5 unsigned ints. >> >> I do not expect to ever be creating these objects in Python. ?They >> will only be created as return values from my wrapper functions to the >> 3rd party library. > > In Cython 0.14, you can declare classes as "final" and "internal" using a > decorator, meaning that they cannot be subtyped from Python and do not show > up in the module dict. However, note that there is no way to prevent users > from getting their hands at the type once you give them an instance. > > >> I could return a tuple from those functions but I want to use dot >> notation (e.g. somestruct.var1). > > Then __getattr__ or properties are your friend. > > >> So, question number 1: >> ? ? Is defining my own type like that overkill just to have an object >> to access using dots? > > Creating wrapper objects is totally normal. > > Also note that recent Python versions have named tuples, BTW. > > >> ? ? I'll never create those objects from Python. >> ? ? Is there a shortcut to creating objects and setting attributes >> from within C? > > The Cython code for instantiating classes is identical to Python. > > >> In any case, I was able to create my own custom object from C code like >> so... >> >> ? ? PyObject *foo(SomeCStruct bar){ >> ? ? ? ? PyObject *ret; >> ? ? ? ? ret = _PyObject_New(&mymodule_SomeStructType); >> ? ? ? ? PyObject_SetAttrString(ret, "var1" , Py_BuildValue("I", bar.var1 >> )); >> ? ? ? ? PyObject_SetAttrString(ret, "var2" , Py_BuildValue("I", bar.var2 >> )); >> ? ? ? ? PyObject_SetAttrString(ret, "var3" , Py_BuildValue("I", bar.var3 >> )); >> ? ? ? ? PyObject_SetAttrString(ret, "var4" , Py_BuildValue("I", bar.var4 >> )); >> ? ? ? ? PyObject_SetAttrString(ret, "var5" , Py_BuildValue("I", bar.var5 >> )); >> ? ? ? ? return ret; >> ? ? } >> >> When using _PyObject_New I notice that neither my new or init function >> are ever called. >> I verified that they are getting called when creating the object from >> Python > > Things often work a little different in Python and C. Directly calling > _PyObject_New() is a lot less than what Python does internally. The > canonical way is to PyObject_Call() the type (or to use one of the other > call functions, depending on what your arguments are). > > >> (which I would never do anyway). > > Your users could do it, though, so you should make sure that won't crash the > interpreter that way by leaving internal data fields uninitialised. > > >> Question number 2: >> ? ? Do I need to be calling PyObject_SetAttrString or is there a way >> to set the unsigned ints on the structure direcly? >> ? ? It seems overkill to create a Python object for an unsigned int >> just to set it as an attribute on a custom defined type. > > You will have to do it at some point, though, either at instantiation time > or at Python access time. Depending on the expected usage, either of the two > can be more wasteful. > > >> Question number 3: >> ? ? In the above code, is there a memory leak? ?Should I be >> Py_DECREF'ing the return value from Py_BuildValue after I'm done using >> it. > > You can look that up in the C-API docs. If a function doesn't say that it > "steals" a reference, you still own the reference when it returns and have > to manually decref it (again, a thing that you won't usually have to care > about in Cython). So, yes, the above leaks one reference for each call to > Py_BuildValue(). > > Stefan > > -- > http://mail.python.org/mailman/listinfo/python-list > From stefan_ml at behnel.de Mon Dec 20 11:44:27 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 20 Dec 2010 17:44:27 +0100 Subject: Creating custom types from C code Message-ID: Eric Frederich, 20.12.2010 16:23: > I remember reading about named tuples when they were back-ported to the > 2.X series but I never played with them. Is there a way to instantiate a > named tuple from C code? There isn't a dedicated C-API for named tuples, but you can instantiate any Python type from C code. > Maybe I'm over-thinking this whole thing. Is there a simple way that I > can define a class in Python and instantiate that type from C? Sure, see my previous comments to your original mail. Stefan From lewisr2 at verizon.net Mon Dec 20 12:10:10 2010 From: lewisr2 at verizon.net (lewisr2 at verizon.net) Date: Mon, 20 Dec 2010 11:10:10 -0600 (CST) Subject: Questions Message-ID: <31346077.1045081.1292865010237.JavaMail.root@vznit170128> An HTML attachment was scrubbed... URL: From givenrandy at gmail.com Mon Dec 20 12:33:08 2010 From: givenrandy at gmail.com (Randy Given) Date: Mon, 20 Dec 2010 12:33:08 -0500 Subject: Python-list Digest, Vol 87, Issue 122 In-Reply-To: References: Message-ID: ZS On Dec 19, 2010 6:05 AM, wrote: > Send Python-list mailing list submissions to > python-list at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.python.org/mailman/listinfo/python-list > or, via email, send a message with subject or body 'help' to > python-list-request at python.org > > You can reach the person managing the list at > python-list-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Python-list digest..." -------------- next part -------------- An HTML attachment was scrubbed... URL: From givenrandy at gmail.com Mon Dec 20 12:33:15 2010 From: givenrandy at gmail.com (Randy Given) Date: Mon, 20 Dec 2010 12:33:15 -0500 Subject: Python-list Digest, Vol 87, Issue 122 In-Reply-To: References: Message-ID: as On Dec 19, 2010 6:05 AM, wrote: > Send Python-list mailing list submissions to > python-list at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.python.org/mailman/listinfo/python-list > or, via email, send a message with subject or body 'help' to > python-list-request at python.org > > You can reach the person managing the list at > python-list-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Python-list digest..." -------------- next part -------------- An HTML attachment was scrubbed... URL: From mpnordland at gmail.com Mon Dec 20 12:54:21 2010 From: mpnordland at gmail.com (mpnordland) Date: Mon, 20 Dec 2010 09:54:21 -0800 (PST) Subject: Catching user switching and getting current active user from root on linux In-Reply-To: Message-ID: <3d190cbf-be7d-4973-b85f-c030bb258742@glegroupsg2000goo.googlegroups.com> I give up, I will never try to use a usenet group again. For the ones of you who tried to help thank you. You helped to identify some of my troubles, as for you @usernet, you are a troll From mrjean1 at gmail.com Mon Dec 20 12:58:56 2010 From: mrjean1 at gmail.com (MrJean1) Date: Mon, 20 Dec 2010 09:58:56 -0800 (PST) Subject: how to measure TCP congestion windows using python ?? References: Message-ID: <2909f9a2-fb78-45d6-845f-5d93f342125e@g25g2000yqn.googlegroups.com> FWIW, on CentOS 4.7, the ctypes version works fine, but the struct version fails, because len(tcp_info) is only 100 bytes while struct.calcsize('B...L') is 104. However, if the format is changed to '7B23L', i.e. one 'L' shorter, the struct version works and returns to same result as the ctypes version. /Jean On Dec 19, 4:45?pm, plz wrote: > hi > many thanks for helping me > i also tried to manipulate it last night > here is my code... > > import socket > import struct > > sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM) > tcp_info = sock.getsockopt(socket.SOL_TCP, socket.TCP_INFO, struct.calcsize('BBBBBBBLLLLLLLLLLLLLLLLLLLLLLLL')) > print struct.unpack('BBBBBBBLLLLLLLLLLLLLLLLLLLLLLLL', tcp_info) > > the result of struct.unpack of tcp_info is following > in /usr/include/linux/tcp.h > used Linux Redhat and Python 2.7 > > anyway your code is very useful > Thxs again ;) From anurag.chourasia at gmail.com Mon Dec 20 13:31:44 2010 From: anurag.chourasia at gmail.com (Anurag Chourasia) Date: Tue, 21 Dec 2010 00:01:44 +0530 Subject: **** httplib.InvalidURL: nonnumeric port **** Message-ID: All, When i try to open a URL of the form http://joule:8041/DteEnLinea/ws/EnvioGuia.jws, I am getting an error as below complaining for some non-numeric port. wm (wmosds) [zibal] - /u01/home/apli/wm/app/gdd :>python Python 2.4.1 (#2, May 30 2005, 09:40:30) [C] on aix5 Type "help", "copyright", "credits" or "license" for more information. >>> import httplib, mimetypes >>> h = httplib.HTTP('http://joule:8041/DteEnLinea/ws/EnvioGuia.jws') Traceback (most recent call last): File "", line 1, in ? File "/u01/home/apli/wm/python241/lib/python2.4/httplib.py", line 1093, in __init__ self._setup(self._connection_class(host, port, strict)) File "/u01/home/apli/wm/python241/lib/python2.4/httplib.py", line 582, in __init__ self._set_hostport(host, port) File "/u01/home/apli/wm/python241/lib/python2.4/httplib.py", line 594, in _set_hostport raise InvalidURL("nonnumeric port: '%s'" % host[i+1:]) httplib.InvalidURL: nonnumeric port: '8041/DteEnLinea/ws/EnvioGuia.jws' How could we avoid this problem? Regards, Anurag -------------- next part -------------- An HTML attachment was scrubbed... URL: From anurag.chourasia at gmail.com Mon Dec 20 13:58:52 2010 From: anurag.chourasia at gmail.com (Anurag Chourasia) Date: Tue, 21 Dec 2010 00:28:52 +0530 Subject: Sending XML to a WEB Service and Getting Response Back Message-ID: Dear Python Mates, I have a requirement to send a XML Data to a WEB Service whose URL is of the form http://joule:8041/DteEnLinea/ws/EnvioGuia.jws I also have to read back the response returned as a result of sending this data to this WebService. This web service implements the following operations: sendNCR This web service has no callbacks. I have pasted the complete WSDL for this WEB Service below my email. I would appreciate if someone could guide me with sample code using a Python Library suitable to fulfill this requirement of mine. Regards, Anurag -------------- next part -------------- An HTML attachment was scrubbed... URL: From kevin.p.dwyer at gmail.com Mon Dec 20 14:12:41 2010 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Mon, 20 Dec 2010 19:12:41 +0000 (UTC) Subject: **** httplib.InvalidURL: nonnumeric port **** References: Message-ID: On Tue, 21 Dec 2010 00:01:44 +0530, Anurag Chourasia wrote: >>> import httplib >>> help(httplib.HTTP) Help on class HTTP in module httplib: class HTTP | Compatibility class with httplib.py from 1.5. | | Methods defined here: | | __init__(self, host='', port=None, strict=None) The constructor doesn't take a complete URL as an argument. Also, shouldn't you be using httplib.HTTPConnection? The docs state that httplib.HTTP is for backward compatibility only. Kev From tyler at tysdomain.com Mon Dec 20 14:14:12 2010 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Mon, 20 Dec 2010 12:14:12 -0700 Subject: help with link parsing? Message-ID: <4D0FAB04.6010307@tysdomain.com> Hello all, I have a question. I guess this worked pre 2.6; I don't remember the last time I used it, but it was a while ago, and now it's failing. Anyone mind looking at it and telling me what's going wrong? Also, is there a quick way to match on a certain site? like links from google.com and only output those? #!/usr/bin/env python #This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published #by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. #This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. # #You should have received a copy of the GNU General Public License along with this program. If not, see #http://www.gnu.org/licenses/. """ This script will parse out all the links in an html document and write them to a textfile. """ import sys,optparse import htmllib,formatter #program class declarations: class Links(htmllib.HTMLParser): def __init__(self,formatter): htmllib.HTMLParser.__init__(self, formatter) self.links=[] def start_a(self, attrs): if (len(attrs)>0): for a in attrs: if a[0]=="href": self.links.append(a[1]) print a[1] break def main(argv): if (len(argv)!=3): print("Error:\n"+argv[0]+" .\nParses for all links and saves them to .") return 1 lcount=0 format=formatter.NullFormatter() html=Links(format) print "Retrieving data:" page=open(argv[1],"r") print "Feeding data to parser:" html.feed(page.read()) page.close() print "Writing links:" output=open(argv[2],"w") for i in (html.links): output.write(i+"\n") lcount+=1 output.close() print("Wrote "+str(lcount)+" links to "+argv[2]+"."); print("done.") if (__name__ == "__main__"): #we call the main function passing a list of args, and exit with the return code passed back. sys.exit(main(sys.argv)) -- Thanks, Ty From anurag.chourasia at gmail.com Mon Dec 20 14:30:36 2010 From: anurag.chourasia at gmail.com (Anurag Chourasia) Date: Tue, 21 Dec 2010 01:00:36 +0530 Subject: **** httplib.InvalidURL: nonnumeric port **** In-Reply-To: References: Message-ID: Hi Kevin, Thanks for the response. I tried with HTTPConnection but the same problem. >>> h1 = httplib.HTTPConnection(' http://joule:8041/DteEnLinea/ws/EnvioGuia.jws') Traceback (most recent call last): File "", line 1, in ? File "/u01/home/apli/wm/python241/lib/python2.4/httplib.py", line 582, in __init__ self._set_hostport(host, port) File "/u01/home/apli/wm/python241/lib/python2.4/httplib.py", line 594, in _set_hostport raise InvalidURL("nonnumeric port: '%s'" % host[i+1:]) httplib.InvalidURL: nonnumeric port: '8041/DteEnLinea/ws/EnvioGuia.jws' Do i need to use some other library to be able to send XML Data (and get a response back) to this Kind of Web Service address i.e. http://joule:8041/DteEnLinea/ws/EnvioGuia.jws ? Regards, Anurag On Tue, Dec 21, 2010 at 12:42 AM, Kev Dwyer wrote: > On Tue, 21 Dec 2010 00:01:44 +0530, Anurag Chourasia wrote: > > >>> import httplib > >>> help(httplib.HTTP) > Help on class HTTP in module httplib: > > class HTTP > | Compatibility class with httplib.py from 1.5. > | > | Methods defined here: > | > | __init__(self, host='', port=None, strict=None) > > The constructor doesn't take a complete URL as an argument. > > Also, shouldn't you be using httplib.HTTPConnection? The docs > state that httplib.HTTP is for backward compatibility only. > > Kev > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ashish.makani at gmail.com Mon Dec 20 14:34:14 2010 From: ashish.makani at gmail.com (spaceman-spiff) Date: Mon, 20 Dec 2010 11:34:14 -0800 (PST) Subject: Trying to parse a HUGE(1gb) xml file Message-ID: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> Hi c.l.p folks This is a rather long post, but i wanted to include all the details & everything i have tried so far myself, so please bear with me & read the entire boringly long post. I am trying to parse a ginormous ( ~ 1gb) xml file. 0. I am a python & xml n00b, s& have been relying on the excellent beginner book DIP(Dive_Into_Python3 by MP(Mark Pilgrim).... Mark , if u are readng this, you are AWESOME & so is your witty & humorous writing style) 1. Almost all exmaples pf parsing xml in python, i have seen, start off with these 4 lines of code. import xml.etree.ElementTree as etree tree = etree.parse('*path_to_ginormous_xml*') root = tree.getroot() #my huge xml has 1 root at the top level print root 2. In the 2nd line of code above, as Mark explains in DIP, the parse function builds & returns a tree object, in-memory(RAM), which represents the entire document. I tried this code, which works fine for a small ( ~ 1MB), but when i run this simple 4 line py code in a terminal for my HUGE target file (1GB), nothing happens. In a separate terminal, i run the top command, & i can see a python process, with memory (the VIRT column) increasing from 100MB , all the way upto 2100MB. I am guessing, as this happens (over the course of 20-30 mins), the tree representing is being slowly built in memory, but even after 30-40 mins, nothing happens. I dont get an error, seg fault or out_of_memory exception. My hardware setup : I have a win7 pro box with 8gb of RAM & intel core2 quad cpuq9400. On this i am running sun virtualbox(3.2.12), with ubuntu 10.10 as guest os, with 23gb disk space & 2gb(2048mb) ram, assigned to the guest ubuntu os. 3. I also tried using lxml, but an lxml tree is much more expensive, as it retains more info about a node's context, including references to it's parent. [http://www.ibm.com/developerworks/xml/library/x-hiperfparse/] When i ran the same 4line code above, but with lxml's elementree ( using the import below in line1of the code above) import lxml.etree as lxml_etree i can see the memory consumption of the python process(which is running the code) shoot upto ~ 2700mb & then, python(or the os ?) kills the process as it nears the total system memory(2gb) I ran the code from 1 terminal window (screenshot :http://imgur.com/ozLkB.png) & ran top from another terminal (http://imgur.com/HAoHA.png) 4. I then investigated some streaming libraries, but am confused - there is SAX[http://en.wikipedia.org/wiki/Simple_API_for_XML] , the iterparse interface[http://effbot.org/zone/element-iterparse.htm] Which one is the best for my situation ? Any & all code_snippets/wisdom/thoughts/ideas/suggestions/feedback/comments/ of the c.l.p community would be greatly appreciated. Plz feel free to email me directly too. thanks a ton cheers ashish email : ashish.makani domain:gmail.com p.s. Other useful links on xml parsing in python 0. http://diveintopython3.org/xml.html 1. http://stackoverflow.com/questions/1513592/python-is-there-an-xml-parser-implemented-as-a-generator 2. http://codespeak.net/lxml/tutorial.html 3. https://groups.google.com/forum/?hl=en&lnk=gst&q=parsing+a+huge+xml#!topic/comp.lang.python/CMgToEnjZBk 4. http://www.ibm.com/developerworks/xml/library/x-hiperfparse/ 5.http://effbot.org/zone/element-index.htm http://effbot.org/zone/element-iterparse.htm 6. SAX : http://en.wikipedia.org/wiki/Simple_API_for_XML From tjreedy at udel.edu Mon Dec 20 14:40:22 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 20 Dec 2010 14:40:22 -0500 Subject: Questions In-Reply-To: <31346077.1045081.1292865010237.JavaMail.root@vznit170128> References: <31346077.1045081.1292865010237.JavaMail.root@vznit170128> Message-ID: On 12/20/2010 12:10 PM, lewisr2 at verizon.net wrote: > 3. I have used Tk in the past with Tcl and IncrTcl. Where can I find a > lot of Python/Tk examples so that I can save some time in developing GUIs? Do a search, or possibly a google codesearch, on tkinter or Tkinter, which is Python's tk inter(face). In fact, search the archive of python-list (or gmane's mirror) for posted examples. -- Terry Jan Reedy From clp2 at rebertia.com Mon Dec 20 14:45:45 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 20 Dec 2010 11:45:45 -0800 Subject: **** httplib.InvalidURL: nonnumeric port **** In-Reply-To: References: Message-ID: > On Tue, Dec 21, 2010 at 12:42 AM, Kev Dwyer wrote: >> On Tue, 21 Dec 2010 00:01:44 +0530, Anurag Chourasia wrote: >> >>> import httplib >> >>> help(httplib.HTTP) >> Help on class HTTP in module httplib: >> >> class HTTP >> ?| ?Compatibility class with httplib.py from 1.5. >> ?| >> ?| ?Methods defined here: >> ?| >> ?| ?__init__(self, host='', port=None, strict=None) >> >> The constructor doesn't take a complete URL as an argument. >> >> Also, shouldn't you be using httplib.HTTPConnection? ?The docs >> ?state that httplib.HTTP is for backward compatibility only. >> On Mon, Dec 20, 2010 at 11:30 AM, Anurag Chourasia wrote: > Hi Kevin, > Thanks for the response. > I tried with?HTTPConnection but the same problem. >>>> h1 = >>>> httplib.HTTPConnection('http://joule:8041/DteEnLinea/ws/EnvioGuia.jws') > Traceback (most recent call last): > ??File "", line 1, in ? > ??File "/u01/home/apli/wm/python241/lib/python2.4/httplib.py", line 582, in > __init__ > ?? ?self._set_hostport(host, port) > ??File "/u01/home/apli/wm/python241/lib/python2.4/httplib.py", line 594, in > _set_hostport > ?? ?raise InvalidURL("nonnumeric port: '%s'" % host[i+1:]) > httplib.InvalidURL: nonnumeric port: '8041/DteEnLinea/ws/EnvioGuia.jws' > Do i need to use some other library to be able to send XML Data (and get a > response back) to this Kind of Web Service address > i.e.?http://joule:8041/DteEnLinea/ws/EnvioGuia.jws?? > Regards, > Anurag (1) Please avoid top-posting (2) Did you read the other part of Kev's comment? "The constructor doesn't take a complete URL as an argument." You must pass only the domain to the constructor and then call .request() on the HTTPConnection object. (3) If you're using SOAP, try https://fedorahosted.org/suds/ Cheers, Chris -- http://blog.rebertia.com From awilliam at whitemice.org Mon Dec 20 14:49:46 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Mon, 20 Dec 2010 14:49:46 -0500 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> Message-ID: <1292874586.11975.8.camel@linux-yu4c.site> On Mon, 2010-12-20 at 11:34 -0800, spaceman-spiff wrote: > Hi c.l.p folks > This is a rather long post, but i wanted to include all the details & > everything i have tried so far myself, so please bear with me & read > the entire boringly long post. > I am trying to parse a ginormous ( ~ 1gb) xml file. Do that hundreds of times a day. > 0. I am a python & xml n00b, s& have been relying on the excellent > beginner book DIP(Dive_Into_Python3 by MP(Mark Pilgrim).... Mark , if > u are readng this, you are AWESOME & so is your witty & humorous > writing style) > 1. Almost all exmaples pf parsing xml in python, i have seen, start off with these 4 lines of code. > import xml.etree.ElementTree as etree > tree = etree.parse('*path_to_ginormous_xml*') > root = tree.getroot() #my huge xml has 1 root at the top level > print root Yes, this is a terrible technique; most examples are crap. > 2. In the 2nd line of code above, as Mark explains in DIP, the parse > function builds & returns a tree object, in-memory(RAM), which > represents the entire document. > I tried this code, which works fine for a small ( ~ 1MB), but when i > run this simple 4 line py code in a terminal for my HUGE target file > (1GB), nothing happens. > In a separate terminal, i run the top command, & i can see a python > process, with memory (the VIRT column) increasing from 100MB , all the > way upto 2100MB. Yes, this is using DOM. DOM is evil and the enemy, full-stop. > I am guessing, as this happens (over the course of 20-30 mins), the > tree representing is being slowly built in memory, but even after > 30-40 mins, nothing happens. > I dont get an error, seg fault or out_of_memory exception. You need to process the document as a stream of elements; aka SAX. > 3. I also tried using lxml, but an lxml tree is much more expensive, > as it retains more info about a node's context, including references > to it's parent. > [http://www.ibm.com/developerworks/xml/library/x-hiperfparse/] > When i ran the same 4line code above, but with lxml's elementree > ( using the import below in line1of the code above) > import lxml.etree as lxml_etree You're still using DOM; DOM is evil. > Which one is the best for my situation ? > Any & all > code_snippets/wisdom/thoughts/ideas/suggestions/feedback/comments/ of > the c.l.p community would be greatly appreciated. > Plz feel free to email me directly too. From clp2 at rebertia.com Mon Dec 20 14:52:30 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 20 Dec 2010 11:52:30 -0800 Subject: help with link parsing? In-Reply-To: <4D0FAB04.6010307@tysdomain.com> References: <4D0FAB04.6010307@tysdomain.com> Message-ID: On Mon, Dec 20, 2010 at 11:14 AM, Littlefield, Tyler wrote: > Hello all, > I have a question. I guess this worked pre 2.6; I don't remember the last > time I used it, but it was a while ago, and now it's failing. Anyone mind > looking at it and telling me what's going wrong? Please describe /exactly/ how it is failing for you, including the full exception traceback (if any). The script seems to work fine for me under both Python v2.6.6 and v2.7.1. Cheers, Chris -- http://blog.rebertia.com From kevin.p.dwyer at gmail.com Mon Dec 20 14:54:06 2010 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Mon, 20 Dec 2010 19:54:06 +0000 (UTC) Subject: **** httplib.InvalidURL: nonnumeric port **** References: Message-ID: On Tue, 21 Dec 2010 01:00:36 +0530, Anurag Chourasia wrote: Anurag, HTTPConnection takes a host and a port number as arguments, not just a URL. So you could construct your connection request like this: conn = httplib.HTTPConnection('joule', 8041) then use the request() method on the connection to make a PUT or GET request: conn.request('PUT', url, body, headers) Please read the documentation for the httplib module, and perhaps some basic material on how HTTP requests work. Cheers, Kev From usernet at ilthio.net Mon Dec 20 15:09:01 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 20 Dec 2010 20:09:01 +0000 (UTC) Subject: Trying to parse a HUGE(1gb) xml file References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> Message-ID: [Wrapped to meet RFC1855 Netiquette Guidelines] On 2010-12-20, spaceman-spiff wrote: > This is a rather long post, but i wanted to include all the details & > everything i have tried so far myself, so please bear with me & read > the entire boringly long post. > > I am trying to parse a ginormous ( ~ 1gb) xml file. [SNIP] > 4. I then investigated some streaming libraries, but am confused - there > is SAX[http://en.wikipedia.org/wiki/Simple_API_for_XML] , the iterparse > interface[http://effbot.org/zone/element-iterparse.htm] I have made extensive use of SAX and it will certainly work for low memory parsing of XML. I have never used "iterparse"; so, I cannot make an informed comparison between them. > Which one is the best for my situation ? Your posed was long but it failed to tell us the most important piece of information: What does your data look like and what are you trying to do with it? SAX is a low level API that provides a callback interface allowing you to processes various elements as they are encountered. You can therefore do anything you want to the information, as you encounter it, including outputing and discarding small chunks as you processes it; ignoring most of it and saving only what you want to memory data structures; or saving all of it to a more random access database or on disk data structure that you can load and process as required. What you need to do will depend on what you are actually trying to accomplish. Without knowing that, I can only affirm that SAX will work for your needs without providing any information about how you should be using it. From hidura at gmail.com Mon Dec 20 15:14:47 2010 From: hidura at gmail.com (Hidura) Date: Mon, 20 Dec 2010 16:14:47 -0400 Subject: Sending XML to a WEB Service and Getting Response Back In-Reply-To: References: Message-ID: I recommend you use the urllib.request in the library of python says everything that you want to know. 2010/12/20, Anurag Chourasia : > Dear Python Mates, > > I have a requirement to send a XML Data to a WEB Service whose URL is of the > form http://joule:8041/DteEnLinea/ws/EnvioGuia.jws > > I also have to read back the response returned as a result of sending this > data to this WebService. > > This web service implements the following operations: > sendNCR > > This web service has no callbacks. > > I have pasted the complete WSDL for this WEB Service below my email. > > I would appreciate if someone could guide me with sample code using a Python > Library suitable to fulfill this requirement of mine. > > Regards, > Anurag > > > > xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc=" > http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl=" > http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://www.openuri.org/"> > > elementFormDefault="qualified" targetNamespace="http://www.openuri.org/"> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > style="document"/> > > style="document"/> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- Enviado desde mi dispositivo m?vil Diego I. Hidalgo D. From ashish.makani at gmail.com Mon Dec 20 15:29:01 2010 From: ashish.makani at gmail.com (spaceman-spiff) Date: Mon, 20 Dec 2010 12:29:01 -0800 (PST) Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: Message-ID: Hi Usernet First up, thanks for your prompt reply. I will make sure i read RFC1855, before posting again, but right now chasing a hard deadline :) I am sorry i left out what exactly i am trying to do. 0. Goal :I am looking for a specific element..there are several 10s/100s occurrences of that element in the 1gb xml file. The contents of the xml, is just a dump of config parameters from a packet switch( although imho, the contents of the xml dont matter) I need to detect them & then for each 1, i need to copy all the content b/w the element's start & end tags & create a smaller xml file. 1. Can you point me to some examples/samples of using SAX, especially , ones dealing with really large XML files. 2.This brings me to another q. which i forgot to ask in my OP(original post). Is simply opening the file, & using reg ex to look for the element i need, a *good* approach ? While researching my problem, some article seemed to advise against this, especially since its known apriori, that the file is an xml & since regex code gets complicated very quickly & is not very readable. But is that just a "style"/"elegance" issue, & for my particular problem (detecting a certain element, & then creating(writing) a smaller xml file corresponding to, each pair of start & end tags of said element), is the open file & regex approach, something you would recommend ? Thanks again for your super-prompt response :) cheers ashish From awilliam at whitemice.org Mon Dec 20 15:33:45 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Mon, 20 Dec 2010 15:33:45 -0500 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: Message-ID: <1292877225.13462.8.camel@linux-yu4c.site> On Mon, 2010-12-20 at 12:29 -0800, spaceman-spiff wrote: > I need to detect them & then for each 1, i need to copy all the > content b/w the element's start & end tags & create a smaller xml > file. Yep, do that a lot; via iterparse. > 1. Can you point me to some examples/samples of using SAX, > especially , ones dealing with really large XML files. SaX is equivalent to iterparse (iterpase is a way, to essentially, do SaX-like processing). I provided an iterparse example already. See the Read_Rows method in > 2.This brings me to another q. which i forgot to ask in my OP(original post). > Is simply opening the file, & using reg ex to look for the element i need, a *good* approach ? No. From Martin at Hvidberg.net Mon Dec 20 16:08:20 2010 From: Martin at Hvidberg.net (Martin Hvidberg) Date: Mon, 20 Dec 2010 22:08:20 +0100 Subject: Why do my list go uni-code by itself? Message-ID: <4D0FC5C4.3060008@Hvidberg.net> I'm reading a fixed format text file, line by line. I hereunder present the code. I have out part not related to the file reading. Only relevant detail left out is the lstCutters. It looks like this: [[1, 9], [11, 21], [23, 48], [50, 59], [61, 96], [98, 123], [125, 150]] It specifies the first and last character position of each token in the fixed format of the input line. All this works fine, and is only to explain where I'm going. The code, in the function definition, is broken up in more lines than necessary, to be able to monitor the variables, step by step. --- Code start ------ import codecs def CutLine2List(strIn,lstCut): strIn = strIn.strip() print '>InNextLine>',strIn # skip if line is empty if len(strIn)<1: return False lstIn = list() for cc in lstCut: strSubline =strIn[cc[0]-1:cc[1]-1].strip() lstIn.append(strSubline) print '>InSubline2>'+lstIn[len(lstIn)-1]+'<' del strIn, lstCut,cc print '>InReturLst>',lstIn return lstIn filIn = codecs.open( strFileNameIn, mode='r', encoding='utf-8', errors='strict', buffering=1) for linIn in filIn: lstIn = CutLine2List(linIn,lstCutters) --- Code end ------ A sample output, representing one line from the input file looks like this: >InNextLine> I 30 2002-12-11 20:01:19.280 563 FAN? 2001-12-12-15.46.12.734502 2001-12-12-15.46.12.734502 >InSubline2>I< >InSubline2>30< >InSubline2>2002-12-11 20:01:19.280< >InSubline2>563< >InSubline2>FAN?< >InSubline2>2001-12-12-15.46.12.73450< >InSubline2>2001-12-12-15.46.12.73450< >InReturLst> [u'I', u'30', u'2002-12-11 20:01:19.280', u'563', u'FAN\xd8', u'2001-12-12-15.46.12.73450', u'2001-12-12-15.46.12.73450'] Question: In the last printout, tagged >InReturLst> all entries turn into uni-code. What happens here? Look for the word 'FAN?'. This word changes from 'FAN?' to u'FAN\xd8' -- That's a problem to me, and I don't want it to change like this. What do I do to stop this behavior? Best Regards Martin -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Mon Dec 20 16:30:20 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 20 Dec 2010 16:30:20 -0500 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: <1292874586.11975.8.camel@linux-yu4c.site> References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <1292874586.11975.8.camel@linux-yu4c.site> Message-ID: On 12/20/2010 2:49 PM, Adam Tauno Williams wrote: > > Yes, this is a terrible technique; most examples are crap. > Yes, this is using DOM. DOM is evil and the enemy, full-stop. > You're still using DOM; DOM is evil. For serial processing, DOM is superfluous superstructure. For random access processing, some might disagree. > >> Which one is the best for my situation ? >> Any& all >> code_snippets/wisdom/thoughts/ideas/suggestions/feedback/comments/ of >> the c.l.p community would be greatly appreciated. >> Plz feel free to email me directly too. > > > > For Python (unlike Java), wrapping module functions as class static methods is superfluous superstructure that only slows things down. raise Exception(...) # should be something specific like raise ValueError(...) -- Terry Jan Reedy From usernet at ilthio.net Mon Dec 20 16:37:48 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 20 Dec 2010 21:37:48 +0000 (UTC) Subject: Trying to parse a HUGE(1gb) xml file References: Message-ID: On 2010-12-20, spaceman-spiff wrote: > 0. Goal :I am looking for a specific element..there are several 10s/100s > occurrences of that element in the 1gb xml file. The contents of the xml, > is just a dump of config parameters from a packet switch( although imho, > the contents of the xml dont matter) Then you need: 1. To detect whenever you move inside of the type element you are seeking and whenever you move out of it. As long as these elements cannot be nested inside of each other, this is an easy binary task. If they can be nested, then you will need to maintain some kind of level count or recursively decompose each level. 2. Once you have obtained a complete element (from its start tag to its end tag) you will need to test whether you have the single correct element that you are looking for. Something like this (untested) will work if the target tag cannot be nested in another target tag: - import xml.sax - class tagSearcher(xml.sax.ContentHandler): - - def startDocument(): - self.inTarget = False - - def startElement(name, attrs): - if name == targetName: - self.inTarget = True - elif inTarget = True: - # save element information - - def endElement(name): - if name == targetName: - self.inTarget = False - # test the saved information to see if you have the - # one you want: - # - # if its the peice you are looking for, then - # you can process the information - # you have saved - # - # if not, disgard the accumulated - # information and move on - - def characters(content): - if self.inTarget == True: - # save the content - - yourHandler = tagSearcher() - yourParser = xml.sax.make_parser() - yourParser.parse(inputXML, yourHandler) Then you just walk through the document picking up and discarding each target element type until you have the one that you are looking for. > I need to detect them & then for each 1, i need to copy all the content > b/w the element's start & end tags & create a smaller xml file. Easy enough; but, with SAX you will have to recreate the tags from the information that they contain because they will be skipped by the character() events; so you will need to save the information from each tag as you come across it. This could probably be done more automatically using saxutils.XMLGenerator; but, I haven't actually worked with it before. xml.dom.pulldom also looks interesting > 1. Can you point me to some examples/samples of using SAX, especially , > ones dealing with really large XML files. There is nothing special about large files with SAX. Sax is very simple. It walks through the document and calls the the functions that you give it for each event as it reaches varius elements. Your callback functions (methods of a handler) do everthing with the information. SAX does nothing more then call your functions. There are events for reaching a starting tag, an end tag, and characters between tags; as well as some for beginning and ending a document. > 2.This brings me to another q. which i forgot to ask in my OP(original > post). Is simply opening the file, & using reg ex to look for the element > i need, a *good* approach ? While researching my problem, some article > seemed to advise against this, especially since its known apriori, that > the file is an xml & since regex code gets complicated very quickly & > is not very readable. > > But is that just a "style"/"elegance" issue, & for my particular problem > (detecting a certain element, & then creating(writing) a smaller xml > file corresponding to, each pair of start & end tags of said element), > is the open file & regex approach, something you would recommend ? It isn't an invalid approach if it works for your situatuation. I have used it before for very simple problems. The thing is, XML is a context free data format which makes it difficult to generate precise regular expressions, especially where where tags of the same type can be nested. It can be very error prone. Its really easy to have a regex work for your tests and fail, either by matching too much or failing to match, because you didn't anticipate a given piece of data. I wouldn't consider it a robust solution. From python at mrabarnett.plus.com Mon Dec 20 16:41:10 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 20 Dec 2010 21:41:10 +0000 Subject: Why do my list go uni-code by itself? In-Reply-To: <4D0FC5C4.3060008@Hvidberg.net> References: <4D0FC5C4.3060008@Hvidberg.net> Message-ID: <4D0FCD76.8000703@mrabarnett.plus.com> > I'm reading a fixed format text file, line by line. I hereunder present the code. I have out part not related to the file reading. > Only relevant detail left out is the lstCutters. It looks like this: > [[1, 9], [11, 21], [23, 48], [50, 59], [61, 96], [98, 123], [125, 150]] > It specifies the first and last character position of each token in the fixed format of the input line. > All this works fine, and is only to explain where I'm going. > > The code, in the function definition, is broken up in more lines than necessary, to be able to monitor the variables, step by step. > > --- Code start ------ > > import codecs > > > > def CutLine2List(strIn,lstCut): > strIn = strIn.strip() > print '>InNextLine>',strIn > # skip if line is empty > if len(strIn)<1: > return False More Pythonic would be: if not strIn: > lstIn = list() > for cc in lstCut: > strSubline =strIn[cc[0]-1:cc[1]-1].strip() The start index is inclusive; the end index is exclusive. > lstIn.append(strSubline) > print '>InSubline2>'+lstIn[len(lstIn)-1]+'<' > del strIn, lstCut,cc Not necessary to del the names. They exist only within the function, which you're about to leave. > print '>InReturLst>',lstIn > return lstIn > Sometimes it returns a list and sometimes False. That's a bad idea; try to be consistent. > > > filIn = codecs.open( > strFileNameIn, > mode='r', > encoding='utf-8', > errors='strict', > buffering=1) You're decoding from UTF-8 to Unicode, so all the strings you're working on are Unicode strings. > for linIn in filIn: > lstIn = CutLine2List(linIn,lstCutters) > From ian.g.kelly at gmail.com Mon Dec 20 16:41:36 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 20 Dec 2010 14:41:36 -0700 Subject: Why do my list go uni-code by itself? In-Reply-To: <4D0FC5C4.3060008@Hvidberg.net> References: <4D0FC5C4.3060008@Hvidberg.net> Message-ID: On Mon, Dec 20, 2010 at 2:08 PM, Martin Hvidberg wrote: > Question: > In the last printout, tagged >InReturLst> all entries turn into uni-code. > What happens here? Actually, they were all unicode to begin with. You're using codecs.open to read the file, which transparently decodes the data using the supplied encoding (in this case, utf-8). If you wanted to preserve the original bytes, you would just use the open() function to open the file instead. > Look for the word 'FAN?'. This word changes from 'FAN?' to u'FAN\xd8' ? > That's a problem to me, and I don't want it to change like this. This happens because you're printing a list instead of a unicode string. When you print the unicode string, it tries to print the actual characters. When you print the list, it constructs the repr of the list, which uses the repr of each of the items in the list, and the repr of the unicode string is u'FAN\xd8'. If you don't want this to happen, then you will need to format the list as a string yourself instead of relying on print to do what it thinks you might want. Cheers, Ian From e_d_k at yahoo.com Mon Dec 20 16:56:02 2010 From: e_d_k at yahoo.com (Ed Keith) Date: Mon, 20 Dec 2010 13:56:02 -0800 (PST) Subject: Modifying an existing excel spreadsheet Message-ID: <377109.56809.qm@web120503.mail.ne1.yahoo.com> I have a user supplied 'template' Excel spreadsheet. I need to create a new excel spreadsheet based on the supplied template, with data filled in. I found the tools here http://www.python-excel.org/,? and http://sourceforge.net/projects/pyexcelerator/. I have been trying to use the former, since the latter seems to be devoid of documentation (not even any docstrings). My first thought was to copy the template, open the copy, modify it and save the modifications. But it looks like if I open an existing spreadsheet it must be read only. So I tried to? open the template, copy it to a new spreadsheet and write the new spreadsheet, but I can't seem to copy the images, and it looks like copying the formatting is going to be difficult. Can anyone give me any tips or advice? Thanks in advance, ?? -EdK Ed Keith e_d_k at yahoo.com Blog: edkeith.blogspot.com From davea at ieee.org Mon Dec 20 17:19:29 2010 From: davea at ieee.org (Dave Angel) Date: Mon, 20 Dec 2010 17:19:29 -0500 Subject: Why do my list go uni-code by itself? In-Reply-To: <4D0FC5C4.3060008@Hvidberg.net> References: <4D0FC5C4.3060008@Hvidberg.net> Message-ID: <4D0FD671.1010901@ieee.org> On 01/-10/-28163 02:59 PM, Martin Hvidberg wrote: > I'm reading a fixed format text file, line by line. I hereunder present > the code. I have out part not related to the file reading. > Only relevant detail left out is the lstCutters. It looks like this: > [[1, 9], [11, 21], [23, 48], [50, 59], [61, 96], [98, 123], [125, 150]] > It specifies the first and last character position of each token in the > fixed format of the input line. > All this works fine, and is only to explain where I'm going. > > The code, in the function definition, is broken up in more lines than > necessary, to be able to monitor the variables, step by step. > > --- Code start ------ > > import codecs > > > > def CutLine2List(strIn,lstCut): > strIn = strIn.strip() > print '>InNextLine>',strIn > # skip if line is empty > if len(strIn)<1: > return False > lstIn = list() > for cc in lstCut: > strSubline =strIn[cc[0]-1:cc[1]-1].strip() > lstIn.append(strSubline) > print '>InSubline2>'+lstIn[len(lstIn)-1]+'<' > del strIn, lstCut,cc > print '>InReturLst>',lstIn > return lstIn > > > > filIn = codecs.open( > strFileNameIn, > mode='r', > encoding='utf-8', > errors='strict', > buffering=1) > for linIn in filIn: > lstIn = CutLine2List(linIn,lstCutters) > > --- Code end ------ > > A sample output, representing one line from the input file looks like this: > > >InNextLine> I 30 2002-12-11 20:01:19.280 563 FAN? > 2001-12-12-15.46.12.734502 2001-12-12-15.46.12.734502 > >InSubline2>I< > >InSubline2>30< > >InSubline2>2002-12-11 20:01:19.280< > >InSubline2>563< > >InSubline2>FAN?< > >InSubline2>2001-12-12-15.46.12.73450< > >InSubline2>2001-12-12-15.46.12.73450< > >InReturLst> [u'I', u'30', u'2002-12-11 20:01:19.280', u'563', > u'FAN\xd8', u'2001-12-12-15.46.12.73450', u'2001-12-12-15.46.12.73450'] > > > Question: > In the last printout, tagged >InReturLst> all entries turn into > uni-code. What happens here? > Look for the word 'FAN?'. This word changes from 'FAN?' to u'FAN\xd8' -- > That's a problem to me, and I don't want it to change like this. > > What do I do to stop this behavior? > > Best Regards > Martin > > If you don't want Unicode, why do you specify that the file is encoded as utf-8 ? If it's ASCII, just open the file, without using a utf-8 codec. Of course, then you'll have to fix the input file to make it ASCII. The character in the input file following the letters "FAN" is not a zero, it's some other character, apparently 00D8 in the Unicode table, not 0030. It didn't "change" in the InRturLst line. You were reading Unicode strings from the file. When you print Unicode, it encodes it in whatever your console device specifies. But when you print a "list," it uses repr() on the elements, so you get to see what their real type is. DaveA From ian.g.kelly at gmail.com Mon Dec 20 18:15:34 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 20 Dec 2010 16:15:34 -0700 Subject: Sending XML to a WEB Service and Getting Response Back In-Reply-To: References: Message-ID: On Mon, Dec 20, 2010 at 11:58 AM, Anurag Chourasia wrote: > Dear Python Mates, > I have a requirement to send a XML Data to a WEB Service whose URL is of the > form?http://joule:8041/DteEnLinea/ws/EnvioGuia.jws > I also have to read back the response returned as a result of sending this > data to this WebService. > This web service implements the following operations: > ?? sendNCR > > This web service has no callbacks. > I have pasted the complete WSDL for this WEB Service below my email. > I would appreciate if someone could guide me with sample code using a Python > Library suitable to fulfill this requirement of mine. The ZSI or SOAPpy library should do what you need. From pythonlist.calin79 at spamgourmet.com Mon Dec 20 18:23:16 2010 From: pythonlist.calin79 at spamgourmet.com (pythonlist.calin79 at spamgourmet.com) Date: Mon, 20 Dec 2010 15:23:16 -0800 Subject: Class-override of a sort-key method? Message-ID: Hi all - it would seem that these days, all the cool kids use the sort function's 'key' kwarg in order to sort a list of custom objects quickly. Unfortunately, as opposed to using 'cmp', where you can implent __cmp__ to get 'automatic sorting' in a similar fashion, there doesn't seem to be a direct analogue for a class-overridable method for providing a sort key. (ie, something like '__sortkey__' or '__key__'). Is there one, and I'm just missing it? If not, are there any plans to add one? (I did a quick search of the PEP list, and the only hits for 'sort' I saw had to do with sorting dictionaries by value). - Paul -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Mon Dec 20 19:10:22 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 20 Dec 2010 16:10:22 -0800 Subject: Class-override of a sort-key method? In-Reply-To: References: Message-ID: On Mon, Dec 20, 2010 at 3:23 PM, wrote: > Hi all - it would seem that these days, all the cool kids use the sort > function's 'key' kwarg in order to sort a list of custom objects quickly. Really? They don't bother to define __cmp__ or similar? Sounds lazy and poorly structured. > Unfortunately, as opposed to using 'cmp', where you can implent __cmp__ to > get 'automatic sorting' in a similar fashion, there doesn't seem to be a > direct analogue for a class-overridable method for providing a sort key. > ?(ie, something like '__sortkey__' or '__key__'). Just simply delegate to key comparison in your __cmp__ (or similar) method(s). > Is there one, and I'm just missing it? If not, are there any plans to add > one? (I did a quick search of the PEP list, and the only hits for 'sort' I > saw had to do with sorting dictionaries by value). If you know at class-definiton-time how you want instances to be sorted, then just define __cmp__ (or the rich comparison methods) appropriately, possibly even delegating to a comparison of keys (as the class defines them). For example: from functools import total_ordering @total_ordering class Person(object): def __init__(self, first_name, last_name): self.first_name = first_name self.last_name = last_name @property def _key(self): """Identifying key for a Person, by which they are sorted""" return (self.last_name, self.first_name) def __eq__(self, other): return isinstance(other, Person) and self._key == other._key def __lt__(self, other): return self._key < other._key If you want to abstract even this away, then just write a class decorator; there's no need to add yet another (rather complicated due to all the interactions with the existing comparison methods) special method. Cheers, Chris -- http://blog.rebertia.com From steve at holdenweb.com Mon Dec 20 20:35:54 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 20 Dec 2010 20:35:54 -0500 Subject: Catching user switching and getting current active user from root on linux In-Reply-To: <3d190cbf-be7d-4973-b85f-c030bb258742@glegroupsg2000goo.googlegroups.com> References: <3d190cbf-be7d-4973-b85f-c030bb258742@glegroupsg2000goo.googlegroups.com> Message-ID: <4D10047A.6020207@holdenweb.com> On 12/20/2010 12:54 PM, mpnordland wrote: > I give up, I will never try to use a usenet group again. For the ones > of you who tried to help thank you. You helped to identify some of my > troubles, as for you @usernet, you are a troll Don't give up after one experience. Usenet can be really useful as long as you know who to listen to and who to ignore ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Mon Dec 20 20:35:54 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 20 Dec 2010 20:35:54 -0500 Subject: Catching user switching and getting current active user from root on linux In-Reply-To: <3d190cbf-be7d-4973-b85f-c030bb258742@glegroupsg2000goo.googlegroups.com> References: <3d190cbf-be7d-4973-b85f-c030bb258742@glegroupsg2000goo.googlegroups.com> Message-ID: <4D10047A.6020207@holdenweb.com> On 12/20/2010 12:54 PM, mpnordland wrote: > I give up, I will never try to use a usenet group again. For the ones > of you who tried to help thank you. You helped to identify some of my > troubles, as for you @usernet, you are a troll Don't give up after one experience. Usenet can be really useful as long as you know who to listen to and who to ignore ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From jshgwave at yahoo.com Mon Dec 20 20:36:45 2010 From: jshgwave at yahoo.com (Jshgwave) Date: Mon, 20 Dec 2010 17:36:45 -0800 (PST) Subject: Redundant importing of modules Message-ID: <528680.17833.qm@web84407.mail.ac2.yahoo.com> When writing a function that uses a module such as NumPy, it is tempting to include the statement "import numpy" or "import numpy as np" in the definition of the function, in case the? function is used in a script that hasn't already imported NumPy. That could lead to the script issuing the "import numpy" command more than once. Does Python know to disregard redundant "import" commands? ? -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Mon Dec 20 20:50:28 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 20 Dec 2010 20:50:28 -0500 Subject: Class-override of a sort-key method? In-Reply-To: References: Message-ID: <4D1007E4.6090401@holdenweb.com> On 12/20/2010 7:10 PM, Chris Rebert wrote: > On Mon, Dec 20, 2010 at 3:23 PM, wrote: >> Hi all - it would seem that these days, all the cool kids use the sort >> function's 'key' kwarg in order to sort a list of custom objects quickly. > > Really? They don't bother to define __cmp__ or similar? Sounds lazy > and poorly structured. > That sounds to me like a potentially ill-informed response. >> Unfortunately, as opposed to using 'cmp', where you can implent __cmp__ to >> get 'automatic sorting' in a similar fashion, there doesn't seem to be a >> direct analogue for a class-overridable method for providing a sort key. >> (ie, something like '__sortkey__' or '__key__'). > Why do you talk about "implementing __cmp__"? Why should this be necessary? > Just simply delegate to key comparison in your __cmp__ (or similar) method(s). > Assuming, of course, that you are conveniently sorting only object over which you have complete control ... >> Is there one, and I'm just missing it? If not, are there any plans to add >> one? (I did a quick search of the PEP list, and the only hits for 'sort' I >> saw had to do with sorting dictionaries by value). > > If you know at class-definiton-time how you want instances to be > sorted, then just define __cmp__ (or the rich comparison methods) > appropriately, possibly even delegating to a comparison of keys (as > the class defines them). > > For example: > > from functools import total_ordering > > @total_ordering > class Person(object): > def __init__(self, first_name, last_name): > self.first_name = first_name > self.last_name = last_name > > @property > def _key(self): > """Identifying key for a Person, by which they are sorted""" > return (self.last_name, self.first_name) > > def __eq__(self, other): > return isinstance(other, Person) and self._key == other._key > > def __lt__(self, other): > return self._key < other._key > > If you want to abstract even this away, then just write a class > decorator; there's no need to add yet another (rather complicated due > to all the interactions with the existing comparison methods) special > method. > But the *real* point is (as the documentation attempts to point out) that by providing the key argument it gets called only once per element, whereas the cmp argument (or the objects' __cmp__() method if you insist on letting sort delegate to that) gets called every time two objects have to be compared. If cmp is a Python function (or equivalently if __cmp__() is a Python method) then calling it will take much longer than calling hte built-in default routines. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Mon Dec 20 20:50:28 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 20 Dec 2010 20:50:28 -0500 Subject: Class-override of a sort-key method? In-Reply-To: References: Message-ID: <4D1007E4.6090401@holdenweb.com> On 12/20/2010 7:10 PM, Chris Rebert wrote: > On Mon, Dec 20, 2010 at 3:23 PM, wrote: >> Hi all - it would seem that these days, all the cool kids use the sort >> function's 'key' kwarg in order to sort a list of custom objects quickly. > > Really? They don't bother to define __cmp__ or similar? Sounds lazy > and poorly structured. > That sounds to me like a potentially ill-informed response. >> Unfortunately, as opposed to using 'cmp', where you can implent __cmp__ to >> get 'automatic sorting' in a similar fashion, there doesn't seem to be a >> direct analogue for a class-overridable method for providing a sort key. >> (ie, something like '__sortkey__' or '__key__'). > Why do you talk about "implementing __cmp__"? Why should this be necessary? > Just simply delegate to key comparison in your __cmp__ (or similar) method(s). > Assuming, of course, that you are conveniently sorting only object over which you have complete control ... >> Is there one, and I'm just missing it? If not, are there any plans to add >> one? (I did a quick search of the PEP list, and the only hits for 'sort' I >> saw had to do with sorting dictionaries by value). > > If you know at class-definiton-time how you want instances to be > sorted, then just define __cmp__ (or the rich comparison methods) > appropriately, possibly even delegating to a comparison of keys (as > the class defines them). > > For example: > > from functools import total_ordering > > @total_ordering > class Person(object): > def __init__(self, first_name, last_name): > self.first_name = first_name > self.last_name = last_name > > @property > def _key(self): > """Identifying key for a Person, by which they are sorted""" > return (self.last_name, self.first_name) > > def __eq__(self, other): > return isinstance(other, Person) and self._key == other._key > > def __lt__(self, other): > return self._key < other._key > > If you want to abstract even this away, then just write a class > decorator; there's no need to add yet another (rather complicated due > to all the interactions with the existing comparison methods) special > method. > But the *real* point is (as the documentation attempts to point out) that by providing the key argument it gets called only once per element, whereas the cmp argument (or the objects' __cmp__() method if you insist on letting sort delegate to that) gets called every time two objects have to be compared. If cmp is a Python function (or equivalently if __cmp__() is a Python method) then calling it will take much longer than calling hte built-in default routines. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Mon Dec 20 21:03:45 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 20 Dec 2010 21:03:45 -0500 Subject: Redundant importing of modules In-Reply-To: <528680.17833.qm@web84407.mail.ac2.yahoo.com> References: <528680.17833.qm@web84407.mail.ac2.yahoo.com> Message-ID: On 12/20/2010 8:36 PM, Jshgwave wrote: > When writing a function that uses a module such as NumPy, it is tempting > to include the statement "import numpy" or "import numpy as np" in the > definition of the function, in case the function is used in a script > that hasn't already imported NumPy. > > That could lead to the script issuing the "import numpy" command more > than once. > > Does Python know to disregard redundant "import" commands? > Oh, yes (as long as they are imported by the same name each time). There's a dict at sys.modules that has a key for each loaded module's name. When an attempt is made to import a module the first thing the interpreter does is to look at sys.modules. If it has the correct key in it then the assumption is that the module has already been imported, and its namespace is made available as the module name immediately. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From cpblpublic at gmail.com Mon Dec 20 22:03:05 2010 From: cpblpublic at gmail.com (C Barrington-Leigh) Date: Mon, 20 Dec 2010 19:03:05 -0800 (PST) Subject: Bug in fixed_point?! Message-ID: <08b56619-c21e-40b8-bafa-490fb6c6277e@z19g2000yqb.googlegroups.com> I cannot figure out what I'm doing wrong. The following does not return a fixed point: from scipy import optimize xxroot= optimize.fixed_point(lambda xx: exp(-2.0*xx)/2.0, 1.0, args=(), xtol=1e-12, maxiter=500) print ' %f solves fixed point, ie f(%f)=%f ?'% (xxroot,xxroot,exp(-2.0*xxroot)/2.0) Chris From stefan.sonnenberg at pythonmeister.com Mon Dec 20 23:25:46 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Tue, 21 Dec 2010 05:25:46 +0100 Subject: Modifying an existing excel spreadsheet In-Reply-To: <377109.56809.qm@web120503.mail.ne1.yahoo.com> References: <377109.56809.qm@web120503.mail.ne1.yahoo.com> Message-ID: <4D102C4A.303@pythonmeister.com> Am 20.12.2010 22:56, schrieb Ed Keith: > I have a user supplied 'template' Excel spreadsheet. I need to create a new excel spreadsheet based on the supplied template, with data filled in. > > I found the tools here http://www.python-excel.org/, and http://sourceforge.net/projects/pyexcelerator/. I have been trying to use the former, since the latter seems to be devoid of documentation (not even any docstrings). > > > My first thought was to copy the template, open the copy, modify it and save the modifications. But it looks like if I open an existing spreadsheet it must be read only. Could you post some code ? Did you try a simple file copy or do you iterate over all the cells ? > So I tried to open the template, copy it to a new spreadsheet and write the new spreadsheet, but I can't seem to copy the images, and it looks like copying the formatting is going to be difficult. > > Can anyone give me any tips or advice? > > Thanks in advance, > > -EdK > > Ed Keith > > e_d_k at yahoo.com > > > > Blog: edkeith.blogspot.com > > > As long as your program only needs to run under windows, COM automation is IMHO the best solution. Python tells Excel what to do. From tjreedy at udel.edu Tue Dec 21 01:03:10 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 21 Dec 2010 01:03:10 -0500 Subject: Bug in fixed_point?! In-Reply-To: <08b56619-c21e-40b8-bafa-490fb6c6277e@z19g2000yqb.googlegroups.com> References: <08b56619-c21e-40b8-bafa-490fb6c6277e@z19g2000yqb.googlegroups.com> Message-ID: On 12/20/2010 10:03 PM, C Barrington-Leigh wrote: > I cannot figure out what I'm doing wrong. The following does not > return a fixed point: What did it do? For nearly all such questions, cut and paste actual output or traceback. > from scipy import optimize > xxroot= optimize.fixed_point(lambda xx: exp(-2.0*xx)/2.0, 1.0, > args=(), xtol=1e-12, maxiter=500) > print ' %f solves fixed point, ie f(%f)=%f ?'% > (xxroot,xxroot,exp(-2.0*xxroot)/2.0) from math import exp x = 1.0 for i in range(70): print(repr(x)) x = exp(-2.0*x)/2.0 converges to 0.2835716452048919 Did you cut and paste what you actually ran? -- Terry Jan Reedy From usenet at ffconsultancy.com Tue Dec 21 01:06:31 2010 From: usenet at ffconsultancy.com (Jon Harrop) Date: Tue, 21 Dec 2010 06:06:31 -0000 Subject: Google AI challenge: planet war. Lisp won. In-Reply-To: <44a8f48f-e291-463e-a042-d0cbc31a2a4e@z17g2000prz.googlegroups.com> References: <44a8f48f-e291-463e-a042-d0cbc31a2a4e@z17g2000prz.googlegroups.com> Message-ID: Wasn't that the "challenge" where they wouldn't even accept solutions written in many other languages (including both OCaml and F#)? Cheers, Jon. "Xah Lee" wrote in message news:44a8f48f-e291-463e-a042-d0cbc31a2a4e at z17g2000prz.googlegroups.com... discovered this rather late. Google has a AI Challenge: planet wars. http://ai-contest.com/index.php it started sometimes 2 months ago and ended first this month. the winner is G?bor Melis, with his code written in lisp. Congrats lispers! G?bor wrote a blog about it here http://quotenil.com/Planet-Wars-Post-Mortem.html (not sure if this has been mentioned here but quick search didn't find it) Xah ? http://xahlee.org/ ? From nagle at animats.com Tue Dec 21 01:34:28 2010 From: nagle at animats.com (John Nagle) Date: Mon, 20 Dec 2010 22:34:28 -0800 Subject: Sending XML to a WEB Service and Getting Response Back In-Reply-To: References: Message-ID: <4d104a72$0$44000$742ec2ed@news.sonic.net> On 12/20/2010 12:14 PM, Hidura wrote: > I recommend you use the urllib.request in the library of python says > everything that you want to know. > > 2010/12/20, Anurag Chourasia: >> Dear Python Mates, >> >> I have a requirement to send a XML Data to a WEB Service whose URL is of the >> form http://joule:8041/DteEnLinea/ws/EnvioGuia.jws >> >> I also have to read back the response returned as a result of sending this >> data to this WebService. >> >> This web service implements the following operations: >> sendNCR >> >> This web service has no callbacks. >> >> I have pasted the complete WSDL for this WEB Service below my email. >> >> I would appreciate if someone could guide me with sample code using a Python >> Library suitable to fulfill this requirement of mine. >> >> Regards, >> Anurag If you're writing the client side, the service talks SOAP, and you have a WSDL file, use the "suds" module. SOAPpy is way out of date. The last update on SourceForge was in 2001. John Nagle From jearl at notengoamigos.org Tue Dec 21 02:04:09 2010 From: jearl at notengoamigos.org (Jason Earl) Date: Tue, 21 Dec 2010 00:04:09 -0700 Subject: Google AI challenge: planet war. Lisp won. References: <44a8f48f-e291-463e-a042-d0cbc31a2a4e@z17g2000prz.googlegroups.com> Message-ID: <87y67jmwt2.fsf@notengoamigos.org> On Mon, Dec 20 2010, Jon Harrop wrote: > Wasn't that the "challenge" where they wouldn't even accept solutions > written in many other languages (including both OCaml and F#)? > > Cheers, > Jon. http://ai-contest.com/faq.php Question: There is no starter package for my favorite language. What shall I do? Answer: You don't know C++, Java, or Python? Okay fine. Tell the forums what starter package you want to see, and we will try our best to make it for you. The folks working on Lisp submissions apparently created their own starter package. I am sure that something similar could have been done for OCaml or F#. That's probably too bad. These types of competitions are good publicity for less popular languages (assuming that the bots to well). Jason From ian.g.kelly at gmail.com Tue Dec 21 02:45:31 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 21 Dec 2010 00:45:31 -0700 Subject: Sending XML to a WEB Service and Getting Response Back In-Reply-To: <4d104a72$0$44000$742ec2ed@news.sonic.net> References: <4d104a72$0$44000$742ec2ed@news.sonic.net> Message-ID: On 12/20/2010 11:34 PM, John Nagle wrote: > SOAPpy is way out of date. The last update on SourceForge was in > 2001. 2007, actually: http://sourceforge.net/projects/pywebsvcs/files/ And there is repository activity within the past 9 months. Still, point taken. From stefan_ml at behnel.de Tue Dec 21 03:16:21 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 21 Dec 2010 09:16:21 +0100 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: <1292874586.11975.8.camel@linux-yu4c.site> References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <1292874586.11975.8.camel@linux-yu4c.site> Message-ID: Adam Tauno Williams, 20.12.2010 20:49: > On Mon, 2010-12-20 at 11:34 -0800, spaceman-spiff wrote: >> This is a rather long post, but i wanted to include all the details& >> everything i have tried so far myself, so please bear with me& read >> the entire boringly long post. >> I am trying to parse a ginormous ( ~ 1gb) xml file. > > Do that hundreds of times a day. > >> 0. I am a python& xml n00b, s& have been relying on the excellent >> beginner book DIP(Dive_Into_Python3 by MP(Mark Pilgrim).... Mark , if >> u are readng this, you are AWESOME& so is your witty& humorous >> writing style) >> 1. Almost all exmaples pf parsing xml in python, i have seen, start off with these 4 lines of code. >> import xml.etree.ElementTree as etree Try import xml.etree.cElementTree as etree instead. Note the leading "c", which hints at the C implementations of ElementTree. It's much faster and much more memory friendly than the Python implementation. >> tree = etree.parse('*path_to_ginormous_xml*') >> root = tree.getroot() #my huge xml has 1 root at the top level >> print root > > Yes, this is a terrible technique; most examples are crap. > >> 2. In the 2nd line of code above, as Mark explains in DIP, the parse >> function builds& returns a tree object, in-memory(RAM), which >> represents the entire document. >> I tried this code, which works fine for a small ( ~ 1MB), but when i >> run this simple 4 line py code in a terminal for my HUGE target file >> (1GB), nothing happens. >> In a separate terminal, i run the top command,& i can see a python >> process, with memory (the VIRT column) increasing from 100MB , all the >> way upto 2100MB. > > Yes, this is using DOM. DOM is evil and the enemy, full-stop. Actually, ElementTree is not "DOM", it's modelled after the XML Infoset. While I agree that DOM is, well, maybe not "the enemy", but not exactly beautiful either, ElementTree is really a good thing, likely also in this case. >> I am guessing, as this happens (over the course of 20-30 mins), the >> tree representing is being slowly built in memory, but even after >> 30-40 mins, nothing happens. >> I dont get an error, seg fault or out_of_memory exception. > > You need to process the document as a stream of elements; aka SAX. IMHO, this is the worst advice you can give. Stefan From bruno.desthuilliers at gmail.com Tue Dec 21 03:30:00 2010 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Tue, 21 Dec 2010 00:30:00 -0800 (PST) Subject: Redundant importing of modules References: <528680.17833.qm@web84407.mail.ac2.yahoo.com> Message-ID: On 21 d?c, 03:03, Steve Holden wrote: > On 12/20/2010 8:36 PM, Jshgwave wrote:> > > When writing a function that uses a module such as NumPy, it is tempting > > to include the statement "import numpy" or "import numpy as np" in the > > definition of the function, in case the ?function is used in a script > > that hasn't already imported NumPy. (answering the OP - post didn't show off here on c.l.py): This is actually totally useless. The global namespace of a function is the namespace of the module in which it has been defined, not the namespace of the module where the function is called. From stefan_ml at behnel.de Tue Dec 21 03:31:50 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 21 Dec 2010 09:31:50 +0100 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: Message-ID: spaceman-spiff, 20.12.2010 21:29: > I am sorry i left out what exactly i am trying to do. > > 0. Goal :I am looking for a specific element..there are several 10s/100s occurrences of that element in the 1gb xml file. > The contents of the xml, is just a dump of config parameters from a packet switch( although imho, the contents of the xml dont matter) > > I need to detect them& then for each 1, i need to copy all the content b/w the element's start& end tags& create a smaller xml file. Then cElementTree's iterparse() is your friend. It allows you to basically iterate over the XML tags while its building an in-memory tree from them. That way, you can either remove subtrees from the tree if you don't need them (to safe memory) or otherwise handle them in any way you like, such as serialising them into a new file (and then deleting them). Also note that the iterparse implementation in lxml.etree allows you to specify a tag name to restrict the iterator to these tags. That's usually a lot faster, but it also means that you need to take more care to clean up the parts of the tree that the iterator stepped over. Depending on your requirements and the amount of manual code optimisation that you want to invest, either cElementTree or lxml.etree may perform better for you. It seems that you already found the article by Liza Daly about high performance XML processing with Python. Give it another read, it has a couple of good hints and examples that will help you here. Stefan From haloha201 at gmail.com Tue Dec 21 04:47:50 2010 From: haloha201 at gmail.com (haloha) Date: Tue, 21 Dec 2010 16:47:50 +0700 Subject: how to inter-working on process in window Message-ID: Hi all how do i send an ESC key into a process on window i already get a pid of process but i dont know how to send ESC key into process Please help Ha -------------- next part -------------- An HTML attachment was scrubbed... URL: From rschuon at mindspring.com Tue Dec 21 08:30:29 2010 From: rschuon at mindspring.com (Robert Schuon) Date: Tue, 21 Dec 2010 13:30:29 GMT Subject: On 07/13/2010 02:18 PM, Adam Mercer wrote:That version of M2Crypto does not References: Message-ID: <2010122182925usenet@eggheadcafe.com> I was getting the same error trying to build M2Crypto 0.20.2 for Python 2.5 on a Win 7 laptop, so I pulled down the trunk, and it did build properly using minGW and Swig. However, when I try to "python setup.py install", python simply gives the same complaint that python was built in visual studio 2003, and will not install M2Crypto. Any help would be greatly appreciated, as I have been trying to get this to work for days. Does anyone have a build for 0.20.2 that works with python 2.5? I found so many other builds, but not that one. Thanks, Bob S. > On Tuesday, July 13, 2010 5:18 PM Adam Mercer wrote: > Hi > > I am trying to build M2Crypto on Mac OS X 10.6.4 against python2.5 > (python2.6 fails in the same way), with SWIG 2.0.0 and OpenSSL 1.0.0a > and it is failing with the following: > > 105 :info:build swigging SWIG/_m2crypto.i to SWIG/_m2crypto_wrap.c > 106 :info:build swig -python > -I/opt/local/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 > -I/opt/local/include -includeall -o SWIG/_m2crypto_wrap.c > SWIG/_m2crypto.i > 107 :info:build SWIG/_bio.i:64: Warning 454: Setting a > pointer/reference variable may leak memory. > 108 :info:build SWIG/_rand.i:19: Warning 454: Setting a > pointer/reference variable may leak memory. > 109 :info:build SWIG/_evp.i:156: Warning 454: Setting a > pointer/reference variable may leak memory. > 110 :info:build SWIG/_dh.i:36: Warning 454: Setting a > pointer/reference variable may leak memory. > 111 :info:build SWIG/_rsa.i:43: Warning 454: Setting a > pointer/reference variable may leak memory. > 112 :info:build SWIG/_dsa.i:31: Warning 454: Setting a > pointer/reference variable may leak memory. > 113 :info:build SWIG/_ssl.i:207: Warning 454: Setting a > pointer/reference variable may leak memory. > 114 :info:build SWIG/_x509.i:313: Warning 454: Setting a > pointer/reference variable may leak memory. > 115 :info:build SWIG/_pkcs7.i:42: Warning 454: Setting a > pointer/reference variable may leak memory. > 116 :info:build SWIG/_pkcs7.i:42: Warning 454: Setting a > pointer/reference variable may leak memory. > 117 :info:build SWIG/_util.i:9: Warning 454: Setting a > pointer/reference variable may leak memory. > 118 :info:build SWIG/_ec.i:111: Warning 454: Setting a > pointer/reference variable may leak memory. > 119 :info:build SWIG/_engine.i:162: Warning 454: Setting a > pointer/reference variable may leak memory. > 120 :info:build creating build/temp.macosx-10.6-x86_64-2.5 > 121 :info:build creating build/temp.macosx-10.6-x86_64-2.5/SWIG > 122 :info:build /usr/bin/gcc-4.2 -fno-strict-aliasing -mno-fused-madd > -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes > -I/opt/local/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 > -I/opt/local/include > -I/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_python_py25-m2crypto/work/M2Crypto-0.20.2/SWIG > -c SWIG/_m2crypto_wrap.c -o > build/temp.macosx-10.6-x86_64-2.5/SWIG/_m2crypto_wrap.o -DTHREADING > 123 :info:build SWIG/_m2crypto_wrap.c: In function 'rand_pseudo_bytes': > 124 :info:build SWIG/_m2crypto_wrap.c:3899: warning: pointer targets > in passing argument 1 of 'PyString_FromStringAndSize' differ in > signedness > 125 :info:build SWIG/_m2crypto_wrap.c: In function 'pkcs5_pbkdf2_hmac_sha1': > 126 :info:build SWIG/_m2crypto_wrap.c:3973: warning: pointer targets > in passing argument 1 of 'PyString_FromStringAndSize' differ in > signedness > 127 :info:build SWIG/_m2crypto_wrap.c: In function 'bytes_to_key': > 128 :info:build SWIG/_m2crypto_wrap.c:4132: warning: pointer targets > in passing argument 1 of 'PyString_FromStringAndSize' differ in > signedness > 129 :info:build SWIG/_m2crypto_wrap.c: In function 'sign_final': > 130 :info:build SWIG/_m2crypto_wrap.c:4228: warning: pointer targets > in passing argument 1 of 'PyString_FromStringAndSize' differ in > signedness > 131 :info:build SWIG/_m2crypto_wrap.c: In function 'pkey_as_der': > 132 :info:build SWIG/_m2crypto_wrap.c:4300: warning: pointer targets > in passing argument 1 of 'PyString_FromStringAndSize' differ in > signedness > 133 :info:build SWIG/_m2crypto_wrap.c: In function 'pkey_get_modulus': > 134 :info:build SWIG/_m2crypto_wrap.c:4333: warning: value computed is not used > 135 :info:build SWIG/_m2crypto_wrap.c:4358: warning: value computed is not used > 136 :info:build SWIG/_m2crypto_wrap.c: In function 'AES_crypt': > 137 :info:build SWIG/_m2crypto_wrap.c:4444: warning: pointer targets > in passing argument 1 of 'PyString_FromStringAndSize' differ in > signedness > 138 :info:build SWIG/_m2crypto_wrap.c: At top level: > 139 :info:build SWIG/_m2crypto_wrap.c:5846: error: expected '=', ',', > ';', 'asm' or '__attribute__' before '*' token > 140 :info:build SWIG/_m2crypto_wrap.c:5850: error: expected ')' before '*' token > 141 :info:build SWIG/_m2crypto_wrap.c:5854: error: expected ')' before '*' token > 142 :info:build SWIG/_m2crypto_wrap.c:5858: error: expected '=', ',', > ';', 'asm' or '__attribute__' before '*' token > 143 :info:build SWIG/_m2crypto_wrap.c:5862: error: expected ')' before '*' token > 144 :info:build SWIG/_m2crypto_wrap.c:5866: error: expected ')' before '*' token > 145 :info:build SWIG/_m2crypto_wrap.c: In function 'i2d_x509': > 146 :info:build SWIG/_m2crypto_wrap.c:5942: warning: pointer targets > in passing argument 1 of 'PyString_FromStringAndSize' differ in > signedness > 147 :info:build SWIG/_m2crypto_wrap.c: In function 'x509_name_set_by_nid': > 148 :info:build SWIG/_m2crypto_wrap.c:6023: warning: pointer targets > in passing argument 4 of 'X509_NAME_add_entry_by_NID' differ in > signedness > 149 :info:build SWIG/_m2crypto_wrap.c: In function 'x509_name_add_entry_by_txt': > 150 :info:build SWIG/_m2crypto_wrap.c:6028: warning: pointer targets > in passing argument 4 of 'X509_NAME_add_entry_by_txt' differ in > signedness > 151 :info:build SWIG/_m2crypto_wrap.c: At top level: > 152 :info:build SWIG/_m2crypto_wrap.c:6038: error: expected '=', ',', > ';', 'asm' or '__attribute__' before '*' token > 153 :info:build SWIG/_m2crypto_wrap.c:6043: error: expected ')' before '*' token > 154 :info:build SWIG/_m2crypto_wrap.c:6048: error: expected ')' before '*' token > 155 :info:build SWIG/_m2crypto_wrap.c:6053: error: expected ')' before '*' token >> On Friday, July 16, 2010 3:09 AM Heikki Toivonen wrote: >> On 07/13/2010 02:18 PM, Adam Mercer wrote: >> >> That version of M2Crypto does not work with OpenSSL 1.0.x because >> OpenSSL changed APIs. M2Crypto trunk works, as will the next M2Crypto >> release. So at this time, you should check out M2Crypto from the >> Subversion repository. See >> http://chandlerproject.org/Projects/MeTooCrypto for details on how to >> get the sources. >> >> -- >> Heikki Toivonen - http://heikkitoivonen.net >>> On Friday, July 16, 2010 11:18 AM Adam Mercer wrote: >>> Thanks any ETA on a new release supporting OpenSSL 1.0.x? >>> >>> Cheers >>> >>> Adam >>>> On Saturday, July 17, 2010 3:20 PM Heikki Toivonen wrote: >>>> On 07/16/2010 08:18 AM, Adam Mercer wrote: >>>> >>>> I was actually planning on doing a release by the end of June, but life >>>> happened. Maybe by the end of August... >>>> >>>> -- >>>> Heikki Toivonen - http://heikkitoivonen.net >>>>> On Saturday, July 17, 2010 8:15 PM Adam Mercer wrote: >>>>> Know what whats like :-) I have backported the OpenSSL patches for the >>>>> MacPorts port so for the time being this particular fire has been put >>>>> out. >>>>> >>>>> Cheers >>>>> >>>>> Adam >>>>> Submitted via EggHeadCafe >>>>> Oracle Developer For Beginners >>>>> http://www.eggheadcafe.com/training-topic-area/Oracle-SQL-Developer/2/Oracle-SQL-Samples.aspx From joncle at googlemail.com Tue Dec 21 10:37:30 2010 From: joncle at googlemail.com (Jon Clements) Date: Tue, 21 Dec 2010 07:37:30 -0800 (PST) Subject: Modifying an existing excel spreadsheet References: Message-ID: On Dec 20, 9:56?pm, Ed Keith wrote: > I have a user supplied 'template' Excel spreadsheet. I need to create a new excel spreadsheet based on the supplied template, with data filled in. > > I found the tools herehttp://www.python-excel.org/,?andhttp://sourceforge.net/projects/pyexcelerator/. I have been trying to use the former, since the latter seems to be devoid of documentation (not even any docstrings). > > My first thought was to copy the template, open the copy, modify it and save the modifications. But it looks like if I open an existing spreadsheet it must be read only. So I tried to? open the template, copy it to a new spreadsheet and write the new spreadsheet, but I can't seem to copy the images, and it looks like copying the formatting is going to be difficult. > > Can anyone give me any tips or advice? > > Thanks in advance, > > ?? -EdK > > Ed Keith > > e_... at yahoo.com > > Blog: edkeith.blogspot.com Have you tried: http://groups.google.com/group/python-excel and searching the archives for "template"? Similar questions have come up before there. hth Jon From robert.kern at gmail.com Tue Dec 21 11:36:07 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 21 Dec 2010 11:36:07 -0500 Subject: Bug in fixed_point?! In-Reply-To: <08b56619-c21e-40b8-bafa-490fb6c6277e@z19g2000yqb.googlegroups.com> References: <08b56619-c21e-40b8-bafa-490fb6c6277e@z19g2000yqb.googlegroups.com> Message-ID: On 12/20/10 10:03 PM, C Barrington-Leigh wrote: > I cannot figure out what I'm doing wrong. The following does not > return a fixed point: > > > from scipy import optimize > xxroot= optimize.fixed_point(lambda xx: exp(-2.0*xx)/2.0, 1.0, > args=(), xtol=1e-12, maxiter=500) > print ' %f solves fixed point, ie f(%f)=%f ?'% > (xxroot,xxroot,exp(-2.0*xxroot)/2.0) You will want to ask scipy questions on the scipy-user mailing list: http://www.scipy.org/Mailing_Lists When you do, please provide the information that Terry Reedy asked for. -- 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 ethan at stoneleaf.us Tue Dec 21 12:21:17 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 21 Dec 2010 09:21:17 -0800 Subject: class inheritance In-Reply-To: References: Message-ID: <4D10E20D.8040204@stoneleaf.us> JLundell wrote: > On Saturday, March 13, 2010 9:03:36 AM UTC-8, Jonathan Lundell wrote: >> I've got a subclass of fractions.Fraction called Value; it's a mostly >> trivial class, except that it overrides __eq__ to mean 'nearly equal'. >> However, since Fraction's operations result in a Fraction, not a >> Value, I end up with stuff like this: >> >> x = Value(1) + Value(2) >> >> where x is now a Fraction, not a Value, and x == y uses >> Fraction.__eq__ rather than Value.__eq__. >> >> This appears to be standard Python behavior (int does the same thing). >> I've worked around it by overriding __add__, etc, with functions that >> invoke Fraction but coerce the result. But that's tedious; there are a >> lot of methods to override. >> >> So I'm wondering: is there a more efficient way to accomplish what I'm >> after? > > I recently implemented a different approach to this. I've got: > > class Rational(fractions.Fraction): > > ... and some methods of my own, including my own __new__ and __str__ (which is one of the reasons I need the class). Then after (outside) the class definition, this code that was inspired by something similar I noticed in Python Cookbook. There are two things going on here. One is, of course, the automation at import time. The other is that the wrapper gets a Fraction instance and simply overrides __class__, rather than creating yet another Rational and unbinding the interim Fraction. Seems to work quite well. [snip] Another option is to use a metaclass: class Perpetuate(ABCMeta): def __new__(metacls, cls_name, cls_bases, cls_dict): if len(cls_bases) > 1: raise TypeError("multiple bases not allowed") result_class = type.__new__(metacls, cls_name, cls_bases, cls_dict) base_class = cls_bases[0] known_attr = set() for attr in cls_dict.keys(): known_attr.add(attr) for attr in base_class.__dict__.keys(): if attr in ('__new__'): continue code = getattr(base_class, attr) if callable(code) and attr not in known_attr: setattr(result_class, attr, metacls._wrap(base_class, code)) elif attr not in known_attr: setattr(result_class, attr, code) return result_class @staticmethod def _wrap(base, code): def wrapper(*args, **kwargs): if args: cls = args[0] result = code(*args, **kwargs) if type(result) == base: return cls.__class__(result) elif isinstance(result, (tuple, list, set)): new_result = [] for partial in result: if type(partial) == base: new_result.append(cls.__class__(partial)) else: new_result.append(partial) result = result.__class__(new_result) elif isinstance(result, dict): for key in result: value = result[key] if type(value) == base: result[key] = cls.__class__(value) return result wrapper.__name__ = code.__name__ wrapper.__doc__ = code.__doc__ return wrapper then the actual class becomes: class CloseFraction(Fraction): __metaclass__ = Perpetuate def __eq__(x, y): return abs(x - y) < 1 # season to taste def __repr__(x): return "CloseFraction(%d, %d)" % (x.numerator, x.denominator) Perpetuate needs to handle multiple inheritance better, but it might meet your needs at this point. Sample run: --> n = CloseFraction(3, 2) --> n CloseFraction(3, 2) --> print n 3/2 --> m = CloseFraction(9, 4) --> m CloseFraction(9, 4) --> n == m True --> n - m CloseFraction(-3, 4) --> n + m CloseFraction(15, 4) --> n.real CloseFraction(3, 2) --> n.imag 0 # this is an int Hope this helps! ~Ethan~ From joncle at googlemail.com Tue Dec 21 12:22:29 2010 From: joncle at googlemail.com (Jon Clements) Date: Tue, 21 Dec 2010 09:22:29 -0800 (PST) Subject: help with link parsing? References: Message-ID: <39ca82ab-1ed3-42d3-ba26-6f1915236e92@v17g2000vbo.googlegroups.com> On Dec 20, 7:14?pm, "Littlefield, Tyler" wrote: > Hello all, > I have a question. I guess this worked pre 2.6; I don't remember the > last time I used it, but it was a while ago, and now it's failing. > Anyone mind looking at it and telling me what's going wrong? Also, is > there a quick way to match on a certain site? like links from google.com > and only output those? > #!/usr/bin/env python > > #This program is free software: you can redistribute it and/or modify it > under the terms of the GNU General Public License as published > #by the Free Software Foundation, either version 3 of the License, or > (at your option) any later version. > > #This program is distributed in the hope that it will be useful, but > WITHOUT ANY WARRANTY; without even the implied warranty of > #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > General Public License for more details. > # > #You should have received a copy of the GNU General Public License along > with this program. If not, see > #http://www.gnu.org/licenses/. > > """ > This script will parse out all the links in an html document and write > them to a textfile. > """ > import sys,optparse > import htmllib,formatter > > #program class declarations: > class Links(htmllib.HTMLParser): > ? ? ?def __init__(self,formatter): > ? ? ? ? ?htmllib.HTMLParser.__init__(self, formatter) > ? ? ? ? ?self.links=[] > ? ? ?def start_a(self, attrs): > ? ? ? ? ?if (len(attrs)>0): > ? ? ? ? ? ? ?for a in attrs: > ? ? ? ? ? ? ? ? ?if a[0]=="href": > ? ? ? ? ? ? ? ? ? ? ?self.links.append(a[1]) > ? ? ? ? ? ? ? ? ? ? ?print a[1] > ? ? ? ? ? ? ? ? ? ? ?break > > def main(argv): > ? ? ?if (len(argv)!=3): > ? ? ? ? ?print("Error:\n"+argv[0]+" .\nParses > for all links and saves them to .") > ? ? ? ? ?return 1 > ? ? ?lcount=0 > ? ? ?format=formatter.NullFormatter() > ? ? ?html=Links(format) > ? ? ?print "Retrieving data:" > ? ? ?page=open(argv[1],"r") > ? ? ?print "Feeding data to parser:" > ? ? ?html.feed(page.read()) > ? ? ?page.close() > ? ? ?print "Writing links:" > ? ? ?output=open(argv[2],"w") > ? ? ?for i in (html.links): > ? ? ? ? ?output.write(i+"\n") > ? ? ? ? ?lcount+=1 > ? ? ?output.close() > ? ? ?print("Wrote "+str(lcount)+" links to "+argv[2]+"."); > ? ? ?print("done.") > > if (__name__ == "__main__"): > ? ? ?#we call the main function passing a list of args, and exit with > the return code passed back. > ? ? ?sys.exit(main(sys.argv)) > > -- > > Thanks, > Ty This doesn't answer your original question, but excluding the command line handling, how's this do you?: import lxml from urlparse import urlsplit doc = lxml.html.parse('http://www.google.com') print map(urlsplit, doc.xpath('//a/@href')) [SplitResult(scheme='http', netloc='www.google.co.uk', path='/imghp', query='hl=en&tab=wi', fragment=''), SplitResult(scheme='http', netloc='video.google.co.uk', path='/', query='hl=en&tab=wv', fragment=''), SplitResult(scheme='http', netloc='maps.google.co.uk', path='/maps', query='hl=en&tab=wl', fragment=''), SplitResult(scheme='http', netloc='news.google.co.uk', path='/nwshp', query='hl=en&tab=wn', fragment=''), ...] Much nicer IMHO, plus the lxml.html has iterlinks() and other convenience functions for handling HTML. hth Jon. From howe.steven at gmail.com Tue Dec 21 14:10:04 2010 From: howe.steven at gmail.com (GrayShark) Date: Tue, 21 Dec 2010 13:10:04 -0600 Subject: seeking pygtk bindings for gtkdatabox Message-ID: Hello, a search for the python bindings for gtkdatabox lead no where. Anyone know of who is maintaining/working/siting such a package? Thanks in advance. Steven From nagle at animats.com Tue Dec 21 14:10:55 2010 From: nagle at animats.com (John Nagle) Date: Tue, 21 Dec 2010 11:10:55 -0800 Subject: Sending XML to a WEB Service and Getting Response Back In-Reply-To: References: <4d104a72$0$44000$742ec2ed@news.sonic.net> Message-ID: <4d10fbbd$0$44066$742ec2ed@news.sonic.net> On 12/20/2010 11:45 PM, Ian Kelly wrote: > On 12/20/2010 11:34 PM, John Nagle wrote: >> SOAPpy is way out of date. The last update on SourceForge was in >> 2001. > > 2007, actually: http://sourceforge.net/projects/pywebsvcs/files/ > > And there is repository activity within the past 9 months. Still, point > taken. The original SOAPpy was at http://sourceforge.net/projects/soapy/files/ but was apparently abandoned in 2001. Someone else picked it up and moved it to http://sourceforge.net/projects/pywebsvcs/files/SOAP.py/ where it was last updated in 2005. ZSI was last updated in 2007. Users are still submitting bug reports, but nobody is answering. Somebody posted "Who maintains the pywebsvcs webpage?" in February 2009, but no one answered them. There's also "Python SOAP" http://sourceforge.net/projects/pythonsoap/ abandoned in 2005. The "suds" module http://sourceforge.net/projects/python-suds/ was last updated in March, 2010. That version will work with Python 2.6, and probably 2.7. There's very little project activity, but at least it's reasonably current. John Nagle From msarro at gmail.com Tue Dec 21 14:17:40 2010 From: msarro at gmail.com (Matty Sarro) Date: Tue, 21 Dec 2010 14:17:40 -0500 Subject: Scanning directories for new files? Message-ID: Hey everyone. I'm in the midst of writing a parser to clean up incoming files, remove extra data that isn't needed, normalize some values, etc. The base files will be uploaded via FTP. How does one go about scanning a directory for new files? For now we're looking to run it as a cron job but eventually would like to move away from that into making it a service running in the background. From georg at python.org Tue Dec 21 14:18:56 2010 From: georg at python.org (Georg Brandl) Date: Tue, 21 Dec 2010 20:18:56 +0100 Subject: [RELEASED] Python 3.2 beta 2 Message-ID: <4D10FDA0.7090808@python.org> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On behalf of the Python development team, I'm happy to announce the second beta preview release of Python 3.2. Python 3.2 is a continuation of the efforts to improve and stabilize the Python 3.x line. Since the final release of Python 2.7, the 2.x line will only receive bugfixes, and new features are developed for 3.x only. Since PEP 3003, the Moratorium on Language Changes, is in effect, there are no changes in Python's syntax and built-in types in Python 3.2. Development efforts concentrated on the standard library and support for porting code to Python 3. Highlights are: * numerous improvements to the unittest module * PEP 3147, support for .pyc repository directories * PEP 3149, support for version tagged dynamic libraries * PEP 3148, a new futures library for concurrent programming * PEP 384, a stable ABI for extension modules * PEP 391, dictionary-based logging configuration * an overhauled GIL implementation that reduces contention * an extended email package that handles bytes messages * countless fixes regarding bytes/string issues; among them full support for a bytes environment (filenames, environment variables) * many consistency and behavior fixes for numeric operations * a sysconfig module to access configuration information * a pure-Python implementation of the datetime module * additions to the shutil module, among them archive file support * improvements to pdb, the Python debugger For a more extensive list of changes in 3.2, see http://docs.python.org/3.2/whatsnew/3.2.html To download Python 3.2 visit: http://www.python.org/download/releases/3.2/ Please consider trying Python 3.2 with your code and reporting any bugs you may notice to: http://bugs.python.org/ Enjoy! - -- Georg Brandl, Release Manager georg at python.org (on behalf of the entire python-dev team and 3.2's contributors) -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iEYEARECAAYFAk0Q/aAACgkQN9GcIYhpnLDf8gCgkLGAsE+T3R505jZc1RxXDYsa NSsAnRGaFjeTm9o2Z5O8FuIzTUG8t1PT =hHzz -----END PGP SIGNATURE----- From anurag.chourasia at gmail.com Tue Dec 21 14:26:52 2010 From: anurag.chourasia at gmail.com (Anurag Chourasia) Date: Wed, 22 Dec 2010 00:56:52 +0530 Subject: Sending XML to a WEB Service and Getting Response Back In-Reply-To: <4d10fbbd$0$44066$742ec2ed@news.sonic.net> References: <4d104a72$0$44000$742ec2ed@news.sonic.net> <4d10fbbd$0$44066$742ec2ed@news.sonic.net> Message-ID: Thanks for the response all. I tried exploring suds (which seems to be the current) and i hit problems right away. I will now try urllib or httplib. I have asked for help in the suds forum. Hope somebody replies. When i try to create a client, the error is as follows. >>> from suds.client import Client >>> url = 'http://10.251.4.33:8041/DteEnLinea/ws/EnvioGuia.jws' >>> client = Client(url) Traceback (most recent call last): File "", line 1, in File "suds/client.py", line 112, in __init__ self.wsdl = reader.open(url) File "suds/reader.py", line 152, in open d = self.fn(url, self.options) File "suds/wsdl.py", line 136, in __init__ d = reader.open(url) File "suds/reader.py", line 79, in open d = self.download(url) File "suds/reader.py", line 101, in download return sax.parse(string=content) File "suds/sax/parser.py", line 136, in parse sax.parse(source) File "/usr/local/lib/python2.7/xml/sax/expatreader.py", line 107, in parse xmlreader.IncrementalParser.parse(self, source) File "/usr/local/lib/python2.7/xml/sax/xmlreader.py", line 123, in parse self.feed(buffer) File "/usr/local/lib/python2.7/xml/sax/expatreader.py", line 211, in feed self._err_handler.fatalError(exc) File "/usr/local/lib/python2.7/xml/sax/handler.py", line 38, in fatalError raise exception xml.sax._exceptions.SAXParseException: :1:62: syntax error >>> [3] + Stopped (SIGTSTP) python This seems to be a old problem passing versions. Regards, Anurag On Wed, Dec 22, 2010 at 12:40 AM, John Nagle wrote: > On 12/20/2010 11:45 PM, Ian Kelly wrote: >> >> On 12/20/2010 11:34 PM, John Nagle wrote: >>> >>> SOAPpy is way out of date. The last update on SourceForge was in >>> 2001. >> >> 2007, actually: http://sourceforge.net/projects/pywebsvcs/files/ >> >> And there is repository activity within the past 9 months. Still, point >> taken. > > ? The original SOAPpy was at > > ? ? ? ?http://sourceforge.net/projects/soapy/files/ > > but was apparently abandoned in 2001. Someone else picked > it up and moved it to > > ? ? ? ?http://sourceforge.net/projects/pywebsvcs/files/SOAP.py/ > > where it was last updated in 2005. ?ZSI was last updated in > 2007. ?Users are still submitting bug reports, but nobody > is answering. ?Somebody posted "Who maintains the pywebsvcs webpage?" > in February 2009, but no one answered them. > > ? ?There's also "Python SOAP" > > http://sourceforge.net/projects/pythonsoap/ > > abandoned in 2005. > > ? ?The "suds" module > > http://sourceforge.net/projects/python-suds/ > > was last updated in March, 2010. ?That version > will work with Python 2.6, and probably 2.7. > There's very little project activity, but at > least it's reasonably current. > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?John Nagle > -- > http://mail.python.org/mailman/listinfo/python-list > From joncle at googlemail.com Tue Dec 21 14:34:00 2010 From: joncle at googlemail.com (Jon Clements) Date: Tue, 21 Dec 2010 11:34:00 -0800 (PST) Subject: Scanning directories for new files? References: Message-ID: On Dec 21, 7:17?pm, Matty Sarro wrote: > Hey everyone. > I'm in the midst of writing a parser to clean up incoming files, > remove extra data that isn't needed, normalize some values, etc. The > base files will be uploaded via FTP. > How does one go about scanning a directory for new files? For now > we're looking to run it as a cron job but eventually would like to > move away from that into making it a service running in the > background. Not a direct answer, but I would choose the approach of letting the FTP server know when a new file has been added. For instance: http://www.pureftpd.org/project/pure-ftpd - "Any external shell script can be called after a successful upload. Virus scanners and database archiveal can easily be set up." Of course, there's loads more servers, that I'm sure will have callback events or similar. Although, yes, the monitoring the file system is completely possible. hth Jon. From stefan.sonnenberg at pythonmeister.com Tue Dec 21 14:36:13 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Tue, 21 Dec 2010 20:36:13 +0100 Subject: Scanning directories for new files? In-Reply-To: References: Message-ID: <4D1101AD.2090105@pythonmeister.com> Am 21.12.2010 20:17, schrieb Matty Sarro: > Hey everyone. > I'm in the midst of writing a parser to clean up incoming files, > remove extra data that isn't needed, normalize some values, etc. The > base files will be uploaded via FTP. > How does one go about scanning a directory for new files? For now > we're looking to run it as a cron job but eventually would like to > move away from that into making it a service running in the > background. When You say cron, I assume you're running linux. One approach would be to os.walk() the directory in question, and filling a dict with the absolute name of the file as key and the output from stat() as content. Then re-scan regularly and check for changes in mtime,ctime etc. A less ressource consuming approach would be to use Linux' inotify infrastructure, which can be used from python https://github.com/seb-m/pyinotify And, your service is only an import away :-) https://github.com/seb-m/pyinotify/blob/master/python2/examples/daemon.py From martin at address-in-sig.invalid Tue Dec 21 14:51:25 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Tue, 21 Dec 2010 19:51:25 +0000 (UTC) Subject: Scanning directories for new files? References: Message-ID: On Tue, 21 Dec 2010 14:17:40 -0500, Matty Sarro wrote: > Hey everyone. > I'm in the midst of writing a parser to clean up incoming files, remove > extra data that isn't needed, normalize some values, etc. The base files > will be uploaded via FTP. > How does one go about scanning a directory for new files? For now we're > looking to run it as a cron job but eventually would like to move away > from that into making it a service running in the background. > Make sure the files are initially uploaded using a name that the parser isn't looking for and rename it when the upload is finished. This way the parser won't try to process a partially loaded file. If you are uploading to a *nix machine You the rename can move the file between directories provided both directories are in the same filing system. Under those conditions rename is always an atomic operation with no copying involved. This would you to, say, upload the file to "temp/ myfile" and renamed it to "uploaded/myfile" with your parser only scanning the uploaded directory and, presumably, renaming processed files to move them to a third directory ready for further processing. I've used this technique reliably with files arriving via FTP at quite high rates. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From fal at togliquesto.fastwebnet.it Tue Dec 21 14:54:02 2010 From: fal at togliquesto.fastwebnet.it (Francesco) Date: Tue, 21 Dec 2010 20:54:02 +0100 Subject: If/then style question In-Reply-To: <4d0d4c42$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <4d0aa5e7$0$29997$c3e8da3$5496439d@news.astraweb.com> <4D0C9B1B.2030605@togliquesto.fastwebnet.it> <4d0d4c42$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: I'd bet you would stress your point Steven! But you don't need to persuade me, I do already agree. I just meant to say that, when the advantage is little, there's no need to rewrite a working function. And that with modern CPUs, if tests take so little time, that even some redundant one is not so much of a nuisance. in your working example, the "payload" is just a couple of integer calculations, that take very little time too. So the overhead due to redundant if tests does show clearly. And also in that not-really-real situation, 60% overhead just meant less than 3 seconds. Just for the sake of discussion, I tried to give both functions some plough to pull, and a worst-case situation too: >>> t1 = Timer('for x in range(100): print func1(0),', ... 'from __main__ import func1') >>> >>> t2 = Timer('for x in range(100): print func2(0),', ... 'from __main__ import func2') >>> >>> min(t1.repeat(number=1, repeat=1)) -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 53.011015366479114 >>> min(t2.repeat(number=1, repeat=1)) -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 47.55442856564332 that accounts for a scant 11% overhead, on more than one million tests per cycle. That said, let's make really clear that I would heartily prefer func2 to func1, based both on readability and speed. Thank you for having spent some time playing with me! Francesco On 19/12/2010 1.05, Steven D'Aprano wrote: > Well, let's try it with a working (albeit contrived) example. This is > just an example -- obviously I wouldn't write the function like this in > real life, I'd use a while loop, but to illustrate the issue it will do. > > def func1(n): > result = -1 > done = False > n = (n+1)//2 > if n%2 == 1: > result = n > done = True > if not done: > n = (n+1)//2 > if n%2 == 1: > result = n > done = True > if not done: > n = (n+1)//2 > if n%2 == 1: > result = n > done = True > if not done: > for i in range(1000000): > if not done: > n = (n+1)//2 > if n%2 == 1: > result = n > done = True > return result > > > def func2(n): > n = (n+1)//2 > if n%2 == 1: > return n > n = (n+1)//2 > if n%2 == 1: > return n > n = (n+1)//2 > if n%2 == 1: > return n > for i in range(1000000): > n = (n+1)//2 > if n%2 == 1: > return n > return -1 > > > Not only is the second far more readable that the first, but it's also > significantly faster: > >>>> from timeit import Timer >>>> t1 = Timer('for i in range(20): x = func1(i)', > ... 'from __main__ import func1') >>>> t2 = Timer('for i in range(20): x = func2(i)', > ... 'from __main__ import func2') >>>> min(t1.repeat(number=10, repeat=5)) > 7.3219029903411865 >>>> min(t2.repeat(number=10, repeat=5)) > 4.530779838562012 > > The first function does approximately 60% more work than the first, all > of it unnecessary overhead. > > > From howe.steven at gmail.com Tue Dec 21 15:03:20 2010 From: howe.steven at gmail.com (GrayShark) Date: Tue, 21 Dec 2010 14:03:20 -0600 Subject: Scanning directories for new files? References: Message-ID: On Tue, 21 Dec 2010 14:17:40 -0500, Matty Sarro wrote: > Hey everyone. > I'm in the midst of writing a parser to clean up incoming files, remove > extra data that isn't needed, normalize some values, etc. The base files > will be uploaded via FTP. > How does one go about scanning a directory for new files? For now we're > looking to run it as a cron job but eventually would like to move away > from that into making it a service running in the background. You can try pyinotify. Pyinotify is a Python module for monitoring filesystems changes. Pyinotify relies on a Linux Kernel feature (merged in kernel 2.6.13) called inotify. inotify is an event-driven notifier, its notifications are exported from kernel space to user space through three system calls. pyinotify binds these system calls and provides an implementation on top of them offering a generic and abstract way to manipulate those functionalities. I'm assuming your using Linux. You seem to be at least using UNIX (cron). read more at: http://pyinotify.sourceforge.net/ Steven From ian.g.kelly at gmail.com Tue Dec 21 15:26:00 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 21 Dec 2010 13:26:00 -0700 Subject: Sending XML to a WEB Service and Getting Response Back In-Reply-To: <4d10fbbd$0$44066$742ec2ed@news.sonic.net> References: <4d104a72$0$44000$742ec2ed@news.sonic.net> <4d10fbbd$0$44066$742ec2ed@news.sonic.net> Message-ID: On 12/21/2010 12:10 PM, John Nagle wrote: > The original SOAPpy was at > > http://sourceforge.net/projects/soapy/files/ > > but was apparently abandoned in 2001. Someone else picked > it up and moved it to > > http://sourceforge.net/projects/pywebsvcs/files/SOAP.py/ These are unrelated projects, AFACT. The former was released as version 0.1 on 4/27/01. According to the changelog, the first public release of the latter was version 0.5 on 4/17/01. From luismgz at gmail.com Tue Dec 21 16:56:58 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Tue, 21 Dec 2010 13:56:58 -0800 (PST) Subject: Python 3.2 beta 2 References: Message-ID: I wonder if Unladen Swallow is still being considered for merger with Python 3.3. Is it? On Dec 21, 4:18?pm, Georg Brandl wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On behalf of the Python development team, I'm happy to announce the > second beta preview release of Python 3.2. > > Python 3.2 is a continuation of the efforts to improve and stabilize the > Python 3.x line. ?Since the final release of Python 2.7, the 2.x line > will only receive bugfixes, and new features are developed for 3.x only. > > Since PEP 3003, the Moratorium on Language Changes, is in effect, there > are no changes in Python's syntax and built-in types in Python 3.2. > Development efforts concentrated on the standard library and support for > porting code to Python 3. ?Highlights are: > > * numerous improvements to the unittest module > * PEP 3147, support for .pyc repository directories > * PEP 3149, support for version tagged dynamic libraries > * PEP 3148, a new futures library for concurrent programming > * PEP 384, a stable ABI for extension modules > * PEP 391, dictionary-based logging configuration > * an overhauled GIL implementation that reduces contention > * an extended email package that handles bytes messages > * countless fixes regarding bytes/string issues; among them full > ? support for a bytes environment (filenames, environment variables) > * many consistency and behavior fixes for numeric operations > * a sysconfig module to access configuration information > * a pure-Python implementation of the datetime module > * additions to the shutil module, among them archive file support > * improvements to pdb, the Python debugger > > For a more extensive list of changes in 3.2, see > > ? ?http://docs.python.org/3.2/whatsnew/3.2.html > > To download Python 3.2 visit: > > ? ?http://www.python.org/download/releases/3.2/ > > Please consider trying Python 3.2 with your code and reporting any bugs > you may notice to: > > ? ?http://bugs.python.org/ > > Enjoy! > > - -- > Georg Brandl, Release Manager > georg at python.org > (on behalf of the entire python-dev team and 3.2's contributors) > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.11 (GNU/Linux) > > iEYEARECAAYFAk0Q/aAACgkQN9GcIYhpnLDf8gCgkLGAsE+T3R505jZc1RxXDYsa > NSsAnRGaFjeTm9o2Z5O8FuIzTUG8t1PT > =hHzz > -----END PGP SIGNATURE----- From martin at v.loewis.de Tue Dec 21 17:10:56 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Tue, 21 Dec 2010 23:10:56 +0100 Subject: Python 3.2 beta 2 In-Reply-To: References: Message-ID: <4D1125F0.5010505@v.loewis.de> Am 21.12.2010 22:56, schrieb Luis M. Gonz?lez: > I wonder if Unladen Swallow is still being considered for merger with > Python 3.3. > Is it? 3.2 isn't even released yet, and 3.3 will appear 18 months after it (so in Summer 2012). It's much too early to tell. OTOH, to answer you literal question: most certainly. At least you seem to be considering it, so it's certainly being considered by somebody. Regards, Martin From ddasilva at umd.edu Tue Dec 21 17:17:22 2010 From: ddasilva at umd.edu (Daniel da Silva) Date: Tue, 21 Dec 2010 17:17:22 -0500 Subject: Funny __future__ imports Message-ID: from __future__ import space_shuttle DeprecationWarning: will be removed in next release Post yours! -------------- next part -------------- An HTML attachment was scrubbed... URL: From arnodel at gmail.com Tue Dec 21 18:27:33 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Tue, 21 Dec 2010 23:27:33 +0000 Subject: True lists in python? References: <4d0dc70d$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87zkryaeqi.fsf@gmail.com> Duncan Booth writes: > I guess you might be able to do it with a double-linked list provided > that when traversing the list you always keep two nodes around to > determine the direction. e.g. instead of asking for node6.nextNode() you > ask for node6.nextNode(previous=node1) and then the code can return > whichever sibling wasn't given. That would make reversal (assuming you > have both nodes) O(1), but would make traversing the list slower. There used to be a trick to implement doubly linked lists with the same memory footprint as singly linked ones: instead of each node storing two pointers (one to the next node, one to the previous one), you just store one value: (previous node) xor (next node) This means that when traversing the list, you need to always remember which node you are coming from. But it also makes these lists kind of symmetrical. -- Arnaud From joncle at googlemail.com Tue Dec 21 20:12:39 2010 From: joncle at googlemail.com (Jon Clements) Date: Tue, 21 Dec 2010 17:12:39 -0800 (PST) Subject: Specialisation / Interests Message-ID: <47fb5d39-a934-4906-8b4b-44d79ad52613@29g2000yqq.googlegroups.com> Hi all, Was thinking tonight (now this morning my time): What would we consider the "long time" posters on c.l.p consider what they respond to and offer serious advice on. For instance: - Raymond Hettinger for algo's in collections and itertools - MRAB for regex's (never seen him duck a post where re was (not) required. - the "effbot" for PIL & ElementTree - Mark Hammond for work on win32 - Mark Dickinson for floating point/number theory etc... Then so many others!... I'm leaving a huge amount out, so no rudeness intended - but what you think guys and gals? Cheers, Jon. From ncoghlan at gmail.com Tue Dec 21 20:15:34 2010 From: ncoghlan at gmail.com (Nick Coghlan) Date: Wed, 22 Dec 2010 12:15:34 +1100 Subject: [python-committers] [RELEASED] Python 3.2 beta 2 In-Reply-To: <4D10FDA0.7090808@python.org> References: <4D10FDA0.7090808@python.org> Message-ID: On Wed, Dec 22, 2010 at 6:18 AM, Georg Brandl wrote: > Since PEP 3003, the Moratorium on Language Changes, is in effect, there > are no changes in Python's syntax and built-in types in Python 3.2. Minor nit - we actually did tweak a few of the builtin types a bit (mostly the stuff to improve Sequence ABC conformance and to make range objects more list-like) Cheers, Nick. -- Nick Coghlan?? |?? ncoghlan at gmail.com?? |?? Brisbane, Australia From python at mrabarnett.plus.com Tue Dec 21 21:38:35 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 22 Dec 2010 02:38:35 +0000 Subject: Funny __future__ imports In-Reply-To: References: Message-ID: <4D1164AB.5020409@mrabarnett.plus.com> On 21/12/2010 22:17, Daniel da Silva wrote: > from __future__ import space_shuttle > DeprecationWarning: will be removed in next release > > > Post yours! > from __future__ import time_machine ImportError: time_machine in use by import From emile at fenx.com Tue Dec 21 22:16:28 2010 From: emile at fenx.com (Emile van Sebille) Date: Tue, 21 Dec 2010 19:16:28 -0800 Subject: Funny __future__ imports In-Reply-To: <4D1164AB.5020409@mrabarnett.plus.com> References: <4D1164AB.5020409@mrabarnett.plus.com> Message-ID: On 12/21/2010 6:38 PM MRAB said... > On 21/12/2010 22:17, Daniel da Silva wrote: >> from __future__ import space_shuttle >> DeprecationWarning: will be removed in next release >> >> >> Post yours! >> > from __future__ import time_machine > ImportError: time_machine in use by import from __future__ import improved_realestate_market ValueError: realestate market depreciated :) From nagle at animats.com Tue Dec 21 22:24:21 2010 From: nagle at animats.com (John Nagle) Date: Tue, 21 Dec 2010 19:24:21 -0800 Subject: Sending XML to a WEB Service and Getting Response Back In-Reply-To: References: <4d104a72$0$44000$742ec2ed@news.sonic.net> <4d10fbbd$0$44066$742ec2ed@news.sonic.net> Message-ID: <4d116f63$0$44060$742ec2ed@news.sonic.net> On 12/21/2010 11:26 AM, Anurag Chourasia wrote: > Thanks for the response all. > > I tried exploring suds (which seems to be the current) and i hit > problems right away. I will now try urllib or httplib. > > I have asked for help in the suds forum. Hope somebody replies. > > When i try to create a client, the error is as follows. > >>>> from suds.client import Client >>>> url = 'http://10.251.4.33:8041/DteEnLinea/ws/EnvioGuia.jws' >>>> client = Client(url) > > Traceback (most recent call last): > File "", line 1, in > File "suds/client.py", line 112, in __init__ > self.wsdl = reader.open(url) > File "suds/reader.py", line 152, in open > d = self.fn(url, self.options) > File "suds/wsdl.py", line 136, in __init__ > d = reader.open(url) > File "suds/reader.py", line 79, in open > d = self.download(url) > File "suds/reader.py", line 101, in download > return sax.parse(string=content) > File "suds/sax/parser.py", line 136, in parse > sax.parse(source) > File "/usr/local/lib/python2.7/xml/sax/expatreader.py", line 107, in parse > xmlreader.IncrementalParser.parse(self, source) > File "/usr/local/lib/python2.7/xml/sax/xmlreader.py", line 123, in parse > self.feed(buffer) > File "/usr/local/lib/python2.7/xml/sax/expatreader.py", line 211, in feed > self._err_handler.fatalError(exc) > File "/usr/local/lib/python2.7/xml/sax/handler.py", line 38, in fatalError > raise exception > xml.sax._exceptions.SAXParseException::1:62: syntax error >>>> [3] + Stopped (SIGTSTP) python > > This seems to be a old problem passing versions. > > Regards, > Anurag Try posting a URL that isn't on network 10. That's some local network at your end. John Nagle From cpblpublic at gmail.com Tue Dec 21 23:33:01 2010 From: cpblpublic at gmail.com (C Barrington-Leigh) Date: Tue, 21 Dec 2010 20:33:01 -0800 (PST) Subject: Bug in fixed_point?! References: <08b56619-c21e-40b8-bafa-490fb6c6277e@z19g2000yqb.googlegroups.com> Message-ID: <2a930684-1d6b-4ed4-8bcc-a3a558479166@z9g2000yqz.googlegroups.com> On Dec 21, 9:36?am, Robert Kern wrote: > When you do, please provide the information that Terry Reedy asked for. > Sorry; quite right. For completeness I'll post here as well as over on scipy. Here's the actual code: --------------------- from scipy import optimize from math import exp xxroot= optimize.fixed_point(lambda xx: exp(-2.0*xx)/2.0, 1.0, args=(), xtol=1e-12, maxiter=500) print ' %f solves fixed point, ie f(%f)=%f ?'% (xxroot,xxroot,exp(-2.0*xxroot)/2.0) Here is the output ------------------ Python 2.6.6 (r266:84292, Sep 15 2010, 16:22:56) In [1]: run tmp.py 0.332058 solves fixed point, ie f(0.332058)=0.257364 ? From benedict.verheyen at gmail.com Wed Dec 22 03:33:27 2010 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Wed, 22 Dec 2010 09:33:27 +0100 Subject: compiling Python 2.7.1 with readline module fails on Debian (Virtualbox) Message-ID: Hi, i'm trying to compile Python 2.7.1 on Debian (Virtual Box). Compiling end successfully but readline and curses fail to build. I'm working with virtualenv and I install all my packages in $HOME/local. I've downloaded readline, compiled and installed it in $HOME/local, same with ncurses. Both were the latest releases. But somehow, Python isn't able to build them. I get this message: Failed to build these modules: _curses _curses_panel readline So it does seems to find the modules. I'm not used to dealing with configure, and make so i can't debug much. I first tried this configure line: ./configure --enable-shared --prefix=$HOME/local Next i tried this one: env CPPFLAGS="-I$HOME/local/include" LDFLAGS="-L$HOME/local/lib" ./configure --enable-shared --prefix=$HOME/local But make yields the same error. Any clues on what I do wrong? The source of ncurses and readline are placed in $HOME/src. Both packages are installed in $HOME/local Thanks for any advice, Regards, Benedict From mark at mark-fink.de Wed Dec 22 03:50:04 2010 From: mark at mark-fink.de (Mark Fink) Date: Wed, 22 Dec 2010 00:50:04 -0800 (PST) Subject: Question regarding Higher-Order-Programming in Python Message-ID: <7819f726-244a-4b6e-9cde-6bde9fe286df@30g2000yql.googlegroups.com> I am about to learn Higher-Order-Programming with Lisp, Haskell, and Python. Some people who have gone completely out of their mind call this FP. In Haskell I learned that when I use map on a list it starts nesting as soon as I start adding elements. If I do not like the nesting I use ConcatMap. In Python I have a similar scenario. I have a generator which creates some combinatorics of a input dictionary. The list starts nesting. Now I could use reduce(concat, ...) which would be the correct thing from a functional perspective. But from a resource utilization perspective it is not a good idea since the reduce is executing the generator. I tried to illustrate this using a small example (the often in combinatorics the real thing would be much bigger that is why I need to use a generator): >>> from operator import itemgetter, concat >>> import itertools as it >>> from functools import partial >>> >>> dims = {'number': [1,2,3], 'letter': ['a', 'b'], 'special': ['+', '-']} >>> dims {'special': ['+', '-'], 'number': [1, 2, 3], 'letter': ['a', 'b']} >>> def get_products(keys): ... # helper to get products from keys in the following form: ... # [('bold', True), ('color', 'black')] ... values = itemgetter(*keys)(dims) ... product = it.product(*values) ... return map(partial(zip, keys), product) ... >>> comb = it.combinations(dims, 2) >>> comb_l = list(comb) >>> comb_l [('special', 'number'), ('special', 'letter'), ('number', 'letter')] >>> res = map(get_products, comb_l) >>> res [[[('special', '+'), ('number', 1)], [('special', '+'), ('number', 2)], [('special', '+'), ('number', 3)], [('special', '-'), ('number', 1)], [('special', '-'), ('number', 2)], [('special', '-'), ('number', 3)]], [[('special', '+'), ('letter', 'a')], [('special', '+'), ('letter', 'b')], [('special', '-'), ('letter', 'a')], [('special', '-'), ('letter', 'b')]], [[('number', 1), ('letter', 'a')], [('number', 1), ('letter', 'b')], [('number', 2), ('letter', 'a')], [('number', 2), ('letter', 'b')], [('number', 3), ('letter', 'a')], [('number', 3), ('letter', 'b')]]] # the resulting list is nested one level to deep caused by the map(get_products, .. >>> My problem is that I want to get single elements from the generator like [('special', '+'), ('number', 1)]. But this does not work because the list is now nested to deep. That is what I expect: (I could get something like that with the following >>> res = reduce(concat, res) [[('special', '+'), ('number', 1)], [('special', '+'), ('number', 2)], [('special', '+'), ('number', 3)], [('special', '-'), ('number', 1)], [('special', '-'), ('number', 2)], [('special', '-'), ('number', 3)], [('special', '+'), ('letter', 'a')], [('special', '+'), ('letter', 'b')], [('special', '-'), ('letter', 'a')], [('special', '-'), ('letter', 'b')], [('number', 1), ('letter', 'a')], [('number', 1), ('letter', 'b')], [('number', 2), ('letter', 'a')], [('number', 2), ('letter', 'b')], [('number', 3), ('letter', 'a')], [('number', 3), ('letter', 'b')]] I have seen the problem many times but so far I could not google a solution on the web. By the way do you know any substantial example using FP in Python (generators, imap, ifilter, ...)? From kentilton at gmail.com Wed Dec 22 05:43:42 2010 From: kentilton at gmail.com (kenny) Date: Wed, 22 Dec 2010 02:43:42 -0800 (PST) Subject: Mo Better Lisp Jobs Message-ID: Check it out: http://lispjobs.wordpress.com/2010/12/22/lisp-developer-mcna-fort-laurderdale-florida/ We already have six splendid folks but business is booming and at least one contract bid has to happen faster than we thought (potential client moved it up) so we are looking to take on a couple more. Lisp wannabe Rails gurus lurking here, plz note the opportunity described in the listing. The rest of the cross-posting is to find great coders with light Lisp. We can talk. HK From __peter__ at web.de Wed Dec 22 07:57:02 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 22 Dec 2010 13:57:02 +0100 Subject: Question regarding Higher-Order-Programming in Python References: <7819f726-244a-4b6e-9cde-6bde9fe286df@30g2000yql.googlegroups.com> Message-ID: Mark Fink wrote: > I am about to learn Higher-Order-Programming with Lisp, Haskell, and > Python. Some people who have gone completely out of their mind call > this FP. > > In Haskell I learned that when I use map on a list it starts nesting > as soon as I start adding elements. If I do not like the nesting I use > ConcatMap. > > In Python I have a similar scenario. I have a generator which creates > some combinatorics of a input dictionary. The list starts nesting. Now > I could use reduce(concat, ...) which would be the correct thing from > a functional perspective. But from a resource utilization perspective > it is not a good idea since the reduce is executing the generator. > > I tried to illustrate this using a small example (the often in > combinatorics the real thing would be much bigger that is why I need > to use a generator): > >>>> from operator import itemgetter, concat >>>> import itertools as it >>>> from functools import partial >>>> >>>> dims = {'number': [1,2,3], 'letter': ['a', 'b'], 'special': ['+', '-']} >>>> dims > {'special': ['+', '-'], 'number': [1, 2, 3], 'letter': ['a', 'b']} >>>> def get_products(keys): > ... # helper to get products from keys in the following form: > ... # [('bold', True), ('color', 'black')] > ... values = itemgetter(*keys)(dims) > ... product = it.product(*values) > ... return map(partial(zip, keys), product) > ... >>>> comb = it.combinations(dims, 2) >>>> comb_l = list(comb) >>>> comb_l > [('special', 'number'), ('special', 'letter'), ('number', 'letter')] >>>> res = map(get_products, comb_l) >>>> res > [[[('special', '+'), ('number', 1)], [('special', '+'), ('number', > 2)], [('special', '+'), ('number', 3)], [('special', '-'), ('number', > 1)], [('special', '-'), ('number', 2)], [('special', '-'), ('number', > 3)]], [[('special', '+'), ('letter', 'a')], [('special', '+'), > ('letter', 'b')], [('special', '-'), ('letter', 'a')], [('special', > '-'), ('letter', 'b')]], [[('number', 1), ('letter', 'a')], > [('number', 1), ('letter', 'b')], [('number', 2), ('letter', 'a')], > [('number', 2), ('letter', 'b')], [('number', 3), ('letter', 'a')], > [('number', 3), ('letter', 'b')]]] # the resulting list is nested one > level to deep caused by the map(get_products, .. >>>> > > My problem is that I want to get single elements from the generator > like [('special', '+'), ('number', 1)]. But this does not work because > the list is now nested to deep. Like this? >>> [(k, v) for k, vv in dims.iteritems() for v in vv] [('special', '+'), ('special', '-'), ('number', 1), ('number', 2), ('number', 3), ('letter', 'a'), ('letter', 'b')] But these are just glorified for-loops, so: >>> list(chain.from_iterable(starmap(product, izip(izip(dims.iterkeys()), dims.itervalues())))) [('special', '+'), ('special', '-'), ('number', 1), ('number', 2), ('number', 3), ('letter', 'a'), ('letter', 'b')] Peter From eric at trueblade.com Wed Dec 22 08:09:46 2010 From: eric at trueblade.com (Eric Smith) Date: Wed, 22 Dec 2010 08:09:46 -0500 Subject: [python-committers] [RELEASED] Python 3.2 beta 2 In-Reply-To: References: <4D10FDA0.7090808@python.org> Message-ID: <4D11F89A.3080103@trueblade.com> On 12/22/2010 8:46 AM, Georg Brandl wrote: > Am 22.12.2010 02:15, schrieb Nick Coghlan: >> On Wed, Dec 22, 2010 at 6:18 AM, Georg Brandl wrote: >>> Since PEP 3003, the Moratorium on Language Changes, is in effect, there >>> are no changes in Python's syntax and built-in types in Python 3.2. >> >> Minor nit - we actually did tweak a few of the builtin types a bit >> (mostly the stuff to improve Sequence ABC conformance and to make >> range objects more list-like) > > Indeed, I'll fix this wording for the next announcement. (And I will > mention SSL, sorry Antoine). If you're only going to mention some vague "some builtins had minor changes", then I'm fine with that. If you're going to enumerate all such changes, that will be a bigger job. There were 2 such changes I'm aware of: str.format_map (#6081) and the addition of alternate ("#") formatting to float, complex and decimal (#7094) __format__ methods. For this announcement I don't think it's necessary to list them all. From no.email at please.post Wed Dec 22 09:20:51 2010 From: no.email at please.post (kj) Date: Wed, 22 Dec 2010 14:20:51 +0000 (UTC) Subject: issubclass(dict, Mapping) Message-ID: In a message (<4cf97c94$0$30003$c3e8da3$5496439d at news.astraweb.com>) on a different thread, Steven D'Aprano tells me: >I suspect you're trying to make this more complicated than it actually >is. You keep finding little corner cases that expose implementation >details (such as the heap-types issue above) and leaping to the erroneous >conclusion that because you didn't understand this tiny little corner of >Python's class model, you didn't understand any of it. Python's object >model is relatively simple, but it does occasionally expose a few messy >corners. I disagree with your assessment. What you call "little corner cases" I call "fundamental", as in "you can't really call yourself competent with Python if you're ignorant about them". To use a term I first saw in an article by Joel Spolsky (http://is.gd/je42O), Python's object model is a rather "leaky abstraction". This refers to the situation in which a user is not shielded from the "implementation details". When an abstraction leaks, implementation details are no longer negligible, they cease to be "little corner cases". Here's another example, fresh from today's crop of wonders: (v. 2.7.0) >>> from collections import Mapping >>> issubclass(dict, Mapping) True >>> dict.__bases__ (,) >>> [issubclass(b, Mapping) for b in dict.__bases__] [False] So dict is a subclass of Mapping, even though none of the bases of dict is either Mapping or a subclass of Mapping. Great. I suspect this is another abstraction leak ("dict is *supposed* to be a Python class like all others, but in fact it's not *really*. You see, once upon a time..."). I conclude that, for me to understand Python's (rather leaky) object model abstraction, I have to understand its underlying implementation. Unfortunately, as far as I know, there's no other choice but to study the source code, since there's no other more readable description of this implementation. Maybe there are fewer "abstraction leaks" in 3.0... ~kj From mark at mark-fink.de Wed Dec 22 09:35:26 2010 From: mark at mark-fink.de (Mark Fink) Date: Wed, 22 Dec 2010 06:35:26 -0800 (PST) Subject: Question regarding Higher-Order-Programming in Python References: <7819f726-244a-4b6e-9cde-6bde9fe286df@30g2000yql.googlegroups.com> Message-ID: <1dc2d2aa-a352-4f71-9cbe-dffb72be17e4@i17g2000vbq.googlegroups.com> > >>> list(chain.from_iterable(starmap(product, izip(izip(dims.iterkeys()), > > dims.itervalues())))) > [('special', '+'), ('special', '-'), ('number', 1), ('number', 2), > ('number', 3), ('letter', 'a'), ('letter', 'b')] > > Peter so far I have never noticed chain.from_iterable, but many thanks to you Peter, I have now a beautiful solution to this problem. >>> from itertools import chain >>> comb = it.combinations(dims, 2) >>> l = chain.from_iterable(it.imap(get_products, comb)) >>> l.next() [('special', '+'), ('number', 1)] >>> l.next() [('special', '+'), ('number', 2)] From awilliam at whitemice.org Wed Dec 22 09:35:48 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Wed, 22 Dec 2010 09:35:48 -0500 Subject: issubclass(dict, Mapping) In-Reply-To: References: Message-ID: <1293028548.7799.39.camel@linux-yu4c.site> On Wed, 2010-12-22 at 14:20 +0000, kj wrote: > In a message (<4cf97c94$0$30003$c3e8da3$5496439d at news.astraweb.com>) > on a different thread, Steven D'Aprano tells me: > >I suspect you're trying to make this more complicated than it actually > >is. You keep finding little corner cases that expose implementation > >details (such as the heap-types issue above) and leaping to the erroneous > >conclusion that because you didn't understand this tiny little corner of > >Python's class model, you didn't understand any of it. Python's object > >model is relatively simple, but it does occasionally expose a few messy > >corners. > I disagree with your assessment. What you call "little corner > cases" I call "fundamental", as in "you can't really call yourself > competent with Python if you're ignorant about them". > To use a term I first saw in an article by Joel Spolsky > (http://is.gd/je42O), Python's object model is a rather "leaky > abstraction". This refers to the situation in which a user is not > shielded from the "implementation details". When an abstraction > leaks, implementation details are no longer negligible, they cease > to be "little corner cases". > Here's another example, fresh from today's crop of wonders: > (v. 2.7.0) > >>> from collections import Mapping > >>> issubclass(dict, Mapping) > True > >>> dict.__bases__ > (,) > >>> [issubclass(b, Mapping) for b in dict.__bases__] > [False] > So dict is a subclass of Mapping, even though none of the bases of > dict is either Mapping or a subclass of Mapping. Great. > I suspect this is another abstraction leak ("dict is *supposed* to > be a Python class like all others, but in fact it's not *really*. > You see, once upon a time..."). > I conclude that, for me to understand Python's (rather leaky) object > model abstraction, I have to understand its underlying implementation. > Unfortunately, as far as I know, there's no other choice but to > study the source code, since there's no other more readable > description of this implementation. > Maybe there are fewer "abstraction leaks" in 3.0... Boy howdy are you going to incite the ire of the Pythonistas! IMO, the "object model" isn't "leaky", it is simply "adhoc" and not really a "model" at all [write as many 800 page books as you want: if it walks like a zombie duck, smells like a zombie duck - it is still a zombie duck]. Performing introspection in Python is awful and a veritable land-mine of "implementation details". The short and honest answer is: avoid doing it whenever possible, try to figure out how to accomplish the task some other way. From solipsis at pitrou.net Wed Dec 22 09:44:01 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Wed, 22 Dec 2010 15:44:01 +0100 Subject: issubclass(dict, Mapping) References: Message-ID: <20101222154401.133e0072@pitrou.net> On Wed, 22 Dec 2010 14:20:51 +0000 (UTC) kj wrote: > > So dict is a subclass of Mapping, even though none of the bases of > dict is either Mapping or a subclass of Mapping. Great. > > I suspect this is another abstraction leak ("dict is *supposed* to > be a Python class like all others, but in fact it's not *really*. It is. You just haven't read about Python's ABCs (abstract base classes): http://docs.python.org/library/abc.html#abc.ABCMeta ? You can also register unrelated concrete classes (even built-in classes) and unrelated ABCs as ?virtual subclasses? ? these and their descendants will be considered subclasses of the registering ABC by the built-in issubclass() function, but the registering ABC won?t show up in their MRO (Method Resolution Order) nor will method implementations defined by the registering ABC be callable (not even via super()). ? With a very simple example in the register() doc: http://docs.python.org/library/abc.html#abc.ABCMeta.register Regards Antoine. From xahlee at gmail.com Wed Dec 22 09:46:34 2010 From: xahlee at gmail.com (Xah Lee) Date: Wed, 22 Dec 2010 06:46:34 -0800 (PST) Subject: Google AI challenge: planet war. Lisp won. References: <44a8f48f-e291-463e-a042-d0cbc31a2a4e@z17g2000prz.googlegroups.com> Message-ID: <1a10a457-6492-4ed6-98fd-bbb0829637c0@o23g2000prh.googlegroups.com> On Dec 20, 10:06?pm, "Jon Harrop" wrote: > Wasn't that the "challenge" where they wouldn't even accept solutions > written in many other languages (including both OCaml and F#)? Ocaml is one of the supported lang. See: http://ai-contest.com/starter_packages.php there are 12 teams using OCaml. See: http://ai-contest.com/rankings.php (click on the lang to see all teams using that lang) Xah From solipsis at pitrou.net Wed Dec 22 09:56:36 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Wed, 22 Dec 2010 15:56:36 +0100 Subject: issubclass(dict, Mapping) References: <1293028548.7799.39.camel@linux-yu4c.site> Message-ID: <20101222155636.3e46c6e7@pitrou.net> On Wed, 22 Dec 2010 09:35:48 -0500 Adam Tauno Williams wrote: > > IMO, the "object model" isn't "leaky", it is simply "adhoc" and not > really a "model" at all [write as many 800 page books as you want: if it > walks like a zombie duck, smells like a zombie duck - it is still a > zombie duck]. Performing introspection in Python is awful and a > veritable land-mine of "implementation details". Introspection is fine as long as you stick to officially promoted tools such as isinstance(), issubclass(), dir() or the inspect module. If you start looking inside the pants of the object model, you can have surprises :) Regards Antoine. From steve at holdenweb.com Wed Dec 22 10:31:06 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 22 Dec 2010 10:31:06 -0500 Subject: issubclass(dict, Mapping) In-Reply-To: References: Message-ID: On 12/22/2010 9:20 AM, kj wrote: [...] > I suspect this is another abstraction leak ("dict is *supposed* to > be a Python class like all others, but in fact it's not *really*. > You see, once upon a time..."). > So your suspicions are to be placed above the knowledge of those who really do understand Python's object model? That seems like a recipe for cargo cult programming ... > I conclude that, for me to understand Python's (rather leaky) object > model abstraction, I have to understand its underlying implementation. > Unfortunately, as far as I know, there's no other choice but to > study the source code, since there's no other more readable > description of this implementation. > You don't have to understand "the implementation" (there are at least five different implementations, which one will you choose as your standard?) > Maybe there are fewer "abstraction leaks" in 3.0... > Python deliberately exposes introspection interfaces, which you may use if you wish. As with all introspectable languages (including Java) if you push the envelope you are likely to hit corner cases. As Steven d'Aprano has already said, these *are* corner cases and not the whole of the language. Don't worry about having a complete knowledge of the language before you start to use it. That can induce paralysis ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From benedict.verheyen at gmail.com Wed Dec 22 11:04:42 2010 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Wed, 22 Dec 2010 17:04:42 +0100 Subject: compiling Python 2.7.1 with readline module fails on Debian (Virtualbox) In-Reply-To: References: Message-ID: On 22/12/2010 9:33, Benedict Verheyen wrote: > Hi, > > > i'm trying to compile Python 2.7.1 on Debian (Virtual Box). > Compiling end successfully but readline and curses fail to build. > > I'm working with virtualenv and I install all my packages in $HOME/local. > I've downloaded readline, compiled and installed it in $HOME/local, same with ncurses. > Both were the latest releases. > But somehow, Python isn't able to build them. > > I get this message: > > Failed to build these modules: > _curses _curses_panel readline > > So it does seems to find the modules. > I'm not used to dealing with configure, and make so i can't debug much. > I first tried this configure line: > ./configure --enable-shared --prefix=$HOME/local > > Next i tried this one: > env CPPFLAGS="-I$HOME/local/include" LDFLAGS="-L$HOME/local/lib" ./configure --enable-shared --prefix=$HOME/local > > But make yields the same error. > > Any clues on what I do wrong? > > The source of ncurses and readline are placed in $HOME/src. > Both packages are installed in $HOME/local > > Thanks for any advice, > > Regards, > Benedict > I found some additional info here: http://www.velocityreviews.com/forums/t733455-problem-building-python-2-7-with-enable-shared.html The error "-collect2: ld returned 1 exit status" is the same error as I'm getting. So what happens is that linking to python2.7 during make, doesn't link to the freshly build library, but to the existing in the system. Is there any solution for this? Or an option i can add to make/config? Cheers, Benedict From franapoli at gmail.com Wed Dec 22 11:22:22 2010 From: franapoli at gmail.com (Ciccio) Date: Wed, 22 Dec 2010 17:22:22 +0100 Subject: Regular expression for "key = value" pairs Message-ID: Hi all, suppose I have: s='a=b, c=d' and I want to extract sub-strings a,b,c and d from s (and in general from any longer list of such comma separated pairs). Some failed attempts: In [12]: re.findall(r'(.+)=(.+)', s) Out[12]: [('a=b, c', 'd')] In [13]: re.findall(r'(.+?)=(.+)', s) Out[13]: [('a', 'b, c=d')] In [14]: re.findall(r'(.+)=(.+)*', s) Out[14]: [('a=b, c', 'd')] In [15]: re.findall(r'(.+)=(.+),', s) Out[15]: [('a', 'b')] In [16]: re.findall(r'(.+)=(.+),?', s) Out[16]: [('a=b, c', 'd')] Thanks for your help, francesco. From cjwilliams43 at gmail.com Wed Dec 22 11:24:03 2010 From: cjwilliams43 at gmail.com (Colin J. Williams) Date: Wed, 22 Dec 2010 11:24:03 -0500 Subject: help with link parsing? In-Reply-To: <39ca82ab-1ed3-42d3-ba26-6f1915236e92@v17g2000vbo.googlegroups.com> References: <39ca82ab-1ed3-42d3-ba26-6f1915236e92@v17g2000vbo.googlegroups.com> Message-ID: On 21-Dec-10 12:22 PM, Jon Clements wrote: > import lxml > from urlparse import urlsplit > > doc = lxml.html.parse('http://www.google.com') > print map(urlsplit, doc.xpath('//a/@href')) > > [SplitResult(scheme='http', netloc='www.google.co.uk', path='/imghp', > query='hl=en&tab=wi', fragment=''), SplitResult(scheme='http', > netloc='video.google.co.uk', path='/', query='hl=en&tab=wv', > fragment=''), SplitResult(scheme='http', netloc='maps.google.co.uk', > path='/maps', query='hl=en&tab=wl', fragment=''), > SplitResult(scheme='http', netloc='news.google.co.uk', path='/nwshp', > query='hl=en&tab=wn', fragment=''), ...] Jon, What version of Python was used to run this? Colin W. From andre.roberge at gmail.com Wed Dec 22 11:36:27 2010 From: andre.roberge at gmail.com (=?ISO-8859-1?Q?Andr=E9?=) Date: Wed, 22 Dec 2010 08:36:27 -0800 (PST) Subject: Regular expression for "key = value" pairs In-Reply-To: Message-ID: <15d61e50-5bba-4241-9040-37175389095f@glegroupsg2000goo.googlegroups.com> On Wednesday, December 22, 2010 12:22:22 PM UTC-4, Francesco Napolitano wrote: > Hi all, > suppose I have: > > s='a=b, c=d' > > and I want to extract sub-strings a,b,c and d from s (and in general > from any longer list of such comma separated pairs). > Some failed attempts: > > In [12]: re.findall(r'(.+)=(.+)', s) > Out[12]: [('a=b, c', 'd')] > > In [13]: re.findall(r'(.+?)=(.+)', s) > Out[13]: [('a', 'b, c=d')] > > In [14]: re.findall(r'(.+)=(.+)*', s) > Out[14]: [('a=b, c', 'd')] > > In [15]: re.findall(r'(.+)=(.+),', s) > Out[15]: [('a', 'b')] > > In [16]: re.findall(r'(.+)=(.+),?', s) > Out[16]: [('a=b, c', 'd')] > How about the following: >>> s = 'a=b,c=d' >>> t = [] >>> for u in s.split(','): ... t.extend(u.split('=')) ... >>> t ['a', 'b', 'c', 'd'] HTH, Andr? > Thanks for your help, > francesco. From noreply at domain.invalid Wed Dec 22 11:40:21 2010 From: noreply at domain.invalid (William Gill) Date: Wed, 22 Dec 2010 11:40:21 -0500 Subject: simple games w/o pygame Message-ID: I am teaching an 11 year old who wants to learn programming. I chose Python, and it is working well. I seem to remember lots of simple script games, like quizzes, number games etc. that would be good for his tutorial. However, now all I can find is more complex games using Pygame. Can anyone help me out here? From vlastimil.brom at gmail.com Wed Dec 22 11:43:15 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Wed, 22 Dec 2010 17:43:15 +0100 Subject: Regular expression for "key = value" pairs In-Reply-To: References: Message-ID: 2010/12/22 Ciccio : > Hi all, > suppose I have: > > s='a=b, c=d' > > and I want to extract sub-strings a,b,c and d from s (and in general from > any longer list of such comma separated pairs). > Some failed attempts: > > In [12]: re.findall(r'(.+)=(.+)', s) > Out[12]: [('a=b, c', 'd')] > > [...] > Thanks for your help, > francesco. > -- > http://mail.python.org/mailman/listinfo/python-list > Hi, I am not sure, the regular expressions are best suited for this task, but if you have a predictable simple parameter list (with ho recursion, escaping commas or equal signs etc.), it might be viable; how about e.g. this pattern? >>> re.findall(r'([^=\s,]+)=([^=\s,]+)', s) [('a', 'b'), ('c', 'd')] >>> vbr From no.email at please.post Wed Dec 22 11:52:38 2010 From: no.email at please.post (kj) Date: Wed, 22 Dec 2010 16:52:38 +0000 (UTC) Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: In Robert Kern writes: >Obfuscating the location that an exception gets raised prevents a lot of >debugging... The Python interpreter does a lot of that "obfuscation" already, and I find the resulting tracebacks more useful for it. An error message is only useful to a given audience if that audience can use the information in the message to modify what they are doing to avoid the error. It is of no use (certainly no *immediate* use) to this audience to see tracebacks that go deep into code that they don't know anything about and cannot change. For example, consider this: #----------------------------------------------------------------- def foo(x, **k): pass def bar(*a, **k): if len(a) > 1: raise TypeError('too many args') def baz(*a, **k): _pre_baz(*a, **k) def _pre_baz(*a, **k): if len(a) > 1: raise TypeError('too many args') if __name__ == '__main__': from traceback import print_exc try: foo(1, 2) except: print_exc() try: bar(1, 2) except: print_exc() try: baz(1, 2) except: print_exc() #----------------------------------------------------------------- (The code in the "if __name__ == '__main__'" section is meant to simulate the general case in which the functions defined in this file are called by third-party code.) When you run this code the output is this (a few blank lines added for clarity): Traceback (most recent call last): File "/tmp/ex2.py", line 5, in try: foo(1, 2) TypeError: foo() takes exactly 1 argument (2 given) Traceback (most recent call last): File "/tmp/ex2.py", line 7, in try: bar(1, 2) File "/tmp/example.py", line 4, in bar if len(a) > 1: raise TypeError('too many args') TypeError: too many args Traceback (most recent call last): File "/tmp/ex2.py", line 9, in try: baz(1, 2) File "/tmp/example.py", line 6, in baz def baz(*a, **k): _pre_baz(*a, **k) File "/tmp/example.py", line 9, in _pre_baz if len(a) > 1: raise TypeError('too many args') TypeError: too many args In all cases, the *programming* errors are identical: functions called with the wrong arguments. The traceback from foo(1, 2) tells me this very clearly, and I'm glad that Python is not also giving me the traceback down to where the underlying C code throws the exception: I don't need to see all this machinery. In contrast, the tracebacks from bar(1, 2) and baz(1, 2) obscure the fundamental problem with useless detail. From the point of view of the programmer that is using these functions, it is of no use to know that the error resulted from some "raise TypeError" statement somewhere, let alone that this happened in some obscure, private function _pre_baz. Perhaps I should have made it clearer in my original post that the tracebacks I want to clean up are those from exceptions *explicitly* raised by my argument-validating helper function, analogous to _pre_baz above. I.e. I want that when my spam function is called (by code written by someone else) with the wrong arguments, the traceback looks more like this Traceback (most recent call last): File "/some/python/code.py", line 123, in spam(some, bad, args) TypeError: the second argument is bad than like this: Traceback (most recent call last): File "/some/python/code.py", line 123, in spam(some, bad, args) File "/my/niftymodule.py", line 456, in niftymodule _pre_spam(*a, **k) File "/my/niftymodule.py", line 789, in __pre_spam raise TypeError('second argument to spam is bad') TypeError: the second argument is bad In my opinion, the idea that more is always better in a traceback is flat out wrong. As the example above illustrates, the most useful traceback is the one that stops at the deepest point where the *intended audience* for the traceback can take action, and goes no further. The intended audience for the errors generated by my argument-checking functions should see no further than the point where they called a function incorrectly. ~kj From mdw at distorted.org.uk Wed Dec 22 11:53:43 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 22 Dec 2010 16:53:43 +0000 Subject: Regular expression for "key = value" pairs References: Message-ID: <87tyi5wxyg.fsf.mdw@metalzone.distorted.org.uk> Ciccio writes: > suppose I have: > > s='a=b, c=d' > > and I want to extract sub-strings a,b,c and d from s (and in general > from any longer list of such comma separated pairs). [...] > In [12]: re.findall(r'(.+)=(.+)', s) > Out[12]: [('a=b, c', 'd')] I think there are two logically separate jobs here: firstly, extracting the comma-separated pairs, and secondly parsing the individual pairs. If you want the extra problem of dealing with regular expressions, this seems to be the way to do it. R_PAIR = re.compile(r''' ^\s* ([^=\s]|[^=\s][^=]*[^=\s]) \s*=\s* (\S|\S.*\S) \s*$ ''', re.X) def parse_pair(pair): m = R_PAIR.match(pair) if not m: raise ValueError, 'not a `KEY = VALUE\' pair' return m.groups([1, 2]) The former is even easier. R_COMMA = re.compile(r'\s*,\s*') kvs = [parse_pair(p) for p in R_COMMA.split(string)] Apply gold-plating to taste. But actually, it's much easier to avoid messing with regular expressions at all. def parse_pair(pair): eq = pair.index('=') return pair[:eq].strip(), pair[eq + 1:].strip() kvs = [parse_pair(p) for p in string.split(',')] -- [mdw] From mdw at distorted.org.uk Wed Dec 22 11:55:27 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 22 Dec 2010 16:55:27 +0000 Subject: Regular expression for "key = value" pairs References: <15d61e50-5bba-4241-9040-37175389095f@glegroupsg2000goo.googlegroups.com> Message-ID: <87pqstwxvk.fsf.mdw@metalzone.distorted.org.uk> Andr? writes: > How about the following: > > >>> s = 'a=b,c=d' > >>> t = [] > >>> for u in s.split(','): > ... t.extend(u.split('=')) s = 'a = b = c, d = e' => ['a ', ' b ', ' c', ' d ', ' e'] Ugh. -- [mdw] From joncle at googlemail.com Wed Dec 22 11:56:11 2010 From: joncle at googlemail.com (Jon Clements) Date: Wed, 22 Dec 2010 08:56:11 -0800 (PST) Subject: help with link parsing? References: <39ca82ab-1ed3-42d3-ba26-6f1915236e92@v17g2000vbo.googlegroups.com> Message-ID: On Dec 22, 4:24?pm, "Colin J. Williams" wrote: > On 21-Dec-10 12:22 PM, Jon Clements wrote: > > > import lxml > > from urlparse import urlsplit > > > doc = lxml.html.parse('http://www.google.com') > > print map(urlsplit, doc.xpath('//a/@href')) > > > [SplitResult(scheme='http', netloc='www.google.co.uk', path='/imghp', > > query='hl=en&tab=wi', fragment=''), SplitResult(scheme='http', > > netloc='video.google.co.uk', path='/', query='hl=en&tab=wv', > > fragment=''), SplitResult(scheme='http', netloc='maps.google.co.uk', > > path='/maps', query='hl=en&tab=wl', fragment=''), > > SplitResult(scheme='http', netloc='news.google.co.uk', path='/nwshp', > > query='hl=en&tab=wn', fragment=''), ...] > > Jon, > > What version of Python was used to run this? > > Colin W. 2.6.5 - the lxml library is not a standard module though and needs to be installed. From ethan at stoneleaf.us Wed Dec 22 12:19:26 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 22 Dec 2010 09:19:26 -0800 Subject: issubclass(dict, Mapping) In-Reply-To: References: Message-ID: <4D12331E.3090007@stoneleaf.us> kj wrote: > In a message (<4cf97c94$0$30003$c3e8da3$5496439d at news.astraweb.com>) > on a different thread, Steven D'Aprano tells me: > >> I suspect you're trying to make this more complicated than it actually >> is. You keep finding little corner cases that expose implementation >> details (such as the heap-types issue above) and leaping to the erroneous >> conclusion that because you didn't understand this tiny little corner of >> Python's class model, you didn't understand any of it. Python's object >> model is relatively simple, but it does occasionally expose a few messy >> corners. > > I disagree with your assessment. What you call "little corner > cases" I call "fundamental", as in "you can't really call yourself > competent with Python if you're ignorant about them". So where on the sliding scale do you place 'competent'? It sounds to me like you are looking at 'master'. > Here's another example, fresh from today's crop of wonders: > > (v. 2.7.0) >>>> from collections import Mapping >>>> issubclass(dict, Mapping) > True >>>> dict.__bases__ > (,) >>>> [issubclass(b, Mapping) for b in dict.__bases__] > [False] Firstly, as I'm sure you know, if you don't import Mapping from collections the issubclass test fails with a NameError. Secondly, why do you care? Did you get bitten by something? Some error, or worse, silently got wrong results? (Sincere question.) > So dict is a subclass of Mapping, even though none of the bases of > dict is either Mapping or a subclass of Mapping. Great. > > I suspect this is another abstraction leak My take on abstraction leaks is when the underlying actuality shows through in a non-ignorable way -- so I ask again, how is this discrepancy making it so you can't ignore it? ~Ethan~ From post at andre-bell.de Wed Dec 22 12:30:45 2010 From: post at andre-bell.de (Andre Alexander Bell) Date: Wed, 22 Dec 2010 18:30:45 +0100 Subject: simple games w/o pygame In-Reply-To: References: Message-ID: <4D1235C5.7060504@andre-bell.de> On 22.12.2010 17:40, William Gill wrote: > I am teaching an 11 year old who wants to learn programming. I chose > Python, and it is working well. I seem to remember lots of simple > script games, like quizzes, number games etc. that would be good for his > tutorial. However, now all I can find is more complex games using > Pygame. Can anyone help me out here? Recently someone posted this link on the list, which might be interesting: http://inventwithpython.com/index.html Regards Andre From stefan.sonnenberg at pythonmeister.com Wed Dec 22 12:47:25 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Wed, 22 Dec 2010 18:47:25 +0100 Subject: compiling Python 2.7.1 with readline module fails on Debian (Virtualbox) In-Reply-To: References: Message-ID: <4D1239AD.7010907@pythonmeister.com> Am 22.12.2010 09:33, schrieb Benedict Verheyen: > Hi, > > > i'm trying to compile Python 2.7.1 on Debian (Virtual Box). > Compiling end successfully but readline and curses fail to build. > > I'm working with virtualenv and I install all my packages in $HOME/local. > I've downloaded readline, compiled and installed it in $HOME/local, same with ncurses. > Both were the latest releases. > But somehow, Python isn't able to build them. > > I get this message: > > Failed to build these modules: > _curses _curses_panel readline > > So it does seems to find the modules. > I'm not used to dealing with configure, and make so i can't debug much. > I first tried this configure line: > ./configure --enable-shared --prefix=$HOME/local > > Next i tried this one: > env CPPFLAGS="-I$HOME/local/include" LDFLAGS="-L$HOME/local/lib" ./configure --enable-shared --prefix=$HOME/local > > But make yields the same error. > > Any clues on what I do wrong? > > The source of ncurses and readline are placed in $HOME/src. > Both packages are installed in $HOME/local > > Thanks for any advice, > > Regards, > Benedict > Did you try apt-get install build-essential apt-get build-dep python2.7 before trying to compile ? Anyway, the config.log file is always of special interest. Btw, which Debian release are you running ? If the system is set up correctly it should not be necessary to change env vars to get it built. From binbrain at gmail.com Wed Dec 22 12:57:21 2010 From: binbrain at gmail.com (Jim Pharis) Date: Wed, 22 Dec 2010 12:57:21 -0500 Subject: compiling Python 2.7.1 with readline module fails on Debian (Virtualbox) In-Reply-To: References: Message-ID: are you running make clean for good measure? On Wed, Dec 22, 2010 at 3:33 AM, Benedict Verheyen < benedict.verheyen at gmail.com> wrote: > Hi, > > > i'm trying to compile Python 2.7.1 on Debian (Virtual Box). > Compiling end successfully but readline and curses fail to build. > > I'm working with virtualenv and I install all my packages in $HOME/local. > I've downloaded readline, compiled and installed it in $HOME/local, same > with ncurses. > Both were the latest releases. > But somehow, Python isn't able to build them. > > I get this message: > > Failed to build these modules: > _curses _curses_panel readline > > So it does seems to find the modules. > I'm not used to dealing with configure, and make so i can't debug much. > I first tried this configure line: > ./configure --enable-shared --prefix=$HOME/local > > Next i tried this one: > env CPPFLAGS="-I$HOME/local/include" LDFLAGS="-L$HOME/local/lib" > ./configure --enable-shared --prefix=$HOME/local > > But make yields the same error. > > Any clues on what I do wrong? > > The source of ncurses and readline are placed in $HOME/src. > Both packages are installed in $HOME/local > > Thanks for any advice, > > Regards, > Benedict > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jasons at adventureaquarium.com Wed Dec 22 13:34:16 2010 From: jasons at adventureaquarium.com (Jason Staudenmayer) Date: Wed, 22 Dec 2010 13:34:16 -0500 Subject: Code review request Message-ID: Hi All, I'm a python newbie so please be kind. I've been reading book after book and have written a script or two but this is my first real "program". Just looking for any suggestions and pointers. I've done some work with bash scripts and php (not OOP) a while a go. I'm not a programmer but would like to possibly expand in to it (right now an IT guy). Am I on the right track so far? The program should be documented enough to explain. """ Created on Tue Dec 21 13:39:41 2010 @author: jason Usage: cmd_drug_testing.py [options]... Will select a random employee from the local database (located in the current directory) and display the name by default. This program (Drug Testing) was written to help select employees for drug testing. Program usage: -h, --help Displays this help info -l, --list-emplys Lists all employees in the database -s, --select Select employee for testing -r, --remove-emply Delete employee from database, usage: -d employee_name or id -e, --edit-emply Edit employee data in database, usage: -e employee_name or id field_to_change new_value -i, --insert-emply Insert new employee in database: must fit this format -- "id:or '','lastname, firstname', 'email',0" -f Display database name and full path This program was written by, Jason S. For the use of AA. """ # import our needed modules import sqlite3 as sqlite import sys, getopt #set global vars global cursor global conn def usage(): """ this just prints the usage in the doc string""" print __doc__ def dbconnect(sql): """handel the connction to the sqlite db """ dbConnection = sqlite.connect("drug-test.db") #set the cursor cursor = dbConnection.cursor() try: #execute the sql passed from the other funtions and return the results result = cursor.execute(sql) dbConnection.commit() except sqlite.Error, e: result = e.args[0] return result def listEmployees(sql): #list all records in the database listemp = dbconnect(sql) for lst in listemp: print "%s, %s, %s, %s" % (lst[0],lst[1],lst[2],lst[3]) def selectOneEmployee(sql): #select a random record from the database listemp = dbconnect(sql) for empl in listemp: print empl[0] def removeOneEmployee(sqlchk,sqldel): #delete one employee by ID number chk = dbconnect(sqlchk) if chk.fetchone() != None: #check to make sure the ID is valid in the database emply = dbconnect(sqlchk) emply = emply.fetchall() print "trying to remove employee %s" % (emply) try: dbconnect(sqldel) except sqlite.Error, e: result = e.args[0] print result else: print "Employees ID is invalid, please check the ID number" def insertEmployee(sql): #insert a new employee into the database print sql try: dbconnect(sql) except sqlite.Error, e: result = e.args[0] print result def main(argv): """The purpose of this program is to select an empployee from this database for random drug testing. This program can also perform maintainance on same database.""" if argv == []: sql = "SELECT name FROM employees ORDER BY RANDOM() LIMIT 1;" print "The following employee has been selected\n" selectOneEmployee(sql) try: #get the options passed by the user opts, args = getopt.getopt(argv, "hlsr:e:i:d",["Help","list-emplys","select","remove-emply=","edit-emply=","insert-emply="]) except getopt.GetoptError: usage() sys.exit(2) #check throught the options and respond accordingly for opt, arg in opts: if opt in ("-h", "--help"): usage() sys.exit() elif opt == '-d': global _debug _debug = 1 elif opt in ("-l", "--list-emplys"): sql = "select * from employees" listEmployees(sql) elif opt in ("-s","--select"): sql = "SELECT name FROM employees ORDER BY RANDOM() LIMIT 1;" print "The following employee has been selected\n" selectOneEmployee(sql) elif opt in ("-r","--remove-emply"): if arg == "": sys.exit("You must provice the ID for the employee to remove") sqlchk = "select * from employees where id = \"%s\"" % (arg) sqldel = "delete from employees where id = \"%s\"" % (arg) removeOneEmployee(sqlchk,sqldel) elif opt in ("-i", "--insert-emply"): sql = "insert into employees values(%s)" % (arg) insertEmployee(sql) if __name__ == "__main__": main(sys.argv[1:]) ########## END ################### Thanks everyone. Jason ..?><((((?> From mpnordland at gmail.com Wed Dec 22 14:28:31 2010 From: mpnordland at gmail.com (mpnordland) Date: Wed, 22 Dec 2010 11:28:31 -0800 (PST) Subject: Catching user switching and getting current active user from root on linux References: <3d190cbf-be7d-4973-b85f-c030bb258742@glegroupsg2000goo.googlegroups.com> Message-ID: ok, I'll give one more chance. First, to pacify those who hate google groups: What is a good usenet client? second, How should I set up this proxy so that when a connection is made, it request's authentication, and then log's the request, if authentication is not gotten, how do I have it block (or firewall) the request? Furthermore, I would like for the proxy to be squid. So all of the nitty gritty should have to do with squid. From stefan.sonnenberg at pythonmeister.com Wed Dec 22 15:24:24 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Wed, 22 Dec 2010 21:24:24 +0100 Subject: Code review request In-Reply-To: References: Message-ID: <4D125E78.10408@pythonmeister.com> Am 22.12.2010 19:34, schrieb Jason Staudenmayer: > Hi All, > I'm a python newbie so please be kind. I've been reading book after book and have written a script or two but this is my first real "program". Just looking for any suggestions and pointers. I've done some work with bash scripts and php (not OOP) a while a go. I'm not a programmer but would like to possibly expand in to it (right now an IT guy). Am I on the right track so far? > > The program should be documented enough to explain. > > """ > Created on Tue Dec 21 13:39:41 2010 > @author: jason > > Usage: cmd_drug_testing.py [options]... > Will select a random employee from the local database (located in the current directory) > and display the name by default. > > This program (Drug Testing) was written to help select employees for drug testing. > Program usage: > > -h, --help Displays this help info > -l, --list-emplys Lists all employees in the database > -s, --select Select employee for testing > -r, --remove-emply Delete employee from database, usage: -d employee_name or id > -e, --edit-emply Edit employee data in database, usage: -e employee_name or id > field_to_change new_value > -i, --insert-emply Insert new employee in database: > must fit this format -- "id:or '','lastname, firstname', 'email',0" > -f Display database name and full path > > This program was written by, Jason S. For the use of AA. > > """ > > # import our needed modules > import sqlite3 as sqlite > import sys, getopt > > #set global vars > global cursor > global conn > > > def usage(): > """ this just prints the usage in the doc string""" > print __doc__ > > def dbconnect(sql): > """handel the connction to the sqlite db """ > dbConnection = sqlite.connect("drug-test.db") > #set the cursor > cursor = dbConnection.cursor() > try: > #execute the sql passed from the other funtions and return the results > result = cursor.execute(sql) > dbConnection.commit() > except sqlite.Error, e: > result = e.args[0] > > return result > > > def listEmployees(sql): > #list all records in the database > listemp = dbconnect(sql) > for lst in listemp: > print "%s, %s, %s, %s" % (lst[0],lst[1],lst[2],lst[3]) > > def selectOneEmployee(sql): > #select a random record from the database > listemp = dbconnect(sql) > for empl in listemp: > print empl[0] > > def removeOneEmployee(sqlchk,sqldel): > #delete one employee by ID number > chk = dbconnect(sqlchk) > > if chk.fetchone() != None: > #check to make sure the ID is valid in the database > emply = dbconnect(sqlchk) > emply = emply.fetchall() > print "trying to remove employee %s" % (emply) > try: > dbconnect(sqldel) > > except sqlite.Error, e: > result = e.args[0] > print result > > else: > print "Employees ID is invalid, please check the ID number" > > def insertEmployee(sql): > #insert a new employee into the database > print sql > try: > dbconnect(sql) > > except sqlite.Error, e: > result = e.args[0] > print result > > def main(argv): > """The purpose of this program is to select an empployee from this database for random drug > testing. This program can also perform maintainance on same database.""" > if argv == []: > sql = "SELECT name FROM employees ORDER BY RANDOM() LIMIT 1;" > print "The following employee has been selected\n" > selectOneEmployee(sql) > > try: > #get the options passed by the user > opts, args = getopt.getopt(argv, "hlsr:e:i:d",["Help","list-emplys","select","remove-emply=","edit-emply=","insert-emply="]) > > except getopt.GetoptError: > usage() > sys.exit(2) > > #check throught the options and respond accordingly > for opt, arg in opts: > if opt in ("-h", "--help"): > usage() > sys.exit() > elif opt == '-d': > global _debug > _debug = 1 > elif opt in ("-l", "--list-emplys"): > sql = "select * from employees" > listEmployees(sql) > elif opt in ("-s","--select"): > sql = "SELECT name FROM employees ORDER BY RANDOM() LIMIT 1;" > print "The following employee has been selected\n" > selectOneEmployee(sql) > elif opt in ("-r","--remove-emply"): > if arg == "": > > sys.exit("You must provice the ID for the employee to remove") > sqlchk = "select * from employees where id = \"%s\"" % (arg) > sqldel = "delete from employees where id = \"%s\"" % (arg) > removeOneEmployee(sqlchk,sqldel) > elif opt in ("-i", "--insert-emply"): > sql = "insert into employees values(%s)" % (arg) > insertEmployee(sql) > > if __name__ == "__main__": > main(sys.argv[1:]) > > ########## END ################### > > Thanks everyone. > > > Jason > > > > ..?><((((?> Hi Jason, the program could be more dense. You have several redundant code in there, too. For example, all the *Employee functions basically just call dbconnect and let it execute the sql there. dbconnect in this respect is not a really straight name, as it does more than only connect to a database. You should avoid "!= None", better is "is not None". The program flow is "awkward": if argv is empty (better say "if not argv"), you show one employee, but then continue to parse opts. I think the program would be more readable, if you would just handle the different cases in an if-elseif-else-cascade. The global statement is not needed, But you can also try pylint, which will point some things out: Report 78 statements analysed. Statistics by type type number old number difference %documented %badname module 1 1 = 100.00 0.00 class 0 0 = 0 0 method 0 0 = 0 0 function 7 7 = 42.86 57.14 Duplication now previous difference nb duplicated lines 0 0 = percent duplicated lines 0.000 0.000 = Raw metrics type number % previous difference code 75 60.98 75 = docstring 31 25.20 31 = comment 3 2.44 3 = empty 14 11.38 14 = External dependencies getopt (cmd_drug_testing) sqlite3 (cmd_drug_testing) Messages by category type number previous difference convention 23 23 = refactor 0 0 = warning 4 4 = error 0 0 = Messages message id occurrences C0103 8 C0301 7 C0324 4 C0111 4 W0604 2 W0612 1 W0601 1 Global evaluation Your code has been rated at 6.54/10 (previous run: 6.54/10) Messages type module object line message C cmd_drug_testing 6 Line too long (88/80) C cmd_drug_testing 9 Line too long (82/80) C cmd_drug_testing 15 Line too long (89/80) C cmd_drug_testing 16 Line too long (91/80) C cmd_drug_testing 19 Line too long (99/80) C cmd_drug_testing 96 Line too long (95/80) C cmd_drug_testing 105 Line too long (132/80) W cmd_drug_testing 31 Using the global statement at the module level W cmd_drug_testing 32 Using the global statement at the module level C cmd_drug_testing dbconnect 41 Invalid name "dbConnection" (should match [a-z_][a-z0-9_]{2,30}$) C cmd_drug_testing dbconnect 48 Invalid name "e" (should match [a-z_][a-z0-9_]{2,30}$) C cmd_drug_testing listEmployees 54 Invalid name "listEmployees" (should match [a-z_][a-z0-9_]{2,30}$) C cmd_drug_testing listEmployees 54 Missing docstring C cmd_drug_testing listEmployees 58 Comma not followed by a space print "%s, %s, %s, %s" % (lst[0],lst[1],lst[2],lst[3]) ^^ C cmd_drug_testing selectOneEmployee 60 Invalid name "selectOneEmployee" (should match [a-z_][a-z0-9_]{2,30}$) C cmd_drug_testing selectOneEmployee 60 Missing docstring C cmd_drug_testing removeOneEmployee 66 Invalid name "removeOneEmployee" (should match [a-z_][a-z0-9_]{2,30}$) C cmd_drug_testing removeOneEmployee 66 Missing docstring C cmd_drug_testing removeOneEmployee 66 Comma not followed by a space def removeOneEmployee(sqlchk,sqldel): ^^ C cmd_drug_testing removeOneEmployee 78 Invalid name "e" (should match [a-z_][a-z0-9_]{2,30}$) C cmd_drug_testing insertEmployee 85 Invalid name "insertEmployee" (should match [a-z_][a-z0-9_]{2,30}$) C cmd_drug_testing insertEmployee 85 Missing docstring C cmd_drug_testing insertEmployee 91 Invalid name "e" (should match [a-z_][a-z0-9_]{2,30}$) C cmd_drug_testing main 105 Comma not followed by a space opts, args = getopt.getopt(argv, "hlsr:e:i:d",["Help","list-emplys","select","remove-emply=","edit-emply=","insert-emply="]) ^^ W cmd_drug_testing main 117 Global variable '_debug' undefined at the module level C cmd_drug_testing main 132 Comma not followed by a space removeOneEmployee(sqlchk,sqldel) ^^ W cmd_drug_testing main 105 Unused variable 'args' -------------- next part -------------- An HTML attachment was scrubbed... URL: From gerald.britton at gmail.com Wed Dec 22 15:29:18 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Wed, 22 Dec 2010 15:29:18 -0500 Subject: Code review request Message-ID: Hi Jason, There are a couple of things that I noticed: 1. You might want to check out PEP 8 -- a Python style guide. Among other things, some lines are very long and you are not consistent with putting a space after a comma in a list or between arguments in a function call. e.g. opts, args = getopt.getopt(argv, "hlsr:e:i:d",["Help","list-emplys","select","remove-emply=","edit-emply=","insert-emply="]) That's 125 characters, not including the indentation! You can break it up and even make it more readable like this: opts, args = getopt.getopt( argv, "hlsr:e:i:d", ["Help","list-emplys","select","remove-emply=","edit-emply=","insert-emply="] ) but then the embedded list is still too long. It can also be split like this: opts, args = getopt.getopt( argv, "hlsr:e:i:d", ["Help", "list-emplys", "select", "remove-emply=", "edit-emply=", "insert-emply="] ) Just do it so that it's easy to read and support. Notice the commas are followed by spaces in the list. In the listEmployees function (check out PEP 8 about naming conventions, while you're at it!) there is one line that could be simpler: print "%s, %s, %s, %s" % (lst[0],lst[1],lst[2],lst[3]) could be: print "%s, %s, %s, %s" % tuple(lst[:4]) or if the number of elements could be more or less, you could even do this: for item in lst: print item, which should do the same thing (the trailing comma suppresses the new line) and you'll never have to count the number of items in lst. You also have some statements like: sqlchk = "select * from employees where id = \"%s\"" % (arg) Since a Python list can be enclosed in apostrophes as well as quotations, you can get the same thing without the escapes: sqlchk = 'select * from employees where id = "%s"' % (arg) Anyway -- just some food for thought. -- Gerald Britton From jasons at adventureaquarium.com Wed Dec 22 15:43:52 2010 From: jasons at adventureaquarium.com (Jason Staudenmayer) Date: Wed, 22 Dec 2010 15:43:52 -0500 Subject: [SPAM] - Re: Code review request In-Reply-To: <4D125E78.10408@pythonmeister.com> Message-ID: -----Original Message----- From: python-list-bounces+jasons=adventureaquarium.com at python.org [mailto:python-list-bounces+jasons=adventureaquarium.com at python.org] On Behalf Of Stefan Sonnenberg-Carstens Sent: Wednesday, December 22, 2010 3:24 PM To: python-list at python.org Subject: [SPAM] - Re: Code review request Am 22.12.2010 19:34, schrieb Jason Staudenmayer: Hi All, Hi Jason, the program could be more dense. You have several redundant code in there, too. For example, all the *Employee functions basically just call dbconnect and let it execute the sql there. dbconnect in this respect is not a really straight name, as it does more than only connect to a database. You should avoid "!= None", better is "is not None". The program flow is "awkward": if argv is empty (better say "if not argv"), you show one employee, but then continue to parse opts. I think the program would be more readable, if you would just handle the different cases in an if-elseif-else-cascade. The global statement is not needed, But you can also try pylint, which will point some things out: Report 78 statements analysed. Thanks for the advice, I'll try to rework some of those issues. I did try the if-elif-else for the getopts but it didn't flow right for some reason (I'll try it again though). Thanks again. Jason ..?><((((?> From python at mrabarnett.plus.com Wed Dec 22 15:44:09 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 22 Dec 2010 20:44:09 +0000 Subject: Code review request In-Reply-To: References: Message-ID: <4D126319.4040306@mrabarnett.plus.com> > """ > Created on Tue Dec 21 13:39:41 2010 > @author: jason > > Usage: cmd_drug_testing.py [options]... > Will select a random employee from the local database (located in the current directory) > and display the name by default. > > This program (Drug Testing) was written to help select employees for drug testing. > Program usage: > > -h, --help Displays this help info > -l, --list-emplys Lists all employees in the database > -s, --select Select employee for testing > -r, --remove-emply Delete employee from database, usage: -d employee_name or id > -e, --edit-emply Edit employee data in database, usage: -e employee_name or id > field_to_change new_value > -i, --insert-emply Insert new employee in database: > must fit this format -- "id:or '','lastname, firstname', 'email',0" > -f Display database name and full path > > This program was written by, Jason S. For the use of AA. > > """ > > # import our needed modules > import sqlite3 as sqlite > import sys, getopt > > #set global vars > global cursor > global conn > By default, if you bind (assign) to a name inside a function then Python assumes that the name is local to the function, unless you tell it otherwise with "global". Using "global" outside a function has no effect. > > def usage(): > """ this just prints the usage in the doc string""" > print __doc__ > > def dbconnect(sql): > """handel the connction to the sqlite db """ "handel the connction" -> "handle the connection" > dbConnection = sqlite.connect("drug-test.db") > #set the cursor > cursor = dbConnection.cursor() > try: > #execute the sql passed from the other funtions and return the results "funtions" -> "functions" > result = cursor.execute(sql) > dbConnection.commit() > except sqlite.Error, e: > result = e.args[0] > > return result > The Pythonic way is to return a result when successful and raise an exception when unsuccessful. > > def listEmployees(sql): > #list all records in the database > listemp = dbconnect(sql) > for lst in listemp: > print "%s, %s, %s, %s" % (lst[0],lst[1],lst[2],lst[3]) > I wouldn't pass in an SQL string. I'd pass in only the parameters (if any) and hide the SQL details inside the function, something like this: def listEmployees(): # list all records in the database dbConnection = sqlite.connect(DB_NAME) try: try: results = dbConnection.execute("select * from employees") for lst in results: print "%s, %s, %s, %s" % (lst[0], lst[1], lst[2], lst[3]) except sqlite.Error, e: print "ERROR:", e.args[0] finally: dbConnection.close() I'd also be explicit about the names of the fields in the database in case their order changed in a later version. > def selectOneEmployee(sql): > #select a random record from the database > listemp = dbconnect(sql) > for empl in listemp: > print empl[0] > def selectOneEmployee(): # select a random record from the database dbConnection = sqlite.connect(DB_NAME) try: try: results = dbConnection.execute("SELECT name FROM employees ORDER BY RANDOM() LIMIT 1;") print "The following employee has been selected\n" for empl in results: print empl[0] except sqlite.Error, e: print "ERROR:", e.args[0] finally: dbConnection.close() > def removeOneEmployee(sqlchk,sqldel): > #delete one employee by ID number > chk = dbconnect(sqlchk) > > if chk.fetchone() != None: > #check to make sure the ID is valid in the database > emply = dbconnect(sqlchk) > emply = emply.fetchall() > print "trying to remove employee %s" % (emply) > try: > dbconnect(sqldel) > > except sqlite.Error, e: > result = e.args[0] > print result > > else: > print "Employees ID is invalid, please check the ID number" > > sqlchk = > sqldel = "delete from employees where id = \"%s\"" % (arg) I'd do: def removeOneEmployee(emplyId): # delete one employee by ID number dbConnection = sqlite.connect(DB_NAME) try: try: # check to make sure the ID is valid in the database results = dbConnection.execute("select * from employees where id = %s", (emplyId, )) if results.fetchone(): print "trying to remove employee %s" % emplyId dbConnection.execute("delete from employees where id = %s", (emplyId, )) dbConnection.commit() else: print "Employees ID is invalid, please check the ID number" except sqlite.Error, e: print "ERROR:", e.args[0] finally: dbConnection.close() Note that it's a very bad idea to build an SQL command yourself because of the risk of SQL injection attacks. The .execute method can do it for you safely. > def insertEmployee(sql): > #insert a new employee into the database > print sql > try: > dbconnect(sql) > > except sqlite.Error, e: > result = e.args[0] > print result > I'd do: def insertEmployee(details): # insert a new employee into the database # parse the details provided into a tuple which can be passed to the .execute method emplyDet = parse_details(details) print emplyDet dbConnection = sqlite.connect(DB_NAME) try: try: dbConnection.execute("insert into employees values (%s)", emplyDet) dbConnection.commit() else: print "Employees ID is invalid, please check the ID number" except sqlite.Error, e: print "ERROR:", e.args[0] finally: dbConnection.close() I wouldn't pass the details from the commandline without parsing and tidying them first. I'd also specify the fields explicitly in the SQL command. > def main(argv): > """The purpose of this program is to select an empployee from this database for random drug > testing. This program can also perform maintainance on same database.""" "empployee" -> "employee" "maintainance" -> "maintenance" > if argv == []: > sql = "SELECT name FROM employees ORDER BY RANDOM() LIMIT 1;" > print "The following employee has been selected\n" > selectOneEmployee(sql) > > try: > #get the options passed by the user > opts, args = getopt.getopt(argv, "hlsr:e:i:d",["Help","list-emplys","select","remove-emply=","edit-emply=","insert-emply="]) > > except getopt.GetoptError: > usage() > sys.exit(2) > > #check throught the options and respond accordingly "throught" -> "through" > for opt, arg in opts: > if opt in ("-h", "--help"): > usage() > sys.exit() It's probably better to return from main instead of exiting. > elif opt == '-d': > global _debug > _debug = 1 _debug isn't used anywhere else; it's not even initialised to 0. Incidentally, if it has only 2 possible values then it's better to use False and True instead of 0 and 1. > elif opt in ("-l", "--list-emplys"): > sql = "select * from employees" > listEmployees(sql) > elif opt in ("-s","--select"): > sql = "SELECT name FROM employees ORDER BY RANDOM() LIMIT 1;" > print "The following employee has been selected\n" > selectOneEmployee(sql) I'd do: selectOneEmployee() and keep the SQL details hidden. > elif opt in ("-r","--remove-emply"): > if arg == "": > > sys.exit("You must provice the ID for the employee to remove") "provice" -> "provide" > sqlchk = "select * from employees where id = \"%s\"" % (arg) > sqldel = "delete from employees where id = \"%s\"" % (arg) > removeOneEmployee(sqlchk,sqldel) I'd do: removeOneEmployee(arg) and keep the SQL details hidden. > elif opt in ("-i", "--insert-emply"): > sql = "insert into employees values(%s)" % (arg) > insertEmployee(sql) I'd do: insertEmployee(arg) and keep the SQL details hidden. > > if __name__ == "__main__": > main(sys.argv[1:]) From cronoklee at gmail.com Wed Dec 22 15:45:38 2010 From: cronoklee at gmail.com (cronoklee) Date: Wed, 22 Dec 2010 12:45:38 -0800 (PST) Subject: Newbie question about importing modules. In-Reply-To: Message-ID: <1a95684f-754e-4a01-849f-e476d078c723@glegroupsg2000goo.googlegroups.com> On Wed, Dec 22, 2010 at 7:57 PM, Tim Roberts wrote: cronoklee wrote: > > Thanks Tim - You've certainly shed some light. I presume the PIL > installer is setup.py and installation is simple a case of running it? Yes: python setup.py install That scheme is called "distutils". Since it became part of the standard Python distribution many years ago, it is now ubiquitous. > Is this usually the case for python 'source distribution' packages? Yes. In the Linux world, with a few exceptions, EVERY Python add-on package is installed that way. In the Windows world, most smaller packages come that way. Larger packages will have an MSI installer that does essentially the same thing. Once in a while, you'll download a script that consists only of a single file. That would really be the only exception. > Is there a term for packages that do not need to be installed? This > might help me search for them in future. I don't think that's the right answer. The installation process is rarely more complicated than copying files to the site-packages directory of your current Python version. The installer can verify dependencies and make sure everything is OK. It's a Good Thing. -- Tim Roberts Thanks a lot Tim - all makes sense. I appreciate the lesson! cronoklee From sjmachin at lexicon.net Wed Dec 22 15:51:42 2010 From: sjmachin at lexicon.net (John Machin) Date: Wed, 22 Dec 2010 12:51:42 -0800 (PST) Subject: Modifying an existing excel spreadsheet References: Message-ID: <110bfe76-0ff3-4f31-bb8e-1d981c854afb@c13g2000prc.googlegroups.com> On Dec 21, 8:56?am, Ed Keith wrote: > I have a user supplied 'template' Excel spreadsheet. I need to create a new excel spreadsheet based on the supplied template, with data filled in. > > I found the tools herehttp://www.python-excel.org/,?andhttp://sourceforge.net/projects/pyexcelerator/. I have been trying to use the former, since the latter seems to be devoid of documentation (not even any docstrings). pyExcelerator is abandonware. Use xlwt instead; it's a bug-fixed/ maintained/enhanced fork of pyExcelerator Read the tutorial that you'll find mentioned on http://www.python-excel.org Join the google group that's also mentioned there; look at past questions, ask some more, ... From emile at fenx.com Wed Dec 22 16:06:18 2010 From: emile at fenx.com (Emile van Sebille) Date: Wed, 22 Dec 2010 13:06:18 -0800 Subject: Catching user switching and getting current active user from root on linux In-Reply-To: References: <3d190cbf-be7d-4973-b85f-c030bb258742@glegroupsg2000goo.googlegroups.com> Message-ID: On 12/22/2010 11:28 AM mpnordland said... > ok, I'll give one more chance. ... which probably won't be enough -- this is potentially a huge question you're asking with lots of little bits to put together. I have an installation where I did somthing similar seven-ish years ago using squid, squidguard, blacklists from Universit? Toulouse in France, python, iptables, sql, php, zope, bash, and who knows what else. It authenticates, logs, tracks, blocks, unblocks, reports activity on an automated In and Out board by user, provides historical stats, automates new user setup and invalidation, and probably more. I put maybe a week or two into it initially, and about the same again over the years adding to it. > First, to pacify those who hate google groups: What is a good usenet > client? I use thunderbird to access gmane groups. > second, How should I set up this proxy so that when a connection is > made, it request's authentication, and then log's the request, if > authentication is not gotten, how do I have it block (or firewall) the > request? Furthermore, I would like for the proxy to be squid. So all > of the nitty gritty should have to do with squid. ... and that's where I'd start looking. Check out the current status of Squid to see how much of what you want can be done out of the box. When you hit the limits of what it'll do for you, start writing glue to fill in the puzzle. HTH, Emile From steve at holdenweb.com Wed Dec 22 16:20:54 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 22 Dec 2010 16:20:54 -0500 Subject: Catching user switching and getting current active user from root on linux In-Reply-To: References: <3d190cbf-be7d-4973-b85f-c030bb258742@glegroupsg2000goo.googlegroups.com> Message-ID: On 12/22/2010 2:28 PM, mpnordland wrote: > ok, I'll give one more chance. > First, to pacify those who hate google groups: What is a good usenet > client? Thunderbird is OK for me (I follow about three groups normally). I access the comp.lang.python group vie the Gmane ("Main") service, where for some strange resaon best known to the gmane admins it is called gmane.comp.python.general. Ho, hum. I seem to remember Outlook Express was a fairly decent NNTP client as well, and Tim Peters says I'm not just blowing smoke up your ass. > second, How should I set up this proxy so that when a connection is > made, it request's authentication, and then log's the request, if > authentication is not gotten, how do I have it block (or firewall) the > request? Furthermore, I would like for the proxy to be squid. So all > of the nitty gritty should have to do with squid. I would recommend you take a look at the Spambayes code, which does all that sort of stuff apparently quite reliably. If you aren't yet proficient enough with Python to understand the code on your own look for a Python Meetup or a local or regional conference to meet people who will helpyou answer your questions. Increasingly there are workspaces like HacDC springing up to give people access to advanced technologies at everyday prices. You could look for such a group locally. There's lots of energy from people once they realise that what gets built can help them. Squid is a different matter. For that, probably if you go on an IRC channel (freenode.net is what I use, but others have their favorites). Maybe #squid? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From secris1 at gmail.com Wed Dec 22 16:43:36 2010 From: secris1 at gmail.com (Sean) Date: Wed, 22 Dec 2010 13:43:36 -0800 (PST) Subject: Python Web App Message-ID: <907fa80e-1814-4ddb-be32-ec14cfd53fab@29g2000yqq.googlegroups.com> Anybody know where I can find a Python Development Environment in the form of a web app for use with Chrome OS. I have been looking for a few days and all i have been able to find is some old discussions with python developers talking about they will want one for the OS to be a success with them. From arnodel at gmail.com Wed Dec 22 16:45:12 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Wed, 22 Dec 2010 21:45:12 +0000 Subject: Question regarding Higher-Order-Programming in Python References: <7819f726-244a-4b6e-9cde-6bde9fe286df@30g2000yql.googlegroups.com> <1dc2d2aa-a352-4f71-9cbe-dffb72be17e4@i17g2000vbq.googlegroups.com> Message-ID: <87sjxpa3dj.fsf@gmail.com> Mark Fink writes: > so far I have never noticed chain.from_iterable, but many thanks to > you Peter, I have now a beautiful solution to this problem. >>>> from itertools import chain >>>> comb = it.combinations(dims, 2) >>>> l = chain.from_iterable(it.imap(get_products, comb)) You can also write this as: l = (p for c in comb for p in get_products(c)) >>>> l.next() > [('special', '+'), ('number', 1)] >>>> l.next() > [('special', '+'), ('number', 2)] Also in your original post you define get_products: >>>> def get_products(keys): > ... # helper to get products from keys in the following form: > ... # [('bold', True), ('color', 'black')] > ... values = itemgetter(*keys)(dims) > ... product = it.product(*values) > ... return map(partial(zip, keys), product) > ... You could define it as e.g. def get_products(keys): key_values = [[(k, v) for v in values] for k in keys] return it.product(*key_values) But maybe for some reason you are trying to avoid list comprehensions and generator expressions? -- Arnaud From pavlovevidence at gmail.com Wed Dec 22 16:53:20 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 22 Dec 2010 13:53:20 -0800 (PST) Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> On Dec 22, 8:52?am, kj wrote: > In Robert Kern writes: > > >Obfuscating the location that an exception gets raised prevents a lot of > >debugging... > > The Python interpreter does a lot of that "obfuscation" already, and I > find the resulting tracebacks more useful for it. > > An error message is only useful to a given audience if that audience > can use the information in the message to modify what they are > doing to avoid the error. So when the audience files a bug report it's not useful for them to include the whole traceback? > ?It is of no use (certainly no *immediate* > use) to this audience to see tracebacks that go deep into code that > they don't know anything about and cannot change. Seriously, quit trying to do the user favors. There's nothing that pisses me off than a self-important developer thinking he knows what the user wants more than the user does. Carl Banks From steve+comp.lang.python at pearwood.info Wed Dec 22 17:05:27 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Dec 2010 22:05:27 GMT Subject: Catching user switching and getting current active user from root on linux References: <3d190cbf-be7d-4973-b85f-c030bb258742@glegroupsg2000goo.googlegroups.com> Message-ID: <4d127627$0$29997$c3e8da3$5496439d@news.astraweb.com> On Mon, 20 Dec 2010 20:35:54 -0500, Steve Holden wrote: > On 12/20/2010 12:54 PM, mpnordland wrote: >> I give up, I will never try to use a usenet group again. For the ones >> of you who tried to help thank you. You helped to identify some of my >> troubles, as for you @usernet, you are a troll > > Don't give up after one experience. Usenet can be really useful as long > as you know who to listen to and who to ignore ... More importantly, Usenet can be very useful so long as you know how to ask smart questions. If you insist on asking stupid questions, you will rapidly get disillusioned: people will either ignore you, abuse you, or give you helpful advice that you don't want to hear. -- Steven From nagle at animats.com Wed Dec 22 17:28:31 2010 From: nagle at animats.com (John Nagle) Date: Wed, 22 Dec 2010 14:28:31 -0800 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: Message-ID: <4d127b8c$0$44035$742ec2ed@news.sonic.net> On 12/20/2010 12:33 PM, Adam Tauno Williams wrote: > On Mon, 2010-12-20 at 12:29 -0800, spaceman-spiff wrote: >> I need to detect them& then for each 1, i need to copy all the >> content b/w the element's start& end tags& create a smaller xml >> file. > > Yep, do that a lot; via iterparse. > >> 1. Can you point me to some examples/samples of using SAX, >> especially , ones dealing with really large XML files. I've just subclassed HTMLparser for this. It's slow, but 100% Python. Using the SAX parser is essentially equivalent. I'm processing multi-gigabyte XML files and updating a MySQL database, so I do need to look at all the entries, but don't need a parse tree of the XML. > SaX is equivalent to iterparse (iterpase is a way, to essentially, do > SaX-like processing). Iterparse does try to build a tree, although you can discard the parts you don't want. If you can't decide whether a part of the XML is of interest until you're deep into it, an "iterparse" approach may result in a big junk tree. You have to keep clearing the "root" element to discard that. > I provided an iterparse example already. See the Read_Rows method in > I don't quite see the point of creating a class with only static methods. That's basically a verbose way to create a module. > >> 2.This brings me to another q. which i forgot to ask in my OP(original post). >> Is simply opening the file,& using reg ex to look for the element i need, a *good* approach ? > > No. If the XML file has a very predictable structure, that may not be a bad idea. It's not very general, but if you have some XML file that's basically fixed format records using XML to delimit the fields, pounding on the thing with a regular expression is simple and fast. John Nagle From stefan.sonnenberg at pythonmeister.com Wed Dec 22 17:29:02 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Wed, 22 Dec 2010 23:29:02 +0100 Subject: Catching user switching and getting current active user from root on linux In-Reply-To: References: <3d190cbf-be7d-4973-b85f-c030bb258742@glegroupsg2000goo.googlegroups.com> Message-ID: <4D127BAE.1090500@pythonmeister.com> Am 22.12.2010 20:28, schrieb mpnordland: > ok, I'll give one more chance. > First, to pacify those who hate google groups: What is a good usenet > client? > second, How should I set up this proxy so that when a connection is > made, it request's authentication, and then log's the request, if > authentication is not gotten, how do I have it block (or firewall) the > request? Furthermore, I would like for the proxy to be squid. So all > of the nitty gritty should have to do with squid. Just install Squid, enable user authentication and grant access only to authenticated people. Now, configure logrotated and tell to rotate logs every day/week/month (your mileage will vary). After rotating run a program such as webalizer to get stats (even on a per user basis). If you have smart guys under your users, set up a) a transparent proxy intercepting http/https requests or b) set up a iptables firewall with redirection to the squid port. There are many, many, many how-to documents on the net describing exactly what you want to do. A first starting point could be http://www.comfsm.fm/computing/squid/FAQ.html And your problems are solved a long time ago: http://www.faqs.org/docs/Linux-mini/TransparentProxy.html And, the most important thing: Check your local laws for this intention. Some, like our german law, require these things to be under clear rules. Cheers From tjreedy at udel.edu Wed Dec 22 17:33:30 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 22 Dec 2010 17:33:30 -0500 Subject: issubclass(dict, Mapping) In-Reply-To: References: Message-ID: On 12/22/2010 9:20 AM, kj wrote: >>>> from collections import Mapping Documented as an *ABSTRACT* base class. ABCs were added in 3.0 and backparted to 2.7. One can be quite competant in Python completely ignoring ABCs. >>>> issubclass(dict, Mapping) > True Yes, dict is a concrete Mapping class. I suppose we could have instead added a new builtin function 'isconcretetizationof' but is seemed easier to reuse issubclass for the test. Most people have no problem with that. >>>> dict.__bases__ > (,) The one and only *CONCRETE* base class. In 3.x, all classes are subclasses of object, which simplifies the class model a bit. >>>> [issubclass(b, Mapping) for b in dict.__bases__] > [False] > So dict is a subclass of Mapping, even though none of the bases of > dict is either Mapping or a subclass of Mapping. Great. Right. dict is direct concrete Mapping implementation and not subclassed from one. The main reason for introducing ABCs was to make it easier to test whether an object passed to a function is an instance of a possibly unknown or yet-to-be-written class in an abstract category, which has a certain api or interface. The actual usage of an ABC would be more like this: from collections import Mapping def f(m): if not isinstance(m, Mapping): raise ValueError('input is not a mapping') else: return True f(dict()) # True f([]) # produces Traceback (most recent call last): File "", line 1, in f([]) File "", line 3, in f raise ValueError('input is not a mapping') ValueError: input is not a mapping -- Terry Jan Reedy From stefan.sonnenberg at pythonmeister.com Wed Dec 22 17:34:28 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Wed, 22 Dec 2010 23:34:28 +0100 Subject: Toy http server In-Reply-To: <4d127627$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <3d190cbf-be7d-4973-b85f-c030bb258742@glegroupsg2000goo.googlegroups.com> <4d127627$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4D127CF4.5070801@pythonmeister.com> Sorry, this one is cross post. I posted my question below some time ago to then jython ml, because this hit me first with jython. Anyway, time passed, problem not solved. So, I'd like to know if some of you know where my error lies: Hi all, I've played around with some code-kata of mine from the past. It's a toy http server: import socket import select import sys import time srv = socket.socket(socket.AF_INET,socket.SOCK_STREAM) srv.setblocking(0) srv.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,True) # Not sure if this is needed. I only remember I've started once for some reason. Commenting out does no change if srv: srv.bind(('',8080)) srv.setblocking(0) srv.listen(5) conns = [srv] buffers = {} while True: reader,writer,failed = select.select(conns,conns,[],1) if failed: sys.exit(1) if srv in reader: client,(ip,port) = srv.accept() client.setblocking(False) conns += [client] for r in reader: if r is not srv: data = r.recv(1024) if not data: conns.remove(r) else: if r in buffers: buffers[r] += data else: buffers[r] = data for w in writer: if w is not srv: if w in buffers and buffers[w][-2:] == '\r\n': msg = 'HTTP/1.0 200 OK\r\nServer: Jython/2.5\r\nContent-type: text/plain\r\n\r\nThe answer is: 42\r\n' w.send(msg) w.close() # THIS ONLY WORKS WHEN THIS LINE IS PRESENT conns.remove(w) # AND THEN THIS IS MUST buffers[w] = '' But today I was asking myself why I should always close the socket, and if wouldn't be more efficient if I let it open. To make a long story short: it does not work. If I comment out the lines with the comment all upper case, jython consumes one core in my laptop completely and ab.exe from apache bails out after a while. Changing send() to sendall() did not do the trick. I've searched the web and did not find anything meaningful. Perhaps someone here can switch the light on. From steve+comp.lang.python at pearwood.info Wed Dec 22 17:36:14 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Dec 2010 22:36:14 GMT Subject: issubclass(dict, Mapping) References: Message-ID: <4d127d5e$0$29997$c3e8da3$5496439d@news.astraweb.com> On Wed, 22 Dec 2010 14:20:51 +0000, kj wrote: > Here's another example, fresh from today's crop of wonders: > > (v. 2.7.0) >>>> from collections import Mapping >>>> issubclass(dict, Mapping) > True >>>> dict.__bases__ > (,) >>>> [issubclass(b, Mapping) for b in dict.__bases__] > [False] > > > So dict is a subclass of Mapping, even though none of the bases of dict > is either Mapping or a subclass of Mapping. Great. Yes. So what? (1) What *actual* problem does this cause you? (2) Do you have an example of code that breaks because of this? (3) Do you understand that since the introduction of ABC (abstract base classes) in Python 2.6 (I think), isinstance and issubclass checks are performed cooperatively? The instance or class are asked if they wish to be known as an instance/subclass of the second argument. Classes can register themselves as subclasses of (say) Mapping without sharing any actual code with Mapping. This is a good thing, and the problem isn't that the abstraction leaks, as you believe, but the opposite: you're *ignoring* the abstraction and looking for concrete details that may or may not exist. I fear that you have fundamentally misunderstood the concept of "leaky abstraction". It does not mean, as you seem to think, that some concrete implementation detail differs between two classes (or functions). It means that some difference in behaviour is exposed, that difference being irrelevant to the abstraction but nevertheless important in some other sense. A contrived example: class MyList(list): def __len__(self): import time time.sleep(3600000) return list.__len__(self) MyList can be used anywhere a regular list can be used. Functionally the two are identical. The abstraction is that MyList is the same as list. But the leak is that len(MyList()) is *incredibly* slow. Coming back to Mapping: Abstraction: issubclass(dict, Mapping) One possible concrete implementation detail of how issubclass is implemented: any(base is Mapping for base in dict.__bases__) The statement "dict is a subclass of Mapping" is about an abstract relationship. It's not necessarily a statement about __bases__. To give an analogy, if you insist on doing DNA testing to determine whether a boy is a son of a man, you're going to be confused and distressed every time you find fathers whose sons are genetically unrelated to them. -- Steven From howe.steven at gmail.com Wed Dec 22 17:51:53 2010 From: howe.steven at gmail.com (Steven Howe) Date: Wed, 22 Dec 2010 14:51:53 -0800 Subject: Code review request In-Reply-To: References: Message-ID: <4D128109.30000@gmail.com> On 12/22/2010 10:34 AM, Jason Staudenmayer wrote: > Hi All, > I'm a python newbie so please be kind. I've been reading book after book and have written a script or two but this is my first real "program". Just looking for any suggestions and pointers. I've done some work with bash scripts and php (not OOP) a while a go. I'm not a programmer but would like to possibly expand in to it (right now an IT guy). Am I on the right track so far? > > The program should be documented enough to explain. > > """ > Created on Tue Dec 21 13:39:41 2010 > @author: jason > > Usage: cmd_drug_testing.py [options]... > Will select a random employee from the local database (located in the current directory) > and display the name by default. > > This program (Drug Testing) was written to help select employees for drug testing. > Program usage: > > -h, --help Displays this help info > -l, --list-emplys Lists all employees in the database > -s, --select Select employee for testing > -r, --remove-emply Delete employee from database, usage: -d employee_name or id > -e, --edit-emply Edit employee data in database, usage: -e employee_name or id > field_to_change new_value > -i, --insert-emply Insert new employee in database: > must fit this format -- "id:or '','lastname, firstname', 'email',0" > -f Display database name and full path > > This program was written by, Jason S. For the use of AA. > > """ > > # import our needed modules > import sqlite3 as sqlite > import sys, getopt > > #set global vars > global cursor > global conn > > > def usage(): > """ this just prints the usage in the doc string""" > print __doc__ > > def dbconnect(sql): > """handel the connction to the sqlite db """ > dbConnection = sqlite.connect("drug-test.db") > #set the cursor > cursor = dbConnection.cursor() > try: > #execute the sql passed from the other funtions and return the results > result = cursor.execute(sql) > dbConnection.commit() > except sqlite.Error, e: > result = e.args[0] > > return result > > > def listEmployees(sql): > #list all records in the database > listemp = dbconnect(sql) > for lst in listemp: > print "%s, %s, %s, %s" % (lst[0],lst[1],lst[2],lst[3]) > > def selectOneEmployee(sql): > #select a random record from the database > listemp = dbconnect(sql) > for empl in listemp: > print empl[0] > > def removeOneEmployee(sqlchk,sqldel): > #delete one employee by ID number > chk = dbconnect(sqlchk) > > if chk.fetchone() != None: > #check to make sure the ID is valid in the database > emply = dbconnect(sqlchk) > emply = emply.fetchall() > print "trying to remove employee %s" % (emply) > try: > dbconnect(sqldel) > > except sqlite.Error, e: > result = e.args[0] > print result > > else: > print "Employees ID is invalid, please check the ID number" > > def insertEmployee(sql): > #insert a new employee into the database > print sql > try: > dbconnect(sql) > > except sqlite.Error, e: > result = e.args[0] > print result > > def main(argv): > """The purpose of this program is to select an empployee from this database for random drug > testing. This program can also perform maintainance on same database.""" > if argv == []: > sql = "SELECT name FROM employees ORDER BY RANDOM() LIMIT 1;" > print "The following employee has been selected\n" > selectOneEmployee(sql) > > try: > #get the options passed by the user > opts, args = getopt.getopt(argv, "hlsr:e:i:d",["Help","list-emplys","select","remove-emply=","edit-emply=","insert-emply="]) > > except getopt.GetoptError: > usage() > sys.exit(2) > > #check throught the options and respond accordingly > for opt, arg in opts: > if opt in ("-h", "--help"): > usage() > sys.exit() > elif opt == '-d': > global _debug > _debug = 1 > elif opt in ("-l", "--list-emplys"): > sql = "select * from employees" > listEmployees(sql) > elif opt in ("-s","--select"): > sql = "SELECT name FROM employees ORDER BY RANDOM() LIMIT 1;" > print "The following employee has been selected\n" > selectOneEmployee(sql) > elif opt in ("-r","--remove-emply"): > if arg == "": > > sys.exit("You must provice the ID for the employee to remove") > sqlchk = "select * from employees where id = \"%s\"" % (arg) > sqldel = "delete from employees where id = \"%s\"" % (arg) > removeOneEmployee(sqlchk,sqldel) > elif opt in ("-i", "--insert-emply"): > sql = "insert into employees values(%s)" % (arg) > insertEmployee(sql) > > if __name__ == "__main__": > main(sys.argv[1:]) > > ########## END ################### > > Thanks everyone. > > > Jason > > > > ..?><((((?> you might consider using optparse (http://docs.python.org/library/optparse.html) to handle your input stream. That will help you decouple your interface from the working code. Easier to swap in a gui. Steven From stefan.sonnenberg at pythonmeister.com Wed Dec 22 17:54:34 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Wed, 22 Dec 2010 23:54:34 +0100 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> Message-ID: <4D1281AA.8020406@pythonmeister.com> Am 20.12.2010 20:34, schrieb spaceman-spiff: > Hi c.l.p folks > > This is a rather long post, but i wanted to include all the details& everything i have tried so far myself, so please bear with me& read the entire boringly long post. > > I am trying to parse a ginormous ( ~ 1gb) xml file. > > > 0. I am a python& xml n00b, s& have been relying on the excellent beginner book DIP(Dive_Into_Python3 by MP(Mark Pilgrim).... Mark , if u are readng this, you are AWESOME& so is your witty& humorous writing style) > > > 1. Almost all exmaples pf parsing xml in python, i have seen, start off with these 4 lines of code. > > import xml.etree.ElementTree as etree > tree = etree.parse('*path_to_ginormous_xml*') > root = tree.getroot() #my huge xml has 1 root at the top level > print root > > 2. In the 2nd line of code above, as Mark explains in DIP, the parse function builds& returns a tree object, in-memory(RAM), which represents the entire document. > I tried this code, which works fine for a small ( ~ 1MB), but when i run this simple 4 line py code in a terminal for my HUGE target file (1GB), nothing happens. > In a separate terminal, i run the top command,& i can see a python process, with memory (the VIRT column) increasing from 100MB , all the way upto 2100MB. > > I am guessing, as this happens (over the course of 20-30 mins), the tree representing is being slowly built in memory, but even after 30-40 mins, nothing happens. > I dont get an error, seg fault or out_of_memory exception. > > My hardware setup : I have a win7 pro box with 8gb of RAM& intel core2 quad cpuq9400. > On this i am running sun virtualbox(3.2.12), with ubuntu 10.10 as guest os, with 23gb disk space& 2gb(2048mb) ram, assigned to the guest ubuntu os. > > 3. I also tried using lxml, but an lxml tree is much more expensive, as it retains more info about a node's context, including references to it's parent. > [http://www.ibm.com/developerworks/xml/library/x-hiperfparse/] > > When i ran the same 4line code above, but with lxml's elementree ( using the import below in line1of the code above) > import lxml.etree as lxml_etree > > i can see the memory consumption of the python process(which is running the code) shoot upto ~ 2700mb& then, python(or the os ?) kills the process as it nears the total system memory(2gb) > > I ran the code from 1 terminal window (screenshot :http://imgur.com/ozLkB.png) > & ran top from another terminal (http://imgur.com/HAoHA.png) > > 4. I then investigated some streaming libraries, but am confused - there is SAX[http://en.wikipedia.org/wiki/Simple_API_for_XML] , the iterparse interface[http://effbot.org/zone/element-iterparse.htm] > > Which one is the best for my situation ? > > Any& all code_snippets/wisdom/thoughts/ideas/suggestions/feedback/comments/ of the c.l.p community would be greatly appreciated. > Plz feel free to email me directly too. > > thanks a ton > > cheers > ashish > > email : > ashish.makani > domain:gmail.com > > p.s. > Other useful links on xml parsing in python > 0. http://diveintopython3.org/xml.html > 1. http://stackoverflow.com/questions/1513592/python-is-there-an-xml-parser-implemented-as-a-generator > 2. http://codespeak.net/lxml/tutorial.html > 3. https://groups.google.com/forum/?hl=en&lnk=gst&q=parsing+a+huge+xml#!topic/comp.lang.python/CMgToEnjZBk > 4. http://www.ibm.com/developerworks/xml/library/x-hiperfparse/ > 5.http://effbot.org/zone/element-index.htm > http://effbot.org/zone/element-iterparse.htm > 6. SAX : http://en.wikipedia.org/wiki/Simple_API_for_XML > > Normally (what is normal, anyway?) such files are auto-generated, and are something that has a apparent similarity with a database query result, encapsuled in xml. Most of the time the structure is same for every "row" thats in there. So, a very unpythonic but fast, way would be to let awk resemble the records and write them in csv format to stdout. then pipe that to your python cruncher of choice and let it do the hard work. The awk part can be done in python, anyway, so could skip that. And take a look at xmlsh.org, they offer tools for the command line, like xml2csv. (Need java, btw). Cheers From rhodri at wildebst.demon.co.uk Wed Dec 22 18:02:11 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 22 Dec 2010 23:02:11 -0000 Subject: simple games w/o pygame References: Message-ID: On Wed, 22 Dec 2010 16:40:21 -0000, William Gill wrote: > I am teaching an 11 year old who wants to learn programming. I chose > Python, and it is working well. I seem to remember lots of simple > script games, like quizzes, number games etc. that would be good for his > tutorial. However, now all I can find is more complex games using > Pygame. Can anyone help me out here? Try the numbered worksheets from the Livewires course: http://www.livewires.org.uk/python/home They are aimed at 12-15 year olds, but an 11 year old should be able to cope. -- Rhodri James *-* Wildebeest Herder to the Masses From see at sig.for.address Wed Dec 22 18:15:35 2010 From: see at sig.for.address (Victor Eijkhout) Date: Wed, 22 Dec 2010 17:15:35 -0600 Subject: Generator question Message-ID: <1jtwvox.1pxdxm314l5m06N%see@sig.for.address> So I have a generator, either as a free function or in a class and I want to generate objects that are initialized from the generated things. def generator(): for whatever: yield something class Object(): def __init__(self): self.data = # the next thing from generator I have not been able to implement this elegantly. For external reasons the following syntax is unacceptable: for g in generator(): ob = Object(g) I really want to be able to write "Object()" in any location and get a properly initialized object. Hints appreciated. Victor. -- Victor Eijkhout -- eijkhout at tacc utexas edu From no.email at please.post Wed Dec 22 18:37:27 2010 From: no.email at please.post (kj) Date: Wed, 22 Dec 2010 23:37:27 +0000 (UTC) Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> Message-ID: In <1f47c36d-a509-4d05-ba79-62b4a534bfe0 at j19g2000prh.googlegroups.com> Carl Banks writes: >On Dec 22, 8:52=A0am, kj wrote: >> In Robert Kern t.k... at gmail.com> writes: >> >> >Obfuscating the location that an exception gets raised prevents a lot of >> >debugging... >> >> The Python interpreter does a lot of that "obfuscation" already, and I >> find the resulting tracebacks more useful for it. >> >> An error message is only useful to a given audience if that audience >> can use the information in the message to modify what they are >> doing to avoid the error. >> =A0It is of no use (certainly no *immediate* >> use) to this audience to see tracebacks that go deep into code that >> they don't know anything about and cannot change. >So when the audience files a bug report it's not useful for them to >include the whole traceback? Learn to read, buster. I wrote *immediate* use. ~kj From emile at fenx.com Wed Dec 22 18:46:37 2010 From: emile at fenx.com (Emile van Sebille) Date: Wed, 22 Dec 2010 15:46:37 -0800 Subject: Generator question In-Reply-To: <1jtwvox.1pxdxm314l5m06N%see@sig.for.address> References: <1jtwvox.1pxdxm314l5m06N%see@sig.for.address> Message-ID: On 12/22/2010 3:15 PM Victor Eijkhout said... > So I have a generator, either as a free function or in a class and I > want to generate objects that are initialized from the generated things. > > def generator(): > for whatever: > yield something > class Object(): > def __init__(self): How about change to def __init__(self, data=generator()): > self.data = # the next thing from generator > then... self.data = data.next()# the next thing from generator HTH, Emile > I have not been able to implement this elegantly. For external reasons > the following syntax is unacceptable: > > for g in generator(): > ob = Object(g) > > I really want to be able to write "Object()" in any location and get a > properly initialized object. > > Hints appreciated. > > Victor. From drsalists at gmail.com Wed Dec 22 18:49:31 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 22 Dec 2010 15:49:31 -0800 Subject: Generator question In-Reply-To: <1jtwvox.1pxdxm314l5m06N%see@sig.for.address> References: <1jtwvox.1pxdxm314l5m06N%see@sig.for.address> Message-ID: On Wed, Dec 22, 2010 at 3:15 PM, Victor Eijkhout wrote: > So I have a generator, either as a free function or in a class and I > want to generate objects that are initialized from the generated things. > > def generator(): > ? ? ? ?for whatever: > ? ? ? ? ? ? ? ?yield something > class Object(): > ? ? ? ?def __init__(self): > ? ? ? ? ? ? ? ?self.data = # the next thing from generator > > I have not been able to implement this elegantly. For external reasons > the following syntax is unacceptable: > > for g in generator(): > ? ? ? ?ob = Object(g) > > I really want to be able to write "Object()" in any location and get a > properly initialized object. > > Hints appreciated. > > Victor. > -- > Victor Eijkhout -- eijkhout at tacc utexas edu > -- > http://mail.python.org/mailman/listinfo/python-list > You likely want a class variable: #!/usr/bin/python def generator(): i = 0 while True: yield i i += 1 class Object: gen = generator() def __init__(self): self.data = Object.gen.next() def __str__(self): return str(self.data) o1 = Object() o2 = Object() o3 = Object() print o1 print o2 print o3 From mafunk at nmsu.edu Wed Dec 22 19:03:23 2010 From: mafunk at nmsu.edu (Matt Funk) Date: Wed, 22 Dec 2010 17:03:23 -0700 Subject: using python ftp Message-ID: <4D1291CB.5010404@nmsu.edu> Hi, i was wondering whether someone can point me whether the following already exists. I want to connect to a server , download various files (for whose name i want to be able to use a wildcard), and store those files in a given location on the hard drive. If the file already exists i do not want to download it. This seems fairly trivial and i would assume that there should be some sort of implementation that does this easily but i didn't find anything googling it. Otherwise i was going to do it "by hand" using ftplib: 1) connect to server, 2) change to directory on server 3) get listing 4) match the file pattern i want to the listing 5) check if file already exists 6) download file if matched and doesn't exist Can anyone offer any advice whether this already done somewhere? thanks matt From hidura at gmail.com Wed Dec 22 19:05:56 2010 From: hidura at gmail.com (Hidura) Date: Wed, 22 Dec 2010 20:05:56 -0400 Subject: Python Web App In-Reply-To: <907fa80e-1814-4ddb-be32-ec14cfd53fab@29g2000yqq.googlegroups.com> References: <907fa80e-1814-4ddb-be32-ec14cfd53fab@29g2000yqq.googlegroups.com> Message-ID: I am creating one, is on test, what kind of app do you want create? 2010/12/22, Sean : > Anybody know where I can find a Python Development Environment in the > form of a web app for use with Chrome OS. I have been looking for a > few days and all i have been able to find is some old discussions with > python developers talking about they will want one for the OS to be a > success with them. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Enviado desde mi dispositivo m?vil Diego I. Hidalgo D. From usernet at ilthio.net Wed Dec 22 19:12:24 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 23 Dec 2010 00:12:24 +0000 (UTC) Subject: Python Web App References: <907fa80e-1814-4ddb-be32-ec14cfd53fab@29g2000yqq.googlegroups.com> Message-ID: On 2010-12-22, Sean wrote: > Anybody know where I can find a Python Development Environment in the > form of a web app for use with Chrome OS. I have been looking for a > few days and all i have been able to find is some old discussions with > python developers talking about they will want one for the OS to be a > success with them. Personally, I think a web app based IDE would be ghastly; but, you might have a look at Mozilla Skywriter (formerly Bespin): https://mozillalabs.com/skywriter/ From hidura at gmail.com Wed Dec 22 19:30:58 2010 From: hidura at gmail.com (Hidura) Date: Wed, 22 Dec 2010 20:30:58 -0400 Subject: Python Web App In-Reply-To: References: <907fa80e-1814-4ddb-be32-ec14cfd53fab@29g2000yqq.googlegroups.com> Message-ID: Why grashtly? 2010/12/22, Tim Harig : > On 2010-12-22, Sean wrote: >> Anybody know where I can find a Python Development Environment in the >> form of a web app for use with Chrome OS. I have been looking for a >> few days and all i have been able to find is some old discussions with >> python developers talking about they will want one for the OS to be a >> success with them. > > Personally, I think a web app based IDE would be ghastly; but, you might > have a look at Mozilla Skywriter (formerly Bespin): > > https://mozillalabs.com/skywriter/ > -- > http://mail.python.org/mailman/listinfo/python-list > -- Enviado desde mi dispositivo m?vil Diego I. Hidalgo D. From drsalists at gmail.com Wed Dec 22 19:42:35 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 22 Dec 2010 16:42:35 -0800 Subject: how to handle output generated after execution of command/script on host unix machine? In-Reply-To: References: Message-ID: On Sun, Dec 19, 2010 at 11:38 PM, Darshak Bavishi wrote: > Hi Experts, > I am still struggling with handling output generated after?execution?of > ?command/script on host unix machine using windows client machine > ssh code : > import sys > import datetime > import time > # setup logging > paramiko.util.log_to_file('darshak_simple.log') > ssh=paramiko.SSHClient() > ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) > ssh.connect("*****",username="****",password="****") > try: > ?? ?stdin,stdout,stderr=ssh.exec_command("BsPlSMProbe -f node -d > > /var/log/Darshak/3.txt ") // output of this command will be store in > /var/log/Darshak/ in remote machine > except: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? {Issue is > files are generating but remaining blank pls pls help me out of this} > ?? ?print "check" > time.sleep(10) > print stdout.readlines() > a=stdout.readlines() > print 1 > ssh.close() > #print stdout.readlines() > Issue is files are generating but remaining blank pls pls help me out of > this > -- > BR > Darshak Bavishi > > -- > BR > Darshak Bavishi > > -- > http://mail.python.org/mailman/listinfo/python-list I've never used paramiko, but I have done some python+ssh. 1) Are you wanting the output from BsPlSMProbe to go to /var/log/Darshak/3.txt or your print stdout.readlines()? If you need both, you'd probably better get a tee in there. 2) If /var/log/Darshak/3.txt is coming up empty, it could mean that BsPlSMProbe simply produces no output. What if you ssh into the server interactively (perhaps using openssh or putty), and your command from there, as the same user, with the same options? 3) If you want errors as well as normal output in the same place, try a 2>&1 in your shell command, assuming you're using sh/ksh/bash (POSIX shell). You can tell what shell you're in with echo $SHELL. 4) If paramiko allows you to access the exit status of the command, you probably should retrieve that, not just stdout (and stderr). Conventionally, if the exit status is 0, things are fine, if they're nonzero, something's wrong - the oppose of what you see in most other languages that treat integers as booleans, because there are usually more ways things can fail than succeed. In fact, strictly speaking, the presence or absence of text on stderr is not a good indication of an error, compared to checking the exit status. HTH From rockitout117 at yahoo.com Wed Dec 22 20:22:32 2010 From: rockitout117 at yahoo.com (Maurice Shih) Date: Wed, 22 Dec 2010 17:22:32 -0800 (PST) Subject: Python programming Message-ID: <941320.45416.qm@web59815.mail.ac4.yahoo.com> Dear python-list at python.org, Thank you for taking the time to listen to my request. I'm a beginner programmer and I se python 2.6. I am making a program that needs a command that can check if a value is in a list. For example to check whether 5 is in [2, 6, 5,]. Thank you for hearing my request. Maurice Shih -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at please.post Wed Dec 22 20:22:36 2010 From: no.email at please.post (kj) Date: Thu, 23 Dec 2010 01:22:36 +0000 (UTC) Subject: general problem when subclassing a built-in class Message-ID: Suppose that you want to implement a subclass of built-in class, to meet some specific design requirements. Where in the Python documentation can one find the information required to determine the minimal[1] set of methods that one would need to override to achieve this goal? In my experience, educated guesswork doesn't get one very far with this question. Here's a *toy example*, just to illustrate this last point. Suppose that one wants to implement a subclass of dict, call it TSDict, to meet these two design requirements: 1. for each one of its keys, an instance of TSDict should keep a timestamp (as given by time.time, and accessible via the new method get_timestamp(key)) of the last time that the key had a value assigned to it; 2. other than the added capability described in (1), an instance of TSDict should behave *exactly* like a built-in dictionary. In particular, we should be able to observe behavior like this: >>> d = TSDict((('uno', 1), ('dos', 2)), tres=3, cuatro=4) >>> d['cinco'] = 5 >>> d {'cuatro': 4, 'dos': 2, 'tres': 3, 'cinco': 5, 'uno': 1} >>> d.get_timestamp('uno') 1293046586.644436 OK, here's one strategy, right out of OOP 101: #--------------------------------------------------------------------------- from time import time class TSDict(dict): def __setitem__(self, key, value): # save the value and timestamp for key as a tuple; # see footnote [2] dict.__setitem__(self, key, (value, time())) def __getitem__(self, key): # extract the value from the value-timestamp pair and return it return dict.__getitem__(self, key)[0] def get_timestamp(self, key): # extract the timestamp from the value-timestamp pair and return it return dict.__getitem__(self, key)[1] #--------------------------------------------------------------------------- This implementation *should* work (again, at least according to OOP 101), but, in fact, it doesn't come *even close*: >>> d = TSDict((('uno', 1), ('dos', 2)), tres=3, cuatro=4) >>> d['cinco'] = 5 >>> d {'cuatro': 4, 'dos': 2, 'tres': 3, 'cinco': (5, 1293059516.942985), 'uno': 1} >>> d.get_timestamp('uno') Traceback (most recent call last): File "", line 1, in File "/tmp/tsdict.py", line 23, in get_timestamp return dict.__getitem__(self, key)[1] TypeError: 'int' object is not subscriptable >From the above you can see that TSDict fails at *both* of the design requirements listed above: it fails to add a timestamp to all keys in the dictionary (e.g. 'uno', ..., 'cuatro' didn't get a timestamp), and get_timestamp bombs; and it also fails to behave in every other respect exactly like a built-in dict (e.g., repr(d) reveals the timestamps and how they are kept). So back to the general problem: to implement a subclass of a built-in class to meet a given set of design specifications. Where is the documentation needed to do this without guesswork? Given results like the one illustrated above, I can think of only two approaches (other than scrapping the whole idea of subclassing a built-in class in the first place): 1) Study the Python C source code for the built-in class in the hopes of somehow figuring out what API methods need to be overridden; 2) Through blind trial-and-error, keep trying different implementation strategies and/or keep overriding additional built-in class methods until the behavior of the resulting subclass approximates sufficiently the design specs. IMO, both of these approaches suck. Approach (1) would take *me* forever, since I don't know the first thing about Python's internals, and even if I did, going behind the documented API like that would make whatever I implement very likely to break with future releases of Python. Approach (2) could also take a very long time (probably much longer than the implementation would take if no guesswork was involved), but worse than that, one would have little assurance that one's experimentation has truly uncovered all the necessary details; IME, programming-by-guesswork leads to numerous and often nasty bugs. Is there any other way? TIA! ~kj [1] The "minimal" bit in the question statement is just another way of specifying a "maximal" reuse of the built-in's class code. [2] For this example, I've accessed the parent's methods directly through dict rather than through super(TSDict, self), just to keep the code as uncluttered as possible, but the results are the same if one uses super. From maxc at me.com Wed Dec 22 20:35:26 2010 From: maxc at me.com (Max Countryman) Date: Wed, 22 Dec 2010 20:35:26 -0500 Subject: Python programming In-Reply-To: <941320.45416.qm@web59815.mail.ac4.yahoo.com> References: <941320.45416.qm@web59815.mail.ac4.yahoo.com> Message-ID: >>> 5 in [2, 6, 5] True Sent from my iPhone On Dec 22, 2010, at 20:22, Maurice Shih wrote: > Dear python-list at python.org, > Thank you for taking the time to listen to my request. I'm a beginner programmer and I se python 2.6. I am making a program that needs a command that can check if a value is in a list. For example to check whether 5 is in [2, 6, 5,]. Thank you for hearing my request. > Maurice Shih > > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.kaplan at case.edu Wed Dec 22 20:39:29 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 22 Dec 2010 20:39:29 -0500 Subject: Python programming In-Reply-To: <941320.45416.qm@web59815.mail.ac4.yahoo.com> References: <941320.45416.qm@web59815.mail.ac4.yahoo.com> Message-ID: If you're just starting out, look at the Python tutorial http://docs.python.org/tutorial/index.html This question is answered in the tutorial- specifically in http://docs.python.org/tutorial/datastructures.html#more-on-conditions Also, there's a separate list, the tutor at python.org , for people just learning python. http://www.python.org/mailman/listinfo/tutor On Wed, Dec 22, 2010 at 8:22 PM, Maurice Shih wrote: > > Dear python-list at python.org, > Thank you for taking the time to listen to my request. I'm a beginner programmer and I se python 2.6. I am making a program that needs a command that can check if a value is in a list. For example to check whether 5 is in [2, 6, 5,]. Thank you for hearing my request. > Maurice Shih > > -- > http://mail.python.org/mailman/listinfo/python-list > From no.email at please.post Wed Dec 22 20:41:08 2010 From: no.email at please.post (kj) Date: Thu, 23 Dec 2010 01:41:08 +0000 (UTC) Subject: issubclass(dict, Mapping) References: <4d127d5e$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: In <4d127d5e$0$29997$c3e8da3$5496439d at news.astraweb.com> Steven D'Aprano writes: >On Wed, 22 Dec 2010 14:20:51 +0000, kj wrote: >> Here's another example, fresh from today's crop of wonders: >> >> (v. 2.7.0) >>>>> from collections import Mapping >>>>> issubclass(dict, Mapping) >> True >>>>> dict.__bases__ >> (,) >>>>> [issubclass(b, Mapping) for b in dict.__bases__] >> [False] >> >> So dict is a subclass of Mapping, even though none of the bases of dict >> is either Mapping or a subclass of Mapping. Great. >Yes. So what? That's being deliberately obtuse. The situation described goes smack against standard OOP semantics, which would be fine if all this stuff was documented clearly and reasonably, i.e. in one (preferably "official") place rather than scattered over a bazillion separate documents, PEP this, module that, GvR musing #42, etc. Let's just say that I'm looking forward to the end to these surprises. ~kj From enalicho at gmail.com Wed Dec 22 20:43:30 2010 From: enalicho at gmail.com (Noah Hall) Date: Thu, 23 Dec 2010 01:43:30 +0000 Subject: Python programming In-Reply-To: <941320.45416.qm@web59815.mail.ac4.yahoo.com> References: <941320.45416.qm@web59815.mail.ac4.yahoo.com> Message-ID: The most Pythonic ways of checking if a value is within a list is to use the "in" keyword, for example, using your data - 5 in [2, 6, 5] Which will return True, as 5 is in the list. You can then use this in the following generic way - if variable in list: do_things Where variable is the varible you wish to seek, and the list is the list you wish to search. Might I also suggest that you use the *tutor*@*python*.org mailing list, where people are perhaps more ready to handle this sort of question. -------------- next part -------------- An HTML attachment was scrubbed... URL: From secris1 at gmail.com Wed Dec 22 20:51:46 2010 From: secris1 at gmail.com (Sean) Date: Wed, 22 Dec 2010 17:51:46 -0800 (PST) Subject: Python Web App References: <907fa80e-1814-4ddb-be32-ec14cfd53fab@29g2000yqq.googlegroups.com> Message-ID: <927a4339-0c9b-46c3-877e-46d939e7e397@w2g2000yqb.googlegroups.com> I am wanting to learn python and I am test a Chrome OS notebook at the same time so I need something that will atleast tell me if I have any syntax errors. Although the more features the better that way learning is an easier experience. On Dec 22, 7:05?pm, Hidura wrote: > I am creating one, is on test, what kind of app do you want create? > > 2010/12/22, Sean : > > > Anybody know where I can find a Python Development Environment in the > > form of a web app for use with Chrome OS. I have been looking for a > > few days and all i have been able to find is some old discussions with > > python developers talking about they will want one for the OS to be a > > success with them. > > -- > >http://mail.python.org/mailman/listinfo/python-list > > -- > Enviado desde mi dispositivo m?vil > > Diego I. Hidalgo D. From python at mrabarnett.plus.com Wed Dec 22 20:54:10 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 23 Dec 2010 01:54:10 +0000 Subject: Toy http server In-Reply-To: <4D127CF4.5070801@pythonmeister.com> References: <3d190cbf-be7d-4973-b85f-c030bb258742@glegroupsg2000goo.googlegroups.com> <4d127627$0$29997$c3e8da3$5496439d@news.astraweb.com> <4D127CF4.5070801@pythonmeister.com> Message-ID: <4D12ABC2.7060801@mrabarnett.plus.com> On 22/12/2010 22:34, Stefan Sonnenberg-Carstens wrote: > Sorry, this one is cross post. > I posted my question below some time ago to then jython ml, because this > hit me first with jython. > Anyway, time passed, problem not solved. > > So, I'd like to know if some of you know where my error lies: > [snip] What happens if the conns list contains a writer that's ready? The select function returns immediately with that writer in the writer list. If it's not srv then nothing is done with it, so execution just loops back to the select function with that writer still in the conns list, and the select function then returns immediately with that writer in the writer list again. Infinite loop! From secris1 at gmail.com Wed Dec 22 20:56:21 2010 From: secris1 at gmail.com (Sean) Date: Wed, 22 Dec 2010 17:56:21 -0800 (PST) Subject: Python Web App References: <907fa80e-1814-4ddb-be32-ec14cfd53fab@29g2000yqq.googlegroups.com> <927a4339-0c9b-46c3-877e-46d939e7e397@w2g2000yqb.googlegroups.com> Message-ID: <73e7f90a-c5d1-4ed8-8fef-6aa7f921aa2e@d8g2000yqf.googlegroups.com> Forgot to point out that Chrome OS has no local storage accessable to the user. Hence why I need a web based solution. On Dec 22, 8:51?pm, Sean wrote: > I am wanting to learn python and I am test a Chrome OS notebook at the > same time so I need something that will atleast tell me if I have any > syntax errors. Although the more features the better that way learning > is an easier experience. > > On Dec 22, 7:05?pm, Hidura wrote: > > > > > > > > > I am creating one, is on test, what kind of app do you want create? > > > 2010/12/22, Sean : > > > > Anybody know where I can find a Python Development Environment in the > > > form of a web app for use with Chrome OS. I have been looking for a > > > few days and all i have been able to find is some old discussions with > > > python developers talking about they will want one for the OS to be a > > > success with them. > > > -- > > >http://mail.python.org/mailman/listinfo/python-list > > > -- > > Enviado desde mi dispositivo m?vil > > > Diego I. Hidalgo D. From anurag.chourasia at gmail.com Wed Dec 22 21:12:44 2010 From: anurag.chourasia at gmail.com (Anurag Chourasia) Date: Thu, 23 Dec 2010 07:42:44 +0530 Subject: using python ftp In-Reply-To: <4D1291CB.5010404@nmsu.edu> References: <4D1291CB.5010404@nmsu.edu> Message-ID: Hi Matt, I have a snippet to "upload" files (that match a particular search pattern) to a remote server. Variable names are self explanatory. You could tweak this a little to "download" files instead. from ftplib import FTP ftp = FTP(hostname) ftp.login(user_id,passwd) ftp.cwd(remote_directory) files_list=glob.glob(file_search_pattern) for file in files_list: try: ftp.storlines('STOR ' + file, open(file)) except Exception, e: print ('Failed to FTP file: %s' %(file)) ftp.close() Regards, Anurag On Thu, Dec 23, 2010 at 5:33 AM, Matt Funk wrote: > Hi, > > i was wondering whether someone can point me whether the following > already exists. > > I want to connect to a server , download various files (for whose name i > want to be able to use a wildcard), and store those files in a given > location on the hard drive. If the file already exists i do not want to > download it. > > This seems fairly trivial and i would assume that there should be some > sort of implementation that does this easily but i didn't find anything > googling it. > > Otherwise i was going to do it "by hand" using ftplib: > 1) connect to server, > 2) change to directory on server > 3) get listing > 4) match the file pattern i want to the listing > 5) check if file already exists > 6) download file if matched and doesn't exist > > Can anyone offer any advice whether this already done somewhere? > > thanks > matt > -- > http://mail.python.org/mailman/listinfo/python-list > From hidura at gmail.com Wed Dec 22 21:21:17 2010 From: hidura at gmail.com (Hidura) Date: Wed, 22 Dec 2010 22:21:17 -0400 Subject: Python Web App In-Reply-To: <927a4339-0c9b-46c3-877e-46d939e7e397@w2g2000yqb.googlegroups.com> References: <907fa80e-1814-4ddb-be32-ec14cfd53fab@29g2000yqq.googlegroups.com> <927a4339-0c9b-46c3-877e-46d939e7e397@w2g2000yqb.googlegroups.com> Message-ID: Use editarea, that's the best option if you want something small, but as i said before i am developing a framework that allows you to create app's from the web and is much more complete than editarea. 2010/12/22, Sean : > I am wanting to learn python and I am test a Chrome OS notebook at the > same time so I need something that will atleast tell me if I have any > syntax errors. Although the more features the better that way learning > is an easier experience. > > On Dec 22, 7:05?pm, Hidura wrote: >> I am creating one, is on test, what kind of app do you want create? >> >> 2010/12/22, Sean : >> >> > Anybody know where I can find a Python Development Environment in the >> > form of a web app for use with Chrome OS. I have been looking for a >> > few days and all i have been able to find is some old discussions with >> > python developers talking about they will want one for the OS to be a >> > success with them. >> > -- >> >http://mail.python.org/mailman/listinfo/python-list >> >> -- >> Enviado desde mi dispositivo m?vil >> >> Diego I. Hidalgo D. > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Enviado desde mi dispositivo m?vil Diego I. Hidalgo D. From hidura at gmail.com Wed Dec 22 21:23:38 2010 From: hidura at gmail.com (Hidura) Date: Wed, 22 Dec 2010 22:23:38 -0400 Subject: Python Web App In-Reply-To: References: <907fa80e-1814-4ddb-be32-ec14cfd53fab@29g2000yqq.googlegroups.com> <927a4339-0c9b-46c3-877e-46d939e7e397@w2g2000yqb.googlegroups.com> Message-ID: My framework let you store online on a hosting server that the same framework provide. 2010/12/22, Hidura : > Use editarea, that's the best option if you want something small, but > as i said before i am developing a framework that allows you to create > app's from the web and is much more complete than editarea. > > 2010/12/22, Sean : >> I am wanting to learn python and I am test a Chrome OS notebook at the >> same time so I need something that will atleast tell me if I have any >> syntax errors. Although the more features the better that way learning >> is an easier experience. >> >> On Dec 22, 7:05?pm, Hidura wrote: >>> I am creating one, is on test, what kind of app do you want create? >>> >>> 2010/12/22, Sean : >>> >>> > Anybody know where I can find a Python Development Environment in the >>> > form of a web app for use with Chrome OS. I have been looking for a >>> > few days and all i have been able to find is some old discussions with >>> > python developers talking about they will want one for the OS to be a >>> > success with them. >>> > -- >>> >http://mail.python.org/mailman/listinfo/python-list >>> >>> -- >>> Enviado desde mi dispositivo m?vil >>> >>> Diego I. Hidalgo D. >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > -- > Enviado desde mi dispositivo m?vil > > Diego I. Hidalgo D. > -- Enviado desde mi dispositivo m?vil Diego I. Hidalgo D. From python at mrabarnett.plus.com Wed Dec 22 21:24:09 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 23 Dec 2010 02:24:09 +0000 Subject: using python ftp In-Reply-To: References: <4D1291CB.5010404@nmsu.edu> Message-ID: <4D12B2C9.7050304@mrabarnett.plus.com> On 23/12/2010 02:12, Anurag Chourasia wrote: > Hi Matt, > > I have a snippet to "upload" files (that match a particular search > pattern) to a remote server. > > Variable names are self explanatory. You could tweak this a little to > "download" files instead. > > from ftplib import FTP > ftp = FTP(hostname) > ftp.login(user_id,passwd) > ftp.cwd(remote_directory) > files_list=glob.glob(file_search_pattern) > for file in files_list: > try: > ftp.storlines('STOR ' + file, open(file)) You should open the file in binary mode: ftp.storlines('STOR ' + file, open(file, 'rb')) This isn't necessary on *nix, but it's recommended for portability. > except Exception, e: > print ('Failed to FTP file: %s' %(file)) > ftp.close() > [snip] From usernet at ilthio.net Wed Dec 22 21:41:33 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 23 Dec 2010 02:41:33 +0000 (UTC) Subject: Python Web App References: <907fa80e-1814-4ddb-be32-ec14cfd53fab@29g2000yqq.googlegroups.com> Message-ID: [Reordered to preserve context in bottom posting] On 2010-12-23, Hidura wrote: > 2010/12/22, Tim Harig : >> On 2010-12-22, Sean wrote: >>> Anybody know where I can find a Python Development Environment in the >>> form of a web app for use with Chrome OS. I have been looking for a >>> few days and all i have been able to find is some old discussions with >>> python developers talking about they will want one for the OS to be a >>> success with them. >> >> Personally, I think a web app based IDE would be ghastly; but, you might >> have a look at Mozilla Skywriter (formerly Bespin): > > Why grashtly? I don't personally think the web makes a good framework for highly interactive applications as they must work within the constraints of the browser and IDEs are highly interactive applications by their very nature. Perhaps HTML5/CSS3 will change things; but, standard DOM manipulation, as I am accustomed to seeing it, cannot generate the kind of rendering that is available from native applications. Attempts to do so end up being kludgy. It also cannot handle the kinds of desktop integrations that are common for native applications without opening up serious security trust issues. (Can everybody say ActiveX fiasco?) Finally, there are difficulties in handling keystrokes without conflicting with the browser's native key bindings. I seldom ever touch a mouse and I am a huge fan of vi, mutt, slrn, screen, ratpoison, etc. where the primary interface is totally accessable through the keyboard without having to tab through many options. From anurag.chourasia at gmail.com Wed Dec 22 21:43:01 2010 From: anurag.chourasia at gmail.com (Anurag Chourasia) Date: Thu, 23 Dec 2010 08:13:01 +0530 Subject: Python programming In-Reply-To: <941320.45416.qm@web59815.mail.ac4.yahoo.com> References: <941320.45416.qm@web59815.mail.ac4.yahoo.com> Message-ID: Here you go..... $ python Python 2.5.2 (r252:60911, Dec 2 2008, 09:26:14) [GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> A=[2,6,5] >>> if 5 in A: ... print 'Yes' ... else: ... print 'No' ... Yes >>> Regards, Anurag On Thu, Dec 23, 2010 at 6:52 AM, Maurice Shih wrote: > Dear python-list at python.org, > Thank you for taking the time to listen to my request. I'm a beginner > programmer and I se python 2.6. I am making a program that needs a command > that can check if a value is in a list. For example to check whether 5 is in > [2, 6, 5,]. Thank you for hearing my request. > Maurice Shih > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From see at sig.for.address Wed Dec 22 21:45:54 2010 From: see at sig.for.address (Victor Eijkhout) Date: Wed, 22 Dec 2010 20:45:54 -0600 Subject: Generator question References: <1jtwvox.1pxdxm314l5m06N%see@sig.for.address> Message-ID: <1jtx5my.ewrrejlduocgN%see@sig.for.address> Dan Stromberg wrote: > You likely want a class variable: Sounds like an elegant solution. Thanks! Victor. -- Victor Eijkhout -- eijkhout at tacc utexas edu From hidura at gmail.com Wed Dec 22 22:22:26 2010 From: hidura at gmail.com (Hidura) Date: Wed, 22 Dec 2010 23:22:26 -0400 Subject: Python Web App In-Reply-To: References: <907fa80e-1814-4ddb-be32-ec14cfd53fab@29g2000yqq.googlegroups.com> Message-ID: Ok, but you are comparing a web-based framework with a native-based framework that use the components of the system to make all the things that need, a web-based framewok use the resourses of the browser to make it all, so the developer that use a framework on the web can't expect get the same results, in my case i beleive that a web-based framework adjust better to the needs if you'll make a web-app, otherwise use eclipse or netbeans. 2010/12/22, Tim Harig : > [Reordered to preserve context in bottom posting] > On 2010-12-23, Hidura wrote: >> 2010/12/22, Tim Harig : >>> On 2010-12-22, Sean wrote: >>>> Anybody know where I can find a Python Development Environment in the >>>> form of a web app for use with Chrome OS. I have been looking for a >>>> few days and all i have been able to find is some old discussions with >>>> python developers talking about they will want one for the OS to be a >>>> success with them. >>> >>> Personally, I think a web app based IDE would be ghastly; but, you might >>> have a look at Mozilla Skywriter (formerly Bespin): >> >> Why grashtly? > > I don't personally think the web makes a good framework for highly > interactive applications as they must work within the constraints of the > browser and IDEs are highly interactive applications by their very nature. > Perhaps HTML5/CSS3 will change things; but, standard DOM manipulation, > as I am accustomed to seeing it, cannot generate the kind of rendering > that is available from native applications. Attempts to do so end up being > kludgy. > > It also cannot handle the kinds of desktop integrations that are common > for native applications without opening up serious security trust issues. > (Can everybody say ActiveX fiasco?) > > Finally, there are difficulties in handling keystrokes without conflicting > with the browser's native key bindings. I seldom ever touch a mouse > and I am a huge fan of vi, mutt, slrn, screen, ratpoison, etc. where > the primary interface is totally accessable through the keyboard without > having to tab through many options. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Enviado desde mi dispositivo m?vil Diego I. Hidalgo D. From steve+comp.lang.python at pearwood.info Wed Dec 22 22:22:40 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Dec 2010 03:22:40 GMT Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> Message-ID: <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> On Wed, 22 Dec 2010 13:53:20 -0800, Carl Banks wrote: > On Dec 22, 8:52?am, kj wrote: >> In Robert Kern >> writes: >> >> >Obfuscating the location that an exception gets raised prevents a lot >> >of debugging... >> >> The Python interpreter does a lot of that "obfuscation" already, and I >> find the resulting tracebacks more useful for it. >> >> An error message is only useful to a given audience if that audience >> can use the information in the message to modify what they are doing to >> avoid the error. > > So when the audience files a bug report it's not useful for them to > include the whole traceback? Well, given the type of error KJ has been discussing, no, it isn't useful. Fault: function raises documented exception when passed input that is documented as being invalid What steps will reproduce the problem? 1. call the function with invalid input 2. read the exception that is raised 3. note that it is the same exception as documented What is the expected output? What do you see instead? Excepted somebody to hit me on the back of the head and tell me not to call the function with invalid input. Instead I just got an exception. You seem to have completely missed that there will be no bug report, because this isn't a bug. (Or if it is a bug, the bug is elsewhere, external to the function that raises the exception.) It is part of the promised API. The fact that the exception is generated deep down some chain of function calls is irrelevant. The analogy is this: imagine a function that delegates processing of the return result to different subroutines: def func(arg): if arg > 0: return _inner1(arg) else: return _inner2(arg) This is entirely irrelevant to the caller. When they receive the return result from calling func(), they have no way of knowing where the result came from, and wouldn't care even if they could. Return results hide information about where the result was calculated, as they should. Why shouldn't deliberate, explicit, documented exceptions be treated the same? Tracebacks expose the implementation details of where the exception was generated. This is the right behaviour if the exception is unexpected -- a bug internal to func -- since you need knowledge of the implementation of func in order to fix the unexpected exception. So far so good -- we accept that Python's behaviour under these circumstances is correct. But this is not the right behaviour when the exception is expected, e.g. an explicitly raised exception in response to an invalid argument. In this case, the traceback exposes internal details of no possible use to the caller. What does the caller care if func() delegates (e.g.) input checking to a subroutine? The subroutine is an irrelevant implementation detail. The exception is promised output of the function, just as much so as if it were a return value. Consider the principle that exceptions should be dealt with as close as possible to the actual source of the problem: >>> f('good input') Traceback (most recent call last): File "", line 1, in File "", line 2, in f File "", line 2, in g File "", line 2, in h File "", line 2, in i File "", line 2, in j File "", line 2, in k <=== error occurs here, and shown here ValueError But now consider the scenario where the error is not internal to f, but external. The deeper down the stack trace you go, the further away from the source of the error you get. The stack trace now obscures the source of the error, rather than illuminating it: >>> f('bad input') <=== error occurs here Traceback (most recent call last): File "", line 1, in File "", line 2, in f File "", line 2, in g File "", line 2, in h File "", line 2, in i File "", line 2, in j File "", line 2, in k <=== far from the source of error ValueError There's no point in inspecting function k for a bug when the problem has nothing to do with k. The problem is that the input fails to match the pre-conditions for f. From the perspective of the caller, the error has nothing to do with k, k is a meaningless implementation detail, and the source of the error is the mismatch between the input and what f expects. And so by the principle of dealing with exceptions as close as possible to the source of the error, we should desire this traceback instead: >>> f('bad input') <=== error occurs here Traceback (most recent call last): File "", line 1, in File "", line 2, in f <=== matches where the error occurs ValueError In the absence of any practical way for function f to know whether an arbitrary exception in a subroutine is a bug or not, the least-worst decision is Python's current behaviour: take the conservative, risk- adverse path and assume the worst, treat the exception as a bug in the subroutine, and expose the entire stack trace. But, I suggest, we can do better using the usual Python strategy of implementing sensible default behaviour but allowing objects to customize themselves. Objects can declare themselves to be instances of some other class, or manipulate what names are reported by dir. Why shouldn't a function deliberately and explicitly take ownership of an exception raised by a subroutine? There should be a mechanism for Python functions to distinguish between unexpected exceptions (commonly known as "bugs"), which should be reported as coming from wherever they come from, and documented, expected exceptions, which should be reported as coming from the function regardless of how deep the function call stack really is. -- Steven From steve+comp.lang.python at pearwood.info Wed Dec 22 22:28:56 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Dec 2010 03:28:56 GMT Subject: issubclass(dict, Mapping) References: <4d127d5e$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4d12c1f7$0$30000$c3e8da3$5496439d@news.astraweb.com> On Thu, 23 Dec 2010 01:41:08 +0000, kj wrote: > In <4d127d5e$0$29997$c3e8da3$5496439d at news.astraweb.com> Steven D'Aprano > writes: > >>On Wed, 22 Dec 2010 14:20:51 +0000, kj wrote: > >>> Here's another example, fresh from today's crop of wonders: >>> >>> (v. 2.7.0) >>>>>> from collections import Mapping >>>>>> issubclass(dict, Mapping) >>> True >>>>>> dict.__bases__ >>> (,) >>>>>> [issubclass(b, Mapping) for b in dict.__bases__] >>> [False] >>> >>> So dict is a subclass of Mapping, even though none of the bases of >>> dict is either Mapping or a subclass of Mapping. Great. > > >>Yes. So what? > > That's being deliberately obtuse. The situation described goes smack > against standard OOP semantics, What are these "standard OOP semantics" you're referring to, and who made them "standard"? If people can't even decide whether multiple inheritance should be allowed or not, what makes you think that there is any such thing as "standard OOP"? I think you are confusing concrete implementation details with the interface. The interface for subclass testing in Python is as follows: A class K is a subclass of class C if, and only if, issubclass(C, K) returns a true result. That's it. Everything else is implementation. __bases__ is implementation. __subclasscheck__ is implementation. If Python adds a third mechanism for implementing subclass checks in version 3.3 or 3.4, the interface will just continue to work correctly. > which would be fine if all this stuff > was documented clearly and reasonably, i.e. in one (preferably > "official") place rather than scattered over a bazillion separate > documents, PEP this, module that, GvR musing #42, etc. This is documented, in the docs. http://docs.python.org/reference/datamodel.html#customizing-instance-and-subclass-checks Nobody says the Python docs are perfect, but most things you ask are in there. Patches for the docs to improve them are welcome. -- Steven From angrybaldguy at gmail.com Wed Dec 22 22:33:52 2010 From: angrybaldguy at gmail.com (Owen Jacobson) Date: Wed, 22 Dec 2010 22:33:52 -0500 Subject: general problem when subclassing a built-in class References: Message-ID: <201012222233525310-angrybaldguy@gmailcom> On 2010-12-22 20:22:36 -0500, kj said: > Suppose that you want to implement a subclass of built-in class, to > meet some specific design requirements. > > Where in the Python documentation can one find the information > required to determine the minimal[1] set of methods that one would > need to override to achieve this goal? (Rest elided.) The short answer is that you can't everything you want. If some behaviour or implementation detail isn't documented, you can't make any assumptions about how a class works, even if you really want to. Whatever you figure out by "educated guesswork" (or, even better, reading the source) is, absent documentation, not guaranteed, and behaviour that's not guaranteed can and will change whenever the code's maintaners feel like it. This is true for for builtins, for things in the standard library, and for things in competently-maintained third party libraries. Requiring that every class document its internals extensively enough to permit subclasses to modify behaviour in totally arbitrary ways has to be balanced against allowing each class's interface to usefully abstract its internal workings. Especially in a duck-typed language like Python, there's very little need for subclassing simply to intercept one or two method calls, and the resulting composition-based system is both more flexible and, being based on documented and stable interfaces, easier to maintain and support. Subclassing is a powerful tool, not suited to every design problem. In your case (tracking timestamps in a dict-like container), you're probably better off implementing your own dict-like container, with support for as much or as little of the protocol you want. You can do that without subclassing dict: the protocol for dict is not difficult to implement, especially if your backing storage is a real dict. What forces do you imagine require you to use a subclass for this? -o From usernet at ilthio.net Wed Dec 22 22:54:07 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 23 Dec 2010 03:54:07 +0000 (UTC) Subject: Python Web App References: <907fa80e-1814-4ddb-be32-ec14cfd53fab@29g2000yqq.googlegroups.com> Message-ID: On 2010-12-23, Hidura wrote: > Ok, but you are comparing a web-based framework with a native-based > framework that use the components of the system to make all the things > that need, a web-based framewok use the resourses of the browser to Right. That is exactly what I am comparing. > make it all, so the developer that use a framework on the web can't > expect get the same results, in my case i beleive that a web-based Which is exactly the problem with web apps that are highly interactive. My suggestion, is not to develope a web based IDE or use one. It just isn't something that the web was designed to do well. > expect get the same results, in my case i beleive that a web-based > framework adjust better to the needs if you'll make a web-app, Most IDEs that are targeted at web developement have a built in web browser or strong integration with one to run the web app as you are developing it. I don't see any advantage or the necessity of actually running the IDE code itself in the browser. > otherwise use eclipse or netbeans. I would; but then, I wouldn't purchase an operating system that is entirely based on a web browser. From hidura at gmail.com Wed Dec 22 23:30:58 2010 From: hidura at gmail.com (hidura at gmail.com) Date: Thu, 23 Dec 2010 04:30:58 +0000 Subject: Python Web App In-Reply-To: Message-ID: <20cf30433d361963ec04980c5652@google.com> > Which is exactly the problem with web apps that are highly interactive. My > suggestion, is not to develope a web based IDE or use one. It just isn't > something that the web was designed to do well. Is not a problem of the IDE, the problem is on what the developer expect as i said i you want something to the desktop well use an IDE that creates apps for desktop, but if you need something for the web you can try on a web-based IDE. > Most IDEs that are targeted at web developement have a built in web > browser > or strong integration with one to run the web app as you are developing > it. > I don't see any advantage or the necessity of actually running the IDE > code > itself in the browser. That's the problem an integration with one, my IDE works on all of them and the result is the same in IE and Chrome or FF, a web page cannot be designed to one browser it has to be designed to all the browser and have to be same. On the visualization is more difficult but nobody could control perfectly that but on the results of the data is has to be the same. > I would; but then, I wouldn't purchase an operating system that is > entirely > based on a web browser. I support that, but the target of those OS are use the share resources of the pc, smartphone, etc and the server. On Dec 22, 2010 11:54pm, Tim Harig wrote: > On 2010-12-23, Hidura hidura at gmail.com> wrote: > > Ok, but you are comparing a web-based framework with a native-based > > framework that use the components of the system to make all the things > > that need, a web-based framewok use the resourses of the browser to > Right. That is exactly what I am comparing. > > make it all, so the developer that use a framework on the web can't > > expect get the same results, in my case i beleive that a web-based > Which is exactly the problem with web apps that are highly interactive. My > suggestion, is not to develope a web based IDE or use one. It just isn't > something that the web was designed to do well. > > expect get the same results, in my case i beleive that a web-based > > framework adjust better to the needs if you'll make a web-app, > Most IDEs that are targeted at web developement have a built in web > browser > or strong integration with one to run the web app as you are developing > it. > I don't see any advantage or the necessity of actually running the IDE > code > itself in the browser. > > otherwise use eclipse or netbeans. > I would; but then, I wouldn't purchase an operating system that is > entirely > based on a web browser. > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Thu Dec 23 00:42:07 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 22 Dec 2010 21:42:07 -0800 Subject: Python programming In-Reply-To: <941320.45416.qm@web59815.mail.ac4.yahoo.com> References: <941320.45416.qm@web59815.mail.ac4.yahoo.com> Message-ID: If it's a big list and you're checking multiple times, you're probably better off converting the list to a set, and using "in" on the set. Once you have your list converted to a set, you can update both quickly. On Wed, Dec 22, 2010 at 5:22 PM, Maurice Shih wrote: > Dear python-list at python.org, > Thank you for taking the time to listen to my request. I'm a beginner > programmer and I se python 2.6. I am making a program that needs a command > that can check if a value is in a list. For example to check whether 5 is in > [2, 6, 5,]. Thank you for hearing my request. > Maurice Shih > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tooscattered at gmail.com Thu Dec 23 01:36:08 2010 From: tooscattered at gmail.com (scattered) Date: Wed, 22 Dec 2010 22:36:08 -0800 (PST) Subject: simple games w/o pygame References: Message-ID: On Dec 22, 11:40?am, William Gill wrote: > I am teaching an 11 year old who wants to learn programming. ?I chose > Python, and it is working well. ?I seem to remember lots of simple > script games, like quizzes, number games etc. that would be good for his > tutorial. ?However, now all I can find is more complex games using > Pygame. ?Can anyone help me out here? Maybe you can check out the book "Python Programming for the Absolute Beginner, 3rd Edition" by Michael Dawson. Its emphasis is on simple games. My son is (who is older - just turned 17) is working through it now and finding it easy going. From benedict.verheyen at gmail.com Thu Dec 23 02:53:47 2010 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Thu, 23 Dec 2010 08:53:47 +0100 Subject: compiling Python 2.7.1 with readline module fails on Debian (Virtualbox) In-Reply-To: References: Message-ID: On 22/12/2010 18:57, Jim Pharis wrote: > are you running make clean for good measure? Yes, i am. I am gong to try and uninstall Python2.7 from $HOME/local and see if that makes a difference. Maybe it interferes with the build process? Regards, Benedict From yccheok at yahoo.com Thu Dec 23 03:33:26 2010 From: yccheok at yahoo.com (Yan Cheng CHEOK) Date: Thu, 23 Dec 2010 00:33:26 -0800 (PST) Subject: Unable to decode file written by C++ wostringstream Message-ID: <482310.52893.qm@web65701.mail.ac4.yahoo.com> Currently, I have the following text file (https://sites.google.com/site/yanchengcheok/Home/TEST.TXT?attredirects=0&d=1) written by C++ wostringstream. What I want to do it, I want to write a python script which accept user browser request, and then send over the entire file for user to download. The downloaded file, should be exactly same as the original text file inside server itself. The code is written as follow : import cgi print "Content-Type: text/plain" print "Content-Disposition: attachment; filename=TEST.txt" print filename = "C:\\TEST.TXT" f = open(filename, 'r') for line in f: print line However, when I open up the downloaded file, the file is all having weird characters. I try to use rb flag, it doesn't either. Is there anything I had missed out? What I wish is, the file (TEST.TXT) downloaded by the client by making query to the above script, will be exactly same as the one in server. I also try to specific the encoding explicitly. import cgi print "Content-Type: text/plain; charset=UTF-16" print "Content-Disposition: attachment; filename=TEST.txt" print filename = "C:\\TEST.TXT" f = open(filename, 'r') for line in f: print line.encode('utf-16') It doesn't work either. Here is the screen shoot for original text file (http://i.imgur.com/S6SjX.png) and file after downloaded from a web browser. (http://i.imgur.com/l39Lc.png) Is there anything I had missed out? Thanks and Regards Yan Cheng CHEOK From orasnita at gmail.com Thu Dec 23 03:46:51 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Thu, 23 Dec 2010 10:46:51 +0200 Subject: using python ftp References: <4D1291CB.5010404@nmsu.edu> Message-ID: Can this lib also work with ftps? Thanks. Octavian ----- Original Message ----- From: "Anurag Chourasia" To: "Matt Funk" Cc: Sent: Thursday, December 23, 2010 4:12 AM Subject: Re: using python ftp > Hi Matt, > > I have a snippet to "upload" files (that match a particular search > pattern) to a remote server. > > Variable names are self explanatory. You could tweak this a little to > "download" files instead. > > from ftplib import FTP > ftp = FTP(hostname) > ftp.login(user_id,passwd) > ftp.cwd(remote_directory) > files_list=glob.glob(file_search_pattern) > for file in files_list: > try: > ftp.storlines('STOR ' + file, open(file)) > except Exception, e: > print ('Failed to FTP file: %s' %(file)) > ftp.close() > > Regards, > Anurag > > On Thu, Dec 23, 2010 at 5:33 AM, Matt Funk wrote: >> Hi, >> >> i was wondering whether someone can point me whether the following >> already exists. >> >> I want to connect to a server , download various files (for whose name i >> want to be able to use a wildcard), and store those files in a given >> location on the hard drive. If the file already exists i do not want to >> download it. >> >> This seems fairly trivial and i would assume that there should be some >> sort of implementation that does this easily but i didn't find anything >> googling it. >> >> Otherwise i was going to do it "by hand" using ftplib: >> 1) connect to server, >> 2) change to directory on server >> 3) get listing >> 4) match the file pattern i want to the listing >> 5) check if file already exists >> 6) download file if matched and doesn't exist >> >> Can anyone offer any advice whether this already done somewhere? >> >> thanks >> matt >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > -- > http://mail.python.org/mailman/listinfo/python-list From benedict.verheyen at gmail.com Thu Dec 23 04:04:13 2010 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Thu, 23 Dec 2010 10:04:13 +0100 Subject: compiling Python 2.7.1 with readline module fails on Debian (Virtualbox) In-Reply-To: <4D1239AD.7010907@pythonmeister.com> References: <4D1239AD.7010907@pythonmeister.com> Message-ID: On 22/12/2010 18:47, Stefan Sonnenberg-Carstens wrote: > Am 22.12.2010 09:33, schrieb Benedict Verheyen: >> > Did you try > > apt-get install build-essential > apt-get build-dep python2.7 > > before trying to compile ? > > Anyway, the config.log file is always of special interest. > Btw, which Debian release are you running ? > If the system is set up correctly it should not be necessary to change env vars to get it built. > > I use Debian stable so "apt-get build-dep python2.7" doesn't work. I removed all installed Python 2.7.1 files and so on and tried to build/install from scratch. Now i can't get Python to find the readline library. What is the normal procedure to make sure the readline library is found? I downloaded readline 6.1, build it and installed it to $HOME/local $HOME/local/lib contains libreadline.so. I did the following to try to enable detection of the libreadline: - export LD_LIBRARY_PATH=$HOME/local/lib:$LD_LIBRARY_PATH - vi Modules/Setup and uncomment the line that specifies the readline module. Added -L$HOME/local/lib - Tried ./configure with env CPPFLAGS="-I$HOME/local/include" LDFLAGS="-L$HOME/local/lib" - Edit setup.py, to add_dirs to $HOME/local/include and $HOME/local/lib - Tried to export CPPFLAGS and LDFLAGS Nothing seems to work. What am i doing wrong? Cheers, Benedict From wxjmfauth at gmail.com Thu Dec 23 04:47:35 2010 From: wxjmfauth at gmail.com (jmfauth) Date: Thu, 23 Dec 2010 01:47:35 -0800 (PST) Subject: Unable to decode file written by C++ wostringstream References: Message-ID: <51ba0526-f37d-493f-8593-463bd8ac7f9a@m35g2000vbn.googlegroups.com> On 23 Dez., 09:33, Yan Cheng CHEOK wrote: > Currently, I have the following text file (https://sites.google.com/site/yanchengcheok/Home/TEST.TXT?attredirect...) written by C++ wostringstream. > The coding of the file is utf-16le. You should take care of this coding when you *read* the file, and not when you display its content. >>> import io >>> with io.open('test.txt', 'r', encoding='utf-16le') as f: ... r = f.readlines() ... >>> len(r) 94 >>> r[:5] [u'\n', u' 0.000 1.500 3.000 0.526 0.527 0.527 0.00036 0.00109 1381.88 485.07\n', u' 0.000 1.500 3.000 1.084 1.085 1.086 0.00037 0.00111 1351.86 978.02\n', u' 0.000 1.500 3.000 1.166 1.167 1.168 0.00043 0.00130 1152.71 897.16\n', u' -3.000 0.000 3.000 -0.031 -0.029 -0.025 0.00158 0.00475 632.17 626.13\n'] >>> # from there, do what you wish with this list... >>> jmf From stefan.sonnenberg at pythonmeister.com Thu Dec 23 05:00:33 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Thu, 23 Dec 2010 11:00:33 +0100 Subject: compiling Python 2.7.1 with readline module fails on Debian (Virtualbox) In-Reply-To: References: <4D1239AD.7010907@pythonmeister.com> Message-ID: <4D131DC1.4060104@pythonmeister.com> Am 23.12.2010 10:04, schrieb Benedict Verheyen: > On 22/12/2010 18:47, Stefan Sonnenberg-Carstens wrote: >> Am 22.12.2010 09:33, schrieb Benedict Verheyen: > >> Did you try >> >> apt-get install build-essential >> apt-get build-dep python2.7 >> >> before trying to compile ? >> >> Anyway, the config.log file is always of special interest. >> Btw, which Debian release are you running ? >> If the system is set up correctly it should not be necessary to change env vars to get it built. >> >> > I use Debian stable so "apt-get build-dep python2.7" doesn't work. > I removed all installed Python 2.7.1 files and so on and tried to build/install from scratch. > Now i can't get Python to find the readline library. > What is the normal procedure to make sure the readline library is found? > > I downloaded readline 6.1, build it and installed it to $HOME/local > $HOME/local/lib contains libreadline.so. > > I did the following to try to enable detection of the libreadline: > > - export LD_LIBRARY_PATH=$HOME/local/lib:$LD_LIBRARY_PATH > - vi Modules/Setup and uncomment the line that specifies the readline module. > Added -L$HOME/local/lib > - Tried ./configure with env CPPFLAGS="-I$HOME/local/include" LDFLAGS="-L$HOME/local/lib" > - Edit setup.py, to add_dirs to $HOME/local/include and $HOME/local/lib > - Tried to export CPPFLAGS and LDFLAGS > > Nothing seems to work. > What am i doing wrong? > > Cheers, > Benedict > apt-get build-dep python 2.6 should do, the dependencies haven't changed (IMHO). Then wipe away $HOME/usr/local (if you can, btw), reset all env vars to default (perhaps reboot). Then untar python from scratch, cd into that dir, and type ./configure --prefix=$HOME/usr/local make make install that should be all. Otherwise your box is somewhat messed up. Anyway, your config.log is of special interest (did I say that already ?) From pavlovevidence at gmail.com Thu Dec 23 05:54:52 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 23 Dec 2010 02:54:52 -0800 (PST) Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Dec 22, 7:22?pm, Steven D'Aprano wrote: > There should be a mechanism for Python functions to distinguish between > unexpected exceptions (commonly known as "bugs"), which should be > reported as coming from wherever they come from, and documented, expected > exceptions, which should be reported as coming from the function > regardless of how deep the function call stack really is. No, -100. The traceback isn't the place for this. I've never disagreed with you more, and I've disagreed with you and awful lot. Carl Banks From ulrich.eckhardt at dominolaser.com Thu Dec 23 06:15:33 2010 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Thu, 23 Dec 2010 12:15:33 +0100 Subject: Unable to decode file written by C++ wostringstream References: Message-ID: Yan Cheng CHEOK wrote: > Currently, I have the following text file > (https://sites.google.com/site/yanchengcheok/Home/TEST.TXT?attredirects=0&d=1) > written by C++ wostringstream. Stringstream? I guess you meant wofstream, or? Anyway, the output encoding of C++ iostreams is implementation-defined, so you can't assume that such code is generally portable. If you want a certain encoding, you need to tell the ofstream using the codecvt facet of the locale, a websearch should turn up more info on that. If you have the data in memory and it is encoded as UTF-16 there (which is what MS Windows uses for its wchar_t) then you could also use a plain ofstream, open it with the binary flag and then simply write the memory to a file. In any case, you need to know the encoding in order to get the content into a Python string or unicode object, otherwise you will only get garbage. Good luck! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From rolf.oltmans at gmail.com Thu Dec 23 07:01:03 2010 From: rolf.oltmans at gmail.com (Oltmans) Date: Thu, 23 Dec 2010 04:01:03 -0800 (PST) Subject: Hosting a Python based TCP server Message-ID: Hi all, I'm writing a very small TCP server(written in Python) and now I want to host it on some ISP so that it can be accessed anywhere from the Internet. I've never done that before so I thought I should ask for some advice. Do you guys know any good ISP that can let me do that? Most importantly, what is usually involved in order to make this happen? Please pardon my ignorance and I will really appreciate your reply. Thanks in advance. From icanbob at gmail.com Thu Dec 23 07:40:26 2010 From: icanbob at gmail.com (bobicanprogram) Date: Thu, 23 Dec 2010 04:40:26 -0800 (PST) Subject: Hosting a Python based TCP server References: Message-ID: <4f87d9de-43be-480b-af56-9912cf657211@t35g2000yqj.googlegroups.com> On Dec 23, 7:01 am, Oltmans wrote: > Hi all, > > I'm writing a very small TCP server(written in Python) and now I want > to host it on some ISP so that it can be accessed anywhere from the > Internet. I've never done that before so I thought I should ask for > some advice. Do you guys know any good ISP that can let me do that? > > Most importantly, what is usually involved in order to make this > happen? > > Please pardon my ignorance and I will really appreciate your reply. > Thanks in advance. If you are familiar with Linux a Linode (http://www.linode.com) might be a perfect option for you. They even offer month by month rentals. bob From python at bdurham.com Thu Dec 23 08:05:43 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 23 Dec 2010 08:05:43 -0500 Subject: Hosting a Python based TCP server In-Reply-To: References: Message-ID: <1293109543.5171.1411762127@webmail.messagingengine.com> Rolf, > I'm writing a very small TCP server (written in Python) and now I want to host it on some ISP so that it can be accessed anywhere from the Internet. I've never done that before so I thought I should ask for some advice. Do you guys know any good ISP that can let me do that? I'm a big fan of webfaction.com. I think they will support this type of project. Malcolm From awilliam at whitemice.org Thu Dec 23 08:06:38 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Thu, 23 Dec 2010 08:06:38 -0500 Subject: Hosting a Python based TCP server In-Reply-To: <4f87d9de-43be-480b-af56-9912cf657211@t35g2000yqj.googlegroups.com> References: <4f87d9de-43be-480b-af56-9912cf657211@t35g2000yqj.googlegroups.com> Message-ID: <1293109598.7957.11.camel@linux-yu4c.site> On Thu, 2010-12-23 at 04:40 -0800, bobicanprogram wrote: > On Dec 23, 7:01 am, Oltmans wrote: > > Hi all, > > I'm writing a very small TCP server(written in Python) and now I want > > to host it on some ISP so that it can be accessed anywhere from the > > Internet. I've never done that before so I thought I should ask for > > some advice. Do you guys know any good ISP that can let me do that? > > Most importantly, what is usually involved in order to make this > > happen? > > Please pardon my ignorance and I will really appreciate your reply. > > Thanks in advance. > If you are familiar with Linux a Linode (http://www.linode.com) might > be a perfect option for you. They even offer month by month rentals. +1 Linode; performance is good, support is excellent. From benedict.verheyen at gmail.com Thu Dec 23 08:09:41 2010 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Thu, 23 Dec 2010 14:09:41 +0100 Subject: compiling Python 2.7.1 with readline module fails on Debian (Virtualbox) In-Reply-To: <4D131DC1.4060104@pythonmeister.com> References: <4D1239AD.7010907@pythonmeister.com> <4D131DC1.4060104@pythonmeister.com> Message-ID: On 23/12/2010 11:00, Stefan Sonnenberg-Carstens wrote: > apt-get build-dep python 2.6 > should do, the dependencies haven't changed (IMHO). > Then wipe away $HOME/usr/local (if you can, btw), > reset all env vars to default (perhaps reboot). > Then untar python from scratch, cd into that dir, and type > ./configure --prefix=$HOME/usr/local > make > make install > > that should be all. > Otherwise your box is somewhat messed up. > > Anyway, your config.log is of special interest (did I say that already ?) I started from scratch. I tried to build readline 6 and 5, and installing the packages system wide as opposed to $HOME/local, but everytime Python fails to find it. On stable, apt-get build-dep python 2.6 doesn't work, but apt-get build-dep python 2.5 does so i did that. At configure time, the libreadline library is now found but i have no clue why it didn't find the readline version i built. At the end of the Python build, it still ends with this message: Failed to build these modules: readline The other modules that where automatically installed via the build-dep command are built successfully. I have pasted the config.log here: http://paste.pocoo.org/show/308859/ Thanks, Benedict From srbc2010 at gmail.com Thu Dec 23 08:31:52 2010 From: srbc2010 at gmail.com (paulraj) Date: Thu, 23 Dec 2010 05:31:52 -0800 (PST) Subject: hot Message-ID: http://srbc2010.blogspot.com http://srbcmusic.blogspot.com From fetchinson at googlemail.com Thu Dec 23 08:47:54 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 23 Dec 2010 14:47:54 +0100 Subject: Python Web App In-Reply-To: References: <907fa80e-1814-4ddb-be32-ec14cfd53fab@29g2000yqq.googlegroups.com> Message-ID: >>>> Anybody know where I can find a Python Development Environment in the >>>> form of a web app for use with Chrome OS. I have been looking for a >>>> few days and all i have been able to find is some old discussions with >>>> python developers talking about they will want one for the OS to be a >>>> success with them. >>> >>> Personally, I think a web app based IDE would be ghastly; but, you might >>> have a look at Mozilla Skywriter (formerly Bespin): >> >> Why grashtly? > > I don't personally think the web makes a good framework for highly > interactive applications as they must work within the constraints of the > browser and IDEs are highly interactive applications by their very nature. > Perhaps HTML5/CSS3 will change things; but, standard DOM manipulation, > as I am accustomed to seeing it, cannot generate the kind of rendering > that is available from native applications. Attempts to do so end up being > kludgy. > > It also cannot handle the kinds of desktop integrations that are common > for native applications without opening up serious security trust issues. > (Can everybody say ActiveX fiasco?) So, in essence, you are predicting that google's chrome OS will be a failure, right? > Finally, there are difficulties in handling keystrokes without conflicting > with the browser's native key bindings. I seldom ever touch a mouse > and I am a huge fan of vi, mutt, slrn, screen, ratpoison, etc. where > the primary interface is totally accessable through the keyboard without > having to tab through many options. Well, implementing vi or other text based tools in the browser is trivial. I mean it will function in exactly the same way as a native vi. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From catdude at gmail.com Thu Dec 23 09:34:00 2010 From: catdude at gmail.com (Dan M) Date: Thu, 23 Dec 2010 08:34:00 -0600 Subject: Hosting a Python based TCP server References: Message-ID: On Thu, 23 Dec 2010 04:01:03 -0800, Oltmans wrote: > Hi all, > > I'm writing a very small TCP server(written in Python) and now I want to > host it on some ISP so that it can be accessed anywhere from the > Internet. I've never done that before so I thought I should ask for some > advice. Do you guys know any good ISP that can let me do that? > > Most importantly, what is usually involved in order to make this happen? > > Please pardon my ignorance and I will really appreciate your reply. > Thanks in advance. Amazon Web Services is offering micro-instances (essentially a small virtual server) free for one year. Since you would have root access to the instance, you can run anything you want that doesn't violate Amazon's terms of service. Send me an e-mail directly (catdude at gmail dot com) if you have questions about it. Dan From benedict.verheyen at gmail.com Thu Dec 23 09:37:40 2010 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Thu, 23 Dec 2010 15:37:40 +0100 Subject: compiling Python 2.7.1 with readline module fails on Debian (Virtualbox) In-Reply-To: References: <4D1239AD.7010907@pythonmeister.com> <4D131DC1.4060104@pythonmeister.com> Message-ID: On 23/12/2010 14:09, Benedict Verheyen wrote: > > I started from scratch. > I tried to build readline 6 and 5, and installing the packages system wide > as opposed to $HOME/local, but everytime Python fails to find it. > > On stable, apt-get build-dep python 2.6 doesn't work, but > apt-get build-dep python 2.5 does so i did that. > > At configure time, the libreadline library is now found but i have no clue > why it didn't find the readline version i built. > At the end of the Python build, it still ends with this message: > > Failed to build these modules: > readline > > The other modules that where automatically installed via the build-dep > command are built successfully. > I have pasted the config.log here: > http://paste.pocoo.org/show/308859/ > > Thanks, > Benedict > I did a new test, again completely from scratch. I built ncurses and readline, installed them system wide (normal make install without a --prefix). Then i editing Modules/Setup.dist to include readline and adding the correct paths to the include and libs files. configure now finds the readline library. However, ncurses and readline still fail to be built. I had a look at the output of make. This is the error for ncurses: building '_curses' extension gcc -pthread -fPIC -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/home/benedict/local/include -I. -IInclude -I./Include -I/usr/local/include -I/home/benedict/src/Python-2.7.1/Include -I/home/benedict/src/Python-2.7.1 -c /home/benedict/src/Python-2.7.1/Modules/_cursesmodule.c -o build/temp.linux-x86_64-2.7/home/benedict/src/Python-2.7.1/Modules/_cursesmodule.o gcc -pthread -shared build/temp.linux-x86_64-2.7/home/benedict/src/Python-2.7.1/Modules/_cursesmodule.o -L/home/benedict/local/lib -L/usr/local/lib -L. -lncurses -lpython2.7 -o build/lib.linux-x86_64-2.7/_curses.so /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.3.2/../../../../lib/libncurses.a(lib_addch.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC /usr/lib/gcc/x86_64-linux-gnu/4.3.2/../../../../lib/libncurses.a: could not read symbols: Bad value collect2: ld returned 1 exit status building '_curses_panel' extension gcc -pthread -fPIC -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/home/benedict/local/include -I. -IInclude -I./Include -I/usr/local/include -I/home/benedict/src/Python-2.7.1/Include -I/home/benedict/src/Python-2.7.1 -c /home/benedict/src/Python-2.7.1/Modules/_curses_panel.c -o build/temp.linux-x86_64-2.7/home/benedict/src/Python-2.7.1/Modules/_curses_panel.o gcc -pthread -shared build/temp.linux-x86_64-2.7/home/benedict/src/Python-2.7.1/Modules/_curses_panel.o -L/home/benedict/local/lib -L/usr/local/lib -L. -lpanel -lncurses -lpython2.7 -o build/lib.linux-x86_64-2.7/_curses_panel.so /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.3.2/../../../../lib/libpanel.a(p_above.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC /usr/lib/gcc/x86_64-linux-gnu/4.3.2/../../../../lib/libpanel.a: could not read symbols: Bad value collect2: ld returned 1 exit status The error for readline: gcc -pthread -Xlinker -export-dynamic -o python \ Modules/python.o \ -L. -lpython2.7 -lpthread -ldl -lutil -lreadline -L/usr/local/lib -lm /usr/local/lib/libreadline.so: undefined reference to `PC' /usr/local/lib/libreadline.so: undefined reference to `tgetflag' /usr/local/lib/libreadline.so: undefined reference to `tgetent' /usr/local/lib/libreadline.so: undefined reference to `UP' /usr/local/lib/libreadline.so: undefined reference to `tputs' /usr/local/lib/libreadline.so: undefined reference to `tgoto' /usr/local/lib/libreadline.so: undefined reference to `tgetnum' /usr/local/lib/libreadline.so: undefined reference to `BC' /usr/local/lib/libreadline.so: undefined reference to `tgetstr' collect2: ld returned 1 exit status make: *** [python] Fout 1 Thanks, Benedict From joncle at googlemail.com Thu Dec 23 09:38:28 2010 From: joncle at googlemail.com (Jon Clements) Date: Thu, 23 Dec 2010 06:38:28 -0800 (PST) Subject: Hosting a Python based TCP server References: Message-ID: <0aa3012d-8cc0-414c-adad-2d0b028b7642@s18g2000vby.googlegroups.com> On Dec 23, 12:01?pm, Oltmans wrote: > Hi all, > > I'm writing a very small TCP server(written in Python) and now I want > to host it on some ISP so that it can be accessed anywhere from the > Internet. I've never done that before so I thought I should ask for > some advice. Do you guys know any good ISP that can let me do that? > > Most importantly, what is usually involved in order to make this > happen? > > Please pardon my ignorance and I will really appreciate your reply. > Thanks in advance. Check out http://wiki.python.org/moin/PythonHosting There's quite a few and they vary in features/pricing/OS used etc... but a lot of the info and links are there for you to find one right for you. hth Jon. From nospam at domain.invalid Thu Dec 23 10:40:44 2010 From: nospam at domain.invalid (William Gill) Date: Thu, 23 Dec 2010 10:40:44 -0500 Subject: simple games w/o pygame In-Reply-To: References: Message-ID: <4D136D7C.6050504@domain.invalid> Thanks everyone. These references will help greatly. I was about to take some javascript examples and rewrite them in Python. From stefan.sonnenberg at pythonmeister.com Thu Dec 23 11:46:44 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Thu, 23 Dec 2010 17:46:44 +0100 Subject: compiling Python 2.7.1 with readline module fails on Debian (Virtualbox) In-Reply-To: References: <4D1239AD.7010907@pythonmeister.com> <4D131DC1.4060104@pythonmeister.com> Message-ID: <4D137CF4.7000608@pythonmeister.com> Am 23.12.2010 15:37, schrieb Benedict Verheyen: > On 23/12/2010 14:09, Benedict Verheyen wrote: > >> I started from scratch. >> I tried to build readline 6 and 5, and installing the packages system wide >> as opposed to $HOME/local, but everytime Python fails to find it. >> >> On stable, apt-get build-dep python 2.6 doesn't work, but >> apt-get build-dep python 2.5 does so i did that. >> >> At configure time, the libreadline library is now found but i have no clue >> why it didn't find the readline version i built. >> At the end of the Python build, it still ends with this message: >> >> Failed to build these modules: >> readline >> >> The other modules that where automatically installed via the build-dep >> command are built successfully. >> I have pasted the config.log here: >> http://paste.pocoo.org/show/308859/ >> >> Thanks, >> Benedict >> > I did a new test, again completely from scratch. > I built ncurses and readline, installed them system wide (normal make install > without a --prefix). > Then i editing Modules/Setup.dist to include readline and adding the correct paths > to the include and libs files. configure now finds the readline library. > However, ncurses and readline still fail to be built. > > I had a look at the output of make. > This is the error for ncurses: > > building '_curses' extension > gcc -pthread -fPIC -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/home/benedict/local/include -I. > -IInclude -I./Include -I/usr/local/include -I/home/benedict/src/Python-2.7.1/Include -I/home/benedict/src/Python-2.7.1 -c > /home/benedict/src/Python-2.7.1/Modules/_cursesmodule.c -o build/temp.linux-x86_64-2.7/home/benedict/src/Python-2.7.1/Modules/_cursesmodule.o > > gcc -pthread -shared build/temp.linux-x86_64-2.7/home/benedict/src/Python-2.7.1/Modules/_cursesmodule.o -L/home/benedict/local/lib > -L/usr/local/lib -L. -lncurses -lpython2.7 -o build/lib.linux-x86_64-2.7/_curses.so > /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.3.2/../../../../lib/libncurses.a(lib_addch.o): relocation R_X86_64_32 against `a local symbol' > can not be used when making a shared object; recompile with -fPIC > /usr/lib/gcc/x86_64-linux-gnu/4.3.2/../../../../lib/libncurses.a: could not read symbols: Bad value > collect2: ld returned 1 exit status > > building '_curses_panel' extension > gcc -pthread -fPIC -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/home/benedict/local/include -I. > -IInclude -I./Include -I/usr/local/include -I/home/benedict/src/Python-2.7.1/Include -I/home/benedict/src/Python-2.7.1 -c > /home/benedict/src/Python-2.7.1/Modules/_curses_panel.c -o build/temp.linux-x86_64-2.7/home/benedict/src/Python-2.7.1/Modules/_curses_panel.o > > gcc -pthread -shared build/temp.linux-x86_64-2.7/home/benedict/src/Python-2.7.1/Modules/_curses_panel.o -L/home/benedict/local/lib > -L/usr/local/lib -L. -lpanel -lncurses -lpython2.7 -o build/lib.linux-x86_64-2.7/_curses_panel.so > /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.3.2/../../../../lib/libpanel.a(p_above.o): relocation R_X86_64_32 against `a local symbol' can > not be used when making a shared object; recompile with -fPIC > /usr/lib/gcc/x86_64-linux-gnu/4.3.2/../../../../lib/libpanel.a: could not read symbols: Bad value > collect2: ld returned 1 exit status > > The error for readline: > > gcc -pthread -Xlinker -export-dynamic -o python \ > Modules/python.o \ > -L. -lpython2.7 -lpthread -ldl -lutil -lreadline -L/usr/local/lib -lm > /usr/local/lib/libreadline.so: undefined reference to `PC' > /usr/local/lib/libreadline.so: undefined reference to `tgetflag' > /usr/local/lib/libreadline.so: undefined reference to `tgetent' > /usr/local/lib/libreadline.so: undefined reference to `UP' > /usr/local/lib/libreadline.so: undefined reference to `tputs' > /usr/local/lib/libreadline.so: undefined reference to `tgoto' > /usr/local/lib/libreadline.so: undefined reference to `tgetnum' > /usr/local/lib/libreadline.so: undefined reference to `BC' > /usr/local/lib/libreadline.so: undefined reference to `tgetstr' > collect2: ld returned 1 exit status > make: *** [python] Fout 1 > > Thanks, > Benedict > It seems some libs are compiled without PIC (position indepentent code), but python should be. That will not work. I'm currently setting up a VM, to try to follow the steps. Why do you want to build a readline etc when it is in the system ? From moura.mario at gmail.com Thu Dec 23 12:26:47 2010 From: moura.mario at gmail.com (macm) Date: Thu, 23 Dec 2010 09:26:47 -0800 (PST) Subject: Partition Recursive Message-ID: Hi Folks I have this: url = 'http://docs.python.org/dev/library/stdtypes.html? highlight=partition#str.partition' So I want convert to myList = ['http',':','//','docs','.','python','.','org','/','dev','/','library','/','stdtypes','.','html','?','highlight','=','partition','#','str','.','partition'] The reserved char are: specialMeaning = ["//",";","/", "?", ":", "@", "=" , "&","#"] Regards Mario From orasnita at gmail.com Thu Dec 23 12:33:14 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Thu, 23 Dec 2010 19:33:14 +0200 Subject: Python Web App References: <907fa80e-1814-4ddb-be32-ec14cfd53fab@29g2000yqq.googlegroups.com> Message-ID: From: "Daniel Fetchinson" >>>>> Anybody know where I can find a Python Development Environment in the >>>>> form of a web app for use with Chrome OS. I have been looking for a >>>>> few days and all i have been able to find is some old discussions with >>>>> python developers talking about they will want one for the OS to be a >>>>> success with them. >>>> >>>> Personally, I think a web app based IDE would be ghastly; but, you might >>>> have a look at Mozilla Skywriter (formerly Bespin): >>> >>> Why grashtly? >> >> I don't personally think the web makes a good framework for highly >> interactive applications as they must work within the constraints of the >> browser and IDEs are highly interactive applications by their very nature. >> Perhaps HTML5/CSS3 will change things; but, standard DOM manipulation, >> as I am accustomed to seeing it, cannot generate the kind of rendering >> that is available from native applications. Attempts to do so end up being >> kludgy. >> >> It also cannot handle the kinds of desktop integrations that are common >> for native applications without opening up serious security trust issues. >> (Can everybody say ActiveX fiasco?) > > So, in essence, you are predicting that google's chrome OS will be a > failure, right? It will surely be. But it won't, because Google's monopoly in an important field will help it to promote that OS, not because that OS will be so great. >> Finally, there are difficulties in handling keystrokes without conflicting >> with the browser's native key bindings. I seldom ever touch a mouse >> and I am a huge fan of vi, mutt, slrn, screen, ratpoison, etc. where >> the primary interface is totally accessable through the keyboard without >> having to tab through many options. > > Well, implementing vi or other text based tools in the browser is > trivial. I mean it will function in exactly the same way as a native > vi. Not exactly. Because not all the computer users can see, and the browsers don't offer the same accessibility features for screen readers as the standard GUIS. (And Google's software is very poor in this field anyway.) Octavian From python at mrabarnett.plus.com Thu Dec 23 12:49:00 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 23 Dec 2010 17:49:00 +0000 Subject: Partition Recursive In-Reply-To: References: Message-ID: <4D138B8C.5040908@mrabarnett.plus.com> On 23/12/2010 17:26, macm wrote: > Hi Folks > > I have this: > > url = 'http://docs.python.org/dev/library/stdtypes.html? > highlight=partition#str.partition' > > So I want convert to > > myList = > ['http',':','//','docs','.','python','.','org','/','dev','/','library','/','stdtypes','.','html','?','highlight','=','partition','#','str','.','partition'] > > The reserved char are: > > specialMeaning = ["//",";","/", "?", ":", "@", "=" , "&","#"] > I would use re.findall. From joncle at googlemail.com Thu Dec 23 12:57:54 2010 From: joncle at googlemail.com (Jon Clements) Date: Thu, 23 Dec 2010 09:57:54 -0800 (PST) Subject: Partition Recursive References: Message-ID: On Dec 23, 5:26?pm, macm wrote: > Hi Folks > > I have this: > > url = 'http://docs.python.org/dev/library/stdtypes.html? > highlight=partition#str.partition' > > So I want convert to > > myList = > ['http',':','//','docs','.','python','.','org','/','dev','/','library','/','stdtypes','.','html','?','highlight','=','partition','#','str','.','partition'] > > The reserved char are: > > specialMeaning = ["//",";","/", "?", ":", "@", "=" , "&","#"] > > Regards > > Mario I would use urlparse.urlsplit, then split further, if required. >>> urlsplit(url) SplitResult(scheme='http', netloc='docs.python.org', path='/dev/ library/stdtypes.html', query='highlight=partition', fragment='str.partition') Jon. From moura.mario at gmail.com Thu Dec 23 13:05:39 2010 From: moura.mario at gmail.com (macm) Date: Thu, 23 Dec 2010 10:05:39 -0800 (PST) Subject: Partition Recursive References: Message-ID: Hi urlparse isnt a option. My reasult must be: myList = ['http',':','//','docs','.','python','.','org','/','dev','/','library','/', 'stdtypes','.','html','?','highlight','=','partition','#','str','.','partition'] re module is slow. Even I make a loop in urlparse.urlsplit I can lost specialMeaning order. Seen easy but best aproach will be recursive. Regards Mario On Dec 23, 3:57?pm, Jon Clements wrote: > On Dec 23, 5:26?pm, macm wrote: > > > > > > > > > > > Hi Folks > > > I have this: > > > url = 'http://docs.python.org/dev/library/stdtypes.html? > > highlight=partition#str.partition' > > > So I want convert to > > > myList = > > ['http',':','//','docs','.','python','.','org','/','dev','/','library','/', 'stdtypes','.','html','?','highlight','=','partition','#','str','.','partit ion'] > > > The reserved char are: > > > specialMeaning = ["//",";","/", "?", ":", "@", "=" , "&","#"] > > > Regards > > > Mario > > I would use urlparse.urlsplit, then split further, if required. > > >>> urlsplit(url) > > SplitResult(scheme='http', netloc='docs.python.org', path='/dev/ > library/stdtypes.html', query='highlight=partition', > fragment='str.partition') > > Jon. From armin.hoebart at aon.at Thu Dec 23 13:43:09 2010 From: armin.hoebart at aon.at (Tintifax) Date: Thu, 23 Dec 2010 10:43:09 -0800 (PST) Subject: installing scikits.timeseries Message-ID: <30524255.post@talk.nabble.com> I tried to install scikits.timeseries via "easy_install" and received following Error Message: Found executable C:\MinGW32\bin\gcc.exe Found executable C:\MinGW32\bin\g++.exe zip_safe flag not set; analyzing archive contents... scikits.timeseries.version: module references __file__ Adding scikits.timeseries 0.91.3 to easy-install.pth file Installed c:\python26\lib\site-packages\scikits.timeseries-0.91.3-py2.6-win32.eg g Processing dependencies for scikits.timeseries Finished processing dependencies for scikits.timeseries C:\Python26\lib\site-packages\numpy\distutils\misc_util.py:251: RuntimeWarning: Parent module 'numpy.distutils' not found while handling absolute import from numpy.distutils import log Does anybody have an idea how I can install scikits.timeseries without getting this error message? I really appreciate every little hint. Thank You!! -- View this message in context: http://old.nabble.com/installing-scikits.timeseries-tp30524255p30524255.html Sent from the Python - python-list mailing list archive at Nabble.com. From hniksic at xemacs.org Thu Dec 23 13:57:13 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Thu, 23 Dec 2010 19:57:13 +0100 Subject: round in 2.6 and 2.7 Message-ID: <87sjxoco6u.fsf@xemacs.org> I stumbled upon this. Python 2.6: Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> 9.95 9.9499999999999993 >>> "%.16g" % 9.95 '9.949999999999999' >>> round(9.95, 1) 10.0 So it seems that Python is going out of its way to intuitively round 9.95, while the repr retains the unnecessary digits. However, with 2.7 it's exactly the opposite: Python 2.7.0+ (r27:82500, Sep 15 2010, 18:04:55) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> 9.95 9.95 >>> "%.16g" % 9.95 '9.949999999999999' >>> round(9.95, 1) 9.9 Is the change to round() expected? From usernet at ilthio.net Thu Dec 23 14:18:24 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 23 Dec 2010 19:18:24 +0000 (UTC) Subject: Python Web App References: <907fa80e-1814-4ddb-be32-ec14cfd53fab@29g2000yqq.googlegroups.com> Message-ID: On 2010-12-23, Daniel Fetchinson wrote: >> I don't personally think the web makes a good framework for highly >> interactive applications as they must work within the constraints of the >> browser and IDEs are highly interactive applications by their very nature. >> Perhaps HTML5/CSS3 will change things; but, standard DOM manipulation, >> as I am accustomed to seeing it, cannot generate the kind of rendering >> that is available from native applications. Attempts to do so end up being >> kludgy. >> >> It also cannot handle the kinds of desktop integrations that are common >> for native applications without opening up serious security trust issues. >> (Can everybody say ActiveX fiasco?) > > So, in essence, you are predicting that google's chrome OS will be a > failure, right? No, most people are happy using web based email interfaces and never even know that native email clients exist. More is the pity. >> Finally, there are difficulties in handling keystrokes without conflicting >> with the browser's native key bindings. I seldom ever touch a mouse >> and I am a huge fan of vi, mutt, slrn, screen, ratpoison, etc. where >> the primary interface is totally accessable through the keyboard without >> having to tab through many options. > > Well, implementing vi or other text based tools in the browser is > trivial. I mean it will function in exactly the same way as a native > vi. Not exactly. I occassionally use web based terminals (Ajaxterm, Anyterm, Shellinabox, etc) to access my systems. This works only partially since many of the keystrokes I use conflict with keystrokes that the browser uses or which cause signals that the browser either does not catch or does not pass on to be accessed by client side scripting. The terminals must therefore place buttons or synthetic keyboards on the screen to allow you to simulate the keystrokes. That kind of negates the advantages of keystrokes in the first place. It doesn't make fore a pleasant experience. From moura.mario at gmail.com Thu Dec 23 14:31:37 2010 From: moura.mario at gmail.com (macm) Date: Thu, 23 Dec 2010 11:31:37 -0800 (PST) Subject: round in 2.6 and 2.7 References: <87sjxoco6u.fsf@xemacs.org> Message-ID: <1319405f-1f4b-4193-ab8e-8595b279b71f@g25g2000yqn.googlegroups.com> On Dec 23, 4:57?pm, Hrvoje Niksic wrote: > I stumbled upon this. ?Python 2.6: > > Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) > [GCC 4.4.5] on linux2 > Type "help", "copyright", "credits" or "license" for more information.>>> 9.95 > 9.9499999999999993 > >>> "%.16g" % 9.95 > '9.949999999999999' > >>> round(9.95, 1) > > 10.0 > > So it seems that Python is going out of its way to intuitively round > 9.95, while the repr retains the unnecessary digits. ?However, with 2.7 > it's exactly the opposite: > > Python 2.7.0+ (r27:82500, Sep 15 2010, 18:04:55) > [GCC 4.4.5] on linux2 > Type "help", "copyright", "credits" or "license" for more information.>>> 9.95 > 9.95 > >>> "%.16g" % 9.95 > '9.949999999999999' > >>> round(9.95, 1) > > 9.9 > > Is the change to round() expected? My guess is use decimal module. Regards mario From please_post at nomail.edu Thu Dec 23 14:40:04 2010 From: please_post at nomail.edu (bill) Date: Thu, 23 Dec 2010 19:40:04 +0000 (UTC) Subject: general problem when subclassing a built-in class References: Message-ID: In kj writes: >Where in the Python documentation can one find the information >required to determine the minimal[1] set of methods that one would >need to override to achieve this goal? > I don't know the answer to that question, but imho it's the wrong question to ask. Instead you should be asking what design will let me implement the subclass making the fewest possible assumptions about the superclass. (hint: the design you're thinking about leads to a world of pain.) > >2. other than the added capability described in (1), an instance >of TSDict should behave *exactly* like a built-in dictionary. (minor point: what about repr? it shouldn't look like a dict, imho) > >#--------------------------------------------------------------------------- >from time import time >class TSDict(dict): > def __setitem__(self, key, value): > # save the value and timestamp for key as a tuple; > # see footnote [2] > dict.__setitem__(self, key, (value, time())) > def __getitem__(self, key): > # extract the value from the value-timestamp pair and return it > return dict.__getitem__(self, key)[0] > def get_timestamp(self, key): > # extract the timestamp from the value-timestamp pair and return it > return dict.__getitem__(self, key)[1] >#--------------------------------------------------------------------------- man, you're asking for trouble! even if you knew all you want to know, unless you had some guarantee that it wouldn't change in a later release, you'd still have to override pretty much all the methods. the problem here is not lack of information, but a horrible design (sorry to be blunt). Just keep the timestamps in a parallel dict and get on with life: from time import time from collections import MutableMapping class TSDict2(dict, MutableMapping): def __init__(self, *args, **kwargs): dict.__init__(self, *args, **kwargs) self.__ts = dict.fromkeys(self.keys(), time()) def __setitem__(self, key, value): self.__ts[key] = time() dict.__setitem__(self, key, value) setdefault = MutableMapping.setdefault update = MutableMapping.update def get_timestamp(self, key): if self.has_key(key): return self.__ts[key] raise KeyError(key) that just took the time needed to type it and worked the first time: >>> d = TSDict2((('uno', 1), ('dos', 2)), tres=3, cuatro=4); d['cinco'] = 5; d.setdefault('six', 6); 6 >>> d.update((('tres', 'amigos'), ('seven', 7),), eight=8); d {'seven': 7, 'six': 6, 'cuatro': 4, 'cinco': 5, 'eight': 8, 'dos': 2, 'tres': 'amigos', 'uno': 1} >>> for p in sorted([(k, d.get_timestamp(k)) for k in d.keys()], key=lambda p: p[1]): print "%s\t%f" % p ... cuatro 1293131496.917215 dos 1293131496.917215 uno 1293131496.917215 cinco 1293131496.917233 six 1293131496.917279 tres 1293131501.676962 seven 1293131501.676974 eight 1293131501.676981 If you insist on bashing your skull against your original problem, take a look at collections.OrderedDict or collections.Counter to see how they use ABCs to tame dict. (still, even if you used all the remaining available MutableMapping methods in your class, i don't know how you'd get the dict constructor to return the right value, ie no timestamps, when you pass it an instance of your subclass as argument. i don't think there's a TSDict.__method__ you can write for that... anyway my TSDict2 doesn't have this problem either.) take home message: respect the privacy of your superclasses and they'll be nice to you. --bill From martin at v.loewis.de Thu Dec 23 14:50:50 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Thu, 23 Dec 2010 20:50:50 +0100 Subject: round in 2.6 and 2.7 In-Reply-To: <87sjxoco6u.fsf@xemacs.org> References: <87sjxoco6u.fsf@xemacs.org> Message-ID: <4D13A81A.5030903@v.loewis.de> > Type "help", "copyright", "credits" or "license" for more information. >>>> 9.95 > 9.9499999999999993 >>>> "%.16g" % 9.95 > '9.949999999999999' >>>> round(9.95, 1) > 10.0 > > So it seems that Python is going out of its way to intuitively round > 9.95, while the repr retains the unnecessary digits. The 2.6 result is simply incorrect. 9.95 cannot be represented as a floating point number; the number that is closest to it is actually smaller than 9.95. Rounding that number should give 9.9 (or something close to it - 9.9 cannot be represented, either), not 10.0. >>>> round(9.95, 1) > 9.9 > > Is the change to round() expected? Yes. It's a bug fix described in "What's new in Python 2.7" thus: Float-to-string and string-to-float conversions are correctly rounded. The round() function is also now correctly rounded. Not sure that this is correct English; I think it means that the round() function is now correct. Regards, Martin From stefan.sonnenberg at pythonmeister.com Thu Dec 23 14:55:15 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Thu, 23 Dec 2010 20:55:15 +0100 Subject: compiling Python 2.7.1 with readline module fails on Debian (Virtualbox) In-Reply-To: References: <4D1239AD.7010907@pythonmeister.com> <4D131DC1.4060104@pythonmeister.com> Message-ID: <4D13A923.8060208@pythonmeister.com> Am 23.12.2010 15:37, schrieb Benedict Verheyen: > On 23/12/2010 14:09, Benedict Verheyen wrote: > >> I started from scratch. >> I tried to build readline 6 and 5, and installing the packages system wide >> as opposed to $HOME/local, but everytime Python fails to find it. >> >> On stable, apt-get build-dep python 2.6 doesn't work, but >> apt-get build-dep python 2.5 does so i did that. >> >> At configure time, the libreadline library is now found but i have no clue >> why it didn't find the readline version i built. >> At the end of the Python build, it still ends with this message: >> >> Failed to build these modules: >> readline >> >> The other modules that where automatically installed via the build-dep >> command are built successfully. >> I have pasted the config.log here: >> http://paste.pocoo.org/show/308859/ >> >> Thanks, >> Benedict >> > I did a new test, again completely from scratch. > I built ncurses and readline, installed them system wide (normal make install > without a --prefix). > Then i editing Modules/Setup.dist to include readline and adding the correct paths > to the include and libs files. configure now finds the readline library. > However, ncurses and readline still fail to be built. > > I had a look at the output of make. > This is the error for ncurses: > > building '_curses' extension > gcc -pthread -fPIC -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/home/benedict/local/include -I. > -IInclude -I./Include -I/usr/local/include -I/home/benedict/src/Python-2.7.1/Include -I/home/benedict/src/Python-2.7.1 -c > /home/benedict/src/Python-2.7.1/Modules/_cursesmodule.c -o build/temp.linux-x86_64-2.7/home/benedict/src/Python-2.7.1/Modules/_cursesmodule.o > > gcc -pthread -shared build/temp.linux-x86_64-2.7/home/benedict/src/Python-2.7.1/Modules/_cursesmodule.o -L/home/benedict/local/lib > -L/usr/local/lib -L. -lncurses -lpython2.7 -o build/lib.linux-x86_64-2.7/_curses.so > /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.3.2/../../../../lib/libncurses.a(lib_addch.o): relocation R_X86_64_32 against `a local symbol' > can not be used when making a shared object; recompile with -fPIC > /usr/lib/gcc/x86_64-linux-gnu/4.3.2/../../../../lib/libncurses.a: could not read symbols: Bad value > collect2: ld returned 1 exit status > > building '_curses_panel' extension > gcc -pthread -fPIC -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/home/benedict/local/include -I. > -IInclude -I./Include -I/usr/local/include -I/home/benedict/src/Python-2.7.1/Include -I/home/benedict/src/Python-2.7.1 -c > /home/benedict/src/Python-2.7.1/Modules/_curses_panel.c -o build/temp.linux-x86_64-2.7/home/benedict/src/Python-2.7.1/Modules/_curses_panel.o > > gcc -pthread -shared build/temp.linux-x86_64-2.7/home/benedict/src/Python-2.7.1/Modules/_curses_panel.o -L/home/benedict/local/lib > -L/usr/local/lib -L. -lpanel -lncurses -lpython2.7 -o build/lib.linux-x86_64-2.7/_curses_panel.so > /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.3.2/../../../../lib/libpanel.a(p_above.o): relocation R_X86_64_32 against `a local symbol' can > not be used when making a shared object; recompile with -fPIC > /usr/lib/gcc/x86_64-linux-gnu/4.3.2/../../../../lib/libpanel.a: could not read symbols: Bad value > collect2: ld returned 1 exit status > > The error for readline: > > gcc -pthread -Xlinker -export-dynamic -o python \ > Modules/python.o \ > -L. -lpython2.7 -lpthread -ldl -lutil -lreadline -L/usr/local/lib -lm > /usr/local/lib/libreadline.so: undefined reference to `PC' > /usr/local/lib/libreadline.so: undefined reference to `tgetflag' > /usr/local/lib/libreadline.so: undefined reference to `tgetent' > /usr/local/lib/libreadline.so: undefined reference to `UP' > /usr/local/lib/libreadline.so: undefined reference to `tputs' > /usr/local/lib/libreadline.so: undefined reference to `tgoto' > /usr/local/lib/libreadline.so: undefined reference to `tgetnum' > /usr/local/lib/libreadline.so: undefined reference to `BC' > /usr/local/lib/libreadline.so: undefined reference to `tgetstr' > collect2: ld returned 1 exit status > make: *** [python] Fout 1 > > Thanks, > Benedict > OK, I compiled it successfully under Debian 5.07 i386. ncurses and libreadline are compiled from hand, both --prefix=$HOME/usr/local. For python the only extra needed was export LD_LIBRARY_PATH=$HOME/usr/local/lib:$LD_LIBRARY_PATH From dasacc22 at gmail.com Thu Dec 23 15:05:38 2010 From: dasacc22 at gmail.com (dasacc22) Date: Thu, 23 Dec 2010 12:05:38 -0800 (PST) Subject: daml 0.1.4 released, a python markup language for the web Message-ID: <275c92ac-ad6a-432a-bf8f-c12c9f33fee5@k25g2000vbl.googlegroups.com> Notes on the latest updates can be read here: http://dasacc22.wordpress.com/2010/12/22/daml-0-1-4-release/ The source is on github: https://github.com/dasacc22/daml An sdist is available on pypi: http://pypi.python.org/pypi/DAML/0.1.4 daml is for outlining html with dynamic content. Features inline python and a sandbox you can update with custom functions (so they are in memory, versus writing the function in the template). As part of a bigger project, daml is playing a part in completely removing the "view" from controller code and will feature an extension for requesting data via IPC from your controllers (or anywhere else for that matter if you want to wait), so no more tacking on related or semi-related views to a particular controller. daml currently depends on cython. There are a few utility functions that are written in cython and it also depends on lxml (written in cython) and makes use of that during the final document build which is done in cython as well. Down the road, after I get all of the specifics worked out for the syntax, cython and lxml will be optional (and necessary if you want it to be as fast as possible), but theres absolutely no reason for there to not be a pure python module. It's really not that complex. daml may also be recognized as a haml implementation. The only things adapted is the use of #id and .class tag hashes and being indention based (if that counts), and particularly the source of inspiration for filters. Beyond that, they are two pretty different things. Also, daml isn't much of a name for anything. Under consideration currently is damsel, da Markup 4 Savvy & Eloquent Ladies (and gentlemen). Just think repunzel in a tower with OSI climbing her hair to save the View[1] from the MVC-implementation-of-hell Tower. [1] She must be a looker From nobody at nowhere.com Thu Dec 23 15:27:59 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 23 Dec 2010 20:27:59 +0000 Subject: Trying to parse a HUGE(1gb) xml file References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> Message-ID: On Wed, 22 Dec 2010 23:54:34 +0100, Stefan Sonnenberg-Carstens wrote: > Normally (what is normal, anyway?) such files are auto-generated, > and are something that has a apparent similarity with a database query > result, encapsuled in xml. > Most of the time the structure is same for every "row" thats in there. > So, a very unpythonic but fast, way would be to let awk resemble the > records and write them in csv format to stdout. awk works well if the input is formatted such that each line is a record; it's not so good otherwise. XML isn't a line-oriented format; in particular, there are many places where both newlines and spaces are just whitespace. A number of XML generators will "word wrap" the resulting XML to make it more human readable, so line-oriented tools aren't a good idea. From nobody at nowhere.com Thu Dec 23 15:32:38 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 23 Dec 2010 20:32:38 +0000 Subject: Generator question References: <1jtwvox.1pxdxm314l5m06N%see@sig.for.address> Message-ID: On Wed, 22 Dec 2010 15:49:31 -0800, Dan Stromberg wrote: > def generator(): > i = 0 > while True: > yield i > i += 1 Shorter version: from itertools import count as generator From stefan.sonnenberg at pythonmeister.com Thu Dec 23 16:02:40 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Thu, 23 Dec 2010 22:02:40 +0100 Subject: round in 2.6 and 2.7 In-Reply-To: <87sjxoco6u.fsf@xemacs.org> References: <87sjxoco6u.fsf@xemacs.org> Message-ID: <4D13B8F0.7080605@pythonmeister.com> Am 23.12.2010 19:57, schrieb Hrvoje Niksic: > I stumbled upon this. Python 2.6: > > Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) > [GCC 4.4.5] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> 9.95 > 9.9499999999999993 >>>> "%.16g" % 9.95 > '9.949999999999999' >>>> round(9.95, 1) > 10.0 > > So it seems that Python is going out of its way to intuitively round > 9.95, while the repr retains the unnecessary digits. However, with 2.7 > it's exactly the opposite: > > Python 2.7.0+ (r27:82500, Sep 15 2010, 18:04:55) > [GCC 4.4.5] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> 9.95 > 9.95 >>>> "%.16g" % 9.95 > '9.949999999999999' >>>> round(9.95, 1) > 9.9 > > Is the change to round() expected? Indeed: http://svn.python.org/view?view=rev&revision=76373 From stefan.sonnenberg at pythonmeister.com Thu Dec 23 16:34:06 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Thu, 23 Dec 2010 22:34:06 +0100 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> Message-ID: <4D13C04E.6070103@pythonmeister.com> Am 23.12.2010 21:27, schrieb Nobody: > On Wed, 22 Dec 2010 23:54:34 +0100, Stefan Sonnenberg-Carstens wrote: > >> Normally (what is normal, anyway?) such files are auto-generated, >> and are something that has a apparent similarity with a database query >> result, encapsuled in xml. >> Most of the time the structure is same for every "row" thats in there. >> So, a very unpythonic but fast, way would be to let awk resemble the >> records and write them in csv format to stdout. > awk works well if the input is formatted such that each line is a record; You shouldn't tell it to awk. > it's not so good otherwise. XML isn't a line-oriented format; in > particular, there are many places where both newlines and spaces are just > whitespace. A number of XML generators will "word wrap" the resulting XML > to make it more human readable, so line-oriented tools aren't a good idea. I never had the opportunity seeing awk fail on this task :-) For large datasets I always have huge question marks if one says "xml". But I don't want to start a flame war. From mafunk at nmsu.edu Thu Dec 23 16:41:15 2010 From: mafunk at nmsu.edu (Matt Funk) Date: Thu, 23 Dec 2010 14:41:15 -0700 Subject: using python ftp In-Reply-To: References: <4D1291CB.5010404@nmsu.edu> Message-ID: <4D13C1FB.6030808@nmsu.edu> Hi, thanks for the response. I kind of was thinking along those lines. The thing is though is that 'grop' appears to work on the local directory only (and not on the remote one which i need) Anyway, i think i'll just do via iterating through a the remote directory listing and then match it via regular pattern. Not sure if this is the best/most elegant way. But it should work. thanks matt On 12/23/2010 1:46 AM, Octavian Rasnita wrote: > Can this lib also work with ftps? > > Thanks. > > Octavian > > ----- Original Message ----- > From: "Anurag Chourasia" > To: "Matt Funk" > Cc: > Sent: Thursday, December 23, 2010 4:12 AM > Subject: Re: using python ftp > > >> Hi Matt, >> >> I have a snippet to "upload" files (that match a particular search >> pattern) to a remote server. >> >> Variable names are self explanatory. You could tweak this a little to >> "download" files instead. >> >> from ftplib import FTP >> ftp = FTP(hostname) >> ftp.login(user_id,passwd) >> ftp.cwd(remote_directory) >> files_list=glob.glob(file_search_pattern) >> for file in files_list: >> try: >> ftp.storlines('STOR ' + file, open(file)) >> except Exception, e: >> print ('Failed to FTP file: %s' %(file)) >> ftp.close() >> >> Regards, >> Anurag >> >> On Thu, Dec 23, 2010 at 5:33 AM, Matt Funk wrote: >>> Hi, >>> >>> i was wondering whether someone can point me whether the following >>> already exists. >>> >>> I want to connect to a server , download various files (for whose name i >>> want to be able to use a wildcard), and store those files in a given >>> location on the hard drive. If the file already exists i do not want to >>> download it. >>> >>> This seems fairly trivial and i would assume that there should be some >>> sort of implementation that does this easily but i didn't find anything >>> googling it. >>> >>> Otherwise i was going to do it "by hand" using ftplib: >>> 1) connect to server, >>> 2) change to directory on server >>> 3) get listing >>> 4) match the file pattern i want to the listing >>> 5) check if file already exists >>> 6) download file if matched and doesn't exist >>> >>> Can anyone offer any advice whether this already done somewhere? >>> >>> thanks >>> matt >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >>> >> -- >> http://mail.python.org/mailman/listinfo/python-list From smallpox911 at gmail.com Thu Dec 23 17:01:20 2010 From: smallpox911 at gmail.com (small Pox) Date: Thu, 23 Dec 2010 14:01:20 -0800 (PST) Subject: What is the the best style and theory of writing a complier in your language Message-ID: What is the the best style and theory of writing a complier in your language Maybe a book will suffice. http://www.veteranstoday.com/2010/12/18/gordon-duff-gov-jesse-ventura-proves-911-cover-up-will-americas-government-fall/ I want to parse the contents of the above link into hebrew audio. CHEERIOS From franapoli at gmail.com Thu Dec 23 18:07:16 2010 From: franapoli at gmail.com (Ciccio) Date: Thu, 23 Dec 2010 15:07:16 -0800 (PST) Subject: Regular expression for "key = value" pairs References: <87tyi5wxyg.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <148d96c0-1b44-4a0f-993d-a07015b5b4a1@v17g2000vbo.googlegroups.com> I extracted an isolated problem from a slightly more complex situation, that's why I'm using REs. Thank you all for your help, my problem is now solved. From mpnordland at gmail.com Thu Dec 23 18:07:38 2010 From: mpnordland at gmail.com (mpnordland) Date: Thu, 23 Dec 2010 18:07:38 -0500 Subject: Catching user switching and getting current active user from root on linux In-Reply-To: <51d9390d-be72-49fe-a63b-5a05832c53e8@fu15g2000vbb.googlegroups.com> References: <1a9bdbd4-2997-4e0f-a24f-cd148247e312@r40g2000prh.googlegroups.com> <8739qhs6dz.fsf.mdw@metalzone.distorted.org.uk> <797ba948-c608-4ed5-b2eb-25177932da91@o4g2000yqd.googlegroups.com> <4d04117b$0$30000$c3e8da3$5496439d@news.astraweb.com> <51d9390d-be72-49fe-a63b-5a05832c53e8@fu15g2000vbb.googlegroups.com> Message-ID: Ok, thank you. I will go look at the resources mentioned. From jlundell at pobox.com Thu Dec 23 18:21:42 2010 From: jlundell at pobox.com (JLundell) Date: Thu, 23 Dec 2010 15:21:42 -0800 (PST) Subject: class inheritance In-Reply-To: Message-ID: That's nice, Ethan, especially in that it saves having to explicitly find and list all the methods being covered. It's perhaps not quite so critical for a Fraction-based class, since the set of methods to be covered is fairly well contained, but that's not always going to be the case. The approach I mentioned earlier (rebinding __class__) is a little faster, since it avoids a call to __new__, but the difference is no doubt negligible in this example, since rational arithmetic isn't exactly lightning fast. Thanks. From jlundell at pobox.com Thu Dec 23 18:21:42 2010 From: jlundell at pobox.com (JLundell) Date: Thu, 23 Dec 2010 15:21:42 -0800 (PST) Subject: class inheritance In-Reply-To: Message-ID: That's nice, Ethan, especially in that it saves having to explicitly find and list all the methods being covered. It's perhaps not quite so critical for a Fraction-based class, since the set of methods to be covered is fairly well contained, but that's not always going to be the case. The approach I mentioned earlier (rebinding __class__) is a little faster, since it avoids a call to __new__, but the difference is no doubt negligible in this example, since rational arithmetic isn't exactly lightning fast. Thanks. From rhodri at wildebst.demon.co.uk Thu Dec 23 18:34:46 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 23 Dec 2010 23:34:46 -0000 Subject: Partition Recursive References: Message-ID: Please don't top-post, it makes everything harder to read. (Re-ordering to make sense...) On Thu, 23 Dec 2010 18:05:39 -0000, macm wrote: > On Dec 23, 3:57 pm, Jon Clements wrote: >> I would use urlparse.urlsplit, then split further, if required. >> >> >>> urlsplit(url) >> >> SplitResult(scheme='http', netloc='docs.python.org', path='/dev/ >> library/stdtypes.html', query='highlight=partition', >> fragment='str.partition') > urlparse isnt a option. Why not? > My reasult must be: > > myList = > ['http',':','//','docs','.','python','.','org','/','dev','/','library','/', > 'stdtypes','.','html','?','highlight','=','partition','#','str','.','partition'] Deriving this from the output of urlparse isn't that hard. I'm slightly baffled as to why this is more useful, but that's your problem. > re module is slow. Is it slow enough to be an issue? > Even I make a loop in urlparse.urlsplit I can lost specialMeaning > order. If you mean what I think you mean, and you're relying on getting queries from browsers in a defined order, you are in for a world of pain. > Seen easy but best aproach will be recursive. If speed is as important to you as you imply, I doubt it. -- Rhodri James *-* Wildebeest Herder to the Masses From smallpox911 at gmail.com Thu Dec 23 18:46:55 2010 From: smallpox911 at gmail.com (small Pox) Date: Thu, 23 Dec 2010 15:46:55 -0800 (PST) Subject: David Epstein Incest Charges: Columbia Professor Charged With Sleeping With Daughter References: Message-ID: <57136320-3fac-4796-8f22-233ab670e924@30g2000yql.googlegroups.com> On Dec 23, 2:01?pm, small Pox wrote: > What is the the best style and theory of writing a complier in your > language > > Maybe a book will suffice. > > http://www.veteranstoday.com/2010/12/18/gordon-duff-gov-jesse-ventura... > > I want to parse the contents of the above link into hebrew audio. > > CHEERIOS I expect this from the zionists of both stripes Shalom Israel David Epstein Incest Charges: Columbia Professor Charged With Sleeping With Daughter A Columbia political science professor has been charged with having a sexual relationship with his 24-year-old daughter, the Columbia Daily Spectator reports. David Epstein, 46, was charged Thursday with one count of third-degree incest. Police told the Spectator that the relationship appeared consensual. Epstein is currently on administrative leave. According to the New York Daily News, Epstein and the woman had a three-year sexual relationship and often exchanged "twisted text messages." The Spectator reports that Epstein is married to another Columbia political science professor, Sharyn O'Halloran, though a recent update to his Facebook page says he is single. The couple was featured in a 2008 Spectator article about professors who "bring love to work." "Our complementary skills lead to a great partnership," O'Halloran told the Spectator. One student described Epstein, who was teaching a class on game theory this semester, as a "very nice guy." Outside of his professorial duties, Epstein also blogged for this website, on topics ranging from torture to Sarah Palin. From benedict.verheyen at gmail.com Thu Dec 23 20:16:52 2010 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Fri, 24 Dec 2010 02:16:52 +0100 Subject: compiling Python 2.7.1 with readline module fails on Debian (Virtualbox) In-Reply-To: <4D13A923.8060208@pythonmeister.com> References: <4D1239AD.7010907@pythonmeister.com> <4D131DC1.4060104@pythonmeister.com> <4D13A923.8060208@pythonmeister.com> Message-ID: On 23/12/2010 20:55, Stefan Sonnenberg-Carstens wrote: >> >> > OK, I compiled it successfully under Debian 5.07 i386. > ncurses and libreadline are compiled from hand, both --prefix=$HOME/usr/local. > For python the only extra needed was export LD_LIBRARY_PATH=$HOME/usr/local/lib:$LD_LIBRARY_PATH > Hi Stefan, thanks for your continued help, I appreciate it very much! The reason why i want my own readline library is that i want to have full control over what version gets used without messing with the system wide libraries. A difference between your system and mine is that i'm using amd64 instead of i386. Anyway, i retried at home, completely clean system. Built ncurses and readline with: ./configure --enable-shared --prefix=$HOME/usr/local make make install Then for Python ./configure --enable-shared --prefix=$HOME/usr/local And now i doesn't find the readline library. I'm really lost now why it sometimes finds it and sometimes it doesn't. Only difference with earlier is that I now used --prefix=$HOME/usr/local So it's not installed system-wide. Could that be the reason why it's not found? Since you've managed to successfully build Python with readline support, could you post the exact steps from building readline to building Python? I even edited /etc/ldconfig.conf.d/libc.conf to include $HOME/usr/local/lib. Then issued sudo ldconfig -v but no go. Editing the Python Modules/Setup to uncomment the readline line doesn't help either so that obviously doesn't work. Should it? As said earlier, I added -L$HOME/usr/local/lib -I$HOME/usr/local/include to the end of the line. Thanks a lot, Benedict From givenrandy at gmail.com Thu Dec 23 21:58:15 2010 From: givenrandy at gmail.com (Randy Given) Date: Thu, 23 Dec 2010 21:58:15 -0500 Subject: GUI Tools for Python 3.1 Message-ID: Lots of stuff for 2.6 and 2.7 -- what GUI tools are there for 3.1? Randy -------------- next part -------------- An HTML attachment was scrubbed... URL: From benedict.verheyen at gmail.com Thu Dec 23 22:01:17 2010 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Fri, 24 Dec 2010 04:01:17 +0100 Subject: compiling Python 2.7.1 with readline module fails on Debian (Virtualbox) In-Reply-To: References: <4D1239AD.7010907@pythonmeister.com> <4D131DC1.4060104@pythonmeister.com> <4D13A923.8060208@pythonmeister.com> Message-ID: On 24/12/2010 2:16, Benedict Verheyen wrote: > On 23/12/2010 20:55, Stefan Sonnenberg-Carstens wrote: >>> I finally succeeded. I built ncurses and installed it to $HOME/usr/local ./configure --with-shared --enable-termcap --prefix=$HOME/usr/local make make install Then i built readline ./configure --enable-shared --prefix=$HOME/usr/local make make install I edited /etc/ld.so.conf.d/libc.conf and added $HOME/usr/local Next: ldconfig -v Next Python, configure doesn't find readline even if LD_LIBRARY_PATH is set. I tried export LDFLAGS="-L$HOME/usr/local" Then Python builds both readline and ncurses and works ok. Finally :) I'm not sure if the ldconfig is necessary. Regards, Benedict From no.email at please.post Thu Dec 23 22:36:28 2010 From: no.email at please.post (kj) Date: Fri, 24 Dec 2010 03:36:28 +0000 (UTC) Subject: How to order base classes? Message-ID: Suppose that I want to write a subclass C of base classes A and B. What considerations should go into choosing the ordering of A and B in C's base class list? Since any order one chooses can be overridden on a per-method basis, by assigning the desired parent's method to the appropriate class attribute, like this: class C(B, A) # override methods spam, ham, and eggs from B spam = A.spam; ham = A.ham; eggs = A.eggs; ... ...it is difficult for me to see a strong compelling reason for picking an ordering over another. But may be just ignorance on my part. How should one go about deciding the ordering of base classes? TIA! ~kj From steve+comp.lang.python at pearwood.info Thu Dec 23 23:25:01 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 24 Dec 2010 04:25:01 GMT Subject: How to order base classes? References: Message-ID: <4d14209d$0$30000$c3e8da3$5496439d@news.astraweb.com> On Fri, 24 Dec 2010 03:36:28 +0000, kj wrote: > How should one go about deciding the ordering of base classes? There is no general way for doing so. You need to consider the actual functionality of the methods involved. Consider a method spam() of class C that inherits from both A and B. To be completely general, you might have any of the following situations: C.spam() overloads A.spam() followed by B.spam() C.spam() overloads B.spam() followed by A.spam() C.spam() overloads A.spam() and overrides B.spam() C.spam() overloads B.spam() and overrides A.spam() C.spam() overrides both A.spam() and B.spam() (where I use "overload" to mean "modify the behaviour of", and "override" to mean "change the behaviour completely" -- basically, overloading will call the superclass' method, while overriding will not.) And (again, we're being completely general) whatever choice you make for C.spam() may not be valid for C.ham(), which could behave completely differently. The question you ask can only be answered in reference to a specific class with specific methods. There is no general principle, it depends entirely on the problem being solved. -- Steven From no.email at please.post Thu Dec 23 23:42:39 2010 From: no.email at please.post (kj) Date: Fri, 24 Dec 2010 04:42:39 +0000 (UTC) Subject: How to order base classes? References: <4d14209d$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: In <4d14209d$0$30000$c3e8da3$5496439d at news.astraweb.com> Steven D'Aprano writes: >The question you ask can only be answered in reference to a specific >class with specific methods. There is no general principle, it depends >entirely on the problem being solved. Thanks! ~kj From steve+comp.lang.python at pearwood.info Thu Dec 23 23:55:09 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 24 Dec 2010 04:55:09 GMT Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4d1427ac$0$30000$c3e8da3$5496439d@news.astraweb.com> On Thu, 23 Dec 2010 02:54:52 -0800, Carl Banks wrote: > On Dec 22, 7:22?pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> There should be a mechanism for Python functions to distinguish between >> unexpected exceptions (commonly known as "bugs"), which should be >> reported as coming from wherever they come from, and documented, >> expected exceptions, which should be reported as coming from the >> function regardless of how deep the function call stack really is. > > No, -100. The traceback isn't the place for this. I've never disagreed > with you more, and I've disagreed with you and awful lot. Okay, it's your right to disagree, but I am trying to understand your reasons for disagreeing, and I simply don't get it. I'm quite frustrated that you don't give any reasons for why you think it's not just unnecessary but actually *horrible* to hide implementation details such as where data validation is performed. I hope you'll try to explain *why* you think it's a bad idea, rather than just continue throwing out dismissive statements about "self-important" programmers (your earlier post to KJ) and "never disagreed more" (to me). Do you accept that, as a general principle, unhandled errors should be reported as close as possible to where the error occurs? If your answer to that is No, then where do you think unhandled errors should be reported? Now, given the scenario I proposed earlier: >>> f('bad input') <=== error occurs here Traceback (most recent call last): File "", line 1, in File "", line 2, in f File "", line 2, in g File "", line 2, in h File "", line 2, in i File "", line 2, in j File "", line 2, in k <=== far from the source of error ValueError do you concede that the actual error occurs at the time 'bad input' is passed to f, and not further down the stack where k happens to raise an exception? If not, where do you think the error occurs, and why? -- Steven From no.email at please.post Fri Dec 24 00:03:06 2010 From: no.email at please.post (kj) Date: Fri, 24 Dec 2010 05:03:06 +0000 (UTC) Subject: Partition Recursive References: Message-ID: In macm writes: >url = 'http://docs.python.org/dev/library/stdtypes.html?highlight=partition#str.partition' >So I want convert to >myList = >['http',':','//','docs','.','python','.','org','/','dev','/','library','/','stdtypes','.','html','?','highlight','=','partition','#','str','.','partition'] >The reserved char are: >specialMeaning = ["//",";","/", "?", ":", "@", "=" , "&","#"] You forgot '.'. >>> import re # sorry >>> sp = re.compile('(//?|[;?:@=&#.])') >>> filter(len, sp.split(url)) ['http', ':', '//', 'docs', '.', 'python', '.', 'org', '/', 'dev', '/', 'library', '/', 'stdtypes', '.', 'html', '\ ?', 'highlight', '=', 'partition', '#', 'str', '.', 'partition'] ~kj From ian.g.kelly at gmail.com Fri Dec 24 00:33:15 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 23 Dec 2010 22:33:15 -0700 Subject: Partition Recursive In-Reply-To: References: Message-ID: On 12/23/2010 10:03 PM, kj wrote: >>>> import re # sorry >>>> sp = re.compile('(//?|[;?:@=&#.])') >>>> filter(len, sp.split(url)) Perhaps I'm being overly pedantic, but I would likely have written that as "filter(None, sp.split(url))" for the same reason that "if string:" is generally preferred to "if len(string):". Cheers, Ian From pavlovevidence at gmail.com Fri Dec 24 01:38:05 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 23 Dec 2010 22:38:05 -0800 (PST) Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d1427ac$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3771d7ec-c030-4d15-a257-4c895ff57ec0@n2g2000pre.googlegroups.com> On Dec 23, 8:55?pm, Steven D'Aprano wrote: > On Thu, 23 Dec 2010 02:54:52 -0800, Carl Banks wrote: > > On Dec 22, 7:22?pm, Steven D'Aprano > +comp.lang.pyt... at pearwood.info> wrote: > >> There should be a mechanism for Python functions to distinguish between > >> unexpected exceptions (commonly known as "bugs"), which should be > >> reported as coming from wherever they come from, and documented, > >> expected exceptions, which should be reported as coming from the > >> function regardless of how deep the function call stack really is. > > > No, -100. ?The traceback isn't the place for this. ?I've never disagreed > > with you more, and I've disagreed with you and awful lot. > > Okay, it's your right to disagree, but I am trying to understand your > reasons for disagreeing, and I simply don't get it. > > I'm quite frustrated that you don't give any reasons for why you think > it's not just unnecessary but actually *horrible* to hide implementation > details such as where data validation is performed. I hope you'll try to > explain *why* you think it's a bad idea, rather than just continue > throwing out dismissive statements about "self-important" programmers > (your earlier post to KJ) and "never disagreed more" (to me). > > Do you accept that, as a general principle, unhandled errors should be > reported as close as possible to where the error occurs? > If your answer to that is No, then where do you think unhandled errors > should be reported? "No", and "where the error is detected". That is, what Python does now. Trying to figure out where the error "occurred" is fool's errand. The former isn't even well-defined, let alone something a compiler or user can be expected to reliably report. Sometimes the error doesn't even "occur" in the same call stack. There's a similar fine line between a bug exception and bad input exception, and it's foolish to distinguish them in a reliable way: in particular bugs can easily be mistaken for bad input. OTOH, going the extra mile to hide useful information from a user is asinine. As a user, I will decide for myself how I want to use implementation-defined information, and I don't want the implementor to decide this for me. It's bad enough if an implementor fails to provide information out of laziness, but when they deliberately do extra work to hide information, that's self-importance and arrogance. The traceback IS NOT THE PLACE for these kinds of games. > Now, given the scenario I proposed earlier: > > >>> f('bad input') ? ?<=== error occurs here > > Traceback (most recent call last): > ? File "", line 1, in > ? File "", line 2, in f > ? File "", line 2, in g > ? File "", line 2, in h > ? File "", line 2, in i > ? File "", line 2, in j > ? File "", line 2, in k ? ?<=== far from the source of error > ValueError > > do you concede that the actual error occurs at the time 'bad input' is > passed to f, and not further down the stack where k happens to raise an > exception? If not, where do you think the error occurs, and why? This question is irrelevant. It doesn't matter where the mistake is made. Carl Banks From nospam at thanks.invalid Fri Dec 24 02:21:12 2010 From: nospam at thanks.invalid (Juha Nieminen) Date: 24 Dec 2010 07:21:12 GMT Subject: What is the the best style and theory of writing a complier in your language References: Message-ID: <4d1449e8$0$32168$7b1e8fa0@news.nbl.fi> In comp.lang.c++ small Pox wrote: > http://www.veteranstoday.com/2010/12/18/gordon-duff-gov-jesse-ventura-proves-911-cover-up-will-americas-government-fall/ You should take your religion somewhere else. From timr at probo.com Fri Dec 24 02:39:47 2010 From: timr at probo.com (Tim Roberts) Date: Thu, 23 Dec 2010 23:39:47 -0800 Subject: How to order base classes? References: Message-ID: <55j8h6ptj3a7cu72q36nan7g6n767a4ma4@4ax.com> kj wrote: > >Suppose that I want to write a subclass C of base classes A and B. >What considerations should go into choosing the ordering of A and >B in C's base class list? >... >...it is difficult for me to see a strong compelling reason for picking >an ordering over another. But may be just ignorance on my part. > >How should one go about deciding the ordering of base classes? In general, it is uncommon to have a class that derives from multiple classes that all provide major functionality. That quickly gets confusing, which is one reason Java doesn't allow multiple inheritance. Now, it is very common for a class to derive from one class primarily, with other classes providing a few additional features. That's the "mix-in" concept. In that case, you'd list the "major" ancestor first, with the mix-ins after, so the mix-ins can modify the behavior. class BlueSpanishListBox( ListBox, ColorBlueMixIn, SpanishMixIn ): ... Reading it, a BlueSpanishListBox is-a ListBox that happens to have a few additional features. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From hniksic at xemacs.org Fri Dec 24 04:08:36 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Fri, 24 Dec 2010 10:08:36 +0100 Subject: round in 2.6 and 2.7 References: <87sjxoco6u.fsf@xemacs.org> <4D13A81A.5030903@v.loewis.de> Message-ID: <87d3orbkrv.fsf@xemacs.org> "Martin v. Loewis" writes: >> Type "help", "copyright", "credits" or "license" for more information. >>>>> 9.95 >> 9.9499999999999993 >>>>> "%.16g" % 9.95 >> '9.949999999999999' >>>>> round(9.95, 1) >> 10.0 >> >> So it seems that Python is going out of its way to intuitively round >> 9.95, while the repr retains the unnecessary digits. > > The 2.6 result is simply incorrect. [...] > Yes. It's a bug fix described in "What's new in Python 2.7" thus: That makes sense, thanks. Even within Python 2.6, rounding with different methods could produce inconsistent results: >>> round(9.95, 1) 10.0 >>> '%.1f' % 9.95 '9.9' From steve+comp.lang.python at pearwood.info Fri Dec 24 04:24:34 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 24 Dec 2010 09:24:34 GMT Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d1427ac$0$30000$c3e8da3$5496439d@news.astraweb.com> <3771d7ec-c030-4d15-a257-4c895ff57ec0@n2g2000pre.googlegroups.com> Message-ID: <4d1466d2$0$30000$c3e8da3$5496439d@news.astraweb.com> On Thu, 23 Dec 2010 22:38:05 -0800, Carl Banks wrote: >> Do you accept that, as a general principle, unhandled errors should be >> reported as close as possible to where the error occurs? If your answer >> to that is No, then where do you think unhandled errors should be >> reported? > > "No", and "where the error is detected". That is, what Python does now. > Trying to figure out where the error "occurred" is fool's errand. But isn't that what debugging is all about -- finding where the error occurred and fixing it? Hardly a fool's errand. > The > former isn't even well-defined, let alone something a compiler or user > can be expected to reliably report. Sometimes the error doesn't even > "occur" in the same call stack. Thank you for taking the time to respond. I think your objection misses the point I'm trying to make completely. But since this argument is rather academic, and it's Christmas Eve here, I'll just make one last comment and leave it at that: > OTOH, going the extra mile to hide useful information from a user is > asinine. As a user, I will decide for myself how I want to use > implementation-defined information, and I don't want the implementor to > decide this for me. It's bad enough if an implementor fails to provide > information out of laziness, but when they deliberately do extra work to > hide information, that's self-importance and arrogance. But that of course is nonsense, because as the user you don't decide anything of the sort. The developer responsible for writing the function decides what information he provides you, starting with whether you get an exception at all, where it comes from, the type of exception, and the error message (if any). Once this information has been passed on to you, you're free to do anything you like with it, but you never get to choose what information you get -- I'm not suggesting any change there. All I'm suggesting is that there should be a way of reducing the boilerplate needed for this idiom: def _validate_arg(x): if x == 'bad input': return False return True def f(arg): if not _validate_arg(arg): raise ValueError process(arg) to something more natural that doesn't needlessly expose implementation details that are completely irrelevant to the caller. -- Steven From pavlovevidence at gmail.com Fri Dec 24 06:24:10 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 24 Dec 2010 03:24:10 -0800 (PST) Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d1427ac$0$30000$c3e8da3$5496439d@news.astraweb.com> <3771d7ec-c030-4d15-a257-4c895ff57ec0@n2g2000pre.googlegroups.com> <4d1466d2$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Dec 24, 1:24?am, Steven D'Aprano wrote: > On Thu, 23 Dec 2010 22:38:05 -0800, Carl Banks wrote: > > OTOH, going the extra mile to hide useful information from a user is > > asinine. As a user, I will decide for myself how I want to use > > implementation-defined information, and I don't want the implementor to > > decide this for me. It's bad enough if an implementor fails to provide > > information out of laziness, but when they deliberately do extra work to > > hide information, that's self-importance and arrogance. > > But that of course is nonsense, because as the user you don't decide > anything of the sort. As a user I can criticize the decision of the implementor to needlessly filter information, and declare that it's borne out of the author's arrogance in thinking he knows what I want when I get a traceback. I can also opine that Python language shouldn't make it easy for library implementors to be arrogant like this. > The developer responsible for writing the function > decides what information he provides you, starting with whether you get > an exception at all, where it comes from, the type of exception, and the > error message (if any). Once this information has been passed on to you, > you're free to do anything you like with it, but you never get to choose > what information you get -- I'm not suggesting any change there. All I'm > suggesting is that there should be a way of reducing the boilerplate > needed for this idiom: > > def _validate_arg(x): > ? ? if x == 'bad input': return False > ? ? return True > > def f(arg): > ? ? if not _validate_arg(arg): > ? ? ? ? raise ValueError > ? ? process(arg) > > to something more natural that doesn't needlessly expose implementation > details that are completely irrelevant to the caller. Arrogance. Who gave you the right to decide what is completely irrelevant to user? I, as the user, decide what's relevant. If I want implementation-dependent information, it's my business. I don't want the language to make it easy for arrogant people, who think they know what information I want better than I do, to hide that information from me. Carl Banks From dyxmert at gmail.com Fri Dec 24 07:31:10 2010 From: dyxmert at gmail.com (Oleg Leschov) Date: Fri, 24 Dec 2010 04:31:10 -0800 (PST) Subject: using strings from extension module question + possible documentation error Message-ID: <20db9603-3c4e-47f3-b55c-ff1fd680aca8@z19g2000yqb.googlegroups.com> Hi, I am writing an extension module in which I want to do some heavy number crunching on large amount of data. The input data is prepared using Python code and passed to this extension module via strings containing binary data, and the result is also passed back as a list of pretty large strings containing binary data. So first I thought I'll just pass the empty strings made in Python along with input data strings, so my extension code would just fill those empty strings with the results. But then I read the PyString docs, it says I must not modify any strings even though it seems to be possible... Ok then I decided I'll create a list and fill it with strings from my C extension code.. However to avoid data copying I wish to fill the newly created (using PyString_FromString(NULL,x) ) strings' buffers (obtained with PyString_AsString) with data after creating them in my extension module. The question is - is this allowed? Because the doc says this > The data must not be modified in any way, unless the string was just created using PyString_FromStringAndSize(NULL, size). but what exactly does "just created" mean? will it not be considered "just created" if I call any more Python stuff after PyString_FromString, like another PyString_FromString along with PyString_AsString? Which I certainly intend to do since I first create all strings I want, and then do my calculations which fill those with actual data. Another question is this - why does PyString_AsString doc states that > Return a NUL-terminated representation of the contents of string. when strings may contain binary data and thus NOT NUL-terminated in general? is this a documentation error or I can't access binary strings using PyString_AsString ? P.S. the doc quotes are from http://docs.python.org/release/2.6.6/c-api/string.html From g.rodola at gmail.com Fri Dec 24 07:52:46 2010 From: g.rodola at gmail.com (=?ISO-8859-1?Q?Giampaolo_Rodol=E0?=) Date: Fri, 24 Dec 2010 13:52:46 +0100 Subject: using python ftp In-Reply-To: References: <4D1291CB.5010404@nmsu.edu> Message-ID: Starting from Python 2.7, yes: http://docs.python.org/library/ftplib.html#ftplib.FTP_TLS Regards, --- Giampaolo http://code.google.com/p/pyftpdlib/ http://code.google.com/p/psutil/ 2010/12/23 Octavian Rasnita : > Can this lib also work with ftps? > > Thanks. > > Octavian > > ----- Original Message ----- > From: "Anurag Chourasia" > To: "Matt Funk" > Cc: > Sent: Thursday, December 23, 2010 4:12 AM > Subject: Re: using python ftp > > >> Hi Matt, >> >> I have a snippet to "upload" files (that match a particular search >> pattern) to a remote server. >> >> Variable names are self explanatory. You could tweak this a little to >> "download" files instead. >> >> from ftplib import FTP >> ftp = FTP(hostname) >> ftp.login(user_id,passwd) >> ftp.cwd(remote_directory) >> files_list=glob.glob(file_search_pattern) >> for file in files_list: >> ? ?try: >> ? ? ? ?ftp.storlines('STOR ' + file, open(file)) >> ? ?except Exception, e: >> ? ? ? ?print ('Failed to FTP file: %s' %(file)) >> ftp.close() >> >> Regards, >> Anurag >> >> On Thu, Dec 23, 2010 at 5:33 AM, Matt Funk wrote: >>> Hi, >>> >>> i was wondering whether someone can point me whether the following >>> already exists. >>> >>> I want to connect to a server , download various files (for whose name i >>> want to be able to use a wildcard), and store those files in a given >>> location on the hard drive. If the file already exists i do not want to >>> download it. >>> >>> This seems fairly trivial and i would assume that there should be some >>> sort of implementation that does this easily but i didn't find anything >>> googling it. >>> >>> Otherwise i was going to do it "by hand" using ftplib: >>> 1) connect to server, >>> 2) change to directory on server >>> 3) get listing >>> 4) match the file pattern i want to the listing >>> 5) check if file already exists >>> 6) download file if matched and doesn't exist >>> >>> Can anyone offer any advice whether this already done somewhere? >>> >>> thanks >>> matt >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >>> >> -- >> http://mail.python.org/mailman/listinfo/python-list > -- > http://mail.python.org/mailman/listinfo/python-list > From moura.mario at gmail.com Fri Dec 24 08:32:47 2010 From: moura.mario at gmail.com (macm) Date: Fri, 24 Dec 2010 05:32:47 -0800 (PST) Subject: Partition Recursive References: Message-ID: Thanks all In [11]: reps = 5 In [12]: t = Timer("url = 'http://docs.python.org/dev/library/ stdtypes.html? highlight=partition#str.partition' ;sp = re.compile('(//?|[;?:@=&#.])'); filter(len, sp.split(url))", 'import re') In [13]: print sum(t.repeat(repeat=reps, number=1)) / reps 4.94003295898e-05 In [65]: t = Timer("url = 'http://docs.python.org/dev/library/ stdtypes.html? highlight=partition#str.partition' ;sp = re.compile('(//?|[;?:@=&#.])'); filter(None, sp.split(url))", 'import re') In [66]: print sum(t.repeat(repeat=reps, number=1)) / reps 3.50475311279e-05 Ian with None is a litle fast, thanks kj! Hi Mr. James, speed is always important. But ok re is fine. (but could be e-07) In next step I'll go to cython to win something. Regards Mario On Dec 24, 3:33?am, Ian Kelly wrote: > On 12/23/2010 10:03 PM, kj wrote: > > >>>> import re # sorry > >>>> sp = re.compile('(//?|[;?:@=&#.])') > >>>> filter(len, sp.split(url)) > > Perhaps I'm being overly pedantic, but I would likely have written that > as "filter(None, sp.split(url))" for the same reason that "if string:" > is generally preferred to "if len(string):". > > Cheers, > Ian From python at bdurham.com Fri Dec 24 08:37:17 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 24 Dec 2010 08:37:17 -0500 Subject: GUI Tools for Python 3.1 In-Reply-To: References: Message-ID: <1293197837.22142.1412104645@webmail.messagingengine.com> Randy, Tkinter is a viable GUI platform with Python 3.1's (and Python 2.7's) support for ttk (Tile). The new ttk module supports theme aware controls so that you can build beautiful GUI's that match your underlying platform's standards. Ttk also includes theme aware treeview and notebook controls. The treeview control supports multiple columns and can be configured as a (1 level) grid. The only glaring weakness is Tkinter's support for image formats other than GIF. This can be addressed by using the PIL (Python Image Library) which adds about 800K to a distribution. Tkinter is built-in, available in the 2.7 and 3.1 branches, and supports both 32 and 64 bit versions of Python. If you're interested in learning more, join Python's Tkinter mailing list. Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan.sonnenberg at pythonmeister.com Fri Dec 24 08:42:48 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Fri, 24 Dec 2010 14:42:48 +0100 Subject: using strings from extension module question + possible documentation error In-Reply-To: <20db9603-3c4e-47f3-b55c-ff1fd680aca8@z19g2000yqb.googlegroups.com> References: <20db9603-3c4e-47f3-b55c-ff1fd680aca8@z19g2000yqb.googlegroups.com> Message-ID: <4D14A358.3010602@pythonmeister.com> Am 24.12.2010 13:31, schrieb Oleg Leschov: > Hi, > > I am writing an extension module in which I want to do some heavy > number crunching on large amount of data. > > The input data is prepared using Python code and passed to this > extension module via strings containing binary data, and the result is > also passed back as a list of pretty large strings containing binary > data. > > So first I thought I'll just pass the empty strings made in Python > along with input data strings, so my extension code would just fill > those empty strings with the results. > > But then I read the PyString docs, it says I must not modify any > strings even though it seems to be possible... strings are immutable. If you pass a string and the underlying C module changes it's contents, this idiom is broken. The source for endless pain ... > Ok then I decided I'll create a list and fill it with strings from my > C extension code.. > > However to avoid data copying I wish to fill the newly created (using > PyString_FromString(NULL,x) ) strings' buffers (obtained with > PyString_AsString) with data after creating them in my extension > module. You could as an alternative just use byte arrays. These are changeable. > The question is - is this allowed? Because the doc says this >> The data must not be modified in any way, unless the string was just created using PyString_FromStringAndSize(NULL, size). Once the string has been used by python code, you should not change it. strings are immutable in python, so that every operation on a string returns a new one. See above. > but what exactly does "just created" mean? will it not be considered Just created means just that. It is created and not been passed back to the interpreter. So long you may change it. > "just created" if I call any more Python stuff after > PyString_FromString, like another PyString_FromString along with > PyString_AsString? Which I certainly intend to do since I first create > all strings I want, and then do my calculations which fill those with > actual data. > > > Another question is this - why does PyString_AsString doc states that >> Return a NUL-terminated representation of the contents of string. > when strings may contain binary data and thus NOT NUL-terminated in > general? is this a documentation error or I can't access binary > strings using PyString_AsString ? Read carefully: NUL-terminated representation of the contents of the string. It may contain other data, but the C-API will take care that this "contract" will be valid. > P.S. the doc quotes are from > http://docs.python.org/release/2.6.6/c-api/string.html There do they live, indeed. From dyxmert at gmail.com Fri Dec 24 09:50:01 2010 From: dyxmert at gmail.com (Oleg Leschov) Date: Fri, 24 Dec 2010 06:50:01 -0800 (PST) Subject: using strings from extension module question + possible documentation error References: <20db9603-3c4e-47f3-b55c-ff1fd680aca8@z19g2000yqb.googlegroups.com> Message-ID: <8be5e7d2-f4dd-41e6-92d0-ec10f2e9ece4@i18g2000yqn.googlegroups.com> On Dec 24, 4:42?pm, Stefan Sonnenberg-Carstens wrote: > You could as an alternative just use byte arrays. These are changeable. thanks, that's exactly what I need. I have completely missed those things since they're pretty new. From jim.hefferon at gmail.com Fri Dec 24 10:10:28 2010 From: jim.hefferon at gmail.com (Jim) Date: Fri, 24 Dec 2010 07:10:28 -0800 (PST) Subject: lxml etree question Message-ID: <98fb45fe-e4d0-49f4-a705-7923b2bfcacb@k22g2000yqh.googlegroups.com> Hello, I wonder if someone knows about lxml.etree and namespaces? I want to build an ElementTree where some of the sub-elements have attributes that serialize this way. .. I've tried just comment_elet.set('xml:lang','de') and it didn't like that at all (although it takes comment_elet.set('auth:id','jones') just fine). I've also spelunked the docs and googled but have not hit on the right invocation. If someone knows, I'd be grateful. Jim From nitinpawar432 at gmail.com Fri Dec 24 10:18:52 2010 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Fri, 24 Dec 2010 20:48:52 +0530 Subject: lxml etree question In-Reply-To: <98fb45fe-e4d0-49f4-a705-7923b2bfcacb@k22g2000yqh.googlegroups.com> References: <98fb45fe-e4d0-49f4-a705-7923b2bfcacb@k22g2000yqh.googlegroups.com> Message-ID: On Fri, Dec 24, 2010 at 8:40 PM, Jim wrote: > Hello, I wonder if someone knows about lxml.etree and namespaces? > > I want to build an ElementTree where some of the sub-elements have > attributes that serialize this way. > > .. > > I've tried just comment_elet.set('xml:lang','de') and it didn't like > that at all (although it takes comment_elet.set('auth:id','jones') > just fine). I've also spelunked the docs and googled but have not hit > on the right invocation. If someone knows, I'd be grateful. > > Jim > -- > http://mail.python.org/mailman/listinfo/python-list > You can check this http://codespeak.net/pipermail/lxml-dev/2006-February/000920.html -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at please.post Fri Dec 24 11:24:34 2010 From: no.email at please.post (kj) Date: Fri, 24 Dec 2010 16:24:34 +0000 (UTC) Subject: How can a function find the function that called it? Message-ID: I want to implement a frozen and ordered dict. I thought I'd implement it as a subclass of collections.OrderedDict that prohibits all modifications to the dictionary after it has been initialized. In particular, calling this frozen subclass's update method should, in general, trigger an exception ("object is not mutable"). But OrderedDict's functionality *requires* that its __init__ be run, and this __init__, in turn, does part of its initialization by calling the update method. Therefore, the update method of the new subclass needs to be able to identify the calling function in order to make a special allowance for calls coming from OrderedDict.__init__. (Better yet, it should be able to allow calls coming from its own class's __init__, via OrderedDict.__init__.) The best I've been able to do is to use inspect to get the name of the calling function. For the case I'm trying to identify, this name is simply "__init__". But Python code is awash in __init__'s... Is it possible to achieve a more precise identification? Specifically, I want to know the *class* (not the file) where this '__init__' is defined. (BTW, I don't understand why inspect doesn't provide something as basic as the *class* that the method belongs to, whenever applicable. I imagine there's a good reason for this coyness, but I can't figure it out.) TIA! ~kj From chris at gonnerman.org Fri Dec 24 11:51:03 2010 From: chris at gonnerman.org (Chris Gonnerman) Date: Fri, 24 Dec 2010 10:51:03 -0600 Subject: [Python] How can a function find the function that called it? In-Reply-To: References: Message-ID: <4D14CF77.40405@gonnerman.org> On 12/24/2010 10:24 AM, kj wrote: > I want to implement a frozen and ordered dict. > > I thought I'd implement it as a subclass of collections.OrderedDict > that prohibits all modifications to the dictionary after it has > been initialized. > > In particular, calling this frozen subclass's update method should, > in general, trigger an exception ("object is not mutable"). > > But OrderedDict's functionality *requires* that its __init__ be > run, and this __init__, in turn, does part of its initialization > by calling the update method. Use a flag, "private" to your new class, to indicate whether initialization is complete or not; your update method would see that initialization is not yet complete when called by __init__, and so it would do its business (calling the class method). At the end of the __init__ function, set the initialized property to true. If your update is called with the initialized property already set to true, it will raise the exception. From smallpox911 at gmail.com Fri Dec 24 12:59:23 2010 From: smallpox911 at gmail.com (small Pox) Date: Fri, 24 Dec 2010 09:59:23 -0800 (PST) Subject: *** Alex Jones Exposes Google's Plan to Dominate the Internet *** plz spread this video References: Message-ID: Alex Jones Exposes Google's Plan to Dominate the Internet http://www.youtube.com/watch?v=LiqOL9ausOI Alex Jones Exposes Google's Plan to Dominate the Internet http://www.youtube.com/watch?v=LiqOL9ausOI Alex Jones Exposes Google's Plan to Dominate the Internet http://www.youtube.com/watch?v=LiqOL9ausOI Alex Jones Exposes Google's Plan to Dominate the Internet http://www.youtube.com/watch?v=LiqOL9ausOI Alex Jones Exposes Google's Plan to Dominate the Internet http://www.youtube.com/watch?v=LiqOL9ausOI Alex Jones Exposes Google's Plan to Dominate the Internet http://www.youtube.com/watch?v=LiqOL9ausOI Alex Jones Exposes Google's Plan to Dominate the Internet http://www.youtube.com/watch?v=LiqOL9ausOI -- The FAT per DIEM FBI bustards use our TAX PAYER MONEY and INCOMPETENCE is UNACCEPTABLE. ===== http://www.youtube.com/watch?v=lX18zUp6WPY http://www.youtube.com/watch?v=XQapkVCx1HI http://www.youtube.com/watch?v=tXJ-k-iOg0M Hey Racist and INcompetent FBI Bustards, where is the ANTHRAX Mailer ? Where are the 4 blackboxes ? Where are the Pentagon Videos ? Why did you release the 5 dancing Israelis compromising the whole 911 investigation ? If the Dubai Police can catch Mossad Murderers and put the videos and Iranian Police can why cant you put the Pentagon Videos ? If Iran police can put the AMERICAN TERRORIST, Riggi and puting on INTERNATIONAL MEDIA a day after catching him without TORTURE, why cant you put the INNOCENT patsies on the MEDIA. Why did you have to LIE about Dr Afiya Siddiqui and torture that Innocent little mother of 3 and smashing the skull of her one child ? http://www.youtube.com/watch?v=DhMcii8smxk http://www.youtube.com/watch?v=0SZ2lxDJmdg There are CRIMINAL cases against CIA CRIMINAL Bustards in Italian courts. FBI bustards paid a penalty of $5.8 million to Steven Hatfill, but only because he was a white. They got away with MURDER of thousands of Non-whites in all parts of the world. Daily 911 news : http://911blogger.com http://www.youtube.com/watch?v=tRfhUezbKLw http://www.youtube.com/watch?v=x7kGZ3XPEm4 http://www.youtube.com/watch?v=lX18zUp6WPY Conclusion : FBI bustards are RACIST and INcompetent. They could neither catch the ANTHRAX or 911 YANK/Jew criminals nor could they cover them up - whichever was their actual goal or task. SLASH the SALARIES of FBI/CIA/NSA etc BUSTARDS into half all across tbe board, esp the whites/jew on the top. FBI Bustards failed to Catch BERNARD MADOFF even after that RACIST and UNPATRIOTIC Act FBI bustards failed to prevent ROMAN POLANSKY from absconding to europe and rapes. FBI bustards failed to prevent OKLAHOMA On Dec 23, 2:01?pm, small Pox wrote: > What is the the best style and theory of writing a complier in your > language > > Maybe a book will suffice. > > http://www.veteranstoday.com/2010/12/18/gordon-duff-gov-jesse-ventura... > > I want to parse the contents of the above link into hebrew audio. > > CHEERIOS From smallpox911 at gmail.com Fri Dec 24 13:06:48 2010 From: smallpox911 at gmail.com (small Pox) Date: Fri, 24 Dec 2010 10:06:48 -0800 (PST) Subject: *** The Jew World Order - A TUTORIAL Exposition in Banking and Economics *** Message-ID: <76ef6b76-a823-40aa-97ea-c33ea3c822e1@g26g2000vbi.googlegroups.com> *** The Jew World Order - A TUTORIAL Exposition in Banking and Economics *** Is the New World Order ?Jewish?? February 12, 2005 What do you trust? Government, Paper or Gold? Let?s begin by defining the ?New World Order.? The mainspring of the New World Order is the desire on the part of the world?s central banksters to translate their vast economic power into permanent global institutions of political and social control. Their power is based on their monopoly over credit. They use the government?s credit to print money, and require the taxpayer to fork over billions in interest to them. Central banks like the Federal Reserve pretend to be government institutions. They are not. They are privately owned by perhaps 300 families. It is significant that the majority of these families are Jewish, how significant I am not yet sure. If they were Lutherans or Zulus, certainly our objections would be the same. I am a non-observant Jew who believes this situation is lethal for humanity and Jews alike. We have already seen the tragic consequences of it in World War II. The American inventor Thomas Edison described this colossal scam, which the New World Order is designed to perpetuate, as follows: ?It is absurd to say our country can issue bonds and cannot issue currency. Both are promises to pay, but one fattens the usurer and the other helps the people.? Central banks also control the supply of credit to businesses and individuals. Robert Hemphill, Credit Manager of the Federal Reserve Bank in Atlanta describes this untenable situation. ?This is a staggering thought. We are completely dependent on the commercial banks. Someone has to borrow every dollar we have in circulation, cash or credit. If the banks create ample synthetic money, we are prosperous; if not, we starve. We are absolutely without a permanent money system. When one gets a complete grasp of the picture, the tragic absurdity of our hopeless position is almost incredible, but there it is? It is so important that our present civilization may collapse unless it becomes widely understood and the defects remedied very soon.? ? When the Federal Reserve was inaugurated in 1913, a London banker acknowledged that it is a scam. ?The few who understand the system will either be so interested in its profits, or so dependent on its favours, that there will be no opposition from that class? The great body of the people, mentally incapable of comprehending, will bear its burden without complaint, and perhaps without even suspecting that the system is inimical (contrary) to their interests.? CONSEQUENCES Obviously printing money should be in the public sphere as prescribed by the U.S. Constitution. This anomalous situation is the source of humanity?s woes. It pits the people who control the economy against society as a whole. It is in their interest to destabilize society, foster immorality, internal division (like gay marriage) and war in order to increase debt and distract and control the masses. The banksters are responsible for social engineering programs such as the (homo) sexual revolution, feminism and multiculturalism, which undermine family and social cohesion. This fundamental antagonism also supports a vast criminal underworld actually run by the elites. The banksters are responsible for the assassinations of presidents like Lincoln and JFK, and for the attack on the World Trade Center. They own or control the mass media, which legitimizes G.W. Bush, the war in Iraq and the impending attack on Iran. War provides an excuse to introduce the draft and a repressive police state. Success today is based on a person?s willingness to become an accomplice, witting or unwitting, to the banker fraud. Even rich entrepreneurs are dependent on credit and are unwilling to support genuine change. As a result of the banksters? scam, Western society and culture are based on a fraud. We do not have genuine democracy or equal access to the mass media or open and truthful education. Western society is a fraud, run by cowards who know they?re frauds. ARE ?THE JEWS? RESPONSIBLE? The New World Order is a hydra-headed monster. The banksters work through many fronts such as Communism, socialism, liberalism, feminism, Zionism, neo conservatism and Freemasonry. Unknown to most members, these ?progressive? movements are all secretly devoted to ?world revolution? which is a euphemism for banker hegemony. (See my ?Rothschild Conducts Red Symphony?) The banksters control the world?s major corporations, media, intelligence agencies, think tanks, foundations and universities. They are responsible for suppressing the truth. Jews figure prominently in all of this, a cause of anti Semitism. Of course many other people are pursuing ?success? as well. The banksters also work through countries. They are largely responsible for British and American imperialism, whose aim is to monopolize the world?s wealth. In his book ?The Jews? (1922) British social critic Hilaire Belloc writes that the British Empire represented a partnership between Jewish finance and the British aristocracy. ?After Waterloo [1815] London became the money market and the clearing house of the world. The interests of the Jew as a financial dealer and the interests of this great commercial polity approximated more and more. One may say that by the last third of the nineteenth century, they had become virtually identical.? The confluence of Jewish and British interest extended to marriage. ?Marriages began to take place, wholesale, between what had once been the aristocratic territorial families of this country and the Jewish commercial fortunes. After two generations of this, with the opening of the twentieth century, those of the great territorial English families in which there was no Jewish blood was the exception. In nearly all of them was the strain more or less marked, in some of them so strong that though the name was still an English name and the traditions those of a purely English lineage of the long past, the physique and character had become wholly Jewish?? If the marriage of Al Gore?s daughter with Jacob Schiff?s grandson is any indication, this mingling of Jewish and Gentile elites extends to America as well. John Forbes Kerry is another example. Belloc continues to say that the British and Jewish goal of world domination was synonymous and used Freemasonry as an instrument. ?Specifically Jewish institutions, such as Freemasonry (which the Jews had inaugurated as a sort of bridge between themselves and their hosts in the seventeenth century) were particularly strong in Britain, and there arose a political tradition, active, and ultimately to prove of great importance, whereby the British state was tacitly accepted by foreign governments as the official protector of the Jews in other countries. It was Britain which was expected to intervene [wherever Jewish persecution took place and] to support the Jewish financial energies throughout the world, and to receive in return the benefit of that connection.? If Belloc is right, you could say the New World Order is an extension of the British Empire, in which elite British, American and Jewish interests are indistinguishable. See also my ?The Jewish Conspiracy is British Imperialism.? CONCLUSION: WHAT IS JEWISH? The majority of Jews would want no part of the New World Order a.k.a. ?globalization? if they understood its undemocratic character and how they are being used. The true Jewish spirit holds that truth and morality are absolute and cannot be trimmed to fit one?s perceived self interest. G.J. Nueberger expresses this spirit in his essay ?The Great Gulf Between Zionism and Judaism.? ?The Jewish people are chosen not for domination over others, not for conquest or warfare, but to serve G-d and thus to serve mankind?Thus physical violence is not a tradition or a value of the Jews. The task for which the Jewish people were chosen is not to set an example of military superiority or technical achievements, but to seek perfection in moral behaviour and spiritual purity. Of all the crimes of political Zionism, the worst and most basic, and which explains all its other misdeeds, is that from its beginning Zionism has sought to separate the Jewish people from their G-d, to render the divine covenant null and void, and to substitute a ?modern? statehood and fraudulent sovereignty for the lofty ideals of the Jewish people.? The banksters obviously aren?t concerned about true Judaism or racial purity and were quite willing to sacrifice millions of Jews to achieve their design by backing Hitler. They are sacrificing thousands more Jewish, American and Muslim lives in the Middle East in their Orwellian ?perpetual war for perpetual peace.? Does the New World Order serve a ?Jewish? agenda or a banker elite agenda? I would venture that it serves the latter, and the Jewish people are an instrument of this agenda like so many other people. By giving private individuals the ability to create money out of nothing, we have created a monster which threatens to devour the planet and with it the human race. Source: Save the Males December 17, 2010 Posted in: AIPAC, Anti Racism, Anti-Defamation League, Anti-Semitism, Anti-Semitism News, B'nai B'rith, Discrimination News, Israel, Jerusalem, Jewish, Jewish American Heritage Month, Jewish Heritage, Jewish History, Jews, Judaism, Racism News, Sephardic, Tel Aviv, West Bank, White Nationalism, White Supremacism, Zionism, ashkenazi From awilliam at whitemice.org Fri Dec 24 13:17:01 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Fri, 24 Dec 2010 13:17:01 -0500 Subject: lxml etree question In-Reply-To: References: <98fb45fe-e4d0-49f4-a705-7923b2bfcacb@k22g2000yqh.googlegroups.com> Message-ID: <1293214621.3872.3.camel@linux-yu4c.site> On Fri, 2010-12-24 at 20:48 +0530, Nitin Pawar wrote: > On Fri, Dec 24, 2010 at 8:40 PM, Jim wrote: > Hello, I wonder if someone knows about lxml.etree and > namespaces? Yes, and don't. > I want to build an ElementTree where some of the sub-elements have > attributes that serialize this way. > .. > I've tried just comment_elet.set('xml:lang','de') and it didn't like > that at all (although it takes comment_elet.set('auth:id','jones') > just fine). I've also spelunked the docs and googled but have not hit > on the right invocation. If someone knows, I'd be grateful. I'd *strongly* recommend using ElementFlow for building XML documents (over ElementTree), especially if namespaces are involved. ElementFlow is far more intuitive. From cbrown at cbrownsystems.com Fri Dec 24 13:23:59 2010 From: cbrown at cbrownsystems.com (ChasBrown) Date: Fri, 24 Dec 2010 10:23:59 -0800 (PST) Subject: How can a function find the function that called it? References: Message-ID: On Dec 24, 8:24?am, kj wrote: > I want to implement a frozen and ordered dict. > > I thought I'd implement it as a subclass of collections.OrderedDict > that prohibits all modifications to the dictionary after it has > been initialized. > > In particular, calling this frozen subclass's update method should, > in general, trigger an exception ("object is not mutable"). > > But OrderedDict's functionality *requires* that its __init__ be > run, and this __init__, in turn, does part of its initialization > by calling the update method. > Rather than trying to identify the caller, I'd do something like: class FrozenODict(OrderedDict): def __init__(self, *args, **kwargs): OrderedDict.__init__(self, *args, **kwargs) self.update = self._update # init is complete, so override # update method for this instance def _update(self, dict2): raise Exception("object is immutable!!") After the __init__, calls to the instance's 'update' function will be mapped to _update. It's essentially overriding the inherited function on the fly. Cheers - Chas From urban.dani at gmail.com Fri Dec 24 13:26:06 2010 From: urban.dani at gmail.com (Daniel Urban) Date: Fri, 24 Dec 2010 19:26:06 +0100 Subject: How can a function find the function that called it? In-Reply-To: References: Message-ID: On Fri, Dec 24, 2010 at 17:24, kj wrote: > (BTW, I don't understand why inspect doesn't provide something as > basic as the *class* that the method belongs to, whenever applicable. > I imagine there's a good reason for this coyness, but I can't figure > it out.) One function object can "belong to" (be in the namespace of) more than one class, so there is no "the class". From nagle at animats.com Fri Dec 24 13:26:40 2010 From: nagle at animats.com (John Nagle) Date: Fri, 24 Dec 2010 10:26:40 -0800 Subject: [Python] How can a function find the function that called it? In-Reply-To: References: Message-ID: <4d14e5db$0$43976$742ec2ed@news.sonic.net> On 12/24/2010 8:51 AM, Chris Gonnerman wrote: > On 12/24/2010 10:24 AM, kj wrote: >> I want to implement a frozen and ordered dict. >> >> I thought I'd implement it as a subclass of collections.OrderedDict >> that prohibits all modifications to the dictionary after it has >> been initialized. That's actually a fairly common question - is an object in initialization, or has it been fully created? It would be useful if Python had some standard way to check if initialization has completed. Sometimes a parent class needs to know if initialization of the entire object has completed. This typically comes up with classes that define "__setattr__" and are then subclassed. John Nagle From no.email at please.post Fri Dec 24 13:43:06 2010 From: no.email at please.post (kj) Date: Fri, 24 Dec 2010 18:43:06 +0000 (UTC) Subject: How can a function find the function that called it? References: Message-ID: In Daniel Urban writes: >On Fri, Dec 24, 2010 at 17:24, kj wrote: >> (BTW, I don't understand why inspect doesn't provide something as >> basic as the *class* that the method belongs to, whenever applicable. >> I imagine there's a good reason for this coyness, but I can't figure >> it out.) >One function object can "belong to" (be in the namespace of) more than >one class, so there is no "the class". There are many other properties that inspect reports on (e.g. filename) that may not apply to an individual case. For 99.9% of methods, the class in which it was lexically defined would be good enough. From nagle at animats.com Fri Dec 24 13:51:32 2010 From: nagle at animats.com (John Nagle) Date: Fri, 24 Dec 2010 10:51:32 -0800 Subject: How to pop the interpreter's stack? In-Reply-To: References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d1427ac$0$30000$c3e8da3$5496439d@news.astraweb.com> <3771d7ec-c030-4d15-a257-4c895ff57ec0@n2g2000pre.googlegroups.com> <4d1466d2$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4d14ebaf$0$44021$742ec2ed@news.sonic.net> On 12/24/2010 3:24 AM, Carl Banks wrote: > On Dec 24, 1:24 am, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: All I'm >> suggesting is that there should be a way of reducing the boilerplate >> needed for this idiom: >> >> def _validate_arg(x): >> if x == 'bad input': return False >> return True >> >> def f(arg): >> if not _validate_arg(arg): >> raise ValueError >> process(arg) >> >> to something more natural that doesn't needlessly expose implementation >> details that are completely irrelevant to the caller. How about raise ValueError("Bad input %s to validate_arg" % (repr(arg),)) You can pass arguments to most exceptions, and the content of the exception is determined entirely by the code raising it. If end users are seeing uncaught tracebacks, the program is broken. It's usually worth it to catch EnvironmentError near the outermost level of the program, since most non program bug events, like I/O and network errors. will raise some subclass of EnvironmentError. John Nagle From no.email at please.post Fri Dec 24 13:52:02 2010 From: no.email at please.post (kj) Date: Fri, 24 Dec 2010 18:52:02 +0000 (UTC) Subject: type(d) != type(d.copy()) when type(d).issubclass(dict) Message-ID: Watch this: >>> class neodict(dict): pass ... >>> d = neodict() >>> type(d) >>> type(d.copy()) Bug? Feature? Genius beyond the grasp of schlubs like me? ~kj From mdw at distorted.org.uk Fri Dec 24 13:58:37 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 24 Dec 2010 18:58:37 +0000 Subject: How can a function find the function that called it? References: Message-ID: <87d3orvvz6.fsf.mdw@metalzone.distorted.org.uk> kj writes: > But OrderedDict's functionality *requires* that its __init__ be > run, and this __init__, in turn, does part of its initialization > by calling the update method. > > Therefore, the update method of the new subclass needs to be able > to identify the calling function in order to make a special allowance > for calls coming from OrderedDict.__init__ That doesn't follow at all. Why not set a `frozen' flag when your initialization is complete? Something like class ImmutableOrderedDict (OrderedDict): def __init__(me, *args, **kw): me._frozen = False OrderedDict.__init__(me, *arg, **kw) me._frozen = True def _check(me): if me._frozen: raise ImmutableError And so on. Thank you for explaining your actual objective, by the way. -- [mdw] From drobinow at gmail.com Fri Dec 24 16:17:40 2010 From: drobinow at gmail.com (David Robinow) Date: Fri, 24 Dec 2010 16:17:40 -0500 Subject: type(d) != type(d.copy()) when type(d).issubclass(dict) In-Reply-To: References: Message-ID: On Fri, Dec 24, 2010 at 1:52 PM, kj wrote: > Watch this: > >>>> class neodict(dict): pass > ... >>>> d = neodict() >>>> type(d) > >>>> type(d.copy()) > > > > Bug? ?Feature? ?Genius beyond the grasp of schlubs like me? copy, here, is a dict method. It will create a dict. If you really need it, you could try this: import copy class neodict(dict): def copy(self): return copy.copy(self) d = neodict() print type(d) dd = d.copy() print type(dd) From flisboa.costa at gmail.com Fri Dec 24 16:37:31 2010 From: flisboa.costa at gmail.com (=?UTF-8?B?RmzDoXZpbyBMaXNiw7Rh?=) Date: Fri, 24 Dec 2010 18:37:31 -0300 Subject: type(d) != type(d.copy()) when type(d).issubclass(dict) In-Reply-To: References: Message-ID: > > copy, here, is a dict method. It will create a dict. > If you really need it, you could try this: > > import copy > class neodict(dict): > def copy(self): > return copy.copy(self) > > d = neodict() > print type(d) > dd = d.copy() > print type(dd) One more gotcha to python... OO in python is strange :p IMO, if i subclass a class, all instance methods from a subclass instance should work with the subclass. But i'm guessing python doesn't make this distinction of instance/class methods like some other languages do (unless one uses annotations, what appears to be not the case with the dict class). Not that it inhibits me on using python in any way, in fact i do use python for my projects. I'm new to it, and I like some of its features, but some others are rather strange. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Fri Dec 24 17:14:42 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 24 Dec 2010 14:14:42 -0800 Subject: How to pop the interpreter's stack? In-Reply-To: References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d1427ac$0$30000$c3e8da3$5496439d@news.astraweb.com> <3771d7ec-c030-4d15-a257-4c895ff57ec0@n2g2000pre.googlegroups.com> <4d1466d2$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4D151B52.4030502@stoneleaf.us> Carl Banks wrote: > On Dec 24, 1:24 am, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> On Thu, 23 Dec 2010 22:38:05 -0800, Carl Banks wrote: >>> OTOH, going the extra mile to hide useful information from a user is >>> asinine. As a user, I will decide for myself how I want to use >>> implementation-defined information, and I don't want the implementor to >>> decide this for me. It's bad enough if an implementor fails to provide >>> information out of laziness, but when they deliberately do extra work to >>> hide information, that's self-importance and arrogance. >> But that of course is nonsense, because as the user you don't decide >> anything of the sort. > > As a user I can criticize the decision of the implementor to > needlessly filter information, and declare that it's borne out of the > author's arrogance in thinking he knows what I want when I get a > traceback. > > I can also opine that Python language shouldn't make it easy for > library implementors to be arrogant like this. > >> The developer responsible for writing the function >> decides what information he provides you, starting with whether you get >> an exception at all, where it comes from, the type of exception, and the >> error message (if any). Once this information has been passed on to you, >> you're free to do anything you like with it, but you never get to choose >> what information you get -- I'm not suggesting any change there. All I'm >> suggesting is that there should be a way of reducing the boilerplate >> needed for this idiom: >> >> def _validate_arg(x): >> if x == 'bad input': return False >> return True >> >> def f(arg): >> if not _validate_arg(arg): >> raise ValueError >> process(arg) >> >> to something more natural that doesn't needlessly expose implementation >> details that are completely irrelevant to the caller. > > Arrogance. Who gave you the right to decide what is completely > irrelevant to user? I, as the user, decide what's relevant. If I > want implementation-dependent information, it's my business. > > I don't want the language to make it easy for arrogant people, who > think they know what information I want better than I do, to hide that > information from me. One of the many things I love about Python is that it stays out of the way of me getting my work done. I think a truly pythonic program/library/module must do the same. So in this regard I agree with Carl. There are also times when I change the exception being raised to match what python expects from that type of object -- for example, from WhatEverException to KeyError for a dict-like object. So in this regard I agree with Steven. For kj's concern, which seems to be along the lines of functional as opposed to custom object, I don't think the traceback should be monkied with -- either use a decorator to keep the traceback short, or give the _pre_func name a good name and don't worry about it. I know when I see a traceback, I start at the bottom and only work my way up if I need to. ~Ethan~ From benjamin.kaplan at case.edu Fri Dec 24 17:40:44 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 24 Dec 2010 17:40:44 -0500 Subject: type(d) != type(d.copy()) when type(d).issubclass(dict) In-Reply-To: References: Message-ID: On Dec 24, 2010 4:40 PM, "Fl?vio Lisb?a" wrote: >> >> copy, here, is a dict method. It will create a dict. >> If you really need it, you could try this: >> >> import copy >> class neodict(dict): >> def copy(self): >> return copy.copy(self) >> >> d = neodict() >> print type(d) >> dd = d.copy() >> print type(dd) > > > One more gotcha to python... OO in python is strange :p > > IMO, if i subclass a class, all instance methods from a subclass instance should work with the subclass. But i'm guessing python doesn't make this distinction of instance/class methods like some other languages do (unless one uses annotations, what appears to be not the case with the dict class). > This isn't at all unique to Python. You'd get the same results in java or any other language. public class Foo { int a; public Foo(int a) { this.a = a; } public Foo clone() { return new Foo(this.a); } } public class Bar extends Foo { public Bar() { super(0); } } What type do you think (new Bar()).clone() is going to return? > Not that it inhibits me on using python in any way, in fact i do use python for my projects. I'm new to it, and I like some of its features, but some others are rather strange. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From cdalten at gmail.com Fri Dec 24 19:00:36 2010 From: cdalten at gmail.com (chad) Date: Fri, 24 Dec 2010 16:00:36 -0800 (PST) Subject: I don't why there is no output.... Message-ID: Given the following... #!/usr/bin/python import pexpect p = pexpect.spawn('cat') p.sendline('1234') p.expect (['1234']) p.expect (['1234']) I no output when I run it... [cdalten at localhost oakland]$ ./ecat.py [cdalten at localhost oakland]$ I don't get it. I was expecting to see the output from both the tty and cat. Instead, I see nothing. Why? From cdalten at gmail.com Fri Dec 24 19:22:18 2010 From: cdalten at gmail.com (chad) Date: Fri, 24 Dec 2010 16:22:18 -0800 (PST) Subject: I don't why there is no output.... References: Message-ID: On Dec 24, 4:00?pm, chad wrote: > Given the following... > > #!/usr/bin/python > > import pexpect > > p = pexpect.spawn('cat') > p.sendline('1234') > p.expect (['1234']) > p.expect (['1234']) > > I no output when I run it... > > [cdalten at localhost oakland]$ ./ecat.py > [cdalten at localhost oakland]$ > > I don't get it. I was expecting to see the output from both the tty > and cat. Instead, I see nothing. Why? Never mind. I figured it out. From stefan_ml at behnel.de Sat Dec 25 05:33:20 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 25 Dec 2010 11:33:20 +0100 Subject: lxml etree question In-Reply-To: <98fb45fe-e4d0-49f4-a705-7923b2bfcacb@k22g2000yqh.googlegroups.com> References: <98fb45fe-e4d0-49f4-a705-7923b2bfcacb@k22g2000yqh.googlegroups.com> Message-ID: Jim, 24.12.2010 16:10: > Hello, I wonder if someone knows about lxml.etree and namespaces? > > I want to build an ElementTree where some of the sub-elements have > attributes that serialize this way. > > .. > > I've tried just comment_elet.set('xml:lang','de') and it didn't like > that at all (although it takes comment_elet.set('auth:id','jones') > just fine). I've also spelunked the docs and googled but have not hit > on the right invocation. If someone knows, I'd be grateful. This should get you on the right track: http://codespeak.net/lxml/tutorial.html#namespaces In short: you need to distinguish between namespaces (URIs) and namespace prefixes. ElementTree and lxml.etree use the fully qualified tag name in the form "{namespace-URI}localname}". As for the special case of the "xml" prefix, the XML namespace spec has this to say: """ The prefix xml is by definition bound to the namespace name http://www.w3.org/XML/1998/namespace. It MAY, but need not, be declared, and MUST NOT be bound to any other namespace name. Other prefixes MUST NOT be bound to this namespace name, and it MUST NOT be declared as the default namespace. """ http://www.w3.org/TR/REC-xml-names/#ns-decl lxml knows about this special case, so you can write {http://www.w3.org/XML/1998/namespace}lang and lxml will take care of using the right prefix. Stefan From rina308 at gmail.com Sat Dec 25 06:38:40 2010 From: rina308 at gmail.com (czarina08) Date: Sat, 25 Dec 2010 03:38:40 -0800 (PST) Subject: Python Average Salary Report Message-ID: Hi there, I'm doing a market research report on the average hourly rates for Python/Django developers. Any input on this? I do understand that it does depend on the location, amount of experience and skills. I'd like to hear what are the hourly rates within your area :-) Thanks! From alice at gothcandy.com Sat Dec 25 09:16:29 2010 From: alice at gothcandy.com (=?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=) Date: Sat, 25 Dec 2010 06:16:29 -0800 Subject: Python Average Salary Report References: Message-ID: Howdy! > I'm doing a market research report on the average hourly rates for > Python/Django developers. Any input on this? I do understand that it > does depend on the location, amount of experience and skills. I'd like > to hear what are the hourly rates within your area :-) Thanks! I'm a strange case, but I like to charge my clients what my clients charge theirs. It's only fair. ;) This, of course, results in my rates varying from between $25 and $125, with a mean of ~$50/hr. More often, though, fixed payment is arranged on a per-project basis regardless of hours, which I understand to be a dangerous practice. (Scope creep is my arch nemesis! ;) - Alice From robert.kern at gmail.com Sat Dec 25 09:17:27 2010 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 25 Dec 2010 09:17:27 -0500 Subject: How to pop the interpreter's stack? In-Reply-To: <4D151B52.4030502@stoneleaf.us> References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d1427ac$0$30000$c3e8da3$5496439d@news.astraweb.com> <3771d7ec-c030-4d15-a257-4c895ff57ec0@n2g2000pre.googlegroups.com> <4d1466d2$0$30000$c3e8da3$5496439d@news.astraweb.com> <4D151B52.4030502@stoneleaf.us> Message-ID: On 12/24/10 5:14 PM, Ethan Furman wrote: > There are also times when I change the exception being raised to match > what python expects from that type of object -- for example, from > WhatEverException to KeyError for a dict-like object. So in this regard I agree > with Steven. Steven isn't arguing that particular point here, nor is anyone arguing against it. -- 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 Sat Dec 25 09:21:54 2010 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 25 Dec 2010 09:21:54 -0500 Subject: How to pop the interpreter's stack? In-Reply-To: <4d1466d2$0$30000$c3e8da3$5496439d@news.astraweb.com> References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d1427ac$0$30000$c3e8da3$5496439d@news.astraweb.com> <3771d7ec-c030-4d15-a257-4c895ff57ec0@n2g2000pre.googlegroups.com> <4d1466d2$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 12/24/10 4:24 AM, Steven D'Aprano wrote: > On Thu, 23 Dec 2010 22:38:05 -0800, Carl Banks wrote: >> OTOH, going the extra mile to hide useful information from a user is >> asinine. As a user, I will decide for myself how I want to use >> implementation-defined information, and I don't want the implementor to >> decide this for me. It's bad enough if an implementor fails to provide >> information out of laziness, but when they deliberately do extra work to >> hide information, that's self-importance and arrogance. > > But that of course is nonsense, because as the user you don't decide > anything of the sort. The developer responsible for writing the function > decides what information he provides you, starting with whether you get > an exception at all, where it comes from, the type of exception, and the > error message (if any). Carl isn't arguing that the user is or should be responsible for this sort of thing. He is arguing that developers should be responsible for doing this in such a way that is beneficial for the developer/user down the road. > Once this information has been passed on to you, > you're free to do anything you like with it, but you never get to choose > what information you get -- I'm not suggesting any change there. All I'm > suggesting is that there should be a way of reducing the boilerplate > needed for this idiom: > > def _validate_arg(x): > if x == 'bad input': return False > return True > > def f(arg): > if not _validate_arg(arg): > raise ValueError > process(arg) > > to something more natural that doesn't needlessly expose implementation > details that are completely irrelevant to the caller. Except that the *caller* never gets the traceback (unless if it deliberately inspects the stack for some metaprogramming reason). It gets the exception, and that is the same no matter what you do. The developer/user gets the traceback, and those implementation details *are* often important to them. -- 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 Sat Dec 25 10:42:29 2010 From: roy at panix.com (Roy Smith) Date: Sat, 25 Dec 2010 10:42:29 -0500 Subject: Keeping track of the N largest values Message-ID: I'm processing a stream of N numbers and want to keep track of the K largest. There's too many numbers in the stream (i.e. N is too large) to keep in memory at once. K is small (100 would be typical). >From a theoretical point of view, I should be able to do this in N log K time. What I'm doing now is essentially: top = [-1] # Assume all x are >= 0 for x in input(): if x <= top[0]: continue top.append(x) if len(top) > K: top.sort() top.pop(0) I can see pathological cases (say, all input values the same) where running time would be N K log K, but on average (N >> K and random distribution of values), this should be pretty close to N. Is there a better way to do this, either from a theoretical running time point of view, or just a nicer way to code this in Python? From steve at holdenweb.com Sat Dec 25 10:55:13 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 25 Dec 2010 10:55:13 -0500 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: <4D13C04E.6070103@pythonmeister.com> References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> Message-ID: On 12/23/2010 4:34 PM, Stefan Sonnenberg-Carstens wrote: > For large datasets I always have huge question marks if one says "xml". > But I don't want to start a flame war. I agree people abuse the "spirit of XML" using it to transfer gigabytes of data, but what else are they to use? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sat Dec 25 10:56:15 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 25 Dec 2010 10:56:15 -0500 Subject: What is the the best style and theory of writing a complier in your language In-Reply-To: References: Message-ID: On 12/23/2010 5:01 PM, small Pox wrote: > What is the the best style and theory of writing a complier in your > language > > Maybe a book will suffice. > > http://something-argumentative/ > > I want to parse the contents of the above link into hebrew audio. > > CHEERIOS > Sure you do. regareds Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From duncan.booth at invalid.invalid Sat Dec 25 10:58:35 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 25 Dec 2010 15:58:35 GMT Subject: type(d) != type(d.copy()) when type(d).issubclass(dict) References: Message-ID: kj wrote: > Watch this: > >>>> class neodict(dict): pass > ... >>>> d = neodict() >>>> type(d) > >>>> type(d.copy()) > > > > Bug? Feature? Genius beyond the grasp of schlubs like me? Feature. In (almost?) all cases any objects constructed by a subclass of a builtin class will be of the original builtin class. So, for example, subclass a string and concatenating your subclassed objects still produces a string. This is reasonable behaviour as for builtin classes performance is more important than fully implementing polymorphism. If you want to subclass a builtin class you need to be aware of this and override the behaviour where it matters. Why do you want to subclass a dict anyway? It is usually the wrong choice. -- Duncan Booth http://kupuguy.blogspot.com From __peter__ at web.de Sat Dec 25 11:04:07 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 25 Dec 2010 17:04:07 +0100 Subject: Keeping track of the N largest values References: Message-ID: Roy Smith wrote: > I'm processing a stream of N numbers and want to keep track of the K > largest. There's too many numbers in the stream (i.e. N is too large) > to keep in memory at once. K is small (100 would be typical). > > From a theoretical point of view, I should be able to do this in N log K > time. What I'm doing now is essentially: > > top = [-1] # Assume all x are >= 0 > for x in input(): > if x <= top[0]: > continue > top.append(x) > if len(top) > K: > top.sort() > top.pop(0) > > I can see pathological cases (say, all input values the same) where > running time would be N K log K, but on average (N >> K and random > distribution of values), this should be pretty close to N. > > Is there a better way to do this, either from a theoretical running time > point of view, or just a nicer way to code this in Python? http://docs.python.org/library/heapq.html#heapq.nlargest From duncan.booth at invalid.invalid Sat Dec 25 11:09:08 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 25 Dec 2010 16:09:08 GMT Subject: Keeping track of the N largest values References: Message-ID: Roy Smith wrote: > > I'm processing a stream of N numbers and want to keep track of the K > largest. There's too many numbers in the stream (i.e. N is too large) > to keep in memory at once. K is small (100 would be typical). > ... > Is there a better way to do this, either from a theoretical running > time point of view, or just a nicer way to code this in Python? How about: from heapq import nlargest top = nlargest(K, input()) It uses a heap so avoids completely resorting each time. -- Duncan Booth http://kupuguy.blogspot.com From stefan_ml at behnel.de Sat Dec 25 11:51:09 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 25 Dec 2010 17:51:09 +0100 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> Message-ID: Steve Holden, 25.12.2010 16:55: > On 12/23/2010 4:34 PM, Stefan Sonnenberg-Carstens wrote: >> For large datasets I always have huge question marks if one says "xml". >> But I don't want to start a flame war. > > I agree people abuse the "spirit of XML" using it to transfer gigabytes > of data I keep reading people say that (and *much* worse). XML may not be the tightly tailored solution for data of that size, but it's not inherently wrong to store gigabytes of data in XML. I mean, XML is a reasonably fast, versatile, widely used, well-compressing and safe data format with an extremely ubiquitous and well optimised set of tools available for all sorts of environments. So as soon as the data is any complex or the environments require portable data exchange, I consider XML a reasonable choice, even for large data sets (which usually implies that it's machine generated outputo anyway). Stefan From robert.kern at gmail.com Sat Dec 25 12:09:09 2010 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 25 Dec 2010 12:09:09 -0500 Subject: Keeping track of the N largest values In-Reply-To: References: Message-ID: On 12/25/10 10:42 AM, Roy Smith wrote: > I'm processing a stream of N numbers and want to keep track of the K > largest. There's too many numbers in the stream (i.e. N is too large) > to keep in memory at once. K is small (100 would be typical). > >> From a theoretical point of view, I should be able to do this in N log K > time. What I'm doing now is essentially: > > top = [-1] # Assume all x are>= 0 > for x in input(): > if x<= top[0]: > continue > top.append(x) > if len(top)> K: > top.sort() > top.pop(0) > > I can see pathological cases (say, all input values the same) where > running time would be N K log K, but on average (N>> K and random > distribution of values), this should be pretty close to N. > > Is there a better way to do this, either from a theoretical running time > point of view, or just a nicer way to code this in Python? heapq.nlargest() http://docs.python.org/library/heapq#heapq.nlargest -- 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 awilliam at whitemice.org Sat Dec 25 12:21:39 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Sat, 25 Dec 2010 11:21:39 -0600 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> Message-ID: "Steve Holden" wrote: >On 12/23/2010 4:34 PM, Stefan Sonnenberg-Carstens wrote: >> For large datasets I always have huge question marks if one says >"xml". >> But I don't want to start a flame war. >I agree people abuse the "spirit of XML" using it to transfer gigabytes >of data, How so? I think this assertion is bogus. XML works extremely well for large datasets. >but what else are they to use? If you are sending me data - please use XML . I've gotten 22GB XML files in the past - worked without issue and pretty quickly too. Sure better than trying to figure out whatever goofy document format someone cooks up on their own. XML toolkits are proven and documented. From usernet at ilthio.net Sat Dec 25 12:27:15 2010 From: usernet at ilthio.net (Tim Harig) Date: Sat, 25 Dec 2010 17:27:15 +0000 (UTC) Subject: Trying to parse a HUGE(1gb) xml file References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> Message-ID: On 2010-12-25, Steve Holden wrote: > On 12/23/2010 4:34 PM, Stefan Sonnenberg-Carstens wrote: >> For large datasets I always have huge question marks if one says "xml". >> But I don't want to start a flame war. I would agree; but, you don't always have the choice over the data format that you have to work with. You just have to do the best you can with what they give you. > I agree people abuse the "spirit of XML" using it to transfer gigabytes > of data, but what else are they to use? Something with an index so that you don't have to parse the entire file would be nice. SQLite comes to mind. It is not standardized; but, the implementation is free with bindings for most languages. From martin.kaspar at campus-24.com Sat Dec 25 12:58:55 2010 From: martin.kaspar at campus-24.com (Martin Kaspar) Date: Sat, 25 Dec 2010 09:58:55 -0800 (PST) Subject: python-parser running Beautiful Soup only spits out one line of 10. What i have gotten wrong here? Message-ID: <7fa4881d-269b-46ef-a8b4-72f8a8ba9e34@i41g2000vbn.googlegroups.com> Hello dear Community,. I am trying to get a scraper up and running: And keep running into problems. when I try what you have i have learnedd so far I only get: Schuldaten Here is the code that I used: import urllib2 from BeautifulSoup import BeautifulSoup page = urllib2.urlopen("http://www.schulministerium.nrw.de/BP/ SchuleSuchen?action=799.601437941842&SchulAdresseMapDO=142323") soup = BeautifulSoup(page) table = soup.find('table' ,attrs={'class':'bp_ergebnis_tab_info'}) first_td = soup.find('td') text = first_td.renderContents() trimmed_text = text.strip() print trimmed_text i run it in the template at http://scraperwiki.com/scrapers/new/python see the target: http://www.schulministerium.nrw.de/BP/SchuleSuchen?action=799.601437941842&SchulAdresseMapDO=142323 What have I gotten wrong? Can anybody review the code - many thanks in Advance regards matze From nagle at animats.com Sat Dec 25 13:36:22 2010 From: nagle at animats.com (John Nagle) Date: Sat, 25 Dec 2010 10:36:22 -0800 Subject: python-parser running Beautiful Soup only spits out one line of 10. What i have gotten wrong here? In-Reply-To: <7fa4881d-269b-46ef-a8b4-72f8a8ba9e34@i41g2000vbn.googlegroups.com> References: <7fa4881d-269b-46ef-a8b4-72f8a8ba9e34@i41g2000vbn.googlegroups.com> Message-ID: <4d1639a0$0$44022$742ec2ed@news.sonic.net> Your program is doing what you asked it to do. It finds the first table with class 'bp_ergebnis_tab_info'. Then it ignores that results. Then it finds the first "td" item in the document, and prints the contents of that. Then it exits. What did you want it to do? Try this. It prints out the TD items on each row of the table, in order. import urllib2 from BeautifulSoup import BeautifulSoup page = urllib2.urlopen("http://www.schulministerium.nrw.de/BP/SchuleSuchen?action=799.601437941842&SchulAdresseMapDO=142323") soup = BeautifulSoup(page) table = soup.find('table' ,attrs={'class':'bp_ergebnis_tab_info'}) for row in table.findAll('tr') : # for all TR items (table rows) for td in row.findAll('td') : # for TD items in row text = td.renderContents().strip() print(text) print('-----') # mark end of row John Nagle On 12/25/2010 9:58 AM, Martin Kaspar wrote: > Hello dear Community,. > I am trying to get a scraper up and running: And keep running into > problems. > > when I try what you have i have learned so far I only get: > Schuldaten > > Here is the code that I used: > > import urllib2 > from BeautifulSoup import BeautifulSoup > page = urllib2.urlopen("http://www.schulministerium.nrw.de/BP/ > SchuleSuchen?action=799.601437941842&SchulAdresseMapDO=142323") > soup = BeautifulSoup(page) > table = soup.find('table' ,attrs={'class':'bp_ergebnis_tab_info'}) > first_td = soup.find('td') > text = first_td.renderContents() > trimmed_text = text.strip() > print trimmed_text > > > i run it in the template at http://scraperwiki.com/scrapers/new/python > > see the target: http://www.schulministerium.nrw.de/BP/SchuleSuchen?action=799.601437941842&SchulAdresseMapDO=142323 > > What have I gotten wrong? > > Can anybody review the code - > > many thanks in Advance > > regards > matze From roy at panix.com Sat Dec 25 14:16:27 2010 From: roy at panix.com (Roy Smith) Date: Sat, 25 Dec 2010 14:16:27 -0500 Subject: Keeping track of the N largest values References: Message-ID: In article , Duncan Booth wrote: > Roy Smith wrote: > > > > > I'm processing a stream of N numbers and want to keep track of the K > > largest. There's too many numbers in the stream (i.e. N is too large) > > to keep in memory at once. K is small (100 would be typical). > > ... > > Is there a better way to do this, either from a theoretical running > > time point of view, or just a nicer way to code this in Python? > > How about: > > from heapq import nlargest > top = nlargest(K, input()) > > It uses a heap so avoids completely resorting each time. Hmmm, that looks like it would solve the problem as stated, but there's another twist. In addition to finding the K largest values, I *also* need to do some other processing on all the values (which I didn't show in the original example, incorrectly thinking it not germane to my question). The problem with nlargest() is that it doesn't give me a hook to do that. PS: I'm assuming heapq.nlargest(n, iterable) operates with memory proportional to n, and not to the iterator length. That's the only reasonable conclusion, but the docs don't actually come out and say it. From roy at panix.com Sat Dec 25 14:41:29 2010 From: roy at panix.com (Roy Smith) Date: Sat, 25 Dec 2010 14:41:29 -0500 Subject: Trying to parse a HUGE(1gb) xml file References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> Message-ID: In article , Adam Tauno Williams wrote: > XML works extremely well for large datasets. Barf. I'll agree that there are some nice points to XML. It is portable. It is (to a certain extent) human readable, and in a pinch you can use standard text tools to do ad-hoc queries (i.e. grep for a particular entry). And, yes, there are plenty of toolsets for dealing with XML files. On the other hand, the verbosity is unbelievable. I'm currently working with a data feed we get from a supplier in XML. Every day we get incremental updates of about 10-50 MB each. The total data set at this point is 61 GB. It's got stuff like this in it: FALSE That's 54 bytes to store a single bit of information. I'm all for human-readable formats, but bloating the data by a factor of 432 is rather excessive. Of course, that's an extreme example. A more efficient example would be: 1173722 which is 26 bytes to store an integer. That's only a bloat factor of 6-1/2. Of course, one advantage of XML is that with so much redundant text, it compresses well. We typically see gzip compression ratios of 20:1. But, that just means you can archive them efficiently; you can't do anything useful until you unzip them. From no.email at nospam.invalid Sat Dec 25 14:41:58 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 25 Dec 2010 11:41:58 -0800 Subject: Keeping track of the N largest values References: Message-ID: <7xtyi1od15.fsf@ruckus.brouhaha.com> Roy Smith writes: >> from heapq import nlargest >> top = nlargest(K, input()) > In addition to finding the K largest values, I *also* need to do some > other processing on all the values .... The problem with nlargest() > is that it doesn't give me a hook to do that. def processed_input(): for x in input(): process(x) yield x top = nlargest(K, processed_input()) You could also write that more consisely with genexps but it's a bit clumsy. From nagle at animats.com Sat Dec 25 15:26:32 2010 From: nagle at animats.com (John Nagle) Date: Sat, 25 Dec 2010 12:26:32 -0800 Subject: Keeping track of the N largest values In-Reply-To: References: Message-ID: <4d165372$0$44038$742ec2ed@news.sonic.net> On 12/25/2010 8:04 AM, Peter Otten wrote: > Roy Smith wrote: > >> I'm processing a stream of N numbers and want to keep track of the K >> largest. There's too many numbers in the stream (i.e. N is too large) >> to keep in memory at once. K is small (100 would be typical). > > http://docs.python.org/library/heapq.html#heapq.nlargest Incidentally, if it happens that the data is already in a database, MySQL will do that. SELECT val FROM tab ORDER BY val DESC LIMIT N; will, for small N, keep only N values. For large N, it sorts. That's for an un-indexed field. If "val" is an index, this is a very fast operation, since the tree building has already been done. John Nagle From stefan.sonnenberg at pythonmeister.com Sat Dec 25 15:51:16 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Sat, 25 Dec 2010 21:51:16 +0100 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> Message-ID: <4D165944.6000801@pythonmeister.com> Am 25.12.2010 20:41, schrieb Roy Smith: > In article, > Adam Tauno Williams wrote: > >> XML works extremely well for large datasets. > Barf. I'll agree that there are some nice points to XML. It is > portable. It is (to a certain extent) human readable, and in a pinch > you can use standard text tools to do ad-hoc queries (i.e. grep for a > particular entry). And, yes, there are plenty of toolsets for dealing > with XML files. > > On the other hand, the verbosity is unbelievable. I'm currently working > with a data feed we get from a supplier in XML. Every day we get > incremental updates of about 10-50 MB each. The total data set at this > point is 61 GB. It's got stuff like this in it: > > FALSE > > That's 54 bytes to store a single bit of information. I'm all for > human-readable formats, but bloating the data by a factor of 432 is > rather excessive. Of course, that's an extreme example. A more > efficient example would be: > > 1173722 > > which is 26 bytes to store an integer. That's only a bloat factor of > 6-1/2. > > Of course, one advantage of XML is that with so much redundant text, it > compresses well. We typically see gzip compression ratios of 20:1. > But, that just means you can archive them efficiently; you can't do > anything useful until you unzip them. Sending complete SQLite databases is absolute perfect. For example Fedora uses (used?) this for their yum catalog updates. Download to the right place, point your tool to it, ready. From nobody at nowhere.com Sat Dec 25 17:34:02 2010 From: nobody at nowhere.com (Nobody) Date: Sat, 25 Dec 2010 22:34:02 +0000 Subject: Trying to parse a HUGE(1gb) xml file References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> Message-ID: On Sat, 25 Dec 2010 14:41:29 -0500, Roy Smith wrote: >> XML works extremely well for large datasets. One advantage it has over many legacy formats is that there are no inherent 2^31/2^32 limitations. Many binary formats inherently cannot support files larger than 2GiB or 4Gib due to the use of 32-bit offsets in indices. > Of course, one advantage of XML is that with so much redundant text, it > compresses well. We typically see gzip compression ratios of 20:1. > But, that just means you can archive them efficiently; you can't do > anything useful until you unzip them. XML is typically processed sequentially, so you don't need to create a decompressed copy of the file before you start processing it. If file size is that much of an issue, eventually we'll see a standard for compressing XML. This could easily result in smaller files than using a dedicated format compressed with general-purpose compression algorithms, as a widely-used format such as XML merits more effort than any application-specific format. From devplayer at gmail.com Sat Dec 25 17:41:16 2010 From: devplayer at gmail.com (DevPlayer) Date: Sat, 25 Dec 2010 14:41:16 -0800 (PST) Subject: How can a function find the function that called it? References: <87d3orvvz6.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <6d34e6ad-1273-44fa-99b7-587daf35fe8b@t35g2000yqj.googlegroups.com> > Original Poster > I thought I'd implement it as a subclass of collections.OrderedDict > that prohibits all modifications to the dictionary after it has > been initialized. I thought the __new__() method was for customizing how objects where instantated. Where in __new__() you would get an object instance and then usually initialize the public data attributes in __init__(). Although I like Mark Wooding's solution as it's clean and easy to understand. From steve+comp.lang.python at pearwood.info Sat Dec 25 17:41:49 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Dec 2010 22:41:49 GMT Subject: type(d) != type(d.copy()) when type(d).issubclass(dict) References: Message-ID: <4d16732c$0$29974$c3e8da3$5496439d@news.astraweb.com> On Sat, 25 Dec 2010 15:58:35 +0000, Duncan Booth wrote: > kj wrote: > >> Watch this: >> >>>>> class neodict(dict): pass >> ... >>>>> d = neodict() >>>>> type(d) >> >>>>> type(d.copy()) >> >> >> >> Bug? Feature? Genius beyond the grasp of schlubs like me? > > Feature. I'd say it is neither, and call it a bloody nuisance that nevertheless has some justification. > In (almost?) all cases any objects constructed by a subclass of a > builtin class will be of the original builtin class. So, for example, > subclass a string and concatenating your subclassed objects still > produces a string. Yes, and the consequence is that any serious subclass must overload every method which returns a new instance, otherwise your new subclass doesn't "stick" -- you find it being replaced by the builtin as soon as you start doing something useful with it. This is especially a nuisance for subclasses of (say) float, where you end up writing heaps of boilerplate like this: class MyFloat(float): def __add__(self, other): return self.__class__(super(MyFloat, self).__add__(other)) # and the same for __mul__, __sub__, __rsub__, __pow__, ... > This is reasonable behaviour as for builtin classes performance is more > important than fully implementing polymorphism. If you want to subclass > a builtin class you need to be aware of this and override the behaviour > where it matters. Yes, but I think builtins could probably afford one extra identity check. Something like this: # Pseudocode if type(self) is builtin type: do exactly what is done now else: do something slower, but kinder for superclasses For all I know, the slower branch might be something as simple as calling the C equivalent of type(self)(arg). -- Steven From steve+comp.lang.python at pearwood.info Sat Dec 25 17:49:08 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Dec 2010 22:49:08 GMT Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d1427ac$0$30000$c3e8da3$5496439d@news.astraweb.com> <3771d7ec-c030-4d15-a257-4c895ff57ec0@n2g2000pre.googlegroups.com> <4d1466d2$0$30000$c3e8da3$5496439d@news.astraweb.com> <4D151B52.4030502@stoneleaf.us> Message-ID: <4d1674e4$0$29974$c3e8da3$5496439d@news.astraweb.com> On Sat, 25 Dec 2010 09:17:27 -0500, Robert Kern wrote: > On 12/24/10 5:14 PM, Ethan Furman wrote: > >> There are also times when I change the exception being raised to match >> what python expects from that type of object -- for example, from >> WhatEverException to KeyError for a dict-like object. So in this regard >> I agree with Steven. > > Steven isn't arguing that particular point here, nor is anyone arguing > against it. Emphasis on *here*. You will note that in Python 3, if you raise an exception inside an except block, both the *original* and the new exception are printed. This is great for fixing bugs inside except blocks, but terribly disruptive for catching one error and raising another error in it's place, e.g.: try: x+0 except ValueError, TypeError as e: # x is not a numeric value, e.g. a string or a NAN. raise MyError('x is not a number') The explicit raise is assumed to indicate a bug in the except block, and the original exception is printed as well. But that's a separate issue from what is being discussed here. What we're discussing here is the idea that a function should be able to delegate work to private subroutines without the caller being aware of that fact. When you return a value, the caller doesn't see the internal details of how you calculated the value, but if you deliberately raise an exception, the caller does. Often this is the right thing to do, but sometimes it isn't. E.g. you can't delegate input validation to a subroutine and raise inside the subroutine without obfuscating the traceback. -- Steven From steve+comp.lang.python at pearwood.info Sat Dec 25 17:49:20 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Dec 2010 22:49:20 GMT Subject: I don't why there is no output.... References: Message-ID: <4d1674f0$0$29974$c3e8da3$5496439d@news.astraweb.com> On Fri, 24 Dec 2010 16:22:18 -0800, chad wrote: >> I don't get it. I was expecting to see the output from both the tty and >> cat. Instead, I see nothing. Why? > > Never mind. I figured it out. Well, don't keep us in suspenders. What was the problem? -- Steven From steve+comp.lang.python at pearwood.info Sat Dec 25 17:50:00 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Dec 2010 22:50:00 GMT Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d1427ac$0$30000$c3e8da3$5496439d@news.astraweb.com> <3771d7ec-c030-4d15-a257-4c895ff57ec0@n2g2000pre.googlegroups.com> <4d1466d2$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d14ebaf$0$44021$742ec2ed@news.sonic.net> Message-ID: <4d167517$0$29974$c3e8da3$5496439d@news.astraweb.com> On Fri, 24 Dec 2010 10:51:32 -0800, John Nagle wrote: > On 12/24/2010 3:24 AM, Carl Banks wrote: >> On Dec 24, 1:24 am, Steven D'Aprano> +comp.lang.pyt... at pearwood.info> wrote: > All I'm >>> suggesting is that there should be a way of reducing the boilerplate >>> needed for this idiom: >>> >>> def _validate_arg(x): >>> if x == 'bad input': return False >>> return True >>> >>> def f(arg): >>> if not _validate_arg(arg): >>> raise ValueError >>> process(arg) >>> >>> to something more natural that doesn't needlessly expose >>> implementation details that are completely irrelevant to the caller. > > How about > > raise ValueError("Bad input %s to validate_arg" % (repr(arg),)) > > You can pass arguments to most exceptions, and the content of the > exception is determined entirely by the code raising it. I know that exceptions can take arguments (usually string error messages). I was writing in short-hand. My apologies, I thought that would have been obvious :( Perhaps you have missed the context of the discussion. The context is that the called function delegates the job of validating input to a private function, which should be hidden from the caller (it's private, not part of the public API, subject to change, hidden, etc.) but tracebacks expose that information, obscuring the cause of the fault. (The fault being bad input to the public function, not an accidental bug in the private function.) > If end users are seeing uncaught tracebacks, the program is broken. Well, perhaps, but that's a separate issue. We're talking about the caller of the function seeing internal details, not the end use. -- Steven From awilliam at whitemice.org Sat Dec 25 18:29:15 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Sat, 25 Dec 2010 18:29:15 -0500 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> Message-ID: <1293319755.8800.2.camel@linux-yu4c.site> On Sat, 2010-12-25 at 22:34 +0000, Nobody wrote: > On Sat, 25 Dec 2010 14:41:29 -0500, Roy Smith wrote: > >> XML works extremely well for large datasets. > One advantage it has over many legacy formats is that there are no > inherent 2^31/2^32 limitations. Many binary formats inherently cannot > support files larger than 2GiB or 4Gib due to the use of 32-bit offsets in > indices. And what legacy format has support for code pages, namespaces, schema verification, or comments? None. > > Of course, one advantage of XML is that with so much redundant text, it > > compresses well. We typically see gzip compression ratios of 20:1. > > But, that just means you can archive them efficiently; you can't do > > anything useful until you unzip them. > XML is typically processed sequentially, so you don't need to create a > decompressed copy of the file before you start processing it. Yep. > If file size is that much of an issue, Which it isn't. > eventually we'll see a standard for > compressing XML. This could easily result in smaller files than using a > dedicated format compressed with general-purpose compression algorithms, > as a widely-used format such as XML merits more effort than any > application-specific format. Agree; and there actually already is a standard compression scheme - HTTP compression [supported by every modern web-server]; so the data is compressed at the only point where it matters [during transfer]. Again: "XML works extremely well for large datasets". From jim.hefferon at gmail.com Sat Dec 25 18:32:50 2010 From: jim.hefferon at gmail.com (Jim) Date: Sat, 25 Dec 2010 15:32:50 -0800 (PST) Subject: lxml etree question References: <98fb45fe-e4d0-49f4-a705-7923b2bfcacb@k22g2000yqh.googlegroups.com> Message-ID: On Dec 25, 5:33?am, Stefan Behnel wrote: > lxml knows about this special case, so you can write > > ? ? ? ? {http://www.w3.org/XML/1998/namespace}lang > > and lxml will take care of using the right prefix. Stefan, thank you for the software, which has helped me a great deal. I tried that exact thing, among a number of others, and it didn't work for me (I got ns0). I'll try again, this time with the understanding that it is the right one, and so perhaps I may discover some small error in what I tried. Regards, and thanks again, Jim From bc at freeuk.com Sat Dec 25 19:11:20 2010 From: bc at freeuk.com (BartC) Date: Sun, 26 Dec 2010 00:11:20 -0000 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com><4D13C04E.6070103@pythonmeister.com> Message-ID: "Adam Tauno Williams" wrote in message news:mailman.287.1293319780.6505.python-list at python.org... > On Sat, 2010-12-25 at 22:34 +0000, Nobody wrote: >> On Sat, 25 Dec 2010 14:41:29 -0500, Roy Smith wrote: >> >> XML works extremely well for large datasets. >> One advantage it has over many legacy formats is that there are no >> inherent 2^31/2^32 limitations. Many binary formats inherently cannot >> support files larger than 2GiB or 4Gib due to the use of 32-bit offsets >> in >> indices. > > And what legacy format has support for code pages, namespaces, schema > verification, or comments? None. > >> > Of course, one advantage of XML is that with so much redundant text, it >> > compresses well. We typically see gzip compression ratios of 20:1. >> > But, that just means you can archive them efficiently; you can't do >> > anything useful until you unzip them. >> XML is typically processed sequentially, so you don't need to create a >> decompressed copy of the file before you start processing it. > > Yep. > >> If file size is that much of an issue, > > Which it isn't. Only if you're prepared to squander resources that could be put to better use. XML is so redundant, anyone (even me :-) could probably spend an afternoon coming up with a compression scheme to reduce it to a fraction of it's size. It can even be an custom format, provided you also send along the few dozen lines of Python (or whatever language) needed to decompress. Although if it's done properly, it might be possible to create an XML library that works directly on the compressed format, and as a plug-in replacement for a conventional library. That will likely save time and memory. Anyway there seem to be existing schemes for binary XML, indicating some people do think it is an issue. I'm just concerned at the waste of computer power (I used to think HTML was bad, for example repeating the same long-winded font name hundreds of times over in the same document. And PDF: years ago I was sent a 1MB document for a modem; perhaps some substantial user manual for it? No, just a simple diagram showing how to plug it into the phone socket!). -- Bartc From pyhtonv at gmail.com Sat Dec 25 19:14:22 2010 From: pyhtonv at gmail.com (Varuna Seneviratna) Date: Sun, 26 Dec 2010 05:44:22 +0530 Subject: I am not able to verify the integrity of python.2.5.4.msi Message-ID: Hello there! I downloaded python msi version for Windows from http://www.python.org/download/releases/2.5.4/ .At the bottom of the page it is said that "The signatures above were generated with GnuPG using release manager Martin v. L?wis's public key which has a key id of 7D9DC8D2" according to this description I want to the page http://www.python.org/download/#pubkeys and downloaded the file http://www.dcl.hpi.uni-potsdam.de/people/loewis/mvl.asc and imported it into gpg as below D:\Python>gpg --import mvl.asc.txt > > gpg: key 7D9DC8D2: "Martin v. L?wis " not changed > > gpg: Total number processed: 1 > > gpg: unchanged: 1 > > And also I downloaded the Signature of python-2.5.4.msi from the download page http://www.python.org/download/releases/2.5.4/python-2.5.4.msi.asc But when I try to verify the integrity of the downloaded Python installation package as below > D:\Python>gpg --verify python-2.5.4.msi.asc gpg: no valid OpenPGP data found. gpg: the signature could not be verified. Please remember that the signature file (.sig or .asc) should be the first file given on the command line What am I doing wrong in this process? Please help me! Varuna -------------- next part -------------- An HTML attachment was scrubbed... URL: From usernet at ilthio.net Sat Dec 25 20:05:53 2010 From: usernet at ilthio.net (Tim Harig) Date: Sun, 26 Dec 2010 01:05:53 +0000 (UTC) Subject: Trying to parse a HUGE(1gb) xml file References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> Message-ID: On 2010-12-25, Nobody wrote: > On Sat, 25 Dec 2010 14:41:29 -0500, Roy Smith wrote: >>> XML works extremely well for large datasets. > One advantage it has over many legacy formats is that there are no > inherent 2^31/2^32 limitations. Many binary formats inherently cannot > support files larger than 2GiB or 4Gib due to the use of 32-bit offsets in > indices. That is probably true of many older and binary formats; but, XML is certainly not the the only format that supports arbitrary size. It certainly doesn't prohibit another format with better handling of large data sets from being developed. XML's primary benefit is its ubiquity. While it is an excellent format for a number of uses, I don't accept ubiquity as the only or preeminent metric when choosing a data format. >> Of course, one advantage of XML is that with so much redundant text, it >> compresses well. We typically see gzip compression ratios of 20:1. >> But, that just means you can archive them efficiently; you can't do >> anything useful until you unzip them. > > XML is typically processed sequentially, so you don't need to create a > decompressed copy of the file before you start processing it. Sometimes XML is processed sequentially. When the markup footprint is large enough it must be. Quite often, as in the case of the OP, you only want to extract a small piece out of the total data. In those cases, being forced to read all of the data sequentially is both inconvenient and and a performance penalty unless there is some way to address the data you want directly. From usernet at ilthio.net Sat Dec 25 20:13:29 2010 From: usernet at ilthio.net (Tim Harig) Date: Sun, 26 Dec 2010 01:13:29 +0000 (UTC) Subject: Trying to parse a HUGE(1gb) xml file References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> Message-ID: On 2010-12-25, Adam Tauno Williams wrote: > On Sat, 2010-12-25 at 22:34 +0000, Nobody wrote: >> On Sat, 25 Dec 2010 14:41:29 -0500, Roy Smith wrote: >> XML is typically processed sequentially, so you don't need to create a >> decompressed copy of the file before you start processing it. > > Yep. Sometimes that is true and sometimes it isn't. There are many situations where you want to access the data nonsequentially or address just a small subset of it. Just because you never want to access data randomly doesn't mean others might not. Certainly the OP would be happier using something like XPath to get just the piece of data that he is looking for. From gervaz at gmail.com Sat Dec 25 20:46:04 2010 From: gervaz at gmail.com (gervaz) Date: Sat, 25 Dec 2010 17:46:04 -0800 (PST) Subject: Signal handler & cygwin Message-ID: <55a87adf-a980-4a9f-ac41-1ebf4996cb21@o4g2000yqd.googlegroups.com> Hi all, given the followin code snippet: import signal import time import sys import os print("{0}\n".format(os.getpid())) ContinueProcessing = True def stop(signal, frame): print("\nSignal received!\n") time.sleep(1) global ContinueProcessing ContinueProcessing = False signal.signal(signal.SIGINT, stop) while ContinueProcessing: try: sys.stdout.write(".") sys.stdout.flush() time.sleep(0.1) except: continue if I kill the process using kill -s SIGINT PID in linux everything works fine and the signal is correctly handled, while in win, using cywin (/bin/kill.exe -f -s SIGINT WINPID), the program just exits without trapping the interrupt. Any similar experience? From katie at coderstack.co.uk Sat Dec 25 21:02:39 2010 From: katie at coderstack.co.uk (Katie T) Date: Sun, 26 Dec 2010 02:02:39 +0000 Subject: Python Web App In-Reply-To: <907fa80e-1814-4ddb-be32-ec14cfd53fab@29g2000yqq.googlegroups.com> References: <907fa80e-1814-4ddb-be32-ec14cfd53fab@29g2000yqq.googlegroups.com> Message-ID: On Wed, Dec 22, 2010 at 9:43 PM, Sean wrote: > Anybody know where I can find a Python Development Environment in the > form of a web app for use with Chrome OS. I have been looking for a > few days and all i have been able to find is some old discussions with > python developers talking about they will want one for the OS to be a > success with them. Your best bet is probably just to SSH to a *nix box and use something like vim or emacs. None of the web solutions are anywhere near acceptable. Katie -- CoderStack http://www.coderstack.co.uk/python-jobs The Software Developer Job Board From katie at coderstack.co.uk Sat Dec 25 21:06:13 2010 From: katie at coderstack.co.uk (Katie T) Date: Sun, 26 Dec 2010 02:06:13 +0000 Subject: Python Average Salary Report In-Reply-To: References: Message-ID: On Sat, Dec 25, 2010 at 11:38 AM, czarina08 wrote: > I'm doing a market research report on the average hourly rates for > Python/Django developers. Any input on this? I do understand that it > does depend on the location, amount of experience and skills. I'd like > to hear what are the hourly rates within your area :-) Thanks! Sector and location have a much bigger impact than language/platform on salary (although obviously demand for different languages varies by sector and location as well). Katie -- CoderStack http://www.coderstack.co.uk/python-jobs The Software Developer Job Board From research at johnohagan.com Sat Dec 25 21:40:16 2010 From: research at johnohagan.com (John O'Hagan) Date: Sun, 26 Dec 2010 02:40:16 +0000 Subject: type(d) != type(d.copy()) when type(d).issubclass(dict) In-Reply-To: <4d16732c$0$29974$c3e8da3$5496439d@news.astraweb.com> References: <4d16732c$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <201012260240.16761.research@johnohagan.com> On Sat, 25 Dec 2010, Steven D'Aprano wrote: > On Sat, 25 Dec 2010 15:58:35 +0000, Duncan Booth wrote: > > kj wrote: > >> Watch this: > >>>>> class neodict(dict): pass > >> > >> ... > >> > >>>>> d = neodict() > >>>>> type(d) > >> > >> > >> > >>>>> type(d.copy()) > >> > >> > >> > >> Bug? Feature? Genius beyond the grasp of schlubs like me? > > > > Feature. > > I'd say it is neither, and call it a bloody nuisance that nevertheless > has some justification. > > > In (almost?) all cases any objects constructed by a subclass of a > > builtin class will be of the original builtin class. So, for example, > > subclass a string and concatenating your subclassed objects still > > produces a string. > > Yes, and the consequence is that any serious subclass must overload every > method which returns a new instance, otherwise your new subclass doesn't > "stick" -- you find it being replaced by the builtin as soon as you start > doing something useful with it. > > This is especially a nuisance for subclasses of (say) float, where you > end up writing heaps of boilerplate like this: > > class MyFloat(float): > def __add__(self, other): > return self.__class__(super(MyFloat, self).__add__(other)) > # and the same for __mul__, __sub__, __rsub__, __pow__, ... [...] I've occasionally wished I could just: import builtin_subclass_fixer class MyList(list): def __init__(self): builtin_subclass_fixer.fix(self) ... ... to automatically ensure that new objects returned by MyList methods are of the same class without my having to identify and override every such method. IMO one of the benefits of subclassing is that you can just "bolt on" additional behaviour without having to know all the inner workings of the superclass, a benefit that is somewhat defeated by this behaviour of builtins. OTOH - not that I advocate nuisance as a deterrent - the nuisance factor of this has encouraged me to look harder for simpler solutions. Most of the time I've realised I didn't really need to subclass at all, and thus avoided "lazy subclassing". John From nobody at nowhere.com Sat Dec 25 21:59:10 2010 From: nobody at nowhere.com (Nobody) Date: Sun, 26 Dec 2010 02:59:10 +0000 Subject: Trying to parse a HUGE(1gb) xml file References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> Message-ID: On Sun, 26 Dec 2010 01:05:53 +0000, Tim Harig wrote: >> XML is typically processed sequentially, so you don't need to create a >> decompressed copy of the file before you start processing it. > > Sometimes XML is processed sequentially. When the markup footprint is > large enough it must be. Quite often, as in the case of the OP, you only > want to extract a small piece out of the total data. In those cases, > being forced to read all of the data sequentially is both inconvenient and > and a performance penalty unless there is some way to address the data you > want directly. Actually, I should have said "must be processed sequentially". Even if you only care about a small portion of the data, you have to read it sequentially to locate that portion. IOW, anything you can do with uncompressed XML can be done with compressed XML; you can't do random access with either. If XML has a drawback over application-specific formats, it's the sequential nature of XML rather than its (uncompressed) size. OTOH, formats designed for random access tend to be more limited in their utility. You can only perform random access based upon criteria which match the format's indexing. Once you step outside that, you often have to walk the entire file anyhow. From jude.bloom at gmail.com Sat Dec 25 22:10:23 2010 From: jude.bloom at gmail.com (Jude Bloom) Date: Sat, 25 Dec 2010 21:10:23 -0600 Subject: *** The Jew World Order - A TUTORIAL Exposition in Banking and Economics *** In-Reply-To: <76ef6b76-a823-40aa-97ea-c33ea3c822e1@g26g2000vbi.googlegroups.com> References: <76ef6b76-a823-40aa-97ea-c33ea3c822e1@g26g2000vbi.googlegroups.com> Message-ID: Why don't you take your paranoia and envy of Jews and shove it straight up your inadequate ass? On Fri, Dec 24, 2010 at 12:06 PM, small Pox wrote: -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Sat Dec 25 22:42:01 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 25 Dec 2010 22:42:01 -0500 Subject: What is the the best style and theory of writing a complier in your language In-Reply-To: <4d1449e8$0$32168$7b1e8fa0__23667.4658059657$1293175629$gmane$org@news.nbl.fi> References: <4d1449e8$0$32168$7b1e8fa0__23667.4658059657$1293175629$gmane$org@news.nbl.fi> Message-ID: On 12/24/2010 2:21 AM, Juha Nieminen wrote: > In comp.lang.c++ small Pox wrote: >> http://... > > You should take your religion somewhere else. And you should learn that by re-posting their links you assist spammers. -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From flebber.crue at gmail.com Sat Dec 25 23:43:22 2010 From: flebber.crue at gmail.com (flebber) Date: Sat, 25 Dec 2010 20:43:22 -0800 (PST) Subject: Design Ideals Goals Python 3 - Forest for the trees Message-ID: <2a7b2f17-1644-499f-848b-10291a12cc80@r19g2000prm.googlegroups.com> Hi I was hoping someone could shed some (articles, links) in regards python 3 design ideals. I was searching guido's blog which has his overarching view of Python from an early development perspective http://python-history.blogspot.com/2009/01/pythons-design-philosophy.html . I was interested in what the design goals/philosphy was of Python 3 from a birds eye view, forest for the trees approach. i can safely assume one goal was speed improvement as in the blog he noted "Don?t fret too much about performance--plan to optimize later when needed." So I assume that means that Python had developed to a point where that was needed. But performance wouldn't be the over-arching criteria for the change. Just curious. From usernet at ilthio.net Sun Dec 26 00:35:53 2010 From: usernet at ilthio.net (Tim Harig) Date: Sun, 26 Dec 2010 05:35:53 +0000 (UTC) Subject: Design Ideals Goals Python 3 - Forest for the trees References: <2a7b2f17-1644-499f-848b-10291a12cc80@r19g2000prm.googlegroups.com> Message-ID: On 2010-12-26, flebber wrote: > I was hoping someone could shed some (articles, links) in regards > python 3 design ideals. I was searching guido's blog which has his > overarching view of Python from an early development perspective > http://python-history.blogspot.com/2009/01/pythons-design-philosophy.html > . > > I was interested in what the design goals/philosphy was of Python 3 > from a birds eye view, forest for the trees approach. This is rather old; but you might watch: http://www.youtube.com/watch?v=1RjtT17WbcQ if you haven't seen it already. From alice at gothcandy.com Sun Dec 26 00:56:15 2010 From: alice at gothcandy.com (=?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=) Date: Sat, 25 Dec 2010 21:56:15 -0800 Subject: Design Ideals Goals Python 3 - Forest for the trees References: <2a7b2f17-1644-499f-848b-10291a12cc80@r19g2000prm.googlegroups.com> Message-ID: > I was interested in what the design goals/philosphy was of Python 3 > from a birds eye view, forest for the trees approach. I think I can safely point to the Zen of Python[1] as many of the points therein directly apply to the simplifiation, clarification, and goals of Python 3. Most notably: :: Beautiful is better than ugly. E.g. dict.iteritems, dict.iterkeys, dict.itervalues? Strip 'iter' and it's fixed. :: Special cases aren't special enough to break the rules. Ever get hung up on core Python modules with title caps? Yeah, those are fixed. :: There should be one-- and preferably only one --obvious way to do it. E.g. urllib, urllib2, urllibX? yeah, that's been fixed, too. :) :: Namespaces are one honking great idea -- let's do more of those! Numerous modules have been merged, or moved into more manageable (and logical) namespaces. > I can safely assume one goal was speed improvement as in the blog he > noted "Don?t fret too much about performance--plan to optimize later > when needed." So I assume that means that Python had developed to a > point where that was needed. The Python GIL (Global Interpreter Lock) has been getting a lot of negative attention over the last little while, and was recently fixed to be far more intelligent (and efficient) in Python 3.2. There are numerous other performance improvements, for which yo ucan examine the change logs. > But performance wouldn't be the over-arching criteria for the change. > Just curious. Clarification, simplification, specivity, efficiency, ? just be more "Pythonic". Note that I'm not a core Python contributor or have ever communicated with the BDFL: this is just the viewpoint of somoene doing her darnd'est to encourage Python 3 support. ;) All of the new projects I work on are Python 2.6+ and Python 3.1+ compatible. (Arguments against dual-compatible polygot code can go to /dev/null for the purposes of this thread.) - Alice [1] http://www.python.org/dev/peps/pep-0020/ From flebber.crue at gmail.com Sun Dec 26 01:22:27 2010 From: flebber.crue at gmail.com (flebber) Date: Sat, 25 Dec 2010 22:22:27 -0800 (PST) Subject: Design Ideals Goals Python 3 - Forest for the trees References: <2a7b2f17-1644-499f-848b-10291a12cc80@r19g2000prm.googlegroups.com> Message-ID: On Dec 26, 4:56?pm, Alice Bevan?McGregor wrote: > > I was interested in what the design goals/philosphy was of Python 3 > > from a birds eye view, forest for the trees approach. > > I think I can safely point to the Zen of Python[1] as many of the > points therein directly apply to the simplifiation, clarification, and > goals of Python 3. ?Most notably: > > :: Beautiful is better than ugly. > > E.g. dict.iteritems, dict.iterkeys, dict.itervalues? ?Strip 'iter' and > it's fixed. > > :: Special cases aren't special enough to break the rules. > > Ever get hung up on core Python modules with title caps? ?Yeah, those > are fixed. > > :: There should be one-- and preferably only one --obvious way to do it. > > E.g. urllib, urllib2, urllibX? yeah, that's been fixed, too. ?:) > > :: Namespaces are one honking great idea -- let's do more of those! > > Numerous modules have been merged, or moved into more manageable (and > logical) namespaces. > > > I can safely assume one goal was speed improvement as in the blog he > > noted "Don?t fret too much about performance--plan to optimize later > > when needed." So I assume that means that Python had developed to a > > point where that was needed. > > The Python GIL (Global Interpreter Lock) has been getting a lot of > negative attention over the last little while, and was recently fixed > to be far more intelligent (and efficient) in Python 3.2. ?There are > numerous other performance improvements, for which yo ucan examine the > change logs. > > > But performance wouldn't be the over-arching criteria for the change. > > Just curious. > > Clarification, simplification, specivity, efficiency, ? just be more > "Pythonic". > > Note that I'm not a core Python contributor or have ever communicated > with the BDFL: this is just the viewpoint of somoene doing her > darnd'est to encourage Python 3 support. ?;) ?All of the new projects I > work on are Python 2.6+ and Python 3.1+ compatible. ?(Arguments against > dual-compatible polygot code can go to /dev/null for the purposes of > this thread.) > > ? ? ? ? - Alice > > [1]http://www.python.org/dev/peps/pep-0020/ So do the new changes(to the GIL) nullify concerns raised by David Beazely here http://dabeaz.com/python/UnderstandingGIL.pdf Some projects have been using and requiring psyco to gain speed improvements in python http://psyco.sourceforge.net/introduction.html however it seems that the developer is not active on this project anymore and is more active on PyPy http://codespeak.net/pypy/dist/pypy/doc/ A program such as AVSP http://avisynth.org/qwerpoi/ which relies on psyco what would be a good proposition to use when taking the project to python 3.0 if psyco will remain unavailable? From pavlovevidence at gmail.com Sun Dec 26 02:59:32 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 25 Dec 2010 23:59:32 -0800 (PST) Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d1427ac$0$30000$c3e8da3$5496439d@news.astraweb.com> <3771d7ec-c030-4d15-a257-4c895ff57ec0@n2g2000pre.googlegroups.com> <4d1466d2$0$30000$c3e8da3$5496439d@news.astraweb.com> <4D151B52.4030502@stoneleaf.us> <4d1674e4$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Dec 25, 2:49?pm, Steven D'Aprano wrote: > But that's a separate issue from what is being discussed here. What we're > discussing here is the idea that a function should be able to delegate > work to private subroutines without the caller being aware of that fact. I can't fathom any possible reason why this could be considered a good thing, especially in Python where the culture is, "We're all adults here". By the same logic, it would be a good idea to prevent the user from accessing private members of a class, internal variables of a module, or importing an internal module directly. There is a convention in Python: internal objects are preceded by underscore. The fact that your internal function is marked this way in the traceback is more than enough information to the user that this is an internal function. Python is not, and never has been, about hiding internal details. It's about openness, and there's no reason a traceback should hide internal details any more than a class should--in fact hiding information in the traceback is far worse, because you're suppressing information that could be crucial for debugging. Carl Banks From pavlovevidence at gmail.com Sun Dec 26 03:01:56 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 26 Dec 2010 00:01:56 -0800 (PST) Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d1427ac$0$30000$c3e8da3$5496439d@news.astraweb.com> <3771d7ec-c030-4d15-a257-4c895ff57ec0@n2g2000pre.googlegroups.com> <4d1466d2$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8b9831a9-18d5-4e65-8f66-2e1a8ba5518a@i32g2000pri.googlegroups.com> On Dec 25, 6:21?am, Robert Kern wrote: > On 12/24/10 4:24 AM, Steven D'Aprano wrote: > > > On Thu, 23 Dec 2010 22:38:05 -0800, Carl Banks wrote: > >> OTOH, going the extra mile to hide useful information from a user is > >> asinine. As a user, I will decide for myself how I want to use > >> implementation-defined information, and I don't want the implementor to > >> decide this for me. It's bad enough if an implementor fails to provide > >> information out of laziness, but when they deliberately do extra work to > >> hide information, that's self-importance and arrogance. > > > But that of course is nonsense, because as the user you don't decide > > anything of the sort. The developer responsible for writing the function > > decides what information he provides you, starting with whether you get > > an exception at all, where it comes from, the type of exception, and the > > error message (if any). > > Carl isn't arguing that the user is or should be responsible for this sort of > thing. He is arguing that developers should be responsible for doing this in > such a way that is beneficial for the developer/user down the road. I'm not even arguing that; I think I would be content if the developer merely doesn't actively work to harm the user. Carl Banks From pavlovevidence at gmail.com Sun Dec 26 03:21:33 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 26 Dec 2010 00:21:33 -0800 (PST) Subject: lxml etree question References: <98fb45fe-e4d0-49f4-a705-7923b2bfcacb@k22g2000yqh.googlegroups.com> Message-ID: On Dec 24, 10:17?am, Adam Tauno Williams wrote: > On Fri, 2010-12-24 at 20:48 +0530, Nitin Pawar wrote: > > On Fri, Dec 24, 2010 at 8:40 PM, Jim wrote: > > ? ? ? ? Hello, ?I wonder if someone knows about lxml.etree and > > ? ? ? ? namespaces? > > Yes, and don't. He's using lxml.etree (which is a third-party library that mimics ElementTree's interface), not ElementTree. Were you aware of this? > > I want to build an ElementTree where some of the sub-elements have > > attributes that serialize this way. > > .. > > I've tried just comment_elet.set('xml:lang','de') and it didn't like > > that at all (although it takes comment_elet.set('auth:id','jones') > > just fine). ?I've also spelunked the docs and googled but have not hit > > on the right invocation. ?If someone knows, I'd be grateful. > > I'd *strongly* recommend using ElementFlow for building XML documents > (over ElementTree), especially if namespaces are involved. ?ElementFlow > is far more intuitive. > I'd have to disagree with the use of strong recommendation here. The library you recommended isn't a general replacement for lxml (or ElementTree), and you didn't qualify the conditions for when it is a suitable alternative. A. What if he needed to keep the tree in memory? B. This library builds the tags with "with" statements, which could be convenient for xml files with rigid structure, but I would think it'd be inconvenient if the format were relatively loose. If you're going to recommend a more specialized solution, you should also give the conditions for which it is suitable. Carl Banks From stefan_ml at behnel.de Sun Dec 26 03:32:04 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 26 Dec 2010 09:32:04 +0100 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> Message-ID: Tim Harig, 26.12.2010 02:05: > On 2010-12-25, Nobody wrote: >> On Sat, 25 Dec 2010 14:41:29 -0500, Roy Smith wrote: >>> Of course, one advantage of XML is that with so much redundant text, it >>> compresses well. We typically see gzip compression ratios of 20:1. >>> But, that just means you can archive them efficiently; you can't do >>> anything useful until you unzip them. >> >> XML is typically processed sequentially, so you don't need to create a >> decompressed copy of the file before you start processing it. > > Sometimes XML is processed sequentially. When the markup footprint is > large enough it must be. Quite often, as in the case of the OP, you only > want to extract a small piece out of the total data. In those cases, being > forced to read all of the data sequentially is both inconvenient and and a > performance penalty unless there is some way to address the data you want > directly. So what? If you only have to do that once, it doesn't matter if you have to read the whole file or just a part of it. Should make a difference of a couple of minutes. If you do it a lot, you will have to find a way to make the access efficient for your specific use case. So the file format doesn't matter either, because the data will most likely end up in a fast data base after reading it in sequentially *once*, just as in the case above. I really don't think there are many important use cases where you need fast random access to large data sets and cannot afford to adapt the storage layout before hand. Stefan From usernet at ilthio.net Sun Dec 26 04:01:54 2010 From: usernet at ilthio.net (Tim Harig) Date: Sun, 26 Dec 2010 09:01:54 +0000 (UTC) Subject: Trying to parse a HUGE(1gb) xml file References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> Message-ID: On 2010-12-26, Nobody wrote: > On Sun, 26 Dec 2010 01:05:53 +0000, Tim Harig wrote: > >>> XML is typically processed sequentially, so you don't need to create a >>> decompressed copy of the file before you start processing it. >> >> Sometimes XML is processed sequentially. When the markup footprint is >> large enough it must be. Quite often, as in the case of the OP, you only >> want to extract a small piece out of the total data. In those cases, >> being forced to read all of the data sequentially is both inconvenient and >> and a performance penalty unless there is some way to address the data you >> want directly. > > OTOH, formats designed for random access tend to be more limited in their > utility. You can only perform random access based upon criteria which > match the format's indexing. Once you step outside that, you often have to > walk the entire file anyhow. That may be true and it may not. Even assuming that you have to walk through a large number of top level elements there may be an advantage to being able to directly access the next element as opposed to having to parse through the entire current element once you have determined it isn't one which you are looking for. To be fair, this may be invalid preoptimization without taking into account how the hard drive buffers; but, I would suspect that there is a threshold where the amount of data skipped starts to outweigh the penalty of overreaching the hard drives buffers. From usernet at ilthio.net Sun Dec 26 04:22:10 2010 From: usernet at ilthio.net (Tim Harig) Date: Sun, 26 Dec 2010 09:22:10 +0000 (UTC) Subject: Trying to parse a HUGE(1gb) xml file References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> Message-ID: On 2010-12-26, Stefan Behnel wrote: > Tim Harig, 26.12.2010 02:05: >> On 2010-12-25, Nobody wrote: >>> On Sat, 25 Dec 2010 14:41:29 -0500, Roy Smith wrote: >>>> Of course, one advantage of XML is that with so much redundant text, it >>>> compresses well. We typically see gzip compression ratios of 20:1. >>>> But, that just means you can archive them efficiently; you can't do >>>> anything useful until you unzip them. >>> >>> XML is typically processed sequentially, so you don't need to create a >>> decompressed copy of the file before you start processing it. >> >> Sometimes XML is processed sequentially. When the markup footprint is >> large enough it must be. Quite often, as in the case of the OP, you only >> want to extract a small piece out of the total data. In those cases, being >> forced to read all of the data sequentially is both inconvenient and and a >> performance penalty unless there is some way to address the data you want >> directly. > > So what? If you only have to do that once, it doesn't matter if you have to > read the whole file or just a part of it. Should make a difference of a > couple of minutes. Much agreed. I assume that the process needs to be repeated or it probably would be simpler just to rip out what I wanted using regular expressions with shell utilities. > If you do it a lot, you will have to find a way to make the access > efficient for your specific use case. So the file format doesn't matter > either, because the data will most likely end up in a fast data base after > reading it in sequentially *once*, just as in the case above. If the data is just going to end up in a database anyway; then why not send it as a database to begin with and save the trouble of having to convert it? From alice at gothcandy.com Sun Dec 26 04:34:21 2010 From: alice at gothcandy.com (=?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=) Date: Sun, 26 Dec 2010 01:34:21 -0800 Subject: Design Ideals Goals Python 3 - Forest for the trees References: Message-ID: > So do the new changes(to the GIL) nullify concerns raised by David > Beazely here http://dabeaz.com/python/UnderstandingGIL.pdf Ah, good catch. I had watched the recorded presentation some time ago. Yes, the rewritten GIL should alleviate those problems. Instead of simply releasing and re-acquiring the GIL, it releases, then determines thread scheduling using the brainfuck algorithm instead of leaving it up to the kernel in the brief instant the GIL is unassigned (which often doesn't context switch to another thread, thus the performance penalty). (I beleive that algorithm, whose name -is- accurate, was the winner of the long, long discussion on the Python ticket.) > Some projects have been using and requiring psyco to gain speed > improvements in python http://psyco.sourceforge.net/introduction.html > however it seems that the developer is not active on this project > anymore and is more active on PyPy > http://codespeak.net/pypy/dist/pypy/doc/ I've never really attempted to use JIT optimizers due to the fact that all of my development and production environments are 64-bit, and I haven't found one yet that supports 64-bit properly. Relying on dead projects, however, is an issue of larger scope than mere portability. ;) > A program such as AVSP http://avisynth.org/qwerpoi/ which relies on > psyco what would be a good proposition to use when taking the project > to python 3.0 if psyco will remain unavailable? I'd take the same approach Python 3 itself did; rewrite it for Python 3 and take the opportunity to remove excessive backwards compatibility cruft, streamline algorithms, etc. With a suite of existing unit/functional tests, that possibility is the ultimate in test-driven development. ;) It would also follow the write clean code, then profile and optimize where actually needed philosophy. Obviously that recommendation won't be the "best" solution for every project. With all of the FOSS projects I really, really care about I'm writing from near-scratch (the code, if not the algorithms) with 2.6+ and 3.1+ polygot (no conversion tools like 2to3, and no split packaging) compatibility as a primary design goal. So far it's working out quite well. - Alice From hpj at urpla.net Sun Dec 26 04:41:06 2010 From: hpj at urpla.net (Hans-Peter Jansen) Date: Sun, 26 Dec 2010 10:41:06 +0100 Subject: GUI Tools for Python 3.1 In-Reply-To: References: Message-ID: <201012261041.07130.hpj@urpla.net> On Friday 24 December 2010, 03:58:15 Randy Given wrote: > Lots of stuff for 2.6 and 2.7 -- what GUI tools are there for 3.1? PyQt4 of course. http://www.riverbankcomputing.com Pete From stefan_ml at behnel.de Sun Dec 26 04:44:35 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 26 Dec 2010 10:44:35 +0100 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> Message-ID: Tim Harig, 26.12.2010 10:22: > On 2010-12-26, Stefan Behnel wrote: >> Tim Harig, 26.12.2010 02:05: >>> On 2010-12-25, Nobody wrote: >>>> On Sat, 25 Dec 2010 14:41:29 -0500, Roy Smith wrote: >>>>> Of course, one advantage of XML is that with so much redundant text, it >>>>> compresses well. We typically see gzip compression ratios of 20:1. >>>>> But, that just means you can archive them efficiently; you can't do >>>>> anything useful until you unzip them. >>>> >>>> XML is typically processed sequentially, so you don't need to create a >>>> decompressed copy of the file before you start processing it. >>> >>> Sometimes XML is processed sequentially. When the markup footprint is >>> large enough it must be. Quite often, as in the case of the OP, you only >>> want to extract a small piece out of the total data. In those cases, being >>> forced to read all of the data sequentially is both inconvenient and and a >>> performance penalty unless there is some way to address the data you want >>> directly. >> [...] >> If you do it a lot, you will have to find a way to make the access >> efficient for your specific use case. So the file format doesn't matter >> either, because the data will most likely end up in a fast data base after >> reading it in sequentially *once*, just as in the case above. > > If the data is just going to end up in a database anyway; then why not > send it as a database to begin with and save the trouble of having to > convert it? I don't think anyone would object to using a native format when copying data from one database 1:1 to another one. But if the database formats are different on both sides, it's a lot easier to map XML formatted data to a given schema than to map a SQL dump, for example. Matter of use cases, not of data size. Stefan From __peter__ at web.de Sun Dec 26 05:36:40 2010 From: __peter__ at web.de (Peter Otten) Date: Sun, 26 Dec 2010 11:36:40 +0100 Subject: Keeping track of the N largest values References: Message-ID: Roy Smith wrote: > In article , > Duncan Booth wrote: > >> Roy Smith wrote: >> >> > >> > I'm processing a stream of N numbers and want to keep track of the K >> > largest. There's too many numbers in the stream (i.e. N is too large) >> > to keep in memory at once. K is small (100 would be typical). >> > ... >> > Is there a better way to do this, either from a theoretical running >> > time point of view, or just a nicer way to code this in Python? >> >> How about: >> >> from heapq import nlargest >> top = nlargest(K, input()) >> >> It uses a heap so avoids completely resorting each time. > > Hmmm, that looks like it would solve the problem as stated, but there's > another twist. In addition to finding the K largest values, I *also* > need to do some other processing on all the values (which I didn't show > in the original example, incorrectly thinking it not germane to my > question). The problem with nlargest() is that it doesn't give me a > hook to do that. If Paul's solution doesn't suffice -- the heapq module has the building blocks for a custom solution, e. g.: import heapq from functools import partial class NLargest(object): def __init__(self, n): self.n = n self.heap = [] def tally(self, item): heap = self.heap if len(heap) >= self.n: heapq.heappushpop(heap, item) self.tally = partial(heapq.heappushpop, heap) else: heapq.heappush(heap, item) def __str__(self): return str(sorted(self.heap, reverse=True)) if __name__ == "__main__": import random items = range(100) random.shuffle(items) accu = NLargest(10) for item in items: accu.tally(item) print item, accu > PS: I'm assuming heapq.nlargest(n, iterable) operates with memory > proportional to n, and not to the iterator length. That's the only > reasonable conclusion, but the docs don't actually come out and say it. I would hope so. From n00m at narod.ru Sun Dec 26 08:56:14 2010 From: n00m at narod.ru (n00m) Date: Sun, 26 Dec 2010 05:56:14 -0800 (PST) Subject: Keeping track of the N largest values References: Message-ID: from bisect import insort_left K = 5 top = [] while 1: x = input() if len(top) < K: insort_left(top, x) elif x > top[0]: del top[0] insort_left(top, x) print top will be enough From calderone.jeanpaul at gmail.com Sun Dec 26 09:44:34 2010 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Sun, 26 Dec 2010 06:44:34 -0800 (PST) Subject: Design Ideals Goals Python 3 - Forest for the trees References: Message-ID: On Dec 26, 5:34?am, Alice Bevan?McGregor wrote: > > I've never really attempted to use JIT optimizers due to the fact that > all of my development and production environments are 64-bit, and I > haven't found one yet that supports 64-bit properly. ?Relying on dead > projects, however, is an issue of larger scope than mere portability. ? > ;) > The PyPy JIT supports x86_64. It's still being improved, but it does provide real speedups in some cases already. Jean-Paul From roy at panix.com Sun Dec 26 10:12:33 2010 From: roy at panix.com (Roy Smith) Date: Sun, 26 Dec 2010 10:12:33 -0500 Subject: Keeping track of the N largest values References: Message-ID: In article , n00m wrote: > from bisect import insort_left > > K = 5 > top = [] > while 1: > x = input() > if len(top) < K: > insort_left(top, x) > elif x > top[0]: > del top[0] > insort_left(top, x) > print top > > > will be enough Hmmm, that's an interesting idea. Thanks. From ethan at stoneleaf.us Sun Dec 26 12:04:21 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 26 Dec 2010 09:04:21 -0800 Subject: How to pop the interpreter's stack? In-Reply-To: References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d1427ac$0$30000$c3e8da3$5496439d@news.astraweb.com> <3771d7ec-c030-4d15-a257-4c895ff57ec0@n2g2000pre.googlegroups.com> <4d1466d2$0$30000$c3e8da3$5496439d@news.astraweb.com> <4D151B52.4030502@stoneleaf.us> <4d1674e4$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4D177595.4060208@stoneleaf.us> Carl Banks wrote: > Python is not, and never has been, about hiding internal details. > It's about openness, and there's no reason a traceback should hide > internal details any more than a class should--in fact hiding > information in the traceback is far worse, because you're suppressing > information that could be crucial for debugging. +100 ~Ethan~ From ethan at stoneleaf.us Sun Dec 26 12:08:08 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 26 Dec 2010 09:08:08 -0800 Subject: How to pop the interpreter's stack? In-Reply-To: <4d1674e4$0$29974$c3e8da3$5496439d@news.astraweb.com> References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d1427ac$0$30000$c3e8da3$5496439d@news.astraweb.com> <3771d7ec-c030-4d15-a257-4c895ff57ec0@n2g2000pre.googlegroups.com> <4d1466d2$0$30000$c3e8da3$5496439d@news.astraweb.com> <4D151B52.4030502@stoneleaf.us> <4d1674e4$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4D177678.3050400@stoneleaf.us> Steven D'Aprano wrote: > On Sat, 25 Dec 2010 09:17:27 -0500, Robert Kern wrote: > >> On 12/24/10 5:14 PM, Ethan Furman wrote: >> >>> There are also times when I change the exception being raised to match >>> what python expects from that type of object -- for example, from >>> WhatEverException to KeyError for a dict-like object. So in this regard >>> I agree with Steven. >> Steven isn't arguing that particular point here, nor is anyone arguing >> against it. > > Emphasis on *here*. > > You will note that in Python 3, if you raise an exception inside an > except block, both the *original* and the new exception are printed. This > is great for fixing bugs inside except blocks, but terribly disruptive > for catching one error and raising another error in it's place... Yes, this is where I was agreeing with Steven. While I love python3, the current nested exception behavior is horrible. ~Ethan~ From ethan at stoneleaf.us Sun Dec 26 12:15:32 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 26 Dec 2010 09:15:32 -0800 Subject: How to pop the interpreter's stack? In-Reply-To: <4d0aafdb$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <4d0aafdb$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4D177834.9070901@stoneleaf.us> Steven D'Aprano wrote: > Right. But I have thought of a clever trick to get the result KJ was > asking for, with the minimum of boilerplate code. Instead of this: > > > def _pre_spam(args): > if condition(args): > raise SomeException("message") > if another_condition(args): > raise AnotherException("message") > if third_condition(args): > raise ThirdException("message") > > def spam(args): > _pre_spam(args) > do_useful_work() > > > you can return the exceptions instead of raising them (exceptions are > just objects, like everything else!), and then add one small piece of > boilerplate to the spam() function: > > > def _pre_spam(args): > if condition(args): > return SomeException("message") > if another_condition(args): > return AnotherException("message") > if third_condition(args): > return ThirdException("message") > > def spam(args): > exc = _pre_spam(args) > if exc: raise exc > do_useful_work() -1 You failed to mention that cleverness is not a prime requisite of the python programmer -- in fact, it's usually frowned upon. The big problem with the above code is you are back to passing errors in-band, pretty much completely defeating the point of have an out-of-band channel. ~Ethan~ From no.email at please.post Sun Dec 26 12:53:17 2010 From: no.email at please.post (kj) Date: Sun, 26 Dec 2010 17:53:17 +0000 (UTC) Subject: __delitem__ "feature" Message-ID: When I execute this file: #---------------------------------------------------------------------- def nodelfactory(klass): class nodel(klass): def _delitem(self, _): raise TypeError("can't delete") # __delitem__ = _delitem def __init__(self, *a, **k): klass.__init__(self, *a, **k) self.__delitem__ = self._delitem nodel.__name__ = 'nodel%s' % klass.__name__ return nodel if __name__ == '__main__': import traceback as tb d = nodelfactory(dict)([('k1', 'v1'), ('k2', 'v2')]) try: d.__delitem__('k1') except TypeError: tb.print_exc() print d try: del d['k1'] except TypeError: tb.print_exc() print d l = nodelfactory(list)([1, 2, 3, 4]) try: l.__delitem__(0) except TypeError: tb.print_exc() print l try: del l[0] except TypeError: tb.print_exc() print l #---------------------------------------------------------------------- ...the output I get is: Traceback (most recent call last): File "/tmp/delbug.py", line 20, in try: d.__delitem__('k1') File "/tmp/delbug.py", line 4, in _delitem raise TypeError("can't delete") TypeError: can't delete {'k2': 'v2', 'k1': 'v1'} {'k2': 'v2'} Traceback (most recent call last): File "/tmp/delbug.py", line 30, in try: l.__delitem__(0) File "/tmp/delbug.py", line 4, in _delitem raise TypeError("can't delete") TypeError: can't delete [1, 2, 3, 4] [2, 3, 4] It means that, for both subclasses, del fails to trigger the dynamically installed instance method __delitem__. If I replace dict with UserDict, *both* deletion attempts lead to a call to the dynamic __delitem__ method, and are thus blocked. This is the behavior I expected of dict (and will help me hold on to my belief that I'm not going insane when inevitably I'm told that there's no bug in dict or list). Interestingly enough, if I replace list with UserList, I see no change in behavior. So maybe I am going insane after all. ~kj P.S. If you uncomment the commented-out line, and comment out the last line of the __init__ method (which installs self._delitem as self.__delitem__) then *all* the deletion attempts invoke the __delitem__ method, and are therefore blocked. FWIW. From ian.g.kelly at gmail.com Sun Dec 26 13:10:27 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 26 Dec 2010 11:10:27 -0700 Subject: __delitem__ "feature" In-Reply-To: References: Message-ID: On 12/26/2010 10:53 AM, kj wrote: > P.S. If you uncomment the commented-out line, and comment out the > last line of the __init__ method (which installs self._delitem as > self.__delitem__) then *all* the deletion attempts invoke the > __delitem__ method, and are therefore blocked. FWIW. Because subclasses of builtins only check the class __dict__ for special method overrides, not the instance __dict__. From franapoli at gmail.com Sun Dec 26 13:24:19 2010 From: franapoli at gmail.com (Ciccio) Date: Sun, 26 Dec 2010 10:24:19 -0800 (PST) Subject: inspect.getsource bug? Message-ID: Try this: 1) define a function 'foo' in a script 2) runfile the script from a shell 3) do 'inspect.getsource(foo)' 4) change the source of 'foo' 5) runfile the script from the same shell 6) do 3 again On my 2.6.6 getsource returns twice the same code. I couldn't find very much about this, is there any known workaround? thanks From lists at cheimes.de Sun Dec 26 13:30:23 2010 From: lists at cheimes.de (Christian Heimes) Date: Sun, 26 Dec 2010 19:30:23 +0100 Subject: __delitem__ "feature" In-Reply-To: References: Message-ID: Am 26.12.2010 18:53, schrieb kj: > It means that, for both subclasses, del fails to trigger the > dynamically installed instance method __delitem__. Magic methods like __delitem__ are looked up on the type, not on the instance. You can't change the behaviour on instances. > If I replace dict with UserDict, *both* deletion attempts lead to > a call to the dynamic __delitem__ method, and are thus blocked. > This is the behavior I expected of dict (and will help me hold on > to my belief that I'm not going insane when inevitably I'm told > that there's no bug in dict or list). UserDict is an old style class (not a subclass of object). Old style classes behave differently. Christian From no.email at please.post Sun Dec 26 13:37:44 2010 From: no.email at please.post (kj) Date: Sun, 26 Dec 2010 18:37:44 +0000 (UTC) Subject: type(d) != type(d.copy()) when type(d).issubclass(dict) References: <4d16732c$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: "John O'Hagan" writes: >IMO one of the benefits of subclassing is that you can just "bolt on" >additional behaviour without having to know all the inner workings of the >superclass, a benefit that is somewhat defeated by this behaviour of builtins. I agree. I've read the old post/articles by GvR and other over how great it will be now that one can subclass Python builtin types like any other class (GvR even gives explicit examples of this luscious possibility in his paper on type/class unification). But now I'm discovering so many caveats, exceptions, and gotchas about subclassing builtins that I have to conclude that this much celebrated new capability is basically useless... Just like "readability counts", it is also true that "conceptual clarity" counts, and treating builtins as classes in Python is the most obfuscated design I've ever seen. UserDict, come back, all is forgotten! ~kj From no.email at please.post Sun Dec 26 13:48:12 2010 From: no.email at please.post (kj) Date: Sun, 26 Dec 2010 18:48:12 +0000 (UTC) Subject: type(d) != type(d.copy()) when type(d).issubclass(dict) References: Message-ID: In Duncan Booth writes: >kj wrote: >> Watch this: >> >>>>> class neodict(dict): pass >> ... >>>>> d = neodict() >>>>> type(d) >> >>>>> type(d.copy()) >> >> >> >> Bug? Feature? Genius beyond the grasp of schlubs like me? >Feature. >In (almost?) all cases any objects constructed by a subclass of a builtin >class will be of the original builtin class. What I *really* would like to know is: how do *you* know this (and the same question goes for the other responders who see this behavior of dict as par for the course). Can you show me where it is in the documentation? I'd really appreciate it. TIA! ~kj From no.email at please.post Sun Dec 26 13:49:55 2010 From: no.email at please.post (kj) Date: Sun, 26 Dec 2010 18:49:55 +0000 (UTC) Subject: __delitem__ "feature" References: Message-ID: In Ian Kelly writes: >On 12/26/2010 10:53 AM, kj wrote: >> P.S. If you uncomment the commented-out line, and comment out the >> last line of the __init__ method (which installs self._delitem as >> self.__delitem__) then *all* the deletion attempts invoke the >> __delitem__ method, and are therefore blocked. FWIW. >Because subclasses of builtins only check the class __dict__ for special >method overrides, not the instance __dict__. How do you know this? Is this documented? Or is this a case of Monday-night quarterbacking? ~kj From stefan.sonnenberg at pythonmeister.com Sun Dec 26 13:51:50 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Sun, 26 Dec 2010 19:51:50 +0100 Subject: Keeping track of the N largest values In-Reply-To: References: Message-ID: <4D178EC6.6010205@pythonmeister.com> Am 25.12.2010 16:42, schrieb Roy Smith: > I'm processing a stream of N numbers and want to keep track of the K > largest. There's too many numbers in the stream (i.e. N is too large) > to keep in memory at once. K is small (100 would be typical). > > > From a theoretical point of view, I should be able to do this in N log K > time. What I'm doing now is essentially: > > top = [-1] # Assume all x are>= 0 > for x in input(): > if x<= top[0]: > continue > top.append(x) > if len(top)> K: > top.sort() > top.pop(0) > > I can see pathological cases (say, all input values the same) where > running time would be N K log K, but on average (N>> K and random > distribution of values), this should be pretty close to N. > > Is there a better way to do this, either from a theoretical running time > point of view, or just a nicer way to code this in Python? Here is my version: l = [] K = 10 while 1: a = input() if len(l) == K: l.remove(min(l)) l=[x for x in l if x < a] + [a] + [x for x in l if x > a] print l From no.email at please.post Sun Dec 26 14:09:34 2010 From: no.email at please.post (kj) Date: Sun, 26 Dec 2010 19:09:34 +0000 (UTC) Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d1427ac$0$30000$c3e8da3$5496439d@news.astraweb.com> <3771d7ec-c030-4d15-a257-4c895ff57ec0@n2g2000pre.googlegroups.com> <4d1466d2$0$30000$c3e8da3$5496439d@news.astraweb.com> In writes: >Except that the *caller* never gets the traceback (unless if it deliberately >inspects the stack for some metaprogramming reason). It gets the exception, and >that is the same no matter what you do. The developer/user gets the traceback, >and those implementation details *are* often important to them. Just look at what Python shows you if you pass the wrong number of arguments to a function: >>> def spam(x, y, z): pass ... >>> spam(1, 2) Traceback (most recent call last): File "", line 1, in TypeError: spam() takes exactly 3 arguments (2 given) That's it. The traceback stops at the point of the error. Python doesn't show you all the underlying C-coded machinery that went into detecting the error and emitting the error message. *No one* needs this information at this point. All I'm saying is that I want to do the same thing with my argument validation code as Python does with its argument validation code: keep it out of sight. When my argument validation code fires an exception ***there's no bug in **my** code***. It's doing exactly what it's supposed to do. Therefore, there's no need for me to debug anything, and certainly no need for me to inspect the traceback all the way to the exception. The bug is in the code that called my function with the wrong arguments. The developer of that code has no more use for seeing the traceback all the way to where my code raises the exception than I have for seeing the traceback of Python's underlying C code when I get an error like the one shown above. ~kj From no.email at please.post Sun Dec 26 14:14:42 2010 From: no.email at please.post (kj) Date: Sun, 26 Dec 2010 19:14:42 +0000 (UTC) Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <4d0aafdb$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: In Ethan Furman writes: >You failed to mention that cleverness is not a prime requisite of the >python programmer -- in fact, it's usually frowned upon. That's the party line, anyway. I no longer believe it. I've been crashing against one bit of cleverness after another in Python's unification of types and classes... From nagle at animats.com Sun Dec 26 14:15:37 2010 From: nagle at animats.com (John Nagle) Date: Sun, 26 Dec 2010 11:15:37 -0800 Subject: How to pop the interpreter's stack? In-Reply-To: <4d167517$0$29974$c3e8da3$5496439d@news.astraweb.com> References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d1427ac$0$30000$c3e8da3$5496439d@news.astraweb.com> <3771d7ec-c030-4d15-a257-4c895ff57ec0@n2g2000pre.googlegroups.com> <4d1466d2$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d14ebaf$0$44021$742ec2ed@news.sonic.net> <4d167517$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4d179459$0$43981$742ec2ed@news.sonic.net> On 12/25/2010 2:50 PM, Steven D'Aprano wrote: > On Fri, 24 Dec 2010 10:51:32 -0800, John Nagle wrote: > >> On 12/24/2010 3:24 AM, Carl Banks wrote: >>> On Dec 24, 1:24 am, Steven D'Aprano>> +comp.lang.pyt... at pearwood.info> wrote: >> All I'm >>>> suggesting is that there should be a way of reducing the boilerplate >>>> needed for this idiom: >>>> >>>> def _validate_arg(x): >>>> if x == 'bad input': return False >>>> return True >>>> >>>> def f(arg): >>>> if not _validate_arg(arg): >>>> raise ValueError >>>> process(arg) >>>> >>>> to something more natural that doesn't needlessly expose >>>> implementation details that are completely irrelevant to the caller. >> >> How about >> >> raise ValueError("Bad input %s to validate_arg" % (repr(arg),)) >> >> You can pass arguments to most exceptions, and the content of the >> exception is determined entirely by the code raising it. > > I know that exceptions can take arguments (usually string error > messages). I was writing in short-hand. My apologies, I thought that > would have been obvious :( > > Perhaps you have missed the context of the discussion. The context is > that the called function delegates the job of validating input to a > private function, which should be hidden from the caller (it's private, > not part of the public API, subject to change, hidden, etc.) but > tracebacks expose that information, obscuring the cause of the fault. > (The fault being bad input to the public function, not an accidental bug > in the private function.) > > >> If end users are seeing uncaught tracebacks, the program is broken. > > Well, perhaps, but that's a separate issue. We're talking about the > caller of the function seeing internal details, not the end use. No, that is the issue, unless the program itself is examining the stack traceback data. Python exception-catching has no notion of what code raised the exception. Only the contents of the exception object are normally available. So the "private function" is always "hidden", unless you're debugging, in which case it shouldn't be hidden. Traceback is purely a debugging feature. In some Python implementations, such as Shed Skin, you don't get tracebacks unless you're running under a debugger. John Nagle From go.gana at hotmail.com Sun Dec 26 14:44:29 2010 From: go.gana at hotmail.com (go.gana at hotmail.com) Date: Sun, 26 Dec 2010 11:44:29 -0800 (PST) Subject: A Brief Illustrated Guide To Understanding Islam Home Message-ID: <659fc323-4e65-4479-8b9e-b320bf24b075@f20g2000vbc.googlegroups.com> A Brief Illustrated Guide To Understanding Islam Home http://www.islam-guide.com/ From secris1 at gmail.com Sun Dec 26 14:53:14 2010 From: secris1 at gmail.com (Sean) Date: Sun, 26 Dec 2010 11:53:14 -0800 (PST) Subject: Python Web App References: <907fa80e-1814-4ddb-be32-ec14cfd53fab@29g2000yqq.googlegroups.com> Message-ID: @Katie Thank you I considered this option until I realized it wouldn't let me do anything other than ping from the command line. The rest of you all make valid points after doing a little more research on my own I found some really nice web based text editors but they didn't have any testing abilities which meant learning in that environment wasn't feasible in my opinion. I am inclined to agree that chrome OS will probably not do as well as they want it to but with the kind of capital Google has they could easily flood the market. In the end I wound up giving the notebook to my mom because all she really does is check her email and Facebook so it was perfect for her. Thank You for all the responses they were a great help with me testing the notebook. On Dec 25, 9:02?pm, Katie T wrote: > On Wed, Dec 22, 2010 at 9:43 PM, Sean wrote: > > Anybody know where I can find a Python Development Environment in the > > form of a web app for use with Chrome OS. I have been looking for a > > few days and all i have been able to find is some old discussions with > > python developers talking about they will want one for the OS to be a > > success with them. > > Your best bet is probably just to SSH to a *nix box and use something > like vim or emacs. None of the web solutions are anywhere near acceptable. > > Katie > -- > CoderStackhttp://www.coderstack.co.uk/python-jobs > The Software Developer Job Board From usernet at ilthio.net Sun Dec 26 15:15:16 2010 From: usernet at ilthio.net (Tim Harig) Date: Sun, 26 Dec 2010 20:15:16 +0000 (UTC) Subject: Trying to parse a HUGE(1gb) xml file References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> Message-ID: On 2010-12-26, Stefan Behnel wrote: > Tim Harig, 26.12.2010 10:22: >> On 2010-12-26, Stefan Behnel wrote: >>> Tim Harig, 26.12.2010 02:05: >>>> On 2010-12-25, Nobody wrote: >>>>> On Sat, 25 Dec 2010 14:41:29 -0500, Roy Smith wrote: >>>>>> Of course, one advantage of XML is that with so much redundant text, it >>>>>> compresses well. We typically see gzip compression ratios of 20:1. >>>>>> But, that just means you can archive them efficiently; you can't do >>>>>> anything useful until you unzip them. >>>>> >>>>> XML is typically processed sequentially, so you don't need to create a >>>>> decompressed copy of the file before you start processing it. >>>> >>>> Sometimes XML is processed sequentially. When the markup footprint is >>>> large enough it must be. Quite often, as in the case of the OP, you only >>>> want to extract a small piece out of the total data. In those cases, being >>>> forced to read all of the data sequentially is both inconvenient and and a >>>> performance penalty unless there is some way to address the data you want >>>> directly. >>> [...] >>> If you do it a lot, you will have to find a way to make the access >>> efficient for your specific use case. So the file format doesn't matter >>> either, because the data will most likely end up in a fast data base after >>> reading it in sequentially *once*, just as in the case above. >> >> If the data is just going to end up in a database anyway; then why not >> send it as a database to begin with and save the trouble of having to >> convert it? > > I don't think anyone would object to using a native format when copying > data from one database 1:1 to another one. But if the database formats are > different on both sides, it's a lot easier to map XML formatted data to a > given schema than to map a SQL dump, for example. Matter of use cases, not > of data size. Your assumption keeps hinging on the fact that I should want to dump the data into a database in the first place. Very often I don't. I just want to rip out the small portion of information that happens to be important to me. I may not even want to archive my little piece of the information once I have processed it. Even assuming that I want to dump all the data into a database, walking through a bunch of database records to translate them into the schema for another database is no more difficult then walking through a bunch of XML elements. In fact, it is even easier since I can use the relational model to reconstruct the information in an organization that better fits how the data is actually structured in my database instead of being constrained by how somebody else wanted to organize their XML. There is no need to "map a[sic] SQL dump." XML is great when the data is set is small enough that parsing the whole tree has negligable costs. I can choose whether I want to parse it sequentially or use XPath/DOM/Etree etc to make it appear as though I am making random accesses. When the data set grows so that parsing it is expensive I loose that choice even if my use case would otherwise prefer a random access paradigm. When that happens, there are better ways of communicating that data that doesn't force me into using a high overhead method of extracting my data. The problem is that XML has become such a defacto standard that it used automatically, without thought, even when there are much better alternatives available. From lists at cheimes.de Sun Dec 26 15:33:09 2010 From: lists at cheimes.de (Christian Heimes) Date: Sun, 26 Dec 2010 21:33:09 +0100 Subject: __delitem__ "feature" In-Reply-To: References: Message-ID: Am 26.12.2010 19:49, schrieb kj: > How do you know this? Is this documented? Or is this a case of > Monday-night quarterbacking? Please stop bitching around. You know that by carefully reading the documentation: http://docs.python.org/reference/datamodel.html#special-method-lookup-for-new-style-classes From stefan_ml at behnel.de Sun Dec 26 15:40:04 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 26 Dec 2010 21:40:04 +0100 Subject: lxml etree question In-Reply-To: References: <98fb45fe-e4d0-49f4-a705-7923b2bfcacb@k22g2000yqh.googlegroups.com> Message-ID: Jim, 26.12.2010 00:32: > On Dec 25, 5:33 am, Stefan Behnel wrote: >> lxml knows about this special case, so you can write >> >> {http://www.w3.org/XML/1998/namespace}lang >> >> and lxml will take care of using the right prefix. > > Stefan, thank you for the software, which has helped me a great deal. > > I tried that exact thing, among a number of others, and it didn't work > for me (I got ns0). Works for me, at least with a recent SVN version: Python 2.7.1rc1+ (trunk:86636, Nov 21 2010, 09:18:37) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import lxml.etree as ET >>> el = ET.Element('test', ... {'{http://www.w3.org/XML/1998/namespace}lang': 'de'}) >>> ET.tostring(el) '' Anyway, I applied a patch that makes sure it will always use the 'xml' prefix for this namespace. Will be in 2.3 final. Stefan From g.statkute at gmail.com Sun Dec 26 17:43:03 2010 From: g.statkute at gmail.com (gintare) Date: Sun, 26 Dec 2010 14:43:03 -0800 (PST) Subject: =?ISO-8859-1?B?c3RyaW5nIHUnaHl2XHhlNCcgdG8gZmlsZSBhcyAgJ2h5duQn?= Message-ID: Could you please help me with special characters saving to file. I need to write the string u'hyv\xe4' to file. I would like to open file and to have line 'hyv?' import codecs word= u'hyv\xe4' F=codecs.open(/opt/finnish.txt, 'w+','Latin-1') F.writelines(item.encode('Latin-1')) F.writelines(item.encode('utf8')) F.writelines(item) F.close() All three writelines gives the same result in finnish.txt: hyv\xe4 i would like to find 'hyv?'. regards, gintare From franapoli at gmail.com Sun Dec 26 17:43:39 2010 From: franapoli at gmail.com (Ciccio) Date: Sun, 26 Dec 2010 14:43:39 -0800 (PST) Subject: inspect.getsource bug? References: Message-ID: <274e75b8-a867-4406-977e-0f1d46ab8f7a@j3g2000vbi.googlegroups.com> On 26 Dic, 19:24, Ciccio wrote: > Try this: > 1) define a function 'foo' in a script > 2) runfile the script from a shell > 3) do 'inspect.getsource(foo)' > 4) change the source of 'foo' > 5) runfile the script from the same shell > 6) do 3 again > > On my 2.6.6 getsource returns twice the same code. I couldn't find > very much about this, is there any known workaround? > > thanks found this in the meantime: http://bugs.python.org/issue993580 From juanlu001 at gmail.com Sun Dec 26 18:03:29 2010 From: juanlu001 at gmail.com (Juanlu_001) Date: Sun, 26 Dec 2010 15:03:29 -0800 (PST) Subject: Need urllib.urlretrieve and urllib2.OpenerDirector together Message-ID: <2f246698-2067-417c-ade7-a9b5fb42bb59@k13g2000vbq.googlegroups.com> Hello everyone. I'm writing a script in Python 2.7 which uses a urllib2.OpenerDirector instance via urllib2.build_opener() to take advantage of the urllib2.HTTPCookieProcessor class, because I need to store and re-send the cookies I get: opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookielib.CookieJar())) However, after making several requests and moving the cookies around, eventually I need to retrieve a list of URLs. I wanted to use urllib.urlretrieve() because I read it downloads the file in chunks, but I cannot because I need to carry my cookies on the request and urllib.urlretrieve() uses a urllib.URLOpener, which doesn't have support for cookie handlers like OpenerDirector has. I want to know the reason of this strange way of splitting functionality, and how can I achieve my goal. Thank you in advance! From python at mrabarnett.plus.com Sun Dec 26 18:14:06 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 26 Dec 2010 23:14:06 +0000 Subject: string u'hyv\xe4' to file as =?ISO-8859-1?Q?=27hyv=E4=27?= In-Reply-To: References: Message-ID: <4D17CC3E.80406@mrabarnett.plus.com> On 26/12/2010 22:43, gintare wrote: > Could you please help me with special characters saving to file. > > I need to write the string u'hyv\xe4' to file. > I would like to open file and to have line 'hyv?' > > import codecs > word= u'hyv\xe4' > F=codecs.open(/opt/finnish.txt, 'w+','Latin-1') This opens the file using the Latin-1 encoding (although only if you put the filename in quotes). > > F.writelines(item.encode('Latin-1')) This encodes the Unicode item (did you mean 'word'?) to a bytestring using the Latin-1 encoding. You opened the file using Latin-1 encoding, so this is pointless. You should pass a Unicode string; it will encode it for you. You're also passing a bytestring to the .writelines method, which expects a list of strings. What you should be doing is this: F.write(word) > F.writelines(item.encode('utf8')) This encodes the Unicode item to a bytestring using the UTF-8 encoding. This is also pointless. You shouldn't be encoding to UTF-8 and then trying to write it to a file which was opened using Latin-1 encoding! > F.writelines(item) > > F.close() > > All three writelines gives the same result in finnish.txt: hyv\xe4 > i would like to find 'hyv?'. > From pythonva at gmail.com Sun Dec 26 18:33:05 2010 From: pythonva at gmail.com (Python Programming) Date: Sun, 26 Dec 2010 15:33:05 -0800 (PST) Subject: IDLE GUI not working Message-ID: Hello all, Newbie here so go easy on me. I've been trying to get the IDLE GUI to work on my machine, but have been unsuccessful so far. I have an IBM Thinkpad running Windows XP and it has an older version of Python running (2.2, I believe). When I try to use the shortcut to open the IDLE GUI nothing happens (not even a process running in task manager). When I use the cmd line to try to open the IDLE GUI, I get this error message: ---------------------------- C:\>C:\python27\python C:\python27\Lib\idlelib\idle.py Traceback (most recent call last): File "C:\python27\Lib\idlelib\idle.py", line 11, in idlelib.PyShell.main() File "C:\python27\Lib\idlelib\PyShell.py", line 1389, in main root = Tk(className="Idle") File "C:\python27\lib\lib-tk\Tkinter.py", line 1685, in __init__ self.tk = _tkinter.create(screenName, baseName, className, interactive, want objects, useTk, sync, use) _tkinter.TclError: Can't find a usable init.tcl in the following directories: {C:\IBMTOOLS\Python22\tcl\tcl8.4} C:/IBMTOOLS/Python22/tcl/tcl8.5 C:/python2 7/lib/tcl8.5 C:/lib/tcl8.5 C:/lib/tcl8.5 C:/library C:/library C:/ tcl8.5.2/libra ry C:/tcl8.5.2/library C:/IBMTOOLS/Python22/tcl/tcl8.4/init.tcl: version conflict for package "Tcl": ha ve 8.5.2, need exactly 8.4 version conflict for package "Tcl": have 8.5.2, need exactly 8.4 while executing "package require -exact Tcl 8.4" (file "C:/IBMTOOLS/Python22/tcl/tcl8.4/init.tcl" line 19) invoked from within "source C:/IBMTOOLS/Python22/tcl/tcl8.4/init.tcl" ("uplevel" body line 1) invoked from within "uplevel #0 [list source $tclfile]" This probably means that Tcl wasn't installed properly. ------------------------------------ As I understand this, python 2.7 is looking in a directory or path specified by the older, python 2.2 for Tcl. I have tried to unset this path by entering this into the cmd line: ------------------------------- C:\>set TCL_LIBRARY= C:\>set TK_LIBRARY= C:\>C:\Python27\python.exe C:\Python27\Lib\idlelib\idle.py ------------------------------- No dice. I tried to enter this information as a new pythonpath in the environment variables. No dice. I've tried, in vain, to get this thing working, but most of the other explanations are way over my head (I'm pretty new to programming and digging around the programming guts of computers) It seems like a fairly common problem, but haven't gotten a good answer from either the official python help boards or elsewhere. I was hoping that someone here could give me a easy to understand way to make the IDLE GUI work. Thanks in advance. From steve at holdenweb.com Sun Dec 26 20:08:49 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 26 Dec 2010 20:08:49 -0500 Subject: How to pop the interpreter's stack? In-Reply-To: References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <4d0aafdb$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4D17E721.1060902@holdenweb.com> On 12/26/2010 2:14 PM, kj wrote: > In Ethan Furman writes: > >> You failed to mention that cleverness is not a prime requisite of the >> python programmer -- in fact, it's usually frowned upon. > > That's the party line, anyway. I no longer believe it. I've been > crashing against one bit of cleverness after another in Python's > unification of types and classes... Well if you can find a way to implement a class system that doesn't use clever tricks *in its implementation* please let me know. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sun Dec 26 20:08:49 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 26 Dec 2010 20:08:49 -0500 Subject: How to pop the interpreter's stack? In-Reply-To: References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <4d0aafdb$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4D17E721.1060902@holdenweb.com> On 12/26/2010 2:14 PM, kj wrote: > In Ethan Furman writes: > >> You failed to mention that cleverness is not a prime requisite of the >> python programmer -- in fact, it's usually frowned upon. > > That's the party line, anyway. I no longer believe it. I've been > crashing against one bit of cleverness after another in Python's > unification of types and classes... Well if you can find a way to implement a class system that doesn't use clever tricks *in its implementation* please let me know. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From misnomer at gmail.com Sun Dec 26 20:12:50 2010 From: misnomer at gmail.com (misnomer at gmail.com) Date: Sun, 26 Dec 2010 17:12:50 -0800 (PST) Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8ed98c33-9ed9-42ab-a74d-d04d6922f8cd@c2g2000yqc.googlegroups.com> On Dec 23, 3:22?am, Steven D'Aprano wrote: > You seem to have completely missed that there will be no bug report, > because this isn't a bug. (Or if it is a bug, the bug is elsewhere, > external to the function that raises the exception.) It is part of the > promised API. The fact that the exception is generated deep down some > chain of function calls is irrelevant. While the idea of being able to do this (create a general validation exception) sounds mildly appealing at first, what happens when the module implementing this documented API and documented error, has a bug? It seems that the user, or even module developer in the midst of writing, would now have no tools to easily tackle the problem, and no useful information to submit in the required bug report. From pavlovevidence at gmail.com Sun Dec 26 21:55:39 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 26 Dec 2010 18:55:39 -0800 (PST) Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d1427ac$0$30000$c3e8da3$5496439d@news.astraweb.com> <3771d7ec-c030-4d15-a257-4c895ff57ec0@n2g2000pre.googlegroups.com> <4d1466d2$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: <282e4be8-ac91-4270-8c20-afbde5880d07@r40g2000prh.googlegroups.com> On Dec 26, 11:09?am, kj wrote: > In writes: > > >Except that the *caller* never gets the traceback (unless if it deliberately > >inspects the stack for some metaprogramming reason). It gets the exception, and > >that is the same no matter what you do. The developer/user gets the traceback, > >and those implementation details *are* often important to them. > > Just look at what Python shows you if you pass the wrong number of > arguments to a function: > > >>> def spam(x, y, z): pass > ... > >>> spam(1, 2) > > Traceback (most recent call last): > ? File "", line 1, in > TypeError: spam() takes exactly 3 arguments (2 given) > > That's it. ?The traceback stops at the point of the error. ?Python > doesn't show you all the underlying C-coded machinery that went > into detecting the error and emitting the error message. ?*No one* > needs this information at this point. ?All I'm saying is that I > want to do the same thing with my argument validation code as Python > does with its argument validation code: keep it out of sight. ?When > my argument validation code fires an exception ***there's no bug > in **my** code***. ?It's doing exactly what it's supposed to do. > Therefore, there's no need for me to debug anything, and certainly > no need for me to inspect the traceback all the way to the exception. > The bug is in the code that called my function with the wrong > arguments. ?The developer of that code has no more use for seeing > the traceback all the way to where my code raises the exception > than I have for seeing the traceback of Python's underlying C code > when I get an error like the one shown above. Python makes no attempt to hide its machinery in tracebacks (that I'm aware of); in fact stack points from internal Python functions, classes, and modules appear in tracebacks all the time. The reason you don't see traceback lines for Python's argument validation is it's written in C. If it bothers you that much, you're welcome to write you own argument validation in C, too. Carl Banks From pavlovevidence at gmail.com Sun Dec 26 22:00:42 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 26 Dec 2010 19:00:42 -0800 (PST) Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d1427ac$0$30000$c3e8da3$5496439d@news.astraweb.com> <3771d7ec-c030-4d15-a257-4c895ff57ec0@n2g2000pre.googlegroups.com> <4d1466d2$0$30000$c3e8da3$5496439d@news.astraweb.com> <4D151B52.4030502@stoneleaf.us> <4d1674e4$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Dec 25, 2:49?pm, Steven D'Aprano wrote: > On Sat, 25 Dec 2010 09:17:27 -0500, Robert Kern wrote: > > On 12/24/10 5:14 PM, Ethan Furman wrote: > > >> There are also times when I change the exception being raised to match > >> what python expects from that type of object -- for example, from > >> WhatEverException to KeyError for a dict-like object. So in this regard > >> I agree with Steven. > > > Steven isn't arguing that particular point here, nor is anyone arguing > > against it. > > Emphasis on *here*. > > You will note that in Python 3, if you raise an exception inside an > except block, both the *original* and the new exception are printed. This > is great for fixing bugs inside except blocks, but terribly disruptive > for catching one error and raising another error in it's place, e.g.: > > try: > ? ? x+0 > except ValueError, TypeError as e: > ? ? # x is not a numeric value, e.g. a string or a NAN. > ? ? raise MyError('x is not a number') > > The explicit raise is assumed to indicate a bug in the except block, and > the original exception is printed as well. > > But that's a separate issue from what is being discussed here. What we're > discussing here is the idea that a function should be able to delegate > work to private subroutines without the caller being aware of that fact. > When you return a value, the caller doesn't see the internal details of > how you calculated the value, but if you deliberately raise an exception, > the caller does. Often this is the right thing to do, but sometimes it > isn't. E.g. you can't delegate input validation to a subroutine and raise > inside the subroutine without obfuscating the traceback. >>> import re >>> re.compile(r"(") Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/re.py", line 190, in compile return _compile(pattern, flags) File "/usr/lib/python2.6/re.py", line 245, in _compile raise error, v # invalid expression sre_constants.error: unbalanced parenthesis OHMYGOD HOW DARE the standard library allow the traceback list an internal function that does input valididation! Carl Banks From gveggie at gmail.com Sun Dec 26 22:56:00 2010 From: gveggie at gmail.com (Grant Andrew) Date: Sun, 26 Dec 2010 20:56:00 -0700 Subject: IDLE GUI not working In-Reply-To: References: Message-ID: On Sun, Dec 26, 2010 at 4:33 PM, Python Programming wrote: > Hello all, > > Newbie here so go easy on me. I've been trying to get the IDLE GUI to > work on my machine, but have been unsuccessful so far. I have an IBM > Thinkpad running Windows XP and it has an older version of Python > running (2.2, I believe). When I try to use the shortcut to open the > IDLE GUI nothing happens (not even a process running in task > manager). When I use the cmd line to try to open the IDLE GUI, I get > this error message: > > ---------------------------- > C:\>C:\python27\python C:\python27\Lib\idlelib\idle.py > Traceback (most recent call last): > File "C:\python27\Lib\idlelib\idle.py", line 11, in > idlelib.PyShell.main() > File "C:\python27\Lib\idlelib\PyShell.py", line 1389, in main > root = Tk(className="Idle") > File "C:\python27\lib\lib-tk\Tkinter.py", line 1685, in __init__ > self.tk = _tkinter.create(screenName, baseName, className, > interactive, want > objects, useTk, sync, use) > _tkinter.TclError: Can't find a usable init.tcl in the following > directories: > {C:\IBMTOOLS\Python22\tcl\tcl8.4} C:/IBMTOOLS/Python22/tcl/tcl8.5 > C:/python2 > 7/lib/tcl8.5 C:/lib/tcl8.5 C:/lib/tcl8.5 C:/library C:/library C:/ > tcl8.5.2/libra > ry C:/tcl8.5.2/library > > C:/IBMTOOLS/Python22/tcl/tcl8.4/init.tcl: version conflict for package > "Tcl": ha > ve 8.5.2, need exactly 8.4 > version conflict for package "Tcl": have 8.5.2, need exactly 8.4 > while executing > "package require -exact Tcl 8.4" > (file "C:/IBMTOOLS/Python22/tcl/tcl8.4/init.tcl" line 19) > invoked from within > "source C:/IBMTOOLS/Python22/tcl/tcl8.4/init.tcl" > ("uplevel" body line 1) > invoked from within > "uplevel #0 [list source $tclfile]" > > > This probably means that Tcl wasn't installed properly. > ------------------------------------ > > As I understand this, python 2.7 is looking in a directory or path > specified by the older, python 2.2 for Tcl. I have tried to unset > this path by entering this into the cmd line: > > ------------------------------- > C:\>set TCL_LIBRARY= > C:\>set TK_LIBRARY= > C:\>C:\Python27\python.exe C:\Python27\Lib\idlelib\idle.py > ------------------------------- > > No dice. > > I tried to enter this information as a new pythonpath in the > environment variables. No dice. > > I've tried, in vain, to get this thing working, but most of the other > explanations are way over my head (I'm pretty new to programming and > digging around the programming guts of computers) > > It seems like a fairly common problem, but haven't gotten a good > answer from either the official python help boards or elsewhere. I > was hoping that someone here could give me a easy to understand way to > make the IDLE GUI work. > > Thanks in advance. > -- > http://mail.python.org/mailman/listinfo/python-list Wow, I wrote a note to this list so closely resembling yours I had to read carefully to ensure it wasn't my own. You have a PATH problem - these machines ship with Tcl installed and that's creating this issue. There is the standard Path variable, but if you'll notice, there is also a scrollbar to the right. Scroll down and find additional variables that need fixed - PythonPath, TCL_Library, and TK Library all need to be redirected to your current install. If you fix all of these, your problem should be solved and you'll be on your way, at least that was my exact issue on a Thinkpad running XP. Best of luck! Grant -------------- next part -------------- An HTML attachment was scrubbed... URL: From flebber.crue at gmail.com Sun Dec 26 23:37:57 2010 From: flebber.crue at gmail.com (flebber) Date: Sun, 26 Dec 2010 20:37:57 -0800 (PST) Subject: User input masks - Access Style Message-ID: <385bcaf1-81a5-405a-b7f0-28d7994a2e95@a28g2000prb.googlegroups.com> Is there anyay to use input masks in python? Similar to the function found in access where a users input is limited to a type, length and format. So in my case I want to ensure that numbers are saved in a basic format. 1) Currency so input limited to 000.00 eg 1.00, 2.50, 13.80 etc For sports times that is time duration not a system or date times should I assume that I would need to calculate a user input to a decimal number and then recalculate it to present it to user? So an example, sorry. import time #not sure if this is any use minute = input("How many minutes: ") seconds = input("How many seconds: ") Hundredths = input("how many Hundredths: ") # convert user input MyTime = (minute/60)+(seconds)+(Hundredths/1800) #Display to user assuming i had written a name and user # had retrieved it print("[User], your time was"), (MyTime/60:MyTime(MyTime-((MyTime/ 60)*60).(MyTime-(MyTime>0))) ) From steve+comp.lang.python at pearwood.info Sun Dec 26 23:50:03 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Dec 2010 04:50:03 GMT Subject: __delitem__ "feature" References: Message-ID: <4d181afb$0$30001$c3e8da3$5496439d@news.astraweb.com> On Sun, 26 Dec 2010 18:49:55 +0000, kj wrote: > In Ian Kelly > writes: > >>On 12/26/2010 10:53 AM, kj wrote: >>> P.S. If you uncomment the commented-out line, and comment out the last >>> line of the __init__ method (which installs self._delitem as >>> self.__delitem__) then *all* the deletion attempts invoke the >>> __delitem__ method, and are therefore blocked. FWIW. > >>Because subclasses of builtins only check the class __dict__ for special >>method overrides, not the instance __dict__. > > > How do you know this? Is this documented? Or is this a case of > Monday-night quarterbacking? We know it because it explains the observable facts. It also happens to be documented, but documentation can be wrong or incomplete. The facts are never wrong, since by definition they are the facts. -- Steven From steve+comp.lang.python at pearwood.info Mon Dec 27 00:03:56 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Dec 2010 05:03:56 GMT Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <4d0aafdb$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4d181e3c$0$30001$c3e8da3$5496439d@news.astraweb.com> On Sun, 26 Dec 2010 09:15:32 -0800, Ethan Furman wrote: > Steven D'Aprano wrote: >> Right. But I have thought of a clever trick to get the result KJ was >> asking for, with the minimum of boilerplate code. Instead of this: >> >> >> def _pre_spam(args): >> if condition(args): >> raise SomeException("message") >> if another_condition(args): >> raise AnotherException("message") >> if third_condition(args): >> raise ThirdException("message") >> >> def spam(args): >> _pre_spam(args) >> do_useful_work() >> >> >> you can return the exceptions instead of raising them (exceptions are >> just objects, like everything else!), and then add one small piece of >> boilerplate to the spam() function: >> >> >> def _pre_spam(args): >> if condition(args): >> return SomeException("message") >> if another_condition(args): >> return AnotherException("message") >> if third_condition(args): >> return ThirdException("message") >> >> def spam(args): >> exc = _pre_spam(args) >> if exc: raise exc >> do_useful_work() > > -1 > > You failed to mention that cleverness is not a prime requisite of the > python programmer -- in fact, it's usually frowned upon. The big > problem with the above code is you are back to passing errors in-band, > pretty much completely defeating the point of have an out-of-band > channel. How is that any worse than making _pre_spam() a validation function that returns a bool? def spam(args): flag = _pre_spam(args) if flag: raise SomeException() do_useful_work() Is that also frowned upon for being too clever? -- Steven From steve+comp.lang.python at pearwood.info Mon Dec 27 00:38:26 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Dec 2010 05:38:26 GMT Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <8ed98c33-9ed9-42ab-a74d-d04d6922f8cd@c2g2000yqc.googlegroups.com> Message-ID: <4d182652$0$30001$c3e8da3$5496439d@news.astraweb.com> On Sun, 26 Dec 2010 17:12:50 -0800, misnomer at gmail.com wrote: > On Dec 23, 3:22?am, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> You seem to have completely missed that there will be no bug report, >> because this isn't a bug. (Or if it is a bug, the bug is elsewhere, >> external to the function that raises the exception.) It is part of the >> promised API. The fact that the exception is generated deep down some >> chain of function calls is irrelevant. > > While the idea of being able to do this (create a general validation > exception) sounds mildly appealing at first, what happens when the > module implementing this documented API and documented error, has a bug? > It seems that the user, or even module developer in the midst of > writing, would now have no tools to easily tackle the problem, and no > useful information to submit in the required bug report. That's very true, but the same applies to *any* use of encapsulation. Any time you hide information, you hide information (duh!). This doesn't stop us from doing this: def public(x): if condition: return _private(x) elif other_condition: return _more_private(x+1) else: return _yet_another_private(x-1) If you call public(42), and get the wrong answer, it's a bug, but the source of the bug is hidden from the caller. If you have access to the source code, you can work out where the bug lies (which of the three private functions is buggy?) given the argument, but the return result itself does not expose any information about where the bug lies. This is considered an unavoidable but acceptable side-effect of an otherwise desirable state of affairs: information hiding and encapsulation. The caller being unaware of where and how the result is calculated is considered a good thing, and the fact that it occasionally adds to the debugging effort is considered such a trivial cost that it normally isn't remarked upon, except by lunatics and die-hard fans of spaghetti code using GOTO. But I repeat myself. Why should exceptions *necessarily* be different? As I've repeatedly acknowledged, for an unexpected exception (a bug), the developer needs all the help he can get, and the current behaviour is the right way to do it. You won't hear me argue differently. But for a documented, explicit, expected, deliberate exception, Python breaks encapsulation by exposing the internal details of any internal subroutines used to generate that exception. This leads to messy tracebacks that obscure the source of bugs in the caller's code: >>> import re >>> re.compile(r"(") Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/re.py", line 190, in compile return _compile(pattern, flags) File "/usr/lib/python2.6/re.py", line 245, in _compile raise error, v # invalid expression sre_constants.error: unbalanced parenthesis I think critics of my position have forgotten what it's like to learning the language. One of the most valuable skills to learn is to *ignore parts of the traceback* -- a skill that takes practice and familiarity with the library or function in use. To those who are less familiar with the function, it can be very difficult to determine which parts of the traceback are relevant and which aren't. In this case, the caller has nothing to do with _compile, and the traceback looks like it's an internal bug in a subroutine, when in fact it is actually due to bad input. The experienced developer learns (by trial and error, possibly) to ignore nearly half of the error message in this case. In principle, the traceback could be roughly half as big, which means the caller would find it half as difficult to read and understand: >>> re.compile(r"(") Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/re.py", line 190, in compile raise error, v # invalid expression sre_constants.error: unbalanced parenthesis With a one-to-one correspondence between the function called, and the function reporting an error, it is easier to recognise that the error lies in the input rather than some internal error in some subroutine you have nothing to do with. Unfortunately there's no straightforward way to consistently get this in Python without giving up the advantages of delegating work to subroutines. It need not be that way. This could, in principle, be left up to the developer of the public function to specify (somehow!) that some specific exceptions are expected, and should be treated as coming from public() rather than from some internal subroutine. I don't have a concrete proposal for such, although I did suggest a work-around. I expected disinterest ("I don't see the point"). I didn't expect the level of hostility to the idea that exceptions should (if and when possible) point to the source of the error rather than some accidental implementation- specific subroutine. Go figure. -- Steven From g.statkute at gmail.com Mon Dec 27 00:57:30 2010 From: g.statkute at gmail.com (gintare) Date: Sun, 26 Dec 2010 21:57:30 -0800 (PST) Subject: =?ISO-8859-1?B?UmU6IHN0cmluZyB1J2h5dlx4ZTQnIHRvIGZpbGUgYXMgJ2h5duQn?= References: Message-ID: <83dc3076-9ddc-42bd-8c33-6af96b2634ba@l32g2000yqc.googlegroups.com> Hello, STILL do not work. WHAT to be done. import codecs item=u'hyv\xe4' F=codecs.open('/opt/finnish.txt', 'w+', 'utf8') F.writelines(item.encode('utf8')) F.close() In file i find 'hyv\xe4' instead of hyv?. (Sorry for mistyping in previous letter about 'latin-1'. I was making all possible combinations, when normal example syntax did not work, before writting to this forum.) regards, gintare On 27 Gruo, 00:43, gintare wrote: > Could you please help me with special characters saving to file. > > I need to write the string u'hyv\xe4' to file. > I would like to open file and to have line 'hyv?' > > import codecs > word= u'hyv\xe4' > F=codecs.open(/opt/finnish.txt, 'w+','Latin-1') > > F.writelines(item.encode('Latin-1')) > F.writelines(item.encode('utf8')) > F.writelines(item) > > F.close() > > All three writelines gives the same result in finnish.txt: ? hyv\xe4 > i would like to find 'hyv?'. > > regards, > gintare From metolone+gmane at gmail.com Mon Dec 27 01:47:58 2010 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Sun, 26 Dec 2010 22:47:58 -0800 Subject: =?iso-8859-1?Q?Re:_string_u'hyv\xe4'_to_file_as_'hyv=E4'?= References: <83dc3076-9ddc-42bd-8c33-6af96b2634ba@l32g2000yqc.googlegroups.com> Message-ID: "gintare" wrote in message news:83dc3076-9ddc-42bd-8c33-6af96b2634ba at l32g2000yqc.googlegroups.com... > Hello, > STILL do not work. WHAT to be done. > > import codecs > item=u'hyv\xe4' > F=codecs.open('/opt/finnish.txt', 'w+', 'utf8') > F.writelines(item.encode('utf8')) > F.close() > > In file i find 'hyv\xe4' instead of hyv?. When you open a file with codecs.open(), it expects Unicode strings to be written to the file. Don't encode them again. Also, .writelines() expects a list of strings. Use .write(): import codecs item=u'hyv\xe4' F=codecs.open('/opt/finnish.txt', 'w+', 'utf8') F.write(item) F.close() An additional comment, if you save the script in UTF8, you can inform Python of that fact with a special comment, and actually use the correct characters in your string constants (? instead of \xe4). Make sure to use a text editor that can save in UTF8, or use the correct coding comment for whatever encoding in which you save the file. # coding: utf8 import codecs item=u'hyv?' F=codecs.open('finnish.txt', 'w+', 'utf8') F.write(item) F.close() -Mark From usernet at ilthio.net Mon Dec 27 02:01:26 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 27 Dec 2010 07:01:26 +0000 (UTC) Subject: User input masks - Access Style References: <385bcaf1-81a5-405a-b7f0-28d7994a2e95@a28g2000prb.googlegroups.com> Message-ID: On 2010-12-27, flebber wrote: > Is there anyay to use input masks in python? Similar to the function > found in access where a users input is limited to a type, length and > format. > > So in my case I want to ensure that numbers are saved in a basic > format. > 1) Currency so input limited to 000.00 eg 1.00, 2.50, 13.80 etc Some GUIs provide this functionality or provide callbacks for validation functions that can determine the validity of the input. I don't know of any modules that provide "formatted input" in a terminal. Most terminal input functions just read from stdin (in this case a buffered line) and output that as a string. It is easy enough to validate whether terminal input is in the proper. Your example time code might look like: ... import re ... import sys ... ... # get the input ... print("Please enter time in the format 'MM:SS:HH': ", end="") ... timeInput = input() ... ... # validate the input is in the correct format (usually this would be in ... # loop that continues until the user enters acceptable data) ... if re.match(r'''^[0-9]{2}:[0-9]{2}:[0-9]{2}$''', timeInput) == None: ... print("I'm sorry, your input is improperly formated.") ... sys.exit(1) ... ... # break the input into its componets ... componets = timeInput.split(":") ... minutes = int(componets[0]) ... seconds = int(componets[1]) ... microseconds = int(componets[2]) ... ... # output the time ... print("Your time is: " + "%02d" % minutes + ":" + "%02d" % seconds + ":" + ... "%02d" % microseconds) Currency works the same way using validating it against: r'''[0-9]+\.[0-9]{2}''' > For sports times that is time duration not a system or date times > should I assume that I would need to calculate a user input to a > decimal number and then recalculate it to present it to user? I am not sure what you are trying to do or asking. Python provides time, date, datetime, and timedelta objects that can be used for date/time calculations, locale based formatting, etc. What you use, if any, will depend on what you are actually tring to accomplish. Your example doesn't really show you doing much with the time so it is difficult giving you any concrete recommendations. From ethan at stoneleaf.us Mon Dec 27 02:03:57 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 26 Dec 2010 23:03:57 -0800 Subject: How to pop the interpreter's stack? In-Reply-To: <4d182652$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <8ed98c33-9ed9-42ab-a74d-d04d6922f8cd@c2g2000yqc.googlegroups.com> <4d182652$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4D183A5D.6030208@stoneleaf.us> Steven D'Aprano wrote: > ... > > I think critics of my position have forgotten what it's like to learning > the language. One of the most valuable skills to learn is to *ignore > parts of the traceback* -- a skill that takes practice and familiarity > with the library or function in use. To those who are less familiar with > the function, it can be very difficult to determine which parts of the > traceback are relevant and which aren't. In this case, the caller has > nothing to do with _compile, and the traceback looks like it's an > internal bug in a subroutine, when in fact it is actually due to bad > input. The experienced developer learns (by trial and error, possibly) to > ignore nearly half of the error message in this case. And it can still be some work to figure out which parts of the traceback are relevant, even after a couple years... > ... > It need not be that way. This could, in principle, be left up to the > developer of the public function to specify (somehow!) that some specific > exceptions are expected, and should be treated as coming from public() > rather than from some internal subroutine. I don't have a concrete > proposal for such, although I did suggest a work-around. I expected > disinterest ("I don't see the point"). I didn't expect the level of > hostility to the idea that exceptions should (if and when possible) point > to the source of the error rather than some accidental implementation- > specific subroutine. Go figure. My objection is not to the idea, but to the ad-hoc methods that would currently be required. Resorting to passing exceptions in-band is a step backwards. If python had a way to specify what level an exception should be reported from, I might be interested. At this point, if sparing the user one level of traceback was that high a priority to me, I would make the validation be either a decorator, or have the validation *be* the main routine, and the *real work* routine be the private one. ~Ethan~ From usernet at ilthio.net Mon Dec 27 02:09:38 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 27 Dec 2010 07:09:38 +0000 (UTC) Subject: User input masks - Access Style References: <385bcaf1-81a5-405a-b7f0-28d7994a2e95@a28g2000prb.googlegroups.com> Message-ID: On 2010-12-27, Tim Harig wrote: > ... if re.match(r'''^[0-9]{2}:[0-9]{2}:[0-9]{2}$''', timeInput) == None: [SNIP] > Currency works the same way using validating it against: > r'''[0-9]+\.[0-9]{2}''' Sorry, you need to check to make sure that there are no trailing characters as in the example above. Checking the beginning is not actually necessary with match(). r'''^[0-9]+\.[0-9]{2}$''' From flebber.crue at gmail.com Mon Dec 27 02:14:16 2010 From: flebber.crue at gmail.com (flebber) Date: Sun, 26 Dec 2010 23:14:16 -0800 (PST) Subject: User input masks - Access Style References: <385bcaf1-81a5-405a-b7f0-28d7994a2e95@a28g2000prb.googlegroups.com> Message-ID: <43752cb5-ef0a-49d9-8e38-80d126b5077b@k14g2000pre.googlegroups.com> On Dec 27, 6:01?pm, Tim Harig wrote: > On 2010-12-27, flebber wrote: > > > Is there anyay to use input masks in python? Similar to the function > > found in access where a users input is limited to a type, length and > > format. > > > So in my case I want to ensure that numbers are saved in a basic > > format. > > 1) Currency so input limited to 000.00 eg 1.00, 2.50, 13.80 etc > > Some GUIs provide this functionality or provide callbacks for validation > functions that can determine the validity of the input. ?I don't know of > any modules that provide "formatted input" in a terminal. ?Most terminal > input functions just read from stdin (in this case a buffered line) > and output that as a string. ?It is easy enough to validate whether > terminal input is in the proper. > > Your example time code might look like: > > ... import re > ... import sys > ... > ... # get the input > ... print("Please enter time in the format 'MM:SS:HH': ", end="") > ... timeInput = input() > ... > ... # validate the input is in the correct format (usually this would be in > ... # loop that continues until the user enters acceptable data) > ... if re.match(r'''^[0-9]{2}:[0-9]{2}:[0-9]{2}$''', timeInput) == None: > ... ? ? print("I'm sorry, your input is improperly formated.") > ... ? ? sys.exit(1) > ... > ... # break the input into its componets > ... componets = timeInput.split(":") > ... minutes = int(componets[0]) > ... seconds = int(componets[1]) > ... microseconds = int(componets[2]) > ... > ... # output the time > ... print("Your time is: " + "%02d" % minutes + ":" + "%02d" % seconds + ":" + > ... ? ? "%02d" % microseconds) > > Currency works the same way using validating it against: > r'''[0-9]+\.[0-9]{2}''' > > > For sports times that is time duration not a system or date times > > should I assume that I would need to calculate a user input to a > > decimal number and then recalculate it to present it to user? > > I am not sure what you are trying to do or asking. ?Python provides time, > date, datetime, and timedelta objects that can be used for date/time > calculations, locale based formatting, etc. ?What you use, if any, will > depend on what you are actually tring to accomplish. ?Your example doesn't > really show you doing much with the time so it is difficult giving you any > concrete recommendations. yes you are right I should have clarified. The time is a duration over distance, so its a speed measure. Ultimately I will need to store the times so I may need to use something likw sqlAlchemy but I am nowehere near the advanced but I know that most Db's mysql, postgre etc don't support time as a duration as such and i will probably need to store it as a decimal and convert it back for the user. From linmq at neusoft.com Mon Dec 27 03:57:56 2010 From: linmq at neusoft.com (linmq) Date: Mon, 27 Dec 2010 16:57:56 +0800 Subject: Fw: Re: User input masks - Access Style References: <385bcaf1-81a5-405a-b7f0-28d7994a2e95@a28g2000prb.googlegroups.com> <43752cb5-ef0a-49d9-8e38-80d126b5077b@k14g2000pre.googlegroups.com> Message-ID: <201012271657483976492@neusoft.com> > On 2010-12-27, flebber wrote: > > > Is there anyay to use input masks in python? Similar to the function > > found in access where a users input is limited to a type, length and > > format. > > > So in my case I want to ensure that numbers are saved in a basic > > format. > > 1) Currency so input limited to 000.00 eg 1.00, 2.50, 13.80 etc > > Some GUIs provide this functionality or provide callbacks for validation > functions that can determine the validity of the input. ? don't know of > any modules that provide "formatted input" in a terminal. ?ost terminal > input functions just read from stdin (in this case a buffered line) > and output that as a string. ?t is easy enough to validate whether > terminal input is in the proper. > > Your example time code might look like: > > ... import re > ... import sys > ... > ... # get the input > ... print("Please enter time in the format 'MM:SS:HH': ", end="") > ... timeInput = input() > ... > ... # validate the input is in the correct format (usually this would be in > ... # loop that continues until the user enters acceptable data) > ... if re.match(r'''^[0-9]{2}:[0-9]{2}:[0-9]{2}$''', timeInput) == None: > ... ??print("I'm sorry, your input is improperly formated.") > ... ??sys.exit(1) > ... > ... # break the input into its componets > ... componets = timeInput.split(":") > ... minutes = int(componets[0]) > ... seconds = int(componets[1]) > ... microseconds = int(componets[2]) > ... > ... # output the time > ... print("Your time is: " + "%02d" % minutes + ":" + "%02d" % seconds + ":" + > ... ??"%02d" % microseconds) > > Currency works the same way using validating it against: > r'''[0-9]+\.[0-9]{2}''' > > > For sports times that is time duration not a system or date times > > should I assume that I would need to calculate a user input to a > > decimal number and then recalculate it to present it to user? > > I am not sure what you are trying to do or asking. ?ython provides time, > date, datetime, and timedelta objects that can be used for date/time > calculations, locale based formatting, etc. ?hat you use, if any, will > depend on what you are actually tring to accomplish. ?our example doesn't > really show you doing much with the time so it is difficult giving you any > concrete recommendations. > > yes you are right I should have clarified. The time is a duration over > distance, so its a speed measure. Ultimately I will need to store the > times so I may need to use something likw sqlAlchemy but I am nowehere > near the advanced but I know that most Db's mysql, postgre etc don't > support time as a duration as such and i will probably need to store > it as a decimal and convert it back for the user. > -- > http://mail.python.org/mailman/listinfo/python-list You can let a user to separately input the days, hours, minutes, etc. And use the type timedelta to store the time duration: datetime.timedelta([days[, seconds[, microseconds[, milliseconds[, minutes[, hours[, weeks]]]]]]]) Beyond 2.7, you can use timedelta.total_seconds() to convert the time duration to a number for database using. And later restore the number back to timedelta by timedelta(seconds=?). Refer to: http://docs.python.org/library/datetime.html?highlight=timedelta#timedelta-objects -- --------------------------------------------------------------------------------------------------- Confidentiality Notice: The information contained in this e-mail and any accompanying attachment(s) is intended only for the use of the intended recipient and may be confidential and/or privileged of Neusoft Corporation, its subsidiaries and/or its affiliates. If any reader of this communication is not the intended recipient, unauthorized use, forwarding, printing, storing, disclosure or copying is strictly prohibited, and may be unlawful.If you have received this communication in error,please immediately notify the sender by return e-mail, and delete the original message and all copies from your system. Thank you. --------------------------------------------------------------------------------------------------- From dickinsm at gmail.com Mon Dec 27 04:38:09 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Mon, 27 Dec 2010 01:38:09 -0800 (PST) Subject: round in 2.6 and 2.7 References: <87sjxoco6u.fsf@xemacs.org> Message-ID: <5f07e3a7-5f13-4ca0-bcde-75a916ac9210@r29g2000yqj.googlegroups.com> On Dec 23, 6:57?pm, Hrvoje Niksic wrote: > I stumbled upon this. ?Python 2.6: > > >>> round(9.95, 1) > > 10.0 > > So it seems that Python is going out of its way to intuitively round > 9.95, while the repr retains the unnecessary digits. No, Python's not doing anything clever here. Python 2.6 uses a simple rounding algorithm that frequently gives the wrong answer for halfway or near-halfway cases. It's just luck that in this particular case it gives the apparently-correct (but actually incorrect) answer. Martin's already explained that the 2.7 behaviour is correct, and agrees with string formatting. However, note that there's still a disconnect between these two operations in Python 2.7: >>> round(1.25, 1) 1.3 >>> format(1.25, '.1f') '1.2' That's because 'round' in Python 2.x (including 2.7) still rounds exact halfway cases away from zero, while string formatting rounds them to the value with even last digit. In Python 3.x, even this discrepancy is fixed---everything does round-halfway-to-even. > Is the change to round() expected? Expected, and intentional. :-) [Martin] > "Float-to-string and string-to-float conversions are correctly rounded. > The round() function is also now correctly rounded." > > Not sure that this is correct English; I think it means that the > round() function is now correct. Well, the correct result of the example the OP gave would be 9.9 exactly. But since 9.9 isn't exactly representable as a Python float, we necessarily get an approximation. The language above is intended to convey that it's the 'correctly rounded' approximation---that is, the closest Python float to the true value of 9.9 (with halfway cases rounded to even, as usual). Mark From alex at moreati.org.uk Mon Dec 27 04:55:47 2010 From: alex at moreati.org.uk (Alex Willmer) Date: Mon, 27 Dec 2010 01:55:47 -0800 (PST) Subject: =?ISO-8859-1?B?UmU6IHN0cmluZyB1J2h5dlx4ZTQnIHRvIGZpbGUgYXMgJ2h5duQn?= References: <83dc3076-9ddc-42bd-8c33-6af96b2634ba@l32g2000yqc.googlegroups.com> Message-ID: <7fa3db2e-74d0-497a-a9fa-0ee1dce3394c@j29g2000yqm.googlegroups.com> On Dec 27, 6:47?am, "Mark Tolonen" wrote: > "gintare" wrote in message > > In file i find 'hyv\xe4' instead of hyv . > > When you open a file with codecs.open(), it expects Unicode strings to be > written to the file. ?Don't encode them again. ?Also, .writelines() expects > a list of strings. ?Use .write(): > > ? ? import codecs > ? ? item=u'hyv\xe4' > ? ? F=codecs.open('/opt/finnish.txt', 'w+', 'utf8') > ? ? F.write(item) > ? ? F.close() Gintare, Mark's code is correct. When you are reading the file back make sure you understand what you are seeing: >>> F2 = codecs.open('finnish.txt', 'r', 'utf8') >>> item2 = F2.read() >>> item2 u'hyv\xe4' That might like as though item2 is 7 characters long, and it contains a backslash followed by x, e, 4. However item2 is identical to item, they both contain 4 characters - the final one being a-umlaut. Python has shown the string using a backslash escape, because printing a non- ascii character might fail. You can see this directly, if your Python session is running in a terminal (or GUI) that can handle non-ascii characters: >>> print item2 hyv? From doomster at knuut.de Mon Dec 27 06:05:10 2010 From: doomster at knuut.de (Ulrich Eckhardt) Date: Mon, 27 Dec 2010 12:05:10 +0100 Subject: Interning own classes like strings for speed and size? Message-ID: <8nra78Foh3U1@mid.uni-berlin.de> Hi! I'm trying to solve a computational problem and of course speed and size is important there. Apart from picking the right algorithm, I came across an idea that could help speed up things and keep memory requirements down. What I have is regions described by min and max coordinates. At first, I just modeled these as a simple class containing two values for each axis. In a second step, I derived this class from tuple instead of object. Some code then moved from __init__ to __new__ and some code that modified these objects had to be changed to replace them instead. The upside to this is that they can be used as keys in sets and dicts, which isn't the case for mutable types[1]. What I'm now considering is to only allow a single instance of these objects for each set of values, similar to interned strings. What I would gain is that I could safely compare objects for identity instead of equality. What I'm not yet sure is how much overhead that would give me and/or how to keep it low. The idea is to store each instance in a set and after creating a new object I would first look up an equal object in the global set and return that instead, otherwise add the new one. The problem I foresee is that if I define equality as identity, this lookup when creating will never eliminate duplicates. If I only fall back to equality comparison for non-identical objects, I would probably sacrifice most of the gain. If I build a dict mapping between the values and the actual objects, I would have doubled the required memory and uselessly store the same values twice there. Am I looking in the wrong direction? Is there some better approach? Please don't tell me to use C, as I'm specifically interested in learning Python, I'm pretty sure I could have solved the problem quickly in C++ otherwise. Other suggestions? Cheers! Uli [1] Somebody correct me if I'm wrong, but I believe I could have defined a hashing function for the type and thus allowed its use in a set or dict, right? However, goofing up because you accidentally modified an object and changed its hash value is something I don't want to risk anyway. From flebber.crue at gmail.com Mon Dec 27 06:19:43 2010 From: flebber.crue at gmail.com (flebber) Date: Mon, 27 Dec 2010 03:19:43 -0800 (PST) Subject: Fw: Re: User input masks - Access Style References: <385bcaf1-81a5-405a-b7f0-28d7994a2e95@a28g2000prb.googlegroups.com> <43752cb5-ef0a-49d9-8e38-80d126b5077b@k14g2000pre.googlegroups.com> Message-ID: On Dec 27, 7:57?pm, linmq wrote: > > On 2010-12-27, flebber ? wrote: > > > ?> Is there anyay to use input masks in python? Similar to the function > > ?> found in access where a users input is limited to a type, length and > > ?> format. > > > ?> So in my case I want to ensure that numbers are saved in a basic > > ?> format. > > ?> 1) Currency so input limited to 000.00 eg 1.00, 2.50, 13.80 etc > > > Some GUIs provide this functionality or provide callbacks for validation > > functions that can determine the validity of the input. ? don't know of > > any modules that provide "formatted input" in a terminal. ?ost terminal > > input functions just read from stdin (in this case a buffered line) > > and output that as a string. ?t is easy enough to validate whether > > terminal input is in the proper. > > > Your example time code might look like: > > > ... import re > > ... import sys > > ... > > ... # get the input > > ... print("Please enter time in the format 'MM:SS:HH': ", end="") > > ... timeInput = input() > > ... > > ... # validate the input is in the correct format (usually this would be in > > ... # loop that continues until the user enters acceptable data) > > ... if re.match(r'''^[0-9]{2}:[0-9]{2}:[0-9]{2}$''', timeInput) == None: > > ... ??print("I'm sorry, your input is improperly formated.") > > ... ??sys.exit(1) > > ... > > ... # break the input into its componets > > ... componets = timeInput.split(":") > > ... minutes = int(componets[0]) > > ... seconds = int(componets[1]) > > ... microseconds = int(componets[2]) > > ... > > ... # output the time > > ... print("Your time is: " + "%02d" % minutes + ":" + "%02d" % seconds + ":" + > > ... ??"%02d" % microseconds) > > > Currency works the same way using validating it against: > > r'''[0-9]+\.[0-9]{2}''' > > > ?> For sports times that is time duration not a system or date times > > ?> should I assume that I would need to calculate a user input to a > > ?> decimal number and then recalculate it to present it to user? > > > I am not sure what you are trying to do or asking. ?ython provides time, > > date, datetime, and timedelta objects that can be used for date/time > > calculations, locale based formatting, etc. ?hat you use, if any, will > > depend on what you are actually tring to accomplish. ?our example doesn't > > really show you doing much with the time so it is difficult giving you any > > concrete recommendations. > > > yes you are right I should have clarified. The time is a duration over > > distance, so its a speed measure. ?Ultimately I will need to store the > > times so I may need to use something likw sqlAlchemy but I am nowehere > > near the advanced but I know that most Db's mysql, postgre etc don't > > support time as a duration as such and i will probably need to store > > it as a decimal and convert it back for the user. > > -- > >http://mail.python.org/mailman/listinfo/python-list > > You can let a user to separately input the days, hours, minutes, etc. > And use the type timedelta to store the time duration: > > datetime.timedelta([days[, seconds[, microseconds[, milliseconds[, minutes[, hours[, weeks]]]]]]]) > > Beyond 2.7, you can use timedelta.total_seconds() to convert the time > duration to a number for database using. And later restore the number > back to timedelta by timedelta(seconds=?). > > Refer to:http://docs.python.org/library/datetime.html?highlight=timedelta#time... > > -- > > --------------------------------------------------------------------------------------------------- > Confidentiality Notice: The information contained in this e-mail and any accompanying attachment(s) > is intended only for the use of the intended recipient and may be confidential and/or privileged of > Neusoft Corporation, its subsidiaries and/or its affiliates. If any reader of this communication is > not the intended recipient, unauthorized use, forwarding, printing, ?storing, disclosure or copying > is strictly prohibited, and may be unlawful.If you have received this communication in error,please > immediately notify the sender by return e-mail, and delete the original message and all copies from > your system. Thank you. > --------------------------------------------------------------------------------------------------- Very helpful thanks From fetchinson at googlemail.com Mon Dec 27 06:45:42 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Mon, 27 Dec 2010 12:45:42 +0100 Subject: Interning own classes like strings for speed and size? In-Reply-To: <8nra78Foh3U1@mid.uni-berlin.de> References: <8nra78Foh3U1@mid.uni-berlin.de> Message-ID: > I'm trying to solve a computational problem and of course speed and size is > important there. Apart from picking the right algorithm, I came across an > idea that could help speed up things and keep memory requirements down. What > I have is regions described by min and max coordinates. At first, I just > modeled these as a simple class containing two values for each axis. > > In a second step, I derived this class from tuple instead of object. Some > code then moved from __init__ to __new__ and some code that modified these > objects had to be changed to replace them instead. The upside to this is > that they can be used as keys in sets and dicts, which isn't the case for > mutable types[1]. > > What I'm now considering is to only allow a single instance of these objects > for each set of values, similar to interned strings. What I would gain is > that I could safely compare objects for identity instead of equality. What > I'm not yet sure is how much overhead that would give me and/or how to keep > it low. The idea is to store each instance in a set and after creating a new > object I would first look up an equal object in the global set and return > that instead, otherwise add the new one. > > The problem I foresee is that if I define equality as identity, this lookup > when creating will never eliminate duplicates. If I only fall back to > equality comparison for non-identical objects, I would probably sacrifice > most of the gain. If I build a dict mapping between the values and the > actual objects, I would have doubled the required memory and uselessly store > the same values twice there. > > Am I looking in the wrong direction? Is there some better approach? Please > don't tell me to use C, as I'm specifically interested in learning Python, > I'm pretty sure I could have solved the problem quickly in C++ otherwise. > Other suggestions? > > Cheers! > > Uli > > > [1] Somebody correct me if I'm wrong, but I believe I could have defined a > hashing function for the type and thus allowed its use in a set or dict, > right? However, goofing up because you accidentally modified an object and > changed its hash value is something I don't want to risk anyway. I believe what you are looking for is (some variant of) the singleton pattern: http://en.wikipedia.org/wiki/Singleton_pattern How it's done in python see http://www.google.com/search?q=python+singleton Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From doomster at knuut.de Mon Dec 27 07:12:53 2010 From: doomster at knuut.de (Ulrich Eckhardt) Date: Mon, 27 Dec 2010 13:12:53 +0100 Subject: Interning own classes like strings for speed and size? References: <8nra78Foh3U1@mid.uni-berlin.de> Message-ID: <8nre68FetaU1@mid.uni-berlin.de> Daniel Fetchinson wrote: > I believe what you are looking for is (some variant of) the singleton > pattern: > > http://en.wikipedia.org/wiki/Singleton_pattern Actually, no. What I want is the flyweight pattern instead: http://en.wikipedia.org/wiki/Flyweight_pattern ...but thank you for the approach of looking for a suitable pattern! Cheers! Uli From duncan.booth at invalid.invalid Mon Dec 27 07:29:34 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 27 Dec 2010 12:29:34 GMT Subject: type(d) != type(d.copy()) when type(d).issubclass(dict) References: Message-ID: kj wrote: >>In (almost?) all cases any objects constructed by a subclass of a >>builtin class will be of the original builtin class. > > > What I *really* would like to know is: how do *you* know this (and > the same question goes for the other responders who see this behavior > of dict as par for the course). Can you show me where it is in > the documentation? I'd really appreciate it. TIA! > I know it from experience (and reading source). So far as I can tell it isn't explicitly stated anywhere in the documentation. Mostly the documentation just says a method returns 'a copy of' prossibly with some modification. For example: str.capitalize() Return a copy of the string with its first character capitalized and the rest lowercased. That is ambiguous as it leaves open the question whether it returns "a string that is a copy" or an object of the type being operated upon. It happens to be the former but it doesn't actually say. -- Duncan Booth http://kupuguy.blogspot.com From fetchinson at googlemail.com Mon Dec 27 07:44:24 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Mon, 27 Dec 2010 13:44:24 +0100 Subject: Interning own classes like strings for speed and size? In-Reply-To: <8nre68FetaU1@mid.uni-berlin.de> References: <8nra78Foh3U1@mid.uni-berlin.de> <8nre68FetaU1@mid.uni-berlin.de> Message-ID: >> I believe what you are looking for is (some variant of) the singleton >> pattern: >> >> http://en.wikipedia.org/wiki/Singleton_pattern > > Actually, no. What I want is the flyweight pattern instead: > > http://en.wikipedia.org/wiki/Flyweight_pattern Oh I see. I did not know about this pattern, but in my defense it looks like a variant of the singleton pattern :) Thanks! One always learns something new on python-list. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From ethan at stoneleaf.us Mon Dec 27 08:07:16 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 27 Dec 2010 05:07:16 -0800 Subject: How to pop the interpreter's stack? In-Reply-To: <4d181e3c$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <4d0aafdb$0$29997$c3e8da3$5496439d@news.astraweb.com> <4d181e3c$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4D188F84.9010501@stoneleaf.us> Steven D'Aprano wrote: > On Sun, 26 Dec 2010 09:15:32 -0800, Ethan Furman wrote: > >> Steven D'Aprano wrote: >>> Right. But I have thought of a clever trick to get the result KJ was >>> asking for, with the minimum of boilerplate code. Instead of this: >>> >>> >>> def _pre_spam(args): >>> if condition(args): >>> raise SomeException("message") >>> if another_condition(args): >>> raise AnotherException("message") >>> if third_condition(args): >>> raise ThirdException("message") >>> >>> def spam(args): >>> _pre_spam(args) >>> do_useful_work() >>> >>> >>> you can return the exceptions instead of raising them (exceptions are >>> just objects, like everything else!), and then add one small piece of >>> boilerplate to the spam() function: >>> >>> >>> def _pre_spam(args): >>> if condition(args): >>> return SomeException("message") >>> if another_condition(args): >>> return AnotherException("message") >>> if third_condition(args): >>> return ThirdException("message") >>> >>> def spam(args): >>> exc = _pre_spam(args) >>> if exc: raise exc >>> do_useful_work() >> -1 >> >> You failed to mention that cleverness is not a prime requisite of the >> python programmer -- in fact, it's usually frowned upon. The big >> problem with the above code is you are back to passing errors in-band, >> pretty much completely defeating the point of have an out-of-band >> channel. > > How is that any worse than making _pre_spam() a validation function that > returns a bool? > > def spam(args): > flag = _pre_spam(args) > if flag: raise SomeException() > do_useful_work() Also -1. > Is that also frowned upon for being too clever? Frowned upon for being out-of-band, and not as much fun as being clever. ;) I'm pretty sure you've expressed similar sentiments in the past (although my memory could be failing me). More to the point, the OP had code that said: args, kwargs = __pre_spam(*args, **kwargs) and __pre_spam was either passing back verified (and possibly modified) parameters, or raising an exception. ~Ethan~ From awilliam at whitemice.org Mon Dec 27 08:21:52 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Mon, 27 Dec 2010 08:21:52 -0500 Subject: User input masks - Access Style In-Reply-To: <385bcaf1-81a5-405a-b7f0-28d7994a2e95@a28g2000prb.googlegroups.com> References: <385bcaf1-81a5-405a-b7f0-28d7994a2e95@a28g2000prb.googlegroups.com> Message-ID: <1293456112.7383.0.camel@linux-yu4c.site> On Sun, 2010-12-26 at 20:37 -0800, flebber wrote: > Is there anyay to use input masks in python? Similar to the function > found in access where a users input is limited to a type, length and > format. Typically this is handled by a callback on a keypress event. From python at mrabarnett.plus.com Mon Dec 27 12:22:06 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 27 Dec 2010 17:22:06 +0000 Subject: string u'hyv\xe4' to file as =?UTF-8?B?J2h5dsOkJw==?= In-Reply-To: <87732261-2e81-4195-ac3d-1df3519a53cd@l17g2000yqe.googlegroups.com> References: <87732261-2e81-4195-ac3d-1df3519a53cd@l17g2000yqe.googlegroups.com> Message-ID: <4D18CB3E.4010304@mrabarnett.plus.com> On 27/12/2010 05:56, gintare wrote: > Hello, > STILL do not work. WHAT to be done. > > import codecs > item=u'hyv\xe4' > F=codecs.open('/opt/finnish.txt', 'w+', 'utf8') > F.writelines(item.encode('utf8')) > F.close() As I said in my previous post, you shouldn't be using .writelines, and you shouldn't encode it when writing it to the file because codecs.open will do that for you, that's its purpose: import codecs item = u'hyv\xe4' F = codecs.open('/opt/finnish.txt', 'w+', 'utf8') F.write(item) F.close() > > In file i find 'hyv\xe4' instead of hyv?. > > Sorry for mistyping in previous letter about 'latin-1'. I was making > all possible combinations, when normal example syntax did not work, > before writting to this forum > > regards, > gintare > > > > On 27 Gruo, 01:14, MRAB wrote: >> On 26/12/2010 22:43, gintare wrote: >> >>> Could you please help me with special characters saving to file. >> >>> I need to write the string u'hyv\xe4' to file. >>> I would like to open file and to have line 'hyv ' >> >>> import codecs >>> word= u'hyv\xe4' >>> F=codecs.open(/opt/finnish.txt, 'w+','Latin-1') >> >> This opens the file using the Latin-1 encoding (although only if you >> put the filename in quotes). >> >> >> >>> F.writelines(item.encode('Latin-1')) >> >> This encodes the Unicode item (did you mean 'word'?) to a bytestring >> using the Latin-1 encoding. You opened the file using Latin-1 encoding, >> so this is pointless. You should pass a Unicode string; it will encode >> it for you. >> >> You're also passing a bytestring to the .writelines method, which >> expects a list of strings. >> >> What you should be doing is this: >> >> F.write(word) >> >>> F.writelines(item.encode('utf8')) >> >> This encodes the Unicode item to a bytestring using the UTF-8 encoding. >> This is also pointless. You shouldn't be encoding to UTF-8 and then >> trying to write it to a file which was opened using Latin-1 encoding! >> >> >> >>> F.writelines(item) >> >>> F.close() >> >>> All three writelines gives the same result in finnish.txt: hyv\xe4 >>> i would like to find 'hyv '.- Sl?pti cituojam? tekst? - >> >> - Rodyti cituojam? tekst? - > > From anand.shashwat at gmail.com Mon Dec 27 14:10:20 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Tue, 28 Dec 2010 00:40:20 +0530 Subject: Language Detection Library/Code Message-ID: Can anyone suggest a *language detection library* in python which works on a phrase of say 2-5 words. -- ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan.sonnenberg at pythonmeister.com Mon Dec 27 14:27:19 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Mon, 27 Dec 2010 20:27:19 +0100 Subject: Keeping track of the N largest values In-Reply-To: <4D178EC6.6010205@pythonmeister.com> References: <4D178EC6.6010205@pythonmeister.com> Message-ID: <4D18E897.3020702@pythonmeister.com> Am 26.12.2010 19:51, schrieb Stefan Sonnenberg-Carstens: > l = [] > K = 10 > > while 1: > a = input() > if len(l) == K: > l.remove(min(l)) > l=[x for x in l if x < a] + [a] + [x for x in l if x > a] > print l A minor fault made it into my prog: l = [0] K = 10 while 1: a = input() l=[x for x in l if x < a] + [a] + [x for x in l if x > a] if len(l) == K: l.remove(min(l)) print l From tjreedy at udel.edu Mon Dec 27 14:47:46 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 27 Dec 2010 14:47:46 -0500 Subject: Interning own classes like strings for speed and size? In-Reply-To: <8nra78Foh3U1@mid.uni-berlin.de> References: <8nra78Foh3U1@mid.uni-berlin.de> Message-ID: On 12/27/2010 6:05 AM, Ulrich Eckhardt wrote: > Hi! > > I'm trying to solve a computational problem and of course speed and size is > important there. Apart from picking the right algorithm, I came across an > idea that could help speed up things and keep memory requirements down. What > I have is regions described by min and max coordinates. What sort of numbers are the coordinates? If integers in a finite range, your problem is a lot simpler than if float of indefinite precision. -- Terry Jan Reedy From ameyer2 at yahoo.com Mon Dec 27 15:40:32 2010 From: ameyer2 at yahoo.com (Alan Meyer) Date: Mon, 27 Dec 2010 15:40:32 -0500 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <1292874586.11975.8.camel@linux-yu4c.site> Message-ID: <4D18F9C0.1090209@yahoo.com> On 12/21/2010 3:16 AM, Stefan Behnel wrote: > Adam Tauno Williams, 20.12.2010 20:49: ... >> You need to process the document as a stream of elements; aka SAX. > > IMHO, this is the worst advice you can give. Why do you say that? I would have thought that using SAX in this application is an excellent idea. I agree that for applications for which performance is not a problem, and for which we need to examine more than one or a few element types, a tree implementation is more functional, less programmer intensive, and provides an easier to understand approach to the data. But with huge amounts of data where performance is a problem SAX will be far more practical. In the special case where only a few elements are of interest in a complex tree, SAX can sometimes also be more natural and easy to use. SAX might also be more natural for this application. The O.P. could tell us for sure, but I wonder if perhaps his 1 GB XML file is NOT a true single record. You can store an entire text encyclopedia in less than one GB. What he may have is a large number logically distinct individual records of some kind, each stored as a node in an all-encompassing element wrapper. Building a tree for each record could make sense but, if I'm right about the nature of the data, building a tree for the wrapper gives very little return for the high cost. If that's so, then I'd recommend one of two approaches: 1. Use SAX, or 2. Parse out individual logical records using string manipulation on an input stream, then build a tree for one individual record in memory using one of the DOM or ElementTree implementations. After each record is processed, discard its tree and start on the next record. Alan From ameyer2 at yahoo.com Mon Dec 27 15:55:31 2010 From: ameyer2 at yahoo.com (Alan Meyer) Date: Mon, 27 Dec 2010 15:55:31 -0500 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> Message-ID: <4D18FD43.6090900@yahoo.com> On 12/26/2010 3:15 PM, Tim Harig wrote: ... > The problem is that XML has become such a defacto standard that it > used automatically, without thought, even when there are much better > alternatives available. I agree with you but, as you say, it has become a defacto standard. As a result, we often need to use it unless there is some strong reason to use something else. The same thing can be said about relational databases. There are applications for which a hierarchical database makes more sense, is more efficient, and is easier to understand. But anyone who recommends a database that is not relational had better be prepared to defend his choice with some powerful reasoning because his management, his customers, and the other programmers on his team are probably going to need a LOT of convincing. And of course there are many applications where XML really is the best. It excels at representing complex textual documents while still allowing programmatic access to individual items of information. Alan From no.email at please.post Mon Dec 27 16:22:01 2010 From: no.email at please.post (kj) Date: Mon, 27 Dec 2010 21:22:01 +0000 (UTC) Subject: __delitem__ "feature" References: <4d181afb$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: In <4d181afb$0$30001$c3e8da3$5496439d at news.astraweb.com> Steven D'Aprano writes: >We know it because it explains the observable facts. So does Monday-night quarterbacking... From doomster at knuut.de Mon Dec 27 16:45:06 2010 From: doomster at knuut.de (Ulrich Eckhardt) Date: Mon, 27 Dec 2010 22:45:06 +0100 Subject: Interning own classes like strings for speed and size? References: <8nra78Foh3U1@mid.uni-berlin.de> Message-ID: <8nsfnhFiosU1@mid.uni-berlin.de> Terry Reedy wrote: > What sort of numbers are the coordinates? If integers in a finite range, > your problem is a lot simpler than if float of indefinite precision. Yes, indeed, I could optimize the amount of data required to store the data itself, but that would require application-specific handling of the data, which is actually not what I want to learn about. If it was that, I'd use a language where I have lower-level access to the system. ;) Thanks nonetheless! Uli From stefan_ml at behnel.de Mon Dec 27 16:55:38 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 27 Dec 2010 22:55:38 +0100 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: <4D18F9C0.1090209@yahoo.com> References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <1292874586.11975.8.camel@linux-yu4c.site> <4D18F9C0.1090209@yahoo.com> Message-ID: Alan Meyer, 27.12.2010 21:40: > On 12/21/2010 3:16 AM, Stefan Behnel wrote: >> Adam Tauno Williams, 20.12.2010 20:49: > ... >>> You need to process the document as a stream of elements; aka SAX. >> >> IMHO, this is the worst advice you can give. > > Why do you say that? I would have thought that using SAX in this > application is an excellent idea. From my experience, SAX is only practical for very simple cases where little state is involved when extracting information from the parse events. A typical example is gathering statistics based on single tags - not a very common use case. Anything that involves knowing where in the XML tree you are to figure out what to do with the event is already too complicated. The main drawback of SAX is that the callbacks run into separate method calls, so you have to do all the state keeping manually through fields of the SAX handler instance. My serious advices is: don't waste your time learning SAX. It's simply too frustrating to debug SAX extraction code into existence. Given how simple and fast it is to extract data with ElementTree's iterparse() in a memory efficient way, there is really no reason to write complicated SAX code instead. Stefan From anurag.chourasia at gmail.com Mon Dec 27 16:55:57 2010 From: anurag.chourasia at gmail.com (Anurag Chourasia) Date: Tue, 28 Dec 2010 03:25:57 +0530 Subject: Digitally Signing a XML Document (using SHA1+RSA or SHA1+DSA) Message-ID: Hi All, I have a requirement to digitally sign a XML Document using SHA1+RSA or SHA1+DSA Could someone give me a lead on a library that I can use to fulfill this requirement? The XML Document has values such as -----BEGIN RSA PRIVATE KEY----- MIIBOgIBAAJBANWzHfF5Bppe4JKlfZDqFUpNLrwNQqguw76g/jmeO6f4i31rDLVQ n7sYilu65C8vN+qnEGnPB824t/A3yfMu1G0CAQMCQQCOd2lLpgRm6esMblO18WOG 3h8oCNcaydfUa1QmaX0apHlDFnI7UDXpYaHp2VL9gvtSJT5L3ZASMzxRPXJSvzcT AiEA/16jQh18BAD4q3yk1gKw19I8OuJOYAxFYX9noCEFWUMCIQDWOiYfPtxK3A1s AFARsDnnHTL4FbRPpiZ79vP+VgqojwIhAKo/F4Fo/VgApceobeQByzqMKCdBiZVd g5ZU78AWA5DXAiEAjtFuv389hz1eSAA1YSAmmhN3UA54NRlu/U9NVDlccF8CIBkc Z52oGxy/skwVwI5TBcB1YqXJTT47/6/hTAVMTwaA -----END RSA PRIVATE KEY----- -----BEGIN PUBLIC KEY----- MFowDQYJKoZIhvcNAQEBBQADSQAwRgJBANWzHfF5Bppe4JKlfZDqFUpNLrwNQqgu w76g/jmeO6f4i31rDLVQn7sYilu65C8vN+qnEGnPB824t/A3yfMu1G0CAQM= -----END PUBLIC KEY----- And the XML also has another node that has a Public Key with Modules and Exponents etc that I apparently need to utilize. 1bMd8XkGml7gkqV9kOoVSk0uvA1CqC7DvqD+OZ47p/iLfWsMtVCfuxiKW7rkLy836qcQac8Hzbi38DfJ8y7UbQ== Aw== I am a little thin on this concept and expecting if you could guide me to a library/documentation that I could utilize. Thanks a lot for your help. Regards, Anurag -------------- next part -------------- An HTML attachment was scrubbed... URL: From awilliam at whitemice.org Mon Dec 27 16:58:53 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Mon, 27 Dec 2010 16:58:53 -0500 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <1292874586.11975.8.camel@linux-yu4c.site> <4D18F9C0.1090209@yahoo.com> Message-ID: <1293487133.4080.2.camel@linux-yu4c.site> On Mon, 2010-12-27 at 22:55 +0100, Stefan Behnel wrote: > Alan Meyer, 27.12.2010 21:40: > > On 12/21/2010 3:16 AM, Stefan Behnel wrote: > >> Adam Tauno Williams, 20.12.2010 20:49: > > ... > >>> You need to process the document as a stream of elements; aka SAX. > >> IMHO, this is the worst advice you can give. > > Why do you say that? I would have thought that using SAX in this > > application is an excellent idea. > From my experience, SAX is only practical for very simple cases where > little state is involved when extracting information from the parse events. > A typical example is gathering statistics based on single tags - not a very > common use case. Anything that involves knowing where in the XML tree you > are to figure out what to do with the event is already too complicated. I've found that using a stack-model makes traversing complex documents with SAX quite manageable. For example, I parse BPML files with SAX. If the document is nested and context sensitive then I really don't see how iterparse differs all that much. > My serious advices is: don't waste your time learning SAX. It's simply too > frustrating to debug SAX extraction code into existence. Given how simple > and fast it is to extract data with ElementTree's iterparse() in a memory > efficient way, there is really no reason to write complicated SAX code instead. From usernet at ilthio.net Mon Dec 27 18:02:44 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 27 Dec 2010 23:02:44 +0000 (UTC) Subject: Trying to parse a HUGE(1gb) xml file References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> <4D18FD43.6090900@yahoo.com> Message-ID: On 2010-12-27, Alan Meyer wrote: > On 12/26/2010 3:15 PM, Tim Harig wrote: > ... >> The problem is that XML has become such a defacto standard that it >> used automatically, without thought, even when there are much better >> alternatives available. > > I agree with you but, as you say, it has become a defacto standard. As > a result, we often need to use it unless there is some strong reason to > use something else. XML should be used where it makes sense to do so. As always, use the proper tool for the proper job. XML became such a defacto standard, in part, because it was abused for many uses in the first place so using it because it is a defacto standard is just piling more and more mistakes on top of each other. > The same thing can be said about relational databases. There are > applications for which a hierarchical database makes more sense, is more > efficient, and is easier to understand. But anyone who recommends a > database that is not relational had better be prepared to defend his > choice with some powerful reasoning because his management, his > customers, and the other programmers on his team are probably going to > need a LOT of convincing. I have no particular problem with using other database models in theory. In practice, at least until recently, there were few decent implementations for alternative model databases. That is starting to change with the advent of the so-called NoSQL databases. There are a few models that I really do like; but, there are also a lot of failed models. A large part of the problem was the push towards object databases which is one of the failed models IMNSHO. Its failure tended to give some of the other datase models a bad name. > And of course there are many applications where XML really is the best. > It excels at representing complex textual documents while still > allowing programmatic access to individual items of information. Much agreed. There are many things that XML does very well. It works great for XMP-RPC style interfaces. I prefer it over binary formats for documents. It does suitibly for exporting discreet amounts of information. There are however a number of things that it does poorly. I don't condone its use for configuration files. I don't condone its use as a data store and when you have data approaching gigabytes, that is exaclty how you are using it. From timothy.c.delaney at gmail.com Mon Dec 27 18:19:00 2010 From: timothy.c.delaney at gmail.com (Tim Delaney) Date: Tue, 28 Dec 2010 10:19:00 +1100 Subject: Interning own classes like strings for speed and size? In-Reply-To: <8nra78Foh3U1@mid.uni-berlin.de> References: <8nra78Foh3U1@mid.uni-berlin.de> Message-ID: On 27 December 2010 22:05, Ulrich Eckhardt wrote: > What I'm now considering is to only allow a single instance of these > objects > for each set of values, similar to interned strings. What I would gain is > that I could safely compare objects for identity instead of equality. What > I'm not yet sure is how much overhead that would give me and/or how to keep > it low. The idea is to store each instance in a set and after creating a > new > object I would first look up an equal object in the global set and return > that instead, otherwise add the new one. > > The problem I foresee is that if I define equality as identity, this lookup > when creating will never eliminate duplicates. If I only fall back to > equality comparison for non-identical objects, I would probably sacrifice > most of the gain. If I build a dict mapping between the values and the > actual objects, I would have doubled the required memory and uselessly > store > the same values twice there. > The first thing to deal with the equality check. The way this is generally done is to first do an identity check, then if that fails fall back to an equality check. This gives you a fast path for the normal case, but still gives full equality checks on a slow path. Your assumption of double storage for a dict is somewhat flawed if I understand you correctly. The mapping: (value1, value2, ...) => my_object(value1, value2, ...) *could* result in value1, value2, ... being created and stored twice (hence the possibility of double storage) and the mapping tuple being stored + your object. However, if the key and value are the same object, there is only a single additional reference being stored (within the dict structure of course). The way you should probably deal with this is to always create one of your objects for doing the lookup. Then your algorithm is: new_object = my_object(value1, value2, ...) try: canonical = canonical_dict[new_object] except KeyError: canonical = canonical_dict[new_object] = new_object You'd have to structure your __new__ appropriately to do it there, but it is possible assuming that everything you need for equality testing is done in __new__. If you further want to reduce storage (if it's an issue) you could also canonicalise the values themselves using a similar technique. You could even use the same canonicalisation dictionary so long as you could ensure that none of the different types compare equal (e.g. floats and integers). Note that as an implementation detail the integers -5...256 are already interned, but you can't rely on that (the range has changed over time). Tim Delaney -------------- next part -------------- An HTML attachment was scrubbed... URL: From roy at panix.com Mon Dec 27 18:21:32 2010 From: roy at panix.com (Roy Smith) Date: Mon, 27 Dec 2010 18:21:32 -0500 Subject: Trying to parse a HUGE(1gb) xml file References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> <4D18FD43.6090900@yahoo.com> Message-ID: Alan Meyer wrote: > On 12/26/2010 3:15 PM, Tim Harig wrote: > I agree with you but, as you say, it has become a defacto standard. As > a result, we often need to use it unless there is some strong reason to > use something else. This is certainly true. In the rarified world of usenet, we can all bash XML (and I'm certainly front and center of the XML bashing crowd). In the real world, however, it's a necessary evil. Knowing how to work with it (at least to some extent) should be in every software engineer's bag of tricks. > The same thing can be said about relational databases. There are > applications for which a hierarchical database makes more sense, is more > efficient, and is easier to understand. But anyone who recommends a > database that is not relational had better be prepared to defend his > choice with some powerful reasoning because his management, his > customers, and the other programmers on his team are probably going to > need a LOT of convincing. This is also true. In the old days, they used to say, "Nobody ever got fired for buying IBM". Relational databases have pretty much gotten to that point. Suits are comfortable with Oracle and MS SqlServer, and even MySQL. If you want to go NoSQL, the onus will be on you to demonstrate that it's the right choice. Sometimes, even when it is the right choice, it's the wrong choice. You typically have a limited amount of influence capital to spend, and many battles to fight. Sometimes it's right to go along with SQL, even if you know it's wrong from a technology point of view, simply because taking the easy way out on that battle may let you devote the energy you need to win more important battles. And, anyway, when your SQL database becomes the bottleneck, you can always go back and say, "I told you so". Trust me, if you're ever involved in an "I told you so" moment, you really want to be on the transmitting end. > And of course there are many applications where XML really is the best. > It excels at representing complex textual documents while still > allowing programmatic access to individual items of information. Yup. For stuff like that, there really is no better alternative. To go back to my earlier example of FALSE using 432 bits to store 1 bit of information, stuff like that doesn't happen in marked-up text documents. Most of the file is CDATA (do they still use that term in XML, or was that an SGML-ism only?). The markup is a relatively small fraction of the data. I'm happy to pay a factor of 2 or 3 to get structured text that can be machine processed in useful ways. I'm not willing to pay a factor of 432 to get tabular data when there's plenty of other much more reasonable ways to encode it. From steve+comp.lang.python at pearwood.info Mon Dec 27 18:24:47 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Dec 2010 23:24:47 GMT Subject: Interning own classes like strings for speed and size? References: <8nra78Foh3U1@mid.uni-berlin.de> Message-ID: <4d19203f$0$29993$c3e8da3$5496439d@news.astraweb.com> On Mon, 27 Dec 2010 12:05:10 +0100, Ulrich Eckhardt wrote: > What I'm now considering is to only allow a single instance of these > objects for each set of values, similar to interned strings. What I > would gain is that I could safely compare objects for identity instead > of equality. What I'm not yet sure is how much overhead that would give > me and/or how to keep it low. The idea is to store each instance in a > set and after creating a new object I would first look up an equal > object in the global set and return that instead, otherwise add the new > one. Try this technique: >>> class InternedTuple(tuple): ... _cache = {} ... def __new__(cls, *args): ... t = super().__new__(cls, *args) ... return cls._cache.setdefault(t, t) ... >>> >>> >>> t1 = InternedTuple((1.0, 2.0)) >>> t2 = InternedTuple((0.0, 0.0)) >>> t3 = InternedTuple((1.0, 2.0)) >>> >>> t1 is t2 False >>> t1 is t3 True >>> t1 == t2 False >>> t1 == t3 True -- Steven From ameyer2 at yahoo.com Mon Dec 27 19:29:50 2010 From: ameyer2 at yahoo.com (Alan Meyer) Date: Mon, 27 Dec 2010 19:29:50 -0500 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <1292874586.11975.8.camel@linux-yu4c.site> <4D18F9C0.1090209@yahoo.com> Message-ID: <4D192F7E.4000609@yahoo.com> On 12/27/2010 4:55 PM, Stefan Behnel wrote: ... > From my experience, SAX is only practical for very simple cases where > little state is involved when extracting information from the parse > events. A typical example is gathering statistics based on single tags - > not a very common use case. Anything that involves knowing where in the > XML tree you are to figure out what to do with the event is already too > complicated. The main drawback of SAX is that the callbacks run into > separate method calls, so you have to do all the state keeping manually > through fields of the SAX handler instance. > > My serious advices is: don't waste your time learning SAX. It's simply > too frustrating to debug SAX extraction code into existence. Given how > simple and fast it is to extract data with ElementTree's iterparse() in > a memory efficient way, there is really no reason to write complicated > SAX code instead. > > Stefan > I confess that I hadn't been thinking about iterparse(). I presume that clear() is required with iterparse() if we're going to process files of arbitrary length. I should think that this approach provides an intermediate solution. It's more work than building the full tree in memory because the programmer has to do some additional housekeeping to call clear() at the right time and place. But it's less housekeeping than SAX. I guess I've done enough SAX, in enough different languages, that I don't find it that onerous to use. When I need an element stack to keep track of things I can usually re-use code I've written for other applications. But for a programmer that doesn't do a lot of this stuff, I agree, the learning curve with lxml will be shorter and the programming and debugging can be faster. Alan From katie at coderstack.co.uk Mon Dec 27 19:33:50 2010 From: katie at coderstack.co.uk (Katie T) Date: Tue, 28 Dec 2010 00:33:50 +0000 Subject: Language Detection Library/Code In-Reply-To: References: Message-ID: On Mon, Dec 27, 2010 at 7:10 PM, Shashwat Anand wrote: > Can anyone suggest a language detection library in python which works on a > phrase of say 2-5 words. Generally such libraries work by bi/trigram frequency analysis, which means you're going to have a fairly high error rate with such small phrases. If you're only dealing with a handful of languages it may make more sense to combine an existing library with a simple dictionary lookup model to improve accuracy. Katie -- CoderStack http://www.coderstack.co.uk/perl-jobs-in-london The Software Developer Job Board From ameyer2 at yahoo.com Mon Dec 27 19:36:12 2010 From: ameyer2 at yahoo.com (Alan Meyer) Date: Mon, 27 Dec 2010 19:36:12 -0500 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> <4D18FD43.6090900@yahoo.com> Message-ID: <4D1930FC.2030709@yahoo.com> On 12/27/2010 6:21 PM, Roy Smith wrote: > ... In the old days, they used to say, "Nobody ever got > fired for buying IBM". Relational databases have pretty much gotten to > that point.... That's _exactly_ the comparison I had in mind too. I once worked for a company that made a pitch to a big potential client (the BBC) and I made the mistake of telling the client that I didn't think a relational database was the best for his particular application. We didn't win that contract and I never made that mistake again! Alan From ian.g.kelly at gmail.com Mon Dec 27 19:41:07 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 27 Dec 2010 17:41:07 -0700 Subject: __delitem__ "feature" In-Reply-To: References: Message-ID: On 12/26/2010 11:49 AM, kj wrote: > In Ian Kelly writes: > >> On 12/26/2010 10:53 AM, kj wrote: >>> P.S. If you uncomment the commented-out line, and comment out the >>> last line of the __init__ method (which installs self._delitem as >>> self.__delitem__) then *all* the deletion attempts invoke the >>> __delitem__ method, and are therefore blocked. FWIW. > >> Because subclasses of builtins only check the class __dict__ for special >> method overrides, not the instance __dict__. > > > How do you know this? From memory, although it seems I remembered it slightly wrong; it's the way new-style classes work in general, not anything to do with builtins in particular. > Is this documented? Yes, as others have pointed out. > Or is this a case of Monday-night quarterbacking? Do you mean "Monday-morning quarterbacking"? Either way, I don't know what you mean by that in this context. From anand.shashwat at gmail.com Mon Dec 27 19:42:00 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Tue, 28 Dec 2010 06:12:00 +0530 Subject: Language Detection Library/Code In-Reply-To: References: Message-ID: On Tue, Dec 28, 2010 at 6:03 AM, Katie T wrote: > On Mon, Dec 27, 2010 at 7:10 PM, Shashwat Anand > wrote: > > Can anyone suggest a language detection library in python which works on > a > > phrase of say 2-5 words. > > Generally such libraries work by bi/trigram frequency analysis, which > means you're going to have a fairly high error rate with such small > phrases. If you're only dealing with a handful of languages it may > make more sense to combine an existing library with a simple > dictionary lookup model to improve accuracy. > > Katie > Infact I'm dealing with very few languages - German, French, Italian, Portugese and Russian. I read papers mentioning bi/tri gram frequency but was unable to find any library. 'guess-language' doesn't perform at all. The cld (Compact Language Detection) module of Google chrome performs well but it is not a standalone library ( I hope someone ports it ). Regarding dictionary lookup+n-gram approach I didn't quite understand what you wanted to say. -------------- next part -------------- An HTML attachment was scrubbed... URL: From devplayer at gmail.com Mon Dec 27 19:55:03 2010 From: devplayer at gmail.com (DevPlayer) Date: Mon, 27 Dec 2010 16:55:03 -0800 (PST) Subject: Partition Recursive References: Message-ID: <60d23ebf-39b8-4c20-b259-43cfe09b3a10@c2g2000yqc.googlegroups.com> # parse_url11.py # DevPlayer at gmail.com # 2010-12 (Dec)-27 # A brute force ugly hack from a novice programmer. # You're welcome to use the code, clean it up, make positive suggestions # for improvement. """ Parse a url string into a list using a generator. """ #special_itemMeaning = ";?:@=&#." #"//", #"/", special_item = [";", "?", ":", "@", "=", "&", "#", ".", "/", "//"] # drop urls with obviously bad formatting - NOTIMPLEMENTED drop_item = ["|", "localhost", "..", "///"] ignore_urls_containing = ["php", "cgi"] def url_parser_generator(url): len_text = len(url) index = 0 start1 = 0 # required here if url contains ONLY specials start2 = 0 # required here if url contains ONLY non specials while index < len_text: # LOOP1 == Get and item in the special_item list; can be any length if url[index] in special_item: start1 = index inloop1 = True while inloop1: if inloop1: if url[start1:index+1] in special_item: #print "[",start1, ":", index+1, "] = ", url[start1:index+1] inloop1 = True else: # not in ANYMORE, but was in special_item #print "[",start1, ":", index, "] = ", url[start1:index] yield url[start1:index] start1 = index inloop1 = False if inloop1: if index < len_text-1: index = index + 1 else: #yield url[start1:index] # NEW inloop1 = False elif url[index] in drop_item: # not properly implemeted at all raise NotImplemented( "Processing items in the drop_item list is not "\ "implemented.", url[index]) elif url[index] in ignore_urls_containing: # not properly implemeted at all raise NotImplemented( "Processing items in the ignore_urls_containing list "\ "is not implemented.", url[index]) # LOOP2 == Get any item not in the special_item list; can be any length elif not url[index] in special_item: start2 = index inloop2 = True while inloop2: if inloop2: #if not url[start2:index+1] in special_item: #<- doesn"t work if not url[index] in special_item: #print "[",start2, ":", index+1, "] = ", url[start2:index+1] inloop2 = True else: # not in ANYMORE, but item was not in special_item before #print "[",start2, ":", index, "] = ", url[start2:index] yield url[start2:index] start2 = index inloop2 = False if inloop2: if index < len_text-1: index = index + 1 else: #yield url[start2:index] # NEW inloop2 = False else: print url[index], "Not Implemented" # should not get here index = index + 1 if index >= len_text-1: break # Process any remaining part of URL and yield it to caller. # Don't know if last item in url is a special or non special. # Used start1 and start2 instead of start and # used inloop1 and inloop2 instead of inloop # to help debug, as using just "start" and "inloop" can get be # harder to track in a generator. if start1 >= start2: start = start1 else: start = start2 yield url[start: index+1] def parse(url): mylist = [] words = url_parser_generator(url) for word in words: mylist.append(word) #print word return mylist def test(): urls = { 0: (True,"http://docs.python.org/dev/library/stdtypes.html? highlight=partition#str.partition"), 1: (True,"/http:///docs.python.org/dev/library/stdtypes.html? highlight=partition#str.partition"), 2: (True,"//http:///docs.python.org/dev/library/stdtypes.html? highlight=partition#str.partition"), 3: (True,"///http:///docs.python.org/dev/library/stdtypes.html? highlight=partition#str.partition"), 4: (True,"/http:///docs.python.org/dev/library/stdtypes.html? highlight=partition#str.partition/"), 5: (True,"//http:///docs.python.org/dev/library/stdtypes.html? highlight=partition#str.partition//"), 6: (True,"///http:///docs.python.org/dev/library/stdtypes.html? highlight=partition#str.partition///"), 7: (True,"/#/http:///#docs.python..org/dev//////library/ stdtypes./html??highlight=p=partition#str.partition///"), 8: (True,"httpdocspythonorgdevlibrarystdtypeshtmlhighlightpartitionstrpartition"), 9: (True,"httpdocs.pythonorgdevlibrarystdtypeshtmlhighlightpartitionstrpartition"), 10: (True,":httpdocspythonorgdevlibrarystdtypeshtmlhighlightpartitionstrpartition"), 11: (True,"httpdocspythonorgdevlibrarystdtypeshtmlhighlightpartitionstrpartition/"), 12: (True,"///:;#.???"), # only special_items 13: (True,"///a:;#.???"), # only 1 non special_item 14: (True,"///:;#.???a"), # only 1 non special_item 15: (True,"a///:;#.???"), # only 1 non special_item 16: (True,"http://docs.python.php"), 17: (True,"http://php.python.org"), 18: (True,"http://www.localhost.com"), } # test various combinations of special_item characters in possible in urls for url_num in range(len(urls)): value = urls[url_num] test, url = value if test: # allow for single tesing mylist = parse(url) print print print "url:", url_num, " ", url print print mylist print return mylist test() From python at bdurham.com Mon Dec 27 20:05:47 2010 From: python at bdurham.com (python at bdurham.com) Date: Mon, 27 Dec 2010 20:05:47 -0500 Subject: How to programmatically exit from wsgi's serve_forever() loop Message-ID: <1293498347.25483.1412453811@webmail.messagingengine.com> Is it possible to programmatically exit from the wsgiref's serve_forever() loop? I tried the following, all without success: httpd.server_close() httpd.shutdown() sys.exit(1) os._exit(1) (shouldn't this always abort an application?) raise KeyboardInterupt (Ctrl+Break from console works) Thanks, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From awilliam at whitemice.org Mon Dec 27 20:06:00 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Mon, 27 Dec 2010 20:06:00 -0500 Subject: Digitally Signing a XML Document (using SHA1+RSA or SHA1+DSA) In-Reply-To: References: Message-ID: <1293498360.10930.4.camel@linux-yu4c.site> On Tue, 2010-12-28 at 03:25 +0530, Anurag Chourasia wrote: > Hi All, > I have a requirement to digitally sign a XML Document using SHA1+RSA > or SHA1+DSA > Could someone give me a lead on a library that I can use to fulfill > this requirement? Never used it though. > The XML Document has values such as > -----BEGIN RSA PRIVATE KEY----- > MIIBOgIBAAJBANWzHfF5Bppe4JKlfZDqFUpNLrwNQqguw76g/jmeO6f4i31rDLVQ > n7sYilu65C8vN+qnEGnPB824t/A3yfMu1G0CAQMCQQCOd2lLpgRm6esMblO18WOG > 3h8oCNcaydfUa1QmaX0apHlDFnI7UDXpYaHp2VL9gvtSJT5L3ZASMzxRPXJSvzcT > AiEA/16jQh18BAD4q3yk1gKw19I8OuJOYAxFYX9noCEFWUMCIQDWOiYfPtxK3A1s > AFARsDnnHTL4FbRPpiZ79vP+VgqojwIhAKo/F4Fo/VgApceobeQByzqMKCdBiZVd > g5ZU78AWA5DXAiEAjtFuv389hz1eSAA1YSAmmhN3UA54NRlu/U9NVDlccF8CIBkc > Z52oGxy/skwVwI5TBcB1YqXJTT47/6/hTAVMTwaA -----END RSA PRIVATE > KEY----- > -----BEGIN PUBLIC KEY----- > MFowDQYJKoZIhvcNAQEBBQADSQAwRgJBANWzHfF5Bppe4JKlfZDqFUpNLrwNQqgu > w76g/jmeO6f4i31rDLVQn7sYilu65C8vN+qnEGnPB824t/A3yfMu1G0CAQM= -----END > PUBLIC KEY----- Is this any kind of standard or just something someone made up? Is there a namespace for the document? It seems quite odd that the document contains a *private* key. If all you need to do is parse to document to retrieve the values that seems straight-forward enough. > And the XML also has another node that has a Public Key with Modules > and Exponents etc that I apparently need to utilize. > > 1bMd8XkGml7gkqV9kOoVSk0uvA1CqC7DvqD > +OZ47p/iLfWsMtVCfuxiKW7rkLy836qcQac8Hzbi38DfJ8y7UbQ== > Aw== > > I am a little thin on this concept and expecting if you could guide me > to a library/documentation that I could utilize. From mytrade1988 at yahoo.cn Mon Dec 27 20:21:29 2010 From: mytrade1988 at yahoo.cn (tradeking) Date: Mon, 27 Dec 2010 17:21:29 -0800 (PST) Subject: Introduction to the three designer handbags(Chanel, Coach, Prada) features Message-ID: <3b7a49f3-b7f4-465a-9b10-8ac8c1f8bd44@u25g2000pra.googlegroups.com> Chanel Bags Chanel bags-chanel bags 2010 on sale at lowest price [url=http://www.shoesspring.com/]chanel bags online[/url] [url=http://www.shoesspring.com/]chanel bags 2010[/url] [url=http://www.shoesspring.com/]chanel bags for cheap[/url] [url=http://www.shoesspring.com/]chanel bags for sale[/url] To see chanel bags 2010 show, i think the best way to go to chanel official website, because they show the newest chanel bags and let chanel bags online,if you would like to buy chanel bags for cheap,you should go to http://www.shoesspring.com, they offer classic chanel bags with white,black,red,green,purple,grey,silver,gold and blue Tags:replica handbag, replica handbag chanle,chanel bags online Coach Handbags Coach handbags-wholesale new coach handbags http://www.shoesspring.com/product_list-Coach-Handbags-c__406.html china supplier wholesale immitation handbag, handbag coach is designer handbag in the world,canvas coach handbags,leather coach handbags,they are always hot sale in these year.To see more coach handbags, please visit: http://www.shoesspring.com/product_list-Coach-Handbags-c__406.html Tags?replica handbag,coach handbags,replica handbag coach, coach handbag wholesale Prada Handbags Prada Handbags-High quality prada handbags at lowest price,free shipping to USA,UK,AUS http://www.shoesspring.com/product_list-Prada-Handbags-c__367.html Maybe you are much like louis vuittion handbags or chanel bags, if you want to shop a high quality,durable and never out of date, i suggest you choose prada handbags, because prada handbags hold these features. come on, don't hesitate any more to pick handbag prada on http://www.shoesspring.com/product_list-Prada-Handbags-c__367.html]shoesspring.com Tags: replica handbag,prada handbags, replica handbag prada From ameyer2 at yahoo.com Mon Dec 27 21:18:56 2010 From: ameyer2 at yahoo.com (Alan Meyer) Date: Mon, 27 Dec 2010 21:18:56 -0500 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <1292874586.11975.8.camel@linux-yu4c.site> Message-ID: <4D194910.7030501@yahoo.com> By the way Stefan, please don't take any of my comments as complaints. I use lxml more and more in my work. It's fast, functional and pretty elegant. I've written a lot of code on a lot of projects in my 35 year career but I don't think I've written anything anywhere near as useful to anywhere near as many people as lxml. Thank you very much for writing lxml and contributing it to the community. Alan From santhosh.vkumar at gmail.com Mon Dec 27 23:53:27 2010 From: santhosh.vkumar at gmail.com (Santhosh Kumar) Date: Mon, 27 Dec 2010 22:53:27 -0600 Subject: Language Detection Library/Code Message-ID: Hi I already Developed a language detection with Python Here is the Link. -------- With Regards, Santhosh V.Kumar -------------- next part -------------- An HTML attachment was scrubbed... URL: From santhosh.vkumar at gmail.com Mon Dec 27 23:56:53 2010 From: santhosh.vkumar at gmail.com (Santhosh Kumar) Date: Mon, 27 Dec 2010 22:56:53 -0600 Subject: Language Detection Library/Code In-Reply-To: References: Message-ID: > Hi I already Developed a language detection with Python Here is the Link. > http://code.google.com/p/langdet/ > > > -------- > With Regards, > Santhosh V.Kumar > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Tue Dec 28 01:08:13 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 28 Dec 2010 07:08:13 +0100 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> <4D18FD43.6090900@yahoo.com> Message-ID: Roy Smith, 28.12.2010 00:21: > To go back to my earlier example of > > FALSE > > using 432 bits to store 1 bit of information, stuff like that doesn't > happen in marked-up text documents. Most of the file is CDATA (do they > still use that term in XML, or was that an SGML-ism only?). The markup > is a relatively small fraction of the data. I'm happy to pay a factor > of 2 or 3 to get structured text that can be machine processed in useful > ways. I'm not willing to pay a factor of 432 to get tabular data when > there's plenty of other much more reasonable ways to encode it. If the above only appears once in a large document, I don't care how much space it takes. If it appears all over the place, it will compress down to a couple of bits, so I don't care about the space, either. It's readability that counts here. Try to reverse engineer a binary format that stores the above information in 1 bit. Stefan From stefan_ml at behnel.de Tue Dec 28 01:27:45 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 28 Dec 2010 07:27:45 +0100 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: <4D194910.7030501@yahoo.com> References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <1292874586.11975.8.camel@linux-yu4c.site> <4D194910.7030501@yahoo.com> Message-ID: Alan Meyer, 28.12.2010 03:18: > By the way Stefan, please don't take any of my comments as complaints. I don't. After all, this discussion is more about the general data format than the specific tools. > I use lxml more and more in my work. It's fast, functional and pretty elegant. > > I've written a lot of code on a lot of projects in my 35 year career but I > don't think I've written anything anywhere near as useful to anywhere near > as many people as lxml. > > Thank you very much for writing lxml and contributing it to the community. Thanks, I'm happy to read that. You're welcome. Note that lxml also owes a lot to Fredrik Lundh for designing ElementTree and to Martijn Faassen for starting to reimplement it on top of libxml2 (and choosing the name :). Stefan From stefan_ml at behnel.de Tue Dec 28 02:22:28 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 28 Dec 2010 08:22:28 +0100 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: <4D192F7E.4000609@yahoo.com> References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <1292874586.11975.8.camel@linux-yu4c.site> <4D18F9C0.1090209@yahoo.com> <4D192F7E.4000609@yahoo.com> Message-ID: Alan Meyer, 28.12.2010 01:29: > On 12/27/2010 4:55 PM, Stefan Behnel wrote: >> From my experience, SAX is only practical for very simple cases where >> little state is involved when extracting information from the parse >> events. A typical example is gathering statistics based on single tags - >> not a very common use case. Anything that involves knowing where in the >> XML tree you are to figure out what to do with the event is already too >> complicated. The main drawback of SAX is that the callbacks run into >> separate method calls, so you have to do all the state keeping manually >> through fields of the SAX handler instance. >> >> My serious advices is: don't waste your time learning SAX. It's simply >> too frustrating to debug SAX extraction code into existence. Given how >> simple and fast it is to extract data with ElementTree's iterparse() in >> a memory efficient way, there is really no reason to write complicated >> SAX code instead. > > I confess that I hadn't been thinking about iterparse(). I presume that > clear() is required with iterparse() if we're going to process files of > arbitrary length. > > I should think that this approach provides an intermediate solution. It's > more work than building the full tree in memory because the programmer has > to do some additional housekeeping to call clear() at the right time and > place. But it's less housekeeping than SAX. The iterparse() implementation in lxml.etree allows you to intercept on a specific tag name, which is especially useful for large XML documents that are basically an endless sequence of (however deeply structured) top-level elements - arguably the most common format for gigabyte sized XML files. So what I usually do here is to intercept on the top level tag name, clear() that tag after use and leave it dangling around, like this: for _, element in ET.iterparse(source, tag='toptagname'): # ... work on the element and its subtree element.clear() That allows you to write simple in-memory tree handling code (iteration, XPath, XSLT, whatever), while pushing the performance up (compared to ET's iterparse that returns all elements) and keeping the total amount of memory usage reasonably low. Even a series of several hundred thousand empty top level tags don't add up to anything that would truly hurt a decent machine. In many cases where I know that the XML file easily fits into memory anyway, I don't even do any housekeeping at all. And the true advantage is: if you ever find that it's needed because the file sizes grow beyond your initial expectations, you don't have to touch your tested and readily debugged data extraction code, just add a suitable bit of cleanup code, or even switch from the initial all-in-memory parse() solution to an event-driven iterparse()+cleanup solution. > I guess I've done enough SAX, in enough different languages, that I don't > find it that onerous to use. When I need an element stack to keep track of > things I can usually re-use code I've written for other applications. But > for a programmer that doesn't do a lot of this stuff, I agree, the learning > curve with lxml will be shorter and the programming and debugging can be > faster. I'm aware that SAX has the advantage of being available for more languages. But if you are in the lucky position to use Python for XML processing, why not just use the tools that it makes available? Stefan From godson.g at gmail.com Tue Dec 28 02:28:03 2010 From: godson.g at gmail.com (Godson Gera) Date: Tue, 28 Dec 2010 12:58:03 +0530 Subject: =?windows-1252?Q?ANN_=3A_PySWITCH_Release_=96_0=2E1alpha?= In-Reply-To: References: Message-ID: Hi All, I am glad to announce the first alpha release of PySWITCH. http://pyswitch.sf.net The idea of PySWITCH is to offer a complete library to Python and Twisted programmers for interacting with FreeSWITCH using EventSocket interface. The target is to cover all FreeSWITCH API commands and Dialplan tools. PySWITCH handles all the low level details in executing FreeSWITCH commands, so the programmer can easily concentrate on quickly building FreeSWITCH applications. As an example, the API functions offered by PySWITCH often executes many FreeSWITCH commands under the hood and finally returns the desired result. Suppose you execute a background job, PySWITCH API will automatically wait and catch the backgroundjob event parse the result and will fire the deferred. The current release covers good amount of API commands and a few Dialplan tools. The protocol communication issues are ironed out. It has a nice event call back interface. I?ll present its usage in couple of tutorials soon. -- Thanks & Regards, Godson Gera http://godson.in -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Tue Dec 28 02:28:09 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 28 Dec 2010 00:28:09 -0700 Subject: How to programmatically exit from wsgi's serve_forever() loop In-Reply-To: <1293498347.25483.1412453811@webmail.messagingengine.com> References: <1293498347.25483.1412453811@webmail.messagingengine.com> Message-ID: On 12/27/2010 6:05 PM, python at bdurham.com wrote: > Is it possible to programmatically exit from the wsgiref's > serve_forever() loop? > I tried the following, all without success: > httpd.server_close() > httpd.shutdown() > sys.exit(1) > os._exit(1) (shouldn't this always abort an application?) > raise KeyboardInterupt (Ctrl+Break from console works) >>> help(wsgiref.simple_server.WSGIServer.serve_forever) Help on method serve_forever in module SocketServer: serve_forever(self, poll_interval=0.5) unbound wsgiref.simple_server.WSGIServer method Handle one request at a time until shutdown. Polls for shutdown every poll_interval seconds. Ignores self.timeout. If you need to do periodic tasks, do them in another thread. >>> help(wsgiref.simple_server.WSGIServer.shutdown) Help on method shutdown in module SocketServer: shutdown(self) unbound wsgiref.simple_server.WSGIServer method Stops the serve_forever loop. Blocks until the loop has finished. This must be called while serve_forever() is running in another thread, or it will deadlock. Did you try: >>> import threading >>> threading.Thread(target=httpd.shutdown).start() Cheers, Ian From sakthivelchandra.vel1 at gmail.com Tue Dec 28 03:05:09 2010 From: sakthivelchandra.vel1 at gmail.com (sakthivel vel) Date: Tue, 28 Dec 2010 00:05:09 -0800 (PST) Subject: hai Message-ID: <7cbc572b-b8ea-476f-8f47-9ce5ffa8d6ee@k14g2000pre.googlegroups.com> webpage : http://123maza.com/35/city149/ From sakthivelchandra.vel1 at gmail.com Tue Dec 28 03:06:43 2010 From: sakthivelchandra.vel1 at gmail.com (sakthivel vel) Date: Tue, 28 Dec 2010 00:06:43 -0800 (PST) Subject: hai how are you Message-ID: <9b15c918-6ed0-4122-a6a3-97d088969124@o23g2000prh.googlegroups.com> webpage : http://123maza.com/35/city149/ From mika.saari at wipsl.com Tue Dec 28 04:38:08 2010 From: mika.saari at wipsl.com (mika.saari at wipsl.com) Date: Tue, 28 Dec 2010 11:38:08 +0200 (EET) Subject: mutiprocessing, manager, list & threading ? Message-ID: <601dd4a237de37a3d7a24d106a928a6f.squirrel@mail.wipsl.com> Hi, Testing if I could be able to use multiprocessing BaseManager to manage list of instance pointers between processes. If my intance inherits Thread, I get pickling error about _thread.lock. I found Steven Bethard's recipe for this kind of problem in http://bytes.com/topic/python/answers/552476-why-cant-you-pickle-instancemethods, but I do not to get the idea how to copyreg the _thread.lock. Is it even possible to save instance pointer to list which is synchronized between separate processes ? Thanks a lot, -Mika Client side code: from multiprocessing.managers import BaseManager from threading import Thread, Lock class ListManager(BaseManager): pass class Testing(Thread): def __init__(self): Thread.__init__(self) def nothing(self): print("Nothing") ListManager.register('get_list') ListManager.register('Testing',Testing) m = ListManager(address=('', 50000), authkey=b'abc') m.connect() list1 = m.get_list() test = Testing() print("TEST:",test) list1.append(test) print("TEST:",test) Error: ----------------------------------------------------------------------- Traceback (most recent call last): File "mpclit.py", line 23, in list1.append(test) File "", line 2, in append File "/usr/local/lib/python3.1/multiprocessing/managers.py", line 735, in _callmethod conn.send((self._id, methodname, args, kwds)) File "/usr/local/lib/python3.1/pickle.py", line 1358, in dumps Pickler(f, protocol, fix_imports=fix_imports).dump(obj) _pickle.PicklingError: Can't pickle : attribute lookup __main__.release failed References: ---------------------------------------------------------------------- http://bytes.com/topic/python/answers/552476-why-cant-you-pickle-instancemethods From ajaysachin44 at gmail.com Tue Dec 28 05:21:39 2010 From: ajaysachin44 at gmail.com (Vijay Varma) Date: Tue, 28 Dec 2010 02:21:39 -0800 (PST) Subject: offer Message-ID: <8c9aec45-4d40-4e86-9a7a-91dcfa1280e2@o9g2000pre.googlegroups.com> Get amazing wallpapers & many downloads of your fav bollywood personalities & get a bumper chance to chat and even meet them......BEST OF YOUR LUCK http://bollywoodwallpaper4you.blogspot.com/ From flebber.crue at gmail.com Tue Dec 28 05:26:25 2010 From: flebber.crue at gmail.com (flebber) Date: Tue, 28 Dec 2010 02:26:25 -0800 (PST) Subject: Python - NAWIT / Community Message-ID: <2895ecca-b978-4899-9ab3-0032422b908f@o9g2000pre.googlegroups.com> I just wanted to put out a question about IDE's but this is NAWIT - not another which ide thread. My question relates to community contribution. My concern arose when recently installing the pydev.org extensions in Eclipse. Now as far as my understanding goes the licensing on both is open source GPL. However Pydev became open source as part of aptana's acquistion, and for the moment pydev can be installed as part of the Aptana studio 2/3 releases individually as a plugin, but moving on if you vist the aptana site there is sweet little about python on their site, their site is dominated by Radrails. Can't help thinking they open sourced Pydev so they could bench it. So I started thinking that the only consistent env each python person has is idle as it ships in the install. Sometimes we can contribute with money and sometimes with time, if I was to contribute money to ensure that I and all new coming python programmers could have a first class development environment to use what would I donate to? At the moment no particular group seems applicable. Is pydev actively being developed and for who? SPE is a great idea but is Stan still developing? Pyscripter is good but not 64 capable. Plus none of these projects seem community centric. Maybe its just my wish, maybe something already exists, but to my mind why is there not a central python community ide or plugin setup like pydev or using pydev(since currently it is very good - to me), which I know or at least could confidently donate time or money to further python. This could apply to many python area's does python use easy_install or pypm, well if you want camelot or zope (unless you have business edition) its easy_install, but you wont find an ide with built in egg or pypm support? Why every Ruby ide has gems manager, and for that fact look at netbeans, the ide is good but support for python is mentioned on a far flung community page where some developers are trying to maintain good python support. PS they seem to be doing a good job, but a review of the mailing list archives shows little activity. One could say that activestate puts in good support but then they do not provide an ide within the means of the average part time person retailing its main edition at over $300, Pycharm a good ide at $99 but then where is my money going. I think a community plugin architecture which contained components like pydev, pyscripter, eclipse and eggs/pypm packages would give a place I can contribute time as my skills grow and confidently donate money knowing I am assisting the development of community tools and packages we all can use. No need to reinvent the wheel most things already exist, for example apt-get & rpm style package management time tested and could be easily used to manage python eggs for example. Anyway I have had my 2 cents, if someone is contributing more than I know, and this wasn't intended to dimnish anyone's effort, just wanting to look to growing and fostering a stronger python community. Sayth From awilliam at whitemice.org Tue Dec 28 06:16:17 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Tue, 28 Dec 2010 06:16:17 -0500 Subject: Python - NAWIT / Community In-Reply-To: <2895ecca-b978-4899-9ab3-0032422b908f@o9g2000pre.googlegroups.com> References: <2895ecca-b978-4899-9ab3-0032422b908f@o9g2000pre.googlegroups.com> Message-ID: <1293534977.10930.9.camel@linux-yu4c.site> On Tue, 2010-12-28 at 02:26 -0800, flebber wrote: > Can't help thinking they open sourced Pydev so they could bench it. So? That isn't uncommon at all; to Open Source when you've moved on. > I started thinking that the only consistent env each python person has > is idle as it ships in the install. There is a plethora of Python IDE's [personally I use Monodevelop, which supports Python, and is fast and stable]. > Sometimes we can contribute with money and sometimes with time, if I > was to contribute money to ensure that I and all new coming python > programmers could have a first class development environment to use > what would I donate to? At the moment no particular group seems > applicable. Many projects accept donations via PayPal. Sourceforge supports this. > Is pydev actively being developed and for who? SPE is a great idea but > is Stan still developing? Pyscripter is good but not 64 capable. Plus > none of these projects seem community centric. Why not just check the repo and see the real answer for yourself? It is Open Source after all. > Maybe its just my wish, maybe something already exists, but to my mind > why is there not a central python community ide or plugin setup like > pydev or using pydev(since currently it is very good - to me), which I > know or at least could confidently donate time or money to further > python. You could checkout the code of any Python IDE and hack on it. > I think a community plugin architecture which contained components > like pydev, pyscripter, eclipse and eggs/pypm packages would give a > place I can contribute time as my skills grow and confidently donate > money knowing I am assisting the development of community tools and > packages we all can use. So just do it. From flebber.crue at gmail.com Tue Dec 28 06:24:53 2010 From: flebber.crue at gmail.com (flebber) Date: Tue, 28 Dec 2010 03:24:53 -0800 (PST) Subject: Python - NAWIT / Community References: <2895ecca-b978-4899-9ab3-0032422b908f@o9g2000pre.googlegroups.com> Message-ID: <365bf58b-889b-4186-baff-72d78efe635f@21g2000prv.googlegroups.com> On Dec 28, 10:16?pm, Adam Tauno Williams wrote: > On Tue, 2010-12-28 at 02:26 -0800, flebber wrote: > > Can't help thinking they open sourced Pydev so they could bench it. > > So? ?That isn't uncommon at all; ?to Open Source when you've moved on. > > > I started thinking that the only consistent env each python person has > > is idle as it ships in the install. > > There is a plethora of Python IDE's [personally I use Monodevelop, which > supports Python, and is fast and stable]. > > > Sometimes we can contribute with money and sometimes with time, if I > > was to contribute money to ensure that I and all new coming python > > programmers could have a first class development environment to use > > what would I donate to? At the moment no particular group seems > > applicable. > > Many projects accept donations via PayPal. ?Sourceforge supports this. > > > Is pydev actively being developed and for who? SPE is a great idea but > > is Stan still developing? Pyscripter is good but not 64 capable. Plus > > none of these projects seem community centric. > > Why not just check the repo and see the real answer for yourself? ?It is > Open Source after all. > > > > Maybe its just my wish, maybe something already exists, but to my mind > > why is there not a central python community ide or plugin setup like > > pydev or using pydev(since currently it is very good - to me), which I > > know or at least could confidently donate time or money to further > > python. > > You could checkout the code of any Python IDE and hack on it. > > > I think a community plugin architecture which contained components > > like pydev, pyscripter, eclipse and eggs/pypm packages would give a > > place I can contribute time as my skills grow and confidently donate > > money knowing I am assisting the development of community tools and > > packages we all can use. > > So just do it. Yes you can answer questions, but have you really? Your answer seems to be things are open source so who cares about community. > Many projects accept donations via PayPal. Sourceforge supports this. Of course any fool can throw his/her money away thats no challenge why even use Paypal, I could have fun and by 10 bottles of vino and hand them out to recovering alcoholics. Don't answer things just for the sake of it, if you have nothing producive to say about furthering python and its community then say that. From flebber.crue at gmail.com Tue Dec 28 06:29:26 2010 From: flebber.crue at gmail.com (flebber) Date: Tue, 28 Dec 2010 03:29:26 -0800 (PST) Subject: Python - NAWIT / Community References: <2895ecca-b978-4899-9ab3-0032422b908f@o9g2000pre.googlegroups.com> <365bf58b-889b-4186-baff-72d78efe635f@21g2000prv.googlegroups.com> Message-ID: On Dec 28, 10:24?pm, flebber wrote: > On Dec 28, 10:16?pm, Adam Tauno Williams > wrote: > > > > > On Tue, 2010-12-28 at 02:26 -0800, flebber wrote: > > > Can't help thinking they open sourced Pydev so they could bench it. > > > So? ?That isn't uncommon at all; ?to Open Source when you've moved on. > > > > I started thinking that the only consistent env each python person has > > > is idle as it ships in the install. > > > There is a plethora of Python IDE's [personally I use Monodevelop, which > > supports Python, and is fast and stable]. > > > > Sometimes we can contribute with money and sometimes with time, if I > > > was to contribute money to ensure that I and all new coming python > > > programmers could have a first class development environment to use > > > what would I donate to? At the moment no particular group seems > > > applicable. > > > Many projects accept donations via PayPal. ?Sourceforge supports this. > > > > Is pydev actively being developed and for who? SPE is a great idea but > > > is Stan still developing? Pyscripter is good but not 64 capable. Plus > > > none of these projects seem community centric. > > > Why not just check the repo and see the real answer for yourself? ?It is > > Open Source after all. > > > > > > Maybe its just my wish, maybe something already exists, but to my mind > > > why is there not a central python community ide or plugin setup like > > > pydev or using pydev(since currently it is very good - to me), which I > > > know or at least could confidently donate time or money to further > > > python. > > > You could checkout the code of any Python IDE and hack on it. > > > > I think a community plugin architecture which contained components > > > like pydev, pyscripter, eclipse and eggs/pypm packages would give a > > > place I can contribute time as my skills grow and confidently donate > > > money knowing I am assisting the development of community tools and > > > packages we all can use. > > > So just do it. > > Yes you can answer questions, but have you really? Your answer seems > to be things are open source so who cares about community. > > > Many projects accept donations via PayPal. ?Sourceforge supports this. > > Of course any fool can throw his/her money away thats no challenge why > even use Paypal, I could have fun and by 10 bottles of vino and hand > them out to recovering alcoholics. > > Don't answer things just for the sake of it, if you have nothing > producive to say about furthering python and its community then say > that. My apologise I didn't mean to be that aggressive. From awilliam at whitemice.org Tue Dec 28 06:37:17 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Tue, 28 Dec 2010 06:37:17 -0500 Subject: Python - NAWIT / Community In-Reply-To: <365bf58b-889b-4186-baff-72d78efe635f@21g2000prv.googlegroups.com> References: <2895ecca-b978-4899-9ab3-0032422b908f@o9g2000pre.googlegroups.com> <365bf58b-889b-4186-baff-72d78efe635f@21g2000prv.googlegroups.com> Message-ID: <1293536237.10930.28.camel@linux-yu4c.site> On Tue, 2010-12-28 at 03:24 -0800, flebber wrote: > On Dec 28, 10:16 pm, Adam Tauno Williams > wrote: > > On Tue, 2010-12-28 at 02:26 -0800, flebber wrote: > > > Is pydev actively being developed and for who? SPE is a great idea but > > > is Stan still developing? Pyscripter is good but not 64 capable. Plus > > > none of these projects seem community centric. > > Why not just check the repo and see the real answer for yourself? It is > > Open Source after all. > > > Yes you can answer questions, but have you really? Your answer seems > to be things are open source so who cares about community. > > Many projects accept donations via PayPal. Sourceforge supports this. > Of course any fool can throw his/her money away thats no challenge why > even use Paypal, I could have fun and by 10 bottles of vino and hand > them out to recovering alcoholics. > Don't answer things just for the sake of it, if you have nothing > producive to say about furthering python and its community then say > that. I provided two concrete points, thank you: (1) Is a project actively developed? Look at the repo. That is the answer to the question [this isn't necessarily obvious to those new to Open Source]. (1.1.) "Is PyDev a potential unifying force amoung IDEs?" Which is the implied question - that is up to the OP and others who do/do-not contribute to it. (2) How can I donate cash? There is a fairly standard mechanism for that. Otherwise I think the OP's thoughts on "community" and how Open Source works are somewhat flawed. "Community" is a manifestation of people *doing* things; it does *not* arise out of people being concerned about things [since "doing" is quite apparently not a natural result of "concern". Concern is like watching TV. Doing is getting out of the chair.] From awilliam at whitemice.org Tue Dec 28 06:56:31 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Tue, 28 Dec 2010 06:56:31 -0500 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> <4D18FD43.6090900@yahoo.com> Message-ID: <1293537391.10930.42.camel@linux-yu4c.site> On Tue, 2010-12-28 at 07:08 +0100, Stefan Behnel wrote: > Roy Smith, 28.12.2010 00:21: > > To go back to my earlier example of > > FALSE > > using 432 bits to store 1 bit of information, stuff like that doesn't > > happen in marked-up text documents. Most of the file is CDATA (do they > > still use that term in XML, or was that an SGML-ism only?). The markup > > is a relatively small fraction of the data. I'm happy to pay a factor > > of 2 or 3 to get structured text that can be machine processed in useful > > ways. I'm not willing to pay a factor of 432 to get tabular data when > > there's plenty of other much more reasonable ways to encode it. > If the above only appears once in a large document, I don't care how much > space it takes. If it appears all over the place, it will compress down to > a couple of bits, so I don't care about the space, either. +1 > It's readability that counts here. Try to reverse engineer a binary format > that stores the above information in 1 bit. I think a point many of the arguments against XML miss is the HR cost of custom solutions. Every time you come up with a cool super-efficient solution it has to be weighed against the increase in the tool-stack [whereas XML is, essentially, built-in] and nobody-else-knows-about-your-super-cool-solution [1]. IMO, tool-stack bloat is a *big* problem in shops with an Open Source tendency. Always tossing the new and shiny thing [it's free!] into the bucket for some theoretical benefit. [This is an unrecognized benefit to expensive software - it creates focus]. Soon the bucket is huge and maintaining it becomes a burden. [1] The odds you sufficiently documented your super-cool-solution is probably nil. So I'm one of those you'd have to make a *really* good argument *not* to use XML. XML is known, the tools are good, the knotty problems are solved [thanks to the likes of SAX, lxml / ElementTree, and ElementFlow]. If the premise argument is "bloat" I'd probably dismiss it out of hand since removing that bloat will necessitate adding bloat somewhere else; that somewhere else almost certainly being more expensive. From flebber.crue at gmail.com Tue Dec 28 07:10:15 2010 From: flebber.crue at gmail.com (flebber) Date: Tue, 28 Dec 2010 04:10:15 -0800 (PST) Subject: Python - NAWIT / Community References: <2895ecca-b978-4899-9ab3-0032422b908f@o9g2000pre.googlegroups.com> <365bf58b-889b-4186-baff-72d78efe635f@21g2000prv.googlegroups.com> Message-ID: On Dec 28, 10:37?pm, Adam Tauno Williams wrote: > On Tue, 2010-12-28 at 03:24 -0800, flebber wrote: > > On Dec 28, 10:16 pm, Adam Tauno Williams > > wrote: > > > On Tue, 2010-12-28 at 02:26 -0800, flebber wrote: > > > > Is pydev actively being developed and for who? SPE is a great idea but > > > > is Stan still developing? Pyscripter is good but not 64 capable. Plus > > > > none of these projects seem community centric. > > > Why not just check the repo and see the real answer for yourself? ?It is > > > Open Source after all. > > > > > Yes you can answer questions, but have you really? Your answer seems > > to be things are open source so who cares about community. > > > Many projects accept donations via PayPal. ?Sourceforge supports this. > > Of course any fool can throw his/her money away thats no challenge why > > even use Paypal, I could have fun and by 10 bottles of vino and hand > > them out to recovering alcoholics. > > Don't answer things just for the sake of it, if you have nothing > > producive to say about furthering python and its community then say > > that. > > I provided two concrete points, thank you: > > (1) Is a project actively developed? ?Look at the repo. That is the > answer to the question [this isn't necessarily obvious to those new to > Open Source]. > (1.1.) "Is PyDev a potential unifying force amoung IDEs?" ?Which is the > implied question - that is up to the OP and others who do/do-not > contribute to it. > (2) How can I donate cash? There is a fairly standard mechanism for > that. > > Otherwise I think the OP's thoughts on "community" and how Open Source > works are somewhat flawed. ?"Community" is a manifestation of people > *doing* things; it does *not* arise out of people being concerned about > things [since "doing" is quite apparently not a natural result of > "concern". Concern is like watching TV. ?Doing is getting out of the > chair.] Fair point. You have mistaken somewhat what I intended, partly my fault due to the verbosity. I wanted gaugue feedback on others perception of the current status quo. I am happy personally currently, currently being the main word. "Community" is a manifestation of people > *doing* things; it does *not* arise out of people being concerned about > things But concern is derived from interaction and observation and like fear and joy tells us we need to take an action. If someone chooses to sir idly by good for them I haven't the time or inclination personally. Tony Robbins "Acheiving a goal is simple, decide what your goal is, set out towards it and consistently review whether you are getting closer or further from your goal and take action immediately." >From a language perspective going to python 3 this definitely seems to be occurring well and strongly lead. Sometimes the fault in open source is the lack of a crystalized and shared goal and proper infrastructure.....Gentoo as an example. Could get to they were going because they didn't share the same vision of what it was. I meant no attack by reviewing, just a somewhat newbies observations of python. From flebber.crue at gmail.com Tue Dec 28 07:12:56 2010 From: flebber.crue at gmail.com (flebber) Date: Tue, 28 Dec 2010 04:12:56 -0800 (PST) Subject: Python - NAWIT / Community References: <2895ecca-b978-4899-9ab3-0032422b908f@o9g2000pre.googlegroups.com> <365bf58b-889b-4186-baff-72d78efe635f@21g2000prv.googlegroups.com> Message-ID: On Dec 28, 11:10?pm, flebber wrote: > On Dec 28, 10:37?pm, Adam Tauno Williams > wrote: > > > > > On Tue, 2010-12-28 at 03:24 -0800, flebber wrote: > > > On Dec 28, 10:16 pm, Adam Tauno Williams > > > wrote: > > > > On Tue, 2010-12-28 at 02:26 -0800, flebber wrote: > > > > > Is pydev actively being developed and for who? SPE is a great idea but > > > > > is Stan still developing? Pyscripter is good but not 64 capable. Plus > > > > > none of these projects seem community centric. > > > > Why not just check the repo and see the real answer for yourself? ?It is > > > > Open Source after all. > > > > > > > Yes you can answer questions, but have you really? Your answer seems > > > to be things are open source so who cares about community. > > > > Many projects accept donations via PayPal. ?Sourceforge supports this. > > > Of course any fool can throw his/her money away thats no challenge why > > > even use Paypal, I could have fun and by 10 bottles of vino and hand > > > them out to recovering alcoholics. > > > Don't answer things just for the sake of it, if you have nothing > > > producive to say about furthering python and its community then say > > > that. > > > I provided two concrete points, thank you: > > > (1) Is a project actively developed? ?Look at the repo. That is the > > answer to the question [this isn't necessarily obvious to those new to > > Open Source]. > > (1.1.) "Is PyDev a potential unifying force amoung IDEs?" ?Which is the > > implied question - that is up to the OP and others who do/do-not > > contribute to it. > > (2) How can I donate cash? There is a fairly standard mechanism for > > that. > > > Otherwise I think the OP's thoughts on "community" and how Open Source > > works are somewhat flawed. ?"Community" is a manifestation of people > > *doing* things; it does *not* arise out of people being concerned about > > things [since "doing" is quite apparently not a natural result of > > "concern". Concern is like watching TV. ?Doing is getting out of the > > chair.] > > Fair point. > > You have mistaken somewhat what I intended, partly my fault due to the > verbosity. I wanted gaugue feedback on others perception of the > current status quo. I am happy personally currently, currently being > the main word. > > "Community" is a manifestation of people > > > *doing* things; it does *not* arise out of people being concerned about > > things > > But concern is derived from interaction and observation and like fear > and joy tells us we need to take an action. If someone chooses to sir > idly by good for them I haven't the time or inclination personally. > > Tony Robbins "Acheiving a goal is simple, decide what your goal is, > set out towards it and consistently review whether you are getting > closer or further from your goal and take action immediately." > > From a language perspective going to python 3 this definitely seems to > be occurring well and strongly lead. > > Sometimes the fault in open source is the lack of a crystalized and > shared goal and proper infrastructure.....Gentoo as an example. Could > get to they were going because they didn't share the same vision of > what it was. > > I meant no attack by reviewing, just a somewhat newbies observations > of python. Edit Gentoo couldn't get to where they were going because of lack of vision and a shared goal. From doomster at knuut.de Tue Dec 28 07:42:39 2010 From: doomster at knuut.de (Ulrich Eckhardt) Date: Tue, 28 Dec 2010 13:42:39 +0100 Subject: Interning own classes like strings for speed and size? References: <8nra78Foh3U1@mid.uni-berlin.de> <4d19203f$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8nu4a2Fp63U1@mid.uni-berlin.de> Steven D'Aprano wrote: >>>> class InternedTuple(tuple): > ... _cache = {} > ... def __new__(cls, *args): > ... t = super().__new__(cls, *args) > ... return cls._cache.setdefault(t, t) That looks good. The only thing that first bothered me is that it creates an object and then possibly discards it again. However, there is no way around that, since at least the key to the dict must be created for lookup. Since key and value are the same here, this is even for free. What I also found was that with the above, I can't provide __eq__ and __ne__ that just check for identity. If I do, the lookup in setdefault() will never find an existing tuple and I will never save memory for a single object. Thanks! Uli From steve+comp.lang.python at pearwood.info Tue Dec 28 07:43:43 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Dec 2010 12:43:43 GMT Subject: Python - NAWIT / Community References: <2895ecca-b978-4899-9ab3-0032422b908f@o9g2000pre.googlegroups.com> <365bf58b-889b-4186-baff-72d78efe635f@21g2000prv.googlegroups.com> Message-ID: <4d19db7f$0$29993$c3e8da3$5496439d@news.astraweb.com> On Tue, 28 Dec 2010 04:10:15 -0800, flebber wrote: > Tony Robbins "Acheiving a goal is simple, decide what your goal is, set > out towards it and consistently review whether you are getting closer or > further from your goal and take action immediately." Writing bug-free code is simple: decide what you want your code to do, write code to do it, and consistently review whether you are getting more or fewer bugs, and take action immediately. -- Steven From bc at freeuk.com Tue Dec 28 07:56:46 2010 From: bc at freeuk.com (BartC) Date: Tue, 28 Dec 2010 12:56:46 -0000 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> <4D18FD43.6090900@yahoo.com> Message-ID: "Stefan Behnel" wrote in message news:mailman.335.1293516506.6505.python-list at python.org... > Roy Smith, 28.12.2010 00:21: >> To go back to my earlier example of >> >> FALSE >> >> using 432 bits to store 1 bit of information, stuff like that doesn't >> happen in marked-up text documents. Most of the file is CDATA (do they >> still use that term in XML, or was that an SGML-ism only?). The markup >> is a relatively small fraction of the data. I'm happy to pay a factor >> of 2 or 3 to get structured text that can be machine processed in useful >> ways. I'm not willing to pay a factor of 432 to get tabular data when >> there's plenty of other much more reasonable ways to encode it. > > If the above only appears once in a large document, I don't care how much > space it takes. If it appears all over the place, it will compress down to > a couple of bits, so I don't care about the space, either. > > It's readability that counts here. Try to reverse engineer a binary format > that stores the above information in 1 bit. The above typically won't get much below 2 bytes (as one character plus a separator, eg. in comma-delimited-format). So it's more like 27:1, if you're going to stay with a text format. Still, that's 27 times as much as it need be. Readability is fine, but why does the full, expanded, human-readable textual format have to be stored on disk too, and for every single instance? What if the 'Parental-Advisory' tag was even longer? Just how long do these things have to get before even the advocates here admit that it's getting ridiculous? Isn't it possible for XML to define a shorter alias for these tags? Isn't there a shortcut available for in simple examples like this (I seem to remember something like this)? And why not use 1 and 0 for TRUE and FALSE? Even the consumer appliances in my house have 1 and 0 on their power switches! With the advantage that they are internationally recognised. -- Bartc From krishna1344 at gmail.com Tue Dec 28 07:57:42 2010 From: krishna1344 at gmail.com (krishna kumar) Date: Tue, 28 Dec 2010 07:57:42 -0500 Subject: etl tool!!!!! Message-ID: Is there any efficient etl tool developed in python? -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan.sonnenberg at pythonmeister.com Tue Dec 28 08:14:33 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Tue, 28 Dec 2010 14:14:33 +0100 Subject: etl tool!!!!! In-Reply-To: References: Message-ID: <4D19E2B9.3080204@pythonmeister.com> Am 28.12.2010 13:57, schrieb krishna kumar: > Is there any efficient etl tool developed in python? Yes, Python. From awilliam at whitemice.org Tue Dec 28 08:19:04 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Tue, 28 Dec 2010 08:19:04 -0500 Subject: etl tool!!!!! In-Reply-To: References: Message-ID: <1293542344.4080.1.camel@linux-yu4c.site> On Tue, 2010-12-28 at 07:57 -0500, krishna kumar wrote: > Is there any efficient etl tool developed in python? What does "efficient" mean to you? I work on a Python workflow solution that I use to do ETL. -- Adam Tauno Williams LPIC-1, Novell CLA OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba From stef.mientki at gmail.com Tue Dec 28 08:34:19 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 28 Dec 2010 14:34:19 +0100 Subject: NameError: global name 'btn_Matlab' is not defined ? Message-ID: <4D19E75B.1010607@gmail.com> hello, Never seen this before and I've no explanation whatsoever (Python 2.6) I've some dynamic generated code, one of objects generated is a wx.Button, called 'btn_Matlab'. After the code is generated, I can see that the button is created in the local namespace print locals()['btn_Matlab'] > but if I try to print the button (at exactly the same location), I get an error print btn_Matlab NameError: global name 'btn_Matlab' is not defined ? Why isn't the compiler first checking the local namespace ? any clues ? thanks, Stef Mientki From steve+comp.lang.python at pearwood.info Tue Dec 28 09:11:56 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Dec 2010 14:11:56 GMT Subject: Interning own classes like strings for speed and size? References: <8nra78Foh3U1@mid.uni-berlin.de> <4d19203f$0$29993$c3e8da3$5496439d@news.astraweb.com> <8nu4a2Fp63U1@mid.uni-berlin.de> Message-ID: <4d19f02c$0$29993$c3e8da3$5496439d@news.astraweb.com> On Tue, 28 Dec 2010 13:42:39 +0100, Ulrich Eckhardt wrote: > Steven D'Aprano wrote: >>>>> class InternedTuple(tuple): >> ... _cache = {} >> ... def __new__(cls, *args): >> ... t = super().__new__(cls, *args) >> ... return cls._cache.setdefault(t, t) > > That looks good. The only thing that first bothered me is that it > creates an object and then possibly discards it again. However, there is > no way around that, since at least the key to the dict must be created > for lookup. Since key and value are the same here, this is even for > free. > > What I also found was that with the above, I can't provide __eq__ and > __ne__ that just check for identity. If I do, the lookup in setdefault() > will never find an existing tuple and I will never save memory for a > single object. If all you want is to save memory, you don't need to change the __eq__ method. But if you still want to, try this: # Untested class InternedTuple(tuple): _cache = {} def __new__(cls, *args): t = super().__new__(cls, *args) return cls._cache.setdefault(args, t) def __eq__(self, other): return self is other def __ne__(self, other): return self is not other -- Steven From steve+comp.lang.python at pearwood.info Tue Dec 28 09:15:41 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Dec 2010 14:15:41 GMT Subject: NameError: global name 'btn_Matlab' is not defined ? References: Message-ID: <4d19f10d$0$29993$c3e8da3$5496439d@news.astraweb.com> On Tue, 28 Dec 2010 14:34:19 +0100, Stef Mientki wrote: > hello, > > Never seen this before and I've no explanation whatsoever (Python 2.6) > > I've some dynamic generated code, > one of objects generated is a wx.Button, called 'btn_Matlab'. How do you generate the code? What code is generated? What does it do? > After the code is generated, I can see that the button is created in the > local namespace > > print locals()['btn_Matlab'] > > 0x3602d28> > > > but if I try to print the button (at exactly the same location), I get > an error > > print btn_Matlab > > NameError: global name 'btn_Matlab' is not defined ? > > Why isn't the compiler first checking the local namespace ? any clues ? My guess is that you've declared btn_Matlab as global, and then dynamically created a local with the same name using exec or similar. -- Steven From stefan_ml at behnel.de Tue Dec 28 09:39:32 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 28 Dec 2010 15:39:32 +0100 Subject: Interning own classes like strings for speed and size? In-Reply-To: <4d19f02c$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <8nra78Foh3U1@mid.uni-berlin.de> <4d19203f$0$29993$c3e8da3$5496439d@news.astraweb.com> <8nu4a2Fp63U1@mid.uni-berlin.de> <4d19f02c$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano, 28.12.2010 15:11: > On Tue, 28 Dec 2010 13:42:39 +0100, Ulrich Eckhardt wrote: > >> Steven D'Aprano wrote: >>>>>> class InternedTuple(tuple): >>> ... _cache = {} >>> ... def __new__(cls, *args): >>> ... t = super().__new__(cls, *args) >>> ... return cls._cache.setdefault(t, t) >> >> That looks good. The only thing that first bothered me is that it >> creates an object and then possibly discards it again. However, there is >> no way around that, since at least the key to the dict must be created >> for lookup. Since key and value are the same here, this is even for >> free. >> >> What I also found was that with the above, I can't provide __eq__ and >> __ne__ that just check for identity. If I do, the lookup in setdefault() >> will never find an existing tuple and I will never save memory for a >> single object. > > If all you want is to save memory, you don't need to change the __eq__ > method. But if you still want to, try this: > > # Untested Yep, that' the problem. ;) > class InternedTuple(tuple): > _cache = {} > def __new__(cls, *args): > t = super().__new__(cls, *args) > return cls._cache.setdefault(args, t) > def __eq__(self, other): > return self is other > def __ne__(self, other): > return self is not other What Ulrich meant, was: doing this will actually kill the caching, because the first time the comparison is called is when looking up the tuple while adding it to the interning dict. Since the new tuple is, well, new, it will not be equal (read: identical) to any cached tuple, thus resulting in a new entry regardless of its content. Stefan From lists at cheimes.de Tue Dec 28 09:46:25 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 28 Dec 2010 15:46:25 +0100 Subject: Interning own classes like strings for speed and size? In-Reply-To: <4d19f02c$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <8nra78Foh3U1@mid.uni-berlin.de> <4d19203f$0$29993$c3e8da3$5496439d@news.astraweb.com> <8nu4a2Fp63U1@mid.uni-berlin.de> <4d19f02c$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 28.12.2010 15:11, schrieb Steven D'Aprano: > # Untested > class InternedTuple(tuple): > _cache = {} > def __new__(cls, *args): > t = super().__new__(cls, *args) > return cls._cache.setdefault(args, t) > def __eq__(self, other): > return self is other > def __ne__(self, other): > return self is not other The code doesn't work, you have to change super().__new__(cls, *args) to super().__new__(cls, args). Don't ask me why. I'm surprised, too. >>> InternedTuple(1) Traceback (most recent call last): File "", line 1, in File "", line 4, in __new__ TypeError: 'int' object is not iterable Also this code is going to use much more memory than an ordinary tuple since every instance of InternedTuple has a __dict__ attribute. This code works but I had to move the cache outside the class because of __slots__. _ituple_cache = {} class ituple(tuple): __slots__ = () # no __dict__ def __new__(cls, *args): cached = _ituple_cache.get(args) if cached is not None: return cached self = _ituple_cache[args] = super(ituple, cls).__new__(cls, args) return self From nat.abbotts at gmail.com Tue Dec 28 09:59:29 2010 From: nat.abbotts at gmail.com (Nathanael Abbotts) Date: Tue, 28 Dec 2010 06:59:29 -0800 (PST) Subject: Replacing Greenlets with Threads or Processes Message-ID: <5b003652-8bd6-4136-ba47-864efefa55bc@glegroupsg2000goo.googlegroups.com> I need to replace the use of 'greenlets' in an application with threads or processes, but as I've never used greenlets, I don't know where to start when replacing them. Could anyone explain to me how I can do this? From fal at togliquesto.fastwebnet.it Tue Dec 28 10:00:37 2010 From: fal at togliquesto.fastwebnet.it (Francesco) Date: Tue, 28 Dec 2010 16:00:37 +0100 Subject: while True or while 1 In-Reply-To: <4d0ab65f$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <4D051506.2060403@holdenweb.com> <4d0ab65f$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: hehehehehehe... On 17/12/2010 2.01, Steven D'Aprano wrote: > On Thu, 16 Dec 2010 23:34:21 +0000, BartC wrote: > >> In terms of a more realistic function (admittedly still a little >> contrived, as the loop would be written differently), I tried this: >> >> def p2(n): >> p=1 >> while True: >> if n<=p: return p >> p<<=1 >> return 0 >> >> for i in xrange(1000000): >> x=p2(i) >> >> p2() calculates the smallest power of 2>= it's operand. >> >> Using while True as shown, it took 3.4 seconds. Using While 1, it took >> 2.6 seconds (Python 2.5). > > > Right. And a saving of 0.8 microseconds per iteration is a micro- > optimization which is likely to be invisible in any real situation. > > I mean, yes, you saved almost an entire second. Wow. Save another 179 of > them and you'll almost have enough time to make yourself a coffee. > > Bart, we get it. Nobody denies that the optimization is real, only that > it is generally meaningful. Who cares whether it takes 2 seconds or 4 > seconds to generate one million results if the rest of the application > takes 3 minutes to run? > > *If* your application is such that saving 0.8 microseconds per iteration > actually is useful, AND your loop has to be written as a while True loop, > then this *may* be a useful micro-optimization to save 0.8 microseconds > per iteration. That's a vanishingly tiny proportion of all code written. > If your code happens to meet those conditions, then by all means use > "while 1". Or move to Python 3, where "while True" has the same > optimization performed. > > But in general, such micro-optimizations are not terribly useful. If you > shave off 1 second off a program that runs in 3 seconds, chances are > nobody is even going to notice. Two seconds or three, who cares? Either > way, it's too short to do anything else, and not long enough to matter. > If you shave off an hour off a program that takes 20 hours, who is going > to care? > > But so long as it doesn't introduce bugs, or make maintenance harder, or > add complexity, such micro-optimizations don't harm either. > HEY! That was MY argument! ;-)) Newsgroups: comp.lang.python Subject: Re: If/then style question Date: Tue, 21 Dec 2010 20:54:02 +0100 I'd bet you would stress your point Steven! But you don't need to persuade me, I do already agree. I just meant to say that, when the advantage is little, there's no need to rewrite a working function. And that with modern CPUs, if tests take so little time, that even some redundant one is not so much of a nuisance. in your working example, the "payload" is just a couple of integer calculations, that take very little time too. So the overhead due to redundant if tests does show clearly. And also in that not-really-real situation, 60% overhead just meant less than 3 seconds. Just for the sake of discussion, I tried to give both functions some plough to pull, and a worst-case situation too: >>> t1 = Timer('for x in range(100): print func1(0),', ... 'from __main__ import func1') >>> >>> t2 = Timer('for x in range(100): print func2(0),', ... 'from __main__ import func2') >>> >>> min(t1.repeat(number=1, repeat=1)) -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 53.011015366479114 >>> min(t2.repeat(number=1, repeat=1)) -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 47.55442856564332 that accounts for a scant 11% overhead, on more than one million tests per cycle. That said, let's make really clear that I would heartily prefer func2 to func1, based both on readability and speed. Thank you for having spent some time playing with me! Francesco On 19/12/2010 1.05, Steven D'Aprano wrote: > Well, let's try it with a working (albeit contrived) example. This is > just an example -- obviously I wouldn't write the function like this in > real life, I'd use a while loop, but to illustrate the issue it will do. > > def func1(n): > result = -1 > done = False > n = (n+1)//2 > if n%2 == 1: > result = n > done = True > if not done: > n = (n+1)//2 > if n%2 == 1: > result = n > done = True > if not done: > n = (n+1)//2 > if n%2 == 1: > result = n > done = True > if not done: > for i in range(1000000): > if not done: > n = (n+1)//2 > if n%2 == 1: > result = n > done = True > return result > > > def func2(n): > n = (n+1)//2 > if n%2 == 1: > return n > n = (n+1)//2 > if n%2 == 1: > return n > n = (n+1)//2 > if n%2 == 1: > return n > for i in range(1000000): > n = (n+1)//2 > if n%2 == 1: > return n > return -1 > > > Not only is the second far more readable that the first, but it's also > significantly faster: > >>>> from timeit import Timer >>>> t1 = Timer('for i in range(20): x = func1(i)', > ... 'from __main__ import func1') >>>> t2 = Timer('for i in range(20): x = func2(i)', > ... 'from __main__ import func2') >>>> min(t1.repeat(number=10, repeat=5)) > 7.3219029903411865 >>>> min(t2.repeat(number=10, repeat=5)) > 4.530779838562012 > > The first function does approximately 60% more work than the first, all > of it unnecessary overhead. From phanindracharya at gmail.com Tue Dec 28 10:20:57 2010 From: phanindracharya at gmail.com (phani indra) Date: Tue, 28 Dec 2010 07:20:57 -0800 Subject: hi Message-ID: -------------- next part -------------- An HTML attachment was scrubbed... URL: From sherm.pendley at gmail.com Tue Dec 28 10:29:43 2010 From: sherm.pendley at gmail.com (Sherm Pendley) Date: Tue, 28 Dec 2010 10:29:43 -0500 Subject: Trying to parse a HUGE(1gb) xml file References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> <4D18FD43.6090900@yahoo.com> Message-ID: "BartC" writes: >> Roy Smith, 28.12.2010 00:21: >>> To go back to my earlier example of >>> >>> FALSE >>> > > Isn't it possible for XML to define a shorter alias for these tags? Isn't > there a shortcut available for in simple examples like > this (I seem to remember something like this)? Yes, you can define your own entities in a DTD: FALSE"> TRUE"> Later, in your document: &paf; &pat; Although, this is a bit of a contrived example - if space is such a major concern, one wouldn't be so wasteful of it to begin with, but might instead use a short tag form whose value attribute defaults to "FALSE". Later, in your document: To save even more space, one could instead define a "pa" attribute as part of the "movie" element, with a default value that would then take no space at all: Later, in your document: When you see someone doing stupid things with a tool, it's usually not the tool's fault. Far more often, it's someone using the wrong tool for the task at hand, or using the right tool the wrong way. > And why not use 1 and 0 for TRUE and FALSE? Sounds reasonable in general, although a parental advisory would more often be a range of possible values (G, PG, R, MA, etc.) rather than a boolean. sherm-- -- Sherm Pendley Cocoa Developer From emile at fenx.com Tue Dec 28 10:32:45 2010 From: emile at fenx.com (Emile van Sebille) Date: Tue, 28 Dec 2010 07:32:45 -0800 Subject: Replacing Greenlets with Threads or Processes In-Reply-To: <5b003652-8bd6-4136-ba47-864efefa55bc@glegroupsg2000goo.googlegroups.com> References: <5b003652-8bd6-4136-ba47-864efefa55bc@glegroupsg2000goo.googlegroups.com> Message-ID: On 12/28/2010 6:59 AM Nathanael Abbotts said... > I need to replace the use of 'greenlets' in an application with threads or processes, but as I've never used greenlets, I don't know where to start when replacing them. > Could anyone explain to me how I can do this? Looks like your choice may be limited to processes... http://groups.google.com/group/pycsp/browse_thread/thread/45209957e27e0293/b67445b092872750?q=python+greenlets Emile From nat.abbotts at gmail.com Tue Dec 28 10:58:23 2010 From: nat.abbotts at gmail.com (Nathanael Abbotts) Date: Tue, 28 Dec 2010 07:58:23 -0800 (PST) Subject: Replacing Greenlets with Threads or Processes In-Reply-To: Message-ID: <1543cad4-92c6-4693-8758-6e2d278a0107@glegroupsg2000goo.googlegroups.com> Processes are better for me - the application is already multiprocessing based. From nat.abbotts at gmail.com Tue Dec 28 10:58:23 2010 From: nat.abbotts at gmail.com (Nathanael Abbotts) Date: Tue, 28 Dec 2010 07:58:23 -0800 (PST) Subject: Replacing Greenlets with Threads or Processes In-Reply-To: Message-ID: <1543cad4-92c6-4693-8758-6e2d278a0107@glegroupsg2000goo.googlegroups.com> Processes are better for me - the application is already multiprocessing based. From roy at panix.com Tue Dec 28 11:02:59 2010 From: roy at panix.com (Roy Smith) Date: Tue, 28 Dec 2010 11:02:59 -0500 Subject: Trying to parse a HUGE(1gb) xml file References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> if5455$s3o$1@dooooooooooooooo ailman.285.1293397695.6505.pythhn-list@python.oooo 4412925122010@nnnnnnnnnnnnnnn an.2010.12.25.22.33.55.172000@nnnnnnnnnnnn dh$eul$1@sperannnnnnnnnnnnn lman.295.1293355338.6505.pythonnlist@python.orgg peranza.aioe.orrr 293356689.6505..ython-list@pythhhhhhhh td$1@speranza.aaaaaaaaa Message-ID: In article , "BartC" wrote: > Still, that's 27 times as much as it need be. Readability is fine, but why > does the full, expanded, human-readable textual format have to be stored on > disk too, and for every single instance? Well, I know the answer to that one. The particular XML feed I'm working with is a dump from an SQL database. The element names in the XML are exactly the same as the column names in the SQL database. The difference being that in the database, the string "Parental-Advisory" appears in exactly one place, in some schema metadata table. In the XML, it appears (doubled!) once per row. It's still obscene. That fact that I understand the cause of the obscenity doesn't make it any less so. Another problem with XML is that some people don't use real XML tools to write their XML files. DTD? What's that? So you end up with tag soup that the real XML tools can't parse on the other end. From nat.abbotts at gmail.com Tue Dec 28 11:07:50 2010 From: nat.abbotts at gmail.com (Nathanael Abbotts) Date: Tue, 28 Dec 2010 08:07:50 -0800 (PST) Subject: Replacing Greenlets with Threads or Processes In-Reply-To: <1543cad4-92c6-4693-8758-6e2d278a0107@glegroupsg2000goo.googlegroups.com> Message-ID: <2bb26924-bb0b-4167-a7dd-f49c8241fafc@glegroupsg2000goo.googlegroups.com> That thread seems to deal with mixing them. I want to replace them completely - is that possible (with either threads or processes)? Some loss of functionality isn't a problem, as the code only seems to use the most basic features of Greenlets. From nat.abbotts at gmail.com Tue Dec 28 11:07:50 2010 From: nat.abbotts at gmail.com (Nathanael Abbotts) Date: Tue, 28 Dec 2010 08:07:50 -0800 (PST) Subject: Replacing Greenlets with Threads or Processes In-Reply-To: <1543cad4-92c6-4693-8758-6e2d278a0107@glegroupsg2000goo.googlegroups.com> Message-ID: <2bb26924-bb0b-4167-a7dd-f49c8241fafc@glegroupsg2000goo.googlegroups.com> That thread seems to deal with mixing them. I want to replace them completely - is that possible (with either threads or processes)? Some loss of functionality isn't a problem, as the code only seems to use the most basic features of Greenlets. From nagle at animats.com Tue Dec 28 11:39:12 2010 From: nagle at animats.com (John Nagle) Date: Tue, 28 Dec 2010 08:39:12 -0800 Subject: mutiprocessing, manager, list & threading ? In-Reply-To: References: Message-ID: <4d1a12ae$0$44060$742ec2ed@news.sonic.net> On 12/28/2010 1:38 AM, mika.saari at wipsl.com wrote: > Hi, > > Testing if I could be able to use multiprocessing BaseManager to manage > list of instance pointers between processes. If my intance inherits > Thread, I get pickling error about _thread.lock. The "multiprocessing" module works by running completely separate programs which communicate by copying data back and forth through pipes or sockets. You can't share thread locks. (There's a gimmick that lets you put an array of fixed type and size in shared memory, but that's very limited, because Python's locking doesn't really understand multiprocessing.) If you need to access a list from several processes, have one process own the list, and use a Manager from the multiprocessing module to create a proxy to access the list from the other processes. Note that this is slower than regular list access. But if you just need to have a to-do list that feeds multiple processes, that's a way to do it. John Nagle From emile at fenx.com Tue Dec 28 12:04:48 2010 From: emile at fenx.com (Emile van Sebille) Date: Tue, 28 Dec 2010 09:04:48 -0800 Subject: Replacing Greenlets with Threads or Processes In-Reply-To: <2bb26924-bb0b-4167-a7dd-f49c8241fafc@glegroupsg2000goo.googlegroups.com> References: <1543cad4-92c6-4693-8758-6e2d278a0107@glegroupsg2000goo.googlegroups.com> <2bb26924-bb0b-4167-a7dd-f49c8241fafc@glegroupsg2000goo.googlegroups.com> Message-ID: On 12/28/2010 8:07 AM Nathanael Abbotts said... > That thread seems to deal with mixing them. I want to replace them > completely - is that possible (with either threads or processes)? Are you working with pycsp? the info at http://code.google.com/p/pycsp/wiki/Getting_Started_With_PyCSP says: "The API is implemented in four versions: Threads, processes, greenlets and net. All implementations share an almost identical API making it trivial to switch from one implementation to another. " Emile From python at bdurham.com Tue Dec 28 14:08:45 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 28 Dec 2010 14:08:45 -0500 Subject: How to programmatically exit from wsgi's serve_forever() loop In-Reply-To: References: <1293498347.25483.1412453811@webmail.messagingengine.com> Message-ID: <1293563325.22535.1412552623@webmail.messagingengine.com> Hi Ian, You are correct - I missed the following 2 nuances: # need to set poll_interval in order to recognize shutdown request httpd.serve_forever(poll_interval=0.5) # shutdown request must be initiated from ANOTHER thread or will block import threading threading.Thread(target=httpd.shutdown).start() Thank you for your help - really appreciated! Malcolm From anurag.chourasia at gmail.com Tue Dec 28 14:19:41 2010 From: anurag.chourasia at gmail.com (Anurag Chourasia) Date: Wed, 29 Dec 2010 00:49:41 +0530 Subject: Digitally Signing a XML Document (using SHA1+RSA or SHA1+DSA) In-Reply-To: <1293498360.10930.4.camel@linux-yu4c.site> References: <1293498360.10930.4.camel@linux-yu4c.site> Message-ID: Dear all, I am required to use the Private Key from that XML below to generate a digital signature. The public key can then be used to validate the generated signature. http://stuvel.eu/rsa does not support PKCS#1 and hence I am required to look for alternates. Please let me know if there is something else out there that could help meet my requirement. Regards, Anurag On Tue, Dec 28, 2010 at 6:36 AM, Adam Tauno Williams wrote: > On Tue, 2010-12-28 at 03:25 +0530, Anurag Chourasia wrote: > > Hi All, > > > I have a requirement to digitally sign a XML Document using SHA1+RSA > > or SHA1+DSA > > Could someone give me a lead on a library that I can use to fulfill > > this requirement? > > Never used it though. > > > The XML Document has values such as > > -----BEGIN RSA PRIVATE KEY----- > > MIIBOgIBAAJBANWzHfF5Bppe4JKlfZDqFUpNLrwNQqguw76g/jmeO6f4i31rDLVQ > > n7sYilu65C8vN+qnEGnPB824t/A3yfMu1G0CAQMCQQCOd2lLpgRm6esMblO18WOG > > 3h8oCNcaydfUa1QmaX0apHlDFnI7UDXpYaHp2VL9gvtSJT5L3ZASMzxRPXJSvzcT > > AiEA/16jQh18BAD4q3yk1gKw19I8OuJOYAxFYX9noCEFWUMCIQDWOiYfPtxK3A1s > > AFARsDnnHTL4FbRPpiZ79vP+VgqojwIhAKo/F4Fo/VgApceobeQByzqMKCdBiZVd > > g5ZU78AWA5DXAiEAjtFuv389hz1eSAA1YSAmmhN3UA54NRlu/U9NVDlccF8CIBkc > > Z52oGxy/skwVwI5TBcB1YqXJTT47/6/hTAVMTwaA -----END RSA PRIVATE > > KEY----- > > -----BEGIN PUBLIC KEY----- > > MFowDQYJKoZIhvcNAQEBBQADSQAwRgJBANWzHfF5Bppe4JKlfZDqFUpNLrwNQqgu > > w76g/jmeO6f4i31rDLVQn7sYilu65C8vN+qnEGnPB824t/A3yfMu1G0CAQM= -----END > > PUBLIC KEY----- > > Is this any kind of standard or just something someone made up? Is > there a namespace for the document? > > It seems quite odd that the document contains a *private* key. > > If all you need to do is parse to document to retrieve the values that > seems straight-forward enough. > > > And the XML also has another node that has a Public Key with Modules > > and Exponents etc that I apparently need to utilize. > > > > 1bMd8XkGml7gkqV9kOoVSk0uvA1CqC7DvqD > > +OZ47p/iLfWsMtVCfuxiKW7rkLy836qcQac8Hzbi38DfJ8y7UbQ== > > Aw== > > > > > I am a little thin on this concept and expecting if you could guide me > > to a library/documentation that I could utilize. > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nagle at animats.com Tue Dec 28 14:23:17 2010 From: nagle at animats.com (John Nagle) Date: Tue, 28 Dec 2010 11:23:17 -0800 Subject: Interning own classes like strings for speed and size? In-Reply-To: <8nra78Foh3U1@mid.uni-berlin.de> References: <8nra78Foh3U1@mid.uni-berlin.de> Message-ID: <4d1a3923$0$43992$742ec2ed@news.sonic.net> On 12/27/2010 3:05 AM, Ulrich Eckhardt wrote: > Hi! > > I'm trying to solve a computational problem and of course speed and size is > important there. Then you probably shouldn't be using CPython. > Apart from picking the right algorithm, I came across an > idea that could help speed up things and keep memory requirements down. What > I have is regions described by min and max coordinates. At first, I just > modeled these as a simple class containing two values for each axis. There are more effective techniques for that. In game physics collision detection systems, it's common to use axis-ordered lists of bounding boxes to partition objects. This still works even when the ranges overlap. Look up "I-Collide" for a classic implementation. > Am I looking in the wrong direction? Is there some better approach? > Please > don't tell me to use C, as I'm specifically interested in > learning Python, > I'm pretty sure I could have solved the problem quickly in > C++ otherwise. CPython is a naive interpreter which does dictionary lookups for every variable and attribute access. If you're doing fast manipulation of linked data structures in CPython, performance is going to suck. Check out Shed Skin 0.7, which is a much faster Python system. It's limited, but for the kind of data structure work you're doing, all the features you should need already work. John Nagle > > In a second step, I derived this class from tuple instead of object. Some > code then moved from __init__ to __new__ and some code that modified these > objects had to be changed to replace them instead. The upside to this is > that they can be used as keys in sets and dicts, which isn't the case for > mutable types[1]. > > What I'm now considering is to only allow a single instance of these objects > for each set of values, similar to interned strings. What I would gain is > that I could safely compare objects for identity instead of equality. What > I'm not yet sure is how much overhead that would give me and/or how to keep > it low. The idea is to store each instance in a set and after creating a new > object I would first look up an equal object in the global set and return > that instead, otherwise add the new one. > > The problem I foresee is that if I define equality as identity, this lookup > when creating will never eliminate duplicates. If I only fall back to > equality comparison for non-identical objects, I would probably sacrifice > most of the gain. If I build a dict mapping between the values and the > actual objects, I would have doubled the required memory and uselessly store > the same values twice there. > > > Cheers! > > Uli > > > [1] Somebody correct me if I'm wrong, but I believe I could have defined a > hashing function for the type and thus allowed its use in a set or dict, > right? However, goofing up because you accidentally modified an object and > changed its hash value is something I don't want to risk anyway. > From ja at sdf.lonestar.org Tue Dec 28 15:07:29 2010 From: ja at sdf.lonestar.org (J. Altman) Date: Tue, 28 Dec 2010 20:07:29 +0000 (UTC) Subject: O'Reilly Python Certification References: <4D0900D3.10000@stoneleaf.us> <4D0927C1.5080209@tim.thechases.com> <4D093176.3010109@pythonmeister.com> <4D0A3306.3090100@stoneleaf.us> Message-ID: On 2010-12-16, Steve Holden wrote: > Each lesson required you to complete a practical assignment. You submit > these assignments for evaluation, and do not proceed to the next lesson > until your assignment reaches a satisfactory standard. Thus, less > experienced students will tend to have more interaction with their tutors. > > A class will typically have between twelve and sixteen lessons. There > are also quizzes and a final practical project. > > regards > Steve I have a general question. Does it seem odd that a certificate in Python, an Open Source language; taught at O'Reilly, which offers an Open Source Programming Certificate and is something like waist-deep in Open Source publishing; is offered to the world at large but only (IIUC) if one runs some version of Windows by MS? Based on what I am given to understand from my correspondence with OST, it seems that I *must* install an instance of Windows to take the certificate's courses. Not that I particularly want to bash MS, but I am running FreeBSD, and have Python 2.x and 3.x installed; I can call either IDE; and I am competent at the shell, I think sufficiently, to manage coding at the shell. Is it normal for people in CS courses at the University and/or certificate level to learn a given language under Windows? Or is it just me who thinks it odd that an OS like FreeBSD won't (apparently, I stress) work with the O'Reilly Sandbox? From hniksic at xemacs.org Tue Dec 28 15:16:51 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Tue, 28 Dec 2010 21:16:51 +0100 Subject: Interning own classes like strings for speed and size? References: <8nra78Foh3U1@mid.uni-berlin.de> <4d19203f$0$29993$c3e8da3$5496439d@news.astraweb.com> <8nu4a2Fp63U1@mid.uni-berlin.de> <4d19f02c$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <878vz9d558.fsf@xemacs.org> Christian Heimes writes: > Also this code is going to use much more memory than an ordinary tuple > since every instance of InternedTuple has a __dict__ attribute. This > code works but I had to move the cache outside the class because of > __slots__. Wouldn't it work inside the class as well? __slots__ applies to instances, not to classes themselves. In Python 3.1: >>> class Foo(tuple): ... __slots__ = () ... _cache = {} ... >>> Foo._cache # works as expected {} >>> Foo()._cache # and so does this {} From martin at v.loewis.de Tue Dec 28 16:47:06 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Tue, 28 Dec 2010 22:47:06 +0100 Subject: round in 2.6 and 2.7 In-Reply-To: <5f07e3a7-5f13-4ca0-bcde-75a916ac9210@r29g2000yqj.googlegroups.com> References: <87sjxoco6u.fsf@xemacs.org> <5f07e3a7-5f13-4ca0-bcde-75a916ac9210@r29g2000yqj.googlegroups.com> Message-ID: <4D1A5ADA.5040500@v.loewis.de> >> "Float-to-string and string-to-float conversions are correctly rounded. >> The round() function is also now correctly rounded." >> >> Not sure that this is correct English; I think it means that the >> round() function is now correct. > > Well, the correct result of the example the OP gave would be 9.9 > exactly. But since 9.9 isn't exactly representable as a Python float, > we necessarily get an approximation. The language above is intended > to convey that it's the 'correctly rounded' approximation I see. Shouldn't it say then "The round() function gives/produces/returns correctly rounded results now", instead of saying that the round function *is* correctly rounded? ISTM that the round function cannot be rounded (correctly or not): py> round(round) Traceback (most recent call last): File "", line 1, in TypeError: a float is required But then, I'm not a native speaker (of English). Regards, Martin From miki.tebeka at gmail.com Tue Dec 28 16:59:36 2010 From: miki.tebeka at gmail.com (Miki) Date: Tue, 28 Dec 2010 13:59:36 -0800 (PST) Subject: Keeping track of the N largest values In-Reply-To: Message-ID: > I'm processing a stream of N numbers and want to keep track of the K > largest. There's too many numbers in the stream (i.e. N is too large) > to keep in memory at once. K is small (100 would be typical). > ... deque can be bounded by maxsize, might fit the bill: >>> from collections import deque >>> d = deque([], 3) >>> for i in range(10): d.append(i) >>> d deque([7, 8, 9], maxlen=3) >>> HTH, -- Miki From katie at coderstack.co.uk Tue Dec 28 17:28:42 2010 From: katie at coderstack.co.uk (Katie T) Date: Tue, 28 Dec 2010 22:28:42 +0000 Subject: Language Detection Library/Code In-Reply-To: References: Message-ID: On Tue, Dec 28, 2010 at 12:42 AM, Shashwat Anand wrote: > Regarding dictionary lookup+n-gram approach I didn't quite understand what > you wanted to say. Run through trigram analysis first, if it identified multiple languages as being matches within the error margin then split the text into words, and look up each word in the respective dictionaries to get a second opinion. Katie -- CoderStack http://www.coderstack.co.uk/python-jobs The Software Developer Job Board From nat.abbotts at gmail.com Tue Dec 28 17:53:56 2010 From: nat.abbotts at gmail.com (Nathanael Abbotts) Date: Tue, 28 Dec 2010 14:53:56 -0800 (PST) Subject: Replacing Greenlets with Threads or Processes In-Reply-To: Message-ID: <857278fc-bf46-407d-ba76-db3e03a39b63@glegroupsg2000goo.googlegroups.com> On Tuesday, December 28, 2010 5:04:48 PM UTC, Emile van Sebille wrote: > On 12/28/2010 8:07 AM Nathanael Abbotts said... > > That thread seems to deal with mixing them. I want to replace them > > completely - is that possible (with either threads or processes)? > > Are you working with pycsp? the info at > http://code.google.com/p/pycsp/wiki/Getting_Started_With_PyCSP says: > > "The API is implemented in four versions: Threads, processes, greenlets > and net. All implementations share an almost identical API making it > trivial to switch from one implementation to another. " > > Emile Unfortunately not. I wish I was! That sounds brilliant. From nat.abbotts at gmail.com Tue Dec 28 17:53:56 2010 From: nat.abbotts at gmail.com (Nathanael Abbotts) Date: Tue, 28 Dec 2010 14:53:56 -0800 (PST) Subject: Replacing Greenlets with Threads or Processes In-Reply-To: Message-ID: <857278fc-bf46-407d-ba76-db3e03a39b63@glegroupsg2000goo.googlegroups.com> On Tuesday, December 28, 2010 5:04:48 PM UTC, Emile van Sebille wrote: > On 12/28/2010 8:07 AM Nathanael Abbotts said... > > That thread seems to deal with mixing them. I want to replace them > > completely - is that possible (with either threads or processes)? > > Are you working with pycsp? the info at > http://code.google.com/p/pycsp/wiki/Getting_Started_With_PyCSP says: > > "The API is implemented in four versions: Threads, processes, greenlets > and net. All implementations share an almost identical API making it > trivial to switch from one implementation to another. " > > Emile Unfortunately not. I wish I was! That sounds brilliant. From tjreedy at udel.edu Tue Dec 28 18:18:43 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 28 Dec 2010 18:18:43 -0500 Subject: round in 2.6 and 2.7 In-Reply-To: <4D1A5ADA.5040500@v.loewis.de> References: <87sjxoco6u.fsf@xemacs.org> <5f07e3a7-5f13-4ca0-bcde-75a916ac9210@r29g2000yqj.googlegroups.com> <4D1A5ADA.5040500@v.loewis.de> Message-ID: On 12/28/2010 4:47 PM, Martin v. Loewis wrote: >>> "Float-to-string and string-to-float conversions are correctly rounded. >>> The round() function is also now correctly rounded." The second line was written to be parallel to the first, but the first is slightly ambiguous in that 'conversions' can refer to either process (not rounded, correctly or otherwise ;-) or result. However the parallelism does not does as 'round() function' is the instrument of the process and definitly not the result. ... > I see. Shouldn't it say then "The round() function > gives/produces/returns correctly rounded results now", instead of saying > that > the round function *is* correctly rounded? ISTM that the round > function cannot be rounded (correctly or not): In 2.7 "Float-to-string and string-to-float conversion results are correctly rounded, as are the results of the round() function." -- Terry Jan Reedy From lists at cheimes.de Tue Dec 28 19:45:49 2010 From: lists at cheimes.de (Christian Heimes) Date: Wed, 29 Dec 2010 01:45:49 +0100 Subject: Interning own classes like strings for speed and size? In-Reply-To: <878vz9d558.fsf@xemacs.org> References: <8nra78Foh3U1@mid.uni-berlin.de> <4d19203f$0$29993$c3e8da3$5496439d@news.astraweb.com> <8nu4a2Fp63U1@mid.uni-berlin.de> <4d19f02c$0$29993$c3e8da3$5496439d@news.astraweb.com> <878vz9d558.fsf@xemacs.org> Message-ID: Am 28.12.2010 21:16, schrieb Hrvoje Niksic: > Christian Heimes writes: > >> Also this code is going to use much more memory than an ordinary tuple >> since every instance of InternedTuple has a __dict__ attribute. This >> code works but I had to move the cache outside the class because of >> __slots__. > > Wouldn't it work inside the class as well? __slots__ applies to > instances, not to classes themselves. In Python 3.1: You are right as long as you don't try to rebind the variable. I recalled that class attributes of classes with __slots__ behave slightly different than ordinary classes. For example you can't have a writeable slot and class default values at the same time. >>> class Example2(object): ... __slots__ = () ... _cache = {} ... >>> Example2()._cache {} >>> Example2()._cache = {} Traceback (most recent call last): File "", line 1, in AttributeError: 'Example2' object attribute '_cache' is read-only Christian From rami.chowdhury at merton.oxon.org Tue Dec 28 21:24:11 2010 From: rami.chowdhury at merton.oxon.org (Rami Chowdhury) Date: Wed, 29 Dec 2010 02:24:11 +0000 Subject: Interning own classes like strings for speed and size? In-Reply-To: References: <8nra78Foh3U1@mid.uni-berlin.de> <4d19203f$0$29993$c3e8da3$5496439d@news.astraweb.com> <8nu4a2Fp63U1@mid.uni-berlin.de> <4d19f02c$0$29993$c3e8da3$5496439d@news.astraweb.com> <878vz9d558.fsf@xemacs.org> Message-ID: On Wed, Dec 29, 2010 at 00:45, Christian Heimes wrote: > Am 28.12.2010 21:16, schrieb Hrvoje Niksic: >> Christian Heimes writes: >> >>> Also this code is going to use much more memory than an ordinary tuple >>> since every instance of InternedTuple has a __dict__ attribute. This >>> code works but I had to move the cache outside the class because of >>> __slots__. >> >> Wouldn't it work inside the class as well? ?__slots__ applies to >> instances, not to classes themselves. ?In Python 3.1: > > You are right as long as you don't try to rebind the variable. I > recalled that class attributes of classes with __slots__ behave slightly > different than ordinary classes. For example you can't have a writeable > slot and class default values at the same time. > >>>> class Example2(object): > ... ? ? __slots__ = () > ... ? ? _cache = {} > ... >>>> Example2()._cache > {} >>>> Example2()._cache = {} > Traceback (most recent call last): > ?File "", line 1, in > AttributeError: 'Example2' object attribute '_cache' is read-only Forgive me if I'm misunderstanding, but if you want to cache instances of a class, surely >> Example2()._cache = {} would defeat the purpose, at least for that instance of Example2? The slot seems writeable enough, after all >> Example2()._cache['foo'] = 'bar' seems to work? -- Rami Chowdhury "Never assume malice when stupidity will suffice." -- Hanlon's Razor +44-7581-430-517 / +1-408-597-7068 / +88-0189-245544 From devplayer at gmail.com Tue Dec 28 23:32:31 2010 From: devplayer at gmail.com (DevPlayer) Date: Tue, 28 Dec 2010 20:32:31 -0800 (PST) Subject: Dynamic list name from a string References: <48c5eb62-b011-4ff6-ad1e-be92abe2e2eb@o4g2000yqd.googlegroups.com> <87ec1487-e42d-4f9b-8d70-cb615e123007@k25g2000vbl.googlegroups.com> Message-ID: <6ac47465-d78c-4913-9795-2537dd168b90@p1g2000yqm.googlegroups.com> # dynamic_named_obj.py # comp.lang.python # 2010-12 Dec-28 # Topic: Dynamic list name from a string Options # attempts to answer OP's question # DevPlayer - not a solution I'd use # TO Original Poster OP: # Start from the bottom OPTION, the one you requested. # Work your way up and see how it gets simpler and # simpler to do what you want. Dynamically named # references start to look pointless. # I hope I addressed your question and hopefully shown # you the right direction and right reasons to avoid # using dynamically made named references. # But I could be wrong in your case. import time class DataStore(object): """A namespace similar to a module global scope.""" #def concatenate( one, two): # """Function to concatonate two lists.""" # return list( one + two) # ========= class Animal(object): """A base class for no real reason.""" def __init__(self, name): self.name = name self.date = time.clock() # --------- class Bear(Animal): def __init__(self, name): super(Bear, self).__init__(name) class BearCub(Bear): def __init__(self, name): super(BearCub, self).__init__(name) # --------- class Doe(Animal): def __init__(self, name): super(Doe, self).__init__(name) class Fawn(Doe): def __init__(self, name): super(Fawn, self).__init__(name) # An alternate namespace instead of module global ns = DataStore() OPTION = "BETTER YET" if OPTION == "BETTER YET": # don't name your lists, just make the global_list and use it # no intermediary lists needed really. ns.Animals = [ # ---------- 1st set of classes Bear("bob"), Bear("bill"), BearCub("obo"), BearCub("Bill jr."), # ---------- 2nd set of classes Doe("DoeADear"), Doe("AFemaleDear"), Fawn("Ray"), Fawn("Adropof"), ] for animal in ns.Animals: kind = animal.__class__.__name__ name = animal.name date = animal.date print kind, name, date # make a sorted, by date, list of bears old_bears = [obj for obj in ns.Animals if type(obj) is Bear] old_bears.sort(None, key=lambda animal: animal.date) ns.bears = old_bears # or sort all animals by date animals = [obj for obj in ns.Animals] animals.sort(None, key=lambda animal: animal.date) # then get just bears bears = [obj for obj in animals if type(obj) is Bear] elif OPTION == "BETTER": # don't name your lists, trust in checking if objects have attributes # that matter ns.Animals = { # ---------- 1st set of classes "bob": Bear("bob"), "Bill": Bear("bill"), "obo": BearCub("obo"), "Bill jr.": BearCub("Bill jr."), # ---------- 2nd set of classes "DoeADear": Doe("DoeADear"), "AFemaleDear": Doe("AFemaleDear"), "Ray": Fawn("Ray"), "Adropof": Fawn("Adropof"), } print ns.Animals['bob'].date # make a sorted list of objects based on an attribute -like date # sort by date for just bears # http://wiki.python.org/moin/HowTo/Sorting # look at Operator Module Functions too # make a sorted, by date, list of bears old_bears = [obj for obj in ns.Animals.values() if type(obj) is Bear] old_bears.sort(None, key=lambda animal: animal.date) ns.bears = old_bears # or sort all animals by date animals = [obj for obj in ns.Animals.values()] animals.sort(None, key=lambda animal: animal.date) # then get just bears bears = [obj for obj in animals if type(obj) is Bear] elif OPTION == "SOSO1": # alternative to dynamically named references (object attributes) # Each item in global_dict is a sub dict ns.Animals = {} # ---------- 1st set of classes ns.Animals[ Bear ] = {"bob": Bear("bob"), "Bill": Bear("Bill")} ns.Animals[ BearCub ] = {"obo": BearCub("obo"), "Bill jr.": Bearcub("Bill jr.")} # ---------- 2nd set of classes ns.Animals[ Doe ] = {"DoeADear": Doe("DoeADear"), "AFemaleDear": Doe("AFemaleDear")} ns.Animals[ Fawn ] = {"Ray": Fawn("Ray"), "Adropof": Fawn("Adropof")} print ns.Animals[Bear]["bob"].date print ns.Animals[BearCub]["Bill jr."].date elif OPTION == "SOSO2": # alternative to dynamically named references (object attributes) # don't use names at all - # Each item in a dict is a list of objects # use class itself as key (not class name) ns.Animals = {} # ---------- 1st set of classes ns.Animals[ Bear ] = [Bear("bob"), Bear("Bill")] ns.Animals[ BearCub ] = [BearCub("obo"), Bearcub("Bill jr.")] # ---------- 2nd set of classes ns.Animals[ Doe ] = [Doe("DoeADear"), Doe("AFemaleDear")] ns.Animals[ Fawn ] = [Fawn("Ray"), Fawn("Adropof")] print ns.Animals[Bear][0].date elif OPTION == "SOSO3": # alternative to dynamically named references (object attributes) # use class __name__ as key ns.Animals = {} # ---------- 1st set of classes ns.Animals[ Bear.__name__ ] = [Bear("bob"), Bear("Bill")] ns.Animals[ BearCub.__name__ ] = [BearCub("obo"), Bearcub("Bill jr.")] # ---------- 2nd set of classes ns.Animals[ Doe.__name__ ] = [Doe("DoeADear"), Doe("AFemaleDear")] ns.Animals[ Fawn.__name__ ] = [Fawn("Ray"), Fawn("Adropof")] else: #OPTION LAST # What OP was requesting # ---------- 1st set of classes ref_name = Bear.__name__ + "_list" setattr(ns, ref_name, {"bob":Bear("bob"), "bill": Bear("Bill")}) ref_name = BearCub.__name__ + "_list" setattr(ns, ref_name, {"obo":Bear("obo"), "Bill jr.": Bear("Bill jr.")}) # ---------- 2nd set of classes ref_name = Doe.__name__ + "_list" setattr(ns, ref_name, {"DoeADear":Bear("DoeADear"), "AFemaleDear": Bear("AFemaleDear")}) ref_name = Doe.__name__ + "_list" setattr(ns, ref_name, {"Ray":Bear("Ray"), "Adropof": Bear("Adropof")}) # bet that didn't look as appealing as you thought it might # Now thing of all the times you'll use those dynamically # generated reference names (variables). # Do you really need to access "unknown" named references? # ---------- # concatenate all instances of all Animal subclasses into one big dict # ns.globalDict = {item[0]:item[1] for item in ns.__dict__.items() if "_list" in item[0]} # ns.globalDict = {} # make a list of lists (where each list contains instances of a certain class) # alist_of_lists = [key for key in ns.__dict__ if "_list" in key] # using reduce because OP didn't know how many sub-lists will be added # a = ['one', 'two', 'three',] # b = [1, 2, 3] # reduce(concatenate, [a, b]) # ['one', 'two', 'three', 1, 2, 3] # poop'd out. From stef.mientki at gmail.com Wed Dec 29 04:27:40 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Wed, 29 Dec 2010 10:27:40 +0100 Subject: NameError: global name 'btn_Matlab' is not defined ? In-Reply-To: <4d19f10d$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <4d19f10d$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4D1AFF0C.1050106@gmail.com> On 28-12-2010 15:15, Steven D'Aprano wrote: > On Tue, 28 Dec 2010 14:34:19 +0100, Stef Mientki wrote: > >> hello, >> >> Never seen this before and I've no explanation whatsoever (Python 2.6) >> >> I've some dynamic generated code, >> one of objects generated is a wx.Button, called 'btn_Matlab'. > How do you generate the code? > > What code is generated? What does it do? > > >> After the code is generated, I can see that the button is created in the >> local namespace >> >> print locals()['btn_Matlab'] >> >> > 0x3602d28> > >> >> but if I try to print the button (at exactly the same location), I get >> an error >> >> print btn_Matlab >> >> NameError: global name 'btn_Matlab' is not defined ? >> >> Why isn't the compiler first checking the local namespace ? any clues ? > > My guess is that you've declared btn_Matlab as global, and then > dynamically created a local with the same name using exec or similar. thanks Stevem, I found a solution. I indeed tried to "inject" local variables from a stack a few levels deeper, which doesn't seem to be possible (or reliable). The documentation isn't overwhelming about that point, exec and eval doesn't mention anything, but execfile warms for this issue. The code now looks something like this: self.p_locals = sys._getframe ( StackUp ).f_locals self.p_globals = sys._getframe ( StackUp ).f_globals Component = eval ( defi[1], self.p_globals, self.p_locals ) ( Parent, **Extra ) self.p_globals[ 'Component' ] = Component if 'self' in defi[0] : exec ( '%s = Component' %( defi[0] ), self.p_globals, self.p_locals ) else : exec ( '%s = Component' %( defi[0] ), self.p_globals) cheers, Stef From as at sci.fi Wed Dec 29 04:48:08 2010 From: as at sci.fi (Anssi Saari) Date: Wed, 29 Dec 2010 11:48:08 +0200 Subject: Noob question on 2 vs 3 Python releases References: Message-ID: Franck Ditter writes: > Pardon my noobness (?) but why is there a 2.x and 3.x development > teams working concurrently in Python ? Well, Python 2.7 is the last major 2.x release, only bugfixes are done for it, like the 2.7.1 release. Actual developement is in the 3.x branch now. > Which one should I choose to start with, to cope with > the future ? I started with a good book covering both. The basics are mostly the same anyways. From steve.gnulinux at gmail.com Wed Dec 29 05:39:02 2010 From: steve.gnulinux at gmail.com (Steve) Date: Wed, 29 Dec 2010 02:39:02 -0800 (PST) Subject: A wrap for a multi-tabbed terminal. Some questions Message-ID: http://pastie.org/763792/wrap This in IMHO, a really useful piece of code, to wrap and run terminal commands, on a gtk+vte python based gui. I would to make some improvements, in order to wrap some terminal applications. How can SET_FOCUS (at start) to the first vte frame? (Avoiding to click on terminal to get focus) How can fork a command thru the menus? thank you, Steve, From dickinsm at gmail.com Wed Dec 29 05:52:52 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 29 Dec 2010 02:52:52 -0800 (PST) Subject: round in 2.6 and 2.7 References: <87sjxoco6u.fsf@xemacs.org> <5f07e3a7-5f13-4ca0-bcde-75a916ac9210@r29g2000yqj.googlegroups.com> <4D1A5ADA.5040500@v.loewis.de> Message-ID: <2c68a5e7-91b9-400d-a706-afae5090ecf7@z9g2000yqz.googlegroups.com> On Dec 28, 9:47?pm, "Martin v. Loewis" wrote: > >> "Float-to-string and string-to-float conversions are correctly rounded. > >> The round() function is also now correctly rounded." > > >> Not sure that this is correct English; I think it means that the > >> round() function is now correct. > > > Well, the correct result of the example the OP gave would be 9.9 > > exactly. ?But since 9.9 isn't exactly representable as a Python float, > > we necessarily get an approximation. ?The language above is intended > > to convey that it's the 'correctly rounded' approximation > > I see. Shouldn't it say then "The round() function > gives/produces/returns correctly rounded results now", instead of saying > that > the round function *is* correctly rounded? ISTM that the round > function cannot be rounded (correctly or not): > > py> round(round) > Traceback (most recent call last): > ? File "", line 1, in > TypeError: a float is required > > But then, I'm not a native speaker (of English). I dare say that you're just as much a native speaker as anyone else when it comes to the language of floating-point arithmetic. Not sure English comes into it that much. :-) Sure, I agree it's probably a slight abuse of language to refer to a function as 'correctly rounded', but I think it's a fairly standard abuse. From the two nearest references to hand: IEEE 754-2008 has a whole section entitled 'Recommended correctly rounded functions' (nit: shouldn't there be a hyphen in that title?), and persists in referring to 'correctly rounded' conversions. The more formal uses in that document do indeed refer to single values, though. ("A conforming function shall return results correctly rounded ...") The 'Handbook of Floating-Point Arithmetic' by Muller et. al. gives a definition of a correctly rounded function in section 2.2. "When the exact result of a function is rounded according to a given rounding mode ..., one says that the function is *correctly rounded*." It's not so dissimilar from other mathematical abuses, like describing a real-valued function as 'positive', when what you actually mean is that all its values are positive. It's also slightly unsettling usage for me, not least because the statement 'f is correctly rounded' for a floating-point function f is really a statement about *two* functions: namely, f (a function from floating-point numbers to floating-point numbers) and the true mathematical function that it's based on; the identity of the underlying mathematical function is left implicit. -- Mark From skarra at gmail.com Wed Dec 29 05:57:31 2010 From: skarra at gmail.com (Karra) Date: Wed, 29 Dec 2010 02:57:31 -0800 (PST) Subject: Making urllib2's POST 302 handle same as Perl LWP's behaviour Message-ID: <1c165589-a054-4065-b050-50f2535b0897@37g2000prx.googlegroups.com> I am doing a POST to a webserver and get a 302 Found response (redirect). urllib2's default behaviour is to do a GET on the new url from the Location: URI in the 302 response. This is different from what I have found with LWP::UserAgent- >request() in perl. After much searching I understand there is a view that automatic redirection for a 302 in response to a POST is not in conformance to the relevant RFCs. Therefore, I believe urllib2's behaviour appears to be non-conformant (as, I believe are many browsers). Now, regardless of what is the "correct" approach to handling the 302, there is some information in the returned html of the 302 which I am losing because of the subsequent GET. I tried to raise a HTTPError from redirect_request() but that just kills the connection with the server. I tried returning None, same result. Can someone point me to how I can get the default LWP:UserAgent behaviour of handling this scenario using urllib2? From meitham at meitham.com Wed Dec 29 06:05:27 2010 From: meitham at meitham.com (meitham) Date: Wed, 29 Dec 2010 03:05:27 -0800 (PST) Subject: etl tool!!!!! References: Message-ID: <1e7b9314-1186-4a94-ad3b-79ea856dafe8@i18g2000yqn.googlegroups.com> BOn Dec 28, 1:14?pm, Stefan Sonnenberg-Carstens wrote: > Am 28.12.2010 13:57, schrieb krishna kumar:> Is there any efficient etl tool developed in python? > > Yes, Python. I use SQLAlchemy for both sources and targets, just because I hate to type sql queries :-) I am convincing clients to ditch solutions such informatica and talend in favour of plain python. I don't understand the mentality that learning an ETL graphical tool can be easier than learning a programming language, why don't just hire programmers and teach them business, after all, programmers are cheaper and often more intelligent. From hniksic at xemacs.org Wed Dec 29 06:25:29 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Wed, 29 Dec 2010 12:25:29 +0100 Subject: Interning own classes like strings for speed and size? References: <8nra78Foh3U1@mid.uni-berlin.de> <4d19203f$0$29993$c3e8da3$5496439d@news.astraweb.com> <8nu4a2Fp63U1@mid.uni-berlin.de> <4d19f02c$0$29993$c3e8da3$5496439d@news.astraweb.com> <878vz9d558.fsf@xemacs.org> Message-ID: <87zkrobz2u.fsf@xemacs.org> Christian Heimes writes: > You are right as long as you don't try to rebind the variable. And then only if you assign through an instance, which doesn't make sense for a class-level cache. Assignment like Example2._cache = {} would work. From scbunn at sbunn.org Wed Dec 29 06:39:54 2010 From: scbunn at sbunn.org (Stephen Bunn) Date: Wed, 29 Dec 2010 20:39:54 +0900 Subject: O'Reilly Python Certification In-Reply-To: References: <4D0900D3.10000@stoneleaf.us> <4D0927C1.5080209@tim.thechases.com> <4D093176.3010109@pythonmeister.com> <4D0A3306.3090100@stoneleaf.us> Message-ID: <87fwtgolit.wl%scbunn@sbunn.org> At Tue, 28 Dec 2010 20:07:29 +0000 (UTC), J. Altman wrote: > > I have a general question. > > Does it seem odd that a certificate in Python, an Open Source > language; taught at O'Reilly, which offers an Open Source Programming > Certificate and is something like waist-deep in Open Source > publishing; is offered to the world at large but only (IIUC) if one > runs some version of Windows by MS? > > Based on what I am given to understand from my correspondence with > OST, it seems that I *must* install an instance of Windows to take the > certificate's courses. This is not true. You can take the course on any operating system that supports a RDP client. I am enrolled with in the python course and I use GNU/Linux. They even have instructions on their website on how to configure it. I would have preferred them to use a UNIX shell. I'm still waiting for somebody to come up with a course that teaches me a programming language, while teaching me a VCS and allows me to write code and submit to a repo with other students contributing. You want to bring people into F/OSS -- That is how you do it! The complaint that I do have with OST (at least the Python course) and the reason I have not completed (or even worked on the course in almost a year) it, is that its just plain boring. It's almost 2011! Give me some interactive flash, a video, something. Reading some pages of dry text just doesn't cut it for me. I can do that on my own. If I'm going to pay for a course I want a teacher that is going to teach me something. I can buy plenty of books and read them. The entire course is just plain dry text. I don't even remeber seeing an image diagram. On top of that the text is horribly ugly to look at. From scbunn at sbunn.org Wed Dec 29 06:40:24 2010 From: scbunn at sbunn.org (Stephen Bunn) Date: Wed, 29 Dec 2010 20:40:24 +0900 Subject: O'Reilly Python Certification In-Reply-To: References: <4D0900D3.10000@stoneleaf.us> <4D0927C1.5080209@tim.thechases.com> <4D093176.3010109@pythonmeister.com> <4D0A3306.3090100@stoneleaf.us> Message-ID: <87ei90olhz.wl%scbunn@sbunn.org> At Tue, 28 Dec 2010 20:07:29 +0000 (UTC), J. Altman wrote: > > I have a general question. > > Does it seem odd that a certificate in Python, an Open Source > language; taught at O'Reilly, which offers an Open Source Programming > Certificate and is something like waist-deep in Open Source > publishing; is offered to the world at large but only (IIUC) if one > runs some version of Windows by MS? > > Based on what I am given to understand from my correspondence with > OST, it seems that I *must* install an instance of Windows to take the > certificate's courses. This is not true. You can take the course on any operating system that supports a RDP client. I am enrolled with in the python course and I use GNU/Linux. They even have instructions on their website on how to configure it. I would have preferred them to use a UNIX shell. I'm still waiting for somebody to come up with a course that teaches me a programming language, while teaching me a VCS and allows me to write code and submit to a repo with other students contributing. You want to bring people into F/OSS -- That is how you do it! The complaint that I do have with OST (at least the Python course) and the reason I have not completed (or even worked on the course in almost a year) it, is that its just plain boring. It's almost 2011! Give me some interactive flash, a video, something. Reading some pages of dry text just doesn't cut it for me. I can do that on my own. If I'm going to pay for a course I want a teacher that is going to teach me something. I can buy plenty of books and read them. The entire course is just plain dry text. I don't even remeber seeing an image diagram. On top of that the text is horribly ugly to look at. From scbunn at sbunn.org Wed Dec 29 06:41:15 2010 From: scbunn at sbunn.org (Stephen Bunn) Date: Wed, 29 Dec 2010 20:41:15 +0900 Subject: O'Reilly Python Certification In-Reply-To: References: <4D0900D3.10000@stoneleaf.us> <4D0927C1.5080209@tim.thechases.com> <4D093176.3010109@pythonmeister.com> <4D0A3306.3090100@stoneleaf.us> Message-ID: <87d3okolgk.wl%scbunn@sbunn.org> At Tue, 28 Dec 2010 20:07:29 +0000 (UTC), J. Altman wrote: > > I have a general question. > > Does it seem odd that a certificate in Python, an Open Source > language; taught at O'Reilly, which offers an Open Source Programming > Certificate and is something like waist-deep in Open Source > publishing; is offered to the world at large but only (IIUC) if one > runs some version of Windows by MS? > > Based on what I am given to understand from my correspondence with > OST, it seems that I *must* install an instance of Windows to take the > certificate's courses. This is not true. You can take the course on any operating system that supports a RDP client. I am enrolled with in the python course and I use GNU/Linux. They even have instructions on their website on how to configure it. I would have preferred them to use a UNIX shell. I'm still waiting for somebody to come up with a course that teaches me a programming language, while teaching me a VCS and allows me to write code and submit to a repo with other students contributing. You want to bring people into F/OSS -- That is how you do it! The complaint that I do have with OST (at least the Python course) and the reason I have not completed (or even worked on the course in almost a year) it, is that its just plain boring. It's almost 2011! Give me some interactive flash, a video, something. Reading some pages of dry text just doesn't cut it for me. I can do that on my own. If I'm going to pay for a course I want a teacher that is going to teach me something. I can buy plenty of books and read them. The entire course is just plain dry text. I don't even remeber seeing an image diagram. On top of that the text is horribly ugly to look at. From skarra at gmail.com Wed Dec 29 07:35:42 2010 From: skarra at gmail.com (Karra) Date: Wed, 29 Dec 2010 04:35:42 -0800 (PST) Subject: Making urllib2's POST 302 handle same as Perl LWP's behaviour References: <1c165589-a054-4065-b050-50f2535b0897@37g2000prx.googlegroups.com> Message-ID: <753d3952-2b21-4939-ae47-d714d9b02bf1@h17g2000pre.googlegroups.com> On Dec 29, 3:57?pm, Karra wrote: > Can someone point me to how I can get the default LWP:UserAgent > behaviour of handling this scenario using urllib2? Out of frustration, I decided to give 'mechanize' a try. It came as an awesome surprise that mechanize implements the exact api of urllib2 - meaning all I had to do was a query-replace of urllib2 to mechanize, and lo-and-behold I got what I wanted! Which is to say, the behaviour of mechanize matches Perl's LWP::UserAgent as afar as handling of POST redirects go. From orasnita at gmail.com Wed Dec 29 09:03:18 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Wed, 29 Dec 2010 16:03:18 +0200 Subject: Making urllib2's POST 302 handle same as Perl LWP's behaviour References: <1c165589-a054-4065-b050-50f2535b0897@37g2000prx.googlegroups.com> <753d3952-2b21-4939-ae47-d714d9b02bf1@h17g2000pre.googlegroups.com> Message-ID: <47800B33A68E4A648FC008806599BB85@teddy> I have tried: In httpd.conf: Redirect /one/ http://localhost/two/ Redirect /two/ http://localhost/three/ redirect /three/ http://www.google.com/ Then I made a POST request with LWP::UserAgent to /one: use LWP::UserAgent; print LWP::UserAgent->new->post('http://localhost/one/')->as_string; And the result was: HTTP/1.1 302 Found Connection: close Date: Wed, 29 Dec 2010 13:58:37 GMT Location: http://localhost/two/ Server: Apache/2.2.15 (Win32) mod_perl/2.0.4-dev Perl/v5.10.1 ... Exactly as you described. Then I made a POST request with WWW::Mechanize: use WWW::Mechanize; print WWW::Mechanize->new->post('http://localhost/one/')->as_string; And the result was: HTTP/1.1 200 OK Cache-Control: private, max-age=0 Connection: close Date: Wed, 29 Dec 2010 14:00:44 GMT Server: gws So it seems that LWP::UserAgent works similarly with mechanize and WWW::Mechanize similarly to urllib. Nice. :-) Octavian ----- Original Message ----- From: "Karra" Newsgroups: comp.lang.python To: Sent: Wednesday, December 29, 2010 2:35 PM Subject: Re: Making urllib2's POST 302 handle same as Perl LWP's behaviour On Dec 29, 3:57 pm, Karra wrote: > Can someone point me to how I can get the default LWP:UserAgent > behaviour of handling this scenario using urllib2? Out of frustration, I decided to give 'mechanize' a try. It came as an awesome surprise that mechanize implements the exact api of urllib2 - meaning all I had to do was a query-replace of urllib2 to mechanize, and lo-and-behold I got what I wanted! Which is to say, the behaviour of mechanize matches Perl's LWP::UserAgent as afar as handling of POST redirects go. -- http://mail.python.org/mailman/listinfo/python-list From inigoserna at gmail.com Wed Dec 29 10:05:23 2010 From: inigoserna at gmail.com (=?UTF-8?B?ScOxaWdvIFNlcm5h?=) Date: Wed, 29 Dec 2010 16:05:23 +0100 Subject: ANN: MyNewspaper v3.0 Message-ID: Hi there, I'm really pleased to announce a new release of MyNewspaper, a web-based personal RSS aggregator and feeds reader. Although no public releases in last years, I've been improving MyNewspaper continually for my personal use, but I think it's the time to publish it again. Some technical points of interest: - backend based on CherryPy web framework, FeedParser, SQLObject, SQLite - frontend with javascript (jQuery, jQueryUI, jQuery-mobile) More information, complete requirements and download link at: [main] https://inigo.katxi.org/devel/mynewspaper/ [mirror] http://www.terra.es/personal7/inigoserna/mynewspaper/ Of course, all comments, suggestions etc. are welcome. Best regards, I?igo Serna From stagi.andrea at gmail.com Wed Dec 29 10:57:18 2010 From: stagi.andrea at gmail.com (Andrea Stagi) Date: Wed, 29 Dec 2010 07:57:18 -0800 (PST) Subject: Tiny4py, a little python wrapper to make shorten urls and QRCodes Message-ID: Hi, I would announce you my new python wrapper to make shorten urls and QRCodes, using main used services: goo.gl, bit.ly and tinyurl. Please, visit http://code.google.com/p/tiny4py/ Bests From wxjmfauth at gmail.com Wed Dec 29 11:07:25 2010 From: wxjmfauth at gmail.com (jmfauth) Date: Wed, 29 Dec 2010 08:07:25 -0800 (PST) Subject: Does Python 3.1 accept \r\n in compile()? Message-ID: <5c7ae38a-4302-427b-98f0-2900eaf2a974@l24g2000vby.googlegroups.com> I wrote miscellaneous interactive interpreters and I fall on this. In Python 2.7 (understand Python > 2.6), a source code can be compiled with "native" '\r\n' as eol. In Python 3.1, it does not seem to be the case. (Python 3.2.a/b not checked). Bug, regression, deliberate choice? >>> sys.version 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] >>> compile('if True:\n print 999\n', '', 'exec') at 02858DA0, file "", line 1> >>> compile('if True:\r\n print 999\r\n', '', 'exec') at 02858E30, file "", line 1> >>> exec(compile('if True:\r\n print 999\r\n', '', 'exec')) 999 >>> sys.version '3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit (Intel)]' compile('if True:\n print(999)\n', '', 'exec') at 0x01FE5458, file "", line 2> >>> exec(compile('if True:\n print(999)\n', '', 'exec')) 999 >>> # this fails >>> compile('if True:\r\n print(999)\r\n', '', 'exec') Traceback (most recent call last): File "", line 1, in File "", line 1 if True: ^ SyntaxError: invalid syntax From wingogoo at gmail.com Wed Dec 29 11:22:57 2010 From: wingogoo at gmail.com (wingoo) Date: Wed, 29 Dec 2010 08:22:57 -0800 (PST) Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> Message-ID: maybe you can try http://vtd-xml.sourceforge.net/ From jwhughes at hughesconcepts.com Wed Dec 29 11:40:07 2010 From: jwhughes at hughesconcepts.com (Joe Hughes) Date: Wed, 29 Dec 2010 11:40:07 -0500 Subject: Python 3 and SNMP Traps Message-ID: <38B73ABD-4C3D-465E-877E-78CEA323D59E@hughesconcepts.com> All: I'm using Python 3.1.3 and need to incorporate sending SNMP traps from my script. I've researched and I found pysnmp and net-snmp with python bindings. The first appears to be only for Python 2.x. The second I'm not certain about. Has anyone experience with this and able to give suggestions? Thanks, Joe From wander.lairson at gmail.com Wed Dec 29 13:18:35 2010 From: wander.lairson at gmail.com (wander.lairson) Date: Wed, 29 Dec 2010 16:18:35 -0200 Subject: PyUSB 1.0.0 alpha 1 release Message-ID: Dear all, PyUSB 1.0.0 alpha 1 is out. Since alpha 0, this version : - Standard control requests through usb.control module. - String descriptors through usb.util module. - Complete PyUSB 0.4 API emulation. - Working libusb 1.0 support under Windows. For details check the ReleaseNotes.txt and ChangeLog files. This version can be download through sourceforge: https://sourceforge.net/projects/pyusb/files/PyUSB%201.0/1.0.0-alpha-1/ For further information about PyUSB visit the project website: http://pyusb.sourceforge.net -- Best Regards, Wander Lairson Costa LCoN - Laborat?rio de Computa??o Natural - Natural Computing Laboratory (http://www.mackenzie.com.br/lcon.html) Programa de P?s-Gradua??o em Engenharia El?trica (PPGEE) Faculdade de Computa??o e Inform?tica (FCI) Universidade Presbiteriana Mackenzie - SP - Brazil From tjreedy at udel.edu Wed Dec 29 14:31:37 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 29 Dec 2010 14:31:37 -0500 Subject: Does Python 3.1 accept \r\n in compile()? In-Reply-To: <5c7ae38a-4302-427b-98f0-2900eaf2a974@l24g2000vby.googlegroups.com> References: <5c7ae38a-4302-427b-98f0-2900eaf2a974@l24g2000vby.googlegroups.com> Message-ID: On 12/29/2010 11:07 AM, jmfauth wrote: > I wrote miscellaneous interactive interpreters and > I fall on this. > > In Python 2.7 (understand Python> 2.6), a source code > can be compiled with "native" '\r\n' as eol. I am a bit surprised, but I presume this is one on many back-compatibility holdovers still in 2.7. I believe 2.7 normally reads input with universal newline support, so that line endings are fixed on input, where they should be. Within Python, 'newline' is '\n'. > In Python 3.1, it does not seem to be the case. In 3.0, there were many simplifications where old things got dropped. > (Python 3.2.a/b not checked). I have not heard of any change. The compile() entry has the following: "Changed in version 3.2: Allowed use of Windows and Mac newlines. Also input in 'exec' mode does not have to end in a newline anymore. Added the optimize parameter." The second and third statement are true, but >>> compile('print(999)\r\n', '', 'exec') Traceback (most recent call last): File "", line 1, in compile('print(999)\r\n', '', 'exec') File "", line 1 print(999) ^ SyntaxError: invalid syntax I will inquire on pydev. > Bug, regression, deliberate choice? I presume deliberate simplification, but you can wait for another answer or check svn logs of the appropriate source file. Or there might be an entry in 3.0 NEWS or What's New files. -- Terry Jan Reedy From tjreedy at udel.edu Wed Dec 29 15:14:45 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 29 Dec 2010 15:14:45 -0500 Subject: Does Python 3.1 accept \r\n in compile()? In-Reply-To: References: <5c7ae38a-4302-427b-98f0-2900eaf2a974@l24g2000vby.googlegroups.com> Message-ID: On 12/29/2010 2:31 PM, Terry Reedy wrote: > "Changed in version 3.2: Allowed use of Windows and Mac newlines. Also > input in 'exec' mode does not have to end in a newline anymore. Added > the optimize parameter." Retest shows that above is correct. >>> compile("print(999)\r\n", "blah", "exec") at 0x00F5EC50, file "blah", line 1> For most development purposes (not just yours), 3.2b2 is already better than 3.1. Terry Jan Reedy From wxjmfauth at gmail.com Wed Dec 29 16:06:38 2010 From: wxjmfauth at gmail.com (jmfauth) Date: Wed, 29 Dec 2010 13:06:38 -0800 (PST) Subject: Does Python 3.1 accept \r\n in compile()? References: <5c7ae38a-4302-427b-98f0-2900eaf2a974@l24g2000vby.googlegroups.com> Message-ID: <19d5330a-1237-4e7a-b9aa-47ce312ce8f9@d7g2000vbv.googlegroups.com> On 29 Dez., 21:14, Terry Reedy wrote: > On 12/29/2010 2:31 PM, Terry Reedy wrote: > > > "Changed in version 3.2: Allowed use of Windows and Mac newlines. Also > > input in 'exec' mode does not have to end in a newline anymore. Added > > the optimize parameter." > > Retest shows that above is correct. > > ?>>> compile("print(999)\r\n", "blah", "exec") > > at 0x00F5EC50, file "blah", line 1> > Ok, I see. Thanks. The '\r\n' acceptance has been introduced in Python 2.7 and I was a little bit suprised with Python 3.1. For the story, I'm not using directly the compile() command, but something like: .runsource(source) where source is coming from a GUI toolkit text widget. From tjreedy at udel.edu Wed Dec 29 18:11:14 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 29 Dec 2010 18:11:14 -0500 Subject: Does Python 3.1 accept \r\n in compile()? In-Reply-To: <19d5330a-1237-4e7a-b9aa-47ce312ce8f9@d7g2000vbv.googlegroups.com> References: <5c7ae38a-4302-427b-98f0-2900eaf2a974@l24g2000vby.googlegroups.com> <19d5330a-1237-4e7a-b9aa-47ce312ce8f9@d7g2000vbv.googlegroups.com> Message-ID: On 12/29/2010 4:06 PM, jmfauth wrote: > On 29 Dez., 21:14, Terry Reedy wrote: >> On 12/29/2010 2:31 PM, Terry Reedy wrote: >> >>> "Changed in version 3.2: Allowed use of Windows and Mac newlines. Also >>> input in 'exec' mode does not have to end in a newline anymore. Added >>> the optimize parameter." >> >> Retest shows that above is correct. >> >> >>> compile("print(999)\r\n", "blah", "exec") >> >> at 0x00F5EC50, file "blah", line 1> >> > > Ok, I see. Thanks. > > The '\r\n' acceptance has been introduced in Python 2.7 > and I was a little bit suprised with Python 3.1. 2.6 was followed by 3.0 and then 3.1. 2.7 will be followed by 3.2 in a couple more month. That feature was added to 2.7 and 3.2 in Nov 2009 long after 3.1. -- Terry Jan Reedy From gervaz at gmail.com Wed Dec 29 18:31:20 2010 From: gervaz at gmail.com (gervaz) Date: Wed, 29 Dec 2010 15:31:20 -0800 (PST) Subject: Interrput a thread Message-ID: <81c24eb1-41b6-442a-a971-8a44d2cd6c1b@p8g2000vbs.googlegroups.com> Hi all, I need to stop a threaded (using CTR+C or kill) application if it runs too much or if I decide to resume the work later. I come up with the following test implementation but I wanted some suggestion from you on how I can implement what I need in a better or more pythonic way. Here the code: import os import signal import time from threading import Thread, current_thread from queue import LifoQueue, Empty COMMAND = {"STOP": 0, "NORMAL": 1} THREAD_NUM = 5 lq = LifoQueue() print("{0}\n".format(os.getpid())) class InterceptInterrupt(Exception): pass class Handler: def __init__(self, queue): self._queue = queue def __del__(self): print("Bye bye!") def getHandler(self, signum, frame): print("Interrupt raised!") for _ in range(THREAD_NUM): self._queue.put((COMMAND["STOP"], None)) raise InterceptInterrupt h = Handler(lq) signal.signal(signal.SIGINT, h.getHandler) for i in range(25): lq.put((COMMAND["NORMAL"], i)) def do_work(queue): while True: time.sleep(5) try: cmd, value = queue.get(block=False) if cmd == COMMAND["STOP"]: print("{0}: STOP command received!".format(current_thread().name)) break elif cmd == COMMAND["NORMAL"]: print(value) except Empty: break threads = [Thread(target=do_work, args=(lq,)) for _ in range(THREAD_NUM)] for t in threads: t.start() while not lq.empty(): try: time.sleep(1) except (IOError, InterceptInterrupt): break for t in threads: t.join() if lq.empty(): print("The queue is empty.") else: print("The queue is NOT empty. Some additional work has to be done.") Thank you, Mattia From Philippe.vouters at laposte.net Wed Dec 29 18:31:36 2010 From: Philippe.vouters at laposte.net (A famous IT technical writer) Date: Wed, 29 Dec 2010 15:31:36 -0800 (PST) Subject: gSOAP and Python/ctypes Message-ID: <365e2387-5459-4783-b497-1937ccb37eb5@l32g2000yqc.googlegroups.com> For the moment onlly studied under Linux Fedora 13, here is a gSOAP + Python/ctypes + ctypesgen introduction available at http://vouters.dyndns.org/tima/Linux-gSOAP-C-Python-ctypes-Why_and_when_using_gSOAP-a_quick_introduction.html Hoping this will help some of you. From rantingrick at gmail.com Wed Dec 29 18:58:53 2010 From: rantingrick at gmail.com (rantingrick) Date: Wed, 29 Dec 2010 15:58:53 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! Message-ID: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> Tkinter: The good, the bad, and the ugly! ----------------------------------------- An expose by rantingrick ---------------------- The Good ---------------------- Back in the early days of Python --when this simplistic beauty of programming bliss we enjoy today was just a tiny glimmer of hope in a archaic world plagued by dark forest of braces and jagged caverns of cryptic syntaxes-- our beloved dictator (Mr. Van Rossum) had the foresight to include a simplistic GUI toolkit that we call Tkinter into the stdlib. And he saw that it was great, and that it was good, and so he rested. And when the first python programmers used this gift handed down from the gods they were pleased. They could see that all of the heavy work of cross-platform-ism landed square on the shoulders of TCL/Tk and all Python had to do was wrap a few methods to wield the beast we all know as graphical user interfaces. Life was good, people were happy...but darkness loomed on the horizon... ---------------- Enter the Bad ---------------- However as we all know there exists no real Utopian bliss without many pitfalls and snares. Since Tkinter is just a wrapping of some TclTk calls the people realized that they are now at the perilous mercy of another group of developers (psst: thats the TCL folks!) who have only their own goals and dreams in mind and could care less for the troubles of others. They realized that Tkinter was lacking. However this lacking was not Tkinters fault, no, the fault lye with TclTk. And to compound these problems they also realized that in order to fix the design problems inherit in TclTk they must learn an obscure and mostly useless language... TclTk!! -------------------------------- Utterly destroyed by the Ugly! -------------------------------- And then the people became very angry... "What a double cross!" they chanted. Why should we learn a language like TclTk just to fix problems that the TclTk folks need to fix themselves? Would not that time be more wisely spent in looking over code that is 100% Python and modifying it? Not only would our community benefit but we can propagate the maintainece and/or improvements to a wider group of folks by removing the high entrance requirements. When we elevate every python programmer to a PythonGUI maintainer then we will have achieved community nirvana! We have now reached a point where the very simplicity we have embraced (Tkinter) has become a stumbling block not only for the users of Tkinter, but more devastating is the damage this TCL/Tk monkey has done to keep our fellow Python brothers and sisters from learning how a GUI kit works (behind the scenes) with each OS to bring all this graphical stuff to life. ------------------------ So what should we do? ------------------------ The answer is simple. We need a 100% Python GUI. A GUI coded in Python from top to bottom. A GUI that is cross platform to the big three (Windows, Linux, and Mac). A GUI that not only is easy as Tkinter but also a GUI that can be manipulated by the average python programmer. A GUI that not only teaches the fundamentals of using a GUI, but also a GUI that teaches how a GUI works under the hood Then and only then will Python be truly what GvR intended. I want everyone here to consider what i am proposing and offer some opinions because it is time for change. From katie at coderstack.co.uk Wed Dec 29 19:07:16 2010 From: katie at coderstack.co.uk (Katie T) Date: Thu, 30 Dec 2010 00:07:16 +0000 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> Message-ID: On Wed, Dec 29, 2010 at 11:58 PM, rantingrick wrote: > > Then and only then will Python be truly what GvR intended. I want > everyone here to consider what i am proposing and offer some opinions > because it is time for change. What's your opinion of the other gui toolkits with Python bindings like PyQt and PyGtk? Katie -- CoderStack http://www.coderstack.co.uk/perl-jobs The Software Developer Job Board From rantingrick at gmail.com Wed Dec 29 19:15:54 2010 From: rantingrick at gmail.com (rantingrick) Date: Wed, 29 Dec 2010 16:15:54 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> Message-ID: <18c2f4d8-0cce-4cdf-a386-80831dc2f114@m37g2000vbn.googlegroups.com> On Dec 29, 6:07?pm, Katie T wrote: > On Wed, Dec 29, 2010 at 11:58 PM, rantingrick wrote: > > What's your opinion of the other gui toolkits with Python bindings > like PyQt and PyGtk? Hello KateT, Well i like wxPython as it is quite well rounded but we all know it has some shortcomings too and wx is far too bloated for the stdlib! pyQt and pyGtk i cannot comment on because i have no experience with them. However i need to stress that my intention is towards a 100% Python GUI. Not a binding, not a wrapping (except for OS calls!) but a *real* Python GUI. The only thing that i know of at this point is pyGUI although there are probably others. Allowing the average Python programmer the ability to read OS specific calls written in Python would not only benefit their GUI knowledge, but also there knowledge of OS's in general. I guess you could sum it as "Getting the most bang for your community buck". From alex.kapps at web.de Wed Dec 29 19:34:32 2010 From: alex.kapps at web.de (Alexander Kapps) Date: Thu, 30 Dec 2010 01:34:32 +0100 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> Message-ID: <4D1BD398.3070003@web.de> On 30.12.2010 00:58, rantingrick preached: > > Tkinter: The good, the bad, and the ugly! > ----------------------------------------- > An expose by rantingrick You are seriously starting to sound like Xah Lee. > our beloved dictator (Mr. Van Rossum) had the foresight to include a simplistic GUI toolkit that we call Tkinter > into the stdlib. And he saw that it was great, and that it was good, and so he rested. For a technocrat (and that's an insult, in my book), you have a really annoying bible-style type of speech (or do you just play too much WoW?). Would you please stop to consider your own, what 4 or 5, years of programming experience to be enough to judge on such reasons? Some thought-food for you: What other GUI toolkit even just *could* had been included by Pan, Jesus, Mohammed, Budda, or God herself? (it's *your* wording that makes me include such names) > The answer is simple. We need a 100% Python GUI. How many times did you say that now? Have you done anything to archive that goal? Have you even tried to support existing projects? I'm going to bet my right arm, that you haven't. > Then and only then will Python be truly what GvR intended. I must admit, you keep true with yourself and even advance on that. Now you not only claim to speech for the whole Python community, but for Guide himself. Sorry, but how megalomaniac are you? From greno at verizon.net Wed Dec 29 19:41:43 2010 From: greno at verizon.net (Gerry Reno) Date: Wed, 29 Dec 2010 19:41:43 -0500 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: <18c2f4d8-0cce-4cdf-a386-80831dc2f114@m37g2000vbn.googlegroups.com> References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <18c2f4d8-0cce-4cdf-a386-80831dc2f114@m37g2000vbn.googlegroups.com> Message-ID: <4D1BD547.3090707@verizon.net> wxPython looks good but I don't see anyone developing support for things like smartphones. Also, what do you think about frameworks such as pyjamas? It lets you write in python and compiles everything down to Javascript so it can be used across the Web as well as on the desktop. From orasnita at gmail.com Wed Dec 29 19:48:59 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Thu, 30 Dec 2010 02:48:59 +0200 Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> Message-ID: <4208D3E6AF924DDABBC2411E051E7DB2@teddy> From: "rantingrick" > Back in the early days of Python --when this simplistic beauty of > programming bliss we enjoy today was just a tiny glimmer of hope in a > archaic world plagued by dark forest of braces and jagged caverns of > cryptic syntaxes-- our beloved dictator (Mr. Van Rossum) had the > foresight to include a simplistic GUI toolkit that we call Tkinter > into the stdlib. And he saw that it was great, and that it was good, > and so he rested. Yes, for that time it was good. > Life was good, people were happy...but darkness loomed on the > horizon... Not all the people were happy because the darkness disappeared partially for some of them and more and more blind people started to use a computer, and discovered that the Tk interfaces are absolutely inaccessible for them. > The answer is simple. We need a 100% Python GUI. A GUI coded in Python > from top to bottom. A GUI that is cross platform to the big three > (Windows, Linux, and Mac). A GUI that not only is easy as Tkinter but > also a GUI that can be manipulated by the average python programmer. A > GUI that not only teaches the fundamentals of using a GUI, but also a > GUI that teaches how a GUI works under the hood So it should be a kind of SWING library made in Python, right? It is a good idea, but it should not have the problems of SWING and in that case it would be very hard to do. First, the interface should look exactly as the native interfaces for each system named, and it should provide the same features, because otherwise the interface would look strange for all the users on all the operating systems. And of course, it should not only look OK, but it should also follow the accessibility standards for beeing accessible for screen readers also. WxPython is the best GUI because it is fast, even though it is bloated, it uses the native GUI elements on all those 3 operating systems and a relatively good accessibility for screen readers. But WxPython still have problems because not all operating systems native GUIS offer the same widgets and features and those features custom-made don't respect the accessibility standards. WxPython is fast because it is made in C - it uses the native GUI elements of the OS which are also made in C. Would a Python - only GUI have the same speed? If yes, it would be great. Octavian From orasnita at gmail.com Wed Dec 29 19:50:47 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Thu, 30 Dec 2010 02:50:47 +0200 Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> Message-ID: <893CF2EE06BA4AF79D4282AE2D475CAD@teddy> From: "Katie T" > What's your opinion of the other gui toolkits with Python bindings > like PyQt and PyGtk? > > Katie > -- They are not accessible at all for screen readers, so the programs that still use them won't be accessible to all potential users. Octavian From almar.klein at gmail.com Wed Dec 29 20:01:30 2010 From: almar.klein at gmail.com (Almar Klein) Date: Thu, 30 Dec 2010 02:01:30 +0100 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> Message-ID: On 30 December 2010 00:58, rantingrick wrote: > > Tkinter: The good, the bad, and the ugly! > ----------------------------------------- > An expose by rantingrick > > > ---------------------- > The Good > ---------------------- > Back in the early days of Python --when this simplistic beauty of > programming bliss we enjoy today was just a tiny glimmer of hope in a > archaic world plagued by dark forest of braces and jagged caverns of > cryptic syntaxes-- our beloved dictator (Mr. Van Rossum) had the > foresight to include a simplistic GUI toolkit that we call Tkinter > into the stdlib. And he saw that it was great, and that it was good, > and so he rested. > > And when the first python programmers used this gift handed down from > the gods they were pleased. They could see that all of the heavy work > of cross-platform-ism landed square on the shoulders of TCL/Tk and all > Python had to do was wrap a few methods to wield the beast we all know > as graphical user interfaces. > > Life was good, people were happy...but darkness loomed on the > horizon... > > > ---------------- > Enter the Bad > ---------------- > However as we all know there exists no real Utopian bliss without many > pitfalls and snares. Since Tkinter is just a wrapping of some TclTk > calls the people realized that they are now at the perilous mercy of > another group of developers (psst: thats the TCL folks!) who have only > their own goals and dreams in mind and could care less for the > troubles of others. They realized that Tkinter was lacking. However > this lacking was not Tkinters fault, no, the fault lye with TclTk. And > to compound these problems they also realized that in order to fix the > design problems inherit in TclTk they must learn an obscure and mostly > useless language... TclTk!! > > -------------------------------- > Utterly destroyed by the Ugly! > -------------------------------- > And then the people became very angry... "What a double cross!" they > chanted. Why should we learn a language like TclTk just to fix > problems that the TclTk folks need to fix themselves? Would not that > time be more wisely spent in looking over code that is 100% Python and > modifying it? Not only would our community benefit but we can > propagate the maintainece and/or improvements to a wider group of > folks by removing the high entrance requirements. When we elevate > every python programmer to a PythonGUI maintainer then we will have > achieved community nirvana! > > We have now reached a point where the very simplicity we have embraced > (Tkinter) has become a stumbling block not only for the users of > Tkinter, but more devastating is the damage this TCL/Tk monkey has > done to keep our fellow Python brothers and sisters from learning how > a GUI kit works (behind the scenes) with each OS to bring all this > graphical stuff to life. > > ------------------------ > So what should we do? > ------------------------ > The answer is simple. We need a 100% Python GUI. A GUI coded in Python > from top to bottom. A GUI that is cross platform to the big three > (Windows, Linux, and Mac). A GUI that not only is easy as Tkinter but > also a GUI that can be manipulated by the average python programmer. A > GUI that not only teaches the fundamentals of using a GUI, but also a > GUI that teaches how a GUI works under the hood > > Then and only then will Python be truly what GvR intended. I want > everyone here to consider what i am proposing and offer some opinions > because it is time for change. > -- > http://mail.python.org/mailman/listinfo/python-list > A lot of ranting indeed... I agree that Tk has a few shortcomings (I never use it myself), but since many people are currently using it, I don't see an easy way of replacing Tk with anything else. FWIW, I like the ideas of FLTK (very lightweight, just draw all widgets itself + has good OpenGl support), although the project seems to have lost its momentum. I think that you are suggesting something like that, but written in Python. Almar -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrick at gmail.com Wed Dec 29 20:03:38 2010 From: rantingrick at gmail.com (rantingrick) Date: Wed, 29 Dec 2010 17:03:38 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <18c2f4d8-0cce-4cdf-a386-80831dc2f114@m37g2000vbn.googlegroups.com> Message-ID: On Dec 29, 6:41?pm, Gerry Reno wrote: > wxPython looks good but I don't see anyone developing support for things > like smartphones. No wx is not the answer to our problems > Also, what do you think about frameworks such as pyjamas? ?It lets you > write in python and compiles everything down to Javascript so it can be > used across the Web as well as on the desktop. Hmm, this is like two double edged swords smashing one another in battle. Sword One: On one hand web frameworks are going to be really big soon -- however legacy GUI's are not going away any time soon! Sword Two: On the other hand web frameworks provide awesome cross platform ability that is surly only going to get better as time goes -- however i utterly hate JavaScript (although much worse web languages exist!). And sending requests back and forth between Python, JavaScript, and BrowserX is also a real PITA. Because even though everyone knows this is coming all the major browsers are trying to insert their API into the mix. So that Joe Scripter has to write code that is compatible between many browsers. Until the world agrees on a unified API --AND IMPLEMENTS IT SERIOUSLY-- we are at the mercy of drunken sailors at the helm. I believe pyjamas has a bright future in the web playground, however we still need to focus our community efforts towards a Python based GUI. I can see a pythonGUI and pyjamas existing side by side in mutual harmony for many years. From stef.mientki at gmail.com Wed Dec 29 21:05:35 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Thu, 30 Dec 2010 03:05:35 +0100 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <18c2f4d8-0cce-4cdf-a386-80831dc2f114@m37g2000vbn.googlegroups.com> Message-ID: <4D1BE8EF.8030900@gmail.com> On 30-12-2010 02:03, rantingrick wrote: > On Dec 29, 6:41 pm, Gerry Reno wrote: >> wxPython looks good but I don't see anyone developing support for things >> like smartphones. > No wx is not the answer to our problems Just partial ;-) Why not write a (Pythonic) wrapper and choose what will be under neat it ? My personal situation at this moment: * for desktop applications we basically use wxPython * the use of sizers in wxPython is not easy and full of cross-pointers with useless names. Therefor we already used a wrapper for wxPython. * for components missing in wxPython, we embed PySide-QT and Delphi components in wxPython * for server-side web applications we use web2py * for client-side web applications we use PyJamas * for mobile devices we use PocketPyGUI * as PySide-QT is making a huge progress at the moment and has improved licenses, (and might be usable for mobile devices) we might want to move gradually from wxPython to PySide-QT Right at this moment, I'm writing a new wrapper, that already can handle (in a simple way) wxPython and PySide-QT(partial). After this works fully, PyJamas and Web2pY will be added (PockectPyGui can probably fully be replaced by QT) cheers, Stef -------------- next part -------------- An HTML attachment was scrubbed... URL: From hankfay at gmail.com Wed Dec 29 21:11:12 2010 From: hankfay at gmail.com (Hank Fay) Date: Wed, 29 Dec 2010 18:11:12 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: Message-ID: <6f2af238-2d5c-4d81-8adf-02d6e782ebae@glegroupsg2000goo.googlegroups.com> 1) pyjamas has a desktop version. 2) I don't consider JSONRpc to be a deal-breaker, and since that's what pyjamas uses naturally, and since it's incredibly easy to use the Python middleware of your choice for the JSONRpc server, running in different browsers is unlikely to be an issue. 3) I don't think legacy apps should be a consideration in deciding what tooling is going to be built today: building for all the yesterdays is a recipe for stagnation. Besides, the legacy apps have their own toolsets for maintenance: if they are to be converted, converting them to a form that can run anywhere (using, e.g., PhoneGap to access native UI hooks) seems to me the best choice. That said, pyjamas has only the beginnings of a visual designer (pyjsglade at http://sourceforge.net/projects/pyjsglade/). It's being written in Python, too, which should please you (as it does me -- so much so that I volunteered to be a documenter for the project). I think pyjamas combined with pyjsglade could be the foundation for a pythonic ui development environment that could carry us forward for many years to come, unlike those available today in Python. Hank PS: At first I thought you were going to do a riff on "The Plan" from years ago. I had broken 5 ribs in multiple places in a bicycling accident 2 days before when a friend faxed it to me (it was that far back): I can't tell you how much it hurt to laugh so hard. But this isn't a laughing matter: I see it as the main impediment to opening up Python to the kinds of programmers who used Access, VB6 and VFP to build the kinds of domain-knowledge-specific apps that continue to enhance many workplaces. From hankfay at gmail.com Wed Dec 29 21:11:12 2010 From: hankfay at gmail.com (Hank Fay) Date: Wed, 29 Dec 2010 18:11:12 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: Message-ID: <6f2af238-2d5c-4d81-8adf-02d6e782ebae@glegroupsg2000goo.googlegroups.com> 1) pyjamas has a desktop version. 2) I don't consider JSONRpc to be a deal-breaker, and since that's what pyjamas uses naturally, and since it's incredibly easy to use the Python middleware of your choice for the JSONRpc server, running in different browsers is unlikely to be an issue. 3) I don't think legacy apps should be a consideration in deciding what tooling is going to be built today: building for all the yesterdays is a recipe for stagnation. Besides, the legacy apps have their own toolsets for maintenance: if they are to be converted, converting them to a form that can run anywhere (using, e.g., PhoneGap to access native UI hooks) seems to me the best choice. That said, pyjamas has only the beginnings of a visual designer (pyjsglade at http://sourceforge.net/projects/pyjsglade/). It's being written in Python, too, which should please you (as it does me -- so much so that I volunteered to be a documenter for the project). I think pyjamas combined with pyjsglade could be the foundation for a pythonic ui development environment that could carry us forward for many years to come, unlike those available today in Python. Hank PS: At first I thought you were going to do a riff on "The Plan" from years ago. I had broken 5 ribs in multiple places in a bicycling accident 2 days before when a friend faxed it to me (it was that far back): I can't tell you how much it hurt to laugh so hard. But this isn't a laughing matter: I see it as the main impediment to opening up Python to the kinds of programmers who used Access, VB6 and VFP to build the kinds of domain-knowledge-specific apps that continue to enhance many workplaces. From ben+python at benfinney.id.au Wed Dec 29 23:04:21 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 30 Dec 2010 15:04:21 +1100 Subject: Building sys.path at run-time? References: Message-ID: <87k4irhpoa.fsf@benfinney.id.au> Roy Smith writes: > I've got a problem that I'm sure many people have solved many times. > > Our project has a bunch of python scripts A very common problem. The solution is to switch to Perl. (Merry solstice silliness, everyone :-) -- \ ?An idea isn't responsible for the people who believe in it.? | `\ ?Donald Robert Perry Marquis | _o__) | Ben Finney From roy at panix.com Wed Dec 29 23:24:09 2010 From: roy at panix.com (Roy Smith) Date: Wed, 29 Dec 2010 23:24:09 -0500 Subject: Building sys.path at run-time? References: <87k4irhpoa.fsf@benfinney.id.au> Message-ID: In article <87k4irhpoa.fsf at benfinney.id.au>, Ben Finney wrote: > Roy Smith writes: > > > I've got a problem that I'm sure many people have solved many times. > > > > Our project has a bunch of python scripts > > A very common problem. The solution is to switch to Perl. > > (Merry solstice silliness, everyone :-) I have another problem. I hit the "Post" button by accident. Please ignore. From steve+comp.lang.python at pearwood.info Thu Dec 30 02:09:49 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Dec 2010 07:09:49 GMT Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> Message-ID: <4d1c303d$0$29967$c3e8da3$5496439d@news.astraweb.com> On Wed, 29 Dec 2010 15:58:53 -0800, rantingrick wrote: > Tkinter: The good, the bad, and the ugly! > ----------------------------------------- > An expose by rantingrick Your ideas are intriguing to me and I wish to subscribe to your newsletter. > The answer is simple. We need a 100% Python GUI. A GUI coded in Python > from top to bottom. A GUI that is cross platform to the big three > (Windows, Linux, and Mac). A GUI that not only is easy as Tkinter but > also a GUI that can be manipulated by the average python programmer. A > GUI that not only teaches the fundamentals of using a GUI, but also a > GUI that teaches how a GUI works under the hood I look forward to seeing this software of yours. Let us know when you've got some code, and not just empty talk. -- Steven From s.selvamsiva at gmail.com Thu Dec 30 02:30:58 2010 From: s.selvamsiva at gmail.com (Selvam) Date: Thu, 30 Dec 2010 13:00:58 +0530 Subject: Removing an attribute from html with Regex Message-ID: Hi all, I have some HTML string which I would like to feed to BeautifulSoup. But, One malformed attribute breaks BeautifulSoup.

My String

I would like it to replace all the occurances of that attribute with an empty string. I am unable to figure out the exact regex, which can do this job. This is what, I have managed so far, m = re.compile("rml_except='([^']*)") As you see, it will stop at the first occurance of single quote. Any suggestions will be useful. -- Regards, S.Selvam SG E-ndicus Infotech Pvt Ltd. http://e-ndicus.com/ " I am because we are " -------------- next part -------------- An HTML attachment was scrubbed... URL: From wxjmfauth at gmail.com Thu Dec 30 03:13:50 2010 From: wxjmfauth at gmail.com (jmfauth) Date: Thu, 30 Dec 2010 00:13:50 -0800 (PST) Subject: Does Python 3.1 accept \r\n in compile()? References: <5c7ae38a-4302-427b-98f0-2900eaf2a974@l24g2000vby.googlegroups.com> <19d5330a-1237-4e7a-b9aa-47ce312ce8f9@d7g2000vbv.googlegroups.com> Message-ID: On 30 Dez., 00:11, Terry Reedy wrote: > On 12/29/2010 4:06 PM, jmfauth wrote: > > > > > On 29 Dez., 21:14, Terry Reedy ?wrote: > >> On 12/29/2010 2:31 PM, Terry Reedy wrote: > > >>> "Changed in version 3.2: Allowed use of Windows and Mac newlines. Also > >>> input in 'exec' mode does not have to end in a newline anymore. Added > >>> the optimize parameter." > > >> Retest shows that above is correct. > > >> ? >>> ?compile("print(999)\r\n", "blah", "exec") > > >> ?at 0x00F5EC50, file "blah", line 1> > > > Ok, I see. Thanks. > > > The '\r\n' acceptance has been introduced in Python 2.7 > > and I was a little bit suprised with Python 3.1. > > 2.6 was followed by 3.0 and then 3.1. > 2.7 will be followed by 3.2 in a couple more month. > That feature was added to 2.7 and 3.2 in Nov 2009 long after 3.1. > > -- > Terry Jan Reedy Thanks for these precisions and don't worry too much, it's not a real isssue. (I'v seen the "noise" on the pydev list). Thanks again. From smainklh at free.fr Thu Dec 30 03:36:06 2010 From: smainklh at free.fr (smainklh at free.fr) Date: Thu, 30 Dec 2010 09:36:06 +0100 Subject: os.path.isfile and wildcard for directory name Message-ID: <1293698166.4d1c447655828@imp.free.fr> Hi everyone, I'm just beginning to learn python language and i'm trying to do something and i can't figure it out. I want to test if a file exists but my path contain a directory name that differs from a server to another. In shell i would have done something like that : #!/bin/bash mypath=/dire*/directory02/ myfile=filename myfile=toto if [ -f $mypath/$myfile ] then echo "File $file exists" fi How can i do the same thing (wildcard in a directory name) in python please ? Thanks for your help ! Smaine From javier.collado at gmail.com Thu Dec 30 03:52:37 2010 From: javier.collado at gmail.com (Javier Collado) Date: Thu, 30 Dec 2010 09:52:37 +0100 Subject: os.path.isfile and wildcard for directory name In-Reply-To: <1293698166.4d1c447655828@imp.free.fr> References: <1293698166.4d1c447655828@imp.free.fr> Message-ID: Hello, 2010/12/30 : > How can i do the same thing (wildcard in a directory name) in python please ? You can get the contents of a directory with os.listdir and filter with fnmatch.fnmatch more or less as in the example from the documentation: --------------------- import fnmatch import os for file in os.listdir('.'): if fnmatch.fnmatch(file, '*.txt'): print file --------------------- Regards, Javier From stefan_ml at behnel.de Thu Dec 30 03:53:53 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 30 Dec 2010 09:53:53 +0100 Subject: Removing an attribute from html with Regex In-Reply-To: References: Message-ID: Selvam, 30.12.2010 08:30: > I have some HTML string which I would like to feed to BeautifulSoup. > > But, One malformed attribute breaks BeautifulSoup. > >

class='terp_header'> My String

Didn't try with BS (and you forgot to say what "breaks" means exactly in your case), but it parses in a somewhat reasonable way with lxml: Python 3.2b2 (py3k:87572, Dec 29 2010, 21:25:38) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import lxml.html as H >>> doc = H.fromstring(''' ...

My String

... ''') >>> H.tostring(doc) b'

My String

' >>> doc.attrib {'text2': '', 'and': '', 'style': 'terp_header', \ 'wrong_tag': ' text1 ', 'class': 'terp_header'} > I would like it to replace all the occurances of that attribute with an > empty string. > > I am unable to figure out the exact regex, which can do this job. > > This is what, I have managed so far, > > m = re.compile("rml_except='([^']*)") I assume "rml_accept" is the real name of the attribute? You may be able to do this with a look-ahead expression, e.g.: replace = re.compile('(wrong_tag\s*=\s*[^>=]*)(?=>|\s+\w+\s*=)').sub html_data = replace('', html_data) The trick is to match everything up to the next character that looks reasonable again, i.e. a closing tag character (">") or another attribute. Stefan From __peter__ at web.de Thu Dec 30 04:01:36 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 30 Dec 2010 10:01:36 +0100 Subject: os.path.isfile and wildcard for directory name References: Message-ID: smainklh at free.fr wrote: > I'm just beginning to learn python language and i'm trying to do something > and i can't figure it out. > > I want to test if a file exists but my path contain a directory name that > differs from a server to another. > In shell i would have done something like that : > > #!/bin/bash > > mypath=/dire*/directory02/ > myfile=filename > > myfile=toto > > if [ -f $mypath/$myfile ] > then > echo "File $file exists" > fi > > > How can i do the same thing (wildcard in a directory name) in python > please ? Given $ mkdir yadda{1..10} $ touch yadda{5,7}/alpha $ mkdir yadda{2,4}/alpha You can get a list of candidates with >>> import glob >>> candidates = glob.glob("yadda*/alpha") >>> candidates ['yadda5/alpha', 'yadda2/alpha', 'yadda4/alpha', 'yadda7/alpha'] and then use isfile() to find the actual files: >>> import os >>> [f for f in candidates if os.path.isfile(f)] ['yadda5/alpha', 'yadda7/alpha'] Peter From cs at zip.com.au Thu Dec 30 04:04:44 2010 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 30 Dec 2010 20:04:44 +1100 Subject: os.path.isfile and wildcard for directory name In-Reply-To: <1293698166.4d1c447655828@imp.free.fr> References: <1293698166.4d1c447655828@imp.free.fr> Message-ID: <20101230090444.GA15318@cskk.homeip.net> On 30Dec2010 09:36, smainklh at free.fr wrote: | I want to test if a file exists but my path contain a directory name that | differs from a server to another. | In shell i would have done something like that : | #!/bin/bash | mypath=/dire*/directory02/ | myfile=filename | myfile=toto | if [ -f $mypath/$myfile ] [...] Check out the glob module: http://docs.python.org/library/glob.html#module-glob Use it to do the glob, then os.path.isfile with a path constructed from the result: http://docs.python.org/library/os.path.html#os.path.isfile Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Any company large enough to have a research lab is large enough not to listen to it. - Alan Kay From grahn+nntp at snipabacken.se Thu Dec 30 04:41:25 2010 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 30 Dec 2010 09:41:25 GMT Subject: Digitally Signing a XML Document (using SHA1+RSA or SHA1+DSA) References: Message-ID: On Tue, 2010-12-28, Adam Tauno Williams wrote: > On Tue, 2010-12-28 at 03:25 +0530, Anurag Chourasia wrote: >> Hi All, > >> I have a requirement to digitally sign a XML Document using SHA1+RSA >> or SHA1+DSA >> Could someone give me a lead on a library that I can use to fulfill >> this requirement? > > Never used it though. > >> The XML Document has values such as >> -----BEGIN RSA PRIVATE KEY----- >> MIIBOgIBAAJBANWzHfF5Bppe4JKlfZDqFUpNLrwNQqguw76g/jmeO6f4i31rDLVQ >> n7sYilu65C8vN+qnEGnPB824t/A3yfMu1G0CAQMCQQCOd2lLpgRm6esMblO18WOG ... > Is this any kind of standard or just something someone made up? Is > there a namespace for the document? > > It seems quite odd that the document contains a *private* key. > > If all you need to do is parse to document to retrieve the values that > seems straight-forward enough. > >> And the XML also has another node that has a Public Key with Modules >> and Exponents etc that I apparently need to utilize. >> >> 1bMd8XkGml7gkqV9kOoVSk0uvA1CqC7DvqD >> +OZ47p/iLfWsMtVCfuxiKW7rkLy836qcQac8Hzbi38DfJ8y7UbQ== >> Aw== >> > >> I am a little thin on this concept and expecting if you could guide me >> to a library/documentation that I could utilize. [The original posting by Anurag Chourasia did not reach my news server.] I'd simply invoke GnuPG. A simple example: % gpg --sign --armor foo You need a passphrase to unlock the secret key for user: ... % head foo.asc -----BEGIN PGP MESSAGE----- Version: GnuPG v1.4.9 (GNU/Linux) owGs+TuuLdGWRQu9B1hTwsAHaRUhPjN+DjVAWBRgxs+nGAgHA58aUA88RHVw6K3N 2PfefJn5Mg2ko6N99lkrYn7G6KN//m//6//l//C/+N/8X/5P/6//+//u//r/+P/+ ... The result isn't XML, but it *is* a standardized file format readable by anyone. That's worth a lot. You can also create a detached signature and ship it together with the original file, or skip the '--armor' and get a binary signed file. If you really *do* have a requirement to make the result XML-like and incompatible with anything else, I'm afraid you're on your own, and will have a lot of extra work testing and making sure it's all secure. /Jorgen -- // Jorgen Grahn O o . From stefan_ml at behnel.de Thu Dec 30 05:23:03 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 30 Dec 2010 11:23:03 +0100 Subject: Digitally Signing a XML Document (using SHA1+RSA or SHA1+DSA) In-Reply-To: References: Message-ID: Jorgen Grahn, 30.12.2010 10:41: > If you really *do* have a requirement to make the result XML-like and > incompatible with anything else, I'm afraid you're on your own Well, there's always xmlsec if you need it. http://www.aleksey.com/xmlsec/ Stefan From sathish at solitontech.com Thu Dec 30 06:15:41 2010 From: sathish at solitontech.com (Sathish S) Date: Thu, 30 Dec 2010 16:45:41 +0530 Subject: Embedding a Python IDE on Windows based Application Message-ID: Hi Ppl, I'm trying to use python for a macro recorder. In short I have a windows based application, which has a macro recorder. The macros are captured as a python script and when the script is executed they accomplish the user action done on my application. I've written python scripts that can invoke the user events on the application through ActiveX server of my application. I've been trying to run these macro python scripts using the command line option from my application. I also explored the extending and embedding the python interpreter option for executing my python scripts from my application. But I feel it will be great if I can embed a simple xpython IDE on my application to write these macro python scripts and debug them. I tried searching for any python IDE's which are available as ActiveX or .net containers, so that I can easily embed them. But I had no success. Is there any way I can accomplish this? Thanks, Sathish -------------- next part -------------- An HTML attachment was scrubbed... URL: From smainklh at free.fr Thu Dec 30 08:35:20 2010 From: smainklh at free.fr (smainklh at free.fr) Date: Thu, 30 Dec 2010 14:35:20 +0100 Subject: os.path.isfile and wildcard for directory name In-Reply-To: <20101230090444.GA15318@cskk.homeip.net> References: <1293698166.4d1c447655828@imp.free.fr> <20101230090444.GA15318@cskk.homeip.net> Message-ID: <1293716120.4d1c8a9875275@imp.free.fr> Hi Cameron, Ok, i'll try that :) Thanks Smaine Selon Cameron Simpson : > On 30Dec2010 09:36, smainklh at free.fr wrote: > | I want to test if a file exists but my path contain a directory name that > | differs from a server to another. > | In shell i would have done something like that : > | #!/bin/bash > | mypath=/dire*/directory02/ > | myfile=filename > | myfile=toto > | if [ -f $mypath/$myfile ] > [...] > > Check out the glob module: > http://docs.python.org/library/glob.html#module-glob > > Use it to do the glob, then os.path.isfile with a path constructed from > the result: > > http://docs.python.org/library/os.path.html#os.path.isfile > > Cheers, > -- > Cameron Simpson DoD#743 > http://www.cskk.ezoshosting.com/cs/ > > Any company large enough to have a research lab > is large enough not to listen to it. - Alan Kay > From wentlv at gmail.com Thu Dec 30 08:52:06 2010 From: wentlv at gmail.com (crow) Date: Thu, 30 Dec 2010 05:52:06 -0800 (PST) Subject: Is there anyway to run JavaScript in python? Message-ID: Hi, I'm writing a test tool to simulate Web browser. Is there anyway to run JavaScript in python? Thanks in advance. From askutt at gmail.com Thu Dec 30 08:53:52 2010 From: askutt at gmail.com (Adam Skutt) Date: Thu, 30 Dec 2010 05:53:52 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> Message-ID: <1a532380-8166-4bb7-ba15-3b2f146b759d@f8g2000yqd.googlegroups.com> On Dec 29, 7:48?pm, "Octavian Rasnita" wrote: > First, the interface should look exactly as the native interfaces for each system named, and it should provide the same features, because otherwise the interface would look strange for all the users on all the operating systems. > And of course, it should not only look OK, but it should also follow the accessibility standards for beeing accessible for screen readers also. > Which is where the contradiction comes into play: to use the actual native widgets, you have to write some C (or Objective-C). Of course, on Windows, people have faked the native widgets so many times that you could probably get away with it if you made a really good fake, though there are still a lot of gotchas that go with that (accessibility and all that "other stuff"). On Linux, it's not like there's really a standard anyway. That leaves OS X as the really troublesome one. >WxPython is fast because it is made in C - it uses the native GUI elements of the OS which are also made in C. Would a Python - only GUI have the same speed? If yes, it would be great. > Speed is not even on the list of things I'd be worried about first. Adam From roy at panix.com Thu Dec 30 09:11:09 2010 From: roy at panix.com (Roy Smith) Date: Thu, 30 Dec 2010 09:11:09 -0500 Subject: Is there anyway to run JavaScript in python? References: Message-ID: In article , crow wrote: > Hi, I'm writing a test tool to simulate Web browser. Is there anyway > to run JavaScript in python? Thanks in advance. The answer to the question you asked is, "Probably. You might want to check out SpiderMonkey as a starting point". The answer to the question you didn't ask is, "Before you invest a lot of effort in this, check out Selenium". http://en.wikipedia.org/wiki/SpiderMonkey_(JavaScript_engine) http://en.wikipedia.org/wiki/Selenium_(software) Another thing to think about is whether you really do need JS to test your web app. Depending on how much your app depends on JS for its core functionality, you may find that just using urllib to fetch pages, parsing the HTML with lxml, and verifying that certain data exists in the appropriate HTML elements might get you 80% of the testing value for 20% of the effort. But, I digress. From kw at codebykevin.com Thu Dec 30 09:59:09 2010 From: kw at codebykevin.com (Kevin Walzer) Date: Thu, 30 Dec 2010 09:59:09 -0500 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> Message-ID: On 12/29/10 6:58 PM, rantingrick wrote: > The answer is simple. We need a 100% Python GUI. A GUI coded in Python > from top to bottom. A GUI that is cross platform to the big three > (Windows, Linux, and Mac). A GUI that not only is easy as Tkinter but > also a GUI that can be manipulated by the average python programmer. A > GUI that not only teaches the fundamentals of using a GUI, but also a > GUI that teaches how a GUI works under the hood Any GUI framework is going to require at least some heavy lifting in C, C++ or Objective-C (depending on the platform). A pure-Python approach to GUI development is technically infeasible. -- Kevin Walzer Code by Kevin http://www.codebykevin.com From martin at v.loewis.de Thu Dec 30 09:59:17 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Thu, 30 Dec 2010 15:59:17 +0100 Subject: Is there anyway to run JavaScript in python? In-Reply-To: References: Message-ID: <4D1C9E45.3060209@v.loewis.de> Am 30.12.2010 14:52, schrieb crow: > Hi, I'm writing a test tool to simulate Web browser. Is there anyway > to run JavaScript in python? Thanks in advance. See PyV8: http://pypi.python.org/pypi/PyV8 Regards, Martin From rantingrick at gmail.com Thu Dec 30 10:24:04 2010 From: rantingrick at gmail.com (rantingrick) Date: Thu, 30 Dec 2010 07:24:04 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> Message-ID: <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> On Dec 30, 8:59?am, Kevin Walzer wrote: > On 12/29/10 6:58 PM, rantingrick wrote: > Any GUI framework is going to require at least some heavy lifting in C, > C++ or Objective-C (depending on the platform). A pure-Python approach > to GUI development is technically infeasible. This is a very good point Kevin however i would much rather spend time learning a language like C --which is hugely useful in many contexts!-- than to waste one second of my time on a domain specific language like TCl which is created only for drawing GUIs using Tk. I think everyone can agree that learning C is of benefit far more benefit to anyone in the programming field. Also one could argue that C and Python are very similar. However Python and Tcl are like night and day. This monkey on our back (TclTk) is dead weight. We need to free ourselves of this GUI prison and bring Python into the 21st century. Tk is old and ugly. Tk is slow. Tk is incomplete and it will never be complete or extensible within our community. There is no OpenGL canvas readily available. Sure you can use Togl (as i have successfully!) however Togl is old and unmaintained. Any GUI library in this day and age must support opengl out of the box! Look, losing Tkinter will be very painful for me as i have tons of code written already. However the more i learn about Tkinter the more i realize how Tkinter is a dead end street. Why let a rotting dinosaur stagnate in the stdlib? Anybody that has foresight knows Tkinter is dying and cannot be revived. It is time to move on. Tkinter served us well for a time but we must let go and evolve -- lest we wither and die ourselves! From hankfay at gmail.com Thu Dec 30 10:28:13 2010 From: hankfay at gmail.com (Hank Fay) Date: Thu, 30 Dec 2010 07:28:13 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: Message-ID: <3dc7137f-465a-4337-a83b-57418d352485@glegroupsg2000goo.googlegroups.com> On Thursday, December 30, 2010 9:59:09 AM UTC-5, kw wrote: > Any GUI framework is going to require at least some heavy lifting in C, > C++ or Objective-C (depending on the platform). A pure-Python approach > to GUI development is technically infeasible. > > -- > Kevin Walzer > Code by Kevin > http://www.codebykevin.com So I thought. Then I came across a framework (Cappucinno.org) and a Visual Designer (280Atlas.com) written entirely in JavaScript (well, Objective-J which gets compiled to JavaScript). Check out 280Slides.com or http://githubissues.heroku.com/#280north/cappuccino for examples of what can be done using JavaScript, and 280Atlas.com for a video of their visual designer. If that designer can be written in JavasScript (it runs on the web, BTW, and only as an after-thought as a desktop app), then it can be done in Python. Having worked for 20 years in a windows-based development tool that painted controls (giving them fake hwnd's) to get enough speed to run on Windows, this was a real game-changer for me. Hank From kw at codebykevin.com Thu Dec 30 10:51:30 2010 From: kw at codebykevin.com (Kevin Walzer) Date: Thu, 30 Dec 2010 10:51:30 -0500 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> Message-ID: <49a1c$4d1caa6e$4275d90a$419@FUSE.NET> On 12/30/10 10:24 AM, rantingrick wrote: > On Dec 30, 8:59 am, Kevin Walzer wrote: >> On 12/29/10 6:58 PM, rantingrick wrote: > >> Any GUI framework is going to require at least some heavy lifting in C, >> C++ or Objective-C (depending on the platform). A pure-Python approach >> to GUI development is technically infeasible. > > > This is a very good point Kevin however i would much rather spend time > learning a language like C --which is hugely useful in many > contexts!-- than to waste one second of my time on a domain specific > language like TCl which is created only for drawing GUIs using Tk. I > think everyone can agree that learning C is of benefit far more > benefit to anyone in the programming field. Also one could argue that > C and Python are very similar. However Python and Tcl are like night > and day. Tcl is not a domain-specific language for creating GUI's. Tcl is a full-featured, general-purpose programming language that is a peer to Python in its capabilities, and surpasses Python in some respects. > > This monkey on our back (TclTk) is dead weight. We need to free > ourselves of this GUI prison and bring Python into the 21st century. > Tk is old and ugly. Tk is slow. Tk is incomplete and it will never be > complete or extensible within our community. In 2010, Tk only lacks two major features common to GUI toolkits: 1. A cross-platform printing API. This is mainly an issue on Windows, which lacks a rich command-line printing framework. The canvas widget can generate PostScript, and the text widget can export its contents to a text file, and then "lpr" can handle the rest on Unix systems (including the Mac). Still, if you want native dialogs and full integration with a platform-specific printing API, you will have to utilize one of several, incompatible, platform-specific extensions. 2. A robust widget for HTML display. The old TkHTML widget (authored by D. Richard Hipp, the author of SQLite) works, but it's very dated (last updated in 2002) and lacks modern features like CSS support. An effort to produce a next-generation HTML widget, TkHTML 3, yielded an alpha-quality widget that is enormously complex, somewhat buggy, and little used. These days, Tkinter has pretty much everything that other GUI toolkits have: tree views, multi-column listboxes, plus all the basics, available through the core widget, the themed ttk widgets, or extension packages. Today, there's no excuse for developing an ugly Tk GUI--if a new Tk app is ugly, that's a reflection on the developer, not the toolkit. > > There is no OpenGL canvas readily available. Sure you can use Togl (as > i have successfully!) however Togl is old and unmaintained. Any GUI > library in this day and age must support opengl out of the box! Togl is still developed. One of its maintainers, Greg Couch, is a developer on the UCSF Chimera project (a Python-Tkinter based molecule viewer). > Look, losing Tkinter will be very painful for me as i have tons of > code written already. However the more i learn about Tkinter the more > i realize how Tkinter is a dead end street. Why let a rotting dinosaur > stagnate in the stdlib? Anybody that has foresight knows Tkinter is > dying and cannot be revived. It is time to move on. Tkinter served us > well for a time but we must let go and evolve -- lest we wither and > die ourselves! > I have nothing against other toolkits, and if one happens to catch on, fine. But your assertions that Tkinter/Tk is dying have no basis in fact. I'm an active developer in Tk with both Tcl and Python, and the reason I have stayed with the toolkit is precisely because it isn't dying. Check out the screenshots at my website--all those GUI's are developed in Tk. Here's one in Tkinter/Python: http://www.codebykevin.com/phynchronicity-running.png --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From stefan_ml at behnel.de Thu Dec 30 10:52:22 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 30 Dec 2010 16:52:22 +0100 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> Message-ID: rantingrick, 30.12.2010 00:58: > So what should we do? > ------------------------ > The answer is simple. We need a 100% Python GUI. A GUI coded in Python > from top to bottom. A GUI that is cross platform to the big three > (Windows, Linux, and Mac). A GUI that not only is easy as Tkinter but > also a GUI that can be manipulated by the average python programmer. A > GUI that not only teaches the fundamentals of using a GUI, but also a > GUI that teaches how a GUI works under the hood I hope you invested as much time into writing this "expose" as you did searching the web before writing it. http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ (the site is currently broken for me, you can use the following instead: http://webcache.googleusercontent.com/search?q=cache:WsGrJKw6ABoJ:www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ Stefan From kw at codebykevin.com Thu Dec 30 10:57:50 2010 From: kw at codebykevin.com (Kevin Walzer) Date: Thu, 30 Dec 2010 10:57:50 -0500 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: <3dc7137f-465a-4337-a83b-57418d352485@glegroupsg2000goo.googlegroups.com> References: <3dc7137f-465a-4337-a83b-57418d352485@glegroupsg2000goo.googlegroups.com> Message-ID: <5d77f$4d1cabea$4275d90a$419@FUSE.NET> On 12/30/10 10:28 AM, Hank Fay wrote: > On Thursday, December 30, 2010 9:59:09 AM UTC-5, kw wrote: > >> Any GUI framework is going to require at least some heavy lifting in C, >> C++ or Objective-C (depending on the platform). A pure-Python approach >> to GUI development is technically infeasible. >> >> -- >> Kevin Walzer >> Code by Kevin >> http://www.codebykevin.com > > So I thought. Then I came across a framework (Cappucinno.org) and a Visual Designer (280Atlas.com) written entirely in JavaScript (well, Objective-J which gets compiled to JavaScript). Check out 280Slides.com or http://githubissues.heroku.com/#280north/cappuccino for examples of what can be done using JavaScript, and 280Atlas.com for a video of their visual designer. If that designer can be written in JavasScript (it runs on the web, BTW, and only as an after-thought as a desktop app), then it can be done in Python. > > Having worked for 20 years in a windows-based development tool that painted controls (giving them fake hwnd's) to get enough speed to run on Windows, this was a real game-changer for me. > > Hank > Yes, this is slick, and it looks nearly native, but, um...it's still running inside a browser. It's not a desktop app. -- Kevin Walzer Code by Kevin http://www.codebykevin.com From aahz at pythoncraft.com Thu Dec 30 11:01:52 2010 From: aahz at pythoncraft.com (Aahz) Date: 30 Dec 2010 08:01:52 -0800 Subject: How to initialize each multithreading Pool worker with an individual value? References: Message-ID: In article , Valery Khamenya wrote: > >However it doesn't look possible to use it to initialize each Pool's >worker with some individual value (I'd wish to be wrong here) > >So, how to initialize each multithreading Pool worker with the >individual values? > >The typical use case might be a connection pool, say, of 3 workers, >where each of 3 workers has its own TCP/IP port. > >from multiprocessing.pool import Pool > >def port_initializer(_port): > global port > port = _port > >def use_connection(some_packet): > global _port > print "sending data over port # %s" % port > >if __name__ == "__main__": > ports=((4001,4002, 4003), ) > p = Pool(3, port_initializer, ports) # oops... :-) You probably can't use initargs here. Your port_initializer needs to be some kind of class instance that works with multiprocessing and emits one port number when its __call__() method gets invoked. (There may be other ways to accomplish the same effect, but that's what springs to mind.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Think of it as evolution in action." --Tony Rand From kw at codebykevin.com Thu Dec 30 11:02:02 2010 From: kw at codebykevin.com (Kevin Walzer) Date: Thu, 30 Dec 2010 11:02:02 -0500 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> Message-ID: <1045b$4d1cad0c$4275d90a$10596@FUSE.NET> On 12/30/10 10:52 AM, Stefan Behnel wrote: > rantingrick, 30.12.2010 00:58: >> So what should we do? >> ------------------------ >> The answer is simple. We need a 100% Python GUI. A GUI coded in Python >> from top to bottom. A GUI that is cross platform to the big three >> (Windows, Linux, and Mac). A GUI that not only is easy as Tkinter but >> also a GUI that can be manipulated by the average python programmer. A >> GUI that not only teaches the fundamentals of using a GUI, but also a >> GUI that teaches how a GUI works under the hood > > I hope you invested as much time into writing this "expose" as you did > searching the web before writing it. > > http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ > > (the site is currently broken for me, you can use the following instead: > > http://webcache.googleusercontent.com/search?q=cache:WsGrJKw6ABoJ:www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ This library isn't much different from other Python GUI toolkits--it's dependent on underlying, rather large, platform-specific implementations--but it provides an even higher level of abstraction. On the Mac, it is dependent on PyObjC; on Windows, pywin32; and on X11, pygtk. In short, it's a wrapper over other wrappers. -- Kevin Walzer Code by Kevin http://www.codebykevin.com From rantingrick at gmail.com Thu Dec 30 11:02:46 2010 From: rantingrick at gmail.com (rantingrick) Date: Thu, 30 Dec 2010 08:02:46 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> Message-ID: On Dec 30, 9:52?am, Stefan Behnel wrote: > I hope you invested as much time into writing this "expose" as you did > searching the web before writing it. And ditto to you. If you would have followed the thread so far, in my second post i said... """However i need to stress that my intention is towards a 100% Python GUI. Not a binding, not a wrapping (except for OS calls!) but a *real* Python GUI. The only thing that i know of at this point is pyGUI although there are probably others."""[198:203] From stefan_ml at behnel.de Thu Dec 30 11:31:04 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 30 Dec 2010 17:31:04 +0100 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> Message-ID: rantingrick, 30.12.2010 17:02: > On Dec 30, 9:52 am, Stefan Behnel wrote: > >> I hope you invested as much time into writing this "expose" as you did >> searching the web before writing it. > > in my second post i said... > > """However i need to stress that my intention is towards a 100% Python > GUI. Not a binding, not a wrapping (except for OS calls!) but a *real* > Python GUI. The only thing that i know of at this point is pyGUI > although there are probably others.""" Sure, fine, just making sure you know the terrain. If that's not enough for you, you should follow Steven's advice to get started implementing something, because this may become a lengthy undertaking. Stefan From python at bdurham.com Thu Dec 30 12:03:54 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 30 Dec 2010 12:03:54 -0500 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: <49a1c$4d1caa6e$4275d90a$419@FUSE.NET> References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com><56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <49a1c$4d1caa6e$4275d90a$419@FUSE.NET> Message-ID: <1293728634.14849.1412816669@webmail.messagingengine.com> > These days, Tkinter has pretty much everything that other GUI toolkits have: tree views, multi-column listboxes, plus all the basics, available through the core widget, the themed ttk widgets, or extension packages. ***Today, there's no excuse for developing an ugly Tk GUI--if a new Tk app is ugly, that's a reflection on the developer, not the toolkit*** +1 (emphasis added) Other tk/ttk benefits: - Very stable - Cross platform (w/native look and feel via Python 2.7/3.1 ttk) - Light weight - Easy to distribute - Extensible Regarding lack of print support: All GUI frameworks suck in this regard. The best approach is to use a technology designed for generating hard copy output - something like PDF, TeX, or RTF library. Malcolm From awilliam at whitemice.org Thu Dec 30 12:17:14 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Thu, 30 Dec 2010 12:17:14 -0500 Subject: How to initialize each multithreading Pool worker with an individual value? In-Reply-To: References: Message-ID: <1293729434.7735.8.camel@linux-yu4c.site> On Thu, 2010-12-30 at 08:01 -0800, Aahz wrote: > In article , > Valery Khamenya wrote: > >However it doesn't look possible to use it to initialize each Pool's > >worker with some individual value (I'd wish to be wrong here) > >So, how to initialize each multithreading Pool worker with the > >individual values? > >The typical use case might be a connection pool, say, of 3 workers, > >where each of 3 workers has its own TCP/IP port. > >from multiprocessing.pool import Pool > >def port_initializer(_port): > > global port > > port = _port > >def use_connection(some_packet): > > global _port > > print "sending data over port # %s" % port > >if __name__ == "__main__": > > ports=((4001,4002, 4003), ) > > p = Pool(3, port_initializer, ports) # oops... :-) > You probably can't use initargs here. Your port_initializer needs to be > some kind of class instance that works with multiprocessing and emits one > port number when its __call__() method gets invoked. (There may be other > ways to accomplish the same effect, but that's what springs to mind.) Maybe this is obvious; but it is possible to create a pool of workers all listening on the same socket. An idle worker will pick-up the connection. Just open the socket in the initial process and then fork your workers - they will inherit the file handle and can accept() on it. From rantingrick at gmail.com Thu Dec 30 12:36:05 2010 From: rantingrick at gmail.com (rantingrick) Date: Thu, 30 Dec 2010 09:36:05 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <49a1c$4d1caa6e$4275d90a$419@FUSE.NET> Message-ID: <6028c783-e960-417d-894d-7afe87f6a2e7@s9g2000vby.googlegroups.com> On Dec 30, 9:51?am, Kevin Walzer wrote: > > Tcl is not a domain-specific language for creating GUI's. Tcl is a > full-featured, general-purpose programming language that is a peer to > Python in its capabilities, Anybody can gloat and gush about their favorite programming language however what separates fantasy from reality is evidence of these "theories". Or rather, Illusions of grandeur! > and surpasses Python in some respects. The only thing that Tcl has over Python is building Tk GUI's. Please post evidence otherwise if you dare! In the meantime i will not be holding my breath. > In 2010, Tk only lacks two major features common to GUI toolkits: > > 1. A cross-platform printing API. This is mainly an issue on Windows, > which lacks a rich command-line printing framework. True windows has no "one-liner" "send-to-print-function" but what it does have is GDI and GDI+ which are far more powerful for windows programmers. Sure you may have to issue a few dc.MoveTo(x,y) and dc.LineTo(x,y) and dc.TextOut(blah) but what is so hard about that? Really, if you want a one liner just wrap up some Python code into a nice interface. This argument is either completely bogus or utterly idiotic. > 2. A robust widget for HTML display. The fact that Tkinter lacks an HTML widget is of no concern to me. Actually if i had a choice of including HTML support or not i would opt for not. Why? Because the simple fact is that Python needs a simplistic GUI and not bloat-ware in the stdlib. HTML widgets, handy dandy anolog clocks, happy faces and dancing bananas widgets belong in 3rd party extension library's and not in the Python stdlib. However we must make sure that any GUI we support not only has these widgets available as extension libraries but that these libraries are currently maintained. If you are going to complain about lacking widgets then Togl would be a good starting point. > These days, Tkinter has pretty much everything that other GUI toolkits > have: tree views, multi-column listboxes, plus all the basics, available > through the core widget, the themed ttk widgets, or extension packages. > Today, there's no excuse for developing an ugly Tk GUI--if a new Tk app > is ugly, that's a reflection on the developer, not the toolkit. Yes Tk is not all bad for TclTk, however it IS all bad for Python. Let the Tcl folks use Tk and we will use a python GUI. Nuff said. > Togl is still developed. One of its maintainers, Greg Couch, is a > developer on the UCSF Chimera project (a Python-Tkinter based molecule > viewer). Have you seen the code in togl.py yourself? I mean really read it from beginning to end? It's a hodgepodge of poorly written code. I know this because i had to update the code myself for one of my projects. Look i have nothing against you Kevin. However i know you and Tkinter (and Tcl) are in bed together. So this is more of a *personal* decision for you instead of a *community* decision. Whether Tkinter exists in the stdlib or not should't matter to you because you can just download it from a 3rd party site. And *if* enough people really love Tkinter as you suggest then removing it will not kill it. However you know as well as i do that Tkinter is a drain on this community and the only thing keeping it alive is the fact that it is packaged in the stdlib. Once Tkinter is removed it will die as it should and something better will take it's place. Something more Pythonic. And most importantly something that is completely and totally under the direct control of the Python community. From rantingrick at gmail.com Thu Dec 30 13:04:19 2010 From: rantingrick at gmail.com (rantingrick) Date: Thu, 30 Dec 2010 10:04:19 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <1045b$4d1cad0c$4275d90a$10596@FUSE.NET> Message-ID: On Dec 30, 10:02?am, Kevin Walzer wrote: > >http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ > This library isn't much different from other Python GUI toolkits--it's > dependent on underlying, rather large, platform-specific > implementations--but it provides an even higher level of abstraction. On > the Mac, it is dependent on PyObjC; ?on Windows, pywin32; and on X11, > pygtk. In short, it's a wrapper over other wrappers. hmm. And what is Tkinter exactly? And more importantly how is it better than pyGUI (design wise)? And even more importanly, how will it be better in the long run? Is this just more FUD Kevin "Gates"? From python at bdurham.com Thu Dec 30 13:05:48 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 30 Dec 2010 13:05:48 -0500 Subject: Tkinter accessability options (was Re: Tkinter: The good, the bad, and the ugly!) In-Reply-To: <4208D3E6AF924DDABBC2411E051E7DB2@teddy> References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <4208D3E6AF924DDABBC2411E051E7DB2@teddy> Message-ID: <1293732348.1669.1412824707@webmail.messagingengine.com> Octavian, > Not all the people were happy because the darkness disappeared partially for some of them and more and more blind people started to use a computer, and discovered that the Tk interfaces are absolutely inaccessible for them. Might this package help? (I have no experience with this project) Tka11y 0.1.1 - accessibility-aware Tkinter http://pypi.python.org/pypi/Tka11y Another idea: Use Tkinters events to speak TTS descriptions of the current control and/or its contents? I would love to hear from anyone using either of techniques ... or other techniques or screen reader products ... to make their Tkinter applications accessible to low vision/blind users. Malcolm From hankfay at gmail.com Thu Dec 30 13:08:23 2010 From: hankfay at gmail.com (Hank Fay) Date: Thu, 30 Dec 2010 10:08:23 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: <5d77f$4d1cabea$4275d90a$419@FUSE.NET> Message-ID: That (the desktop app issue) was the big game-change for me. It looks like a desktop app, it acts like a desktop app, and our enterprise customers would be delighted to a) have no installs to do for fat clients; or b) not have to run a TS or Citrix farm. From orasnita at gmail.com Thu Dec 30 14:13:59 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Thu, 30 Dec 2010 21:13:59 +0200 Subject: Tkinter: The good, the bad, and the ugly! References: Message-ID: From: "Hank Fay" Subject: Re: Tkinter: The good, the bad, and the ugly! > That (the desktop app issue) was the big game-change for me. It looks like a desktop app, it acts like a desktop app, and our enterprise customers would be delighted to a) have no installs to do for fat clients; or b) not have to run a TS or Citrix farm. > It looks like a desktop app, but it doesn't fully act like a desktop app. Not all the computer users are using a mouse and not all of them can see, but the good desktop apps are very accessible for those users who can't do those things. Octavian From orasnita at gmail.com Thu Dec 30 14:18:43 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Thu, 30 Dec 2010 21:18:43 +0200 Subject: Tkinter accessability options (was Re: Tkinter: The good, the bad, and the ugly!) References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <4208D3E6AF924DDABBC2411E051E7DB2@teddy> <1293732348.1669.1412824707@webmail.messagingengine.com> Message-ID: <77CB511375AB4D75A8E67881C866DB90@teddy> From: Subject: Tkinter accessability options (was Re: Tkinter: The good, the bad, and the ugly!) > Octavian, > >> Not all the people were happy because the darkness disappeared partially for some of them and more and more blind people started to use a computer, and discovered that the Tk interfaces are absolutely inaccessible for them. > > Might this package help? (I have no experience with this project) > > Tka11y 0.1.1 - accessibility-aware Tkinter > http://pypi.python.org/pypi/Tka11y > > Another idea: Use Tkinters events to speak TTS descriptions of > the current control and/or its contents? > > I would love to hear from anyone using either of techniques ... or other > techniques or screen reader products ... to make their Tkinter > applications accessible to low vision/blind users. > > Malcolm Thank you very much for those projects! I will test them. Unfortunately they are not a solution because if I want to create an accessible app I can do it using an accessible library, but if the other programmers of the world use a non-accessible by default GUI, than their programs won't be accessible, or they will offer a limited accessibility like Java Access Bridge offers to SWING-based apps. If Tkinter would use that project that should offer the accessibility by default, that would be a real solution. Octavian From devplayer at gmail.com Thu Dec 30 14:26:50 2010 From: devplayer at gmail.com (DevPlayer) Date: Thu, 30 Dec 2010 11:26:50 -0800 (PST) Subject: default argument in method References: <4d0955ae$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9f77af4a-83b0-47b6-9e38-5ac5d2214c66@29g2000yqq.googlegroups.com> There's some_object.some_method.func_defaults and some_function.func_defaults both are a settable attribute. How to set the methods func_defaults? You'd have to have code in _getattribute__(yourmethod) if not __getattr__(yourmethod) def __getattribute__(self, attr): if attr == self.my_method: # something like this, but i'm probably a little off # you might need to use super or something to prevent recursive __getattribute__ calls here self.my_method.func_defaults = self.foo From steve+comp.lang.python at pearwood.info Thu Dec 30 14:51:48 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Dec 2010 19:51:48 GMT Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> Message-ID: <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> On Thu, 30 Dec 2010 07:24:04 -0800, rantingrick wrote: > Also one could argue that C and Python are very similar. One could also argue that black is white, that diamond is softer than chalk, and that bananas are a type of spaceship. Doesn't make it so. How to add two numbers in C: #include int main() { int a, b; scanf("%d%d", &a, &b); printf("%d\n", a + b); return 0; } And in Python: a, b = input().split() # use raw_input in Python 2 print(int(a) + int(b)) And in Tcl: scan [gets stdin] "%d %d" x y puts [expr {$x + $y}] None of the three are exactly clones of each other, but it seems to me that Tcl and Python are quite close in spirit, if not syntax. -- Steven From tjreedy at udel.edu Thu Dec 30 15:03:41 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 30 Dec 2010 15:03:41 -0500 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: <49a1c$4d1caa6e$4275d90a$419@FUSE.NET> References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <49a1c$4d1caa6e$4275d90a$419@FUSE.NET> Message-ID: On 12/30/2010 10:51 AM, Kevin Walzer wrote: > In 2010, Tk only lacks two major features common to GUI toolkits: > > 1. A cross-platform printing API. This is mainly an issue on Windows, > which lacks a rich command-line printing framework. The canvas widget > can generate PostScript, Uh. 1. Postscript is somewhat obsolete; being superseded somewhat by svg. 2. It is not as useful on Windows as it seems to be on *nux and macs -- not easy to either view or print. 3. The files it calls '.eps' are not readable by OOo. They can be read by Photoshop, which can then write a file, supposedly the same but actually not, that *can* be read by OOo. There was a thread on this list about the issue. I do not know whether tk is too sloppy in what it writes (and the file I look for a trivial drawing did look sloppy, with lots of near repetition) or whether OOo is too strict. But clearly, TK *could* write better .eps files (like Photoshop does). And the current output is clearly limited for my purposes. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Thu Dec 30 15:03:55 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Dec 2010 20:03:55 GMT Subject: default argument in method References: <4d0955ae$0$29997$c3e8da3$5496439d@news.astraweb.com> <9f77af4a-83b0-47b6-9e38-5ac5d2214c66@29g2000yqq.googlegroups.com> Message-ID: <4d1ce5ab$0$29968$c3e8da3$5496439d@news.astraweb.com> On Thu, 30 Dec 2010 11:26:50 -0800, DevPlayer wrote: > There's some_object.some_method.func_defaults Not quite -- method objects don't expose the function attributes directly. You need some_object.some_method.im_func to get the function object, which then has a func_defaults attribute. > and > some_function.func_defaults both are a settable attribute. How to set > the methods func_defaults? (1) You shouldn't mess with func_defaults unless you know what you're doing. (2) If you do know what you are doing, you probably won't want to mess with func_defaults. (3) But if you insist, then you would so the same way you would set any other object's attribute. >>> class C(object): ... def method(self, x=[]): ... print x ... >>> C().method() [] >>> function = inst.method.im_func >>> function.func_defaults ([],) >>> function.func_defaults = ("spam",) >>> inst.method() spam (4) Seriously, don't do this. > You'd have to have code in > _getattribute__(yourmethod) if not __getattr__(yourmethod) > > def __getattribute__(self, attr): > if attr == self.my_method: > # something like this, but i'm probably a little off > # you might need to use super or something to prevent > recursive __getattribute__ calls here > self.my_method.func_defaults = self.foo *cries* A much better solution would be: class MyClass: def my_method(self, x=None): if x is None: x = self.foo ... Don't write slow, confusing, complex, convoluted, self-modifying code when you can write fast, simple, straight-forward, obvious code. Unless you're doing it to win a bet. -- Steven From mwilson at the-wire.com Thu Dec 30 15:26:39 2010 From: mwilson at the-wire.com (Mel) Date: Thu, 30 Dec 2010 15:26:39 -0500 Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Thu, 30 Dec 2010 07:24:04 -0800, rantingrick wrote: > >> Also one could argue that C and Python are very similar. > > One could also argue that black is white, that diamond is softer than > chalk, and that bananas are a type of spaceship. Doesn't make it so. > > How to add two numbers in C: > > #include > int main() > { > int a, b; > scanf("%d%d", &a, &b); > printf("%d\n", a + b); > return 0; > } > > And in Python: > > a, b = input().split() # use raw_input in Python 2 > print(int(a) + int(b)) > > > And in Tcl: > > scan [gets stdin] "%d %d" x y > puts [expr {$x + $y}] > > > None of the three are exactly clones of each other, but it seems to me > that Tcl and Python are quite close in spirit, if not syntax. They both have the interpreter spirit. Very different under the hood; Tcl is the LISP of strings. They could have called it STRP. Mel. From harijay at gmail.com Thu Dec 30 16:46:35 2010 From: harijay at gmail.com (harijay) Date: Thu, 30 Dec 2010 13:46:35 -0800 (PST) Subject: OSError: [Errno 26] Text file busy during subprocess.check_call() :seems os dependent Message-ID: <7592441b-301d-4c98-bcb5-56b32947ade1@d8g2000yqf.googlegroups.com> Hi, I am writing some multithreaded code which aims to automate three sequential data processing applications and distribute the processing on my 16GB RAM, 64 bit Ubuntu box running Python 2.6.5 The basic class that orchestrates these jobs use Queue.Queue() to feed the product of the first job into the Queue for the next job. Each Thread receives a dynamically generated shell script from some classes I wrote and then runs the script using subprocess.call(["shell_script_file.sh"]) I tested the code on a mac laptop and also on ubuntu. Curiously on Mac OSX 32 bit Core duo running snow leopard, the code always runs fine. However on my ubuntu box I get sporadic errors detailed below. I tried replacing the subprocess.call() with subprocess.Popen(["shellscriptfile.sh"],stdout=open("unique_process_id.log","w"),stderr=open("unique_error_log.log","w") But I get the same "OSError: [Errno 26] Text file busy" error Everytime I run the same job queue a different part of the job fails. Unfortunately I dont see anybody else reporting this OSError. ANy help in troubleshooting my "newbie" thread code will be greatly appreciated. Thanks hari The orchestrator class is at: https://github.com/harijay/auriga/blob/master/process_multi.py A sample thread subclass is at : https://github.com/harijay/auriga/blob/master/scatomtzrunthread.py Detailed error: Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python2.6/threading.py", line 532, in __bootstrap_inner self.run() File "/home/hari/Dropbox/auriga/scatomtzrunthread.py", line 28, in run stat = subprocess.call([file]) File "/usr/lib/python2.6/subprocess.py", line 480, in call return Popen(*popenargs, **kwargs).wait() File "/usr/lib/python2.6/subprocess.py", line 633, in __init__ errread, errwrite) File "/usr/lib/python2.6/subprocess.py", line 1139, in _execute_child raise child_exception OSError: [Errno 26] Text file busy From tshinnic at io.com Thu Dec 30 17:34:11 2010 From: tshinnic at io.com (Thomas L. Shinnick) Date: Thu, 30 Dec 2010 16:34:11 -0600 Subject: OSError: [Errno 26] Text file busy during subprocess.check_call() :seems os dependent In-Reply-To: <7592441b-301d-4c98-bcb5-56b32947ade1@d8g2000yqf.googlegrou ps.com> References: <7592441b-301d-4c98-bcb5-56b32947ade1@d8g2000yqf.googlegroups.com> Message-ID: <64.94.12606.7E80D1D4@hrndva-omtalb.mail.rr.com> At 03:46 PM 12/30/2010, harijay wrote: >Hi, >I am writing some multithreaded code which aims to automate three >sequential data processing applications and distribute the processing >on my 16GB RAM, 64 bit Ubuntu box running Python 2.6.5 > >The basic class that orchestrates these jobs use Queue.Queue() to feed >the product of the first job into the Queue for the next job. > >Each Thread receives a dynamically generated shell script from some >classes I wrote and then runs the script using > >subprocess.call(["shell_script_file.sh"]) You say dynamically generated. Any chance you are (re)using the same filename each time? Is it possible that two uses of that filename could occur at the same time? That is, is it possible that at the same time while one process is running from the script file, another process is trying to re-write the script file? And so maybe you need to have dynamically generated and unique filenames Most often I see references to binary executable files for the error message, but I've also seen references to script files, e.g. http://www.cyberciti.biz/faq/binbash-bad-interpreter-text-file-busy/ >I tested the code on a mac laptop and also on ubuntu. Curiously on Mac >OSX 32 bit Core duo running snow leopard, the code always runs fine. >However on my ubuntu box I get sporadic errors detailed below. > >I tried replacing the >subprocess.call() with > >subprocess.Popen(["shellscriptfile.sh"],stdout=open("unique_process_id.log","w"),stderr=open("unique_error_log.log","w") > >But I get the same "OSError: [Errno 26] Text file busy" error > >Everytime I run the same job queue a different part of the job fails. > >Unfortunately I dont see anybody else reporting this OSError. ANy help >in troubleshooting my "newbie" thread code will be greatly >appreciated. > >Thanks >hari > >The orchestrator class is at: >https://github.com/harijay/auriga/blob/master/process_multi.py > >A sample thread subclass is at : >https://github.com/harijay/auriga/blob/master/scatomtzrunthread.py > > >Detailed error: > >Exception in thread Thread-1: >Traceback (most recent call last): > File "/usr/lib/python2.6/threading.py", line 532, in >__bootstrap_inner > self.run() > File "/home/hari/Dropbox/auriga/scatomtzrunthread.py", line 28, in >run > stat = subprocess.call([file]) > File "/usr/lib/python2.6/subprocess.py", line 480, in call > return Popen(*popenargs, **kwargs).wait() > File "/usr/lib/python2.6/subprocess.py", line 633, in __init__ > errread, errwrite) > File "/usr/lib/python2.6/subprocess.py", line 1139, in >_execute_child > raise child_exception >OSError: [Errno 26] Text file busy From kw at codebykevin.com Thu Dec 30 17:44:10 2010 From: kw at codebykevin.com (Kevin Walzer) Date: Thu, 30 Dec 2010 17:44:10 -0500 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: <6028c783-e960-417d-894d-7afe87f6a2e7@s9g2000vby.googlegroups.com> References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <49a1c$4d1caa6e$4275d90a$419@FUSE.NET> <6028c783-e960-417d-894d-7afe87f6a2e7@s9g2000vby.googlegroups.com> Message-ID: On 12/30/10 12:36 PM, rantingrick wrote: > On Dec 30, 9:51 am, Kevin Walzer wrote: >> >> Tcl is not a domain-specific language for creating GUI's. Tcl is a >> full-featured, general-purpose programming language that is a peer to >> Python in its capabilities, > > Anybody can gloat and gush about their favorite programming language > however what separates fantasy from reality is evidence of these > "theories". Or rather, Illusions of grandeur! You can build web servers, database tools, FTP clients, test suite/automation tools, chat clients, and drivers of other CLI tools with Tcl, just to name a few. In terms of what can be done with the language, I'm not aware of anything that can be done in Python that can't be done in Tcl. The size of Python's community and its large standard library are an advantage over Tcl. While Tcl is technically capable of many things, it's often easier to find a Python library already coded for specific functions--for instance, while Tcl has XML parsing and can parse RSS, it doesn't have a rich library like feedparser all wrapped up and ready to go. > >> and surpasses Python in some respects. > > The only thing that Tcl has over Python is building Tk GUI's. Please > post evidence otherwise if you dare! In the meantime i will not be > holding my breath. I find that Tcl's "everything is a string" representation offers a more flexible and expressive approach in certain contexts. Tcl's "exec" function makes interacting with external tools simpler than os.popen and subprocess--I can get the output of a command with less code. Of course, this is partly a matter of taste. --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From tjreedy at udel.edu Thu Dec 30 17:46:17 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 30 Dec 2010 17:46:17 -0500 Subject: OSError: [Errno 26] Text file busy during subprocess.check_call() :seems os dependent In-Reply-To: <7592441b-301d-4c98-bcb5-56b32947ade1@d8g2000yqf.googlegroups.com> References: <7592441b-301d-4c98-bcb5-56b32947ade1@d8g2000yqf.googlegroups.com> Message-ID: On 12/30/2010 4:46 PM, harijay wrote: > "OSError: [Errno 26] Text file busy" error Searching 'errno 26', the third Google response suggests that you are trying to write to a file (especially an executable or shared library?) that is already in use. Perhaps just trying to read when locked will trigger? -- Terry Jan Reedy From rantingrick at gmail.com Thu Dec 30 18:12:21 2010 From: rantingrick at gmail.com (rantingrick) Date: Thu, 30 Dec 2010 15:12:21 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> On Dec 30, 1:51?pm, Steven D'Aprano wrote: > How to add two numbers in C: > > [...snip code example...] > > None of the three are exactly clones of each other, but it seems to me > that Tcl and Python are quite close in spirit, if not syntax. Yes i'll agree to that if you also agree that Python and Perl are the same. Then i "maybe" your "suggestion" holds water, maybe. But you forgot to comment on the other big point which is... What language would you rather spend your time learning if you only had C and Tcl to choose from? If you answer Tcl you are either foolish or just trying to win the argument by playing devils advocate, and in that case you're even more foolish! The moral is that C and Python are far more useful to any programmer than Tcl will ever be -- whether you consider them together or apart does not matter. Tcl is too limited whereas Python and especially C are far more useful in various situations. From rantingrick at gmail.com Thu Dec 30 18:17:57 2010 From: rantingrick at gmail.com (rantingrick) Date: Thu, 30 Dec 2010 15:17:57 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <49a1c$4d1caa6e$4275d90a$419@FUSE.NET> <6028c783-e960-417d-894d-7afe87f6a2e7@s9g2000vby.googlegroups.com> Message-ID: On Dec 30, 4:44?pm, Kevin Walzer wrote: > You can build web servers, database tools, FTP clients, test > suite/automation tools, chat clients, and drivers of other CLI tools > with Tcl, just to name a few. Ok, thats swell. But do you have any real examples, links, or some evidence of this? Or are we witnessing more wishful thinking? > In terms of what can be done with the > language, I'm not aware of anything that can be done in Python that > can't be done in Tcl. Again the proof is in the pudding my friend! > The size of Python's community and its large standard library are an > advantage over Tcl. Yes, go on... > While Tcl is technically capable of many things, > it's often easier to find a Python library already coded for specific > functions--for instance, while Tcl has XML parsing and can parse RSS, it > doesn't have a rich library like feedparser all wrapped up and ready to go. Thanks, well i must say that it it getting easier to win this argument. > I find that Tcl's "everything is a string" representation offers a more > flexible and expressive approach in certain contexts. Maybe but that is hardly going to "woo" the masses is it? > Tcl's "exec" > function makes interacting with external tools simpler than os.popen and > subprocess--I can get the output of a command with less code. Newsflash!, NewsFlash!, Python has an exec function. Am i missing something here? :) > Of course, this is partly a matter of taste. Well your posts so far are leaning heavily that way Kevin :) From joncle at googlemail.com Thu Dec 30 18:51:20 2010 From: joncle at googlemail.com (Jon Clements) Date: Thu, 30 Dec 2010 15:51:20 -0800 (PST) Subject: Building sys.path at run-time? References: <87k4irhpoa.fsf@benfinney.id.au> Message-ID: <758cd28c-d6c9-4b37-8467-26d62ae4e90b@30g2000yql.googlegroups.com> On Dec 30, 4:24?am, Roy Smith wrote: > In article <87k4irhpoa.... at benfinney.id.au>, > ?Ben Finney wrote: > > > Roy Smith writes: > > > > I've got a problem that I'm sure many people have solved many times. > > > > Our project has a bunch of python scripts > > > A very common problem. The solution is to switch to Perl. > > > (Merry solstice silliness, everyone :-) > > I have another problem. ?I hit the "Post" button by accident. ?Please > ignore. Sorry all, festive joy and all that. +1 for a laugh that your problem is "[a] bunch of python scripts", and another +1 'cos "I have another problem"... Damn it, if this was 10-15 years ago, with bash.org/qdb.us etc..., I'd have posted that... Thanks Roy for the laugh, Jon. From arndt.roger at addcom.de Thu Dec 30 18:55:21 2010 From: arndt.roger at addcom.de (Arndt Roger Schneider) Date: Fri, 31 Dec 2010 00:55:21 +0100 Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <18c2f4d8-0cce-4cdf-a386-80831dc2f114@m37g2000vbn.googlegroups.com> Message-ID: rantingrick schrieb: > On Dec 29, 6:41 pm, Gerry Reno wrote: > >>wxPython looks good but I don't see anyone developing support for things >>like smartphones. > > > No wx is not the answer to our problems > Rather: ... to *your* problem... > >>Also, what do you think about frameworks such as pyjamas? It lets you >>write in python and compiles everything down to Javascript so it can be >>used across the Web as well as on the desktop. > > > Hmm, this is like two double edged swords smashing one another in > battle. > > Sword One: On one hand web frameworks are going to be really big soon > -- however legacy GUI's are not going away any time soon! There are enough out there in the wild, they will last quite for awhile indeed; but it's time for them to die. > > Sword Two: On the other hand web frameworks provide awesome cross > platform ability that is surly only going to get better as time goes > -- however i utterly hate JavaScript (although much worse web > languages exist!). And sending requests back and forth between Python, > JavaScript, Apparently the authors do know that, too: MessageID:, *sigh* no svg. BTW: Look in comp.lang.javascript: javascript is framework/toolkit resistent. and BrowserX is also a real PITA. Because even though > everyone knows this is coming all the major browsers are trying to > insert their API into the mix. So that Joe Scripter has to write code > that is compatible between many browsers. Until the world agrees on a > unified API --AND IMPLEMENTS IT SERIOUSLY-- we are at the mercy of > drunken sailors at the helm. svg: opera, chrome, safari(including ios), ie9, firefox. Although svg is missing under webkit/android --Apple kept the hardware accelerated part to themeselves. Goolge is currently implementing hardware acceleration for svg in chrome/webkit, likewise Microsoft/ie. Lets wait and see when svg becomes available in android, too. Although smil is quiet another subject. > > I believe pyjamas has a bright future in the web playground, however > we still need to focus our community efforts towards a Python based > GUI. I can see a pythonGUI and pyjamas existing side by side in mutual > harmony for many years. > pyjamas: Perhaps without javascript. -roger From harijay at gmail.com Thu Dec 30 18:59:40 2010 From: harijay at gmail.com (harijay) Date: Thu, 30 Dec 2010 15:59:40 -0800 (PST) Subject: OSError: [Errno 26] Text file busy during subprocess.check_call() :seems os dependent References: <7592441b-301d-4c98-bcb5-56b32947ade1@d8g2000yqf.googlegroups.com> Message-ID: I am writing to a unique script file . Each script file has prefixes like script1.sh script2.sh and they reside in different directories . The scripts will never trample each other since they are all sequential and shell scripts and no directory will have more than one shell script. The only thing I am doing is dir1 and dir2 will each have a script1.sh . But that still makes it mutually exclusive paths. Hari On Dec 30, 5:34?pm, "Thomas L. Shinnick" wrote: > At 03:46 PM 12/30/2010, harijay wrote: > > >Hi, > >I am writing some multithreaded code which aims to automate three > >sequential data processing applications and distribute the processing > >on my 16GB RAM, 64 bit Ubuntu box running Python 2.6.5 > > >The basic class that orchestrates these jobs use Queue.Queue() to feed > >the product of the first job into the Queue for the next job. > > >Each Thread receives a dynamically generated shell script from some > >classes I wrote and then runs the script using > > >subprocess.call(["shell_script_file.sh"]) > > You say dynamically generated. ?Any chance you are (re)using the same > filename each time? ?Is it possible that two uses of that filename > could occur at the same time? ?That is, is it possible that at the > same time while one process is running from the script file, another > process is trying to re-write the script file? ?And so maybe you need > to have dynamically generated and unique filenames > > Most often I see references to binary executable files for the error > message, but I've also seen references to script files, e.g. > ? ? ?http://www.cyberciti.biz/faq/binbash-bad-interpreter-text-file-busy/ > > > > >I tested the code on a mac laptop and also on ubuntu. Curiously on Mac > >OSX 32 bit Core duo running snow leopard, the code always runs fine. > >However on my ubuntu box I get sporadic errors detailed below. > > >I tried replacing the > >subprocess.call() with > > >subprocess.Popen(["shellscriptfile.sh"],stdout=open("unique_process_id.log ","w"),stderr=open("unique_error_log.log","w") > > >But I get the same "OSError: [Errno 26] Text file busy" ?error > > >Everytime I run the same job queue a different part of the job fails. > > >Unfortunately I dont see anybody else reporting this OSError. ANy help > >in troubleshooting my "newbie" thread code will be greatly > >appreciated. > > >Thanks > >hari > > >The orchestrator class is at: > >https://github.com/harijay/auriga/blob/master/process_multi.py > > >A sample thread subclass is at : > >https://github.com/harijay/auriga/blob/master/scatomtzrunthread.py > > >Detailed error: > > >Exception in thread Thread-1: > >Traceback (most recent call last): > > ? File "/usr/lib/python2.6/threading.py", line 532, in > >__bootstrap_inner > > ? ? self.run() > > ? File "/home/hari/Dropbox/auriga/scatomtzrunthread.py", line 28, in > >run > > ? ? stat = subprocess.call([file]) > > ? File "/usr/lib/python2.6/subprocess.py", line 480, in call > > ? ? return Popen(*popenargs, **kwargs).wait() > > ? File "/usr/lib/python2.6/subprocess.py", line 633, in __init__ > > ? ? errread, errwrite) > > ? File "/usr/lib/python2.6/subprocess.py", line 1139, in > >_execute_child > > ? ? raise child_exception > >OSError: [Errno 26] Text file busy From kw at codebykevin.com Thu Dec 30 19:01:04 2010 From: kw at codebykevin.com (Kevin Walzer) Date: Thu, 30 Dec 2010 19:01:04 -0500 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <49a1c$4d1caa6e$4275d90a$419@FUSE.NET> <6028c783-e960-417d-894d-7afe87f6a2e7@s9g2000vby.googlegroups.com> Message-ID: <9eb33$4d1d1d29$4275d90a$30950@FUSE.NET> On 12/30/10 6:17 PM, rantingrick wrote: > Ok, thats swell. But do you have any real examples, links, or some > evidence of this? Or are we witnessing more wishful thinking? http://tcl.apache.org/rivet/ http://www.amsn-project.net/ http://thecoccinella.org/ http://personal5.iddeo.es/andresgarci/tclcurl/english/ http://openacs.org/ http://www.aolserver.com/ http://www.macports.org/ http://www.nist.gov/el/msid/expect.cfm http://www.simulistics.com/ http://personal5.iddeo.es/andresgarci/getleft/english/ http://model.com/ http://sqlitestudio.one.pl/index.rvt http://www.speech.kth.se/wavesurfer/ http://www.ellogon.org/ http://moodss.sourceforge.net/ http://www.projectforum.com/ http://www.eggheads.org/ http://brlcad.org/ http://www.muonics.com/ -- Kevin Walzer Code by Kevin http://www.codebykevin.com From sigzero at gmail.com Thu Dec 30 19:16:14 2010 From: sigzero at gmail.com (Robert) Date: Thu, 30 Dec 2010 19:16:14 -0500 Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <1045b$4d1cad0c$4275d90a$10596@FUSE.NET> Message-ID: On 2010-12-30 13:04:19 -0500, rantingrick said: > On Dec 30, 10:02?am, Kevin Walzer wrote: > >>> http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ > >> This library isn't much different from other Python GUI toolkits--it's >> dependent on underlying, rather large, platform-specific >> implementations--but it provides an even higher level of abstraction. On >> the Mac, it is dependent on PyObjC; ?on Windows, pywin32; and on X11, >> pygtk. In short, it's a wrapper over other wrappers. > > > hmm. And what is Tkinter exactly? And more importantly how is it > better than pyGUI (design wise)? And even more importanly, how will it > be better in the long run? Is this just more FUD Kevin "Gates"? I am sorry, are you always an inconsiderate idiot? That is exactly what you are coming across as. -- Robert From sigzero at gmail.com Thu Dec 30 19:16:56 2010 From: sigzero at gmail.com (Robert) Date: Thu, 30 Dec 2010 19:16:56 -0500 Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> Message-ID: On 2010-12-30 11:02:46 -0500, rantingrick said: > On Dec 30, 9:52?am, Stefan Behnel wrote: > >> I hope you invested as much time into writing this "expose" as you did >> searching the web before writing it. > > And ditto to you. If you would have followed the thread so far, in my > second post i said... > > """However i need to stress that my intention is towards a 100% Python > GUI. Not a binding, not a wrapping (except for OS calls!) but a *real* > Python GUI. The only thing that i know of at this point is pyGUI > although there are probably others."""[198:203] Good luck with that. -- Robert From sigzero at gmail.com Thu Dec 30 19:32:26 2010 From: sigzero at gmail.com (Robert) Date: Thu, 30 Dec 2010 19:32:26 -0500 Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> Message-ID: On 2010-12-30 18:12:21 -0500, rantingrick said: > On Dec 30, 1:51?pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> How to add two numbers in C: >> >> [...snip code example...] >> >> None of the three are exactly clones of each other, but it seems to me >> that Tcl and Python are quite close in spirit, if not syntax. > > Yes i'll agree to that if you also agree that Python and Perl are the > same. Then i "maybe" your "suggestion" holds water, maybe. But you > forgot to comment on the other big point which is... What language > would you rather spend your time learning if you only had C and Tcl to > choose from? If you answer Tcl you are either foolish or just trying > to win the argument by playing devils advocate, and in that case > you're even more foolish! > > The moral is that C and Python are far more useful to any programmer > than Tcl will ever be -- whether you consider them together or apart > does not matter. Tcl is too limited whereas Python and especially C > are far more useful in various situations. I'll bite. Exactly how is Tcl too limited in your view? -- Robert From greno at verizon.net Thu Dec 30 19:43:21 2010 From: greno at verizon.net (Gerry Reno) Date: Thu, 30 Dec 2010 19:43:21 -0500 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> Message-ID: <4D1D2729.3070806@verizon.net> For those that are lurking, this might provide a little background: http://journal.dedasys.com/2010/03/30/where-tcl-and-tk-went-wrong Essentially, there is nothing "wrong" with Tcl and Tkinter. They are part of a long evolutionary chain of how we got to where we are today. They deserve to be respected for the contributions that they have made. The question now is whether Python needs to evolve its own GUI toolset. Regards, Gerry From rantingrick at gmail.com Thu Dec 30 19:46:24 2010 From: rantingrick at gmail.com (rantingrick) Date: Thu, 30 Dec 2010 16:46:24 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> Message-ID: <661858a7-2eaa-4ba5-a014-0805707f0a3f@p8g2000vbs.googlegroups.com> On Dec 30, 6:32?pm, Robert wrote: > Exactly how is Tcl too limited in your view? Well Robert if have explain to you why C and Python make Tcl look limited by comparison then explaining will probably do neither of us any good. But if you think Tcl is so great by all means go spend the next couple of years writing legacy code until you realize one day it was all for nothing. But let's get back on topic here shall we. I have some questions specifically for you Robert... 1. Have you ever used Tkinter? 2. If so, explain what you created with it in detail? 3. What is your opinion of Tkinter as to it's usefulness within the stdlib? 4. How long should we keep Tkinter in the stdlib? 5. Should Python even have a GUI in the stdlib? 6. If Python should have a GUI, then what traits would serve our community best? I will be really surprised if you answer any of these questions. And sorry, but i did not have time to spec out a multiple choice Q&A for you. So take your time Robert. :) From sschwarzer at sschwarzer.net Thu Dec 30 19:51:22 2010 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Fri, 31 Dec 2010 01:51:22 +0100 Subject: using python ftp In-Reply-To: References: Message-ID: <4D1D290A.7080507@sschwarzer.net> Hello Matt, On 2010-12-23 01:03, Matt Funk wrote: > i was wondering whether someone can point me whether the following > already exists. > > I want to connect to a server , download various files (for whose name i > want to be able to use a wildcard), and store those files in a given > location on the hard drive. If the file already exists i do not want to > download it. > [...] You might want to check out ftputil: http://ftputil.sschwarzer.net/ http://ftputil.sschwarzer.net/trac/wiki/Documentation > Otherwise i was going to do it "by hand" using ftplib: > 1) connect to server, > 2) change to directory on server > 3) get listing > 4) match the file pattern i want to the listing > 5) check if file already exists > 6) download file if matched and doesn't exist > > Can anyone offer any advice whether this already done somewhere? ftputil will do most of these tasks easily. For step 4 you probably want to use Python's fnmatch module, see http://docs.python.org/library/fnmatch.html . If you have questions on ftputil, there's also a mailing list: http://ftputil.sschwarzer.net/trac/wiki/MailingList (You need to be subscribed to the list to post, though.) Stefan From aahz at pythoncraft.com Thu Dec 30 19:59:09 2010 From: aahz at pythoncraft.com (Aahz) Date: 30 Dec 2010 16:59:09 -0800 Subject: Catching user switching and getting current active user from root on linux References: <3d190cbf-be7d-4973-b85f-c030bb258742@glegroupsg2000goo.googlegroups.com> Message-ID: In article , mpnordland wrote: > >First, to pacify those who hate google groups: What is a good usenet >client? trn3.6 ;-) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Think of it as evolution in action." --Tony Rand From katie at coderstack.co.uk Thu Dec 30 20:54:32 2010 From: katie at coderstack.co.uk (Katie T) Date: Fri, 31 Dec 2010 01:54:32 +0000 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: <18c2f4d8-0cce-4cdf-a386-80831dc2f114@m37g2000vbn.googlegroups.com> References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <18c2f4d8-0cce-4cdf-a386-80831dc2f114@m37g2000vbn.googlegroups.com> Message-ID: On Thu, Dec 30, 2010 at 12:15 AM, rantingrick wrote: > > However i need to stress that my intention is towards a 100% Python > GUI. Not a binding, not a wrapping (except for OS calls!) but a *real* > Python GUI. The only thing that i know of at this point is pyGUI > although there are probably others. Allowing the average Python > programmer the ability to read OS specific calls written in Python > would not only benefit their GUI knowledge, but also there knowledge > of OS's in general. It's very hard to write a good gui framework, very very few people have managed to do it well. Microsoft, Sun and Google have all had the resources to hire very good developers and designers to dedicate to the task and still haven't managed to do it well. There's not the expertise or the investment in the Python community to build a strong Python GUI solution. From an educational viewpoint I see that there could be value in having a pure Python solution, but in terms of having a GUI solution that people will actually want to use in their apps, I'm dubious that it's achievable. Katie -- CoderStack http://www.coderstack.co.uk/perl-jobs The Software Developer Job Board From data.2 at rediff.com Thu Dec 30 21:26:29 2010 From: data.2 at rediff.com (gaurav) Date: Thu, 30 Dec 2010 18:26:29 -0800 (PST) Subject: Management careers. Message-ID: Big chance in Management careers. Careers recruitment in Management work. http://topcareer.webs.com/executivemanager.htm http://topcareer.webs.com/executivemanager.htm Government Jobs in site lot of opportunities for graduates. http://rojgars1.webs.com/gov.htm http://printmediajobs.webs.com/fl.htm From sigzero at gmail.com Thu Dec 30 21:30:41 2010 From: sigzero at gmail.com (Robert) Date: Thu, 30 Dec 2010 21:30:41 -0500 Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> <4D1D2729.3070806@verizon.net> Message-ID: On 2010-12-30 19:43:21 -0500, Gerry Reno said: > For those that are lurking, this might provide a little background: > > http://journal.dedasys.com/2010/03/30/where-tcl-and-tk-went-wrong > > > > Essentially, there is nothing "wrong" with Tcl and Tkinter. They are > part of a long evolutionary chain of how we got to where we are today. > They deserve to be respected for the contributions that they have made. > > The question now is whether Python needs to evolve its own GUI toolset. > > > Regards, > Gerry You mean outside of wxPython or PySide/PyQt? I don't see the need really. -- Robert From steve+comp.lang.python at pearwood.info Thu Dec 30 21:39:38 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 31 Dec 2010 02:39:38 GMT Subject: OSError: [Errno 26] Text file busy during subprocess.check_call() :seems os dependent References: <7592441b-301d-4c98-bcb5-56b32947ade1@d8g2000yqf.googlegroups.com> Message-ID: <4d1d426a$0$29968$c3e8da3$5496439d@news.astraweb.com> On Thu, 30 Dec 2010 13:46:35 -0800, harijay wrote: [...] > But I get the same "OSError: [Errno 26] Text file busy" error > > Everytime I run the same job queue a different part of the job fails. > > Unfortunately I dont see anybody else reporting this OSError. ANy help > in troubleshooting my "newbie" thread code will be greatly appreciated. Try catching the OSError exception and inspecting the filename attribute. Something like this might help: # Untested def report_error(type, value, traceback): if type is OSError: print value.filename sys.__excepthook__(type, value, traceback) sys.excepthook = report_error -- Steven From sigzero at gmail.com Thu Dec 30 21:41:23 2010 From: sigzero at gmail.com (Robert) Date: Thu, 30 Dec 2010 21:41:23 -0500 Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> <661858a7-2eaa-4ba5-a014-0805707f0a3f@p8g2000vbs.googlegroups.com> Message-ID: On 2010-12-30 19:46:24 -0500, rantingrick said: > On Dec 30, 6:32?pm, Robert wrote: >> Exactly how is Tcl too limited in your view? > > Well Robert if have explain to you why C and Python make Tcl look > limited by comparison then explaining will probably do neither of us > any good. But if you think Tcl is so great by all means go spend the > next couple of years writing legacy code until you realize one day it > was all for nothing. You make a big assumption. That I program in Tcl. I do not. I am simply curious why you are being such a non-gentleman. If I was going to program in Tcl, I would use Gnocl (a GTk binding) and not Tk. Tcl and C will get anyone just as far as Python and C or you suck as a programmer. Just to clarify...I like Python. I am learning it at the moment. > > But let's get back on topic here shall we. I have some questions > specifically for you Robert... > > 1. Have you ever used Tkinter? Yes...nothing big though. > 2. If so, explain what you created with it in detail? Simple utilities is all. Simple meaning ~500-1000 LOC. I have done a few of those just to scratch an itch. > 3. What is your opinion of Tkinter as to it's usefulness within the > stdlib? No, I really don't see the need for it to be in the stdlib but that isn't my call. I am not a huge fan of Tk as it is. > 4. How long should we keep Tkinter in the stdlib? See the last answer. I would yank it. > 5. Should Python even have a GUI in the stdlib? I would say "no" but that is my opinion only and it doesn't matter. Python's domain isn't GUI programming so having it readily available on the sidelines would be fine for me. > 6. If Python should have a GUI, then what traits would serve our > community best? This is a good one. It should be: - cross platform - Pythonic - as "native" as possible Cross platform and native are hard. Just look at all the work with PyQt/PySide and wxPython. It took them years to get where they are. > > I will be really surprised if you answer any of these questions. And > sorry, but i did not have time to spec out a multiple choice Q&A for > you. So take your time Robert. :) Hey, there you go. At least I have real answers. :-) -- Robert From rantingrick at gmail.com Thu Dec 30 21:43:14 2010 From: rantingrick at gmail.com (rantingrick) Date: Thu, 30 Dec 2010 18:43:14 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> Message-ID: <1368b119-2af0-45d3-9a9b-b7d13440e036@p1g2000yqm.googlegroups.com> On Dec 30, 6:43?pm, Gerry Reno wrote: > For those that are lurking, this might provide a little background: > > ? ?http://journal.dedasys.com/2010/03/30/where-tcl-and-tk-went-wrong That was a great and thought provoking article Gerry. Thanks! From data.2 at rediff.com Thu Dec 30 21:47:56 2010 From: data.2 at rediff.com (gaurav) Date: Thu, 30 Dec 2010 18:47:56 -0800 (PST) Subject: Career in IT and management Message-ID: <6a2cf77e-df97-4da7-83b2-e4e0bce8256a@c13g2000prc.googlegroups.com> Latest job listing with IT manager job search and government jobs http://topcareer.webs.com/itmanagement.htm Are you looking for a job in government, this is the right place to start. http://rojgars1.webs.com/gov.htm http://printmediajobs.webs.com/fl.htm From rantingrick at gmail.com Thu Dec 30 22:06:57 2010 From: rantingrick at gmail.com (rantingrick) Date: Thu, 30 Dec 2010 19:06:57 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <18c2f4d8-0cce-4cdf-a386-80831dc2f114@m37g2000vbn.googlegroups.com> Message-ID: On Dec 30, 7:54?pm, Katie T wrote: > It's very hard to write a good gui framework, very very few people > have managed to do it well. This is a very good point Katie. Creating a Python GUI is a huge undertaking and it will take much time to work out the bugs. A truly Pythonic GUI may be (i must admit) a pipe dream at this time. However i know that unless we start thinking about something new right now, it will be two, three, ten years down the road and we will be in the same situation. A lot of folks are probably thinking that since Python3000 is here that Python is up to current technology but i must differ with that opinion. Yes Python3 is much better than the 2.x line however Tkinter and IDLE are so dated and antique that Py3000 is a bit lackluster. Look, when Guido breathed life into Tkinter many years ago he did so with good intentions. I believe at that time (and for a while after) Tkinter was an asset to this community. However, now Tkinter just looks old and dumpy. Actually i would't mind keeping Tkinter and just tweaking it a bit but that is impossible! There will always be a glass ceiling between us and Tcl. We are confined from the Tcl folks and there is nothing we can do about. Tkinter has had a decade to become more relevant in the 21st century however the Tcl folks have failed to deliver. We cannot keep depending on outsiders, we must start the transition to something better. > There's not the expertise or the investment in the Python community to > build a strong Python GUI solution. From an educational viewpoint I > see that there could be value in having a pure Python solution, but in > terms of having a GUI solution that people will actually want to use > in their apps, I'm dubious that it's achievable. Also a good point Katie. But i think i have just a little more optimism than you :). I will conceded that if we cannot build a truly Pythonic GUI then we must at least pick a GUI that is up to date with Python3000. A good choice might be a limited version of wxPython in the stdlib and a 3rd party extension module available for download. We can use Tkinter as the template. All you need in the stdlib are the same widgets that are in Tkinter now. However unlike Tkinter, now a rich 3rd party module will be available. By doing this we will have removed the glass ceiling, and we did not have to re-invent the wheel to do it. What is your opinion (or anyone) on wxPython? From rantingrick at gmail.com Thu Dec 30 22:28:39 2010 From: rantingrick at gmail.com (rantingrick) Date: Thu, 30 Dec 2010 19:28:39 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> <661858a7-2eaa-4ba5-a014-0805707f0a3f@p8g2000vbs.googlegroups.com> Message-ID: On Dec 30, 8:41?pm, Robert wrote: > On 2010-12-30 19:46:24 -0500, rantingrick said: > Just to clarify...I like Python. I am learning it at the moment. Glad to have you aboard Robert! > > 3. What is your opinion of Tkinter as to it's usefulness within the > > stdlib? > > No, I really don't see the need for it to be in the stdlib but that > isn't my call. But it is your call Robert. Anyone who writes Python code --whether they be a beginner with no prior programming experience or a fire breathing Python Guru-- has a right to inject their opinion into th community. We really need input from first time users as they carry the very perspective that we have completely lost! > > 5. Should Python even have a GUI in the stdlib? > > I would say "no" but that is my opinion only and it doesn't matter. > Python's domain isn't GUI programming so having it readily available on > the sidelines would be fine for me. I agree that Python's domain is not "specifically" GUI programming however to understand why Tkinter and IDLE exists you need to understand what Guido's dream was in the beginning. GvR wanted to bring Programming to everyone (just one of his many heroic goals!). He believed (i think) that GUI programming is very important , and that was 20 years ago!!. So he included Tkinter mainly so new Python programmers could hack away at GUI's with little or no effort. He also created a wonderful IDE for beginners called IDLE. His idea was perfect, however his faith in TclTk was flawed and so we find ourselves in the current situation we have today. With the decay of Tkinter the dream has faded. However we can revive this dream and truly bring Python into the 21st century! > > 6. If Python should have a GUI, then what traits would serve our > > community best? > > This is a good one. > > It should be: > > - cross platform > - Pythonic > - as "native" as possible > > Cross platform and native are hard. Just look at all the work with > PyQt/PySide and wxPython. It took them years to get where they are. Hmm, wxPython is starting to look like the answer to all our problems. WxPython already has an IDE so there is no need to rewrite IDLE completely. What do we have to loose by integrating wx into the stdlib, really? From greno at verizon.net Thu Dec 30 22:44:52 2010 From: greno at verizon.net (Gerry Reno) Date: Thu, 30 Dec 2010 22:44:52 -0500 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> <661858a7-2eaa-4ba5-a014-0805707f0a3f@p8g2000vbs.googlegroups.com> Message-ID: <4D1D51B4.6080707@verizon.net> On 12/30/2010 10:28 PM, rantingrick wrote: > > Hmm, wxPython is starting to look like the answer to all our problems. > WxPython already has an IDE so there is no need to rewrite IDLE > completely. What do we have to loose by integrating wx into the > stdlib, really? > > In the spirit of "batteries included", Python needs to have "something" in the stdlib as far as gui. But it cannot be overwhelming. The problem with wx is that it is BIG. And so if we want something like wx to be in the stdlib then it would have to be refactored so that there was a small basic wx that was part of stdlib and then import wx-the-whole-enchilada if you need heavy gui artillery. From sigzero at gmail.com Thu Dec 30 22:51:49 2010 From: sigzero at gmail.com (Robert) Date: Thu, 30 Dec 2010 22:51:49 -0500 Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <18c2f4d8-0cce-4cdf-a386-80831dc2f114@m37g2000vbn.googlegroups.com> Message-ID: On 2010-12-30 22:06:57 -0500, rantingrick said: > > > What is your opinion (or anyone) on wxPython? Ok, I am curious again. Have you even tried wxPython or PySide/PyQt? -- Robert From sigzero at gmail.com Thu Dec 30 22:54:33 2010 From: sigzero at gmail.com (Robert) Date: Thu, 30 Dec 2010 22:54:33 -0500 Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> <661858a7-2eaa-4ba5-a014-0805707f0a3f@p8g2000vbs.googlegroups.com> <4D1D51B4.6080707@verizon.net> Message-ID: On 2010-12-30 22:44:52 -0500, Gerry Reno said: > On 12/30/2010 10:28 PM, rantingrick wrote: >> >> Hmm, wxPython is starting to look like the answer to all our problems. >> WxPython already has an IDE so there is no need to rewrite IDLE >> completely. What do we have to loose by integrating wx into the >> stdlib, really? >> >> > > In the spirit of "batteries included", Python needs to have "something" > in the stdlib as far as gui. But it cannot be overwhelming. > > The problem with wx is that it is BIG. And so if we want something like > wx to be in the stdlib then it would have to be refactored so that there > was a small basic wx that was part of stdlib and then import > wx-the-whole-enchilada if you need heavy gui artillery. It's BIG. The question really is, do we need a GUI toolkit in the stdlib. I would say "no". In wxPython's case it is a no-brainer to install (even as a second package). I am not sure if PySide is "that easy" but it could be. -- Robert From sigzero at gmail.com Thu Dec 30 23:04:33 2010 From: sigzero at gmail.com (Robert) Date: Thu, 30 Dec 2010 23:04:33 -0500 Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> <661858a7-2eaa-4ba5-a014-0805707f0a3f@p8g2000vbs.googlegroups.com> Message-ID: On 2010-12-30 22:28:39 -0500, rantingrick said: > On Dec 30, 8:41?pm, Robert wrote: >> On 2010-12-30 19:46:24 -0500, rantingrick said: >> Just to clarify...I like Python. I am learning it at the moment. > > Glad to have you aboard Robert! Thanks! > >>> 3. What is your opinion of Tkinter as to it's usefulness within the >>> stdlib? >> >> No, I really don't see the need for it to be in the stdlib but that >> isn't my call. > > But it is your call Robert. Anyone who writes Python code --whether > they be a beginner with no prior programming experience or a fire > breathing Python Guru-- has a right to inject their opinion into th > community. We really need input from first time users as they carry > the very perspective that we have completely lost! I speak up. :-) > >>> 5. Should Python even have a GUI in the stdlib? >> >> I would say "no" but that is my opinion only and it doesn't matter. >> Python's domain isn't GUI programming so having it readily available on >> the sidelines would be fine for me. > > I agree that Python's domain is not "specifically" GUI programming > however to understand why Tkinter and IDLE exists you need to > understand what Guido's dream was in the beginning. GvR wanted to > bring Programming to everyone (just one of his many heroic goals!). He > believed (i think) that GUI programming is very important , and that > was 20 years ago!!. So he included Tkinter mainly so new Python > programmers could hack away at GUI's with little or no effort. He also > created a wonderful IDE for beginners called IDLE. His idea was > perfect, however his faith in TclTk was flawed and so we find > ourselves in the current situation we have today. With the decay of > Tkinter the dream has faded. However we can revive this dream and > truly bring Python into the 21st century! I don't think Tkinter was in there for "large" programming. Tkinter is crufty and probably should be moved out. For whipping up quick gui things to scratch an itch it is good. I lurk more on the Tcl side of things. When the mention of "separating" Tcl and Tk development, I fall on the side of separating them. Tcl, like Python should stand on its own. Widget frameworks are extras to me. One way the Tcl community has "stagnated" has been its insistence on Tk. There was a wxTcl project...it died. That would have been good for the Tcl community. Luckily there is a GTk framework (Gnocl) that is really good. But it still doesn't get the props that it deserves. The second way the Tcl community irks me is the "not invented here" attitude. I like the syntax of Tcl and I like the community. They are some good folks. Try asking "I want to build a Nagios clone in Tcl" type question and invariably you get "Why? There is already Nagios?". That stems from the "glue" language roots I think but to me that is the wrong attitude. You want people to take a look at a language (any language), you build stuff with it that people want to use. Ruby would not be as big as it is if Rails hadn't come along. Nuff of that... ;-) > > >>> 6. If Python should have a GUI, then what traits would serve our >>> community best? >> >> This is a good one. >> >> It should be: >> >> - cross platform >> - Pythonic >> - as "native" as possible >> >> Cross platform and native are hard. Just look at all the work with >> PyQt/PySide and wxPython. It took them years to get where they are. > > Hmm, wxPython is starting to look like the answer to all our problems. > WxPython already has an IDE so there is no need to rewrite IDLE > completely. What do we have to loose by integrating wx into the > stdlib, really? wxPython is really good. The downside is that is shows (or did show) its C++ roots. Nokia is making a run with PySide (their version of the PyQt framework) and since it has a company behind it might go pretty far. Qt can be used for a lot of problem domains. Anyway, I wasn't meaning to be rough with you. Just trying to figure out where you were coming from. I am acquianted with Kevin Walzer and he is a good guy. -- Robert From steve+comp.lang.python at pearwood.info Thu Dec 30 23:20:59 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 31 Dec 2010 04:20:59 GMT Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> <661858a7-2eaa-4ba5-a014-0805707f0a3f@p8g2000vbs.googlegroups.com> Message-ID: <4d1d5a2b$0$29968$c3e8da3$5496439d@news.astraweb.com> On Thu, 30 Dec 2010 23:04:33 -0500, Robert wrote: > The > second way the Tcl community irks me is the "not invented here" > attitude. I like the syntax of Tcl and I like the community. They are > some good folks. Try asking "I want to build a Nagios clone in Tcl" type > question and invariably you get "Why? There is already Nagios?". You're the one who wants to re-write Nagios in Tcl, the Tcl community are perfectly happy using the existing Nagios instead of re-inventing the wheel, and you accuse *them* of suffering from NIH syndrome. Oh the irony. -- Steven From rantingrick at gmail.com Thu Dec 30 23:24:05 2010 From: rantingrick at gmail.com (rantingrick) Date: Thu, 30 Dec 2010 20:24:05 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> <661858a7-2eaa-4ba5-a014-0805707f0a3f@p8g2000vbs.googlegroups.com> Message-ID: <6895332e-26dd-4306-ada9-d44533a3c7ab@l8g2000yqh.googlegroups.com> On Dec 30, 9:44?pm, Gerry Reno wrote: > In the spirit of "batteries included", Python needs to have "something" > in the stdlib as far as gui. ?But it cannot be overwhelming. Agreed! > The problem with wx is that it is BIG. ?And so if we want something like > wx to be in the stdlib then it would have to be refactored so that there > was a small basic wx that was part of stdlib and then import > wx-the-whole-enchilada if you need heavy gui artillery. Exactly! All we need to do is replace the existing Tkinter with a small sub-set of wxPython widgets that mirrors exactly what we have now... Toplevel Label Entry Button Radiobutton Checkbutton Canvas Textbox Listbox Menu Scale Scrollbar ...thats all you need in the std library "widget wise". The rest of what makes up wx can exist in the "wxPython Extension Library". Python needs this change! We have already made incompatible changes so now is the time to start seriously brainstorming on how we can integrate the beauty, elegance, and feature rich power of wxPython. From rantingrick at gmail.com Thu Dec 30 23:27:55 2010 From: rantingrick at gmail.com (rantingrick) Date: Thu, 30 Dec 2010 20:27:55 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <18c2f4d8-0cce-4cdf-a386-80831dc2f114@m37g2000vbn.googlegroups.com> Message-ID: <3550c472-80be-46f8-bd78-c1e814c4901f@30g2000yql.googlegroups.com> On Dec 30, 9:51?pm, Robert wrote: > Ok, I am curious again. Have you even tried wxPython or PySide/PyQt? Yes i have used wxPython on a few projects and was very happy with the feature rich nature of it. I found previously (with Tkinter) i would have to build my own compound widgets due to non-existence or just plain poor design. That was not the case in wx as it has more eye candy than i could ever put to good use ;) From askutt at gmail.com Thu Dec 30 23:41:39 2010 From: askutt at gmail.com (Adam Skutt) Date: Thu, 30 Dec 2010 20:41:39 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> <661858a7-2eaa-4ba5-a014-0805707f0a3f@p8g2000vbs.googlegroups.com> <6895332e-26dd-4306-ada9-d44533a3c7ab@l8g2000yqh.googlegroups.com> Message-ID: <7de8ad23-5613-46e4-8330-0eaa3d428935@j29g2000yqm.googlegroups.com> On Dec 30, 11:24?pm, rantingrick wrote: > > > The problem with wx is that it is BIG. ?And so if we want something like > > wx to be in the stdlib then it would have to be refactored so that there > > was a small basic wx that was part of stdlib and then import > > wx-the-whole-enchilada if you need heavy gui artillery. > > Exactly! All we need to do is replace the existing Tkinter with a > small sub-set of wxPython widgets that mirrors exactly what we have > now... > > Toplevel > Label > Entry > Button > Radiobutton > Checkbutton > Canvas > Textbox > Listbox > Menu > Scale > Scrollbar > > ...thats all you need in the std library "widget wise". The rest of > what makes up wx can exist in the ?"wxPython Extension Library". > Python needs this change! We have already made incompatible changes so > now is the time to start seriously brainstorming on how we can > integrate the beauty, elegance, and feature rich power of wxPython. I have never, ever, made a GUI that consistent only of those options excep when following a tutorial, sorry. While I won't claim to stand for anyone else, I'm hardly alone, judging by /every application running on my desktop right now/. Well, maybe notepad. Interesting applications require interesting features. Anything you end up writing is going to be at least as complicated as TkInter for the standard library, if not vastly more so, and have all of the same faults you find in TkInter. This would be because such problems are fundamentally inescapable, a simple fact of reality you have yet to even grasp, AFAICT, much yet acknowledge. Adam From rantingrick at gmail.com Thu Dec 30 23:51:16 2010 From: rantingrick at gmail.com (rantingrick) Date: Thu, 30 Dec 2010 20:51:16 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> <661858a7-2eaa-4ba5-a014-0805707f0a3f@p8g2000vbs.googlegroups.com> Message-ID: On Dec 30, 10:04?pm, Robert wrote: > wxPython is really good. The downside is that is shows (or did show) > its C++ roots. Well i will admit the api is not as simplistic as Tkinter. However i noticed over time that wx had started adopting a slight Tkinter "feel" to the API and that is a good thing. So they are coming around. :) > Anyway, I wasn't meaning to be rough with you. Just trying to figure > out where you were coming from. I am acquianted with Kevin Walzer and > he is a good guy. No harm done Robert my skin is far thicker than your average grape. We just ended up on opposite sides of a passionate argument. I hope you stick around with us because I look forward to hearing more of your opinions and ideas. And i agree that Kevin is a great guy! I've never met him but i can tell from his writing style and mannerisms that he is truly an honest and virtuous soul. And i totally understand why he wants to keep Tkinter alive as he and i both have tons of code that depends on Tkinter. I wish we could keep Tkinter forever as it really is a great starter GUI. I wrote my first GUI code with it and fell in love just like with Python! However i know we will always be lacking our full potential with Tkinter as developers and as a community. Sadly i see no other way but to replace it with something more up-to-date. Sometimes we have to "take one for the team". What is in our best interest may not necessarily be in the community's best interest. If we *do* replace Tkinter, it will be a very painful adjustment because it has been with us for such a long time. However, just as Py3000 was painful at first, and then started slowly gaining speed into a much better language, i also believe this change will move us forward into an even greater language. From rantingrick at gmail.com Fri Dec 31 00:21:19 2010 From: rantingrick at gmail.com (rantingrick) Date: Thu, 30 Dec 2010 21:21:19 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> <661858a7-2eaa-4ba5-a014-0805707f0a3f@p8g2000vbs.googlegroups.com> <6895332e-26dd-4306-ada9-d44533a3c7ab@l8g2000yqh.googlegroups.com> <7de8ad23-5613-46e4-8330-0eaa3d428935@j29g2000yqm.googlegroups.com> Message-ID: <23b1017b-2b14-457d-b4df-0219989940db@f30g2000yqa.googlegroups.com> On Dec 30, 10:41?pm, Adam Skutt wrote: > On Dec 30, 11:24?pm, rantingrick wrote: > > Exactly! All we need to do is replace the existing Tkinter with a > > small sub-set of wxPython widgets that mirrors exactly what we have > > now... > > > Toplevel > > Label > > Entry > > Button > > Radiobutton > > Checkbutton > > Canvas > > Textbox > > Listbox > > Menu > > Scale > > Scrollbar > I have never, ever, made a GUI that consistent only of those options > excep when following a tutorial, sorry. ?While I won't claim to stand > for anyone else, I'm hardly alone, judging by /every application > running on my desktop right now/. ?Well, maybe notepad. Of course a tiny widget set like this is not going to handle extensive GUI coding, thats a no brainer. But currently that is EXACTLY what we have to work with in the stdlib. Sure you have TIX and a few other extensions but they will never compare to the vast features of wxPython. Have you even aquinted yourself with wxPython Adam? What i (and others) are proposing is to replace the existing Tkinter library with a matching wxPython libray. Then allocate the remaining wxPython library (which is ginormous btw!) into a 3rd party module available for download. My argument is that because wxPython is soooo feature rich. We will break the glass ceiling that exist now with Tkinter. > Interesting applications require interesting features. ?Anything you > end up writing is going to be at least as complicated as TkInter for > the standard library, if not vastly more so, Agreed! We need at least the same capability that Tkinter offers in the stdlib. Why would we sacrifice? > and have all of the same > faults you find in TkInter. Thats not true. Yes all projects have faults of some kind. I am not suggesting that wxPython is some sort of "miracle" library. However anyone of average intelligence can do a side by side comparison and agree that wx is far superior to TclTk in many, many ways. If you have a valid argument as to how Tkinter is better feel free to share this information with us. > ?This would be because such problems are > fundamentally inescapable, a simple fact of reality you have yet to > even grasp, AFAICT, much yet acknowledge. Adam, Adam. I feel you are desperately trying to inject negative energy into what is now the very beginnings of a healthy and positive community discussion on the future of Python's GUI library. If you do care about Python's future then you should get involved with this discussion in a positive way. You can disagree with me and still be positive. I wish you would spend more energy bringing forth your own ideas and thoughtful discussion instead of resorting to these wasteful and vengeful tactics. So with that in mind i ask you some direct questions... 1. Do you use Tkinter yourself? 2. Explain some of the applications you have created with Tkinter. 3. How do you feel about Tkinter being in the stdlib? 4. Should Python even include a GUI library? 5. If so, what traits should this library encompass? 6. If you could choose what library do you think would be in the communities best interest? From nuptyu at 163.com Fri Dec 31 01:05:14 2010 From: nuptyu at 163.com (=?GBK?B?0+DBwe64?=) Date: Fri, 31 Dec 2010 14:05:14 +0800 (CST) Subject: A quesstion with matplotlib Message-ID: Dear all, I have a quesstion about change the width of the ylabel.You know the width of the ylabel is relaete to the x axi,how can i change the width of the ylabel not depend on the width of the x-axis? Thank you! George -------------- next part -------------- An HTML attachment was scrubbed... URL: From nobody at nowhere.com Fri Dec 31 01:58:01 2010 From: nobody at nowhere.com (Nobody) Date: Fri, 31 Dec 2010 06:58:01 +0000 Subject: OSError: [Errno 26] Text file busy during subprocess.check_call() :seems os dependent References: <7592441b-301d-4c98-bcb5-56b32947ade1@d8g2000yqf.googlegroups.com> Message-ID: On Thu, 30 Dec 2010 13:46:35 -0800, harijay wrote: > Each Thread receives a dynamically generated shell script from some > classes I wrote and then runs the script using > > subprocess.call(["shell_script_file.sh"]) > But I get the same "OSError: [Errno 26] Text file busy" error "Text file busy" aka ETXTBSY occurs if you try to execute a file which is open for write by any process. Be sure to explicitly close() the script before attempting to execute it. Don't rely upon the destructor closing it, as that may be deferred. Also, if you spawn any child processes, ensure that they don't inherit the descriptor being used to write to the script. Ideally, you should set the close-on-exec flag on the descriptor as soon as the file is opened. Using close_fds=True in subprocess.Popen() will solve the issue for processes spawned that way, but you also need to consider subprocesses which may be spawned "behind the scenes" by library functions. From baptiste.lepilleur at gmail.com Fri Dec 31 02:40:39 2010 From: baptiste.lepilleur at gmail.com (Baptiste Lepilleur) Date: Fri, 31 Dec 2010 08:40:39 +0100 Subject: Change in scope of handled exception variable in Python 3? Message-ID: Hi, I stumbled on a small bug with httplib2 that I reduced to the example below. It seems that with Python 3, when an exception is handled it "unbound" the previously declared local variable. This did not occurs with Python 2.5. It is a Python 3 feature? I did not find anything in the what's news, but it's hard to search... (notes: I'm using Python 3.1.2) --- def main(): msg = 'a message' try: raise ValueError( 'An error' ) except ValueError as msg: pass return msg main() python localmask.py Traceback (most recent call last): File "localmask.py", line 12, in main() File "localmask.py", line 10, in main return msg UnboundLocalError: local variable 'msg' referenced before assignment --- -------------- next part -------------- An HTML attachment was scrubbed... URL: From aman.6677 at gmail.com Fri Dec 31 02:47:17 2010 From: aman.6677 at gmail.com (Aman) Date: Thu, 30 Dec 2010 23:47:17 -0800 (PST) Subject: Python3 Web Framework Message-ID: <5a863ddc-20bf-4c00-83e6-61d4a4551c7d@c13g2000prc.googlegroups.com> Hey all... I just started with Python, and I chose Python3 because it seemed a subtle choice as compared to doing Pthon 2.x now and then porting to Python3.x later... I plan to start with Web Development soon... I wanted to know what all web frameworks are available for Python3... I heard the Django is still not compatible with 3.x... Any idea guys? From angrybaldguy at gmail.com Fri Dec 31 02:48:35 2010 From: angrybaldguy at gmail.com (Owen Jacobson) Date: Fri, 31 Dec 2010 02:48:35 -0500 Subject: Put up or shut up (Was Re: Tkinter: The good, the bad, and the ugly!) References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <49a1c$4d1caa6e$4275d90a$419@FUSE.NET> <6028c783-e960-417d-894d-7afe87f6a2e7@s9g2000vby.googlegroups.com> Message-ID: <2010123102483513840-angrybaldguy@gmailcom> On 2010-12-30 12:36:05 -0500, rantingrick said: > On Dec 30, 9:51?am, Kevin Walzer wrote: >> >> Tcl is not a domain-specific language for creating GUI's. Tcl is a >> full-featured, general-purpose programming language that is a peer to >> Python in its capabilities, > > Anybody can gloat and gush about their favorite programming language > however what separates fantasy from reality is evidence of these > "theories". Or rather, Illusions of grandeur! One: it's "delusions" of grandeur. >> and surpasses Python in some respects. > > The only thing that Tcl has over Python is building Tk GUI's. Please > post evidence otherwise if you dare! In the meantime i will not be > holding my breath. Two: were you raised in a barn? How the hell did you get so up on yourself that you think this is an okay way to respond to a perfectly civil post? Abusing people's opinions and soldiering around demanding everyone justify themselves to you is a great way to get people to ignore whatever point you were trying to make. >From your other posts, I gather that you have a very clear idea of what your ideal Python GUI framework would look like. That puts you in the best possible position to implement it. If you're successful, share it around; if it's good, it will gain traction on its own merit. You're not earning any traction on rhetorical grounds here. -o From angrybaldguy at gmail.com Fri Dec 31 03:14:44 2010 From: angrybaldguy at gmail.com (Owen Jacobson) Date: Fri, 31 Dec 2010 03:14:44 -0500 Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> Message-ID: <2010123103144482179-angrybaldguy@gmailcom> On 2010-12-30 19:43:21 -0500, Gerry Reno said: > For those that are lurking, this might provide a little background: > > http://journal.dedasys.com/2010/03/30/where-tcl-and-tk-went-wrong > > > > Essentially, there is nothing "wrong" with Tcl and Tkinter. They are > part of a long evolutionary chain of how we got to where we are today. > They deserve to be respected for the contributions that they have made. > > The question now is whether Python needs to evolve its own GUI toolset. My two cents, given freely: I'd rather have better integration with each platform's GUI libraries and desktop services than one cross-platform GUI library. There are so many fundamental differences in accepted behaviour between each of the major GUI platforms (Gnome, KDE, Mac OS, and Windows, at minimum; you could include Blackberry, iOS, and Android in here as well, if you wanted something really different) that being able to put the same window with the same widgets on all of them is of limited value. Consider Java's Swing toolkit - a passable cross-platform GUI library, whether you like its API or not. Swing apps almost *never* feel as pleasant to use as a native application, even on modern JVMs where performance isn't the problem and even using the native look & feel. Little things like keyboard shortcut conventions, mouse button conventions, and menu organization guidelines don't quite mesh. Then there are more complex issues, like process management, library packaging, software updates, and user notification, where the conventions on each platform differ more dramatically. Python's native UI capabilities, on the other hand, give programmers the tools they need to write the core of their application using portable code while being able to write a UI (or UIs) that actually takes advantage of the underlying platform's features and that plays nicely with the underlying platform's conventions and interfaces - all without switching languages. I don't see having to maintain two or three UI codebases as being that much worse than riddling a single UI codebase with conditionals or extension points for handling each platform's idiosyncracies. Fortunately for me and my opinions, Python is already shaped like that. PyObjC provides bindings for writing OS X applications; PyGTK and PyQt support Gnome and KDE respectively (as well as any other X11 desktop); PyWin32 provides passable support for Windows UIs, or you can use IronPython and .Net's GUI APIs. It is absolutely zero skin off of my nose if someone decides I'm utterly out of my tree, figures out that cross-platform GUIs are the future, and goes on to write an amazing pure-Python GUI stack that works everywhere with a colour monitor. Cheers, -o From alice at gothcandy.com Fri Dec 31 03:47:11 2010 From: alice at gothcandy.com (=?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=) Date: Fri, 31 Dec 2010 00:47:11 -0800 Subject: Python3 Web Framework References: <5a863ddc-20bf-4c00-83e6-61d4a4551c7d@c13g2000prc.googlegroups.com> Message-ID: On 2010-12-30 23:47:17 -0800, Aman said: > Hey all... I just started with Python, and I chose Python3 because it > seemed a subtle choice as compared to doing Pthon 2.x now and then > porting to Python3.x later... I plan to start with Web Development > soon... I wanted to know what all web frameworks are available for > Python3... I heard the Django is still not compatible with 3.x... Any > idea guys? Python 3 has a number of issues with web development thus far: WSGI[1] (PEP 333) isn't directly compatible with Python 3, for one. However, PEP 3333 is looking good[2] for making web framework code compatible with Python 3 without needing too much modification. I'm not sure what the state of affairs is for PEP 3333 or Python 3 compatible frameworks, however. (CherryPy -might- be compatible, I can not recall.) Basically this means that using Python 3, you'll be "roughing it" for a while. On the other hand, I'm working on PEP 444[3] (WSGI 2) and have a highly performant web server compatible with Python 3 available[4] that is compatible with PEP 444 as published on Python.org[5] (master branch) and with my rewritten draft (draft branch, to be merged when my rewrite is complete and published on Python.org). Another developer and I have been working on the WebOb-style helper exceptions and wrappers, from which a microframework can quickly spawn. The HTTP server has 100% coverage (master) and near-100% coverage (draft) and compatibility with Python 2.6+ and 3.1+. Have a great day, - Alice. [1] http://www.python.org/dev/peps/pep-0333/ [2] http://www.python.org/dev/peps/pep-3333/ [3] http://bit.ly/e7rtI6 [4] http://bit.ly/fLfamO [5] http://bit.ly/gmT17O From steve+comp.lang.python at pearwood.info Fri Dec 31 04:16:01 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 31 Dec 2010 09:16:01 GMT Subject: ANN: stats0.1.2a calculator statistics for Python Message-ID: <4d1d9f51$0$29968$c3e8da3$5496439d@news.astraweb.com> I am pleased to announce the third public release of stats for Python. This is a minor point release, mostly consisting of improved tests and documentation, plus the addition of six new statistics functions: midhinge, quartile_skewness, cumulative_sum, running_sum, stderrskewness, stderrkurtosis. http://pypi.python.org/pypi/stats stats is a pure-Python module providing basic statistics functions similar to those found on scientific calculators. It has over 40 statistics functions, including: Univariate statistics: * arithmetic, harmonic, geometric and quadratic means * median, mode, midrange, trimean * mean of angular quantities * running and weighted averages * quartiles, hinges and quantiles * variance and standard deviation (sample and population) * average deviation and median average deviation (MAD) * skewness and kurtosis * standard error of the mean Multivariate statistics: * Pearson's correlation coefficient * Q-correlation coefficient * covariance (sample and population) * linear regression * sums Sxx, Syy and Sxy and others. This is an unstable alpha release of the software. Feedback and contributions are welcome. -- Steven D'Aprano From __peter__ at web.de Fri Dec 31 04:29:03 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 31 Dec 2010 10:29:03 +0100 Subject: Change in scope of handled exception variable in Python 3? References: Message-ID: Baptiste Lepilleur wrote: > I stumbled on a small bug with httplib2 that I reduced to the example > below. > > It seems that with Python 3, when an exception is handled it "unbound" the > previously declared local variable. This did not occurs with Python 2.5. > > It is a Python 3 feature? I did not find anything in the what's news, but > it's hard to search... (notes: I'm using Python 3.1.2) > > --- > def main(): > msg = 'a message' > try: > raise ValueError( 'An error' ) > except ValueError as msg: > pass > return msg > > main() > > python localmask.py > Traceback (most recent call last): > File "localmask.py", line 12, in > main() > File "localmask.py", line 10, in main > return msg > UnboundLocalError: local variable 'msg' referenced before assignment > --- Yes, that's intentional, see http://docs.python.org/dev/py3k/whatsnew/3.0.html#changes-to-exceptions http://www.python.org/dev/peps/pep-3110/#semantic-changes From python at bdurham.com Fri Dec 31 04:45:06 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 31 Dec 2010 04:45:06 -0500 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com><18c2f4d8-0cce-4cdf-a386-80831dc2f114@m37g2000vbn.googlegroups.com> Message-ID: <1293788706.6120.1412904363@webmail.messagingengine.com> Rick, > However, now Tkinter just looks old and dumpy. Have you taken a look at the ttk module (based on tile) that ships with Python 2.7/3.1? This adds native/theme-aware widgets to Tkinter. And it adds additional widgets such as a treeview (which can also be used as a grid), notebook, progressbar, scales, panedwindow (splitters), etc. The widgets in ttk match each platform's standards and look as professional as the equivalents found in wxPython/pyQt. Take a look at the screenshots on this rather long page to get an idea of what is now possible - "out-of-box" with Python 2.7/3.1. http://www.tkdocs.com/tutorial/onepage.html I've done GUI development in wxPython and pyQt, and until recently *never* considered Tkinter. Once I saw what was possible with the ttk module, I've started moving a lot of new GUI projects from these other platforms back to Tkinter/ttk (enhanced with PIL module). Why Tkinter/ttk vs. wxPython or pyQt - professional looking apps are now possible (really!) - very light weight install and distribution - works with both 2.x/3.x (not possible with wx) - very robust (wx can be finicky at times) Subjective: I also prefer Tk's geometry managers to wx's sizers even though I learned sizers first. You seem to be very enamored with wxPython. What have you found in wxPython that's not available with the latest versions of Tkinter/ttk other than an AUI equivalent and better support for RTL languages? Malcolm From xrgtn at yandex.ru Fri Dec 31 05:09:22 2010 From: xrgtn at yandex.ru (Alexander Gattin) Date: Fri, 31 Dec 2010 12:09:22 +0200 Subject: I am not able to verify the integrity of python.2.5.4.msi In-Reply-To: References: Message-ID: <20101231100922.GA18741@xrgtn-q40> Hello, On Sun, Dec 26, 2010 at 05:44:22AM +0530, Varuna Seneviratna wrote: > > D:\Python>gpg --verify python-2.5.4.msi.asc > gpg: no valid OpenPGP data found. > gpg: the signature could not be verified. > Please remember that the signature file (.sig or .asc) > should be the first file given on the command line > > What am I doing wrong in this process? probably you should try to perform LF=>CRLF conversion on the downloaded python-2.5.4.msi.asc file -- With best regards, xrgtn From tjreedy at udel.edu Fri Dec 31 05:20:47 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 31 Dec 2010 05:20:47 -0500 Subject: Python3 Web Framework In-Reply-To: References: <5a863ddc-20bf-4c00-83e6-61d4a4551c7d@c13g2000prc.googlegroups.com> Message-ID: On 12/31/2010 3:47 AM, Alice Bevan?McGregor wrote: > Python 3 has a number of issues with web development thus far: I believe some will be improved or even solved in 3.2. -- Terry Jan Reedy From flebber.crue at gmail.com Fri Dec 31 06:28:07 2010 From: flebber.crue at gmail.com (flebber) Date: Fri, 31 Dec 2010 03:28:07 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> <661858a7-2eaa-4ba5-a014-0805707f0a3f@p8g2000vbs.googlegroups.com> Message-ID: <8378996c-b463-4e99-9bc3-a19bb6208542@k14g2000pre.googlegroups.com> On Dec 31, 3:04?pm, Robert wrote: > On 2010-12-30 22:28:39 -0500, rantingrick said: > > > ?On Dec 30, 8:41???pm, Robert wrote: > >> On 2010-12-30 19:46:24 -0500, rantingrick said: > >> Just to clarify...I like Python. I am learning it at the moment. > > > Glad to have you aboard Robert! > > Thanks! > > > > >>> 3. What is your opinion of Tkinter as to it's usefulness within the > >>> stdlib? > > >> No, I really don't see the need for it to be in the stdlib but that > >> isn't my call. > > > But it is your call Robert. Anyone who writes Python code --whether > > they be a beginner with no prior programming experience or a fire > > breathing Python Guru-- has a right to inject their opinion into th > > community. We really need input from first time users as they carry > > the very perspective that we have completely lost! > > I speak up. ?:-) > > > > > > >>> 5. Should Python even have a GUI in the stdlib? > > >> I would say "no" but that is my opinion only and it doesn't matter. > >> Python's domain isn't GUI programming so having it readily available on > >> the sidelines would be fine for me. > > > I agree that Python's domain is not "specifically" GUI programming > > however to understand why Tkinter and IDLE exists you need to > > understand what Guido's dream was in the beginning. GvR wanted to > > bring Programming to everyone (just one of his many heroic goals!). He > > believed (i think) that GUI programming is very important , and that > > was 20 years ago!!. So he included Tkinter mainly so new Python > > programmers could hack away at GUI's with little or no effort. He also > > created a wonderful IDE for beginners called IDLE. His idea was > > perfect, however his faith in TclTk was flawed and so we find > > ourselves in the current situation we have today. With the decay of > > Tkinter the dream has faded. However we can revive this dream and > > truly bring Python into the 21st century! > > I don't think Tkinter was in there for "large" programming. Tkinter is > crufty and probably should be moved out. For whipping up quick gui > things to scratch an itch it is good. > > I lurk more on the Tcl side of things. When the mention of "separating" > Tcl and Tk development, I fall on the side of separating them. Tcl, > like Python should stand on its own. Widget frameworks are extras to > me. One way the Tcl community has "stagnated" has been its insistence > on Tk. There was a wxTcl project...it died. That would have been good > for the Tcl community. Luckily there is a GTk framework (Gnocl) that is > really good. But it still doesn't get the props that it deserves. The > second way the Tcl community irks me is the "not invented here" > attitude. I like the syntax of Tcl and I like the community. They are > some good folks. Try asking "I want to build a Nagios clone in Tcl" > type question and invariably you get "Why? There is already Nagios?". > That stems from the "glue" language roots I think but to me that is the > wrong attitude. You want people to take a look at a language (any > language), you build stuff with it that people want to use. Ruby would > not be as big as it is if Rails hadn't come along. > > Nuff of that... ?;-) > > > > > > >>> 6. If Python should have a GUI, then what traits would serve our > >>> community best? > > >> This is a good one. > > >> It should be: > > >> - cross platform > >> - Pythonic > >> - as "native" as possible > > >> Cross platform and native are hard. Just look at all the work with > >> PyQt/PySide and wxPython. It took them years to get where they are. > > > Hmm, wxPython is starting to look like the answer to all our problems. > > WxPython already has an IDE so there is no need to rewrite IDLE > > completely. What do we have to loose by integrating wx into the > > stdlib, really? > > wxPython is really good. The downside is that is shows (or did show) > its C++ roots. > > Nokia is making a run with PySide (their version of the PyQt framework) > and since it has a company behind it might go pretty far. Qt can be > used for a lot of problem domains. > > Anyway, I wasn't meaning to be rough with you. Just trying to figure > out where you were coming from. I am acquianted with Kevin Walzer and > he is a good guy. > > -- > Robert I thank this thread for putting me onto Pyside +1 From flebber.crue at gmail.com Fri Dec 31 09:11:17 2010 From: flebber.crue at gmail.com (flebber) Date: Fri, 31 Dec 2010 06:11:17 -0800 (PST) Subject: User input masks - Access Style References: <385bcaf1-81a5-405a-b7f0-28d7994a2e95@a28g2000prb.googlegroups.com> Message-ID: <33855355-0417-408d-b9bf-3c9a387d9eb0@21g2000prv.googlegroups.com> On Dec 28 2010, 12:21?am, Adam Tauno Williams wrote: > On Sun, 2010-12-26 at 20:37 -0800, flebber wrote: > > Is there anyay to use input masks in python? Similar to the function > > found in access where a users input is limited to a type, length and > > format. > > > > Typically this is handled by a callback on a keypress event. Can I get some clarification on the re module specifically on matching string Line 137 of the Re module def match(pattern, string, flags=0): """Try to apply the pattern at the start of the string, returning a match object, or None if no match was found.""" return _compile(pattern, flags).match(string) From flebber.crue at gmail.com Fri Dec 31 09:15:52 2010 From: flebber.crue at gmail.com (flebber) Date: Fri, 31 Dec 2010 06:15:52 -0800 (PST) Subject: User input masks - Access Style References: <385bcaf1-81a5-405a-b7f0-28d7994a2e95@a28g2000prb.googlegroups.com> Message-ID: <7a7e3beb-380a-4d09-8bf6-71a3ecac17e8@p7g2000prb.googlegroups.com> On Dec 28 2010, 12:21?am, Adam Tauno Williams wrote: > On Sun, 2010-12-26 at 20:37 -0800, flebber wrote: > > Is there anyay to use input masks in python? Similar to the function > > found in access where a users input is limited to a type, length and > > format. > > > > Typically this is handled by a callback on a keypress event. Sorry Regarding 137 of the re module, relating to the code above. # validate the input is in the correct format (usually this would be in # loop that continues until the user enters acceptable data) if re.match(r'''^[0-9]{2}:[0-9]{2}:[0-9]{2}$''', timeInput) == None: print("I'm sorry, your input is improperly formated.") sys.exit(1) EDIT: I just needed to use raw_input rather than input to stop this input error. Please enter time in the format 'MM:SS:HH': 11:12:13 Traceback (most recent call last): File "C:\Documents and Settings\renshaw\workspace\Testing\src \Time.py", line 13, in timeInput = input() File "C:\Eclipse\plugins\org.python.pydev_1.6.3.2010100422\PySrc \pydev_sitecustomize\sitecustomize.py", line 176, in input return eval(raw_input(prompt)) File "", line 1 11:12:13 ^ SyntaxError: invalid syntax From martin at v.loewis.de Fri Dec 31 09:44:10 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Fri, 31 Dec 2010 15:44:10 +0100 Subject: Python3 Web Framework In-Reply-To: <5a863ddc-20bf-4c00-83e6-61d4a4551c7d@c13g2000prc.googlegroups.com> References: <5a863ddc-20bf-4c00-83e6-61d4a4551c7d@c13g2000prc.googlegroups.com> Message-ID: <4D1DEC3A.6060905@v.loewis.de> Am 31.12.2010 08:47, schrieb Aman: > Hey all... I just started with Python, and I chose Python3 because it > seemed a subtle choice as compared to doing Pthon 2.x now and then > porting to Python3.x later... I plan to start with Web Development > soon... I wanted to know what all web frameworks are available for > Python3... I heard the Django is still not compatible with 3.x... Any > idea guys? You could try my port of Django to Py3k: https://bitbucket.org/loewis/django-3k Regards, Martin From askutt at gmail.com Fri Dec 31 09:47:53 2010 From: askutt at gmail.com (Adam Skutt) Date: Fri, 31 Dec 2010 06:47:53 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> <661858a7-2eaa-4ba5-a014-0805707f0a3f@p8g2000vbs.googlegroups.com> <6895332e-26dd-4306-ada9-d44533a3c7ab@l8g2000yqh.googlegroups.com> <7de8ad23-5613-46e4-8330-0eaa3d428935@j29g2000yqm.googlegroups.com> <23b1017b-2b14-457d-b4df-0219989940db@f30g2000yqa.googlegroups.com> Message-ID: On Dec 31, 12:21?am, rantingrick wrote: > Of course a tiny widget set like this is not going to handle extensive > GUI coding, thats a no brainer. No, it's not going to handle any GUI coding except notepad.exe. That's already been written, so we're left with no new application that can be written with this proposed minimal widget set. Why do you think Tix exists? Why do you think there are Python bindings for it in the standard library (to say nothing of a bunch of other additional Tk controls)? > But currently that is EXACTLY what we > have to work with in the stdlib. Sure you have TIX and a few other > extensions but they will never compare to the vast features of > wxPython. Have you even aquinted yourself with wxPython Adam? > It is nothing of the sort even if you erroneously believe it is. Have you looked at Tix? The fact you dismiss it away as some "extension" like it is a leper really betrays your argument. Others (not you) have already described the legitimate deficiencies at length, I will defer to them. > ?What i (and others) are proposing is to replace the existing Tkinter > library with a matching wxPython libray. Then allocate the remaining > wxPython library (which is ginormous btw!) into a 3rd party module > available for download. My argument is that because wxPython is soooo > feature rich. We will break the glass ceiling that exist now with > Tkinter. > And what I pointed out is that wxWidgets (and Qt, and Swing, and Tk+Tix +whatever, and every other GUI toolkit in existence) is so feature rich for a reason: you actually need all of that stuff in order to build rich, functional, useful GUI applications. I think you'll find that it's very hard to cut any functionality, even functionality Python more or less entirely replicates (e.g., wxNet, wxODBC). Why? Because useful widgets rely on such low-level functionality (blame C+ +'s rather anemic standard library). Moreover, even if you find things to cut, coming to a consensus about what belongs outside of the stdlib will be difficult, if not impossible; plus, it's considerable work for very little gain: I still need a full install of wxwidgets to even build your useless minimal set. There's definitely no point in minimizing the python side of things if it doesn't minimize the native code side of things. Note how the divisions with the Tk bindings follow the divisions of the native libraries. > Agreed! We need at least the same capability that Tkinter offers in > the stdlib. Why would we sacrifice? I don't know, but a sacrifice is precisely what you proposed. > Thats not true. Yes all projects have faults of some kind. I am not > suggesting that wxPython is some sort of "miracle" library. However > anyone of average intelligence can do a side by side comparison and > agree that wx is far superior to TclTk in many, many ways. If you have > a valid argument as to how Tkinter is better feel free to share this > information with us. >From this claim I've forced to conclude you are not of average intelligence, because you haven't managed yet to do an actual, factual side-by-side comparison of wxWidgets and Tk. Here is one to start: the native footprint of Tk has fewer dependencies than the native footprint of wxWidgets. > Adam, Adam. I feel you are desperately trying to inject negative > energy into what is now the very beginnings of a healthy and positive > community discussion on the future of Python's GUI library. There's nothing positive about this discussion, since it's being spearheaded by arrogance and ignorance. It's highly improbable, in fact, for this discussion to ever be healthy and positive without a desperate attitude and behavior chance on your part. Seriously, given that widget set you listed, what applications am I supposed to write? I can't write a web browser. I can't write an audio player. I can't write a terminal. I can't write an IM client. I can't write a social media client/application/mashup. I can't write a web browser. I can't write a game community client/launcher. I can't write office productivity applications. So what can I write? The fact your proposal shows you're entirely disconnected with reality isn't my fault in the least, nor does it mean I'm "trying to inject negative energy", nor that I'm "resorting to these wasteful and vengeful tactics." You want to be told your proposal isn't disconnected with reality? Then propose ideas that actually have technical merit and that can be actually accomplished, instead of proposing things that plainly lack merit to anyone who's ever written a complicated GUI application before and/or that are flat-out impossible. Calling a bad proposal a bad proposal is a positive thing, like it or not. If you can't accept that, you should consider a pastime that involves less criticism. > If you do care about Python's future then you should get involved with this > discussion in a positive way. I have, I told you what you want to do isn't possible. The fact you don't want to nor like to hear that doesn't mean it is not positive. A pure Python GUI toolkit isn't really possible. Even if we agreed that "pure" means something akin to AWT, it's still a really awful idea (again, for really obvious reasons). Building something like WPF would be worthwhile, but won't free you from needing a traditional GUI library for quite some time, so you're still right back where we started. Replacing TkInter with some sort of minimized wxwidgets is a dumb idea for some very obvious reasons, reasons that are obvious if you simply look at a widget gallery and then the applications you run on your own computer. Quite honestly, if you're not capable of that, there's little reason to believe you'll ever be able to bring forth a coherent, cogent proposal. Adam From gervaz at gmail.com Fri Dec 31 10:22:26 2010 From: gervaz at gmail.com (gervaz) Date: Fri, 31 Dec 2010 07:22:26 -0800 (PST) Subject: String building using join Message-ID: Hi all, I would like to ask you how I can use the more efficient join operation in a code like this: >>> class Test: ... def __init__(self, v1, v2): ... self.v1 = v1 ... self.v2 = v2 ... >>> def prg(l): ... txt = "" ... for x in l: ... if x.v1 is not None: ... txt += x.v1 + "\n" ... if x.v2 is not None: ... txt += x.v2 + "\n" ... return txt ... >>> t1 = Test("hello", None) >>> t2 = Test(None, "ciao") >>> t3 = Test("salut", "hallo") >>> t = [t1, t2, t3] >>> >>> prg(t) 'hello\nciao\nsalut\nhallo\n' The idea would be create a new list with the values not None and then use the join function... but I don't know if it is really worth it. Any hint? >>> def prg2(l): ... e = [] ... for x in l: ... if x.v1 is not None: ... e.append(x.v1) ... if x.v2 is not None: ... e.append(x.v2) ... return "\n".join(e) ... >>> prg2(t) 'hello\nciao\nsalut\nhallo' Thanks, Mattia From grappale at hotmail.it Fri Dec 31 10:41:48 2010 From: grappale at hotmail.it (Ale Ghelfi) Date: Fri, 31 Dec 2010 16:41:48 +0100 Subject: kinterbasdb error connection References: Message-ID: On 09/12/2010 15:17, Uwe Grauer wrote: > On 12/07/2010 04:35 PM, Ale Ghelfi wrote: >> (i'm under Ubuntu 10.10 amd64 and python 2.6 and kinterbasdb 3.2 ) >> I try to connect my database of firebird 2.5 by kinterbasdb. >> But python return this error : > > > You are not using the current kinterbasdb version. > See: > http://firebirdsql.org/index.php?op=devel&sub=python > > Uwe > kinterbasdb 3.2.3 is the Really current version for Ubuntu 10.10 AMD64. Kinterbasdb 3.3.0 exists only for ubuntu 10.10 i386 I've check in the repository. From emile at fenx.com Fri Dec 31 10:43:27 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 31 Dec 2010 07:43:27 -0800 Subject: String building using join In-Reply-To: References: Message-ID: On 12/31/2010 7:22 AM gervaz said... > Hi all, I would like to ask you how I can use the more efficient join > operation in a code like this: > >>>> class Test: > ... def __init__(self, v1, v2): > ... self.v1 = v1 > ... self.v2 = v2 > ... >>>> def prg(l): > ... txt = "" > ... for x in l: > ... if x.v1 is not None: > ... txt += x.v1 + "\n" > ... if x.v2 is not None: > ... txt += x.v2 + "\n" > ... return txt > ... >>>> t1 = Test("hello", None) >>>> t2 = Test(None, "ciao") >>>> t3 = Test("salut", "hallo") >>>> t = [t1, t2, t3] >>>> >>>> prg(t) > 'hello\nciao\nsalut\nhallo\n' > > The idea would be create a new list with the values not None and then > use the join function... but I don't know if it is really worth it. > Any hint? > >>>> def prg2(l): return "\n".join([x for x in l if x]) Emile > ... e = [] > ... for x in l: > ... if x.v1 is not None: > ... e.append(x.v1) > ... if x.v2 is not None: > ... e.append(x.v2) > ... return "\n".join(e) > ... >>>> prg2(t) > 'hello\nciao\nsalut\nhallo' > > Thanks, Mattia From cheungtifan at gmail.com Fri Dec 31 11:34:39 2010 From: cheungtifan at gmail.com (Alex Zhang) Date: Sat, 01 Jan 2011 00:34:39 +0800 Subject: Compile on SunOS? Message-ID: Hi All, I'm trying to build Python 2.7.1 on Sun Solaris 10 amd64, however end up with: Python build finished, but the necessary bits to build these modules were not found: _bsddb _tkinter bsddb185 gdbm linuxaudiodev ossaudiodev To find the necessary bits, look in setup.py in detect_modules() for the module's name. Failed to build these modules: _bisect _codecs_cn _codecs_hk _codecs_iso2022 _codecs_jp _codecs_kr _codecs_tw _collections _csv _ctypes _ctypes_test _curses _curses_panel _elementtree _functools _hashlib _heapq _hotshot _io _json _locale _lsprof _multibytecodec _multiprocessing _random _socket _sqlite3 _ssl _struct _testcapi array audioop binascii bz2 cmath cPickle crypt cStringIO datetime dbm dl fcntl future_builtins grp imageop itertools math mmap nis operator parser pyexpat resource select spwd strop sunaudiodev syslog termios time unicodedata zlib running build_scripts I am using cc provided in Solaris 10, readline downloaded from GNU and compiled in 32bit. Also, I added this entry: readline readline.c -I/local32/include -L/local32/lib -R/local32/lib -lreadline -ltermcap to Modules/Setup.local in order to get readline running. Currently: dns# /opt/python/bin/python Python 2.7.1 (r271:86832, Dec 31 2010, 07:21:22) [C] on sunos5 Type "help", "copyright", "credits" or "license" for more information. >>> import hashlib Traceback (most recent call last): File "", line 1, in File "/opt/python/lib/python2.7/hashlib.py", line 136, in globals()[__func_name] = __get_hash(__func_name) File "/opt/python/lib/python2.7/hashlib.py", line 71, in __get_builtin_constructor import _md5 ImportError: No module named _md5 I can not use hashlib and many other modules however I can use the rest modules. Thanks for all your kind reply. -- OSQDU::Alex From nagle at animats.com Fri Dec 31 13:28:26 2010 From: nagle at animats.com (John Nagle) Date: Fri, 31 Dec 2010 10:28:26 -0800 Subject: Interrput a thread In-Reply-To: <81c24eb1-41b6-442a-a971-8a44d2cd6c1b@p8g2000vbs.googlegroups.com> References: <81c24eb1-41b6-442a-a971-8a44d2cd6c1b@p8g2000vbs.googlegroups.com> Message-ID: <4d1e20c5$0$43986$742ec2ed@news.sonic.net> On 12/29/2010 3:31 PM, gervaz wrote: > Hi all, I need to stop a threaded (using CTR+C or kill) application if > it runs too much or if I decide to resume the work later. > I come up with the following test implementation but I wanted some > suggestion from you on how I can implement what I need in a better or > more pythonic way. You can't send signals to individual threads under CPython. Even where the OS supports it, CPython does not. See "http://docs.python.org/library/signal.html" Nor can you kill a thread. All you can do is ask it nicely to stop itself. Even worse, sending control-C to a multi-thread program is unreliable in CPython. See "http://blip.tv/file/2232410" for why. It's painful. John Nagle From sigzero at gmail.com Fri Dec 31 14:01:15 2010 From: sigzero at gmail.com (Robert) Date: Fri, 31 Dec 2010 14:01:15 -0500 Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> <661858a7-2eaa-4ba5-a014-0805707f0a3f@p8g2000vbs.googlegroups.com> <4d1d5a2b$0$29968$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-12-30 23:20:59 -0500, Steven D'Aprano said: > On Thu, 30 Dec 2010 23:04:33 -0500, Robert wrote: > >> The >> second way the Tcl community irks me is the "not invented here" >> attitude. I like the syntax of Tcl and I like the community. They are >> some good folks. Try asking "I want to build a Nagios clone in Tcl" type >> question and invariably you get "Why? There is already Nagios?". > > You're the one who wants to re-write Nagios in Tcl, the Tcl community are > perfectly happy using the existing Nagios instead of re-inventing the > wheel, and you accuse *them* of suffering from NIH syndrome. > > Oh the irony. No, that was just an example! My goodness.... -- Robert From solipsis at pitrou.net Fri Dec 31 16:52:30 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Fri, 31 Dec 2010 22:52:30 +0100 Subject: Nagios References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> <661858a7-2eaa-4ba5-a014-0805707f0a3f@p8g2000vbs.googlegroups.com> <4d1d5a2b$0$29968$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20101231225230.38992926@pitrou.net> On 31 Dec 2010 04:20:59 GMT Steven D'Aprano wrote: > On Thu, 30 Dec 2010 23:04:33 -0500, Robert wrote: > > > The > > second way the Tcl community irks me is the "not invented here" > > attitude. I like the syntax of Tcl and I like the community. They are > > some good folks. Try asking "I want to build a Nagios clone in Tcl" type > > question and invariably you get "Why? There is already Nagios?". > > You're the one who wants to re-write Nagios in Tcl, the Tcl community are > perfectly happy using the existing Nagios instead of re-inventing the > wheel, and you accuse *them* of suffering from NIH syndrome. Well, I don't know about Tcl but Nagios was re-written in Python: http://www.shinken-monitoring.org/features/ Regards Antoine. From fabiofz at gmail.com Fri Dec 31 17:03:39 2010 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Fri, 31 Dec 2010 20:03:39 -0200 Subject: Python - NAWIT / Community In-Reply-To: <2895ecca-b978-4899-9ab3-0032422b908f@o9g2000pre.googlegroups.com> References: <2895ecca-b978-4899-9ab3-0032422b908f@o9g2000pre.googlegroups.com> Message-ID: > My question relates to community contribution. My concern arose when > recently installing the pydev.org extensions in Eclipse. Now as far as > my understanding goes the licensing on both is open source GPL. > However Pydev became open source as part of aptana's acquistion, and > for the moment pydev can be installed as part of the Aptana studio 2/3 > releases individually as a plugin, but moving on if you vist the > aptana site there is sweet little about python on their site, their > site is dominated by Radrails. Just a little fix there, Pydev is open source EPL (not GPL). Also, yes, there's little content about Pydev in the Aptana homepage, but it points to the main Pydev homepage (http://pydev.org) which has the proper content related to Python (and it's currently being actively developed and also integrated in Aptana Studio 3, which is where the current efforts are targeted within Aptana now). Sorry if this causes the (wrong) perception that Pydev doesn't get as much attention. > Can't help thinking they open sourced Pydev so they could bench it. So > I started thinking that the only consistent env each python person has > is idle as it ships in the install. Sorry, but I don't follow your thoughts here... there are many consistent environments for python development which are properly supported (Pydev being only one of them as you can see at http://stackoverflow.com/questions/81584/what-ide-to-use-for-python ). > Sometimes we can contribute with money and sometimes with time, if I > was to contribute money to ensure that I and all new coming python > programmers could have a first class development environment to use > what would I donate to? At the moment no particular group seems > applicable. > > Is pydev actively being developed and for who? SPE is a great idea but > is Stan still developing? Pyscripter is good but not 64 capable. Plus > none of these projects seem community centric. I'm the current Pydev maintainer (since 2005)... and while I cannot state that I'll be in that role forever (forever is quite a long time), I do think it's well maintained and there are occasional patches from the community that uses it (although I still get to review all that goes in). > Maybe its just my wish, maybe something already exists, but to my mind > why is there not a central python community ide or plugin setup like > pydev or using pydev(since currently it is very good - to me), which I > know or at least could confidently donate time or money to further > python. > > This could apply to many python area's does python use easy_install or > pypm, well if you want camelot or zope (unless you have business > edition) its easy_install, but you wont find an ide with built in egg > or pypm support? I think the issue is that only recently (if you compare with the others) has easy_install became the de facto standard in python (so, it'd be more an issue of interest adding such a feature to the ide). > Why every Ruby ide has gems manager, and for that > fact look at netbeans, the ide is good but support for python is > mentioned on a far flung community page where some developers are > trying to maintain good python support. PS they seem to be doing a > good job, but a review of the mailing list archives shows little > activity. > One could say that activestate puts in good support but then they do > not provide an ide within the means of the average part time person > retailing its main edition at over $300, Pycharm a good ide at $99 but > then where is my money going. > > I think a community plugin architecture which contained components > like pydev, pyscripter, eclipse and eggs/pypm packages would give a > place I can contribute time as my skills grow and confidently donate > money knowing I am assisting the development of community tools and > packages we all can use. No need to reinvent the wheel most things > already exist, for example apt-get & rpm style package management time > tested and could be easily used to manage python eggs for example. > Anyway I have had my 2 cents, if someone is contributing more than I > know, and this wasn't intended to dimnish anyone's effort, just > wanting to look to growing and fostering a stronger python community. > Well, I can only comment from the Pydev side here, but do you think it'd be worth reinventing all that's already done in it just for having it in Python? When I started contributing to Pydev back in 2004 I didn't go that way because Eclipse itself has a huge community that's already in place and is properly maintained, which takes a lot of effort, so, I'm not sure it'd be worth reproducing all that just to have it 100% Python code -- I say 100% because Pydev does have a number of things that are in Python, such as the debugger and Jython for the scripting engine, although the major portion is really in java. Another important aspect is that it's much better if you can get an experience that can later be replicated to other languages (which Eclipse provides). Cheers, Fabio From alice at gothcandy.com Fri Dec 31 17:24:56 2010 From: alice at gothcandy.com (=?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=) Date: Fri, 31 Dec 2010 14:24:56 -0800 Subject: Python3 Web Framework References: <5a863ddc-20bf-4c00-83e6-61d4a4551c7d@c13g2000prc.googlegroups.com> Message-ID: On 2010-12-31 02:20:47 -0800, Terry Reedy said: > I believe some will be improved or even solved in 3.2. Evidence to back this statement up would be appreciated. ;) - Alice. From alice at gothcandy.com Fri Dec 31 17:25:57 2010 From: alice at gothcandy.com (=?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=) Date: Fri, 31 Dec 2010 14:25:57 -0800 Subject: Interrput a thread References: <81c24eb1-41b6-442a-a971-8a44d2cd6c1b@p8g2000vbs.googlegroups.com> <4d1e20c5$0$43986$742ec2ed@news.sonic.net> Message-ID: On 2010-12-31 10:28:26 -0800, John Nagle said: > Even worse, sending control-C to a multi-thread program > is unreliable in CPython. See "http://blip.tv/file/2232410" > for why. It's painful. AFIK, that has been resolved in Python 3.2 with the introduction of an intelligent thread scheduler as part of the GIL release/acquire process. - Alice. From roy at panix.com Fri Dec 31 17:37:16 2010 From: roy at panix.com (Roy Smith) Date: Fri, 31 Dec 2010 17:37:16 -0500 Subject: tempfile.NamedTemporaryFile use case? Message-ID: What is the use case for tempfile.NamedTemporaryFile? As far as I can tell, the only way it differs from TemporaryFile is that it is guaranteed to have a name in the file system. BUT, it's not guaranteed that you can open the file a second time via that name. So, what's the point? In what situations would NamedTemporaryFile do what you want but TemporaryFile not? I'm writing a unit test where I want to verify operation of my code on a path which can't be opened (i.e. that it raises IOError). NamedTemporaryFile almost gives me what I want. It creates a file, tells me what the path is (so I can os.chmod() it to mode 0), and cleans it up when I'm done (so I don't have to write my own context manager or whatever). But, it's not guaranteed that I can open the path, so the whole test is moot. I can work around that (plain old mktemp() or mkstemp() and have my tearDown() method do the cleanup), but the more I look at this, the more I'm scratching my head why NamedTemporaryFile exists. From drsalists at gmail.com Fri Dec 31 17:52:57 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 31 Dec 2010 14:52:57 -0800 Subject: Keeping track of the N largest values In-Reply-To: References: Message-ID: On Sat, Dec 25, 2010 at 7:42 AM, Roy Smith wrote: > I'm processing a stream of N numbers and want to keep track of the K > largest. ?There's too many numbers in the stream (i.e. N is too large) > to keep in memory at once. ?K is small (100 would be typical). > > >From a theoretical point of view, I should be able to do this in N log K > time. ?What I'm doing now is essentially: > > top = [-1] ? ?# Assume all x are >= 0 > for x in input(): > ? ?if x <= top[0]: > ? ? ? ?continue > ? ?top.append(x) > ? ?if len(top) > K: > ? ? ? ?top.sort() > ? ? ? ?top.pop(0) > > I can see pathological cases (say, all input values the same) where > running time would be N K log K, but on average (N >> K and random > distribution of values), this should be pretty close to N. > > Is there a better way to do this, either from a theoretical running time > point of view, or just a nicer way to code this in Python? > -- > http://mail.python.org/mailman/listinfo/python-list > heapq is probably fine, but I've empirically found a treap faster than a heap under some conditions: http://stromberg.dnsalias.org/~strombrg/treap/ http://stromberg.dnsalias.org/~strombrg/highest/ From alice at gothcandy.com Fri Dec 31 17:58:58 2010 From: alice at gothcandy.com (=?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=) Date: Fri, 31 Dec 2010 14:58:58 -0800 Subject: tempfile.NamedTemporaryFile use case? References: Message-ID: I'm a bad person, but one use case I have is for shuffling templates around such that: * An inherited ('parent') template can be stored in a database. * The 'views' of my application are told to either use the real master template or the db parent template. * The rendering engine loads the parent from disk. Thus I create a NamedTemporaryFile (with some custom prefix and suffix stuff), write the parent template from DB to it, flush, then let the rendering engine do its thing. Works like a hot damn, and lets the users of my CMS manage custom layouts from within the CMS. Templates are cached using the CMS template path as the dict key, and a 2-tuple of modification time and the NamedTemporaryFile as the value. Cleanup of old versions on-disk is simple: just close the file! - Alice. From usernet at ilthio.net Fri Dec 31 19:13:00 2010 From: usernet at ilthio.net (Tim Harig) Date: Sat, 1 Jan 2011 00:13:00 +0000 (UTC) Subject: User input masks - Access Style References: <385bcaf1-81a5-405a-b7f0-28d7994a2e95@a28g2000prb.googlegroups.com> <7a7e3beb-380a-4d09-8bf6-71a3ecac17e8@p7g2000prb.googlegroups.com> Message-ID: On 2010-12-31, flebber wrote: > On Dec 28 2010, 12:21?am, Adam Tauno Williams > wrote: >> On Sun, 2010-12-26 at 20:37 -0800, flebber wrote: >> > Is there anyay to use input masks in python? Similar to the function >> > found in access where a users input is limited to a type, length and >> > format. >> >> >> >> Typically this is handled by a callback on a keypress event. > > Regarding 137 of the re module, relating to the code above. 137? I am not sure what you are referencing? > EDIT: I just needed to use raw_input rather than input to stop this > input error. Sorry, I used input() because that is what you had used in your example and it worked for my system. Normally, I would have used window.getstr() from the curses module, or whatever the platform equivilant is, for getting line buffered input. From bchang2002 at gmail.com Fri Dec 31 19:55:05 2010 From: bchang2002 at gmail.com (dontcare) Date: Fri, 31 Dec 2010 16:55:05 -0800 (PST) Subject: Trying to parse a HUGE(1gb) xml file References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> Message-ID: You should look into vtd-xml, available in c, c++, java and c#. On Dec 20, 11:34?am, spaceman-spiff wrote: > Hi c.l.p folks > > This is a rather long post, but i wanted to include all the details & everything i have tried so far myself, so please bear with me & read the entire boringly long post. > > I am trying to parse a ginormous ( ~ 1gb) xml file. > > 0. I am a python & xml n00b, s& have been relying on the excellent beginner book DIP(Dive_Into_Python3 by MP(Mark Pilgrim).... Mark , if u are readng this, you are AWESOME & so is your witty & humorous writing style) > > 1. Almost all exmaples pf parsing xml in python, i have seen, start off with these 4 lines of code. > > import xml.etree.ElementTree as etree > tree = etree.parse('*path_to_ginormous_xml*') > root = tree.getroot() ?#my huge xml has 1 root at the top level > print root > > 2. In the 2nd line of code above, as Mark explains in DIP, the parse function builds & returns a tree object, in-memory(RAM), which represents the entire document. > I tried this code, which works fine for a small ( ~ 1MB), but when i run this simple 4 line py code in a terminal for my HUGE target file (1GB), nothing happens. > In a separate terminal, i run the top command, & i can see a python process, with memory (the VIRT column) increasing from 100MB , all the way upto 2100MB. > > I am guessing, as this happens (over the course of 20-30 mins), the tree representing is being slowly built in memory, but even after 30-40 mins, nothing happens. > I dont get an error, seg fault or out_of_memory exception. > > My hardware setup : I have a win7 pro box with 8gb of RAM & intel core2 quad cpuq9400. > On this i am running sun virtualbox(3.2.12), with ubuntu 10.10 as guest os, with 23gb disk space & 2gb(2048mb) ram, assigned to the guest ubuntu os. > > 3. I also tried using lxml, but an lxml tree is much more expensive, as it retains more info about a node's context, including references to it's parent. > [http://www.ibm.com/developerworks/xml/library/x-hiperfparse/] > > When i ran the same 4line code above, but with lxml's elementree ( using the import below in line1of the code above) > import lxml.etree as lxml_etree > > i can see the memory consumption of the python process(which is running the code) shoot upto ~ 2700mb & then, python(or the os ?) kills the process as it nears the total system memory(2gb) > > I ran the code from 1 terminal window (screenshot :http://imgur.com/ozLkB.png) > & ran top from another terminal (http://imgur.com/HAoHA.png) > > 4. I then investigated some streaming libraries, but am confused - there is SAX[http://en.wikipedia.org/wiki/Simple_API_for_XML] , the iterparse interface[http://effbot.org/zone/element-iterparse.htm] > > Which one is the best for my situation ? > > Any & all code_snippets/wisdom/thoughts/ideas/suggestions/feedback/comments/ of the c.l.p community would be greatly appreciated. > Plz feel free to email me directly too. > > thanks a ton > > cheers > ashish > > email : > ashish.makani > domain:gmail.com > > p.s. > Other useful links on xml parsing in python > 0.http://diveintopython3.org/xml.html > 1.http://stackoverflow.com/questions/1513592/python-is-there-an-xml-par... > 2.http://codespeak.net/lxml/tutorial.html > 3.https://groups.google.com/forum/?hl=en&lnk=gst&q=parsing+a+huge+xml#!... > 4.http://www.ibm.com/developerworks/xml/library/x-hiperfparse/ > 5.http://effbot.org/zone/element-index.htmhttp://effbot.org/zone/element-iterparse.htm > 6. SAX :http://en.wikipedia.org/wiki/Simple_API_for_XML From flebber.crue at gmail.com Fri Dec 31 20:08:08 2010 From: flebber.crue at gmail.com (flebber) Date: Fri, 31 Dec 2010 17:08:08 -0800 (PST) Subject: Python - NAWIT / Community References: <2895ecca-b978-4899-9ab3-0032422b908f@o9g2000pre.googlegroups.com> Message-ID: <75bb7ce4-3542-420e-8a66-70e15bd21030@f20g2000prn.googlegroups.com> On Jan 1, 9:03?am, Fabio Zadrozny wrote: > > My question relates to community contribution. My concern arose when > > recently installing the pydev.org extensions in Eclipse. Now as far as > > my understanding goes the licensing on both is open source GPL. > > However Pydev became open source as part of aptana's acquistion, and > > for the moment pydev can be installed as part of the Aptana studio 2/3 > > releases individually as a plugin, but moving on if you vist the > > aptana site there is sweet little about python on their site, their > > site is dominated by Radrails. > > Just a little fix there, Pydev is open source EPL (not GPL). > > Also, yes, there's little content about Pydev in the Aptana homepage, > but it points to the main Pydev homepage (http://pydev.org) which has > the proper content related to Python (and it's currently being > actively developed and also integrated in Aptana Studio 3, which is > where the current efforts are targeted within Aptana now). Sorry if > this causes the (wrong) perception that Pydev doesn't get as much > attention. > > > Can't help thinking they open sourced Pydev so they could bench it. So > > I started thinking that the only consistent env each python person has > > is idle as it ships in the install. > > Sorry, but I don't follow your thoughts here... there are many > consistent environments for python development which are properly > supported (Pydev being only one of them as you can see athttp://stackoverflow.com/questions/81584/what-ide-to-use-for-python). > > > Sometimes we can contribute with money and sometimes with time, if I > > was to contribute money to ensure that I and all new coming python > > programmers could have a first class development environment to use > > what would I donate to? At the moment no particular group seems > > applicable. > > > Is pydev actively being developed and for who? SPE is a great idea but > > is Stan still developing? Pyscripter is good but not 64 capable. Plus > > none of these projects seem community centric. > > I'm the current Pydev maintainer (since 2005)... and while I cannot > state that I'll be in that role forever (forever is quite a long > time), I do think it's well maintained and there are occasional > patches from the community that uses it (although I still get to > review all that goes in). > > > Maybe its just my wish, maybe something already exists, but to my mind > > why is there not a central python community ide or plugin setup like > > pydev or using pydev(since currently it is very good - to me), which I > > know or at least could confidently donate time or money to further > > python. > > > This could apply to many python area's does python use easy_install or > > pypm, well if you want camelot or zope (unless you have business > > edition) its easy_install, but you wont find an ide with built in egg > > or pypm support? > > I think the issue is that only recently (if you compare with the > others) has easy_install became the de facto standard in python (so, > it'd be more an issue of interest adding such a feature to the ide). > > > > > Why every Ruby ide has gems manager, and for that > > fact look at netbeans, the ide is good but support for python is > > mentioned on a far flung community page where some developers are > > trying to maintain good python support. PS they seem to be doing a > > good job, but a review of the mailing list archives shows little > > activity. > > One could say that activestate puts in good support but then they do > > not provide an ide within the means of the average part time person > > retailing its main edition at over $300, Pycharm a good ide at $99 but > > then where is my money going. > > > I think a community plugin architecture which contained components > > like pydev, pyscripter, eclipse and eggs/pypm packages would give a > > place I can contribute time as my skills grow and confidently donate > > money knowing I am assisting the development of community tools and > > packages we all can use. No need to reinvent the wheel most things > > already exist, for example apt-get & rpm style package management time > > tested and could be easily used to manage python eggs for example. > > Anyway I have had my 2 cents, if someone is contributing more than I > > know, and this wasn't intended to dimnish anyone's effort, just > > wanting to look to growing and fostering a stronger python community. > > Well, I can only comment from the Pydev side here, but do you think > it'd be worth reinventing all that's already done in it just for > having it in Python? When I started contributing to Pydev back in 2004 > I didn't go that way because Eclipse itself has a huge community > that's already in place and is properly maintained, which takes a lot > of effort, so, I'm not sure it'd be worth reproducing all that just to > have it 100% Python code -- I say 100% because Pydev does have a > number of things that are in Python, such as the debugger and Jython > for the scripting engine, although the major portion is really in > java. > > Another important aspect is that it's much better if you can get an > experience that can later be replicated to other languages (which > Eclipse provides). > > Cheers, > > Fabio Fabio right off the bat let me thank you for your work on Pydev, I use eclipse and the Pydev plugin and enjoy it very much. My question and statement come to think of it should have been, is the python community framework the most efficient it could be? If not what framework would reduce duplication, value contributor effort and allow rapid development and utilisation of python projects Zope/Django/ Pyjamas/SQLAlchemy...etc. Would a new framework being clearer allow more investment from both commercial and community sources(time resources & financial resources) and ensure python has the ability to stay current. >Well, I can only comment from the Pydev side here, but do you think >it'd be worth reinventing all that's already done in it just for >having it in Python? No, not at all worth the effort. My main post could have clearer but I became somewhat passionate & less clear. Main points were supposed to reflect 1. Both Netbeans, Aptana and Activestate represent commercial companies. - netbeans and Aptana by perception don't seem to have python as their main focus - Activestate has python at pride of place but both ide and package mgt are at cost and not cheap. Even a free package such as camelot, sqlalchemy require you to pay eg pypm camelot - will give you a message "you need business edition python to access this program" 2. I highly valuable contributors like yourself and had concern that via unecessary duplication could reduce the potential impact and gains that could be had. For example Eclipse and Netbeans are both java ide's that feature mulit syntax programming environments. So is it potentially necessary for both sets of developers to work separately, is it the most productive efficient framework. In my head, and thats the only place this may exist, if for example the pydev plugins where the central community python plugin for syntax features, debugging etc then the commuity could re-use these. This would mean to me that if I want to build an ide with its main focus as Zope/Grok for example(could be anything Pyjamas etc) I wouldn't have to re-write code I could build a base ide and plugin the pydev syntax features to give me full python support and then focus on the part of the implementation I want to develop. Reducing my duplication and increasing productivity And over and over this could be done an ide for python desktop apps, plugin, plugin develop new code for Pyside etc. Whether these apps are 100% python is not the main focus. From drsalists at gmail.com Fri Dec 31 20:15:44 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 31 Dec 2010 17:15:44 -0800 Subject: Is there anyway to run JavaScript in python? In-Reply-To: References: Message-ID: On Thu, Dec 30, 2010 at 5:52 AM, crow wrote: > Hi, I'm writing a test tool to simulate Web browser. Is there anyway > to run JavaScript in python? Thanks in advance. > -- > http://mail.python.org/mailman/listinfo/python-list > You might also consider Pyjamas, which translates Python (somewhere between 2.5 and 2.6) to Javascript. Then your python code ends up running on a javascript interpreter with interlanguage calling available. From mrjean1 at gmail.com Fri Dec 31 20:18:43 2010 From: mrjean1 at gmail.com (MrJean1) Date: Fri, 31 Dec 2010 17:18:43 -0800 (PST) Subject: Compile on SunOS? References: Message-ID: <04608d49-9922-464c-aad7-3fc80b892edb@j25g2000yqa.googlegroups.com> These command lines used to build 32-bit Python 2.4 and 2.5 on Solaris 10 Opteron using SUN's compilers: setenv LD_LIBRARY_PATH .... env CCSHARED="-KPIC" LDSHARED="cc -xtarget=native -G" LDFLAGS="- xtarget=native" CC="cc" \ CPP="cc-xtarget=native -E" BASECFLAGS="-xtarget=native" OPT="-xO5" CFLAGS="-xtarget=native" \ CXX="CC -xtarget=native" ./configure --enable-shared --without-gcc --disable-ipv6 --prefix=.... make Replace the ....'s accordingly. Use BASECFLAGS="-xtarget=native - xlibmieee" for IEEE floating point. Disclaimer, I have not tried building Python 2.6 nor 2.7. /Jean On Dec 31, 8:34?am, Alex Zhang wrote: > Hi All, > I'm trying to build Python 2.7.1 on Sun Solaris 10 amd64, however end up > with: > > Python build finished, but the necessary bits to build these modules > were not found: > _bsddb ? ? ? ? ? ? _tkinter ? ? ? ? ? bsddb185 > gdbm ? ? ? ? ? ? ? linuxaudiodev ? ? ?ossaudiodev > To find the necessary bits, look in setup.py in detect_modules() for the > module's name. > > Failed to build these modules: > _bisect ? ? ? ? ? ?_codecs_cn ? ? ? ? _codecs_hk > _codecs_iso2022 ? ?_codecs_jp ? ? ? ? _codecs_kr > _codecs_tw ? ? ? ? _collections ? ? ? _csv > _ctypes ? ? ? ? ? ?_ctypes_test ? ? ? _curses > _curses_panel ? ? ?_elementtree ? ? ? _functools > _hashlib ? ? ? ? ? _heapq ? ? ? ? ? ? _hotshot > _io ? ? ? ? ? ? ? ?_json ? ? ? ? ? ? ?_locale > _lsprof ? ? ? ? ? ?_multibytecodec ? ?_multiprocessing > _random ? ? ? ? ? ?_socket ? ? ? ? ? ?_sqlite3 > _ssl ? ? ? ? ? ? ? _struct ? ? ? ? ? ?_testcapi > array ? ? ? ? ? ? ?audioop ? ? ? ? ? ?binascii > bz2 ? ? ? ? ? ? ? ?cmath ? ? ? ? ? ? ?cPickle > crypt ? ? ? ? ? ? ?cStringIO ? ? ? ? ?datetime > dbm ? ? ? ? ? ? ? ?dl ? ? ? ? ? ? ? ? fcntl > future_builtins ? ?grp ? ? ? ? ? ? ? ?imageop > itertools ? ? ? ? ?math ? ? ? ? ? ? ? mmap > nis ? ? ? ? ? ? ? ?operator ? ? ? ? ? parser > pyexpat ? ? ? ? ? ?resource ? ? ? ? ? select > spwd ? ? ? ? ? ? ? strop ? ? ? ? ? ? ?sunaudiodev > syslog ? ? ? ? ? ? termios ? ? ? ? ? ?time > unicodedata ? ? ? ?zlib > > running build_scripts > > I am using cc provided in Solaris 10, readline downloaded from GNU and > compiled in 32bit. Also, I added this entry: > > readline readline.c -I/local32/include -L/local32/lib -R/local32/lib > -lreadline -ltermcap > > to Modules/Setup.local in order to get readline running. > Currently: > > dns# /opt/python/bin/python > Python 2.7.1 (r271:86832, Dec 31 2010, 07:21:22) [C] on sunos5 > Type "help", "copyright", "credits" or "license" for more information. > ?>>> import hashlib > Traceback (most recent call last): > ? ?File "", line 1, in > ? ?File "/opt/python/lib/python2.7/hashlib.py", line 136, in > ? ? ?globals()[__func_name] = __get_hash(__func_name) > ? ?File "/opt/python/lib/python2.7/hashlib.py", line 71, in > __get_builtin_constructor > ? ? ?import _md5 > ImportError: No module named _md5 > > I can not use hashlib and many other modules however I can use the rest > modules. > Thanks for all your kind reply. > -- > OSQDU::Alex From sigzero at gmail.com Fri Dec 31 21:53:49 2010 From: sigzero at gmail.com (Robert) Date: Fri, 31 Dec 2010 21:53:49 -0500 Subject: Python3 Web Framework References: <5a863ddc-20bf-4c00-83e6-61d4a4551c7d@c13g2000prc.googlegroups.com> Message-ID: On 2010-12-31 17:24:56 -0500, Alice Bevan?McGregor said: > On 2010-12-31 02:20:47 -0800, Terry Reedy said: > >> I believe some will be improved or even solved in 3.2. > > Evidence to back this statement up would be appreciated. ;) > > - Alice. - wsgiref now implements and validates PEP 3333, rather than an experimental extension of PEP 333. (Note: earlier versions of Python 3.x may have incorrectly validated some non-compliant applications as WSGI compliant; if your app validates with Python <3.2b1+, but not on this version, it is likely the case that your app was not compliant.) That is from the changes file...so they are working to fix it all. HTH -- Robert From sigzero at gmail.com Fri Dec 31 21:56:02 2010 From: sigzero at gmail.com (Robert) Date: Fri, 31 Dec 2010 21:56:02 -0500 Subject: Nagios References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> <661858a7-2eaa-4ba5-a014-0805707f0a3f@p8g2000vbs.googlegroups.com> <4d1d5a2b$0$29968$c3e8da3$5496439d@news.astraweb.com> <20101231225230.38992926@pitrou.net> Message-ID: On 2010-12-31 16:52:30 -0500, Antoine Pitrou said: > On 31 Dec 2010 04:20:59 GMT > Steven D'Aprano wrote: >> On Thu, 30 Dec 2010 23:04:33 -0500, Robert wrote: >> >>> The >>> second way the Tcl community irks me is the "not invented here" >>> attitude. I like the syntax of Tcl and I like the community. They are >>> some good folks. Try asking "I want to build a Nagios clone in Tcl" type >>> question and invariably you get "Why? There is already Nagios?". >> >> You're the one who wants to re-write Nagios in Tcl, the Tcl community are >> perfectly happy using the existing Nagios instead of re-inventing the >> wheel, and you accuse *them* of suffering from NIH syndrome. > > Well, I don't know about Tcl but Nagios was re-written in Python: > http://www.shinken-monitoring.org/features/ > > Regards > > Antoine. It was forked to be written in Python, yes. The whole point (and it wasn't a Nagios port to Tcl) was that the Tcl community (and I like the Tcl community a lot) has a strange fixation with not reinventing the wheel, even when the wheel would be in Tcl and it might give Tcl more exposure. It is what it is though. -- Robert From flebber.crue at gmail.com Fri Dec 31 22:36:26 2010 From: flebber.crue at gmail.com (flebber) Date: Fri, 31 Dec 2010 19:36:26 -0800 (PST) Subject: GUI Tools for Python 3.1 References: Message-ID: <09e67821-46cb-4199-91e1-ab31663ced75@c13g2000prc.googlegroups.com> On Dec 26 2010, 8:41?pm, "Hans-Peter Jansen" wrote: > On Friday 24 December 2010, 03:58:15 Randy Given wrote: > > > Lots of stuff for 2.6 and 2.7 -- what GUI tools are there for 3.1? > > PyQt4 of course. > > http://www.riverbankcomputing.com > > Pete Pyside, Nokia have split with riverbank computing and are quickly developing pyside. Currently not supported in Py3000 but have already a roadmap for implementation when they finalise Python 2 support. Here is what they see as roadblocks(not insurmountble) to python3. http://developer.qt.nokia.com/wiki/PySide_Python_3_Issues From askutt at gmail.com Fri Dec 31 23:57:24 2010 From: askutt at gmail.com (Adam Skutt) Date: Fri, 31 Dec 2010 20:57:24 -0800 (PST) Subject: Nagios In-Reply-To: Message-ID: <3f7e76bf-3d62-4314-987f-62b9fda71f91@glegroupsg2000goo.googlegroups.com> On Friday, December 31, 2010 9:56:02 PM UTC-5, Robert H wrote: > It was forked to be written in Python, yes. The whole point (and it > wasn't a Nagios port to Tcl) was that the Tcl community (and I like the > Tcl community a lot) has a strange fixation with not reinventing the > wheel, even when the wheel would be in Tcl and it might give Tcl more > exposure. It is what it is though. > > -- Perhaps because they'd rather do something useful with the tool they've created instead of trying to win some sort of nonexistent popularity contest? What value would there be in that? Not trying to reinvent the wheel whenever feasible is both good programming and good engineering most of the time. Unfortunately, the fact you see this as irksome only paints you in a negative light. Adam From askutt at gmail.com Fri Dec 31 23:57:24 2010 From: askutt at gmail.com (Adam Skutt) Date: Fri, 31 Dec 2010 20:57:24 -0800 (PST) Subject: Nagios In-Reply-To: Message-ID: <3f7e76bf-3d62-4314-987f-62b9fda71f91@glegroupsg2000goo.googlegroups.com> On Friday, December 31, 2010 9:56:02 PM UTC-5, Robert H wrote: > It was forked to be written in Python, yes. The whole point (and it > wasn't a Nagios port to Tcl) was that the Tcl community (and I like the > Tcl community a lot) has a strange fixation with not reinventing the > wheel, even when the wheel would be in Tcl and it might give Tcl more > exposure. It is what it is though. > > -- Perhaps because they'd rather do something useful with the tool they've created instead of trying to win some sort of nonexistent popularity contest? What value would there be in that? Not trying to reinvent the wheel whenever feasible is both good programming and good engineering most of the time. Unfortunately, the fact you see this as irksome only paints you in a negative light. Adam From usernet at ilthio.net Wed Dec 1 01:15:12 2010 From: usernet at ilthio.net (Tim Harig) Date: Wed, 1 Dec 2010 06:15:12 +0000 (UTC) Subject: Reading by positions plain text files References: <39a07597-02b9-4ef8-9ca9-93e2d2425e66@p7g2000prb.googlegroups.com> Message-ID: On 2010-12-01, javivd wrote: > On Nov 30, 11:43?pm, Tim Harig wrote: >> On 2010-11-30, javivd wrote: >> >> > I have a case now in wich another file has been provided (besides the >> > database) that tells me in wich column of the file is every variable, >> > because there isn't any blank or tab character that separates the >> > variables, they are stick together. This second file specify the >> > variable name and his position: >> >> > VARIABLE NAME ? ? ?POSITION (COLUMN) IN FILE >> > var_name_1 ? ? ? ? ? ? ? ? 123-123 >> > var_name_2 ? ? ? ? ? ? ? ? 124-125 >> > var_name_3 ? ? ? ? ? ? ? ? 126-126 >> > .. >> > .. >> > var_name_N ? ? ? ? ? ? ? ? 512-513 (last positions) >> >> I am unclear on the format of these positions. ?They do not look like >> what I would expect from absolute references in the data. ?For instance, >> 123-123 may only contain one byte??? which could change for different >> encodings and how you mark line endings. ?Frankly, the use of the >> world columns in the header suggests that the data *is* separated by >> line endings rather then absolute position and the position refers to >> the line number. In which case, you can use splitlines() to break up >> the data and then address the proper line by index. ?Nevertheless, >> you can use file.seek() to move to an absolute offset in the file, >> if that really is what you are looking for. > > I work in a survey research firm. the data im talking about has a lot > of 0-1 variables, meaning yes or no of a lot of questions. so only one > position of a character is needed (not byte), explaining the 123-123 > kind of positions of a lot of variables. Then file.seek() is what you are looking for; but, you need to be aware of line endings and encodings as indicated. Make sure that you open the file using whatever encoding was used when it was generated or you could have problems with multibyte characters affecting the offsets. From jelari at gmail.com Wed Dec 1 02:07:03 2010 From: jelari at gmail.com (Ramprakash Jelari thinakaran) Date: Wed, 1 Dec 2010 12:37:03 +0530 Subject: Regarding searching directory and to delete it with specific pattern. Message-ID: Hi all, Would like to search list of directories with specific pattern and delete it?.. How can i do it?. Example: in /home/jpr/ i have the following list of directories. 1.2.3-2, 1.2.3-10, 1.2.3-8, i would like to delete the directories other than 1.2.3-10 which is the higher value?.. Regards, JPR. -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin at v.loewis.de Wed Dec 1 02:23:54 2010 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 01 Dec 2010 08:23:54 +0100 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename In-Reply-To: References: <4CF554ED.9050706@v.loewis.de> Message-ID: <4CF5F80A.8060804@v.loewis.de> > It'd be great if all programs used the same encoding on a given OS, > but at least on Linux, I believe historically filenames have been > created with different encodings. IOW, if I pick one encoding and go > with it, filenames written in some other encoding are likely to cause > problems. So I need something for which a filename is just a blob > that shouldn't be monkeyed with. In that case, you should use byte strings as file names, not character strings. Regards, Martin From martin at v.loewis.de Wed Dec 1 02:30:52 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Wed, 01 Dec 2010 08:30:52 +0100 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename In-Reply-To: References: <1291124813.414884.22.camel@WOPR> <4CF5AF71.3090705@mrabarnett.plus.com> Message-ID: <4CF5F9AC.7000203@v.loewis.de> > The world does not revolve around Python. Unix filenames have been > encoding-agnostic long before Python was around. If Python3 does not > support this then it's a regression on Python's part. Fortunately, Python 3 does support that. Regards, Martin From martin at v.loewis.de Wed Dec 1 02:33:23 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Wed, 01 Dec 2010 08:33:23 +0100 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename In-Reply-To: References: <1291124813.414884.22.camel@WOPR> Message-ID: <4CF5FA43.7020209@v.loewis.de> > This sounds like a strong prospect for how to get things working (I > didn't realize open would accept a bytes argument for the filename), > but I'm also interested in whether reading filenames from stdin and > subsequently opening them is supposed to "just work" given a suitable > encoding - like with Java which also uses unicode strings. In Java, > I'm told that ISO-8859-1 is supposed to "guarantee a roundtrip > conversion". It's the same in Python. However, as in Java, Python will *not* necessarily use ISO-8859-1 when you pass a (Unicode) string to open; instead, it will (as will Java) use your locale's encoding. Regards, Martin From smallpox911 at gmail.com Wed Dec 1 02:47:46 2010 From: smallpox911 at gmail.com (small Pox) Date: Tue, 30 Nov 2010 23:47:46 -0800 (PST) Subject: Watch the YANK CIA BUSTARDS Censorship live delete this post on KEY WIKILEAK REVELATIONS - RARE Message-ID: http://www.telegraph.co.uk/news/worldnews/northamerica/usa/8152326/WikiLeaks-release-Timeline-of-the-key-WikiLeaks-revelations.html WikiLeaks release: Timeline of the key WikiLeaks revelations By Jon Swaine in New York 6:53PM GMT 22 Nov 2010 December 2007: Guantanamo Bay operating procedures A US Army manual for soldiers at Camp Delta discloses that prisoners were denied access to the Red Cross for up to four weeks and that inmates could earn ?special rewards?, including a roll of lavatory paper, for good behaviour and co-operation. September 2008: Sarah Palin's email account Emails taken from the then-Republican Vice-Presidential candidate's personal account suggest that she has been using it for official business as Governor of Alaska. Doing so could have helped her avoid having her communications subjected to state laws on the disclosure of public records. November 2008: BNP membership list The names, addresses and occupations of more than 13,000 members of the far-Right British party are released in one file. The list shows that members include police officers, senior members of the military, doctors and other professionals. October 2009: Trafigura report An internal study about the effects of dumping waste by the energy trading company discloses that it used amateurish processes while dumping gasoline on the Ivory Coast and probably would have left dangerous sulphur compounds untreated November 2009: Climategate emails More than 1,000 emails sent between staff at the University of East Anglia's Climate Research Unit appeared to show that scientists distorted research to boost their argument that global warming was man- made, causing an international media storm. November 2009: September 11 pager messages About half a million pager messages sent in New York City on September 11, 2001, tell the story of the 9/11 terrorist attacks through individuals. Personal messages from people caught up in the carnage emerge, prompting criticism from commentators who claim the leak is an invasion of privacy. April 2010: Apache helicopter attack on journalists Video footage shows 15 people, including two people working for the Reuters news agency, being gunned down by a US Army helicopter in Iraq. The crew, who were not disciplined, mistook their targets' camera equipment for weapons. July 2010: Afghanistan war logs Tens of thousands of classified US military documents tell of the daily events of war in Afghanistan. The logs disclose that the Taliban is receiving greater assistance from the Pakistani intelligence services than was previously known and that the US runs a secret assassination squad. They also raise questions over potential crimes committed by coalition troops. October 2010: Iraq war logs Almost 400,000 classified US military documents recording the Iraq war suggest that evidence of the torture of Iraqis by coalition troops was ignored and record civilian deaths in more detail than was previously known. More than 66,000 civilians suffered ?violent deaths? between 2004 and the end of 2009, they show. From stefan_ml at behnel.de Wed Dec 1 02:55:14 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 01 Dec 2010 08:55:14 +0100 Subject: SAX unicode and ascii parsing problem In-Reply-To: References: <7fd52fd8-c6e0-48fa-bc50-1cff3354c3a3@u9g2000pra.googlegroups.com> Message-ID: goldtech, 30.11.2010 22:15: > Think I found it, for example: > > line = 'my big string' > line.encode('ascii', 'ignore') > > I processed the problem strings during parsing with this and it works > now. That's not the right way of dealing with encodings, though. You should open the file with a well defined encoding (using codecs.open() or io.open() in Python >= 2.6), and then write the unicode strings into it just as you get them. Stefan From smallpox911 at gmail.com Wed Dec 1 03:00:51 2010 From: smallpox911 at gmail.com (small Pox) Date: Wed, 1 Dec 2010 00:00:51 -0800 (PST) Subject: Iran slams Wiki-release as US psywar - WIKILEAKS is replacing those BIN LADEN communiques of CIA (the global ELITE) intended to threaten MASSES References: Message-ID: <2671169d-14b8-469d-bc56-d03bbefe807b@w2g2000yqb.googlegroups.com> Iran slams Wiki-release as US psywar - WIKILEAKS is replacing those BIN LADEN communiques of CIA (the global ELITE) intended to threaten MASSES CIA is the criminal agency of the global elite. They want to destroy the middle class from the planet and also create a global tyranny of a police state. http://presstv.ir/detail/153128.html http://presstv.ir/detail/153128.html http://presstv.ir/detail/153128.html Iran slams Wiki-release as US psywar Mon Nov 29, 2010 12:56PM Share | Email | Print Iran's President Mahmoud Ahmadinejad has questioned the recent 'leaked' documents published by Wikileaks website, describing them as part of a US "psychological warfare." In response to a question by Press TV on Monday over the whistleblower website's "leaks," President Mahmoud Ahmadinejad said "let me first correct you. The material was not leaked, but rather released in an organized effort." "The US administration releases documents and makes a judgment based on them. They are mostly like a psychological warfare and lack legal basis," President Ahmadinejad told reporters on Monday. "The documents will certainly have no political effects. Nations are vigilant today and such moves will have no impact on international relations," the Iranian chief executive added at the press briefing in Tehran. President Ahmadinejad stressed that the Wikileaks "game" is "not even worth a discussion and that no one would waste their time analysing them." "The countries in the region are like friends and brothers and these acts of mischief will not affect their relations," he concluded. Talks with the West The president announced that aside from Brazil and Turkey a number of other countries may take part in the new round of talks between Iran and the P5+1 -- Britain, China, France, Russia, the US, plus Germany. Human rights "They (Western powers) trample on the dignity of man, their identity and real freedom. They infringe all of these and then they call it human rights," Ahmadinejad said. Earlier this month, the UN General Assembly's Third Committee accused Iran of violating human rights regulations. The 118-member Non-Aligned Movement and the 57-member Organization of the Islamic Conference have condemned the resolution against the Islamic Republic. "In 2005, the human rights [issue] got a new mechanism in the United Nations ... human rights was pushed away and human rights was used for political manipulation," Secretary General of Iran's High Council for Human Rights Mohammed Javad Larijani told Press TV following the vote on the resolution. This is while the United Nations Human Rights Council reviewed the US human rights record for the first time in its history. The council then issued a document making 228 suggestions to the US to improve its rights record. IAEA 'leak' The president said that Iran has always had a positive relationship with the International Atomic Energy Agency but criticized the UN nuclear agency for caving under pressure from the "masters of power and wealth." The president said due to this pressure the IAEA has at times adopted "unfair and illegal stances" against the Islamic Republic. "Their recent one (IAEA report) is better than the previous ones and is closer to the truth but still all the facts are not reflected," he added. "Of course the latest report also has shortcomings, for example all [of Iran's nuclear] information has been released and these are secret and confidential documents belonging to the country." Ahmadinejad said since Iran was following a policy of nuclear transparency, it did not care about the leaks, but called the move 'illegal." New world order "The world needs order ? an order in which different people form different walks of life enjoy equal rights and proper dignity," the president said in his opening speech before taking questions form Iranian and foreign journalist. The president added that the world was already on the path to setting up this order. Iran isolation When asked to comment on the US and Western media claims that Iran has become highly isolated in the region despite an active diplomacy with Persian Gulf littoral states, the president said the remarks were part of the "discourse of hegemony." "In the hegemonic discourse, it seems that concepts and words take on different meanings than those offered by dictionaries," Ahmadinejad said. "When they say they have isolated Iran, it means that they themselves are isolated and when they say Iran is economically weak, it means that it has strengthened," the president reasoned. When they say there is a dictatorship somewhere, it means that country is really chosen by the people and vise a versa, the president further noted, adding, "I do not want to name names." ZHD/HGH/SF/MMN/MB Comments Add Comment Click Here Note: The views expressed and the links provided on our comment pages are the personal views of individual contributors and do not necessarily reflect the views of Press TV. check this out 11/30/2010 9:18:05 AMit is a coincidence that ?documents regarding Israel, their spying, influence peddling, suspicions of complicity in terrorism, Yemen, Iraq, Pakistan, Somalia, across Europe and even the Detroit bombing, those reports are there, they are classified but you will never see one on Wikileaks. In fact, they are the only classified information that never gets out to the news.? Ali 11/30/2010 7:47:47 AM"The world needs order ? an order in which different people form different walks of life enjoy equal rights and proper dignity,"very true! JHK 11/30/2010 7:37:09 AMIran should offer support to Western Media which is trying to portray the Truth. Moving these outlets outside the United States may help with this. Everyday American Citizens are at a loss as to what to do, and they need our support, some of them are Muslims. It's time4Africa 11/30/2010 7:19:25 AMDefinitely a zionist plot. All her enemies were bashed, and it was the only country to be praised in these 'leaks'. People are wiser and smarter now. "Fool me ones, shame on you. Fool me twice, shame on me!" SMARTI 11/30/2010 7:04:09 AMLOOK AT THE WESTERN MANIPULATING MEDIA, LIKE CNN FOX NEWS.FRONTPAGE HEADLINES LIKE; 'HOSTILITY TOWARDS IRAN BY NEIGHBORS'.BUT THIS LIE MEDIA ALWAYS FAILS TO MENTION THE ARAB PUBLIC OPINION TOWARDS IRAN! THEIR PROPAGANDA DON'T DISTINGUISH BETWEEN ARAB PEOPLE AND THEIR LEADERS! REASON?!: DIVIDE AND RULE!. THIS PRINCIPLE NEVER CHANGES!. IRAN BE CAREFULL, REMEMBER WHAT HIZBOLLAH LEADER ONCE SAID:THEY HAVE FAILED ON ALL THEIR PLOTS, THEY WILL TRY THEIR LAST ATTEMPT BY CREATING SUNNI-SHIA DIVISIONS 11/30/2010 6:49:48 AMI ask Sunni brothers to view Shiite not as a different religion but as a different school of thought. For example we have Hanafi, Hanbaly, etc... within Sunni Islam, why not view Shia also as such? The differences are not in the paradigm, therefore unity can be maintained. IRAN IS TOO WISE FOR CIA 11/30/2010 6:27:35 AMTHE USA IS USING WIKILEAKS TO CO-ORDINATE AND RELEASE MATERIAL WITH ALL THE OTHER STUFF TO MAKE IT LOOK LIKE IT WAS WIKILEAKS BUT IT ISNT IT IS THE CIA AND IN THIS WAY THEY CAN CAUSE PROBLEMS FOR IRAN AND NEIGHBOURING COUNTRIES. IRAN rules 11/30/2010 5:54:27 AMWIKILEAKS, IS AMERICA NEW PUBLIC RELATION TOOLS.WIKILEAKS IS HEAVELY INFLUENCED BY AMERICAN DOLLARS.AS USUAL AMERICA HIDE ITS CRIMES BY THIS TYPE OF MISINFORMATION. ify1979 11/30/2010 5:21:30 AMwiki leaks is just a proppganda game its playing wih iran! The Open Conspiracy 11/30/2010 4:36:52 AMThis is a plan that Winston Churchill had predicted would be the policy for the New World Order. Tony Blair was a typical "spill the beans" kind of speaker and the new ones are copying his style, sometimes chuckling as they make their statements. mumbo 11/30/2010 4:32:13 AMI almost think that there has never been a military coup in the US cause the military always gets (almost) all the money it wants. So the head of state has to take care of the military apparatus sustain their need for growing budgets and ongoing conflicts whether it was the red indians, french, spanish of the 19th century or the germans, vietnamese, arabs, soviets etc of the 20th and 21st century and beyond 11/30/2010 2:59:05 AMWhat many seem to have forgotten is that the so- called anti-Iranian sentiments of all the Arab PG states have been constantly touted by Western media for quite a while, long before these "leaks". Such news were also reported by PressTV and you don't think Iranians know what's going on? @ Political Game 11/30/2010 2:55:16 AMThe media is a great tool if one knows how to use it, and one of the oldest tricks in the game is a controlled leak. This is the case here. Sure, you can fool a few ignorant westerners with this trick, but Iran is an old and civilized country. Your tricks won't work here. The game is up. 11/30/2010 2:39:42 AMDamage Control by Iran's President who is rushing in, I would recommend him to be on "wait and see" mode rather than making any comments. Wikileaks may be RIGHT and maybe NOT. Political Game 11/30/2010 2:25:14 AMPresident Ahmadinejad is in denial, He knows that Wikileaks files are based on FACTS & TRUETH, however to show the world and assure the neighbouring countries(Saudis, UAE, Bahrain,etc) that Iran won't buy those facts. Just a little Political Game going on here. PEACE 11/30/2010 2:12:46 AMIt is a fabrication, how come 1/4 millions documents leak and some must br fake. @european 11/30/2010 2:07:23 AMThese are also not leaks because there are strategic elements in the contents to achieve certain agenda as with Iran and certain other countries only. Well said John Ellis 11/30/2010 1:56:06 AMThe Western media is owned by builderbergs who sees the public as dispensable items that can be best served at the lowest level of cognitive recall of events without inference, deduction, analysis, and any form of reasoning. The truth is the public may be ahead of the builderbergs in at least not tuning in as predicted. No body is in charge. So, the builderbergs have opted for offshore investments and outsourcing for the last couple of decades. The dynamics continue to indicate a bizarre future. Ranim Kalif 11/30/2010 1:46:55 AMRumour has it... That wikileaks is nothing but a CIA propaganda/counter propaganda program. The proof lies with The head honcho Julian Asange. Apparently Mr. Asange believes that 9/11 was done by fanatics from a cave in afghanistan, but anyone with half a brain can tell you that 3 steel framed building cannot collapse due to fire, its just not mathematically possible. And math does not lie, but people do. @Anti-bully 11/30/2010 12:54:13 AMAfter this week, you can retrospectively analyse and find more clues from the so-called WL documents that can be told now based on extrapolation using systemic hypocrisy templates. The West is so easy to read in either way. But, stay on the objective track. Anti-bully 11/30/2010 12:22:43 AM(Cont.) After the "Second Wikileaks" a month ago I said: "The answer to the Western idiocy is simple: Iran, Iraq & Afghanistan are neighbours, and you [[]the West INCL. Israel] DON'T BELONG THERE! SHOO!" Those neighbours of course include: Pakistan, Turkey, Azerbaijan, Syria, Lebanon, Central Asia, .... Revenge and Blessing 11/30/2010 12:12:39 AMRevenge is like Hurricane Katrina, California forest fire, American soldiers' suicides, Gulf of Mexico Spills, US rescue helicopters colliding and falling in an Iranian desert ....Blessings come with gentle earthquakes as wake-up calls to improve construction of buildings, wisdom to take technological leaps, intelligence to see the Wikileak psychological warfare,.... John Ellis 11/30/2010 12:06:17 AMWikiLeaks is doing to the public what Western corporate media does each and every day -- keep society locked in darkness by not saying a word about the root cause or solution to a problem, disclosing only the confusion, controversy, blood and guts of a problem, until finally the people in disgust back away and let the corporate rich to be enriched by the problem. Iranians know from their history 11/29/2010 11:57:39 PMthat when their leaders are liked by the West the country is in trouble and vice versa when the leaders are criticized by the West they must be very good leaders! New World Order = Slavery For All 11/29/2010 11:47:02 PMIt is already evident in the West through the public disenchantment and the authority's unwillingness to serve the public as before. The governments are not doing their usual services as if they are preparing to run slave camps soon. There are lots of telltales like trampling on constitutional rights that are bothersome. Saul 11/29/2010 11:36:33 PMI hear that the President Of Iran will soon be impeached. Is this true. Iran helps because Iran believes in God 11/29/2010 11:32:12 PM...and helps even those who have attacked Iran in the past. Because Iran does not believe in revenge like the West that is for ever occupying Germany, Japan, South Korea, etc. Iran knows better that revenge is best left to God. european 11/29/2010 10:51:03 PMThese are not leaks at all. They never compliment or give more attention to such things... just like 9/11, nobody could suggest a possiblity of an inside job. Nobody. So how come, Assange comes in and publish leaks and he becomes an idol of masses?This is one big joke.The US behaves like a shaitan, then issues a represantative to openly admit that their country belongs to the devil. AB 11/29/2010 10:49:56 PMToday popularity contest is base on economic liberty not on propaganda policy. If Iran didn?t help Lebanon or Iraq to back on their feet, today had no popularity the same as Egypt. Abd 11/29/2010 10:02:12 PMThe enemies of humanity who think they have saved a face behind addiction, corruption and oppression of even their citizens are actually at an ideological dead end. The US demons and their Salary worshiper pupits in the almost expired UN should cry their heart out and get drunk before lying about Iran. Sincerely.www.criesofdarwinism.com Iranian 11/29/2010 10:00:35 PMAnd some people criticize his foreign policy. this announcement is something that every Iranian can be proud of, proud of their president, unfortunately it is fashionable to criticize or insult Ahmadinejad without any reason thanks to zionist media. To Anti-Bully 11/29/2010 10:00:00 PMEven when there is a physical court, it is inconspicuously hollowed out in favour of the Western dictatorships that pretend to be democratic. scott68 11/29/2010 9:53:56 PMcertain comments that were leaked to the western media from Wikileaks is being used by western media to create a hostile climate on the subject of say for example Iran's nuclear program by using the names of certain key leaders in the middle east who have said the US should attack Iran to prevent them obtaining nuclear weapons it seems as though the western media want to create a hostile reaction towards Iran with this information Anti-bully 11/29/2010 9:51:10 PMThe 3-step Wikileaks (WL) rocket. First WL: US army atrocities. 2nd WL: People in ME kill and bribe each other (which according to West's fascist "logic" makes it OK if US/UK/NATO/Israel do it as well). 3rd WL: The big fish panjandrums are in on it. IOW: 1) "We, WEST, have the muscles", 2) "You, ME, deserve what's coming to you" 3) "WE-HAVE-THE-POWER". Conclusion: "You, the "REST", can do ZIT!". @Anti-bully 11/29/2010 9:38:54 PMAffirmative! Took me more than 45 years in the West to research the systemic anatomy of hypocricy. You have come a long way, and so have most of those who have commented here. Anti-bully 11/29/2010 9:18:07 PMWest, when it deems convenient, shows evidences of it's atrocities (Vietnam files, Wikileaks, Abu Ghraib pics) and boohoos "look how TERRIBLE we are", but you wouldn't SEE the smirk. Of course, some evidences could hold in a court of law, but what if there is NO court? This makes the Anglo-American psycho-West grin even wider. IOW, West gets off flaunting how disgusting it can be. You think Iran was joking when calling them "Great Satan"? PIONEER 11/29/2010 8:58:05 PMso it's true (and quoted by iran) when it's about the u.s. and the west, but untrue when it's about iran? EB 11/29/2010 8:30:55 PMSo when something bad about the US is released by wikileaks, Iran agrees with them, but when something bad about Iran comes out, they say it's not true and planned by the west.. Wonderful double standards. PressTV is a joke, and it's just like FoxNews, completely biased. Katifa 11/29/2010 8:22:24 PMI wish Ahmadinejad would go into more detail as to why he feels the US benefits from this leak. I don't understand his point of view and usually I do! mumbo 11/29/2010 7:52:07 PMsome of the statements by Bahraini, UAE or Saudi Arab leaders would have never been made, even in private if it weren't for certain imperialist powers constantly dabbling in this region. Now that they do dabble, it should be treated as private thoughts - nothing more nothing less. However let s remember that it was superpower support of Saddam Hussein that got many arab leaders to dole money to Saddam fighting the Persians. hussain mehdi 11/29/2010 7:33:06 PMthis is leak??? first they announce and then they publish leak!!! this is leak??? is this leak??? 11/29/2010 7:13:06 PMYhere was time Muslims were divided in Shia and Sunni but the Ediots of West have helped us to get rid of the prejudices and now Thanks God we are one. Iran was always Great Shia Nation and Turkey Great Sinni Nation. Now they Mashallah are Great Islamic Nation. subhan Allah. The enemy has cut its own throat. fred Kay 11/29/2010 6:15:06 PMALL ARAB COUNTRIES HAVE PUPPET GOVERNMENTS PUT IN POWER BY THE MASTERS IN THE WEST.MUSLIM BROTHERHOOD WITH ARABS?!MY FOOT,WHAT POSITIVE STEPS HAVE THEY TAKEN TOWARDS IRAN?,NONE.IRAN MUST PAY THEM IN KIND AND SHAKE THEIR GLASS HOUSES.ISRAEL IS RIGHT TO GIVE THEM A BLOW EVERY TIME THEY OPEN THEIR BRAINLESS MOUTHS. Pak 11/29/2010 6:12:52 PMHis Excellency Mr. AhamdiNejad is a great leader of Muslim nation.And the arrogant powers are scared from this thing.For Non Muslims nations there is nothing Shia or Sunni only Muslims.And these Non Muslims nations always try their best to use all resources to make difference between Muslims. RESON 11/29/2010 5:51:43 PMWEST HAVE BIG SOCIAL PROBLEM & THAT IS THRUST BETWEEN ITS PEAPOL V GOVT TO BUILD THAT THRUST NEED TO PROVE DOMACRECY EXCICT. IRAQ WAR PRODUCE BIG MASS OF SOCIAL UNREST INWEST IN TOTAL. THE LEAK WORKS LIKE PRESUR COOKER.HAVE RELISE AIR OUT Abu bukk 11/29/2010 5:34:50 PMVery well said asgar I'm a Muslim Sunni aswell and I agree that all Muslims are brothers wa Salam Albert Hakim 11/29/2010 4:56:39 PMWhat if this is a real leak?! Then what? I think if Iranians are smart, they should give it a possibility. I believe, Iranians should not trust Arabs who have proven to be America's servants in the Middle East. Truth seeker 11/29/2010 4:42:26 PMThe Council on Foreign Relations (most influential foreign-policy think tank), are the secret rulers of every country and they can knock out anyone who doesn't obey their rules. Make for Public 11/29/2010 4:27:41 PMWikileaks is an Zionist Agent Provocateur, Period. sana 11/29/2010 4:09:26 PMThis is a cheap game and will not work at all. if they think people in the ME are stupid; they prove themselves to be stupid. At the end of the day, they will be the losing party. We consider themselves brothers and sisters and will remains so. Days of colonialism and imperialism are over. You cannot rule the whole China with a bunch of colonial thiefs anymore. ASGAR 11/29/2010 3:43:47 PMIM a Sunni if the west or Arab Leaders are trying to divide shia and Sunni they will fail with me, my friends and people i talk to. We all see the Good Iran is doing and i hope it will bring us closer and end the man made divied of sunni /shia for good. south african 11/29/2010 3:39:24 PMAgreed. America would have stopped this if they were not behind it. They are a super power and should be able to stop some man from stealing their top secret documents, which are probably hidden inside a thick vault with 10 CIA agents guarding it. James 11/29/2010 3:38:07 PMIran has not fallen for childish Amreican tricks. Congratulations. Iran knows Wiki and other such attempts are ploys of its enemies. Every child can see throught them. Ernest in USA 11/29/2010 3:37:56 PMSince our government has lost all its credibility with us Americans due to its lies to get us in a war against Iraq, it has to release propaganda through other sources, like wikileaks. These are not leaks, but deliberate propaganda attempts to incite hatred against Iran, and division between Muslim governments. We Americans are not falling for it! Former US Marine 11/29/2010 3:27:28 PMWikileaks spreads the OFFICIAL 9/11 propaganda and even says Bin Laden is still alive. So funny. Anyone with half a brain knows that 9/11 was a DEMOLITION done by Israel and Zionist Traitors. Wikileaks is 100[[]%] Zionist approved propaganda. Wikileaks = controlled opposition NY 11/29/2010 3:22:45 PMPresident Ahmadinejad is absolutely correct in what he says. It is so nice to read facts and not the lies and deceptions in the US media that even a baby can see through. Long live Iran! Londoner 11/29/2010 3:20:37 PMThe leaks said Netanyahu is "a charming man." Most other leaders were insulted. Guess who is behind these "leaks." KIKI 11/29/2010 3:06:24 PMLOOK ONLY TO THE MEDIA THAT WIKILEAKS HAVE CHOSEN TO GIVE THEM THE SO/CALLED LEAKS, DER SPIEGEL AND LE MONDE ARE THE SAME MEDIA THAT PUBLISHED THE SO/CALLED ACCUSATIONS OF HIZBOLLAH ON THE HARIRI CASE. I WONDER WHY THE ISRAELI MEDIA LOOKS SOO HAPPY ABOUT ALL THIS. WHY THEIR IS SOO FEW THINGS ABOUT ISRAEL IN THE SO/CALLED LEAKS. IT DOESNT SEEM RATIONAL THAT ONE MAN CAN LEAK SOOO MUCH OF THE SO/CALLED SECRET DOC. bob 11/29/2010 3:03:01 PMWikileaks is israel!!!! Its so obvious!! truthseeker 11/29/2010 2:59:23 PMJulian Assange works for the cia and is also funded by George Soros. Do you really think that this guy would still be walking around as freely as he does if they did not want this info out. This guy is well known in the alternative media for being funded by soros and why does he release the info first to state controlled newspapers, why not alternative news, which is getting bigger by the day. CD 11/29/2010 2:58:04 PMYes, President Mahmoud Ahmadinejad is right and we should all come together united against western imperialisme. Unity and Tolerance amongst the people is the "Leitmotive" and a new equale world order,permetting us to secure the future of the humanity and making this world a better place to live for our children. Nick 11/29/2010 2:57:03 PMThe US government controls our finances eg. wall street derivatives... They control our business, eg. government motors (GM)... and they control our press, along with all these so-called 'Wiki leaks' ! To All Iranians 11/29/2010 2:22:30 PMAlways ask yourselve what is the consequence of what you say in reacting to hearsay accounts like WikiLeak stories. Your enemies live in hypocricy. They force international commissions like IAEA to act and report in hypocricy. They demonstrate in their own courts to judge as hypocrites. They blame you and find you guilty with hypocricy. Do not fall for it. Demand facts and proofs. Rely on the verified public statements of leaders. Show your enemies that they are the stupid ones. Iranian 11/29/2010 2:12:43 PMWell, it's quite obvious. lots of was about Iran and how Iran hated by american puppets in the middle east. and also some ridiculous useless about some other things that we already knew about them, just to make the whole thing acceptable. I really thought that they would prepare the material much better than the first time. but it was even more obvious who leaked those. Seems they are getting sloppy and desperate. Common Sense 11/29/2010 1:51:01 PMChances leak ever to survive World of Zionis regime that include US. Agent will be assassinate period (even their President). Infomation need to be filted carefully and wisely. To good to be true for sure. Pakistani 11/29/2010 1:49:44 PMAhmadinejad is very wise to ignore wikileaks revelations by branding it a propagenda.Although you have to be very naive to actually believe this is a propaganda but Ahmadinejad is right to call it a propaganda in public. I would have done the exact same thing. Disagreement between iran and saudiarabia should never turn into a war between sunni and shias. Mona Montgomery 11/29/2010 1:40:45 PMMohammed, thank you for explaing that. Mohammed 11/29/2010 1:16:40 PMYes, very smart man. I think the same thing. There is something not quite right about the Wikileaks. Maybe the this whole 'leak' thing is a controlled dissent by the Western powers. The real juicy stuff will stay in storage for the next 100 years. From nobody at nowhere.com Wed Dec 1 03:43:51 2010 From: nobody at nowhere.com (Nobody) Date: Wed, 01 Dec 2010 08:43:51 +0000 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename References: <1291124813.414884.22.camel@WOPR> Message-ID: On Wed, 01 Dec 2010 02:14:09 +0000, MRAB wrote: > If the filenames are to be shown to a user then there needs to be a > mapping between bytes and glyphs. That's an encoding. If different > users use different encodings then exchange of textual data becomes > difficult. OTOH, the exchange of binary data is unaffected. In the worst case, users see a few wrong glyphs, but the software doesn't care. > That's where encodings which can be used globally come in. > By the time Python 4 is released I'd be surprised if Unix hadn't > standardised on a single encoding like UTF-8. That's probably not a serious option in parts of the world which don't use a latin-based alphabet, i.e. outside western Europe and its former colonies. In countries with non-latin alphabets, existing encodings are often too heavily entrenched. There's also a lot of legacy software which can only handle unibyte encodings, and not much incentive to fix it if 98% of your market can get by with an ISO-8859- locale (making software work in e.g. CJK locales often requires a lot more work than just dealing with encodings). And it doesn't help that Windows has negligible support for UTF-8. It's either UTF-16-LE (i.e. the in-memory format dumped directly to file) or one of Microsoft's non-standard encodings. At least the latter are mostly compatible with the corresponding ISO-8859-* encoding. Finally, ISO-8859-* encoding/decoding can't fail. The result might be complete gibberish, but converting to gibberish then back to bytes won't lose information. From mail at timgolden.me.uk Wed Dec 1 03:48:45 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 01 Dec 2010 08:48:45 +0000 Subject: Catching user switching and getting current active user from root on linux In-Reply-To: <1a9bdbd4-2997-4e0f-a24f-cd148247e312@r40g2000prh.googlegroups.com> References: <1a9bdbd4-2997-4e0f-a24f-cd148247e312@r40g2000prh.googlegroups.com> Message-ID: <4CF60BED.8020904@timgolden.me.uk> On 30/11/2010 22:47, mpnordland wrote: > I have situation where I need to be able to get the current active > user, and catch user switching eg user1 locks screen, leaves computer, > user2 comes, and logs on. > basically, when there is any type of user switch my script needs to > know. If it's Windows you're on, have a look at this: http://timgolden.me.uk/python/win32_how_do_i/track-session-events.html TJG From steve+comp.lang.python at pearwood.info Wed Dec 1 03:54:49 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Dec 2010 08:54:49 GMT Subject: Change one list item in place References: <17175f49-087f-4d05-ada2-7e8c7e7e86dd@z17g2000prz.googlegroups.com> Message-ID: <4cf60d59$0$30003$c3e8da3$5496439d@news.astraweb.com> On Tue, 30 Nov 2010 17:08:57 -0800, Gnarlodious wrote: > This works for me: > > def sendList(): > return ["item0", "item1"] > > def query(): > l=sendList() > return ["Formatting only {0} into a string".format(l[0]), l[1]] For the record, you're not actually changing a list in place, you're creating a new list. I would prefer: def query(): l = sendList() l[0] = "Formatting only {0} into a string".format(l[0]) return l which will continue to work even if sendlist() gets changed to return 47 items instead of 2. An alternative would be: -- Steven From ulrich.eckhardt at dominolaser.com Wed Dec 1 03:57:54 2010 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Wed, 01 Dec 2010 09:57:54 +0100 Subject: SAX unicode and ascii parsing problem References: <7fd52fd8-c6e0-48fa-bc50-1cff3354c3a3@u9g2000pra.googlegroups.com> Message-ID: <19fhs7-sac.ln1@satorlaser.homedns.org> goldtech wrote: > I tried this but nothing changed, I thought this might convert it and > then I'd paerse the new file - didn't work: > > uc = open(r'E:\sc\ppb4.xml').read().decode('utf8') > ascii = uc.decode('ascii') > mex9 = open( r'E:\scrapes\ppb5.xml', 'w' ) > mex9.write(ascii) This doesn't make sense either. decode() will convert bytes into (Unicode) characters. After the first decode('utf8'), you have those already. Calling decode('ascii') on that doesn't make sense. If you want ASCII, as the assignee suggests, you need to _encode_ the string. Be aware that not all characters can be represented as ASCII though, and the presence of such a character seems to have caused your initial problem. BTW: - XML is not necessarily UTF-8, but that's a different issue. - I would suggest you open files with 'rb' or 'wb' in order to suppress any conversions on line endings. Especially writing UTF-16 would fail if that is active. Good luck! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From solipsis at pitrou.net Wed Dec 1 04:12:51 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Wed, 1 Dec 2010 10:12:51 +0100 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename In-Reply-To: References: <339421.80548.qm@web54205.mail.re2.yahoo.com> <20101130161919.693a1d78@pitrou.net> Message-ID: <20101201101251.51c83197@pitrou.net> On Tue, 30 Nov 2010 16:57:57 -0800 Dan Stromberg wrote: > >> --- On Tue, 11/30/10, Dan Stromberg wrote: > >> > In Python 3, I'm finding that I have encoding issues with > >> > characters > >> > with their high bit set.? Things are fine with strictly > >> > ASCII > >> > filenames.? With high-bit-set characters, even if I > >> > change stdin's > >> > encoding with: > >> [...] > > I have the same problem using 3.2alpha4: the word man~ana (6 > characters long) in a filename causes problems (I'm catching the > exception and skipping the file for now) despite using what I believe > is an 8-bit, all 256-bytes-are-characters encoding: iso-8859-1. 'not > sure if you wanted both of us to try this, or Yingjie alone though. What do sys.stdin.encoding and sys.getfilesystemencoding() return? If they are different, then it's the cause of the problem, since sys.getfilesystemencoding() is used by open() to encode filenames. In this case, the solution is to encode filenames yourself using sys.stdin.encoding, or read them as bytes directly from sys.stdin.buffer (which is the binary non-unicode counterpart of sys.stdin). If they are the same, then I guess you can open an issue, provided you give enough indications for people to reproduce :) Regards Antoine. From steve+comp.lang.python at pearwood.info Wed Dec 1 04:14:35 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Dec 2010 09:14:35 GMT Subject: Change one list item in place References: <17175f49-087f-4d05-ada2-7e8c7e7e86dd@z17g2000prz.googlegroups.com> <4cf60d59$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cf611fb$0$30004$c3e8da3$5496439d@news.astraweb.com> On Wed, 01 Dec 2010 08:54:49 +0000, Steven D'Aprano wrote: > An alternative would be: > Please ignore. That was an accidental Send mid-edit. -- Steven From solipsis at pitrou.net Wed Dec 1 04:15:41 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Wed, 1 Dec 2010 10:15:41 +0100 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename References: <1291124813.414884.22.camel@WOPR> <4CF5AF71.3090705@mrabarnett.plus.com> <1291173721.687410.18.camel@WOPR> Message-ID: <20101201101541.7d2adaa9@pitrou.net> On Tue, 30 Nov 2010 22:22:01 -0500 Albert Hopkins wrote: > And I can freely copy > these "invalid" files across different (Unix) systems, because the OS > doesn't care about encoding. And so can Python, thanks to PEP 383. > > That's where encodings which can be used globally come in. > > By the time Python 4 is released I'd be surprised if Unix hadn't > > standardised on a single encoding like UTF-8. > > I have serious doubts about that. At least in the Linux world the > kernel wants to stay out of encoding debates (except where it has to > like Window filesystems). That doesn't matter. Vendors (Linux distributions) have to make a choice and that choice will probably standardize on UTF-8 in most situations. The kernel won't have a say, since it doesn't care about encodings anyway. > The world does not revolve around Python. Unix filenames have been > encoding-agnostic long before Python was around. If Python3 does not > support this then it's a regression on Python's part. Python 3 does support it, see other messages about using bytes filenames. Regards Antoine. From solipsis at pitrou.net Wed Dec 1 04:24:09 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Wed, 1 Dec 2010 10:24:09 +0100 Subject: To Thread or not to Thread....? References: Message-ID: <20101201102409.686e016f@pitrou.net> On Wed, 1 Dec 2010 02:45:50 +0000 Jack Keegan wrote: > Hi there, > > I'm currently writing an application to control and take measurements during > an experiments. This is to be done on an embedded computer running XPe so I > am happy to have python available, although I am pretty new to it. > The application basically runs as a state machine, which transitions through > it's states based on inputs read in from a set of general purpose > input/output (GPIO) lines. So when a certain line is pulled low/high, do > something and move to another state. All good so far and since I get through > main loop pretty quickly, I can just do a read of the GPIO lines on each > pass through the loop and respond accordingly. > However, in one of the states I have to start reading in, and storing frames > from a camera. In another, I have to start reading accelerometer data from > an I2C bus (which operates at 400kHz). I haven't implemented either yet but > I would imagine that, in the case of the camera data, reading a frame would > take a large amount of time as compared to other operations. Therefore, if I > just tried to read one (or one set of) frames on each pass through the loop > then I would hold up the rest of the application. Conversely, as the I2C bus > will need to be read at such a high rate, I may not be able to get the > required data rate I need even without the camera data. This naturally leads > me to think I need to use threads. > As I am no expert in either I2C, cameras, python or threading I thought I > would chance asking for some advice on the subject. Do you think I need > threads here or would I be better off using some other method. I was > previously toying with the idea of using generators to create weightless > threads (as detailed in > http://www.ibm.com/developerworks/library/l-pythrd.html) for reading the > GPIOs. Do you think this would work in this situation? The main question IMO: the I2C bus operates at 400kHz, but how much received data can it buffer? That will give you a hint as to how much latency you can tolerate. I don't think soft threads would work at all, since they wouldn't allow overlapping between frame reading and other ops. If frame reading releases the GIL (as any properly implemented IO primitive in Python should), then at least you can try using OS threads. Then, depending on the tolerable latency for I2C operation, you can try to run it as an OS thread, or a separate process (if running as a separate process, make sure it cannot block while sending IO to the master process). Regards Antoine. From steve+comp.lang.python at pearwood.info Wed Dec 1 04:26:05 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Dec 2010 09:26:05 GMT Subject: Programming games in historical linguistics with Python References: Message-ID: <4cf614ad$0$30003$c3e8da3$5496439d@news.astraweb.com> On Tue, 30 Nov 2010 07:03:28 -0800, Dax Bloom wrote: > Is there a way to refer to vowels and consonants as a subcategory of > text? Is there a function to remove all vowels? How should one create > and order the dictionary file for the rules? How to chain several > transformations automatically from multiple rules? Finally can anyone > show me what existing python program or phonological software can do > this? Have you looked at NLTK? http://www.nltk.org/ The questions you are asking are awfully specific for a general programming forum like this. You might have better luck asking on a NLTK forum, or possibly if you could pose your questions in ways that don't assume extensive familiarity in linguistics ("word nucleus"? "codas"?). Is there a function to remove vowels -- not specifically, but provided you can tell us what characters you wish to treat as vowels, and provided you are satisfied with a fairly simple search-and-replace, this will do it: # For Python 2.x def disemvowel(s): """Quick and dirty disemvoweller.""" tbl = string.maketrans('', '') return string.translate(s, tbl, "aeiouAEIOU") If you want a function that can distinguish between Y being used as a vowel from Y being used as a consonant, you'll need something much more sophisticated -- try the NLTK. -- Steven From __peter__ at web.de Wed Dec 1 04:34:24 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 01 Dec 2010 10:34:24 +0100 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename References: <1291124813.414884.22.camel@WOPR> Message-ID: Nobody wrote: > Python 3.x's decision to treat filenames (and environment variables) as > text even on Unix is, in short, a bug. One which, IMNSHO, will mean that > Python 2.x is still around when Python 4 is released. For filenames in Python 3 the user has the choice between "text" (str) and bytes. If the user chooses text that will be converted to bytes using a default encoding that hopefully matches that of the other tools on the machine that manipulate filenames. I see that you may run into problems with the text approach when you encounter byte sequences that are illegal in the chosen encoding. I therefore expect that lowlevel tools will use bytes to manipulate filenames while end user scripts will choose text. I don't see how a dogmatic bytes only restriction can improve the situation. Also, you can already provide unicode filenames in Python 2.x (and a script containing constant filenames becomes more portable if you do), so IMHO the situation in Python 2 and 3 is similar enough as to not hinder adoption of 3.x. Peter From vithyam6 at gmail.com Wed Dec 1 04:37:16 2010 From: vithyam6 at gmail.com (cinema) Date: Wed, 1 Dec 2010 01:37:16 -0800 (PST) Subject: HOW TO EARN MONEY FROM FOREX TRADING ONLINE? Message-ID: <276e0e3e-c43f-4f63-9840-941ac1d03223@e16g2000pri.googlegroups.com> http://forextradingonlinetoday.blogspot.com http://forextradingonlinetoday.blogspot.com http://forextradingonlinetoday.blogspot.com http://forextradingonlinetoday.blogspot.com http://forextradingonlinetoday.blogspot.com From dudeja.rajat at gmail.com Wed Dec 1 04:53:59 2010 From: dudeja.rajat at gmail.com (dudeja.rajat at gmail.com) Date: Wed, 1 Dec 2010 15:23:59 +0530 Subject: Login using usrllib2 Message-ID: Hi All, I'm using urllib2 module to login to an https server. However I'm unable to login as the password is not getting accepted. Here is the code: import urllib2, urllib values={'Username': 'admin', 'Password': 'admin123'} url='https://172.25.17.20:9443' data = urllib.urlencode(values) data = urllib.urlencode(values) req = urllib2.Request(url, data) response = urllib2.urlopen(req) the_page = response.read() print the_page The error message I get in the_page output is the same as I get when I access this site using a browser and supply a wrong password. It appears password is not accepting. I'm new to web programming. The aim is to automate user clicks on a web server which can be replicated using python and http. Please suggest / help. Regards, Rajat -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Wed Dec 1 05:16:46 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 1 Dec 2010 02:16:46 -0800 Subject: Login using usrllib2 In-Reply-To: References: Message-ID: On Wed, Dec 1, 2010 at 1:53 AM, wrote: > Hi All, > > > I'm using urllib2 module to login to an https server. However I'm unable to > login as the password is not getting accepted. > > Here is the code: > > import urllib2, urllib > values={'Username': 'admin', 'Password': 'admin123'} > url='https://172.25.17.20:9443' > data = urllib.urlencode(values) > > > data = urllib.urlencode(values) > req = urllib2.Request(url, data) > response = urllib2.urlopen(req) > the_page = response.read() > print the_page > > The error message I get in the_page output is the same as I get when I > access this site using a browser and supply a wrong password. It appears > password is not accepting. > > I'm new to web programming. The aim is to automate user clicks on a web > server which can be replicated using python and http. Please suggest / help. You should probably use something like Firefox's "Live HTTP Headers" extension to see what exactly the web browser is doing when you normally login to the site, so that you can correctly replicate the browser's actions in your script. The site may be using HTTP Basic or HTTP Digest authentication, in which case you'll need to use urllib2.HTTPBasicAuthHandler or urllib2.HTTPDigestAuthHandler. Cheers, Chris -- http://blog.rebertia.com From whatsjacksemail at gmail.com Wed Dec 1 06:50:46 2010 From: whatsjacksemail at gmail.com (Jack Keegan) Date: Wed, 1 Dec 2010 11:50:46 +0000 Subject: To Thread or not to Thread....? In-Reply-To: <20101201102409.686e016f@pitrou.net> References: <20101201102409.686e016f@pitrou.net> Message-ID: Hi Antoine, On Wed, Dec 1, 2010 at 9:24 AM, Antoine Pitrou wrote: > > > The main question IMO: the I2C bus operates at 400kHz, but how much > received data can it buffer? That will give you a hint as to how much > latency you can tolerate. > I'm not sure on buffering, but I have to ask the device on the I2C bus for a sample each time I want one. This is done by sending out the address of the device on the I2C bus, waiting for a reply, then addressing the registers I want to read data from, then read the data. Therefore, I would need to make the request at the rate I require. > > I don't think soft threads would work at all, since they wouldn't allow > overlapping between frame reading and other ops. If frame reading > releases the GIL (as any properly implemented IO primitive in Python > should), then at least you can try using OS threads. > It's actually a separate piece of hardware that does the frame reading/encoding. I then interface to this via a DLL so I'm not sure how it handles things in the background. Unless I am mistaken, I have to allocate a chunk of memory for it to read the frames into, while I read from there. It's probably some sort of ring buffer implementation so I'd have to read the frames out and store them to disk before the next run through the buffer overwrites the old frames. How does that sound, process/thread wise? Thanks, Jack -- The earth is a very small stage in a vast cosmic arena. Think of the rivers of blood spilled by all those generals and emperors so that in glory and in triumph they could become the momentary masters of a fraction of a dot. - Carl Sagan [Pale Blue Dot] -------------- next part -------------- An HTML attachment was scrubbed... URL: From solipsis at pitrou.net Wed Dec 1 07:04:03 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Wed, 1 Dec 2010 13:04:03 +0100 Subject: To Thread or not to Thread....? In-Reply-To: References: <20101201102409.686e016f@pitrou.net> Message-ID: <20101201130403.41c270c1@pitrou.net> On Wed, 1 Dec 2010 11:50:46 +0000 Jack Keegan wrote: > Hi Antoine, > > On Wed, Dec 1, 2010 at 9:24 AM, Antoine Pitrou wrote: > > > > > > The main question IMO: the I2C bus operates at 400kHz, but how much > > received data can it buffer? That will give you a hint as to how much > > latency you can tolerate. > > > I'm not sure on buffering, but I have to ask the device on the I2C bus for a > sample each time I want one. This is done by sending out the address of the > device on the I2C bus, waiting for a reply, then addressing the registers I > want to read data from, then read the data. Therefore, I would need to make > the request at the rate I require. Sounds like you want to do this part in raw C and in a separate process, IMO. > > I don't think soft threads would work at all, since they wouldn't allow > > overlapping between frame reading and other ops. If frame reading > > releases the GIL (as any properly implemented IO primitive in Python > > should), then at least you can try using OS threads. > > > It's actually a separate piece of hardware that does the frame > reading/encoding. I then interface to this via a DLL so I'm not sure how it > handles things in the background. Unless I am mistaken, I have to allocate a > chunk of memory for it to read the frames into, while I read from there. Well, if you are the one writing the CPython interface against the DLL, you are responsible for releasing the GIL properly. > It's probably some sort of ring buffer implementation so I'd have to read > the frames out and store them to disk before the next run through the buffer > overwrites the old frames. You have to evaluate the latency requirements there too. I have to point out that I have no experience on embedded software, so the advice I'm giving is out of pure common sense :) Regards Antoine. From dario.beraldi at ed.ac.uk Wed Dec 1 07:23:09 2010 From: dario.beraldi at ed.ac.uk (Dario Beraldi) Date: Wed, 01 Dec 2010 12:23:09 +0000 Subject: SFTP: max bytes to be transferred Message-ID: <20101201122309.77330rdwews4egc0@www.staffmail.ed.ac.uk> Hello, I'm using the module paramiko to transfer files via sftp (see code below). I would like to specify the maximum amount of bytes to be transferred (say 10MB, if the file is bigger just transfer up to these many bytes). From the docs of paramiko (http://www.lag.net/paramiko/docs/paramiko.SFTPClient-class.html#get) I see that the method get() can take an optional callback parameter which is a "function that accepts the bytes transferred so far and the total bytes to be transferred". This seems to do what I need but I don't know how to specify such callback function. Any idea? This is my code: ------------[ Cut here ]------------- import paramiko host = "my.host" port = 22 transport = paramiko.Transport((host, port)) password = "mypassword" username = "myname" transport.connect(username = username, password = password) sftp = paramiko.SFTPClient.from_transport(transport) filepath = 'file/to/myfile.txt' localpath = 'D:/Tritume/myfile.txt' sftp.get(filepath, localpath) ## <-- Calback function should go here ------------[ cut here]----------- Many thanks Dario -- Dr. Dario Beraldi Institute of Evolutionary Biology University of Edinburgh West Mains Road Edinburgh EH9 3JT Scotland, UK -- Dr. Dario Beraldi Institute of Evolutionary Biology University of Edinburgh West Mains Road Edinburgh EH9 3JT Scotland, UK -- The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336. From javivd319 at hotmail.com Wed Dec 1 07:40:38 2010 From: javivd319 at hotmail.com (Javier Van Dam) Date: Wed, 1 Dec 2010 09:40:38 -0300 Subject: Reading by positions plain text files In-Reply-To: <4CF5B3D8.3030206@tim.thechases.com> References: <39a07597-02b9-4ef8-9ca9-93e2d2425e66@p7g2000prb.googlegroups.com> , <4CF5B3D8.3030206@tim.thechases.com> Message-ID: Ok. I will try it and let you know. Thanks a lot!! J > Date: Tue, 30 Nov 2010 20:32:56 -0600 > From: python.list at tim.thechases.com > To: javiervandam at gmail.com > CC: python-list at python.org > Subject: Re: Reading by positions plain text files > > On 11/30/2010 08:03 PM, javivd wrote: > > On Nov 30, 11:43 pm, Tim Harig wrote: > >>> VARIABLE NAME POSITION (COLUMN) IN FILE > >>> var_name_1 123-123 > >>> var_name_2 124-125 > >>> var_name_3 126-126 > >>> .. > >>> .. > >>> var_name_N 512-513 (last positions) > >> > > and no, MRAB, it's not the similar problem (at least what i understood > > of it). I have to associate the position this file give me with the > > variable name this file give me for those positions. > > MRAB may be referring to my reply in that thread where you can do > something like > > OFFSETS = 'offsets.txt' > offsets = {} > f = file(OFFSETS) > f.next() # throw away the headers > for row in f: > varname, rest = row.split()[:2] > # sanity check > if varname in offsets: > print "[%s] in %s twice?!" % (varname, OFFSETS) > if '-' not in rest: continue > start, stop = map(int, rest.split('-')) > offsets[varname] = slice(start, stop+1) # 0-based offsets > #offsets[varname] = slice(start+1, stop+2) # 1-based offsets > f.close() > > def do_something_with(data): > # your real code goes here > print data['var_name_2'] > > for row in file('data.txt'): > data = dict((name, row[offsets[name]]) for name in offsets) > do_something_with(data) > > There's additional robustness-checks I'd include if your > offsets-file isn't controlled by you (people send me daft data). > > -tkc > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Wed Dec 1 08:23:59 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 01 Dec 2010 14:23:59 +0100 Subject: Change one list item in place In-Reply-To: <17175f49-087f-4d05-ada2-7e8c7e7e86dd@z17g2000prz.googlegroups.com> References: <17175f49-087f-4d05-ada2-7e8c7e7e86dd@z17g2000prz.googlegroups.com> Message-ID: <4CF64C6F.2080809@sequans.com> Gnarlodious wrote: > This works for me: > > def sendList(): > return ["item0", "item1"] > > def query(): > l=sendList() > return ["Formatting only {0} into a string".format(l[0]), l[1]] > > query() > > > However, is there a way to bypass the > > l=sendList() > > and change one list item in-place? Possibly a list comprehension > operating on a numbered item? > > -- Gnarlie > what about def query(): return ["Formating only {0} into a string".format(sendList()[0])] + sendList()[1:] JM From awilliam at whitemice.org Wed Dec 1 08:33:28 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Wed, 01 Dec 2010 08:33:28 -0500 Subject: SAX unicode and ascii parsing problem In-Reply-To: References: Message-ID: <1291210408.7712.2.camel@linux-yu4c.site> On Tue, 2010-11-30 at 12:28 -0800, goldtech wrote: > I'm trying to parse an xml file using SAX. About half-way through a > file I get this error: > Traceback (most recent call last): > File "C:\Python26\Lib\site-packages\pythonwin\pywin\framework > \scriptutils.py", line 325, in RunScript > exec codeObject in __main__.__dict__ > File "E:\sc\b2.py", line 58, in > parser.parse(open(r'ppb5.xml')) > File "C:\Python26\Lib\xml\sax\expatreader.py", line 107, in parse > xmlreader.IncrementalParser.parse(self, source) > File "C:\Python26\Lib\xml\sax\xmlreader.py", line 123, in parse > self.feed(buffer) > File "C:\Python26\Lib\xml\sax\expatreader.py", line 207, in feed > self._parser.Parse(data, isFinal) > File "C:\Python26\Lib\xml\sax\expatreader.py", line 304, in > end_element > self._cont_handler.endElement(name) > File "E:\sc\b2.py", line 51, in endElement > d.write(csv+"\n") > UnicodeEncodeError: 'ascii' codec can't encode characters in position > 146-147: ordinal not in range(128) Catch the UnicodeEncodeError exception and display the value of csv. Are you certain the error isn't actually in your data? What encoding is the source data? What is "d"? A file object? Is it in binary mode, or is it StringIO, or a codec? > I'm using ActivePython 2.6. I trying to figure out the simplest fix. > If there's a Python way to just take the source XML file and covert/ > process it so this will not happen - that would be best. Or should I > just update to Python 3 ? > I tried this but nothing changed, I thought this might convert it and > then I'd paerse the new file - didn't work: > u = open(r'E:\sc\ppb4.xml').read().decode('utf8') > ascii = uc.decode('ascii') > mex9 = open( r'E:\scrapes\ppb5.xml', 'w' ) > mex9.write(ascii) > Again I'm looking for something simple even it's a few more lines of > codes...or upgrade(?) If the input data contains characters that cannot be represented in ASCII simply decoding the stream (a) won't fix it and (b) should raise an exception. From gnarlodious at gmail.com Wed Dec 1 08:33:55 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Wed, 1 Dec 2010 05:33:55 -0800 (PST) Subject: Change one list item in place References: <17175f49-087f-4d05-ada2-7e8c7e7e86dd@z17g2000prz.googlegroups.com> Message-ID: On Dec 1, 6:23?am, Jean-Michel Pichavant wrote: > what about > > def query(): > ? ? return ["Formating only {0} into a string".format(sendList()[0])] + > sendList()[1:] However this solution calls sendList() twice, which is too processor intensive. Thanks for all the ideas, I've resigned myself to unpacking a tuple and reassembling it. -- Gnarlie http://Sectrum.com From nelson1977 at gmail.com Wed Dec 1 08:48:24 2010 From: nelson1977 at gmail.com (nelson) Date: Wed, 1 Dec 2010 05:48:24 -0800 (PST) Subject: strange TypeError exception in function compiled from a string Message-ID: Hi all, I have this function, defined in a string and ecetuted through ad exec call def cell1(d): x=d.get('x') print x import y return y.add(y.add(self.adf0(x),self.adf0(x)),self.adf0(x)) d is a dict of this kind {'x':2} I receive the following exception, that i find very strange... File "", line 7, in cell1 TypeError: 'dict' object is not callable I have tested all the function al line 7, and none of them raise any exception. Have anyone some suggestion on how to solve this? thanks! From prologic at shortcircuit.net.au Wed Dec 1 08:48:38 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 1 Dec 2010 23:48:38 +1000 Subject: To Thread or not to Thread....? In-Reply-To: <20101201102409.686e016f@pitrou.net> References: <20101201102409.686e016f@pitrou.net> Message-ID: Surely I2C is just a serial-like interface and one should be able to do async I/O on it ? The use of threads is not necessary here and the GIL doesn't become a problem in async I/O anyway. I only use threads for operating that might block (not for I/O). cheers James On Wed, Dec 1, 2010 at 7:24 PM, Antoine Pitrou wrote: > On Wed, 1 Dec 2010 02:45:50 +0000 > Jack Keegan wrote: > >> Hi there, >> >> I'm currently writing an application to control and take measurements during >> an experiments. This is to be done on an embedded computer running XPe so I >> am happy to have python available, although I am pretty new to it. >> The application basically runs as a state machine, which transitions through >> it's states based on inputs read in from a set of general purpose >> input/output (GPIO) lines. So when a certain line is pulled low/high, do >> something and move to another state. All good so far and since I get through >> main loop pretty quickly, I can just do a read of the GPIO lines on each >> pass through the loop and respond accordingly. > >> However, in one of the states I have to start reading in, and storing frames >> from a camera. In another, I have to start reading accelerometer data from >> an I2C bus (which operates at 400kHz). I haven't implemented either yet but >> I would imagine that, in the case of the camera data, reading a frame would >> take a large amount of time as compared to other operations. Therefore, if I >> just tried to read one (or one set of) frames on each pass through the loop >> then I would hold up the rest of the application. Conversely, as the I2C bus >> will need to be read at such a high rate, I may not be able to get the >> required data rate I need even without the camera data. This naturally leads >> me to think I need to use threads. >> As I am no expert in either I2C, cameras, python or threading I thought I >> would chance asking for some advice on the subject. Do you think I need >> threads here or would I be better off using some other method. I was >> previously toying with the idea of using generators to create weightless >> threads (as detailed in >> http://www.ibm.com/developerworks/library/l-pythrd.html) for reading the >> GPIOs. Do you think this would work in this situation? > > The main question IMO: the I2C bus operates at 400kHz, but how much > received data can it buffer? That will give you a hint as to how much > latency you can tolerate. > > I don't think soft threads would work at all, since they wouldn't allow > overlapping between frame reading and other ops. If frame reading > releases the GIL (as any properly implemented IO primitive in Python > should), then at least you can try using OS threads. > > Then, depending on the tolerable latency for I2C operation, you can try > to run it as an OS thread, or a separate process (if running as a > separate process, make sure it cannot block while sending IO to the > master process). > > Regards > > Antoine. > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- -- James Mills -- -- "Problems are solved by method" From khamenya at gmail.com Wed Dec 1 08:52:30 2010 From: khamenya at gmail.com (Valery Khamenya) Date: Wed, 1 Dec 2010 14:52:30 +0100 Subject: How to initialize each multithreading Pool worker with an individual value? In-Reply-To: References: Message-ID: Hi Dan, > If you create in the parent a queue in shared memory (multiprocessing > facilitates this nicely), and fill that queue with the values in your > ports tuple, then you could have each child in the worker pool extract > a single value from this queue so each worker can have its own, unique > port value. this port number is supposed to be used once, namely during initialization. Quite usual situation with conections is so, that it is a bit expensive to initiate it each time the connection is about to be used. So, it is often initialized once and dropped only when all communication is done. In contrast, your case looks for me that you rather propose to initiate the connection each time a new job comes from queue for an execution. Regards, Valery From jeanmichel at sequans.com Wed Dec 1 08:59:37 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 01 Dec 2010 14:59:37 +0100 Subject: Change one list item in place In-Reply-To: References: <17175f49-087f-4d05-ada2-7e8c7e7e86dd@z17g2000prz.googlegroups.com> Message-ID: <4CF654C9.8060203@sequans.com> Gnarlodious wrote: > On Dec 1, 6:23 am, Jean-Michel Pichavant > wrote: > >> what about >> >> def query(): >> return ["Formating only {0} into a string".format(sendList()[0])] + >> sendList()[1:] >> > > However this solution calls sendList() twice, which is too processor > intensive. > > You got to get rid of those nerd habits of unecessary optimization. To put it simple, you just don't give a [put whatever suitable word] to the overhead of 2 calls of sendList instead of one. Until query is called a million time a second, there's no need to sacrifice anything on the optimization altar, because no one will never ever see the difference. You can find my solution not that readable, that would be a proper reason for not using it. It's up to you. JM From bruno.desthuilliers at gmail.com Wed Dec 1 09:17:57 2010 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Wed, 1 Dec 2010 06:17:57 -0800 (PST) Subject: strange TypeError exception in function compiled from a string References: Message-ID: On 1 d?c, 14:48, nelson wrote: > Hi all, > ? I have this function, defined in a string and ecetuted through ad > exec call > > def cell1(d): > > ? ? x=d.get('x') > ? ? print x > > ? ? import y > ? ? return y.add(y.add(self.adf0(x),self.adf0(x)),self.adf0(x)) > > d is a dict of this kind {'x':2} > > I receive the following exception, that i find very strange... > > ? File "", line 7, in cell1 > TypeError: 'dict' object is not callable > > I have tested all the function al line 7, and none of them raise any > exception. > Have anyone some suggestion on how to solve this? > Not without the minimal executable code reproducing your error. From tw55413 at gmail.com Wed Dec 1 09:18:25 2010 From: tw55413 at gmail.com (erikj) Date: Wed, 1 Dec 2010 06:18:25 -0800 (PST) Subject: position independent build of python Message-ID: Hi, If my understanding is correct, the sys.prefix variable holds the root directory python uses to find related files, and eg its site-packages. the value of sys.prefix is specified at compile time. it seems that on windows, when I build/install python at one location, and later move it to another location, python will find all its needs relative to the new location. however, when I do the same on linux, python keeps looking for its dependencies in the build location. is there a possibility to have it always look at a position relative to the location of the executable ? the goal is to be able to build python on one machine, and then simply copy the build tree to other machines at other locations. Thank you and regards, Erik From werner at thieprojects.ch Wed Dec 1 09:28:15 2010 From: werner at thieprojects.ch (Werner Thie) Date: Wed, 01 Dec 2010 15:28:15 +0100 Subject: To Thread or not to Thread....? In-Reply-To: References: <20101201102409.686e016f@pitrou.net> Message-ID: <4CF65B7F.90806@thieprojects.ch> Hi I see quite a few alleys to go down when stuck with such types of problems, but instead of listing and discussing them have a look at a quite complete discussion and comparison of the various async programming options available at http://syncless.googlecode.com Also have a look at the presentation at http://syncless.googlecode.com/svn/trunk/doc/slides_2010-11-29/pts_coro_2010-11-29.html If I were in your shoes I would solve the problem in stackless, if exchanging the python interpreter is not possible then Twisted would be my second choice, having done a lot of work with it (see the NMEA classes for serial ports). I don't know if syncless handles other types of fd's like serial ports, I've never played with it. The monkey patching of syncless might pose other problems in your case. HTH, Werner Am 01.12.2010 14:48, schrieb James Mills: > Surely I2C is just a serial-like interface > and one should be able to do async I/O on it ? > > The use of threads is not necessary here and the GIL > doesn't become a problem in async I/O anyway. > > I only use threads for operating that might block (not for I/O). > > cheers > James > > On Wed, Dec 1, 2010 at 7:24 PM, Antoine Pitrou wrote: >> On Wed, 1 Dec 2010 02:45:50 +0000 >> Jack Keegan wrote: >> >>> Hi there, >>> >>> I'm currently writing an application to control and take measurements during >>> an experiments. This is to be done on an embedded computer running XPe so I >>> am happy to have python available, although I am pretty new to it. >>> The application basically runs as a state machine, which transitions through >>> it's states based on inputs read in from a set of general purpose >>> input/output (GPIO) lines. So when a certain line is pulled low/high, do >>> something and move to another state. All good so far and since I get through >>> main loop pretty quickly, I can just do a read of the GPIO lines on each >>> pass through the loop and respond accordingly. >> >>> However, in one of the states I have to start reading in, and storing frames >>> from a camera. In another, I have to start reading accelerometer data from >>> an I2C bus (which operates at 400kHz). I haven't implemented either yet but >>> I would imagine that, in the case of the camera data, reading a frame would >>> take a large amount of time as compared to other operations. Therefore, if I >>> just tried to read one (or one set of) frames on each pass through the loop >>> then I would hold up the rest of the application. Conversely, as the I2C bus >>> will need to be read at such a high rate, I may not be able to get the >>> required data rate I need even without the camera data. This naturally leads >>> me to think I need to use threads. >>> As I am no expert in either I2C, cameras, python or threading I thought I >>> would chance asking for some advice on the subject. Do you think I need >>> threads here or would I be better off using some other method. I was >>> previously toying with the idea of using generators to create weightless >>> threads (as detailed in >>> http://www.ibm.com/developerworks/library/l-pythrd.html) for reading the >>> GPIOs. Do you think this would work in this situation? >> >> The main question IMO: the I2C bus operates at 400kHz, but how much >> received data can it buffer? That will give you a hint as to how much >> latency you can tolerate. >> >> I don't think soft threads would work at all, since they wouldn't allow >> overlapping between frame reading and other ops. If frame reading >> releases the GIL (as any properly implemented IO primitive in Python >> should), then at least you can try using OS threads. >> >> Then, depending on the tolerable latency for I2C operation, you can try >> to run it as an OS thread, or a separate process (if running as a >> separate process, make sure it cannot block while sending IO to the >> master process). >> >> Regards >> >> Antoine. >> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > -------------- next part -------------- A non-text attachment was scrubbed... Name: werner.vcf Type: text/x-vcard Size: 297 bytes Desc: not available URL: From python at bdurham.com Wed Dec 1 09:55:01 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 01 Dec 2010 09:55:01 -0500 Subject: When to use codecs vs. io module (Python 2.7 and higher) Message-ID: <1291215301.9144.1408094187@webmail.messagingengine.com> Python 2.7 or higher: Looking for reasons/scenarios where one should use the codecs vs. io module. Are there use cases that favor one specific module over the other module? My understanding is that the io module is much faster than the codecs module (and can be used interchangably), but the codecs module provides backward compatibility if you need to target versions of Python less than 2.6. Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From solipsis at pitrou.net Wed Dec 1 10:04:55 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Wed, 1 Dec 2010 16:04:55 +0100 Subject: To Thread or not to Thread....? In-Reply-To: References: <20101201102409.686e016f@pitrou.net> Message-ID: <20101201160455.0e9aa70e@pitrou.net> On Wed, 1 Dec 2010 23:48:38 +1000 James Mills wrote: > Surely I2C is just a serial-like interface > and one should be able to do async I/O on it ? > > The use of threads is not necessary here and the GIL > doesn't become a problem in async I/O anyway. Well, you are missing the point. The OP wants to do operations that have certain latency requirements while doing other operations "in parallel". Using several preemptively-switching threads (or processes) is the simplest way of achieving that; you can do cooperative multithreading (which is conceptually the same as single-threaded async programming), but you'll have to insert as many explicit synchronization points as necessary to achieve the latency objectives. Not very practical obviously. (and, yes, the GIL amounts to some bastardized, fine-grained form of cooperative multithreading, which is why separate processes might be a better answer if the latency requirements are tight - especially on Python 2.x-3.1 where the GIL is badly implemented) Regards Antoine. From solipsis at pitrou.net Wed Dec 1 10:06:53 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Wed, 1 Dec 2010 16:06:53 +0100 Subject: When to use codecs vs. io module (Python 2.7 and higher) References: <1291215301.9144.1408094187@webmail.messagingengine.com> Message-ID: <20101201160653.280fa90c@pitrou.net> On Wed, 01 Dec 2010 09:55:01 -0500 python at bdurham.com wrote: > Python 2.7 or higher: Looking for reasons/scenarios where one > should use the codecs vs. io module. > > Are there use cases that favor one specific module over the other > module? > > My understanding is that the io module is much faster than the > codecs module (and can be used interchangably), but the codecs > module provides backward compatibility if you need to target > versions of Python less than 2.6. That's a good summary, although I'm not sure codecs and io are interchangeable. They will certainly have slightly different behaviour in corner cases. The io module is much more tested since it's the official way to do I/O in Python 3, so its own corner cases are probably better than those in the codecs module :) Regards Antoine. From invalid at invalid.invalid Wed Dec 1 10:23:21 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 1 Dec 2010 15:23:21 +0000 (UTC) Subject: Catching user switching and getting current active user from root on linux References: <1a9bdbd4-2997-4e0f-a24f-cd148247e312@r40g2000prh.googlegroups.com> Message-ID: On 2010-11-30, mpnordland wrote: > I have situation where I need to be able to get the current active > user, How do you define "current active user"? > and catch user switching eg user1 locks screen, leaves computer, > user2 comes, and logs on. basically, when there is any type of user > switch my script needs to know. What do you do when there are multiple users logged in? -- Grant Edwards grant.b.edwards Yow! How's the wife? at Is she at home enjoying gmail.com capitalism? From prog at vtr.net Wed Dec 1 10:48:41 2010 From: prog at vtr.net (craf) Date: Wed, 01 Dec 2010 12:48:41 -0300 Subject: Decorate un Frame with window managers title bar, etc en Tkinter 8.5 Message-ID: <1291218521.4983.24.camel@cristian-desktop> Hi. I use python 3.1 and Tkinter 8.5 in Ubuntu 9.10 I would like to turn a frame into a toolbox, ,and for that I read that you can use the command wm manage (window) The information can be found at: http://www.tcl.tk/man/tcl8.5/TkCmd/wm.htm#M39 the explanation says: wm manage widget: The widget specified will become a stand alone top-level window. The window will be decorated with the window managers title bar, etc. Only frame, labelframe and toplevel widgets can be used with this command. Attempting to pass any other widget type will raise an error. Attempting to manage a toplevel widget is benign and achieves nothing. See also GEOMETRY MANAGEMENT. I have tried to use it in Tkinter but I can not know how is its structure. In Tkinter should be: ---TEST CODE------------------- from Tkinter import master = Tk() frame = Frame(master) wm_manager(Frame) master.mainloop() -------------------------------- But this does not work. I appreciate any of this item Regards. Cristian Abarz?a From info at wingware.com Wed Dec 1 10:59:46 2010 From: info at wingware.com (Wingware) Date: Wed, 01 Dec 2010 10:59:46 -0500 Subject: Wing IDE 3.2.12 released Message-ID: <4CF670F2.4060908@wingware.com> Hi, Wingware has released version 3.2.12 of Wing IDE, an integrated development environment designed specifically for the Python programming language. This release includes the following improvements: * Support for Stackless version 2.7 * Correctly ignore exceptions in debugger for logged exceptions * Fix indent conversion when file had inconsistent eol characters * Change Mako block commenting to use ## * Fix testing tool result display when re-running similarly named tests * 8 other minor bug fixes See http://wingware.com/pub/wingide/3.2.12/CHANGELOG.txt for details. *Downloads* Wing IDE Professional http://wingware.com/downloads/wingide/3.2 Wing IDE Personal http://wingware.com/downloads/wingide-personal/3.2 Wing IDE 101 http://wingware.com/downloads/wingide-101/3.2 *About Wing IDE* Wing IDE is an integrated development environment designed specifically for the Python programming language. It provides powerful editing, testing, and debugging features that help reduce development and debugging time, cut down on coding errors, and make it easier to understand and navigate Python code. Wing IDE can be used to develop Python code for web, GUI, and embedded scripting applications. Wing IDE is available in three product levels: Wing IDE Professional is the full-featured Python IDE, Wing IDE Personal offers a reduced feature set at a low price, and Wing IDE 101 is a free simplified version designed for teaching entry level programming courses with Python. Version 3.2 of Wing IDE Professional includes the following major features: * Professional quality code editor with vi, emacs, and other keyboard personalities * Code intelligence for Python: Auto-completion, call tips, goto-definition, error indicators, smart indent and re-wrapping, and source navigation * Advanced multi-threaded debugger with graphical UI, command line interaction, conditional breakpoints, data value tool tips over code, watch tool, and externally launched and remote debugging * Powerful search and replace options including keyboard driven and graphical UIs, multi-file, wild card, and regular expression search and replace * Version control integration for Subversion, CVS, Bazaar, git, Mercurial, and Perforce * Integrated unit testing for the unittest, nose, and doctest frameworks * Many other features including project manager, bookmarks, code snippets, OS command integration, indentation manager, PyLint integration, and perspectives * Extremely configurable and may be extended with Python scripts Please refer to the feature list at http://wingware.com/wingide/features for a detailed listing of features by product level. System requirements are Windows 2000 or later, OS X 10.3.9 or later for PPC or Intel (requires X11 Server), or a recent Linux system (either 32 or 64 bit). Wing IDE supports Python versions 2.0.x through 3.1.x and Stackless Python. For more information, see http://wingware.com/products *Purchasing and Upgrading* Wing 3.2 is a free upgrade for all Wing IDE 3.0 and 3.1 users. Version 2.x licenses cost 1/2 the normal price to upgrade. Upgrade a license: https://wingware.com/store/upgrade Purchase a license: https://wingware.com/store/purchase -- Wingware | Python IDE The Intelligent Development Environment for Python Programmers www.wingware.com From goldtech at worldpost.com Wed Dec 1 11:16:28 2010 From: goldtech at worldpost.com (goldtech) Date: Wed, 1 Dec 2010 08:16:28 -0800 (PST) Subject: Python's equivalent to Main calling program and subprograms Message-ID: Hi, Could someone link me to info - I'm sure this is commonly done: "Long ago" with Fortran and Pascal there was a pattern used a lot. It was like: Start Main Global Var Subprogram1 Subprogram2 Subprogram3 End of Main End The global var was a var that all the subprograms could access. I wanted a container for several scripts that run in succession one after dhere other. This has to be newbie stuff - sorry to ask. If you could give me some keywords or link me or provide a simple example I would be grateful. Thanks From usernet at ilthio.net Wed Dec 1 11:28:56 2010 From: usernet at ilthio.net (Tim Harig) Date: Wed, 1 Dec 2010 16:28:56 +0000 (UTC) Subject: Python's equivalent to Main calling program and subprograms References: Message-ID: On 2010-12-01, goldtech wrote: > Start > Main > Global Var > Subprogram1 > Subprogram2 > Subprogram3 > End of Main > End module_wide_var = value def Subprogram1: # code def Subprogram2: # code def Subprogram3: # code def main: Subprogram1() Subprogram2() Subprogram3() if __name__ == "__main__": main() From jeanmichel at sequans.com Wed Dec 1 11:42:28 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 01 Dec 2010 17:42:28 +0100 Subject: Python's equivalent to Main calling program and subprograms In-Reply-To: References: Message-ID: <4CF67AF4.7040201@sequans.com> Tim Harig wrote: > On 2010-12-01, goldtech wrote: > >> Start >> Main >> Global Var >> Subprogram1 >> Subprogram2 >> Subprogram3 >> End of Main >> End >> > > module_wide_var = value > > def Subprogram1: > # code > > def Subprogram2: > # code > > def Subprogram3: > # code > > def main: > Subprogram1() > Subprogram2() > Subprogram3() > > if __name__ == "__main__": > main() > "def main:" raises a syntax error. "def main():" does not (python 2.5) JM From joncle at googlemail.com Wed Dec 1 12:02:41 2010 From: joncle at googlemail.com (Jon Clements) Date: Wed, 1 Dec 2010 09:02:41 -0800 (PST) Subject: Login using usrllib2 References: Message-ID: <5873559c-edd5-44c0-aae3-81d41e77948b@fj16g2000vbb.googlegroups.com> On Dec 1, 10:16?am, Chris Rebert wrote: > On Wed, Dec 1, 2010 at 1:53 AM, ? wrote: > > Hi All, > > > I'm using urllib2 module to login to an https server. However I'm unable to > > login as the password is not getting accepted. > > > Here is the code: > > > import urllib2, urllib > > values={'Username': 'admin', 'Password': 'admin123'} > > url='https://172.25.17.20:9443' > > data = urllib.urlencode(values) > > > data = urllib.urlencode(values) > > req = urllib2.Request(url, data) > > response = urllib2.urlopen(req) > > the_page = response.read() > > print the_page > > > The error message I get in the_page output is the same as I get when I > > access this site using a browser and supply a wrong password. It appears > > password is not accepting. > > > I'm new to web programming. The aim is to automate user clicks on a web > > server which can be replicated using python and http. Please suggest / help. > > You should probably use something like Firefox's "Live HTTP Headers" > extension to see what exactly the web browser is doing when you > normally login to the site, so that you can correctly replicate the > browser's actions in your script. > The site may be using HTTP Basic or HTTP Digest authentication, in > which case you'll need to use urllib2.HTTPBasicAuthHandler or > urllib2.HTTPDigestAuthHandler. > > Cheers, > Chris > --http://blog.rebertia.com If the OP is doing this a lot I would suggest installing FF's Firebug extension. Then use the Net tab to monitor activity. Also the OP might want to look at the urllib2.HTTPSHandler. Jon From snert at hotmail.se Wed Dec 1 12:08:14 2010 From: snert at hotmail.se (m b) Date: Wed, 1 Dec 2010 18:08:14 +0100 Subject: Python's equivalent to Main calling program and subprograms In-Reply-To: <4CF67AF4.7040201@sequans.com> References: , , <4CF67AF4.7040201@sequans.com> Message-ID: > > > > if __name__ == "__main__": > > main() What does this mean? /Mikael -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Wed Dec 1 12:13:39 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 01 Dec 2010 17:13:39 +0000 Subject: strange TypeError exception in function compiled from a string In-Reply-To: References: Message-ID: <4CF68243.7030709@mrabarnett.plus.com> On 01/12/2010 13:48, nelson wrote: > Hi all, > I have this function, defined in a string and ecetuted through ad > exec call > > def cell1(d): > > x=d.get('x') > print x > > import y > return y.add(y.add(self.adf0(x),self.adf0(x)),self.adf0(x)) > > > d is a dict of this kind {'x':2} > > I receive the following exception, that i find very strange... > > File "", line 7, in cell1 > TypeError: 'dict' object is not callable > > I have tested all the function al line 7, and none of them raise any > exception. > Have anyone some suggestion on how to solve this? > A call looks like foo(), so probably either y.add or self.adf0 is a dict. Print both of them to check. From clp2 at rebertia.com Wed Dec 1 12:18:48 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 1 Dec 2010 09:18:48 -0800 Subject: Python's equivalent to Main calling program and subprograms In-Reply-To: References: <4CF67AF4.7040201@sequans.com> Message-ID: On Wed, Dec 1, 2010 at 9:08 AM, m b wrote: >> > >> > if __name__ == "__main__": >> > main() > > What does this mean? See http://effbot.org/pyfaq/tutor-what-is-if-name-main-for.htm (which is the 3rd Google hit for "__main__") Cheers, Chris From jeanmichel at sequans.com Wed Dec 1 12:20:01 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 01 Dec 2010 18:20:01 +0100 Subject: Python's equivalent to Main calling program and subprograms In-Reply-To: References: , , <4CF67AF4.7040201@sequans.com> Message-ID: <4CF683C1.7010709@sequans.com> m b wrote: > > > > > > > > if __name__ == "__main__": > > > main() > > What does this mean? > > /Mikael __name__ is an attribute of the module. Usually it is set to the module name, except when the module is acutally executed as the entry point, in that case __name__ is set to '__main__'. foo.py: print __name__ > python foo.py '__main__' > python -c "import foo" 'foo' This is a very basic concept, you should read the python tutorial. JM From benjamin.kaplan at case.edu Wed Dec 1 12:24:18 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 1 Dec 2010 12:24:18 -0500 Subject: Python's equivalent to Main calling program and subprograms In-Reply-To: References: <4CF67AF4.7040201@sequans.com> Message-ID: On Wed, Dec 1, 2010 at 12:08 PM, m b wrote: > > >> > >> > if __name__ == "__main__": >> > main() > > What does this mean? > > /Mikael > Every module has an attribute called __name__. Normally, it's the name of the module itself. However, the module being run as a script (rather than imported) is called __main__. You can use if __name__ == "__main__" to have certain things only run if the file is executed directly. ---- a.py ---- print "I'm A" if __name__ == '__main__' : print "I'm the main script" --- b.py --- import a $ python a.py I'm A I'm the main script $ python b.py I'm A From hanif_1989 at btinternet.com Wed Dec 1 12:25:30 2010 From: hanif_1989 at btinternet.com (Hanif Jameel) Date: Wed, 01 Dec 2010 17:25:30 +0000 Subject: Python's equivalent to Main calling program and subprograms In-Reply-To: References: , , <4CF67AF4.7040201@sequans.com> Message-ID: <4CF6850A.1020708@btinternet.com> On 01/12/2010 17:08, m b wrote: > > > > > > > > if __name__ == "__main__": > > > main() > > What does this mean? > > /Mikael > Python will not cause the main() function to run automatically when you execute the script, it has to be called. __name__ is a special variable which is set by the python interpreter when it runs a source file. If the source file is run directly(as opposed to being imported), then the value of __name__ will be set to __main__. so if __name__ == "__main__": main() checks to see if the source file be being directly executed, and if it is, calls the main() function. From python at mrabarnett.plus.com Wed Dec 1 12:35:53 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 01 Dec 2010 17:35:53 +0000 Subject: Regarding searching directory and to delete it with specific pattern. In-Reply-To: References: Message-ID: <4CF68779.60902@mrabarnett.plus.com> On 01/12/2010 07:07, Ramprakash Jelari thinakaran wrote: > Hi all, > Would like to search list of directories with specific pattern and > delete it?.. How can i do it?. > Example: in /home/jpr/ i have the following list of directories. > 1.2.3-2, 1.2.3-10, 1.2.3-8, i would like to delete the directories > other than 1.2.3-10 which is the higher value?.. > Use os.listdir to get a list of the names in the directory. Use os.path.isdir to identify those which are subdirectories. Identify the names which match the pattern, eg: name.startswith("1.2.3-") and name[6 : ].isdigit() Identify the 'highest' name (it's the one with the maximum value of int(name[6 : ])). Remove each of the unwanted subdirectories with shutil.rmtree. It's also a good idea if initially it doesn't actually remove the unwanted directories, but just prints out the paths of them, because you really don't want to discover that you've made a mistake and it has deleted something important! :-) From carlo at somewhere.com Wed Dec 1 12:36:42 2010 From: carlo at somewhere.com (Carlo) Date: 01 Dec 2010 17:36:42 GMT Subject: string find/replace Message-ID: <4cf687aa$0$5000$e4fe514c@dreader19.news.xs4all.nl> Hello, I want the Python equivalent of the Perl expression: s/([a-z])([A-Z])/\1 \2/g In plain language: place a space between a lowercase and uppercase letter. I get lost in the RE module. Can someone help me? Thanks! From steve at holdenweb.com Wed Dec 1 12:38:15 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 01 Dec 2010 12:38:15 -0500 Subject: Python's equivalent to Main calling program and subprograms In-Reply-To: References: , , <4CF67AF4.7040201@sequans.com> Message-ID: On 12/1/2010 12:08 PM, m b wrote: > > >> > >> > if __name__ == "__main__": >> > main() > > What does this mean? > > /Mikael > It's a standard way of allowing programs to test themselves. When a module is imported its __name__ attribute us bound to the name of the module. When the module is run as a main program (from the command line) its __name__ attribute is set to "__main__". The main() call just calls a function that (presumably) tests the functions the module provides. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From __peter__ at web.de Wed Dec 1 12:42:43 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 01 Dec 2010 18:42:43 +0100 Subject: string find/replace References: <4cf687aa$0$5000$e4fe514c@dreader19.news.xs4all.nl> Message-ID: Carlo wrote: > I want the Python equivalent of the Perl expression: > s/([a-z])([A-Z])/\1 \2/g > In plain language: place a space between a lowercase and uppercase > letter. I get lost in the RE module. Can someone help me? >>> import re >>> re.compile("([a-z])([A-Z])").sub(r"\1 \2", "camelCase") 'camel Case' or >>> re.sub("([a-z])([A-Z])", r"\1 \2", "camelCase") 'camel Case' From donnieodonnell at gmail.com Wed Dec 1 12:46:03 2010 From: donnieodonnell at gmail.com (Donald O'Donnell) Date: Wed, 1 Dec 2010 09:46:03 -0800 (PST) Subject: string find/replace References: <4cf687aa$0$5000$e4fe514c@dreader19.news.xs4all.nl> Message-ID: <710c0436-58b1-49d7-a54d-bff0c0504604@j29g2000yqm.googlegroups.com> On Dec 1, 12:36?pm, Carlo wrote: > Hello, > > I want the Python equivalent of the Perl expression: > s/([a-z])([A-Z])/\1 \2/g > In plain language: place a space between a lowercase and uppercase > letter. I get lost in the RE module. Can someone help me? > > Thanks! This will also replace '_' with space:: recamelsub = re.compile(r"([a-z])([A-Z])").sub def spacify(string): """ Replace '_' with space & insert space between lower & upper case letters """ return recamelsub(r"\1 \2", string.replace('_',' ')) From carlo at somewhere.com Wed Dec 1 12:59:04 2010 From: carlo at somewhere.com (Carlo) Date: 01 Dec 2010 17:59:04 GMT Subject: string find/replace References: <4cf687aa$0$5000$e4fe514c@dreader19.news.xs4all.nl> Message-ID: <4cf68ce8$0$12821$e4fe514c@dreader19.news.xs4all.nl> On 2010-12-01, Peter Otten <__peter__ at web.de> wrote: >>>> import re >>>> re.compile("([a-z])([A-Z])").sub(r"\1 \2", "camelCase") > 'camel Case' Very simple if you know it. Thank you! From python at mrabarnett.plus.com Wed Dec 1 13:07:03 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 01 Dec 2010 18:07:03 +0000 Subject: string find/replace In-Reply-To: <4cf687aa$0$5000$e4fe514c@dreader19.news.xs4all.nl> References: <4cf687aa$0$5000$e4fe514c@dreader19.news.xs4all.nl> Message-ID: <4CF68EC7.8090803@mrabarnett.plus.com> On 01/12/2010 17:36, Carlo wrote: > Hello, > > I want the Python equivalent of the Perl expression: > s/([a-z])([A-Z])/\1 \2/g > In plain language: place a space between a lowercase and uppercase > letter. I get lost in the RE module. Can someone help me? > That's easy: new_text = re.sub(r'([a-z])([A-Z])', r'\1 \2', old_text) From mdw at distorted.org.uk Wed Dec 1 13:19:20 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 01 Dec 2010 18:19:20 +0000 Subject: Catching user switching and getting current active user from root on linux References: <1a9bdbd4-2997-4e0f-a24f-cd148247e312@r40g2000prh.googlegroups.com> Message-ID: <8739qhs6dz.fsf.mdw@metalzone.distorted.org.uk> Grant Edwards writes: > On 2010-11-30, mpnordland wrote: > > and catch user switching eg user1 locks screen, leaves computer, > > user2 comes, and logs on. basically, when there is any type of user > > switch my script needs to know. > > What do you do when there are multiple users logged in? In case it's not clear: this situation doesn't just occur on `exotic' systems like Unix servers. Even Windows systems can have several people logged into the console (with one active, using `fast user switching') and another one or two connected using terminal services. -- [mdw] From usernet at ilthio.net Wed Dec 1 14:13:54 2010 From: usernet at ilthio.net (Tim Harig) Date: Wed, 1 Dec 2010 19:13:54 +0000 (UTC) Subject: Python's equivalent to Main calling program and subprograms References: <4CF67AF4.7040201@sequans.com> Message-ID: > On Wed, Dec 1, 2010 at 9:08 AM, m b wrote: >>> > if __name__ == "__main__": >>> > main() >> >> What does this mean? It is a Python idiom and a good practice. Strictly speaking it is unnecessary. Python doesn't recognize any functional initialization vector other then the start of the file. When Python loads a module, it executes anything it finds in the module scope (Anything not in the body of a class or function declaration). Using a main function is just a convention. You could just place all of your main level code in the module scope: def Subprogram1(): # code def Subprogram2(): # code def Subprogram3(): # code # main code or equivilantly, always execute main(): def Subprogram1(): # code def Subprogram2(): # code def Subprogram3(): # code def main(): # main code main() Both are valid from Python's point of view. The 'if __name__ == "__main__":' idiom is used, because it allows the module to be loaded without running main(). This is useful if you wanted to use Subprogram2() from another program. Even if you don't forsee using any of the subprograms (functions to Python), this can be useful when writing test code as you can import the program as a module to test its classes or functions separately. From kirby.urner at gmail.com Wed Dec 1 15:38:34 2010 From: kirby.urner at gmail.com (kirby.urner at gmail.com) Date: Wed, 1 Dec 2010 12:38:34 -0800 (PST) Subject: Packages at Python.org Message-ID: <084f9299-b2b3-440f-b83f-9fbe42220221@j19g2000prh.googlegroups.com> With Microsoft abandoning Visual FoxPro come 2015, we have 100K developers jumping ship (rough guess), perhaps to dot NET, but not necessarily.** This page is potentially getting a lot of hits (I'm not privy to the analytics): http://packages.python.org/dbf/ So how *do* you get source code from such a web place? I'm not finding a tar ball or installer. Sorry if I'm missing something obvious, like a link to Sourceforge. Kirby ** Unconfirmed rumors about IronPython leave me blog searching this afternoon. Still part of Codeplex? From ian.g.kelly at gmail.com Wed Dec 1 15:48:33 2010 From: ian.g.kelly at gmail.com (Ian) Date: Wed, 1 Dec 2010 12:48:33 -0800 (PST) Subject: Packages at Python.org References: <084f9299-b2b3-440f-b83f-9fbe42220221@j19g2000prh.googlegroups.com> Message-ID: <1f034df4-bb14-4996-8185-e75976bf320c@i25g2000prd.googlegroups.com> On Dec 1, 1:38?pm, "kirby.ur... at gmail.com" wrote: > http://packages.python.org/dbf/ > > So how *do* you get source code from such a web place? ?I'm not > finding > a tar ball or installer. ?Sorry if I'm missing something obvious, like > a link > to Sourceforge. That site only contains documentation. Try this page instead: http://pypi.python.org/pypi/dbf/ From clp2 at rebertia.com Wed Dec 1 15:49:03 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 1 Dec 2010 12:49:03 -0800 Subject: Packages at Python.org In-Reply-To: <084f9299-b2b3-440f-b83f-9fbe42220221@j19g2000prh.googlegroups.com> References: <084f9299-b2b3-440f-b83f-9fbe42220221@j19g2000prh.googlegroups.com> Message-ID: On Wed, Dec 1, 2010 at 12:38 PM, kirby.urner at gmail.com wrote: > With Microsoft abandoning Visual FoxPro come 2015, we have 100K > developers > jumping ship (rough guess), perhaps to dot NET, but not necessarily.** > > This page is potentially getting a lot of hits (I'm not privy to the > analytics): > > http://packages.python.org/dbf/ > > So how *do* you get source code from such a web place? You don't; that's only a docs page. You instead want the index entry page: http://pypi.python.org/pypi/dbf which has nice obvious download links. Cheers, Chris From dinov at microsoft.com Wed Dec 1 15:52:41 2010 From: dinov at microsoft.com (Dino Viehland) Date: Wed, 1 Dec 2010 20:52:41 +0000 Subject: Packages at Python.org In-Reply-To: <084f9299-b2b3-440f-b83f-9fbe42220221@j19g2000prh.googlegroups.com> References: <084f9299-b2b3-440f-b83f-9fbe42220221@j19g2000prh.googlegroups.com> Message-ID: <6C7ABA8B4E309440B857D74348836F2EFDD778@TK5EX14MBXC135.redmond.corp.microsoft.com> Kirby wrote: > ** Unconfirmed rumors about IronPython leave me blog searching this > afternoon. Still part of Codeplex? IronPython is still using CodePlex for bug tracking and posting releases but active development is now on GitHub w/ a Mercurial mirror. Jeff's blog has more info: http://jdhardy.blogspot.com/ From kirby.urner at gmail.com Wed Dec 1 15:56:59 2010 From: kirby.urner at gmail.com (kirby.urner at gmail.com) Date: Wed, 1 Dec 2010 12:56:59 -0800 (PST) Subject: Packages at Python.org References: <084f9299-b2b3-440f-b83f-9fbe42220221@j19g2000prh.googlegroups.com> Message-ID: > http://packages.python.org/dbf/ > > So how *do* you get source code from such a web place? ?I'm not > finding > a tar ball or installer. ?Sorry if I'm missing something obvious, like > a link > to Sourceforge. > Thanks to very quick replies with pointers to http://pypi.python.org/pypi/dbf/ instead of to packages.python.org/dbf So this packages.python.org subdomain is perhaps unaware of its pypi.python.org competition, which has a brighter and more open look and feel? What's the story there I wonder? Quite an archeology (reminds me of the Vaults of Parnassus). Thanks again, for restoring me to productivity (was dead in the water for a minute there). Kirby From clp2 at rebertia.com Wed Dec 1 16:07:37 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 1 Dec 2010 13:07:37 -0800 Subject: Packages at Python.org In-Reply-To: References: <084f9299-b2b3-440f-b83f-9fbe42220221@j19g2000prh.googlegroups.com> Message-ID: On Wed, Dec 1, 2010 at 12:56 PM, kirby.urner at gmail.com wrote: >> http://packages.python.org/dbf/ >> >> So how *do* you get source code from such a web place? ?I'm not >> finding >> a tar ball or installer. ?Sorry if I'm missing something obvious, like >> a link >> to Sourceforge. >> > > Thanks to very quick replies with pointers to > > http://pypi.python.org/pypi/dbf/ > > instead of to packages.python.org/dbf > > So this packages.python.org subdomain is perhaps > unaware of its pypi.python.org competition, which > has a brighter and more open look and feel? > > What's the story there I wonder? It's quite simple actually. http://packages.python.org/ : """ This site hosts documentation uploaded by authors of packages in the Python Package Index (http://pypi.python.org). """ One is the actual package index, the other holds docs for packages in the index. Cheers, Chris From robert.kern at gmail.com Wed Dec 1 16:11:52 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 01 Dec 2010 15:11:52 -0600 Subject: Packages at Python.org In-Reply-To: References: <084f9299-b2b3-440f-b83f-9fbe42220221@j19g2000prh.googlegroups.com> Message-ID: On 12/1/10 2:56 PM, kirby.urner at gmail.com wrote: > >> http://packages.python.org/dbf/ >> >> So how *do* you get source code from such a web place? I'm not >> finding >> a tar ball or installer. Sorry if I'm missing something obvious, like >> a link >> to Sourceforge. >> > > Thanks to very quick replies with pointers to > > http://pypi.python.org/pypi/dbf/ > > instead of to packages.python.org/dbf > > So this packages.python.org subdomain is perhaps > unaware of its pypi.python.org competition, which > has a brighter and more open look and feel? > > What's the story there I wonder? pypi.python.org is the Python Package Index (PyPI). packages.python.org is a service for packages on PyPI to host their documentation if they have no other host. They are complementary services, not competition. -- 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 joncle at googlemail.com Wed Dec 1 16:35:47 2010 From: joncle at googlemail.com (Jon Clements) Date: Wed, 1 Dec 2010 13:35:47 -0800 (PST) Subject: Packages at Python.org References: <084f9299-b2b3-440f-b83f-9fbe42220221@j19g2000prh.googlegroups.com> Message-ID: On Dec 1, 8:56?pm, "kirby.ur... at gmail.com" wrote: > >http://packages.python.org/dbf/ > > > So how *do* you get source code from such a web place? ?I'm not > > finding > > a tar ball or installer. ?Sorry if I'm missing something obvious, like > > a link > > to Sourceforge. > > Thanks to very quick replies with pointers to > > http://pypi.python.org/pypi/dbf/ > > instead of to packages.python.org/dbf [snip] > > Kirby I've only had a quick play with it, however, you may want to take a look at Dabo on http://dabodev.com/ Jon. From python at bdurham.com Wed Dec 1 16:55:32 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 01 Dec 2010 16:55:32 -0500 Subject: Packages at Python.org In-Reply-To: References: <084f9299-b2b3-440f-b83f-9fbe42220221@j19g2000prh.googlegroups.com> Message-ID: <1291240532.10840.1408171861@webmail.messagingengine.com> > You may want to take a look at Dabo > http://dabodev.com/ +1 Malcolm From eric.frederich at gmail.com Wed Dec 1 17:12:07 2010 From: eric.frederich at gmail.com (Eric Frederich) Date: Wed, 1 Dec 2010 17:12:07 -0500 Subject: multiple modules from single c extension Message-ID: I have an extension to some C library that I created using the guide found here... http://docs.python.org/extending/extending.html I am starting to have A LOT of functions being wrapped. The library that I'm creating bindings for is organized into modules. In fact, all of their function calls start with a prefix like ABC_do_something, XYZ_something_else. I'd like to start putting the bindings for each module into a separate C file and have each set of bindings end up in its own Python module as well. Is this possible to do using a single .dll / .pyd file so that I can use a single Visual Studio project for these bindings? Is it just a matter of initializing more than one module in the initspam function? PyMODINIT_FUNC initspam(void) { (void) Py_InitModule("spam", SpamMethods); // can I do this? (void) Py_InitModule("spam.ABC", SpamABCMethods); } Would this even work? How would I get a hold of SpamABCMethods now that its in a different file? I tried creating a .h file for the ABC functions which had the prototypes defined as well as the static PyMethodDef SpamABCMethods[] array. This way I could include SpamABC.h which had the array. When I try doing that though, I get link errors saying things like functions are declared but not defined. The example online has everything in a single C file. If I split things up into a .h and a .c file... what should be declared as staic?, should anything be declared as extern? This is where I'm stuck. Thanks, ~Eric From steve+comp.lang.python at pearwood.info Wed Dec 1 17:26:40 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Dec 2010 22:26:40 GMT Subject: Change one list item in place References: <17175f49-087f-4d05-ada2-7e8c7e7e86dd@z17g2000prz.googlegroups.com> Message-ID: <4cf6cba0$0$30003$c3e8da3$5496439d@news.astraweb.com> On Wed, 01 Dec 2010 05:33:55 -0800, Gnarlodious wrote: > Thanks for all the ideas, I've resigned myself to unpacking a tuple and > reassembling it. You make it sound like that's an onerous task. -- Steven From ethan at stoneleaf.us Wed Dec 1 17:32:23 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 01 Dec 2010 14:32:23 -0800 Subject: Packages at Python.org In-Reply-To: <084f9299-b2b3-440f-b83f-9fbe42220221@j19g2000prh.googlegroups.com> References: <084f9299-b2b3-440f-b83f-9fbe42220221@j19g2000prh.googlegroups.com> Message-ID: <4CF6CCF7.3000304@stoneleaf.us> kirby.urner at gmail.com wrote: > > With Microsoft abandoning Visual FoxPro come 2015, we have 100K > developers > jumping ship (rough guess), perhaps to dot NET, but not necessarily.** > > This page is potentially getting a lot of hits (I'm not privy to the > analytics): > > http://packages.python.org/dbf/ The dbf package does not yet support index files. Normal indexes won't be too hard to add in, but I have been unable to find the algorithms used to create/work with compact index files. Does anybody know where I might find those? ~Ethan~ (author of said package) From nobody at nowhere.com Wed Dec 1 17:45:53 2010 From: nobody at nowhere.com (Nobody) Date: Wed, 01 Dec 2010 22:45:53 +0000 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename References: <1291124813.414884.22.camel@WOPR> Message-ID: On Wed, 01 Dec 2010 10:34:24 +0100, Peter Otten wrote: >> Python 3.x's decision to treat filenames (and environment variables) as >> text even on Unix is, in short, a bug. One which, IMNSHO, will mean that >> Python 2.x is still around when Python 4 is released. > > For filenames in Python 3 the user has the choice between "text" (str) and > bytes. If the user chooses text that will be converted to bytes using a > default encoding that hopefully matches that of the other tools on the > machine that manipulate filenames. However, sys.argv and os.environ are automatically converted to text. If you want bytes, you have to convert them back explicitly. Also, I'm unsure as to how far the choice between bytes and str will extend beyond the core modules. > I see that you may run into problems with the text approach when you > encounter byte sequences that are illegal in the chosen encoding. This was actually a critical flaw in Python 3.0, as it meant that filenames which weren't valid in the locale's encoding simply couldn't be passed via argv or environ. 3.1 fixed this using the "surrogateescape" encoding, so now it's only an annoyance (i.e. you can recover the original bytes once you've spent enough time digging through the documentation). There could be a problem with encodings which aren't invertable (e.g. ISO-2022), but those tend to be quite rare and Python flat-out doesn't support those as system encodings anyhow. From joncle at googlemail.com Wed Dec 1 17:51:21 2010 From: joncle at googlemail.com (Jon Clements) Date: Wed, 1 Dec 2010 14:51:21 -0800 (PST) Subject: Packages at Python.org References: <084f9299-b2b3-440f-b83f-9fbe42220221@j19g2000prh.googlegroups.com> Message-ID: On Dec 1, 10:32?pm, Ethan Furman wrote: > kirby.ur... at gmail.com wrote: > > > With Microsoft abandoning Visual FoxPro come 2015, we have 100K > > developers > > jumping ship (rough guess), perhaps to dot NET, but not necessarily.** > > > This page is potentially getting a lot of hits (I'm not privy to the > > analytics): > > >http://packages.python.org/dbf/ > > The dbf package does not yet support index files. ?Normal indexes won't > be too hard to add in, but I have been unable to find the algorithms > used to create/work with compact index files. > > Does anybody know where I might find those? > > ~Ethan~ ?(author of said package) I think John Machin has done work on this, or at least mentioned it in a post somewhere. I could be wrong though - apologies to both you and John, if I'm imagining things. Jon. From lambdadmitry at gmail.com Wed Dec 1 18:18:32 2010 From: lambdadmitry at gmail.com (Dmitry Groshev) Date: Wed, 1 Dec 2010 15:18:32 -0800 (PST) Subject: Some syntactic sugar proposals References: <1290424902.6446.5.camel@laptop> Message-ID: On Nov 22, 2:21?pm, Andreas L?scher wrote: > > ? ? if x in range(a, b): #wrong! > > it feels so natural to check it that way, but we have to write > > ? ? if a <= x <= b > > I understand that it's not a big deal, but it would be awesome to have > > some optimisations - it's clearly possible to detect things like that > > "wrong" one and fix it in a bytecode. > > You can implement it yourself: > > class between(object): > ? ? ? ? def __init__(self, a,b): > ? ? ? ? ? ? ? ? super(crang, self).__init__() > ? ? ? ? ? ? ? ? self.a=a > ? ? ? ? ? ? ? ? self.b=b > ? ? ? ? def __contains__(self, value): > ? ? ? ? ? ? ? ? return self.a <= value <= self.b > > >>> 12.45 in between(-100,100) > > true > > But do you need > > a < ?x < ?b > a <= x < ?b > a <= x <= b or > a < ?x <= b ? > > Sure, you could set a new parameter for this, but the normal way is not > broken at all. > > Best Of course there are better ways to do this. Your "between", standart comparisons and so, but expressing this as "i in range(a, b)" is just intuitive and declarative. Here is a fresh example of what I meant by my first proposal. You need to build a matrix like this: 2 1 0 ... 1 2 1 ... 0 1 2 ... ... ... 1 2 1 ... 0 1 2 You could do this by one-liner: [[(2 - abs(x - y)) if it > 0 else 0 for x in xrange(8)] for y in xrange(8)] ...but in reality you should write something like this: [[(lambda t: t if t > 0 else 0)(2 - abs(x - y)) for x in xrange(8)] for y in xrange(8)] or this [[(2 - abs(x - y)) if (2 - abs(x - y)) > 0 else 0 for x in xrange(8)] for y in xrange(8)] or even this def foo(x, y): if abs(x - y) == 0: return 2 elif abs(x - y) == 1: return 1 else: return 0 [[foo(x, y) for x in xrange(8)] for y in xrange(8)] It's not THAT matter, but it's just about readability and shortness in some cases. From cdalten at gmail.com Wed Dec 1 19:45:34 2010 From: cdalten at gmail.com (chad) Date: Wed, 1 Dec 2010 16:45:34 -0800 (PST) Subject: I can't seem to change the timeout value on pexpect Message-ID: <0387d0dd-9af5-49e6-a0c2-159f016fd319@r31g2000prg.googlegroups.com> I tried to change the timeout value from 30 to 90 for pexpect in the following script... #!/usr/bin/python import telnetlib import time import pexpect def get_name(): user = raw_input("\nUsername: ") password = raw_input("Password: ") idle(user, password) def idle(user, password): child = pexpect.spawn('telnet game.mortalrealms.com 4321') child.expect("Who art thou:", timeout=90) child.sendline(user) print "\nEntered username.." child.expect("Password:",timeout=90) child.sendline(password) print "Entered pass.." child.expect('Press return to continue:', timeout=90) child.sendline('\n') if child == 2: print "Connection timeout" elif child == 3: print "Another timeout" #while 1: child.expect('Druidess Supi burps loudly.') child.sendline('say oh my aching back') #time.sleep(15) #time.sleep(5) #now.write("\n") #while 1: # now.write("wc") # time.sleep(15) if __name__ == "__main__": get_name() However, when I run it, the timeout still shows 30 seconds... Entered username.. Entered pass.. TrFAvAvaricest): File "./mort.py", line 42, in ? FAvAvarice File "./mort.py", line 10, in get_name idle(user, password) File "./mort.py", line 31, in idle child.expect('Druidess Supi burps loudly.') File "/usr/lib/python2.4/site-packages/pexpect.py", line 1311, in expect return self.expect_list(compiled_pattern_list, timeout, searchwindowsize) File "/usr/lib/python2.4/site-packages/pexpect.py", line 1325, in expect_list return self.expect_loop(searcher_re(pattern_list), timeout, searchwindowsize) File "/usr/lib/python2.4/site-packages/pexpect.py", line 1409, in expect_loop raise TIMEOUT (str(e) + '\n' + str(self)) pexpect.TIMEOUT: Timeout exceeded in read_nonblocking(). version: 2.3 ($Revision: 399 $) command: /usr/kerberos/bin/telnet args: ['/usr/kerberos/bin/telnet', 'game.mortalrealms.com', '4321'] searcher: searcher_re: 0: re.compile("Druidess Supi burps loudly.") buffer (last 100 chars): all. before (last 100 chars): all. after: pexpect.TIMEOUT match: None match_index: None exitstatus: None flag_eof: False pid: 23652 child_fd: 3 closed: False timeout: 30 delimiter: pexpect.EOF logfile: None logfile_read: None logfile_send: None maxread: 2000 ignorecase: False searchwindowsize: None delaybeforesend: 0.05 delayafterclose: 0.1 delayafterterminate: 0.1 What am I doing wrong? From dmlb2000 at gmail.com Wed Dec 1 19:49:30 2010 From: dmlb2000 at gmail.com (David Brown) Date: Wed, 1 Dec 2010 16:49:30 -0800 Subject: odd runtime error Message-ID: So I'm not subscribed to python-list but would like to get an answer to my question. I've made a small test program that dumps a RuntimeError and I'd like to know why. $ python test2.py doing stuff Traceback (most recent call last): File "test2.py", line 3, in import test RuntimeError: not holding the import lock child 3693 exited with 256 $ Here's the setup, there's two files test.py and test2.py $ cat test.py #!/usr/bin/python import os, sys if os.fork() == 0: print "doing stuff" sys.exit() print "child %d exited with %d" % os.wait() $ cat test2.py #!/usr/bin/python import test $ I understand that sys.exit() is really just doing a `raise SystemExit(0)' and the RuntimeError shows up with that as well. If you change out sys.exit with os._exit(0) then it doesn't show dump the RuntimeError. Also, this seems to be a python2.6 and python2.7 issue. Python3 doesn't have this issue. I haven't checked with python2.5 or before yet. I was more curious about what this behavior is and why python is doing things this way. I've scoured the python documentation and can't seem to figure out why. Thanks, - David Brown From clp2 at rebertia.com Wed Dec 1 19:59:19 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 1 Dec 2010 16:59:19 -0800 Subject: odd runtime error In-Reply-To: References: Message-ID: On Wed, Dec 1, 2010 at 4:49 PM, David Brown wrote: > So I'm not subscribed to python-list but would like to get an answer > to my question. I've made a small test program that dumps a > RuntimeError and I'd like to know why. > > $ python test2.py > doing stuff > Traceback (most recent call last): > ?File "test2.py", line 3, in > ? ?import test > RuntimeError: not holding the import lock > child 3693 exited with 256 > $ > > Here's the setup, there's two files test.py and test2.py > > $ cat test.py > #!/usr/bin/python > > import os, sys > > if os.fork() == 0: > ? ? ? ?print "doing stuff" > ? ? ? ?sys.exit() > > print "child %d exited with %d" % os.wait() It's *quite* strange for a module that's being imported to execute a fork() in its body; this is almost assuredly the cause of the RuntimeError. Why are you fork()ing in an importable module in the first place? Cheers, Chris -- http://blog.rebertia.com From dmlb2000 at gmail.com Wed Dec 1 20:04:33 2010 From: dmlb2000 at gmail.com (David Brown) Date: Wed, 1 Dec 2010 17:04:33 -0800 Subject: odd runtime error In-Reply-To: References: Message-ID: On Wed, Dec 1, 2010 at 4:59 PM, Chris Rebert wrote: > On Wed, Dec 1, 2010 at 4:49 PM, David Brown wrote: >> So I'm not subscribed to python-list but would like to get an answer >> to my question. I've made a small test program that dumps a >> RuntimeError and I'd like to know why. >> >> $ python test2.py >> doing stuff >> Traceback (most recent call last): >> ?File "test2.py", line 3, in >> ? ?import test >> RuntimeError: not holding the import lock >> child 3693 exited with 256 >> $ >> >> Here's the setup, there's two files test.py and test2.py >> >> $ cat test.py >> #!/usr/bin/python >> >> import os, sys >> >> if os.fork() == 0: >> ? ? ? ?print "doing stuff" >> ? ? ? ?sys.exit() >> >> print "child %d exited with %d" % os.wait() > > It's *quite* strange for a module that's being imported to execute a > fork() in its body; this is almost assuredly the cause of the > RuntimeError. Why are you fork()ing in an importable module in the > first place? Well, to be specific the fork isn't the cause of the RuntimeError, the sys.exit() causes the runtime error. I agree that forking in a module is bad coding practice and I'm working with the developer to help him understand why that's bad. If that makes sense. However, knowing why sys.exit() is producing a RuntimeError on some versions of python and not others also more interesting a question. Thanks, - David Brown > Cheers, > Chris > -- > http://blog.rebertia.com > From prologic at shortcircuit.net.au Wed Dec 1 20:12:17 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 2 Dec 2010 11:12:17 +1000 Subject: odd runtime error In-Reply-To: References: Message-ID: On Thu, Dec 2, 2010 at 10:59 AM, Chris Rebert wrote: > On Wed, Dec 1, 2010 at 4:49 PM, David Brown wrote: >> So I'm not subscribed to python-list but would like to get an answer >> to my question. I've made a small test program that dumps a >> RuntimeError and I'd like to know why. >> >> $ python test2.py >> doing stuff >> Traceback (most recent call last): >> ?File "test2.py", line 3, in >> ? ?import test >> RuntimeError: not holding the import lock >> child 3693 exited with 256 >> $ >> >> Here's the setup, there's two files test.py and test2.py >> >> $ cat test.py >> #!/usr/bin/python >> >> import os, sys >> >> if os.fork() == 0: >> ? ? ? ?print "doing stuff" >> ? ? ? ?sys.exit() >> >> print "child %d exited with %d" % os.wait() Assuming you actually want to fork and do something inside the forked child process, the correct implementation is this: $ cat test.py #!/usr/bin/env python import os from time import sleep def main(): print "parent %d started" % os.getpid() if os.fork() == 0: print "doing stuff" sleep(5) print "done" raise SystemExit, 0 print "child %d exited with %d" % os.wait() if __name__ == "__main__": main() cheers James -- -- James Mills -- -- "Problems are solved by method" From cs at zip.com.au Wed Dec 1 20:19:05 2010 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 2 Dec 2010 12:19:05 +1100 Subject: odd runtime error In-Reply-To: References: Message-ID: <20101202011905.GA14396@cskk.homeip.net> On 01Dec2010 16:49, David Brown wrote: | So I'm not subscribed to python-list but would like to get an answer | to my question. I've made a small test program that dumps a | RuntimeError and I'd like to know why. | | $ python test2.py | doing stuff | Traceback (most recent call last): | File "test2.py", line 3, in | import test | RuntimeError: not holding the import lock | child 3693 exited with 256 | $ | | Here's the setup, there's two files test.py and test2.py | | $ cat test.py | #!/usr/bin/python | | import os, sys | | if os.fork() == 0: | print "doing stuff" | sys.exit() | | print "child %d exited with %d" % os.wait() | $ cat test2.py | #!/usr/bin/python | | import test | $ | | I understand that sys.exit() is really just doing a `raise | SystemExit(0)' and the RuntimeError shows up with that as well. If you | change out sys.exit with os._exit(0) then it doesn't show dump the | RuntimeError. Also, this seems to be a python2.6 and python2.7 issue. | Python3 doesn't have this issue. I haven't checked with python2.5 or | before yet. | | I was more curious about what this behavior is and why python is doing | things this way. I've scoured the python documentation and can't seem | to figure out why. So, test2.py imports "test", which is in "test.py". And the test module forks _during_ the import. Python takes a lock during imports - this stops multiple threads from importing the same module at the same time (avoiding multiple instantiation etc) and other racy fribbing with the in-memory module data structures. So: import test test.py... fork... At this point two programs exist, each in the midst of the import of test.py. It would seem the import lock breaks over the fork, so that the child process doesn't hold the lock. But because it is a fork, it does not know this! (Being identical to its parent.) So you raise SystemExit, and during the stack unwind the child tries to release the lock. Which it doesn't have, thus the breakage. Does that clarify the sequence of events? -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ "I think not," said Descartes, and promptly disappeared. From dmlb2000 at gmail.com Wed Dec 1 20:27:05 2010 From: dmlb2000 at gmail.com (David Brown) Date: Wed, 1 Dec 2010 17:27:05 -0800 Subject: odd runtime error In-Reply-To: <20101202011905.GA14396@cskk.homeip.net> References: <20101202011905.GA14396@cskk.homeip.net> Message-ID: On Wed, Dec 1, 2010 at 5:19 PM, Cameron Simpson wrote: > On 01Dec2010 16:49, David Brown wrote: > | So I'm not subscribed to python-list but would like to get an answer > | to my question. I've made a small test program that dumps a > | RuntimeError and I'd like to know why. > | > | $ python test2.py > | doing stuff > | Traceback (most recent call last): > | ? File "test2.py", line 3, in > | ? ? import test > | RuntimeError: not holding the import lock > | child 3693 exited with 256 > | $ > | > | Here's the setup, there's two files test.py and test2.py > | > | $ cat test.py > | #!/usr/bin/python > | > | import os, sys > | > | if os.fork() == 0: > | ? ? ? print "doing stuff" > | ? ? ? sys.exit() > | > | print "child %d exited with %d" % os.wait() > | $ cat test2.py > | #!/usr/bin/python > | > | import test > | $ > | > | I understand that sys.exit() is really just doing a `raise > | SystemExit(0)' and the RuntimeError shows up with that as well. If you > | change out sys.exit with os._exit(0) then it doesn't show dump the > | RuntimeError. Also, this seems to be a python2.6 and python2.7 issue. > | Python3 doesn't have this issue. I haven't checked with python2.5 or > | before yet. > | > | I was more curious about what this behavior is and why python is doing > | things this way. I've scoured the python documentation and can't seem > | to figure out why. > > So, test2.py imports "test", which is in "test.py". > And the test module forks _during_ the import. > > Python takes a lock during imports - this stops multiple threads > from importing the same module at the same time (avoiding multiple > instantiation etc) and other racy fribbing with the in-memory module > data structures. > > So: > ?import test > ? ?test.py... > ? ? ?fork... > > At this point two programs exist, each in the midst of the import of > test.py. It would seem the import lock breaks over the fork, so that the > child process doesn't hold the lock. But because it is a fork, it does > not know this! (Being identical to its parent.) So you raise SystemExit, > and during the stack unwind the child tries to release the lock. Which > it doesn't have, thus the breakage. > > Does that clarify the sequence of events? Thanks for the clarification I like the idea of wrapping all the primary code in the script to a main function then calling it if its being called by main. I think I got a better handle on things. Thanks, - David Brown > Cameron Simpson DoD#743 > http://www.cskk.ezoshosting.com/cs/ > > "I think not," said Descartes, and promptly disappeared. > From robert.kern at gmail.com Wed Dec 1 20:39:14 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 01 Dec 2010 19:39:14 -0600 Subject: multiple modules from single c extension In-Reply-To: References: Message-ID: On 12/1/10 4:12 PM, Eric Frederich wrote: > I have an extension to some C library that I created using the guide > found here... > > http://docs.python.org/extending/extending.html > > I am starting to have A LOT of functions being wrapped. > > The library that I'm creating bindings for is organized into modules. > In fact, all of their function calls start with a prefix like > ABC_do_something, XYZ_something_else. > > I'd like to start putting the bindings for each module into a separate > C file and have each set of bindings end up in its own Python module > as well. > > Is this possible to do using a single .dll / .pyd file so that I can > use a single Visual Studio project for these bindings? No, I don't think so. The Python import mechanism will be looking for an appropriately-named .pyd file for each module. In any case, you shouldn't be using Visual Studio directly to build the .pyd. Instead, use distutils. -- 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 kirby.urner at gmail.com Wed Dec 1 21:29:01 2010 From: kirby.urner at gmail.com (kirby urner) Date: Wed, 1 Dec 2010 18:29:01 -0800 Subject: Packages at Python.org In-Reply-To: <4CF6CCF7.3000304@stoneleaf.us> References: <084f9299-b2b3-440f-b83f-9fbe42220221@j19g2000prh.googlegroups.com> <4CF6CCF7.3000304@stoneleaf.us> Message-ID: Good to hear from you sir. I've enjoying working with your modules and am getting some good results. I sent you a note off-list wondering how actively you might be supporting this valuable utility. Encouraging to find you here so quickly. Kirby On Wed, Dec 1, 2010 at 2:32 PM, Ethan Furman wrote: > kirby.urner at gmail.com wrote: > >> >> With Microsoft abandoning Visual FoxPro come 2015, we have 100K >> developers >> jumping ship (rough guess), perhaps to dot NET, but not necessarily.** >> >> This page is potentially getting a lot of hits (I'm not privy to the >> analytics): >> >> http://packages.python.org/dbf/ >> > > The dbf package does not yet support index files. Normal indexes won't be > too hard to add in, but I have been unable to find the algorithms used to > create/work with compact index files. > > Does anybody know where I might find those? > > ~Ethan~ (author of said package) > -------------- next part -------------- An HTML attachment was scrubbed... URL: From hugh.seckerwalker at gmail.com Wed Dec 1 21:49:28 2010 From: hugh.seckerwalker at gmail.com (HughSW) Date: Wed, 1 Dec 2010 18:49:28 -0800 (PST) Subject: docstring inheritance Message-ID: <0037b3b8-36f7-4568-a5a6-22020e7e5b2d@a17g2000yql.googlegroups.com> We've been trying to find an easy way to inherit docstrings when overriding methods in subclasses, e.g. so that Sphinx does a nice job. We used Shai's DocInherit code from this post: http://groups.google.com/group/comp.lang.python/tree/browse_frm/thread/1e4075ba10dcbdd9/f63651cd9e76df63?rnum=1&_done=%2Fgroup%2Fcomp.lang.python%2Fbrowse_frm%2Fthread%2F1e4075ba10dcbdd9%2F%3F#doc_5f5963372b951d79 of this thread http://groups.google.com/group/comp.lang.python/browse_frm/thread/1e4075ba10dcbdd9/ The DocInherit property works fine, except that all the logic for adding the docstring to the method is evaluated every single time the method is looked up. I experimented with a simple caching scheme but abandoned it. I've tried a new approach -- it uses the same property mechanism as Shai's code to delay doing anything until the class exists and the method is used -- but it does its work only once, the first time the method is looked up; it adds the docstring from the first mro parent, and then the property *replaces itself* in the class's namespace with the method that now has a docstring. It appears to work in a large project with extensive testing. My question concerns whether it is risky to replace a class property attribute to a method attribute after the class has been created, and perhaps after the class has been used? Does this kind of change violate some subtle or internal expectations of the interpreter runtime? Thanks. -Hugh Here's the code and doctests: class InheritDoc(object): """ Docstring inheriting method descriptor The class itself is used as a decorator that creates a class property for the method; the first time the property is used it installs the method's doc and then replaces itself as a class attribute with the method! Usage: >>> class Foo(object): ... def foo(self, x): ... 'Frobber' ... print 'Foo.foo()', x Correct usage for overridden method foo(), incorrect usage for method bar() >>> class Bar(Foo): ... @inherit_doc ... def foo(self, x): ... print 'Bar.foo()', x ... @inherit_doc ... def bar(self): ... print 'Bar.bar()' >>> Bar.foo.__doc__ == Bar().foo.__doc__ == Foo.foo.__doc__ == 'Frobber' True >>> Foo.foo >>> Foo().foo(10) Foo.foo() 10 >>> Bar.foo >>> Bar().foo(11) Bar.foo() 11 >>> Bar.bar Traceback (most recent call last): ... NameError: inherit_doc cannot find method 'bar' in parents of '__main__.Bar' >>> Bar().bar Traceback (most recent call last): ... NameError: inherit_doc cannot find method 'bar' in parents of '__main__.Bar' """ __slots__ = 'inherit_doc_unbound_method' def __init__(self, unbound_method): self.inherit_doc_unbound_method = unbound_method def __get__(self, obj, cls): # a self-destructing descriptor/ property: # the first and only time it's used, it fixes the method's doc and then # replaces itself with the method # find the overridden method in mro sequence, skipping the class itself method_name = self.inherit_doc_unbound_method.__name__ mro_iter = iter(cls.__mro__) mro_iter.next() for parent in mro_iter: overridden = getattr(parent, method_name, None) if overridden is not None: break if overridden is None: raise NameError('inherit_doc cannot find method %r in parents of %r' % (method_name, '%s.%s'%(cls.__module__, cls.__name__))) # XXX next steps are not threadsafe, maybe not safe at all! # set the doc self.inherit_doc_unbound_method.__doc__ = overridden.__doc__ # replace the property with the function setattr(cls, method_name, self.inherit_doc_unbound_method) # use the replacement return getattr(obj if obj is not None else cls, method_name) inherit_doc = InheritDoc From hugh.seckerwalker at gmail.com Wed Dec 1 21:56:31 2010 From: hugh.seckerwalker at gmail.com (HughSW) Date: Wed, 1 Dec 2010 18:56:31 -0800 (PST) Subject: docstring inheritance References: <0037b3b8-36f7-4568-a5a6-22020e7e5b2d@a17g2000yql.googlegroups.com> Message-ID: Grrrr, sorry about the line wrapping horror; trying again. class InheritDoc(object): """ Docstring inheriting method descriptor The class itself is used as a decorator that creates a class property for the method; the first time the property is used it installs the method's doc and then replaces itself as a class attribute with the method! Usage: >>> class Foo(object): ... def foo(self, x): ... 'Frobber' ... print 'Foo.foo()', x Correct usage for overridden method foo(), incorrect usage for method bar() >>> class Bar(Foo): ... @inherit_doc ... def foo(self, x): ... print 'Bar.foo()', x ... @inherit_doc ... def bar(self): ... print 'Bar.bar()' >>> Bar.foo.__doc__ == Bar().foo.__doc__ == Foo.foo.__doc__ == 'Frobber' True >>> Foo.foo >>> Foo().foo(10) Foo.foo() 10 >>> Bar.foo >>> Bar().foo(11) Bar.foo() 11 >>> Bar.bar Traceback (most recent call last): ... NameError: inherit_doc cannot find method 'bar' in parents of '__main__.Bar' >>> Bar().bar Traceback (most recent call last): ... NameError: inherit_doc cannot find method 'bar' in parents of '__main__.Bar' """ __slots__ = 'inherit_doc_unbound_method' def __init__(self, unbound_method): self.inherit_doc_unbound_method = unbound_method def __get__(self, obj, cls): # a self-destructing descriptor/property: # the first and only time it's used, it fixes the method's doc and then # replaces itself with the method # find the overridden method in mro sequence, skipping the class itself method_name = self.inherit_doc_unbound_method.__name__ mro_iter = iter(cls.__mro__) mro_iter.next() for parent in mro_iter: overridden = getattr(parent, method_name, None) if overridden is not None: break if overridden is None: raise NameError('inherit_doc cannot find method %r in parents of %r' % (method_name, '%s.%s'%(cls.__module__, cls.__name__))) # XXX next steps are not threadsafe, maybe not safe at all! # set the doc self.inherit_doc_unbound_method.__doc__ = overridden.__doc__ # replace the property with the function setattr(cls, method_name, self.inherit_doc_unbound_method) # use the replacement return getattr(obj if obj is not None else cls, method_name) inherit_doc = InheritDoc From wallenpb at gmail.com Wed Dec 1 22:39:01 2010 From: wallenpb at gmail.com (Bill Allen) Date: Wed, 1 Dec 2010 21:39:01 -0600 Subject: Python's equivalent to Main calling program and subprograms In-Reply-To: References: <4CF67AF4.7040201@sequans.com> Message-ID: Thanks for the explanation of "main". Some tutorials mention it, some don't. I have written some not trial Python programs and have never had a real need to use that convention, but at least I understand it now. --Bill On Wed, Dec 1, 2010 at 1:13 PM, Tim Harig wrote: > > On Wed, Dec 1, 2010 at 9:08 AM, m b wrote: > >>> > if __name__ == "__main__": > >>> > main() > >> > >> What does this mean? > > It is a Python idiom and a good practice. Strictly speaking it is > unnecessary. Python doesn't recognize any functional initialization > vector other then the start of the file. When Python loads a module, > it executes anything it finds in the module scope (Anything not in the > body of a class or function declaration). Using a main function is just > a convention. You could just place all of your main level code in the > module scope: > > def Subprogram1(): > # code > def Subprogram2(): > # code > def Subprogram3(): > # code > > # main code > > or equivilantly, always execute main(): > > def Subprogram1(): > # code > def Subprogram2(): > # code > def Subprogram3(): > # code > def main(): > # main code > main() > > Both are valid from Python's point of view. > > The 'if __name__ == "__main__":' idiom is used, because it allows the > module to be loaded without running main(). This is useful if you wanted > to use Subprogram2() from another program. Even if you don't forsee using > any of the subprograms (functions to Python), this can be useful when > writing test code as you can import the program as a module to test its > classes or functions separately. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From cs at zip.com.au Wed Dec 1 23:16:43 2010 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 2 Dec 2010 15:16:43 +1100 Subject: odd runtime error In-Reply-To: References: Message-ID: <20101202041643.GA5381@cskk.homeip.net> On 01Dec2010 17:27, David Brown wrote: | Thanks for the clarification No worries. | I like the idea of wrapping all the | primary code in the script to a main function then calling it if its | being called by main. I find that useful too. I've got a few modules-that-implement-commands that look like this: def main(argv): ... parse args, do stuff ... return exit_status ... functions, classes etc ... if __name__ == '__main__': sys.exit(main(sys.argv)) It seems fairly effective for keeping the top level logic up the top. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ It's better, when you're riding with someone you don't know so well, to stick to the inside line - it's easier to avoid the bits... - Barry Sheene From jlconlin at gmail.com Thu Dec 2 00:36:32 2010 From: jlconlin at gmail.com (Jeremy) Date: Wed, 1 Dec 2010 21:36:32 -0800 (PST) Subject: How can I define class methods outside of the class? Message-ID: I have some methods that I need (would like) to define outside of the class. I know this can be done by defining the function and then setting it equal to some member of an instance of the class. But, because of the complexity of what I'm doing (I have to set many functions as class methods) I would rather not do this. Can someone show me how to do this? Is it even possible? Can decorators be used here? Thanks, Jeremy From prologic at shortcircuit.net.au Thu Dec 2 00:47:35 2010 From: prologic at shortcircuit.net.au (James Mills) Date: Thu, 2 Dec 2010 15:47:35 +1000 Subject: How can I define class methods outside of the class? In-Reply-To: References: Message-ID: On Thu, Dec 2, 2010 at 3:36 PM, Jeremy wrote: > I have some methods that I need (would like) to define outside of the > class. ?I know this can be done by defining the function and then > setting it equal to some member of an instance of the class. ?But, > because of the complexity of what I'm doing (I have to set many > functions as class methods) I would rather not do this. ?Can someone > show me how to do this? ?Is it even possible? ?Can decorators be used > here? Do you mean something like this ? @classmethod def foo(cls): print "I am the foo classmethod on %r" % cls class Foo(object): pass Foo.foo = foo cheers James -- -- James Mills -- -- "Problems are solved by method" From steve+comp.lang.python at pearwood.info Thu Dec 2 01:14:14 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 Dec 2010 06:14:14 GMT Subject: Some syntactic sugar proposals References: <1290424902.6446.5.camel@laptop> Message-ID: <4cf73935$0$30004$c3e8da3$5496439d@news.astraweb.com> On Wed, 01 Dec 2010 15:18:32 -0800, Dmitry Groshev wrote: > Here is a fresh example of what I meant by my first proposal. You need > to build a matrix like this: > 2 1 0 ... > 1 2 1 ... > 0 1 2 ... > ... > ... 1 2 1 > ... 0 1 2 > You could do this by one-liner: > [[(2 - abs(x - y)) if it > 0 else 0 for x in xrange(8)] for y in > xrange(8)] > ...but in reality you should write something like this: [[(lambda t: t > if t > 0 else 0)(2 - abs(x - y)) for x in xrange(8)] for y in xrange(8)] > or this > [[(2 - abs(x - y)) if (2 - abs(x - y)) > 0 else 0 for x in xrange(8)] > for y in xrange(8)] > or even this > def foo(x, y): > if abs(x - y) == 0: > return 2 > elif abs(x - y) == 1: > return 1 > else: > return 0 > [[foo(x, y) for x in xrange(8)] for y in xrange(8)] All those one-liners give me a headache. At least your "foo" solution is understandable. But I'd do it like this: >>> array = [[0]*8 for _ in range(8)] >>> for i in range(8): ... array[i][i] = 2 ... if i > 0: array[i][i-1] = 1 ... if i < 7: array[i][i+1] = 1 ... >>> pprint.pprint(array) [[2, 1, 0, 0, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0, 0, 0], [0, 1, 2, 1, 0, 0, 0, 0], [0, 0, 1, 2, 1, 0, 0, 0], [0, 0, 0, 1, 2, 1, 0, 0], [0, 0, 0, 0, 1, 2, 1, 0], [0, 0, 0, 0, 0, 1, 2, 1], [0, 0, 0, 0, 0, 0, 1, 2]] When you stop trying to make everything a one-liner, it's amazing how readable you can make code :) -- Steven From drsalists at gmail.com Thu Dec 2 01:14:19 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 1 Dec 2010 22:14:19 -0800 Subject: Unicode thing that causes a traceback in 2.6 and 2.7 but not in 2.5, and only when writing to a pipe, not to the terminal Message-ID: What is this about? It's another n~ thing, but this time in 2.x. All I'm doing is printing a str containing a character > 127. It works fine in 2.5, to a terminal or to a pipe. In 2.6 and 2.7, it fails when writing to a pipe but works fine writing to my terminal - an mrxvt.\ I really kind of want octets to just be octets, since I'm on a Linux system - it probably should be up to the user and their related software to decide how those octets are interpreted. I'm assuming that the bytes() workarounds I'm using in 3.x aren't going to work in 2.x - it looks like bytes() is just an alias for str() in 2.6 and 2.7. BTW, the print(line) in the traceback looks like Python 3 syntax, and it is I guess, but it's also Python 2 compatible. In 3.x, it's a function with a single argument, in 2.x it's a statement with a parenthesized expression. Thanks! benchbox-dstromberg:~/src/home-svn/readline0/trunk i686-pc-linux-gnu 17932 - above cmd done 2010 Wed Dec 01 09:40 PM $ find /usr/share/jpilot -print0 | /usr/local/cpython-2.5/bin/python ./test-readline0 2>&1 | cat /usr/share/jpilot /usr/share/jpilot/CalendarDB-PDat.pdb /usr/share/jpilot/Ma?anaDB.pdb /usr/share/jpilot/jpilotrc.green /usr/share/jpilot/jpilotrc.purple /usr/share/jpilot/ContactsDB-PAdd.pdb /usr/share/jpilot/MemoDB.pdb /usr/share/jpilot/jpilotrc.blue /usr/share/jpilot/ExpenseDB.pdb /usr/share/jpilot/jpilotrc.default /usr/share/jpilot/AddressDB.pdb /usr/share/jpilot/ToDoDB.pdb /usr/share/jpilot/TasksDB-PTod.pdb /usr/share/jpilot/DatebookDB.pdb /usr/share/jpilot/Memo32DB.pdb /usr/share/jpilot/MemosDB-PMem.pdb /usr/share/jpilot/jpilotrc.steel benchbox-dstromberg:~/src/home-svn/readline0/trunk i686-pc-linux-gnu 17932 - above cmd done 2010 Wed Dec 01 09:40 PM $ find /usr/share/jpilot -print0 | /usr/local/cpython-2.6/bin/python ./test-readline0 2>&1 | cat /usr/share/jpilot /usr/share/jpilot/CalendarDB-PDat.pdb Traceback (most recent call last): File "./test-readline0", line 22, in print(line) UnicodeEncodeError: 'ascii' codec can't encode character u'\xf1' in position 20: ordinal not in range(128) benchbox-dstromberg:~/src/home-svn/readline0/trunk i686-pc-linux-gnu 17932 - above cmd done 2010 Wed Dec 01 09:40 PM $ find /usr/share/jpilot -print0 | /usr/local/cpython-2.6/bin/python ./test-readline0 2>&1 /usr/share/jpilot /usr/share/jpilot/CalendarDB-PDat.pdb /usr/share/jpilot/Ma??anaDB.pdb /usr/share/jpilot/jpilotrc.green /usr/share/jpilot/jpilotrc.purple /usr/share/jpilot/ContactsDB-PAdd.pdb /usr/share/jpilot/MemoDB.pdb /usr/share/jpilot/jpilotrc.blue /usr/share/jpilot/ExpenseDB.pdb /usr/share/jpilot/jpilotrc.default /usr/share/jpilot/AddressDB.pdb /usr/share/jpilot/ToDoDB.pdb /usr/share/jpilot/TasksDB-PTod.pdb /usr/share/jpilot/DatebookDB.pdb /usr/share/jpilot/Memo32DB.pdb /usr/share/jpilot/MemosDB-PMem.pdb /usr/share/jpilot/jpilotrc.steel benchbox-dstromberg:~/src/home-svn/readline0/trunk i686-pc-linux-gnu 17932 - above cmd done 2010 Wed Dec 01 09:41 PM $ From kirby.urner at gmail.com Thu Dec 2 01:28:09 2010 From: kirby.urner at gmail.com (kirby.urner at gmail.com) Date: Wed, 1 Dec 2010 22:28:09 -0800 (PST) Subject: DBF (VFP) to XLS (Excel) in pure Python References: <084f9299-b2b3-440f-b83f-9fbe42220221@j19g2000prh.googlegroups.com> Message-ID: <5ddf7758-754f-4649-be1e-85cdee7860e5@y23g2000yqd.googlegroups.com> Playing around with arcane tools to read those pesky DBF files (with memo fields), like floating wine barrels cast off the sinking VFP ship. http://pypi.python.org/pypi/dbf http://packages.python.org/dbf/dbf-module.html Me threading on comp.lang.python: http://bit.ly/e547Za xlwt and xlrt for reading and writing Excel data, without needing Excel, are also making Python attractive Here's a code fragment giving the idea: from os import path from time import time import dbf def test2(): thepath = path.normpath(<< file path >>) thefile = "shiptemp.dbf" pathfile = path.join(thepath, thefile) thedbf = dbf.VfpTable(pathfile) header_style = easyxf('font: name Arial, bold True, height 200;') book = Workbook() sheet1 = book.add_sheet('Sheet 1') for (i, name) in enumerate(thedbf.field_names): sheet1.write(0, i, name, header_style) for (i, thecol) in enumerate(thedbf.structure()): name, thetype = str(thecol).split() thelen, thedec = 0,0 if "(" in thetype: if "," in thetype: thelen, thedec = [int(k) for k in thetype[2:-1].split(",")] else: thelen, thedec = int(thetype[2:-1]), 0 thetype = thetype[0] if thetype == "M": thelen = 100 elif thelen == 0: thelen = 1 colwidth = max(len(name), int(thelen)) # print colwidth sheet1.col(i).width = colwidth * 310 thedbf.top() messages = [] for row in range(1, len(thedbf)): record = thedbf.next() for col in range(len(thedbf.field_names)): try: sheet1.row(row).write(col, record[col]) except Exception: pass book.save("C:\\Documents and Settings\\HP_Administrator\\My Documents\\Visual FoxPro Projects\\shiptemp.xls") thedbf.close() if __name__ == "__main__": start = time() test2() end = time() print end - start At the moment I'm unable to get the 1500 record x 156 column table (with memos) to stay in memory even with the disk file closed, which I understand is a feature of this package http://pypi.python.org/pypi/dbf/ >>> thetable = dbf.VfpTable(thefile) >>> thetable[1] << data dump >> >>> thetable.close(keep_table=True, keep_memos=True) Traceback (most recent call last): File "", line 1, in thetable.close(keep_table=True, keep_memos=True) File "C:/Python26/Lib/site-packages\dbf\tables.py", line 1141, in close for record in yo: File "C:/Python26/Lib/site-packages\dbf\tables.py", line 676, in next record = yo._table[yo._index] File "C:/Python26/Lib/site-packages\dbf\tables.py", line 817, in __getitem__ return yo._table[yo._index[value]] File "C:/Python26/Lib/site-packages\dbf\tables.py", line 655, in __getitem__ yo._meta.dfd.seek(location) AttributeError: 'NoneType' object has no attribute 'seek' Same error with: >>> thetable = dbf.VfpTable(thefile) >>> thetable.close(keep_memos=True) Python 2.6 / Win7 Kirby From v.harishankar at gmail.com Thu Dec 2 02:28:30 2010 From: v.harishankar at gmail.com (Harishankar) Date: Thu, 2 Dec 2010 07:28:30 +0000 (UTC) Subject: Comparison with False - something I don't understand Message-ID: When I run pychecker through my modules I get the message that comparisons with "False" is not necessary and that it might yield unexpected results. Yet in some situations I need to specifically check whether False was returned or None was returned. Why is comparison with False so bad? # example code which matches both False and None if not var: # do something # specifically check if False is returned # I don't want None if var == False: # do something So how do you get around this? My functions return False and None under different circumstances. Should I raise exceptions instead? I feel it's unnecessary clutter to use exceptions unless absolutely no other solution is available and yet I have doubts about the "False" value. -- Harishankar (http://harishankar.org http://lawstudentscommunity.com) From ian.g.kelly at gmail.com Thu Dec 2 02:32:07 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 02 Dec 2010 00:32:07 -0700 Subject: How can I define class methods outside of the class? In-Reply-To: References: Message-ID: On 12/1/2010 10:47 PM, James Mills wrote: > On Thu, Dec 2, 2010 at 3:36 PM, Jeremy wrote: >> I have some methods that I need (would like) to define outside of the >> class. I know this can be done by defining the function and then >> setting it equal to some member of an instance of the class. But, >> because of the complexity of what I'm doing (I have to set many >> functions as class methods) I would rather not do this. Can someone >> show me how to do this? Is it even possible? Can decorators be used >> here? > > Do you mean something like this ? > > @classmethod > def foo(cls): > print "I am the foo classmethod on %r" % cls > > class Foo(object): > pass > > Foo.foo = foo Slightly better: def foo(cls): # Do something class Foo(object): pass Foo.foo = classmethod(foo) This way the unbound foo is callable as well. Cheers, Ian From alice at gothcandy.com Thu Dec 2 03:15:42 2010 From: alice at gothcandy.com (=?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=) Date: Thu, 2 Dec 2010 00:15:42 -0800 Subject: Comparison with False - something I don't understand References: Message-ID: Howdy! > When I run pychecker through my modules I get the message that > comparisons with "False" is not necessary and that it might yield > unexpected results. Comparisons against False -are- dangerous, demonstrated below. > Yet in some situations I need to specifically check whether False was > returned or None was returned. Why is comparison with False so bad? (False == 0) is True (True == 1) is True The bool type is a subclass of int! (Run those lines in a Python interpreter to see. ;) > if var == False: if var is False: ? > So how do you get around this? My functions return False and None under > different circumstances. Should I raise exceptions instead? I feel it's > unnecessary clutter to use exceptions unless absolutely no other > solution is available and yet I have doubts about the "False" value. If you want to check not just for value equivelance (False == 0) but literal type, use the "is" comparator. "is" checks, and others correct me if I'm wrong, the literal memory address of an object against another. E.g. False, being a singleton, will always have the same memory address. (This is true of CPython, possibly not of Python implementations like Jython or IronPython.) Using "is" will be effective for checking for literal None as well. When ever I need to test for None, I always use the "is" comparator. It's also more English-like. (None, evaluating to False when using '==', is useful when all you care about is having a blank default value, for example.) ? Alice. From eric.brunel at pragmadev.nospam.com Thu Dec 2 04:21:49 2010 From: eric.brunel at pragmadev.nospam.com (Eric Brunel) Date: Thu, 02 Dec 2010 10:21:49 +0100 Subject: Decorate un Frame with window managers title bar, etc en Tkinter 8.5 References: Message-ID: In article , craf wrote: > Hi. > > I use python 3.1 and Tkinter 8.5 in Ubuntu 9.10 > > I would like to turn a frame into a toolbox, > ,and for that I read that you can use the command wm manage (window) > > The information can be found at: > http://www.tcl.tk/man/tcl8.5/TkCmd/wm.htm#M39 > > the explanation says: > > wm manage widget: > The widget specified will become a stand alone top-level window. > The window will be decorated with the window managers title bar, > etc. Only frame, labelframe and toplevel widgets can be used > with this command. Attempting to pass any other widget type will > raise an error. Attempting to manage a toplevel widget is benign > and achieves nothing. See also GEOMETRY MANAGEMENT. > > I have tried to use it in Tkinter but I can not know how is its > structure. > > In Tkinter should be: > > ---TEST CODE------------------- > > from Tkinter import > > master = Tk() > frame = Frame(master) > wm_manager(Frame) > master.mainloop() > > -------------------------------- > > But this does not work. If your version of Tkinter supports it, then the correct syntax is: frame.wm_manage() Please note you have to call it on the Frame instance (the one you named frame), and not on Frame with a big F which is the class. If it says the method doesn't exist (AttributeError raised on the line frame.wm_manage()), you can also try to do it at tcl/tk level with the line: master.tk.call('wm', 'manage', frame) > I appreciate any of this item HTH - Eric - From nobody at nowhere.com Thu Dec 2 04:58:18 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 02 Dec 2010 09:58:18 +0000 Subject: Comparison with False - something I don't understand References: Message-ID: On Thu, 02 Dec 2010 07:28:30 +0000, Harishankar wrote: > When I run pychecker through my modules I get the message that > comparisons with "False" is not necessary and that it might yield > unexpected results. > > Yet in some situations I need to specifically check whether False was > returned or None was returned. Why is comparison with False so bad? The behaviour may be counterintuitive. One might expect that "x == False" is equivalent to "not x". Sometimes it is, sometimes it isn't. E.g. 0 and 0.0 are equal to False and are equivalent to False when converted to booleans: > 0 == False True > not 0 True > 0.0 == False True > not 0.0 True [], "" and None aren't equal to False but are equivalent to False when converted to booleans: > [] == False False > not [] True > "" == False False > not "" True > None == False False > not None True The boolean conversions are what's relevant for "if x ...", "while x ...", etc. If you want to test specifically for True, False or None, use "is" rather than an equality check. This eliminates the warning and doesn't risk misleading someone reading the code. From v.harishankar at gmail.com Thu Dec 2 05:02:03 2010 From: v.harishankar at gmail.com (Harishankar) Date: Thu, 2 Dec 2010 10:02:03 +0000 (UTC) Subject: Comparison with False - something I don't understand References: Message-ID: On Thu, 02 Dec 2010 00:15:42 -0800, Alice Bevan?McGregor wrote: > Howdy! Good day to you! > (False == 0) is True > (True == 1) is True I see. Thanks for this. I suspected this, but wasn't sure. > The bool type is a subclass of int! (Run those lines in a Python > interpreter to see. ;) > >> if var == False: > > if var is False: ? So "var is False" is safer to use when I want to specifically check whether var is set to False and not 0 or None? > If you want to check not just for value equivelance (False == 0) but > literal type, use the "is" comparator. "is" checks, and others correct > me if I'm wrong, the literal memory address of an object against > another. E.g. False, being a singleton, will always have the same > memory address. (This is true of CPython, possibly not of Python > implementations like Jython or IronPython.) Using "is" will be > effective for checking for literal None as well. Thanks, it makes sense to me now. Literal equivalence is what I was looking for. I didn't quite understand whether == achieved this or not. Now I guess I know. > > When ever I need to test for None, I always use the "is" comparator. > It's also more English-like. (None, evaluating to False when using > '==', is useful when all you care about is having a blank default value, > for example.) Yes, but in my function I don't want to confuse False with 0 or anything else except False. Thanks again for explaining this clearly. -- Harishankar (http://harishankar.org http://lawstudentscommunity.com) From v.harishankar at gmail.com Thu Dec 2 05:04:11 2010 From: v.harishankar at gmail.com (Harishankar) Date: Thu, 2 Dec 2010 10:04:11 +0000 (UTC) Subject: Comparison with False - something I don't understand References: Message-ID: On Thu, 02 Dec 2010 09:58:18 +0000, Nobody wrote: > If you want to test specifically for True, False or None, use "is" > rather than an equality check. This eliminates the warning and doesn't > risk misleading someone reading the code. Thanks so much for this very specific answer. I guess "is" is what I am looking for. :-) -- Harishankar (http://harishankar.org http://lawstudentscommunity.com) From me+list/python at ixokai.io Thu Dec 2 05:49:50 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 02 Dec 2010 02:49:50 -0800 Subject: Comparison with False - something I don't understand In-Reply-To: References: Message-ID: <4CF779CE.3040209@ixokai.io> On 12/2/10 2:02 AM, Harishankar wrote: > On Thu, 02 Dec 2010 00:15:42 -0800, Alice Bevan?McGregor wrote: >> The bool type is a subclass of int! (Run those lines in a Python >> interpreter to see. ;) >> >>> if var == False: >> >> if var is False: ? > > So "var is False" is safer to use when I want to specifically check > whether var is set to False and not 0 or None? Equality is a somewhat fuzzy concept. By convention and habit, its usually fine and clear: but its still fuzzy and up to each individual object involved to answer the question of equality. Now, its generally suggested in Python to do fairly vague truth testing: "if x" and "if not x" as opposed to concepts like "if x == True" and "if x == False" because the former is broad but usually more correct, and the latter can lead to some unexpected semantics. But that doesn't mean you must never check if something is False or True: there are times when you really do want or need to see if _False_ is what's being returned, or _True_, or _None_. In this case, use "is", yes, indeed. The "is" operator checks absolute object identity, and so is how you should do that check in cases where you want to test the distinction between "Is it /False/, or just something false-ish or not-true or nothing-ish?" Generally speaking in Python, you usually want to do tests as "if x" or "if not x". But sometimes you need to know if "x" is a specific singleton value: True, False or None. In that case, its okay to do "if x is True", "if x is False" or "if x is None". But you should only do that after the simple test is deemed inappropriate in your API or situation. And-- here's the rub-- while "is" is absolutely OK and right for you to use to test if an object is one of those singletons, its *probably* NOT what you want to do in any other situation*. Outside of the True/False/None singletons, and places where you're doing some special OOP-stuff, you almost certainly don't want to use 'is', but use equality checking (even if its fuzzy, because its fuzzy) instead. This demonstrates why "is" should be avoided except when in those singleton situations (except when you need to, of course): >>> a = 2 >>> b = 2 >>> a is b True >>> a == b True >>> a = 20000 >>> b = 20000 >>> a is b False >>> a == b True (If you're wondering why that's happening: Python makes very little in the way of promises with regard to object identity. It may choose to make a whole new int object of value 2 every time you type 2, or use the same old int object each time: sure, presently it tends to only share "small" integers for re-use, but that's not a promise, not a documented feature, but a function of the current implementation. It could happen tomorrow, in theory, that where a = 10000; b = 10000; become the same object as far as "is" is concerned even though today they are different... "is" should only be used in situations where you care about absolute object identity, not *value*.) -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ * P.S. I'm not saying its never right to use "is" outside of The Singletons. Just that its probably not, for most people, what they actually should do in most code. There are numerous counter-examples, of course. Its just a general guideline to follow. Until a need arises that demonstrates otherwise. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From yegorov.p at gmail.com Thu Dec 2 06:12:42 2010 From: yegorov.p at gmail.com (yegorov-p) Date: Thu, 2 Dec 2010 03:12:42 -0800 (PST) Subject: How to send an IP packet in Python? Message-ID: <6800bc0a-14f5-4262-ab0b-fb3f175e7a25@y23g2000yqd.googlegroups.com> Hello. I have sniffed some packet and now I would like to send it with the help of python. It's some simple IGMP packet with VLAN tag. (01 00 5E 00 43 67 00 02 B3 C8 7F 44 81 00 00 DE 08 00 46 00 00 20 00 01 00 00 01 02 36 4C C0 A8 00 7B EA 00 43 67 94 04 00 00 16 00 BC 97 EA 00 43 67) At first I wrote that: dst = '234.0.67.103' # Open a raw socket. s = socket.socket(socket.AF_INET, socket.SOCK_RAW,2) res='' temp='01 00 5E 00 43 67 00 02 B3 C8 7F 44 81 00 00 DE 08 00 46 00 00 20 00 01 00 00 01 02 36 4C C0 A8 00 7B EA 00 43 67 94 04 00 00 16 00 BC 97 EA 00 43 67' for i in temp.split(' '): res+=chr(int(i, 16)) print res s.sendto(res, (dst, 0)) But for some reason python send that: 0x0000 01 00 5E 00 43 67 00 02-B3 C8 7F 44 08 00 45 00 ..^.Cg..??D..E. 0x0010 00 46 07 06 00 00 01 02-C4 25 C0 A8 00 7B EA 00 .F......? %??.{?. 0x0020 43 67 01 00 5E 00 43 67-00 02 B3 C8 7F 44 81 00 Cg..^.Cg..??D?. 0x0030 00 DE 08 00 46 00 00 20-00 01 00 00 01 02 36 4C .?..F.. ......6L 0x0040 C0 A8 00 7B EA 00 43 67-94 04 00 00 16 00 BC 97 ??. {?.Cg?.....?? 0x0050 EA 00 43 67 ?.Cg As you can see, python ignores my headers and creates its own. I discussed that problem on stackoverflow.com and one user told me to try that: import socket s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, 0x8100) s.bind(('eth0', 0x8100)) res='' temp='01 00 5E 00 43 67 00 02 B3 C8 7F 44 81 00 00 DE 08 00 46 00 00 20 00 01 00 00 01 02 36 4C C0 A8 00 7B EA 00 43 67 94 04 00 00 16 00 BC 97 EA 00 43 67' for i in temp.split(' '): res+=chr(int(i, 16)) s.send(res) But under Windows, AF_PACKET is said to be undefined. =( I tried to replace it with AF_INET, but now python tells me that that protocol (0x8100) is not supported. 0x8100 is IEEE 802.1Q and I just don't understand, why it isn't supported. I can generate packet with VLAN tag inside and send it with the help of pierf, for example. In fact, I can generate and send the packet from my example with pierf and it runs just fine. =) I've found a topic with the same problem (http:// www.computing.net/answers/programming/python-windows-sockets/11884.html) So, is there any way to somehow send a packet with ready headers and data under Windows with the help of python? From __peter__ at web.de Thu Dec 2 06:17:53 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 02 Dec 2010 12:17:53 +0100 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename References: <1291124813.414884.22.camel@WOPR> Message-ID: Nobody wrote: > This was actually a critical flaw in Python 3.0, as it meant that > filenames which weren't valid in the locale's encoding simply couldn't be > passed via argv or environ. 3.1 fixed this using the "surrogateescape" > encoding, so now it's only an annoyance (i.e. you can recover the original > bytes once you've spent enough time digging through the documentation). Is it just that you need to harden your scripts against these byte sequences or do you actually encounter them? If the latter, can you give some examples? From ben+python at benfinney.id.au Thu Dec 2 06:19:25 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 02 Dec 2010 22:19:25 +1100 Subject: Comparison with False - something I don't understand References: Message-ID: <877hfs2zia.fsf@benfinney.id.au> Harishankar writes: > When I run pychecker through my modules I get the message that > comparisons with "False" is not necessary and that it might yield > unexpected results. Good advice. > Yet in some situations I need to specifically check whether False was > returned or None was returned. Why is comparison with False so bad? Because it's almost always unnecessary and can yield unexpected results :-) In other words, the only purpose of the ?bool? type is to have values explicitly designed for testing in Boolean conditions. Comparing them to the literals is a code smell ? indicating a poor design. > # example code which matches both False and None > if not var: > # do something Can you give a specific real-world example of why this is not good enough? It's likely we can suggest better ways of achieving the broader purpose. > So how do you get around this? My functions return False and None > under different circumstances. Usually it is None that will be the special case, so it's usually better to write something like:: result = foo() if result is None: # do special things But that's just one possibility, and might not apply in your use case. > Should I raise exceptions instead? I feel it's unnecessary clutter to > use exceptions unless absolutely no other solution is available and > yet I have doubts about the "False" value. More details of the problem you're trying to solve would help with giving specific advice. -- \ ?I was sad because I had no shoes, until I met a man who had no | `\ feet. So I said, ?Got any shoes you're not using??? ?Steven | _o__) Wright | Ben Finney From prog at vtr.net Thu Dec 2 07:54:50 2010 From: prog at vtr.net (craf) Date: Thu, 02 Dec 2010 09:54:50 -0300 Subject: [Fwd: Re: Decorate un Frame with window managers title bar, etc en Tkinter 8.5] Message-ID: <1291294490.2473.0.camel@cristian-desktop> --------- Mensaje reenviado -------- > De: Eric Brunel > Para: python-list at python.org > Asunto: Re: Decorate un Frame with window managers title bar, etc en > Tkinter 8.5 > Fecha: Thu, 02 Dec 2010 10:21:49 +0100 > Grupos de noticias: comp.lang.python > > In article , > craf wrote: > > > Hi. > > > > I use python 3.1 and Tkinter 8.5 in Ubuntu 9.10 > > > > I would like to turn a frame into a toolbox, > > ,and for that I read that you can use the command wm manage (window) > > > > The information can be found at: > > http://www.tcl.tk/man/tcl8.5/TkCmd/wm.htm#M39 > > > > the explanation says: > > > > wm manage widget: > > The widget specified will become a stand alone top-level window. > > The window will be decorated with the window managers title bar, > > etc. Only frame, labelframe and toplevel widgets can be used > > with this command. Attempting to pass any other widget type will > > raise an error. Attempting to manage a toplevel widget is benign > > and achieves nothing. See also GEOMETRY MANAGEMENT. > > > > I have tried to use it in Tkinter but I can not know how is its > > structure. > > > > In Tkinter should be: > > > > ---TEST CODE------------------- > > > > from Tkinter import > > > > master = Tk() > > frame = Frame(master) > > wm_manager(Frame) > > master.mainloop() > > > > -------------------------------- > > > > But this does not work. > > If your version of Tkinter supports it, then the correct syntax is: > frame.wm_manage() > Please note you have to call it on the Frame instance (the one you named > frame), and not on Frame with a big F which is the class. > > If it says the method doesn't exist (AttributeError raised on the line > frame.wm_manage()), you can also try to do it at tcl/tk level with the > line: > master.tk.call('wm', 'manage', frame) > > > I appreciate any of this item > > HTH > - Eric - Thank you very much Eric! Regards. Cristian. From v.harishankar at gmail.com Thu Dec 2 09:13:05 2010 From: v.harishankar at gmail.com (Harishankar) Date: Thu, 2 Dec 2010 14:13:05 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> Message-ID: On Thu, 02 Dec 2010 22:19:25 +1100, Ben Finney wrote: > More details of the problem you're trying to solve would help with > giving specific advice. I'm writing functions with multiple points of failure exits. I use return False as a way to flag the error condition rather than raising exceptions. But under certain circumstances, the function can also return empty lists which equate to false when using the condition like: # myfunction () can return a list of tuples, but can also return an empty # list under certain conditions since it's query a database and the result # can be empty also result = myfunction (vars) if not result: # error condition Now above I first realized that the function can also return an empty list under some conditions and so changed it to if result == False: # error condition But now I realize that it's better to use "is" if result is False: # error condition That is how my problem arose. - Harishankar (http://harishankar.org http://lawstudentscommunity.com) From v.harishankar at gmail.com Thu Dec 2 09:18:25 2010 From: v.harishankar at gmail.com (Harishankar) Date: Thu, 2 Dec 2010 14:18:25 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> Message-ID: On Thu, 02 Dec 2010 02:49:50 -0800, Stephen Hansen wrote: >... >... >... > * P.S. I'm not saying its never right to use "is" outside of The > Singletons. Just that its probably not, for most people, what they > actually should do in most code. There are numerous counter-examples, of > course. Its just a general guideline to follow. Until a need arises that > demonstrates otherwise. Here I'm using it to compare the result of a function where I specifically return False on error condition, so I think it's better I check it against the literal False rather than the fuzzy False produced by the boolean operation. I wouldn't do this in most situations though, but I did need to distinguish between the the empty list and False and using the broader form as in "if not a" did not work as expected. -- Harishankar (http://harishankar.org http://lawstudentscommunity.com) From khamenya at gmail.com Thu Dec 2 09:43:27 2010 From: khamenya at gmail.com (Valery) Date: Thu, 2 Dec 2010 06:43:27 -0800 (PST) Subject: How to initialize each multithreading Pool worker with an individual value? References: Message-ID: On Dec 1, 3:24?am, James Mills wrote: > I assume you are talking about multiprocessing > despite you mentioning "multithreading" in the mix. yes, sorry. > Have a look at the source code for multiprocessing.pool > and how the Pool object works and what it does > with the initializer argument. I'm not entirely sure it > does what you expect and yes documentation on this > is lacking... I see I found my way "to seed" each member of Pool with own data. I do it right after after initialization: port = None def port_seeder(port_val) from time import sleep sleep(1) # or less... global port port = port_val if __name__ == '__main__': pool = Pool(3) pool.map(port_seeder, range(3), chunksize=1) # now child processes are initialized with individual values. Another (a bit more heavier) approach would be via shared resource. P.S. sorry, I found your answer only now. reagrds -- Valery From python.list at tim.thechases.com Thu Dec 2 09:44:11 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 02 Dec 2010 08:44:11 -0600 Subject: Comparison with False - something I don't understand In-Reply-To: References: <4CF779CE.3040209@ixokai.io> Message-ID: <4CF7B0BB.7080008@tim.thechases.com> On 12/02/2010 08:18 AM, Harishankar wrote: > Here I'm using it to compare the result of a function where I > specifically return False on error condition, This sounds exactly like the reason to use exceptions...you have an exceptional error condition. -tkc From jlconlin at gmail.com Thu Dec 2 09:45:46 2010 From: jlconlin at gmail.com (Jeremy) Date: Thu, 2 Dec 2010 06:45:46 -0800 (PST) Subject: How can I define class methods outside of the class? References: Message-ID: <5007196a-0366-41ed-ae8d-8a1633a22dff@r31g2000prg.googlegroups.com> On Dec 1, 10:47?pm, James Mills wrote: > On Thu, Dec 2, 2010 at 3:36 PM, Jeremy wrote: > > I have some methods that I need (would like) to define outside of the > > class. ?I know this can be done by defining the function and then > > setting it equal to some member of an instance of the class. ?But, > > because of the complexity of what I'm doing (I have to set many > > functions as class methods) I would rather not do this. ?Can someone > > show me how to do this? ?Is it even possible? ?Can decorators be used > > here? > > Do you mean something like this ? > > @classmethod > def foo(cls): > ? ? print "I am the foo classmethod on %r" % cls > > class Foo(object): > ? ? pass > > Foo.foo = foo > > cheers > James Thanks, James. That is almost exactly what I want. However, I want to avoid doing Foo.foo = foo Is this going to be possible? I'm trying to understand how decorators are used. Are they really necessary in this example? Thanks, Jeremy From milan.petrasek at gmail.com Thu Dec 2 09:51:24 2010 From: milan.petrasek at gmail.com (Milan Petrasek) Date: Thu, 2 Dec 2010 15:51:24 +0100 Subject: m2crypto, base64, quoted-printable, xml Message-ID: Hi, I have encrypted signed smime message with xml file. Messages are constructed: 1) xml file is embedded to MIME message as attacment (Content-Disposition: attachment;). 2) over whole content MIME message is signed by PKCS#7 and encoded Base64. 3) This message is encrypted by public key. I use M2crypto to decrypt: from M2Crypto import BIO, SMIME, X509 import os output = open("c://decrypted.txt", 'w') s = SMIME.SMIME() s.load_key('test.pem', 'test.pem') p7, data = SMIME.smime_load_pkcs7('input.txt') out = s.decrypt(p7) output.write(out) output.close() this part works properly. I try to verify the signed data, but without success. File decrypted.txt contains base64 encoded data. ( I tried to decode through from M2Crypto import BIO, SMIME, X509 import base64 import os input = open("C://decrypted.txt", 'r') output= open("C://decoded.txt", 'w') base64.decode(input,output) output.close input.close Decoded.txt contains quoted printable data, but if I try decode these data: import os import quopri input = open("c://decoded.txt", 'r') output= open("c://output.xml", 'w') quopri.decode(input, output) output.close input.close I obtain invalid and incomplete data. Data contains for example "s ? ?plitting" instead of "splitting". Do you have any idea, what do I do wrong? Thanks you very much Best regards Milan -------------- next part -------------- 0? *?H?? ??0?1 0 +0? *?H?? ??$???Content-Type: application/octet-stream; name=60000000809820.XML Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename=60000000809820.XML <= Trade acceptance=3D"N" id=3D"84953" market=3D"VDT" trade-day=3D"2010-11-20"= trade-order=3D"1" trade-type=3D"P" version=3D"0"><= ProfileData profile-role=3D"P72"><= /ProfileData>= = 8YHs/sxfgB3k0UzVK008AA4GHO4=3D zf+U2XLnE14YWQdeJ0apGPQBVviiQ1JJqCKZGFWcQ1ljwgG61f9JnALZsBYZP+6G2p9aAsyto2+= D at78MnNiuENXwzBnKdCMUU9wOYsnVdKXnfCCUQzJeP7yQgaev4QL8fSXpaziI52AH1caXPM4e7V= 3 bcpQKXBwUrZq+hhJfyFSLm/R31APWqlujPk9gwSSiDWZ6aFLFob4jKj1FWQBTQzi0fnC/N50dA7= 7 C4V/X5XsbqlRxA4G83GneryrOEa0l1UXggFGlFQ5xNFwAMFOHnAz55HXQ9llRnm4safqvl4HNAX= x mZIqoiF7caWYe2WfGsQ+Soy3MCwltlemK4/FHQ=3D=3D MIIDyTCCArGgAwIBAgIKL7h+8AAFAAAV8DANBgkqhkiG9w0BAQUFADBCMQswCQYDVQQGEwJDWjE= P MA0GA1??UEChMGTG9naWNhMRIwEAYDVQQLEwlQS0kgR3JvdXAxDjAMBgNVBAMTBU9URUNBMB4XDTE= w MDIxNjEzNDM0MloXDTEyMDIxNjEzNTM0MlowZTEkMCIGCSqGSIb3DQEJARYVY3NvdGVAY3NvdGU= u b3RlLWNyLmN6MQswCQYDVQQGEwJDWjESMBAGA1UEChMJT1RFLCBhLnMuMQwwCgYDVQQLEwNQS0k= x DjAMBgNVBAMTBUNTT1RFMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA9mo6AupquHb= e Q26caDIOgOIchGVpv7DV0QjqqixFNPSkg+POqDSB8txUKjcRmV0HKWT1o46SzpIVaUod1eaESTR= o KiEp10v7EFC+InYBRk7HzHoBau1kyYaGHrECdeOddFN1LhFsZXcdWQLGE5AWW9A5hmyksQK8aoJ= o ZNWXYzBSrNIHRQpQi7x3rEg80o/UhezBbU1KZXhg0LSCzayzixjzw++TR6l3YwdkO2wHUpBzKwd= U 46rWPMdN3NcWbocrVDUWkyLnNHWlO6olKVWV+751ZjszjjgNI+E+Wc2kxRUqKJRR9Ren5PYLvPP= v +oCnZaxvkKQDd30fyPSnyvVoxQIDAQABo4GdMIGaMB0GA1UdDgQWBBThBbCUiVlEPsXoCMOg7cd= f /wOyAjB5BgNVHSMEcjBwgBT08Vf3iDofXlR27DvrxE+H5diP0aFGpEQwQjELMAkGA1UEBhMCQ1o= x DzANBgNVBAoTBkxvZ2ljYTESMBAGA1UECxMJUEtJIEdyb3VwMQ4wDAYDVQQDEwVPVEVDQYIQeYN= C Xj6Lf6NNexTEztftfDANBgkqhkiG9w0BAQUFAAOCAQEAgq5DSjn0uZsjIBpaff+Y/gGgXAhpD7L= b IbPEJTIxc6vb4uSSssht5SapXKfyek2bG0?uYuDkv3Cubv1Gf77qrOcyNsmMzbpXpYMCRiJ2oZ9FZ= 4 +NuQK68jK5MAT8GH3GiJ/ikphTTknSpLm/9JRjnjX9pbGbKpIFPYiRBzdQI28Y7wqOuzvRPcknI= X LGWh+QYymRTGHQDaJts5mOzgsl2WbvdFMgt3wocAp35HyK9QHH9NrnT0+x+VxvW8sTJ5zQYQyhq= 5 mXmQwgKSAJUnM3y2NHEjOiYwNf2iwoAwHgM8/GNymaLLHbgeaK7GoTqiBsmuUKcFSGC9lRJhGZq= L EufT1A=3D=3D 9mo6AupquHbeQ26caDIOgOIchGVpv7DV0QjqqixFNPSkg+POqDSB8txUKjcRmV0HKWT1o46SzpI= V aUod1eaESTRoKiEp10v7EFC+InYBRk7HzHoBau1kyYaGHrECdeOddFN1LhFsZXcdWQLGE5AWW9A= 5 hmyksQK8aoJoZNWXYzBSrNIHRQpQi7x3rEg80o/UhezBbU1KZXhg0LSCzayzixjzw++TR6l3Ywd= k O2wHUpBzKwdU46rWPMdN3NcWbocrVDUWkyLnNHWlO6olKVWV+751ZjszjjgNI+E+Wc2kxRUqKJR= R 9Ren5PYLvPPv+oCnZaxvkKQDd30fyPSnyvVoxQ=3D=3D AQAB ??0??0??? /?~??0  *?H?? 0B1 0 UCZ10 U Logica10U  PKI Group10 UOTECA0  100216134342Z 120216135342Z0e1$0" *?H??  csote at csote.ote-cr.cz1 0 UCZ10U  OTE, a.s.1 0 U PKI10 UCSOTE0?"0  *?H?? ?0? ??j:?j?v?Cn?h2?? ?ei??????,E4??????4???T*7?])d??????iJ ???I4h*!)?K?P?"vFN??zj?d??? ?u??tSu.lew Y??[?9?l???j?hd??c0R??E P??w?HY???*(?Q???? ??????e?o??w}?????h????0??0 U ????YD>??????_??0yU #r0p???W??:^Tv?;??O??????F?D0B1 0 UCZ10 U Logica10U  PKI Group10 UOTECA?y?B^>??M{????|0  *?H?? ???CJ9???# Z}????\i??!??%21s???????m?&?\??zM?F.K? ???g????s#l????zX0$b'j?Vx???+?#+?O???h??))?4??*K??IF9?_?[?? S??su6?????????r,e??2?? ?&?9????]?n?E2 w???~G??P M?t???????2y????y????'3|?4q#:&05????0  <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> Message-ID: On Thu, 02 Dec 2010 08:44:11 -0600, Tim Chase wrote: > On 12/02/2010 08:18 AM, Harishankar wrote: >> Here I'm using it to compare the result of a function where I >> specifically return False on error condition, > > This sounds exactly like the reason to use exceptions...you have an > exceptional error condition. > > -tkc There are some reasons why I hate exceptions but that is a different topic. However, in short I can say that personally: 1. I hate try blocks which add complexity to the code when none is needed. Try blocks make code much more unreadable in my view and I use it only for the built-in exceptions when absolutely needed. 2. I prefer the less irksome True or False to do error checking. Exceptions seem too heavyweight for simple problems. 3. Philosophically I think exception handling is the wrong approach to error management. I have never grown up programming with exceptions in C and I couldn't pick up the habit with python either. Did I mention that I detest try blocks? try blocks seem ugly and destroy code clarity at least in my view. And enclosing single statements under separate try blocks seem to add a lot of clutter. -- Harishankar (http://harishankar.org http://lawstudentscommunity.com) From steve at holdenweb.com Thu Dec 2 10:19:35 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 02 Dec 2010 10:19:35 -0500 Subject: Comparison with False - something I don't understand In-Reply-To: References: <877hfs2zia.fsf@benfinney.id.au> Message-ID: On 12/2/2010 9:13 AM, Harishankar wrote: > On Thu, 02 Dec 2010 22:19:25 +1100, Ben Finney wrote: > >> More details of the problem you're trying to solve would help with >> giving specific advice. > > I'm writing functions with multiple points of failure exits. I use return > False as a way to flag the error condition rather than raising > exceptions. But under certain circumstances, the function can also return > empty lists which equate to false when using the condition like: > > # myfunction () can return a list of tuples, but can also return an empty > # list under certain conditions since it's query a database and the result > # can be empty also > > result = myfunction (vars) > > if not result: > # error condition > > Now above I first realized that the function can also return an empty > list under some conditions and so changed it to > > if result == False: > # error condition > > > But now I realize that it's better to use "is" > > if result is False: > # error condition > > That is how my problem arose. > Did you think about using exceptions to handle exceptional conditions? If you are new to Python it may not be the obvious soltuion, but it can greatly simplify program logic. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Thu Dec 2 10:21:53 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 02 Dec 2010 10:21:53 -0500 Subject: Comparison with False - something I don't understand In-Reply-To: References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> Message-ID: On 12/2/2010 9:56 AM, Harishankar wrote: > 3. Philosophically I think exception handling is the wrong approach to > error management. I have never grown up programming with exceptions in C > and I couldn't pick up the habit with python either. Did I mention that I > detest try blocks? try blocks seem ugly and destroy code clarity at least > in my view. And enclosing single statements under separate try blocks > seem to add a lot of clutter. Whereas lots of nested if statements to test that multiple errors have all not occurred is a model of clarity? This sounds to me like a prejudice that will harm your Python development. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From usernet at ilthio.net Thu Dec 2 10:25:55 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 2 Dec 2010 15:25:55 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> Message-ID: On 2010-12-02, Harishankar wrote: > There are some reasons why I hate exceptions but that is a different > topic. However, in short I can say that personally: > > 1. I hate try blocks which add complexity to the code when none is > needed. Try blocks make code much more unreadable in my view and I use it > only for the built-in exceptions when absolutely needed. Actually, exceptions remove a ton of complexity and almost universally remove a ton of redundant error checking code. Second, they aleviate a ton of design complexity about designing a clean and unified method of error handling throughout the program. Using exceptions, the only real questions are where to handle various errors. It is a godsend for having to clean up intermediary results when an error occurs as part of a complex set of dependant sequential operations. > 2. I prefer the less irksome True or False to do error checking. > Exceptions seem too heavyweight for simple problems. Error handling in C huge source of bugs. First, error handling code is scattered throughout the codebase and second it is hard to test the error handling code for a number of failures. Being able to raise exceptions within your test code makes it much easier to write tests capable of detecting error handling bugs. > 3. Philosophically I think exception handling is the wrong approach to > error management. I have never grown up programming with exceptions in C > and I couldn't pick up the habit with python either. Did I mention that I > detest try blocks? try blocks seem ugly and destroy code clarity at least > in my view. And enclosing single statements under separate try blocks > seem to add a lot of clutter. Perhaps you should take a look at how Erlang appoaches exception handling. Being message passing and concurrency oriented, Erlang encourages ignoring error conditions within worker processes. Errors instead cause the worker processes to be killed and a supervisory process is notified, by message, so that it can handle the error and respawn the worker process. Since it doesn't use try/exept blocks, maybe that will be more to your liking. From invalid at invalid.invalid Thu Dec 2 10:31:47 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 2 Dec 2010 15:31:47 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> Message-ID: On 2010-12-02, Steve Holden wrote: > On 12/2/2010 9:13 AM, Harishankar wrote: >> >> if not result: >> # error condition >> >> Now above I first realized that the function can also return an empty >> list under some conditions and so changed it to >> >> if result == False: >> # error condition >> >> >> But now I realize that it's better to use "is" >> >> if result is False: >> # error condition >> >> That is how my problem arose. > > Did you think about using exceptions to handle exceptional conditions? > If you are new to Python it may not be the obvious soltuion, but it can > greatly simplify program logic. If you're not used to using exceptions it may at first seem like they take extra effort to use. But usually, in the end, they end up being less work (and more importantly easier to read and less bugs). -- Grant Edwards grant.b.edwards Yow! He is the MELBA-BEING at ... the ANGEL CAKE gmail.com ... XEROX him ... XEROX him -- From v.harishankar at gmail.com Thu Dec 2 10:34:31 2010 From: v.harishankar at gmail.com (Harishankar) Date: Thu, 2 Dec 2010 15:34:31 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> Message-ID: On Thu, 02 Dec 2010 10:19:35 -0500, Steve Holden wrote: > On 12/2/2010 9:13 AM, Harishankar wrote: >> On Thu, 02 Dec 2010 22:19:25 +1100, Ben Finney wrote: >> >>> More details of the problem you're trying to solve would help with >>> giving specific advice. >> >> I'm writing functions with multiple points of failure exits. I use >> return False as a way to flag the error condition rather than raising >> exceptions. But under certain circumstances, the function can also >> return empty lists which equate to false when using the condition like: >> >> # myfunction () can return a list of tuples, but can also return an >> empty # list under certain conditions since it's query a database and >> the result # can be empty also >> >> result = myfunction (vars) >> >> if not result: >> # error condition >> >> Now above I first realized that the function can also return an empty >> list under some conditions and so changed it to >> >> if result == False: >> # error condition >> >> >> But now I realize that it's better to use "is" >> >> if result is False: >> # error condition >> >> That is how my problem arose. >> > Did you think about using exceptions to handle exceptional conditions? > If you are new to Python it may not be the obvious soltuion, but it can > greatly simplify program logic. > > regards > Steve I am not new to Python but I am not a fan of exceptions either. I prefer to avoid writing my own exceptions because it feels too heavy and clunky for simple error checking. Most times I find simple error checking ample for my purposes. Of course, I use the built-in exception objects when I have no choice, but I hate try blocks. They add clunkiness to code and besides exception objects seem to be fairly heavy-duty for simple error conditions where a true/false flag would probably suffice. I am also wary of using larger catch-all try blocks or try blocks with multiple exception exits (which seem to make tracking subtle bugs harder). I prefer the philosophy of dealing with errors immediately as they arise, rather than delegate them to exception mechanism. Of course, I could wrap single statements in try blocks, but that makes the code even messier without any significant benefits. -- Harishankar (http://harishankar.org http://lawstudentscommunity.com) From me+list/python at ixokai.io Thu Dec 2 10:35:18 2010 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 02 Dec 2010 07:35:18 -0800 Subject: Comparison with False - something I don't understand In-Reply-To: References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> Message-ID: <4CF7BCB6.1080501@ixokai.io> On 12/2/10 6:56 AM, Harishankar wrote: > On Thu, 02 Dec 2010 08:44:11 -0600, Tim Chase wrote: > >> On 12/02/2010 08:18 AM, Harishankar wrote: >>> Here I'm using it to compare the result of a function where I >>> specifically return False on error condition, >> >> This sounds exactly like the reason to use exceptions...you have an >> exceptional error condition. >> >> -tkc > > There are some reasons why I hate exceptions but that is a different > topic. However, in short I can say that personally: To each his/her own, of course; but -- > 3. Philosophically I think exception handling is the wrong approach to > error management. Exceptions aren't about "error management"; they are about exceptional conditions: some are errors, others are entirely normal situations you know are going to happen (such as reaching the end of a sequence as you iterate over it: that's not an error, but it is special). To be philosophically opposed to them seems to me to be philosophically in favor of race conditions. > I have never grown up programming with exceptions in C > and I couldn't pick up the habit with python either. Did I mention that I > detest try blocks? try blocks seem ugly and destroy code clarity at least > in my view. And enclosing single statements under separate try blocks > seem to add a lot of clutter. ? How do they destroy clarity or add clutter, since presumably you have to deal with that "False" in some way with logical structure -- which always does whitespace in Python. If not immediately, then up the call stack (which seems to imply you should just not use a try/except and let the exception unwind the stack to wherever in your code someone wants to deal with it). if is_correct(): result = do_thing() else: do_error_handling() try: result = do_thing() except KeyError: do_error_handling() And as an aside, the more statements one puts into a try/except block: and the more complicated a statement at that-- the more likely it is they are going to mess up and do something Wrong. Now, all that said: sure, in some situations I do prefer the "check first" style of programming where exceptions don't end up being used. Its not *wrong* to return False on an "error condition": its going against the grain, though, and makes your code harder to deal with long-term if only because now there's two separate mechanisms that "errors" happen in it. You can't totally do away with exceptions in Python, even if you try very hard. So with that in mind, IMHO, the best approach is to just... get over it, and learn to appreciate them :) But, to each his or her own. :) -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From v.jagan201 at gmail.com Thu Dec 2 10:41:57 2010 From: v.jagan201 at gmail.com (kameni) Date: Thu, 2 Dec 2010 07:41:57 -0800 (PST) Subject: thousand of application for you Message-ID: <48acc4c3-6552-45fd-a49e-cef7a543f475@i32g2000pri.googlegroups.com> http://123maza.com/28/come123/ From v.harishankar at gmail.com Thu Dec 2 10:44:00 2010 From: v.harishankar at gmail.com (Harishankar) Date: Thu, 2 Dec 2010 15:44:00 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> Message-ID: On Thu, 02 Dec 2010 15:25:55 +0000, Tim Harig wrote: >... >... > > Perhaps you should take a look at how Erlang appoaches exception > handling. Being message passing and concurrency oriented, Erlang > encourages ignoring error conditions within worker processes. Errors > instead cause the worker processes to be killed and a supervisory > process is notified, by message, so that it can handle the error and > respawn the worker process. Since it doesn't use try/exept blocks, > maybe that will be more to your liking. Thanks for the reply. I understand that the error vs exception debate is quite a big one in the programming community as a whole and I don't consider myself very knowledgeable in these issues. However, I will try to approach this with an open mind and see whether I can work with exceptions comfortably in Python. I do understand both sides of the issue. Exceptions seem to be generally more reliable but I feel they add a lot of complexity particular when a lot of code is placed in a try block. -- Harishankar (http://harishankar.org http://lawstudentscommunity.com) From usernet at ilthio.net Thu Dec 2 10:53:49 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 2 Dec 2010 15:53:49 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> Message-ID: On 2010-12-02, Harishankar wrote: > I am also wary of using larger catch-all try blocks or try blocks with > multiple exception exits (which seem to make tracking subtle bugs > harder). I prefer the philosophy of dealing with errors immediately as If you are using exceptions to try to catch bug then you are using them improperly. Exceptions (with the exception (no pun intended) of AssertionError) are designed to catch error conditions, not bugs. > harder). I prefer the philosophy of dealing with errors immediately as > they arise, rather than delegate them to exception mechanism. Of course, > I could wrap single statements in try blocks, but that makes the code > even messier without any significant benefits. Actually, finer grained error handling commonly covers up bugs. If you want to find bugs, you want to make the program prone to crashing if a bug is present. It is all too easy to accidently mistake the return value of a function as error condition and handle it rather the letting the program crash. By separating the results from the transmission of error conditions (in effect taking error conditions out of band) then you make it much harder to make such a mistake because you have to explicity indicate which error conditions your code is capable of generating. From v.harishankar at gmail.com Thu Dec 2 10:58:39 2010 From: v.harishankar at gmail.com (Harishankar) Date: Thu, 2 Dec 2010 15:58:39 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <4CF7BCB6.1080501@ixokai.io> Message-ID: On Thu, 02 Dec 2010 07:35:18 -0800, Stephen Hansen wrote: > Exceptions aren't about "error management"; they are about exceptional > conditions: some are errors, others are entirely normal situations you > know are going to happen (such as reaching the end of a sequence as you > iterate over it: that's not an error, but it is special). To be > philosophically opposed to them seems to me to be philosophically in > favor of race conditions. Maybe I worded that part wrongly. Of course I get that error handling is only a part of exception mechanism. I agree that the built-in exceptions are useful but I prefer most times not to catch them. :-) > ? How do they destroy clarity or add clutter, since presumably you have > to deal with that "False" in some way with logical structure -- which > always does whitespace in Python. If not immediately, then up the call > stack (which seems to imply you should just not use a try/except and let > the exception unwind the stack to wherever in your code someone wants to > deal with it). The reason why I said they remove clarity is because it's not always obvious at which point the exception may be raised. In other words, within a try block there may be multiple statements that generate the exception. Of course, as I said before, one way would be to wrap single statements with the try block and avoid this issue. > > if is_correct(): > result = do_thing() > else: > do_error_handling() > > try: > result = do_thing() > except KeyError: > do_error_handling() Of course, to me the if statement would make more sense because I immediately figure out the exact condition being tested against while the exception object is not always so clear and maybe ambiguous in some cases. Also if that same type of exception is raised by another statement within a function that is called within the try block then it would be handled by the same except block right? This is where it gets a bit confusing to me and the flow of code is not always obvious. That's why I prefer atomic error handling where I know exactly which part of the code led to the result. > And as an aside, the more statements one puts into a try/except block: > and the more complicated a statement at that-- the more likely it is > they are going to mess up and do something Wrong. > > Now, all that said: sure, in some situations I do prefer the "check > first" style of programming where exceptions don't end up being used. > Its not *wrong* to return False on an "error condition": its going > against the grain, though, and makes your code harder to deal with > long-term if only because now there's two separate mechanisms that > "errors" happen in it. I realize that it is impossible for me to avoid exception mechanism myself. So I restrict it only to situations where I cannot avoid it (e.g. inbuilt exceptions in some cases where I want to handle it myself) > > You can't totally do away with exceptions in Python, even if you try > very hard. So with that in mind, IMHO, the best approach is to just... > get over it, and learn to appreciate them :) Finding it hard to appreciate exceptions myself. But I am used to thinking linearly. A piece of code which does not explain itself in the most obvious way even if I wrote it always worries me. -- Harishankar (http://harishankar.org http://lawstudentscommunity.com) From piet at vanoostrum.org Thu Dec 2 11:09:25 2010 From: piet at vanoostrum.org (Piet van Oostrum) Date: Thu, 02 Dec 2010 12:09:25 -0400 Subject: strange TypeError exception in function compiled from a string References: Message-ID: nelson writes: > Hi all, > I have this function, defined in a string and ecetuted through ad > exec call > > def cell1(d): > > x=d.get('x') > print x > > import y > return y.add(y.add(self.adf0(x),self.adf0(x)),self.adf0(x)) > What is self in line 7? -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] Nu Fair Trade woonartikelen op http://www.zylja.com From usernet at ilthio.net Thu Dec 2 11:12:39 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 2 Dec 2010 16:12:39 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> Message-ID: On 2010-12-02, Harishankar wrote: > I understand that the error vs exception debate is quite a big one in the > programming community as a whole and I don't consider myself very Actually, I thought that debate was resolved years ago. I cannot think of a single recently developed programming language that does not provide exception handling mechanisms because they have been proven more reliable. > Python. I do understand both sides of the issue. Exceptions seem to be > generally more reliable but I feel they add a lot of complexity > particular when a lot of code is placed in a try block. Lines of code is one measure of complexity. Each line of code has a small chance of containing a bug. The more lines of code that you have, then the more likely that one of them contains a bug. Exceptions, by placing error handling code in fewer places, requires much fewer lines of code then requiring error handling code after each call that might produce an error condition. The operations of propogating an error up to the higher level logic of the program is another measure. In languages without exception handling, careful planning is needed to pass error conditions up through the call stack until they reach a high enough level in the logic that decisions can be made about how to handle them. Even further planning must be taken so that when the error condition reaches level where it needs to be handled, that enough information about the error is present to know exactly what went wrong so that it can figure out what to do about it. This usually involves using globals like errorno to pass out of band information about the error. Sometimes you even need to know about how the error affect intermediate levels, did the intermediate code attempt to handle the condtion and fail? The Openssl error handling system, that creates an error logging chain is an example of just how complex this can become. You gain all of this functionality automatically through exception mechanisms; without all of the complexity. From v.harishankar at gmail.com Thu Dec 2 11:15:30 2010 From: v.harishankar at gmail.com (Harishankar) Date: Thu, 2 Dec 2010 16:15:30 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> Message-ID: On Thu, 02 Dec 2010 15:53:49 +0000, Tim Harig wrote: > If you are using exceptions to try to catch bug then you are using them > improperly. Exceptions (with the exception (no pun intended) of > AssertionError) are designed to catch error conditions, not bugs. I agree. But more specifically some exceptions seem too broad to catch specific errors that occur in MY code rather than in a system call or a library call. Also writing my own exception objects and raising exceptions seem to add too much of complexity to what is essentially a simple problem. This is what I was trying to explain. > Actually, finer grained error handling commonly covers up bugs. If you > want to find bugs, you want to make the program prone to crashing if a > bug is present. It is all too easy to accidently mistake the return > value of a function as error condition and handle it rather the letting > the program crash. By separating the results from the transmission of > error conditions (in effect taking error conditions out of band) then > you make it much harder to make such a mistake because you have to > explicity indicate which error conditions your code is capable of > generating. Doesn't the same finer grained exception mechanism make it prone to the same problems? Actually return values of functions which I write myself can be as specific and to the point. I could make it as fuzzy or as precise as I like. This is no doubt, something that I could emulate with an exception as well, but only make it slightly more complex with no obvious benefit. As I said before, the way exceptions are caught seem to me to be the most confusing bit. Non-atomic operations always worry me. What if my function which is wrapped inside a try block has two different statements that raised the same exception but for different reasons? With error handling I could probably handle it right below the statement which was called and thus reduce the problem??? -- Harishankar (http://harishankar.org http://lawstudentscommunity.com) From piet at vanoostrum.org Thu Dec 2 11:17:18 2010 From: piet at vanoostrum.org (Piet van Oostrum) Date: Thu, 02 Dec 2010 12:17:18 -0400 Subject: string find/replace References: <4cf687aa$0$5000$e4fe514c@dreader19.news.xs4all.nl> <4cf68ce8$0$12821$e4fe514c@dreader19.news.xs4all.nl> Message-ID: Carlo writes: > On 2010-12-01, Peter Otten <__peter__ at web.de> wrote: >>>>> import re >>>>> re.compile("([a-z])([A-Z])").sub(r"\1 \2", "camelCase") >> 'camel Case' > > Very simple if you know it. Thank you! And almost as cryptic as Perl!! -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] Nu Fair Trade woonartikelen op http://www.zylja.com From kirby.urner at gmail.com Thu Dec 2 11:30:24 2010 From: kirby.urner at gmail.com (kirby.urner at gmail.com) Date: Thu, 2 Dec 2010 08:30:24 -0800 (PST) Subject: DBF (VFP) to XLS (Excel) in pure Python References: <084f9299-b2b3-440f-b83f-9fbe42220221@j19g2000prh.googlegroups.com> <5ddf7758-754f-4649-be1e-85cdee7860e5@y23g2000yqd.googlegroups.com> Message-ID: On Dec 1, 10:28?pm, "kirby.ur... at gmail.com" wrote: > Playing around with arcane tools to read those pesky DBF files (with > memo fields), like floating wine barrels cast off the sinking VFP > ship. > Although it's true I don't know that I'm getting "in memory" DBF reads, the bulk of the time in the code I just shared is in the "writing to XLS" inner loop. Looking to a different solution for writing, perhaps a DLL available for $ (one time). Been reading more about VFP, Silverlight and HTML5. Python seems in a good position. All caught up on IronPython now too. Kirby From mdw at distorted.org.uk Thu Dec 2 11:35:08 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 02 Dec 2010 16:35:08 +0000 Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> Message-ID: <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> Harishankar writes: > There are some reasons why I hate exceptions but that is a different > topic. However, in short I can say that personally: > > 1. I hate try blocks which add complexity to the code when none is > needed. Try blocks make code much more unreadable in my view and I use it > only for the built-in exceptions when absolutely needed. Very little code actually needs `try' blocks. > 2. I prefer the less irksome True or False to do error checking. > Exceptions seem too heavyweight for simple problems. Just write simple programs as if errors never happen; if an exception is raised, the program prints a vaguely useful message and exits. Besides, this complaint is incoherent. One needs at least as much structure to check an error code as to catch an exception. > 3. Philosophically I think exception handling is the wrong approach to > error management. There are better ways to handle errors than Python's exception system. Passing error codes around manually is most definitely not one of them. (One of the main reasons I ditched Perl in favour of Python is the former's insistence on returning error codes for I/O and system calls.) -- [mdw] From eric.frederich at gmail.com Thu Dec 2 11:39:23 2010 From: eric.frederich at gmail.com (Eric Frederich) Date: Thu, 2 Dec 2010 11:39:23 -0500 Subject: multiple modules from single c extension In-Reply-To: References: Message-ID: Can you explain how to do this with distutils then? Would I need a separate setup.py for SpamABC and SpamXYZ? How would I get them included in the parent module Spam? Could you explain what you mean when you say "The Python import mechanism will be looking for an appropriately-named .pyd file for each module"? Are you saying that in python when I say from "Spam.ABC import *" I need a file called "Spam.ABC.[so|pyd]"? On Wed, Dec 1, 2010 at 8:39 PM, Robert Kern wrote: > On 12/1/10 4:12 PM, Eric Frederich wrote: >> >> I have an extension to some C library that I created using the guide >> found here... >> >> ? ? http://docs.python.org/extending/extending.html >> >> I am starting to have A LOT of functions being wrapped. >> >> The library that I'm creating bindings for is organized into modules. >> In fact, all of their function calls start with a prefix like >> ABC_do_something, XYZ_something_else. >> >> I'd like to start putting the bindings for each module into a separate >> C file and have each set of bindings end up in its own Python module >> as well. >> >> Is this possible to do using a single .dll / .pyd file so that I can >> use a single Visual Studio project for these bindings? > > No, I don't think so. The Python import mechanism will be looking for an > appropriately-named .pyd file for each module. In any case, you shouldn't be > using Visual Studio directly to build the .pyd. Instead, use distutils. > > -- > 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 > > -- > http://mail.python.org/mailman/listinfo/python-list > From dickinsm at gmail.com Thu Dec 2 11:39:41 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Thu, 2 Dec 2010 08:39:41 -0800 (PST) Subject: Some syntactic sugar proposals References: Message-ID: <215bc600-d3aa-4c39-adfd-d46ea2843ee7@i32g2000pri.googlegroups.com> On Nov 15, 12:46?pm, Tim Chase wrote: > On 11/15/2010 12:39 AM, Dmitry Groshev wrote: > > > x in range optimisation > > I've often thought this would make a nice O(1)-test lookup on an > xrange() generator. An O(1) test for 'x in ' is implemented in Python 3.2, at least provided that x has type 'int', 'long' or 'bool'. (If x is an instance of a subclass of int or long, then there's a risk that the semantics of the membership test have been changed by an explicitly overridden __eq__, so Python wimps out and falls back to the O(n) algorithm in that case.) Python 3.2a4+ (py3k:86635:86636M, Nov 21 2010, 19:22:18) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> -1 in range(10**9) False >>> 5 in range(0, 10**100, 2) False >>> 10**99 in range(0, 10**100, 2) True IIRC, there wasn't sufficient interest to get it backported to Python 2.7 in time for its release. Though as a pure optimization, one could argue that it would still be possible to get this into Python 2.7.2. Mark From robert.kern at gmail.com Thu Dec 2 11:49:25 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 02 Dec 2010 10:49:25 -0600 Subject: multiple modules from single c extension In-Reply-To: References: Message-ID: On 12/2/10 10:39 AM, Eric Frederich wrote: > Can you explain how to do this with distutils then? > Would I need a separate setup.py for SpamABC and SpamXYZ? > How would I get them included in the parent module Spam? Please consult the distutils documentation. http://docs.python.org/distutils/index.html In short, you only need one setup.py file. from distutils.core import setup, Extension setup( ... ext_modules=[ Extension('Spam.ABC', sources=['src/spam_abc.c']), Extension('Spam.XYZ', sources=['src/spam_xyz.c']), ], packages=['Spam'], ... ) > Could you explain what you mean when you say "The Python import > mechanism will be looking for an appropriately-named .pyd file for > each module"? > > Are you saying that in python when I say from "Spam.ABC import *" I > need a file called "Spam.ABC.[so|pyd]"? No, it will be looking for Spam/ABC.pyd where Spam/ is your package directory (i.e. it should have an __init__.py file, like any other Python package). -- 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 usernet at ilthio.net Thu Dec 2 11:52:57 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 2 Dec 2010 16:52:57 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> Message-ID: On 2010-12-02, Harishankar wrote: >> Actually, finer grained error handling commonly covers up bugs. If you >> want to find bugs, you want to make the program prone to crashing if a >> bug is present. It is all too easy to accidently mistake the return >> value of a function as error condition and handle it rather the letting >> the program crash. By separating the results from the transmission of >> error conditions (in effect taking error conditions out of band) then >> you make it much harder to make such a mistake because you have to >> explicity indicate which error conditions your code is capable of >> generating. > > Doesn't the same finer grained exception mechanism make it prone to the > same problems? Exception handling is a move away from fine grained handling. If in IOError is raised by a parser, I don't need to know at exactly which line the error occured. All I need to know is that the file is somehow unreadable; and that is why the parser failed. Therefore, none of the parser code should be handling IOError because it is being handled higher up in the stack. Since I expected that the parser might have problemes reading files, for problems that have nothing to do with my code, I explicity catch that error if it occurs. I am not expecting an IndexError from the parser and I don't bother to catch it. If the parser code does raise an IndexError, then my program crashes and I know that I have a bug in the parsing code. The call trace will tell me where that error occurs. I can watch that section of code in debugger to find out exactly what went wrong. > Actually return values of functions which I write myself can be as > specific and to the point. I could make it as fuzzy or as precise as I > like. This is no doubt, something that I could emulate with an exception > as well, but only make it slightly more complex with no obvious benefit. You seem to be making it complex because you are still trying to be too fine grained in handling each exception where it occurs as opposed to handing where the logic makes sense that it should be handled and because you are trying to code too defensively against your own code. Exception handling does require a different focus from handling errors from return values alone. > As I said before, the way exceptions are caught seem to me to be the most > confusing bit. Non-atomic operations always worry me. What if my function > which is wrapped inside a try block has two different statements that > raised the same exception but for different reasons? With error handling > I could probably handle it right below the statement which was called and > thus reduce the problem??? If you are having that issue, then you are likely placing the try blocks at too low of a level in your code. In general you will find that most systems have a gateway function as an entry point to the system. If there is not one already, then create such a function in you code. The parse function in my code above would be an example of such a gateway function. Beneath that function, you don't need to know exactly where the error occured, you just need to know the nature of the error and have general error handling procedures for each kind of error that you expect might occur. From piet at vanoostrum.org Thu Dec 2 12:03:58 2010 From: piet at vanoostrum.org (Piet van Oostrum) Date: Thu, 02 Dec 2010 13:03:58 -0400 Subject: Unicode thing that causes a traceback in 2.6 and 2.7 but not in 2.5, and only when writing to a pipe, not to the terminal References: Message-ID: Dan Stromberg writes: > What is this about? It's another n~ thing, but this time in 2.x. > All I'm doing is printing a str containing a character > 127. > > It works fine in 2.5, to a terminal or to a pipe. In 2.6 and 2.7, it > fails when writing to a pipe but works fine writing to my terminal - > an mrxvt.\ > > I really kind of want octets to just be octets, since I'm on a Linux > system - it probably should be up to the user and their related > software to decide how those octets are interpreted. I'm assuming > that the bytes() workarounds I'm using in 3.x aren't going to work in > 2.x - it looks like bytes() is just an alias for str() in 2.6 and 2.7. Strings are indeed byte strings (or octet strings if you prefer) in Python 2.x. > Traceback (most recent call last): > File "./test-readline0", line 22, in > print(line) > UnicodeEncodeError: 'ascii' codec can't encode character u'\xf1' in > position 20: ordinal not in range(128) This message shows that line is not a byte string but a unicode string. If you want to output a unicode string it has to be converted to bytes first, and Python must know which encoding to use. For output to the terminal it can usually get that information from the system, but not for a pipe. You will have to supply it. By the way, if you just want to work with octets, why is the variable line in unicode? If you keep everything in byte strings your problem may disappear. In Python 3 you have to do this explicitely as the default is unicode. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] Nu Fair Trade woonartikelen op http://www.zylja.com From xahlee at gmail.com Thu Dec 2 12:06:23 2010 From: xahlee at gmail.com (Xah Lee) Date: Thu, 2 Dec 2010 09:06:23 -0800 (PST) Subject: Google AI challenge: planet war. Lisp won. Message-ID: <44a8f48f-e291-463e-a042-d0cbc31a2a4e@z17g2000prz.googlegroups.com> discovered this rather late. Google has a AI Challenge: planet wars. http://ai-contest.com/index.php it started sometimes 2 months ago and ended first this month. the winner is G?bor Melis, with his code written in lisp. Congrats lispers! G?bor wrote a blog about it here http://quotenil.com/Planet-Wars-Post-Mortem.html (not sure if this has been mentioned here but quick search didn't find it) Xah ? http://xahlee.org/ ? From love_ram2040 at yahoo.com Thu Dec 2 12:12:28 2010 From: love_ram2040 at yahoo.com (porxy) Date: Thu, 2 Dec 2010 09:12:28 -0800 (PST) Subject: Site to forbidden sites, and blocked Message-ID: Site to forbidden sites, and blocked http://essam.zxq.net From ronsoule at gmail.com Thu Dec 2 12:18:06 2010 From: ronsoule at gmail.com (Ron) Date: Thu, 2 Dec 2010 09:18:06 -0800 (PST) Subject: pyOpenGL Error unable to detect undefined names Message-ID: <3a4317e6-a511-42ff-aff5-fffcedcd6b33@c13g2000prc.googlegroups.com> Hello, I am trying to use pyOpenGL and I keep getting the following errors: Traceback (most recent call last): File "C:\Temp\Python\OpenGL_Test.py", line 10, in from OpenGL.GLU import * File "C:\Python26\lib\site-packages\OpenGL\GLU\__init__.py", line 4, in from OpenGL.raw.GLU import * File "C:\Python26\lib\site-packages\OpenGL\raw\GLU\__init__.py", line 6, in from OpenGL.raw.GLU.constants import * File "C:\Python26\lib\site-packages\OpenGL\raw\GLU\constants.py", line 7, in from OpenGL import platform, arrays File "C:\Python26\lib\site-packages\OpenGL\arrays\__init__.py", line 22, in formathandler.FormatHandler.loadAll() File "C:\Python26\lib\site-packages\OpenGL\arrays\formathandler.py", line 37, in loadAll cls.loadPlugin( entrypoint ) File "C:\Python26\lib\site-packages\OpenGL\arrays\formathandler.py", line 44, in loadPlugin plugin_class = entrypoint.load() File "C:\Python26\lib\site-packages\OpenGL\plugins.py", line 14, in load return importByName( self.import_path ) File "C:\Python26\lib\site-packages\OpenGL\plugins.py", line 28, in importByName module = __import__( ".".join(moduleName), {}, {}, moduleName) File "C:\Python26\lib\site-packages\OpenGL\arrays\numpymodule.py", line 25, in from OpenGL_accelerate.numpy_formathandler import NumpyHandler File "numpy.pxd", line 30, in OpenGL_accelerate.numpy_formathandler (src\numpy_formathandler.c:3543) ValueError: numpy.dtype does not appear to be the correct type object The code is very simple all I have is two import statements: from OpenGL.GLU import * from OpenGL.GL import * The code analysis says that it is "unable to detect undefined names". What does that mean and how do I fix it? Is it an installation error? Thanks for the help, Ron From bruno.desthuilliers at gmail.com Thu Dec 2 12:19:53 2010 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Thu, 2 Dec 2010 09:19:53 -0800 (PST) Subject: How can I define class methods outside of the class? References: Message-ID: On 2 d?c, 06:36, Jeremy wrote: > I have some methods that I need (would like) to define outside of the > class. ?I know this can be done by defining the function and then > setting it equal to some member "assignement" or "binding" might be the terms you were looking for here ;) Also in Python we talk about "attributes", not "members" > of an instance of the class. What you describe here will not "define class methods", nor even instance methods FWIW - it will only make the function an attribute of the instance, but won't turn the function into a method (IOW: the function won't get the instance as first argument). Also and while we're at it, a Python "classmethod" is something special - it's a method that can be called on either an instance or the class itself, and takes the class - not the instance - as first argument. >?But, > because of the complexity of what I'm doing (I have to set many > functions as class methods) I would rather not do this. ?Can someone > show me how to do this? ?Is it even possible? To "no do this" ? Yes, certainly More seriously: if your problem is to dynamically add a bunch of methods to an existing *class*, it's quite easy - just import the class and assign your functions to it, ie: from otherlib import OtherClass def foo(self): print "%s.foo" % self OtherClass.foo = foo And voila, The "foo" method is now available to all (even already existing) instances of OtherClass. If this doesn't answer your question, please provide more context. > ?Can decorators be used > here? What for ? From kavalapooja at gmail.com Thu Dec 2 12:24:25 2010 From: kavalapooja at gmail.com (pooja kavala) Date: Thu, 2 Dec 2010 09:24:25 -0800 (PST) Subject: Simple hack To Get $5999 To Your Paypal Message-ID: <7a93aea6-845f-4a8a-b883-95493504ee52@j19g2000prh.googlegroups.com> Simple hack To Get $5999 To Your Paypal At http://freegiftvideos.co.c Due to High Security Risk I have Hidden the Videos In an Image In that Website On Right Side Below Search Box Click On Image And Watch Videos From bruno.desthuilliers at gmail.com Thu Dec 2 12:26:53 2010 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Thu, 2 Dec 2010 09:26:53 -0800 (PST) Subject: How can I define class methods outside of the class? References: <5007196a-0366-41ed-ae8d-8a1633a22dff@r31g2000prg.googlegroups.com> Message-ID: <87b6efa0-0d24-4858-a37c-d104c3b2c12d@c13g2000prc.googlegroups.com> On 2 d?c, 15:45, Jeremy wrote: > On Dec 1, 10:47?pm, James Mills wrote: > > > > > On Thu, Dec 2, 2010 at 3:36 PM, Jeremy wrote: > > > I have some methods that I need (would like) to define outside of the > > > class. ?I know this can be done by defining the function and then > > > setting it equal to some member of an instance of the class. ?But, > > > because of the complexity of what I'm doing (I have to set many > > > functions as class methods) I would rather not do this. ?Can someone > > > show me how to do this? ?Is it even possible? ?Can decorators be used > > > here? > > > Do you mean something like this ? > > > @classmethod > > def foo(cls): > > ? ? print "I am the foo classmethod on %r" % cls > > > class Foo(object): > > ? ? pass > > > Foo.foo = foo > > > cheers > > James > > Thanks, James. ?That is almost exactly what I want. ?However, I want to avoid doing > > Foo.foo = foo > > Is this going to be possible? ? def patch(cls): def _patch(func): setattr(cls, func.__name__, func) return func return _patch class Foo(object): pass @patch(Foo) def bar(self): print self f = Foo() f.bar() > I'm trying to understand how decorators > are used. ?Are they really necessary in this example? In the above example, the classmethod type was used as a decorator to turn the function into, well, a classmethod (read my other answer in this thread if you don't know what a classmethod is). From jeanmichel at sequans.com Thu Dec 2 12:42:46 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 02 Dec 2010 18:42:46 +0100 Subject: Comparison with False - something I don't understand In-Reply-To: References: <877hfs2zia.fsf@benfinney.id.au> Message-ID: <4CF7DA96.2030608@sequans.com> Harishankar wrote: > As I said before, the way exceptions are caught seem to me to be the most > confusing bit. Non-atomic operations always worry me. What if my function > which is wrapped inside a try block has two different statements that > raised the same exception but for different reasons? With error handling > I could probably handle it right below the statement which was called and > thus reduce the problem??? > > Exception actually are the solution as you can give an unlimitted quantity of information: def myfunction(self): error = myfuncException('a meaninful message') # error 1 error.blame = whateverobjectresponsibleoftheerror # error 2 error.blame = anotherobject_anothercause raise error try: myfunction() except myfuncException, exception: cause = exception.blame # you can inspect the 'cause' for specific handling In a more general and simple manner, you can tune the error feedback of exceptions by changing the message of the exception. Using different exception classes is also an obvious way to do it. But my point was that you can also set attributes to the exception you're raising with reference to almost anything at the time the exception occurs. And that is a very cool way to give precise feedback to exception handlers. JM From aahz at pythoncraft.com Thu Dec 2 12:43:28 2010 From: aahz at pythoncraft.com (Aahz) Date: 2 Dec 2010 09:43:28 -0800 Subject: Get frame object of last called function References: Message-ID: In article , moerchendiser2k3 wrote: > >Hi, is there any chance to get the frame object of the previous called >function? sys._current_frames(), sys._getframe() -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Think of it as evolution in action." --Tony Rand From python at mrabarnett.plus.com Thu Dec 2 12:57:33 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 02 Dec 2010 17:57:33 +0000 Subject: Comparison with False - something I don't understand In-Reply-To: References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> Message-ID: <4CF7DE0D.3030709@mrabarnett.plus.com> On 02/12/2010 16:12, Tim Harig wrote: > On 2010-12-02, Harishankar wrote: >> I understand that the error vs exception debate is quite a big one in the >> programming community as a whole and I don't consider myself very > > Actually, I thought that debate was resolved years ago. I cannot think of > a single recently developed programming language that does not provide > exception handling mechanisms because they have been proven more reliable. > >> Python. I do understand both sides of the issue. Exceptions seem to be >> generally more reliable but I feel they add a lot of complexity >> particular when a lot of code is placed in a try block. > > Lines of code is one measure of complexity. Each line of code has a small > chance of containing a bug. The more lines of code that you have, then the > more likely that one of them contains a bug. Exceptions, by placing error > handling code in fewer places, requires much fewer lines of code then > requiring error handling code after each call that might produce an error > condition. > > The operations of propogating an error up to the higher level logic of > the program is another measure. In languages without exception handling, > careful planning is needed to pass error conditions up through the call > stack until they reach a high enough level in the logic that decisions > can be made about how to handle them. Even further planning must be > taken so that when the error condition reaches level where it needs to > be handled, that enough information about the error is present to know > exactly what went wrong so that it can figure out what to do about it. > This usually involves using globals like errorno to pass out of band > information about the error. Sometimes you even need to know about how > the error affect intermediate levels, did the intermediate code attempt > to handle the condtion and fail? The Openssl error handling system, > that creates an error logging chain is an example of just how complex > this can become. You gain all of this functionality automatically > through exception mechanisms; without all of the complexity. When writing the C code for the new regex module I thought that it would've been easier if I could've used exceptions to propagate errors and unwind the stack, instead of having to return an error code which had to be checked by the caller, and then have the caller explicitly return an error code to /its/ caller. Automatic garbage collection would also have been nice. You don't realise how nice it is to have such things until you have to go without them. From no.email at nospam.invalid Thu Dec 2 13:09:30 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 02 Dec 2010 10:09:30 -0800 Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> Message-ID: <7xvd3crqqt.fsf@ruckus.brouhaha.com> MRAB writes: > When writing the C code for the new regex module I thought that it > would've been easier if I could've used exceptions to propagate errors > and unwind the stack, instead of having to return an error code which > had to be checked by the caller, and then have the caller explicitly > return an error code to /its/ caller. That's called longjmp. > Automatic garbage collection would also have been nice. alloca might help. From tjreedy at udel.edu Thu Dec 2 13:13:10 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 02 Dec 2010 13:13:10 -0500 Subject: Comparison with False - something I don't understand In-Reply-To: References: Message-ID: Aside from the other issues raised, I will just note that is more common to return None when there is no answer (for whatever reason) rather than False and explicitly compare 'is None' than 'is False'. -- Terry Jan Reedy From usernet at ilthio.net Thu Dec 2 13:16:03 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 2 Dec 2010 18:16:03 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <7xvd3crqqt.fsf@ruckus.brouhaha.com> Message-ID: On 2010-12-02, Paul Rubin wrote: > MRAB writes: >> When writing the C code for the new regex module I thought that it >> would've been easier if I could've used exceptions to propagate errors >> and unwind the stack, instead of having to return an error code which >> had to be checked by the caller, and then have the caller explicitly >> return an error code to /its/ caller. > > That's called longjmp. The problem is that you might have partially allocated data structures that you need to free before you can go anywhere. Jumping up several levels, without letting the intermediate levels do their cleanup could easily lead to a memory leak or worse. From python.list at tim.thechases.com Thu Dec 2 13:18:42 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 02 Dec 2010 12:18:42 -0600 Subject: Some syntactic sugar proposals In-Reply-To: <215bc600-d3aa-4c39-adfd-d46ea2843ee7@i32g2000pri.googlegroups.com> References: <215bc600-d3aa-4c39-adfd-d46ea2843ee7@i32g2000pri.googlegroups.com> Message-ID: <4CF7E302.8070103@tim.thechases.com> On 12/02/2010 10:39 AM, Mark Dickinson wrote: > On Nov 15, 12:46 pm, Tim Chase wrote: >> On 11/15/2010 12:39 AM, Dmitry Groshev wrote: >> >>> x in range optimisation >> >> I've often thought this would make a nice O(1)-test lookup on an >> xrange() generator. > > An O(1) test for 'x in' is implemented in Python 3.2, > at least provided that x has type 'int', 'long' or 'bool'. (If x is > an instance of a subclass of int or long, then there's a risk that the > semantics of the membership test have been changed by an explicitly > overridden __eq__, so Python wimps out and falls back to the O(n) > algorithm in that case.) Drat, bested again by the python time-machine. Thanks for bringing that to my attention. -tkc From jlconlin at gmail.com Thu Dec 2 13:22:48 2010 From: jlconlin at gmail.com (Jeremy) Date: Thu, 2 Dec 2010 10:22:48 -0800 (PST) Subject: How can I define class methods outside of the class? References: <5007196a-0366-41ed-ae8d-8a1633a22dff@r31g2000prg.googlegroups.com> <87b6efa0-0d24-4858-a37c-d104c3b2c12d@c13g2000prc.googlegroups.com> Message-ID: <6eb1baa2-3553-4315-b7e9-02d0b2688c92@f20g2000prn.googlegroups.com> On Dec 2, 10:26?am, "bruno.desthuilli... at gmail.com" wrote: > On 2 d?c, 15:45, Jeremy wrote: > > > > > > > On Dec 1, 10:47?pm, James Mills wrote: > > > > On Thu, Dec 2, 2010 at 3:36 PM, Jeremy wrote: > > > > I have some methods that I need (would like) to define outside of the > > > > class. ?I know this can be done by defining the function and then > > > > setting it equal to some member of an instance of the class. ?But, > > > > because of the complexity of what I'm doing (I have to set many > > > > functions as class methods) I would rather not do this. ?Can someone > > > > show me how to do this? ?Is it even possible? ?Can decorators be used > > > > here? > > > > Do you mean something like this ? > > > > @classmethod > > > def foo(cls): > > > ? ? print "I am the foo classmethod on %r" % cls > > > > class Foo(object): > > > ? ? pass > > > > Foo.foo = foo > > > > cheers > > > James > > > Thanks, James. ?That is almost exactly what I want. ?However, I want to avoid doing > > > Foo.foo = foo > > > Is this going to be possible? ? > > def patch(cls): > ? ?def _patch(func): > ? ? ? ?setattr(cls, func.__name__, func) > ? ? ? ?return func > ? ?return _patch > > class Foo(object): pass > > @patch(Foo) > def bar(self): > ? ? print self > > f = Foo() > f.bar() Yes! This is what I was looking for. Thanks! Jeremy From tjreedy at udel.edu Thu Dec 2 13:31:30 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 02 Dec 2010 13:31:30 -0500 Subject: Comparison with False - something I don't understand In-Reply-To: References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> Message-ID: On 12/2/2010 9:56 AM, Harishankar wrote: > There are some reasons why I hate exceptions but that is a different > topic. However, in short I can say that personally: > > 1. I hate try blocks which add complexity to the code when none is > needed. Try blocks make code much more unreadable in my view and I use it > only for the built-in exceptions when absolutely needed. > > 2. I prefer the less irksome True or False to do error checking. > Exceptions seem too heavyweight for simple problems. It turns out that try block are computationally lighter weight (faster) for normal execution ;-) > 3. Philosophically I think exception handling is the wrong approach to > error management. I have never grown up programming with exceptions in C > and I couldn't pick up the habit with python either. Did I mention that I > detest try blocks? try blocks seem ugly and destroy code clarity at least > in my view. And enclosing single statements under separate try blocks > seem to add a lot of clutter. Having also come to Python directly from C, I can sympathize. It took me a while to adjust. -- Terry Jan Reedy From no.email at nospam.invalid Thu Dec 2 13:33:40 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 02 Dec 2010 10:33:40 -0800 Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <7xvd3crqqt.fsf@ruckus.brouhaha.com> Message-ID: <7xr5e0rpmj.fsf@ruckus.brouhaha.com> Tim Harig writes: >> That's called longjmp. > > The problem is that you might have partially allocated data structures > that you need to free before you can go anywhere. Alloca can help with that since the stack stuff gets released by the longjmp. Alternatively you can have an auxiliary stack of cleanup records that the longjmp handler walks through. Of course if you do that, you're halfway towards reinventing exceptions. From invalid at invalid.invalid Thu Dec 2 13:36:58 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 2 Dec 2010 18:36:58 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <7xvd3crqqt.fsf@ruckus.brouhaha.com> Message-ID: On 2010-12-02, Paul Rubin wrote: > MRAB writes: >> When writing the C code for the new regex module I thought that it >> would've been easier if I could've used exceptions to propagate errors >> and unwind the stack, instead of having to return an error code which >> had to be checked by the caller, and then have the caller explicitly >> return an error code to /its/ caller. > > That's called longjmp. In theory. In practice, using longjump for that without blowing your foot off isn't easy. >> Automatic garbage collection would also have been nice. > > alloca might help. And that's almost as easy to screw up. :) -- Grant Edwards grant.b.edwards Yow! I want EARS! I want at two ROUND BLACK EARS gmail.com to make me feel warm 'n secure!! From python at mrabarnett.plus.com Thu Dec 2 13:41:13 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 02 Dec 2010 18:41:13 +0000 Subject: Comparison with False - something I don't understand In-Reply-To: <7xvd3crqqt.fsf@ruckus.brouhaha.com> References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <7xvd3crqqt.fsf@ruckus.brouhaha.com> Message-ID: <4CF7E849.8040902@mrabarnett.plus.com> On 02/12/2010 18:09, Paul Rubin wrote: > MRAB writes: >> When writing the C code for the new regex module I thought that it >> would've been easier if I could've used exceptions to propagate errors >> and unwind the stack, instead of having to return an error code which >> had to be checked by the caller, and then have the caller explicitly >> return an error code to /its/ caller. > > That's called longjmp. > The problem with that is that the caller might have to do some tidying up, such as deallocation. Exceptions give the caller the chance of catching it (ideally in a 'finally' block), tidying up, and then propagating. >> Automatic garbage collection would also have been nice. > > alloca might help. I didn't know about that. It looks like that's allocated on the stack, and the allocation I'm talking must be on the heap, so it's not suitable anyway. From iamforufriends at gmail.com Thu Dec 2 13:44:46 2010 From: iamforufriends at gmail.com (kate for free dating) Date: Thu, 2 Dec 2010 10:44:46 -0800 (PST) Subject: hai this is kate, im staing near u, date with me for free... girls and boyz... Message-ID: hai this is kate, im staing near u, date with me for free... girls and boyz... http://x2c.eu/5i http://x2c.eu/5i http://x2c.eu/5i http://x2c.eu/5i From ethan at stoneleaf.us Thu Dec 2 13:51:18 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 02 Dec 2010 10:51:18 -0800 Subject: DBF (VFP) to XLS (Excel) in pure Python In-Reply-To: <5ddf7758-754f-4649-be1e-85cdee7860e5@y23g2000yqd.googlegroups.com> References: <084f9299-b2b3-440f-b83f-9fbe42220221@j19g2000prh.googlegroups.com> <5ddf7758-754f-4649-be1e-85cdee7860e5@y23g2000yqd.googlegroups.com> Message-ID: <4CF7EAA6.1050906@stoneleaf.us> kirby.urner at gmail.com wrote: Some ideas: for (i, name) in enumerate(thedbf.field_names): sheet1.write(0, i, name, header_style) thetype = thedbf.type(name) thelen, thedec = thedbf.size(name) if thetype == "M": thelen = 100 elif thelen == 0: thelen = 1 colwidth = max(len(name), int(thelen)) sheet1.col(i).width = colwidth * 310 messages = [] for row, record in enumerate(thedbf): . . . > Same error with: > >>>> thetable = dbf.VfpTable(thefile) >>>> thetable.close(keep_memos=True) Does this still happen with the latest code? (Not yet on PyPI for those following along -- hope to get a new package released this week.) ~Ethan~ From usernet at ilthio.net Thu Dec 2 13:51:48 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 2 Dec 2010 18:51:48 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <7xvd3crqqt.fsf@ruckus.brouhaha.com> <7xr5e0rpmj.fsf@ruckus.brouhaha.com> Message-ID: On 2010-12-02, Paul Rubin wrote: > Tim Harig writes: >>> That's called longjmp. >> >> The problem is that you might have partially allocated data structures >> that you need to free before you can go anywhere. > > Alloca can help with that since the stack stuff gets released by the > longjmp. Alternatively you can have an auxiliary stack of cleanup alloca() only helps if you actually *want* the data stored on the stack. There are many reasons one might prefer or need that the data in the heap. > longjmp. Alternatively you can have an auxiliary stack of cleanup > records that the longjmp handler walks through. Of course if you do Only if you already have pointers to *all* of the data structures at the point where you put your setjmp(). This approach is error prone. > records that the longjmp handler walks through. Of course if you do > that, you're halfway towards reinventing exceptions. Exactly. From ozric at web.de Thu Dec 2 14:01:05 2010 From: ozric at web.de (chris) Date: Thu, 2 Dec 2010 11:01:05 -0800 (PST) Subject: aggregation for a nested dict Message-ID: Hi, i would like to parse many thousand files and aggregate the counts for the field entries related to every id. extract_field grep the identifier for the fields with regex. result = [ { extract_field("id", line) : [extract_field("field1", line),extract_field("field2", line)]} for line in FILE ] result gives me. {'a: ['0', '84']}, {'a': ['0', '84']}, {'b': ['1000', '83']}, {'b': ['0', '84']}, i like to aggregate them for every line or maybe file and get after the complete parsing procedure the possibility to count the amount of ids having > 0 entries in '83'. {'a: {'0':2, '84':2}} {'b': {'1000':1,'83':1,'84':1} } My current solution with mysql is really slow. Many thanks for advance. Christian From no.email at nospam.invalid Thu Dec 2 14:04:07 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 02 Dec 2010 11:04:07 -0800 Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <7xvd3crqqt.fsf@ruckus.brouhaha.com> <7xr5e0rpmj.fsf@ruckus.brouhaha.com> Message-ID: <7xmxooro7s.fsf@ruckus.brouhaha.com> Tim Harig writes: >> longjmp. Alternatively you can have an auxiliary stack of cleanup >> records that the longjmp handler walks through. Of course if you do > > Only if you already have pointers to *all* of the data structures at > the point where you put your setjmp(). The setjmp point only has to know where the aux stack is and its depth when the longjmp happens. The cleanup records contain any necessary pointers to data structures that need freeing. That is basically how try/finally would do it too. This is pretty standard stuff. From usernet at ilthio.net Thu Dec 2 14:15:50 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 2 Dec 2010 19:15:50 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <7xvd3crqqt.fsf@ruckus.brouhaha.com> <7xr5e0rpmj.fsf@ruckus.brouhaha.com> <7xmxooro7s.fsf@ruckus.brouhaha.com> Message-ID: On 2010-12-02, Paul Rubin wrote: > Tim Harig writes: >>> longjmp. Alternatively you can have an auxiliary stack of cleanup >>> records that the longjmp handler walks through. Of course if you do >> >> Only if you already have pointers to *all* of the data structures at >> the point where you put your setjmp(). > > The setjmp point only has to know where the aux stack is and its depth > when the longjmp happens. The cleanup records contain any necessary > pointers to data structures that need freeing. That is basically how > try/finally would do it too. This is pretty standard stuff. I am not talking about what setjmp() has to do, I am talking about what *you* have to do after setjmp() returns. If you have allocated memory in intermediate functions and you don't have a reference to them outside of the functions that longjmp() bypasses from returning properly (and thus either not clearning data structures or returning a reference to those data structures as it normally would) then you have potential memory leaks, dangling pointers, etc. I am not saying that this cannot be done. What I am saying is that it is inherently error prone. From python at mrabarnett.plus.com Thu Dec 2 14:49:20 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 02 Dec 2010 19:49:20 +0000 Subject: aggregation for a nested dict In-Reply-To: References: Message-ID: <4CF7F840.9060000@mrabarnett.plus.com> On 02/12/2010 19:01, chris wrote: > Hi, > > i would like to parse many thousand files and aggregate the counts for > the field entries related to every id. > > extract_field grep the identifier for the fields with regex. > > result = [ { extract_field("id", line) : [extract_field("field1", > line),extract_field("field2", line)]} for line in FILE ] > > result gives me. > {'a: ['0', '84']}, > {'a': ['0', '84']}, > {'b': ['1000', '83']}, > {'b': ['0', '84']}, > > i like to aggregate them for every line or maybe file and get after > the complete parsing procedure > the possibility to count the amount of ids having> 0 entries in > '83'. > > {'a: {'0':2, '84':2}} > {'b': {'1000':1,'83':1,'84':1} } > > My current solution with mysql is really slow. > result = [ {'a': ['0', '84']}, {'a': ['0', '84']}, {'b': ['1000', '83']}, {'b': ['0', '84']}, ] from collections import defaultdict aggregates = defaultdict(lambda: defaultdict(int)) for entry in result: for key, values in entry.items(): for v in values: aggregates[key][v] += 1 print(aggregates) From steve at holdenweb.com Thu Dec 2 14:50:08 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 02 Dec 2010 14:50:08 -0500 Subject: Comparison with False - something I don't understand In-Reply-To: References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> Message-ID: On 12/2/2010 1:31 PM, Terry Reedy wrote: > It turns out that try block are computationally lighter weight (faster) > for normal execution ;-) Though that alone would hardly be sufficient reason to use them. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From python at mrabarnett.plus.com Thu Dec 2 14:54:33 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 02 Dec 2010 19:54:33 +0000 Subject: Comparison with False - something I don't understand In-Reply-To: References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <7xvd3crqqt.fsf@ruckus.brouhaha.com> <7xr5e0rpmj.fsf@ruckus.brouhaha.com> <7xmxooro7s.fsf@ruckus.brouhaha.com> Message-ID: <4CF7F979.1080108@mrabarnett.plus.com> On 02/12/2010 19:15, Tim Harig wrote: > On 2010-12-02, Paul Rubin wrote: >> Tim Harig writes: >>>> longjmp. Alternatively you can have an auxiliary stack of cleanup >>>> records that the longjmp handler walks through. Of course if you do >>> >>> Only if you already have pointers to *all* of the data structures at >>> the point where you put your setjmp(). >> >> The setjmp point only has to know where the aux stack is and its depth >> when the longjmp happens. The cleanup records contain any necessary >> pointers to data structures that need freeing. That is basically how >> try/finally would do it too. This is pretty standard stuff. > > I am not talking about what setjmp() has to do, I am talking about what > *you* have to do after setjmp() returns. If you have allocated memory in > intermediate functions and you don't have a reference to them outside of > the functions that longjmp() bypasses from returning properly (and thus > either not clearning data structures or returning a reference to those data > structures as it normally would) then you have potential memory leaks, > dangling pointers, etc. > > I am not saying that this cannot be done. What I am saying is that it > is inherently error prone. Automatic garbage collection is nice to have when using exceptions precisely because it's automatic, so unwinding the stack is much safer. From clp2 at rebertia.com Thu Dec 2 15:07:35 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 2 Dec 2010 12:07:35 -0800 Subject: aggregation for a nested dict In-Reply-To: References: Message-ID: On Thu, Dec 2, 2010 at 11:01 AM, chris wrote: > Hi, > > i would like to parse many thousand files and aggregate the counts for > the field entries related to every id. > > extract_field grep the identifier for the fields with regex. > > result = [ { extract_field("id", line) : [extract_field("field1", > line),extract_field("field2", line)]} ?for line ?in FILE ] > > result gives me. > {'a: ['0', '84']}, > {'a': ['0', '84']}, > {'b': ['1000', '83']}, > {'b': ['0', '84']}, > > i like to aggregate them for every line or maybe file and get after > the complete parsing procedure > the possibility to count the amount of ids ?having > 0 entries in > '83'. > > {'a: {'0':2, '84':2}} > {'b': {'1000':1,'83':1,'84':1} } Er, what happened to the '0' for 'b'? > My current solution with mysql is really slow. Untested: # requires Python 2.7+ due to Counter from collections import defaultdict, Counter FIELDS = ["field1", "field2"] id2counter = defaultdict(Counter) for line in FILE: identifier = extract_field("id", line) counter = id2counter[identifier] for field_name in FIELDS: field_val = int(extract_field(field_name, line)) counter[field_val] += 1 print(id2counter) print(sum(1 for counter in id2counter.values() if counter[83])) Cheers, Chris -- http://blog.rebertia.com From __peter__ at web.de Thu Dec 2 15:15:06 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 02 Dec 2010 21:15:06 +0100 Subject: aggregation for a nested dict References: Message-ID: chris wrote: > Hi, > > i would like to parse many thousand files and aggregate the counts for > the field entries related to every id. > > extract_field grep the identifier for the fields with regex. > > result = [ { extract_field("id", line) : [extract_field("field1", > line),extract_field("field2", line)]} for line in FILE ] > > result gives me. > {'a: ['0', '84']}, > {'a': ['0', '84']}, > {'b': ['1000', '83']}, > {'b': ['0', '84']}, > > i like to aggregate them for every line or maybe file and get after > the complete parsing procedure > the possibility to count the amount of ids having > 0 entries in > '83'. > > {'a: {'0':2, '84':2}} > {'b': {'1000':1,'83':1,'84':1} } > > My current solution with mysql is really slow. >>> def rows(lines): ... for line in lines: ... yield extract_field("id", line), [extract_field(name, line) for name in "field1", "field2"] ... >>> for row in rows(lines): ... print row ... ('a', ['0', '84']) ('b', ['1000', '83']) ('a', ['0', '84']) ('b', ['0', '84']) >>> from collections import defaultdict >>> class defaultdict(defaultdict): # omit that in your real code ... def __repr__(self): return repr(dict(self)) ... >>> outer = defaultdict(lambda: defaultdict(int)) >>> for key, values in rows(lines): ... inner = outer[key] ... for v in values: ... inner[v] += 1 ... >>> outer {'a': {'0': 2, '84': 2}, 'b': {'83': 1, '1000': 1, '84': 1, '0': 1}} From no.email at nospam.invalid Thu Dec 2 15:21:28 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 02 Dec 2010 12:21:28 -0800 Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <7xvd3crqqt.fsf@ruckus.brouhaha.com> <7xr5e0rpmj.fsf@ruckus.brouhaha.com> <7xmxooro7s.fsf@ruckus.brouhaha.com> Message-ID: <7xipzcrkmv.fsf@ruckus.brouhaha.com> Tim Harig writes: > I am not talking about what setjmp() has to do, I am talking about what > *you* have to do after setjmp() returns. If you have allocated memory in > intermediate functions and you don't have a reference to them outside of > the functions that longjmp() bypasses from returning properly (and thus > either not clearning data structures or returning a reference to those data > structures as it normally would) then you have potential memory leaks, > dangling pointers, etc. Sure, that's what the aux stack is for--you put any such references into it, for the setjmp handler to find later. You do that BEFORE setjmp returns, of course. > I am not saying that this cannot be done. What I am saying is that it > is inherently error prone. I suppose so, but so is everything else in C. On the overall scale of C-related hazards, this particular one isn't so bad if you code in a consistent style and are disciplined about recording the cleanups. You could also use something like an obstack, which is a stack allocated on the heap, so it persists after the control stack returns, but you can release the whole thing in one operation. From usernet at ilthio.net Thu Dec 2 15:32:47 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 2 Dec 2010 20:32:47 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <7xvd3crqqt.fsf@ruckus.brouhaha.com> <7xr5e0rpmj.fsf@ruckus.brouhaha.com> <7xmxooro7s.fsf@ruckus.brouhaha.com> Message-ID: On 2010-12-02, MRAB wrote: > On 02/12/2010 19:15, Tim Harig wrote: >> On 2010-12-02, Paul Rubin wrote: >>> Tim Harig writes: >>>>> longjmp. Alternatively you can have an auxiliary stack of cleanup >>>>> records that the longjmp handler walks through. Of course if you do >>>> >>>> Only if you already have pointers to *all* of the data structures at >>>> the point where you put your setjmp(). >>> >>> The setjmp point only has to know where the aux stack is and its depth >>> when the longjmp happens. The cleanup records contain any necessary >>> pointers to data structures that need freeing. That is basically how >>> try/finally would do it too. This is pretty standard stuff. >> >> I am not talking about what setjmp() has to do, I am talking about what >> *you* have to do after setjmp() returns. If you have allocated memory in >> intermediate functions and you don't have a reference to them outside of >> the functions that longjmp() bypasses from returning properly (and thus >> either not clearning data structures or returning a reference to those data >> structures as it normally would) then you have potential memory leaks, >> dangling pointers, etc. >> >> I am not saying that this cannot be done. What I am saying is that it >> is inherently error prone. > > Automatic garbage collection is nice to have when using exceptions > precisely because it's automatic, so unwinding the stack is much safer. Indeed. From python.list at tim.thechases.com Thu Dec 2 15:40:17 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 02 Dec 2010 14:40:17 -0600 Subject: aggregation for a nested dict In-Reply-To: <4CF7F840.9060000@mrabarnett.plus.com> References: <4CF7F840.9060000@mrabarnett.plus.com> Message-ID: <4CF80431.3050605@tim.thechases.com> On 12/02/2010 01:49 PM, MRAB wrote: > On 02/12/2010 19:01, chris wrote: >> i would like to parse many thousand files and aggregate the counts for >> the field entries related to every id. >> >> extract_field grep the identifier for the fields with regex. >> >> result = [ { extract_field("id", line) : [extract_field("field1", >> line),extract_field("field2", line)]} for line in FILE ] >> >> i like to aggregate them for every line or maybe file and get after >> the complete parsing procedure >> >> {'a: {'0':2, '84':2}} >> {'b': {'1000':1,'83':1,'84':1} } I'm not sure what happened to b['0'] based on your initial data, but assuming that was an oversight... > from collections import defaultdict > > aggregates = defaultdict(lambda: defaultdict(int)) > for entry in result: > for key, values in entry.items(): > for v in values: > aggregates[key][v] += 1 Or, if you don't need the intermediate result, you can tweak MRAB's solution and just iterate over the file(s): aggregates = defaultdict(lambda: defaultdict(int)) for line in FILE: key = extract_field("id", line) aggregates[key][extract_field("field1", line)] += 1 aggregates[key][extract_field("field2", line)] += 1 or, if you're using an older version (<2.5) that doesn't provide defaultdict, you could do something like aggregates = {} for line in FILE: key = extract_field("id", line) d = aggregates.setdefault(key, {}) for fieldname in ('field1', 'field2'): value = extract_field(fieldname, line) d[value] = d.get(value, 0) + 1 -tkc From usernet at ilthio.net Thu Dec 2 15:51:15 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 2 Dec 2010 20:51:15 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <7xvd3crqqt.fsf@ruckus.brouhaha.com> <7xr5e0rpmj.fsf@ruckus.brouhaha.com> <7xmxooro7s.fsf@ruckus.brouhaha.com> <7xipzcrkmv.fsf@ruckus.brouhaha.com> Message-ID: On 2010-12-02, Paul Rubin wrote: > Tim Harig writes: >> I am not talking about what setjmp() has to do, I am talking about what >> *you* have to do after setjmp() returns. If you have allocated memory in >> intermediate functions and you don't have a reference to them outside of >> the functions that longjmp() bypasses from returning properly (and thus >> either not clearning data structures or returning a reference to those data >> structures as it normally would) then you have potential memory leaks, >> dangling pointers, etc. > > Sure, that's what the aux stack is for--you put any such references into > it, for the setjmp handler to find later. You do that BEFORE setjmp > returns, of course. If you miss something, you are in trouble. There is a concept of variable life that is measured by how many lines separate the use of variable from its first use to its last. By using setjmp/longjmp, you effectively extend the life of these variables, potentially through several files, to at least as long as the jump. If there are several function calls in depth, there may be quite a lot of space that you have to check to make sure that you have not missed anything. >> I am not saying that this cannot be done. What I am saying is that it >> is inherently error prone. > > I suppose so, but so is everything else in C. On the overall scale of > C-related hazards, this particular one isn't so bad if you code in a > consistent style and are disciplined about recording the cleanups. > > You could also use something like an obstack, which is a stack allocated > on the heap, so it persists after the control stack returns, but you can > release the whole thing in one operation. By working the error back up through the call stack, you can keep track of the variables and allocations in each function isolated to that function. The smaller each function is, the easier and less error prone it will be to theck it is to check. That makes it much easier to make sure that you have not missed anything. Essentially, you can validate that each function correctly handles is allocations rather then having to validate the setjmp/longjmp structure as a whole. To use Joe Armstrong's phrase, "it makes the impossible merely difficult." Back to the topic, by using Python with its exceptions and garbage collection, all of this is a moot point. From ben+python at benfinney.id.au Thu Dec 2 16:06:35 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 03 Dec 2010 08:06:35 +1100 Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> Message-ID: <8739qf3mw4.fsf@benfinney.id.au> Harishankar writes: > On Thu, 02 Dec 2010 22:19:25 +1100, Ben Finney wrote: > > > More details of the problem you're trying to solve would help with > > giving specific advice. > > I'm writing functions with multiple points of failure exits. I use > return False as a way to flag the error condition rather than raising > exceptions. That's not much detail. Based only on that, I would say you should be raising an exception at each ?point of failure?, preferably of a type defined for the purpose, instead of returning False. > But under certain circumstances, the function can also return empty > lists The function returns boolean, list, and None types? That's very much a case where the function is trying to do too many things with the return value. Raise exceptions for exceptional cases, and define the function interface so that it's doing one clear job only. Often that involves breaking a complicated function into several collaborating functions with simpler interfaces. -- \ ?Pinky, are you pondering what I'm pondering?? ?Umm, I think | `\ so, Brain, but three men in a tub? Ooh, that's unsanitary!? | _o__) ?_Pinky and The Brain_ | Ben Finney From prog at vtr.net Thu Dec 2 16:45:44 2010 From: prog at vtr.net (craf) Date: Thu, 02 Dec 2010 18:45:44 -0300 Subject: Uso de variable Global Message-ID: <1291326344.4743.5.camel@cristian-desktop> Hola. Estoy probando Tkinter y escrib? este peque?o c?digo el cual crea un formulario con un textbox y un bot?n. Al ingresar un dato en el textbox y presionar el bot?n, se imprime en la consola el valor. ---CODE-------------------- from Tkinter import * def muestra(): print(valor.get()) class App: def __init__(self,master): global valor valor = StringVar() e = Entry(master,textvariable=valor).pack() b = Button(master,text='Mostrar',command=muestra).pack() master = Tk() app = App(master) master.mainloop() ----------------------------- Funciona, pero tuve que hacer uso de una variable Global. Pregunta: ?Es valida esta forma?, ?Se puede hacer de otra forma, sin ocuparla?. Saludos. Cristian From pau.cervera at gmail.com Thu Dec 2 17:04:24 2010 From: pau.cervera at gmail.com (Pau Cervera) Date: Thu, 2 Dec 2010 23:04:24 +0100 Subject: [Python-es] Uso de variable Global In-Reply-To: <1291326344.4743.5.camel@cristian-desktop> References: <1291326344.4743.5.camel@cristian-desktop> Message-ID: Ni idea de Tkinter, pero ?no puedes almacenar *valor* en una variable de instancia de App y convertir la funci?n *muestra* en un m?todo de la classe App que teng aceso a las variables de instancia de App? ----- Pau Python..., what else? 2010/12/2 craf > Hola. > > > Estoy probando Tkinter y escrib? este peque?o c?digo el cual crea un > formulario con un textbox y un bot?n. Al ingresar un dato en el textbox > y presionar el bot?n, se imprime en la consola el valor. > > > ---CODE-------------------- > > from Tkinter import * > > def muestra(): > print(valor.get()) > > class App: > def __init__(self,master): > global valor > valor = StringVar() > e = Entry(master,textvariable=valor).pack() > b = Button(master,text='Mostrar',command=muestra).pack() > > > master = Tk() > app = App(master) > master.mainloop() > > ----------------------------- > > Funciona, pero tuve que hacer uso de una variable Global. > > Pregunta: ?Es valida esta forma?, ?Se puede hacer de otra forma, sin > ocuparla?. > > Saludos. > > Cristian > > > > _______________________________________________ > Python-es mailing list > Python-es at python.org > http://mail.python.org/mailman/listinfo/python-es > FAQ: http://python-es-faq.wikidot.com/ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Thu Dec 2 17:06:25 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 02 Dec 2010 23:06:25 +0100 Subject: Uso de variable Global References: Message-ID: craf wrote: > Hola. > > > Estoy probando Tkinter y escrib? este peque?o c?digo el cual crea un > formulario con un textbox y un bot?n. Al ingresar un dato en el textbox > y presionar el bot?n, se imprime en la consola el valor. > > > ---CODE-------------------- > > from Tkinter import * > > def muestra(): > print(valor.get()) > > class App: > def __init__(self,master): > global valor > valor = StringVar() > e = Entry(master,textvariable=valor).pack() > b = Button(master,text='Mostrar',command=muestra).pack() pack() returns None so both e and b set to None here. In this case it doesn't matter because you don't do anything with e and b. > master = Tk() > app = App(master) > master.mainloop() > > ----------------------------- > > Funciona, pero tuve que hacer uso de una variable Global. > > Pregunta: ?Es valida esta forma?, ?Se puede hacer de otra forma, sin > ocuparla?. I'd prefer to make valor an attribute and muestra() a method: from Tkinter import * class App: def __init__(self, master): self.valor = StringVar() Entry(master, textvariable=self.valor).pack() Button(master, text='Mostrar', command=self.muestra).pack() def muestra(self): print self.valor.get() master = Tk() app = App(master) master.mainloop() From nagle at animats.com Thu Dec 2 17:11:05 2010 From: nagle at animats.com (John Nagle) Date: Thu, 02 Dec 2010 14:11:05 -0800 Subject: Comparison with False - something I don't understand In-Reply-To: References: Message-ID: <4cf81999$0$1625$742ec2ed@news.sonic.net> On 12/2/2010 10:13 AM, Terry Reedy wrote: > Aside from the other issues raised, I will just note that is more common > to return None when there is no answer (for whatever reason) rather than > False and explicitly compare 'is None' than 'is False'. The basic problem is that the original design of Python lacked a "bool" type. Classic language design error. It seems reasonable to people not familiar with programming language history to let True be equivalent to 1 and False be equivalent to 0, but it doesn't work out well. Retrofitting a "bool" type never quite works right. C/C++ went through this decades ago. The semantics of integers are clear, and the semantics of booleans are clear, but the semantics of mixed booleans and integers are not. You get questions like the one in this thread. Related questions include the semantics of x = True + True What's the value of "x"? "True"? 2? Is "+" between two "Bool" items addition, logical OR, or an error? The same problem applies to "*". The arguments on either side can be seen in PEP 285, but they gloss over the fact that the original design was botched. Similar design errors show up in other places in Python. Using "+" for concatenation seemed reasonable, but didn't scale out well, especially after NumPy's "array" type was introduced. [1,2,3] + [4,5,6] and array([1,2,3]) + array([4,5,6]) produce quite different results. Worse, what should array([1,2,3]) + [4,5,6] do? It doesn't raise an exception. I went to a talk by Alexander Stepanov at Stanford recently, where he talked about problems in the fundamentals of programming. This is one of the issues that came up. Defining addition in a way that is not associative and commutative leads to problems, and breaks generic algorithms. If the basic operators follow the expected rules, generic algorithms will work on them. That was botched in Python. John Nagle From draeath.spamtrap at gmail.com Thu Dec 2 17:44:01 2010 From: draeath.spamtrap at gmail.com (draeath) Date: Thu, 02 Dec 2010 22:44:01 GMT Subject: three column dataset - additions and deletions Message-ID: I'm going to be writing a utility that will be pulling three fields from a MySQL table. I've already got a sample dataset - there's a long int (which is a db key), a short string, and a looong string. Many rows. As it is, receive this data from the DB interface as a rather large tuple of tuples. I plan on hashing the long string field (both for convenience and security) and storing the set in a pickle. The idea is that this script will run periodically, pulling the table, and comparing the data gathered at that run to that stored by the previous, acting on changes made, and storing the current data back (to be referenced against in the next invocation) I figure it will be easy enough to determine changed hashes for a given key. What I'm unclear on is what the best type of structure to keep this data in, given that I need to modify the data after it comes in (replacing that long string with, say, an MD5 from hashlib) and both need to act on "new" rows (rows that don't exist in the 'old' data) and deleted rows (rows that only exist in the 'old' data). Keeping in mind that I'm a newbie here, and I'm probably not aware of most of the different ways to store such things. I shouldn't have any problems with the logic itself - I just know enough to know I don't know the best ways of doing things :) Any suggestions? I'm not asking for code or handholding, but some objects or datatypes to look into would be very helpful at this early stage. Thanks! From usernet at ilthio.net Thu Dec 2 17:55:53 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 2 Dec 2010 22:55:53 +0000 (UTC) Subject: three column dataset - additions and deletions References: Message-ID: On 2010-12-02, draeath wrote: > The idea is that this script will run periodically, pulling the table, > and comparing the data gathered at that run to that stored by the > previous, acting on changes made, and storing the current data back (to > be referenced against in the next invocation) So, basically, you want to store a local copy of the data and sync it to the original. > I figure it will be easy enough to determine changed hashes for a given > key. What I'm unclear on is what the best type of structure to keep this > data in, given that I need to modify the data after it comes in > (replacing that long string with, say, an MD5 from hashlib) and both need > to act on "new" rows (rows that don't exist in the 'old' data) and > deleted rows (rows that only exist in the 'old' data). You need to differentiate between the in memory data model and the storage model. Since this data comes from a database in the first place, I would dump it to an sqlite3 database from the beginning. You can use this to store, modify, and change the values as you receive them from the database. If you are looking for in-memory structures, then you haven't really provided us with enough information on the significance and organization of the data. From abarzua at vtr.net Thu Dec 2 17:57:11 2010 From: abarzua at vtr.net (cristian =?ISO-8859-1?Q?abarz=FAa?=) Date: Thu, 02 Dec 2010 19:57:11 -0300 Subject: [Fwd: Re: Uso de variable Global] Message-ID: <1291330631.2048.1.camel@cristian-desktop> --------- Mensaje reenviado -------- > De: Peter Otten <__peter__ at web.de> > Para: python-list at python.org > Asunto: Re: Uso de variable Global > Fecha: Thu, 02 Dec 2010 23:06:25 +0100 > Grupos de noticias: comp.lang.python > > craf wrote: > > > Hola. > > > > > > Estoy probando Tkinter y escrib? este peque?o c?digo el cual crea un > > formulario con un textbox y un bot?n. Al ingresar un dato en el textbox > > y presionar el bot?n, se imprime en la consola el valor. > > > > > > ---CODE-------------------- > > > > from Tkinter import * > > > > def muestra(): > > print(valor.get()) > > > > class App: > > def __init__(self,master): > > global valor > > valor = StringVar() > > e = Entry(master,textvariable=valor).pack() > > b = Button(master,text='Mostrar',command=muestra).pack() > > pack() returns None so both e and b set to None here. In this case it > doesn't matter because you don't do anything with e and b. > > > master = Tk() > > app = App(master) > > master.mainloop() > > > > ----------------------------- > > > > Funciona, pero tuve que hacer uso de una variable Global. > > > > Pregunta: ?Es valida esta forma?, ?Se puede hacer de otra forma, sin > > ocuparla?. > > I'd prefer to make valor an attribute and muestra() a method: > > from Tkinter import * > > class App: > def __init__(self, master): > self.valor = StringVar() > Entry(master, textvariable=self.valor).pack() > Button(master, text='Mostrar', command=self.muestra).pack() > def muestra(self): > print self.valor.get() > > master = Tk() > app = App(master) > master.mainloop() Thanks!, Sorry for the Spanish mail. Regards Cristian From prog at vtr.net Thu Dec 2 17:58:36 2010 From: prog at vtr.net (craf) Date: Thu, 02 Dec 2010 19:58:36 -0300 Subject: [Fwd: Re: Uso de variable Global] Message-ID: <1291330716.2048.2.camel@cristian-desktop> --------- Mensaje reenviado -------- > De: Peter Otten <__peter__ at web.de> > Para: python-list at python.org > Asunto: Re: Uso de variable Global > Fecha: Thu, 02 Dec 2010 23:06:25 +0100 > Grupos de noticias: comp.lang.python > > craf wrote: > > > Hola. > > > > > > Estoy probando Tkinter y escrib? este peque?o c?digo el cual crea un > > formulario con un textbox y un bot?n. Al ingresar un dato en el textbox > > y presionar el bot?n, se imprime en la consola el valor. > > > > > > ---CODE-------------------- > > > > from Tkinter import * > > > > def muestra(): > > print(valor.get()) > > > > class App: > > def __init__(self,master): > > global valor > > valor = StringVar() > > e = Entry(master,textvariable=valor).pack() > > b = Button(master,text='Mostrar',command=muestra).pack() > > pack() returns None so both e and b set to None here. In this case it > doesn't matter because you don't do anything with e and b. > > > master = Tk() > > app = App(master) > > master.mainloop() > > > > ----------------------------- > > > > Funciona, pero tuve que hacer uso de una variable Global. > > > > Pregunta: ?Es valida esta forma?, ?Se puede hacer de otra forma, sin > > ocuparla?. > > I'd prefer to make valor an attribute and muestra() a method: > > from Tkinter import * > > class App: > def __init__(self, master): > self.valor = StringVar() > Entry(master, textvariable=self.valor).pack() > Button(master, text='Mostrar', command=self.muestra).pack() > def muestra(self): > print self.valor.get() > > master = Tk() > app = App(master) > master.mainloop() > Thanks!, Sorry for the Spanish mail. Regards Cristian From burton at userful.com Thu Dec 2 18:06:59 2010 From: burton at userful.com (Burton Samograd) Date: Thu, 02 Dec 2010 16:06:59 -0700 Subject: Changing ' to " in printed representation of dictionaries Message-ID: Hello, I was wondering if there was a way to change the quote character for keys in string representation of dictionaries, so that they will be JSON equivalent. For example: >>> x = { 'x': 1, 'y': 2 } { 'x': 1, 'y': 2 } >>> `x` "{ 'x': 1, 'y': 2 }" # close but not quite a JSON string >>> `x`.replace("'", '"') '{ "x": 1, "y": 2 }' # JSON and python compatible So the question is, is there an automatic way to tell python to use " instead of ' when doing a repr of lists? Thanks. -- Burton Samograd From nobody at nowhere.com Thu Dec 2 18:12:27 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 02 Dec 2010 23:12:27 +0000 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename References: <1291124813.414884.22.camel@WOPR> Message-ID: On Thu, 02 Dec 2010 12:17:53 +0100, Peter Otten wrote: >> This was actually a critical flaw in Python 3.0, as it meant that >> filenames which weren't valid in the locale's encoding simply couldn't be >> passed via argv or environ. 3.1 fixed this using the "surrogateescape" >> encoding, so now it's only an annoyance (i.e. you can recover the original >> bytes once you've spent enough time digging through the documentation). > > Is it just that you need to harden your scripts against these byte sequences > or do you actually encounter them? If the latter, can you give some > examples? Assume that you have a Python3 script which takes filenames on the command-line. If any of the filenames contain byte sequences which aren't valid in the locale's encoding, the bytes will be decoded to characters in the range U+DC00 to U+DCFF. To recover the original bytes, you need to use 'surrogateescape' as the error handling method when decoding, e.g.: enc = sys.getfilesystemencoding() argv_bytes = [arg.encode(enc, 'surrogateescape') for arg in sys.argv] Otherwise, it will complain about not being able to encode the surrogate characters. Similarly for os.environ. For anything else, you can just use sys.setfilesystemencoding('iso-8859-1') at the beginning of the script. Decoding as ISO-8859-1 will never fail, and encoding as ISO-8859-1 will give you the original bytes. But argv and environ are decoded before your script can change the encoding, so you need to know the "trick" to undo them if you want to write a robust Python 3 script which works with byte strings in an encoding-agnostic manner (i.e. a traditional Unix script). From nobody at nowhere.com Thu Dec 2 18:32:04 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 02 Dec 2010 23:32:04 +0000 Subject: How to send an IP packet in Python? References: <6800bc0a-14f5-4262-ab0b-fb3f175e7a25@y23g2000yqd.googlegroups.com> Message-ID: On Thu, 02 Dec 2010 03:12:42 -0800, yegorov-p wrote: > I have sniffed some packet and now I would like to send it with the > help of python. > But for some reason python send that: > As you can see, python ignores my headers and creates its own. It isn't Python doing that, but the OS. At least on Unix, you need setsockopt(IP_HDRINCL) to tell the OS that the packet includes a header. It appears that Windows supports the same option: http://msdn.microsoft.com/en-us/library/ms738586%28v=VS.85%29.aspx From emile at fenx.com Thu Dec 2 18:33:05 2010 From: emile at fenx.com (Emile van Sebille) Date: Thu, 02 Dec 2010 15:33:05 -0800 Subject: Changing ' to " in printed representation of dictionaries In-Reply-To: References: Message-ID: On 12/2/2010 3:06 PM Burton Samograd said... > Hello, > > I was wondering if there was a way to change the quote character for > keys in string representation of dictionaries, so that they will be JSON > equivalent. For example: > >>>> x = { 'x': 1, 'y': 2 } > { 'x': 1, 'y': 2 } >>>> `x` > "{ 'x': 1, 'y': 2 }" # close but not quite a JSON string >>>> `x`.replace("'", '"') > '{ "x": 1, "y": 2 }' # JSON and python compatible > > So the question is, is there an automatic way to tell python to use " > instead of ' when doing a repr of lists? import json json.dumps(x) Emile From tjreedy at udel.edu Thu Dec 2 18:37:00 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 02 Dec 2010 18:37:00 -0500 Subject: Changing ' to " in printed representation of dictionaries In-Reply-To: References: Message-ID: On 12/2/2010 6:06 PM, Burton Samograd wrote: > Hello, > > I was wondering if there was a way to change the quote character for > keys in string representation of dictionaries, so that they will be JSON > equivalent. For example: > >>>> x = { 'x': 1, 'y': 2 } > { 'x': 1, 'y': 2 } >>>> `x` > "{ 'x': 1, 'y': 2 }" # close but not quite a JSON string >>>> `x`.replace("'", '"') > '{ "x": 1, "y": 2 }' # JSON and python compatible > > So the question is, is there an automatic way to tell python to use " > instead of ' when doing a repr of lists? You meant dicts rather than lists, but the issue is repr of strings. And no, there is no control of that (without subclassing strings). Note that dicts are not limited to string keys, or even keys prepresentable in json. If you want the json representation, when you know it is possible, use the json module! -- Terry Jan Reedy From python at mrabarnett.plus.com Thu Dec 2 18:54:56 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 02 Dec 2010 23:54:56 +0000 Subject: Changing ' to " in printed representation of dictionaries In-Reply-To: References: Message-ID: <4CF831D0.3090805@mrabarnett.plus.com> On 02/12/2010 23:06, Burton Samograd wrote: > Hello, > > I was wondering if there was a way to change the quote character for > keys in string representation of dictionaries, so that they will be JSON > equivalent. For example: > >>>> x = { 'x': 1, 'y': 2 } > { 'x': 1, 'y': 2 } >>>> `x` > "{ 'x': 1, 'y': 2 }" # close but not quite a JSON string >>>> `x`.replace("'", '"') > '{ "x": 1, "y": 2 }' # JSON and python compatible > > So the question is, is there an automatic way to tell python to use " > instead of ' when doing a repr of lists? > Try the "json" module. From lescoutinhovr at gmail.com Thu Dec 2 19:59:19 2010 From: lescoutinhovr at gmail.com (tivrfoa) Date: Thu, 2 Dec 2010 16:59:19 -0800 (PST) Subject: Google AI challenge: planet war. Lisp won. References: <44a8f48f-e291-463e-a042-d0cbc31a2a4e@z17g2000prz.googlegroups.com> Message-ID: On Dec 2, 3:06?pm, Xah Lee wrote: > discovered this rather late. > > Google has a AI Challenge: planet wars.http://ai-contest.com/index.php > > it started sometimes 2 months ago and ended first this month. > > the winner is G?bor Melis, with his code written in lisp. > > Congrats lispers! > > G?bor wrote a blog about it herehttp://quotenil.com/Planet-Wars-Post-Mortem.html > > (not sure if this has been mentioned here but quick search didn't find > it) > > ?Xah ?http://xahlee.org/? this game is very cool and it's hard .. argh http://www.galcon.com/flash/play.php From ozric at web.de Thu Dec 2 20:00:33 2010 From: ozric at web.de (chris) Date: Thu, 2 Dec 2010 17:00:33 -0800 (PST) Subject: aggregation for a nested dict References: <4CF7F840.9060000@mrabarnett.plus.com> Message-ID: I very appreciate all responses. It's incredible how fast it is! Cheers Christian From draeath.spamtrap at gmail.com Thu Dec 2 20:06:58 2010 From: draeath.spamtrap at gmail.com (draeath) Date: Fri, 03 Dec 2010 01:06:58 GMT Subject: three column dataset - additions and deletions References: Message-ID: On Thu, 02 Dec 2010 22:55:53 +0000, Tim Harig wrote: Thanks for taking the time to check in on this, Tim! > So, basically, you want to store a local copy of the data and sync it to > the original. In a way. I only need to store one copy of the data, and make note of changes between it and the current data. > You need to differentiate between the in memory data model and the > storage model. Since this data comes from a database in the first > place, I would dump it to an sqlite3 database from the beginning. You > can use this to store, modify, and change the values as you receive them > from the database. I thought of doing that, but given that I only need to store a single instance of the data, a simple pickle will do the job nicely (am I correct in reading that it can save/load any python object?) > If you are looking for in-memory structures, then you haven't really > provided us with enough information on the significance and organization > of the data. The data columns: Long Int, String (under 30 chars), String (over 100 chars) The rows can scale up to hundreds, perhaps thousands. The integer is the database key, the shorter string is a user name, and the longer string is an access control definition. The whole idea of this script is to check, daily, for any added or removed users - or any altered access control definition. I realize this could likely all be done from inside the database itself - but altering the DB itself is not an option (as the product vendor is very touchy about that, and altering it can null our support agreement) From ian.g.kelly at gmail.com Thu Dec 2 20:11:17 2010 From: ian.g.kelly at gmail.com (Ian) Date: Thu, 2 Dec 2010 17:11:17 -0800 (PST) Subject: Google AI challenge: planet war. Lisp won. References: <44a8f48f-e291-463e-a042-d0cbc31a2a4e@z17g2000prz.googlegroups.com> Message-ID: <83aba984-15a8-485b-b630-7d7456aab080@i41g2000vbn.googlegroups.com> On Dec 2, 5:59?pm, tivrfoa wrote: > On Dec 2, 3:06?pm, Xah Lee wrote: > > > > > discovered this rather late. > > > Google has a AI Challenge: planet wars.http://ai-contest.com/index.php > > > it started sometimes 2 months ago and ended first this month. > > > the winner is G?bor Melis, with his code written in lisp. > > > Congrats lispers! > > > G?bor wrote a blog about it herehttp://quotenil.com/Planet-Wars-Post-Mortem.html > > > (not sure if this has been mentioned here but quick search didn't find > > it) > > > ?Xah ?http://xahlee.org/? > > this game is very cool and it's hard .. arghhttp://www.galcon.com/flash/play.php For what it's worth, I recollect that the original GalCon was written in Python as part of one of the PyWeek competitions. ;-) Cheers, Ian From aahz at pythoncraft.com Thu Dec 2 20:33:47 2010 From: aahz at pythoncraft.com (Aahz) Date: 2 Dec 2010 17:33:47 -0800 Subject: Comparison with False - something I don't understand References: <4CF7B0BB.7080008@tim.thechases.com> Message-ID: In article , Harishankar wrote: > >There are some reasons why I hate exceptions but that is a different >topic. However, in short I can say that personally: > >1. I hate try blocks which add complexity to the code when none is >needed. Try blocks make code much more unreadable in my view and I use it >only for the built-in exceptions when absolutely needed. > >2. I prefer the less irksome True or False to do error checking. >Exceptions seem too heavyweight for simple problems. Please demonstrate that using ``if`` blocks for True/False is impler and cleaner than using ``try`` blocks to handle exceptions. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Think of it as evolution in action." --Tony Rand From usernet at ilthio.net Thu Dec 2 20:42:33 2010 From: usernet at ilthio.net (Tim Harig) Date: Fri, 3 Dec 2010 01:42:33 +0000 (UTC) Subject: three column dataset - additions and deletions References: Message-ID: On 2010-12-03, draeath wrote: > On Thu, 02 Dec 2010 22:55:53 +0000, Tim Harig wrote: > > Thanks for taking the time to check in on this, Tim! > >> So, basically, you want to store a local copy of the data and sync it to >> the original. > In a way. I only need to store one copy of the data, and make note of > changes between it and the current data. Perhaps I am missing a sublty that makes those statements different. >> You need to differentiate between the in memory data model and the >> storage model. Since this data comes from a database in the first >> place, I would dump it to an sqlite3 database from the beginning. You >> can use this to store, modify, and change the values as you receive them >> from the database. > I thought of doing that, but given that I only need to store a single > instance of the data, a simple pickle will do the job nicely (am I > correct in reading that it can save/load any python object?) So, you start by dumping the data from the remote server into an sqlite3 database table. What you end up with is a record=record copy of the original query (plus any other meta data that you want to add). Then, when the data changes, you apply those same changes to your local table (or just regenerate it since you seem to be pulling all of the information from the server anyway. The result is a *single instance of the data*. Why you would want to replace this with a pickle of a nested set up tuples or a homebrew on disk data structure is beyond me. Using sqlite3 is almost certainly faster and more functional then anything you are going to create without some serious work. >> If you are looking for in-memory structures, then you haven't really >> provided us with enough information on the significance and organization >> of the data. > The data columns: > Long Int, String (under 30 chars), String (over 100 chars) > The rows can scale up to hundreds, perhaps thousands. Then those are the columns that you create for your local table. > The integer is the database key, the shorter string is a user name, and > the longer string is an access control definition. The whole idea of this > script is to check, daily, for any added or removed users - or any > altered access control definition. The question is how are you going to use this information once you have mirroed it locally. Most likely, from you description, you just need to access it as a local read only data store. Now compare the differences in how you would acces the data: pickle method: 1. You have to load the entire pickle into memory. 2. Unless you add some kind of tree or indexing mechanism, you will have to walk through an average of 1/2 of the records to find the matching id. If you do use an advanced mechanism you have to create the code that inserts and locates the data. sqlite3 method: 1. You open the file using the sqlite3 connector which does not have to read all of the data into memory. 2. You use a select query to get just the record for the id that you are looking for. sqlite3 has already provided you with optimized lookup and indexing capability, as well as modification operations, etc (most likely written in C). As an added bonus, you don't have to worry about locking issues, to keep the clients from accesses the datastore and receiving an inconsistant copy, while you are making your periodic updates to the database Summary: the pickle method is reinventing the wheel. You can do what has already been done for you with the sqlite3 module (and library) that has already been written for you; but, getting anything near the same functionality is going to require considerable effort on your part; and you are probably going to have to write C to get the equivilant performance. Which seems like a better option to you? > I realize this could likely all be done from inside the database itself - > but altering the DB itself is not an option (as the product vendor is > very touchy about that, and altering it can null our support agreement) Altering the remote database is not an option; but, I am talking about modifying only your local copy. If you can rewrite your pickle file, then you can modify the sqlite3 file. From python at mrabarnett.plus.com Thu Dec 2 21:01:24 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 03 Dec 2010 02:01:24 +0000 Subject: three column dataset - additions and deletions In-Reply-To: References: Message-ID: <4CF84F74.4090807@mrabarnett.plus.com> On 03/12/2010 01:42, Tim Harig wrote: > On 2010-12-03, draeath wrote: >> On Thu, 02 Dec 2010 22:55:53 +0000, Tim Harig wrote: >> >> Thanks for taking the time to check in on this, Tim! >> >>> So, basically, you want to store a local copy of the data and sync it to >>> the original. >> In a way. I only need to store one copy of the data, and make note of >> changes between it and the current data. > > Perhaps I am missing a sublty that makes those statements different. > [snip] I take the difference to be this: The first statement says there are 2 copies, the local one and the original one, with the local one kept in synch with the original one. The second statement says there's 1 copy, plus the changes which have been made to it. From usernet at ilthio.net Thu Dec 2 21:19:54 2010 From: usernet at ilthio.net (Tim Harig) Date: Fri, 3 Dec 2010 02:19:54 +0000 (UTC) Subject: three column dataset - additions and deletions References: Message-ID: On 2010-12-03, MRAB wrote: > On 03/12/2010 01:42, Tim Harig wrote: >> On 2010-12-03, draeath wrote: >>> On Thu, 02 Dec 2010 22:55:53 +0000, Tim Harig wrote: >>> >>> Thanks for taking the time to check in on this, Tim! >>> >>>> So, basically, you want to store a local copy of the data and sync it to >>>> the original. >>> In a way. I only need to store one copy of the data, and make note of >>> changes between it and the current data. >> >> Perhaps I am missing a sublty that makes those statements different. >> > [snip] > I take the difference to be this: > > The first statement says there are 2 copies, the local one and the > original one, with the local one kept in synch with the original one. > > The second statement says there's 1 copy, plus the changes which have > been made to it. Okay, so you keep one local copy of the data pristine with what is on the server, then you want to keep what is effectively a set of local changes from the what is on the server like a patch so that when you want to access the data locally, you can generate return a local copy by applying the patch to the pristine server data. Then you want to be able to pull down and incorporate changes from the server, something like what you would do with "update" on an SCM. The informated is still changed on a record by record basis. Does that sound correct? In that case, I would use the same basic scheme that I suggested before but adding a row in the table to track the changes for each field that might be locally modified. Null would of course mark fields that have not changed. You could store the changes literaly or using some kind of diff style delta that could be applied against the pristine copy. Updating from the server works as before; but, you need to decide what happens if there is a conflict between what changes on the server and local changes. From draeath.spamtrap at gmail.com Thu Dec 2 21:36:45 2010 From: draeath.spamtrap at gmail.com (draeath) Date: Fri, 03 Dec 2010 02:36:45 GMT Subject: three column dataset - additions and deletions References: Message-ID: <1JYJo.114482$ZM.81155@en-nntp-02.dc1.easynews.com> On Fri, 03 Dec 2010 02:19:54 +0000, Tim Harig wrote: > a whole bunch of useful stuff Certainly some good points for me to chew on... thanks! From v.harishankar at gmail.com Thu Dec 2 23:36:50 2010 From: v.harishankar at gmail.com (Harishankar) Date: Fri, 3 Dec 2010 04:36:50 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> <8739qf3mw4.fsf@benfinney.id.au> Message-ID: On Fri, 03 Dec 2010 08:06:35 +1100, Ben Finney wrote: > Raise exceptions for exceptional cases, and define the function > interface so that it's doing one clear job only. Often that involves > breaking a complicated function into several collaborating functions > with simpler interfaces. This is probably what I should try to do. Of course my function returns only a list in most circumstances. Only in error does it return False. I mis-represented the None type for the empty list in my previous post, my apologies. -- Harishankar (http://harishankar.org http://lawstudentscommunity.com) From v.harishankar at gmail.com Thu Dec 2 23:42:21 2010 From: v.harishankar at gmail.com (Harishankar) Date: Fri, 3 Dec 2010 04:42:21 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> Message-ID: On Thu, 02 Dec 2010 16:52:57 +0000, Tim Harig wrote: > If you are having that issue, then you are likely placing the try blocks > at too low of a level in your code. In general you will find that most > systems have a gateway function as an entry point to the system. If > there is not one already, then create such a function in you code. The > parse function in my code above would be an example of such a gateway > function. Beneath that function, you don't need to know exactly where > the error occured, you just need to know the nature of the error and > have general error handling procedures for each kind of error that you > expect might occur. I think I might very well by using try blocks rather defensively rather than letting the code reach its logical conclusion in normal circumstances. This is why I think I find it a bit clunky. I think I understand the general trend of what you're saying. It definitely requires a mindset change. I still feel that user-defined exception classes might not be the way, but maybe I should allow the built-in exceptions which are thrown by library functions to follow its natural path upwards till it reaches the top level where it could be handled. Maybe I should handle the error only at the highest level (UI level) rather than returning False to flag errors. One of the reasons why I feared to do this is because I need to know each and every exception that might be thrown by the function and litter my top-level code with too many exception handlers. -- Harishankar (http://harishankar.org http://lawstudentscommunity.com) From nagle at animats.com Thu Dec 2 23:44:47 2010 From: nagle at animats.com (John Nagle) Date: Thu, 02 Dec 2010 20:44:47 -0800 Subject: To Thread or not to Thread....? In-Reply-To: References: Message-ID: <4cf875df$0$1586$742ec2ed@news.sonic.net> On 12/1/2010 1:24 AM, Antoine Pitrou wrote: > On Wed, 1 Dec 2010 02:45:50 +0000 > Jack Keegan wrote: > >> Hi there, >> >> I'm currently writing an application to control and take measurements during >> an experiments. This is to be done on an embedded computer running XPe so I >> am happy to have python available, although I am pretty new to it. >> The application basically runs as a state machine, which transitions through >> it's states based on inputs read in from a set of general purpose >> input/output (GPIO) lines. So when a certain line is pulled low/high, do >> something and move to another state. All good so far and since I get through >> main loop pretty quickly, I can just do a read of the GPIO lines on each >> pass through the loop and respond accordingly. > >> However, in one of the states I have to start reading in, and storing frames >> from a camera. In another, I have to start reading accelerometer data from >> an I2C bus (which operates at 400kHz). I haven't implemented either yet but >> I would imagine that, in the case of the camera data, reading a frame would >> take a large amount of time as compared to other operations. Therefore, if I >> just tried to read one (or one set of) frames on each pass through the loop >> then I would hold up the rest of the application. Conversely, as the I2C bus >> will need to be read at such a high rate, I may not be able to get the >> required data rate I need even without the camera data. This naturally leads >> me to think I need to use threads. >> As I am no expert in either I2C, cameras, python or threading I thought I >> would chance asking for some advice on the subject. Do you think I need >> threads here or would I be better off using some other method. I was >> previously toying with the idea of using generators to create weightless >> threads (as detailed in >> http://www.ibm.com/developerworks/library/l-pythrd.html) for reading the >> GPIOs. Do you think this would work in this situation? > > The main question IMO: the I2C bus operates at 400kHz, but how much > received data can it buffer? That will give you a hint as to how much > latency you can tolerate. Right. Neither Windows XPe nor Python is designed for hard real time work. Unless your peripheral devices have considerable buffering, don't expect this to work without missing a measurement once in a while. If you have to talk to the I2C interface for each bus transaction before you get another reading, so that you have to respond to the device within 2ms every time, this probably won't work. If you were writing this in C++ on QNX, which is intended for hard real-time work, you could easily meet those time requirements. I've done that, and just reading the devices took maybe 3% of a Pentium 4. Python on Windows XPe, maybe not. You'll need to test. XPe is just XP with some stuff taken out; it's not a real-time OS. A good test is to hook up a square wave generator to some I2C device you can read, and try to read it in real time, measuring the time in microseconds between each pulse. Turn up the frequency until you start missing events. That will give you a handle on how good your real time capabilities are. Note that the machine you're using matters. Some computers have stuff going on in system management mode that results in long interrupt lockout latencies. One option may be to put something like an Arduno on a USB port, and let it talk to the I2C device. See http://www.arduino.cc/playground/Learning/I2C Let it queue up and timestamp the accelerometer data, which can then be read in blocks from the USB port. If both the accelerometer data and video frames are buffered, then you can do your processing in Python without trying to meet hard real-time constraints. This is the usual approach in Windows land. John Nagle From nagle at animats.com Fri Dec 3 00:02:29 2010 From: nagle at animats.com (John Nagle) Date: Thu, 02 Dec 2010 21:02:29 -0800 Subject: three column dataset - additions and deletions In-Reply-To: References: Message-ID: <4cf87a05$0$1625$742ec2ed@news.sonic.net> On 12/2/2010 5:06 PM, draeath wrote: > On Thu, 02 Dec 2010 22:55:53 +0000, Tim Harig wrote: > > Thanks for taking the time to check in on this, Tim! > I realize this could likely all be done from inside the database itself - > but altering the DB itself is not an option (as the product vendor is > very touchy about that, and altering it can null our support agreement) A local database is probably the way to go. You're already using MySQL, so you know how to do that. You can use MySQL or SQlite on a local machine machine for your local database, while also talking to the remote MySQL database. Locally, you probably want to store the key, the short string, the MD5 of the long string, and the long string. When you get an update, put it in a temporary table, then compare that table with your permanent table. (The comparison is one line of SQL.) What you do with the differences is your problem. I have a system running which does something like this. Every three hours, it fetches PhishTank's database of a few hundred thousand phishign sites, and compares it to my local copy. Another system of mine reads the daily updates to SEC filings and updates my local database. This is all routine database stuff. If you have to work with big, persistent data sets, use a real database. That's what they are for, and they already have good algorithms for the hard stuff. Storing some local data structure with "pickle" is probably not the right approach. John Nagle From usernet at ilthio.net Fri Dec 3 00:48:57 2010 From: usernet at ilthio.net (Tim Harig) Date: Fri, 3 Dec 2010 05:48:57 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> Message-ID: On 2010-12-03, Harishankar wrote: > On Thu, 02 Dec 2010 16:52:57 +0000, Tim Harig wrote: > >> If you are having that issue, then you are likely placing the try blocks >> at too low of a level in your code. In general you will find that most >> systems have a gateway function as an entry point to the system. If >> there is not one already, then create such a function in you code. The >> parse function in my code above would be an example of such a gateway >> function. Beneath that function, you don't need to know exactly where >> the error occured, you just need to know the nature of the error and >> have general error handling procedures for each kind of error that you >> expect might occur. > > I think I might very well by using try blocks rather defensively rather > than letting the code reach its logical conclusion in normal > circumstances. This is why I think I find it a bit clunky. That was the conclusion I was coming to. > I think I understand the general trend of what you're saying. It > definitely requires a mindset change. I still feel that user-defined > exception classes might not be the way, but maybe I should allow the > built-in exceptions which are thrown by library functions to follow its > natural path upwards till it reaches the top level where it could be > handled. Look at it this way, in C you were constrained to place your error handling code around ever function that might fail. Now you are free to place the error handling code wherever it makes sense to do so. As a general rule, if, in C, your function would handle the error by passing an error return value to the calling function, then the error handling code should be higher up. > Maybe I should handle the error only at the highest level (UI level) > rather than returning False to flag errors. I don't write many UIs; but, I normally consider the UI code to be yet another subsystem. In general, I find the best place to place error handling code in the high level business logic of your application (which might be what you actually meant by UI, to me the UI code is the code that actually draws the interface), in the high level logic of the systems, and in the bounderies between subsystems. The exceptions caught at each level depend on where the logic to handle the error is best applied. > One of the reasons why I feared to do this is because I need to know each > and every exception that might be thrown by the function and litter my > top-level code with too many exception handlers. Each exception has a place where it is better handled. Wherever you find boundaries between subsystems, think about what error conditions that subsystem might encounter. Subsystems dealing with are likely to encounter io related errors, network subsystems network errors, parsers validation errors etc. Logic exceptions that indicate errors in your code should be left alone entirely so that they may be easily found. Look at the exceptions pertaining to these subsystems. For each error reaching the boundery, think about whether you have enough information within the module to handle the error in a constructive manner or whether the error handling would benefit from information further up in the program. If you have all of the information that you need then handle it in the main logic of that subsystem. If not, pass it up to the error handlers on top of the boundry. When you get there, make the same decision. In general you only need to catch a handful of exceptions at each level. The easy excpetions will be handled at lower levels. The most difficult exceptions will rise towards the top of the program until only the terminal exceptions, that cannot be resolved are left with the inevitable result that you should notify the user and exit, will remain. From steve+comp.lang.python at pearwood.info Fri Dec 3 01:46:22 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Dec 2010 06:46:22 GMT Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> On Thu, 02 Dec 2010 16:35:08 +0000, Mark Wooding wrote: >> 3. Philosophically I think exception handling is the wrong approach to >> error management. > > There are better ways to handle errors than Python's exception system. I'm curious -- what ways would they be? I'm aware of three general exception handling techniques: 1. return a sentinel value or error code to indicate an exceptional case (e.g. str.find returns -1); 2. raise an exception (e.g. nearly everything else in Python); 3. set an error code somewhere (often a global variable) and hope the caller remembers to check it; plus some de facto techniques sadly in common use: 4. dump core; 5. do nothing and produce garbage output. What else is there? -- Steven From draeath.spamtrap at gmail.com Fri Dec 3 02:15:45 2010 From: draeath.spamtrap at gmail.com (draeath) Date: Fri, 03 Dec 2010 07:15:45 GMT Subject: three column dataset - additions and deletions References: Message-ID: The only reason I want the hash is that I don't want a copy of this string laying around. I also don't need to know what it is, I just need to know if it's different. Think of this as a tripwire - if someone's user access level is changed, we find out. I still think using a separate database (sqlite or not) is entirely unnecessary. The task simply isn't large enough of a scale to justify going to that extreme. That's like cutting a string with a chainsaw. Granted, the next time I'm at my workstation I'll just give it a go and just stick with whatever turns out "best" The alternatives are what I was looking for, and you all did provide them :) So here's the goal, since it seems it's still unclear: Cron will call my script on an interval (probably once a day... so yea). The script will determine if users were added, removed, or changed. If so, an email will be constructed with generic details "users bjoe, jdoe created; user mwallace deleted; user psouter access level changed" and sent to the MUA/MTA/whatever for delivery to myself and the other admins. From no.email at nospam.invalid Fri Dec 3 02:25:15 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 02 Dec 2010 23:25:15 -0800 Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7xsjyfl3ms.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: >> There are better ways to handle errors than Python's exception system. > I'm curious -- what ways would they be? > I'm aware of three general exception handling techniques: ... > What else is there? The Erlang approach is to chop the application into a lot of very lightweight processes, and let any process that encounters an error simply crash. A monitoring process notices the crashed process and restarts it. There is a "supervision tree" of uber-monitor processes that restart crashed monitor proceses. I haven't programmed in that style myself and I'm not persuaded that it's better than what Python does, but I think it's different from the stuff on your list, which is an answer to your "what else is there". I do know that they write some complex, very high reliability systems (phone switches) in Erlang. From usernet at ilthio.net Fri Dec 3 03:43:18 2010 From: usernet at ilthio.net (Tim Harig) Date: Fri, 3 Dec 2010 08:43:18 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> <7xsjyfl3ms.fsf@ruckus.brouhaha.com> Message-ID: On 2010-12-03, Paul Rubin wrote: > Steven D'Aprano writes: >>> There are better ways to handle errors than Python's exception system. >> I'm curious -- what ways would they be? >> I'm aware of three general exception handling techniques: ... >> What else is there? > > The Erlang approach is to chop the application into a lot of very > lightweight processes, and let any process that encounters an error > simply crash. A monitoring process notices the crashed process and > restarts it. There is a "supervision tree" of uber-monitor processes > that restart crashed monitor proceses. I haven't programmed in that > style myself and I'm not persuaded that it's better than what Python > does, but I think it's different from the stuff on your list, which is Erlang also offers an exception syntax almost identical to Python's for use within a single process. What makes Erlang's supervisor mode of error handling superior is that it works for more then just the current vm. If a process throws an exception, the supervisor catches and handles it. If a vm dies, a supervisor from another vm takes over. If an entire computer dies, a supervisor on another computer takes over. OTP provides some extremely advanced support for supervisory structures. > an answer to your "what else is there". I do know that they write some > complex, very high reliability systems (phone switches) in Erlang. Erlang isn't what I would call a very general purpose programming language like Python; but, if you want to build highly scalable and/or highly available systemes, there really isn't anything else that comes close to it. I am not really a huge fan of the purely functional nature of the language; but, light weight processes using the actor model is the way to go for concurrent processing. The BEAM virtual machine is also a powerful system with its ability to patch systems on the fly. It has start to become the target for other languages. I know of two that are in current developement. I wouldn't mind seeing a version of Python that could leverage the power of the BEAM vm. From mwilson at the-wire.com Fri Dec 3 04:10:24 2010 From: mwilson at the-wire.com (Mel) Date: Fri, 03 Dec 2010 04:10:24 -0500 Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> Message-ID: Harishankar wrote: > I think I understand the general trend of what you're saying. It > definitely requires a mindset change. I still feel that user-defined > exception classes might not be the way, but maybe I should allow the > built-in exceptions which are thrown by library functions to follow its > natural path upwards till it reaches the top level where it could be > handled. User-defined exception classes are no big deal, and I think they're helpful. At the minimum, they're just a few lines in a module, e.g.: class SumpError (StandardError): '''Errors raised by the SUMP client.''' class SumpIdError (SumpError): '''The wrong string was returned by an ID request.''' class SumpFlagsError (SumpError): '''Illegal combination of flags.''' class SumpStageError (SumpError): '''Illegal trigger stage setting.''' This is from a module to drive some special hardware through a serial connection. At this stage in development, I don't even have try/except statements for these. It's enough that some typo will not silently put the hardware into an illegal state, and instead will report Traceback (most recent call last): File "logic_sniffer.py", line 184, in OnDeviceCapture set_sump_options (grabber) File "logic_sniffer.py", line 21, in set_sump_options sump.set_flags (demux=True, filter=True, channel_groups=0x0, external=False, inverted=False) # only 1 channel group File "/home/mwilson/sandbox/sump-analyzer/sump.py", line 160, in set_flags raise SumpFlagsError sump.SumpFlagsError Because these are subclasses of StandardError, they'll be caught by any `except StandardError`, which may or may not turn out to be a mistake. Once development is done, try/except for these will be in some window methods as part of a wxPython GUI, several call levels above the code that would raise the exceptions, up where a human user would take steps to change the way things are being done, or submit a bug report (more likely), or something. > Maybe I should handle the error only at the highest level (UI level) > rather than returning False to flag errors. > > One of the reasons why I feared to do this is because I need to know each > and every exception that might be thrown by the function and litter my > top-level code with too many exception handlers. The advantage to the exceptions, is that they only need to be recognized and caught and handled at the UI level. They don't have to be recognized and passed back up the call chain from level to level till they get to the right place -- the way out-of-band error returns have to be. Mel. From steve+comp.lang.python at pearwood.info Fri Dec 3 08:04:26 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Dec 2010 13:04:26 GMT Subject: Exception handling in Python 3.x Message-ID: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> Consider the following common exception handling idiom: def func(iterable): it = iter(iterable) try: x = next(it) except StopIteration: raise ValueError("can't process empty iterable") print(x) The intention is: * detect an empty iterator by catching StopIteration; * if the iterator is empty, raise a ValueError; * otherwise process the iterator. Note that StopIteration is an internal detail of no relevance whatsoever to the caller. Expose this is unnecessary at best and confusing at worst. In Python 2.6 this idiom works as intended: >>> func([]) Traceback (most recent call last): File "", line 1, in File "", line 6, in func ValueError: can't process empty iterable There is no sign of the StopIteration, and nor should there be. But Python 3.1 changes this behaviour, exposing the unimportant StopIteration and leading to a more complicated and confusing traceback: >>> func([]) Traceback (most recent call last): File "", line 4, in func StopIteration During handling of the above exception, another exception occurred: Traceback (most recent call last): File "", line 1, in File "", line 6, in func ValueError: can't process empty iterable I understand the rational of this approach -- it is to assist in debugging code where the except block is buggy and raises an error. But a deliberate and explicit call to raise is not a buggy except block. It is terribly inappropriate for the common use-case of catching one exception and substituting another. I note that the PEP explicitly notes this use-case, but merely sweeps it under the carpet: Open Issue: Suppressing Context As written, this PEP makes it impossible to suppress '__context__', since setting exc.__context__ to None in an 'except' or 'finally' clause will only result in it being set again when exc is raised. http://www.python.org/dev/peps/pep-3134/ Apart from this horrible idiom: def func(iterable): it = iter(iterable) failed = False try: x = next(it) except StopIteration: failed = True if failed: raise ValueError("can't process empty iterable") print(x) or similar, is there really no way to avoid these chained exceptions? -- Steven From javiervandam at gmail.com Fri Dec 3 08:12:29 2010 From: javiervandam at gmail.com (javivd) Date: Fri, 3 Dec 2010 05:12:29 -0800 (PST) Subject: Reading by positions plain text files References: <39a07597-02b9-4ef8-9ca9-93e2d2425e66@p7g2000prb.googlegroups.com> Message-ID: On Dec 1, 3:15?am, Tim Harig wrote: > On 2010-12-01, javivd wrote: > > > > > On Nov 30, 11:43?pm, Tim Harig wrote: > >> On 2010-11-30, javivd wrote: > > >> > I have a case now in wich another file has been provided (besides the > >> > database) that tells me in wich column of the file is every variable, > >> > because there isn't any blank or tab character that separates the > >> > variables, they are stick together. This second file specify the > >> > variable name and his position: > > >> > VARIABLE NAME ? ? ?POSITION (COLUMN) IN FILE > >> > var_name_1 ? ? ? ? ? ? ? ? 123-123 > >> > var_name_2 ? ? ? ? ? ? ? ? 124-125 > >> > var_name_3 ? ? ? ? ? ? ? ? 126-126 > >> > .. > >> > .. > >> > var_name_N ? ? ? ? ? ? ? ? 512-513 (last positions) > > >> I am unclear on the format of these positions. ?They do not look like > >> what I would expect from absolute references in the data. ?For instance, > >> 123-123 may only contain one byte??? which could change for different > >> encodings and how you mark line endings. ?Frankly, the use of the > >> world columns in the header suggests that the data *is* separated by > >> line endings rather then absolute position and the position refers to > >> the line number. In which case, you can use splitlines() to break up > >> the data and then address the proper line by index. ?Nevertheless, > >> you can use file.seek() to move to an absolute offset in the file, > >> if that really is what you are looking for. > > > I work in a survey research firm. the data im talking about has a lot > > of 0-1 variables, meaning yes or no of a lot of questions. so only one > > position of a character is needed (not byte), explaining the 123-123 > > kind of positions of a lot of variables. > > Then file.seek() is what you are looking for; but, you need to be aware of > line endings and encodings as indicated. ?Make sure that you open the file > using whatever encoding was used when it was generated or you could have > problems with multibyte characters affecting the offsets. Ok, I will try it and let you know. Thanks all!! From jeanmichel at sequans.com Fri Dec 3 08:44:40 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 03 Dec 2010 14:44:40 +0100 Subject: is id(self) constant over an object lifetime ? Message-ID: <4CF8F448.4030008@sequans.com> Hello fellows, I would need a unique internal identifier to an object. Can I use the object python id ? class Foo: def getUniqueIdentifier(): return id(self) This id needs to be unique and constant over the python process lifetime. JM From jeanmichel at sequans.com Fri Dec 3 08:47:48 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 03 Dec 2010 14:47:48 +0100 Subject: is id(self) constant over an object lifetime ? In-Reply-To: <4CF8F448.4030008@sequans.com> References: <4CF8F448.4030008@sequans.com> Message-ID: <4CF8F504.2000803@sequans.com> Jean-Michel Pichavant wrote: > Hello fellows, > > I would need a unique internal identifier to an object. Can I use the > object python id ? > > class Foo: > def getUniqueIdentifier(): > return id(self) > > > This id needs to be unique and constant over the python process lifetime. > > JM > erratum python process lifetime => object lifetime From sn at sncs.se Fri Dec 3 08:50:40 2010 From: sn at sncs.se (Sverker Nilsson) Date: Fri, 3 Dec 2010 05:50:40 -0800 (PST) Subject: Python assignments Message-ID: Dear friends, This is Sverker from Sweden. You probably know me better as the guy who made Guppy/Heapy: http://guppy-pe.sf.net I am currently in the process of preparing version 0.1.10 with support for Python 2.7. I will let you know when it is updated. For those who don?t know, I work as a consultant and I am looking for new assignments and I really wish to work with Heapy/Python instead of regular programming in eg Java or C++. Therefore I was wondering if any of you know any companies in the States or anywhere else that need my services. Further information about who I am and what I can do you can find on my website: http://sncs.se I appreciate all advice and information you can provide me with. So long my friends, Sverker From awilliam at whitemice.org Fri Dec 3 08:52:20 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Fri, 03 Dec 2010 08:52:20 -0500 Subject: is id(self) constant over an object lifetime ? In-Reply-To: <4CF8F448.4030008@sequans.com> References: <4CF8F448.4030008@sequans.com> Message-ID: <1291384340.3790.16.camel@linux-yu4c.site> On Fri, 2010-12-03 at 14:44 +0100, Jean-Michel Pichavant wrote: > Hello fellows, > I would need a unique internal identifier to an object. Can I use the > object python id ? > class Foo: > def getUniqueIdentifier(): > return id(self) > This id needs to be unique and constant over the python process lifetime. Return the ?identity? of an object. This is an integer (or long integer) which is guaranteed to be unique and constant for this object during its lifetime. Two objects with non-overlapping lifetimes may have the same id() value. Of course, "lifetime" is an interesting concept. If an object is serializable then this id cannot be used as an idempotent value. Personally I would never use this; if an object needs an idempotent value - create one. "import uuid" From jeanmichel at sequans.com Fri Dec 3 08:53:38 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 03 Dec 2010 14:53:38 +0100 Subject: is id(self) constant over an object lifetime ? In-Reply-To: <4CF8F448.4030008@sequans.com> References: <4CF8F448.4030008@sequans.com> Message-ID: <4CF8F662.7050603@sequans.com> Jean-Michel Pichavant wrote: > Hello fellows, > > I would need a unique internal identifier to an object. Can I use the > object python id ? > > class Foo: > def getUniqueIdentifier(): > return id(self) > > > This id needs to be unique and constant over the python process lifetime. > > JM > sorry guys " id(/object/)? Return the ?identity? of an object. This is an integer (or long integer) which is guaranteed to be unique and constant for this object during its lifetime. Two objects with non-overlapping lifetimes may have the same id() value. " Next time I promise to look at the doc before actually asking the question here :) JM From dobedani at gmx.net Fri Dec 3 09:03:41 2010 From: dobedani at gmx.net (Dobedani) Date: Fri, 3 Dec 2010 06:03:41 -0800 (PST) Subject: New to Jython - how to install setuptools? Message-ID: Hi folks, I'm new to Jython - not to Python. The good thing about Python is that there are many packages available which can be installed easily by means of setuptools. Today I installed Jython, because I'm thinking of integrating some Python code into a web application which will be hosted on a web server with Tomcat behind it plus Jython. I found this webpage and followed the instructions about installing setuptools: http://www.jython.org/jythonbook/en/1.0/appendixA.html Unfortunately, it did not work for me. These are the errors I got: C:\TEMP\jython>java -jar D:\usr\lib\jython25\jython.jar ez_setup.py Downloading http://pypi.python.org/packages/2.5/s/setuptools/setuptools-0.6c11-py2.5.egg Traceback (most recent call last): File "ez_setup.py", line 278, in main(sys.argv[1:]) File "ez_setup.py", line 212, in main from setuptools.command.easy_install import main File "C:\TEMP\jython\setuptools-0.6c11-py2.5.egg\setuptools \__init__.py", line 2, in File "C:\TEMP\jython\setuptools-0.6c11-py2.5.egg\setuptools \extension.py", line 2, in File "C:\TEMP\jython\setuptools-0.6c11-py2.5.egg\setuptools \dist.py", line 5, in File "C:\TEMP\jython\setuptools-0.6c11-py2.5.egg\setuptools\command \install.py", line 2, in File "D:\usr\lib\jython25\Lib\distutils\command\install.py", line 15, in from distutils.sysconfig import get_config_vars File "D:\usr\lib\jython25\Lib\distutils\sysconfig.py", line 29, in argv0_path = os.path.dirname(os.path.abspath(sys.executable)) File "D:\usr\lib\jython25\Lib\ntpath.py", line 492, in abspath if not isabs(path): File "D:\usr\lib\jython25\Lib\ntpath.py", line 55, in isabs s = splitdrive(s)[1] File "D:\usr\lib\jython25\Lib\ntpath.py", line 121, in splitdrive if p[1:2] == ':': TypeError: 'NoneType' object is unsubscriptable I'm suspecting the installation failed because I did not apply certain settings, but I don't even know how to go about that! Any help will be appreciated. As you'll understand I'm using Windows XP ;-) Kind regards ... From jeanmichel at sequans.com Fri Dec 3 09:04:47 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 03 Dec 2010 15:04:47 +0100 Subject: is id(self) constant over an object lifetime ? In-Reply-To: <1291384340.3790.16.camel@linux-yu4c.site> References: <4CF8F448.4030008@sequans.com> <1291384340.3790.16.camel@linux-yu4c.site> Message-ID: <4CF8F8FF.3010901@sequans.com> Adam Tauno Williams wrote: > On Fri, 2010-12-03 at 14:44 +0100, Jean-Michel Pichavant wrote: > >> Hello fellows, >> I would need a unique internal identifier to an object. Can I use the >> object python id ? >> class Foo: >> def getUniqueIdentifier(): >> return id(self) >> This id needs to be unique and constant over the python process lifetime. >> > > > > > Return the ?identity? of an object. This is an integer (or long integer) > which is guaranteed to be unique and constant for this object during its > lifetime. Two objects with non-overlapping lifetimes may have the same > id() value. > > > Of course, "lifetime" is an interesting concept. If an object is > serializable then this id cannot be used as an idempotent value. > > Personally I would never use this; if an object needs an idempotent > value - create one. "import uuid" > > Yep I saw that on the doc sorry for asking here before checking it. Anyway your uuid is an awesome suggestion. However since I'll need to send the id over xmlrpc, it needs to be marshallable, so I would need to send uuid1().hex, or something liek that. JM From hniksic at xemacs.org Fri Dec 3 09:15:46 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Fri, 03 Dec 2010 15:15:46 +0100 Subject: Exception handling in Python 3.x References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87sjyfx7ql.fsf@xemacs.org> Steven D'Aprano writes: > Consider the following common exception handling idiom: > > def func(iterable): > it = iter(iterable) > try: > x = next(it) > except StopIteration: > raise ValueError("can't process empty iterable") > print(x) Not exactly what you're looking for, but another way to express the above is: def func(iterable): for x in iterable: break else: raise ValueError("can't process empty iterable") print(x) Otherwise, I completely agree that being unable to completely replace the original exception is an annoyance at best. From data.2 at rediff.com Fri Dec 3 09:31:07 2010 From: data.2 at rediff.com (gaurav) Date: Fri, 3 Dec 2010 06:31:07 -0800 (PST) Subject: Great chance for Management work. Message-ID: <8828a40e-4a0c-4495-9429-eb56066b8896@y19g2000prb.googlegroups.com> Best site for management careers. Career in Management. http://jobscore.webs.com/executivemanager.htm http://topcareer.webs.com/businessmanagement.htm Chances for banking career listing to all over cites person can get work as bank employee. http://rojgars1.webs.com/gov.htm http://printmediajobs.webs.com/fl.htm From mdw at distorted.org.uk Fri Dec 3 09:31:43 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 03 Dec 2010 14:31:43 +0000 Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > On Thu, 02 Dec 2010 16:35:08 +0000, Mark Wooding wrote: > > There are better ways to handle errors than Python's exception system. > > I'm curious -- what ways would they be? The most obvious improvement is resumable exceptions. In general, recovering from an exceptional condition requires three activities: * doing something about the condition so that the program can continue running; * identifying some way of rejoining the program's main (unexceptional) flow of control; and * actually performing that transfer, ensuring that any necessary invariants are restored. Python's `try ... finally' helps with the last; but Python intertwines the first two, implementing both with `try ... except'. The most important consequence of this is that the logic which contains knowledge about how to fix the condition must be closer to the code that encountered the condition than the resume point is. It's therefore hard to factor out high-level policy about fixing conditions from the relatively tedious business of providing safe points at which to resume main execution. (Effectively, each section of your program which wants to avail itself of some high-level condition-fixing policy has to provide its own protocol for expressing and implementing them.) Phew. That was abstract. Can I come up with some examples? I've been writing a (sort of) compiler recently. When it encounters errors, it reports a message to the user containing the position it had reached in the source, updates a counter so that it can report a summary at the end of the run and produce a sensible exit status, and then attempts to carry on compiling as best it can. The last bit -- attempting to carry on as best it can -- needs local knowledge of what the compiler's doing and what actually went wrong. If the parser expected to find a delimiter, maybe it should pretend that it found one, for example. The other stuff, printing messages, updating counters, and so on, is all done with some condition handlers wrapped around the meat of the compiler. That's written only once. Everything that signals errors, including standard I/O functions like open-a-file, gets the same treatment. (The remaining missing ingredient is a fluid variable which tracks the current position in the source and is updated by the scanner; bits of the compiler's semantic analysis machinery will temporarily focus attention on other parts of the source using locations they saved during the parse. Implementing fluids in Python can be done with a context manager: if you don't care about concurrency then you can use simple variables; otherwise it's little fiddly and the syntax isn't very comfortable, but it's still possible.) A more familiar example, maybe, is the good old DOS `abort/retry/fail' query. Implementing such a thing in Python, as a general policy for handling I/O errors, isn't possible. Viewed narrowly, this is probably a good thing: the old DOS query was very annoying. But the difficulty of implementing this policy illustrates the missing functionality. And, of course, if DOS had a proper resumable exception system, programs could have overridden the annoying query. In general, the code which discovers an exceptional condition may have several options for how to resume. It might be possible to ignore the situation entirely and carry on regardless (`false alarm!'). It might be possible to try again (`transient failure'). Alas, the logic which is capable of implementing these options is usually too low-level and too close to the action to be able to decide among them sensibly. (Maybe a human user should be consulted -- but that can drag in user interface baggage into a low-level networking library or whatever.) Resumable exceptions provide a way out of this mess by separating the mechanics of resumption from policy of which resumption option to choose. It's easy to show that a resumable exception system can do everything that a nonresumable system (like Python's) can do (simply put all of the recovery logic at the resume point); but the converse is not true. There are some other fringe benefits to resumable exceptions. * It's usual to report a stack backtrace or similar if an exception occurs but nothing manages to resume execution. If unwinding the stack is intertwined with working out how to resume execution, then whenever you /try/ to run an applicable handler, you have to reify the stack context and stash it somewhere in case the handler doesn't complete the job. This makes raising exceptions more expensive than they need to be. * You can use the same mechanism for other kinds of communication with surrounding context. For example, Python occasionally emits `warnings', which have their own rather simple management system (using global state, so it's hard to say `don't issue MumbleWarnings while we frob the widgets' in a concurrent program). A resumable exceptions system could easily integrate warnings fully with other kinds of conditions (and avoid the concurrency problems). You could also use it for reporting progress indications, for example. Of course, there's a downside. Resumable exceptions aren't the usual kind, so people aren't used to them. I'm not sure whether resumable exceptions are actually more complicated to understand: there are more named concepts involved, but they do less and their various roles are clearer and less tangled. (The `handler' for an exceptional condition can be called just like a function. Python doesn't have nonlocal flow control distinct from its exception system, but a nonlocal transfer to a resumption point isn't conceptually very complicated.) > 1. return a sentinel value or error code to indicate an exceptional case > (e.g. str.find returns -1); This works fine if you consider failure as being unexceptional. If you're not actually expecting to find that substring, and have something sensible to do if it wasn't there, a report that it wasn't there isn't really exceptional. (I think I use str.find more frequently than str.index, so it's nice that there are both.) > 2. raise an exception (e.g. nearly everything else in Python); Raising exceptions is a more complicated business than this suggests. Python made some specific design decisions regarding its exception system; they're pretty common choices, but not, I think, the best ones. > 3. set an error code somewhere (often a global variable) and hope the > caller remembers to check it; That's less common than you might think. Usually there's some sentinel value to tell you to look at the global error code. (Obvious examples where there isn't a clear sentinel: strtol and friends, math.h.) I think we can agree that this sucks. Someone else mentioned Erlang. An Erlang system is structured as a collection of `processes' (they don't have any shared state, so they aren't really `threads') which communicate by sending messages to each other. If an Erlang process encounters a problem, it dies, and a message is sent to report its demise. Erlang processes are very cheap, it's not unusual for a system to have tens of thousands of them. > plus some de facto techniques sadly in common use: > > 4. dump core; > > 5. do nothing and produce garbage output. > > What else is there? You missed `6. assume that erroneous input is actually executable code and transfer control to it', which is a popular approach in C. -- [mdw] From __peter__ at web.de Fri Dec 3 09:42:33 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 03 Dec 2010 15:42:33 +0100 Subject: Exception handling in Python 3.x References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Consider the following common exception handling idiom: > > def func(iterable): > it = iter(iterable) > try: > x = next(it) > except StopIteration: > raise ValueError("can't process empty iterable") > print(x) > > The intention is: > > * detect an empty iterator by catching StopIteration; > * if the iterator is empty, raise a ValueError; > * otherwise process the iterator. > > Note that StopIteration is an internal detail of no relevance whatsoever > to the caller. Expose this is unnecessary at best and confusing at worst. http://mail.python.org/pipermail/python-list/2010-October/1258606.html http://mail.python.org/pipermail/python-list/2010-October/1259024.html From namekuseijin at gmail.com Fri Dec 3 09:51:44 2010 From: namekuseijin at gmail.com (namekuseijin) Date: Fri, 3 Dec 2010 06:51:44 -0800 (PST) Subject: Google AI challenge: planet war. Lisp won. References: <44a8f48f-e291-463e-a042-d0cbc31a2a4e@z17g2000prz.googlegroups.com> Message-ID: On 2 dez, 15:06, Xah Lee wrote: > discovered this rather late. > > Google has a AI Challenge: planet wars.http://ai-contest.com/index.php > > it started sometimes 2 months ago and ended first this month. > > the winner is G?bor Melis, with his code written in lisp. > > Congrats lispers! > > G?bor wrote a blog about it herehttp://quotenil.com/Planet-Wars-Post-Mortem.html > > (not sure if this has been mentioned here but quick search didn't find > it) > > ?Xah ?http://xahlee.org/? definitely cool! From lists at cheimes.de Fri Dec 3 09:58:05 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 03 Dec 2010 15:58:05 +0100 Subject: is id(self) constant over an object lifetime ? In-Reply-To: <4CF8F662.7050603@sequans.com> References: <4CF8F448.4030008@sequans.com> <4CF8F662.7050603@sequans.com> Message-ID: Am 03.12.2010 14:53, schrieb Jean-Michel Pichavant: > Next time I promise to look at the doc before actually asking the > question here :) You are misinterpreting the excerpt. You are right that the id of an object doesn't change during the lifetime of a Python process and as long as it stays inside a single process. However if you use some sort of persistence layer like pickles or an IPC mechanism like multiprocessing the id is definitely not constant. If you need something stable, I suggest you look at the uuid module. Christian From pasxal.antix at gmail.com Fri Dec 3 10:16:49 2010 From: pasxal.antix at gmail.com (Kechagias Apostolos) Date: Fri, 3 Dec 2010 17:16:49 +0200 Subject: Using python for web IM? Message-ID: Hello, We are currently working on a project which needs video and audio streaming(peer to peer). We need to know if there are any available open source libraries to embed video,audio,p2p transfer in our client OR if there is any available framework which could help us with our project. It would bereally helpful if you could also provide us some feedback on what we can use as XMPP server. -------------- next part -------------- An HTML attachment was scrubbed... URL: From hniksic at xemacs.org Fri Dec 3 10:26:19 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Fri, 03 Dec 2010 16:26:19 +0100 Subject: Exception handling in Python 3.x References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87hbeuyj1g.fsf@xemacs.org> Peter Otten <__peter__ at web.de> writes: >> Note that StopIteration is an internal detail of no relevance whatsoever >> to the caller. Expose this is unnecessary at best and confusing at worst. > > http://mail.python.org/pipermail/python-list/2010-October/1258606.html > http://mail.python.org/pipermail/python-list/2010-October/1259024.html Both of these involve suppressing the chaining at the wrong place, namely in the outer handler or, worse yet, in the exception display mechanism. Steven, on the other hand, wants his *inner* handler to express that the original exception was an implementation detail, a business exception such as StopIteration, that is completely irrelevant to the actual exception being raised. The outer handler is the wrong place to suppress the chaining because it has no way of distinguishing Steven's case from a genuine case of a new exception unexpectedly occurring during handling of the original exception. One solution would be for "raise" inside except to not use the context. For example: try: {}[1] except KeyError: 1/0 would behave as before, but: But: try: {}[1] except KeyError: raise Exception("my error") ...would raise the custom error forgetting the KeyError. From deets at web.de Fri Dec 3 11:05:20 2010 From: deets at web.de (Diez B. Roggisch) Date: Fri, 03 Dec 2010 17:05:20 +0100 Subject: position independent build of python References: Message-ID: erikj writes: > If my understanding is correct, the sys.prefix variable holds the root > directory python uses to find related files, and eg its site-packages. > > the value of sys.prefix is specified at compile time. > > it seems that on windows, when I build/install python at one location, > and > later move it to another location, python will find all its needs > relative to the new location. > > however, when I do the same on linux, python keeps looking for > its dependencies in the build location. > > is there a possibility to have it always look at a position relative > to the location of the executable ? the goal is to be able to build > python on one machine, and then simply copy the build tree to > other machines at other locations. Maybe looking at virtualenv, especially with the --no-site-packages variable set gives you a hint. AFAIK there are some hard-coded paths involved, but not inside compiled code. Maybe you can remedy that somehow. Diez From __peter__ at web.de Fri Dec 3 11:08:38 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 03 Dec 2010 17:08:38 +0100 Subject: Exception handling in Python 3.x References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> <87hbeuyj1g.fsf@xemacs.org> Message-ID: Hrvoje Niksic wrote: > Peter Otten <__peter__ at web.de> writes: > >>> Note that StopIteration is an internal detail of no relevance whatsoever >>> to the caller. Expose this is unnecessary at best and confusing at >>> worst. >> >> http://mail.python.org/pipermail/python-list/2010-October/1258606.html >> http://mail.python.org/pipermail/python-list/2010-October/1259024.html > > Both of these involve suppressing the chaining at the wrong place, > namely in the outer handler or, worse yet, in the exception display > mechanism. Steven, on the other hand, wants his *inner* handler to > express that the original exception was an implementation detail, a > business exception such as StopIteration, that is completely irrelevant > to the actual exception being raised. The outer handler is the wrong > place to suppress the chaining because it has no way of distinguishing > Steven's case from a genuine case of a new exception unexpectedly > occurring during handling of the original exception. To quote the Rolling Stones: You can't always get what you want. After rereading the original post I still don't get why the workarounds provided in those links aren't worth considering. Peter From prog at vtr.net Fri Dec 3 12:04:27 2010 From: prog at vtr.net (craf) Date: Fri, 03 Dec 2010 14:04:27 -0300 Subject: Using a window style in a Toplevel window Message-ID: <1291395867.4604.13.camel@cristian-desktop> Hi. I use Python 3.1 and Tkinter.ttk 8.5 on Ubuntu 9.10. CODE:---------------------------------------------------- module:FMain.py from tkinter import ttk from FSecondWindow import * class App: def __init__(self,master): button1 = ttk.Button(master,text='Show TopLevel',command=lambda:window()) button1.pack() master = Tk() app = App(master) style = ttk.Style() style.theme_use('clam') master.mainloop() module:FSecondWindow.py from tkinter import * from tkinter import ttk def window(): t = Toplevel() button2 = Button(t,text='Hello').pack() CODE EXPLANATION:------------------------------------------- 1. From the main module FMain.py call the window function that is located in FSecondWindow module and create a toplevel window. 2.I apply a theme called 'clam' to the master window to improve the appearance of their widgets. QUERY:-------------------------------------------------- How I can make the toplevel window also take the theme 'clam'? Thanks in advance. Regards. Cristian Abarz?a. From v.harishankar at gmail.com Fri Dec 3 12:16:58 2010 From: v.harishankar at gmail.com (Harishankar) Date: Fri, 3 Dec 2010 17:16:58 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On Fri, 03 Dec 2010 14:31:43 +0000, Mark Wooding wrote: > The most obvious improvement is resumable exceptions. This is probably what I had in mind but I just couldn't explain it the way you did below. > > In general, recovering from an exceptional condition requires three > activities: > > * doing something about the condition so that the program can continue > running; > > * identifying some way of rejoining the program's main (unexceptional) > flow of control; and > > * actually performing that transfer, ensuring that any necessary > invariants are restored. This really sums up my thoughts about exceptions better than I could have explained! I just felt instinctively that I had missed something, but it appears to be a break in logic of the code somewhere which I thought was my fault. Seems that exception handling requires a lot of forethought since the control of program execution breaks at the point of exception with no obvious way to rejoin it seamlessly whereas with an error, a simple if condition could handle the error state and resume execution from that point forward. This is the main reason why I think I used simple error codes to handle certain recoverable conditions and avoided exceptions. I quite enjoyed your post. Thank you for explaining a lot of issues which I probably could not have figured out on my own. -- Harishankar (http://harishankar.org http://lawstudentscommunity.com) From noydb00 at gmail.com Fri Dec 3 12:21:52 2010 From: noydb00 at gmail.com (noydb) Date: Fri, 3 Dec 2010 09:21:52 -0800 (PST) Subject: How to add data into exisitng Excel file at next open row? Message-ID: <2acc7858-e55b-4cfe-8e10-1c0d716a10d4@o4g2000yqd.googlegroups.com> How can you determine the next open row in an existing Excel file such that you can start adding data to the cells in that row? As in below, I want a variable in place of the 6 (row 6 in the four ws1.Cells(x,1) lines), but have no other way of knowing what row I am on besides looking to the first free cell in column A. How to do? Examples I see make it seem really complicated - this can't be that hard. Thanks for any help. worksheet = "C:\\Excel_Reports\\ea" + ea + "report"# + ".xls" xlApp = win32com.client.Dispatch("Excel.Application") xlApp.Visible = 1 xlApp.Workbooks.Open(worksheet) ## for existing file ##xlApp.SheetsInNewWorkbook = 1 ##wb = xlApp.Workbooks() ws1 = xlApp.Worksheets(1) ws1.Cells(6,1).Value = "selection" ws1.Cells(6,2).Value = count ws1.Cells(6,3).Value = epcFloat ws1.Cells(6,8).Value = currentGMT wb.SaveAs(worksheet) wb.Close(False) ## False/1 From v.harishankar at gmail.com Fri Dec 3 12:32:12 2010 From: v.harishankar at gmail.com (Harishankar) Date: Fri, 3 Dec 2010 17:32:12 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <4CF7B0BB.7080008@tim.thechases.com> Message-ID: On Thu, 02 Dec 2010 17:33:47 -0800, Aahz wrote: > Please demonstrate that using ``if`` blocks for True/False is impler and > cleaner than using ``try`` blocks to handle exceptions. It is my personal preference and coding style for certain situations I encounter in my own programs and not something that I could prove to anybody else by theory. But anyway, in certain circumstances, exceptions create a break in flow of the execution of a program that makes it non-obvious as to how to resume flow at the point of disruption especially when the exception handling mechanism is at a higher level. While an error flag can simply set an alarm and allow other code to continue and allow the calling higher-level code to handle the alarm/flag as it sees fit. -- Harishankar (http://harishankar.org http://lawstudentscommunity.com) From no.email at nospam.invalid Fri Dec 3 13:15:58 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 03 Dec 2010 10:15:58 -0800 Subject: Exception handling in Python 3.x References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7xlj46vi1t.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > def func(iterable): > it = iter(iterable) > failed = False > try: > x = next(it) > except StopIteration: > failed = True > if failed: > raise ValueError("can't process empty iterable") > print(x) Untested: from itertools import islice def func(iterable): xs = list(islice(iter(iterable), 1)) if len(xs) == 0: raise ValueError(...) print xs[0] From emile at fenx.com Fri Dec 3 13:53:08 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 03 Dec 2010 10:53:08 -0800 Subject: Comparison with False - something I don't understand In-Reply-To: <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 12/3/2010 6:31 AM Mark Wooding said... > It's easy to show that a resumable exception system can do everything > that a nonresumable system (like Python's) can do (simply put all of the > recovery logic at the resume point); but the converse is not true. > > There are some other fringe benefits to resumable exceptions. I do a lot of work in a variant of Business Basic that has always offered resumable exceptions. The closest I get in python is using import pdb;pdb.set_trace(). I wonder what it would take to allow for any exceptions occurring outside a try/except context to dump the traceback, then invoke pdb.set_trace() before bailing to allow for both investigation and possible recovery and continuance? Emile From user at compgroups.net/ Fri Dec 3 13:55:43 2010 From: user at compgroups.net/ (jaime) Date: Fri, 03 Dec 2010 12:55:43 -0600 Subject: Twisted and txJSON-RPC References: <53e3097c-edc8-4d09-8651-ec220758016f@n31g2000vbd.googlegroups.com> Message-ID: did you fix it? I have the same problem From no.email at please.post Fri Dec 3 14:28:00 2010 From: no.email at please.post (kj) Date: Fri, 3 Dec 2010 19:28:00 +0000 (UTC) Subject: Assigning to __class__ attribute Message-ID: I have a couple of questions regarding assigning to an instance's __class__ attribute. The first is illustrated by the following interaction. First I define an empty class: >>> class Spam(object): pass ... Now I define an instance of Spam and an instance of Spam's superclass: >>> x = Spam() >>> y = Spam.__mro__[1]() # (btw, is there a less uncouth way to do this???) >>> [z.__class__.__name__ for z in x, y] ['Spam', 'object'] Now I define a second empty class: >>> class Ham(object): pass ... Next, I attempt to assign the value Ham to x.__class__: >>> x.__class__ = Ham >>> [isinstance(x, z) for z in Spam, Ham] [False, True] This was the first surprise for me: assigning to the __class__ attribute not only isn't vetoed, but in fact changes the instances class: Oh-kaaaay... First question: how kosher is this sort of class transmutation through assignment to __class__? I've never seen it done. Is this because it considered something to do only as a last resort, or is it simply because the technique is not needed often, but it is otherwise perfectly ok? The second, and much bigger, surprise comes when I attempt to do the same class-switching with y: >>> y.__class__ = Ham Traceback (most recent call last): File "", line 1, in TypeError: __class__ assignment: only for heap types (If you recall, y's class is object, the superclass of x.) Apparently Spam is a "heap type" (whatever that is) but its superclass, object, isn't. This definitely rattles my notions of inheritance: since the definition of Spam was empty, I didn't expect it to have any significant properties that are not already present in its superclass. What's going on here? Is this a bug, or a feature? I can see no logical justification for allowing such class switching for only some class and not others. One last question: as the questions above make clear, I have a colossal muddle inside my head regarding Python's model of classes and inheritance. This is not for lack of trying to understand it, but, rather, for exactly the opposite reason: in my zeal to gain the fullest understanding of this topic, I think I have read too much that is incorrect, or obsolete, or incomplete... What is the most complete, definitive, excruciatingly detailed exposition of Python's class and inheritance model? I'm expressly avoiding Google to answer this question, and instead asking it here, because I suspect that there's some connection between my state of utter confusion on this topic and the ease with which the complete/definitive/highest-quality information can get lost among a huge number of Google hits to popular-but-only-partially-correct sources of information. (In fact, I *may* have already read the source I'm seeking, but subsequent readings of incorrect stuff may have overwritten the correct information in my brain.) TIA! ~kj From ethan at stoneleaf.us Fri Dec 3 15:15:36 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 03 Dec 2010 12:15:36 -0800 Subject: Exception handling in Python 3.x In-Reply-To: References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4CF94FE8.3010405@stoneleaf.us> Peter Otten wrote: > http://mail.python.org/pipermail/python-list/2010-October/1258606.html > http://mail.python.org/pipermail/python-list/2010-October/1259024.html I found #6210 on bugs.python.org -- does anyone know if there are any others regarding this issue? Or any progress on MRAB's idea? MRAB wrote: > Suggestion: an explicit 'raise' in the exception handler excludes the > context, but if you want to include it then 'raise with'. For example: > > # Exclude the context > try: > command_dict[command]() > except KeyError: > raise CommandError("Unknown command") > > # Include the context > try: > command_dict[command]() > except KeyError: > raise with CommandError("Unknown command") ~Ethan~ From goldtech at worldpost.com Fri Dec 3 15:27:04 2010 From: goldtech at worldpost.com (goldtech) Date: Fri, 3 Dec 2010 12:27:04 -0800 (PST) Subject: import module doesn't work for new package Message-ID: <1e9b4955-d60d-44f0-9b62-2ce50be35fdf@u9g2000pra.googlegroups.com> I tried install a Python - would the word be "package"? - on Ubuntu 10.10. Could you tell me how to fix? I would be grateful, is it a path problem? Thanks. Lee giga1 at giga1:~/Desktop/pykhtml-0.2$ sudo python setup.py install [sudo] password for giga1: running install running build running build_py creating build creating build/lib.linux-i686-2.6 creating build/lib.linux-i686-2.6/pykhtml copying pykhtml/dom.py -> build/lib.linux-i686-2.6/pykhtml copying pykhtml/__init__.py -> build/lib.linux-i686-2.6/pykhtml running install_lib running install_egg_info Removing /usr/local/lib/python2.6/dist-packages/PyKHTML-0.2.egg-info Writing /usr/local/lib/python2.6/dist-packages/PyKHTML-0.2.egg-info then: >>> import pykhtml Traceback (most recent call last): File "", line 1, in File "pykhtml/__init__.py", line 3, in import khtml, kdecore, kdeui, kio, dcopext ImportError: No module named khtml From ethan at stoneleaf.us Fri Dec 3 15:27:09 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 03 Dec 2010 12:27:09 -0800 Subject: Exception handling in Python 3.x In-Reply-To: References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> <87hbeuyj1g.fsf@xemacs.org> Message-ID: <4CF9529D.4050808@stoneleaf.us> Peter Otten wrote: > Hrvoje Niksic wrote: > >> Peter Otten <__peter__ at web.de> writes: >> >>>> Note that StopIteration is an internal detail of no relevance whatsoever >>>> to the caller. Expose this is unnecessary at best and confusing at >>>> worst. >>> http://mail.python.org/pipermail/python-list/2010-October/1258606.html >>> http://mail.python.org/pipermail/python-list/2010-October/1259024.html >> Both of these involve suppressing the chaining at the wrong place, >> namely in the outer handler or, worse yet, in the exception display >> mechanism. Steven, on the other hand, wants his *inner* handler to >> express that the original exception was an implementation detail, a >> business exception such as StopIteration, that is completely irrelevant >> to the actual exception being raised. The outer handler is the wrong >> place to suppress the chaining because it has no way of distinguishing >> Steven's case from a genuine case of a new exception unexpectedly >> occurring during handling of the original exception. > > To quote the Rolling Stones: You can't always get what you want. > > After rereading the original post I still don't get why the workarounds > provided in those links aren't worth considering. For me at least it's a matter of simplicity, clarity, and the Way of the Python ;) The workarounds are boiler-plate for a fairly common situation, and one of the things i _love_ about python is the *lack* of boilerplate. I think the real question is is there any progress on dealing with the Open Issue in the PEP? Open Issue: Suppressing Context As written, this PEP makes it impossible to suppress '__context__', since setting exc.__context__ to None in an 'except' or 'finally' clause will only result in it being set again when exc is raised. http://www.python.org/dev/peps/pep-3134/ ~Ethan~ From robert.kern at gmail.com Fri Dec 3 15:57:56 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 03 Dec 2010 14:57:56 -0600 Subject: Assigning to __class__ attribute In-Reply-To: References: Message-ID: On 12/3/10 1:28 PM, kj wrote: > > > I have a couple of questions regarding assigning to an instance's > __class__ attribute. > > The first is illustrated by the following interaction. First I > define an empty class: > >>>> class Spam(object): pass > ... > > Now I define an instance of Spam and an instance of Spam's superclass: >>>> x = Spam() >>>> y = Spam.__mro__[1]() # (btw, is there a less uncouth way to do this???) >>>> [z.__class__.__name__ for z in x, y] > ['Spam', 'object'] > > Now I define a second empty class: >>>> class Ham(object): pass > ... > > Next, I attempt to assign the value Ham to x.__class__: > >>>> x.__class__ = Ham >>>> [isinstance(x, z) for z in Spam, Ham] > [False, True] > > This was the first surprise for me: assigning to the __class__ > attribute not only isn't vetoed, but in fact changes the instances > class: > > Oh-kaaaay... > > First question: how kosher is this sort of class transmutation > through assignment to __class__? I've never seen it done. Is this > because it considered something to do only as a last resort, or is > it simply because the technique is not needed often, but it is > otherwise perfectly ok? Last resort for very special purposes, and only extremely rarely in production. > The second, and much bigger, surprise comes when I attempt to do > the same class-switching with y: > >>>> y.__class__ = Ham > Traceback (most recent call last): > File "", line 1, in > TypeError: __class__ assignment: only for heap types > > (If you recall, y's class is object, the superclass of x.) Apparently > Spam is a "heap type" (whatever that is) but its superclass, object, > isn't. This definitely rattles my notions of inheritance: since > the definition of Spam was empty, I didn't expect it to have any > significant properties that are not already present in its superclass. > What's going on here? Is this a bug, or a feature? I can see no > logical justification for allowing such class switching for only > some class and not others. Feature. When you have C-implemented types, you cannot safely swap out their instance's __class__. There are memory issues involved. Only subclasses of object made by the class statement (or the equivalent type(...) call), i.e. "heap types", permit this modification. object is a C-implemented type. Importantly, as for most other C-implemented types, plain object instances have no __dict__. Types and classes were unified a long time ago in Python 2.2, but there are still relevant distinctions between C-implemented types and Python-implemented types. > One last question: as the questions above make clear, I have a > colossal muddle inside my head regarding Python's model of classes > and inheritance. This is not for lack of trying to understand it, > but, rather, for exactly the opposite reason: in my zeal to gain > the fullest understanding of this topic, I think I have read too > much that is incorrect, or obsolete, or incomplete... > > What is the most complete, definitive, excruciatingly detailed > exposition of Python's class and inheritance model? I'm expressly > avoiding Google to answer this question, and instead asking it > here, because I suspect that there's some connection between my > state of utter confusion on this topic and the ease with which the > complete/definitive/highest-quality information can get lost among > a huge number of Google hits to popular-but-only-partially-correct > sources of information. (In fact, I *may* have already read the > source I'm seeking, but subsequent readings of incorrect stuff may > have overwritten the correct information in my brain.) http://www.python.org/download/releases/2.2.3/descrintro/ -- 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 arnodel at gmail.com Fri Dec 3 16:11:11 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Fri, 03 Dec 2010 21:11:11 +0000 Subject: Assigning to __class__ attribute References: Message-ID: <87oc92d0k0.fsf@gmail.com> kj writes: > I have a couple of questions regarding assigning to an instance's > __class__ attribute. > > The first is illustrated by the following interaction. First I > define an empty class: > >>>> class Spam(object): pass > ... > > Now I define an instance of Spam and an instance of Spam's superclass: >>>> x = Spam() >>>> y = Spam.__mro__[1]() # (btw, is there a less uncouth way to do this???) Yes: y = object() >>>> [z.__class__.__name__ for z in x, y] > ['Spam', 'object'] > > Now I define a second empty class: >>>> class Ham(object): pass > ... > > Next, I attempt to assign the value Ham to x.__class__: > >>>> x.__class__ = Ham >>>> [isinstance(x, z) for z in Spam, Ham] > [False, True] > > This was the first surprise for me: assigning to the __class__ > attribute not only isn't vetoed, but in fact changes the instances > class: > > Oh-kaaaay... > > First question: how kosher is this sort of class transmutation > through assignment to __class__? I've never seen it done. Is this > because it considered something to do only as a last resort, or is > it simply because the technique is not needed often, but it is > otherwise perfectly ok? It's OK as long as the slots defined in the classes are the same (using Python 3 below so no need for specifying that classes derive from object): >>> class Foo: pass ... >>> class Bar: __slots__ = 'x', 'y' ... >>> foo = Foo() >>> foo.__class__ = Bar Traceback (most recent call last): File "", line 1, in TypeError: __class__ assignment: 'Foo' object layout differs from 'Bar' >>> class Baz: __slots__ = 'x', 'y' ... >>> bar = Bar() >>> bar.__class__ = Baz > The second, and much bigger, surprise comes when I attempt to do > the same class-switching with y: > >>>> y.__class__ = Ham > Traceback (most recent call last): > File "", line 1, in > TypeError: __class__ assignment: only for heap types y is of type object, which is a builtin type. You can only switch the __class__ of an instance of a user-defined class. > (If you recall, y's class is object, the superclass of x.) Apparently > Spam is a "heap type" (whatever that is) but its superclass, object, > isn't. This definitely rattles my notions of inheritance: since > the definition of Spam was empty, I didn't expect it to have any > significant properties that are not already present in its superclass. > What's going on here? Is this a bug, or a feature? I can see no > logical justification for allowing such class switching for only > some class and not others. There is a big difference: >>> class Foo: pass >>> x, y = Foo(), object() >>> x.__dict__ {} >>> y.__dict__ Traceback (most recent call last): File "", line 1, in AttributeError: 'object' object has no attribute '__dict__' This means that you can have instance attributes for x but not for y: >>> x.myattr = 123 >>> y.myattr = 123 Traceback (most recent call last): File "", line 1, in AttributeError: 'object' object has no attribute 'myattr' This reflects the fact that x and y are a different kind of object, with a different layout so you can't hotswap their types. I imagine that the term "heap type" is used to types which are objects that live on the heap (in practice they are types defined in Python, by using a "class" statement or calling type(name, bases, attrs)) as opposed to builtin types such as object, int, str, etc... which don't live on the heap. > One last question: as the questions above make clear, I have a > colossal muddle inside my head regarding Python's model of classes > and inheritance. This is not for lack of trying to understand it, > but, rather, for exactly the opposite reason: in my zeal to gain > the fullest understanding of this topic, I think I have read too > much that is incorrect, or obsolete, or incomplete... > What is the most complete, definitive, excruciatingly detailed > exposition of Python's class and inheritance model? I learnt by reading Guido's "Unifying types and classes in Python 2.2", available here: http://www.python.org/download/releases/2.2.3/descrintro/ -- Arnaud From aahz at pythoncraft.com Fri Dec 3 16:41:58 2010 From: aahz at pythoncraft.com (Aahz) Date: 3 Dec 2010 13:41:58 -0800 Subject: Comparison with False - something I don't understand References: Message-ID: In article , Harishankar wrote: >On Thu, 02 Dec 2010 17:33:47 -0800, Aahz wrote: >> >> Please demonstrate that using ``if`` blocks for True/False is impler and >> cleaner than using ``try`` blocks to handle exceptions. > >It is my personal preference and coding style for certain situations I >encounter in my own programs and not something that I could prove to >anybody else by theory. Note carefully that I said "demonstrate", not "prove". If using ``if`` is so clearly better in some situations, you should be able to provide an example. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Think of it as evolution in action." --Tony Rand From programming at toomuchcookies.net Fri Dec 3 16:54:19 2010 From: programming at toomuchcookies.net (OAN) Date: Fri, 03 Dec 2010 22:54:19 +0100 Subject: class attribute confusion Message-ID: <4CF9670B.5020209@toomuchcookies.net> Hi, i was having a problem with class attributes initiated outside of __init__. This code is a demonstration of what i mean: class A(): mylist = [] def __init__(self): self.mylist.append(1) pass class B(A): def __init__(self): A.__init__(self) self.mylist.append(2) v = A() print 'v:',v.mylist x = B() print 'x:',x.mylist y = B() print 'y:',y.mylist z = A() print 'z:',z.mylist print 'v:',v.mylist I would expect the following result: v: [1] x: [1, 2] y: [1, 2] z: [1] v: [1] Who wouldn't, right? But actually python 2.6(.6) gives me the following result: v: [1] x: [1, 1, 2] y: [1, 1, 2, 1, 2] z: [1, 1, 2, 1, 2, 1] v: [1, 1, 2, 1, 2, 1] The four variables v,x,y and z now actually share the same 'mylist'!! To get the correct results, i have to initialize 'mylist' inside of the __init__ method! I think this behaviour is totally wrong, since it seems A.__init__(self) is changing the value inside of A() not inside of the object variable 'self' (that should be x or y)!! Could someone explain this to me, please? regards. From arnodel at gmail.com Fri Dec 3 17:11:09 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Fri, 03 Dec 2010 22:11:09 +0000 Subject: class attribute confusion References: Message-ID: <87k4jqcxs2.fsf@gmail.com> OAN writes: > Hi, > > i was having a problem with class attributes initiated outside of > __init__. This code is a demonstration of what i mean: > > class A(): > mylist = [] > def __init__(self): > self.mylist.append(1) > pass > > class B(A): > def __init__(self): > A.__init__(self) > self.mylist.append(2) > > v = A() > print 'v:',v.mylist > x = B() > print 'x:',x.mylist > y = B() > print 'y:',y.mylist > z = A() > print 'z:',z.mylist > print 'v:',v.mylist > > I would expect the following result: > > v: [1] > x: [1, 2] > y: [1, 2] > z: [1] > v: [1] > > Who wouldn't, right? But actually python 2.6(.6) gives me the > following result: > > v: [1] > x: [1, 1, 2] > y: [1, 1, 2, 1, 2] > z: [1, 1, 2, 1, 2, 1] > v: [1, 1, 2, 1, 2, 1] > > The four variables v,x,y and z now actually share the same 'mylist'!! > To get the correct results, i have to initialize 'mylist' inside of > the __init__ method! Yes. See below. > I think this behaviour is totally wrong, since it seems > A.__init__(self) is changing the value inside of A() not inside of the > object variable 'self' (that should be x or y)!! It's not wrong at all. You expect "mylist" to behave as an instance attribute, but you defined it as a class attribute. Instance attributes are naturally initialised in the __init__() method. -- Arnaud From mdw at distorted.org.uk Fri Dec 3 17:15:54 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 03 Dec 2010 22:15:54 +0000 Subject: Assigning to __class__ attribute References: Message-ID: <878w06o63p.fsf.mdw@metalzone.distorted.org.uk> kj writes: > >>> class Spam(object): pass > > Now I define an instance of Spam and an instance of Spam's superclass: > >>> x = Spam() > >>> y = Spam.__mro__[1]() # (btw, is there a less uncouth way to do this???) There's the `__bases__' attribute, which is simply a tuple of the class's direct superclasses in order. Spam.__bases__[0] will always be equal to Spam.__mro__[1] because of the way the linearization works. There's also `__base__' attribute, which seems to correspond to a PyTypeObject's `tp_base' slot; this /isn't/ always the first direct superclass; I'm not quite sure what the rules are, and it doesn't seem to be documented anywhere. > >>> [z.__class__.__name__ for z in x, y] > ['Spam', 'object'] > > >>> class Ham(object): pass > ... > > >>> x.__class__ = Ham > >>> [isinstance(x, z) for z in Spam, Ham] > [False, True] > > First question: how kosher is this sort of class transmutation > through assignment to __class__? Yep. That's allowed, and useful. Consider something like a red/black tree: red and black nodes behave differently from one another, and it would be convenient to make use of method dispatch rather than writing a bunch of conditional code; unfortunately, nodes change between being red and black occasionally. Swizzling classes lets you do this. Various other languages have similar features. The scariest is probably Smalltalk's `become: anObject' method, which actually swaps two objects. Python `__class__' assignment is similarly low-level: all it does is tweak a pointer, and it's entirely up to the program to make sure that the object's attributes are valid according to the rules for the new class. The Common Lisp Object System has CHANGE-CLASS, which is a rather more heavyweight and hairy procedure which tries to understand and cope with the differences between the two classes. > I've never seen it done. Is this because it considered something to > do only as a last resort, or is it simply because the technique is not > needed often, but it is otherwise perfectly ok? It's not needed very often, and can be surprising to readers who aren't familiar with other highly dynamic object systems, so I don't think it's particularly encouraged; but it seems like it might be the best approach in some cases. I think it's one of those things where you'll just /know/ when it's the right answer, and if you don't know that it's the right answer, it isn't. > >>> y.__class__ = Ham > Traceback (most recent call last): > File "", line 1, in > TypeError: __class__ assignment: only for heap types `Heap types' are types which are allocated dynamically. Non-heap types are ones which are dreamt up by C extensions or built into Python. I suspect that the logic here is that non-heap types in general are magical and weird, and their instances might have special C stuff attached to them, so changing their classes is a Bad Idea, though there's an extra check which catches most problems: In [1]: class foo (str): pass In [2]: class bar (object): pass In [3]: x = foo() In [4]: x.__class__ = bar TypeError: __class__ assignment: 'foo' object layout differs from 'bar' Anyway, I'd guess it's just a bug that `object' is caught this way, but it doesn't seem an especially important one. > This definitely rattles my notions of inheritance: since the > definition of Spam was empty, I didn't expect it to have any > significant properties that are not already present in its superclass. Yes, sorry. I think this is a bit poor, really, but it's hard to do a much better job. Pure Python objects are pretty simple things, really: they have a pointer to their class, and a bunch of attributes stored in a dictionary. What other languages call instance variables or methods are found using attribute lookup, which just searches the object, and then its class and its superclasses in the method resolution order. If you fiddle with `__class__', then attribute lookup searches a different bunch of classes. Nothing else needs to change -- or, at least, if it does, then you'd better do it yourself. Types implemented in C work by extending the underlying Python object structure. The magical type-specific stuff is stored in the extra space. Unfortunately, changing classes is now hard, because Python code can't even see the magic C stuff -- and, besides, a different special C type may require a different amount of space, and the CPython implementation can't cope with the idea that objects might move around in memory. Similar complications occur if one of the classes has a `__slots__' attribute: in this case, both the original and new class must have a `__slots__' attribute and they must be the same length and have the same names. > What is the most complete, definitive, excruciatingly detailed > exposition of Python's class and inheritance model? It's kind of scattered. The language reference sections 3.3 and 3.4 contain some useful information, but it's rather detailed and it's a (mostly) comprehensive list of what a bunch of strangely shaped things do rather than a presentation of a coherent model. Guido's essay `Unifying types and classes in Python 2.2' is pretty good (http://www.python.org/download/releases/2.2.3/descrintro/) and provides some of the background. Unsurprisingly, Python's object system takes (mostly good) ideas from other languages, particularly dynamic ones. Python's object system is /very/ different from what you might expect from C++, Ada and Eiffel, for example; but coming from Smalltalk, Flavors or Dylan, you might not be particularly surprised. Some knowledge of these other languages will help fill in the gaps. > I'm expressly avoiding Google to answer this question, I'd say this was sensible, except for the fact that you seem to expect a more reliable answer from Usenet. ;-) -- [mdw] From steve+comp.lang.python at pearwood.info Fri Dec 3 17:58:46 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Dec 2010 22:58:46 GMT Subject: class attribute confusion References: Message-ID: <4cf97626$0$30003$c3e8da3$5496439d@news.astraweb.com> On Fri, 03 Dec 2010 22:54:19 +0100, OAN wrote: > Hi, > > i was having a problem with class attributes initiated outside of > __init__. This code is a demonstration of what i mean: [...] > I would expect the following result: > > v: [1] > x: [1, 2] > y: [1, 2] > z: [1] > v: [1] > > Who wouldn't, right? Everybody who actually understands Python's object model. > The four variables v,x,y and z now actually share the same 'mylist'!! To > get the correct results, i have to initialize 'mylist' inside of the > __init__ method! Right. If you define a *class* attribute, it lives in the class, not the instance, and so all instances share the same value. > I think this behaviour is totally wrong, since it seems A.__init__(self) > is changing the value inside of A() not inside of the object variable > 'self' (that should be x or y)!! A.__init__(self) calls A's init method with self (either x or y) as the self parameter, but A's init method merely modifies the class attribute mylist in place. It doesn't create a new list. The behaviour you're seeing is no different from this: shared = [] a = {"spam": shared, "ham": 23} b = {"spam": shared, "ham": 42} a["spam"].append("parrot") What would you expect the value of b["spam"] to be? -- Steven From steve+comp.lang.python at pearwood.info Fri Dec 3 18:26:12 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Dec 2010 23:26:12 GMT Subject: Assigning to __class__ attribute References: Message-ID: <4cf97c94$0$30003$c3e8da3$5496439d@news.astraweb.com> On Fri, 03 Dec 2010 19:28:00 +0000, kj wrote: > This was the first surprise for me: assigning to the __class__ attribute > not only isn't vetoed, but in fact changes the instances class: > > Oh-kaaaay... > > First question: how kosher is this sort of class transmutation through > assignment to __class__? I've never seen it done. Is this because it > considered something to do only as a last resort, or is it simply > because the technique is not needed often, but it is otherwise perfectly > ok? While not exactly encouraged, it is a deliberate feature. It's not a good idea to go around randomly monkey-patching instances with a new class, and in fact Python makes some attempts to protect you from the most egregious errors, but the technique has its uses. Especially if you're swapping between two classes which you have designed to be swapped between. For instance, if you have an object that needs to display two distinct behaviours during different times of its life, then a good technique is to write two classes, one for each set of behaviours, and automatically switch between them as needed. A ring buffer is a common example: http://code.activestate.com/recipes/68429-ring-buffer/ This made it into the Python Cookbook, so it comes with the approval of Alex Martelli, which is nearly as good as the approval of Guido :) > The second, and much bigger, surprise comes when I attempt to do the > same class-switching with y: > >>>> y.__class__ = Ham > Traceback (most recent call last): > File "", line 1, in > TypeError: __class__ assignment: only for heap types > > (If you recall, y's class is object, the superclass of x.) Apparently > Spam is a "heap type" (whatever that is) but its superclass, object, > isn't. This definitely rattles my notions of inheritance: since the > definition of Spam was empty, I didn't expect it to have any significant > properties that are not already present in its superclass. What's going > on here? Is this a bug, or a feature? I can see no logical justification > for allowing such class switching for only some class and not others. That is more of a design compromise than a feature... it is unsafe to change the class of types implemented in C, for various implementation- related reasons, and so Python prohibits it. Heap types are dynamically allocated types that you create using the class statement (or the type function). They're so-called because they live in the heap. The builtin types defined in C presumably aren't dynamically allocated, but statically. Presumably they have a fixed layout in memory and don't live in the heap. Not being a C programmer, I've never cared about the implementation, only that you can't sensibly turn a str instance into an int instance by assigning to __class__ and so Python prohibits it. > One last question: as the questions above make clear, I have a colossal > muddle inside my head regarding Python's model of classes and > inheritance. This is not for lack of trying to understand it, but, > rather, for exactly the opposite reason: in my zeal to gain the fullest > understanding of this topic, I think I have read too much that is > incorrect, or obsolete, or incomplete... I suspect you're trying to make this more complicated than it actually is. You keep finding little corner cases that expose implementation details (such as the heap-types issue above) and leaping to the erroneous conclusion that because you didn't understand this tiny little corner of Python's class model, you didn't understand any of it. Python's object model is relatively simple, but it does occasionally expose a few messy corners. > What is the most complete, definitive, excruciatingly detailed > exposition of Python's class and inheritance model? That would be the source code. -- Steven From steve+comp.lang.python at pearwood.info Fri Dec 3 18:28:22 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Dec 2010 23:28:22 GMT Subject: Exception handling in Python 3.x References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> <7xlj46vi1t.fsf@ruckus.brouhaha.com> Message-ID: <4cf97d15$0$30003$c3e8da3$5496439d@news.astraweb.com> On Fri, 03 Dec 2010 10:15:58 -0800, Paul Rubin wrote: > Steven D'Aprano writes: >> def func(iterable): >> it = iter(iterable) >> failed = False >> try: >> x = next(it) >> except StopIteration: >> failed = True >> if failed: >> raise ValueError("can't process empty iterable") >> print(x) > > Untested: > > from itertools import islice > > def func(iterable): > xs = list(islice(iter(iterable), 1)) > if len(xs) == 0: > raise ValueError(...) > print xs[0] If you're intention was to make me feel better about the version above that sets a flag, you succeeded admirably! :) -- Steven From g.candia at vtr.net Fri Dec 3 19:31:21 2010 From: g.candia at vtr.net (Guillermo Candia Huerta) Date: Fri, 03 Dec 2010 21:31:21 -0300 Subject: [Python-es] Uso de variable Global In-Reply-To: References: <1291326344.4743.5.camel@cristian-desktop> Message-ID: <4CF98BD9.3030707@vtr.net> El 02/12/10 19:04, Pau Cervera escribi?: > Ni idea de Tkinter, pero ?no puedes almacenar *valor* en una variable de > instancia de App y convertir la funci?n *muestra* en un m?todo de la classe > App que teng aceso a las variables de instancia de App? > > ----- > Pau > > Python..., what else? > > > 2010/12/2 craf > >> Hola. >> >> >> Estoy probando Tkinter y escrib? este peque?o c?digo el cual crea un >> formulario con un textbox y un bot?n. Al ingresar un dato en el textbox >> y presionar el bot?n, se imprime en la consola el valor. >> >> >> ---CODE-------------------- >> >> from Tkinter import * >> >> def muestra(): >> print(valor.get()) >> >> class App: >> def __init__(self,master): >> global valor >> valor = StringVar() >> e = Entry(master,textvariable=valor).pack() >> b = Button(master,text='Mostrar',command=muestra).pack() >> >> >> master = Tk() >> app = App(master) >> master.mainloop() >> >> ----------------------------- >> >> Funciona, pero tuve que hacer uso de una variable Global. >> >> Pregunta: ?Es valida esta forma?, ?Se puede hacer de otra forma, sin >> ocuparla?. >> >> Saludos. >> >> Cristian >> >> >> >> _______________________________________________ >> Python-es mailing list >> Python-es at python.org >> http://mail.python.org/mailman/listinfo/python-es >> FAQ: http://python-es-faq.wikidot.com/ >> > puede heredar el bot?n y agregas los atributos y m?todos que necesites, en el constructor le pasas las variables que necesitas From steve+comp.lang.python at pearwood.info Fri Dec 3 19:42:42 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Dec 2010 00:42:42 GMT Subject: Exception handling in Python 3.x References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> <87hbeuyj1g.fsf@xemacs.org> Message-ID: <4cf98e82$0$30003$c3e8da3$5496439d@news.astraweb.com> On Fri, 03 Dec 2010 16:26:19 +0100, Hrvoje Niksic wrote: > Peter Otten <__peter__ at web.de> writes: > >>> Note that StopIteration is an internal detail of no relevance >>> whatsoever to the caller. Expose this is unnecessary at best and >>> confusing at worst. >> >> http://mail.python.org/pipermail/python-list/2010-October/1258606.html >> http://mail.python.org/pipermail/python-list/2010-October/1259024.html Thanks for the links Peter. > Both of these involve suppressing the chaining at the wrong place, > namely in the outer handler or, worse yet, in the exception display > mechanism. Steven, on the other hand, wants his *inner* handler to > express that the original exception was an implementation detail, a > business exception such as StopIteration, that is completely irrelevant > to the actual exception being raised. Yes, exactly! Python 3.x exposes completely irrelevant and internal details in the traceback. > The outer handler is the wrong > place to suppress the chaining because it has no way of distinguishing > Steven's case from a genuine case of a new exception unexpectedly > occurring during handling of the original exception. > > One solution would be for "raise" inside except to not use the context. I would have thought that was such an obvious solution that I was gobsmacked to discover the PEP 3134 hadn't already considered it. If you *explicitly* raise an exception inside an exception handler, surely it's because you want to suppress the previous exception as an internal detail? If not, and you want to chain it with the previous exception, the solution is simple, obvious and straight-forward: explicit chaining. try: something() except SomeException as exc: raise MyException from exc > For example: > > try: > {}[1] > except KeyError: > 1/0 > > would behave as before, but: Yes, that presumably would be a bug and should chain exceptions. > But: > > try: > {}[1] > except KeyError: > raise Exception("my error") > > ...would raise the custom error forgetting the KeyError. That's exactly the behaviour I would expect and I'm surprised that this feature was put into production without some simple way to support this idiom. -- Steven From steve+comp.lang.python at pearwood.info Fri Dec 3 19:52:22 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Dec 2010 00:52:22 GMT Subject: Exception handling in Python 3.x References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> <87hbeuyj1g.fsf@xemacs.org> Message-ID: <4cf990c6$0$30003$c3e8da3$5496439d@news.astraweb.com> On Fri, 03 Dec 2010 17:08:38 +0100, Peter Otten wrote: > After rereading the original post I still don't get why the workarounds > provided in those links aren't worth considering. The first work-around: http://mail.python.org/pipermail/python-list/2010-October/1258606.html is unsuitable because it requires the caller to install a custom excepthook. It would be rude and unacceptable for arbitrary functions to install hooks, possibly stomping all over the caller's own custom excepthook. And even if I did, or the caller did, it has the unfortunate side-effect of suppressing the display of *all* chained exceptions, including those that come from the bugs in exception handlers. The second work-around might be worth considering: http://mail.python.org/pipermail/python-list/2010-October/1259024.html however it adds unnecessary boilerplate to what should be a simple try...except...raise block, it obscures the intention of the code. As a work-around, it might be worth considering, but it's hardly elegant and it could very well be a fluke of the implementation rather than a guaranteed promise of the language. In the absence of a supported way to suppress exception chaining, I'm leaning towards my original work-around: set a flag in the except block, then raise the exception once I leave the block. But thanks again for the links. -- Steven From steve+comp.lang.python at pearwood.info Fri Dec 3 20:53:12 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Dec 2010 01:53:12 GMT Subject: import module doesn't work for new package References: <1e9b4955-d60d-44f0-9b62-2ce50be35fdf@u9g2000pra.googlegroups.com> Message-ID: <4cf99f07$0$30003$c3e8da3$5496439d@news.astraweb.com> On Fri, 03 Dec 2010 12:27:04 -0800, goldtech wrote: > I tried install a Python - would the word be "package"? - on Ubuntu > 10.10. Could you tell me how to fix? I would be grateful, is it a path > problem? Thanks. Lee That looks to me like either a missing dependency, or a bug in the package. It could be that package pykhtml depends on another package khtml, which isn't installed, or it could simply be a bug in pykhtml. It might help if you look at the MANIFEST file that came with the pykhtml package, and see what files it lists. -- Steven From wuwei23 at gmail.com Fri Dec 3 21:10:34 2010 From: wuwei23 at gmail.com (alex23) Date: Fri, 3 Dec 2010 18:10:34 -0800 (PST) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> Message-ID: <12f46102-0d2b-44eb-abf4-e4f1c3606c79@e16g2000pri.googlegroups.com> On Dec 3, 2:12?am, Tim Harig wrote: > Actually, I thought that debate was resolved years ago. ?I cannot think of > a single recently developed programming language that does not provide > exception handling mechanisms because they have been proven more reliable. Google's Go lacks exceptions and I believe that was a deliberate design choice. From mirko.vukovic at gmail.com Fri Dec 3 21:45:02 2010 From: mirko.vukovic at gmail.com (Mirko) Date: Fri, 3 Dec 2010 18:45:02 -0800 (PST) Subject: Google AI challenge: planet war. Lisp won. References: <44a8f48f-e291-463e-a042-d0cbc31a2a4e@z17g2000prz.googlegroups.com> Message-ID: <2a853d74-09d7-4910-8f52-3b42f9c275ae@w21g2000vby.googlegroups.com> On Dec 2, 12:06?pm, Xah Lee wrote: > discovered this rather late. > > Google has a AI Challenge: planet wars.http://ai-contest.com/index.php > > it started sometimes 2 months ago and ended first this month. > > the winner is G?bor Melis, with his code written in lisp. > > Congrats lispers! > > G?bor wrote a blog about it herehttp://quotenil.com/Planet-Wars-Post-Mortem.html > > (not sure if this has been mentioned here but quick search didn't find > it) > > ?Xah ?http://xahlee.org/? Thanks for letting us know and congratulations to Gabor. From usernet at ilthio.net Fri Dec 3 23:14:00 2010 From: usernet at ilthio.net (Tim Harig) Date: Sat, 4 Dec 2010 04:14:00 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <12f46102-0d2b-44eb-abf4-e4f1c3606c79@e16g2000pri.googlegroups.com> Message-ID: On 2010-12-04, alex23 wrote: > On Dec 3, 2:12?am, Tim Harig wrote: >> Actually, I thought that debate was resolved years ago. ?I cannot think of >> a single recently developed programming language that does not provide >> exception handling mechanisms because they have been proven more reliable. > > Google's Go lacks exceptions and I believe that was a deliberate > design choice. 1. The debate that I was referring to was between simple function checking vs. everything else. I didn't mean to automatically proclude any newer methodologies of which I might not even be aware. 2. I would consider the defer/panic/recovery mechanism functionally similar to exceptions in most ways. It allows the error handling code to be placed at a higher level and panics tranverse the stack until they are handled by a recovery. This is basically equivilent to how exceptions work using different names. The change is basically the defer function which solves the problem of any cleanup work that the function needs to do before the panic is raised. I like it, its nice. It formalizes the pattern of cleaning up within an exception block and re-raising the exception. I do have to wonder what patterns will emerge in the object given to panic(). Since it takes anything, and since Go doesn't have an object hierarchy, much less an exception hierarchy, the panic value raised may or may not contain the kind of detailed information that can be obtained about the error that we are able to get from the Exception objects in Python. From usernet at ilthio.net Fri Dec 3 23:25:37 2010 From: usernet at ilthio.net (Tim Harig) Date: Sat, 4 Dec 2010 04:25:37 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> Message-ID: On 2010-12-03, Harishankar wrote: > On Fri, 03 Dec 2010 14:31:43 +0000, Mark Wooding wrote: >> In general, recovering from an exceptional condition requires three >> activities: >> >> * doing something about the condition so that the program can continue >> running; >> >> * identifying some way of rejoining the program's main (unexceptional) >> flow of control; and >> >> * actually performing that transfer, ensuring that any necessary >> invariants are restored. > > my fault. Seems that exception handling requires a lot of forethought > since the control of program execution breaks at the point of exception > with no obvious way to rejoin it seamlessly whereas with an error, a > simple if condition could handle the error state and resume execution > from that point forward. This is the main reason why I think I used > simple error codes to handle certain recoverable conditions and avoided > exceptions. If you are returning an error code to the above function, then there is nothing that you cannot do with with the exception. Basically, you resolve the issue in your except block just as you would in the block of your if statement after returning the error code. If you try and fail to handle the exception or just needed to do some cleanup before allowing the exception to continue, then you just re-raise the exception. From smallpox911 at gmail.com Fri Dec 3 23:56:12 2010 From: smallpox911 at gmail.com (small Pox) Date: Fri, 3 Dec 2010 20:56:12 -0800 (PST) Subject: Google AI challenge: planet war. Lisp won. References: <44a8f48f-e291-463e-a042-d0cbc31a2a4e@z17g2000prz.googlegroups.com> <2a853d74-09d7-4910-8f52-3b42f9c275ae@w21g2000vby.googlegroups.com> Message-ID: <42634615-6233-4082-a7a8-22dff724c7bd@o9g2000pre.googlegroups.com> > > G?bor wrote a blog about it herehttp://quotenil.com/Planet-Wars-Post-Mortem.html http://presstv.ir/detail/153770.html It is said in the protocols to corrupt the minds of the GOYIM by alcohol gambling games <------------- pornography adulteries sex Watch the photo and proof of israel in LEBANON. these are vicious murderous criminals and spies. All the intellectual property of the planet has been stolen by them. betah.co.il was operational for a long time and just the tip of the iceberg. then these criminals helped saudis and other kuwaitis set some forums. arabic software was developed by them to help the foulish saudis. some desperate saudis, koreans, vietnam and other were baited and given the ebooks to spread. look how viciously they go for extradition of WIKILEAKS guy Julian Assange (on false rape charges), but ROMAN POLANSKY is a TRUE RAPIST of 13 year old innocent German girl in USA. Now, it should be somehow made kosher that what the jew has stolen should me made available to everyone otherwise as historically they convert black into white. which means all those "cubs" going back to israel for the annual kibbutz from europe,US,Australia etc, are taught lying, deception, hacking and all the top level mossad skills. This is infact happening. Bernard Madoff is not the only one. They will convert the knowledge into war material and money as they are clamoring for iran. How do you explain all the zionist jews buying all the software and hardware companies and setting up the worlds biggest monopolies. Watch the israeli espionage photos http://presstv.ir/detail/153770.html http://presstv.ir/detail/153770.html http://presstv.ir/detail/153770.html From smallpox911 at gmail.com Fri Dec 3 23:59:41 2010 From: smallpox911 at gmail.com (small Pox) Date: Fri, 3 Dec 2010 20:59:41 -0800 (PST) Subject: Google AI challenge: planet war. Lisp won. References: <44a8f48f-e291-463e-a042-d0cbc31a2a4e@z17g2000prz.googlegroups.com> <2a853d74-09d7-4910-8f52-3b42f9c275ae@w21g2000vby.googlegroups.com> <42634615-6233-4082-a7a8-22dff724c7bd@o9g2000pre.googlegroups.com> Message-ID: <38101daf-9cde-4cb8-a26a-5c0e4437b5e5@n32g2000pre.googlegroups.com> On Dec 3, 8:56?pm, small Pox wrote: > > > G?bor wrote a blog about it herehttp://quotenil.com/Planet-Wars-Post-Mortem.html > > http://presstv.ir/detail/153770.html > > It is said in the protocols to corrupt the minds of the GOYIM by > > alcohol > gambling > games ? ? ?<------------- > pornography > adulteries > sex > > Watch the photo and proof of israel in LEBANON. these are vicious > murderous criminals and spies. All the intellectual property of the > planet has been stolen by them. betah.co.il was operational for a long > time and just the tip of the iceberg. > > then these criminals helped saudis and other kuwaitis set some forums. > arabic software was developed by them to help the foulish saudis. some > desperate saudis, koreans, vietnam and other were baited and given the > ebooks to spread. > > look how viciously they go for extradition of WIKILEAKS guy Julian > Assange (on false rape charges), but ROMAN POLANSKY is a TRUE RAPIST > of 13 year old innocent German girl in USA. > > Now, it should be somehow made kosher that what the jew has stolen > should me made available to everyone otherwise as historically they > convert black into white. which means all those "cubs" going back to > israel for the annual kibbutz from europe,US,Australia etc, are taught > lying, deception, hacking and all the top level mossad skills. This is > infact happening. > > Bernard Madoff is not the only one. > > They will convert the knowledge into war material and money as they > are clamoring for iran. > > How do you explain all the zionist jews buying all the software and > hardware companies and setting up the worlds biggest monopolies. > > Watch the israeli espionage photos > > http://presstv.ir/detail/153770.htmlhttp://presstv.ir/detail/153770.htmlhttp://presstv.ir/detail/153770.html The whole narrative that lying bitch judith miller on lying NY times made up about arabs and alqaeda of sleeper agents and terrorists infact applied to israel and zionists. that is why there are all the airlines alerts not sparing whites coz they know but dont open their mouth that israelis could stage terror attacks and blame on arabs but dead are the innocent. like the 911 they did. and the anthrax From smallpox911 at gmail.com Sat Dec 4 00:02:40 2010 From: smallpox911 at gmail.com (small Pox) Date: Fri, 3 Dec 2010 21:02:40 -0800 (PST) Subject: Google AI challenge: planet war. Lisp won. References: <44a8f48f-e291-463e-a042-d0cbc31a2a4e@z17g2000prz.googlegroups.com> <2a853d74-09d7-4910-8f52-3b42f9c275ae@w21g2000vby.googlegroups.com> <42634615-6233-4082-a7a8-22dff724c7bd@o9g2000pre.googlegroups.com> Message-ID: On Dec 3, 8:56?pm, small Pox wrote: > > > G?bor wrote a blog about it herehttp://quotenil.com/Planet-Wars-Post-Mortem.html > > http://presstv.ir/detail/153770.html > > It is said in the protocols to corrupt the minds of the GOYIM by > > alcohol > gambling > games ? ? ?<------------- > pornography > adulteries > sex > > Watch the photo and proof of israel in LEBANON. these are vicious > murderous criminals and spies. All the intellectual property of the > planet has been stolen by them. betah.co.il was operational for a long > time and just the tip of the iceberg. > > then these criminals helped saudis and other kuwaitis set some forums. > arabic software was developed by them to help the foulish saudis. some > desperate saudis, koreans, vietnam and other were baited and given the > ebooks to spread. > > look how viciously they go for extradition of WIKILEAKS guy Julian > Assange (on false rape charges), but ROMAN POLANSKY is a TRUE RAPIST > of 13 year old innocent German girl in USA. > > Now, it should be somehow made kosher that what the jew has stolen > should me made available to everyone otherwise as historically they > convert black into white. which means all those "cubs" going back to > israel for the annual kibbutz from europe,US,Australia etc, are taught > lying, deception, hacking and all the top level mossad skills. This is > infact happening. > > Bernard Madoff is not the only one. > > They will convert the knowledge into war material and money as they > are clamoring for iran. > > How do you explain all the zionist jews buying all the software and > hardware companies and setting up the worlds biggest monopolies. > > Watch the israeli espionage photos > > http://presstv.ir/detail/153770.htmlhttp://presstv.ir/detail/153770.htmlhttp://presstv.ir/detail/153770.html Hezbollah discovers Israeli spy devices Fri Dec 3, 2010 8:5PM Share | Email | Print Israel has remotely detonated two of its spying devices in southern Lebanon after they were discovered by the Hezbollah resistance movement. At least two Lebanese were injured after the espionage devises were detonated remotely in Wadi al-Qaysiyya outside of Majdal Selem near the southern coastal city of Tyre on Friday. "Telecom technicians of the resistance (Hezbollah) managed to discover a spying device the enemy had planted in Wadi al-Qaysiyya. The enemy detonated its devices as a result of the discovery," said a statement released by the Hezbollah media relations department. "This technical espionage by the enemy is part of the persistent Israeli violations of the national telecom network with the aim of infiltrating and controlling it, which represents a breach of sovereignty and an attempt at violating the security and safety of the Lebanese," the statement added. No other details were immediately available. Friday's incident came just two days after Israeli troops opened fire on Lebanon from two border posts near Shebaa Farms. HM/HGH/MMN Related Stories: 'Israeli troops open fire on Lebanon' Ten Israeli warplanes fly over Lebanon Israeli planes enter Lebanon airspace Comments Add Comment Click Here Note: The views expressed and the links provided on our comment pages are the personal views of individual contributors and do not necessarily reflect the views of Press TV. Damon 12/3/2010 10:17:48 PMUh.... the last I heard, Lebaon and Israel are still in a state of beliggerancy, so why is the presence of spy devices a surprise? From smallpox911 at gmail.com Sat Dec 4 01:57:59 2010 From: smallpox911 at gmail.com (small Pox) Date: Fri, 3 Dec 2010 22:57:59 -0800 (PST) Subject: Unknown function operation deciphering, exercise in readability by program reasoning Message-ID: <46365e1d-42d8-4b3b-8e69-941472467472@u25g2000pra.googlegroups.com> Rules : @1@ No execution of the function, only checking syntax @2@ No profiling using a debugger or profiler @3@ Editing allowed to make simpler variables (defun unknown-function (nano-thermite-911-FBI-fat-per-diem-bustards- kept-their-odious-mouth-shut-on-anthrax-and-911-lie) (let (BERNARD-MADOFF-PHILIP-MARKOFF-MIKHAIL-KHODORKOVSKY-NEOCONS- PAUL-WOLFOWITZ-LEWIS-SCOOTER-LIBBY-MOSHE-KATSEV-MOSSAD-DUBAI-MURDERERS I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN-SPEECH-ON-KHAZARS) (while (or I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN- SPEECH-ON-KHAZARS nano-thermite-911-FBI-fat-per-diem-bustards-kept- their-odious-mouth-shut-on-anthrax-and-911-lie) (if nano-thermite-911-FBI-fat-per-diem-bustards-kept-their- odious-mouth-shut-on-anthrax-and-911-lie (if (consp nano-thermite-911-FBI-fat-per-diem-bustards-kept- their-odious-mouth-shut-on-anthrax-and-911-lie) (setq I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN- SPEECH-ON-KHAZARS (cons (cdr nano-thermite-911-FBI-fat-per-diem- bustards-kept-their-odious-mouth-shut-on-anthrax-and-911-lie) I-AM-THE-WITNESS-DOT-COM-has-MR- BENJAMIN-FREEDMAN-SPEECH-ON-KHAZARS) nano-thermite-911-FBI-fat-per-diem-bustards-kept- their-odious-mouth-shut-on-anthrax-and-911-lie (car nano-thermite-911- FBI-fat-per-diem-bustards-kept-their-odious-mouth-shut-on-anthrax- and-911-lie)) (setq BERNARD-MADOFF-PHILIP-MARKOFF-MIKHAIL-KHODORKOVSKY- NEOCONS-PAUL-WOLFOWITZ-LEWIS-SCOOTER-LIBBY-MOSHE-KATSEV-MOSSAD-DUBAI- MURDERERS (cons nano-thermite-911-FBI-fat-per-diem-bustards-kept-their- odious-mouth-shut-on-anthrax-and-911-lie BERNARD-MADOFF-PHILIP-MARKOFF- MIKHAIL-KHODORKOVSKY-NEOCONS-PAUL-WOLFOWITZ-LEWIS-SCOOTER-LIBBY-MOSHE- KATSEV-MOSSAD-DUBAI-MURDERERS) nano-thermite-911-FBI-fat-per-diem-bustards-kept- their-odious-mouth-shut-on-anthrax-and-911-lie nil)) (setq nano-thermite-911-FBI-fat-per-diem-bustards-kept-their- odious-mouth-shut-on-anthrax-and-911-lie (car I-AM-THE-WITNESS-DOT-COM- has-MR-BENJAMIN-FREEDMAN-SPEECH-ON-KHAZARS) I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN-SPEECH- ON-KHAZARS (cdr I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN- SPEECH-ON-KHAZARS)))) BERNARD-MADOFF-PHILIP-MARKOFF-MIKHAIL-KHODORKOVSKY-NEOCONS-PAUL- WOLFOWITZ-LEWIS-SCOOTER-LIBBY-MOSHE-KATSEV-MOSSAD-DUBAI-MURDERERS)) From tw55413 at gmail.com Sat Dec 4 03:22:01 2010 From: tw55413 at gmail.com (erikj) Date: Sat, 4 Dec 2010 00:22:01 -0800 (PST) Subject: position independent build of python References: Message-ID: On Dec 3, 5:05?pm, de... at web.de (Diez B. Roggisch) wrote: > erikj writes: > > If my understanding is correct, the sys.prefix variable holds the root > > directory python uses to find related files, and eg its site-packages. > > > the value of sys.prefix is specified at compile time. > > > it seems that on windows, when I build/install python at one location, > > and > > later move it to another location, python will find all its needs > > relative to the new location. That's indeed a good idea, I will investigate it. But if this works, I still need some kind of wrapper around python itself... > > > however, when I do the same on linux, python keeps looking for > > its dependencies in the build location. > > > is there a possibility to have it always look at a position relative > > to the location of the executable ? ?the goal is to be able to build > > python on one machine, and then simply copy the build tree to > > other machines at other locations. > > Maybe looking at virtualenv, especially with the --no-site-packages > variable set gives you a hint. AFAIK there are some hard-coded paths > involved, but not inside compiled code. Maybe you can remedy that somehow. > > Diez From progreo at gmail.com Sat Dec 4 04:48:14 2010 From: progreo at gmail.com (robos85) Date: Sat, 4 Dec 2010 01:48:14 -0800 (PST) Subject: PIL how to enlarge image Message-ID: <365f5ebd-8e77-4741-b4ee-36d81f8da279@v17g2000prc.googlegroups.com> Hi, I try to enlarge original image. I have image in size: 100x100 and I want to make it 120x120. But resize() doesn't make it bigger. Is there any method for that? From __peter__ at web.de Sat Dec 4 05:36:03 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 04 Dec 2010 11:36:03 +0100 Subject: import module doesn't work for new package References: <1e9b4955-d60d-44f0-9b62-2ce50be35fdf@u9g2000pra.googlegroups.com> Message-ID: goldtech wrote: > I tried install a Python - would the word be "package"? - on Ubuntu > 10.10. Could you tell me how to fix? I would be grateful, is it a path > problem? Thanks. Lee If you are talking about http://paul.giannaros.org/pykhtml/ , this package requires kde3 while you are /probably/ running kde4. > giga1 at giga1:~/Desktop/pykhtml-0.2$ sudo python setup.py install > [sudo] password for giga1: > running install > running build > running build_py > creating build > creating build/lib.linux-i686-2.6 > creating build/lib.linux-i686-2.6/pykhtml > copying pykhtml/dom.py -> build/lib.linux-i686-2.6/pykhtml > copying pykhtml/__init__.py -> build/lib.linux-i686-2.6/pykhtml > running install_lib > running install_egg_info > Removing /usr/local/lib/python2.6/dist-packages/PyKHTML-0.2.egg-info > Writing /usr/local/lib/python2.6/dist-packages/PyKHTML-0.2.egg-info > > then: > >>>> import pykhtml > Traceback (most recent call last): > File "", line 1, in > File "pykhtml/__init__.py", line 3, in > import khtml, kdecore, kdeui, kio, dcopext > ImportError: No module named khtml This would become from PyKDE4 import khtml, kdecore, kdeui, kio in KDE4, but there are /probably/ API changes. DCOP which is /probably/ what dcopext provides has been replaced with dbus. Given these changes and the fact that pykhtml development has stopped in early 2008 you'd /probably/ have to put in a lot of effort to make it work with your current desktop environment. From alain at dpt-info.u-strasbg.fr Sat Dec 4 05:58:16 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Sat, 04 Dec 2010 11:58:16 +0100 Subject: PIL how to enlarge image References: <365f5ebd-8e77-4741-b4ee-36d81f8da279@v17g2000prc.googlegroups.com> Message-ID: <87sjydst2v.fsf@dpt-info.u-strasbg.fr> robos85 writes: > Hi, I try to enlarge original image. > I have image in size: 100x100 and I want to make it 120x120. > But resize() doesn't make it bigger. Is there any method for that? You have to use i.transform() -- Alain. From vs at it.uu.se Sat Dec 4 08:32:53 2010 From: vs at it.uu.se (Virgil Stokes) Date: Sat, 04 Dec 2010 14:32:53 +0100 Subject: A web site using Python Message-ID: <4CFA4305.10004@it.uu.se> I would like to design a web site that can be used to help people to find a cat that they can adopt. Note, this is a non-profit project, but one that I believe to be quite important. Here are some of my initial thoughts on this project. /Site purpose:/ *To provide a web site for anyone to look at information on cats at this home, and how they can adopt one or more of these homeless cats.* /Some features of the site:/ 1. A cat database that I as the web site designer would create. This database would contain an entry for each cat available for adoption. It would include such things as the name, sex, age, paths to image(s) and/or video(s) of the cat, health status, etc (see below). 2. Anyone accessing this site should be able to easily navigate around it and to examine entries in this database. The client (designated person at the home where the cats are kept for adoption) would be given privileges to modify the database (add, delete, and modify entries). The user interface for the client to update the database should be very easy to use. This GUI provided to the client for modification of the database would be written in Python. 3. There would be no inputs to this web site. There would be an embedded link for a potential customer to send an email to the responsible person (bringing up their email client). 4. Track number of visitors to the site. /Preliminary notes on the database/ Fields: - ID code (key) - Name - Sex (M / F) - Neutered / Not neutered - Age (estimated) - Type (breed) - Tagged (chip or ear marking)/ Not tagged - Checked In date (yy/mm/dd) - Checked Out date (yy/mm/dd) - Status (needs home / has home) - Social state (1,2,3,4,5) - Health state (1,2,3,4,5) - Companion state (1,2,3,4,5) - Image (file name) % multiple files allowed - Video (file name) % multiple files allowed - Medical/vet data (text on vaccinations, etc.) - General information (text on cat that includes comments, observations, etc.) ------------------------------------------------------------------------------- Notes on database: * state = 1, Best 5, Worst Examples: Social state = 5, very unfriendly, afraid, etc. 3, can touch if careful 1, very friendly, unafraid Health state = 5, not in good health (e.g. infection) 3, only minor health problems 1, in very good health Companion state = 5, must have another cat or cats as company 3, could be with other cat(s) company 1, does not need the company of another cat Now, with this initial information (granted this is very rough), my question: *How, armed with Python 2.6 (or 2.7) and all of the Python packages available, should I attack the problem of getting this web site up and running on a Windows platform?* Please keep in mind that do have some experience with Python and HTML; but, this would be my first web site project using Python. Any suggestions, study plan, references, etc. would be welcomed. --V -------------- next part -------------- An HTML attachment was scrubbed... URL: From kontakt at toomuchcookies.net Sat Dec 4 09:00:43 2010 From: kontakt at toomuchcookies.net (Omar Abo-Namous) Date: Sat, 04 Dec 2010 15:00:43 +0100 Subject: class attribute confusion In-Reply-To: <87k4jqcxs2.fsf@gmail.com> References: <87k4jqcxs2.fsf@gmail.com> Message-ID: <4CFA498B.7070905@toomuchcookies.net> Am 03.12.2010 23:11, schrieb Arnaud Delobelle: > OAN writes: > >> Hi, >> >> i was having a problem with class attributes initiated outside of >> __init__. This code is a demonstration of what i mean: >> >> class A(): >> mylist = [] >> def __init__(self): >> self.mylist.append(1) >> pass >> >> class B(A): >> def __init__(self): >> A.__init__(self) >> self.mylist.append(2) >> >> v = A() >> print 'v:',v.mylist >> x = B() >> print 'x:',x.mylist >> y = B() >> print 'y:',y.mylist >> z = A() >> print 'z:',z.mylist >> print 'v:',v.mylist >> >> I would expect the following result: >> >> v: [1] >> x: [1, 2] >> y: [1, 2] >> z: [1] >> v: [1] >> >> Who wouldn't, right? But actually python 2.6(.6) gives me the >> following result: >> >> v: [1] >> x: [1, 1, 2] >> y: [1, 1, 2, 1, 2] >> z: [1, 1, 2, 1, 2, 1] >> v: [1, 1, 2, 1, 2, 1] >> >> The four variables v,x,y and z now actually share the same 'mylist'!! >> To get the correct results, i have to initialize 'mylist' inside of >> the __init__ method! > Yes. See below. > >> I think this behaviour is totally wrong, since it seems >> A.__init__(self) is changing the value inside of A() not inside of the >> object variable 'self' (that should be x or y)!! > It's not wrong at all. You expect "mylist" to behave as an instance > attribute, but you defined it as a class attribute. Instance attributes > are naturally initialised in the __init__() method. > Could you please point me to a reference in the doc?? Thanks in advance. From steve+comp.lang.python at pearwood.info Sat Dec 4 09:34:38 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Dec 2010 14:34:38 GMT Subject: class attribute confusion References: <87k4jqcxs2.fsf@gmail.com> Message-ID: <4cfa517e$0$30003$c3e8da3$5496439d@news.astraweb.com> On Sat, 04 Dec 2010 15:00:43 +0100, Omar Abo-Namous wrote: >>> I think this behaviour is totally wrong, since it seems >>> A.__init__(self) is changing the value inside of A() not inside of the >>> object variable 'self' (that should be x or y)!! >> It's not wrong at all. You expect "mylist" to behave as an instance >> attribute, but you defined it as a class attribute. Instance >> attributes are naturally initialised in the __init__() method. >> > Could you please point me to a reference in the doc?? http://docs.python.org/reference/datamodel.html In the section about classes: "Class attribute assignments update the class?s dictionary ..." and in the section about class instances: "Attribute assignments and deletions update the instance?s dictionary, never a class?s dictionary." In this specific example, you also have to realise that mylist.append() mutates the list in place, and doesn't create a new list. It doesn't matter whether the list comes from a global variable, a local variable, an instance attribute or a class attribute, append is always an inplace operation. -- Steven From hidura at gmail.com Sat Dec 4 09:54:44 2010 From: hidura at gmail.com (hidura at gmail.com) Date: Sat, 04 Dec 2010 14:54:44 +0000 Subject: A web site using Python In-Reply-To: <4CFA4305.10004@it.uu.se> Message-ID: <0014853d0112e94116049696d504@google.com> I am working on a tool that can create an application like that without write server code, but the system is write in Python3.1 On Dec 4, 2010 9:32am, Virgil Stokes wrote: > I would like to design a web site that can be used to help > people to find a cat > that they can adopt. Note, this is a non-profit project, but one > that I > believe to be quite important. Here are some of my initial > thoughts on this > project. > Site purpose: > To provide a web site for anyone to look at information on cats > at this home, and how > they can adopt one or more of these homeless cats. > Some features of the site: > 1. A cat database that I as the web site designer would create. > This database would > contain an entry for each cat available for adoption. It would > include such things > as the name, sex, age, paths to image(s) and/or video(s) of the > cat, health status, > etc (see below). > 2. Anyone accessing this site should be able to easily navigate > around it and to > examine entries in this database. The client (designated person > at the home > where the cats are kept for adoption) would be given privileges > to modify the > database (add, delete, and modify entries). The user interface > for the client > to update the database should be very easy to use. This GUI > provided to the > client for modification of the database would be written in > Python. > 3. There would be no inputs to this web site. There would be an > embedded link for a > potential customer to send an email to the responsible person > (bringing up > their email client). > 4. Track number of visitors to the site. > Preliminary notes on the database > Fields: > - ID code (key) > - Name > - Sex (M / F) > - Neutered / Not neutered > - Age (estimated) > - Type (breed) > - Tagged (chip or ear marking)/ Not tagged > - Checked In date (yy/mm/dd) > - Checked Out date (yy/mm/dd) > - Status (needs home / has home) > - Social state (1,2,3,4,5) > - Health state (1,2,3,4,5) > - Companion state (1,2,3,4,5) > - Image (file name) % multiple files allowed > - Video (file name) % multiple files allowed > - Medical/vet data (text on vaccinations, etc.) > - General information (text on cat that includes comments, > observations, etc.) > ------------------------------------------------------------------------------- > Notes on database: > * state = 1, Best > 5, Worst > Examples: > Social state = 5, very unfriendly, afraid, etc. > 3, can touch if careful > 1, very friendly, unafraid > Health state = 5, not in good health (eg infection) > 3, only minor health problems > 1, in very good health > Companion state = 5, must have another cat or cats as company > 3, could be with other cat(s) company > 1, does not need the company of another cat > Now, with this initial information (granted this is very > rough), my question: > How, armed with Python 2.6 (or 2.7) and all of the Python > packages available, > should I attack the problem of getting this web site up and > running on a Windows > platform? > Please keep in mind that do have some experience with Python and > HTML; but, this > would be my first web site project using Python. > Any suggestions, study plan, references, etc. would be welcomed. > --V -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Sat Dec 4 11:40:54 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 04 Dec 2010 11:40:54 -0500 Subject: Comparison with False - something I don't understand In-Reply-To: References: <877hfs2zia.fsf@benfinney.id.au> Message-ID: <4CFA6F16.2060001@holdenweb.com> On 12/2/2010 11:42 PM, Harishankar wrote: > One of the reasons why I feared to do this is because I need to know each > and every exception that might be thrown by the function and litter my > top-level code with too many exception handlers. > You appear to be suffering from the delusion that all exceptions must be caught and handled. This is far from being the case. But still, better to have your top-level code "littered with exception handlers" than to have your functions "littered with if statements". Quite often it's impossible for the function to know what needs to be done when a specific conditions arises, in which case (presumably) you have to return some error code and test for that ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sat Dec 4 11:40:54 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 04 Dec 2010 11:40:54 -0500 Subject: Comparison with False - something I don't understand In-Reply-To: References: <877hfs2zia.fsf@benfinney.id.au> Message-ID: <4CFA6F16.2060001@holdenweb.com> On 12/2/2010 11:42 PM, Harishankar wrote: > One of the reasons why I feared to do this is because I need to know each > and every exception that might be thrown by the function and litter my > top-level code with too many exception handlers. > You appear to be suffering from the delusion that all exceptions must be caught and handled. This is far from being the case. But still, better to have your top-level code "littered with exception handlers" than to have your functions "littered with if statements". Quite often it's impossible for the function to know what needs to be done when a specific conditions arises, in which case (presumably) you have to return some error code and test for that ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From v.harishankar at gmail.com Sat Dec 4 12:07:45 2010 From: v.harishankar at gmail.com (Harishankar) Date: Sat, 4 Dec 2010 17:07:45 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> <4CFA6F16.2060001@holdenweb.com> Message-ID: > You appear to be suffering from the delusion that all exceptions must be > caught and handled. This is far from being the case. But still, better > to have your top-level code "littered with exception handlers" than to > have your functions "littered with if statements". Of course not. But going by the replies here, it appears that Python has made exceptions as the "norm" for error handling which is ironical considering the meaning of the word "exception". I find a bit cumbersome that exceptions are advocated for certain conditions which can be sanely worked around in the application's logic and even avoided, rather than waiting for them to get caught and providing an unsatisfactory result. > > Quite often it's impossible for the function to know what needs to be > done when a specific conditions arises, in which case (presumably) you > have to return some error code and test for that ... Not necessarily. I wasn't talking about low-level or built-in exceptions. I was talking about using exceptions in my programming where often the function is reasonably confident of the kind of errors it is likely to incur. I did not start this as a criticism of Python's exceptions as such. I just expressed my personal aversion to using them in my own code. However, in my next project I have started using exceptions and will keep an open mind on how it turns out. So far it doesn't seem too bad. > > regards > Steve -- Harishankar (http://harishankar.org http://lawstudentscommunity.com) From darcy at druid.net Sat Dec 4 12:41:15 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sat, 4 Dec 2010 12:41:15 -0500 Subject: Comparison with False - something I don't understand In-Reply-To: References: <877hfs2zia.fsf@benfinney.id.au> <4CFA6F16.2060001@holdenweb.com> Message-ID: <20101204124115.712e6983.darcy@druid.net> On Sat, 4 Dec 2010 17:07:45 +0000 (UTC) Harishankar wrote: > Of course not. But going by the replies here, it appears that Python has > made exceptions as the "norm" for error handling which is ironical > considering the meaning of the word "exception". I find a bit cumbersome > that exceptions are advocated for certain conditions which can be sanely > worked around in the application's logic and even avoided, rather than > waiting for them to get caught and providing an unsatisfactory result. It just seems to me that you have a semantic issue rather than a technical one. If the word "exception" was replaced by "check" or something else would that make the process easier to swallow? try: somefunc() check ValueError: handle_error() Whatever it's called it's just flow control. > > Quite often it's impossible for the function to know what needs to be > > done when a specific conditions arises, in which case (presumably) you > > have to return some error code and test for that ... > > Not necessarily. I wasn't talking about low-level or built-in exceptions. > I was talking about using exceptions in my programming where often the > function is reasonably confident of the kind of errors it is likely to > incur. I did not start this as a criticism of Python's exceptions as > such. I just expressed my personal aversion to using them in my own code. > > However, in my next project I have started using exceptions and will keep > an open mind on how it turns out. So far it doesn't seem too bad. Open minds are good. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From gnarlodious at gmail.com Sat Dec 4 13:33:01 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Sat, 4 Dec 2010 10:33:01 -0800 (PST) Subject: Print recent CGI error Message-ID: <98b43d3b-01aa-4a6a-8288-71b65435d3c2@k38g2000vbc.googlegroups.com> I have a serious error that causes the process to crash. Apache refuses to log the error and it only happens on the server, not on the dev machine. Problem is, I can't figure out how to get the most recent error. I can find all sorts of pages telling how to print a specific error, but how to get an unknown error: Here is where I am: NowCookie.load(savedCookie) try: savedCookie=NowCookie['Sectrum'].value # PROCESS CRASHES HERE except: print("Content-type:text/html\n\n") print("???") # PRINT WHATEVER ERROR OCCURRED quit() There must be something so simple I am missing... This is Python 3. -- Gnarlie From DekuDekuplex at Yahoo.com Sat Dec 4 13:49:45 2010 From: DekuDekuplex at Yahoo.com (Benjamin L. Russell) Date: Sun, 05 Dec 2010 03:49:45 +0900 Subject: Google AI challenge: planet war. Lisp won. References: <44a8f48f-e291-463e-a042-d0cbc31a2a4e@z17g2000prz.googlegroups.com> <2a853d74-09d7-4910-8f52-3b42f9c275ae@w21g2000vby.googlegroups.com> <42634615-6233-4082-a7a8-22dff724c7bd@o9g2000pre.googlegroups.com> Message-ID: small Pox writes: >> > G?bor wrote a blog about it herehttp://quotenil.com/Planet-Wars-Post-Mortem.html > > http://presstv.ir/detail/153770.html > > It is said in the protocols to corrupt the minds of the GOYIM by > > alcohol > gambling > games <------------- > pornography > adulteries > sex Yeah, riiight. So it's a crime to have any fun in life, right? Go get a life. -- Benjamin L. Russell From starglider.dev at gmail.com Sat Dec 4 14:12:08 2010 From: starglider.dev at gmail.com (starglider develop) Date: Sat, 4 Dec 2010 19:12:08 +0000 Subject: Backup postgresql database from python Message-ID: Hi, I need to backup a postgresql database from python withour using pg_dump! Is any way of doing that? Thank you in advance for your help. Zorze -------------- next part -------------- An HTML attachment was scrubbed... URL: From darcy at druid.net Sat Dec 4 14:32:18 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sat, 4 Dec 2010 14:32:18 -0500 Subject: Backup postgresql database from python In-Reply-To: References: Message-ID: <20101204143218.bbe3d2ed.darcy@druid.net> On Sat, 4 Dec 2010 19:12:08 +0000 starglider develop wrote: > I need to backup a postgresql database from python withour using pg_dump! > Is any way of doing that? Probably. I guess the first question is why can't you use pg_dump? That might give us a clue as to the requirements. Any other details would be good too. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From drsalists at gmail.com Sat Dec 4 14:33:46 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 4 Dec 2010 11:33:46 -0800 Subject: Print recent CGI error In-Reply-To: <98b43d3b-01aa-4a6a-8288-71b65435d3c2@k38g2000vbc.googlegroups.com> References: <98b43d3b-01aa-4a6a-8288-71b65435d3c2@k38g2000vbc.googlegroups.com> Message-ID: I've sometimes got similar situations in CGI, that turned out to be because of a syntax error that kept apache from being able to run the script. What if you just run the script at the command line? It should either error out due to lack of a CGI environment/arguments, but hopefully it'll give you an error message that'll be useful. Also, you might be able to get some mileage out of finding out what env vars and command line options are being passed, and running from the command line with those. On Sat, Dec 4, 2010 at 10:33 AM, Gnarlodious wrote: > I have a serious error that causes the process to crash. Apache > refuses to log the error and it only happens on the server, not on the > dev machine. Problem is, I can't figure out how to get the most recent > error. I can find all sorts of pages telling how to print a specific > error, but how to get an unknown error: > > Here is where I am: > > NowCookie.load(savedCookie) > try: > ? ?savedCookie=NowCookie['Sectrum'].value ?# PROCESS CRASHES HERE > except: > ? ?print("Content-type:text/html\n\n") > ? ?print("???") ?# PRINT WHATEVER ERROR OCCURRED > ? ?quit() > > There must be something so simple I am missing... > > This is Python 3. > > -- Gnarlie > -- > http://mail.python.org/mailman/listinfo/python-list > From philip at semanchuk.com Sat Dec 4 14:52:37 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Sat, 4 Dec 2010 14:52:37 -0500 Subject: Backup postgresql database from python In-Reply-To: <20101204143218.bbe3d2ed.darcy@druid.net> References: <20101204143218.bbe3d2ed.darcy@druid.net> Message-ID: On Dec 4, 2010, at 2:32 PM, D'Arcy J.M. Cain wrote: > On Sat, 4 Dec 2010 19:12:08 +0000 > starglider develop wrote: >> I need to backup a postgresql database from python withour using pg_dump! >> Is any way of doing that? > > Probably. I guess the first question is why can't you use pg_dump? > That might give us a clue as to the requirements. Excellent point. No offense to the OP, but this isn't really a Python question. You could re-implement pg_dump in Python, Javascript, or any language you like and you'd have your solution. That's probably not what you were looking for though. As D'Arcy said, the first thing to establish is why you want to avoid pg_dump. Another important question is whether or not you expect the database to be in use while you're doing backups. bye Philip From python at mrabarnett.plus.com Sat Dec 4 15:01:10 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 04 Dec 2010 20:01:10 +0000 Subject: Print recent CGI error In-Reply-To: <98b43d3b-01aa-4a6a-8288-71b65435d3c2@k38g2000vbc.googlegroups.com> References: <98b43d3b-01aa-4a6a-8288-71b65435d3c2@k38g2000vbc.googlegroups.com> Message-ID: <4CFA9E06.6000802@mrabarnett.plus.com> On 04/12/2010 18:33, Gnarlodious wrote: > I have a serious error that causes the process to crash. Apache > refuses to log the error and it only happens on the server, not on the > dev machine. Problem is, I can't figure out how to get the most recent > error. I can find all sorts of pages telling how to print a specific > error, but how to get an unknown error: > > Here is where I am: > > NowCookie.load(savedCookie) > try: > savedCookie=NowCookie['Sectrum'].value # PROCESS CRASHES HERE > except: > print("Content-type:text/html\n\n") > print("???") # PRINT WHATEVER ERROR OCCURRED > quit() > > There must be something so simple I am missing... > > This is Python 3. > You could try something like: import traceback NowCookie.load(savedCookie) try: savedCookie=NowCookie['Sectrum'].value # PROCESS CRASHES HERE except: print("Content-type:text/html\n\n") traceback.print_exception(*sys.exc_info()) # PRINT WHATEVER ERROR OCCURRED quit() From redjohn367 at gmail.com Sat Dec 4 15:32:33 2010 From: redjohn367 at gmail.com (Red John) Date: Sat, 4 Dec 2010 12:32:33 -0800 (PST) Subject: Google AI challenge: planet war. Lisp won. References: <44a8f48f-e291-463e-a042-d0cbc31a2a4e@z17g2000prz.googlegroups.com> <2a853d74-09d7-4910-8f52-3b42f9c275ae@w21g2000vby.googlegroups.com> <42634615-6233-4082-a7a8-22dff724c7bd@o9g2000pre.googlegroups.com> Message-ID: > > Yeah, riiight. ?So it's a crime to have any fun in life, right? ?Go get > a life. > > -- Benjamin L. Russell +1 From gnarlodious at gmail.com Sat Dec 4 16:13:35 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Sat, 4 Dec 2010 13:13:35 -0800 (PST) Subject: Print recent CGI error References: mailman.208.1291492876.2649.python-list@python.org Message-ID: What you posted doesn't work, I don't know why. All I get is a blank page and no Apache error report. There are two problems with this. I am really trying to figure out how to trap an error on the server without exposing my innards to the world, which import cgitb; cgitb.enable() does. The other problem is that no traceback seems to play well with a try-except block. I guess I am forced to use one or the other, but not both. What I really wanted to do is display any error in a simple error statement. This is probably a KeyError, but how am I to know? There must be some way to print a dump of the current thread before it deallocates. -- Gnarlie From python at mrabarnett.plus.com Sat Dec 4 16:48:52 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 04 Dec 2010 21:48:52 +0000 Subject: Print recent CGI error In-Reply-To: References: mailman.208.1291492876.2649.python-list@python.org Message-ID: <4CFAB744.6070204@mrabarnett.plus.com> On 04/12/2010 21:13, Gnarlodious wrote: > What you posted doesn't work, I don't know why. All I get is a blank > page and no Apache error report. > > There are two problems with this. I am really trying to figure out how > to trap an error on the server without exposing my innards to the > world, which import cgitb; cgitb.enable() does. The other problem is > that no traceback seems to play well with a try-except block. I guess > I am forced to use one or the other, but not both. > > What I really wanted to do is display any error in a simple error > statement. This is probably a KeyError, but how am I to know? There > must be some way to print a dump of the current thread before it > deallocates. > Double-check what version of Python is on the server. See if you can write the traceback to a file on the server which you can then download. From see at sig.below Sat Dec 4 16:49:20 2010 From: see at sig.below (Barb Knox) Date: Sun, 05 Dec 2010 10:49:20 +1300 Subject: Unknown function operation deciphering, exercise in readability by program reasoning References: <46365e1d-42d8-4b3b-8e69-941472467472@u25g2000pra.googlegroups.com> Message-ID: In article <46365e1d-42d8-4b3b-8e69-941472467472 at u25g2000pra.googlegroups.com>, small Pox wrote: > Rules : No need to add any additional hurdles -- the code as presented is thoroughly unreadable by humans. > @1@ No execution of the function, only checking syntax What about "desk checking" (a lost art from the oldene dayes)? > @2@ No profiling using a debugger or profiler > > @3@ Editing allowed to make simpler variables Maybe if you had done that yourself before posting it then I would have tried to understand it. As it is, no way. > (defun unknown-function (nano-thermite-911-FBI-fat-per-diem-bustards- > kept-their-odious-mouth-shut-on-anthrax-and-911-lie) > (let (BERNARD-MADOFF-PHILIP-MARKOFF-MIKHAIL-KHODORKOVSKY-NEOCONS- > PAUL-WOLFOWITZ-LEWIS-SCOOTER-LIBBY-MOSHE-KATSEV-MOSSAD-DUBAI-MURDERERS > I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN-SPEECH-ON-KHAZARS) > (while (or I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN- > SPEECH-ON-KHAZARS nano-thermite-911-FBI-fat-per-diem-bustards-kept- > their-odious-mouth-shut-on-anthrax-and-911-lie) > (if nano-thermite-911-FBI-fat-per-diem-bustards-kept-their- > odious-mouth-shut-on-anthrax-and-911-lie > (if (consp nano-thermite-911-FBI-fat-per-diem-bustards-kept- > their-odious-mouth-shut-on-anthrax-and-911-lie) > (setq I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN- > SPEECH-ON-KHAZARS (cons (cdr nano-thermite-911-FBI-fat-per-diem- > bustards-kept-their-odious-mouth-shut-on-anthrax-and-911-lie) > I-AM-THE-WITNESS-DOT-COM-has-MR- > BENJAMIN-FREEDMAN-SPEECH-ON-KHAZARS) > nano-thermite-911-FBI-fat-per-diem-bustards-kept- > their-odious-mouth-shut-on-anthrax-and-911-lie (car nano-thermite-911- > FBI-fat-per-diem-bustards-kept-their-odious-mouth-shut-on-anthrax- > and-911-lie)) > (setq BERNARD-MADOFF-PHILIP-MARKOFF-MIKHAIL-KHODORKOVSKY- > NEOCONS-PAUL-WOLFOWITZ-LEWIS-SCOOTER-LIBBY-MOSHE-KATSEV-MOSSAD-DUBAI- > MURDERERS (cons nano-thermite-911-FBI-fat-per-diem-bustards-kept-their- > odious-mouth-shut-on-anthrax-and-911-lie BERNARD-MADOFF-PHILIP-MARKOFF- > MIKHAIL-KHODORKOVSKY-NEOCONS-PAUL-WOLFOWITZ-LEWIS-SCOOTER-LIBBY-MOSHE- > KATSEV-MOSSAD-DUBAI-MURDERERS) > nano-thermite-911-FBI-fat-per-diem-bustards-kept- > their-odious-mouth-shut-on-anthrax-and-911-lie nil)) > (setq nano-thermite-911-FBI-fat-per-diem-bustards-kept-their- > odious-mouth-shut-on-anthrax-and-911-lie (car I-AM-THE-WITNESS-DOT-COM- > has-MR-BENJAMIN-FREEDMAN-SPEECH-ON-KHAZARS) > I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN-SPEECH- > ON-KHAZARS (cdr I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN- > SPEECH-ON-KHAZARS)))) > BERNARD-MADOFF-PHILIP-MARKOFF-MIKHAIL-KHODORKOVSKY-NEOCONS-PAUL- > WOLFOWITZ-LEWIS-SCOOTER-LIBBY-MOSHE-KATSEV-MOSSAD-DUBAI-MURDERERS)) -- --------------------------- | BBB b \ Barbara at LivingHistory stop co stop uk | B B aa rrr b | | BBB a a r bbb | Quidquid latine dictum sit, | B B a a r b b | altum videtur. | BBB aa a r bbb | ----------------------------- From bavlakes at gmail.com Sat Dec 4 17:34:50 2010 From: bavlakes at gmail.com (Biglakes) Date: Sat, 4 Dec 2010 14:34:50 -0800 (PST) Subject: 3 Sr. Mac OS X Developer Position - West End Toronto, ON (Urgently needed) Message-ID: <4bd1d780-3d1f-4112-8692-165d2fee0928@29g2000prb.googlegroups.com> Here?s the details of a job opportunity I may have for any of you or someone you may know. Below is the job description. Please send me a copy of your resume in word format and state the best time I can give you a call. Please feel free to pass it on to anyone whom you think may fit in the profile as there are currently three (3) openings for this position. It is a full time permanent position with an attractive compensation package. Email me at: lakeside at mtmstaffing.com SENIOR MAC OS X DEVELOPER Our client is an innovative software & consumer products company with advanced media mobility solutions; allowing users to view their content incomparably & experience seamless media mobility. Job Summary: As a Senior MAC OS X Developer, you are an integral member of a team of talented software and systems engineers committed to developing world-class embedded STB software solutions for the digital-TV, consumer electronics, IPTV, cable and broadcasting industries. Job Responsibilities: ? Design and development of iOS application software, with the further goal of using core technologies from the iOS application in a Mac OS X application. ? User interface design and development ? Coordination with human interface specialists ? Re-factoring components to insure proper Cocoa design patterns ? Working with Quality Assurance team on issue identification and resolution ? Testing & implementing multimedia/networking products with a primary focus iPhone ? Writes & debugs multi-threaded applications ? Works closely with team members to quickly diagnose and resolve problems Requirements: ? Bachelors degree or higher in a technical discipline, (e.g.: Computer Science or Electrical Engineering etc) ? Established MAC OS, iPhone & iPad development Experience ? Experience in digital video, audio, cable and/or broadcasting industry ? Minimum 5 Years experience in Objective-C, Cocoa, XCode, Interface Builder, C/C++ on Mac OS X systems (iPhone OS development alone does not qualify) ? Detail oriented, with strong analytical, problem solving and troubleshooting skills ? Networking Experience ? Excellent verbal and written communication From jbiquez at icsmx.com Sat Dec 4 17:42:36 2010 From: jbiquez at icsmx.com (Jorge Biquez) Date: Sat, 04 Dec 2010 16:42:36 -0600 Subject: Which non SQL Database ? Message-ID: <201012042241.oB4Mfcfi079977@krusty.intranet.com.mx> Hello all. Newbie question. Sorry. As part of my process to learn python I am working on two personal applications. Both will do it fine with a simple structure of data stored in files. I now there are lot of databases around I can use but I would like to know yoor advice on what other options you would consider for the job (it is training so no pressure on performance). One application will run as a desktop one,under Windows, Linux, Macintosh, being able to update data, not much, not complex, not many records. The second application, running behind web pages, will do the same, I mean, process simple data, updating showing data. not much info, not complex. As an excersice it is more than enough I guess and will let me learn what I need for now. Talking with a friend about what he will do (he use C only) he suggest to take a look on dBase format file since it is a stable format, fast and the index structure will be fine or maybe go with BD (Berkley) database file format (I hope I understood this one correctly) . Plain files it is not an option since I would like to have option to do rapid searches. What would do you suggest to take a look? If possible available under the 3 plattforms. Thanks in advance for your comments. Jorge Biquez From arnodel at gmail.com Sat Dec 4 18:02:31 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sat, 04 Dec 2010 23:02:31 +0000 Subject: Which non SQL Database ? References: Message-ID: <87d3phcfaw.fsf@gmail.com> Jorge Biquez writes: > Hello all. > > Newbie question. Sorry. > > As part of my process to learn python I am working on two personal > applications. Both will do it fine with a simple structure of data > stored in files. I now there are lot of databases around I can use but > I would like to know yoor advice on what other options you would > consider for the job (it is training so no pressure on > performance). One application will run as a desktop one,under Windows, > Linux, Macintosh, being able to update data, not much, not complex, > not many records. The second application, running behind web pages, > will do the same, I mean, process simple data, updating showing > data. not much info, not complex. As an excersice it is more than > enough I guess and will let me learn what I need for now. > Talking with a friend about what he will do (he use C only) he suggest > to take a look on dBase format file since it is a stable format, fast > and the index structure will be fine or maybe go with BD (Berkley) > database file format (I hope I understood this one correctly) . Plain > files it is not an option since I would like to have option to do > rapid searches. > > What would do you suggest to take a look? If possible available under > the 3 plattforms. Have you considered sqlite3? It is part of the Python standard library. It'll work under GNU/Linux, Windows and Mac OSX. For more details see: http://docs.python.org/library/sqlite3.html -- Arnaud From gnarlodious at gmail.com Sat Dec 4 18:09:13 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Sat, 4 Dec 2010 15:09:13 -0800 (PST) Subject: Which non SQL Database ? References: <87d3phcfaw.fsf@gmail.com> Message-ID: I use sqlite3, it is fairly simple, fast and not too strict. -- Gnarlie From swiftone at swiftone.org Sat Dec 4 18:27:59 2010 From: swiftone at swiftone.org (Brett Ritter) Date: Sat, 4 Dec 2010 18:27:59 -0500 Subject: [Tutor] Which non SQL Database ? In-Reply-To: <201012042241.oB4Mfcfi079977@krusty.intranet.com.mx> References: <201012042241.oB4Mfcfi079977@krusty.intranet.com.mx> Message-ID: On Sat, Dec 4, 2010 at 5:42 PM, Jorge Biquez wrote: > Newbie question. Sorry. If it isn't you're on the wrong list :) > training so no pressure on performance). One application will run as a > desktop one,under Windows, Linux, Macintosh, being able to update data, not > much, not complex, not many records. The important details here are: simple data, low-volume. I'm assuming this is single-user (as in, each instance of your application has it's own DB) > The second application, running behind > ?web pages, will do the same, Is this multiple users, each accessing the same DB? That really changes what you are looking for. If you are dealing with single-user, or only a few users, I'd say look into SQLite - It uses SQL syntax but doesn't run as a server and stores the database as a single file. It's great to use in small projects because the syntax is the same as larger projects, and you can replace with a full-blown multi-user SQL DB if you ever need to without having to rework everything. It's also very simple to use. I believe SQLite (sqlite3) is part of the core library in recent Python versions, or available as a package for older pythons. Berkeley DB is pretty much interchangeable with SQLite in terms of functionality. I much prefer SQLite. If your web application intends to have multiple users interacting with the same data, neither is probably a good fit. -- Brett Ritter / SwiftOne swiftone at swiftone.org From jbiquez at icsmx.com Sat Dec 4 18:43:48 2010 From: jbiquez at icsmx.com (Jorge Biquez) Date: Sat, 04 Dec 2010 17:43:48 -0600 Subject: Which non SQL Database ? In-Reply-To: <87d3phcfaw.fsf@gmail.com> References: <87d3phcfaw.fsf@gmail.com> Message-ID: <201012042343.oB4Nh18D084173@krusty.intranet.com.mx> At 05:02 p.m. 04/12/2010, you wrote: >Jorge Biquez writes: > > > Hello all. > > > > Newbie question. Sorry. > > > > As part of my process to learn python I am working on two personal > > applications. Both will do it fine with a simple structure of data > > stored in files. I now there are lot of databases around I can use but > > I would like to know yoor advice on what other options you would > > consider for the job (it is training so no pressure on > > performance). One application will run as a desktop one,under Windows, > > Linux, Macintosh, being able to update data, not much, not complex, > > not many records. The second application, running behind web pages, > > will do the same, I mean, process simple data, updating showing > > data. not much info, not complex. As an excersice it is more than > > enough I guess and will let me learn what I need for now. > > Talking with a friend about what he will do (he use C only) he suggest > > to take a look on dBase format file since it is a stable format, fast > > and the index structure will be fine or maybe go with BD (Berkley) > > database file format (I hope I understood this one correctly) . Plain > > files it is not an option since I would like to have option to do > > rapid searches. > > > > What would do you suggest to take a look? If possible available under > > the 3 plattforms. > >Have you considered sqlite3? It is part of the Python standard library. >It'll work under GNU/Linux, Windows and Mac OSX. For more details see: > > http://docs.python.org/library/sqlite3.html > >-- >Arnaud >-- Hello all. Ok. sqlite3 seems like it is the best option since it is part of python already.... you are right of course. I do not see a good reason for not using Sqlite3 BUT if for some reason would not be an option.... what plain schema of files would you use? I am sorry to insist. I do not know much about the size tha using Sqlite adds to the application but the idea is that the , application, single user for desktop yes, will be the smallest it can be since the idea is to distribute the executable only. (all this is to have a prototype I have done in other language) For the web part, yes, of course would be multiple users. Thanks to all. Jorge Biquez From cmpython at gmail.com Sat Dec 4 18:59:31 2010 From: cmpython at gmail.com (CM) Date: Sat, 4 Dec 2010 15:59:31 -0800 (PST) Subject: Which non SQL Database ? References: <87d3phcfaw.fsf@gmail.com> Message-ID: <1ae2b7eb-0ccc-420e-8e62-92aafebd827e@p38g2000vbn.googlegroups.com> On Dec 4, 6:43?pm, Jorge Biquez wrote: > At 05:02 p.m. 04/12/2010, you wrote: > > > > >Jorge Biquez writes: > > > > Hello all. > > > > Newbie question. Sorry. > > > > As part of my process to learn python I am working on two personal > > > applications. Both will do it fine with a simple structure of data > > > stored in files. I now there are lot of databases around I can use but > > > I would like to know yoor advice on what other options you would > > > consider for the job (it is training so no pressure on > > > performance). One application will run as a desktop one,under Windows, > > > Linux, Macintosh, being able to update data, not much, not complex, > > > not many records. The second application, running behind ?web pages, > > > will do the same, I mean, process simple data, updating showing > > > data. not much info, not complex. As an excersice it is more than > > > enough I guess and will let me learn what I need for now. > > > Talking with a friend about what he will do (he use C only) he suggest > > > to take a look on dBase format file since it is a stable format, fast > > > and the index structure will be fine or maybe go with BD (Berkley) > > > database file format (I hope I understood this one correctly) . Plain > > > files it is not an option since I would like to have option to do > > > rapid searches. > > > > What would do you suggest to take a look? If possible available under > > > the 3 plattforms. > > >Have you considered sqlite3? It is part of the Python standard library. > >It'll work under GNU/Linux, Windows and Mac OSX. ?For more details see: > > > ? ?http://docs.python.org/library/sqlite3.html > > >-- > >Arnaud > >-- > > Hello all. > > Ok. sqlite3 seems like it is the best option since it is part of > python already.... you are right of course. > > I do not see a good reason for not using Sqlite3 BUT if for some > reason would not be an option.... what plain schema of files would > you use? I am sorry to insist. I do not know much about the size tha > using Sqlite adds to the application but the idea is that the , > application, single user for desktop yes, will be the smallest it can > be since the idea is to distribute the executable only. (all this is > to have a prototype I have done in other language) SQlite itself is around 300 kilobytes. That's negligible. It is also already in Python, so you'd have to purposefully exclude it in creating your executable to save those 300 kb and thus the 1/13th of a second additional time it would take average (3.9 MB/s) users to download your app if it were included. From gnarlodious at gmail.com Sat Dec 4 19:00:25 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Sat, 4 Dec 2010 16:00:25 -0800 (PST) Subject: Print recent CGI error References: mailman.208.1291492876.2649.python-list@python.org Message-ID: <9856eb02-672c-4483-91fd-51095ce2b6d5@d24g2000prj.googlegroups.com> After many curse words I figured it out. A two-stage filter was needed. The 5th line solves the problem of colliding domain cookies: NowCookie=http.cookies.SimpleCookie() # Instantiate a SimpleCookie object savedCookie=os.environ.get('HTTP_COOKIE') # get the cookie string if savedCookie: # Already is a domain cookie NowCookie.load(savedCookie) # Could be any domain cookie if CookieName in NowCookie: # Look for a specific cookie savedCookie=NowCookie[CookieName].value # Load the cookie string into a dict self.List=list(savedCookie.split('~')) # Parse the payload string delimited at tilde return self.List=[hashlib.sha1(repr(time.time()).encode()).hexdigest(), '', ''] # Else default payload self.Write() # Tell the client to remember -- Gnarlie From ben+python at benfinney.id.au Sat Dec 4 19:01:32 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 05 Dec 2010 11:01:32 +1100 Subject: Which non SQL Database ? References: <87d3phcfaw.fsf@gmail.com> Message-ID: <87mxol140z.fsf@benfinney.id.au> Jorge Biquez writes: > I do not see a good reason for not using Sqlite3 BUT if for some > reason would not be an option.... what plain schema of files would you > use? I am sorry to insist. SQLite stores the entire database in a single file. Does that answer the question? I'm not sure I understand. Preferably, check SQLite's own site for answers, since it seems your concerns are not specific to Python. If you have Python-specific concerns about SQLite you'll need to make them more explicit for us to answer them. > I do not know much about the size tha using Sqlite adds to the > application As you noted, SQLite is already in the Python standard library. > For the web part, yes, of course would be multiple users. Systems like Berkeley DB, SQLite, dBase, et cetera achieve their simplicity at the expense of concurrent access to the database. If you want concurrent access to the database by many connections, that's where you need to look at a more sophisticated solution. For efficient concurrent access, a DBMS such as PostgreSQL is the best choice. -- \ ?When I was little, my grandfather used to make me stand in a | `\ closet for five minutes without moving. He said it was elevator | _o__) practice.? ?Steven Wright | Ben Finney From azeynel1 at gmail.com Sat Dec 4 19:15:22 2010 From: azeynel1 at gmail.com (Zeynel) Date: Sat, 4 Dec 2010 16:15:22 -0800 (PST) Subject: How do I get the email address of the person who clicked the link in the email? Message-ID: <63971a7c-8366-471b-ac7f-812f7dab81ba@n10g2000yqd.googlegroups.com> Hello, I am working with Google App Engine python version. The app sends an email to the user with a link to a page to upload an image as an avatar. It would be nice to have the email so that I can associate the avatar with that email. How can I do this? Thank you. From kentilton at gmail.com Sat Dec 4 19:21:52 2010 From: kentilton at gmail.com (kenny) Date: Sat, 4 Dec 2010 16:21:52 -0800 (PST) Subject: SunLisp: A new Lisp drinking society in Ft Lauderdale, FL debuting 7PM, Pearl Harbor Day Message-ID: <57fd943c-eeb5-408a-a249-9ad3cb33013d@e16g2000pri.googlegroups.com> In case you missed it, SunLisp is debuting on Pearl Harbor Day (December 7th) at 7PM. It's been added to the Lisp Meetings Calendar as well. Who: His Kennyness, his CIO Dan (can you say "Lisp jobs"? Sher ya can) and a notable group of Lispers doing a nice project in FL and anyone who cares to join them. When: First Tuesday of the month, 7PM, starting with Pearl Harbor Day, 2010 Where: http://www.thefrogandtoadpub.com/ That is just a couple of blocks below West Cypress Creek aka 62nd on the east side of Powerline. What: They serve beer, wine, and a substantial menu of great food. Why: So we can flame each other in person over beer about the right number of namespaces. Why else? RSVP for this first meet so we know if we should ask them to tidy up the back room which is smashing but lacks tellys. HK (Someone want to pass this along to the yobbos on #lisp?) From contact at xavierho.com Sat Dec 4 19:49:40 2010 From: contact at xavierho.com (Xavier Ho) Date: Sun, 5 Dec 2010 08:49:40 +0800 Subject: How do I get the email address of the person who clicked the link in the email? In-Reply-To: <63971a7c-8366-471b-ac7f-812f7dab81ba@n10g2000yqd.googlegroups.com> References: <63971a7c-8366-471b-ac7f-812f7dab81ba@n10g2000yqd.googlegroups.com> Message-ID: As a suggestion, you can auto-format your email link so that the email of the user is sent as part of the URL GET argument. Cheers, Xav On 5 December 2010 08:15, Zeynel wrote: > Hello, > > I am working with Google App Engine python version. The app sends an > email to the user with a link to a page to upload an image as an > avatar. It would be nice to have the email so that I can associate the > avatar with that email. How can I do this? Thank you. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Sat Dec 4 19:53:00 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 04 Dec 2010 19:53:00 -0500 Subject: Comparison with False - something I don't understand In-Reply-To: References: <877hfs2zia.fsf@benfinney.id.au> <4CFA6F16.2060001@holdenweb.com> Message-ID: On 12/4/2010 12:07 PM, Harishankar wrote: > Of course not. But going by the replies here, it appears that Python has > made exceptions as the "norm" for error handling which is ironical > considering the meaning of the word "exception". In communications parlance, 'exception' = out-of-band signal or return value, while 'return'ed value = in-band signal. A fake in-band return value, like returning None (ok) or False (worse) to *signal* 'I cannot return a list' is still an exception signal, even if 'in-band'. The advantage of out-of-band signals is that they cannot be mistaken for valid in-band signals (return values). If a caller neglects to catch an exception, the process stops, as it should. If a caller neglects to check return values, the process goes on (at least for a while) under the pretense that error codes (in-band exception signals) are valid return values. Neglecting to check return values for error codes is a common bug in C code. At worst, the process eventually return a bad value or performs a bad action. At best, it crashes sometime later, making the bug hard to find. Or a function is called without even storing, let alone checking the return value. This is common for i/o functions. A program may 'finish' without any indication that it failed. If one does the same with Python functions (equally common), any exceptions *will* be passed up until either caught or displayed on the screen with an informative traceback (assuming that the screen is the not source of the error). -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Sat Dec 4 20:59:27 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Dec 2010 01:59:27 GMT Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> <4CFA6F16.2060001@holdenweb.com> Message-ID: <4cfaf1ff$0$30003$c3e8da3$5496439d@news.astraweb.com> On Sat, 04 Dec 2010 17:07:45 +0000, Harishankar wrote: > I find a bit cumbersome > that exceptions are advocated for certain conditions which can be sanely > worked around in the application's logic and even avoided, rather than > waiting for them to get caught and providing an unsatisfactory result. That's surprisingly rare in Python. In fact, I'd go so far as to say that in Python there is *nothing* that you can test for and then have a *guarantee* that it will succeed. Of course, this is mainly of theoretical concern. In practice, "Look Before You Leap" (test first, then process) is often fine. But there are traps to look out for. For example, unless you are running a single- process machine, the following code is subject to race conditions and is not safe: if os.exists(pathname): fp = open(pathname) else: handle_missing_file() Just because the file is there when os.exists() looks for it, doesn't mean it still exists a microsecond later when you try opening it. Or consider this code: if y != 0: result = x/y else: handle_division_by_zero() This is also unsafe unless you know the type of y. Suppose y is an interval quantity that straddles zero, then division by y may fail even though y != 0. -- Steven From jbiquez at icsmx.com Sat Dec 4 21:39:47 2010 From: jbiquez at icsmx.com (Jorge Biquez) Date: Sat, 04 Dec 2010 20:39:47 -0600 Subject: Which non SQL Database ? In-Reply-To: <87mxol140z.fsf@benfinney.id.au> References: <87d3phcfaw.fsf@gmail.com> <87mxol140z.fsf@benfinney.id.au> Message-ID: <201012050238.oB52cpgc098631@krusty.intranet.com.mx> Hello all. Understood perfectly. Will forget other alternatives. Sqlite3 is the best option. Thanks for the explanation and time. Sqlite for single user and Postgresql will be the choice. Thanks all. Take care Jorge Biquez At 06:01 p.m. 04/12/2010, you wrote: >Jorge Biquez writes: > > > I do not see a good reason for not using Sqlite3 BUT if for some > > reason would not be an option.... what plain schema of files would you > > use? I am sorry to insist. > >SQLite stores the entire database in a single file. Does that answer the >question? I'm not sure I understand. > >Preferably, check SQLite's own site for >answers, since it seems your concerns are not specific to Python. If you >have Python-specific concerns about SQLite you'll need to make them more >explicit for us to answer them. > > > I do not know much about the size tha using Sqlite adds to the > > application > >As you noted, SQLite is already in the Python standard library. > > > For the web part, yes, of course would be multiple users. > >Systems like Berkeley DB, SQLite, dBase, et cetera achieve their >simplicity at the expense of concurrent access to the database. > >If you want concurrent access to the database by many connections, >that's where you need to look at a more sophisticated solution. For >efficient concurrent access, a DBMS such as PostgreSQL is the best >choice. > >-- > \ ???When I was little, my grandfather used to make me stand in a | > `\ closet for five minutes without moving. He said it was elevator | >_o__) practice.??? ?Steven Wright | >Ben Finney >-- >http://mail.python.org/mailman/listinfo/python-list From v.harishankar at gmail.com Sat Dec 4 22:26:21 2010 From: v.harishankar at gmail.com (Harishankar) Date: Sun, 5 Dec 2010 03:26:21 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> <4CFA6F16.2060001@holdenweb.com> <4cfaf1ff$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, 05 Dec 2010 01:59:27 +0000, Steven D'Aprano wrote: > Of course, this is mainly of theoretical concern. In practice, "Look > Before You Leap" (test first, then process) is often fine. But there are > traps to look out for. For example, unless you are running a single- > process machine, the following code is subject to race conditions and is > not safe: > > if os.exists(pathname): > fp = open(pathname) > else: > handle_missing_file() > > Just because the file is there when os.exists() looks for it, doesn't > mean it still exists a microsecond later when you try opening it. I understand this line of thinking. And it makes sense to see why it would matter to leave the exception handling mechanism deal with such issues. > > Or consider this code: > > if y != 0: > result = x/y > else: > handle_division_by_zero() > > > This is also unsafe unless you know the type of y. Suppose y is an > interval quantity that straddles zero, then division by y may fail even > though y != 0. Of course in each of these cases the in-built exceptions are used to verify the result of certain system level or lower level operations. My object was not to deprecate the system-level or other low level exceptions thrown by Python, but to consider whether such a mechanism would be a preferable method of handling your own programs error- conditions. The issue to be considered by every programmer is to define what can be defined as the exceptional condition and what is a condition that merits merely different treatment without causing disruption of the normal flow of the program. -- Harishankar (http://harishankar.org http://lawstudentscommunity.com) From vincent.toups at gmail.com Sat Dec 4 22:34:53 2010 From: vincent.toups at gmail.com (jvt) Date: Sat, 4 Dec 2010 19:34:53 -0800 (PST) Subject: Unknown function operation deciphering, exercise in readability by program reasoning References: <46365e1d-42d8-4b3b-8e69-941472467472@u25g2000pra.googlegroups.com> Message-ID: <5e1f79ab-5432-4f18-b896-362b7406c75c@i18g2000yqn.googlegroups.com> On Dec 4, 4:49?pm, Barb Knox wrote: > In article > <46365e1d-42d8-4b3b-8e69-941472467... at u25g2000pra.googlegroups.com>, > ?small Pox wrote: > > > Rules : > > No need to add any additional hurdles -- the code as presented is > thoroughly unreadable by humans. > > > @1@ ?No execution of the function, only checking syntax > > What about "desk checking" (a lost art from the oldene dayes)? > > > @2@ ?No profiling using a debugger or profiler > > > @3@ ?Editing allowed to make simpler variables > > Maybe if you had done that yourself before posting it then I would have > tried to understand it. ?As it is, no way. > > > > > > > > > > > (defun unknown-function (nano-thermite-911-FBI-fat-per-diem-bustards- > > kept-their-odious-mouth-shut-on-anthrax-and-911-lie) > > ? (let (BERNARD-MADOFF-PHILIP-MARKOFF-MIKHAIL-KHODORKOVSKY-NEOCONS- > > PAUL-WOLFOWITZ-LEWIS-SCOOTER-LIBBY-MOSHE-KATSEV-MOSSAD-DUBAI-MURDERERS > > I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN-SPEECH-ON-KHAZARS) > > ? ? (while (or I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN- > > SPEECH-ON-KHAZARS nano-thermite-911-FBI-fat-per-diem-bustards-kept- > > their-odious-mouth-shut-on-anthrax-and-911-lie) > > ? ? ? (if nano-thermite-911-FBI-fat-per-diem-bustards-kept-their- > > odious-mouth-shut-on-anthrax-and-911-lie > > ? ? ? ? ? (if (consp nano-thermite-911-FBI-fat-per-diem-bustards-kept- > > their-odious-mouth-shut-on-anthrax-and-911-lie) > > ? ? ? ? ? ? ? (setq I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN- > > SPEECH-ON-KHAZARS (cons (cdr nano-thermite-911-FBI-fat-per-diem- > > bustards-kept-their-odious-mouth-shut-on-anthrax-and-911-lie) > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? I-AM-THE-WITNESS-DOT-COM-has-MR- > > BENJAMIN-FREEDMAN-SPEECH-ON-KHAZARS) > > ? ? ? ? ? ? ? ? ? ? nano-thermite-911-FBI-fat-per-diem-bustards-kept- > > their-odious-mouth-shut-on-anthrax-and-911-lie (car nano-thermite-911- > > FBI-fat-per-diem-bustards-kept-their-odious-mouth-shut-on-anthrax- > > and-911-lie)) > > ? ? ? ? ? ? (setq BERNARD-MADOFF-PHILIP-MARKOFF-MIKHAIL-KHODORKOVSKY- > > NEOCONS-PAUL-WOLFOWITZ-LEWIS-SCOOTER-LIBBY-MOSHE-KATSEV-MOSSAD-DUBAI- > > MURDERERS (cons nano-thermite-911-FBI-fat-per-diem-bustards-kept-their- > > odious-mouth-shut-on-anthrax-and-911-lie BERNARD-MADOFF-PHILIP-MARKOFF- > > MIKHAIL-KHODORKOVSKY-NEOCONS-PAUL-WOLFOWITZ-LEWIS-SCOOTER-LIBBY-MOSHE- > > KATSEV-MOSSAD-DUBAI-MURDERERS) > > ? ? ? ? ? ? ? ? ? nano-thermite-911-FBI-fat-per-diem-bustards-kept- > > their-odious-mouth-shut-on-anthrax-and-911-lie nil)) > > ? ? ? ? (setq nano-thermite-911-FBI-fat-per-diem-bustards-kept-their- > > odious-mouth-shut-on-anthrax-and-911-lie (car I-AM-THE-WITNESS-DOT-COM- > > has-MR-BENJAMIN-FREEDMAN-SPEECH-ON-KHAZARS) > > ? ? ? ? ? ? ? I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN-SPEECH- > > ON-KHAZARS (cdr I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN- > > SPEECH-ON-KHAZARS)))) > > ? ? BERNARD-MADOFF-PHILIP-MARKOFF-MIKHAIL-KHODORKOVSKY-NEOCONS-PAUL- > > WOLFOWITZ-LEWIS-SCOOTER-LIBBY-MOSHE-KATSEV-MOSSAD-DUBAI-MURDERERS)) > > -- > --------------------------- > | ?BBB ? ? ? ? ? ? ? ?b ? ?\ ? ? Barbara at LivingHistory stop co stop uk > | ?B ?B ? aa ? ? rrr ?b ? ? | > | ?BBB ? a ?a ? r ? ? bbb ? | ? ?Quidquid latine dictum sit, > | ?B ?B ?a ?a ? r ? ? b ?b ?| ? ?altum videtur. > | ?BBB ? ?aa a ?r ? ? bbb ? | ? > ----------------------------- I think this is correct: (defun unknown-function (sym0) (let (sym1 sym2) (while (or sym2 sym0) (if sym0 (if (consp sym0) (setq sym2 (cons (cdr sym0) sym2) sym0 (car sym0)) (setq sym3 sym4 (cons sym0 sym1) sym0 nil)) (setq sym0 (car sym2) sym2 (cdr sym2)))) sym1)) Thank emacs, not me. From aysegul.ozz11 at gmail.com Sat Dec 4 22:52:24 2010 From: aysegul.ozz11 at gmail.com (=?ISO-8859-1?B?R/xsINZncmV0bWVuIC4uLg==?=) Date: Sat, 4 Dec 2010 19:52:24 -0800 (PST) Subject: INVITATION TO AN INFORMATION FOR GROUP (...) Message-ID: <4e3301a4-7f86-4405-ae04-9cf078d6c3db@y23g2000yqd.googlegroups.com> INVITATION TO AN INFORMATION FOR GROUP (...) BUSINESS ADS (ANNOUNCEMENTS) http://nettengelir.blogspot.com/ ___________ ONLINE NEWS SYSTEMS THAT'S REPLY ... http://nettengelir.blogspot.com/ From timr at probo.com Sat Dec 4 23:11:34 2010 From: timr at probo.com (Tim Roberts) Date: Sat, 04 Dec 2010 20:11:34 -0800 Subject: PIL how to enlarge image References: <365f5ebd-8e77-4741-b4ee-36d81f8da279@v17g2000prc.googlegroups.com> Message-ID: <034mf69odlbjn8cflh38aftsmu7o8e381s@4ax.com> robos85 wrote: > >Hi, I try to enlarge original image. >I have image in size: 100x100 and I want to make it 120x120. >But resize() doesn't make it bigger. Is there any method for that? "resize" does not change the image. Instead, it returns the resized image. If you don't need the original any more: img = img.resize((120,120)) -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From usernet at ilthio.net Sat Dec 4 23:13:02 2010 From: usernet at ilthio.net (Tim Harig) Date: Sun, 5 Dec 2010 04:13:02 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> <4CFA6F16.2060001@holdenweb.com> <4cfaf1ff$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-12-05, Harishankar wrote: >> Or consider this code: >> >> if y != 0: >> result = x/y >> else: >> handle_division_by_zero() >> >> >> This is also unsafe unless you know the type of y. Suppose y is an >> interval quantity that straddles zero, then division by y may fail even >> though y != 0. > > Of course in each of these cases the in-built exceptions are used to > verify the result of certain system level or lower level operations. My > object was not to deprecate the system-level or other low level > exceptions thrown by Python, but to consider whether such a mechanism > would be a preferable method of handling your own programs error- > conditions. Whether you happen to like the exception mechanism and syntax or not, it is the idiomatic way of handling errors in Python. Using two different conventions in your code will lead to confusion. I come from a long C background as well. I have come to appreciate the power the Python's exception handling provides. It does everything that you need to do with passing values in C and more. > The issue to be considered by every programmer is to define what can be > defined as the exceptional condition and what is a condition that merits > merely different treatment without causing disruption of the normal flow > of the program. That is an issue much harder to define. Anything it is an obvious error *should* throw an exception. Invalid input is an error. Unusable hardware states are errors. Any invalid request to an object, is an error. Essentially anything that deviates from a normal flow of a program, to handle an exceptional condition, is an error Where it becomes less obvious is when you start using exceptions as part normal control flow. An example is a try it and see methodology. You might for instance have a group of file objects which might or might not support a particular method attribute. You might have a preference for using the attribute; but, have a fallback plan if it does not. One way to handle this is to try to use the attribute and catch the exception raised if it is not present to execute your backup method. I have found this *essential* in some marsaling enviroments where you might not have access to the meta-data of the object that you are working with. Another, questionable but useful use, is to ignore the complex accounting of your position inside of a complex data structure. You can continue moving through the structure until an exception is raised indicating that you have reached a boundary of the structure. Whether you accept uses of exceptions like these is more of a personal quesion. Like many good tools, they can be useful in ways that they were never really designed to be and I would hate to proclude some of these really useful features. This can, of course, be easily abused. I was once writing code, involving complex object marshaling like I described above, with a partner who wasn't totally familiar with Python. We came to a situation where it was impossible to know ahead of time what kind of object (one of two possiblities) we would receive from another marshalled object and had no meta-data to be able to figure out before attempting to access the object. I used a try/except clause to resolve the problem. The next day, I found several poorly conceived try/except blocks in the codebase that my partner had used for control structures using dictionaries because he didn't know of dict.has_key(). I was not so pleased. From memilanuk at gmail.com Sat Dec 4 23:44:47 2010 From: memilanuk at gmail.com (Monte Milanuk) Date: Sat, 04 Dec 2010 20:44:47 -0800 Subject: Which non SQL Database ? In-Reply-To: <201012042343.oB4Nh18D084173@krusty.intranet.com.mx> References: <87d3phcfaw.fsf@gmail.com> <201012042343.oB4Nh18D084173@krusty.intranet.com.mx> Message-ID: <4CFB18BF.5040407@gmail.com> On 12/4/10 3:43 PM, Jorge Biquez wrote: > I do not see a good reason for not using Sqlite3 BUT if for some reason > would not be an option.... what plain schema of files would you use? Would shelve work? From memilanuk at gmail.com Sat Dec 4 23:44:47 2010 From: memilanuk at gmail.com (Monte Milanuk) Date: Sat, 04 Dec 2010 20:44:47 -0800 Subject: Which non SQL Database ? In-Reply-To: <201012042343.oB4Nh18D084173@krusty.intranet.com.mx> References: <87d3phcfaw.fsf@gmail.com> <201012042343.oB4Nh18D084173@krusty.intranet.com.mx> Message-ID: <4CFB18BF.5040407@gmail.com> On 12/4/10 3:43 PM, Jorge Biquez wrote: > I do not see a good reason for not using Sqlite3 BUT if for some reason > would not be an option.... what plain schema of files would you use? Would shelve work? From usernet at ilthio.net Sat Dec 4 23:52:29 2010 From: usernet at ilthio.net (Tim Harig) Date: Sun, 5 Dec 2010 04:52:29 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> <4CFA6F16.2060001@holdenweb.com> <4cfaf1ff$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-12-05, Tim Harig wrote: > Another, questionable but useful use, is to ignore the complex accounting > of your position inside of a complex data structure. You can continue > moving through the structure until an exception is raised indicating > that you have reached a boundary of the structure. Here is another example in this vein. A friend was trying to derive a mathematical formula for determining the possibly distribution of results from rolling arbitrariy numbers of m n-sided dice and needed several sets of data in different directions from which to draw conclusions. I created objects for dice and roles which contained and manipulated multiple dice. To generate a listing of all (non-uniq) possible roles, I would call the first dices increment method read and read the dice faces into a log until the first dice threw an exception that it could not be further incremented. Then I would call reset() on the first dice and increment the second and so on much like the odometer of a car. By using exceptions rather then checking the return value of increment, the state information of the dice was completely isolated to the dice and did not polute into the role structure; the logic for incrementing the dice, logging the role state, and rolling over the dice where all completely seperated and independent of any state; and therefore reseting multiple previous dice as the higher values on the odometer were incremented functioned automatically as each dice threw its own exception recursively rather then requiring logic to handle these multiple rollovers. From no.email at nospam.invalid Sun Dec 5 00:37:22 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 04 Dec 2010 21:37:22 -0800 Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> <4CFA6F16.2060001@holdenweb.com> <4cfaf1ff$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7xfwucye3x.fsf@ruckus.brouhaha.com> Tim Harig writes: > A friend was trying to derive a mathematical formula for determining > the possibly distribution of results from rolling arbitrariy numbers > of m n-sided dice http://en.wikipedia.org/wiki/Multinomial_distribution > To generate a listing of all (non-uniq) possible roles, I would call > the first dices increment method read and read the dice faces into a > log until the first dice threw an exception that it could not be > further incremented. Then I would call reset() on the first dice and > increment the second and so on much like the odometer of a car. from itertools import product m, n = 5, 2 for roll in product(*(xrange(1,m+1) for i in xrange(n))): print roll From steve+comp.lang.python at pearwood.info Sun Dec 5 00:42:18 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Dec 2010 05:42:18 GMT Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> <4CFA6F16.2060001@holdenweb.com> <4cfaf1ff$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cfb263a$0$30003$c3e8da3$5496439d@news.astraweb.com> On Sun, 05 Dec 2010 04:13:02 +0000, Tim Harig wrote: > Anything it is an obvious > error *should* throw an exception. Well, maybe... there are good use-cases for returning a sentinel. E.g. str.find, or the use of quiet NANs in IEEE floating point and decimal maths. NANs and INFs in floating point maths are a good example of the right way to do it. If you forget to check for a NAN, it will propagate through your calculation. INF will, under some circumstances where it is mathematically valid to do so, will disappear leaving a normal result. This means you only need to check your result at the very end of the calculation, not after every step. str.find is more troublesome, because the sentinel -1 doesn't propagate and is a common source of errors: result = string[string.find(delim):] will return a plausible-looking but incorrect result if delim is missing from string. But the convenience and familiarity of str.find means it will probably be around forever. -- Steven From usernet at ilthio.net Sun Dec 5 01:56:59 2010 From: usernet at ilthio.net (Tim Harig) Date: Sun, 5 Dec 2010 06:56:59 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> <4CFA6F16.2060001@holdenweb.com> <4cfaf1ff$0$30003$c3e8da3$5496439d@news.astraweb.com> <7xfwucye3x.fsf@ruckus.brouhaha.com> Message-ID: On 2010-12-05, Paul Rubin wrote: > Tim Harig writes: >> A friend was trying to derive a mathematical formula for determining >> the possibly distribution of results from rolling arbitrariy numbers >> of m n-sided dice > > http://en.wikipedia.org/wiki/Multinomial_distribution I sure he rediscovered much of that. Working that out for himeself was probably far more educational then simply reading an article on the solution. >> To generate a listing of all (non-uniq) possible roles, I would call >> the first dices increment method read and read the dice faces into a >> log until the first dice threw an exception that it could not be >> further incremented. Then I would call reset() on the first dice and >> increment the second and so on much like the odometer of a car. > > from itertools import product > m, n = 5, 2 > for roll in product(*(xrange(1,m+1) for i in xrange(n))): > print roll The fact that I bothered to create classes for the dice and roles, rather then simply iterating over a list of numbers, should tell you that I produced was of a far more flexible nature; including the support for roles with dice having different numbers of sides. I basically created a DSL that he could use to generate and automatically calculate the properties of series of roles defined by one or more varying property. I merely posted a simplied description of the dice-role objects because I thought that it demonstrated how exceptions can provide eligance of control for situations that don't involve what would traditionally be defined as an error. From nagle at animats.com Sun Dec 5 03:01:58 2010 From: nagle at animats.com (John Nagle) Date: Sun, 05 Dec 2010 00:01:58 -0800 Subject: Which non SQL Database ? In-Reply-To: References: <87d3phcfaw.fsf@gmail.com> <201012042343.oB4Nh18D084173@krusty.intranet.com.mx> Message-ID: <4cfb4714$0$1594$742ec2ed@news.sonic.net> On 12/4/2010 8:44 PM, Monte Milanuk wrote: > On 12/4/10 3:43 PM, Jorge Biquez wrote: > >> I do not see a good reason for not using Sqlite3 BUT if for some reason >> would not be an option.... what plain schema of files would you use? > > Would shelve work? There are some systems for storing key-value pairs in files. Underneath "shelve" is some primitive database, dbm, gdbm or bsddb. "bsddb" is deprecated and was removed from Python 3.x. "dbm" has some classic problems. "gdbm" is an improved version of "dbm". None of these handle access from multiple processes, or crash recovery. We're looking at 1979 technology here. SQLite works right when accessed from multiple processes. SQLite is the entry-level database technology for Python today. It handles the hard cases, like undoing transactions after a crash and locking against multiple accesses. Lookup performance is good; simultaneous update by multiple processes, though, is not so good. When you have a web site that has many processes hitting the same database, it's time to move up to MySQL or Postgres. There's a lot of interest in "non-SQL" databases for very large distributed systems. You worry about this if you're Facebook or Google, or are running a big game server farm. John Nagle From borisb0ri5 at gmail.com Sun Dec 5 03:31:43 2010 From: borisb0ri5 at gmail.com (Greg) Date: Sun, 5 Dec 2010 00:31:43 -0800 (PST) Subject: Perceived inconsistency in py3k documentation Message-ID: <724b26b4-8233-4d57-b76f-cd781cf0cd03@z17g2000prz.googlegroups.com> Hello, This is my first post here, so if this is not the correct place to ask this, please direct me to the best place. In looking at the py3k documentation for comparing two classes, two different view points are expressed (at least it seems so to me). 1) At http://docs.python.org/py3k/reference/datamodel.html: "There are no implied relationships among the comparison operators. The truth of x==y does not imply that x!=y is false. Accordingly, when defining __eq__(), one should also define __ne__()..." -- This seems to support the view that if in our code, we would like to use comparison operators <, >, =, !=, etc. then we should define a __lt__(), __gt__(), __eq__(), __ne__(), etc. for each comparison operator we would like. This appears to contrast 2) At http://docs.python.org/py3k/library/stdtypes.html: "Instances of a class cannot be ordered with respect to other instances of the same class, or other types of object, unless the class defines enough of the methods __lt__(), __le__(), __gt__(), and __ge__() (in general, __lt__() and __eq__() are sufficient, if you want the conventional meanings of the comparison operators)." -- This seems to imply that to get all of the operators, only __lt__() and __eq__() need to be defined (just __lt__() should suffice though I thought). So, which is it supposed to be? Or am I reading the documentation wrong? Thanks! -Greg- From no.email at nospam.invalid Sun Dec 5 04:18:22 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 05 Dec 2010 01:18:22 -0800 Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> <4CFA6F16.2060001@holdenweb.com> <4cfaf1ff$0$30003$c3e8da3$5496439d@news.astraweb.com> <7xfwucye3x.fsf@ruckus.brouhaha.com> Message-ID: <7xwrnomvc1.fsf@ruckus.brouhaha.com> Tim Harig writes: > The fact that I bothered to create classes for the dice and roles, rather > then simply iterating over a list of numbers, should tell you that I > produced was of a far more flexible nature; including the support for > roles with dice having different numbers of sides. from itertools import product def n_sided_die(n): return xrange(1, n+1) # make one 3-sided die, one 4-sided die, and one 5-sided die dice = (n_sided_die(3), n_sided_die(4), n_sided_die(5)) for roll in product(*dice): print roll > I merely posted a simplied description of the dice-role objects > because I thought that it demonstrated how exceptions can provide > eligance of control for situations that don't involve what would > traditionally be defined as an error. Exceptions (though sometimes necessary) are messy and I'm having a hard time trying to envision that code being cleaner with them than without them. If you post the actual code maybe that will help me understand. From darragh.ssa at gmail.com Sun Dec 5 04:48:04 2010 From: darragh.ssa at gmail.com (Kruptein) Date: Sun, 5 Dec 2010 01:48:04 -0800 (PST) Subject: Deditor 0.2.3 Message-ID: A new version of the python dedicated linux text-editor has been released! This editor is python specific offering some features to python users like code analyzing, code inspecting, syntax highlighting, ... Information about this project: http://launchpad.net/deditor Information about the latest release: http://kruptein.alwaysdata.net/blag From naseqmohiuddin at gmail.com Sun Dec 5 05:27:08 2010 From: naseqmohiuddin at gmail.com (hollyood) Date: Sun, 5 Dec 2010 02:27:08 -0800 (PST) Subject: s;hlhdlhlah Message-ID: lhdglfhglshglhash From __peter__ at web.de Sun Dec 5 05:37:23 2010 From: __peter__ at web.de (Peter Otten) Date: Sun, 05 Dec 2010 11:37:23 +0100 Subject: Perceived inconsistency in py3k documentation References: <724b26b4-8233-4d57-b76f-cd781cf0cd03@z17g2000prz.googlegroups.com> Message-ID: Greg wrote: > This is my first post here, so if this is not the correct place to ask > this, please direct me to the best place. This is a good place to get general advice and to discuss potential bugs when you are unsure whether they actually are bugs. If you are sure that you ran into a bug in python or want to suggest an improvement of the documentation where it is wrong or unclear or hard to understand you can report to http://bugs.python.org . > In looking at the py3k documentation for comparing two classes, two > different view points are expressed (at least it seems so to me). > 1) At http://docs.python.org/py3k/reference/datamodel.html: > "There are no implied relationships among the comparison operators. > The truth of x==y does not imply that x!=y is false. Accordingly, when > defining __eq__(), one should also define __ne__()..." > -- This seems to support the view that if in our code, we would like > to use comparison operators <, >, =, !=, etc. then we should define a > __lt__(), __gt__(), __eq__(), __ne__(), etc. for each comparison > operator we would like. > > This appears to contrast > 2) At http://docs.python.org/py3k/library/stdtypes.html: > "Instances of a class cannot be ordered with respect to other > instances of the same class, or other types of object, unless the > class defines enough of the methods __lt__(), __le__(), __gt__(), and > __ge__() (in general, __lt__() and __eq__() are sufficient, if you > want the conventional meanings of the comparison operators)." > -- This seems to imply that to get all of the operators, only > __lt__() and __eq__() need to be defined (just __lt__() should suffice > though I thought). > > So, which is it supposed to be? Or am I reading the documentation > wrong? I agree with you that the documentation is at least unclear. The following experiment suggests that list.sort() works correctly if only __lt__() and __eq__() are implemented which in my reading is what your second quote intends to convey. But "enough of the methods..." is a fuzzy statement. The other finding: (1) a != b is emulated with not (a == b) (2) a > b is emulated with b < a is not something I'd expect after reading your first quote, but technically (2) is covered by """... __lt__() and __gt__() are each other?s reflection ...""" $ cat py3compare.py report = True class A: def __init__(self, key, side="A"): self.key = key self.side = side def __eq__(self, other): result = self.key == other.key if report: print(self, "__eq__", other, "-->", result) return result def __lt__(self, other): result = self.key < other.key if report: print(self, "__lt__", other, "-->", result) return result def __str__(self): return "{}({})".format(self.side, self.key) def __repr__(self): return str(self.key) a = A(1, "L") for k in range(3): b = A(k, "R") print("{} != {}: {}\n".format(a, b, a != b)) print("{} > {}: {}\n".format(a, b, a > b)) print() import random items = [] for n in 10, 20: items.extend(map(A, range(n))) random.shuffle(items) report = False items.sort() print(items) print(a <= b) $ python3 py3compare.py L(1) __eq__ R(0) --> False L(1) != R(0): True R(0) __lt__ L(1) --> True L(1) > R(0): True L(1) __eq__ R(1) --> True L(1) != R(1): False R(1) __lt__ L(1) --> False L(1) > R(1): False L(1) __eq__ R(2) --> False L(1) != R(2): True R(2) __lt__ L(1) --> False L(1) > R(2): False [0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] Traceback (most recent call last): File "py3compare.py", line 39, in print(a <= b) TypeError: unorderable types: A() <= A() $ Conclusion: If you can come up with a text that is both correct and clear, don't hesitate to tell us, here or on the bug tracker. Peter PS: The painless way out: always use @functools.total_ordering or the equivalent cookbok recipe. From xdegaye at gmail.com Sun Dec 5 06:15:02 2010 From: xdegaye at gmail.com (Xavier de Gaye) Date: Sun, 5 Dec 2010 12:15:02 +0100 Subject: [ANN] Pyclewn: Vim as a front end to pdb Message-ID: Pyclewn 1.5 has been released at http://pyclewn.sourceforge.net/ Pyclewn is a python program that allows the use of Vim as a front end to gdb and pdb. This release adds support for ``pdb``, the python debugger. + A python script may be run under the control of ``pdb``. For example the current vim buffer may be started and debugged with the vim command ``:Pyclewn pdb %:p`` + One may also attach to a running python process, interrupt the process, manage a debugging session and terminate the debugging session by detaching from the process. A new debugging session may be conducted later on this same process, possibly from another Vim instance. + All the ``pdb`` commands are supported except ``list`` and ``commands``. This includes alias expansion and executing a python statement in the context of the current frame. The new command ``threadstack`` prints the instantaneous backtrace of all the threads, including those that are stuck in a deadlock. * Pdb is currently supported on unix platforms and requires the latest Vim version: Vim 7.3. Python3 is not supported yet. -- Xavier Les Chemins de Lokoti: http://lokoti.alwaysdata.net From usernet at ilthio.net Sun Dec 5 06:21:52 2010 From: usernet at ilthio.net (Tim Harig) Date: Sun, 5 Dec 2010 11:21:52 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> <4CFA6F16.2060001@holdenweb.com> <4cfaf1ff$0$30003$c3e8da3$5496439d@news.astraweb.com> <7xfwucye3x.fsf@ruckus.brouhaha.com> <7xwrnomvc1.fsf@ruckus.brouhaha.com> Message-ID: On 2010-12-05, Paul Rubin wrote: > Tim Harig writes: >> The fact that I bothered to create classes for the dice and roles, rather >> then simply iterating over a list of numbers, should tell you that I >> produced was of a far more flexible nature; including the support for >> roles with dice having different numbers of sides. > > from itertools import product > def n_sided_die(n): return xrange(1, n+1) > > # make one 3-sided die, one 4-sided die, and one 5-sided die > dice = (n_sided_die(3), n_sided_die(4), n_sided_die(5)) > for roll in product(*dice): > print roll Notice that you had to change the structure of your program to accomodate the new possiblity; and, if I throw further requirements at you, you will have to change them again. I didn't want that. What the dice returned may or may not have returned an easy to compute sequence. In fact, for all of the rest of the logic cared, the dice could have computed their value from a previous role of another dice. All of the logic of about what the dice may have returned when asked for their value and how they derived, was encapsilated in the dice themselves. It did not need to be known anywhere else in the program logic. The DSL effectively provided a way do define how the dice decided how to increment themselves, how to choose the value that they returned for their face, and how to know when they could no longer be incremented. The DSL parser generated the dice set from the description given. Creating new dice objects was much easier then attempting to change the logic of how they were rolled. >> I merely posted a simplied description of the dice-role objects >> because I thought that it demonstrated how exceptions can provide >> eligance of control for situations that don't involve what would >> traditionally be defined as an error. > > Exceptions (though sometimes necessary) are messy and I'm having a hard > time trying to envision that code being cleaner with them than without > them. If you post the actual code maybe that will help me understand. Let me get this straight, the same person that was trying to tell me setjmp/longjmp weren't messy thinks exceptions are messy? I have used both. I much prefer the exceptions. I not have to code here to post. The cleanliness of using the exception and calling the dice increments recursively, was that there was no need to figure out which dice needed to be incremented whenever the first die needed to be reset. When a dice needed to be reset, it would raise an exception. This exception would rise through the recursion stack, and thus through the dice, resetting each along the way until it found the one which needed to be incremented or raised past the top call indicating that all of the combinations has been exhausted. There, once the reset condition for the previous dice had been effectively handled, it would be supprested. Had this been done using in band data: 1. The roll object would have needed logic to determine when a reset condition needed to take place, effectively leaking some of the logic from the dice object to the role object. 2. The roll object would have needed logic to determine how to follow the dice which needed to be reset until it found which one needed incrementing. Once again, this logic was better left to the dice walking the resets was automatically handled by the progression of the exception. Even if it wasn't an error, the resets were effectively a exceptional condition from the normal flow of the role object (the primary flow simply being to increment the first die). By using exceptions, I effectively isolated each into its own separate independent flow; and, because they where called separatly, neither needed to have control conditions to detect which was needed. They simply allowed the dice object to decide. From usernet at ilthio.net Sun Dec 5 06:53:24 2010 From: usernet at ilthio.net (Tim Harig) Date: Sun, 5 Dec 2010 11:53:24 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <877hfs2zia.fsf@benfinney.id.au> <4CFA6F16.2060001@holdenweb.com> <4cfaf1ff$0$30003$c3e8da3$5496439d@news.astraweb.com> <7xfwucye3x.fsf@ruckus.brouhaha.com> <7xwrnomvc1.fsf@ruckus.brouhaha.com> Message-ID: On 2010-12-05, Tim Harig wrote: > On 2010-12-05, Paul Rubin wrote: >> Tim Harig writes: >>> The fact that I bothered to create classes for the dice and roles, rather >>> then simply iterating over a list of numbers, should tell you that I >>> produced was of a far more flexible nature; including the support for >>> roles with dice having different numbers of sides. >> >> from itertools import product >> def n_sided_die(n): return xrange(1, n+1) >> >> # make one 3-sided die, one 4-sided die, and one 5-sided die >> dice = (n_sided_die(3), n_sided_die(4), n_sided_die(5)) >> for roll in product(*dice): >> print roll > > Notice that you had to change the structure of your program to accomodate > the new possiblity; and, if I throw further requirements at you, you > will have to change them again. I didn't want that. What the dice > returned may or may not have returned an easy to compute sequence. > In fact, for all of the rest of the logic cared, the dice could have > computed their value from a previous role of another dice. All of the > logic of about what the dice may have returned when asked for their > value and how they derived, was encapsilated in the dice themselves. > It did not need to be known anywhere else in the program logic. > > The DSL effectively provided a way do define how the dice decided how > to increment themselves, how to choose the value that they returned for > their face, and how to know when they could no longer be incremented. > The DSL parser generated the dice set from the description given. > Creating new dice objects was much easier then attempting to change the > logic of how they were rolled. > >>> I merely posted a simplied description of the dice-role objects >>> because I thought that it demonstrated how exceptions can provide >>> eligance of control for situations that don't involve what would >>> traditionally be defined as an error. >> >> Exceptions (though sometimes necessary) are messy and I'm having a hard >> time trying to envision that code being cleaner with them than without >> them. If you post the actual code maybe that will help me understand. > > Let me get this straight, the same person that was trying to tell me > setjmp/longjmp weren't messy thinks exceptions are messy? I have used > both. I much prefer the exceptions. I not have to code here to post. > > The cleanliness of using the exception and calling the dice increments > recursively, was that there was no need to figure out which dice needed > to be incremented whenever the first die needed to be reset. When a dice > needed to be reset, it would raise an exception. This exception would > rise through the recursion stack, and thus through the dice, resetting > each along the way until it found the one which needed to be incremented > or raised past the top call indicating that all of the combinations has > been exhausted. There, once the reset condition for the previous dice > had been effectively handled, it would be supprested. > > Had this been done using in band data: > > 1. The roll object would have needed logic to determine when > a reset condition needed to take place, effectively > leaking some of the logic from the dice object to the > role object. > > 2. The roll object would have needed logic to determine how to > follow the dice which needed to be reset until it found > which one needed incrementing. Once again, this logic > was better left to the dice walking the resets was > automatically handled by the progression of the exception. > > Even if it wasn't an error, the resets were effectively a exceptional > condition from the normal flow of the role object (the primary flow simply > being to increment the first die). By using exceptions, I effectively > isolated each into its own separate independent flow; and, because they > where called separatly, neither needed to have control conditions to detect > which was needed. They simply allowed the dice object to decide. Okay, it occures to me that you don't really need to see much to know what was going on, here is the basic idea of how the role function of the object would have looked like: def role(self, dice): try: self.role(dice.previous()) except diceReset: dice.increment() except endOfDice: raise diceReset From lie.1296 at gmail.com Sun Dec 5 07:08:47 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 05 Dec 2010 23:08:47 +1100 Subject: Which non SQL Database ? In-Reply-To: References: <87d3phcfaw.fsf@gmail.com> Message-ID: <4cfb8021$1@dnews.tpgi.com.au> On 12/05/10 10:43, Jorge Biquez wrote: > I do not see a good reason for not using Sqlite3 BUT if for some reason > would not be an option.... what plain schema of files would you use? Assuming you don't want SQL, you can use filesystem-based database. Most people doesn't realize that a filesystem is essentially a database (of files) and a file explorer is a (sort of) DBMS. It is relatively easy to create a robust (as robust as the filesystem) and fast (as fast as the filesystem) database system by using folders and files (and optionally hard and symbolic links) to store data in hierarchical topology. From python.list at tim.thechases.com Sun Dec 5 08:00:17 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 05 Dec 2010 07:00:17 -0600 Subject: Comparison with False - something I don't understand In-Reply-To: <4cfb263a$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <877hfs2zia.fsf@benfinney.id.au> <4CFA6F16.2060001@holdenweb.com> <4cfaf1ff$0$30003$c3e8da3$5496439d@news.astraweb.com> <4cfb263a$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4CFB8CE1.9000807@tim.thechases.com> On 12/04/2010 11:42 PM, Steven D'Aprano wrote: > On Sun, 05 Dec 2010 04:13:02 +0000, Tim Harig wrote: > str.find is more troublesome, because the sentinel -1 doesn't propagate > and is a common source of errors: > > result = string[string.find(delim):] > > will return a plausible-looking but incorrect result if delim is missing > from string. But the convenience and familiarity of str.find means it > will probably be around forever. Fortunately, string objects offer both .find() and .index() so you can choose whether you want sentinels or exceptions according to your use-case. -tkc From python.list at tim.thechases.com Sun Dec 5 08:03:52 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 05 Dec 2010 07:03:52 -0600 Subject: Which non SQL Database ? In-Reply-To: References: <201012042241.oB4Mfcfi079977@krusty.intranet.com.mx> Message-ID: <4CFB8DB8.3070101@tim.thechases.com> On 12/05/2010 03:41 AM, Alan Gauld wrote: > Why not use SQL? > SQLlite comes with Python, is small, easy to use and if necessary > can be used in-memory and as such fast. The only reason I could see using something other than sqlite3 for such a use-case would be if the OP has to support Python before version 2.5 and can't add/install the sqlite libraries to his deployment platform(s). I've got a couple targets still running 2.4 and regularly mutter under my breath when I reach for sqlite to find it's not there. -tkc From steve at holdenweb.com Sun Dec 5 08:42:47 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 05 Dec 2010 14:42:47 +0100 Subject: How to add data into exisitng Excel file at next open row? In-Reply-To: <2acc7858-e55b-4cfe-8e10-1c0d716a10d4@o4g2000yqd.googlegroups.com> References: <2acc7858-e55b-4cfe-8e10-1c0d716a10d4@o4g2000yqd.googlegroups.com> Message-ID: On 12/3/2010 6:21 PM, noydb wrote: > How can you determine the next open row in an existing Excel file such > that you can start adding data to the cells in that row? As in below, > I want a variable in place of the 6 (row 6 in the four ws1.Cells(x,1) > lines), but have no other way of knowing what row I am on besides > looking to the first free cell in column A. How to do? Examples I > see make it seem really complicated - this can't be that hard. > > Thanks for any help. > > worksheet = "C:\\Excel_Reports\\ea" + ea + "report"# + ".xls" > xlApp = win32com.client.Dispatch("Excel.Application") > xlApp.Visible = 1 > xlApp.Workbooks.Open(worksheet) ## for existing file > ##xlApp.SheetsInNewWorkbook = 1 > ##wb = xlApp.Workbooks() > ws1 = xlApp.Worksheets(1) > > ws1.Cells(6,1).Value = "selection" > ws1.Cells(6,2).Value = count > ws1.Cells(6,3).Value = epcFloat > ws1.Cells(6,8).Value = currentGMT > > wb.SaveAs(worksheet) > wb.Close(False) ## False/1 You might want to take a look at the xlrd library. This lets you read Excel spreadsheets even on Unix platforms and without the use of COM magic. There's also an xlwt module for writing spreadsheets. However I understand that the two together may not be as convenient as modifying a spreadsheet in place. In particular, if sh is a spreadsheet then sh.nrows gives you the number of rows currently used in the sheet. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From roy at panix.com Sun Dec 5 09:22:13 2010 From: roy at panix.com (Roy Smith) Date: Sun, 05 Dec 2010 09:22:13 -0500 Subject: Which non SQL Database ? References: <87d3phcfaw.fsf@gmail.com> <4cfb8021$1@dnews.tpgi.com.au> Message-ID: In article <4cfb8021$1 at dnews.tpgi.com.au>, Lie Ryan wrote: > On 12/05/10 10:43, Jorge Biquez wrote: > > I do not see a good reason for not using Sqlite3 BUT if for some reason > > would not be an option.... what plain schema of files would you use? > > Assuming you don't want SQL, you can use filesystem-based database. Most > people doesn't realize that a filesystem is essentially a database (of > files) and a file explorer is a (sort of) DBMS. It is relatively easy to > create a robust (as robust as the filesystem) and fast (as fast as the > filesystem) database system by using folders and files (and optionally > hard and symbolic links) to store data in hierarchical topology. Another possibility is one of the new breed of non-relational databases. We've been using MongoDB (http://www.mongodb.org/) and so far are happy with it. You can find a bunch of other alternatives in Wikipedia's NoSQL article. From rupertlssmith at googlemail.com Sun Dec 5 12:13:22 2010 From: rupertlssmith at googlemail.com (rupertlssmith at googlemail.com) Date: Sun, 5 Dec 2010 09:13:22 -0800 (PST) Subject: Unknown function operation deciphering, exercise in readability by program reasoning References: <46365e1d-42d8-4b3b-8e69-941472467472@u25g2000pra.googlegroups.com> <5e1f79ab-5432-4f18-b896-362b7406c75c@i18g2000yqn.googlegroups.com> Message-ID: <7a4bf118-1068-432b-ae3f-3a31d1489865@q18g2000vbk.googlegroups.com> On Dec 5, 3:34?am, jvt wrote: > On Dec 4, 4:49?pm, Barb Knox wrote: > > > > > > > In article > > <46365e1d-42d8-4b3b-8e69-941472467... at u25g2000pra.googlegroups.com>, > > ?small Pox wrote: > > > > Rules : > > > No need to add any additional hurdles -- the code as presented is > > thoroughly unreadable by humans. > > > > @1@ ?No execution of the function, only checking syntax > > > What about "desk checking" (a lost art from the oldene dayes)? > > > > @2@ ?No profiling using a debugger or profiler > > > > @3@ ?Editing allowed to make simpler variables > > > Maybe if you had done that yourself before posting it then I would have > > tried to understand it. ?As it is, no way. > > > > (defun unknown-function (nano-thermite-911-FBI-fat-per-diem-bustards- > > > kept-their-odious-mouth-shut-on-anthrax-and-911-lie) > > > ? (let (BERNARD-MADOFF-PHILIP-MARKOFF-MIKHAIL-KHODORKOVSKY-NEOCONS- > > > PAUL-WOLFOWITZ-LEWIS-SCOOTER-LIBBY-MOSHE-KATSEV-MOSSAD-DUBAI-MURDERERS > > > I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN-SPEECH-ON-KHAZARS) > > > ? ? (while (or I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN- > > > SPEECH-ON-KHAZARS nano-thermite-911-FBI-fat-per-diem-bustards-kept- > > > their-odious-mouth-shut-on-anthrax-and-911-lie) > > > ? ? ? (if nano-thermite-911-FBI-fat-per-diem-bustards-kept-their- > > > odious-mouth-shut-on-anthrax-and-911-lie > > > ? ? ? ? ? (if (consp nano-thermite-911-FBI-fat-per-diem-bustards-kept- > > > their-odious-mouth-shut-on-anthrax-and-911-lie) > > > ? ? ? ? ? ? ? (setq I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN- > > > SPEECH-ON-KHAZARS (cons (cdr nano-thermite-911-FBI-fat-per-diem- > > > bustards-kept-their-odious-mouth-shut-on-anthrax-and-911-lie) > > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? I-AM-THE-WITNESS-DOT-COM-has-MR- > > > BENJAMIN-FREEDMAN-SPEECH-ON-KHAZARS) > > > ? ? ? ? ? ? ? ? ? ? nano-thermite-911-FBI-fat-per-diem-bustards-kept- > > > their-odious-mouth-shut-on-anthrax-and-911-lie (car nano-thermite-911- > > > FBI-fat-per-diem-bustards-kept-their-odious-mouth-shut-on-anthrax- > > > and-911-lie)) > > > ? ? ? ? ? ? (setq BERNARD-MADOFF-PHILIP-MARKOFF-MIKHAIL-KHODORKOVSKY- > > > NEOCONS-PAUL-WOLFOWITZ-LEWIS-SCOOTER-LIBBY-MOSHE-KATSEV-MOSSAD-DUBAI- > > > MURDERERS (cons nano-thermite-911-FBI-fat-per-diem-bustards-kept-their- > > > odious-mouth-shut-on-anthrax-and-911-lie BERNARD-MADOFF-PHILIP-MARKOFF- > > > MIKHAIL-KHODORKOVSKY-NEOCONS-PAUL-WOLFOWITZ-LEWIS-SCOOTER-LIBBY-MOSHE- > > > KATSEV-MOSSAD-DUBAI-MURDERERS) > > > ? ? ? ? ? ? ? ? ? nano-thermite-911-FBI-fat-per-diem-bustards-kept- > > > their-odious-mouth-shut-on-anthrax-and-911-lie nil)) > > > ? ? ? ? (setq nano-thermite-911-FBI-fat-per-diem-bustards-kept-their- > > > odious-mouth-shut-on-anthrax-and-911-lie (car I-AM-THE-WITNESS-DOT-COM- > > > has-MR-BENJAMIN-FREEDMAN-SPEECH-ON-KHAZARS) > > > ? ? ? ? ? ? ? I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN-SPEECH- > > > ON-KHAZARS (cdr I-AM-THE-WITNESS-DOT-COM-has-MR-BENJAMIN-FREEDMAN- > > > SPEECH-ON-KHAZARS)))) > > > ? ? BERNARD-MADOFF-PHILIP-MARKOFF-MIKHAIL-KHODORKOVSKY-NEOCONS-PAUL- > > > WOLFOWITZ-LEWIS-SCOOTER-LIBBY-MOSHE-KATSEV-MOSSAD-DUBAI-MURDERERS)) > > > -- > > --------------------------- > > | ?BBB ? ? ? ? ? ? ? ?b ? ?\ ? ? Barbara at LivingHistory stop co stop uk > > | ?B ?B ? aa ? ? rrr ?b ? ? | > > | ?BBB ? a ?a ? r ? ? bbb ? | ? ?Quidquid latine dictum sit, > > | ?B ?B ?a ?a ? r ? ? b ?b ?| ? ?altum videtur. > > | ?BBB ? ?aa a ?r ? ? bbb ? | ? > > ----------------------------- > > I think this is correct: > > (defun unknown-function (sym0) > ? (let (sym1 sym2) > ? ? ? ? (while (or sym2 sym0) > ? ? ? ? ? (if sym0 > ? ? ? ? ? ? ? ? ? (if (consp sym0) > ? ? ? ? ? ? ? ? ? ? ? ? ? (setq sym2 (cons (cdr sym0) sym2) sym0 (car sym0)) > ? ? ? ? ? ? ? ? ? ? ? ? (setq sym3 sym4 (cons sym0 sym1) sym0 nil)) > ? ? ? ? ? ? ? ? (setq sym0 (car sym2) sym2 (cdr sym2)))) > ? ? ? ? sym1)) > Thank emacs, not me. Lisp? Still can't read it... ;-) From smallpox911 at gmail.com Sun Dec 5 12:57:12 2010 From: smallpox911 at gmail.com (small Pox) Date: Sun, 5 Dec 2010 09:57:12 -0800 (PST) Subject: Unknown function operation deciphering, exercise in readability by program reasoning References: <46365e1d-42d8-4b3b-8e69-941472467472@u25g2000pra.googlegroups.com> <5e1f79ab-5432-4f18-b896-362b7406c75c@i18g2000yqn.googlegroups.com> <7a4bf118-1068-432b-ae3f-3a31d1489865@q18g2000vbk.googlegroups.com> Message-ID: <8105915f-e5c3-48c8-9f25-3cbe7ba332d4@i25g2000prd.googlegroups.com> On Dec 5, 9:13?am, "rupertlssm... at googlemail.com" wrote: > On Dec 5, 3:34?am, jvt wrote: > > > I think this is correct: > > > (defun unknown-function (sym0) > > ? (let (sym1 sym2) > > ? ? ? ? (while (or sym2 sym0) > > ? ? ? ? ? (if sym0 > > ? ? ? ? ? ? ? ? ? (if (consp sym0) > > ? ? ? ? ? ? ? ? ? ? ? ? ? (setq sym2 (cons (cdr sym0) sym2) sym0 (car sym0)) > > ? ? ? ? ? ? ? ? ? ? ? ? (setq sym3 sym4 (cons sym0 sym1) sym0 nil)) > > ? ? ? ? ? ? ? ? (setq sym0 (car sym2) sym2 (cdr sym2)))) > > ? ? ? ? sym1)) > > Thank emacs, not me. > > Lisp? Still can't read it... ;-)- Hide quoted text - > This is because madhu did not explain how he reasoned. Does it appear to you that she broke first two rules. its a list flattener that also reverses the operation. it appears that she took the consp predicate and/or flatten and started googling ... naughty girl. From smallpox911 at gmail.com Sun Dec 5 13:03:33 2010 From: smallpox911 at gmail.com (small Pox) Date: Sun, 5 Dec 2010 10:03:33 -0800 (PST) Subject: Unknown function operation deciphering, exercise in readability by program reasoning References: <46365e1d-42d8-4b3b-8e69-941472467472@u25g2000pra.googlegroups.com> <5e1f79ab-5432-4f18-b896-362b7406c75c@i18g2000yqn.googlegroups.com> Message-ID: On Dec 4, 11:37?pm, Madhu wrote: > * jvt <5e1f79ab-5432-4f18-b896-362b7406c... at i18g2000yqn.googlegroups.com> : > Wrote on Sat, 4 Dec 2010 19:34:53 -0800 (PST): > > | > | I think this is correct: > | > | > | (defun unknown-function (sym0) > | ? (let (sym1 sym2) > | ? ? ? (while (or sym2 sym0) > | ? ? ? ? (if sym0 > | ? ? ? ? ? ? ? ? (if (consp sym0) > | ? ? ? ? ? ? ? ? ? ? ? ? (setq sym2 (cons (cdr sym0) sym2) sym0 (car sym0)) > | ? ? ? ? ? ? ? ? ? ? ? (setq sym3 sym4 (cons sym0 sym1) sym0 nil)) > | ? ? ? ? ? ? ? (setq sym0 (car sym2) sym2 (cdr sym2)))) > | ? ? ? sym1)) > | Thank emacs, not me. > > Not quite. You didn't account for the original poster's go- > ogle masters mangling his message. ? But your function appears to be a > list flattener: explanation > (defun unknown-function (list) > ? (let (stack ret) > ? ? (while (or ret list) > ? ? ? (if list > ? ? ? ? ? (if (consp list) > ? ? ? ? ? ? ? (setq ret (cons (cdr list) ret) ;; hint: this is a push followed by list (car list)) ;; pop > ? ? ? ? ? ? (setq stack (cons list stack) ;; and so is this list nil)) > ? ? ? ? (setq list (car ret) ret (cdr ret)))) > ? ? stack)) > > --- > Madhu I will post an explanation in a few days if no one does this before since its not urgent for anyone and i have some job assignments to finish. From aharrisreid at googlemail.com Sun Dec 5 13:20:17 2010 From: aharrisreid at googlemail.com (Alan Harris-Reid) Date: Sun, 05 Dec 2010 18:20:17 +0000 Subject: Framework design question Message-ID: <4CFBD7E1.9030908@googlemail.com> Hi, When committing data that has originally come from a webpage, sometimes data has to be converted to a data type or format which is suitable for the back-end database. For instance, a date in 'dd/mm/yyyy' format needs to be converted to a Python date-object or 'yyyy-mm-dd' in order to be stored in a SQLite date column (SQLite will accept 'dd/mm/yy', but that can cause problems when data is retrieved). Question - at what point should the data be converted? a) As part of a generic web_page_save() method (immediately after data validation, but before a row.table_update() method is called). b) As part of row.table_update() (a data-object method called from web- or non-web-based applications, and includes construction of a field-value parameter list prior to executing the UPDATE command). In other words, from a framework point-of-view, does the data-conversion belong to page-object processing or data-object processing? Any opinions would be appreciated. Alan From python at mrabarnett.plus.com Sun Dec 5 14:09:24 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 05 Dec 2010 19:09:24 +0000 Subject: Framework design question In-Reply-To: <4CFBD7E1.9030908@googlemail.com> References: <4CFBD7E1.9030908@googlemail.com> Message-ID: <4CFBE364.6040400@mrabarnett.plus.com> On 05/12/2010 18:20, Alan Harris-Reid wrote: > > Hi, > > When committing data that has originally come from a webpage, sometimes > data has to be converted to a data type or format which is suitable for > the back-end database. For instance, a date in 'dd/mm/yyyy' format needs > to be converted to a Python date-object or 'yyyy-mm-dd' in order to be > stored in a SQLite date column (SQLite will accept 'dd/mm/yy', but that > can cause problems when data is retrieved). > > Question - at what point should the data be converted? > a) As part of a generic web_page_save() method (immediately after data > validation, but before a row.table_update() method is called). > b) As part of row.table_update() (a data-object method called from web- > or non-web-based applications, and includes construction of a > field-value parameter list prior to executing the UPDATE command). > > In other words, from a framework point-of-view, does the data-conversion > belong to page-object processing or data-object processing? > > Any opinions would be appreciated. > I would use a standardised 'international' form as much as possible, converting to it as early as possible and from it as late as possible. This applies to dates, text (using Unicode internally), etc. From noydb00 at gmail.com Sun Dec 5 14:26:41 2010 From: noydb00 at gmail.com (noydb) Date: Sun, 5 Dec 2010 11:26:41 -0800 (PST) Subject: How to add data into exisitng Excel file at next open row? References: <2acc7858-e55b-4cfe-8e10-1c0d716a10d4@o4g2000yqd.googlegroups.com> Message-ID: <73cd31ad-f9bf-4767-8a25-0884a9f072a5@h22g2000vbr.googlegroups.com> On Dec 5, 8:42?am, Steve Holden wrote: > On 12/3/2010 6:21 PM, noydb wrote: > > > > > > > How can you determine the next open row in an existing Excel file such > > that you can start adding data to the cells in that row? ?As in below, > > I want a variable in place of the 6 (row 6 in the four ws1.Cells(x,1) > > lines), but have no other way of knowing what row I am on besides > > looking to the first free cell in column A. ?How to do? ?Examples I > > see make it seem really complicated - this can't be that hard. > > > Thanks for any help. > > > worksheet = "C:\\Excel_Reports\\ea" + ea + "report"# + ".xls" > > xlApp = win32com.client.Dispatch("Excel.Application") > > xlApp.Visible = 1 > > xlApp.Workbooks.Open(worksheet) ## for existing file > > ##xlApp.SheetsInNewWorkbook = 1 > > ##wb = xlApp.Workbooks() > > ws1 = xlApp.Worksheets(1) > > > ws1.Cells(6,1).Value = "selection" > > ws1.Cells(6,2).Value = count > > ws1.Cells(6,3).Value = epcFloat > > ws1.Cells(6,8).Value = currentGMT > > > wb.SaveAs(worksheet) > > wb.Close(False) ## False/1 > > You might want to take a look at the xlrd library. This lets you read > Excel spreadsheets even on Unix platforms and without the use of COM > magic. There's also an xlwt module for writing spreadsheets. However I > understand that the two together may not be as convenient as modifying a > spreadsheet in place. > > In particular, if sh is a spreadsheet then sh.nrows gives you the number > of rows currently used in the sheet. > > regards > ?Steve > -- > Steve Holden ? ? ? ? ? +1 571 484 6266 ? +1 800 494 3119 > PyCon 2011 Atlanta March 9-17 ? ? ?http://us.pycon.org/ > See Python Video! ? ? ?http://python.mirocommunity.org/ > Holden Web LLC ? ? ? ? ? ? ? ?http://www.holdenweb.com/- Hide quoted text - > > - Show quoted text - Thanks, good to keep in mind. I have used xlrd before in cases where i'm not sure if excel is installed on a user's machine. Someone else helped, provided this> NextRow = ws1.Range("A1").SpecialCells(xlLastCell).Row + 1 Although to get it to work for me, I have to use the number code for some reason, like > NextRow = ws1.Range("A1").SpecialCells(11).Row + 1 From tjreedy at udel.edu Sun Dec 5 14:47:38 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 05 Dec 2010 14:47:38 -0500 Subject: Perceived inconsistency in py3k documentation In-Reply-To: <724b26b4-8233-4d57-b76f-cd781cf0cd03@z17g2000prz.googlegroups.com> References: <724b26b4-8233-4d57-b76f-cd781cf0cd03@z17g2000prz.googlegroups.com> Message-ID: On 12/5/2010 3:31 AM, Greg wrote: For future reference, > 1) At http://docs.python.org/py3k/reference/datamodel.html: > 2) At http://docs.python.org/py3k/library/stdtypes.html: do not work because of the trailing :s, at least not with FireFox. > 1) At http://docs.python.org/py3k/reference/datamodel.html : > 2) At http://docs.python.org/py3k/library/stdtypes.html : These, with space after the url, should. Other puctuation can be a problem too, so it is best to always follow urls with whitespace. -- Terry Jan Reedy From stef.mientki at gmail.com Sun Dec 5 15:11:20 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 05 Dec 2010 21:11:20 +0100 Subject: Which non SQL Database ? In-Reply-To: <201012042241.oB4Mfcfi079977@krusty.intranet.com.mx> References: <201012042241.oB4Mfcfi079977@krusty.intranet.com.mx> Message-ID: <4CFBF1E8.9070505@gmail.com> On 04-12-2010 23:42, Jorge Biquez wrote: > Hello all. > > Newbie question. Sorry. > > As part of my process to learn python I am working on two personal applications. Both will do it > fine with a simple structure of data stored in files. I now there are lot of databases around I > can use but I would like to know yoor advice on what other options you would consider for the job > (it is training so no pressure on performance). One application will run as a desktop one,under > Windows, Linux, Macintosh, being able to update data, not much, not complex, not many records. The > second application, running behind web pages, will do the same, I mean, process simple data, > updating showing data. not much info, not complex. As an excersice it is more than enough I guess > and will let me learn what I need for now. > Talking with a friend about what he will do (he use C only) he suggest to take a look on dBase > format file since it is a stable format, fast and the index structure will be fine or maybe go > with BD (Berkley) database file format (I hope I understood this one correctly) . Plain files it > is not an option since I would like to have option to do rapid searches. > > What would do you suggest to take a look? If possible available under the 3 plattforms. > > Thanks in advance for your comments. > > Jorge Biquez > You should take a look at one of the database wrappers. I use the DAL of Web2Py, the main advantages are - easy use of database (more easy than SQL) - easy migration of database structure (is done automatically) - same interface on desktop and in web applications - all major database (including SQLite and Postgres) supported and can be switched easily cheers, Stef From martin at v.loewis.de Sun Dec 5 16:01:27 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sun, 05 Dec 2010 22:01:27 +0100 Subject: Comparison with False - something I don't understand In-Reply-To: References: <877hfs2zia.fsf@benfinney.id.au> Message-ID: <4CFBFDA7.4000907@v.loewis.de> > result = myfunction (vars) > > if not result: > # error condition > > Now above I first realized that the function can also return an empty > list under some conditions and so changed it to If your function returns a list when successful, it should not return False in the error case. Instead, it should return None (indicating that there is no list). Then the condition changes to result = myfunction() if result is None: # error condition Using None for "no result available" is very common in Python. Using False for the same purpose (i.e. returning either a list or False) is not. If you return False from a function, the only other possible result should be True. Regards, Martin From drsalists at gmail.com Sun Dec 5 16:55:35 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 5 Dec 2010 13:55:35 -0800 Subject: Which non SQL Database ? In-Reply-To: <4cfb4714$0$1594$742ec2ed@news.sonic.net> References: <87d3phcfaw.fsf@gmail.com> <201012042343.oB4Nh18D084173@krusty.intranet.com.mx> <4cfb4714$0$1594$742ec2ed@news.sonic.net> Message-ID: On Sun, Dec 5, 2010 at 12:01 AM, John Nagle wrote: > On 12/4/2010 8:44 PM, Monte Milanuk wrote: >> >> On 12/4/10 3:43 PM, Jorge Biquez wrote: >> >>> I do not see a good reason for not using Sqlite3 BUT if for some reason >>> would not be an option.... what plain schema of files would you use? >> >> Would shelve work? > > ? ?There are some systems for storing key-value pairs in files. > > ? ?Underneath "shelve" is some primitive database, dbm, gdbm or bsddb. > "bsddb" is deprecated and was removed from Python 3.x. ?"dbm" has > some classic problems. ?"gdbm" is an improved version of "dbm". > None of these handle access from multiple processes, or crash > recovery. ?We're looking at 1979 technology here. > > ? SQLite works right when accessed from multiple processes. ?SQLite > is the entry-level database technology for Python today. ?It handles > the hard cases, like undoing transactions after a crash and > locking against multiple accesses. ?Lookup performance is good; > simultaneous update by multiple processes, though, is not so > good. ?When you have a web site that has many processes hitting > the same database, it's time to move up to MySQL or Postgres. > > ? There's a lot of interest in "non-SQL" databases for very > large distributed systems. ?You worry about this if you're Facebook > or Google, or are running a big game server farm. SQLite isn't exactly no SQL. I've used the bsddb and gdbm modules quite a bit. I've found that bsddb tables tend to get corrupted (whether used from CPython or C), EG when a filesystem fills up. I quite like the gdbm module though, and have been using it in my current project. If you find that converting your database keys and values to/from strings is expensive, you could check out http://stromberg.dnsalias.org/~dstromberg/cachedb.html which is a caching wrapper around gdbm and other single-table database interfaces supporting the same API. As far as multiple processes, IINM, gdbm supports a single writer and multiple readers. From mmanns at gmx.net Sun Dec 5 17:49:36 2010 From: mmanns at gmx.net (Martin Manns) Date: Sun, 5 Dec 2010 23:49:36 +0100 Subject: Collision of rotated rectangles without pygame Message-ID: <20101205234936.39dc1a4e@Knock> Hello, I am looking for a Python library for 2D collision checks of rotated rectangles. Currently, I have found vizier 0.5b that is based on pygame. Since I do not want to add a pygame dependency to my app, I replaced the pygame.rect.Rect by a wxPython wx.Rect (see code below). However, collision checks do not work correctly, i. e. identical rects are not found to be colliding: $ python Python 2.6.6 (r266:84292, Nov 28 2010, 18:42:58) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import xrect >>> r=xrect.RotoRect(10,10,30,20,angle=34) >>> s=xrect.RotoRect(10,10,30,20,angle=34) >>> r.rotocollide(s) False >>> Is my replacement of the rectangle object wrong or is vizier not working correctly with pygame as well? Do you know of any other pure Python library for rotated rectangle collision checks? Cheers Martin ---------------------------------------- from __future__ import division import math import wx ############################################################################## cos_table = dict([(deg, math.cos(math.radians(deg))) for deg in xrange(360)]) sin_table = dict([(deg, math.sin(math.radians(deg))) for deg in xrange(360)]) class RotoRect(wx.Rect): def __init__(self, *a, **kw): self.deg = kw.pop('angle') wx.Rect.__init__(self, *a, **kw) # pygame rect compatibility for wx.Rect def get_center(self): return self.centerx, self.centery def set_center(self, center): self.centerx, self.centery = center def get_centerx(self): return self.x + self.width / 2 def set_centerx(self, centerx): self.SetX(centerx - self.width / 2) def get_centery(self): return self.y + self.height / 2 def set_centery(self, centery): self.SetY(centery - self.height / 2) def get_topleft(self): return self.GetTopLeft() def set_topleft(self, p): self.SetTopLeft(p) def get_topright(self): return self.GetTopRight() def set_topright(self, p): self.SetTopRight(p) center = property(get_center, set_center) centerx = property(get_centerx, set_centerx) centery = property(get_centery, set_centery) topleft = property(get_topleft, set_topleft) topright = property(get_topright, set_topright) # Now for the vizier code def rotate(self, point, origin = 0): """Returns coords of point p rotated self.theta radians with the rectangle around its center """ if not origin: origin = self.center p_x = point[0] p_y = point[1] o_x = origin[0] o_y = origin[1] costheta = cos_table[self.deg] sintheta = sin_table[self.deg] return ((o_x + costheta * (p_x - o_x)) - (sintheta * (p_y - o_y)), (o_y + sintheta * (p_x - o_x)) + (costheta * (p_y - o_y))) def rotoxt(self, a, b): """Returns the y extremity xt of rect between self.rect""" a_x = a[0] a_y = a[1] b_x = b[0] b_y = b[1] #calculate difference between self.left and b_x dxl = self.left - b_x #calculate difference between self.right and b_x dxr = self.right - b_x #if b_x isn't between self.left and self.right if (dxl * dxr) > 0: #if dxl < 1, b_x is on the right if (dxl < 0): #xt = (m * dxr) + b_y xt = ((((b_y - (-a_y)) / (b_x - (-a_x))) * dxr) + b_y) else: #else b_x is on the left #xt = (m * dxl) + b_y xt = ((((b_y - a_y) / (b_x - a_x)) * dxl) + b_y) return xt else: #else b_x is between self.left and self.right, and xt = b_y return b_y def rotocollide(self, rect): """Check for collision between self.rect and rect""" #initialize collision to False col = False #transforming the plane to set rect's center to the origin transplane = rect.center #set rect's center to the origin rect.center = (0, 0) #transform self.rect's center by the transplane amount self.center = (self.centerx - transplane[0], self.centery - transplane[1]) #transforming the plane to set self.rect's theta to 0 transdeg = self.deg #set self.rect's theta to 0 self.deg = 0 #transform rect's theta by the transtheta amount rect.deg -= transdeg #determine which vertice is min/max x/y NOTE: # a = left/right, b = top/bottom if (sin_table[rect.deg] * cos_table[rect.deg]) > 0: #a = extreme left/right, b = extreme top/bottom a, b = rect.topright, rect.topleft else: a, b = rect.topleft, rect.topright #determine if a.x is min/max if sin_table[rect.deg] < 0: #ensure a is always max a = -a[0], -a[1] a_x = a[0] negb = -b[0], -b[1] #check that range of rect (-a.x, a.x) overlaps range of #self.rect (self.left, self.right) if (a_x >= self.left) and (self.right >= -a_x): #get the first extremity xt1 = self.rotoxt(a, b) #get the other extermity xt2 = self.rotoxt(a, negb) #check for an intersection between the two extremities and #self.rect's top/bottom col = (((xt1 >= self.top) and (self.bottom >= xt2)) or ((xt2 >= self.top) and (self.bottom >= xt1))) #retransform rect.center rect.center = transplane #retransform self.rect.center self.center = (self.centerx + transplane[0], self.centery + transplane[1]) #retransform self.theta self.deg = transdeg #retransform rect.theta rect.deg += transdeg #return results of collision test return col @property def rotox(self): return self.rotate(self.topleft)[0] @property def rotoy(self): return self.rotate(self.topleft)[1] @property def rotoleft(self): return self.rotate(self.left) @property def rotoright(self): return self.rotate(self.right) @property def rototop(self): return self.rotate(self.top) @property def rotobottom(self): return self.rotate(self.bottom) @property def rototopleft(self): return self.rotate(self.topleft) @property def rototopright(self): return self.rotate(self.topright) @property def rotobottomright(self): return self.rotate(self.bottomright) @property def rotobottomleft(self): return self.rotate(self.bottomleft) @property def rotomidleft(self): return self.rotate(self.midleft) @property def rotomidright(self): return self.rotate(self.midright) @property def rotomidtop(self): return self.rotate(self.midtop) @property def rotomidbottom(self): return self.rotate(self.midbottom) From mmanns at gmx.net Sun Dec 5 17:56:03 2010 From: mmanns at gmx.net (Martin Manns) Date: Sun, 5 Dec 2010 23:56:03 +0100 Subject: Collision of rotated rectangles without pygame References: <20101205234936.39dc1a4e@Knock> Message-ID: <20101205235603.16fdce09@Knock> On Sun, 5 Dec 2010 23:49:36 +0100 Martin Manns wrote: > Is my replacement of the rectangle object wrong or is vizier not > working correctly with pygame as well? Answering my first question: Vizier works O.K. with pygame. I am unsure what I did wrong in the rect replacement though. Cheers Martin From python at mrabarnett.plus.com Sun Dec 5 21:01:24 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 06 Dec 2010 02:01:24 +0000 Subject: Comparison with False - something I don't understand In-Reply-To: <4CFBFDA7.4000907@v.loewis.de> References: <877hfs2zia.fsf@benfinney.id.au> <4CFBFDA7.4000907@v.loewis.de> Message-ID: <4CFC43F4.2090705@mrabarnett.plus.com> On 05/12/2010 21:01, Martin v. Loewis wrote: >> result = myfunction (vars) >> >> if not result: >> # error condition >> >> Now above I first realized that the function can also return an empty >> list under some conditions and so changed it to > > If your function returns a list when successful, it should not return > False in the error case. Instead, it should return None (indicating that > there is no list). > > Then the condition changes to > > result = myfunction() > if result is None: > # error condition > > Using None for "no result available" is very common in Python. Using > False for the same purpose (i.e. returning either a list or False) > is not. If you return False from a function, the only other possible > result should be True. > As an example, the re module uses both two approaches. If you ask it to compile a regex: rgx = re.compile(regex) it either returns a PatternObject (if the regex is valid) or raises an exception (if the regex isn't valid). If you ask it to search a string: rgx.search(string) it returns either a MatchObject (if the match is successful) or None (if the match isn't successful). From wuwei23 at gmail.com Sun Dec 5 21:26:05 2010 From: wuwei23 at gmail.com (alex23) Date: Sun, 5 Dec 2010 18:26:05 -0800 (PST) Subject: How do I get the email address of the person who clicked the link in the email? References: <63971a7c-8366-471b-ac7f-812f7dab81ba@n10g2000yqd.googlegroups.com> Message-ID: <19d3af43-13d8-4ed2-a63f-0df86b9e602a@o14g2000prn.googlegroups.com> On Dec 5, 10:15?am, Zeynel wrote: > I am working with Google App Engine python version. The app sends an > email to the user with a link to a page to upload an image as an > avatar. It would be nice to have the email so that I can associate the > avatar with that email. How can I do this? Thank you. One approach would be to assign a unique identifier to the email address, then include that identifier as a parameter in the link that allows for image uploading: http://your.site.tld/avatar/upload/ (for eg) Then the upload process can get the ID from the path and identify the email address with which the image is associated. From shearichard at gmail.com Sun Dec 5 22:40:47 2010 From: shearichard at gmail.com (shearichard) Date: Sun, 5 Dec 2010 19:40:47 -0800 (PST) Subject: PEP8 compliance and exception messages ? Message-ID: <63cab97f-4e46-4c30-83ce-dc531a900d40@u25g2000pra.googlegroups.com> Hi - PEP8 says lines should not exceed 79 characters in length ( http://www.python.org/dev/peps/pep-0008/ ). So if you've got some code that looks like this : raise fooMod.fooException("Some message which is quite long") ... and assuming a certain amount of indenting you're going to break that guideline. However there's a way around that ! You can do this ... raise fooMod.fooException("\ Some message \ which is quite long") ... but the trouble is when that Exception is raised the message is displayed as : "Some message which is quite long" I'm aware that a foolish consistency is the hobgoblin of something or the other so maybe I should just let the PEP8 verifier complain but otherwise does anyone have any ideas for how to get around this ? Thanks richard From clp2 at rebertia.com Sun Dec 5 22:52:54 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 5 Dec 2010 19:52:54 -0800 Subject: PEP8 compliance and exception messages ? In-Reply-To: <63cab97f-4e46-4c30-83ce-dc531a900d40@u25g2000pra.googlegroups.com> References: <63cab97f-4e46-4c30-83ce-dc531a900d40@u25g2000pra.googlegroups.com> Message-ID: On Sun, Dec 5, 2010 at 7:40 PM, shearichard wrote: > Hi - PEP8 says lines should not exceed 79 characters in length > ( http://www.python.org/dev/peps/pep-0008/ ). > > So if you've got some code that looks like this : > > raise fooMod.fooException("Some message which is quite long") > > ... and assuming a certain amount of indenting you're going to break > that guideline. > > However there's a way around that ! You can do this ... > > raise fooMod.fooException("\ > ? ? ? ?Some message \ > ? ? ? ?which is quite long") > > ... but the trouble is when that Exception is raised the message is > displayed as : > > "Some message ? ? ? ? ? ? ? ? ? ? which is quite long" > > > I'm aware that a foolish consistency is the hobgoblin of something or > the other so maybe I should just let the PEP8 verifier complain but > otherwise does anyone have any ideas for how to get around this ? Use implicit string literal concatenation: raise fooMod.fooException( "Some message " "which is quite long") #) # you could also put the closing paren here instead Alternatively, you could disregard PEP 8 on this point on the grounds that the 79/80 characters per line limit is outdated. Cheers, Chris -- http://blog.rebertia.com From python at mrabarnett.plus.com Sun Dec 5 22:54:51 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 06 Dec 2010 03:54:51 +0000 Subject: PEP8 compliance and exception messages ? In-Reply-To: <63cab97f-4e46-4c30-83ce-dc531a900d40@u25g2000pra.googlegroups.com> References: <63cab97f-4e46-4c30-83ce-dc531a900d40@u25g2000pra.googlegroups.com> Message-ID: <4CFC5E8B.5080200@mrabarnett.plus.com> On 06/12/2010 03:40, shearichard wrote: > Hi - PEP8 says lines should not exceed 79 characters in length > ( http://www.python.org/dev/peps/pep-0008/ ). > > So if you've got some code that looks like this : > > raise fooMod.fooException("Some message which is quite long") > > ... and assuming a certain amount of indenting you're going to break > that guideline. > > However there's a way around that ! You can do this ... > > raise fooMod.fooException("\ > Some message \ > which is quite long") > > ... but the trouble is when that Exception is raised the message is > displayed as : > > "Some message which is quite long" > > > I'm aware that a foolish consistency is the hobgoblin of something or > the other so maybe I should just let the PEP8 verifier complain but > otherwise does anyone have any ideas for how to get around this ? > You can use implied string concatenation: >>> "abc" "def" 'abcdef' so: raise fooMod.fooException( "Some message " "which is quite long") From python at mrabarnett.plus.com Sun Dec 5 23:08:16 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 06 Dec 2010 04:08:16 +0000 Subject: Wanted: slow regexes Message-ID: <4CFC61B0.8000109@mrabarnett.plus.com> I'm looking for examples of regexes which are slow (especially those which seem never to finish) but whose results are known. I already have those reported in the bug tracker, but further ones will be welcome. This is for testing additional modifications to the new regex implementation (available on PyPI). From drsalists at gmail.com Mon Dec 6 00:01:58 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 5 Dec 2010 21:01:58 -0800 Subject: Python 3 encoding question: Read a filename from stdin, subsequently open that filename In-Reply-To: References: Message-ID: Ultimately I switched to reading the filenames from file descriptor 0 using os.read(); this gave back bytes in 3.x, strings of single-byte characters in 2.x - which are similar enough for my purposes, and eliminated the filesystem encoding(s) question nicely. I rewrote readline0 (http://stromberg.dnsalias.org/cgi-bin/viewvc.cgi/readline0/trunk/?root=svn) for 2.x and 3.x to facilitate reading null-terminated strings from stdin. It's in better shape now anyway - more OOP than functional, and with a bunch of unit tests. The module now works on CPython 2.x, CPython 3.x and PyPy 1.4 from the same code. On Mon, Nov 29, 2010 at 9:26 PM, Dan Stromberg wrote: > I've got a couple of programs that read filenames from stdin, and then > open those files and do things with them. ?These programs sort of do > the *ix xargs thing, without requiring xargs. > > In Python 2, these work well. ?Irrespective of how filenames are > encoded, things are opened OK, because it's all just a stream of > single byte characters. > > In Python 3, I'm finding that I have encoding issues with characters > with their high bit set.? Things are fine with strictly ASCII > filenames. ?With high-bit-set characters, even if I change stdin's > encoding with: > > ? ? ? import io > ? ? ? STDIN = io.open(sys.stdin.fileno(), 'r', encoding='ISO-8859-1') > > ...even with that, when I read a filename from stdin with a > single-character Spanish n~, the program cannot open that filename > because the n~ is apparently internally converted to two bytes, but > remains one byte in the filesystem. ?I decided to try ISO-8859-1 with > Python 3, because I have a Java program that encountered a similar > problem until I used en_US.ISO-8859-1 in an environment variable to > set the JVM's encoding for stdin. > > Python 2 shows the n~ as 0xf1 in an os.listdir('.'). ?Python 3 with an > encoding of ISO-8859-1 wants it to be 0xc3 followed by 0xb1. > > Does anyone know what I need to do to read filenames from stdin with > Python 3.1 and subsequently open them, when some of those filenames > include characters with their high bit set? > > TIA! > From ben+python at benfinney.id.au Mon Dec 6 00:21:26 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 06 Dec 2010 16:21:26 +1100 Subject: PEP8 compliance and exception messages ? References: <63cab97f-4e46-4c30-83ce-dc531a900d40@u25g2000pra.googlegroups.com> Message-ID: <87ei9v1nop.fsf@benfinney.id.au> shearichard writes: > Hi - PEP8 says lines should not exceed 79 characters in length > ( http://www.python.org/dev/peps/pep-0008/ ). > > So if you've got some code that looks like this : > > raise fooMod.fooException("Some message which is quite long") PEP 8 also says those names are poorly chosen. Better: raise foomod.FooException("Some message which is quite long") > raise fooMod.fooException("\ > Some message \ > which is quite long") Take advantage of the parsing of string literals and parenthesis: raise foomod.FooException( "Some message" " which is quite long") and for the sake of my eyes, avoid camelCase. From usenot at geekmail.INVALID Mon Dec 6 00:22:49 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Mon, 6 Dec 2010 00:22:49 -0500 Subject: PEP8 compliance and exception messages ? References: <63cab97f-4e46-4c30-83ce-dc531a900d40@u25g2000pra.googlegroups.com> Message-ID: <20101206002249.2d804250@wldmr> On Sun, 5 Dec 2010 19:52:54 -0800 Chris Rebert wrote: > On Sun, Dec 5, 2010 at 7:40 PM, shearichard > wrote: > > Hi - PEP8 says lines should not exceed 79 characters in length > > ( http://www.python.org/dev/peps/pep-0008/ ). > > > > So if you've got some code that looks like this : > > > > raise fooMod.fooException("Some message which is quite long") > > > > ... and assuming a certain amount of indenting you're going to break > > that guideline. > > > > [etc.] > > Use implicit string literal concatenation: > > [...] > But isn't explicit string literal concatenation better than implicit string literal concatenation? ... sorry ... On a more serious note: > Alternatively, you could disregard PEP 8 on this point on the grounds > that the 79/80 characters per line limit is outdated. > Maybe, but it's not outmoded. /W -- To reach me via email, replace INVALID with the country code of my home country. But if you spam me, I'll be one sour Kraut. From usernet at ilthio.net Mon Dec 6 01:15:06 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 6 Dec 2010 06:15:06 +0000 (UTC) Subject: PEP8 compliance and exception messages ? References: <63cab97f-4e46-4c30-83ce-dc531a900d40@u25g2000pra.googlegroups.com> <20101206002249.2d804250@wldmr> Message-ID: On 2010-12-06, Andreas Waldenburger wrote: > On Sun, 5 Dec 2010 19:52:54 -0800 Chris Rebert wrote: > >> On Sun, Dec 5, 2010 at 7:40 PM, shearichard >> wrote: >> > Hi - PEP8 says lines should not exceed 79 characters in length >> > ( http://www.python.org/dev/peps/pep-0008/ ). >> > >> > So if you've got some code that looks like this : >> > >> > raise fooMod.fooException("Some message which is quite long") >> > >> > ... and assuming a certain amount of indenting you're going to break >> > that guideline. >> > >> > [etc.] >> >> Use implicit string literal concatenation: >> >> [...] >> > But isn't explicit string literal concatenation better than implicit > string literal concatenation? So add the "+", it really doesn't change it much. >> Alternatively, you could disregard PEP 8 on this point on the grounds >> that the 79/80 characters per line limit is outdated. >> > Maybe, but it's not outmoded. I would say that it is not even outdated. Just because you happen to enjoy longer lines doesn't mean that everybody does. Not all progammers have 20/10 vision and even those who have hardware to handled it don't necessarily like having a single piece of code take up their entire display just to be readable. Many of us like the extra ability that wider screen technology gives us to actually be able to view more of the file at once by splitting the display into a couple of columns. From steve+comp.lang.python at pearwood.info Mon Dec 6 01:52:53 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Dec 2010 06:52:53 GMT Subject: PEP8 compliance and exception messages ? References: <63cab97f-4e46-4c30-83ce-dc531a900d40@u25g2000pra.googlegroups.com> <20101206002249.2d804250@wldmr> Message-ID: <4cfc8845$0$29998$c3e8da3$5496439d@news.astraweb.com> On Mon, 06 Dec 2010 06:15:06 +0000, Tim Harig wrote: >> But isn't explicit string literal concatenation better than implicit >> string literal concatenation? > > So add the "+", it really doesn't change it much. Perhaps not *much*, but it *may* change it a bit. Implicit concatenation of literals is promised to be handled by the compiler, at compile time: >>> from dis import dis >>> dis(compile("s = 'hello' 'world'", "", "single")) 1 0 LOAD_CONST 0 ('helloworld') 3 STORE_NAME 0 (s) 6 LOAD_CONST 1 (None) 9 RETURN_VALUE This holds all the way back to Python 1.5 and probably older. But explicit concatenation may occur at run-time, depending on the implementation and the presence or absence of a keyhole optimizer. E.g. in Python 2.4: >>> dis(compile("s = 'hello' + 'world'", "", "single")) 1 0 LOAD_CONST 0 ('hello') 3 LOAD_CONST 1 ('world') 6 BINARY_ADD 7 STORE_NAME 0 (s) 10 LOAD_CONST 2 (None) 13 RETURN_VALUE A small difference, but a real one. -- Steven From steve at holdenweb.com Mon Dec 6 01:58:29 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 06 Dec 2010 07:58:29 +0100 Subject: class attribute confusion In-Reply-To: <4cf97626$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <4cf97626$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 12/3/2010 11:58 PM, Steven D'Aprano wrote: > Right. If you define a *class* attribute, it lives in the class, not the > instance, and so all instances share the same value. Unless, of course, an instance binds the same name in its namespace, in which case it will (usually) mask the class attribute for that instance. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Mon Dec 6 02:17:55 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 06 Dec 2010 08:17:55 +0100 Subject: Which non SQL Database ? In-Reply-To: <1ae2b7eb-0ccc-420e-8e62-92aafebd827e@p38g2000vbn.googlegroups.com> References: <87d3phcfaw.fsf@gmail.com> <1ae2b7eb-0ccc-420e-8e62-92aafebd827e@p38g2000vbn.googlegroups.com> Message-ID: On 12/5/2010 12:59 AM, CM wrote: > SQlite itself is around 300 kilobytes. That's negligible. It is also > already in Python, so you'd have to purposefully exclude it in > creating your executable to save those 300 kb and thus the 1/13th of a > second additional time it would take average (3.9 MB/s) users to > download your app if it were included. Just as a matter of interest where do you get the information that the average user has a 3.9 MB/s path to the Internet? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From no.email at nospam.invalid Mon Dec 6 03:14:11 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 06 Dec 2010 00:14:11 -0800 Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <7x39qbfhd8.fsf@ruckus.brouhaha.com> mdw at distorted.org.uk (Mark Wooding) writes: > The most obvious improvement is resumable exceptions. You know, I've heard the story from language designers several times over, that they tried putting resumable exceptions into their languages and it turned out to be a big mess, so they went to termination exceptions that fixed the issue. Are there any languages out there with resumable exceptions? Escaping to a debugger doesn't really count as that. I guess one way to do it would be call a coroutine to handle the exception, and either continue or unwind after the continue returns, but doing it in a single-threaded system just seems full of hazards. From steve at holdenweb.com Mon Dec 6 03:40:53 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 06 Dec 2010 09:40:53 +0100 Subject: Comparison with False - something I don't understand In-Reply-To: <7x39qbfhd8.fsf@ruckus.brouhaha.com> References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> <7x39qbfhd8.fsf@ruckus.brouhaha.com> Message-ID: <4CFCA195.4020003@holdenweb.com> On 12/6/2010 9:14 AM, Paul Rubin wrote: > mdw at distorted.org.uk (Mark Wooding) writes: >> The most obvious improvement is resumable exceptions. > > You know, I've heard the story from language designers several times > over, that they tried putting resumable exceptions into their languages > and it turned out to be a big mess, so they went to termination > exceptions that fixed the issue. Are there any languages out there with > resumable exceptions? Escaping to a debugger doesn't really count as > that. I guess one way to do it would be call a coroutine to handle the > exception, and either continue or unwind after the continue returns, but > doing it in a single-threaded system just seems full of hazards. I seem to remember PL/1 has resumable exceptions, but I don't ever remember finding a real use for them. And it's so long since I used PL/1 I may be mistaken. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From drygalski at googlemail.com Mon Dec 6 04:07:11 2010 From: drygalski at googlemail.com (drygal) Date: Mon, 6 Dec 2010 01:07:11 -0800 (PST) Subject: Which non SQL Database ? References: Message-ID: <8015839c-9400-4ccd-ae5d-db34f68dbee4@22g2000prx.googlegroups.com> On Dec 4, 10:42?pm, Jorge Biquez wrote: > Hello all. > > Newbie question. Sorry. > > As part of my process to learn python I am working on two personal > applications. Both will do it fine with a simple structure of data > stored in files. I now there are lot of databases around I can use > but I would like to know yoor advice on what other options you would > consider for the job (it is training so no pressure on performance). > One application will run as a desktop one,under Windows, Linux, > Macintosh, being able to update data, not much, not complex, not many > records. The second application, running behind ?web pages, will do > the same, I mean, process simple data, updating showing data. not > much info, not complex. As an excersice it is more than enough I > guess and will let me learn what I need for now. > Talking with a friend about what he will do (he use C only) he > suggest to take a look on dBase format file since it is a stable > format, fast and the index structure will be fine or maybe go with BD > (Berkley) database file format (I hope I understood this one > correctly) . Plain files it is not an option since I would like to > have option to do rapid searches. > > What would do you suggest to take a look? If possible available under > the 3 plattforms. > > Thanks in advance for your comments. > > Jorge Biquez Pickle dictionary object perhaps? http://docs.python.org/library/pickle.html From stef.mientki at gmail.com Mon Dec 6 04:40:48 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Mon, 06 Dec 2010 10:40:48 +0100 Subject: is it possible to see if a class has a decorator ? Message-ID: <4CFCAFA0.1090906@gmail.com> hello, I would like to know if a class definition has a decorator, is that possible ? And if so, is it possible to determine the name of these decorator(s) ? thanks, Stef Mientki From ben+python at benfinney.id.au Mon Dec 6 06:08:33 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 06 Dec 2010 22:08:33 +1100 Subject: is it possible to see if a class has a decorator ? References: Message-ID: <87aakj17m6.fsf@benfinney.id.au> Stef Mientki writes: > I would like to know if a class definition has a decorator, I'm not sure what this question means. Applying a decorator to a class definition produces a normal class. Classes don't ?have? decorators; classes can be returned by a decorator function, but AFAIK the resulting class doesn't ?have? the decorator in any sense. > is that possible ? The return value of a decorator isn't special in any way, AFAIK. Any function can return a class object or a function object, and any function can be used as a decorator. The only thing that makes a function a decorator is how it is used in the code; but it doesn't leave a trace that I know of. Now, what is it you're trying to do? Perhaps there's a better solution we can come up with. -- \ ?Pinky, are you pondering what I'm pondering?? ?I think so, | `\ Brain, but there's still a bug stuck in here from last time.? | _o__) ?_Pinky and The Brain_ | Ben Finney From stef.mientki at gmail.com Mon Dec 6 06:29:32 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Mon, 06 Dec 2010 12:29:32 +0100 Subject: is it possible to see if a class has a decorator ? In-Reply-To: <87aakj17m6.fsf@benfinney.id.au> References: <87aakj17m6.fsf@benfinney.id.au> Message-ID: <4CFCC91C.3060102@gmail.com> On 06-12-2010 12:08, Ben Finney wrote: > Stef Mientki writes: > >> I would like to know if a class definition has a decorator, > I'm not sure what this question means. > > Applying a decorator to a class definition produces a normal class. > > Classes don't ?have? decorators; classes can be returned by a decorator > function, but AFAIK the resulting class doesn't ?have? the decorator in > any sense. > >> is that possible ? > The return value of a decorator isn't special in any way, AFAIK. > > Any function can return a class object or a function object, and any > function can be used as a decorator. > > The only thing that makes a function a decorator is how it is used in > the code; but it doesn't leave a trace that I know of. > > Now, what is it you're trying to do? Perhaps there's a better solution > we can come up with. > Thanks Ben, here some more explanation. I've a number of (dynamic) applications, launched from a central wrapper. All these modules have a class "Start", which launches the application and embeds them in the wrapper application. Module 1: class Start (): .... Module 2: @auth class Start (): ... When the wrapper application is started, it looks for all dynamic modules (without importing them), and list these application in a hierarchical tree. In the above axmple, I would like to know that the class "Start" in Module 2 has the decorator "Auth", *without importing the module*, (so depending on the user logged in, I can decide to add or not add the module to the hierarchical tree). thanks, Stef Mientki -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Mon Dec 6 06:32:50 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Dec 2010 11:32:50 GMT Subject: is it possible to see if a class has a decorator ? References: <87aakj17m6.fsf@benfinney.id.au> Message-ID: <4cfcc9e2$0$29997$c3e8da3$5496439d@news.astraweb.com> On Mon, 06 Dec 2010 22:08:33 +1100, Ben Finney wrote: > Stef Mientki writes: > >> I would like to know if a class definition has a decorator, > > I'm not sure what this question means. > > Applying a decorator to a class definition produces a normal class. > > Classes don't ?have? decorators; classes can be returned by a decorator > function, but AFAIK the resulting class doesn't ?have? the decorator in > any sense. It seems to me that a class decorator is (usually) like a class factory, in that it returns a class; the difference being that it takes a pre- existing class as argument, and (probably) modifies it in place, rather than creates a new class from scratch. I say "usually" and "probably" because, of course, a class decorator can do *anything*. Even something pointless: >>> def decorator(cls): ... return 1 ... >>> @decorator ... class K: ... pass ... >>> K 1 >> is that possible ? > > The return value of a decorator isn't special in any way, AFAIK. > > Any function can return a class object or a function object, and any > function can be used as a decorator. [pedant] Any callable can be a decorator, provided it has an appropriate calling signature. But you knew that :) [/pedant] > The only thing that makes a function a decorator is how it is used in > the code; but it doesn't leave a trace that I know of. Function decorators can, because they usually wrap the input function in a closure, which is detectable: >>> def decorator(func): ... def inner(): ... return func("spam") ... return inner ... >>> >>> @decorator ... def ham(s): ... return s.upper() ... >>> ham.__closure__ (,) >>> >>> def cheese(s): # no decorator ... return s.upper() ... >>> cheese.__closure__ >>> But this is only a common practice, not a guarantee, because the decorating function can do anything. I think that the only way to find out what was used to decorate a class, or a function, is for the decorator itself to leave some sort of mark on the wrapped class/function. Perhaps by adding itself to the wrapped object as an attribute: def decorate(cls): cls._decorated_by = decorate -- Steven From lie.1296 at gmail.com Mon Dec 6 06:42:31 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 06 Dec 2010 22:42:31 +1100 Subject: Comparison with False - something I don't understand In-Reply-To: References: <877hfs2zia.fsf@benfinney.id.au> <4CFA6F16.2060001@holdenweb.com> <4cfaf1ff$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cfccb7e$1@dnews.tpgi.com.au> On 12/05/10 15:52, Tim Harig wrote: > On 2010-12-05, Tim Harig wrote: >> Another, questionable but useful use, is to ignore the complex accounting >> of your position inside of a complex data structure. You can continue >> moving through the structure until an exception is raised indicating >> that you have reached a boundary of the structure. > > Here is another example in this vein. I had another example where using Exception as a control structure proves to be the most elegant solution. The problem was a logic puzzle solver (e.g. for Sudoku, Einstein's Logic problem, etc). The algorithm used is recursive backtracking solver (yes, I know there are more efficient constraint-based solver, but that's besides the point). The function modifies the `puzzle` list in-place such that after the call `puzzle` list will contain the solution to the puzzle (if any exists). The solving "in-place" is important since this solver thread runs in a "solver thread" and there is another "drawing thread" that draws the currently tested board asynchronously. This means we do not make a copy of the game board. No locking is done, since it is fine for the drawing thread to draw malformed board, and we do not want to compromise the solver's thread's speed. The two versions of using return value and exception: def solve_return(puzzle, index): """ return True when puzzle is solved, return False when backtracking or when no solution exists """ # recursion base case if all cells are filled and puzzle does not violate game rules: return True # solution found if puzzle violates game rules: return False # backtrack if puzzle[index] is unfilled: for i in possible_candidates(puzzle, index): puzzle[index] = i if solve(puzzle, index+1): # solution already found, unwinding the stack return True # all candidates failed, backtrack puzzle[r][c] = unfilled return False else: # the current cell is part of the base clue return solve(puzzle, index+1) # skip it def main_return(): puzzle = [...] if solve_return(puzzle, 0): print('solution found') else: print('no solution found') def solve_raise(puzzle, index): """ no return value throws SolutionFound when solution is found """ # recursion base case if all cells are filled and puzzle does not violate game rules: raise SolutionFound if puzzle[index] is unfilled: for i in possible_candidates(puzzle, index): puzzle[index] = i if puzzle does not violate game rules: solve(puzzle, index+1) # all candidates failed, backtrack puzzle[r][c] = unfilled else: # the current cell is part of the base clue solve(puzzle, index+1) # skip it def main_raise(): puzzle = [...] try: solve_raise(puzzle, 0) except SolutionFound: print('solution found') else: print('no solution found') Personally, I've found the logic in the exception version clearer than the return version. Also, the exception version is easier to extend, if I wanted to add a smarter algorithm that can deterministically infer certain cell's value (this creates indirect recursion, solve() may call either infer() or solve() which may call either infer() or solve()), it can work beside the existing mechanism without explicitly handling the return flag when a solution is found. If we suppose that end-of-line (e.g. the semicolon, in C-like language) is a single-step forward control structure, the if-statement is a n-step forward control structure, and looping is a n-step backward control structure. Now, if we suppose function call as a single-step downward control structure, and function return as a single-step upward control structure, then exception is a n-step upward control structure. It throws control upwards of the function call stack, while doing cleanup along its way up. From lnenov at mm-sol.com Mon Dec 6 07:36:41 2010 From: lnenov at mm-sol.com (lnenov) Date: Mon, 06 Dec 2010 14:36:41 +0200 Subject: simple threading.Thread and Semaphores hang Message-ID: <4CFCD8D9.4000805@mm-sol.com> Hi, My application hangs on exit. I have isoleted this piece of code that reproduces the error: (the time module is extra and not needed to reproduce) import threading import time def func(): b = threading.Semaphore(value=0) b.acquire() a = threading.Thread(target=func) a.start() time.sleep(2) quit() When SystemExit is raised, nothing happens. Python hangs. pdb does seem to have problem with this code too: pdb smth.py ... (Pdb) Traceback (most recent call last): File "/usr/bin/pdb", line 1319, in pdb.main() File "/usr/lib/python2.6/pdb.py", line 1312, in main pdb.interaction(None, t) File "/usr/lib/python2.6/pdb.py", line 198, in interaction self.cmdloop() File "/usr/lib/python2.6/cmd.py", line 130, in cmdloop line = raw_input(self.prompt) ValueError: I/O operation on closed file Any help would be appreciated, Lyudmil From python.list at tim.thechases.com Mon Dec 6 07:53:46 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 06 Dec 2010 06:53:46 -0600 Subject: Wanted: slow regexes In-Reply-To: <4CFC61B0.8000109@mrabarnett.plus.com> References: <4CFC61B0.8000109@mrabarnett.plus.com> Message-ID: <4CFCDCDA.1030400@tim.thechases.com> On 12/05/2010 10:08 PM, MRAB wrote: > I'm looking for examples of regexes which are slow (especially those > which seem never to finish) but whose results are known. I already have > those reported in the bug tracker, but further ones will be welcome. > > This is for testing additional modifications to the new regex > implementation (available on PyPI). There was a DOS security issue in Django about a year back (fixed the day it came to light in changeset 11603), triggered by a regexp with a lot of back-tracking: http://code.djangoproject.com/changeset/11603 which tried to match email_re = re.compile( r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*" # dot-atom r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*"' # quoted-string r')@(?:[A-Z0-9]+(?:-*[A-Z0-9]+)*\.)+[A-Z]{2,6}$', re.IGNORECASE) # domain against 'viewx3dtextx26qx3d at yahoo.comx26latlngx3d15854521645943074058' (should return None rather than a MatchObject). Folks were reporting that it was taking >20min to run. -tkc From alain at dpt-info.u-strasbg.fr Mon Dec 6 08:15:04 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Mon, 06 Dec 2010 14:15:04 +0100 Subject: simple threading.Thread and Semaphores hang References: Message-ID: <87bp4zt547.fsf@dpt-info.u-strasbg.fr> lnenov writes: > My application hangs on exit. > I have isoleted this piece of code that reproduces the error: (the > time module is extra and not needed to reproduce) > > import threading > import time > > def func(): > b = threading.Semaphore(value=0) > b.acquire() This waits for the semaphore to have a positive value. This thread is blocked (apparently forever, since no other thread has access to the semaphore). > a = threading.Thread(target=func) > a.start() > > time.sleep(2) > quit() > > When SystemExit is raised, nothing happens. Python hangs. Your blocked thread is still around, still waiting for the semaphore. Your program won't exit while there are non-daemon threads alive. -- Alain. From mwilson at the-wire.com Mon Dec 6 08:32:18 2010 From: mwilson at the-wire.com (Mel) Date: Mon, 06 Dec 2010 08:32:18 -0500 Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> <7x39qbfhd8.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > mdw at distorted.org.uk (Mark Wooding) writes: >> The most obvious improvement is resumable exceptions. > > You know, I've heard the story from language designers several times > over, that they tried putting resumable exceptions into their languages > and it turned out to be a big mess, so they went to termination > exceptions that fixed the issue. Are there any languages out there with > resumable exceptions? Escaping to a debugger doesn't really count as > that. I guess one way to do it would be call a coroutine to handle the > exception, and either continue or unwind after the continue returns, but > doing it in a single-threaded system just seems full of hazards. Apparently, at the end of his research, Alan Turing was trying out the idea of 'oracles', where a computable process would have access to an uncomputable process to get particular results. I would imagine that the idea here was to clarify what this would do to the computable process. If he had lived, I doubt that Turing would have built an oracle, but the idea does live on in interactive debuggers. It would seem if some situation has arisen that can be fixed by code, then you can just run that code there and then. Then 'resumable exceptions' just become a kind of subroutine call, perhaps like the triggers in SQL. Mel. From jeanmichel at sequans.com Mon Dec 6 09:39:10 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 06 Dec 2010 15:39:10 +0100 Subject: [ANN] Pyclewn: Vim as a front end to pdb In-Reply-To: References: Message-ID: <4CFCF58E.9070603@sequans.com> Xavier de Gaye wrote: > Pyclewn 1.5 has been released at http://pyclewn.sourceforge.net/ > > Pyclewn is a python program that allows the use of Vim as a front end > to gdb and pdb. > > This release adds support for ``pdb``, the python debugger. > > + A python script may be run under the control of ``pdb``. For > example the current vim buffer may be started and debugged with > the vim command ``:Pyclewn pdb %:p`` > > + One may also attach to a running python process, interrupt the > process, manage a debugging session and terminate the debugging > session by detaching from the process. A new debugging session may > be conducted later on this same process, possibly from another Vim > instance. > > + All the ``pdb`` commands are supported except ``list`` and > ``commands``. This includes alias expansion and executing a > python statement in the context of the current frame. The new > command ``threadstack`` prints the instantaneous backtrace of all > the threads, including those that are stuck in a deadlock. > > * Pdb is currently supported on unix platforms and requires the latest > Vim version: Vim 7.3. Python3 is not supported yet. > > The installation fails miserabily if the environment var EDITOR is set to something different than vim (or empty). (I had it set to 'jed'). I had a quick look and I'm not sured it's mentioned anywhere in the help files. By the way I had a quick look at this frontend, it's pretty neat. JM From dan at catfolks.net Mon Dec 6 10:03:48 2010 From: dan at catfolks.net (Dan M) Date: Mon, 06 Dec 2010 09:03:48 -0600 Subject: Newbie needs regex help Message-ID: I'm getting bogged down with backslash escaping. I have some text files containing characters with the 8th bit set. These characters are encoded one of two ways: either "=hh" or "\xhh", where "h" represents a hex digit, and "\x" is a literal backslash followed by a lower-case x. Catching the first case with a regex is simple. But when I try to write a regex to catch the second case, I mess up the escaping. I took at look at http://docs.python.org/howto/regex.html, especially the section titled "The Backslash Plague". I started out trying : dan at dan:~/personal/usenet$ python Python 2.7 (r27:82500, Nov 15 2010, 12:10:23) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import re >>> r = re.compile('\\\\x([0-9a-fA-F]{2})') >>> a = "This \xef file \xef has \x20 a bunch \xa0 of \xb0 crap \xc0 characters \xefn \xeft." >>> m = r.search(a) >>> m No match. I then followed the advice of the above-mentioned document, and expressed the regex as a raw string: >>> r = re.compile(r'\\x([0-9a-fA-F]{2})') >>> r.search(a) Still no match. I'm obviously missing something. I spent a fair bit of time playing with this over the weekend, and I got nowhere. Now it's time to ask for help. What am I doing wrong here? From jeanmichel at sequans.com Mon Dec 6 10:04:24 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 06 Dec 2010 16:04:24 +0100 Subject: is it possible to see if a class has a decorator ? In-Reply-To: <4CFCC91C.3060102@gmail.com> References: <87aakj17m6.fsf@benfinney.id.au> <4CFCC91C.3060102@gmail.com> Message-ID: <4CFCFB78.1020200@sequans.com> Stef Mientki wrote: > On 06-12-2010 12:08, Ben Finney wrote: >> Stef Mientki writes: >> >> >>> I would like to know if a class definition has a decorator, >>> >> I'm not sure what this question means. >> >> Applying a decorator to a class definition produces a normal class. >> >> Classes don't ?have? decorators; classes can be returned by a decorator >> function, but AFAIK the resulting class doesn't ?have? the decorator in >> any sense. >> >> >>> is that possible ? >>> >> The return value of a decorator isn't special in any way, AFAIK. >> >> Any function can return a class object or a function object, and any >> function can be used as a decorator. >> >> The only thing that makes a function a decorator is how it is used in >> the code; but it doesn't leave a trace that I know of. >> >> Now, what is it you're trying to do? Perhaps there's a better solution >> we can come up with. >> >> > Thanks Ben, > here some more explanation. > > I've a number of (dynamic) applications, > launched from a central wrapper. > All these modules have a class "Start", which launches the application > and embeds them in the wrapper application. > > Module 1: > class Start (): > .... > > Module 2: > @auth > class Start (): > ... > > When the wrapper application is started, it looks for all dynamic > modules (without importing them), > and list these application in a hierarchical tree. > In the above axmple, > I would like to know that the class "Start" in Module 2 has the > decorator "Auth", *without importing the module*, > (so depending on the user logged in, I can decide to add or not add > the module to the hierarchical tree). > > thanks, > Stef Mientki > > > > You best bet is to parse the source file. JM From reshma.kerla at gmail.com Mon Dec 6 10:09:37 2010 From: reshma.kerla at gmail.com (Raksha R) Date: Mon, 6 Dec 2010 07:09:37 -0800 (PST) Subject: Anushka Hot still More Message-ID: http://dattinggirls.hpage.us/linklist_75279.html From stef.mientki at gmail.com Mon Dec 6 10:21:35 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Mon, 06 Dec 2010 16:21:35 +0100 Subject: is it possible to see if a class has a decorator ? In-Reply-To: <4CFCFB78.1020200@sequans.com> References: <87aakj17m6.fsf@benfinney.id.au> <4CFCC91C.3060102@gmail.com> <4CFCFB78.1020200@sequans.com> Message-ID: <4CFCFF7F.9030208@gmail.com> On 06-12-2010 16:04, Jean-Michel Pichavant wrote: > Stef Mientki wrote: >> On 06-12-2010 12:08, Ben Finney wrote: >>> Stef Mientki writes: >>> >>> >>>> I would like to know if a class definition has a decorator, >>>> >>> I'm not sure what this question means. >>> >>> Applying a decorator to a class definition produces a normal class. >>> >>> Classes don't ?have? decorators; classes can be returned by a decorator >>> function, but AFAIK the resulting class doesn't ?have? the decorator in >>> any sense. >>> >>> >>>> is that possible ? >>>> >>> The return value of a decorator isn't special in any way, AFAIK. >>> >>> Any function can return a class object or a function object, and any >>> function can be used as a decorator. >>> >>> The only thing that makes a function a decorator is how it is used in >>> the code; but it doesn't leave a trace that I know of. >>> >>> Now, what is it you're trying to do? Perhaps there's a better solution >>> we can come up with. >>> >>> >> Thanks Ben, >> here some more explanation. >> >> I've a number of (dynamic) applications, >> launched from a central wrapper. >> All these modules have a class "Start", which launches the application and embeds them in the >> wrapper application. >> >> Module 1: >> class Start (): >> .... >> >> Module 2: >> @auth >> class Start (): >> ... >> >> When the wrapper application is started, it looks for all dynamic modules (without importing them), >> and list these application in a hierarchical tree. >> In the above axmple, >> I would like to know that the class "Start" in Module 2 has the decorator "Auth", *without >> importing the module*, >> (so depending on the user logged in, I can decide to add or not add the module to the >> hierarchical tree). >> >> thanks, >> Stef Mientki >> >> >> >> > You best bet is to parse the source file. thanks, I was afraid of that. cheers, Stef > > JM From mwilson at the-wire.com Mon Dec 6 10:29:41 2010 From: mwilson at the-wire.com (Mel) Date: Mon, 06 Dec 2010 10:29:41 -0500 Subject: Newbie needs regex help References: Message-ID: Dan M wrote: > I'm getting bogged down with backslash escaping. > > I have some text files containing characters with the 8th bit set. These > characters are encoded one of two ways: either "=hh" or "\xhh", where "h" > represents a hex digit, and "\x" is a literal backslash followed by a > lower-case x. > > Catching the first case with a regex is simple. But when I try to write a > regex to catch the second case, I mess up the escaping. > > I took at look at http://docs.python.org/howto/regex.html, especially the > section titled "The Backslash Plague". I started out trying : > > dan at dan:~/personal/usenet$ python > Python 2.7 (r27:82500, Nov 15 2010, 12:10:23) > [GCC 4.3.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import re >>>> r = re.compile('\\\\x([0-9a-fA-F]{2})') >>>> a = "This \xef file \xef has \x20 a bunch \xa0 of \xb0 crap \xc0 > characters \xefn \xeft." >>>> m = r.search(a) >>>> m > > No match. > > I then followed the advice of the above-mentioned document, and expressed > the regex as a raw string: > >>>> r = re.compile(r'\\x([0-9a-fA-F]{2})') >>>> r.search(a) > > Still no match. > > I'm obviously missing something. I spent a fair bit of time playing with > this over the weekend, and I got nowhere. Now it's time to ask for help. > What am I doing wrong here? What you're missing is that string `a` doesn't actually contain four- character sequences like '\', 'x', 'a', 'a' . It contains single characters that you encode in string literals as '\xaa' and so on. You might do better with p1 = r'([\x80-\xff])' r1 = re.compile (p1) m = r1.search (a) I get at least an <_sre.SRE_Match object at 0xb749a6e0> when I try this. Mel. From alain at dpt-info.u-strasbg.fr Mon Dec 6 10:34:56 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Mon, 06 Dec 2010 16:34:56 +0100 Subject: Newbie needs regex help References: Message-ID: <8739qaud7j.fsf@dpt-info.u-strasbg.fr> Dan M writes: > I took at look at http://docs.python.org/howto/regex.html, especially the > section titled "The Backslash Plague". I started out trying : >>>> import re >>>> r = re.compile('\\\\x([0-9a-fA-F]{2})') >>>> a = "This \xef file \xef has \x20 a bunch \xa0 of \xb0 crap \xc0 The backslash trickery applies to string literals also, not only regexps. Your string does not have the value you think it has. Double each backslash (or make your string raw) and you'll get what you expect. -- Alain. From astan.chee at gmail.com Mon Dec 6 10:37:30 2010 From: astan.chee at gmail.com (Astan Chee) Date: Tue, 7 Dec 2010 02:37:30 +1100 Subject: RCX using python serial help Message-ID: Hi, I've got a lego mindstorm RCX 1.0 (but firmware is 2.0) that uses one of those old serial IR towers to control the microcontroller. I've had a look around at python's serial documentation as well as the RCX's documentation and I'm trying to write something to control the RCX directly using python. Several examples from of doing this in python include using lnp (i think) and that doesn't quite run well in windows. I've had a look at the C++ code and some protocol documentation here: http://www.generation5.org/content/2001/rob08.asp and converted it to python. I've attached it at the end of the email. So now I've figured out how to check for the battery level and it seems to work (I've tested it on my RCX) but I'm confused with the other documentation (e.g. http://graphics.stanford.edu/~kekoa/rcx/ ) about how to do this in python or what this all means. I was wondering if anyone can help me complete these? or maybe help me do it step-by-step? Thanks for any help. Below is the python code I've been working on: import time import serial import struct import binascii def tcbin(x, y=8): """ This function returns the padded, two's complement representation of x, in y-bits. It is conventional for y to be 8, 16, 32 or 64, though y can have any non-zero positive value. """ if x >= 0: binstr = bin(x) # pad with leading zeros while len(binstr) < y + 2: binstr = "0b0" + binstr[2:] return binstr return bin((2**y) + x) # x is negative def bitcompliment(hex_code): return hex(int(tcbin(~(ord(hex_code))),2)) def processOutput(raw_data,output): outputStatus = True pos = 0 for i in range(3): if raw_data[i] != output[i]: outputStatus = False pos+=1 if outputStatus: print "output OK" else: print "problem with output" outputCompliment = True while outputCompliment: if hex(ord(output[pos])) == bitcompliment(output[pos+1]): print "output compliment OK" else: print "problem with output compliment" pos+=2 if hex(ord(output[pos])) == '0x55' and hex(ord(output[pos+1])) == '0xff' and hex(ord(output[pos+2])) == '0x0': pos+=3 outputCompliment = False if hex(ord(output[pos])) == '0xcf' or hex(ord(output[pos])) == '0xc7': #battery checker pos+=2 if hex(ord(output[pos])) == bitcompliment(output[pos+1]) and hex(ord(output[pos+2])) == bitcompliment(output[pos+3]): s = ((ord(output[pos+2]) * 256) + ord(output[pos])) / 1000.0 print "Battery is at " + str(s) + " Volts" else: for i in range(len(output[pos:]),len(output),2): print hex(ord(output[i])) if i+1 < len(output): if hex(ord(output[i])) == bitcompliment(output[i+1]): print "message OK. contents: " + hex(ord(output[i])) # configure the serial connections (the parameters differs on the device you are connecting to) ser = serial.Serial( port='COM1', baudrate=2400, parity=serial.PARITY_ODD, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS ) raw_data = '\x55\xff\x00\x38\xc7\x38\xc7' result = ser.write(raw_data) out = '' time.sleep(1) #pause for a second while ser.inWaiting() > 0: out+=ser.read(1) processOutput(raw_data,out) -------------- next part -------------- An HTML attachment was scrubbed... URL: From dan at catfolks.net Mon Dec 6 10:44:39 2010 From: dan at catfolks.net (Dan M) Date: Mon, 06 Dec 2010 09:44:39 -0600 Subject: Newbie needs regex help References: Message-ID: On Mon, 06 Dec 2010 10:29:41 -0500, Mel wrote: > What you're missing is that string `a` doesn't actually contain four- > character sequences like '\', 'x', 'a', 'a' . It contains single > characters that you encode in string literals as '\xaa' and so on. You > might do better with > > p1 = r'([\x80-\xff])' > r1 = re.compile (p1) > m = r1.search (a) > > I get at least an <_sre.SRE_Match object at 0xb749a6e0> when I try this. > > Mel. That's what I had initially assumed was the case, but looking at the data files with a hex editor showed me that I do indeed have four-character sequences. That's what makes this such as interesting task! From phd at phd.pp.ru Mon Dec 6 10:47:14 2010 From: phd at phd.pp.ru (Oleg Broytman) Date: Mon, 6 Dec 2010 18:47:14 +0300 Subject: SQLObject 0.15.0 Message-ID: <20101206154714.GB12211@phd.pp.ru> Hello! I'm pleased to announce version 0.15.0, the first stable release of branch 0.15 of SQLObject. What is SQLObject ================= SQLObject is an object-relational mapper. Your database tables are described as classes, and rows are instances of those classes. SQLObject is meant to be easy to use and quick to get started with. SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite, Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB). Where is SQLObject ================== Site: http://sqlobject.org Development: http://sqlobject.org/devel/ Mailing list: https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss Archives: http://news.gmane.org/gmane.comp.python.sqlobject Download: http://cheeseshop.python.org/pypi/SQLObject/0.15.0 News and changes: http://sqlobject.org/News.html What's New ========== * Major API change: all signals are sent with the instance (or the class) as the first parameter. The following signals were changed: RowCreateSignal, RowCreatedSignal, DeleteColumnSignal. * Major API change: post-processing functions for all signals are called with the instance as the first parameter. The following signals were changed: RowUpdatedSignal, RowDestroySignal, RowDestroyedSignal. For a more complete list, please see the news: http://sqlobject.org/News.html Oleg. -- Oleg Broytman http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From dan at catfolks.net Mon Dec 6 10:48:50 2010 From: dan at catfolks.net (Dan M) Date: Mon, 06 Dec 2010 09:48:50 -0600 Subject: Newbie needs regex help References: <8739qaud7j.fsf@dpt-info.u-strasbg.fr> Message-ID: On Mon, 06 Dec 2010 16:34:56 +0100, Alain Ketterlin wrote: > Dan M writes: > >> I took at look at http://docs.python.org/howto/regex.html, especially >> the section titled "The Backslash Plague". I started out trying : > >>>>> import re >>>>> r = re.compile('\\\\x([0-9a-fA-F]{2})') a = "This \xef file \xef has >>>>> \x20 a bunch \xa0 of \xb0 crap \xc0 > > The backslash trickery applies to string literals also, not only > regexps. > > Your string does not have the value you think it has. Double each > backslash (or make your string raw) and you'll get what you expect. > > -- Alain. D'oh! I hadn't thought of that. If I read my data file in from disk, use the raw string version of the regex, and do the search that way I do indeed get the results I'm looking for. Thanks for pointing that out. I guess I need to think a little deeper into what I'm doing when I escape stuff. From iamforufriends at gmail.com Mon Dec 6 11:25:14 2010 From: iamforufriends at gmail.com (kate for free dating) Date: Mon, 6 Dec 2010 08:25:14 -0800 (PST) Subject: hay... this is kate, we r staying near by u, wanna dating with me... Message-ID: hay... this is kate, we r staying near by u, wanna dating with me... http://x2c.eu/57 http://x2c.eu/57 http://x2c.eu/57 http://x2c.eu/57 From cmpython at gmail.com Mon Dec 6 11:35:39 2010 From: cmpython at gmail.com (CM) Date: Mon, 6 Dec 2010 08:35:39 -0800 (PST) Subject: Which non SQL Database ? References: <87d3phcfaw.fsf@gmail.com> <1ae2b7eb-0ccc-420e-8e62-92aafebd827e@p38g2000vbn.googlegroups.com> Message-ID: <90914734-4fa5-4a2e-8d14-079b87ba3d73@n32g2000pre.googlegroups.com> On Dec 6, 2:17?am, Steve Holden wrote: > On 12/5/2010 12:59 AM, CM wrote: > > > SQlite itself is around 300 kilobytes. ?That's negligible. ?It is also > > already in Python, so you'd have to purposefully exclude it in > > creating your executable to save those 300 kb and thus the 1/13th of a > > second additional time it would take average (3.9 MB/s) users to > > download your app if it were included. > > Just as a matter of interest where do you get the information that the > average user has a 3.9 MB/s path to the Internet? First, I should have specified the average *U.S.* user, and in so doing realized how dumbly "own-nation-centric" that was. My apologies. But I got it from this: http://arstechnica.com/telecom/news/2010/01/us-broadband-still-lagging-in-speed-and-penetration.ars No idea how accurate that is, and I didn't break that into download vs. upload speeds. It puts the U.S. 18th in the world rankings of average connection speed. Also, for what it's worth, I noticed in making an .exe yesterday that sqlite3.dll is listed as 843 kB. That may be because it includes pysqlite as well, I don't know. In any case, that is at least appreciably higher than the 300 kb I listed above, though not too bad. If someone is trying to squeak out every last bit of savings in making their .exe small, then sqlite.dll is something they could consider excluding, if they can. But for most cases, no user will care about the extra size. Che > regards > ?Steve > -- > Steve Holden ? ? ? ? ? +1 571 484 6266 ? +1 800 494 3119 > PyCon 2011 Atlanta March 9-17 ? ? ?http://us.pycon.org/ > See Python Video! ? ? ?http://python.mirocommunity.org/ > Holden Web LLC ? ? ? ? ? ? ? ?http://www.holdenweb.com/ From bigblueswope at gmail.com Mon Dec 6 11:40:21 2010 From: bigblueswope at gmail.com (BJ Swope) Date: Mon, 6 Dec 2010 11:40:21 -0500 Subject: Passing Variable(s) as kwargs Message-ID: Hello All. I am trying to use values, retrieved from a config file, as kwargs and not having any luck. Well at least I think that's what I'm trying to do ;) Any suggestions would be most appreciated. Here's the exception: Traceback (most recent call last): File "c:\dev\LogServerMonitor\LogServerMonitor.py", line 246, in sched.add_cron_job(check_logging_db, minute = '*/run_interval_quantity') File "c:\Python26\lib\site-packages\apscheduler\scheduler.py", line 249, in add_cron_job second) File "c:\Python26\lib\site-packages\apscheduler\triggers.py", line 22, in __init__ self._compile_expressions(minutes, 'minute') File "c:\Python26\lib\site-packages\apscheduler\triggers.py", line 43, in _compile_expressions compiled_expr_list = [compile_single(expr) for expr in expr_list] File "c:\Python26\lib\site-packages\apscheduler\triggers.py", line 36, in compile_single (expr, fieldname)) ValueError: Unrecognized expression "*/run_interval_quantity" for field "minute" An example of what I am doing is: ###################################################################################### Config File Contents: [RunInterval] #How often the application queries the DB to look for the date of #the last entry (Default every 1 Minute). #Valid RunInterval Quantities are integers > 0 RunIntervalQuantity: 1 #Valid RunInterval Types are S=Seconds, M=Minutes, H=Hours, D=Days RunIntervalType: M ############################################################################################## My Code config = ConfigParser.ConfigParser() try: config.readfp(open(config_file)) except: sys.stderr.write('Config file, "%s", is missing or unreadable. Exiting.' % config_file) sys.stderr.write('ERROR: %s\r\n' % str(err)) sys.exit(1) def getOption(section, option): try: opt_value = config.get(section, option) return opt_value except (ConfigParser.NoOptionError), err: sys.stderr.write( "Application requires \"%s\" be defined in the [%s] section of the config file %s\r\n" % (option, section, config_file)) sys.stderr.write('ERROR: %s\r\n' % str(err)) sys.exit(1) def getOptionInt(section, option): try: opt_value = config.getint(section, option) return opt_value except (ValueError, ConfigParser.NoOptionError), err: sys.stderr.write("Application requires \"%s\" be defined as an Integer in the \"[%s]\" section of the config file %s" % (option, section, config_file)) sys.stderr.write('ERROR: %s\r\n' % str(err)) sys.exit(1) # Start the scheduler sched = Scheduler() sched.start() run_interval_quantity = getOptionInt('RunInterval', 'RunIntervalQuantity') run_interval_type = getOption('RunInterval', 'RunIntervalType') if run_interval_type in ['S', 's']: sched.add_cron_job(check_logging_db, second = '*/run_interval_quantity') elif run_interval_type in ['M', 'm']: sched.add_cron_job(check_logging_db, minute = '*/run_interval_quantity') elif run_interval_type in ['H', 'h']: sched.add_cron_job(check_logging_db, hour = '*/run_interval_quantity') elif run_interval_type in ['D', 'd']: sched.add_cron_job(check_logging_db, day = '*/run_interval_quantity') else: my_logger.warning('The value of RunIntervalType in the configuration file section RunInterval was not one of "S, M, H or D". Running LogServerMonitor application once per minute by default.') sched.add_cron_job(check_logging_db, minute = '*') -------------- next part -------------- An HTML attachment was scrubbed... URL: From tomf.sessile at gmail.com Mon Dec 6 11:59:12 2010 From: tomf.sessile at gmail.com (TomF) Date: Mon, 6 Dec 2010 08:59:12 -0800 Subject: Comparisons of incompatible types Message-ID: <2010120608591221344-tomfsessile@gmailcom> I'm aggravated by this behavior in python: x = "4" print x < 7 # prints False The issue, of course, is comparisons of incompatible types. In most languages this throws an error (in Perl the types are converted silently). In Python this comparison fails silently. The documentation says: "objects of different types *always* compare unequal, and are ordered consistently but arbitrarily." I can't imagine why this design decision was made. I've been bitten by this several times (reading data from a file and not converting the numbers before comparison). Can I get this to throw an error instead of failing silently? Thanks, -Tom From dan at catfolks.net Mon Dec 6 12:02:11 2010 From: dan at catfolks.net (Dan M) Date: Mon, 06 Dec 2010 11:02:11 -0600 Subject: Newbie needs regex help References: Message-ID: On Mon, 06 Dec 2010 09:44:39 -0600, Dan M wrote: > That's what I had initially assumed was the case, but looking at the > data files with a hex editor showed me that I do indeed have > four-character sequences. That's what makes this such as interesting > task! Sorry, I misunderstood the first time I read your reply. You're right, the string I showed did indeed contain single-byte characters, not four-character sequences. The data file I work with, though, does contain four-character sequences. From __peter__ at web.de Mon Dec 6 12:04:00 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 06 Dec 2010 18:04 +0100 Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> Message-ID: TomF wrote: > I'm aggravated by this behavior in python: > > x = "4" > print x < 7 # prints False > > The issue, of course, is comparisons of incompatible types. In most > languages this throws an error (in Perl the types are converted > silently). In Python this comparison fails silently. The > documentation says: "objects of different types *always* compare > unequal, and are ordered consistently but arbitrarily." > > I can't imagine why this design decision was made. I've been bitten by > this several times (reading data from a file and not converting the > numbers before comparison). Can I get this to throw an error instead > of failing silently? This change would break a lot of code, so it could not be made within the 2.x series. However: Python 3.1.1+ (r311:74480, Nov 2 2009, 15:45:00) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> "4" < 7 Traceback (most recent call last): File "", line 1, in TypeError: unorderable types: str() < int() Peter From mail at timgolden.me.uk Mon Dec 6 12:04:39 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 06 Dec 2010 17:04:39 +0000 Subject: Comparisons of incompatible types In-Reply-To: <2010120608591221344-tomfsessile@gmailcom> References: <2010120608591221344-tomfsessile@gmailcom> Message-ID: <4CFD17A7.2010805@timgolden.me.uk> On 06/12/2010 16:59, TomF wrote: > I'm aggravated by this behavior in python: > > x = "4" > print x < 7 # prints False > > The issue, of course, is comparisons of incompatible types. In most > languages this throws an error (in Perl the types are converted > silently). In Python this comparison fails silently. The documentation > says: "objects of different types *always* compare unequal, and are > ordered consistently but arbitrarily." > > I can't imagine why this design decision was made. I've been bitten by > this several times (reading data from a file and not converting the > numbers before comparison). Can I get this to throw an error instead of > failing silently? Yes: switch to python 3 where this does throw an exception: Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52 Type "help", "copyright", "credits" or "license >>> 7 < "eight" Traceback (most recent call last): File "", line 1, in TypeError: unorderable types: int() < str() >>> TJG From python at mrabarnett.plus.com Mon Dec 6 12:11:30 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 06 Dec 2010 17:11:30 +0000 Subject: Which non SQL Database ? In-Reply-To: <90914734-4fa5-4a2e-8d14-079b87ba3d73@n32g2000pre.googlegroups.com> References: <87d3phcfaw.fsf@gmail.com> <1ae2b7eb-0ccc-420e-8e62-92aafebd827e@p38g2000vbn.googlegroups.com> <90914734-4fa5-4a2e-8d14-079b87ba3d73@n32g2000pre.googlegroups.com> Message-ID: <4CFD1942.7060102@mrabarnett.plus.com> On 06/12/2010 16:35, CM wrote: > On Dec 6, 2:17 am, Steve Holden wrote: >> On 12/5/2010 12:59 AM, CM wrote: >> >>> SQlite itself is around 300 kilobytes. That's negligible. It is also >>> already in Python, so you'd have to purposefully exclude it in >>> creating your executable to save those 300 kb and thus the 1/13th of a >>> second additional time it would take average (3.9 MB/s) users to >>> download your app if it were included. >> >> Just as a matter of interest where do you get the information that the >> average user has a 3.9 MB/s path to the Internet? > > First, I should have specified the average *U.S.* user, and in so > doing realized how dumbly "own-nation-centric" that was. My > apologies. But I got it from this: > http://arstechnica.com/telecom/news/2010/01/us-broadband-still-lagging-in-speed-and-penetration.ars > [snip] You're also confusing MB/s (bytes) with Mb/s (bits). From __peter__ at web.de Mon Dec 6 12:12:33 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 06 Dec 2010 18:12:33 +0100 Subject: Newbie needs regex help References: Message-ID: Dan M wrote: > I'm getting bogged down with backslash escaping. > > I have some text files containing characters with the 8th bit set. These > characters are encoded one of two ways: either "=hh" or "\xhh", where "h" > represents a hex digit, and "\x" is a literal backslash followed by a > lower-case x. By the way: >>> print quopri.decodestring("=E4=F6=FC").decode("iso-8859-1") ??? >>> print r"\xe4\xf6\xfc".decode("string-escape").decode("iso-8859-1") ??? From tomf.sessile at gmail.com Mon Dec 6 12:16:10 2010 From: tomf.sessile at gmail.com (TomF) Date: Mon, 6 Dec 2010 09:16:10 -0800 Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> Message-ID: <2010120609161055524-tomfsessile@gmailcom> On 2010-12-06 09:04:00 -0800, Peter Otten said: > TomF wrote: > >> I'm aggravated by this behavior in python: >> >> x = "4" >> print x < 7 # prints False >> >> The issue, of course, is comparisons of incompatible types. In most >> languages this throws an error (in Perl the types are converted >> silently). In Python this comparison fails silently. The >> documentation says: "objects of different types *always* compare >> unequal, and are ordered consistently but arbitrarily." >> >> I can't imagine why this design decision was made. I've been bitten by >> this several times (reading data from a file and not converting the >> numbers before comparison). Can I get this to throw an error instead >> of failing silently? > > This change would break a lot of code, so it could not be made within the > 2.x series. However: > > Python 3.1.1+ (r311:74480, Nov 2 2009, 15:45:00) > [GCC 4.4.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> "4" < 7 > Traceback (most recent call last): > File "", line 1, in > TypeError: unorderable types: str() < int() Thanks. I was hoping there was something I could do for 2.x but I suppose this will have to do. But I'm mystified by your statement, "this change would break a lot of code". Given that the semantics are virtually random, how could code depend on this? -Tom From python at mrabarnett.plus.com Mon Dec 6 12:23:42 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 06 Dec 2010 17:23:42 +0000 Subject: Passing Variable(s) as kwargs In-Reply-To: References: Message-ID: <4CFD1C1E.8040500@mrabarnett.plus.com> On 06/12/2010 16:40, BJ Swope wrote: > Hello All. > > I am trying to use values, retrieved from a config file, as kwargs and > not having any luck. Well at least I think that's what I'm trying to do ;) > > Any suggestions would be most appreciated. > > Here's the exception: > > Traceback (most recent call last): > File "c:\dev\LogServerMonitor\LogServerMonitor.py", line 246, in > sched.add_cron_job(check_logging_db, minute = > '*/run_interval_quantity') > File "c:\Python26\lib\site-packages\apscheduler\scheduler.py", line > 249, in add_cron_job > second) > File "c:\Python26\lib\site-packages\apscheduler\triggers.py", line > 22, in __init__ > self._compile_expressions(minutes, 'minute') > File "c:\Python26\lib\site-packages\apscheduler\triggers.py", line > 43, in _compile_expressions > compiled_expr_list = [compile_single(expr) for expr in expr_list] > File "c:\Python26\lib\site-packages\apscheduler\triggers.py", line > 36, in compile_single > (expr, fieldname)) > ValueError: Unrecognized expression "*/run_interval_quantity" for field > "minute" > > > > An example of what I am doing is: > ###################################################################################### > Config File Contents: > [RunInterval] > #How often the application queries the DB to look for the date of > #the last entry (Default every 1 Minute). > > #Valid RunInterval Quantities are integers > 0 > RunIntervalQuantity: 1 > > #Valid RunInterval Types are S=Seconds, M=Minutes, H=Hours, D=Days > RunIntervalType: M > > ############################################################################################## > > My Code > > > config = ConfigParser.ConfigParser() > try: > config.readfp(open(config_file)) > except: > sys.stderr.write('Config file, "%s", is missing or unreadable. > Exiting.' % config_file) > sys.stderr.write('ERROR: %s\r\n' % str(err)) > sys.exit(1) > > > def getOption(section, option): > try: > opt_value = config.get(section, option) > return opt_value > except (ConfigParser.NoOptionError), err: > sys.stderr.write( "Application requires \"%s\" be defined in > the [%s] section of the config file %s\r\n" % (option, section, > config_file)) > sys.stderr.write('ERROR: %s\r\n' % str(err)) > sys.exit(1) > > def getOptionInt(section, option): > try: > opt_value = config.getint(section, option) > return opt_value > except (ValueError, ConfigParser.NoOptionError), err: > sys.stderr.write("Application requires \"%s\" be defined as an > Integer in the \"[%s]\" section of the config file %s" % (option, > section, config_file)) > sys.stderr.write('ERROR: %s\r\n' % str(err)) > sys.exit(1) > > > > # Start the scheduler > sched = Scheduler() > sched.start() > run_interval_quantity = getOptionInt('RunInterval', 'RunIntervalQuantity') > run_interval_type = getOption('RunInterval', 'RunIntervalType') > > if run_interval_type in ['S', 's']: > sched.add_cron_job(check_logging_db, second = > '*/run_interval_quantity') > elif run_interval_type in ['M', 'm']: > sched.add_cron_job(check_logging_db, minute = > '*/run_interval_quantity') > elif run_interval_type in ['H', 'h']: > sched.add_cron_job(check_logging_db, hour = '*/run_interval_quantity') > elif run_interval_type in ['D', 'd']: > sched.add_cron_job(check_logging_db, day = '*/run_interval_quantity') > else: > my_logger.warning('The value of RunIntervalType in the > configuration file section RunInterval was not one of "S, M, H or D". > Running LogServerMonitor application once per minute by default.') > sched.add_cron_job(check_logging_db, minute = '*') > It's complaining that the 'minute' argument which you're passing to 'add_cron_job' is '*/run_interval_quantity', which the scheduler doesn't understand. From davea at ieee.org Mon Dec 6 12:39:23 2010 From: davea at ieee.org (Dave Angel) Date: Mon, 06 Dec 2010 12:39:23 -0500 Subject: Which non SQL Database ? In-Reply-To: <90914734-4fa5-4a2e-8d14-079b87ba3d73@n32g2000pre.googlegroups.com> References: <87d3phcfaw.fsf@gmail.com> <1ae2b7eb-0ccc-420e-8e62-92aafebd827e@p38g2000vbn.googlegroups.com> <90914734-4fa5-4a2e-8d14-079b87ba3d73@n32g2000pre.googlegroups.com> Message-ID: <4CFD1FCB.40009@ieee.org> On 01/-10/-28163 02:59 PM, CM wrote: > On Dec 6, 2:17 am, Steve Holden wrote: >> Just as a matter of interest where do you get the information that the >> average user has a 3.9 MB/s path to the Internet? > > First, I should have specified the average *U.S.* user, and in so > doing realized how dumbly "own-nation-centric" that was. My > apologies. But I got it from this: > http://arstechnica.com/telecom/news/2010/01/us-broadband-still-lagging-in-speed-and-penetration.ars > You're confusing megabits with megabytes. The article says the average in the US is 3.9Mb/s, which is only 0.41MB/s. Still seems high to me, but I have no statistics. DaveA From robert.kern at gmail.com Mon Dec 6 12:46:21 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 06 Dec 2010 11:46:21 -0600 Subject: Comparisons of incompatible types In-Reply-To: <2010120609161055524-tomfsessile@gmailcom> References: <2010120608591221344-tomfsessile@gmailcom> <2010120609161055524-tomfsessile@gmailcom> Message-ID: On 12/6/10 11:16 AM, TomF wrote: > > On 2010-12-06 09:04:00 -0800, Peter Otten said: >> This change would break a lot of code, so it could not be made within the >> 2.x series. However: >> >> Python 3.1.1+ (r311:74480, Nov 2 2009, 15:45:00) >> [GCC 4.4.1] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >>>>> "4" < 7 >> Traceback (most recent call last): >> File "", line 1, in >> TypeError: unorderable types: str() < int() > > Thanks. I was hoping there was something I could do for 2.x but I suppose this > will have to do. > > But I'm mystified by your statement, "this change would break a lot of code". > Given that the semantics are virtually random, how could code depend on this? There are cases where you don't particularly care *what* order is given as long as it is consistent. Let's say you want to make sure that two lists have the same contents (which may mix types), but you don't care about the order. You could just sort each list and then compare the sorted lists. Before sets were added to the language, this was a fairly common approach. -- 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 bigblueswope at gmail.com Mon Dec 6 12:47:27 2010 From: bigblueswope at gmail.com (BJ Swope) Date: Mon, 6 Dec 2010 12:47:27 -0500 Subject: Passing Variable(s) as kwargs In-Reply-To: <4CFD1C1E.8040500@mrabarnett.plus.com> References: <4CFD1C1E.8040500@mrabarnett.plus.com> Message-ID: > > It's complaining that the 'minute' argument which you're passing to > 'add_cron_job' is '*/run_interval_quantity', which the scheduler > doesn't understand. > -- > Hey, what do you know, there's a forest amongst all those trees... key_words = '*/%d' % (run_interval_quantity) sched.add_cron_job(check_logging_db, minute = key_words) Works! -------------- next part -------------- An HTML attachment was scrubbed... URL: From dan at catfolks.net Mon Dec 6 12:58:05 2010 From: dan at catfolks.net (Dan M) Date: Mon, 06 Dec 2010 11:58:05 -0600 Subject: Newbie needs regex help References: Message-ID: On Mon, 06 Dec 2010 18:12:33 +0100, Peter Otten wrote: > By the way: > >>>> print quopri.decodestring("=E4=F6=FC").decode("iso-8859-1") > ??? >>>> print r"\xe4\xf6\xfc".decode("string-escape").decode("iso-8859-1") > ??? Ah - better than a regex. Thanks! From cmpython at gmail.com Mon Dec 6 13:46:26 2010 From: cmpython at gmail.com (CM) Date: Mon, 6 Dec 2010 10:46:26 -0800 (PST) Subject: Which non SQL Database ? References: <87d3phcfaw.fsf@gmail.com> <1ae2b7eb-0ccc-420e-8e62-92aafebd827e@p38g2000vbn.googlegroups.com> <90914734-4fa5-4a2e-8d14-079b87ba3d73@n32g2000pre.googlegroups.com> Message-ID: <9531285a-ae41-4149-b8ef-969aee5d19a4@n32g2000pre.googlegroups.com> > You're also confusing MB/s (bytes) with Mb/s (bits). Yes I am. I think I will now recuse myself from the proceedings... From nagle at animats.com Mon Dec 6 13:50:51 2010 From: nagle at animats.com (John Nagle) Date: Mon, 06 Dec 2010 10:50:51 -0800 Subject: Comparison with False - something I don't understand In-Reply-To: <7xvd3crqqt.fsf@ruckus.brouhaha.com> References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <7xvd3crqqt.fsf@ruckus.brouhaha.com> Message-ID: <4cfd308a$0$1605$742ec2ed@news.sonic.net> On 12/2/2010 10:09 AM, Paul Rubin wrote: > MRAB writes: >> When writing the C code for the new regex module I thought that it >> would've been easier if I could've used exceptions to propagate errors >> and unwind the stack, instead of having to return an error code which >> had to be checked by the caller, and then have the caller explicitly >> return an error code to /its/ caller. > > That's called longjmp. > >> Automatic garbage collection would also have been nice. > > alloca might help. If you want proper exception unwinding, use C++, which has it. "longjmp" is a hack from the PDP-11 era. John Nagle From martin at address-in-sig.invalid Mon Dec 6 13:59:21 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Mon, 6 Dec 2010 18:59:21 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> <7x39qbfhd8.fsf@ruckus.brouhaha.com> Message-ID: On Mon, 06 Dec 2010 09:54:46 -0800, Dennis Lee Bieber wrote: > On Mon, 06 Dec 2010 00:14:11 -0800, Paul Rubin > declaimed the following in gmane.comp.python.general: > > >> exceptions that fixed the issue. Are there any languages out there >> with resumable exceptions? Escaping to a debugger doesn't really count >> as > > Visual BASIC 6 > > -=-=-=-=- > On Error GoTo line > 9999 REM Actions to sort out the error RESUME > Enables the error-handling routine that starts at line > specified in the required line argument. The line argument is any line > label or line number. If a run-time error occurs, control branches to > line, making the error handler active. The specified line must be in the > same procedure as the On Error statement; otherwise, a compile-time > error occurs. > Any BASIC that implements ON ERROR (i.e. just about all of them) will do this, not just VB. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From solipsis at pitrou.net Mon Dec 6 14:00:17 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 6 Dec 2010 20:00:17 +0100 Subject: Perceived inconsistency in py3k documentation References: <724b26b4-8233-4d57-b76f-cd781cf0cd03@z17g2000prz.googlegroups.com> Message-ID: <20101206200017.0c5fc63f@pitrou.net> On Sun, 05 Dec 2010 14:47:38 -0500 Terry Reedy wrote: > On 12/5/2010 3:31 AM, Greg wrote: > > For future reference, > > > 1) At http://docs.python.org/py3k/reference/datamodel.html: > > 2) At http://docs.python.org/py3k/library/stdtypes.html: > > do not work because of the trailing :s, at least not with FireFox. Work fine here. The problem isn't Firefox, it is your e-mail or news client. Antoine. From nagle at animats.com Mon Dec 6 14:23:15 2010 From: nagle at animats.com (John Nagle) Date: Mon, 06 Dec 2010 11:23:15 -0800 Subject: Resumable exceptions bad: (was Re: Comparison with False - something I don't understand) In-Reply-To: References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> <7x39qbfhd8.fsf@ruckus.brouhaha.com> Message-ID: <4cfd3822$0$1629$742ec2ed@news.sonic.net> On 12/6/2010 12:40 AM, Steve Holden wrote: > On 12/6/2010 9:14 AM, Paul Rubin wrote: >> mdw at distorted.org.uk (Mark Wooding) writes: >>> The most obvious improvement is resumable exceptions. >> >> You know, I've heard the story from language designers several times >> over, that they tried putting resumable exceptions into their languages >> and it turned out to be a big mess, so they went to termination >> exceptions that fixed the issue. Are there any languages out there with >> resumable exceptions? Escaping to a debugger doesn't really count as >> that. I guess one way to do it would be call a coroutine to handle the >> exception, and either continue or unwind after the continue returns, but >> doing it in a single-threaded system just seems full of hazards. > > I seem to remember PL/1 has resumable exceptions, but I don't ever > remember finding a real use for them. And it's so long since I used PL/1 > I may be mistaken. Resumable exceptions were a popular idea in the early days of programming. LISP, PL/I, and early COBOL had constructs which could be considered resumable exceptions. They didn't work out well, because the exception handler gets control in an ambiguous situation, perhaps in the middle of an expression. Changing the state of the execution, then returning, can leave the program in an invalid state. Signal handling has many of the same problems. A POSIX signal is a forced subroutine call while something else is going on, which is in itself a weird concept. That's what a resumable exception looks like. CPython has a terrible time with signal handling. See "http://www.dabeaz.com/python/UnderstandingGIL.pdf" for the whole ugly mess. That's why control-C won't terminate multi-thread programs, among other things. Unwinding cleanly from a signal is difficult, but possible with proper CPU and compiler design. It's done right in Ada, and in Visual C++ for x86 on Windows. Only some CPUs support "exact" floating point exceptions, where you're guaranteed that the exception comes in at the point where the problem occurred. In modern superscalar CPUs, the exception comes in several instructions after the problem was detected. In x86 type CPUs, the CPU hardware in the "retirement unit" backs up the CPU state to the point at which the exception was detected. PowerPC and SPARC CPUs do not do this; if you need exactness in exception position on them, you have to put in "fence" instructions to stop lookahead. This costs performance. As a result, C code which unwinds from signals via "longjmp" is not portable. See "https://www.securecoding.cert.org/confluence/display/seccode/SIG32-C.+Do+not+call+longjmp%28%29+from+inside+a+signal+handler" Nor is changing the program state from inside a signal handler. You're not entirely sure, on many CPUs, where control is at the point the signal came in. (In a physics simulator, I once had to handle floating point overflow, which indicated that the computation had to be backed up and rerun with a smaller time step. It's possible to do this safely under Windows on x86 if you read all the appropriate documents. It's not portable. That's why I'm aware of this mess.) So that's why resumable exceptions are a bad idea. John Nagle From tjreedy at udel.edu Mon Dec 6 14:34:42 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 06 Dec 2010 14:34:42 -0500 Subject: Comparisons of incompatible types In-Reply-To: References: <2010120608591221344-tomfsessile@gmailcom> <2010120609161055524-tomfsessile@gmailcom> Message-ID: On 12/6/2010 12:46 PM, Robert Kern wrote: > On 12/6/10 11:16 AM, TomF wrote: >> Given that the semantics are virtually random, how could code depend >> on this? > > There are cases where you don't particularly care *what* order is given > as long as it is consistent. Let's say you want to make sure that two > lists have the same contents (which may mix types), but you don't care > about the order. You could just sort each list and then compare the > sorted lists. Before sets were added to the language, this was a fairly > common approach. And indeed, code like this that has not been updated does break in 3.x. to some people's annoyance. We really really cannot please everyone ;-). -- Terry Jan Reedy From zooko at zooko.com Mon Dec 6 14:50:33 2010 From: zooko at zooko.com (Zooko O'Whielacronx) Date: Mon, 6 Dec 2010 11:50:33 -0800 Subject: announcing pyutil-1.8.0 Message-ID: Folks: pyutil is a collection of modules and functions that we've found useful over the years. Peter Westlake and Ravi Pinjala (who found pyutil through the Tahoe-LAFS project) contributed some documentation about what each module in pyutil does, and SimpleGeo (my employer) is using one small part of pyutil (the jsonutil [1] module) in an upcoming new product, so I packaged up version 1.8.0. The main differences from previous versions are better docs, a very simple declaration of permissive open source licensing [2], and several of the modules have been marked as deprecated. read me: http://tahoe-lafs.org/trac/pyutil/browser/trunk/README.rst download: http://pypi.python.org/pypi/pyutil Regards, Zooko [1] http://tahoe-lafs.org/trac/pyutil/browser/trunk/pyutil/jsonutil.py [2] http://tahoe-lafs.org/trac/pyutil/browser/trunk/COPYING.SPL.txt From usenot at geekmail.INVALID Mon Dec 6 15:17:21 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Mon, 6 Dec 2010 15:17:21 -0500 Subject: PEP8 compliance and exception messages ? References: <63cab97f-4e46-4c30-83ce-dc531a900d40@u25g2000pra.googlegroups.com> <20101206002249.2d804250@wldmr> Message-ID: <20101206151721.4446d722@wldmr> On Mon, 6 Dec 2010 00:22:49 -0500 Andreas Waldenburger wrote: > On Sun, 5 Dec 2010 19:52:54 -0800 Chris Rebert > wrote: > > > On Sun, Dec 5, 2010 at 7:40 PM, shearichard > > wrote: > > > Hi - PEP8 says lines should not exceed 79 characters in length > > > ( http://www.python.org/dev/peps/pep-0008/ ). > > > > > > So if you've got some code that looks like this : > > > > > > raise fooMod.fooException("Some message which is quite long") > > > > > > ... and assuming a certain amount of indenting you're going to > > > break that guideline. > > > > > > [etc.] > > > > [...] > > Alternatively, you could disregard PEP 8 on this point on the > > grounds that the 79/80 characters per line limit is outdated. > > > Maybe, but it's not outmoded. > As a more useful (I hope) reply, my opinion in this case is to just make the line a little longer. Even if you can't read it all at once, it is pretty obvious what comes next: The rest of the error message. There is no additional functionality hidden there, and you don't need to see it all at once to grasp the meaning of the code. /W -- To reach me via email, replace INVALID with the country code of my home country. But if you spam me, I'll be one sour Kraut. From nagle at animats.com Mon Dec 6 15:53:47 2010 From: nagle at animats.com (John Nagle) Date: Mon, 06 Dec 2010 12:53:47 -0800 Subject: Exception handling in Python 3.x In-Reply-To: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cfd4d5a$0$1662$742ec2ed@news.sonic.net> On 12/3/2010 5:04 AM, Steven D'Aprano wrote: > Consider the following common exception handling idiom: > > def func(iterable): > it = iter(iterable) > try: > x = next(it) > except StopIteration: > raise ValueError("can't process empty iterable") > print(x) > > The intention is: > > * detect an empty iterator by catching StopIteration; > * if the iterator is empty, raise a ValueError; > * otherwise process the iterator. > > Note that StopIteration is an internal detail of no relevance whatsoever > to the caller. Expose this is unnecessary at best and confusing at worst. Right. You're not entitled to assume that StopIteration is how a generator exits. That's a CPyton thing; generators were a retrofit, and that's how they were hacked in. Other implementations may do generators differently. John Nagle From mdw at distorted.org.uk Mon Dec 6 15:58:13 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Mon, 06 Dec 2010 20:58:13 +0000 Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> <7x39qbfhd8.fsf@ruckus.brouhaha.com> Message-ID: <87lj42liu2.fsf.mdw@metalzone.distorted.org.uk> Paul Rubin writes: > You know, I've heard the story from language designers several times > over, that they tried putting resumable exceptions into their languages > and it turned out to be a big mess, so they went to termination > exceptions that fixed the issue. That seems very surprising to me. > Are there any languages out there with resumable exceptions? Common Lisp and Smalltalk spring to mind. It's fairly straightforward to write one in Scheme. (Actually, implementing the Common Lisp one in terms of fluids, closures and blocks isn't especially difficult.) > Escaping to a debugger doesn't really count as that. Indeed not. > I guess one way to do it would be call a coroutine to handle the > exception, and either continue or unwind after the continue returns, > but doing it in a single-threaded system just seems full of hazards. It seems pretty straightforward to me. Handlers are simply closures; the registered handlers are part of the prevailing dynamic context. When an exception occurs, you invoke the handlers, most-recently registered first. A handler that returns normally can be thought of as `declining' to handle the exception; a handler that explicitly transfers control elsewhere can be thought of as having handled it. To make this work, all you need is: * a fluid list (i.e., one which is part of the dynamic context) of handlers, which you can build in pure Python if you try hard enough (see below); * closures to represent handlers, which Python has already, and; * a nonlocal transfer mechanism, and a mechanism like try ... finally to allow functions to clean up if they're unwound. We can actually come up with a nonlocal transfer if we try, by abusing exceptions. [The code in this article is lightly tested, but probably contains stupid bugs. Be careful.] class block (object): """ Context manager for escapable blocks. Write with block() as escape: ... Invoking the `escape' function causes the context body to exit immediately. Invoking the `escape' function outside of the block's dynamic context raises a ValueError. """ def __init__(me): me._tag = None def _escape(me, value = None): if me._tag is None: raise ValueError, 'defunct block' me.result = value raise me._tag def __enter__(me, value = None): if me._tag: raise ValueError, 'block already active' me._tag = type('block tag', (BaseException,), {}) me.result = value return me._escape def __exit__(me, ty, val, tb): tag, me._tag = me._tag, None return ty is tag This is somewhat brittle, since some intervening context might capture the custom exception we're using, but I don't think we can do significantly better. Implementing fluids badly is easy. Effectively what we'd do to bind a fluid dynamically is try: old, fluid = fluid, new ... finally: fluid = old but this is visible in other threads. The following will do the job in a multithreaded environment. import threading as T import weakref as W class FluidBinding (object): """Context object for fluid bindings.""" def __init__(me, fluid, value): me.fluid = fluid me.value = value def __enter__(me): me.fluid._bind(me.value) def __exit__(me, ty, val, tb): me.fluid._unbind() class Fluid (object): """ Represents a fluid variable, i.e., one whose binding respects the dynamic context rather than the lexical context. Read and write the Fluid through the `value' property. The global value is shared by all threads. To dynamically bind the fluid, use the context manager `binding': with myfluid.binding(NEWVALUE): ... The binding is visible in functions called MAP within the context body, but not in other threads. """ _TLS = T.local() _UNBOUND = ['fluid unbound'] _OMIT = ['fluid omitted'] def __init__(me, value = _UNBOUND): """ Iinitialze a fluid, optionally setting the global value. """ me._value = value @property def value(me): """ Return the current value of the fluid. Raises AttributeError if the fluid is currently unbound. """ try: value, _ = me._TLS.map[me] except (AttributeError, KeyError): value = me._value if value == me._UNBOUND: raise AttributeError, 'unbound fluid' return value @value.setter def value(me, value): try: map = me._TLS.map _, stack = map[me] map[me] = value, stack except (AttributeError, KeyError): me._value = value @value.deleter def value(me): me.value = me._UNBOUND def binding(me, value = _OMIT, unbound = False): """ Bind the fluid dynamically. If UNBOUND is true then make the fluid be `unbound', i.e., not associated with a value. Otherwise, if VALUE is unset, then preserve the current value. Otherwise, set it to VALUE. The fluid can be modified and deleted. This will not affect the value outside of the dynamic extent of the context (e.g., in other threads, or when the context is unwound). """ if unbound: value = me._UNBOUND elif value == me._OMIT: value = me.value return _FluidBinding(me, value) def _bind(me, value): try: map = me._TLS.map except AttributeError: me._TLS.map = map = W.WeakKeyDictionary() try: old, stack = map[me] stack.append(old) map[me] = value, stack except KeyError: map[me] = value, [] def _unbind(me): map = me._TLS.map _, stack = map[me] if stack: map[me] = stack.pop(), stack else: del map[me] Now we can say with fluid.binding(new): ... and all is well. So, how do we piece all of this together to make a resumable exception system? We're going to need to keep a list of handlers. We're going to be adding and removing stuff a lot; and we want to make use of the fluid mechanism we've already built, which will restore old values automatically when we leave a dynamic context. So maintaining a linked list seems like a good idea. The nodes in the list will look somewhat like this. class Link (object): def __init__(me, item, next): me.item = item me.next = next Our handlers are going to be simple functions which take exception objects as arguments. A more advanced handler might filter exceptions based on their classes. That's not especially difficult to do badly, but it's fiddly to do well and it doesn't shed much light on the overall mechanism, so I'll omit that complication. We'll want a fluid for the handler list. HANDLERS = Fluid(None) Now we want to run a chunk of code with a handler attached. This seems like another good use for a context manager. class handler (object): def __init__(me, func): me._func = func def __enter__(me): me._bind = FluidBinding(HANDLERS, Link(me.func, HANDLERS.value) me._bind.__enter__() def __exit__(me, ty, val, tb): return me._bind.__exit__(ty, val, tb) (Context managers don't compose very nicely. It'd be prettier with the contextmanager decorator.) Let's say that we `signal' resumable exceptions rather than `raising' them. How do we do that? def signal(exc): with HANDLERS.binding(): while HANDLERS.value: h = HANDLERS.value HANDLERS.value = h.next h.item(exc) Yes, if all of the handlers decline, we just return. This is Bad for errors, but good for other kinds of situations, so `signal' is a convenient substrate to build on. def error(exc): signal(exc) raise RuntimeError, 'unhandled resumable exception' def warning(exc): signal(exc) ## Crank up python's usual warning stuff Note also that handlers are invoked in a dynamic environment which doesn't include them or any handlers added since. Obviously they can install their own handlers just fine. Cool. Now how about recovery? This is where nonlocal transfer comes in. If a handler wants to take responsibility for the exception, it has to make a nonlocal transfer. Where should it go? Let's maintain a table of restart points. Again, it'll be a linked list. RESTARTS = Fluid(None) class restart (block): def __init__(me, name): me.name = name super(restart, me).__init__(me) def invoke(me, value = None): me._escape(value) def __enter__(me): me._bind = FluidBinding(RESTARTS, Link(me, RESTARTS.value)) me._bind.__enter__() return super(restart, me).__enter__() def __exit__(me, ty, val, tb): ## Poor man's PROG1. try: return super(restart, me).__exit__(ty, val, tb) finally: me._bind.__exit__(ty, val, tb) def find_restart(name): r = RESTARTS.value while r: if r.item.name == name: return r.item r = r.next return None Using all of this is rather cumbersome, and Python doesn't allow syntactic abstraction so there isn't really much we can do to sweeten the pill. But I ought to provide an example of this machinery in action. def toy(x, y): r = restart('use-value') with r: if y == 0: error(ZeroDivisionError()) r.result = x/y return r.result def example(): def zd(exc): if not isinstance(exc, ZeroDivisionError): return r = find_restart('use-value') if not r: return r.invoke(42) print toy(5, 2) with handler(zd): print toy(1, 0) Does any of that help? -- [mdw] From no.email at nospam.invalid Mon Dec 6 16:13:40 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 06 Dec 2010 13:13:40 -0800 Subject: Exception handling in Python 3.x References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7xmxoi8v0b.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > Apart from this horrible idiom: > > def func(iterable): > it = iter(iterable) > failed = False > try: > x = next(it) > except StopIteration: > failed = True > if failed: > raise ValueError("can't process empty iterable") > print(x) > > > or similar, is there really no way to avoid these chained exceptions? Seems like yet another example of people doing messy things with exceptions that can easily be done with iterators and itertools: from itertools import islice def func(iterable): xs = list(islice(iter(iterable), 1)) if len(xs) == 0: raise ValueError(...) print xs[0] It's really unfortunate, though, that Python 3 didn't offer a way to peek at the next element of an iterable and test emptiness directly. From mdw at distorted.org.uk Mon Dec 6 16:23:06 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Mon, 06 Dec 2010 21:23:06 +0000 Subject: Resumable exceptions bad: References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> <7x39qbfhd8.fsf@ruckus.brouhaha.com> <4cfd3822$0$1629$742ec2ed@news.sonic.net> Message-ID: <87hbeqlhol.fsf.mdw@metalzone.distorted.org.uk> John Nagle writes: > Resumable exceptions were a popular idea in the early days of > programming. LISP, PL/I, and early COBOL had constructs which could > be considered resumable exceptions. They didn't work out well, > because the exception handler gets control in an ambiguous situation, > perhaps in the middle of an expression. Changing the state of the > execution, then returning, can leave the program in an invalid state. Right, but that's not the important really important trick. The important bit is separating out the `how should I fix this?' logic from the point where execution should resume. There's no good reason why the former should have to come from a dynamic context smaller than the latter: it's just an unnecessary conflation. [Snip stuff about signals. I agree that Unix signals are a disaster.] > So that's why resumable exceptions are a bad idea. That's why a primitive resumable exception system, used naively, is a bad idea. Now look at the good ones. -- [mdw] From mdw at distorted.org.uk Mon Dec 6 16:31:09 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Mon, 06 Dec 2010 21:31:09 +0000 Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> <2010120609161055524-tomfsessile@gmailcom> Message-ID: <87d3pelhb6.fsf.mdw@metalzone.distorted.org.uk> Terry Reedy writes: > And indeed, code like this that has not been updated does break in > 3.x. to some people's annoyance. We really really cannot please > everyone ;-). The problem is that there are too many useful properties that one might expect from comparison operators. For example, it's frequently nice to have a total ordering on all objects. For real numbers, it's nice that the ordering obey the usual ordered-field axioms; but the complex numbers don't have an ordering compatible with the field operators, and imposing a default ordering (e.g., degree-lexicographic) is probably asking for trouble. I agree that the Python 3 behaviour is an improvement, by the way. -- [mdw] From georg at python.org Mon Dec 6 16:46:48 2010 From: georg at python.org (Georg Brandl) Date: Mon, 06 Dec 2010 22:46:48 +0100 Subject: [RELEASED] Python 3.2 beta 1 Message-ID: <4CFD59C8.4070006@python.org> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On behalf of the Python development team, I'm happy to announce the first of two beta preview releases of Python 3.2. Python 3.2 is a continuation of the efforts to improve and stabilize the Python 3.x line. Since the final release of Python 2.7, the 2.x line will only receive bugfixes, and new features are developed for 3.x only. Since PEP 3003, the Moratorium on Language Changes, is in effect, there are no changes in Python's syntax and built-in types in Python 3.2. Development efforts concentrated on the standard library and support for porting code to Python 3. Highlights are: * numerous improvements to the unittest module * PEP 3147, support for .pyc repository directories * PEP 3149, support for version tagged dynamic libraries * PEP 3148, a new futures library for concurrent programming * PEP 384, a stable ABI for extension modules * PEP 391, dictionary-based logging configuration * an overhauled GIL implementation that reduces contention * an extended email package that handles bytes messages * countless fixes regarding bytes/string issues; among them full support for a bytes environment (filenames, environment variables) * many consistency and behavior fixes for numeric operations * a sysconfig module to access configuration information * a pure-Python implementation of the datetime module * additions to the shutil module, among them archive file support * improvements to pdb, the Python debugger For a more extensive list of changes in 3.2, see http://docs.python.org/3.2/whatsnew/3.2.html To download Python 3.2 visit: http://www.python.org/download/releases/3.2/ Please consider trying Python 3.2 with your code and reporting any bugs you may notice to: http://bugs.python.org/ Enjoy! - -- Georg Brandl, Release Manager georg at python.org (on behalf of the entire python-dev team and 3.2's contributors) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.16 (GNU/Linux) iEYEARECAAYFAkz9WcgACgkQN9GcIYhpnLBRYwCeMmH1GMmKOx9fVk8a/F0/TOzj Vp0AoIHYBNcxV/U0AXIwMGWFHi1bAB+a =KBam -----END PGP SIGNATURE----- From mdw at distorted.org.uk Mon Dec 6 17:24:10 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Mon, 06 Dec 2010 22:24:10 +0000 Subject: Exception handling in Python 3.x References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> <4cfd4d5a$0$1662$742ec2ed@news.sonic.net> Message-ID: <878w02leut.fsf.mdw@metalzone.distorted.org.uk> John Nagle writes: > Right. You're not entitled to assume that StopIteration is how a > generator exits. That's a CPyton thing; generators were a retrofit, > and that's how they were hacked in. Other implementations may do > generators differently. This is simply wrong. The StopIteration exception is a clear part of the generator protocol as described in 5.2.8 of the language reference; the language reference also refers to 3.5 of the library reference, which describes the iterator protocol (note, not the generator implementation -- all iterators work the same way), and explicitly mentions StopIteration as part of the protocol. -- [mdw] From chris at simplistix.co.uk Mon Dec 6 17:38:48 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 06 Dec 2010 22:38:48 +0000 Subject: TDD in python In-Reply-To: References: <0906c010-709d-41d9-8b29-2f42afb87f94@32g2000yqz.googlegroups.com> <58fe3680-21f5-42f8-9341-e069cbb88975@r19g2000prm.googlegroups.com> Message-ID: <4CFD65F8.7020908@simplistix.co.uk> On 30/11/2010 13:33, Roy Smith wrote: > In article > <58fe3680-21f5-42f8-9341-e069cbb88975 at r19g2000prm.googlegroups.com>, > rustom wrote: > >> Looking around I found this: >> http://bytes.com/topic/python/answers/43330-unittest-vs-py-test >> where Raymond Hettinger no less says quite unequivocally that he >> prefers test.py to builtin unittest >> because it is not so heavy-weight >> >> Is this the general consensus nowadays among pythonistas? >> [Note I tend to agree but Ive no experience so asking] > > Both frameworks have their fans; I doubt you'll find any consensus. > > Pick one, learn it, and use it. What's important is that you write > tests, write lots of tests, and write good tests. Which framework you > use is a detail. For a great mailing lists that covers all of these types of issues, see here: http://lists.idyll.org/listinfo/testing-in-python cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From pavlovevidence at gmail.com Mon Dec 6 17:42:15 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 6 Dec 2010 14:42:15 -0800 (PST) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> <7x39qbfhd8.fsf@ruckus.brouhaha.com> <87lj42liu2.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <7491b308-0e41-416b-84e9-1ed5ff3408be@n32g2000pre.googlegroups.com> On Dec 6, 12:58?pm, m... at distorted.org.uk (Mark Wooding) wrote: > Paul Rubin writes: > > You know, I've heard the story from language designers several times > > over, that they tried putting resumable exceptions into their languages > > and it turned out to be a big mess, so they went to termination > > exceptions that fixed the issue. > > That seems very surprising to me. > > > Are there any languages out there with resumable exceptions? > > Common Lisp and Smalltalk spring to mind. ?It's fairly straightforward > to write one in Scheme. ?(Actually, implementing the Common Lisp one in > terms of fluids, closures and blocks isn't especially difficult.) > > > Escaping to a debugger doesn't really count as that. > > Indeed not. > > > I guess one way to do it would be call a coroutine to handle the > > exception, and either continue or unwind after the continue returns, > > but doing it in a single-threaded system just seems full of hazards. > > It seems pretty straightforward to me. ?Handlers are simply closures; > the registered handlers are part of the prevailing dynamic context. > When an exception occurs, you invoke the handlers, most-recently > registered first. ?A handler that returns normally can be thought of as > `declining' to handle the exception; a handler that explicitly transfers > control elsewhere can be thought of as having handled it. > > To make this work, all you need is: > > ? * a fluid list (i.e., one which is part of the dynamic context) of > ? ? handlers, which you can build in pure Python if you try hard enough > ? ? (see below); > > ? * closures to represent handlers, which Python has already, and; > > ? * a nonlocal transfer mechanism, and a mechanism like try ... finally > ? ? to allow functions to clean up if they're unwound. > > We can actually come up with a nonlocal transfer if we try, by abusing > exceptions. > > [The code in this article is lightly tested, but probably contains > stupid bugs. ?Be careful.] > > ? ? ? ? class block (object): > ? ? ? ? ? """ > ? ? ? ? ? Context manager for escapable blocks. > > ? ? ? ? ? Write > > ? ? ? ? ? ? ? ? with block() as escape: > ? ? ? ? ? ? ? ? ? ... > > ? ? ? ? ? Invoking the `escape' function causes the context body to exit > ? ? ? ? ? immediately. ?Invoking the `escape' function outside of the > ? ? ? ? ? block's dynamic context raises a ValueError. > ? ? ? ? ? """ > ? ? ? ? ? def __init__(me): > ? ? ? ? ? ? me._tag = None > ? ? ? ? ? def _escape(me, value = None): > ? ? ? ? ? ? if me._tag is None: > ? ? ? ? ? ? ? raise ValueError, 'defunct block' > ? ? ? ? ? ? me.result = value > ? ? ? ? ? ? raise me._tag > ? ? ? ? ? def __enter__(me, value = None): > ? ? ? ? ? ? if me._tag: > ? ? ? ? ? ? ? raise ValueError, 'block already active' > ? ? ? ? ? ? me._tag = type('block tag', (BaseException,), {}) > ? ? ? ? ? ? me.result = value > ? ? ? ? ? ? return me._escape > ? ? ? ? ? def __exit__(me, ty, val, tb): > ? ? ? ? ? ? tag, me._tag = me._tag, None > ? ? ? ? ? ? return ty is tag > > This is somewhat brittle, since some intervening context might capture > the custom exception we're using, but I don't think we can do > significantly better. > > Implementing fluids badly is easy. ?Effectively what we'd do to bind a > fluid dynamically is > > ? ? ? ? try: > ? ? ? ? ? old, fluid = fluid, new > ? ? ? ? ? ... > ? ? ? ? finally: > ? ? ? ? ? fluid = old > > but this is visible in other threads. ?The following will do the job in > a multithreaded environment. > > ? ? ? ? import threading as T > ? ? ? ? import weakref as W > > ? ? ? ? class FluidBinding (object): > ? ? ? ? ? """Context object for fluid bindings.""" > ? ? ? ? ? def __init__(me, fluid, value): > ? ? ? ? ? ? me.fluid = fluid > ? ? ? ? ? ? me.value = value > ? ? ? ? ? def __enter__(me): > ? ? ? ? ? ? me.fluid._bind(me.value) > ? ? ? ? ? def __exit__(me, ty, val, tb): > ? ? ? ? ? ? me.fluid._unbind() > > ? ? ? ? class Fluid (object): > ? ? ? ? ? """ > ? ? ? ? ? Represents a fluid variable, i.e., one whose binding respects > ? ? ? ? ? the dynamic context rather than the lexical context. > > ? ? ? ? ? Read and write the Fluid through the `value' property. > > ? ? ? ? ? The global value is shared by all threads. ?To dynamically > ? ? ? ? ? bind the fluid, use the context manager `binding': > > ? ? ? ? ? ? ? ? ? with myfluid.binding(NEWVALUE): > ? ? ? ? ? ? ? ? ? ? ... > > ? ? ? ? ? The binding is visible in functions called MAP within the > ? ? ? ? ? context body, but not in other threads. > ? ? ? ? ? """ > > ? ? ? ? ? _TLS = T.local() > ? ? ? ? ? _UNBOUND = ['fluid unbound'] > ? ? ? ? ? _OMIT = ['fluid omitted'] > > ? ? ? ? ? def __init__(me, value = _UNBOUND): > ? ? ? ? ? ? """ > ? ? ? ? ? ? Iinitialze a fluid, optionally setting the global value. > ? ? ? ? ? ? """ > ? ? ? ? ? ? me._value = value > > ? ? ? ? ? @property > ? ? ? ? ? def value(me): > ? ? ? ? ? ? """ > ? ? ? ? ? ? Return the current value of the fluid. > > ? ? ? ? ? ? Raises AttributeError if the fluid is currently unbound. > ? ? ? ? ? ? """ > ? ? ? ? ? ? try: > ? ? ? ? ? ? ? value, _ = me._TLS.map[me] > ? ? ? ? ? ? except (AttributeError, KeyError): > ? ? ? ? ? ? ? value = me._value > ? ? ? ? ? ? if value == me._UNBOUND: > ? ? ? ? ? ? ? raise AttributeError, 'unbound fluid' > ? ? ? ? ? ? return value > ? ? ? ? ? @value.setter > ? ? ? ? ? def value(me, value): > ? ? ? ? ? ? try: > ? ? ? ? ? ? ? map = me._TLS.map > ? ? ? ? ? ? ? _, stack = map[me] > ? ? ? ? ? ? ? map[me] = value, stack > ? ? ? ? ? ? except (AttributeError, KeyError): > ? ? ? ? ? ? ? me._value = value > ? ? ? ? ? @value.deleter > ? ? ? ? ? def value(me): > ? ? ? ? ? ? me.value = me._UNBOUND > > ? ? ? ? ? def binding(me, value = _OMIT, unbound = False): > ? ? ? ? ? ? """ > ? ? ? ? ? ? Bind the fluid dynamically. > > ? ? ? ? ? ? If UNBOUND is true then make the fluid be `unbound', i.e., > ? ? ? ? ? ? not associated with a value. ?Otherwise, if VALUE is unset, > ? ? ? ? ? ? then preserve the current value. ?Otherwise, set it to > ? ? ? ? ? ? VALUE. > > ? ? ? ? ? ? The fluid can be modified and deleted. ?This will not affect > ? ? ? ? ? ? the value outside of the dynamic extent of the context > ? ? ? ? ? ? (e.g., in other threads, or when the context is unwound). > ? ? ? ? ? ? """ > ? ? ? ? ? ? if unbound: > ? ? ? ? ? ? ? value = me._UNBOUND > ? ? ? ? ? ? elif value == me._OMIT: > ? ? ? ? ? ? ? value = me.value > ? ? ? ? ? ? return _FluidBinding(me, value) > > ? ? ? ? ? def _bind(me, value): > ? ? ? ? ? ? try: > ? ? ? ? ? ? ? map = me._TLS.map > ? ? ? ? ? ? except AttributeError: > ? ? ? ? ? ? ? me._TLS.map = map = W.WeakKeyDictionary() > ? ? ? ? ? ? try: > ? ? ? ? ? ? ? old, stack = map[me] > ? ? ? ? ? ? ? stack.append(old) > ? ? ? ? ? ? ? map[me] = value, stack > ? ? ? ? ? ? except KeyError: > ? ? ? ? ? ? ? map[me] = value, [] > > ? ? ? ? ? def _unbind(me): > ? ? ? ? ? ? map = me._TLS.map > ? ? ? ? ? ? _, stack = map[me] > ? ? ? ? ? ? if stack: > ? ? ? ? ? ? ? map[me] = stack.pop(), stack > ? ? ? ? ? ? else: > ? ? ? ? ? ? ? del map[me] > > Now we can say > > ? ? ? ? with fluid.binding(new): > ? ? ? ? ? ... > > and all is well. > > So, how do we piece all of this together to make a resumable exception > system? > > We're going to need to keep a list of handlers. ?We're going to be > adding and removing stuff a lot; and we want to make use of the fluid > mechanism we've already built, which will restore old values > automatically when we leave a dynamic context. ?So maintaining a linked > list seems like a good idea. ?The nodes in the list will look somewhat > like this. > > ? ? ? ? class Link (object): > ? ? ? ? ? def __init__(me, item, next): > ? ? ? ? ? ? me.item = item > ? ? ? ? ? ? me.next = next > > Our handlers are going to be simple functions which take exception > objects as arguments. ?A more advanced handler might filter exceptions > based on their classes. ?That's not especially difficult to do badly, > but it's fiddly to do well and it doesn't shed much light on the overall > mechanism, so I'll omit that complication. > > We'll want a fluid for the handler list. > > ? ? ? ? HANDLERS = Fluid(None) > > Now we want to run a chunk of code with a handler attached. ?This seems > like another good use for a context manager. > > ? ? ? ? class handler (object): > ? ? ? ? ? def __init__(me, func): > ? ? ? ? ? ? me._func = func > ? ? ? ? ? def __enter__(me): > ? ? ? ? ? ? me._bind = FluidBinding(HANDLERS, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Link(me.func, HANDLERS.value) > ? ? ? ? ? ? me._bind.__enter__() > ? ? ? ? ? def __exit__(me, ty, val, tb): > ? ? ? ? ? ? return me._bind.__exit__(ty, val, tb) > > (Context managers don't compose very nicely. ?It'd be prettier with the > contextmanager decorator.) > > Let's say that we `signal' resumable exceptions rather than `raising' > them. ?How do we do that? > > ? ? ? ? def signal(exc): > ? ? ? ? ? with HANDLERS.binding(): > ? ? ? ? ? ? while HANDLERS.value: > ? ? ? ? ? ? ? h = HANDLERS.value > ? ? ? ? ? ? ? HANDLERS.value = h.next > ? ? ? ? ? ? ? h.item(exc) > > Yes, if all of the handlers decline, we just return. ?This is Bad for > errors, but good for other kinds of situations, so `signal' is a > convenient substrate to build on. > > ? ? ? ? def error(exc): > ? ? ? ? ? signal(exc) > ? ? ? ? ? raise RuntimeError, 'unhandled resumable exception' > > ? ? ? ? def warning(exc): > ? ? ? ? ? signal(exc) > ? ? ? ? ? ## Crank up python's usual warning stuff > > Note also that handlers are invoked in a dynamic environment which > doesn't include them or any handlers added since. ?Obviously they can > install their own handlers just fine. > > Cool. ?Now how about recovery? ?This is where nonlocal transfer comes > in. ?If a handler wants to take responsibility for the exception, it has > to make a nonlocal transfer. ?Where should it go? ?Let's maintain a > table of restart points. ?Again, it'll be a linked list. > > ? ? ? ? RESTARTS = Fluid(None) > > ? ? ? ? class restart (block): > ? ? ? ? ? def __init__(me, name): > ? ? ? ? ? ? me.name = name > ? ? ? ? ? ? super(restart, me).__init__(me) > ? ? ? ? ? def invoke(me, value = None): > ? ? ? ? ? ? me._escape(value) > ? ? ? ? ? def __enter__(me): > ? ? ? ? ? ? me._bind = FluidBinding(RESTARTS, Link(me, RESTARTS.value)) > ? ? ? ? ? ? me._bind.__enter__() > ? ? ? ? ? ? return super(restart, me).__enter__() > ? ? ? ? ? def __exit__(me, ty, val, tb): > ? ? ? ? ? ? ## Poor man's PROG1. > ? ? ? ? ? ? try: > ? ? ? ? ? ? ? return super(restart, me).__exit__(ty, val, tb) > ? ? ? ? ? ? finally: > ? ? ? ? ? ? ? me._bind.__exit__(ty, val, tb) > > ? ? ? ? def find_restart(name): > ? ? ? ? ? r = RESTARTS.value > ? ? ? ? ? while r: > ? ? ? ? ? ? if r.item.name == name: > ? ? ? ? ? ? ? return r.item > ? ? ? ? ? ? r = r.next > ? ? ? ? ? return None > > Using all of this is rather cumbersome, and Python doesn't allow > syntactic abstraction so there isn't really much we can do to sweeten > the pill. ?But I ought to provide an example of this machinery in > action. > > ? ? ? ? def toy(x, y): > ? ? ? ? ? r = restart('use-value') > ? ? ? ? ? with r: > ? ? ? ? ? ? if y == 0: > ? ? ? ? ? ? ? error(ZeroDivisionError()) > ? ? ? ? ? ? r.result = x/y > ? ? ? ? ? return r.result > > ? ? ? ? def example(): > ? ? ? ? ? def zd(exc): > ? ? ? ? ? ? if not isinstance(exc, ZeroDivisionError): > ? ? ? ? ? ? ? return > ? ? ? ? ? ? r = find_restart('use-value') > ? ? ? ? ? ? if not r: return > ? ? ? ? ? ? r.invoke(42) > ? ? ? ? ? print toy(5, 2) > ? ? ? ? ? with handler(zd): > ? ? ? ? ? ? print toy(1, 0) > > Does any of that help? You could do that. Or, you could just put your try...finally inside a loop. Carl Banks From pavlovevidence at gmail.com Mon Dec 6 17:43:16 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 6 Dec 2010 14:43:16 -0800 (PST) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> <7x39qbfhd8.fsf@ruckus.brouhaha.com> <87lj42liu2.fsf.mdw@metalzone.distorted.org.uk> <7491b308-0e41-416b-84e9-1ed5ff3408be@n32g2000pre.googlegroups.com> Message-ID: <67307449-5ab0-4368-9268-811b712a1a8d@a28g2000prb.googlegroups.com> On Dec 6, 2:42?pm, Carl Banks wrote: > Or, you could just put your try...finally inside a loop. er, try...except Carl Banks From chris at simplistix.co.uk Mon Dec 6 17:45:09 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 06 Dec 2010 22:45:09 +0000 Subject: Python assignments In-Reply-To: References: Message-ID: <4CFD6775.3060701@simplistix.co.uk> Try here: http://www.python.org/community/jobs/ Chris On 03/12/2010 13:50, Sverker Nilsson wrote: > Dear friends, > > This is Sverker from Sweden. You probably know me better as the guy > who made Guppy/Heapy: http://guppy-pe.sf.net > > I am currently in the process of preparing version 0.1.10 with support > for Python 2.7. I will let you know when it is updated. > > For those who don?t know, I work as a consultant and I am looking for > new assignments and I really wish to work with Heapy/Python instead of > regular programming in eg Java or C++. > > Therefore I was wondering if any of you know any companies in the > States or anywhere else that need my services. > > Further information about who I am and what I can do you can find on > my website: > > http://sncs.se > > I appreciate all advice and information you can provide me with. > > So long my friends, > > Sverker -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From chris at simplistix.co.uk Mon Dec 6 17:48:05 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 06 Dec 2010 22:48:05 +0000 Subject: A web site using Python In-Reply-To: <4CFA4305.10004@it.uu.se> References: <4CFA4305.10004@it.uu.se> Message-ID: <4CFD6825.9020200@simplistix.co.uk> On 04/12/2010 13:32, Virgil Stokes wrote: > *How, armed with Python 2.6 (or 2.7) and all of the Python packages > available, > should I attack the problem of getting this web site up and running on a > Windows > platform?* 1. Pick a web framework, I'd suggest looking at: Django (http://www.djangoproject.com/) Pyramid (http://docs.pylonshq.com/pyramid/dev/) 2. Use it to develop your site. cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From mdw at distorted.org.uk Mon Dec 6 18:03:44 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Mon, 06 Dec 2010 23:03:44 +0000 Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> <7x39qbfhd8.fsf@ruckus.brouhaha.com> <87lj42liu2.fsf.mdw@metalzone.distorted.org.uk> <7491b308-0e41-416b-84e9-1ed5ff3408be@n32g2000pre.googlegroups.com> Message-ID: <874oaqld0v.fsf.mdw@metalzone.distorted.org.uk> Carl Banks writes: > On Dec 6, 12:58?pm, m... at distorted.org.uk (Mark Wooding) wrote: > > ? ? ? ? def toy(x, y): > > ? ? ? ? ? r = restart('use-value') > > ? ? ? ? ? with r: > > ? ? ? ? ? ? if y == 0: > > ? ? ? ? ? ? ? error(ZeroDivisionError()) > > ? ? ? ? ? ? r.result = x/y > > ? ? ? ? ? return r.result > > > > ? ? ? ? def example(): > > ? ? ? ? ? def zd(exc): > > ? ? ? ? ? ? if not isinstance(exc, ZeroDivisionError): > > ? ? ? ? ? ? ? return > > ? ? ? ? ? ? r = find_restart('use-value') > > ? ? ? ? ? ? if not r: return > > ? ? ? ? ? ? r.invoke(42) > > ? ? ? ? ? print toy(5, 2) > > ? ? ? ? ? with handler(zd): > > ? ? ? ? ? ? print toy(1, 0) > > You could do that. > > Or, you could just put your try...finally inside a loop. [You correct `finally' to `except' in a follow-up.] I think you've missed the point almost entirely. Any code called from within the `with handler' context will (unless overridden) cause a call `toy(x, 0)' to return 42. Even if the `with handler' block calls other functions and so on. Note also that the expression of this is dynamically further from where the error is signalled than the resume point (which is within the same function). You can't do this with `try' ... `except'. Which was, of course, the point. -- [mdw] From shearern at gmail.com Mon Dec 6 18:11:44 2010 From: shearern at gmail.com (Nate) Date: Mon, 6 Dec 2010 15:11:44 -0800 (PST) Subject: Task Engine Framework? Message-ID: Hello, I'm in the process of developing a task engine / workflow module for my Python application and I'm wondering if anyone knows of existing code that could be used or adapted. Since I know that's far too generic a question, let me share my goals: 1) Support long running operations (think backing up millions of files) where: - The operation can be paused (application closed) and the operation resumed later. - Individual tasks can be chained, run in parallel, or looped over (the workflow part) 2) Would like to graph each defined operation (task A starts task B with parameters... ) for documenting algorithms in Software Design Document 3) Each individual task in the operation would a self-contained class. I'd imagine implementing its action by defining a doTask() method. Hopefully that's clear. I just feel like someone must have already solved this elegantly. I greatly enjoy Python and I look forward to proving its use as a valuable language for a Masters student even though everyone thinks I should use C# :-). Thanks! -Nate Masters Student at Eastern Washington University From bthate at gmail.com Mon Dec 6 18:29:08 2010 From: bthate at gmail.com (Bart Thate) Date: Mon, 6 Dec 2010 15:29:08 -0800 (PST) Subject: JSONBOT 0.5 RELEASED Message-ID: <251c8455-9693-46fa-a28f-15c315018e01@q12g2000yqe.googlegroups.com> Hello world ;] I'm back with another release of JSONBOT, this time it is version 0.5 so we are half way through making this a 1.0 release. Lot of changes to the core as well as other bug fixes, let me sum it up: * this version requires an upgrade of your 0.4 JSONBOT if you run already a JSONBOT see UPGRADE for more details on this. * code is adapted to use the Channel API, you need google_appengine version 1.4.0 for this. * website has gotten a brand new look and feel. * JSONBOT now uses ~/.jsonbot as its default datadir. * the RSS plugin was rewritten to work on any feed instead of only feed that support the pubDate token. * shell bots now log to ~/.jsonbot/botlogs by default, rotating the logs every day. * lots and lots of bug fixes. pointers: * source code: http://jsonbot.googlecode.com * web demo: http://jsonbot.appspot.com * jabber demo: jsonbot at appspot.com * documentation: http://jsonbot.appspot.com/docs * bugs: http://code.google.com/p/jsonbot/issues/list * twitter: http://twitter.com/#!jsonbot I consider JSONBOT to be of BETA quality now, i think it has become quite usable ;] Any feedback would be very much appreciated. As always ... HF ! Bart about JSONBOT: JSONBOT is a remote event-driven framework for building bots that talk JSON to each other over XMPP. This distribution provides bots built on this framework for console, IRC, XMPP for the shell and WWW and XMPP for the Google Application engine. JSONBOT is all of the following: * a shell console bot * a shell IRC bot * a shell XMPP bot * a Web bot running on Google Application Engine * a XMPP bot running on Google Application Engine * a Google Wave bot running op Google Application Engine * the XMPP bots are used to communicate between bots * plugin infrastructure to write your own functionality * event driven framework by the use of callbacks From stef.mientki at gmail.com Mon Dec 6 18:36:25 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 07 Dec 2010 00:36:25 +0100 Subject: A web site using Python In-Reply-To: <0014853d0112e94116049696d504@google.com> References: <0014853d0112e94116049696d504@google.com> Message-ID: <4CFD7379.8060804@gmail.com> On 04-12-2010 15:54, hidura at gmail.com wrote: > I am working on a tool that can create an application like that without write server code, but the > system is write in Python3.1 very interesting, could you give us some more information about the project for the OP: with web2py, your site could be up within an hour. cheers, Stef From steve+comp.lang.python at pearwood.info Mon Dec 6 19:17:11 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Dec 2010 00:17:11 GMT Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> Message-ID: <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> On Mon, 06 Dec 2010 08:59:12 -0800, TomF wrote: > I'm aggravated by this behavior in python: > > x = "4" > print x < 7 # prints False > I can't imagine why this design decision was made. You've never needed to deal with an heterogeneous list? data = ["Fred", "Barney", 2, 1, None] data.sort() Nevertheless, I agree that in hindsight, the ability to sort such lists is not as important as the consistency of comparisons. -- Steven From steve+comp.lang.python at pearwood.info Mon Dec 6 19:23:06 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Dec 2010 00:23:06 GMT Subject: Exception handling in Python 3.x References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> <7xmxoi8v0b.fsf@ruckus.brouhaha.com> Message-ID: <4cfd7e6a$0$29993$c3e8da3$5496439d@news.astraweb.com> On Mon, 06 Dec 2010 13:13:40 -0800, Paul Rubin wrote: > It's really unfortunate, though, that Python 3 didn't offer a way to > peek at the next element of an iterable and test emptiness directly. This idea of peekable iterables just won't die, despite the obvious flaws in the idea. There's no general way of telling whether or not a lazy sequence is done except to actually generate the next value, and caching that value is not appropriate for all such sequences since it could depend on factors which have changed between the call to peek and the call to next. If you want to implement a peek method in your own iterables, go right ahead. But you can't make arbitrary iterables peekable without making a significant class of them buggy. -- Steven From alice at gothcandy.com Mon Dec 6 19:42:27 2010 From: alice at gothcandy.com (=?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=) Date: Mon, 6 Dec 2010 16:42:27 -0800 Subject: A web site using Python References: <4CFA4305.10004@it.uu.se> <4CFD6825.9020200@simplistix.co.uk> Message-ID: > 1. Pick a web framework, I'd suggest looking at: > > Django (http://www.djangoproject.com/) > > Pyramid (http://docs.pylonshq.com/pyramid/dev/) I'm biased, but I can highly recommend WebCore (http://www.web-core.org/) as it more easily supports small to mid-sized applications and actively encourages the use of standard Python idioms. A reasonable example (though it was hurried) would be the codebase behind tsatimeline.org: https://github.com/GothAlice/TSA-Timeline The important files are application.py (controllers), model.py (data model), and the templates (views) folder. (The public folder is where CSS/JS/images go.) Similar to Stef's comment on web2py, development with WebCore (or web2py, or WebPy, or? basically any micro-framework) is extremely rapid. ? Alice. From python at mrabarnett.plus.com Mon Dec 6 19:48:30 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 07 Dec 2010 00:48:30 +0000 Subject: Exception handling in Python 3.x In-Reply-To: <4cfd7e6a$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> <7xmxoi8v0b.fsf@ruckus.brouhaha.com> <4cfd7e6a$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4CFD845E.90007@mrabarnett.plus.com> On 07/12/2010 00:23, Steven D'Aprano wrote: > On Mon, 06 Dec 2010 13:13:40 -0800, Paul Rubin wrote: > >> It's really unfortunate, though, that Python 3 didn't offer a way to >> peek at the next element of an iterable and test emptiness directly. > > This idea of peekable iterables just won't die, despite the obvious flaws > in the idea. > > There's no general way of telling whether or not a lazy sequence is done > except to actually generate the next value, and caching that value is not > appropriate for all such sequences since it could depend on factors which > have changed between the call to peek and the call to next. > > If you want to implement a peek method in your own iterables, go right > ahead. But you can't make arbitrary iterables peekable without making a > significant class of them buggy. > Perhaps Python could use Guido's time machine to check whether the sequence will yield another object in the future. :-) From hidura at gmail.com Mon Dec 6 19:57:55 2010 From: hidura at gmail.com (Hidura) Date: Mon, 6 Dec 2010 20:57:55 -0400 Subject: A web site using Python In-Reply-To: <4CFD7379.8060804@gmail.com> References: <0014853d0112e94116049696d504@google.com> <4CFD7379.8060804@gmail.com> Message-ID: KarinApp will allow you to create an application without writing code, eg: you want to insert the information of a person in the DB, with all the current framework you will write a code that takes the data, and after you will write the insert, and if you want to send a response you will have to write it too. KarinApp is a framework that comes with several libraries inside-all writes on Pythn- and like Python is extensible, so you can create a page and save it-KarinApp has a hosting service so you can create pages like in DW but highly appended to the standard of the W3C- and on the page you put a all the inputs with the form, and create a batute-that is the function on KarinApp- and design the model of the response, and with it you just call in some cases to a javascript function named 'catcher' that will collect the data and send it to the server. The server will run the batute-calling the libraries on KarinApp- and the result will be sent to the client as HTML element(s) and will be appended on the area that you want. If you need more detailed information, please let me know. On Mon, Dec 6, 2010 at 7:36 PM, Stef Mientki wrote: > On 04-12-2010 15:54, hidura at gmail.com wrote: > > I am working on a tool that can create an application like that without > write server code, but the > > system is write in Python3.1 > > very interesting, could you give us some more information about the project > > for the OP: > with web2py, your site could be up within an hour. > > cheers, > Stef > -- > http://mail.python.org/mailman/listinfo/python-list > -- Diego I. Hidalgo D. -------------- next part -------------- An HTML attachment was scrubbed... URL: From greno at verizon.net Mon Dec 6 20:17:29 2010 From: greno at verizon.net (Gerry Reno) Date: Mon, 06 Dec 2010 20:17:29 -0500 Subject: A web site using Python In-Reply-To: References: <4CFA4305.10004@it.uu.se> <4CFD6825.9020200@simplistix.co.uk> Message-ID: <4CFD8B29.3020006@verizon.net> If you have any need of a portable LAMP stack, I just finished writing some How-To's for getting Python, VirtualEnv and WSGI frameworks running with XAMPP: How-To: Add VirtualEnv and Pylons (WSGI framework) to XAMPP How-To: Add VirtualEnv and Django (WSGI framework) to XAMPP How-To: Add Python and mod_wsgi to XAMPP -Gerry On 12/06/2010 07:42 PM, Alice Bevan?McGregor wrote: >> 1. Pick a web framework, I'd suggest looking at: >> >> Django (http://www.djangoproject.com/) >> >> Pyramid (http://docs.pylonshq.com/pyramid/dev/) > > I'm biased, but I can highly recommend WebCore > (http://www.web-core.org/) as it more easily supports small to > mid-sized applications and actively encourages the use of standard > Python idioms. > > A reasonable example (though it was hurried) would be the codebase > behind tsatimeline.org: > > https://github.com/GothAlice/TSA-Timeline > > The important files are application.py (controllers), model.py (data > model), and the templates (views) folder. (The public folder is where > CSS/JS/images go.) Similar to Stef's comment on web2py, development > with WebCore (or web2py, or WebPy, or? basically any micro-framework) > is extremely rapid. > > ? Alice. > > From ax003d at gmail.com Mon Dec 6 20:22:50 2010 From: ax003d at gmail.com (ax003d) Date: Tue, 7 Dec 2010 09:22:50 +0800 Subject: TDD in python In-Reply-To: <4CFD65F8.7020908@simplistix.co.uk> References: <0906c010-709d-41d9-8b29-2f42afb87f94@32g2000yqz.googlegroups.com> <58fe3680-21f5-42f8-9341-e069cbb88975@r19g2000prm.googlegroups.com> <4CFD65F8.7020908@simplistix.co.uk> Message-ID: This book may help you: http://www.apress.com/book/view/9781590599815 2010/12/7 Chris Withers > On 30/11/2010 13:33, Roy Smith wrote: > >> In article >> <58fe3680-21f5-42f8-9341-e069cbb88975 at r19g2000prm.googlegroups.com>, >> rustom wrote: >> >> Looking around I found this: >>> http://bytes.com/topic/python/answers/43330-unittest-vs-py-test >>> where Raymond Hettinger no less says quite unequivocally that he >>> prefers test.py to builtin unittest >>> because it is not so heavy-weight >>> >>> Is this the general consensus nowadays among pythonistas? >>> [Note I tend to agree but Ive no experience so asking] >>> >> >> Both frameworks have their fans; I doubt you'll find any consensus. >> >> Pick one, learn it, and use it. What's important is that you write >> tests, write lots of tests, and write good tests. Which framework you >> use is a detail. >> > > For a great mailing lists that covers all of these types of issues, see > here: > > http://lists.idyll.org/listinfo/testing-in-python > > cheers, > > Chris > > -- > Simplistix - Content Management, Batch Processing & Python Consulting > - http://www.simplistix.co.uk > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nobody at nowhere.com Mon Dec 6 21:26:02 2010 From: nobody at nowhere.com (Nobody) Date: Tue, 07 Dec 2010 02:26:02 +0000 Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> <7x39qbfhd8.fsf@ruckus.brouhaha.com> Message-ID: On Mon, 06 Dec 2010 08:32:18 -0500, Mel wrote: > Apparently, at the end of his research, Alan Turing was trying out the idea > of 'oracles', where a computable process would have access to an > uncomputable process to get particular results. I would imagine that the > idea here was to clarify what this would do to the computable process. If > he had lived, I doubt that Turing would have built an oracle, but the idea > does live on in interactive debuggers. The "oracle" concept was introduced quite early on in Turing's work, late 1930s. The idea is to examine the complexity of problems relative to other problems. E.g. if you have a Turing machine with access to an oracle which can solve some NP-complete problem, you can analyse the complexity of solving other NP-complete problems in that context. From nagle at animats.com Mon Dec 6 23:58:48 2010 From: nagle at animats.com (John Nagle) Date: Mon, 06 Dec 2010 20:58:48 -0800 Subject: Exception handling in Python 3.x In-Reply-To: <878w02leut.fsf.mdw@metalzone.distorted.org.uk> References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> <4cfd4d5a$0$1662$742ec2ed@news.sonic.net> <878w02leut.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4cfdbf06$0$1629$742ec2ed@news.sonic.net> On 12/6/2010 2:24 PM, Mark Wooding wrote: > John Nagle writes: > >> Right. You're not entitled to assume that StopIteration is how a >> generator exits. That's a CPyton thing; generators were a retrofit, >> and that's how they were hacked in. Other implementations may do >> generators differently. > > This is simply wrong. The StopIteration exception is a clear part of > the generator protocol as described in 5.2.8 of the language reference; > the language reference also refers to 3.5 of the library reference, > which describes the iterator protocol (note, not the generator > implementation -- all iterators work the same way), and explicitly > mentions StopIteration as part of the protocol. > > -- [mdw] PEP 255, like too much Python literature, doesn't distinguish clearly between the language definition and implementation detail. It says "The mechanics of StopIteration are low-level details, much like the mechanics of IndexError in Python 2.1". Applications shouldn't be explicitly using StopIteration. IronPython doesn't do StopIteration the same way CPython does. http://ironpython.codeplex.com/wikipage?title=IPy1.0.xCPyDifferences Neither does Shed Skin. John Nagle From nagle at animats.com Tue Dec 7 00:05:34 2010 From: nagle at animats.com (John Nagle) Date: Mon, 06 Dec 2010 21:05:34 -0800 Subject: Exception handling in Python 3.x In-Reply-To: <4cfd7e6a$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> <7xmxoi8v0b.fsf@ruckus.brouhaha.com> <4cfd7e6a$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cfdc09d$0$1643$742ec2ed@news.sonic.net> On 12/6/2010 4:23 PM, Steven D'Aprano wrote: > On Mon, 06 Dec 2010 13:13:40 -0800, Paul Rubin wrote: > >> It's really unfortunate, though, that Python 3 didn't offer a way to >> peek at the next element of an iterable and test emptiness directly. > > This idea of peekable iterables just won't die, despite the obvious flaws > in the idea. > > There's no general way of telling whether or not a lazy sequence is done > except to actually generate the next value, and caching that value is not > appropriate for all such sequences since it could depend on factors which > have changed between the call to peek and the call to next. Right. Pascal had the predicates "eoln(file)" and "eof(file)", which were tests for end of line and end of file made before reading. This caused much grief with interactive input, because the test would stall waiting for the user to type something. Wirth originally intended Pascal for batch jobs, and his version didn't translate well to interactive use. (Wirth fell in love with his original recursive-descent compiler, which was simple but limited. He hated to have language features that didn't fit his compiler model well. This held the language back and eventually killed it.) C I/O returned a unique value on EOF, but there was no way to test for it before reading. Works much better. The same issues apply to pipes, sockets, qeueues, interprocess communication, etc. John Nagle From lukasz at langa.pl Tue Dec 7 03:24:37 2010 From: lukasz at langa.pl (=?utf-8?Q?=C5=81ukasz_Langa?=) Date: Tue, 7 Dec 2010 09:24:37 +0100 Subject: [Python-Dev] [RELEASED] Python 3.2 beta 1 In-Reply-To: <4CFD59C8.4070006@python.org> References: <4CFD59C8.4070006@python.org> Message-ID: <433FCEE2-CD6C-48BD-90DF-2990B27E4EED@langa.pl> Wiadomo?? napisana przez Georg Brandl w dniu 2010-12-06, o godz. 22:46: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On behalf of the Python development team, I'm happy to announce the > first of two beta preview releases of Python 3.2. > > Python 3.2 is a continuation of the efforts to improve and stabilize the > Python 3.x line. Since the final release of Python 2.7, the 2.x line > will only receive bugfixes, and new features are developed for 3.x only. > > Since PEP 3003, the Moratorium on Language Changes, is in effect, there > are no changes in Python's syntax and built-in types in Python 3.2. > Development efforts concentrated on the standard library and support for > porting code to Python 3. Highlights are: > > [snip] * configparser 1.1: new API using the mapping protocol access, support for pluggable interpolation handlers, additional interpolation handler (ExtendedInterpolation) which supports the zc.buildout syntax, support for alternative option/value delimiters, support for customization of accepted INI file structure (e.g. comment prefixes, name of the DEFAULT section, indentation, empty lines in multiline values, etc.), support for specifying encoding for read operations, ConfigParser class deprecated in favor of SafeConfigParser, lots of other small changes. -- Best regards, ?ukasz Langa tel. +48 791 080 144 WWW http://lukasz.langa.pl/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From nagle at animats.com Tue Dec 7 03:53:27 2010 From: nagle at animats.com (John Nagle) Date: Tue, 07 Dec 2010 00:53:27 -0800 Subject: Collision of rotated rectangles without pygame In-Reply-To: <20101205234936.39dc1a4e@Knock> References: <20101205234936.39dc1a4e@Knock> Message-ID: <4cfdf605$0$1639$742ec2ed@news.sonic.net> On 12/5/2010 2:49 PM, Martin Manns wrote: > Hello, > > I am looking for a Python library for 2D collision checks of rotated > rectangles. Currently, I have found vizier 0.5b that is based on pygame. > > Since I do not want to add a pygame dependency to my app, I replaced the > pygame.rect.Rect by a wxPython wx.Rect (see code below). > > However, collision checks do not work correctly, i. e. identical rects > are not found to be colliding: Probably because you seem to be trying to compute the intersection point for coincident lines, which is not well-defined. I don't have time to debug this, but you might want to get some basic books on game programming and graphics. Incidentally, a dictionary lookup in Python is far more expensive than computing trig functions. If you need to speed this up for large numbers of rectangles, there are algorithms that are several orders of magnitude faster. Realistically, though, this is the kind of problem that runs slow in CPython. This is why you don't write your own collision library. (I once did, for 3D, but that was in 1996, when it was cutting-edge technology.) John Nagle From dheeraj.gupta4 at gmail.com Tue Dec 7 04:16:56 2010 From: dheeraj.gupta4 at gmail.com (RedBaron) Date: Tue, 7 Dec 2010 01:16:56 -0800 (PST) Subject: Using logging module to log either to screen or a file Message-ID: <3b9112c2-7a63-40ef-a0f6-f64a090acb59@j18g2000prn.googlegroups.com> Hi, I am beginner to python and i am writing a program that does a lot of things. One of the requirements is that the program shud generate a log file. I came across python loggging module and found it very useful. But I have a few problems Suppose by giving option '-v' along with the program the user can turn off logging to a file and instead display log on the screen. Since I am using a config file for logging, how do I accomplish this. I tried to define two handlers (fil and screen) and added it to my logger. But that logs data to both screen and the file. I need to log it to only one. How do I dynamically remove one of the handler from the logger based on user option. As a precursor how do i reference the handlers defined in config file in the code?? From mdw at distorted.org.uk Tue Dec 7 05:00:30 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 07 Dec 2010 10:00:30 +0000 Subject: Exception handling in Python 3.x References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> <4cfd4d5a$0$1662$742ec2ed@news.sonic.net> <878w02leut.fsf.mdw@metalzone.distorted.org.uk> <4cfdbf06$0$1629$742ec2ed@news.sonic.net> Message-ID: <87zkshkim9.fsf.mdw@metalzone.distorted.org.uk> John Nagle writes: > PEP 255, like too much Python literature, doesn't distinguish > clearly between the language definition and implementation detail. It > says "The mechanics of StopIteration are low-level details, much like > the mechanics of IndexError in Python 2.1". Applications shouldn't be > explicitly using StopIteration. You've twisted the words by quoting them out of context, and have attempted to force a misinterpretation of `low-level details' as `implementation detail'. That text comes from a question-and-answer section, in response to the question `why not force termination to be spelled "StopIteration"?'. This is a fine answer to the question: the details of the (preexisting -- see PEP 234) iteration protocol are abstracted by the generator syntax. But it doesn't at all mean that the StopIteration exception isn't an official, use-visible part of Python. > IronPython doesn't do StopIteration the same way CPython does. > > http://ironpython.codeplex.com/wikipage?title=IPy1.0.xCPyDifferences IronPython's behaviour when you try to fetch items from a spent generator is different. It still implements the same iterator protocol, and raises StopIteration when it has no more items to yield. You're not stupid, but you'd have to be in order to think that these references support your claim that > >> You're not entitled to assume that StopIteration is how a generator > >> exits. That's a CPyton thing; generators were a retrofit, and > >> that's how they were hacked in. Other implementations may do > >> generators differently. I don't want to conclude that you're not arguing in good faith but I'm not seeing many other possibilities. -- [mdw] From shearichard at gmail.com Tue Dec 7 05:49:00 2010 From: shearichard at gmail.com (shearichard) Date: Tue, 7 Dec 2010 02:49:00 -0800 (PST) Subject: PEP8 compliance and exception messages ? References: <63cab97f-4e46-4c30-83ce-dc531a900d40@u25g2000pra.googlegroups.com> <87ei9v1nop.fsf@benfinney.id.au> Message-ID: <0f8ab582-97e2-4027-b59d-0fa37708a9d3@n2g2000pre.googlegroups.com> On Dec 6, 6:21?pm, Ben Finney wrote: > shearichard writes: > > Hi - PEP8 says lines should not exceed 79 characters in length > > (http://www.python.org/dev/peps/pep-0008/). > > > So if you've got some code that looks like this : > > > raise fooMod.fooException("Some message which is quite long") > > PEP 8 also says those names are poorly chosen. Better: > > ? ? raise foomod.FooException("Some message which is quite long") > > > raise fooMod.fooException("\ > > ? ? ? ? Some message \ > > ? ? ? ? which is quite long") > > Take advantage of the parsing of string literals and parenthesis: > > ? ? raise foomod.FooException( > ? ? ? ? "Some message" > ? ? ? ? " which is quite long") > > and for the sake of my eyes, avoid camelCase. OK you got me ! Thanks for pointing this out, I will take a look at the relevant section From shearichard at gmail.com Tue Dec 7 05:53:44 2010 From: shearichard at gmail.com (shearichard) Date: Tue, 7 Dec 2010 02:53:44 -0800 (PST) Subject: PEP8 compliance and exception messages ? References: <63cab97f-4e46-4c30-83ce-dc531a900d40@u25g2000pra.googlegroups.com> <20101206002249.2d804250@wldmr> <20101206151721.4446d722@wldmr> Message-ID: <61321d11-76ad-4355-958f-e70f7c58ab7d@n2g2000pre.googlegroups.com> On Dec 7, 9:17?am, Andreas Waldenburger wrote: > On Mon, 6 Dec 2010 00:22:49 -0500 Andreas Waldenburger wrote: > > > > > On Sun, 5 Dec 2010 19:52:54 -0800 Chris Rebert > > wrote: > > > > On Sun, Dec 5, 2010 at 7:40 PM, shearichard > > > wrote: > > > > Hi - PEP8 says lines should not exceed 79 characters in length > > > > (http://www.python.org/dev/peps/pep-0008/). > > > > > So if you've got some code that looks like this : > > > > > raise fooMod.fooException("Some message which is quite long") > > > > > ... and assuming a certain amount of indenting you're going to > > > > break that guideline. > > > > > [etc.] > > > > [...] > > > Alternatively, you could disregard PEP 8 on this point on the > > > grounds that the 79/80 characters per line limit is outdated. > > > Maybe, but it's not outmoded. > > As a more useful (I hope) reply, my opinion in this case is to just make the line a little longer. Even if you can't read it all at once, it is pretty obvious what comes next: The rest of the error message. There is no additional functionality hidden there, and you don't need to see it all at once to grasp the meaning of the code. > > /W > > -- > To reach me via email, replace INVALID with the country code of my home > country. ?But if you spam me, I'll be one sour Kraut. Thanks to everyone for their helpful replies. Thanks for the pointers towards implicit (or explicit) string concatenation - just what was needed. I appreciate everyone has different opinions by I'm happy to try to stick with 79 character lines for the meantime - largely for the 'may have a wide screen but like to have lots of files open in slim windows' reason. regards Richard. From steve.gnulinux at gmail.com Tue Dec 7 06:05:06 2010 From: steve.gnulinux at gmail.com (Steve) Date: Tue, 7 Dec 2010 03:05:06 -0800 (PST) Subject: v = vte.Terminal() AttributeError: 'module' object has no attribute 'Terminal' Message-ID: Hi, I try to run a terminal emulation using Python+Gtk+Vte. Before develop my own sources, i'm testing some examples like this ; http://www.eurion.net/python-snippets/snippet/Embed%20a%20VTE%20terminal.html But when i try to run, i get this message error; v = vte.Terminal() AttributeError: 'module' object has no attribute 'Terminal' I'm using ubuntu 9.10 karmic. I've installed (apt-get) python-gtk, /2, -dev, libvte... Anyone know if there's a bug on this using karmic, or i must to download and compile gtk/vte from sources? thanks, Steve, From zdoor at xs4all.nl Tue Dec 7 06:11:44 2010 From: zdoor at xs4all.nl (Alex van der Spek) Date: Tue, 7 Dec 2010 12:11:44 +0100 Subject: Calling FORTAN dll functions from Python Message-ID: <4cfe167a$0$81476$e4fe514c@news.xs4all.nl> Does anyone know how to call functions from FORTRAN dlls in Python? Is it even possible? I browsed the documentation for Python 2.6.1 and the Python/C API comes close to what I would like to do but it is strictly limited to C. Unfortunately the passing of arguments in C and FORTRAN is very different, not to mention the differences with strings where FORTRAN expects a hidden length argument. It could call the FORTRAN dll from C and call the C functions from Python but is that my only option? For reference: I am using Python 2.6.1 FORTRAN powerstation 4.0. It is not an option to translate the FORTRAN code to C (using f2c) as the source code is the official ASME version of calculating steam tables. I am interested in a solution that will work on Windows (XP and Vista) as well as Linux (Ubuntu 10.4) although the latter would not use dlls but code resources. I am a beginner in Python. The fact that I still use and can use FORTRAN gives away my age. Mixed language programming is not an issue for me (C/VB, VB/FORTRAN, C/FORTRAN) but Python is new. Just pointing me to relevant documentation would be helpful in its own right. Thank you in advance, Alex van der Spek From stefan_ml at behnel.de Tue Dec 7 06:52:54 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 07 Dec 2010 12:52:54 +0100 Subject: Calling FORTAN dll functions from Python In-Reply-To: <4cfe167a$0$81476$e4fe514c@news.xs4all.nl> References: <4cfe167a$0$81476$e4fe514c@news.xs4all.nl> Message-ID: Alex van der Spek, 07.12.2010 12:11: > Does anyone know how to call functions from FORTRAN dlls in Python? Is > it even possible? Sure, have a look at fwrap and Cython. Stefan From anders.u.persson at gmail.com Tue Dec 7 08:23:06 2010 From: anders.u.persson at gmail.com (Anders Persson) Date: Tue, 7 Dec 2010 05:23:06 -0800 (PST) Subject: is py2exe still active ? Message-ID: <5f32249f-50d4-440e-9005-04f954572894@32g2000yqz.googlegroups.com> Hi! When a look att py2exe homepage it is not looking like mutch happen, as a beginner i was thinking to start with Python 3, but i like to now if py2exe will be for 3 too. Is any one have any info ? From orasnita at gmail.com Tue Dec 7 08:39:18 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Tue, 7 Dec 2010 15:39:18 +0200 Subject: Books recommendation Message-ID: Hello, Do you have, or can I find elsewhere a recommendation for books,tutorials and sites appropriate for beginners? I have a lot of experience in Perl but I am interested to also learn Python for: - web development (with frameworks similar with Catalyst and Ruby on Rails, good templating systems, good ORMS and form processors) - Desktop apps with WxPython - Create MS Windows apps, executables, dlls, ActiveX, OS interaction... - Text parsing, regular expressions... I am also interested to find where I can get Python modules from and how... similar tools and sites with cpan and ppm for Perl. Thank you. Octavian From anders.u.persson at gmail.com Tue Dec 7 09:14:21 2010 From: anders.u.persson at gmail.com (Anders Persson) Date: Tue, 7 Dec 2010 06:14:21 -0800 (PST) Subject: Books recommendation References: Message-ID: <4eeb8e48-93b7-42aa-8d0a-43b4fdd5fef0@z9g2000yqz.googlegroups.com> You can't compile Python to exe files, but there is program packing your script to a exe files, look att www.py2exe.org Beware that you must have py2exe version match your pythonversion and att current time the highest version is 2.7. /A On Dec 7, 2:39?pm, "Octavian Rasnita" wrote: > Hello, > > Do you have, or can I find elsewhere a recommendation for books,tutorials and sites appropriate for beginners? > > I have a lot of experience in Perl but I am interested to also learn Python for: > - web development (with frameworks similar with Catalyst and Ruby on Rails, good templating systems, good ORMS and form processors) > - Desktop apps with WxPython > - Create MS Windows apps, executables, dlls, ActiveX, OS interaction... > - Text parsing, regular expressions... > > I am also interested to find where I can get Python modules from and how... similar tools and sites with cpan and ppm for Perl. > > Thank you. > > Octavian From data.2 at rediff.com Tue Dec 7 09:16:01 2010 From: data.2 at rediff.com (gaurav) Date: Tue, 7 Dec 2010 06:16:01 -0800 (PST) Subject: Fresher career in Management work. Message-ID: Recent recruitment you can reach your goal. Careers recruitment. http://managementjobs.webs.com/itm.htm http://topcareer.webs.com/businessmanagement.htm Latest government works to earn money, other vacancies in office jobs. http://printmediajobs.webs.com/index.htm http://rojgars1.webs.com/gov.htm From jeanmichel at sequans.com Tue Dec 7 09:33:14 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 07 Dec 2010 15:33:14 +0100 Subject: Using logging module to log either to screen or a file In-Reply-To: <3b9112c2-7a63-40ef-a0f6-f64a090acb59@j18g2000prn.googlegroups.com> References: <3b9112c2-7a63-40ef-a0f6-f64a090acb59@j18g2000prn.googlegroups.com> Message-ID: <4CFE45AA.5010405@sequans.com> RedBaron wrote: > Hi, > I am beginner to python and i am writing a program that does a lot of > things. One of the requirements is that the program shud generate a > log file. I came across python loggging module and found it very > useful. But I have a few problems > Suppose by giving option '-v' along with the program the user can turn > off logging to a file and instead display log on the screen. Since I > am using a config file for logging, how do I accomplish this. > I tried to define two handlers (fil and screen) and added it to my > logger. But that logs data to both screen and the file. I need to log > it to only one. How do I dynamically remove one of the handler from > the logger based on user option. As a precursor how do i reference the > handlers defined in config file in the code?? > your logger has a public 'handlers' attribute. consoleHandlers = [h for h in logger.handlers if h.__class__ is logging.StreamHandler] # the list of handlers logging to the console (assuming they are instances of the StreamHandler class) if consoleHandlers: h1 = consoleHandlers[0] h1.filter = lambda x:True # enable the handler h1.filter = lambda x:False # disable the handler JM From sebastien.frigon at gmail.com Tue Dec 7 10:00:12 2010 From: sebastien.frigon at gmail.com (Cbast) Date: Tue, 7 Dec 2010 07:00:12 -0800 (PST) Subject: is py2exe still active ? References: <5f32249f-50d4-440e-9005-04f954572894@32g2000yqz.googlegroups.com> Message-ID: <89dd2092-d6e9-4d5c-b966-54df3f48f065@g19g2000yqg.googlegroups.com> On Dec 7, 8:23?am, Anders Persson wrote: > Hi! > When a look att py2exe homepage it is not looking like mutch happen, > as a beginner i was thinking to start with Python 3, but i like to now > if py2exe will be for 3 too. > > Is any one have any info ? I don't have the answer about py2exe, but I'm using cxFreeze to create executables with Python 3.1, if it's what you're looking for. http://cx-freeze.sourceforge.net/ From grappale at hotmail.it Tue Dec 7 10:26:04 2010 From: grappale at hotmail.it (Ale Ghelfi) Date: Tue, 07 Dec 2010 16:26:04 +0100 Subject: sqlite3 and UTF-8 Message-ID: I try to connect a database sqlite by sqlite3, but return an error. >>> rowset = cur.fetchall() Traceback (most recent call last): File "", line 1, in rowset = cur.fetchall() OperationalError: Could not decode to UTF-8 column 'DATO' with text 'Document n?10' What's happend? thank you From grappale at hotmail.it Tue Dec 7 10:35:02 2010 From: grappale at hotmail.it (Ale Ghelfi) Date: Tue, 07 Dec 2010 16:35:02 +0100 Subject: kinterbasdb error connection Message-ID: (i'm under Ubuntu 10.10 amd64 and python 2.6 and kinterbasdb 3.2 ) I try to connect my database of firebird 2.5 by kinterbasdb. But python return this error : >>> c = kinterbasdb.connect(dsn="/media/VINACCIA.FDB",user="user",password="password",charset="UTF-8") Traceback (most recent call last): File "", line 1, in c = kinterbasdb.connect(dsn="/media/VINACCIA.FDB",user="user",password="password",charset="UTF-8") File "/usr/lib/pymodules/python2.6/kinterbasdb/__init__.py", line 435, in connect return Connection(*args, **keywords_args) File "/usr/lib/pymodules/python2.6/kinterbasdb/__init__.py", line 612, in __init__ b.dsn, b.dpb, b.dialect, timeout OperationalError: (-902, 'isc_attach_database: \n I/O error during "open" operation for file "/media/VINACCIA.FDB"\n Error while trying to open file\n Permission denied') By terminal of Ubuntu this is the permission of database: $ls -l /media/VINACCIA.FDB -rw-r--r-- 1 grappale grappale 1720320 2010-12-06 17:33 /media/VINACCIA.FDB Where am i wrong? Please. Thank you! From orasnita at gmail.com Tue Dec 7 10:47:32 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Tue, 7 Dec 2010 17:47:32 +0200 Subject: Books recommendation References: <4eeb8e48-93b7-42aa-8d0a-43b4fdd5fef0@z9g2000yqz.googlegroups.com> Message-ID: <4F36CB2A698F48AB8F613C4E12B18C47@teddy> Thank you for your help. I have succeeded to create a Windows executable with py2exe. I've seen that the source code of the sample script is hidden. Do you know if it happens the same if the script uses other Python modules I will make? (Will py2exe hide the source code of those modules also?) Thanks. Octavian ----- Original Message ----- From: "Anders Persson" Newsgroups: comp.lang.python To: Sent: Tuesday, December 07, 2010 4:14 PM Subject: Re: Books recommendation You can't compile Python to exe files, but there is program packing your script to a exe files, look att www.py2exe.org Beware that you must have py2exe version match your pythonversion and att current time the highest version is 2.7. /A On Dec 7, 2:39 pm, "Octavian Rasnita" wrote: > Hello, > > Do you have, or can I find elsewhere a recommendation for books,tutorials and sites appropriate for beginners? > > I have a lot of experience in Perl but I am interested to also learn Python for: > - web development (with frameworks similar with Catalyst and Ruby on Rails, good templating systems, good ORMS and form processors) > - Desktop apps with WxPython > - Create MS Windows apps, executables, dlls, ActiveX, OS interaction... > - Text parsing, regular expressions... > > I am also interested to find where I can get Python modules from and how... similar tools and sites with cpan and ppm for Perl. > > Thank you. > > Octavian -- http://mail.python.org/mailman/listinfo/python-list From g.starck at gmail.com Tue Dec 7 10:52:06 2010 From: g.starck at gmail.com (gst) Date: Tue, 7 Dec 2010 07:52:06 -0800 (PST) Subject: use of __new__ to permit "dynamic" completion within (any?) IDE ? Message-ID: <0b90e80b-8b9b-412d-bfff-9a9ec4b172d2@h22g2000vbr.googlegroups.com> Hi, I met a situation where I was passing an object created in/with an upper level module class to a lower level module class' instance in one of its __init__ argument and saving a ref of the upper object in that lower level class' new instance. But in my IDE I want the completion to also work from within the lower level module when it's refering to the object passed from the upper level: Well, I'm sure I'm not very clear in my terms (and probably a bit long in the sentence) so here it is in code: files: module1.py subpackage/module2.py file module1.py: from subpackage.module2 import class2 class class1(object): def __new__(cls, _self=None, *args, **kwargs): if _self: ## we've been passed an instance already initialyzed ## so directly return it instead of creating a new object. return _self return object.__new__(cls) def __init__(self, _self=None, *args, **kwargs): if _self: ## we've been passed an instance already initialyzed ## so directly returns ## assert(self is _self) ? return self.object2 = class2(object1=self, "blip", "blop") # others init file module2.py: class class2(object): def __init__(self, object1, *args, **kwargs): from ..module1 import class1 self.object1 = class1(_self=object1) ## instead of: self.object1 = object1 ## others functions and/or init.. ## where now I've completion working on self.object1 : ## if I add(or remove) fields/methods in module1 (and save) then ## I have them available(or disappeared) in the completion when executed from this submodule. ## This ofcourse permits to save me of remembering all of the class1 attributes/methods when I'm working with self.object1 from within one of class2 methods. What do you think of this ? I guess there can be others ways of doing this.. ? Thanks, Regards, Greg. note: I'm using Eclipse 3.5.2 with pydev so (I don't really know how others IDE can handle this case) . From __peter__ at web.de Tue Dec 7 10:55:29 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 07 Dec 2010 16:55:29 +0100 Subject: sqlite3 and UTF-8 References: Message-ID: Ale Ghelfi wrote: > I try to connect a database sqlite by sqlite3, but return an error. > > >>> rowset = cur.fetchall() > Traceback (most recent call last): > File "", line 1, in > rowset = cur.fetchall() > OperationalError: Could not decode to UTF-8 column 'DATO' with text > 'Document n?10' > > What's happend? thank you How did you enter the data into the database? If it was with a script under your control modify it to feed unicode instead of str to the database. Otherwise, if you know the encoding used in the database maybe setting Connection.text_factory actual_encoding = ... # whatever def decode(s): return s.decode(actual_encoding) db = sqlite3.connect(...) db.text_factory = decode helps (untested). See also http://docs.python.org/library/sqlite3.html#sqlite3.Connection.text_factory Peter From lists at cheimes.de Tue Dec 7 10:55:47 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 07 Dec 2010 16:55:47 +0100 Subject: kinterbasdb error connection In-Reply-To: References: Message-ID: Am 07.12.2010 16:35, schrieb Ale Ghelfi: > (i'm under Ubuntu 10.10 amd64 and python 2.6 and kinterbasdb 3.2 ) > I try to connect my database of firebird 2.5 by kinterbasdb. > But python return this error : > > >>> c = > kinterbasdb.connect(dsn="/media/VINACCIA.FDB",user="user",password="password",charset="UTF-8") > Traceback (most recent call last): > File "", line 1, in > c = > kinterbasdb.connect(dsn="/media/VINACCIA.FDB",user="user",password="password",charset="UTF-8") > File "/usr/lib/pymodules/python2.6/kinterbasdb/__init__.py", line > 435, in connect > return Connection(*args, **keywords_args) > File "/usr/lib/pymodules/python2.6/kinterbasdb/__init__.py", line > 612, in __init__ > b.dsn, b.dpb, b.dialect, timeout > OperationalError: (-902, 'isc_attach_database: \n I/O error during > "open" operation for file "/media/VINACCIA.FDB"\n Error while trying to > open file\n Permission denied') > > By terminal of Ubuntu this is the permission of database: > $ls -l /media/VINACCIA.FDB > -rw-r--r-- 1 grappale grappale 1720320 2010-12-06 17:33 /media/VINACCIA.FDB > > Where am i wrong? Please. Thank you! Are you using classic mode or super mode? I have no experience with classic mode but for super mode, the firebird user or group needs permission to enter the directory (rx for / and /media) and to alter the file (rw for media/VINACCIA.FDB). I suggest that you change the permission to 664 and the group of the file to firebird. Christian From awilliam at whitemice.org Tue Dec 7 11:32:30 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Tue, 07 Dec 2010 11:32:30 -0500 Subject: Task Engine Framework? In-Reply-To: References: Message-ID: <1291739550.12904.6.camel@linux-yu4c.site> On Mon, 2010-12-06 at 15:11 -0800, Nate wrote: > Hello, > I'm in the process of developing a task engine / workflow module for > my Python application and I'm wondering if anyone knows of existing > code that could be used or adapted. Since I know that's far too > generic a question, let me share my goals: > 1) Support long running operations (think backing up millions of > files) where: > - The operation can be paused (application closed) and the > operation resumed later. > - Individual tasks can be chained, run in parallel, or looped over > (the workflow part) We have something like that in OIE (OpenGroupware Integration Engine). . These things tend to turn out to be quite specific [and thus not generic]. But if you have any questions feel free to ask. The focus in OIE was the ability to describe processes in BPML and facilitate process management [creating, queuing, parking (stopping for later resume) of business / ETL tasks. Parts of the code aren't especially elegant but it does move a fairly large amount of data every day. > 2) Would like to graph each defined operation (task A starts task B > with parameters... ) for documenting algorithms in Software Design > Document > 3) Each individual task in the operation would a self-contained > class. I'd imagine implementing its action by defining a doTask() > method > Hopefully that's clear. I just feel like someone must have already > solved this elegantly. I greatly enjoy Python and I look forward to > proving its use as a valuable language for a Masters student even > though everyone thinks I should use C# :-). From bruno.desthuilliers at gmail.com Tue Dec 7 11:34:08 2010 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Tue, 7 Dec 2010 08:34:08 -0800 (PST) Subject: v = vte.Terminal() AttributeError: 'module' object has no attribute 'Terminal' References: Message-ID: On 7 d?c, 12:05, Steve wrote: > Hi, > > I try to run a terminal emulation using Python+Gtk+Vte. Before develop > my own sources, i'm testing some examples like this ;http://www.eurion.net/python-snippets/snippet/Embed%20a%20VTE%20termi... > > But when i try to run, i get this message error; > > ? ? v = vte.Terminal() > AttributeError: 'module' object has no attribute 'Terminal' Before any other thing, make sure the "vte" module you imported is the expected one. Edit your script that way: # import vte try: import vte except: error = gtk.MessageDialog (None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, 'You need to install python bindings for libvte') error.run() sys.exit (1) else: print "using wte module : %s" % vte and check the module path this prints to your stdout. From grappale at hotmail.it Tue Dec 7 11:37:37 2010 From: grappale at hotmail.it (Ale Ghelfi) Date: Tue, 07 Dec 2010 17:37:37 +0100 Subject: sqlite3 and UTF-8 References: Message-ID: i try this : > actual_encoding = ... # whatever > def decode(s): > return s.decode(actual_encoding) > > db = sqlite3.connect(...) > db.text_factory = decode but now the error is : >>> rowset = cur.fetchall() Traceback (most recent call last): File "", line 1, in rowset = cur.fetchall() File "", line 2, in decode return s.decode(enc) File "/usr/lib/python2.6/encodings/utf_8.py", line 16, in decode return codecs.utf_8_decode(input, errors, True) UnicodeDecodeError: 'utf8' codec can't decode byte 0xb0 in position 33: invalid start byte From pythonmarco at gmail.com Tue Dec 7 11:51:05 2010 From: pythonmarco at gmail.com (Marco Hornung) Date: Tue, 7 Dec 2010 11:51:05 -0500 Subject: find memory leaks in running program Message-ID: <391F8BF8-8FF5-42B8-8F10-C6F0428CA27B@gmail.com> Hey, ------------------------------------------------------------------------------------------ questions ------------------------------------------------------------------------------------------ 1. What are the best tools to analyze pythons memory stack, while it is running? 2. Is there a possibility to analyze the memory stack of a program with external programs? (without to change the source code - I am only interested in the object size) 3. Can I sort of "break" into the memory to see what objects consume how much memory? ------------------------------------------------------------------------------------------ my scenario ------------------------------------------------------------------------------------------ I have to debug a multithreaded server, which is written in the twisted-framework. One of the processes has some sort of memory leak - After one of our jobs is finished the main process has still over 59% of the entire memory allocated. I will probably have to recreate our scenario and equip our server with some memory sensors - but it takes 12h to reproduce the scenario and I will have to change the source code(at least I do not know of other options). Therefore I am looking for quicker possibilities to look into what causes our memory leak. Regards, Marco From __peter__ at web.de Tue Dec 7 11:52:00 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 07 Dec 2010 17:52 +0100 Subject: sqlite3 and UTF-8 References: Message-ID: Ale Ghelfi wrote: > i try this : > >> actual_encoding = ... # whatever >> def decode(s): >> return s.decode(actual_encoding) >> >> db = sqlite3.connect(...) >> db.text_factory = decode > > but now the error is : > > >>> rowset = cur.fetchall() > Traceback (most recent call last): > File "", line 1, in > rowset = cur.fetchall() > File "", line 2, in decode > return s.decode(enc) > File "/usr/lib/python2.6/encodings/utf_8.py", line 16, in decode > return codecs.utf_8_decode(input, errors, True) > UnicodeDecodeError: 'utf8' codec can't decode byte 0xb0 in position 33: > invalid start byte So you specified actual_encoding = "UTF-8" ? That's pointless because UTF-8 is the default, and you've already seen that failing. You can set db.text_factory = str but you'll probably run into problems with that later, e. g. when you try to display the retrieved data. So again, what data do you expect to find in the column(s) you can't decode properly? Peter From shearern at gmail.com Tue Dec 7 11:56:49 2010 From: shearern at gmail.com (Nate) Date: Tue, 7 Dec 2010 08:56:49 -0800 (PST) Subject: Task Engine Framework? References: Message-ID: <4a482ab5-2096-45d5-ae76-1af5ccc971da@c13g2000prc.googlegroups.com> On Dec 7, 8:32?am, Adam Tauno Williams wrote: > On Mon, 2010-12-06 at 15:11 -0800, Nate wrote: > > Hello, > > I'm in the process of developing a task engine / workflow module for > > my Python application and I'm wondering if anyone knows of existing > > code that could be used or adapted. ?Since I know that's far too > > generic a question, let me share my goals: > > 1) Support long running operations (think backing up millions of > > files) where: > > ? ?- The operation can be paused (application closed) and the > > operation resumed later. > > ? ?- Individual tasks can be chained, run in parallel, or looped over > > (the workflow part) > > We have something like that in OIE (OpenGroupware Integration Engine). > . ?These things tend to turn out > to be quite specific [and thus not generic]. ?But if you have any > questions feel free to ask. ?The focus in OIE was the ability to > describe processes in BPML and facilitate process management [creating, > queuing, parking (stopping for later resume) of business / ETL tasks. > Parts of the code aren't especially elegant but it does move a fairly > large amount of data every day. > > > > > > > > > 2) Would like to graph each defined operation (task A starts task B > > with parameters... ) for documenting algorithms in Software Design > > Document > > 3) Each individual task in the operation would a self-contained > > class. ?I'd imagine implementing its action by defining a doTask() > > method > > Hopefully that's clear. ?I just feel like someone must have already > > solved this elegantly. ?I greatly enjoy Python and I look forward to > > proving its use as a valuable language for a Masters student even > > though everyone thinks I should use C# :-). Thank you, I'll take a look at the project. At the very least, seeing someone else's solution would be helpful. I'm trying desperately hard to keep the code simple :-) -Nate From mauro.caceres at gmail.com Tue Dec 7 12:13:34 2010 From: mauro.caceres at gmail.com (Mauro Caceres) Date: Tue, 7 Dec 2010 14:13:34 -0300 Subject: Books recommendation In-Reply-To: References: Message-ID: > > > I am also interested to find where I can get Python modules from and how... > similar tools and sites with cpan and ppm for Perl. > > You should look at http://pypi.python.org/pypi, for modules. pip (http://pip.openplans.org/) is a tool used to install python modules. enjoy -- Mauro C?ceres -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomas.burdick at gmail.com Tue Dec 7 12:37:41 2010 From: thomas.burdick at gmail.com (Thomas Burdick) Date: Tue, 7 Dec 2010 11:37:41 -0600 Subject: select on multiprocessing Listener class Message-ID: The multiprocessing module has some wrappers for sockets and while the Client object is selectable the Listener is not, I'm wondering if that could be changed or if there's a way to do it already that I'm not seeing? -Tom From edicionsdigitals at gmail.com Tue Dec 7 12:48:17 2010 From: edicionsdigitals at gmail.com (edicionsdigitals.com edicions digitals xarxa social slu) Date: Tue, 7 Dec 2010 09:48:17 -0800 (PST) Subject: v = vte.Terminal() AttributeError: 'module' object has no attribute 'Terminal' References: Message-ID: Solved! A really dummy error: I've a vte.py file in the same folder, so import vte found this first than the needed! Thanks! (and sorry) Steve, On 7 Des, 17:34, "bruno.desthuilli... at gmail.com" wrote: > On 7 d?c, 12:05, Steve wrote: > > > Hi, > > > I try to run a terminal emulation using Python+Gtk+Vte. Before develop > > my own sources, i'm testing some examples like this ;http://www.eurion.net/python-snippets/snippet/Embed%20a%20VTE%20termi... > > > But when i try to run, i get this message error; > > > ? ? v = vte.Terminal() > > AttributeError: 'module' object has no attribute 'Terminal' > > Before any other thing, make sure the "vte" module you imported is the > expected one. Edit your script that way: > > # import vte > try: > ? ? import vte > except: > ? ? error = gtk.MessageDialog (None, gtk.DIALOG_MODAL, > gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, > ? ? ? ? 'You need to install python bindings for libvte') > ? ? error.run() > ? ? sys.exit (1) > else: > ? ? print "using wte module : %s" % vte > > and check the module path this prints to your stdout. From orasnita at gmail.com Tue Dec 7 12:49:54 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Tue, 7 Dec 2010 19:49:54 +0200 Subject: is py2exe still active ? References: <5f32249f-50d4-440e-9005-04f954572894@32g2000yqz.googlegroups.com> <89dd2092-d6e9-4d5c-b966-54df3f48f065@g19g2000yqg.googlegroups.com> Message-ID: <2DEA78DF996B485E8B52F3B29B1124A1@teddy> This packager is also nice. If someone cares, I've discovered a small bug in it. If Python is installed on another drive than C under Windows, the cxfreeze.bat file still calls Python on the drive C and it doesn't work until it is corrected. Octavian ----- Original Message ----- From: "Cbast" Newsgroups: comp.lang.python To: Sent: Tuesday, December 07, 2010 5:00 PM Subject: Re: is py2exe still active ? On Dec 7, 8:23 am, Anders Persson wrote: > Hi! > When a look att py2exe homepage it is not looking like mutch happen, > as a beginner i was thinking to start with Python 3, but i like to now > if py2exe will be for 3 too. > > Is any one have any info ? I don't have the answer about py2exe, but I'm using cxFreeze to create executables with Python 3.1, if it's what you're looking for. http://cx-freeze.sourceforge.net/ -- http://mail.python.org/mailman/listinfo/python-list From harijay at gmail.com Tue Dec 7 13:02:53 2010 From: harijay at gmail.com (harijay) Date: Tue, 7 Dec 2010 10:02:53 -0800 (PST) Subject: win32com pythonwin extensions part of stdlib? Message-ID: Hi I am using Python 2.6.5 on Windows. I wanted to start using the win32com extensions which I understand are "essentially part of the stdlib" ( quoted in http://tgolden.sc.sabren.com/python/win32_how_do_i.html) Since I didnt have the extensions as standard I went to sourceforge to get the module. However when I tried to do a distutils install of the python extensions for windows downloaded from sourceforge , I found out I need some proprietary components from Microsoft visual studio 7)."vcsvarsall.bat" needed. My question is : Can I use the win32com extensions on a licensed windows setup without having access to Visual Studio components. I did see some places where they suggested compiling with mingw32 , but the compilation didnt work. Any help in getting the module running would be greatly appreciated From python.list at tim.thechases.com Tue Dec 7 13:20:40 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 07 Dec 2010 12:20:40 -0600 Subject: Task Engine Framework? In-Reply-To: <4a482ab5-2096-45d5-ae76-1af5ccc971da@c13g2000prc.googlegroups.com> References: <4a482ab5-2096-45d5-ae76-1af5ccc971da@c13g2000prc.googlegroups.com> Message-ID: <4CFE7AF8.2080302@tim.thechases.com> On 12/07/2010 10:56 AM, Nate wrote: > On Dec 7, 8:32 am, Adam Tauno Williams wrote: >>> I'm in the process of developing a task engine / workflow module for >>> my Python application and I'm wondering if anyone knows of existing >>> code that could be used or adapted. Since I know that's far too >>> generic a question, let me share my goals: >>> 1) Support long running operations (think backing up millions of >>> files) where: >>> - The operation can be paused (application closed) and the >>> operation resumed later. >>> - Individual tasks can be chained, run in parallel, or looped over >>> (the workflow part) >> >> We have something like that in OIE (OpenGroupware Integration Engine). >> . > > I'll take a look at the project. At the very least, seeing someone > else's solution would be helpful. I'm trying desperately hard to keep > the code simple :-) You might also want to look at Celery[1] which may do some (if not all) of what you're looking for. -tkc [1] http://celeryproject.org From godson.g at gmail.com Tue Dec 7 13:25:32 2010 From: godson.g at gmail.com (Godson Gera) Date: Tue, 7 Dec 2010 23:55:32 +0530 Subject: win32com pythonwin extensions part of stdlib? In-Reply-To: References: Message-ID: Not sure what you are trying to do but you can get a standalone binaries from http://sourceforge.net/projects/pywin32/ which gets installed without any issues. If for some reason you are still having issues, you can try ActiveState Python which come bundled with pywin32 packages. On Tue, Dec 7, 2010 at 11:32 PM, harijay wrote: > Hi I am using Python 2.6.5 on Windows. > > I wanted to start using the win32com extensions which I understand are > "essentially part of the stdlib" ( quoted in > http://tgolden.sc.sabren.com/python/win32_how_do_i.html) > Since I didnt have the extensions as standard I went to sourceforge > to get the module. > > However when I tried to do a distutils install of the python > extensions for windows downloaded from sourceforge , I found out I > need some proprietary components from Microsoft visual studio > 7)."vcsvarsall.bat" needed. > > My question is : Can I use the win32com extensions on a licensed > windows setup without having access to Visual Studio components. > > I did see some places where they suggested compiling with mingw32 , > but the compilation didnt work. > > Any help in getting the module running would be greatly appreciated > -- > http://mail.python.org/mailman/listinfo/python-list > -- Python Consultant India -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Tue Dec 7 13:27:38 2010 From: ian.g.kelly at gmail.com (Ian) Date: Tue, 7 Dec 2010 10:27:38 -0800 (PST) Subject: win32com pythonwin extensions part of stdlib? References: Message-ID: On Dec 7, 11:02?am, harijay wrote: > Hi I am using Python 2.6.5 on Windows. > > I wanted to start using the win32com extensions which I understand are > "essentially part of the stdlib" ( quoted inhttp://tgolden.sc.sabren.com/python/win32_how_do_i.html) > Since I didnt have the extensions as standard ?I went to sourceforge > to get the module. > > However when I tried to do a distutils install of the python > extensions for windows downloaded from sourceforge , I found out I > need some proprietary components from Microsoft visual studio > 7)."vcsvarsall.bat" needed. > > My question is : Can I use the win32com extensions on a licensed > windows setup without having access to Visual Studio components. > > I did see some places where they suggested compiling with mingw32 , > but the compilation didnt work. > > Any help in getting the module running would be greatly appreciated There are pre-built binary distributions available on sourceforge. Why not just use one of those? From kee at kagi.com Tue Dec 7 14:00:35 2010 From: kee at kagi.com (Kee Nethery) Date: Tue, 7 Dec 2010 11:00:35 -0800 Subject: Books recommendation In-Reply-To: References: Message-ID: <237490BE-143B-4474-940E-48421488BEDC@kagi.com> On Dec 7, 2010, at 5:39 AM, Octavian Rasnita wrote: > Do you have, or can I find elsewhere a recommendation for books,tutorials and sites appropriate for beginners? I have found that Python for Dummies is the book I use the most. It has lots of examples that work and that I can build upon. The O'Reilly books talk about the language but are scarce on actual code. Kee Nethery From invalid at invalid.invalid Tue Dec 7 14:44:17 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 7 Dec 2010 19:44:17 +0000 (UTC) Subject: is py2exe still active ? References: <5f32249f-50d4-440e-9005-04f954572894@32g2000yqz.googlegroups.com> Message-ID: On 2010-12-07, Anders Persson wrote: > When a look att py2exe homepage it is not looking like mutch happen, Why do you say that? The homepage was update last month. If you click on "recent changes" the last wiki page edit was less than two weeks ago, and there ahve been 19 posts to four different threads on the mailing list so far this month. > as a beginner i was thinking to start with Python 3, but i like to > now if py2exe will be for 3 too. > > Is any one have any info ? Probably. https://lists.sourceforge.net/lists/listinfo/py2exe-users -- Grant Edwards grant.b.edwards Yow! Don't SANFORIZE me!! at gmail.com From harijay at gmail.com Tue Dec 7 15:14:26 2010 From: harijay at gmail.com (harijay) Date: Tue, 7 Dec 2010 12:14:26 -0800 (PST) Subject: win32com pythonwin extensions part of stdlib? References: Message-ID: <357d284b-ef2d-4404-a811-59f5f3a148df@o14g2000prn.googlegroups.com> Using the "binary" offered on sourceforge and calling "python setup.py install" Has the install asking for "vcsvarsall.bat" . So this does not seem to be a binary build On Dec 7, 1:27?pm, Ian wrote: > On Dec 7, 11:02?am, harijay wrote: > > > > > > > > > > > Hi I am using Python 2.6.5 on Windows. > > > I wanted to start using the win32com extensions which I understand are > > "essentially part of the stdlib" ( quoted inhttp://tgolden.sc.sabren.com/python/win32_how_do_i.html) > > Since I didnt have the extensions as standard ?I went to sourceforge > > to get the module. > > > However when I tried to do a distutils install of the python > > extensions for windows downloaded from sourceforge , I found out I > > need some proprietary components from Microsoft visual studio > > 7)."vcsvarsall.bat" needed. > > > My question is : Can I use the win32com extensions on a licensed > > windows setup without having access to Visual Studio components. > > > I did see some places where they suggested compiling with mingw32 , > > but the compilation didnt work. > > > Any help in getting the module running would be greatly appreciated > > There are pre-built binary distributions available on sourceforge. > Why not just use one of those? From mail at timgolden.me.uk Tue Dec 7 15:22:49 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 07 Dec 2010 20:22:49 +0000 Subject: win32com pythonwin extensions part of stdlib? In-Reply-To: <357d284b-ef2d-4404-a811-59f5f3a148df@o14g2000prn.googlegroups.com> References: <357d284b-ef2d-4404-a811-59f5f3a148df@o14g2000prn.googlegroups.com> Message-ID: <4CFE9799.9080106@timgolden.me.uk> You want something from here: http://sourceforge.net/projects/pywin32/files/pywin32/Build%20214/ Which one you need will depend on your architecture and the version of Python you're running TJG From python at mrabarnett.plus.com Tue Dec 7 15:42:11 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 07 Dec 2010 20:42:11 +0000 Subject: RCX using python serial help In-Reply-To: References: Message-ID: <4CFE9C23.2060703@mrabarnett.plus.com> On 06/12/2010 15:37, Astan Chee wrote: > Hi, > I've got a lego mindstorm RCX 1.0 (but firmware is 2.0) that uses one of > those old serial IR towers to control the microcontroller. I've had a > look around at python's serial documentation as well as the RCX's > documentation and I'm trying to write something to control the RCX > directly using python. Several examples from of doing this in python > include using lnp (i think) and that doesn't quite run well in windows. > I've had a look at the C++ code and some protocol documentation here: > http://www.generation5.org/content/2001/rob08.asp and converted it to > python. I've attached it at the end of the email. So now I've figured > out how to check for the battery level and it seems to work (I've tested > it on my RCX) but I'm confused with the other documentation (e.g. > http://graphics.stanford.edu/~kekoa/rcx/ ) about how to do this in > python or what this all means. I was wondering if anyone can help me > complete these? or maybe help me do it step-by-step? > Thanks for any help. > Below is the python code I've been working on: > import time > import serial > import struct > import binascii > def tcbin(x, y=8): > """ > This function returns the padded, two's complement representation > of x, in y-bits. > It is conventional for y to be 8, 16, 32 or 64, though y can have > any non-zero positive value. > """ > if x >= 0: > binstr = bin(x) > # pad with leading zeros > while len(binstr) < y + 2: > binstr = "0b0" + binstr[2:] > return binstr > return bin((2**y) + x) # x is negative > def bitcompliment(hex_code): > return hex(int(tcbin(~(ord(hex_code))),2)) > > def processOutput(raw_data,output): > outputStatus = True > pos = 0 > for i in range(3): > if raw_data[i] != output[i]: > outputStatus = False > pos+=1 > if outputStatus: > print "output OK" > else: > print "problem with output" > outputCompliment = True > while outputCompliment: > if hex(ord(output[pos])) == bitcompliment(output[pos+1]): > print "output compliment OK" > else: > print "problem with output compliment" > pos+=2 > if hex(ord(output[pos])) == '0x55' and hex(ord(output[pos+1])) > == '0xff' and hex(ord(output[pos+2])) == '0x0': > pos+=3 > outputCompliment = False > if hex(ord(output[pos])) == '0xcf' or hex(ord(output[pos])) == '0xc7': > #battery checker > pos+=2 > if hex(ord(output[pos])) == bitcompliment(output[pos+1]) and > hex(ord(output[pos+2])) == bitcompliment(output[pos+3]): > s = ((ord(output[pos+2]) * 256) + ord(output[pos])) / 1000.0 > print "Battery is at " + str(s) + " Volts" > else: > for i in range(len(output[pos:]),len(output),2): > print hex(ord(output[i])) > if i+1 < len(output): > if hex(ord(output[i])) == bitcompliment(output[i+1]): > print "message OK. contents: " + hex(ord(output[i])) > > # configure the serial connections (the parameters differs on the device > you are connecting to) > ser = serial.Serial( > port='COM1', > baudrate=2400, > parity=serial.PARITY_ODD, > stopbits=serial.STOPBITS_ONE, > bytesize=serial.EIGHTBITS > ) > raw_data = '\x55\xff\x00\x38\xc7\x38\xc7' > result = ser.write(raw_data) > out = '' > time.sleep(1) #pause for a second > while ser.inWaiting() > 0: > out+=ser.read(1) > processOutput(raw_data,out) > Here's my version of your code: import time import serial import struct import binascii # not needed! def tcbin(x, y=8): """ This function returns the padded, two's complement representation of x, in y-bits. It is conventional for y to be 8, 16, 32 or 64, though y can have any non-zero positive value. """ return "0b" + bin((2 ** y) + x)[-y : ] def byte_complement(hex_code): return (~ord(hex_code)) & 0xff def process_output(raw_data, output): output_status = raw_data[ : 3] == output[ : 3] if output_status: print "output OK" else: print "problem with output" pos = 3 output_complement = True while output_complement: if ord(output[pos]) == byte_complement(output[pos + 1]): print "output complement OK" else: print "problem with output complement" pos += 2 if ord(output[pos]) == 0x55 and ord(output[pos + 1]) == 0xff and ord(output[pos + 2]) == 0x00: pos += 3 output_complement = False if ord(output[pos]) == 0xcf or ord(output[pos]) == 0xc7: # battery checker pos += 2 if ord(output[pos]) == byte_complement(output[pos + 1]) and ord(output[pos + 2]) == byte_complement(output[pos + 3]): s = ((ord(output[pos + 2]) * 256) + ord(output[pos])) / 1000.0 print "Battery is at %s Volts" % s else: for i in range(len(output[pos : ]), len(output), 2): print hex(ord(output[i])) if i + 1 < len(output): if ord(output[i]) == byte_complement(output[i + 1]): print "message OK. contents: %s" % hex(ord(output[i])) # configure the serial connections (the parameters differs on the device you are connecting to) ser = serial.Serial( port='COM1', baudrate=2400, parity=serial.PARITY_ODD, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS ) raw_data = '\x55\xff\x00\x38\xc7\x38\xc7' result = ser.write(raw_data) out = '' time.sleep(1) # pause for a second while ser.inWaiting() > 0: out += ser.read(1) process_output(raw_data, out) From harijay at gmail.com Tue Dec 7 15:59:31 2010 From: harijay at gmail.com (harijay) Date: Tue, 7 Dec 2010 12:59:31 -0800 (PST) Subject: win32com pythonwin extensions part of stdlib? References: <357d284b-ef2d-4404-a811-59f5f3a148df@o14g2000prn.googlegroups.com> Message-ID: <6f9358ed-dd54-435f-aa65-0eab84dbf147@h17g2000pre.googlegroups.com> Thanks Ian for your reply. I downloaded the zip file linked by the "Download Binaries/View All files link" . All that gave me was a zip file which unpacked to the source and documentation implying I had to use distutils. If instead I looked at the Build 214 link on sourceforge which corresponds to the latest build ( same time stamp as the link labeled "Download Binaries / View all Files") There was an exe file corresponding to my python version. Which came with an installer that installed the binaries Thanks for your help I looked in the right place. Hari On Dec 7, 3:14?pm, harijay wrote: > Using the "binary" offered on sourceforge and calling > "python setup.py install" > > Has the install asking for "vcsvarsall.bat" . So this does not seem to > be a binary build > > On Dec 7, 1:27?pm, Ian wrote: > > > > > > > > > On Dec 7, 11:02?am, harijay wrote: > > > > Hi I am using Python 2.6.5 on Windows. > > > > I wanted to start using the win32com extensions which I understand are > > > "essentially part of the stdlib" ( quoted inhttp://tgolden.sc.sabren.com/python/win32_how_do_i.html) > > > Since I didnt have the extensions as standard ?I went to sourceforge > > > to get the module. > > > > However when I tried to do a distutils install of the python > > > extensions for windows downloaded from sourceforge , I found out I > > > need some proprietary components from Microsoft visual studio > > > 7)."vcsvarsall.bat" needed. > > > > My question is : Can I use the win32com extensions on a licensed > > > windows setup without having access to Visual Studio components. > > > > I did see some places where they suggested compiling with mingw32 , > > > but the compilation didnt work. > > > > Any help in getting the module running would be greatly appreciated > > > There are pre-built binary distributions available on sourceforge. > > Why not just use one of those? From harijay at gmail.com Tue Dec 7 16:01:52 2010 From: harijay at gmail.com (harijay) Date: Tue, 7 Dec 2010 13:01:52 -0800 (PST) Subject: win32com pythonwin extensions part of stdlib? References: <357d284b-ef2d-4404-a811-59f5f3a148df@o14g2000prn.googlegroups.com> Message-ID: Thanks Tim for your reply. I did get that build . Also thanks for the examples. Looking forward to using the module Hari On Dec 7, 3:22?pm, Tim Golden wrote: > You want something from here: > > ? ?http://sourceforge.net/projects/pywin32/files/pywin32/Build%20214/ > > Which one you need will depend on your architecture > and the version of Python you're running > > TJG From utabintarbo at gmail.com Tue Dec 7 16:03:40 2010 From: utabintarbo at gmail.com (utabintarbo) Date: Tue, 7 Dec 2010 13:03:40 -0800 (PST) Subject: Python creates "locked" temp dir Message-ID: <0c30c818-f73b-4b09-b707-64ea457c757d@z26g2000prf.googlegroups.com> I am using tempfile.mkdtemp() to create a working directory on a remote *nix system through a Samba share. When I use this on a Windows box, it works, and I have full access to the created dir. When used on a Linux box (through the same Samba share), the created directory shows as "locked", and I am unable to access. Obviously, I need access. Any clues? Background/environment: Python 2.6.5 on Red Hat Enterprise Linux 5.3 TIA From shearichard at gmail.com Tue Dec 7 16:45:23 2010 From: shearichard at gmail.com (shearichard) Date: Tue, 7 Dec 2010 13:45:23 -0800 (PST) Subject: find memory leaks in running program References: Message-ID: <6b8a92f4-5de9-47e1-90ce-a79d994e0664@y19g2000prb.googlegroups.com> On Dec 8, 5:51?am, Marco Hornung wrote: > Hey, > > ------------------------------------------------------------------------------------------ > questions > ------------------------------------------------------------------------------------------ > 1. What are the best tools to analyze pythons memory stack, while it is running? > 2. Is there a possibility to analyze the memory stack of a program with external programs? (without to change the source code - I am only interested in the object size) > 3. Can I sort of "break" into the memory to see what objects consume how much memory? > > ------------------------------------------------------------------------------------------ > my scenario > ------------------------------------------------------------------------------------------ > I have to debug a multithreaded server, which is written in the twisted-framework. One of the processes has some sort of memory leak - After one of our jobs is finished the main process has still over 59% of the entire memory allocated. I will probably have to recreate our scenario and equip our server with some memory sensors - but ?it takes 12h to reproduce the scenario and I will have to change the source code(at least I do not know of other options). > Therefore I am looking for quicker possibilities to look into what causes our memory leak. > > Regards, > Marco I haven't used this myself but sometime ago I bookmarked yappi which may go some way towards helping you ... http://code.google.com/p/yappi/ http://code.google.com/p/yappi/wiki/apiyappi ... also sometime ago I was at presentation (Pycon NZ 2009) where the twisted.manhole functionality was used to hook a remote console up to a running twisted task and examine the interior of the target task. Can't remember the details but someone else here may be able to help. This touches upon the idea ... http://stackoverflow.com/questions/1721699/is-there-any-remote-console-for-twisted-server ... and in turn references Heapy which I'd forgotten about but may also be useful in your circs ... http://guppy-pe.sourceforge.net/ regards Richard. From horos11 at gmail.com Tue Dec 7 17:21:18 2010 From: horos11 at gmail.com (Edward Peschko) Date: Tue, 7 Dec 2010 14:21:18 -0800 Subject: using trace to do 'in place' evaluation of variables Message-ID: All, I've been using the trace module for python (as per http://www.dalkescientific.com/writings/diary/archive/2005/04/20/tracing_python_code.html), and would very much like to have a feature there that I've implemented for perl already. Namely, I would like output in the format as described on that page, but with the ability to have the running window partitioned into 2, like: /tmp/file.py:13: yy = 12 | = 12 /tmp/file.py14: xx = yy | = 12 where the window on the left shows the actual source code, and the right shows how that code eval's (ie: how the scalars resolve based on their current scope.) Is this possible given the current trace functionality? I've found it an *incredible* time saver with my perl code, especially for hard to find data bugs - to debug I simply look for a pattern which is associated with a given bug, and then backtrack that pattern to where it first appeared in my code. Also, is there a good archive searcher for the python-list archives? Short of doing a complete download of http://mail.python.org/pipermail/python-list/ and indexing it, I don't see how I can do a decent pattern search on previous archive entries.. Thanks much, Ed From mmanns at gmx.net Tue Dec 7 17:47:16 2010 From: mmanns at gmx.net (Martin Manns) Date: Tue, 7 Dec 2010 23:47:16 +0100 Subject: Collision of rotated rectangles without pygame References: <20101205234936.39dc1a4e@Knock> <4cfdf605$0$1639$742ec2ed@news.sonic.net> Message-ID: <20101207234716.4587ef12@Knock> On Tue, 07 Dec 2010 00:53:27 -0800 John Nagle wrote: > On 12/5/2010 2:49 PM, Martin Manns wrote: > Probably because you seem to be trying to compute the intersection > point for coincident lines, which is not well-defined. I found the problem: pygame returns one pixel more for the right border than wx. > Incidentally, a dictionary lookup in Python is far more expensive > than computing trig functions. If you need to speed this up > for large numbers of rectangles, there are algorithms that are > several orders of magnitude faster. Realistically, though, > this is the kind of problem that runs slow in CPython. This was taken from the vizier code. I fixed it. > This is why you don't write your own collision library. > (I once did, for 3D, but that was in 1996, when it was > cutting-edge technology.) Is there a pure Python collision library other than vizier? Martin From steve at holdenweb.com Tue Dec 7 17:56:46 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 07 Dec 2010 23:56:46 +0100 Subject: is py2exe still active ? In-Reply-To: <2DEA78DF996B485E8B52F3B29B1124A1@teddy> References: <5f32249f-50d4-440e-9005-04f954572894@32g2000yqz.googlegroups.com> <89dd2092-d6e9-4d5c-b966-54df3f48f065@g19g2000yqg.googlegroups.com> <2DEA78DF996B485E8B52F3B29B1124A1@teddy> Message-ID: <4CFEBBAE.2060400@holdenweb.com> Octavian: It's great that you want to let people know about bugs. Put yourself in the position of the package maintainer, however. She or he doesn't spend all day working on cxFreeze, and probably doesn't even do a Google search on cxFreeze very often. So they are unlikely to find out about this problem form your well-intentioned note. It's just possible nobody does care, as I can't find a link to an issue tracker - the best I could advise in this case would be to join the mailing list by visiting https://lists.sourceforge.net/lists/listinfo/cx-freeze-users regards Steve On 12/7/2010 6:49 PM, Octavian Rasnita wrote: > This packager is also nice. > > If someone cares, I've discovered a small bug in it. > If Python is installed on another drive than C under Windows, the cxfreeze.bat file still calls Python on the drive C and it doesn't work until it is corrected. > > Octavian > > ----- Original Message ----- > From: "Cbast" > Newsgroups: comp.lang.python > To: > Sent: Tuesday, December 07, 2010 5:00 PM > Subject: Re: is py2exe still active ? > > > On Dec 7, 8:23 am, Anders Persson wrote: >> Hi! >> When a look att py2exe homepage it is not looking like mutch happen, >> as a beginner i was thinking to start with Python 3, but i like to now >> if py2exe will be for 3 too. >> >> Is any one have any info ? > > I don't have the answer about py2exe, but I'm using cxFreeze to create > executables with Python 3.1, if it's what you're looking for. > > http://cx-freeze.sourceforge.net/ -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Tue Dec 7 17:56:46 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 07 Dec 2010 23:56:46 +0100 Subject: is py2exe still active ? In-Reply-To: <2DEA78DF996B485E8B52F3B29B1124A1@teddy> References: <5f32249f-50d4-440e-9005-04f954572894@32g2000yqz.googlegroups.com> <89dd2092-d6e9-4d5c-b966-54df3f48f065@g19g2000yqg.googlegroups.com> <2DEA78DF996B485E8B52F3B29B1124A1@teddy> Message-ID: <4CFEBBAE.2060400@holdenweb.com> Octavian: It's great that you want to let people know about bugs. Put yourself in the position of the package maintainer, however. She or he doesn't spend all day working on cxFreeze, and probably doesn't even do a Google search on cxFreeze very often. So they are unlikely to find out about this problem form your well-intentioned note. It's just possible nobody does care, as I can't find a link to an issue tracker - the best I could advise in this case would be to join the mailing list by visiting https://lists.sourceforge.net/lists/listinfo/cx-freeze-users regards Steve On 12/7/2010 6:49 PM, Octavian Rasnita wrote: > This packager is also nice. > > If someone cares, I've discovered a small bug in it. > If Python is installed on another drive than C under Windows, the cxfreeze.bat file still calls Python on the drive C and it doesn't work until it is corrected. > > Octavian > > ----- Original Message ----- > From: "Cbast" > Newsgroups: comp.lang.python > To: > Sent: Tuesday, December 07, 2010 5:00 PM > Subject: Re: is py2exe still active ? > > > On Dec 7, 8:23 am, Anders Persson wrote: >> Hi! >> When a look att py2exe homepage it is not looking like mutch happen, >> as a beginner i was thinking to start with Python 3, but i like to now >> if py2exe will be for 3 too. >> >> Is any one have any info ? > > I don't have the answer about py2exe, but I'm using cxFreeze to create > executables with Python 3.1, if it's what you're looking for. > > http://cx-freeze.sourceforge.net/ -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From nagle at animats.com Tue Dec 7 18:08:23 2010 From: nagle at animats.com (John Nagle) Date: Tue, 07 Dec 2010 15:08:23 -0800 Subject: Comparisons of incompatible types In-Reply-To: <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4cfebe65$0$1590$742ec2ed@news.sonic.net> On 12/6/2010 4:17 PM, Steven D'Aprano wrote: > On Mon, 06 Dec 2010 08:59:12 -0800, TomF wrote: > >> I'm aggravated by this behavior in python: >> >> x = "4" >> print x< 7 # prints False > >> I can't imagine why this design decision was made. > > You've never needed to deal with an heterogeneous list? > > data = ["Fred", "Barney", 2, 1, None] > data.sort() > > Nevertheless, I agree that in hindsight, the ability to sort such lists > is not as important as the consistency of comparisons. If you're thinking hard about this, I recommend viewing Alexander Stepanov's talk at Stanford last month: http://www.stanford.edu/class/ee380/Abstracts/101103.html He makes the point that, for generic programs to work right, the basic operations must have certain well-defined semantics. Then the same algorithms will work right across a wide variety of objects. This is consistent with Python's "duck typing", but inconsistent with the current semantics of some operators. For example, "+" as concatenation makes "+" non-commutative. In other words, a + b is not always equal to b + a which is not good. Important properties to have across all types: a + b == b + a Exactly one of a > b a = b a < b is true, or an type exception must be raised. The basic Boolean identities (a or b) == (b or a) not (a or b) == (not a) and (not b) not (not a) == a should all hold, or an type exception should be raised. With Python accepting both "True" and "1" as sort of equivalent, there are cases where those don't hold. John Nagle From steve at holdenweb.com Tue Dec 7 18:11:09 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 08 Dec 2010 00:11:09 +0100 Subject: Collision of rotated rectangles without pygame In-Reply-To: <4cfdf605$0$1639$742ec2ed@news.sonic.net> References: <20101205234936.39dc1a4e@Knock> <4cfdf605$0$1639$742ec2ed@news.sonic.net> Message-ID: On 12/7/2010 9:53 AM, John Nagle wrote: > On 12/5/2010 2:49 PM, Martin Manns wrote: >> Hello, >> >> I am looking for a Python library for 2D collision checks of rotated >> rectangles. Currently, I have found vizier 0.5b that is based on pygame. >> >> Since I do not want to add a pygame dependency to my app, I replaced the >> pygame.rect.Rect by a wxPython wx.Rect (see code below). >> >> However, collision checks do not work correctly, i. e. identical rects >> are not found to be colliding: > > Probably because you seem to be trying to compute the intersection > point for coincident lines, which is not well-defined. > > I don't have time to debug this, but you might want to get some > basic books on game programming and graphics. > > Incidentally, a dictionary lookup in Python is far more expensive > than computing trig functions. If you need to speed this up > for large numbers of rectangles, there are algorithms that are > several orders of magnitude faster. Realistically, though, > this is the kind of problem that runs slow in CPython. > That appears to be (from a rather limited investigation) a wild-assed assertion unjustified by anything other than preconceptions. With d as a dict containing 100 random numbers from (0,1) I see this: >>> def fm(): ... x = random.random() ... return math.sin(x) ... >>> def fd(): ... x = random.random() ... return x in d ... >>> timeit.timeit(fm) 0.58099985122680664 >>> timeit.timeit(fd) 0.55200004577636719 >>> Of course it's possible that the random number generation is dominating, but I'd still like to see some proof. I know for a fact that dict lookup has been extensively optimized, and while I am no longer involved in numerical computing it seems to me there's still a lot to do to compute a sin unless your CPU will do it for you. regards Steve > This is why you don't write your own collision library. > (I once did, for 3D, but that was in 1996, when it was > cutting-edge technology.) > > John Nagle -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From pavlovevidence at gmail.com Tue Dec 7 18:20:01 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 7 Dec 2010 15:20:01 -0800 (PST) Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Dec 6, 4:17?pm, Steven D'Aprano wrote: > On Mon, 06 Dec 2010 08:59:12 -0800, TomF wrote: > > I'm aggravated by this behavior in python: > > > x = "4" > > print x < 7 ? ?# prints False > > I can't imagine why this design decision was made. > > You've never needed to deal with an heterogeneous list? > > data = ["Fred", "Barney", 2, 1, None] > data.sort() Not once, ever. > Nevertheless, I agree that in hindsight, the ability to sort such lists > is not as important as the consistency of comparisons. I think that feeling the need to sort non-homogenous lists is indictative of bad design. If the order of the items doesn't matter, then there must be some small bit of homogeneity to exploit to use as a sort criterion. In that case you should use key= parameter or DSU. Carl Banks From pavlovevidence at gmail.com Tue Dec 7 18:31:53 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 7 Dec 2010 15:31:53 -0800 (PST) Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <4cfebe65$0$1590$742ec2ed@news.sonic.net> Message-ID: On Dec 7, 3:08?pm, John Nagle wrote: > The basic Boolean identities > > ? ? ? ? (a or b) == (b or a) > ? ? ? ? not (a or b) == (not a) and (not b) > ? ? ? ? not (not a) == a > > should all hold, or an type exception should be raised. > With Python accepting both "True" and "1" as sort of > equivalent, there are cases where those don't hold. For better or worse (and I say worse, but YMMV) "and" and "or" are not boolean operators in Python but special-form expressions that resemble boolean semantics in some instances, but not (as you mention above) in others. Likewise, the comparison operators <, >, >=, and <= aren't well- ordered; sets use these operators to indicate topological ordering. IMO having the operators adhere to defined properties would be a good thing. It would improve code reusability since the operators could be expected to act in consistent ways, but Python isn't that language. So you might as well use the operators for whatever seems like it works, + for concatenation, > for superset, and so on. Carl Banks From python at mrabarnett.plus.com Tue Dec 7 18:46:51 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 07 Dec 2010 23:46:51 +0000 Subject: RCX using python serial help In-Reply-To: References: Message-ID: <4CFEC76B.9080503@mrabarnett.plus.com> On 06/12/2010 15:37, Astan Chee wrote: > Hi, > I've got a lego mindstorm RCX 1.0 (but firmware is 2.0) that uses one of > those old serial IR towers to control the microcontroller. I've had a > look around at python's serial documentation as well as the RCX's > documentation and I'm trying to write something to control the RCX > directly using python. Several examples from of doing this in python > include using lnp (i think) and that doesn't quite run well in windows. > I've had a look at the C++ code and some protocol documentation here: > http://www.generation5.org/content/2001/rob08.asp and converted it to > python. I've attached it at the end of the email. So now I've figured > out how to check for the battery level and it seems to work (I've tested > it on my RCX) but I'm confused with the other documentation (e.g. > http://graphics.stanford.edu/~kekoa/rcx/ ) about how to do this in > python or what this all means. I was wondering if anyone can help me > complete these? or maybe help me do it step-by-step? > Thanks for any help. [snip] Here's a brief summary of the protocol: A command or request to the microcontroller is a packet consisting of a header, an opcode, arguments, and a checksum. The header used in the documentation is 0x55, 0xFF, 0x00. The opcode is 1 byte, followed by its one's complement. The argument is 0 or more bytes, each followed by its one's complement. The checksum is the sum of the opcode and the arguments, modulo 256, followed by its one's complement. A reply from the microcontroller is also a packet consisting of a header, an opcode, arguments, and a checksum. The header is the same as the original command or request. The opcode is the one's complement of the original opcode, followed by its one's complement (ie, the original opcode). The argument is 0 or more bytes, each followed by its one's complement. The checksum is the sum of the opcode and the arguments, modulo 256, followed by its one's complement. The microcontroller will ignore a packet whose opcode is the same as the previous one; this is to prevent unintended duplicates due to communication errors. Each opcode has 2 alternatives, one with bit 3 clear and the other with bit 3 set (bitwise-ored with 0x08), so if you do want to send a command or request with the same opcode as the previous packet you can just use the alternative form. From steve at holdenweb.com Tue Dec 7 18:47:37 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 08 Dec 2010 00:47:37 +0100 Subject: Perceived inconsistency in py3k documentation In-Reply-To: <20101206200017.0c5fc63f@pitrou.net> References: <724b26b4-8233-4d57-b76f-cd781cf0cd03@z17g2000prz.googlegroups.com> <20101206200017.0c5fc63f@pitrou.net> Message-ID: <4CFEC799.50102@holdenweb.com> On 12/6/2010 8:00 PM, Antoine Pitrou wrote: > On Sun, 05 Dec 2010 14:47:38 -0500 > Terry Reedy wrote: >> On 12/5/2010 3:31 AM, Greg wrote: >> >> For future reference, >> >>> 1) At http://docs.python.org/py3k/reference/datamodel.html: >>> 2) At http://docs.python.org/py3k/library/stdtypes.html: >> >> do not work because of the trailing :s, at least not with FireFox. > > Work fine here. The problem isn't Firefox, it is your e-mail or news > client. > > Antoine. > > In my case also the links don't work, because my newsreader (Thunderbird) makes the assumption that the colons are part of the URLs. This behavior is common enough that people need to be aware of it. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Tue Dec 7 18:47:37 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 08 Dec 2010 00:47:37 +0100 Subject: Perceived inconsistency in py3k documentation In-Reply-To: <20101206200017.0c5fc63f@pitrou.net> References: <724b26b4-8233-4d57-b76f-cd781cf0cd03@z17g2000prz.googlegroups.com> <20101206200017.0c5fc63f@pitrou.net> Message-ID: <4CFEC799.50102@holdenweb.com> On 12/6/2010 8:00 PM, Antoine Pitrou wrote: > On Sun, 05 Dec 2010 14:47:38 -0500 > Terry Reedy wrote: >> On 12/5/2010 3:31 AM, Greg wrote: >> >> For future reference, >> >>> 1) At http://docs.python.org/py3k/reference/datamodel.html: >>> 2) At http://docs.python.org/py3k/library/stdtypes.html: >> >> do not work because of the trailing :s, at least not with FireFox. > > Work fine here. The problem isn't Firefox, it is your e-mail or news > client. > > Antoine. > > In my case also the links don't work, because my newsreader (Thunderbird) makes the assumption that the colons are part of the URLs. This behavior is common enough that people need to be aware of it. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Tue Dec 7 18:56:29 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 08 Dec 2010 00:56:29 +0100 Subject: Exception handling in Python 3.x In-Reply-To: <4cfdbf06$0$1629$742ec2ed@news.sonic.net> References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> <4cfd4d5a$0$1662$742ec2ed@news.sonic.net> <878w02leut.fsf.mdw@metalzone.distorted.org.uk> <4cfdbf06$0$1629$742ec2ed@news.sonic.net> Message-ID: On 12/7/2010 5:58 AM, John Nagle wrote: > PEP 255, like too much Python literature, doesn't distinguish clearly > between the language definition and implementation detail. It says > "The mechanics of StopIteration are low-level details, much like the > mechanics of IndexError in Python 2.1". Applications shouldn't be > explicitly using StopIteration. > So you don't think that we should rely on iterables with no __iter__() method to raise IndexError to terminate iterations when their __getitem__() is called with an invalid index? The IndexError mechanism was, to the best of my less-than-complete knowledge, used by all pre-2.2 implementations. The quoted paragraph appears to be intended to reassure the applications programmer that there is no normal need to handle StopIteration specially - just as there was no need to handle IndexError specially. > IronPython doesn't do StopIteration the same way CPython does. > > http://ironpython.codeplex.com/wikipage?title=IPy1.0.xCPyDifferences > Perhaps not, but the only difference is what happens on repeated calls to next() after the iterator is exhausted. The iterator still terminates by raising a StopIteration error. I have no idea what Shed Skin does, but to the extent that iterators don't raise StopIteration on exhaustion I'd say it is in error. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Tue Dec 7 18:58:06 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 08 Dec 2010 00:58:06 +0100 Subject: Exception handling in Python 3.x In-Reply-To: <4CFD845E.90007@mrabarnett.plus.com> References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> <7xmxoi8v0b.fsf@ruckus.brouhaha.com> <4cfd7e6a$0$29993$c3e8da3$5496439d@news.astraweb.com> <4CFD845E.90007@mrabarnett.plus.com> Message-ID: <4CFECA0E.4050105@holdenweb.com> On 12/7/2010 1:48 AM, MRAB wrote: > Perhaps Python could use Guido's time machine to check whether the > sequence will yield another object in the future. :-) Since there's only one time machine that would effectively be a lock across all Python interpreters. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Tue Dec 7 18:58:06 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 08 Dec 2010 00:58:06 +0100 Subject: Exception handling in Python 3.x In-Reply-To: <4CFD845E.90007@mrabarnett.plus.com> References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> <7xmxoi8v0b.fsf@ruckus.brouhaha.com> <4cfd7e6a$0$29993$c3e8da3$5496439d@news.astraweb.com> <4CFD845E.90007@mrabarnett.plus.com> Message-ID: <4CFECA0E.4050105@holdenweb.com> On 12/7/2010 1:48 AM, MRAB wrote: > Perhaps Python could use Guido's time machine to check whether the > sequence will yield another object in the future. :-) Since there's only one time machine that would effectively be a lock across all Python interpreters. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From mdw at distorted.org.uk Tue Dec 7 18:59:54 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 07 Dec 2010 23:59:54 +0000 Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <4cfebe65$0$1590$742ec2ed@news.sonic.net> Message-ID: <87ipz5jfr9.fsf.mdw@metalzone.distorted.org.uk> John Nagle writes: [Stepanov] > makes the point that, for generic programs to work right, the basic > operations must have certain well-defined semantics. Then the same > algorithms will work right across a wide variety of objects. > > This is consistent with Python's "duck typing", but inconsistent with > the current semantics of some operators. This isn't a disaster. You should check that the arguments define the necessary operations and obey the necessary axioms. Python is already dynamically typed: this kind of proof-obligation is already endemic in Python programming, so you've not lost anything significant. > For example, "+" as concatenation makes "+" non-commutative. In other > words, > > a + b > > is not always equal to > > b + a > > which is not good. I think I probably agree with this. Concatenation yields a nonabelian monoid (usually with identity); `+' is pretty much universally an abelian group operator (exception: natural numbers, where it's used in an abelian monoid which extends to a group in a relatively obvious way). But then we'd need another operator symbol for concatenation. Nonnegative integers act on strings properly, but the action doesn't distribute over concatenation, which is also a shame. i.e., n*(a + b) != n*a + n*b But it's a familiar notation, by no means peculiar to Python, and changing it would be difficult. > Exactly one of > > a > b > a = b > a < b > > is true, or an type exception must be raised. This will get the numerical people screaming. Non-signalling NaNs are useful, and they don't obey these axioms. I think, more generally, that requiring a full total order (rather than either a preorder or a partial order) is unnecessarily proscriptive. Sorting only requires a preorder, for example, i.e., { (a, b) | a <= b <= a } is an equivalence relation, and the preorder naturally induces a total order on the equivalence classes. Topological sorting requires only a partial order, and makes good use of the notation. As an example, sets use `<=' to denote subsetness, which is well known to be a partial order. (I presume you weren't going to deny a <= b iff a < b or a == b or a < b iff b > a because that really would be bad.) > The basic Boolean identities > > (a or b) == (b or a) > not (a or b) == (not a) and (not b) > not (not a) == a > > should all hold, or an type exception should be raised. The first of these contradicts the axiom x => x or _|_ == x which is probably more useful. The last can't usefully be true since `not' is lossy. But I think that, for all values a, b, not (a or b) == not (b or a) == (not a) and (not b) not (not (not a)) == not a which is probably good enough. (The application of `not' applies a boolean coercion, which canonifies adequately.) -- [mdw] From mdw at distorted.org.uk Tue Dec 7 19:09:17 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 08 Dec 2010 00:09:17 +0000 Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87ei9tjfbm.fsf.mdw@metalzone.distorted.org.uk> Carl Banks writes: > I think that feeling the need to sort non-homogenous lists is > indictative of bad design. Here's a reason you might want to. You're given an object, and you want to compute a hash of it. (Maybe you want to see whether someone else's object is the same as yours, but don't want to disclose the actual object, say.) To hash it, you'll need to serialize it somehow. But here's a problem: objects like dictionaries and sets don't impose an ordering on their elements. For example, the set { 1, 'two' } is the same as the set { 'two', 1 } -- but iterating the two might well yield the elements in a different order. (The internal details of a hash table tend to reflect the history of operations on the hash table as well as its current contents.) The obvious answer is to apply a canonical ordering to unordered objects like sets and dictionaries. A set can be serialized with its elements in ascending order; a dictionary can be serialized as key/value pairs with the keys in ascending order. But to do this, you need an (arbitrary, total) order on all objects which might be set elements or dictionary keys. The order also needs to be dependent only on the objects' serializable values, and not on any incidental facts such as memory addresses or whatever. -- [mdw] From ben+python at benfinney.id.au Tue Dec 7 19:58:03 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 08 Dec 2010 11:58:03 +1100 Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <871v5t13ok.fsf@benfinney.id.au> Carl Banks writes: > On Dec 6, 4:17?pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: > > Nevertheless, I agree that in hindsight, the ability to sort such > > lists is not as important as the consistency of comparisons. > > I think that feeling the need to sort non-homogenous lists is > indictative of bad design. It can also be indicative of code written for a Python that doesn't have sets. Comparing two list objects to see whether they have the same items in any sequence can be done with:: set(foolist) == set(barlist) but, if there is no ?set? type, it's fine to write:: sorted(foolist) == sorted(barlist) So there's no design error in wanting heterogenerous sequences to sort; it can be quite Pythonic (until the advent of the ?set? type). And, of course, that code needs to continue to work in Python 2.x; hence, the comparison of incompatible types cannot be fixed without breaking backward compatibility. Hence it's not fixed until Python 3.x. -- \ ?All opinions are not equal. Some are a very great deal more | `\ robust, sophisticated and well supported in logic and argument | _o__) than others.? ?Douglas Adams | Ben Finney From no.email at nospam.invalid Tue Dec 7 20:04:28 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 07 Dec 2010 17:04:28 -0800 Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <871v5t13ok.fsf@benfinney.id.au> Message-ID: <7xpqtdrs6b.fsf@ruckus.brouhaha.com> Ben Finney writes: > but, if there is no ?set? type, it's fine to write:: > sorted(foolist) == sorted(barlist) what about dictionaries? From ben+python at benfinney.id.au Tue Dec 7 20:11:33 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 08 Dec 2010 12:11:33 +1100 Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <871v5t13ok.fsf@benfinney.id.au> <7xpqtdrs6b.fsf@ruckus.brouhaha.com> Message-ID: <87wrnlysoq.fsf@benfinney.id.au> Paul Rubin writes: > Ben Finney writes: > > but, if there is no ?set? type, it's fine to write:: > > sorted(foolist) == sorted(barlist) > > what about dictionaries? Creating a needless dict for each list would make the code even less clear, I'd think. (We're talking here about design, which is why clarity of communicating semantic intent is a concern.) Of course, the ?set? type is an even clearer way of communicating the intent; so, the above doesn't need to work in Python 3, which can break code written before the advent of the ?set? type. -- \ ?But Marge, what if we chose the wrong religion? Each week we | `\ just make God madder and madder.? ?Homer, _The Simpsons_ | _o__) | Ben Finney From bc at freeuk.com Tue Dec 7 20:24:48 2010 From: bc at freeuk.com (BartC) Date: Wed, 8 Dec 2010 01:24:48 -0000 Subject: Comparisons of incompatible types In-Reply-To: References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: "Carl Banks" wrote in message news:bf4be9a7-a079-4454-9969-60e9be305a03 at k14g2000pre.googlegroups.com... > On Dec 6, 4:17 pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> On Mon, 06 Dec 2010 08:59:12 -0800, TomF wrote: >> > I'm aggravated by this behavior in python: >> >> > x = "4" >> > print x < 7 # prints False >> > I can't imagine why this design decision was made. >> >> You've never needed to deal with an heterogeneous list? >> >> data = ["Fred", "Barney", 2, 1, None] >> data.sort() > > Not once, ever. > > >> Nevertheless, I agree that in hindsight, the ability to sort such lists >> is not as important as the consistency of comparisons. > > I think that feeling the need to sort non-homogenous lists is > indictative of bad design. Using a simple "<" comparison, perhaps. But can't a list be sorted by other criteria? For example, by comparing the string representations of each element. So some sorts will make sense, and others (such as "<" or ">") won't. -- Bartc From horos11 at gmail.com Tue Dec 7 20:49:59 2010 From: horos11 at gmail.com (Edward Peschko) Date: Tue, 7 Dec 2010 17:49:59 -0800 Subject: completely implicit interpolation based on a frame object Message-ID: All, Ok, it looks like in order to implement a tracer that does interpolation, I'm going to have to hack around with frames. Perl's interpolation is fairly straightforward, to do interpolation of $a == 1 all you need to do is put quotes around "$a == 1" to have $a evaluated. So, I'd like to do the same thing with python. It looks like I can do the same thing with frames, ie: interpolate_frame(frame, "if not wx.Platform == '__WXMAC' ") would interpolate wx based off of the frame that you passed to interpolate_frame, because wx is in the f_locals or f_globals dictionary. Hence, this would become: loc_wx = _first_defined(frame.f_locals["wx"], frame.f_globals["wx"]) return "if not ", loc_wx.Platform , " == \"__WXMAC\"" which would then do the interpolation. I guess my question is - has something like this been released? I see some close hits, namely Evan Forsmark's http://www.evanfosmark.com/2008/06/string-interpolation-in-python/ but I don't see anything exact, and getting this right would be fairly tricky, so I was hoping for canned solution. Any ideas would be great on this, including pitfalls that people see in implementing it. Ed From lanyjie at yahoo.com Tue Dec 7 21:23:10 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Tue, 7 Dec 2010 18:23:10 -0800 (PST) Subject: group 0 in the re module Message-ID: <194828.16515.qm@web54205.mail.re2.yahoo.com> Hi, According to the doc, group(0) is the entire match. >>> m = re.match(r"(\w+) (\w+)", "Isaac Newton, physicist") >>> m.group(0) # The entire match 'Isaac Newton' But if you do this: >>> import re >>> re.sub(r'(\d{3})(\d{3})', r'\0 to \1-\2', '757234') '\x00 to 757-234' where I expected '757234 to 757-234' Then I found that in python re '\0' is considered an octal number. So, is there anyway to refer to the entire match by an escaped notation? Thanks, Yingjie From tobias.koeck at gmail.com Tue Dec 7 21:36:25 2010 From: tobias.koeck at gmail.com (joblack) Date: Tue, 7 Dec 2010 18:36:25 -0800 (PST) Subject: convert assembly data (double words and bytes) in two tupple Message-ID: <1d2585a4-a023-4676-8743-a4998eacb41f@c17g2000prm.googlegroups.com> I have two assembly data txt files, one has the structure: 0E1459D1Fh, 0AB58FAAEh, 4303E35Bh, 55FA3020h, 0E66D76ADh, 0EF434544h, ... and the other has the structure: 53h, 6, 6Bh, 0D4h, 40h, 35h, 0B5h, 33h, 0AFh, 30h, 0B3h, 66h, ... (I removed the dd and db with awk) Now I want both of them in a tupple (like map1 = ( ... ) and map2 = ( ...) in my source code so I can index them.. Any idea how to give python a hint that the h at the end of the number means it's a hex number? Or do I have to torture myself with regex to get it right? From python at mrabarnett.plus.com Tue Dec 7 21:45:30 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 08 Dec 2010 02:45:30 +0000 Subject: group 0 in the re module In-Reply-To: <194828.16515.qm@web54205.mail.re2.yahoo.com> References: <194828.16515.qm@web54205.mail.re2.yahoo.com> Message-ID: <4CFEF14A.4080004@mrabarnett.plus.com> On 08/12/2010 02:23, Yingjie Lan wrote: > Hi, > > According to the doc, group(0) is the entire match. > >>>> m = re.match(r"(\w+) (\w+)", "Isaac Newton, physicist") >>>> m.group(0) # The entire match 'Isaac Newton' > > But if you do this: >>>> import re >>>> re.sub(r'(\d{3})(\d{3})', r'\0 to \1-\2', '757234') > '\x00 to 757-234' > > where I expected > '757234 to 757-234' > > Then I found that in python re '\0' is considered an octal number. > So, is there anyway to refer to the entire match by an escaped > notation? > Use \g<0>. This notation works in the replacement template for both named and numbered groups: >>> re.sub(r'(\d{3})(\d{3})', r'\g<0> to \g<1>-\g<2>', '757234') '757234 to 757-234' >>> re.sub(r'(?P\d{3})(?P\d{3})', r'\g<0> to \g-\g', '757234') '757234 to 757-234' From clp2 at rebertia.com Tue Dec 7 21:46:57 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 7 Dec 2010 18:46:57 -0800 Subject: convert assembly data (double words and bytes) in two tupple In-Reply-To: <1d2585a4-a023-4676-8743-a4998eacb41f@c17g2000prm.googlegroups.com> References: <1d2585a4-a023-4676-8743-a4998eacb41f@c17g2000prm.googlegroups.com> Message-ID: On Tue, Dec 7, 2010 at 6:36 PM, joblack wrote: > I have two assembly data txt files, one has the structure: > > 0E1459D1Fh, 0AB58FAAEh, 4303E35Bh, 55FA3020h, 0E66D76ADh, > 0EF434544h, ... > > and the other has the structure: > > 53h, 6, 6Bh, 0D4h, 40h, 35h, 0B5h, 33h, 0AFh, 30h, 0B3h, > 66h, ... > > (I removed the dd and db with awk) > > Now I want both of them in a tupple (like map1 = ( ... ) and map2 = > ( ...) in my source code so I can index them.. > > Any idea how to give python a hint that the h at the end of the number > means it's a hex number? Or do I have to torture myself with regex to > get it right? No regex necessary whatsoever: # will be inefficient if file is huge f = open("path/to/assembly/file/1") content = f.read() f.close() map1 = [int(hexnum[:-1], 16) for hexnum content.split(", ")] # do same thing for 2nd file Cheers, Chris -- http://blog.rebertia.com From ian.g.kelly at gmail.com Tue Dec 7 21:51:01 2010 From: ian.g.kelly at gmail.com (Ian) Date: Tue, 7 Dec 2010 18:51:01 -0800 (PST) Subject: Collision of rotated rectangles without pygame References: <20101205234936.39dc1a4e@Knock> <4cfdf605$0$1639$742ec2ed@news.sonic.net> Message-ID: <48036888-7df2-44fb-924c-7b2d86a4d16c@c39g2000yqi.googlegroups.com> On Dec 7, 4:11?pm, Steve Holden wrote: > >>> timeit.timeit(fm) > 0.58099985122680664 > >>> timeit.timeit(fd) > 0.55200004577636719 > > Of course it's possible that the random number generation is dominating, I think that it is. Moving the random number generation out into setup: >>> t1 = timeit.Timer("sin(x.next())", "from math import sin, radians; import random; x = iter([random.random() for i in xrange(1000000)])") >>> t1.timeit(1000000) 0.45154733352978838 >>> t2 = timeit.Timer("d[x.next()]", "import math, random; x = iter([random.randrange(360) for i in xrange(1000000)]); d = dict((i, math.sin(math.radians(i))) for i in xrange(360))") >>> t2.timeit(1000000) 0.21765364033694823 Of course, the dict approach assumes that all angles will be an integer number of degrees. One could add precision, but looking up specific float values in a dict is dicey, so then one has to switch to decimal math, and that's going to add extra overhead -- probably enough to tip the scales in favor of math.sin. Cheers, Ian From python at mrabarnett.plus.com Tue Dec 7 21:58:17 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 08 Dec 2010 02:58:17 +0000 Subject: convert assembly data (double words and bytes) in two tupple In-Reply-To: <1d2585a4-a023-4676-8743-a4998eacb41f@c17g2000prm.googlegroups.com> References: <1d2585a4-a023-4676-8743-a4998eacb41f@c17g2000prm.googlegroups.com> Message-ID: <4CFEF449.6070705@mrabarnett.plus.com> On 08/12/2010 02:36, joblack wrote: > I have two assembly data txt files, one has the structure: > > 0E1459D1Fh, 0AB58FAAEh, 4303E35Bh, 55FA3020h, 0E66D76ADh, > 0EF434544h, ... > > and the other has the structure: > > 53h, 6, 6Bh, 0D4h, 40h, 35h, 0B5h, 33h, 0AFh, 30h, 0B3h, > 66h, ... > > (I removed the dd and db with awk) > > Now I want both of them in a tupple (like map1 = ( ... ) and map2 = > ( ...) in my source code so I can index them.. > > Any idea how to give python a hint that the h at the end of the number > means it's a hex number? Or do I have to torture myself with regex to > get it right? If you insist on not using regex (:-)) then: >>> text = "53h, 6, 6Bh, 0D4h, 40h, 35h, 0B5h, 33h, 0AFh, 30h, 0B3h, 66h" >>> data = [t.strip() for t in text.split(",")] >>> data ['53h', '6', '6Bh', '0D4h', '40h', '35h', '0B5h', '33h', '0AFh', '30h', '0B3h', '66h'] >>> data = [int(d[ : -1], 16) if d[-1] == "h" else int(d) for d in data] >>> data [83, 6, 107, 212, 64, 53, 181, 51, 175, 48, 179, 102] From lanyjie at yahoo.com Tue Dec 7 22:24:59 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Tue, 7 Dec 2010 19:24:59 -0800 (PST) Subject: group 0 in the re module In-Reply-To: <4CFEF14A.4080004@mrabarnett.plus.com> References: <194828.16515.qm@web54205.mail.re2.yahoo.com> <4CFEF14A.4080004@mrabarnett.plus.com> Message-ID: <108409.24308.qm@web54206.mail.re2.yahoo.com> : Use \g<0>. Thanks! Though I wish all \1, \2, ..., should also be forbidden. Such a mixture of things looks like a patch work. No offense meant. Yingjie From tomf.sessile at gmail.com Tue Dec 7 22:39:29 2010 From: tomf.sessile at gmail.com (TomF) Date: Tue, 7 Dec 2010 19:39:29 -0800 Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <87ei9tjfbm.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <2010120719392986644-tomfsessile@gmailcom> On 2010-12-07 16:09:17 -0800, Mark Wooding said: > Carl Banks writes: > >> I think that feeling the need to sort non-homogenous lists is >> indictative of bad design. > > Here's a reason you might want to. > > You're given an object, and you want to compute a hash of it. (Maybe > you want to see whether someone else's object is the same as yours, but > don't want to disclose the actual object, say.) To hash it, you'll need > to serialize it somehow. But here's a problem: objects like > dictionaries and sets don't impose an ordering on their elements. For > example, the set { 1, 'two' } is the same as the set { 'two', 1 } -- but > iterating the two might well yield the elements in a different order. > (The internal details of a hash table tend to reflect the history of > operations on the hash table as well as its current contents.) > > The obvious answer is to apply a canonical ordering to unordered objects > like sets and dictionaries. A set can be serialized with its elements > in ascending order; a dictionary can be serialized as key/value pairs > with the keys in ascending order. But to do this, you need an > (arbitrary, total) order on all objects which might be set elements or > dictionary keys. The order also needs to be dependent only on the > objects' serializable values, and not on any incidental facts such as > memory addresses or whatever. I have no argument that there might be an extra-logical use for such an ordering which you might find convenient. This is the point you're making. sort() and sorted() both take a cmp argument for this sort of thing. My complaint is with Python adopting nonsensical semantics ("shoe" < 7) to accomodate it. By analogy, I often find it convenient to have division by zero return 0 to the caller for use in calculations. But if Python defined 0/0==0 I'd consider it broken. -Tom From piet at vanoostrum.org Tue Dec 7 23:04:36 2010 From: piet at vanoostrum.org (Piet van Oostrum) Date: Wed, 08 Dec 2010 00:04:36 -0400 Subject: default behavior References: <0272074b-8508-4b7a-a11e-3f004506f522@v41g2000yqv.googlegroups.com> <4c64dd6b$0$28668$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano writes: > You don't need the space between strings and the attribute access: > "1".zfill(2) is fine. You only need it for numbers, due to the ambiguity > between the decimal point and dotted attribute access. Personally I prefer parentheses: (1).conjugate -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] Nu Fair Trade woonartikelen op http://www.zylja.com From ozizlk at gmail.com Tue Dec 7 23:40:23 2010 From: ozizlk at gmail.com (Oshan) Date: Wed, 8 Dec 2010 10:10:23 +0530 Subject: Books recommendation In-Reply-To: <237490BE-143B-4474-940E-48421488BEDC@kagi.com> References: <237490BE-143B-4474-940E-48421488BEDC@kagi.com> Message-ID: hi kee, i'm a beginner too.. when i asked the same question, some python gurus recommended these books and videos. in fact it worked.. so now i'm forwarding the same to you... 1. Core Python Programming by Wesley J. Chun 2. python quick reference guide - *http://rgruet.free.fr/#QuickRef.* 3. Python Phrasebook: Essential Code and Commands by Brad Dayley 4. Python pocket reference by mark luts (O'reilly) 5. PYTHON FOR SOFTWARE DESIGN - How to Think Like a Computer Scientist by allen B Downey 6. Thenewboston video tutorials - * http://www.thenewboston.com/?cat=40&pOpen=tutorial* 7. Showmedo video tutorials - *http://showmedo.com/videotutorials/python* there are so many resources on internet for python. i have mentioned only few, which i used to read. all the best !!! oshan. On Wed, Dec 8, 2010 at 12:30 AM, Kee Nethery wrote: > > On Dec 7, 2010, at 5:39 AM, Octavian Rasnita wrote: > > > Do you have, or can I find elsewhere a recommendation for books,tutorials > and sites appropriate for beginners? > > I have found that Python for Dummies is the book I use the most. It has > lots of examples that work and that I can build upon. The O'Reilly books > talk about the language but are scarce on actual code. > > Kee Nethery > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dheeraj.gupta4 at gmail.com Tue Dec 7 23:52:07 2010 From: dheeraj.gupta4 at gmail.com (RedBaron) Date: Tue, 7 Dec 2010 20:52:07 -0800 (PST) Subject: Using logging module to log either to screen or a file References: <3b9112c2-7a63-40ef-a0f6-f64a090acb59@j18g2000prn.googlegroups.com> Message-ID: <60982d41-6fff-472d-aad4-cd32a3e90d44@h17g2000pre.googlegroups.com> On Dec 7, 7:33?pm, Jean-Michel Pichavant wrote: > RedBaron wrote: > > Hi, > > I am beginner to python and i am writing a program that does a lot of > > things. One of the requirements is that the program shud generate a > > log file. I came across python loggging module and found it very > > useful. But I have a few problems > > Suppose by giving option '-v' along with the program the user can turn > > off logging to a file and instead display log on the screen. Since I > > am using a config file for logging, how do I accomplish this. > > I tried to define two handlers (fil and screen) and added it to my > > logger. But that logs data to both screen and the file. I need to log > > it to only one. How do I dynamically remove one of the handler from > > the logger based on user option. As a precursor how do i reference the > > handlers defined in config file in the code?? > > your logger has a public 'handlers' attribute. > > consoleHandlers = [h for h in logger.handlers if h.__class__ is > logging.StreamHandler] # the list of handlers logging to the console > (assuming they are instances of the StreamHandler class) > > if consoleHandlers: > ? ? h1 = consoleHandlers[0] > ? ? h1.filter = lambda x:True # enable the handler > ? ? h1.filter = lambda x:False # disable the handler > > JM Thanks JM, This works like charm. I had also though on similar lines bt I was using isinstance(). I have two handlers - logging.RotatingFIleHandler and StreamHandler. isinstance() was weird in the sense that no matter which handle I checked for being 'StreamHandler' I always got true. Also instead of setting filter to false, I was popping from the handlers list...Silly me Thanks a ton From steve at holdenweb.com Wed Dec 8 01:40:16 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 08 Dec 2010 07:40:16 +0100 Subject: completely implicit interpolation based on a frame object In-Reply-To: References: Message-ID: On 12/8/2010 2:49 AM, Edward Peschko wrote: > All, > > Ok, it looks like in order to implement a tracer that does > interpolation, I'm going to have to hack around with frames. > > Perl's interpolation is fairly straightforward, to do interpolation of > $a == 1 all you need to do is put quotes around "$a == 1" to have $a > evaluated. > > So, I'd like to do the same thing with python. It looks like I can do > the same thing with frames, ie: > > interpolate_frame(frame, "if not wx.Platform == '__WXMAC' ") > > would interpolate wx based off of the frame that you passed to > interpolate_frame, because wx is in the f_locals or f_globals > dictionary. > > Hence, this would become: > > loc_wx = _first_defined(frame.f_locals["wx"], frame.f_globals["wx"]) > return "if not ", loc_wx.Platform , " == \"__WXMAC\"" > > which would then do the interpolation. > > I guess my question is - has something like this been released? I see > some close hits, namely Evan Forsmark's > http://www.evanfosmark.com/2008/06/string-interpolation-in-python/ > > but I don't see anything exact, and getting this right would be fairly > tricky, so I was hoping for canned solution. > > Any ideas would be great on this, including pitfalls that people see > in implementing it. > http://docs.python.org/library/string.html#template-strings regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From rustompmody at gmail.com Wed Dec 8 02:48:39 2010 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 8 Dec 2010 13:18:39 +0530 Subject: class browser Message-ID: If I have a medium to large python code base to browse/study, what are the class browsers available? -------------- next part -------------- An HTML attachment was scrubbed... URL: From ddasilva at umd.edu Wed Dec 8 03:08:00 2010 From: ddasilva at umd.edu (Daniel da Silva) Date: Wed, 8 Dec 2010 00:08:00 -0800 Subject: Calling FORTAN dll functions from Python In-Reply-To: References: <4cfe167a$0$81476$e4fe514c@news.xs4all.nl> Message-ID: I don't know much about fortran+python, but I work with someone who does, and he absolutely loves this tool: http://cens.ioc.ee/projects/f2py2e/ Daniel On Tue, Dec 7, 2010 at 10:19 PM, Dennis Lee Bieber wrote: > On Tue, 07 Dec 2010 12:52:54 +0100, Stefan Behnel > declaimed the following in gmane.comp.python.general: > > > Alex van der Spek, 07.12.2010 12:11: > > > Does anyone know how to call functions from FORTRAN dlls in Python? Is > > > it even possible? > > > > Sure, have a look at fwrap and Cython. > > > > Stefan > > Possibly ctypes too... > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From alex at moreati.org.uk Wed Dec 8 04:31:49 2010 From: alex at moreati.org.uk (Alex Willmer) Date: Wed, 8 Dec 2010 01:31:49 -0800 (PST) Subject: Python creates "locked" temp dir References: <0c30c818-f73b-4b09-b707-64ea457c757d@z26g2000prf.googlegroups.com> Message-ID: <91dca7c4-00c7-44ad-8902-54221534107c@o9g2000pre.googlegroups.com> On Dec 7, 9:03?pm, utabintarbo wrote: > I am using tempfile.mkdtemp() to create a working directory on a > remote *nix system through a Samba share. When I use this on a Windows > box, it works, and I have full access to the created dir. When used on > a Linux box (through the same Samba share), the created directory > shows as "locked", and I am unable to access. Obviously, I need > access. Any clues? You haven't provided enough details to go on. 1. Please post the actual code, and the trace back (if any). 2. When you say "I am unable to access". Do you mean another script/ process is unable to access? If so, that is the point of mkdtemp() - to make a temporary directory that _only_ the creating process can access. If you want to share it then tempfile is not the right module for you. Regards, Alex From steve+comp.lang.python at pearwood.info Wed Dec 8 04:47:21 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 Dec 2010 09:47:21 GMT Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <871v5t13ok.fsf@benfinney.id.au> Message-ID: <4cff5429$0$30002$c3e8da3$5496439d@news.astraweb.com> On Wed, 08 Dec 2010 11:58:03 +1100, Ben Finney wrote: > Carl Banks writes: > >> On Dec 6, 4:17?pm, Steven D'Aprano > +comp.lang.pyt... at pearwood.info> wrote: >> > Nevertheless, I agree that in hindsight, the ability to sort such >> > lists is not as important as the consistency of comparisons. >> >> I think that feeling the need to sort non-homogenous lists is >> indictative of bad design. > > It can also be indicative of code written for a Python that doesn't have > sets. Or a list that contains unhashable objects. Or a list that needs to be presented to a human reader in some arbitrary but consistent order. Or a doctest that needs to show the keys in a dict: >>> d = myfunction() >>> sorted(d.keys()) ['ham', 'spam', 42, None] (although that case is probably the weakest of the three). > So there's no design error in wanting heterogenerous sequences to sort; > it can be quite Pythonic (until the advent of the ?set? type). Agreed, but in hindsight I think it would be better if there was a separate lexicographic sort function, that guaranteed to sort anything (including such unorderable values as complex numbers!), without relying on the vagaries of the standard comparison operators. Or at least anything printable, in which case sorted() with a key function of lambda obj: (repr(type(obj)), repr(obj)) might work, I suppose... Then at least we could limit our arguments to how this hypothetical lexicographic sort function was broken, instead of how all comparison operators are broken :) -- Steven From steve+comp.lang.python at pearwood.info Wed Dec 8 04:48:05 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 Dec 2010 09:48:05 GMT Subject: Perceived inconsistency in py3k documentation References: <724b26b4-8233-4d57-b76f-cd781cf0cd03@z17g2000prz.googlegroups.com> <20101206200017.0c5fc63f@pitrou.net> Message-ID: <4cff5455$0$30002$c3e8da3$5496439d@news.astraweb.com> On Wed, 08 Dec 2010 00:47:37 +0100, Steve Holden wrote: > On 12/6/2010 8:00 PM, Antoine Pitrou wrote: >> On Sun, 05 Dec 2010 14:47:38 -0500 >> Terry Reedy wrote: >>> On 12/5/2010 3:31 AM, Greg wrote: >>> >>> For future reference, >>> >>>> 1) At http://docs.python.org/py3k/reference/datamodel.html: 2) At >>>> http://docs.python.org/py3k/library/stdtypes.html: >>> >>> do not work because of the trailing :s, at least not with FireFox. >> >> Work fine here. The problem isn't Firefox, it is your e-mail or news >> client. >> >> Antoine. >> >> > In my case also the links don't work, because my newsreader > (Thunderbird) makes the assumption that the colons are part of the URLs. > This behavior is common enough that people need to be aware of it. It seems to me that colons are legal inside URIs and don't need to be escaped. If that is the case, then Thunderbird is correct to treat the colon as part of the URL, and whatever client Antoine is using is wrong to exclude it. See this thread here for a discussion which concluded that colons are legal and don't need to be escaped: http://markmail.org/message/juowogoeiff44qc4 Personally, I never let any character except whitespace or < > delimiters touch a URL. I never know how applications will interpret it. -- Steven From orasnita at gmail.com Wed Dec 8 05:09:02 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Wed, 8 Dec 2010 12:09:02 +0200 Subject: is py2exe still active ? References: <5f32249f-50d4-440e-9005-04f954572894@32g2000yqz.googlegroups.com> <89dd2092-d6e9-4d5c-b966-54df3f48f065@g19g2000yqg.googlegroups.com> <2DEA78DF996B485E8B52F3B29B1124A1@teddy> <4CFEBBAE.2060400@holdenweb.com> Message-ID: <0053AA37CC664343BD6FC2E75627821C@teddy> Hi Steve, I may put some stupid questions because I am very new to Python, but... I heard about pypi/pip. Aren't all these Python libraries (like cxFreeze) provided on a central archive where we can get them and also report the bugs using a single request/issue tracker? Octavian ----- Original Message ----- From: "Steve Holden" Newsgroups: gmane.comp.python.general To: "Octavian Rasnita" Cc: Sent: Wednesday, December 08, 2010 12:56 AM Subject: Re: is py2exe still active ? > Octavian: > > It's great that you want to let people know about bugs. Put yourself in > the position of the package maintainer, however. She or he doesn't spend > all day working on cxFreeze, and probably doesn't even do a Google > search on cxFreeze very often. So they are unlikely to find out about > this problem form your well-intentioned note. > > It's just possible nobody does care, as I can't find a link to an issue > tracker - the best I could advise in this case would be to join the > mailing list by visiting > > https://lists.sourceforge.net/lists/listinfo/cx-freeze-users > > regards > Steve > > On 12/7/2010 6:49 PM, Octavian Rasnita wrote: >> This packager is also nice. >> >> If someone cares, I've discovered a small bug in it. >> If Python is installed on another drive than C under Windows, the cxfreeze.bat file still calls Python on the drive C and it doesn't work until it is corrected. >> >> Octavian >> >> ----- Original Message ----- >> From: "Cbast" >> Newsgroups: comp.lang.python >> To: >> Sent: Tuesday, December 07, 2010 5:00 PM >> Subject: Re: is py2exe still active ? >> >> >> On Dec 7, 8:23 am, Anders Persson wrote: >>> Hi! >>> When a look att py2exe homepage it is not looking like mutch happen, >>> as a beginner i was thinking to start with Python 3, but i like to now >>> if py2exe will be for 3 too. >>> >>> Is any one have any info ? >> >> I don't have the answer about py2exe, but I'm using cxFreeze to create >> executables with Python 3.1, if it's what you're looking for. >> >> http://cx-freeze.sourceforge.net/ > > > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ > See Python Video! http://python.mirocommunity.org/ > Holden Web LLC http://www.holdenweb.com/ From gerlach_joerg at web.de Wed Dec 8 05:12:35 2010 From: gerlach_joerg at web.de (J. Gerlach) Date: Wed, 08 Dec 2010 11:12:35 +0100 Subject: group 0 in the re module In-Reply-To: References: Message-ID: Am 08.12.2010 03:23, schrieb Yingjie Lan: > Hi, > > According to the doc, group(0) is the entire match. > >>>> m = re.match(r"(\w+) (\w+)", "Isaac Newton, physicist") >>>> m.group(0) # The entire match 'Isaac Newton' > > But if you do this: >>>> import re >>>> re.sub(r'(\d{3})(\d{3})', r'\0 to \1-\2', '757234') > '\x00 to 757-234' > > where I expected > '757234 to 757-234' > > Then I found that in python re '\0' is considered an octal number. > So, is there anyway to refer to the entire match by an escaped > notation? > > Thanks, > > Yingjie > the documentation of the re module says: > \g uses the corresponding group number; \g<2> is > therefore equivalent to \2, but isn?t ambiguous in a replacement such > as \g<2>0. \20 would be interpreted as a reference to group 20, not a > reference to group 2 followed by the literal character '0'. The > backreference \g<0> substitutes in the entire substring matched by > the RE. .. so you're looking for r"\g<0> to \1-\2" From steve+comp.lang.python at pearwood.info Wed Dec 8 05:29:35 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 Dec 2010 10:29:35 GMT Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <4cfebe65$0$1590$742ec2ed@news.sonic.net> Message-ID: <4cff5e0e$0$30002$c3e8da3$5496439d@news.astraweb.com> On Tue, 07 Dec 2010 15:08:23 -0800, John Nagle wrote: > If you're thinking hard about this, I recommend viewing Alexander > Stepanov's talk at Stanford last month: > > http://www.stanford.edu/class/ee380/Abstracts/101103.html > > He makes the point that, for generic programs to work right, the basic > operations must have certain well-defined semantics. Then the same > algorithms will work right across a wide variety of objects. But they already work right across a wide variety of objects, so long as you limit yourself to the subset of objects where the basic operations have the same semantics. I think that insisting that all operators must always have the same semantics is as impractical and unnecessary as insisting that all functions and methods with the same name must always have the same semantics. We wouldn't expect pencil.draw six_shooter.draw game.draw to all have the same semantics, or math.sin priest.sin despite the inconvenience it makes to duck-typing. Why should we expect more from operators than we expect from named functions, when there are so many more named functions and so few useful symbols for operators? To my mind, it is foolish for us to expect x*y to always have the same semantics when even mathematicians don't expect that. In pure mathematics, x*y != y*x for any of the following: matrices quaternions octonions and probably many others I don't know about. > This is consistent with Python's "duck typing", but inconsistent > with the current semantics of some operators. > > For example, "+" as concatenation makes "+" non-commutative. No, it only makes + non-commutative for those types where + is non- commutative. > In other words, > > a + b > > is not always equal to > > b + a > > which is not good. I don't see why. It seems to me that it's only a bad thing if you hope to reason about the meaning of a+b without knowing what a and b actually are. Personally, I don't consider that a particularly useful trait. > Important properties to have across all types: > > a + b == b + a > > Exactly one of > > a > b > a = b > a < b > > is true, or an type exception must be raised. As Mark Wooding has already pointed out, that would make numeric programmers mad, as it eliminates NANs, which are far more important to them. And me. It also would make it impossible to use > and < to talk about rankings in natural hierarchies, such as (say) pecking orders. Using > to mean "out- ranks", you might have a pecking order among five hens like this: A > B > C > D > E but D > B Not all comparisons are equivalence relations, and it would be a crying shame to lose the ability to use > and < to discuss (e.g.) non-transitive comparisons. -- Steven From dheeraj.gupta4 at gmail.com Wed Dec 8 05:32:17 2010 From: dheeraj.gupta4 at gmail.com (RedBaron) Date: Wed, 8 Dec 2010 02:32:17 -0800 (PST) Subject: Case Sensitive Section names configparser Message-ID: Is there any way by which configParser's get() function can be made case insensitive? From pavlovevidence at gmail.com Wed Dec 8 05:33:46 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 8 Dec 2010 02:33:46 -0800 (PST) Subject: Calling FORTAN dll functions from Python References: <4cfe167a$0$81476$e4fe514c@news.xs4all.nl> Message-ID: On Dec 7, 3:11?am, "Alex van der Spek" wrote: > Does anyone know how to call functions from FORTRAN dlls in Python? Is it > even possible? I browsed the documentation for Python 2.6.1 and the Python/C > API comes close to what I would like to do but it is strictly limited to C. > > Unfortunately the passing of arguments in C and FORTRAN is very different, > not to mention the differences with strings where FORTRAN expects a hidden > length argument. It could call the FORTRAN dll from C and call the C > functions from Python but is that my only option? I'd recommend f2py, which is part of the numpy package. Carl Banks From tartley at tartley.com Wed Dec 8 05:40:12 2010 From: tartley at tartley.com (Jonathan Hartley) Date: Wed, 8 Dec 2010 02:40:12 -0800 (PST) Subject: is py2exe still active ? References: <5f32249f-50d4-440e-9005-04f954572894@32g2000yqz.googlegroups.com> <89dd2092-d6e9-4d5c-b966-54df3f48f065@g19g2000yqg.googlegroups.com> <2DEA78DF996B485E8B52F3B29B1124A1@teddy> <4CFEBBAE.2060400@holdenweb.com> Message-ID: <5b8bb079-6000-45a8-b21e-aee78baaa678@p26g2000pra.googlegroups.com> On Dec 8, 10:09?am, "Octavian Rasnita" wrote: > Hi Steve, > > I may put some stupid questions because I am very new to Python, but... I heard about pypi/pip. Aren't all these Python libraries (like cxFreeze) provided on a central archive where we can get them and also report the bugs using a single request/issue tracker? > > Octavian > > > > ----- Original Message ----- > From: "Steve Holden" > > Newsgroups: gmane.comp.python.general > To: "Octavian Rasnita" > Cc: > Sent: Wednesday, December 08, 2010 12:56 AM > Subject: Re: is py2exe still active ? > > > Octavian: > > > It's great that you want to let people know about bugs. Put yourself in > > the position of the package maintainer, however. She or he doesn't spend > > all day working on cxFreeze, and probably doesn't even do a Google > > search on cxFreeze very often. So they are unlikely to find out about > > this problem form your well-intentioned note. > > > It's just possible nobody does care, as I can't find a link to an issue > > tracker - the best I could advise in this case would be to join the > > mailing list by visiting > > > ?https://lists.sourceforge.net/lists/listinfo/cx-freeze-users > > > regards > > Steve > > > On 12/7/2010 6:49 PM, Octavian Rasnita wrote: > >> This packager is also nice. > > >> If someone cares, I've discovered a small bug in it. > >> If Python is installed on another drive than C under Windows, the cxfreeze.bat file still calls Python on the drive C and it doesn't work until it is corrected. > > >> Octavian > > >> ----- Original Message ----- > >> From: "Cbast" > >> Newsgroups: comp.lang.python > >> To: > >> Sent: Tuesday, December 07, 2010 5:00 PM > >> Subject: Re: is py2exe still active ? > > >> On Dec 7, 8:23 am, Anders Persson wrote: > >>> Hi! > >>> When a look att py2exe homepage it is not looking like mutch happen, > >>> as a beginner i was thinking to start with Python 3, but i like to now > >>> if py2exe will be for 3 too. > > >>> Is any one have any info ? > > >> I don't have the answer about py2exe, but I'm using cxFreeze to create > >> executables with Python 3.1, if it's what you're looking for. > > >>http://cx-freeze.sourceforge.net/ > > > -- > > Steve Holden ? ? ? ? ? +1 571 484 6266 ? +1 800 494 3119 > > PyCon 2011 Atlanta March 9-17 ? ? ?http://us.pycon.org/ > > See Python Video! ? ? ?http://python.mirocommunity.org/ > > Holden Web LLC ? ? ? ? ? ? ? ?http://www.holdenweb.com/ Hey, Yes, they are all Python packages or applications, and yes, PyPI aka The Cheese Shop is a single repository for them. However, they do not share mailing lists or issue trackers. Each project maintains its own bug tracking, etc. Best regards, Jonathan From tartley at tartley.com Wed Dec 8 05:40:13 2010 From: tartley at tartley.com (Jonathan Hartley) Date: Wed, 8 Dec 2010 02:40:13 -0800 (PST) Subject: is py2exe still active ? References: <5f32249f-50d4-440e-9005-04f954572894@32g2000yqz.googlegroups.com> <89dd2092-d6e9-4d5c-b966-54df3f48f065@g19g2000yqg.googlegroups.com> <2DEA78DF996B485E8B52F3B29B1124A1@teddy> <4CFEBBAE.2060400@holdenweb.com> Message-ID: On Dec 8, 10:09?am, "Octavian Rasnita" wrote: > Hi Steve, > > I may put some stupid questions because I am very new to Python, but... I heard about pypi/pip. Aren't all these Python libraries (like cxFreeze) provided on a central archive where we can get them and also report the bugs using a single request/issue tracker? > > Octavian > > > > ----- Original Message ----- > From: "Steve Holden" > > Newsgroups: gmane.comp.python.general > To: "Octavian Rasnita" > Cc: > Sent: Wednesday, December 08, 2010 12:56 AM > Subject: Re: is py2exe still active ? > > > Octavian: > > > It's great that you want to let people know about bugs. Put yourself in > > the position of the package maintainer, however. She or he doesn't spend > > all day working on cxFreeze, and probably doesn't even do a Google > > search on cxFreeze very often. So they are unlikely to find out about > > this problem form your well-intentioned note. > > > It's just possible nobody does care, as I can't find a link to an issue > > tracker - the best I could advise in this case would be to join the > > mailing list by visiting > > > ?https://lists.sourceforge.net/lists/listinfo/cx-freeze-users > > > regards > > Steve > > > On 12/7/2010 6:49 PM, Octavian Rasnita wrote: > >> This packager is also nice. > > >> If someone cares, I've discovered a small bug in it. > >> If Python is installed on another drive than C under Windows, the cxfreeze.bat file still calls Python on the drive C and it doesn't work until it is corrected. > > >> Octavian > > >> ----- Original Message ----- > >> From: "Cbast" > >> Newsgroups: comp.lang.python > >> To: > >> Sent: Tuesday, December 07, 2010 5:00 PM > >> Subject: Re: is py2exe still active ? > > >> On Dec 7, 8:23 am, Anders Persson wrote: > >>> Hi! > >>> When a look att py2exe homepage it is not looking like mutch happen, > >>> as a beginner i was thinking to start with Python 3, but i like to now > >>> if py2exe will be for 3 too. > > >>> Is any one have any info ? > > >> I don't have the answer about py2exe, but I'm using cxFreeze to create > >> executables with Python 3.1, if it's what you're looking for. > > >>http://cx-freeze.sourceforge.net/ > > > -- > > Steve Holden ? ? ? ? ? +1 571 484 6266 ? +1 800 494 3119 > > PyCon 2011 Atlanta March 9-17 ? ? ?http://us.pycon.org/ > > See Python Video! ? ? ?http://python.mirocommunity.org/ > > Holden Web LLC ? ? ? ? ? ? ? ?http://www.holdenweb.com/ Hey, Yes, they are all Python packages or applications, and yes, PyPI aka The Cheese Shop is a single repository for them. However, they do not share mailing lists or issue trackers. Each project maintains its own bug tracking, etc. Best regards, Jonathan From steve+comp.lang.python at pearwood.info Wed Dec 8 05:45:55 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 Dec 2010 10:45:55 GMT Subject: use of __new__ to permit "dynamic" completion within (any?) IDE ? References: <0b90e80b-8b9b-412d-bfff-9a9ec4b172d2@h22g2000vbr.googlegroups.com> Message-ID: <4cff61e3$0$30002$c3e8da3$5496439d@news.astraweb.com> On Tue, 07 Dec 2010 07:52:06 -0800, gst wrote: > Hi, > > I met a situation where I was passing an object created in/with an upper > level module class to a lower level module class' instance in one of its > __init__ argument and saving a ref of the upper object in that lower > level class' new instance. > > But in my IDE I want the completion to also work from within the lower > level module when it's refering to the object passed from the upper > level: "The completion"? What do you mean? > Well, I'm sure I'm not very clear in my terms (and probably a bit long > in the sentence) so here it is in code: I'm afraid I have to agree with your, your description is not clear to me. Unfortunately, neither is your code, because I don't understand *why* you do the things you do. > files: > module1.py > subpackage/module2.py > > > file module1.py: > > from subpackage.module2 import class2 Is it relevant that class2 comes from another module? Would your concept work if class1 and class2 were defined in the same file? By the way, it's conventional (but not compulsory) to name classes with an initial capital letter, and instances in all lowercase. > class class1(object): > > def __new__(cls, _self=None, *args, **kwargs): > if _self: ## we've been passed an instance already > initialyzed > ## so directly return it instead of creating a > new object. > return _self > return object.__new__(cls) Depending on your application, this may be an unsafe assumption. If the caller says class1("spam"), your class will return "spam". This may or may not be what you want. > def __init__(self, _self=None, *args, **kwargs): > if _self: ## we've been passed an instance already > initialyzed > ## so directly returns > ## assert(self is _self) ? > return > self.object2 = class2(object1=self, "blip", "blop") # others > init Okay, this seems like a fairly straightforward case of adding an attribute to your instance that includes a reference to itself. No big deal... there's nothing wrong with this, although you are creating a reference cycle, which is somewhat of a (mild) code-smell. > file module2.py: > > class class2(object): > > def __init__(self, object1, *args, **kwargs): > > from ..module1 import class1 Now you have a circular import, and that's a pretty major code smell. That's dangerous. Try to avoid it. Perhaps the easiest way to avoid it is to place class1 and class2 in the same module, and stop writing Java :) > self.object1 = class1(_self=object1) ## instead of: > self.object1 = object1 > > ## others functions and/or init.. > ## where now I've completion working on self.object1 : ## if I > add(or remove) fields/methods in module1 (and save) then ## I have > them available(or disappeared) in the completion when > executed from this submodule. > ## This ofcourse permits to save me of remembering all of the > class1 attributes/methods when I'm working with self.object1 from within > one of class2 methods. I'm afraid I don't understand what you mean here in these comments. What do you mean, "save me of (from?) remembering all the class1 attributes/ methods..." -- how does it save you from knowing the methods? Whether you write this: instance = class1() instance.method() or this: instance = class1() another_instance = class2(instance) another_instance.object1.method() you still need to know the name "method". It seems to me that this scheme is unnecessarily complex, convoluted and confusing, for very little gain. Perhaps you could try explaining what you hope to accomplish, giving examples? -- Steven From bieffe62 at gmail.com Wed Dec 8 05:53:30 2010 From: bieffe62 at gmail.com (Francesco Bochicchio) Date: Wed, 8 Dec 2010 02:53:30 -0800 (PST) Subject: Case Sensitive Section names configparser References: Message-ID: <4c2179f5-fa90-4fd7-9cd8-808fb8d54468@u9g2000pra.googlegroups.com> On 8 Dic, 11:32, RedBaron wrote: > Is there any way by which configParser's get() function can be made > case insensitive? If you don't care about the case of the config parameter values, you could pre-convert the input to configParser all in UPPER or lower letter with a file-like object like this (NOT TESTED): class AllUpperFile(object): def __init__(self, fname): self.fp = file(fname) def readline(self): return self.fp.readline().upper() and the use configParser.readfp method to feed the file-like object to the config parser myConfigparser.readfp( AllUpperFile("myconnfigfile.cfg") HTH Ciao ---- FB From jeanmichel at sequans.com Wed Dec 8 06:05:41 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 08 Dec 2010 12:05:41 +0100 Subject: class browser In-Reply-To: References: Message-ID: <4CFF6685.3070900@sequans.com> Rustom Mody wrote: > If I have a medium to large python code base to browse/study, what are > the class browsers available? vim + ctags is one of them. JM From joncle at googlemail.com Wed Dec 8 06:11:51 2010 From: joncle at googlemail.com (Jon Clements) Date: Wed, 8 Dec 2010 03:11:51 -0800 (PST) Subject: Case Sensitive Section names configparser References: Message-ID: On Dec 8, 10:32?am, RedBaron wrote: > Is there any way by which configParser's get() function can be made > case insensitive? I would probably subclass dict to create a string specific, case insensitive version, and supply it as the dict_type. See http://docs.python.org/library/configparser.html#ConfigParser.RawConfigParser That way your values would remain cased correctly, but lookups would be insensitive. hth Jon. From g.starck at gmail.com Wed Dec 8 07:01:38 2010 From: g.starck at gmail.com (gst) Date: Wed, 8 Dec 2010 04:01:38 -0800 (PST) Subject: use of __new__ to permit "dynamic" completion within (any?) IDE ? References: <0b90e80b-8b9b-412d-bfff-9a9ec4b172d2@h22g2000vbr.googlegroups.com> <4cff61e3$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8ec4f0a5-a7d7-46ef-91d2-2427f696cb11@y3g2000vbm.googlegroups.com> On 8 d?c, 11:45, Steven D'Aprano wrote: > On Tue, 07 Dec 2010 07:52:06 -0800, gst wrote: > > Hi, > > > But in my IDE I want the completion to also work from within the lower > > level module when it's refering to the object passed from the upper > > level: > > "The completion"? What do you mean? Hi, I mean the autocompletion feature of my IDE : when I type "object." then on the "." it shows me possible members/ methods of the 'object'. depending on what my IDE can guess about the object possible type(s) ; in the worst case it can't guess nothing about it and that's my point below.. > > Well, I'm sure I'm not very clear in my terms (and probably a bit long > > in the sentence) so here it is in code: > > I'm afraid I have to agree with your, your description is not clear to me. I hope I'm now ;) > Unfortunately, neither is your code, because I don't understand *why* you > do the things you do. damn. ok let's go.. > > file module1.py: > > > from subpackage.module2 import class2 > > Is it relevant that class2 comes from another module? yes. hmmm or maybe not completely.. I think it only highly depends on what the IDE can guess on an object type used inside some methods depending on the files hierarchy.. > Would your concept work if class1 and class2 were defined in the same file? I guess yes also. > > class class1(object): > > > ? ? def __new__(cls, _self=None, *args, **kwargs): > > ? ? ? ? if _self: ?## we've been passed an instance already > > initialyzed > > ? ? ? ? ? ? ? ? ? ? ?## so directly return it instead of creating a > > new object. > > ? ? ? ? ? ? return _self > > ? ? ? ? return object.__new__(cls) > > Depending on your application, this may be an unsafe assumption. If the > caller says class1("spam"), your class will return "spam". This may or > may not be what you want. I'm always passing the good object type when I do this. > > ? ? def __init__(self, _self=None, *args, **kwargs): > > ? ? ? ? if _self: ?## we've been passed an instance already > > initialyzed > > ? ? ? ? ? ? ? ? ? ? ?## so directly returns > > ? ? ? ? ? ? ## assert(self is _self) ? > > ? ? ? ? ? ? return > > ? ? ? ? self.object2 = class2(object1=self, "blip", "blop") # others > > ? ? ? ? init > > Okay, this seems like a fairly straightforward case of adding an > attribute to your instance that includes a reference to itself. No big > deal... there's nothing wrong with this, although you are creating a > reference cycle, which is somewhat of a (mild) code-smell. that is a worry effectively. (hmm when you say it's a case of adding an attribute that includes a ref to itself it's not really that (or i badly understand) : it's adding an attribute to a lower level class instance that contains a ref to an upper level class instance (which also contains a ref to the lower level class' instance and that's the cycle (and that's a bit my worry)) > > file module2.py: > > > class class2(object): > > > ? ? def __init__(self, object1, *args, **kwargs): > > > ? ? ? ? from ..module1 import class1 > > Now you have a circular import, and that's a pretty major code smell. > That's dangerous. Try to avoid it. Perhaps the easiest way to avoid it is > to place class1 and class2 in the same module, and stop writing Java :) damn if this looks like Java it's really not my will ; I've not made Java anymore for probably 10 years ! I'll try by putting class1 and class2 in same module (or at same directory level first) and see if that can do it.. > > > ? ? ? ? self.object1 = class1(_self=object1) ? ?## instead of: > > self.object1 = object1 > > > ? ? ## others functions and/or init.. > > ? ? ## where ?now I've completion working on self.object1 : ## if I > > ? ? add(or remove) fields/methods in module1 (and save) then ## I have > > ? ? them available(or disappeared) in the completion when > > executed from this submodule. > > ? ? ## This ofcourse permits to save me of remembering all of the > > class1 attributes/methods when I'm working with self.object1 from within > > one of class2 methods. > > I'm afraid I don't understand what you mean here in these comments. What > do you mean, "save me of (from?) remembering all the class1 attributes/ > methods..." -- how does it save you from knowing the methods? Whether you > write this: > > instance = class1() > instance.method() > > or this: > > instance = class1() > another_instance = class2(instance) > another_instance.object1.method() > > you still need to know the name "method". > > It seems to me that this scheme is unnecessarily complex, convoluted and > confusing, for very little gain. Perhaps you could try explaining what > you hope to accomplish, giving examples? Effectively I recognise that this seems like a bit silly/odd .. but as it's working I wanted some advises so ;) As I told I try to have some kind of "ultimate" autocompletion, always working for this kind of case (I know exactly that a certain member of a certain class' instance will always have the same type but my IDE doesn't seem to guess/know it.. ; I guess the best answer would be : bad IDE, change IDE but I'm guessing that others IDE can't do a lot better in this case. Anyway many thanks for your reply ; I'll do some further tests with your comments already.. regards, greg. nb: so this "hack" is only relevant during dev ; once the project would be finished the "hack" could be removed (i.e : in class2 init I would directly do : self.object1 = object1) From python.list at tim.thechases.com Wed Dec 8 07:29:57 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 08 Dec 2010 06:29:57 -0600 Subject: Comparisons of incompatible types In-Reply-To: <4cff5429$0$30002$c3e8da3$5496439d@news.astraweb.com> References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <871v5t13ok.fsf@benfinney.id.au> <4cff5429$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4CFF7A45.7060000@tim.thechases.com> On 12/08/2010 03:47 AM, Steven D'Aprano wrote: > Or a list that needs to be presented to a human reader in some arbitrary > but consistent order. > > Or a doctest that needs to show the keys in a dict: > > >>> d = myfunction() > >>> sorted(d.keys()) > ['ham', 'spam', 42, None] > [snip] > > Agreed, but in hindsight I think it would be better if there was a > separate lexicographic sort function, that guaranteed to sort anything > (including such unorderable values as complex numbers!), without relying > on the vagaries of the standard comparison operators. wouldn't that be something like sorted(mixedstuff, key=str) or if all you need is a stable order regardless of what that order is, one could even get away with: sorted(mixedstuff, key=id) -tkc From xrgtn at yandex.ru Wed Dec 8 07:42:25 2010 From: xrgtn at yandex.ru (Alexander Gattin) Date: Wed, 8 Dec 2010 14:42:25 +0200 Subject: Wanted: slow regexes In-Reply-To: <4CFC61B0.8000109@mrabarnett.plus.com> References: <4CFC61B0.8000109@mrabarnett.plus.com> Message-ID: <20101208124225.GA4846@xrgtn-q40> Hello, On Mon, Dec 06, 2010 at 04:08:16AM +0000, MRAB wrote: > I'm looking for examples of regexes which are > slow (especially those which seem never to > finish) but whose results are known. does it have anything to do with http://swtch.com/~rsc/regexp/regexp1.html? -- With best regards, xrgtn From jonathan.slenders at gmail.com Wed Dec 8 08:01:04 2010 From: jonathan.slenders at gmail.com (Jonathan S) Date: Wed, 8 Dec 2010 05:01:04 -0800 (PST) Subject: Replacing globals in exec by custom class Message-ID: Hi all, I wonder if anyone can explain some weird behaviour in Python. What I'm trying to do is to execute a string of python code through the 'exec' statement. I pass an instance of my Global class, which acts like a dict. By overriding the __getitem__ method, the Global should pretend that a global variable, named 'xx' does exist. This does work for the outermost scope in the executed code, but inside the nested function, 'q', the Global instance seems never to be accessed, 'xx' is not found, while the globals() built-in still returns the custom Global instance. According to python's executing model [1], the interpreter is supposed to look into globals(), if a variable has not been assigned in the inner scope. What am I missing here? [1] http://docs.python.org/reference/executionmodel.html {{{ class Global(dict): def __init__(self): pass def __getitem__(self, key): import __builtin__ if key == 'xx': return 'xx' if hasattr(__builtin__, key): return getattr(__builtin__, key) else key in self.__dict__: return self.__dict__[key] def __setitem__(self, key, value): self.__dict__[key] = value def __str__(self): return ' ' + unicode(self.__dict__) code=""" print globals() print xx # Does work, prints 'xx' def q(): print globals().__getitem__('xx') # Does work, prints 'xx' print globals()['xx'] # Does work, prints 'xx' print xx # Does not work, cannot find xx q() """ g = Global() exec(compile(code, 'my code', 'exec'), g, g) }}} From utabintarbo at gmail.com Wed Dec 8 08:09:06 2010 From: utabintarbo at gmail.com (utabintarbo) Date: Wed, 8 Dec 2010 05:09:06 -0800 (PST) Subject: Python creates "locked" temp dir References: <0c30c818-f73b-4b09-b707-64ea457c757d@z26g2000prf.googlegroups.com> <91dca7c4-00c7-44ad-8902-54221534107c@o9g2000pre.googlegroups.com> Message-ID: <51e4ed46-41dd-46db-b3c4-0fdb475be97f@o14g2000prn.googlegroups.com> Thanks for the reply. The relevant function (in a module) is as follows: def createWorkDir(pathdir="k:\\"): import tempfile, os if os.name == 'posix': pathdir = os.path.join(config.get('paths', 'MOUNTPOINT'), 'subdir1') else: pathdir = os.path.normpath(r"\\windowsmount\subdir1") if not os.path.exists(os.path.join(pathdir,'tmp','program')): os.makedirs(os.path.join(pathdir,'tmp','program')) return os.path.normpath(tempfile.mkdtemp("", "", os.path.join(pathdir,'tmp','program'))) The calling program calls the function as such: updateWorkDir = createWorkDir() I then attempt to copy a file (using shutil.move) into updateWorkDir and get an: IOError: [Errno 13] Permission denied: '/MOUNTPOINT/subdir1/tmp/ program/y-Z0h3/file.ext' I also tried to create a similar dir under 'tmp' using os.mkdir and while the dir was not locked such that only the owner could do anything in it, it was not writeable by anything other than the owner, even when mode 0777 was specified explicitly. Thanks for the help. On Dec 8, 4:31?am, Alex Willmer wrote: > On Dec 7, 9:03?pm, utabintarbo wrote: > > > I am using tempfile.mkdtemp() to create a working directory on a > > remote *nix system through a Samba share. When I use this on a Windows > > box, it works, and I have full access to the created dir. When used on > > a Linux box (through the same Samba share), the created directory > > shows as "locked", and I am unable to access. Obviously, I need > > access. Any clues? > > You haven't provided enough details to go on. > 1. Please post the actual code, and the trace back (if any). > 2. When you say "I am unable to access". Do you mean another script/ > process is unable to access? If so, that is the point of mkdtemp() - > to make a temporary directory that _only_ the creating process can > access. If you want to share it then tempfile is not the right module > for you. > > Regards, Alex From steve at holdenweb.com Wed Dec 8 08:09:42 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 08 Dec 2010 14:09:42 +0100 Subject: use of __new__ to permit "dynamic" completion within (any?) IDE ? In-Reply-To: <8ec4f0a5-a7d7-46ef-91d2-2427f696cb11@y3g2000vbm.googlegroups.com> References: <0b90e80b-8b9b-412d-bfff-9a9ec4b172d2@h22g2000vbr.googlegroups.com> <4cff61e3$0$30002$c3e8da3$5496439d@news.astraweb.com> <8ec4f0a5-a7d7-46ef-91d2-2427f696cb11@y3g2000vbm.googlegroups.com> Message-ID: On 12/8/2010 1:01 PM, gst wrote: > As I told I try to have some kind of "ultimate" autocompletion, always > working for this kind of case (I know exactly that a certain member of > a certain class' instance will always have the same type but my IDE > doesn't seem to guess/know it.. ; I guess the best answer would be : > bad IDE, change IDE but I'm guessing that others IDE can't do a lot > better in this case. > If you'd told us which IDE you were using we might have offered better advice, but you seem to want to keep that a secret ("my IDE" tells us nothing). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From g.starck at gmail.com Wed Dec 8 09:21:18 2010 From: g.starck at gmail.com (gst) Date: Wed, 8 Dec 2010 06:21:18 -0800 (PST) Subject: use of __new__ to permit "dynamic" completion within (any?) IDE ? References: <0b90e80b-8b9b-412d-bfff-9a9ec4b172d2@h22g2000vbr.googlegroups.com> <4cff61e3$0$30002$c3e8da3$5496439d@news.astraweb.com> <8ec4f0a5-a7d7-46ef-91d2-2427f696cb11@y3g2000vbm.googlegroups.com> Message-ID: On 8 d?c, 14:09, Steve Holden wrote: > > If you'd told us which IDE you were using we might have offered better > advice, but you seem to want to keep that a secret ("my IDE" tells us > nothing). > sorry it was totally bottom of my first message : > note: I'm using Eclipse 3.5.2 with pydev so (I don't really know how others IDE can handle this case) . now I realyze that my question has not a lot to do with python language itself and I should resubmit that probably on pydev forums/.. but as I told I wanted to have some advises on the "good" (or not) use of this "way of doing" with python itself. You already explained me it's not the best so far.. and I agree although during (my) dev it helps ;) (but I do this only with very few classes that have lot of attributes/methods ofcourse). regards, greg. From rob.randall2 at gmail.com Wed Dec 8 09:44:30 2010 From: rob.randall2 at gmail.com (Rob Randall) Date: Wed, 8 Dec 2010 14:44:30 +0000 Subject: 64 bit memory usage Message-ID: I am trying to understand how much memory is available to a 64 bit python process running under Windows XP 64 bit. When I run tests just creating a series of large dictionaries containing string keys and float values I do not seem to be able to grow the process beyond the amount of RAM present. For example, on a box with 2GB RAM and 3 GB pagefile the process stalls at around 2GB. On another machine with 16GB RAM and 24GB pagefile the process stalls at 16GB. In other tests where a C++ program loads and runs the python DLL, if C++ based operations are performed the memory usage will grow to 40GB, but if python is used to grab the memory it can still only grow to 16GB. With this program if the memory usage is grown to over 16GB on the C++ side, attempting to grab any from python crashes the process. I was under the impression that python could grab as much memory as other programs. Can anyone tell me what is happening or where I may be going wrong? Thanks, Rob Randall -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Wed Dec 8 09:51:10 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 08 Dec 2010 15:51:10 +0100 Subject: use of __new__ to permit "dynamic" completion within (any?) IDE ? In-Reply-To: <8ec4f0a5-a7d7-46ef-91d2-2427f696cb11@y3g2000vbm.googlegroups.com> References: <0b90e80b-8b9b-412d-bfff-9a9ec4b172d2@h22g2000vbr.googlegroups.com> <4cff61e3$0$30002$c3e8da3$5496439d@news.astraweb.com> <8ec4f0a5-a7d7-46ef-91d2-2427f696cb11@y3g2000vbm.googlegroups.com> Message-ID: <4CFF9B5E.5060702@sequans.com> gst wrote: > greg. > > nb: so this "hack" is only relevant during dev ; once the project > would be finished the "hack" could be removed (i.e : in class2 init I > would directly do : self.object1 = object1) > Expect some bugs then on the 'release' version. I'm not sure I understood everything you mentioned in your OP, however writing python code on class creation to make Eclipse completion 'work' is ... a very bad idea IMO. Just don't do it. quoting eclipse page: "Pydev [...] uses advanced type inference techniques to provide features such code completion and code analysis" I don't know exactly what's hidden behind this marketing stuff. Did you try to document your method with a markup language supported by Eclipse (if there is any)? class class2(object): def __init__(self, object1, *args, **kwargs): """blablabla @param object1: a L{class1} reference """ self.object1 = object1 The docstring would be the only way for an IDE to infer a argument type. Note that I used the epydoc markup language because it's the only one I know but it's unlikely supported by Eclipse. You better try reStructuredText. JM From g.starck at gmail.com Wed Dec 8 10:20:25 2010 From: g.starck at gmail.com (gst) Date: Wed, 8 Dec 2010 07:20:25 -0800 (PST) Subject: use of __new__ to permit "dynamic" completion within (any?) IDE ? References: <0b90e80b-8b9b-412d-bfff-9a9ec4b172d2@h22g2000vbr.googlegroups.com> <4cff61e3$0$30002$c3e8da3$5496439d@news.astraweb.com> <8ec4f0a5-a7d7-46ef-91d2-2427f696cb11@y3g2000vbm.googlegroups.com> Message-ID: On 8 d?c, 15:51, Jean-Michel Pichavant wrote: Hi, > gst wrote: > > nb: so this "hack" is only relevant during dev ; once the project > > would be finished the "hack" could be removed (i.e : in class2 init I > > would directly do : self.object1 = object1) > > Expect some bugs then on the 'release' version. even with the "assert(self is _self)" in the "if _self:" condition in the new and/or init methods of the class1 ? > I'm not sure I understood everything you mentioned in your OP, however > writing python code on class creation to make Eclipse completion 'work' > is ... a very bad idea IMO. > Just don't do it. yes I'm trying to find better ways for having completion works out of the box in this case.. (that would be a high help to my opinion). > quoting eclipse page: > > "Pydev [...] uses advanced type inference techniques to provide features > such code completion and code analysis" > > I don't know exactly what's hidden behind this marketing stuff. Did you > try to document your method with a markup language supported by Eclipse > (if there is any)? pydev completion apparently is restricted (as far as i see) to some very specific cases (basically it works when you import a module at top of another one and that you instantiate objects from the imported module within the init methods of the classes of the module which is importing the other one (but so "circular" references created on some objects from the first module (the one imported) in the second one won't have the completion working for them (that's what I see)). > class class2(object): > ? ? def __init__(self, object1, *args, **kwargs): > ? ? """blablabla > > ? ? @param object1: a L{class1} reference > ? ? """ > ? ? self.object1 = object1 > > The docstring would be the only way for an IDE to infer a argument type. > Note that I used the epydoc markup language because it's the only one I > know but it's unlikely supported by Eclipse. You better try > reStructuredText. > > JM well, I'm not very used to docstrings in fact but it's effectively a way to achieve this ; well certainly better than doing this kind of "ugly" hack so. I'll have a try at that. Thanks for your reply, regards, greg. From g.starck at gmail.com Wed Dec 8 10:23:45 2010 From: g.starck at gmail.com (gst) Date: Wed, 8 Dec 2010 07:23:45 -0800 (PST) Subject: use of __new__ to permit "dynamic" completion within (any?) IDE ? References: <0b90e80b-8b9b-412d-bfff-9a9ec4b172d2@h22g2000vbr.googlegroups.com> <4cff61e3$0$30002$c3e8da3$5496439d@news.astraweb.com> <8ec4f0a5-a7d7-46ef-91d2-2427f696cb11@y3g2000vbm.googlegroups.com> Message-ID: <070fc00b-fa60-4b10-8629-7dc836ef8d99@p11g2000vbn.googlegroups.com> On 8 d?c, 16:20, gst wrote: > On 8 d?c, 15:51, Jean-Michel Pichavant wrote: > > Hi, > > > gst wrote: > > > nb: so this "hack" is only relevant during dev ; once the project > > > would be finished the "hack" could be removed (i.e : in class2 init I > > > would directly do : self.object1 = object1) > > > Expect some bugs then on the 'release' version. > > even with the "assert(self is _self)" in the "if _self:" condition in > the new and/or ?init methods of the class1 ? note: I don't know if that matters but I'm using __slots__ in this class1 .. greg. From g.starck at gmail.com Wed Dec 8 10:40:18 2010 From: g.starck at gmail.com (gst) Date: Wed, 8 Dec 2010 07:40:18 -0800 (PST) Subject: use of __new__ to permit "dynamic" completion within (any?) IDE ? References: <0b90e80b-8b9b-412d-bfff-9a9ec4b172d2@h22g2000vbr.googlegroups.com> <4cff61e3$0$30002$c3e8da3$5496439d@news.astraweb.com> <8ec4f0a5-a7d7-46ef-91d2-2427f696cb11@y3g2000vbm.googlegroups.com> Message-ID: <58605a3b-6572-449c-8dd9-87156af140b8@u9g2000pra.googlegroups.com> On 8 d?c, 16:20, gst wrote: > even with the "assert(self is _self)" in the "if _self:" condition in > the new and/or ?init methods of the class1 ? damn : in the init method only of course.. From jeanmichel at sequans.com Wed Dec 8 10:55:37 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 08 Dec 2010 16:55:37 +0100 Subject: use of __new__ to permit "dynamic" completion within (any?) IDE ? In-Reply-To: References: <0b90e80b-8b9b-412d-bfff-9a9ec4b172d2@h22g2000vbr.googlegroups.com> <4cff61e3$0$30002$c3e8da3$5496439d@news.astraweb.com> <8ec4f0a5-a7d7-46ef-91d2-2427f696cb11@y3g2000vbm.googlegroups.com> Message-ID: <4CFFAA79.3050106@sequans.com> >> quoting eclipse page: >> >> "Pydev [...] uses advanced type inference techniques to provide features >> such code completion and code analysis" >> >> I don't know exactly what's hidden behind this marketing stuff. Did you >> try to document your method with a markup language supported by Eclipse >> (if there is any)? >> > > pydev completion apparently is restricted (as far as i see) to some > very specific cases (basically it works when you import a module at > top of another one and that you instantiate objects from the imported > module within the init methods of the classes of the module which is > importing the other one (but so "circular" references created on some > objects from the first module (the one imported) in the second one > won't have the completion working for them (that's what I see)). > To understand what is possible and what is not, you simply need to think like a completion feature. case 1: self.object = MyClass() self.object is a MyClass instance, easy stuff I need to parse MyClass and get the list of attributes/method case 2: self.object = object1 There may be simply no way to know the type/class of object1, object1 could be even of an inconsistent type, sometimes None, int, MyClass, who knows ? Your trick worked because you found a way to write self.object = MyClass(object1) and getting barely the same effect than self.object = object1. I'm still thinking that's it's a bad idea. In any case your IDE can still be fooled by the dynamic of python (like pylint is) How to write python code then ? Well I guess most people either knows all the attributes by heart, have the documentation, or a split screen to the class definition, possibly folded using advanced text editor feature. You need to forget about code completion with any dynamic language. I also sometimes use an ipython shell to instanciate objects and inspect their attributes. JM From pruebauno at latinmail.com Wed Dec 8 10:56:42 2010 From: pruebauno at latinmail.com (nn) Date: Wed, 8 Dec 2010 07:56:42 -0800 (PST) Subject: use of __new__ to permit "dynamic" completion within (any?) IDE ? References: <0b90e80b-8b9b-412d-bfff-9a9ec4b172d2@h22g2000vbr.googlegroups.com> Message-ID: <713b9cdc-7ff2-45ba-8e68-ed341b7b6ea2@32g2000yqz.googlegroups.com> On Dec 7, 10:52?am, gst wrote: > Hi, > > I met a situation where I was passing an object created in/with an > upper level module class to a lower level module class' instance in > one of its __init__ argument and saving a ref of the upper object in > that lower level class' new instance. > > But in my IDE I want the completion to also work from within the lower > level module when it's refering to the object passed from the upper > level: > > Well, I'm sure I'm not very clear in my terms (and probably a bit long > in the sentence) so here it is in code: > > files: > module1.py > subpackage/module2.py > > file module1.py: > > from subpackage.module2 import class2 > > class class1(object): > > ? ? def __new__(cls, _self=None, *args, **kwargs): > ? ? ? ? if _self: ?## we've been passed an instance already > initialyzed > ? ? ? ? ? ? ? ? ? ? ?## so directly return it instead of creating a > new object. > ? ? ? ? ? ? return _self > ? ? ? ? return object.__new__(cls) > > ? ? def __init__(self, _self=None, *args, **kwargs): > ? ? ? ? if _self: ?## we've been passed an instance already > initialyzed > ? ? ? ? ? ? ? ? ? ? ?## so directly returns > ? ? ? ? ? ? ## assert(self is _self) ? > ? ? ? ? ? ? return > ? ? ? ? self.object2 = class2(object1=self, "blip", "blop") > ? ? ? ? # others init > > file module2.py: > > class class2(object): > > ? ? def __init__(self, object1, *args, **kwargs): > > ? ? ? ? from ..module1 import class1 > > ? ? ? ? self.object1 = class1(_self=object1) ? ?## instead of: > self.object1 = object1 > > ? ? ## others functions and/or init.. > ? ? ## where ?now I've completion working on self.object1 : > ? ? ## if I add(or remove) fields/methods in module1 (and save) then > ? ? ## I have them available(or disappeared) in the completion when > executed from this submodule. > ? ? ## This ofcourse permits to save me of remembering all of the > class1 attributes/methods when I'm working with self.object1 from > within one of class2 methods. > > What do you think of this ? > > I guess there can be others ways of doing this.. ?? > > Thanks, > > Regards, > > Greg. > > note: I'm using Eclipse 3.5.2 with pydev so (I don't really know how > others IDE can handle this case) . You might want to test with Wing IDE http://wingware.com/ using the 10 day trial version to see if that works just for kicks. I've heard it has the best autocomplete of all IDEs out there. From python at mrabarnett.plus.com Wed Dec 8 11:24:02 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 08 Dec 2010 16:24:02 +0000 Subject: Wanted: slow regexes In-Reply-To: <20101208124225.GA4846@xrgtn-q40> References: <4CFC61B0.8000109@mrabarnett.plus.com> <20101208124225.GA4846@xrgtn-q40> Message-ID: <4CFFB122.5040504@mrabarnett.plus.com> On 08/12/2010 12:42, Alexander Gattin wrote: > Hello, > > On Mon, Dec 06, 2010 at 04:08:16AM +0000, MRAB wrote: >> I'm looking for examples of regexes which are >> slow (especially those which seem never to >> finish) but whose results are known. > > does it have anything to do with > http://swtch.com/~rsc/regexp/regexp1.html? > The new regex still uses backtracking. Interestingly, that webpage says that: ("a" x 100000) =~ /^(ab?)*$/ caused Perl to segfault. I tried it and it didn't segfault, but it didn't match either, although: ("a" x 10000) =~ /^(ab?)*$/ did match. Neither the re nor regex modules had any problem with it! From katie at coderstack.co.uk Wed Dec 8 12:28:34 2010 From: katie at coderstack.co.uk (Katie T) Date: Wed, 8 Dec 2010 17:28:34 +0000 Subject: Calling FORTAN dll functions from Python In-Reply-To: <4cfe167a$0$81476$e4fe514c@news.xs4all.nl> References: <4cfe167a$0$81476$e4fe514c@news.xs4all.nl> Message-ID: On Tue, Dec 7, 2010 at 11:11 AM, Alex van der Spek wrote: > Does anyone know how to call functions from FORTRAN dlls in Python? Is it > even possible? I browsed the documentation for Python 2.6.1 and the Python/C > API comes close to what I would like to do but it is strictly limited to C. > > Unfortunately the passing of arguments in C and FORTRAN is very different, > not to mention the differences with strings where FORTRAN expects a hidden > length argument. It could call the FORTRAN dll from C and call the C > functions from Python but is that my only option? > > For reference: I am using Python 2.6.1 FORTRAN powerstation 4.0. It is not > an option to translate the FORTRAN code to C (using f2c) as the source code > is the official ASME version of calculating steam tables. > > I've done it before by creating C wrapper function and it was relatively painless, using C wrappers means that it's much easier to integrate into other languages as well if you need to do more integration down the line. Katie -- CoderStack http://www.coderstack.co.uk The Software Developer Job Board -------------- next part -------------- An HTML attachment was scrubbed... URL: From devplayer at gmail.com Wed Dec 8 12:32:58 2010 From: devplayer at gmail.com (DevPlayer) Date: Wed, 8 Dec 2010 09:32:58 -0800 (PST) Subject: Replacing globals in exec by custom class References: Message-ID: Couple of things: I don't think this is what you want: def __getitem__(self, key): import __builtin__ if key == 'xx': return 'xx' I won't return a KeyError for any string you give g[] It will return 'xx' only if you supply key='xx' and ignore every other key=??? With the above code you can do g['yyy'] and you would get None For your example code to work, line 14 in your example needs to be: elif key in self.__dict__: # (change else to elif) for your dict (or globalscl) to act like other dicts() add an else: raise KeyError( 'Key not found: %s' % (key,)) __dict__ of a dict I believe is not the namespace of dict. I thought dict[key] and dict.__dict__[key] where not the same place __dict__ of dict in Python 2.5 and prior was rumored to be buggy and unused. Don't know about Python 2.6 + I thought __getitem__() did not look in __dict__ of dict(). If I copy your code into a module globalcl.py and comment out "print xx" in the string, and in PyCrust I "import globalcl" I too get the results and errors you claim. If I then do: >>>globalcl.g.keys() I get: ['__builtins__'] >>>globalcl.g['__builtins__'] I get: nothing (or None) >>>globalcl.g['__builtin__'] I get: nothing (or None) # ------------------------- # interesting part >>>globalcl.g['xx'] I get: 'xx' >>>if 'xx' in globalcl.g: ... print True ...else: ... print False I get: False # ------------------------- >>>globalcl.g.__builtins__ AttributeError: 'Global' object has no attribute __builtins__' >>>globalcl.g.__builtins__ AttributeError: 'Global' object has no attribute '__builtin__' >>>globalcl.g.__dict__ {'q': } From devplayer at gmail.com Wed Dec 8 12:36:39 2010 From: devplayer at gmail.com (DevPlayer) Date: Wed, 8 Dec 2010 09:36:39 -0800 (PST) Subject: Replacing globals in exec by custom class References: Message-ID: <331b53be-f6d3-4f12-8ec5-9547c09c8001@h17g2000pre.googlegroups.com> Shouldn't return 'xx' be return self['xx'] From devplayer at gmail.com Wed Dec 8 12:47:30 2010 From: devplayer at gmail.com (DevPlayer) Date: Wed, 8 Dec 2010 09:47:30 -0800 (PST) Subject: Replacing globals in exec by custom class References: Message-ID: Shouldn't return 'xx' be return self['xx' I don't know why precisely you're using a class as a global namespace, not that I personally find fault with it. But here are some other things you can do. Idea one: ====================================================== class NS(object): """place to put junk""" ns = NS() ns.global_var1 = "SPAM and eggs" ns.global_var2 = "use as you like just prefix with ns." del ns.global_var # because I'm fickle dir(ns) Idea two: ====================================================== Instead of a class as a global namespace, use a module ns.py ------ """My global namespace""" # do not import anything or make # classes or run functions here, just a place to have varibles ns_var = "var defined in ns.py" ignore = ['__builtins__', '__class__', '__delattr__', '__dict__', '__doc__', '__file__', '__format__', '__getattribute__', '__hash__', '__init__', '__name__', '__new__', '__package__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__'] main.py -------- import ns import mod1 import mod2 import mod3 ns.main_var = "this is main var" ns.mod3_var = mod3.mod3_var ns.mod3_somefunc_var = mod3.somefunc.somefunc_var mod3.show( "ns.ns_var", ns.ns_var) mod3.show( "ns.main_var", ns.main_var) mod3.show( "ns.mod1_var", ns.mod1_var) mod3.show( "ns.mod2_var", ns.mod2_var) mod3.show( "ns.somefunc_var", ns.somefunc_var) mod3.show( "ns.mod3_var", ns.mod3_var) mod3.show( "ns.mod3_somefunc_var", ns.mod3_somefunc_var) mod3.show( "dir(ns)", dir(ns)) mod3.list_globals() mod1.py ------- import ns # good usage; var not in mod1 global namespace and value is not copied # from one namespace to another but just put in it. ns.mod1_var = "this is text in mod1" # therefore by doing this your code in mod1 is likely to use # ns.mod1_var and not just mod1_var -is- not ns.mod1_var mod2.py ------- import ns ns.mod2_var = "text in mod2" def somefunc(): # good app globals ns.somefunc_var = "make a var not in the global namespace of the mod2" ns.renamed_var = "rename this" somefunc() mod3.py ------- # mod3_var is misleading; because you might use it but mod3.mod3_var # would not be the same value as the ns.mod3_var mod3_var = "not assigned to ns from in mod3.py but from main.py" def somefunc(): # bad globals somefunc.somefunc_var = "make a var not in the global namespace of the mod3" somefunc.renamed_var = "rename this" somefunc() # instinate somefunc_var def show(astring, avalue): print astring print ' ', str(avalue) def list_globals(): print 'ns variable list' import ns print ' [', for item in dir(ns): if not item in ns.ignore: print "'" + item.strip() + "', ", print ']' From astar at spamcop.net Wed Dec 8 13:05:22 2010 From: astar at spamcop.net (astar) Date: Wed, 8 Dec 2010 10:05:22 -0800 (PST) Subject: Python creates "locked" temp dir References: <0c30c818-f73b-4b09-b707-64ea457c757d@z26g2000prf.googlegroups.com> <91dca7c4-00c7-44ad-8902-54221534107c@o9g2000pre.googlegroups.com> <51e4ed46-41dd-46db-b3c4-0fdb475be97f@o14g2000prn.googlegroups.com> Message-ID: Hi, I recently got caught on tempfiles with respect to urllib.urlretrieve, which can create a tmpfile. Ah, but the file simply could not be found on the file system, even as root. But within the program that created the tmpfile, you could do useful things with the tmpfile. So the discussion in this thread is useful to me in understanding the rules. But having been given a clue by someone else, I never did find any python library documentation that was at all informative, even to the level of discourse in this thread. But here is a relevant question: I wonder if a child process is the *same* process as the parent for these purposes? Thanks. max From alust at alust.homeunix.com Wed Dec 8 13:06:01 2010 From: alust at alust.homeunix.com (alust) Date: Wed, 8 Dec 2010 10:06:01 -0800 (PST) Subject: del operator and global namespace Message-ID: Hello, Can somebody explain this strange (to me) effect please. In this program it is impossible to access a global variable within a function: $ cat /tmp/test.py x='xxx' def f(): print x del x f() $ python /tmp/test.py Traceback (most recent call last): File "/tmp/test.py", line 6, in f() File "/tmp/test.py", line 3, in f print x UnboundLocalError: local variable 'x' referenced before assignment But if we comment the del operator the program will work: $ cat /tmp/test.py x='xxx' def f(): print x #del x f() $ python /tmp/test.py xxx So why in this example the print operator is influenced by del operator that should be executed after it? -- Thanks, Alexei From affdfsdfdsfsd at b.com Wed Dec 8 13:23:05 2010 From: affdfsdfdsfsd at b.com (Tracubik) Date: 08 Dec 2010 18:23:05 GMT Subject: email discovering code Message-ID: <4cffcd09$0$6546$4fafbaef@reader4.news.tin.it> Hi all, i remember i've found somewhere (i think here but i'm not sure) a signature of a user with a strange python code that, if runned on terminal, reveal the email of the contact Can anyone help me finding it? thanks Nico From lists at cheimes.de Wed Dec 8 13:23:57 2010 From: lists at cheimes.de (Christian Heimes) Date: Wed, 08 Dec 2010 19:23:57 +0100 Subject: Python creates "locked" temp dir In-Reply-To: References: <0c30c818-f73b-4b09-b707-64ea457c757d@z26g2000prf.googlegroups.com> <91dca7c4-00c7-44ad-8902-54221534107c@o9g2000pre.googlegroups.com> <51e4ed46-41dd-46db-b3c4-0fdb475be97f@o14g2000prn.googlegroups.com> Message-ID: Am 08.12.2010 19:05, schrieb astar: > Hi, > > I recently got caught on tempfiles with respect to > urllib.urlretrieve, which can create a tmpfile. Ah, but the file > simply could not be found on the file system, even as root. But > within the program that created the tmpfile, you could do useful > things with the tmpfile. So the discussion in this thread is useful > to me in understanding the rules. But having been given a clue by > someone else, I never did find any python library documentation that > was at all informative, even to the level of discourse in this > thread. By default the tempfile module creates anonymous temporary files. The files are created with O_CREAT | O_EXCL and unlinked ASAP. As a result the temporary file no longer has a filename on the file system, just an open file descriptor in the current process. If you need a file with a name, use the NamedTemporaryFile feature of the tempfile module. Christian From awilliam at whitemice.org Wed Dec 8 13:24:53 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Wed, 08 Dec 2010 13:24:53 -0500 Subject: class browser In-Reply-To: References: Message-ID: <1291832693.3706.0.camel@linux-yu4c.site> On Wed, 2010-12-08 at 13:18 +0530, Rustom Mody wrote: > If I have a medium to large python code base to browse/study, what are > the class browsers available? Monodevelop has good Python support which includes a working Python class browser for Python projects & solutions. From lists at cheimes.de Wed Dec 8 13:26:59 2010 From: lists at cheimes.de (Christian Heimes) Date: Wed, 08 Dec 2010 19:26:59 +0100 Subject: Python creates "locked" temp dir In-Reply-To: <91dca7c4-00c7-44ad-8902-54221534107c@o9g2000pre.googlegroups.com> References: <0c30c818-f73b-4b09-b707-64ea457c757d@z26g2000prf.googlegroups.com> <91dca7c4-00c7-44ad-8902-54221534107c@o9g2000pre.googlegroups.com> Message-ID: Am 08.12.2010 10:31, schrieb Alex Willmer: > 2. When you say "I am unable to access". Do you mean another script/ > process is unable to access? If so, that is the point of mkdtemp() - > to make a temporary directory that _only_ the creating process can > access. If you want to share it then tempfile is not the right module > for you. There isn't a way to limit access to a single process. mkdtemp creates the directory with mode 0700 and thus limits it to the (effective) user of the current process. Any process of the same user is able to access the directory. Christian From python at mrabarnett.plus.com Wed Dec 8 13:32:14 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 08 Dec 2010 18:32:14 +0000 Subject: del operator and global namespace In-Reply-To: References: Message-ID: <4CFFCF2E.6080506@mrabarnett.plus.com> On 08/12/2010 18:06, alust wrote: > Hello, > > Can somebody explain this strange (to me) effect please. > > In this program it is impossible to access a global variable within a > function: > > $ cat /tmp/test.py > x='xxx' > def f(): > print x > del x > > f() > > $ python /tmp/test.py > Traceback (most recent call last): > File "/tmp/test.py", line 6, in > f() > File "/tmp/test.py", line 3, in f > print x > UnboundLocalError: local variable 'x' referenced before assignment > > But if we comment the del operator the program will work: > > $ cat /tmp/test.py > x='xxx' > def f(): > print x > #del x > > f() > > $ python /tmp/test.py > xxx > > So why in this example the print operator is influenced by del > operator > that should be executed after it? > The Python source code is compiled to bytecodes which are then interpreted. It's during the compilation stage that it determines whether a name is local. If you bind to a name: x = 0 or del a name: del x anywhere in the function, it takes that name to be local. When it actually interprets the bytecode at the print statement it tries to reference the name, but nothing has been bound to it yet, so it raises an exception. From gerald.britton at gmail.com Wed Dec 8 13:39:45 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Wed, 8 Dec 2010 13:39:45 -0500 Subject: PEP8 compliance and exception messages ? Message-ID: I'm a bit late to the discussion, but remembering that raise takes an expression, I can break it up like this: >>> raise ( ... Exception ( ... "Long " ... "exception " ... "text." ... ) ... ) Traceback (most recent call last): File "", line 3, in Exception: Long exception text Then, you can indent the individual lines any way you like. -- Gerald Britton From drsalists at gmail.com Wed Dec 8 13:52:00 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 8 Dec 2010 10:52:00 -0800 Subject: del operator and global namespace In-Reply-To: References: Message-ID: Please try adding "global x" to the beginning of f(). On Wed, Dec 8, 2010 at 10:06 AM, alust wrote: > Hello, > > Can somebody explain this strange (to me) effect please. > > In this program it is impossible to access a global variable within a > function: > > $ cat /tmp/test.py > x='xxx' > def f(): > ? ? print x > ? ? del x > > f() > > $ python /tmp/test.py > Traceback (most recent call last): > ? File "/tmp/test.py", line 6, in > ? ? f() > ? File "/tmp/test.py", line 3, in f > ? ? print x > UnboundLocalError: local variable 'x' referenced before assignment > > But if we comment the del operator the program will work: > > $ cat /tmp/test.py > x='xxx' > def f(): > ? ? print x > ? ? #del x > > f() > > $ python /tmp/test.py > xxx > > So why in this example the print operator is influenced by del > operator > that should be executed after it? > > -- > Thanks, Alexei > -- > http://mail.python.org/mailman/listinfo/python-list > From sudheer.s at sudheer.net Wed Dec 8 14:11:00 2010 From: sudheer.s at sudheer.net (Sudheer Satyanarayana) Date: Thu, 09 Dec 2010 00:41:00 +0530 Subject: email discovering code In-Reply-To: <4cffcd09$0$6546$4fafbaef@reader4.news.tin.it> References: <4cffcd09$0$6546$4fafbaef@reader4.news.tin.it> Message-ID: <4CFFD844.2000104@sudheer.net> On 12/08/2010 11:53 PM, Tracubik wrote: > Hi all, > i remember i've found somewhere (i think here but i'm not sure) a > signature of a user with a strange python code that, if runned on > terminal, reveal the email of the contact > > Can anyone help me finding it? > > thanks > Nico > import base64 encoded = base64.b64encode('my at email.address') print base64.b64decode(encoded) -- With warm regards, Sudheer. S Personal home page - http://sudheer.net | Tech Chorus - http://techchorus.net Web and IT services - http://binaryvibes.co.in From daniel.goertzen at gmail.com Wed Dec 8 14:42:00 2010 From: daniel.goertzen at gmail.com (Dan) Date: Wed, 8 Dec 2010 11:42:00 -0800 (PST) Subject: Can't deepcopy bytes-derived class Message-ID: <69dc1506-be6f-443c-95b8-7f214510f0ed@p7g2000prb.googlegroups.com> I have a simple type derived from bytes... class atom(bytes): pass ... that I cannot deepcopy(). The session below demonstrates how deepcopy() of "bytes" works fine, but deepcopy() of "atom" does not. What's going wrong? Thanks, Dan. Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit (Intel)] Type "help", "copyright", "credits" or "license" for more information. >>> import copy >>> class atom(bytes): ... pass ... >>> copy.deepcopy(b'abc') b'abc' >>> copy.deepcopy(atom(b'abc')) Traceback (most recent call last): File "C:\Program Files (x86)\Wing IDE 3.2\src\debug\tserver \_sandbox.py", line 1, in # Used internally for debug sandbox under external interpreter File "C:\Python31\Lib\copy.py", line 173, in deepcopy y = _reconstruct(x, rv, 1, memo) File "C:\Python31\Lib\copy.py", line 280, in _reconstruct y = callable(*args) File "C:\Python31\Lib\copyreg.py", line 88, in __newobj__ return cls.__new__(cls, *args) builtins.TypeError: string argument without an encoding >>> From tjreedy at udel.edu Wed Dec 8 15:00:12 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 08 Dec 2010 15:00:12 -0500 Subject: Replacing globals in exec by custom class In-Reply-To: References: Message-ID: On 12/8/2010 8:01 AM, Jonathan S wrote: > class Global(dict): > def __init__(self): > pass > def __getitem__(self, key): > import __builtin__ > if key == 'xx': > return 'xx' > > if hasattr(__builtin__, key): > return getattr(__builtin__, key) > > else key in self.__dict__: > return self.__dict__[key] syntax error > def __setitem__(self, key, value): > self.__dict__[key] = value > > def __str__(self): > return ' ' + unicode(self.__dict__) > > > code=""" > print globals() > print xx # Does work, prints 'xx' > > def q(): > print globals().__getitem__('xx') # Does work, prints 'xx' > print globals()['xx'] # Does work, prints 'xx' > print xx # Does not work, cannot find xx > q() > """ > g = Global() > > exec(compile(code, 'my code', 'exec'), g, g) > }}} When asking such questions, paste both the actual code that compiled and ran and the actual traceback you got in response. -- Terry Jan Reedy From brenNOSPAMbarn at NObrenSPAMbarn.net Wed Dec 8 15:09:19 2010 From: brenNOSPAMbarn at NObrenSPAMbarn.net (OKB (not okblacke)) Date: Wed, 8 Dec 2010 20:09:19 +0000 (UTC) Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> <7x39qbfhd8.fsf@ruckus.brouhaha.com> <87lj42liu2.fsf.mdw@metalzone.distorted.org.uk> <7491b308-0e41-416b-84e9-1ed5ff3408be@n32g2000pre.googlegroups.com> <874oaqld0v.fsf.mdw@metalzone.distorted.org.uk> Message-ID: Mark Wooding wrote: > Any code called from within the `with handler' context will (unless > overridden) cause a call `toy(x, 0)' to return 42. Even if the `with > handler' block calls other functions and so on. Note also that the > expression of this is dynamically further from where the error is > signalled than the resume point (which is within the same function). > You can't do this with `try' ... `except'. Which was, of course, the > point. This is an interesting setup, but I'm not sure I see why you need it. If you know that, in a particular context, you want toy(x, 0) to result in 42 instead of ZeroDivisionError, why not just define safeToy(x, y): try: retVal = toy(x, y) except ZeroDivisionError: retVal = 42 return retVal . . . and then call safeToy instead of toy in those contexts? -- --OKB (not okblacke) Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown From mdw at distorted.org.uk Wed Dec 8 15:48:57 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 08 Dec 2010 20:48:57 +0000 Subject: Comparison with False - something I don't understand References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> <7x39qbfhd8.fsf@ruckus.brouhaha.com> <87lj42liu2.fsf.mdw@metalzone.distorted.org.uk> <7491b308-0e41-416b-84e9-1ed5ff3408be@n32g2000pre.googlegroups.com> <874oaqld0v.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <87zksghtxi.fsf.mdw@metalzone.distorted.org.uk> "OKB (not okblacke)" writes: > This is an interesting setup, but I'm not sure I see why you need > it. If you know that, in a particular context, you want toy(x, 0) to > result in 42 instead of ZeroDivisionError, ... and that's the point. You don't know whether you'll need it at the call site. Something further up has decided that, in its context, 42 shall be the magic value returned. In some other context, there shouldn't be a magic value, and the exception should terminate the program. My toy example was just that: a minimal example showing the machinery in action. The value of separating out exception handling like this is only apparent if there's a fair amount of code in between the policy (`return 42') and the site where the exception is signalled. Small examples of powerful abstractions aren't very convincing: a small example trivially doesn't require powerful abstraction. Sorry. -- [mdw] From nagle at animats.com Wed Dec 8 16:01:28 2010 From: nagle at animats.com (John Nagle) Date: Wed, 08 Dec 2010 13:01:28 -0800 Subject: Comparisons of incompatible types In-Reply-To: <87ipz5jfr9.fsf.mdw@metalzone.distorted.org.uk> References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <4cfebe65$0$1590$742ec2ed@news.sonic.net> <87ipz5jfr9.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4cfff225$0$1650$742ec2ed@news.sonic.net> On 12/7/2010 3:59 PM, Mark Wooding wrote: >> Exactly one of >> > >> > a> b >> > a = b >> > a< b >> > >> > is true, or an type exception must be raised. > This will get the numerical people screaming. Non-signalling NaNs are > useful, and they don't obey these axioms. As a sometime numerical person, I've been screaming at this from the other side. The problem with comparing non-signalling NaNs is that eventually, the program has to make a control flow decision, and it may not make it correctly. I used to do dynamic simulation engines for animation. I was probably the first person to get ragdoll physics to work right, back in 1996-1997. In hard collisions, the program would get floating point overflows, and I had to abort the interation, back up, cut the time step down, and go forward again, until the time step was small enough to allow stable integration. This was under Windows on x86, where it's possible, in a Windows-dependent way, to catch signalling NaNs and turn the hardware exception into a C++ exception. If the computation just plowed ahead with non-signalling NaNs, with a check at the end, it could go wrong and produce bad results, because incorrect branches would be taken and the final bogus results might not contain NaNs. I personally think that comparing NaN with numbers or other NaNs should raise an exception. There's no valid result for such comparisons. John Nagle From tjreedy at udel.edu Wed Dec 8 16:16:11 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 08 Dec 2010 16:16:11 -0500 Subject: Can't deepcopy bytes-derived class In-Reply-To: <69dc1506-be6f-443c-95b8-7f214510f0ed@p7g2000prb.googlegroups.com> References: <69dc1506-be6f-443c-95b8-7f214510f0ed@p7g2000prb.googlegroups.com> Message-ID: On 12/8/2010 2:42 PM, Dan wrote: > I have a simple type derived from bytes... > > class atom(bytes): > pass > > ... that I cannot deepcopy(). The session below demonstrates how > deepcopy() of "bytes" works fine, but deepcopy() of "atom" does not. > What's going wrong? > > Thanks, > Dan. > > > Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit > (Intel)] > Type "help", "copyright", "credits" or "license" for more information. >>>> import copy >>>> class atom(bytes): > ... pass > ... >>>> copy.deepcopy(b'abc') > b'abc' >>>> copy.deepcopy(atom(b'abc')) > Traceback (most recent call last): > File "C:\Program Files (x86)\Wing IDE 3.2\src\debug\tserver > \_sandbox.py", line 1, in > # Used internally for debug sandbox under external interpreter > File "C:\Python31\Lib\copy.py", line 173, in deepcopy > y = _reconstruct(x, rv, 1, memo) > File "C:\Python31\Lib\copy.py", line 280, in _reconstruct > y = callable(*args) > File "C:\Python31\Lib\copyreg.py", line 88, in __newobj__ > return cls.__new__(cls, *args) > builtins.TypeError: string argument without an encoding You could trace through copy.py and copyreg.py to see where bytes and atom get treated differently. This might be a bug that should be reported on the tracker, but I do not know. Let see what anyone else says. -- Terry Jan Reedy From nagle at animats.com Wed Dec 8 17:49:55 2010 From: nagle at animats.com (John Nagle) Date: Wed, 08 Dec 2010 14:49:55 -0800 Subject: Comparisons of incompatible types In-Reply-To: <4cff5429$0$30002$c3e8da3$5496439d@news.astraweb.com> References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <871v5t13ok.fsf@benfinney.id.au> <4cff5429$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4d000b8f$0$1640$742ec2ed@news.sonic.net> On 12/8/2010 1:47 AM, Steven D'Aprano wrote: > On Wed, 08 Dec 2010 11:58:03 +1100, Ben Finney wrote: > >> Carl Banks writes: >> >>> On Dec 6, 4:17 pm, Steven D'Aprano>> +comp.lang.pyt... at pearwood.info> wrote: >>>> Nevertheless, I agree that in hindsight, the ability to sort such >>>> lists is not as important as the consistency of comparisons. >>> >>> I think that feeling the need to sort non-homogenous lists is >>> indicative of bad design. >> >> It can also be indicative of code written for a Python that doesn't have >> sets. > > Or a list that contains unhashable objects. If you can't hash it, and it doesn't have some definition of comparison associated with the object, you probably can't order it properly, either. "<" can't be some random function. For sorting to work, a < b and b < c implies a < c must hold. John Nagle From nad at acm.org Wed Dec 8 19:11:14 2010 From: nad at acm.org (Ned Deily) Date: Wed, 08 Dec 2010 16:11:14 -0800 Subject: Can't deepcopy bytes-derived class References: <69dc1506-be6f-443c-95b8-7f214510f0ed@p7g2000prb.googlegroups.com> Message-ID: In article , Terry Reedy wrote: > On 12/8/2010 2:42 PM, Dan wrote: > > I have a simple type derived from bytes... > > > > class atom(bytes): > > pass > > > > ... that I cannot deepcopy(). The session below demonstrates how > > deepcopy() of "bytes" works fine, but deepcopy() of "atom" does not. [...] > > Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit > > (Intel)] > > Type "help", "copyright", "credits" or "license" for more information. > >>>> import copy > >>>> class atom(bytes): > > ... pass > > ... > >>>> copy.deepcopy(b'abc') > > b'abc' > >>>> copy.deepcopy(atom(b'abc')) > > Traceback (most recent call last): > > File "C:\Program Files (x86)\Wing IDE 3.2\src\debug\tserver > > \_sandbox.py", line 1, in > > # Used internally for debug sandbox under external interpreter > > File "C:\Python31\Lib\copy.py", line 173, in deepcopy > > y = _reconstruct(x, rv, 1, memo) > > File "C:\Python31\Lib\copy.py", line 280, in _reconstruct > > y = callable(*args) > > File "C:\Python31\Lib\copyreg.py", line 88, in __newobj__ > > return cls.__new__(cls, *args) > > builtins.TypeError: string argument without an encoding > > You could trace through copy.py and copyreg.py to see where bytes and > atom get treated differently. > > This might be a bug that should be reported on the tracker, but I do not > know. Let see what anyone else says. FWIW, the example still fails with Python 3.1.3 but seems to work OK with a recent alpha build of Python 3.2. What specific change might have fixed it doesn't come immediately to mind. -- Ned Deily, nad at acm.org From philip at semanchuk.com Wed Dec 8 20:55:33 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 8 Dec 2010 20:55:33 -0500 Subject: is py2exe still active ? In-Reply-To: <0053AA37CC664343BD6FC2E75627821C@teddy> References: <5f32249f-50d4-440e-9005-04f954572894@32g2000yqz.googlegroups.com> <89dd2092-d6e9-4d5c-b966-54df3f48f065@g19g2000yqg.googlegroups.com> <2DEA78DF996B485E8B52F3B29B1124A1@teddy> <4CFEBBAE.2060400@holdenweb.com> <0053AA37CC664343BD6FC2E75627821C@teddy> Message-ID: On Dec 8, 2010, at 5:09 AM, Octavian Rasnita wrote: > Hi Steve, > > I may put some stupid questions because I am very new to Python, but... I heard about pypi/pip. Aren't all these Python libraries (like cxFreeze) provided on a central archive where we can get them and also report the bugs using a single request/issue tracker? Hi Octavian, I didn't see anyone reply to you on the list... The short answer to your question is "no". PyPI stands for the Python Package Index. The key word there is "Index". It's a catalog of packages but many of those packages are hosted elsewhere. The places where those packages are hosted may or may not have an issue tracker, etc. For instance, one the packages that I offer through PyPI (posix_ipc) is hosted on my personal Web site. Hope this helps Philip > ----- Original Message ----- > From: "Steve Holden" > Newsgroups: gmane.comp.python.general > To: "Octavian Rasnita" > Cc: > Sent: Wednesday, December 08, 2010 12:56 AM > Subject: Re: is py2exe still active ? > > >> Octavian: >> >> It's great that you want to let people know about bugs. Put yourself in >> the position of the package maintainer, however. She or he doesn't spend >> all day working on cxFreeze, and probably doesn't even do a Google >> search on cxFreeze very often. So they are unlikely to find out about >> this problem form your well-intentioned note. >> >> It's just possible nobody does care, as I can't find a link to an issue >> tracker - the best I could advise in this case would be to join the >> mailing list by visiting >> >> https://lists.sourceforge.net/lists/listinfo/cx-freeze-users >> >> regards >> Steve >> >> On 12/7/2010 6:49 PM, Octavian Rasnita wrote: >>> This packager is also nice. >>> >>> If someone cares, I've discovered a small bug in it. >>> If Python is installed on another drive than C under Windows, the cxfreeze.bat file still calls Python on the drive C and it doesn't work until it is corrected. >>> >>> Octavian >>> >>> ----- Original Message ----- >>> From: "Cbast" >>> Newsgroups: comp.lang.python >>> To: >>> Sent: Tuesday, December 07, 2010 5:00 PM >>> Subject: Re: is py2exe still active ? >>> >>> >>> On Dec 7, 8:23 am, Anders Persson wrote: >>>> Hi! >>>> When a look att py2exe homepage it is not looking like mutch happen, >>>> as a beginner i was thinking to start with Python 3, but i like to now >>>> if py2exe will be for 3 too. >>>> >>>> Is any one have any info ? >>> >>> I don't have the answer about py2exe, but I'm using cxFreeze to create >>> executables with Python 3.1, if it's what you're looking for. >>> >>> http://cx-freeze.sourceforge.net/ >> >> >> -- >> Steve Holden +1 571 484 6266 +1 800 494 3119 >> PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ >> See Python Video! http://python.mirocommunity.org/ >> Holden Web LLC http://www.holdenweb.com/ > -- > http://mail.python.org/mailman/listinfo/python-list From cdalten at gmail.com Wed Dec 8 21:00:43 2010 From: cdalten at gmail.com (chad) Date: Wed, 8 Dec 2010 18:00:43 -0800 (PST) Subject: Automating a shell session question Message-ID: <50fb4385-f8b7-4754-a8a5-e63820fee3b4@a28g2000prb.googlegroups.com> I manually log into a remote shell and so some stuff. After I do some stuff, I want the rest of the session to be automated. I've tried pexpect using the interact() function. However, I don't see any way to go into non-interactive mode going this route. Ideas? From tjreedy at udel.edu Wed Dec 8 22:05:26 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 08 Dec 2010 22:05:26 -0500 Subject: Can't deepcopy bytes-derived class In-Reply-To: References: <69dc1506-be6f-443c-95b8-7f214510f0ed@p7g2000prb.googlegroups.com> Message-ID: On 12/8/2010 7:11 PM, Ned Deily wrote: > In article, Terry > Reedy wrote: >> On 12/8/2010 2:42 PM, Dan wrote: >>> I have a simple type derived from bytes... >>> >>> class atom(bytes): pass >>> >>> ... that I cannot deepcopy(). The session below demonstrates >>> how deepcopy() of "bytes" works fine, but deepcopy() of "atom" >>> does not. > [...] >>> Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 >>> bit (Intel)] Type "help", "copyright", "credits" or "license" for >>> more information. >>>>>> import copy class atom(bytes): >>> ... pass ... >>>>>> copy.deepcopy(b'abc') >>> b'abc' >>>>>> copy.deepcopy(atom(b'abc')) >>> Traceback (most recent call last): File "C:\Program Files >>> (x86)\Wing IDE 3.2\src\debug\tserver \_sandbox.py", line 1, >>> in # Used internally for debug sandbox under external >>> interpreter File "C:\Python31\Lib\copy.py", line 173, in >>> deepcopy y = _reconstruct(x, rv, 1, memo) File >>> "C:\Python31\Lib\copy.py", line 280, in _reconstruct y = >>> callable(*args) File "C:\Python31\Lib\copyreg.py", line 88, in >>> __newobj__ return cls.__new__(cls, *args) builtins.TypeError: >>> string argument without an encoding >> >> You could trace through copy.py and copyreg.py to see where bytes >> and atom get treated differently. >> >> This might be a bug that should be reported on the tracker, but I >> do not know. Let see what anyone else says. > > FWIW, the example still fails with Python 3.1.3 but seems to work OK > with a recent alpha build of Python 3.2. What specific change might > have fixed it doesn't come immediately to mind. According to difflib.unified_diff, the only difference between Lib/copy.py from 3.1 to 3.2 is 4 lines: + +def _deepcopy_method(x, memo): # Copy instance methods + return type(x)(x.__func__, deepcopy(x.__self__, memo)) +_deepcopy_dispatch[types.MethodType] = _deepcopy_method (and none in copyreg.py) These were added in rev76572 as part of http://bugs.python.org/issue1515 Guido decreed this to be a new feature rather than bugfix, so the change went into future 2.7 and 3.2 and not existing 2.6 and 3.1. Tto verify that these cause the change, comment out in 3.2 or add to 3.1. I have not read through the issue to understand it or why it would affect the OP's code case. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Wed Dec 8 22:30:39 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Dec 2010 03:30:39 GMT Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <4cfebe65$0$1590$742ec2ed@news.sonic.net> <87ipz5jfr9.fsf.mdw@metalzone.distorted.org.uk> <4cfff225$0$1650$742ec2ed@news.sonic.net> Message-ID: <4d004d5f$0$29985$c3e8da3$5496439d@news.astraweb.com> On Wed, 08 Dec 2010 13:01:28 -0800, John Nagle wrote: > On 12/7/2010 3:59 PM, Mark Wooding wrote: >>> Exactly one of >>> > >>> > a> b >>> > a = b >>> > a< b >>> > >>> > is true, or an type exception must be raised. >> This will get the numerical people screaming. Non-signalling NaNs are >> useful, and they don't obey these axioms. > > As a sometime numerical person, I've been screaming at this from > the other side. The problem with comparing non-signalling NaNs is that > eventually, the program has to make a control flow decision, and it may > not make it correctly. Then use signalling NANs. Nobody is suggesting that quiet NANs should be compulsory, or are the solution for all problems. But they're a solution for some problems, which is why people use them. [...] > I personally think that comparing NaN with numbers or other > NaNs should raise an exception. There's no valid result for such > comparisons. If NAN and 1 are unordered, then NAN is not less or equal to 1, nor is it larger than 1. Hence both NAN <= 1 and NAN >= 1 are false. The problem only comes when the caller mistakenly thinks that floats are real numbers, and tries to reason about floats like they would reason about real numbers. -- Steven From debatem1 at gmail.com Wed Dec 8 22:56:43 2010 From: debatem1 at gmail.com (geremy condra) Date: Wed, 8 Dec 2010 19:56:43 -0800 Subject: Comparisons of incompatible types In-Reply-To: <4cfff225$0$1650$742ec2ed@news.sonic.net> References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <4cfebe65$0$1590$742ec2ed@news.sonic.net> <87ipz5jfr9.fsf.mdw@metalzone.distorted.org.uk> <4cfff225$0$1650$742ec2ed@news.sonic.net> Message-ID: On Wed, Dec 8, 2010 at 1:01 PM, John Nagle wrote: > On 12/7/2010 3:59 PM, Mark Wooding wrote: >>> >>> Exactly one of >>> > >>> > ? ? ? a> ?b >>> > ? ? ? a = b >>> > ? ? ? a< ?b >>> > >>> > ?is true, or an type exception must be raised. >> >> This will get the numerical people screaming. ?Non-signalling NaNs are >> useful, and they don't obey these axioms. > > ? As a sometime numerical person, I've been screaming at this from > the other side. ? The problem with comparing non-signalling NaNs is that > eventually, the program has to make a control flow decision, and it > may not make it correctly. > > ? I used to do dynamic simulation engines for animation. ?I was > probably the first person to get ragdoll physics to work right, > back in 1996-1997. ?In hard collisions, the program would get > floating point overflows, and I had to abort the interation, back > up, cut the time step down, and go forward again, until the time > step was small enough to allow stable integration. ?This was > under Windows on x86, where it's possible, in a Windows-dependent > way, to catch signalling NaNs and turn the hardware exception into > a C++ exception. ?If the computation just plowed ahead with > non-signalling NaNs, with a check at the end, it could go wrong > and produce bad results, because incorrect branches would be taken > and the final bogus results might not contain NaNs. > > ? I personally think that comparing NaN with numbers or other > NaNs should raise an exception. ?There's no valid result for > such comparisons. This, in big letters. Geremy Condra From kirby.urner at gmail.com Wed Dec 8 23:03:05 2010 From: kirby.urner at gmail.com (kirby.urner at gmail.com) Date: Wed, 8 Dec 2010 20:03:05 -0800 (PST) Subject: win32 design pattern: COM localserver? Message-ID: <92573244-ab87-4143-9e87-26f851b6a3a1@w17g2000yqh.googlegroups.com> Greetings gurus. I'm faced with the challenge of having a single-threaded proprietary Win32 language wanting to do multiple calls against a Python COM object. Something like... loObj = CREATEOBJECT("map_maker") loObj.report( params, filename) do while .True. yadda yadda enddo RETURN I.e. the client program continues execution while loObj churns away somewhere doing work in Python, say accessing a MySQL database and building a map, embedding it in a PDF. Am I right that the COM object will need to "serve forever" i.e. be built around some non-terminating loop? Will the client's call then spawn a process or thread that continues until finished? All it has to do is leave a file on disk somewhere, then die. But the client can't be kept on the hook until that's all done. I've had good luck doing an InProcess COM object the generates a PDF from ReportLab. But this "stay alive while returning control to the client" challenge looks like it might be a job for sockets? Gee I hope not. Quick links to favorite blog articles will give me a sense of the ballpark... Any clues welcome. Yes, I have the Win32 book from O'Reilly. Kirby PS: my thanks to Ethan Furman for performing maintenance and upgrades on his dbf module on PyPI. The FoxPro gods thank you. http://pypi.python.org/pypi/dbf/0.88.16 PPS: some thoughts about IronPython filed here, after trying to catch up some, sorry about my formatting, here too. http://mail.python.org/pipermail/edu-sig/2010-December/010138.html From nagle at animats.com Wed Dec 8 23:16:57 2010 From: nagle at animats.com (John Nagle) Date: Wed, 08 Dec 2010 20:16:57 -0800 Subject: Comparisons of incompatible types In-Reply-To: References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <4cfebe65$0$1590$742ec2ed@news.sonic.net> <87ipz5jfr9.fsf.mdw@metalzone.distorted.org.uk> <4cfff225$0$1650$742ec2ed@news.sonic.net> Message-ID: <4d005835$0$1597$742ec2ed@news.sonic.net> On 12/8/2010 7:56 PM, geremy condra wrote: > On Wed, Dec 8, 2010 at 1:01 PM, John Nagle wrote: >> On 12/7/2010 3:59 PM, Mark Wooding wrote: >>>> >>>> Exactly one of >>>>> >>>>> a > b >>>>> a = b >>>>> a < b >>>>> >>>>> is true, or an type exception must be raised. Here's an example where this issue produces invalid results in Python. >>> NaN = float("nan") >>> arr = [1.0, 4.0, 3.0, 2.0, 5.0, NaN, 6.0, 3.0, NaN, 0.0, 1.0, 4.0, 3.0, 2.0, 5.0, NaN, 6.0, 3.0, NaN, 0.0] >>> sorted(arr) [0.0, 0.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 3.0, 3.0, 4.0, 5.0, nan, 5.0, 6.0, nan, 4.0, nan, 6.0, nan] The sorted numerical values aren't in order. Note the 4.0 near the end, after the 6.0. "sort" has failed because it assumes that a < b and b < c implies a < c. But that's not a valid assumption here. It's not good to break trichotomy. John Nagle From astan.chee at gmail.com Thu Dec 9 00:17:27 2010 From: astan.chee at gmail.com (Astan Chee) Date: Thu, 9 Dec 2010 16:17:27 +1100 Subject: RCX using python serial help In-Reply-To: <4CFEC76B.9080503@mrabarnett.plus.com> References: <4CFEC76B.9080503@mrabarnett.plus.com> Message-ID: Thanks for that help. I really appriciate it. My next question is how do I code or what is the checksum? The sum of opcode and arguments in hex and then mod 256? Does it include the compliment opcode and arguments as well? Is the checksum compliment equal to the sum of the opcode (and arguments) compliment? Thanks again for the clarification On 12/8/10, MRAB wrote: > On 06/12/2010 15:37, Astan Chee wrote: >> Hi, >> I've got a lego mindstorm RCX 1.0 (but firmware is 2.0) that uses one of >> those old serial IR towers to control the microcontroller. I've had a >> look around at python's serial documentation as well as the RCX's >> documentation and I'm trying to write something to control the RCX >> directly using python. Several examples from of doing this in python >> include using lnp (i think) and that doesn't quite run well in windows. >> I've had a look at the C++ code and some protocol documentation here: >> http://www.generation5.org/content/2001/rob08.asp and converted it to >> python. I've attached it at the end of the email. So now I've figured >> out how to check for the battery level and it seems to work (I've tested >> it on my RCX) but I'm confused with the other documentation (e.g. >> http://graphics.stanford.edu/~kekoa/rcx/ ) about how to do this in >> python or what this all means. I was wondering if anyone can help me >> complete these? or maybe help me do it step-by-step? >> Thanks for any help. > [snip] > Here's a brief summary of the protocol: > > A command or request to the microcontroller is a packet consisting of a > header, an opcode, arguments, and a checksum. > > The header used in the documentation is 0x55, 0xFF, 0x00. > > The opcode is 1 byte, followed by its one's complement. > > The argument is 0 or more bytes, each followed by its one's complement. > > The checksum is the sum of the opcode and the arguments, modulo 256, > followed by its one's complement. > > A reply from the microcontroller is also a packet consisting of a > header, an opcode, arguments, and a checksum. > > The header is the same as the original command or request. > > The opcode is the one's complement of the original opcode, followed by > its one's complement (ie, the original opcode). > > The argument is 0 or more bytes, each followed by its one's complement. > > The checksum is the sum of the opcode and the arguments, modulo 256, > followed by its one's complement. > > The microcontroller will ignore a packet whose opcode is the same as the > previous one; this is to prevent unintended duplicates due to > communication errors. > > Each opcode has 2 alternatives, one with bit 3 clear and the other with > bit 3 set (bitwise-ored with 0x08), so if you do want to send a command > or request with the same opcode as the previous packet you can just use > the alternative form. > -- > http://mail.python.org/mailman/listinfo/python-list > From rustompmody at gmail.com Thu Dec 9 01:10:42 2010 From: rustompmody at gmail.com (rusi) Date: Wed, 8 Dec 2010 22:10:42 -0800 (PST) Subject: trace cmd line args Message-ID: <37243f10-91f5-4a18-959f-fed96c145b36@29g2000prb.googlegroups.com> I am unable to get trace to not trace system modules. I tried: $ python -m trace --listfuncs tt.py --ignore-module 'bdb' > tracefile $ python -m trace --listfuncs --ignore-dir /usr/lib/python2.6 tt.py > tracefile and many other combinations But anyhow my tracefile contains lines like this: filename: /usr/lib/python2.6/bdb.py, modulename: bdb, funcname: filename: /usr/lib/python2.6/bdb.py, modulename: bdb, funcname: Bdb filename: /usr/lib/python2.6/bdb.py, modulename: bdb, funcname: BdbQuit filename: /usr/lib/python2.6/bdb.py, modulename: bdb, funcname: Breakpoint filename: /usr/lib/python2.6/bdb.py, modulename: bdb, funcname: Tdb filename: /usr/lib/python2.6/cmd.py, modulename: cmd, funcname: filename: /usr/lib/python2.6/cmd.py, modulename: cmd, funcname: Cmd filename: /usr/lib/python2.6/collections.py, modulename: collections, funcname: filename: /usr/lib/python2.6/collections.py, modulename: collections, funcname: namedtuple filename: /usr/lib/python2.6/dis.py, modulename: dis, funcname: filename: /usr/lib/python2.6/inspect.py, modulename: inspect, funcname: filename: /usr/lib/python2.6/inspect.py, modulename: inspect, funcname: BlockFinder filename: /usr/lib/python2.6/inspect.py, modulename: inspect, funcname: EndOfBlock filename: /usr/lib/python2.6/opcode.py, modulename: opcode, funcname: filename: /usr/lib/python2.6/opcode.py, modulename: opcode, funcname: def_op filename: /usr/lib/python2.6/opcode.py, modulename: opcode, funcname: jabs_op filename: /usr/lib/python2.6/opcode.py, modulename: opcode, funcname: jrel_op filename: /usr/lib/python2.6/opcode.py, modulename: opcode, funcname: name_op filename: /usr/lib/python2.6/pdb.py, modulename: pdb, funcname: filename: /usr/lib/python2.6/pdb.py, modulename: pdb, funcname: Pdb filename: /usr/lib/python2.6/pdb.py, modulename: pdb, funcname: Restart filename: /usr/lib/python2.6/pprint.py, modulename: pprint, funcname: From horos11 at gmail.com Thu Dec 9 02:29:52 2010 From: horos11 at gmail.com (Edward Peschko) Date: Wed, 8 Dec 2010 23:29:52 -0800 Subject: completely implicit interpolation based on a frame object Message-ID: >> Any ideas would be great on this, including pitfalls that people see >> in implementing it. >> > http://docs.python.org/library/string.html#template-strings > > regards > ?Steve Steve, Thanks for the tip, I did look at templates and decided that they weren't quite completely what I was looking for, although they could be part of the solution. 1. they require ${ } around the variables in question that you want to interpolate. When run through the trace hook, normal code doesn't do that. 2. they don't provide (AFAICT) a complete interpolation solution. Suppose I want to define custom interpolations in my tracer, like say, expanding out lists and dicts, or fleshing out objects using their stringification method. Does template do this? Formats may be a bit closer here, but I'm not sure if they are workable (or usable) with 2.5... which is where I need to work. Ed From ian.g.kelly at gmail.com Thu Dec 9 02:40:57 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 09 Dec 2010 00:40:57 -0700 Subject: 64 bit memory usage In-Reply-To: References: Message-ID: On 12/8/2010 11:42 PM, Dennis Lee Bieber wrote: > The page file can be larger than physical memory because it contains > memory "images" for multiple processes. However, all those "images" have > to map into the physically addressable memory -- so a process is likely > limited to physical memory, but you can have multiple processes adding > up to physical + pagefile in total. Only those pages that are currently paged in need be mapped to physical memory. The rest are not mapped to anything at all (other than a location in the page file) -- once a page is paged out, it need not be put back in its original page frame when it is paged in again. Since a process need not have all its pages in physical memory simultaneously, there is no reason to suppose that a single process could not consume the entirety of the available virtual memory (minus what is used by the operating system) on a 64-bit system (the same cannot be said of a 32-bit system, where the total virtual memory available may well be larger than the addressable space). From steve+comp.lang.python at pearwood.info Thu Dec 9 02:58:29 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Dec 2010 07:58:29 GMT Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <4cfebe65$0$1590$742ec2ed@news.sonic.net> <87ipz5jfr9.fsf.mdw@metalzone.distorted.org.uk> <4cfff225$0$1650$742ec2ed@news.sonic.net> <4d005835$0$1597$742ec2ed@news.sonic.net> Message-ID: <4d008c25$0$29987$c3e8da3$5496439d@news.astraweb.com> On Wed, 08 Dec 2010 20:16:57 -0800, John Nagle wrote: > Here's an example where this issue produces invalid results in > Python. > > >>> NaN = float("nan") > >>> arr = [1.0, 4.0, 3.0, 2.0, 5.0, NaN, 6.0, 3.0, NaN, 0.0, 1.0, 4.0, > 3.0, 2.0, 5.0, NaN, 6.0, 3.0, NaN, 0.0] > >>> sorted(arr) > [0.0, 0.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 3.0, 3.0, 4.0, 5.0, nan, 5.0, > 6.0, nan, 4.0, nan, 6.0, nan] > > The sorted numerical values aren't in order. Note the 4.0 near the end, > after the 6.0. "sort" has failed because it assumes that a < b and b < > c implies a < c. But that's not a valid assumption here. > > It's not good to break trichotomy. It's perfectly fine to break trichotomy. People do it all the time -- they prefer chicken to pizza, pizza to steak, but prefer steak to chicken. (Modulo whatever foods you prefer. Or sports, or politicians, or any one of many things which don't make up an equivalence relationship.) Equivalence relationships make up only a tiny portion of relationships, and it is both useful and conventional to use the same operators in both situations. What's not good is to assume trichotomy when it doesn't apply, but that's no different from any other faulty assumption, e.g. a coder who assumes multiplication is always commutative may be puzzled why his matrix calculations are frequently wrong. Python's sort assumes trichotomy, even when sorting floats. Perhaps it shouldn't. But one way or another, that's an issue with sort, not with the idea that there are data types where trichotomy doesn't apply. And like it or not, floats are one of those data types, just as neither commutativity nor associativity applies to floats -- even excluding NANs and INFs. -- Steven From orasnita at gmail.com Thu Dec 9 03:31:49 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Thu, 9 Dec 2010 10:31:49 +0200 Subject: is py2exe still active ? References: <5f32249f-50d4-440e-9005-04f954572894@32g2000yqz.googlegroups.com> <89dd2092-d6e9-4d5c-b966-54df3f48f065@g19g2000yqg.googlegroups.com><2DEA78DF996B485E8B52F3B29B1124A1@teddy><4CFEBBAE.2060400@holdenweb.com><0053AA37CC664343BD6FC2E75627821C@teddy> Message-ID: Hi Philip, I thought that pypi works like cpan for Perl, but now I understand. Thank you for clarifications. -- Octavian --- From: "Philip Semanchuk" > > On Dec 8, 2010, at 5:09 AM, Octavian Rasnita wrote: > >> Hi Steve, >> >> I may put some stupid questions because I am very new to Python, but... I heard about pypi/pip. Aren't all these Python libraries (like cxFreeze) provided on a central archive where we can get them and also report the bugs using a single request/issue tracker? > > Hi Octavian, > I didn't see anyone reply to you on the list... > > The short answer to your question is "no". PyPI stands for the Python Package Index. The key word there is "Index". It's a catalog of packages but many of those packages are hosted elsewhere. The places where those packages are hosted may or may not have an issue tracker, etc. > > For instance, one the packages that I offer through PyPI (posix_ipc) is hosted on my personal Web site. > > Hope this helps > Philip > > >> ----- Original Message ----- >> From: "Steve Holden" >> Newsgroups: gmane.comp.python.general >> To: "Octavian Rasnita" >> Cc: >> Sent: Wednesday, December 08, 2010 12:56 AM >> Subject: Re: is py2exe still active ? >> >> >>> Octavian: >>> >>> It's great that you want to let people know about bugs. Put yourself in >>> the position of the package maintainer, however. She or he doesn't spend >>> all day working on cxFreeze, and probably doesn't even do a Google >>> search on cxFreeze very often. So they are unlikely to find out about >>> this problem form your well-intentioned note. >>> >>> It's just possible nobody does care, as I can't find a link to an issue >>> tracker - the best I could advise in this case would be to join the >>> mailing list by visiting >>> >>> https://lists.sourceforge.net/lists/listinfo/cx-freeze-users >>> >>> regards >>> Steve >>> >>> On 12/7/2010 6:49 PM, Octavian Rasnita wrote: >>>> This packager is also nice. >>>> >>>> If someone cares, I've discovered a small bug in it. >>>> If Python is installed on another drive than C under Windows, the cxfreeze.bat file still calls Python on the drive C and it doesn't work until it is corrected. >>>> >>>> Octavian >>>> >>>> ----- Original Message ----- >>>> From: "Cbast" >>>> Newsgroups: comp.lang.python >>>> To: >>>> Sent: Tuesday, December 07, 2010 5:00 PM >>>> Subject: Re: is py2exe still active ? >>>> >>>> >>>> On Dec 7, 8:23 am, Anders Persson wrote: >>>>> Hi! >>>>> When a look att py2exe homepage it is not looking like mutch happen, >>>>> as a beginner i was thinking to start with Python 3, but i like to now >>>>> if py2exe will be for 3 too. >>>>> >>>>> Is any one have any info ? >>>> >>>> I don't have the answer about py2exe, but I'm using cxFreeze to create >>>> executables with Python 3.1, if it's what you're looking for. >>>> >>>> http://cx-freeze.sourceforge.net/ >>> >>> >>> -- >>> Steve Holden +1 571 484 6266 +1 800 494 3119 >>> PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ >>> See Python Video! http://python.mirocommunity.org/ >>> Holden Web LLC http://www.holdenweb.com/ >> -- >> http://mail.python.org/mailman/listinfo/python-list > > -- > http://mail.python.org/mailman/listinfo/python-list From tjreedy at udel.edu Thu Dec 9 03:36:53 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 09 Dec 2010 03:36:53 -0500 Subject: Comparisons of incompatible types In-Reply-To: <4d008c25$0$29987$c3e8da3$5496439d@news.astraweb.com> References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <4cfebe65$0$1590$742ec2ed@news.sonic.net> <87ipz5jfr9.fsf.mdw@metalzone.distorted.org.uk> <4cfff225$0$1650$742ec2ed@news.sonic.net> <4d005835$0$1597$742ec2ed@news.sonic.net> <4d008c25$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 12/9/2010 2:58 AM, Steven D'Aprano wrote: > On Wed, 08 Dec 2010 20:16:57 -0800, John Nagle wrote: > >> Here's an example where this issue produces invalid results in >> Python. >> >> >>> NaN = float("nan") >> >>> arr = [1.0, 4.0, 3.0, 2.0, 5.0, NaN, 6.0, 3.0, NaN, 0.0, 1.0, 4.0, >> 3.0, 2.0, 5.0, NaN, 6.0, 3.0, NaN, 0.0] >> >>> sorted(arr) >> [0.0, 0.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 3.0, 3.0, 4.0, 5.0, nan, 5.0, >> 6.0, nan, 4.0, nan, 6.0, nan] >> >> The sorted numerical values aren't in order. Note the 4.0 near the end, >> after the 6.0. "sort" has failed because it assumes that a< b and b< >> c implies a< c. But that's not a valid assumption here. This is transitivity. >> It's not good to break trichotomy. I believe that is that exactly one of <,=.> are true. -- Terry Jan Reedy From tjreedy at udel.edu Thu Dec 9 03:39:23 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 09 Dec 2010 03:39:23 -0500 Subject: trace cmd line args In-Reply-To: <37243f10-91f5-4a18-959f-fed96c145b36@29g2000prb.googlegroups.com> References: <37243f10-91f5-4a18-959f-fed96c145b36@29g2000prb.googlegroups.com> Message-ID: On 12/9/2010 1:10 AM, rusi wrote: > I am unable to get trace to not trace system modules. Try it with 3.2b1, just released. Multiple bugs were fixed in trace. Some fixes might also be in recent 2.7.1 and 3.1.3. Not sure. -- Terry Jan Reedy From eric.brunel at pragmadev.nospam.com Thu Dec 9 04:00:39 2010 From: eric.brunel at pragmadev.nospam.com (Eric Brunel) Date: Thu, 09 Dec 2010 10:00:39 +0100 Subject: Using a window style in a Toplevel window References: Message-ID: In article , craf wrote: > Hi. > > I use Python 3.1 and Tkinter.ttk 8.5 on Ubuntu 9.10. > > CODE:---------------------------------------------------- > > module:FMain.py > > from tkinter import ttk > from FSecondWindow import * > > class App: > def __init__(self,master): > > button1 = ttk.Button(master,text='Show > TopLevel',command=lambda:window()) > button1.pack() > > > master = Tk() > app = App(master) > style = ttk.Style() > style.theme_use('clam') > master.mainloop() > > > module:FSecondWindow.py > > from tkinter import * > from tkinter import ttk > > def window(): > t = Toplevel() > button2 = Button(t,text='Hello').pack() > > > CODE EXPLANATION:------------------------------------------- > > 1. From the main module FMain.py call the window function that is > located in FSecondWindow module and create a toplevel window. > > 2.I apply a theme called 'clam' to the master window to improve the > appearance of their widgets. > > QUERY:-------------------------------------------------- > > How I can make the toplevel window also take the theme 'clam'? Short answer: you can't. No directly anyway. Long answer: As you might be aware, there are 2 widget sets in tk/tkinter, the "old" one for which classes are directly in the tkinter module, and the new one that are in the ttk submodule. Only the second set supports theming, not the first one. Unfortunately, there are a few widgets that exist only in the first set, and Toplevel is one of those. So no theming is directly available for toplevels, and you can change whatever you want via style.theme_use, it won't be reflected on toplevels. By the way, as you wrote the code above, it won't be reflected on your button either, since you used the Button class, which is taken in tkinter directly, so it is the "old" Button class, not the new one. To get the new one, use ttk.Button, not Button. For your toplevel, there is however a simple workaround: Since there is a Frame widget in the new widget set, you can simply insert such a frame in your toplevel, make sure it will take the whole space, and then insert your widgets in this frame rather than in the toplevel directly. The code for your 'window' function would then become: def window() t = Toplevel() frm = ttk.Frame(t) frm.pack(fill=BOTH, expand=True) button2 = ttk.Button(frm, text='Hello') button2.pack() (Note also that I have put the creation of the button and its packing in 2 lines. You should never do variable = widget.pack(???) since pack does not return the widget. It always returns None, so doing so won't put your widget in the variable). The code above should do what you're after. > Thanks in advance. HTH - Eric - From astan.chee at gmail.com Thu Dec 9 04:54:22 2010 From: astan.chee at gmail.com (Astan Chee) Date: Thu, 9 Dec 2010 20:54:22 +1100 Subject: run a function in another processor in python Message-ID: Hi, I've got a python script that calls a function many times with various arguments and returns a result. What I'm trying to do is run this function each on different processors and compile the result at the end based on the function result. The script looks something like this: import time def functionTester(num): return ((num+2)/(num-2))**2 num_args = [1,2,3,7,12,16,19,35,36,37,38,55,56,57,63,44,71,81,91] max_result = 0 start = time.time() for n in num_args: result = functionTester(n) if result > max_result: max_result = result print "Result " + str(max_result) end = time.time() elapsed= end - start print "Took", elapsed, "seconds to execute" What I'm trying to do is run each function on a processor and when its done, move on to the next function-argument specifically on windows 7 x64 using python 2.6. How do I do this? Thanks for any help From jeanmichel at sequans.com Thu Dec 9 05:48:54 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 09 Dec 2010 11:48:54 +0100 Subject: run a function in another processor in python In-Reply-To: References: Message-ID: <4D00B416.5090509@sequans.com> Astan Chee wrote: > Hi, > I've got a python script that calls a function many times with various > arguments and returns a result. What I'm trying to do is run this > function each on different processors and compile the result at the > end based on the function result. The script looks something like > this: > > > import time > > def functionTester(num): > return ((num+2)/(num-2))**2 > > num_args = [1,2,3,7,12,16,19,35,36,37,38,55,56,57,63,44,71,81,91] > > max_result = 0 > > start = time.time() > > for n in num_args: > result = functionTester(n) > if result > max_result: > max_result = result > > print "Result " + str(max_result) > end = time.time() > elapsed= end - start > print "Took", elapsed, "seconds to execute" > > > What I'm trying to do is run each function on a processor and when its > done, move on to the next function-argument specifically on windows 7 > x64 using python 2.6. How do I do this? > Thanks for any help > If I'm not wrong, CPU management is handled by your system, meaning there's no way to 'force' anything to run on a specific CPU. However, you may try to execute your fonction in a subprocess, so that the system will use different CPUs (hopefully). You then just need to limit the number of subprocess alive at the same time. Have a look here http://docs.python.org/library/multiprocessing.html JM From markjason72 at gmail.com Thu Dec 9 06:32:04 2010 From: markjason72 at gmail.com (mark jason) Date: Thu, 9 Dec 2010 03:32:04 -0800 (PST) Subject: packaging python code in zip file Message-ID: <0119a6ea-7352-41f1-b8bf-46144d160d5d@i32g2000pri.googlegroups.com> hi, I have created a python app in eclipse pydev .The app is structured as below.. mypackage |______ __init__.py |______ driver.py |______ helper.py |______ utils.py The driver.py has the main program.I have added if __name__=="__main__" block in the driver.py and pydev's run configuration has the following values, Project : myproject Main Module :${workspace_loc:myproject/src/mypackage/driver.py} So,the app runs in pydev without any problems. Then I thought of providing the modules as a zip file.So I created a zip file containing mypackage directory.The user should be able to unzip the zip file and run the application from command line . What bothers me is that ,the user will have to cd to mypackage folder and run python driver.py.. This doesn't look like the proper way.. I also thought of putting the driver,helper,utils modules in a folder called mycode and zipping it without the __init__.py file . I am not sure which is the correct way. Can somebody advise me as to how I can package it better? thanks, mark From nitinpawar432 at gmail.com Thu Dec 9 06:49:23 2010 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Thu, 9 Dec 2010 17:19:23 +0530 Subject: packaging python code in zip file In-Reply-To: <0119a6ea-7352-41f1-b8bf-46144d160d5d@i32g2000pri.googlegroups.com> References: <0119a6ea-7352-41f1-b8bf-46144d160d5d@i32g2000pri.googlegroups.com> Message-ID: have u tried using setuptools and distutils they are used for python package distributions On Thu, Dec 9, 2010 at 5:02 PM, mark jason wrote: > hi, > I have created a python app in eclipse pydev .The app is structured as > below.. > > mypackage > |______ __init__.py > |______ driver.py > |______ helper.py > |______ utils.py > > The driver.py has the main program.I have added if > __name__=="__main__" block in the > > driver.py and pydev's run configuration has the following values, > Project : myproject > Main Module :${workspace_loc:myproject/src/mypackage/driver.py} > So,the app runs in pydev without any problems. > > Then I thought of providing the modules as a zip file.So I created a > zip file containing > mypackage directory.The user should be able to unzip the zip file and > run the application from command line . > > What bothers me is that ,the user will have to cd to mypackage folder > and run python driver.py.. > This doesn't look like the proper way.. > I also thought of putting the driver,helper,utils modules in a folder > called mycode and zipping it without the __init__.py file . > I am not sure which is the correct way. > Can somebody advise me as to how I can package it better? > > thanks, > > mark > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From prog at vtr.net Thu Dec 9 07:12:09 2010 From: prog at vtr.net (craf) Date: Thu, 09 Dec 2010 09:12:09 -0300 Subject: [Fwd: Re: Using a window style in a Toplevel window] Message-ID: <1291896729.2069.1.camel@cristian-desktop> --------- Mensaje reenviado -------- > De: Eric Brunel > Para: python-list at python.org > Asunto: Re: Using a window style in a Toplevel window > Fecha: Thu, 09 Dec 2010 10:00:39 +0100 > Grupos de noticias: comp.lang.python > > In article , > craf wrote: > > > Hi. > > > > I use Python 3.1 and Tkinter.ttk 8.5 on Ubuntu 9.10. > > > > CODE:---------------------------------------------------- > > > > module:FMain.py > > > > from tkinter import ttk > > from FSecondWindow import * > > > > class App: > > def __init__(self,master): > > > > button1 = ttk.Button(master,text='Show > > TopLevel',command=lambda:window()) > > button1.pack() > > > > > > master = Tk() > > app = App(master) > > style = ttk.Style() > > style.theme_use('clam') > > master.mainloop() > > > > > > module:FSecondWindow.py > > > > from tkinter import * > > from tkinter import ttk > > > > def window(): > > t = Toplevel() > > button2 = Button(t,text='Hello').pack() > > > > > > CODE EXPLANATION:------------------------------------------- > > > > 1. From the main module FMain.py call the window function that is > > located in FSecondWindow module and create a toplevel window. > > > > 2.I apply a theme called 'clam' to the master window to improve the > > appearance of their widgets. > > > > QUERY:-------------------------------------------------- > > > > How I can make the toplevel window also take the theme 'clam'? > > Short answer: you can't. No directly anyway. > > Long answer: As you might be aware, there are 2 widget sets in > tk/tkinter, the "old" one for which classes are directly in the tkinter > module, and the new one that are in the ttk submodule. Only the second > set supports theming, not the first one. Unfortunately, there are a few > widgets that exist only in the first set, and Toplevel is one of those. > So no theming is directly available for toplevels, and you can change > whatever you want via style.theme_use, it won't be reflected on > toplevels. > > By the way, as you wrote the code above, it won't be reflected on your > button either, since you used the Button class, which is taken in > tkinter directly, so it is the "old" Button class, not the new one. To > get the new one, use ttk.Button, not Button. > > For your toplevel, there is however a simple workaround: Since there is > a Frame widget in the new widget set, you can simply insert such a frame > in your toplevel, make sure it will take the whole space, and then > insert your widgets in this frame rather than in the toplevel directly. > The code for your 'window' function would then become: > > def window() > t = Toplevel() > frm = ttk.Frame(t) > frm.pack(fill=BOTH, expand=True) > button2 = ttk.Button(frm, text='Hello') > button2.pack() > > (Note also that I have put the creation of the button and its packing in > 2 lines. You should never do variable = widget.pack(?) since pack does > not return the widget. It always returns None, so doing so won't put > your widget in the variable). > > The code above should do what you're after. > > > Thanks in advance. > > HTH > - Eric - Hi Eric. ?Thank you very much, for the answer.! Regards Cristian Abarz?a F From rustompmody at gmail.com Thu Dec 9 07:12:25 2010 From: rustompmody at gmail.com (rusi) Date: Thu, 9 Dec 2010 04:12:25 -0800 (PST) Subject: trace cmd line args References: <37243f10-91f5-4a18-959f-fed96c145b36@29g2000prb.googlegroups.com> Message-ID: <41e52394-3a5a-409b-a9f1-ed0209ea38ef@p7g2000prb.googlegroups.com> On Dec 9, 1:39?pm, Terry Reedy wrote: > On 12/9/2010 1:10 AM, rusi wrote: > > > I am unable to get trace to not trace system modules. > > Try it with 3.2b1, just released. Multiple bugs were fixed in trace. > Some fixes might also be in recent 2.7.1 and 3.1.3. Not sure. > > -- > Terry Jan Reedy I am doing this to port a 2.x app to 3 which is giving me a hell of a time! :-; From python at bdurham.com Thu Dec 9 07:19:30 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 09 Dec 2010 07:19:30 -0500 Subject: Using a window style in a Toplevel window In-Reply-To: References: Message-ID: <1291897170.24466.1409471291@webmail.messagingengine.com> Eric, Besides style support, what are the advantages of ttk.Frame vs. Tkinter.Frame? Thanks, Malcolm From mdw at distorted.org.uk Thu Dec 9 07:21:45 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Thu, 09 Dec 2010 12:21:45 +0000 Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <4cfebe65$0$1590$742ec2ed@news.sonic.net> <87ipz5jfr9.fsf.mdw@metalzone.distorted.org.uk> <4cfff225$0$1650$742ec2ed@news.sonic.net> <4d005835$0$1597$742ec2ed@news.sonic.net> Message-ID: <87vd33i1ba.fsf.mdw@metalzone.distorted.org.uk> John Nagle writes: > >>> NaN = float("nan") > >>> arr = [1.0, 4.0, 3.0, 2.0, 5.0, NaN, 6.0, 3.0, NaN, 0.0, 1.0, 4.0, > 3.0, 2.0, 5.0, NaN, 6.0, 3.0, NaN, 0.0] > >>> sorted(arr) > [0.0, 0.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 3.0, 3.0, 4.0, 5.0, nan, 5.0, 6.0, > nan, 4.0, nan, 6.0, nan] > > The sorted numerical values aren't in order. Indeed. You failed to provide a valid ordering to `sorted'. By failing to satisfy its precondition, you relieved it of its obligation to satisfy its postcondition. > "sort" has failed because it assumes that a < b and b < c implies a < > c. But that's not a valid assumption here. > > It's not good to break trichotomy. You're confused. The property a < b and b < c => a < c is called `transitivity'. But the `float' ordering /is/ transitive. Note that a < b implies that neither a nor b is a NaN. Also, trichotomy is unnecessary for sorting, and Python's `sort' method doesn't require it; it does require a total preorder, though. What properties does a total preorder require? 1. Transitivity: a <= b and b <= c => a <= c 2. Totality: a <= b or b <= a The above list sorting goes wrong because the `float' ordering isn't total. In particular, x References: <4CFA4305.10004@it.uu.se> Message-ID: > 1. Pick a web framework, I'd suggest looking at: web2py: http://web2py.com - probably the easiest to install (no configuration needed) and learn. Suitable for both small and big projects. No worries when upgrading to a newer version as backward compatibility is an explicit design goal. From __peter__ at web.de Thu Dec 9 08:02:09 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 09 Dec 2010 14:02:09 +0100 Subject: packaging python code in zip file References: <0119a6ea-7352-41f1-b8bf-46144d160d5d@i32g2000pri.googlegroups.com> Message-ID: mark jason wrote: > hi, > I have created a python app in eclipse pydev .The app is structured as > below.. > > mypackage > |______ __init__.py > |______ driver.py > |______ helper.py > |______ utils.py > > The driver.py has the main program.I have added if > __name__=="__main__" block in the > > driver.py and pydev's run configuration has the following values, > Project : myproject > Main Module :${workspace_loc:myproject/src/mypackage/driver.py} > So,the app runs in pydev without any problems. > > Then I thought of providing the modules as a zip file.So I created a > zip file containing > mypackage directory.The user should be able to unzip the zip file and > run the application from command line . > > What bothers me is that ,the user will have to cd to mypackage folder > and run python driver.py.. > This doesn't look like the proper way.. > I also thought of putting the driver,helper,utils modules in a folder > called mycode and zipping it without the __init__.py file . > I am not sure which is the correct way. > Can somebody advise me as to how I can package it better? If you put a __main__.py file at the top level you can run the zip archive directly (requires Python 2.6): $ echo 'import alpha > print "main"' > __main__.py $ mkdir alpha $ echo 'print "init alpha"' > alpha/__init__.py $ zip -r demo . adding: alpha/ (stored 0%) adding: alpha/__init__.py (stored 0%) adding: __main__.py (stored 0%) $ rm -rf __main__.py alpha/ $ ls demo.zip $ python demo.zip init alpha main Peter From astan.chee at gmail.com Thu Dec 9 08:03:40 2010 From: astan.chee at gmail.com (Astan Chee) Date: Fri, 10 Dec 2010 00:03:40 +1100 Subject: run a function in another processor in python In-Reply-To: <4D00B416.5090509@sequans.com> References: <4D00B416.5090509@sequans.com> Message-ID: Thanks but I'm having trouble with that module too. Currently what I have is something like this: import sys import os import multiprocessing import time def functionTester(num): return ((num+2)/(num-2))**2 num_args = [61,62,33,7,12,16,19,35,36,37,38,55,56,57,63] max_result = 0 start = time.time() num_processes = multiprocessing.cpu_count() threads = [] len_stas = len(num_args) for list_item in num_args: if len(threads) < num_processes: p = multiprocessing.Process(target=functionTester,args=[list_item]) p.start() print p, p.is_alive() threads.append(p) else: for thread in threads: if not thread.is_alive(): threads.remove(thread) print "Result " + str(max_result) end = time.time() elapsed= end - start print "Took", elapsed, "seconds to execute" But it doesn't give me any return data. It also spawns an infinite number of (sub)processes that crashes my machine. What am I doing wrong here? On 12/9/10, Jean-Michel Pichavant wrote: > Astan Chee wrote: >> Hi, >> I've got a python script that calls a function many times with various >> arguments and returns a result. What I'm trying to do is run this >> function each on different processors and compile the result at the >> end based on the function result. The script looks something like >> this: >> >> >> import time >> >> def functionTester(num): >> return ((num+2)/(num-2))**2 >> >> num_args = [1,2,3,7,12,16,19,35,36,37,38,55,56,57,63,44,71,81,91] >> >> max_result = 0 >> >> start = time.time() >> >> for n in num_args: >> result = functionTester(n) >> if result > max_result: >> max_result = result >> >> print "Result " + str(max_result) >> end = time.time() >> elapsed= end - start >> print "Took", elapsed, "seconds to execute" >> >> >> What I'm trying to do is run each function on a processor and when its >> done, move on to the next function-argument specifically on windows 7 >> x64 using python 2.6. How do I do this? >> Thanks for any help >> > If I'm not wrong, CPU management is handled by your system, meaning > there's no way to 'force' anything to run on a specific CPU. However, > you may try to execute your fonction in a subprocess, so that the system > will use different CPUs (hopefully). You then just need to limit the > number of subprocess alive at the same time. > > Have a look here > http://docs.python.org/library/multiprocessing.html > > JM > From heather at dejaviewphoto.com Thu Dec 9 08:18:25 2010 From: heather at dejaviewphoto.com (Heather Brown) Date: Thu, 09 Dec 2010 08:18:25 -0500 Subject: 64 bit memory usage In-Reply-To: References: Message-ID: <4D00D721.4000306@dejaviewphoto.com> On 01/-10/-28163 02:59 PM, Dennis Lee Bieber wrote: > On Wed, 8 Dec 2010 14:44:30 +0000, Rob Randall > declaimed the following in gmane.comp.python.general: > >> I am trying to understand how much memory is available to a 64 bit python >> process running under Windows XP 64 bit. >> >> When I run tests just creating a series of large dictionaries containing >> string keys and float values I do not seem to be able to grow the process >> beyond the amount of RAM present. >> >> For example, on a box with 2GB RAM and 3 GB pagefile the process stalls at >> around 2GB. >> >> On another machine with 16GB RAM and 24GB pagefile the process stalls at >> 16GB. >> > > Probably need to ask M$, but I can understand this behavior as a > hypothetical... > > The page file can be larger than physical memory because it contains > memory "images" for multiple processes. However, all those "images" have > to map into the physically addressable memory -- so a process is likely > limited to physical memory, but you can have multiple processes adding > up to physical + pagefile in total. It's plausible that MS did that, but it's not reasonable. An application's entire data space is never in physical memory, except for trivial applications. When new pages are needed, old ones are swapped out, in an LRU manner. If the application is the only thing "running," it'll eventually be mapped into most of physical memory, but even then, the swapper keeps some back. The limit in 32bit world was 4gb, not whatever RAM happened to be in the machine. That limit came from the address space (or linear space, as MS calls it), not from the amount of RAM. It's only in recent years that those numbers have tended to be close. DaveA From jonathan.slenders at gmail.com Thu Dec 9 08:28:25 2010 From: jonathan.slenders at gmail.com (Jonathan S) Date: Thu, 9 Dec 2010 05:28:25 -0800 (PST) Subject: Replacing globals in exec by custom class References: Message-ID: <6f371eb9-8486-4598-b87d-97d74505c9cf@l17g2000yqe.googlegroups.com> Thanks for your response! (And sorry about the syntax error, I forgot to test my code after cleaning up some debug statements before posting, the else should have been elif indeed.) It's very interesing, how Python works internally. According to a thread on the Python mailing list in 2002, it seems that the implementation of CPython bypasses __getitem__ of the dict object, when it is used as Global namespace. (For performance reasons.) http://mail.python.org/pipermail/python-dev/2002-October/029753.html From ugnews at onlinehome.de Thu Dec 9 09:17:57 2010 From: ugnews at onlinehome.de (Uwe Grauer) Date: Thu, 09 Dec 2010 15:17:57 +0100 Subject: kinterbasdb error connection In-Reply-To: References: Message-ID: On 12/07/2010 04:35 PM, Ale Ghelfi wrote: > (i'm under Ubuntu 10.10 amd64 and python 2.6 and kinterbasdb 3.2 ) > I try to connect my database of firebird 2.5 by kinterbasdb. > But python return this error : You are not using the current kinterbasdb version. See: http://firebirdsql.org/index.php?op=devel&sub=python Uwe From daniel.goertzen at gmail.com Thu Dec 9 09:19:38 2010 From: daniel.goertzen at gmail.com (Dan) Date: Thu, 9 Dec 2010 06:19:38 -0800 (PST) Subject: Can't deepcopy bytes-derived class References: <69dc1506-be6f-443c-95b8-7f214510f0ed@p7g2000prb.googlegroups.com> Message-ID: <9946739d-fcd1-4c25-9a9d-f3a6b41aacb8@e20g2000vbn.googlegroups.com> On Dec 8, 9:05?pm, Terry Reedy wrote: > On 12/8/2010 7:11 PM, Ned Deily wrote: > > > > > > > > > > > In article, Terry > > Reedy ?wrote: > >> On 12/8/2010 2:42 PM, Dan wrote: > >>> I have a simple type derived from bytes... > > >>> class atom(bytes): pass > > >>> ... that I cannot deepcopy(). ?The session below demonstrates > >>> how deepcopy() of "bytes" works fine, but deepcopy() of "atom" > >>> does not. > > [...] > >>> Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 > >>> bit (Intel)] Type "help", "copyright", "credits" or "license" for > >>> more information. > >>>>>> import copy class atom(bytes): > >>> ... ? ? ? ?pass ... > >>>>>> copy.deepcopy(b'abc') > >>> b'abc' > >>>>>> copy.deepcopy(atom(b'abc')) > >>> Traceback (most recent call last): File "C:\Program Files > >>> (x86)\Wing IDE 3.2\src\debug\tserver \_sandbox.py", line 1, > >>> in # Used internally for debug sandbox under external > >>> interpreter File "C:\Python31\Lib\copy.py", line 173, in > >>> deepcopy y = _reconstruct(x, rv, 1, memo) File > >>> "C:\Python31\Lib\copy.py", line 280, in _reconstruct y = > >>> callable(*args) File "C:\Python31\Lib\copyreg.py", line 88, in > >>> __newobj__ return cls.__new__(cls, *args) builtins.TypeError: > >>> string argument without an encoding > > >> You could trace through copy.py and copyreg.py to see where bytes > >> and atom get treated differently. > > >> This might be a bug that should be reported on the tracker, but I > >> do not know. Let see what anyone else says. > > > FWIW, the example still fails with Python 3.1.3 but seems to work OK > > with a recent alpha build of Python 3.2. ?What specific change might > > have fixed it doesn't come immediately to mind. > > According to difflib.unified_diff, the only difference between > Lib/copy.py from 3.1 to 3.2 is 4 lines: > + > +def _deepcopy_method(x, memo): # Copy instance methods > + ? ?return type(x)(x.__func__, deepcopy(x.__self__, memo)) > +_deepcopy_dispatch[types.MethodType] = _deepcopy_method > > (and none in copyreg.py) > > These were added in rev76572 as part ofhttp://bugs.python.org/issue1515 > > Guido decreed this to be a new feature rather than bugfix, so the change > went into future 2.7 and 3.2 and not existing 2.6 and 3.1. > > Tto verify that these cause the change, comment out in 3.2 or add to > 3.1. I have not read through the issue to understand it or why it would > affect the OP's code case. > > -- > Terry Jan Reedy Thank you everyone. Knowing that it works in 3.2 is good enough for me. I tested the 4 line change anyway...removing it from 3.2 had no detrimental effect, adding it to 3.1 had no effect. It must be something else. Regards, Dan. From __peter__ at web.de Thu Dec 9 09:37:27 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 09 Dec 2010 15:37:27 +0100 Subject: run a function in another processor in python References: <4D00B416.5090509@sequans.com> Message-ID: Astan Chee wrote: > Thanks but I'm having trouble with that module too. Currently what I > have is something like this: > > import sys > import os > import multiprocessing > > import time > > def functionTester(num): > return ((num+2)/(num-2))**2 > > num_args = [61,62,33,7,12,16,19,35,36,37,38,55,56,57,63] > > max_result = 0 > > start = time.time() > > num_processes = multiprocessing.cpu_count() > > threads = [] > len_stas = len(num_args) > > for list_item in num_args: > if len(threads) < num_processes: > p = > multiprocessing.Process(target=functionTester,args=[list_item]) > p.start() print p, p.is_alive() > threads.append(p) > else: > for thread in threads: > if not thread.is_alive(): > threads.remove(thread) > > print "Result " + str(max_result) > end = time.time() > elapsed= end - start > print "Took", elapsed, "seconds to execute" > > But it doesn't give me any return data. It also spawns an infinite > number of (sub)processes that crashes my machine. What am I doing > wrong here? I can't replicate the crash. However, your problem looks like there is a ready-to-use solution: http://docs.python.org/library/multiprocessing.html#using-a-pool-of-workers From pruebauno at latinmail.com Thu Dec 9 10:49:37 2010 From: pruebauno at latinmail.com (nn) Date: Thu, 9 Dec 2010 07:49:37 -0800 (PST) Subject: completely implicit interpolation based on a frame object References: Message-ID: On Dec 9, 2:29?am, Edward Peschko wrote: > >> Any ideas would be great on this, including pitfalls that people see > >> in implementing it. > > >http://docs.python.org/library/string.html#template-strings > > > regards > > ?Steve > > Steve, > > Thanks for the tip, I did look at templates and decided that they > weren't quite completely what I was looking for, although they could > be part of the solution. > > 1. they require ${ } around the variables in question that you want to > interpolate. When run through the trace hook, normal code doesn't do > that. > 2. they don't provide (AFAICT) a complete interpolation solution. > Suppose I want to define custom interpolations in my tracer, like say, > expanding out lists and dicts, or fleshing out objects using their > stringification method. Does template do this? > > Formats may be a bit closer here, but I'm not sure if they are > workable (or usable) with 2.5... which is where I need to work. > > Ed One of the solutions from here might work for you: http://wiki.python.org/moin/Templating From tjreedy at udel.edu Thu Dec 9 10:50:16 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 09 Dec 2010 10:50:16 -0500 Subject: Can't deepcopy bytes-derived class In-Reply-To: <9946739d-fcd1-4c25-9a9d-f3a6b41aacb8@e20g2000vbn.googlegroups.com> References: <69dc1506-be6f-443c-95b8-7f214510f0ed@p7g2000prb.googlegroups.com> <9946739d-fcd1-4c25-9a9d-f3a6b41aacb8@e20g2000vbn.googlegroups.com> Message-ID: On 12/9/2010 9:19 AM, Dan wrote: > I tested the 4 line change anyway...removing it from 3.2 had no > detrimental effect, adding it to 3.1 had no effect. It must be > something else. Then there must have been a change in the bytes object, which is deeper than I want to go. 3.2 has a LOT of little improvements. When it comes out, just about all 3.1 users should upgrade unless one has production code disabled by a bugfix. -- Terry Jan Reedy From tjreedy at udel.edu Thu Dec 9 11:03:27 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 09 Dec 2010 11:03:27 -0500 Subject: trace cmd line args In-Reply-To: <41e52394-3a5a-409b-a9f1-ed0209ea38ef@p7g2000prb.googlegroups.com> References: <37243f10-91f5-4a18-959f-fed96c145b36@29g2000prb.googlegroups.com> <41e52394-3a5a-409b-a9f1-ed0209ea38ef@p7g2000prb.googlegroups.com> Message-ID: On 12/9/2010 7:12 AM, rusi wrote: > On Dec 9, 1:39 pm, Terry Reedy wrote: >> On 12/9/2010 1:10 AM, rusi wrote: >> >>> I am unable to get trace to not trace system modules. >> >> Try it with 3.2b1, just released. Multiple bugs were fixed in trace. >> Some fixes might also be in recent 2.7.1 and 3.1.3. Not sure. >> >> -- >> Terry Jan Reedy > > I am doing this to port a 2.x app to 3 which is giving me a hell of a > time! :-; I would get it to run on 2.7 first, with out getting any DeprecationWarnings when they are turned on. They are off by default and I am not sure how to turn on but presume the warnings module doc says how. -- Terry Jan Reedy From nobody at nowhere.com Thu Dec 9 11:17:06 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 09 Dec 2010 16:17:06 +0000 Subject: 64 bit memory usage References: Message-ID: Rob Randall wrote: > I am trying to understand how much memory is available to a 64 bit python > process running under Windows XP 64 bit. > > When I run tests just creating a series of large dictionaries containing > string keys and float values I do not seem to be able to grow the process > beyond the amount of RAM present. > > For example, on a box with 2GB RAM and 3 GB pagefile the process stalls at > around 2GB. What do you mean by "stalls"? Do you get an exception, or does the program just slow to a crawl? From eric.brunel at pragmadev.nospam.com Thu Dec 9 11:50:36 2010 From: eric.brunel at pragmadev.nospam.com (Eric Brunel) Date: Thu, 09 Dec 2010 17:50:36 +0100 Subject: Using a window style in a Toplevel window References: Message-ID: In article , python at bdurham.com wrote: > Eric, > > Besides style support, what are the advantages of ttk.Frame vs. > Tkinter.Frame? I'd say none. They are both just containers for other widgets, support the same layout managers, and so on. For me, using a ttk.Frame is really just for getting the correct theme, nothing else... > Thanks, > Malcolm From solipsis at pitrou.net Thu Dec 9 11:54:39 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Thu, 9 Dec 2010 17:54:39 +0100 Subject: 64 bit memory usage References: Message-ID: <20101209175439.3f0ffa35@pitrou.net> On Wed, 8 Dec 2010 14:44:30 +0000 Rob Randall wrote: > I am trying to understand how much memory is available to a 64 bit python > process running under Windows XP 64 bit. > > When I run tests just creating a series of large dictionaries containing > string keys and float values I do not seem to be able to grow the process > beyond the amount of RAM present. > > For example, on a box with 2GB RAM and 3 GB pagefile the process stalls at > around 2GB. > > On another machine with 16GB RAM and 24GB pagefile the process stalls at > 16GB. How is it surprising? When you go past the available RAM, your process starts swapping and everything becomes incredibly slower. Regards Antoine. From debatem1 at gmail.com Thu Dec 9 12:16:09 2010 From: debatem1 at gmail.com (geremy condra) Date: Thu, 9 Dec 2010 09:16:09 -0800 Subject: run a function in another processor in python In-Reply-To: References: <4D00B416.5090509@sequans.com> Message-ID: On Thu, Dec 9, 2010 at 5:03 AM, Astan Chee wrote: > Thanks but I'm having trouble with that module too. Currently what I > have is something like this: > > import sys > import os > import multiprocessing > > import time > > def functionTester(num): > ? ?return ((num+2)/(num-2))**2 > > num_args = [61,62,33,7,12,16,19,35,36,37,38,55,56,57,63] > > max_result = 0 > > start = time.time() > > num_processes = multiprocessing.cpu_count() > > threads = [] > len_stas = len(num_args) > > for list_item in num_args: > ? ?if len(threads) < num_processes: > ? ? ? ?p = multiprocessing.Process(target=functionTester,args=[list_item]) > ? ? ? ?p.start() > ? ? ? ?print p, p.is_alive() > ? ? ? ?threads.append(p) > ? ?else: > ? ? ? ?for thread in threads: > ? ? ? ? ? ?if not thread.is_alive(): > ? ? ? ? ? ? ? ?threads.remove(thread) > > print "Result " + str(max_result) > end = time.time() > elapsed= end - start > print "Took", elapsed, "seconds to execute" > > But it doesn't give me any return data. It also spawns an infinite > number of (sub)processes that crashes my machine. What am I doing > wrong here? > > On 12/9/10, Jean-Michel Pichavant wrote: >> Astan Chee wrote: >>> Hi, >>> I've got a python script that calls a function many times with various >>> arguments and returns a result. What I'm trying to do is run this >>> function each on different processors and compile the result at the >>> end based on the function result. The script looks something like >>> this: >>> >>> >>> import time >>> >>> def functionTester(num): >>> ? ? return ((num+2)/(num-2))**2 >>> >>> num_args = [1,2,3,7,12,16,19,35,36,37,38,55,56,57,63,44,71,81,91] >>> >>> max_result = 0 >>> >>> start = time.time() >>> >>> for n in num_args: >>> ? ? result = functionTester(n) >>> ? ? if result > max_result: >>> ? ? ? ? max_result = result >>> >>> print "Result " + str(max_result) >>> end = time.time() >>> elapsed= end - start >>> print "Took", elapsed, "seconds to execute" >>> >>> >>> What I'm trying to do is run each function on a processor and when its >>> done, move on to the next function-argument specifically on windows 7 >>> x64 using python 2.6. How do I do this? >>> Thanks for any help >>> >> If I'm not wrong, CPU management is handled by your system, meaning >> there's no way to 'force' anything to run on a specific CPU. However, >> you may try to execute your fonction in a subprocess, so that the system >> will use different CPUs (hopefully). You then just need to limit the >> number of subprocess alive at the same time. >> >> Have a look here >> http://docs.python.org/library/multiprocessing.html >> >> JM >> > -- > http://mail.python.org/mailman/listinfo/python-list > Here's a way of doing what I think you mean to do. I assume that max_result should be the maximum value returned by a run of functionTester. Also, just a note, usually function names like this are spelled function_tester rather than functionTester in python. If you need to de-python3ify it just change the line at the top and cast your nums to floats, otherwise you'll get integer division (which I again assume you don't want). #! /usr/bin/env python3 import time import multiprocessing def functionTester(num): return ((num+2)/(num-2))**2 num_args = [61,62,33,7,12,16,19,35,36,37,38,55,56,57,63] num_processes = multiprocessing.cpu_count() pool = multiprocessing.Pool(num_processes) start = time.time() results = pool.map(functionTester, num_args) end = time.time() # is this what you meant to do with the results? max_result = max(results) print("Result " + str(max_result)) elapsed = end - start print("Took", elapsed, "seconds to execute") Geremy Condra From rob.randall2 at gmail.com Thu Dec 9 12:18:19 2010 From: rob.randall2 at gmail.com (Rob Randall) Date: Thu, 9 Dec 2010 17:18:19 +0000 Subject: 64 bit memory usage In-Reply-To: <20101209175439.3f0ffa35@pitrou.net> References: <20101209175439.3f0ffa35@pitrou.net> Message-ID: But the C++ program using up memory does not slow up. It has gone to 40GB without much trouble. Does anyone have a 64 bit python application that uses more the 2GB? On 9 December 2010 16:54, Antoine Pitrou wrote: > On Wed, 8 Dec 2010 14:44:30 +0000 > Rob Randall wrote: > > I am trying to understand how much memory is available to a 64 bit python > > process running under Windows XP 64 bit. > > > > When I run tests just creating a series of large dictionaries containing > > string keys and float values I do not seem to be able to grow the process > > beyond the amount of RAM present. > > > > For example, on a box with 2GB RAM and 3 GB pagefile the process stalls > at > > around 2GB. > > > > On another machine with 16GB RAM and 24GB pagefile the process stalls at > > 16GB. > > How is it surprising? When you go past the available RAM, your process > starts swapping and everything becomes incredibly slower. > > Regards > > Antoine. > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rob.randall2 at gmail.com Thu Dec 9 12:18:58 2010 From: rob.randall2 at gmail.com (Rob Randall) Date: Thu, 9 Dec 2010 17:18:58 +0000 Subject: 64 bit memory usage In-Reply-To: <20101209175439.3f0ffa35@pitrou.net> References: <20101209175439.3f0ffa35@pitrou.net> Message-ID: Basically the process runs at around 1% and it never seems to grow in size again. When running the C++ with python app the process slows when a new 'page' is required but then goes back to 'full' speed. It does this until basically all the virtual memory is used. I have had memory exceptions when running the same sort of stuff on 32 bit, but never 64 bit. On 9 December 2010 16:54, Antoine Pitrou wrote: > On Wed, 8 Dec 2010 14:44:30 +0000 > Rob Randall wrote: > > I am trying to understand how much memory is available to a 64 bit python > > process running under Windows XP 64 bit. > > > > When I run tests just creating a series of large dictionaries containing > > string keys and float values I do not seem to be able to grow the process > > beyond the amount of RAM present. > > > > For example, on a box with 2GB RAM and 3 GB pagefile the process stalls > at > > around 2GB. > > > > On another machine with 16GB RAM and 24GB pagefile the process stalls at > > 16GB. > > How is it surprising? When you go past the available RAM, your process > starts swapping and everything becomes incredibly slower. > > Regards > > Antoine. > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nagle at animats.com Thu Dec 9 12:23:54 2010 From: nagle at animats.com (John Nagle) Date: Thu, 09 Dec 2010 09:23:54 -0800 Subject: 64 bit memory usage In-Reply-To: References: Message-ID: <4d0110a6$0$1607$742ec2ed@news.sonic.net> On 12/8/2010 11:40 PM, Ian Kelly wrote: > Since a process need not have all its pages in physical memory > simultaneously, there is no reason to suppose that a single process > could not consume the entirety of the available virtual memory (minus > what is used by the operating system) on a 64-bit system (the same > cannot be said of a 32-bit system, where the total virtual memory > available may well be larger than the addressable space). Actually, the "32-bit" x86 machines since the Pentium Pro are really 36 to 48-bit machines. They only offer 32-bit flat address spaces to user programs, but the MMU and memory interface support a larger address space. The page table design supports 64-bit physical memory, but most of the bits beyond 36 usually aren't implemented. Linux fully supported this; Windows tried, but older drivers were a problem. That's why there are 32 bit machines with more than 4GB of RAM. None of the real 64-bit architectures, from AMD64 to SPARC to Itanium, need this hack. John Nagle From benjamin.kaplan at case.edu Thu Dec 9 12:29:51 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 9 Dec 2010 12:29:51 -0500 Subject: 64 bit memory usage In-Reply-To: References: <20101209175439.3f0ffa35@pitrou.net> Message-ID: On Thursday, December 9, 2010, Rob Randall wrote: > But the C++ program using up memory does not slow up. > It has gone to 40GB without much trouble. > Your C++ program probably doesn't have a garbage collector traversing the entire allocated memory looking for reference cycles. > Does anyone have a 64 bit python application that uses more the 2GB? > > On 9 December 2010 16:54, Antoine Pitrou wrote: > On Wed, 8 Dec 2010 14:44:30 +0000 > Rob Randall wrote: >> I am trying to understand how much memory is available to a 64 bit python >> process running under Windows XP 64 bit. >> >> When I run tests just creating a series of large dictionaries containing >> string keys and float values I do not seem to be able to grow the process >> beyond the amount of RAM present. >> >> For example, on a box with 2GB RAM and 3 GB pagefile the process stalls at >> around 2GB. >> >> On another machine with 16GB RAM and 24GB pagefile the process stalls at >> 16GB. > > How is it surprising? When you go past the available RAM, your process > starts swapping and everything becomes incredibly slower. > > Regards > > Antoine. > > > -- > http://mail.python.org/mailman/listinfo/python-list > > From nagle at animats.com Thu Dec 9 12:34:19 2010 From: nagle at animats.com (John Nagle) Date: Thu, 09 Dec 2010 09:34:19 -0800 Subject: Comparisons of incompatible types In-Reply-To: References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <4cfebe65$0$1590$742ec2ed@news.sonic.net> <87ipz5jfr9.fsf.mdw@metalzone.distorted.org.uk> <4cfff225$0$1650$742ec2ed@news.sonic.net> <4d005835$0$1597$742ec2ed@news.sonic.net> <4d008c25$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4d011317$0$1664$742ec2ed@news.sonic.net> On 12/9/2010 12:36 AM, Terry Reedy wrote: > On 12/9/2010 2:58 AM, Steven D'Aprano wrote: >> On Wed, 08 Dec 2010 20:16:57 -0800, John Nagle wrote: > I believe that is that exactly one of <,=.> are true. Not for NaNs. >>> NaN = float('nan') >>> NaN == NaN False >>> NaN > NaN False >>> NaN < NaN False That's IEEE 754 compliant. NaN is not equal to NaN. That's by design. But it really messes up sorting. Python "dict" types, however, treat "NaN" as a unique value, because they're hash based on the underlying representation. (The best coverage of this whole topic was the Apple Numerics Manual for the original Mac. Apple hired the floating point expert from Berkeley to get this right. Then Apple went from the M68xxx series to the IBM PowerPC, and 80-bit floats to 64-bit floats, breaking all the engineering applications, most of which were never ported to the PowerPC.) John Nagle From rustompmody at gmail.com Thu Dec 9 12:37:27 2010 From: rustompmody at gmail.com (rusi) Date: Thu, 9 Dec 2010 09:37:27 -0800 (PST) Subject: trace cmd line args References: <37243f10-91f5-4a18-959f-fed96c145b36@29g2000prb.googlegroups.com> <41e52394-3a5a-409b-a9f1-ed0209ea38ef@p7g2000prb.googlegroups.com> Message-ID: <4587947a-e82a-43fb-9ef5-46ada0db8ee3@35g2000prt.googlegroups.com> On Dec 9, 9:03?pm, Terry Reedy wrote: > On 12/9/2010 7:12 AM, rusi wrote: > > > On Dec 9, 1:39 pm, Terry Reedy ?wrote: > >> On 12/9/2010 1:10 AM, rusi wrote: > > >>> I am unable to get trace to not trace system modules. > > >> Try it with 3.2b1, just released. Multiple bugs were fixed in trace. > >> Some fixes might also be in recent 2.7.1 and 3.1.3. Not sure. > > >> -- > >> Terry Jan Reedy > > > I am doing this to port a 2.x app to 3 which is giving me a hell of a > > time! :-; > > I would get it to run on 2.7 first, with out getting any > DeprecationWarnings when they are turned on. They are off by default and > I am not sure how to turn on but presume the warnings module doc says how. > > -- > Terry Jan Reedy This is a bit of a headache... Am on debian unstable but no 2.7 in the repos so I'll have to compile it... Ok can do that but first I'd like to check that this trace 'bug' has been cleared Where do I look? From rustompmody at gmail.com Thu Dec 9 12:47:35 2010 From: rustompmody at gmail.com (rusi) Date: Thu, 9 Dec 2010 09:47:35 -0800 (PST) Subject: trace cmd line args References: <37243f10-91f5-4a18-959f-fed96c145b36@29g2000prb.googlegroups.com> <41e52394-3a5a-409b-a9f1-ed0209ea38ef@p7g2000prb.googlegroups.com> <4587947a-e82a-43fb-9ef5-46ada0db8ee3@35g2000prt.googlegroups.com> Message-ID: On Dec 9, 10:37?pm, rusi wrote: > On Dec 9, 9:03?pm, Terry Reedy wrote: > > > > > On 12/9/2010 7:12 AM, rusi wrote: > > > > On Dec 9, 1:39 pm, Terry Reedy ?wrote: > > >> On 12/9/2010 1:10 AM, rusi wrote: > > > >>> I am unable to get trace to not trace system modules. > > > >> Try it with 3.2b1, just released. Multiple bugs were fixed in trace. > > >> Some fixes might also be in recent 2.7.1 and 3.1.3. Not sure. > > > >> -- > > >> Terry Jan Reedy > > > > I am doing this to port a 2.x app to 3 which is giving me a hell of a > > > time! :-; > > > I would get it to run on 2.7 first, with out getting any > > DeprecationWarnings when they are turned on. They are off by default and > > I am not sure how to turn on but presume the warnings module doc says how. > > > -- > > Terry Jan Reedy > > This is a bit of a headache... > Am on debian unstable but no 2.7 in the repos so I'll have to compile > it... > Ok can do that but first I'd like to check that this trace 'bug' has > been cleared > Where do I look? Ok Ive got 2.7 from 'experimental' without any (apparent) glitches From tlikonen at iki.fi Thu Dec 9 12:54:51 2010 From: tlikonen at iki.fi (Teemu Likonen) Date: Thu, 09 Dec 2010 19:54:51 +0200 Subject: Condition signals and restarts, resumable exceptions (was: Comparison with False - something I don't understand) References: <4CF779CE.3040209@ixokai.io> <4CF7B0BB.7080008@tim.thechases.com> <87d3pkp1z7.fsf.mdw@metalzone.distorted.org.uk> <4cf8923d$0$30003$c3e8da3$5496439d@news.astraweb.com> <87tyivnd0w.fsf.mdw@metalzone.distorted.org.uk> <7x39qbfhd8.fsf@ruckus.brouhaha.com> Message-ID: <87aakej0gk.fsf_-_@mithlond.arda> * 2010-12-06 00:14 (-0800), Paul Rubin wrote: > You know, I've heard the story from language designers several times > over, that they tried putting resumable exceptions into their > languages and it turned out to be a big mess, so they went to > termination exceptions that fixed the issue. Are there any languages > out there with resumable exceptions? As some people have pointer out Common Lisp is one of those languages. I don't know anything about language design, I'm just a hobbyist programmer, but I think Common Lisp's condition system and its restarts are straight-forward and easy to understand from programmer's point of view. Here's the relevant chapter in Peter Seibel's Practical Common Lisp: http://www.gigamonkeys.com/book/beyond-exception-handling-conditions-and-restarts.html From rob.randall2 at gmail.com Thu Dec 9 12:56:25 2010 From: rob.randall2 at gmail.com (Rob Randall) Date: Thu, 9 Dec 2010 17:56:25 +0000 Subject: 64 bit memory usage In-Reply-To: References: <20101209175439.3f0ffa35@pitrou.net> Message-ID: I will give it a try with the garbage collector disabled. On 9 December 2010 17:29, Benjamin Kaplan wrote: > On Thursday, December 9, 2010, Rob Randall wrote: > > But the C++ program using up memory does not slow up. > > It has gone to 40GB without much trouble. > > > > Your C++ program probably doesn't have a garbage collector traversing > the entire allocated memory looking for reference cycles. > > > Does anyone have a 64 bit python application that uses more the 2GB? > > > > On 9 December 2010 16:54, Antoine Pitrou wrote: > > On Wed, 8 Dec 2010 14:44:30 +0000 > > Rob Randall wrote: > >> I am trying to understand how much memory is available to a 64 bit > python > >> process running under Windows XP 64 bit. > >> > >> When I run tests just creating a series of large dictionaries containing > >> string keys and float values I do not seem to be able to grow the > process > >> beyond the amount of RAM present. > >> > >> For example, on a box with 2GB RAM and 3 GB pagefile the process stalls > at > >> around 2GB. > >> > >> On another machine with 16GB RAM and 24GB pagefile the process stalls at > >> 16GB. > > > > How is it surprising? When you go past the available RAM, your process > > starts swapping and everything becomes incredibly slower. > > > > Regards > > > > Antoine. > > > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From solipsis at pitrou.net Thu Dec 9 15:01:26 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Thu, 9 Dec 2010 21:01:26 +0100 Subject: 64 bit memory usage References: <20101209175439.3f0ffa35@pitrou.net> Message-ID: <20101209210126.5c85a7c7@pitrou.net> On Thu, 9 Dec 2010 17:18:58 +0000 Rob Randall wrote: > Basically the process runs at around 1% and it never seems to grow in size > again. > When running the C++ with python app the process slows when a new 'page' is > required but then goes back to 'full' speed. It does this until basically > all the virtual memory is used. Intuitively, Benjamin Kaplan had the right answer: Python will periodically walk the heap of objects to look for dead reference cycles to collect; if your working set is larger than the available RAM, then this will thrash the pagefile to death. So try gc.disable() before doing your tests. I would stress that, of course, you will still have performance problems as soon as you start using all those areas you are allocating. And if you don't use them, I guess there's no point allocating them either. So I don't know what exactly you're trying to do (is this an actual application? or just some random test you're doing?), but relying on the pagefile to have more available memory than the system RAM is a very bad idea IMO. Regards Antoine. From eric.frederich at gmail.com Thu Dec 9 15:23:40 2010 From: eric.frederich at gmail.com (Eric Frederich) Date: Thu, 9 Dec 2010 15:23:40 -0500 Subject: Reference counting problems? Message-ID: I am attempting to automate the building of binding for a 3rd party library. The functions I'm wrapping all return an integer of whether they failed and output are passed as pointers. There can be multiple return values. So the code that I generate has a PyObject* called python__return_val that I use for returning. In the 'wrapped_foo' function below you see I build the return value with Py_BuildValue and "OO" as the format. For every output I have I do a C to Python conversion and add another 'O' to the format. What I'm wondering is if I can use the same logic when wrapping functions that only return one value like the wrapped_bar function below. So for multiples, I wind up doing this which is fine. python__x = Py_BuildValue("s", x) python__y = Py_BuildValue("s", y) python__return_val = Py_BuildValue("OO", python__x, python__y); But for single returns I do something like this.... I realize that the 2 lines below are pointless, but are they causing a memory leak or problems with reference counting? python__x = Py_BuildValue("s", x) python__return_val = Py_BuildValue("O", python__x); Are python__x and python__return_val the same object, a copy of the object? Would python__x ever get garbage collected? Should my code generator detect when there is only one output and not go through the extra step? Thanks, ~Eric static PyObject * wrapped_foo(PyObject *self, PyObject *args) { int wrapp_fail; // C types int x; const char* some_str; int* y; char** abc; // Python types PyObject* python__return_val; PyObject* python__y; PyObject* python__abc; // Get Python args if (!PyArg_ParseTuple(args, "is", &x, &some_str)) return NULL; // Wrapped Call wrapp_fail = foo(x, some_str, &y, &abc); if(wrapp_fail != 0){ return NULL; } // Convert output to Python types python__y = Py_BuildValue("i", y) python__abc = Py_BuildValue("s", abc) // Build Python return value python__return_val = Py_BuildValue("OO", python__y, python__abc); // Memory free's MEM_free(abc) return python__return_val; } static PyObject * wrapped_bar(PyObject *self, PyObject *args) { int wrapp_fail; // C types int a; const char* b; char** c; // Python types PyObject* python__return_val; PyObject* python__c; // Get Python args if (!PyArg_ParseTuple(args, "is", &a, &b)) return NULL; // Wrapped Call wrapp_fail = bar(a, b, &c); if(wrapp_fail != 0){ return NULL; } // Convert output to Python types python__c = Py_BuildValue("s", c) // Build Python return value python__return_val = Py_BuildValue("O", python__c); // Memory free's MEM_free(c) return python__return_val; } From greno at verizon.net Thu Dec 9 16:29:33 2010 From: greno at verizon.net (Gerry Reno) Date: Thu, 09 Dec 2010 16:29:33 -0500 Subject: Added Python, WSGI to XAMPP In-Reply-To: <4CFD8B29.3020006@verizon.net> References: <4CFA4305.10004@it.uu.se> <4CFD6825.9020200@simplistix.co.uk> <4CFD8B29.3020006@verizon.net> Message-ID: <4D014A3D.7020101@verizon.net> If you have any need of a portable LAMP stack, I just finished writing some How-To's for getting Python, VirtualEnv and WSGI frameworks running with XAMPP: How-To: Add VirtualEnv and Pylons (WSGI framework) to XAMPP How-To: Add VirtualEnv and Django (WSGI framework) to XAMPP How-To: Add Python and mod_wsgi to XAMPP -Gerry From horos11 at gmail.com Thu Dec 9 16:37:40 2010 From: horos11 at gmail.com (Edward Peschko) Date: Thu, 9 Dec 2010 13:37:40 -0800 Subject: completely implicit interpolation based on a frame object (nn) Message-ID: >> a bit closer here, but I'm not sure if they are >> workable (or usable) with 2.5... which is where I need to work. >> >> Ed > > One of the solutions from here might work for you: > > http://wiki.python.org/moin/Templating > Ok, cool. A couple of followups - I'd be interested in knowing which of the solutions listed there was: 1. lightweight 2. usable with 2.5 (and if possible 2.3,2.2, and 2.1) 3. able to do inplace expansion of arrays and/or hashes, using arbitrary functions, in a simplistic way (perhaps like formats and the {var!func} syntax) I'll read up on them, but as it is with perl, you can spend a lot of time fiddling around with a module to find out that the implementation doesn't support the featureset that you are looking for, or otherwise is just plain junk, so pointers are definitely welcome on which one to use. -- Anyways, the problem isn't completely solved here. Since it is a free-flowing string that needs to be interpolated, there needs to be some way of picking out the identifiers that are to be evaluated and turning them into a template. In the following code: person="mary" print "then along came a person named ", person this has to evaluate to print "then along came a person named ", mary There's also subtleties here - if foo.somesuch is an attribute, there is no chance of a side effect, but if foo.somesuch is a property, then it could inadvertently cause side effects, and only one side effect can totally ruin your day (that was the bulk of the complexity in the perl version of this, ensuring no side effects in the expanded vars) Likewise, if a line of code spans multiple lines, you may have identifiers that span these multiple lines which means you may miss some substitutions. So, again, I'm interested in ways of getting around these problems. In perl its very easy to do this because of sigils, would very much like to know how to do the same thing in python. thanks much, Ed (ps - this is what I've got so far, which is basically cobbled together from stuff on stackoverflow. Works ok, but lines #15-#16 AFAICT are the one that needs to be bulletproofed: 1 import sys 2 import linecache 3 import random 4 5 def traceit(frame, event, arg): 6 if event == "line": 7 lineno = frame.f_lineno 8 filename = frame.f_globals["__file__"] 9 if filename == "": 10 filename = "traceit.py" 11 if (filename.endswith(".pyc") or 12 filename.endswith(".pyo")): 13 filename = filename[:-1] 14 name = frame.f_globals["__name__"] 15 line = linecache.getline(filename, lineno) 16 print "%s:%s:%s: %s" % (name, lineno,frame.f_code.co_name,line.rstrip()) 17 return traceit 18 20 sys.settrace(traceit) 21 main() ) ( pps - is there a collection of tracers somewhere? This seems definitely the thing that you'd want to collect in a library somewhere, and switch tracers as you see fit depending on what you are looking for.. ) From anurag.chourasia at gmail.com Thu Dec 9 17:31:04 2010 From: anurag.chourasia at gmail.com (Anurag Chourasia) Date: Fri, 10 Dec 2010 04:01:04 +0530 Subject: ***locale.Error: unsupported locale setting*** Message-ID: Hi All, When i try to set a locale manually, i get this error. >>> import locale >>> locale.setlocale(locale.LC_ALL, 'es_cl.iso88591') Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/locale.py", line 531, in setlocale return _setlocale(category, locale) locale.Error: unsupported locale setting On my OS, when i run the locale -a command, i get this output ------------------------- *locale -a* C POSIX en_US en_US.8859-15 en_US.ISO8859-1 ------------------------- Does this means that on my machine, Python will be able to make use of above listed locales? *If yes then how can i possibly use the locale.setformat (or anything else for that matter) to group numbers using '.' as the thousands separator?* If i use the locale en_US then ',' is the thousands separator. >>> import locale >>> locale.setlocale(locale.LC_ALL, 'en_US') 'en_US' >>> locale.format("%d", 1255000, grouping=True) '1,255,000' Regards, Anurag -------------- next part -------------- An HTML attachment was scrubbed... URL: From nagle at animats.com Thu Dec 9 17:44:59 2010 From: nagle at animats.com (John Nagle) Date: Thu, 09 Dec 2010 14:44:59 -0800 Subject: 64 bit memory usage In-Reply-To: References: Message-ID: <4d015be7$0$1670$742ec2ed@news.sonic.net> On 12/8/2010 10:42 PM, Dennis Lee Bieber wrote: > On Wed, 8 Dec 2010 14:44:30 +0000, Rob Randall > declaimed the following in gmane.comp.python.general: > >> I am trying to understand how much memory is available to a 64 bit python >> process running under Windows XP 64 bit. >> >> When I run tests just creating a series of large dictionaries containing >> string keys and float values I do not seem to be able to grow the process >> beyond the amount of RAM present. If you get to the point where you need multi-gigabyte Python dictionaries, you may be using the wrong tool for the job. If it's simply that you need to manage a large amount of data, that's what databases are for. If this is some super high performance application that needs to keep a big database in memory for performance reasons, CPython is probably too slow. For that, something like Google's BigTable may be more appropriate, and will scale to terabytes if necessary. John Nagle From steve+comp.lang.python at pearwood.info Thu Dec 9 18:11:28 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Dec 2010 23:11:28 GMT Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <4cfebe65$0$1590$742ec2ed@news.sonic.net> <87ipz5jfr9.fsf.mdw@metalzone.distorted.org.uk> <4cfff225$0$1650$742ec2ed@news.sonic.net> <4d005835$0$1597$742ec2ed@news.sonic.net> <87vd33i1ba.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <4d016220$0$30002$c3e8da3$5496439d@news.astraweb.com> On Thu, 09 Dec 2010 12:21:45 +0000, Mark Wooding wrote: > John Nagle writes: >> "sort" has failed because it assumes that a < b and b < c implies a < >> c. But that's not a valid assumption here. >> >> It's not good to break trichotomy. > > You're confused. The property > > a < b and b < c => a < c > > is called `transitivity'. Yes, but I believe that John is referring to the trichotomy (like a dichotomy, only there are three options instead of two) that exactly one of these relations are true: a < b a == b a > b It is true for real numbers, but not for IEEE floats, since none of the three are true if either a or b are a NAN. (Non-IEEE floats could do anything...) [...] > 2. Totality: a <= b or b <= a > > The above list sorting goes wrong because the `float' ordering isn't > total. In particular, x NaN!). I believe this is equivalent to trichotomy. > So, your last remark is in the right direction (though strict trichotomy > is unnecessary, as I've mentioned), but apparently only by accident > since the preceding discussion is completely wrong. "Completely" is surely a tad strong -- John might not be using the exact same terminology as you, but he's clearly talking about the equivalent concepts. He wants and expects all data types to either meet a total order, or raise an exception to any of the < > <= and >= operators. -- Steven From steve+comp.lang.python at pearwood.info Thu Dec 9 18:23:03 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Dec 2010 23:23:03 GMT Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <4cfebe65$0$1590$742ec2ed@news.sonic.net> <87ipz5jfr9.fsf.mdw@metalzone.distorted.org.uk> <4cfff225$0$1650$742ec2ed@news.sonic.net> <4d005835$0$1597$742ec2ed@news.sonic.net> <4d008c25$0$29987$c3e8da3$5496439d@news.astraweb.com> <4d011317$0$1664$742ec2ed@news.sonic.net> Message-ID: <4d0164d7$0$30002$c3e8da3$5496439d@news.astraweb.com> On Thu, 09 Dec 2010 09:34:19 -0800, John Nagle wrote: > (The best coverage of this whole topic was the Apple Numerics Manual > for the original Mac. Apple hired the floating point expert from > Berkeley to get this right. Then Apple went from the M68xxx series to > the IBM PowerPC, and 80-bit floats to 64-bit floats, breaking all the > engineering applications, most of which were never ported to the > PowerPC.) I second John's recommendation re the Apple Numerics Manual. Even if the Apple specific stuff is obsolete, it's a great resource for understanding floating point issues. -- Steven From steve+comp.lang.python at pearwood.info Thu Dec 9 18:44:35 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Dec 2010 23:44:35 GMT Subject: Request for feedback on API design Message-ID: <4d0169e2$0$30002$c3e8da3$5496439d@news.astraweb.com> I am soliciting feedback regarding the API of my statistics module: http://code.google.com/p/pycalcstats/ Specifically the following couple of issues: (1) Multivariate statistics such as covariance have two obvious APIs: A pass the X and Y values as two separate iterable arguments, e.g.: cov([1, 2, 3], [4, 5, 6]) B pass the X and Y values as a single iterable of tuples, e.g.: cov([(1, 4), (2, 5), (3, 6)] I currently support both APIs. Do people prefer one, or the other, or both? If there is a clear preference for one over the other, I may drop support for the other. (2) Statistics text books often give formulae in terms of sums and differences such as Sxx = n*?(x**2) - (?x)**2 There are quite a few of these: I count at least six common ones, all closely related and confusing named: Sxx, Syy, Sxy, SSx, SSy, SPxy (the x and y should all be subscript). Are they useful, or would they just add unnecessary complexity? Would people would like to see these included in the package? Thank you for your feedback. -- Steven From python at mrabarnett.plus.com Thu Dec 9 18:50:31 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 09 Dec 2010 23:50:31 +0000 Subject: Reference counting problems? In-Reply-To: References: Message-ID: <4D016B47.30206@mrabarnett.plus.com> On 09/12/2010 20:23, Eric Frederich wrote: > I am attempting to automate the building of binding for a 3rd party library. > The functions I'm wrapping all return an integer of whether they > failed and output are passed as pointers. > There can be multiple return values. > So the code that I generate has a PyObject* called python__return_val > that I use for returning. > In the 'wrapped_foo' function below you see I build the return value > with Py_BuildValue and "OO" as the format. > For every output I have I do a C to Python conversion and add another > 'O' to the format. > What I'm wondering is if I can use the same logic when wrapping > functions that only return one value like the wrapped_bar function > below. > > So for multiples, I wind up doing this which is fine. > > python__x = Py_BuildValue("s", x) The object at python__x has a refcount of 1. > python__y = Py_BuildValue("s", y) The object at python__y has a refcount of 1. > python__return_val = Py_BuildValue("OO", python__x, python__y); The object at python__return_val (a tuple) has a refcount of 1. This object refers to the objects at python__x and python__y, so both of their refcounts will have been incremented to 2. You will need to DECREF the objects at python__x and python__y before the C variables python__x and python__y go out of scope. > > But for single returns I do something like this.... > I realize that the 2 lines below are pointless, but are they causing a > memory leak or problems with reference counting? > > python__x = Py_BuildValue("s", x) The object at python__x has a refcount of 1. > python__return_val = Py_BuildValue("O", python__x); In this case Py_BuildValue returns its argument python__x, but will have incremented its refcount to 2. This means that you still need to DECREF the object at python__x before the C variable python__x goes out of scope. This is probably just for consistency, because it's easier to remember that /every time/ you pass an object to Py_BuildValue its refcount will be incremented, than if it was sometimes yes, sometimes no. > > > Are python__x and python__return_val the same object, a copy of the object? > Would python__x ever get garbage collected? > Should my code generator detect when there is only one output and not > go through the extra step? > [snip] From vlastimil.brom at gmail.com Thu Dec 9 18:52:15 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Fri, 10 Dec 2010 00:52:15 +0100 Subject: ***locale.Error: unsupported locale setting*** In-Reply-To: References: Message-ID: 2010/12/9 Anurag Chourasia : > Hi All, > When i try to set a locale manually, i get this error. >>>> import locale >>>> locale.setlocale(locale.LC_ALL, 'es_cl.iso88591') > Traceback (most recent call last): > ??File "", line 1, in > ??File "/usr/local/lib/python2.7/locale.py", line 531, in setlocale > ?? ?return _setlocale(category, locale) > locale.Error: unsupported locale setting > On my OS, when i run the locale -a command, i get this output > ------------------------- > locale -a > C > POSIX > en_US > en_US.8859-15 > en_US.ISO8859-1 > ------------------------- > Does this means that on my machine, Python will be able to make use of above > listed locales? > If yes then how can i possibly use the locale.setformat (or anything else > for that matter) to group numbers using '.' as the thousands separator? > If i use the locale en_US then ',' is the thousands separator. >>>> import locale >>>> locale.setlocale(locale.LC_ALL, 'en_US') > 'en_US' >>>> locale.format("%d", 1255000, grouping=True) > '1,255,000' > Regards, > Anurag > -- > http://mail.python.org/mailman/listinfo/python-list > > Hi, I am not sure, it helps in your case, but the simple locale aliases (like "Spanish") seem to work for me (py 2.7.1, win 7) >>> locale.getlocale() ('Czech_Czech Republic', '1250') >>> locale.localeconv()['thousands_sep'] '\xa0' >>> locale.setlocale(locale.LC_ALL, "Spanish") 'Spanish_Spain.1252' >>> locale.localeconv()['thousands_sep'] '.' >>> locale.format("%d", 1255000, grouping=True) '1.255.000' >>> hth, vbr From vinay_sajip at yahoo.co.uk Thu Dec 9 19:12:13 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Thu, 9 Dec 2010 16:12:13 -0800 (PST) Subject: Proposed changes to logging defaults Message-ID: <3763d355-9074-485c-a694-031d600d5b84@m11g2000vbs.googlegroups.com> Some changes are being proposed to how logging works in default configurations. Briefly - when a logging event occurs which needs to be output to some log, the behaviour of the logging package when no explicit logging configuration is provided will change, most likely to log those events to sys.stderr with a default format. Since this proposed change to behaviour is backwards-incompatible (and scheduled to come in to Python 3.2 - earlier Pythons, including 2.X, are unaffected), you may be interested in seeing if the changes affect you. More details are available here: http://plumberjack.blogspot.com/2010/12/proposed-changes-to-logging-defaults.html Please feel free to add comments to the linked blog post. Regards, Vinay Sajip From python.list at tim.thechases.com Thu Dec 9 19:48:10 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 09 Dec 2010 18:48:10 -0600 Subject: Request for feedback on API design In-Reply-To: <4d0169e2$0$30002$c3e8da3$5496439d@news.astraweb.com> References: <4d0169e2$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4D0178CA.1060200@tim.thechases.com> On 12/09/2010 05:44 PM, Steven D'Aprano wrote: > (1) Multivariate statistics such as covariance have two obvious APIs: > > A pass the X and Y values as two separate iterable arguments, e.g.: > cov([1, 2, 3], [4, 5, 6]) > > B pass the X and Y values as a single iterable of tuples, e.g.: > cov([(1, 4), (2, 5), (3, 6)] > > I currently support both APIs. Do people prefer one, or the other, or > both? If there is a clear preference for one over the other, I may drop > support for the other. I'm partial to the "B" form (iterable of 2-tuples) -- it indicates that the two data-sets (x_n and y_n) should be of the same length and paired. The "A" form leaves this less obvious that len(param1) should equal len(param2). I haven't poked at your code sufficiently to determine whether all the functions within can handle streamed data, or whether they keep the entire dataset internally, but handing off an iterable-of-pairs tends to be a little more straight-forward: cov(humongous_dataset_iter) or cov(izip(humongous_dataset_iter1, humongous_dataset_iter2)) The "A" form makes doing this a little less obvious than the "B" form. > (2) Statistics text books often give formulae in terms of sums and > differences such as > > Sxx = n*?(x**2) - (?x)**2 > > There are quite a few of these: I count at least six common ones, When you take this count, is it across multiple text-books, or are they common in just a small sampling of texts? (I confess it's been a decade and a half since I last suffered a stats class) > all closely related and confusing named: > > Sxx, Syy, Sxy, SSx, SSy, SPxy > > (the x and y should all be subscript). > > Are they useful, or would they just add unnecessary complexity? I think it depends on your audience: amateur statisticians or pros? I suspect that pros wouldn't blink at the distinctions while weekenders like myself would get a little bleary-eyed without at least a module docstring to clearly spell out the distinctions and the forumlae used for determining them. Just my from-the-hip thoughts for whatever little they may be worth. -tkc From ethan at stoneleaf.us Thu Dec 9 19:48:47 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 09 Dec 2010 16:48:47 -0800 Subject: Proposed changes to logging defaults In-Reply-To: <3763d355-9074-485c-a694-031d600d5b84@m11g2000vbs.googlegroups.com> References: <3763d355-9074-485c-a694-031d600d5b84@m11g2000vbs.googlegroups.com> Message-ID: <4D0178EF.9040407@stoneleaf.us> Vinay Sajip wrote: > Some changes are being proposed to how logging works in default > configurations. I like the changes proposed. Question about the "handler of last resort": is there only one of them, or will each library have its own so it can decide what the minimum severity should be for itself? (My apologies if this question only reveals my own ignorance.) ~Ethan~ From skippy.hammond at gmail.com Thu Dec 9 19:59:49 2010 From: skippy.hammond at gmail.com (Mark Hammond) Date: Thu, 09 Dec 2010 16:59:49 -0800 Subject: win32 design pattern: COM localserver? In-Reply-To: <92573244-ab87-4143-9e87-26f851b6a3a1@w17g2000yqh.googlegroups.com> References: <92573244-ab87-4143-9e87-26f851b6a3a1@w17g2000yqh.googlegroups.com> Message-ID: <4D017B85.9060301@gmail.com> If you are implementing a COM object using win32com, then Python will never be unloaded from the host process, which works in your favour. Just have the COM object use a thread and a queue for this processing. The 'report' method would just stick the params and filenames in the queue and return immediately - your thread should stay alive and working away so long as the host process remains alive. You probably need to deal with the face the thread will be unexpectedly terminated when the host process terminates or add a new method designed explicitly to block the host process until everything is complete - the host program would then call this method just before it terminates. Also note there is a python-win32 at python.org mailing list where you might get better or more advice... Cheers, Mark On 8/12/2010 8:03 PM, kirby.urner at gmail.com wrote: > Greetings gurus. > > I'm faced with the challenge of having a single-threaded proprietary > Win32 > language wanting to do multiple calls against a Python COM object. > > Something like... > > loObj = CREATEOBJECT("map_maker") > loObj.report( params, filename) > > do while .True. > yadda yadda > enddo > > RETURN > > I.e. the client program continues execution while loObj churns away > somewhere doing work in Python, say accessing a MySQL database > and building a map, embedding it in a PDF. > > Am I right that the COM object will need to "serve forever" i.e. be > built around some non-terminating loop? Will the client's call then > spawn a process or thread that continues until finished? > > All it has to do is leave a file on disk somewhere, then die. But > the client can't be kept on the hook until that's all done. > > I've had good luck doing an InProcess COM object the generates > a PDF from ReportLab. But this "stay alive while returning control > to the client" challenge looks like it might be a job for sockets? > > Gee I hope not. > > Quick links to favorite blog articles will give me a sense of the > ballpark... Any clues welcome. Yes, I have the Win32 book from > O'Reilly. > > Kirby > > PS: my thanks to Ethan Furman for performing maintenance and > upgrades on his dbf module on PyPI. The FoxPro gods thank you. > http://pypi.python.org/pypi/dbf/0.88.16 > > PPS: some thoughts about IronPython filed here, after trying to > catch up some, sorry about my formatting, here too. > http://mail.python.org/pipermail/edu-sig/2010-December/010138.html > From psdasilva.nospam at netcabonospam.pt Thu Dec 9 20:15:37 2010 From: psdasilva.nospam at netcabonospam.pt (Paulo da Silva) Date: Fri, 10 Dec 2010 01:15:37 +0000 Subject: dns library Message-ID: <4d017f39$0$30503$a729d347@news.telepac.pt> Hi. Is there a python library/module to handle both the server and client sides of dns protocol? I have googled for it but I only found client side ones (at least from the superficial readings I did). Thanks. From vinay_sajip at yahoo.co.uk Thu Dec 9 21:49:31 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Thu, 9 Dec 2010 18:49:31 -0800 (PST) Subject: Proposed changes to logging defaults References: <3763d355-9074-485c-a694-031d600d5b84@m11g2000vbs.googlegroups.com> Message-ID: <06eff2d7-bdd1-4750-b07f-9d95752c8b0b@j1g2000vbl.googlegroups.com> On Dec 10, 12:48?am, Ethan Furman wrote: > > I like the changes proposed. > > Question about the "handler of last resort": ?is there only one of them, > or will each library have its own so it can decide what the minimum > severity should be for itself? Libraries decide their severities differently, by setting a level on their top level logger. There's only one handler of last resort (else it wouldn't be a last resort). Generally, application developers determine the level for each logger they're interested; if no explicit levels are set, the default is the level of the root logger (WARNING by default). Thanks for the feedback, Vinay Sajip From calderone.jeanpaul at gmail.com Thu Dec 9 21:59:59 2010 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Thu, 9 Dec 2010 18:59:59 -0800 (PST) Subject: dns library References: <4d017f39$0$30503$a729d347@news.telepac.pt> Message-ID: On Dec 9, 8:15?pm, Paulo da Silva wrote: > Hi. > > Is there a python library/module to handle both the server and client > sides of dns protocol? > > I have googled for it but I only found client side ones (at least from > the superficial readings I did). > > Thanks. Twisted Names is one such library: http://twistedmatrix.com/trac/wiki/TwistedNames From rustompmody at gmail.com Thu Dec 9 22:15:11 2010 From: rustompmody at gmail.com (rusi) Date: Thu, 9 Dec 2010 19:15:11 -0800 (PST) Subject: Deprecation warnings (2.7 -> 3 ) Message-ID: <44caabf0-7f83-42b8-abf9-eb40ea6b63a8@i32g2000pri.googlegroups.com> In trying to get from 2.x to 3 Terry suggested I use 2.7 with deprecation warnings Heres the (first) set DeprecationWarning: Overriding __eq__ blocks inheritance of __hash__ in 3.x DeprecationWarning: callable() not supported in 3.x; use isinstance(x, collections.Callable) Is there one place/site I can go to for understanding all these and trying to clear them? From smallpox911 at gmail.com Thu Dec 9 22:32:23 2010 From: smallpox911 at gmail.com (small Pox) Date: Thu, 9 Dec 2010 19:32:23 -0800 (PST) Subject: little emacs lisp tutorial on turning a url into a link References: <8aa7d0e9-4263-4083-b1a9-2013a83a0f81@z20g2000pra.googlegroups.com> <9431e600-5930-4964-908e-2ed5a3f2f2db@o23g2000prh.googlegroups.com> <84f8e44e-af70-430b-b498-e1482aa7d0fc@t8g2000prh.googlegroups.com> Message-ID: On Dec 4, 1:38 am, Xah Lee wrote: > > On Dec 3, 8:20 pm, duckblue wrote: > > > why is xah lee posting this information? > > > > sites with more external links pointing to them are given a higher > > > ranking by search engines such as google. as a result they appear > > > closer to the top of the search engine results pages ('SERPs' in SEO > > > lingo). > > > xah's posting here is part of active an SEO campaign that he is > > > carrying out in order bring traffic to his site.- Hide quoted text - > > On Dec 3, 9:16 pm, small Pox wrote: > > > Xah Lee writes good articles. She has a helpful attitude. Do you want > > her to become so financially dependent like that innocent looking > > rabbit teeth Adelyn Lee so she become a prostitute of Larry Ellis > > Islander who has gobbled up Sun, mysql, cray and so many software and > > hardware companies to make the largest and possibly going to be a most > > evil monopoly on earth ? > > thanks. > > interesting mention about Adelyn Lee. > > I looked up, > > ?Woman Who Accused Oracle Chief Guilty of Perjury? January 29, 1997, > By Benjamin Pimentel, Chronicle Peninsula Bureau. SFGate Articles. > ?http://articles.sfgate.com/1997-01-29/news/17741019_1_mr-ellison-adel... > ? > > Quote: > > ?A San Mateo woman accused of forging e-mail to sue Oracle Corp. was > found guilty yesterday of perjury and falsification of evidence.? > > ?Adelyn Lee, a 33-year-old former girlfriend of Oracle Chief Executive > Officer Larry Ellison, was convicted by a San Mateo County jury, > ending a Silicon Valley soap opera that revealed some of the inner > workings of the world's second-largest software company. ? > > ?In 1995, Lee won a $100,000 settlement of a wrongful termination suit > in which she claimed that she was fired from her job as an executive > assistant after she refused to have sex with Ellison. ? > > interesting. Yeah, the 1990s, everything is sexual harassment. > > it so happpens, i have a story to tell as well. I was officially > accused of sexual harassment in around 2000 while working at Netopia. I dont know about your story, but I know about many stories http://www.orafraud.info/terminator_4.0.html To dig them you have to search hard enough. The one you found was skewed by SEO type work. The khazars are very tight-knit. Also rasputin has lots of money to get people to write fiction on him and his current wife is a fiction writer as well. The Kourts are cangaroo. Lies are as common as roman polansky fleed to europe after raping a 13years old. Your attempt to flatter is amateurish. It shows through that you are trying to flatter the money. Dont be cannibalizing that innocent girl. He baited her by a car which is worthless. Her virginity was stolen - priceless. She expected to be married and everyone knows that this is what any woman's price of sex is. Like your own mother. The guy is from anonymous father so he tries to put every decent woman down ... perhaps. He fired her to escape her vengeance. His sycophants then altered database records. She could not fight in the court. American courts are filled with false lawsuits. They did this to germany and now doing to USA. Orwell understood them one century before us. In 1984 he describes them as the guy O?Brien who "treated" Winston. You should thoroughly read the protocols of the learned elders of zion at the atzlan site and archive all of their versions and commentaries. Flattery wont get you anywhere ... better apply your brain power to create a rival to database before they gobble up all the hardware companies to make computers with builtin trojans in hardware like the telescreen of 1984. > The whole case is ridiculous. The woman who accused me, was > romantically interested in me. She's got some personal psychological > problems. We both are sys admins (but i also do dev). She lives and > work at the Kansas branch, while i work in California. Once or twice a > year, the company has her flew over for business, typically lasting > just a day. I'm not her superior or vice versa. Our relationship > started when she started to IM me and got me to use AOL. The AOL chat > is kinda used for business discussions as well, since it's just > convenient, and apparantly it became popular in the company. > (remember, this is 1999.) When she came over, i think the second time, > then later, she filed a sexual harassment to Netopia. (i didn't even > know before) We did not sleep together. The closest physical contact > might be holding hands, which, i don't remember we actually did. All i > know after the whole thing is that she's got some kinda love hang- > over. > > At the end, they (the human resource woman who handles this) ask me to > sign a paper, which, if i recall correctly, basically want me to admit > some wrong doing or something like that. I do not agree to it, i > refused to sign. And that basically is the end of it. She quit or was > fired sometimes later on (don't think it has anything to do with > this). I was laid off in 2002. (Netopia got bought by Motorola in > ~2005) > > I may write up a blog, with full disclosure of all documents of the > case and emails sometimes later. > > Xah From smallpox911 at gmail.com Thu Dec 9 22:51:33 2010 From: smallpox911 at gmail.com (small Pox) Date: Thu, 9 Dec 2010 19:51:33 -0800 (PST) Subject: little emacs lisp tutorial on turning a url into a link References: <8aa7d0e9-4263-4083-b1a9-2013a83a0f81@z20g2000pra.googlegroups.com> <9431e600-5930-4964-908e-2ed5a3f2f2db@o23g2000prh.googlegroups.com> <84f8e44e-af70-430b-b498-e1482aa7d0fc@t8g2000prh.googlegroups.com> Message-ID: <8861922a-88e7-4fc5-a877-5b852273da56@30g2000yql.googlegroups.com> On Dec 9, 7:32?pm, small Pox wrote: > On Dec 4, 1:38 am, Xah Lee wrote: > > > > > > > > On Dec 3, 8:20 pm, duckblue wrote: > > > > why is xah lee posting this information? > > > > > sites with more external links pointing to them are given a higher > > > > ranking by search engines such as google. as a result they appear > > > > closer to the top of the search engine results pages ('SERPs' in SEO > > > > lingo). > > > > xah's posting here is part of active an SEO campaign that he is > > > > carrying out in order bring traffic to his site.- Hide quoted text - > > > On Dec 3, 9:16 pm, small Pox wrote: > > > > Xah Lee writes good articles. She has a helpful attitude. Do you want > > > her to become so financially dependent like that innocent looking > > > rabbit teeth Adelyn Lee so she become a prostitute of Larry Ellis > > > Islander who has gobbled up Sun, mysql, cray and so many software and > > > hardware companies to make the largest and possibly going to be a most > > > evil monopoly on earth ? > > > thanks. > > > interesting mention about Adelyn Lee. > > > I looked up, > > > ?Woman Who Accused Oracle Chief Guilty of Perjury? January 29, 1997, > > By Benjamin Pimentel, Chronicle Peninsula Bureau. SFGate Articles. > > ?http://articles.sfgate.com/1997-01-29/news/17741019_1_mr-ellison-adel... > > ? > > > Quote: > > > ?A San Mateo woman accused of forging e-mail to sue Oracle Corp. was > > found guilty yesterday of perjury and falsification of evidence.? > > > ?Adelyn Lee, a 33-year-old former girlfriend of Oracle Chief Executive > > Officer Larry Ellison, was convicted by a San Mateo County jury, > > ending a Silicon Valley soap opera that revealed some of the inner > > workings of the world's second-largest software company. ? > > > ?In 1995, Lee won a $100,000 settlement of a wrongful termination suit > > in which she claimed that she was fired from her job as an executive > > assistant after she refused to have sex with Ellison. ? > > > interesting. Yeah, the 1990s, everything is sexual harassment. > > > it so happpens, i have a story to tell as well. I was officially > > accused of sexual harassment in around 2000 while working at Netopia. > > I dont know about your story, but I know about many stories > > http://www.orafraud.info/terminator_4.0.html > > To dig them you have to search hard enough. > > The one you found was skewed by SEO type work. The khazars are very > tight-knit. > > Also rasputin has lots of money to get people to write fiction on him > and his current wife is a fiction writer as well. The Kourts are > cangaroo. Lies are as common as roman polansky fleed to europe after > raping a 13years old. > > Your attempt to flatter is amateurish. It shows through that you are > trying to flatter the money. > > Dont be cannibalizing that innocent girl. He baited her by a car which > is worthless. Her virginity was stolen - priceless. She expected to be > married and everyone knows that this is what any woman's price of sex > is. > > Like your own mother. > > The guy is from anonymous father so he tries to put every decent woman > down ... perhaps. > > He fired her to escape her vengeance. > > His sycophants then altered database records. > > She could not fight in the court. American courts are filled with > false lawsuits. > > They did this to germany and now doing to USA. > > Orwell understood them one century before us. In 1984 he describes > them as the guy O?Brien who "treated" Winston. You should thoroughly > read the protocols of the learned elders of zion at the atzlan site > and archive all of their versions and commentaries. > > Flattery wont get you anywhere ?... better apply your brain power to > create a rival to database before they gobble up all the hardware > companies to make computers with builtin trojans in hardware like the > telescreen of 1984. > > > > > The whole case is ridiculous. The woman who accused me, was > > romantically interested in me. She's got some personal psychological > > problems. We both are sys admins (but i also do dev). She lives and > > work at the Kansas branch, while i work in California. Once or twice a > > year, the company has her flew over for business, typically lasting > > just a day. I'm not her superior or vice versa. Our relationship > > started when she started to IM me and got me to use AOL. ?The AOL chat > > is kinda used for business discussions as well, since it's just > > convenient, and apparantly it became popular in the company. > > (remember, this is 1999.) When she came over, i think the second time, > > then later, she filed a sexual harassment to Netopia. (i didn't even > > know before) We did not sleep together. The closest physical contact > > might be holding hands, which, i don't remember we actually did. All i > > know after the whole thing is that she's got some kinda love hang- > > over. > > > At the end, they (the human resource woman who handles this) ask me to > > sign a paper, which, if i recall correctly, basically want me to admit > > some wrong doing or something like that. I do not agree to it, i > > refused to sign. And that basically is the end of it. She quit or was > > fired sometimes later on (don't think it has anything to do with > > this). I was laid off in 2002. (Netopia got bought by Motorola in > > ~2005) > > > I may write up a blog, with full disclosure of all documents of the > > case and emails sometimes later. > > > ?Xah- Hide quoted text - > > - Show quoted text -- Hide quoted text - > > - Show quoted text - I advocate neither anti semitism nor pro semitism. just the rule of law that treats people equally and fairly and where money does not count. this cannot be achieved without demolishing fractional reserve lending, and not without making the courts free and preventing knowledge monopolies. If a certain group is going up disproportionately, then there is something to look at. I see everyone work as hard as anyone else. From smallpox911 at gmail.com Thu Dec 9 22:52:12 2010 From: smallpox911 at gmail.com (small Pox) Date: Thu, 9 Dec 2010 19:52:12 -0800 (PST) Subject: little emacs lisp tutorial on turning a url into a link References: <8aa7d0e9-4263-4083-b1a9-2013a83a0f81@z20g2000pra.googlegroups.com> <9431e600-5930-4964-908e-2ed5a3f2f2db@o23g2000prh.googlegroups.com> <84f8e44e-af70-430b-b498-e1482aa7d0fc@t8g2000prh.googlegroups.com> Message-ID: <4ecd60b8-7366-4bc6-b7dc-1e5cf2aa874f@t35g2000yqj.googlegroups.com> On Dec 9, 7:32 pm, small Pox wrote: > On Dec 4, 1:38 am, Xah Lee wrote: > > > > > > > > On Dec 3, 8:20 pm, duckblue wrote: > > > > why is xah lee posting this information? > > > > > sites with more external links pointing to them are given a higher > > > > ranking by search engines such as google. as a result they appear > > > > closer to the top of the search engine results pages ('SERPs' in SEO > > > > lingo). > > > > xah's posting here is part of active an SEO campaign that he is > > > > carrying out in order bring traffic to his site.- Hide quoted text - > > > On Dec 3, 9:16 pm, small Pox wrote: > > > > Xah Lee writes good articles. She has a helpful attitude. Do you want > > > her to become so financially dependent like that innocent looking > > > rabbit teeth Adelyn Lee so she become a prostitute of Larry Ellis > > > Islander who has gobbled up Sun, mysql, cray and so many software and > > > hardware companies to make the largest and possibly going to be a most > > > evil monopoly on earth ? > > > thanks. > > > interesting mention about Adelyn Lee. > > > I looked up, > > > ?Woman Who Accused Oracle Chief Guilty of Perjury? January 29, 1997, > > By Benjamin Pimentel, Chronicle Peninsula Bureau. SFGate Articles. > > ?http://articles.sfgate.com/1997-01-29/news/17741019_1_mr-ellison-adel... > > ? > > > Quote: > > > ?A San Mateo woman accused of forging e-mail to sue Oracle Corp. was > > found guilty yesterday of perjury and falsification of evidence.? > > > ?Adelyn Lee, a 33-year-old former girlfriend of Oracle Chief Executive > > Officer Larry Ellison, was convicted by a San Mateo County jury, > > ending a Silicon Valley soap opera that revealed some of the inner > > workings of the world's second-largest software company. ? > > > ?In 1995, Lee won a $100,000 settlement of a wrongful termination suit > > in which she claimed that she was fired from her job as an executive > > assistant after she refused to have sex with Ellison. ? > > > interesting. Yeah, the 1990s, everything is sexual harassment. > > > it so happpens, i have a story to tell as well. I was officially > > accused of sexual harassment in around 2000 while working at Netopia. > > I dont know about your story, but I know about many stories > > http://www.orafraud.info/terminator_4.0.html > > To dig them you have to search hard enough. > > The one you found was skewed by SEO type work. The khazars are very > tight-knit. > > Also rasputin has lots of money to get people to write fiction on him > and his current wife is a fiction writer as well. The Kourts are > cangaroo. Lies are as common as roman polansky fleed to europe after > raping a 13years old. > > Your attempt to flatter is amateurish. It shows through that you are > trying to flatter the money. > > Dont be cannibalizing that innocent girl. He baited her by a car which > is worthless. Her virginity was stolen - priceless. She expected to be > married and everyone knows that this is what any woman's price of sex > is. > > Like your own mother. > > The guy is from anonymous father so he tries to put every decent woman > down ... perhaps. > > He fired her to escape her vengeance. > > His sycophants then altered database records. > > She could not fight in the court. American courts are filled with > false lawsuits. > > They did this to germany and now doing to USA. > > Orwell understood them one century before us. In 1984 he describes > them as the guy O?Brien who "treated" Winston. You should thoroughly > read the protocols of the learned elders of zion at the atzlan site > and archive all of their versions and commentaries. > > Flattery wont get you anywhere ... better apply your brain power to > create a rival to database before they gobble up all the hardware > companies to make computers with builtin trojans in hardware like the > telescreen of 1984. > > > > > The whole case is ridiculous. The woman who accused me, was > > romantically interested in me. She's got some personal psychological > > problems. We both are sys admins (but i also do dev). She lives and > > work at the Kansas branch, while i work in California. Once or twice a > > year, the company has her flew over for business, typically lasting > > just a day. I'm not her superior or vice versa. Our relationship > > started when she started to IM me and got me to use AOL. The AOL chat > > is kinda used for business discussions as well, since it's just > > convenient, and apparantly it became popular in the company. > > (remember, this is 1999.) When she came over, i think the second time, > > then later, she filed a sexual harassment to Netopia. (i didn't even > > know before) We did not sleep together. The closest physical contact > > might be holding hands, which, i don't remember we actually did. All i > > know after the whole thing is that she's got some kinda love hang- > > over. > > > At the end, they (the human resource woman who handles this) ask me to > > sign a paper, which, if i recall correctly, basically want me to admit > > some wrong doing or something like that. I do not agree to it, i > > refused to sign. And that basically is the end of it. She quit or was > > fired sometimes later on (don't think it has anything to do with > > this). I was laid off in 2002. (Netopia got bought by Motorola in > > ~2005) > > > I may write up a blog, with full disclosure of all documents of the > > case and emails sometimes later. > > > Xah- Hide quoted text - > > - Show quoted text -- Hide quoted text - > > - Show quoted text - I advocate neither anti semitism nor pro semitism. just the rule of law that treats people equally and fairly and where money does not count. this cannot be achieved without demolishing fractional reserve lending, and not without making the courts free and preventing knowledge monopolies. If a certain group is going up disproportionately, then there is something to look at. I see everyone work as hard as anyone else. From tjreedy at udel.edu Thu Dec 9 23:21:47 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 09 Dec 2010 23:21:47 -0500 Subject: Deprecation warnings (2.7 -> 3 ) In-Reply-To: <44caabf0-7f83-42b8-abf9-eb40ea6b63a8@i32g2000pri.googlegroups.com> References: <44caabf0-7f83-42b8-abf9-eb40ea6b63a8@i32g2000pri.googlegroups.com> Message-ID: On 12/9/2010 10:15 PM, rusi wrote: > In trying to get from 2.x to 3 Terry suggested I use 2.7 with > deprecation warnings > > > Heres the (first) set > > DeprecationWarning: Overriding __eq__ blocks inheritance of __hash__ > in 3.x > DeprecationWarning: callable() not supported in 3.x; use isinstance(x, > collections.Callable) > > Is there one place/site I can go to for understanding all these and > trying to clear them? Not that I know of, but it would be a good idea. You could suggest on the tracker the addition of HOW TO Clear Deprecation Warnings, 2.7. There would need to be a new one for each release, based on grepping the codebase. -- Terry Jan Reedy From rustompmody at gmail.com Fri Dec 10 00:53:39 2010 From: rustompmody at gmail.com (rusi) Date: Thu, 9 Dec 2010 21:53:39 -0800 (PST) Subject: trace cmd line args in 2.7 Message-ID: Ive installed python 2.7 And trace still ignores my ignore-module etc requests From psdasilva.nospam at netcabonospam.pt Fri Dec 10 01:12:31 2010 From: psdasilva.nospam at netcabonospam.pt (Paulo da Silva) Date: Fri, 10 Dec 2010 06:12:31 +0000 Subject: dns library In-Reply-To: References: <4d017f39$0$30503$a729d347@news.telepac.pt> Message-ID: <4d01c4ce$0$30506$a729d347@news.telepac.pt> Em 10-12-2010 02:59, Jean-Paul Calderone escreveu: > On Dec 9, 8:15 pm, Paulo da Silva > wrote: >> Hi. >> >> Is there a python library/module to handle both the server and client >> sides of dns protocol? >> >> I have googled for it but I only found client side ones (at least from >> the superficial readings I did). >> >> Thanks. > > Twisted Names is one such library: http://twistedmatrix.com/trac/wiki/TwistedNames I've just looked at its home page and it seems to be what I need. Thank you very much. From markjason72 at gmail.com Fri Dec 10 01:16:17 2010 From: markjason72 at gmail.com (mark jason) Date: Thu, 9 Dec 2010 22:16:17 -0800 (PST) Subject: printing error message from an Exception Message-ID: <2c9af3ec-294c-4cd4-aca3-cbc62dba09b6@u9g2000pra.googlegroups.com> hi I was trying out some file operations and was trying to open a non existing file as below def do_work(filename): try: f = open(filename,"r"); print 'opened' except IOError, e: print 'failed',e.message finally: f.close() print 'closed' if __name__=='__main__': do_work("C:\code\misc.txt") # there is no such file I am getting an error and a warning DeprecationWarning: BaseException.message has been deprecated as of Python 2.6 print 'failed',e.message UnboundLocalError: local variable 'f' referenced before assignment Is there a way to overcome the DeprecationWarning? I wanted to print the error message from the IOError.How do I do this? Also ,what should I do about the UnboundLocalError? thanks and regards , mark From steve+comp.lang.python at pearwood.info Fri Dec 10 01:55:27 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Dec 2010 06:55:27 GMT Subject: printing error message from an Exception References: <2c9af3ec-294c-4cd4-aca3-cbc62dba09b6@u9g2000pra.googlegroups.com> Message-ID: <4d01cede$0$30002$c3e8da3$5496439d@news.astraweb.com> On Thu, 09 Dec 2010 22:16:17 -0800, mark jason wrote: > hi > I was trying out some file operations and was trying to open a non > existing file as below > > def do_work(filename): > try: > f = open(filename,"r"); > print 'opened' > except IOError, e: > print 'failed',e.message > finally: > f.close() > print 'closed' The problem is, you try to close a file that not only hasn't been opened, but the name f isn't bound to a value: >>> do_work('no such file') failed Traceback (most recent call last): File "", line 1, in File "", line 8, in do_work UnboundLocalError: local variable 'f' referenced before assignment > if __name__=='__main__': > do_work("C:\code\misc.txt") # there is no such file > > I am getting an error and a warning > > DeprecationWarning: BaseException.message has been deprecated as of > Python 2.6 > print 'failed',e.message > > UnboundLocalError: local variable 'f' referenced before assignment > > Is there a way to overcome the DeprecationWarning? I wanted to print the > error message from the IOError.How do I do this? Generally, the best way to print error messages is to print the *entire* error message, including the traceback. You do that by just not catching the exception at all. But for the times you do need to do something else with the exception, instead of exception.message, look at exception.args. This will be a tuple of one or more items, the first item should be the error message. > Also ,what should I do about the UnboundLocalError? Use finally for things which must be done regardless of whether or not the previous operation succeeded, not for things that should only be done if the previous operation succeeded but not if it failed. def do_work(filename): try: f = open(filename,"r"); print 'opened' except IOError, e: # By the way, IOError is not the only exception you could see. print 'failed', e.args else: f.close() print 'closed' Or, slightly more useful: def do_work(filename): s = '' try: f = open(filename,"r"); print 'opened' except IOError, e: # By the way, IOError is not the only exception you could see. print 'failed', e.args else: try: s = f.read() finally: f.close() print 'closed' print s -- Steven From steve+comp.lang.python at pearwood.info Fri Dec 10 02:51:54 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Dec 2010 07:51:54 GMT Subject: Request for feedback on API design References: <4d0169e2$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4d01dc19$0$30002$c3e8da3$5496439d@news.astraweb.com> On Thu, 09 Dec 2010 18:48:10 -0600, Tim Chase wrote: > On 12/09/2010 05:44 PM, Steven D'Aprano wrote: >> (1) Multivariate statistics such as covariance have two obvious APIs: >> >> A pass the X and Y values as two separate iterable arguments, >> e.g.: >> cov([1, 2, 3], [4, 5, 6]) >> >> B pass the X and Y values as a single iterable of tuples, e.g.: >> cov([(1, 4), (2, 5), (3, 6)] >> >> I currently support both APIs. Do people prefer one, or the other, or >> both? If there is a clear preference for one over the other, I may drop >> support for the other. > > I'm partial to the "B" form (iterable of 2-tuples) -- it indicates that > the two data-sets (x_n and y_n) should be of the same length and paired. > The "A" form leaves this less obvious that len(param1) should equal > len(param2). Thanks for the comments Tim. To answer your questions: > I haven't poked at your code sufficiently to determine whether all the > functions within can handle streamed data, or whether they keep the > entire dataset internally, Where possible, the functions don't keep the entire dataset internally. Some functions have to (e.g. order statistics need to see the entire data sequence at once), but the rest are capable of dealing with streamed data. Also, there are a few functions such as standard deviation that have a single-pass algorithm, and a more accurate multiple-pass algorithm. >> (2) Statistics text books often give formulae in terms of sums and >> differences such as >> >> Sxx = n*?(x**2) - (?x)**2 >> >> There are quite a few of these: I count at least six common ones, > > When you take this count, is it across multiple text-books, or are they > common in just a small sampling of texts? (I confess it's been a decade > and a half since I last suffered a stats class) I admit that I haven't done an exhaustive search of the literature, but it does seen quite common to extract common expressions from various stats formulae and give them names. The only use-case I can imagine for them is checking hand-calculations or doing schoolwork. -- Steven From steve at holdenweb.com Fri Dec 10 03:49:01 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 10 Dec 2010 09:49:01 +0100 Subject: little emacs lisp tutorial on turning a url into a link In-Reply-To: <4ecd60b8-7366-4bc6-b7dc-1e5cf2aa874f@t35g2000yqj.googlegroups.com> References: <8aa7d0e9-4263-4083-b1a9-2013a83a0f81@z20g2000pra.googlegroups.com> <9431e600-5930-4964-908e-2ed5a3f2f2db@o23g2000prh.googlegroups.com> <84f8e44e-af70-430b-b498-e1482aa7d0fc@t8g2000prh.googlegroups.com> <4ecd60b8-7366-4bc6-b7dc-1e5cf2aa874f@t35g2000yqj.googlegroups.com> Message-ID: <4D01E97D.5040009@holdenweb.com> On 12/10/2010 4:52 AM, small Pox wrote: [... irrelevant stuff...] > I advocate neither anti semitism nor pro semitism. just the rule of > law that treats people equally and fairly and where money does not > count. this cannot be achieved without demolishing fractional reserve > lending, and not without making the courts free and preventing > knowledge monopolies. If a certain group is going up > disproportionately, then there is something to look at. I see everyone > work as hard as anyone else. This is completely off-topic for c.l.py. Kindly bugger off. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Fri Dec 10 03:49:01 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 10 Dec 2010 09:49:01 +0100 Subject: little emacs lisp tutorial on turning a url into a link In-Reply-To: <4ecd60b8-7366-4bc6-b7dc-1e5cf2aa874f@t35g2000yqj.googlegroups.com> References: <8aa7d0e9-4263-4083-b1a9-2013a83a0f81@z20g2000pra.googlegroups.com> <9431e600-5930-4964-908e-2ed5a3f2f2db@o23g2000prh.googlegroups.com> <84f8e44e-af70-430b-b498-e1482aa7d0fc@t8g2000prh.googlegroups.com> <4ecd60b8-7366-4bc6-b7dc-1e5cf2aa874f@t35g2000yqj.googlegroups.com> Message-ID: <4D01E97D.5040009@holdenweb.com> On 12/10/2010 4:52 AM, small Pox wrote: [... irrelevant stuff...] > I advocate neither anti semitism nor pro semitism. just the rule of > law that treats people equally and fairly and where money does not > count. this cannot be achieved without demolishing fractional reserve > lending, and not without making the courts free and preventing > knowledge monopolies. If a certain group is going up > disproportionately, then there is something to look at. I see everyone > work as hard as anyone else. This is completely off-topic for c.l.py. Kindly bugger off. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From markjason72 at gmail.com Fri Dec 10 04:12:51 2010 From: markjason72 at gmail.com (mark jason) Date: Fri, 10 Dec 2010 01:12:51 -0800 (PST) Subject: printing error message from an Exception References: <2c9af3ec-294c-4cd4-aca3-cbc62dba09b6@u9g2000pra.googlegroups.com> <4d01cede$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <47a48cbd-146b-4cf5-a7bb-546572c4ef0e@k14g2000pre.googlegroups.com> On Dec 10, 11:55?am, Steven D'Aprano wrote: > ? ? # By the way, IOError is not the only exception you could see. thanks for the help Steven. Is it OK to catch Exception instead of IOError ? In some operation which can cause many errors ,can I use the following? try: do_something() except Exception,e: display_message(e.args) handle_exception(e) thanks, mark From __peter__ at web.de Fri Dec 10 04:15:05 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 10 Dec 2010 10:15:05 +0100 Subject: printing error message from an Exception References: <2c9af3ec-294c-4cd4-aca3-cbc62dba09b6@u9g2000pra.googlegroups.com> Message-ID: mark jason wrote: > hi > I was trying out some file operations and was trying to open a non > existing file as below > > def do_work(filename): > try: > f = open(filename,"r"); > print 'opened' > except IOError, e: > print 'failed',e.message > finally: > f.close() > print 'closed' > > if __name__=='__main__': > do_work("C:\code\misc.txt") # there is no such file > > I am getting an error and a warning > > DeprecationWarning: BaseException.message has been deprecated as of > Python 2.6 > print 'failed',e.message > > UnboundLocalError: local variable 'f' referenced before assignment > > Is there a way to overcome the DeprecationWarning? I wanted to print > the error message from the IOError.How do I do this? > Also ,what should I do about the UnboundLocalError? You are mixing two things here: (1) print an error message when the file cannot be opened (2) ensure that the file will always be closed If you attack both aspects separately they become simpler: # 1 try: f = open(...) except IOError as e: print "Failed", e # 2a f = open(...) try: print "opened" finally: f.close() which can be simplified to # 2b with open(...) as f: print "opened" Putting 1 and 2b together: try: with open(...) as f: print "opened" except IOError as e: print "Failed", e There is a disadvantage though: an IOError that is raised in the with-suite will also be caught. If you're concerned about that you can use: try: f = open(...) except IOError as e: print "Failed", e else: with contextlib.closing(f): print "opened" From jeanmichel at sequans.com Fri Dec 10 05:17:33 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 10 Dec 2010 11:17:33 +0100 Subject: Proposed changes to logging defaults In-Reply-To: <3763d355-9074-485c-a694-031d600d5b84@m11g2000vbs.googlegroups.com> References: <3763d355-9074-485c-a694-031d600d5b84@m11g2000vbs.googlegroups.com> Message-ID: <4D01FE3D.2020103@sequans.com> Vinay Sajip wrote: > Some changes are being proposed to how logging works in default > configurations. > > Briefly - when a logging event occurs which needs to be output to some > log, the behaviour of the logging package when no explicit logging > configuration is provided will change, most likely to log those events > to sys.stderr with a default format. > > Since this proposed change to behaviour is backwards-incompatible (and > scheduled to come in to Python 3.2 - earlier Pythons, including 2.X, > are unaffected), you may be interested in seeing if the changes affect > you. More details are available here: > > http://plumberjack.blogspot.com/2010/12/proposed-changes-to-logging-defaults.html > > Please feel free to add comments to the linked blog post. > > Regards, > > Vinay Sajip > Why would you log informative messages to stderr ? (debug, info, warning) How stderr is a better choice than stdout ? A naive approach would rather send errors to stderr & everything else on stdout (including warnings ?). IMO, the StreamHandler(sys.stderr) level should be set to logging.ERROR by default. Because nobody can answer the question 'is a warning an error', endless debate, there's a risk to log warnings to stderr. I also think that if someone did'nt care about configuring the logging machine for 3rd party libraries, this guy just don't care about those library warnings. Last question, if no handler is found, why not simply drop the log event, doing nothing ? It sounds pretty reasonable and less intrusive. JM From frankcui24 at gmail.com Fri Dec 10 05:20:53 2010 From: frankcui24 at gmail.com (frank cui) Date: Fri, 10 Dec 2010 18:20:53 +0800 Subject: instance has no __call__ method Message-ID: Hi all, I'm a novice learner of python and get caught in the following trouble and hope experienced users can help me solve it:) Code: ----------------------------------------------------------------------- $ cat Muffle_ZeroDivision.py #!/usr/bin/env python class MuffledCalculator: muffled = False def clac(self,expr): try: return eval(expr) except: if self.muffled: print 'Division by zero is illegal' else: raise -------------------------------------------------------------------------- $ python Python 2.7 (r27:82500, Sep 16 2010, 18:03:06) [GCC 4.5.1 20100907 (Red Hat 4.5.1-3)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import Muffle_ZeroDivision >>> calc = Muffle_ZeroDivision.MuffledCalculator() >>> calc = ('10/2') >>> calc = Muffle_ZeroDivision.MuffledCalculator() >>> calc('10/2') Traceback (most recent call last): File "", line 1, in AttributeError: MuffledCalculator instance has no __call__ method ---------------------------------------------------------------------------- There is an AttributeError that this instance doesn't have the __call__ method, so how to add this kind of method to my instance? Thanks a lot in advance. Regards Frank.Cui -------------- next part -------------- An HTML attachment was scrubbed... URL: From kala32kolo at gmail.com Fri Dec 10 05:31:13 2010 From: kala32kolo at gmail.com (kolo 32) Date: Fri, 10 Dec 2010 02:31:13 -0800 (PST) Subject: Python critique Message-ID: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> Hi, all, Python critique from strchr.com: http://www.strchr.com/python_critique From jeanmichel at sequans.com Fri Dec 10 05:33:13 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 10 Dec 2010 11:33:13 +0100 Subject: printing error message from an Exception In-Reply-To: <47a48cbd-146b-4cf5-a7bb-546572c4ef0e@k14g2000pre.googlegroups.com> References: <2c9af3ec-294c-4cd4-aca3-cbc62dba09b6@u9g2000pra.googlegroups.com> <4d01cede$0$30002$c3e8da3$5496439d@news.astraweb.com> <47a48cbd-146b-4cf5-a7bb-546572c4ef0e@k14g2000pre.googlegroups.com> Message-ID: <4D0201E9.8090305@sequans.com> mark jason wrote: > On Dec 10, 11:55 am, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: > >> # By the way, IOError is not the only exception you could see. >> > > > thanks for the help Steven. Is it OK to catch Exception instead of > IOError ? > In some operation which can cause many errors ,can I use the > following? > > try: > do_something() > except Exception,e: > display_message(e.args) > handle_exception(e) > > > thanks, > mark > You shouldn't. If you want to handle an exception, you need to know about it. What if your handle_exception meets some exception it does not know how to handle ? People are sometimes using bare try except clause to say 'look ! my function never crash !'. True but it usually has an unpredictable behavior upon exception being raised, and that is much worse that a clean uncought exception. What you can do : try: do_something() except IOError: # handler IOerror except KeyboardInterrupt: print 'stopping...' sys.exit(0) except NotImplementedError: # handler missing implementation Everything else should be kept uncought. JM From davea at ieee.org Fri Dec 10 06:28:39 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 10 Dec 2010 06:28:39 -0500 Subject: instance has no __call__ method In-Reply-To: References: Message-ID: <4D020EE7.9010508@ieee.org> On 01/-10/-28163 02:59 PM, frank cui wrote: > Hi all, > > I'm a novice learner of python and get caught in the following trouble and > hope experienced users can help me solve it:) > > Code: > ----------------------------------------------------------------------- > $ cat Muffle_ZeroDivision.py > #!/usr/bin/env python > > class MuffledCalculator: > muffled = False > def clac(self,expr): > try: > return eval(expr) > except: > if self.muffled: > print 'Division by zero is illegal' > else: > raise > -------------------------------------------------------------------------- > > $ python > Python 2.7 (r27:82500, Sep 16 2010, 18:03:06) > [GCC 4.5.1 20100907 (Red Hat 4.5.1-3)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import Muffle_ZeroDivision >>>> calc = Muffle_ZeroDivision.MuffledCalculator() >>>> calc = ('10/2') >>>> calc = Muffle_ZeroDivision.MuffledCalculator() >>>> calc('10/2') > Traceback (most recent call last): > File "", line 1, in > AttributeError: MuffledCalculator instance has no __call__ method > > ---------------------------------------------------------------------------- > > There is an AttributeError that this instance doesn't have the __call__ > method, so how to add this kind of method to my instance? > Your problem is that you defined a clac() method, but never call it. So instead of calc('10/2') you need calc.clac("10/2") I'm not sure why you have such a confusing name, however. DaveA From solipsis at pitrou.net Fri Dec 10 06:57:02 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Fri, 10 Dec 2010 12:57:02 +0100 Subject: Proposed changes to logging defaults References: <3763d355-9074-485c-a694-031d600d5b84@m11g2000vbs.googlegroups.com> <4D01FE3D.2020103@sequans.com> Message-ID: <20101210125702.18262cd5@pitrou.net> On Fri, 10 Dec 2010 11:17:33 +0100 Jean-Michel Pichavant wrote: > Why would you log informative messages to stderr ? (debug, info, warning) > How stderr is a better choice than stdout ? By construction really. stderr is initially for errors, but it is generally used for "out of band" messages such as warnings and various optional information. stdout is used to output whatever data the user asked for (which generally isn't errors and warnings). If you redirect said data to a file, you don't want out of band information to end up mingled with it. Regards Antoine. From astan.chee at gmail.com Fri Dec 10 07:02:24 2010 From: astan.chee at gmail.com (Astan Chee) Date: Fri, 10 Dec 2010 23:02:24 +1100 Subject: run a function in another processor in python In-Reply-To: References: <4D00B416.5090509@sequans.com> Message-ID: Thanks for that. I'll try and see if it makes any difference but I'm using python 2.6 not 3 Are the multiprocessing modules different? That code (or whatever is using the multiprocessing module) seems to cause infinite python processes on my machine and eventually kills it. I'm running python 2.6 on windows 7 x64 ....is it the ammount of memory/cpu speed/number of cpu that is the issue? Thanks for any clarification On Fri, Dec 10, 2010 at 4:16 AM, geremy condra wrote: > On Thu, Dec 9, 2010 at 5:03 AM, Astan Chee wrote: > > Thanks but I'm having trouble with that module too. Currently what I > > have is something like this: > > > > import sys > > import os > > import multiprocessing > > > > import time > > > > def functionTester(num): > > return ((num+2)/(num-2))**2 > > > > num_args = [61,62,33,7,12,16,19,35,36,37,38,55,56,57,63] > > > > max_result = 0 > > > > start = time.time() > > > > num_processes = multiprocessing.cpu_count() > > > > threads = [] > > len_stas = len(num_args) > > > > for list_item in num_args: > > if len(threads) < num_processes: > > p = > multiprocessing.Process(target=functionTester,args=[list_item]) > > p.start() > > print p, p.is_alive() > > threads.append(p) > > else: > > for thread in threads: > > if not thread.is_alive(): > > threads.remove(thread) > > > > print "Result " + str(max_result) > > end = time.time() > > elapsed= end - start > > print "Took", elapsed, "seconds to execute" > > > > But it doesn't give me any return data. It also spawns an infinite > > number of (sub)processes that crashes my machine. What am I doing > > wrong here? > > > > On 12/9/10, Jean-Michel Pichavant wrote: > >> Astan Chee wrote: > >>> Hi, > >>> I've got a python script that calls a function many times with various > >>> arguments and returns a result. What I'm trying to do is run this > >>> function each on different processors and compile the result at the > >>> end based on the function result. The script looks something like > >>> this: > >>> > >>> > >>> import time > >>> > >>> def functionTester(num): > >>> return ((num+2)/(num-2))**2 > >>> > >>> num_args = [1,2,3,7,12,16,19,35,36,37,38,55,56,57,63,44,71,81,91] > >>> > >>> max_result = 0 > >>> > >>> start = time.time() > >>> > >>> for n in num_args: > >>> result = functionTester(n) > >>> if result > max_result: > >>> max_result = result > >>> > >>> print "Result " + str(max_result) > >>> end = time.time() > >>> elapsed= end - start > >>> print "Took", elapsed, "seconds to execute" > >>> > >>> > >>> What I'm trying to do is run each function on a processor and when its > >>> done, move on to the next function-argument specifically on windows 7 > >>> x64 using python 2.6. How do I do this? > >>> Thanks for any help > >>> > >> If I'm not wrong, CPU management is handled by your system, meaning > >> there's no way to 'force' anything to run on a specific CPU. However, > >> you may try to execute your fonction in a subprocess, so that the system > >> will use different CPUs (hopefully). You then just need to limit the > >> number of subprocess alive at the same time. > >> > >> Have a look here > >> http://docs.python.org/library/multiprocessing.html > >> > >> JM > >> > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > Here's a way of doing what I think you mean to do. I assume that > max_result should be the maximum value returned by a run of > functionTester. > > Also, just a note, usually function names like this are spelled > function_tester rather than functionTester in python. > > If you need to de-python3ify it just change the line at the top and > cast your nums to floats, otherwise you'll get integer division (which > I again assume you don't want). > > #! /usr/bin/env python3 > > import time > import multiprocessing > > > def functionTester(num): > return ((num+2)/(num-2))**2 > > num_args = [61,62,33,7,12,16,19,35,36,37,38,55,56,57,63] > > num_processes = multiprocessing.cpu_count() > pool = multiprocessing.Pool(num_processes) > > start = time.time() > results = pool.map(functionTester, num_args) > end = time.time() > > # is this what you meant to do with the results? > max_result = max(results) > print("Result " + str(max_result)) > > elapsed = end - start > print("Took", elapsed, "seconds to execute") > > Geremy Condra > -------------- next part -------------- An HTML attachment was scrubbed... URL: From astan.chee at gmail.com Fri Dec 10 07:08:06 2010 From: astan.chee at gmail.com (Astan Chee) Date: Fri, 10 Dec 2010 23:08:06 +1100 Subject: run a function in another processor in python In-Reply-To: References: <4D00B416.5090509@sequans.com> Message-ID: I just saw this: http://bugs.python.org/issue8094 which seem to be similar to what I'm having. Does anyone know if there is a fix for it? Thanks again On Fri, Dec 10, 2010 at 11:02 PM, Astan Chee wrote: > Thanks for that. I'll try and see if it makes any difference but I'm using > python 2.6 not 3 > Are the multiprocessing modules different? That code (or whatever is using > the multiprocessing module) seems to cause infinite python processes on my > machine and eventually kills it. > I'm running python 2.6 on windows 7 x64 ....is it the ammount of memory/cpu > speed/number of cpu that is the issue? > Thanks for any clarification > > > > On Fri, Dec 10, 2010 at 4:16 AM, geremy condra wrote: > >> On Thu, Dec 9, 2010 at 5:03 AM, Astan Chee wrote: >> > Thanks but I'm having trouble with that module too. Currently what I >> > have is something like this: >> > >> > import sys >> > import os >> > import multiprocessing >> > >> > import time >> > >> > def functionTester(num): >> > return ((num+2)/(num-2))**2 >> > >> > num_args = [61,62,33,7,12,16,19,35,36,37,38,55,56,57,63] >> > >> > max_result = 0 >> > >> > start = time.time() >> > >> > num_processes = multiprocessing.cpu_count() >> > >> > threads = [] >> > len_stas = len(num_args) >> > >> > for list_item in num_args: >> > if len(threads) < num_processes: >> > p = >> multiprocessing.Process(target=functionTester,args=[list_item]) >> > p.start() >> > print p, p.is_alive() >> > threads.append(p) >> > else: >> > for thread in threads: >> > if not thread.is_alive(): >> > threads.remove(thread) >> > >> > print "Result " + str(max_result) >> > end = time.time() >> > elapsed= end - start >> > print "Took", elapsed, "seconds to execute" >> > >> > But it doesn't give me any return data. It also spawns an infinite >> > number of (sub)processes that crashes my machine. What am I doing >> > wrong here? >> > >> > On 12/9/10, Jean-Michel Pichavant wrote: >> >> Astan Chee wrote: >> >>> Hi, >> >>> I've got a python script that calls a function many times with various >> >>> arguments and returns a result. What I'm trying to do is run this >> >>> function each on different processors and compile the result at the >> >>> end based on the function result. The script looks something like >> >>> this: >> >>> >> >>> >> >>> import time >> >>> >> >>> def functionTester(num): >> >>> return ((num+2)/(num-2))**2 >> >>> >> >>> num_args = [1,2,3,7,12,16,19,35,36,37,38,55,56,57,63,44,71,81,91] >> >>> >> >>> max_result = 0 >> >>> >> >>> start = time.time() >> >>> >> >>> for n in num_args: >> >>> result = functionTester(n) >> >>> if result > max_result: >> >>> max_result = result >> >>> >> >>> print "Result " + str(max_result) >> >>> end = time.time() >> >>> elapsed= end - start >> >>> print "Took", elapsed, "seconds to execute" >> >>> >> >>> >> >>> What I'm trying to do is run each function on a processor and when its >> >>> done, move on to the next function-argument specifically on windows 7 >> >>> x64 using python 2.6. How do I do this? >> >>> Thanks for any help >> >>> >> >> If I'm not wrong, CPU management is handled by your system, meaning >> >> there's no way to 'force' anything to run on a specific CPU. However, >> >> you may try to execute your fonction in a subprocess, so that the >> system >> >> will use different CPUs (hopefully). You then just need to limit the >> >> number of subprocess alive at the same time. >> >> >> >> Have a look here >> >> http://docs.python.org/library/multiprocessing.html >> >> >> >> JM >> >> >> > -- >> > http://mail.python.org/mailman/listinfo/python-list >> > >> >> Here's a way of doing what I think you mean to do. I assume that >> max_result should be the maximum value returned by a run of >> functionTester. >> >> Also, just a note, usually function names like this are spelled >> function_tester rather than functionTester in python. >> >> If you need to de-python3ify it just change the line at the top and >> cast your nums to floats, otherwise you'll get integer division (which >> I again assume you don't want). >> >> #! /usr/bin/env python3 >> >> import time >> import multiprocessing >> >> >> def functionTester(num): >> return ((num+2)/(num-2))**2 >> >> num_args = [61,62,33,7,12,16,19,35,36,37,38,55,56,57,63] >> >> num_processes = multiprocessing.cpu_count() >> pool = multiprocessing.Pool(num_processes) >> >> start = time.time() >> results = pool.map(functionTester, num_args) >> end = time.time() >> >> # is this what you meant to do with the results? >> max_result = max(results) >> print("Result " + str(max_result)) >> >> elapsed = end - start >> print("Took", elapsed, "seconds to execute") >> >> Geremy Condra >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From astan.chee at gmail.com Fri Dec 10 07:42:04 2010 From: astan.chee at gmail.com (Astan Chee) Date: Fri, 10 Dec 2010 23:42:04 +1100 Subject: run a function in another processor in python In-Reply-To: References: <4D00B416.5090509@sequans.com> Message-ID: On Fri, Dec 10, 2010 at 1:37 AM, Peter Otten <__peter__ at web.de> wrote: > I can't replicate the crash. However, your problem looks like there is a > ready-to-use solution: > > http://docs.python.org/library/multiprocessing.html#using-a-pool-of-workers > > -- > http://mail.python.org/mailman/listinfo/python-list > Pool.map doesn't seem to be able to support multiple argument functions which is what I'm trying to do here. Any other suggestions? Thanks again -------------- next part -------------- An HTML attachment was scrubbed... URL: From orasnita at gmail.com Fri Dec 10 08:39:34 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Fri, 10 Dec 2010 15:39:34 +0200 Subject: Python critique References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> Message-ID: It is true that Python doesn't use scope limitations for variables? Octavian ----- Original Message ----- From: "kolo 32" Newsgroups: comp.lang.python To: Sent: Friday, December 10, 2010 12:31 PM Subject: Python critique > Hi, all, > > Python critique from strchr.com: > > http://www.strchr.com/python_critique > -- > http://mail.python.org/mailman/listinfo/python-list From dirknbr at gmail.com Fri Dec 10 08:48:32 2010 From: dirknbr at gmail.com (Dirk Nachbar) Date: Fri, 10 Dec 2010 05:48:32 -0800 (PST) Subject: decouple copy of a list Message-ID: <9a8681fb-0c8b-42ae-aa2b-9200ca92bd2b@k11g2000vbf.googlegroups.com> I want to take a copy of a list a b=a and then do things with b which don't affect a. How can I do this? Dirk From rob.randall2 at gmail.com Fri Dec 10 08:54:42 2010 From: rob.randall2 at gmail.com (Rob Randall) Date: Fri, 10 Dec 2010 13:54:42 +0000 Subject: 64 bit memory usage In-Reply-To: <4d015be7$0$1670$742ec2ed@news.sonic.net> References: <4d015be7$0$1670$742ec2ed@news.sonic.net> Message-ID: You guys are right. If I disable the gc it will use all the virtual RAM in my test. The application I have been running these tests for is a port of a program written in a LISP-based tool running on Unix. It does a mass of stress calculations. The port has been written using a python-based toolkit I am responsible for. This toolkit offers much of the same functionlity as the LISP tool. It is based around the use of demand-driven/declarative programming. When the porting project started no one realised just how much memory the heaviest of the test cases used. It uses 40+ GB on an HP Unix machine. It is easy to see now that the port should have been written differently, but it is essentially complete now. This has lead me to see if a hardware solution can be found using 64 bit windows machnes. I will try running one the tests next to see what impact disabling the gc will have. Thanks, Rob. On 9 December 2010 22:44, John Nagle wrote: > On 12/8/2010 10:42 PM, Dennis Lee Bieber wrote: > >> On Wed, 8 Dec 2010 14:44:30 +0000, Rob Randall >> declaimed the following in gmane.comp.python.general: >> >> I am trying to understand how much memory is available to a 64 bit python >>> process running under Windows XP 64 bit. >>> >>> When I run tests just creating a series of large dictionaries containing >>> string keys and float values I do not seem to be able to grow the process >>> beyond the amount of RAM present. >>> >> > If you get to the point where you need multi-gigabyte Python > dictionaries, you may be using the wrong tool for the job. > If it's simply that you need to manage a large amount of data, > that's what databases are for. > > If this is some super high performance application that needs to keep a > big database in memory for performance reasons, CPython > is probably too slow. For that, something like Google's BigTable > may be more appropriate, and will scale to terabytes if necessary. > > John Nagle > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kushal.kumaran+python at gmail.com Fri Dec 10 08:54:51 2010 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Fri, 10 Dec 2010 19:24:51 +0530 Subject: decouple copy of a list In-Reply-To: <9a8681fb-0c8b-42ae-aa2b-9200ca92bd2b@k11g2000vbf.googlegroups.com> References: <9a8681fb-0c8b-42ae-aa2b-9200ca92bd2b@k11g2000vbf.googlegroups.com> Message-ID: On Fri, Dec 10, 2010 at 7:18 PM, Dirk Nachbar wrote: > I want to take a copy of a list a > > b=a > > and then do things with b which don't affect a. > > How can I do this? > b = a[:] will create a copy of the list. If the elements of the list are references to mutable objects (objects of your own classes, for example), you might take a look at copy.deepcopy. -- regards, kushal From urban.dani at gmail.com Fri Dec 10 08:55:25 2010 From: urban.dani at gmail.com (Daniel Urban) Date: Fri, 10 Dec 2010 14:55:25 +0100 Subject: decouple copy of a list In-Reply-To: <9a8681fb-0c8b-42ae-aa2b-9200ca92bd2b@k11g2000vbf.googlegroups.com> References: <9a8681fb-0c8b-42ae-aa2b-9200ca92bd2b@k11g2000vbf.googlegroups.com> Message-ID: b = list(a) or b = a[:] From mdw at distorted.org.uk Fri Dec 10 08:55:57 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 10 Dec 2010 13:55:57 +0000 Subject: Comparisons of incompatible types References: <2010120608591221344-tomfsessile@gmailcom> <4cfd7d07$0$29993$c3e8da3$5496439d@news.astraweb.com> <4cfebe65$0$1590$742ec2ed@news.sonic.net> <87ipz5jfr9.fsf.mdw@metalzone.distorted.org.uk> <4cfff225$0$1650$742ec2ed@news.sonic.net> <4d005835$0$1597$742ec2ed@news.sonic.net> <87vd33i1ba.fsf.mdw@metalzone.distorted.org.uk> <4d016220$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <871v5pivf6.fsf.mdw@metalzone.distorted.org.uk> Steven D'Aprano writes: > On Thu, 09 Dec 2010 12:21:45 +0000, Mark Wooding wrote: > > > John Nagle writes: > > >> "sort" has failed because it assumes that a < b and b < c implies a < > >> c. But that's not a valid assumption here. > >> > >> It's not good to break trichotomy. > > > > You're confused. The property > > > > a < b and b < c => a < c > > > > is called `transitivity'. > > Yes, but I believe that John is referring to the trichotomy (like a > dichotomy, Then why did he say `it assumes that a < b and b < c implies a < c'? This assumption is transitivity, not trichotomy. > > 2. Totality: a <= b or b <= a > > > > The above list sorting goes wrong because the `float' ordering isn't > > total. In particular, x > NaN!). > > I believe this is equivalent to trichotomy. No, it isn't. In particular, the definition of totality I gave above allows a <= b and b <= a and a /= b. You gave a perfectly good definition of trichotomy, which I have moved out of its original order: > exactly one of these relations are true: > > a < b > a == b > a > b A total preorder (as defined above) doesn't exhibit this property -- but can be described in terms of a total order (which /does/ exhibit proper trichotomy) applied to a set of equivalence classes. > > So, your last remark is in the right direction (though strict trichotomy > > is unnecessary, as I've mentioned), but apparently only by accident > > since the preceding discussion is completely wrong. > > "Completely" is surely a tad strong -- John might not be using the > exact same terminology as you, but he's clearly talking about the > equivalent concepts. He wants and expects all data types to either > meet a total order, or raise an exception to any of the < > <= and >= > operators. No. He was hopelessly confused, describing the problem in terms of a failure of transitivity (which doesn't, in fact, fail), but using the word `trichotomy', apparently more by luck than judgement. I don't want to insist on a total order. Efficient sorting requires a total preorder, and that's all I want. -- [mdw] From wolfgang at rohdewald.de Fri Dec 10 08:56:47 2010 From: wolfgang at rohdewald.de (Wolfgang Rohdewald) Date: Fri, 10 Dec 2010 14:56:47 +0100 Subject: decouple copy of a list In-Reply-To: <9a8681fb-0c8b-42ae-aa2b-9200ca92bd2b@k11g2000vbf.googlegroups.com> References: <9a8681fb-0c8b-42ae-aa2b-9200ca92bd2b@k11g2000vbf.googlegroups.com> Message-ID: <201012101456.48062.wolfgang@rohdewald.de> On Freitag 10 Dezember 2010, Dirk Nachbar wrote: > I want to take a copy of a list a > > b=a > > and then do things with b which don't affect a. > > How can I do this? > > Dirk b=a[:] -- Wolfgang From jeanmichel at sequans.com Fri Dec 10 09:02:50 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 10 Dec 2010 15:02:50 +0100 Subject: Python critique In-Reply-To: References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> Message-ID: <4D02330A.5000305@sequans.com> Octavian Rasnita wrote: > It is true that Python doesn't use scope limitations for variables? > > Octavian > Python does have scope. The problem is not the lack of scope, to problem is the shadow declaration of some python construct in the current scope. print x # raise NameError [x for x in range(10)] # shadow declaration of x print x # will print 9 it can become a problem if you write such code: index = 1 myNewList = [index*2 for index in [1,2,3,4,5]] print myNewList(index) # here most new commer would want to use index=1. To compare to some C construct, python declares the variable in the current scope while the C construct will create a new scope for the following block. IMO, i don't see this one as an issue, because even when coding in C, you do NOT use the same name for 2 different things. Python shadow declarations would be a problem for someone used to take "advantage" of the C construct. The author states that this is bug prone, I did write a lot of python lines, never happened to me. JM PS : pylint reports such shadow declaration, W0631: 4: Using possibly undefined loop variable 'x' From jeanmichel at sequans.com Fri Dec 10 09:06:18 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 10 Dec 2010 15:06:18 +0100 Subject: decouple copy of a list In-Reply-To: <9a8681fb-0c8b-42ae-aa2b-9200ca92bd2b@k11g2000vbf.googlegroups.com> References: <9a8681fb-0c8b-42ae-aa2b-9200ca92bd2b@k11g2000vbf.googlegroups.com> Message-ID: <4D0233DA.2060809@sequans.com> Dirk Nachbar wrote: > I want to take a copy of a list a > > b=a > > and then do things with b which don't affect a. > > How can I do this? > > Dirk > In [1]: a = [1,2,3] In [2]: b = a[:] In [3]: b[0] = 5 In [4]: a Out[4]: [1, 2, 3] In [5]: b Out[5]: [5, 2, 3] Alternatively, you can write import copy a = [1,2,3] b = a.copy() if the list a contains mutable objects, use copy.deepcopy (http://docs.python.org/library/copy.html) JM From dirknbr at gmail.com Fri Dec 10 09:06:42 2010 From: dirknbr at gmail.com (Dirk Nachbar) Date: Fri, 10 Dec 2010 06:06:42 -0800 (PST) Subject: decouple copy of a list References: <9a8681fb-0c8b-42ae-aa2b-9200ca92bd2b@k11g2000vbf.googlegroups.com> Message-ID: On Dec 10, 1:56?pm, Wolfgang Rohdewald wrote: > On Freitag 10 Dezember 2010, Dirk Nachbar wrote: > > > I want to take a copy of a list a > > > b=a > > > and then do things with b which don't affect a. > > > How can I do this? > > > Dirk > > b=a[:] > > -- > Wolfgang I did that but then some things I do with b happen to a as well. From stefan_ml at behnel.de Fri Dec 10 09:30:56 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 10 Dec 2010 15:30:56 +0100 Subject: Python critique In-Reply-To: <4D02330A.5000305@sequans.com> References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> <4D02330A.5000305@sequans.com> Message-ID: Jean-Michel Pichavant, 10.12.2010 15:02: > the shadow declaration of some python construct in the current scope. > > print x # raise NameError > [x for x in range(10)] # shadow declaration of x > print x # will print 9 Note that this is rarely a problem in practice, and that this has been fixed in Python 3. Stefan From wolfgang at rohdewald.de Fri Dec 10 09:36:01 2010 From: wolfgang at rohdewald.de (Wolfgang Rohdewald) Date: Fri, 10 Dec 2010 15:36:01 +0100 Subject: decouple copy of a list In-Reply-To: References: <9a8681fb-0c8b-42ae-aa2b-9200ca92bd2b@k11g2000vbf.googlegroups.com> Message-ID: <201012101536.01207.wolfgang@rohdewald.de> On Freitag 10 Dezember 2010, Dirk Nachbar wrote: > > b=a[:] > > > > -- > > Wolfgang > > I did that but then some things I do with b happen to a as > well. as others said, this is no deep copy. So if you do something to an element in b, and if the same element is in a, both are changed as they are still the same objects: >>> x,y=5,6 >>> a=[x,y] >>> b=a[:] >>> id(a),id(b) (140695481867368, 140695481867512) >>> id(a[0]),id(b[0]) (33530584, 33530584) >>> a=b >>> id(a),id(b) (140695481867512, 140695481867512) -- Wolfgang From raespi at uci.cu Fri Dec 10 09:38:28 2010 From: raespi at uci.cu (Teratux) Date: Fri, 10 Dec 2010 09:38:28 -0500 Subject: about module import .. Message-ID: <4D023B64.5010103@uci.cu> Hello ... I'm using buildbot to build some of my projects. I'm having problems when I configure it and I think it might be with the python configuration on my pc: I'm getting this error: Traceback (most recent call last): File "/usr/bin/buildbot", line 3, in from buildbot.scripts import runner File "/usr/lib/python2.5/site-packages/buildbot/scripts/runner.py", line 7, in from twisted.python import usage, util, runtime ImportError: No module named twisted.python Ok, so I assumed it might be that the python-twisted module wasn't installed. I opened up a python console and wrote: import twisted.python And it doesn't complain. I have the twisted.python module installed on my pc but for some reason buildbot isn't loading it. Is there some way to know if there's a misconfiguration in my computer? I'm using Debian Lenny 5.0 and python 2.5.2. Thanks ... -------------- next part -------------- An HTML attachment was scrubbed... URL: From orasnita at gmail.com Fri Dec 10 10:27:25 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Fri, 10 Dec 2010 17:27:25 +0200 Subject: Python critique References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> <4D02330A.5000305@sequans.com> Message-ID: <1FDA7F3970EA4D79B4BD52BA8EBC28D2@teddy> From: "Jean-Michel Pichavant" > > Octavian Rasnita wrote: >> It is true that Python doesn't use scope limitations for variables? >> >> Octavian >> > Python does have scope. The problem is not the lack of scope, to > problem is the shadow declaration of some python construct in the > current scope. It's OK then. > print x # raise NameError > [x for x in range(10)] # shadow declaration of x > print x # will print 9 > > it can become a problem if you write such code: > > index = 1 > myNewList = [index*2 for index in [1,2,3,4,5]] > print myNewList(index) # here most new commer would want to use index=1. Yes, it is not such a big deal. Octavian From pruebauno at latinmail.com Fri Dec 10 11:17:19 2010 From: pruebauno at latinmail.com (nn) Date: Fri, 10 Dec 2010 08:17:19 -0800 (PST) Subject: Deprecation warnings (2.7 -> 3 ) References: <44caabf0-7f83-42b8-abf9-eb40ea6b63a8@i32g2000pri.googlegroups.com> Message-ID: On Dec 9, 10:15?pm, rusi wrote: > In trying to get from 2.x to 3 Terry suggested I use 2.7 with > deprecation warnings > > Heres the (first) set > > DeprecationWarning: Overriding __eq__ blocks inheritance of __hash__ > in 3.x > DeprecationWarning: callable() not supported in 3.x; use isinstance(x, > collections.Callable) > > Is there one place/site I can go to for understanding all these and > trying to clear them? I don't know any place that explains those. But the second is a pretty straightforward: replace "callable(x)" by "isinstance(x, collections.Callable)" The first one is more tricky. You have to find the class with a __eq__ method in it and copy and paste the __hash__ method from its superclass into itself. From fpm at u.washington.edu Fri Dec 10 11:18:36 2010 From: fpm at u.washington.edu (cassiope) Date: Fri, 10 Dec 2010 08:18:36 -0800 (PST) Subject: decouple copy of a list References: <9a8681fb-0c8b-42ae-aa2b-9200ca92bd2b@k11g2000vbf.googlegroups.com> Message-ID: <1a0f8988-e206-46c4-babb-c02738792740@f21g2000prn.googlegroups.com> On Dec 10, 6:06?am, Jean-Michel Pichavant wrote: > Dirk Nachbar wrote: > > I want to take a copy of a list a > > > b=a > > > and then do things with b which don't affect a. > > > How can I do this? > > > Dirk > > In [1]: a = [1,2,3] > > In [2]: b = a[:] > > In [3]: b[0] = 5 > > In [4]: a > Out[4]: [1, 2, 3] > > In [5]: b > Out[5]: [5, 2, 3] > > Alternatively, you can write > > import copy > a = [1,2,3] > b = a.copy() > > if the list a contains mutable objects, use copy.deepcopy > (http://docs.python.org/library/copy.html) > > JM I'm not a pyguru, but... you didn't use copy quite right. Try instead: b= copy.copy(a) The other issue that the original person has noticed is that a list may include a reference to something. When a list is copied - if the reference is copied (not "deepcopied"], changes to the referred object will be visible in both lists, even if they are different lists. For more information, refer to the docs in the module. HTH... From pruebauno at latinmail.com Fri Dec 10 11:24:08 2010 From: pruebauno at latinmail.com (nn) Date: Fri, 10 Dec 2010 08:24:08 -0800 (PST) Subject: Deprecation warnings (2.7 -> 3 ) References: <44caabf0-7f83-42b8-abf9-eb40ea6b63a8@i32g2000pri.googlegroups.com> Message-ID: On Dec 10, 11:17?am, nn wrote: > On Dec 9, 10:15?pm, rusi wrote: > > > In trying to get from 2.x to 3 Terry suggested I use 2.7 with > > deprecation warnings > > > Heres the (first) set > > > DeprecationWarning: Overriding __eq__ blocks inheritance of __hash__ > > in 3.x > > DeprecationWarning: callable() not supported in 3.x; use isinstance(x, > > collections.Callable) > > > Is there one place/site I can go to for understanding all these and > > trying to clear them? > > I don't know any place that explains those. But the second is a pretty > straightforward: replace "callable(x)" by "isinstance(x, > collections.Callable)" > > The first one is more tricky. You have to find the class with a __eq__ > method in it and copy and paste the __hash__ method from its > superclass into itself. And BTW callable was deprecated in 3.0 and then added back in for 3.2. So if you decide to not support 3.0 and 3.1 you would be fine just leaving it as is. From mail at timgolden.me.uk Fri Dec 10 11:25:37 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 10 Dec 2010 16:25:37 +0000 Subject: Deprecation warnings (2.7 -> 3 ) In-Reply-To: References: <44caabf0-7f83-42b8-abf9-eb40ea6b63a8@i32g2000pri.googlegroups.com> Message-ID: <4D025481.3090808@timgolden.me.uk> On 10/12/2010 16:17, nn wrote: > On Dec 9, 10:15 pm, rusi wrote: >> In trying to get from 2.x to 3 Terry suggested I use 2.7 with >> deprecation warnings >> >> Heres the (first) set >> >> DeprecationWarning: Overriding __eq__ blocks inheritance of __hash__ >> in 3.x >> DeprecationWarning: callable() not supported in 3.x; use isinstance(x, >> collections.Callable) >> >> Is there one place/site I can go to for understanding all these and >> trying to clear them? Not quite an answer, but: http://docs.python.org/dev/py3k/whatsnew/3.0.html TJG From rustompmody at gmail.com Fri Dec 10 11:25:43 2010 From: rustompmody at gmail.com (rusi) Date: Fri, 10 Dec 2010 08:25:43 -0800 (PST) Subject: Deprecation warnings (2.7 -> 3 ) References: <44caabf0-7f83-42b8-abf9-eb40ea6b63a8@i32g2000pri.googlegroups.com> Message-ID: <139e14a8-2ba9-429f-984f-7b7e6c277efb@r16g2000prh.googlegroups.com> On Dec 10, 9:17?pm, nn wrote: > On Dec 9, 10:15?pm, rusi wrote: > > > In trying to get from 2.x to 3 Terry suggested I use 2.7 with > > deprecation warnings > > > Heres the (first) set > > > DeprecationWarning: Overriding __eq__ blocks inheritance of __hash__ > > in 3.x > > DeprecationWarning: callable() not supported in 3.x; use isinstance(x, > > collections.Callable) > > > Is there one place/site I can go to for understanding all these and > > trying to clear them? > > I don't know any place that explains those. But the second is a pretty > straightforward: replace "callable(x)" by "isinstance(x, > collections.Callable)" Of course. I was asking for more generic instructions/suggestions on porting like what you've given below [Say I get 25 more such warnings... And then moving to 3.2 I get errors...] > > The first one is more tricky. You have to find the class with a __eq__ > method in it and copy and paste the __hash__ method from its > superclass into itself. From rustompmody at gmail.com Fri Dec 10 11:28:01 2010 From: rustompmody at gmail.com (rusi) Date: Fri, 10 Dec 2010 08:28:01 -0800 (PST) Subject: trace cmd line args in 2.7 References: Message-ID: <3c56b207-2e65-4505-a337-afe2c4ec8650@m20g2000prc.googlegroups.com> On Dec 10, 10:53?am, rusi wrote: > Ive installed python 2.7 > And trace still ignores my ignore-module etc requests Is this a know bug with the trace module? I find it hard to believe that as traces naturally tend to get huge unless carefully trimmed From pruebauno at latinmail.com Fri Dec 10 11:29:38 2010 From: pruebauno at latinmail.com (nn) Date: Fri, 10 Dec 2010 08:29:38 -0800 (PST) Subject: decouple copy of a list References: <9a8681fb-0c8b-42ae-aa2b-9200ca92bd2b@k11g2000vbf.googlegroups.com> Message-ID: <22718b65-8da7-4076-a8fd-2314d70a0e04@29g2000yqq.googlegroups.com> On Dec 10, 8:48?am, Dirk Nachbar wrote: > I want to take a copy of a list a > > b=a > > and then do things with b which don't affect a. > > How can I do this? > > Dirk Not knowing the particulars, you may have to use: import copy b=copy.deepcopy(a) From samwyse at gmail.com Fri Dec 10 11:36:13 2010 From: samwyse at gmail.com (samwyse) Date: Fri, 10 Dec 2010 08:36:13 -0800 (PST) Subject: optparse/argparse for cgi/wsgi? Message-ID: Has anyone ever built some sort of optparse/argparse module for cgi/ wsgi programs? I can see why a straight port wouldn't work, but a module that can organize parameter handling for web pages seems like a good idea, especially if it provided a standard collection of both client- and server-side validation processes, easy internationalization, and a way to create customizable help pages. From hoesley at gmail.com Fri Dec 10 11:57:49 2010 From: hoesley at gmail.com (hoesley) Date: Fri, 10 Dec 2010 08:57:49 -0800 (PST) Subject: continuing development on modules after they're installed Message-ID: <2a700607-78ee-4186-bf80-da02920daceb@m7g2000vbn.googlegroups.com> I just started using distutils to install the modules I'm working on to site-packages. Now, however, if I make changes in my development directory, then import the modules into python, it always loads up the installed version. Thus, I can't continue development without first uninstalling the modules I'm working on, so that the interpreter finds them in the local directory instead of site-packages. Is there any simple way around this? I figure this must be a very common thing to encounter. Thanks! From sohel807 at gmail.com Fri Dec 10 12:11:55 2010 From: sohel807 at gmail.com (Akand Islam) Date: Fri, 10 Dec 2010 09:11:55 -0800 (PST) Subject: Sage's Python Message-ID: In my system (Ubuntu 10.04) there are sage-4.6, python 2.6.5, tk8.5- dev installed. When I give command from terminal "sage -f python-2.6.5.p8" to get sage's python it shows following message: No command 'sage' found, did you mean: Command 'save' from package 'atfs' (universe) Command 'page' from package 'tcllib' (universe) sage: command not found How can I get Sage's python to be worked so that I can import sage.all in python shell? Thanks in advance. --Akand From ian.g.kelly at gmail.com Fri Dec 10 12:32:05 2010 From: ian.g.kelly at gmail.com (Ian) Date: Fri, 10 Dec 2010 09:32:05 -0800 (PST) Subject: continuing development on modules after they're installed References: <2a700607-78ee-4186-bf80-da02920daceb@m7g2000vbn.googlegroups.com> Message-ID: On Dec 10, 9:57?am, hoesley wrote: > I just started using distutils to install the modules I'm working on > to site-packages. Now, however, if I make changes in my development > directory, then import the modules into python, it always loads up the > installed version. Thus, I can't continue development without first > uninstalling the modules I'm working on, so that the interpreter finds > them in the local directory instead of site-packages. Is there any > simple way around this? I figure this must be a very common thing to > encounter. Thanks! Do you need the installed version to be distinct from the development version? If not, you can "install" the module using a simple soft link (on Unix) or a .pth file (on Windows) that points to your development directory. If you do need them to be distinct, a simple way to preferentially get the development version is to add it to the *beginning* of sys.path: sys.path.insert(0, '/path/to/development/directory/') This process can be simplified further by putting it in a PYTHONSTARTUP script. HTH, Ian From jeanmichel at sequans.com Fri Dec 10 13:23:15 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 10 Dec 2010 19:23:15 +0100 Subject: decouple copy of a list In-Reply-To: <1a0f8988-e206-46c4-babb-c02738792740@f21g2000prn.googlegroups.com> References: <9a8681fb-0c8b-42ae-aa2b-9200ca92bd2b@k11g2000vbf.googlegroups.com> <1a0f8988-e206-46c4-babb-c02738792740@f21g2000prn.googlegroups.com> Message-ID: <4D027013.9070405@sequans.com> cassiope wrote: >> Alternatively, you can write >> >> import copy >> a = [1,2,3] >> b = a.copy() >> >> >> JM >> > > I'm not a pyguru, but... you didn't use copy quite right. > Try instead: b= copy.copy(a) > > You're right, you're not a python guru so don't even try to contradict me ever again. ... :D of course I did it completly wrong. I don't know what happened in my brain at that time, maybe nothing and that's the point. JM From vinay_sajip at yahoo.co.uk Fri Dec 10 13:44:33 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Fri, 10 Dec 2010 10:44:33 -0800 (PST) Subject: Proposed changes to logging defaults References: <3763d355-9074-485c-a694-031d600d5b84@m11g2000vbs.googlegroups.com> Message-ID: <9a8c49a6-d24f-4e27-b2e7-2ba654f8236a@t8g2000prh.googlegroups.com> On Dec 10, 10:17?am, Jean-Michel Pichavant wrote: Hi Jean-Michel, I think Antoine answered your other points, so I'll address the last one: > Last question, if no handler is found, why not simply drop the log > event, doing nothing ? It sounds pretty reasonable and less intrusive. That is what happens at the moment if configured for production (logging.raiseExceptions is False) - nothing happens, and the event is discarded. For development (logging.raiseExceptions is True), the "No handlers were found for logger XXX" is printed once, to assist developers to detect misconfiguration. However, the original logged event is still discarded. The original philosophy (when logging was added to Python) was that logging is an adjunct to the operation of the program using it - the program should work the same way whether or not logging is configured. However, the consensus on Python-dev is that the logging package should do useful work, and not just act as an adjunct, i.e. notify the user on warning and error conditions by default if no logging configuration is set up. A program will now work differently depending on whether logging is configured, but if it is not configured, the default should be to display warnings and errors, unless explicitly silenced (as per the Zen of Python). These two approaches (original vs. proposed) are of course quite different, and there's no way of satisfying both proponents of both approaches, nor any easy way of measuring how many of each there are. The proposed change moves logging closer to the current Python-dev consensus, and means that messages currently written to sys.stderr by stdlib modules could be logged instead, with the stdlib maintainers writing those messages knowing that unless explicitly silenced, those messages will appear to the user as they would via a sys.stderr.write(). It will be good if this happens, so that application writers will have better control over what messages are displayed (when they need it), by configuring logging. Remember - no changes to behaviour will occur if this change is implemented and an application configures logging. It's only the no- configuration case that will change. To get the current behaviour after the proposed changes are implemented, an application developer would have to do logging.lastResort = None, which is a small price to pay (and more or less equivalent in difficulty with what users who want verbosity by default have to do, e.g. call basicConfig(). Regards, Vinay Sajip From aviral.nit at gmail.com Fri Dec 10 13:47:42 2010 From: aviral.nit at gmail.com (aviral gupta) Date: Fri, 10 Dec 2010 10:47:42 -0800 (PST) Subject: Interview Programming puzzles Message-ID: <4c87194d-c5a7-4a97-aa10-b7b7b997ce6f@h17g2000pre.googlegroups.com> For Programming puzzles visit the blog http://coders-stop.blogspot.com/ From rob.randall2 at gmail.com Fri Dec 10 14:03:19 2010 From: rob.randall2 at gmail.com (Rob Randall) Date: Fri, 10 Dec 2010 19:03:19 +0000 Subject: 64 bit memory usage In-Reply-To: References: <4d015be7$0$1670$742ec2ed@news.sonic.net> Message-ID: I manged to get my python app past 3GB on a smaller 64 bit machine. On a test to check memory usage with gc disabled only an extra 6MB was used. The figures were 1693MB to 1687MB. This is great. Thanks again for the help. On 10 December 2010 13:54, Rob Randall wrote: > You guys are right. If I disable the gc it will use all the virtual RAM in > my test. > > The application I have been running these tests for is a port of a program > written in a LISP-based tool running on Unix. > It does a mass of stress calculations. > > The port has been written using a python-based toolkit I am responsible > for. This toolkit offers much of the same functionlity as the LISP tool. > It is based around the use of demand-driven/declarative programming. > > When the porting project started no one realised just how much memory the > heaviest of the test cases used. > It uses 40+ GB on an HP Unix machine. > > It is easy to see now that the port should have been written differently, > but it is essentially complete now. > > This has lead me to see if a hardware solution can be found using 64 bit > windows machnes. > > I will try running one the tests next to see what impact disabling the gc > will have. > > Thanks, > Rob. > > > > On 9 December 2010 22:44, John Nagle wrote: > >> On 12/8/2010 10:42 PM, Dennis Lee Bieber wrote: >> >>> On Wed, 8 Dec 2010 14:44:30 +0000, Rob Randall >>> declaimed the following in gmane.comp.python.general: >>> >>> I am trying to understand how much memory is available to a 64 bit >>>> python >>>> process running under Windows XP 64 bit. >>>> >>>> When I run tests just creating a series of large dictionaries containing >>>> string keys and float values I do not seem to be able to grow the >>>> process >>>> beyond the amount of RAM present. >>>> >>> >> If you get to the point where you need multi-gigabyte Python >> dictionaries, you may be using the wrong tool for the job. >> If it's simply that you need to manage a large amount of data, >> that's what databases are for. >> >> If this is some super high performance application that needs to keep a >> big database in memory for performance reasons, CPython >> is probably too slow. For that, something like Google's BigTable >> may be more appropriate, and will scale to terabytes if necessary. >> >> John Nagle >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jgardner at jonathangardner.net Fri Dec 10 14:08:46 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Fri, 10 Dec 2010 11:08:46 -0800 Subject: continuing development on modules after they're installed In-Reply-To: References: <2a700607-78ee-4186-bf80-da02920daceb@m7g2000vbn.googlegroups.com> Message-ID: On Fri, Dec 10, 2010 at 9:32 AM, Ian wrote: > On Dec 10, 9:57?am, hoesley wrote: >> I just started using distutils to install the modules I'm working on >> to site-packages. Now, however, if I make changes in my development >> directory, then import the modules into python, it always loads up the >> installed version. Thus, I can't continue development without first >> uninstalling the modules I'm working on, so that the interpreter finds >> them in the local directory instead of site-packages. Is there any >> simple way around this? I figure this must be a very common thing to >> encounter. Thanks! > > Do you need the installed version to be distinct from the development > version? ?If not, you can "install" the module using a simple soft > link (on Unix) or a .pth file (on Windows) that points to your > development directory. > > If you do need them to be distinct, a simple way to preferentially get > the development version is to add it to the *beginning* of sys.path: > > sys.path.insert(0, '/path/to/development/directory/') > > This process can be simplified further by putting it in a > PYTHONSTARTUP script. > A simpler way to do this is to use virtualenv. $ virtualenv --no-site-packages YourEnv $ . YourEnv/bin/activate $ cd YourProject $ python setup.py develop (I'm not sure on the Windows commands, although I assume they exist and are just as trivial as the Unix ones.) Now, there is a link from the lib/python2.6/site-packages files to YourProject. (Or Python2.7 or whatever version you are using.) I'd also look at using Paster to create the package. It gives you a pretty decent setup for straight up Python packages. -- Jonathan Gardner jgardner at jonathangardner.net From python at mrabarnett.plus.com Fri Dec 10 14:18:41 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 10 Dec 2010 19:18:41 +0000 Subject: run a function in another processor in python In-Reply-To: References: <4D00B416.5090509@sequans.com> Message-ID: <4D027D11.9090400@mrabarnett.plus.com> On 10/12/2010 17:52, Dennis Lee Bieber wrote: > On Fri, 10 Dec 2010 23:02:24 +1100, Astan Chee > declaimed the following in gmane.comp.python.general: > >>>> for thread in threads: >>>> if not thread.is_alive(): >>>> threads.remove(thread) >>>> > > I can see a potential flaw just in that... You are changing the > length of the list you are iterating over, which is never recommended. > > Consider this simplistic attempt at removing the even numbers from a > list: > >>>> tlist = [1, 1, 0, 0, 2, 2, 3, 4, 3, 4, 5, 6, 7, 8] >>>> for t in tlist: > ... if t % 2 == 0: > ... tlist.remove(t) > ... >>>> tlist > [1, 1, 0, 2, 3, 3, 5, 7] >>>> > > Doesn't work if a pair of even numbers are adjacent. In your case, > adjacent "dead" threads will not be removed. > > Something like the following may be safer: > > dead = [] > for t in threads: > if not t.is_alive(): > dead.append(t) > for dt in dead: > threads.remove(dt) I think this will be more efficient: threads = [t for t in threads if t.is_alive()] From rossgk at gmail.com Fri Dec 10 14:51:44 2010 From: rossgk at gmail.com (Ross) Date: Fri, 10 Dec 2010 11:51:44 -0800 (PST) Subject: unicode compare errors Message-ID: <549e0020-e21e-49c5-bc89-21122f9ce0a9@35g2000prb.googlegroups.com> I've a character encoding issue that has stumped me (not that hard to do). I am parsing a small text file with some possibility of various currencies being involved, and want to handle them without messing up. Initially I was simply doing: currs = [u'$', u'?', u'?', u'?'] aFile = open(thisFile, 'r') for mline in aFile: # mline might be "?5.50" if item[0] in currs: item = item[1:] But the problem was: SyntaxError: Non-ASCII character '\xa3' in file The remedy was of course to declare the file encoding for my Python module, at the start of the file I used: # -*- coding: UTF-8 -*- That allowed me to progress. But now when I come to line item that is a non $ currency, I get this error: views.py:3364: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal. ?which I think means Python's unable to convert the char's in the file I'm reading from into unicode to compare to the items in the list currs. I think this is saying that u'?' == '?' is false. (I hope those chars show up okay in my post here) Since I can't control the encoding of the input file that users submit, how to I get past this? How do I make such comparisons be True? Thanks in advance for any suggestions Ross. From alex at moreati.org.uk Fri Dec 10 14:57:56 2010 From: alex at moreati.org.uk (Alex Willmer) Date: Fri, 10 Dec 2010 11:57:56 -0800 (PST) Subject: Python creates "locked" temp dir References: <0c30c818-f73b-4b09-b707-64ea457c757d@z26g2000prf.googlegroups.com> <91dca7c4-00c7-44ad-8902-54221534107c@o9g2000pre.googlegroups.com> Message-ID: <753d0b5b-867b-456c-b3e9-2662ce1df1f8@f20g2000vbc.googlegroups.com> On Dec 8, 6:26?pm, Christian Heimes wrote: > There isn't a way to limit access to a single process. mkdtemp creates > the directory with mode 0700 and thus limits it to the (effective) user > of the current process. Any process of the same user is able to access > the directory. > > Christian Quite right. My apologies for confusing temporary file creation, for which exclusive access is used and temporary directory creation for which there is no such mode. From smallpox911 at gmail.com Fri Dec 10 15:01:51 2010 From: smallpox911 at gmail.com (small Pox) Date: Fri, 10 Dec 2010 12:01:51 -0800 (PST) Subject: Biography, Dr Michel Chossudovsky, Dr.Evgeny Chossudovsky: Writer with a distinguished UN career Message-ID: <1007de6e-544d-4d9f-8b66-615566a1fb29@e16g2000pri.googlegroups.com> http://www.globalresearch.ca/index.php?context=viewArticle&code=20060212&articleId=1955 Evgeny Chossudovsky: Writer with a distinguished UN career Global Research, February 12, 2006 The Irish Times - 2006-01-18 Throughout his UN career and until his death, Evgeny Chossudovsky expressed his firm support for the Palestinian cause. He supported the Centre for Research on Globalization from the outset. Global Research will continue in his footsteps to support the causes of social justice and World peace. (Michel Chossudovsky) The Irish Times January 28, 2006 Saturday OBITUARY Dr Evgeny Chossudovsky, who has died aged 91, was a Russian Jewish ?migr? who had a distinguished career with the United Nations following the second World War. In Dublin, in the late 1970s, he continued another role as a prestigious writer on international relations. He was a trenchant, knowledgeable and dogged participant in internationalist discussions at the Royal Irish Academy and in many publications, including The Irish Times. "Chossy" to his friends, he was well known too for a fine sense of humour. His family had been displaced by the civil war that followed the 1917 Russian Revolution and by the first World War. The Irish connection was made in the 1930s when, as a student, he met his wife Rachel Sullivan, then studying at Queen's University Belfast, at a Geneva summer school. She was from a Co Antrim Protestant family. In 1939 they were married in a Belfast registry office. In the late 1970s they settled in Baily, Howth. Chossudovsky "decided he wanted to be in the UN before it even existed", his son Michel, professor of economics at the University of Ottawa, said at his funeral. In 1947 he became one of three special assistants to the distinguished Swedish economist, and later Nobel laureate, Gunnar Myrdal, director of the UN's Economic Commission for Europe (ECE). As the Cold War deepened, Myrdal and his "ECE trinity" pushed the concept of East-West co-operation and peaceful coexistence between conflicting economic systems, in which Chossudovsky believed passionately. He served the UN Conference on Trade and Development (Unctad) under the Argentinian former central banker, Ra?l Prebisch. Intended to embrace the aspirations of poor countries, Unctad was a Non-Aligned Movement initiative. Chossudovsky was secretary of its Trade and Development Board and his considerable diplomatic skills as a consensus-maker emerged at international conferences. He worked behind the scenes, often into the small hours, agreeing resolutions with delegations in a determination to achieve global social justice. But as the toothless Unctad became undermined by the "neo-liberal" agenda and the later Uruguay Round and General Agreement on Tariffs and Trade (Gatt), Chossudovsky moved to become director of the UN Institute for Training and Research (Unitar) in Geneva. Later, in semi- retirement, he became a special fellow of the institute. All his life Chossudovsky retained a patriotic attachment to Russia and a sympathy for socialist ideas. But at the end he expressed disappointment that the spirit of the UN was being undermined, saying only weeks ago to his son that the world was now "in an awful situation". He was born in 1914 into an affluent Jewish merchant family in Rostov- on-Don near the Sea of Azov. His grandfather traded in wheat. The family went to Berlin in 1921 during the civil war. Their property had been confiscated. His father was a gifted actor who had trained as a lawyer but as a Jew was unable to practise. In Rostov-on-Don he ran a Shakespearean theatre and in Berlin various jobs included selling ice-cream on the street. But Chossudovsky's beloved rich maternal uncle, Moses Gorfman, stepped in to "look after" the family, particularly as it became dispersed. In Berlin Chossudovsky resumed school, and studied Goethe. He became equally fluent in German and Russian - and later English and French. After school, he applied to universities abroad. As a Jew, there was little question of studying in Nazi Germany. He was accepted by the University of Edinburgh, where he studied economics and earned a PhD. As Chossudovsky's studies started in 1934 his uncle Moses, a businessman who traded in the stock market, was living in London. He later left for Paris, where Evgeny's parents joined him. During the war, on the night French police came to take uncle Moses away for extermination at Auschwitz, his parents were overlooked. Chossudovsky received no news of them until after the war. He worked for the Co-operative Movement, first in Wales as an adult education officer for miners giving evening courses in international affairs, and then in London. Highly committed to its ideals, he worked for the movement until 1947. A year earlier, he had applied to the UN. He had a Soviet passport and the UN wanted Russians. After a brief stint in New York (which he judged no place to bring up children) he transferred to the Europe office of the UN in Geneva. Ever since falling in love in Geneva he had wanted to live there. Chossudovsky was author and co-author of several books including The Helsinki Final Act Viewed in the United Nations Perspective. He co- edited The United Nations System at Geneva - A Working Guide and contributed to the International Herald Tribune, Le Monde Diplomatique and the journal Foreign Affairs. He was also a frequent participant at disarmament conferences of the Pugwash group. His Irish Times contributions were on a wide range of issues, including the North. He also contributed to the Royal Irish Academy's Irish Studies in International Affairs. Dr Ronan Fanning, professor of history at UCD, said Chossudovsky was "an outside voice" at the academy who "played a role broadening our perspectives" at a time when objective discussion was difficult in Ireland. He loved Wilde, Beckett and Joyce. He was predeceased by his wife Rachel in 1996; is survived by his daughter, Eugenia, son Michel and his wife Micheline; and two grandchildren, Natacha and Maya. Dr Evgeny Michel Chossudovsky: born August 15th, 1914; died January 4th, 2006 P.S. Google is mischieving with my posts ? If there are duplicate, they are because sometimes I post and it does not and if I repeat it dups at other times. It only happens from this account ... so its targetted. Google mischief or censorship to put me in disrepute as spammer ????!!!! From nagle at animats.com Fri Dec 10 15:02:21 2010 From: nagle at animats.com (John Nagle) Date: Fri, 10 Dec 2010 12:02:21 -0800 Subject: Python critique In-Reply-To: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> Message-ID: <4d028748$0$1621$742ec2ed@news.sonic.net> On 12/10/2010 2:31 AM, kolo 32 wrote: > Hi, all, > > Python critique from strchr.com: > > http://www.strchr.com/python_critique I have criticisms of Python, but those aren't them. Probably the biggest practical problem with CPython is that C modules have to be closely matched to the version of CPython. There's no well-defined API that doesn't change. This make life easier for Guido and tough on everybody else. That's the real cause of Python's "version hell". On the scope front, given the lack of declarations, Python has done reasonably well. Scopes in Python aren't as narrow as one might like, but this isn't a major headache. Python has been more successful with the "no declarations" rule than most other languages. Others that started with no declarations, from FORTRAN to JavaScript, eventually had to retrofit them. Interestingly, some of the motivation for "functional programming" in Python, with lambdas and list comprehensions, is to get a very local scope for a very local variable. John Nagle From rossgk at gmail.com Fri Dec 10 15:07:19 2010 From: rossgk at gmail.com (Ross) Date: Fri, 10 Dec 2010 12:07:19 -0800 (PST) Subject: unicode compare errors References: <549e0020-e21e-49c5-bc89-21122f9ce0a9@35g2000prb.googlegroups.com> Message-ID: On Dec 10, 2:51?pm, Ross wrote: > Initially I was simply doing: > > ? currs = [u'$', u'?', u'?', u'?'] > ? aFile = open(thisFile, 'r') > ? for mline in aFile: ? ? ? ? ? ? ?# mline might be "?5.50" > ? ? ?if item[0] in currs: > ? ? ? ? ? item = item[1:] > Don't you love it when someone solves their own problem? Posting a reply here so that other poor chumps like me can get around this... I found I could import codecs that allow me to read the file with my desired encoding. Huzzah! Instead of opening the file with a standard aFile = open(thisFile, 'r') I instead ensure I've imported the codecs: import codecs ... and then I used a specific encoding on the file read: aFile = codecs.open(thisFile, encoding='utf-8') Then all my compares seem to work fine. If I'm off-base and kludgey here and should be doing something differently please give me a poke. Regards, Ross. From ben+python at benfinney.id.au Fri Dec 10 15:23:49 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 11 Dec 2010 07:23:49 +1100 Subject: decouple copy of a list References: <9a8681fb-0c8b-42ae-aa2b-9200ca92bd2b@k11g2000vbf.googlegroups.com> Message-ID: <87k4jhz8a2.fsf@benfinney.id.au> Dirk Nachbar writes: > I want to take a copy of a list a > > b=a In addition to the other good replies you've received: To take a copy of an object, the answer is never ?b = a?. That binds a reference ?b? to the same object referenced by ?a?. The assignment operator ?=? never copies; it binds a reference to an existing object. To create a copy, you always need to do something other than assignment. Hope that keeps it clear for you. -- \ ?Computer perspective on Moore's Law: Human effort becomes | `\ twice as expensive roughly every two years.? ?anonymous | _o__) | Ben Finney From nobody at nowhere.com Fri Dec 10 16:09:05 2010 From: nobody at nowhere.com (Nobody) Date: Fri, 10 Dec 2010 21:09:05 +0000 Subject: unicode compare errors References: <549e0020-e21e-49c5-bc89-21122f9ce0a9@35g2000prb.googlegroups.com> Message-ID: On Fri, 10 Dec 2010 11:51:44 -0800, Ross wrote: > Since I can't control the encoding of the input file that users > submit, how to I get past this? How do I make such comparisons be > True? On Fri, 10 Dec 2010 12:07:19 -0800, Ross wrote: > I found I could import codecs that allow me to read the file with my > desired encoding. Huzzah! > If I'm off-base and kludgey here and should be doing something Er, do you know the file's encoding or don't you? Using: aFile = codecs.open(thisFile, encoding='utf-8') is telling Python that the file /is/ in utf-8. If it isn't in utf-8, you'll get decoding errors. If you are given a file with no known encoding, then you can't reliably determine what /characters/ it contains, and thus can't reliably compare the contents of the file against strings of characters, only against strings of bytes. About the best you can do is to use an autodetection library such as: http://chardet.feedparser.org/ From debatem1 at gmail.com Fri Dec 10 17:04:12 2010 From: debatem1 at gmail.com (geremy condra) Date: Fri, 10 Dec 2010 14:04:12 -0800 Subject: run a function in another processor in python In-Reply-To: References: <4D00B416.5090509@sequans.com> Message-ID: On Fri, Dec 10, 2010 at 4:42 AM, Astan Chee wrote: > On Fri, Dec 10, 2010 at 1:37 AM, Peter Otten <__peter__ at web.de> wrote: >> >> I can't replicate the crash. However, your problem looks like there is a >> ready-to-use solution: >> >> >> http://docs.python.org/library/multiprocessing.html#using-a-pool-of-workers >> >> -- >> http://mail.python.org/mailman/listinfo/python-list > > > Pool.map doesn't seem to be able to support multiple argument functions > which is what I'm trying to do here. Any other suggestions? > Thanks again 1. Post the real code you're using, and 2. Put the arguments you want in a tuple and pass that. As an example, let's say I have the following function: def my_func(x, y, z): return x + y * z you could rewrite this as: def my_func(*args): return args[0] + args[1] * args[2] Here's a worked-out example: #! /usr/bin/env python3 import multiprocessing def my_func(x, y, z): return x + y * z def my_func_wrapper(t): return my_func(*t) # assume we can get an iterable over each argument xs = [1, 2, 3, 4] ys = [5, 6, 7, 8] zs = [9, 1, 2, 3] # set up the pool to match the number of CPUs num_processes = multiprocessing.cpu_count() pool = multiprocessing.Pool(num_processes) #will call my_func(1, 5, 9), my_func(2, 6, 1), etc. results = pool.map(my_func_wrapper, zip(xs, ys, zs)) print(results) Interesting factoid: you can't seem to use lambda or a decorator to do this, which would have been my first instinct. Pickle apparently chokes, although marshall wouldn't. Geremy Condra From stefaan.himpe at gmail.com Fri Dec 10 17:06:43 2010 From: stefaan.himpe at gmail.com (Stefaan Himpe) Date: Fri, 10 Dec 2010 23:06:43 +0100 Subject: surprised by import in python 2.6 Message-ID: Hello list, Recently someone asked me this question, to which I could not give an answer. I'm hoping for some insight, or a manual page. What follows is python 2.6. The problem is with the difference between from test import * and import test First things first. Here's the code to test.py: a = 3 def f(): global a return a Now, in the interactive interpreter: >>> from test import * >>> a 3 >>> f() 3 >>> a = 4 >>> f() 3 in a second session: >>> import test >>> test.a 3 >>> test.f() 3 >>> test.a = 4 >>> test.f() 4 Somehow, in the first session I cannot modify the global variable a returned from f, but in the second session I can. To my eye, the only difference seems to be a namespace. Can anyone shine some light on this matter? Thanks, Stefaan. From ian.g.kelly at gmail.com Fri Dec 10 17:22:54 2010 From: ian.g.kelly at gmail.com (Ian) Date: Fri, 10 Dec 2010 14:22:54 -0800 (PST) Subject: surprised by import in python 2.6 References: Message-ID: On Dec 10, 3:06?pm, Stefaan Himpe wrote: > Somehow, in the first session I cannot modify the global variable a > returned from f, but in the second session I can. To my eye, the only > difference seems to be a namespace. Can anyone shine some light on this > matter? It's not the same global variable. In the second session, you import the module test and bind it to the name "test" in the main namespace. "test.a" and "test.f" refer to the objects named "a" and "f" in the test namespace. In the first session, you import all the variables exported by the module test and bind them using the same names in the main namespace. Thus "a" and "test.a" refer to the same int; and "f" and "test.f" refer to the same function, but they are not the same variables. When you rebind the name "a", it does not also magically rebind "test.a", and vice versa. Cheers, Ian From emile at fenx.com Fri Dec 10 17:40:01 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 10 Dec 2010 14:40:01 -0800 Subject: surprised by import in python 2.6 In-Reply-To: References: Message-ID: On 12/10/2010 2:22 PM Ian said... > On Dec 10, 3:06 pm, Stefaan Himpe wrote: >> Somehow, in the first session I cannot modify the global variable a >> returned from f, but in the second session I can. To my eye, the only >> difference seems to be a namespace. Can anyone shine some light on this >> matter? > > It's not the same global variable. In the second session, you import > the module test and bind it to the name "test" in the main namespace. > "test.a" and "test.f" refer to the objects named "a" and "f" in the > test namespace. > > In the first session, you import all the variables exported by the > module test and bind them using the same names in the main namespace. > Thus "a" and "test.a" refer to the same int; and "f" and "test.f" > refer to the same function, but they are not the same variables. When > you rebind the name "a", it does not also magically rebind "test.a", > and vice versa. > Here's an example of what Ian's explained showing that f's global namespace is the test module: emile at paj39:~$ cat > test.py a = 3 def f(): global a return a emile at paj39:~$ python Python 2.6.4rc2 (r264rc2:75497, Oct 20 2009, 02:55:11) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from test import * >>> import test >>> a 3 >>> a = 4 >>> f() 3 >>> test.a = 5 >>> f() 5 >>> From orasnita at gmail.com Fri Dec 10 17:46:41 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Sat, 11 Dec 2010 00:46:41 +0200 Subject: Python critique References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> <4d028748$0$1621$742ec2ed@news.sonic.net> Message-ID: <499F3F3D16A34734B5D195F91EB58520@teddy> From: "John Nagle" > On 12/10/2010 2:31 AM, kolo 32 wrote: >> Hi, all, >> >> Python critique from strchr.com: >> >> http://www.strchr.com/python_critique > > I have criticisms of Python, but those aren't them. > > Probably the biggest practical problem with CPython is > that C modules have to be closely matched to the version of > CPython. There's no well-defined API that doesn't change. > This make life easier for Guido and tough on everybody else. > That's the real cause of Python's "version hell". > > On the scope front, given the lack of declarations, Python > has done reasonably well. Scopes in Python aren't as narrow > as one might like, but this isn't a major headache. How narrow are the scopes in Python? Is each block (each level of indentation) a scope? If it is, then I think it is very enough because the other cases can be detected easier or it might not appear at all in a well-written program. If it is not, then yes, it is a problem. Can you please tell me how to write the following program in Python? my $n = 1; { my $n = 2; print "$n\n"; } print "$n\n"; If this program if ran in Perl, it prints: 2 1 I have tried to write it, but I don't know how I can create that block because it tells that there is an unexpected indent. Thanks. Octavian From sridharr at activestate.com Fri Dec 10 17:47:50 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Fri, 10 Dec 2010 14:47:50 -0800 Subject: ANN: ActivePython 3.1.3.5 is now available Message-ID: ActiveState is pleased to announce ActivePython 3.1.3.5, a complete, ready-to-install binary distribution of Python 3.1. http://www.activestate.com/activepython/downloads What's New in ActivePython-3.1.3.5 ================================== *Release date: 6-Dec-2010* New Features & Upgrades ----------------------- - Upgrade to Python 3.1.3 (`release notes `__) - Upgrade to Tcl/Tk 8.5.9 (`changes `_) - Security upgrade to openssl-0.9.8q - [MacOSX] Tkinter now requires ActiveTcl 8.5 64-bit (not Apple's Tcl/Tk 8.5 on OSX) - Upgrade to PyPM 1.2.6; noteworthy changes: - New command 'pypm log' to view log entries for last operation - Upgraded the following packages: - SQLAlchemy-0.6.5 - virtualenv5-1.3.4.5 Noteworthy Changes & Bug Fixes ------------------------------ - [MacOSX] Include missing architecture binaries - Bug #88876 - PyPM bug fixes: - depgraph: Fix a bug with missing extra in install_requires - Bug #88825 - depgraph: Fix a bug with double-marking a package for upgrade - Bug #88664: handle cyclic dependencies in the depgraph algorithm - Ignore comments (starting with #) in the requirements file - Fix: ignore empty lines in requirements.txt - Bug #88882: Fix pickle incompatability (sqlite) on Python 3.x What is ActivePython? ===================== ActivePython is ActiveState's binary distribution of Python. Builds for Windows, Mac OS X, Linux are made freely available. Solaris, HP-UX and AIX builds, and access to older versions are available in ActivePython Business, Enterprise and OEM editions: http://www.activestate.com/python ActivePython includes the Python core and the many core extensions: zlib and bzip2 for data compression, the Berkeley DB (bsddb) and SQLite (sqlite3) database libraries, OpenSSL bindings for HTTPS support, the Tix GUI widgets for Tkinter, ElementTree for XML processing, ctypes (on supported platforms) for low-level library access, and others. The Windows distribution ships with PyWin32 -- a suite of Windows tools developed by Mark Hammond, including bindings to the Win32 API and Windows COM. ActivePython 2.6, 2.7 and 3.1 also include a binary package manager for Python (PyPM) that can be used to install packages much easily. For example: C:\>pypm install mysql-python [...] C:\>python >>> import MySQLdb >>> See this page for full details: http://docs.activestate.com/activepython/3.1/whatsincluded.html As well, ActivePython ships with a wealth of documentation for both new and experienced Python programmers. In addition to the core Python docs, ActivePython includes the "What's New in Python" series, "Dive into Python", the Python FAQs & HOWTOs, and the Python Enhancement Proposals (PEPs). An online version of the docs can be found here: http://docs.activestate.com/activepython/3.1/ We would welcome any and all feedback to: activepython-feedback at activestate.com Please file bugs against ActivePython at: http://bugs.activestate.com/enter_bug.cgi?product=ActivePython Supported Platforms =================== ActivePython is available for the following platforms: - Windows (x86 and x64) - Mac OS X (x86 and x86_64; 10.5+) - Linux (x86 and x86_64) - Solaris/SPARC (32-bit and 64-bit) (Business, Enterprise or OEM edition only) - Solaris/x86 (32-bit) (Business, Enterprise or OEM edition only) - HP-UX/PA-RISC (32-bit) (Business, Enterprise or OEM edition only) - HP-UX/IA-64 (32-bit and 64-bit) (Enterprise or OEM edition only) - AIX/PowerPC (32-bit and 64-bit) (Business, Enterprise or OEM edition only) More information about the Business Edition can be found here: http://www.activestate.com/business-edition Custom builds are available in the Enterprise Edition: http://www.activestate.com/enterprise-edition Thanks, and enjoy! The Python Team -- Sridhar Ratnakumar Python Developer ActiveState, The Dynamic Language Experts sridharr at activestate.com http://www.activestate.com Get insights on Open Source and Dynamic Languages at www.activestate.com/blog From solipsis at pitrou.net Fri Dec 10 18:09:33 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Sat, 11 Dec 2010 00:09:33 +0100 Subject: Python critique References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> <4d028748$0$1621$742ec2ed@news.sonic.net> Message-ID: <20101211000933.43833327@pitrou.net> On Fri, 10 Dec 2010 12:02:21 -0800 John Nagle wrote: > > Probably the biggest practical problem with CPython is > that C modules have to be closely matched to the version of > CPython. There's no well-defined API that doesn't change. Please stop spreading FUD: http://docs.python.org/c-api/index.html Thank you Antoine. From benjamin.kaplan at case.edu Fri Dec 10 18:13:48 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 10 Dec 2010 18:13:48 -0500 Subject: Python critique In-Reply-To: <499F3F3D16A34734B5D195F91EB58520@teddy> References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> <4d028748$0$1621$742ec2ed@news.sonic.net> <499F3F3D16A34734B5D195F91EB58520@teddy> Message-ID: On Fri, Dec 10, 2010 at 5:46 PM, Octavian Rasnita wrote: > From: "John Nagle" >> On 12/10/2010 2:31 AM, kolo 32 wrote: >>> Hi, all, >>> >>> Python critique from strchr.com: >>> >>> http://www.strchr.com/python_critique >> >> ? ?I have criticisms of Python, but those aren't them. >> >> ? ?Probably the biggest practical problem with CPython is >> that C modules have to be closely matched to the version of >> CPython. ?There's no well-defined API that doesn't change. >> This make life easier for Guido and tough on everybody else. >> That's the real cause of Python's "version hell". >> >> ? ?On the scope front, given the lack of declarations, Python >> has done reasonably well. ?Scopes in Python aren't as narrow >> as one might like, but this isn't a major headache. > > How narrow are the scopes in Python? > Is each block (each level of indentation) a scope? > If it is, then I think it is very enough because the other cases can be detected easier or it might not appear at all in a well-written program. > If it is not, then yes, it is a problem. > > Can you please tell me how to write the following program in Python? > > my $n = 1; > > { > ?my $n = 2; > ?print "$n\n"; > } > > print "$n\n"; > > If this program if ran in Perl, it prints: > 2 > 1 > > I have tried to write it, but I don't know how I can create that block because it tells that there is an unexpected indent. > > Thanks. > > Octavian The only scopes Python has are module and function. Python doesn't have declarations like Perl (or most other languages), so there's no way to specify that you want a different variable within the block. From steve+comp.lang.python at pearwood.info Fri Dec 10 18:15:07 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Dec 2010 23:15:07 GMT Subject: Python critique References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> <4d028748$0$1621$742ec2ed@news.sonic.net> Message-ID: <4d02b47b$0$30000$c3e8da3$5496439d@news.astraweb.com> On Sat, 11 Dec 2010 00:46:41 +0200, Octavian Rasnita wrote: > How narrow are the scopes in Python? > Is each block (each level of indentation) a scope? Thankfully, no. > If it is, then I > think it is very enough because the other cases can be detected easier > or it might not appear at all in a well-written program. I don't understand what this means. > If it is not, then yes, it is a problem. Why is it a problem? > Can you please tell me how to write the following program in Python? > > my $n = 1; > > { > my $n = 2; > print "$n\n"; > } > > print "$n\n"; > > If this program if ran in Perl, it prints: > 2 > 1 Lots of ways. Here's one: n = 1 class Scope: n = 2 print n print n Here's another: n = 1 print (lambda n=2: n)() print n Here's a third: n = 1 def scope(): n = 2 print n scope() print n Here's a fourth: import sys n = 1 (sys.stdout.write("%d\n" % n) for n in (2,)).next() print n In Python 3, this can be written more simply: n = 1 [print(n) for n in (2,)] print n > I have tried to write it, but I don't know how I can create that block > because it tells that there is an unexpected indent. Functions, closures, classes and modules are scopes in Python. If you want a new scope, create one of those. -- Steven From stefan_ml at behnel.de Fri Dec 10 18:18:27 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 11 Dec 2010 00:18:27 +0100 Subject: Python critique In-Reply-To: <4d028748$0$1621$742ec2ed@news.sonic.net> References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> <4d028748$0$1621$742ec2ed@news.sonic.net> Message-ID: John Nagle, 10.12.2010 21:02: > Probably the biggest practical problem with CPython is > that C modules have to be closely matched to the version of > CPython. There's no well-defined API that doesn't change. Well, there are no huge differences between CPython versions (apart from the Py_ssize_t change back in 2.5), and porting isn't as hard as you seem to suggest here. > This make life easier for Guido and tough on everybody else. > That's the real cause of Python's "version hell". If you write your code in Cython instead of C, it's a lot easier to keep it portable across CPython versions (and C compilers). It's also a lot easier to write it in the first place. Note also that Py3.2 introduces a stable ABI for extension modules. This implies a stable API as well. Stefan From stefan_ml at behnel.de Fri Dec 10 18:25:47 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 11 Dec 2010 00:25:47 +0100 Subject: Python critique In-Reply-To: References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> <4d028748$0$1621$742ec2ed@news.sonic.net> <499F3F3D16A34734B5D195F91EB58520@teddy> Message-ID: Benjamin Kaplan, 11.12.2010 00:13: > On Fri, Dec 10, 2010 at 5:46 PM, Octavian Rasnita wrote: >> How narrow are the scopes in Python? >> Is each block (each level of indentation) a scope? >> If it is, then I think it is very enough because the other cases can be detected easier or it might not appear at all in a well-written program. >> If it is not, then yes, it is a problem. Why would it? >> Can you please tell me how to write the following program in Python? >> >> my $n = 1; >> >> { >> my $n = 2; >> print "$n\n"; >> } >> >> print "$n\n"; >> >> If this program if ran in Perl, it prints: >> 2 >> 1 >> >> I have tried to write it, but I don't know how I can create that block because it tells that there is an unexpected indent. > > The only scopes Python has are module and function. Python doesn't > have declarations like Perl (or most other languages), so there's no > way to specify that you want a different variable within the block. Yep, keeps you from writing bad style code like the above. Stefan From newswombat at gmail.com Fri Dec 10 18:32:30 2010 From: newswombat at gmail.com (News Wombat) Date: Fri, 10 Dec 2010 15:32:30 -0800 (PST) Subject: ctypes question Message-ID: <2abdd9b3-66ec-4125-a5f8-41315008cccc@l17g2000yqe.googlegroups.com> Hi everyone, I've been experimenting with the ctypes module and think it's great. I'm hitting a few snags though with seg faults. I attached two links that holds the code. The line i'm having problems with is this, sn=clibsmi.smiGetNextNode(pointer(sno),SMI_NODEKIND_ANY) It will work one time, and if I call it again with the result of the previous, even though the result (a c struct) looks ok, it will segfault. I think it's a problem with pointers or maybe the function in the c library trying to change a string that python won't let it change. I'm stuck, any tips would be appreciated. Thanks, and Merry Christmas! constants.py: http://pastebin.com/HvngjzZN libsmi.py: http://pastebin.com/19C9kYEa From nagle at animats.com Fri Dec 10 18:51:19 2010 From: nagle at animats.com (John Nagle) Date: Fri, 10 Dec 2010 15:51:19 -0800 Subject: Python critique In-Reply-To: References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> <4d028748$0$1621$742ec2ed@news.sonic.net> <499F3F3D16A34734B5D195F91EB58520@teddy> Message-ID: <4d02bcf2$0$1624$742ec2ed@news.sonic.net> On 12/10/2010 3:25 PM, Stefan Behnel wrote: > Benjamin Kaplan, 11.12.2010 00:13: >> On Fri, Dec 10, 2010 at 5:46 PM, Octavian Rasnita wrote: >> The only scopes Python has are module and function. There's more. Both a lambda, and in Python 3.x, list comprehensions, introduce a new scope. John Nagle From drsalists at gmail.com Fri Dec 10 19:37:29 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 10 Dec 2010 16:37:29 -0800 Subject: Python critique In-Reply-To: <4d02bcf2$0$1624$742ec2ed@news.sonic.net> References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> <4d028748$0$1621$742ec2ed@news.sonic.net> <499F3F3D16A34734B5D195F91EB58520@teddy> <4d02bcf2$0$1624$742ec2ed@news.sonic.net> Message-ID: On Fri, Dec 10, 2010 at 3:51 PM, John Nagle wrote: > On 12/10/2010 3:25 PM, Stefan Behnel wrote: >> >> Benjamin Kaplan, 11.12.2010 00:13: >>> >>> On Fri, Dec 10, 2010 at 5:46 PM, Octavian Rasnita wrote: > >>> The only scopes Python has are module and function. > > ? There's more. ?Both a lambda, and in Python 3.x, > list comprehensions, introduce a new scope. > > ? ? ? ? ? ? ? ? ? ? ? ?John Nagle > -- > http://mail.python.org/mailman/listinfo/python-list > And classes and methods. Also, I like to draw a distinction between "code scopes" and "data scopes". We've been talking about data scopes. Code scopes are pretty much indents and dedents in Python - they define what code is operated on by something code-flow-related. To the OP: Python doesn't need a "my" or "local" - it has more rational defaults. From stefan_ml at behnel.de Fri Dec 10 19:49:44 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 11 Dec 2010 01:49:44 +0100 Subject: Python critique In-Reply-To: <4d02bcf2$0$1624$742ec2ed@news.sonic.net> References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> <4d028748$0$1621$742ec2ed@news.sonic.net> <499F3F3D16A34734B5D195F91EB58520@teddy> <4d02bcf2$0$1624$742ec2ed@news.sonic.net> Message-ID: John Nagle, 11.12.2010 00:51: > On 12/10/2010 3:25 PM, Stefan Behnel wrote: >> Benjamin Kaplan, 11.12.2010 00:13: >>> On Fri, Dec 10, 2010 at 5:46 PM, Octavian Rasnita wrote: > >>> The only scopes Python has are module and function. > > There's more. Both a lambda, and in Python 3.x, > list comprehensions, introduce a new scope. To be a little more precise: in Py3, list comprehensions use the same kind of scope that generator expressions, set comprehensions and dict comprehensions always had. Stefan From __peter__ at web.de Fri Dec 10 19:58:10 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 11 Dec 2010 01:58:10 +0100 Subject: run a function in another processor in python References: <4D00B416.5090509@sequans.com> Message-ID: geremy condra wrote: > On Fri, Dec 10, 2010 at 4:42 AM, Astan Chee wrote: >> On Fri, Dec 10, 2010 at 1:37 AM, Peter Otten <__peter__ at web.de> wrote: >>> >>> I can't replicate the crash. However, your problem looks like there is a >>> ready-to-use solution: >>> >>> >>> http://docs.python.org/library/multiprocessing.html#using-a-pool-of- workers >>> >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >> >> >> Pool.map doesn't seem to be able to support multiple argument functions >> which is what I'm trying to do here. Any other suggestions? >> Thanks again > > 1. Post the real code you're using, and > 2. Put the arguments you want in a tuple and pass that. As an example, > let's say I have the following function: > > def my_func(x, y, z): > return x + y * z > > you could rewrite this as: > > def my_func(*args): > return args[0] + args[1] * args[2] > > > Here's a worked-out example: > > #! /usr/bin/env python3 > > import multiprocessing > > def my_func(x, y, z): > return x + y * z > > def my_func_wrapper(t): > return my_func(*t) > > # assume we can get an iterable over each argument > xs = [1, 2, 3, 4] > ys = [5, 6, 7, 8] > zs = [9, 1, 2, 3] > > # set up the pool to match the number of CPUs > num_processes = multiprocessing.cpu_count() > pool = multiprocessing.Pool(num_processes) > > #will call my_func(1, 5, 9), my_func(2, 6, 1), etc. > results = pool.map(my_func_wrapper, zip(xs, ys, zs)) > print(results) > > > Interesting factoid: you can't seem to use lambda or a decorator to do > this, which would have been my first instinct. Pickle apparently > chokes, although marshall wouldn't. You basically have to ensure that the resulting function is found under its __name__ in the global namespace of its __module__. This can be done with functools.wraps(): #! /usr/bin/env python3 import multiprocessing import functools def starcall(f): @functools.wraps(f) def g(args): return f(*args) return g @starcall def my_func(x, y, z): return x + y * z xs = [1, 2, 3, 4] ys = [5, 6, 7, 8] zs = [9, 1, 2, 3] num_processes = multiprocessing.cpu_count() pool = multiprocessing.Pool(num_processes) results = pool.map(my_func, zip(xs, ys, zs)) print(results) From bavishi.darshak at gmail.com Sat Dec 11 01:02:01 2010 From: bavishi.darshak at gmail.com (Darshak Bavishi) Date: Sat, 11 Dec 2010 11:32:01 +0530 Subject: stuck with Pexpect script need help!! Message-ID: Hi Experts, got ready made code for ssh to unix using python host machine is windows now when i run this its gives following error : * Traceback (most recent call last): File "C:\Python26\pexpect-2.1\pexpect-2.1\pxssh.py", line 1, in from pexpect import * File "C:\Python26\pexpect-2.1\pexpect-2.1\pexpect.py", line 83, in Pexpect is intended for UNIX-like operating systems.""") ImportError: No module named resource A critical module was not found. Probably this operating system does not support it. Pexpect is intended for UNIX-like operating systems. >>> ================================ RESTART ================================ >>> Traceback (most recent call last): File "C:\Python26\ssh_session.py", line 7, in from pexpect import * ImportError: No module named pexpect >>> * Can we use pexpect from windows host machine ?! -- BR Darshak Bavishi -------------- next part -------------- An HTML attachment was scrubbed... URL: From metolone+gmane at gmail.com Sat Dec 11 01:23:23 2010 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Fri, 10 Dec 2010 22:23:23 -0800 Subject: ctypes question References: <2abdd9b3-66ec-4125-a5f8-41315008cccc@l17g2000yqe.googlegroups.com> Message-ID: "News Wombat" wrote in message news:2abdd9b3-66ec-4125-a5f8-41315008cccc at l17g2000yqe.googlegroups.com... > Hi everyone, > > I've been experimenting with the ctypes module and think it's great. > I'm hitting a few snags though with seg faults. I attached two links > that holds the code. The line i'm having problems with is this, > > sn=clibsmi.smiGetNextNode(pointer(sno),SMI_NODEKIND_ANY) > > It will work one time, and if I call it again with the result of the > previous, even though the result (a c struct) looks ok, it will > segfault. I think it's a problem with pointers or maybe the function > in the c library trying to change a string that python won't let it > change. I'm stuck, any tips would be appreciated. Thanks, and Merry > Christmas! > > constants.py: http://pastebin.com/HvngjzZN > libsmi.py: http://pastebin.com/19C9kYEa Well, I can't run your code, but I think you should pass the original "sn" pointer from smiGetNode() and not a pointer(sno). The values are not the same and the library probably relies on passing the original pointer back into smiGetNextNode. sn.contents returns a new SmiNode object so its pointer will be different. -Mark From astan.chee at gmail.com Sat Dec 11 01:35:38 2010 From: astan.chee at gmail.com (Astan Chee) Date: Sat, 11 Dec 2010 17:35:38 +1100 Subject: run a function in another processor in python In-Reply-To: References: <4D00B416.5090509@sequans.com> Message-ID: Sorry about that, here is a summary of my complete code. I haven't cleaned it up much or anything, but this is what it does: import time import multiprocessing test_constx =0 test_consty =0 def functionTester(x): global test_constx global test_consty print "constx " + str(test_constx) print "consty " + str(test_consty) return (test_constx*x[0]-x[1]+test_consty*x[0]+x[2]) def functionTesterMain(constx,consty): global test_constx global test_consty test_constx = constx test_consty = consty num_args = [(61,12,1),(61,12,2),(61,12,3),(61,11,4),(61,12,4),(62,33,4),(7,12,4),(16,19,4),(35,36,4),(37,38,3),(55,56,3),(57,63,3)] num_processes = multiprocessing.cpu_count() pool = multiprocessing.Pool(num_processes) rs = [] start = time.time() rs = pool.map(functionTester,num_args) end = time.time() elapsed= end - start min = elapsed/60 print "Took", elapsed, "seconds to run, which is the same as", min, "minutes" pos = 0 high = 0 n = None for r in rs: if r > high: n = num_args[pos] high = r pos+=1 print "high " + str(high) print "n " + str(n) return high,n if __name__ == '__main__': for i in range(1,4): a,b = functionTesterMain(i,7) print "-----------" print "a " + str(a) print "b " + str(a) Which doesn't seem to work because the functionTester() needs to be simpler and not use global variables. I'm using global variables because I'm also trying to pass a few other variables and I tried using a class but that just gave me a unpickleable error. I tried using zip but I'm confused with how I can get to pass the data. I know I can probably combine the data into tuples but that means that there is alot of data duplication, especially if the constx and consty are large dictionaries (or even custom objects), which might happen later. So it seems that map doesn't quite like functions like these. Anyway, I'll try and see if threads or something can substitute. I'd appriciate any help. Thanks On Sat, Dec 11, 2010 at 9:04 AM, geremy condra wrote: > On Fri, Dec 10, 2010 at 4:42 AM, Astan Chee wrote: > > On Fri, Dec 10, 2010 at 1:37 AM, Peter Otten <__peter__ at web.de> wrote: > >> > >> I can't replicate the crash. However, your problem looks like there is a > >> ready-to-use solution: > >> > >> > >> > http://docs.python.org/library/multiprocessing.html#using-a-pool-of-workers > >> > >> -- > >> http://mail.python.org/mailman/listinfo/python-list > > > > > > Pool.map doesn't seem to be able to support multiple argument functions > > which is what I'm trying to do here. Any other suggestions? > > Thanks again > > 1. Post the real code you're using, and > 2. Put the arguments you want in a tuple and pass that. As an example, > let's say I have the following function: > > def my_func(x, y, z): > return x + y * z > > you could rewrite this as: > > def my_func(*args): > return args[0] + args[1] * args[2] > > > Here's a worked-out example: > > #! /usr/bin/env python3 > > import multiprocessing > > def my_func(x, y, z): > return x + y * z > > def my_func_wrapper(t): > return my_func(*t) > > # assume we can get an iterable over each argument > xs = [1, 2, 3, 4] > ys = [5, 6, 7, 8] > zs = [9, 1, 2, 3] > > # set up the pool to match the number of CPUs > num_processes = multiprocessing.cpu_count() > pool = multiprocessing.Pool(num_processes) > > #will call my_func(1, 5, 9), my_func(2, 6, 1), etc. > results = pool.map(my_func_wrapper, zip(xs, ys, zs)) > print(results) > > > Interesting factoid: you can't seem to use lambda or a decorator to do > this, which would have been my first instinct. Pickle apparently > chokes, although marshall wouldn't. > > Geremy Condra > -------------- next part -------------- An HTML attachment was scrubbed... URL: From orasnita at gmail.com Sat Dec 11 04:17:53 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Sat, 11 Dec 2010 11:17:53 +0200 Subject: Python critique References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com><4d028748$0$1621$742ec2ed@news.sonic.net> <4d02b47b$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52430F724D9B40DFB856FCDD172C28C8@teddy> From: "Steven D'Aprano" ... >> Can you please tell me how to write the following program in Python? >> >> my $n = 1; >> >> { >> my $n = 2; >> print "$n\n"; >> } >> >> print "$n\n"; >> >> If this program if ran in Perl, it prints: >> 2 >> 1 > > Lots of ways. Here's one: > > > n = 1 > > class Scope: > n = 2 > print n > > print n > > > > Here's another: > > n = 1 > print (lambda n=2: n)() > print n > > > > Here's a third: > > n = 1 > > def scope(): > n = 2 > print n > > scope() > print n > > > Here's a fourth: > > import sys > n = 1 > (sys.stdout.write("%d\n" % n) for n in (2,)).next() > print n > > > In Python 3, this can be written more simply: > > n = 1 > [print(n) for n in (2,)] > print n > > > >> I have tried to write it, but I don't know how I can create that block >> because it tells that there is an unexpected indent. > > Functions, closures, classes and modules are scopes in Python. If you > want a new scope, create one of those. > > > > -- > Steven Hi Steven, Thank you for your message. It is very helpful for me. I don't fully understand the syntax of all these variants yet, but I can see that there are more scopes in Python than I thought, and this is very good. Octavian From __peter__ at web.de Sat Dec 11 05:33:34 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 11 Dec 2010 11:33:34 +0100 Subject: run a function in another processor in python References: <4D00B416.5090509@sequans.com> Message-ID: Astan Chee wrote: > Sorry about that, here is a summary of my complete code. I haven't cleaned > it up much or anything, but this is what it does: > > import time > import multiprocessing > > test_constx =0 > test_consty =0 > > def functionTester(x): > global test_constx You don't need to declare a variable as global unless you want to rebind (assign to) it. > global test_consty > print "constx " + str(test_constx) > print "consty " + str(test_consty) > return (test_constx*x[0]-x[1]+test_consty*x[0]+x[2]) > > def functionTesterMain(constx,consty): > global test_constx > global test_consty > test_constx = constx > test_consty = consty > num_args = > [(61,12,1),(61,12,2),(61,12,3),(61,11,4),(61,12,4),(62,33,4),(7,12,4), (16,19,4),(35,36,4),(37,38,3),(55,56,3),(57,63,3)] > num_processes = multiprocessing.cpu_count() > pool = multiprocessing.Pool(num_processes) I think you need to create the pool outside the function; in the current configuration you get three not one Pool instance. > rs = [] > start = time.time() > rs = pool.map(functionTester,num_args) > end = time.time() > elapsed= end - start > min = elapsed/60 > print "Took", elapsed, "seconds to run, which is the same as", min, > "minutes" > pos = 0 > high = 0 > n = None > for r in rs: > if r > high: > n = num_args[pos] > high = r > pos+=1 > print "high " + str(high) > print "n " + str(n) > > return high,n > > if __name__ == '__main__': > for i in range(1,4): > a,b = functionTesterMain(i,7) > print "-----------" > print "a " + str(a) > print "b " + str(a) > > > Which doesn't seem to work because the functionTester() needs to be > simpler and not use global variables. > I'm using global variables because I'm also trying to pass a few other > variables and I tried using a class but that just gave me a unpickleable > error. I tried using zip but I'm confused with how I can get to pass the > data. A simple approach would be to pass an index into a list const_data = zip(range(1, 4), [7]*3) > I know I can probably combine the data into tuples but that means that > there is alot of data duplication, especially if the constx and consty are > large dictionaries (or even custom objects), which might happen later. > So it seems that map doesn't quite like functions like these. Anyway, I'll > try and see if threads or something can substitute. I'd appriciate any help. Thanks Your code, slightly modified and cleaned up (yes, four-space indent improves readability): import time import multiprocessing const_data = zip(range(1, 4), [7]*3) num_args = [(61, 12, 1), (61, 12, 2), (61, 12, 3), (61, 11, 4), (61, 12, 4), (62, 33, 4), (7, 12, 4), (16, 19, 4), (35, 36, 4), (37, 38, 3), (55, 56, 3), (57, 63, 3)] def functionTester(args): i, x, y, z = args constx, consty = const_data[i] print "constx", constx print "consty", consty return constx*x - y + consty*x + z def functionTesterMain(pool, index): start = time.time() rs = pool.map(functionTester, (((index, ) + x) for x in num_args)) end = time.time() elapsed = end - start min = elapsed/60 print "Took", elapsed, print "seconds to run, which is the same as", min, "minutes" return max(zip(rs, num_args)) if __name__ == '__main__': num_processes = multiprocessing.cpu_count() pool = multiprocessing.Pool(num_processes) for i, _ in enumerate(const_data): a, b = functionTesterMain(pool, i) print "-----------" print "a", a print "b", b From bavishi.darshak at gmail.com Sat Dec 11 06:20:35 2010 From: bavishi.darshak at gmail.com (Darshak Bavishi) Date: Sat, 11 Dec 2010 16:50:35 +0530 Subject: how to read o/p of telenet (python) ?! Message-ID: hi experts , i have code to telnet remote machine (unix) i am using port 5400 to telnet but o/p is not in visible format when i run random commands or run when i give as read_some() it displays some lines but in case of read_all() it gets hang !! In actual i want to get some string from o/p and process pls help [code] import getpass import sys import telnetlib import time HOST = "hostname" #user = raw_input("Enter your remote account: ") #password = getpass.getpass() user = "hostname" password = "ABC" tn = telnetlib.Telnet(HOST , 5400) print "1" print "2" tn.write(user + "\n") print "3" if password: tn.read_until("Password: ") tn.write(password + "\n") print "4" tn.write("set alarm = off" + "\n") tn.write("set event = off" + "\n") print "5" tn.write("Cd /Office-Parameters/" + "\n") print "6" tn.write("\n") tn.write("\n") tn.write("vlrsubquery msisdn=*******" + "\n") tn.write("\n") print tn.read_all() tn.write("exit" + "\n") tn.close() -- BR Darshak Bavishi -------------- next part -------------- An HTML attachment was scrubbed... URL: From lie.1296 at gmail.com Sat Dec 11 06:46:16 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 11 Dec 2010 22:46:16 +1100 Subject: Python critique In-Reply-To: References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> <4d028748$0$1621$742ec2ed@news.sonic.net> <499F3F3D16A34734B5D195F91EB58520@teddy> <4d02bcf2$0$1624$742ec2ed@news.sonic.net> Message-ID: <4d036383$1@dnews.tpgi.com.au> On 12/11/10 11:37, Dan Stromberg wrote: > On Fri, Dec 10, 2010 at 3:51 PM, John Nagle wrote: >> On 12/10/2010 3:25 PM, Stefan Behnel wrote: >>> Benjamin Kaplan, 11.12.2010 00:13: >>>> On Fri, Dec 10, 2010 at 5:46 PM, Octavian Rasnita wrote: >>>> The only scopes Python has are module and function. >> >> There's more. Both a lambda, and in Python 3.x, >> list comprehensions, introduce a new scope. > > And classes and methods. Also, class scope and instance scope, though similar, are distinct scopes. Python also have the hidden interpreter-level scope (the __builtins__). From orasnita at gmail.com Sat Dec 11 07:43:33 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Sat, 11 Dec 2010 14:43:33 +0200 Subject: Python distribution recommendation? Message-ID: Hi, Is there a "recommended" Python distribution for Windows XP? I know about the one that can be downloaded from python.org (which I am using for the moment) and the one offered by ActiveState but I don't know which one is better for a beginner nor if there are other distributions available. I am especially interested in creating MS Windows apps with Python. Thanks. Octavian From katie at coderstack.co.uk Sat Dec 11 08:08:53 2010 From: katie at coderstack.co.uk (Katie T) Date: Sat, 11 Dec 2010 13:08:53 +0000 Subject: Python distribution recommendation? In-Reply-To: References: Message-ID: On Sat, Dec 11, 2010 at 12:43 PM, Octavian Rasnita wrote: > Hi, > > Is there a "recommended" Python distribution for Windows XP? Either will work, although the python.org one is the more popular and is likely the one used by most tutorials and beginners guides. The ActiveState one bundles PyQT if you want to build apps with GUIs using QT (although it's fairly trivial to install with the regular Python as well). Katie -- CoderStack http://www.coderstack.co.uk The Software Developer Job Board From lie.1296 at gmail.com Sat Dec 11 08:59:46 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 12 Dec 2010 00:59:46 +1100 Subject: Python distribution recommendation? In-Reply-To: References: Message-ID: <4d0382cd$1@dnews.tpgi.com.au> On 12/11/10 23:43, Octavian Rasnita wrote: > Hi, > > Is there a "recommended" Python distribution for Windows XP? > > I know about the one that can be downloaded from python.org (which I am using for the moment) and the one offered by ActiveState but I don't know which one is better for a beginner nor if there are other distributions available. > > I am especially interested in creating MS Windows apps with Python. > ActiveState comes with more third party libraries, if you're developing python and do not want to install those libraries yourself, they're the way to go to. However, if you only need to use standard libraries, or want to target the broadest possible platforms with very little dependencies, then you should use python.org's version. From godson.g at gmail.com Sat Dec 11 09:02:21 2010 From: godson.g at gmail.com (Godson Gera) Date: Sat, 11 Dec 2010 19:32:21 +0530 Subject: Python distribution recommendation? In-Reply-To: References: Message-ID: On Sat, Dec 11, 2010 at 6:13 PM, Octavian Rasnita wrote: > > > I am especially interested in creating MS Windows apps with Python. > If you want to access win32api and do some COM programming then ActiveState comes bundled with pywin32. Where in vanilla python distro you have to install those packages separately by downloading them. ActiveState is the same python with additional batteries included. -- Python Consultant India -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Sat Dec 11 09:24:54 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 11 Dec 2010 09:24:54 -0500 Subject: instance has no __call__ method In-Reply-To: References: Message-ID: <4D0389B6.3020405@holdenweb.com> On 12/10/2010 5:20 AM, frank cui wrote: > Hi all, > > I'm a novice learner of python and get caught in the following trouble > and hope experienced users can help me solve it:) > > Code: > ----------------------------------------------------------------------- > $ cat Muffle_ZeroDivision.py > #!/usr/bin/env python > > class MuffledCalculator: > muffled = False > def clac(self,expr): > try: > return eval(expr) > except: > if self.muffled: > print 'Division by zero is illegal' > else: > raise > -------------------------------------------------------------------------- > > $ python > Python 2.7 (r27:82500, Sep 16 2010, 18:03:06) > [GCC 4.5.1 20100907 (Red Hat 4.5.1-3)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import Muffle_ZeroDivision >>>> calc = Muffle_ZeroDivision.MuffledCalculator() >>>> calc = ('10/2') >>>> calc = Muffle_ZeroDivision.MuffledCalculator() >>>> calc('10/2') > Traceback (most recent call last): > File "", line 1, in > AttributeError: MuffledCalculator instance has no __call__ method > > ---------------------------------------------------------------------------- > > There is an AttributeError that this instance doesn't have the __call__ > method, so how to add this kind of method to my instance? > > Thanks a lot in advance. > > Regards > Frank.Cui > Try renaming your .calc() method to .__call__(). That way the method will be called when you perform a function call on an instance. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sat Dec 11 09:24:54 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 11 Dec 2010 09:24:54 -0500 Subject: instance has no __call__ method In-Reply-To: References: Message-ID: <4D0389B6.3020405@holdenweb.com> On 12/10/2010 5:20 AM, frank cui wrote: > Hi all, > > I'm a novice learner of python and get caught in the following trouble > and hope experienced users can help me solve it:) > > Code: > ----------------------------------------------------------------------- > $ cat Muffle_ZeroDivision.py > #!/usr/bin/env python > > class MuffledCalculator: > muffled = False > def clac(self,expr): > try: > return eval(expr) > except: > if self.muffled: > print 'Division by zero is illegal' > else: > raise > -------------------------------------------------------------------------- > > $ python > Python 2.7 (r27:82500, Sep 16 2010, 18:03:06) > [GCC 4.5.1 20100907 (Red Hat 4.5.1-3)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import Muffle_ZeroDivision >>>> calc = Muffle_ZeroDivision.MuffledCalculator() >>>> calc = ('10/2') >>>> calc = Muffle_ZeroDivision.MuffledCalculator() >>>> calc('10/2') > Traceback (most recent call last): > File "", line 1, in > AttributeError: MuffledCalculator instance has no __call__ method > > ---------------------------------------------------------------------------- > > There is an AttributeError that this instance doesn't have the __call__ > method, so how to add this kind of method to my instance? > > Thanks a lot in advance. > > Regards > Frank.Cui > Try renaming your .calc() method to .__call__(). That way the method will be called when you perform a function call on an instance. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From orasnita at gmail.com Sat Dec 11 09:31:04 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Sat, 11 Dec 2010 16:31:04 +0200 Subject: Python distribution recommendation? References: Message-ID: <16E90EF945B946F39CF1EA5836F024DA@teddy> Ok, thank you all for your recommendations. I think I will install ActivePython because it seems that it offers more features for Windows programming than the other distro (by default, which is important for a beginner). I will use WxPython and not other GUIS like QT, Tk or GTK because they are not accessible for screen readers, so I will also need to install WxPython if ActiveState's Python doesn't include it. Octavian ----- Original Message ----- From: "Godson Gera" To: "Octavian Rasnita" Cc: Sent: Saturday, December 11, 2010 4:02 PM Subject: Re: Python distribution recommendation? > On Sat, Dec 11, 2010 at 6:13 PM, Octavian Rasnita wrote: > >> >> >> I am especially interested in creating MS Windows apps with Python. >> > > If you want to access win32api and do some COM programming then ActiveState > comes bundled with pywin32. Where in vanilla python distro you have to > install those packages separately by downloading them. ActiveState is the > same python with additional batteries included. > > -- > Python Consultant India > From steve+comp.lang.python at pearwood.info Sat Dec 11 09:32:03 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Dec 2010 14:32:03 GMT Subject: Integrating doctest with unittest Message-ID: <4d038b63$0$30000$c3e8da3$5496439d@news.astraweb.com> I have a module with doctests, and a module that performs unit testing for it. The test module looks like this: import doctest import unittest import module_to_test # ... # many test suites # ... if __name__ == '__main__': doctest.testmod(module_to_test) unittest.main() but now I'd like to integrate the doctests with the unittests. I thought I could follow the instructions here: http://docs.python.org/py3k/library/doctest.html#unittest-api so I added a line: doc_test_suite = doctest.DocTestSuite(module=module_to_test) expecting that it would be found by unittest.main(), but it is not. I imagine this is because DocTestSuite returns a TestSuite instance, while the unittest test finder only looks for classes. I realise that I could manually run the doc_test_suite with this: unittest.TextTestRunner().run(doc_test_suite) but this leads to two test outputs: Ran 100 tests in 3.037s OK Ran 10 tests in 0.012s OK instead of combining them: Ran 110 tests in 3.049s OK Is there a way to have unittest.main() find and run doc_test_suite together with the other test suites? -- Steven From steve at holdenweb.com Sat Dec 11 09:32:39 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 11 Dec 2010 09:32:39 -0500 Subject: 64 bit memory usage In-Reply-To: References: <4d015be7$0$1670$742ec2ed@news.sonic.net> Message-ID: <4D038B87.7050601@holdenweb.com> On 12/10/2010 2:03 PM, Rob Randall wrote: > I manged to get my python app past 3GB on a smaller 64 bit machine. > On a test to check memory usage with gc disabled only an extra 6MB was > used. > The figures were 1693MB to 1687MB. > > This is great. > > Thanks again for the help. Do remember, though, that with the GC turned off you will "lose" memory if you accidentally create cyclic data structures, since they will never be reclaimed. It doesn't sound like this is an issue, but I wanted this to act as a warning to others who might come across your solution but have programmed less carefully. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sat Dec 11 09:32:39 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 11 Dec 2010 09:32:39 -0500 Subject: 64 bit memory usage In-Reply-To: References: <4d015be7$0$1670$742ec2ed@news.sonic.net> Message-ID: <4D038B87.7050601@holdenweb.com> On 12/10/2010 2:03 PM, Rob Randall wrote: > I manged to get my python app past 3GB on a smaller 64 bit machine. > On a test to check memory usage with gc disabled only an extra 6MB was > used. > The figures were 1693MB to 1687MB. > > This is great. > > Thanks again for the help. Do remember, though, that with the GC turned off you will "lose" memory if you accidentally create cyclic data structures, since they will never be reclaimed. It doesn't sound like this is an issue, but I wanted this to act as a warning to others who might come across your solution but have programmed less carefully. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From martin.kaspar at campus-24.com Sat Dec 11 11:24:26 2010 From: martin.kaspar at campus-24.com (Martin Kaspar) Date: Sat, 11 Dec 2010 08:24:26 -0800 (PST) Subject: python-parser running Beautiful Soup needs to be reviewed Message-ID: <3dcf2ff3-1b23-4dd8-a719-d1647a1a051e@o4g2000yqd.googlegroups.com> Hello commnity i am new to Python and to Beatiful Soup also! It is told to be a great tool to parse and extract content. So here i am...: I want to take the content of a -tag of a table in a html document. For example, i have this table
This is a sample text This is the second sample text
How can i use beautifulsoup to take the text "This is a sample text"? Should i make use soup.findAll('table' ,attrs={'class':'bp_ergebnis_tab_info'}) to get the whole table. See the target http://www.schulministerium.nrw.de/BP/SchuleSuchen?action=799.601437941842&SchulAdresseMapDO=142323 Well - what have we to do first: The first thing is t o find the table: i do this with Using find rather than findall returns the first item in the list (rather than returning a list of all finds - in which case we'd have to add an extra [0] to take the first element of the list): table = soup.find('table' ,attrs={'class':'bp_ergebnis_tab_info'}) Then use find again to find the first td: first_td = soup.find('td') Then we have to use renderContents() to extract the textual contents: text = first_td.renderContents() ... and the job is done (though we may also want to use strip() to remove leading and trailing spaces: trimmed_text = text.strip() This should give us: print trimmed_text This is a sample text as desired. What do you think about the code? I love to hear from you!? greetings matze From nitinpawar432 at gmail.com Sat Dec 11 11:31:09 2010 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Sat, 11 Dec 2010 11:31:09 -0500 Subject: python-parser running Beautiful Soup needs to be reviewed In-Reply-To: <3dcf2ff3-1b23-4dd8-a719-d1647a1a051e@o4g2000yqd.googlegroups.com> References: <3dcf2ff3-1b23-4dd8-a719-d1647a1a051e@o4g2000yqd.googlegroups.com> Message-ID: try using lxml ... its very useful On Sat, Dec 11, 2010 at 11:24 AM, Martin Kaspar wrote: > Hello commnity > > i am new to Python and to Beatiful Soup also! > It is told to be a great tool to parse and extract content. So here i > am...: > > I want to take the content of a -tag of a table in a html > document. For example, i have this table > > > > > > > >
> This is a sample text > > This is the second sample text >
> > How can i use beautifulsoup to take the text "This is a sample text"? > > Should i make use > soup.findAll('table' ,attrs={'class':'bp_ergebnis_tab_info'}) to get > the whole table. > > See the target > http://www.schulministerium.nrw.de/BP/SchuleSuchen?action=799.601437941842&SchulAdresseMapDO=142323 > > Well - what have we to do first: > > The first thing is t o find the table: > > i do this with Using find rather than findall returns the first item > in the list > (rather than returning a list of all finds - in which case we'd have > to add an extra [0] > to take the first element of the list): > > > table = soup.find('table' ,attrs={'class':'bp_ergebnis_tab_info'}) > > Then use find again to find the first td: > > first_td = soup.find('td') > > Then we have to use renderContents() to extract the textual contents: > > text = first_td.renderContents() > > ... and the job is done (though we may also want to use strip() to > remove leading and trailing spaces: > > trimmed_text = text.strip() > > This should give us: > > > print trimmed_text > This is a sample text > > as desired. > > > What do you think about the code? I love to hear from you!? > > greetings > matze > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From roy at panix.com Sat Dec 11 12:04:01 2010 From: roy at panix.com (Roy Smith) Date: Sat, 11 Dec 2010 12:04:01 -0500 Subject: Making os.unlink() act like "rm -f" Message-ID: I just wrote an annoying little piece of code: try: os.unlink("file") except OSError: pass The point being I want to make sure the file is gone, but am not sure if it exists currently. Essentially, I want to do what "rm -f" does in the unix shell. In fact, what I did doesn't even do that. By catching OSError, I catch "No such file or directory" (which is what I want), but I also catch lots of things I want to know about, like "Permission denied". I could do: if os.access("file", os.F_OK): os.unlink("file") but that's annoying too. What would people think about a patch to os.unlink() to add an optional second parameter which says to ignore attempts to remove non-existent files (just like "rm -f")? Then you could do: os.unlink("file", ignore=True) From lists at cheimes.de Sat Dec 11 12:25:14 2010 From: lists at cheimes.de (Christian Heimes) Date: Sat, 11 Dec 2010 18:25:14 +0100 Subject: Making os.unlink() act like "rm -f" In-Reply-To: References: Message-ID: Am 11.12.2010 18:04, schrieb Roy Smith: > if os.access("file", os.F_OK): > os.unlink("file") > > but that's annoying too. What would people think about a patch to > os.unlink() to add an optional second parameter which says to ignore > attempts to remove non-existent files (just like "rm -f")? Then you > could do: -1 os.unlink is a small wrapper around the unlink(2) function. You want to ignore the ENOENT error number and re-raise the exception for other errors: try: os.unlink("file") except OSError, e: if e.errno != errno.ENOENT: raise You may be interested in EISDIR, too. unlink() doesn't remove directories. Christian From nobody at nowhere.com Sat Dec 11 12:25:20 2010 From: nobody at nowhere.com (Nobody) Date: Sat, 11 Dec 2010 17:25:20 +0000 Subject: Making os.unlink() act like "rm -f" References: Message-ID: On Sat, 11 Dec 2010 12:04:01 -0500, Roy Smith wrote: > I just wrote an annoying little piece of code: > > try: > os.unlink("file") > except OSError: > pass > > The point being I want to make sure the file is gone, but am not sure if > it exists currently. Essentially, I want to do what "rm -f" does in the > unix shell. > > In fact, what I did doesn't even do that. By catching OSError, I catch > "No such file or directory" (which is what I want), but I also catch lots > of things I want to know about, like "Permission denied". import errno try: os.unlink("file") except OSError as e: if e.errno != errno.ENOENT: raise > I could do: > > if os.access("file", os.F_OK): > os.unlink("file") > > but that's annoying too. It also has a race condition. EAFP is the right approach here. From godson.g at gmail.com Sat Dec 11 12:31:11 2010 From: godson.g at gmail.com (Godson Gera) Date: Sat, 11 Dec 2010 23:01:11 +0530 Subject: Making os.unlink() act like "rm -f" In-Reply-To: References: Message-ID: On Sat, Dec 11, 2010 at 10:34 PM, Roy Smith wrote: > os.unlink("file", ignore=True) > -- > http://mail.python.org/mailman/listinfo/python-list > Take a look at shutil.rmtree http://docs.python.org/library/shutil.html?highlight=shutil#shutil.rmtree -- Thanks & Regards, Godson Gera Python Consultant India -------------- next part -------------- An HTML attachment was scrubbed... URL: From perry at nomail.net.invalid Sat Dec 11 12:33:15 2010 From: perry at nomail.net.invalid (Perry Johnson) Date: Sat, 11 Dec 2010 17:33:15 +0000 (UTC) Subject: Enabling the use of POSIX character classes in Python Message-ID: Python's re module does not support POSIX character classes, for example [:alpha:]. It is, of course, trivial to simulate them using character ranges when the text to be matched uses the ASCII character set. Sadly, my problem is that I need to process Unicode text. The re module has its own character classes that do support Unicode, however they are not sufficient. I would find it extremely useful if there was information on the Unicode code points that map to each of the POSIX character classes. From ian.g.kelly at gmail.com Sat Dec 11 12:44:04 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 11 Dec 2010 10:44:04 -0700 Subject: how to read o/p of telenet (python) ?! In-Reply-To: References: Message-ID: On 12/11/2010 4:20 AM, Darshak Bavishi wrote: > i have code to telnet remote machine (unix) > i am using port 5400 to telnet but o/p is not in visible format when i > run random commands or run What is "o/p"? > when i give as read_some() it displays some lines but in case of > read_all() it gets hang !! read_all() blocks until the server closes the connection. If the server is waiting for a command, then it will be blocking for a long time. Try sending the "exit" command before you call read_all(). The server should finish processing the previous command before exiting, so you will still receive all of the requested data. Cheers, Ian From martin at v.loewis.de Sat Dec 11 12:55:42 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sat, 11 Dec 2010 18:55:42 +0100 Subject: Enabling the use of POSIX character classes in Python In-Reply-To: References: Message-ID: Am 11.12.2010 18:33, schrieb Perry Johnson: > Python's re module does not support POSIX character classes, for > example [:alpha:]. It is, of course, trivial to simulate them using > character ranges when the text to be matched uses the ASCII character > set. Sadly, my problem is that I need to process Unicode text. The re > module has its own character classes that do support Unicode, however > they are not sufficient. > > I would find it extremely useful if there was information on the > Unicode code points that map to each of the POSIX character classes. By definition, this is not possible. The POSIX character classes are locale-dependent, whereas the recommendation for Unicode regular expressions is that they are not (i.e. a Unicode regex character class should refer to the same characters independent from the locale). If you want to construct locale-dependent Unicode character classes, you should use this procedure: - iterate over all byte values (0..255) - perform the relevant locale-specific tests - decode each byte into Unicode, using the locale's encoding - construct a character class out of that Unfortunately, that will work only for single-byte encodings. I'm not aware of a procedure that does that for multi-byte strings. But perhaps you didn't mean "POSIX character class" in this literal way. Regards, Martin From python at mrabarnett.plus.com Sat Dec 11 12:58:06 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 11 Dec 2010 17:58:06 +0000 Subject: Enabling the use of POSIX character classes in Python In-Reply-To: References: Message-ID: <4D03BBAE.9080106@mrabarnett.plus.com> On 11/12/2010 17:33, Perry Johnson wrote: > Python's re module does not support POSIX character classes, for > example [:alpha:]. It is, of course, trivial to simulate them using > character ranges when the text to be matched uses the ASCII character > set. Sadly, my problem is that I need to process Unicode text. The re > module has its own character classes that do support Unicode, however > they are not sufficient. > > I would find it extremely useful if there was information on the > Unicode code points that map to each of the POSIX character classes. Have a look at the new regex implementation on PyPI: http://pypi.python.org/pypi/regex From python at mrabarnett.plus.com Sat Dec 11 13:01:56 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 11 Dec 2010 18:01:56 +0000 Subject: how to read o/p of telenet (python) ?! In-Reply-To: References: Message-ID: <4D03BC94.2090402@mrabarnett.plus.com> On 11/12/2010 17:44, Ian Kelly wrote: > On 12/11/2010 4:20 AM, Darshak Bavishi wrote: >> i have code to telnet remote machine (unix) >> i am using port 5400 to telnet but o/p is not in visible format when i >> run random commands or run > > What is "o/p"? > [snip] "o/p" is an abbreviation for "output" (and "i/p" is abbreviation for "input"). From mrjean1 at gmail.com Sat Dec 11 13:59:14 2010 From: mrjean1 at gmail.com (MrJean1) Date: Sat, 11 Dec 2010 10:59:14 -0800 (PST) Subject: ctypes question References: <2abdd9b3-66ec-4125-a5f8-41315008cccc@l17g2000yqe.googlegroups.com> Message-ID: <7e4306de-b95a-40c8-9c9c-10745d8dc793@z19g2000yqb.googlegroups.com> It is not entirely clear what the functions and especially what their signatures are in that C library clibsmi. In general, for shared libraries, you need to define those first as prototype using ctypes.CFUNCTYPE() and then instantiate each prototype once supplying the necessary parameter flags using prototype(func_spec, tuple_of_param_flags). See sections 15.16.2.3 and 4 of the ctypes docs*. Take a look the Python bindings** for the VLC library, the file called vlc.py***. The function _Cfunction is used to create the Python callable for each C function in that VLC library. All the Python callables are in the second half of the vlc.py file, starting at line 2600. Hope this helps, /Jean *) **) ***) On Dec 10, 3:32?pm, News Wombat wrote: > Hi everyone, > > I've been experimenting with the ctypes module and think it's great. > I'm hitting a few snags though with seg faults. ?I attached two links > that holds the code. ?The line i'm having problems with is this, > > sn=clibsmi.smiGetNextNode(pointer(sno),SMI_NODEKIND_ANY) > > It will work one time, and if I call it again with the result of the > previous, even though the result (a c struct) looks ok, it will > segfault. ?I think it's a problem with pointers or maybe the function > in the c library trying to change a string that python won't let it > change. ?I'm stuck, any tips would be appreciated. ?Thanks, and Merry > Christmas! > > constants.py:http://pastebin.com/HvngjzZN > libsmi.py:http://pastebin.com/19C9kYEa From mpnordland at gmail.com Sat Dec 11 14:43:13 2010 From: mpnordland at gmail.com (mpnordland) Date: Sat, 11 Dec 2010 11:43:13 -0800 (PST) Subject: Catching user switching and getting current active user from root on linux References: <1a9bdbd4-2997-4e0f-a24f-cd148247e312@r40g2000prh.googlegroups.com> <8739qhs6dz.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <797ba948-c608-4ed5-b2eb-25177932da91@o4g2000yqd.googlegroups.com> sorry, I've been busy, it's on linux, and current active user is the user currently using the computer. My program needs to switch log files when a different user starts using the computer. From mpnordland at gmail.com Sat Dec 11 14:51:18 2010 From: mpnordland at gmail.com (mpnordland) Date: Sat, 11 Dec 2010 11:51:18 -0800 (PST) Subject: Catching user switching and getting current active user from root on linux References: <1a9bdbd4-2997-4e0f-a24f-cd148247e312@r40g2000prh.googlegroups.com> <8739qhs6dz.fsf.mdw@metalzone.distorted.org.uk> <797ba948-c608-4ed5-b2eb-25177932da91@o4g2000yqd.googlegroups.com> Message-ID: about the pyutmp, is the most recent entry at the top or bottom of the file? From steve at holdenweb.com Sat Dec 11 15:21:53 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 11 Dec 2010 15:21:53 -0500 Subject: Python critique In-Reply-To: <4d036383$1@dnews.tpgi.com.au> References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> <4d028748$0$1621$742ec2ed@news.sonic.net> <499F3F3D16A34734B5D195F91EB58520@teddy> <4d02bcf2$0$1624$742ec2ed@news.sonic.net> <4d036383$1@dnews.tpgi.com.au> Message-ID: On 12/11/2010 6:46 AM, Lie Ryan wrote: > On 12/11/10 11:37, Dan Stromberg wrote: >> On Fri, Dec 10, 2010 at 3:51 PM, John Nagle wrote: >>> On 12/10/2010 3:25 PM, Stefan Behnel wrote: >>>> Benjamin Kaplan, 11.12.2010 00:13: >>>>> On Fri, Dec 10, 2010 at 5:46 PM, Octavian Rasnita wrote: >>>>> The only scopes Python has are module and function. >>> >>> There's more. Both a lambda, and in Python 3.x, >>> list comprehensions, introduce a new scope. >> >> And classes and methods. > > Also, class scope and instance scope, though similar, are distinct > scopes. Python also have the hidden interpreter-level scope (the > __builtins__). But classes and instances don't have scopes. They have namespaces. That is, if we are talking about lexical scoping. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sat Dec 11 15:23:51 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 11 Dec 2010 15:23:51 -0500 Subject: Python critique In-Reply-To: <4d036383$1@dnews.tpgi.com.au> References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com> <4d028748$0$1621$742ec2ed@news.sonic.net> <499F3F3D16A34734B5D195F91EB58520@teddy> <4d02bcf2$0$1624$742ec2ed@news.sonic.net> <4d036383$1@dnews.tpgi.com.au> Message-ID: On 12/11/2010 6:46 AM, Lie Ryan wrote: > Also, class scope and instance scope, though similar, are distinct > scopes. Python also have the hidden interpreter-level scope (the > __builtins__). Kindly ignore my last post. Class scopes are lexical, instance scopes are not. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sat Dec 11 15:31:58 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 11 Dec 2010 15:31:58 -0500 Subject: Python distribution recommendation? In-Reply-To: <16E90EF945B946F39CF1EA5836F024DA@teddy> References: <16E90EF945B946F39CF1EA5836F024DA@teddy> Message-ID: On 12/11/2010 9:31 AM, Octavian Rasnita wrote: > Ok, thank you all for your recommendations. > > I think I will install ActivePython because it seems that it offers more features for Windows programming than the other distro (by default, which is important for a beginner). > > I will use WxPython and not other GUIS like QT, Tk or GTK because they are not accessible for screen readers, so I will also need to install WxPython if ActiveState's Python doesn't include it. > I must say that wxPython has been one of the most consistently easy packages to install over the last ten years. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From roy at panix.com Sat Dec 11 15:47:09 2010 From: roy at panix.com (Roy Smith) Date: Sat, 11 Dec 2010 15:47:09 -0500 Subject: Making os.unlink() act like "rm -f" References: Message-ID: In article , Christian Heimes wrote: > Am 11.12.2010 18:04, schrieb Roy Smith: > > if os.access("file", os.F_OK): > > os.unlink("file") > > > > but that's annoying too. What would people think about a patch to > > os.unlink() to add an optional second parameter which says to ignore > > attempts to remove non-existent files (just like "rm -f")? Then you > > could do: > > -1 > > os.unlink is a small wrapper around the unlink(2) function. OK, fair enough. Perhaps a better place would be in a higher level module like shutil. It was suggested I look at shutil.rmtree(), but that only works of path is a directory. Also, the meaning of the ignore_errors flag is not quite what I'm looking for. I don't want to ignore errors, I just want "if it doesn't exist, this is a no-op". In short, exactly what "rm -r" does in the unix shell. So, maybe a new function is shutils? shutils.rm(path, force=False) Delete the file at path. If force is True, this is a no-op if path does not exist. Raises OSError if the operation fails. From python.list at tim.thechases.com Sat Dec 11 16:01:52 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 11 Dec 2010 15:01:52 -0600 Subject: Catching user switching and getting current active user from root on linux In-Reply-To: <797ba948-c608-4ed5-b2eb-25177932da91@o4g2000yqd.googlegroups.com> References: <1a9bdbd4-2997-4e0f-a24f-cd148247e312@r40g2000prh.googlegroups.com> <8739qhs6dz.fsf.mdw@metalzone.distorted.org.uk> <797ba948-c608-4ed5-b2eb-25177932da91@o4g2000yqd.googlegroups.com> Message-ID: <4D03E6C0.3000904@tim.thechases.com> On 12/11/2010 01:43 PM, mpnordland wrote: > it's on linux, and current active user is the user currently > using the computer. My program needs to switch log files when > a different user starts using the computer. The problem is that multiple users can be logged on at the same time. You might be able to come up with a solution that works for a small set of use-cases, but I admin several Linux boxes where multiple people can be logged-in at the same time. There are also some multi-head arrangements (multiple keyboards/mice/monitors and sometimes even sound-cards attached to the same motherboard) and people can log into each "terminal" (if you will) concurrently, all on the same box. So if I'm using the computer, and a co-worker logs in, I'm still using it at the same time you might catch the "new user logged in" event. Watching wtmp (or possibly /var/log/auth) can capture the "hey, somebody logged in" event, but that doesn't mean that other previous users are done with their sessions. -tkc From stef.mientki at gmail.com Sat Dec 11 16:38:43 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Sat, 11 Dec 2010 22:38:43 +0100 Subject: python-parser running Beautiful Soup needs to be reviewed In-Reply-To: <3dcf2ff3-1b23-4dd8-a719-d1647a1a051e@o4g2000yqd.googlegroups.com> References: <3dcf2ff3-1b23-4dd8-a719-d1647a1a051e@o4g2000yqd.googlegroups.com> Message-ID: <4D03EF63.4040306@gmail.com> On 11-12-2010 17:24, Martin Kaspar wrote: > Hello commnity > > i am new to Python and to Beatiful Soup also! > It is told to be a great tool to parse and extract content. So here i > am...: > > I want to take the content of a -tag of a table in a html > document. For example, i have this table > > > > > > > >
> This is a sample text > > This is the second sample text >
> > How can i use beautifulsoup to take the text "This is a sample text"? > > Should i make use > soup.findAll('table' ,attrs={'class':'bp_ergebnis_tab_info'}) to get > the whole table. > > See the target http://www.schulministerium.nrw.de/BP/SchuleSuchen?action=799.601437941842&SchulAdresseMapDO=142323 > > Well - what have we to do first: > > The first thing is t o find the table: > > i do this with Using find rather than findall returns the first item > in the list > (rather than returning a list of all finds - in which case we'd have > to add an extra [0] > to take the first element of the list): > > > table = soup.find('table' ,attrs={'class':'bp_ergebnis_tab_info'}) > > Then use find again to find the first td: > > first_td = soup.find('td') > > Then we have to use renderContents() to extract the textual contents: > > text = first_td.renderContents() > > ... and the job is done (though we may also want to use strip() to > remove leading and trailing spaces: > > trimmed_text = text.strip() > > This should give us: > > > print trimmed_text > This is a sample text > > as desired. > > > What do you think about the code? I love to hear from you!? I've no opinion. I'm just struggling with BeautifulSoup myself, finding it one of the toughest libs I've seen ;-) So the simplest solution I came up with: Text = """
This is a sample text This is the second sample text
""" Content = BeautifulSoup ( Text ) print Content.find('td').contents[0].strip() >>> This is a sample text And now I wonder how to get the next contents !! cheers, Stef > greetings > matze From ppearson at nowhere.invalid Sat Dec 11 17:13:09 2010 From: ppearson at nowhere.invalid (Peter Pearson) Date: 11 Dec 2010 22:13:09 GMT Subject: python-parser running Beautiful Soup needs to be reviewed References: <3dcf2ff3-1b23-4dd8-a719-d1647a1a051e@o4g2000yqd.googlegroups.com> Message-ID: <8mibblFbk1U1@mid.individual.net> On Sat, 11 Dec 2010 22:38:43 +0100, Stef Mientki wrote: [snip] > So the simplest solution I came up with: > > Text = """ > > > > > > >
> This is a sample text > > This is the second sample text >
> """ > Content = BeautifulSoup ( Text ) > print Content.find('td').contents[0].strip() >>>> This is a sample text > > And now I wonder how to get the next contents !! Here's a suggestion: peter at eleodes:~$ python Python 2.5.2 (r252:60911, Jul 22 2009, 15:35:03) [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from BeautifulSoup import BeautifulSoup >>> Text = """ ... ... ... ... ... ... ...
... This is a sample text ... ... This is the second sample text ...
... """ >>> Content = BeautifulSoup ( Text ) >>> for xx in Content.findAll('td'): ... print xx.contents[0].strip() ... This is a sample text This is the second sample text >>> -- To email me, substitute nowhere->spamcop, invalid->net. From alex.kapps at web.de Sat Dec 11 17:26:12 2010 From: alex.kapps at web.de (Alexander Kapps) Date: Sat, 11 Dec 2010 23:26:12 +0100 Subject: python-parser running Beautiful Soup needs to be reviewed In-Reply-To: <4D03EF63.4040306@gmail.com> References: <3dcf2ff3-1b23-4dd8-a719-d1647a1a051e@o4g2000yqd.googlegroups.com> <4D03EF63.4040306@gmail.com> Message-ID: <4D03FA84.6040605@web.de> On 11.12.2010 22:38, Stef Mientki wrote: > On 11-12-2010 17:24, Martin Kaspar wrote: >> Hello commnity >> >> i am new to Python and to Beatiful Soup also! >> It is told to be a great tool to parse and extract content. So here i >> am...: >> >> I want to take the content of a-tag of a table in a html >> document. For example, i have this table >> >> >> >> >> >> >> >>
>> This is a sample text >> >> This is the second sample text >>
>> >> How can i use beautifulsoup to take the text "This is a sample text"? >> >> Should i make use >> soup.findAll('table' ,attrs={'class':'bp_ergebnis_tab_info'}) to get >> the whole table. >> >> See the target http://www.schulministerium.nrw.de/BP/SchuleSuchen?action=799.601437941842&SchulAdresseMapDO=142323 >> >> Well - what have we to do first: >> >> The first thing is t o find the table: >> >> i do this with Using find rather than findall returns the first item >> in the list >> (rather than returning a list of all finds - in which case we'd have >> to add an extra [0] >> to take the first element of the list): >> >> >> table = soup.find('table' ,attrs={'class':'bp_ergebnis_tab_info'}) >> >> Then use find again to find the first td: >> >> first_td = soup.find('td') >> >> Then we have to use renderContents() to extract the textual contents: >> >> text = first_td.renderContents() >> >> ... and the job is done (though we may also want to use strip() to >> remove leading and trailing spaces: >> >> trimmed_text = text.strip() >> >> This should give us: >> >> >> print trimmed_text >> This is a sample text >> >> as desired. >> >> >> What do you think about the code? I love to hear from you!? > I've no opinion. > I'm just struggling with BeautifulSoup myself, finding it one of the toughest libs I've seen ;-) Really? While I'm by no means an expert, I find it very easy to work with. It's very well structured IMHO. > So the simplest solution I came up with: > > Text = """ > > > > > > >
> This is a sample text > > This is the second sample text >
> """ > Content = BeautifulSoup ( Text ) > print Content.find('td').contents[0].strip() >>>> This is a sample text > > And now I wonder how to get the next contents !! Content = BeautifulSoup ( Text ) for td in Content.findAll('td'): print td.string.strip() # or td.renderContents().strip() From usernet at ilthio.net Sat Dec 11 17:32:23 2010 From: usernet at ilthio.net (Tim Harig) Date: Sat, 11 Dec 2010 22:32:23 +0000 (UTC) Subject: Catching user switching and getting current active user from root on linux References: <1a9bdbd4-2997-4e0f-a24f-cd148247e312@r40g2000prh.googlegroups.com> <8739qhs6dz.fsf.mdw@metalzone.distorted.org.uk> <797ba948-c608-4ed5-b2eb-25177932da91@o4g2000yqd.googlegroups.com> Message-ID: Mr. Chase, I really wouldn't even bother wasting my time on this one. He asked an incomplete question to start with; so, the replies that he received were insufficient to solve his problem. He still has not provided enough information to know how to answer his question propery. He doesn't understand a sacastic reply when he hears one, he doesn't understand the concept of a multi-user operating system, and he doesn't understand the concept of how usenet threads work. Until he demonstrates some intelligence, I would say that he has flunked the Turing test. From th3flyboy at gmail.com Sat Dec 11 17:41:00 2010 From: th3flyboy at gmail.com (Peter C.) Date: Sat, 11 Dec 2010 14:41:00 -0800 (PST) Subject: Bind C++ program for use with both Python 2.x and 3.x Message-ID: Hello, I am looking at the possibility of making a program in C++. The catch is it will require the ability to work with binding for use with scripting in both Python 2.x and 3.x for various tool plugins. Is there any way to bind a C++ app to work with both Python 2.x and 3.x using the Python C API? Note if I could I'd just do Python 3, however I need Python 2 support to allow for the use of this application as a plugin in apps that use Python 2 as well. From martin at v.loewis.de Sat Dec 11 18:03:31 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sun, 12 Dec 2010 00:03:31 +0100 Subject: Bind C++ program for use with both Python 2.x and 3.x In-Reply-To: References: Message-ID: <4D040343.6040600@v.loewis.de> Am 11.12.2010 23:41, schrieb Peter C.: > Hello, I am looking at the possibility of making a program in C++. The > catch is it will require the ability to work with binding for use with > scripting in both Python 2.x and 3.x for various tool plugins. Is > there any way to bind a C++ app to work with both Python 2.x and 3.x > using the Python C API? Note if I could I'd just do Python 3, however > I need Python 2 support to allow for the use of this application as a > plugin in apps that use Python 2 as well. Notice that binding to Python 2 may not be enough: you also need to specify the Python 2 version (i.e. different bindings for 2.5, 2.6, and 2.7, say). You will have to ship different copies of the binding. Of course, you can ship them in a single distribution (zip file, or whatever your distribution format is). If you are creating different copies of the binding, supporting both 2.x and 3.x simultaneously will be straight-forward. Regards, Martin From perry at nomail.net.invalid Sat Dec 11 18:23:43 2010 From: perry at nomail.net.invalid (Perry Johnson) Date: Sat, 11 Dec 2010 23:23:43 +0000 (UTC) Subject: Enabling the use of POSIX character classes in Python References: Message-ID: On 2010-12-11, MRAB wrote: > On 11/12/2010 17:33, Perry Johnson wrote: >> Python's re module does not support POSIX character classes, for >> example [:alpha:]. It is, of course, trivial to simulate them using >> character ranges when the text to be matched uses the ASCII character >> set. Sadly, my problem is that I need to process Unicode text. The re >> module has its own character classes that do support Unicode, however >> they are not sufficient. >> >> I would find it extremely useful if there was information on the >> Unicode code points that map to each of the POSIX character classes. > > Have a look at the new regex implementation on PyPI: > > http://pypi.python.org/pypi/regex This is exactly what I needed! Thanks! From martin.schoon at gmail.com Sat Dec 11 18:32:14 2010 From: martin.schoon at gmail.com (Martin Schoeoen) Date: 11 Dec 2010 23:32:14 GMT Subject: Ways of accessing this mailing list? References: <871v7050b0.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <8mifvuF424U1@mid.individual.net> On 2010-11-04, Mark Wooding wrote: > John Bond writes: > >> Hope this isn't too O/T - I was just wondering how people read/send to >> this mailing list, eg. normal email client, gmane, some other software >> or online service? >> >> My normal inbox is getting unmanageable, and I think I need to find a >> new way of following this and other lists. > > I read and post to it as comp.lang.python. I maintain a local NNTP > server, which interacts with my ISP's news server. I read and post news > (and mail) using GNU Emacs and Gnus. > > (Interestingly, if enormous folders are your problem, Gnus can apply > news-like expiry rules to email folders.) > Same here: comp.lang.python and gnus. Well, right now I am actually trying out slrn -- a bit of a dejavu experience since I used slrn a bit in the early 1990s (and I have not used vi in many, many years). I have tried out other programs such as traditional email clients and mainstream gui programs such as Pan but find that user interface paradigm does not work well for usenet news and me. /Martin From steve+comp.lang.python at pearwood.info Sat Dec 11 19:04:11 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 Dec 2010 00:04:11 GMT Subject: Catching user switching and getting current active user from root on linux References: <1a9bdbd4-2997-4e0f-a24f-cd148247e312@r40g2000prh.googlegroups.com> <8739qhs6dz.fsf.mdw@metalzone.distorted.org.uk> <797ba948-c608-4ed5-b2eb-25177932da91@o4g2000yqd.googlegroups.com> Message-ID: <4d04117b$0$30000$c3e8da3$5496439d@news.astraweb.com> On Sat, 11 Dec 2010 11:43:13 -0800, mpnordland wrote: > sorry, I've been busy, it's on linux, and current active user is the > user currently using the computer. My program needs to switch log files > when a different user starts using the computer. I think you have missed what people are trying to tell you: if you're running Linux, you may have more than one human being logged into and using the computer AT THE SAME TIME. You can also have a single human being logged into the computer as more than one user, and one user being used by multiple human beings. As we speak, I am logged into my Linux computer eight times, five times as myself (two GUI sessions, just to prove I can do it, plus three terminals), two times as root, and one time as another user; my wife's computer has two people logged in simultaneously (me and her); I'm also logged into a server at work, which currently lists eight people logged in twenty-one times between them. Perhaps you should explain what problem you are trying to solve, rather than how you think you should solve it ("catch the user switching"). -- Steven From wander.lairson at gmail.com Sat Dec 11 20:32:20 2010 From: wander.lairson at gmail.com (wander.lairson) Date: Sat, 11 Dec 2010 23:32:20 -0200 Subject: array and strings in Python 3 Message-ID: Hello, This is my first post on python mailing list. I've working in code which must run on python 2 and python 3. I am using array.array as data buffers. I am stuck with the following code line, which works on Python 2, but not on Python 3.1.2: >>> import array >>> array.array('B', 'test') Traceback (most recent call last): File "", line 1, in TypeError: an integer is required According to Python 3 documentation (as far as I understood it), it should work. Again, no problem on Python 2. I've googled for people with similar problems, but got nothing. Does anyone have an idea what could I be doing wrong? Thanks in advance. -- Best Regards, Wander Lairson Costa LCoN - Laborat?rio de Computa??o Natural - Natural Computing Laboratory (http://www.mackenzie.com.br/lcon.html) Programa de P?s-Gradua??o em Engenharia El?trica (PPGEE) Faculdade de Computa??o e Inform?tica (FCI) Universidade Presbiteriana Mackenzie - SP - Brazil From clp2 at rebertia.com Sat Dec 11 20:48:27 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 11 Dec 2010 17:48:27 -0800 Subject: array and strings in Python 3 In-Reply-To: References: Message-ID: On Sat, Dec 11, 2010 at 5:32 PM, wander.lairson wrote: > Hello, > > This is my first post on python mailing list. I've working in code > which must run on python 2 and python 3. I am using array.array as > data buffers. I am stuck with the following code line, which works on > Python 2, but not on Python 3.1.2: > >>>> import array >>>> array.array('B', 'test') > Traceback (most recent call last): > ?File "", line 1, in > TypeError: an integer is required > > According to Python 3 documentation (as far as I understood it), it > should work. I think you forgot to keep in mind the changes in bytes vs. unicode in Python 3 when reading the docs. > Again, no problem on Python 2. I've googled for people > with similar problems, but got nothing. Does anyone have an idea what > could I be doing wrong? Recall that string handling changed incompatibly between Python 2 and Python 3. Your 'test' was a bytestring in Python 2 but is now a *Unicode string* in Python 3. The `array` module's handling of strings changed as well. Reading the Python 3 docs @ http://docs.python.org/dev/library/array.html , we find (all emphases added): class array.array(typecode[, initializer]) [...] If given a list or string, the initializer is passed to the new array?s fromlist(), frombytes(), or **fromunicode()** method (see below) to add initial items to the array. Otherwise, the iterable initializer is passed to the extend() method. [...] array.fromunicode(s) Extends this array with data from the given unicode string. The array **must be a type 'u' array**; **otherwise a ValueError is raised**. Use array.frombytes(unicodestring.encode(enc)) to append Unicode data to an array of some other type. Since your array's typecode is not 'u', you're getting a ValueError just like the docs say. Try using a bytestring instead: array.array('B', b"test") # Note the b prefix Incidentally, if you ran 2to3 over your code and weren't warned about this change in the array module, then that's probably a bug in 2to3 which ought to be reported: http://bugs.python.org Cheers, Chris -- http://blog.rebertia.com From wander.lairson at gmail.com Sat Dec 11 21:09:40 2010 From: wander.lairson at gmail.com (wander.lairson) Date: Sun, 12 Dec 2010 00:09:40 -0200 Subject: array and strings in Python 3 In-Reply-To: References: Message-ID: > The `array` module's handling of strings changed as well. Reading the > Python 3 docs @ http://docs.python.org/dev/library/array.html , we > find (all emphases added): > class array.array(typecode[, initializer]) > ? ?[...] > ? ?If given a list or string, the initializer is passed to the new > array?s fromlist(), frombytes(), or **fromunicode()** method (see > below) to add initial items to the array. Otherwise, the iterable > initializer is passed to the extend() method. > [...] > array.fromunicode(s) > ? ?Extends this array with data from the given unicode string. The > array **must be a type 'u' array**; **otherwise a ValueError is > raised**. Use array.frombytes(unicodestring.encode(enc)) to append > Unicode data to an array of some other type. > Actually I was using the 3.1 docs as reference, as it is the stable one. After your comments, I dug a bit more in the documentation and in the code, and I figured out that for unicode strings, you must pass 'u' as the first constructor parameter. > Incidentally, if you ran 2to3 over your code and weren't warned about > this change in the array module, then that's probably a bug in 2to3 > which ought to be reported: http://bugs.python.org > I am not using 2to3 because I am not converting Python 2 code to Python 3, I am writing code that must run on Python 2 and Python 3. Thank you for your help :) -- Best Regards, Wander Lairson Costa LCoN - Laborat?rio de Computa??o Natural - Natural Computing Laboratory (http://www.mackenzie.com.br/lcon.html) Programa de P?s-Gradua??o em Engenharia El?trica (PPGEE) Faculdade de Computa??o e Inform?tica (FCI) Universidade Presbiteriana Mackenzie - SP - Brazil From memilanuk at gmail.com Sun Dec 12 00:15:13 2010 From: memilanuk at gmail.com (Monte Milanuk) Date: Sat, 11 Dec 2010 21:15:13 -0800 Subject: Ways of accessing this mailing list? In-Reply-To: <8mifvuF424U1@mid.individual.net> References: <871v7050b0.fsf.mdw@metalzone.distorted.org.uk> <8mifvuF424U1@mid.individual.net> Message-ID: On 12/11/10 3:32 PM, Martin Schoeoen wrote: > On 2010-11-04, Mark Wooding wrote: >> John Bond writes: >> >>> Hope this isn't too O/T - I was just wondering how people read/send to >>> this mailing list, eg. normal email client, gmane, some other software >>> or online service? Thunderbird + gmane works for me. From v.harishankar at gmail.com Sun Dec 12 01:50:51 2010 From: v.harishankar at gmail.com (Harishankar) Date: Sun, 12 Dec 2010 06:50:51 +0000 (UTC) Subject: Ways of accessing this mailing list? References: <871v7050b0.fsf.mdw@metalzone.distorted.org.uk> <8mifvuF424U1@mid.individual.net> Message-ID: On Sat, 11 Dec 2010 21:15:13 -0800, Monte Milanuk wrote: > Thunderbird + gmane works for me. I myself post using Pan Usenet client accessing this mailing list from gmane. The advantage of a proper newsreader software is that it quotes correctly (i.e. quote at top, reply below). Many Usenet and mailing list users get angry if you top post (i.e. quote below the reply) -- Harishankar (http://harishankar.org http://lawstudentscommunity.com) From ben+python at benfinney.id.au Sun Dec 12 03:18:52 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 12 Dec 2010 19:18:52 +1100 Subject: Ways of accessing this mailing list? References: <871v7050b0.fsf.mdw@metalzone.distorted.org.uk> <8mifvuF424U1@mid.individual.net> Message-ID: <87sjy3xv2r.fsf@benfinney.id.au> Harishankar writes: > The advantage of a proper newsreader [program] is that it quotes > correctly (i.e. quote at top, reply below). That's a function of the person typing into it, not of the program. Placing the cursor at the top of the message allows the person to trim the superfluous parts of the quoted material, replying in-line to each point as they work their way down. -- \ ?No matter how far down the wrong road you've gone, turn back.? | `\ ?Turkish proverb | _o__) | Ben Finney From v.harishankar at gmail.com Sun Dec 12 05:07:11 2010 From: v.harishankar at gmail.com (Harishankar) Date: Sun, 12 Dec 2010 10:07:11 +0000 (UTC) Subject: Ways of accessing this mailing list? References: <871v7050b0.fsf.mdw@metalzone.distorted.org.uk> <8mifvuF424U1@mid.individual.net> <87sjy3xv2r.fsf@benfinney.id.au> Message-ID: On Sun, 12 Dec 2010 19:18:52 +1100, Ben Finney wrote: > That's a function of the person typing into it, not of the program. I was talking about the default program behaviour. Yes, you can move the cursor up or down, but I was talking about the way regular e-mail clients generally handle quoted blocks. -- Harishankar (http://harishankar.org http://lawstudentscommunity.com) From stefan_ml at behnel.de Sun Dec 12 06:06:28 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 12 Dec 2010 12:06:28 +0100 Subject: Bind C++ program for use with both Python 2.x and 3.x In-Reply-To: References: Message-ID: Peter C., 11.12.2010 23:41: > Hello, I am looking at the possibility of making a program in C++. The > catch is it will require the ability to work with binding for use with > scripting in both Python 2.x and 3.x for various tool plugins. Do I read this right that you want your program to be written in C++, and use an embedded Python interpreter to provide scripting capabilities? Is there a reason you'd want to write the application itself in C++ in the first place? If it's new code, it's likely faster to write it Python directly. Usually, that also leads to a lot less code, which helps in keeping the code more maintainable. > Is > there any way to bind a C++ app to work with both Python 2.x and 3.x > using the Python C API? Note if I could I'd just do Python 3, however > I need Python 2 support to allow for the use of this application as a > plugin in apps that use Python 2 as well. The easiest (and fastest etc.) way to do that is to write the glue code in Cython. It generates portable C/C++ code that supports Python 2.3 to 3.2. However, if you ship binaries, you will still need to provide them for the different Python versions (even for different Py2.x versions), as the runtimes are not binary compatible. Stefan From nfdisco at gmail.com Sun Dec 12 06:35:22 2010 From: nfdisco at gmail.com (ernest) Date: Sun, 12 Dec 2010 03:35:22 -0800 (PST) Subject: default argument in method Message-ID: Hi, I'd like to have a reference to an instance attribute as default argument in a method. It doesn't work because "self" is not defined at the time the method signature is evaluated. For example: class C(object): def __init__(self): self.foo = 5 def m(self, val=self.foo): return val Raises NameError because 'self' is not defined. The obvious solution is put val=None in the signature and set val to the appropriate value inside the method (if val is None: ...), but I wonder if there's another way. Cheers, Ernest From clp2 at rebertia.com Sun Dec 12 06:49:41 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 12 Dec 2010 03:49:41 -0800 Subject: default argument in method In-Reply-To: References: Message-ID: On Sun, Dec 12, 2010 at 3:35 AM, ernest wrote: > Hi, > > I'd like to have a reference to an instance attribute as > default argument in a method. It doesn't work because > "self" is not defined at the time the method signature is > evaluated. For example: > > class C(object): > ? ?def __init__(self): > ? ? ? ?self.foo = 5 > ? ?def m(self, val=self.foo): > ? ? ? ?return val > > Raises NameError because 'self' is not defined. > The obvious solution is put val=None in the signature > and set val to the appropriate value inside the method > (if val is None: ...), but I wonder if there's another way. Nope, not really. There are some more complicated slight variations on the same theme (e.g. hoisting the idiom into a decorator), but they're of fairly dubious merit; just use the straightforward idiom you already outlined. Cheers, Chris -- http://blog.rebertia.com From data.2 at rediff.com Sun Dec 12 07:40:12 2010 From: data.2 at rediff.com (gaurav) Date: Sun, 12 Dec 2010 04:40:12 -0800 (PST) Subject: Get careers in Management stage. Message-ID: Great careers in Management work. Institutional careers in Management http://topcareer.webs.com/humanresourcemgmt.htm & http://rojgars.webs.com/bankingjobs.htm Full ranges of Banking and insurance banking jobs, railway jobs opportunities to make career. http://rojgars.webs.com/bankingjobs.htm From rustompmody at gmail.com Sun Dec 12 08:01:24 2010 From: rustompmody at gmail.com (rusi) Date: Sun, 12 Dec 2010 05:01:24 -0800 (PST) Subject: class browser References: Message-ID: <0c5c92c8-6a51-4ed3-aa29-cc6a2a40fa77@37g2000prx.googlegroups.com> On Dec 8, 11:24?pm, Adam Tauno Williams wrote: > On Wed, 2010-12-08 at 13:18 +0530, Rustom Mody wrote: > > If I have a medium to large python code base to browse/study, what are > > the class browsers available? > > Monodevelop has good Python support which includes a working Python > class browser for Python projects & solutions. > Ok downloaded mono. How do I import an existing project? From stef.mientki at gmail.com Sun Dec 12 08:29:47 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 12 Dec 2010 14:29:47 +0100 Subject: python-parser running Beautiful Soup needs to be reviewed In-Reply-To: <4D03FA84.6040605@web.de> References: <3dcf2ff3-1b23-4dd8-a719-d1647a1a051e@o4g2000yqd.googlegroups.com> <4D03EF63.4040306@gmail.com> <4D03FA84.6040605@web.de> Message-ID: <4D04CE4B.2020607@gmail.com> I've no opinion. >> I'm just struggling with BeautifulSoup myself, finding it one of the toughest libs I've seen ;-) > > Really? While I'm by no means an expert, I find it very easy to work with. It's very well > structured IMHO. I think the cause lies in the documentation. The PySide documentation is much easier to understand (at least for me) http://www.pyside.org/docs/pyside/PySide/QtWebKit/QWebElement.html cheers, Stef From maxc at me.com Sun Dec 12 09:14:16 2010 From: maxc at me.com (Max Countryman) Date: Sun, 12 Dec 2010 09:14:16 -0500 Subject: while True or while 1 In-Reply-To: References: Message-ID: I'm sure this has been brought up many times, but a quick Googling didn't yield the decisive results I was hoping for, so I apologize if this has already been addressed in great detail somewhere else. I am wondering what the rationale is behind preferring while True over while 1? For me, it seems that using True provides more clarity, but is that the only benefit? Is while 1 more prone to errors? Thanks! From python at lists.fastmail.net Sun Dec 12 09:28:29 2010 From: python at lists.fastmail.net (python at lists.fastmail.net) Date: Sun, 12 Dec 2010 15:28:29 +0100 Subject: Objects and validation Message-ID: <1292164109.18709.1409927215@webmail.messagingengine.com> I have a routine in Python which is extracting information from a website. This information is read and inserted into objects. I currently have all the validations and checks implemented in the routines which are reading the HTML and creating the objects. It is however also possible to move all the validations into the class itself. What is considered the best practice for this: validation in the functions which read the information and creates the objects or in the class itself? Thijs From javiervandam at gmail.com Sun Dec 12 10:02:13 2010 From: javiervandam at gmail.com (javivd) Date: Sun, 12 Dec 2010 07:02:13 -0800 (PST) Subject: Reading by positions plain text files References: <39a07597-02b9-4ef8-9ca9-93e2d2425e66@p7g2000prb.googlegroups.com> Message-ID: On Dec 1, 7:15?am, Tim Harig wrote: > On 2010-12-01, javivd wrote: > > > > > > > > > > > On Nov 30, 11:43?pm, Tim Harig wrote: > >> On 2010-11-30, javivd wrote: > > >> > I have a case now in wich anotherfilehas been provided (besides the > >> > database) that tells me in wich column of thefileis every variable, > >> > because there isn't any blank or tab character that separates the > >> > variables, they are stick together. This secondfilespecify the > >> > variable name and his position: > > >> > VARIABLE NAME ? ? ?POSITION (COLUMN) INFILE > >> > var_name_1 ? ? ? ? ? ? ? ? 123-123 > >> > var_name_2 ? ? ? ? ? ? ? ? 124-125 > >> > var_name_3 ? ? ? ? ? ? ? ? 126-126 > >> > .. > >> > .. > >> > var_name_N ? ? ? ? ? ? ? ? 512-513 (last positions) > > >> I am unclear on the format of these positions. ?They do not look like > >> what I would expect from absolute references in the data. ?For instance, > >> 123-123 may only contain one byte??? which could change for different > >> encodings and how you mark line endings. ?Frankly, the use of the > >> world columns in the header suggests that the data *is* separated by > >> line endings rather then absolute position and the position refers to > >> the line number. In which case, you can use splitlines() to break up > >> the data and then address the proper line by index. ?Nevertheless, > >> you can usefile.seek() to move to an absolute offset in thefile, > >> if that really is what you are looking for. > > > I work in a survey research firm. the data im talking about has a lot > > of 0-1 variables, meaning yes or no of a lot of questions. so only one > > position of a character is needed (not byte), explaining the 123-123 > > kind of positions of a lot of variables. > > Thenfile.seek() is what you are looking for; but, you need to be aware of > line endings and encodings as indicated. ?Make sure that you open thefile > using whatever encoding was used when it was generated or you could have > problems with multibyte characters affecting the offsets. I've tried your advice and something is wrong. Here is my code, f = open(r'c:c:\somefile.txt', 'w') f.write('0123456789\n0123456789\n0123456789') f.close() f = open(r'c:\somefile.txt', 'r') for line in f: f.seek(3,0) print f.read(1) #just to know if its printing the rigth column I used .seek() in this manner, but is not working. Let me put the problem in another way. I have .txt file with NO headers, and NO blanks between any columns. But i know that from columns, say 13 to 15, is variable VARNAME_1 (of course, a three digit var). How can extract that column in a list call VARNAME_1?? Obviously, this should extend to all the positions and variables i have to extract from the file. Thanks! J From lists at cheimes.de Sun Dec 12 10:30:38 2010 From: lists at cheimes.de (Christian Heimes) Date: Sun, 12 Dec 2010 16:30:38 +0100 Subject: while True or while 1 In-Reply-To: References: Message-ID: Am 12.12.2010 15:14, schrieb Max Countryman: > I'm sure this has been brought up many times, but a quick Googling didn't yield the decisive results I was hoping for, so I apologize if this has already been addressed in great detail somewhere else. > > I am wondering what the rationale is behind preferring while True over while 1? For me, it seems that using True provides more clarity, but is that the only benefit? Is while 1 more prone to errors? In Python 2.x, "while 1" is slightly faster than "while True". The interpreter can't optimize "while True" because the name "True" can be bind to another value. In Python 3.x it's no longer possible to rebind the names True and False just like None in Python 2.x Christian From krister.svanlund at gmail.com Sun Dec 12 10:33:41 2010 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Sun, 12 Dec 2010 16:33:41 +0100 Subject: while True or while 1 In-Reply-To: References: Message-ID: On Sun, Dec 12, 2010 at 3:14 PM, Max Countryman wrote: > I'm sure this has been brought up many times, but a quick Googling didn't yield the decisive results I was hoping for, so I apologize if this has already been addressed in great detail somewhere else. > > I am wondering what the rationale is behind preferring while True over while 1? For me, it seems that using True provides more clarity, but is that the only benefit? Is while 1 more prone to errors? It's just silly to use 1 since it will evaluate to True either way. From pakalk at gmail.com Sun Dec 12 11:03:32 2010 From: pakalk at gmail.com (pakalk) Date: Sun, 12 Dec 2010 08:03:32 -0800 (PST) Subject: Objects and validation References: Message-ID: <33c2de8c-f7dd-445d-b0c8-27ae89870e44@o9g2000pre.googlegroups.com> On 12 Gru, 15:28, pyt... at lists.fastmail.net wrote: > I have a routine in Python which is extracting information from a > website. This information is read and inserted into objects. > > I currently have all the validations and checks implemented in the > routines which are reading the HTML and creating the objects. It is > however also possible to move all the validations into the class itself. > What is considered the best practice for this: validation in the > functions which read the information and creates the objects or in the > class itself? setter Data sources may differ, and may be used for many reasons, so validating data there is not a good idea. Object has to keep correct data, so it should validate it. If you want to have object created no matter what, you can add validate() method, but you may also use setters for this - error will be raised every try to set wrong data. From emile at fenx.com Sun Dec 12 11:06:17 2010 From: emile at fenx.com (Emile van Sebille) Date: Sun, 12 Dec 2010 08:06:17 -0800 Subject: stuck with Pexpect script need help!! In-Reply-To: References: Message-ID: On 12/10/2010 10:02 PM Darshak Bavishi said... > Pexpect is intended for UNIX-like operating systems.""") > > Can we use pexpect from windows host machine ?! > I expect not... Emile From emile at fenx.com Sun Dec 12 11:22:12 2010 From: emile at fenx.com (Emile van Sebille) Date: Sun, 12 Dec 2010 08:22:12 -0800 Subject: Ways of accessing this mailing list? In-Reply-To: References: <871v7050b0.fsf.mdw@metalzone.distorted.org.uk> <8mifvuF424U1@mid.individual.net> <87sjy3xv2r.fsf@benfinney.id.au> Message-ID: On 12/12/2010 2:07 AM Harishankar said... > On Sun, 12 Dec 2010 19:18:52 +1100, Ben Finney wrote: > >> That's a function of the person typing into it, not of the program. > > I was talking about the default program behaviour. Yes, you can move the > cursor up or down, but I was talking about the way regular e-mail clients > generally handle quoted blocks. > http://web.archive.org/web/20041224190115/lists.suse.com/archive/suse-linux-e/2002-Oct/1698.html Emile From alex.kapps at web.de Sun Dec 12 11:31:32 2010 From: alex.kapps at web.de (Alexander Kapps) Date: Sun, 12 Dec 2010 17:31:32 +0100 Subject: stuck with Pexpect script need help!! In-Reply-To: References: Message-ID: <4D04F8E4.1040208@web.de> On 12.12.2010 17:06, Emile van Sebille wrote: > On 12/10/2010 10:02 PM Darshak Bavishi said... > >> Pexpect is intended for UNIX-like operating systems.""") > >> >> Can we use pexpect from windows host machine ?! >> > > I expect not... > > Emile > According to [1] you might get it working with the Cygwin port of Python. Alternatively try WinPexpect [2] [1] http://www.noah.org/wiki/Pexpect#Python [2] http://bitbucket.org/geertj/winpexpect/wiki/Home From steve at holdenweb.com Sun Dec 12 13:31:34 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 12 Dec 2010 13:31:34 -0500 Subject: while True or while 1 In-Reply-To: References: Message-ID: <4D051506.2060403@holdenweb.com> On 12/12/2010 10:30 AM, Christian Heimes wrote: > Am 12.12.2010 15:14, schrieb Max Countryman: >> I'm sure this has been brought up many times, but a quick Googling didn't yield the decisive results I was hoping for, so I apologize if this has already been addressed in great detail somewhere else. >> >> I am wondering what the rationale is behind preferring while True over while 1? For me, it seems that using True provides more clarity, but is that the only benefit? Is while 1 more prone to errors? > > In Python 2.x, "while 1" is slightly faster than "while True". The > interpreter can't optimize "while True" because the name "True" can be > bind to another value. In Python 3.x it's no longer possible to rebind > the names True and False just like None in Python 2.x > Would you care to quantify how much CPU time that optimization will typically save for a loop of fair magnitude (say, a billion iterations)? Python is designed to provide readable code. Writing while True: ... is much more legible than its pre-True couterpart while 1: ... and is, I'd say, therefore to be preferred (except in a code base intended to compile on 2.2 and before). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From usernet at ilthio.net Sun Dec 12 14:09:56 2010 From: usernet at ilthio.net (Tim Harig) Date: Sun, 12 Dec 2010 19:09:56 +0000 (UTC) Subject: Reading by positions plain text files References: <39a07597-02b9-4ef8-9ca9-93e2d2425e66@p7g2000prb.googlegroups.com> Message-ID: On 2010-12-12, javivd wrote: > On Dec 1, 7:15?am, Tim Harig wrote: >> On 2010-12-01, javivd wrote: >> > On Nov 30, 11:43?pm, Tim Harig wrote: >> >> encodings and how you mark line endings. ?Frankly, the use of the >> >> world columns in the header suggests that the data *is* separated by >> >> line endings rather then absolute position and the position refers to >> >> the line number. In which case, you can use splitlines() to break up >> >> the data and then address the proper line by index. ?Nevertheless, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Note that I specifically questioned the use of absolute file position vs. postion within a column. These are two different things. You use different methods to extract each. >> > I work in a survey research firm. the data im talking about has a lot >> > of 0-1 variables, meaning yes or no of a lot of questions. so only one >> > position of a character is needed (not byte), explaining the 123-123 >> > kind of positions of a lot of variables. >> >> Thenfile.seek() is what you are looking for; but, you need to be aware of >> line endings and encodings as indicated. ?Make sure that you open thefile >> using whatever encoding was used when it was generated or you could have >> problems with multibyte characters affecting the offsets. > > f = open(r'c:c:\somefile.txt', 'w') I suspect you don't need to use the c: twice. > f.write('0123456789\n0123456789\n0123456789') Note that the file you a writing contains three lines. Is the data that you are looking for located at an absolute position in the file or on a position within a individual line? If the latter, not that line endings may be composed of more then a single character. > f.write('0123456789\n0123456789\n0123456789') ^ postion 3 using fseek() > for line in f: Perhaps you meant: for character in f.read(): or for line in f.read().splitlines() > f.seek(3,0) This will always take you back to the exact fourth position in the file (indicated above). > I used .seek() in this manner, but is not working. It is working the way it is supposed to. If you want the absolution position 3 in a file then: f = open('somefile.txt', 'r') f.seek(3) variable = f.read(1) If you want the absolute position in a column: f = open('somefile.txt', 'r').read().splitlines() for column in f: variable = column[3] From urban.dani at gmail.com Sun Dec 12 14:10:48 2010 From: urban.dani at gmail.com (Daniel Urban) Date: Sun, 12 Dec 2010 20:10:48 +0100 Subject: Needed: Real-world examples for Python's Cooperative Multiple Inheritance In-Reply-To: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> References: <89b6d53f-dcdc-4442-957f-1f4d29115a26@n32g2000pre.googlegroups.com> Message-ID: > So far, the only situation I can find where method names necessarily > overlap is for the basics like __init__(), close(), flush(), and > save() where multiple parents need to have their own initialization > and finalization. One other possibility is subclasses of the JSONEncoder class. For example the writer of class X provides a class, XJSONEncoder, which is able to serialize X instances (by extending the default method). Similarly there is a YJSONEncoder class, which can serialize Y instances. Those classes implement the default method like this: def default(self, o): if isinstance(o, X): ... # serialize the X instance else: return super().default(o) # let the next in the MRO try to handle it If YJSONEncoder encodes Y instances similarly, one can create an encoder class, which can encode both X and Y instances: class XYJSONEncoder(XJSONEncoder, YJSONEncoder): pass It is usable this way: json.dumps([X(), Y()], cls=XYJSONEncoder) Regards, Daniel From usernet at ilthio.net Sun Dec 12 14:27:51 2010 From: usernet at ilthio.net (Tim Harig) Date: Sun, 12 Dec 2010 19:27:51 +0000 (UTC) Subject: Reading by positions plain text files References: <39a07597-02b9-4ef8-9ca9-93e2d2425e66@p7g2000prb.googlegroups.com> Message-ID: On 2010-12-12, Tim Harig wrote: >> I used .seek() in this manner, but is not working. > > It is working the way it is supposed to. > If you want the absolute position in a column: > > f = open('somefile.txt', 'r').read().splitlines() > for column in f: > variable = column[3] or: f = open('somefile.txt', 'r') for column in f.readlines(): variable = column[3] From lists at cheimes.de Sun Dec 12 14:32:00 2010 From: lists at cheimes.de (Christian Heimes) Date: Sun, 12 Dec 2010 20:32:00 +0100 Subject: while True or while 1 In-Reply-To: <4D051506.2060403@holdenweb.com> References: <4D051506.2060403@holdenweb.com> Message-ID: Am 12.12.2010 19:31, schrieb Steve Holden: > Would you care to quantify how much CPU time that optimization will > typically save for a loop of fair magnitude (say, a billion iterations)? The difference is minimal but measurable for very tight loops. $ python -m timeit -n20 -- "i = 0" "while 1:" " i+=1" " if i == 1000000: break" 20 loops, best of 3: 89.7 msec per loop $ python -m timeit -n20 -- "i = 0" "while True:" " i+=1" " if i == 1000000: break" 20 loops, best of 3: 117 msec per loop In Python 2.x the peep hole optimizer can't remove the global lookup and check for trueness for "while True". >>> def while1(): ... while 1: ... pass ... >>> import dis >>> dis.dis(while1) 2 0 SETUP_LOOP 3 (to 6) 3 >> 3 JUMP_ABSOLUTE 3 >> 6 LOAD_CONST 0 (None) 9 RETURN_VALUE >>> def whiletrue(): ... while True: ... pass ... >>> dis.dis(whiletrue) 2 0 SETUP_LOOP 12 (to 15) >> 3 LOAD_GLOBAL 0 (True) 6 JUMP_IF_FALSE 4 (to 13) 9 POP_TOP 3 10 JUMP_ABSOLUTE 3 >> 13 POP_TOP 14 POP_BLOCK >> 15 LOAD_CONST 0 (None) 18 RETURN_VALUE > Python is designed to provide readable code. Writing > > while True: > ... > > is much more legible than its pre-True couterpart > > while 1: > ... No argue with that! I was merely making a point that "while 1" executes different byte code than "while True". Readability is important but sometimes speed is of the essence. "while 1" is one of the few tricks to speed up tight loops a bit. Christian From xrgtn at yandex.ru Sun Dec 12 15:04:22 2010 From: xrgtn at yandex.ru (Alexander Gattin) Date: Sun, 12 Dec 2010 22:04:22 +0200 Subject: Wanted: slow regexes In-Reply-To: <4CFFB122.5040504@mrabarnett.plus.com> References: <4CFC61B0.8000109@mrabarnett.plus.com> <20101208124225.GA4846@xrgtn-q40> <4CFFB122.5040504@mrabarnett.plus.com> Message-ID: <20101212200422.GA8060@xrgtn-q40> Hello, On Wed, Dec 08, 2010 at 04:24:02PM +0000, MRAB wrote: > Interestingly, that webpage says that: > > ("a" x 100000) =~ /^(ab?)*$/ > > caused Perl to segfault. I tried it and it didn't segfault, but it > didn't match either It doesn't segfault but produces a warning with -w: xrgtn at xrgtn-q40:~$ perl -wse 'print(("a" x 100000) =~ /^(ab?)*$/)' Complex regular subexpression recursion limit (32766) exceeded at -e line 1. xrgtn at xrgtn-q40:~$ -- With best regards, xrgtn From martin at v.loewis.de Sun Dec 12 16:01:06 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sun, 12 Dec 2010 22:01:06 +0100 Subject: while True or while 1 In-Reply-To: References: <4D051506.2060403@holdenweb.com> Message-ID: <4D053812.5000305@v.loewis.de> >> Python is designed to provide readable code. Writing >> >> while True: >> ... >> >> is much more legible than its pre-True couterpart >> >> while 1: >> ... > > No argue with that! I actually want to argue with that: I find "while 1" more legible. That's probably because a) I'm use to it, and b) the English words "while" and "True" don't mean much to me, I need recognize them, and recognizing "True" is slightly more difficult than recognizing "1". In the end, in any project, there should be coding conventions, and authors should follow them. What is legible is IMO much more determined by convention than "intuition", at least to experienced programmers (i.e. those that have been following the convention for a long time). Regards, Martin From chambon.pascal at wanadoo.fr Sun Dec 12 16:15:43 2010 From: chambon.pascal at wanadoo.fr (Pascal Chambon) Date: Sun, 12 Dec 2010 22:15:43 +0100 Subject: Directly calling python's function arguments dispatcher Message-ID: <4D053B7F.1080202@wanadoo.fr> Hello I've encountered several times, when dealing with adaptation of function signatures, the need for explicitly resolving complex argument sets into a simple variable mapping. Explanations. Consider that function: def foo(a1, a2, *args, **kwargs): pass calling foo(1, a2=2, a3=3) will map these arguments to local variables like these: { 'a1': 1, 'a2': 2, 'args': tuple(), 'kwarg's: {'a3': 3} } That's a quite complex resolution mechanism, which must handle positional and keyword arguments, and deal with both collision and missing argument cases. Normally, the simplest way to invoke this mechanism is to define a function with the proper signature, and then call it (like, here, foo()). But there are cases where a more "meta" approach would suit me well. For example when adapting xmlrpc methods : due to the limitations of xmlrpc (no keyword arguments), we use a trick, i.e our xmlrpc functions only accept a single argument, a "struct" (python dict) which gets unpacked on arrival, when calling the real functions exposed by the xmlrpc server. But on client side, I'd like to offer a more native interface (allowing both positional and keyword arguments), without having to manually define an adapter function for each xmlrpc method. To summarize, I'd like to implement a magic method like this one (please don't care about performance isues for now): class XmlrpcAdapter: def __getattr__(self, funcname): # we create an on-the-fly adapter def adapter(*args, **kwargs): xmlrpc_kwargs = _resolve_func_signature(funcname, *args, **kwargs) # we call the remote function with an unique dict argument self.xmlrpc_server.call(funcname, xmlrpc_kwargs) return adapter As you see, all I need is _resolve_func_signature(), which is actually the routine (internal to the python runtime) which transforms complex function calls in a simple mapping of variables to be added to the function local namespace. Of course this routine would need information about the target functions' signature, but I have that info available (for example, via a set of functions that are a mockup of the real xmlrpc API). Is that routine exposed to python, somewhere ? Does anybody know a working implementation here or there ? Thanks for the help, regards, Pakal From devplayer at gmail.com Sun Dec 12 16:21:43 2010 From: devplayer at gmail.com (DevPlayer) Date: Sun, 12 Dec 2010 13:21:43 -0800 (PST) Subject: Python on wikipedia Message-ID: Snapshot in time, hey look at that; someone used Python as THE example of what a programming language is on Wikipedia. http://en.wikipedia.org/wiki/Programming_language From pakalk at gmail.com Sun Dec 12 16:38:28 2010 From: pakalk at gmail.com (pakalk) Date: Sun, 12 Dec 2010 13:38:28 -0800 (PST) Subject: Python on wikipedia References: Message-ID: On 12 Gru, 22:21, DevPlayer wrote: > Snapshot in time, hey look at that; someone used Python as THE example > of what a programming language is on Wikipedia.http://en.wikipedia.org/wiki/Programming_language aaaaaaaaaaaaaand? what is the catch? From steve+comp.lang.python at pearwood.info Sun Dec 12 16:49:02 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 Dec 2010 21:49:02 GMT Subject: while True or while 1 References: Message-ID: <4d05434e$0$29970$c3e8da3$5496439d@news.astraweb.com> On Sun, 12 Dec 2010 16:33:41 +0100, Krister Svanlund wrote: > On Sun, Dec 12, 2010 at 3:14 PM, Max Countryman wrote: >> I'm sure this has been brought up many times, but a quick Googling >> didn't yield the decisive results I was hoping for, so I apologize if >> this has already been addressed in great detail somewhere else. >> >> I am wondering what the rationale is behind preferring while True over >> while 1? For me, it seems that using True provides more clarity, but is >> that the only benefit? Is while 1 more prone to errors? > > It's just silly to use 1 since it will evaluate to True either way. With the "while True" idiom in Python 2.x, you can easily exit out of an infinite loop without using break: >>> while True: ... print "Looping" ... True = 0 ... Looping >>> >>> while True: # Execute an infinite loop in 0 seconds. ... print "Looping" ... >>> *wink* -- Steven From john at nmt.edu Sun Dec 12 16:56:27 2010 From: john at nmt.edu (JohnWShipman) Date: Sun, 12 Dec 2010 13:56:27 -0800 (PST) Subject: Tkinter polling example: file copy with progress bar Message-ID: Attached below is a Tkinter script that demonstrates polling, that is, performing a long-running process in parallel with the GUI. The script asks for an input file name and an output file name and copies the input file to the output file. The copy operation is done in a child process managed with pexpect, and the GUI reports the progress of the file copy using a Scale widget as a progress bar. Cordially, John W. Shipman, NM Tech Computer Center, Socorro, NM; john at nmt.edu ================ #!/usr/bin/env python #================================================================ # copyprogress: File copy with a progress bar for Tkinter 8.4. # - Demonstrates Tkinter .after() and the pexpect module. # Written by John W. Shipman (john at nmt.edu), New Mexico Tech # Computer Center, Socorro, NM 87801 USA. This script is in # the public domain. #---------------------------------------------------------------- # - - - - - I m p o r t s import sys, os, stat import Tkinter as tk import tkFileDialog, tkMessageBox import pexpect # - - - - - M a n i f e s t c o n s t a n t s BUTTON_FONT = ("Helvetica", 17) LABEL_FONT = ("Helvetica", 14) ENTRY_FONT = ("DejaVu Sans Mono", 12) POLL_TIME = 50 # Polling frequency in milliseconds # - - - - - m a i n def main(): """ """ app = App() app.master.title("Copy with progress bar") app.mainloop() # - - - - - c l a s s A p p class App(tk.Frame): '''Copies a file with a progress bar. Widgets: .fromFileVar: StringVar for source file name .fromFileEntry: Entry for source file name .fromFileBrowse: Browse button for source file name .fromFileLabel: Label for above .toFileVar: StringVar for destination file name .toFileEntry: Entry for destination file name .toFileBrowse: Browse button for destination file name .toFileLabel: Label for above .copyButton: Button to start copying .progressVar: DoubleVar for progress scale .progressScale: Scale to show progress Grid plan: 0 1 2 +----------------+-----------------+----------------+ 0 | .fromFileEntry | .fromFileBrowse | .fromFileLabel | +----------------+-----------------+----------------+ 1 | .toFileEntry | .toFileBrowse | .toFileLabel | +----------------+-----------------+----------------+ 2 | .progress | .copyButton | .quitButton | +----------------+-----------------+----------------+ Internal state: .fromFileSize: Source file size in bytes .child: pexpect child process to do the copy ''' # - - - A p p . _ _ i n i t _ _ def __init__(self, master=None): tk.Frame.__init__(self, master) self.grid() self.__createWidgets() # - - - A p p . _ _ c r e a t e w i d g e t s def __createWidgets(self): '''Create all widgets and associated variables. ''' self.fromFileVar = tk.StringVar() self.fromFileEntry = tk.Entry ( self, textvariable=self.fromFileVar, font=ENTRY_FONT, width=50 ) rowx, colx = 0, 0 self.fromFileEntry.grid(row=rowx, column=colx, sticky=tk.E) self.fromFileBrowse = tk.Button ( self, command=self.__browseFrom, font=BUTTON_FONT, text="Browse" ) colx += 1 self.fromFileBrowse.grid(row=rowx, column=colx) self.fromFileLabel = tk.Label ( self, font=LABEL_FONT, text="Source file" ) colx += 1 self.fromFileLabel.grid(row=rowx, column=colx, sticky=tk.W) self.toFileVar = tk.StringVar() self.toFileEntry = tk.Entry ( self, textvariable=self.toFileVar, font=ENTRY_FONT, width=50 ) rowx, colx = rowx+1, 0 self.toFileEntry.grid(row=rowx, column=colx, sticky=tk.E) self.toFileBrowse = tk.Button ( self, command=self.__browseTo, font=BUTTON_FONT, text="Browse" ) colx += 1 self.toFileBrowse.grid(row=rowx, column=colx) self.toFileLabel = tk.Label ( self, font=LABEL_FONT, text="Destination file") colx += 1 self.toFileLabel.grid(row=rowx, column=colx, sticky=tk.W) self.progressVar = tk.DoubleVar() self.progressScale = tk.Scale ( self, length=400, orient=tk.HORIZONTAL, from_=0.0, to=100.0, resolution=0.1, tickinterval=20.0, variable=self.progressVar, label="Percent completion", font=LABEL_FONT ) rowx, colx = rowx+1, 0 self.progressScale.grid(row=rowx, column=colx, sticky=tk.E) self.copyButton = tk.Button ( self, command=self.__copyHandler, font=BUTTON_FONT, text="Copy" ) colx += 1 self.copyButton.grid(row=rowx, column=colx ) self.quitButton = tk.Button ( self, command=self.quit, font=BUTTON_FONT, text="Quit" ) colx += 1 self.quitButton.grid(row=rowx, column=colx, sticky=tk.W) # - - - A p p . _ _ b r o w s e F r o m def __browseFrom(self): '''Handler for Browse button for the source file. ''' # [ if the user enters an existing file name in a popup -> # self.fromFileVar := that name # else -> # f := an empty string ] f = tkFileDialog.askopenfilename(title="Source file name") if len(f) == 0: return else: self.fromFileVar.set(f) # - - - A p p . _ _ b r o w s e T o def __browseTo(self): '''Handler for Browse button for the source file. ''' # [ if the user enters a nonexistent existing file name in # a popup, or enters an existing name and then says it's # okay to overwrite it -> # self.toFileVar := that name # else -> # f := an empty string ] f = tkFileDialog.asksaveasfilename(title="Destination file name") if len(f) == 0: return else: self.toFileVar.set(f) # - - - A p p . _ _ c o p y H a n d l e r def __copyHandler(self): '''Start the file copy process. ''' # [ if the source file name is empty -> # display a popup error message # return # else -> I ] if len(self.fromFileVar.get()) == 0: tkMessageBox.showerror("Error", "Please enter a source file name." ) return # [ if the destination file name is empty -> # show an error popup # return # else if the destination file exists and the user's reply # to a popup indicates they do not want to proceed -> # return # else -> I ] toFileName = self.toFileVar.get() if len(toFileName) == 0: tkMessageBox.showerror("Error", "Please enter a destination file name." ) return elif os.path.exists(toFileName): message = ( "File '%s' exists.\nDo you want to overwrite " "it?" % toFileName ) answer = tkMessageBox.askokcancel("Destination file exists", message, default=tkMessageBox.CANCEL) if not answer: return # [ if the source file exists -> # self.fromFileSize := that file's size in bytes # else -> # display a popup and return ] if not self.__copySetup(): return # [ self.child := a pexpect.spawn child process that copies # the source file to the destination file with -f # self := self with a callback to self.__poll after # POLL_TIME ] self.__startCopy() # - - - A p p . _ _ c o p y S e t u p def __copySetup(self): '''Operations done before the copy is started. [ if the source file exists -> self.fromFileSize := that file's size in bytes return True else -> display an error popup return False ] ''' fromFileName = self.fromFileVar.get() try: self.fromFileSize = self.__measureFile(fromFileName) except OSError, details: tkMessageBox.showerror ( "Source file error", "File %s: %s" % (fromFileName, str(details)) ) return False return True # - - - A p p . _ _ s t a r t C o p y def __startCopy ( self ): '''Start up a file copy operation. [ (self.fromFileVar contains the name of a readable file) and (self.toFileVar contains the name of a writeable file) -> self.child := a pexpect.spawn child process that copies the source file to the destination file with -f self := self with a callback to self.__poll after POLL_TIME ] ''' # [ command := a copy command from the source file to the # destination file, with a force option ] command = ( "cp -f %s %s" % (self.fromFileVar.get(), self.toFileVar.get()) ) # [ self.progressVar := 0 # self := self with a callback after POLL_TIME to # self.__poll ] self.progressVar.set(0.0) self.after(POLL_TIME, self.__poll) # [ self.child := a pexpect.spawn process to run command ] self.child = pexpect.spawn(command) # - - - A p p . _ _ m e a s u r e F i l e def __measureFile(self, fileName): '''Determine the current length of a file, if it exists. [ if fileName can be statted -> return the current length of that file else -> raise OSError ] ''' status = os.stat ( fileName ) return status[stat.ST_SIZE] # - - - A p p . _ _ p o l l def __poll(self): '''Periodic check of the copy progress. [ if self.child has terminated -> self.progressVar := 100.0 self.child := (closed) show a status popup else if we can stat the output file -> self.progressVar := (destination file size / self.fromFileSize) as a percentage self := self with a callback to self.__poll after POLL_TIME ] ''' # [ if self.child has terminated -> # self.progressVar := 100.0 # return # else -> I ] if not self.child.isalive(): self.child.close() self.progressVar.set(100.0) tkMessageBox.showinfo ( "Success", "File %s has been copied to %s, size %s." % (self.fromFileVar.get(), self.toFileVar.get(), self.fromFileSize) ) return # [ if we can stat the output file -> # outFileSize := its size in bytes # else -> # display an error popup # return ] toFileName = self.toFileVar.get() try: toFileSize = self.__measureFile ( toFileName ) except OSError, details: tkMessageBox.showerror ( "Destination file error", "File %s: %s" % (toFileName, str(details)) ) return # [ self.progressVar := toFileSize / self.fromFileSize # as a percentage # self := self with a callback to self.__poll after # POLL_TIME ] self.progressVar.set ( 100.0 * float(toFileSize) / float(self.fromFileSize) ) self.after(POLL_TIME, self.__poll) # - - - - - E p i l o g u e if __name__ == "__main__": main() From tjreedy at udel.edu Sun Dec 12 17:41:45 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 12 Dec 2010 17:41:45 -0500 Subject: Python on wikipedia In-Reply-To: References: Message-ID: On 12/12/2010 4:38 PM, pakalk wrote: > On 12 Gru, 22:21, DevPlayer wrote: >> Snapshot in time, hey look at that; someone used Python as THE example >> of what a programming language is on Wikipedia.http://en.wikipedia.org/wiki/Programming_language > > aaaaaaaaaaaaaand? what is the catch? Wikipedia entries can be edited. -- Terry Jan Reedy From __peter__ at web.de Sun Dec 12 17:41:47 2010 From: __peter__ at web.de (Peter Otten) Date: Sun, 12 Dec 2010 23:41:47 +0100 Subject: Directly calling python's function arguments dispatcher References: Message-ID: Pascal Chambon wrote: > I've encountered several times, when dealing with adaptation of function > signatures, the need for explicitly resolving complex argument sets into > a simple variable mapping. Explanations. > > > Consider that function: > > def foo(a1, a2, *args, **kwargs): > pass > > calling foo(1, a2=2, a3=3) > > will map these arguments to local variables like these: > { > 'a1': 1, > 'a2': 2, > 'args': tuple(), > 'kwarg's: {'a3': 3} > } > > That's a quite complex resolution mechanism, which must handle > positional and keyword arguments, and deal with both collision and > missing argument cases. > Is that routine exposed to python, somewhere ? Does anybody know a > working implementation here or there ? http://docs.python.org/library/inspect.html#inspect.getcallargs From wallenpb at gmail.com Sun Dec 12 21:15:01 2010 From: wallenpb at gmail.com (Bill Allen) Date: Sun, 12 Dec 2010 20:15:01 -0600 Subject: Python on wikipedia In-Reply-To: References: Message-ID: Yeah, I noticed that a while back too. Kinda cool. --Bill On Sun, Dec 12, 2010 at 3:21 PM, DevPlayer wrote: > Snapshot in time, hey look at that; someone used Python as THE example > of what a programming language is on Wikipedia. > http://en.wikipedia.org/wiki/Programming_language > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Sun Dec 12 23:20:40 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 12 Dec 2010 23:20:40 -0500 Subject: while True or while 1 In-Reply-To: References: <4D051506.2060403@holdenweb.com> Message-ID: On 12/12/2010 2:32 PM, Christian Heimes wrote: > Am 12.12.2010 19:31, schrieb Steve Holden: >> > Would you care to quantify how much CPU time that optimization will >> > typically save for a loop of fair magnitude (say, a billion iterations)? > The difference is minimal but measurable for very tight loops. > > $ python -m timeit -n20 -- "i = 0" "while 1:" " i+=1" " if i == > 1000000: break" > 20 loops, best of 3: 89.7 msec per loop > $ python -m timeit -n20 -- "i = 0" "while True:" " i+=1" " if i == > 1000000: break" > 20 loops, best of 3: 117 msec per loop > > In Python 2.x the peep hole optimizer can't remove the global lookup and > check for trueness for "while True". > Yes, you said that already and I certainly didn't disagree. [...] >> Python is designed to provide readable code. Writing >> > >> > while True: >> > ... >> > >> > is much more legible than its pre-True couterpart >> > >> > while 1: >> > ... > No argue with that! I was merely making a point that "while 1" executes > different byte code than "while True". Readability is important but > sometimes speed is of the essence. "while 1" is one of the few tricks to > speed up tight loops a bit. OK, but the figures you quote save you 27.3 ms per million iterations, for a grand total saving of 27.3 ns per iteration. So "a bit" is hardly worth considering for most programs, is it? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From bavishi.darshak at gmail.com Mon Dec 13 00:03:07 2010 From: bavishi.darshak at gmail.com (Darshak Bavishi) Date: Mon, 13 Dec 2010 10:33:07 +0530 Subject: Is there any way to SSH from Python ?! Message-ID: Hi Experts, I need to know that is there any way to SSH (From Windows Host) to Unix machine ?! If Yes than How ? Because when i use telenet it not showing the no result !! As earlier it was suggested that i should try with exit first and than read_all() but still issue persist and getting hang import getpass import sys import telnetlib import time HOST = "*.*.*.*" #user = raw_input("Enter your remote account: ") #password = getpass.getpass() user = "Darshak2" password = "****" tn = telnetlib.Telnet(HOST , 5400) print "1" tn.read_until("login:" , 5) print "2" tn.write(user + "\n") print "3" if password: tn.read_until("Password: ") tn.write(password + "\n") print "4" tn.write("set alarm = off" + "\n") tn.write("set event = off" + "\n") print "5" tn.write("Cd /Office-Parameters/Mobility-Config-Parameters/Subscriber-Query-by-IMSI-MSISDN-or-IMEI" + "\n") print "6" tn.write("\n") tn.write("\n") tn.write("vlrsubquery msisdn=***" + "\n") tn.write("\n") tn.write("exit" + "\n") print tn.read_all() tn.close() -- BR Darshak Bavishi -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Mon Dec 13 00:09:00 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 12 Dec 2010 21:09:00 -0800 Subject: Is there any way to SSH from Python ?! In-Reply-To: References: Message-ID: On Sun, Dec 12, 2010 at 9:03 PM, Darshak Bavishi wrote: > Hi Experts, > I need to know that is there any way to SSH (From Windows Host) to Unix > machine ?! > If Yes than How ? http://www.lag.net/paramiko/ Did you try googling "ssh python"? Cheers, Chris -- http://blog.rebertia.com From bavishi.darshak at gmail.com Mon Dec 13 00:11:20 2010 From: bavishi.darshak at gmail.com (Darshak Bavishi) Date: Mon, 13 Dec 2010 10:41:20 +0530 Subject: Is there any way to SSH from Python ?! In-Reply-To: References: Message-ID: i am trying from last week but no luck !! one thing only found that pexpect it not useful in windows pls help out of this On Mon, Dec 13, 2010 at 10:39 AM, Chris Rebert wrote: > On Sun, Dec 12, 2010 at 9:03 PM, Darshak Bavishi > wrote: > > Hi Experts, > > I need to know that is there any way to SSH (From Windows Host) to Unix > > machine ?! > > If Yes than How ? > > http://www.lag.net/paramiko/ > > Did you try googling "ssh python"? > > Cheers, > Chris > -- > http://blog.rebertia.com > -- BR Darshak Bavishi -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Mon Dec 13 02:29:56 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 Dec 2010 07:29:56 GMT Subject: while True or while 1 References: <4D051506.2060403@holdenweb.com> Message-ID: <4d05cb74$0$30003$c3e8da3$5496439d@news.astraweb.com> On Sun, 12 Dec 2010 23:20:40 -0500, Steve Holden wrote: > On 12/12/2010 2:32 PM, Christian Heimes wrote: [...] >> No argue with that! I was merely making a point that "while 1" executes >> different byte code than "while True". Readability is important but >> sometimes speed is of the essence. "while 1" is one of the few tricks >> to speed up tight loops a bit. > > OK, but the figures you quote save you 27.3 ms per million iterations, > for a grand total saving of 27.3 ns per iteration. So "a bit" is hardly > worth considering for most programs, is it? I don't think anyone is saying that people should routinely use "while 1" for loops because they're faster than the alternatives. But it is a real, if small, optimization for a particular class of tight loops. Using the figures shown by Christian, it could be a 20-25% speed up on extremely tight loops. You're right though, it's hardly worth the effort for large, expensive loops though -- but then on the other hand, "while 1" is not so unreadable that it should be avoided. I'm actually quite fond of the look of "while 1:", and sometimes use it, not because it's faster, but just because I like it. -- Steven From no.email at nospam.invalid Mon Dec 13 02:48:04 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 12 Dec 2010 23:48:04 -0800 Subject: while True or while 1 References: <4D051506.2060403@holdenweb.com> <4d05cb74$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7xbp4q5d1n.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > I'm actually quite fond of the look of "while 1:", and sometimes use it, > not because it's faster, but just because I like it. for v in itertools.repeat(True): ... ;-) From bruno.desthuilliers at gmail.com Mon Dec 13 03:51:57 2010 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Mon, 13 Dec 2010 00:51:57 -0800 (PST) Subject: Objects and validation References: Message-ID: <2435365b-5aea-4561-933b-d5242d0729ab@d8g2000yqf.googlegroups.com> On 12 d?c, 15:28, pyt... at lists.fastmail.net wrote: > I have a routine in Python which is extracting information from a > website. This information is read and inserted into objects. > > I currently have all the validations and checks implemented in the > routines which are reading the HTML and creating the objects. It is > however also possible to move all the validations into the class itself. > What is considered the best practice for this: validation in the > functions which read the information and creates the objects or in the > class itself? > There's no one-size-fits-all answer to this question. Part of the work really belongs to the layer that accepts data from the outside world, part of it belong to the 'model' object itself. In any case, the 'model' object shouldn't have to worry about data conversion etc - like, if one of the attribute is supposed to be a datetime, it's the client code's responsability to provide a proper datetime object, not a string that may (or not) be the textual representation of a date and time. From jeanmichel at sequans.com Mon Dec 13 05:19:35 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 13 Dec 2010 11:19:35 +0100 Subject: Proposed changes to logging defaults In-Reply-To: <9a8c49a6-d24f-4e27-b2e7-2ba654f8236a@t8g2000prh.googlegroups.com> References: <3763d355-9074-485c-a694-031d600d5b84@m11g2000vbs.googlegroups.com> <9a8c49a6-d24f-4e27-b2e7-2ba654f8236a@t8g2000prh.googlegroups.com> Message-ID: <4D05F337.1010402@sequans.com> Vinay Sajip wrote: > On Dec 10, 10:17 am, Jean-Michel Pichavant > wrote: > > Hi Jean-Michel, > > I think Antoine answered your other points, so I'll address the last > one: > > >> Last question, if no handler is found, why not simply drop the log >> event, doing nothing ? It sounds pretty reasonable and less intrusive. >> > > That is what happens at the moment if configured for production > (logging.raiseExceptions is False) - nothing happens, and the event is > discarded. For development (logging.raiseExceptions is True), the "No > handlers were found for logger XXX" is printed once, to assist > developers to detect misconfiguration. However, the original logged > event is still discarded. > > The original philosophy (when logging was added to Python) was that > logging is an adjunct to the operation of the program using it - the > program should work the same way whether or not logging is configured. > However, the consensus on Python-dev is that the logging package > should do useful work, and not just act as an adjunct, i.e. notify the > user on warning and error conditions by default if no logging > configuration is set up. A program will now work differently depending > on whether logging is configured, but if it is not configured, the > default should be to display warnings and errors, unless explicitly > silenced (as per the Zen of Python). > > These two approaches (original vs. proposed) are of course quite > different, and there's no way of satisfying both proponents of both > approaches, nor any easy way of measuring how many of each there are. > The proposed change moves logging closer to the current Python-dev > consensus, and means that messages currently written to sys.stderr by > stdlib modules could be logged instead, with the stdlib maintainers > writing those messages knowing that unless explicitly silenced, those > messages will appear to the user as they would via a > sys.stderr.write(). It will be good if this happens, so that > application writers will have better control over what messages are > displayed (when they need it), by configuring logging. > > Remember - no changes to behaviour will occur if this change is > implemented and an application configures logging. It's only the no- > configuration case that will change. > > To get the current behaviour after the proposed changes are > implemented, an application developer would have to do > logging.lastResort = None, which is a small price to pay (and more or > less equivalent in difficulty with what users who want verbosity by > default have to do, e.g. call basicConfig(). > > Regards, > > Vinay Sajip > Thanks for the explanation. JM From bavishi.darshak at gmail.com Mon Dec 13 05:20:29 2010 From: bavishi.darshak at gmail.com (Darshak Bavishi) Date: Mon, 13 Dec 2010 15:50:29 +0530 Subject: How to install pycrypto mode in windows ?! Message-ID: Hi Experts , I am using python 2.6 and i had installed paramiko module which needs pycrypto but , when i am installing pycrypto in windows its giving error as follows: creating build\lib.win32-2.6\Crypto\PublicKey copying .\PublicKey\DSA.py -> build\lib.win32-2.6\Crypto\PublicKey copying .\PublicKey\ElGamal.py -> build\lib.win32-2.6\Crypto\PublicKey copying .\PublicKey\pubkey.py -> build\lib.win32-2.6\Crypto\PublicKey copying .\PublicKey\qNEW.py -> build\lib.win32-2.6\Crypto\PublicKey copying .\PublicKey\RSA.py -> build\lib.win32-2.6\Crypto\PublicKey copying .\PublicKey\__init__.py -> build\lib.win32-2.6\Crypto\PublicKey running build_ext building 'Crypto.Hash.MD2' extension error: Unable to find vcvarsall.bat can u suggest any source to get pycrypto to avoid such events?! -- BR Darshak Bavishi -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at cheimes.de Mon Dec 13 05:33:03 2010 From: lists at cheimes.de (Christian Heimes) Date: Mon, 13 Dec 2010 11:33:03 +0100 Subject: How to install pycrypto mode in windows ?! In-Reply-To: References: Message-ID: Am 13.12.2010 11:20, schrieb Darshak Bavishi: > Hi Experts , > > I am using python 2.6 and i had installed paramiko module which needs > pycrypto but , > when i am installing pycrypto in windows its giving error as follows: > [...] > can u suggest any source to get pycrypto to avoid such events?! Well, your problem is that you are using the sources of pycrypto. vcvarsall.bat is a part of MS Visual Studio. You need either VS2008 or MinGW32 to compile the sources of Windows. Better look for precompiled binaries. Michael offers prebuild binaries on his site [1]. There are fine, I'm using them on Windows, too. Christian [1] http://www.voidspace.org.uk/python/modules.shtml#pycrypto From jeanmichel at sequans.com Mon Dec 13 05:40:20 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 13 Dec 2010 11:40:20 +0100 Subject: Python critique In-Reply-To: <52430F724D9B40DFB856FCDD172C28C8@teddy> References: <21868b6d-ab01-402d-a9b3-ee1be39771b8@o4g2000yqd.googlegroups.com><4d028748$0$1621$742ec2ed@news.sonic.net> <4d02b47b$0$30000$c3e8da3$5496439d@news.astraweb.com> <52430F724D9B40DFB856FCDD172C28C8@teddy> Message-ID: <4D05F814.70505@sequans.com> Octavian Rasnita wrote: > From: "Steven D'Aprano" > ... > >>> Can you please tell me how to write the following program in Python? >>> >>> my $n = 1; >>> >>> { >>> my $n = 2; >>> print "$n\n"; >>> } >>> >>> print "$n\n"; >>> >>> If this program if ran in Perl, it prints: >>> 2 >>> 1 >>> >> Lots of ways. Here's one: >> >> >> n = 1 >> >> class Scope: >> n = 2 >> print n >> >> print n >> >> >> >> Here's another: >> >> n = 1 >> print (lambda n=2: n)() >> print n >> >> >> >> Here's a third: >> >> n = 1 >> >> def scope(): >> n = 2 >> print n >> >> scope() >> print n >> >> >> Here's a fourth: >> >> import sys >> n = 1 >> (sys.stdout.write("%d\n" % n) for n in (2,)).next() >> print n >> >> >> In Python 3, this can be written more simply: >> >> n = 1 >> [print(n) for n in (2,)] >> print n >> >> >> >> >>> I have tried to write it, but I don't know how I can create that block >>> because it tells that there is an unexpected indent. >>> >> Functions, closures, classes and modules are scopes in Python. If you >> want a new scope, create one of those. >> >> >> >> -- >> Steven >> > > > Hi Steven, > > Thank you for your message. It is very helpful for me. > I don't fully understand the syntax of all these variants yet, but I can see that there are more scopes in Python than I thought, and this is very good. > > Octavian > > Local scopes like described above by Steven are not constructs that are used that often, not to solve any scoping issue (except for the first example maybe). It's more a demonstration that you can do it with python. The reason is that Python developpers will not put themself in the situation where they need to use a variable 'orange' line 32 and use the same variable 'orange' line 33 to refer to something else. JM From jeanmichel at sequans.com Mon Dec 13 05:51:38 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 13 Dec 2010 11:51:38 +0100 Subject: default argument in method In-Reply-To: References: Message-ID: <4D05FABA.6090302@sequans.com> ernest wrote: > Hi, > > I'd like to have a reference to an instance attribute as > default argument in a method. It doesn't work because > "self" is not defined at the time the method signature is > evaluated. For example: > > class C(object): > def __init__(self): > self.foo = 5 > def m(self, val=self.foo): > return val > > Raises NameError because 'self' is not defined. > The obvious solution is put val=None in the signature > and set val to the appropriate value inside the method > (if val is None: ...), but I wonder if there's another way. > > Cheers, > Ernest > your 'val=None' is jus fine. JM From jeanmichel at sequans.com Mon Dec 13 06:04:57 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 13 Dec 2010 12:04:57 +0100 Subject: while True or while 1 In-Reply-To: <7xbp4q5d1n.fsf@ruckus.brouhaha.com> References: <4D051506.2060403@holdenweb.com> <4d05cb74$0$30003$c3e8da3$5496439d@news.astraweb.com> <7xbp4q5d1n.fsf@ruckus.brouhaha.com> Message-ID: <4D05FDD9.7010004@sequans.com> Paul Rubin wrote: > Steven D'Aprano writes: > >> I'm actually quite fond of the look of "while 1:", and sometimes use it, >> not because it's faster, but just because I like it. >> > > for v in itertools.repeat(True): > ... > > ;-) while '__For_ever___' not in ['nit-picking']: :) JM From felipe.vinturini at gmail.com Mon Dec 13 06:34:00 2010 From: felipe.vinturini at gmail.com (Felipe Vinturini) Date: Mon, 13 Dec 2010 09:34:00 -0200 Subject: Is there any way to SSH from Python ?! In-Reply-To: References: Message-ID: On Mon, Dec 13, 2010 at 3:11 AM, Darshak Bavishi wrote: > > i am trying from last week but no luck !! > > one thing only found that pexpect it not useful in windows > > pls help out of this > > On Mon, Dec 13, 2010 at 10:39 AM, Chris Rebert wrote: > >> On Sun, Dec 12, 2010 at 9:03 PM, Darshak Bavishi >> wrote: >> > Hi Experts, >> > I need to know that is there any way to SSH (From Windows Host) to Unix >> > machine ?! >> > If Yes than How ? >> >> http://www.lag.net/paramiko/ >> >> Did you try googling "ssh python"? >> >> Cheers, >> Chris >> -- >> http://blog.rebertia.com >> > > > > -- > BR > Darshak Bavishi > > -- > http://mail.python.org/mailman/listinfo/python-list > > Hi! Here is a good link about SSH and paramiko: http://jessenoller.com/2009/02/05/ssh-programming-with-paramiko-completely-different/ Regards, Felipe. -------------- next part -------------- An HTML attachment was scrubbed... URL: From bavishi.darshak at gmail.com Mon Dec 13 06:41:45 2010 From: bavishi.darshak at gmail.com (Darshak Bavishi) Date: Mon, 13 Dec 2010 17:11:45 +0530 Subject: Is there any way to SSH from Python ?! In-Reply-To: References: Message-ID: Hi, I have downloaded paramiko and installed it now it needs Pycrypto . So i tried to install pycrypto but its giving error of vcvarsall.bat so from christian suggestion i downloaded MinGW . But i have no idea how to install it in windows machine pls help me out of this!! On Mon, Dec 13, 2010 at 5:04 PM, Felipe Vinturini < felipe.vinturini at gmail.com> wrote: > > > On Mon, Dec 13, 2010 at 3:11 AM, Darshak Bavishi < > bavishi.darshak at gmail.com> wrote: > >> >> i am trying from last week but no luck !! >> >> one thing only found that pexpect it not useful in windows >> >> pls help out of this >> >> On Mon, Dec 13, 2010 at 10:39 AM, Chris Rebert wrote: >> >>> On Sun, Dec 12, 2010 at 9:03 PM, Darshak Bavishi >>> wrote: >>> > Hi Experts, >>> > I need to know that is there any way to SSH (From Windows Host) to Unix >>> > machine ?! >>> > If Yes than How ? >>> >>> http://www.lag.net/paramiko/ >>> >>> Did you try googling "ssh python"? >>> >>> Cheers, >>> Chris >>> -- >>> http://blog.rebertia.com >>> >> >> >> >> -- >> BR >> Darshak Bavishi >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > Hi! > > Here is a good link about SSH and paramiko: > http://jessenoller.com/2009/02/05/ssh-programming-with-paramiko-completely-different/ > > Regards, > Felipe. > -- BR Darshak Bavishi -------------- next part -------------- An HTML attachment was scrubbed... URL: From jnoller at gmail.com Mon Dec 13 06:51:46 2010 From: jnoller at gmail.com (Jesse Noller) Date: Mon, 13 Dec 2010 06:51:46 -0500 Subject: PyCon 2011 Registration and Financial aid open and available! Message-ID: Just q From jnoller at gmail.com Mon Dec 13 07:01:23 2010 From: jnoller at gmail.com (Jesse Noller) Date: Mon, 13 Dec 2010 07:01:23 -0500 Subject: PyCon 2011 Registration and Financial aid open and available! Message-ID: [Sorry for that last partial email] I wanted to take a moment and let everyone know that the PyCon 2011 Registration system is now online and accepting registrations for the conference! http://us.pycon.org/2011/tickets/ PyCon 2011 is looking to be the biggest, and most impressive PyCon yet, we've already booked one fantastic keynote speaker, and the program committee is hard at work selecting the talks for the conference - over 200 proposals were submitted! We're filling up the poster sessions, a stunning number of tutorials are being reviewed - this really does look like it's going to be huge. Financial aid is also open and available: http://us.pycon.org/2011/registration/financialaid/ Feel free to reach out to anyone on the PyCon 2011 team to ask any questions you might have. We look forward to seeing you in Atlanta. Jesse Noller PyCon 2011 From lists at cheimes.de Mon Dec 13 07:18:55 2010 From: lists at cheimes.de (Christian Heimes) Date: Mon, 13 Dec 2010 13:18:55 +0100 Subject: Is there any way to SSH from Python ?! In-Reply-To: References: Message-ID: Am 13.12.2010 12:41, schrieb Darshak Bavishi: > Hi, > > I have downloaded paramiko and installed it now it needs Pycrypto . So i > tried to install pycrypto but its giving error of vcvarsall.bat > so from christian suggestion i downloaded MinGW . But i have no idea how to > install it in windows machine Please use the prebuild Windows binaries from Michael Foord. Christian From awilliam at whitemice.org Mon Dec 13 09:04:38 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Mon, 13 Dec 2010 09:04:38 -0500 Subject: class browser In-Reply-To: <0c5c92c8-6a51-4ed3-aa29-cc6a2a40fa77@37g2000prx.googlegroups.com> References: <0c5c92c8-6a51-4ed3-aa29-cc6a2a40fa77@37g2000prx.googlegroups.com> Message-ID: <1292249078.7399.30.camel@linux-yu4c.site> On Sun, 2010-12-12 at 05:01 -0800, rusi wrote: > On Dec 8, 11:24 pm, Adam Tauno Williams > wrote: > > On Wed, 2010-12-08 at 13:18 +0530, Rustom Mody wrote: > > > If I have a medium to large python code base to browse/study, what are > > > the class browsers available? > > Monodevelop has good Python support which includes a working Python > > class browser for Python projects & solutions. > > > Ok downloaded mono. > How do I import an existing project? Just create a new Python project with the root of the project being the root of your existing project; then add the files [because you aren't really importing an existing project - there is no existing project - just a bunch of files and folders]. Monodevelop will create the required solution files for the advanced features. From bavishi.darshak at gmail.com Mon Dec 13 09:14:30 2010 From: bavishi.darshak at gmail.com (Darshak Bavishi) Date: Mon, 13 Dec 2010 19:44:30 +0530 Subject: AttributeError while running ssh (from windows) paramiko need help Message-ID: Hi Experts , while i am running following demo ssh script of paramiko --> *import base64* *import getpass* *import os* *import socket* *import sys* *import traceback* * * *import paramiko* *import interactive* * * * * *# setup logging* *paramiko.util.log_to_file('demo_simple.log')* * * *# get hostname* *username = ''* *if len(sys.argv) > 1:* * hostname = sys.argv[1]* * if hostname.find('@') >= 0:* * username, hostname = hostname.split('@')* *else:* * hostname = raw_input('Hostname: ')* *if len(hostname) == 0:* * print '*** Hostname required.'* * sys.exit(1)* *port = 22* *if hostname.find(':') >= 0:* * hostname, portstr = hostname.split(':')* * port = int(portstr)* * * * * *# get username* *if username == '':* * default_username = getpass.getuser()* * username = raw_input('Username [%s]: ' % default_username)* * if len(username) == 0:* * username = default_username* *password = getpass.getpass('Password for %s@%s: ' % (username, hostname))* * * * * *# get host key, if we know one* *hostkeytype = None* *hostkey = None* *try:* * host_keys = paramiko.util.load_host_keys(os.path.expanduser('~/.ssh/known_hosts'))* *except IOError:* * try:* * # try ~/ssh/ too, because windows can't have a folder named ~/.ssh/ * * host_keys = paramiko.util.load_host_keys(os.path.expanduser('~/ssh/known_hosts'))* * except IOError:* * print '*** Unable to open host keys file'* * host_keys = {}* * * *if host_keys.has_key(hostname):* * hostkeytype = host_keys[hostname].keys()[0]* * hostkey = host_keys[hostname][hostkeytype]* * print 'Using host key of type %s' % hostkeytype* * * * * *# now, connect and use paramiko Transport to negotiate SSH2 across the connection* *try:* * t = paramiko.Transport((hostname, port))* * t.connect(username=username, password=password, hostkey=hostkey)* * chan = t.open_session()* * chan.get_pty()* * chan.invoke_shell()* * print '*** Here we go!'* * print* * interactive.interactive_shell(chan)* * chan.close()* * t.close()* * * *except Exception, e:* * print '*** Caught exception: %s: %s' % (e.__class__, e)* * traceback.print_exc()* * try:* * t.close()* * except:* * pass* * sys.exit(1)* It gives error as follows : *Warning (from warnings module):* * File "C:\Python26\lib\site-packages\Crypto\Hash\SHA.py", line 6* * from sha import ** *DeprecationWarning: the sha module is deprecated; use the hashlib module instead* * * *Warning (from warnings module):* * File "C:\Python26\lib\site-packages\Crypto\Hash\MD5.py", line 6* * from md5 import ** *DeprecationWarning: the md5 module is deprecated; use hashlib instead* *Hostname: 10.135.15.41* *Username [admin]: root* * * *Warning (from warnings module):* * File "C:\Python26\lib\getpass.py", line 88* * return fallback_getpass(prompt, stream)* *GetPassWarning: Can not control echo on the terminal.* *Warning: Password input may be echoed.* *Password for root at 10.135.15.41: alcatel* **** Unable to open host keys file* **** Here we go!* * * *Line-buffered terminal emulation. Press F6 or ^Z to send EOF.* * * * * * * *Last login: Mon Dec 13 19:38:31 2010 from 10.135.19.50* * * * * **** Caught exception: : read* *Traceback (most recent call last):* * File "C:\Python26\paramiko-1.7.4\demos\demo_simple.py", line 90, in * * interactive.interactive_shell(chan)* * File "C:\Python26\paramiko-1.7.4\demos\interactive.py", line 36, in interactive_shell* * windows_shell(chan)* * File "C:\Python26\paramiko-1.7.4\demos\interactive.py", line 91, in windows_shell* * d = sys.stdin.read(1)* * File "C:\Python26\lib\idlelib\rpc.py", line 560, in __getattr__* * raise AttributeError, name* *AttributeError: read* * * * * **** EOF **** * * *Traceback (most recent call last):* * File "C:\Python26\paramiko-1.7.4\demos\demo_simple.py", line 101, in * * sys.exit(1)* *SystemExit: 1* * * *can you tell me what is use of Hostkey and how to overcome this issue?!* -- BR Darshak Bavishi -------------- next part -------------- An HTML attachment was scrubbed... URL: From ss.datics at gmail.com Mon Dec 13 09:44:55 2010 From: ss.datics at gmail.com (SS DATICS) Date: Mon, 13 Dec 2010 22:44:55 +0800 Subject: International Workshop: DATICS-ISPA'11 (EI Indexed) Message-ID: Dear authors, ===================================================================== International Workshop: DATICS-ISPA'11 CALL FOR PAPERS http://datics.nesea-conference.org/datics-ispa2011 Busan, Korea, 26-28 May, 2011. ===================================================================== Aims and Scope of DATICS-ISPA?11 Workshop: DATICS Workshops were initially created by a network of researchers and engineers both from academia and industry in the areas of Design, Analysis and Tools for Integrated Circuits and Systems. Recently, DATICS has been extended to the fields of Communication, Computer Science, Software Engineering and Information Technology. The main target of DATICS-ISPA?11 is to bring together software/hardware engineering researchers, computer scientists, practitioners and people from industry to exchange theories, ideas, techniques and experiences related to all aspects of DATICS. Topics of interest include, but are not limited to, the following: Circuits, Systems and Communications: digital, analog, mixed-signal, VLSI, asynchronous and RF design processor and memory DSP and FPGA/ASIC-based design synthesis and physical design embedded system hardware/software co-design CAD/EDA methodologies and tools statistical timing analysis and low power design methodologies network/system on-a-chip and applications hardware description languages, SystemC and SystemVerilog simulation, verification and test technology semiconductor devices and solid-state circuits fuzzy and neural networks communication signal processing mobile and wireless communications peer-to-peer video streaming and multimedia communications communication channel modeling antenna radio-wave propagation Computer Science, Software Engineering and Information Technology: equivalence checking, model checking, SAT-based methods, compositional methods and probabilistic methods graph theory, process algebras, petri-nets, automaton theory, BDDs and UML formal methods distributed, real-time and hybrid systems reversible computing and biocomputing software architecture and design software testing and analysis software dependability, safety and reliability programming languages, tools and environments face detection and recognition database and data mining image and video processing watermarking artificial intelligence average-case analysis and worst-case analysis design and programming methodologies for network protocols and applications coding, cryptography algorithms and security protocols evolutionary computation numerical algorithms e-commerce Please note that all accepted papers will be included in IEEE Xplore and indexed by EI Compendex. After workshop, several special issues of international journals such as IJDATICS and IJCECS will be arranged for selected papers. For more details about DATICS-ISPA'11, please visit http://datics.nesea-conference.org/datics-ispa2011 From rossgk at gmail.com Mon Dec 13 10:33:07 2010 From: rossgk at gmail.com (Ross) Date: Mon, 13 Dec 2010 07:33:07 -0800 (PST) Subject: unicode compare errors References: <549e0020-e21e-49c5-bc89-21122f9ce0a9@35g2000prb.googlegroups.com> Message-ID: <01f62ebd-f8c6-4765-a363-96da52ccd6d5@y19g2000prb.googlegroups.com> On Dec 10, 4:09?pm, Nobody wrote: > On Fri, 10 Dec 2010 11:51:44 -0800, Ross wrote: > > Since I can't control the encoding of the input file that users > > submit, how to I get past this? ?How do I make such comparisons be > > True? > On Fri, 10 Dec 2010 12:07:19 -0800, Ross wrote: > > I found I could import codecs that allow me to read the file with my > > desired encoding. Huzzah! > > If I'm off-base and kludgey here and should be doing something > > Er, do you know the file's encoding or don't you? Using: > > ? ? aFile = codecs.open(thisFile, encoding='utf-8') > > is telling Python that the file /is/ in utf-8. If it isn't in utf-8, > you'll get decoding errors. > > If you are given a file with no known encoding, then you can't reliably > determine what /characters/ it contains, and thus can't reliably compare > the contents of the file against strings of characters, only against > strings of bytes. > > About the best you can do is to use an autodetection library such as: > > ? ? ? ?http://chardet.feedparser.org/ That's right I don't know what encoding the user will have used. The use of autodetection sounds good - I'll look into that. Thx. R. From invalid at invalid.invalid Mon Dec 13 10:49:12 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 13 Dec 2010 15:49:12 +0000 (UTC) Subject: while True or while 1 References: <4d05434e$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-12-12, Steven D'Aprano wrote: > With the "while True" idiom in Python 2.x, you can easily exit out of an > infinite loop without using break: > >>>> while True: > ... print "Looping" > ... True = 0 > ... > Looping >>>> >>>> while True: # Execute an infinite loop in 0 seconds. > ... print "Looping" > ... >>>> > > *wink* Sadly, I've seen people do stuff like that in real programs... -- Grant Edwards grant.b.edwards Yow! I was making donuts at and now I'm on a bus! gmail.com From godson.g at gmail.com Mon Dec 13 12:14:27 2010 From: godson.g at gmail.com (Godson Gera) Date: Mon, 13 Dec 2010 22:44:27 +0530 Subject: default argument in method In-Reply-To: References: Message-ID: On Sun, Dec 12, 2010 at 5:05 PM, ernest wrote: > Hi, > > I'd like to have a reference to an instance attribute as > default argument in a method. It doesn't work because > "self" is not defined at the time the method signature is > evaluated. For example: > > class C(object): > def __init__(self): > self.foo = 5 > def m(self, val=self.foo): > return val > > Raises NameError because 'self' is not defined. > You can defined foo outside the __init__ and can access it inside methods using self.foo class C(object): foo=5 def __init__(self): print self.foo def m(self,val=foo): return val class attributes can be accessed with out self before them in method signatures. However, becareful if you change the value of foo inside any method, the method signature will still hold on to old value. -- Thanks & Regards, Godson Gera Python Consultant India -------------- next part -------------- An HTML attachment was scrubbed... URL: From bblais at bryant.edu Mon Dec 13 12:16:49 2010 From: bblais at bryant.edu (Brian Blais) Date: Mon, 13 Dec 2010 12:16:49 -0500 Subject: packaging and installing Message-ID: <50410C1D-2234-400A-8E1B-F78C4C3AA9D3@bryant.edu> Hello, I was wondering if there is any standard or suggested way of installing packages *without* going to the commandline. I often have students who, from there experience in Windows, have never looked at the commandline before and it is a bit of a challenge to get them to install something (i.e. go to the commandline, cd over to the proper folder, type python setup.py install, etc...). I've never seen a package with something like a "compileme.bat", but was wondering if there is some suggested way of doing this or some reasons *not* to do this. I can always write my own (1-line) .bat file, but I didn't want to reinvent the wheel. Perhaps there is a better way for me to do this, ideally in a platform independent way. thanks, Brian Blais -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais http://bblais.blogspot.com/ From godson.g at gmail.com Mon Dec 13 12:30:25 2010 From: godson.g at gmail.com (Godson Gera) Date: Mon, 13 Dec 2010 23:00:25 +0530 Subject: packaging and installing In-Reply-To: <50410C1D-2234-400A-8E1B-F78C4C3AA9D3@bryant.edu> References: <50410C1D-2234-400A-8E1B-F78C4C3AA9D3@bryant.edu> Message-ID: On Mon, Dec 13, 2010 at 10:46 PM, Brian Blais wrote: > Hello, > > I was wondering if there is any standard or suggested way of installing > packages *without* going to the commandline. I often have students who, > from there experience in Windows, have never looked at the commandline > before and it is a bit of a challenge to get them to install something (i.e. > go to the commandline, cd over to the proper folder, type python setup.py > install, etc...). I've never seen a package with something like a > "compileme.bat", but was wondering if there is some suggested way of doing > this or some reasons *not* to do this. I can always write my own (1-line) > .bat file, but I didn't want to reinvent the wheel. Perhaps there is a > better way for me to do this, ideally in a platform independent way. > You don't even have to write a bat file. Python's distutils package allows you to build exe file which creates generic windows wizard window for installing packages. Take a look at distutils package http://docs.python.org/distutils/builtdist.html -- Thanks & Regards, Godson Gera Asterisk consultant India -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Mon Dec 13 12:45:43 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 13 Dec 2010 12:45:43 -0500 Subject: default argument in method In-Reply-To: References: Message-ID: On 12/13/2010 12:14 PM, Godson Gera wrote: > > > On Sun, Dec 12, 2010 at 5:05 PM, ernest > wrote: > > Hi, > > I'd like to have a reference to an instance attribute as > default argument in a method. It doesn't work because > "self" is not defined at the time the method signature is > evaluated. For example: > > class C(object): > def __init__(self): > self.foo = 5 > def m(self, val=self.foo): > return val > > Raises NameError because 'self' is not defined. > > > You can defined foo outside the __init__ and can access it inside > methods using self.foo > > class C(object): > foo=5 > def __init__(self): > print self.foo > def m(self,val=foo): > return val > > class attributes can be accessed with out self before them in method > signatures. However, becareful if you change the value of foo inside any > method, the method signature will still hold on to old value. > You are, of course, correct. It might be more accurate to say that if C.foo is rebound this does not change the binding of the val default value. "Change the value of foo" could be though to include "mutate a mutable value", but in that case both C.foo and the method's val parameter would still be bound to the same object. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From sridharr at activestate.com Mon Dec 13 13:08:48 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Mon, 13 Dec 2010 10:08:48 -0800 Subject: ANN: ActivePython 2.7.1.3 is now available Message-ID: ActiveState is pleased to announce ActivePython 2.7.1.3, a complete, ready-to-install binary distribution of Python 2.7. http://www.activestate.com/activepython/downloads What's New in ActivePython-2.7.1.3 ================================== *Release date: 6-Dec-2010* New Features & Upgrades ----------------------- - Upgrade to Python 2.7.1 (`release notes `__) - Upgrade to Tcl/Tk 8.5.9 (`changes `_) - Security upgrade to openssl-0.9.8q - [MacOSX] Tkinter now requires ActiveTcl 8.5 64-bit (not Apple's Tcl/Tk 8.5 on OSX) - Upgrade to PyPM 1.2.6; noteworthy changes: - New command 'pypm log' to view log entries for last operation - Faster startup (performance) especially on Windows. - Rewrite of an improved dependency algorithm (#88038) - install/uninstall now accepts the --nodeps option - 'pypm install ' to directly download and install a .pypm file - 'pypm show' improvements - 'pypm show' shows other installed packages depending on the shown package - 'pypm show' accepts --rdepends to show the list of dependents - 'pypm show' shows extra dependencies (for use in the 'install' cmd) - 'pypm show' lists all available versions in the repository - 'pypm freeze' to dump installed packages as requirements (like 'pip freeze') - Support for pip-stye requirements file ('pypm install -r requirements.txt') - Upgraded the following packages: - Distribute-0.6.14 - pip-0.8.2 - SQLAlchemy-0.6.5 - virtualenv-1.5.1 Noteworthy Changes & Bug Fixes ------------------------------ - Bug #87951: Exclude PyPM install db to prevent overwriting user's database. - Bug #87600: create a `idleX.Y` script on unix - [Windows] Installer upgrade: automatically uninstall previous versions - Bug #87783 - [Windows] Renamed "python27.exe" to "python2.7.exe" (Unix like) - [Windows] Include "python2.exe" - PyPM bug fixes: - Bug #88882: Fix pickle incompatability (sqlite) on Python 3.x - Bug #87764: 'pypm upgrade' will not error out for missing packages - Bug #87902: fix infinite loops with cyclic package dependencies (eg: plone) - Bug #88370: Handle file-overwrite conflicts (implement --force) What is ActivePython? ===================== ActivePython is ActiveState's binary distribution of Python. Builds for Windows, Mac OS X, Linux are made freely available. Solaris, HP-UX and AIX builds, and access to older versions are available in ActivePython Business, Enterprise and OEM editions: http://www.activestate.com/python ActivePython includes the Python core and the many core extensions: zlib and bzip2 for data compression, the Berkeley DB (bsddb) and SQLite (sqlite3) database libraries, OpenSSL bindings for HTTPS support, the Tix GUI widgets for Tkinter, ElementTree for XML processing, ctypes (on supported platforms) for low-level library access, and others. The Windows distribution ships with PyWin32 -- a suite of Windows tools developed by Mark Hammond, including bindings to the Win32 API and Windows COM. ActivePython 2.6, 2.7 and 3.1 also include a binary package manager for Python (PyPM) that can be used to install packages much easily. For example: C:\>pypm install mysql-python [...] C:\>python >>> import MySQLdb >>> See this page for full details: http://docs.activestate.com/activepython/2.7/whatsincluded.html As well, ActivePython ships with a wealth of documentation for both new and experienced Python programmers. In addition to the core Python docs, ActivePython includes the "What's New in Python" series, "Dive into Python", the Python FAQs & HOWTOs, and the Python Enhancement Proposals (PEPs). An online version of the docs can be found here: http://docs.activestate.com/activepython/2.7/ We would welcome any and all feedback to: activepython-feedback at activestate.com Please file bugs against ActivePython at: http://bugs.activestate.com/enter_bug.cgi?product=ActivePython Supported Platforms =================== ActivePython is available for the following platforms: - Windows (x86 and x64) - Mac OS X (x86 and x86_64; 10.5+) - Linux (x86 and x86_64) - Solaris/SPARC (32-bit and 64-bit) (Business, Enterprise or OEM edition only) - Solaris/x86 (32-bit) (Business, Enterprise or OEM edition only) - HP-UX/PA-RISC (32-bit) (Business, Enterprise or OEM edition only) - HP-UX/IA-64 (32-bit and 64-bit) (Enterprise or OEM edition only) - AIX/PowerPC (32-bit and 64-bit) (Business, Enterprise or OEM edition only) More information about the Business Edition can be found here: http://www.activestate.com/business-edition Custom builds are available in the Enterprise Edition: http://www.activestate.com/enterprise-edition Thanks, and enjoy! The Python Team -- Sridhar Ratnakumar Python Developer ActiveState, The Dynamic Language Experts sridharr at activestate.com http://www.activestate.com Get insights on Open Source and Dynamic Languages at www.activestate.com/blog From python at bdurham.com Mon Dec 13 13:38:59 2010 From: python at bdurham.com (python at bdurham.com) Date: Mon, 13 Dec 2010 13:38:59 -0500 Subject: ANN: ActivePython 2.7.1.3 is now available In-Reply-To: References: Message-ID: <1292265539.4906.1410124185@webmail.messagingengine.com> Sridhar, Do the Windows versions of ActivePython 2.7.1.3 have different versions of Tcl/Tk, sqlite3(.dll), and/or openssl (_ssl.pyd?) than the python.org builds of Python 2.7.1? Thank you, Malcolm From sridharr at activestate.com Mon Dec 13 13:48:27 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Mon, 13 Dec 2010 10:48:27 -0800 Subject: ANN: ActivePython 2.7.1.3 is now available In-Reply-To: <1292265539.4906.1410124185@webmail.messagingengine.com> References: <1292265539.4906.1410124185@webmail.messagingengine.com> Message-ID: On 2010-12-13, at 10:38 AM, python at bdurham.com wrote: > [SRID] Release notes for 2.7.1.3 [...] > [SRID] - Upgrade to Tcl/Tk 8.5.9 (`changes `_) > Do the Windows versions of ActivePython 2.7.1.3 have different versions > of Tcl/Tk, sqlite3(.dll), and/or openssl (_ssl.pyd?) than the python.org > builds of Python 2.7.1? You can find the versions used in ActivePython here, http://docs.activestate.com/activepython/2.7/whatsincluded.html We generally build with the latest compatible version of extensions (except for Tcl/Tk on 2.5/2.6/3.1 as python.org still uses 8.4) ... but that should not be an issue with 2.7 as I believe that the python.org MSI installer is now using Tcl/Tk 8.5 (albeit with an older patch-level version?) to support the new `ttk` module in 2.7+. Does that answer your query? -srid From chambon.pascal at wanadoo.fr Mon Dec 13 13:53:31 2010 From: chambon.pascal at wanadoo.fr (Pascal Chambon) Date: Mon, 13 Dec 2010 19:53:31 +0100 Subject: Directly calling python's function arguments dispatcher In-Reply-To: References: Message-ID: <4D066BAB.6020707@wanadoo.fr> Le 12/12/2010 23:41, Peter Otten a ?crit : > Pascal Chambon wrote: > > > >> I've encountered several times, when dealing with adaptation of function >> signatures, the need for explicitly resolving complex argument sets into >> a simple variable mapping. Explanations. >> >> >> Consider that function: >> >> def foo(a1, a2, *args, **kwargs): >> pass >> >> calling foo(1, a2=2, a3=3) >> >> will map these arguments to local variables like these: >> { >> 'a1': 1, >> 'a2': 2, >> 'args': tuple(), >> 'kwarg's: {'a3': 3} >> } >> >> That's a quite complex resolution mechanism, which must handle >> positional and keyword arguments, and deal with both collision and >> missing argument cases. >> > >> Is that routine exposed to python, somewhere ? Does anybody know a >> working implementation here or there ? >> > http://docs.python.org/library/inspect.html#inspect.getcallargs > > Too sweeeeeeeeeet \o/ Thanks a lot, regards, Pakal From arnodel at gmail.com Mon Dec 13 14:09:22 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Mon, 13 Dec 2010 19:09:22 +0000 Subject: Exception handling in Python 3.x References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> <7xmxoi8v0b.fsf@ruckus.brouhaha.com> Message-ID: <87wrnd7an1.fsf@gmail.com> Paul Rubin writes: > Steven D'Aprano writes: >> Apart from this horrible idiom: >> >> def func(iterable): >> it = iter(iterable) >> failed = False >> try: >> x = next(it) >> except StopIteration: >> failed = True >> if failed: >> raise ValueError("can't process empty iterable") >> print(x) >> >> >> or similar, is there really no way to avoid these chained exceptions? > > Seems like yet another example of people doing messy things with > exceptions that can easily be done with iterators and itertools: > > from itertools import islice > > def func(iterable): > xs = list(islice(iter(iterable), 1)) > if len(xs) == 0: > raise ValueError(...) > print xs[0] > > It's really unfortunate, though, that Python 3 didn't offer a way to > peek at the next element of an iterable and test emptiness directly. I missed the start of this discussion but there are two simpler ways: def func(iterable): for x in iterable: print(x) return raise ValueError("... empty iterable") Or using 3.x's next's optional second argument: _nonext=object() def func(iterable): x = next(iter(iterable), _nonext) if x is _nonext: raise ValueError("... empty iterable") print(x) -- Arnaud From python at bdurham.com Mon Dec 13 14:16:33 2010 From: python at bdurham.com (python at bdurham.com) Date: Mon, 13 Dec 2010 14:16:33 -0500 Subject: ANN: ActivePython 2.7.1.3 is now available In-Reply-To: References: <1292265539.4906.1410124185@webmail.messagingengine.com> Message-ID: <1292267793.18518.1410132979@webmail.messagingengine.com> Sridhar, > You can find the versions used in ActivePython here, > http://docs.activestate.com/activepython/2.7/whatsincluded.html Thank you - that page answered my questions. Malcolm From tjreedy at udel.edu Mon Dec 13 14:50:05 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 13 Dec 2010 14:50:05 -0500 Subject: ANN: ActivePython 2.7.1.3 is now available In-Reply-To: References: <1292265539.4906.1410124185@webmail.messagingengine.com> Message-ID: On 12/13/2010 1:48 PM, Sridhar Ratnakumar wrote: > We generally build with the latest compatible version of extensions > (except for Tcl/Tk on 2.5/2.6/3.1 as python.org still uses 8.4) ... The PSF 3.1 Windows installer ships with tcl/tk 8.5 and ttk support. You ought to too. > but that should not be an issue with 2.7 as I believe that the > python.org MSI installer is now using Tcl/Tk 8.5 (albeit with an > older patch-level version?) to support the new `ttk` module in 2.7+. For 3.1.3 and 3.2, the tcl/tk85.libs are dated 8/28/2010. Don't know what that means though. Terry Jan Reedy From Rob.Richardson at rad-con.com Mon Dec 13 14:56:02 2010 From: Rob.Richardson at rad-con.com (Rob Richardson) Date: Mon, 13 Dec 2010 14:56:02 -0500 Subject: Exception handling in Python 3.x In-Reply-To: <87wrnd7an1.fsf@gmail.com> Message-ID: <04A6DB42D2BA534FAC77B90562A6A03D01689233@server.rad-con.local> Arnaud, Wouldn't your first suggestion exit after the first element in iterable? And would your second suggestion throw an exception after normal processing of all elements in the interator? RobR -----Original Message----- I missed the start of this discussion but there are two simpler ways: def func(iterable): for x in iterable: print(x) return raise ValueError("... empty iterable") Or using 3.x's next's optional second argument: _nonext=object() def func(iterable): x = next(iter(iterable), _nonext) if x is _nonext: raise ValueError("... empty iterable") print(x) -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list From arnodel at gmail.com Mon Dec 13 15:19:27 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Mon, 13 Dec 2010 20:19:27 +0000 Subject: Request for feedback on API design References: <4d0169e2$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87sjy177e8.fsf@gmail.com> Steven D'Aprano writes: > I am soliciting feedback regarding the API of my statistics module: > > http://code.google.com/p/pycalcstats/ > > > Specifically the following couple of issues: > > (1) Multivariate statistics such as covariance have two obvious APIs: > > A pass the X and Y values as two separate iterable arguments, e.g.: > cov([1, 2, 3], [4, 5, 6]) > > B pass the X and Y values as a single iterable of tuples, e.g.: > cov([(1, 4), (2, 5), (3, 6)] > > I currently support both APIs. Do people prefer one, or the other, or > both? If there is a clear preference for one over the other, I may drop > support for the other. > I don't have an informed opinion on this. > (2) Statistics text books often give formulae in terms of sums and > differences such as > > Sxx = n*?(x**2) - (?x)**2 Interestingly, your Sxx is closely related to the variance: if x is a list of n numbers then Sxx == (n**2)*var(x) And more generally if x and y have the same length n, then Sxy (*) is related to the covariance Sxy == (n**2)*cov(x, y) So if you have a variance and covariance function, it would be redundant to include Sxx and Sxy. Another argument against including Sxx & co is that their definition is not universally agreed upon. For example, I have seen Sxx = ?(x**2) - (?x)**2/n HTH -- Arnaud (*) Here I take Sxy to be n*?(xy) - (?x)(?y), generalising from your definition of Sxx. From arnodel at gmail.com Mon Dec 13 15:39:19 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Mon, 13 Dec 2010 20:39:19 +0000 Subject: Exception handling in Python 3.x References: Message-ID: <87oc8p76h4.fsf@gmail.com> "Rob Richardson" writes: You shouldn't top-post! > Arnaud, > > Wouldn't your first suggestion exit after the first element in iterable? Yes, after printing that element, which is what the code I quoted did. > And would your second suggestion throw an exception after normal > processing of all elements in the interator? No. It would have the same behaviour as the first one. > RobR > > -----Original Message----- > > > I missed the start of this discussion but there are two simpler ways: > > def func(iterable): > for x in iterable: > print(x) > return > raise ValueError("... empty iterable") > > Or using 3.x's next's optional second argument: > > _nonext=object() > def func(iterable): > x = next(iter(iterable), _nonext) > if x is _nonext: > raise ValueError("... empty iterable") > print(x) > > -- > Arnaud -- Arnaud From ethan at stoneleaf.us Mon Dec 13 15:44:28 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 13 Dec 2010 12:44:28 -0800 Subject: Exception handling in Python 3.x In-Reply-To: <04A6DB42D2BA534FAC77B90562A6A03D01689233@server.rad-con.local> References: <04A6DB42D2BA534FAC77B90562A6A03D01689233@server.rad-con.local> Message-ID: <4D0685AC.6070907@stoneleaf.us> Please don't top-post. Rob Richardson wrote: >> -----Original Message----- >> >> >> I missed the start of this discussion but there are two simpler ways: >> >> def func(iterable): >> for x in iterable: >> print(x) >> return >> raise ValueError("... empty iterable") >> >> Or using 3.x's next's optional second argument: >> >> _nonext=object() >> def func(iterable): >> x = next(iter(iterable), _nonext) >> if x is _nonext: >> raise ValueError("... empty iterable") >> print(x) > Arnaud, > > Wouldn't your first suggestion exit after the first element in > iterable? No, it hit's return instead. > And would your second suggestion throw an exception after normal > processing of all elements in the interator? Looks like the second solution doesn't process the entire iterable, just it's first element. ~Ethan~ From ethan at stoneleaf.us Mon Dec 13 15:46:31 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 13 Dec 2010 12:46:31 -0800 Subject: Exception handling in Python 3.x In-Reply-To: <87wrnd7an1.fsf@gmail.com> References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> <7xmxoi8v0b.fsf@ruckus.brouhaha.com> <87wrnd7an1.fsf@gmail.com> Message-ID: <4D068627.3030705@stoneleaf.us> Arnaud Delobelle wrote: > > I missed the start of this discussion but there are two simpler ways: > > def func(iterable): > for x in iterable: > print(x) > return > raise ValueError("... empty iterable") For the immediate case this is a cool solution. Unfortunately, it doesn't fix the unwanted nesting of exceptions problem. ~Ethan~ From ethan at stoneleaf.us Mon Dec 13 16:19:44 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 13 Dec 2010 13:19:44 -0800 Subject: Exception handling in Python 3.x In-Reply-To: <4D0685AC.6070907@stoneleaf.us> References: <04A6DB42D2BA534FAC77B90562A6A03D01689233@server.rad-con.local> <4D0685AC.6070907@stoneleaf.us> Message-ID: <4D068DF0.3000806@stoneleaf.us> Ethan Furman wrote: > Please don't top-post. > > Rob Richardson wrote: > >>> -----Original Message----- >>> >>> >>> I missed the start of this discussion but there are two simpler ways: >>> >>> def func(iterable): >>> for x in iterable: >>> print(x) >>> return >>> raise ValueError("... empty iterable") >>> >>> Or using 3.x's next's optional second argument: >>> >>> _nonext=object() >>> def func(iterable): >>> x = next(iter(iterable), _nonext) >>> if x is _nonext: >>> raise ValueError("... empty iterable") >>> print(x) > > > > Arnaud, > > > > Wouldn't your first suggestion exit after the first element in > > iterable? > > No, it hit's return instead. Doh -- Yes, it does. It seems both solutions only get the first element, not all elements in the iterator... Maybe this instead: def func(iterable): for x in iterable: break else: raise ValueError("... empty iterable") for xx in chain((x, ), iterable): process(xx) Can't say as I care for this -- better to fix the unwanted nesting in the tracebacks from raise. ~Ethan~ From godson.g at gmail.com Mon Dec 13 16:20:40 2010 From: godson.g at gmail.com (Godson Gera) Date: Tue, 14 Dec 2010 02:50:40 +0530 Subject: Is there any way to SSH from Python ?! In-Reply-To: References: Message-ID: On Mon, Dec 13, 2010 at 10:33 AM, Darshak Bavishi wrote: > Hi Experts, > > I need to know that is there any way to SSH (From Windows Host) to Unix > machine ?! > > If Yes than How ? > > Because when i use telenet it not showing the no result !! As earlier it > was suggested that i should try with exit first and than read_all() > but still issue persist and getting hang > > import getpass > import sys > import telnetlib > import time > HOST = "*.*.*.*" > #user = raw_input("Enter your remote account: ") > #password = getpass.getpass() > user = "Darshak2" > password = "****" > tn = telnetlib.Telnet(HOST , 5400) > print "1" > tn.read_until("login:" , 5) > print "2" > tn.write(user + "\n") > print "3" > if password: > tn.read_until("Password: ") > tn.write(password + "\n") > > print "4" > tn.write("set alarm = off" + "\n") > tn.write("set event = off" + "\n") > print "5" > tn.write("Cd > /Office-Parameters/Mobility-Config-Parameters/Subscriber-Query-by-IMSI-MSISDN-or-IMEI" > + "\n") > print "6" > tn.write("\n") > tn.write("\n") > tn.write("vlrsubquery msisdn=***" + "\n") > tn.write("\n") > tn.write("exit" + "\n") > print tn.read_all() > tn.close() > > -- > BR > Darshak Bavishi > > -- > http://mail.python.org/mailman/listinfo/python-list > > you can try read_very_eager() which won't block. Twisted has complete support for SSH check it out http://twistedmatrix.com -- Thanks & Regards, Godson Gera Asterisk Consultant India -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Mon Dec 13 16:23:09 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 13 Dec 2010 13:23:09 -0800 Subject: Exception handling in Python 3.x In-Reply-To: <4D068627.3030705@stoneleaf.us> References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> <7xmxoi8v0b.fsf@ruckus.brouhaha.com> <87wrnd7an1.fsf@gmail.com> <4D068627.3030705@stoneleaf.us> Message-ID: <4D068EBD.2040102@stoneleaf.us> Ethan Furman wrote: > Arnaud Delobelle wrote: >> >> I missed the start of this discussion but there are two simpler ways: >> >> def func(iterable): >> for x in iterable: >> print(x) >> return >> raise ValueError("... empty iterable") > > > For the immediate case this is a cool solution. Drat -- I have to take that back -- the OP stated: > The intention is: > > * detect an empty iterator by catching StopIteration; > * if the iterator is empty, raise a ValueError; > * otherwise process the iterator. Presumably, the print(x) would be replaced with code that processed the entire iterable (including x, of course), and not just its first element. ~Ethan~ From sridharr at activestate.com Mon Dec 13 16:23:59 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Mon, 13 Dec 2010 13:23:59 -0800 Subject: ANN: ActivePython 2.7.1.3 is now available In-Reply-To: References: <1292265539.4906.1410124185@webmail.messagingengine.com> Message-ID: <8D0BABA0-44C4-45C9-BAC6-28F9BD06B340@activestate.com> On 2010-12-13, at 11:50 AM, Terry Reedy wrote: > On 12/13/2010 1:48 PM, Sridhar Ratnakumar wrote: > >> We generally build with the latest compatible version of extensions >> (except for Tcl/Tk on 2.5/2.6/3.1 as python.org still uses 8.4) ... > > The PSF 3.1 Windows installer ships with tcl/tk 8.5 and ttk support. > You ought to too. ActivePython (APy) 2.5+/3.1+ already use Tcl/Tk 8.5 ... I was referring to the PSF installers (hence the mismatch in versions between APy and PSF). Maybe that was changed in 3.1.3. >> but that should not be an issue with 2.7 as I believe that the >> python.org MSI installer is now using Tcl/Tk 8.5 (albeit with an >> older patch-level version?) to support the new `ttk` module in 2.7+. > > For 3.1.3 and 3.2, the tcl/tk85.libs are dated 8/28/2010. Don't know what that means though. I did this for ActivePython 2.7, >>> import Tkinter >>> root = Tkinter.Tk() >>> root.tk.eval('info patchlevel') '8.5.9' >>> -srid From arnodel at gmail.com Mon Dec 13 16:43:31 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Mon, 13 Dec 2010 21:43:31 +0000 Subject: Exception handling in Python 3.x References: <4cf8eada$0$30003$c3e8da3$5496439d@news.astraweb.com> <7xmxoi8v0b.fsf@ruckus.brouhaha.com> <87wrnd7an1.fsf@gmail.com> <4D068627.3030705@stoneleaf.us> Message-ID: <87k4jd73i4.fsf@gmail.com> Ethan Furman writes: > Ethan Furman wrote: >> Arnaud Delobelle wrote: >>> >>> I missed the start of this discussion but there are two simpler ways: >>> >>> def func(iterable): >>> for x in iterable: >>> print(x) >>> return >>> raise ValueError("... empty iterable") >> >> >> For the immediate case this is a cool solution. > > > Drat -- I have to take that back -- the OP stated: > >> The intention is: >> >> * detect an empty iterator by catching StopIteration; >> * if the iterator is empty, raise a ValueError; >> * otherwise process the iterator. > > > Presumably, the print(x) would be replaced with code that processed > the entire iterable (including x, of course), and not just its first > element. As I had stated before, I didn't where the discussion started from. I replied to code posted by Steven D'Aprano and Paul Rubin. My code snippet was equivalent in functionality to theirs, only a little simpler. Now if one wants to raise an exception if an iterator is empty, else process it somehow, it must mean that the iterator needs to have at least one element for the processing to be meaningful and so it can be thought of as a function of one element and of one iterator: process(first, others) which never needs to raise an exception (at least related to the number of items in the iterator). Therefore you can write your function as follows: def func(iterable): iterator = iter(iterable) for first in iterable: return process(first, iterator) else: raise ValueError("need non-empty iterable") -- Arnaud From ethan at stoneleaf.us Mon Dec 13 16:44:00 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 13 Dec 2010 13:44:00 -0800 Subject: Request for feedback on API design In-Reply-To: <4d0169e2$0$30002$c3e8da3$5496439d@news.astraweb.com> References: <4d0169e2$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4D0693A0.3030707@stoneleaf.us> Steven D'Aprano wrote: > I am soliciting feedback regarding the API of my statistics module: > > http://code.google.com/p/pycalcstats/ > > > Specifically the following couple of issues: > > (1) Multivariate statistics such as covariance have two obvious APIs: > > A pass the X and Y values as two separate iterable arguments, e.g.: > cov([1, 2, 3], [4, 5, 6]) > > B pass the X and Y values as a single iterable of tuples, e.g.: > cov([(1, 4), (2, 5), (3, 6)] > > I currently support both APIs. Do people prefer one, or the other, or > both? If there is a clear preference for one over the other, I may drop > support for the other. > Don't currently need/use stats, but B seems clearer to me. ~Ethan~ From news1234 at free.fr Mon Dec 13 16:51:35 2010 From: news1234 at free.fr (News123) Date: Mon, 13 Dec 2010 22:51:35 +0100 Subject: run a function in another processor in python In-Reply-To: References: Message-ID: <4d069567$0$28575$426a34cc@news.free.fr> On 12/09/2010 10:54 AM, Astan Chee wrote: > Hi, > I've got a python script that calls a function many times with various > arguments and returns a result. What I'm trying to do is run this > function each on different processors and compile the result at the > end based on the function result. The script looks something like > this: > > You could look at the multiprocessing module of pythonhttp://docs.python.org/library/multiprocessing.html From rhodri at wildebst.demon.co.uk Mon Dec 13 17:33:42 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Mon, 13 Dec 2010 22:33:42 -0000 Subject: Sage's Python References: Message-ID: On Fri, 10 Dec 2010 17:11:55 -0000, Akand Islam wrote: > In my system (Ubuntu 10.04) there are sage-4.6, python 2.6.5, tk8.5- > dev installed. When I give command from terminal "sage -f > python-2.6.5.p8" to get sage's python it shows following message: > > No command 'sage' found, did you mean: > Command 'save' from package 'atfs' (universe) > Command 'page' from package 'tcllib' (universe) > sage: command not found > > How can I get Sage's python to be worked so that I can import sage.all > in python shell? The fact that you have no executable called "sage" suggests that you haven't actually installed it yet. Check the Sage website, which has plenty of documentation, and try to figure out where you left the path on whichever method you used. -- Rhodri James *-* Wildebeest Herder to the Masses From kikkocristian at gmail.com Mon Dec 13 17:38:07 2010 From: kikkocristian at gmail.com (Cristian Consonni) Date: Mon, 13 Dec 2010 23:38:07 +0100 Subject: "Download/windows" site page Message-ID: Dear all, I'm not sure this is the right place to point this out, but on this page: http://www.python.org/download/windows/ It is not mentioned "Windows 7". Is there some problem with 7 or it is simply an omission? A friend of mine is refusing to install python on his machine because "it does not say it is compatible with Windows 7" (sic). So, may somebody fix that? Thanks in advance. Cristian From martin at v.loewis.de Mon Dec 13 17:56:23 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Mon, 13 Dec 2010 23:56:23 +0100 Subject: "Download/windows" site page In-Reply-To: References: Message-ID: <4D06A497.2040704@v.loewis.de> Am 13.12.2010 23:38, schrieb Cristian Consonni: > Dear all, > > I'm not sure this is the right place to point this out, but on this page: > > http://www.python.org/download/windows/ > > It is not mentioned "Windows 7". > > Is there some problem with 7 or it is simply an omission? It's simply an omission. You'll notice that Windows 2003 and Windows 2008, as well as Windows 2003 R2 and Windows 2008R2 are omitted as well. Likely, Python also works on Windows Media Center Edition, which is also omitted. > So, may somebody fix that? I'd rather not fix it by adding all product names that Microsoft has used for Windows. How about "Microsoft Windows (XP and later releases)"? Regards, Martin From martin at v.loewis.de Mon Dec 13 17:56:23 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Mon, 13 Dec 2010 23:56:23 +0100 Subject: "Download/windows" site page In-Reply-To: References: Message-ID: <4D06A497.2040704@v.loewis.de> Am 13.12.2010 23:38, schrieb Cristian Consonni: > Dear all, > > I'm not sure this is the right place to point this out, but on this page: > > http://www.python.org/download/windows/ > > It is not mentioned "Windows 7". > > Is there some problem with 7 or it is simply an omission? It's simply an omission. You'll notice that Windows 2003 and Windows 2008, as well as Windows 2003 R2 and Windows 2008R2 are omitted as well. Likely, Python also works on Windows Media Center Edition, which is also omitted. > So, may somebody fix that? I'd rather not fix it by adding all product names that Microsoft has used for Windows. How about "Microsoft Windows (XP and later releases)"? Regards, Martin From mpnordland at gmail.com Mon Dec 13 18:04:22 2010 From: mpnordland at gmail.com (mpnordland) Date: Mon, 13 Dec 2010 15:04:22 -0800 (PST) Subject: Catching user switching and getting current active user from root on linux References: <1a9bdbd4-2997-4e0f-a24f-cd148247e312@r40g2000prh.googlegroups.com> <8739qhs6dz.fsf.mdw@metalzone.distorted.org.uk> <797ba948-c608-4ed5-b2eb-25177932da91@o4g2000yqd.googlegroups.com> <4d04117b$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: <51d9390d-be72-49fe-a63b-5a05832c53e8@fu15g2000vbb.googlegroups.com> I think I do understand multiuser systems, although I'm sorry I did not make my self clear. Yes, I understand that there can be multiple people logged in, and yes if you really wanted to, you could login as yourself as many times as you want. This is not a server based program, it is intended for use in a normal environment. The people using it will probably not be logging in multiple times as themselves, or someone else. The problem I have is I want monitor what sites the user visits, I need to know what sites were accessed by which user. So, a way to find which user is requesting what url is what I want. Have I passed the Turing test? From emekamicro at gmail.com Mon Dec 13 18:06:05 2010 From: emekamicro at gmail.com (Emeka) Date: Tue, 14 Dec 2010 00:06:05 +0100 Subject: Tkinter's unbind method Message-ID: Hello All I have an uncompleted version of a game http://pastebin.com/gkhTaYPZ I am trying to code.... I have struggled to make method unbind work. But it has refused to listen to me. Could someone come to my help? Regards, Emeka http://pastebin.com/gkhTaYPZ -- *Satajanus Nig. Ltd * -------------- next part -------------- An HTML attachment was scrubbed... URL: From kikkocristian at gmail.com Mon Dec 13 18:15:33 2010 From: kikkocristian at gmail.com (Cristian Consonni) Date: Tue, 14 Dec 2010 00:15:33 +0100 Subject: "Download/windows" site page In-Reply-To: <4D06A497.2040704@v.loewis.de> References: <4D06A497.2040704@v.loewis.de> Message-ID: 2010/12/13 Martin v. Loewis : [...] >> It is not mentioned "Windows 7". >> >> Is there some problem with 7 or it is simply an omission? > > It's simply an omission. You'll notice that Windows 2003 and Windows > 2008, as well as Windows 2003 R2 and Windows 2008R2 are omitted as > well. Likely, Python also works on Windows Media Center Edition, which > is also omitted. > >> So, may somebody fix that? > > I'd rather not fix it by adding all product names that Microsoft has > used for Windows. How about "Microsoft Windows (XP and later releases)"? Sounds as a reasonable solution to me. Thank you. Cristian From javiervandam at gmail.com Mon Dec 13 18:29:52 2010 From: javiervandam at gmail.com (javivd) Date: Mon, 13 Dec 2010 15:29:52 -0800 (PST) Subject: Reading by positions plain text files References: <39a07597-02b9-4ef8-9ca9-93e2d2425e66@p7g2000prb.googlegroups.com> Message-ID: <35a7413f-47c3-439d-b480-4cc905e49c40@fu15g2000vbb.googlegroups.com> On Dec 12, 11:21?pm, Dennis Lee Bieber wrote: > On Sun, 12 Dec 2010 07:02:13 -0800 (PST), javivd > declaimed the following in > gmane.comp.python.general: > > > > > f = open(r'c:c:\somefile.txt', 'w') > > > f.write('0123456789\n0123456789\n0123456789') > > ? ? ? ? Not the most explanatory sample data... It would be better if the > records had different contents. > > > f.close() > > > f = open(r'c:\somefile.txt', 'r') > > > for line in f: > > ? ? ? ? Here you extract one "line" from the file > > > ? ? f.seek(3,0) > > ? ? print f.read(1) #just to know if its printing the rigth column > > ? ? ? ? And here you ignored the entire line you read, seeking to the fourth > byte from the beginning of the file, andreadingjust one byte from it. > > ? ? ? ? I have no idea of how seek()/read() behaves relative to line > iteration in the for loop... Given the small size of the test data set > it is quite likely that the first "for line in f" resulted in the entire > file being read into a buffer, and that buffer scanned to find the line > ending and return the data preceding it; then the buffer position is set > to after that line ending so the next "for line" continues from that > point. > > ? ? ? ? But in a situation with a large data set, or an unbuffered I/O > system, the seek()/read() could easily result in resetting the file > position used by the "for line", so that the second call returns > "456789\n"... And all subsequent calls too, resulting in an infinite > loop. > > ? ? ? ? Presuming the assignment requires pulling multiple selected fields > from individual records, where each record is of the same > format/spacing, AND that the field selection can not be preprogrammed... > > Sample data file (use fixed width font to view): > -=-=-=-=-=- > Wulfraed ? ? ? 09Ranger ?1915 > Bask Euren ? ? 13Cleric ?1511 > Aethelwulf ? ? 07Mage ? ?0908 > Cwiculf ? ? ? ?08Mage ? ?1008 > -=-=-=-=-=- > > Sample format definition file: > -=-=-=-=-=- > Name ? ?0-14 > Level ? 15-16 > Class ? 17-24 > THAC0 ? 25-26 > Armor ? 27-28 > -=-=-=-=-=- > > Code to process (Python 2.5, with minimal error handling): > -=-=-=-=-=- > > class Extractor(object): > ? ? def __init__(self, formatFile): > ? ? ? ? ff = open(formatFile, "r") > ? ? ? ? self._format = {} > ? ? ? ? self._length = 0 > ? ? ? ? for line in ff: > ? ? ? ? ? ? form = line.split("\t") #file must be tab separated > ? ? ? ? ? ? if len(form) != 2: > ? ? ? ? ? ? ? ? print "Invalid file format definition: %s" % line > ? ? ? ? ? ? ? ? continue > ? ? ? ? ? ? name = form[0] > ? ? ? ? ? ? columns = form[1].split("-") > ? ? ? ? ? ? if len(columns) == 1: ? #single column definition > ? ? ? ? ? ? ? ? start = int(columns[0]) > ? ? ? ? ? ? ? ? end = start > ? ? ? ? ? ? elif len(columns) == 2: > ? ? ? ? ? ? ? ? start = int(columns[0]) > ? ? ? ? ? ? ? ? end = int(columns[1]) > ? ? ? ? ? ? else: > ? ? ? ? ? ? ? ? print "Invalid column definition: %s" % form[1] > ? ? ? ? ? ? ? ? continue > ? ? ? ? ? ? self._format[name] = (start, end) > ? ? ? ? ? ? self._length = max(self._length, end) > ? ? ? ? ff.close() > > ? ? def __call__(self, line): > ? ? ? ? data = {} > ? ? ? ? if len(line) < self._length: > ? ? ? ? ? ? print "Data line is too short for required format: ignored" > ? ? ? ? else: > ? ? ? ? ? ? for (name, (start, end)) in self._format.items(): > ? ? ? ? ? ? ? ? data[name] = line[start:end+1] > ? ? ? ? return data > > if __name__ == "__main__": > ? ? FORMATFILE = "SampleFormat.tsv" > ? ? DATAFILE = "SampleData.txt" > > ? ? characterExtractor = Extractor(FORMATFILE) > > ? ? df = open(DATAFILE, "r") > ? ? for line in df: > ? ? ? ? fields = characterExtractor(line) > ? ? ? ? for (name, value) in fields.items(): > ? ? ? ? ? ? print "Field name: '%s'\t\tvalue: '%s'" % (name, value) > ? ? ? ? print > > ? ? df.close() > -=-=-=-=-=- > > Output from running above code: > -=-=-=-=-=- > Field name: 'Armor' ? ? ? ? ? ? value: '15' > Field name: 'THAC0' ? ? ? ? ? ? value: '19' > Field name: 'Level' ? ? ? ? ? ? value: '09' > Field name: 'Class' ? ? ? ? ? ? value: 'Ranger ?' > Field name: 'Name' ? ? ? ? ? ? ?value: 'Wulfraed ? ? ? ' > > Field name: 'Armor' ? ? ? ? ? ? value: '11' > Field name: 'THAC0' ? ? ? ? ? ? value: '15' > Field name: 'Level' ? ? ? ? ? ? value: '13' > Field name: 'Class' ? ? ? ? ? ? value: 'Cleric ?' > Field name: 'Name' ? ? ? ? ? ? ?value: 'Bask Euren ? ? ' > > Field name: 'Armor' ? ? ? ? ? ? value: '08' > Field name: 'THAC0' ? ? ? ? ? ? value: '09' > Field name: 'Level' ? ? ? ? ? ? value: '07' > Field name: 'Class' ? ? ? ? ? ? value: 'Mage ? ?' > Field name: 'Name' ? ? ? ? ? ? ?value: 'Aethelwulf ? ? ' > > Field name: 'Armor' ? ? ? ? ? ? value: '08' > Field name: 'THAC0' ? ? ? ? ? ? value: '10' > Field name: 'Level' ? ? ? ? ? ? value: '08' > Field name: 'Class' ? ? ? ? ? ? value: 'Mage ? ?' > Field name: 'Name' ? ? ? ? ? ? ?value: 'Cwiculf ? ? ? ?' > -=-=-=-=-=- > > ? ? ? ? Note that string fields have not been trimmed, also numeric fields > are still intextformat... The format definition file would need to be > expanded to include a "string", "integer", "float" (and "Boolean"?) code > in order for the extractor to do proper type conversions. > > -- > ? ? ? ? Wulfraed ? ? ? ? ? ? ? ? Dennis Lee Bieber ? ? ? ? AF6VN > ? ? ? ? wlfr... at ix.netcom.com ? ?HTTP://wlfraed.home.netcom.com/ Clearly it's working. Altough, this code is beyond my python knowledge (i don't get along with classes, maybe it's a good moment to learn about them...) but i'll dig into it. Thanks a lot! It really helps... J From chris at simplistix.co.uk Mon Dec 13 18:30:17 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 13 Dec 2010 23:30:17 +0000 Subject: find memory leaks in running program In-Reply-To: <391F8BF8-8FF5-42B8-8F10-C6F0428CA27B@gmail.com> References: <391F8BF8-8FF5-42B8-8F10-C6F0428CA27B@gmail.com> Message-ID: <4D06AC89.1020903@simplistix.co.uk> On 07/12/2010 16:51, Marco Hornung wrote: > 1. What are the best tools to analyze pythons memory stack, while it is running? Look for the heapy stuff in the guppy package. > 2. Is there a possibility to analyze the memory stack of a program with external programs? (without to change the source code - I am only interested in the object size) heapy is your best bet. > 3. Can I sort of "break" into the memory to see what objects consume how much memory? The GC module might help here too, but really, heapy is what you want. cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From chris at simplistix.co.uk Mon Dec 13 18:34:01 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 13 Dec 2010 23:34:01 +0000 Subject: Added Python, WSGI to XAMPP In-Reply-To: <4D014A3D.7020101@verizon.net> References: <4CFA4305.10004@it.uu.se> <4CFD6825.9020200@simplistix.co.uk> <4CFD8B29.3020006@verizon.net> <4D014A3D.7020101@verizon.net> Message-ID: <4D06AD69.4030302@simplistix.co.uk> On 09/12/2010 21:29, Gerry Reno wrote: > How-To: Add VirtualEnv and Pylons (WSGI framework) to XAMPP > You mean Pyramid, right? ;-) Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From pavlovevidence at gmail.com Mon Dec 13 18:40:47 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 13 Dec 2010 15:40:47 -0800 (PST) Subject: Catching user switching and getting current active user from root on linux References: <1a9bdbd4-2997-4e0f-a24f-cd148247e312@r40g2000prh.googlegroups.com> <8739qhs6dz.fsf.mdw@metalzone.distorted.org.uk> <797ba948-c608-4ed5-b2eb-25177932da91@o4g2000yqd.googlegroups.com> <4d04117b$0$30000$c3e8da3$5496439d@news.astraweb.com> <51d9390d-be72-49fe-a63b-5a05832c53e8@fu15g2000vbb.googlegroups.com> Message-ID: On Dec 13, 3:04?pm, mpnordland wrote: > I think I do understand multiuser systems, although I'm sorry I did > not make my self clear. Yes, I understand that there can be multiple > people logged in, and yes if you really wanted to, you could login as > yourself as many times as you want. This is not a server based > program, it is intended for use in a normal environment. The people > using it will probably not be logging in multiple times as themselves, > or someone else. The problem I have is I want monitor what sites the > user visits, I need to know what sites were accessed by which user. > So, a way to find which user is requesting what url is what I want. > Have I passed the Turing test? Install a web proxy. In a pinch you can stat /dev/console to see who the owner is, which I think was what they did last time I looked. If you're ambitious there's some stuff you can do with netfilter to attach user ids to network packets which you might be able to read with your logging software. How are you logging web site accesses anyway? That would be helpful to know. Carl Banks From chris at simplistix.co.uk Mon Dec 13 19:12:33 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Tue, 14 Dec 2010 00:12:33 +0000 Subject: Added Python, WSGI to XAMPP In-Reply-To: <4D06B6D1.6080208@verizon.net> References: <4CFA4305.10004@it.uu.se> <4CFD6825.9020200@simplistix.co.uk> <4CFD8B29.3020006@verizon.net> <4D014A3D.7020101@verizon.net> <4D06AD69.4030302@simplistix.co.uk> <4D06B6D1.6080208@verizon.net> Message-ID: <4D06B671.5020601@simplistix.co.uk> On 14/12/2010 00:14, Gerry Reno wrote: > On 12/13/2010 06:34 PM, Chris Withers wrote: >> On 09/12/2010 21:29, Gerry Reno wrote: >>> How-To: Add VirtualEnv and Pylons (WSGI framework) to XAMPP >>> > > Maybe, if there's no Zope. Or we'll run away screaming... That is rather pathetically true... Ah well, each to their own... Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From greno at verizon.net Mon Dec 13 19:14:09 2010 From: greno at verizon.net (Gerry Reno) Date: Mon, 13 Dec 2010 19:14:09 -0500 Subject: Added Python, WSGI to XAMPP In-Reply-To: <4D06AD69.4030302@simplistix.co.uk> References: <4CFA4305.10004@it.uu.se> <4CFD6825.9020200@simplistix.co.uk> <4CFD8B29.3020006@verizon.net> <4D014A3D.7020101@verizon.net> <4D06AD69.4030302@simplistix.co.uk> Message-ID: <4D06B6D1.6080208@verizon.net> On 12/13/2010 06:34 PM, Chris Withers wrote: > On 09/12/2010 21:29, Gerry Reno wrote: >> How-To: Add VirtualEnv and Pylons (WSGI framework) to XAMPP >> > > You mean Pyramid, right? ;-) > > Chris > Maybe, if there's no Zope. Or we'll run away screaming... Anyway, Pyramid is still only alpha. But if it is a true WSGI framework then as my technique shows it can certainly be made to work with XAMPP. -Gerry From tjreedy at udel.edu Mon Dec 13 19:21:50 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 13 Dec 2010 19:21:50 -0500 Subject: ANN: ActivePython 2.7.1.3 is now available In-Reply-To: <8D0BABA0-44C4-45C9-BAC6-28F9BD06B340@activestate.com> References: <1292265539.4906.1410124185@webmail.messagingengine.com> <8D0BABA0-44C4-45C9-BAC6-28F9BD06B340@activestate.com> Message-ID: On 12/13/2010 4:23 PM, Sridhar Ratnakumar wrote: >> The PSF 3.1 Windows installer ships with tcl/tk 8.5 and ttk support. > Maybe that was changed in 3.1.3. No, 3.1 (not sure of 3.0) has always used 8.5 on windows and included tkinter.ttk module. > I did this for ActivePython 2.7, > >>>> import Tkinter >>>> root = Tkinter.Tk() >>>> root.tk.eval('info patchlevel') > '8.5.9' 8.5.2 here. Are there noticeable improvements? -- Terry Jan Reedy From sridharr at activestate.com Mon Dec 13 19:35:05 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Mon, 13 Dec 2010 16:35:05 -0800 Subject: ANN: ActivePython 2.7.1.3 is now available In-Reply-To: References: <1292265539.4906.1410124185@webmail.messagingengine.com> <8D0BABA0-44C4-45C9-BAC6-28F9BD06B340@activestate.com> Message-ID: <99D047E5-871C-4405-AA66-6A71BFF2B738@activestate.com> On 2010-12-13, at 4:21 PM, Terry Reedy wrote: > On 12/13/2010 4:23 PM, Sridhar Ratnakumar wrote: > >>> The PSF 3.1 Windows installer ships with tcl/tk 8.5 and ttk support. > >> Maybe that was changed in 3.1.3. > > No, 3.1 (not sure of 3.0) has always used 8.5 on windows and included > tkinter.ttk module. Ok, good to know. >> I did this for ActivePython 2.7, >> >>>>> import Tkinter >>>>> root = Tkinter.Tk() >>>>> root.tk.eval('info patchlevel') >> '8.5.9' > > 8.5.2 here. Are there noticeable improvements? Nothing I can think of except module updates and bug fixes[1], http://wiki.tcl.tk/405 I don't know how dependencies are managed when building PSF installers. From my experience, updating to newer tcl/tk patchlevel releases never broke the ActivePython build. -srid [1] David wanted to use >=8.5.8 due to a specific bug fix, http://community.activestate.com/forum/version-859-under-mac-os-x-am-i-getting-it From nospam at panda.com Mon Dec 13 19:50:21 2010 From: nospam at panda.com (Mark Crispin) Date: Mon, 13 Dec 2010 16:50:21 -0800 Subject: PyArg_ParseTuple question Message-ID: In a C module, I want to pick up the arguments for a Python call like: module.call("string1",["string2a", "string2b", "string2c"], "string3") and stash these into: char *arg1; char *arg2[]; char *arg3; All arguments are required, and we can assume that the arg2 vector is terminated with a null pointer. It doesn't look like PyArg_ParseTuple will do this easily; and that instead I have to use either the "O!" format with a PyList prototype, or use "O&" and write a converter. If I use "O!", at what level does it check? In particular, does it just check that the argument is a list, so I can get away with something like: static PyObject *call(PyObject *self, PyObject *args) { char *arg1, **arg2, *arg3; PyObject *arg2obj; PyObject *list = PyList_New(0); PyObject *ret = NULL; if(PyArg_ParseTuple(args, "sO!s", &arg1, list, &arg2obj, &arg3) { // grovel over arg2obj to get the number of members and make // sure they are all strings // allocate a big enough arg2 // copy the string pointers. ret = doMyThing(arg1, arg2, arg3); } PyObject_del(list); return ret; } By the way,... Python has tossed me a couple of curve balls, but all in all it's been quite reasonable. I still haven't read though the Python tutorial (I really do need to get up to speed on all the data types), but I've been able to get a tremendous amount of work done in a very short period of time. Oh, I've made it SEGV a few times, but these were all blunders in my C module, such as a C method returning self to indicate success (oops!). Python is the best development environment since LISP and SmallTalk nearly 20 years ago. Coming from me, that's quite high praise. -- Mark -- http://panda.com/mrc Democracy is two wolves and a sheep deciding what to eat for lunch. Liberty is a well-armed sheep contesting the vote. From greno at verizon.net Mon Dec 13 19:58:24 2010 From: greno at verizon.net (Gerry Reno) Date: Mon, 13 Dec 2010 19:58:24 -0500 Subject: Added Python, WSGI to XAMPP In-Reply-To: <4D06B671.5020601@simplistix.co.uk> References: <4CFA4305.10004@it.uu.se> <4CFD6825.9020200@simplistix.co.uk> <4CFD8B29.3020006@verizon.net> <4D014A3D.7020101@verizon.net> <4D06AD69.4030302@simplistix.co.uk> <4D06B6D1.6080208@verizon.net> <4D06B671.5020601@simplistix.co.uk> Message-ID: <4D06C130.9040506@verizon.net> On 12/13/2010 07:12 PM, Chris Withers wrote: > On 14/12/2010 00:14, Gerry Reno wrote: >> On 12/13/2010 06:34 PM, Chris Withers wrote: >>> On 09/12/2010 21:29, Gerry Reno wrote: >>>> How-To: Add VirtualEnv and Pylons (WSGI framework) to XAMPP >>>> >> >> Maybe, if there's no Zope. Or we'll run away screaming... > > That is rather pathetically true... > > Ah well, each to their own... > > Chris > What I really don't like right off is that Pyramid is contorting the MVC model just as Django did with their MTV model. They are both making the controller be the view and this confuses the hell out of people who come from true MVC based projects. The VIEW is the bits that stream out of the webserver back to the users browser. The CONTROLLER is the code that gathers all the pieces from the model and constructs the python code that is then fed to the engine that then creates the view. And just because the controller navigates the logic to dynamically contruct/render a view, that does not make 'it' the view. -Gerry From georgeryoung at gmail.com Mon Dec 13 21:50:38 2010 From: georgeryoung at gmail.com (gry) Date: Mon, 13 Dec 2010 18:50:38 -0800 (PST) Subject: performance of tight loop Message-ID: <51729934-2560-4ff7-b998-53a242a74729@j25g2000vbs.googlegroups.com> [python-2.4.3, rh CentOS release 5.5 linux, 24 xeon cpu's, 24GB ram] I have a little data generator that I'd like to go faster... any suggestions? maxint is usually 9223372036854775808(max 64bit int), but could occasionally be 99. width is usually 500 or 1600, rows ~ 5000. from random import randint def row(i, wd, mx): first = ['%d' % i] rest = ['%d' % randint(1, mx) for i in range(wd - 1)] return first + rest ... while True: print "copy %s from stdin direct delimiter ',';" % table_name for i in range(i,i+rows): print ','.join(row(i, width, maxint)) print '\.' From usernet at ilthio.net Mon Dec 13 21:53:29 2010 From: usernet at ilthio.net (Tim Harig) Date: Tue, 14 Dec 2010 02:53:29 +0000 (UTC) Subject: Catching user switching and getting current active user from root on linux References: <1a9bdbd4-2997-4e0f-a24f-cd148247e312@r40g2000prh.googlegroups.com> <8739qhs6dz.fsf.mdw@metalzone.distorted.org.uk> <797ba948-c608-4ed5-b2eb-25177932da91@o4g2000yqd.googlegroups.com> <4d04117b$0$30000$c3e8da3$5496439d@news.astraweb.com> <51d9390d-be72-49fe-a63b-5a05832c53e8@fu15g2000vbb.googlegroups.com> Message-ID: On 2010-12-13, mpnordland wrote: > I think I do understand multiuser systems, although I'm sorry I did > not make my self clear. Yes, I understand that there can be multiple > people logged in, and yes if you really wanted to, you could login as Apparantly you do not. There is nothing that prevents me from downloading from the web when I am not even at the computer. The point people are making is that there is no such thing as a single active user. Any user that has a running process is active. Somebody is not going to appreciate getting fired because somebody else scheduled a porn download at a time when they happened to be flagged as the current user. > yourself as many times as you want. This is not a server based > program, it is intended for use in a normal environment. The people There is nothing definitive about a so-called "normal" enviroment and since you didn't really specify anything, we had go make assumtpions for ourselves. Note also that a server is a piece of software, it need not be running on server class hardware. There are probably several local servers running on your system right now. As is commonly the case, the reason that you are having trouble with this problem is that you are trying to solve it wrong in the first place. You told us how you thought you should solve it which meant that we couldn't help you because we didn't know what problem you were trying to solve in the first place. For future reference, always give a 10,000ft explanation of the problem that you are actually trying to solve rather then just the microcosm of the problem that you feel is relevant. > or someone else. The problem I have is I want monitor what sites the > user visits, I need to know what sites were accessed by which user. > So, a way to find which user is requesting what url is what I want. As Carl has already pointed out, an authenticated proxy is the proper way to get the individualized logging that you are looking for. It is capable of logging each connection (including software from which you might not have anticipated) with its own identified user of origin. Even when several users are accessing the network at once, the network connections can be tied directly to the person who initated the connection. Users cannot use somebody elses connection without their authentication credentials. With a little bit of scripting, the browser can be configured to automatically use the user's credentials whenever the user account is created so that the user never needs to enter their credentials manually after logging in to their account. All connections that attempt to bypass the proxy should be firewalled. > Have I passed the Turing test? You still don't seem to understand how to use threads. Heres a clue: find a decent usenet client that actually displays them by default. Or, if you can't manage to get rid of that junky interface that is Google Groups, at least select the option to view as a tree. Then you might be able to actually post your replies in the proper thread rather then just appending on the the person who last posted. From steve+comp.lang.python at pearwood.info Mon Dec 13 22:29:38 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Dec 2010 03:29:38 GMT Subject: performance of tight loop References: <51729934-2560-4ff7-b998-53a242a74729@j25g2000vbs.googlegroups.com> Message-ID: <4d06e4a1$0$29971$c3e8da3$5496439d@news.astraweb.com> On Mon, 13 Dec 2010 18:50:38 -0800, gry wrote: > [python-2.4.3, rh CentOS release 5.5 linux, 24 xeon cpu's, 24GB ram] I > have a little data generator that I'd like to go faster... any > suggestions? > maxint is usually 9223372036854775808(max 64bit int), but could > occasionally be 99. > width is usually 500 or 1600, rows ~ 5000. > > from random import randint > > def row(i, wd, mx): > first = ['%d' % i] > rest = ['%d' % randint(1, mx) for i in range(wd - 1)] > return first + rest > ... > while True: > print "copy %s from stdin direct delimiter ',';" % table_name > for i in range(i,i+rows): > print ','.join(row(i, width, maxint)) > print '\.' This isn't entirely clear to me. Why is the while loop indented? I assume it's part of some other function that you haven't shown us, rather than part of the function row(). Assuming this, I would say that the overhead of I/O (the print commands) will likely be tens or hundreds of times greater than the overhead of the loop, so you're probably not likely to see much appreciable benefit. You might save off a few seconds from something that runs for many minutes. I don't see the point, really. If the print statements are informative rather than necessary, I would print every tenth (say) line rather than every line. That should save *lots* of time. Replacing "while True" with "while 1" may save a tiny bit of overhead. Whether it is significant or not is another thing. Replacing range with xrange should also make a difference, especially if rows is a large number. Moving the code from row() inline, replacing string interpolation with calls to str(), may also help. Making local variables of any globals may also help a tiny bit. But as I said, you're shaving microseconds of overhead and spending millseconds printing -- the difference will be tiny. But for what it's worth, I'd try this: # Avoid globals in favour of locals. from random import randint _maxint = maxint loop = xrange(i, i+rows) # Where does i come from? inner_loop = xrange(width) # Note 1 more than before. while 1: print "copy %s from stdin direct delimiter ',';" % table_name for i in loop: row = [str(randint(1, _maxint)) for _ in inner_loop] row[0] = str(i) # replace in place print ','.join(row) print '\.' Hope it helps. -- Steven From rustompmody at gmail.com Mon Dec 13 23:13:21 2010 From: rustompmody at gmail.com (rusi) Date: Mon, 13 Dec 2010 20:13:21 -0800 (PST) Subject: Added Python, WSGI to XAMPP References: <4CFA4305.10004@it.uu.se> <4CFD6825.9020200@simplistix.co.uk> <4CFD8B29.3020006@verizon.net> Message-ID: On Dec 10, 2:29?am, Gerry Reno wrote: > If you have any need of a portable LAMP stack, I just finished writing > some How-To's for getting Python, VirtualEnv and WSGI frameworks running > with XAMPP: > > How-To: Add VirtualEnv and Pylons (WSGI framework) to XAMPP > > > How-To: Add VirtualEnv and Django (WSGI framework) to XAMPP > > > How-To: Add Python and mod_wsgi to XAMPP > > > -Gerry What does XAMPP give (on linux) that the distro apache,mysql dont? From greno at verizon.net Mon Dec 13 23:28:48 2010 From: greno at verizon.net (Gerry Reno) Date: Mon, 13 Dec 2010 23:28:48 -0500 Subject: Added Python, WSGI to XAMPP In-Reply-To: References: <4CFA4305.10004@it.uu.se> <4CFD6825.9020200@simplistix.co.uk> <4CFD8B29.3020006@verizon.net> Message-ID: <4D06F280.5070609@verizon.net> On 12/13/2010 11:13 PM, rusi wrote: > On Dec 10, 2:29 am, Gerry Reno wrote: > >> If you have any need of a portable LAMP stack, I just finished writing >> some How-To's for getting Python, VirtualEnv and WSGI frameworks running >> with XAMPP: >> >> How-To: Add VirtualEnv and Pylons (WSGI framework) to XAMPP >> >> >> How-To: Add VirtualEnv and Django (WSGI framework) to XAMPP >> >> >> How-To: Add Python and mod_wsgi to XAMPP >> >> >> -Gerry >> > What does XAMPP give (on linux) that the distro apache,mysql dont? > It is a portable LAMP stack that is basically independent of your distro. If you want to upgrade PHP or Apache or whatever without disturbing your distro PHP or Apache you can do this. If you want to try out cutting edge releases of things you can do this on XAMPP without bothering your distro. It's an environment and what you can do with it is only limited by your imagination. -Gerry From ulrich.eckhardt at dominolaser.com Tue Dec 14 02:05:11 2010 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Tue, 14 Dec 2010 08:05:11 +0100 Subject: performance of tight loop References: <51729934-2560-4ff7-b998-53a242a74729@j25g2000vbs.googlegroups.com> Message-ID: gry wrote: > I have a little data generator that I'd like to go faster... any > suggestions? > maxint is usually 9223372036854775808(max 64bit int), but could > occasionally be 99. > width is usually 500 or 1600, rows ~ 5000. > > from random import randint > > def row(i, wd, mx): > first = ['%d' % i] > rest = ['%d' % randint(1, mx) for i in range(wd - 1)] > return first + rest A few things here: * If you can, don't convert the ints to strings. I'm not 100% sure about Python 2.4, but newer versions will automatically yield long instead of int if the range exceeds that of an int, so even with large numbers that should be safe. * Replace range with xrange. * Instead of creating and appending lists, you could also use a generator expression. > print ','.join(row(i, width, maxint)) All you do here is take a list of strings, build a single string from them and then print the string. Why not iterate over the list (or, as suggested, the generator) and print the elements? Summary: Avoid unnecessary conversions. This includes int to string, but also logical sequences into arrays. Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From ulrich.eckhardt at dominolaser.com Tue Dec 14 02:08:14 2010 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Tue, 14 Dec 2010 08:08:14 +0100 Subject: performance of tight loop References: <51729934-2560-4ff7-b998-53a242a74729@j25g2000vbs.googlegroups.com> <4d06e4a1$0$29971$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2nhjt7-pei.ln1@satorlaser.homedns.org> Steven D'Aprano wrote: > Replacing "while True" with "while 1" may save a tiny bit of overhead. > Whether it is significant or not is another thing. Is this the price for an intentional complexity or just a well-known optimizer deficiency? Just curious... Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From ryan at rfk.id.au Tue Dec 14 02:56:21 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Tue, 14 Dec 2010 18:56:21 +1100 Subject: performance of tight loop In-Reply-To: <2nhjt7-pei.ln1@satorlaser.homedns.org> References: <51729934-2560-4ff7-b998-53a242a74729@j25g2000vbs.googlegroups.com> <4d06e4a1$0$29971$c3e8da3$5496439d@news.astraweb.com> <2nhjt7-pei.ln1@satorlaser.homedns.org> Message-ID: <1292313381.20208.47.camel@durian> On Tue, 2010-12-14 at 08:08 +0100, Ulrich Eckhardt wrote: > Steven D'Aprano wrote: > > Replacing "while True" with "while 1" may save a tiny bit of overhead. > > Whether it is significant or not is another thing. > > Is this the price for an intentional complexity or just a well-known > optimizer deficiency? At least on older pythons, you can assign to the name "True" so it's not possible to optimize that loop - you must look up the name "True" on each iteration. For example, in python 2.6 this loop will exit after one iteration: >>> while True: ... True = False ... >>> To see the difference, take a look at the bytecode python generators for the type types of loop: >>> import dis >>> def while1(): ... while 1: ... pass ... >>> def whileTrue(): ... while True: ... pass ... >>> dis.dis(while1) 2 0 SETUP_LOOP 3 (to 6) 3 >> 3 JUMP_ABSOLUTE 3 >> 6 LOAD_CONST 0 (None) 9 RETURN_VALUE >>> >>> dis.dis(whileTrue) 2 0 SETUP_LOOP 12 (to 15) >> 3 LOAD_GLOBAL 0 (True) 6 JUMP_IF_FALSE 4 (to 13) 9 POP_TOP 3 10 JUMP_ABSOLUTE 3 >> 13 POP_TOP 14 POP_BLOCK >> 15 LOAD_CONST 0 (None) 18 RETURN_VALUE >>> Still, I just can't bring myself to write "while 1" in favour of "while True" in code. Python 3 does away with this madness entirely: >>> while True: ... True = False ... File "", line 2 SyntaxError: assignment to keyword >>> Looking at the bytecode shows that in Python 3, "while 1" and "while True" are indeed identical. Cheers, Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit ryan at rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part URL: From ulrich.eckhardt at dominolaser.com Tue Dec 14 03:20:07 2010 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Tue, 14 Dec 2010 09:20:07 +0100 Subject: performance of tight loop References: <51729934-2560-4ff7-b998-53a242a74729@j25g2000vbs.googlegroups.com> <4d06e4a1$0$29971$c3e8da3$5496439d@news.astraweb.com> <2nhjt7-pei.ln1@satorlaser.homedns.org> Message-ID: Thank you for the explanation, Ryan! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From mhv at dmu.dk Tue Dec 14 03:43:11 2010 From: mhv at dmu.dk (Hvidberg, Martin) Date: Tue, 14 Dec 2010 09:43:11 +0100 Subject: Fail import with SWIG generated imp.load_module ? Message-ID: I'm trying to load a module GDAL into a Python script. The loader/binder that is then called, seems to be generated by SWIG, a project with which I'm unfortunately not familiar. The part of the SWIG generated code that fails on me is as follow: ------ start code snip 1 ------------- # This file was automatically generated by SWIG (http://www.swig.org). # Version 1.3.39 # # Do not make changes to this file unless you know what you are doing--modify # the SWIG interface file instead. from sys import version_info if version_info >= (2,6,0): def swig_import_helper(): from os.path import dirname import imp fp = None try: fp, pathname, description = imp.find_module('_gdal', [dirname(__file__)]) except ImportError: import _gdal return _gdal if fp is not None: print "fp:",fp # <- My code ... print "pn:",pathname # <- My code ... print "de:",description # <- My code ... try: _mod = imp.load_module('_gdal', fp, pathname, description) finally: fp.close() return _mod _gdal = swig_import_helper() del swig_import_helper else: import _gdal del version_info ... ------ end code snip 1 ------------- I had to redo the indents manually in this mail, I hope I didn't make any mistakes. When I run the script that activates this code, it returns the following: ------ start code snip 2 ------------- fp: pn: C:\gdal\bin\gdal\python\osgeo\_gdal.pyd de: ('.pyd', 'rb', 3) Traceback (most recent call last): File "C:\Martin\Work_Eclipse\Hilfe\src\check_GDAL.py", line 8, in import gdal File "C:\gdal\bin\gdal\python\osgeo\gdal.py", line 27, in _gdal = swig_import_helper() File "C:\gdal\bin\gdal\python\osgeo\gdal.py", line 26, in swig_import_helper return _mod UnboundLocalError: local variable '_mod' referenced before assignment ------ end code snip 2 ------------- It appears to me that the objects returned by imp.find_module, and printed out as fp:, pn: and de:, are valid. So why is mp.load_module returning what appears to be some flavour of NULL ? I'm using Python version 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] The GDAL lib is from http://download.osgeo.org/gdal/win32/1.6/gdalwin32exe160.zip All suggestions appreciated ... Best Regards Martin -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at nospam.invalid Tue Dec 14 04:02:06 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 14 Dec 2010 01:02:06 -0800 Subject: performance of tight loop References: <51729934-2560-4ff7-b998-53a242a74729@j25g2000vbs.googlegroups.com> Message-ID: <7xzks8u3qp.fsf@ruckus.brouhaha.com> gry writes: ... > rest = ['%d' % randint(1, mx) for i in range(wd - 1)] > for i in range(i,i+rows): ... One thing that immediately comes to mind is use xrange instead of range. Also, instead of first = ['%d' % i] rest = ['%d' % randint(1, mx) for i in range(wd - 1)] return first + rest you might save some copying with: rest = ['%d' % randint(1, mx) for i in xrange(wd)] rest[0] = '%d'%i return rest That's uglier than the old-fashioned rest = ['%d'%i] for i in xrange(wd-1): rest.append('%d' % randint(1, mx)) I think a generator would be cleanest, but maybe slowest: def row(i, wd, mx): yield '%d' % i for j in xrange(wd-1): yield ('%d' % randint(1, mx)) From greg.ewing at canterbury.ac.nz Tue Dec 14 04:19:04 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 14 Dec 2010 22:19:04 +1300 Subject: while True or while 1 In-Reply-To: <4d05434e$0$29970$c3e8da3$5496439d@news.astraweb.com> References: <4d05434e$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8mor4bFl3oU1@mid.individual.net> Steven D'Aprano wrote: >>>>while True: > > ... print "Looping" > ... True = 0 Just remember that if you use that inside a function, you'll have to initialise True to True before... er, wait a moment, that won't work... ah, I know: def f(true = True): True = true while True: ... True = False -- Greg From hpj at urpla.net Tue Dec 14 05:33:34 2010 From: hpj at urpla.net (Hans-Peter Jansen) Date: Tue, 14 Dec 2010 11:33:34 +0100 Subject: while True or while 1 In-Reply-To: <8mor4bFl3oU1@mid.individual.net> References: <4d05434e$0$29970$c3e8da3$5496439d@news.astraweb.com> <8mor4bFl3oU1@mid.individual.net> Message-ID: <201012141133.35082.hpj@urpla.net> On Tuesday 14 December 2010, 10:19:04 Gregory Ewing wrote: > Steven D'Aprano wrote: > >>>>while True: > > > > ... print "Looping" > > ... True = 0 > > Just remember that if you use that inside a function, you'll > have to initialise True to True before... er, wait a moment, > that won't work... ah, I know: > > def f(true = True): > True = true > while True: > ... > True = False Thankfully, with Python 3 this code falls flat on its face. If I would have to _consume_ code like that more often, it would require me to also use a vomit resistant keyboard cover.. Pete From j.j.molenaar at gmail.com Tue Dec 14 06:19:12 2010 From: j.j.molenaar at gmail.com (Joost Molenaar) Date: Tue, 14 Dec 2010 12:19:12 +0100 Subject: optparse/argparse for cgi/wsgi? In-Reply-To: References: Message-ID: Many people have. :-) In the context of WSGI you're basically talking about routing middleware, which solves the problem: "given a request, which application should be called to construct a response?" In my case, it turned out as simple as a list of (regex, resource) tuples, where regex is a regular expression that looks at the request URI and resource is an object that may or may not implement GET, POST, PUT, DELETE methods. In the regex I can capture any arguments that the resource needs. If the request method is GET and the method GET exists on the matched resource, it is called, else a 'Method Not Allowed' response code is returned. HTH Joost On 10 December 2010 17:36, samwyse wrote: > Has anyone ever built some sort of optparse/argparse module for cgi/ > wsgi programs? I can see why a straight port wouldn't work, but a > module that can organize parameter handling for web pages seems like a > good idea, especially if it provided a standard collection of both > client- and server-side validation processes, easy > internationalization, and a way to create customizable help pages. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From j.j.molenaar at gmail.com Tue Dec 14 06:23:58 2010 From: j.j.molenaar at gmail.com (Joost Molenaar) Date: Tue, 14 Dec 2010 12:23:58 +0100 Subject: optparse/argparse for cgi/wsgi? In-Reply-To: References: Message-ID: To aid your googling, the problem is also commonly called 'Dispatching' instead of 'Routing'. Joost On 14 December 2010 12:19, Joost Molenaar wrote: > Many people have. :-) > > In the context of WSGI you're basically talking about routing > middleware, which solves the problem: "given a request, which > application should be called to construct a response?" > > In my case, it turned out as simple as a list of (regex, resource) > tuples, where regex is a regular expression that looks at the > request URI and resource is an object that may or may not > implement GET, POST, PUT, DELETE methods. In the regex > I can capture any arguments that the resource needs. If the > request method is GET and the method GET exists on the > matched resource, it is called, else a 'Method Not Allowed' > response code is returned. > > HTH > > Joost > > > On 10 December 2010 17:36, samwyse wrote: > >> Has anyone ever built some sort of optparse/argparse module for cgi/ >> wsgi programs? I can see why a straight port wouldn't work, but a >> module that can organize parameter handling for web pages seems like a >> good idea, especially if it provided a standard collection of both >> client- and server-side validation processes, easy >> internationalization, and a way to create customizable help pages. >> > -- Joost Molenaar +31 644 015 510 -------------- next part -------------- An HTML attachment was scrubbed... URL: From kurt.alfred.mueller at gmail.com Tue Dec 14 06:37:29 2010 From: kurt.alfred.mueller at gmail.com (Kurt Mueller) Date: Tue, 14 Dec 2010 12:37:29 +0100 Subject: while True or while 1 In-Reply-To: <201012141133.35082.hpj@urpla.net> References: <4d05434e$0$29970$c3e8da3$5496439d@news.astraweb.com> <8mor4bFl3oU1@mid.individual.net> <201012141133.35082.hpj@urpla.net> Message-ID: <4D0756F9.9040501@gmail.com> Am 14.12.2010 11:33, schrieb Hans-Peter Jansen: > On Tuesday 14 December 2010, 10:19:04 Gregory Ewing wrote: >> Steven D'Aprano wrote: >>>>>> while True: >>> >>> ... print "Looping" >>> ... True = 0 >> >> Just remember that if you use that inside a function, you'll >> have to initialise True to True before... er, wait a moment, >> that won't work... ah, I know: >> >> def f(true = True): >> True = true >> while True: >> ... >> True = False > > Thankfully, with Python 3 this code falls flat on its face. > > If I would have to _consume_ code like that more often, > it would require me to also use a vomit resistant keyboard cover.. > > Pete True yesterday, today and in the future: Yesterday: "Pilate said to him, True? what is true? Having said this he went out again to the Jews and said to them, I see no wrong in him." Today: We are so thankful that today we are free to define "True" ourselves using Python 2.x. Future: Be warned, the future gets darker! ;-) Gr?essli -- Kurt Mueller From __peter__ at web.de Tue Dec 14 06:48:37 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 14 Dec 2010 12:48:37 +0100 Subject: performance of tight loop References: <51729934-2560-4ff7-b998-53a242a74729@j25g2000vbs.googlegroups.com> Message-ID: gry wrote: > [python-2.4.3, rh CentOS release 5.5 linux, 24 xeon cpu's, 24GB ram] > I have a little data generator that I'd like to go faster... any > suggestions? > maxint is usually 9223372036854775808(max 64bit int), but could > occasionally be 99. > width is usually 500 or 1600, rows ~ 5000. > > from random import randint > > def row(i, wd, mx): > first = ['%d' % i] > rest = ['%d' % randint(1, mx) for i in range(wd - 1)] > return first + rest > ... > while True: > print "copy %s from stdin direct delimiter ',';" % table_name > for i in range(i,i+rows): > print ','.join(row(i, width, maxint)) > print '\.' I see the biggest potential in inlining randint. Unfortunately you did not provide an executable script and I had to make it up: $ cat gry.py from random import randint import sys def row(i, wd, mx): first = ['%d' % i] rest = ['%d' % randint(1, mx) for i in range(wd - 1)] return first + rest def main(): table_name = "unknown" maxint = sys.maxint width = 500 rows = 1000 offset = 0 print "copy %s from stdin direct delimiter ',';" % table_name for i in range(offset, offset+rows): print ','.join(row(i, width, maxint)) print '\.' if __name__ == "__main__": main() $ time python gry.py > /dev/null real 0m5.280s user 0m5.230s sys 0m0.050s $ $ cat gry_inline.py import random import math import sys def make_rand(n): if n < 1 << random.BPF: def rand(random=random.random): return int(n*random())+1 else: k = int(1.00001 + math.log(n-1, 2.0)) def rand(getrandbits=random.getrandbits): r = getrandbits(k) while r >= n: r = getrandbits(k) return r+1 return rand def row(i, wd, rand): first = ['%d' % i] rest = ['%d' % rand() for i in range(wd - 1)] return first + rest def main(): table_name = "unknown" maxint = sys.maxint width = 500 rows = 1000 offset = 0 rand = make_rand(maxint) print "copy %s from stdin direct delimiter ',';" % table_name for i in range(offset, offset+rows): print ','.join(row(i, width, rand)) print '\.' if __name__ == "__main__": main() $ time python gry_inline.py > /dev/null real 0m2.004s user 0m2.000s sys 0m0.000s $ Disclaimer: the code in random.py is complex enough that I cannot guarantee I snatched the right pieces. Peter From __peter__ at web.de Tue Dec 14 06:59:01 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 14 Dec 2010 12:59:01 +0100 Subject: performance of tight loop References: <51729934-2560-4ff7-b998-53a242a74729@j25g2000vbs.googlegroups.com> Message-ID: Peter Otten wrote: > gry wrote: > >> [python-2.4.3, rh CentOS release 5.5 linux, 24 xeon cpu's, 24GB ram] >> I have a little data generator that I'd like to go faster... any >> suggestions? >> maxint is usually 9223372036854775808(max 64bit int), but could >> occasionally be 99. >> width is usually 500 or 1600, rows ~ 5000. >> >> from random import randint >> >> def row(i, wd, mx): >> first = ['%d' % i] >> rest = ['%d' % randint(1, mx) for i in range(wd - 1)] >> return first + rest >> ... >> while True: >> print "copy %s from stdin direct delimiter ',';" % table_name >> for i in range(i,i+rows): >> print ','.join(row(i, width, maxint)) >> print '\.' > > I see the biggest potential in inlining randint. Unfortunately you did not > provide an executable script and I had to make it up: > $ time python gry_inline.py > /dev/null > > real 0m2.004s > user 0m2.000s > sys 0m0.000s On second thought, if you have numpy available: $ cat gry_numpy.py from numpy.random import randint import sys def row(i, wd, mx): first = ['%d' % i] rest = ['%d' % i for i in randint(1, mx, wd - 1)] return first + rest def main(): table_name = "unknown" maxint = sys.maxint width = 500 rows = 1000 offset = 0 print "copy %s from stdin direct delimiter ',';" % table_name for i in range(offset, offset+rows): print ','.join(row(i, width, maxint)) print '\.' if __name__ == "__main__": main() $ time python gry_numpy.py > /dev/null real 0m1.024s user 0m1.010s sys 0m0.010s $ Argh Peter From bblais at bryant.edu Tue Dec 14 08:29:04 2010 From: bblais at bryant.edu (Brian Blais) Date: Tue, 14 Dec 2010 08:29:04 -0500 Subject: packaging and installing In-Reply-To: References: <50410C1D-2234-400A-8E1B-F78C4C3AA9D3@bryant.edu> Message-ID: <747D9C66-1B22-4EE4-9A31-2B51CA4DB517@bryant.edu> On Dec 13, 2010, at 12:30 PM, Godson Gera wrote: > > > On Mon, Dec 13, 2010 at 10:46 PM, Brian Blais wrote: >> Hello, >> >> I was wondering if there is any standard or suggested way of installing packages *without* going to the commandline. I often have students who, from there experience in Windows, have never looked at the commandline before and it is a bit of a challenge to get them to install something (i.e. go to the commandline, cd over to the proper folder, type python setup.py install, etc...). I've never seen a package with something like a "compileme.bat", but was wondering if there is some suggested way of doing this or some reasons *not* to do this. I can always write my own (1-line) .bat file, but I didn't want to reinvent the wheel. Perhaps there is a better way for me to do this, ideally in a platform independent way. >> > You don't even have to write a bat file. Python's distutils package allows you to build exe file which creates generic windows wizard window for installing packages. > > Take a look at distutils package http://docs.python.org/distutils/builtdist.html > that's very interesting, and I didn't realize that. it may be useful, and solves part of my problem, but the other part is that I am not on a windows machine and have to distribute to windows users. Or perhaps I am on windows, and need to distribute to Mac. It's great that python itself is so cross-platform, but the installation process for packages seems a lot less so. thanks, bb -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais http://bblais.blogspot.com/ From godson.g at gmail.com Tue Dec 14 10:12:06 2010 From: godson.g at gmail.com (Godson Gera) Date: Tue, 14 Dec 2010 20:42:06 +0530 Subject: packaging and installing In-Reply-To: <747D9C66-1B22-4EE4-9A31-2B51CA4DB517@bryant.edu> References: <50410C1D-2234-400A-8E1B-F78C4C3AA9D3@bryant.edu> <747D9C66-1B22-4EE4-9A31-2B51CA4DB517@bryant.edu> Message-ID: On Tue, Dec 14, 2010 at 6:59 PM, Brian Blais wrote: > On Dec 13, 2010, at 12:30 PM, Godson Gera wrote: > > > > > > > On Mon, Dec 13, 2010 at 10:46 PM, Brian Blais wrote: > >> Hello, > >> > >> I was wondering if there is any standard or suggested way of installing > packages *without* going to the commandline. I often have students who, > from there experience in Windows, have never looked at the commandline > before and it is a bit of a challenge to get them to install something (i.e. > go to the commandline, cd over to the proper folder, type python setup.py > install, etc...). I've never seen a package with something like a > "compileme.bat", but was wondering if there is some suggested way of doing > this or some reasons *not* to do this. I can always write my own (1-line) > .bat file, but I didn't want to reinvent the wheel. Perhaps there is a > better way for me to do this, ideally in a platform independent way. > >> > > You don't even have to write a bat file. Python's distutils package > allows you to build exe file which creates generic windows wizard window for > installing packages. > > > > Take a look at distutils package > http://docs.python.org/distutils/builtdist.html > > > > that's very interesting, and I didn't realize that. it may be useful, and > solves part of my problem, but the other part is that I am not on a windows > machine and have to distribute to windows users. Or perhaps I am on > windows, and need to distribute to Mac. It's great that python itself is so > cross-platform, but the installation process for packages seems a lot less > so. > > Don't blame python for that. command line is least command denominator across all platforms and you don't wanted your audience to visit command line. As of 2010 you have to be on specific platform to make distributions for that platform. This kind of asking for toomuch from a few MB sized python. You need to make your own python distro to support all platform specific(exe, msi, ELF, app, rpm, deb etc etc ) packaing in one installation whose size may swell over many MBs or resort back to wiriting batch file on windows and bash and sh scripts on *nix platforms. -- Thanks & Regards, Godson Gera Asterisk Consultant India -------------- next part -------------- An HTML attachment was scrubbed... URL: From baloand at googlemail.com Tue Dec 14 10:35:45 2010 From: baloand at googlemail.com (baloan) Date: Tue, 14 Dec 2010 07:35:45 -0800 (PST) Subject: Tkinter polling example: file copy with progress bar References: Message-ID: <80524fc1-fcb7-4279-89f0-f04fd7018106@m7g2000vbn.googlegroups.com> Unfortunately you use command('cp...') to copy the file instead of Pythons portable library methods. This choice effectively makes your program work on Unix only (not Windows). See http://modcopy.sourceforge.net for a more portable version. Regards, baloan at gmail.com From darcy at druid.net Tue Dec 14 10:57:40 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 14 Dec 2010 10:57:40 -0500 Subject: Tkinter polling example: file copy with progress bar In-Reply-To: <80524fc1-fcb7-4279-89f0-f04fd7018106@m7g2000vbn.googlegroups.com> References: <80524fc1-fcb7-4279-89f0-f04fd7018106@m7g2000vbn.googlegroups.com> Message-ID: <20101214105740.2b155473.darcy@druid.net> On Tue, 14 Dec 2010 07:35:45 -0800 (PST) baloan wrote: > Unfortunately you use command('cp...') to copy the file instead of > Pythons portable library methods. This choice > effectively makes your program work on Unix only (not Windows). > > See http://modcopy.sourceforge.net for a more portable version. I guess I missed the beginning of this thread but can someone tell me why one needs to download a whole other program in order to do this? open(out_fn, 'w').write(open(in_fn).read()) -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From rboehne at gmail.com Tue Dec 14 11:15:26 2010 From: rboehne at gmail.com (Robert Boehne) Date: Tue, 14 Dec 2010 10:15:26 -0600 Subject: Sybase module 0.40pre1 released Message-ID: WHAT IS IT: The Sybase module provides a Python interface to the Sybase relational database system. It supports all of the Python Database API, version 2.0 with extensions. ** This version is a pre-release not intended for production use ** The module is available here: http://downloads.sourceforge.net/python-sybase/python-sybase-0.40pre1.tar.gz The module home page is here: http://python-sybase.sourceforge.net/ MAJOR CHANGES SINCE 0.39: Modify the DateTimeAsPython output conversion to return None when NULL is output support for Python without threads Ignore additional non-error codes from Sybase (1918 and 11932) Use outputmap in bulkcopy mode (thanks to patch by Cyrille Froehlich) Raise exception when opening a cursor on a closed connection Added unit tests Added new exception DeadLockError when Sybase is in a deadlock situation Add command properties CS_STICKY_BINDS and CS_HAVE_BINDS Added support for inputmap in bulkcopy reuse command and cursor when calling cursor.execute with same request Use ct_setparam to define ct_cursor parameters types instead of ct_param implicit conversion for CS_DATE_TYPE in CS_DATETIME_TYPE DataBuf Adding ct_cmd_props wrapper Increase DataBuf maxlength for params of a request when using CS_CHAR_TYPE params so that the buf can be reused BUGS CORRECTED SINCE 0.39: Corrected money type when using CS_MONEY4 (close bug 2615821) Corrected thread locking in ct_cmd_props (thanks to patch by Cyrille Froehlich) Corrected bug in type mapping in callproc (thanks to report by Skip Montanaro) Correct passing None in a DataBuf (thanks to patch by Bram Kuijvenhoven) The full ChangeLog is here: https://python-sybase.svn.sourceforge.net/svnroot/python-sybase/tags/r0_40pre1/ChangeLog -------------- next part -------------- An HTML attachment was scrubbed... URL: From v.harishankar at gmail.com Tue Dec 14 11:25:54 2010 From: v.harishankar at gmail.com (Harishankar) Date: Tue, 14 Dec 2010 16:25:54 +0000 (UTC) Subject: Tkinter polling example: file copy with progress bar References: <80524fc1-fcb7-4279-89f0-f04fd7018106@m7g2000vbn.googlegroups.com> <20101214105740.2b155473.darcy@druid.net> Message-ID: On Tue, 14 Dec 2010 10:57:40 -0500, D'Arcy J.M. Cain wrote: > I guess I missed the beginning of this thread but can someone tell me > why one needs to download a whole other program in order to do this? > > open(out_fn, 'w').write(open(in_fn).read()) Or what about shutil? Isn't that the higher level file operation module? -- Harishankar (http://harishankar.org http://lawstudentscommunity.com) From darcy at druid.net Tue Dec 14 11:33:00 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 14 Dec 2010 11:33:00 -0500 Subject: Tkinter polling example: file copy with progress bar In-Reply-To: References: <80524fc1-fcb7-4279-89f0-f04fd7018106@m7g2000vbn.googlegroups.com> <20101214105740.2b155473.darcy@druid.net> Message-ID: <20101214113300.29ee9021.darcy@druid.net> On Tue, 14 Dec 2010 16:25:54 +0000 (UTC) Harishankar wrote: > On Tue, 14 Dec 2010 10:57:40 -0500, D'Arcy J.M. Cain wrote: > > open(out_fn, 'w').write(open(in_fn).read()) > Or what about shutil? Isn't that the higher level file operation module? At least that's in the standard library but even then it can be overkill for a simple copy. It does do some error checking that the above doesn't do if you need that. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From arnodel at gmail.com Tue Dec 14 11:52:38 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Tue, 14 Dec 2010 16:52:38 +0000 Subject: while True or while 1 References: <4d05434e$0$29970$c3e8da3$5496439d@news.astraweb.com> <8mor4bFl3oU1@mid.individual.net> Message-ID: <87lj3sb8kp.fsf@gmail.com> Gregory Ewing writes: > Steven D'Aprano wrote: > >>>>>while True: >> >> ... print "Looping" >> ... True = 0 > > Just remember that if you use that inside a function, you'll > have to initialise True to True before... er, wait a moment, > that won't work... ah, I know: > > def f(true = True): > True = true > while True: > ... > True = False You also need to initialise False to False for it to be really robust. So something like this will do. True = not 0 False = not True while True: ... True = False :) -- Arnaud From python at mrabarnett.plus.com Tue Dec 14 13:10:50 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 14 Dec 2010 18:10:50 +0000 Subject: Fail import with SWIG generated imp.load_module ? In-Reply-To: References: Message-ID: <4D07B32A.2010308@mrabarnett.plus.com> On 14/12/2010 08:43, Hvidberg, Martin wrote: > I'm trying to load a module GDAL into a Python script. > > The loader/binderthat is then called, seems to be generated by SWIG, a > project with which I'm unfortunately not familiar. > > The part of the SWIG generated code that fails on me is as follow: > [snip] It _might_ be that imp.load_module(...) is raising an exception, so it doesn't assign to '_mod', and then it tries to run the 'finally' block and return _mod. This raises the exception you see and hides the original cause. From sohel807 at gmail.com Tue Dec 14 13:27:24 2010 From: sohel807 at gmail.com (Akand Islam) Date: Tue, 14 Dec 2010 10:27:24 -0800 (PST) Subject: Sage's Python References: Message-ID: <46480720-4334-47ce-a35c-4895472b351b@29g2000prb.googlegroups.com> On Dec 13, 4:33?pm, "Rhodri James" wrote: > On Fri, 10 Dec 2010 17:11:55 -0000, Akand Islam wrote: > > In my system (Ubuntu 10.04) there are sage-4.6, python 2.6.5, tk8.5- > > dev installed. When I give command from terminal "sage -f > > python-2.6.5.p8" to get sage's python it shows following message: > > > ?No command 'sage' found, did you mean: > > ?Command 'save' from package 'atfs' (universe) > > ?Command 'page' from package 'tcllib' (universe) > > ?sage: command not found > > > How can I get Sage's python to be worked so that I can import sage.all > > in python shell? > > The fact that you have no executable called "sage" suggests that you ? > haven't actually installed it yet. ?Check the Sage website, which has ? > plenty of documentation, and try to figure out where you left the path on ? > whichever method you used. > > -- > Rhodri James *-* Wildebeest Herder to the Masses Dear Rhodri James, Thanks for your response. But I have installed sage-4.6 as per instructions. Sage-4.6 folder is in my ~/Desktop, therefore, from ~/ Desktop/sage-4.6 I can initiate ./sage and can work with sage. -- Akand From newswombat at gmail.com Tue Dec 14 13:36:26 2010 From: newswombat at gmail.com (News Wombat) Date: Tue, 14 Dec 2010 10:36:26 -0800 (PST) Subject: ctypes question References: <2abdd9b3-66ec-4125-a5f8-41315008cccc@l17g2000yqe.googlegroups.com> <7e4306de-b95a-40c8-9c9c-10745d8dc793@z19g2000yqb.googlegroups.com> Message-ID: <413f5a8f-69a0-4351-acc2-18d7edda8149@j3g2000vbp.googlegroups.com> On Dec 11, 12:59?pm, MrJean1 wrote: > In general, for shared libraries, you need to define those first as > prototype using ctypes.CFUNCTYPE() and then instantiate each prototype > once supplying the necessary parameter flags using > prototype(func_spec, tuple_of_param_flags). ?See sections 15.16.2.3 > and 4 of the ctypes docs*. I tried the cfuntype and proto steps, and it's not crashing now (that's good), but now i'm just left with null pointers as a return object. I'm still working through all of the examples you sent. They were extremely helpful. Here's where I'm at now... What is strange is I can actually get smiGetNode to work if I don't cfunctype/proto it. If i do, nada. however, the smiGetNextNode fails no matter what, usually with a segfault, but depending on how i construct it, sometimes a null pointer. constants.py: http://pastebin.com/f3b4Wbf0 libsmi.py: http://pastebin.com/XgtpG6gr smi.c (the actual function): http://pastebin.com/Pu2vabWM From lists at cheimes.de Tue Dec 14 13:38:59 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 14 Dec 2010 19:38:59 +0100 Subject: while True or while 1 In-Reply-To: <87lj3sb8kp.fsf@gmail.com> References: <4d05434e$0$29970$c3e8da3$5496439d@news.astraweb.com> <8mor4bFl3oU1@mid.individual.net> <87lj3sb8kp.fsf@gmail.com> Message-ID: Am 14.12.2010 17:52, schrieb Arnaud Delobelle: > You also need to initialise False to False for it to be really > robust. So something like this will do. > > True = not 0 > False = not True > while True: > ... > True = False Tres Seavers once told me a joke like this: True = not not "Who's at the door?" # say it out loud! This was back in the old days of Zope 2.5 and Python 2.1, which didn't have True and False. Christian From python at bdurham.com Tue Dec 14 14:27:07 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 14 Dec 2010 14:27:07 -0500 Subject: Map Linux locale codes to Windows locale codes? Message-ID: <1292354827.12980.1410327469@webmail.messagingengine.com> Is there a way to map Linux locale codes to Windows locale codes? Windows has locale codes like 'Spanish_Mexico'. We would like to use the more ISO compliant 'es_MX' locale format under Windows. Is there a resource or API that might help us with this mapping? Babel is not an option for us since we're using Python 2.7. Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From jjjaime at gmail.com Tue Dec 14 14:50:41 2010 From: jjjaime at gmail.com (=?ISO-8859-1?Q?Jaime_Fern=E1ndez?=) Date: Tue, 14 Dec 2010 20:50:41 +0100 Subject: Concatenate a string as binary bytes Message-ID: Hi To build a binary packet (for SMPP protocol), we have to concatenate different types of data: integers, floats, strings. We are using struct.pack to generate the binary representation of each integer and float of the packet, and then they are concatenated with the + operand. However, for strings we directly concatenate the string with +, without using struct. Everything works with python 2 except when string encoding is introduced. Whenever, a non ASCII char appears in the string, an exception is launched. In python 3, it's not possible to do this trick because all the strings are unicode. What would be the best approach to: - Support non-ascii chars (we just want to concatenate the binary representation of the string without any modification) - Compatibility between python 2 and python 3. Thanks, Jaime -------------- next part -------------- An HTML attachment was scrubbed... URL: From emile at fenx.com Tue Dec 14 14:51:35 2010 From: emile at fenx.com (Emile van Sebille) Date: Tue, 14 Dec 2010 11:51:35 -0800 Subject: Sage's Python In-Reply-To: <46480720-4334-47ce-a35c-4895472b351b@29g2000prb.googlegroups.com> References: <46480720-4334-47ce-a35c-4895472b351b@29g2000prb.googlegroups.com> Message-ID: On 12/14/2010 10:27 AM Akand Islam said... > On Dec 13, 4:33 pm, "Rhodri James" > wrote: >> On Fri, 10 Dec 2010 17:11:55 -0000, Akand Islam wrote: >>> In my system (Ubuntu 10.04) there are sage-4.6, python 2.6.5, tk8.5- >>> dev installed. When I give command from terminal "sage -f >>> python-2.6.5.p8" to get sage's python it shows following message: >> >>> No command 'sage' found, did you mean: This means that no sage command was found on your path. Check to be sure that ~/Desktop is in your path. Emile >>> Command 'save' from package 'atfs' (universe) >>> Command 'page' from package 'tcllib' (universe) >>> sage: command not found >> >>> How can I get Sage's python to be worked so that I can import sage.all >>> in python shell? >> >> The fact that you have no executable called "sage" suggests that you >> haven't actually installed it yet. Check the Sage website, which has >> plenty of documentation, and try to figure out where you left the path on >> whichever method you used. >> >> -- >> Rhodri James *-* Wildebeest Herder to the Masses > > Dear Rhodri James, > Thanks for your response. But I have installed sage-4.6 as per > instructions. Sage-4.6 folder is in my ~/Desktop, therefore, from ~/ > Desktop/sage-4.6 I can initiate ./sage and can work with sage. > > -- Akand From python at mrabarnett.plus.com Tue Dec 14 15:02:49 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 14 Dec 2010 20:02:49 +0000 Subject: Concatenate a string as binary bytes In-Reply-To: References: Message-ID: <4D07CD69.9080003@mrabarnett.plus.com> On 14/12/2010 19:50, Jaime Fern?ndez wrote: > Hi > > To build a binary packet (for SMPP protocol), we have to concatenate > different types of data: integers, floats, strings. > > We are using struct.pack to generate the binary representation of each > integer and float of the packet, and then they are concatenated with the > + operand. > However, for strings we directly concatenate the string with +, without > using struct. > > Everything works with python 2 except when string encoding is > introduced. Whenever, a non ASCII char appears in the string, an > exception is launched. In python 3, it's not possible to do this trick > because all the strings are unicode. > > What would be the best approach to: > - Support non-ascii chars (we just want to concatenate the binary > representation of the string without any modification) > - Compatibility between python 2 and python 3. > I'd say encode to UTF-8. From benjamin.kaplan at case.edu Tue Dec 14 15:06:04 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 14 Dec 2010 15:06:04 -0500 Subject: Concatenate a string as binary bytes In-Reply-To: References: Message-ID: 2010/12/14 Jaime Fern?ndez : > Hi > To build a binary packet (for SMPP protocol), we have to concatenate > different types of data: integers, floats, strings. > We are using struct.pack to generate the binary representation of each > integer and float of the packet, and then they are concatenated with the + > operand. > However, for strings we directly concatenate the string with +, without > using struct. > Everything works with python 2 except when string encoding is introduced. > Whenever, a non ASCII char appears in the string, an exception is launched. > In python 3, it's not possible to do this trick because all the strings are > unicode. > What would be the best approach to: > ?- Support non-ascii chars (we just want to concatenate the binary > representation of the string without any modification) > ?- Compatibility between python 2 and python 3. > Thanks, > Jaime > -- I don't think you quite understand how encodings and unicode work.You have two similar, but distinct data types involved: a byte string ("" in python 2.x, b"" in Python 3.x) which is a sequence of bytes, and a unicode String (u"" in Python 2.x and "" in Python 3.x) which is a sequence of characters. Neither type of strings has an encoding associated with it- an encoding is just a function for converting between these two data types. You only get those non-ascii character problems when you try concatenating Unicode strings with byte strings, because Python defaults to using ASCII as the encoding when you don't specify the encoding yourself. If you want to avoid those errors (in both Python 2.x and Python 3.x), use the unicode string's encode method to turn the characters into a sequence of bytes before you concat them. From arnodel at gmail.com Tue Dec 14 15:38:47 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Tue, 14 Dec 2010 20:38:47 +0000 Subject: while True or while 1 References: <4d05434e$0$29970$c3e8da3$5496439d@news.astraweb.com> <8mor4bFl3oU1@mid.individual.net> <87lj3sb8kp.fsf@gmail.com> Message-ID: <87hbegay3s.fsf@gmail.com> Christian Heimes writes: [...] > Tres Seavers once told me a joke like this: > > True = not not "Who's at the door?" # say it out loud! > > This was back in the old days of Zope 2.5 and Python 2.1, which didn't > have True and False. I almost used: True = "to be" or not "to be" # that is the question but didn't dare! -- Arnaud From mdw at distorted.org.uk Tue Dec 14 15:42:49 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Tue, 14 Dec 2010 20:42:49 +0000 Subject: PyArg_ParseTuple question References: Message-ID: <87wrncf5me.fsf.mdw@metalzone.distorted.org.uk> Mark Crispin writes: > In a C module, I want to pick up the arguments for a Python call like: > module.call("string1",["string2a", "string2b", "string2c"], "string3") > and stash these into: > char *arg1; > char *arg2[]; > char *arg3; > All arguments are required, and we can assume that the arg2 vector is > terminated with a null pointer. > > It doesn't look like PyArg_ParseTuple will do this easily; and that > instead I have to use either the "O!" format with a PyList prototype, > or use "O&" and write a converter. I think the latter is probably your best bet. > If I use "O!", at what level does it check? In particular, does it > just check that the argument is a list, so I can get away with > something like: It does the equivalent of `isinstance', so you'll accept a `list' or an instance of any subclass of `list'. The `O&' converter is pretty straightforward. Something like this ought to do. static int convertlist(PyObject *o, void *p) { PyObject **v; Py_ssize_t i, n; /* Could allow general sequences using PySequence_Fast */ if (!PyList_Check(o)) return (0); /* Copy stuff */ n = PyList_GET_SIZE(o); if ((v = PyMem_New(PyObject *, n + 1)) == 0) return (0); for (i = 0; i < n; i++) { v[i] = PyList_GET_ITEM(o, n); Py_INCREF(v[i]); } v[n] = 0; return (1); } If you want to do a more complex conversion (e.g., to the individual items) there's more work to be done. I could have used PySequence_* functions to read the size and items, but that makes error handling more complicated. One could also borrow the references from the underlying list, which would leave the underlying storage for the vector as the only thing to free. I ended up writing a lot of conversion functions when I was doing Python library bindings (for a crypto library); they're generally a good thing. I found that the trickiest thing about PyArg_ParseTuple is in making sure that you can clean everything up even if it goes wrong half way through. -- [mdw] From flisboa.costa at gmail.com Tue Dec 14 16:00:36 2010 From: flisboa.costa at gmail.com (=?UTF-8?B?RmzDoXZpbyBMaXNiw7Rh?=) Date: Tue, 14 Dec 2010 19:00:36 -0200 Subject: Map Linux locale codes to Windows locale codes? In-Reply-To: <1292354827.12980.1410327469@webmail.messagingengine.com> References: <1292354827.12980.1410327469@webmail.messagingengine.com> Message-ID: You could look into the windows registry, the key "HKLM\SYSTEM\CurrentControlSet\Control\Nls" has all the supported LCID's listed. If not, you could simply get the codepage provided by locale.setlocale(), e.g.: import locale print(locale.setlocale(locale.LC_ALL, "")) prints "Portuguese_Brazil.1252" for me. That codepage part is actually a LCID, that you can then cross-reference with any LCID list on the net. I guess there may be a way to look that up entirely from the registry, including getting a short reference or ANSI codepage from the LCID, but i doubt it'd be portable at all. Maybe what you should do is to make up a dict with known LCID's and their corresponding language codes. I don't know of any way to do this automatically in python... Take a look at http://msdn.microsoft.com/en-us/goglobal/bb896001.aspx 2010/12/14 > Is there a way to map Linux locale codes to Windows locale codes? > > Windows has locale codes like 'Spanish_Mexico'. We would like to use the > more ISO compliant 'es_MX' locale format under Windows. > > Is there a resource or API that might help us with this mapping? > > Babel is not an option for us since we're using Python 2.7. > > Thank you, > Malcolm > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at please.post Tue Dec 14 16:14:35 2010 From: no.email at please.post (kj) Date: Tue, 14 Dec 2010 21:14:35 +0000 (UTC) Subject: How to pop the interpreter's stack? Message-ID: Consider this code: def spam(*args, **kwargs): args, kwargs = __pre_spam(*args, **kwargs) # args & kwargs are OK: proceed # ... def __pre_spam(*args, **kwargs): # validate args & kwargs; # return canonicalized versions of args & kwargs; # on failure, raise some *informative* exception # ... return canonicalized_args, canonicalized_kwargs I write functions like __pre_spam for one reason only: to remove clutter from a corresponding spam function that has a particularly complex argument-validation/canonicalization stage. In effect, spam "outsources" to __pre_spam the messy business of checking and conditioning its arguments. The one thing I don't like about this strategy is that the tracebacks of exceptions raised during the execution of __pre_spam include one unwanted stack level (namely, the one corresponding to __pre_spam itself). __pre_spam should be completely invisible and unobtrusive, as if it had been textually "inlined" into spam prior to the code's interpretation. And I want to achieve this without in any way cluttering spam with try/catches, decorators, and whatnot. (After all, the whole point of introducing __pre_spam is to declutter spam.) It occurs to me, in my innocence (since I don't know the first thing about the Python internals), that one way to achieve this would be to have __pre_spam trap any exceptions (with a try/catch around its entire body), and somehow pop its frame from the interpreter stack before re-raising the exception. (Or some clueful/non-oxymoronic version of this.) How feasible is this? And, if it is quite unfeasible, is there some other way to achieve the same overall design goals described above? TIA! ~kj From prog at vtr.net Tue Dec 14 18:17:48 2010 From: prog at vtr.net (craf) Date: Tue, 14 Dec 2010 20:17:48 -0300 Subject: Alternative to PIL in Python 3.1 Message-ID: <1292368668.4959.1.camel@cristian-desktop> Hi. I wonder if anyone knows any alternative to PIL library, as this does not work with Python 3.1. Thanks in advance Regards. Cristian From stonesnake at kol.co.nz Tue Dec 14 18:30:36 2010 From: stonesnake at kol.co.nz (stateslave) Date: Wed, 15 Dec 2010 12:30:36 +1300 Subject: How to experience python on a handheld, tablet, etc on linux? Message-ID: Without buying first? I'd like to run the front end of all these new devices, on my PC and program in python, to assess which is the best on for me. pre-test python scripts before cross loading onto the device I finally buy. Is that possible? It would also be nice to have some of the look and feel on a PC of these devices anyway, with python of course. Has that be done yet? Any hints? Cheers in advance. From kirby.urner at gmail.com Tue Dec 14 18:34:11 2010 From: kirby.urner at gmail.com (kirby.urner at gmail.com) Date: Tue, 14 Dec 2010 15:34:11 -0800 (PST) Subject: Combing Medusa's Hair... (Design Pattern) Message-ID: <39a583d2-f5a1-4632-848c-c9205fbaa2d0@l24g2000vby.googlegroups.com> This is an idea I got thinking about COM objects, and getting some support from Mark Hammond, Python's Win32 wizard. The goal is to have a host language (not Python) instantiate an object that runs against the Python interpreter, which lives as its own process. The VMs have various ways of implementing this. Mono isn't that different right? In this design pattern, you have something like a dry cleaner's, where people submit jobs at the counter, and go away right away with a ticket (Python returns -- but keeps running). When they come back is more up to them. Work has been done in the meantime (or not, if the queue is backed up). So Python needs a queue in the front, to accept these job orders, a facility for issuing tickets, and a way to catalog what tasks are completed in some urn or receptacle (given this is Python, we might call it a "holy grail"). The host process has a method from querying the Python object as to whether such-and-such a job is complete or not. More primitively, it could just check an output bin (folder) for the expected file (perhaps each "hair" creates a PDF in roughly 1 to 4 seconds). The reason "Medusa" is useful wordplay is it reminds us of the asynchronous server embedded in early Zope. How Medusa relates to Twisted is lore for others to recount. However, given we're spawning strands, hairs or threads each time a host process calls into our object, we're looking at a multi-snaked environment, so the image could hardly be more apt. The act of "combing" suggests some synchronization / communication between threads, but that's not a requirement. More on tap here: http://mail.python.org/pipermail/edu-sig/2010-December/010141.html Kirby From emile at fenx.com Tue Dec 14 19:39:19 2010 From: emile at fenx.com (Emile van Sebille) Date: Tue, 14 Dec 2010 16:39:19 -0800 Subject: Alternative to PIL in Python 3.1 In-Reply-To: <1292368668.4959.1.camel@cristian-desktop> References: <1292368668.4959.1.camel@cristian-desktop> Message-ID: On 12/14/2010 3:17 PM craf said... > Hi. > > I wonder if anyone knows any alternative to PIL library, as this does > not work with Python 3.1. > > Thanks in advance > > Regards. > > Cristian > You might try the 1.1.6 port referenced here: http://www.mail-archive.com/image-sig at python.org/msg02404.html Emile From mrjean1 at gmail.com Tue Dec 14 19:47:05 2010 From: mrjean1 at gmail.com (MrJean1) Date: Tue, 14 Dec 2010 16:47:05 -0800 (PST) Subject: ctypes question References: <2abdd9b3-66ec-4125-a5f8-41315008cccc@l17g2000yqe.googlegroups.com> <7e4306de-b95a-40c8-9c9c-10745d8dc793@z19g2000yqb.googlegroups.com> <413f5a8f-69a0-4351-acc2-18d7edda8149@j3g2000vbp.googlegroups.com> Message-ID: Try again after changing line 16 to sn = SmiGetNode(None, "1.3.6.1.2.1.2.2") Because, SmiGetNode is a Python function which accepts Python objects as arguments. Passing is a ctypes object oid is incorrect. /Jean On Dec 14, 10:36?am, News Wombat wrote: > On Dec 11, 12:59?pm, MrJean1 wrote: > > > In general, for shared libraries, you need to define those first as > > prototype using ctypes.CFUNCTYPE() and then instantiate each prototype > > once supplying the necessary parameter flags using > > prototype(func_spec, tuple_of_param_flags). ?See sections 15.16.2.3 > > and 4 of the ctypes docs*. > > I tried the cfuntype and proto steps, and it's not crashing now > (that's good), but now i'm just left with null pointers as a return > object. ?I'm still working through all of the examples you sent. ?They > were extremely helpful. ?Here's where I'm at now... > > What is strange is I can actually get smiGetNode to work if I don't > cfunctype/proto it. ?If i do, nada. ?however, the smiGetNextNode fails > no matter what, usually with a segfault, but depending on how i > construct it, sometimes a null pointer. > > constants.py:http://pastebin.com/f3b4Wbf0 > libsmi.py:http://pastebin.com/XgtpG6gr > smi.c (the actual function):http://pastebin.com/Pu2vabWM From prog at vtr.net Tue Dec 14 20:15:59 2010 From: prog at vtr.net (craf) Date: Tue, 14 Dec 2010 22:15:59 -0300 Subject: [Fwd: Re: Alternative to PIL in Python 3.1] Message-ID: <1292375759.6322.6.camel@cristian-desktop> --------- Mensaje reenviado -------- > De: Emile van Sebille > Para: python-list at python.org > Asunto: Re: Alternative to PIL in Python 3.1 > Fecha: Tue, 14 Dec 2010 16:39:19 -0800 > > On 12/14/2010 3:17 PM craf said... > > Hi. > > > > I wonder if anyone knows any alternative to PIL library, as this does > > not work with Python 3.1. > > > > Thanks in advance > > > > Regards. > > > > Cristian > > > > > You might try the 1.1.6 port referenced here: > > http://www.mail-archive.com/image-sig at python.org/msg02404.html > > Emile > Hi Emile. Thanks for the info. I'll try it. Regards. Cristian From benjamin.kaplan at case.edu Tue Dec 14 21:06:34 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 14 Dec 2010 21:06:34 -0500 Subject: How to experience python on a handheld, tablet, etc on linux? In-Reply-To: References: Message-ID: On Tue, Dec 14, 2010 at 6:30 PM, stateslave wrote: > > Without buying first? > > I'd like to run the front end of all these new devices, > on my PC and program in python, to assess which is the > best on for me. pre-test python scripts before cross > loading onto the device I finally buy. > > Is that possible? It would also be nice to have some of > the look and feel on a PC of these devices anyway, with > python of course. > > Has that be done yet? > > Any hints? Cheers in advance. > -- Python on Linux is Python on Linux. Whether you have Ubuntu running on a tablet or on a desktop, it's going to behave the same. There are going to be two important things different between running Linux on your PC and running it on a tablet: the processor and the UI. And there's really no good way to simulate either one of those. From ethan at stoneleaf.us Tue Dec 14 21:31:48 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 14 Dec 2010 18:31:48 -0800 Subject: How to pop the interpreter's stack? In-Reply-To: References: Message-ID: <4D082894.6070203@stoneleaf.us> kj wrote: > The one thing I don't like about this strategy is that the tracebacks > of exceptions raised during the execution of __pre_spam include one > unwanted stack level (namely, the one corresponding to __pre_spam > itself). > > __pre_spam should be completely invisible and unobtrusive I am unaware of any way to accomplish what you desire. I also think this is one of those things that's not worth fighting -- how often are you going to see such a traceback? When somebody makes a coding mistake? I would say change the name (assuming yours was a real example) to something more meaningful like _spam_arg_verifier and call it good. Alternatively, perhaps you could make a more general arg_verifier that could be used for all such needs, and then your traceback would have: caller spam arg_verifier and that seems useful to me (it is, in fact, how I have mine set up). Hope this helps! ~Ethan~ From samwyse at gmail.com Tue Dec 14 22:51:21 2010 From: samwyse at gmail.com (samwyse) Date: Tue, 14 Dec 2010 19:51:21 -0800 (PST) Subject: Proposed changes to logging defaults References: <3763d355-9074-485c-a694-031d600d5b84@m11g2000vbs.googlegroups.com> Message-ID: <0d23a9b8-544c-4dfe-81ce-653909ea2385@g26g2000vbi.googlegroups.com> On Dec 9, 6:12?pm, Vinay Sajip wrote: > Some changes are being proposed to how logging works in default > configurations. > > Briefly - when a logging event occurs which needs to be output to some > log, the behaviour of the logging package when no explicit logging > configuration is provided will change, most likely to log those events > to sys.stderr with a default format. I'm in favor of this change. I've long wished that I could just add lots of warning/error/info logging to a script and have it just work without having to spend time configuring the logging system. From kushal.kumaran+python at gmail.com Tue Dec 14 23:10:05 2010 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Wed, 15 Dec 2010 09:40:05 +0530 Subject: Combing Medusa's Hair... (Design Pattern) In-Reply-To: <39a583d2-f5a1-4632-848c-c9205fbaa2d0@l24g2000vby.googlegroups.com> References: <39a583d2-f5a1-4632-848c-c9205fbaa2d0@l24g2000vby.googlegroups.com> Message-ID: On Wed, Dec 15, 2010 at 5:04 AM, kirby.urner at gmail.com wrote: > > This is an idea I got thinking about COM objects, and getting > some support from Mark Hammond, Python's Win32 wizard. > > The goal is to have a host language (not Python) instantiate > an object that runs against the Python interpreter, which lives > as its own process. ?The VMs have various ways of implementing > this. ?Mono isn't that different right? > > In this design pattern, you have something like a dry cleaner's, > where people submit jobs at the counter, and go away right > away with a ticket (Python returns -- but keeps running). ?When > they come back is more up to them. ?Work has been done in > the meantime (or not, if the queue is backed up). > Isn't this the way people use queuing systems (ActiveMQ and the like)? Or simply multiprocessing + Queue. -- regards, kushal From john at nmt.edu Tue Dec 14 23:52:52 2010 From: john at nmt.edu (JohnWShipman) Date: Tue, 14 Dec 2010 20:52:52 -0800 (PST) Subject: Tkinter polling example: file copy with progress bar References: <80524fc1-fcb7-4279-89f0-f04fd7018106@m7g2000vbn.googlegroups.com> Message-ID: <632a3b9e-626c-4bd7-bc81-574f90569c4a@21g2000prv.googlegroups.com> On Dec 14, 8:57?am, "D'Arcy J.M. Cain" wrote: > On Tue, 14 Dec 2010 07:35:45 -0800 (PST) > > baloan wrote: > > Unfortunately you use command('cp...') to copy the file instead of > > Pythons portable library methods. This choice > > effectively makes your program work on Unix only (not Windows). > > > Seehttp://modcopy.sourceforge.netfor a more portable version. > > I guess I missed the beginning of this thread but can someone tell me > why one needs to download a whole other program in order to do this? > > ? open(out_fn, 'w').write(open(in_fn).read()) I posted this example because I got several queries on how to do polling in Tkinter, specifically how to use the .after() universal widget method. The points about using the portable library methods are all well taken. I used file copy as the example long-running process because a reader wanted to know how to do that specifically. Please forgive me for not thinking about portability and stuff; you know how us ancient Unix weenies are. From john at nmt.edu Tue Dec 14 23:53:10 2010 From: john at nmt.edu (JohnWShipman) Date: Tue, 14 Dec 2010 20:53:10 -0800 (PST) Subject: Tkinter polling example: file copy with progress bar References: <80524fc1-fcb7-4279-89f0-f04fd7018106@m7g2000vbn.googlegroups.com> Message-ID: On Dec 14, 8:57?am, "D'Arcy J.M. Cain" wrote: > On Tue, 14 Dec 2010 07:35:45 -0800 (PST) > > baloan wrote: > > Unfortunately you use command('cp...') to copy the file instead of > > Pythons portable library methods. This choice > > effectively makes your program work on Unix only (not Windows). > > > Seehttp://modcopy.sourceforge.netfor a more portable version. > > I guess I missed the beginning of this thread but can someone tell me > why one needs to download a whole other program in order to do this? > > ? open(out_fn, 'w').write(open(in_fn).read()) I posted this example because I got several queries on how to do polling in Tkinter, specifically how to use the .after() universal widget method. The points about using the portable library methods are all well taken. I used file copy as the example long-running process because a reader wanted to know how to do that specifically. Please forgive me for not thinking about portability and stuff; you know how us ancient Unix weenies are. From kirby.urner at gmail.com Wed Dec 15 00:01:55 2010 From: kirby.urner at gmail.com (kirby urner) Date: Tue, 14 Dec 2010 21:01:55 -0800 Subject: Combing Medusa's Hair... (Design Pattern) In-Reply-To: References: <39a583d2-f5a1-4632-848c-c9205fbaa2d0@l24g2000vby.googlegroups.com> Message-ID: On Tue, Dec 14, 2010 at 8:10 PM, Kushal Kumaran wrote: << snip >> >> >> In this design pattern, you have something like a dry cleaner's, >> where people submit jobs at the counter, and go away right >> away with a ticket (Python returns -- but keeps running). ?When >> they come back is more up to them. ?Work has been done in >> the meantime (or not, if the queue is backed up). >> > > Isn't this the way people use queuing systems (ActiveMQ and the like)? > ?Or simply multiprocessing + Queue. > > -- > regards, > kushal > Yeah, that's probably right. This is more like a pedagogical metaphor, a mnemonic. As the name for a design pattern, it should probably be confined to Python examples, as that's where the wordplay on Medusa makes some sense, and not just because her hair was all snakes. http://bytes.com/topic/python/answers/26771-twisted-medusa-zope Kirby From metolone+gmane at gmail.com Wed Dec 15 00:53:36 2010 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Tue, 14 Dec 2010 21:53:36 -0800 Subject: ctypes question References: <2abdd9b3-66ec-4125-a5f8-41315008cccc@l17g2000yqe.googlegroups.com><7e4306de-b95a-40c8-9c9c-10745d8dc793@z19g2000yqb.googlegroups.com> <413f5a8f-69a0-4351-acc2-18d7edda8149@j3g2000vbp.googlegroups.com> Message-ID: > "News Wombat" wrote in message > news:413f5a8f-69a0-4351-acc2-18d7edda8149 at j3g2000vbp.googlegroups.com... > On Dec 11, 12:59 pm, MrJean1 wrote: > > > In general, for shared libraries, you need to define those first as > > prototype using ctypes.CFUNCTYPE() and then instantiate each prototype > > once supplying the necessary parameter flags using > > prototype(func_spec, tuple_of_param_flags). See sections 15.16.2.3 > > and 4 of the ctypes docs*. > > I tried the cfuntype and proto steps, and it's not crashing now > (that's good), but now i'm just left with null pointers as a return > object. I'm still working through all of the examples you sent. They > were extremely helpful. Here's where I'm at now... > > What is strange is I can actually get smiGetNode to work if I don't > cfunctype/proto it. If i do, nada. however, the smiGetNextNode fails > no matter what, usually with a segfault, but depending on how i > construct it, sometimes a null pointer. > > constants.py: http://pastebin.com/f3b4Wbf0 > libsmi.py: http://pastebin.com/XgtpG6gr > smi.c (the actual function): http://pastebin.com/Pu2vabWM > -- > http://mail.python.org/mailman/listinfo/python-list constants.py, in SmiNode and SmiModule definitions: - Any field defined "char*" in C should be "c_char_p" not "POINTER(c_char_p)" (which is char**). The function definition can be simplified, and 2nd argument corrected (c_char_p not POINTER(c_char_p)). Python strings can be passed directly to c_char_p arguments. SmiGetNode = clibsmi.smiGetNode SmiGetNode.argtypes = [POINTER(SmiModule),c_char_p] SmiGetNode.restype = POINTER(SmiNode) oid = "1.3.6.1.2.1.2.2" sn=SmiGetNode(None,oid) Give these fixes a try... -Mark From bavishi.darshak at gmail.com Wed Dec 15 02:12:36 2010 From: bavishi.darshak at gmail.com (Darshak Bavishi) Date: Wed, 15 Dec 2010 12:42:36 +0530 Subject: how tohandling output generated after execution of command/script on host unix machine? Message-ID: Hi Experts, I am still struggling with handling output generated after execution of command/script on host unix machine using windows client machine ssh code : import sys import datetime import time # setup logging paramiko.util.log_to_file('darshak_simple.log') ssh=paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect("*****",username="****",password="****") try: stdin,stdout,stderr=ssh.exec_command("BsPlSMProbe -f node -d > /var/log/Darshak/3.txt ") // output of this command will be store in /var/log/Darshak/ in remote machine except: {Issue is files are generating but remaining blank pls pls help me out of this} print "check" time.sleep(10) print stdout.readlines() a=stdout.readlines() print 1 ssh.close() #print stdout.readlines() Issue is files are generating but remaining blank pls pls help me out of this -- BR Darshak Bavishi -------------- next part -------------- An HTML attachment was scrubbed... URL: From vinay_sajip at yahoo.co.uk Wed Dec 15 03:13:55 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Wed, 15 Dec 2010 00:13:55 -0800 (PST) Subject: Proposed changes to logging defaults References: 0d23a9b8-544c-4dfe-81ce-653909ea2385@g26g2000vbi.googlegroups.com Message-ID: <5af6dffb-ddb7-4563-aef4-7996d78da5b0@p38g2000vbn.googlegroups.com> On Dec 15, 3:51?am, samwyse wrote: > I'm in favor of this change. ?I've long wished that I could just add > lots of warning/error/infologgingto a script and have it just work > without having to spend time configuring theloggingsystem. Note that INFO logging will still not be sent to sys.stderr. Only events of severity WARNING and above will be logged to sys.stderr. If you need INFO logging as well, it's easy enough to configure for a simple script (to get the same effect): basicConfig(level=logging.INFO, format='%(message)s') # or whatever level/format you need So I'm not sure how much time you really have to spend on configuring logging. Regards, Vinay Sajip From nagle at animats.com Wed Dec 15 03:46:57 2010 From: nagle at animats.com (John Nagle) Date: Wed, 15 Dec 2010 00:46:57 -0800 Subject: Proposed changes to logging defaults In-Reply-To: <3763d355-9074-485c-a694-031d600d5b84@m11g2000vbs.googlegroups.com> References: <3763d355-9074-485c-a694-031d600d5b84@m11g2000vbs.googlegroups.com> Message-ID: <4d088078$0$44007$742ec2ed@news.sonic.net> On 12/9/2010 4:12 PM, Vinay Sajip wrote: > Some changes are being proposed to how logging works in default > configurations. > > Briefly - when a logging event occurs which needs to be output to some > log, the behaviour of the logging package when no explicit logging > configuration is provided will change, most likely to log those events > to sys.stderr with a default format. Bad idea. You're assuming that the logging package has the right to blither on the default sys.stderr. There are many cases in which it should not. The program could be running in a web server, and output would end up in the output HTML. The program could be running as a subprocess, and the output could end up in the pipe back to the the parent. "sys.stderr" might be connected to a dead pipe, and writing to it would then kill the program. So this change could break existing programs in subtle ways. John Nagle From stefan_ml at behnel.de Wed Dec 15 04:19:59 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 15 Dec 2010 10:19:59 +0100 Subject: PyArg_ParseTuple question In-Reply-To: <87wrncf5me.fsf.mdw@metalzone.distorted.org.uk> References: <87wrncf5me.fsf.mdw@metalzone.distorted.org.uk> Message-ID: Mark Wooding, 14.12.2010 21:42: > I could have used PySequence_* functions to read the size and items, but > that makes error handling more complicated. One could also borrow the > references from the underlying list, which would leave the underlying > storage for the vector as the only thing to free. > > I ended up writing a lot of conversion functions when I was doing Python > library bindings (for a crypto library); they're generally a good thing. > I found that the trickiest thing about PyArg_ParseTuple is in making > sure that you can clean everything up even if it goes wrong half way > through. I think it's worth mentioning here that the Cython compiler generates tightly tailored code for argument unpacking and type conversion. So unless you really want (or need) to write your code directly against Python's C-API, Cython will do a substantially better job with much less coding. Even if you have already written a major part of your code in C, it's worth considering to (re-)write the Python API wrapper parts in Cython if you need better performance. Stefan From bruno.desthuilliers at gmail.com Wed Dec 15 04:31:04 2010 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Wed, 15 Dec 2010 01:31:04 -0800 (PST) Subject: while True or while 1 References: <4d05434e$0$29970$c3e8da3$5496439d@news.astraweb.com> <8mor4bFl3oU1@mid.individual.net> <87lj3sb8kp.fsf@gmail.com> <87hbegay3s.fsf@gmail.com> Message-ID: On 14 d?c, 21:38, Arnaud Delobelle wrote: > I almost used: > > ? ? True = "to be" or not "to be" # that is the question KEYBOARD !-) From vinay_sajip at yahoo.co.uk Wed Dec 15 05:03:40 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Wed, 15 Dec 2010 02:03:40 -0800 (PST) Subject: Proposed changes to logging defaults References: <3763d355-9074-485c-a694-031d600d5b84@m11g2000vbs.googlegroups.com> <4d088078$0$44007$742ec2ed@news.sonic.net> Message-ID: On Dec 15, 8:46?am, John Nagle wrote: > ? ? You're assuming that theloggingpackage has the right to blither > on the default sys.stderr. ?There are many cases in which it > should not. ?The program could be running in a web server, and > output would end up in the output HTML. ?The program could be > running as a subprocess, and the output could end up in the > pipe back to the the parent. ?"sys.stderr" might be connected > to a dead pipe, and writing to it would then kill the program. > > ? ? So this change could break existing programs in subtle ways. I'm not assuming anything, and the rationale for the change is described in detail in the linked-to post. The reason for posting the link on this list is to give people advance warning of the changes, so they can see if they're affected and take the appropriate action. Note that since this change only affects the user who is using Python 3.2 and has not configured logging. Since the necessary configuration is easy to do, I'm assuming people who might be affected can easily update their code in time for the 3.2 release. Regards, Vinay Sajip From steve+comp.lang.python at pearwood.info Wed Dec 15 05:16:14 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Dec 2010 10:16:14 GMT Subject: How to pop the interpreter's stack? References: Message-ID: <4d08956e$0$29997$c3e8da3$5496439d@news.astraweb.com> On Tue, 14 Dec 2010 21:14:35 +0000, kj wrote: > Consider this code: > > > def spam(*args, **kwargs): > args, kwargs = __pre_spam(*args, **kwargs) > > # args & kwargs are OK: proceed > # ... > > > def __pre_spam(*args, **kwargs): > # validate args & kwargs; > # return canonicalized versions of args & kwargs; # on failure, > raise some *informative* exception # ... > return canonicalized_args, canonicalized_kwargs Double leading underscores don't have any special meaning in the global scope. Save yourself an underscore and call it _pre_spam instead :) In fact, even if spam and __pre_spam are methods, it's probably a good idea to avoid the double-underscore name mangling. It's usually more trouble than it's worth. > I write functions like __pre_spam for one reason only: to remove clutter > from a corresponding spam function that has a particularly complex > argument-validation/canonicalization stage. In effect, spam > "outsources" to __pre_spam the messy business of checking and > conditioning its arguments. A perfectly sensible arrangement. > The one thing I don't like about this strategy is that the tracebacks of > exceptions raised during the execution of __pre_spam include one > unwanted stack level (namely, the one corresponding to __pre_spam > itself). But why is it unwanted? The traceback shows where the error occurs -- it occurs in __pre_spam, not spam, or __post_spam, or spam_caller, or anywhere else. Even if it's possible, having the traceback *lie* about where it occurs is a bad idea which will cause confusion to anyone trying to maintain the software in the future. I can't think of any way to do it, but frankly I haven't thought too hard about it. I'm glad I can't think of any way of doing it, because the thought of having tracebacks lie about where they come from gives me the shivers. Imagine debugging when you've edited the source but are still running the old version, and now the reported line numbers don't match up with the source file -- it would be like that, only worse. -- Steven From rde at audaxis.com Wed Dec 15 06:34:21 2010 From: rde at audaxis.com (Romaric DEFAUX) Date: Wed, 15 Dec 2010 12:34:21 +0100 Subject: Encoding trouble Message-ID: <4D08A7BD.7080206@audaxis.com> Hi all, Since yesterday I'm working on an encoding problem, I become crazy now :) Could you please help me ? Here's the description of the problem : I've got two table in a MysqlDB : history_website and website The important column in them are : history_website.message (varchar(255), encoding = utf8_general_ci) website.client_name (varchar(255), encoding = utf8_general_ci) Why : 1? ) INSERT INTO history_website (time, ip, servername, message) VALUES ('1292411324.22', '192.168.2.15', 'system_server_test.audaxis.com', 'client_name UPDATED from Romariqu to Romariqu? Admin\n') is working perfectly when 2?) UPDATE website SET client_name='Romariqu? Admin\n' WHERE ip='192.168.2.15' is producing error : Warning: Incorrect string value: '\xE9 Admi...' for column 'client_name' at row 1 ??? To create these query, I do this : query = "UPDATE website SET client_name='%s' WHERE ip='%s'" % (self.client_name, self.ip) then self.cursor.execute(query) query = "INSERT INTO history_website (time, ip, servername, message) VALUES ('%s', '%s', '%s', '%s')" % (now, self.ip, self.servername, message)" where message = "client_name UPDATED from %s to %s" % (old_website.client_name, self.client_name) They're both string : type(message) = type(client_name) = My default encoding is sys.setdefaultencoding('utf-8') In my opinion, it should not work for both or work for both, no ? This is strange that it's working only for one... Romaric -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 5361 bytes Desc: S/MIME Cryptographic Signature URL: From hnsri49 at gmail.com Wed Dec 15 07:38:04 2010 From: hnsri49 at gmail.com (srinivas hn) Date: Wed, 15 Dec 2010 18:08:04 +0530 Subject: Links and pointers to basics of soap and suds Message-ID: Hi All, I am very new to the soap and its python client suds.Can anyone tell me how the actual will happens i nthe webservices including suds and soap API. Thanks in advance CHEERS CNA 9986229891 -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Wed Dec 15 07:55:04 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 15 Dec 2010 07:55:04 -0500 Subject: Tkinter polling example: file copy with progress bar In-Reply-To: <632a3b9e-626c-4bd7-bc81-574f90569c4a@21g2000prv.googlegroups.com> References: <80524fc1-fcb7-4279-89f0-f04fd7018106@m7g2000vbn.googlegroups.com> <632a3b9e-626c-4bd7-bc81-574f90569c4a@21g2000prv.googlegroups.com> Message-ID: On 12/14/2010 11:52 PM, JohnWShipman wrote: > you > know how us ancient Unix weenies are. Indeed we do ... ;-) regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From benedict.verheyen at gmail.com Wed Dec 15 07:58:49 2010 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Wed, 15 Dec 2010 13:58:49 +0100 Subject: Dealing with pywin32 on Linux Message-ID: Hi, I'm moving my development environment (python, Django, virtualenv) from Windows to Linux (Debian more specific). However, on one app (uses Django), i have a log on module that uses AD to authenticate users. It's based on the active_directory wrapper of Tim Golden. That needs the win32 module but installation of pywin32 fails on importing: import _winreg ImportError: No module named _winreg Kind of logical in hindsight :) However, this makes programming and testing under Linux a bit of a pain if you're dealing with Windows specific stuff. What is the correct way to proceed (i want to keep my development environment in Linux)? I could adjust my software modules to use the Linux counterparts of the AD functions that i have to authenticate. Or is there another way to deal with this? Thanks for any insight, Cheers, Benedict From steve at holdenweb.com Wed Dec 15 08:06:12 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 15 Dec 2010 08:06:12 -0500 Subject: Proposed changes to logging defaults In-Reply-To: References: <3763d355-9074-485c-a694-031d600d5b84@m11g2000vbs.googlegroups.com> <4d088078$0$44007$742ec2ed@news.sonic.net> Message-ID: On 12/15/2010 5:03 AM, Vinay Sajip wrote: > On Dec 15, 8:46 am, John Nagle wrote: >> You're assuming that theloggingpackage has the right to blither >> on the default sys.stderr. There are many cases in which it >> should not. The program could be running in a web server, and >> output would end up in the output HTML. The program could be >> running as a subprocess, and the output could end up in the >> pipe back to the the parent. "sys.stderr" might be connected >> to a dead pipe, and writing to it would then kill the program. >> >> So this change could break existing programs in subtle ways. > > I'm not assuming anything, and the rationale for the change is > described in detail in the linked-to post. The reason for posting the > link on this list is to give people advance warning of the changes, so > they can see if they're affected and take the appropriate action. > > Note that since this change only affects the user who is using Python > 3.2 and has not configured logging. Since the necessary configuration > is easy to do, I'm assuming people who might be affected can easily > update their code in time for the 3.2 release. > I might add that any web server that sends sys.stderr to the HTTP output stream is not likely to be professionally managed. It's far preferable, in the general case, to ensure that logging messages do not enter the stdout-stdin pipelines carrying information between coordinating processes. If a current task is assuming the prior logging package's behavior and analysing a process's stdout for messages it arguably needs fixing anyway, though I agree that breakage of any kind is unfortunate. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From hpj at urpla.net Wed Dec 15 08:10:43 2010 From: hpj at urpla.net (Hans-Peter Jansen) Date: Wed, 15 Dec 2010 14:10:43 +0100 Subject: while True or while 1 In-Reply-To: <87hbegay3s.fsf@gmail.com> References: <87hbegay3s.fsf@gmail.com> Message-ID: <201012151410.43852.hpj@urpla.net> On Tuesday 14 December 2010, 21:38:47 Arnaud Delobelle wrote: > Christian Heimes writes: > [...] > > > Tres Seavers once told me a joke like this: > > > > True = not not "Who's at the door?" # say it out loud! > > > > This was back in the old days of Zope 2.5 and Python 2.1, which > > didn't have True and False. > > I almost used: > > True = "to be" or not "to be" # that is the question That's wrong: >>> "to be" or not "to be" 'to be' You need to wrap it with bool() at least (even without interpreting Pythons answer to the duality contradiction of consciousness for now ;-)) > but didn't dare! Pete From steve at holdenweb.com Wed Dec 15 08:14:39 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 15 Dec 2010 08:14:39 -0500 Subject: Links and pointers to basics of soap and suds In-Reply-To: References: Message-ID: On 12/15/2010 7:38 AM, srinivas hn wrote: > Hi All, > > I am very new to the soap and its python client suds.Can anyone tell me > how the actual will happens i nthe webservices including suds and soap API. > That's a bit like saying "I need to go around the corner. Would you mind teaching me to drive?". Google for phrases like "web services architecture" and "SOAP WSDL" to get some idea of how these technologies are put together. This assumes, of course, that you already possess a fair idea of how the web is put together. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From benedict.verheyen at gmail.com Wed Dec 15 08:16:36 2010 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Wed, 15 Dec 2010 14:16:36 +0100 Subject: Encoding trouble In-Reply-To: <4D08A7BD.7080206@audaxis.com> References: <4D08A7BD.7080206@audaxis.com> Message-ID: On 15/12/2010 12:34, Romaric DEFAUX wrote: > To create these query, I do this : > query = "UPDATE website SET client_name='%s' WHERE ip='%s'" % (self.client_name, self.ip) > then self.cursor.execute(query) > Unicode can be tricky. Don't you have to encode the string again? I tested this in the interpreter: a = ("UPDATE website SET client_name='%s'" % "Romariqu? Admin").decode("iso-8859-15") print "Query %s " % a.encode("iso-8859-15") produces UPDATE website SET client_name='Romariqu? Admin' So i would try to encode the query before issuing the self.cursor.execute(query) Cheers, Benedict From rde at audaxis.com Wed Dec 15 08:28:07 2010 From: rde at audaxis.com (Romaric DEFAUX) Date: Wed, 15 Dec 2010 14:28:07 +0100 Subject: Encoding trouble In-Reply-To: References: <4D08A7BD.7080206@audaxis.com> Message-ID: <4D08C267.30305@audaxis.com> Le 15/12/2010 14:16, Benedict Verheyen a ?crit : > On 15/12/2010 12:34, Romaric DEFAUX wrote: > >> To create these query, I do this : >> query = "UPDATE website SET client_name='%s' WHERE ip='%s'" % (self.client_name, self.ip) >> then self.cursor.execute(query) >> > Unicode can be tricky. > Don't you have to encode the string again? > I tested this in the interpreter: > > a = ("UPDATE website SET client_name='%s'" % "Romariqu? Admin").decode("iso-8859-15") > > print "Query %s " % a.encode("iso-8859-15") > produces UPDATE website SET client_name='Romariqu? Admin' > > So i would try to encode the query before issuing the self.cursor.execute(query) > > Cheers, > Benedict > Thanks for your answer :) I finally found the solution, I removed the following line from my db connection : # con.cursor().execute('SET NAMES \'utf8\';') # con.cursor().execute('SET CHARACTER SET utf8;') # con.cursor().execute('SET character_set_connection=utf8;') And now it's working fine ! Thanks for your help ! Romaric -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 5361 bytes Desc: S/MIME Cryptographic Signature URL: From mail at timgolden.me.uk Wed Dec 15 08:37:30 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 15 Dec 2010 13:37:30 +0000 Subject: Dealing with pywin32 on Linux In-Reply-To: References: Message-ID: <4D08C49A.90107@timgolden.me.uk> On 15/12/2010 12:58, Benedict Verheyen wrote: > I'm moving my development environment (python, Django, virtualenv) from Windows > to Linux (Debian more specific). However, on one app (uses Django), i have a log on > module that uses AD to authenticate users. > It's based on the active_directory wrapper of Tim Golden. > That needs the win32 module but installation of pywin32 fails on importing: > > import _winreg > ImportError: No module named _winreg > > Kind of logical in hindsight :) > > However, this makes programming and testing under Linux a bit of a pain if you're > dealing with Windows specific stuff. > What is the correct way to proceed (i want to keep my development environment in Linux)? > > I could adjust my software modules to use the Linux counterparts of the AD functions > that i have to authenticate. > Or is there another way to deal with this? Well I'm not sure how far something like WINE would take you, but I suggest that trying to develop Windows-specific code in a Linux Dev environment is creating a rod for your own back. For the specific case you mention, you should be able to switch, lock, stock & barrel to python-ldap or other LDAP modules. But that means a fairly major rewrite, plus that's only one issue. None of the Windows-specific stuff will work: registry, win32api calls, whatever you're pulling out of the pywin32 packages. TJG From benedict.verheyen at gmail.com Wed Dec 15 08:51:38 2010 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Wed, 15 Dec 2010 14:51:38 +0100 Subject: Dealing with pywin32 on Linux In-Reply-To: <4D08C49A.90107@timgolden.me.uk> References: <4D08C49A.90107@timgolden.me.uk> Message-ID: On 15/12/2010 14:37, Tim Golden wrote: > Well I'm not sure how far something like WINE would take you, > but I suggest that trying to develop Windows-specific code in > a Linux Dev environment is creating a rod for your own back. > > For the specific case you mention, you should be able to switch, > lock, stock & barrel to python-ldap or other LDAP modules. But > that means a fairly major rewrite, plus that's only one issue. > None of the Windows-specific stuff will work: registry, win32api > calls, whatever you're pulling out of the pywin32 packages. > > TJG Hi, thanks for your answer. For the moment, i only need to connect to AD to authenticate. But you raise a good point that if I need more functionality, I will encounter problems. Regards, Benedict From steve at holdenweb.com Wed Dec 15 09:17:13 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 15 Dec 2010 09:17:13 -0500 Subject: Dealing with pywin32 on Linux In-Reply-To: References: <4D08C49A.90107@timgolden.me.uk> Message-ID: <4D08CDE9.1060201@holdenweb.com> On 12/15/2010 8:51 AM, Benedict Verheyen wrote: > On 15/12/2010 14:37, Tim Golden wrote: > >> Well I'm not sure how far something like WINE would take you, >> but I suggest that trying to develop Windows-specific code in >> a Linux Dev environment is creating a rod for your own back. >> >> For the specific case you mention, you should be able to switch, >> lock, stock & barrel to python-ldap or other LDAP modules. But >> that means a fairly major rewrite, plus that's only one issue. >> None of the Windows-specific stuff will work: registry, win32api >> calls, whatever you're pulling out of the pywin32 packages. >> >> TJG > > Hi, > > thanks for your answer. > For the moment, i only need to connect to AD to authenticate. > But you raise a good point that if I need more functionality, I will encounter problems. > Benedict: Have you considered running a virtual Windows machine to handle the specific issues that really require a Windows environment? If the loading isn't at brutal levels VirtualBox is a very adequate solution, and of course Python user VMWare has a full range of industrial-grade solutions for virtualization. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Wed Dec 15 09:17:18 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 15 Dec 2010 09:17:18 -0500 Subject: while True or while 1 In-Reply-To: <201012151410.43852.hpj@urpla.net> References: <87hbegay3s.fsf@gmail.com> <201012151410.43852.hpj@urpla.net> Message-ID: On 12/15/2010 8:10 AM, Hans-Peter Jansen wrote: > On Tuesday 14 December 2010, 21:38:47 Arnaud Delobelle wrote: >> Christian Heimes writes: >> [...] >> >>> Tres Seavers once told me a joke like this: >>> >>> True = not not "Who's at the door?" # say it out loud! >>> >>> This was back in the old days of Zope 2.5 and Python 2.1, which >>> didn't have True and False. >> >> I almost used: >> >> True = "to be" or not "to be" # that is the question > > That's wrong: > >>>> "to be" or not "to be" > 'to be' > > You need to wrap it with bool() at least (even without interpreting > Pythons answer to the duality contradiction of consciousness for > now ;-)) > >> but didn't dare! > Yeah, if Hamlet had been a Python programmer that play would have been a light comedy. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From benedict.verheyen at gmail.com Wed Dec 15 09:25:11 2010 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Wed, 15 Dec 2010 15:25:11 +0100 Subject: Dealing with pywin32 on Linux In-Reply-To: <4D08CDE9.1060201@holdenweb.com> References: <4D08C49A.90107@timgolden.me.uk> <4D08CDE9.1060201@holdenweb.com> Message-ID: On 15/12/2010 15:17, Steve Holden wrote: >> >> Hi, >> >> thanks for your answer. >> For the moment, i only need to connect to AD to authenticate. >> But you raise a good point that if I need more functionality, I will encounter problems. >> > Benedict: > > Have you considered running a virtual Windows machine to handle the > specific issues that really require a Windows environment? If the > loading isn't at brutal levels VirtualBox is a very adequate solution, > and of course Python user VMWare has a full range of industrial-grade > solutions for virtualization. > > regards > Steve Hi Steve, good suggestion. I use VirtualBox for other needs so it's not a lot of hassle to set one up. Thanks ! Regards, Benedict From tjreedy at udel.edu Wed Dec 15 10:01:15 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 15 Dec 2010 10:01:15 -0500 Subject: Proposed changes to logging defaults In-Reply-To: <4d088078$0$44007$742ec2ed@news.sonic.net> References: <3763d355-9074-485c-a694-031d600d5b84@m11g2000vbs.googlegroups.com> <4d088078$0$44007$742ec2ed@news.sonic.net> Message-ID: On 12/15/2010 3:46 AM, John Nagle wrote: > You're assuming that the logging package has the right to blither > on the default sys.stderr. The Python stdlib *already* assumes that it can write to stderr. Using logging instead will make it easier for app writers to do something else. -- Terry Jan Reedy From dmitrey.kroshko at scipy.org Wed Dec 15 10:29:50 2010 From: dmitrey.kroshko at scipy.org (dmitrey) Date: Wed, 15 Dec 2010 07:29:50 -0800 (PST) Subject: New OpenOpt/FuncDesigner release 0.32 Message-ID: <631ec423-9cac-4d77-ba8d-b40d7ae7b354@j3g2000vbi.googlegroups.com> Hi all, I'm glad to inform you about new quarterly OpenOpt/FuncDesigner release (0.32): OpenOpt: * New class: LCP (and related solver) * New QP solver: qlcp * New NLP solver: sqlcp * New large-scale NSP (nonsmooth) solver gsubg. Currently it still requires lots of improvements (especially for constraints - their handling is very premature yet and often fails), but since the solver sometimes already works better than ipopt, algencan and other competitors it was tried with, I decided to include the one into the release. * Now SOCP can handle Ax <= b constraints (and bugfix for handling lb <= x <= ub has been committed) * Some other fixes and improvements FuncDesigner: * Add new function removeAttachedConstraints * Add new oofuns min and max (their capabilities are quite restricted yet) * Systems of nonlinear equations: possibility to assign personal tolerance for an equation * Some fixes and improvements For more details see our forum entry http://forum.openopt.org/viewtopic.php?id=325 Regards, D. From stefan.sonnenberg at pythonmeister.com Wed Dec 15 10:54:24 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Wed, 15 Dec 2010 16:54:24 +0100 Subject: Dealing with pywin32 on Linux In-Reply-To: References: Message-ID: <4D08E4B0.1080007@pythonmeister.com> Am 15.12.2010 13:58, schrieb Benedict Verheyen: > Hi, > > > I'm moving my development environment (python, Django, virtualenv) from Windows > to Linux (Debian more specific). However, on one app (uses Django), i have a log on > module that uses AD to authenticate users. > It's based on the active_directory wrapper of Tim Golden. > That needs the win32 module but installation of pywin32 fails on importing: > > import _winreg > ImportError: No module named _winreg > > Kind of logical in hindsight :) > > However, this makes programming and testing under Linux a bit of a pain if you're > dealing with Windows specific stuff. > What is the correct way to proceed (i want to keep my development environment in Linux)? > > I could adjust my software modules to use the Linux counterparts of the AD functions > that i have to authenticate. > Or is there another way to deal with this? > > Thanks for any insight, > > Cheers, > Benedict > Just change to LDAP as authentication method. Even Active Directory offers LDAP (w/o SSL), and there are modules to interact with LDAP using python. And, it is platform indipendent. See here: http://www.python-ldap.org/ I've done this quite often to auth users in an AD with apache/ldap-auth. From tim.arnold at sas.com Wed Dec 15 12:38:50 2010 From: tim.arnold at sas.com (Tim Arnold) Date: Wed, 15 Dec 2010 12:38:50 -0500 Subject: How to pop the interpreter's stack? References: Message-ID: "Ethan Furman" wrote in message news:mailman.4.1292379995.6505.python-list at python.org... > kj wrote: >> The one thing I don't like about this strategy is that the tracebacks >> of exceptions raised during the execution of __pre_spam include one >> unwanted stack level (namely, the one corresponding to __pre_spam >> itself). >> >> __pre_spam should be completely invisible and unobtrusive > > I am unaware of any way to accomplish what you desire. I also think this > is one of those things that's not worth fighting -- how often are you > going to see such a traceback? When somebody makes a coding mistake? I > would say change the name (assuming yours was a real example) to something > more meaningful like _spam_arg_verifier and call it good. > > Alternatively, perhaps you could make a more general arg_verifier that > could be used for all such needs, and then your traceback would have: > > caller > > spam > > arg_verifier > > and that seems useful to me (it is, in fact, how I have mine set up). > > Hope this helps! > > ~Ethan~ I thought people would advise using a decorator for this one. Wouldn't that work? thanks, --Tim From ethan at stoneleaf.us Wed Dec 15 12:54:27 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 15 Dec 2010 09:54:27 -0800 Subject: O'Reilly Python Certification Message-ID: <4D0900D3.10000@stoneleaf.us> So I just got an e-mail from O'Reilly and their School of Technology about a Python Certification course... anybody have any experience with this? It also says Steve Holden is involved -- is this True? (Steve?) ~Ethan~ PS Can you tell I've been programming? ;) From steve at holdenweb.com Wed Dec 15 13:14:26 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 15 Dec 2010 13:14:26 -0500 Subject: O'Reilly Python Certification In-Reply-To: <4D0900D3.10000@stoneleaf.us> References: <4D0900D3.10000@stoneleaf.us> Message-ID: <4D090582.5020906@holdenweb.com> On 12/15/2010 12:54 PM, Ethan Furman wrote: > So I just got an e-mail from O'Reilly and their School of Technology > about a Python Certification course... anybody have any experience with > this? > > It also says Steve Holden is involved -- is this True? (Steve?) > Well, it's not not not False. You think O'Reilly would publish lies on their web site? :-) I am a little more that involved. In ham and eggs the chicken is involved. I am committed, like the pig, having got three of the four classes into production after almost two years' work. So for those of you who may have wondered why I have been on c.l.py only sporadically lately, now you know. The certificate will come from the University of Illinois after approximately 160 hours of study. By the end of the series you should have a substantial corpus of Python code that you have typed in yourself, understand and can discuss with potential employers and others. You will have a fair knowledge of Python and you will be accustomed to test-driven development. > ~Ethan~ > > PS > > Can you tell I've been programming? ;) I would really like to hear from anyone who takes the class. I would like to ensure that it is kept up to date and relevant with continuous improvements, and feedback will be invaluable in helping me to achieve this goal. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From sohel807 at gmail.com Wed Dec 15 13:22:47 2010 From: sohel807 at gmail.com (Akand Islam) Date: Wed, 15 Dec 2010 10:22:47 -0800 (PST) Subject: Sage's Python References: <46480720-4334-47ce-a35c-4895472b351b@29g2000prb.googlegroups.com> Message-ID: <93700dc9-2c7e-434e-af46-60a7a9ef90cc@j13g2000vbp.googlegroups.com> On Dec 14, 1:51?pm, Emile van Sebille wrote: > On 12/14/2010 10:27 AM Akand Islam said... > > > On Dec 13, 4:33 pm, "Rhodri James" > > wrote: > >> On Fri, 10 Dec 2010 17:11:55 -0000, Akand Islam ?wrote: > >>> In my system (Ubuntu 10.04) there are sage-4.6, python 2.6.5, tk8.5- > >>> dev installed. When I give command from terminal "sage -f > >>> python-2.6.5.p8" to get sage's python it shows following message: > > >>> ? No command 'sage' found, did you mean: > > This means that no sage command was found on your path. ?Check to be > sure that ~/Desktop is in your path. > > Emile Thanks Emile. -- Akand. From hpj at urpla.net Wed Dec 15 15:10:05 2010 From: hpj at urpla.net (Hans-Peter Jansen) Date: Wed, 15 Dec 2010 21:10:05 +0100 Subject: default argument in method In-Reply-To: References: Message-ID: <201012152110.05744.hpj@urpla.net> On Monday 13 December 2010, 18:14:27 Godson Gera wrote: > On Sun, Dec 12, 2010 at 5:05 PM, ernest wrote: > > Hi, > > > > I'd like to have a reference to an instance attribute as > > default argument in a method. It doesn't work because > > "self" is not defined at the time the method signature is > > evaluated. For example: > > > > class C(object): > > def __init__(self): > > self.foo = 5 > > def m(self, val=self.foo): > > return val > > > > Raises NameError because 'self' is not defined. > > You can defined foo outside the __init__ and can access it inside > methods using self.foo > > class C(object): > foo=5 > def __init__(self): > print self.foo > def m(self,val=foo): > return val > > class attributes can be accessed with out self before them in method > signatures. However, becareful if you change the value of foo inside > any method, the method signature will still hold on to old value. Since this is a major pitfall, it might be worth mentioning, that mutable default arguments are generally a bad idea, as the default arguments are evaluated just once, hence e.g. using an empty list might contain the items, that were appended in earlier calls of this method.. Code, that _relies_ on such behavior should be yanked instantaneous and the producer of such code should be punished with coding APL? on a dubeolsik hangul keyboard? for a year at least.. Pete ?) Not, that APL is a bad language per se, but even one liners tend to be rather cryptic for usual brains. Let's say it with Dijkstra: "APL is a mistake, carried out through perfection..." but given the second constraint, it's going to be a, hmm, challenge. http://en.wikipedia.org/wiki/APL_(programming_language) ?) http://en.wikipedia.org/wiki/Keyboard_layout#Dubeolsik From python.list at tim.thechases.com Wed Dec 15 15:40:33 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 15 Dec 2010 14:40:33 -0600 Subject: O'Reilly Python Certification In-Reply-To: <4D0900D3.10000@stoneleaf.us> References: <4D0900D3.10000@stoneleaf.us> Message-ID: <4D0927C1.5080209@tim.thechases.com> On 12/15/2010 11:54 AM, Ethan Furman wrote: > So I just got an e-mail from O'Reilly and their School of Technology > about a Python Certification course... anybody have any experience with > this? > > It also says Steve Holden is involved -- is this True? you should just test for the truthiness without comparing to True: if is_involved(steve_holden): your_code() rather than asking if is_involved(steve_holden) is True: your_code() ;-) On a more serious note, it would be interesting to know if it's possible to test out of the certification for those of us that have been using Python for a long time. -tkc From steve at holdenweb.com Wed Dec 15 16:11:38 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 15 Dec 2010 16:11:38 -0500 Subject: O'Reilly Python Certification In-Reply-To: <4D0927C1.5080209@tim.thechases.com> References: <4D0900D3.10000@stoneleaf.us> <4D0927C1.5080209@tim.thechases.com> Message-ID: On 12/15/2010 3:40 PM, Tim Chase wrote: > On a more serious note, it would be interesting to know if it's possible > to test out of the certification for those of us that have been using > Python for a long time. That's an interesting idea - let a bunch of experienced Python users tell me what a lousy job I have done of explaining the language. :) Seriously, I would be interested, and it's a terrific idea. I can't do anything before January, but if anyone is interested in taking part in such a review of the materials I'd be grateful if they would contact me privately by email on a "no promises" basis. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From anil.jupiter9 at gmail.com Wed Dec 15 16:21:26 2010 From: anil.jupiter9 at gmail.com (jupiter) Date: Wed, 15 Dec 2010 13:21:26 -0800 (PST) Subject: Help regarding pattern matching Message-ID: Hi People, I need some ideas on how to find pattern in random data series like stock chart. What I want is to be able to find Head & Shoulder pattern in chart. Thanx Anil From stefan.sonnenberg at pythonmeister.com Wed Dec 15 16:21:58 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Wed, 15 Dec 2010 22:21:58 +0100 Subject: O'Reilly Python Certification In-Reply-To: References: <4D0900D3.10000@stoneleaf.us> <4D0927C1.5080209@tim.thechases.com> Message-ID: <4D093176.3010109@pythonmeister.com> Am 15.12.2010 22:11, schrieb Steve Holden: > On 12/15/2010 3:40 PM, Tim Chase wrote: >> On a more serious note, it would be interesting to know if it's possible >> to test out of the certification for those of us that have been using >> Python for a long time. > That's an interesting idea - let a bunch of experienced Python users > tell me what a lousy job I have done of explaining the language. :) > > Seriously, I would be interested, and it's a terrific idea. I can't do > anything before January, but if anyone is interested in taking part in > such a review of the materials I'd be grateful if they would contact me > privately by email on a "no promises" basis. > > regards > Steve I think he meant: take the test without study first. I'd be interested in both, though. From van.lindberg at gmail.com Wed Dec 15 16:46:40 2010 From: van.lindberg at gmail.com (VanL) Date: Wed, 15 Dec 2010 15:46:40 -0600 Subject: Help influence which tutorials are given at PyCon 2011 Message-ID: PyCon is made up of a number of different parts, each with its own goals. For the talks presented during the conference portion of PyCon, we go for both breadth and quality. There are enough different sessions and different tracks that each person can customize their PyCon experience according to their interests. For tutorials, the goal is slightly different. We want to present tutorials that help developers deal effectively with their most common day-to-day challenges. We categorized the various tutorial proposals into a number of broad buckets. You can vote on which topics you would like to see at PyCon 2011! We will take this information into account when deciding which tutorials will be presented. You can view the poll at . From greg.ewing at canterbury.ac.nz Wed Dec 15 16:50:19 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 16 Dec 2010 10:50:19 +1300 Subject: Proposed changes to logging defaults In-Reply-To: References: <3763d355-9074-485c-a694-031d600d5b84@m11g2000vbs.googlegroups.com> <4d088078$0$44007$742ec2ed@news.sonic.net> Message-ID: <8msrgrFeo3U1@mid.individual.net> Terry Reedy wrote: > On 12/15/2010 3:46 AM, John Nagle wrote: > >> You're assuming that the logging package has the right to blither >> on the default sys.stderr. > > The Python stdlib *already* assumes that it can write to stderr. Also ISTM that any program relying on nothing it calls ever writing to stderr would be rather fragile. -- Greg From python.list at tim.thechases.com Wed Dec 15 17:01:04 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 15 Dec 2010 16:01:04 -0600 Subject: O'Reilly Python Certification In-Reply-To: References: <4D0900D3.10000@stoneleaf.us> <4D0927C1.5080209@tim.thechases.com> Message-ID: <4D093AA0.1050803@tim.thechases.com> On 12/15/2010 03:11 PM, Steve Holden wrote: > On 12/15/2010 3:40 PM, Tim Chase wrote: >> On a more serious note, it would be interesting to know if it's possible >> to test out of the certification for those of us that have been using >> Python for a long time. > > That's an interesting idea - let a bunch of experienced Python users > tell me what a lousy job I have done of explaining the language. :) Actually Stephan read what I intended -- a way to take the final test (and receive the cert) without belaboring the taker or you with the actual course-work. I did that with several classes back in college where I needed a prereq. for a class but was able to ace the final for that prereq to show the prof(s) that I knew the material. Saved me a semester-long class in each case, and saved the professor the time spent grading my stuff. That said, having peer-review of your course material can (well, *should*) only improve it. -tkc From chris at simplistix.co.uk Wed Dec 15 17:03:45 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Wed, 15 Dec 2010 22:03:45 +0000 Subject: Added Python, WSGI to XAMPP In-Reply-To: <4D06C130.9040506@verizon.net> References: <4CFA4305.10004@it.uu.se> <4CFD6825.9020200@simplistix.co.uk> <4CFD8B29.3020006@verizon.net> <4D014A3D.7020101@verizon.net> <4D06AD69.4030302@simplistix.co.uk> <4D06B6D1.6080208@verizon.net> <4D06B671.5020601@simplistix.co.uk> <4D06C130.9040506@verizon.net> Message-ID: <4D093B41.2050707@simplistix.co.uk> On 14/12/2010 00:58, Gerry Reno wrote: > What I really don't like right off is that Pyramid is contorting the MVC > model That specific pattern, I'm afraid, is a little antiquated nowadays, particularly when it comes to web apps... > The VIEW is the bits that stream out of the webserver back to the users > browser. Yep, and in Pyramid I guess this would be the template renderer, which is usually a decorator on the view function or class. The view's job is to process a request and turn it into a response dictionary. That sounds a lot like your controller to me ;-) > The CONTROLLER is the code that gathers all the pieces from > the model and constructs the python code Slightly scared as to what "constructed the python code" might mean :-S > that is then fed to the engine > that then creates the view. And just because the controller navigates > the logic to dynamically contruct/render a view, that does not make 'it' > the view. Well, for me, the MVC isn't really what happens anymore, here's my take: - the model nowadays has all the "business logic" in it, rather than just the data. The model is now a collection of objects that can be interacted on through many/any UIs needed, some of which may be web apps. - web apps are *always* a collection of request/response transactions. As such, the "control" layer does just become a "view" that does that. - singleton objects and other stuff that used to live in a "control" are now factored out into utilities and services (of which zope.component provides a pretty good abstraction, and doesn't really have anything to do with Zope, other than the fact that Zope makes use of it). Welcome to the 2nd decade in the new millenium ;-) Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From greno at verizon.net Wed Dec 15 17:28:56 2010 From: greno at verizon.net (Gerry Reno) Date: Wed, 15 Dec 2010 17:28:56 -0500 Subject: Pyramid and MVC (split from: Re: Added Python, WSGI to XAMPP) In-Reply-To: <4D093B41.2050707@simplistix.co.uk> References: <4CFA4305.10004@it.uu.se> <4CFD6825.9020200@simplistix.co.uk> <4CFD8B29.3020006@verizon.net> <4D014A3D.7020101@verizon.net> <4D06AD69.4030302@simplistix.co.uk> <4D06B6D1.6080208@verizon.net> <4D06B671.5020601@simplistix.co.uk> <4D06C130.9040506@verizon.net> <4D093B41.2050707@simplistix.co.uk> Message-ID: <4D094128.3010807@verizon.net> On 12/15/2010 05:03 PM, Chris Withers wrote: > On 14/12/2010 00:58, Gerry Reno wrote: >> What I really don't like right off is that Pyramid is contorting the MVC >> model > > That specific pattern, I'm afraid, is a little antiquated nowadays, > particularly when it comes to web apps... > >> The VIEW is the bits that stream out of the webserver back to the users >> browser. > > Yep, and in Pyramid I guess this would be the template renderer, which > is usually a decorator on the view function or class. The view's job > is to process a request and turn it into a response dictionary. That > sounds a lot like your controller to me ;-) > >> The CONTROLLER is the code that gathers all the pieces from >> the model and constructs the python code > > Slightly scared as to what "constructed the python code" might mean :-S > >> that is then fed to the engine >> that then creates the view. And just because the controller navigates >> the logic to dynamically contruct/render a view, that does not make 'it' >> the view. > > Well, for me, the MVC isn't really what happens anymore, here's my take: > > - the model nowadays has all the "business logic" in it, rather than > just the data. The model is now a collection of objects that can be > interacted on through many/any UIs needed, some of which may be web apps. > > - web apps are *always* a collection of request/response transactions. > As such, the "control" layer does just become a "view" that does that. > > - singleton objects and other stuff that used to live in a "control" > are now factored out into utilities and services (of which > zope.component provides a pretty good abstraction, and doesn't really > have anything to do with Zope, other than the fact that Zope makes use > of it). > > Welcome to the 2nd decade in the new millenium ;-) > > Chris > It doesn't matter whether you are building a desktop app or a webapp. MVC still applies. And that includes when things like Ajax are added to the mix because Ajax just performs a mini-MVC transaction. The problems arise when people start rigidly thinking that M only meant database. M means model, model means any source that emits data. A database, another webapp, whatever, that is M. The view as I said before is just the bits streaming out of the webserver back to the client device. There should be NOTHING on the server call view-anything. The view only exists on the clients. The view is the result of what the controllers(servers) in conjunction with renderers emit as their work product. -Gerry From steve+comp.lang.python at pearwood.info Wed Dec 15 18:56:31 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Dec 2010 23:56:31 GMT Subject: default argument in method References: Message-ID: <4d0955ae$0$29997$c3e8da3$5496439d@news.astraweb.com> On Wed, 15 Dec 2010 21:10:05 +0100, Hans-Peter Jansen wrote: > Since this is a major pitfall, it might be worth mentioning, that > mutable default arguments are generally a bad idea, as the default > arguments are evaluated just once, hence e.g. using an empty list might > contain the items, that were appended in earlier calls of this method.. It's only a pitfall for users who expect that default arguments are re- created every time you call the function; it's only a bad idea for code which relies on the default arguments being re-created each time. If you hold misunderstandings about the behaviour of a language, you'll have trouble understanding what code does. Default arguments are no different from any other feature. > Code, that _relies_ on such behavior should be yanked instantaneous and > the producer of such code should be punished with coding APL? on a > dubeolsik hangul keyboard? for a year at least.. Python code that relies on default arguments to *not* be re-created on each function call is no worse than (say) Ruby code that relies on default arguments *to* be re-created each time. I don't mean to be elitist (ah, who am I fooling, of course I do), but when coders of the skill and experience of the Effbot and Guido use mutable defaults, who are you to say they shouldn't? http://effbot.org/zone/default-values.htm http://www.python.org/doc/essays/graphs/ -- Steven From ian.g.kelly at gmail.com Wed Dec 15 19:36:10 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 15 Dec 2010 17:36:10 -0700 Subject: Added Python, WSGI to XAMPP In-Reply-To: <4D06C130.9040506@verizon.net> References: <4CFA4305.10004@it.uu.se> <4CFD6825.9020200@simplistix.co.uk> <4CFD8B29.3020006@verizon.net> <4D014A3D.7020101@verizon.net> <4D06AD69.4030302@simplistix.co.uk> <4D06B6D1.6080208@verizon.net> <4D06B671.5020601@simplistix.co.uk> <4D06C130.9040506@verizon.net> Message-ID: On Mon, Dec 13, 2010 at 5:58 PM, Gerry Reno wrote: > The VIEW is the bits that stream out of the webserver back to the users > browser. ?The CONTROLLER is the code that gathers all the pieces from > the model and constructs the python code that is then fed to the engine > that then creates the view. ?And just because the controller navigates > the logic to dynamically contruct/render a view, that does not make 'it' > the view. In traditional MVC, the controller is the part that receives the user input, decides how to react to it, and instructs the model to update itself accordingly. It is not supposed to be some sort of intermediary between the model and the view, as many people seem to make it; the view is supposed to gather the data it needs to render itself directly from the model. In that light, I think that this quote from the Django FAQ is defensible: > In our interpretation of MVC, the ?view? describes the data that gets presented to the user. It?s not necessarily how the data looks, but which data is presented. The view describes which data you see, not how you see it. It?s a subtle distinction. Traditionally, the view would describe both of these things, but since "how you see it" is ultimately decided by the user's browser, they are fundamentally separated in the context of the web. The Django template-view split is in recognition of this fact. As for where the controller went, there are basically two decisions that need to be made when input is received: how to update the model as a result, and what data should be displayed next. The former decision belongs to the controller, the latter to the view. But in a web app, these two things tend to be highly correlated, and there seems to be little reason to separate them out into distinct components. This part then is both controller and view, and which word we use for it is not terribly important. I suppose that "view" tends to prevail since there are other components, such as URL dispatch, that are controllerish in nature. For these reasons, I find that in practice traditional MVC does not lend itself well to the HTTP request/response cycle, where the "view" as you define it has no access to the model and lacks any continuity whatsoever from one request to the next; but the Django MTV approach works just fine once you're willing to accept that it's not the same thing. Cheers, Ian From prog at vtr.net Wed Dec 15 19:46:38 2010 From: prog at vtr.net (craf) Date: Wed, 15 Dec 2010 21:46:38 -0300 Subject: Calling function from another module Message-ID: <1292460398.2086.11.camel@cristian-desktop> Hi. The query code is as follows: ------------------------------------------------------ import Tkinter import tkMessageBox class App: def __init__(self, master): master.protocol("WM_DELETE_WINDOW",quit) def quit(): if tkMessageBox.askyesno('','Exit'): master.quit() master =Tkinter.Tk() app = App(master) master.mainloop() ------------------------------------------------------- As you can see, when I run and close the main window displays a text box asking if you want to quit, if so, closes application. Question: Is it possible to define the quit() function in another separate module?. I tried it, but it throws the error that the global name 'master' is not defined. Thanks in advance. Regards Cristian Abarz?a From hpj at urpla.net Wed Dec 15 20:09:33 2010 From: hpj at urpla.net (Hans-Peter Jansen) Date: Thu, 16 Dec 2010 02:09:33 +0100 Subject: default argument in method In-Reply-To: <4d0955ae$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <4d0955ae$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <201012160209.34049.hpj@urpla.net> On Thursday 16 December 2010, 00:56:31 Steven D'Aprano wrote: > On Wed, 15 Dec 2010 21:10:05 +0100, Hans-Peter Jansen wrote: > > Since this is a major pitfall, it might be worth mentioning, that > > mutable default arguments are generally a bad idea, as the default > > arguments are evaluated just once, hence e.g. using an empty list > > might contain the items, that were appended in earlier calls of > > this method.. > > It's only a pitfall for users who expect that default arguments are > re- created every time you call the function; it's only a bad idea > for code which relies on the default arguments being re-created each > time. > > If you hold misunderstandings about the behaviour of a language, > you'll have trouble understanding what code does. Default arguments > are no different from any other feature. > > > Code, that _relies_ on such behavior should be yanked instantaneous > > and the producer of such code should be punished with coding APL? > > on a dubeolsik hangul keyboard? for a year at least.. > > Python code that relies on default arguments to *not* be re-created > on each function call is no worse than (say) Ruby code that relies on > default arguments *to* be re-created each time. > > I don't mean to be elitist (ah, who am I fooling, of course I do), > but when coders of the skill and experience of the Effbot and Guido > use mutable defaults, who are you to say they shouldn't? > > http://effbot.org/zone/default-values.htm > http://www.python.org/doc/essays/graphs/ Hmm, thanks for the pointers, Steven. I stand corrected, as I won't argue with taste.. I like the part about the disastrous results specially. If such code would be used in any collaborations, I would expect an explicit comment at least. Pete From greno at verizon.net Wed Dec 15 20:46:46 2010 From: greno at verizon.net (Gerry Reno) Date: Wed, 15 Dec 2010 20:46:46 -0500 Subject: Added Python, WSGI to XAMPP In-Reply-To: References: <4CFA4305.10004@it.uu.se> <4CFD6825.9020200@simplistix.co.uk> <4CFD8B29.3020006@verizon.net> <4D014A3D.7020101@verizon.net> <4D06AD69.4030302@simplistix.co.uk> <4D06B6D1.6080208@verizon.net> <4D06B671.5020601@simplistix.co.uk> <4D06C130.9040506@verizon.net> Message-ID: <4D096F86.80806@verizon.net> On 12/15/2010 07:36 PM, Ian Kelly wrote: > On Mon, Dec 13, 2010 at 5:58 PM, Gerry Reno wrote: > >> The VIEW is the bits that stream out of the webserver back to the users >> browser. The CONTROLLER is the code that gathers all the pieces from >> the model and constructs the python code that is then fed to the engine >> that then creates the view. And just because the controller navigates >> the logic to dynamically contruct/render a view, that does not make 'it' >> the view. >> > In traditional MVC, the controller is the part that receives the user > input, decides how to react to it, and instructs the model to update > itself accordingly. It is not supposed to be some sort of > intermediary between the model and the view, as many people seem to > make it; the view is supposed to gather the data it needs to render > itself directly from the model. In that light, I think that this > quote from the Django FAQ is defensible: > > >> In our interpretation of MVC, the ?view? describes the data that gets presented to the user. It?s not necessarily how the data looks, but which data is presented. The view describes which data you see, not how you see it. It?s a subtle distinction. >> > Traditionally, the view would describe both of these things, but since > "how you see it" is ultimately decided by the user's browser, they are > fundamentally separated in the context of the web. The Django > template-view split is in recognition of this fact. > > As for where the controller went, there are basically two decisions > that need to be made when input is received: how to update the model > as a result, and what data should be displayed next. The former > decision belongs to the controller, the latter to the view. But in a > web app, these two things tend to be highly correlated, and there > seems to be little reason to separate them out into distinct > components. This part then is both controller and view, and which > word we use for it is not terribly important. I suppose that "view" > tends to prevail since there are other components, such as URL > dispatch, that are controllerish in nature. > > For these reasons, I find that in practice traditional MVC does not > lend itself well to the HTTP request/response cycle, where the "view" > as you define it has no access to the model and lacks any continuity > whatsoever from one request to the next; but the Django MTV approach > works just fine once you're willing to accept that it's not the same > thing. > > Cheers, > Ian > > Django can use whatever approach they like. But don't call it an MVC framework and that is what they did initially at least. MTV is a contorted MVC. And it does not correlate very well with other MVC documentation which is very confusing to people. No doubt, the web is constraining. Request/response makes it difficult to have the Model independently notify the View that it needs to update itself because some state in the model has changed. That is why many of the diagrams about MVC on the web show the Controller interceding between the View and the Model. That doesn't mean MVC does not work on the web. It just means that there is a constraint imposed by the nature of the request/response stateless architecture. Maybe it's splitting hairs, but having things named 'View' on the server implies especially to newbies that the View exists on the server. The View exists on the client. And then later they discover that it's not really View but Controller and that Templates are View. I guess if we were screen-scraping we could actually have a server-side View. But normal MVC has the View on the client, and the Model and Controller in server capacities. And I don't see the value in naming things View on the server when for the most part the View (or view parts in the case of Ajax) are merely the output of render processes. -Gerry From katie at coderstack.co.uk Wed Dec 15 21:22:47 2010 From: katie at coderstack.co.uk (Katie T) Date: Thu, 16 Dec 2010 02:22:47 +0000 Subject: Help regarding pattern matching In-Reply-To: References: Message-ID: On Wed, Dec 15, 2010 at 9:21 PM, jupiter wrote: > Hi People, > > > I need some ideas on how to find pattern in random data series like stock chart. > > > What I want is to be able to find Head & Shoulder pattern in chart. Have a look at the references in: http://www.dpem.tuc.gr/fel/fm2009/Papers/Tsinaslanidis.pdf They cover a variety of algorithms for detecting such patterns. Katie -- CoderStack http://www.coderstack.co.uk/python-jobs The Software Developer Job Board From clp2 at rebertia.com Wed Dec 15 21:34:12 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 15 Dec 2010 18:34:12 -0800 Subject: Help regarding pattern matching In-Reply-To: References: Message-ID: On Wed, Dec 15, 2010 at 6:22 PM, Katie T wrote: > On Wed, Dec 15, 2010 at 9:21 PM, jupiter wrote: >> Hi People, >> >> I need some ideas on how to find pattern in random data series like stock chart. >> >> What I want is to be able to find Head & Shoulder pattern in chart. > > Have a look at the references in: > > http://www.dpem.tuc.gr/fel/fm2009/Papers/Tsinaslanidis.pdf Dead link! Cheers, Chris From katie at coderstack.co.uk Wed Dec 15 21:55:36 2010 From: katie at coderstack.co.uk (Katie T) Date: Thu, 16 Dec 2010 02:55:36 +0000 Subject: Help regarding pattern matching In-Reply-To: References: Message-ID: On Thu, Dec 16, 2010 at 2:34 AM, Chris Rebert wrote: > On Wed, Dec 15, 2010 at 6:22 PM, Katie T wrote: >> On Wed, Dec 15, 2010 at 9:21 PM, jupiter wrote: >>> Hi People, >>> >>> I need some ideas on how to find pattern in random data series like stock chart. >>> >>> What I want is to be able to find Head & Shoulder pattern in chart. >> >> Have a look at the references in: >> >> http://www.dpem.tuc.gr/fel/fm2009/Papers/Tsinaslanidis.pdf > http://uom-gr.academia.edu/ProdromosTsinaslanidis/Papers/281823/An_Examination_of_the_Head_and_Shoulders_Technical_Pattern_A_Support_of_the_Technical_Analysiss_Subjective_Nature Katie -- CoderStack http://www.coderstack.co.uk/python-jobs The Software Developer Job Board From rantingrick at gmail.com Thu Dec 16 00:06:02 2010 From: rantingrick at gmail.com (rantingrick) Date: Wed, 15 Dec 2010 21:06:02 -0800 (PST) Subject: Calling function from another module References: Message-ID: On Dec 15, 6:46?pm, craf wrote: > Hi. > > The query code is as follows: > > ------------------------------------------------------ > import Tkinter > import tkMessageBox > > class App: > ? ? def __init__(self, master): > ? ? ? ? master.protocol("WM_DELETE_WINDOW",quit) > > def quit(): > ? ? if tkMessageBox.askyesno('','Exit'): > ? ? ? ? master.quit() > > master =Tkinter.Tk() > app = App(master) > master.mainloop() > ------------------------------------------------------- > > As you can see, when I run and close the main window displays > a text box asking if you want to quit, if so, closes > application. > > Question: > > Is it possible to define the quit() function in another separate > module?. > I tried it, but it throws the error that the global name > 'master' is not defined. Please explain in detail what the "other module" is doing. And as written this class "app" looks pretty useless to me. Why subclass Tk (well it appears you "tried" to subclass it anyway) just to override capabilities that are already available within Tk? Also i see many mistakes in this very small code sample. Using my deductive logic leads me to believe that many mistakes in a small code sample translates to enormous mistakes in a larger code base. So feel free to ramble incessantly about the intricate workings of this jewel of Python scripting you are soon to drop on this malnourished group of coders. From greg.ewing at canterbury.ac.nz Thu Dec 16 01:09:32 2010 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Thu, 16 Dec 2010 19:09:32 +1300 Subject: ANN: PyGUI 2.3.2 Message-ID: PyGUI 2.3.2 is available: http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ This version fixes a problem in Cocoa whereby the coordinate system for drawing in a Pixmap was upside down, and corrects a slight mistake in the Canvas documentation. What is PyGUI? -------------- PyGUI is a cross-platform GUI toolkit designed to be lightweight and have a highly Pythonic API. -- Gregory Ewing greg.ewing at canterbury.ac.nz http://www.cosc.canterbury.ac.nz/greg.ewing/ From steve at holdenweb.com Thu Dec 16 01:48:46 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 16 Dec 2010 01:48:46 -0500 Subject: O'Reilly Python Certification In-Reply-To: <4D093176.3010109@pythonmeister.com> References: <4D0900D3.10000@stoneleaf.us> <4D0927C1.5080209@tim.thechases.com> <4D093176.3010109@pythonmeister.com> Message-ID: On 12/15/2010 4:21 PM, Stefan Sonnenberg-Carstens wrote: > Am 15.12.2010 22:11, schrieb Steve Holden: >> On 12/15/2010 3:40 PM, Tim Chase wrote: >>> On a more serious note, it would be interesting to know if it's possible >>> to test out of the certification for those of us that have been using >>> Python for a long time. >> That's an interesting idea - let a bunch of experienced Python users >> tell me what a lousy job I have done of explaining the language. :) >> >> Seriously, I would be interested, and it's a terrific idea. I can't do >> anything before January, but if anyone is interested in taking part in >> such a review of the materials I'd be grateful if they would contact me >> privately by email on a "no promises" basis. >> >> regards >> Steve > I think he meant: take the test without study first. > I'd be interested in both, though. > There isn't a test. The award of the certificate is based on providing working solutions to projects at the end of each lesson. Bear in mind I have not spoken to my O'Reilly contacts about whether they would be OK with such a scheme, hence the "no promises". regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From nagle at animats.com Thu Dec 16 02:21:27 2010 From: nagle at animats.com (John Nagle) Date: Wed, 15 Dec 2010 23:21:27 -0800 Subject: Links and pointers to basics of soap and suds In-Reply-To: References: Message-ID: <4d09be05$0$43998$742ec2ed@news.sonic.net> On 12/15/2010 5:14 AM, Steve Holden wrote: > On 12/15/2010 7:38 AM, srinivas hn wrote: >> Hi All, >> >> I am very new to the soap and its python client suds. Can anyone tell me >> how the actual will happens i nthe webservices including suds and soap API. >> > That's a bit like saying "I need to go around the corner. Would you mind > teaching me to drive?". > > Google for phrases like "web services architecture" and "SOAP WSDL" to > get some idea of how these technologies are put together. This assumes, > of course, that you already possess a fair idea of how the web is put > together. > > regards > Steve The "suds" module is a quite good client for well-written SOAP servers. Basically, it's a system for making a remote procedure call to a service on another machine. The "suds" module is quite easy to use if the service you're calling already exists, has a correct WSDL file describing the interface, and the documentation for users of the interface is correct. I use it to talk to Dun and Bradstreet's business database, for which it works quite well. Most simpler web services today tend to just encode queries in the URL and send back not-too-strict XML or JSON. This is called a "REST" interface. John Nagle From benedict.verheyen at gmail.com Thu Dec 16 03:09:55 2010 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Thu, 16 Dec 2010 09:09:55 +0100 Subject: Dealing with pywin32 on Linux In-Reply-To: <4D08E4B0.1080007@pythonmeister.com> References: <4D08E4B0.1080007@pythonmeister.com> Message-ID: On 15/12/2010 16:54, Stefan Sonnenberg-Carstens wrote: > Just change to LDAP as authentication method. > Even Active Directory offers LDAP (w/o SSL), and there > are modules to interact with LDAP using python. > And, it is platform indipendent. > > See here: http://www.python-ldap.org/ > > I've done this quite often to auth users in an AD with apache/ldap-auth. I've already ported some code yesterday with python-ldap. It works so it's fine for now, Regards, Benedict From nitinpawar432 at gmail.com Thu Dec 16 03:11:05 2010 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Thu, 16 Dec 2010 13:41:05 +0530 Subject: O'Reilly Python Certification In-Reply-To: References: <4D0900D3.10000@stoneleaf.us> <4D0927C1.5080209@tim.thechases.com> <4D093176.3010109@pythonmeister.com> Message-ID: Can someone provide any links or any starting points on how to apply and what are the prerequisites Thanks, Nitin On Thu, Dec 16, 2010 at 12:18 PM, Steve Holden wrote: > On 12/15/2010 4:21 PM, Stefan Sonnenberg-Carstens wrote: > > Am 15.12.2010 22:11, schrieb Steve Holden: > >> On 12/15/2010 3:40 PM, Tim Chase wrote: > >>> On a more serious note, it would be interesting to know if it's > possible > >>> to test out of the certification for those of us that have been using > >>> Python for a long time. > >> That's an interesting idea - let a bunch of experienced Python users > >> tell me what a lousy job I have done of explaining the language. :) > >> > >> Seriously, I would be interested, and it's a terrific idea. I can't do > >> anything before January, but if anyone is interested in taking part in > >> such a review of the materials I'd be grateful if they would contact me > >> privately by email on a "no promises" basis. > >> > >> regards > >> Steve > > I think he meant: take the test without study first. > > I'd be interested in both, though. > > > There isn't a test. The award of the certificate is based on providing > working solutions to projects at the end of each lesson. > > Bear in mind I have not spoken to my O'Reilly contacts about whether > they would be OK with such a scheme, hence the "no promises". > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ > See Python Video! http://python.mirocommunity.org/ > Holden Web LLC http://www.holdenweb.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From orasnita at gmail.com Thu Dec 16 04:36:30 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Thu, 16 Dec 2010 11:36:30 +0200 Subject: Added Python, WSGI to XAMPP References: <4CFA4305.10004@it.uu.se> <4CFD6825.9020200@simplistix.co.uk> <4CFD8B29.3020006@verizon.net><4D014A3D.7020101@verizon.net> <4D06AD69.4030302@simplistix.co.uk><4D06B6D1.6080208@verizon.net> <4D06B671.5020601@simplistix.co.uk><4D06C130.9040506@verizon.net> Message-ID: <08B25692CE8542B386238F7E02D317DD@teddy> From: "Ian Kelly" On Mon, Dec 13, 2010 at 5:58 PM, Gerry Reno wrote: > The VIEW is the bits that stream out of the webserver back to the users > browser. Why only to the user's browser? A web app could also offer the results in formats that can be accessed with something else than a browser. The view just offer the results, no matter what way. > The CONTROLLER is the code that gathers all the pieces from > the model and constructs the python code that is then fed to the engine > that then creates the view. And just because the controller navigates > the logic to dynamically contruct/render a view, that does not make 'it' > the view. > In traditional MVC, the controller is the part that receives the user > input, decides how to react to it, and instructs the model to update > itself accordingly. It is not supposed to be some sort of > intermediary between the model and the view, as many people seem to > make it; the view is supposed to gather the data it needs to render > itself directly from the model. How can the view know what data it should render if the controller doesn't inform it about it? It is less important if the view uses a smart templating system that doesn't need to ask the controller for data but can access the model directly, but the view or that templating system need to be informed by the controller what data need to ask from the model, so we can say that the intermediary is still the controller. And accessing the model directly from the view/templating system is not a good idea, because MVC is also prefered because it decouples the programming code and the web design, and in some cases it can be a security issue if the web designer that might not know programming would be able to change by mistake or with intention the code from the view/templating system that access the model. > In that light, I think that this quote from the Django FAQ is defensible: > > In our interpretation of MVC, the ?view? describes the data that gets presented to the user. It?s not necessarily how the data looks, but which > data is presented. The view describes which data you see, not how you see it. It?s a subtle distinction. But if the view doesn't decide how the data looks, who decide it? :-) > Traditionally, the view would describe both of these things, but since > "how you see it" is ultimately decided by the user's browser, they are > fundamentally separated in the context of the web. The Django > template-view split is in recognition of this fact. The same data can have any format that's not decided by the user browser. For example it can be displayed in .csv format, or .xls, or .xlsx, or .pdf, or .html, or it can be submitted by email, or sent to Twitter or another web site... > As for where the controller went, there are basically two decisions > that need to be made when input is received: how to update the model > as a result, and what data should be displayed next. The former > decision belongs to the controller, the latter to the view. The update of the model depends on the model and the display of results depends on the view. But the decision is controlled by the... controller. That's why it has that name, because it controls these things. Of course, the frontiers between the M and V and C might be subtle in some cases, but it is a good idea to push as much logic to the base. It is not a good idea to make the controller do the job of the model and imply in the business logic or make the view do the job of the controller and do something else than just present the data it receives. > But in a > web app, these two things tend to be highly correlated, and there > seems to be little reason to separate them out into distinct > components. This part then is both controller and view, and which > word we use for it is not terribly important. Yes, but in that case such a program wouldn't use the MVC model. And as I exemplified above, there are reasons why the view should only present the data it receives and don't access the model directly. Some web developers aren't even alowed to offer the ORM objects to the templates, although the coding would be much easier that way, but need to generate other objects in the controller that don't allow the web designers to change some things in the templates and access more data from the database than it is needed. > For these reasons, I find that in practice traditional MVC does not > lend itself well to the HTTP request/response cycle, where the "view" > as you define it has no access to the model and lacks any continuity > whatsoever from one request to the next; but the Django MTV approach > works just fine once you're willing to accept that it's not the same > thing. > > Cheers, Ian There is no "traditional MVC". There is just MVC or not MVC. The view shouldn't have any kind of continuity. The view should just present the data. HTTP is a stateless protocol and the controller that handles the requests, does URL dispatching, uses cookies or URL-based ways for maintaining that continuity, not the view. The so called "non-traditional" MVC idea appeared because many web apps use a lot of Javascript these days, and because of this thing Javascript gained a much bigger importance, and the Javascript programmers would like to happen everything in the view if possible because they don't like to depend so much on the server-side code. Octavian From bc at freeuk.com Thu Dec 16 05:44:28 2010 From: bc at freeuk.com (BartC) Date: Thu, 16 Dec 2010 10:44:28 -0000 Subject: while True or while 1 In-Reply-To: References: <4D051506.2060403@holdenweb.com> Message-ID: "Steve Holden" wrote in message news:mailman.462.1292214062.2649.python-list at python.org... > On 12/12/2010 2:32 PM, Christian Heimes wrote: >> Am 12.12.2010 19:31, schrieb Steve Holden: >> $ python -m timeit -n20 -- "i = 0" "while 1:" " i+=1" " if i == >> 1000000: break" >> 20 loops, best of 3: 89.7 msec per loop >> $ python -m timeit -n20 -- "i = 0" "while True:" " i+=1" " if i == >> 1000000: break" >> 20 loops, best of 3: 117 msec per loop >> No argue with that! I was merely making a point that "while 1" executes >> different byte code than "while True". Readability is important but >> sometimes speed is of the essence. "while 1" is one of the few tricks to >> speed up tight loops a bit. > > OK, but the figures you quote save you 27.3 ms per million iterations, > for a grand total saving of 27.3 ns per iteration. So "a bit" is hardly > worth considering for most programs, is it? One these is 30% faster than the other. That's an appreciable difference, which you can't really just dismiss. And you can't tell what the overall effect on a program will be: perhaps the loop will be in a library function , which might be called billions of times. -- Bartc From jeanmichel at sequans.com Thu Dec 16 06:55:20 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 16 Dec 2010 12:55:20 +0100 Subject: string identity and comparison Message-ID: <4D09FE28.4080907@sequans.com> Fellows, I'd like to illutrate the fact that comparing strings using identity is, most of the time, a bad idea. However I'm searching a short example of code that yields 2 differents object for the same string content. id('foo') 3082385472L id('foo') 3082385472L Anyone has that kind of code ? JM From bruno.desthuilliers at gmail.com Thu Dec 16 07:06:12 2010 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Thu, 16 Dec 2010 04:06:12 -0800 (PST) Subject: string identity and comparison References: Message-ID: <080f1a8f-8152-492b-8982-989a810278df@y3g2000vbm.googlegroups.com> On 16 d?c, 12:55, Jean-Michel Pichavant wrote: > Fellows, > > I'd like to illutrate the fact that comparing strings using identity is, > most of the time, a bad idea. However I'm searching a short example of > code that yields 2 differents object for the same string content. > > id('foo') > 3082385472L > id('foo') > 3082385472L > > Anyone has that kind of code ? 2 points: 1- an id is only valid for the lifetime of a given object - when the object has been collected, the id can be reused for another object. 2- in CPython, strings that would be valid Python identifiers are interned. Try using a string that would not be a valid Python identifier Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> id("Not a valid python identifier") 3076522016L >>> id("Not a valid python identifier") 3076522016L >>> s1 = "Not a valid python identifier" >>> s2 = "Not a valid python identifier" >>> s1 is s2 False >>> s1 == s2 True >>> HTH From andre.roberge at gmail.com Thu Dec 16 07:07:06 2010 From: andre.roberge at gmail.com (=?ISO-8859-1?Q?Andr=E9?=) Date: Thu, 16 Dec 2010 04:07:06 -0800 (PST) Subject: string identity and comparison In-Reply-To: Message-ID: On Thursday, December 16, 2010 7:55:20 AM UTC-4, jeanmichel wrote: > Fellows, > > I'd like to illutrate the fact that comparing strings using identity is, > most of the time, a bad idea. However I'm searching a short example of > code that yields 2 differents object for the same string content. > > id('foo') > 3082385472L > id('foo') > 3082385472L > > Anyone has that kind of code ? > > JM How about this: Python 2.6 (trunk:66714:66715M, Oct 1 2008, 18:36:04) [GCC 4.0.1 (Apple Computer, Inc. build 5370)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> a = 'spam' >>> b = 'spa' >>> c = a[:-1] >>> c 'spa' >>> id(c) 548256 >>> id(b) 548224 Or, even more simply, this: Jython 2.5.0 (Release_2_5_0:6476, Jun 16 2009, 13:33:26) [Java HotSpot(TM) Client VM (Apple Inc.)] on java1.5.0_26 Type "help", "copyright", "credits" or "license" for more information. >>> a = 'foo' >>> b = 'foo' >>> id(a) 1 >>> id(b) 2 Reusing immutable objects, for the sake of efficiency, is an implementation details which should not be relied upon (as you know since you ask for examples). Andr? From andre.roberge at gmail.com Thu Dec 16 07:07:06 2010 From: andre.roberge at gmail.com (=?ISO-8859-1?Q?Andr=E9?=) Date: Thu, 16 Dec 2010 04:07:06 -0800 (PST) Subject: string identity and comparison In-Reply-To: Message-ID: On Thursday, December 16, 2010 7:55:20 AM UTC-4, jeanmichel wrote: > Fellows, > > I'd like to illutrate the fact that comparing strings using identity is, > most of the time, a bad idea. However I'm searching a short example of > code that yields 2 differents object for the same string content. > > id('foo') > 3082385472L > id('foo') > 3082385472L > > Anyone has that kind of code ? > > JM How about this: Python 2.6 (trunk:66714:66715M, Oct 1 2008, 18:36:04) [GCC 4.0.1 (Apple Computer, Inc. build 5370)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> a = 'spam' >>> b = 'spa' >>> c = a[:-1] >>> c 'spa' >>> id(c) 548256 >>> id(b) 548224 Or, even more simply, this: Jython 2.5.0 (Release_2_5_0:6476, Jun 16 2009, 13:33:26) [Java HotSpot(TM) Client VM (Apple Inc.)] on java1.5.0_26 Type "help", "copyright", "credits" or "license" for more information. >>> a = 'foo' >>> b = 'foo' >>> id(a) 1 >>> id(b) 2 Reusing immutable objects, for the sake of efficiency, is an implementation details which should not be relied upon (as you know since you ask for examples). Andr? From __peter__ at web.de Thu Dec 16 07:16:30 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 16 Dec 2010 13:16:30 +0100 Subject: Calling function from another module References: Message-ID: craf wrote: > Hi. > > The query code is as follows: > > ------------------------------------------------------ > import Tkinter > import tkMessageBox > > > class App: > def __init__(self, master): > master.protocol("WM_DELETE_WINDOW",quit) > > > def quit(): > if tkMessageBox.askyesno('','Exit'): > master.quit() > > > master =Tkinter.Tk() > app = App(master) > master.mainloop() > ------------------------------------------------------- > > As you can see, when I run and close the main window displays > a text box asking if you want to quit, if so, closes > application. > > Question: > > Is it possible to define the quit() function in another separate > module?. > I tried it, but it throws the error that the global name > 'master' is not defined. You can have the modules import each other and then access the master as .master where you'd have to replace with the actual name of the module, but that's a bad design because (1) you create an import circle (2) functions relying on global variables already are a bad idea Your other option is to pass 'master' explicitly and then wrap it into a lambda function (or functools.partial): $ cat tkquitlib.py import tkMessageBox def quit(master): if tkMessageBox.askyesno('','Exit'): master.quit() $ cat tkquit_main.py import Tkinter import tkquitlib class App: def __init__(self, master): master.protocol("WM_DELETE_WINDOW", lambda: tkquitlib.quit(master)) master = Tkinter.Tk() app = App(master) master.mainloop() Peter From steve at holdenweb.com Thu Dec 16 07:23:40 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 16 Dec 2010 07:23:40 -0500 Subject: while True or while 1 In-Reply-To: References: <4D051506.2060403@holdenweb.com> Message-ID: On 12/16/2010 5:44 AM, BartC wrote: >> On 12/12/2010 2:32 PM, Christian Heimes wrote: >>> Am 12.12.2010 19:31, schrieb Steve Holden: >>> $ python -m timeit -n20 -- "i = 0" "while 1:" " i+=1" " if i == >>> 1000000: break" >>> 20 loops, best of 3: 89.7 msec per loop >>> $ python -m timeit -n20 -- "i = 0" "while True:" " i+=1" " if i == >>> 1000000: break" >>> 20 loops, best of 3: 117 msec per loop > >>> No argue with that! I was merely making a point that "while 1" executes >>> different byte code than "while True". Readability is important but >>> sometimes speed is of the essence. "while 1" is one of the few tricks to >>> speed up tight loops a bit. >> >> OK, but the figures you quote save you 27.3 ms per million iterations, >> for a grand total saving of 27.3 ns per iteration. So "a bit" is hardly >> worth considering for most programs, is it? > > One these is 30% faster than the other. That's an appreciable > difference, which you can't really just dismiss. > > And you can't tell what the overall effect on a program will be: perhaps > the loop will be in a library function , which might be called billions > of times. It might. But if the code it is calling does *anything* at all significant I can promise you that spending an extra 30% purely on the looping construct will still make a negligible difference to a program's execution time, and there are almost certainly going to be many other aspects of performance that will yield greater benefits from tuning. I realise that there are going to be some people who just flatly say "since 'while 1:' is quicker I am going to use it every time", and that their programs will still work. And I still maintain that (for English speakers) "while True:" is to be preferred. sholden at lifeboy ~ $ python -m timeit -- "i = 1" "while True:" " i += 1" " if i == 1000000: break" 10 loops, best of 3: 157 msec per loop sholden at lifeboy ~ $ python -m timeit -- "i = 1" "while True:" " i += 1" " if i == 1000000: break" " x = i+1" 10 loops, best of 3: 238 msec per loop sholden at lifeboy ~ $ python -m timeit -- "i = 1" "while 1:" " i += 1" " if i == 1000000: break" 10 loops, best of 3: 116 msec per loop sholden at lifeboy ~ $ python -m timeit -- "i = 1" "while 1:" " i += 1" " if i == 1000000: break" " x = i+1" 10 loops, best of 3: 195 msec per loop If binding a simple arithmetic expression adds more to the loop than the difference between "while 1:" and "while True:" you are wasting your time thinking about the savings under all but the most rigorous circumstances. Fortunately there is no penalty for ignoring my advice. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Thu Dec 16 07:28:15 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 16 Dec 2010 07:28:15 -0500 Subject: string identity and comparison In-Reply-To: <4D09FE28.4080907@sequans.com> References: <4D09FE28.4080907@sequans.com> Message-ID: On 12/16/2010 6:55 AM, Jean-Michel Pichavant wrote: > Fellows, > > I'd like to illutrate the fact that comparing strings using identity is, > most of the time, a bad idea. However I'm searching a short example of > code that yields 2 differents object for the same string content. > > id('foo') > 3082385472L > id('foo') > 3082385472L > > Anyone has that kind of code ? > > JM > >>> id("foo") 2146743808 >>> id ("f"+"o"+"o") 2146744096 >>> regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From prog at vtr.net Thu Dec 16 07:33:16 2010 From: prog at vtr.net (craf) Date: Thu, 16 Dec 2010 09:33:16 -0300 Subject: [Fwd: Re: Calling function from another module] Message-ID: <1292502796.2616.1.camel@cristian-desktop> --------- Mensaje reenviado -------- > De: Peter Otten <__peter__ at web.de> > Para: python-list at python.org > Asunto: Re: Calling function from another module > Fecha: Thu, 16 Dec 2010 13:16:30 +0100 > Grupos de noticias: comp.lang.python > > craf wrote: > > > Hi. > > > > The query code is as follows: > > > > ------------------------------------------------------ > > import Tkinter > > import tkMessageBox > > > > > > class App: > > def __init__(self, master): > > master.protocol("WM_DELETE_WINDOW",quit) > > > > > > def quit(): > > if tkMessageBox.askyesno('','Exit'): > > master.quit() > > > > > > master =Tkinter.Tk() > > app = App(master) > > master.mainloop() > > ------------------------------------------------------- > > > > As you can see, when I run and close the main window displays > > a text box asking if you want to quit, if so, closes > > application. > > > > Question: > > > > Is it possible to define the quit() function in another separate > > module?. > > I tried it, but it throws the error that the global name > > 'master' is not defined. > > You can have the modules import each other and then access the master as > .master where you'd have to replace with the actual name of > the module, but that's a bad design because > > (1) you create an import circle > (2) functions relying on global variables already are a bad idea > > Your other option is to pass 'master' explicitly and then wrap it into a > lambda function (or functools.partial): > > $ cat tkquitlib.py > import tkMessageBox > > def quit(master): > if tkMessageBox.askyesno('','Exit'): > master.quit() > > > $ cat tkquit_main.py > import Tkinter > > import tkquitlib > > class App: > def __init__(self, master): > master.protocol("WM_DELETE_WINDOW", lambda: tkquitlib.quit(master)) > > master = Tkinter.Tk() > app = App(master) > master.mainloop() > > Peter Hi Peter. ?Right!. Your example can separate the creation of the interface to the code execution. Thanks for your time. Regards Cristian From __peter__ at web.de Thu Dec 16 07:50:45 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 16 Dec 2010 13:50:45 +0100 Subject: string identity and comparison References: <4D09FE28.4080907@sequans.com> Message-ID: Steve Holden wrote: > On 12/16/2010 6:55 AM, Jean-Michel Pichavant wrote: >> Fellows, >> >> I'd like to illutrate the fact that comparing strings using identity is, >> most of the time, a bad idea. However I'm searching a short example of >> code that yields 2 differents object for the same string content. >> >> id('foo') >> 3082385472L >> id('foo') >> 3082385472L >> >> Anyone has that kind of code ? >> >> JM >> >>>> id("foo") > 2146743808 >>>> id ("f"+"o"+"o") > 2146744096 Note that the concatenation may be misleading because it's not the direct reason that the ids differ; the first string doesn't exist anymore when the second is built, but the memory location of the first "foo" is occupied (perhaps by an intermediate string) when the second "foo" is created. To illustrate: >>> id("foo") 140394722220912 >>> id("bar") 140394722220912 >>> id("foo") 140394722220912 >>> x = 1234 >>> id("foo") 140394722221008 From mark.dufour at gmail.com Thu Dec 16 07:54:37 2010 From: mark.dufour at gmail.com (Mark Dufour) Date: Thu, 16 Dec 2010 13:54:37 +0100 Subject: ANN: Shed Skin 0.7 Message-ID: Hi all, I have just released Shed Skin 0.7, an optimizing (restricted-)Python-to-C++ compiler. It comes with lots of minor fixes and some optimizations, a new Windows package (which includes GCC 4.5), and two nice new examples, for a total of 52 examples at around 14,000 lines (sloccount). Please see my blog for the full announcement: http://shed-skin.blogspot.com Or go straight to the homepage: http://shedskin.googlecode.com Please have a look at the tutorial, try it out, and report issues at the homepage. Thanks, Mark Dufour -- http://www.youtube.com/watch?v=E6LsfnBmdnk -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Thu Dec 16 07:58:06 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 16 Dec 2010 13:58:06 +0100 Subject: string identity and comparison References: <4D09FE28.4080907@sequans.com> Message-ID: Peter Otten wrote: > Steve Holden wrote: > >> On 12/16/2010 6:55 AM, Jean-Michel Pichavant wrote: >>> Fellows, >>> >>> I'd like to illutrate the fact that comparing strings using identity is, >>> most of the time, a bad idea. However I'm searching a short example of >>> code that yields 2 differents object for the same string content. >>> >>> id('foo') >>> 3082385472L >>> id('foo') >>> 3082385472L >>> >>> Anyone has that kind of code ? >>> >>> JM >>> >>>>> id("foo") >> 2146743808 >>>>> id ("f"+"o"+"o") >> 2146744096 > > Note that the concatenation may be misleading because it's not the direct > reason that the ids differ; the first string doesn't exist anymore when > the second is built, but the memory location of the first "foo" is > occupied (perhaps by an intermediate string) when the second "foo" is > created. To illustrate: > >>>> id("foo") > 140394722220912 >>>> id("bar") > 140394722220912 > >>>> id("foo") > 140394722220912 >>>> x = 1234 >>>> id("foo") > 140394722221008 Or less convoluted: >>> foo = "f" + "o" + "o" >>> foo is "foo" True From jiangsuwu88 at gmail.com Thu Dec 16 08:13:28 2010 From: jiangsuwu88 at gmail.com (brandseller) Date: Thu, 16 Dec 2010 05:13:28 -0800 (PST) Subject: Cheap Wholesale Adidas Running (paypal payment) (http://www.brandtrade66.com/ Message-ID: <6042073c-8f09-42b3-a648-82e48cc11815@q8g2000prm.googlegroups.com> Cheap Wholesale UGG Shoes (paypal payment) (http://www.brandtrade66.com/) Cheap Wholesale Ugg Boots (paypal payment) Cheap Wholesale Gucci Shoes (paypal payment) (http://www.brandtrade66.com/) Cheap Wholesale GUCCI Boots Cheap Wholesale Lacoste Shoes Cheap Wholesale LV Shoes (paypal payment) (http://www.brandtrade66.com/ ) Cheap Wholesale LV Boots Cheap Wholesale Prada Shoes (paypal payment) (http://www.brandtrade66.com/) Cheap Wholesale Timberland Shoes Cheap Wholesale D&G Shoes (paypal payment) (http://www.brandtrade66.com/) Cheap Wholesale D&G Boots Cheap Wholesale Puma Shoes Cheap Wholesale Puma AAA (paypal payment) (http://www.brandtrade66.com/) Cheap Wholesale UGG Boots Shoes Cheap Wholesale Bikkem Bergs Shoes (free shipping) Cheap Wholesale Mauri Shoes Man Cheap Wholesale Versace Shoes (paypal payment) (http://www.brandtrade66.com/) Cheap Wholesale Versace Boots Cheap Wholesale Paul Smith Shoes (free shipping) Cheap Wholesale BOSS Shoes Cheap Wholesale Burberry Shoes (paypal payment) (http://www.brandtrade66.com/ ) Cheap Wholesale Dsquared shoes Cheap Wholesale Dior Shoes (free shipping) Cheap Wholesale Dior Boots Cheap Wholesale ED Hardy Shoes (paypal payment) (http://www.brandtrade66.com/ ) Cheap Wholesale ED Hardy Boots Cheap Wholesale ED Hardy Shoes Man (paypal payment) (http://www.brandtrade66.com/ ) Cheap Wholesale Fendi Shoes (paypal payment) (http://www.brandtrade66.com/ ) Cheap Wholesale Fendi Boots Cheap Wholesale AFF Shoes (paypal payment) (http://www.brandtrade66.com/ ) Cheap Wholesale Evisu Shoes (free shipping) Cheap Wholesale 4US Shoes Cheap Wholesale Sebago Shoes (paypal payment) (http://www.brandtrade66.com/ ) Cheap Wholesale Supra Shoes Cheap Wholesale Hight Converse Shoes (paypal payment) (http://www.brandtrade66.com/ ) Cheap Wholesale Coach Boots Cheap Wholesale Coach Shoes Women Christian Louboutin (paypal payment) (http://www.brandtrade66.com/ ) Cheap Wholesale Chanel Shoes Cheap Wholesale Chanel Boots (free shipping) Cheap Wholesale Bape Shoes Cheap Wholesale Adidas Shoes (paypal payment) (http://www.brandtrade66.com/ ) Cheap Wholesale Adicolor (free shipping) Cheap Wholesale Adidas 35TH (paypal payment) (http://www.brandtrade66.com/ ) Cheap Wholesale Adidas NBA Cheap Wholesale Adidas Running (paypal payment) (http://www.brandtrade66.com/ ) Cheap Wholesale Adidas Y3 Cheap Wholesale Soccer Shoes (paypal payment) (http://www.brandtrade66.com/ ) From as at sci.fi Thu Dec 16 08:20:47 2010 From: as at sci.fi (Anssi Saari) Date: Thu, 16 Dec 2010 15:20:47 +0200 Subject: Extending Thunderbird mail client with Python References: Message-ID: John Bond writes: > Anyone have any experience with this, ideally using Python 3? I don't but there is a great need to have a working SyncML client for Thunderbird. Funambol used to have one available, but it has crashing problems with Thunderbird 3 for some people. The existing extension was done in C++. From mwilson at the-wire.com Thu Dec 16 08:50:36 2010 From: mwilson at the-wire.com (Mel) Date: Thu, 16 Dec 2010 08:50:36 -0500 Subject: string identity and comparison References: Message-ID: Jean-Michel Pichavant wrote: > Fellows, > > I'd like to illutrate the fact that comparing strings using identity is, > most of the time, a bad idea. However I'm searching a short example of > code that yields 2 differents object for the same string content. > > id('foo') > 3082385472L > id('foo') > 3082385472L > > Anyone has that kind of code ? Currently, CPython interns strings that look like identifiers. Any strings that don't look like identifiers are on their own: mwilson at tecumseth:~/sandbox/candlekit/stringlight-1$ python Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> a = 'x(3)' >>> id(a) 3075373248L >>> c='x(3)' >>> id(c) 3075373856L >>> a==c True Mel. From jeanmichel at sequans.com Thu Dec 16 08:58:46 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 16 Dec 2010 14:58:46 +0100 Subject: string identity and comparison In-Reply-To: <4D09FE28.4080907@sequans.com> References: <4D09FE28.4080907@sequans.com> Message-ID: <4D0A1B16.7040702@sequans.com> Jean-Michel Pichavant wrote: > Fellows, > > I'd like to illutrate the fact that comparing strings using identity > is, most of the time, a bad idea. However I'm searching a short > example of code that yields 2 differents object for the same string > content. > > id('foo') > 3082385472L > id('foo') > 3082385472L > > Anyone has that kind of code ? > > JM > a = 'foo' b = '%s' % a a is b >>> False Yet another Auto replied thread from myself :-/ JM From python at bdurham.com Thu Dec 16 09:20:58 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 16 Dec 2010 09:20:58 -0500 Subject: ANN: Shed Skin 0.7 In-Reply-To: References: Message-ID: <1292509258.10819.1410661291@webmail.messagingengine.com> Mark, Congratulations on your latest release! How well do python extension modules created with ShedSkin work with applications that expose a GUI, eg. Tkinter or wxPython apps? Can ShedSkin code be run in a thread and communicate with the main interpreter thread through a Queue or Lock? (Or should one use the multiprocessing module?) Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Thu Dec 16 09:52:50 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 16 Dec 2010 15:52:50 +0100 Subject: string identity and comparison In-Reply-To: <080f1a8f-8152-492b-8982-989a810278df@y3g2000vbm.googlegroups.com> References: <080f1a8f-8152-492b-8982-989a810278df@y3g2000vbm.googlegroups.com> Message-ID: <4D0A27C2.6080805@sequans.com> bruno.desthuilliers at gmail.com wrote: > On 16 d?c, 12:55, Jean-Michel Pichavant > wrote: > >> id('foo') >> 3082385472L >> id('foo') >> 3082385472L >> >> Anyone has that kind of code ? >> > > 2 points: > > > 1- an id is only valid for the lifetime of a given object - when the > object has been collected, the id can be reused for another object. > > that's exactly what happened in my example, the 2 'foo' are not the same object actually, the fact that the 2 successive id() calls return the same value is implementation specific. Thanks for pointing that out, I didn't realize in the first place. JM From jeanmichel at sequans.com Thu Dec 16 09:53:19 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 16 Dec 2010 15:53:19 +0100 Subject: string identity and comparison In-Reply-To: References: Message-ID: <4D0A27DF.7060108@sequans.com> Mel wrote: > Jean-Michel Pichavant wrote: > > >> Fellows, >> >> I'd like to illutrate the fact that comparing strings using identity is, >> most of the time, a bad idea. However I'm searching a short example of >> code that yields 2 differents object for the same string content. >> >> id('foo') >> 3082385472L >> id('foo') >> 3082385472L >> >> Anyone has that kind of code ? >> > > Currently, CPython interns strings that look like identifiers. Any strings > that don't look like identifiers are on their own: > > mwilson at tecumseth:~/sandbox/candlekit/stringlight-1$ python > Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) > [GCC 4.4.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>>> a = 'x(3)' >>>> id(a) >>>> > 3075373248L > >>>> c='x(3)' >>>> id(c) >>>> > 3075373856L > >>>> a==c >>>> > True > > > Mel. > thanks to all who replied. It looks like there are some differences between python 2.5 & 2.6, I tested all the possibilities I've been given in this thread and did not always get the same result. Anyway I found what I was looking for. JM From ethan at stoneleaf.us Thu Dec 16 10:29:25 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 16 Dec 2010 07:29:25 -0800 Subject: How to pop the interpreter's stack? In-Reply-To: References: Message-ID: <4D0A3055.7030308@stoneleaf.us> Tim Arnold wrote: > "Ethan Furman" wrote in message > news:mailman.4.1292379995.6505.python-list at python.org... >> kj wrote: >>> The one thing I don't like about this strategy is that the tracebacks >>> of exceptions raised during the execution of __pre_spam include one >>> unwanted stack level (namely, the one corresponding to __pre_spam >>> itself). >>> >>> __pre_spam should be completely invisible and unobtrusive >> I am unaware of any way to accomplish what you desire. I also think this >> is one of those things that's not worth fighting -- how often are you >> going to see such a traceback? When somebody makes a coding mistake? I >> would say change the name (assuming yours was a real example) to something >> more meaningful like _spam_arg_verifier and call it good. >> >> Alternatively, perhaps you could make a more general arg_verifier that >> could be used for all such needs, and then your traceback would have: >> >> caller >> >> spam >> >> arg_verifier >> >> and that seems useful to me (it is, in fact, how I have mine set up). >> >> Hope this helps! >> >> ~Ethan~ > > I thought people would advise using a decorator for this one. Wouldn't that > work? > thanks, > --Tim A decorator was one of the items kj explicity didn't want. Also, while it would have a shallower traceback for exceptions raised during the __pre_spam portion, any exceptions raised during spam itself would then be one level deeper than desired... while that could be masked by catching and (re-?)raising the exception in the decorator, Steven had a very good point about why that is a bad idea -- namely, tracebacks shouldn't lie about where the error is. ~Ethan~ From ethan at stoneleaf.us Thu Dec 16 10:36:10 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 16 Dec 2010 07:36:10 -0800 Subject: while True or while 1 In-Reply-To: References: <4D051506.2060403@holdenweb.com> Message-ID: <4D0A31EA.10203@stoneleaf.us> BartC wrote: > "Steve Holden" wrote in message > news:mailman.462.1292214062.2649.python-list at python.org... >> On 12/12/2010 2:32 PM, Christian Heimes wrote: >>> Am 12.12.2010 19:31, schrieb Steve Holden: >>> $ python -m timeit -n20 -- "i = 0" "while 1:" " i+=1" " if i == >>> 1000000: break" >>> 20 loops, best of 3: 89.7 msec per loop >>> $ python -m timeit -n20 -- "i = 0" "while True:" " i+=1" " if i == >>> 1000000: break" >>> 20 loops, best of 3: 117 msec per loop > >>> No argue with that! I was merely making a point that "while 1" executes >>> different byte code than "while True". Readability is important but >>> sometimes speed is of the essence. "while 1" is one of the few tricks to >>> speed up tight loops a bit. >> >> OK, but the figures you quote save you 27.3 ms per million iterations, >> for a grand total saving of 27.3 ns per iteration. So "a bit" is hardly >> worth considering for most programs, is it? > > One these is 30% faster than the other. That's an appreciable > difference, which you can't really just dismiss. Anecdotal evidence says it is easily dismissed: I had a routine that processed records from a table using custom, on the fly, code. I could either use exec for each record to do the work, or create a function that would then be called. I timed exec vs function, and found the function style to be about 200% faster... Eureka!, I thought. After putting the functional method in place, a run that took about 16 minutes using the old exec method ran two (2!) seconds faster. Great learning experience, for both the function method (which I prefer), and the need for profiling. ~Ethan~ From ethan at stoneleaf.us Thu Dec 16 10:40:54 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 16 Dec 2010 07:40:54 -0800 Subject: O'Reilly Python Certification In-Reply-To: References: <4D0900D3.10000@stoneleaf.us> <4D0927C1.5080209@tim.thechases.com> <4D093176.3010109@pythonmeister.com> Message-ID: <4D0A3306.3090100@stoneleaf.us> Please don't top-post. :) Nitin Pawar wrote: > Can someone provide any links or any starting points on how to apply and > what are the prerequisites http://www.oreillyschool.com/certificates/python-programming.php No prerequisites that I could see, and currently they are running a 25% discount promotional. ~Ethan~ From bruno.desthuilliers at gmail.com Thu Dec 16 10:41:39 2010 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Thu, 16 Dec 2010 07:41:39 -0800 (PST) Subject: string identity and comparison References: <080f1a8f-8152-492b-8982-989a810278df@y3g2000vbm.googlegroups.com> Message-ID: <00a175d6-a8ea-4d81-b6bf-296b3202f269@c13g2000prc.googlegroups.com> On 16 d?c, 15:52, Jean-Michel Pichavant wrote: > bruno.desthuilli... at gmail.com wrote: > > On 16 d c, 12:55, Jean-Michel Pichavant > > wrote: > > >> id('foo') > >> 3082385472L > >> id('foo') > >> 3082385472L > > >> Anyone has that kind of code ? > > > 2 points: > > > 1- an id is only valid for the lifetime of a given object - when the > > object has been collected, the id can be reused for another object. > > that's exactly what happened in my example, the 2 'foo' are not the same > object actually, the fact that the 2 successive id() calls return the > same value is implementation specific. > Thanks for pointing that out, I didn't realize in the first place. > been here, done that :-/ From bruno.desthuilliers at gmail.com Thu Dec 16 10:43:41 2010 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Thu, 16 Dec 2010 07:43:41 -0800 (PST) Subject: string identity and comparison References: Message-ID: <63f18a8e-1ef7-456e-895f-6347a7d732e2@a28g2000prb.googlegroups.com> On 16 d?c, 15:53, Jean-Michel Pichavant wrote: > Mel wrote: > > Jean-Michel Pichavant wrote: > > >> Fellows, > > >> I'd like to illutrate the fact that comparing strings using identity is, > >> most of the time, a bad idea. However I'm searching a short example of > >> code that yields 2 differents object for the same string content. > > >> id('foo') > >> 3082385472L > >> id('foo') > >> 3082385472L > > >> Anyone has that kind of code ? > > > Currently, CPython interns strings that look like identifiers. ?Any strings > > that don't look like identifiers are on their own: > > > mwilson at tecumseth:~/sandbox/candlekit/stringlight-1$ python > > Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) > > [GCC 4.4.3] on linux2 > > Type "help", "copyright", "credits" or "license" for more information. > > >>>> a = 'x(3)' > >>>> id(a) > > > 3075373248L > > >>>> c='x(3)' > >>>> id(c) > > > 3075373856L > > >>>> a==c > > > True > > > ? ?Mel. > > thanks to all who replied. > > It looks like there are some differences between python 2.5 & 2.6, I > tested all the possibilities I've been given in this thread and did not > always get the same result. Which FWIW is one more reason to avoid identity testing on strings - too much implementation specific stuff happening here. From steve+comp.lang.python at pearwood.info Thu Dec 16 11:23:36 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Dec 2010 16:23:36 GMT Subject: How to pop the interpreter's stack? References: Message-ID: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> On Thu, 16 Dec 2010 07:29:25 -0800, Ethan Furman wrote: > Tim Arnold wrote: >> "Ethan Furman" wrote in message >> news:mailman.4.1292379995.6505.python-list at python.org... >>> kj wrote: >>>> The one thing I don't like about this strategy is that the tracebacks >>>> of exceptions raised during the execution of __pre_spam include one >>>> unwanted stack level (namely, the one corresponding to __pre_spam >>>> itself). [...] > A decorator was one of the items kj explicity didn't want. Also, while > it would have a shallower traceback for exceptions raised during the > __pre_spam portion, any exceptions raised during spam itself would then > be one level deeper than desired... while that could be masked by > catching and (re-?)raising the exception in the decorator, Steven had a > very good point about why that is a bad idea -- namely, tracebacks > shouldn't lie about where the error is. True, very true... but many hours later, it suddenly hit me that what KJ was asking for wasn't *necessarily* such a bad idea. My thought is, suppose you have a function spam(x) which raises an exception. If it's a *bug*, then absolutely you need to see exactly where the error occurred, without the traceback being mangled or changed in any way. But what if the exception is deliberate, part of the function's documented behaviour? Then you might want the exception to appear to come from the function spam even if it was actually generated inside some private sub-routine. So, with qualifications, I have half changed my mind. -- Steven From robert.kern at gmail.com Thu Dec 16 11:39:34 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 16 Dec 2010 10:39:34 -0600 Subject: How to pop the interpreter's stack? In-Reply-To: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 12/16/10 10:23 AM, Steven D'Aprano wrote: > On Thu, 16 Dec 2010 07:29:25 -0800, Ethan Furman wrote: > >> Tim Arnold wrote: >>> "Ethan Furman" wrote in message >>> news:mailman.4.1292379995.6505.python-list at python.org... >>>> kj wrote: >>>>> The one thing I don't like about this strategy is that the tracebacks >>>>> of exceptions raised during the execution of __pre_spam include one >>>>> unwanted stack level (namely, the one corresponding to __pre_spam >>>>> itself). > [...] >> A decorator was one of the items kj explicity didn't want. Also, while >> it would have a shallower traceback for exceptions raised during the >> __pre_spam portion, any exceptions raised during spam itself would then >> be one level deeper than desired... while that could be masked by >> catching and (re-?)raising the exception in the decorator, Steven had a >> very good point about why that is a bad idea -- namely, tracebacks >> shouldn't lie about where the error is. > > True, very true... but many hours later, it suddenly hit me that what KJ > was asking for wasn't *necessarily* such a bad idea. My thought is, > suppose you have a function spam(x) which raises an exception. If it's a > *bug*, then absolutely you need to see exactly where the error occurred, > without the traceback being mangled or changed in any way. > > But what if the exception is deliberate, part of the function's > documented behaviour? Then you might want the exception to appear to come > from the function spam even if it was actually generated inside some > private sub-routine. Obfuscating the location that an exception gets raised prevents a lot of debugging (by inspection or by pdb), even if the exception is deliberately raised with an informative error message. Not least, the code that decides to raise that exception may be buggy. But even if the actual error is outside of the function (e.g. the caller is passing bad arguments), you want to at least see what tests the __pre_spam function is doing in order to decide to raise that exception. Tracebacks are inherently over-verbose. This is necessarily true because no algorithm (or clever programmer) can know all the pieces of information that the person debugging may want to know a priori. Most customizations of tracebacks *add* more verbosity rather than reduce it. Removing one stack level from the traceback barely makes the traceback more readable and removes some of the most relevant 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 mixedpuppy at gmail.com Thu Dec 16 12:03:49 2010 From: mixedpuppy at gmail.com (mixedpuppy) Date: Thu, 16 Dec 2010 09:03:49 -0800 (PST) Subject: Extending Thunderbird mail client with Python References: Message-ID: <110411fa-26da-4023-b955-f1dfff13665c@z26g2000prf.googlegroups.com> On Nov 11, 11:48?pm, John Bond wrote: > Anyone have any experience with this, ideally using Python 3? > > I'd like to sync my Thunderbird contacts with various things including > my mobile phone. Of course, I want to do it with Python! I've seen some > stuff around, eg. an XPI that provides Python bindings to the Mozilla > XPCOM APIs (through which I imagine you can access Thunderbird data like > its contacts database), but it doesn't seem maintained or ported to > Python 3. > > Cheers, JB While this doesn't provide a solution right now...look at https://mozillalabs.com/messaging/thunderbird-contacts/ and the highly experimental-working-but-not-yet-right sync addon for thunderbird (weave-ext and weaver repos) at https://bitbucket.org/mixedpuppy The sync addon is Firefox sync for thunderbird, not an ability to sync to your phone (yet). however, this is all js. shane From msarro at gmail.com Thu Dec 16 12:12:42 2010 From: msarro at gmail.com (Matty Sarro) Date: Thu, 16 Dec 2010 12:12:42 -0500 Subject: O'Reilly Python Certification In-Reply-To: <4D0A3306.3090100@stoneleaf.us> References: <4D0900D3.10000@stoneleaf.us> <4D0927C1.5080209@tim.thechases.com> <4D093176.3010109@pythonmeister.com> <4D0A3306.3090100@stoneleaf.us> Message-ID: So how exactly does the class work? Is it like an elementary CS class where you have a teacher, assignments, etc. Or is it more like a guided tour through the O'Reilly Python book/cookbook? On Thu, Dec 16, 2010 at 10:40 AM, Ethan Furman wrote: > Please don't top-post. ?:) > > Nitin Pawar wrote: >> >> Can someone provide any links or any starting points on how to apply and >> what are the prerequisites > > http://www.oreillyschool.com/certificates/python-programming.php > > No prerequisites that I could see, and currently they are running a 25% > discount promotional. > > ~Ethan~ > -- > http://mail.python.org/mailman/listinfo/python-list > From steve at holdenweb.com Thu Dec 16 13:27:23 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 16 Dec 2010 13:27:23 -0500 Subject: O'Reilly Python Certification In-Reply-To: References: <4D0900D3.10000@stoneleaf.us> <4D0927C1.5080209@tim.thechases.com> <4D093176.3010109@pythonmeister.com> <4D0A3306.3090100@stoneleaf.us> Message-ID: <4D0A5A0B.3040709@holdenweb.com> Each lesson required you to complete a practical assignment. You submit these assignments for evaluation, and do not proceed to the next lesson until your assignment reaches a satisfactory standard. Thus, less experienced students will tend to have more interaction with their tutors. A class will typically have between twelve and sixteen lessons. There are also quizzes and a final practical project. regards Steve On 12/16/2010 12:12 PM, Matty Sarro wrote: > So how exactly does the class work? Is it like an elementary CS class > where you have a teacher, assignments, etc. Or is it more like a > guided tour through the O'Reilly Python book/cookbook? > > On Thu, Dec 16, 2010 at 10:40 AM, Ethan Furman wrote: >> Please don't top-post. :) >> >> Nitin Pawar wrote: >>> >>> Can someone provide any links or any starting points on how to apply and >>> what are the prerequisites >> >> http://www.oreillyschool.com/certificates/python-programming.php >> >> No prerequisites that I could see, and currently they are running a 25% >> discount promotional. >> >> ~Ethan~ >> -- >> http://mail.python.org/mailman/listinfo/python-list >> -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From utabintarbo at gmail.com Thu Dec 16 13:33:53 2010 From: utabintarbo at gmail.com (utabintarbo) Date: Thu, 16 Dec 2010 10:33:53 -0800 (PST) Subject: Python creates "locked" temp dir References: <0c30c818-f73b-4b09-b707-64ea457c757d@z26g2000prf.googlegroups.com> <91dca7c4-00c7-44ad-8902-54221534107c@o9g2000pre.googlegroups.com> <753d0b5b-867b-456c-b3e9-2662ce1df1f8@f20g2000vbc.googlegroups.com> Message-ID: FWIW, I got around the issue with some samba mount options. They still show as 0700, but I, or anybody elsefor that matter, can still access them. Computers are weird. :P Thanks to all who responded. :) On Dec 10, 2:57?pm, Alex Willmer wrote: > On Dec 8, 6:26?pm, Christian Heimes wrote: > > > There isn't a way to limit access to a single process. mkdtemp creates > > the directory with mode 0700 and thus limits it to the (effective) user > > of the current process. Any process of the same user is able to access > > the directory. > > > Christian > > Quite right. My apologies for confusing temporary file creation, for > which exclusive access is used and temporary directory creation for > which there is no such mode. From python at bdurham.com Thu Dec 16 15:03:13 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 16 Dec 2010 15:03:13 -0500 Subject: Is text processing with dicts a good use case for Python cross-compilers like Cython/Pyrex or ShedSkin? Message-ID: <1292529793.31067.1410717477@webmail.messagingengine.com> Is text processing with dicts a good use case for Python cross-compilers like Cython/Pyrex or ShedSkin? (I've read the cross compiler claims about massive increases in pure numeric performance). I have 3 use cases I'm considering for Python-to-C++ cross-compilers for generating 32-bit Python extension modules for Python 2.7 for Windows. 1. Parsing UTF-8 files (basic Python with lots of string processing and dict lookups) 2. Generating UTF-8 files from nested list/dict structures 3. Parsing large ASCII "CSV-like" files and using dict's to calculate simple statistics like running totals, min, max, etc. Are any of these text processing scenarios good use cases for tools like Cython, Pyrex, or ShedSkin? Are any of these specifically bad use cases for these tools? We've tried Psyco and it has sped up some of our parsing utilities by 200%. But Psyco doesn't support Python 2.7 yet and we're committed to using Python 2.7 moving forward. Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From arnodel at gmail.com Thu Dec 16 15:27:36 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Thu, 16 Dec 2010 20:27:36 +0000 Subject: while True or while 1 References: <4D051506.2060403@holdenweb.com> Message-ID: <87d3p1bgzr.fsf@gmail.com> Ethan Furman writes: > ...I timed exec vs function, and found the function style to be about > 200% faster... So it finished before it started? -- Arnaud From tjreedy at udel.edu Thu Dec 16 15:32:31 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 16 Dec 2010 15:32:31 -0500 Subject: while True or while 1 In-Reply-To: References: <4D051506.2060403@holdenweb.com> Message-ID: On 12/16/2010 7:23 AM, Steve Holden wrote: > On 12/16/2010 5:44 AM, BartC wrote: >> One these is 30% faster than the other. That's an appreciable >> difference, which you can't really just dismiss. >> >> And you can't tell what the overall effect on a program will be: perhaps >> the loop will be in a library function , which might be called billions >> of times. > > It might. But if the code it is calling does *anything* at all > significant I can promise you that spending an extra 30% purely on the > looping construct will still make a negligible difference to a program's > execution time, and there are almost certainly going to be many other > aspects of performance that will yield greater benefits from tuning. > > I realise that there are going to be some people who just flatly say > "since 'while 1:' is quicker I am going to use it every time", and that > their programs will still work. And I still maintain that (for English > speakers) "while True:" is to be preferred. > > sholden at lifeboy ~ > $ python -m timeit -- "i = 1" "while True:" " i += 1" " if i == > 1000000: break" > 10 loops, best of 3: 157 msec per loop > > sholden at lifeboy ~ > $ python -m timeit -- "i = 1" "while True:" " i += 1" " if i == > 1000000: break" " x = i+1" > 10 loops, best of 3: 238 msec per loop > > sholden at lifeboy ~ > $ python -m timeit -- "i = 1" "while 1:" " i += 1" " if i == > 1000000: break" > 10 loops, best of 3: 116 msec per loop > > sholden at lifeboy ~ > $ python -m timeit -- "i = 1" "while 1:" " i += 1" " if i == > 1000000: break" " x = i+1" > 10 loops, best of 3: 195 msec per loop This are all Python2 timings. > If binding a simple arithmetic expression adds more to the loop than the > difference between "while 1:" and "while True:" you are wasting your > time thinking about the savings under all but the most rigorous > circumstances. *Especially* when the 'problem' has been fixed in Python 3. -- Terry Jan Reedy From greno at verizon.net Thu Dec 16 15:40:55 2010 From: greno at verizon.net (Gerry Reno) Date: Thu, 16 Dec 2010 15:40:55 -0500 Subject: Added Python, WSGI to XAMPP In-Reply-To: <08B25692CE8542B386238F7E02D317DD@teddy> References: <4CFA4305.10004@it.uu.se> <4CFD6825.9020200@simplistix.co.uk> <4CFD8B29.3020006@verizon.net><4D014A3D.7020101@verizon.net> <4D06AD69.4030302@simplistix.co.uk><4D06B6D1.6080208@verizon.net> <4D06B671.5020601@simplistix.co.uk><4D06C130.9040506@verizon.net> <08B25692CE8542B386238F7E02D317DD@teddy> Message-ID: <4D0A7957.4000306@verizon.net> On 12/16/2010 04:36 AM, Octavian Rasnita wrote: > From: "Ian Kelly" > > On Mon, Dec 13, 2010 at 5:58 PM, Gerry Reno wrote: > >> The VIEW is the bits that stream out of the webserver back to the users >> browser. >> > Why only to the user's browser? A web app could also offer the results in formats that can be accessed with something else than a browser. The view just offer the results, no matter what way. > > >> The CONTROLLER is the code that gathers all the pieces from >> the model and constructs the python code that is then fed to the engine >> that then creates the view. And just because the controller navigates >> the logic to dynamically contruct/render a view, that does not make 'it' >> the view. >> > >> In traditional MVC, the controller is the part that receives the user >> input, decides how to react to it, and instructs the model to update >> itself accordingly. It is not supposed to be some sort of >> intermediary between the model and the view, as many people seem to >> make it; the view is supposed to gather the data it needs to render >> itself directly from the model. >> > How can the view know what data it should render if the controller doesn't inform it about it? > It is less important if the view uses a smart templating system that doesn't need to ask the controller for data but can access the model directly, but the view or that templating system need to be informed by the controller what data need to ask from the model, so we can say that the intermediary is still the controller. > > And accessing the model directly from the view/templating system is not a good idea, because MVC is also prefered because it decouples the programming code and the web design, and in some cases it can be a security issue if the web designer that might not know programming would be able to change by mistake or with intention the code from the view/templating system that access the model. > > >> In that light, I think that this >> > quote from the Django FAQ is defensible: > > >>> In our interpretation of MVC, the ?view? describes the data that gets presented to the user. It?s not necessarily how the data looks, but which > data is presented. The view describes which data you see, not how you see it. It?s a subtle distinction. >>> > But if the view doesn't decide how the data looks, who decide it? :-) > > >> Traditionally, the view would describe both of these things, but since >> "how you see it" is ultimately decided by the user's browser, they are >> fundamentally separated in the context of the web. The Django >> template-view split is in recognition of this fact. >> > The same data can have any format that's not decided by the user browser. For example it can be displayed in .csv format, or .xls, or .xlsx, or .pdf, or .html, or it can be submitted by email, or sent to Twitter or another web site... > > > >> As for where the controller went, there are basically two decisions >> that need to be made when input is received: how to update the model >> as a result, and what data should be displayed next. The former >> decision belongs to the controller, the latter to the view. >> > The update of the model depends on the model and the display of results depends on the view. But the decision is controlled by the... controller. That's why it has that name, because it controls these things. > Of course, the frontiers between the M and V and C might be subtle in some cases, but it is a good idea to push as much logic to the base. It is not a good idea to make the controller do the job of the model and imply in the business logic or make the view do the job of the controller and do something else than just present the data it receives. > > >> But in a >> web app, these two things tend to be highly correlated, and there >> seems to be little reason to separate them out into distinct >> components. This part then is both controller and view, and which >> word we use for it is not terribly important. >> > Yes, but in that case such a program wouldn't use the MVC model. And as I exemplified above, there are reasons why the view should only present the data it receives and don't access the model directly. Some web developers aren't even alowed to offer the ORM objects to the templates, although the coding would be much easier that way, but need to generate other objects in the controller that don't allow the web designers to change some things in the templates and access more data from the database than it is needed. > > >> For these reasons, I find that in practice traditional MVC does not >> lend itself well to the HTTP request/response cycle, where the "view" >> as you define it has no access to the model and lacks any continuity >> whatsoever from one request to the next; but the Django MTV approach >> works just fine once you're willing to accept that it's not the same >> thing. >> >> Cheers, >> > Ian > > There is no "traditional MVC". There is just MVC or not MVC. > The view shouldn't have any kind of continuity. The view should just present the data. HTTP is a stateless protocol and the controller that handles the requests, does URL dispatching, uses cookies or URL-based ways for maintaining that continuity, not the view. > > The so called "non-traditional" MVC idea appeared because many web apps use a lot of Javascript these days, and because of this thing Javascript gained a much bigger importance, and the Javascript programmers would like to happen everything in the view if possible because they don't like to depend so much on the server-side code. > > Octavian > > > Javascript is like Ajax only it is client-side. Javascript acts as Controller and does mini-MVC based on bits of 'local' Model and sometimes uses Ajax in the background to perform other mini-MVC transactions back to the server to retrieve data or View parts. All of this, webapp, Ajax, Javascript is doing MVC only at different levels and scopes. -Gerry From ethan at stoneleaf.us Thu Dec 16 15:58:36 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 16 Dec 2010 12:58:36 -0800 Subject: while True or while 1 In-Reply-To: <87d3p1bgzr.fsf@gmail.com> References: <4D051506.2060403@holdenweb.com> <87d3p1bgzr.fsf@gmail.com> Message-ID: <4D0A7D7C.2010006@stoneleaf.us> Arnaud Delobelle wrote: > Ethan Furman writes: > >> ...I timed exec vs function, and found the function style to be about >> 200% faster... > > So it finished before it started? Hmmm.... Let me check my calculator... . . . Ah! Okay, that was 200x faster. :) I think -- it was a few months ago now, and my numbers might be off a bit, but I was definitely impressed with A) how much faster the function style was, and B), how very little time it saved me. ~Ethan~ From arnodel at gmail.com Thu Dec 16 16:15:28 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Thu, 16 Dec 2010 21:15:28 +0000 Subject: string identity and comparison References: Message-ID: <878vzpberz.fsf@gmail.com> Jean-Michel Pichavant writes: > Fellows, > > I'd like to illutrate the fact that comparing strings using identity > is, most of the time, a bad idea. However I'm searching a short > example of code that yields 2 differents object for the same string > content. > > id('foo') > 3082385472L > id('foo') > 3082385472L > > Anyone has that kind of code ? > > JM Have you tried this? >>> id("foo") 3078219968L >>> id("bar") 3078219968L >>> And this? >>> id("foo") 3077306560L >>> n = 42 >>> id("foo") 3077306720L And this? >>> "a"*2 is "a"*2 True >>> "a"*30 is "a"*30 False >>> n = 2 >>> "a"*n is "a"*n False -- Arnaud From shearichard at gmail.com Thu Dec 16 16:16:41 2010 From: shearichard at gmail.com (shearichard) Date: Thu, 16 Dec 2010 13:16:41 -0800 (PST) Subject: pudb on windows (dependent upon unix only termios ?) Message-ID: <0ea7ba67-a410-4f59-bc2c-f80a03b7fab5@21g2000prv.googlegroups.com> Hi - I was just trying to install the Python debugger pudb (http:// pypi.python.org/pypi/pudb) and easy install fell over saying it couldn't find a module termios. It turns out termios is only for Unix (http://docs.python.org/library/ termios.html). Does anyone know of way around this ? Is there an equivalent to termios which would run on windows and which could be hacked into pudb ? Alternatively suggestions for a pudb workalike ? (I like the console/ keyboard centric aspect of pudb). Thanks Richard. From stefan_ml at behnel.de Thu Dec 16 16:45:14 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 16 Dec 2010 22:45:14 +0100 Subject: Is text processing with dicts a good use case for Python cross-compilers like Cython/Pyrex or ShedSkin? In-Reply-To: <1292529793.31067.1410717477@webmail.messagingengine.com> References: <1292529793.31067.1410717477@webmail.messagingengine.com> Message-ID: python at bdurham.com, 16.12.2010 21:03: > Is text processing with dicts a good use case for Python > cross-compilers like Cython/Pyrex or ShedSkin? (I've read the > cross compiler claims about massive increases in pure numeric > performance). Cython is generally a good choice for string processing, simply because it can drop a lot of code into plain C, such as character iteration and comparison. Depending on what kind of operations you do, you can get speed-ups of 100x or more for that. http://docs.cython.org/src/tutorial/strings.html However, when it comes to dict lookups, it uses CPython's own dicts which are heavily optimised for string lookups already. So the speedup in that area will likely stay below 30%. Similarly, encoding and decoding use Python's codecs, so don't expect a major difference there. > I have 3 use cases I'm considering for Python-to-C++ > cross-compilers for generating 32-bit Python extension modules > for Python 2.7 for Windows. > > 1. Parsing UTF-8 files (basic Python with lots of string > processing and dict lookups) "Parsing" sounds like something that could easily benefit from Cython compilation. > 2. Generating UTF-8 files from nested list/dict structures That should be much faster in Cython, too, simply because iteration on builtin types is much faster than in Python. > 3. Parsing large ASCII "CSV-like" files and using dict's to > calculate simple statistics like running totals, min, max, etc. Again, parsing will be much faster, especially when reading from raw C files (which would also enable freeing the GIL, in case you want to use multi-threading). The rest may not win that much. A nice feature of Cython is that you do not have to go low-level right away. You can use all the niceness of Python, and only push the code closer to C level where your benchmarks point you. And if you really have to go all the way down to C, it's just a declaration away. > Are any of these text processing scenarios good use cases for > tools like Cython, Pyrex, or ShedSkin? Are any of these > specifically bad use cases for these tools? Pyrex isn't worth trying here, simply because you'd have to invest a lot more work to make it as fast as what Cython gives you anyway. ShedSkin may be worth a try, depending on how well you get your ShedSkin module integrated with CPython. (It seems that it has support for building extension modules by now, but I have no idea how well that is fleshed out). > We've tried Psyco and it has sped up some of our parsing > utilities by 200%. But Psyco doesn't support Python 2.7 yet and > we're committed to using Python 2.7 moving forward. If 3x is not enough for you, I strongly suggest you try Cython. The C code that it generates compiles nicely in all major Python versions, currently from 2.3 to 3.2. Stefan From gordon at panix.com Thu Dec 16 16:49:07 2010 From: gordon at panix.com (John Gordon) Date: Thu, 16 Dec 2010 21:49:07 +0000 (UTC) Subject: If/then style question Message-ID: (This is mostly a style question, and perhaps one that has already been discussed elsewhere. If so, a pointer to that discussion will be appreciated!) When I started learning Python, I wrote a lot of methods that looked like this: def myMethod(self, arg1, arg2): if some_good_condition: if some_other_good_condition: if yet_another_good_condition: do_some_useful_stuff() exitCode = good1 else: exitCode = bad3 else: exitCode = bad2 else: exitCode = bad1 return exitCode But lately I've been preferring this style: def myMethod(self, arg1, arg2): if some_bad_condition: return bad1 elif some_other_bad_condition: return bad2 elif yet_another_bad_condition: return bad3 do_some_useful_stuff() return good1 I like this style more, mostly because it eliminates a lot of indentation. However I recall one of my college CS courses stating that "one entry, one exit" was a good way to write code, and this style has lots of exits. Are there any concrete advantages of one style over the other? Thanks. -- 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 usernet at ilthio.net Thu Dec 16 17:05:52 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 16 Dec 2010 22:05:52 +0000 (UTC) Subject: If/then style question References: Message-ID: On 2010-12-16, John Gordon wrote: > I like this style more, mostly because it eliminates a lot of indentation. > > However I recall one of my college CS courses stating that "one entry, > one exit" was a good way to write code, and this style has lots of exits. So, take the good intentation from one and the single exit from the other: def myMethod(self, arg1, arg2): if some_bad_condition: exitCode = bad1 elif some_other_bad_condition: exitCode = bad2 elif yet_another_bad_condition: exitCode = bad3 else: exitCode = do_some_useful_stuff() # possible common cleanup code here return exitCode Or, raise an exception on bad condtions rather then passing an error code. From ethan at stoneleaf.us Thu Dec 16 17:11:51 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 16 Dec 2010 14:11:51 -0800 Subject: If/then style question In-Reply-To: References: Message-ID: <4D0A8EA7.7080104@stoneleaf.us> John Gordon wrote: > (This is mostly a style question, and perhaps one that has already been > discussed elsewhere. If so, a pointer to that discussion will be > appreciated!) > > When I started learning Python, I wrote a lot of methods that looked like > this: > > > def myMethod(self, arg1, arg2): > if some_good_condition: > if some_other_good_condition: > if yet_another_good_condition: > do_some_useful_stuff() > exitCode = good1 > else: > exitCode = bad3 > else: > exitCode = bad2 > else: > exitCode = bad1 > return exitCode > > > But lately I've been preferring this style: > > def myMethod(self, arg1, arg2): > if some_bad_condition: > return bad1 > elif some_other_bad_condition: > return bad2 > elif yet_another_bad_condition: > return bad3 > do_some_useful_stuff() > return good1 > > I like this style more, mostly because it eliminates a lot of indentation. As far as if/else goes, I prefer the second style also. As far as returning bad codes, you are better off raising exceptions: def myMethod(self, arg1, arg2): if some_bad_condition: raise Bad1() elif some_other_bad_condition: raise Bad2() elif yet_another_bad_condition: raise Bad3() do_some_useful_stuff # no need to return 'good' code -- success means no problems ~Ethan~ From invalid at invalid.invalid Thu Dec 16 17:13:40 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 16 Dec 2010 22:13:40 +0000 (UTC) Subject: If/then style question References: Message-ID: On 2010-12-16, John Gordon wrote: > (This is mostly a style question, and perhaps one that has already been > discussed elsewhere. If so, a pointer to that discussion will be > appreciated!) > > When I started learning Python, I wrote a lot of methods that looked like > this: > > > def myMethod(self, arg1, arg2): > if some_good_condition: > if some_other_good_condition: > if yet_another_good_condition: > do_some_useful_stuff() > exitCode = good1 > else: > exitCode = bad3 > else: > exitCode = bad2 > else: > exitCode = bad1 > return exitCode > > > But lately I've been preferring this style: > > > def myMethod(self, arg1, arg2): > > if some_bad_condition: > return bad1 > > elif some_other_bad_condition: > return bad2 > > elif yet_another_bad_condition: > return bad3 > > do_some_useful_stuff() > return good1 > > I like this style more, mostly because it eliminates a lot of > indentation. There's nothing inherently wrong with indentation, but in this case the latter style is a _lot_ easier to read (and modify without breaking). > However I recall one of my college CS courses stating that "one > entry, one exit" was a good way to write code, and this style has > lots of exits. > > Are there any concrete advantages of one style over the other? I think the check/exit style is far more readable. It can trip you up if there is cleanup stuff that needs to happen before you return from the function. In that case putting the whole function in a try statement and raising exceptions for the "bad conditions" works nicely. Then you get the more readable style of the check/exit style, plus the advantage of a single exit (it's easy to verify visually that all the required cleanup is happening). -- Grant Edwards grant.b.edwards Yow! I want a WESSON OIL at lease!! gmail.com From stefan.sonnenberg at pythonmeister.com Thu Dec 16 17:41:41 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Thu, 16 Dec 2010 23:41:41 +0100 Subject: If/then style question In-Reply-To: References: Message-ID: <4D0A95A5.4070103@pythonmeister.com> Am 16.12.2010 22:49, schrieb John Gordon: > (This is mostly a style question, and perhaps one that has already been > discussed elsewhere. If so, a pointer to that discussion will be > appreciated!) > > When I started learning Python, I wrote a lot of methods that looked like > this: > > > def myMethod(self, arg1, arg2): > > if some_good_condition: > > if some_other_good_condition: > > if yet_another_good_condition: > > do_some_useful_stuff() > exitCode = good1 > > else: > exitCode = bad3 > > else: > exitCode = bad2 > > else: > exitCode = bad1 > > return exitCode > > > But lately I've been preferring this style: > > > def myMethod(self, arg1, arg2): > > if some_bad_condition: > return bad1 > > elif some_other_bad_condition: > return bad2 > > elif yet_another_bad_condition: > return bad3 > else: > do_some_useful_stuff() > return good1 > > I like this style more, mostly because it eliminates a lot of indentation. > > However I recall one of my college CS courses stating that "one entry, > one exit" was a good way to write code, and this style has lots of exits. > > Are there any concrete advantages of one style over the other? > > Thanks. > The advantage in latter case is fewer operations, because you can skip the assignments, and it is more readable. The "one entry, one exit" is an advice. Not a law. Your code is OK. As long as it works ;-) P.S.: Sorry, I could not resist: return bad1 if some_bad_condition else bad2 if some_other_bad_condition else bad3 if yet_another_bad_condition else good1 if do_some_useful_stuff() else good1 Or consider this: return [x for x,y in ((bad1,some_bad_condition),(bad2,some_other_bad_condition),(bad3,yet_another_bad_condition),(good1,do_some_useful_stuff() or True)) if x][0] Neither self explanatory nor readable :-( From ryan at rfk.id.au Thu Dec 16 17:56:37 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Fri, 17 Dec 2010 09:56:37 +1100 Subject: If/then style question In-Reply-To: References: Message-ID: <1292540197.27568.22.camel@durian> On Thu, 2010-12-16 at 21:49 +0000, John Gordon wrote: > (This is mostly a style question, and perhaps one that has already been > discussed elsewhere. If so, a pointer to that discussion will be > appreciated!) > > When I started learning Python, I wrote a lot of methods that looked like > this: > > > def myMethod(self, arg1, arg2): > if some_good_condition: > if some_other_good_condition: > if yet_another_good_condition: > do_some_useful_stuff() > exitCode = good1 > else: > exitCode = bad3 > else: > exitCode = bad2 > else: > exitCode = bad1 > return exitCode > > > But lately I've been preferring this style: > > > def myMethod(self, arg1, arg2): > if some_bad_condition: > return bad1 > elif some_other_bad_condition: > return bad2 > elif yet_another_bad_condition: > return bad3 > do_some_useful_stuff() > return good1 > > I like this style more, mostly because it eliminates a lot of indentation. > > However I recall one of my college CS courses stating that "one entry, > one exit" was a good way to write code, and this style has lots of exits. > > Are there any concrete advantages of one style over the other? "one entry, one exit" has its good points, but it's *way* overquoted and overused. Do you raise any exceptions? Do you call any functions that might raise exceptions? If so, you've got multiple exit points already. I think this style a lot more important in a language like C where you have to be super-careful about cleaning up after yourself. The single exit point makes it easier to verify that all cleanup tasks have been performed. Assuming you're using "with" or "try-finally" then you just don't need such guarantees in python. I'm not a PEP-8 pedant by any means, but I think that the first section of PEP-8 contains the best advice I've ever read about programming language style. In fact, I'm going to quote it right here: A Foolish Consistency is the Hobgoblin of Little Minds ====================================================== One of Guido's key insights is that code is read much more often than it is written. The guidelines provided here are intended to improve the readability of code and make it consistent across the wide spectrum of Python code. As PEP 20 says, "Readability counts". ...snip... But most importantly: know when to be inconsistent -- sometimes the style guide just doesn't apply. When in doubt, use your best judgment. Look at other examples and decide what looks best. And don't hesitate to ask! In your example, the first style is difficult to read wile the second style is easy to read. You don't need any further justification for preferring the latter. Cheers, Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit ryan at rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part URL: From ian.g.kelly at gmail.com Thu Dec 16 18:02:38 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 16 Dec 2010 16:02:38 -0700 Subject: If/then style question In-Reply-To: <4D0A95A5.4070103@pythonmeister.com> References: <4D0A95A5.4070103@pythonmeister.com> Message-ID: On Thu, Dec 16, 2010 at 3:41 PM, Stefan Sonnenberg-Carstens wrote: > return [x for x,y in > ((bad1,some_bad_condition),(bad2,some_other_bad_condition),(bad3,yet_another_bad_condition),(good1,do_some_useful_stuff() > or True)) if x][0] This doesn't work. do_some_usefull_stuff() gets called during the tuple construction regardless of the conditions, not during the list comprehension execution as you would want. Here's my take on an unreadable one-liner: return reduce(lambda x, y: (x or (y[0]() and y[1])), [(some_bad_condition, bad1), (some_other_bad_condition, bad2), (yet_another_bad_condition, bad3), (lambda: (do_some_useful_stuff() or True), good1)], None) This of course assumes that bad1, bad2, and bad3 all evaluate as true. Cheers, Ian From bc at freeuk.com Thu Dec 16 18:34:21 2010 From: bc at freeuk.com (BartC) Date: Thu, 16 Dec 2010 23:34:21 -0000 Subject: while True or while 1 In-Reply-To: References: <4D051506.2060403@holdenweb.com> Message-ID: "Steve Holden" wrote in message news:mailman.54.1292502247.6505.python-list at python.org... > On 12/16/2010 5:44 AM, BartC wrote: >> One these is 30% faster than the other. That's an appreciable >> difference, which you can't really just dismiss. > sholden at lifeboy ~ > $ python -m timeit -- "i = 1" "while True:" " i += 1" " if i == > 1000000: break" > 10 loops, best of 3: 157 msec per loop > $ python -m timeit -- "i = 1" "while 1:" " i += 1" " if i == > 1000000: break" > 10 loops, best of 3: 116 msec per loop I used a single loop counting to 10 million, and the timings were roughly 2.5xx and 1.8xx seconds, on Python 2.5 (1.35 and 1.05 seconds inside a function). In terms of a more realistic function (admittedly still a little contrived, as the loop would be written differently), I tried this: def p2(n): p=1 while True: if n<=p: return p p<<=1 return 0 for i in xrange(1000000): x=p2(i) p2() calculates the smallest power of 2 >= it's operand. Using while True as shown, it took 3.4 seconds. Using While 1, it took 2.6 seconds (Python 2.5). -- Bartc From steve+comp.lang.python at pearwood.info Thu Dec 16 18:51:04 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Dec 2010 23:51:04 GMT Subject: If/then style question References: Message-ID: <4d0aa5e7$0$29997$c3e8da3$5496439d@news.astraweb.com> On Thu, 16 Dec 2010 21:49:07 +0000, John Gordon wrote: > (This is mostly a style question, and perhaps one that has already been > discussed elsewhere. If so, a pointer to that discussion will be > appreciated!) > > When I started learning Python, I wrote a lot of methods that looked > like this: > > def myMethod(self, arg1, arg2): > if some_good_condition: > if some_other_good_condition: > if yet_another_good_condition: > do_some_useful_stuff() > exitCode = good1 > else: > exitCode = bad3 > else: > exitCode = bad2 > else: > exitCode = bad1 > return exitCode It doesn't look like you were learning Python. It looks like you were learning C with Python syntax :( The above would be more Pythonically written as: def myMethod(self, arg1, arg2): if not some_good_condition: raise SomeException("message") if not some_other_good_condition: raise SomeOtherException("another message") if yet_another_good_condition: do_some_useful_stuff() else: raise SomeThirdException("whatever") using exceptions to communicate errors out-of-band. Since no return result is needed, no explicit return is used and the method is the closest thing to a procedure that Python can offer. The problem with in-band transmission of errors is that they invite the anti-pattern of this: result = obj.myMethod(arg1, arg2) if result == good1: do_something_good() elif result == bad1: handle_error1() elif result == bad2: handle_error2() elif result == bad3(): handle_error3() else: print "This can't ever happen, but if it does..." which all too often becomes: result = obj.myMethod(arg1, arg2) if result == good1: do_something_good() else: # assume result is bad1 handle_error1() or even: who_cares = obj.myMethod(arg1, arg2) do_something_good() > But lately I've been preferring this style: > > def myMethod(self, arg1, arg2): > if some_bad_condition: > return bad1 > elif some_other_bad_condition: > return bad2 > elif yet_another_bad_condition: > return bad3 > do_some_useful_stuff() > return good1 > > I like this style more, mostly because it eliminates a lot of > indentation. Well, that's better, but still more like C rather than Python. Avoid the anti-pattern of returning in-band error codes. In some languages, either exceptions aren't available at all, or the overhead of them is so great that for performance you have to avoid them, but Python is not one of those languages. In Python, exceptions are *the* primary way of communicating exceptional cases such as (but not limited to) errors. I can only think of two, er, exceptions to this rule: str.find() and some of the regular expression methods. > However I recall one of my college CS courses stating that "one entry, > one exit" was a good way to write code, and this style has lots of > exits. Functions always have one entry. The only way to have multiple entry points is if the language allows you to GOTO into the middle of a function, and Python sensibly does not allow this. The "one entry, one exit" rule comes from the days when people would routinely write spaghetti code, jumping into and out of blocks of code without using functions at all. If "one entry" is pointless (all functions have one entry!) then "one exit" is actively harmful. It leads to adding unnecessary complexity to functions, purely to meet the requirements of a rule invented to discourage spaghetti code. This hides bugs and increases the maintenance burden. Don't get me wrong... spaghetti code is *bad*. But there are other ways of writing bad code too, and hanging around inside a function long after you've finished is also bad: def function(arg): done = False do_something() if some_condition: result = "finished" done = True if not done: do_something_else() if another_condition: result = "now we're finished" done = True if not done: do_yet_more_work() if third_condition: result = "finished this time for sure" done = True if not done: for i in range(1000000): if not done: do_something_small() if yet_another_condition: result = "finally done!" done = True return result It's far more complicated than it need be, and does *lots* of unnecessary work. This can be written more simply and efficiently as: def function(arg): do_something() if some_condition: return "finished" do_something_else() if another_condition: return "now we're finished" do_yet_more_work() if third_condition: return "finished this time for sure" for i in range(1000000): do_something_small() if yet_another_condition: return "finally done!" Over 40% of the code in the first version is scaffolding to support skipping the rest of the function body once you have a result. It needlessly performs all one million iterations of the loop, even if the final result was calculated on the first iteration (loops also should have "one entry, one exit"). There's not one good thing that can be said about it except that it has "one exit", and that is only a good thing compared to the Bad Old Days of writing spaghetti code with GOTO. -- Steven From ian.g.kelly at gmail.com Thu Dec 16 19:00:39 2010 From: ian.g.kelly at gmail.com (Ian) Date: Thu, 16 Dec 2010 16:00:39 -0800 (PST) Subject: while True or while 1 References: <4D051506.2060403@holdenweb.com> Message-ID: On Dec 16, 4:34?pm, "BartC" wrote: > def p2(n): > ? p=1 > ?whileTrue: > ? ? if n<=p: return p > ? ? p<<=1 > ? return 0 > > for i in xrange(1000000): > ? x=p2(i) > > p2() calculates the smallest power of 2 >= it's operand. def p2(n): return 1 << n.bit_length() From wuwei23 at gmail.com Thu Dec 16 19:18:07 2010 From: wuwei23 at gmail.com (alex23) Date: Thu, 16 Dec 2010 16:18:07 -0800 (PST) Subject: If/then style question References: Message-ID: <32e2b64f-c400-4fe5-b1ae-f3d75329291c@l34g2000pro.googlegroups.com> John Gordon wrote: > But lately I've been preferring this style: > > ? def myMethod(self, arg1, arg2): > > ? ? if some_bad_condition: > ? ? ? return bad1 > > ? ? elif some_other_bad_condition: > ? ? ? return bad2 > > ? ? elif yet_another_bad_condition: > ? ? ? return bad3 > > ? ? do_some_useful_stuff() > ? ? return good1 For more than 2 tests in a function like this, I'd probably use dictionary dispatch: def myMethod(self, arg1, arg2): branches = dict( cond1: bad1, cond2: bad2, cond3: bad3 ) cond = if cond == cond_good: do_some_useful_stuff() exitCode = good1 else: exitCode = branches[cond] return exitCode From steve+comp.lang.python at pearwood.info Thu Dec 16 19:33:32 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Dec 2010 00:33:32 GMT Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4d0aafdb$0$29997$c3e8da3$5496439d@news.astraweb.com> On Thu, 16 Dec 2010 10:39:34 -0600, Robert Kern wrote: > On 12/16/10 10:23 AM, Steven D'Aprano wrote: >> On Thu, 16 Dec 2010 07:29:25 -0800, Ethan Furman wrote: >> >>> Tim Arnold wrote: >>>> "Ethan Furman" wrote in message >>>> news:mailman.4.1292379995.6505.python-list at python.org... >>>>> kj wrote: >>>>>> The one thing I don't like about this strategy is that the >>>>>> tracebacks of exceptions raised during the execution of __pre_spam >>>>>> include one unwanted stack level (namely, the one corresponding to >>>>>> __pre_spam itself). >> [...] >>> A decorator was one of the items kj explicity didn't want. Also, >>> while it would have a shallower traceback for exceptions raised during >>> the __pre_spam portion, any exceptions raised during spam itself would >>> then be one level deeper than desired... while that could be masked by >>> catching and (re-?)raising the exception in the decorator, Steven had >>> a very good point about why that is a bad idea -- namely, tracebacks >>> shouldn't lie about where the error is. >> >> True, very true... but many hours later, it suddenly hit me that what >> KJ was asking for wasn't *necessarily* such a bad idea. My thought is, >> suppose you have a function spam(x) which raises an exception. If it's >> a *bug*, then absolutely you need to see exactly where the error >> occurred, without the traceback being mangled or changed in any way. >> >> But what if the exception is deliberate, part of the function's >> documented behaviour? Then you might want the exception to appear to >> come from the function spam even if it was actually generated inside >> some private sub-routine. > > Obfuscating the location that an exception gets raised prevents a lot of > debugging (by inspection or by pdb), even if the exception is > deliberately raised with an informative error message. Not least, the > code that decides to raise that exception may be buggy. But even if the > actual error is outside of the function (e.g. the caller is passing bad > arguments), you want to at least see what tests the __pre_spam function > is doing in order to decide to raise that exception. And how do you think you see that from the traceback? The traceback prints the line which actually raises the exception (and sometimes not even that!), which is likely to be a raise statement: >>> import example >>> example.func(42) Traceback (most recent call last): File "", line 1, in File "example.py", line 3, in func raise ValueError('bad value for x') ValueError: bad value for x The actual test is: def func(x): if x > 10 and x%2 == 0: raise ValueError('bad value for x') but you can't get that information from the traceback. Python's exception system has to handle two different situations: buggy code, and bad data. It's not even clear whether there is a general distinction to be made between the two, but even if there's not a general distinction, there's certainly a distinction which we can *sometimes* make. If a function contains a bug, we need all the information we can get, including the exact line that causes the fault. But if the function deliberately raises an exception due to bad input, we don't need any information regarding the internals of the function (assuming that the exception is sufficiently detailed, a big assumption I grant you!). If I re-wrote the above func() like this: def func(x): if !(x <= 10): if x%2 != 0: pass else: raise ValueError('bad value for x') return I would have got the same traceback, except the location of the exception would have been different (line 6, in a nested if-block). To the caller, whether I had written the first version of func() or the second is irrelevant. If I had passed the input validation off to a second function, that too would be irrelevant. I don't expect Python to magically know whether an exception is a bug or not, but there's something to be said for the ability to turn Python functions into black boxes with their internals invisible, like C functions already are. If (say) math.atan2(y, x) raises an exception, you have no way of knowing whether atan2 is a single monolithic function, or whether it is split into multiple pieces. The location of the exception is invisible to the caller: all you can see is that atan2 raised an exception. > Tracebacks are inherently over-verbose. This is necessarily true because > no algorithm (or clever programmer) can know all the pieces of > information that the person debugging may want to know a priori. Most > customizations of tracebacks *add* more verbosity rather than reduce it. > Removing one stack level from the traceback barely makes the traceback > more readable and removes some of the most relevant information. Right. But I have thought of a clever trick to get the result KJ was asking for, with the minimum of boilerplate code. Instead of this: def _pre_spam(args): if condition(args): raise SomeException("message") if another_condition(args): raise AnotherException("message") if third_condition(args): raise ThirdException("message") def spam(args): _pre_spam(args) do_useful_work() you can return the exceptions instead of raising them (exceptions are just objects, like everything else!), and then add one small piece of boilerplate to the spam() function: def _pre_spam(args): if condition(args): return SomeException("message") if another_condition(args): return AnotherException("message") if third_condition(args): return ThirdException("message") def spam(args): exc = _pre_spam(args) if exc: raise exc do_useful_work() -- Steven From wuwei23 at gmail.com Thu Dec 16 19:56:12 2010 From: wuwei23 at gmail.com (alex23) Date: Thu, 16 Dec 2010 16:56:12 -0800 (PST) Subject: string identity and comparison References: Message-ID: <8fcdad15-e378-4bad-848c-75f0bac8ca49@a28g2000prb.googlegroups.com> On Dec 16, 9:55?pm, Jean-Michel Pichavant wrote: > I'd like to illutrate the fact that comparing strings using identity is, > most of the time, a bad idea. However I'm searching a short example of > code that yields 2 differents object for the same string content. > > Anyone has that kind of code ? It's quite obvious when they come from different contexts: >>> def f(): return 'some string' ... >>> def g(): return 'some string' ... >>> f() == g() True >>> f() is g() False From steve+comp.lang.python at pearwood.info Thu Dec 16 20:01:19 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Dec 2010 01:01:19 GMT Subject: while True or while 1 References: <4D051506.2060403@holdenweb.com> Message-ID: <4d0ab65f$0$29997$c3e8da3$5496439d@news.astraweb.com> On Thu, 16 Dec 2010 23:34:21 +0000, BartC wrote: > In terms of a more realistic function (admittedly still a little > contrived, as the loop would be written differently), I tried this: > > def p2(n): > p=1 > while True: > if n<=p: return p > p<<=1 > return 0 > > for i in xrange(1000000): > x=p2(i) > > p2() calculates the smallest power of 2 >= it's operand. > > Using while True as shown, it took 3.4 seconds. Using While 1, it took > 2.6 seconds (Python 2.5). Right. And a saving of 0.8 microseconds per iteration is a micro- optimization which is likely to be invisible in any real situation. I mean, yes, you saved almost an entire second. Wow. Save another 179 of them and you'll almost have enough time to make yourself a coffee. Bart, we get it. Nobody denies that the optimization is real, only that it is generally meaningful. Who cares whether it takes 2 seconds or 4 seconds to generate one million results if the rest of the application takes 3 minutes to run? *If* your application is such that saving 0.8 microseconds per iteration actually is useful, AND your loop has to be written as a while True loop, then this *may* be a useful micro-optimization to save 0.8 microseconds per iteration. That's a vanishingly tiny proportion of all code written. If your code happens to meet those conditions, then by all means use "while 1". Or move to Python 3, where "while True" has the same optimization performed. But in general, such micro-optimizations are not terribly useful. If you shave off 1 second off a program that runs in 3 seconds, chances are nobody is even going to notice. Two seconds or three, who cares? Either way, it's too short to do anything else, and not long enough to matter. If you shave off an hour off a program that takes 20 hours, who is going to care? But so long as it doesn't introduce bugs, or make maintenance harder, or add complexity, such micro-optimizations don't harm either. -- Steven From tmohr at s.netic.de Thu Dec 16 20:07:07 2010 From: tmohr at s.netic.de (Torsten Mohr) Date: Fri, 17 Dec 2010 02:07:07 +0100 Subject: Read / Write OpenOffice SpreadSheet ? Message-ID: Hi, i search for a possibility to access OpenOffoce SpreadSheets from Python with a reasonably new version of Python. Can anybody point me to a package that can do this? Best regards, Torsten. From emile at fenx.com Thu Dec 16 20:21:31 2010 From: emile at fenx.com (Emile van Sebille) Date: Thu, 16 Dec 2010 17:21:31 -0800 Subject: Read / Write OpenOffice SpreadSheet ? In-Reply-To: References: Message-ID: On 12/16/2010 5:07 PM Torsten Mohr said... > Hi, > > i search for a possibility to access OpenOffoce SpreadSheets from Python > with a reasonably new version of Python. > > Can anybody point me to a package that can do this? > > If you're open to 'saving as xls' then xlrd/xlwt works well. Otherwise, when I last checked in on this about 18 months ago, it appeared that python support in OO never quite got the traction I hoped it might... Emile From zapwireDASHgroups at yahoo.com Thu Dec 16 20:39:30 2010 From: zapwireDASHgroups at yahoo.com (Joel Koltner) Date: Thu, 16 Dec 2010 17:39:30 -0800 Subject: If/then style question References: <4d0aa5e7$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: "Steven D'Aprano" wrote in message news:4d0aa5e7$0$29997$c3e8da3$5496439d at news.astraweb.com... > It doesn't look like you were learning Python. It looks like you were > learning C with Python syntax :( True, although in many cases one has to interface to legacy C code where it'd be rather more code to start throwing exceptions left or right... since sooner or later those exceptions would still have to be turned into a single status (error) code! > which all too often becomes: > > result = obj.myMethod(arg1, arg2) > if result == good1: > do_something_good() > else: # assume result is bad1 > handle_error1() This really isn't a bad way to go *if you weren't planning on spending the time to really, fully flesh out the individual error cases anyway.* I see this pretty often: Peple put in sophisticated exception handling infrastructure, but when an error actually occurs, all six dozen cases handled individually end up just printing some generic message and exiting the program anyway. In an ideal world all the error cases would do something "smart," but pragmatically one has to balance how likely an error is to occur and how much damage it does with how much time you want to spend making a really smart error handler. > or even: > > who_cares = obj.myMethod(arg1, arg2) > do_something_good() Even this can be OK if do_something_good() behaves in a relatively benign fashion when feed gibberish. I mean, how many people actually check to see whether or not printf() succeeded, you know? But I would agree that often you see... who_care = obj.myMethod(arg1, arg2) do_something_really_dangerous_that_depends_on_the_success_of_myMethod() :-) > Well, that's better, but still more like C rather than Python. Avoid the > anti-pattern of returning in-band error codes. The main sticky point here is that what's an "error" vs. a "warning" or "note" (but not "success") is often rather a grey area. E.g., Pyhton's open() raises an IOError is the file can't be opened, but in my mind that's still a common enough/expected occurrence that elevating its behavior to an exception is more a judgement call than something everyone would agree on. (On the other hand, trying to read or write to an un-opened file is now clearly in the realm of an error and deserves an exception.) ---Joel From usernet at ilthio.net Thu Dec 16 20:53:20 2010 From: usernet at ilthio.net (Tim Harig) Date: Fri, 17 Dec 2010 01:53:20 +0000 (UTC) Subject: Read / Write OpenOffice SpreadSheet ? References: Message-ID: On 2010-12-17, Torsten Mohr wrote: > i search for a possibility to access OpenOffoce SpreadSheets from Python > with a reasonably new version of Python. > > Can anybody point me to a package that can do this? There is no package needed to read or write the new open document files. The files are merely a jar archive containing XML files. You can open and update them using jar as a subprocess and manipulate the XML files using your favorite XML libraries DOM/SAX/XPath/Etree/etc. If that doesn't suit you, you can manipulate them using OO.org through its UNO interface; but, I find that much more involved then simply accessing the files directly. From python.list at tim.thechases.com Thu Dec 16 21:08:27 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 16 Dec 2010 20:08:27 -0600 Subject: Read / Write OpenOffice SpreadSheet ? In-Reply-To: References: Message-ID: <4D0AC61B.6040903@tim.thechases.com> On 12/16/2010 07:53 PM, Tim Harig wrote: > On 2010-12-17, Torsten Mohr wrote: >> i search for a possibility to access OpenOffoce SpreadSheets from Python >> with a reasonably new version of Python. >> >> Can anybody point me to a package that can do this? > > There is no package needed to read or write the new open document files. > The files are merely a jar archive containing XML files. You can open > and update them using jar as a subprocess and manipulate the XML files > using your favorite XML libraries DOM/SAX/XPath/Etree/etc. To make that even easier (no need for a subprocess launching a JAR tool), JAR files are just ZIP files (IIRC, they may have some particularly-named files for metadata purposes, but it's all just a big zip-blob), so you can use Python's native zipfile module to crack into it. Then, as TimH suggests, wander around in the XML (and other files) inside. -tkc From joychenqi at qq.com Thu Dec 16 21:46:54 2010 From: joychenqi at qq.com (joymanchen) Date: Fri, 17 Dec 2010 10:46:54 +0800 Subject: Read / Write OpenOffice SpreadSheet ? In-Reply-To: References: Message-ID: "Torsten Mohr" ???? news:ieed6o$iqd$1 at news.LF.net... Hi, i search for a possibility to access OpenOffoce SpreadSheets from Python with a reasonably new version of Python. Can anybody point me to a package that can do this? Best regards, Torsten. --- news://freenews.netfront.net/ - complaints: news at netfront.net --- From cronoklee at gmail.com Thu Dec 16 22:42:48 2010 From: cronoklee at gmail.com (cronoklee) Date: Thu, 16 Dec 2010 19:42:48 -0800 (PST) Subject: Newbie question about importing modules. Message-ID: Hi I'm starting my first python project but I'm having trouble getting off the ground. I've read all I can find about relative and absolute import paths but it's just not making sense to me... There seems to be around ten different ways to import a script. I need my project to be portable so I can copy the whole folder to run on any PC that has python installed. Is it always possible to simply include modules in the project directory and reference them without installing into the main python directory? I've managed this with small classes through trial and error but when I try it with anything larger (like PIL module for example) I get errors. Do I need to actually install anything or is it enough just to include the relevant scripts? All the modules I've found come with tonnes of files and subdirectories. Do I need all these files or should I just choose the scripts/folders I need? Thanks, cronoklee From pavlovevidence at gmail.com Thu Dec 16 23:32:29 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 16 Dec 2010 20:32:29 -0800 (PST) Subject: If/then style question References: Message-ID: On Dec 16, 2:56?pm, Ryan Kelly wrote: > On Thu, 2010-12-16 at 21:49 +0000, John Gordon wrote: > > (This is mostly a style question, and perhaps one that has already been > > discussed elsewhere. ?If so, a pointer to that discussion will be > > appreciated!) > > > When I started learning Python, I wrote a lot of methods that looked like > > this: > > > ? def myMethod(self, arg1, arg2): > > ? ? if some_good_condition: > > ? ? ? if some_other_good_condition: > > ? ? ? ? if yet_another_good_condition: > > ? ? ? ? ? do_some_useful_stuff() > > ? ? ? ? ? exitCode = good1 > > ? ? ? ? else: > > ? ? ? ? ? exitCode = bad3 > > ? ? ? else: > > ? ? ? ? exitCode = bad2 > > ? ? else: > > ? ? ? exitCode = bad1 > > ? ? return exitCode > > > But lately I've been preferring this style: > > > ? def myMethod(self, arg1, arg2): > > ? ? if some_bad_condition: > > ? ? ? return bad1 > > ? ? elif some_other_bad_condition: > > ? ? ? return bad2 > > ? ? elif yet_another_bad_condition: > > ? ? ? return bad3 > > ? ? do_some_useful_stuff() > > ? ? return good1 > > > I like this style more, mostly because it eliminates a lot of indentation. > > > However I recall one of my college CS courses stating that "one entry, > > one exit" was a good way to write code, and this style has lots of exits. > > > Are there any concrete advantages of one style over the other? > > "one entry, one exit" has its good points, but it's *way* overquoted and > overused. > > Do you raise any exceptions? Do you call any functions that might raise > exceptions? ?If so, you've got multiple exit points already. > > I think this style a lot more important in a language like C where you > have to be super-careful about cleaning up after yourself. ?The single > exit point makes it easier to verify that all cleanup tasks have been > performed. ?Assuming you're using "with" or "try-finally" then you just > don't need such guarantees in python. Even without the cleanup issue, sometimes you want to edit a function to affect all return values somehow. If you have a single exit point you just make the change there; if you have mulitple you have to hunt them down and change all of them--if you remember to. I just got bit by that one. It's a trade-off. Readability and/or conciseness versus error robustness. I tend to go for the former but mileage varies. Carl Banks From jonyzhu at 163.com Thu Dec 16 23:36:01 2010 From: jonyzhu at 163.com (Jony Zhu) Date: Fri, 17 Dec 2010 12:36:01 +0800 Subject: Newbie question about importing modules. In-Reply-To: References: Message-ID: Hi, cronoklee maybe you should check every module directory you want to import to see if there is a __init__.py in it? missing a __init__.py file would cause error when you try to import the directory as a module. ? Fri, 17 Dec 2010 11:42:48 +0800?cronoklee ??: > Hi > I'm starting my first python project but I'm having trouble getting > off the ground. > I've read all I can find about relative and absolute import paths but > it's just not making sense to me... There seems to be around ten > different ways to import a script. > > I need my project to be portable so I can copy the whole folder to run > on any PC that has python installed. Is it always possible to simply > include modules in the project directory and reference them without > installing into the main python directory? I've managed this with > small classes through trial and error but when I try it with anything > larger (like PIL module for example) I get errors. Do I need to > actually install anything or is it enough just to include the relevant > scripts? > > All the modules I've found come with tonnes of files and > subdirectories. Do I need all these files or should I just choose the > scripts/folders I need? > > Thanks, > cronoklee -- ?? Opera ????????????: http://www.opera.com/mail/ From steve at holdenweb.com Fri Dec 17 00:19:42 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 17 Dec 2010 00:19:42 -0500 Subject: If/then style question In-Reply-To: References: Message-ID: On 12/16/2010 11:32 PM, Carl Banks wrote: > On Dec 16, 2:56 pm, Ryan Kelly wrote: >> On Thu, 2010-12-16 at 21:49 +0000, John Gordon wrote: >>> (This is mostly a style question, and perhaps one that has already been >>> discussed elsewhere. If so, a pointer to that discussion will be >>> appreciated!) >> >>> When I started learning Python, I wrote a lot of methods that looked like >>> this: >> >>> def myMethod(self, arg1, arg2): >>> if some_good_condition: >>> if some_other_good_condition: >>> if yet_another_good_condition: >>> do_some_useful_stuff() >>> exitCode = good1 >>> else: >>> exitCode = bad3 >>> else: >>> exitCode = bad2 >>> else: >>> exitCode = bad1 >>> return exitCode >> >>> But lately I've been preferring this style: >> >>> def myMethod(self, arg1, arg2): >>> if some_bad_condition: >>> return bad1 >>> elif some_other_bad_condition: >>> return bad2 >>> elif yet_another_bad_condition: >>> return bad3 >>> do_some_useful_stuff() >>> return good1 >> >>> I like this style more, mostly because it eliminates a lot of indentation. >> >>> However I recall one of my college CS courses stating that "one entry, >>> one exit" was a good way to write code, and this style has lots of exits. >> >>> Are there any concrete advantages of one style over the other? >> >> "one entry, one exit" has its good points, but it's *way* overquoted and >> overused. >> >> Do you raise any exceptions? Do you call any functions that might raise >> exceptions? If so, you've got multiple exit points already. >> >> I think this style a lot more important in a language like C where you >> have to be super-careful about cleaning up after yourself. The single >> exit point makes it easier to verify that all cleanup tasks have been >> performed. Assuming you're using "with" or "try-finally" then you just >> don't need such guarantees in python. > > Even without the cleanup issue, sometimes you want to edit a function > to affect all return values somehow. If you have a single exit point > you just make the change there; if you have mulitple you have to hunt > them down and change all of them--if you remember to. I just got bit > by that one. > > It's a trade-off. Readability and/or conciseness versus error > robustness. I tend to go for the former but mileage varies. > Heaven forfend you should just wrap the existing function inside another one which takes its name, if all its returns need to be altered. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From pavlovevidence at gmail.com Fri Dec 17 00:25:21 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 16 Dec 2010 21:25:21 -0800 (PST) Subject: How to pop the interpreter's stack? References: <4d08956e$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Dec 15, 2:16?am, Steven D'Aprano wrote: > On Tue, 14 Dec 2010 21:14:35 +0000, kj wrote: > > Consider this code: > > > def spam(*args, **kwargs): > > ? ? args, kwargs = __pre_spam(*args, **kwargs) > > > ? ? # args & kwargs are OK: proceed > > ? ? # ... > > > def __pre_spam(*args, **kwargs): > > ? ? # validate args & kwargs; > > ? ? # return canonicalized versions of args & kwargs; # on failure, > > ? ? raise some *informative* exception # ... > > ? ? return canonicalized_args, canonicalized_kwargs > > Double leading underscores don't have any special meaning in the global > scope. Save yourself an underscore and call it _pre_spam instead :) > > In fact, even if spam and __pre_spam are methods, it's probably a good > idea to avoid the double-underscore name mangling. It's usually more > trouble than it's worth. > > > I write functions like __pre_spam for one reason only: to remove clutter > > from a corresponding spam function that has a particularly complex > > argument-validation/canonicalization stage. ?In effect, spam > > "outsources" to __pre_spam the messy business of checking and > > conditioning its arguments. > > A perfectly sensible arrangement. > > > The one thing I don't like about this strategy is that the tracebacks of > > exceptions raised during the execution of __pre_spam include one > > unwanted stack level (namely, the one corresponding to __pre_spam > > itself). > > But why is it unwanted? The traceback shows where the error occurs -- it > occurs in __pre_spam, not spam, or __post_spam, or spam_caller, or > anywhere else. Even if it's possible, having the traceback *lie* about > where it occurs is a bad idea which will cause confusion to anyone trying > to maintain the software in the future. I don't agree with kj's usage, but I have customized the traceback to remove items before. In my case it was to remove lines for endemic wrapper functions. The traceback lines showing the wrapper functions in the stack were useless, and since pretty much every function was wrapped it meant half the lines in that traceback were useless. (Really. I was scanning the loaded modules and adding wrappers to every function found. Never mind why.) I only printed the wrapper line if it was the very top of the stack. > I can't think of any way to do it, You override sys.excepthook to print lines from the traceback selectively. Carl Banks From nagle at animats.com Fri Dec 17 02:07:44 2010 From: nagle at animats.com (John Nagle) Date: Thu, 16 Dec 2010 23:07:44 -0800 Subject: How to pop the interpreter's stack? In-Reply-To: References: Message-ID: <4d0b0c4c$0$44018$742ec2ed@news.sonic.net> On 12/14/2010 6:31 PM, Ethan Furman wrote: > kj wrote: >> The one thing I don't like about this strategy is that the tracebacks >> of exceptions raised during the execution of __pre_spam include one >> unwanted stack level (namely, the one corresponding to __pre_spam >> itself). >> >> __pre_spam should be completely invisible and unobtrusive > > I am unaware of any way to accomplish what you desire. I also think this > is one of those things that's not worth fighting -- how often are you > going to see such a traceback? When somebody makes a coding mistake? Right. If you are worried about what the user sees in a traceback, you are doing it wrong. Consider reporting detailed error information via the logging module, for example. John Nagle From tjreedy at udel.edu Fri Dec 17 02:22:31 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 17 Dec 2010 02:22:31 -0500 Subject: How to pop the interpreter's stack? In-Reply-To: <4d0aafdb$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <4d0aafdb$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 12/16/2010 7:33 PM, Steven D'Aprano wrote: > Python's exception system has to handle two different situations: buggy > code, and bad data. It's not even clear whether there is a general > distinction to be made between the two, but even if there's not a general > distinction, there's certainly a distinction which we can *sometimes* > make. The two are intertwined. Production code that passes bad data to a function without catching the exception is buggy. > def func(x): > if !(x<= 10): > if x%2 != 0: > pass > else: > raise ValueError('bad value for x') > return > > I would have got the same traceback, A traceback is printed only if the code passes bad data and does not catch the exception. Tracebacks are for developers, not for users. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Fri Dec 17 03:23:11 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Dec 2010 08:23:11 GMT Subject: If/then style question References: Message-ID: <4d0b1def$0$29997$c3e8da3$5496439d@news.astraweb.com> On Thu, 16 Dec 2010 20:32:29 -0800, Carl Banks wrote: > Even without the cleanup issue, sometimes you want to edit a function to > affect all return values somehow. If you have a single exit point you > just make the change there; if you have mulitple you have to hunt them > down and change all of them--if you remember to. I just got bit by that > one. If your function has so many exit points that you can miss some of them while editing, your function is too big, does too much, or both. Refactor and simplify. Or wrap the function in a decorator: def affect_all_return_values(func): @functools.wraps(func) def inner(*args, **kwargs): result = func(*args, **kwargs) do_something_to(result) return result return inner @affect_all_return_values def my_big_complicated_function(args): do_something_with_many_exit_points() -- Steven From timr at probo.com Fri Dec 17 03:59:34 2010 From: timr at probo.com (Tim Roberts) Date: Fri, 17 Dec 2010 00:59:34 -0800 Subject: Newbie question about importing modules. References: Message-ID: cronoklee wrote: > >I'm starting my first python project but I'm having trouble getting >off the ground. >I've read all I can find about relative and absolute import paths but >it's just not making sense to me... There seems to be around ten >different ways to import a script. That's not really true. >I need my project to be portable so I can copy the whole folder to run >on any PC that has python installed. Is it always possible to simply >include modules in the project directory and reference them without >installing into the main python directory? Absolutely. >I've managed this with >small classes through trial and error but when I try it with anything >larger (like PIL module for example) I get errors. Do I need to >actually install anything or is it enough just to include the relevant >scripts? PIL requires DLLs as well as other Python files. You can't just copy the top-level PIL files to your own private directory. >All the modules I've found come with tonnes of files and >subdirectories. Do I need all these files or should I just choose the >scripts/folders I need? If you are delivering a program to clients, then you should look at something like py2exe, which will examine your code and produce a zip file that includes all of the files your application will need. If you are delivering a script for someone that will definitely have Python installed, then you just need to identify the dependencies. Let that person install PIL. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From tmohr at s.netic.de Fri Dec 17 04:19:53 2010 From: tmohr at s.netic.de (Torsten Mohr) Date: Fri, 17 Dec 2010 10:19:53 +0100 Subject: Read / Write OpenOffice SpreadSheet ? References: Message-ID: Hello, > There is no package needed to read or write the new open document files. > The files are merely a jar archive containing XML files. You can open > and update them using jar as a subprocess and manipulate the XML files > using your favorite XML libraries DOM/SAX/XPath/Etree/etc. thanks for your hint. I was aware of that, OO files are a bunch of zipped XML files. But, i searh for something more comfortable/highlevel that lets me just do things like doc.Cell(1, 3) = 'abc' or so. > If that doesn't suit you, you can manipulate them using OO.org through its > UNO interface; but, I find that much more involved then simply accessing > the files directly. Thanks, i read about it but as i understood it, UNO needs Python 2.3.x and i'd like to base on something actual. Best regards, Torsten. From shearichard at gmail.com Fri Dec 17 06:30:15 2010 From: shearichard at gmail.com (shearichard) Date: Fri, 17 Dec 2010 03:30:15 -0800 (PST) Subject: Newbie question about importing modules. References: Message-ID: <24e3fd89-79d9-4329-bdb7-a050597c09ab@o9g2000pre.googlegroups.com> On Dec 17, 4:42?pm, cronoklee wrote: > Hi > I'm starting my first python project but I'm having trouble getting > off the ground. > I've read all I can find about relative and absolute import paths but > it's just not making sense to me... There seems to be around ten > different ways to import a script. > > I need my project to be portable so I can copy the whole folder to run > on any PC that has python installed. Is it always possible to simply > include modules in the project directory and reference them without > installing into the main python directory? I've managed this with > small classes through trial and error but when I try it with anything > larger (like PIL module for example) I get errors. Do I need to > actually install anything or is it enough just to include the relevant > scripts? > > All the modules I've found come with tonnes of files and > subdirectories. Do I need all these files or should I just choose the > scripts/folders I need? > > Thanks, > cronoklee You may find this useful as an overview of importing ... http://effbot.org/zone/import-confusion.htm ... also this ... http://diveintopython.org/object_oriented_framework/importing_modules.html I may be stating the obvious but here's an example of using the Image object offered by PIL ... from PIL import Image ... as documented here ... http://www.pythonware.com/library/pil/handbook/image.htm Regarding bundling PIL with an app I'd second what Tim Roberts has to say regarding py2Exe regards Richard. From jeanmichel at sequans.com Fri Dec 17 08:22:35 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 17 Dec 2010 14:22:35 +0100 Subject: If/then style question In-Reply-To: References: Message-ID: <4D0B641B.1020701@sequans.com> John Gordon wrote: > (This is mostly a style question, and perhaps one that has already been > discussed elsewhere. If so, a pointer to that discussion will be > appreciated!) > > When I started learning Python, I wrote a lot of methods that looked like > this: > > > def myMethod(self, arg1, arg2): > > if some_good_condition: > > if some_other_good_condition: > > if yet_another_good_condition: > > do_some_useful_stuff() > exitCode = good1 > > else: > exitCode = bad3 > > else: > exitCode = bad2 > > else: > exitCode = bad1 > > return exitCode > > > But lately I've been preferring this style: > > > def myMethod(self, arg1, arg2): > > if some_bad_condition: > return bad1 > > elif some_other_bad_condition: > return bad2 > > elif yet_another_bad_condition: > return bad3 > > do_some_useful_stuff() > return good1 > > I like this style more, mostly because it eliminates a lot of indentation. > > However I recall one of my college CS courses stating that "one entry, > one exit" was a good way to write code, and this style has lots of exits. > > Are there any concrete advantages of one style over the other? > > Thanks. > > What about, def myMethod(): for condition, exitCode in [ (cond1, 'error1'), (cond2, 'very bad error'), ]: if not condition: break else: do_some_usefull_stuff() # executed only if the we never hit the break statement. exitCode = good1 return exitCode This version uses the 'for ... else' statement. You can easily add conditions by simply adding a line in the list, that's it. Note that this code uses a shadow declaration of exitCode in the for loop. If you're not comfortable with that, you'll have to use a properly 'declared' variable retCode and write retCode = exitCode before breaking. Actually I would advise to do so. JM From Rob.Richardson at rad-con.com Fri Dec 17 09:09:49 2010 From: Rob.Richardson at rad-con.com (Rob Richardson) Date: Fri, 17 Dec 2010 09:09:49 -0500 Subject: If/then style question In-Reply-To: <4D0B641B.1020701@sequans.com> Message-ID: <04A6DB42D2BA534FAC77B90562A6A03D016894CB@server.rad-con.local> -----Original Message----- What about, def myMethod(): for condition, exitCode in [ (cond1, 'error1'), (cond2, 'very bad error'), ]: if not condition: break else: do_some_usefull_stuff() # executed only if the we never hit the break statement. exitCode = good1 return exitCode ---- I reply ----- This is interesting, but I don't understand it (which speaks volumes about the level of my understanding of Python). First, just to clarify, I don't think the indentation I saw was what was originally posted. The "else" must be indented to match the "if", and the two statements under "else" are in the else block. The return statement is indented at the same level as the for statement, so that it will be executed after the for loop exits. Correct? Now, the for loop will set condition to cond1 and exitCode to 'error1'. Then it checks the contents of the condition variable. But what does "not " by itself mean? I'm guessing that it checks that the variable refers to an object. So, the first time through, condition refers to cond1, the if condition is false, and the else block gets executed, and exitCode is changed to refer to good1. The next time through the loop, condition is set to refer to cond2 and exitCode is set to refer to 'very bad error'. Again, condition is refering to something, so the else block is executed and we do useful stuff again, which is probably not helpful and could well be harmful. exitCode is set to good1, we're finished with the loop, and we return exitCode. What happens if we try to do useful stuff, and we can't? Where does the error indication get set? And once it does get set, the only way we can exit the for loop is for condition to not refer to anything. How can that happen? Thank you very much for your explanation and your patience with one who only uses Python in very simplistic ways. RobR From steve+comp.lang.python at pearwood.info Fri Dec 17 09:38:11 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Dec 2010 14:38:11 GMT Subject: If/then style question References: Message-ID: <4d0b75d2$0$29997$c3e8da3$5496439d@news.astraweb.com> On Fri, 17 Dec 2010 09:09:49 -0500, Rob Richardson wrote: > First, just to clarify, I don't think the indentation I saw was what was > originally posted. The "else" must be indented to match the "if", and > the two statements under "else" are in the else block. The return > statement is indented at the same level as the for statement, so that it > will be executed after the for loop exits. Correct? I think that what you are missing is that for-loops can include an else clause too, like this: >>> for x in (1,2,3): ... print(x) ... else: ... print("finished") ... 1 2 3 finished >>> The else block runs after the for block, unless you exit the entire block by returning, raising an exception, or using break: >>> for x in (1,2,3): ... print(x) ... if x == 3: break ... else: ... print("finished") ... 1 2 3 >>> Does that clear up what is going on? -- Steven From jeanmichel at sequans.com Fri Dec 17 09:41:09 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 17 Dec 2010 15:41:09 +0100 Subject: If/then style question In-Reply-To: <04A6DB42D2BA534FAC77B90562A6A03D016894CB@server.rad-con.local> References: <04A6DB42D2BA534FAC77B90562A6A03D016894CB@server.rad-con.local> Message-ID: <4D0B7685.8080009@sequans.com> Rob Richardson wrote: > -----Original Message----- > What about, > > > def myMethod(): > for condition, exitCode in [ > (cond1, 'error1'), > (cond2, 'very bad error'), > ]: > if not condition: > break > else: > do_some_usefull_stuff() # executed only if the we never hit the > break statement. > exitCode = good1 > > return exitCode > > ---- I reply ----- > > This is interesting, but I don't understand it (which speaks volumes > about the level of my understanding of Python). > > First, just to clarify, I don't think the indentation I saw was what was > originally posted. The "else" must be indented to match the "if", and > the two statements under "else" are in the else block. No, the else is indented to the for loop. for ... else is a python statement, the else block is executed only if the loop did never break. http://docs.python.org/reference/compound_stmts.html#for > The return > statement is indented at the same level as the for statement, so that it > will be executed after the for loop exits. Correct? > > Now, the for loop will set condition to cond1 and exitCode to 'error1'. > Then it checks the contents of the condition variable. But what does > "not " by itself mean? condition is a bool value. if not condition is evaluated to True, if the condition is False. condition = False not condition => True condition = ('Foo' == 'Foo') not condition => False [snip] > RobR > > My mail client could have messed up with the indentation. Here is the code: http://paste-it.net/public/t8a4acd/python/ JM From drobinow at gmail.com Fri Dec 17 09:47:43 2010 From: drobinow at gmail.com (David Robinow) Date: Fri, 17 Dec 2010 09:47:43 -0500 Subject: If/then style question In-Reply-To: <4d0aa5e7$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <4d0aa5e7$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Dec 16, 2010 at 6:51 PM, Steven D'Aprano wrote: ... > Functions always have one entry. The only way to have multiple entry > points is if the language allows you to GOTO into the middle of a > function, and Python sensibly does not allow this. The "one entry, one > exit" rule comes from the days when people would routinely write > spaghetti code, jumping into and out of blocks of code without using > functions at all. Only 99.7% true. Fortran still allows the appalling ENTRY statement. From cronoklee at gmail.com Fri Dec 17 10:30:40 2010 From: cronoklee at gmail.com (cronoklee) Date: Fri, 17 Dec 2010 07:30:40 -0800 (PST) Subject: Newbie question about importing modules. In-Reply-To: <24e3fd89-79d9-4329-bdb7-a050597c09ab@o9g2000pre.googlegroups.com> Message-ID: <7f998afc-1406-4055-b00d-4107c7fcb0af@glegroupsg2000goo.googlegroups.com> Hey thanks for the help fellas. The links were helpful and the pyExe program looks great. I might well end up using this. I'm still a little confused as to how the directory structure works. PIL (http://www.pythonware.com/products/pil/#pil117), for example comes packed in a folder called Imaging-1.1.7 which contains a bunch of other directories, one of which is PIL. Now, what I've done is move this subfolder PIL into the same directory as my python test script and used: from PIL import Image I assume this instructs python to look in the PIL folder for Image.py. Am I wrong? I feel like I'm wrong. If I need to put the whole Imaging-1.1.7 folder somewhere else, how do I reference the specific Image module that I need? Sorry for the stupidity - I'm coming from PHP where you just include path/to/script.php so this is a bit alien to me. Thanks a lot, cronoklee From robert.kern at gmail.com Fri Dec 17 10:47:01 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 17 Dec 2010 09:47:01 -0600 Subject: How to pop the interpreter's stack? In-Reply-To: <4d0aafdb$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <4d0aafdb$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 12/16/10 6:33 PM, Steven D'Aprano wrote: > On Thu, 16 Dec 2010 10:39:34 -0600, Robert Kern wrote: > >> On 12/16/10 10:23 AM, Steven D'Aprano wrote: >>> On Thu, 16 Dec 2010 07:29:25 -0800, Ethan Furman wrote: >>> >>>> Tim Arnold wrote: >>>>> "Ethan Furman" wrote in message >>>>> news:mailman.4.1292379995.6505.python-list at python.org... >>>>>> kj wrote: >>>>>>> The one thing I don't like about this strategy is that the >>>>>>> tracebacks of exceptions raised during the execution of __pre_spam >>>>>>> include one unwanted stack level (namely, the one corresponding to >>>>>>> __pre_spam itself). >>> [...] >>>> A decorator was one of the items kj explicity didn't want. Also, >>>> while it would have a shallower traceback for exceptions raised during >>>> the __pre_spam portion, any exceptions raised during spam itself would >>>> then be one level deeper than desired... while that could be masked by >>>> catching and (re-?)raising the exception in the decorator, Steven had >>>> a very good point about why that is a bad idea -- namely, tracebacks >>>> shouldn't lie about where the error is. >>> >>> True, very true... but many hours later, it suddenly hit me that what >>> KJ was asking for wasn't *necessarily* such a bad idea. My thought is, >>> suppose you have a function spam(x) which raises an exception. If it's >>> a *bug*, then absolutely you need to see exactly where the error >>> occurred, without the traceback being mangled or changed in any way. >>> >>> But what if the exception is deliberate, part of the function's >>> documented behaviour? Then you might want the exception to appear to >>> come from the function spam even if it was actually generated inside >>> some private sub-routine. >> >> Obfuscating the location that an exception gets raised prevents a lot of >> debugging (by inspection or by pdb), even if the exception is >> deliberately raised with an informative error message. Not least, the >> code that decides to raise that exception may be buggy. But even if the >> actual error is outside of the function (e.g. the caller is passing bad >> arguments), you want to at least see what tests the __pre_spam function >> is doing in order to decide to raise that exception. > > And how do you think you see that from the traceback? The traceback > prints the line which actually raises the exception (and sometimes not > even that!), which is likely to be a raise statement: > >>>> import example >>>> example.func(42) > Traceback (most recent call last): > File "", line 1, in > File "example.py", line 3, in func > raise ValueError('bad value for x') > ValueError: bad value for x > > The actual test is: > > def func(x): > if x> 10 and x%2 == 0: > raise ValueError('bad value for x') > > but you can't get that information from the traceback. But I can get the line number and trivially go look it up. If we elide that stack frame, I have to go hunting and possibly make some guesses. Depending on the organization of the code, I may have to make some guesses anyways, but if I keep the decision to raise an exception close to the actual raising of the exception, it makes things a lot easier. > Python's exception system has to handle two different situations: buggy > code, and bad data. It's not even clear whether there is a general > distinction to be made between the two, but even if there's not a general > distinction, there's certainly a distinction which we can *sometimes* > make. If a function contains a bug, we need all the information we can > get, including the exact line that causes the fault. But if the function > deliberately raises an exception due to bad input, we don't need any > information regarding the internals of the function (assuming that the > exception is sufficiently detailed, a big assumption I grant you!). If I > re-wrote the above func() like this: > > def func(x): > if !(x<= 10): > if x%2 != 0: > pass > else: > raise ValueError('bad value for x') > return > > I would have got the same traceback, except the location of the exception > would have been different (line 6, in a nested if-block). To the caller, > whether I had written the first version of func() or the second is > irrelevant. If I had passed the input validation off to a second > function, that too would be irrelevant. The caller doesn't care about tracebacks one way or the other, either. Only someone *viewing* the traceback cares as well as debuggers like pdb. Eliding the stack frame neither helps nor harms the caller, but it does substantially harm the developer viewing tracebacks or using a debugger. > I don't expect Python to magically know whether an exception is a bug or > not, but there's something to be said for the ability to turn Python > functions into black boxes with their internals invisible, like C > functions already are. If (say) math.atan2(y, x) raises an exception, you > have no way of knowing whether atan2 is a single monolithic function, or > whether it is split into multiple pieces. The location of the exception > is invisible to the caller: all you can see is that atan2 raised an > exception. And that has frustrated my debugging efforts more often than I can count. I would dearly love to have a debugger that can traverse both Python and C stack frames. This is a deficiency, not a benefit to be extended to pure Python functions. >> Tracebacks are inherently over-verbose. This is necessarily true because >> no algorithm (or clever programmer) can know all the pieces of >> information that the person debugging may want to know a priori. Most >> customizations of tracebacks *add* more verbosity rather than reduce it. >> Removing one stack level from the traceback barely makes the traceback >> more readable and removes some of the most relevant information. > > Right. But I have thought of a clever trick to get the result KJ was > asking for, with the minimum of boilerplate code. Instead of this: > > > def _pre_spam(args): > if condition(args): > raise SomeException("message") > if another_condition(args): > raise AnotherException("message") > if third_condition(args): > raise ThirdException("message") > > def spam(args): > _pre_spam(args) > do_useful_work() > > > you can return the exceptions instead of raising them (exceptions are > just objects, like everything else!), and then add one small piece of > boilerplate to the spam() function: > > > def _pre_spam(args): > if condition(args): > return SomeException("message") > if another_condition(args): > return AnotherException("message") > if third_condition(args): > return ThirdException("message") > > def spam(args): > exc = _pre_spam(args) > if exc: raise exc > do_useful_work() And that makes post-mortem pdb debugging into _pre_spam impossible. Like I said, whether the bug is inside _pre_spam or is in the code that is passing the bad argument, being able to navigate stack frames to where the code is deciding that there is an exceptional condition is important. Kern's First Maxim: Raise exceptions close to the code that decides to raise an exception. -- 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 stefan_ml at behnel.de Fri Dec 17 10:48:34 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 17 Dec 2010 16:48:34 +0100 Subject: Read / Write OpenOffice SpreadSheet ? In-Reply-To: References: Message-ID: Torsten Mohr, 17.12.2010 02:07: > i search for a possibility to access OpenOffoce SpreadSheets from Python > with a reasonably new version of Python. > > Can anybody point me to a package that can do this? Have you looked through the relevant PyPI packages? http://pypi.python.org/pypi?%3Aaction=search&term=openoffice Stefan From steve at holdenweb.com Fri Dec 17 10:53:45 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 17 Dec 2010 10:53:45 -0500 Subject: If/then style question In-Reply-To: <4d0b75d2$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <4d0b75d2$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 12/17/2010 9:38 AM, Steven D'Aprano wrote: > On Fri, 17 Dec 2010 09:09:49 -0500, Rob Richardson wrote: > > >> First, just to clarify, I don't think the indentation I saw was what was >> originally posted. The "else" must be indented to match the "if", and >> the two statements under "else" are in the else block. The return >> statement is indented at the same level as the for statement, so that it >> will be executed after the for loop exits. Correct? > > I think that what you are missing is that for-loops can include an else > clause too, like this: > > >>>> for x in (1,2,3): > ... print(x) > ... else: > ... print("finished") > ... > 1 > 2 > 3 > finished >>>> > > > The else block runs after the for block, unless you exit the entire block > by returning, raising an exception, or using break: > > >>>> for x in (1,2,3): > ... print(x) > ... if x == 3: break > ... else: > ... print("finished") > ... > 1 > 2 > 3 >>>> > > > Does that clear up what is going on? > > This construct appears to be unpopular in actual use, and when it comes up in classes and seminars there is always interesting debate as people discuss potential uses and realise there are useful applications. I think the choice of keyword is probably not Guido's crowning language achievement, but then since the English keywords don't make natural sense to those who speak other languages it's at least fair that there should be one that isn't totally natural to English speakers. A small price to pay for all the other keywords not being Dutch. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From awilliam at whitemice.org Fri Dec 17 11:02:27 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Fri, 17 Dec 2010 11:02:27 -0500 Subject: PyUNO [Was: Read / Write OpenOffice SpreadSheet ?] In-Reply-To: References: Message-ID: <1292601747.15765.1.camel@linux-yu4c.site> On Fri, 2010-12-17 at 10:19 +0100, Torsten Mohr wrote: > Thanks, i read about it but as i understood it, UNO needs Python 2.3.x and > i'd like to base on something actual. I do not *believe* this is true. for instance is Python 2.6 and uses PyUNO. I would strongly recommend against floundering about in OOo's very complex XML files - it is trivially easy to render a document unusable. From Rob.Richardson at rad-con.com Fri Dec 17 11:06:30 2010 From: Rob.Richardson at rad-con.com (Rob Richardson) Date: Fri, 17 Dec 2010 11:06:30 -0500 Subject: If/then style question In-Reply-To: <4D0B7685.8080009@sequans.com> Message-ID: <04A6DB42D2BA534FAC77B90562A6A03D016894F8@server.rad-con.local> My thanks for pointing out the existence of the else: suite in the for statement. However, I remain confused. For reference, here's the original code: > def myMethod(): > for condition, exitCode in [ > (cond1, 'error1'), > (cond2, 'very bad error'), > ]: > if not condition: > break > else: > do_some_usefull_stuff() # executed only if the we never hit the > break statement. > exitCode = good1 > > return exitCode What do we know about cond1 and cond2? Do they have to be assigned before this for statement is executed? The sample code doesn't show it. The loop is going to to execute once for condition = cond1 and exitCode = 'error1'. The only thing it's going to do is check to see what condition is. Since we can assume (I hope) that cond1 is not false, then the for loop continues. Now condition = cond2 and exitCode = 'very bad error'. The if condition is still false, so the loop continues. We've come to the end now, and the else: suite is executed. We finally do some useful stuff and exitCode = good1. (Should that have been in quotes, or doesn't it matter?) But now the for loop's job is done and we return the exitCode, which at this point is good1. But I still don't understand what happens if we can't do useful stuff. Where does an error code get set, and where is that error code checked? We don't have a chance to check it in the for loop, because once we're in the else: suite the loop condition is never rechecked. Or is it? Thanks again! RobR From mail at timgolden.me.uk Fri Dec 17 11:13:38 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 17 Dec 2010 16:13:38 +0000 Subject: If/then style question In-Reply-To: References: <4d0b75d2$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4D0B8C32.7050307@timgolden.me.uk> On 17/12/2010 15:53, Steve Holden wrote: [... snip example of for-else ...] > This construct appears to be unpopular in actual use, and when it comes > up in classes and seminars there is always interesting debate as people > discuss potential uses and realise there are useful applications. I use this not infrequently, and I like it when it seems to be an elegant way to express the code path. But I still misremember from time to time and assume that the "else" clause fires when the for loop is empty. TJG From mark.dufour at gmail.com Fri Dec 17 11:34:04 2010 From: mark.dufour at gmail.com (Mark Dufour) Date: Fri, 17 Dec 2010 17:34:04 +0100 Subject: ANN: Shed Skin 0.7 In-Reply-To: References: <1292509258.10819.1410661291@webmail.messagingengine.com> Message-ID: hi malcolm, Congratulations on your latest release! > thanks! :D > > How well do python extension modules created with ShedSkin work with > applications that expose a GUI, eg. Tkinter or wxPython apps? > quite well I think, but there are some limitations you probably want to be aware of. these are described in the tutorial. > Can ShedSkin code be run in a thread and communicate with the main > interpreter thread through a Queue or Lock? (Or should one use the > multiprocessing module?) > I'm sure things are not thread safe, so you probably want to use the multiprocessing module. how to do this is also described in the tutorial (it's very simple). you probably don't want to use threading anyway for computationally intensive code (because of the GIL). several of the shedskin examples have a GUI, and the new 'pylot' example both has a GUI and uses the multiprocessing module in combination with a shedskin-generated extension module. thanks, mark. -- http://www.youtube.com/watch?v=E6LsfnBmdnk -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at nospam.invalid Fri Dec 17 11:34:23 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 17 Dec 2010 08:34:23 -0800 Subject: If/then style question References: Message-ID: <7xei9gpddc.fsf@ruckus.brouhaha.com> Jean-Michel Pichavant writes: > What about, > > def myMethod(): > for condition, exitCode in [ > (cond1, 'error1'), > (cond2, 'very bad error'), > ]: > if not condition: > break > else: > do_some_usefull_stuff() # executed only if the we never hit the > break statement. > exitCode = good1 > > return exitCode > > This version uses the 'for ... else' statement. For..else always has seemed ugly and confusing to me, as does that thing of using the captured loop indexes after the loop finishes. I'd prefer a more functional style (untested): def myMethod(): def success(): do_some_usefull_stuff() return good1 cond_table = [ (cond1, lambda: 'error1'), (cond2, lambda: 'very bad error'), (True, success) ] func = next(f for c,f in cond_table if c) return func() This uses the next() builtin from Python 2.6. You could make it more concise: def myMethod(): cond_table = [ (cond1, lambda: 'error1'), (cond2, lambda: 'very bad error'), (True, lambda: (do_some_usefull_stuff(), good1)[1]) ] return next(f for c,f in cond_table if c)() From stefan_ml at behnel.de Fri Dec 17 11:35:52 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 17 Dec 2010 17:35:52 +0100 Subject: PyUNO [Was: Read / Write OpenOffice SpreadSheet ?] In-Reply-To: <1292601747.15765.1.camel@linux-yu4c.site> References: <1292601747.15765.1.camel@linux-yu4c.site> Message-ID: Adam Tauno Williams, 17.12.2010 17:02: > On Fri, 2010-12-17 at 10:19 +0100, Torsten Mohr wrote: >> Thanks, i read about it but as i understood it, UNO needs Python 2.3.x and >> i'd like to base on something actual. > > I do not *believe* this is true. > > for instance is Python 2.6 > and uses PyUNO. The Python installation can be replaced. Last I heard, many Linux distros used the platform Python, for example, instead of shipping an embedded one with OOo. > I would strongly recommend against floundering about in OOo's very > complex XML files - it is trivially easy to render a document unusable. True. It's not so much of a problem to read them, but writing a correct document can be tricky. What works relatively well is to write a template document in OOo and do programmatic replacements in it. But that's not guaranteed to work, either. Stefan From ethan at stoneleaf.us Fri Dec 17 11:43:46 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 17 Dec 2010 08:43:46 -0800 Subject: If/then style question In-Reply-To: <04A6DB42D2BA534FAC77B90562A6A03D016894F8@server.rad-con.local> References: <04A6DB42D2BA534FAC77B90562A6A03D016894F8@server.rad-con.local> Message-ID: <4D0B9342.80606@stoneleaf.us> Rob Richardson wrote: > My thanks for pointing out the existence of the else: suite in the for > statement. However, I remain confused. For reference, here's the > original code: > >> def myMethod(): >> for condition, exitCode in [ >> (cond1, 'error1'), >> (cond2, 'very bad error'), >> ]: >> if not condition: >> break >> else: >> do_some_usefull_stuff() # executed only if the we never hit the > >> break statement. >> exitCode = good1 >> >> return exitCode > > What do we know about cond1 and cond2? Do they have to be assigned > before this for statement is executed? The sample code doesn't show it. cond1 and cond2 should be expressions of some sort, e.g. check_files() or feedback (feedback being a variable of some sort). > The loop is going to to execute once for condition = cond1 and exitCode > = 'error1'. The only thing it's going to do is check to see what > condition is. Since we can assume (I hope) that cond1 is not false, > then the for loop continues. Now condition = cond2 and exitCode = 'very > bad error'. The if condition is still false, so the loop continues. > We've come to the end now, and the else: suite is executed. We finally > do some useful stuff and exitCode = good1. (Should that have been in > quotes, or doesn't it matter?) But now the for loop's job is done and > we return the exitCode, which at this point is good1. > > But I still don't understand what happens if we can't do useful stuff. > Where does an error code get set, and where is that error code checked? > We don't have a chance to check it in the for loop, because once we're > in the else: suite the loop condition is never rechecked. Or is it? You have outlined what happens when cond1 and cond2 both evaluate to True -- what happens if, say, cond2 evaluates to False? . . . . . if not cond2 becomes True, we hit the break, do not do do_some_usefull_stuff(), but proceed to return exitCode -- and exitCode was set in the for loop to 'very bad error' when condition was set to cond2. The exitCode no longer needs to be checked inside the function, because there is no chance of do_some_useful_stuff running if any of the conditions are False. Hope this helps. ~Ethan~ From mdw at distorted.org.uk Fri Dec 17 11:45:01 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 17 Dec 2010 16:45:01 +0000 Subject: If/then style question References: <4d0b75d2$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87ei9gz6uq.fsf.mdw@metalzone.distorted.org.uk> Steve Holden writes: > I think the choice of keyword is probably not Guido's crowning > language achievement, I remember the behaviour by considering a typical application: for thing in things: if shinyp(thing): break else: raise DullError, 'nothing shiny found' In this kind of search loop, `break' signifies a kind of successful completion: the `for' loop can be considered to be a test acting over an iterable, and `else' therefore denotes the action if the test fails. I don't know whether that's the official intuition, or even if there is an official intuition, but it works well enough for me. I'm quite fond of Python's extra `else' clauses in `for' and (particularly) `try'. -- [mdw] From steve at holdenweb.com Fri Dec 17 11:46:56 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 17 Dec 2010 11:46:56 -0500 Subject: If/then style question In-Reply-To: <4D0B8C32.7050307@timgolden.me.uk> References: <4d0b75d2$0$29997$c3e8da3$5496439d@news.astraweb.com> <4D0B8C32.7050307@timgolden.me.uk> Message-ID: On 12/17/2010 11:13 AM, Tim Golden wrote: > On 17/12/2010 15:53, Steve Holden wrote: > > [... snip example of for-else ...] > >> This construct appears to be unpopular in actual use, and when it comes >> up in classes and seminars there is always interesting debate as people >> discuss potential uses and realise there are useful applications. > > I use this not infrequently, and I like it when it seems to be an > elegant way to express the code path. But I still misremember from > time to time and assume that the "else" clause fires when the for > loop is empty. > Yes, that's a common misconception. The classical use is something like for item in possibilities: if item == target: break else: raise NotFound("Didn't find it") Though of course arguably that logic might be expressed in other ways, such as if target not in possibilities: raise NotFound("Didn't find it") regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From arnodel at gmail.com Fri Dec 17 11:59:37 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Fri, 17 Dec 2010 16:59:37 +0000 Subject: If/then style question References: <4d0b75d2$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <874oacbaiu.fsf@gmail.com> Tim Golden writes: > On 17/12/2010 15:53, Steve Holden wrote: > > [... snip example of for-else ...] > >> This construct appears to be unpopular in actual use, and when it comes >> up in classes and seminars there is always interesting debate as people >> discuss potential uses and realise there are useful applications. > > I use this not infrequently, and I like it when it seems to be an > elegant way to express the code path. But I still misremember from > time to time and assume that the "else" clause fires when the for > loop is empty. I use it from time to time, even though, like you, I used to always be unsure when the "else:" suite would be executed. I now remember this idiom as the "break else" construct: either the loop breaks, or the "else:" suite is executed. -- Arnaud From python at bdurham.com Fri Dec 17 12:13:07 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 17 Dec 2010 12:13:07 -0500 Subject: If/then style question In-Reply-To: <874oacbaiu.fsf@gmail.com> References: <4d0b75d2$0$29997$c3e8da3$5496439d@news.astraweb.com> <874oacbaiu.fsf@gmail.com> Message-ID: <1292605987.20936.1410872247@webmail.messagingengine.com> > I now remember this idiom as the "break else" construct: either the loop breaks, or the "else:" suite is executed. A perfect description. Malcolm From invalid at invalid.invalid Fri Dec 17 12:26:08 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 17 Dec 2010 17:26:08 +0000 (UTC) Subject: If/then style question References: Message-ID: On 2010-12-16, Stefan Sonnenberg-Carstens wrote: > The advantage in latter case is fewer operations, because you can > skip the assignments, and it is more readable. > > The "one entry, one exit" is an advice. Not a law. > Your code is OK. > > As long as it works ;-) Even that last bit isn't that important. Give me code that's easy-to-read and doesn't work rather code that works and can't be read any day. -- Grant Edwards grant.b.edwards Yow! What's the MATTER at Sid? ... Is your BEVERAGE gmail.com unsatisfactory? From invalid at invalid.invalid Fri Dec 17 12:31:17 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 17 Dec 2010 17:31:17 +0000 (UTC) Subject: If/then style question References: <4d0aa5e7$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-12-16, Steven D'Aprano wrote: > On Thu, 16 Dec 2010 21:49:07 +0000, John Gordon wrote: > >> (This is mostly a style question, and perhaps one that has already been >> discussed elsewhere. If so, a pointer to that discussion will be >> appreciated!) >> >> When I started learning Python, I wrote a lot of methods that looked >> like this: >> >> def myMethod(self, arg1, arg2): >> if some_good_condition: >> if some_other_good_condition: >> if yet_another_good_condition: >> do_some_useful_stuff() >> exitCode = good1 >> else: >> exitCode = bad3 >> else: >> exitCode = bad2 >> else: >> exitCode = bad1 >> return exitCode > > > It doesn't look like you were learning Python. It looks like you were > learning C with Python syntax :( Let's not blame C for bad program structure. No good C programmer would use that construct either. One choice in C would look like this: if (some_condition) return code1; if (other_condition) return code2; if (condition3) return code3; //do whatever work really needs to be done here. return successCode; Or, if there's cleanup that needs to be done, then you "raise a an exception": if (condition1) { ret = code1; goto errexit; } if (condition2) { ret = code2; goto errexit; } if (condition3) { ret = code3; goto errexit; } // do the normal bit of work errexit: //cleanup return ret; -- Grant Edwards grant.b.edwards Yow! Awright, which one of at you hid my PENIS ENVY? gmail.com From Rob.Richardson at rad-con.com Fri Dec 17 12:44:31 2010 From: Rob.Richardson at rad-con.com (Rob Richardson) Date: Fri, 17 Dec 2010 12:44:31 -0500 Subject: If/then style question In-Reply-To: <4D0B9342.80606@stoneleaf.us> Message-ID: <04A6DB42D2BA534FAC77B90562A6A03D01689508@server.rad-con.local> -----Original Message----- You have outlined what happens when cond1 and cond2 both evaluate to True -- what happens if, say, cond2 evaluates to False? ----- I reply ------------ And the light goes on! (And palm strikes forehead.) I was thinking that the error we were processing was raised by the do_some_useful_stuff() function. But the whole purpose of this thread was to evaluate error conditions that might have been set before we do useful stuff! Which, of course, was what the original poster was asking. My thanks again for your patience. RobR From usernet at ilthio.net Fri Dec 17 13:31:53 2010 From: usernet at ilthio.net (Tim Harig) Date: Fri, 17 Dec 2010 18:31:53 +0000 (UTC) Subject: PyUNO [Was: Read / Write OpenOffice SpreadSheet ?] References: Message-ID: On 2010-12-17, Adam Tauno Williams wrote: > I would strongly recommend against floundering about in OOo's very > complex XML files - it is trivially easy to render a document unusable. I do it all the time and have never had a problem. I don't generate the documents from scratch; I generate a template that contains everything that don't need to dynamically generate. Then I use one of two methods to to update the content.xml: 1. In the simplest cases, I only need to change a single data field. I replace the literal data in the content.xml file with: Then, using a DOM implementation, I can use getElementsByTagName() to get all of the replace tags and send the variable name to a distpach that generates the text used to replace the tag. 2. For collections of data (spreadsheet cells, table cells/rows, etc, I leave one piece of sample data in place. I then clone the DOM element that I can use as a template and delete the origional. Entering the data is then a simple matter of cloning the template element, updating the information that it contains, and adding it to the childNodes of the parent. Since tags all come from the file that OO.org/LibreOffice generated, the resulting markup will be valid. Once the content.xml file has been updated, I simply run jar as a subprocess to update the content.xml file in the ods/odt file. From stef.mientki at gmail.com Fri Dec 17 14:02:57 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Fri, 17 Dec 2010 20:02:57 +0100 Subject: PyUNO [Was: Read / Write OpenOffice SpreadSheet ?] In-Reply-To: <1292601747.15765.1.camel@linux-yu4c.site> References: <1292601747.15765.1.camel@linux-yu4c.site> Message-ID: <4D0BB3E1.8040603@gmail.com> On 17-12-2010 17:02, Adam Tauno Williams wrote: > On Fri, 2010-12-17 at 10:19 +0100, Torsten Mohr wrote: >> Thanks, i read about it but as i understood it, UNO needs Python 2.3.x and >> i'd like to base on something actual. > I do not *believe* this is true. > > for instance is Python 2.6 > and uses PyUNO. > > I would strongly recommend against floundering about in OOo's very > complex XML files - it is trivially easy to render a document unusable. > looks great, but is there something alike for Windows ? thanks, Stef Mientki From kevin.p.dwyer at gmail.com Fri Dec 17 14:18:43 2010 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Fri, 17 Dec 2010 19:18:43 +0000 (UTC) Subject: If/then style question References: Message-ID: On Thu, 16 Dec 2010 21:49:07 +0000, John Gordon wrote: > (This is mostly a style question, and perhaps one that has already been > discussed elsewhere. If so, a pointer to that discussion will be > appreciated!) > > When I started learning Python, I wrote a lot of methods that looked > like this: > > > def myMethod(self, arg1, arg2): > > if some_good_condition: > > if some_other_good_condition: > > if yet_another_good_condition: > > do_some_useful_stuff() > exitCode = good1 > > else: > exitCode = bad3 > > else: > exitCode = bad2 > > else: > exitCode = bad1 > > return exitCode > > Another way to look at this is as question of object-oriented style, as you are using a method in your example... Arguably, rather than branching your code based on the arguments being passed to your method, you can embody the required behaviour in subclasses of your class, and at runtime just use an object that "does the right thing". Of course, you end up writing the same branching in some factory object instead, but at least it isn't cluttering up your business logic any longer. Trying to write an OO-style program without using any if statements in the business logic can be an interesting exercise, albeit not a terribly realistic one. Apologies if your choice of a method for your example was entirely incidental to your question :) Kev From fetchinson at googlemail.com Fri Dec 17 14:36:25 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Fri, 17 Dec 2010 20:36:25 +0100 Subject: Added Python, WSGI to XAMPP In-Reply-To: <4D06C130.9040506@verizon.net> References: <4CFA4305.10004@it.uu.se> <4CFD6825.9020200@simplistix.co.uk> <4CFD8B29.3020006@verizon.net> <4D014A3D.7020101@verizon.net> <4D06AD69.4030302@simplistix.co.uk> <4D06B6D1.6080208@verizon.net> <4D06B671.5020601@simplistix.co.uk> <4D06C130.9040506@verizon.net> Message-ID: >>>>> How-To: Add VirtualEnv and Pylons (WSGI framework) to XAMPP >>>>> >>> >>> Maybe, if there's no Zope. Or we'll run away screaming... >> >> That is rather pathetically true... >> >> Ah well, each to their own... >> >> Chris >> > What I really don't like right off is that Pyramid is contorting the MVC > model just as Django did with their MTV model. They are both making the > controller be the view and this confuses the hell out of people who come > from true MVC based projects. > > The VIEW is the bits that stream out of the webserver back to the users > browser. The CONTROLLER is the code that gathers all the pieces from > the model and constructs the python code that is then fed to the engine > that then creates the view. And just because the controller navigates > the logic to dynamically contruct/render a view, that does not make 'it' > the view. In turbogears that is exactly what happens. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From jafo at tummy.com Fri Dec 17 16:23:46 2010 From: jafo at tummy.com (Sean Reifschneider) Date: Fri, 17 Dec 2010 14:23:46 -0700 Subject: Help with threading.local use in python-memcache module. Message-ID: <4D0BD4E2.2030906@tummy.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Some time ago I accepted a patch to base the memcache client module on the threading.local class. Now I've got some reports of issues with this that I'm not sure what the best way to resolve is. Bug #530229: https://bugs.launchpad.net/python-memcached/+bug/530229 says: Client is derived from threading.local presumably at some misguided sense of working across multiple threads. However this doesn't work if the same Client is used across threads serially. For instance if I create a client in one thread and then call set_servers and then use the Client in another thread the set_servers call would have had no effect since the servers and buckets are per-thread due to threading.local. and that the set_servers call only impacts one thread rather than them all. I'm a bit reluctant to just remove threading.local, in case anyone is relying on it now that it's in there. But I'd like to offer a solution for the cases where it doesn't work. Any suggestions on the solution for this? Thanks, Sean -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/ iD8DBQFNC9TixUhyMYEjVX0RAnOWAJwKZnmE/6cKR4I4tl4Km//gtkxo1QCgvK1Y ULmOdWnAViTzAS4sMts97ZA= =7qXJ -----END PGP SIGNATURE----- From jlundell at pobox.com Fri Dec 17 17:19:54 2010 From: jlundell at pobox.com (JLundell) Date: Fri, 17 Dec 2010 14:19:54 -0800 (PST) Subject: class inheritance In-Reply-To: <3db38a5b-4ede-4a14-954e-f5c9be1008ee@a10g2000pri.googlegroups.com> Message-ID: On Saturday, March 13, 2010 9:03:36 AM UTC-8, Jonathan Lundell wrote: > I've got a subclass of fractions.Fraction called Value; it's a mostly > trivial class, except that it overrides __eq__ to mean 'nearly equal'. > However, since Fraction's operations result in a Fraction, not a > Value, I end up with stuff like this: > > x = Value(1) + Value(2) > > where x is now a Fraction, not a Value, and x == y uses > Fraction.__eq__ rather than Value.__eq__. > > This appears to be standard Python behavior (int does the same thing). > I've worked around it by overriding __add__, etc, with functions that > invoke Fraction but coerce the result. But that's tedious; there are a > lot of methods to override. > > So I'm wondering: is there a more efficient way to accomplish what I'm > after? I recently implemented a different approach to this. I've got: class Rational(fractions.Fraction): ... and some methods of my own, including my own __new__ and __str__ (which is one of the reasons I need the class). Then after (outside) the class definition, this code that was inspired by something similar I noticed in Python Cookbook. There are two things going on here. One is, of course, the automation at import time. The other is that the wrapper gets a Fraction instance and simply overrides __class__, rather than creating yet another Rational and unbinding the interim Fraction. Seems to work quite well. # create wrappers for Rational methods that return Rational (not Fraction) objects # def _wrap_method(method): "wrap a Fraction method in Rational" fraction_method = getattr(Fraction, method) def x(*args): "call Fraction and change result to Rational" v = fraction_method(*args) v.__class__ = Rational return v x.func_name = method setattr(Rational, method, x) for name in "pos neg abs trunc".split(): _wrap_method("__%s__" % name) # wrap method, eg __pos__ for name in "add sub mul div truediv floordiv mod pow".split(): _wrap_method("__%s__" % name) # wrap method, eg __add__ _wrap_method("__r%s__" % name) # wrap reversed-argument method, eg __radd__ del _wrap_method From alon.sebastian at gmail.com Fri Dec 17 17:57:28 2010 From: alon.sebastian at gmail.com (Sebastian Alonso) Date: Fri, 17 Dec 2010 19:57:28 -0300 Subject: subprocess.Popen() and a .msi installer Message-ID: Hey everyone, I'm working on a script which uses subprocess to launch a bunch of installers, but I'm getting problems with .msi installers although .exe ones work fine. The output I get is this: >>> import subprocess >>> p = subprocess.Popen('python.msi') Traceback (most recent call last): File "", line 1, in p = subprocess.Popen('python.msi') File "C:\Python25\lib\subprocess.py", line 593, in __init__ errread, errwrite) File "C:\Python25\lib\subprocess.py", line 793, in _execute_child startupinfo) WindowsError: [Error 8] %1 no es una aplicaci?n Win32 v?lida >>> Has this ever happen to any of you? The idea is to get this running, make it an exe (with py2exe) and use it whenever I need to install my whole development environment in the right order. Thanks in advance to all of you. Alonso Sebastian. -------------- next part -------------- An HTML attachment was scrubbed... URL: From eric.frederich at gmail.com Fri Dec 17 17:58:54 2010 From: eric.frederich at gmail.com (Eric Frederich) Date: Fri, 17 Dec 2010 17:58:54 -0500 Subject: Creating custom types from C code Message-ID: Hello, I have an extension module for a 3rd party library in which I am wrapping some structures. My initial attempt worked okay on Windows but failed on Linux. I was doing it in two parts. The first part on the C side of things I was turning the entire structure into a char array. The second part in Python code I would unpack the structure. Anyway, I decided I should be doing things a little cleaner so I read up on "Defining New Types" http://docs.python.org/extending/newtypes.html I got it to work but I'm not sure how to create these new objects from C. My setup is almost exactly like the example on that page except instead of 2 strings and an integer I have 5 unsigned ints. I do not expect to ever be creating these objects in Python. They will only be created as return values from my wrapper functions to the 3rd party library. I could return a tuple from those functions but I want to use dot notation (e.g. somestruct.var1). So, question number 1: Is defining my own type like that overkill just to have an object to access using dots? I'll never create those objects from Python. Is there a shortcut to creating objects and setting attributes from within C? In any case, I was able to create my own custom object from C code like so... PyObject *foo(SomeCStruct bar){ PyObject *ret; ret = _PyObject_New(&mymodule_SomeStructType); PyObject_SetAttrString(ret, "var1" , Py_BuildValue("I", bar.var1 )); PyObject_SetAttrString(ret, "var2" , Py_BuildValue("I", bar.var2 )); PyObject_SetAttrString(ret, "var3" , Py_BuildValue("I", bar.var3 )); PyObject_SetAttrString(ret, "var4" , Py_BuildValue("I", bar.var4 )); PyObject_SetAttrString(ret, "var5" , Py_BuildValue("I", bar.var5 )); return ret; } When using _PyObject_New I notice that neither my new or init function are ever called. I verified that they are getting called when creating the object from Python (which I would never do anyway). Question number 2: Do I need to be calling PyObject_SetAttrString or is there a way to set the unsigned ints on the structure direcly? It seems overkill to create a Python object for an unsigned int just to set it as an attribute on a custom defined type. Question number 3: In the above code, is there a memory leak? Should I be Py_DECREF'ing the return value from Py_BuildValue after I'm done using it. From emile at fenx.com Fri Dec 17 18:08:44 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 17 Dec 2010 15:08:44 -0800 Subject: Odd listcomp behaviour Message-ID: Does anyone else consider this a bug? Python 2.6.2 (r262:71600, Jun 16 2009, 11:09:39) [GCC 3.4.6 20060404 (Red Hat 3.4.6-10)] on linux2 Type "help", "copyright", "credits" or "license" for more information. ---1--- >>> skippedords = '1,2,3,4,5' >>> ['10%s' % ii for ii in skippedords.split(',')] ['101', '102', '103', '104', '105'] ---2--- >>> skippedords = '' >>> ['10%s' % ii for ii in skippedords.split(',')] ['10'] ---3--- >>> test = '' >>> ['%s' % ii for ii in test.split() ] [] I got stung because I expected ---2--- to do what ---3--- did. Emile From emile at fenx.com Fri Dec 17 18:17:10 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 17 Dec 2010 15:17:10 -0800 Subject: Odd listcomp behaviour In-Reply-To: References: Message-ID: On 12/17/2010 3:08 PM Emile van Sebille said... > Does anyone else consider this a bug? Hmmm... looks like it's split that I've got the issue with... >>> "this is a test".split() ['this', 'is', 'a', 'test'] >>> "this is a test".split(' ') ['this', 'is', 'a', 'test'] >>> "".split(' ') [''] >>> "".split() [] Emile From emile at fenx.com Fri Dec 17 18:20:46 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 17 Dec 2010 15:20:46 -0800 Subject: Odd listcomp behaviour In-Reply-To: References: Message-ID: On 12/17/2010 3:17 PM Emile van Sebille said... > On 12/17/2010 3:08 PM Emile van Sebille said... >> Does anyone else consider this a bug? > > Hmmm... looks like it's split that I've got the issue with... > Nevermind... if it's documented it's not a bug, right? Hrrmph. Emile str.split([sep[, maxsplit]])? Return a list of the words in the string, using sep as the delimiter string. If maxsplit is given, at most maxsplit splits are done (thus, the list will have at most maxsplit+1 elements). If maxsplit is not specified, then there is no limit on the number of splits (all possible splits are made). If sep is given, consecutive delimiters are not grouped together and are deemed to delimit empty strings (for example, '1,,2'.split(',') returns ['1', '', '2']). The sep argument may consist of multiple characters (for example, '1<>2<>3'.split('<>') returns ['1', '2', '3']). Splitting an empty string with a specified separator returns ['']. If sep is not specified or is None, a different splitting algorithm is applied: runs of consecutive whitespace are regarded as a single separator, and the result will contain no empty strings at the start or end if the string has leading or trailing whitespace. Consequently, splitting an empty string or a string consisting of just whitespace with a None separator returns []. For example, ' 1 2 3 '.split() returns ['1', '2', '3'], and ' 1 2 3 '.split(None, 1) returns ['1', '2 3 ']. From benjamin.kaplan at case.edu Fri Dec 17 18:27:36 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 17 Dec 2010 18:27:36 -0500 Subject: subprocess.Popen() and a .msi installer In-Reply-To: References: Message-ID: On Fri, Dec 17, 2010 at 5:57 PM, Sebastian Alonso wrote: > Hey everyone, I'm working on a script which uses subprocess to launch a > bunch of installers, but I'm getting problems with .msi installers although > .exe ones work fine. The output I get is this: > >>>> import subprocess >>>> p = subprocess.Popen('python.msi') > Traceback (most recent call last): > File "", line 1, in > p = subprocess.Popen('python.msi') > File "C:\Python25\lib\subprocess.py", line 593, in __init__ > errread, errwrite) > File "C:\Python25\lib\subprocess.py", line 793, in _execute_child > startupinfo) > WindowsError: [Error 8] %1 no es una aplicaci?n Win32 v?lida >>>> > > Has this ever happen to any of you? The idea is to get this running, make it > an exe (with py2exe) and use it whenever I need to install my whole > development environment in the right order. > > Thanks in advance to all of you. > > > Alonso Sebastian. > msi files are not executables. You need to use msiexec to run them. From ethan at stoneleaf.us Fri Dec 17 18:28:33 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 17 Dec 2010 15:28:33 -0800 Subject: Odd listcomp behaviour In-Reply-To: References: Message-ID: <4D0BF221.8080505@stoneleaf.us> Emile van Sebille wrote: > Does anyone else consider this a bug? > > Python 2.6.2 (r262:71600, Jun 16 2009, 11:09:39) > [GCC 3.4.6 20060404 (Red Hat 3.4.6-10)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > > ---1--- > >>> skippedords = '1,2,3,4,5' > >>> ['10%s' % ii for ii in skippedords.split(',')] > ['101', '102', '103', '104', '105'] > > ---2--- > >>> skippedords = '' > >>> ['10%s' % ii for ii in skippedords.split(',')] > ['10'] > > ---3--- > >>> test = '' > >>> ['%s' % ii for ii in test.split() ] > [] > > > I got stung because I expected ---2--- to do what ---3--- did. It's stung me too (more times than I care to admit! ;), but it's not a bug. 2.5 docs: split( [sep [,maxsplit]]) Return a list of the words in the string, using sep as the delimiter string. ... Splitting an empty string with a specified separator returns "['']". If sep is not specified or is None, a different splitting algorithm is applied. ... Splitting an empty string or a string consisting of just whitespace returns an empty list. Note the bit in the second paragraph. Here's my code snippet: Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. --> test = '' --> test.split() [] --> test.split(' ') [''] --> test.split(',') [''] --> test.split(None) [] Hope this helps! ~Ethan~ From python at mrabarnett.plus.com Fri Dec 17 18:29:45 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 17 Dec 2010 23:29:45 +0000 Subject: Odd listcomp behaviour In-Reply-To: References: Message-ID: <4D0BF269.2020203@mrabarnett.plus.com> On 17/12/2010 23:08, Emile van Sebille wrote: > Does anyone else consider this a bug? > > Python 2.6.2 (r262:71600, Jun 16 2009, 11:09:39) > [GCC 3.4.6 20060404 (Red Hat 3.4.6-10)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > > ---1--- > >>> skippedords = '1,2,3,4,5' > >>> ['10%s' % ii for ii in skippedords.split(',')] > ['101', '102', '103', '104', '105'] > > ---2--- > >>> skippedords = '' > >>> ['10%s' % ii for ii in skippedords.split(',')] > ['10'] > > ---3--- > >>> test = '' > >>> ['%s' % ii for ii in test.split() ] > [] > > > I got stung because I expected ---2--- to do what ---3--- did. > It's not a bug. The third example is the odd one out because it splits on a sequence of one or more (whitespace) characters and discards empty strings. For example: >>> ',,1,,2,,'.split(',') ['', '', '1', '', '2', '', ''] >>> ' 1 2 '.split(' ') ['', '', '1', '', '2', '', ''] >>> # But... >>> ' 1 2 '.split() ['1', '2'] From tjreedy at udel.edu Fri Dec 17 18:56:57 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 17 Dec 2010 18:56:57 -0500 Subject: Read / Write OpenOffice SpreadSheet ? In-Reply-To: References: Message-ID: On 12/17/2010 4:19 AM, Torsten Mohr wrote: > Hello, > >> There is no package needed to read or write the new open document files. >> The files are merely a jar archive containing XML files. You can open >> and update them using jar as a subprocess and manipulate the XML files >> using your favorite XML libraries DOM/SAX/XPath/Etree/etc. > > thanks for your hint. I was aware of that, OO files are a bunch of zipped > XML files. But, i searh for something more comfortable/highlevel that lets > me just do things like doc.Cell(1, 3) = 'abc' or so. http://opendocumentfellowship.com/projects/odfpy -- Terry Jan Reedy From matti.p.airas at nokia.com Fri Dec 17 19:04:33 2010 From: matti.p.airas at nokia.com (Matti Airas) Date: Fri, 17 Dec 2010 21:04:33 -0300 Subject: PySide: Python for Qt version 1.0.0~beta2 "Mineshaft gap" released Message-ID: <4D0BFA91.9010203@nokia.com> The PySide team is happy to announce the second beta release of PySide: Python for Qt. New versions of some of the PySide toolchain components (API Extractor and Shiboken) have been released as well. This is a source code release only; we hope our community packagers will be providing provide binary packages shortly. To acquire the source code packages, refer to our download wiki page [1] or pull the relevant tagged versions from our git repositories [2]. Major changes since 1.0.0~beta1 =============================== PySide now supports exposing list-like properties to QML using QDeclarativeListProperty. Documentation is still rather sparse, but refer to the example to see a how it works [3]. Other than the QML work, we have been working on fixing outstanding bugs. Since beta1, a total of 16 high-priority bugs have been fixed. See the list of fixed bugs at the end of this message. Note for Windows users ====================== While preparing the release, we noticed at the last minute a regression that only occurs on Windows (bug 554) [4]. Due to insufficient time for fixing the bug, we decided to move forward with the release nevertheless. We will provide a separate patch for fixing the Windows regression within the next few days. Path towards 1.0 release ======================== There are still plenty of outstanding bugs in our Bugzilla [5]. To improve our quality in a controlled fashion, we plan to do probably a couple more beta releases after the current one. Due to the holiday season, the next release will be three weeks from now, but after that we'll return to two-week release cadence until 1.0. About PySide ============ PySide is the Nokia-sponsored Python Qt bindings project, providing access to not only the complete Qt 4.7 framework but also Qt Mobility, as well as to generator tools for rapidly generating bindings for any Qt-based libraries. The PySide project is developed in the open, with all facilities you'd expect from any modern OSS project such as all code in a git repository [2], an open Bugzilla [5] for reporting bugs, and an open design process [6]. We welcome any contribution without requring a transfer of copyright. List of bugs fixed ================== 383 qelapsedtimer_wrapper.cpp: No such file or directory 415 phonon bindings does not build 468 Segfaults, segfaults and more segfaults 489 PySide.QtGui.QImage with string buffer argument 491 pyside doesn't respect BUILD_TESTS 500 If an instance of QPrintDialog is created a deadlock happens on shutdown. 505 CppObject was destroyed before __del__ be called 508 qmltopy1 crashes when setContextProperty is called twice without keeping a reference 512 QGridLayout::getItemPosition() is not available 513 Hardcoded bool return type for operator overloads 517 Documentation for QtDeclarative is not linked in contents.html, modules.html 518 The file "genindex.html" is not found (linked from contents.html) 524 Debugging errors during work of createpackage.js on windows is hard 527 Two different PySide Wikis 542 New style signals/slots + curried functions: unexpected argument during call 543 Regression: Signals with default values broken References ========== [1] http://developer.qt.nokia.com/wiki/PySideDownloads [2] http://qt.gitorious.org/pyside [3] http://qt.gitorious.org/pyside/pyside-examples/trees/master/examples/declarative/extending/chapter5-listproperties [4] http://bugs.openbossa.org/show_bug.cgi?id=554 [5] http://bugs.openbossa.org/ [6] http://www.pyside.org/docs/pseps/psep-0001.html From hpj at urpla.net Fri Dec 17 19:19:14 2010 From: hpj at urpla.net (Hans-Peter Jansen) Date: Sat, 18 Dec 2010 01:19:14 +0100 Subject: Read / Write OpenOffice SpreadSheet ? In-Reply-To: References: Message-ID: <201012180119.14801.hpj@urpla.net> On Friday 17 December 2010, 02:07:07 Torsten Mohr wrote: > Hi, > > i search for a possibility to access OpenOffoce SpreadSheets from > Python with a reasonably new version of Python. > > Can anybody point me to a package that can do this? http://ooopy.sourceforge.net/ Pete From steve+comp.lang.python at pearwood.info Sat Dec 18 00:50:46 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Dec 2010 05:50:46 GMT Subject: If/then style question References: <4d0b75d2$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4d0c4bb6$0$29997$c3e8da3$5496439d@news.astraweb.com> On Fri, 17 Dec 2010 10:53:45 -0500, Steve Holden wrote about for...else: > This construct appears to be unpopular in actual use, and when it comes > up in classes and seminars there is always interesting debate as people > discuss potential uses and realise there are useful applications. Yes, I find I don't need it often, but it is useful from time to time. I wonder whether it would have been more useful to reverse the sense of the else, and have it run only if the for loop *didn't* run to completion. That seemed more intuitive to me, and I've wanted to do this more than once. Here's a toy example: for x in sequence: if x == "spam": print("exiting early") break elif x == "ham": print("exiting early") break do_something(x) would become: for x in sequence: if x == "spam": break elif x == "ham": break do_something(x) else: print("exiting early") > I think the choice of keyword is probably not Guido's crowning language > achievement, but then since the English keywords don't make natural > sense to those who speak other languages it's at least fair that there > should be one that isn't totally natural to English speakers. A small > price to pay for all the other keywords not being Dutch. Indeed :) -- Steven From steve+comp.lang.python at pearwood.info Sat Dec 18 01:02:39 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Dec 2010 06:02:39 GMT Subject: If/then style question References: Message-ID: <4d0c4e7f$0$29997$c3e8da3$5496439d@news.astraweb.com> On Fri, 17 Dec 2010 17:26:08 +0000, Grant Edwards wrote: > Give me code that's easy-to-read and doesn't work rather code that works > and can't be read any day. Well, in that case, you'll love my new operating system, written in 100% pure Python: [start code] print("this is an operating system") [end code] I expect it to rapidly make Windows, Linux and OS-X all obsolete. Bill Gates and Steve Jobs, look out! *grin* Surely your attitude towards usefulness vs. readability will depend strongly on whether you are intending to *use* the code, or *maintain* the code? -- Steven From stefan_ml at behnel.de Sat Dec 18 01:18:35 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 18 Dec 2010 07:18:35 +0100 Subject: Creating custom types from C code In-Reply-To: References: Message-ID: Eric Frederich, 17.12.2010 23:58: > I have an extension module for a 3rd party library in which I am > wrapping some structures. > My initial attempt worked okay on Windows but failed on Linux. > I was doing it in two parts. > The first part on the C side of things I was turning the entire > structure into a char array. > The second part in Python code I would unpack the structure. > > Anyway, I decided I should be doing things a little cleaner so I read > up on "Defining New Types" > http://docs.python.org/extending/newtypes.html > > I got it to work but I'm not sure how to create these new objects from C. You may want to take a look at Cython. It makes writing C extensions easy. For one, it will do all sorts of type conversions for you, and do them efficiently and safely (you get an exception on overflow, for example). It's basically Python, so creating classes and instantiating them is trivial. Also note that it's generally not too much work to rewrite an existing C wrapper in Cython, but it's almost always worth it. You immediately get more maintainable code that's much easier to extend and work on. It's also often faster than hand written code. http://cython.org > My setup is almost exactly like the example on that page except > instead of 2 strings and an integer I have 5 unsigned ints. > > I do not expect to ever be creating these objects in Python. They > will only be created as return values from my wrapper functions to the > 3rd party library. In Cython 0.14, you can declare classes as "final" and "internal" using a decorator, meaning that they cannot be subtyped from Python and do not show up in the module dict. However, note that there is no way to prevent users from getting their hands at the type once you give them an instance. > I could return a tuple from those functions but I want to use dot > notation (e.g. somestruct.var1). Then __getattr__ or properties are your friend. > So, question number 1: > Is defining my own type like that overkill just to have an object > to access using dots? Creating wrapper objects is totally normal. Also note that recent Python versions have named tuples, BTW. > I'll never create those objects from Python. > Is there a shortcut to creating objects and setting attributes > from within C? The Cython code for instantiating classes is identical to Python. > In any case, I was able to create my own custom object from C code like so... > > PyObject *foo(SomeCStruct bar){ > PyObject *ret; > ret = _PyObject_New(&mymodule_SomeStructType); > PyObject_SetAttrString(ret, "var1" , Py_BuildValue("I", bar.var1 )); > PyObject_SetAttrString(ret, "var2" , Py_BuildValue("I", bar.var2 )); > PyObject_SetAttrString(ret, "var3" , Py_BuildValue("I", bar.var3 )); > PyObject_SetAttrString(ret, "var4" , Py_BuildValue("I", bar.var4 )); > PyObject_SetAttrString(ret, "var5" , Py_BuildValue("I", bar.var5 )); > return ret; > } > > When using _PyObject_New I notice that neither my new or init function > are ever called. > I verified that they are getting called when creating the object from > Python Things often work a little different in Python and C. Directly calling _PyObject_New() is a lot less than what Python does internally. The canonical way is to PyObject_Call() the type (or to use one of the other call functions, depending on what your arguments are). > (which I would never do anyway). Your users could do it, though, so you should make sure that won't crash the interpreter that way by leaving internal data fields uninitialised. > Question number 2: > Do I need to be calling PyObject_SetAttrString or is there a way > to set the unsigned ints on the structure direcly? > It seems overkill to create a Python object for an unsigned int > just to set it as an attribute on a custom defined type. You will have to do it at some point, though, either at instantiation time or at Python access time. Depending on the expected usage, either of the two can be more wasteful. > Question number 3: > In the above code, is there a memory leak? Should I be > Py_DECREF'ing the return value from Py_BuildValue after I'm done using > it. You can look that up in the C-API docs. If a function doesn't say that it "steals" a reference, you still own the reference when it returns and have to manually decref it (again, a thing that you won't usually have to care about in Cython). So, yes, the above leaks one reference for each call to Py_BuildValue(). Stefan From shearichard at gmail.com Sat Dec 18 05:06:44 2010 From: shearichard at gmail.com (shearichard) Date: Sat, 18 Dec 2010 02:06:44 -0800 (PST) Subject: Serialize my class as JSON causes "__init__() got an unexpected keyword argument 'indent'" ? Message-ID: <9bf689d5-6099-4d79-8b71-0bbe4e5203d3@m20g2000prc.googlegroups.com> Hi - I've got a straightforward class I want to serialize as JSON (actually I want to a serialize a list of them but I believe that's irrelevant). I've subclassed JSONEncoder and defined my own version of the 'default' method ( based upon what I read at http://docs.python.org/library/json.html ) but when I then try to serialize the class I get the (fairly weird) error message : "TypeError: __init__() got an unexpected keyword argument 'indent'". I suspect I'm doing something pretty fundamentally wrong but I don't know what - can anyone tell me what's wrong (or alternatively tell me how to log this as a bug ;-) Here's my test case : import json class SuperPeople(object): pass class People(SuperPeople, json.JSONEncoder): def __init__(self, name, age): self.__name = name self.__age = age def default(self, obj): if isinstance(obj, People): return [obj.__name, obj.__age] else: return json.JSONEncoder.default(self, obj) def main(): lstPeople = [] lstPeople.append(People("Mary", 50)) lstPeople.append(People("Joe", 40)) lstPeople.append(People("Sue", 30)) print json.dumps(lstPeople, cls=People) if __name__ == "__main__": main() ... and this is what the stacktrace looks like .... Traceback (most recent call last): File "testJSON.py", line 24, in main() File "testJSON.py", line 20, in main json.dumps(lstPeople, cls=People) File "C:\bin\installed\Python2.6\lib\json\__init__.py", line 237, in dumps **kw).encode(obj) TypeError: __init__() got an unexpected keyword argument 'indent' ... I'm running Python 2.6 on Win32. All suggestions welcomed . Richard. From __peter__ at web.de Sat Dec 18 05:30:13 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 18 Dec 2010 11:30:13 +0100 Subject: Serialize my class as JSON causes "__init__() got an unexpected keyword argument 'indent'" ? References: <9bf689d5-6099-4d79-8b71-0bbe4e5203d3@m20g2000prc.googlegroups.com> Message-ID: shearichard wrote: > Hi - I've got a straightforward class I want to serialize as JSON > (actually I want to a serialize a list of them but I believe that's > irrelevant). > > I've subclassed JSONEncoder and defined my own version of the > 'default' method ( based upon what I read at > http://docs.python.org/library/json.html ) but when I then try to > serialize the class I get the (fairly weird) error message : "TypeError: > __init__() got an unexpected keyword argument 'indent'". > > I suspect I'm doing something pretty fundamentally wrong but I don't > know what - can anyone tell me what's wrong (or alternatively tell me > how to log this as a bug ;-) > > Here's my test case : > > import json > class SuperPeople(object): > pass > class People(SuperPeople, json.JSONEncoder): > def __init__(self, name, age): > self.__name = name > self.__age = age > def default(self, obj): > if isinstance(obj, People): > return [obj.__name, obj.__age] > else: > return json.JSONEncoder.default(self, obj) > > def main(): > lstPeople = [] > lstPeople.append(People("Mary", 50)) > lstPeople.append(People("Joe", 40)) > lstPeople.append(People("Sue", 30)) > > print json.dumps(lstPeople, cls=People) > > > if __name__ == "__main__": > main() > > > ... and this is what the stacktrace looks like .... > > Traceback (most recent call last): > File "testJSON.py", line 24, in > main() > File "testJSON.py", line 20, in main > json.dumps(lstPeople, cls=People) > File "C:\bin\installed\Python2.6\lib\json\__init__.py", line 237, in > dumps > **kw).encode(obj) > TypeError: __init__() got an unexpected keyword argument 'indent' > > > ... I'm running Python 2.6 on Win32. > > All suggestions welcomed . You pass the encoder *class* to json.dumps(), so the function has to instantiate it. It does that with the arguments that an encoder class must accept. There's no way for it to expect that an encoder requires a name and an age. The solution is to separate the encoder and the class that shall be encoded. Here's one way: import json class People(object): def __init__(self, name, age): self.__name = name self.__age = age def get_json_state(self): return [self.__name, self.__age] class PeopleEncoder(json.JSONEncoder): def default(self, obj): if isinstance(obj, People): return obj.get_json_state() else: return json.JSONEncoder.default(self, obj) def main(): lstPeople = [] lstPeople.append(People("Mary", 50)) lstPeople.append(People("Joe", 40)) lstPeople.append(People("Sue", 30)) print json.dumps(lstPeople, cls=PeopleEncoder) if __name__ == "__main__": main() From fal at togliquesto.fastwebnet.it Sat Dec 18 06:29:31 2010 From: fal at togliquesto.fastwebnet.it (Francesco) Date: Sat, 18 Dec 2010 12:29:31 +0100 Subject: If/then style question In-Reply-To: <4d0aa5e7$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <4d0aa5e7$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4D0C9B1B.2030605@togliquesto.fastwebnet.it> On 17/12/2010 0.51, Steven D'Aprano wrote: > Don't get me wrong... spaghetti code is*bad*. But there are other ways > of writing bad code too, and hanging around inside a function long after > you've finished is also bad: > > def function(arg): > done = False > do_something() > if some_condition: > result = "finished" > done = True > if not done: > do_something_else() > if another_condition: > result = "now we're finished" > done = True > if not done: > do_yet_more_work() > if third_condition: > result = "finished this time for sure" > done = True > if not done: > for i in range(1000000): > if not done: > do_something_small() > if yet_another_condition: > result = "finally done!" > done = True > return result > > It's far more complicated than it need be, and does*lots* of unnecessary > work. This can be written more simply and efficiently as: > > def function(arg): > do_something() > if some_condition: > return "finished" > do_something_else() > if another_condition: > return "now we're finished" > do_yet_more_work() > if third_condition: > return "finished this time for sure" > for i in range(1000000): > do_something_small() > if yet_another_condition: > return "finally done!" I agree to your point, but I'm afraid you chose a wrong example (AFAIK, and that's not much). Sure, the second version of function(arg) is much more readable, but why do you think the first one would do "*lots* of unnecessary work"? All the overhead in that function would be: if some_condition, three IF tests, and you know that's NOT a lot! if no conditions were met, (worst case) the first version would return an exception (unless result was globally defined) while the second would happily return None. Apart from this, the overhead in the first one would amount to one million IF tests, again not a lot these days. I don't think I would rewrite that function, if I found it written in the first way... I don't mean that the fist example is better, just I'm sure you could imagine a more compelling proof of your concept. Maybe there's something I don't know... in that case, please enlighten me! Francesco From shearichard at gmail.com Sat Dec 18 06:32:29 2010 From: shearichard at gmail.com (shearichard) Date: Sat, 18 Dec 2010 03:32:29 -0800 (PST) Subject: Serialize my class as JSON causes "__init__() got an unexpected keyword argument 'indent'" ? References: <9bf689d5-6099-4d79-8b71-0bbe4e5203d3@m20g2000prc.googlegroups.com> Message-ID: On Dec 18, 11:30?pm, Peter Otten <__pete... at web.de> wrote: > shearichard wrote: > > Hi - I've got a straightforward class I want to serialize as JSON > > (actually I want to a serialize a list of them but I believe that's > > irrelevant). > > > I've subclassed JSONEncoder and defined my own version of the > > 'default' method ( based upon what I read at > >http://docs.python.org/library/json.html) but when I then try to > > serialize the class I get the (fairly weird) error message : "TypeError: > > __init__() got an unexpected keyword argument 'indent'". > > > I suspect I'm doing something pretty fundamentally wrong but I don't > > know what - can anyone tell me what's wrong (or alternatively tell me > > how to log this as a bug ;-) > > > Here's my test case : > > > import json > > class SuperPeople(object): > > ? ? pass > > class People(SuperPeople, json.JSONEncoder): > > ? ? def __init__(self, name, age): > > ? ? ? ? self.__name = name > > ? ? ? ? self.__age = age > > ? ? def default(self, obj): > > ? ? ? ? if isinstance(obj, People): > > ? ? ? ? ? ? return [obj.__name, obj.__age] > > ? ? ? ? else: > > ? ? ? ? ? ? return json.JSONEncoder.default(self, obj) > > > def main(): > > ? ? lstPeople = [] > > ? ? lstPeople.append(People("Mary", 50)) > > ? ? lstPeople.append(People("Joe", 40)) > > ? ? lstPeople.append(People("Sue", 30)) > > > ? ? print json.dumps(lstPeople, cls=People) > > > if __name__ == "__main__": > > ? ? main() > > > ... and this is what the stacktrace looks like ?.... > > > Traceback (most recent call last): > > ? File "testJSON.py", line 24, in > > ? ? main() > > ? File "testJSON.py", line 20, in main > > ? ? json.dumps(lstPeople, cls=People) > > ? File "C:\bin\installed\Python2.6\lib\json\__init__.py", line 237, in > > dumps > > ? ? **kw).encode(obj) > > TypeError: __init__() got an unexpected keyword argument 'indent' > > > ... I'm running Python 2.6 on Win32. > > > All suggestions welcomed . > > You pass the encoder *class* to json.dumps(), so the function has to > instantiate it. It does that with the arguments that an encoder class must > accept. There's no way for it to expect that an encoder requires a name and > an age. > > The solution is to separate the encoder and the class that shall be encoded. > Here's one way: > > import json > > class People(object): > ? ? def __init__(self, name, age): > ? ? ? ? self.__name = name > ? ? ? ? self.__age = age > ? ? def get_json_state(self): > ? ? ? ? return [self.__name, self.__age] > > class PeopleEncoder(json.JSONEncoder): > ? ? def default(self, obj): > ? ? ? ? if isinstance(obj, People): > ? ? ? ? ? ? return obj.get_json_state() > ? ? ? ? else: > ? ? ? ? ? ? return json.JSONEncoder.default(self, obj) > > def main(): > ? ? lstPeople = [] > ? ? lstPeople.append(People("Mary", 50)) > ? ? lstPeople.append(People("Joe", 40)) > ? ? lstPeople.append(People("Sue", 30)) > > ? ? print json.dumps(lstPeople, cls=PeopleEncoder) > > if __name__ == "__main__": > ? ? main() Brilliant - thank you very much. Now that you've explained it I can see why the documentation is written the way it is ! Before I saw your example I thought the documentation was a bit strange but I can see now what it was trying to tell me ! Your help is much appreciated. Richard. From nobody at nowhere.com Sat Dec 18 10:04:33 2010 From: nobody at nowhere.com (Nobody) Date: Sat, 18 Dec 2010 15:04:33 +0000 Subject: subprocess.Popen() and a .msi installer References: Message-ID: On Fri, Dec 17, 2010 at 17:57, Sebastian Alonso wrote: > Hey everyone, I'm working on a script which uses subprocess to launch a > bunch of installers, but I'm getting problems with .msi installers > although .exe ones work fine. The output I get is this: > >>>> import subprocess >>>> p = subprocess.Popen('python.msi') You need to add shell=True to "execute" anything which isn't a binary executable (EXE). From timr at probo.com Sat Dec 18 14:20:53 2010 From: timr at probo.com (Tim Roberts) Date: Sat, 18 Dec 2010 11:20:53 -0800 Subject: Newbie question about importing modules. References: <24e3fd89-79d9-4329-bdb7-a050597c09ab@o9g2000pre.googlegroups.com> <7f998afc-1406-4055-b00d-4107c7fcb0af@glegroupsg2000goo.googlegroups.com> Message-ID: cronoklee wrote: > >Hey thanks for the help fellas. The links were helpful and the pyExe >program looks great. I might well end up using this. > >I'm still a little confused as to how the directory structure works. PIL >(http://www.pythonware.com/products/pil/#pil117), for example comes packed >in a folder called Imaging-1.1.7 which contains a bunch of other >directories, one of which is PIL. That is a source distribution. It is not intended to be used as is -- it must be installed first. The installation process will build whatever shared libraries might be required, and then move the directories and folders into the site-packages directory of your Python installation. In this case, it will create a subdirectory called site-packages/PIL. The "site-packages" directory is already on your Python path, so when you say from PIL import Image the interpreter will scan through all of the directories in the path, notice that one of them contains a folder called PIL that has the right format for a module (meaning it has __init__.py), and will bring in Image.py from that directory. The PIL installer also creates a file called site-packages/PIL.pth which contains the name "PIL". Python looks for .pth files and adds those directories to the module path at startup. So, this would ALSO work: import Image >Sorry for the stupidity - I'm coming from PHP where you just include path/to/script.php so this is a bit alien to me. That certainly works for individual scripts, but even with PHP there are customary central locations where complicated packages are installed. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From greno at verizon.net Sat Dec 18 14:51:55 2010 From: greno at verizon.net (Gerry Reno) Date: Sat, 18 Dec 2010 14:51:55 -0500 Subject: Added Python, WSGI to XAMPP In-Reply-To: References: <4CFA4305.10004@it.uu.se> <4CFD6825.9020200@simplistix.co.uk> <4CFD8B29.3020006@verizon.net> <4D014A3D.7020101@verizon.net> <4D06AD69.4030302@simplistix.co.uk> <4D06B6D1.6080208@verizon.net> <4D06B671.5020601@simplistix.co.uk> <4D06C130.9040506@verizon.net> Message-ID: <4D0D10DB.4070102@verizon.net> On 12/17/2010 02:36 PM, Daniel Fetchinson wrote: >>>>>> How-To: Add VirtualEnv and Pylons (WSGI framework) to XAMPP >>>>>> >>>> >>>> Maybe, if there's no Zope. Or we'll run away screaming... >>> >>> That is rather pathetically true... >>> >>> Ah well, each to their own... >>> >>> Chris >>> >> What I really don't like right off is that Pyramid is contorting the MVC >> model just as Django did with their MTV model. They are both making the >> controller be the view and this confuses the hell out of people who come >> from true MVC based projects. >> >> The VIEW is the bits that stream out of the webserver back to the users >> browser. The CONTROLLER is the code that gathers all the pieces from >> the model and constructs the python code that is then fed to the engine >> that then creates the view. And just because the controller navigates >> the logic to dynamically contruct/render a view, that does not make 'it' >> the view. > > In turbogears that is exactly what happens. > > Cheers, > Daniel > > > How-To: Add VirtualEnv and TurboGears2 (WSGI frmwk) to XAMPP http://www.apachefriends.org/f/viewtopic.php?f=17&t=43207 -Gerry From greg.ewing at canterbury.ac.nz Sat Dec 18 18:27:44 2010 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sun, 19 Dec 2010 12:27:44 +1300 Subject: ANN: PyGUI 2.3.3 Message-ID: PyGUI 2.3.3 is available: http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ Minor update to fix a problem with the previous release on some versions of MacOSX. What is PyGUI? -------------- PyGUI is a cross-platform GUI toolkit designed to be lightweight and have a highly Pythonic API. -- Gregory Ewing greg.ewing at canterbury.ac.nz http://www.cosc.canterbury.ac.nz/greg.ewing/ From tjreedy at udel.edu Sat Dec 18 18:28:48 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 18 Dec 2010 18:28:48 -0500 Subject: Serialize my class as JSON causes "__init__() got an unexpected keyword argument 'indent'" ? In-Reply-To: References: <9bf689d5-6099-4d79-8b71-0bbe4e5203d3@m20g2000prc.googlegroups.com> Message-ID: On 12/18/2010 6:32 AM, shearichard wrote: > Brilliant - thank you very much. > > Now that you've explained it I can see why the documentation is > written the way it is ! Before I saw your example I thought the > documentation was a bit strange but I can see now what it was trying > to tell me ! If you have any idea who to improve that part of the doc so you would have understood it without Peter's nice explanation and example here, please open a doc issue on the tracker. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Sat Dec 18 19:05:22 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Dec 2010 00:05:22 GMT Subject: If/then style question References: <4d0aa5e7$0$29997$c3e8da3$5496439d@news.astraweb.com> <4D0C9B1B.2030605@togliquesto.fastwebnet.it> Message-ID: <4d0d4c42$0$29997$c3e8da3$5496439d@news.astraweb.com> On Sat, 18 Dec 2010 12:29:31 +0100, Francesco wrote: [...] > I agree to your point, but I'm afraid you chose a wrong example (AFAIK, > and that's not much). Sure, the second version of function(arg) is much > more readable, but why do you think the first one would do "*lots* of > unnecessary work"? > All the overhead in that function would be: > if some_condition, three IF tests, and you know that's NOT a lot! Well, let's try it with a working (albeit contrived) example. This is just an example -- obviously I wouldn't write the function like this in real life, I'd use a while loop, but to illustrate the issue it will do. def func1(n): result = -1 done = False n = (n+1)//2 if n%2 == 1: result = n done = True if not done: n = (n+1)//2 if n%2 == 1: result = n done = True if not done: n = (n+1)//2 if n%2 == 1: result = n done = True if not done: for i in range(1000000): if not done: n = (n+1)//2 if n%2 == 1: result = n done = True return result def func2(n): n = (n+1)//2 if n%2 == 1: return n n = (n+1)//2 if n%2 == 1: return n n = (n+1)//2 if n%2 == 1: return n for i in range(1000000): n = (n+1)//2 if n%2 == 1: return n return -1 Not only is the second far more readable that the first, but it's also significantly faster: >>> from timeit import Timer >>> t1 = Timer('for i in range(20): x = func1(i)', ... 'from __main__ import func1') >>> t2 = Timer('for i in range(20): x = func2(i)', ... 'from __main__ import func2') >>> min(t1.repeat(number=10, repeat=5)) 7.3219029903411865 >>> min(t2.repeat(number=10, repeat=5)) 4.530779838562012 The first function does approximately 60% more work than the first, all of it unnecessary overhead. -- Steven From zhangqi88686 at yahoo.cn Sat Dec 18 22:44:59 2010 From: zhangqi88686 at yahoo.cn (shoesbuy) Date: Sat, 18 Dec 2010 19:44:59 -0800 (PST) Subject: moncler balck cap vest Moncler Jackets Kids Black <4d0b1def$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <60aff542-c760-48af-b683-c1749bb67435@n10g2000yqd.googlegroups.com> On Dec 17, 12:23?am, Steven D'Aprano wrote: > On Thu, 16 Dec 2010 20:32:29 -0800, Carl Banks wrote: > > Even without the cleanup issue, sometimes you want to edit a function to > > affect all return values somehow. ?If you have a single exit point you > > just make the change there; if you have mulitple you have to hunt them > > down and change all of them--if you remember to. ?I just got bit by that > > one. > > If your function has so many exit points that you can miss some of them > while editing, your function is too big, does too much, or both. Sanctimonious much? In the real world, people "miss things" and "make mistakes" and not necessarily because they are working on something too complex to handle. It happens. Carl Banks From lambdadmitry at gmail.com Sun Dec 19 01:18:07 2010 From: lambdadmitry at gmail.com (Dmitry Groshev) Date: Sat, 18 Dec 2010 22:18:07 -0800 (PST) Subject: True lists in python? Message-ID: Is there any way to use a true lists (with O(c) insertion/deletion and O(n) search) in python? For example, to make things like reversing part of the list with a constant time. From lambdadmitry at gmail.com Sun Dec 19 01:41:57 2010 From: lambdadmitry at gmail.com (Dmitry Groshev) Date: Sat, 18 Dec 2010 22:41:57 -0800 (PST) Subject: True lists in python? References: Message-ID: <97c3f195-3a56-47ca-892e-bf724bdd1601@l32g2000yqc.googlegroups.com> On Dec 19, 9:18?am, Dmitry Groshev wrote: > Is there any way to use a true lists (with O(c) insertion/deletion and > O(n) search) in python? For example, to make things like reversing > part of the list with a constant time. I forgot to mention that I mean *fast* lists. It's trivial to do things like this with objects, but it will be sloooow. From zak.mc.kraken at libero.it Sun Dec 19 01:48:54 2010 From: zak.mc.kraken at libero.it (Vito 'ZeD' De Tullio) Date: Sun, 19 Dec 2010 07:48:54 +0100 Subject: True lists in python? References: Message-ID: Dmitry Groshev wrote: > Is there any way to use a true lists (with O(c) insertion/deletion and > O(n) search) in python? For example, to make things like reversing > part of the list with a constant time. if you're interested just in "reverse" a collection maybe you can take a look at the deque[0] module. If you want "true lists" (um... "linked list"?) there are is this recipe[1] you might look. [0] http://docs.python.org/library/collections.html#collections.deque [1] http://code.activestate.com/recipes/577355-python-27-linked-list-vs- list/ -- By ZeD From lambdadmitry at gmail.com Sun Dec 19 02:12:43 2010 From: lambdadmitry at gmail.com (Dmitry Groshev) Date: Sat, 18 Dec 2010 23:12:43 -0800 (PST) Subject: True lists in python? References: Message-ID: <35a132b9-ab6b-45d9-9dd4-0a9decf078b3@d8g2000yqf.googlegroups.com> On Dec 19, 9:48?am, Vito 'ZeD' De Tullio wrote: > Dmitry Groshev wrote: > > Is there any way to use a true lists (with O(c) insertion/deletion and > > O(n) search) in python? For example, to make things like reversing > > part of the list with a constant time. > > if you're interested just in "reverse" a collection maybe you can take a > look at the deque[0] module. > > If you want "true lists" (um... "linked list"?) there are is this recipe[1] > you might look. > > [0]http://docs.python.org/library/collections.html#collections.deque > [1]http://code.activestate.com/recipes/577355-python-27-linked-list-vs- > list/ > > -- > By ZeD -I can't find any information about reverse's complexity in python docs, but it seems that deque is a linked list. Maybe this is the one I need. -Yes, I meant linked list - sorry for misunderstanding. -Linked list on objects is too slow. It must be a C-extension for a proper speed. From no.email at nospam.invalid Sun Dec 19 03:24:48 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 19 Dec 2010 00:24:48 -0800 Subject: True lists in python? References: <35a132b9-ab6b-45d9-9dd4-0a9decf078b3@d8g2000yqf.googlegroups.com> Message-ID: <7x1v5e186n.fsf@ruckus.brouhaha.com> Dmitry Groshev writes: > -I can't find any information about reverse's complexity in python > docs, but it seems that deque is a linked list. Maybe this is the one > I need. Deques are not linked lists. They're just like regular Python lists (i.e. resizeable arrays) except they can grow and shrink at both ends rather than just one. The amortized complexity of an append or pop operation (at either end) is O(1) but occasionally the list has to be reallocated, which is O(N). From steve+comp.lang.python at pearwood.info Sun Dec 19 03:33:51 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Dec 2010 08:33:51 GMT Subject: If/then style question References: <4d0b1def$0$29997$c3e8da3$5496439d@news.astraweb.com> <60aff542-c760-48af-b683-c1749bb67435@n10g2000yqd.googlegroups.com> Message-ID: <4d0dc36e$0$29997$c3e8da3$5496439d@news.astraweb.com> On Sat, 18 Dec 2010 19:59:45 -0800, Carl Banks wrote: > On Dec 17, 12:23?am, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> On Thu, 16 Dec 2010 20:32:29 -0800, Carl Banks wrote: >> > Even without the cleanup issue, sometimes you want to edit a function >> > to affect all return values somehow. ?If you have a single exit point >> > you just make the change there; if you have mulitple you have to hunt >> > them down and change all of them--if you remember to. ?I just got bit >> > by that one. >> >> If your function has so many exit points that you can miss some of them >> while editing, your function is too big, does too much, or both. > > Sanctimonious much? In the real world, people "miss things" and "make > mistakes" and not necessarily because they are working on something too > complex to handle. It happens. Really? I had no idea. I've never made a misteak, I asumed evrybody else was equally brilliant. No, wait, there was that one time... *wink* Of course people make mistakes. So what's your point? The point I was trying to make is that rather than encouraging an idiom (only one return statement, even if the algorithm is more clearly written with multiple exists) that leads to more complex, less efficient code just in case you might someday need to modify the return result, there are simple alternatives that avoid the need for anti-patterns like copy- and-paste coding or enforced single exit point. I gave two: - refactor the complex code so that it's less complex (e.g. instead of 20 exit points, which makes it easy to miss one or two, refactor it so there are two or three exit points); or if that's not practical: - wrap it in a decorator that performs the post-processing you need. Both can be simple, effective and Pythonic. Neither require the coder to use an artificial idiom just in case of some future need. The decorator solution works even if you don't have access to the source code, or if the function is a complex black box that nobody understands well enough to touch. -- Steven From steve+comp.lang.python at pearwood.info Sun Dec 19 03:49:17 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Dec 2010 08:49:17 GMT Subject: True lists in python? References: Message-ID: <4d0dc70d$0$29997$c3e8da3$5496439d@news.astraweb.com> On Sat, 18 Dec 2010 22:18:07 -0800, Dmitry Groshev wrote: > Is there any way to use a true lists (with O(c) insertion/deletion and > O(n) search) in python? Python lists have amortized constant time insertion and deletion at the end of the list, O(N) insertion and deletion at the beginning of the list, and O(N) search. > For example, to make things like reversing part > of the list with a constant time. It's been many years since I've had to worry about rolling my own low- level linked lists, but I don't think that reversing a list can be done in constant time. I can't see any way to go from this linked list: node1 -> node2 -> node3 -> node4 -> node5 -> node6 -> node7 to this: node1 -> node6 -> node5 -> node4 -> node3 -> node2 -> node7 in constant time. You have to touch each of the nodes being reversed. Others have already suggested you look at deques, but I'm curious as to what application you have where regular lists are too slow. (I assume you have actually profiled your application, and are trying to solve an actual speed issue, not just assuming it is slow.) I would normally reverse a portion of a list like this: mylist[23:42] = mylist[23:42][::-1] So long as the section you are reversing is small enough to fit in memory without paging, this should be quite quick. -- Steven From lists at cheimes.de Sun Dec 19 03:58:55 2010 From: lists at cheimes.de (Christian Heimes) Date: Sun, 19 Dec 2010 09:58:55 +0100 Subject: True lists in python? In-Reply-To: <7x1v5e186n.fsf@ruckus.brouhaha.com> References: <35a132b9-ab6b-45d9-9dd4-0a9decf078b3@d8g2000yqf.googlegroups.com> <7x1v5e186n.fsf@ruckus.brouhaha.com> Message-ID: Am 19.12.2010 09:24, schrieb Paul Rubin: > Deques are not linked lists. They're just like regular Python lists > (i.e. resizeable arrays) except they can grow and shrink at both ends > rather than just one. The amortized complexity of an append or pop > operation (at either end) is O(1) but occasionally the list has to > be reallocated, which is O(N). You are both right and both wrong at the same time. Python's deques are neither linked lists nor ordinary lists. They are combination of both techniques. Deques are made of double linked blocks where each block can contain up the 62 Python objects. The type is optimized for push and pop on both sides but not for iteration or search. Christian From user at compgroups.net/ Sun Dec 19 05:39:51 2010 From: user at compgroups.net/ (plz) Date: Sun, 19 Dec 2010 04:39:51 -0600 Subject: how to measure TCP congestion windows using python ?? Message-ID: hi! i'm newbie about python and i want to measure the value of cwnd in TCP socket. I have searched from an internet and got that we could handle it from SOL_TCP, TCP_INFO...since unix had #include and we could refer to tcp_info for getting the information of TCP by using this method but i don't know how to declare the tcp_info in Python.. does anyone know how to handle this? please suggest me Thanks in advance From stefan.sonnenberg at pythonmeister.com Sun Dec 19 07:02:13 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Sun, 19 Dec 2010 13:02:13 +0100 Subject: how to measure TCP congestion windows using python ?? In-Reply-To: References: Message-ID: <4D0DF445.20206@pythonmeister.com> Am 19.12.2010 11:39, schrieb plz: > hi! i'm newbie about python and i want to measure the value of cwnd in TCP socket. > > I have searched from an internet and got that we could handle it from SOL_TCP, TCP_INFO...since unix had #include and we could refer to tcp_info > for getting the information of TCP by using this method > > but i don't know how to declare the tcp_info in Python.. > does anyone know how to handle this? please suggest me > > Thanks in advance > > Which OS ? I remember these parts not being really paltform indepentend. From zak.mc.kraken at libero.it Sun Dec 19 07:59:12 2010 From: zak.mc.kraken at libero.it (Vito 'ZeD' De Tullio) Date: Sun, 19 Dec 2010 13:59:12 +0100 Subject: True lists in python? References: <4d0dc70d$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > I can't see any way to go from this linked list: > > node1 -> node2 -> node3 -> node4 -> node5 -> node6 -> node7 > > to this: > > node1 -> node6 -> node5 -> node4 -> node3 -> node2 -> node7 > > in constant time. You have to touch each of the nodes being reversed. very crude example: class Node(object): def __init__(self, value, list): self.value = value self.next = self.previous = None self.list = list def nextNode(self): if not self.list.reversed: return self.next else: return self.previous class LinkedList(object): def __init__(self): self.head = None self.reversed = False def insertAsHead(self, value): n = Node(value, self) n.next = self.head if self.head is not None: self.head.previous = n self.head = n def main(): ll = LinkedList() ll.insertAsHead(4) ll.insertAsHead(3) ll.insertAsHead(2) n = ll.head while n is not None: n_previous = n print n.value n = n.nextNode() print 'reversed' ll.reversed = True n = n_previous while n is not None: print n.value n = n.nextNode() if __name__ == '__main__': main() -- By ZeD From stefan.sonnenberg at pythonmeister.com Sun Dec 19 08:56:27 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Sun, 19 Dec 2010 14:56:27 +0100 Subject: how to measure TCP congestion windows using python ?? In-Reply-To: References: Message-ID: <4D0E0F0B.5060601@pythonmeister.com> Am 19.12.2010 11:39, schrieb plz: > hi! i'm newbie about python and i want to measure the value of cwnd in TCP socket. > > I have searched from an internet and got that we could handle it from SOL_TCP, TCP_INFO...since unix had #include and we could refer to tcp_info > for getting the information of TCP by using this method > > but i don't know how to declare the tcp_info in Python.. > does anyone know how to handle this? please suggest me > > Thanks in advance > > Here is non-portable way to get the data under Linux: import socket from ctypes import * cdll.LoadLibrary('libc.so.6') libc = CDLL('libc.so.6') class tcp_info(Structure): _fields_ = [ ('tcpi_state',c_uint8), ('tcpi_ca_state',c_uint8), ('tcpi_retransmits',c_uint8), ('tcpi_probes',c_uint8), ('tcpi_backoff',c_uint8), ('tcpi_options',c_uint8), ('tcpi_snd_wscale',c_uint8,4), ('tcpi_rcv_wscale',c_uint8,4), ('tcpi_rto',c_uint32), ('tcpi_ato',c_uint32), ('tcpi_snd_mss',c_uint32), ('tcpi_rcv_mss',c_uint32), ('tcpi_unacked',c_uint32), ('tcpi_sacked',c_uint32), ('tcpi_lost',c_uint32), ('tcpi_retrans',c_uint32), ('tcpi_fackets',c_uint32), ('tcpi_last_data_sent',c_uint32), ('tcpi_last_ack_sent',c_uint32), ('tcpi_last_data_recv',c_uint32), ('tcpi_last_ack_recv',c_uint32), ('tcpi_pmtu',c_uint32), ('tcpi_rcv_ssthresh',c_uint32), ('tcpi_rtt',c_uint32), ('tcpi_rttvar',c_uint32), ('tcpi_snd_ssthresh',c_uint32), ('tcpi_snd_cwnd',c_uint32), ('tcpi_advmss',c_uint32), ('tcpi_reordering',c_uint32), ('tcpi_rcv_rtt',c_uint32), ('tcpi_rcv_space',c_uint32), ('tcpi_total_retrans',c_uint32) ] sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM,socket.IPPROTO_TCP) info = tcp_info() pinfo = pointer(info) len_info = c_uint32(sizeof(tcp_info)) plen_info = pointer(len_info) res = libc.getsockopt(sock.fileno(),socket.SOL_TCP,socket.TCP_INFO,pinfo,plen_info) if res == 0: for n in (x[0] for x in tcp_info._fields_): print n,getattr(info,n) else: print 'getsockopt() failed. (%i)' % res Tested under Ubuntu 10.10 and Python 2.6.6. From doomster at knuut.de Sun Dec 19 10:41:18 2010 From: doomster at knuut.de (Ulrich Eckhardt) Date: Sun, 19 Dec 2010 16:41:18 +0100 Subject: True lists in python? References: Message-ID: <8n6nd0FqpuU1@mid.uni-berlin.de> Dmitry Groshev wrote: > Is there any way to use a true lists (with O(c) insertion/deletion > and O(n) search) in python? Inserting/deleting in the middle requires shuffling elements around, since Python's list is an array/vector. If you don't rely on the ordering, insert or delete at the end instead, possibly swapping the last element with the one you want to delete first: class x(list): def pop(self, index=None): if index is None: return list.pop(self) res = self[index] self[index] = self[-1] self.pop() return res > For example, to make things like reversing > part of the list with a constant time. a) This doesn't work in constant time but O(n) time. b) You can have the same complexity with a Python list, too. Cheers! Uli From stefan.sonnenberg at pythonmeister.com Sun Dec 19 14:45:55 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Sun, 19 Dec 2010 20:45:55 +0100 Subject: True lists in python? In-Reply-To: References: Message-ID: <4D0E60F3.7070205@pythonmeister.com> Am 19.12.2010 07:18, schrieb Dmitry Groshev: > Is there any way to use a true lists (with O(c) insertion/deletion and > O(n) search) in python? For example, to make things like reversing > part of the list with a constant time. reversing part of the list could also be interpreted as reading it in the opposite direction from a given starting point to a known end. Perhaps you want to look into the array module, but you have to sacrifice the typelessness of a true python list: it can only contain numerical data (also char, byte). But don't know the timing pattern of array objects, only that they are *way* faster then lists. From nagle at animats.com Sun Dec 19 14:58:11 2010 From: nagle at animats.com (John Nagle) Date: Sun, 19 Dec 2010 11:58:11 -0800 Subject: True lists in python? In-Reply-To: <97c3f195-3a56-47ca-892e-bf724bdd1601@l32g2000yqc.googlegroups.com> References: <97c3f195-3a56-47ca-892e-bf724bdd1601@l32g2000yqc.googlegroups.com> Message-ID: <4d0e63d2$0$43987$742ec2ed@news.sonic.net> On 12/18/2010 10:41 PM, Dmitry Groshev wrote: > On Dec 19, 9:18 am, Dmitry Groshev wrote: >> Is there any way to use a true lists (with O(c) insertion/deletion and >> O(n) search) in python? For example, to make things like reversing >> part of the list with a constant time. > > I forgot to mention that I mean *fast* lists. It's trivial to do > things like this with objects, but it will be sloooow. Try using objects with "slots". If you have a large number of small objects, and are doing many very simple operations on them, the attribute lookup time will dominate. A nice example of when you might need real lists is for the Traveling Salesman Problem. The usual way to solve that is: 1. Link up all the nodes in a random order. 2. Pick two links at random, and cut the list into three lists. 3. Try all possible ways to arrange the three lists (there are 6*4*2/2 = 24 ways) and compute the path length for each. 4. Pick the shortest path. 5. Repeat steps 2-5 until no improvement is observed for a while. The cut-and-reassemble steps are constant time for real lists, but require expensive copying with arrays. If you're really worried about low-level performance issues, CPython is probably the wrong tool for the job. John Nagle From tomf.sessile at gmail.com Sun Dec 19 16:35:34 2010 From: tomf.sessile at gmail.com (TomF) Date: Sun, 19 Dec 2010 13:35:34 -0800 Subject: True lists in python? References: Message-ID: <2010121913353464730-tomfsessile@gmailcom> On 2010-12-18 22:18:07 -0800, Dmitry Groshev said: > Is there any way to use a true lists (with O(c) insertion/deletion and > O(n) search) in python? For example, to make things like reversing > part of the list with a constant time. I assume you mean a C extension that implements doubly linked lists (reversing part of a list is only constant time if the list is doubly-linked). I'm not aware of one. A longer answer is that many high level languages (Python, Perl, Ruby) don't bother implementing simple linked lists because they're not very useful. Instead they use hybrid data structures that can operate as lists and arrays with flexibility and acceptable costs. And if you need greater speed you usually go to special purpose arrays (for constant time access) rather than lists. -Tom From Martin at Hvidberg.net Sun Dec 19 16:41:58 2010 From: Martin at Hvidberg.net (Martin Hvidberg) Date: Sun, 19 Dec 2010 22:41:58 +0100 Subject: Reading special Danish letters in Python Message-ID: <4D0E7C26.8070204@Hvidberg.net> Dear list I have to read some data from an ASCII text file, filter it, and then export it to a .dbf file. Basically a straight forward task... My problem is that the input files contains some special national (Danish) characters, and it appears that I have to do something special to handle these in Python. The Danish language contains three letters not in the English alphabet: ?, ? and ?. E.g. the Danish city name 'SOLR?D' is red by Python as 'SOLR\xc3\x98D' The three letters, in lower and upper case, seems to get translated as follow: ? = \xc3\xa6 ? = \xc3\xb8 ? = \xc3\xa5 ? = \xc3\x86 ? = \xc3\x98 ? = \xc3\x85 Question: What is this, how do I get my Danish letters back? Best Regards Martin -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Sun Dec 19 16:42:27 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 19 Dec 2010 14:42:27 -0700 Subject: True lists in python? In-Reply-To: References: <4d0dc70d$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Dec 19, 2010 at 5:59 AM, Vito 'ZeD' De Tullio wrote: > Steven D'Aprano wrote: > >> I can't see any way to go from this linked list: >> >> node1 -> node2 -> node3 -> node4 -> node5 -> node6 -> node7 >> >> to this: >> >> node1 -> node6 -> node5 -> node4 -> node3 -> node2 -> node7 >> >> in constant time. You have to touch each of the nodes being reversed. > > very crude example: [SNIPPED] That reverses the whole list. How does it help with reversing only part of the list, as in Steven's example? From solipsis at pitrou.net Sun Dec 19 16:54:55 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Sun, 19 Dec 2010 22:54:55 +0100 Subject: True lists in python? References: <4D0E60F3.7070205@pythonmeister.com> Message-ID: <20101219225455.367a79c2@pitrou.net> On Sun, 19 Dec 2010 20:45:55 +0100 Stefan Sonnenberg-Carstens wrote: > Am 19.12.2010 07:18, schrieb Dmitry Groshev: > > Is there any way to use a true lists (with O(c) insertion/deletion and > > O(n) search) in python? For example, to make things like reversing > > part of the list with a constant time. > reversing part of the list could also be interpreted as reading it > in the opposite direction from a given starting point to a known end. > > Perhaps you want to look into the array module, but you > have to sacrifice the typelessness of a true python list: > it can only contain numerical data (also char, byte). > > But don't know the timing pattern of array objects, only that they are *way* > faster then lists. Why do you say there're much faster? Regards Antoine. From vlastimil.brom at gmail.com Sun Dec 19 17:53:48 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sun, 19 Dec 2010 23:53:48 +0100 Subject: Reading special Danish letters in Python In-Reply-To: <4D0E7C26.8070204@Hvidberg.net> References: <4D0E7C26.8070204@Hvidberg.net> Message-ID: 2010/12/19 Martin Hvidberg : > Dear list > > I have to read some data from an ASCII text file, filter it, and then export > it to a .dbf file. Basically a straight forward task... > My problem is that the input files contains some special national (Danish) > characters, and it appears that I have to do something special to handle > these in Python. > The Danish language contains three letters not in the English alphabet: ?, ? > and ?. > E.g. the Danish city name 'SOLR?D' is red by Python as 'SOLR\xc3\x98D' > The three letters, in lower and upper case, seems to get translated as > follow: > > ? = \xc3\xa6 > ? = \xc3\xb8 > ? = \xc3\xa5 > ? = \xc3\x86 > ? = \xc3\x98 > ? = \xc3\x85 > > Question: > What is this, how do I get my Danish letters back? > > Best Regards > Martin > > -- > http://mail.python.org/mailman/listinfo/python-list > > Hi, it seems, your data is utf-8 encoded text cf. >>> u"?".encode("utf-8") '\xc3\xa6' >>> u"?".encode("utf-8") '\xc3\xb8' you can decode the file content using this encoding if it is already read somewhere or use codecs.open with the same encoding >>> print '\xc3\xa6'.decode("utf-8") ? >>> hth, vbr From user at compgroups.net/ Sun Dec 19 19:45:49 2010 From: user at compgroups.net/ (plz) Date: Sun, 19 Dec 2010 18:45:49 -0600 Subject: how to measure TCP congestion windows using python ?? References: Message-ID: hi many thanks for helping me i also tried to manipulate it last night here is my code... import socket import struct sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM) tcp_info = sock.getsockopt(socket.SOL_TCP, socket.TCP_INFO, struct.calcsize('BBBBBBBLLLLLLLLLLLLLLLLLLLLLLLL')) print struct.unpack('BBBBBBBLLLLLLLLLLLLLLLLLLLLLLLL', tcp_info) the result of struct.unpack of tcp_info is following in /usr/include/linux/tcp.h used Linux Redhat and Python 2.7 anyway your code is very useful Thxs again ;) From nad at acm.org Sun Dec 19 19:52:14 2010 From: nad at acm.org (Ned Deily) Date: Sun, 19 Dec 2010 16:52:14 -0800 Subject: get python bit version as in (32 or 64) References: <4CBE0FC2.6060604@gmx.net> <6C3DD9D7-A1D6-49EA-97C2-4A6F9630758A@semanchuk.com> Message-ID: In article , Ned Deily wrote: > In article > , > Vincent Davis wrote: > > On Tue, Oct 19, 2010 at 3:55 PM, Philip Semanchuk > > wrote: > > > On Oct 19, 2010, at 5:38 PM, Hexamorph wrote: > > >> On 19.10.2010 23:18, Vincent Davis wrote: > > >>> How do I get the bit version of the installed python. In my case, osx > > >>> python2.7 binary installed. I know it runs 64 bt as I can see it in > > >>> activity monitor. but how do I ask python? > > >>> sys.version > > >>> '2.7 (r27:82508, Jul ?3 2010, 21:12:11) \n[GCC 4.0.1 (Apple Inc. build > > >>> 5493)]' > > >>> > > >> > > >> In [1]: import platform > > >> > > >> In [2]: platform.architecture() > > >> Out[2]: ('32bit', 'ELF') > > >> > > >> In [3]: > > > > > > > > > Looks a lot better than my suggestion! > > It looks better but, unfortunately, it doesn't work correctly on OS X > where a universal build can have both 32-bit and 64-bit executables in > the same file. > > $ arch -x86_64 /usr/local/bin/python2.7 -c 'import sys,platform; > print(sys.maxint,platform.architecture())' > (9223372036854775807, ('64bit', '')) > $ arch -i386 /usr/local/bin/python2.7 -c 'import sys,platform; > print(sys.maxint,platform.architecture())' > (2147483647, ('64bit', '')) > > At the moment, the sys.maxint trick is the simplest reliable test for > Python 2 on OS X. For Python 3, substitute sys.maxsize. For the record, I've supplied a patch to fix platform.architecture() for OS X universal builds: http://bugs.python.org/issue10735 The sys.maxsize (or sys.maxint prior to Python 2.6) test is still a better cross-platform choice. -- Ned Deily, nad at acm.org From bavishi.darshak at gmail.com Mon Dec 20 02:38:40 2010 From: bavishi.darshak at gmail.com (Darshak Bavishi) Date: Mon, 20 Dec 2010 13:08:40 +0530 Subject: how to handle output generated after execution of command/script on host unix machine? Message-ID: Hi Experts, I am still struggling with handling output generated after execution of command/script on host unix machine using windows client machine ssh code : import sys import datetime import time # setup logging paramiko.util.log_to_file('darshak_simple.log') ssh=paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect("*****",username="****",password="****") try: stdin,stdout,stderr=ssh.exec_command("BsPlSMProbe -f node -d > /var/log/Darshak/3.txt ") // output of this command will be store in /var/log/Darshak/ in remote machine except: {Issue is files are generating but remaining blank pls pls help me out of this} print "check" time.sleep(10) print stdout.readlines() a=stdout.readlines() print 1 ssh.close() #print stdout.readlines() Issue is files are generating but remaining blank pls pls help me out of this -- BR Darshak Bavishi -- BR Darshak Bavishi -------------- next part -------------- An HTML attachment was scrubbed... URL: From mechtheist at gmail.com Mon Dec 20 03:45:18 2010 From: mechtheist at gmail.com (mechtheist) Date: Mon, 20 Dec 2010 02:45:18 -0600 Subject: How can I intentionally crash my lappy? Message-ID: <4D0F179E.4050704@gmail.com> I am no programmer, but know the rudiments [the rudi'est of rudiments] of working with Python. I have a simple need, to have a simple script/app I can run that will crash my PC. On my desktops, I can always hit the reset, but that is not an option with my laptop. Can anyone tell me of an easy way to guarantee a program will instantly kill/BSOD my windows7/64bit laptop? Any help is much appreciated. From stefan.sonnenberg at pythonmeister.com Mon Dec 20 04:31:05 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Mon, 20 Dec 2010 10:31:05 +0100 Subject: How can I intentionally crash my lappy? In-Reply-To: <4D0F179E.4050704@gmail.com> References: <4D0F179E.4050704@gmail.com> Message-ID: <55d991ae7a5068ee10a3637b2330b5c4-EhVcX1lJRApWRxoDCzpQCEFddQZLVF5dQUBFCzBYWENGU1kWXlpwH1RcWzBeQ0wAV1leRF5Q-webmailer1@server02.webmailer.hosteurope.de> http://pcsupport.about.com/od/tipstricks/ht/makebsodxp.htm Am Mo, 20.12.2010, 09:45 schrieb mechtheist: > I am no programmer, but know the rudiments [the rudi'est of rudiments] > of working with Python. I have a simple need, to have a simple > script/app I can run that will crash my PC. On my desktops, I can > always hit the reset, but that is not an option with my laptop. Can > anyone tell me of an easy way to guarantee a program will instantly > kill/BSOD my windows7/64bit laptop? > > Any help is much appreciated. > -- > http://mail.python.org/mailman/listinfo/python-list From marc.sedda at gmail.com Mon Dec 20 05:08:57 2010 From: marc.sedda at gmail.com (MarcoS) Date: Mon, 20 Dec 2010 02:08:57 -0800 (PST) Subject: Dynamic list name from a string Message-ID: <48c5eb62-b011-4ff6-ad1e-be92abe2e2eb@o4g2000yqd.googlegroups.com> Hi, I need to create a list with a dynamic name, something like this: '%s_list' %my_dynamic list = [] It's this possible? From steve+comp.lang.python at pearwood.info Mon Dec 20 05:22:33 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Dec 2010 10:22:33 GMT Subject: How can I intentionally crash my lappy? References: Message-ID: <4d0f2e69$0$29966$c3e8da3$5496439d@news.astraweb.com> On Mon, 20 Dec 2010 02:45:18 -0600, mechtheist wrote: > I am no programmer, but know the rudiments [the rudi'est of rudiments] > of working with Python. I have a simple need, to have a simple > script/app I can run that will crash my PC. On my desktops, I can > always hit the reset, but that is not an option with my laptop. Can > anyone tell me of an easy way to guarantee a program will instantly > kill/BSOD my windows7/64bit laptop? > > Any help is much appreciated. You realise that the operating system (yes, even Windows!) is designed to *not* crash no matter what the application does? (The OS may live up to that requirement imperfectly, but still, it tries.) You'll probably find that task easier from C than from Python. But if I were to attempt such a strange thing, I'd try to shut down some critical processes used by the OS. I'm not much of a Windows person, but if you call up the task manager (ctrl-alt-del) and inspect the process list, then find one that causes the machine to crash if you shut it down, you can probably do the same thing from a script. -- Steven From steve+comp.lang.python at pearwood.info Mon Dec 20 05:32:13 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Dec 2010 10:32:13 GMT Subject: Dynamic list name from a string References: <48c5eb62-b011-4ff6-ad1e-be92abe2e2eb@o4g2000yqd.googlegroups.com> Message-ID: <4d0f30ad$0$29966$c3e8da3$5496439d@news.astraweb.com> On Mon, 20 Dec 2010 02:08:57 -0800, MarcoS wrote: > Hi, I need to create a list with a dynamic name, something like this: > > '%s_list' %my_dynamic list = [] > > It's this possible? I'm pretty sure you don't *need* to, you just think you do. It is highly unlikely that there is anything you can do with such a variable-variable- name that you can't do by a more sensible technique. But since you ask: >>> name = 'variable' >>> variable Traceback (most recent call last): File "", line 1, in NameError: name 'variable' is not defined >>> globals()[name] = "this is a bad idea, don't do it" >>> variable "this is a bad idea, don't do it" Here's another way: >>> del variable >>> exec("%s = 'this is an even worse idea, be careful with this'" % name) >>> variable 'this is an even worse idea, be careful with this' Seriously, you probably shouldn't do this. The first is harmful because it leads to confusing, complicated, unclear code that is hard to maintain; the second is harmful for the same reasons, *plus* it is slower, AND could lead to serious security bugs. Google on "code injection attack" for more information. (There are uses for these techniques, or at least similar techniques, but they are rare, fairly advanced, and quite specialised.) -- Steven From post at andre-bell.de Mon Dec 20 05:33:56 2010 From: post at andre-bell.de (Andre Alexander Bell) Date: Mon, 20 Dec 2010 11:33:56 +0100 Subject: Dynamic list name from a string In-Reply-To: <48c5eb62-b011-4ff6-ad1e-be92abe2e2eb@o4g2000yqd.googlegroups.com> References: <48c5eb62-b011-4ff6-ad1e-be92abe2e2eb@o4g2000yqd.googlegroups.com> Message-ID: <4D0F3114.5030107@andre-bell.de> Hello, On 12/20/2010 11:08 AM, MarcoS wrote: > Hi, I need to create a list with a dynamic name, something like this: > > '%s_list' %my_dynamic list = [] > > It's this possible? I would suggest you use a dictionary to store your lists like this: lists = {} lists[my_dynamic_list] = [] Maybe you tell us some more what you want to achieve... Regards Andre From pscott at uwc.ac.za Mon Dec 20 05:39:04 2010 From: pscott at uwc.ac.za (Paul Scott) Date: Mon, 20 Dec 2010 12:39:04 +0200 Subject: How can I intentionally crash my lappy? In-Reply-To: <4D0F179E.4050704@gmail.com> References: <4D0F179E.4050704@gmail.com> Message-ID: <4D0F3248.3010901@uwc.ac.za> On 20/12/2010 10:45, mechtheist wrote: > I am no programmer, but know the rudiments [the rudi'est of rudiments] > of working with Python. I have a simple need, to have a simple > script/app I can run that will crash my PC. On my desktops, I can > always hit the reset, but that is not an option with my laptop. Can > anyone tell me of an easy way to guarantee a program will instantly > kill/BSOD my windows7/64bit laptop? You could try a forkbomb and execute that via a system call. Not sure why anyone would want to do such a thing, but there you go... -- -- Paul http://www.paulscott.za.net http://twitter.com/paulscott56 http://avoir.uwc.ac.za -------------- next part -------------- All Email originating from UWC is covered by disclaimer http://www.uwc.ac.za/portal From hniksic at xemacs.org Mon Dec 20 05:57:43 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Mon, 20 Dec 2010 11:57:43 +0100 Subject: "encoding" attribute codecs.getwriter-produced streams Message-ID: <87ei9cd848.fsf@xemacs.org> Try this code: # foo.py import sys, codecs stream = codecs.getwriter('utf-8')(sys.stdout) print stream.encoding $ python foo.py | cat None I expected the `encoding' attribute to be "UTF-8", since the stream otherwise correctly functions as a utf-8 encoding stream. Is this a bug in the stream factory returned by codecs.getwriter(...)? If not, is there another way to determine a stream's output encoding that would work for both default and codecs-created streams? From marc.sedda at gmail.com Mon Dec 20 06:38:31 2010 From: marc.sedda at gmail.com (MarcoS) Date: Mon, 20 Dec 2010 03:38:31 -0800 (PST) Subject: Dynamic list name from a string References: <48c5eb62-b011-4ff6-ad1e-be92abe2e2eb@o4g2000yqd.googlegroups.com> Message-ID: <87ec1487-e42d-4f9b-8d70-cb615e123007@k25g2000vbl.googlegroups.com> Ok, thanks Steven and Andre for yours reply. This is my situation: I've a list of objects of differents classes, with a common attribute name Something like this: class Object1: obj1_name .... other fields date class Object2: obj2_name .... other fields date ... class ObjectN: objN_name .... other fields date the lists are created dynamically at runtime, depending or not if there one or more correspondig Objects, ex. list_object1 = [object1_1, object1_2 ... object1_n] ... list_objectN = [object2_1, object2_2 ... object2_n] Then i need to include all into one global list sorting the various objects by date ex global_list = [object1_1, object2_n, object1_2 ... etc] I think that Andre solution it's the best way to solve my dynamics lists problem, now I'll verify how to create the global list and sort it From rob at beyondyourken.com Mon Dec 20 06:56:35 2010 From: rob at beyondyourken.com (rob) Date: Mon, 20 Dec 2010 05:56:35 -0600 Subject: How can I intentionally crash my lappy? In-Reply-To: <55d991ae7a5068ee10a3637b2330b5c4-EhVcX1lJRApWRxoDCzpQCEFddQZLVF5dQUBFCzBYWENGU1kWXlpwH1RcWzBeQ0wAV1leRF5Q-webmailer1@server02.webmailer.hosteurope.de> References: <4D0F179E.4050704@gmail.com> <55d991ae7a5068ee10a3637b2330b5c4-EhVcX1lJRApWRxoDCzpQCEFddQZLVF5dQUBFCzBYWENGU1kWXlpwH1RcWzBeQ0wAV1leRF5Q-webmailer1@server02.webmailer.hosteurope.de> Message-ID: <4D0F4473.9070703@beyondyourken.com> Thanks, that is exactly what I was looking for. Unfortunately, it is only for /non/-USB keyboards, I may be able to figure something out from there with hotkey or something. On 12/20/2010 3:31 AM, Stefan Sonnenberg-Carstens wrote: > http://pcsupport.about.com/od/tipstricks/ht/makebsodxp.htm > Am Mo, 20.12.2010, 09:45 schrieb mechtheist: >> I am no programmer, but know the rudiments [the rudi'est of rudiments] >> of working with Python. I have a simple need, to have a simple >> script/app I can run that will crash my PC. On my desktops, I can >> always hit the reset, but that is not an option with my laptop. Can >> anyone tell me of an easy way to guarantee a program will instantly >> kill/BSOD my windows7/64bit laptop? >> >> Any help is much appreciated. >> -- >> http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From rob at beyondyourken.com Mon Dec 20 07:15:10 2010 From: rob at beyondyourken.com (rob) Date: Mon, 20 Dec 2010 06:15:10 -0600 Subject: How can I intentionally crash my lappy? In-Reply-To: <4d0f2e69$0$29966$c3e8da3$5496439d@news.astraweb.com> References: <4d0f2e69$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4D0F48CE.8010608@beyondyourken.com> On 12/20/2010 4:22 AM, Steven D'Aprano wrote: > On Mon, 20 Dec 2010 02:45:18 -0600, mechtheist wrote: > >> I am no programmer, but know the rudiments [the rudi'est of rudiments] >> of working with Python. I have a simple need, to have a simple >> script/app I can run that will crash my PC. On my desktops, I can >> always hit the reset, but that is not an option with my laptop. Can >> anyone tell me of an easy way to guarantee a program will instantly >> kill/BSOD my windows7/64bit laptop? >> >> Any help is much appreciated. > You realise that the operating system (yes, even Windows!) is designed to > *not* crash no matter what the application does? > > (The OS may live up to that requirement imperfectly, but still, it tries.) > > > You'll probably find that task easier from C than from Python. But if I > were to attempt such a strange thing, I'd try to shut down some critical > processes used by the OS. I'm not much of a Windows person, but if you > call up the task manager (ctrl-alt-del) and inspect the process list, > then find one that causes the machine to crash if you shut it down, you > can probably do the same thing from a script. Thank you, good approach ideas there. Windows has gotten a lot better about crashing, but it is definitely still way the f 'imperfect'. Now I just have to figure a way to make it imperfecter. From duncan.booth at invalid.invalid Mon Dec 20 07:58:43 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 20 Dec 2010 12:58:43 GMT Subject: True lists in python? References: <4d0dc70d$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: Vito 'ZeD' De Tullio wrote: > Steven D'Aprano wrote: > >> I can't see any way to go from this linked list: >> >> node1 -> node2 -> node3 -> node4 -> node5 -> node6 -> node7 >> >> to this: >> >> node1 -> node6 -> node5 -> node4 -> node3 -> node2 -> node7 >> >> in constant time. You have to touch each of the nodes being reversed. > > very crude example: > No, you just showed how you can reverse an entire list in constant time. The original question and Steven's example were asking to reverse just part of the list. I guess you might be able to do it with a double-linked list provided that when traversing the list you always keep two nodes around to determine the direction. e.g. instead of asking for node6.nextNode() you ask for node6.nextNode(previous=node1) and then the code can return whichever sibling wasn't given. That would make reversal (assuming you have both nodes) O(1), but would make traversing the list slower. Also, I don't think it would help if you wanted to implement John Nagle's algorithm for the travelling salesman problem: you could hold a separate (array based) list of nodes in order to make the random selection O(1), but you wouldn't know which direction to follow from each node when it comes to cutting the list into 3. -- Duncan Booth http://kupuguy.blogspot.com From lists at cheimes.de Mon Dec 20 09:09:58 2010 From: lists at cheimes.de (Christian Heimes) Date: Mon, 20 Dec 2010 15:09:58 +0100 Subject: How can I intentionally crash my lappy? In-Reply-To: <4D0F179E.4050704@gmail.com> References: <4D0F179E.4050704@gmail.com> Message-ID: Am 20.12.2010 09:45, schrieb mechtheist: > I am no programmer, but know the rudiments [the rudi'est of rudiments] > of working with Python. I have a simple need, to have a simple > script/app I can run that will crash my PC. On my desktops, I can > always hit the reset, but that is not an option with my laptop. Can > anyone tell me of an easy way to guarantee a program will instantly > kill/BSOD my windows7/64bit laptop? Do you want to crash it or are you looking for a way to restart Windows? Every modern operating system tries very hard (and successful) to prevent users from messing with the system. You have two choices. Either you ask the OS politely to restart (e.g. shutdown -r -f -t 1) or you need some sort of STONITH device (e.g. IPMI card, watchdog, other node fencing device, multi-plug with network interface). Christian From eric.frederich at gmail.com Mon Dec 20 10:23:02 2010 From: eric.frederich at gmail.com (Eric Frederich) Date: Mon, 20 Dec 2010 10:23:02 -0500 Subject: Creating custom types from C code In-Reply-To: References: Message-ID: Thanks for the reply. I remember reading about named tuples when they were back-ported to the 2.X series but I never played with them. Is there a way to instantiate a named tuple from C code? Maybe I'm over-thinking this whole thing. Is there a simple way that I can define a class in Python and instantiate that type from C? On Sat, Dec 18, 2010 at 1:18 AM, Stefan Behnel wrote: > Eric Frederich, 17.12.2010 23:58: >> >> I have an extension module for a 3rd party library in which I am >> wrapping some structures. >> My initial attempt worked okay on Windows but failed on Linux. >> I was doing it in two parts. >> The first part on the C side of things I was turning the entire >> structure into a char array. >> The second part in Python code I would unpack the structure. >> >> Anyway, I decided I should be doing things a little cleaner so I read >> up on "Defining New Types" >> http://docs.python.org/extending/newtypes.html >> >> I got it to work but I'm not sure how to create these new objects from C. > > You may want to take a look at Cython. It makes writing C extensions easy. > For one, it will do all sorts of type conversions for you, and do them > efficiently and safely (you get an exception on overflow, for example). It's > basically Python, so creating classes and instantiating them is trivial. > > Also note that it's generally not too much work to rewrite an existing C > wrapper in Cython, but it's almost always worth it. You immediately get more > maintainable code that's much easier to extend and work on. It's also often > faster than hand written code. > > http://cython.org > > >> My setup is almost exactly like the example on that page except >> instead of 2 strings and an integer I have 5 unsigned ints. >> >> I do not expect to ever be creating these objects in Python. ?They >> will only be created as return values from my wrapper functions to the >> 3rd party library. > > In Cython 0.14, you can declare classes as "final" and "internal" using a > decorator, meaning that they cannot be subtyped from Python and do not show > up in the module dict. However, note that there is no way to prevent users > from getting their hands at the type once you give them an instance. > > >> I could return a tuple from those functions but I want to use dot >> notation (e.g. somestruct.var1). > > Then __getattr__ or properties are your friend. > > >> So, question number 1: >> ? ? Is defining my own type like that overkill just to have an object >> to access using dots? > > Creating wrapper objects is totally normal. > > Also note that recent Python versions have named tuples, BTW. > > >> ? ? I'll never create those objects from Python. >> ? ? Is there a shortcut to creating objects and setting attributes >> from within C? > > The Cython code for instantiating classes is identical to Python. > > >> In any case, I was able to create my own custom object from C code like >> so... >> >> ? ? PyObject *foo(SomeCStruct bar){ >> ? ? ? ? PyObject *ret; >> ? ? ? ? ret = _PyObject_New(&mymodule_SomeStructType); >> ? ? ? ? PyObject_SetAttrString(ret, "var1" , Py_BuildValue("I", bar.var1 >> )); >> ? ? ? ? PyObject_SetAttrString(ret, "var2" , Py_BuildValue("I", bar.var2 >> )); >> ? ? ? ? PyObject_SetAttrString(ret, "var3" , Py_BuildValue("I", bar.var3 >> )); >> ? ? ? ? PyObject_SetAttrString(ret, "var4" , Py_BuildValue("I", bar.var4 >> )); >> ? ? ? ? PyObject_SetAttrString(ret, "var5" , Py_BuildValue("I", bar.var5 >> )); >> ? ? ? ? return ret; >> ? ? } >> >> When using _PyObject_New I notice that neither my new or init function >> are ever called. >> I verified that they are getting called when creating the object from >> Python > > Things often work a little different in Python and C. Directly calling > _PyObject_New() is a lot less than what Python does internally. The > canonical way is to PyObject_Call() the type (or to use one of the other > call functions, depending on what your arguments are). > > >> (which I would never do anyway). > > Your users could do it, though, so you should make sure that won't crash the > interpreter that way by leaving internal data fields uninitialised. > > >> Question number 2: >> ? ? Do I need to be calling PyObject_SetAttrString or is there a way >> to set the unsigned ints on the structure direcly? >> ? ? It seems overkill to create a Python object for an unsigned int >> just to set it as an attribute on a custom defined type. > > You will have to do it at some point, though, either at instantiation time > or at Python access time. Depending on the expected usage, either of the two > can be more wasteful. > > >> Question number 3: >> ? ? In the above code, is there a memory leak? ?Should I be >> Py_DECREF'ing the return value from Py_BuildValue after I'm done using >> it. > > You can look that up in the C-API docs. If a function doesn't say that it > "steals" a reference, you still own the reference when it returns and have > to manually decref it (again, a thing that you won't usually have to care > about in Cython). So, yes, the above leaks one reference for each call to > Py_BuildValue(). > > Stefan > > -- > http://mail.python.org/mailman/listinfo/python-list > From stefan_ml at behnel.de Mon Dec 20 11:44:27 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 20 Dec 2010 17:44:27 +0100 Subject: Creating custom types from C code Message-ID: Eric Frederich, 20.12.2010 16:23: > I remember reading about named tuples when they were back-ported to the > 2.X series but I never played with them. Is there a way to instantiate a > named tuple from C code? There isn't a dedicated C-API for named tuples, but you can instantiate any Python type from C code. > Maybe I'm over-thinking this whole thing. Is there a simple way that I > can define a class in Python and instantiate that type from C? Sure, see my previous comments to your original mail. Stefan From lewisr2 at verizon.net Mon Dec 20 12:10:10 2010 From: lewisr2 at verizon.net (lewisr2 at verizon.net) Date: Mon, 20 Dec 2010 11:10:10 -0600 (CST) Subject: Questions Message-ID: <31346077.1045081.1292865010237.JavaMail.root@vznit170128> An HTML attachment was scrubbed... URL: From givenrandy at gmail.com Mon Dec 20 12:33:08 2010 From: givenrandy at gmail.com (Randy Given) Date: Mon, 20 Dec 2010 12:33:08 -0500 Subject: Python-list Digest, Vol 87, Issue 122 In-Reply-To: References: Message-ID: ZS On Dec 19, 2010 6:05 AM, wrote: > Send Python-list mailing list submissions to > python-list at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.python.org/mailman/listinfo/python-list > or, via email, send a message with subject or body 'help' to > python-list-request at python.org > > You can reach the person managing the list at > python-list-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Python-list digest..." -------------- next part -------------- An HTML attachment was scrubbed... URL: From givenrandy at gmail.com Mon Dec 20 12:33:15 2010 From: givenrandy at gmail.com (Randy Given) Date: Mon, 20 Dec 2010 12:33:15 -0500 Subject: Python-list Digest, Vol 87, Issue 122 In-Reply-To: References: Message-ID: as On Dec 19, 2010 6:05 AM, wrote: > Send Python-list mailing list submissions to > python-list at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.python.org/mailman/listinfo/python-list > or, via email, send a message with subject or body 'help' to > python-list-request at python.org > > You can reach the person managing the list at > python-list-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Python-list digest..." -------------- next part -------------- An HTML attachment was scrubbed... URL: From mpnordland at gmail.com Mon Dec 20 12:54:21 2010 From: mpnordland at gmail.com (mpnordland) Date: Mon, 20 Dec 2010 09:54:21 -0800 (PST) Subject: Catching user switching and getting current active user from root on linux In-Reply-To: Message-ID: <3d190cbf-be7d-4973-b85f-c030bb258742@glegroupsg2000goo.googlegroups.com> I give up, I will never try to use a usenet group again. For the ones of you who tried to help thank you. You helped to identify some of my troubles, as for you @usernet, you are a troll From mrjean1 at gmail.com Mon Dec 20 12:58:56 2010 From: mrjean1 at gmail.com (MrJean1) Date: Mon, 20 Dec 2010 09:58:56 -0800 (PST) Subject: how to measure TCP congestion windows using python ?? References: Message-ID: <2909f9a2-fb78-45d6-845f-5d93f342125e@g25g2000yqn.googlegroups.com> FWIW, on CentOS 4.7, the ctypes version works fine, but the struct version fails, because len(tcp_info) is only 100 bytes while struct.calcsize('B...L') is 104. However, if the format is changed to '7B23L', i.e. one 'L' shorter, the struct version works and returns to same result as the ctypes version. /Jean On Dec 19, 4:45?pm, plz wrote: > hi > many thanks for helping me > i also tried to manipulate it last night > here is my code... > > import socket > import struct > > sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM) > tcp_info = sock.getsockopt(socket.SOL_TCP, socket.TCP_INFO, struct.calcsize('BBBBBBBLLLLLLLLLLLLLLLLLLLLLLLL')) > print struct.unpack('BBBBBBBLLLLLLLLLLLLLLLLLLLLLLLL', tcp_info) > > the result of struct.unpack of tcp_info is following > in /usr/include/linux/tcp.h > used Linux Redhat and Python 2.7 > > anyway your code is very useful > Thxs again ;) From anurag.chourasia at gmail.com Mon Dec 20 13:31:44 2010 From: anurag.chourasia at gmail.com (Anurag Chourasia) Date: Tue, 21 Dec 2010 00:01:44 +0530 Subject: **** httplib.InvalidURL: nonnumeric port **** Message-ID: All, When i try to open a URL of the form http://joule:8041/DteEnLinea/ws/EnvioGuia.jws, I am getting an error as below complaining for some non-numeric port. wm (wmosds) [zibal] - /u01/home/apli/wm/app/gdd :>python Python 2.4.1 (#2, May 30 2005, 09:40:30) [C] on aix5 Type "help", "copyright", "credits" or "license" for more information. >>> import httplib, mimetypes >>> h = httplib.HTTP('http://joule:8041/DteEnLinea/ws/EnvioGuia.jws') Traceback (most recent call last): File "", line 1, in ? File "/u01/home/apli/wm/python241/lib/python2.4/httplib.py", line 1093, in __init__ self._setup(self._connection_class(host, port, strict)) File "/u01/home/apli/wm/python241/lib/python2.4/httplib.py", line 582, in __init__ self._set_hostport(host, port) File "/u01/home/apli/wm/python241/lib/python2.4/httplib.py", line 594, in _set_hostport raise InvalidURL("nonnumeric port: '%s'" % host[i+1:]) httplib.InvalidURL: nonnumeric port: '8041/DteEnLinea/ws/EnvioGuia.jws' How could we avoid this problem? Regards, Anurag -------------- next part -------------- An HTML attachment was scrubbed... URL: From anurag.chourasia at gmail.com Mon Dec 20 13:58:52 2010 From: anurag.chourasia at gmail.com (Anurag Chourasia) Date: Tue, 21 Dec 2010 00:28:52 +0530 Subject: Sending XML to a WEB Service and Getting Response Back Message-ID: Dear Python Mates, I have a requirement to send a XML Data to a WEB Service whose URL is of the form http://joule:8041/DteEnLinea/ws/EnvioGuia.jws I also have to read back the response returned as a result of sending this data to this WebService. This web service implements the following operations: sendNCR This web service has no callbacks. I have pasted the complete WSDL for this WEB Service below my email. I would appreciate if someone could guide me with sample code using a Python Library suitable to fulfill this requirement of mine. Regards, Anurag -------------- next part -------------- An HTML attachment was scrubbed... URL: From kevin.p.dwyer at gmail.com Mon Dec 20 14:12:41 2010 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Mon, 20 Dec 2010 19:12:41 +0000 (UTC) Subject: **** httplib.InvalidURL: nonnumeric port **** References: Message-ID: On Tue, 21 Dec 2010 00:01:44 +0530, Anurag Chourasia wrote: >>> import httplib >>> help(httplib.HTTP) Help on class HTTP in module httplib: class HTTP | Compatibility class with httplib.py from 1.5. | | Methods defined here: | | __init__(self, host='', port=None, strict=None) The constructor doesn't take a complete URL as an argument. Also, shouldn't you be using httplib.HTTPConnection? The docs state that httplib.HTTP is for backward compatibility only. Kev From tyler at tysdomain.com Mon Dec 20 14:14:12 2010 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Mon, 20 Dec 2010 12:14:12 -0700 Subject: help with link parsing? Message-ID: <4D0FAB04.6010307@tysdomain.com> Hello all, I have a question. I guess this worked pre 2.6; I don't remember the last time I used it, but it was a while ago, and now it's failing. Anyone mind looking at it and telling me what's going wrong? Also, is there a quick way to match on a certain site? like links from google.com and only output those? #!/usr/bin/env python #This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published #by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. #This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. # #You should have received a copy of the GNU General Public License along with this program. If not, see #http://www.gnu.org/licenses/. """ This script will parse out all the links in an html document and write them to a textfile. """ import sys,optparse import htmllib,formatter #program class declarations: class Links(htmllib.HTMLParser): def __init__(self,formatter): htmllib.HTMLParser.__init__(self, formatter) self.links=[] def start_a(self, attrs): if (len(attrs)>0): for a in attrs: if a[0]=="href": self.links.append(a[1]) print a[1] break def main(argv): if (len(argv)!=3): print("Error:\n"+argv[0]+" .\nParses for all links and saves them to .") return 1 lcount=0 format=formatter.NullFormatter() html=Links(format) print "Retrieving data:" page=open(argv[1],"r") print "Feeding data to parser:" html.feed(page.read()) page.close() print "Writing links:" output=open(argv[2],"w") for i in (html.links): output.write(i+"\n") lcount+=1 output.close() print("Wrote "+str(lcount)+" links to "+argv[2]+"."); print("done.") if (__name__ == "__main__"): #we call the main function passing a list of args, and exit with the return code passed back. sys.exit(main(sys.argv)) -- Thanks, Ty From anurag.chourasia at gmail.com Mon Dec 20 14:30:36 2010 From: anurag.chourasia at gmail.com (Anurag Chourasia) Date: Tue, 21 Dec 2010 01:00:36 +0530 Subject: **** httplib.InvalidURL: nonnumeric port **** In-Reply-To: References: Message-ID: Hi Kevin, Thanks for the response. I tried with HTTPConnection but the same problem. >>> h1 = httplib.HTTPConnection(' http://joule:8041/DteEnLinea/ws/EnvioGuia.jws') Traceback (most recent call last): File "", line 1, in ? File "/u01/home/apli/wm/python241/lib/python2.4/httplib.py", line 582, in __init__ self._set_hostport(host, port) File "/u01/home/apli/wm/python241/lib/python2.4/httplib.py", line 594, in _set_hostport raise InvalidURL("nonnumeric port: '%s'" % host[i+1:]) httplib.InvalidURL: nonnumeric port: '8041/DteEnLinea/ws/EnvioGuia.jws' Do i need to use some other library to be able to send XML Data (and get a response back) to this Kind of Web Service address i.e. http://joule:8041/DteEnLinea/ws/EnvioGuia.jws ? Regards, Anurag On Tue, Dec 21, 2010 at 12:42 AM, Kev Dwyer wrote: > On Tue, 21 Dec 2010 00:01:44 +0530, Anurag Chourasia wrote: > > >>> import httplib > >>> help(httplib.HTTP) > Help on class HTTP in module httplib: > > class HTTP > | Compatibility class with httplib.py from 1.5. > | > | Methods defined here: > | > | __init__(self, host='', port=None, strict=None) > > The constructor doesn't take a complete URL as an argument. > > Also, shouldn't you be using httplib.HTTPConnection? The docs > state that httplib.HTTP is for backward compatibility only. > > Kev > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ashish.makani at gmail.com Mon Dec 20 14:34:14 2010 From: ashish.makani at gmail.com (spaceman-spiff) Date: Mon, 20 Dec 2010 11:34:14 -0800 (PST) Subject: Trying to parse a HUGE(1gb) xml file Message-ID: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> Hi c.l.p folks This is a rather long post, but i wanted to include all the details & everything i have tried so far myself, so please bear with me & read the entire boringly long post. I am trying to parse a ginormous ( ~ 1gb) xml file. 0. I am a python & xml n00b, s& have been relying on the excellent beginner book DIP(Dive_Into_Python3 by MP(Mark Pilgrim).... Mark , if u are readng this, you are AWESOME & so is your witty & humorous writing style) 1. Almost all exmaples pf parsing xml in python, i have seen, start off with these 4 lines of code. import xml.etree.ElementTree as etree tree = etree.parse('*path_to_ginormous_xml*') root = tree.getroot() #my huge xml has 1 root at the top level print root 2. In the 2nd line of code above, as Mark explains in DIP, the parse function builds & returns a tree object, in-memory(RAM), which represents the entire document. I tried this code, which works fine for a small ( ~ 1MB), but when i run this simple 4 line py code in a terminal for my HUGE target file (1GB), nothing happens. In a separate terminal, i run the top command, & i can see a python process, with memory (the VIRT column) increasing from 100MB , all the way upto 2100MB. I am guessing, as this happens (over the course of 20-30 mins), the tree representing is being slowly built in memory, but even after 30-40 mins, nothing happens. I dont get an error, seg fault or out_of_memory exception. My hardware setup : I have a win7 pro box with 8gb of RAM & intel core2 quad cpuq9400. On this i am running sun virtualbox(3.2.12), with ubuntu 10.10 as guest os, with 23gb disk space & 2gb(2048mb) ram, assigned to the guest ubuntu os. 3. I also tried using lxml, but an lxml tree is much more expensive, as it retains more info about a node's context, including references to it's parent. [http://www.ibm.com/developerworks/xml/library/x-hiperfparse/] When i ran the same 4line code above, but with lxml's elementree ( using the import below in line1of the code above) import lxml.etree as lxml_etree i can see the memory consumption of the python process(which is running the code) shoot upto ~ 2700mb & then, python(or the os ?) kills the process as it nears the total system memory(2gb) I ran the code from 1 terminal window (screenshot :http://imgur.com/ozLkB.png) & ran top from another terminal (http://imgur.com/HAoHA.png) 4. I then investigated some streaming libraries, but am confused - there is SAX[http://en.wikipedia.org/wiki/Simple_API_for_XML] , the iterparse interface[http://effbot.org/zone/element-iterparse.htm] Which one is the best for my situation ? Any & all code_snippets/wisdom/thoughts/ideas/suggestions/feedback/comments/ of the c.l.p community would be greatly appreciated. Plz feel free to email me directly too. thanks a ton cheers ashish email : ashish.makani domain:gmail.com p.s. Other useful links on xml parsing in python 0. http://diveintopython3.org/xml.html 1. http://stackoverflow.com/questions/1513592/python-is-there-an-xml-parser-implemented-as-a-generator 2. http://codespeak.net/lxml/tutorial.html 3. https://groups.google.com/forum/?hl=en&lnk=gst&q=parsing+a+huge+xml#!topic/comp.lang.python/CMgToEnjZBk 4. http://www.ibm.com/developerworks/xml/library/x-hiperfparse/ 5.http://effbot.org/zone/element-index.htm http://effbot.org/zone/element-iterparse.htm 6. SAX : http://en.wikipedia.org/wiki/Simple_API_for_XML From tjreedy at udel.edu Mon Dec 20 14:40:22 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 20 Dec 2010 14:40:22 -0500 Subject: Questions In-Reply-To: <31346077.1045081.1292865010237.JavaMail.root@vznit170128> References: <31346077.1045081.1292865010237.JavaMail.root@vznit170128> Message-ID: On 12/20/2010 12:10 PM, lewisr2 at verizon.net wrote: > 3. I have used Tk in the past with Tcl and IncrTcl. Where can I find a > lot of Python/Tk examples so that I can save some time in developing GUIs? Do a search, or possibly a google codesearch, on tkinter or Tkinter, which is Python's tk inter(face). In fact, search the archive of python-list (or gmane's mirror) for posted examples. -- Terry Jan Reedy From clp2 at rebertia.com Mon Dec 20 14:45:45 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 20 Dec 2010 11:45:45 -0800 Subject: **** httplib.InvalidURL: nonnumeric port **** In-Reply-To: References: Message-ID: > On Tue, Dec 21, 2010 at 12:42 AM, Kev Dwyer wrote: >> On Tue, 21 Dec 2010 00:01:44 +0530, Anurag Chourasia wrote: >> >>> import httplib >> >>> help(httplib.HTTP) >> Help on class HTTP in module httplib: >> >> class HTTP >> ?| ?Compatibility class with httplib.py from 1.5. >> ?| >> ?| ?Methods defined here: >> ?| >> ?| ?__init__(self, host='', port=None, strict=None) >> >> The constructor doesn't take a complete URL as an argument. >> >> Also, shouldn't you be using httplib.HTTPConnection? ?The docs >> ?state that httplib.HTTP is for backward compatibility only. >> On Mon, Dec 20, 2010 at 11:30 AM, Anurag Chourasia wrote: > Hi Kevin, > Thanks for the response. > I tried with?HTTPConnection but the same problem. >>>> h1 = >>>> httplib.HTTPConnection('http://joule:8041/DteEnLinea/ws/EnvioGuia.jws') > Traceback (most recent call last): > ??File "", line 1, in ? > ??File "/u01/home/apli/wm/python241/lib/python2.4/httplib.py", line 582, in > __init__ > ?? ?self._set_hostport(host, port) > ??File "/u01/home/apli/wm/python241/lib/python2.4/httplib.py", line 594, in > _set_hostport > ?? ?raise InvalidURL("nonnumeric port: '%s'" % host[i+1:]) > httplib.InvalidURL: nonnumeric port: '8041/DteEnLinea/ws/EnvioGuia.jws' > Do i need to use some other library to be able to send XML Data (and get a > response back) to this Kind of Web Service address > i.e.?http://joule:8041/DteEnLinea/ws/EnvioGuia.jws?? > Regards, > Anurag (1) Please avoid top-posting (2) Did you read the other part of Kev's comment? "The constructor doesn't take a complete URL as an argument." You must pass only the domain to the constructor and then call .request() on the HTTPConnection object. (3) If you're using SOAP, try https://fedorahosted.org/suds/ Cheers, Chris -- http://blog.rebertia.com From awilliam at whitemice.org Mon Dec 20 14:49:46 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Mon, 20 Dec 2010 14:49:46 -0500 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> Message-ID: <1292874586.11975.8.camel@linux-yu4c.site> On Mon, 2010-12-20 at 11:34 -0800, spaceman-spiff wrote: > Hi c.l.p folks > This is a rather long post, but i wanted to include all the details & > everything i have tried so far myself, so please bear with me & read > the entire boringly long post. > I am trying to parse a ginormous ( ~ 1gb) xml file. Do that hundreds of times a day. > 0. I am a python & xml n00b, s& have been relying on the excellent > beginner book DIP(Dive_Into_Python3 by MP(Mark Pilgrim).... Mark , if > u are readng this, you are AWESOME & so is your witty & humorous > writing style) > 1. Almost all exmaples pf parsing xml in python, i have seen, start off with these 4 lines of code. > import xml.etree.ElementTree as etree > tree = etree.parse('*path_to_ginormous_xml*') > root = tree.getroot() #my huge xml has 1 root at the top level > print root Yes, this is a terrible technique; most examples are crap. > 2. In the 2nd line of code above, as Mark explains in DIP, the parse > function builds & returns a tree object, in-memory(RAM), which > represents the entire document. > I tried this code, which works fine for a small ( ~ 1MB), but when i > run this simple 4 line py code in a terminal for my HUGE target file > (1GB), nothing happens. > In a separate terminal, i run the top command, & i can see a python > process, with memory (the VIRT column) increasing from 100MB , all the > way upto 2100MB. Yes, this is using DOM. DOM is evil and the enemy, full-stop. > I am guessing, as this happens (over the course of 20-30 mins), the > tree representing is being slowly built in memory, but even after > 30-40 mins, nothing happens. > I dont get an error, seg fault or out_of_memory exception. You need to process the document as a stream of elements; aka SAX. > 3. I also tried using lxml, but an lxml tree is much more expensive, > as it retains more info about a node's context, including references > to it's parent. > [http://www.ibm.com/developerworks/xml/library/x-hiperfparse/] > When i ran the same 4line code above, but with lxml's elementree > ( using the import below in line1of the code above) > import lxml.etree as lxml_etree You're still using DOM; DOM is evil. > Which one is the best for my situation ? > Any & all > code_snippets/wisdom/thoughts/ideas/suggestions/feedback/comments/ of > the c.l.p community would be greatly appreciated. > Plz feel free to email me directly too. From clp2 at rebertia.com Mon Dec 20 14:52:30 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 20 Dec 2010 11:52:30 -0800 Subject: help with link parsing? In-Reply-To: <4D0FAB04.6010307@tysdomain.com> References: <4D0FAB04.6010307@tysdomain.com> Message-ID: On Mon, Dec 20, 2010 at 11:14 AM, Littlefield, Tyler wrote: > Hello all, > I have a question. I guess this worked pre 2.6; I don't remember the last > time I used it, but it was a while ago, and now it's failing. Anyone mind > looking at it and telling me what's going wrong? Please describe /exactly/ how it is failing for you, including the full exception traceback (if any). The script seems to work fine for me under both Python v2.6.6 and v2.7.1. Cheers, Chris -- http://blog.rebertia.com From kevin.p.dwyer at gmail.com Mon Dec 20 14:54:06 2010 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Mon, 20 Dec 2010 19:54:06 +0000 (UTC) Subject: **** httplib.InvalidURL: nonnumeric port **** References: Message-ID: On Tue, 21 Dec 2010 01:00:36 +0530, Anurag Chourasia wrote: Anurag, HTTPConnection takes a host and a port number as arguments, not just a URL. So you could construct your connection request like this: conn = httplib.HTTPConnection('joule', 8041) then use the request() method on the connection to make a PUT or GET request: conn.request('PUT', url, body, headers) Please read the documentation for the httplib module, and perhaps some basic material on how HTTP requests work. Cheers, Kev From usernet at ilthio.net Mon Dec 20 15:09:01 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 20 Dec 2010 20:09:01 +0000 (UTC) Subject: Trying to parse a HUGE(1gb) xml file References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> Message-ID: [Wrapped to meet RFC1855 Netiquette Guidelines] On 2010-12-20, spaceman-spiff wrote: > This is a rather long post, but i wanted to include all the details & > everything i have tried so far myself, so please bear with me & read > the entire boringly long post. > > I am trying to parse a ginormous ( ~ 1gb) xml file. [SNIP] > 4. I then investigated some streaming libraries, but am confused - there > is SAX[http://en.wikipedia.org/wiki/Simple_API_for_XML] , the iterparse > interface[http://effbot.org/zone/element-iterparse.htm] I have made extensive use of SAX and it will certainly work for low memory parsing of XML. I have never used "iterparse"; so, I cannot make an informed comparison between them. > Which one is the best for my situation ? Your posed was long but it failed to tell us the most important piece of information: What does your data look like and what are you trying to do with it? SAX is a low level API that provides a callback interface allowing you to processes various elements as they are encountered. You can therefore do anything you want to the information, as you encounter it, including outputing and discarding small chunks as you processes it; ignoring most of it and saving only what you want to memory data structures; or saving all of it to a more random access database or on disk data structure that you can load and process as required. What you need to do will depend on what you are actually trying to accomplish. Without knowing that, I can only affirm that SAX will work for your needs without providing any information about how you should be using it. From hidura at gmail.com Mon Dec 20 15:14:47 2010 From: hidura at gmail.com (Hidura) Date: Mon, 20 Dec 2010 16:14:47 -0400 Subject: Sending XML to a WEB Service and Getting Response Back In-Reply-To: References: Message-ID: I recommend you use the urllib.request in the library of python says everything that you want to know. 2010/12/20, Anurag Chourasia : > Dear Python Mates, > > I have a requirement to send a XML Data to a WEB Service whose URL is of the > form http://joule:8041/DteEnLinea/ws/EnvioGuia.jws > > I also have to read back the response returned as a result of sending this > data to this WebService. > > This web service implements the following operations: > sendNCR > > This web service has no callbacks. > > I have pasted the complete WSDL for this WEB Service below my email. > > I would appreciate if someone could guide me with sample code using a Python > Library suitable to fulfill this requirement of mine. > > Regards, > Anurag > > > > xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc=" > http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl=" > http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://www.openuri.org/"> > > elementFormDefault="qualified" targetNamespace="http://www.openuri.org/"> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > style="document"/> > > style="document"/> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- Enviado desde mi dispositivo m?vil Diego I. Hidalgo D. From ashish.makani at gmail.com Mon Dec 20 15:29:01 2010 From: ashish.makani at gmail.com (spaceman-spiff) Date: Mon, 20 Dec 2010 12:29:01 -0800 (PST) Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: Message-ID: Hi Usernet First up, thanks for your prompt reply. I will make sure i read RFC1855, before posting again, but right now chasing a hard deadline :) I am sorry i left out what exactly i am trying to do. 0. Goal :I am looking for a specific element..there are several 10s/100s occurrences of that element in the 1gb xml file. The contents of the xml, is just a dump of config parameters from a packet switch( although imho, the contents of the xml dont matter) I need to detect them & then for each 1, i need to copy all the content b/w the element's start & end tags & create a smaller xml file. 1. Can you point me to some examples/samples of using SAX, especially , ones dealing with really large XML files. 2.This brings me to another q. which i forgot to ask in my OP(original post). Is simply opening the file, & using reg ex to look for the element i need, a *good* approach ? While researching my problem, some article seemed to advise against this, especially since its known apriori, that the file is an xml & since regex code gets complicated very quickly & is not very readable. But is that just a "style"/"elegance" issue, & for my particular problem (detecting a certain element, & then creating(writing) a smaller xml file corresponding to, each pair of start & end tags of said element), is the open file & regex approach, something you would recommend ? Thanks again for your super-prompt response :) cheers ashish From awilliam at whitemice.org Mon Dec 20 15:33:45 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Mon, 20 Dec 2010 15:33:45 -0500 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: Message-ID: <1292877225.13462.8.camel@linux-yu4c.site> On Mon, 2010-12-20 at 12:29 -0800, spaceman-spiff wrote: > I need to detect them & then for each 1, i need to copy all the > content b/w the element's start & end tags & create a smaller xml > file. Yep, do that a lot; via iterparse. > 1. Can you point me to some examples/samples of using SAX, > especially , ones dealing with really large XML files. SaX is equivalent to iterparse (iterpase is a way, to essentially, do SaX-like processing). I provided an iterparse example already. See the Read_Rows method in > 2.This brings me to another q. which i forgot to ask in my OP(original post). > Is simply opening the file, & using reg ex to look for the element i need, a *good* approach ? No. From Martin at Hvidberg.net Mon Dec 20 16:08:20 2010 From: Martin at Hvidberg.net (Martin Hvidberg) Date: Mon, 20 Dec 2010 22:08:20 +0100 Subject: Why do my list go uni-code by itself? Message-ID: <4D0FC5C4.3060008@Hvidberg.net> I'm reading a fixed format text file, line by line. I hereunder present the code. I have out part not related to the file reading. Only relevant detail left out is the lstCutters. It looks like this: [[1, 9], [11, 21], [23, 48], [50, 59], [61, 96], [98, 123], [125, 150]] It specifies the first and last character position of each token in the fixed format of the input line. All this works fine, and is only to explain where I'm going. The code, in the function definition, is broken up in more lines than necessary, to be able to monitor the variables, step by step. --- Code start ------ import codecs def CutLine2List(strIn,lstCut): strIn = strIn.strip() print '>InNextLine>',strIn # skip if line is empty if len(strIn)<1: return False lstIn = list() for cc in lstCut: strSubline =strIn[cc[0]-1:cc[1]-1].strip() lstIn.append(strSubline) print '>InSubline2>'+lstIn[len(lstIn)-1]+'<' del strIn, lstCut,cc print '>InReturLst>',lstIn return lstIn filIn = codecs.open( strFileNameIn, mode='r', encoding='utf-8', errors='strict', buffering=1) for linIn in filIn: lstIn = CutLine2List(linIn,lstCutters) --- Code end ------ A sample output, representing one line from the input file looks like this: >InNextLine> I 30 2002-12-11 20:01:19.280 563 FAN? 2001-12-12-15.46.12.734502 2001-12-12-15.46.12.734502 >InSubline2>I< >InSubline2>30< >InSubline2>2002-12-11 20:01:19.280< >InSubline2>563< >InSubline2>FAN?< >InSubline2>2001-12-12-15.46.12.73450< >InSubline2>2001-12-12-15.46.12.73450< >InReturLst> [u'I', u'30', u'2002-12-11 20:01:19.280', u'563', u'FAN\xd8', u'2001-12-12-15.46.12.73450', u'2001-12-12-15.46.12.73450'] Question: In the last printout, tagged >InReturLst> all entries turn into uni-code. What happens here? Look for the word 'FAN?'. This word changes from 'FAN?' to u'FAN\xd8' -- That's a problem to me, and I don't want it to change like this. What do I do to stop this behavior? Best Regards Martin -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Mon Dec 20 16:30:20 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 20 Dec 2010 16:30:20 -0500 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: <1292874586.11975.8.camel@linux-yu4c.site> References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <1292874586.11975.8.camel@linux-yu4c.site> Message-ID: On 12/20/2010 2:49 PM, Adam Tauno Williams wrote: > > Yes, this is a terrible technique; most examples are crap. > Yes, this is using DOM. DOM is evil and the enemy, full-stop. > You're still using DOM; DOM is evil. For serial processing, DOM is superfluous superstructure. For random access processing, some might disagree. > >> Which one is the best for my situation ? >> Any& all >> code_snippets/wisdom/thoughts/ideas/suggestions/feedback/comments/ of >> the c.l.p community would be greatly appreciated. >> Plz feel free to email me directly too. > > > > For Python (unlike Java), wrapping module functions as class static methods is superfluous superstructure that only slows things down. raise Exception(...) # should be something specific like raise ValueError(...) -- Terry Jan Reedy From usernet at ilthio.net Mon Dec 20 16:37:48 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 20 Dec 2010 21:37:48 +0000 (UTC) Subject: Trying to parse a HUGE(1gb) xml file References: Message-ID: On 2010-12-20, spaceman-spiff wrote: > 0. Goal :I am looking for a specific element..there are several 10s/100s > occurrences of that element in the 1gb xml file. The contents of the xml, > is just a dump of config parameters from a packet switch( although imho, > the contents of the xml dont matter) Then you need: 1. To detect whenever you move inside of the type element you are seeking and whenever you move out of it. As long as these elements cannot be nested inside of each other, this is an easy binary task. If they can be nested, then you will need to maintain some kind of level count or recursively decompose each level. 2. Once you have obtained a complete element (from its start tag to its end tag) you will need to test whether you have the single correct element that you are looking for. Something like this (untested) will work if the target tag cannot be nested in another target tag: - import xml.sax - class tagSearcher(xml.sax.ContentHandler): - - def startDocument(): - self.inTarget = False - - def startElement(name, attrs): - if name == targetName: - self.inTarget = True - elif inTarget = True: - # save element information - - def endElement(name): - if name == targetName: - self.inTarget = False - # test the saved information to see if you have the - # one you want: - # - # if its the peice you are looking for, then - # you can process the information - # you have saved - # - # if not, disgard the accumulated - # information and move on - - def characters(content): - if self.inTarget == True: - # save the content - - yourHandler = tagSearcher() - yourParser = xml.sax.make_parser() - yourParser.parse(inputXML, yourHandler) Then you just walk through the document picking up and discarding each target element type until you have the one that you are looking for. > I need to detect them & then for each 1, i need to copy all the content > b/w the element's start & end tags & create a smaller xml file. Easy enough; but, with SAX you will have to recreate the tags from the information that they contain because they will be skipped by the character() events; so you will need to save the information from each tag as you come across it. This could probably be done more automatically using saxutils.XMLGenerator; but, I haven't actually worked with it before. xml.dom.pulldom also looks interesting > 1. Can you point me to some examples/samples of using SAX, especially , > ones dealing with really large XML files. There is nothing special about large files with SAX. Sax is very simple. It walks through the document and calls the the functions that you give it for each event as it reaches varius elements. Your callback functions (methods of a handler) do everthing with the information. SAX does nothing more then call your functions. There are events for reaching a starting tag, an end tag, and characters between tags; as well as some for beginning and ending a document. > 2.This brings me to another q. which i forgot to ask in my OP(original > post). Is simply opening the file, & using reg ex to look for the element > i need, a *good* approach ? While researching my problem, some article > seemed to advise against this, especially since its known apriori, that > the file is an xml & since regex code gets complicated very quickly & > is not very readable. > > But is that just a "style"/"elegance" issue, & for my particular problem > (detecting a certain element, & then creating(writing) a smaller xml > file corresponding to, each pair of start & end tags of said element), > is the open file & regex approach, something you would recommend ? It isn't an invalid approach if it works for your situatuation. I have used it before for very simple problems. The thing is, XML is a context free data format which makes it difficult to generate precise regular expressions, especially where where tags of the same type can be nested. It can be very error prone. Its really easy to have a regex work for your tests and fail, either by matching too much or failing to match, because you didn't anticipate a given piece of data. I wouldn't consider it a robust solution. From python at mrabarnett.plus.com Mon Dec 20 16:41:10 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 20 Dec 2010 21:41:10 +0000 Subject: Why do my list go uni-code by itself? In-Reply-To: <4D0FC5C4.3060008@Hvidberg.net> References: <4D0FC5C4.3060008@Hvidberg.net> Message-ID: <4D0FCD76.8000703@mrabarnett.plus.com> > I'm reading a fixed format text file, line by line. I hereunder present the code. I have out part not related to the file reading. > Only relevant detail left out is the lstCutters. It looks like this: > [[1, 9], [11, 21], [23, 48], [50, 59], [61, 96], [98, 123], [125, 150]] > It specifies the first and last character position of each token in the fixed format of the input line. > All this works fine, and is only to explain where I'm going. > > The code, in the function definition, is broken up in more lines than necessary, to be able to monitor the variables, step by step. > > --- Code start ------ > > import codecs > > > > def CutLine2List(strIn,lstCut): > strIn = strIn.strip() > print '>InNextLine>',strIn > # skip if line is empty > if len(strIn)<1: > return False More Pythonic would be: if not strIn: > lstIn = list() > for cc in lstCut: > strSubline =strIn[cc[0]-1:cc[1]-1].strip() The start index is inclusive; the end index is exclusive. > lstIn.append(strSubline) > print '>InSubline2>'+lstIn[len(lstIn)-1]+'<' > del strIn, lstCut,cc Not necessary to del the names. They exist only within the function, which you're about to leave. > print '>InReturLst>',lstIn > return lstIn > Sometimes it returns a list and sometimes False. That's a bad idea; try to be consistent. > > > filIn = codecs.open( > strFileNameIn, > mode='r', > encoding='utf-8', > errors='strict', > buffering=1) You're decoding from UTF-8 to Unicode, so all the strings you're working on are Unicode strings. > for linIn in filIn: > lstIn = CutLine2List(linIn,lstCutters) > From ian.g.kelly at gmail.com Mon Dec 20 16:41:36 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 20 Dec 2010 14:41:36 -0700 Subject: Why do my list go uni-code by itself? In-Reply-To: <4D0FC5C4.3060008@Hvidberg.net> References: <4D0FC5C4.3060008@Hvidberg.net> Message-ID: On Mon, Dec 20, 2010 at 2:08 PM, Martin Hvidberg wrote: > Question: > In the last printout, tagged >InReturLst> all entries turn into uni-code. > What happens here? Actually, they were all unicode to begin with. You're using codecs.open to read the file, which transparently decodes the data using the supplied encoding (in this case, utf-8). If you wanted to preserve the original bytes, you would just use the open() function to open the file instead. > Look for the word 'FAN?'. This word changes from 'FAN?' to u'FAN\xd8' ? > That's a problem to me, and I don't want it to change like this. This happens because you're printing a list instead of a unicode string. When you print the unicode string, it tries to print the actual characters. When you print the list, it constructs the repr of the list, which uses the repr of each of the items in the list, and the repr of the unicode string is u'FAN\xd8'. If you don't want this to happen, then you will need to format the list as a string yourself instead of relying on print to do what it thinks you might want. Cheers, Ian From e_d_k at yahoo.com Mon Dec 20 16:56:02 2010 From: e_d_k at yahoo.com (Ed Keith) Date: Mon, 20 Dec 2010 13:56:02 -0800 (PST) Subject: Modifying an existing excel spreadsheet Message-ID: <377109.56809.qm@web120503.mail.ne1.yahoo.com> I have a user supplied 'template' Excel spreadsheet. I need to create a new excel spreadsheet based on the supplied template, with data filled in. I found the tools here http://www.python-excel.org/,? and http://sourceforge.net/projects/pyexcelerator/. I have been trying to use the former, since the latter seems to be devoid of documentation (not even any docstrings). My first thought was to copy the template, open the copy, modify it and save the modifications. But it looks like if I open an existing spreadsheet it must be read only. So I tried to? open the template, copy it to a new spreadsheet and write the new spreadsheet, but I can't seem to copy the images, and it looks like copying the formatting is going to be difficult. Can anyone give me any tips or advice? Thanks in advance, ?? -EdK Ed Keith e_d_k at yahoo.com Blog: edkeith.blogspot.com From davea at ieee.org Mon Dec 20 17:19:29 2010 From: davea at ieee.org (Dave Angel) Date: Mon, 20 Dec 2010 17:19:29 -0500 Subject: Why do my list go uni-code by itself? In-Reply-To: <4D0FC5C4.3060008@Hvidberg.net> References: <4D0FC5C4.3060008@Hvidberg.net> Message-ID: <4D0FD671.1010901@ieee.org> On 01/-10/-28163 02:59 PM, Martin Hvidberg wrote: > I'm reading a fixed format text file, line by line. I hereunder present > the code. I have out part not related to the file reading. > Only relevant detail left out is the lstCutters. It looks like this: > [[1, 9], [11, 21], [23, 48], [50, 59], [61, 96], [98, 123], [125, 150]] > It specifies the first and last character position of each token in the > fixed format of the input line. > All this works fine, and is only to explain where I'm going. > > The code, in the function definition, is broken up in more lines than > necessary, to be able to monitor the variables, step by step. > > --- Code start ------ > > import codecs > > > > def CutLine2List(strIn,lstCut): > strIn = strIn.strip() > print '>InNextLine>',strIn > # skip if line is empty > if len(strIn)<1: > return False > lstIn = list() > for cc in lstCut: > strSubline =strIn[cc[0]-1:cc[1]-1].strip() > lstIn.append(strSubline) > print '>InSubline2>'+lstIn[len(lstIn)-1]+'<' > del strIn, lstCut,cc > print '>InReturLst>',lstIn > return lstIn > > > > filIn = codecs.open( > strFileNameIn, > mode='r', > encoding='utf-8', > errors='strict', > buffering=1) > for linIn in filIn: > lstIn = CutLine2List(linIn,lstCutters) > > --- Code end ------ > > A sample output, representing one line from the input file looks like this: > > >InNextLine> I 30 2002-12-11 20:01:19.280 563 FAN? > 2001-12-12-15.46.12.734502 2001-12-12-15.46.12.734502 > >InSubline2>I< > >InSubline2>30< > >InSubline2>2002-12-11 20:01:19.280< > >InSubline2>563< > >InSubline2>FAN?< > >InSubline2>2001-12-12-15.46.12.73450< > >InSubline2>2001-12-12-15.46.12.73450< > >InReturLst> [u'I', u'30', u'2002-12-11 20:01:19.280', u'563', > u'FAN\xd8', u'2001-12-12-15.46.12.73450', u'2001-12-12-15.46.12.73450'] > > > Question: > In the last printout, tagged >InReturLst> all entries turn into > uni-code. What happens here? > Look for the word 'FAN?'. This word changes from 'FAN?' to u'FAN\xd8' -- > That's a problem to me, and I don't want it to change like this. > > What do I do to stop this behavior? > > Best Regards > Martin > > If you don't want Unicode, why do you specify that the file is encoded as utf-8 ? If it's ASCII, just open the file, without using a utf-8 codec. Of course, then you'll have to fix the input file to make it ASCII. The character in the input file following the letters "FAN" is not a zero, it's some other character, apparently 00D8 in the Unicode table, not 0030. It didn't "change" in the InRturLst line. You were reading Unicode strings from the file. When you print Unicode, it encodes it in whatever your console device specifies. But when you print a "list," it uses repr() on the elements, so you get to see what their real type is. DaveA From ian.g.kelly at gmail.com Mon Dec 20 18:15:34 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 20 Dec 2010 16:15:34 -0700 Subject: Sending XML to a WEB Service and Getting Response Back In-Reply-To: References: Message-ID: On Mon, Dec 20, 2010 at 11:58 AM, Anurag Chourasia wrote: > Dear Python Mates, > I have a requirement to send a XML Data to a WEB Service whose URL is of the > form?http://joule:8041/DteEnLinea/ws/EnvioGuia.jws > I also have to read back the response returned as a result of sending this > data to this WebService. > This web service implements the following operations: > ?? sendNCR > > This web service has no callbacks. > I have pasted the complete WSDL for this WEB Service below my email. > I would appreciate if someone could guide me with sample code using a Python > Library suitable to fulfill this requirement of mine. The ZSI or SOAPpy library should do what you need. From pythonlist.calin79 at spamgourmet.com Mon Dec 20 18:23:16 2010 From: pythonlist.calin79 at spamgourmet.com (pythonlist.calin79 at spamgourmet.com) Date: Mon, 20 Dec 2010 15:23:16 -0800 Subject: Class-override of a sort-key method? Message-ID: Hi all - it would seem that these days, all the cool kids use the sort function's 'key' kwarg in order to sort a list of custom objects quickly. Unfortunately, as opposed to using 'cmp', where you can implent __cmp__ to get 'automatic sorting' in a similar fashion, there doesn't seem to be a direct analogue for a class-overridable method for providing a sort key. (ie, something like '__sortkey__' or '__key__'). Is there one, and I'm just missing it? If not, are there any plans to add one? (I did a quick search of the PEP list, and the only hits for 'sort' I saw had to do with sorting dictionaries by value). - Paul -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Mon Dec 20 19:10:22 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 20 Dec 2010 16:10:22 -0800 Subject: Class-override of a sort-key method? In-Reply-To: References: Message-ID: On Mon, Dec 20, 2010 at 3:23 PM, wrote: > Hi all - it would seem that these days, all the cool kids use the sort > function's 'key' kwarg in order to sort a list of custom objects quickly. Really? They don't bother to define __cmp__ or similar? Sounds lazy and poorly structured. > Unfortunately, as opposed to using 'cmp', where you can implent __cmp__ to > get 'automatic sorting' in a similar fashion, there doesn't seem to be a > direct analogue for a class-overridable method for providing a sort key. > ?(ie, something like '__sortkey__' or '__key__'). Just simply delegate to key comparison in your __cmp__ (or similar) method(s). > Is there one, and I'm just missing it? If not, are there any plans to add > one? (I did a quick search of the PEP list, and the only hits for 'sort' I > saw had to do with sorting dictionaries by value). If you know at class-definiton-time how you want instances to be sorted, then just define __cmp__ (or the rich comparison methods) appropriately, possibly even delegating to a comparison of keys (as the class defines them). For example: from functools import total_ordering @total_ordering class Person(object): def __init__(self, first_name, last_name): self.first_name = first_name self.last_name = last_name @property def _key(self): """Identifying key for a Person, by which they are sorted""" return (self.last_name, self.first_name) def __eq__(self, other): return isinstance(other, Person) and self._key == other._key def __lt__(self, other): return self._key < other._key If you want to abstract even this away, then just write a class decorator; there's no need to add yet another (rather complicated due to all the interactions with the existing comparison methods) special method. Cheers, Chris -- http://blog.rebertia.com From steve at holdenweb.com Mon Dec 20 20:35:54 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 20 Dec 2010 20:35:54 -0500 Subject: Catching user switching and getting current active user from root on linux In-Reply-To: <3d190cbf-be7d-4973-b85f-c030bb258742@glegroupsg2000goo.googlegroups.com> References: <3d190cbf-be7d-4973-b85f-c030bb258742@glegroupsg2000goo.googlegroups.com> Message-ID: <4D10047A.6020207@holdenweb.com> On 12/20/2010 12:54 PM, mpnordland wrote: > I give up, I will never try to use a usenet group again. For the ones > of you who tried to help thank you. You helped to identify some of my > troubles, as for you @usernet, you are a troll Don't give up after one experience. Usenet can be really useful as long as you know who to listen to and who to ignore ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Mon Dec 20 20:35:54 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 20 Dec 2010 20:35:54 -0500 Subject: Catching user switching and getting current active user from root on linux In-Reply-To: <3d190cbf-be7d-4973-b85f-c030bb258742@glegroupsg2000goo.googlegroups.com> References: <3d190cbf-be7d-4973-b85f-c030bb258742@glegroupsg2000goo.googlegroups.com> Message-ID: <4D10047A.6020207@holdenweb.com> On 12/20/2010 12:54 PM, mpnordland wrote: > I give up, I will never try to use a usenet group again. For the ones > of you who tried to help thank you. You helped to identify some of my > troubles, as for you @usernet, you are a troll Don't give up after one experience. Usenet can be really useful as long as you know who to listen to and who to ignore ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From jshgwave at yahoo.com Mon Dec 20 20:36:45 2010 From: jshgwave at yahoo.com (Jshgwave) Date: Mon, 20 Dec 2010 17:36:45 -0800 (PST) Subject: Redundant importing of modules Message-ID: <528680.17833.qm@web84407.mail.ac2.yahoo.com> When writing a function that uses a module such as NumPy, it is tempting to include the statement "import numpy" or "import numpy as np" in the definition of the function, in case the? function is used in a script that hasn't already imported NumPy. That could lead to the script issuing the "import numpy" command more than once. Does Python know to disregard redundant "import" commands? ? -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Mon Dec 20 20:50:28 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 20 Dec 2010 20:50:28 -0500 Subject: Class-override of a sort-key method? In-Reply-To: References: Message-ID: <4D1007E4.6090401@holdenweb.com> On 12/20/2010 7:10 PM, Chris Rebert wrote: > On Mon, Dec 20, 2010 at 3:23 PM, wrote: >> Hi all - it would seem that these days, all the cool kids use the sort >> function's 'key' kwarg in order to sort a list of custom objects quickly. > > Really? They don't bother to define __cmp__ or similar? Sounds lazy > and poorly structured. > That sounds to me like a potentially ill-informed response. >> Unfortunately, as opposed to using 'cmp', where you can implent __cmp__ to >> get 'automatic sorting' in a similar fashion, there doesn't seem to be a >> direct analogue for a class-overridable method for providing a sort key. >> (ie, something like '__sortkey__' or '__key__'). > Why do you talk about "implementing __cmp__"? Why should this be necessary? > Just simply delegate to key comparison in your __cmp__ (or similar) method(s). > Assuming, of course, that you are conveniently sorting only object over which you have complete control ... >> Is there one, and I'm just missing it? If not, are there any plans to add >> one? (I did a quick search of the PEP list, and the only hits for 'sort' I >> saw had to do with sorting dictionaries by value). > > If you know at class-definiton-time how you want instances to be > sorted, then just define __cmp__ (or the rich comparison methods) > appropriately, possibly even delegating to a comparison of keys (as > the class defines them). > > For example: > > from functools import total_ordering > > @total_ordering > class Person(object): > def __init__(self, first_name, last_name): > self.first_name = first_name > self.last_name = last_name > > @property > def _key(self): > """Identifying key for a Person, by which they are sorted""" > return (self.last_name, self.first_name) > > def __eq__(self, other): > return isinstance(other, Person) and self._key == other._key > > def __lt__(self, other): > return self._key < other._key > > If you want to abstract even this away, then just write a class > decorator; there's no need to add yet another (rather complicated due > to all the interactions with the existing comparison methods) special > method. > But the *real* point is (as the documentation attempts to point out) that by providing the key argument it gets called only once per element, whereas the cmp argument (or the objects' __cmp__() method if you insist on letting sort delegate to that) gets called every time two objects have to be compared. If cmp is a Python function (or equivalently if __cmp__() is a Python method) then calling it will take much longer than calling hte built-in default routines. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Mon Dec 20 20:50:28 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 20 Dec 2010 20:50:28 -0500 Subject: Class-override of a sort-key method? In-Reply-To: References: Message-ID: <4D1007E4.6090401@holdenweb.com> On 12/20/2010 7:10 PM, Chris Rebert wrote: > On Mon, Dec 20, 2010 at 3:23 PM, wrote: >> Hi all - it would seem that these days, all the cool kids use the sort >> function's 'key' kwarg in order to sort a list of custom objects quickly. > > Really? They don't bother to define __cmp__ or similar? Sounds lazy > and poorly structured. > That sounds to me like a potentially ill-informed response. >> Unfortunately, as opposed to using 'cmp', where you can implent __cmp__ to >> get 'automatic sorting' in a similar fashion, there doesn't seem to be a >> direct analogue for a class-overridable method for providing a sort key. >> (ie, something like '__sortkey__' or '__key__'). > Why do you talk about "implementing __cmp__"? Why should this be necessary? > Just simply delegate to key comparison in your __cmp__ (or similar) method(s). > Assuming, of course, that you are conveniently sorting only object over which you have complete control ... >> Is there one, and I'm just missing it? If not, are there any plans to add >> one? (I did a quick search of the PEP list, and the only hits for 'sort' I >> saw had to do with sorting dictionaries by value). > > If you know at class-definiton-time how you want instances to be > sorted, then just define __cmp__ (or the rich comparison methods) > appropriately, possibly even delegating to a comparison of keys (as > the class defines them). > > For example: > > from functools import total_ordering > > @total_ordering > class Person(object): > def __init__(self, first_name, last_name): > self.first_name = first_name > self.last_name = last_name > > @property > def _key(self): > """Identifying key for a Person, by which they are sorted""" > return (self.last_name, self.first_name) > > def __eq__(self, other): > return isinstance(other, Person) and self._key == other._key > > def __lt__(self, other): > return self._key < other._key > > If you want to abstract even this away, then just write a class > decorator; there's no need to add yet another (rather complicated due > to all the interactions with the existing comparison methods) special > method. > But the *real* point is (as the documentation attempts to point out) that by providing the key argument it gets called only once per element, whereas the cmp argument (or the objects' __cmp__() method if you insist on letting sort delegate to that) gets called every time two objects have to be compared. If cmp is a Python function (or equivalently if __cmp__() is a Python method) then calling it will take much longer than calling hte built-in default routines. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Mon Dec 20 21:03:45 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 20 Dec 2010 21:03:45 -0500 Subject: Redundant importing of modules In-Reply-To: <528680.17833.qm@web84407.mail.ac2.yahoo.com> References: <528680.17833.qm@web84407.mail.ac2.yahoo.com> Message-ID: On 12/20/2010 8:36 PM, Jshgwave wrote: > When writing a function that uses a module such as NumPy, it is tempting > to include the statement "import numpy" or "import numpy as np" in the > definition of the function, in case the function is used in a script > that hasn't already imported NumPy. > > That could lead to the script issuing the "import numpy" command more > than once. > > Does Python know to disregard redundant "import" commands? > Oh, yes (as long as they are imported by the same name each time). There's a dict at sys.modules that has a key for each loaded module's name. When an attempt is made to import a module the first thing the interpreter does is to look at sys.modules. If it has the correct key in it then the assumption is that the module has already been imported, and its namespace is made available as the module name immediately. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From cpblpublic at gmail.com Mon Dec 20 22:03:05 2010 From: cpblpublic at gmail.com (C Barrington-Leigh) Date: Mon, 20 Dec 2010 19:03:05 -0800 (PST) Subject: Bug in fixed_point?! Message-ID: <08b56619-c21e-40b8-bafa-490fb6c6277e@z19g2000yqb.googlegroups.com> I cannot figure out what I'm doing wrong. The following does not return a fixed point: from scipy import optimize xxroot= optimize.fixed_point(lambda xx: exp(-2.0*xx)/2.0, 1.0, args=(), xtol=1e-12, maxiter=500) print ' %f solves fixed point, ie f(%f)=%f ?'% (xxroot,xxroot,exp(-2.0*xxroot)/2.0) Chris From stefan.sonnenberg at pythonmeister.com Mon Dec 20 23:25:46 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Tue, 21 Dec 2010 05:25:46 +0100 Subject: Modifying an existing excel spreadsheet In-Reply-To: <377109.56809.qm@web120503.mail.ne1.yahoo.com> References: <377109.56809.qm@web120503.mail.ne1.yahoo.com> Message-ID: <4D102C4A.303@pythonmeister.com> Am 20.12.2010 22:56, schrieb Ed Keith: > I have a user supplied 'template' Excel spreadsheet. I need to create a new excel spreadsheet based on the supplied template, with data filled in. > > I found the tools here http://www.python-excel.org/, and http://sourceforge.net/projects/pyexcelerator/. I have been trying to use the former, since the latter seems to be devoid of documentation (not even any docstrings). > > > My first thought was to copy the template, open the copy, modify it and save the modifications. But it looks like if I open an existing spreadsheet it must be read only. Could you post some code ? Did you try a simple file copy or do you iterate over all the cells ? > So I tried to open the template, copy it to a new spreadsheet and write the new spreadsheet, but I can't seem to copy the images, and it looks like copying the formatting is going to be difficult. > > Can anyone give me any tips or advice? > > Thanks in advance, > > -EdK > > Ed Keith > > e_d_k at yahoo.com > > > > Blog: edkeith.blogspot.com > > > As long as your program only needs to run under windows, COM automation is IMHO the best solution. Python tells Excel what to do. From tjreedy at udel.edu Tue Dec 21 01:03:10 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 21 Dec 2010 01:03:10 -0500 Subject: Bug in fixed_point?! In-Reply-To: <08b56619-c21e-40b8-bafa-490fb6c6277e@z19g2000yqb.googlegroups.com> References: <08b56619-c21e-40b8-bafa-490fb6c6277e@z19g2000yqb.googlegroups.com> Message-ID: On 12/20/2010 10:03 PM, C Barrington-Leigh wrote: > I cannot figure out what I'm doing wrong. The following does not > return a fixed point: What did it do? For nearly all such questions, cut and paste actual output or traceback. > from scipy import optimize > xxroot= optimize.fixed_point(lambda xx: exp(-2.0*xx)/2.0, 1.0, > args=(), xtol=1e-12, maxiter=500) > print ' %f solves fixed point, ie f(%f)=%f ?'% > (xxroot,xxroot,exp(-2.0*xxroot)/2.0) from math import exp x = 1.0 for i in range(70): print(repr(x)) x = exp(-2.0*x)/2.0 converges to 0.2835716452048919 Did you cut and paste what you actually ran? -- Terry Jan Reedy From usenet at ffconsultancy.com Tue Dec 21 01:06:31 2010 From: usenet at ffconsultancy.com (Jon Harrop) Date: Tue, 21 Dec 2010 06:06:31 -0000 Subject: Google AI challenge: planet war. Lisp won. In-Reply-To: <44a8f48f-e291-463e-a042-d0cbc31a2a4e@z17g2000prz.googlegroups.com> References: <44a8f48f-e291-463e-a042-d0cbc31a2a4e@z17g2000prz.googlegroups.com> Message-ID: Wasn't that the "challenge" where they wouldn't even accept solutions written in many other languages (including both OCaml and F#)? Cheers, Jon. "Xah Lee" wrote in message news:44a8f48f-e291-463e-a042-d0cbc31a2a4e at z17g2000prz.googlegroups.com... discovered this rather late. Google has a AI Challenge: planet wars. http://ai-contest.com/index.php it started sometimes 2 months ago and ended first this month. the winner is G?bor Melis, with his code written in lisp. Congrats lispers! G?bor wrote a blog about it here http://quotenil.com/Planet-Wars-Post-Mortem.html (not sure if this has been mentioned here but quick search didn't find it) Xah ? http://xahlee.org/ ? From nagle at animats.com Tue Dec 21 01:34:28 2010 From: nagle at animats.com (John Nagle) Date: Mon, 20 Dec 2010 22:34:28 -0800 Subject: Sending XML to a WEB Service and Getting Response Back In-Reply-To: References: Message-ID: <4d104a72$0$44000$742ec2ed@news.sonic.net> On 12/20/2010 12:14 PM, Hidura wrote: > I recommend you use the urllib.request in the library of python says > everything that you want to know. > > 2010/12/20, Anurag Chourasia: >> Dear Python Mates, >> >> I have a requirement to send a XML Data to a WEB Service whose URL is of the >> form http://joule:8041/DteEnLinea/ws/EnvioGuia.jws >> >> I also have to read back the response returned as a result of sending this >> data to this WebService. >> >> This web service implements the following operations: >> sendNCR >> >> This web service has no callbacks. >> >> I have pasted the complete WSDL for this WEB Service below my email. >> >> I would appreciate if someone could guide me with sample code using a Python >> Library suitable to fulfill this requirement of mine. >> >> Regards, >> Anurag If you're writing the client side, the service talks SOAP, and you have a WSDL file, use the "suds" module. SOAPpy is way out of date. The last update on SourceForge was in 2001. John Nagle From jearl at notengoamigos.org Tue Dec 21 02:04:09 2010 From: jearl at notengoamigos.org (Jason Earl) Date: Tue, 21 Dec 2010 00:04:09 -0700 Subject: Google AI challenge: planet war. Lisp won. References: <44a8f48f-e291-463e-a042-d0cbc31a2a4e@z17g2000prz.googlegroups.com> Message-ID: <87y67jmwt2.fsf@notengoamigos.org> On Mon, Dec 20 2010, Jon Harrop wrote: > Wasn't that the "challenge" where they wouldn't even accept solutions > written in many other languages (including both OCaml and F#)? > > Cheers, > Jon. http://ai-contest.com/faq.php Question: There is no starter package for my favorite language. What shall I do? Answer: You don't know C++, Java, or Python? Okay fine. Tell the forums what starter package you want to see, and we will try our best to make it for you. The folks working on Lisp submissions apparently created their own starter package. I am sure that something similar could have been done for OCaml or F#. That's probably too bad. These types of competitions are good publicity for less popular languages (assuming that the bots to well). Jason From ian.g.kelly at gmail.com Tue Dec 21 02:45:31 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 21 Dec 2010 00:45:31 -0700 Subject: Sending XML to a WEB Service and Getting Response Back In-Reply-To: <4d104a72$0$44000$742ec2ed@news.sonic.net> References: <4d104a72$0$44000$742ec2ed@news.sonic.net> Message-ID: On 12/20/2010 11:34 PM, John Nagle wrote: > SOAPpy is way out of date. The last update on SourceForge was in > 2001. 2007, actually: http://sourceforge.net/projects/pywebsvcs/files/ And there is repository activity within the past 9 months. Still, point taken. From stefan_ml at behnel.de Tue Dec 21 03:16:21 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 21 Dec 2010 09:16:21 +0100 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: <1292874586.11975.8.camel@linux-yu4c.site> References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <1292874586.11975.8.camel@linux-yu4c.site> Message-ID: Adam Tauno Williams, 20.12.2010 20:49: > On Mon, 2010-12-20 at 11:34 -0800, spaceman-spiff wrote: >> This is a rather long post, but i wanted to include all the details& >> everything i have tried so far myself, so please bear with me& read >> the entire boringly long post. >> I am trying to parse a ginormous ( ~ 1gb) xml file. > > Do that hundreds of times a day. > >> 0. I am a python& xml n00b, s& have been relying on the excellent >> beginner book DIP(Dive_Into_Python3 by MP(Mark Pilgrim).... Mark , if >> u are readng this, you are AWESOME& so is your witty& humorous >> writing style) >> 1. Almost all exmaples pf parsing xml in python, i have seen, start off with these 4 lines of code. >> import xml.etree.ElementTree as etree Try import xml.etree.cElementTree as etree instead. Note the leading "c", which hints at the C implementations of ElementTree. It's much faster and much more memory friendly than the Python implementation. >> tree = etree.parse('*path_to_ginormous_xml*') >> root = tree.getroot() #my huge xml has 1 root at the top level >> print root > > Yes, this is a terrible technique; most examples are crap. > >> 2. In the 2nd line of code above, as Mark explains in DIP, the parse >> function builds& returns a tree object, in-memory(RAM), which >> represents the entire document. >> I tried this code, which works fine for a small ( ~ 1MB), but when i >> run this simple 4 line py code in a terminal for my HUGE target file >> (1GB), nothing happens. >> In a separate terminal, i run the top command,& i can see a python >> process, with memory (the VIRT column) increasing from 100MB , all the >> way upto 2100MB. > > Yes, this is using DOM. DOM is evil and the enemy, full-stop. Actually, ElementTree is not "DOM", it's modelled after the XML Infoset. While I agree that DOM is, well, maybe not "the enemy", but not exactly beautiful either, ElementTree is really a good thing, likely also in this case. >> I am guessing, as this happens (over the course of 20-30 mins), the >> tree representing is being slowly built in memory, but even after >> 30-40 mins, nothing happens. >> I dont get an error, seg fault or out_of_memory exception. > > You need to process the document as a stream of elements; aka SAX. IMHO, this is the worst advice you can give. Stefan From bruno.desthuilliers at gmail.com Tue Dec 21 03:30:00 2010 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Tue, 21 Dec 2010 00:30:00 -0800 (PST) Subject: Redundant importing of modules References: <528680.17833.qm@web84407.mail.ac2.yahoo.com> Message-ID: On 21 d?c, 03:03, Steve Holden wrote: > On 12/20/2010 8:36 PM, Jshgwave wrote:> > > When writing a function that uses a module such as NumPy, it is tempting > > to include the statement "import numpy" or "import numpy as np" in the > > definition of the function, in case the ?function is used in a script > > that hasn't already imported NumPy. (answering the OP - post didn't show off here on c.l.py): This is actually totally useless. The global namespace of a function is the namespace of the module in which it has been defined, not the namespace of the module where the function is called. From stefan_ml at behnel.de Tue Dec 21 03:31:50 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 21 Dec 2010 09:31:50 +0100 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: Message-ID: spaceman-spiff, 20.12.2010 21:29: > I am sorry i left out what exactly i am trying to do. > > 0. Goal :I am looking for a specific element..there are several 10s/100s occurrences of that element in the 1gb xml file. > The contents of the xml, is just a dump of config parameters from a packet switch( although imho, the contents of the xml dont matter) > > I need to detect them& then for each 1, i need to copy all the content b/w the element's start& end tags& create a smaller xml file. Then cElementTree's iterparse() is your friend. It allows you to basically iterate over the XML tags while its building an in-memory tree from them. That way, you can either remove subtrees from the tree if you don't need them (to safe memory) or otherwise handle them in any way you like, such as serialising them into a new file (and then deleting them). Also note that the iterparse implementation in lxml.etree allows you to specify a tag name to restrict the iterator to these tags. That's usually a lot faster, but it also means that you need to take more care to clean up the parts of the tree that the iterator stepped over. Depending on your requirements and the amount of manual code optimisation that you want to invest, either cElementTree or lxml.etree may perform better for you. It seems that you already found the article by Liza Daly about high performance XML processing with Python. Give it another read, it has a couple of good hints and examples that will help you here. Stefan From haloha201 at gmail.com Tue Dec 21 04:47:50 2010 From: haloha201 at gmail.com (haloha) Date: Tue, 21 Dec 2010 16:47:50 +0700 Subject: how to inter-working on process in window Message-ID: Hi all how do i send an ESC key into a process on window i already get a pid of process but i dont know how to send ESC key into process Please help Ha -------------- next part -------------- An HTML attachment was scrubbed... URL: From rschuon at mindspring.com Tue Dec 21 08:30:29 2010 From: rschuon at mindspring.com (Robert Schuon) Date: Tue, 21 Dec 2010 13:30:29 GMT Subject: On 07/13/2010 02:18 PM, Adam Mercer wrote:That version of M2Crypto does not References: Message-ID: <2010122182925usenet@eggheadcafe.com> I was getting the same error trying to build M2Crypto 0.20.2 for Python 2.5 on a Win 7 laptop, so I pulled down the trunk, and it did build properly using minGW and Swig. However, when I try to "python setup.py install", python simply gives the same complaint that python was built in visual studio 2003, and will not install M2Crypto. Any help would be greatly appreciated, as I have been trying to get this to work for days. Does anyone have a build for 0.20.2 that works with python 2.5? I found so many other builds, but not that one. Thanks, Bob S. > On Tuesday, July 13, 2010 5:18 PM Adam Mercer wrote: > Hi > > I am trying to build M2Crypto on Mac OS X 10.6.4 against python2.5 > (python2.6 fails in the same way), with SWIG 2.0.0 and OpenSSL 1.0.0a > and it is failing with the following: > > 105 :info:build swigging SWIG/_m2crypto.i to SWIG/_m2crypto_wrap.c > 106 :info:build swig -python > -I/opt/local/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 > -I/opt/local/include -includeall -o SWIG/_m2crypto_wrap.c > SWIG/_m2crypto.i > 107 :info:build SWIG/_bio.i:64: Warning 454: Setting a > pointer/reference variable may leak memory. > 108 :info:build SWIG/_rand.i:19: Warning 454: Setting a > pointer/reference variable may leak memory. > 109 :info:build SWIG/_evp.i:156: Warning 454: Setting a > pointer/reference variable may leak memory. > 110 :info:build SWIG/_dh.i:36: Warning 454: Setting a > pointer/reference variable may leak memory. > 111 :info:build SWIG/_rsa.i:43: Warning 454: Setting a > pointer/reference variable may leak memory. > 112 :info:build SWIG/_dsa.i:31: Warning 454: Setting a > pointer/reference variable may leak memory. > 113 :info:build SWIG/_ssl.i:207: Warning 454: Setting a > pointer/reference variable may leak memory. > 114 :info:build SWIG/_x509.i:313: Warning 454: Setting a > pointer/reference variable may leak memory. > 115 :info:build SWIG/_pkcs7.i:42: Warning 454: Setting a > pointer/reference variable may leak memory. > 116 :info:build SWIG/_pkcs7.i:42: Warning 454: Setting a > pointer/reference variable may leak memory. > 117 :info:build SWIG/_util.i:9: Warning 454: Setting a > pointer/reference variable may leak memory. > 118 :info:build SWIG/_ec.i:111: Warning 454: Setting a > pointer/reference variable may leak memory. > 119 :info:build SWIG/_engine.i:162: Warning 454: Setting a > pointer/reference variable may leak memory. > 120 :info:build creating build/temp.macosx-10.6-x86_64-2.5 > 121 :info:build creating build/temp.macosx-10.6-x86_64-2.5/SWIG > 122 :info:build /usr/bin/gcc-4.2 -fno-strict-aliasing -mno-fused-madd > -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes > -I/opt/local/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 > -I/opt/local/include > -I/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_python_py25-m2crypto/work/M2Crypto-0.20.2/SWIG > -c SWIG/_m2crypto_wrap.c -o > build/temp.macosx-10.6-x86_64-2.5/SWIG/_m2crypto_wrap.o -DTHREADING > 123 :info:build SWIG/_m2crypto_wrap.c: In function 'rand_pseudo_bytes': > 124 :info:build SWIG/_m2crypto_wrap.c:3899: warning: pointer targets > in passing argument 1 of 'PyString_FromStringAndSize' differ in > signedness > 125 :info:build SWIG/_m2crypto_wrap.c: In function 'pkcs5_pbkdf2_hmac_sha1': > 126 :info:build SWIG/_m2crypto_wrap.c:3973: warning: pointer targets > in passing argument 1 of 'PyString_FromStringAndSize' differ in > signedness > 127 :info:build SWIG/_m2crypto_wrap.c: In function 'bytes_to_key': > 128 :info:build SWIG/_m2crypto_wrap.c:4132: warning: pointer targets > in passing argument 1 of 'PyString_FromStringAndSize' differ in > signedness > 129 :info:build SWIG/_m2crypto_wrap.c: In function 'sign_final': > 130 :info:build SWIG/_m2crypto_wrap.c:4228: warning: pointer targets > in passing argument 1 of 'PyString_FromStringAndSize' differ in > signedness > 131 :info:build SWIG/_m2crypto_wrap.c: In function 'pkey_as_der': > 132 :info:build SWIG/_m2crypto_wrap.c:4300: warning: pointer targets > in passing argument 1 of 'PyString_FromStringAndSize' differ in > signedness > 133 :info:build SWIG/_m2crypto_wrap.c: In function 'pkey_get_modulus': > 134 :info:build SWIG/_m2crypto_wrap.c:4333: warning: value computed is not used > 135 :info:build SWIG/_m2crypto_wrap.c:4358: warning: value computed is not used > 136 :info:build SWIG/_m2crypto_wrap.c: In function 'AES_crypt': > 137 :info:build SWIG/_m2crypto_wrap.c:4444: warning: pointer targets > in passing argument 1 of 'PyString_FromStringAndSize' differ in > signedness > 138 :info:build SWIG/_m2crypto_wrap.c: At top level: > 139 :info:build SWIG/_m2crypto_wrap.c:5846: error: expected '=', ',', > ';', 'asm' or '__attribute__' before '*' token > 140 :info:build SWIG/_m2crypto_wrap.c:5850: error: expected ')' before '*' token > 141 :info:build SWIG/_m2crypto_wrap.c:5854: error: expected ')' before '*' token > 142 :info:build SWIG/_m2crypto_wrap.c:5858: error: expected '=', ',', > ';', 'asm' or '__attribute__' before '*' token > 143 :info:build SWIG/_m2crypto_wrap.c:5862: error: expected ')' before '*' token > 144 :info:build SWIG/_m2crypto_wrap.c:5866: error: expected ')' before '*' token > 145 :info:build SWIG/_m2crypto_wrap.c: In function 'i2d_x509': > 146 :info:build SWIG/_m2crypto_wrap.c:5942: warning: pointer targets > in passing argument 1 of 'PyString_FromStringAndSize' differ in > signedness > 147 :info:build SWIG/_m2crypto_wrap.c: In function 'x509_name_set_by_nid': > 148 :info:build SWIG/_m2crypto_wrap.c:6023: warning: pointer targets > in passing argument 4 of 'X509_NAME_add_entry_by_NID' differ in > signedness > 149 :info:build SWIG/_m2crypto_wrap.c: In function 'x509_name_add_entry_by_txt': > 150 :info:build SWIG/_m2crypto_wrap.c:6028: warning: pointer targets > in passing argument 4 of 'X509_NAME_add_entry_by_txt' differ in > signedness > 151 :info:build SWIG/_m2crypto_wrap.c: At top level: > 152 :info:build SWIG/_m2crypto_wrap.c:6038: error: expected '=', ',', > ';', 'asm' or '__attribute__' before '*' token > 153 :info:build SWIG/_m2crypto_wrap.c:6043: error: expected ')' before '*' token > 154 :info:build SWIG/_m2crypto_wrap.c:6048: error: expected ')' before '*' token > 155 :info:build SWIG/_m2crypto_wrap.c:6053: error: expected ')' before '*' token >> On Friday, July 16, 2010 3:09 AM Heikki Toivonen wrote: >> On 07/13/2010 02:18 PM, Adam Mercer wrote: >> >> That version of M2Crypto does not work with OpenSSL 1.0.x because >> OpenSSL changed APIs. M2Crypto trunk works, as will the next M2Crypto >> release. So at this time, you should check out M2Crypto from the >> Subversion repository. See >> http://chandlerproject.org/Projects/MeTooCrypto for details on how to >> get the sources. >> >> -- >> Heikki Toivonen - http://heikkitoivonen.net >>> On Friday, July 16, 2010 11:18 AM Adam Mercer wrote: >>> Thanks any ETA on a new release supporting OpenSSL 1.0.x? >>> >>> Cheers >>> >>> Adam >>>> On Saturday, July 17, 2010 3:20 PM Heikki Toivonen wrote: >>>> On 07/16/2010 08:18 AM, Adam Mercer wrote: >>>> >>>> I was actually planning on doing a release by the end of June, but life >>>> happened. Maybe by the end of August... >>>> >>>> -- >>>> Heikki Toivonen - http://heikkitoivonen.net >>>>> On Saturday, July 17, 2010 8:15 PM Adam Mercer wrote: >>>>> Know what whats like :-) I have backported the OpenSSL patches for the >>>>> MacPorts port so for the time being this particular fire has been put >>>>> out. >>>>> >>>>> Cheers >>>>> >>>>> Adam >>>>> Submitted via EggHeadCafe >>>>> Oracle Developer For Beginners >>>>> http://www.eggheadcafe.com/training-topic-area/Oracle-SQL-Developer/2/Oracle-SQL-Samples.aspx From joncle at googlemail.com Tue Dec 21 10:37:30 2010 From: joncle at googlemail.com (Jon Clements) Date: Tue, 21 Dec 2010 07:37:30 -0800 (PST) Subject: Modifying an existing excel spreadsheet References: Message-ID: On Dec 20, 9:56?pm, Ed Keith wrote: > I have a user supplied 'template' Excel spreadsheet. I need to create a new excel spreadsheet based on the supplied template, with data filled in. > > I found the tools herehttp://www.python-excel.org/,?andhttp://sourceforge.net/projects/pyexcelerator/. I have been trying to use the former, since the latter seems to be devoid of documentation (not even any docstrings). > > My first thought was to copy the template, open the copy, modify it and save the modifications. But it looks like if I open an existing spreadsheet it must be read only. So I tried to? open the template, copy it to a new spreadsheet and write the new spreadsheet, but I can't seem to copy the images, and it looks like copying the formatting is going to be difficult. > > Can anyone give me any tips or advice? > > Thanks in advance, > > ?? -EdK > > Ed Keith > > e_... at yahoo.com > > Blog: edkeith.blogspot.com Have you tried: http://groups.google.com/group/python-excel and searching the archives for "template"? Similar questions have come up before there. hth Jon From robert.kern at gmail.com Tue Dec 21 11:36:07 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 21 Dec 2010 11:36:07 -0500 Subject: Bug in fixed_point?! In-Reply-To: <08b56619-c21e-40b8-bafa-490fb6c6277e@z19g2000yqb.googlegroups.com> References: <08b56619-c21e-40b8-bafa-490fb6c6277e@z19g2000yqb.googlegroups.com> Message-ID: On 12/20/10 10:03 PM, C Barrington-Leigh wrote: > I cannot figure out what I'm doing wrong. The following does not > return a fixed point: > > > from scipy import optimize > xxroot= optimize.fixed_point(lambda xx: exp(-2.0*xx)/2.0, 1.0, > args=(), xtol=1e-12, maxiter=500) > print ' %f solves fixed point, ie f(%f)=%f ?'% > (xxroot,xxroot,exp(-2.0*xxroot)/2.0) You will want to ask scipy questions on the scipy-user mailing list: http://www.scipy.org/Mailing_Lists When you do, please provide the information that Terry Reedy asked for. -- 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 ethan at stoneleaf.us Tue Dec 21 12:21:17 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 21 Dec 2010 09:21:17 -0800 Subject: class inheritance In-Reply-To: References: Message-ID: <4D10E20D.8040204@stoneleaf.us> JLundell wrote: > On Saturday, March 13, 2010 9:03:36 AM UTC-8, Jonathan Lundell wrote: >> I've got a subclass of fractions.Fraction called Value; it's a mostly >> trivial class, except that it overrides __eq__ to mean 'nearly equal'. >> However, since Fraction's operations result in a Fraction, not a >> Value, I end up with stuff like this: >> >> x = Value(1) + Value(2) >> >> where x is now a Fraction, not a Value, and x == y uses >> Fraction.__eq__ rather than Value.__eq__. >> >> This appears to be standard Python behavior (int does the same thing). >> I've worked around it by overriding __add__, etc, with functions that >> invoke Fraction but coerce the result. But that's tedious; there are a >> lot of methods to override. >> >> So I'm wondering: is there a more efficient way to accomplish what I'm >> after? > > I recently implemented a different approach to this. I've got: > > class Rational(fractions.Fraction): > > ... and some methods of my own, including my own __new__ and __str__ (which is one of the reasons I need the class). Then after (outside) the class definition, this code that was inspired by something similar I noticed in Python Cookbook. There are two things going on here. One is, of course, the automation at import time. The other is that the wrapper gets a Fraction instance and simply overrides __class__, rather than creating yet another Rational and unbinding the interim Fraction. Seems to work quite well. [snip] Another option is to use a metaclass: class Perpetuate(ABCMeta): def __new__(metacls, cls_name, cls_bases, cls_dict): if len(cls_bases) > 1: raise TypeError("multiple bases not allowed") result_class = type.__new__(metacls, cls_name, cls_bases, cls_dict) base_class = cls_bases[0] known_attr = set() for attr in cls_dict.keys(): known_attr.add(attr) for attr in base_class.__dict__.keys(): if attr in ('__new__'): continue code = getattr(base_class, attr) if callable(code) and attr not in known_attr: setattr(result_class, attr, metacls._wrap(base_class, code)) elif attr not in known_attr: setattr(result_class, attr, code) return result_class @staticmethod def _wrap(base, code): def wrapper(*args, **kwargs): if args: cls = args[0] result = code(*args, **kwargs) if type(result) == base: return cls.__class__(result) elif isinstance(result, (tuple, list, set)): new_result = [] for partial in result: if type(partial) == base: new_result.append(cls.__class__(partial)) else: new_result.append(partial) result = result.__class__(new_result) elif isinstance(result, dict): for key in result: value = result[key] if type(value) == base: result[key] = cls.__class__(value) return result wrapper.__name__ = code.__name__ wrapper.__doc__ = code.__doc__ return wrapper then the actual class becomes: class CloseFraction(Fraction): __metaclass__ = Perpetuate def __eq__(x, y): return abs(x - y) < 1 # season to taste def __repr__(x): return "CloseFraction(%d, %d)" % (x.numerator, x.denominator) Perpetuate needs to handle multiple inheritance better, but it might meet your needs at this point. Sample run: --> n = CloseFraction(3, 2) --> n CloseFraction(3, 2) --> print n 3/2 --> m = CloseFraction(9, 4) --> m CloseFraction(9, 4) --> n == m True --> n - m CloseFraction(-3, 4) --> n + m CloseFraction(15, 4) --> n.real CloseFraction(3, 2) --> n.imag 0 # this is an int Hope this helps! ~Ethan~ From joncle at googlemail.com Tue Dec 21 12:22:29 2010 From: joncle at googlemail.com (Jon Clements) Date: Tue, 21 Dec 2010 09:22:29 -0800 (PST) Subject: help with link parsing? References: Message-ID: <39ca82ab-1ed3-42d3-ba26-6f1915236e92@v17g2000vbo.googlegroups.com> On Dec 20, 7:14?pm, "Littlefield, Tyler" wrote: > Hello all, > I have a question. I guess this worked pre 2.6; I don't remember the > last time I used it, but it was a while ago, and now it's failing. > Anyone mind looking at it and telling me what's going wrong? Also, is > there a quick way to match on a certain site? like links from google.com > and only output those? > #!/usr/bin/env python > > #This program is free software: you can redistribute it and/or modify it > under the terms of the GNU General Public License as published > #by the Free Software Foundation, either version 3 of the License, or > (at your option) any later version. > > #This program is distributed in the hope that it will be useful, but > WITHOUT ANY WARRANTY; without even the implied warranty of > #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > General Public License for more details. > # > #You should have received a copy of the GNU General Public License along > with this program. If not, see > #http://www.gnu.org/licenses/. > > """ > This script will parse out all the links in an html document and write > them to a textfile. > """ > import sys,optparse > import htmllib,formatter > > #program class declarations: > class Links(htmllib.HTMLParser): > ? ? ?def __init__(self,formatter): > ? ? ? ? ?htmllib.HTMLParser.__init__(self, formatter) > ? ? ? ? ?self.links=[] > ? ? ?def start_a(self, attrs): > ? ? ? ? ?if (len(attrs)>0): > ? ? ? ? ? ? ?for a in attrs: > ? ? ? ? ? ? ? ? ?if a[0]=="href": > ? ? ? ? ? ? ? ? ? ? ?self.links.append(a[1]) > ? ? ? ? ? ? ? ? ? ? ?print a[1] > ? ? ? ? ? ? ? ? ? ? ?break > > def main(argv): > ? ? ?if (len(argv)!=3): > ? ? ? ? ?print("Error:\n"+argv[0]+" .\nParses > for all links and saves them to .") > ? ? ? ? ?return 1 > ? ? ?lcount=0 > ? ? ?format=formatter.NullFormatter() > ? ? ?html=Links(format) > ? ? ?print "Retrieving data:" > ? ? ?page=open(argv[1],"r") > ? ? ?print "Feeding data to parser:" > ? ? ?html.feed(page.read()) > ? ? ?page.close() > ? ? ?print "Writing links:" > ? ? ?output=open(argv[2],"w") > ? ? ?for i in (html.links): > ? ? ? ? ?output.write(i+"\n") > ? ? ? ? ?lcount+=1 > ? ? ?output.close() > ? ? ?print("Wrote "+str(lcount)+" links to "+argv[2]+"."); > ? ? ?print("done.") > > if (__name__ == "__main__"): > ? ? ?#we call the main function passing a list of args, and exit with > the return code passed back. > ? ? ?sys.exit(main(sys.argv)) > > -- > > Thanks, > Ty This doesn't answer your original question, but excluding the command line handling, how's this do you?: import lxml from urlparse import urlsplit doc = lxml.html.parse('http://www.google.com') print map(urlsplit, doc.xpath('//a/@href')) [SplitResult(scheme='http', netloc='www.google.co.uk', path='/imghp', query='hl=en&tab=wi', fragment=''), SplitResult(scheme='http', netloc='video.google.co.uk', path='/', query='hl=en&tab=wv', fragment=''), SplitResult(scheme='http', netloc='maps.google.co.uk', path='/maps', query='hl=en&tab=wl', fragment=''), SplitResult(scheme='http', netloc='news.google.co.uk', path='/nwshp', query='hl=en&tab=wn', fragment=''), ...] Much nicer IMHO, plus the lxml.html has iterlinks() and other convenience functions for handling HTML. hth Jon. From howe.steven at gmail.com Tue Dec 21 14:10:04 2010 From: howe.steven at gmail.com (GrayShark) Date: Tue, 21 Dec 2010 13:10:04 -0600 Subject: seeking pygtk bindings for gtkdatabox Message-ID: Hello, a search for the python bindings for gtkdatabox lead no where. Anyone know of who is maintaining/working/siting such a package? Thanks in advance. Steven From nagle at animats.com Tue Dec 21 14:10:55 2010 From: nagle at animats.com (John Nagle) Date: Tue, 21 Dec 2010 11:10:55 -0800 Subject: Sending XML to a WEB Service and Getting Response Back In-Reply-To: References: <4d104a72$0$44000$742ec2ed@news.sonic.net> Message-ID: <4d10fbbd$0$44066$742ec2ed@news.sonic.net> On 12/20/2010 11:45 PM, Ian Kelly wrote: > On 12/20/2010 11:34 PM, John Nagle wrote: >> SOAPpy is way out of date. The last update on SourceForge was in >> 2001. > > 2007, actually: http://sourceforge.net/projects/pywebsvcs/files/ > > And there is repository activity within the past 9 months. Still, point > taken. The original SOAPpy was at http://sourceforge.net/projects/soapy/files/ but was apparently abandoned in 2001. Someone else picked it up and moved it to http://sourceforge.net/projects/pywebsvcs/files/SOAP.py/ where it was last updated in 2005. ZSI was last updated in 2007. Users are still submitting bug reports, but nobody is answering. Somebody posted "Who maintains the pywebsvcs webpage?" in February 2009, but no one answered them. There's also "Python SOAP" http://sourceforge.net/projects/pythonsoap/ abandoned in 2005. The "suds" module http://sourceforge.net/projects/python-suds/ was last updated in March, 2010. That version will work with Python 2.6, and probably 2.7. There's very little project activity, but at least it's reasonably current. John Nagle From msarro at gmail.com Tue Dec 21 14:17:40 2010 From: msarro at gmail.com (Matty Sarro) Date: Tue, 21 Dec 2010 14:17:40 -0500 Subject: Scanning directories for new files? Message-ID: Hey everyone. I'm in the midst of writing a parser to clean up incoming files, remove extra data that isn't needed, normalize some values, etc. The base files will be uploaded via FTP. How does one go about scanning a directory for new files? For now we're looking to run it as a cron job but eventually would like to move away from that into making it a service running in the background. From georg at python.org Tue Dec 21 14:18:56 2010 From: georg at python.org (Georg Brandl) Date: Tue, 21 Dec 2010 20:18:56 +0100 Subject: [RELEASED] Python 3.2 beta 2 Message-ID: <4D10FDA0.7090808@python.org> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On behalf of the Python development team, I'm happy to announce the second beta preview release of Python 3.2. Python 3.2 is a continuation of the efforts to improve and stabilize the Python 3.x line. Since the final release of Python 2.7, the 2.x line will only receive bugfixes, and new features are developed for 3.x only. Since PEP 3003, the Moratorium on Language Changes, is in effect, there are no changes in Python's syntax and built-in types in Python 3.2. Development efforts concentrated on the standard library and support for porting code to Python 3. Highlights are: * numerous improvements to the unittest module * PEP 3147, support for .pyc repository directories * PEP 3149, support for version tagged dynamic libraries * PEP 3148, a new futures library for concurrent programming * PEP 384, a stable ABI for extension modules * PEP 391, dictionary-based logging configuration * an overhauled GIL implementation that reduces contention * an extended email package that handles bytes messages * countless fixes regarding bytes/string issues; among them full support for a bytes environment (filenames, environment variables) * many consistency and behavior fixes for numeric operations * a sysconfig module to access configuration information * a pure-Python implementation of the datetime module * additions to the shutil module, among them archive file support * improvements to pdb, the Python debugger For a more extensive list of changes in 3.2, see http://docs.python.org/3.2/whatsnew/3.2.html To download Python 3.2 visit: http://www.python.org/download/releases/3.2/ Please consider trying Python 3.2 with your code and reporting any bugs you may notice to: http://bugs.python.org/ Enjoy! - -- Georg Brandl, Release Manager georg at python.org (on behalf of the entire python-dev team and 3.2's contributors) -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iEYEARECAAYFAk0Q/aAACgkQN9GcIYhpnLDf8gCgkLGAsE+T3R505jZc1RxXDYsa NSsAnRGaFjeTm9o2Z5O8FuIzTUG8t1PT =hHzz -----END PGP SIGNATURE----- From anurag.chourasia at gmail.com Tue Dec 21 14:26:52 2010 From: anurag.chourasia at gmail.com (Anurag Chourasia) Date: Wed, 22 Dec 2010 00:56:52 +0530 Subject: Sending XML to a WEB Service and Getting Response Back In-Reply-To: <4d10fbbd$0$44066$742ec2ed@news.sonic.net> References: <4d104a72$0$44000$742ec2ed@news.sonic.net> <4d10fbbd$0$44066$742ec2ed@news.sonic.net> Message-ID: Thanks for the response all. I tried exploring suds (which seems to be the current) and i hit problems right away. I will now try urllib or httplib. I have asked for help in the suds forum. Hope somebody replies. When i try to create a client, the error is as follows. >>> from suds.client import Client >>> url = 'http://10.251.4.33:8041/DteEnLinea/ws/EnvioGuia.jws' >>> client = Client(url) Traceback (most recent call last): File "", line 1, in File "suds/client.py", line 112, in __init__ self.wsdl = reader.open(url) File "suds/reader.py", line 152, in open d = self.fn(url, self.options) File "suds/wsdl.py", line 136, in __init__ d = reader.open(url) File "suds/reader.py", line 79, in open d = self.download(url) File "suds/reader.py", line 101, in download return sax.parse(string=content) File "suds/sax/parser.py", line 136, in parse sax.parse(source) File "/usr/local/lib/python2.7/xml/sax/expatreader.py", line 107, in parse xmlreader.IncrementalParser.parse(self, source) File "/usr/local/lib/python2.7/xml/sax/xmlreader.py", line 123, in parse self.feed(buffer) File "/usr/local/lib/python2.7/xml/sax/expatreader.py", line 211, in feed self._err_handler.fatalError(exc) File "/usr/local/lib/python2.7/xml/sax/handler.py", line 38, in fatalError raise exception xml.sax._exceptions.SAXParseException: :1:62: syntax error >>> [3] + Stopped (SIGTSTP) python This seems to be a old problem passing versions. Regards, Anurag On Wed, Dec 22, 2010 at 12:40 AM, John Nagle wrote: > On 12/20/2010 11:45 PM, Ian Kelly wrote: >> >> On 12/20/2010 11:34 PM, John Nagle wrote: >>> >>> SOAPpy is way out of date. The last update on SourceForge was in >>> 2001. >> >> 2007, actually: http://sourceforge.net/projects/pywebsvcs/files/ >> >> And there is repository activity within the past 9 months. Still, point >> taken. > > ? The original SOAPpy was at > > ? ? ? ?http://sourceforge.net/projects/soapy/files/ > > but was apparently abandoned in 2001. Someone else picked > it up and moved it to > > ? ? ? ?http://sourceforge.net/projects/pywebsvcs/files/SOAP.py/ > > where it was last updated in 2005. ?ZSI was last updated in > 2007. ?Users are still submitting bug reports, but nobody > is answering. ?Somebody posted "Who maintains the pywebsvcs webpage?" > in February 2009, but no one answered them. > > ? ?There's also "Python SOAP" > > http://sourceforge.net/projects/pythonsoap/ > > abandoned in 2005. > > ? ?The "suds" module > > http://sourceforge.net/projects/python-suds/ > > was last updated in March, 2010. ?That version > will work with Python 2.6, and probably 2.7. > There's very little project activity, but at > least it's reasonably current. > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?John Nagle > -- > http://mail.python.org/mailman/listinfo/python-list > From joncle at googlemail.com Tue Dec 21 14:34:00 2010 From: joncle at googlemail.com (Jon Clements) Date: Tue, 21 Dec 2010 11:34:00 -0800 (PST) Subject: Scanning directories for new files? References: Message-ID: On Dec 21, 7:17?pm, Matty Sarro wrote: > Hey everyone. > I'm in the midst of writing a parser to clean up incoming files, > remove extra data that isn't needed, normalize some values, etc. The > base files will be uploaded via FTP. > How does one go about scanning a directory for new files? For now > we're looking to run it as a cron job but eventually would like to > move away from that into making it a service running in the > background. Not a direct answer, but I would choose the approach of letting the FTP server know when a new file has been added. For instance: http://www.pureftpd.org/project/pure-ftpd - "Any external shell script can be called after a successful upload. Virus scanners and database archiveal can easily be set up." Of course, there's loads more servers, that I'm sure will have callback events or similar. Although, yes, the monitoring the file system is completely possible. hth Jon. From stefan.sonnenberg at pythonmeister.com Tue Dec 21 14:36:13 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Tue, 21 Dec 2010 20:36:13 +0100 Subject: Scanning directories for new files? In-Reply-To: References: Message-ID: <4D1101AD.2090105@pythonmeister.com> Am 21.12.2010 20:17, schrieb Matty Sarro: > Hey everyone. > I'm in the midst of writing a parser to clean up incoming files, > remove extra data that isn't needed, normalize some values, etc. The > base files will be uploaded via FTP. > How does one go about scanning a directory for new files? For now > we're looking to run it as a cron job but eventually would like to > move away from that into making it a service running in the > background. When You say cron, I assume you're running linux. One approach would be to os.walk() the directory in question, and filling a dict with the absolute name of the file as key and the output from stat() as content. Then re-scan regularly and check for changes in mtime,ctime etc. A less ressource consuming approach would be to use Linux' inotify infrastructure, which can be used from python https://github.com/seb-m/pyinotify And, your service is only an import away :-) https://github.com/seb-m/pyinotify/blob/master/python2/examples/daemon.py From martin at address-in-sig.invalid Tue Dec 21 14:51:25 2010 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Tue, 21 Dec 2010 19:51:25 +0000 (UTC) Subject: Scanning directories for new files? References: Message-ID: On Tue, 21 Dec 2010 14:17:40 -0500, Matty Sarro wrote: > Hey everyone. > I'm in the midst of writing a parser to clean up incoming files, remove > extra data that isn't needed, normalize some values, etc. The base files > will be uploaded via FTP. > How does one go about scanning a directory for new files? For now we're > looking to run it as a cron job but eventually would like to move away > from that into making it a service running in the background. > Make sure the files are initially uploaded using a name that the parser isn't looking for and rename it when the upload is finished. This way the parser won't try to process a partially loaded file. If you are uploading to a *nix machine You the rename can move the file between directories provided both directories are in the same filing system. Under those conditions rename is always an atomic operation with no copying involved. This would you to, say, upload the file to "temp/ myfile" and renamed it to "uploaded/myfile" with your parser only scanning the uploaded directory and, presumably, renaming processed files to move them to a third directory ready for further processing. I've used this technique reliably with files arriving via FTP at quite high rates. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From fal at togliquesto.fastwebnet.it Tue Dec 21 14:54:02 2010 From: fal at togliquesto.fastwebnet.it (Francesco) Date: Tue, 21 Dec 2010 20:54:02 +0100 Subject: If/then style question In-Reply-To: <4d0d4c42$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <4d0aa5e7$0$29997$c3e8da3$5496439d@news.astraweb.com> <4D0C9B1B.2030605@togliquesto.fastwebnet.it> <4d0d4c42$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: I'd bet you would stress your point Steven! But you don't need to persuade me, I do already agree. I just meant to say that, when the advantage is little, there's no need to rewrite a working function. And that with modern CPUs, if tests take so little time, that even some redundant one is not so much of a nuisance. in your working example, the "payload" is just a couple of integer calculations, that take very little time too. So the overhead due to redundant if tests does show clearly. And also in that not-really-real situation, 60% overhead just meant less than 3 seconds. Just for the sake of discussion, I tried to give both functions some plough to pull, and a worst-case situation too: >>> t1 = Timer('for x in range(100): print func1(0),', ... 'from __main__ import func1') >>> >>> t2 = Timer('for x in range(100): print func2(0),', ... 'from __main__ import func2') >>> >>> min(t1.repeat(number=1, repeat=1)) -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 53.011015366479114 >>> min(t2.repeat(number=1, repeat=1)) -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 47.55442856564332 that accounts for a scant 11% overhead, on more than one million tests per cycle. That said, let's make really clear that I would heartily prefer func2 to func1, based both on readability and speed. Thank you for having spent some time playing with me! Francesco On 19/12/2010 1.05, Steven D'Aprano wrote: > Well, let's try it with a working (albeit contrived) example. This is > just an example -- obviously I wouldn't write the function like this in > real life, I'd use a while loop, but to illustrate the issue it will do. > > def func1(n): > result = -1 > done = False > n = (n+1)//2 > if n%2 == 1: > result = n > done = True > if not done: > n = (n+1)//2 > if n%2 == 1: > result = n > done = True > if not done: > n = (n+1)//2 > if n%2 == 1: > result = n > done = True > if not done: > for i in range(1000000): > if not done: > n = (n+1)//2 > if n%2 == 1: > result = n > done = True > return result > > > def func2(n): > n = (n+1)//2 > if n%2 == 1: > return n > n = (n+1)//2 > if n%2 == 1: > return n > n = (n+1)//2 > if n%2 == 1: > return n > for i in range(1000000): > n = (n+1)//2 > if n%2 == 1: > return n > return -1 > > > Not only is the second far more readable that the first, but it's also > significantly faster: > >>>> from timeit import Timer >>>> t1 = Timer('for i in range(20): x = func1(i)', > ... 'from __main__ import func1') >>>> t2 = Timer('for i in range(20): x = func2(i)', > ... 'from __main__ import func2') >>>> min(t1.repeat(number=10, repeat=5)) > 7.3219029903411865 >>>> min(t2.repeat(number=10, repeat=5)) > 4.530779838562012 > > The first function does approximately 60% more work than the first, all > of it unnecessary overhead. > > > From howe.steven at gmail.com Tue Dec 21 15:03:20 2010 From: howe.steven at gmail.com (GrayShark) Date: Tue, 21 Dec 2010 14:03:20 -0600 Subject: Scanning directories for new files? References: Message-ID: On Tue, 21 Dec 2010 14:17:40 -0500, Matty Sarro wrote: > Hey everyone. > I'm in the midst of writing a parser to clean up incoming files, remove > extra data that isn't needed, normalize some values, etc. The base files > will be uploaded via FTP. > How does one go about scanning a directory for new files? For now we're > looking to run it as a cron job but eventually would like to move away > from that into making it a service running in the background. You can try pyinotify. Pyinotify is a Python module for monitoring filesystems changes. Pyinotify relies on a Linux Kernel feature (merged in kernel 2.6.13) called inotify. inotify is an event-driven notifier, its notifications are exported from kernel space to user space through three system calls. pyinotify binds these system calls and provides an implementation on top of them offering a generic and abstract way to manipulate those functionalities. I'm assuming your using Linux. You seem to be at least using UNIX (cron). read more at: http://pyinotify.sourceforge.net/ Steven From ian.g.kelly at gmail.com Tue Dec 21 15:26:00 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 21 Dec 2010 13:26:00 -0700 Subject: Sending XML to a WEB Service and Getting Response Back In-Reply-To: <4d10fbbd$0$44066$742ec2ed@news.sonic.net> References: <4d104a72$0$44000$742ec2ed@news.sonic.net> <4d10fbbd$0$44066$742ec2ed@news.sonic.net> Message-ID: On 12/21/2010 12:10 PM, John Nagle wrote: > The original SOAPpy was at > > http://sourceforge.net/projects/soapy/files/ > > but was apparently abandoned in 2001. Someone else picked > it up and moved it to > > http://sourceforge.net/projects/pywebsvcs/files/SOAP.py/ These are unrelated projects, AFACT. The former was released as version 0.1 on 4/27/01. According to the changelog, the first public release of the latter was version 0.5 on 4/17/01. From luismgz at gmail.com Tue Dec 21 16:56:58 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Tue, 21 Dec 2010 13:56:58 -0800 (PST) Subject: Python 3.2 beta 2 References: Message-ID: I wonder if Unladen Swallow is still being considered for merger with Python 3.3. Is it? On Dec 21, 4:18?pm, Georg Brandl wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On behalf of the Python development team, I'm happy to announce the > second beta preview release of Python 3.2. > > Python 3.2 is a continuation of the efforts to improve and stabilize the > Python 3.x line. ?Since the final release of Python 2.7, the 2.x line > will only receive bugfixes, and new features are developed for 3.x only. > > Since PEP 3003, the Moratorium on Language Changes, is in effect, there > are no changes in Python's syntax and built-in types in Python 3.2. > Development efforts concentrated on the standard library and support for > porting code to Python 3. ?Highlights are: > > * numerous improvements to the unittest module > * PEP 3147, support for .pyc repository directories > * PEP 3149, support for version tagged dynamic libraries > * PEP 3148, a new futures library for concurrent programming > * PEP 384, a stable ABI for extension modules > * PEP 391, dictionary-based logging configuration > * an overhauled GIL implementation that reduces contention > * an extended email package that handles bytes messages > * countless fixes regarding bytes/string issues; among them full > ? support for a bytes environment (filenames, environment variables) > * many consistency and behavior fixes for numeric operations > * a sysconfig module to access configuration information > * a pure-Python implementation of the datetime module > * additions to the shutil module, among them archive file support > * improvements to pdb, the Python debugger > > For a more extensive list of changes in 3.2, see > > ? ?http://docs.python.org/3.2/whatsnew/3.2.html > > To download Python 3.2 visit: > > ? ?http://www.python.org/download/releases/3.2/ > > Please consider trying Python 3.2 with your code and reporting any bugs > you may notice to: > > ? ?http://bugs.python.org/ > > Enjoy! > > - -- > Georg Brandl, Release Manager > georg at python.org > (on behalf of the entire python-dev team and 3.2's contributors) > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.11 (GNU/Linux) > > iEYEARECAAYFAk0Q/aAACgkQN9GcIYhpnLDf8gCgkLGAsE+T3R505jZc1RxXDYsa > NSsAnRGaFjeTm9o2Z5O8FuIzTUG8t1PT > =hHzz > -----END PGP SIGNATURE----- From martin at v.loewis.de Tue Dec 21 17:10:56 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Tue, 21 Dec 2010 23:10:56 +0100 Subject: Python 3.2 beta 2 In-Reply-To: References: Message-ID: <4D1125F0.5010505@v.loewis.de> Am 21.12.2010 22:56, schrieb Luis M. Gonz?lez: > I wonder if Unladen Swallow is still being considered for merger with > Python 3.3. > Is it? 3.2 isn't even released yet, and 3.3 will appear 18 months after it (so in Summer 2012). It's much too early to tell. OTOH, to answer you literal question: most certainly. At least you seem to be considering it, so it's certainly being considered by somebody. Regards, Martin From ddasilva at umd.edu Tue Dec 21 17:17:22 2010 From: ddasilva at umd.edu (Daniel da Silva) Date: Tue, 21 Dec 2010 17:17:22 -0500 Subject: Funny __future__ imports Message-ID: from __future__ import space_shuttle DeprecationWarning: will be removed in next release Post yours! -------------- next part -------------- An HTML attachment was scrubbed... URL: From arnodel at gmail.com Tue Dec 21 18:27:33 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Tue, 21 Dec 2010 23:27:33 +0000 Subject: True lists in python? References: <4d0dc70d$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87zkryaeqi.fsf@gmail.com> Duncan Booth writes: > I guess you might be able to do it with a double-linked list provided > that when traversing the list you always keep two nodes around to > determine the direction. e.g. instead of asking for node6.nextNode() you > ask for node6.nextNode(previous=node1) and then the code can return > whichever sibling wasn't given. That would make reversal (assuming you > have both nodes) O(1), but would make traversing the list slower. There used to be a trick to implement doubly linked lists with the same memory footprint as singly linked ones: instead of each node storing two pointers (one to the next node, one to the previous one), you just store one value: (previous node) xor (next node) This means that when traversing the list, you need to always remember which node you are coming from. But it also makes these lists kind of symmetrical. -- Arnaud From joncle at googlemail.com Tue Dec 21 20:12:39 2010 From: joncle at googlemail.com (Jon Clements) Date: Tue, 21 Dec 2010 17:12:39 -0800 (PST) Subject: Specialisation / Interests Message-ID: <47fb5d39-a934-4906-8b4b-44d79ad52613@29g2000yqq.googlegroups.com> Hi all, Was thinking tonight (now this morning my time): What would we consider the "long time" posters on c.l.p consider what they respond to and offer serious advice on. For instance: - Raymond Hettinger for algo's in collections and itertools - MRAB for regex's (never seen him duck a post where re was (not) required. - the "effbot" for PIL & ElementTree - Mark Hammond for work on win32 - Mark Dickinson for floating point/number theory etc... Then so many others!... I'm leaving a huge amount out, so no rudeness intended - but what you think guys and gals? Cheers, Jon. From ncoghlan at gmail.com Tue Dec 21 20:15:34 2010 From: ncoghlan at gmail.com (Nick Coghlan) Date: Wed, 22 Dec 2010 12:15:34 +1100 Subject: [python-committers] [RELEASED] Python 3.2 beta 2 In-Reply-To: <4D10FDA0.7090808@python.org> References: <4D10FDA0.7090808@python.org> Message-ID: On Wed, Dec 22, 2010 at 6:18 AM, Georg Brandl wrote: > Since PEP 3003, the Moratorium on Language Changes, is in effect, there > are no changes in Python's syntax and built-in types in Python 3.2. Minor nit - we actually did tweak a few of the builtin types a bit (mostly the stuff to improve Sequence ABC conformance and to make range objects more list-like) Cheers, Nick. -- Nick Coghlan?? |?? ncoghlan at gmail.com?? |?? Brisbane, Australia From python at mrabarnett.plus.com Tue Dec 21 21:38:35 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 22 Dec 2010 02:38:35 +0000 Subject: Funny __future__ imports In-Reply-To: References: Message-ID: <4D1164AB.5020409@mrabarnett.plus.com> On 21/12/2010 22:17, Daniel da Silva wrote: > from __future__ import space_shuttle > DeprecationWarning: will be removed in next release > > > Post yours! > from __future__ import time_machine ImportError: time_machine in use by import From emile at fenx.com Tue Dec 21 22:16:28 2010 From: emile at fenx.com (Emile van Sebille) Date: Tue, 21 Dec 2010 19:16:28 -0800 Subject: Funny __future__ imports In-Reply-To: <4D1164AB.5020409@mrabarnett.plus.com> References: <4D1164AB.5020409@mrabarnett.plus.com> Message-ID: On 12/21/2010 6:38 PM MRAB said... > On 21/12/2010 22:17, Daniel da Silva wrote: >> from __future__ import space_shuttle >> DeprecationWarning: will be removed in next release >> >> >> Post yours! >> > from __future__ import time_machine > ImportError: time_machine in use by import from __future__ import improved_realestate_market ValueError: realestate market depreciated :) From nagle at animats.com Tue Dec 21 22:24:21 2010 From: nagle at animats.com (John Nagle) Date: Tue, 21 Dec 2010 19:24:21 -0800 Subject: Sending XML to a WEB Service and Getting Response Back In-Reply-To: References: <4d104a72$0$44000$742ec2ed@news.sonic.net> <4d10fbbd$0$44066$742ec2ed@news.sonic.net> Message-ID: <4d116f63$0$44060$742ec2ed@news.sonic.net> On 12/21/2010 11:26 AM, Anurag Chourasia wrote: > Thanks for the response all. > > I tried exploring suds (which seems to be the current) and i hit > problems right away. I will now try urllib or httplib. > > I have asked for help in the suds forum. Hope somebody replies. > > When i try to create a client, the error is as follows. > >>>> from suds.client import Client >>>> url = 'http://10.251.4.33:8041/DteEnLinea/ws/EnvioGuia.jws' >>>> client = Client(url) > > Traceback (most recent call last): > File "", line 1, in > File "suds/client.py", line 112, in __init__ > self.wsdl = reader.open(url) > File "suds/reader.py", line 152, in open > d = self.fn(url, self.options) > File "suds/wsdl.py", line 136, in __init__ > d = reader.open(url) > File "suds/reader.py", line 79, in open > d = self.download(url) > File "suds/reader.py", line 101, in download > return sax.parse(string=content) > File "suds/sax/parser.py", line 136, in parse > sax.parse(source) > File "/usr/local/lib/python2.7/xml/sax/expatreader.py", line 107, in parse > xmlreader.IncrementalParser.parse(self, source) > File "/usr/local/lib/python2.7/xml/sax/xmlreader.py", line 123, in parse > self.feed(buffer) > File "/usr/local/lib/python2.7/xml/sax/expatreader.py", line 211, in feed > self._err_handler.fatalError(exc) > File "/usr/local/lib/python2.7/xml/sax/handler.py", line 38, in fatalError > raise exception > xml.sax._exceptions.SAXParseException::1:62: syntax error >>>> [3] + Stopped (SIGTSTP) python > > This seems to be a old problem passing versions. > > Regards, > Anurag Try posting a URL that isn't on network 10. That's some local network at your end. John Nagle From cpblpublic at gmail.com Tue Dec 21 23:33:01 2010 From: cpblpublic at gmail.com (C Barrington-Leigh) Date: Tue, 21 Dec 2010 20:33:01 -0800 (PST) Subject: Bug in fixed_point?! References: <08b56619-c21e-40b8-bafa-490fb6c6277e@z19g2000yqb.googlegroups.com> Message-ID: <2a930684-1d6b-4ed4-8bcc-a3a558479166@z9g2000yqz.googlegroups.com> On Dec 21, 9:36?am, Robert Kern wrote: > When you do, please provide the information that Terry Reedy asked for. > Sorry; quite right. For completeness I'll post here as well as over on scipy. Here's the actual code: --------------------- from scipy import optimize from math import exp xxroot= optimize.fixed_point(lambda xx: exp(-2.0*xx)/2.0, 1.0, args=(), xtol=1e-12, maxiter=500) print ' %f solves fixed point, ie f(%f)=%f ?'% (xxroot,xxroot,exp(-2.0*xxroot)/2.0) Here is the output ------------------ Python 2.6.6 (r266:84292, Sep 15 2010, 16:22:56) In [1]: run tmp.py 0.332058 solves fixed point, ie f(0.332058)=0.257364 ? From benedict.verheyen at gmail.com Wed Dec 22 03:33:27 2010 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Wed, 22 Dec 2010 09:33:27 +0100 Subject: compiling Python 2.7.1 with readline module fails on Debian (Virtualbox) Message-ID: Hi, i'm trying to compile Python 2.7.1 on Debian (Virtual Box). Compiling end successfully but readline and curses fail to build. I'm working with virtualenv and I install all my packages in $HOME/local. I've downloaded readline, compiled and installed it in $HOME/local, same with ncurses. Both were the latest releases. But somehow, Python isn't able to build them. I get this message: Failed to build these modules: _curses _curses_panel readline So it does seems to find the modules. I'm not used to dealing with configure, and make so i can't debug much. I first tried this configure line: ./configure --enable-shared --prefix=$HOME/local Next i tried this one: env CPPFLAGS="-I$HOME/local/include" LDFLAGS="-L$HOME/local/lib" ./configure --enable-shared --prefix=$HOME/local But make yields the same error. Any clues on what I do wrong? The source of ncurses and readline are placed in $HOME/src. Both packages are installed in $HOME/local Thanks for any advice, Regards, Benedict From mark at mark-fink.de Wed Dec 22 03:50:04 2010 From: mark at mark-fink.de (Mark Fink) Date: Wed, 22 Dec 2010 00:50:04 -0800 (PST) Subject: Question regarding Higher-Order-Programming in Python Message-ID: <7819f726-244a-4b6e-9cde-6bde9fe286df@30g2000yql.googlegroups.com> I am about to learn Higher-Order-Programming with Lisp, Haskell, and Python. Some people who have gone completely out of their mind call this FP. In Haskell I learned that when I use map on a list it starts nesting as soon as I start adding elements. If I do not like the nesting I use ConcatMap. In Python I have a similar scenario. I have a generator which creates some combinatorics of a input dictionary. The list starts nesting. Now I could use reduce(concat, ...) which would be the correct thing from a functional perspective. But from a resource utilization perspective it is not a good idea since the reduce is executing the generator. I tried to illustrate this using a small example (the often in combinatorics the real thing would be much bigger that is why I need to use a generator): >>> from operator import itemgetter, concat >>> import itertools as it >>> from functools import partial >>> >>> dims = {'number': [1,2,3], 'letter': ['a', 'b'], 'special': ['+', '-']} >>> dims {'special': ['+', '-'], 'number': [1, 2, 3], 'letter': ['a', 'b']} >>> def get_products(keys): ... # helper to get products from keys in the following form: ... # [('bold', True), ('color', 'black')] ... values = itemgetter(*keys)(dims) ... product = it.product(*values) ... return map(partial(zip, keys), product) ... >>> comb = it.combinations(dims, 2) >>> comb_l = list(comb) >>> comb_l [('special', 'number'), ('special', 'letter'), ('number', 'letter')] >>> res = map(get_products, comb_l) >>> res [[[('special', '+'), ('number', 1)], [('special', '+'), ('number', 2)], [('special', '+'), ('number', 3)], [('special', '-'), ('number', 1)], [('special', '-'), ('number', 2)], [('special', '-'), ('number', 3)]], [[('special', '+'), ('letter', 'a')], [('special', '+'), ('letter', 'b')], [('special', '-'), ('letter', 'a')], [('special', '-'), ('letter', 'b')]], [[('number', 1), ('letter', 'a')], [('number', 1), ('letter', 'b')], [('number', 2), ('letter', 'a')], [('number', 2), ('letter', 'b')], [('number', 3), ('letter', 'a')], [('number', 3), ('letter', 'b')]]] # the resulting list is nested one level to deep caused by the map(get_products, .. >>> My problem is that I want to get single elements from the generator like [('special', '+'), ('number', 1)]. But this does not work because the list is now nested to deep. That is what I expect: (I could get something like that with the following >>> res = reduce(concat, res) [[('special', '+'), ('number', 1)], [('special', '+'), ('number', 2)], [('special', '+'), ('number', 3)], [('special', '-'), ('number', 1)], [('special', '-'), ('number', 2)], [('special', '-'), ('number', 3)], [('special', '+'), ('letter', 'a')], [('special', '+'), ('letter', 'b')], [('special', '-'), ('letter', 'a')], [('special', '-'), ('letter', 'b')], [('number', 1), ('letter', 'a')], [('number', 1), ('letter', 'b')], [('number', 2), ('letter', 'a')], [('number', 2), ('letter', 'b')], [('number', 3), ('letter', 'a')], [('number', 3), ('letter', 'b')]] I have seen the problem many times but so far I could not google a solution on the web. By the way do you know any substantial example using FP in Python (generators, imap, ifilter, ...)? From kentilton at gmail.com Wed Dec 22 05:43:42 2010 From: kentilton at gmail.com (kenny) Date: Wed, 22 Dec 2010 02:43:42 -0800 (PST) Subject: Mo Better Lisp Jobs Message-ID: Check it out: http://lispjobs.wordpress.com/2010/12/22/lisp-developer-mcna-fort-laurderdale-florida/ We already have six splendid folks but business is booming and at least one contract bid has to happen faster than we thought (potential client moved it up) so we are looking to take on a couple more. Lisp wannabe Rails gurus lurking here, plz note the opportunity described in the listing. The rest of the cross-posting is to find great coders with light Lisp. We can talk. HK From __peter__ at web.de Wed Dec 22 07:57:02 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 22 Dec 2010 13:57:02 +0100 Subject: Question regarding Higher-Order-Programming in Python References: <7819f726-244a-4b6e-9cde-6bde9fe286df@30g2000yql.googlegroups.com> Message-ID: Mark Fink wrote: > I am about to learn Higher-Order-Programming with Lisp, Haskell, and > Python. Some people who have gone completely out of their mind call > this FP. > > In Haskell I learned that when I use map on a list it starts nesting > as soon as I start adding elements. If I do not like the nesting I use > ConcatMap. > > In Python I have a similar scenario. I have a generator which creates > some combinatorics of a input dictionary. The list starts nesting. Now > I could use reduce(concat, ...) which would be the correct thing from > a functional perspective. But from a resource utilization perspective > it is not a good idea since the reduce is executing the generator. > > I tried to illustrate this using a small example (the often in > combinatorics the real thing would be much bigger that is why I need > to use a generator): > >>>> from operator import itemgetter, concat >>>> import itertools as it >>>> from functools import partial >>>> >>>> dims = {'number': [1,2,3], 'letter': ['a', 'b'], 'special': ['+', '-']} >>>> dims > {'special': ['+', '-'], 'number': [1, 2, 3], 'letter': ['a', 'b']} >>>> def get_products(keys): > ... # helper to get products from keys in the following form: > ... # [('bold', True), ('color', 'black')] > ... values = itemgetter(*keys)(dims) > ... product = it.product(*values) > ... return map(partial(zip, keys), product) > ... >>>> comb = it.combinations(dims, 2) >>>> comb_l = list(comb) >>>> comb_l > [('special', 'number'), ('special', 'letter'), ('number', 'letter')] >>>> res = map(get_products, comb_l) >>>> res > [[[('special', '+'), ('number', 1)], [('special', '+'), ('number', > 2)], [('special', '+'), ('number', 3)], [('special', '-'), ('number', > 1)], [('special', '-'), ('number', 2)], [('special', '-'), ('number', > 3)]], [[('special', '+'), ('letter', 'a')], [('special', '+'), > ('letter', 'b')], [('special', '-'), ('letter', 'a')], [('special', > '-'), ('letter', 'b')]], [[('number', 1), ('letter', 'a')], > [('number', 1), ('letter', 'b')], [('number', 2), ('letter', 'a')], > [('number', 2), ('letter', 'b')], [('number', 3), ('letter', 'a')], > [('number', 3), ('letter', 'b')]]] # the resulting list is nested one > level to deep caused by the map(get_products, .. >>>> > > My problem is that I want to get single elements from the generator > like [('special', '+'), ('number', 1)]. But this does not work because > the list is now nested to deep. Like this? >>> [(k, v) for k, vv in dims.iteritems() for v in vv] [('special', '+'), ('special', '-'), ('number', 1), ('number', 2), ('number', 3), ('letter', 'a'), ('letter', 'b')] But these are just glorified for-loops, so: >>> list(chain.from_iterable(starmap(product, izip(izip(dims.iterkeys()), dims.itervalues())))) [('special', '+'), ('special', '-'), ('number', 1), ('number', 2), ('number', 3), ('letter', 'a'), ('letter', 'b')] Peter From eric at trueblade.com Wed Dec 22 08:09:46 2010 From: eric at trueblade.com (Eric Smith) Date: Wed, 22 Dec 2010 08:09:46 -0500 Subject: [python-committers] [RELEASED] Python 3.2 beta 2 In-Reply-To: References: <4D10FDA0.7090808@python.org> Message-ID: <4D11F89A.3080103@trueblade.com> On 12/22/2010 8:46 AM, Georg Brandl wrote: > Am 22.12.2010 02:15, schrieb Nick Coghlan: >> On Wed, Dec 22, 2010 at 6:18 AM, Georg Brandl wrote: >>> Since PEP 3003, the Moratorium on Language Changes, is in effect, there >>> are no changes in Python's syntax and built-in types in Python 3.2. >> >> Minor nit - we actually did tweak a few of the builtin types a bit >> (mostly the stuff to improve Sequence ABC conformance and to make >> range objects more list-like) > > Indeed, I'll fix this wording for the next announcement. (And I will > mention SSL, sorry Antoine). If you're only going to mention some vague "some builtins had minor changes", then I'm fine with that. If you're going to enumerate all such changes, that will be a bigger job. There were 2 such changes I'm aware of: str.format_map (#6081) and the addition of alternate ("#") formatting to float, complex and decimal (#7094) __format__ methods. For this announcement I don't think it's necessary to list them all. From no.email at please.post Wed Dec 22 09:20:51 2010 From: no.email at please.post (kj) Date: Wed, 22 Dec 2010 14:20:51 +0000 (UTC) Subject: issubclass(dict, Mapping) Message-ID: In a message (<4cf97c94$0$30003$c3e8da3$5496439d at news.astraweb.com>) on a different thread, Steven D'Aprano tells me: >I suspect you're trying to make this more complicated than it actually >is. You keep finding little corner cases that expose implementation >details (such as the heap-types issue above) and leaping to the erroneous >conclusion that because you didn't understand this tiny little corner of >Python's class model, you didn't understand any of it. Python's object >model is relatively simple, but it does occasionally expose a few messy >corners. I disagree with your assessment. What you call "little corner cases" I call "fundamental", as in "you can't really call yourself competent with Python if you're ignorant about them". To use a term I first saw in an article by Joel Spolsky (http://is.gd/je42O), Python's object model is a rather "leaky abstraction". This refers to the situation in which a user is not shielded from the "implementation details". When an abstraction leaks, implementation details are no longer negligible, they cease to be "little corner cases". Here's another example, fresh from today's crop of wonders: (v. 2.7.0) >>> from collections import Mapping >>> issubclass(dict, Mapping) True >>> dict.__bases__ (,) >>> [issubclass(b, Mapping) for b in dict.__bases__] [False] So dict is a subclass of Mapping, even though none of the bases of dict is either Mapping or a subclass of Mapping. Great. I suspect this is another abstraction leak ("dict is *supposed* to be a Python class like all others, but in fact it's not *really*. You see, once upon a time..."). I conclude that, for me to understand Python's (rather leaky) object model abstraction, I have to understand its underlying implementation. Unfortunately, as far as I know, there's no other choice but to study the source code, since there's no other more readable description of this implementation. Maybe there are fewer "abstraction leaks" in 3.0... ~kj From mark at mark-fink.de Wed Dec 22 09:35:26 2010 From: mark at mark-fink.de (Mark Fink) Date: Wed, 22 Dec 2010 06:35:26 -0800 (PST) Subject: Question regarding Higher-Order-Programming in Python References: <7819f726-244a-4b6e-9cde-6bde9fe286df@30g2000yql.googlegroups.com> Message-ID: <1dc2d2aa-a352-4f71-9cbe-dffb72be17e4@i17g2000vbq.googlegroups.com> > >>> list(chain.from_iterable(starmap(product, izip(izip(dims.iterkeys()), > > dims.itervalues())))) > [('special', '+'), ('special', '-'), ('number', 1), ('number', 2), > ('number', 3), ('letter', 'a'), ('letter', 'b')] > > Peter so far I have never noticed chain.from_iterable, but many thanks to you Peter, I have now a beautiful solution to this problem. >>> from itertools import chain >>> comb = it.combinations(dims, 2) >>> l = chain.from_iterable(it.imap(get_products, comb)) >>> l.next() [('special', '+'), ('number', 1)] >>> l.next() [('special', '+'), ('number', 2)] From awilliam at whitemice.org Wed Dec 22 09:35:48 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Wed, 22 Dec 2010 09:35:48 -0500 Subject: issubclass(dict, Mapping) In-Reply-To: References: Message-ID: <1293028548.7799.39.camel@linux-yu4c.site> On Wed, 2010-12-22 at 14:20 +0000, kj wrote: > In a message (<4cf97c94$0$30003$c3e8da3$5496439d at news.astraweb.com>) > on a different thread, Steven D'Aprano tells me: > >I suspect you're trying to make this more complicated than it actually > >is. You keep finding little corner cases that expose implementation > >details (such as the heap-types issue above) and leaping to the erroneous > >conclusion that because you didn't understand this tiny little corner of > >Python's class model, you didn't understand any of it. Python's object > >model is relatively simple, but it does occasionally expose a few messy > >corners. > I disagree with your assessment. What you call "little corner > cases" I call "fundamental", as in "you can't really call yourself > competent with Python if you're ignorant about them". > To use a term I first saw in an article by Joel Spolsky > (http://is.gd/je42O), Python's object model is a rather "leaky > abstraction". This refers to the situation in which a user is not > shielded from the "implementation details". When an abstraction > leaks, implementation details are no longer negligible, they cease > to be "little corner cases". > Here's another example, fresh from today's crop of wonders: > (v. 2.7.0) > >>> from collections import Mapping > >>> issubclass(dict, Mapping) > True > >>> dict.__bases__ > (,) > >>> [issubclass(b, Mapping) for b in dict.__bases__] > [False] > So dict is a subclass of Mapping, even though none of the bases of > dict is either Mapping or a subclass of Mapping. Great. > I suspect this is another abstraction leak ("dict is *supposed* to > be a Python class like all others, but in fact it's not *really*. > You see, once upon a time..."). > I conclude that, for me to understand Python's (rather leaky) object > model abstraction, I have to understand its underlying implementation. > Unfortunately, as far as I know, there's no other choice but to > study the source code, since there's no other more readable > description of this implementation. > Maybe there are fewer "abstraction leaks" in 3.0... Boy howdy are you going to incite the ire of the Pythonistas! IMO, the "object model" isn't "leaky", it is simply "adhoc" and not really a "model" at all [write as many 800 page books as you want: if it walks like a zombie duck, smells like a zombie duck - it is still a zombie duck]. Performing introspection in Python is awful and a veritable land-mine of "implementation details". The short and honest answer is: avoid doing it whenever possible, try to figure out how to accomplish the task some other way. From solipsis at pitrou.net Wed Dec 22 09:44:01 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Wed, 22 Dec 2010 15:44:01 +0100 Subject: issubclass(dict, Mapping) References: Message-ID: <20101222154401.133e0072@pitrou.net> On Wed, 22 Dec 2010 14:20:51 +0000 (UTC) kj wrote: > > So dict is a subclass of Mapping, even though none of the bases of > dict is either Mapping or a subclass of Mapping. Great. > > I suspect this is another abstraction leak ("dict is *supposed* to > be a Python class like all others, but in fact it's not *really*. It is. You just haven't read about Python's ABCs (abstract base classes): http://docs.python.org/library/abc.html#abc.ABCMeta ? You can also register unrelated concrete classes (even built-in classes) and unrelated ABCs as ?virtual subclasses? ? these and their descendants will be considered subclasses of the registering ABC by the built-in issubclass() function, but the registering ABC won?t show up in their MRO (Method Resolution Order) nor will method implementations defined by the registering ABC be callable (not even via super()). ? With a very simple example in the register() doc: http://docs.python.org/library/abc.html#abc.ABCMeta.register Regards Antoine. From xahlee at gmail.com Wed Dec 22 09:46:34 2010 From: xahlee at gmail.com (Xah Lee) Date: Wed, 22 Dec 2010 06:46:34 -0800 (PST) Subject: Google AI challenge: planet war. Lisp won. References: <44a8f48f-e291-463e-a042-d0cbc31a2a4e@z17g2000prz.googlegroups.com> Message-ID: <1a10a457-6492-4ed6-98fd-bbb0829637c0@o23g2000prh.googlegroups.com> On Dec 20, 10:06?pm, "Jon Harrop" wrote: > Wasn't that the "challenge" where they wouldn't even accept solutions > written in many other languages (including both OCaml and F#)? Ocaml is one of the supported lang. See: http://ai-contest.com/starter_packages.php there are 12 teams using OCaml. See: http://ai-contest.com/rankings.php (click on the lang to see all teams using that lang) Xah From solipsis at pitrou.net Wed Dec 22 09:56:36 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Wed, 22 Dec 2010 15:56:36 +0100 Subject: issubclass(dict, Mapping) References: <1293028548.7799.39.camel@linux-yu4c.site> Message-ID: <20101222155636.3e46c6e7@pitrou.net> On Wed, 22 Dec 2010 09:35:48 -0500 Adam Tauno Williams wrote: > > IMO, the "object model" isn't "leaky", it is simply "adhoc" and not > really a "model" at all [write as many 800 page books as you want: if it > walks like a zombie duck, smells like a zombie duck - it is still a > zombie duck]. Performing introspection in Python is awful and a > veritable land-mine of "implementation details". Introspection is fine as long as you stick to officially promoted tools such as isinstance(), issubclass(), dir() or the inspect module. If you start looking inside the pants of the object model, you can have surprises :) Regards Antoine. From steve at holdenweb.com Wed Dec 22 10:31:06 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 22 Dec 2010 10:31:06 -0500 Subject: issubclass(dict, Mapping) In-Reply-To: References: Message-ID: On 12/22/2010 9:20 AM, kj wrote: [...] > I suspect this is another abstraction leak ("dict is *supposed* to > be a Python class like all others, but in fact it's not *really*. > You see, once upon a time..."). > So your suspicions are to be placed above the knowledge of those who really do understand Python's object model? That seems like a recipe for cargo cult programming ... > I conclude that, for me to understand Python's (rather leaky) object > model abstraction, I have to understand its underlying implementation. > Unfortunately, as far as I know, there's no other choice but to > study the source code, since there's no other more readable > description of this implementation. > You don't have to understand "the implementation" (there are at least five different implementations, which one will you choose as your standard?) > Maybe there are fewer "abstraction leaks" in 3.0... > Python deliberately exposes introspection interfaces, which you may use if you wish. As with all introspectable languages (including Java) if you push the envelope you are likely to hit corner cases. As Steven d'Aprano has already said, these *are* corner cases and not the whole of the language. Don't worry about having a complete knowledge of the language before you start to use it. That can induce paralysis ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From benedict.verheyen at gmail.com Wed Dec 22 11:04:42 2010 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Wed, 22 Dec 2010 17:04:42 +0100 Subject: compiling Python 2.7.1 with readline module fails on Debian (Virtualbox) In-Reply-To: References: Message-ID: On 22/12/2010 9:33, Benedict Verheyen wrote: > Hi, > > > i'm trying to compile Python 2.7.1 on Debian (Virtual Box). > Compiling end successfully but readline and curses fail to build. > > I'm working with virtualenv and I install all my packages in $HOME/local. > I've downloaded readline, compiled and installed it in $HOME/local, same with ncurses. > Both were the latest releases. > But somehow, Python isn't able to build them. > > I get this message: > > Failed to build these modules: > _curses _curses_panel readline > > So it does seems to find the modules. > I'm not used to dealing with configure, and make so i can't debug much. > I first tried this configure line: > ./configure --enable-shared --prefix=$HOME/local > > Next i tried this one: > env CPPFLAGS="-I$HOME/local/include" LDFLAGS="-L$HOME/local/lib" ./configure --enable-shared --prefix=$HOME/local > > But make yields the same error. > > Any clues on what I do wrong? > > The source of ncurses and readline are placed in $HOME/src. > Both packages are installed in $HOME/local > > Thanks for any advice, > > Regards, > Benedict > I found some additional info here: http://www.velocityreviews.com/forums/t733455-problem-building-python-2-7-with-enable-shared.html The error "-collect2: ld returned 1 exit status" is the same error as I'm getting. So what happens is that linking to python2.7 during make, doesn't link to the freshly build library, but to the existing in the system. Is there any solution for this? Or an option i can add to make/config? Cheers, Benedict From franapoli at gmail.com Wed Dec 22 11:22:22 2010 From: franapoli at gmail.com (Ciccio) Date: Wed, 22 Dec 2010 17:22:22 +0100 Subject: Regular expression for "key = value" pairs Message-ID: Hi all, suppose I have: s='a=b, c=d' and I want to extract sub-strings a,b,c and d from s (and in general from any longer list of such comma separated pairs). Some failed attempts: In [12]: re.findall(r'(.+)=(.+)', s) Out[12]: [('a=b, c', 'd')] In [13]: re.findall(r'(.+?)=(.+)', s) Out[13]: [('a', 'b, c=d')] In [14]: re.findall(r'(.+)=(.+)*', s) Out[14]: [('a=b, c', 'd')] In [15]: re.findall(r'(.+)=(.+),', s) Out[15]: [('a', 'b')] In [16]: re.findall(r'(.+)=(.+),?', s) Out[16]: [('a=b, c', 'd')] Thanks for your help, francesco. From cjwilliams43 at gmail.com Wed Dec 22 11:24:03 2010 From: cjwilliams43 at gmail.com (Colin J. Williams) Date: Wed, 22 Dec 2010 11:24:03 -0500 Subject: help with link parsing? In-Reply-To: <39ca82ab-1ed3-42d3-ba26-6f1915236e92@v17g2000vbo.googlegroups.com> References: <39ca82ab-1ed3-42d3-ba26-6f1915236e92@v17g2000vbo.googlegroups.com> Message-ID: On 21-Dec-10 12:22 PM, Jon Clements wrote: > import lxml > from urlparse import urlsplit > > doc = lxml.html.parse('http://www.google.com') > print map(urlsplit, doc.xpath('//a/@href')) > > [SplitResult(scheme='http', netloc='www.google.co.uk', path='/imghp', > query='hl=en&tab=wi', fragment=''), SplitResult(scheme='http', > netloc='video.google.co.uk', path='/', query='hl=en&tab=wv', > fragment=''), SplitResult(scheme='http', netloc='maps.google.co.uk', > path='/maps', query='hl=en&tab=wl', fragment=''), > SplitResult(scheme='http', netloc='news.google.co.uk', path='/nwshp', > query='hl=en&tab=wn', fragment=''), ...] Jon, What version of Python was used to run this? Colin W. From andre.roberge at gmail.com Wed Dec 22 11:36:27 2010 From: andre.roberge at gmail.com (=?ISO-8859-1?Q?Andr=E9?=) Date: Wed, 22 Dec 2010 08:36:27 -0800 (PST) Subject: Regular expression for "key = value" pairs In-Reply-To: Message-ID: <15d61e50-5bba-4241-9040-37175389095f@glegroupsg2000goo.googlegroups.com> On Wednesday, December 22, 2010 12:22:22 PM UTC-4, Francesco Napolitano wrote: > Hi all, > suppose I have: > > s='a=b, c=d' > > and I want to extract sub-strings a,b,c and d from s (and in general > from any longer list of such comma separated pairs). > Some failed attempts: > > In [12]: re.findall(r'(.+)=(.+)', s) > Out[12]: [('a=b, c', 'd')] > > In [13]: re.findall(r'(.+?)=(.+)', s) > Out[13]: [('a', 'b, c=d')] > > In [14]: re.findall(r'(.+)=(.+)*', s) > Out[14]: [('a=b, c', 'd')] > > In [15]: re.findall(r'(.+)=(.+),', s) > Out[15]: [('a', 'b')] > > In [16]: re.findall(r'(.+)=(.+),?', s) > Out[16]: [('a=b, c', 'd')] > How about the following: >>> s = 'a=b,c=d' >>> t = [] >>> for u in s.split(','): ... t.extend(u.split('=')) ... >>> t ['a', 'b', 'c', 'd'] HTH, Andr? > Thanks for your help, > francesco. From noreply at domain.invalid Wed Dec 22 11:40:21 2010 From: noreply at domain.invalid (William Gill) Date: Wed, 22 Dec 2010 11:40:21 -0500 Subject: simple games w/o pygame Message-ID: I am teaching an 11 year old who wants to learn programming. I chose Python, and it is working well. I seem to remember lots of simple script games, like quizzes, number games etc. that would be good for his tutorial. However, now all I can find is more complex games using Pygame. Can anyone help me out here? From vlastimil.brom at gmail.com Wed Dec 22 11:43:15 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Wed, 22 Dec 2010 17:43:15 +0100 Subject: Regular expression for "key = value" pairs In-Reply-To: References: Message-ID: 2010/12/22 Ciccio : > Hi all, > suppose I have: > > s='a=b, c=d' > > and I want to extract sub-strings a,b,c and d from s (and in general from > any longer list of such comma separated pairs). > Some failed attempts: > > In [12]: re.findall(r'(.+)=(.+)', s) > Out[12]: [('a=b, c', 'd')] > > [...] > Thanks for your help, > francesco. > -- > http://mail.python.org/mailman/listinfo/python-list > Hi, I am not sure, the regular expressions are best suited for this task, but if you have a predictable simple parameter list (with ho recursion, escaping commas or equal signs etc.), it might be viable; how about e.g. this pattern? >>> re.findall(r'([^=\s,]+)=([^=\s,]+)', s) [('a', 'b'), ('c', 'd')] >>> vbr From no.email at please.post Wed Dec 22 11:52:38 2010 From: no.email at please.post (kj) Date: Wed, 22 Dec 2010 16:52:38 +0000 (UTC) Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: In Robert Kern writes: >Obfuscating the location that an exception gets raised prevents a lot of >debugging... The Python interpreter does a lot of that "obfuscation" already, and I find the resulting tracebacks more useful for it. An error message is only useful to a given audience if that audience can use the information in the message to modify what they are doing to avoid the error. It is of no use (certainly no *immediate* use) to this audience to see tracebacks that go deep into code that they don't know anything about and cannot change. For example, consider this: #----------------------------------------------------------------- def foo(x, **k): pass def bar(*a, **k): if len(a) > 1: raise TypeError('too many args') def baz(*a, **k): _pre_baz(*a, **k) def _pre_baz(*a, **k): if len(a) > 1: raise TypeError('too many args') if __name__ == '__main__': from traceback import print_exc try: foo(1, 2) except: print_exc() try: bar(1, 2) except: print_exc() try: baz(1, 2) except: print_exc() #----------------------------------------------------------------- (The code in the "if __name__ == '__main__'" section is meant to simulate the general case in which the functions defined in this file are called by third-party code.) When you run this code the output is this (a few blank lines added for clarity): Traceback (most recent call last): File "/tmp/ex2.py", line 5, in try: foo(1, 2) TypeError: foo() takes exactly 1 argument (2 given) Traceback (most recent call last): File "/tmp/ex2.py", line 7, in try: bar(1, 2) File "/tmp/example.py", line 4, in bar if len(a) > 1: raise TypeError('too many args') TypeError: too many args Traceback (most recent call last): File "/tmp/ex2.py", line 9, in try: baz(1, 2) File "/tmp/example.py", line 6, in baz def baz(*a, **k): _pre_baz(*a, **k) File "/tmp/example.py", line 9, in _pre_baz if len(a) > 1: raise TypeError('too many args') TypeError: too many args In all cases, the *programming* errors are identical: functions called with the wrong arguments. The traceback from foo(1, 2) tells me this very clearly, and I'm glad that Python is not also giving me the traceback down to where the underlying C code throws the exception: I don't need to see all this machinery. In contrast, the tracebacks from bar(1, 2) and baz(1, 2) obscure the fundamental problem with useless detail. From the point of view of the programmer that is using these functions, it is of no use to know that the error resulted from some "raise TypeError" statement somewhere, let alone that this happened in some obscure, private function _pre_baz. Perhaps I should have made it clearer in my original post that the tracebacks I want to clean up are those from exceptions *explicitly* raised by my argument-validating helper function, analogous to _pre_baz above. I.e. I want that when my spam function is called (by code written by someone else) with the wrong arguments, the traceback looks more like this Traceback (most recent call last): File "/some/python/code.py", line 123, in spam(some, bad, args) TypeError: the second argument is bad than like this: Traceback (most recent call last): File "/some/python/code.py", line 123, in spam(some, bad, args) File "/my/niftymodule.py", line 456, in niftymodule _pre_spam(*a, **k) File "/my/niftymodule.py", line 789, in __pre_spam raise TypeError('second argument to spam is bad') TypeError: the second argument is bad In my opinion, the idea that more is always better in a traceback is flat out wrong. As the example above illustrates, the most useful traceback is the one that stops at the deepest point where the *intended audience* for the traceback can take action, and goes no further. The intended audience for the errors generated by my argument-checking functions should see no further than the point where they called a function incorrectly. ~kj From mdw at distorted.org.uk Wed Dec 22 11:53:43 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 22 Dec 2010 16:53:43 +0000 Subject: Regular expression for "key = value" pairs References: Message-ID: <87tyi5wxyg.fsf.mdw@metalzone.distorted.org.uk> Ciccio writes: > suppose I have: > > s='a=b, c=d' > > and I want to extract sub-strings a,b,c and d from s (and in general > from any longer list of such comma separated pairs). [...] > In [12]: re.findall(r'(.+)=(.+)', s) > Out[12]: [('a=b, c', 'd')] I think there are two logically separate jobs here: firstly, extracting the comma-separated pairs, and secondly parsing the individual pairs. If you want the extra problem of dealing with regular expressions, this seems to be the way to do it. R_PAIR = re.compile(r''' ^\s* ([^=\s]|[^=\s][^=]*[^=\s]) \s*=\s* (\S|\S.*\S) \s*$ ''', re.X) def parse_pair(pair): m = R_PAIR.match(pair) if not m: raise ValueError, 'not a `KEY = VALUE\' pair' return m.groups([1, 2]) The former is even easier. R_COMMA = re.compile(r'\s*,\s*') kvs = [parse_pair(p) for p in R_COMMA.split(string)] Apply gold-plating to taste. But actually, it's much easier to avoid messing with regular expressions at all. def parse_pair(pair): eq = pair.index('=') return pair[:eq].strip(), pair[eq + 1:].strip() kvs = [parse_pair(p) for p in string.split(',')] -- [mdw] From mdw at distorted.org.uk Wed Dec 22 11:55:27 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Wed, 22 Dec 2010 16:55:27 +0000 Subject: Regular expression for "key = value" pairs References: <15d61e50-5bba-4241-9040-37175389095f@glegroupsg2000goo.googlegroups.com> Message-ID: <87pqstwxvk.fsf.mdw@metalzone.distorted.org.uk> Andr? writes: > How about the following: > > >>> s = 'a=b,c=d' > >>> t = [] > >>> for u in s.split(','): > ... t.extend(u.split('=')) s = 'a = b = c, d = e' => ['a ', ' b ', ' c', ' d ', ' e'] Ugh. -- [mdw] From joncle at googlemail.com Wed Dec 22 11:56:11 2010 From: joncle at googlemail.com (Jon Clements) Date: Wed, 22 Dec 2010 08:56:11 -0800 (PST) Subject: help with link parsing? References: <39ca82ab-1ed3-42d3-ba26-6f1915236e92@v17g2000vbo.googlegroups.com> Message-ID: On Dec 22, 4:24?pm, "Colin J. Williams" wrote: > On 21-Dec-10 12:22 PM, Jon Clements wrote: > > > import lxml > > from urlparse import urlsplit > > > doc = lxml.html.parse('http://www.google.com') > > print map(urlsplit, doc.xpath('//a/@href')) > > > [SplitResult(scheme='http', netloc='www.google.co.uk', path='/imghp', > > query='hl=en&tab=wi', fragment=''), SplitResult(scheme='http', > > netloc='video.google.co.uk', path='/', query='hl=en&tab=wv', > > fragment=''), SplitResult(scheme='http', netloc='maps.google.co.uk', > > path='/maps', query='hl=en&tab=wl', fragment=''), > > SplitResult(scheme='http', netloc='news.google.co.uk', path='/nwshp', > > query='hl=en&tab=wn', fragment=''), ...] > > Jon, > > What version of Python was used to run this? > > Colin W. 2.6.5 - the lxml library is not a standard module though and needs to be installed. From ethan at stoneleaf.us Wed Dec 22 12:19:26 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 22 Dec 2010 09:19:26 -0800 Subject: issubclass(dict, Mapping) In-Reply-To: References: Message-ID: <4D12331E.3090007@stoneleaf.us> kj wrote: > In a message (<4cf97c94$0$30003$c3e8da3$5496439d at news.astraweb.com>) > on a different thread, Steven D'Aprano tells me: > >> I suspect you're trying to make this more complicated than it actually >> is. You keep finding little corner cases that expose implementation >> details (such as the heap-types issue above) and leaping to the erroneous >> conclusion that because you didn't understand this tiny little corner of >> Python's class model, you didn't understand any of it. Python's object >> model is relatively simple, but it does occasionally expose a few messy >> corners. > > I disagree with your assessment. What you call "little corner > cases" I call "fundamental", as in "you can't really call yourself > competent with Python if you're ignorant about them". So where on the sliding scale do you place 'competent'? It sounds to me like you are looking at 'master'. > Here's another example, fresh from today's crop of wonders: > > (v. 2.7.0) >>>> from collections import Mapping >>>> issubclass(dict, Mapping) > True >>>> dict.__bases__ > (,) >>>> [issubclass(b, Mapping) for b in dict.__bases__] > [False] Firstly, as I'm sure you know, if you don't import Mapping from collections the issubclass test fails with a NameError. Secondly, why do you care? Did you get bitten by something? Some error, or worse, silently got wrong results? (Sincere question.) > So dict is a subclass of Mapping, even though none of the bases of > dict is either Mapping or a subclass of Mapping. Great. > > I suspect this is another abstraction leak My take on abstraction leaks is when the underlying actuality shows through in a non-ignorable way -- so I ask again, how is this discrepancy making it so you can't ignore it? ~Ethan~ From post at andre-bell.de Wed Dec 22 12:30:45 2010 From: post at andre-bell.de (Andre Alexander Bell) Date: Wed, 22 Dec 2010 18:30:45 +0100 Subject: simple games w/o pygame In-Reply-To: References: Message-ID: <4D1235C5.7060504@andre-bell.de> On 22.12.2010 17:40, William Gill wrote: > I am teaching an 11 year old who wants to learn programming. I chose > Python, and it is working well. I seem to remember lots of simple > script games, like quizzes, number games etc. that would be good for his > tutorial. However, now all I can find is more complex games using > Pygame. Can anyone help me out here? Recently someone posted this link on the list, which might be interesting: http://inventwithpython.com/index.html Regards Andre From stefan.sonnenberg at pythonmeister.com Wed Dec 22 12:47:25 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Wed, 22 Dec 2010 18:47:25 +0100 Subject: compiling Python 2.7.1 with readline module fails on Debian (Virtualbox) In-Reply-To: References: Message-ID: <4D1239AD.7010907@pythonmeister.com> Am 22.12.2010 09:33, schrieb Benedict Verheyen: > Hi, > > > i'm trying to compile Python 2.7.1 on Debian (Virtual Box). > Compiling end successfully but readline and curses fail to build. > > I'm working with virtualenv and I install all my packages in $HOME/local. > I've downloaded readline, compiled and installed it in $HOME/local, same with ncurses. > Both were the latest releases. > But somehow, Python isn't able to build them. > > I get this message: > > Failed to build these modules: > _curses _curses_panel readline > > So it does seems to find the modules. > I'm not used to dealing with configure, and make so i can't debug much. > I first tried this configure line: > ./configure --enable-shared --prefix=$HOME/local > > Next i tried this one: > env CPPFLAGS="-I$HOME/local/include" LDFLAGS="-L$HOME/local/lib" ./configure --enable-shared --prefix=$HOME/local > > But make yields the same error. > > Any clues on what I do wrong? > > The source of ncurses and readline are placed in $HOME/src. > Both packages are installed in $HOME/local > > Thanks for any advice, > > Regards, > Benedict > Did you try apt-get install build-essential apt-get build-dep python2.7 before trying to compile ? Anyway, the config.log file is always of special interest. Btw, which Debian release are you running ? If the system is set up correctly it should not be necessary to change env vars to get it built. From binbrain at gmail.com Wed Dec 22 12:57:21 2010 From: binbrain at gmail.com (Jim Pharis) Date: Wed, 22 Dec 2010 12:57:21 -0500 Subject: compiling Python 2.7.1 with readline module fails on Debian (Virtualbox) In-Reply-To: References: Message-ID: are you running make clean for good measure? On Wed, Dec 22, 2010 at 3:33 AM, Benedict Verheyen < benedict.verheyen at gmail.com> wrote: > Hi, > > > i'm trying to compile Python 2.7.1 on Debian (Virtual Box). > Compiling end successfully but readline and curses fail to build. > > I'm working with virtualenv and I install all my packages in $HOME/local. > I've downloaded readline, compiled and installed it in $HOME/local, same > with ncurses. > Both were the latest releases. > But somehow, Python isn't able to build them. > > I get this message: > > Failed to build these modules: > _curses _curses_panel readline > > So it does seems to find the modules. > I'm not used to dealing with configure, and make so i can't debug much. > I first tried this configure line: > ./configure --enable-shared --prefix=$HOME/local > > Next i tried this one: > env CPPFLAGS="-I$HOME/local/include" LDFLAGS="-L$HOME/local/lib" > ./configure --enable-shared --prefix=$HOME/local > > But make yields the same error. > > Any clues on what I do wrong? > > The source of ncurses and readline are placed in $HOME/src. > Both packages are installed in $HOME/local > > Thanks for any advice, > > Regards, > Benedict > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jasons at adventureaquarium.com Wed Dec 22 13:34:16 2010 From: jasons at adventureaquarium.com (Jason Staudenmayer) Date: Wed, 22 Dec 2010 13:34:16 -0500 Subject: Code review request Message-ID: Hi All, I'm a python newbie so please be kind. I've been reading book after book and have written a script or two but this is my first real "program". Just looking for any suggestions and pointers. I've done some work with bash scripts and php (not OOP) a while a go. I'm not a programmer but would like to possibly expand in to it (right now an IT guy). Am I on the right track so far? The program should be documented enough to explain. """ Created on Tue Dec 21 13:39:41 2010 @author: jason Usage: cmd_drug_testing.py [options]... Will select a random employee from the local database (located in the current directory) and display the name by default. This program (Drug Testing) was written to help select employees for drug testing. Program usage: -h, --help Displays this help info -l, --list-emplys Lists all employees in the database -s, --select Select employee for testing -r, --remove-emply Delete employee from database, usage: -d employee_name or id -e, --edit-emply Edit employee data in database, usage: -e employee_name or id field_to_change new_value -i, --insert-emply Insert new employee in database: must fit this format -- "id:or '','lastname, firstname', 'email',0" -f Display database name and full path This program was written by, Jason S. For the use of AA. """ # import our needed modules import sqlite3 as sqlite import sys, getopt #set global vars global cursor global conn def usage(): """ this just prints the usage in the doc string""" print __doc__ def dbconnect(sql): """handel the connction to the sqlite db """ dbConnection = sqlite.connect("drug-test.db") #set the cursor cursor = dbConnection.cursor() try: #execute the sql passed from the other funtions and return the results result = cursor.execute(sql) dbConnection.commit() except sqlite.Error, e: result = e.args[0] return result def listEmployees(sql): #list all records in the database listemp = dbconnect(sql) for lst in listemp: print "%s, %s, %s, %s" % (lst[0],lst[1],lst[2],lst[3]) def selectOneEmployee(sql): #select a random record from the database listemp = dbconnect(sql) for empl in listemp: print empl[0] def removeOneEmployee(sqlchk,sqldel): #delete one employee by ID number chk = dbconnect(sqlchk) if chk.fetchone() != None: #check to make sure the ID is valid in the database emply = dbconnect(sqlchk) emply = emply.fetchall() print "trying to remove employee %s" % (emply) try: dbconnect(sqldel) except sqlite.Error, e: result = e.args[0] print result else: print "Employees ID is invalid, please check the ID number" def insertEmployee(sql): #insert a new employee into the database print sql try: dbconnect(sql) except sqlite.Error, e: result = e.args[0] print result def main(argv): """The purpose of this program is to select an empployee from this database for random drug testing. This program can also perform maintainance on same database.""" if argv == []: sql = "SELECT name FROM employees ORDER BY RANDOM() LIMIT 1;" print "The following employee has been selected\n" selectOneEmployee(sql) try: #get the options passed by the user opts, args = getopt.getopt(argv, "hlsr:e:i:d",["Help","list-emplys","select","remove-emply=","edit-emply=","insert-emply="]) except getopt.GetoptError: usage() sys.exit(2) #check throught the options and respond accordingly for opt, arg in opts: if opt in ("-h", "--help"): usage() sys.exit() elif opt == '-d': global _debug _debug = 1 elif opt in ("-l", "--list-emplys"): sql = "select * from employees" listEmployees(sql) elif opt in ("-s","--select"): sql = "SELECT name FROM employees ORDER BY RANDOM() LIMIT 1;" print "The following employee has been selected\n" selectOneEmployee(sql) elif opt in ("-r","--remove-emply"): if arg == "": sys.exit("You must provice the ID for the employee to remove") sqlchk = "select * from employees where id = \"%s\"" % (arg) sqldel = "delete from employees where id = \"%s\"" % (arg) removeOneEmployee(sqlchk,sqldel) elif opt in ("-i", "--insert-emply"): sql = "insert into employees values(%s)" % (arg) insertEmployee(sql) if __name__ == "__main__": main(sys.argv[1:]) ########## END ################### Thanks everyone. Jason ..?><((((?> From mpnordland at gmail.com Wed Dec 22 14:28:31 2010 From: mpnordland at gmail.com (mpnordland) Date: Wed, 22 Dec 2010 11:28:31 -0800 (PST) Subject: Catching user switching and getting current active user from root on linux References: <3d190cbf-be7d-4973-b85f-c030bb258742@glegroupsg2000goo.googlegroups.com> Message-ID: ok, I'll give one more chance. First, to pacify those who hate google groups: What is a good usenet client? second, How should I set up this proxy so that when a connection is made, it request's authentication, and then log's the request, if authentication is not gotten, how do I have it block (or firewall) the request? Furthermore, I would like for the proxy to be squid. So all of the nitty gritty should have to do with squid. From stefan.sonnenberg at pythonmeister.com Wed Dec 22 15:24:24 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Wed, 22 Dec 2010 21:24:24 +0100 Subject: Code review request In-Reply-To: References: Message-ID: <4D125E78.10408@pythonmeister.com> Am 22.12.2010 19:34, schrieb Jason Staudenmayer: > Hi All, > I'm a python newbie so please be kind. I've been reading book after book and have written a script or two but this is my first real "program". Just looking for any suggestions and pointers. I've done some work with bash scripts and php (not OOP) a while a go. I'm not a programmer but would like to possibly expand in to it (right now an IT guy). Am I on the right track so far? > > The program should be documented enough to explain. > > """ > Created on Tue Dec 21 13:39:41 2010 > @author: jason > > Usage: cmd_drug_testing.py [options]... > Will select a random employee from the local database (located in the current directory) > and display the name by default. > > This program (Drug Testing) was written to help select employees for drug testing. > Program usage: > > -h, --help Displays this help info > -l, --list-emplys Lists all employees in the database > -s, --select Select employee for testing > -r, --remove-emply Delete employee from database, usage: -d employee_name or id > -e, --edit-emply Edit employee data in database, usage: -e employee_name or id > field_to_change new_value > -i, --insert-emply Insert new employee in database: > must fit this format -- "id:or '','lastname, firstname', 'email',0" > -f Display database name and full path > > This program was written by, Jason S. For the use of AA. > > """ > > # import our needed modules > import sqlite3 as sqlite > import sys, getopt > > #set global vars > global cursor > global conn > > > def usage(): > """ this just prints the usage in the doc string""" > print __doc__ > > def dbconnect(sql): > """handel the connction to the sqlite db """ > dbConnection = sqlite.connect("drug-test.db") > #set the cursor > cursor = dbConnection.cursor() > try: > #execute the sql passed from the other funtions and return the results > result = cursor.execute(sql) > dbConnection.commit() > except sqlite.Error, e: > result = e.args[0] > > return result > > > def listEmployees(sql): > #list all records in the database > listemp = dbconnect(sql) > for lst in listemp: > print "%s, %s, %s, %s" % (lst[0],lst[1],lst[2],lst[3]) > > def selectOneEmployee(sql): > #select a random record from the database > listemp = dbconnect(sql) > for empl in listemp: > print empl[0] > > def removeOneEmployee(sqlchk,sqldel): > #delete one employee by ID number > chk = dbconnect(sqlchk) > > if chk.fetchone() != None: > #check to make sure the ID is valid in the database > emply = dbconnect(sqlchk) > emply = emply.fetchall() > print "trying to remove employee %s" % (emply) > try: > dbconnect(sqldel) > > except sqlite.Error, e: > result = e.args[0] > print result > > else: > print "Employees ID is invalid, please check the ID number" > > def insertEmployee(sql): > #insert a new employee into the database > print sql > try: > dbconnect(sql) > > except sqlite.Error, e: > result = e.args[0] > print result > > def main(argv): > """The purpose of this program is to select an empployee from this database for random drug > testing. This program can also perform maintainance on same database.""" > if argv == []: > sql = "SELECT name FROM employees ORDER BY RANDOM() LIMIT 1;" > print "The following employee has been selected\n" > selectOneEmployee(sql) > > try: > #get the options passed by the user > opts, args = getopt.getopt(argv, "hlsr:e:i:d",["Help","list-emplys","select","remove-emply=","edit-emply=","insert-emply="]) > > except getopt.GetoptError: > usage() > sys.exit(2) > > #check throught the options and respond accordingly > for opt, arg in opts: > if opt in ("-h", "--help"): > usage() > sys.exit() > elif opt == '-d': > global _debug > _debug = 1 > elif opt in ("-l", "--list-emplys"): > sql = "select * from employees" > listEmployees(sql) > elif opt in ("-s","--select"): > sql = "SELECT name FROM employees ORDER BY RANDOM() LIMIT 1;" > print "The following employee has been selected\n" > selectOneEmployee(sql) > elif opt in ("-r","--remove-emply"): > if arg == "": > > sys.exit("You must provice the ID for the employee to remove") > sqlchk = "select * from employees where id = \"%s\"" % (arg) > sqldel = "delete from employees where id = \"%s\"" % (arg) > removeOneEmployee(sqlchk,sqldel) > elif opt in ("-i", "--insert-emply"): > sql = "insert into employees values(%s)" % (arg) > insertEmployee(sql) > > if __name__ == "__main__": > main(sys.argv[1:]) > > ########## END ################### > > Thanks everyone. > > > Jason > > > > ..?><((((?> Hi Jason, the program could be more dense. You have several redundant code in there, too. For example, all the *Employee functions basically just call dbconnect and let it execute the sql there. dbconnect in this respect is not a really straight name, as it does more than only connect to a database. You should avoid "!= None", better is "is not None". The program flow is "awkward": if argv is empty (better say "if not argv"), you show one employee, but then continue to parse opts. I think the program would be more readable, if you would just handle the different cases in an if-elseif-else-cascade. The global statement is not needed, But you can also try pylint, which will point some things out: Report 78 statements analysed. Statistics by type type number old number difference %documented %badname module 1 1 = 100.00 0.00 class 0 0 = 0 0 method 0 0 = 0 0 function 7 7 = 42.86 57.14 Duplication now previous difference nb duplicated lines 0 0 = percent duplicated lines 0.000 0.000 = Raw metrics type number % previous difference code 75 60.98 75 = docstring 31 25.20 31 = comment 3 2.44 3 = empty 14 11.38 14 = External dependencies getopt (cmd_drug_testing) sqlite3 (cmd_drug_testing) Messages by category type number previous difference convention 23 23 = refactor 0 0 = warning 4 4 = error 0 0 = Messages message id occurrences C0103 8 C0301 7 C0324 4 C0111 4 W0604 2 W0612 1 W0601 1 Global evaluation Your code has been rated at 6.54/10 (previous run: 6.54/10) Messages type module object line message C cmd_drug_testing 6 Line too long (88/80) C cmd_drug_testing 9 Line too long (82/80) C cmd_drug_testing 15 Line too long (89/80) C cmd_drug_testing 16 Line too long (91/80) C cmd_drug_testing 19 Line too long (99/80) C cmd_drug_testing 96 Line too long (95/80) C cmd_drug_testing 105 Line too long (132/80) W cmd_drug_testing 31 Using the global statement at the module level W cmd_drug_testing 32 Using the global statement at the module level C cmd_drug_testing dbconnect 41 Invalid name "dbConnection" (should match [a-z_][a-z0-9_]{2,30}$) C cmd_drug_testing dbconnect 48 Invalid name "e" (should match [a-z_][a-z0-9_]{2,30}$) C cmd_drug_testing listEmployees 54 Invalid name "listEmployees" (should match [a-z_][a-z0-9_]{2,30}$) C cmd_drug_testing listEmployees 54 Missing docstring C cmd_drug_testing listEmployees 58 Comma not followed by a space print "%s, %s, %s, %s" % (lst[0],lst[1],lst[2],lst[3]) ^^ C cmd_drug_testing selectOneEmployee 60 Invalid name "selectOneEmployee" (should match [a-z_][a-z0-9_]{2,30}$) C cmd_drug_testing selectOneEmployee 60 Missing docstring C cmd_drug_testing removeOneEmployee 66 Invalid name "removeOneEmployee" (should match [a-z_][a-z0-9_]{2,30}$) C cmd_drug_testing removeOneEmployee 66 Missing docstring C cmd_drug_testing removeOneEmployee 66 Comma not followed by a space def removeOneEmployee(sqlchk,sqldel): ^^ C cmd_drug_testing removeOneEmployee 78 Invalid name "e" (should match [a-z_][a-z0-9_]{2,30}$) C cmd_drug_testing insertEmployee 85 Invalid name "insertEmployee" (should match [a-z_][a-z0-9_]{2,30}$) C cmd_drug_testing insertEmployee 85 Missing docstring C cmd_drug_testing insertEmployee 91 Invalid name "e" (should match [a-z_][a-z0-9_]{2,30}$) C cmd_drug_testing main 105 Comma not followed by a space opts, args = getopt.getopt(argv, "hlsr:e:i:d",["Help","list-emplys","select","remove-emply=","edit-emply=","insert-emply="]) ^^ W cmd_drug_testing main 117 Global variable '_debug' undefined at the module level C cmd_drug_testing main 132 Comma not followed by a space removeOneEmployee(sqlchk,sqldel) ^^ W cmd_drug_testing main 105 Unused variable 'args' -------------- next part -------------- An HTML attachment was scrubbed... URL: From gerald.britton at gmail.com Wed Dec 22 15:29:18 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Wed, 22 Dec 2010 15:29:18 -0500 Subject: Code review request Message-ID: Hi Jason, There are a couple of things that I noticed: 1. You might want to check out PEP 8 -- a Python style guide. Among other things, some lines are very long and you are not consistent with putting a space after a comma in a list or between arguments in a function call. e.g. opts, args = getopt.getopt(argv, "hlsr:e:i:d",["Help","list-emplys","select","remove-emply=","edit-emply=","insert-emply="]) That's 125 characters, not including the indentation! You can break it up and even make it more readable like this: opts, args = getopt.getopt( argv, "hlsr:e:i:d", ["Help","list-emplys","select","remove-emply=","edit-emply=","insert-emply="] ) but then the embedded list is still too long. It can also be split like this: opts, args = getopt.getopt( argv, "hlsr:e:i:d", ["Help", "list-emplys", "select", "remove-emply=", "edit-emply=", "insert-emply="] ) Just do it so that it's easy to read and support. Notice the commas are followed by spaces in the list. In the listEmployees function (check out PEP 8 about naming conventions, while you're at it!) there is one line that could be simpler: print "%s, %s, %s, %s" % (lst[0],lst[1],lst[2],lst[3]) could be: print "%s, %s, %s, %s" % tuple(lst[:4]) or if the number of elements could be more or less, you could even do this: for item in lst: print item, which should do the same thing (the trailing comma suppresses the new line) and you'll never have to count the number of items in lst. You also have some statements like: sqlchk = "select * from employees where id = \"%s\"" % (arg) Since a Python list can be enclosed in apostrophes as well as quotations, you can get the same thing without the escapes: sqlchk = 'select * from employees where id = "%s"' % (arg) Anyway -- just some food for thought. -- Gerald Britton From jasons at adventureaquarium.com Wed Dec 22 15:43:52 2010 From: jasons at adventureaquarium.com (Jason Staudenmayer) Date: Wed, 22 Dec 2010 15:43:52 -0500 Subject: [SPAM] - Re: Code review request In-Reply-To: <4D125E78.10408@pythonmeister.com> Message-ID: -----Original Message----- From: python-list-bounces+jasons=adventureaquarium.com at python.org [mailto:python-list-bounces+jasons=adventureaquarium.com at python.org] On Behalf Of Stefan Sonnenberg-Carstens Sent: Wednesday, December 22, 2010 3:24 PM To: python-list at python.org Subject: [SPAM] - Re: Code review request Am 22.12.2010 19:34, schrieb Jason Staudenmayer: Hi All, Hi Jason, the program could be more dense. You have several redundant code in there, too. For example, all the *Employee functions basically just call dbconnect and let it execute the sql there. dbconnect in this respect is not a really straight name, as it does more than only connect to a database. You should avoid "!= None", better is "is not None". The program flow is "awkward": if argv is empty (better say "if not argv"), you show one employee, but then continue to parse opts. I think the program would be more readable, if you would just handle the different cases in an if-elseif-else-cascade. The global statement is not needed, But you can also try pylint, which will point some things out: Report 78 statements analysed. Thanks for the advice, I'll try to rework some of those issues. I did try the if-elif-else for the getopts but it didn't flow right for some reason (I'll try it again though). Thanks again. Jason ..?><((((?> From python at mrabarnett.plus.com Wed Dec 22 15:44:09 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 22 Dec 2010 20:44:09 +0000 Subject: Code review request In-Reply-To: References: Message-ID: <4D126319.4040306@mrabarnett.plus.com> > """ > Created on Tue Dec 21 13:39:41 2010 > @author: jason > > Usage: cmd_drug_testing.py [options]... > Will select a random employee from the local database (located in the current directory) > and display the name by default. > > This program (Drug Testing) was written to help select employees for drug testing. > Program usage: > > -h, --help Displays this help info > -l, --list-emplys Lists all employees in the database > -s, --select Select employee for testing > -r, --remove-emply Delete employee from database, usage: -d employee_name or id > -e, --edit-emply Edit employee data in database, usage: -e employee_name or id > field_to_change new_value > -i, --insert-emply Insert new employee in database: > must fit this format -- "id:or '','lastname, firstname', 'email',0" > -f Display database name and full path > > This program was written by, Jason S. For the use of AA. > > """ > > # import our needed modules > import sqlite3 as sqlite > import sys, getopt > > #set global vars > global cursor > global conn > By default, if you bind (assign) to a name inside a function then Python assumes that the name is local to the function, unless you tell it otherwise with "global". Using "global" outside a function has no effect. > > def usage(): > """ this just prints the usage in the doc string""" > print __doc__ > > def dbconnect(sql): > """handel the connction to the sqlite db """ "handel the connction" -> "handle the connection" > dbConnection = sqlite.connect("drug-test.db") > #set the cursor > cursor = dbConnection.cursor() > try: > #execute the sql passed from the other funtions and return the results "funtions" -> "functions" > result = cursor.execute(sql) > dbConnection.commit() > except sqlite.Error, e: > result = e.args[0] > > return result > The Pythonic way is to return a result when successful and raise an exception when unsuccessful. > > def listEmployees(sql): > #list all records in the database > listemp = dbconnect(sql) > for lst in listemp: > print "%s, %s, %s, %s" % (lst[0],lst[1],lst[2],lst[3]) > I wouldn't pass in an SQL string. I'd pass in only the parameters (if any) and hide the SQL details inside the function, something like this: def listEmployees(): # list all records in the database dbConnection = sqlite.connect(DB_NAME) try: try: results = dbConnection.execute("select * from employees") for lst in results: print "%s, %s, %s, %s" % (lst[0], lst[1], lst[2], lst[3]) except sqlite.Error, e: print "ERROR:", e.args[0] finally: dbConnection.close() I'd also be explicit about the names of the fields in the database in case their order changed in a later version. > def selectOneEmployee(sql): > #select a random record from the database > listemp = dbconnect(sql) > for empl in listemp: > print empl[0] > def selectOneEmployee(): # select a random record from the database dbConnection = sqlite.connect(DB_NAME) try: try: results = dbConnection.execute("SELECT name FROM employees ORDER BY RANDOM() LIMIT 1;") print "The following employee has been selected\n" for empl in results: print empl[0] except sqlite.Error, e: print "ERROR:", e.args[0] finally: dbConnection.close() > def removeOneEmployee(sqlchk,sqldel): > #delete one employee by ID number > chk = dbconnect(sqlchk) > > if chk.fetchone() != None: > #check to make sure the ID is valid in the database > emply = dbconnect(sqlchk) > emply = emply.fetchall() > print "trying to remove employee %s" % (emply) > try: > dbconnect(sqldel) > > except sqlite.Error, e: > result = e.args[0] > print result > > else: > print "Employees ID is invalid, please check the ID number" > > sqlchk = > sqldel = "delete from employees where id = \"%s\"" % (arg) I'd do: def removeOneEmployee(emplyId): # delete one employee by ID number dbConnection = sqlite.connect(DB_NAME) try: try: # check to make sure the ID is valid in the database results = dbConnection.execute("select * from employees where id = %s", (emplyId, )) if results.fetchone(): print "trying to remove employee %s" % emplyId dbConnection.execute("delete from employees where id = %s", (emplyId, )) dbConnection.commit() else: print "Employees ID is invalid, please check the ID number" except sqlite.Error, e: print "ERROR:", e.args[0] finally: dbConnection.close() Note that it's a very bad idea to build an SQL command yourself because of the risk of SQL injection attacks. The .execute method can do it for you safely. > def insertEmployee(sql): > #insert a new employee into the database > print sql > try: > dbconnect(sql) > > except sqlite.Error, e: > result = e.args[0] > print result > I'd do: def insertEmployee(details): # insert a new employee into the database # parse the details provided into a tuple which can be passed to the .execute method emplyDet = parse_details(details) print emplyDet dbConnection = sqlite.connect(DB_NAME) try: try: dbConnection.execute("insert into employees values (%s)", emplyDet) dbConnection.commit() else: print "Employees ID is invalid, please check the ID number" except sqlite.Error, e: print "ERROR:", e.args[0] finally: dbConnection.close() I wouldn't pass the details from the commandline without parsing and tidying them first. I'd also specify the fields explicitly in the SQL command. > def main(argv): > """The purpose of this program is to select an empployee from this database for random drug > testing. This program can also perform maintainance on same database.""" "empployee" -> "employee" "maintainance" -> "maintenance" > if argv == []: > sql = "SELECT name FROM employees ORDER BY RANDOM() LIMIT 1;" > print "The following employee has been selected\n" > selectOneEmployee(sql) > > try: > #get the options passed by the user > opts, args = getopt.getopt(argv, "hlsr:e:i:d",["Help","list-emplys","select","remove-emply=","edit-emply=","insert-emply="]) > > except getopt.GetoptError: > usage() > sys.exit(2) > > #check throught the options and respond accordingly "throught" -> "through" > for opt, arg in opts: > if opt in ("-h", "--help"): > usage() > sys.exit() It's probably better to return from main instead of exiting. > elif opt == '-d': > global _debug > _debug = 1 _debug isn't used anywhere else; it's not even initialised to 0. Incidentally, if it has only 2 possible values then it's better to use False and True instead of 0 and 1. > elif opt in ("-l", "--list-emplys"): > sql = "select * from employees" > listEmployees(sql) > elif opt in ("-s","--select"): > sql = "SELECT name FROM employees ORDER BY RANDOM() LIMIT 1;" > print "The following employee has been selected\n" > selectOneEmployee(sql) I'd do: selectOneEmployee() and keep the SQL details hidden. > elif opt in ("-r","--remove-emply"): > if arg == "": > > sys.exit("You must provice the ID for the employee to remove") "provice" -> "provide" > sqlchk = "select * from employees where id = \"%s\"" % (arg) > sqldel = "delete from employees where id = \"%s\"" % (arg) > removeOneEmployee(sqlchk,sqldel) I'd do: removeOneEmployee(arg) and keep the SQL details hidden. > elif opt in ("-i", "--insert-emply"): > sql = "insert into employees values(%s)" % (arg) > insertEmployee(sql) I'd do: insertEmployee(arg) and keep the SQL details hidden. > > if __name__ == "__main__": > main(sys.argv[1:]) From cronoklee at gmail.com Wed Dec 22 15:45:38 2010 From: cronoklee at gmail.com (cronoklee) Date: Wed, 22 Dec 2010 12:45:38 -0800 (PST) Subject: Newbie question about importing modules. In-Reply-To: Message-ID: <1a95684f-754e-4a01-849f-e476d078c723@glegroupsg2000goo.googlegroups.com> On Wed, Dec 22, 2010 at 7:57 PM, Tim Roberts wrote: cronoklee wrote: > > Thanks Tim - You've certainly shed some light. I presume the PIL > installer is setup.py and installation is simple a case of running it? Yes: python setup.py install That scheme is called "distutils". Since it became part of the standard Python distribution many years ago, it is now ubiquitous. > Is this usually the case for python 'source distribution' packages? Yes. In the Linux world, with a few exceptions, EVERY Python add-on package is installed that way. In the Windows world, most smaller packages come that way. Larger packages will have an MSI installer that does essentially the same thing. Once in a while, you'll download a script that consists only of a single file. That would really be the only exception. > Is there a term for packages that do not need to be installed? This > might help me search for them in future. I don't think that's the right answer. The installation process is rarely more complicated than copying files to the site-packages directory of your current Python version. The installer can verify dependencies and make sure everything is OK. It's a Good Thing. -- Tim Roberts Thanks a lot Tim - all makes sense. I appreciate the lesson! cronoklee From sjmachin at lexicon.net Wed Dec 22 15:51:42 2010 From: sjmachin at lexicon.net (John Machin) Date: Wed, 22 Dec 2010 12:51:42 -0800 (PST) Subject: Modifying an existing excel spreadsheet References: Message-ID: <110bfe76-0ff3-4f31-bb8e-1d981c854afb@c13g2000prc.googlegroups.com> On Dec 21, 8:56?am, Ed Keith wrote: > I have a user supplied 'template' Excel spreadsheet. I need to create a new excel spreadsheet based on the supplied template, with data filled in. > > I found the tools herehttp://www.python-excel.org/,?andhttp://sourceforge.net/projects/pyexcelerator/. I have been trying to use the former, since the latter seems to be devoid of documentation (not even any docstrings). pyExcelerator is abandonware. Use xlwt instead; it's a bug-fixed/ maintained/enhanced fork of pyExcelerator Read the tutorial that you'll find mentioned on http://www.python-excel.org Join the google group that's also mentioned there; look at past questions, ask some more, ... From emile at fenx.com Wed Dec 22 16:06:18 2010 From: emile at fenx.com (Emile van Sebille) Date: Wed, 22 Dec 2010 13:06:18 -0800 Subject: Catching user switching and getting current active user from root on linux In-Reply-To: References: <3d190cbf-be7d-4973-b85f-c030bb258742@glegroupsg2000goo.googlegroups.com> Message-ID: On 12/22/2010 11:28 AM mpnordland said... > ok, I'll give one more chance. ... which probably won't be enough -- this is potentially a huge question you're asking with lots of little bits to put together. I have an installation where I did somthing similar seven-ish years ago using squid, squidguard, blacklists from Universit? Toulouse in France, python, iptables, sql, php, zope, bash, and who knows what else. It authenticates, logs, tracks, blocks, unblocks, reports activity on an automated In and Out board by user, provides historical stats, automates new user setup and invalidation, and probably more. I put maybe a week or two into it initially, and about the same again over the years adding to it. > First, to pacify those who hate google groups: What is a good usenet > client? I use thunderbird to access gmane groups. > second, How should I set up this proxy so that when a connection is > made, it request's authentication, and then log's the request, if > authentication is not gotten, how do I have it block (or firewall) the > request? Furthermore, I would like for the proxy to be squid. So all > of the nitty gritty should have to do with squid. ... and that's where I'd start looking. Check out the current status of Squid to see how much of what you want can be done out of the box. When you hit the limits of what it'll do for you, start writing glue to fill in the puzzle. HTH, Emile From steve at holdenweb.com Wed Dec 22 16:20:54 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 22 Dec 2010 16:20:54 -0500 Subject: Catching user switching and getting current active user from root on linux In-Reply-To: References: <3d190cbf-be7d-4973-b85f-c030bb258742@glegroupsg2000goo.googlegroups.com> Message-ID: On 12/22/2010 2:28 PM, mpnordland wrote: > ok, I'll give one more chance. > First, to pacify those who hate google groups: What is a good usenet > client? Thunderbird is OK for me (I follow about three groups normally). I access the comp.lang.python group vie the Gmane ("Main") service, where for some strange resaon best known to the gmane admins it is called gmane.comp.python.general. Ho, hum. I seem to remember Outlook Express was a fairly decent NNTP client as well, and Tim Peters says I'm not just blowing smoke up your ass. > second, How should I set up this proxy so that when a connection is > made, it request's authentication, and then log's the request, if > authentication is not gotten, how do I have it block (or firewall) the > request? Furthermore, I would like for the proxy to be squid. So all > of the nitty gritty should have to do with squid. I would recommend you take a look at the Spambayes code, which does all that sort of stuff apparently quite reliably. If you aren't yet proficient enough with Python to understand the code on your own look for a Python Meetup or a local or regional conference to meet people who will helpyou answer your questions. Increasingly there are workspaces like HacDC springing up to give people access to advanced technologies at everyday prices. You could look for such a group locally. There's lots of energy from people once they realise that what gets built can help them. Squid is a different matter. For that, probably if you go on an IRC channel (freenode.net is what I use, but others have their favorites). Maybe #squid? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From secris1 at gmail.com Wed Dec 22 16:43:36 2010 From: secris1 at gmail.com (Sean) Date: Wed, 22 Dec 2010 13:43:36 -0800 (PST) Subject: Python Web App Message-ID: <907fa80e-1814-4ddb-be32-ec14cfd53fab@29g2000yqq.googlegroups.com> Anybody know where I can find a Python Development Environment in the form of a web app for use with Chrome OS. I have been looking for a few days and all i have been able to find is some old discussions with python developers talking about they will want one for the OS to be a success with them. From arnodel at gmail.com Wed Dec 22 16:45:12 2010 From: arnodel at gmail.com (Arnaud Delobelle) Date: Wed, 22 Dec 2010 21:45:12 +0000 Subject: Question regarding Higher-Order-Programming in Python References: <7819f726-244a-4b6e-9cde-6bde9fe286df@30g2000yql.googlegroups.com> <1dc2d2aa-a352-4f71-9cbe-dffb72be17e4@i17g2000vbq.googlegroups.com> Message-ID: <87sjxpa3dj.fsf@gmail.com> Mark Fink writes: > so far I have never noticed chain.from_iterable, but many thanks to > you Peter, I have now a beautiful solution to this problem. >>>> from itertools import chain >>>> comb = it.combinations(dims, 2) >>>> l = chain.from_iterable(it.imap(get_products, comb)) You can also write this as: l = (p for c in comb for p in get_products(c)) >>>> l.next() > [('special', '+'), ('number', 1)] >>>> l.next() > [('special', '+'), ('number', 2)] Also in your original post you define get_products: >>>> def get_products(keys): > ... # helper to get products from keys in the following form: > ... # [('bold', True), ('color', 'black')] > ... values = itemgetter(*keys)(dims) > ... product = it.product(*values) > ... return map(partial(zip, keys), product) > ... You could define it as e.g. def get_products(keys): key_values = [[(k, v) for v in values] for k in keys] return it.product(*key_values) But maybe for some reason you are trying to avoid list comprehensions and generator expressions? -- Arnaud From pavlovevidence at gmail.com Wed Dec 22 16:53:20 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 22 Dec 2010 13:53:20 -0800 (PST) Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> On Dec 22, 8:52?am, kj wrote: > In Robert Kern writes: > > >Obfuscating the location that an exception gets raised prevents a lot of > >debugging... > > The Python interpreter does a lot of that "obfuscation" already, and I > find the resulting tracebacks more useful for it. > > An error message is only useful to a given audience if that audience > can use the information in the message to modify what they are > doing to avoid the error. So when the audience files a bug report it's not useful for them to include the whole traceback? > ?It is of no use (certainly no *immediate* > use) to this audience to see tracebacks that go deep into code that > they don't know anything about and cannot change. Seriously, quit trying to do the user favors. There's nothing that pisses me off than a self-important developer thinking he knows what the user wants more than the user does. Carl Banks From steve+comp.lang.python at pearwood.info Wed Dec 22 17:05:27 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Dec 2010 22:05:27 GMT Subject: Catching user switching and getting current active user from root on linux References: <3d190cbf-be7d-4973-b85f-c030bb258742@glegroupsg2000goo.googlegroups.com> Message-ID: <4d127627$0$29997$c3e8da3$5496439d@news.astraweb.com> On Mon, 20 Dec 2010 20:35:54 -0500, Steve Holden wrote: > On 12/20/2010 12:54 PM, mpnordland wrote: >> I give up, I will never try to use a usenet group again. For the ones >> of you who tried to help thank you. You helped to identify some of my >> troubles, as for you @usernet, you are a troll > > Don't give up after one experience. Usenet can be really useful as long > as you know who to listen to and who to ignore ... More importantly, Usenet can be very useful so long as you know how to ask smart questions. If you insist on asking stupid questions, you will rapidly get disillusioned: people will either ignore you, abuse you, or give you helpful advice that you don't want to hear. -- Steven From nagle at animats.com Wed Dec 22 17:28:31 2010 From: nagle at animats.com (John Nagle) Date: Wed, 22 Dec 2010 14:28:31 -0800 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: Message-ID: <4d127b8c$0$44035$742ec2ed@news.sonic.net> On 12/20/2010 12:33 PM, Adam Tauno Williams wrote: > On Mon, 2010-12-20 at 12:29 -0800, spaceman-spiff wrote: >> I need to detect them& then for each 1, i need to copy all the >> content b/w the element's start& end tags& create a smaller xml >> file. > > Yep, do that a lot; via iterparse. > >> 1. Can you point me to some examples/samples of using SAX, >> especially , ones dealing with really large XML files. I've just subclassed HTMLparser for this. It's slow, but 100% Python. Using the SAX parser is essentially equivalent. I'm processing multi-gigabyte XML files and updating a MySQL database, so I do need to look at all the entries, but don't need a parse tree of the XML. > SaX is equivalent to iterparse (iterpase is a way, to essentially, do > SaX-like processing). Iterparse does try to build a tree, although you can discard the parts you don't want. If you can't decide whether a part of the XML is of interest until you're deep into it, an "iterparse" approach may result in a big junk tree. You have to keep clearing the "root" element to discard that. > I provided an iterparse example already. See the Read_Rows method in > I don't quite see the point of creating a class with only static methods. That's basically a verbose way to create a module. > >> 2.This brings me to another q. which i forgot to ask in my OP(original post). >> Is simply opening the file,& using reg ex to look for the element i need, a *good* approach ? > > No. If the XML file has a very predictable structure, that may not be a bad idea. It's not very general, but if you have some XML file that's basically fixed format records using XML to delimit the fields, pounding on the thing with a regular expression is simple and fast. John Nagle From stefan.sonnenberg at pythonmeister.com Wed Dec 22 17:29:02 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Wed, 22 Dec 2010 23:29:02 +0100 Subject: Catching user switching and getting current active user from root on linux In-Reply-To: References: <3d190cbf-be7d-4973-b85f-c030bb258742@glegroupsg2000goo.googlegroups.com> Message-ID: <4D127BAE.1090500@pythonmeister.com> Am 22.12.2010 20:28, schrieb mpnordland: > ok, I'll give one more chance. > First, to pacify those who hate google groups: What is a good usenet > client? > second, How should I set up this proxy so that when a connection is > made, it request's authentication, and then log's the request, if > authentication is not gotten, how do I have it block (or firewall) the > request? Furthermore, I would like for the proxy to be squid. So all > of the nitty gritty should have to do with squid. Just install Squid, enable user authentication and grant access only to authenticated people. Now, configure logrotated and tell to rotate logs every day/week/month (your mileage will vary). After rotating run a program such as webalizer to get stats (even on a per user basis). If you have smart guys under your users, set up a) a transparent proxy intercepting http/https requests or b) set up a iptables firewall with redirection to the squid port. There are many, many, many how-to documents on the net describing exactly what you want to do. A first starting point could be http://www.comfsm.fm/computing/squid/FAQ.html And your problems are solved a long time ago: http://www.faqs.org/docs/Linux-mini/TransparentProxy.html And, the most important thing: Check your local laws for this intention. Some, like our german law, require these things to be under clear rules. Cheers From tjreedy at udel.edu Wed Dec 22 17:33:30 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 22 Dec 2010 17:33:30 -0500 Subject: issubclass(dict, Mapping) In-Reply-To: References: Message-ID: On 12/22/2010 9:20 AM, kj wrote: >>>> from collections import Mapping Documented as an *ABSTRACT* base class. ABCs were added in 3.0 and backparted to 2.7. One can be quite competant in Python completely ignoring ABCs. >>>> issubclass(dict, Mapping) > True Yes, dict is a concrete Mapping class. I suppose we could have instead added a new builtin function 'isconcretetizationof' but is seemed easier to reuse issubclass for the test. Most people have no problem with that. >>>> dict.__bases__ > (,) The one and only *CONCRETE* base class. In 3.x, all classes are subclasses of object, which simplifies the class model a bit. >>>> [issubclass(b, Mapping) for b in dict.__bases__] > [False] > So dict is a subclass of Mapping, even though none of the bases of > dict is either Mapping or a subclass of Mapping. Great. Right. dict is direct concrete Mapping implementation and not subclassed from one. The main reason for introducing ABCs was to make it easier to test whether an object passed to a function is an instance of a possibly unknown or yet-to-be-written class in an abstract category, which has a certain api or interface. The actual usage of an ABC would be more like this: from collections import Mapping def f(m): if not isinstance(m, Mapping): raise ValueError('input is not a mapping') else: return True f(dict()) # True f([]) # produces Traceback (most recent call last): File "", line 1, in f([]) File "", line 3, in f raise ValueError('input is not a mapping') ValueError: input is not a mapping -- Terry Jan Reedy From stefan.sonnenberg at pythonmeister.com Wed Dec 22 17:34:28 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Wed, 22 Dec 2010 23:34:28 +0100 Subject: Toy http server In-Reply-To: <4d127627$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <3d190cbf-be7d-4973-b85f-c030bb258742@glegroupsg2000goo.googlegroups.com> <4d127627$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4D127CF4.5070801@pythonmeister.com> Sorry, this one is cross post. I posted my question below some time ago to then jython ml, because this hit me first with jython. Anyway, time passed, problem not solved. So, I'd like to know if some of you know where my error lies: Hi all, I've played around with some code-kata of mine from the past. It's a toy http server: import socket import select import sys import time srv = socket.socket(socket.AF_INET,socket.SOCK_STREAM) srv.setblocking(0) srv.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,True) # Not sure if this is needed. I only remember I've started once for some reason. Commenting out does no change if srv: srv.bind(('',8080)) srv.setblocking(0) srv.listen(5) conns = [srv] buffers = {} while True: reader,writer,failed = select.select(conns,conns,[],1) if failed: sys.exit(1) if srv in reader: client,(ip,port) = srv.accept() client.setblocking(False) conns += [client] for r in reader: if r is not srv: data = r.recv(1024) if not data: conns.remove(r) else: if r in buffers: buffers[r] += data else: buffers[r] = data for w in writer: if w is not srv: if w in buffers and buffers[w][-2:] == '\r\n': msg = 'HTTP/1.0 200 OK\r\nServer: Jython/2.5\r\nContent-type: text/plain\r\n\r\nThe answer is: 42\r\n' w.send(msg) w.close() # THIS ONLY WORKS WHEN THIS LINE IS PRESENT conns.remove(w) # AND THEN THIS IS MUST buffers[w] = '' But today I was asking myself why I should always close the socket, and if wouldn't be more efficient if I let it open. To make a long story short: it does not work. If I comment out the lines with the comment all upper case, jython consumes one core in my laptop completely and ab.exe from apache bails out after a while. Changing send() to sendall() did not do the trick. I've searched the web and did not find anything meaningful. Perhaps someone here can switch the light on. From steve+comp.lang.python at pearwood.info Wed Dec 22 17:36:14 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Dec 2010 22:36:14 GMT Subject: issubclass(dict, Mapping) References: Message-ID: <4d127d5e$0$29997$c3e8da3$5496439d@news.astraweb.com> On Wed, 22 Dec 2010 14:20:51 +0000, kj wrote: > Here's another example, fresh from today's crop of wonders: > > (v. 2.7.0) >>>> from collections import Mapping >>>> issubclass(dict, Mapping) > True >>>> dict.__bases__ > (,) >>>> [issubclass(b, Mapping) for b in dict.__bases__] > [False] > > > So dict is a subclass of Mapping, even though none of the bases of dict > is either Mapping or a subclass of Mapping. Great. Yes. So what? (1) What *actual* problem does this cause you? (2) Do you have an example of code that breaks because of this? (3) Do you understand that since the introduction of ABC (abstract base classes) in Python 2.6 (I think), isinstance and issubclass checks are performed cooperatively? The instance or class are asked if they wish to be known as an instance/subclass of the second argument. Classes can register themselves as subclasses of (say) Mapping without sharing any actual code with Mapping. This is a good thing, and the problem isn't that the abstraction leaks, as you believe, but the opposite: you're *ignoring* the abstraction and looking for concrete details that may or may not exist. I fear that you have fundamentally misunderstood the concept of "leaky abstraction". It does not mean, as you seem to think, that some concrete implementation detail differs between two classes (or functions). It means that some difference in behaviour is exposed, that difference being irrelevant to the abstraction but nevertheless important in some other sense. A contrived example: class MyList(list): def __len__(self): import time time.sleep(3600000) return list.__len__(self) MyList can be used anywhere a regular list can be used. Functionally the two are identical. The abstraction is that MyList is the same as list. But the leak is that len(MyList()) is *incredibly* slow. Coming back to Mapping: Abstraction: issubclass(dict, Mapping) One possible concrete implementation detail of how issubclass is implemented: any(base is Mapping for base in dict.__bases__) The statement "dict is a subclass of Mapping" is about an abstract relationship. It's not necessarily a statement about __bases__. To give an analogy, if you insist on doing DNA testing to determine whether a boy is a son of a man, you're going to be confused and distressed every time you find fathers whose sons are genetically unrelated to them. -- Steven From howe.steven at gmail.com Wed Dec 22 17:51:53 2010 From: howe.steven at gmail.com (Steven Howe) Date: Wed, 22 Dec 2010 14:51:53 -0800 Subject: Code review request In-Reply-To: References: Message-ID: <4D128109.30000@gmail.com> On 12/22/2010 10:34 AM, Jason Staudenmayer wrote: > Hi All, > I'm a python newbie so please be kind. I've been reading book after book and have written a script or two but this is my first real "program". Just looking for any suggestions and pointers. I've done some work with bash scripts and php (not OOP) a while a go. I'm not a programmer but would like to possibly expand in to it (right now an IT guy). Am I on the right track so far? > > The program should be documented enough to explain. > > """ > Created on Tue Dec 21 13:39:41 2010 > @author: jason > > Usage: cmd_drug_testing.py [options]... > Will select a random employee from the local database (located in the current directory) > and display the name by default. > > This program (Drug Testing) was written to help select employees for drug testing. > Program usage: > > -h, --help Displays this help info > -l, --list-emplys Lists all employees in the database > -s, --select Select employee for testing > -r, --remove-emply Delete employee from database, usage: -d employee_name or id > -e, --edit-emply Edit employee data in database, usage: -e employee_name or id > field_to_change new_value > -i, --insert-emply Insert new employee in database: > must fit this format -- "id:or '','lastname, firstname', 'email',0" > -f Display database name and full path > > This program was written by, Jason S. For the use of AA. > > """ > > # import our needed modules > import sqlite3 as sqlite > import sys, getopt > > #set global vars > global cursor > global conn > > > def usage(): > """ this just prints the usage in the doc string""" > print __doc__ > > def dbconnect(sql): > """handel the connction to the sqlite db """ > dbConnection = sqlite.connect("drug-test.db") > #set the cursor > cursor = dbConnection.cursor() > try: > #execute the sql passed from the other funtions and return the results > result = cursor.execute(sql) > dbConnection.commit() > except sqlite.Error, e: > result = e.args[0] > > return result > > > def listEmployees(sql): > #list all records in the database > listemp = dbconnect(sql) > for lst in listemp: > print "%s, %s, %s, %s" % (lst[0],lst[1],lst[2],lst[3]) > > def selectOneEmployee(sql): > #select a random record from the database > listemp = dbconnect(sql) > for empl in listemp: > print empl[0] > > def removeOneEmployee(sqlchk,sqldel): > #delete one employee by ID number > chk = dbconnect(sqlchk) > > if chk.fetchone() != None: > #check to make sure the ID is valid in the database > emply = dbconnect(sqlchk) > emply = emply.fetchall() > print "trying to remove employee %s" % (emply) > try: > dbconnect(sqldel) > > except sqlite.Error, e: > result = e.args[0] > print result > > else: > print "Employees ID is invalid, please check the ID number" > > def insertEmployee(sql): > #insert a new employee into the database > print sql > try: > dbconnect(sql) > > except sqlite.Error, e: > result = e.args[0] > print result > > def main(argv): > """The purpose of this program is to select an empployee from this database for random drug > testing. This program can also perform maintainance on same database.""" > if argv == []: > sql = "SELECT name FROM employees ORDER BY RANDOM() LIMIT 1;" > print "The following employee has been selected\n" > selectOneEmployee(sql) > > try: > #get the options passed by the user > opts, args = getopt.getopt(argv, "hlsr:e:i:d",["Help","list-emplys","select","remove-emply=","edit-emply=","insert-emply="]) > > except getopt.GetoptError: > usage() > sys.exit(2) > > #check throught the options and respond accordingly > for opt, arg in opts: > if opt in ("-h", "--help"): > usage() > sys.exit() > elif opt == '-d': > global _debug > _debug = 1 > elif opt in ("-l", "--list-emplys"): > sql = "select * from employees" > listEmployees(sql) > elif opt in ("-s","--select"): > sql = "SELECT name FROM employees ORDER BY RANDOM() LIMIT 1;" > print "The following employee has been selected\n" > selectOneEmployee(sql) > elif opt in ("-r","--remove-emply"): > if arg == "": > > sys.exit("You must provice the ID for the employee to remove") > sqlchk = "select * from employees where id = \"%s\"" % (arg) > sqldel = "delete from employees where id = \"%s\"" % (arg) > removeOneEmployee(sqlchk,sqldel) > elif opt in ("-i", "--insert-emply"): > sql = "insert into employees values(%s)" % (arg) > insertEmployee(sql) > > if __name__ == "__main__": > main(sys.argv[1:]) > > ########## END ################### > > Thanks everyone. > > > Jason > > > > ..?><((((?> you might consider using optparse (http://docs.python.org/library/optparse.html) to handle your input stream. That will help you decouple your interface from the working code. Easier to swap in a gui. Steven From stefan.sonnenberg at pythonmeister.com Wed Dec 22 17:54:34 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Wed, 22 Dec 2010 23:54:34 +0100 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> Message-ID: <4D1281AA.8020406@pythonmeister.com> Am 20.12.2010 20:34, schrieb spaceman-spiff: > Hi c.l.p folks > > This is a rather long post, but i wanted to include all the details& everything i have tried so far myself, so please bear with me& read the entire boringly long post. > > I am trying to parse a ginormous ( ~ 1gb) xml file. > > > 0. I am a python& xml n00b, s& have been relying on the excellent beginner book DIP(Dive_Into_Python3 by MP(Mark Pilgrim).... Mark , if u are readng this, you are AWESOME& so is your witty& humorous writing style) > > > 1. Almost all exmaples pf parsing xml in python, i have seen, start off with these 4 lines of code. > > import xml.etree.ElementTree as etree > tree = etree.parse('*path_to_ginormous_xml*') > root = tree.getroot() #my huge xml has 1 root at the top level > print root > > 2. In the 2nd line of code above, as Mark explains in DIP, the parse function builds& returns a tree object, in-memory(RAM), which represents the entire document. > I tried this code, which works fine for a small ( ~ 1MB), but when i run this simple 4 line py code in a terminal for my HUGE target file (1GB), nothing happens. > In a separate terminal, i run the top command,& i can see a python process, with memory (the VIRT column) increasing from 100MB , all the way upto 2100MB. > > I am guessing, as this happens (over the course of 20-30 mins), the tree representing is being slowly built in memory, but even after 30-40 mins, nothing happens. > I dont get an error, seg fault or out_of_memory exception. > > My hardware setup : I have a win7 pro box with 8gb of RAM& intel core2 quad cpuq9400. > On this i am running sun virtualbox(3.2.12), with ubuntu 10.10 as guest os, with 23gb disk space& 2gb(2048mb) ram, assigned to the guest ubuntu os. > > 3. I also tried using lxml, but an lxml tree is much more expensive, as it retains more info about a node's context, including references to it's parent. > [http://www.ibm.com/developerworks/xml/library/x-hiperfparse/] > > When i ran the same 4line code above, but with lxml's elementree ( using the import below in line1of the code above) > import lxml.etree as lxml_etree > > i can see the memory consumption of the python process(which is running the code) shoot upto ~ 2700mb& then, python(or the os ?) kills the process as it nears the total system memory(2gb) > > I ran the code from 1 terminal window (screenshot :http://imgur.com/ozLkB.png) > & ran top from another terminal (http://imgur.com/HAoHA.png) > > 4. I then investigated some streaming libraries, but am confused - there is SAX[http://en.wikipedia.org/wiki/Simple_API_for_XML] , the iterparse interface[http://effbot.org/zone/element-iterparse.htm] > > Which one is the best for my situation ? > > Any& all code_snippets/wisdom/thoughts/ideas/suggestions/feedback/comments/ of the c.l.p community would be greatly appreciated. > Plz feel free to email me directly too. > > thanks a ton > > cheers > ashish > > email : > ashish.makani > domain:gmail.com > > p.s. > Other useful links on xml parsing in python > 0. http://diveintopython3.org/xml.html > 1. http://stackoverflow.com/questions/1513592/python-is-there-an-xml-parser-implemented-as-a-generator > 2. http://codespeak.net/lxml/tutorial.html > 3. https://groups.google.com/forum/?hl=en&lnk=gst&q=parsing+a+huge+xml#!topic/comp.lang.python/CMgToEnjZBk > 4. http://www.ibm.com/developerworks/xml/library/x-hiperfparse/ > 5.http://effbot.org/zone/element-index.htm > http://effbot.org/zone/element-iterparse.htm > 6. SAX : http://en.wikipedia.org/wiki/Simple_API_for_XML > > Normally (what is normal, anyway?) such files are auto-generated, and are something that has a apparent similarity with a database query result, encapsuled in xml. Most of the time the structure is same for every "row" thats in there. So, a very unpythonic but fast, way would be to let awk resemble the records and write them in csv format to stdout. then pipe that to your python cruncher of choice and let it do the hard work. The awk part can be done in python, anyway, so could skip that. And take a look at xmlsh.org, they offer tools for the command line, like xml2csv. (Need java, btw). Cheers From rhodri at wildebst.demon.co.uk Wed Dec 22 18:02:11 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 22 Dec 2010 23:02:11 -0000 Subject: simple games w/o pygame References: Message-ID: On Wed, 22 Dec 2010 16:40:21 -0000, William Gill wrote: > I am teaching an 11 year old who wants to learn programming. I chose > Python, and it is working well. I seem to remember lots of simple > script games, like quizzes, number games etc. that would be good for his > tutorial. However, now all I can find is more complex games using > Pygame. Can anyone help me out here? Try the numbered worksheets from the Livewires course: http://www.livewires.org.uk/python/home They are aimed at 12-15 year olds, but an 11 year old should be able to cope. -- Rhodri James *-* Wildebeest Herder to the Masses From see at sig.for.address Wed Dec 22 18:15:35 2010 From: see at sig.for.address (Victor Eijkhout) Date: Wed, 22 Dec 2010 17:15:35 -0600 Subject: Generator question Message-ID: <1jtwvox.1pxdxm314l5m06N%see@sig.for.address> So I have a generator, either as a free function or in a class and I want to generate objects that are initialized from the generated things. def generator(): for whatever: yield something class Object(): def __init__(self): self.data = # the next thing from generator I have not been able to implement this elegantly. For external reasons the following syntax is unacceptable: for g in generator(): ob = Object(g) I really want to be able to write "Object()" in any location and get a properly initialized object. Hints appreciated. Victor. -- Victor Eijkhout -- eijkhout at tacc utexas edu From no.email at please.post Wed Dec 22 18:37:27 2010 From: no.email at please.post (kj) Date: Wed, 22 Dec 2010 23:37:27 +0000 (UTC) Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> Message-ID: In <1f47c36d-a509-4d05-ba79-62b4a534bfe0 at j19g2000prh.googlegroups.com> Carl Banks writes: >On Dec 22, 8:52=A0am, kj wrote: >> In Robert Kern t.k... at gmail.com> writes: >> >> >Obfuscating the location that an exception gets raised prevents a lot of >> >debugging... >> >> The Python interpreter does a lot of that "obfuscation" already, and I >> find the resulting tracebacks more useful for it. >> >> An error message is only useful to a given audience if that audience >> can use the information in the message to modify what they are >> doing to avoid the error. >> =A0It is of no use (certainly no *immediate* >> use) to this audience to see tracebacks that go deep into code that >> they don't know anything about and cannot change. >So when the audience files a bug report it's not useful for them to >include the whole traceback? Learn to read, buster. I wrote *immediate* use. ~kj From emile at fenx.com Wed Dec 22 18:46:37 2010 From: emile at fenx.com (Emile van Sebille) Date: Wed, 22 Dec 2010 15:46:37 -0800 Subject: Generator question In-Reply-To: <1jtwvox.1pxdxm314l5m06N%see@sig.for.address> References: <1jtwvox.1pxdxm314l5m06N%see@sig.for.address> Message-ID: On 12/22/2010 3:15 PM Victor Eijkhout said... > So I have a generator, either as a free function or in a class and I > want to generate objects that are initialized from the generated things. > > def generator(): > for whatever: > yield something > class Object(): > def __init__(self): How about change to def __init__(self, data=generator()): > self.data = # the next thing from generator > then... self.data = data.next()# the next thing from generator HTH, Emile > I have not been able to implement this elegantly. For external reasons > the following syntax is unacceptable: > > for g in generator(): > ob = Object(g) > > I really want to be able to write "Object()" in any location and get a > properly initialized object. > > Hints appreciated. > > Victor. From drsalists at gmail.com Wed Dec 22 18:49:31 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 22 Dec 2010 15:49:31 -0800 Subject: Generator question In-Reply-To: <1jtwvox.1pxdxm314l5m06N%see@sig.for.address> References: <1jtwvox.1pxdxm314l5m06N%see@sig.for.address> Message-ID: On Wed, Dec 22, 2010 at 3:15 PM, Victor Eijkhout wrote: > So I have a generator, either as a free function or in a class and I > want to generate objects that are initialized from the generated things. > > def generator(): > ? ? ? ?for whatever: > ? ? ? ? ? ? ? ?yield something > class Object(): > ? ? ? ?def __init__(self): > ? ? ? ? ? ? ? ?self.data = # the next thing from generator > > I have not been able to implement this elegantly. For external reasons > the following syntax is unacceptable: > > for g in generator(): > ? ? ? ?ob = Object(g) > > I really want to be able to write "Object()" in any location and get a > properly initialized object. > > Hints appreciated. > > Victor. > -- > Victor Eijkhout -- eijkhout at tacc utexas edu > -- > http://mail.python.org/mailman/listinfo/python-list > You likely want a class variable: #!/usr/bin/python def generator(): i = 0 while True: yield i i += 1 class Object: gen = generator() def __init__(self): self.data = Object.gen.next() def __str__(self): return str(self.data) o1 = Object() o2 = Object() o3 = Object() print o1 print o2 print o3 From mafunk at nmsu.edu Wed Dec 22 19:03:23 2010 From: mafunk at nmsu.edu (Matt Funk) Date: Wed, 22 Dec 2010 17:03:23 -0700 Subject: using python ftp Message-ID: <4D1291CB.5010404@nmsu.edu> Hi, i was wondering whether someone can point me whether the following already exists. I want to connect to a server , download various files (for whose name i want to be able to use a wildcard), and store those files in a given location on the hard drive. If the file already exists i do not want to download it. This seems fairly trivial and i would assume that there should be some sort of implementation that does this easily but i didn't find anything googling it. Otherwise i was going to do it "by hand" using ftplib: 1) connect to server, 2) change to directory on server 3) get listing 4) match the file pattern i want to the listing 5) check if file already exists 6) download file if matched and doesn't exist Can anyone offer any advice whether this already done somewhere? thanks matt From hidura at gmail.com Wed Dec 22 19:05:56 2010 From: hidura at gmail.com (Hidura) Date: Wed, 22 Dec 2010 20:05:56 -0400 Subject: Python Web App In-Reply-To: <907fa80e-1814-4ddb-be32-ec14cfd53fab@29g2000yqq.googlegroups.com> References: <907fa80e-1814-4ddb-be32-ec14cfd53fab@29g2000yqq.googlegroups.com> Message-ID: I am creating one, is on test, what kind of app do you want create? 2010/12/22, Sean : > Anybody know where I can find a Python Development Environment in the > form of a web app for use with Chrome OS. I have been looking for a > few days and all i have been able to find is some old discussions with > python developers talking about they will want one for the OS to be a > success with them. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Enviado desde mi dispositivo m?vil Diego I. Hidalgo D. From usernet at ilthio.net Wed Dec 22 19:12:24 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 23 Dec 2010 00:12:24 +0000 (UTC) Subject: Python Web App References: <907fa80e-1814-4ddb-be32-ec14cfd53fab@29g2000yqq.googlegroups.com> Message-ID: On 2010-12-22, Sean wrote: > Anybody know where I can find a Python Development Environment in the > form of a web app for use with Chrome OS. I have been looking for a > few days and all i have been able to find is some old discussions with > python developers talking about they will want one for the OS to be a > success with them. Personally, I think a web app based IDE would be ghastly; but, you might have a look at Mozilla Skywriter (formerly Bespin): https://mozillalabs.com/skywriter/ From hidura at gmail.com Wed Dec 22 19:30:58 2010 From: hidura at gmail.com (Hidura) Date: Wed, 22 Dec 2010 20:30:58 -0400 Subject: Python Web App In-Reply-To: References: <907fa80e-1814-4ddb-be32-ec14cfd53fab@29g2000yqq.googlegroups.com> Message-ID: Why grashtly? 2010/12/22, Tim Harig : > On 2010-12-22, Sean wrote: >> Anybody know where I can find a Python Development Environment in the >> form of a web app for use with Chrome OS. I have been looking for a >> few days and all i have been able to find is some old discussions with >> python developers talking about they will want one for the OS to be a >> success with them. > > Personally, I think a web app based IDE would be ghastly; but, you might > have a look at Mozilla Skywriter (formerly Bespin): > > https://mozillalabs.com/skywriter/ > -- > http://mail.python.org/mailman/listinfo/python-list > -- Enviado desde mi dispositivo m?vil Diego I. Hidalgo D. From drsalists at gmail.com Wed Dec 22 19:42:35 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 22 Dec 2010 16:42:35 -0800 Subject: how to handle output generated after execution of command/script on host unix machine? In-Reply-To: References: Message-ID: On Sun, Dec 19, 2010 at 11:38 PM, Darshak Bavishi wrote: > Hi Experts, > I am still struggling with handling output generated after?execution?of > ?command/script on host unix machine using windows client machine > ssh code : > import sys > import datetime > import time > # setup logging > paramiko.util.log_to_file('darshak_simple.log') > ssh=paramiko.SSHClient() > ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) > ssh.connect("*****",username="****",password="****") > try: > ?? ?stdin,stdout,stderr=ssh.exec_command("BsPlSMProbe -f node -d > > /var/log/Darshak/3.txt ") // output of this command will be store in > /var/log/Darshak/ in remote machine > except: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? {Issue is > files are generating but remaining blank pls pls help me out of this} > ?? ?print "check" > time.sleep(10) > print stdout.readlines() > a=stdout.readlines() > print 1 > ssh.close() > #print stdout.readlines() > Issue is files are generating but remaining blank pls pls help me out of > this > -- > BR > Darshak Bavishi > > -- > BR > Darshak Bavishi > > -- > http://mail.python.org/mailman/listinfo/python-list I've never used paramiko, but I have done some python+ssh. 1) Are you wanting the output from BsPlSMProbe to go to /var/log/Darshak/3.txt or your print stdout.readlines()? If you need both, you'd probably better get a tee in there. 2) If /var/log/Darshak/3.txt is coming up empty, it could mean that BsPlSMProbe simply produces no output. What if you ssh into the server interactively (perhaps using openssh or putty), and your command from there, as the same user, with the same options? 3) If you want errors as well as normal output in the same place, try a 2>&1 in your shell command, assuming you're using sh/ksh/bash (POSIX shell). You can tell what shell you're in with echo $SHELL. 4) If paramiko allows you to access the exit status of the command, you probably should retrieve that, not just stdout (and stderr). Conventionally, if the exit status is 0, things are fine, if they're nonzero, something's wrong - the oppose of what you see in most other languages that treat integers as booleans, because there are usually more ways things can fail than succeed. In fact, strictly speaking, the presence or absence of text on stderr is not a good indication of an error, compared to checking the exit status. HTH From rockitout117 at yahoo.com Wed Dec 22 20:22:32 2010 From: rockitout117 at yahoo.com (Maurice Shih) Date: Wed, 22 Dec 2010 17:22:32 -0800 (PST) Subject: Python programming Message-ID: <941320.45416.qm@web59815.mail.ac4.yahoo.com> Dear python-list at python.org, Thank you for taking the time to listen to my request. I'm a beginner programmer and I se python 2.6. I am making a program that needs a command that can check if a value is in a list. For example to check whether 5 is in [2, 6, 5,]. Thank you for hearing my request. Maurice Shih -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at please.post Wed Dec 22 20:22:36 2010 From: no.email at please.post (kj) Date: Thu, 23 Dec 2010 01:22:36 +0000 (UTC) Subject: general problem when subclassing a built-in class Message-ID: Suppose that you want to implement a subclass of built-in class, to meet some specific design requirements. Where in the Python documentation can one find the information required to determine the minimal[1] set of methods that one would need to override to achieve this goal? In my experience, educated guesswork doesn't get one very far with this question. Here's a *toy example*, just to illustrate this last point. Suppose that one wants to implement a subclass of dict, call it TSDict, to meet these two design requirements: 1. for each one of its keys, an instance of TSDict should keep a timestamp (as given by time.time, and accessible via the new method get_timestamp(key)) of the last time that the key had a value assigned to it; 2. other than the added capability described in (1), an instance of TSDict should behave *exactly* like a built-in dictionary. In particular, we should be able to observe behavior like this: >>> d = TSDict((('uno', 1), ('dos', 2)), tres=3, cuatro=4) >>> d['cinco'] = 5 >>> d {'cuatro': 4, 'dos': 2, 'tres': 3, 'cinco': 5, 'uno': 1} >>> d.get_timestamp('uno') 1293046586.644436 OK, here's one strategy, right out of OOP 101: #--------------------------------------------------------------------------- from time import time class TSDict(dict): def __setitem__(self, key, value): # save the value and timestamp for key as a tuple; # see footnote [2] dict.__setitem__(self, key, (value, time())) def __getitem__(self, key): # extract the value from the value-timestamp pair and return it return dict.__getitem__(self, key)[0] def get_timestamp(self, key): # extract the timestamp from the value-timestamp pair and return it return dict.__getitem__(self, key)[1] #--------------------------------------------------------------------------- This implementation *should* work (again, at least according to OOP 101), but, in fact, it doesn't come *even close*: >>> d = TSDict((('uno', 1), ('dos', 2)), tres=3, cuatro=4) >>> d['cinco'] = 5 >>> d {'cuatro': 4, 'dos': 2, 'tres': 3, 'cinco': (5, 1293059516.942985), 'uno': 1} >>> d.get_timestamp('uno') Traceback (most recent call last): File "", line 1, in File "/tmp/tsdict.py", line 23, in get_timestamp return dict.__getitem__(self, key)[1] TypeError: 'int' object is not subscriptable >From the above you can see that TSDict fails at *both* of the design requirements listed above: it fails to add a timestamp to all keys in the dictionary (e.g. 'uno', ..., 'cuatro' didn't get a timestamp), and get_timestamp bombs; and it also fails to behave in every other respect exactly like a built-in dict (e.g., repr(d) reveals the timestamps and how they are kept). So back to the general problem: to implement a subclass of a built-in class to meet a given set of design specifications. Where is the documentation needed to do this without guesswork? Given results like the one illustrated above, I can think of only two approaches (other than scrapping the whole idea of subclassing a built-in class in the first place): 1) Study the Python C source code for the built-in class in the hopes of somehow figuring out what API methods need to be overridden; 2) Through blind trial-and-error, keep trying different implementation strategies and/or keep overriding additional built-in class methods until the behavior of the resulting subclass approximates sufficiently the design specs. IMO, both of these approaches suck. Approach (1) would take *me* forever, since I don't know the first thing about Python's internals, and even if I did, going behind the documented API like that would make whatever I implement very likely to break with future releases of Python. Approach (2) could also take a very long time (probably much longer than the implementation would take if no guesswork was involved), but worse than that, one would have little assurance that one's experimentation has truly uncovered all the necessary details; IME, programming-by-guesswork leads to numerous and often nasty bugs. Is there any other way? TIA! ~kj [1] The "minimal" bit in the question statement is just another way of specifying a "maximal" reuse of the built-in's class code. [2] For this example, I've accessed the parent's methods directly through dict rather than through super(TSDict, self), just to keep the code as uncluttered as possible, but the results are the same if one uses super. From maxc at me.com Wed Dec 22 20:35:26 2010 From: maxc at me.com (Max Countryman) Date: Wed, 22 Dec 2010 20:35:26 -0500 Subject: Python programming In-Reply-To: <941320.45416.qm@web59815.mail.ac4.yahoo.com> References: <941320.45416.qm@web59815.mail.ac4.yahoo.com> Message-ID: >>> 5 in [2, 6, 5] True Sent from my iPhone On Dec 22, 2010, at 20:22, Maurice Shih wrote: > Dear python-list at python.org, > Thank you for taking the time to listen to my request. I'm a beginner programmer and I se python 2.6. I am making a program that needs a command that can check if a value is in a list. For example to check whether 5 is in [2, 6, 5,]. Thank you for hearing my request. > Maurice Shih > > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.kaplan at case.edu Wed Dec 22 20:39:29 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 22 Dec 2010 20:39:29 -0500 Subject: Python programming In-Reply-To: <941320.45416.qm@web59815.mail.ac4.yahoo.com> References: <941320.45416.qm@web59815.mail.ac4.yahoo.com> Message-ID: If you're just starting out, look at the Python tutorial http://docs.python.org/tutorial/index.html This question is answered in the tutorial- specifically in http://docs.python.org/tutorial/datastructures.html#more-on-conditions Also, there's a separate list, the tutor at python.org , for people just learning python. http://www.python.org/mailman/listinfo/tutor On Wed, Dec 22, 2010 at 8:22 PM, Maurice Shih wrote: > > Dear python-list at python.org, > Thank you for taking the time to listen to my request. I'm a beginner programmer and I se python 2.6. I am making a program that needs a command that can check if a value is in a list. For example to check whether 5 is in [2, 6, 5,]. Thank you for hearing my request. > Maurice Shih > > -- > http://mail.python.org/mailman/listinfo/python-list > From no.email at please.post Wed Dec 22 20:41:08 2010 From: no.email at please.post (kj) Date: Thu, 23 Dec 2010 01:41:08 +0000 (UTC) Subject: issubclass(dict, Mapping) References: <4d127d5e$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: In <4d127d5e$0$29997$c3e8da3$5496439d at news.astraweb.com> Steven D'Aprano writes: >On Wed, 22 Dec 2010 14:20:51 +0000, kj wrote: >> Here's another example, fresh from today's crop of wonders: >> >> (v. 2.7.0) >>>>> from collections import Mapping >>>>> issubclass(dict, Mapping) >> True >>>>> dict.__bases__ >> (,) >>>>> [issubclass(b, Mapping) for b in dict.__bases__] >> [False] >> >> So dict is a subclass of Mapping, even though none of the bases of dict >> is either Mapping or a subclass of Mapping. Great. >Yes. So what? That's being deliberately obtuse. The situation described goes smack against standard OOP semantics, which would be fine if all this stuff was documented clearly and reasonably, i.e. in one (preferably "official") place rather than scattered over a bazillion separate documents, PEP this, module that, GvR musing #42, etc. Let's just say that I'm looking forward to the end to these surprises. ~kj From enalicho at gmail.com Wed Dec 22 20:43:30 2010 From: enalicho at gmail.com (Noah Hall) Date: Thu, 23 Dec 2010 01:43:30 +0000 Subject: Python programming In-Reply-To: <941320.45416.qm@web59815.mail.ac4.yahoo.com> References: <941320.45416.qm@web59815.mail.ac4.yahoo.com> Message-ID: The most Pythonic ways of checking if a value is within a list is to use the "in" keyword, for example, using your data - 5 in [2, 6, 5] Which will return True, as 5 is in the list. You can then use this in the following generic way - if variable in list: do_things Where variable is the varible you wish to seek, and the list is the list you wish to search. Might I also suggest that you use the *tutor*@*python*.org mailing list, where people are perhaps more ready to handle this sort of question. -------------- next part -------------- An HTML attachment was scrubbed... URL: From secris1 at gmail.com Wed Dec 22 20:51:46 2010 From: secris1 at gmail.com (Sean) Date: Wed, 22 Dec 2010 17:51:46 -0800 (PST) Subject: Python Web App References: <907fa80e-1814-4ddb-be32-ec14cfd53fab@29g2000yqq.googlegroups.com> Message-ID: <927a4339-0c9b-46c3-877e-46d939e7e397@w2g2000yqb.googlegroups.com> I am wanting to learn python and I am test a Chrome OS notebook at the same time so I need something that will atleast tell me if I have any syntax errors. Although the more features the better that way learning is an easier experience. On Dec 22, 7:05?pm, Hidura wrote: > I am creating one, is on test, what kind of app do you want create? > > 2010/12/22, Sean : > > > Anybody know where I can find a Python Development Environment in the > > form of a web app for use with Chrome OS. I have been looking for a > > few days and all i have been able to find is some old discussions with > > python developers talking about they will want one for the OS to be a > > success with them. > > -- > >http://mail.python.org/mailman/listinfo/python-list > > -- > Enviado desde mi dispositivo m?vil > > Diego I. Hidalgo D. From python at mrabarnett.plus.com Wed Dec 22 20:54:10 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 23 Dec 2010 01:54:10 +0000 Subject: Toy http server In-Reply-To: <4D127CF4.5070801@pythonmeister.com> References: <3d190cbf-be7d-4973-b85f-c030bb258742@glegroupsg2000goo.googlegroups.com> <4d127627$0$29997$c3e8da3$5496439d@news.astraweb.com> <4D127CF4.5070801@pythonmeister.com> Message-ID: <4D12ABC2.7060801@mrabarnett.plus.com> On 22/12/2010 22:34, Stefan Sonnenberg-Carstens wrote: > Sorry, this one is cross post. > I posted my question below some time ago to then jython ml, because this > hit me first with jython. > Anyway, time passed, problem not solved. > > So, I'd like to know if some of you know where my error lies: > [snip] What happens if the conns list contains a writer that's ready? The select function returns immediately with that writer in the writer list. If it's not srv then nothing is done with it, so execution just loops back to the select function with that writer still in the conns list, and the select function then returns immediately with that writer in the writer list again. Infinite loop! From secris1 at gmail.com Wed Dec 22 20:56:21 2010 From: secris1 at gmail.com (Sean) Date: Wed, 22 Dec 2010 17:56:21 -0800 (PST) Subject: Python Web App References: <907fa80e-1814-4ddb-be32-ec14cfd53fab@29g2000yqq.googlegroups.com> <927a4339-0c9b-46c3-877e-46d939e7e397@w2g2000yqb.googlegroups.com> Message-ID: <73e7f90a-c5d1-4ed8-8fef-6aa7f921aa2e@d8g2000yqf.googlegroups.com> Forgot to point out that Chrome OS has no local storage accessable to the user. Hence why I need a web based solution. On Dec 22, 8:51?pm, Sean wrote: > I am wanting to learn python and I am test a Chrome OS notebook at the > same time so I need something that will atleast tell me if I have any > syntax errors. Although the more features the better that way learning > is an easier experience. > > On Dec 22, 7:05?pm, Hidura wrote: > > > > > > > > > I am creating one, is on test, what kind of app do you want create? > > > 2010/12/22, Sean : > > > > Anybody know where I can find a Python Development Environment in the > > > form of a web app for use with Chrome OS. I have been looking for a > > > few days and all i have been able to find is some old discussions with > > > python developers talking about they will want one for the OS to be a > > > success with them. > > > -- > > >http://mail.python.org/mailman/listinfo/python-list > > > -- > > Enviado desde mi dispositivo m?vil > > > Diego I. Hidalgo D. From anurag.chourasia at gmail.com Wed Dec 22 21:12:44 2010 From: anurag.chourasia at gmail.com (Anurag Chourasia) Date: Thu, 23 Dec 2010 07:42:44 +0530 Subject: using python ftp In-Reply-To: <4D1291CB.5010404@nmsu.edu> References: <4D1291CB.5010404@nmsu.edu> Message-ID: Hi Matt, I have a snippet to "upload" files (that match a particular search pattern) to a remote server. Variable names are self explanatory. You could tweak this a little to "download" files instead. from ftplib import FTP ftp = FTP(hostname) ftp.login(user_id,passwd) ftp.cwd(remote_directory) files_list=glob.glob(file_search_pattern) for file in files_list: try: ftp.storlines('STOR ' + file, open(file)) except Exception, e: print ('Failed to FTP file: %s' %(file)) ftp.close() Regards, Anurag On Thu, Dec 23, 2010 at 5:33 AM, Matt Funk wrote: > Hi, > > i was wondering whether someone can point me whether the following > already exists. > > I want to connect to a server , download various files (for whose name i > want to be able to use a wildcard), and store those files in a given > location on the hard drive. If the file already exists i do not want to > download it. > > This seems fairly trivial and i would assume that there should be some > sort of implementation that does this easily but i didn't find anything > googling it. > > Otherwise i was going to do it "by hand" using ftplib: > 1) connect to server, > 2) change to directory on server > 3) get listing > 4) match the file pattern i want to the listing > 5) check if file already exists > 6) download file if matched and doesn't exist > > Can anyone offer any advice whether this already done somewhere? > > thanks > matt > -- > http://mail.python.org/mailman/listinfo/python-list > From hidura at gmail.com Wed Dec 22 21:21:17 2010 From: hidura at gmail.com (Hidura) Date: Wed, 22 Dec 2010 22:21:17 -0400 Subject: Python Web App In-Reply-To: <927a4339-0c9b-46c3-877e-46d939e7e397@w2g2000yqb.googlegroups.com> References: <907fa80e-1814-4ddb-be32-ec14cfd53fab@29g2000yqq.googlegroups.com> <927a4339-0c9b-46c3-877e-46d939e7e397@w2g2000yqb.googlegroups.com> Message-ID: Use editarea, that's the best option if you want something small, but as i said before i am developing a framework that allows you to create app's from the web and is much more complete than editarea. 2010/12/22, Sean : > I am wanting to learn python and I am test a Chrome OS notebook at the > same time so I need something that will atleast tell me if I have any > syntax errors. Although the more features the better that way learning > is an easier experience. > > On Dec 22, 7:05?pm, Hidura wrote: >> I am creating one, is on test, what kind of app do you want create? >> >> 2010/12/22, Sean : >> >> > Anybody know where I can find a Python Development Environment in the >> > form of a web app for use with Chrome OS. I have been looking for a >> > few days and all i have been able to find is some old discussions with >> > python developers talking about they will want one for the OS to be a >> > success with them. >> > -- >> >http://mail.python.org/mailman/listinfo/python-list >> >> -- >> Enviado desde mi dispositivo m?vil >> >> Diego I. Hidalgo D. > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Enviado desde mi dispositivo m?vil Diego I. Hidalgo D. From hidura at gmail.com Wed Dec 22 21:23:38 2010 From: hidura at gmail.com (Hidura) Date: Wed, 22 Dec 2010 22:23:38 -0400 Subject: Python Web App In-Reply-To: References: <907fa80e-1814-4ddb-be32-ec14cfd53fab@29g2000yqq.googlegroups.com> <927a4339-0c9b-46c3-877e-46d939e7e397@w2g2000yqb.googlegroups.com> Message-ID: My framework let you store online on a hosting server that the same framework provide. 2010/12/22, Hidura : > Use editarea, that's the best option if you want something small, but > as i said before i am developing a framework that allows you to create > app's from the web and is much more complete than editarea. > > 2010/12/22, Sean : >> I am wanting to learn python and I am test a Chrome OS notebook at the >> same time so I need something that will atleast tell me if I have any >> syntax errors. Although the more features the better that way learning >> is an easier experience. >> >> On Dec 22, 7:05?pm, Hidura wrote: >>> I am creating one, is on test, what kind of app do you want create? >>> >>> 2010/12/22, Sean : >>> >>> > Anybody know where I can find a Python Development Environment in the >>> > form of a web app for use with Chrome OS. I have been looking for a >>> > few days and all i have been able to find is some old discussions with >>> > python developers talking about they will want one for the OS to be a >>> > success with them. >>> > -- >>> >http://mail.python.org/mailman/listinfo/python-list >>> >>> -- >>> Enviado desde mi dispositivo m?vil >>> >>> Diego I. Hidalgo D. >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > -- > Enviado desde mi dispositivo m?vil > > Diego I. Hidalgo D. > -- Enviado desde mi dispositivo m?vil Diego I. Hidalgo D. From python at mrabarnett.plus.com Wed Dec 22 21:24:09 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 23 Dec 2010 02:24:09 +0000 Subject: using python ftp In-Reply-To: References: <4D1291CB.5010404@nmsu.edu> Message-ID: <4D12B2C9.7050304@mrabarnett.plus.com> On 23/12/2010 02:12, Anurag Chourasia wrote: > Hi Matt, > > I have a snippet to "upload" files (that match a particular search > pattern) to a remote server. > > Variable names are self explanatory. You could tweak this a little to > "download" files instead. > > from ftplib import FTP > ftp = FTP(hostname) > ftp.login(user_id,passwd) > ftp.cwd(remote_directory) > files_list=glob.glob(file_search_pattern) > for file in files_list: > try: > ftp.storlines('STOR ' + file, open(file)) You should open the file in binary mode: ftp.storlines('STOR ' + file, open(file, 'rb')) This isn't necessary on *nix, but it's recommended for portability. > except Exception, e: > print ('Failed to FTP file: %s' %(file)) > ftp.close() > [snip] From usernet at ilthio.net Wed Dec 22 21:41:33 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 23 Dec 2010 02:41:33 +0000 (UTC) Subject: Python Web App References: <907fa80e-1814-4ddb-be32-ec14cfd53fab@29g2000yqq.googlegroups.com> Message-ID: [Reordered to preserve context in bottom posting] On 2010-12-23, Hidura wrote: > 2010/12/22, Tim Harig : >> On 2010-12-22, Sean wrote: >>> Anybody know where I can find a Python Development Environment in the >>> form of a web app for use with Chrome OS. I have been looking for a >>> few days and all i have been able to find is some old discussions with >>> python developers talking about they will want one for the OS to be a >>> success with them. >> >> Personally, I think a web app based IDE would be ghastly; but, you might >> have a look at Mozilla Skywriter (formerly Bespin): > > Why grashtly? I don't personally think the web makes a good framework for highly interactive applications as they must work within the constraints of the browser and IDEs are highly interactive applications by their very nature. Perhaps HTML5/CSS3 will change things; but, standard DOM manipulation, as I am accustomed to seeing it, cannot generate the kind of rendering that is available from native applications. Attempts to do so end up being kludgy. It also cannot handle the kinds of desktop integrations that are common for native applications without opening up serious security trust issues. (Can everybody say ActiveX fiasco?) Finally, there are difficulties in handling keystrokes without conflicting with the browser's native key bindings. I seldom ever touch a mouse and I am a huge fan of vi, mutt, slrn, screen, ratpoison, etc. where the primary interface is totally accessable through the keyboard without having to tab through many options. From anurag.chourasia at gmail.com Wed Dec 22 21:43:01 2010 From: anurag.chourasia at gmail.com (Anurag Chourasia) Date: Thu, 23 Dec 2010 08:13:01 +0530 Subject: Python programming In-Reply-To: <941320.45416.qm@web59815.mail.ac4.yahoo.com> References: <941320.45416.qm@web59815.mail.ac4.yahoo.com> Message-ID: Here you go..... $ python Python 2.5.2 (r252:60911, Dec 2 2008, 09:26:14) [GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> A=[2,6,5] >>> if 5 in A: ... print 'Yes' ... else: ... print 'No' ... Yes >>> Regards, Anurag On Thu, Dec 23, 2010 at 6:52 AM, Maurice Shih wrote: > Dear python-list at python.org, > Thank you for taking the time to listen to my request. I'm a beginner > programmer and I se python 2.6. I am making a program that needs a command > that can check if a value is in a list. For example to check whether 5 is in > [2, 6, 5,]. Thank you for hearing my request. > Maurice Shih > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From see at sig.for.address Wed Dec 22 21:45:54 2010 From: see at sig.for.address (Victor Eijkhout) Date: Wed, 22 Dec 2010 20:45:54 -0600 Subject: Generator question References: <1jtwvox.1pxdxm314l5m06N%see@sig.for.address> Message-ID: <1jtx5my.ewrrejlduocgN%see@sig.for.address> Dan Stromberg wrote: > You likely want a class variable: Sounds like an elegant solution. Thanks! Victor. -- Victor Eijkhout -- eijkhout at tacc utexas edu From hidura at gmail.com Wed Dec 22 22:22:26 2010 From: hidura at gmail.com (Hidura) Date: Wed, 22 Dec 2010 23:22:26 -0400 Subject: Python Web App In-Reply-To: References: <907fa80e-1814-4ddb-be32-ec14cfd53fab@29g2000yqq.googlegroups.com> Message-ID: Ok, but you are comparing a web-based framework with a native-based framework that use the components of the system to make all the things that need, a web-based framewok use the resourses of the browser to make it all, so the developer that use a framework on the web can't expect get the same results, in my case i beleive that a web-based framework adjust better to the needs if you'll make a web-app, otherwise use eclipse or netbeans. 2010/12/22, Tim Harig : > [Reordered to preserve context in bottom posting] > On 2010-12-23, Hidura wrote: >> 2010/12/22, Tim Harig : >>> On 2010-12-22, Sean wrote: >>>> Anybody know where I can find a Python Development Environment in the >>>> form of a web app for use with Chrome OS. I have been looking for a >>>> few days and all i have been able to find is some old discussions with >>>> python developers talking about they will want one for the OS to be a >>>> success with them. >>> >>> Personally, I think a web app based IDE would be ghastly; but, you might >>> have a look at Mozilla Skywriter (formerly Bespin): >> >> Why grashtly? > > I don't personally think the web makes a good framework for highly > interactive applications as they must work within the constraints of the > browser and IDEs are highly interactive applications by their very nature. > Perhaps HTML5/CSS3 will change things; but, standard DOM manipulation, > as I am accustomed to seeing it, cannot generate the kind of rendering > that is available from native applications. Attempts to do so end up being > kludgy. > > It also cannot handle the kinds of desktop integrations that are common > for native applications without opening up serious security trust issues. > (Can everybody say ActiveX fiasco?) > > Finally, there are difficulties in handling keystrokes without conflicting > with the browser's native key bindings. I seldom ever touch a mouse > and I am a huge fan of vi, mutt, slrn, screen, ratpoison, etc. where > the primary interface is totally accessable through the keyboard without > having to tab through many options. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Enviado desde mi dispositivo m?vil Diego I. Hidalgo D. From steve+comp.lang.python at pearwood.info Wed Dec 22 22:22:40 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Dec 2010 03:22:40 GMT Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> Message-ID: <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> On Wed, 22 Dec 2010 13:53:20 -0800, Carl Banks wrote: > On Dec 22, 8:52?am, kj wrote: >> In Robert Kern >> writes: >> >> >Obfuscating the location that an exception gets raised prevents a lot >> >of debugging... >> >> The Python interpreter does a lot of that "obfuscation" already, and I >> find the resulting tracebacks more useful for it. >> >> An error message is only useful to a given audience if that audience >> can use the information in the message to modify what they are doing to >> avoid the error. > > So when the audience files a bug report it's not useful for them to > include the whole traceback? Well, given the type of error KJ has been discussing, no, it isn't useful. Fault: function raises documented exception when passed input that is documented as being invalid What steps will reproduce the problem? 1. call the function with invalid input 2. read the exception that is raised 3. note that it is the same exception as documented What is the expected output? What do you see instead? Excepted somebody to hit me on the back of the head and tell me not to call the function with invalid input. Instead I just got an exception. You seem to have completely missed that there will be no bug report, because this isn't a bug. (Or if it is a bug, the bug is elsewhere, external to the function that raises the exception.) It is part of the promised API. The fact that the exception is generated deep down some chain of function calls is irrelevant. The analogy is this: imagine a function that delegates processing of the return result to different subroutines: def func(arg): if arg > 0: return _inner1(arg) else: return _inner2(arg) This is entirely irrelevant to the caller. When they receive the return result from calling func(), they have no way of knowing where the result came from, and wouldn't care even if they could. Return results hide information about where the result was calculated, as they should. Why shouldn't deliberate, explicit, documented exceptions be treated the same? Tracebacks expose the implementation details of where the exception was generated. This is the right behaviour if the exception is unexpected -- a bug internal to func -- since you need knowledge of the implementation of func in order to fix the unexpected exception. So far so good -- we accept that Python's behaviour under these circumstances is correct. But this is not the right behaviour when the exception is expected, e.g. an explicitly raised exception in response to an invalid argument. In this case, the traceback exposes internal details of no possible use to the caller. What does the caller care if func() delegates (e.g.) input checking to a subroutine? The subroutine is an irrelevant implementation detail. The exception is promised output of the function, just as much so as if it were a return value. Consider the principle that exceptions should be dealt with as close as possible to the actual source of the problem: >>> f('good input') Traceback (most recent call last): File "", line 1, in File "", line 2, in f File "", line 2, in g File "", line 2, in h File "", line 2, in i File "", line 2, in j File "", line 2, in k <=== error occurs here, and shown here ValueError But now consider the scenario where the error is not internal to f, but external. The deeper down the stack trace you go, the further away from the source of the error you get. The stack trace now obscures the source of the error, rather than illuminating it: >>> f('bad input') <=== error occurs here Traceback (most recent call last): File "", line 1, in File "", line 2, in f File "", line 2, in g File "", line 2, in h File "", line 2, in i File "", line 2, in j File "", line 2, in k <=== far from the source of error ValueError There's no point in inspecting function k for a bug when the problem has nothing to do with k. The problem is that the input fails to match the pre-conditions for f. From the perspective of the caller, the error has nothing to do with k, k is a meaningless implementation detail, and the source of the error is the mismatch between the input and what f expects. And so by the principle of dealing with exceptions as close as possible to the source of the error, we should desire this traceback instead: >>> f('bad input') <=== error occurs here Traceback (most recent call last): File "", line 1, in File "", line 2, in f <=== matches where the error occurs ValueError In the absence of any practical way for function f to know whether an arbitrary exception in a subroutine is a bug or not, the least-worst decision is Python's current behaviour: take the conservative, risk- adverse path and assume the worst, treat the exception as a bug in the subroutine, and expose the entire stack trace. But, I suggest, we can do better using the usual Python strategy of implementing sensible default behaviour but allowing objects to customize themselves. Objects can declare themselves to be instances of some other class, or manipulate what names are reported by dir. Why shouldn't a function deliberately and explicitly take ownership of an exception raised by a subroutine? There should be a mechanism for Python functions to distinguish between unexpected exceptions (commonly known as "bugs"), which should be reported as coming from wherever they come from, and documented, expected exceptions, which should be reported as coming from the function regardless of how deep the function call stack really is. -- Steven From steve+comp.lang.python at pearwood.info Wed Dec 22 22:28:56 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Dec 2010 03:28:56 GMT Subject: issubclass(dict, Mapping) References: <4d127d5e$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4d12c1f7$0$30000$c3e8da3$5496439d@news.astraweb.com> On Thu, 23 Dec 2010 01:41:08 +0000, kj wrote: > In <4d127d5e$0$29997$c3e8da3$5496439d at news.astraweb.com> Steven D'Aprano > writes: > >>On Wed, 22 Dec 2010 14:20:51 +0000, kj wrote: > >>> Here's another example, fresh from today's crop of wonders: >>> >>> (v. 2.7.0) >>>>>> from collections import Mapping >>>>>> issubclass(dict, Mapping) >>> True >>>>>> dict.__bases__ >>> (,) >>>>>> [issubclass(b, Mapping) for b in dict.__bases__] >>> [False] >>> >>> So dict is a subclass of Mapping, even though none of the bases of >>> dict is either Mapping or a subclass of Mapping. Great. > > >>Yes. So what? > > That's being deliberately obtuse. The situation described goes smack > against standard OOP semantics, What are these "standard OOP semantics" you're referring to, and who made them "standard"? If people can't even decide whether multiple inheritance should be allowed or not, what makes you think that there is any such thing as "standard OOP"? I think you are confusing concrete implementation details with the interface. The interface for subclass testing in Python is as follows: A class K is a subclass of class C if, and only if, issubclass(C, K) returns a true result. That's it. Everything else is implementation. __bases__ is implementation. __subclasscheck__ is implementation. If Python adds a third mechanism for implementing subclass checks in version 3.3 or 3.4, the interface will just continue to work correctly. > which would be fine if all this stuff > was documented clearly and reasonably, i.e. in one (preferably > "official") place rather than scattered over a bazillion separate > documents, PEP this, module that, GvR musing #42, etc. This is documented, in the docs. http://docs.python.org/reference/datamodel.html#customizing-instance-and-subclass-checks Nobody says the Python docs are perfect, but most things you ask are in there. Patches for the docs to improve them are welcome. -- Steven From angrybaldguy at gmail.com Wed Dec 22 22:33:52 2010 From: angrybaldguy at gmail.com (Owen Jacobson) Date: Wed, 22 Dec 2010 22:33:52 -0500 Subject: general problem when subclassing a built-in class References: Message-ID: <201012222233525310-angrybaldguy@gmailcom> On 2010-12-22 20:22:36 -0500, kj said: > Suppose that you want to implement a subclass of built-in class, to > meet some specific design requirements. > > Where in the Python documentation can one find the information > required to determine the minimal[1] set of methods that one would > need to override to achieve this goal? (Rest elided.) The short answer is that you can't everything you want. If some behaviour or implementation detail isn't documented, you can't make any assumptions about how a class works, even if you really want to. Whatever you figure out by "educated guesswork" (or, even better, reading the source) is, absent documentation, not guaranteed, and behaviour that's not guaranteed can and will change whenever the code's maintaners feel like it. This is true for for builtins, for things in the standard library, and for things in competently-maintained third party libraries. Requiring that every class document its internals extensively enough to permit subclasses to modify behaviour in totally arbitrary ways has to be balanced against allowing each class's interface to usefully abstract its internal workings. Especially in a duck-typed language like Python, there's very little need for subclassing simply to intercept one or two method calls, and the resulting composition-based system is both more flexible and, being based on documented and stable interfaces, easier to maintain and support. Subclassing is a powerful tool, not suited to every design problem. In your case (tracking timestamps in a dict-like container), you're probably better off implementing your own dict-like container, with support for as much or as little of the protocol you want. You can do that without subclassing dict: the protocol for dict is not difficult to implement, especially if your backing storage is a real dict. What forces do you imagine require you to use a subclass for this? -o From usernet at ilthio.net Wed Dec 22 22:54:07 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 23 Dec 2010 03:54:07 +0000 (UTC) Subject: Python Web App References: <907fa80e-1814-4ddb-be32-ec14cfd53fab@29g2000yqq.googlegroups.com> Message-ID: On 2010-12-23, Hidura wrote: > Ok, but you are comparing a web-based framework with a native-based > framework that use the components of the system to make all the things > that need, a web-based framewok use the resourses of the browser to Right. That is exactly what I am comparing. > make it all, so the developer that use a framework on the web can't > expect get the same results, in my case i beleive that a web-based Which is exactly the problem with web apps that are highly interactive. My suggestion, is not to develope a web based IDE or use one. It just isn't something that the web was designed to do well. > expect get the same results, in my case i beleive that a web-based > framework adjust better to the needs if you'll make a web-app, Most IDEs that are targeted at web developement have a built in web browser or strong integration with one to run the web app as you are developing it. I don't see any advantage or the necessity of actually running the IDE code itself in the browser. > otherwise use eclipse or netbeans. I would; but then, I wouldn't purchase an operating system that is entirely based on a web browser. From hidura at gmail.com Wed Dec 22 23:30:58 2010 From: hidura at gmail.com (hidura at gmail.com) Date: Thu, 23 Dec 2010 04:30:58 +0000 Subject: Python Web App In-Reply-To: Message-ID: <20cf30433d361963ec04980c5652@google.com> > Which is exactly the problem with web apps that are highly interactive. My > suggestion, is not to develope a web based IDE or use one. It just isn't > something that the web was designed to do well. Is not a problem of the IDE, the problem is on what the developer expect as i said i you want something to the desktop well use an IDE that creates apps for desktop, but if you need something for the web you can try on a web-based IDE. > Most IDEs that are targeted at web developement have a built in web > browser > or strong integration with one to run the web app as you are developing > it. > I don't see any advantage or the necessity of actually running the IDE > code > itself in the browser. That's the problem an integration with one, my IDE works on all of them and the result is the same in IE and Chrome or FF, a web page cannot be designed to one browser it has to be designed to all the browser and have to be same. On the visualization is more difficult but nobody could control perfectly that but on the results of the data is has to be the same. > I would; but then, I wouldn't purchase an operating system that is > entirely > based on a web browser. I support that, but the target of those OS are use the share resources of the pc, smartphone, etc and the server. On Dec 22, 2010 11:54pm, Tim Harig wrote: > On 2010-12-23, Hidura hidura at gmail.com> wrote: > > Ok, but you are comparing a web-based framework with a native-based > > framework that use the components of the system to make all the things > > that need, a web-based framewok use the resourses of the browser to > Right. That is exactly what I am comparing. > > make it all, so the developer that use a framework on the web can't > > expect get the same results, in my case i beleive that a web-based > Which is exactly the problem with web apps that are highly interactive. My > suggestion, is not to develope a web based IDE or use one. It just isn't > something that the web was designed to do well. > > expect get the same results, in my case i beleive that a web-based > > framework adjust better to the needs if you'll make a web-app, > Most IDEs that are targeted at web developement have a built in web > browser > or strong integration with one to run the web app as you are developing > it. > I don't see any advantage or the necessity of actually running the IDE > code > itself in the browser. > > otherwise use eclipse or netbeans. > I would; but then, I wouldn't purchase an operating system that is > entirely > based on a web browser. > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Thu Dec 23 00:42:07 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 22 Dec 2010 21:42:07 -0800 Subject: Python programming In-Reply-To: <941320.45416.qm@web59815.mail.ac4.yahoo.com> References: <941320.45416.qm@web59815.mail.ac4.yahoo.com> Message-ID: If it's a big list and you're checking multiple times, you're probably better off converting the list to a set, and using "in" on the set. Once you have your list converted to a set, you can update both quickly. On Wed, Dec 22, 2010 at 5:22 PM, Maurice Shih wrote: > Dear python-list at python.org, > Thank you for taking the time to listen to my request. I'm a beginner > programmer and I se python 2.6. I am making a program that needs a command > that can check if a value is in a list. For example to check whether 5 is in > [2, 6, 5,]. Thank you for hearing my request. > Maurice Shih > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tooscattered at gmail.com Thu Dec 23 01:36:08 2010 From: tooscattered at gmail.com (scattered) Date: Wed, 22 Dec 2010 22:36:08 -0800 (PST) Subject: simple games w/o pygame References: Message-ID: On Dec 22, 11:40?am, William Gill wrote: > I am teaching an 11 year old who wants to learn programming. ?I chose > Python, and it is working well. ?I seem to remember lots of simple > script games, like quizzes, number games etc. that would be good for his > tutorial. ?However, now all I can find is more complex games using > Pygame. ?Can anyone help me out here? Maybe you can check out the book "Python Programming for the Absolute Beginner, 3rd Edition" by Michael Dawson. Its emphasis is on simple games. My son is (who is older - just turned 17) is working through it now and finding it easy going. From benedict.verheyen at gmail.com Thu Dec 23 02:53:47 2010 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Thu, 23 Dec 2010 08:53:47 +0100 Subject: compiling Python 2.7.1 with readline module fails on Debian (Virtualbox) In-Reply-To: References: Message-ID: On 22/12/2010 18:57, Jim Pharis wrote: > are you running make clean for good measure? Yes, i am. I am gong to try and uninstall Python2.7 from $HOME/local and see if that makes a difference. Maybe it interferes with the build process? Regards, Benedict From yccheok at yahoo.com Thu Dec 23 03:33:26 2010 From: yccheok at yahoo.com (Yan Cheng CHEOK) Date: Thu, 23 Dec 2010 00:33:26 -0800 (PST) Subject: Unable to decode file written by C++ wostringstream Message-ID: <482310.52893.qm@web65701.mail.ac4.yahoo.com> Currently, I have the following text file (https://sites.google.com/site/yanchengcheok/Home/TEST.TXT?attredirects=0&d=1) written by C++ wostringstream. What I want to do it, I want to write a python script which accept user browser request, and then send over the entire file for user to download. The downloaded file, should be exactly same as the original text file inside server itself. The code is written as follow : import cgi print "Content-Type: text/plain" print "Content-Disposition: attachment; filename=TEST.txt" print filename = "C:\\TEST.TXT" f = open(filename, 'r') for line in f: print line However, when I open up the downloaded file, the file is all having weird characters. I try to use rb flag, it doesn't either. Is there anything I had missed out? What I wish is, the file (TEST.TXT) downloaded by the client by making query to the above script, will be exactly same as the one in server. I also try to specific the encoding explicitly. import cgi print "Content-Type: text/plain; charset=UTF-16" print "Content-Disposition: attachment; filename=TEST.txt" print filename = "C:\\TEST.TXT" f = open(filename, 'r') for line in f: print line.encode('utf-16') It doesn't work either. Here is the screen shoot for original text file (http://i.imgur.com/S6SjX.png) and file after downloaded from a web browser. (http://i.imgur.com/l39Lc.png) Is there anything I had missed out? Thanks and Regards Yan Cheng CHEOK From orasnita at gmail.com Thu Dec 23 03:46:51 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Thu, 23 Dec 2010 10:46:51 +0200 Subject: using python ftp References: <4D1291CB.5010404@nmsu.edu> Message-ID: Can this lib also work with ftps? Thanks. Octavian ----- Original Message ----- From: "Anurag Chourasia" To: "Matt Funk" Cc: Sent: Thursday, December 23, 2010 4:12 AM Subject: Re: using python ftp > Hi Matt, > > I have a snippet to "upload" files (that match a particular search > pattern) to a remote server. > > Variable names are self explanatory. You could tweak this a little to > "download" files instead. > > from ftplib import FTP > ftp = FTP(hostname) > ftp.login(user_id,passwd) > ftp.cwd(remote_directory) > files_list=glob.glob(file_search_pattern) > for file in files_list: > try: > ftp.storlines('STOR ' + file, open(file)) > except Exception, e: > print ('Failed to FTP file: %s' %(file)) > ftp.close() > > Regards, > Anurag > > On Thu, Dec 23, 2010 at 5:33 AM, Matt Funk wrote: >> Hi, >> >> i was wondering whether someone can point me whether the following >> already exists. >> >> I want to connect to a server , download various files (for whose name i >> want to be able to use a wildcard), and store those files in a given >> location on the hard drive. If the file already exists i do not want to >> download it. >> >> This seems fairly trivial and i would assume that there should be some >> sort of implementation that does this easily but i didn't find anything >> googling it. >> >> Otherwise i was going to do it "by hand" using ftplib: >> 1) connect to server, >> 2) change to directory on server >> 3) get listing >> 4) match the file pattern i want to the listing >> 5) check if file already exists >> 6) download file if matched and doesn't exist >> >> Can anyone offer any advice whether this already done somewhere? >> >> thanks >> matt >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > -- > http://mail.python.org/mailman/listinfo/python-list From benedict.verheyen at gmail.com Thu Dec 23 04:04:13 2010 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Thu, 23 Dec 2010 10:04:13 +0100 Subject: compiling Python 2.7.1 with readline module fails on Debian (Virtualbox) In-Reply-To: <4D1239AD.7010907@pythonmeister.com> References: <4D1239AD.7010907@pythonmeister.com> Message-ID: On 22/12/2010 18:47, Stefan Sonnenberg-Carstens wrote: > Am 22.12.2010 09:33, schrieb Benedict Verheyen: >> > Did you try > > apt-get install build-essential > apt-get build-dep python2.7 > > before trying to compile ? > > Anyway, the config.log file is always of special interest. > Btw, which Debian release are you running ? > If the system is set up correctly it should not be necessary to change env vars to get it built. > > I use Debian stable so "apt-get build-dep python2.7" doesn't work. I removed all installed Python 2.7.1 files and so on and tried to build/install from scratch. Now i can't get Python to find the readline library. What is the normal procedure to make sure the readline library is found? I downloaded readline 6.1, build it and installed it to $HOME/local $HOME/local/lib contains libreadline.so. I did the following to try to enable detection of the libreadline: - export LD_LIBRARY_PATH=$HOME/local/lib:$LD_LIBRARY_PATH - vi Modules/Setup and uncomment the line that specifies the readline module. Added -L$HOME/local/lib - Tried ./configure with env CPPFLAGS="-I$HOME/local/include" LDFLAGS="-L$HOME/local/lib" - Edit setup.py, to add_dirs to $HOME/local/include and $HOME/local/lib - Tried to export CPPFLAGS and LDFLAGS Nothing seems to work. What am i doing wrong? Cheers, Benedict From wxjmfauth at gmail.com Thu Dec 23 04:47:35 2010 From: wxjmfauth at gmail.com (jmfauth) Date: Thu, 23 Dec 2010 01:47:35 -0800 (PST) Subject: Unable to decode file written by C++ wostringstream References: Message-ID: <51ba0526-f37d-493f-8593-463bd8ac7f9a@m35g2000vbn.googlegroups.com> On 23 Dez., 09:33, Yan Cheng CHEOK wrote: > Currently, I have the following text file (https://sites.google.com/site/yanchengcheok/Home/TEST.TXT?attredirect...) written by C++ wostringstream. > The coding of the file is utf-16le. You should take care of this coding when you *read* the file, and not when you display its content. >>> import io >>> with io.open('test.txt', 'r', encoding='utf-16le') as f: ... r = f.readlines() ... >>> len(r) 94 >>> r[:5] [u'\n', u' 0.000 1.500 3.000 0.526 0.527 0.527 0.00036 0.00109 1381.88 485.07\n', u' 0.000 1.500 3.000 1.084 1.085 1.086 0.00037 0.00111 1351.86 978.02\n', u' 0.000 1.500 3.000 1.166 1.167 1.168 0.00043 0.00130 1152.71 897.16\n', u' -3.000 0.000 3.000 -0.031 -0.029 -0.025 0.00158 0.00475 632.17 626.13\n'] >>> # from there, do what you wish with this list... >>> jmf From stefan.sonnenberg at pythonmeister.com Thu Dec 23 05:00:33 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Thu, 23 Dec 2010 11:00:33 +0100 Subject: compiling Python 2.7.1 with readline module fails on Debian (Virtualbox) In-Reply-To: References: <4D1239AD.7010907@pythonmeister.com> Message-ID: <4D131DC1.4060104@pythonmeister.com> Am 23.12.2010 10:04, schrieb Benedict Verheyen: > On 22/12/2010 18:47, Stefan Sonnenberg-Carstens wrote: >> Am 22.12.2010 09:33, schrieb Benedict Verheyen: > >> Did you try >> >> apt-get install build-essential >> apt-get build-dep python2.7 >> >> before trying to compile ? >> >> Anyway, the config.log file is always of special interest. >> Btw, which Debian release are you running ? >> If the system is set up correctly it should not be necessary to change env vars to get it built. >> >> > I use Debian stable so "apt-get build-dep python2.7" doesn't work. > I removed all installed Python 2.7.1 files and so on and tried to build/install from scratch. > Now i can't get Python to find the readline library. > What is the normal procedure to make sure the readline library is found? > > I downloaded readline 6.1, build it and installed it to $HOME/local > $HOME/local/lib contains libreadline.so. > > I did the following to try to enable detection of the libreadline: > > - export LD_LIBRARY_PATH=$HOME/local/lib:$LD_LIBRARY_PATH > - vi Modules/Setup and uncomment the line that specifies the readline module. > Added -L$HOME/local/lib > - Tried ./configure with env CPPFLAGS="-I$HOME/local/include" LDFLAGS="-L$HOME/local/lib" > - Edit setup.py, to add_dirs to $HOME/local/include and $HOME/local/lib > - Tried to export CPPFLAGS and LDFLAGS > > Nothing seems to work. > What am i doing wrong? > > Cheers, > Benedict > apt-get build-dep python 2.6 should do, the dependencies haven't changed (IMHO). Then wipe away $HOME/usr/local (if you can, btw), reset all env vars to default (perhaps reboot). Then untar python from scratch, cd into that dir, and type ./configure --prefix=$HOME/usr/local make make install that should be all. Otherwise your box is somewhat messed up. Anyway, your config.log is of special interest (did I say that already ?) From pavlovevidence at gmail.com Thu Dec 23 05:54:52 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 23 Dec 2010 02:54:52 -0800 (PST) Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Dec 22, 7:22?pm, Steven D'Aprano wrote: > There should be a mechanism for Python functions to distinguish between > unexpected exceptions (commonly known as "bugs"), which should be > reported as coming from wherever they come from, and documented, expected > exceptions, which should be reported as coming from the function > regardless of how deep the function call stack really is. No, -100. The traceback isn't the place for this. I've never disagreed with you more, and I've disagreed with you and awful lot. Carl Banks From ulrich.eckhardt at dominolaser.com Thu Dec 23 06:15:33 2010 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Thu, 23 Dec 2010 12:15:33 +0100 Subject: Unable to decode file written by C++ wostringstream References: Message-ID: Yan Cheng CHEOK wrote: > Currently, I have the following text file > (https://sites.google.com/site/yanchengcheok/Home/TEST.TXT?attredirects=0&d=1) > written by C++ wostringstream. Stringstream? I guess you meant wofstream, or? Anyway, the output encoding of C++ iostreams is implementation-defined, so you can't assume that such code is generally portable. If you want a certain encoding, you need to tell the ofstream using the codecvt facet of the locale, a websearch should turn up more info on that. If you have the data in memory and it is encoded as UTF-16 there (which is what MS Windows uses for its wchar_t) then you could also use a plain ofstream, open it with the binary flag and then simply write the memory to a file. In any case, you need to know the encoding in order to get the content into a Python string or unicode object, otherwise you will only get garbage. Good luck! Uli -- Domino Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From rolf.oltmans at gmail.com Thu Dec 23 07:01:03 2010 From: rolf.oltmans at gmail.com (Oltmans) Date: Thu, 23 Dec 2010 04:01:03 -0800 (PST) Subject: Hosting a Python based TCP server Message-ID: Hi all, I'm writing a very small TCP server(written in Python) and now I want to host it on some ISP so that it can be accessed anywhere from the Internet. I've never done that before so I thought I should ask for some advice. Do you guys know any good ISP that can let me do that? Most importantly, what is usually involved in order to make this happen? Please pardon my ignorance and I will really appreciate your reply. Thanks in advance. From icanbob at gmail.com Thu Dec 23 07:40:26 2010 From: icanbob at gmail.com (bobicanprogram) Date: Thu, 23 Dec 2010 04:40:26 -0800 (PST) Subject: Hosting a Python based TCP server References: Message-ID: <4f87d9de-43be-480b-af56-9912cf657211@t35g2000yqj.googlegroups.com> On Dec 23, 7:01 am, Oltmans wrote: > Hi all, > > I'm writing a very small TCP server(written in Python) and now I want > to host it on some ISP so that it can be accessed anywhere from the > Internet. I've never done that before so I thought I should ask for > some advice. Do you guys know any good ISP that can let me do that? > > Most importantly, what is usually involved in order to make this > happen? > > Please pardon my ignorance and I will really appreciate your reply. > Thanks in advance. If you are familiar with Linux a Linode (http://www.linode.com) might be a perfect option for you. They even offer month by month rentals. bob From python at bdurham.com Thu Dec 23 08:05:43 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 23 Dec 2010 08:05:43 -0500 Subject: Hosting a Python based TCP server In-Reply-To: References: Message-ID: <1293109543.5171.1411762127@webmail.messagingengine.com> Rolf, > I'm writing a very small TCP server (written in Python) and now I want to host it on some ISP so that it can be accessed anywhere from the Internet. I've never done that before so I thought I should ask for some advice. Do you guys know any good ISP that can let me do that? I'm a big fan of webfaction.com. I think they will support this type of project. Malcolm From awilliam at whitemice.org Thu Dec 23 08:06:38 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Thu, 23 Dec 2010 08:06:38 -0500 Subject: Hosting a Python based TCP server In-Reply-To: <4f87d9de-43be-480b-af56-9912cf657211@t35g2000yqj.googlegroups.com> References: <4f87d9de-43be-480b-af56-9912cf657211@t35g2000yqj.googlegroups.com> Message-ID: <1293109598.7957.11.camel@linux-yu4c.site> On Thu, 2010-12-23 at 04:40 -0800, bobicanprogram wrote: > On Dec 23, 7:01 am, Oltmans wrote: > > Hi all, > > I'm writing a very small TCP server(written in Python) and now I want > > to host it on some ISP so that it can be accessed anywhere from the > > Internet. I've never done that before so I thought I should ask for > > some advice. Do you guys know any good ISP that can let me do that? > > Most importantly, what is usually involved in order to make this > > happen? > > Please pardon my ignorance and I will really appreciate your reply. > > Thanks in advance. > If you are familiar with Linux a Linode (http://www.linode.com) might > be a perfect option for you. They even offer month by month rentals. +1 Linode; performance is good, support is excellent. From benedict.verheyen at gmail.com Thu Dec 23 08:09:41 2010 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Thu, 23 Dec 2010 14:09:41 +0100 Subject: compiling Python 2.7.1 with readline module fails on Debian (Virtualbox) In-Reply-To: <4D131DC1.4060104@pythonmeister.com> References: <4D1239AD.7010907@pythonmeister.com> <4D131DC1.4060104@pythonmeister.com> Message-ID: On 23/12/2010 11:00, Stefan Sonnenberg-Carstens wrote: > apt-get build-dep python 2.6 > should do, the dependencies haven't changed (IMHO). > Then wipe away $HOME/usr/local (if you can, btw), > reset all env vars to default (perhaps reboot). > Then untar python from scratch, cd into that dir, and type > ./configure --prefix=$HOME/usr/local > make > make install > > that should be all. > Otherwise your box is somewhat messed up. > > Anyway, your config.log is of special interest (did I say that already ?) I started from scratch. I tried to build readline 6 and 5, and installing the packages system wide as opposed to $HOME/local, but everytime Python fails to find it. On stable, apt-get build-dep python 2.6 doesn't work, but apt-get build-dep python 2.5 does so i did that. At configure time, the libreadline library is now found but i have no clue why it didn't find the readline version i built. At the end of the Python build, it still ends with this message: Failed to build these modules: readline The other modules that where automatically installed via the build-dep command are built successfully. I have pasted the config.log here: http://paste.pocoo.org/show/308859/ Thanks, Benedict From srbc2010 at gmail.com Thu Dec 23 08:31:52 2010 From: srbc2010 at gmail.com (paulraj) Date: Thu, 23 Dec 2010 05:31:52 -0800 (PST) Subject: hot Message-ID: http://srbc2010.blogspot.com http://srbcmusic.blogspot.com From fetchinson at googlemail.com Thu Dec 23 08:47:54 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 23 Dec 2010 14:47:54 +0100 Subject: Python Web App In-Reply-To: References: <907fa80e-1814-4ddb-be32-ec14cfd53fab@29g2000yqq.googlegroups.com> Message-ID: >>>> Anybody know where I can find a Python Development Environment in the >>>> form of a web app for use with Chrome OS. I have been looking for a >>>> few days and all i have been able to find is some old discussions with >>>> python developers talking about they will want one for the OS to be a >>>> success with them. >>> >>> Personally, I think a web app based IDE would be ghastly; but, you might >>> have a look at Mozilla Skywriter (formerly Bespin): >> >> Why grashtly? > > I don't personally think the web makes a good framework for highly > interactive applications as they must work within the constraints of the > browser and IDEs are highly interactive applications by their very nature. > Perhaps HTML5/CSS3 will change things; but, standard DOM manipulation, > as I am accustomed to seeing it, cannot generate the kind of rendering > that is available from native applications. Attempts to do so end up being > kludgy. > > It also cannot handle the kinds of desktop integrations that are common > for native applications without opening up serious security trust issues. > (Can everybody say ActiveX fiasco?) So, in essence, you are predicting that google's chrome OS will be a failure, right? > Finally, there are difficulties in handling keystrokes without conflicting > with the browser's native key bindings. I seldom ever touch a mouse > and I am a huge fan of vi, mutt, slrn, screen, ratpoison, etc. where > the primary interface is totally accessable through the keyboard without > having to tab through many options. Well, implementing vi or other text based tools in the browser is trivial. I mean it will function in exactly the same way as a native vi. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From catdude at gmail.com Thu Dec 23 09:34:00 2010 From: catdude at gmail.com (Dan M) Date: Thu, 23 Dec 2010 08:34:00 -0600 Subject: Hosting a Python based TCP server References: Message-ID: On Thu, 23 Dec 2010 04:01:03 -0800, Oltmans wrote: > Hi all, > > I'm writing a very small TCP server(written in Python) and now I want to > host it on some ISP so that it can be accessed anywhere from the > Internet. I've never done that before so I thought I should ask for some > advice. Do you guys know any good ISP that can let me do that? > > Most importantly, what is usually involved in order to make this happen? > > Please pardon my ignorance and I will really appreciate your reply. > Thanks in advance. Amazon Web Services is offering micro-instances (essentially a small virtual server) free for one year. Since you would have root access to the instance, you can run anything you want that doesn't violate Amazon's terms of service. Send me an e-mail directly (catdude at gmail dot com) if you have questions about it. Dan From benedict.verheyen at gmail.com Thu Dec 23 09:37:40 2010 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Thu, 23 Dec 2010 15:37:40 +0100 Subject: compiling Python 2.7.1 with readline module fails on Debian (Virtualbox) In-Reply-To: References: <4D1239AD.7010907@pythonmeister.com> <4D131DC1.4060104@pythonmeister.com> Message-ID: On 23/12/2010 14:09, Benedict Verheyen wrote: > > I started from scratch. > I tried to build readline 6 and 5, and installing the packages system wide > as opposed to $HOME/local, but everytime Python fails to find it. > > On stable, apt-get build-dep python 2.6 doesn't work, but > apt-get build-dep python 2.5 does so i did that. > > At configure time, the libreadline library is now found but i have no clue > why it didn't find the readline version i built. > At the end of the Python build, it still ends with this message: > > Failed to build these modules: > readline > > The other modules that where automatically installed via the build-dep > command are built successfully. > I have pasted the config.log here: > http://paste.pocoo.org/show/308859/ > > Thanks, > Benedict > I did a new test, again completely from scratch. I built ncurses and readline, installed them system wide (normal make install without a --prefix). Then i editing Modules/Setup.dist to include readline and adding the correct paths to the include and libs files. configure now finds the readline library. However, ncurses and readline still fail to be built. I had a look at the output of make. This is the error for ncurses: building '_curses' extension gcc -pthread -fPIC -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/home/benedict/local/include -I. -IInclude -I./Include -I/usr/local/include -I/home/benedict/src/Python-2.7.1/Include -I/home/benedict/src/Python-2.7.1 -c /home/benedict/src/Python-2.7.1/Modules/_cursesmodule.c -o build/temp.linux-x86_64-2.7/home/benedict/src/Python-2.7.1/Modules/_cursesmodule.o gcc -pthread -shared build/temp.linux-x86_64-2.7/home/benedict/src/Python-2.7.1/Modules/_cursesmodule.o -L/home/benedict/local/lib -L/usr/local/lib -L. -lncurses -lpython2.7 -o build/lib.linux-x86_64-2.7/_curses.so /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.3.2/../../../../lib/libncurses.a(lib_addch.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC /usr/lib/gcc/x86_64-linux-gnu/4.3.2/../../../../lib/libncurses.a: could not read symbols: Bad value collect2: ld returned 1 exit status building '_curses_panel' extension gcc -pthread -fPIC -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/home/benedict/local/include -I. -IInclude -I./Include -I/usr/local/include -I/home/benedict/src/Python-2.7.1/Include -I/home/benedict/src/Python-2.7.1 -c /home/benedict/src/Python-2.7.1/Modules/_curses_panel.c -o build/temp.linux-x86_64-2.7/home/benedict/src/Python-2.7.1/Modules/_curses_panel.o gcc -pthread -shared build/temp.linux-x86_64-2.7/home/benedict/src/Python-2.7.1/Modules/_curses_panel.o -L/home/benedict/local/lib -L/usr/local/lib -L. -lpanel -lncurses -lpython2.7 -o build/lib.linux-x86_64-2.7/_curses_panel.so /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.3.2/../../../../lib/libpanel.a(p_above.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC /usr/lib/gcc/x86_64-linux-gnu/4.3.2/../../../../lib/libpanel.a: could not read symbols: Bad value collect2: ld returned 1 exit status The error for readline: gcc -pthread -Xlinker -export-dynamic -o python \ Modules/python.o \ -L. -lpython2.7 -lpthread -ldl -lutil -lreadline -L/usr/local/lib -lm /usr/local/lib/libreadline.so: undefined reference to `PC' /usr/local/lib/libreadline.so: undefined reference to `tgetflag' /usr/local/lib/libreadline.so: undefined reference to `tgetent' /usr/local/lib/libreadline.so: undefined reference to `UP' /usr/local/lib/libreadline.so: undefined reference to `tputs' /usr/local/lib/libreadline.so: undefined reference to `tgoto' /usr/local/lib/libreadline.so: undefined reference to `tgetnum' /usr/local/lib/libreadline.so: undefined reference to `BC' /usr/local/lib/libreadline.so: undefined reference to `tgetstr' collect2: ld returned 1 exit status make: *** [python] Fout 1 Thanks, Benedict From joncle at googlemail.com Thu Dec 23 09:38:28 2010 From: joncle at googlemail.com (Jon Clements) Date: Thu, 23 Dec 2010 06:38:28 -0800 (PST) Subject: Hosting a Python based TCP server References: Message-ID: <0aa3012d-8cc0-414c-adad-2d0b028b7642@s18g2000vby.googlegroups.com> On Dec 23, 12:01?pm, Oltmans wrote: > Hi all, > > I'm writing a very small TCP server(written in Python) and now I want > to host it on some ISP so that it can be accessed anywhere from the > Internet. I've never done that before so I thought I should ask for > some advice. Do you guys know any good ISP that can let me do that? > > Most importantly, what is usually involved in order to make this > happen? > > Please pardon my ignorance and I will really appreciate your reply. > Thanks in advance. Check out http://wiki.python.org/moin/PythonHosting There's quite a few and they vary in features/pricing/OS used etc... but a lot of the info and links are there for you to find one right for you. hth Jon. From nospam at domain.invalid Thu Dec 23 10:40:44 2010 From: nospam at domain.invalid (William Gill) Date: Thu, 23 Dec 2010 10:40:44 -0500 Subject: simple games w/o pygame In-Reply-To: References: Message-ID: <4D136D7C.6050504@domain.invalid> Thanks everyone. These references will help greatly. I was about to take some javascript examples and rewrite them in Python. From stefan.sonnenberg at pythonmeister.com Thu Dec 23 11:46:44 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Thu, 23 Dec 2010 17:46:44 +0100 Subject: compiling Python 2.7.1 with readline module fails on Debian (Virtualbox) In-Reply-To: References: <4D1239AD.7010907@pythonmeister.com> <4D131DC1.4060104@pythonmeister.com> Message-ID: <4D137CF4.7000608@pythonmeister.com> Am 23.12.2010 15:37, schrieb Benedict Verheyen: > On 23/12/2010 14:09, Benedict Verheyen wrote: > >> I started from scratch. >> I tried to build readline 6 and 5, and installing the packages system wide >> as opposed to $HOME/local, but everytime Python fails to find it. >> >> On stable, apt-get build-dep python 2.6 doesn't work, but >> apt-get build-dep python 2.5 does so i did that. >> >> At configure time, the libreadline library is now found but i have no clue >> why it didn't find the readline version i built. >> At the end of the Python build, it still ends with this message: >> >> Failed to build these modules: >> readline >> >> The other modules that where automatically installed via the build-dep >> command are built successfully. >> I have pasted the config.log here: >> http://paste.pocoo.org/show/308859/ >> >> Thanks, >> Benedict >> > I did a new test, again completely from scratch. > I built ncurses and readline, installed them system wide (normal make install > without a --prefix). > Then i editing Modules/Setup.dist to include readline and adding the correct paths > to the include and libs files. configure now finds the readline library. > However, ncurses and readline still fail to be built. > > I had a look at the output of make. > This is the error for ncurses: > > building '_curses' extension > gcc -pthread -fPIC -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/home/benedict/local/include -I. > -IInclude -I./Include -I/usr/local/include -I/home/benedict/src/Python-2.7.1/Include -I/home/benedict/src/Python-2.7.1 -c > /home/benedict/src/Python-2.7.1/Modules/_cursesmodule.c -o build/temp.linux-x86_64-2.7/home/benedict/src/Python-2.7.1/Modules/_cursesmodule.o > > gcc -pthread -shared build/temp.linux-x86_64-2.7/home/benedict/src/Python-2.7.1/Modules/_cursesmodule.o -L/home/benedict/local/lib > -L/usr/local/lib -L. -lncurses -lpython2.7 -o build/lib.linux-x86_64-2.7/_curses.so > /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.3.2/../../../../lib/libncurses.a(lib_addch.o): relocation R_X86_64_32 against `a local symbol' > can not be used when making a shared object; recompile with -fPIC > /usr/lib/gcc/x86_64-linux-gnu/4.3.2/../../../../lib/libncurses.a: could not read symbols: Bad value > collect2: ld returned 1 exit status > > building '_curses_panel' extension > gcc -pthread -fPIC -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/home/benedict/local/include -I. > -IInclude -I./Include -I/usr/local/include -I/home/benedict/src/Python-2.7.1/Include -I/home/benedict/src/Python-2.7.1 -c > /home/benedict/src/Python-2.7.1/Modules/_curses_panel.c -o build/temp.linux-x86_64-2.7/home/benedict/src/Python-2.7.1/Modules/_curses_panel.o > > gcc -pthread -shared build/temp.linux-x86_64-2.7/home/benedict/src/Python-2.7.1/Modules/_curses_panel.o -L/home/benedict/local/lib > -L/usr/local/lib -L. -lpanel -lncurses -lpython2.7 -o build/lib.linux-x86_64-2.7/_curses_panel.so > /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.3.2/../../../../lib/libpanel.a(p_above.o): relocation R_X86_64_32 against `a local symbol' can > not be used when making a shared object; recompile with -fPIC > /usr/lib/gcc/x86_64-linux-gnu/4.3.2/../../../../lib/libpanel.a: could not read symbols: Bad value > collect2: ld returned 1 exit status > > The error for readline: > > gcc -pthread -Xlinker -export-dynamic -o python \ > Modules/python.o \ > -L. -lpython2.7 -lpthread -ldl -lutil -lreadline -L/usr/local/lib -lm > /usr/local/lib/libreadline.so: undefined reference to `PC' > /usr/local/lib/libreadline.so: undefined reference to `tgetflag' > /usr/local/lib/libreadline.so: undefined reference to `tgetent' > /usr/local/lib/libreadline.so: undefined reference to `UP' > /usr/local/lib/libreadline.so: undefined reference to `tputs' > /usr/local/lib/libreadline.so: undefined reference to `tgoto' > /usr/local/lib/libreadline.so: undefined reference to `tgetnum' > /usr/local/lib/libreadline.so: undefined reference to `BC' > /usr/local/lib/libreadline.so: undefined reference to `tgetstr' > collect2: ld returned 1 exit status > make: *** [python] Fout 1 > > Thanks, > Benedict > It seems some libs are compiled without PIC (position indepentent code), but python should be. That will not work. I'm currently setting up a VM, to try to follow the steps. Why do you want to build a readline etc when it is in the system ? From moura.mario at gmail.com Thu Dec 23 12:26:47 2010 From: moura.mario at gmail.com (macm) Date: Thu, 23 Dec 2010 09:26:47 -0800 (PST) Subject: Partition Recursive Message-ID: Hi Folks I have this: url = 'http://docs.python.org/dev/library/stdtypes.html? highlight=partition#str.partition' So I want convert to myList = ['http',':','//','docs','.','python','.','org','/','dev','/','library','/','stdtypes','.','html','?','highlight','=','partition','#','str','.','partition'] The reserved char are: specialMeaning = ["//",";","/", "?", ":", "@", "=" , "&","#"] Regards Mario From orasnita at gmail.com Thu Dec 23 12:33:14 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Thu, 23 Dec 2010 19:33:14 +0200 Subject: Python Web App References: <907fa80e-1814-4ddb-be32-ec14cfd53fab@29g2000yqq.googlegroups.com> Message-ID: From: "Daniel Fetchinson" >>>>> Anybody know where I can find a Python Development Environment in the >>>>> form of a web app for use with Chrome OS. I have been looking for a >>>>> few days and all i have been able to find is some old discussions with >>>>> python developers talking about they will want one for the OS to be a >>>>> success with them. >>>> >>>> Personally, I think a web app based IDE would be ghastly; but, you might >>>> have a look at Mozilla Skywriter (formerly Bespin): >>> >>> Why grashtly? >> >> I don't personally think the web makes a good framework for highly >> interactive applications as they must work within the constraints of the >> browser and IDEs are highly interactive applications by their very nature. >> Perhaps HTML5/CSS3 will change things; but, standard DOM manipulation, >> as I am accustomed to seeing it, cannot generate the kind of rendering >> that is available from native applications. Attempts to do so end up being >> kludgy. >> >> It also cannot handle the kinds of desktop integrations that are common >> for native applications without opening up serious security trust issues. >> (Can everybody say ActiveX fiasco?) > > So, in essence, you are predicting that google's chrome OS will be a > failure, right? It will surely be. But it won't, because Google's monopoly in an important field will help it to promote that OS, not because that OS will be so great. >> Finally, there are difficulties in handling keystrokes without conflicting >> with the browser's native key bindings. I seldom ever touch a mouse >> and I am a huge fan of vi, mutt, slrn, screen, ratpoison, etc. where >> the primary interface is totally accessable through the keyboard without >> having to tab through many options. > > Well, implementing vi or other text based tools in the browser is > trivial. I mean it will function in exactly the same way as a native > vi. Not exactly. Because not all the computer users can see, and the browsers don't offer the same accessibility features for screen readers as the standard GUIS. (And Google's software is very poor in this field anyway.) Octavian From python at mrabarnett.plus.com Thu Dec 23 12:49:00 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 23 Dec 2010 17:49:00 +0000 Subject: Partition Recursive In-Reply-To: References: Message-ID: <4D138B8C.5040908@mrabarnett.plus.com> On 23/12/2010 17:26, macm wrote: > Hi Folks > > I have this: > > url = 'http://docs.python.org/dev/library/stdtypes.html? > highlight=partition#str.partition' > > So I want convert to > > myList = > ['http',':','//','docs','.','python','.','org','/','dev','/','library','/','stdtypes','.','html','?','highlight','=','partition','#','str','.','partition'] > > The reserved char are: > > specialMeaning = ["//",";","/", "?", ":", "@", "=" , "&","#"] > I would use re.findall. From joncle at googlemail.com Thu Dec 23 12:57:54 2010 From: joncle at googlemail.com (Jon Clements) Date: Thu, 23 Dec 2010 09:57:54 -0800 (PST) Subject: Partition Recursive References: Message-ID: On Dec 23, 5:26?pm, macm wrote: > Hi Folks > > I have this: > > url = 'http://docs.python.org/dev/library/stdtypes.html? > highlight=partition#str.partition' > > So I want convert to > > myList = > ['http',':','//','docs','.','python','.','org','/','dev','/','library','/','stdtypes','.','html','?','highlight','=','partition','#','str','.','partition'] > > The reserved char are: > > specialMeaning = ["//",";","/", "?", ":", "@", "=" , "&","#"] > > Regards > > Mario I would use urlparse.urlsplit, then split further, if required. >>> urlsplit(url) SplitResult(scheme='http', netloc='docs.python.org', path='/dev/ library/stdtypes.html', query='highlight=partition', fragment='str.partition') Jon. From moura.mario at gmail.com Thu Dec 23 13:05:39 2010 From: moura.mario at gmail.com (macm) Date: Thu, 23 Dec 2010 10:05:39 -0800 (PST) Subject: Partition Recursive References: Message-ID: Hi urlparse isnt a option. My reasult must be: myList = ['http',':','//','docs','.','python','.','org','/','dev','/','library','/', 'stdtypes','.','html','?','highlight','=','partition','#','str','.','partition'] re module is slow. Even I make a loop in urlparse.urlsplit I can lost specialMeaning order. Seen easy but best aproach will be recursive. Regards Mario On Dec 23, 3:57?pm, Jon Clements wrote: > On Dec 23, 5:26?pm, macm wrote: > > > > > > > > > > > Hi Folks > > > I have this: > > > url = 'http://docs.python.org/dev/library/stdtypes.html? > > highlight=partition#str.partition' > > > So I want convert to > > > myList = > > ['http',':','//','docs','.','python','.','org','/','dev','/','library','/', 'stdtypes','.','html','?','highlight','=','partition','#','str','.','partit ion'] > > > The reserved char are: > > > specialMeaning = ["//",";","/", "?", ":", "@", "=" , "&","#"] > > > Regards > > > Mario > > I would use urlparse.urlsplit, then split further, if required. > > >>> urlsplit(url) > > SplitResult(scheme='http', netloc='docs.python.org', path='/dev/ > library/stdtypes.html', query='highlight=partition', > fragment='str.partition') > > Jon. From armin.hoebart at aon.at Thu Dec 23 13:43:09 2010 From: armin.hoebart at aon.at (Tintifax) Date: Thu, 23 Dec 2010 10:43:09 -0800 (PST) Subject: installing scikits.timeseries Message-ID: <30524255.post@talk.nabble.com> I tried to install scikits.timeseries via "easy_install" and received following Error Message: Found executable C:\MinGW32\bin\gcc.exe Found executable C:\MinGW32\bin\g++.exe zip_safe flag not set; analyzing archive contents... scikits.timeseries.version: module references __file__ Adding scikits.timeseries 0.91.3 to easy-install.pth file Installed c:\python26\lib\site-packages\scikits.timeseries-0.91.3-py2.6-win32.eg g Processing dependencies for scikits.timeseries Finished processing dependencies for scikits.timeseries C:\Python26\lib\site-packages\numpy\distutils\misc_util.py:251: RuntimeWarning: Parent module 'numpy.distutils' not found while handling absolute import from numpy.distutils import log Does anybody have an idea how I can install scikits.timeseries without getting this error message? I really appreciate every little hint. Thank You!! -- View this message in context: http://old.nabble.com/installing-scikits.timeseries-tp30524255p30524255.html Sent from the Python - python-list mailing list archive at Nabble.com. From hniksic at xemacs.org Thu Dec 23 13:57:13 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Thu, 23 Dec 2010 19:57:13 +0100 Subject: round in 2.6 and 2.7 Message-ID: <87sjxoco6u.fsf@xemacs.org> I stumbled upon this. Python 2.6: Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> 9.95 9.9499999999999993 >>> "%.16g" % 9.95 '9.949999999999999' >>> round(9.95, 1) 10.0 So it seems that Python is going out of its way to intuitively round 9.95, while the repr retains the unnecessary digits. However, with 2.7 it's exactly the opposite: Python 2.7.0+ (r27:82500, Sep 15 2010, 18:04:55) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> 9.95 9.95 >>> "%.16g" % 9.95 '9.949999999999999' >>> round(9.95, 1) 9.9 Is the change to round() expected? From usernet at ilthio.net Thu Dec 23 14:18:24 2010 From: usernet at ilthio.net (Tim Harig) Date: Thu, 23 Dec 2010 19:18:24 +0000 (UTC) Subject: Python Web App References: <907fa80e-1814-4ddb-be32-ec14cfd53fab@29g2000yqq.googlegroups.com> Message-ID: On 2010-12-23, Daniel Fetchinson wrote: >> I don't personally think the web makes a good framework for highly >> interactive applications as they must work within the constraints of the >> browser and IDEs are highly interactive applications by their very nature. >> Perhaps HTML5/CSS3 will change things; but, standard DOM manipulation, >> as I am accustomed to seeing it, cannot generate the kind of rendering >> that is available from native applications. Attempts to do so end up being >> kludgy. >> >> It also cannot handle the kinds of desktop integrations that are common >> for native applications without opening up serious security trust issues. >> (Can everybody say ActiveX fiasco?) > > So, in essence, you are predicting that google's chrome OS will be a > failure, right? No, most people are happy using web based email interfaces and never even know that native email clients exist. More is the pity. >> Finally, there are difficulties in handling keystrokes without conflicting >> with the browser's native key bindings. I seldom ever touch a mouse >> and I am a huge fan of vi, mutt, slrn, screen, ratpoison, etc. where >> the primary interface is totally accessable through the keyboard without >> having to tab through many options. > > Well, implementing vi or other text based tools in the browser is > trivial. I mean it will function in exactly the same way as a native > vi. Not exactly. I occassionally use web based terminals (Ajaxterm, Anyterm, Shellinabox, etc) to access my systems. This works only partially since many of the keystrokes I use conflict with keystrokes that the browser uses or which cause signals that the browser either does not catch or does not pass on to be accessed by client side scripting. The terminals must therefore place buttons or synthetic keyboards on the screen to allow you to simulate the keystrokes. That kind of negates the advantages of keystrokes in the first place. It doesn't make fore a pleasant experience. From moura.mario at gmail.com Thu Dec 23 14:31:37 2010 From: moura.mario at gmail.com (macm) Date: Thu, 23 Dec 2010 11:31:37 -0800 (PST) Subject: round in 2.6 and 2.7 References: <87sjxoco6u.fsf@xemacs.org> Message-ID: <1319405f-1f4b-4193-ab8e-8595b279b71f@g25g2000yqn.googlegroups.com> On Dec 23, 4:57?pm, Hrvoje Niksic wrote: > I stumbled upon this. ?Python 2.6: > > Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) > [GCC 4.4.5] on linux2 > Type "help", "copyright", "credits" or "license" for more information.>>> 9.95 > 9.9499999999999993 > >>> "%.16g" % 9.95 > '9.949999999999999' > >>> round(9.95, 1) > > 10.0 > > So it seems that Python is going out of its way to intuitively round > 9.95, while the repr retains the unnecessary digits. ?However, with 2.7 > it's exactly the opposite: > > Python 2.7.0+ (r27:82500, Sep 15 2010, 18:04:55) > [GCC 4.4.5] on linux2 > Type "help", "copyright", "credits" or "license" for more information.>>> 9.95 > 9.95 > >>> "%.16g" % 9.95 > '9.949999999999999' > >>> round(9.95, 1) > > 9.9 > > Is the change to round() expected? My guess is use decimal module. Regards mario From please_post at nomail.edu Thu Dec 23 14:40:04 2010 From: please_post at nomail.edu (bill) Date: Thu, 23 Dec 2010 19:40:04 +0000 (UTC) Subject: general problem when subclassing a built-in class References: Message-ID: In kj writes: >Where in the Python documentation can one find the information >required to determine the minimal[1] set of methods that one would >need to override to achieve this goal? > I don't know the answer to that question, but imho it's the wrong question to ask. Instead you should be asking what design will let me implement the subclass making the fewest possible assumptions about the superclass. (hint: the design you're thinking about leads to a world of pain.) > >2. other than the added capability described in (1), an instance >of TSDict should behave *exactly* like a built-in dictionary. (minor point: what about repr? it shouldn't look like a dict, imho) > >#--------------------------------------------------------------------------- >from time import time >class TSDict(dict): > def __setitem__(self, key, value): > # save the value and timestamp for key as a tuple; > # see footnote [2] > dict.__setitem__(self, key, (value, time())) > def __getitem__(self, key): > # extract the value from the value-timestamp pair and return it > return dict.__getitem__(self, key)[0] > def get_timestamp(self, key): > # extract the timestamp from the value-timestamp pair and return it > return dict.__getitem__(self, key)[1] >#--------------------------------------------------------------------------- man, you're asking for trouble! even if you knew all you want to know, unless you had some guarantee that it wouldn't change in a later release, you'd still have to override pretty much all the methods. the problem here is not lack of information, but a horrible design (sorry to be blunt). Just keep the timestamps in a parallel dict and get on with life: from time import time from collections import MutableMapping class TSDict2(dict, MutableMapping): def __init__(self, *args, **kwargs): dict.__init__(self, *args, **kwargs) self.__ts = dict.fromkeys(self.keys(), time()) def __setitem__(self, key, value): self.__ts[key] = time() dict.__setitem__(self, key, value) setdefault = MutableMapping.setdefault update = MutableMapping.update def get_timestamp(self, key): if self.has_key(key): return self.__ts[key] raise KeyError(key) that just took the time needed to type it and worked the first time: >>> d = TSDict2((('uno', 1), ('dos', 2)), tres=3, cuatro=4); d['cinco'] = 5; d.setdefault('six', 6); 6 >>> d.update((('tres', 'amigos'), ('seven', 7),), eight=8); d {'seven': 7, 'six': 6, 'cuatro': 4, 'cinco': 5, 'eight': 8, 'dos': 2, 'tres': 'amigos', 'uno': 1} >>> for p in sorted([(k, d.get_timestamp(k)) for k in d.keys()], key=lambda p: p[1]): print "%s\t%f" % p ... cuatro 1293131496.917215 dos 1293131496.917215 uno 1293131496.917215 cinco 1293131496.917233 six 1293131496.917279 tres 1293131501.676962 seven 1293131501.676974 eight 1293131501.676981 If you insist on bashing your skull against your original problem, take a look at collections.OrderedDict or collections.Counter to see how they use ABCs to tame dict. (still, even if you used all the remaining available MutableMapping methods in your class, i don't know how you'd get the dict constructor to return the right value, ie no timestamps, when you pass it an instance of your subclass as argument. i don't think there's a TSDict.__method__ you can write for that... anyway my TSDict2 doesn't have this problem either.) take home message: respect the privacy of your superclasses and they'll be nice to you. --bill From martin at v.loewis.de Thu Dec 23 14:50:50 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Thu, 23 Dec 2010 20:50:50 +0100 Subject: round in 2.6 and 2.7 In-Reply-To: <87sjxoco6u.fsf@xemacs.org> References: <87sjxoco6u.fsf@xemacs.org> Message-ID: <4D13A81A.5030903@v.loewis.de> > Type "help", "copyright", "credits" or "license" for more information. >>>> 9.95 > 9.9499999999999993 >>>> "%.16g" % 9.95 > '9.949999999999999' >>>> round(9.95, 1) > 10.0 > > So it seems that Python is going out of its way to intuitively round > 9.95, while the repr retains the unnecessary digits. The 2.6 result is simply incorrect. 9.95 cannot be represented as a floating point number; the number that is closest to it is actually smaller than 9.95. Rounding that number should give 9.9 (or something close to it - 9.9 cannot be represented, either), not 10.0. >>>> round(9.95, 1) > 9.9 > > Is the change to round() expected? Yes. It's a bug fix described in "What's new in Python 2.7" thus: Float-to-string and string-to-float conversions are correctly rounded. The round() function is also now correctly rounded. Not sure that this is correct English; I think it means that the round() function is now correct. Regards, Martin From stefan.sonnenberg at pythonmeister.com Thu Dec 23 14:55:15 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Thu, 23 Dec 2010 20:55:15 +0100 Subject: compiling Python 2.7.1 with readline module fails on Debian (Virtualbox) In-Reply-To: References: <4D1239AD.7010907@pythonmeister.com> <4D131DC1.4060104@pythonmeister.com> Message-ID: <4D13A923.8060208@pythonmeister.com> Am 23.12.2010 15:37, schrieb Benedict Verheyen: > On 23/12/2010 14:09, Benedict Verheyen wrote: > >> I started from scratch. >> I tried to build readline 6 and 5, and installing the packages system wide >> as opposed to $HOME/local, but everytime Python fails to find it. >> >> On stable, apt-get build-dep python 2.6 doesn't work, but >> apt-get build-dep python 2.5 does so i did that. >> >> At configure time, the libreadline library is now found but i have no clue >> why it didn't find the readline version i built. >> At the end of the Python build, it still ends with this message: >> >> Failed to build these modules: >> readline >> >> The other modules that where automatically installed via the build-dep >> command are built successfully. >> I have pasted the config.log here: >> http://paste.pocoo.org/show/308859/ >> >> Thanks, >> Benedict >> > I did a new test, again completely from scratch. > I built ncurses and readline, installed them system wide (normal make install > without a --prefix). > Then i editing Modules/Setup.dist to include readline and adding the correct paths > to the include and libs files. configure now finds the readline library. > However, ncurses and readline still fail to be built. > > I had a look at the output of make. > This is the error for ncurses: > > building '_curses' extension > gcc -pthread -fPIC -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/home/benedict/local/include -I. > -IInclude -I./Include -I/usr/local/include -I/home/benedict/src/Python-2.7.1/Include -I/home/benedict/src/Python-2.7.1 -c > /home/benedict/src/Python-2.7.1/Modules/_cursesmodule.c -o build/temp.linux-x86_64-2.7/home/benedict/src/Python-2.7.1/Modules/_cursesmodule.o > > gcc -pthread -shared build/temp.linux-x86_64-2.7/home/benedict/src/Python-2.7.1/Modules/_cursesmodule.o -L/home/benedict/local/lib > -L/usr/local/lib -L. -lncurses -lpython2.7 -o build/lib.linux-x86_64-2.7/_curses.so > /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.3.2/../../../../lib/libncurses.a(lib_addch.o): relocation R_X86_64_32 against `a local symbol' > can not be used when making a shared object; recompile with -fPIC > /usr/lib/gcc/x86_64-linux-gnu/4.3.2/../../../../lib/libncurses.a: could not read symbols: Bad value > collect2: ld returned 1 exit status > > building '_curses_panel' extension > gcc -pthread -fPIC -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/home/benedict/local/include -I. > -IInclude -I./Include -I/usr/local/include -I/home/benedict/src/Python-2.7.1/Include -I/home/benedict/src/Python-2.7.1 -c > /home/benedict/src/Python-2.7.1/Modules/_curses_panel.c -o build/temp.linux-x86_64-2.7/home/benedict/src/Python-2.7.1/Modules/_curses_panel.o > > gcc -pthread -shared build/temp.linux-x86_64-2.7/home/benedict/src/Python-2.7.1/Modules/_curses_panel.o -L/home/benedict/local/lib > -L/usr/local/lib -L. -lpanel -lncurses -lpython2.7 -o build/lib.linux-x86_64-2.7/_curses_panel.so > /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.3.2/../../../../lib/libpanel.a(p_above.o): relocation R_X86_64_32 against `a local symbol' can > not be used when making a shared object; recompile with -fPIC > /usr/lib/gcc/x86_64-linux-gnu/4.3.2/../../../../lib/libpanel.a: could not read symbols: Bad value > collect2: ld returned 1 exit status > > The error for readline: > > gcc -pthread -Xlinker -export-dynamic -o python \ > Modules/python.o \ > -L. -lpython2.7 -lpthread -ldl -lutil -lreadline -L/usr/local/lib -lm > /usr/local/lib/libreadline.so: undefined reference to `PC' > /usr/local/lib/libreadline.so: undefined reference to `tgetflag' > /usr/local/lib/libreadline.so: undefined reference to `tgetent' > /usr/local/lib/libreadline.so: undefined reference to `UP' > /usr/local/lib/libreadline.so: undefined reference to `tputs' > /usr/local/lib/libreadline.so: undefined reference to `tgoto' > /usr/local/lib/libreadline.so: undefined reference to `tgetnum' > /usr/local/lib/libreadline.so: undefined reference to `BC' > /usr/local/lib/libreadline.so: undefined reference to `tgetstr' > collect2: ld returned 1 exit status > make: *** [python] Fout 1 > > Thanks, > Benedict > OK, I compiled it successfully under Debian 5.07 i386. ncurses and libreadline are compiled from hand, both --prefix=$HOME/usr/local. For python the only extra needed was export LD_LIBRARY_PATH=$HOME/usr/local/lib:$LD_LIBRARY_PATH From dasacc22 at gmail.com Thu Dec 23 15:05:38 2010 From: dasacc22 at gmail.com (dasacc22) Date: Thu, 23 Dec 2010 12:05:38 -0800 (PST) Subject: daml 0.1.4 released, a python markup language for the web Message-ID: <275c92ac-ad6a-432a-bf8f-c12c9f33fee5@k25g2000vbl.googlegroups.com> Notes on the latest updates can be read here: http://dasacc22.wordpress.com/2010/12/22/daml-0-1-4-release/ The source is on github: https://github.com/dasacc22/daml An sdist is available on pypi: http://pypi.python.org/pypi/DAML/0.1.4 daml is for outlining html with dynamic content. Features inline python and a sandbox you can update with custom functions (so they are in memory, versus writing the function in the template). As part of a bigger project, daml is playing a part in completely removing the "view" from controller code and will feature an extension for requesting data via IPC from your controllers (or anywhere else for that matter if you want to wait), so no more tacking on related or semi-related views to a particular controller. daml currently depends on cython. There are a few utility functions that are written in cython and it also depends on lxml (written in cython) and makes use of that during the final document build which is done in cython as well. Down the road, after I get all of the specifics worked out for the syntax, cython and lxml will be optional (and necessary if you want it to be as fast as possible), but theres absolutely no reason for there to not be a pure python module. It's really not that complex. daml may also be recognized as a haml implementation. The only things adapted is the use of #id and .class tag hashes and being indention based (if that counts), and particularly the source of inspiration for filters. Beyond that, they are two pretty different things. Also, daml isn't much of a name for anything. Under consideration currently is damsel, da Markup 4 Savvy & Eloquent Ladies (and gentlemen). Just think repunzel in a tower with OSI climbing her hair to save the View[1] from the MVC-implementation-of-hell Tower. [1] She must be a looker From nobody at nowhere.com Thu Dec 23 15:27:59 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 23 Dec 2010 20:27:59 +0000 Subject: Trying to parse a HUGE(1gb) xml file References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> Message-ID: On Wed, 22 Dec 2010 23:54:34 +0100, Stefan Sonnenberg-Carstens wrote: > Normally (what is normal, anyway?) such files are auto-generated, > and are something that has a apparent similarity with a database query > result, encapsuled in xml. > Most of the time the structure is same for every "row" thats in there. > So, a very unpythonic but fast, way would be to let awk resemble the > records and write them in csv format to stdout. awk works well if the input is formatted such that each line is a record; it's not so good otherwise. XML isn't a line-oriented format; in particular, there are many places where both newlines and spaces are just whitespace. A number of XML generators will "word wrap" the resulting XML to make it more human readable, so line-oriented tools aren't a good idea. From nobody at nowhere.com Thu Dec 23 15:32:38 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 23 Dec 2010 20:32:38 +0000 Subject: Generator question References: <1jtwvox.1pxdxm314l5m06N%see@sig.for.address> Message-ID: On Wed, 22 Dec 2010 15:49:31 -0800, Dan Stromberg wrote: > def generator(): > i = 0 > while True: > yield i > i += 1 Shorter version: from itertools import count as generator From stefan.sonnenberg at pythonmeister.com Thu Dec 23 16:02:40 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Thu, 23 Dec 2010 22:02:40 +0100 Subject: round in 2.6 and 2.7 In-Reply-To: <87sjxoco6u.fsf@xemacs.org> References: <87sjxoco6u.fsf@xemacs.org> Message-ID: <4D13B8F0.7080605@pythonmeister.com> Am 23.12.2010 19:57, schrieb Hrvoje Niksic: > I stumbled upon this. Python 2.6: > > Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) > [GCC 4.4.5] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> 9.95 > 9.9499999999999993 >>>> "%.16g" % 9.95 > '9.949999999999999' >>>> round(9.95, 1) > 10.0 > > So it seems that Python is going out of its way to intuitively round > 9.95, while the repr retains the unnecessary digits. However, with 2.7 > it's exactly the opposite: > > Python 2.7.0+ (r27:82500, Sep 15 2010, 18:04:55) > [GCC 4.4.5] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> 9.95 > 9.95 >>>> "%.16g" % 9.95 > '9.949999999999999' >>>> round(9.95, 1) > 9.9 > > Is the change to round() expected? Indeed: http://svn.python.org/view?view=rev&revision=76373 From stefan.sonnenberg at pythonmeister.com Thu Dec 23 16:34:06 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Thu, 23 Dec 2010 22:34:06 +0100 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> Message-ID: <4D13C04E.6070103@pythonmeister.com> Am 23.12.2010 21:27, schrieb Nobody: > On Wed, 22 Dec 2010 23:54:34 +0100, Stefan Sonnenberg-Carstens wrote: > >> Normally (what is normal, anyway?) such files are auto-generated, >> and are something that has a apparent similarity with a database query >> result, encapsuled in xml. >> Most of the time the structure is same for every "row" thats in there. >> So, a very unpythonic but fast, way would be to let awk resemble the >> records and write them in csv format to stdout. > awk works well if the input is formatted such that each line is a record; You shouldn't tell it to awk. > it's not so good otherwise. XML isn't a line-oriented format; in > particular, there are many places where both newlines and spaces are just > whitespace. A number of XML generators will "word wrap" the resulting XML > to make it more human readable, so line-oriented tools aren't a good idea. I never had the opportunity seeing awk fail on this task :-) For large datasets I always have huge question marks if one says "xml". But I don't want to start a flame war. From mafunk at nmsu.edu Thu Dec 23 16:41:15 2010 From: mafunk at nmsu.edu (Matt Funk) Date: Thu, 23 Dec 2010 14:41:15 -0700 Subject: using python ftp In-Reply-To: References: <4D1291CB.5010404@nmsu.edu> Message-ID: <4D13C1FB.6030808@nmsu.edu> Hi, thanks for the response. I kind of was thinking along those lines. The thing is though is that 'grop' appears to work on the local directory only (and not on the remote one which i need) Anyway, i think i'll just do via iterating through a the remote directory listing and then match it via regular pattern. Not sure if this is the best/most elegant way. But it should work. thanks matt On 12/23/2010 1:46 AM, Octavian Rasnita wrote: > Can this lib also work with ftps? > > Thanks. > > Octavian > > ----- Original Message ----- > From: "Anurag Chourasia" > To: "Matt Funk" > Cc: > Sent: Thursday, December 23, 2010 4:12 AM > Subject: Re: using python ftp > > >> Hi Matt, >> >> I have a snippet to "upload" files (that match a particular search >> pattern) to a remote server. >> >> Variable names are self explanatory. You could tweak this a little to >> "download" files instead. >> >> from ftplib import FTP >> ftp = FTP(hostname) >> ftp.login(user_id,passwd) >> ftp.cwd(remote_directory) >> files_list=glob.glob(file_search_pattern) >> for file in files_list: >> try: >> ftp.storlines('STOR ' + file, open(file)) >> except Exception, e: >> print ('Failed to FTP file: %s' %(file)) >> ftp.close() >> >> Regards, >> Anurag >> >> On Thu, Dec 23, 2010 at 5:33 AM, Matt Funk wrote: >>> Hi, >>> >>> i was wondering whether someone can point me whether the following >>> already exists. >>> >>> I want to connect to a server , download various files (for whose name i >>> want to be able to use a wildcard), and store those files in a given >>> location on the hard drive. If the file already exists i do not want to >>> download it. >>> >>> This seems fairly trivial and i would assume that there should be some >>> sort of implementation that does this easily but i didn't find anything >>> googling it. >>> >>> Otherwise i was going to do it "by hand" using ftplib: >>> 1) connect to server, >>> 2) change to directory on server >>> 3) get listing >>> 4) match the file pattern i want to the listing >>> 5) check if file already exists >>> 6) download file if matched and doesn't exist >>> >>> Can anyone offer any advice whether this already done somewhere? >>> >>> thanks >>> matt >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >>> >> -- >> http://mail.python.org/mailman/listinfo/python-list From smallpox911 at gmail.com Thu Dec 23 17:01:20 2010 From: smallpox911 at gmail.com (small Pox) Date: Thu, 23 Dec 2010 14:01:20 -0800 (PST) Subject: What is the the best style and theory of writing a complier in your language Message-ID: What is the the best style and theory of writing a complier in your language Maybe a book will suffice. http://www.veteranstoday.com/2010/12/18/gordon-duff-gov-jesse-ventura-proves-911-cover-up-will-americas-government-fall/ I want to parse the contents of the above link into hebrew audio. CHEERIOS From franapoli at gmail.com Thu Dec 23 18:07:16 2010 From: franapoli at gmail.com (Ciccio) Date: Thu, 23 Dec 2010 15:07:16 -0800 (PST) Subject: Regular expression for "key = value" pairs References: <87tyi5wxyg.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <148d96c0-1b44-4a0f-993d-a07015b5b4a1@v17g2000vbo.googlegroups.com> I extracted an isolated problem from a slightly more complex situation, that's why I'm using REs. Thank you all for your help, my problem is now solved. From mpnordland at gmail.com Thu Dec 23 18:07:38 2010 From: mpnordland at gmail.com (mpnordland) Date: Thu, 23 Dec 2010 18:07:38 -0500 Subject: Catching user switching and getting current active user from root on linux In-Reply-To: <51d9390d-be72-49fe-a63b-5a05832c53e8@fu15g2000vbb.googlegroups.com> References: <1a9bdbd4-2997-4e0f-a24f-cd148247e312@r40g2000prh.googlegroups.com> <8739qhs6dz.fsf.mdw@metalzone.distorted.org.uk> <797ba948-c608-4ed5-b2eb-25177932da91@o4g2000yqd.googlegroups.com> <4d04117b$0$30000$c3e8da3$5496439d@news.astraweb.com> <51d9390d-be72-49fe-a63b-5a05832c53e8@fu15g2000vbb.googlegroups.com> Message-ID: Ok, thank you. I will go look at the resources mentioned. From jlundell at pobox.com Thu Dec 23 18:21:42 2010 From: jlundell at pobox.com (JLundell) Date: Thu, 23 Dec 2010 15:21:42 -0800 (PST) Subject: class inheritance In-Reply-To: Message-ID: That's nice, Ethan, especially in that it saves having to explicitly find and list all the methods being covered. It's perhaps not quite so critical for a Fraction-based class, since the set of methods to be covered is fairly well contained, but that's not always going to be the case. The approach I mentioned earlier (rebinding __class__) is a little faster, since it avoids a call to __new__, but the difference is no doubt negligible in this example, since rational arithmetic isn't exactly lightning fast. Thanks. From jlundell at pobox.com Thu Dec 23 18:21:42 2010 From: jlundell at pobox.com (JLundell) Date: Thu, 23 Dec 2010 15:21:42 -0800 (PST) Subject: class inheritance In-Reply-To: Message-ID: That's nice, Ethan, especially in that it saves having to explicitly find and list all the methods being covered. It's perhaps not quite so critical for a Fraction-based class, since the set of methods to be covered is fairly well contained, but that's not always going to be the case. The approach I mentioned earlier (rebinding __class__) is a little faster, since it avoids a call to __new__, but the difference is no doubt negligible in this example, since rational arithmetic isn't exactly lightning fast. Thanks. From rhodri at wildebst.demon.co.uk Thu Dec 23 18:34:46 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 23 Dec 2010 23:34:46 -0000 Subject: Partition Recursive References: Message-ID: Please don't top-post, it makes everything harder to read. (Re-ordering to make sense...) On Thu, 23 Dec 2010 18:05:39 -0000, macm wrote: > On Dec 23, 3:57 pm, Jon Clements wrote: >> I would use urlparse.urlsplit, then split further, if required. >> >> >>> urlsplit(url) >> >> SplitResult(scheme='http', netloc='docs.python.org', path='/dev/ >> library/stdtypes.html', query='highlight=partition', >> fragment='str.partition') > urlparse isnt a option. Why not? > My reasult must be: > > myList = > ['http',':','//','docs','.','python','.','org','/','dev','/','library','/', > 'stdtypes','.','html','?','highlight','=','partition','#','str','.','partition'] Deriving this from the output of urlparse isn't that hard. I'm slightly baffled as to why this is more useful, but that's your problem. > re module is slow. Is it slow enough to be an issue? > Even I make a loop in urlparse.urlsplit I can lost specialMeaning > order. If you mean what I think you mean, and you're relying on getting queries from browsers in a defined order, you are in for a world of pain. > Seen easy but best aproach will be recursive. If speed is as important to you as you imply, I doubt it. -- Rhodri James *-* Wildebeest Herder to the Masses From smallpox911 at gmail.com Thu Dec 23 18:46:55 2010 From: smallpox911 at gmail.com (small Pox) Date: Thu, 23 Dec 2010 15:46:55 -0800 (PST) Subject: David Epstein Incest Charges: Columbia Professor Charged With Sleeping With Daughter References: Message-ID: <57136320-3fac-4796-8f22-233ab670e924@30g2000yql.googlegroups.com> On Dec 23, 2:01?pm, small Pox wrote: > What is the the best style and theory of writing a complier in your > language > > Maybe a book will suffice. > > http://www.veteranstoday.com/2010/12/18/gordon-duff-gov-jesse-ventura... > > I want to parse the contents of the above link into hebrew audio. > > CHEERIOS I expect this from the zionists of both stripes Shalom Israel David Epstein Incest Charges: Columbia Professor Charged With Sleeping With Daughter A Columbia political science professor has been charged with having a sexual relationship with his 24-year-old daughter, the Columbia Daily Spectator reports. David Epstein, 46, was charged Thursday with one count of third-degree incest. Police told the Spectator that the relationship appeared consensual. Epstein is currently on administrative leave. According to the New York Daily News, Epstein and the woman had a three-year sexual relationship and often exchanged "twisted text messages." The Spectator reports that Epstein is married to another Columbia political science professor, Sharyn O'Halloran, though a recent update to his Facebook page says he is single. The couple was featured in a 2008 Spectator article about professors who "bring love to work." "Our complementary skills lead to a great partnership," O'Halloran told the Spectator. One student described Epstein, who was teaching a class on game theory this semester, as a "very nice guy." Outside of his professorial duties, Epstein also blogged for this website, on topics ranging from torture to Sarah Palin. From benedict.verheyen at gmail.com Thu Dec 23 20:16:52 2010 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Fri, 24 Dec 2010 02:16:52 +0100 Subject: compiling Python 2.7.1 with readline module fails on Debian (Virtualbox) In-Reply-To: <4D13A923.8060208@pythonmeister.com> References: <4D1239AD.7010907@pythonmeister.com> <4D131DC1.4060104@pythonmeister.com> <4D13A923.8060208@pythonmeister.com> Message-ID: On 23/12/2010 20:55, Stefan Sonnenberg-Carstens wrote: >> >> > OK, I compiled it successfully under Debian 5.07 i386. > ncurses and libreadline are compiled from hand, both --prefix=$HOME/usr/local. > For python the only extra needed was export LD_LIBRARY_PATH=$HOME/usr/local/lib:$LD_LIBRARY_PATH > Hi Stefan, thanks for your continued help, I appreciate it very much! The reason why i want my own readline library is that i want to have full control over what version gets used without messing with the system wide libraries. A difference between your system and mine is that i'm using amd64 instead of i386. Anyway, i retried at home, completely clean system. Built ncurses and readline with: ./configure --enable-shared --prefix=$HOME/usr/local make make install Then for Python ./configure --enable-shared --prefix=$HOME/usr/local And now i doesn't find the readline library. I'm really lost now why it sometimes finds it and sometimes it doesn't. Only difference with earlier is that I now used --prefix=$HOME/usr/local So it's not installed system-wide. Could that be the reason why it's not found? Since you've managed to successfully build Python with readline support, could you post the exact steps from building readline to building Python? I even edited /etc/ldconfig.conf.d/libc.conf to include $HOME/usr/local/lib. Then issued sudo ldconfig -v but no go. Editing the Python Modules/Setup to uncomment the readline line doesn't help either so that obviously doesn't work. Should it? As said earlier, I added -L$HOME/usr/local/lib -I$HOME/usr/local/include to the end of the line. Thanks a lot, Benedict From givenrandy at gmail.com Thu Dec 23 21:58:15 2010 From: givenrandy at gmail.com (Randy Given) Date: Thu, 23 Dec 2010 21:58:15 -0500 Subject: GUI Tools for Python 3.1 Message-ID: Lots of stuff for 2.6 and 2.7 -- what GUI tools are there for 3.1? Randy -------------- next part -------------- An HTML attachment was scrubbed... URL: From benedict.verheyen at gmail.com Thu Dec 23 22:01:17 2010 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Fri, 24 Dec 2010 04:01:17 +0100 Subject: compiling Python 2.7.1 with readline module fails on Debian (Virtualbox) In-Reply-To: References: <4D1239AD.7010907@pythonmeister.com> <4D131DC1.4060104@pythonmeister.com> <4D13A923.8060208@pythonmeister.com> Message-ID: On 24/12/2010 2:16, Benedict Verheyen wrote: > On 23/12/2010 20:55, Stefan Sonnenberg-Carstens wrote: >>> I finally succeeded. I built ncurses and installed it to $HOME/usr/local ./configure --with-shared --enable-termcap --prefix=$HOME/usr/local make make install Then i built readline ./configure --enable-shared --prefix=$HOME/usr/local make make install I edited /etc/ld.so.conf.d/libc.conf and added $HOME/usr/local Next: ldconfig -v Next Python, configure doesn't find readline even if LD_LIBRARY_PATH is set. I tried export LDFLAGS="-L$HOME/usr/local" Then Python builds both readline and ncurses and works ok. Finally :) I'm not sure if the ldconfig is necessary. Regards, Benedict From no.email at please.post Thu Dec 23 22:36:28 2010 From: no.email at please.post (kj) Date: Fri, 24 Dec 2010 03:36:28 +0000 (UTC) Subject: How to order base classes? Message-ID: Suppose that I want to write a subclass C of base classes A and B. What considerations should go into choosing the ordering of A and B in C's base class list? Since any order one chooses can be overridden on a per-method basis, by assigning the desired parent's method to the appropriate class attribute, like this: class C(B, A) # override methods spam, ham, and eggs from B spam = A.spam; ham = A.ham; eggs = A.eggs; ... ...it is difficult for me to see a strong compelling reason for picking an ordering over another. But may be just ignorance on my part. How should one go about deciding the ordering of base classes? TIA! ~kj From steve+comp.lang.python at pearwood.info Thu Dec 23 23:25:01 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 24 Dec 2010 04:25:01 GMT Subject: How to order base classes? References: Message-ID: <4d14209d$0$30000$c3e8da3$5496439d@news.astraweb.com> On Fri, 24 Dec 2010 03:36:28 +0000, kj wrote: > How should one go about deciding the ordering of base classes? There is no general way for doing so. You need to consider the actual functionality of the methods involved. Consider a method spam() of class C that inherits from both A and B. To be completely general, you might have any of the following situations: C.spam() overloads A.spam() followed by B.spam() C.spam() overloads B.spam() followed by A.spam() C.spam() overloads A.spam() and overrides B.spam() C.spam() overloads B.spam() and overrides A.spam() C.spam() overrides both A.spam() and B.spam() (where I use "overload" to mean "modify the behaviour of", and "override" to mean "change the behaviour completely" -- basically, overloading will call the superclass' method, while overriding will not.) And (again, we're being completely general) whatever choice you make for C.spam() may not be valid for C.ham(), which could behave completely differently. The question you ask can only be answered in reference to a specific class with specific methods. There is no general principle, it depends entirely on the problem being solved. -- Steven From no.email at please.post Thu Dec 23 23:42:39 2010 From: no.email at please.post (kj) Date: Fri, 24 Dec 2010 04:42:39 +0000 (UTC) Subject: How to order base classes? References: <4d14209d$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: In <4d14209d$0$30000$c3e8da3$5496439d at news.astraweb.com> Steven D'Aprano writes: >The question you ask can only be answered in reference to a specific >class with specific methods. There is no general principle, it depends >entirely on the problem being solved. Thanks! ~kj From steve+comp.lang.python at pearwood.info Thu Dec 23 23:55:09 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 24 Dec 2010 04:55:09 GMT Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4d1427ac$0$30000$c3e8da3$5496439d@news.astraweb.com> On Thu, 23 Dec 2010 02:54:52 -0800, Carl Banks wrote: > On Dec 22, 7:22?pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> There should be a mechanism for Python functions to distinguish between >> unexpected exceptions (commonly known as "bugs"), which should be >> reported as coming from wherever they come from, and documented, >> expected exceptions, which should be reported as coming from the >> function regardless of how deep the function call stack really is. > > No, -100. The traceback isn't the place for this. I've never disagreed > with you more, and I've disagreed with you and awful lot. Okay, it's your right to disagree, but I am trying to understand your reasons for disagreeing, and I simply don't get it. I'm quite frustrated that you don't give any reasons for why you think it's not just unnecessary but actually *horrible* to hide implementation details such as where data validation is performed. I hope you'll try to explain *why* you think it's a bad idea, rather than just continue throwing out dismissive statements about "self-important" programmers (your earlier post to KJ) and "never disagreed more" (to me). Do you accept that, as a general principle, unhandled errors should be reported as close as possible to where the error occurs? If your answer to that is No, then where do you think unhandled errors should be reported? Now, given the scenario I proposed earlier: >>> f('bad input') <=== error occurs here Traceback (most recent call last): File "", line 1, in File "", line 2, in f File "", line 2, in g File "", line 2, in h File "", line 2, in i File "", line 2, in j File "", line 2, in k <=== far from the source of error ValueError do you concede that the actual error occurs at the time 'bad input' is passed to f, and not further down the stack where k happens to raise an exception? If not, where do you think the error occurs, and why? -- Steven From no.email at please.post Fri Dec 24 00:03:06 2010 From: no.email at please.post (kj) Date: Fri, 24 Dec 2010 05:03:06 +0000 (UTC) Subject: Partition Recursive References: Message-ID: In macm writes: >url = 'http://docs.python.org/dev/library/stdtypes.html?highlight=partition#str.partition' >So I want convert to >myList = >['http',':','//','docs','.','python','.','org','/','dev','/','library','/','stdtypes','.','html','?','highlight','=','partition','#','str','.','partition'] >The reserved char are: >specialMeaning = ["//",";","/", "?", ":", "@", "=" , "&","#"] You forgot '.'. >>> import re # sorry >>> sp = re.compile('(//?|[;?:@=&#.])') >>> filter(len, sp.split(url)) ['http', ':', '//', 'docs', '.', 'python', '.', 'org', '/', 'dev', '/', 'library', '/', 'stdtypes', '.', 'html', '\ ?', 'highlight', '=', 'partition', '#', 'str', '.', 'partition'] ~kj From ian.g.kelly at gmail.com Fri Dec 24 00:33:15 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 23 Dec 2010 22:33:15 -0700 Subject: Partition Recursive In-Reply-To: References: Message-ID: On 12/23/2010 10:03 PM, kj wrote: >>>> import re # sorry >>>> sp = re.compile('(//?|[;?:@=&#.])') >>>> filter(len, sp.split(url)) Perhaps I'm being overly pedantic, but I would likely have written that as "filter(None, sp.split(url))" for the same reason that "if string:" is generally preferred to "if len(string):". Cheers, Ian From pavlovevidence at gmail.com Fri Dec 24 01:38:05 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 23 Dec 2010 22:38:05 -0800 (PST) Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d1427ac$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3771d7ec-c030-4d15-a257-4c895ff57ec0@n2g2000pre.googlegroups.com> On Dec 23, 8:55?pm, Steven D'Aprano wrote: > On Thu, 23 Dec 2010 02:54:52 -0800, Carl Banks wrote: > > On Dec 22, 7:22?pm, Steven D'Aprano > +comp.lang.pyt... at pearwood.info> wrote: > >> There should be a mechanism for Python functions to distinguish between > >> unexpected exceptions (commonly known as "bugs"), which should be > >> reported as coming from wherever they come from, and documented, > >> expected exceptions, which should be reported as coming from the > >> function regardless of how deep the function call stack really is. > > > No, -100. ?The traceback isn't the place for this. ?I've never disagreed > > with you more, and I've disagreed with you and awful lot. > > Okay, it's your right to disagree, but I am trying to understand your > reasons for disagreeing, and I simply don't get it. > > I'm quite frustrated that you don't give any reasons for why you think > it's not just unnecessary but actually *horrible* to hide implementation > details such as where data validation is performed. I hope you'll try to > explain *why* you think it's a bad idea, rather than just continue > throwing out dismissive statements about "self-important" programmers > (your earlier post to KJ) and "never disagreed more" (to me). > > Do you accept that, as a general principle, unhandled errors should be > reported as close as possible to where the error occurs? > If your answer to that is No, then where do you think unhandled errors > should be reported? "No", and "where the error is detected". That is, what Python does now. Trying to figure out where the error "occurred" is fool's errand. The former isn't even well-defined, let alone something a compiler or user can be expected to reliably report. Sometimes the error doesn't even "occur" in the same call stack. There's a similar fine line between a bug exception and bad input exception, and it's foolish to distinguish them in a reliable way: in particular bugs can easily be mistaken for bad input. OTOH, going the extra mile to hide useful information from a user is asinine. As a user, I will decide for myself how I want to use implementation-defined information, and I don't want the implementor to decide this for me. It's bad enough if an implementor fails to provide information out of laziness, but when they deliberately do extra work to hide information, that's self-importance and arrogance. The traceback IS NOT THE PLACE for these kinds of games. > Now, given the scenario I proposed earlier: > > >>> f('bad input') ? ?<=== error occurs here > > Traceback (most recent call last): > ? File "", line 1, in > ? File "", line 2, in f > ? File "", line 2, in g > ? File "", line 2, in h > ? File "", line 2, in i > ? File "", line 2, in j > ? File "", line 2, in k ? ?<=== far from the source of error > ValueError > > do you concede that the actual error occurs at the time 'bad input' is > passed to f, and not further down the stack where k happens to raise an > exception? If not, where do you think the error occurs, and why? This question is irrelevant. It doesn't matter where the mistake is made. Carl Banks From nospam at thanks.invalid Fri Dec 24 02:21:12 2010 From: nospam at thanks.invalid (Juha Nieminen) Date: 24 Dec 2010 07:21:12 GMT Subject: What is the the best style and theory of writing a complier in your language References: Message-ID: <4d1449e8$0$32168$7b1e8fa0@news.nbl.fi> In comp.lang.c++ small Pox wrote: > http://www.veteranstoday.com/2010/12/18/gordon-duff-gov-jesse-ventura-proves-911-cover-up-will-americas-government-fall/ You should take your religion somewhere else. From timr at probo.com Fri Dec 24 02:39:47 2010 From: timr at probo.com (Tim Roberts) Date: Thu, 23 Dec 2010 23:39:47 -0800 Subject: How to order base classes? References: Message-ID: <55j8h6ptj3a7cu72q36nan7g6n767a4ma4@4ax.com> kj wrote: > >Suppose that I want to write a subclass C of base classes A and B. >What considerations should go into choosing the ordering of A and >B in C's base class list? >... >...it is difficult for me to see a strong compelling reason for picking >an ordering over another. But may be just ignorance on my part. > >How should one go about deciding the ordering of base classes? In general, it is uncommon to have a class that derives from multiple classes that all provide major functionality. That quickly gets confusing, which is one reason Java doesn't allow multiple inheritance. Now, it is very common for a class to derive from one class primarily, with other classes providing a few additional features. That's the "mix-in" concept. In that case, you'd list the "major" ancestor first, with the mix-ins after, so the mix-ins can modify the behavior. class BlueSpanishListBox( ListBox, ColorBlueMixIn, SpanishMixIn ): ... Reading it, a BlueSpanishListBox is-a ListBox that happens to have a few additional features. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From hniksic at xemacs.org Fri Dec 24 04:08:36 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Fri, 24 Dec 2010 10:08:36 +0100 Subject: round in 2.6 and 2.7 References: <87sjxoco6u.fsf@xemacs.org> <4D13A81A.5030903@v.loewis.de> Message-ID: <87d3orbkrv.fsf@xemacs.org> "Martin v. Loewis" writes: >> Type "help", "copyright", "credits" or "license" for more information. >>>>> 9.95 >> 9.9499999999999993 >>>>> "%.16g" % 9.95 >> '9.949999999999999' >>>>> round(9.95, 1) >> 10.0 >> >> So it seems that Python is going out of its way to intuitively round >> 9.95, while the repr retains the unnecessary digits. > > The 2.6 result is simply incorrect. [...] > Yes. It's a bug fix described in "What's new in Python 2.7" thus: That makes sense, thanks. Even within Python 2.6, rounding with different methods could produce inconsistent results: >>> round(9.95, 1) 10.0 >>> '%.1f' % 9.95 '9.9' From steve+comp.lang.python at pearwood.info Fri Dec 24 04:24:34 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 24 Dec 2010 09:24:34 GMT Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d1427ac$0$30000$c3e8da3$5496439d@news.astraweb.com> <3771d7ec-c030-4d15-a257-4c895ff57ec0@n2g2000pre.googlegroups.com> Message-ID: <4d1466d2$0$30000$c3e8da3$5496439d@news.astraweb.com> On Thu, 23 Dec 2010 22:38:05 -0800, Carl Banks wrote: >> Do you accept that, as a general principle, unhandled errors should be >> reported as close as possible to where the error occurs? If your answer >> to that is No, then where do you think unhandled errors should be >> reported? > > "No", and "where the error is detected". That is, what Python does now. > Trying to figure out where the error "occurred" is fool's errand. But isn't that what debugging is all about -- finding where the error occurred and fixing it? Hardly a fool's errand. > The > former isn't even well-defined, let alone something a compiler or user > can be expected to reliably report. Sometimes the error doesn't even > "occur" in the same call stack. Thank you for taking the time to respond. I think your objection misses the point I'm trying to make completely. But since this argument is rather academic, and it's Christmas Eve here, I'll just make one last comment and leave it at that: > OTOH, going the extra mile to hide useful information from a user is > asinine. As a user, I will decide for myself how I want to use > implementation-defined information, and I don't want the implementor to > decide this for me. It's bad enough if an implementor fails to provide > information out of laziness, but when they deliberately do extra work to > hide information, that's self-importance and arrogance. But that of course is nonsense, because as the user you don't decide anything of the sort. The developer responsible for writing the function decides what information he provides you, starting with whether you get an exception at all, where it comes from, the type of exception, and the error message (if any). Once this information has been passed on to you, you're free to do anything you like with it, but you never get to choose what information you get -- I'm not suggesting any change there. All I'm suggesting is that there should be a way of reducing the boilerplate needed for this idiom: def _validate_arg(x): if x == 'bad input': return False return True def f(arg): if not _validate_arg(arg): raise ValueError process(arg) to something more natural that doesn't needlessly expose implementation details that are completely irrelevant to the caller. -- Steven From pavlovevidence at gmail.com Fri Dec 24 06:24:10 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 24 Dec 2010 03:24:10 -0800 (PST) Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d1427ac$0$30000$c3e8da3$5496439d@news.astraweb.com> <3771d7ec-c030-4d15-a257-4c895ff57ec0@n2g2000pre.googlegroups.com> <4d1466d2$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Dec 24, 1:24?am, Steven D'Aprano wrote: > On Thu, 23 Dec 2010 22:38:05 -0800, Carl Banks wrote: > > OTOH, going the extra mile to hide useful information from a user is > > asinine. As a user, I will decide for myself how I want to use > > implementation-defined information, and I don't want the implementor to > > decide this for me. It's bad enough if an implementor fails to provide > > information out of laziness, but when they deliberately do extra work to > > hide information, that's self-importance and arrogance. > > But that of course is nonsense, because as the user you don't decide > anything of the sort. As a user I can criticize the decision of the implementor to needlessly filter information, and declare that it's borne out of the author's arrogance in thinking he knows what I want when I get a traceback. I can also opine that Python language shouldn't make it easy for library implementors to be arrogant like this. > The developer responsible for writing the function > decides what information he provides you, starting with whether you get > an exception at all, where it comes from, the type of exception, and the > error message (if any). Once this information has been passed on to you, > you're free to do anything you like with it, but you never get to choose > what information you get -- I'm not suggesting any change there. All I'm > suggesting is that there should be a way of reducing the boilerplate > needed for this idiom: > > def _validate_arg(x): > ? ? if x == 'bad input': return False > ? ? return True > > def f(arg): > ? ? if not _validate_arg(arg): > ? ? ? ? raise ValueError > ? ? process(arg) > > to something more natural that doesn't needlessly expose implementation > details that are completely irrelevant to the caller. Arrogance. Who gave you the right to decide what is completely irrelevant to user? I, as the user, decide what's relevant. If I want implementation-dependent information, it's my business. I don't want the language to make it easy for arrogant people, who think they know what information I want better than I do, to hide that information from me. Carl Banks From dyxmert at gmail.com Fri Dec 24 07:31:10 2010 From: dyxmert at gmail.com (Oleg Leschov) Date: Fri, 24 Dec 2010 04:31:10 -0800 (PST) Subject: using strings from extension module question + possible documentation error Message-ID: <20db9603-3c4e-47f3-b55c-ff1fd680aca8@z19g2000yqb.googlegroups.com> Hi, I am writing an extension module in which I want to do some heavy number crunching on large amount of data. The input data is prepared using Python code and passed to this extension module via strings containing binary data, and the result is also passed back as a list of pretty large strings containing binary data. So first I thought I'll just pass the empty strings made in Python along with input data strings, so my extension code would just fill those empty strings with the results. But then I read the PyString docs, it says I must not modify any strings even though it seems to be possible... Ok then I decided I'll create a list and fill it with strings from my C extension code.. However to avoid data copying I wish to fill the newly created (using PyString_FromString(NULL,x) ) strings' buffers (obtained with PyString_AsString) with data after creating them in my extension module. The question is - is this allowed? Because the doc says this > The data must not be modified in any way, unless the string was just created using PyString_FromStringAndSize(NULL, size). but what exactly does "just created" mean? will it not be considered "just created" if I call any more Python stuff after PyString_FromString, like another PyString_FromString along with PyString_AsString? Which I certainly intend to do since I first create all strings I want, and then do my calculations which fill those with actual data. Another question is this - why does PyString_AsString doc states that > Return a NUL-terminated representation of the contents of string. when strings may contain binary data and thus NOT NUL-terminated in general? is this a documentation error or I can't access binary strings using PyString_AsString ? P.S. the doc quotes are from http://docs.python.org/release/2.6.6/c-api/string.html From g.rodola at gmail.com Fri Dec 24 07:52:46 2010 From: g.rodola at gmail.com (=?ISO-8859-1?Q?Giampaolo_Rodol=E0?=) Date: Fri, 24 Dec 2010 13:52:46 +0100 Subject: using python ftp In-Reply-To: References: <4D1291CB.5010404@nmsu.edu> Message-ID: Starting from Python 2.7, yes: http://docs.python.org/library/ftplib.html#ftplib.FTP_TLS Regards, --- Giampaolo http://code.google.com/p/pyftpdlib/ http://code.google.com/p/psutil/ 2010/12/23 Octavian Rasnita : > Can this lib also work with ftps? > > Thanks. > > Octavian > > ----- Original Message ----- > From: "Anurag Chourasia" > To: "Matt Funk" > Cc: > Sent: Thursday, December 23, 2010 4:12 AM > Subject: Re: using python ftp > > >> Hi Matt, >> >> I have a snippet to "upload" files (that match a particular search >> pattern) to a remote server. >> >> Variable names are self explanatory. You could tweak this a little to >> "download" files instead. >> >> from ftplib import FTP >> ftp = FTP(hostname) >> ftp.login(user_id,passwd) >> ftp.cwd(remote_directory) >> files_list=glob.glob(file_search_pattern) >> for file in files_list: >> ? ?try: >> ? ? ? ?ftp.storlines('STOR ' + file, open(file)) >> ? ?except Exception, e: >> ? ? ? ?print ('Failed to FTP file: %s' %(file)) >> ftp.close() >> >> Regards, >> Anurag >> >> On Thu, Dec 23, 2010 at 5:33 AM, Matt Funk wrote: >>> Hi, >>> >>> i was wondering whether someone can point me whether the following >>> already exists. >>> >>> I want to connect to a server , download various files (for whose name i >>> want to be able to use a wildcard), and store those files in a given >>> location on the hard drive. If the file already exists i do not want to >>> download it. >>> >>> This seems fairly trivial and i would assume that there should be some >>> sort of implementation that does this easily but i didn't find anything >>> googling it. >>> >>> Otherwise i was going to do it "by hand" using ftplib: >>> 1) connect to server, >>> 2) change to directory on server >>> 3) get listing >>> 4) match the file pattern i want to the listing >>> 5) check if file already exists >>> 6) download file if matched and doesn't exist >>> >>> Can anyone offer any advice whether this already done somewhere? >>> >>> thanks >>> matt >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >>> >> -- >> http://mail.python.org/mailman/listinfo/python-list > -- > http://mail.python.org/mailman/listinfo/python-list > From moura.mario at gmail.com Fri Dec 24 08:32:47 2010 From: moura.mario at gmail.com (macm) Date: Fri, 24 Dec 2010 05:32:47 -0800 (PST) Subject: Partition Recursive References: Message-ID: Thanks all In [11]: reps = 5 In [12]: t = Timer("url = 'http://docs.python.org/dev/library/ stdtypes.html? highlight=partition#str.partition' ;sp = re.compile('(//?|[;?:@=&#.])'); filter(len, sp.split(url))", 'import re') In [13]: print sum(t.repeat(repeat=reps, number=1)) / reps 4.94003295898e-05 In [65]: t = Timer("url = 'http://docs.python.org/dev/library/ stdtypes.html? highlight=partition#str.partition' ;sp = re.compile('(//?|[;?:@=&#.])'); filter(None, sp.split(url))", 'import re') In [66]: print sum(t.repeat(repeat=reps, number=1)) / reps 3.50475311279e-05 Ian with None is a litle fast, thanks kj! Hi Mr. James, speed is always important. But ok re is fine. (but could be e-07) In next step I'll go to cython to win something. Regards Mario On Dec 24, 3:33?am, Ian Kelly wrote: > On 12/23/2010 10:03 PM, kj wrote: > > >>>> import re # sorry > >>>> sp = re.compile('(//?|[;?:@=&#.])') > >>>> filter(len, sp.split(url)) > > Perhaps I'm being overly pedantic, but I would likely have written that > as "filter(None, sp.split(url))" for the same reason that "if string:" > is generally preferred to "if len(string):". > > Cheers, > Ian From python at bdurham.com Fri Dec 24 08:37:17 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 24 Dec 2010 08:37:17 -0500 Subject: GUI Tools for Python 3.1 In-Reply-To: References: Message-ID: <1293197837.22142.1412104645@webmail.messagingengine.com> Randy, Tkinter is a viable GUI platform with Python 3.1's (and Python 2.7's) support for ttk (Tile). The new ttk module supports theme aware controls so that you can build beautiful GUI's that match your underlying platform's standards. Ttk also includes theme aware treeview and notebook controls. The treeview control supports multiple columns and can be configured as a (1 level) grid. The only glaring weakness is Tkinter's support for image formats other than GIF. This can be addressed by using the PIL (Python Image Library) which adds about 800K to a distribution. Tkinter is built-in, available in the 2.7 and 3.1 branches, and supports both 32 and 64 bit versions of Python. If you're interested in learning more, join Python's Tkinter mailing list. Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan.sonnenberg at pythonmeister.com Fri Dec 24 08:42:48 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Fri, 24 Dec 2010 14:42:48 +0100 Subject: using strings from extension module question + possible documentation error In-Reply-To: <20db9603-3c4e-47f3-b55c-ff1fd680aca8@z19g2000yqb.googlegroups.com> References: <20db9603-3c4e-47f3-b55c-ff1fd680aca8@z19g2000yqb.googlegroups.com> Message-ID: <4D14A358.3010602@pythonmeister.com> Am 24.12.2010 13:31, schrieb Oleg Leschov: > Hi, > > I am writing an extension module in which I want to do some heavy > number crunching on large amount of data. > > The input data is prepared using Python code and passed to this > extension module via strings containing binary data, and the result is > also passed back as a list of pretty large strings containing binary > data. > > So first I thought I'll just pass the empty strings made in Python > along with input data strings, so my extension code would just fill > those empty strings with the results. > > But then I read the PyString docs, it says I must not modify any > strings even though it seems to be possible... strings are immutable. If you pass a string and the underlying C module changes it's contents, this idiom is broken. The source for endless pain ... > Ok then I decided I'll create a list and fill it with strings from my > C extension code.. > > However to avoid data copying I wish to fill the newly created (using > PyString_FromString(NULL,x) ) strings' buffers (obtained with > PyString_AsString) with data after creating them in my extension > module. You could as an alternative just use byte arrays. These are changeable. > The question is - is this allowed? Because the doc says this >> The data must not be modified in any way, unless the string was just created using PyString_FromStringAndSize(NULL, size). Once the string has been used by python code, you should not change it. strings are immutable in python, so that every operation on a string returns a new one. See above. > but what exactly does "just created" mean? will it not be considered Just created means just that. It is created and not been passed back to the interpreter. So long you may change it. > "just created" if I call any more Python stuff after > PyString_FromString, like another PyString_FromString along with > PyString_AsString? Which I certainly intend to do since I first create > all strings I want, and then do my calculations which fill those with > actual data. > > > Another question is this - why does PyString_AsString doc states that >> Return a NUL-terminated representation of the contents of string. > when strings may contain binary data and thus NOT NUL-terminated in > general? is this a documentation error or I can't access binary > strings using PyString_AsString ? Read carefully: NUL-terminated representation of the contents of the string. It may contain other data, but the C-API will take care that this "contract" will be valid. > P.S. the doc quotes are from > http://docs.python.org/release/2.6.6/c-api/string.html There do they live, indeed. From dyxmert at gmail.com Fri Dec 24 09:50:01 2010 From: dyxmert at gmail.com (Oleg Leschov) Date: Fri, 24 Dec 2010 06:50:01 -0800 (PST) Subject: using strings from extension module question + possible documentation error References: <20db9603-3c4e-47f3-b55c-ff1fd680aca8@z19g2000yqb.googlegroups.com> Message-ID: <8be5e7d2-f4dd-41e6-92d0-ec10f2e9ece4@i18g2000yqn.googlegroups.com> On Dec 24, 4:42?pm, Stefan Sonnenberg-Carstens wrote: > You could as an alternative just use byte arrays. These are changeable. thanks, that's exactly what I need. I have completely missed those things since they're pretty new. From jim.hefferon at gmail.com Fri Dec 24 10:10:28 2010 From: jim.hefferon at gmail.com (Jim) Date: Fri, 24 Dec 2010 07:10:28 -0800 (PST) Subject: lxml etree question Message-ID: <98fb45fe-e4d0-49f4-a705-7923b2bfcacb@k22g2000yqh.googlegroups.com> Hello, I wonder if someone knows about lxml.etree and namespaces? I want to build an ElementTree where some of the sub-elements have attributes that serialize this way. .. I've tried just comment_elet.set('xml:lang','de') and it didn't like that at all (although it takes comment_elet.set('auth:id','jones') just fine). I've also spelunked the docs and googled but have not hit on the right invocation. If someone knows, I'd be grateful. Jim From nitinpawar432 at gmail.com Fri Dec 24 10:18:52 2010 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Fri, 24 Dec 2010 20:48:52 +0530 Subject: lxml etree question In-Reply-To: <98fb45fe-e4d0-49f4-a705-7923b2bfcacb@k22g2000yqh.googlegroups.com> References: <98fb45fe-e4d0-49f4-a705-7923b2bfcacb@k22g2000yqh.googlegroups.com> Message-ID: On Fri, Dec 24, 2010 at 8:40 PM, Jim wrote: > Hello, I wonder if someone knows about lxml.etree and namespaces? > > I want to build an ElementTree where some of the sub-elements have > attributes that serialize this way. > > .. > > I've tried just comment_elet.set('xml:lang','de') and it didn't like > that at all (although it takes comment_elet.set('auth:id','jones') > just fine). I've also spelunked the docs and googled but have not hit > on the right invocation. If someone knows, I'd be grateful. > > Jim > -- > http://mail.python.org/mailman/listinfo/python-list > You can check this http://codespeak.net/pipermail/lxml-dev/2006-February/000920.html -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at please.post Fri Dec 24 11:24:34 2010 From: no.email at please.post (kj) Date: Fri, 24 Dec 2010 16:24:34 +0000 (UTC) Subject: How can a function find the function that called it? Message-ID: I want to implement a frozen and ordered dict. I thought I'd implement it as a subclass of collections.OrderedDict that prohibits all modifications to the dictionary after it has been initialized. In particular, calling this frozen subclass's update method should, in general, trigger an exception ("object is not mutable"). But OrderedDict's functionality *requires* that its __init__ be run, and this __init__, in turn, does part of its initialization by calling the update method. Therefore, the update method of the new subclass needs to be able to identify the calling function in order to make a special allowance for calls coming from OrderedDict.__init__. (Better yet, it should be able to allow calls coming from its own class's __init__, via OrderedDict.__init__.) The best I've been able to do is to use inspect to get the name of the calling function. For the case I'm trying to identify, this name is simply "__init__". But Python code is awash in __init__'s... Is it possible to achieve a more precise identification? Specifically, I want to know the *class* (not the file) where this '__init__' is defined. (BTW, I don't understand why inspect doesn't provide something as basic as the *class* that the method belongs to, whenever applicable. I imagine there's a good reason for this coyness, but I can't figure it out.) TIA! ~kj From chris at gonnerman.org Fri Dec 24 11:51:03 2010 From: chris at gonnerman.org (Chris Gonnerman) Date: Fri, 24 Dec 2010 10:51:03 -0600 Subject: [Python] How can a function find the function that called it? In-Reply-To: References: Message-ID: <4D14CF77.40405@gonnerman.org> On 12/24/2010 10:24 AM, kj wrote: > I want to implement a frozen and ordered dict. > > I thought I'd implement it as a subclass of collections.OrderedDict > that prohibits all modifications to the dictionary after it has > been initialized. > > In particular, calling this frozen subclass's update method should, > in general, trigger an exception ("object is not mutable"). > > But OrderedDict's functionality *requires* that its __init__ be > run, and this __init__, in turn, does part of its initialization > by calling the update method. Use a flag, "private" to your new class, to indicate whether initialization is complete or not; your update method would see that initialization is not yet complete when called by __init__, and so it would do its business (calling the class method). At the end of the __init__ function, set the initialized property to true. If your update is called with the initialized property already set to true, it will raise the exception. From smallpox911 at gmail.com Fri Dec 24 12:59:23 2010 From: smallpox911 at gmail.com (small Pox) Date: Fri, 24 Dec 2010 09:59:23 -0800 (PST) Subject: *** Alex Jones Exposes Google's Plan to Dominate the Internet *** plz spread this video References: Message-ID: Alex Jones Exposes Google's Plan to Dominate the Internet http://www.youtube.com/watch?v=LiqOL9ausOI Alex Jones Exposes Google's Plan to Dominate the Internet http://www.youtube.com/watch?v=LiqOL9ausOI Alex Jones Exposes Google's Plan to Dominate the Internet http://www.youtube.com/watch?v=LiqOL9ausOI Alex Jones Exposes Google's Plan to Dominate the Internet http://www.youtube.com/watch?v=LiqOL9ausOI Alex Jones Exposes Google's Plan to Dominate the Internet http://www.youtube.com/watch?v=LiqOL9ausOI Alex Jones Exposes Google's Plan to Dominate the Internet http://www.youtube.com/watch?v=LiqOL9ausOI Alex Jones Exposes Google's Plan to Dominate the Internet http://www.youtube.com/watch?v=LiqOL9ausOI -- The FAT per DIEM FBI bustards use our TAX PAYER MONEY and INCOMPETENCE is UNACCEPTABLE. ===== http://www.youtube.com/watch?v=lX18zUp6WPY http://www.youtube.com/watch?v=XQapkVCx1HI http://www.youtube.com/watch?v=tXJ-k-iOg0M Hey Racist and INcompetent FBI Bustards, where is the ANTHRAX Mailer ? Where are the 4 blackboxes ? Where are the Pentagon Videos ? Why did you release the 5 dancing Israelis compromising the whole 911 investigation ? If the Dubai Police can catch Mossad Murderers and put the videos and Iranian Police can why cant you put the Pentagon Videos ? If Iran police can put the AMERICAN TERRORIST, Riggi and puting on INTERNATIONAL MEDIA a day after catching him without TORTURE, why cant you put the INNOCENT patsies on the MEDIA. Why did you have to LIE about Dr Afiya Siddiqui and torture that Innocent little mother of 3 and smashing the skull of her one child ? http://www.youtube.com/watch?v=DhMcii8smxk http://www.youtube.com/watch?v=0SZ2lxDJmdg There are CRIMINAL cases against CIA CRIMINAL Bustards in Italian courts. FBI bustards paid a penalty of $5.8 million to Steven Hatfill, but only because he was a white. They got away with MURDER of thousands of Non-whites in all parts of the world. Daily 911 news : http://911blogger.com http://www.youtube.com/watch?v=tRfhUezbKLw http://www.youtube.com/watch?v=x7kGZ3XPEm4 http://www.youtube.com/watch?v=lX18zUp6WPY Conclusion : FBI bustards are RACIST and INcompetent. They could neither catch the ANTHRAX or 911 YANK/Jew criminals nor could they cover them up - whichever was their actual goal or task. SLASH the SALARIES of FBI/CIA/NSA etc BUSTARDS into half all across tbe board, esp the whites/jew on the top. FBI Bustards failed to Catch BERNARD MADOFF even after that RACIST and UNPATRIOTIC Act FBI bustards failed to prevent ROMAN POLANSKY from absconding to europe and rapes. FBI bustards failed to prevent OKLAHOMA On Dec 23, 2:01?pm, small Pox wrote: > What is the the best style and theory of writing a complier in your > language > > Maybe a book will suffice. > > http://www.veteranstoday.com/2010/12/18/gordon-duff-gov-jesse-ventura... > > I want to parse the contents of the above link into hebrew audio. > > CHEERIOS From smallpox911 at gmail.com Fri Dec 24 13:06:48 2010 From: smallpox911 at gmail.com (small Pox) Date: Fri, 24 Dec 2010 10:06:48 -0800 (PST) Subject: *** The Jew World Order - A TUTORIAL Exposition in Banking and Economics *** Message-ID: <76ef6b76-a823-40aa-97ea-c33ea3c822e1@g26g2000vbi.googlegroups.com> *** The Jew World Order - A TUTORIAL Exposition in Banking and Economics *** Is the New World Order ?Jewish?? February 12, 2005 What do you trust? Government, Paper or Gold? Let?s begin by defining the ?New World Order.? The mainspring of the New World Order is the desire on the part of the world?s central banksters to translate their vast economic power into permanent global institutions of political and social control. Their power is based on their monopoly over credit. They use the government?s credit to print money, and require the taxpayer to fork over billions in interest to them. Central banks like the Federal Reserve pretend to be government institutions. They are not. They are privately owned by perhaps 300 families. It is significant that the majority of these families are Jewish, how significant I am not yet sure. If they were Lutherans or Zulus, certainly our objections would be the same. I am a non-observant Jew who believes this situation is lethal for humanity and Jews alike. We have already seen the tragic consequences of it in World War II. The American inventor Thomas Edison described this colossal scam, which the New World Order is designed to perpetuate, as follows: ?It is absurd to say our country can issue bonds and cannot issue currency. Both are promises to pay, but one fattens the usurer and the other helps the people.? Central banks also control the supply of credit to businesses and individuals. Robert Hemphill, Credit Manager of the Federal Reserve Bank in Atlanta describes this untenable situation. ?This is a staggering thought. We are completely dependent on the commercial banks. Someone has to borrow every dollar we have in circulation, cash or credit. If the banks create ample synthetic money, we are prosperous; if not, we starve. We are absolutely without a permanent money system. When one gets a complete grasp of the picture, the tragic absurdity of our hopeless position is almost incredible, but there it is? It is so important that our present civilization may collapse unless it becomes widely understood and the defects remedied very soon.? ? When the Federal Reserve was inaugurated in 1913, a London banker acknowledged that it is a scam. ?The few who understand the system will either be so interested in its profits, or so dependent on its favours, that there will be no opposition from that class? The great body of the people, mentally incapable of comprehending, will bear its burden without complaint, and perhaps without even suspecting that the system is inimical (contrary) to their interests.? CONSEQUENCES Obviously printing money should be in the public sphere as prescribed by the U.S. Constitution. This anomalous situation is the source of humanity?s woes. It pits the people who control the economy against society as a whole. It is in their interest to destabilize society, foster immorality, internal division (like gay marriage) and war in order to increase debt and distract and control the masses. The banksters are responsible for social engineering programs such as the (homo) sexual revolution, feminism and multiculturalism, which undermine family and social cohesion. This fundamental antagonism also supports a vast criminal underworld actually run by the elites. The banksters are responsible for the assassinations of presidents like Lincoln and JFK, and for the attack on the World Trade Center. They own or control the mass media, which legitimizes G.W. Bush, the war in Iraq and the impending attack on Iran. War provides an excuse to introduce the draft and a repressive police state. Success today is based on a person?s willingness to become an accomplice, witting or unwitting, to the banker fraud. Even rich entrepreneurs are dependent on credit and are unwilling to support genuine change. As a result of the banksters? scam, Western society and culture are based on a fraud. We do not have genuine democracy or equal access to the mass media or open and truthful education. Western society is a fraud, run by cowards who know they?re frauds. ARE ?THE JEWS? RESPONSIBLE? The New World Order is a hydra-headed monster. The banksters work through many fronts such as Communism, socialism, liberalism, feminism, Zionism, neo conservatism and Freemasonry. Unknown to most members, these ?progressive? movements are all secretly devoted to ?world revolution? which is a euphemism for banker hegemony. (See my ?Rothschild Conducts Red Symphony?) The banksters control the world?s major corporations, media, intelligence agencies, think tanks, foundations and universities. They are responsible for suppressing the truth. Jews figure prominently in all of this, a cause of anti Semitism. Of course many other people are pursuing ?success? as well. The banksters also work through countries. They are largely responsible for British and American imperialism, whose aim is to monopolize the world?s wealth. In his book ?The Jews? (1922) British social critic Hilaire Belloc writes that the British Empire represented a partnership between Jewish finance and the British aristocracy. ?After Waterloo [1815] London became the money market and the clearing house of the world. The interests of the Jew as a financial dealer and the interests of this great commercial polity approximated more and more. One may say that by the last third of the nineteenth century, they had become virtually identical.? The confluence of Jewish and British interest extended to marriage. ?Marriages began to take place, wholesale, between what had once been the aristocratic territorial families of this country and the Jewish commercial fortunes. After two generations of this, with the opening of the twentieth century, those of the great territorial English families in which there was no Jewish blood was the exception. In nearly all of them was the strain more or less marked, in some of them so strong that though the name was still an English name and the traditions those of a purely English lineage of the long past, the physique and character had become wholly Jewish?? If the marriage of Al Gore?s daughter with Jacob Schiff?s grandson is any indication, this mingling of Jewish and Gentile elites extends to America as well. John Forbes Kerry is another example. Belloc continues to say that the British and Jewish goal of world domination was synonymous and used Freemasonry as an instrument. ?Specifically Jewish institutions, such as Freemasonry (which the Jews had inaugurated as a sort of bridge between themselves and their hosts in the seventeenth century) were particularly strong in Britain, and there arose a political tradition, active, and ultimately to prove of great importance, whereby the British state was tacitly accepted by foreign governments as the official protector of the Jews in other countries. It was Britain which was expected to intervene [wherever Jewish persecution took place and] to support the Jewish financial energies throughout the world, and to receive in return the benefit of that connection.? If Belloc is right, you could say the New World Order is an extension of the British Empire, in which elite British, American and Jewish interests are indistinguishable. See also my ?The Jewish Conspiracy is British Imperialism.? CONCLUSION: WHAT IS JEWISH? The majority of Jews would want no part of the New World Order a.k.a. ?globalization? if they understood its undemocratic character and how they are being used. The true Jewish spirit holds that truth and morality are absolute and cannot be trimmed to fit one?s perceived self interest. G.J. Nueberger expresses this spirit in his essay ?The Great Gulf Between Zionism and Judaism.? ?The Jewish people are chosen not for domination over others, not for conquest or warfare, but to serve G-d and thus to serve mankind?Thus physical violence is not a tradition or a value of the Jews. The task for which the Jewish people were chosen is not to set an example of military superiority or technical achievements, but to seek perfection in moral behaviour and spiritual purity. Of all the crimes of political Zionism, the worst and most basic, and which explains all its other misdeeds, is that from its beginning Zionism has sought to separate the Jewish people from their G-d, to render the divine covenant null and void, and to substitute a ?modern? statehood and fraudulent sovereignty for the lofty ideals of the Jewish people.? The banksters obviously aren?t concerned about true Judaism or racial purity and were quite willing to sacrifice millions of Jews to achieve their design by backing Hitler. They are sacrificing thousands more Jewish, American and Muslim lives in the Middle East in their Orwellian ?perpetual war for perpetual peace.? Does the New World Order serve a ?Jewish? agenda or a banker elite agenda? I would venture that it serves the latter, and the Jewish people are an instrument of this agenda like so many other people. By giving private individuals the ability to create money out of nothing, we have created a monster which threatens to devour the planet and with it the human race. Source: Save the Males December 17, 2010 Posted in: AIPAC, Anti Racism, Anti-Defamation League, Anti-Semitism, Anti-Semitism News, B'nai B'rith, Discrimination News, Israel, Jerusalem, Jewish, Jewish American Heritage Month, Jewish Heritage, Jewish History, Jews, Judaism, Racism News, Sephardic, Tel Aviv, West Bank, White Nationalism, White Supremacism, Zionism, ashkenazi From awilliam at whitemice.org Fri Dec 24 13:17:01 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Fri, 24 Dec 2010 13:17:01 -0500 Subject: lxml etree question In-Reply-To: References: <98fb45fe-e4d0-49f4-a705-7923b2bfcacb@k22g2000yqh.googlegroups.com> Message-ID: <1293214621.3872.3.camel@linux-yu4c.site> On Fri, 2010-12-24 at 20:48 +0530, Nitin Pawar wrote: > On Fri, Dec 24, 2010 at 8:40 PM, Jim wrote: > Hello, I wonder if someone knows about lxml.etree and > namespaces? Yes, and don't. > I want to build an ElementTree where some of the sub-elements have > attributes that serialize this way. > .. > I've tried just comment_elet.set('xml:lang','de') and it didn't like > that at all (although it takes comment_elet.set('auth:id','jones') > just fine). I've also spelunked the docs and googled but have not hit > on the right invocation. If someone knows, I'd be grateful. I'd *strongly* recommend using ElementFlow for building XML documents (over ElementTree), especially if namespaces are involved. ElementFlow is far more intuitive. From cbrown at cbrownsystems.com Fri Dec 24 13:23:59 2010 From: cbrown at cbrownsystems.com (ChasBrown) Date: Fri, 24 Dec 2010 10:23:59 -0800 (PST) Subject: How can a function find the function that called it? References: Message-ID: On Dec 24, 8:24?am, kj wrote: > I want to implement a frozen and ordered dict. > > I thought I'd implement it as a subclass of collections.OrderedDict > that prohibits all modifications to the dictionary after it has > been initialized. > > In particular, calling this frozen subclass's update method should, > in general, trigger an exception ("object is not mutable"). > > But OrderedDict's functionality *requires* that its __init__ be > run, and this __init__, in turn, does part of its initialization > by calling the update method. > Rather than trying to identify the caller, I'd do something like: class FrozenODict(OrderedDict): def __init__(self, *args, **kwargs): OrderedDict.__init__(self, *args, **kwargs) self.update = self._update # init is complete, so override # update method for this instance def _update(self, dict2): raise Exception("object is immutable!!") After the __init__, calls to the instance's 'update' function will be mapped to _update. It's essentially overriding the inherited function on the fly. Cheers - Chas From urban.dani at gmail.com Fri Dec 24 13:26:06 2010 From: urban.dani at gmail.com (Daniel Urban) Date: Fri, 24 Dec 2010 19:26:06 +0100 Subject: How can a function find the function that called it? In-Reply-To: References: Message-ID: On Fri, Dec 24, 2010 at 17:24, kj wrote: > (BTW, I don't understand why inspect doesn't provide something as > basic as the *class* that the method belongs to, whenever applicable. > I imagine there's a good reason for this coyness, but I can't figure > it out.) One function object can "belong to" (be in the namespace of) more than one class, so there is no "the class". From nagle at animats.com Fri Dec 24 13:26:40 2010 From: nagle at animats.com (John Nagle) Date: Fri, 24 Dec 2010 10:26:40 -0800 Subject: [Python] How can a function find the function that called it? In-Reply-To: References: Message-ID: <4d14e5db$0$43976$742ec2ed@news.sonic.net> On 12/24/2010 8:51 AM, Chris Gonnerman wrote: > On 12/24/2010 10:24 AM, kj wrote: >> I want to implement a frozen and ordered dict. >> >> I thought I'd implement it as a subclass of collections.OrderedDict >> that prohibits all modifications to the dictionary after it has >> been initialized. That's actually a fairly common question - is an object in initialization, or has it been fully created? It would be useful if Python had some standard way to check if initialization has completed. Sometimes a parent class needs to know if initialization of the entire object has completed. This typically comes up with classes that define "__setattr__" and are then subclassed. John Nagle From no.email at please.post Fri Dec 24 13:43:06 2010 From: no.email at please.post (kj) Date: Fri, 24 Dec 2010 18:43:06 +0000 (UTC) Subject: How can a function find the function that called it? References: Message-ID: In Daniel Urban writes: >On Fri, Dec 24, 2010 at 17:24, kj wrote: >> (BTW, I don't understand why inspect doesn't provide something as >> basic as the *class* that the method belongs to, whenever applicable. >> I imagine there's a good reason for this coyness, but I can't figure >> it out.) >One function object can "belong to" (be in the namespace of) more than >one class, so there is no "the class". There are many other properties that inspect reports on (e.g. filename) that may not apply to an individual case. For 99.9% of methods, the class in which it was lexically defined would be good enough. From nagle at animats.com Fri Dec 24 13:51:32 2010 From: nagle at animats.com (John Nagle) Date: Fri, 24 Dec 2010 10:51:32 -0800 Subject: How to pop the interpreter's stack? In-Reply-To: References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d1427ac$0$30000$c3e8da3$5496439d@news.astraweb.com> <3771d7ec-c030-4d15-a257-4c895ff57ec0@n2g2000pre.googlegroups.com> <4d1466d2$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4d14ebaf$0$44021$742ec2ed@news.sonic.net> On 12/24/2010 3:24 AM, Carl Banks wrote: > On Dec 24, 1:24 am, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: All I'm >> suggesting is that there should be a way of reducing the boilerplate >> needed for this idiom: >> >> def _validate_arg(x): >> if x == 'bad input': return False >> return True >> >> def f(arg): >> if not _validate_arg(arg): >> raise ValueError >> process(arg) >> >> to something more natural that doesn't needlessly expose implementation >> details that are completely irrelevant to the caller. How about raise ValueError("Bad input %s to validate_arg" % (repr(arg),)) You can pass arguments to most exceptions, and the content of the exception is determined entirely by the code raising it. If end users are seeing uncaught tracebacks, the program is broken. It's usually worth it to catch EnvironmentError near the outermost level of the program, since most non program bug events, like I/O and network errors. will raise some subclass of EnvironmentError. John Nagle From no.email at please.post Fri Dec 24 13:52:02 2010 From: no.email at please.post (kj) Date: Fri, 24 Dec 2010 18:52:02 +0000 (UTC) Subject: type(d) != type(d.copy()) when type(d).issubclass(dict) Message-ID: Watch this: >>> class neodict(dict): pass ... >>> d = neodict() >>> type(d) >>> type(d.copy()) Bug? Feature? Genius beyond the grasp of schlubs like me? ~kj From mdw at distorted.org.uk Fri Dec 24 13:58:37 2010 From: mdw at distorted.org.uk (Mark Wooding) Date: Fri, 24 Dec 2010 18:58:37 +0000 Subject: How can a function find the function that called it? References: Message-ID: <87d3orvvz6.fsf.mdw@metalzone.distorted.org.uk> kj writes: > But OrderedDict's functionality *requires* that its __init__ be > run, and this __init__, in turn, does part of its initialization > by calling the update method. > > Therefore, the update method of the new subclass needs to be able > to identify the calling function in order to make a special allowance > for calls coming from OrderedDict.__init__ That doesn't follow at all. Why not set a `frozen' flag when your initialization is complete? Something like class ImmutableOrderedDict (OrderedDict): def __init__(me, *args, **kw): me._frozen = False OrderedDict.__init__(me, *arg, **kw) me._frozen = True def _check(me): if me._frozen: raise ImmutableError And so on. Thank you for explaining your actual objective, by the way. -- [mdw] From drobinow at gmail.com Fri Dec 24 16:17:40 2010 From: drobinow at gmail.com (David Robinow) Date: Fri, 24 Dec 2010 16:17:40 -0500 Subject: type(d) != type(d.copy()) when type(d).issubclass(dict) In-Reply-To: References: Message-ID: On Fri, Dec 24, 2010 at 1:52 PM, kj wrote: > Watch this: > >>>> class neodict(dict): pass > ... >>>> d = neodict() >>>> type(d) > >>>> type(d.copy()) > > > > Bug? ?Feature? ?Genius beyond the grasp of schlubs like me? copy, here, is a dict method. It will create a dict. If you really need it, you could try this: import copy class neodict(dict): def copy(self): return copy.copy(self) d = neodict() print type(d) dd = d.copy() print type(dd) From flisboa.costa at gmail.com Fri Dec 24 16:37:31 2010 From: flisboa.costa at gmail.com (=?UTF-8?B?RmzDoXZpbyBMaXNiw7Rh?=) Date: Fri, 24 Dec 2010 18:37:31 -0300 Subject: type(d) != type(d.copy()) when type(d).issubclass(dict) In-Reply-To: References: Message-ID: > > copy, here, is a dict method. It will create a dict. > If you really need it, you could try this: > > import copy > class neodict(dict): > def copy(self): > return copy.copy(self) > > d = neodict() > print type(d) > dd = d.copy() > print type(dd) One more gotcha to python... OO in python is strange :p IMO, if i subclass a class, all instance methods from a subclass instance should work with the subclass. But i'm guessing python doesn't make this distinction of instance/class methods like some other languages do (unless one uses annotations, what appears to be not the case with the dict class). Not that it inhibits me on using python in any way, in fact i do use python for my projects. I'm new to it, and I like some of its features, but some others are rather strange. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Fri Dec 24 17:14:42 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 24 Dec 2010 14:14:42 -0800 Subject: How to pop the interpreter's stack? In-Reply-To: References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d1427ac$0$30000$c3e8da3$5496439d@news.astraweb.com> <3771d7ec-c030-4d15-a257-4c895ff57ec0@n2g2000pre.googlegroups.com> <4d1466d2$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4D151B52.4030502@stoneleaf.us> Carl Banks wrote: > On Dec 24, 1:24 am, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> On Thu, 23 Dec 2010 22:38:05 -0800, Carl Banks wrote: >>> OTOH, going the extra mile to hide useful information from a user is >>> asinine. As a user, I will decide for myself how I want to use >>> implementation-defined information, and I don't want the implementor to >>> decide this for me. It's bad enough if an implementor fails to provide >>> information out of laziness, but when they deliberately do extra work to >>> hide information, that's self-importance and arrogance. >> But that of course is nonsense, because as the user you don't decide >> anything of the sort. > > As a user I can criticize the decision of the implementor to > needlessly filter information, and declare that it's borne out of the > author's arrogance in thinking he knows what I want when I get a > traceback. > > I can also opine that Python language shouldn't make it easy for > library implementors to be arrogant like this. > >> The developer responsible for writing the function >> decides what information he provides you, starting with whether you get >> an exception at all, where it comes from, the type of exception, and the >> error message (if any). Once this information has been passed on to you, >> you're free to do anything you like with it, but you never get to choose >> what information you get -- I'm not suggesting any change there. All I'm >> suggesting is that there should be a way of reducing the boilerplate >> needed for this idiom: >> >> def _validate_arg(x): >> if x == 'bad input': return False >> return True >> >> def f(arg): >> if not _validate_arg(arg): >> raise ValueError >> process(arg) >> >> to something more natural that doesn't needlessly expose implementation >> details that are completely irrelevant to the caller. > > Arrogance. Who gave you the right to decide what is completely > irrelevant to user? I, as the user, decide what's relevant. If I > want implementation-dependent information, it's my business. > > I don't want the language to make it easy for arrogant people, who > think they know what information I want better than I do, to hide that > information from me. One of the many things I love about Python is that it stays out of the way of me getting my work done. I think a truly pythonic program/library/module must do the same. So in this regard I agree with Carl. There are also times when I change the exception being raised to match what python expects from that type of object -- for example, from WhatEverException to KeyError for a dict-like object. So in this regard I agree with Steven. For kj's concern, which seems to be along the lines of functional as opposed to custom object, I don't think the traceback should be monkied with -- either use a decorator to keep the traceback short, or give the _pre_func name a good name and don't worry about it. I know when I see a traceback, I start at the bottom and only work my way up if I need to. ~Ethan~ From benjamin.kaplan at case.edu Fri Dec 24 17:40:44 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 24 Dec 2010 17:40:44 -0500 Subject: type(d) != type(d.copy()) when type(d).issubclass(dict) In-Reply-To: References: Message-ID: On Dec 24, 2010 4:40 PM, "Fl?vio Lisb?a" wrote: >> >> copy, here, is a dict method. It will create a dict. >> If you really need it, you could try this: >> >> import copy >> class neodict(dict): >> def copy(self): >> return copy.copy(self) >> >> d = neodict() >> print type(d) >> dd = d.copy() >> print type(dd) > > > One more gotcha to python... OO in python is strange :p > > IMO, if i subclass a class, all instance methods from a subclass instance should work with the subclass. But i'm guessing python doesn't make this distinction of instance/class methods like some other languages do (unless one uses annotations, what appears to be not the case with the dict class). > This isn't at all unique to Python. You'd get the same results in java or any other language. public class Foo { int a; public Foo(int a) { this.a = a; } public Foo clone() { return new Foo(this.a); } } public class Bar extends Foo { public Bar() { super(0); } } What type do you think (new Bar()).clone() is going to return? > Not that it inhibits me on using python in any way, in fact i do use python for my projects. I'm new to it, and I like some of its features, but some others are rather strange. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From cdalten at gmail.com Fri Dec 24 19:00:36 2010 From: cdalten at gmail.com (chad) Date: Fri, 24 Dec 2010 16:00:36 -0800 (PST) Subject: I don't why there is no output.... Message-ID: Given the following... #!/usr/bin/python import pexpect p = pexpect.spawn('cat') p.sendline('1234') p.expect (['1234']) p.expect (['1234']) I no output when I run it... [cdalten at localhost oakland]$ ./ecat.py [cdalten at localhost oakland]$ I don't get it. I was expecting to see the output from both the tty and cat. Instead, I see nothing. Why? From cdalten at gmail.com Fri Dec 24 19:22:18 2010 From: cdalten at gmail.com (chad) Date: Fri, 24 Dec 2010 16:22:18 -0800 (PST) Subject: I don't why there is no output.... References: Message-ID: On Dec 24, 4:00?pm, chad wrote: > Given the following... > > #!/usr/bin/python > > import pexpect > > p = pexpect.spawn('cat') > p.sendline('1234') > p.expect (['1234']) > p.expect (['1234']) > > I no output when I run it... > > [cdalten at localhost oakland]$ ./ecat.py > [cdalten at localhost oakland]$ > > I don't get it. I was expecting to see the output from both the tty > and cat. Instead, I see nothing. Why? Never mind. I figured it out. From stefan_ml at behnel.de Sat Dec 25 05:33:20 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 25 Dec 2010 11:33:20 +0100 Subject: lxml etree question In-Reply-To: <98fb45fe-e4d0-49f4-a705-7923b2bfcacb@k22g2000yqh.googlegroups.com> References: <98fb45fe-e4d0-49f4-a705-7923b2bfcacb@k22g2000yqh.googlegroups.com> Message-ID: Jim, 24.12.2010 16:10: > Hello, I wonder if someone knows about lxml.etree and namespaces? > > I want to build an ElementTree where some of the sub-elements have > attributes that serialize this way. > > .. > > I've tried just comment_elet.set('xml:lang','de') and it didn't like > that at all (although it takes comment_elet.set('auth:id','jones') > just fine). I've also spelunked the docs and googled but have not hit > on the right invocation. If someone knows, I'd be grateful. This should get you on the right track: http://codespeak.net/lxml/tutorial.html#namespaces In short: you need to distinguish between namespaces (URIs) and namespace prefixes. ElementTree and lxml.etree use the fully qualified tag name in the form "{namespace-URI}localname}". As for the special case of the "xml" prefix, the XML namespace spec has this to say: """ The prefix xml is by definition bound to the namespace name http://www.w3.org/XML/1998/namespace. It MAY, but need not, be declared, and MUST NOT be bound to any other namespace name. Other prefixes MUST NOT be bound to this namespace name, and it MUST NOT be declared as the default namespace. """ http://www.w3.org/TR/REC-xml-names/#ns-decl lxml knows about this special case, so you can write {http://www.w3.org/XML/1998/namespace}lang and lxml will take care of using the right prefix. Stefan From rina308 at gmail.com Sat Dec 25 06:38:40 2010 From: rina308 at gmail.com (czarina08) Date: Sat, 25 Dec 2010 03:38:40 -0800 (PST) Subject: Python Average Salary Report Message-ID: Hi there, I'm doing a market research report on the average hourly rates for Python/Django developers. Any input on this? I do understand that it does depend on the location, amount of experience and skills. I'd like to hear what are the hourly rates within your area :-) Thanks! From alice at gothcandy.com Sat Dec 25 09:16:29 2010 From: alice at gothcandy.com (=?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=) Date: Sat, 25 Dec 2010 06:16:29 -0800 Subject: Python Average Salary Report References: Message-ID: Howdy! > I'm doing a market research report on the average hourly rates for > Python/Django developers. Any input on this? I do understand that it > does depend on the location, amount of experience and skills. I'd like > to hear what are the hourly rates within your area :-) Thanks! I'm a strange case, but I like to charge my clients what my clients charge theirs. It's only fair. ;) This, of course, results in my rates varying from between $25 and $125, with a mean of ~$50/hr. More often, though, fixed payment is arranged on a per-project basis regardless of hours, which I understand to be a dangerous practice. (Scope creep is my arch nemesis! ;) - Alice From robert.kern at gmail.com Sat Dec 25 09:17:27 2010 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 25 Dec 2010 09:17:27 -0500 Subject: How to pop the interpreter's stack? In-Reply-To: <4D151B52.4030502@stoneleaf.us> References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d1427ac$0$30000$c3e8da3$5496439d@news.astraweb.com> <3771d7ec-c030-4d15-a257-4c895ff57ec0@n2g2000pre.googlegroups.com> <4d1466d2$0$30000$c3e8da3$5496439d@news.astraweb.com> <4D151B52.4030502@stoneleaf.us> Message-ID: On 12/24/10 5:14 PM, Ethan Furman wrote: > There are also times when I change the exception being raised to match > what python expects from that type of object -- for example, from > WhatEverException to KeyError for a dict-like object. So in this regard I agree > with Steven. Steven isn't arguing that particular point here, nor is anyone arguing against it. -- 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 Sat Dec 25 09:21:54 2010 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 25 Dec 2010 09:21:54 -0500 Subject: How to pop the interpreter's stack? In-Reply-To: <4d1466d2$0$30000$c3e8da3$5496439d@news.astraweb.com> References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d1427ac$0$30000$c3e8da3$5496439d@news.astraweb.com> <3771d7ec-c030-4d15-a257-4c895ff57ec0@n2g2000pre.googlegroups.com> <4d1466d2$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 12/24/10 4:24 AM, Steven D'Aprano wrote: > On Thu, 23 Dec 2010 22:38:05 -0800, Carl Banks wrote: >> OTOH, going the extra mile to hide useful information from a user is >> asinine. As a user, I will decide for myself how I want to use >> implementation-defined information, and I don't want the implementor to >> decide this for me. It's bad enough if an implementor fails to provide >> information out of laziness, but when they deliberately do extra work to >> hide information, that's self-importance and arrogance. > > But that of course is nonsense, because as the user you don't decide > anything of the sort. The developer responsible for writing the function > decides what information he provides you, starting with whether you get > an exception at all, where it comes from, the type of exception, and the > error message (if any). Carl isn't arguing that the user is or should be responsible for this sort of thing. He is arguing that developers should be responsible for doing this in such a way that is beneficial for the developer/user down the road. > Once this information has been passed on to you, > you're free to do anything you like with it, but you never get to choose > what information you get -- I'm not suggesting any change there. All I'm > suggesting is that there should be a way of reducing the boilerplate > needed for this idiom: > > def _validate_arg(x): > if x == 'bad input': return False > return True > > def f(arg): > if not _validate_arg(arg): > raise ValueError > process(arg) > > to something more natural that doesn't needlessly expose implementation > details that are completely irrelevant to the caller. Except that the *caller* never gets the traceback (unless if it deliberately inspects the stack for some metaprogramming reason). It gets the exception, and that is the same no matter what you do. The developer/user gets the traceback, and those implementation details *are* often important to them. -- 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 Sat Dec 25 10:42:29 2010 From: roy at panix.com (Roy Smith) Date: Sat, 25 Dec 2010 10:42:29 -0500 Subject: Keeping track of the N largest values Message-ID: I'm processing a stream of N numbers and want to keep track of the K largest. There's too many numbers in the stream (i.e. N is too large) to keep in memory at once. K is small (100 would be typical). >From a theoretical point of view, I should be able to do this in N log K time. What I'm doing now is essentially: top = [-1] # Assume all x are >= 0 for x in input(): if x <= top[0]: continue top.append(x) if len(top) > K: top.sort() top.pop(0) I can see pathological cases (say, all input values the same) where running time would be N K log K, but on average (N >> K and random distribution of values), this should be pretty close to N. Is there a better way to do this, either from a theoretical running time point of view, or just a nicer way to code this in Python? From steve at holdenweb.com Sat Dec 25 10:55:13 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 25 Dec 2010 10:55:13 -0500 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: <4D13C04E.6070103@pythonmeister.com> References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> Message-ID: On 12/23/2010 4:34 PM, Stefan Sonnenberg-Carstens wrote: > For large datasets I always have huge question marks if one says "xml". > But I don't want to start a flame war. I agree people abuse the "spirit of XML" using it to transfer gigabytes of data, but what else are they to use? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sat Dec 25 10:56:15 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 25 Dec 2010 10:56:15 -0500 Subject: What is the the best style and theory of writing a complier in your language In-Reply-To: References: Message-ID: On 12/23/2010 5:01 PM, small Pox wrote: > What is the the best style and theory of writing a complier in your > language > > Maybe a book will suffice. > > http://something-argumentative/ > > I want to parse the contents of the above link into hebrew audio. > > CHEERIOS > Sure you do. regareds Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From duncan.booth at invalid.invalid Sat Dec 25 10:58:35 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 25 Dec 2010 15:58:35 GMT Subject: type(d) != type(d.copy()) when type(d).issubclass(dict) References: Message-ID: kj wrote: > Watch this: > >>>> class neodict(dict): pass > ... >>>> d = neodict() >>>> type(d) > >>>> type(d.copy()) > > > > Bug? Feature? Genius beyond the grasp of schlubs like me? Feature. In (almost?) all cases any objects constructed by a subclass of a builtin class will be of the original builtin class. So, for example, subclass a string and concatenating your subclassed objects still produces a string. This is reasonable behaviour as for builtin classes performance is more important than fully implementing polymorphism. If you want to subclass a builtin class you need to be aware of this and override the behaviour where it matters. Why do you want to subclass a dict anyway? It is usually the wrong choice. -- Duncan Booth http://kupuguy.blogspot.com From __peter__ at web.de Sat Dec 25 11:04:07 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 25 Dec 2010 17:04:07 +0100 Subject: Keeping track of the N largest values References: Message-ID: Roy Smith wrote: > I'm processing a stream of N numbers and want to keep track of the K > largest. There's too many numbers in the stream (i.e. N is too large) > to keep in memory at once. K is small (100 would be typical). > > From a theoretical point of view, I should be able to do this in N log K > time. What I'm doing now is essentially: > > top = [-1] # Assume all x are >= 0 > for x in input(): > if x <= top[0]: > continue > top.append(x) > if len(top) > K: > top.sort() > top.pop(0) > > I can see pathological cases (say, all input values the same) where > running time would be N K log K, but on average (N >> K and random > distribution of values), this should be pretty close to N. > > Is there a better way to do this, either from a theoretical running time > point of view, or just a nicer way to code this in Python? http://docs.python.org/library/heapq.html#heapq.nlargest From duncan.booth at invalid.invalid Sat Dec 25 11:09:08 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 25 Dec 2010 16:09:08 GMT Subject: Keeping track of the N largest values References: Message-ID: Roy Smith wrote: > > I'm processing a stream of N numbers and want to keep track of the K > largest. There's too many numbers in the stream (i.e. N is too large) > to keep in memory at once. K is small (100 would be typical). > ... > Is there a better way to do this, either from a theoretical running > time point of view, or just a nicer way to code this in Python? How about: from heapq import nlargest top = nlargest(K, input()) It uses a heap so avoids completely resorting each time. -- Duncan Booth http://kupuguy.blogspot.com From stefan_ml at behnel.de Sat Dec 25 11:51:09 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 25 Dec 2010 17:51:09 +0100 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> Message-ID: Steve Holden, 25.12.2010 16:55: > On 12/23/2010 4:34 PM, Stefan Sonnenberg-Carstens wrote: >> For large datasets I always have huge question marks if one says "xml". >> But I don't want to start a flame war. > > I agree people abuse the "spirit of XML" using it to transfer gigabytes > of data I keep reading people say that (and *much* worse). XML may not be the tightly tailored solution for data of that size, but it's not inherently wrong to store gigabytes of data in XML. I mean, XML is a reasonably fast, versatile, widely used, well-compressing and safe data format with an extremely ubiquitous and well optimised set of tools available for all sorts of environments. So as soon as the data is any complex or the environments require portable data exchange, I consider XML a reasonable choice, even for large data sets (which usually implies that it's machine generated outputo anyway). Stefan From robert.kern at gmail.com Sat Dec 25 12:09:09 2010 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 25 Dec 2010 12:09:09 -0500 Subject: Keeping track of the N largest values In-Reply-To: References: Message-ID: On 12/25/10 10:42 AM, Roy Smith wrote: > I'm processing a stream of N numbers and want to keep track of the K > largest. There's too many numbers in the stream (i.e. N is too large) > to keep in memory at once. K is small (100 would be typical). > >> From a theoretical point of view, I should be able to do this in N log K > time. What I'm doing now is essentially: > > top = [-1] # Assume all x are>= 0 > for x in input(): > if x<= top[0]: > continue > top.append(x) > if len(top)> K: > top.sort() > top.pop(0) > > I can see pathological cases (say, all input values the same) where > running time would be N K log K, but on average (N>> K and random > distribution of values), this should be pretty close to N. > > Is there a better way to do this, either from a theoretical running time > point of view, or just a nicer way to code this in Python? heapq.nlargest() http://docs.python.org/library/heapq#heapq.nlargest -- 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 awilliam at whitemice.org Sat Dec 25 12:21:39 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Sat, 25 Dec 2010 11:21:39 -0600 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> Message-ID: "Steve Holden" wrote: >On 12/23/2010 4:34 PM, Stefan Sonnenberg-Carstens wrote: >> For large datasets I always have huge question marks if one says >"xml". >> But I don't want to start a flame war. >I agree people abuse the "spirit of XML" using it to transfer gigabytes >of data, How so? I think this assertion is bogus. XML works extremely well for large datasets. >but what else are they to use? If you are sending me data - please use XML . I've gotten 22GB XML files in the past - worked without issue and pretty quickly too. Sure better than trying to figure out whatever goofy document format someone cooks up on their own. XML toolkits are proven and documented. From usernet at ilthio.net Sat Dec 25 12:27:15 2010 From: usernet at ilthio.net (Tim Harig) Date: Sat, 25 Dec 2010 17:27:15 +0000 (UTC) Subject: Trying to parse a HUGE(1gb) xml file References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> Message-ID: On 2010-12-25, Steve Holden wrote: > On 12/23/2010 4:34 PM, Stefan Sonnenberg-Carstens wrote: >> For large datasets I always have huge question marks if one says "xml". >> But I don't want to start a flame war. I would agree; but, you don't always have the choice over the data format that you have to work with. You just have to do the best you can with what they give you. > I agree people abuse the "spirit of XML" using it to transfer gigabytes > of data, but what else are they to use? Something with an index so that you don't have to parse the entire file would be nice. SQLite comes to mind. It is not standardized; but, the implementation is free with bindings for most languages. From martin.kaspar at campus-24.com Sat Dec 25 12:58:55 2010 From: martin.kaspar at campus-24.com (Martin Kaspar) Date: Sat, 25 Dec 2010 09:58:55 -0800 (PST) Subject: python-parser running Beautiful Soup only spits out one line of 10. What i have gotten wrong here? Message-ID: <7fa4881d-269b-46ef-a8b4-72f8a8ba9e34@i41g2000vbn.googlegroups.com> Hello dear Community,. I am trying to get a scraper up and running: And keep running into problems. when I try what you have i have learnedd so far I only get: Schuldaten Here is the code that I used: import urllib2 from BeautifulSoup import BeautifulSoup page = urllib2.urlopen("http://www.schulministerium.nrw.de/BP/ SchuleSuchen?action=799.601437941842&SchulAdresseMapDO=142323") soup = BeautifulSoup(page) table = soup.find('table' ,attrs={'class':'bp_ergebnis_tab_info'}) first_td = soup.find('td') text = first_td.renderContents() trimmed_text = text.strip() print trimmed_text i run it in the template at http://scraperwiki.com/scrapers/new/python see the target: http://www.schulministerium.nrw.de/BP/SchuleSuchen?action=799.601437941842&SchulAdresseMapDO=142323 What have I gotten wrong? Can anybody review the code - many thanks in Advance regards matze From nagle at animats.com Sat Dec 25 13:36:22 2010 From: nagle at animats.com (John Nagle) Date: Sat, 25 Dec 2010 10:36:22 -0800 Subject: python-parser running Beautiful Soup only spits out one line of 10. What i have gotten wrong here? In-Reply-To: <7fa4881d-269b-46ef-a8b4-72f8a8ba9e34@i41g2000vbn.googlegroups.com> References: <7fa4881d-269b-46ef-a8b4-72f8a8ba9e34@i41g2000vbn.googlegroups.com> Message-ID: <4d1639a0$0$44022$742ec2ed@news.sonic.net> Your program is doing what you asked it to do. It finds the first table with class 'bp_ergebnis_tab_info'. Then it ignores that results. Then it finds the first "td" item in the document, and prints the contents of that. Then it exits. What did you want it to do? Try this. It prints out the TD items on each row of the table, in order. import urllib2 from BeautifulSoup import BeautifulSoup page = urllib2.urlopen("http://www.schulministerium.nrw.de/BP/SchuleSuchen?action=799.601437941842&SchulAdresseMapDO=142323") soup = BeautifulSoup(page) table = soup.find('table' ,attrs={'class':'bp_ergebnis_tab_info'}) for row in table.findAll('tr') : # for all TR items (table rows) for td in row.findAll('td') : # for TD items in row text = td.renderContents().strip() print(text) print('-----') # mark end of row John Nagle On 12/25/2010 9:58 AM, Martin Kaspar wrote: > Hello dear Community,. > I am trying to get a scraper up and running: And keep running into > problems. > > when I try what you have i have learned so far I only get: > Schuldaten > > Here is the code that I used: > > import urllib2 > from BeautifulSoup import BeautifulSoup > page = urllib2.urlopen("http://www.schulministerium.nrw.de/BP/ > SchuleSuchen?action=799.601437941842&SchulAdresseMapDO=142323") > soup = BeautifulSoup(page) > table = soup.find('table' ,attrs={'class':'bp_ergebnis_tab_info'}) > first_td = soup.find('td') > text = first_td.renderContents() > trimmed_text = text.strip() > print trimmed_text > > > i run it in the template at http://scraperwiki.com/scrapers/new/python > > see the target: http://www.schulministerium.nrw.de/BP/SchuleSuchen?action=799.601437941842&SchulAdresseMapDO=142323 > > What have I gotten wrong? > > Can anybody review the code - > > many thanks in Advance > > regards > matze From roy at panix.com Sat Dec 25 14:16:27 2010 From: roy at panix.com (Roy Smith) Date: Sat, 25 Dec 2010 14:16:27 -0500 Subject: Keeping track of the N largest values References: Message-ID: In article , Duncan Booth wrote: > Roy Smith wrote: > > > > > I'm processing a stream of N numbers and want to keep track of the K > > largest. There's too many numbers in the stream (i.e. N is too large) > > to keep in memory at once. K is small (100 would be typical). > > ... > > Is there a better way to do this, either from a theoretical running > > time point of view, or just a nicer way to code this in Python? > > How about: > > from heapq import nlargest > top = nlargest(K, input()) > > It uses a heap so avoids completely resorting each time. Hmmm, that looks like it would solve the problem as stated, but there's another twist. In addition to finding the K largest values, I *also* need to do some other processing on all the values (which I didn't show in the original example, incorrectly thinking it not germane to my question). The problem with nlargest() is that it doesn't give me a hook to do that. PS: I'm assuming heapq.nlargest(n, iterable) operates with memory proportional to n, and not to the iterator length. That's the only reasonable conclusion, but the docs don't actually come out and say it. From roy at panix.com Sat Dec 25 14:41:29 2010 From: roy at panix.com (Roy Smith) Date: Sat, 25 Dec 2010 14:41:29 -0500 Subject: Trying to parse a HUGE(1gb) xml file References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> Message-ID: In article , Adam Tauno Williams wrote: > XML works extremely well for large datasets. Barf. I'll agree that there are some nice points to XML. It is portable. It is (to a certain extent) human readable, and in a pinch you can use standard text tools to do ad-hoc queries (i.e. grep for a particular entry). And, yes, there are plenty of toolsets for dealing with XML files. On the other hand, the verbosity is unbelievable. I'm currently working with a data feed we get from a supplier in XML. Every day we get incremental updates of about 10-50 MB each. The total data set at this point is 61 GB. It's got stuff like this in it: FALSE That's 54 bytes to store a single bit of information. I'm all for human-readable formats, but bloating the data by a factor of 432 is rather excessive. Of course, that's an extreme example. A more efficient example would be: 1173722 which is 26 bytes to store an integer. That's only a bloat factor of 6-1/2. Of course, one advantage of XML is that with so much redundant text, it compresses well. We typically see gzip compression ratios of 20:1. But, that just means you can archive them efficiently; you can't do anything useful until you unzip them. From no.email at nospam.invalid Sat Dec 25 14:41:58 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 25 Dec 2010 11:41:58 -0800 Subject: Keeping track of the N largest values References: Message-ID: <7xtyi1od15.fsf@ruckus.brouhaha.com> Roy Smith writes: >> from heapq import nlargest >> top = nlargest(K, input()) > In addition to finding the K largest values, I *also* need to do some > other processing on all the values .... The problem with nlargest() > is that it doesn't give me a hook to do that. def processed_input(): for x in input(): process(x) yield x top = nlargest(K, processed_input()) You could also write that more consisely with genexps but it's a bit clumsy. From nagle at animats.com Sat Dec 25 15:26:32 2010 From: nagle at animats.com (John Nagle) Date: Sat, 25 Dec 2010 12:26:32 -0800 Subject: Keeping track of the N largest values In-Reply-To: References: Message-ID: <4d165372$0$44038$742ec2ed@news.sonic.net> On 12/25/2010 8:04 AM, Peter Otten wrote: > Roy Smith wrote: > >> I'm processing a stream of N numbers and want to keep track of the K >> largest. There's too many numbers in the stream (i.e. N is too large) >> to keep in memory at once. K is small (100 would be typical). > > http://docs.python.org/library/heapq.html#heapq.nlargest Incidentally, if it happens that the data is already in a database, MySQL will do that. SELECT val FROM tab ORDER BY val DESC LIMIT N; will, for small N, keep only N values. For large N, it sorts. That's for an un-indexed field. If "val" is an index, this is a very fast operation, since the tree building has already been done. John Nagle From stefan.sonnenberg at pythonmeister.com Sat Dec 25 15:51:16 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Sat, 25 Dec 2010 21:51:16 +0100 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> Message-ID: <4D165944.6000801@pythonmeister.com> Am 25.12.2010 20:41, schrieb Roy Smith: > In article, > Adam Tauno Williams wrote: > >> XML works extremely well for large datasets. > Barf. I'll agree that there are some nice points to XML. It is > portable. It is (to a certain extent) human readable, and in a pinch > you can use standard text tools to do ad-hoc queries (i.e. grep for a > particular entry). And, yes, there are plenty of toolsets for dealing > with XML files. > > On the other hand, the verbosity is unbelievable. I'm currently working > with a data feed we get from a supplier in XML. Every day we get > incremental updates of about 10-50 MB each. The total data set at this > point is 61 GB. It's got stuff like this in it: > > FALSE > > That's 54 bytes to store a single bit of information. I'm all for > human-readable formats, but bloating the data by a factor of 432 is > rather excessive. Of course, that's an extreme example. A more > efficient example would be: > > 1173722 > > which is 26 bytes to store an integer. That's only a bloat factor of > 6-1/2. > > Of course, one advantage of XML is that with so much redundant text, it > compresses well. We typically see gzip compression ratios of 20:1. > But, that just means you can archive them efficiently; you can't do > anything useful until you unzip them. Sending complete SQLite databases is absolute perfect. For example Fedora uses (used?) this for their yum catalog updates. Download to the right place, point your tool to it, ready. From nobody at nowhere.com Sat Dec 25 17:34:02 2010 From: nobody at nowhere.com (Nobody) Date: Sat, 25 Dec 2010 22:34:02 +0000 Subject: Trying to parse a HUGE(1gb) xml file References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> Message-ID: On Sat, 25 Dec 2010 14:41:29 -0500, Roy Smith wrote: >> XML works extremely well for large datasets. One advantage it has over many legacy formats is that there are no inherent 2^31/2^32 limitations. Many binary formats inherently cannot support files larger than 2GiB or 4Gib due to the use of 32-bit offsets in indices. > Of course, one advantage of XML is that with so much redundant text, it > compresses well. We typically see gzip compression ratios of 20:1. > But, that just means you can archive them efficiently; you can't do > anything useful until you unzip them. XML is typically processed sequentially, so you don't need to create a decompressed copy of the file before you start processing it. If file size is that much of an issue, eventually we'll see a standard for compressing XML. This could easily result in smaller files than using a dedicated format compressed with general-purpose compression algorithms, as a widely-used format such as XML merits more effort than any application-specific format. From devplayer at gmail.com Sat Dec 25 17:41:16 2010 From: devplayer at gmail.com (DevPlayer) Date: Sat, 25 Dec 2010 14:41:16 -0800 (PST) Subject: How can a function find the function that called it? References: <87d3orvvz6.fsf.mdw@metalzone.distorted.org.uk> Message-ID: <6d34e6ad-1273-44fa-99b7-587daf35fe8b@t35g2000yqj.googlegroups.com> > Original Poster > I thought I'd implement it as a subclass of collections.OrderedDict > that prohibits all modifications to the dictionary after it has > been initialized. I thought the __new__() method was for customizing how objects where instantated. Where in __new__() you would get an object instance and then usually initialize the public data attributes in __init__(). Although I like Mark Wooding's solution as it's clean and easy to understand. From steve+comp.lang.python at pearwood.info Sat Dec 25 17:41:49 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Dec 2010 22:41:49 GMT Subject: type(d) != type(d.copy()) when type(d).issubclass(dict) References: Message-ID: <4d16732c$0$29974$c3e8da3$5496439d@news.astraweb.com> On Sat, 25 Dec 2010 15:58:35 +0000, Duncan Booth wrote: > kj wrote: > >> Watch this: >> >>>>> class neodict(dict): pass >> ... >>>>> d = neodict() >>>>> type(d) >> >>>>> type(d.copy()) >> >> >> >> Bug? Feature? Genius beyond the grasp of schlubs like me? > > Feature. I'd say it is neither, and call it a bloody nuisance that nevertheless has some justification. > In (almost?) all cases any objects constructed by a subclass of a > builtin class will be of the original builtin class. So, for example, > subclass a string and concatenating your subclassed objects still > produces a string. Yes, and the consequence is that any serious subclass must overload every method which returns a new instance, otherwise your new subclass doesn't "stick" -- you find it being replaced by the builtin as soon as you start doing something useful with it. This is especially a nuisance for subclasses of (say) float, where you end up writing heaps of boilerplate like this: class MyFloat(float): def __add__(self, other): return self.__class__(super(MyFloat, self).__add__(other)) # and the same for __mul__, __sub__, __rsub__, __pow__, ... > This is reasonable behaviour as for builtin classes performance is more > important than fully implementing polymorphism. If you want to subclass > a builtin class you need to be aware of this and override the behaviour > where it matters. Yes, but I think builtins could probably afford one extra identity check. Something like this: # Pseudocode if type(self) is builtin type: do exactly what is done now else: do something slower, but kinder for superclasses For all I know, the slower branch might be something as simple as calling the C equivalent of type(self)(arg). -- Steven From steve+comp.lang.python at pearwood.info Sat Dec 25 17:49:08 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Dec 2010 22:49:08 GMT Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d1427ac$0$30000$c3e8da3$5496439d@news.astraweb.com> <3771d7ec-c030-4d15-a257-4c895ff57ec0@n2g2000pre.googlegroups.com> <4d1466d2$0$30000$c3e8da3$5496439d@news.astraweb.com> <4D151B52.4030502@stoneleaf.us> Message-ID: <4d1674e4$0$29974$c3e8da3$5496439d@news.astraweb.com> On Sat, 25 Dec 2010 09:17:27 -0500, Robert Kern wrote: > On 12/24/10 5:14 PM, Ethan Furman wrote: > >> There are also times when I change the exception being raised to match >> what python expects from that type of object -- for example, from >> WhatEverException to KeyError for a dict-like object. So in this regard >> I agree with Steven. > > Steven isn't arguing that particular point here, nor is anyone arguing > against it. Emphasis on *here*. You will note that in Python 3, if you raise an exception inside an except block, both the *original* and the new exception are printed. This is great for fixing bugs inside except blocks, but terribly disruptive for catching one error and raising another error in it's place, e.g.: try: x+0 except ValueError, TypeError as e: # x is not a numeric value, e.g. a string or a NAN. raise MyError('x is not a number') The explicit raise is assumed to indicate a bug in the except block, and the original exception is printed as well. But that's a separate issue from what is being discussed here. What we're discussing here is the idea that a function should be able to delegate work to private subroutines without the caller being aware of that fact. When you return a value, the caller doesn't see the internal details of how you calculated the value, but if you deliberately raise an exception, the caller does. Often this is the right thing to do, but sometimes it isn't. E.g. you can't delegate input validation to a subroutine and raise inside the subroutine without obfuscating the traceback. -- Steven From steve+comp.lang.python at pearwood.info Sat Dec 25 17:49:20 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Dec 2010 22:49:20 GMT Subject: I don't why there is no output.... References: Message-ID: <4d1674f0$0$29974$c3e8da3$5496439d@news.astraweb.com> On Fri, 24 Dec 2010 16:22:18 -0800, chad wrote: >> I don't get it. I was expecting to see the output from both the tty and >> cat. Instead, I see nothing. Why? > > Never mind. I figured it out. Well, don't keep us in suspenders. What was the problem? -- Steven From steve+comp.lang.python at pearwood.info Sat Dec 25 17:50:00 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Dec 2010 22:50:00 GMT Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d1427ac$0$30000$c3e8da3$5496439d@news.astraweb.com> <3771d7ec-c030-4d15-a257-4c895ff57ec0@n2g2000pre.googlegroups.com> <4d1466d2$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d14ebaf$0$44021$742ec2ed@news.sonic.net> Message-ID: <4d167517$0$29974$c3e8da3$5496439d@news.astraweb.com> On Fri, 24 Dec 2010 10:51:32 -0800, John Nagle wrote: > On 12/24/2010 3:24 AM, Carl Banks wrote: >> On Dec 24, 1:24 am, Steven D'Aprano> +comp.lang.pyt... at pearwood.info> wrote: > All I'm >>> suggesting is that there should be a way of reducing the boilerplate >>> needed for this idiom: >>> >>> def _validate_arg(x): >>> if x == 'bad input': return False >>> return True >>> >>> def f(arg): >>> if not _validate_arg(arg): >>> raise ValueError >>> process(arg) >>> >>> to something more natural that doesn't needlessly expose >>> implementation details that are completely irrelevant to the caller. > > How about > > raise ValueError("Bad input %s to validate_arg" % (repr(arg),)) > > You can pass arguments to most exceptions, and the content of the > exception is determined entirely by the code raising it. I know that exceptions can take arguments (usually string error messages). I was writing in short-hand. My apologies, I thought that would have been obvious :( Perhaps you have missed the context of the discussion. The context is that the called function delegates the job of validating input to a private function, which should be hidden from the caller (it's private, not part of the public API, subject to change, hidden, etc.) but tracebacks expose that information, obscuring the cause of the fault. (The fault being bad input to the public function, not an accidental bug in the private function.) > If end users are seeing uncaught tracebacks, the program is broken. Well, perhaps, but that's a separate issue. We're talking about the caller of the function seeing internal details, not the end use. -- Steven From awilliam at whitemice.org Sat Dec 25 18:29:15 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Sat, 25 Dec 2010 18:29:15 -0500 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> Message-ID: <1293319755.8800.2.camel@linux-yu4c.site> On Sat, 2010-12-25 at 22:34 +0000, Nobody wrote: > On Sat, 25 Dec 2010 14:41:29 -0500, Roy Smith wrote: > >> XML works extremely well for large datasets. > One advantage it has over many legacy formats is that there are no > inherent 2^31/2^32 limitations. Many binary formats inherently cannot > support files larger than 2GiB or 4Gib due to the use of 32-bit offsets in > indices. And what legacy format has support for code pages, namespaces, schema verification, or comments? None. > > Of course, one advantage of XML is that with so much redundant text, it > > compresses well. We typically see gzip compression ratios of 20:1. > > But, that just means you can archive them efficiently; you can't do > > anything useful until you unzip them. > XML is typically processed sequentially, so you don't need to create a > decompressed copy of the file before you start processing it. Yep. > If file size is that much of an issue, Which it isn't. > eventually we'll see a standard for > compressing XML. This could easily result in smaller files than using a > dedicated format compressed with general-purpose compression algorithms, > as a widely-used format such as XML merits more effort than any > application-specific format. Agree; and there actually already is a standard compression scheme - HTTP compression [supported by every modern web-server]; so the data is compressed at the only point where it matters [during transfer]. Again: "XML works extremely well for large datasets". From jim.hefferon at gmail.com Sat Dec 25 18:32:50 2010 From: jim.hefferon at gmail.com (Jim) Date: Sat, 25 Dec 2010 15:32:50 -0800 (PST) Subject: lxml etree question References: <98fb45fe-e4d0-49f4-a705-7923b2bfcacb@k22g2000yqh.googlegroups.com> Message-ID: On Dec 25, 5:33?am, Stefan Behnel wrote: > lxml knows about this special case, so you can write > > ? ? ? ? {http://www.w3.org/XML/1998/namespace}lang > > and lxml will take care of using the right prefix. Stefan, thank you for the software, which has helped me a great deal. I tried that exact thing, among a number of others, and it didn't work for me (I got ns0). I'll try again, this time with the understanding that it is the right one, and so perhaps I may discover some small error in what I tried. Regards, and thanks again, Jim From bc at freeuk.com Sat Dec 25 19:11:20 2010 From: bc at freeuk.com (BartC) Date: Sun, 26 Dec 2010 00:11:20 -0000 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com><4D13C04E.6070103@pythonmeister.com> Message-ID: "Adam Tauno Williams" wrote in message news:mailman.287.1293319780.6505.python-list at python.org... > On Sat, 2010-12-25 at 22:34 +0000, Nobody wrote: >> On Sat, 25 Dec 2010 14:41:29 -0500, Roy Smith wrote: >> >> XML works extremely well for large datasets. >> One advantage it has over many legacy formats is that there are no >> inherent 2^31/2^32 limitations. Many binary formats inherently cannot >> support files larger than 2GiB or 4Gib due to the use of 32-bit offsets >> in >> indices. > > And what legacy format has support for code pages, namespaces, schema > verification, or comments? None. > >> > Of course, one advantage of XML is that with so much redundant text, it >> > compresses well. We typically see gzip compression ratios of 20:1. >> > But, that just means you can archive them efficiently; you can't do >> > anything useful until you unzip them. >> XML is typically processed sequentially, so you don't need to create a >> decompressed copy of the file before you start processing it. > > Yep. > >> If file size is that much of an issue, > > Which it isn't. Only if you're prepared to squander resources that could be put to better use. XML is so redundant, anyone (even me :-) could probably spend an afternoon coming up with a compression scheme to reduce it to a fraction of it's size. It can even be an custom format, provided you also send along the few dozen lines of Python (or whatever language) needed to decompress. Although if it's done properly, it might be possible to create an XML library that works directly on the compressed format, and as a plug-in replacement for a conventional library. That will likely save time and memory. Anyway there seem to be existing schemes for binary XML, indicating some people do think it is an issue. I'm just concerned at the waste of computer power (I used to think HTML was bad, for example repeating the same long-winded font name hundreds of times over in the same document. And PDF: years ago I was sent a 1MB document for a modem; perhaps some substantial user manual for it? No, just a simple diagram showing how to plug it into the phone socket!). -- Bartc From pyhtonv at gmail.com Sat Dec 25 19:14:22 2010 From: pyhtonv at gmail.com (Varuna Seneviratna) Date: Sun, 26 Dec 2010 05:44:22 +0530 Subject: I am not able to verify the integrity of python.2.5.4.msi Message-ID: Hello there! I downloaded python msi version for Windows from http://www.python.org/download/releases/2.5.4/ .At the bottom of the page it is said that "The signatures above were generated with GnuPG using release manager Martin v. L?wis's public key which has a key id of 7D9DC8D2" according to this description I want to the page http://www.python.org/download/#pubkeys and downloaded the file http://www.dcl.hpi.uni-potsdam.de/people/loewis/mvl.asc and imported it into gpg as below D:\Python>gpg --import mvl.asc.txt > > gpg: key 7D9DC8D2: "Martin v. L?wis " not changed > > gpg: Total number processed: 1 > > gpg: unchanged: 1 > > And also I downloaded the Signature of python-2.5.4.msi from the download page http://www.python.org/download/releases/2.5.4/python-2.5.4.msi.asc But when I try to verify the integrity of the downloaded Python installation package as below > D:\Python>gpg --verify python-2.5.4.msi.asc gpg: no valid OpenPGP data found. gpg: the signature could not be verified. Please remember that the signature file (.sig or .asc) should be the first file given on the command line What am I doing wrong in this process? Please help me! Varuna -------------- next part -------------- An HTML attachment was scrubbed... URL: From usernet at ilthio.net Sat Dec 25 20:05:53 2010 From: usernet at ilthio.net (Tim Harig) Date: Sun, 26 Dec 2010 01:05:53 +0000 (UTC) Subject: Trying to parse a HUGE(1gb) xml file References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> Message-ID: On 2010-12-25, Nobody wrote: > On Sat, 25 Dec 2010 14:41:29 -0500, Roy Smith wrote: >>> XML works extremely well for large datasets. > One advantage it has over many legacy formats is that there are no > inherent 2^31/2^32 limitations. Many binary formats inherently cannot > support files larger than 2GiB or 4Gib due to the use of 32-bit offsets in > indices. That is probably true of many older and binary formats; but, XML is certainly not the the only format that supports arbitrary size. It certainly doesn't prohibit another format with better handling of large data sets from being developed. XML's primary benefit is its ubiquity. While it is an excellent format for a number of uses, I don't accept ubiquity as the only or preeminent metric when choosing a data format. >> Of course, one advantage of XML is that with so much redundant text, it >> compresses well. We typically see gzip compression ratios of 20:1. >> But, that just means you can archive them efficiently; you can't do >> anything useful until you unzip them. > > XML is typically processed sequentially, so you don't need to create a > decompressed copy of the file before you start processing it. Sometimes XML is processed sequentially. When the markup footprint is large enough it must be. Quite often, as in the case of the OP, you only want to extract a small piece out of the total data. In those cases, being forced to read all of the data sequentially is both inconvenient and and a performance penalty unless there is some way to address the data you want directly. From usernet at ilthio.net Sat Dec 25 20:13:29 2010 From: usernet at ilthio.net (Tim Harig) Date: Sun, 26 Dec 2010 01:13:29 +0000 (UTC) Subject: Trying to parse a HUGE(1gb) xml file References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> Message-ID: On 2010-12-25, Adam Tauno Williams wrote: > On Sat, 2010-12-25 at 22:34 +0000, Nobody wrote: >> On Sat, 25 Dec 2010 14:41:29 -0500, Roy Smith wrote: >> XML is typically processed sequentially, so you don't need to create a >> decompressed copy of the file before you start processing it. > > Yep. Sometimes that is true and sometimes it isn't. There are many situations where you want to access the data nonsequentially or address just a small subset of it. Just because you never want to access data randomly doesn't mean others might not. Certainly the OP would be happier using something like XPath to get just the piece of data that he is looking for. From gervaz at gmail.com Sat Dec 25 20:46:04 2010 From: gervaz at gmail.com (gervaz) Date: Sat, 25 Dec 2010 17:46:04 -0800 (PST) Subject: Signal handler & cygwin Message-ID: <55a87adf-a980-4a9f-ac41-1ebf4996cb21@o4g2000yqd.googlegroups.com> Hi all, given the followin code snippet: import signal import time import sys import os print("{0}\n".format(os.getpid())) ContinueProcessing = True def stop(signal, frame): print("\nSignal received!\n") time.sleep(1) global ContinueProcessing ContinueProcessing = False signal.signal(signal.SIGINT, stop) while ContinueProcessing: try: sys.stdout.write(".") sys.stdout.flush() time.sleep(0.1) except: continue if I kill the process using kill -s SIGINT PID in linux everything works fine and the signal is correctly handled, while in win, using cywin (/bin/kill.exe -f -s SIGINT WINPID), the program just exits without trapping the interrupt. Any similar experience? From katie at coderstack.co.uk Sat Dec 25 21:02:39 2010 From: katie at coderstack.co.uk (Katie T) Date: Sun, 26 Dec 2010 02:02:39 +0000 Subject: Python Web App In-Reply-To: <907fa80e-1814-4ddb-be32-ec14cfd53fab@29g2000yqq.googlegroups.com> References: <907fa80e-1814-4ddb-be32-ec14cfd53fab@29g2000yqq.googlegroups.com> Message-ID: On Wed, Dec 22, 2010 at 9:43 PM, Sean wrote: > Anybody know where I can find a Python Development Environment in the > form of a web app for use with Chrome OS. I have been looking for a > few days and all i have been able to find is some old discussions with > python developers talking about they will want one for the OS to be a > success with them. Your best bet is probably just to SSH to a *nix box and use something like vim or emacs. None of the web solutions are anywhere near acceptable. Katie -- CoderStack http://www.coderstack.co.uk/python-jobs The Software Developer Job Board From katie at coderstack.co.uk Sat Dec 25 21:06:13 2010 From: katie at coderstack.co.uk (Katie T) Date: Sun, 26 Dec 2010 02:06:13 +0000 Subject: Python Average Salary Report In-Reply-To: References: Message-ID: On Sat, Dec 25, 2010 at 11:38 AM, czarina08 wrote: > I'm doing a market research report on the average hourly rates for > Python/Django developers. Any input on this? I do understand that it > does depend on the location, amount of experience and skills. I'd like > to hear what are the hourly rates within your area :-) Thanks! Sector and location have a much bigger impact than language/platform on salary (although obviously demand for different languages varies by sector and location as well). Katie -- CoderStack http://www.coderstack.co.uk/python-jobs The Software Developer Job Board From research at johnohagan.com Sat Dec 25 21:40:16 2010 From: research at johnohagan.com (John O'Hagan) Date: Sun, 26 Dec 2010 02:40:16 +0000 Subject: type(d) != type(d.copy()) when type(d).issubclass(dict) In-Reply-To: <4d16732c$0$29974$c3e8da3$5496439d@news.astraweb.com> References: <4d16732c$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <201012260240.16761.research@johnohagan.com> On Sat, 25 Dec 2010, Steven D'Aprano wrote: > On Sat, 25 Dec 2010 15:58:35 +0000, Duncan Booth wrote: > > kj wrote: > >> Watch this: > >>>>> class neodict(dict): pass > >> > >> ... > >> > >>>>> d = neodict() > >>>>> type(d) > >> > >> > >> > >>>>> type(d.copy()) > >> > >> > >> > >> Bug? Feature? Genius beyond the grasp of schlubs like me? > > > > Feature. > > I'd say it is neither, and call it a bloody nuisance that nevertheless > has some justification. > > > In (almost?) all cases any objects constructed by a subclass of a > > builtin class will be of the original builtin class. So, for example, > > subclass a string and concatenating your subclassed objects still > > produces a string. > > Yes, and the consequence is that any serious subclass must overload every > method which returns a new instance, otherwise your new subclass doesn't > "stick" -- you find it being replaced by the builtin as soon as you start > doing something useful with it. > > This is especially a nuisance for subclasses of (say) float, where you > end up writing heaps of boilerplate like this: > > class MyFloat(float): > def __add__(self, other): > return self.__class__(super(MyFloat, self).__add__(other)) > # and the same for __mul__, __sub__, __rsub__, __pow__, ... [...] I've occasionally wished I could just: import builtin_subclass_fixer class MyList(list): def __init__(self): builtin_subclass_fixer.fix(self) ... ... to automatically ensure that new objects returned by MyList methods are of the same class without my having to identify and override every such method. IMO one of the benefits of subclassing is that you can just "bolt on" additional behaviour without having to know all the inner workings of the superclass, a benefit that is somewhat defeated by this behaviour of builtins. OTOH - not that I advocate nuisance as a deterrent - the nuisance factor of this has encouraged me to look harder for simpler solutions. Most of the time I've realised I didn't really need to subclass at all, and thus avoided "lazy subclassing". John From nobody at nowhere.com Sat Dec 25 21:59:10 2010 From: nobody at nowhere.com (Nobody) Date: Sun, 26 Dec 2010 02:59:10 +0000 Subject: Trying to parse a HUGE(1gb) xml file References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> Message-ID: On Sun, 26 Dec 2010 01:05:53 +0000, Tim Harig wrote: >> XML is typically processed sequentially, so you don't need to create a >> decompressed copy of the file before you start processing it. > > Sometimes XML is processed sequentially. When the markup footprint is > large enough it must be. Quite often, as in the case of the OP, you only > want to extract a small piece out of the total data. In those cases, > being forced to read all of the data sequentially is both inconvenient and > and a performance penalty unless there is some way to address the data you > want directly. Actually, I should have said "must be processed sequentially". Even if you only care about a small portion of the data, you have to read it sequentially to locate that portion. IOW, anything you can do with uncompressed XML can be done with compressed XML; you can't do random access with either. If XML has a drawback over application-specific formats, it's the sequential nature of XML rather than its (uncompressed) size. OTOH, formats designed for random access tend to be more limited in their utility. You can only perform random access based upon criteria which match the format's indexing. Once you step outside that, you often have to walk the entire file anyhow. From jude.bloom at gmail.com Sat Dec 25 22:10:23 2010 From: jude.bloom at gmail.com (Jude Bloom) Date: Sat, 25 Dec 2010 21:10:23 -0600 Subject: *** The Jew World Order - A TUTORIAL Exposition in Banking and Economics *** In-Reply-To: <76ef6b76-a823-40aa-97ea-c33ea3c822e1@g26g2000vbi.googlegroups.com> References: <76ef6b76-a823-40aa-97ea-c33ea3c822e1@g26g2000vbi.googlegroups.com> Message-ID: Why don't you take your paranoia and envy of Jews and shove it straight up your inadequate ass? On Fri, Dec 24, 2010 at 12:06 PM, small Pox wrote: -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Sat Dec 25 22:42:01 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 25 Dec 2010 22:42:01 -0500 Subject: What is the the best style and theory of writing a complier in your language In-Reply-To: <4d1449e8$0$32168$7b1e8fa0__23667.4658059657$1293175629$gmane$org@news.nbl.fi> References: <4d1449e8$0$32168$7b1e8fa0__23667.4658059657$1293175629$gmane$org@news.nbl.fi> Message-ID: On 12/24/2010 2:21 AM, Juha Nieminen wrote: > In comp.lang.c++ small Pox wrote: >> http://... > > You should take your religion somewhere else. And you should learn that by re-posting their links you assist spammers. -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From flebber.crue at gmail.com Sat Dec 25 23:43:22 2010 From: flebber.crue at gmail.com (flebber) Date: Sat, 25 Dec 2010 20:43:22 -0800 (PST) Subject: Design Ideals Goals Python 3 - Forest for the trees Message-ID: <2a7b2f17-1644-499f-848b-10291a12cc80@r19g2000prm.googlegroups.com> Hi I was hoping someone could shed some (articles, links) in regards python 3 design ideals. I was searching guido's blog which has his overarching view of Python from an early development perspective http://python-history.blogspot.com/2009/01/pythons-design-philosophy.html . I was interested in what the design goals/philosphy was of Python 3 from a birds eye view, forest for the trees approach. i can safely assume one goal was speed improvement as in the blog he noted "Don?t fret too much about performance--plan to optimize later when needed." So I assume that means that Python had developed to a point where that was needed. But performance wouldn't be the over-arching criteria for the change. Just curious. From usernet at ilthio.net Sun Dec 26 00:35:53 2010 From: usernet at ilthio.net (Tim Harig) Date: Sun, 26 Dec 2010 05:35:53 +0000 (UTC) Subject: Design Ideals Goals Python 3 - Forest for the trees References: <2a7b2f17-1644-499f-848b-10291a12cc80@r19g2000prm.googlegroups.com> Message-ID: On 2010-12-26, flebber wrote: > I was hoping someone could shed some (articles, links) in regards > python 3 design ideals. I was searching guido's blog which has his > overarching view of Python from an early development perspective > http://python-history.blogspot.com/2009/01/pythons-design-philosophy.html > . > > I was interested in what the design goals/philosphy was of Python 3 > from a birds eye view, forest for the trees approach. This is rather old; but you might watch: http://www.youtube.com/watch?v=1RjtT17WbcQ if you haven't seen it already. From alice at gothcandy.com Sun Dec 26 00:56:15 2010 From: alice at gothcandy.com (=?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=) Date: Sat, 25 Dec 2010 21:56:15 -0800 Subject: Design Ideals Goals Python 3 - Forest for the trees References: <2a7b2f17-1644-499f-848b-10291a12cc80@r19g2000prm.googlegroups.com> Message-ID: > I was interested in what the design goals/philosphy was of Python 3 > from a birds eye view, forest for the trees approach. I think I can safely point to the Zen of Python[1] as many of the points therein directly apply to the simplifiation, clarification, and goals of Python 3. Most notably: :: Beautiful is better than ugly. E.g. dict.iteritems, dict.iterkeys, dict.itervalues? Strip 'iter' and it's fixed. :: Special cases aren't special enough to break the rules. Ever get hung up on core Python modules with title caps? Yeah, those are fixed. :: There should be one-- and preferably only one --obvious way to do it. E.g. urllib, urllib2, urllibX? yeah, that's been fixed, too. :) :: Namespaces are one honking great idea -- let's do more of those! Numerous modules have been merged, or moved into more manageable (and logical) namespaces. > I can safely assume one goal was speed improvement as in the blog he > noted "Don?t fret too much about performance--plan to optimize later > when needed." So I assume that means that Python had developed to a > point where that was needed. The Python GIL (Global Interpreter Lock) has been getting a lot of negative attention over the last little while, and was recently fixed to be far more intelligent (and efficient) in Python 3.2. There are numerous other performance improvements, for which yo ucan examine the change logs. > But performance wouldn't be the over-arching criteria for the change. > Just curious. Clarification, simplification, specivity, efficiency, ? just be more "Pythonic". Note that I'm not a core Python contributor or have ever communicated with the BDFL: this is just the viewpoint of somoene doing her darnd'est to encourage Python 3 support. ;) All of the new projects I work on are Python 2.6+ and Python 3.1+ compatible. (Arguments against dual-compatible polygot code can go to /dev/null for the purposes of this thread.) - Alice [1] http://www.python.org/dev/peps/pep-0020/ From flebber.crue at gmail.com Sun Dec 26 01:22:27 2010 From: flebber.crue at gmail.com (flebber) Date: Sat, 25 Dec 2010 22:22:27 -0800 (PST) Subject: Design Ideals Goals Python 3 - Forest for the trees References: <2a7b2f17-1644-499f-848b-10291a12cc80@r19g2000prm.googlegroups.com> Message-ID: On Dec 26, 4:56?pm, Alice Bevan?McGregor wrote: > > I was interested in what the design goals/philosphy was of Python 3 > > from a birds eye view, forest for the trees approach. > > I think I can safely point to the Zen of Python[1] as many of the > points therein directly apply to the simplifiation, clarification, and > goals of Python 3. ?Most notably: > > :: Beautiful is better than ugly. > > E.g. dict.iteritems, dict.iterkeys, dict.itervalues? ?Strip 'iter' and > it's fixed. > > :: Special cases aren't special enough to break the rules. > > Ever get hung up on core Python modules with title caps? ?Yeah, those > are fixed. > > :: There should be one-- and preferably only one --obvious way to do it. > > E.g. urllib, urllib2, urllibX? yeah, that's been fixed, too. ?:) > > :: Namespaces are one honking great idea -- let's do more of those! > > Numerous modules have been merged, or moved into more manageable (and > logical) namespaces. > > > I can safely assume one goal was speed improvement as in the blog he > > noted "Don?t fret too much about performance--plan to optimize later > > when needed." So I assume that means that Python had developed to a > > point where that was needed. > > The Python GIL (Global Interpreter Lock) has been getting a lot of > negative attention over the last little while, and was recently fixed > to be far more intelligent (and efficient) in Python 3.2. ?There are > numerous other performance improvements, for which yo ucan examine the > change logs. > > > But performance wouldn't be the over-arching criteria for the change. > > Just curious. > > Clarification, simplification, specivity, efficiency, ? just be more > "Pythonic". > > Note that I'm not a core Python contributor or have ever communicated > with the BDFL: this is just the viewpoint of somoene doing her > darnd'est to encourage Python 3 support. ?;) ?All of the new projects I > work on are Python 2.6+ and Python 3.1+ compatible. ?(Arguments against > dual-compatible polygot code can go to /dev/null for the purposes of > this thread.) > > ? ? ? ? - Alice > > [1]http://www.python.org/dev/peps/pep-0020/ So do the new changes(to the GIL) nullify concerns raised by David Beazely here http://dabeaz.com/python/UnderstandingGIL.pdf Some projects have been using and requiring psyco to gain speed improvements in python http://psyco.sourceforge.net/introduction.html however it seems that the developer is not active on this project anymore and is more active on PyPy http://codespeak.net/pypy/dist/pypy/doc/ A program such as AVSP http://avisynth.org/qwerpoi/ which relies on psyco what would be a good proposition to use when taking the project to python 3.0 if psyco will remain unavailable? From pavlovevidence at gmail.com Sun Dec 26 02:59:32 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 25 Dec 2010 23:59:32 -0800 (PST) Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d1427ac$0$30000$c3e8da3$5496439d@news.astraweb.com> <3771d7ec-c030-4d15-a257-4c895ff57ec0@n2g2000pre.googlegroups.com> <4d1466d2$0$30000$c3e8da3$5496439d@news.astraweb.com> <4D151B52.4030502@stoneleaf.us> <4d1674e4$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Dec 25, 2:49?pm, Steven D'Aprano wrote: > But that's a separate issue from what is being discussed here. What we're > discussing here is the idea that a function should be able to delegate > work to private subroutines without the caller being aware of that fact. I can't fathom any possible reason why this could be considered a good thing, especially in Python where the culture is, "We're all adults here". By the same logic, it would be a good idea to prevent the user from accessing private members of a class, internal variables of a module, or importing an internal module directly. There is a convention in Python: internal objects are preceded by underscore. The fact that your internal function is marked this way in the traceback is more than enough information to the user that this is an internal function. Python is not, and never has been, about hiding internal details. It's about openness, and there's no reason a traceback should hide internal details any more than a class should--in fact hiding information in the traceback is far worse, because you're suppressing information that could be crucial for debugging. Carl Banks From pavlovevidence at gmail.com Sun Dec 26 03:01:56 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 26 Dec 2010 00:01:56 -0800 (PST) Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d1427ac$0$30000$c3e8da3$5496439d@news.astraweb.com> <3771d7ec-c030-4d15-a257-4c895ff57ec0@n2g2000pre.googlegroups.com> <4d1466d2$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8b9831a9-18d5-4e65-8f66-2e1a8ba5518a@i32g2000pri.googlegroups.com> On Dec 25, 6:21?am, Robert Kern wrote: > On 12/24/10 4:24 AM, Steven D'Aprano wrote: > > > On Thu, 23 Dec 2010 22:38:05 -0800, Carl Banks wrote: > >> OTOH, going the extra mile to hide useful information from a user is > >> asinine. As a user, I will decide for myself how I want to use > >> implementation-defined information, and I don't want the implementor to > >> decide this for me. It's bad enough if an implementor fails to provide > >> information out of laziness, but when they deliberately do extra work to > >> hide information, that's self-importance and arrogance. > > > But that of course is nonsense, because as the user you don't decide > > anything of the sort. The developer responsible for writing the function > > decides what information he provides you, starting with whether you get > > an exception at all, where it comes from, the type of exception, and the > > error message (if any). > > Carl isn't arguing that the user is or should be responsible for this sort of > thing. He is arguing that developers should be responsible for doing this in > such a way that is beneficial for the developer/user down the road. I'm not even arguing that; I think I would be content if the developer merely doesn't actively work to harm the user. Carl Banks From pavlovevidence at gmail.com Sun Dec 26 03:21:33 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 26 Dec 2010 00:21:33 -0800 (PST) Subject: lxml etree question References: <98fb45fe-e4d0-49f4-a705-7923b2bfcacb@k22g2000yqh.googlegroups.com> Message-ID: On Dec 24, 10:17?am, Adam Tauno Williams wrote: > On Fri, 2010-12-24 at 20:48 +0530, Nitin Pawar wrote: > > On Fri, Dec 24, 2010 at 8:40 PM, Jim wrote: > > ? ? ? ? Hello, ?I wonder if someone knows about lxml.etree and > > ? ? ? ? namespaces? > > Yes, and don't. He's using lxml.etree (which is a third-party library that mimics ElementTree's interface), not ElementTree. Were you aware of this? > > I want to build an ElementTree where some of the sub-elements have > > attributes that serialize this way. > > .. > > I've tried just comment_elet.set('xml:lang','de') and it didn't like > > that at all (although it takes comment_elet.set('auth:id','jones') > > just fine). ?I've also spelunked the docs and googled but have not hit > > on the right invocation. ?If someone knows, I'd be grateful. > > I'd *strongly* recommend using ElementFlow for building XML documents > (over ElementTree), especially if namespaces are involved. ?ElementFlow > is far more intuitive. > I'd have to disagree with the use of strong recommendation here. The library you recommended isn't a general replacement for lxml (or ElementTree), and you didn't qualify the conditions for when it is a suitable alternative. A. What if he needed to keep the tree in memory? B. This library builds the tags with "with" statements, which could be convenient for xml files with rigid structure, but I would think it'd be inconvenient if the format were relatively loose. If you're going to recommend a more specialized solution, you should also give the conditions for which it is suitable. Carl Banks From stefan_ml at behnel.de Sun Dec 26 03:32:04 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 26 Dec 2010 09:32:04 +0100 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> Message-ID: Tim Harig, 26.12.2010 02:05: > On 2010-12-25, Nobody wrote: >> On Sat, 25 Dec 2010 14:41:29 -0500, Roy Smith wrote: >>> Of course, one advantage of XML is that with so much redundant text, it >>> compresses well. We typically see gzip compression ratios of 20:1. >>> But, that just means you can archive them efficiently; you can't do >>> anything useful until you unzip them. >> >> XML is typically processed sequentially, so you don't need to create a >> decompressed copy of the file before you start processing it. > > Sometimes XML is processed sequentially. When the markup footprint is > large enough it must be. Quite often, as in the case of the OP, you only > want to extract a small piece out of the total data. In those cases, being > forced to read all of the data sequentially is both inconvenient and and a > performance penalty unless there is some way to address the data you want > directly. So what? If you only have to do that once, it doesn't matter if you have to read the whole file or just a part of it. Should make a difference of a couple of minutes. If you do it a lot, you will have to find a way to make the access efficient for your specific use case. So the file format doesn't matter either, because the data will most likely end up in a fast data base after reading it in sequentially *once*, just as in the case above. I really don't think there are many important use cases where you need fast random access to large data sets and cannot afford to adapt the storage layout before hand. Stefan From usernet at ilthio.net Sun Dec 26 04:01:54 2010 From: usernet at ilthio.net (Tim Harig) Date: Sun, 26 Dec 2010 09:01:54 +0000 (UTC) Subject: Trying to parse a HUGE(1gb) xml file References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> Message-ID: On 2010-12-26, Nobody wrote: > On Sun, 26 Dec 2010 01:05:53 +0000, Tim Harig wrote: > >>> XML is typically processed sequentially, so you don't need to create a >>> decompressed copy of the file before you start processing it. >> >> Sometimes XML is processed sequentially. When the markup footprint is >> large enough it must be. Quite often, as in the case of the OP, you only >> want to extract a small piece out of the total data. In those cases, >> being forced to read all of the data sequentially is both inconvenient and >> and a performance penalty unless there is some way to address the data you >> want directly. > > OTOH, formats designed for random access tend to be more limited in their > utility. You can only perform random access based upon criteria which > match the format's indexing. Once you step outside that, you often have to > walk the entire file anyhow. That may be true and it may not. Even assuming that you have to walk through a large number of top level elements there may be an advantage to being able to directly access the next element as opposed to having to parse through the entire current element once you have determined it isn't one which you are looking for. To be fair, this may be invalid preoptimization without taking into account how the hard drive buffers; but, I would suspect that there is a threshold where the amount of data skipped starts to outweigh the penalty of overreaching the hard drives buffers. From usernet at ilthio.net Sun Dec 26 04:22:10 2010 From: usernet at ilthio.net (Tim Harig) Date: Sun, 26 Dec 2010 09:22:10 +0000 (UTC) Subject: Trying to parse a HUGE(1gb) xml file References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> Message-ID: On 2010-12-26, Stefan Behnel wrote: > Tim Harig, 26.12.2010 02:05: >> On 2010-12-25, Nobody wrote: >>> On Sat, 25 Dec 2010 14:41:29 -0500, Roy Smith wrote: >>>> Of course, one advantage of XML is that with so much redundant text, it >>>> compresses well. We typically see gzip compression ratios of 20:1. >>>> But, that just means you can archive them efficiently; you can't do >>>> anything useful until you unzip them. >>> >>> XML is typically processed sequentially, so you don't need to create a >>> decompressed copy of the file before you start processing it. >> >> Sometimes XML is processed sequentially. When the markup footprint is >> large enough it must be. Quite often, as in the case of the OP, you only >> want to extract a small piece out of the total data. In those cases, being >> forced to read all of the data sequentially is both inconvenient and and a >> performance penalty unless there is some way to address the data you want >> directly. > > So what? If you only have to do that once, it doesn't matter if you have to > read the whole file or just a part of it. Should make a difference of a > couple of minutes. Much agreed. I assume that the process needs to be repeated or it probably would be simpler just to rip out what I wanted using regular expressions with shell utilities. > If you do it a lot, you will have to find a way to make the access > efficient for your specific use case. So the file format doesn't matter > either, because the data will most likely end up in a fast data base after > reading it in sequentially *once*, just as in the case above. If the data is just going to end up in a database anyway; then why not send it as a database to begin with and save the trouble of having to convert it? From alice at gothcandy.com Sun Dec 26 04:34:21 2010 From: alice at gothcandy.com (=?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=) Date: Sun, 26 Dec 2010 01:34:21 -0800 Subject: Design Ideals Goals Python 3 - Forest for the trees References: Message-ID: > So do the new changes(to the GIL) nullify concerns raised by David > Beazely here http://dabeaz.com/python/UnderstandingGIL.pdf Ah, good catch. I had watched the recorded presentation some time ago. Yes, the rewritten GIL should alleviate those problems. Instead of simply releasing and re-acquiring the GIL, it releases, then determines thread scheduling using the brainfuck algorithm instead of leaving it up to the kernel in the brief instant the GIL is unassigned (which often doesn't context switch to another thread, thus the performance penalty). (I beleive that algorithm, whose name -is- accurate, was the winner of the long, long discussion on the Python ticket.) > Some projects have been using and requiring psyco to gain speed > improvements in python http://psyco.sourceforge.net/introduction.html > however it seems that the developer is not active on this project > anymore and is more active on PyPy > http://codespeak.net/pypy/dist/pypy/doc/ I've never really attempted to use JIT optimizers due to the fact that all of my development and production environments are 64-bit, and I haven't found one yet that supports 64-bit properly. Relying on dead projects, however, is an issue of larger scope than mere portability. ;) > A program such as AVSP http://avisynth.org/qwerpoi/ which relies on > psyco what would be a good proposition to use when taking the project > to python 3.0 if psyco will remain unavailable? I'd take the same approach Python 3 itself did; rewrite it for Python 3 and take the opportunity to remove excessive backwards compatibility cruft, streamline algorithms, etc. With a suite of existing unit/functional tests, that possibility is the ultimate in test-driven development. ;) It would also follow the write clean code, then profile and optimize where actually needed philosophy. Obviously that recommendation won't be the "best" solution for every project. With all of the FOSS projects I really, really care about I'm writing from near-scratch (the code, if not the algorithms) with 2.6+ and 3.1+ polygot (no conversion tools like 2to3, and no split packaging) compatibility as a primary design goal. So far it's working out quite well. - Alice From hpj at urpla.net Sun Dec 26 04:41:06 2010 From: hpj at urpla.net (Hans-Peter Jansen) Date: Sun, 26 Dec 2010 10:41:06 +0100 Subject: GUI Tools for Python 3.1 In-Reply-To: References: Message-ID: <201012261041.07130.hpj@urpla.net> On Friday 24 December 2010, 03:58:15 Randy Given wrote: > Lots of stuff for 2.6 and 2.7 -- what GUI tools are there for 3.1? PyQt4 of course. http://www.riverbankcomputing.com Pete From stefan_ml at behnel.de Sun Dec 26 04:44:35 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 26 Dec 2010 10:44:35 +0100 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> Message-ID: Tim Harig, 26.12.2010 10:22: > On 2010-12-26, Stefan Behnel wrote: >> Tim Harig, 26.12.2010 02:05: >>> On 2010-12-25, Nobody wrote: >>>> On Sat, 25 Dec 2010 14:41:29 -0500, Roy Smith wrote: >>>>> Of course, one advantage of XML is that with so much redundant text, it >>>>> compresses well. We typically see gzip compression ratios of 20:1. >>>>> But, that just means you can archive them efficiently; you can't do >>>>> anything useful until you unzip them. >>>> >>>> XML is typically processed sequentially, so you don't need to create a >>>> decompressed copy of the file before you start processing it. >>> >>> Sometimes XML is processed sequentially. When the markup footprint is >>> large enough it must be. Quite often, as in the case of the OP, you only >>> want to extract a small piece out of the total data. In those cases, being >>> forced to read all of the data sequentially is both inconvenient and and a >>> performance penalty unless there is some way to address the data you want >>> directly. >> [...] >> If you do it a lot, you will have to find a way to make the access >> efficient for your specific use case. So the file format doesn't matter >> either, because the data will most likely end up in a fast data base after >> reading it in sequentially *once*, just as in the case above. > > If the data is just going to end up in a database anyway; then why not > send it as a database to begin with and save the trouble of having to > convert it? I don't think anyone would object to using a native format when copying data from one database 1:1 to another one. But if the database formats are different on both sides, it's a lot easier to map XML formatted data to a given schema than to map a SQL dump, for example. Matter of use cases, not of data size. Stefan From __peter__ at web.de Sun Dec 26 05:36:40 2010 From: __peter__ at web.de (Peter Otten) Date: Sun, 26 Dec 2010 11:36:40 +0100 Subject: Keeping track of the N largest values References: Message-ID: Roy Smith wrote: > In article , > Duncan Booth wrote: > >> Roy Smith wrote: >> >> > >> > I'm processing a stream of N numbers and want to keep track of the K >> > largest. There's too many numbers in the stream (i.e. N is too large) >> > to keep in memory at once. K is small (100 would be typical). >> > ... >> > Is there a better way to do this, either from a theoretical running >> > time point of view, or just a nicer way to code this in Python? >> >> How about: >> >> from heapq import nlargest >> top = nlargest(K, input()) >> >> It uses a heap so avoids completely resorting each time. > > Hmmm, that looks like it would solve the problem as stated, but there's > another twist. In addition to finding the K largest values, I *also* > need to do some other processing on all the values (which I didn't show > in the original example, incorrectly thinking it not germane to my > question). The problem with nlargest() is that it doesn't give me a > hook to do that. If Paul's solution doesn't suffice -- the heapq module has the building blocks for a custom solution, e. g.: import heapq from functools import partial class NLargest(object): def __init__(self, n): self.n = n self.heap = [] def tally(self, item): heap = self.heap if len(heap) >= self.n: heapq.heappushpop(heap, item) self.tally = partial(heapq.heappushpop, heap) else: heapq.heappush(heap, item) def __str__(self): return str(sorted(self.heap, reverse=True)) if __name__ == "__main__": import random items = range(100) random.shuffle(items) accu = NLargest(10) for item in items: accu.tally(item) print item, accu > PS: I'm assuming heapq.nlargest(n, iterable) operates with memory > proportional to n, and not to the iterator length. That's the only > reasonable conclusion, but the docs don't actually come out and say it. I would hope so. From n00m at narod.ru Sun Dec 26 08:56:14 2010 From: n00m at narod.ru (n00m) Date: Sun, 26 Dec 2010 05:56:14 -0800 (PST) Subject: Keeping track of the N largest values References: Message-ID: from bisect import insort_left K = 5 top = [] while 1: x = input() if len(top) < K: insort_left(top, x) elif x > top[0]: del top[0] insort_left(top, x) print top will be enough From calderone.jeanpaul at gmail.com Sun Dec 26 09:44:34 2010 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Sun, 26 Dec 2010 06:44:34 -0800 (PST) Subject: Design Ideals Goals Python 3 - Forest for the trees References: Message-ID: On Dec 26, 5:34?am, Alice Bevan?McGregor wrote: > > I've never really attempted to use JIT optimizers due to the fact that > all of my development and production environments are 64-bit, and I > haven't found one yet that supports 64-bit properly. ?Relying on dead > projects, however, is an issue of larger scope than mere portability. ? > ;) > The PyPy JIT supports x86_64. It's still being improved, but it does provide real speedups in some cases already. Jean-Paul From roy at panix.com Sun Dec 26 10:12:33 2010 From: roy at panix.com (Roy Smith) Date: Sun, 26 Dec 2010 10:12:33 -0500 Subject: Keeping track of the N largest values References: Message-ID: In article , n00m wrote: > from bisect import insort_left > > K = 5 > top = [] > while 1: > x = input() > if len(top) < K: > insort_left(top, x) > elif x > top[0]: > del top[0] > insort_left(top, x) > print top > > > will be enough Hmmm, that's an interesting idea. Thanks. From ethan at stoneleaf.us Sun Dec 26 12:04:21 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 26 Dec 2010 09:04:21 -0800 Subject: How to pop the interpreter's stack? In-Reply-To: References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d1427ac$0$30000$c3e8da3$5496439d@news.astraweb.com> <3771d7ec-c030-4d15-a257-4c895ff57ec0@n2g2000pre.googlegroups.com> <4d1466d2$0$30000$c3e8da3$5496439d@news.astraweb.com> <4D151B52.4030502@stoneleaf.us> <4d1674e4$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4D177595.4060208@stoneleaf.us> Carl Banks wrote: > Python is not, and never has been, about hiding internal details. > It's about openness, and there's no reason a traceback should hide > internal details any more than a class should--in fact hiding > information in the traceback is far worse, because you're suppressing > information that could be crucial for debugging. +100 ~Ethan~ From ethan at stoneleaf.us Sun Dec 26 12:08:08 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 26 Dec 2010 09:08:08 -0800 Subject: How to pop the interpreter's stack? In-Reply-To: <4d1674e4$0$29974$c3e8da3$5496439d@news.astraweb.com> References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d1427ac$0$30000$c3e8da3$5496439d@news.astraweb.com> <3771d7ec-c030-4d15-a257-4c895ff57ec0@n2g2000pre.googlegroups.com> <4d1466d2$0$30000$c3e8da3$5496439d@news.astraweb.com> <4D151B52.4030502@stoneleaf.us> <4d1674e4$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4D177678.3050400@stoneleaf.us> Steven D'Aprano wrote: > On Sat, 25 Dec 2010 09:17:27 -0500, Robert Kern wrote: > >> On 12/24/10 5:14 PM, Ethan Furman wrote: >> >>> There are also times when I change the exception being raised to match >>> what python expects from that type of object -- for example, from >>> WhatEverException to KeyError for a dict-like object. So in this regard >>> I agree with Steven. >> Steven isn't arguing that particular point here, nor is anyone arguing >> against it. > > Emphasis on *here*. > > You will note that in Python 3, if you raise an exception inside an > except block, both the *original* and the new exception are printed. This > is great for fixing bugs inside except blocks, but terribly disruptive > for catching one error and raising another error in it's place... Yes, this is where I was agreeing with Steven. While I love python3, the current nested exception behavior is horrible. ~Ethan~ From ethan at stoneleaf.us Sun Dec 26 12:15:32 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 26 Dec 2010 09:15:32 -0800 Subject: How to pop the interpreter's stack? In-Reply-To: <4d0aafdb$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <4d0aafdb$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4D177834.9070901@stoneleaf.us> Steven D'Aprano wrote: > Right. But I have thought of a clever trick to get the result KJ was > asking for, with the minimum of boilerplate code. Instead of this: > > > def _pre_spam(args): > if condition(args): > raise SomeException("message") > if another_condition(args): > raise AnotherException("message") > if third_condition(args): > raise ThirdException("message") > > def spam(args): > _pre_spam(args) > do_useful_work() > > > you can return the exceptions instead of raising them (exceptions are > just objects, like everything else!), and then add one small piece of > boilerplate to the spam() function: > > > def _pre_spam(args): > if condition(args): > return SomeException("message") > if another_condition(args): > return AnotherException("message") > if third_condition(args): > return ThirdException("message") > > def spam(args): > exc = _pre_spam(args) > if exc: raise exc > do_useful_work() -1 You failed to mention that cleverness is not a prime requisite of the python programmer -- in fact, it's usually frowned upon. The big problem with the above code is you are back to passing errors in-band, pretty much completely defeating the point of have an out-of-band channel. ~Ethan~ From no.email at please.post Sun Dec 26 12:53:17 2010 From: no.email at please.post (kj) Date: Sun, 26 Dec 2010 17:53:17 +0000 (UTC) Subject: __delitem__ "feature" Message-ID: When I execute this file: #---------------------------------------------------------------------- def nodelfactory(klass): class nodel(klass): def _delitem(self, _): raise TypeError("can't delete") # __delitem__ = _delitem def __init__(self, *a, **k): klass.__init__(self, *a, **k) self.__delitem__ = self._delitem nodel.__name__ = 'nodel%s' % klass.__name__ return nodel if __name__ == '__main__': import traceback as tb d = nodelfactory(dict)([('k1', 'v1'), ('k2', 'v2')]) try: d.__delitem__('k1') except TypeError: tb.print_exc() print d try: del d['k1'] except TypeError: tb.print_exc() print d l = nodelfactory(list)([1, 2, 3, 4]) try: l.__delitem__(0) except TypeError: tb.print_exc() print l try: del l[0] except TypeError: tb.print_exc() print l #---------------------------------------------------------------------- ...the output I get is: Traceback (most recent call last): File "/tmp/delbug.py", line 20, in try: d.__delitem__('k1') File "/tmp/delbug.py", line 4, in _delitem raise TypeError("can't delete") TypeError: can't delete {'k2': 'v2', 'k1': 'v1'} {'k2': 'v2'} Traceback (most recent call last): File "/tmp/delbug.py", line 30, in try: l.__delitem__(0) File "/tmp/delbug.py", line 4, in _delitem raise TypeError("can't delete") TypeError: can't delete [1, 2, 3, 4] [2, 3, 4] It means that, for both subclasses, del fails to trigger the dynamically installed instance method __delitem__. If I replace dict with UserDict, *both* deletion attempts lead to a call to the dynamic __delitem__ method, and are thus blocked. This is the behavior I expected of dict (and will help me hold on to my belief that I'm not going insane when inevitably I'm told that there's no bug in dict or list). Interestingly enough, if I replace list with UserList, I see no change in behavior. So maybe I am going insane after all. ~kj P.S. If you uncomment the commented-out line, and comment out the last line of the __init__ method (which installs self._delitem as self.__delitem__) then *all* the deletion attempts invoke the __delitem__ method, and are therefore blocked. FWIW. From ian.g.kelly at gmail.com Sun Dec 26 13:10:27 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 26 Dec 2010 11:10:27 -0700 Subject: __delitem__ "feature" In-Reply-To: References: Message-ID: On 12/26/2010 10:53 AM, kj wrote: > P.S. If you uncomment the commented-out line, and comment out the > last line of the __init__ method (which installs self._delitem as > self.__delitem__) then *all* the deletion attempts invoke the > __delitem__ method, and are therefore blocked. FWIW. Because subclasses of builtins only check the class __dict__ for special method overrides, not the instance __dict__. From franapoli at gmail.com Sun Dec 26 13:24:19 2010 From: franapoli at gmail.com (Ciccio) Date: Sun, 26 Dec 2010 10:24:19 -0800 (PST) Subject: inspect.getsource bug? Message-ID: Try this: 1) define a function 'foo' in a script 2) runfile the script from a shell 3) do 'inspect.getsource(foo)' 4) change the source of 'foo' 5) runfile the script from the same shell 6) do 3 again On my 2.6.6 getsource returns twice the same code. I couldn't find very much about this, is there any known workaround? thanks From lists at cheimes.de Sun Dec 26 13:30:23 2010 From: lists at cheimes.de (Christian Heimes) Date: Sun, 26 Dec 2010 19:30:23 +0100 Subject: __delitem__ "feature" In-Reply-To: References: Message-ID: Am 26.12.2010 18:53, schrieb kj: > It means that, for both subclasses, del fails to trigger the > dynamically installed instance method __delitem__. Magic methods like __delitem__ are looked up on the type, not on the instance. You can't change the behaviour on instances. > If I replace dict with UserDict, *both* deletion attempts lead to > a call to the dynamic __delitem__ method, and are thus blocked. > This is the behavior I expected of dict (and will help me hold on > to my belief that I'm not going insane when inevitably I'm told > that there's no bug in dict or list). UserDict is an old style class (not a subclass of object). Old style classes behave differently. Christian From no.email at please.post Sun Dec 26 13:37:44 2010 From: no.email at please.post (kj) Date: Sun, 26 Dec 2010 18:37:44 +0000 (UTC) Subject: type(d) != type(d.copy()) when type(d).issubclass(dict) References: <4d16732c$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: "John O'Hagan" writes: >IMO one of the benefits of subclassing is that you can just "bolt on" >additional behaviour without having to know all the inner workings of the >superclass, a benefit that is somewhat defeated by this behaviour of builtins. I agree. I've read the old post/articles by GvR and other over how great it will be now that one can subclass Python builtin types like any other class (GvR even gives explicit examples of this luscious possibility in his paper on type/class unification). But now I'm discovering so many caveats, exceptions, and gotchas about subclassing builtins that I have to conclude that this much celebrated new capability is basically useless... Just like "readability counts", it is also true that "conceptual clarity" counts, and treating builtins as classes in Python is the most obfuscated design I've ever seen. UserDict, come back, all is forgotten! ~kj From no.email at please.post Sun Dec 26 13:48:12 2010 From: no.email at please.post (kj) Date: Sun, 26 Dec 2010 18:48:12 +0000 (UTC) Subject: type(d) != type(d.copy()) when type(d).issubclass(dict) References: Message-ID: In Duncan Booth writes: >kj wrote: >> Watch this: >> >>>>> class neodict(dict): pass >> ... >>>>> d = neodict() >>>>> type(d) >> >>>>> type(d.copy()) >> >> >> >> Bug? Feature? Genius beyond the grasp of schlubs like me? >Feature. >In (almost?) all cases any objects constructed by a subclass of a builtin >class will be of the original builtin class. What I *really* would like to know is: how do *you* know this (and the same question goes for the other responders who see this behavior of dict as par for the course). Can you show me where it is in the documentation? I'd really appreciate it. TIA! ~kj From no.email at please.post Sun Dec 26 13:49:55 2010 From: no.email at please.post (kj) Date: Sun, 26 Dec 2010 18:49:55 +0000 (UTC) Subject: __delitem__ "feature" References: Message-ID: In Ian Kelly writes: >On 12/26/2010 10:53 AM, kj wrote: >> P.S. If you uncomment the commented-out line, and comment out the >> last line of the __init__ method (which installs self._delitem as >> self.__delitem__) then *all* the deletion attempts invoke the >> __delitem__ method, and are therefore blocked. FWIW. >Because subclasses of builtins only check the class __dict__ for special >method overrides, not the instance __dict__. How do you know this? Is this documented? Or is this a case of Monday-night quarterbacking? ~kj From stefan.sonnenberg at pythonmeister.com Sun Dec 26 13:51:50 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Sun, 26 Dec 2010 19:51:50 +0100 Subject: Keeping track of the N largest values In-Reply-To: References: Message-ID: <4D178EC6.6010205@pythonmeister.com> Am 25.12.2010 16:42, schrieb Roy Smith: > I'm processing a stream of N numbers and want to keep track of the K > largest. There's too many numbers in the stream (i.e. N is too large) > to keep in memory at once. K is small (100 would be typical). > > > From a theoretical point of view, I should be able to do this in N log K > time. What I'm doing now is essentially: > > top = [-1] # Assume all x are>= 0 > for x in input(): > if x<= top[0]: > continue > top.append(x) > if len(top)> K: > top.sort() > top.pop(0) > > I can see pathological cases (say, all input values the same) where > running time would be N K log K, but on average (N>> K and random > distribution of values), this should be pretty close to N. > > Is there a better way to do this, either from a theoretical running time > point of view, or just a nicer way to code this in Python? Here is my version: l = [] K = 10 while 1: a = input() if len(l) == K: l.remove(min(l)) l=[x for x in l if x < a] + [a] + [x for x in l if x > a] print l From no.email at please.post Sun Dec 26 14:09:34 2010 From: no.email at please.post (kj) Date: Sun, 26 Dec 2010 19:09:34 +0000 (UTC) Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d1427ac$0$30000$c3e8da3$5496439d@news.astraweb.com> <3771d7ec-c030-4d15-a257-4c895ff57ec0@n2g2000pre.googlegroups.com> <4d1466d2$0$30000$c3e8da3$5496439d@news.astraweb.com> In writes: >Except that the *caller* never gets the traceback (unless if it deliberately >inspects the stack for some metaprogramming reason). It gets the exception, and >that is the same no matter what you do. The developer/user gets the traceback, >and those implementation details *are* often important to them. Just look at what Python shows you if you pass the wrong number of arguments to a function: >>> def spam(x, y, z): pass ... >>> spam(1, 2) Traceback (most recent call last): File "", line 1, in TypeError: spam() takes exactly 3 arguments (2 given) That's it. The traceback stops at the point of the error. Python doesn't show you all the underlying C-coded machinery that went into detecting the error and emitting the error message. *No one* needs this information at this point. All I'm saying is that I want to do the same thing with my argument validation code as Python does with its argument validation code: keep it out of sight. When my argument validation code fires an exception ***there's no bug in **my** code***. It's doing exactly what it's supposed to do. Therefore, there's no need for me to debug anything, and certainly no need for me to inspect the traceback all the way to the exception. The bug is in the code that called my function with the wrong arguments. The developer of that code has no more use for seeing the traceback all the way to where my code raises the exception than I have for seeing the traceback of Python's underlying C code when I get an error like the one shown above. ~kj From no.email at please.post Sun Dec 26 14:14:42 2010 From: no.email at please.post (kj) Date: Sun, 26 Dec 2010 19:14:42 +0000 (UTC) Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <4d0aafdb$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: In Ethan Furman writes: >You failed to mention that cleverness is not a prime requisite of the >python programmer -- in fact, it's usually frowned upon. That's the party line, anyway. I no longer believe it. I've been crashing against one bit of cleverness after another in Python's unification of types and classes... From nagle at animats.com Sun Dec 26 14:15:37 2010 From: nagle at animats.com (John Nagle) Date: Sun, 26 Dec 2010 11:15:37 -0800 Subject: How to pop the interpreter's stack? In-Reply-To: <4d167517$0$29974$c3e8da3$5496439d@news.astraweb.com> References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d1427ac$0$30000$c3e8da3$5496439d@news.astraweb.com> <3771d7ec-c030-4d15-a257-4c895ff57ec0@n2g2000pre.googlegroups.com> <4d1466d2$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d14ebaf$0$44021$742ec2ed@news.sonic.net> <4d167517$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4d179459$0$43981$742ec2ed@news.sonic.net> On 12/25/2010 2:50 PM, Steven D'Aprano wrote: > On Fri, 24 Dec 2010 10:51:32 -0800, John Nagle wrote: > >> On 12/24/2010 3:24 AM, Carl Banks wrote: >>> On Dec 24, 1:24 am, Steven D'Aprano>> +comp.lang.pyt... at pearwood.info> wrote: >> All I'm >>>> suggesting is that there should be a way of reducing the boilerplate >>>> needed for this idiom: >>>> >>>> def _validate_arg(x): >>>> if x == 'bad input': return False >>>> return True >>>> >>>> def f(arg): >>>> if not _validate_arg(arg): >>>> raise ValueError >>>> process(arg) >>>> >>>> to something more natural that doesn't needlessly expose >>>> implementation details that are completely irrelevant to the caller. >> >> How about >> >> raise ValueError("Bad input %s to validate_arg" % (repr(arg),)) >> >> You can pass arguments to most exceptions, and the content of the >> exception is determined entirely by the code raising it. > > I know that exceptions can take arguments (usually string error > messages). I was writing in short-hand. My apologies, I thought that > would have been obvious :( > > Perhaps you have missed the context of the discussion. The context is > that the called function delegates the job of validating input to a > private function, which should be hidden from the caller (it's private, > not part of the public API, subject to change, hidden, etc.) but > tracebacks expose that information, obscuring the cause of the fault. > (The fault being bad input to the public function, not an accidental bug > in the private function.) > > >> If end users are seeing uncaught tracebacks, the program is broken. > > Well, perhaps, but that's a separate issue. We're talking about the > caller of the function seeing internal details, not the end use. No, that is the issue, unless the program itself is examining the stack traceback data. Python exception-catching has no notion of what code raised the exception. Only the contents of the exception object are normally available. So the "private function" is always "hidden", unless you're debugging, in which case it shouldn't be hidden. Traceback is purely a debugging feature. In some Python implementations, such as Shed Skin, you don't get tracebacks unless you're running under a debugger. John Nagle From go.gana at hotmail.com Sun Dec 26 14:44:29 2010 From: go.gana at hotmail.com (go.gana at hotmail.com) Date: Sun, 26 Dec 2010 11:44:29 -0800 (PST) Subject: A Brief Illustrated Guide To Understanding Islam Home Message-ID: <659fc323-4e65-4479-8b9e-b320bf24b075@f20g2000vbc.googlegroups.com> A Brief Illustrated Guide To Understanding Islam Home http://www.islam-guide.com/ From secris1 at gmail.com Sun Dec 26 14:53:14 2010 From: secris1 at gmail.com (Sean) Date: Sun, 26 Dec 2010 11:53:14 -0800 (PST) Subject: Python Web App References: <907fa80e-1814-4ddb-be32-ec14cfd53fab@29g2000yqq.googlegroups.com> Message-ID: @Katie Thank you I considered this option until I realized it wouldn't let me do anything other than ping from the command line. The rest of you all make valid points after doing a little more research on my own I found some really nice web based text editors but they didn't have any testing abilities which meant learning in that environment wasn't feasible in my opinion. I am inclined to agree that chrome OS will probably not do as well as they want it to but with the kind of capital Google has they could easily flood the market. In the end I wound up giving the notebook to my mom because all she really does is check her email and Facebook so it was perfect for her. Thank You for all the responses they were a great help with me testing the notebook. On Dec 25, 9:02?pm, Katie T wrote: > On Wed, Dec 22, 2010 at 9:43 PM, Sean wrote: > > Anybody know where I can find a Python Development Environment in the > > form of a web app for use with Chrome OS. I have been looking for a > > few days and all i have been able to find is some old discussions with > > python developers talking about they will want one for the OS to be a > > success with them. > > Your best bet is probably just to SSH to a *nix box and use something > like vim or emacs. None of the web solutions are anywhere near acceptable. > > Katie > -- > CoderStackhttp://www.coderstack.co.uk/python-jobs > The Software Developer Job Board From usernet at ilthio.net Sun Dec 26 15:15:16 2010 From: usernet at ilthio.net (Tim Harig) Date: Sun, 26 Dec 2010 20:15:16 +0000 (UTC) Subject: Trying to parse a HUGE(1gb) xml file References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> Message-ID: On 2010-12-26, Stefan Behnel wrote: > Tim Harig, 26.12.2010 10:22: >> On 2010-12-26, Stefan Behnel wrote: >>> Tim Harig, 26.12.2010 02:05: >>>> On 2010-12-25, Nobody wrote: >>>>> On Sat, 25 Dec 2010 14:41:29 -0500, Roy Smith wrote: >>>>>> Of course, one advantage of XML is that with so much redundant text, it >>>>>> compresses well. We typically see gzip compression ratios of 20:1. >>>>>> But, that just means you can archive them efficiently; you can't do >>>>>> anything useful until you unzip them. >>>>> >>>>> XML is typically processed sequentially, so you don't need to create a >>>>> decompressed copy of the file before you start processing it. >>>> >>>> Sometimes XML is processed sequentially. When the markup footprint is >>>> large enough it must be. Quite often, as in the case of the OP, you only >>>> want to extract a small piece out of the total data. In those cases, being >>>> forced to read all of the data sequentially is both inconvenient and and a >>>> performance penalty unless there is some way to address the data you want >>>> directly. >>> [...] >>> If you do it a lot, you will have to find a way to make the access >>> efficient for your specific use case. So the file format doesn't matter >>> either, because the data will most likely end up in a fast data base after >>> reading it in sequentially *once*, just as in the case above. >> >> If the data is just going to end up in a database anyway; then why not >> send it as a database to begin with and save the trouble of having to >> convert it? > > I don't think anyone would object to using a native format when copying > data from one database 1:1 to another one. But if the database formats are > different on both sides, it's a lot easier to map XML formatted data to a > given schema than to map a SQL dump, for example. Matter of use cases, not > of data size. Your assumption keeps hinging on the fact that I should want to dump the data into a database in the first place. Very often I don't. I just want to rip out the small portion of information that happens to be important to me. I may not even want to archive my little piece of the information once I have processed it. Even assuming that I want to dump all the data into a database, walking through a bunch of database records to translate them into the schema for another database is no more difficult then walking through a bunch of XML elements. In fact, it is even easier since I can use the relational model to reconstruct the information in an organization that better fits how the data is actually structured in my database instead of being constrained by how somebody else wanted to organize their XML. There is no need to "map a[sic] SQL dump." XML is great when the data is set is small enough that parsing the whole tree has negligable costs. I can choose whether I want to parse it sequentially or use XPath/DOM/Etree etc to make it appear as though I am making random accesses. When the data set grows so that parsing it is expensive I loose that choice even if my use case would otherwise prefer a random access paradigm. When that happens, there are better ways of communicating that data that doesn't force me into using a high overhead method of extracting my data. The problem is that XML has become such a defacto standard that it used automatically, without thought, even when there are much better alternatives available. From lists at cheimes.de Sun Dec 26 15:33:09 2010 From: lists at cheimes.de (Christian Heimes) Date: Sun, 26 Dec 2010 21:33:09 +0100 Subject: __delitem__ "feature" In-Reply-To: References: Message-ID: Am 26.12.2010 19:49, schrieb kj: > How do you know this? Is this documented? Or is this a case of > Monday-night quarterbacking? Please stop bitching around. You know that by carefully reading the documentation: http://docs.python.org/reference/datamodel.html#special-method-lookup-for-new-style-classes From stefan_ml at behnel.de Sun Dec 26 15:40:04 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 26 Dec 2010 21:40:04 +0100 Subject: lxml etree question In-Reply-To: References: <98fb45fe-e4d0-49f4-a705-7923b2bfcacb@k22g2000yqh.googlegroups.com> Message-ID: Jim, 26.12.2010 00:32: > On Dec 25, 5:33 am, Stefan Behnel wrote: >> lxml knows about this special case, so you can write >> >> {http://www.w3.org/XML/1998/namespace}lang >> >> and lxml will take care of using the right prefix. > > Stefan, thank you for the software, which has helped me a great deal. > > I tried that exact thing, among a number of others, and it didn't work > for me (I got ns0). Works for me, at least with a recent SVN version: Python 2.7.1rc1+ (trunk:86636, Nov 21 2010, 09:18:37) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import lxml.etree as ET >>> el = ET.Element('test', ... {'{http://www.w3.org/XML/1998/namespace}lang': 'de'}) >>> ET.tostring(el) '' Anyway, I applied a patch that makes sure it will always use the 'xml' prefix for this namespace. Will be in 2.3 final. Stefan From g.statkute at gmail.com Sun Dec 26 17:43:03 2010 From: g.statkute at gmail.com (gintare) Date: Sun, 26 Dec 2010 14:43:03 -0800 (PST) Subject: =?ISO-8859-1?B?c3RyaW5nIHUnaHl2XHhlNCcgdG8gZmlsZSBhcyAgJ2h5duQn?= Message-ID: Could you please help me with special characters saving to file. I need to write the string u'hyv\xe4' to file. I would like to open file and to have line 'hyv?' import codecs word= u'hyv\xe4' F=codecs.open(/opt/finnish.txt, 'w+','Latin-1') F.writelines(item.encode('Latin-1')) F.writelines(item.encode('utf8')) F.writelines(item) F.close() All three writelines gives the same result in finnish.txt: hyv\xe4 i would like to find 'hyv?'. regards, gintare From franapoli at gmail.com Sun Dec 26 17:43:39 2010 From: franapoli at gmail.com (Ciccio) Date: Sun, 26 Dec 2010 14:43:39 -0800 (PST) Subject: inspect.getsource bug? References: Message-ID: <274e75b8-a867-4406-977e-0f1d46ab8f7a@j3g2000vbi.googlegroups.com> On 26 Dic, 19:24, Ciccio wrote: > Try this: > 1) define a function 'foo' in a script > 2) runfile the script from a shell > 3) do 'inspect.getsource(foo)' > 4) change the source of 'foo' > 5) runfile the script from the same shell > 6) do 3 again > > On my 2.6.6 getsource returns twice the same code. I couldn't find > very much about this, is there any known workaround? > > thanks found this in the meantime: http://bugs.python.org/issue993580 From juanlu001 at gmail.com Sun Dec 26 18:03:29 2010 From: juanlu001 at gmail.com (Juanlu_001) Date: Sun, 26 Dec 2010 15:03:29 -0800 (PST) Subject: Need urllib.urlretrieve and urllib2.OpenerDirector together Message-ID: <2f246698-2067-417c-ade7-a9b5fb42bb59@k13g2000vbq.googlegroups.com> Hello everyone. I'm writing a script in Python 2.7 which uses a urllib2.OpenerDirector instance via urllib2.build_opener() to take advantage of the urllib2.HTTPCookieProcessor class, because I need to store and re-send the cookies I get: opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookielib.CookieJar())) However, after making several requests and moving the cookies around, eventually I need to retrieve a list of URLs. I wanted to use urllib.urlretrieve() because I read it downloads the file in chunks, but I cannot because I need to carry my cookies on the request and urllib.urlretrieve() uses a urllib.URLOpener, which doesn't have support for cookie handlers like OpenerDirector has. I want to know the reason of this strange way of splitting functionality, and how can I achieve my goal. Thank you in advance! From python at mrabarnett.plus.com Sun Dec 26 18:14:06 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 26 Dec 2010 23:14:06 +0000 Subject: string u'hyv\xe4' to file as =?ISO-8859-1?Q?=27hyv=E4=27?= In-Reply-To: References: Message-ID: <4D17CC3E.80406@mrabarnett.plus.com> On 26/12/2010 22:43, gintare wrote: > Could you please help me with special characters saving to file. > > I need to write the string u'hyv\xe4' to file. > I would like to open file and to have line 'hyv?' > > import codecs > word= u'hyv\xe4' > F=codecs.open(/opt/finnish.txt, 'w+','Latin-1') This opens the file using the Latin-1 encoding (although only if you put the filename in quotes). > > F.writelines(item.encode('Latin-1')) This encodes the Unicode item (did you mean 'word'?) to a bytestring using the Latin-1 encoding. You opened the file using Latin-1 encoding, so this is pointless. You should pass a Unicode string; it will encode it for you. You're also passing a bytestring to the .writelines method, which expects a list of strings. What you should be doing is this: F.write(word) > F.writelines(item.encode('utf8')) This encodes the Unicode item to a bytestring using the UTF-8 encoding. This is also pointless. You shouldn't be encoding to UTF-8 and then trying to write it to a file which was opened using Latin-1 encoding! > F.writelines(item) > > F.close() > > All three writelines gives the same result in finnish.txt: hyv\xe4 > i would like to find 'hyv?'. > From pythonva at gmail.com Sun Dec 26 18:33:05 2010 From: pythonva at gmail.com (Python Programming) Date: Sun, 26 Dec 2010 15:33:05 -0800 (PST) Subject: IDLE GUI not working Message-ID: Hello all, Newbie here so go easy on me. I've been trying to get the IDLE GUI to work on my machine, but have been unsuccessful so far. I have an IBM Thinkpad running Windows XP and it has an older version of Python running (2.2, I believe). When I try to use the shortcut to open the IDLE GUI nothing happens (not even a process running in task manager). When I use the cmd line to try to open the IDLE GUI, I get this error message: ---------------------------- C:\>C:\python27\python C:\python27\Lib\idlelib\idle.py Traceback (most recent call last): File "C:\python27\Lib\idlelib\idle.py", line 11, in idlelib.PyShell.main() File "C:\python27\Lib\idlelib\PyShell.py", line 1389, in main root = Tk(className="Idle") File "C:\python27\lib\lib-tk\Tkinter.py", line 1685, in __init__ self.tk = _tkinter.create(screenName, baseName, className, interactive, want objects, useTk, sync, use) _tkinter.TclError: Can't find a usable init.tcl in the following directories: {C:\IBMTOOLS\Python22\tcl\tcl8.4} C:/IBMTOOLS/Python22/tcl/tcl8.5 C:/python2 7/lib/tcl8.5 C:/lib/tcl8.5 C:/lib/tcl8.5 C:/library C:/library C:/ tcl8.5.2/libra ry C:/tcl8.5.2/library C:/IBMTOOLS/Python22/tcl/tcl8.4/init.tcl: version conflict for package "Tcl": ha ve 8.5.2, need exactly 8.4 version conflict for package "Tcl": have 8.5.2, need exactly 8.4 while executing "package require -exact Tcl 8.4" (file "C:/IBMTOOLS/Python22/tcl/tcl8.4/init.tcl" line 19) invoked from within "source C:/IBMTOOLS/Python22/tcl/tcl8.4/init.tcl" ("uplevel" body line 1) invoked from within "uplevel #0 [list source $tclfile]" This probably means that Tcl wasn't installed properly. ------------------------------------ As I understand this, python 2.7 is looking in a directory or path specified by the older, python 2.2 for Tcl. I have tried to unset this path by entering this into the cmd line: ------------------------------- C:\>set TCL_LIBRARY= C:\>set TK_LIBRARY= C:\>C:\Python27\python.exe C:\Python27\Lib\idlelib\idle.py ------------------------------- No dice. I tried to enter this information as a new pythonpath in the environment variables. No dice. I've tried, in vain, to get this thing working, but most of the other explanations are way over my head (I'm pretty new to programming and digging around the programming guts of computers) It seems like a fairly common problem, but haven't gotten a good answer from either the official python help boards or elsewhere. I was hoping that someone here could give me a easy to understand way to make the IDLE GUI work. Thanks in advance. From steve at holdenweb.com Sun Dec 26 20:08:49 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 26 Dec 2010 20:08:49 -0500 Subject: How to pop the interpreter's stack? In-Reply-To: References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <4d0aafdb$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4D17E721.1060902@holdenweb.com> On 12/26/2010 2:14 PM, kj wrote: > In Ethan Furman writes: > >> You failed to mention that cleverness is not a prime requisite of the >> python programmer -- in fact, it's usually frowned upon. > > That's the party line, anyway. I no longer believe it. I've been > crashing against one bit of cleverness after another in Python's > unification of types and classes... Well if you can find a way to implement a class system that doesn't use clever tricks *in its implementation* please let me know. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From steve at holdenweb.com Sun Dec 26 20:08:49 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 26 Dec 2010 20:08:49 -0500 Subject: How to pop the interpreter's stack? In-Reply-To: References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <4d0aafdb$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4D17E721.1060902@holdenweb.com> On 12/26/2010 2:14 PM, kj wrote: > In Ethan Furman writes: > >> You failed to mention that cleverness is not a prime requisite of the >> python programmer -- in fact, it's usually frowned upon. > > That's the party line, anyway. I no longer believe it. I've been > crashing against one bit of cleverness after another in Python's > unification of types and classes... Well if you can find a way to implement a class system that doesn't use clever tricks *in its implementation* please let me know. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ From misnomer at gmail.com Sun Dec 26 20:12:50 2010 From: misnomer at gmail.com (misnomer at gmail.com) Date: Sun, 26 Dec 2010 17:12:50 -0800 (PST) Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8ed98c33-9ed9-42ab-a74d-d04d6922f8cd@c2g2000yqc.googlegroups.com> On Dec 23, 3:22?am, Steven D'Aprano wrote: > You seem to have completely missed that there will be no bug report, > because this isn't a bug. (Or if it is a bug, the bug is elsewhere, > external to the function that raises the exception.) It is part of the > promised API. The fact that the exception is generated deep down some > chain of function calls is irrelevant. While the idea of being able to do this (create a general validation exception) sounds mildly appealing at first, what happens when the module implementing this documented API and documented error, has a bug? It seems that the user, or even module developer in the midst of writing, would now have no tools to easily tackle the problem, and no useful information to submit in the required bug report. From pavlovevidence at gmail.com Sun Dec 26 21:55:39 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 26 Dec 2010 18:55:39 -0800 (PST) Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d1427ac$0$30000$c3e8da3$5496439d@news.astraweb.com> <3771d7ec-c030-4d15-a257-4c895ff57ec0@n2g2000pre.googlegroups.com> <4d1466d2$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: <282e4be8-ac91-4270-8c20-afbde5880d07@r40g2000prh.googlegroups.com> On Dec 26, 11:09?am, kj wrote: > In writes: > > >Except that the *caller* never gets the traceback (unless if it deliberately > >inspects the stack for some metaprogramming reason). It gets the exception, and > >that is the same no matter what you do. The developer/user gets the traceback, > >and those implementation details *are* often important to them. > > Just look at what Python shows you if you pass the wrong number of > arguments to a function: > > >>> def spam(x, y, z): pass > ... > >>> spam(1, 2) > > Traceback (most recent call last): > ? File "", line 1, in > TypeError: spam() takes exactly 3 arguments (2 given) > > That's it. ?The traceback stops at the point of the error. ?Python > doesn't show you all the underlying C-coded machinery that went > into detecting the error and emitting the error message. ?*No one* > needs this information at this point. ?All I'm saying is that I > want to do the same thing with my argument validation code as Python > does with its argument validation code: keep it out of sight. ?When > my argument validation code fires an exception ***there's no bug > in **my** code***. ?It's doing exactly what it's supposed to do. > Therefore, there's no need for me to debug anything, and certainly > no need for me to inspect the traceback all the way to the exception. > The bug is in the code that called my function with the wrong > arguments. ?The developer of that code has no more use for seeing > the traceback all the way to where my code raises the exception > than I have for seeing the traceback of Python's underlying C code > when I get an error like the one shown above. Python makes no attempt to hide its machinery in tracebacks (that I'm aware of); in fact stack points from internal Python functions, classes, and modules appear in tracebacks all the time. The reason you don't see traceback lines for Python's argument validation is it's written in C. If it bothers you that much, you're welcome to write you own argument validation in C, too. Carl Banks From pavlovevidence at gmail.com Sun Dec 26 22:00:42 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sun, 26 Dec 2010 19:00:42 -0800 (PST) Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <4d1427ac$0$30000$c3e8da3$5496439d@news.astraweb.com> <3771d7ec-c030-4d15-a257-4c895ff57ec0@n2g2000pre.googlegroups.com> <4d1466d2$0$30000$c3e8da3$5496439d@news.astraweb.com> <4D151B52.4030502@stoneleaf.us> <4d1674e4$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Dec 25, 2:49?pm, Steven D'Aprano wrote: > On Sat, 25 Dec 2010 09:17:27 -0500, Robert Kern wrote: > > On 12/24/10 5:14 PM, Ethan Furman wrote: > > >> There are also times when I change the exception being raised to match > >> what python expects from that type of object -- for example, from > >> WhatEverException to KeyError for a dict-like object. So in this regard > >> I agree with Steven. > > > Steven isn't arguing that particular point here, nor is anyone arguing > > against it. > > Emphasis on *here*. > > You will note that in Python 3, if you raise an exception inside an > except block, both the *original* and the new exception are printed. This > is great for fixing bugs inside except blocks, but terribly disruptive > for catching one error and raising another error in it's place, e.g.: > > try: > ? ? x+0 > except ValueError, TypeError as e: > ? ? # x is not a numeric value, e.g. a string or a NAN. > ? ? raise MyError('x is not a number') > > The explicit raise is assumed to indicate a bug in the except block, and > the original exception is printed as well. > > But that's a separate issue from what is being discussed here. What we're > discussing here is the idea that a function should be able to delegate > work to private subroutines without the caller being aware of that fact. > When you return a value, the caller doesn't see the internal details of > how you calculated the value, but if you deliberately raise an exception, > the caller does. Often this is the right thing to do, but sometimes it > isn't. E.g. you can't delegate input validation to a subroutine and raise > inside the subroutine without obfuscating the traceback. >>> import re >>> re.compile(r"(") Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/re.py", line 190, in compile return _compile(pattern, flags) File "/usr/lib/python2.6/re.py", line 245, in _compile raise error, v # invalid expression sre_constants.error: unbalanced parenthesis OHMYGOD HOW DARE the standard library allow the traceback list an internal function that does input valididation! Carl Banks From gveggie at gmail.com Sun Dec 26 22:56:00 2010 From: gveggie at gmail.com (Grant Andrew) Date: Sun, 26 Dec 2010 20:56:00 -0700 Subject: IDLE GUI not working In-Reply-To: References: Message-ID: On Sun, Dec 26, 2010 at 4:33 PM, Python Programming wrote: > Hello all, > > Newbie here so go easy on me. I've been trying to get the IDLE GUI to > work on my machine, but have been unsuccessful so far. I have an IBM > Thinkpad running Windows XP and it has an older version of Python > running (2.2, I believe). When I try to use the shortcut to open the > IDLE GUI nothing happens (not even a process running in task > manager). When I use the cmd line to try to open the IDLE GUI, I get > this error message: > > ---------------------------- > C:\>C:\python27\python C:\python27\Lib\idlelib\idle.py > Traceback (most recent call last): > File "C:\python27\Lib\idlelib\idle.py", line 11, in > idlelib.PyShell.main() > File "C:\python27\Lib\idlelib\PyShell.py", line 1389, in main > root = Tk(className="Idle") > File "C:\python27\lib\lib-tk\Tkinter.py", line 1685, in __init__ > self.tk = _tkinter.create(screenName, baseName, className, > interactive, want > objects, useTk, sync, use) > _tkinter.TclError: Can't find a usable init.tcl in the following > directories: > {C:\IBMTOOLS\Python22\tcl\tcl8.4} C:/IBMTOOLS/Python22/tcl/tcl8.5 > C:/python2 > 7/lib/tcl8.5 C:/lib/tcl8.5 C:/lib/tcl8.5 C:/library C:/library C:/ > tcl8.5.2/libra > ry C:/tcl8.5.2/library > > C:/IBMTOOLS/Python22/tcl/tcl8.4/init.tcl: version conflict for package > "Tcl": ha > ve 8.5.2, need exactly 8.4 > version conflict for package "Tcl": have 8.5.2, need exactly 8.4 > while executing > "package require -exact Tcl 8.4" > (file "C:/IBMTOOLS/Python22/tcl/tcl8.4/init.tcl" line 19) > invoked from within > "source C:/IBMTOOLS/Python22/tcl/tcl8.4/init.tcl" > ("uplevel" body line 1) > invoked from within > "uplevel #0 [list source $tclfile]" > > > This probably means that Tcl wasn't installed properly. > ------------------------------------ > > As I understand this, python 2.7 is looking in a directory or path > specified by the older, python 2.2 for Tcl. I have tried to unset > this path by entering this into the cmd line: > > ------------------------------- > C:\>set TCL_LIBRARY= > C:\>set TK_LIBRARY= > C:\>C:\Python27\python.exe C:\Python27\Lib\idlelib\idle.py > ------------------------------- > > No dice. > > I tried to enter this information as a new pythonpath in the > environment variables. No dice. > > I've tried, in vain, to get this thing working, but most of the other > explanations are way over my head (I'm pretty new to programming and > digging around the programming guts of computers) > > It seems like a fairly common problem, but haven't gotten a good > answer from either the official python help boards or elsewhere. I > was hoping that someone here could give me a easy to understand way to > make the IDLE GUI work. > > Thanks in advance. > -- > http://mail.python.org/mailman/listinfo/python-list Wow, I wrote a note to this list so closely resembling yours I had to read carefully to ensure it wasn't my own. You have a PATH problem - these machines ship with Tcl installed and that's creating this issue. There is the standard Path variable, but if you'll notice, there is also a scrollbar to the right. Scroll down and find additional variables that need fixed - PythonPath, TCL_Library, and TK Library all need to be redirected to your current install. If you fix all of these, your problem should be solved and you'll be on your way, at least that was my exact issue on a Thinkpad running XP. Best of luck! Grant -------------- next part -------------- An HTML attachment was scrubbed... URL: From flebber.crue at gmail.com Sun Dec 26 23:37:57 2010 From: flebber.crue at gmail.com (flebber) Date: Sun, 26 Dec 2010 20:37:57 -0800 (PST) Subject: User input masks - Access Style Message-ID: <385bcaf1-81a5-405a-b7f0-28d7994a2e95@a28g2000prb.googlegroups.com> Is there anyay to use input masks in python? Similar to the function found in access where a users input is limited to a type, length and format. So in my case I want to ensure that numbers are saved in a basic format. 1) Currency so input limited to 000.00 eg 1.00, 2.50, 13.80 etc For sports times that is time duration not a system or date times should I assume that I would need to calculate a user input to a decimal number and then recalculate it to present it to user? So an example, sorry. import time #not sure if this is any use minute = input("How many minutes: ") seconds = input("How many seconds: ") Hundredths = input("how many Hundredths: ") # convert user input MyTime = (minute/60)+(seconds)+(Hundredths/1800) #Display to user assuming i had written a name and user # had retrieved it print("[User], your time was"), (MyTime/60:MyTime(MyTime-((MyTime/ 60)*60).(MyTime-(MyTime>0))) ) From steve+comp.lang.python at pearwood.info Sun Dec 26 23:50:03 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Dec 2010 04:50:03 GMT Subject: __delitem__ "feature" References: Message-ID: <4d181afb$0$30001$c3e8da3$5496439d@news.astraweb.com> On Sun, 26 Dec 2010 18:49:55 +0000, kj wrote: > In Ian Kelly > writes: > >>On 12/26/2010 10:53 AM, kj wrote: >>> P.S. If you uncomment the commented-out line, and comment out the last >>> line of the __init__ method (which installs self._delitem as >>> self.__delitem__) then *all* the deletion attempts invoke the >>> __delitem__ method, and are therefore blocked. FWIW. > >>Because subclasses of builtins only check the class __dict__ for special >>method overrides, not the instance __dict__. > > > How do you know this? Is this documented? Or is this a case of > Monday-night quarterbacking? We know it because it explains the observable facts. It also happens to be documented, but documentation can be wrong or incomplete. The facts are never wrong, since by definition they are the facts. -- Steven From steve+comp.lang.python at pearwood.info Mon Dec 27 00:03:56 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Dec 2010 05:03:56 GMT Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <4d0aafdb$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4d181e3c$0$30001$c3e8da3$5496439d@news.astraweb.com> On Sun, 26 Dec 2010 09:15:32 -0800, Ethan Furman wrote: > Steven D'Aprano wrote: >> Right. But I have thought of a clever trick to get the result KJ was >> asking for, with the minimum of boilerplate code. Instead of this: >> >> >> def _pre_spam(args): >> if condition(args): >> raise SomeException("message") >> if another_condition(args): >> raise AnotherException("message") >> if third_condition(args): >> raise ThirdException("message") >> >> def spam(args): >> _pre_spam(args) >> do_useful_work() >> >> >> you can return the exceptions instead of raising them (exceptions are >> just objects, like everything else!), and then add one small piece of >> boilerplate to the spam() function: >> >> >> def _pre_spam(args): >> if condition(args): >> return SomeException("message") >> if another_condition(args): >> return AnotherException("message") >> if third_condition(args): >> return ThirdException("message") >> >> def spam(args): >> exc = _pre_spam(args) >> if exc: raise exc >> do_useful_work() > > -1 > > You failed to mention that cleverness is not a prime requisite of the > python programmer -- in fact, it's usually frowned upon. The big > problem with the above code is you are back to passing errors in-band, > pretty much completely defeating the point of have an out-of-band > channel. How is that any worse than making _pre_spam() a validation function that returns a bool? def spam(args): flag = _pre_spam(args) if flag: raise SomeException() do_useful_work() Is that also frowned upon for being too clever? -- Steven From steve+comp.lang.python at pearwood.info Mon Dec 27 00:38:26 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Dec 2010 05:38:26 GMT Subject: How to pop the interpreter's stack? References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <8ed98c33-9ed9-42ab-a74d-d04d6922f8cd@c2g2000yqc.googlegroups.com> Message-ID: <4d182652$0$30001$c3e8da3$5496439d@news.astraweb.com> On Sun, 26 Dec 2010 17:12:50 -0800, misnomer at gmail.com wrote: > On Dec 23, 3:22?am, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> You seem to have completely missed that there will be no bug report, >> because this isn't a bug. (Or if it is a bug, the bug is elsewhere, >> external to the function that raises the exception.) It is part of the >> promised API. The fact that the exception is generated deep down some >> chain of function calls is irrelevant. > > While the idea of being able to do this (create a general validation > exception) sounds mildly appealing at first, what happens when the > module implementing this documented API and documented error, has a bug? > It seems that the user, or even module developer in the midst of > writing, would now have no tools to easily tackle the problem, and no > useful information to submit in the required bug report. That's very true, but the same applies to *any* use of encapsulation. Any time you hide information, you hide information (duh!). This doesn't stop us from doing this: def public(x): if condition: return _private(x) elif other_condition: return _more_private(x+1) else: return _yet_another_private(x-1) If you call public(42), and get the wrong answer, it's a bug, but the source of the bug is hidden from the caller. If you have access to the source code, you can work out where the bug lies (which of the three private functions is buggy?) given the argument, but the return result itself does not expose any information about where the bug lies. This is considered an unavoidable but acceptable side-effect of an otherwise desirable state of affairs: information hiding and encapsulation. The caller being unaware of where and how the result is calculated is considered a good thing, and the fact that it occasionally adds to the debugging effort is considered such a trivial cost that it normally isn't remarked upon, except by lunatics and die-hard fans of spaghetti code using GOTO. But I repeat myself. Why should exceptions *necessarily* be different? As I've repeatedly acknowledged, for an unexpected exception (a bug), the developer needs all the help he can get, and the current behaviour is the right way to do it. You won't hear me argue differently. But for a documented, explicit, expected, deliberate exception, Python breaks encapsulation by exposing the internal details of any internal subroutines used to generate that exception. This leads to messy tracebacks that obscure the source of bugs in the caller's code: >>> import re >>> re.compile(r"(") Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/re.py", line 190, in compile return _compile(pattern, flags) File "/usr/lib/python2.6/re.py", line 245, in _compile raise error, v # invalid expression sre_constants.error: unbalanced parenthesis I think critics of my position have forgotten what it's like to learning the language. One of the most valuable skills to learn is to *ignore parts of the traceback* -- a skill that takes practice and familiarity with the library or function in use. To those who are less familiar with the function, it can be very difficult to determine which parts of the traceback are relevant and which aren't. In this case, the caller has nothing to do with _compile, and the traceback looks like it's an internal bug in a subroutine, when in fact it is actually due to bad input. The experienced developer learns (by trial and error, possibly) to ignore nearly half of the error message in this case. In principle, the traceback could be roughly half as big, which means the caller would find it half as difficult to read and understand: >>> re.compile(r"(") Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/re.py", line 190, in compile raise error, v # invalid expression sre_constants.error: unbalanced parenthesis With a one-to-one correspondence between the function called, and the function reporting an error, it is easier to recognise that the error lies in the input rather than some internal error in some subroutine you have nothing to do with. Unfortunately there's no straightforward way to consistently get this in Python without giving up the advantages of delegating work to subroutines. It need not be that way. This could, in principle, be left up to the developer of the public function to specify (somehow!) that some specific exceptions are expected, and should be treated as coming from public() rather than from some internal subroutine. I don't have a concrete proposal for such, although I did suggest a work-around. I expected disinterest ("I don't see the point"). I didn't expect the level of hostility to the idea that exceptions should (if and when possible) point to the source of the error rather than some accidental implementation- specific subroutine. Go figure. -- Steven From g.statkute at gmail.com Mon Dec 27 00:57:30 2010 From: g.statkute at gmail.com (gintare) Date: Sun, 26 Dec 2010 21:57:30 -0800 (PST) Subject: =?ISO-8859-1?B?UmU6IHN0cmluZyB1J2h5dlx4ZTQnIHRvIGZpbGUgYXMgJ2h5duQn?= References: Message-ID: <83dc3076-9ddc-42bd-8c33-6af96b2634ba@l32g2000yqc.googlegroups.com> Hello, STILL do not work. WHAT to be done. import codecs item=u'hyv\xe4' F=codecs.open('/opt/finnish.txt', 'w+', 'utf8') F.writelines(item.encode('utf8')) F.close() In file i find 'hyv\xe4' instead of hyv?. (Sorry for mistyping in previous letter about 'latin-1'. I was making all possible combinations, when normal example syntax did not work, before writting to this forum.) regards, gintare On 27 Gruo, 00:43, gintare wrote: > Could you please help me with special characters saving to file. > > I need to write the string u'hyv\xe4' to file. > I would like to open file and to have line 'hyv?' > > import codecs > word= u'hyv\xe4' > F=codecs.open(/opt/finnish.txt, 'w+','Latin-1') > > F.writelines(item.encode('Latin-1')) > F.writelines(item.encode('utf8')) > F.writelines(item) > > F.close() > > All three writelines gives the same result in finnish.txt: ? hyv\xe4 > i would like to find 'hyv?'. > > regards, > gintare From metolone+gmane at gmail.com Mon Dec 27 01:47:58 2010 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Sun, 26 Dec 2010 22:47:58 -0800 Subject: =?iso-8859-1?Q?Re:_string_u'hyv\xe4'_to_file_as_'hyv=E4'?= References: <83dc3076-9ddc-42bd-8c33-6af96b2634ba@l32g2000yqc.googlegroups.com> Message-ID: "gintare" wrote in message news:83dc3076-9ddc-42bd-8c33-6af96b2634ba at l32g2000yqc.googlegroups.com... > Hello, > STILL do not work. WHAT to be done. > > import codecs > item=u'hyv\xe4' > F=codecs.open('/opt/finnish.txt', 'w+', 'utf8') > F.writelines(item.encode('utf8')) > F.close() > > In file i find 'hyv\xe4' instead of hyv?. When you open a file with codecs.open(), it expects Unicode strings to be written to the file. Don't encode them again. Also, .writelines() expects a list of strings. Use .write(): import codecs item=u'hyv\xe4' F=codecs.open('/opt/finnish.txt', 'w+', 'utf8') F.write(item) F.close() An additional comment, if you save the script in UTF8, you can inform Python of that fact with a special comment, and actually use the correct characters in your string constants (? instead of \xe4). Make sure to use a text editor that can save in UTF8, or use the correct coding comment for whatever encoding in which you save the file. # coding: utf8 import codecs item=u'hyv?' F=codecs.open('finnish.txt', 'w+', 'utf8') F.write(item) F.close() -Mark From usernet at ilthio.net Mon Dec 27 02:01:26 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 27 Dec 2010 07:01:26 +0000 (UTC) Subject: User input masks - Access Style References: <385bcaf1-81a5-405a-b7f0-28d7994a2e95@a28g2000prb.googlegroups.com> Message-ID: On 2010-12-27, flebber wrote: > Is there anyay to use input masks in python? Similar to the function > found in access where a users input is limited to a type, length and > format. > > So in my case I want to ensure that numbers are saved in a basic > format. > 1) Currency so input limited to 000.00 eg 1.00, 2.50, 13.80 etc Some GUIs provide this functionality or provide callbacks for validation functions that can determine the validity of the input. I don't know of any modules that provide "formatted input" in a terminal. Most terminal input functions just read from stdin (in this case a buffered line) and output that as a string. It is easy enough to validate whether terminal input is in the proper. Your example time code might look like: ... import re ... import sys ... ... # get the input ... print("Please enter time in the format 'MM:SS:HH': ", end="") ... timeInput = input() ... ... # validate the input is in the correct format (usually this would be in ... # loop that continues until the user enters acceptable data) ... if re.match(r'''^[0-9]{2}:[0-9]{2}:[0-9]{2}$''', timeInput) == None: ... print("I'm sorry, your input is improperly formated.") ... sys.exit(1) ... ... # break the input into its componets ... componets = timeInput.split(":") ... minutes = int(componets[0]) ... seconds = int(componets[1]) ... microseconds = int(componets[2]) ... ... # output the time ... print("Your time is: " + "%02d" % minutes + ":" + "%02d" % seconds + ":" + ... "%02d" % microseconds) Currency works the same way using validating it against: r'''[0-9]+\.[0-9]{2}''' > For sports times that is time duration not a system or date times > should I assume that I would need to calculate a user input to a > decimal number and then recalculate it to present it to user? I am not sure what you are trying to do or asking. Python provides time, date, datetime, and timedelta objects that can be used for date/time calculations, locale based formatting, etc. What you use, if any, will depend on what you are actually tring to accomplish. Your example doesn't really show you doing much with the time so it is difficult giving you any concrete recommendations. From ethan at stoneleaf.us Mon Dec 27 02:03:57 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 26 Dec 2010 23:03:57 -0800 Subject: How to pop the interpreter's stack? In-Reply-To: <4d182652$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <1f47c36d-a509-4d05-ba79-62b4a534bfe0@j19g2000prh.googlegroups.com> <4d12c07f$0$30000$c3e8da3$5496439d@news.astraweb.com> <8ed98c33-9ed9-42ab-a74d-d04d6922f8cd@c2g2000yqc.googlegroups.com> <4d182652$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4D183A5D.6030208@stoneleaf.us> Steven D'Aprano wrote: > ... > > I think critics of my position have forgotten what it's like to learning > the language. One of the most valuable skills to learn is to *ignore > parts of the traceback* -- a skill that takes practice and familiarity > with the library or function in use. To those who are less familiar with > the function, it can be very difficult to determine which parts of the > traceback are relevant and which aren't. In this case, the caller has > nothing to do with _compile, and the traceback looks like it's an > internal bug in a subroutine, when in fact it is actually due to bad > input. The experienced developer learns (by trial and error, possibly) to > ignore nearly half of the error message in this case. And it can still be some work to figure out which parts of the traceback are relevant, even after a couple years... > ... > It need not be that way. This could, in principle, be left up to the > developer of the public function to specify (somehow!) that some specific > exceptions are expected, and should be treated as coming from public() > rather than from some internal subroutine. I don't have a concrete > proposal for such, although I did suggest a work-around. I expected > disinterest ("I don't see the point"). I didn't expect the level of > hostility to the idea that exceptions should (if and when possible) point > to the source of the error rather than some accidental implementation- > specific subroutine. Go figure. My objection is not to the idea, but to the ad-hoc methods that would currently be required. Resorting to passing exceptions in-band is a step backwards. If python had a way to specify what level an exception should be reported from, I might be interested. At this point, if sparing the user one level of traceback was that high a priority to me, I would make the validation be either a decorator, or have the validation *be* the main routine, and the *real work* routine be the private one. ~Ethan~ From usernet at ilthio.net Mon Dec 27 02:09:38 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 27 Dec 2010 07:09:38 +0000 (UTC) Subject: User input masks - Access Style References: <385bcaf1-81a5-405a-b7f0-28d7994a2e95@a28g2000prb.googlegroups.com> Message-ID: On 2010-12-27, Tim Harig wrote: > ... if re.match(r'''^[0-9]{2}:[0-9]{2}:[0-9]{2}$''', timeInput) == None: [SNIP] > Currency works the same way using validating it against: > r'''[0-9]+\.[0-9]{2}''' Sorry, you need to check to make sure that there are no trailing characters as in the example above. Checking the beginning is not actually necessary with match(). r'''^[0-9]+\.[0-9]{2}$''' From flebber.crue at gmail.com Mon Dec 27 02:14:16 2010 From: flebber.crue at gmail.com (flebber) Date: Sun, 26 Dec 2010 23:14:16 -0800 (PST) Subject: User input masks - Access Style References: <385bcaf1-81a5-405a-b7f0-28d7994a2e95@a28g2000prb.googlegroups.com> Message-ID: <43752cb5-ef0a-49d9-8e38-80d126b5077b@k14g2000pre.googlegroups.com> On Dec 27, 6:01?pm, Tim Harig wrote: > On 2010-12-27, flebber wrote: > > > Is there anyay to use input masks in python? Similar to the function > > found in access where a users input is limited to a type, length and > > format. > > > So in my case I want to ensure that numbers are saved in a basic > > format. > > 1) Currency so input limited to 000.00 eg 1.00, 2.50, 13.80 etc > > Some GUIs provide this functionality or provide callbacks for validation > functions that can determine the validity of the input. ?I don't know of > any modules that provide "formatted input" in a terminal. ?Most terminal > input functions just read from stdin (in this case a buffered line) > and output that as a string. ?It is easy enough to validate whether > terminal input is in the proper. > > Your example time code might look like: > > ... import re > ... import sys > ... > ... # get the input > ... print("Please enter time in the format 'MM:SS:HH': ", end="") > ... timeInput = input() > ... > ... # validate the input is in the correct format (usually this would be in > ... # loop that continues until the user enters acceptable data) > ... if re.match(r'''^[0-9]{2}:[0-9]{2}:[0-9]{2}$''', timeInput) == None: > ... ? ? print("I'm sorry, your input is improperly formated.") > ... ? ? sys.exit(1) > ... > ... # break the input into its componets > ... componets = timeInput.split(":") > ... minutes = int(componets[0]) > ... seconds = int(componets[1]) > ... microseconds = int(componets[2]) > ... > ... # output the time > ... print("Your time is: " + "%02d" % minutes + ":" + "%02d" % seconds + ":" + > ... ? ? "%02d" % microseconds) > > Currency works the same way using validating it against: > r'''[0-9]+\.[0-9]{2}''' > > > For sports times that is time duration not a system or date times > > should I assume that I would need to calculate a user input to a > > decimal number and then recalculate it to present it to user? > > I am not sure what you are trying to do or asking. ?Python provides time, > date, datetime, and timedelta objects that can be used for date/time > calculations, locale based formatting, etc. ?What you use, if any, will > depend on what you are actually tring to accomplish. ?Your example doesn't > really show you doing much with the time so it is difficult giving you any > concrete recommendations. yes you are right I should have clarified. The time is a duration over distance, so its a speed measure. Ultimately I will need to store the times so I may need to use something likw sqlAlchemy but I am nowehere near the advanced but I know that most Db's mysql, postgre etc don't support time as a duration as such and i will probably need to store it as a decimal and convert it back for the user. From linmq at neusoft.com Mon Dec 27 03:57:56 2010 From: linmq at neusoft.com (linmq) Date: Mon, 27 Dec 2010 16:57:56 +0800 Subject: Fw: Re: User input masks - Access Style References: <385bcaf1-81a5-405a-b7f0-28d7994a2e95@a28g2000prb.googlegroups.com> <43752cb5-ef0a-49d9-8e38-80d126b5077b@k14g2000pre.googlegroups.com> Message-ID: <201012271657483976492@neusoft.com> > On 2010-12-27, flebber wrote: > > > Is there anyay to use input masks in python? Similar to the function > > found in access where a users input is limited to a type, length and > > format. > > > So in my case I want to ensure that numbers are saved in a basic > > format. > > 1) Currency so input limited to 000.00 eg 1.00, 2.50, 13.80 etc > > Some GUIs provide this functionality or provide callbacks for validation > functions that can determine the validity of the input. ? don't know of > any modules that provide "formatted input" in a terminal. ?ost terminal > input functions just read from stdin (in this case a buffered line) > and output that as a string. ?t is easy enough to validate whether > terminal input is in the proper. > > Your example time code might look like: > > ... import re > ... import sys > ... > ... # get the input > ... print("Please enter time in the format 'MM:SS:HH': ", end="") > ... timeInput = input() > ... > ... # validate the input is in the correct format (usually this would be in > ... # loop that continues until the user enters acceptable data) > ... if re.match(r'''^[0-9]{2}:[0-9]{2}:[0-9]{2}$''', timeInput) == None: > ... ??print("I'm sorry, your input is improperly formated.") > ... ??sys.exit(1) > ... > ... # break the input into its componets > ... componets = timeInput.split(":") > ... minutes = int(componets[0]) > ... seconds = int(componets[1]) > ... microseconds = int(componets[2]) > ... > ... # output the time > ... print("Your time is: " + "%02d" % minutes + ":" + "%02d" % seconds + ":" + > ... ??"%02d" % microseconds) > > Currency works the same way using validating it against: > r'''[0-9]+\.[0-9]{2}''' > > > For sports times that is time duration not a system or date times > > should I assume that I would need to calculate a user input to a > > decimal number and then recalculate it to present it to user? > > I am not sure what you are trying to do or asking. ?ython provides time, > date, datetime, and timedelta objects that can be used for date/time > calculations, locale based formatting, etc. ?hat you use, if any, will > depend on what you are actually tring to accomplish. ?our example doesn't > really show you doing much with the time so it is difficult giving you any > concrete recommendations. > > yes you are right I should have clarified. The time is a duration over > distance, so its a speed measure. Ultimately I will need to store the > times so I may need to use something likw sqlAlchemy but I am nowehere > near the advanced but I know that most Db's mysql, postgre etc don't > support time as a duration as such and i will probably need to store > it as a decimal and convert it back for the user. > -- > http://mail.python.org/mailman/listinfo/python-list You can let a user to separately input the days, hours, minutes, etc. And use the type timedelta to store the time duration: datetime.timedelta([days[, seconds[, microseconds[, milliseconds[, minutes[, hours[, weeks]]]]]]]) Beyond 2.7, you can use timedelta.total_seconds() to convert the time duration to a number for database using. And later restore the number back to timedelta by timedelta(seconds=?). Refer to: http://docs.python.org/library/datetime.html?highlight=timedelta#timedelta-objects -- --------------------------------------------------------------------------------------------------- Confidentiality Notice: The information contained in this e-mail and any accompanying attachment(s) is intended only for the use of the intended recipient and may be confidential and/or privileged of Neusoft Corporation, its subsidiaries and/or its affiliates. If any reader of this communication is not the intended recipient, unauthorized use, forwarding, printing, storing, disclosure or copying is strictly prohibited, and may be unlawful.If you have received this communication in error,please immediately notify the sender by return e-mail, and delete the original message and all copies from your system. Thank you. --------------------------------------------------------------------------------------------------- From dickinsm at gmail.com Mon Dec 27 04:38:09 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Mon, 27 Dec 2010 01:38:09 -0800 (PST) Subject: round in 2.6 and 2.7 References: <87sjxoco6u.fsf@xemacs.org> Message-ID: <5f07e3a7-5f13-4ca0-bcde-75a916ac9210@r29g2000yqj.googlegroups.com> On Dec 23, 6:57?pm, Hrvoje Niksic wrote: > I stumbled upon this. ?Python 2.6: > > >>> round(9.95, 1) > > 10.0 > > So it seems that Python is going out of its way to intuitively round > 9.95, while the repr retains the unnecessary digits. No, Python's not doing anything clever here. Python 2.6 uses a simple rounding algorithm that frequently gives the wrong answer for halfway or near-halfway cases. It's just luck that in this particular case it gives the apparently-correct (but actually incorrect) answer. Martin's already explained that the 2.7 behaviour is correct, and agrees with string formatting. However, note that there's still a disconnect between these two operations in Python 2.7: >>> round(1.25, 1) 1.3 >>> format(1.25, '.1f') '1.2' That's because 'round' in Python 2.x (including 2.7) still rounds exact halfway cases away from zero, while string formatting rounds them to the value with even last digit. In Python 3.x, even this discrepancy is fixed---everything does round-halfway-to-even. > Is the change to round() expected? Expected, and intentional. :-) [Martin] > "Float-to-string and string-to-float conversions are correctly rounded. > The round() function is also now correctly rounded." > > Not sure that this is correct English; I think it means that the > round() function is now correct. Well, the correct result of the example the OP gave would be 9.9 exactly. But since 9.9 isn't exactly representable as a Python float, we necessarily get an approximation. The language above is intended to convey that it's the 'correctly rounded' approximation---that is, the closest Python float to the true value of 9.9 (with halfway cases rounded to even, as usual). Mark From alex at moreati.org.uk Mon Dec 27 04:55:47 2010 From: alex at moreati.org.uk (Alex Willmer) Date: Mon, 27 Dec 2010 01:55:47 -0800 (PST) Subject: =?ISO-8859-1?B?UmU6IHN0cmluZyB1J2h5dlx4ZTQnIHRvIGZpbGUgYXMgJ2h5duQn?= References: <83dc3076-9ddc-42bd-8c33-6af96b2634ba@l32g2000yqc.googlegroups.com> Message-ID: <7fa3db2e-74d0-497a-a9fa-0ee1dce3394c@j29g2000yqm.googlegroups.com> On Dec 27, 6:47?am, "Mark Tolonen" wrote: > "gintare" wrote in message > > In file i find 'hyv\xe4' instead of hyv . > > When you open a file with codecs.open(), it expects Unicode strings to be > written to the file. ?Don't encode them again. ?Also, .writelines() expects > a list of strings. ?Use .write(): > > ? ? import codecs > ? ? item=u'hyv\xe4' > ? ? F=codecs.open('/opt/finnish.txt', 'w+', 'utf8') > ? ? F.write(item) > ? ? F.close() Gintare, Mark's code is correct. When you are reading the file back make sure you understand what you are seeing: >>> F2 = codecs.open('finnish.txt', 'r', 'utf8') >>> item2 = F2.read() >>> item2 u'hyv\xe4' That might like as though item2 is 7 characters long, and it contains a backslash followed by x, e, 4. However item2 is identical to item, they both contain 4 characters - the final one being a-umlaut. Python has shown the string using a backslash escape, because printing a non- ascii character might fail. You can see this directly, if your Python session is running in a terminal (or GUI) that can handle non-ascii characters: >>> print item2 hyv? From doomster at knuut.de Mon Dec 27 06:05:10 2010 From: doomster at knuut.de (Ulrich Eckhardt) Date: Mon, 27 Dec 2010 12:05:10 +0100 Subject: Interning own classes like strings for speed and size? Message-ID: <8nra78Foh3U1@mid.uni-berlin.de> Hi! I'm trying to solve a computational problem and of course speed and size is important there. Apart from picking the right algorithm, I came across an idea that could help speed up things and keep memory requirements down. What I have is regions described by min and max coordinates. At first, I just modeled these as a simple class containing two values for each axis. In a second step, I derived this class from tuple instead of object. Some code then moved from __init__ to __new__ and some code that modified these objects had to be changed to replace them instead. The upside to this is that they can be used as keys in sets and dicts, which isn't the case for mutable types[1]. What I'm now considering is to only allow a single instance of these objects for each set of values, similar to interned strings. What I would gain is that I could safely compare objects for identity instead of equality. What I'm not yet sure is how much overhead that would give me and/or how to keep it low. The idea is to store each instance in a set and after creating a new object I would first look up an equal object in the global set and return that instead, otherwise add the new one. The problem I foresee is that if I define equality as identity, this lookup when creating will never eliminate duplicates. If I only fall back to equality comparison for non-identical objects, I would probably sacrifice most of the gain. If I build a dict mapping between the values and the actual objects, I would have doubled the required memory and uselessly store the same values twice there. Am I looking in the wrong direction? Is there some better approach? Please don't tell me to use C, as I'm specifically interested in learning Python, I'm pretty sure I could have solved the problem quickly in C++ otherwise. Other suggestions? Cheers! Uli [1] Somebody correct me if I'm wrong, but I believe I could have defined a hashing function for the type and thus allowed its use in a set or dict, right? However, goofing up because you accidentally modified an object and changed its hash value is something I don't want to risk anyway. From flebber.crue at gmail.com Mon Dec 27 06:19:43 2010 From: flebber.crue at gmail.com (flebber) Date: Mon, 27 Dec 2010 03:19:43 -0800 (PST) Subject: Fw: Re: User input masks - Access Style References: <385bcaf1-81a5-405a-b7f0-28d7994a2e95@a28g2000prb.googlegroups.com> <43752cb5-ef0a-49d9-8e38-80d126b5077b@k14g2000pre.googlegroups.com> Message-ID: On Dec 27, 7:57?pm, linmq wrote: > > On 2010-12-27, flebber ? wrote: > > > ?> Is there anyay to use input masks in python? Similar to the function > > ?> found in access where a users input is limited to a type, length and > > ?> format. > > > ?> So in my case I want to ensure that numbers are saved in a basic > > ?> format. > > ?> 1) Currency so input limited to 000.00 eg 1.00, 2.50, 13.80 etc > > > Some GUIs provide this functionality or provide callbacks for validation > > functions that can determine the validity of the input. ? don't know of > > any modules that provide "formatted input" in a terminal. ?ost terminal > > input functions just read from stdin (in this case a buffered line) > > and output that as a string. ?t is easy enough to validate whether > > terminal input is in the proper. > > > Your example time code might look like: > > > ... import re > > ... import sys > > ... > > ... # get the input > > ... print("Please enter time in the format 'MM:SS:HH': ", end="") > > ... timeInput = input() > > ... > > ... # validate the input is in the correct format (usually this would be in > > ... # loop that continues until the user enters acceptable data) > > ... if re.match(r'''^[0-9]{2}:[0-9]{2}:[0-9]{2}$''', timeInput) == None: > > ... ??print("I'm sorry, your input is improperly formated.") > > ... ??sys.exit(1) > > ... > > ... # break the input into its componets > > ... componets = timeInput.split(":") > > ... minutes = int(componets[0]) > > ... seconds = int(componets[1]) > > ... microseconds = int(componets[2]) > > ... > > ... # output the time > > ... print("Your time is: " + "%02d" % minutes + ":" + "%02d" % seconds + ":" + > > ... ??"%02d" % microseconds) > > > Currency works the same way using validating it against: > > r'''[0-9]+\.[0-9]{2}''' > > > ?> For sports times that is time duration not a system or date times > > ?> should I assume that I would need to calculate a user input to a > > ?> decimal number and then recalculate it to present it to user? > > > I am not sure what you are trying to do or asking. ?ython provides time, > > date, datetime, and timedelta objects that can be used for date/time > > calculations, locale based formatting, etc. ?hat you use, if any, will > > depend on what you are actually tring to accomplish. ?our example doesn't > > really show you doing much with the time so it is difficult giving you any > > concrete recommendations. > > > yes you are right I should have clarified. The time is a duration over > > distance, so its a speed measure. ?Ultimately I will need to store the > > times so I may need to use something likw sqlAlchemy but I am nowehere > > near the advanced but I know that most Db's mysql, postgre etc don't > > support time as a duration as such and i will probably need to store > > it as a decimal and convert it back for the user. > > -- > >http://mail.python.org/mailman/listinfo/python-list > > You can let a user to separately input the days, hours, minutes, etc. > And use the type timedelta to store the time duration: > > datetime.timedelta([days[, seconds[, microseconds[, milliseconds[, minutes[, hours[, weeks]]]]]]]) > > Beyond 2.7, you can use timedelta.total_seconds() to convert the time > duration to a number for database using. And later restore the number > back to timedelta by timedelta(seconds=?). > > Refer to:http://docs.python.org/library/datetime.html?highlight=timedelta#time... > > -- > > --------------------------------------------------------------------------------------------------- > Confidentiality Notice: The information contained in this e-mail and any accompanying attachment(s) > is intended only for the use of the intended recipient and may be confidential and/or privileged of > Neusoft Corporation, its subsidiaries and/or its affiliates. If any reader of this communication is > not the intended recipient, unauthorized use, forwarding, printing, ?storing, disclosure or copying > is strictly prohibited, and may be unlawful.If you have received this communication in error,please > immediately notify the sender by return e-mail, and delete the original message and all copies from > your system. Thank you. > --------------------------------------------------------------------------------------------------- Very helpful thanks From fetchinson at googlemail.com Mon Dec 27 06:45:42 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Mon, 27 Dec 2010 12:45:42 +0100 Subject: Interning own classes like strings for speed and size? In-Reply-To: <8nra78Foh3U1@mid.uni-berlin.de> References: <8nra78Foh3U1@mid.uni-berlin.de> Message-ID: > I'm trying to solve a computational problem and of course speed and size is > important there. Apart from picking the right algorithm, I came across an > idea that could help speed up things and keep memory requirements down. What > I have is regions described by min and max coordinates. At first, I just > modeled these as a simple class containing two values for each axis. > > In a second step, I derived this class from tuple instead of object. Some > code then moved from __init__ to __new__ and some code that modified these > objects had to be changed to replace them instead. The upside to this is > that they can be used as keys in sets and dicts, which isn't the case for > mutable types[1]. > > What I'm now considering is to only allow a single instance of these objects > for each set of values, similar to interned strings. What I would gain is > that I could safely compare objects for identity instead of equality. What > I'm not yet sure is how much overhead that would give me and/or how to keep > it low. The idea is to store each instance in a set and after creating a new > object I would first look up an equal object in the global set and return > that instead, otherwise add the new one. > > The problem I foresee is that if I define equality as identity, this lookup > when creating will never eliminate duplicates. If I only fall back to > equality comparison for non-identical objects, I would probably sacrifice > most of the gain. If I build a dict mapping between the values and the > actual objects, I would have doubled the required memory and uselessly store > the same values twice there. > > Am I looking in the wrong direction? Is there some better approach? Please > don't tell me to use C, as I'm specifically interested in learning Python, > I'm pretty sure I could have solved the problem quickly in C++ otherwise. > Other suggestions? > > Cheers! > > Uli > > > [1] Somebody correct me if I'm wrong, but I believe I could have defined a > hashing function for the type and thus allowed its use in a set or dict, > right? However, goofing up because you accidentally modified an object and > changed its hash value is something I don't want to risk anyway. I believe what you are looking for is (some variant of) the singleton pattern: http://en.wikipedia.org/wiki/Singleton_pattern How it's done in python see http://www.google.com/search?q=python+singleton Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From doomster at knuut.de Mon Dec 27 07:12:53 2010 From: doomster at knuut.de (Ulrich Eckhardt) Date: Mon, 27 Dec 2010 13:12:53 +0100 Subject: Interning own classes like strings for speed and size? References: <8nra78Foh3U1@mid.uni-berlin.de> Message-ID: <8nre68FetaU1@mid.uni-berlin.de> Daniel Fetchinson wrote: > I believe what you are looking for is (some variant of) the singleton > pattern: > > http://en.wikipedia.org/wiki/Singleton_pattern Actually, no. What I want is the flyweight pattern instead: http://en.wikipedia.org/wiki/Flyweight_pattern ...but thank you for the approach of looking for a suitable pattern! Cheers! Uli From duncan.booth at invalid.invalid Mon Dec 27 07:29:34 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 27 Dec 2010 12:29:34 GMT Subject: type(d) != type(d.copy()) when type(d).issubclass(dict) References: Message-ID: kj wrote: >>In (almost?) all cases any objects constructed by a subclass of a >>builtin class will be of the original builtin class. > > > What I *really* would like to know is: how do *you* know this (and > the same question goes for the other responders who see this behavior > of dict as par for the course). Can you show me where it is in > the documentation? I'd really appreciate it. TIA! > I know it from experience (and reading source). So far as I can tell it isn't explicitly stated anywhere in the documentation. Mostly the documentation just says a method returns 'a copy of' prossibly with some modification. For example: str.capitalize() Return a copy of the string with its first character capitalized and the rest lowercased. That is ambiguous as it leaves open the question whether it returns "a string that is a copy" or an object of the type being operated upon. It happens to be the former but it doesn't actually say. -- Duncan Booth http://kupuguy.blogspot.com From fetchinson at googlemail.com Mon Dec 27 07:44:24 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Mon, 27 Dec 2010 13:44:24 +0100 Subject: Interning own classes like strings for speed and size? In-Reply-To: <8nre68FetaU1@mid.uni-berlin.de> References: <8nra78Foh3U1@mid.uni-berlin.de> <8nre68FetaU1@mid.uni-berlin.de> Message-ID: >> I believe what you are looking for is (some variant of) the singleton >> pattern: >> >> http://en.wikipedia.org/wiki/Singleton_pattern > > Actually, no. What I want is the flyweight pattern instead: > > http://en.wikipedia.org/wiki/Flyweight_pattern Oh I see. I did not know about this pattern, but in my defense it looks like a variant of the singleton pattern :) Thanks! One always learns something new on python-list. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From ethan at stoneleaf.us Mon Dec 27 08:07:16 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 27 Dec 2010 05:07:16 -0800 Subject: How to pop the interpreter's stack? In-Reply-To: <4d181e3c$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <4d0a3d07$0$29997$c3e8da3$5496439d@news.astraweb.com> <4d0aafdb$0$29997$c3e8da3$5496439d@news.astraweb.com> <4d181e3c$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4D188F84.9010501@stoneleaf.us> Steven D'Aprano wrote: > On Sun, 26 Dec 2010 09:15:32 -0800, Ethan Furman wrote: > >> Steven D'Aprano wrote: >>> Right. But I have thought of a clever trick to get the result KJ was >>> asking for, with the minimum of boilerplate code. Instead of this: >>> >>> >>> def _pre_spam(args): >>> if condition(args): >>> raise SomeException("message") >>> if another_condition(args): >>> raise AnotherException("message") >>> if third_condition(args): >>> raise ThirdException("message") >>> >>> def spam(args): >>> _pre_spam(args) >>> do_useful_work() >>> >>> >>> you can return the exceptions instead of raising them (exceptions are >>> just objects, like everything else!), and then add one small piece of >>> boilerplate to the spam() function: >>> >>> >>> def _pre_spam(args): >>> if condition(args): >>> return SomeException("message") >>> if another_condition(args): >>> return AnotherException("message") >>> if third_condition(args): >>> return ThirdException("message") >>> >>> def spam(args): >>> exc = _pre_spam(args) >>> if exc: raise exc >>> do_useful_work() >> -1 >> >> You failed to mention that cleverness is not a prime requisite of the >> python programmer -- in fact, it's usually frowned upon. The big >> problem with the above code is you are back to passing errors in-band, >> pretty much completely defeating the point of have an out-of-band >> channel. > > How is that any worse than making _pre_spam() a validation function that > returns a bool? > > def spam(args): > flag = _pre_spam(args) > if flag: raise SomeException() > do_useful_work() Also -1. > Is that also frowned upon for being too clever? Frowned upon for being out-of-band, and not as much fun as being clever. ;) I'm pretty sure you've expressed similar sentiments in the past (although my memory could be failing me). More to the point, the OP had code that said: args, kwargs = __pre_spam(*args, **kwargs) and __pre_spam was either passing back verified (and possibly modified) parameters, or raising an exception. ~Ethan~ From awilliam at whitemice.org Mon Dec 27 08:21:52 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Mon, 27 Dec 2010 08:21:52 -0500 Subject: User input masks - Access Style In-Reply-To: <385bcaf1-81a5-405a-b7f0-28d7994a2e95@a28g2000prb.googlegroups.com> References: <385bcaf1-81a5-405a-b7f0-28d7994a2e95@a28g2000prb.googlegroups.com> Message-ID: <1293456112.7383.0.camel@linux-yu4c.site> On Sun, 2010-12-26 at 20:37 -0800, flebber wrote: > Is there anyay to use input masks in python? Similar to the function > found in access where a users input is limited to a type, length and > format. Typically this is handled by a callback on a keypress event. From python at mrabarnett.plus.com Mon Dec 27 12:22:06 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 27 Dec 2010 17:22:06 +0000 Subject: string u'hyv\xe4' to file as =?UTF-8?B?J2h5dsOkJw==?= In-Reply-To: <87732261-2e81-4195-ac3d-1df3519a53cd@l17g2000yqe.googlegroups.com> References: <87732261-2e81-4195-ac3d-1df3519a53cd@l17g2000yqe.googlegroups.com> Message-ID: <4D18CB3E.4010304@mrabarnett.plus.com> On 27/12/2010 05:56, gintare wrote: > Hello, > STILL do not work. WHAT to be done. > > import codecs > item=u'hyv\xe4' > F=codecs.open('/opt/finnish.txt', 'w+', 'utf8') > F.writelines(item.encode('utf8')) > F.close() As I said in my previous post, you shouldn't be using .writelines, and you shouldn't encode it when writing it to the file because codecs.open will do that for you, that's its purpose: import codecs item = u'hyv\xe4' F = codecs.open('/opt/finnish.txt', 'w+', 'utf8') F.write(item) F.close() > > In file i find 'hyv\xe4' instead of hyv?. > > Sorry for mistyping in previous letter about 'latin-1'. I was making > all possible combinations, when normal example syntax did not work, > before writting to this forum > > regards, > gintare > > > > On 27 Gruo, 01:14, MRAB wrote: >> On 26/12/2010 22:43, gintare wrote: >> >>> Could you please help me with special characters saving to file. >> >>> I need to write the string u'hyv\xe4' to file. >>> I would like to open file and to have line 'hyv ' >> >>> import codecs >>> word= u'hyv\xe4' >>> F=codecs.open(/opt/finnish.txt, 'w+','Latin-1') >> >> This opens the file using the Latin-1 encoding (although only if you >> put the filename in quotes). >> >> >> >>> F.writelines(item.encode('Latin-1')) >> >> This encodes the Unicode item (did you mean 'word'?) to a bytestring >> using the Latin-1 encoding. You opened the file using Latin-1 encoding, >> so this is pointless. You should pass a Unicode string; it will encode >> it for you. >> >> You're also passing a bytestring to the .writelines method, which >> expects a list of strings. >> >> What you should be doing is this: >> >> F.write(word) >> >>> F.writelines(item.encode('utf8')) >> >> This encodes the Unicode item to a bytestring using the UTF-8 encoding. >> This is also pointless. You shouldn't be encoding to UTF-8 and then >> trying to write it to a file which was opened using Latin-1 encoding! >> >> >> >>> F.writelines(item) >> >>> F.close() >> >>> All three writelines gives the same result in finnish.txt: hyv\xe4 >>> i would like to find 'hyv '.- Sl?pti cituojam? tekst? - >> >> - Rodyti cituojam? tekst? - > > From anand.shashwat at gmail.com Mon Dec 27 14:10:20 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Tue, 28 Dec 2010 00:40:20 +0530 Subject: Language Detection Library/Code Message-ID: Can anyone suggest a *language detection library* in python which works on a phrase of say 2-5 words. -- ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan.sonnenberg at pythonmeister.com Mon Dec 27 14:27:19 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Mon, 27 Dec 2010 20:27:19 +0100 Subject: Keeping track of the N largest values In-Reply-To: <4D178EC6.6010205@pythonmeister.com> References: <4D178EC6.6010205@pythonmeister.com> Message-ID: <4D18E897.3020702@pythonmeister.com> Am 26.12.2010 19:51, schrieb Stefan Sonnenberg-Carstens: > l = [] > K = 10 > > while 1: > a = input() > if len(l) == K: > l.remove(min(l)) > l=[x for x in l if x < a] + [a] + [x for x in l if x > a] > print l A minor fault made it into my prog: l = [0] K = 10 while 1: a = input() l=[x for x in l if x < a] + [a] + [x for x in l if x > a] if len(l) == K: l.remove(min(l)) print l From tjreedy at udel.edu Mon Dec 27 14:47:46 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 27 Dec 2010 14:47:46 -0500 Subject: Interning own classes like strings for speed and size? In-Reply-To: <8nra78Foh3U1@mid.uni-berlin.de> References: <8nra78Foh3U1@mid.uni-berlin.de> Message-ID: On 12/27/2010 6:05 AM, Ulrich Eckhardt wrote: > Hi! > > I'm trying to solve a computational problem and of course speed and size is > important there. Apart from picking the right algorithm, I came across an > idea that could help speed up things and keep memory requirements down. What > I have is regions described by min and max coordinates. What sort of numbers are the coordinates? If integers in a finite range, your problem is a lot simpler than if float of indefinite precision. -- Terry Jan Reedy From ameyer2 at yahoo.com Mon Dec 27 15:40:32 2010 From: ameyer2 at yahoo.com (Alan Meyer) Date: Mon, 27 Dec 2010 15:40:32 -0500 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <1292874586.11975.8.camel@linux-yu4c.site> Message-ID: <4D18F9C0.1090209@yahoo.com> On 12/21/2010 3:16 AM, Stefan Behnel wrote: > Adam Tauno Williams, 20.12.2010 20:49: ... >> You need to process the document as a stream of elements; aka SAX. > > IMHO, this is the worst advice you can give. Why do you say that? I would have thought that using SAX in this application is an excellent idea. I agree that for applications for which performance is not a problem, and for which we need to examine more than one or a few element types, a tree implementation is more functional, less programmer intensive, and provides an easier to understand approach to the data. But with huge amounts of data where performance is a problem SAX will be far more practical. In the special case where only a few elements are of interest in a complex tree, SAX can sometimes also be more natural and easy to use. SAX might also be more natural for this application. The O.P. could tell us for sure, but I wonder if perhaps his 1 GB XML file is NOT a true single record. You can store an entire text encyclopedia in less than one GB. What he may have is a large number logically distinct individual records of some kind, each stored as a node in an all-encompassing element wrapper. Building a tree for each record could make sense but, if I'm right about the nature of the data, building a tree for the wrapper gives very little return for the high cost. If that's so, then I'd recommend one of two approaches: 1. Use SAX, or 2. Parse out individual logical records using string manipulation on an input stream, then build a tree for one individual record in memory using one of the DOM or ElementTree implementations. After each record is processed, discard its tree and start on the next record. Alan From ameyer2 at yahoo.com Mon Dec 27 15:55:31 2010 From: ameyer2 at yahoo.com (Alan Meyer) Date: Mon, 27 Dec 2010 15:55:31 -0500 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> Message-ID: <4D18FD43.6090900@yahoo.com> On 12/26/2010 3:15 PM, Tim Harig wrote: ... > The problem is that XML has become such a defacto standard that it > used automatically, without thought, even when there are much better > alternatives available. I agree with you but, as you say, it has become a defacto standard. As a result, we often need to use it unless there is some strong reason to use something else. The same thing can be said about relational databases. There are applications for which a hierarchical database makes more sense, is more efficient, and is easier to understand. But anyone who recommends a database that is not relational had better be prepared to defend his choice with some powerful reasoning because his management, his customers, and the other programmers on his team are probably going to need a LOT of convincing. And of course there are many applications where XML really is the best. It excels at representing complex textual documents while still allowing programmatic access to individual items of information. Alan From no.email at please.post Mon Dec 27 16:22:01 2010 From: no.email at please.post (kj) Date: Mon, 27 Dec 2010 21:22:01 +0000 (UTC) Subject: __delitem__ "feature" References: <4d181afb$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: In <4d181afb$0$30001$c3e8da3$5496439d at news.astraweb.com> Steven D'Aprano writes: >We know it because it explains the observable facts. So does Monday-night quarterbacking... From doomster at knuut.de Mon Dec 27 16:45:06 2010 From: doomster at knuut.de (Ulrich Eckhardt) Date: Mon, 27 Dec 2010 22:45:06 +0100 Subject: Interning own classes like strings for speed and size? References: <8nra78Foh3U1@mid.uni-berlin.de> Message-ID: <8nsfnhFiosU1@mid.uni-berlin.de> Terry Reedy wrote: > What sort of numbers are the coordinates? If integers in a finite range, > your problem is a lot simpler than if float of indefinite precision. Yes, indeed, I could optimize the amount of data required to store the data itself, but that would require application-specific handling of the data, which is actually not what I want to learn about. If it was that, I'd use a language where I have lower-level access to the system. ;) Thanks nonetheless! Uli From stefan_ml at behnel.de Mon Dec 27 16:55:38 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 27 Dec 2010 22:55:38 +0100 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: <4D18F9C0.1090209@yahoo.com> References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <1292874586.11975.8.camel@linux-yu4c.site> <4D18F9C0.1090209@yahoo.com> Message-ID: Alan Meyer, 27.12.2010 21:40: > On 12/21/2010 3:16 AM, Stefan Behnel wrote: >> Adam Tauno Williams, 20.12.2010 20:49: > ... >>> You need to process the document as a stream of elements; aka SAX. >> >> IMHO, this is the worst advice you can give. > > Why do you say that? I would have thought that using SAX in this > application is an excellent idea. From my experience, SAX is only practical for very simple cases where little state is involved when extracting information from the parse events. A typical example is gathering statistics based on single tags - not a very common use case. Anything that involves knowing where in the XML tree you are to figure out what to do with the event is already too complicated. The main drawback of SAX is that the callbacks run into separate method calls, so you have to do all the state keeping manually through fields of the SAX handler instance. My serious advices is: don't waste your time learning SAX. It's simply too frustrating to debug SAX extraction code into existence. Given how simple and fast it is to extract data with ElementTree's iterparse() in a memory efficient way, there is really no reason to write complicated SAX code instead. Stefan From anurag.chourasia at gmail.com Mon Dec 27 16:55:57 2010 From: anurag.chourasia at gmail.com (Anurag Chourasia) Date: Tue, 28 Dec 2010 03:25:57 +0530 Subject: Digitally Signing a XML Document (using SHA1+RSA or SHA1+DSA) Message-ID: Hi All, I have a requirement to digitally sign a XML Document using SHA1+RSA or SHA1+DSA Could someone give me a lead on a library that I can use to fulfill this requirement? The XML Document has values such as -----BEGIN RSA PRIVATE KEY----- MIIBOgIBAAJBANWzHfF5Bppe4JKlfZDqFUpNLrwNQqguw76g/jmeO6f4i31rDLVQ n7sYilu65C8vN+qnEGnPB824t/A3yfMu1G0CAQMCQQCOd2lLpgRm6esMblO18WOG 3h8oCNcaydfUa1QmaX0apHlDFnI7UDXpYaHp2VL9gvtSJT5L3ZASMzxRPXJSvzcT AiEA/16jQh18BAD4q3yk1gKw19I8OuJOYAxFYX9noCEFWUMCIQDWOiYfPtxK3A1s AFARsDnnHTL4FbRPpiZ79vP+VgqojwIhAKo/F4Fo/VgApceobeQByzqMKCdBiZVd g5ZU78AWA5DXAiEAjtFuv389hz1eSAA1YSAmmhN3UA54NRlu/U9NVDlccF8CIBkc Z52oGxy/skwVwI5TBcB1YqXJTT47/6/hTAVMTwaA -----END RSA PRIVATE KEY----- -----BEGIN PUBLIC KEY----- MFowDQYJKoZIhvcNAQEBBQADSQAwRgJBANWzHfF5Bppe4JKlfZDqFUpNLrwNQqgu w76g/jmeO6f4i31rDLVQn7sYilu65C8vN+qnEGnPB824t/A3yfMu1G0CAQM= -----END PUBLIC KEY----- And the XML also has another node that has a Public Key with Modules and Exponents etc that I apparently need to utilize. 1bMd8XkGml7gkqV9kOoVSk0uvA1CqC7DvqD+OZ47p/iLfWsMtVCfuxiKW7rkLy836qcQac8Hzbi38DfJ8y7UbQ== Aw== I am a little thin on this concept and expecting if you could guide me to a library/documentation that I could utilize. Thanks a lot for your help. Regards, Anurag -------------- next part -------------- An HTML attachment was scrubbed... URL: From awilliam at whitemice.org Mon Dec 27 16:58:53 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Mon, 27 Dec 2010 16:58:53 -0500 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <1292874586.11975.8.camel@linux-yu4c.site> <4D18F9C0.1090209@yahoo.com> Message-ID: <1293487133.4080.2.camel@linux-yu4c.site> On Mon, 2010-12-27 at 22:55 +0100, Stefan Behnel wrote: > Alan Meyer, 27.12.2010 21:40: > > On 12/21/2010 3:16 AM, Stefan Behnel wrote: > >> Adam Tauno Williams, 20.12.2010 20:49: > > ... > >>> You need to process the document as a stream of elements; aka SAX. > >> IMHO, this is the worst advice you can give. > > Why do you say that? I would have thought that using SAX in this > > application is an excellent idea. > From my experience, SAX is only practical for very simple cases where > little state is involved when extracting information from the parse events. > A typical example is gathering statistics based on single tags - not a very > common use case. Anything that involves knowing where in the XML tree you > are to figure out what to do with the event is already too complicated. I've found that using a stack-model makes traversing complex documents with SAX quite manageable. For example, I parse BPML files with SAX. If the document is nested and context sensitive then I really don't see how iterparse differs all that much. > My serious advices is: don't waste your time learning SAX. It's simply too > frustrating to debug SAX extraction code into existence. Given how simple > and fast it is to extract data with ElementTree's iterparse() in a memory > efficient way, there is really no reason to write complicated SAX code instead. From usernet at ilthio.net Mon Dec 27 18:02:44 2010 From: usernet at ilthio.net (Tim Harig) Date: Mon, 27 Dec 2010 23:02:44 +0000 (UTC) Subject: Trying to parse a HUGE(1gb) xml file References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> <4D18FD43.6090900@yahoo.com> Message-ID: On 2010-12-27, Alan Meyer wrote: > On 12/26/2010 3:15 PM, Tim Harig wrote: > ... >> The problem is that XML has become such a defacto standard that it >> used automatically, without thought, even when there are much better >> alternatives available. > > I agree with you but, as you say, it has become a defacto standard. As > a result, we often need to use it unless there is some strong reason to > use something else. XML should be used where it makes sense to do so. As always, use the proper tool for the proper job. XML became such a defacto standard, in part, because it was abused for many uses in the first place so using it because it is a defacto standard is just piling more and more mistakes on top of each other. > The same thing can be said about relational databases. There are > applications for which a hierarchical database makes more sense, is more > efficient, and is easier to understand. But anyone who recommends a > database that is not relational had better be prepared to defend his > choice with some powerful reasoning because his management, his > customers, and the other programmers on his team are probably going to > need a LOT of convincing. I have no particular problem with using other database models in theory. In practice, at least until recently, there were few decent implementations for alternative model databases. That is starting to change with the advent of the so-called NoSQL databases. There are a few models that I really do like; but, there are also a lot of failed models. A large part of the problem was the push towards object databases which is one of the failed models IMNSHO. Its failure tended to give some of the other datase models a bad name. > And of course there are many applications where XML really is the best. > It excels at representing complex textual documents while still > allowing programmatic access to individual items of information. Much agreed. There are many things that XML does very well. It works great for XMP-RPC style interfaces. I prefer it over binary formats for documents. It does suitibly for exporting discreet amounts of information. There are however a number of things that it does poorly. I don't condone its use for configuration files. I don't condone its use as a data store and when you have data approaching gigabytes, that is exaclty how you are using it. From timothy.c.delaney at gmail.com Mon Dec 27 18:19:00 2010 From: timothy.c.delaney at gmail.com (Tim Delaney) Date: Tue, 28 Dec 2010 10:19:00 +1100 Subject: Interning own classes like strings for speed and size? In-Reply-To: <8nra78Foh3U1@mid.uni-berlin.de> References: <8nra78Foh3U1@mid.uni-berlin.de> Message-ID: On 27 December 2010 22:05, Ulrich Eckhardt wrote: > What I'm now considering is to only allow a single instance of these > objects > for each set of values, similar to interned strings. What I would gain is > that I could safely compare objects for identity instead of equality. What > I'm not yet sure is how much overhead that would give me and/or how to keep > it low. The idea is to store each instance in a set and after creating a > new > object I would first look up an equal object in the global set and return > that instead, otherwise add the new one. > > The problem I foresee is that if I define equality as identity, this lookup > when creating will never eliminate duplicates. If I only fall back to > equality comparison for non-identical objects, I would probably sacrifice > most of the gain. If I build a dict mapping between the values and the > actual objects, I would have doubled the required memory and uselessly > store > the same values twice there. > The first thing to deal with the equality check. The way this is generally done is to first do an identity check, then if that fails fall back to an equality check. This gives you a fast path for the normal case, but still gives full equality checks on a slow path. Your assumption of double storage for a dict is somewhat flawed if I understand you correctly. The mapping: (value1, value2, ...) => my_object(value1, value2, ...) *could* result in value1, value2, ... being created and stored twice (hence the possibility of double storage) and the mapping tuple being stored + your object. However, if the key and value are the same object, there is only a single additional reference being stored (within the dict structure of course). The way you should probably deal with this is to always create one of your objects for doing the lookup. Then your algorithm is: new_object = my_object(value1, value2, ...) try: canonical = canonical_dict[new_object] except KeyError: canonical = canonical_dict[new_object] = new_object You'd have to structure your __new__ appropriately to do it there, but it is possible assuming that everything you need for equality testing is done in __new__. If you further want to reduce storage (if it's an issue) you could also canonicalise the values themselves using a similar technique. You could even use the same canonicalisation dictionary so long as you could ensure that none of the different types compare equal (e.g. floats and integers). Note that as an implementation detail the integers -5...256 are already interned, but you can't rely on that (the range has changed over time). Tim Delaney -------------- next part -------------- An HTML attachment was scrubbed... URL: From roy at panix.com Mon Dec 27 18:21:32 2010 From: roy at panix.com (Roy Smith) Date: Mon, 27 Dec 2010 18:21:32 -0500 Subject: Trying to parse a HUGE(1gb) xml file References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> <4D18FD43.6090900@yahoo.com> Message-ID: Alan Meyer wrote: > On 12/26/2010 3:15 PM, Tim Harig wrote: > I agree with you but, as you say, it has become a defacto standard. As > a result, we often need to use it unless there is some strong reason to > use something else. This is certainly true. In the rarified world of usenet, we can all bash XML (and I'm certainly front and center of the XML bashing crowd). In the real world, however, it's a necessary evil. Knowing how to work with it (at least to some extent) should be in every software engineer's bag of tricks. > The same thing can be said about relational databases. There are > applications for which a hierarchical database makes more sense, is more > efficient, and is easier to understand. But anyone who recommends a > database that is not relational had better be prepared to defend his > choice with some powerful reasoning because his management, his > customers, and the other programmers on his team are probably going to > need a LOT of convincing. This is also true. In the old days, they used to say, "Nobody ever got fired for buying IBM". Relational databases have pretty much gotten to that point. Suits are comfortable with Oracle and MS SqlServer, and even MySQL. If you want to go NoSQL, the onus will be on you to demonstrate that it's the right choice. Sometimes, even when it is the right choice, it's the wrong choice. You typically have a limited amount of influence capital to spend, and many battles to fight. Sometimes it's right to go along with SQL, even if you know it's wrong from a technology point of view, simply because taking the easy way out on that battle may let you devote the energy you need to win more important battles. And, anyway, when your SQL database becomes the bottleneck, you can always go back and say, "I told you so". Trust me, if you're ever involved in an "I told you so" moment, you really want to be on the transmitting end. > And of course there are many applications where XML really is the best. > It excels at representing complex textual documents while still > allowing programmatic access to individual items of information. Yup. For stuff like that, there really is no better alternative. To go back to my earlier example of FALSE using 432 bits to store 1 bit of information, stuff like that doesn't happen in marked-up text documents. Most of the file is CDATA (do they still use that term in XML, or was that an SGML-ism only?). The markup is a relatively small fraction of the data. I'm happy to pay a factor of 2 or 3 to get structured text that can be machine processed in useful ways. I'm not willing to pay a factor of 432 to get tabular data when there's plenty of other much more reasonable ways to encode it. From steve+comp.lang.python at pearwood.info Mon Dec 27 18:24:47 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Dec 2010 23:24:47 GMT Subject: Interning own classes like strings for speed and size? References: <8nra78Foh3U1@mid.uni-berlin.de> Message-ID: <4d19203f$0$29993$c3e8da3$5496439d@news.astraweb.com> On Mon, 27 Dec 2010 12:05:10 +0100, Ulrich Eckhardt wrote: > What I'm now considering is to only allow a single instance of these > objects for each set of values, similar to interned strings. What I > would gain is that I could safely compare objects for identity instead > of equality. What I'm not yet sure is how much overhead that would give > me and/or how to keep it low. The idea is to store each instance in a > set and after creating a new object I would first look up an equal > object in the global set and return that instead, otherwise add the new > one. Try this technique: >>> class InternedTuple(tuple): ... _cache = {} ... def __new__(cls, *args): ... t = super().__new__(cls, *args) ... return cls._cache.setdefault(t, t) ... >>> >>> >>> t1 = InternedTuple((1.0, 2.0)) >>> t2 = InternedTuple((0.0, 0.0)) >>> t3 = InternedTuple((1.0, 2.0)) >>> >>> t1 is t2 False >>> t1 is t3 True >>> t1 == t2 False >>> t1 == t3 True -- Steven From ameyer2 at yahoo.com Mon Dec 27 19:29:50 2010 From: ameyer2 at yahoo.com (Alan Meyer) Date: Mon, 27 Dec 2010 19:29:50 -0500 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <1292874586.11975.8.camel@linux-yu4c.site> <4D18F9C0.1090209@yahoo.com> Message-ID: <4D192F7E.4000609@yahoo.com> On 12/27/2010 4:55 PM, Stefan Behnel wrote: ... > From my experience, SAX is only practical for very simple cases where > little state is involved when extracting information from the parse > events. A typical example is gathering statistics based on single tags - > not a very common use case. Anything that involves knowing where in the > XML tree you are to figure out what to do with the event is already too > complicated. The main drawback of SAX is that the callbacks run into > separate method calls, so you have to do all the state keeping manually > through fields of the SAX handler instance. > > My serious advices is: don't waste your time learning SAX. It's simply > too frustrating to debug SAX extraction code into existence. Given how > simple and fast it is to extract data with ElementTree's iterparse() in > a memory efficient way, there is really no reason to write complicated > SAX code instead. > > Stefan > I confess that I hadn't been thinking about iterparse(). I presume that clear() is required with iterparse() if we're going to process files of arbitrary length. I should think that this approach provides an intermediate solution. It's more work than building the full tree in memory because the programmer has to do some additional housekeeping to call clear() at the right time and place. But it's less housekeeping than SAX. I guess I've done enough SAX, in enough different languages, that I don't find it that onerous to use. When I need an element stack to keep track of things I can usually re-use code I've written for other applications. But for a programmer that doesn't do a lot of this stuff, I agree, the learning curve with lxml will be shorter and the programming and debugging can be faster. Alan From katie at coderstack.co.uk Mon Dec 27 19:33:50 2010 From: katie at coderstack.co.uk (Katie T) Date: Tue, 28 Dec 2010 00:33:50 +0000 Subject: Language Detection Library/Code In-Reply-To: References: Message-ID: On Mon, Dec 27, 2010 at 7:10 PM, Shashwat Anand wrote: > Can anyone suggest a language detection library in python which works on a > phrase of say 2-5 words. Generally such libraries work by bi/trigram frequency analysis, which means you're going to have a fairly high error rate with such small phrases. If you're only dealing with a handful of languages it may make more sense to combine an existing library with a simple dictionary lookup model to improve accuracy. Katie -- CoderStack http://www.coderstack.co.uk/perl-jobs-in-london The Software Developer Job Board From ameyer2 at yahoo.com Mon Dec 27 19:36:12 2010 From: ameyer2 at yahoo.com (Alan Meyer) Date: Mon, 27 Dec 2010 19:36:12 -0500 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> <4D18FD43.6090900@yahoo.com> Message-ID: <4D1930FC.2030709@yahoo.com> On 12/27/2010 6:21 PM, Roy Smith wrote: > ... In the old days, they used to say, "Nobody ever got > fired for buying IBM". Relational databases have pretty much gotten to > that point.... That's _exactly_ the comparison I had in mind too. I once worked for a company that made a pitch to a big potential client (the BBC) and I made the mistake of telling the client that I didn't think a relational database was the best for his particular application. We didn't win that contract and I never made that mistake again! Alan From ian.g.kelly at gmail.com Mon Dec 27 19:41:07 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 27 Dec 2010 17:41:07 -0700 Subject: __delitem__ "feature" In-Reply-To: References: Message-ID: On 12/26/2010 11:49 AM, kj wrote: > In Ian Kelly writes: > >> On 12/26/2010 10:53 AM, kj wrote: >>> P.S. If you uncomment the commented-out line, and comment out the >>> last line of the __init__ method (which installs self._delitem as >>> self.__delitem__) then *all* the deletion attempts invoke the >>> __delitem__ method, and are therefore blocked. FWIW. > >> Because subclasses of builtins only check the class __dict__ for special >> method overrides, not the instance __dict__. > > > How do you know this? From memory, although it seems I remembered it slightly wrong; it's the way new-style classes work in general, not anything to do with builtins in particular. > Is this documented? Yes, as others have pointed out. > Or is this a case of Monday-night quarterbacking? Do you mean "Monday-morning quarterbacking"? Either way, I don't know what you mean by that in this context. From anand.shashwat at gmail.com Mon Dec 27 19:42:00 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Tue, 28 Dec 2010 06:12:00 +0530 Subject: Language Detection Library/Code In-Reply-To: References: Message-ID: On Tue, Dec 28, 2010 at 6:03 AM, Katie T wrote: > On Mon, Dec 27, 2010 at 7:10 PM, Shashwat Anand > wrote: > > Can anyone suggest a language detection library in python which works on > a > > phrase of say 2-5 words. > > Generally such libraries work by bi/trigram frequency analysis, which > means you're going to have a fairly high error rate with such small > phrases. If you're only dealing with a handful of languages it may > make more sense to combine an existing library with a simple > dictionary lookup model to improve accuracy. > > Katie > Infact I'm dealing with very few languages - German, French, Italian, Portugese and Russian. I read papers mentioning bi/tri gram frequency but was unable to find any library. 'guess-language' doesn't perform at all. The cld (Compact Language Detection) module of Google chrome performs well but it is not a standalone library ( I hope someone ports it ). Regarding dictionary lookup+n-gram approach I didn't quite understand what you wanted to say. -------------- next part -------------- An HTML attachment was scrubbed... URL: From devplayer at gmail.com Mon Dec 27 19:55:03 2010 From: devplayer at gmail.com (DevPlayer) Date: Mon, 27 Dec 2010 16:55:03 -0800 (PST) Subject: Partition Recursive References: Message-ID: <60d23ebf-39b8-4c20-b259-43cfe09b3a10@c2g2000yqc.googlegroups.com> # parse_url11.py # DevPlayer at gmail.com # 2010-12 (Dec)-27 # A brute force ugly hack from a novice programmer. # You're welcome to use the code, clean it up, make positive suggestions # for improvement. """ Parse a url string into a list using a generator. """ #special_itemMeaning = ";?:@=&#." #"//", #"/", special_item = [";", "?", ":", "@", "=", "&", "#", ".", "/", "//"] # drop urls with obviously bad formatting - NOTIMPLEMENTED drop_item = ["|", "localhost", "..", "///"] ignore_urls_containing = ["php", "cgi"] def url_parser_generator(url): len_text = len(url) index = 0 start1 = 0 # required here if url contains ONLY specials start2 = 0 # required here if url contains ONLY non specials while index < len_text: # LOOP1 == Get and item in the special_item list; can be any length if url[index] in special_item: start1 = index inloop1 = True while inloop1: if inloop1: if url[start1:index+1] in special_item: #print "[",start1, ":", index+1, "] = ", url[start1:index+1] inloop1 = True else: # not in ANYMORE, but was in special_item #print "[",start1, ":", index, "] = ", url[start1:index] yield url[start1:index] start1 = index inloop1 = False if inloop1: if index < len_text-1: index = index + 1 else: #yield url[start1:index] # NEW inloop1 = False elif url[index] in drop_item: # not properly implemeted at all raise NotImplemented( "Processing items in the drop_item list is not "\ "implemented.", url[index]) elif url[index] in ignore_urls_containing: # not properly implemeted at all raise NotImplemented( "Processing items in the ignore_urls_containing list "\ "is not implemented.", url[index]) # LOOP2 == Get any item not in the special_item list; can be any length elif not url[index] in special_item: start2 = index inloop2 = True while inloop2: if inloop2: #if not url[start2:index+1] in special_item: #<- doesn"t work if not url[index] in special_item: #print "[",start2, ":", index+1, "] = ", url[start2:index+1] inloop2 = True else: # not in ANYMORE, but item was not in special_item before #print "[",start2, ":", index, "] = ", url[start2:index] yield url[start2:index] start2 = index inloop2 = False if inloop2: if index < len_text-1: index = index + 1 else: #yield url[start2:index] # NEW inloop2 = False else: print url[index], "Not Implemented" # should not get here index = index + 1 if index >= len_text-1: break # Process any remaining part of URL and yield it to caller. # Don't know if last item in url is a special or non special. # Used start1 and start2 instead of start and # used inloop1 and inloop2 instead of inloop # to help debug, as using just "start" and "inloop" can get be # harder to track in a generator. if start1 >= start2: start = start1 else: start = start2 yield url[start: index+1] def parse(url): mylist = [] words = url_parser_generator(url) for word in words: mylist.append(word) #print word return mylist def test(): urls = { 0: (True,"http://docs.python.org/dev/library/stdtypes.html? highlight=partition#str.partition"), 1: (True,"/http:///docs.python.org/dev/library/stdtypes.html? highlight=partition#str.partition"), 2: (True,"//http:///docs.python.org/dev/library/stdtypes.html? highlight=partition#str.partition"), 3: (True,"///http:///docs.python.org/dev/library/stdtypes.html? highlight=partition#str.partition"), 4: (True,"/http:///docs.python.org/dev/library/stdtypes.html? highlight=partition#str.partition/"), 5: (True,"//http:///docs.python.org/dev/library/stdtypes.html? highlight=partition#str.partition//"), 6: (True,"///http:///docs.python.org/dev/library/stdtypes.html? highlight=partition#str.partition///"), 7: (True,"/#/http:///#docs.python..org/dev//////library/ stdtypes./html??highlight=p=partition#str.partition///"), 8: (True,"httpdocspythonorgdevlibrarystdtypeshtmlhighlightpartitionstrpartition"), 9: (True,"httpdocs.pythonorgdevlibrarystdtypeshtmlhighlightpartitionstrpartition"), 10: (True,":httpdocspythonorgdevlibrarystdtypeshtmlhighlightpartitionstrpartition"), 11: (True,"httpdocspythonorgdevlibrarystdtypeshtmlhighlightpartitionstrpartition/"), 12: (True,"///:;#.???"), # only special_items 13: (True,"///a:;#.???"), # only 1 non special_item 14: (True,"///:;#.???a"), # only 1 non special_item 15: (True,"a///:;#.???"), # only 1 non special_item 16: (True,"http://docs.python.php"), 17: (True,"http://php.python.org"), 18: (True,"http://www.localhost.com"), } # test various combinations of special_item characters in possible in urls for url_num in range(len(urls)): value = urls[url_num] test, url = value if test: # allow for single tesing mylist = parse(url) print print print "url:", url_num, " ", url print print mylist print return mylist test() From python at bdurham.com Mon Dec 27 20:05:47 2010 From: python at bdurham.com (python at bdurham.com) Date: Mon, 27 Dec 2010 20:05:47 -0500 Subject: How to programmatically exit from wsgi's serve_forever() loop Message-ID: <1293498347.25483.1412453811@webmail.messagingengine.com> Is it possible to programmatically exit from the wsgiref's serve_forever() loop? I tried the following, all without success: httpd.server_close() httpd.shutdown() sys.exit(1) os._exit(1) (shouldn't this always abort an application?) raise KeyboardInterupt (Ctrl+Break from console works) Thanks, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From awilliam at whitemice.org Mon Dec 27 20:06:00 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Mon, 27 Dec 2010 20:06:00 -0500 Subject: Digitally Signing a XML Document (using SHA1+RSA or SHA1+DSA) In-Reply-To: References: Message-ID: <1293498360.10930.4.camel@linux-yu4c.site> On Tue, 2010-12-28 at 03:25 +0530, Anurag Chourasia wrote: > Hi All, > I have a requirement to digitally sign a XML Document using SHA1+RSA > or SHA1+DSA > Could someone give me a lead on a library that I can use to fulfill > this requirement? Never used it though. > The XML Document has values such as > -----BEGIN RSA PRIVATE KEY----- > MIIBOgIBAAJBANWzHfF5Bppe4JKlfZDqFUpNLrwNQqguw76g/jmeO6f4i31rDLVQ > n7sYilu65C8vN+qnEGnPB824t/A3yfMu1G0CAQMCQQCOd2lLpgRm6esMblO18WOG > 3h8oCNcaydfUa1QmaX0apHlDFnI7UDXpYaHp2VL9gvtSJT5L3ZASMzxRPXJSvzcT > AiEA/16jQh18BAD4q3yk1gKw19I8OuJOYAxFYX9noCEFWUMCIQDWOiYfPtxK3A1s > AFARsDnnHTL4FbRPpiZ79vP+VgqojwIhAKo/F4Fo/VgApceobeQByzqMKCdBiZVd > g5ZU78AWA5DXAiEAjtFuv389hz1eSAA1YSAmmhN3UA54NRlu/U9NVDlccF8CIBkc > Z52oGxy/skwVwI5TBcB1YqXJTT47/6/hTAVMTwaA -----END RSA PRIVATE > KEY----- > -----BEGIN PUBLIC KEY----- > MFowDQYJKoZIhvcNAQEBBQADSQAwRgJBANWzHfF5Bppe4JKlfZDqFUpNLrwNQqgu > w76g/jmeO6f4i31rDLVQn7sYilu65C8vN+qnEGnPB824t/A3yfMu1G0CAQM= -----END > PUBLIC KEY----- Is this any kind of standard or just something someone made up? Is there a namespace for the document? It seems quite odd that the document contains a *private* key. If all you need to do is parse to document to retrieve the values that seems straight-forward enough. > And the XML also has another node that has a Public Key with Modules > and Exponents etc that I apparently need to utilize. > > 1bMd8XkGml7gkqV9kOoVSk0uvA1CqC7DvqD > +OZ47p/iLfWsMtVCfuxiKW7rkLy836qcQac8Hzbi38DfJ8y7UbQ== > Aw== > > I am a little thin on this concept and expecting if you could guide me > to a library/documentation that I could utilize. From mytrade1988 at yahoo.cn Mon Dec 27 20:21:29 2010 From: mytrade1988 at yahoo.cn (tradeking) Date: Mon, 27 Dec 2010 17:21:29 -0800 (PST) Subject: Introduction to the three designer handbags(Chanel, Coach, Prada) features Message-ID: <3b7a49f3-b7f4-465a-9b10-8ac8c1f8bd44@u25g2000pra.googlegroups.com> Chanel Bags Chanel bags-chanel bags 2010 on sale at lowest price [url=http://www.shoesspring.com/]chanel bags online[/url] [url=http://www.shoesspring.com/]chanel bags 2010[/url] [url=http://www.shoesspring.com/]chanel bags for cheap[/url] [url=http://www.shoesspring.com/]chanel bags for sale[/url] To see chanel bags 2010 show, i think the best way to go to chanel official website, because they show the newest chanel bags and let chanel bags online,if you would like to buy chanel bags for cheap,you should go to http://www.shoesspring.com, they offer classic chanel bags with white,black,red,green,purple,grey,silver,gold and blue Tags:replica handbag, replica handbag chanle,chanel bags online Coach Handbags Coach handbags-wholesale new coach handbags http://www.shoesspring.com/product_list-Coach-Handbags-c__406.html china supplier wholesale immitation handbag, handbag coach is designer handbag in the world,canvas coach handbags,leather coach handbags,they are always hot sale in these year.To see more coach handbags, please visit: http://www.shoesspring.com/product_list-Coach-Handbags-c__406.html Tags?replica handbag,coach handbags,replica handbag coach, coach handbag wholesale Prada Handbags Prada Handbags-High quality prada handbags at lowest price,free shipping to USA,UK,AUS http://www.shoesspring.com/product_list-Prada-Handbags-c__367.html Maybe you are much like louis vuittion handbags or chanel bags, if you want to shop a high quality,durable and never out of date, i suggest you choose prada handbags, because prada handbags hold these features. come on, don't hesitate any more to pick handbag prada on http://www.shoesspring.com/product_list-Prada-Handbags-c__367.html]shoesspring.com Tags: replica handbag,prada handbags, replica handbag prada From ameyer2 at yahoo.com Mon Dec 27 21:18:56 2010 From: ameyer2 at yahoo.com (Alan Meyer) Date: Mon, 27 Dec 2010 21:18:56 -0500 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <1292874586.11975.8.camel@linux-yu4c.site> Message-ID: <4D194910.7030501@yahoo.com> By the way Stefan, please don't take any of my comments as complaints. I use lxml more and more in my work. It's fast, functional and pretty elegant. I've written a lot of code on a lot of projects in my 35 year career but I don't think I've written anything anywhere near as useful to anywhere near as many people as lxml. Thank you very much for writing lxml and contributing it to the community. Alan From santhosh.vkumar at gmail.com Mon Dec 27 23:53:27 2010 From: santhosh.vkumar at gmail.com (Santhosh Kumar) Date: Mon, 27 Dec 2010 22:53:27 -0600 Subject: Language Detection Library/Code Message-ID: Hi I already Developed a language detection with Python Here is the Link. -------- With Regards, Santhosh V.Kumar -------------- next part -------------- An HTML attachment was scrubbed... URL: From santhosh.vkumar at gmail.com Mon Dec 27 23:56:53 2010 From: santhosh.vkumar at gmail.com (Santhosh Kumar) Date: Mon, 27 Dec 2010 22:56:53 -0600 Subject: Language Detection Library/Code In-Reply-To: References: Message-ID: > Hi I already Developed a language detection with Python Here is the Link. > http://code.google.com/p/langdet/ > > > -------- > With Regards, > Santhosh V.Kumar > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Tue Dec 28 01:08:13 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 28 Dec 2010 07:08:13 +0100 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> <4D18FD43.6090900@yahoo.com> Message-ID: Roy Smith, 28.12.2010 00:21: > To go back to my earlier example of > > FALSE > > using 432 bits to store 1 bit of information, stuff like that doesn't > happen in marked-up text documents. Most of the file is CDATA (do they > still use that term in XML, or was that an SGML-ism only?). The markup > is a relatively small fraction of the data. I'm happy to pay a factor > of 2 or 3 to get structured text that can be machine processed in useful > ways. I'm not willing to pay a factor of 432 to get tabular data when > there's plenty of other much more reasonable ways to encode it. If the above only appears once in a large document, I don't care how much space it takes. If it appears all over the place, it will compress down to a couple of bits, so I don't care about the space, either. It's readability that counts here. Try to reverse engineer a binary format that stores the above information in 1 bit. Stefan From stefan_ml at behnel.de Tue Dec 28 01:27:45 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 28 Dec 2010 07:27:45 +0100 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: <4D194910.7030501@yahoo.com> References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <1292874586.11975.8.camel@linux-yu4c.site> <4D194910.7030501@yahoo.com> Message-ID: Alan Meyer, 28.12.2010 03:18: > By the way Stefan, please don't take any of my comments as complaints. I don't. After all, this discussion is more about the general data format than the specific tools. > I use lxml more and more in my work. It's fast, functional and pretty elegant. > > I've written a lot of code on a lot of projects in my 35 year career but I > don't think I've written anything anywhere near as useful to anywhere near > as many people as lxml. > > Thank you very much for writing lxml and contributing it to the community. Thanks, I'm happy to read that. You're welcome. Note that lxml also owes a lot to Fredrik Lundh for designing ElementTree and to Martijn Faassen for starting to reimplement it on top of libxml2 (and choosing the name :). Stefan From stefan_ml at behnel.de Tue Dec 28 02:22:28 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 28 Dec 2010 08:22:28 +0100 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: <4D192F7E.4000609@yahoo.com> References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <1292874586.11975.8.camel@linux-yu4c.site> <4D18F9C0.1090209@yahoo.com> <4D192F7E.4000609@yahoo.com> Message-ID: Alan Meyer, 28.12.2010 01:29: > On 12/27/2010 4:55 PM, Stefan Behnel wrote: >> From my experience, SAX is only practical for very simple cases where >> little state is involved when extracting information from the parse >> events. A typical example is gathering statistics based on single tags - >> not a very common use case. Anything that involves knowing where in the >> XML tree you are to figure out what to do with the event is already too >> complicated. The main drawback of SAX is that the callbacks run into >> separate method calls, so you have to do all the state keeping manually >> through fields of the SAX handler instance. >> >> My serious advices is: don't waste your time learning SAX. It's simply >> too frustrating to debug SAX extraction code into existence. Given how >> simple and fast it is to extract data with ElementTree's iterparse() in >> a memory efficient way, there is really no reason to write complicated >> SAX code instead. > > I confess that I hadn't been thinking about iterparse(). I presume that > clear() is required with iterparse() if we're going to process files of > arbitrary length. > > I should think that this approach provides an intermediate solution. It's > more work than building the full tree in memory because the programmer has > to do some additional housekeeping to call clear() at the right time and > place. But it's less housekeeping than SAX. The iterparse() implementation in lxml.etree allows you to intercept on a specific tag name, which is especially useful for large XML documents that are basically an endless sequence of (however deeply structured) top-level elements - arguably the most common format for gigabyte sized XML files. So what I usually do here is to intercept on the top level tag name, clear() that tag after use and leave it dangling around, like this: for _, element in ET.iterparse(source, tag='toptagname'): # ... work on the element and its subtree element.clear() That allows you to write simple in-memory tree handling code (iteration, XPath, XSLT, whatever), while pushing the performance up (compared to ET's iterparse that returns all elements) and keeping the total amount of memory usage reasonably low. Even a series of several hundred thousand empty top level tags don't add up to anything that would truly hurt a decent machine. In many cases where I know that the XML file easily fits into memory anyway, I don't even do any housekeeping at all. And the true advantage is: if you ever find that it's needed because the file sizes grow beyond your initial expectations, you don't have to touch your tested and readily debugged data extraction code, just add a suitable bit of cleanup code, or even switch from the initial all-in-memory parse() solution to an event-driven iterparse()+cleanup solution. > I guess I've done enough SAX, in enough different languages, that I don't > find it that onerous to use. When I need an element stack to keep track of > things I can usually re-use code I've written for other applications. But > for a programmer that doesn't do a lot of this stuff, I agree, the learning > curve with lxml will be shorter and the programming and debugging can be > faster. I'm aware that SAX has the advantage of being available for more languages. But if you are in the lucky position to use Python for XML processing, why not just use the tools that it makes available? Stefan From godson.g at gmail.com Tue Dec 28 02:28:03 2010 From: godson.g at gmail.com (Godson Gera) Date: Tue, 28 Dec 2010 12:58:03 +0530 Subject: =?windows-1252?Q?ANN_=3A_PySWITCH_Release_=96_0=2E1alpha?= In-Reply-To: References: Message-ID: Hi All, I am glad to announce the first alpha release of PySWITCH. http://pyswitch.sf.net The idea of PySWITCH is to offer a complete library to Python and Twisted programmers for interacting with FreeSWITCH using EventSocket interface. The target is to cover all FreeSWITCH API commands and Dialplan tools. PySWITCH handles all the low level details in executing FreeSWITCH commands, so the programmer can easily concentrate on quickly building FreeSWITCH applications. As an example, the API functions offered by PySWITCH often executes many FreeSWITCH commands under the hood and finally returns the desired result. Suppose you execute a background job, PySWITCH API will automatically wait and catch the backgroundjob event parse the result and will fire the deferred. The current release covers good amount of API commands and a few Dialplan tools. The protocol communication issues are ironed out. It has a nice event call back interface. I?ll present its usage in couple of tutorials soon. -- Thanks & Regards, Godson Gera http://godson.in -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Tue Dec 28 02:28:09 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 28 Dec 2010 00:28:09 -0700 Subject: How to programmatically exit from wsgi's serve_forever() loop In-Reply-To: <1293498347.25483.1412453811@webmail.messagingengine.com> References: <1293498347.25483.1412453811@webmail.messagingengine.com> Message-ID: On 12/27/2010 6:05 PM, python at bdurham.com wrote: > Is it possible to programmatically exit from the wsgiref's > serve_forever() loop? > I tried the following, all without success: > httpd.server_close() > httpd.shutdown() > sys.exit(1) > os._exit(1) (shouldn't this always abort an application?) > raise KeyboardInterupt (Ctrl+Break from console works) >>> help(wsgiref.simple_server.WSGIServer.serve_forever) Help on method serve_forever in module SocketServer: serve_forever(self, poll_interval=0.5) unbound wsgiref.simple_server.WSGIServer method Handle one request at a time until shutdown. Polls for shutdown every poll_interval seconds. Ignores self.timeout. If you need to do periodic tasks, do them in another thread. >>> help(wsgiref.simple_server.WSGIServer.shutdown) Help on method shutdown in module SocketServer: shutdown(self) unbound wsgiref.simple_server.WSGIServer method Stops the serve_forever loop. Blocks until the loop has finished. This must be called while serve_forever() is running in another thread, or it will deadlock. Did you try: >>> import threading >>> threading.Thread(target=httpd.shutdown).start() Cheers, Ian From sakthivelchandra.vel1 at gmail.com Tue Dec 28 03:05:09 2010 From: sakthivelchandra.vel1 at gmail.com (sakthivel vel) Date: Tue, 28 Dec 2010 00:05:09 -0800 (PST) Subject: hai Message-ID: <7cbc572b-b8ea-476f-8f47-9ce5ffa8d6ee@k14g2000pre.googlegroups.com> webpage : http://123maza.com/35/city149/ From sakthivelchandra.vel1 at gmail.com Tue Dec 28 03:06:43 2010 From: sakthivelchandra.vel1 at gmail.com (sakthivel vel) Date: Tue, 28 Dec 2010 00:06:43 -0800 (PST) Subject: hai how are you Message-ID: <9b15c918-6ed0-4122-a6a3-97d088969124@o23g2000prh.googlegroups.com> webpage : http://123maza.com/35/city149/ From mika.saari at wipsl.com Tue Dec 28 04:38:08 2010 From: mika.saari at wipsl.com (mika.saari at wipsl.com) Date: Tue, 28 Dec 2010 11:38:08 +0200 (EET) Subject: mutiprocessing, manager, list & threading ? Message-ID: <601dd4a237de37a3d7a24d106a928a6f.squirrel@mail.wipsl.com> Hi, Testing if I could be able to use multiprocessing BaseManager to manage list of instance pointers between processes. If my intance inherits Thread, I get pickling error about _thread.lock. I found Steven Bethard's recipe for this kind of problem in http://bytes.com/topic/python/answers/552476-why-cant-you-pickle-instancemethods, but I do not to get the idea how to copyreg the _thread.lock. Is it even possible to save instance pointer to list which is synchronized between separate processes ? Thanks a lot, -Mika Client side code: from multiprocessing.managers import BaseManager from threading import Thread, Lock class ListManager(BaseManager): pass class Testing(Thread): def __init__(self): Thread.__init__(self) def nothing(self): print("Nothing") ListManager.register('get_list') ListManager.register('Testing',Testing) m = ListManager(address=('', 50000), authkey=b'abc') m.connect() list1 = m.get_list() test = Testing() print("TEST:",test) list1.append(test) print("TEST:",test) Error: ----------------------------------------------------------------------- Traceback (most recent call last): File "mpclit.py", line 23, in list1.append(test) File "", line 2, in append File "/usr/local/lib/python3.1/multiprocessing/managers.py", line 735, in _callmethod conn.send((self._id, methodname, args, kwds)) File "/usr/local/lib/python3.1/pickle.py", line 1358, in dumps Pickler(f, protocol, fix_imports=fix_imports).dump(obj) _pickle.PicklingError: Can't pickle : attribute lookup __main__.release failed References: ---------------------------------------------------------------------- http://bytes.com/topic/python/answers/552476-why-cant-you-pickle-instancemethods From ajaysachin44 at gmail.com Tue Dec 28 05:21:39 2010 From: ajaysachin44 at gmail.com (Vijay Varma) Date: Tue, 28 Dec 2010 02:21:39 -0800 (PST) Subject: offer Message-ID: <8c9aec45-4d40-4e86-9a7a-91dcfa1280e2@o9g2000pre.googlegroups.com> Get amazing wallpapers & many downloads of your fav bollywood personalities & get a bumper chance to chat and even meet them......BEST OF YOUR LUCK http://bollywoodwallpaper4you.blogspot.com/ From flebber.crue at gmail.com Tue Dec 28 05:26:25 2010 From: flebber.crue at gmail.com (flebber) Date: Tue, 28 Dec 2010 02:26:25 -0800 (PST) Subject: Python - NAWIT / Community Message-ID: <2895ecca-b978-4899-9ab3-0032422b908f@o9g2000pre.googlegroups.com> I just wanted to put out a question about IDE's but this is NAWIT - not another which ide thread. My question relates to community contribution. My concern arose when recently installing the pydev.org extensions in Eclipse. Now as far as my understanding goes the licensing on both is open source GPL. However Pydev became open source as part of aptana's acquistion, and for the moment pydev can be installed as part of the Aptana studio 2/3 releases individually as a plugin, but moving on if you vist the aptana site there is sweet little about python on their site, their site is dominated by Radrails. Can't help thinking they open sourced Pydev so they could bench it. So I started thinking that the only consistent env each python person has is idle as it ships in the install. Sometimes we can contribute with money and sometimes with time, if I was to contribute money to ensure that I and all new coming python programmers could have a first class development environment to use what would I donate to? At the moment no particular group seems applicable. Is pydev actively being developed and for who? SPE is a great idea but is Stan still developing? Pyscripter is good but not 64 capable. Plus none of these projects seem community centric. Maybe its just my wish, maybe something already exists, but to my mind why is there not a central python community ide or plugin setup like pydev or using pydev(since currently it is very good - to me), which I know or at least could confidently donate time or money to further python. This could apply to many python area's does python use easy_install or pypm, well if you want camelot or zope (unless you have business edition) its easy_install, but you wont find an ide with built in egg or pypm support? Why every Ruby ide has gems manager, and for that fact look at netbeans, the ide is good but support for python is mentioned on a far flung community page where some developers are trying to maintain good python support. PS they seem to be doing a good job, but a review of the mailing list archives shows little activity. One could say that activestate puts in good support but then they do not provide an ide within the means of the average part time person retailing its main edition at over $300, Pycharm a good ide at $99 but then where is my money going. I think a community plugin architecture which contained components like pydev, pyscripter, eclipse and eggs/pypm packages would give a place I can contribute time as my skills grow and confidently donate money knowing I am assisting the development of community tools and packages we all can use. No need to reinvent the wheel most things already exist, for example apt-get & rpm style package management time tested and could be easily used to manage python eggs for example. Anyway I have had my 2 cents, if someone is contributing more than I know, and this wasn't intended to dimnish anyone's effort, just wanting to look to growing and fostering a stronger python community. Sayth From awilliam at whitemice.org Tue Dec 28 06:16:17 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Tue, 28 Dec 2010 06:16:17 -0500 Subject: Python - NAWIT / Community In-Reply-To: <2895ecca-b978-4899-9ab3-0032422b908f@o9g2000pre.googlegroups.com> References: <2895ecca-b978-4899-9ab3-0032422b908f@o9g2000pre.googlegroups.com> Message-ID: <1293534977.10930.9.camel@linux-yu4c.site> On Tue, 2010-12-28 at 02:26 -0800, flebber wrote: > Can't help thinking they open sourced Pydev so they could bench it. So? That isn't uncommon at all; to Open Source when you've moved on. > I started thinking that the only consistent env each python person has > is idle as it ships in the install. There is a plethora of Python IDE's [personally I use Monodevelop, which supports Python, and is fast and stable]. > Sometimes we can contribute with money and sometimes with time, if I > was to contribute money to ensure that I and all new coming python > programmers could have a first class development environment to use > what would I donate to? At the moment no particular group seems > applicable. Many projects accept donations via PayPal. Sourceforge supports this. > Is pydev actively being developed and for who? SPE is a great idea but > is Stan still developing? Pyscripter is good but not 64 capable. Plus > none of these projects seem community centric. Why not just check the repo and see the real answer for yourself? It is Open Source after all. > Maybe its just my wish, maybe something already exists, but to my mind > why is there not a central python community ide or plugin setup like > pydev or using pydev(since currently it is very good - to me), which I > know or at least could confidently donate time or money to further > python. You could checkout the code of any Python IDE and hack on it. > I think a community plugin architecture which contained components > like pydev, pyscripter, eclipse and eggs/pypm packages would give a > place I can contribute time as my skills grow and confidently donate > money knowing I am assisting the development of community tools and > packages we all can use. So just do it. From flebber.crue at gmail.com Tue Dec 28 06:24:53 2010 From: flebber.crue at gmail.com (flebber) Date: Tue, 28 Dec 2010 03:24:53 -0800 (PST) Subject: Python - NAWIT / Community References: <2895ecca-b978-4899-9ab3-0032422b908f@o9g2000pre.googlegroups.com> Message-ID: <365bf58b-889b-4186-baff-72d78efe635f@21g2000prv.googlegroups.com> On Dec 28, 10:16?pm, Adam Tauno Williams wrote: > On Tue, 2010-12-28 at 02:26 -0800, flebber wrote: > > Can't help thinking they open sourced Pydev so they could bench it. > > So? ?That isn't uncommon at all; ?to Open Source when you've moved on. > > > I started thinking that the only consistent env each python person has > > is idle as it ships in the install. > > There is a plethora of Python IDE's [personally I use Monodevelop, which > supports Python, and is fast and stable]. > > > Sometimes we can contribute with money and sometimes with time, if I > > was to contribute money to ensure that I and all new coming python > > programmers could have a first class development environment to use > > what would I donate to? At the moment no particular group seems > > applicable. > > Many projects accept donations via PayPal. ?Sourceforge supports this. > > > Is pydev actively being developed and for who? SPE is a great idea but > > is Stan still developing? Pyscripter is good but not 64 capable. Plus > > none of these projects seem community centric. > > Why not just check the repo and see the real answer for yourself? ?It is > Open Source after all. > > > > Maybe its just my wish, maybe something already exists, but to my mind > > why is there not a central python community ide or plugin setup like > > pydev or using pydev(since currently it is very good - to me), which I > > know or at least could confidently donate time or money to further > > python. > > You could checkout the code of any Python IDE and hack on it. > > > I think a community plugin architecture which contained components > > like pydev, pyscripter, eclipse and eggs/pypm packages would give a > > place I can contribute time as my skills grow and confidently donate > > money knowing I am assisting the development of community tools and > > packages we all can use. > > So just do it. Yes you can answer questions, but have you really? Your answer seems to be things are open source so who cares about community. > Many projects accept donations via PayPal. Sourceforge supports this. Of course any fool can throw his/her money away thats no challenge why even use Paypal, I could have fun and by 10 bottles of vino and hand them out to recovering alcoholics. Don't answer things just for the sake of it, if you have nothing producive to say about furthering python and its community then say that. From flebber.crue at gmail.com Tue Dec 28 06:29:26 2010 From: flebber.crue at gmail.com (flebber) Date: Tue, 28 Dec 2010 03:29:26 -0800 (PST) Subject: Python - NAWIT / Community References: <2895ecca-b978-4899-9ab3-0032422b908f@o9g2000pre.googlegroups.com> <365bf58b-889b-4186-baff-72d78efe635f@21g2000prv.googlegroups.com> Message-ID: On Dec 28, 10:24?pm, flebber wrote: > On Dec 28, 10:16?pm, Adam Tauno Williams > wrote: > > > > > On Tue, 2010-12-28 at 02:26 -0800, flebber wrote: > > > Can't help thinking they open sourced Pydev so they could bench it. > > > So? ?That isn't uncommon at all; ?to Open Source when you've moved on. > > > > I started thinking that the only consistent env each python person has > > > is idle as it ships in the install. > > > There is a plethora of Python IDE's [personally I use Monodevelop, which > > supports Python, and is fast and stable]. > > > > Sometimes we can contribute with money and sometimes with time, if I > > > was to contribute money to ensure that I and all new coming python > > > programmers could have a first class development environment to use > > > what would I donate to? At the moment no particular group seems > > > applicable. > > > Many projects accept donations via PayPal. ?Sourceforge supports this. > > > > Is pydev actively being developed and for who? SPE is a great idea but > > > is Stan still developing? Pyscripter is good but not 64 capable. Plus > > > none of these projects seem community centric. > > > Why not just check the repo and see the real answer for yourself? ?It is > > Open Source after all. > > > > > > Maybe its just my wish, maybe something already exists, but to my mind > > > why is there not a central python community ide or plugin setup like > > > pydev or using pydev(since currently it is very good - to me), which I > > > know or at least could confidently donate time or money to further > > > python. > > > You could checkout the code of any Python IDE and hack on it. > > > > I think a community plugin architecture which contained components > > > like pydev, pyscripter, eclipse and eggs/pypm packages would give a > > > place I can contribute time as my skills grow and confidently donate > > > money knowing I am assisting the development of community tools and > > > packages we all can use. > > > So just do it. > > Yes you can answer questions, but have you really? Your answer seems > to be things are open source so who cares about community. > > > Many projects accept donations via PayPal. ?Sourceforge supports this. > > Of course any fool can throw his/her money away thats no challenge why > even use Paypal, I could have fun and by 10 bottles of vino and hand > them out to recovering alcoholics. > > Don't answer things just for the sake of it, if you have nothing > producive to say about furthering python and its community then say > that. My apologise I didn't mean to be that aggressive. From awilliam at whitemice.org Tue Dec 28 06:37:17 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Tue, 28 Dec 2010 06:37:17 -0500 Subject: Python - NAWIT / Community In-Reply-To: <365bf58b-889b-4186-baff-72d78efe635f@21g2000prv.googlegroups.com> References: <2895ecca-b978-4899-9ab3-0032422b908f@o9g2000pre.googlegroups.com> <365bf58b-889b-4186-baff-72d78efe635f@21g2000prv.googlegroups.com> Message-ID: <1293536237.10930.28.camel@linux-yu4c.site> On Tue, 2010-12-28 at 03:24 -0800, flebber wrote: > On Dec 28, 10:16 pm, Adam Tauno Williams > wrote: > > On Tue, 2010-12-28 at 02:26 -0800, flebber wrote: > > > Is pydev actively being developed and for who? SPE is a great idea but > > > is Stan still developing? Pyscripter is good but not 64 capable. Plus > > > none of these projects seem community centric. > > Why not just check the repo and see the real answer for yourself? It is > > Open Source after all. > > > Yes you can answer questions, but have you really? Your answer seems > to be things are open source so who cares about community. > > Many projects accept donations via PayPal. Sourceforge supports this. > Of course any fool can throw his/her money away thats no challenge why > even use Paypal, I could have fun and by 10 bottles of vino and hand > them out to recovering alcoholics. > Don't answer things just for the sake of it, if you have nothing > producive to say about furthering python and its community then say > that. I provided two concrete points, thank you: (1) Is a project actively developed? Look at the repo. That is the answer to the question [this isn't necessarily obvious to those new to Open Source]. (1.1.) "Is PyDev a potential unifying force amoung IDEs?" Which is the implied question - that is up to the OP and others who do/do-not contribute to it. (2) How can I donate cash? There is a fairly standard mechanism for that. Otherwise I think the OP's thoughts on "community" and how Open Source works are somewhat flawed. "Community" is a manifestation of people *doing* things; it does *not* arise out of people being concerned about things [since "doing" is quite apparently not a natural result of "concern". Concern is like watching TV. Doing is getting out of the chair.] From awilliam at whitemice.org Tue Dec 28 06:56:31 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Tue, 28 Dec 2010 06:56:31 -0500 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> <4D18FD43.6090900@yahoo.com> Message-ID: <1293537391.10930.42.camel@linux-yu4c.site> On Tue, 2010-12-28 at 07:08 +0100, Stefan Behnel wrote: > Roy Smith, 28.12.2010 00:21: > > To go back to my earlier example of > > FALSE > > using 432 bits to store 1 bit of information, stuff like that doesn't > > happen in marked-up text documents. Most of the file is CDATA (do they > > still use that term in XML, or was that an SGML-ism only?). The markup > > is a relatively small fraction of the data. I'm happy to pay a factor > > of 2 or 3 to get structured text that can be machine processed in useful > > ways. I'm not willing to pay a factor of 432 to get tabular data when > > there's plenty of other much more reasonable ways to encode it. > If the above only appears once in a large document, I don't care how much > space it takes. If it appears all over the place, it will compress down to > a couple of bits, so I don't care about the space, either. +1 > It's readability that counts here. Try to reverse engineer a binary format > that stores the above information in 1 bit. I think a point many of the arguments against XML miss is the HR cost of custom solutions. Every time you come up with a cool super-efficient solution it has to be weighed against the increase in the tool-stack [whereas XML is, essentially, built-in] and nobody-else-knows-about-your-super-cool-solution [1]. IMO, tool-stack bloat is a *big* problem in shops with an Open Source tendency. Always tossing the new and shiny thing [it's free!] into the bucket for some theoretical benefit. [This is an unrecognized benefit to expensive software - it creates focus]. Soon the bucket is huge and maintaining it becomes a burden. [1] The odds you sufficiently documented your super-cool-solution is probably nil. So I'm one of those you'd have to make a *really* good argument *not* to use XML. XML is known, the tools are good, the knotty problems are solved [thanks to the likes of SAX, lxml / ElementTree, and ElementFlow]. If the premise argument is "bloat" I'd probably dismiss it out of hand since removing that bloat will necessitate adding bloat somewhere else; that somewhere else almost certainly being more expensive. From flebber.crue at gmail.com Tue Dec 28 07:10:15 2010 From: flebber.crue at gmail.com (flebber) Date: Tue, 28 Dec 2010 04:10:15 -0800 (PST) Subject: Python - NAWIT / Community References: <2895ecca-b978-4899-9ab3-0032422b908f@o9g2000pre.googlegroups.com> <365bf58b-889b-4186-baff-72d78efe635f@21g2000prv.googlegroups.com> Message-ID: On Dec 28, 10:37?pm, Adam Tauno Williams wrote: > On Tue, 2010-12-28 at 03:24 -0800, flebber wrote: > > On Dec 28, 10:16 pm, Adam Tauno Williams > > wrote: > > > On Tue, 2010-12-28 at 02:26 -0800, flebber wrote: > > > > Is pydev actively being developed and for who? SPE is a great idea but > > > > is Stan still developing? Pyscripter is good but not 64 capable. Plus > > > > none of these projects seem community centric. > > > Why not just check the repo and see the real answer for yourself? ?It is > > > Open Source after all. > > > > > Yes you can answer questions, but have you really? Your answer seems > > to be things are open source so who cares about community. > > > Many projects accept donations via PayPal. ?Sourceforge supports this. > > Of course any fool can throw his/her money away thats no challenge why > > even use Paypal, I could have fun and by 10 bottles of vino and hand > > them out to recovering alcoholics. > > Don't answer things just for the sake of it, if you have nothing > > producive to say about furthering python and its community then say > > that. > > I provided two concrete points, thank you: > > (1) Is a project actively developed? ?Look at the repo. That is the > answer to the question [this isn't necessarily obvious to those new to > Open Source]. > (1.1.) "Is PyDev a potential unifying force amoung IDEs?" ?Which is the > implied question - that is up to the OP and others who do/do-not > contribute to it. > (2) How can I donate cash? There is a fairly standard mechanism for > that. > > Otherwise I think the OP's thoughts on "community" and how Open Source > works are somewhat flawed. ?"Community" is a manifestation of people > *doing* things; it does *not* arise out of people being concerned about > things [since "doing" is quite apparently not a natural result of > "concern". Concern is like watching TV. ?Doing is getting out of the > chair.] Fair point. You have mistaken somewhat what I intended, partly my fault due to the verbosity. I wanted gaugue feedback on others perception of the current status quo. I am happy personally currently, currently being the main word. "Community" is a manifestation of people > *doing* things; it does *not* arise out of people being concerned about > things But concern is derived from interaction and observation and like fear and joy tells us we need to take an action. If someone chooses to sir idly by good for them I haven't the time or inclination personally. Tony Robbins "Acheiving a goal is simple, decide what your goal is, set out towards it and consistently review whether you are getting closer or further from your goal and take action immediately." >From a language perspective going to python 3 this definitely seems to be occurring well and strongly lead. Sometimes the fault in open source is the lack of a crystalized and shared goal and proper infrastructure.....Gentoo as an example. Could get to they were going because they didn't share the same vision of what it was. I meant no attack by reviewing, just a somewhat newbies observations of python. From flebber.crue at gmail.com Tue Dec 28 07:12:56 2010 From: flebber.crue at gmail.com (flebber) Date: Tue, 28 Dec 2010 04:12:56 -0800 (PST) Subject: Python - NAWIT / Community References: <2895ecca-b978-4899-9ab3-0032422b908f@o9g2000pre.googlegroups.com> <365bf58b-889b-4186-baff-72d78efe635f@21g2000prv.googlegroups.com> Message-ID: On Dec 28, 11:10?pm, flebber wrote: > On Dec 28, 10:37?pm, Adam Tauno Williams > wrote: > > > > > On Tue, 2010-12-28 at 03:24 -0800, flebber wrote: > > > On Dec 28, 10:16 pm, Adam Tauno Williams > > > wrote: > > > > On Tue, 2010-12-28 at 02:26 -0800, flebber wrote: > > > > > Is pydev actively being developed and for who? SPE is a great idea but > > > > > is Stan still developing? Pyscripter is good but not 64 capable. Plus > > > > > none of these projects seem community centric. > > > > Why not just check the repo and see the real answer for yourself? ?It is > > > > Open Source after all. > > > > > > > Yes you can answer questions, but have you really? Your answer seems > > > to be things are open source so who cares about community. > > > > Many projects accept donations via PayPal. ?Sourceforge supports this. > > > Of course any fool can throw his/her money away thats no challenge why > > > even use Paypal, I could have fun and by 10 bottles of vino and hand > > > them out to recovering alcoholics. > > > Don't answer things just for the sake of it, if you have nothing > > > producive to say about furthering python and its community then say > > > that. > > > I provided two concrete points, thank you: > > > (1) Is a project actively developed? ?Look at the repo. That is the > > answer to the question [this isn't necessarily obvious to those new to > > Open Source]. > > (1.1.) "Is PyDev a potential unifying force amoung IDEs?" ?Which is the > > implied question - that is up to the OP and others who do/do-not > > contribute to it. > > (2) How can I donate cash? There is a fairly standard mechanism for > > that. > > > Otherwise I think the OP's thoughts on "community" and how Open Source > > works are somewhat flawed. ?"Community" is a manifestation of people > > *doing* things; it does *not* arise out of people being concerned about > > things [since "doing" is quite apparently not a natural result of > > "concern". Concern is like watching TV. ?Doing is getting out of the > > chair.] > > Fair point. > > You have mistaken somewhat what I intended, partly my fault due to the > verbosity. I wanted gaugue feedback on others perception of the > current status quo. I am happy personally currently, currently being > the main word. > > "Community" is a manifestation of people > > > *doing* things; it does *not* arise out of people being concerned about > > things > > But concern is derived from interaction and observation and like fear > and joy tells us we need to take an action. If someone chooses to sir > idly by good for them I haven't the time or inclination personally. > > Tony Robbins "Acheiving a goal is simple, decide what your goal is, > set out towards it and consistently review whether you are getting > closer or further from your goal and take action immediately." > > From a language perspective going to python 3 this definitely seems to > be occurring well and strongly lead. > > Sometimes the fault in open source is the lack of a crystalized and > shared goal and proper infrastructure.....Gentoo as an example. Could > get to they were going because they didn't share the same vision of > what it was. > > I meant no attack by reviewing, just a somewhat newbies observations > of python. Edit Gentoo couldn't get to where they were going because of lack of vision and a shared goal. From doomster at knuut.de Tue Dec 28 07:42:39 2010 From: doomster at knuut.de (Ulrich Eckhardt) Date: Tue, 28 Dec 2010 13:42:39 +0100 Subject: Interning own classes like strings for speed and size? References: <8nra78Foh3U1@mid.uni-berlin.de> <4d19203f$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8nu4a2Fp63U1@mid.uni-berlin.de> Steven D'Aprano wrote: >>>> class InternedTuple(tuple): > ... _cache = {} > ... def __new__(cls, *args): > ... t = super().__new__(cls, *args) > ... return cls._cache.setdefault(t, t) That looks good. The only thing that first bothered me is that it creates an object and then possibly discards it again. However, there is no way around that, since at least the key to the dict must be created for lookup. Since key and value are the same here, this is even for free. What I also found was that with the above, I can't provide __eq__ and __ne__ that just check for identity. If I do, the lookup in setdefault() will never find an existing tuple and I will never save memory for a single object. Thanks! Uli From steve+comp.lang.python at pearwood.info Tue Dec 28 07:43:43 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Dec 2010 12:43:43 GMT Subject: Python - NAWIT / Community References: <2895ecca-b978-4899-9ab3-0032422b908f@o9g2000pre.googlegroups.com> <365bf58b-889b-4186-baff-72d78efe635f@21g2000prv.googlegroups.com> Message-ID: <4d19db7f$0$29993$c3e8da3$5496439d@news.astraweb.com> On Tue, 28 Dec 2010 04:10:15 -0800, flebber wrote: > Tony Robbins "Acheiving a goal is simple, decide what your goal is, set > out towards it and consistently review whether you are getting closer or > further from your goal and take action immediately." Writing bug-free code is simple: decide what you want your code to do, write code to do it, and consistently review whether you are getting more or fewer bugs, and take action immediately. -- Steven From bc at freeuk.com Tue Dec 28 07:56:46 2010 From: bc at freeuk.com (BartC) Date: Tue, 28 Dec 2010 12:56:46 -0000 Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> <4D18FD43.6090900@yahoo.com> Message-ID: "Stefan Behnel" wrote in message news:mailman.335.1293516506.6505.python-list at python.org... > Roy Smith, 28.12.2010 00:21: >> To go back to my earlier example of >> >> FALSE >> >> using 432 bits to store 1 bit of information, stuff like that doesn't >> happen in marked-up text documents. Most of the file is CDATA (do they >> still use that term in XML, or was that an SGML-ism only?). The markup >> is a relatively small fraction of the data. I'm happy to pay a factor >> of 2 or 3 to get structured text that can be machine processed in useful >> ways. I'm not willing to pay a factor of 432 to get tabular data when >> there's plenty of other much more reasonable ways to encode it. > > If the above only appears once in a large document, I don't care how much > space it takes. If it appears all over the place, it will compress down to > a couple of bits, so I don't care about the space, either. > > It's readability that counts here. Try to reverse engineer a binary format > that stores the above information in 1 bit. The above typically won't get much below 2 bytes (as one character plus a separator, eg. in comma-delimited-format). So it's more like 27:1, if you're going to stay with a text format. Still, that's 27 times as much as it need be. Readability is fine, but why does the full, expanded, human-readable textual format have to be stored on disk too, and for every single instance? What if the 'Parental-Advisory' tag was even longer? Just how long do these things have to get before even the advocates here admit that it's getting ridiculous? Isn't it possible for XML to define a shorter alias for these tags? Isn't there a shortcut available for in simple examples like this (I seem to remember something like this)? And why not use 1 and 0 for TRUE and FALSE? Even the consumer appliances in my house have 1 and 0 on their power switches! With the advantage that they are internationally recognised. -- Bartc From krishna1344 at gmail.com Tue Dec 28 07:57:42 2010 From: krishna1344 at gmail.com (krishna kumar) Date: Tue, 28 Dec 2010 07:57:42 -0500 Subject: etl tool!!!!! Message-ID: Is there any efficient etl tool developed in python? -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan.sonnenberg at pythonmeister.com Tue Dec 28 08:14:33 2010 From: stefan.sonnenberg at pythonmeister.com (Stefan Sonnenberg-Carstens) Date: Tue, 28 Dec 2010 14:14:33 +0100 Subject: etl tool!!!!! In-Reply-To: References: Message-ID: <4D19E2B9.3080204@pythonmeister.com> Am 28.12.2010 13:57, schrieb krishna kumar: > Is there any efficient etl tool developed in python? Yes, Python. From awilliam at whitemice.org Tue Dec 28 08:19:04 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Tue, 28 Dec 2010 08:19:04 -0500 Subject: etl tool!!!!! In-Reply-To: References: Message-ID: <1293542344.4080.1.camel@linux-yu4c.site> On Tue, 2010-12-28 at 07:57 -0500, krishna kumar wrote: > Is there any efficient etl tool developed in python? What does "efficient" mean to you? I work on a Python workflow solution that I use to do ETL. -- Adam Tauno Williams LPIC-1, Novell CLA OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba From stef.mientki at gmail.com Tue Dec 28 08:34:19 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 28 Dec 2010 14:34:19 +0100 Subject: NameError: global name 'btn_Matlab' is not defined ? Message-ID: <4D19E75B.1010607@gmail.com> hello, Never seen this before and I've no explanation whatsoever (Python 2.6) I've some dynamic generated code, one of objects generated is a wx.Button, called 'btn_Matlab'. After the code is generated, I can see that the button is created in the local namespace print locals()['btn_Matlab'] > but if I try to print the button (at exactly the same location), I get an error print btn_Matlab NameError: global name 'btn_Matlab' is not defined ? Why isn't the compiler first checking the local namespace ? any clues ? thanks, Stef Mientki From steve+comp.lang.python at pearwood.info Tue Dec 28 09:11:56 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Dec 2010 14:11:56 GMT Subject: Interning own classes like strings for speed and size? References: <8nra78Foh3U1@mid.uni-berlin.de> <4d19203f$0$29993$c3e8da3$5496439d@news.astraweb.com> <8nu4a2Fp63U1@mid.uni-berlin.de> Message-ID: <4d19f02c$0$29993$c3e8da3$5496439d@news.astraweb.com> On Tue, 28 Dec 2010 13:42:39 +0100, Ulrich Eckhardt wrote: > Steven D'Aprano wrote: >>>>> class InternedTuple(tuple): >> ... _cache = {} >> ... def __new__(cls, *args): >> ... t = super().__new__(cls, *args) >> ... return cls._cache.setdefault(t, t) > > That looks good. The only thing that first bothered me is that it > creates an object and then possibly discards it again. However, there is > no way around that, since at least the key to the dict must be created > for lookup. Since key and value are the same here, this is even for > free. > > What I also found was that with the above, I can't provide __eq__ and > __ne__ that just check for identity. If I do, the lookup in setdefault() > will never find an existing tuple and I will never save memory for a > single object. If all you want is to save memory, you don't need to change the __eq__ method. But if you still want to, try this: # Untested class InternedTuple(tuple): _cache = {} def __new__(cls, *args): t = super().__new__(cls, *args) return cls._cache.setdefault(args, t) def __eq__(self, other): return self is other def __ne__(self, other): return self is not other -- Steven From steve+comp.lang.python at pearwood.info Tue Dec 28 09:15:41 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Dec 2010 14:15:41 GMT Subject: NameError: global name 'btn_Matlab' is not defined ? References: Message-ID: <4d19f10d$0$29993$c3e8da3$5496439d@news.astraweb.com> On Tue, 28 Dec 2010 14:34:19 +0100, Stef Mientki wrote: > hello, > > Never seen this before and I've no explanation whatsoever (Python 2.6) > > I've some dynamic generated code, > one of objects generated is a wx.Button, called 'btn_Matlab'. How do you generate the code? What code is generated? What does it do? > After the code is generated, I can see that the button is created in the > local namespace > > print locals()['btn_Matlab'] > > 0x3602d28> > > > but if I try to print the button (at exactly the same location), I get > an error > > print btn_Matlab > > NameError: global name 'btn_Matlab' is not defined ? > > Why isn't the compiler first checking the local namespace ? any clues ? My guess is that you've declared btn_Matlab as global, and then dynamically created a local with the same name using exec or similar. -- Steven From stefan_ml at behnel.de Tue Dec 28 09:39:32 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 28 Dec 2010 15:39:32 +0100 Subject: Interning own classes like strings for speed and size? In-Reply-To: <4d19f02c$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <8nra78Foh3U1@mid.uni-berlin.de> <4d19203f$0$29993$c3e8da3$5496439d@news.astraweb.com> <8nu4a2Fp63U1@mid.uni-berlin.de> <4d19f02c$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano, 28.12.2010 15:11: > On Tue, 28 Dec 2010 13:42:39 +0100, Ulrich Eckhardt wrote: > >> Steven D'Aprano wrote: >>>>>> class InternedTuple(tuple): >>> ... _cache = {} >>> ... def __new__(cls, *args): >>> ... t = super().__new__(cls, *args) >>> ... return cls._cache.setdefault(t, t) >> >> That looks good. The only thing that first bothered me is that it >> creates an object and then possibly discards it again. However, there is >> no way around that, since at least the key to the dict must be created >> for lookup. Since key and value are the same here, this is even for >> free. >> >> What I also found was that with the above, I can't provide __eq__ and >> __ne__ that just check for identity. If I do, the lookup in setdefault() >> will never find an existing tuple and I will never save memory for a >> single object. > > If all you want is to save memory, you don't need to change the __eq__ > method. But if you still want to, try this: > > # Untested Yep, that' the problem. ;) > class InternedTuple(tuple): > _cache = {} > def __new__(cls, *args): > t = super().__new__(cls, *args) > return cls._cache.setdefault(args, t) > def __eq__(self, other): > return self is other > def __ne__(self, other): > return self is not other What Ulrich meant, was: doing this will actually kill the caching, because the first time the comparison is called is when looking up the tuple while adding it to the interning dict. Since the new tuple is, well, new, it will not be equal (read: identical) to any cached tuple, thus resulting in a new entry regardless of its content. Stefan From lists at cheimes.de Tue Dec 28 09:46:25 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 28 Dec 2010 15:46:25 +0100 Subject: Interning own classes like strings for speed and size? In-Reply-To: <4d19f02c$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <8nra78Foh3U1@mid.uni-berlin.de> <4d19203f$0$29993$c3e8da3$5496439d@news.astraweb.com> <8nu4a2Fp63U1@mid.uni-berlin.de> <4d19f02c$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 28.12.2010 15:11, schrieb Steven D'Aprano: > # Untested > class InternedTuple(tuple): > _cache = {} > def __new__(cls, *args): > t = super().__new__(cls, *args) > return cls._cache.setdefault(args, t) > def __eq__(self, other): > return self is other > def __ne__(self, other): > return self is not other The code doesn't work, you have to change super().__new__(cls, *args) to super().__new__(cls, args). Don't ask me why. I'm surprised, too. >>> InternedTuple(1) Traceback (most recent call last): File "", line 1, in File "", line 4, in __new__ TypeError: 'int' object is not iterable Also this code is going to use much more memory than an ordinary tuple since every instance of InternedTuple has a __dict__ attribute. This code works but I had to move the cache outside the class because of __slots__. _ituple_cache = {} class ituple(tuple): __slots__ = () # no __dict__ def __new__(cls, *args): cached = _ituple_cache.get(args) if cached is not None: return cached self = _ituple_cache[args] = super(ituple, cls).__new__(cls, args) return self From nat.abbotts at gmail.com Tue Dec 28 09:59:29 2010 From: nat.abbotts at gmail.com (Nathanael Abbotts) Date: Tue, 28 Dec 2010 06:59:29 -0800 (PST) Subject: Replacing Greenlets with Threads or Processes Message-ID: <5b003652-8bd6-4136-ba47-864efefa55bc@glegroupsg2000goo.googlegroups.com> I need to replace the use of 'greenlets' in an application with threads or processes, but as I've never used greenlets, I don't know where to start when replacing them. Could anyone explain to me how I can do this? From fal at togliquesto.fastwebnet.it Tue Dec 28 10:00:37 2010 From: fal at togliquesto.fastwebnet.it (Francesco) Date: Tue, 28 Dec 2010 16:00:37 +0100 Subject: while True or while 1 In-Reply-To: <4d0ab65f$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <4D051506.2060403@holdenweb.com> <4d0ab65f$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: hehehehehehe... On 17/12/2010 2.01, Steven D'Aprano wrote: > On Thu, 16 Dec 2010 23:34:21 +0000, BartC wrote: > >> In terms of a more realistic function (admittedly still a little >> contrived, as the loop would be written differently), I tried this: >> >> def p2(n): >> p=1 >> while True: >> if n<=p: return p >> p<<=1 >> return 0 >> >> for i in xrange(1000000): >> x=p2(i) >> >> p2() calculates the smallest power of 2>= it's operand. >> >> Using while True as shown, it took 3.4 seconds. Using While 1, it took >> 2.6 seconds (Python 2.5). > > > Right. And a saving of 0.8 microseconds per iteration is a micro- > optimization which is likely to be invisible in any real situation. > > I mean, yes, you saved almost an entire second. Wow. Save another 179 of > them and you'll almost have enough time to make yourself a coffee. > > Bart, we get it. Nobody denies that the optimization is real, only that > it is generally meaningful. Who cares whether it takes 2 seconds or 4 > seconds to generate one million results if the rest of the application > takes 3 minutes to run? > > *If* your application is such that saving 0.8 microseconds per iteration > actually is useful, AND your loop has to be written as a while True loop, > then this *may* be a useful micro-optimization to save 0.8 microseconds > per iteration. That's a vanishingly tiny proportion of all code written. > If your code happens to meet those conditions, then by all means use > "while 1". Or move to Python 3, where "while True" has the same > optimization performed. > > But in general, such micro-optimizations are not terribly useful. If you > shave off 1 second off a program that runs in 3 seconds, chances are > nobody is even going to notice. Two seconds or three, who cares? Either > way, it's too short to do anything else, and not long enough to matter. > If you shave off an hour off a program that takes 20 hours, who is going > to care? > > But so long as it doesn't introduce bugs, or make maintenance harder, or > add complexity, such micro-optimizations don't harm either. > HEY! That was MY argument! ;-)) Newsgroups: comp.lang.python Subject: Re: If/then style question Date: Tue, 21 Dec 2010 20:54:02 +0100 I'd bet you would stress your point Steven! But you don't need to persuade me, I do already agree. I just meant to say that, when the advantage is little, there's no need to rewrite a working function. And that with modern CPUs, if tests take so little time, that even some redundant one is not so much of a nuisance. in your working example, the "payload" is just a couple of integer calculations, that take very little time too. So the overhead due to redundant if tests does show clearly. And also in that not-really-real situation, 60% overhead just meant less than 3 seconds. Just for the sake of discussion, I tried to give both functions some plough to pull, and a worst-case situation too: >>> t1 = Timer('for x in range(100): print func1(0),', ... 'from __main__ import func1') >>> >>> t2 = Timer('for x in range(100): print func2(0),', ... 'from __main__ import func2') >>> >>> min(t1.repeat(number=1, repeat=1)) -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 53.011015366479114 >>> min(t2.repeat(number=1, repeat=1)) -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 47.55442856564332 that accounts for a scant 11% overhead, on more than one million tests per cycle. That said, let's make really clear that I would heartily prefer func2 to func1, based both on readability and speed. Thank you for having spent some time playing with me! Francesco On 19/12/2010 1.05, Steven D'Aprano wrote: > Well, let's try it with a working (albeit contrived) example. This is > just an example -- obviously I wouldn't write the function like this in > real life, I'd use a while loop, but to illustrate the issue it will do. > > def func1(n): > result = -1 > done = False > n = (n+1)//2 > if n%2 == 1: > result = n > done = True > if not done: > n = (n+1)//2 > if n%2 == 1: > result = n > done = True > if not done: > n = (n+1)//2 > if n%2 == 1: > result = n > done = True > if not done: > for i in range(1000000): > if not done: > n = (n+1)//2 > if n%2 == 1: > result = n > done = True > return result > > > def func2(n): > n = (n+1)//2 > if n%2 == 1: > return n > n = (n+1)//2 > if n%2 == 1: > return n > n = (n+1)//2 > if n%2 == 1: > return n > for i in range(1000000): > n = (n+1)//2 > if n%2 == 1: > return n > return -1 > > > Not only is the second far more readable that the first, but it's also > significantly faster: > >>>> from timeit import Timer >>>> t1 = Timer('for i in range(20): x = func1(i)', > ... 'from __main__ import func1') >>>> t2 = Timer('for i in range(20): x = func2(i)', > ... 'from __main__ import func2') >>>> min(t1.repeat(number=10, repeat=5)) > 7.3219029903411865 >>>> min(t2.repeat(number=10, repeat=5)) > 4.530779838562012 > > The first function does approximately 60% more work than the first, all > of it unnecessary overhead. From phanindracharya at gmail.com Tue Dec 28 10:20:57 2010 From: phanindracharya at gmail.com (phani indra) Date: Tue, 28 Dec 2010 07:20:57 -0800 Subject: hi Message-ID: -------------- next part -------------- An HTML attachment was scrubbed... URL: From sherm.pendley at gmail.com Tue Dec 28 10:29:43 2010 From: sherm.pendley at gmail.com (Sherm Pendley) Date: Tue, 28 Dec 2010 10:29:43 -0500 Subject: Trying to parse a HUGE(1gb) xml file References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> <4D18FD43.6090900@yahoo.com> Message-ID: "BartC" writes: >> Roy Smith, 28.12.2010 00:21: >>> To go back to my earlier example of >>> >>> FALSE >>> > > Isn't it possible for XML to define a shorter alias for these tags? Isn't > there a shortcut available for in simple examples like > this (I seem to remember something like this)? Yes, you can define your own entities in a DTD: FALSE"> TRUE"> Later, in your document: &paf; &pat; Although, this is a bit of a contrived example - if space is such a major concern, one wouldn't be so wasteful of it to begin with, but might instead use a short tag form whose value attribute defaults to "FALSE". Later, in your document: To save even more space, one could instead define a "pa" attribute as part of the "movie" element, with a default value that would then take no space at all: Later, in your document: When you see someone doing stupid things with a tool, it's usually not the tool's fault. Far more often, it's someone using the wrong tool for the task at hand, or using the right tool the wrong way. > And why not use 1 and 0 for TRUE and FALSE? Sounds reasonable in general, although a parental advisory would more often be a range of possible values (G, PG, R, MA, etc.) rather than a boolean. sherm-- -- Sherm Pendley Cocoa Developer From emile at fenx.com Tue Dec 28 10:32:45 2010 From: emile at fenx.com (Emile van Sebille) Date: Tue, 28 Dec 2010 07:32:45 -0800 Subject: Replacing Greenlets with Threads or Processes In-Reply-To: <5b003652-8bd6-4136-ba47-864efefa55bc@glegroupsg2000goo.googlegroups.com> References: <5b003652-8bd6-4136-ba47-864efefa55bc@glegroupsg2000goo.googlegroups.com> Message-ID: On 12/28/2010 6:59 AM Nathanael Abbotts said... > I need to replace the use of 'greenlets' in an application with threads or processes, but as I've never used greenlets, I don't know where to start when replacing them. > Could anyone explain to me how I can do this? Looks like your choice may be limited to processes... http://groups.google.com/group/pycsp/browse_thread/thread/45209957e27e0293/b67445b092872750?q=python+greenlets Emile From nat.abbotts at gmail.com Tue Dec 28 10:58:23 2010 From: nat.abbotts at gmail.com (Nathanael Abbotts) Date: Tue, 28 Dec 2010 07:58:23 -0800 (PST) Subject: Replacing Greenlets with Threads or Processes In-Reply-To: Message-ID: <1543cad4-92c6-4693-8758-6e2d278a0107@glegroupsg2000goo.googlegroups.com> Processes are better for me - the application is already multiprocessing based. From nat.abbotts at gmail.com Tue Dec 28 10:58:23 2010 From: nat.abbotts at gmail.com (Nathanael Abbotts) Date: Tue, 28 Dec 2010 07:58:23 -0800 (PST) Subject: Replacing Greenlets with Threads or Processes In-Reply-To: Message-ID: <1543cad4-92c6-4693-8758-6e2d278a0107@glegroupsg2000goo.googlegroups.com> Processes are better for me - the application is already multiprocessing based. From roy at panix.com Tue Dec 28 11:02:59 2010 From: roy at panix.com (Roy Smith) Date: Tue, 28 Dec 2010 11:02:59 -0500 Subject: Trying to parse a HUGE(1gb) xml file References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> <4D13C04E.6070103@pythonmeister.com> if5455$s3o$1@dooooooooooooooo ailman.285.1293397695.6505.pythhn-list@python.oooo 4412925122010@nnnnnnnnnnnnnnn an.2010.12.25.22.33.55.172000@nnnnnnnnnnnn dh$eul$1@sperannnnnnnnnnnnn lman.295.1293355338.6505.pythonnlist@python.orgg peranza.aioe.orrr 293356689.6505..ython-list@pythhhhhhhh td$1@speranza.aaaaaaaaa Message-ID: In article , "BartC" wrote: > Still, that's 27 times as much as it need be. Readability is fine, but why > does the full, expanded, human-readable textual format have to be stored on > disk too, and for every single instance? Well, I know the answer to that one. The particular XML feed I'm working with is a dump from an SQL database. The element names in the XML are exactly the same as the column names in the SQL database. The difference being that in the database, the string "Parental-Advisory" appears in exactly one place, in some schema metadata table. In the XML, it appears (doubled!) once per row. It's still obscene. That fact that I understand the cause of the obscenity doesn't make it any less so. Another problem with XML is that some people don't use real XML tools to write their XML files. DTD? What's that? So you end up with tag soup that the real XML tools can't parse on the other end. From nat.abbotts at gmail.com Tue Dec 28 11:07:50 2010 From: nat.abbotts at gmail.com (Nathanael Abbotts) Date: Tue, 28 Dec 2010 08:07:50 -0800 (PST) Subject: Replacing Greenlets with Threads or Processes In-Reply-To: <1543cad4-92c6-4693-8758-6e2d278a0107@glegroupsg2000goo.googlegroups.com> Message-ID: <2bb26924-bb0b-4167-a7dd-f49c8241fafc@glegroupsg2000goo.googlegroups.com> That thread seems to deal with mixing them. I want to replace them completely - is that possible (with either threads or processes)? Some loss of functionality isn't a problem, as the code only seems to use the most basic features of Greenlets. From nat.abbotts at gmail.com Tue Dec 28 11:07:50 2010 From: nat.abbotts at gmail.com (Nathanael Abbotts) Date: Tue, 28 Dec 2010 08:07:50 -0800 (PST) Subject: Replacing Greenlets with Threads or Processes In-Reply-To: <1543cad4-92c6-4693-8758-6e2d278a0107@glegroupsg2000goo.googlegroups.com> Message-ID: <2bb26924-bb0b-4167-a7dd-f49c8241fafc@glegroupsg2000goo.googlegroups.com> That thread seems to deal with mixing them. I want to replace them completely - is that possible (with either threads or processes)? Some loss of functionality isn't a problem, as the code only seems to use the most basic features of Greenlets. From nagle at animats.com Tue Dec 28 11:39:12 2010 From: nagle at animats.com (John Nagle) Date: Tue, 28 Dec 2010 08:39:12 -0800 Subject: mutiprocessing, manager, list & threading ? In-Reply-To: References: Message-ID: <4d1a12ae$0$44060$742ec2ed@news.sonic.net> On 12/28/2010 1:38 AM, mika.saari at wipsl.com wrote: > Hi, > > Testing if I could be able to use multiprocessing BaseManager to manage > list of instance pointers between processes. If my intance inherits > Thread, I get pickling error about _thread.lock. The "multiprocessing" module works by running completely separate programs which communicate by copying data back and forth through pipes or sockets. You can't share thread locks. (There's a gimmick that lets you put an array of fixed type and size in shared memory, but that's very limited, because Python's locking doesn't really understand multiprocessing.) If you need to access a list from several processes, have one process own the list, and use a Manager from the multiprocessing module to create a proxy to access the list from the other processes. Note that this is slower than regular list access. But if you just need to have a to-do list that feeds multiple processes, that's a way to do it. John Nagle From emile at fenx.com Tue Dec 28 12:04:48 2010 From: emile at fenx.com (Emile van Sebille) Date: Tue, 28 Dec 2010 09:04:48 -0800 Subject: Replacing Greenlets with Threads or Processes In-Reply-To: <2bb26924-bb0b-4167-a7dd-f49c8241fafc@glegroupsg2000goo.googlegroups.com> References: <1543cad4-92c6-4693-8758-6e2d278a0107@glegroupsg2000goo.googlegroups.com> <2bb26924-bb0b-4167-a7dd-f49c8241fafc@glegroupsg2000goo.googlegroups.com> Message-ID: On 12/28/2010 8:07 AM Nathanael Abbotts said... > That thread seems to deal with mixing them. I want to replace them > completely - is that possible (with either threads or processes)? Are you working with pycsp? the info at http://code.google.com/p/pycsp/wiki/Getting_Started_With_PyCSP says: "The API is implemented in four versions: Threads, processes, greenlets and net. All implementations share an almost identical API making it trivial to switch from one implementation to another. " Emile From python at bdurham.com Tue Dec 28 14:08:45 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 28 Dec 2010 14:08:45 -0500 Subject: How to programmatically exit from wsgi's serve_forever() loop In-Reply-To: References: <1293498347.25483.1412453811@webmail.messagingengine.com> Message-ID: <1293563325.22535.1412552623@webmail.messagingengine.com> Hi Ian, You are correct - I missed the following 2 nuances: # need to set poll_interval in order to recognize shutdown request httpd.serve_forever(poll_interval=0.5) # shutdown request must be initiated from ANOTHER thread or will block import threading threading.Thread(target=httpd.shutdown).start() Thank you for your help - really appreciated! Malcolm From anurag.chourasia at gmail.com Tue Dec 28 14:19:41 2010 From: anurag.chourasia at gmail.com (Anurag Chourasia) Date: Wed, 29 Dec 2010 00:49:41 +0530 Subject: Digitally Signing a XML Document (using SHA1+RSA or SHA1+DSA) In-Reply-To: <1293498360.10930.4.camel@linux-yu4c.site> References: <1293498360.10930.4.camel@linux-yu4c.site> Message-ID: Dear all, I am required to use the Private Key from that XML below to generate a digital signature. The public key can then be used to validate the generated signature. http://stuvel.eu/rsa does not support PKCS#1 and hence I am required to look for alternates. Please let me know if there is something else out there that could help meet my requirement. Regards, Anurag On Tue, Dec 28, 2010 at 6:36 AM, Adam Tauno Williams wrote: > On Tue, 2010-12-28 at 03:25 +0530, Anurag Chourasia wrote: > > Hi All, > > > I have a requirement to digitally sign a XML Document using SHA1+RSA > > or SHA1+DSA > > Could someone give me a lead on a library that I can use to fulfill > > this requirement? > > Never used it though. > > > The XML Document has values such as > > -----BEGIN RSA PRIVATE KEY----- > > MIIBOgIBAAJBANWzHfF5Bppe4JKlfZDqFUpNLrwNQqguw76g/jmeO6f4i31rDLVQ > > n7sYilu65C8vN+qnEGnPB824t/A3yfMu1G0CAQMCQQCOd2lLpgRm6esMblO18WOG > > 3h8oCNcaydfUa1QmaX0apHlDFnI7UDXpYaHp2VL9gvtSJT5L3ZASMzxRPXJSvzcT > > AiEA/16jQh18BAD4q3yk1gKw19I8OuJOYAxFYX9noCEFWUMCIQDWOiYfPtxK3A1s > > AFARsDnnHTL4FbRPpiZ79vP+VgqojwIhAKo/F4Fo/VgApceobeQByzqMKCdBiZVd > > g5ZU78AWA5DXAiEAjtFuv389hz1eSAA1YSAmmhN3UA54NRlu/U9NVDlccF8CIBkc > > Z52oGxy/skwVwI5TBcB1YqXJTT47/6/hTAVMTwaA -----END RSA PRIVATE > > KEY----- > > -----BEGIN PUBLIC KEY----- > > MFowDQYJKoZIhvcNAQEBBQADSQAwRgJBANWzHfF5Bppe4JKlfZDqFUpNLrwNQqgu > > w76g/jmeO6f4i31rDLVQn7sYilu65C8vN+qnEGnPB824t/A3yfMu1G0CAQM= -----END > > PUBLIC KEY----- > > Is this any kind of standard or just something someone made up? Is > there a namespace for the document? > > It seems quite odd that the document contains a *private* key. > > If all you need to do is parse to document to retrieve the values that > seems straight-forward enough. > > > And the XML also has another node that has a Public Key with Modules > > and Exponents etc that I apparently need to utilize. > > > > 1bMd8XkGml7gkqV9kOoVSk0uvA1CqC7DvqD > > +OZ47p/iLfWsMtVCfuxiKW7rkLy836qcQac8Hzbi38DfJ8y7UbQ== > > Aw== > > > > > I am a little thin on this concept and expecting if you could guide me > > to a library/documentation that I could utilize. > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nagle at animats.com Tue Dec 28 14:23:17 2010 From: nagle at animats.com (John Nagle) Date: Tue, 28 Dec 2010 11:23:17 -0800 Subject: Interning own classes like strings for speed and size? In-Reply-To: <8nra78Foh3U1@mid.uni-berlin.de> References: <8nra78Foh3U1@mid.uni-berlin.de> Message-ID: <4d1a3923$0$43992$742ec2ed@news.sonic.net> On 12/27/2010 3:05 AM, Ulrich Eckhardt wrote: > Hi! > > I'm trying to solve a computational problem and of course speed and size is > important there. Then you probably shouldn't be using CPython. > Apart from picking the right algorithm, I came across an > idea that could help speed up things and keep memory requirements down. What > I have is regions described by min and max coordinates. At first, I just > modeled these as a simple class containing two values for each axis. There are more effective techniques for that. In game physics collision detection systems, it's common to use axis-ordered lists of bounding boxes to partition objects. This still works even when the ranges overlap. Look up "I-Collide" for a classic implementation. > Am I looking in the wrong direction? Is there some better approach? > Please > don't tell me to use C, as I'm specifically interested in > learning Python, > I'm pretty sure I could have solved the problem quickly in > C++ otherwise. CPython is a naive interpreter which does dictionary lookups for every variable and attribute access. If you're doing fast manipulation of linked data structures in CPython, performance is going to suck. Check out Shed Skin 0.7, which is a much faster Python system. It's limited, but for the kind of data structure work you're doing, all the features you should need already work. John Nagle > > In a second step, I derived this class from tuple instead of object. Some > code then moved from __init__ to __new__ and some code that modified these > objects had to be changed to replace them instead. The upside to this is > that they can be used as keys in sets and dicts, which isn't the case for > mutable types[1]. > > What I'm now considering is to only allow a single instance of these objects > for each set of values, similar to interned strings. What I would gain is > that I could safely compare objects for identity instead of equality. What > I'm not yet sure is how much overhead that would give me and/or how to keep > it low. The idea is to store each instance in a set and after creating a new > object I would first look up an equal object in the global set and return > that instead, otherwise add the new one. > > The problem I foresee is that if I define equality as identity, this lookup > when creating will never eliminate duplicates. If I only fall back to > equality comparison for non-identical objects, I would probably sacrifice > most of the gain. If I build a dict mapping between the values and the > actual objects, I would have doubled the required memory and uselessly store > the same values twice there. > > > Cheers! > > Uli > > > [1] Somebody correct me if I'm wrong, but I believe I could have defined a > hashing function for the type and thus allowed its use in a set or dict, > right? However, goofing up because you accidentally modified an object and > changed its hash value is something I don't want to risk anyway. > From ja at sdf.lonestar.org Tue Dec 28 15:07:29 2010 From: ja at sdf.lonestar.org (J. Altman) Date: Tue, 28 Dec 2010 20:07:29 +0000 (UTC) Subject: O'Reilly Python Certification References: <4D0900D3.10000@stoneleaf.us> <4D0927C1.5080209@tim.thechases.com> <4D093176.3010109@pythonmeister.com> <4D0A3306.3090100@stoneleaf.us> Message-ID: On 2010-12-16, Steve Holden wrote: > Each lesson required you to complete a practical assignment. You submit > these assignments for evaluation, and do not proceed to the next lesson > until your assignment reaches a satisfactory standard. Thus, less > experienced students will tend to have more interaction with their tutors. > > A class will typically have between twelve and sixteen lessons. There > are also quizzes and a final practical project. > > regards > Steve I have a general question. Does it seem odd that a certificate in Python, an Open Source language; taught at O'Reilly, which offers an Open Source Programming Certificate and is something like waist-deep in Open Source publishing; is offered to the world at large but only (IIUC) if one runs some version of Windows by MS? Based on what I am given to understand from my correspondence with OST, it seems that I *must* install an instance of Windows to take the certificate's courses. Not that I particularly want to bash MS, but I am running FreeBSD, and have Python 2.x and 3.x installed; I can call either IDE; and I am competent at the shell, I think sufficiently, to manage coding at the shell. Is it normal for people in CS courses at the University and/or certificate level to learn a given language under Windows? Or is it just me who thinks it odd that an OS like FreeBSD won't (apparently, I stress) work with the O'Reilly Sandbox? From hniksic at xemacs.org Tue Dec 28 15:16:51 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Tue, 28 Dec 2010 21:16:51 +0100 Subject: Interning own classes like strings for speed and size? References: <8nra78Foh3U1@mid.uni-berlin.de> <4d19203f$0$29993$c3e8da3$5496439d@news.astraweb.com> <8nu4a2Fp63U1@mid.uni-berlin.de> <4d19f02c$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <878vz9d558.fsf@xemacs.org> Christian Heimes writes: > Also this code is going to use much more memory than an ordinary tuple > since every instance of InternedTuple has a __dict__ attribute. This > code works but I had to move the cache outside the class because of > __slots__. Wouldn't it work inside the class as well? __slots__ applies to instances, not to classes themselves. In Python 3.1: >>> class Foo(tuple): ... __slots__ = () ... _cache = {} ... >>> Foo._cache # works as expected {} >>> Foo()._cache # and so does this {} From martin at v.loewis.de Tue Dec 28 16:47:06 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Tue, 28 Dec 2010 22:47:06 +0100 Subject: round in 2.6 and 2.7 In-Reply-To: <5f07e3a7-5f13-4ca0-bcde-75a916ac9210@r29g2000yqj.googlegroups.com> References: <87sjxoco6u.fsf@xemacs.org> <5f07e3a7-5f13-4ca0-bcde-75a916ac9210@r29g2000yqj.googlegroups.com> Message-ID: <4D1A5ADA.5040500@v.loewis.de> >> "Float-to-string and string-to-float conversions are correctly rounded. >> The round() function is also now correctly rounded." >> >> Not sure that this is correct English; I think it means that the >> round() function is now correct. > > Well, the correct result of the example the OP gave would be 9.9 > exactly. But since 9.9 isn't exactly representable as a Python float, > we necessarily get an approximation. The language above is intended > to convey that it's the 'correctly rounded' approximation I see. Shouldn't it say then "The round() function gives/produces/returns correctly rounded results now", instead of saying that the round function *is* correctly rounded? ISTM that the round function cannot be rounded (correctly or not): py> round(round) Traceback (most recent call last): File "", line 1, in TypeError: a float is required But then, I'm not a native speaker (of English). Regards, Martin From miki.tebeka at gmail.com Tue Dec 28 16:59:36 2010 From: miki.tebeka at gmail.com (Miki) Date: Tue, 28 Dec 2010 13:59:36 -0800 (PST) Subject: Keeping track of the N largest values In-Reply-To: Message-ID: > I'm processing a stream of N numbers and want to keep track of the K > largest. There's too many numbers in the stream (i.e. N is too large) > to keep in memory at once. K is small (100 would be typical). > ... deque can be bounded by maxsize, might fit the bill: >>> from collections import deque >>> d = deque([], 3) >>> for i in range(10): d.append(i) >>> d deque([7, 8, 9], maxlen=3) >>> HTH, -- Miki From katie at coderstack.co.uk Tue Dec 28 17:28:42 2010 From: katie at coderstack.co.uk (Katie T) Date: Tue, 28 Dec 2010 22:28:42 +0000 Subject: Language Detection Library/Code In-Reply-To: References: Message-ID: On Tue, Dec 28, 2010 at 12:42 AM, Shashwat Anand wrote: > Regarding dictionary lookup+n-gram approach I didn't quite understand what > you wanted to say. Run through trigram analysis first, if it identified multiple languages as being matches within the error margin then split the text into words, and look up each word in the respective dictionaries to get a second opinion. Katie -- CoderStack http://www.coderstack.co.uk/python-jobs The Software Developer Job Board From nat.abbotts at gmail.com Tue Dec 28 17:53:56 2010 From: nat.abbotts at gmail.com (Nathanael Abbotts) Date: Tue, 28 Dec 2010 14:53:56 -0800 (PST) Subject: Replacing Greenlets with Threads or Processes In-Reply-To: Message-ID: <857278fc-bf46-407d-ba76-db3e03a39b63@glegroupsg2000goo.googlegroups.com> On Tuesday, December 28, 2010 5:04:48 PM UTC, Emile van Sebille wrote: > On 12/28/2010 8:07 AM Nathanael Abbotts said... > > That thread seems to deal with mixing them. I want to replace them > > completely - is that possible (with either threads or processes)? > > Are you working with pycsp? the info at > http://code.google.com/p/pycsp/wiki/Getting_Started_With_PyCSP says: > > "The API is implemented in four versions: Threads, processes, greenlets > and net. All implementations share an almost identical API making it > trivial to switch from one implementation to another. " > > Emile Unfortunately not. I wish I was! That sounds brilliant. From nat.abbotts at gmail.com Tue Dec 28 17:53:56 2010 From: nat.abbotts at gmail.com (Nathanael Abbotts) Date: Tue, 28 Dec 2010 14:53:56 -0800 (PST) Subject: Replacing Greenlets with Threads or Processes In-Reply-To: Message-ID: <857278fc-bf46-407d-ba76-db3e03a39b63@glegroupsg2000goo.googlegroups.com> On Tuesday, December 28, 2010 5:04:48 PM UTC, Emile van Sebille wrote: > On 12/28/2010 8:07 AM Nathanael Abbotts said... > > That thread seems to deal with mixing them. I want to replace them > > completely - is that possible (with either threads or processes)? > > Are you working with pycsp? the info at > http://code.google.com/p/pycsp/wiki/Getting_Started_With_PyCSP says: > > "The API is implemented in four versions: Threads, processes, greenlets > and net. All implementations share an almost identical API making it > trivial to switch from one implementation to another. " > > Emile Unfortunately not. I wish I was! That sounds brilliant. From tjreedy at udel.edu Tue Dec 28 18:18:43 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 28 Dec 2010 18:18:43 -0500 Subject: round in 2.6 and 2.7 In-Reply-To: <4D1A5ADA.5040500@v.loewis.de> References: <87sjxoco6u.fsf@xemacs.org> <5f07e3a7-5f13-4ca0-bcde-75a916ac9210@r29g2000yqj.googlegroups.com> <4D1A5ADA.5040500@v.loewis.de> Message-ID: On 12/28/2010 4:47 PM, Martin v. Loewis wrote: >>> "Float-to-string and string-to-float conversions are correctly rounded. >>> The round() function is also now correctly rounded." The second line was written to be parallel to the first, but the first is slightly ambiguous in that 'conversions' can refer to either process (not rounded, correctly or otherwise ;-) or result. However the parallelism does not does as 'round() function' is the instrument of the process and definitly not the result. ... > I see. Shouldn't it say then "The round() function > gives/produces/returns correctly rounded results now", instead of saying > that > the round function *is* correctly rounded? ISTM that the round > function cannot be rounded (correctly or not): In 2.7 "Float-to-string and string-to-float conversion results are correctly rounded, as are the results of the round() function." -- Terry Jan Reedy From lists at cheimes.de Tue Dec 28 19:45:49 2010 From: lists at cheimes.de (Christian Heimes) Date: Wed, 29 Dec 2010 01:45:49 +0100 Subject: Interning own classes like strings for speed and size? In-Reply-To: <878vz9d558.fsf@xemacs.org> References: <8nra78Foh3U1@mid.uni-berlin.de> <4d19203f$0$29993$c3e8da3$5496439d@news.astraweb.com> <8nu4a2Fp63U1@mid.uni-berlin.de> <4d19f02c$0$29993$c3e8da3$5496439d@news.astraweb.com> <878vz9d558.fsf@xemacs.org> Message-ID: Am 28.12.2010 21:16, schrieb Hrvoje Niksic: > Christian Heimes writes: > >> Also this code is going to use much more memory than an ordinary tuple >> since every instance of InternedTuple has a __dict__ attribute. This >> code works but I had to move the cache outside the class because of >> __slots__. > > Wouldn't it work inside the class as well? __slots__ applies to > instances, not to classes themselves. In Python 3.1: You are right as long as you don't try to rebind the variable. I recalled that class attributes of classes with __slots__ behave slightly different than ordinary classes. For example you can't have a writeable slot and class default values at the same time. >>> class Example2(object): ... __slots__ = () ... _cache = {} ... >>> Example2()._cache {} >>> Example2()._cache = {} Traceback (most recent call last): File "", line 1, in AttributeError: 'Example2' object attribute '_cache' is read-only Christian From rami.chowdhury at merton.oxon.org Tue Dec 28 21:24:11 2010 From: rami.chowdhury at merton.oxon.org (Rami Chowdhury) Date: Wed, 29 Dec 2010 02:24:11 +0000 Subject: Interning own classes like strings for speed and size? In-Reply-To: References: <8nra78Foh3U1@mid.uni-berlin.de> <4d19203f$0$29993$c3e8da3$5496439d@news.astraweb.com> <8nu4a2Fp63U1@mid.uni-berlin.de> <4d19f02c$0$29993$c3e8da3$5496439d@news.astraweb.com> <878vz9d558.fsf@xemacs.org> Message-ID: On Wed, Dec 29, 2010 at 00:45, Christian Heimes wrote: > Am 28.12.2010 21:16, schrieb Hrvoje Niksic: >> Christian Heimes writes: >> >>> Also this code is going to use much more memory than an ordinary tuple >>> since every instance of InternedTuple has a __dict__ attribute. This >>> code works but I had to move the cache outside the class because of >>> __slots__. >> >> Wouldn't it work inside the class as well? ?__slots__ applies to >> instances, not to classes themselves. ?In Python 3.1: > > You are right as long as you don't try to rebind the variable. I > recalled that class attributes of classes with __slots__ behave slightly > different than ordinary classes. For example you can't have a writeable > slot and class default values at the same time. > >>>> class Example2(object): > ... ? ? __slots__ = () > ... ? ? _cache = {} > ... >>>> Example2()._cache > {} >>>> Example2()._cache = {} > Traceback (most recent call last): > ?File "", line 1, in > AttributeError: 'Example2' object attribute '_cache' is read-only Forgive me if I'm misunderstanding, but if you want to cache instances of a class, surely >> Example2()._cache = {} would defeat the purpose, at least for that instance of Example2? The slot seems writeable enough, after all >> Example2()._cache['foo'] = 'bar' seems to work? -- Rami Chowdhury "Never assume malice when stupidity will suffice." -- Hanlon's Razor +44-7581-430-517 / +1-408-597-7068 / +88-0189-245544 From devplayer at gmail.com Tue Dec 28 23:32:31 2010 From: devplayer at gmail.com (DevPlayer) Date: Tue, 28 Dec 2010 20:32:31 -0800 (PST) Subject: Dynamic list name from a string References: <48c5eb62-b011-4ff6-ad1e-be92abe2e2eb@o4g2000yqd.googlegroups.com> <87ec1487-e42d-4f9b-8d70-cb615e123007@k25g2000vbl.googlegroups.com> Message-ID: <6ac47465-d78c-4913-9795-2537dd168b90@p1g2000yqm.googlegroups.com> # dynamic_named_obj.py # comp.lang.python # 2010-12 Dec-28 # Topic: Dynamic list name from a string Options # attempts to answer OP's question # DevPlayer - not a solution I'd use # TO Original Poster OP: # Start from the bottom OPTION, the one you requested. # Work your way up and see how it gets simpler and # simpler to do what you want. Dynamically named # references start to look pointless. # I hope I addressed your question and hopefully shown # you the right direction and right reasons to avoid # using dynamically made named references. # But I could be wrong in your case. import time class DataStore(object): """A namespace similar to a module global scope.""" #def concatenate( one, two): # """Function to concatonate two lists.""" # return list( one + two) # ========= class Animal(object): """A base class for no real reason.""" def __init__(self, name): self.name = name self.date = time.clock() # --------- class Bear(Animal): def __init__(self, name): super(Bear, self).__init__(name) class BearCub(Bear): def __init__(self, name): super(BearCub, self).__init__(name) # --------- class Doe(Animal): def __init__(self, name): super(Doe, self).__init__(name) class Fawn(Doe): def __init__(self, name): super(Fawn, self).__init__(name) # An alternate namespace instead of module global ns = DataStore() OPTION = "BETTER YET" if OPTION == "BETTER YET": # don't name your lists, just make the global_list and use it # no intermediary lists needed really. ns.Animals = [ # ---------- 1st set of classes Bear("bob"), Bear("bill"), BearCub("obo"), BearCub("Bill jr."), # ---------- 2nd set of classes Doe("DoeADear"), Doe("AFemaleDear"), Fawn("Ray"), Fawn("Adropof"), ] for animal in ns.Animals: kind = animal.__class__.__name__ name = animal.name date = animal.date print kind, name, date # make a sorted, by date, list of bears old_bears = [obj for obj in ns.Animals if type(obj) is Bear] old_bears.sort(None, key=lambda animal: animal.date) ns.bears = old_bears # or sort all animals by date animals = [obj for obj in ns.Animals] animals.sort(None, key=lambda animal: animal.date) # then get just bears bears = [obj for obj in animals if type(obj) is Bear] elif OPTION == "BETTER": # don't name your lists, trust in checking if objects have attributes # that matter ns.Animals = { # ---------- 1st set of classes "bob": Bear("bob"), "Bill": Bear("bill"), "obo": BearCub("obo"), "Bill jr.": BearCub("Bill jr."), # ---------- 2nd set of classes "DoeADear": Doe("DoeADear"), "AFemaleDear": Doe("AFemaleDear"), "Ray": Fawn("Ray"), "Adropof": Fawn("Adropof"), } print ns.Animals['bob'].date # make a sorted list of objects based on an attribute -like date # sort by date for just bears # http://wiki.python.org/moin/HowTo/Sorting # look at Operator Module Functions too # make a sorted, by date, list of bears old_bears = [obj for obj in ns.Animals.values() if type(obj) is Bear] old_bears.sort(None, key=lambda animal: animal.date) ns.bears = old_bears # or sort all animals by date animals = [obj for obj in ns.Animals.values()] animals.sort(None, key=lambda animal: animal.date) # then get just bears bears = [obj for obj in animals if type(obj) is Bear] elif OPTION == "SOSO1": # alternative to dynamically named references (object attributes) # Each item in global_dict is a sub dict ns.Animals = {} # ---------- 1st set of classes ns.Animals[ Bear ] = {"bob": Bear("bob"), "Bill": Bear("Bill")} ns.Animals[ BearCub ] = {"obo": BearCub("obo"), "Bill jr.": Bearcub("Bill jr.")} # ---------- 2nd set of classes ns.Animals[ Doe ] = {"DoeADear": Doe("DoeADear"), "AFemaleDear": Doe("AFemaleDear")} ns.Animals[ Fawn ] = {"Ray": Fawn("Ray"), "Adropof": Fawn("Adropof")} print ns.Animals[Bear]["bob"].date print ns.Animals[BearCub]["Bill jr."].date elif OPTION == "SOSO2": # alternative to dynamically named references (object attributes) # don't use names at all - # Each item in a dict is a list of objects # use class itself as key (not class name) ns.Animals = {} # ---------- 1st set of classes ns.Animals[ Bear ] = [Bear("bob"), Bear("Bill")] ns.Animals[ BearCub ] = [BearCub("obo"), Bearcub("Bill jr.")] # ---------- 2nd set of classes ns.Animals[ Doe ] = [Doe("DoeADear"), Doe("AFemaleDear")] ns.Animals[ Fawn ] = [Fawn("Ray"), Fawn("Adropof")] print ns.Animals[Bear][0].date elif OPTION == "SOSO3": # alternative to dynamically named references (object attributes) # use class __name__ as key ns.Animals = {} # ---------- 1st set of classes ns.Animals[ Bear.__name__ ] = [Bear("bob"), Bear("Bill")] ns.Animals[ BearCub.__name__ ] = [BearCub("obo"), Bearcub("Bill jr.")] # ---------- 2nd set of classes ns.Animals[ Doe.__name__ ] = [Doe("DoeADear"), Doe("AFemaleDear")] ns.Animals[ Fawn.__name__ ] = [Fawn("Ray"), Fawn("Adropof")] else: #OPTION LAST # What OP was requesting # ---------- 1st set of classes ref_name = Bear.__name__ + "_list" setattr(ns, ref_name, {"bob":Bear("bob"), "bill": Bear("Bill")}) ref_name = BearCub.__name__ + "_list" setattr(ns, ref_name, {"obo":Bear("obo"), "Bill jr.": Bear("Bill jr.")}) # ---------- 2nd set of classes ref_name = Doe.__name__ + "_list" setattr(ns, ref_name, {"DoeADear":Bear("DoeADear"), "AFemaleDear": Bear("AFemaleDear")}) ref_name = Doe.__name__ + "_list" setattr(ns, ref_name, {"Ray":Bear("Ray"), "Adropof": Bear("Adropof")}) # bet that didn't look as appealing as you thought it might # Now thing of all the times you'll use those dynamically # generated reference names (variables). # Do you really need to access "unknown" named references? # ---------- # concatenate all instances of all Animal subclasses into one big dict # ns.globalDict = {item[0]:item[1] for item in ns.__dict__.items() if "_list" in item[0]} # ns.globalDict = {} # make a list of lists (where each list contains instances of a certain class) # alist_of_lists = [key for key in ns.__dict__ if "_list" in key] # using reduce because OP didn't know how many sub-lists will be added # a = ['one', 'two', 'three',] # b = [1, 2, 3] # reduce(concatenate, [a, b]) # ['one', 'two', 'three', 1, 2, 3] # poop'd out. From stef.mientki at gmail.com Wed Dec 29 04:27:40 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Wed, 29 Dec 2010 10:27:40 +0100 Subject: NameError: global name 'btn_Matlab' is not defined ? In-Reply-To: <4d19f10d$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <4d19f10d$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4D1AFF0C.1050106@gmail.com> On 28-12-2010 15:15, Steven D'Aprano wrote: > On Tue, 28 Dec 2010 14:34:19 +0100, Stef Mientki wrote: > >> hello, >> >> Never seen this before and I've no explanation whatsoever (Python 2.6) >> >> I've some dynamic generated code, >> one of objects generated is a wx.Button, called 'btn_Matlab'. > How do you generate the code? > > What code is generated? What does it do? > > >> After the code is generated, I can see that the button is created in the >> local namespace >> >> print locals()['btn_Matlab'] >> >> > 0x3602d28> > >> >> but if I try to print the button (at exactly the same location), I get >> an error >> >> print btn_Matlab >> >> NameError: global name 'btn_Matlab' is not defined ? >> >> Why isn't the compiler first checking the local namespace ? any clues ? > > My guess is that you've declared btn_Matlab as global, and then > dynamically created a local with the same name using exec or similar. thanks Stevem, I found a solution. I indeed tried to "inject" local variables from a stack a few levels deeper, which doesn't seem to be possible (or reliable). The documentation isn't overwhelming about that point, exec and eval doesn't mention anything, but execfile warms for this issue. The code now looks something like this: self.p_locals = sys._getframe ( StackUp ).f_locals self.p_globals = sys._getframe ( StackUp ).f_globals Component = eval ( defi[1], self.p_globals, self.p_locals ) ( Parent, **Extra ) self.p_globals[ 'Component' ] = Component if 'self' in defi[0] : exec ( '%s = Component' %( defi[0] ), self.p_globals, self.p_locals ) else : exec ( '%s = Component' %( defi[0] ), self.p_globals) cheers, Stef From as at sci.fi Wed Dec 29 04:48:08 2010 From: as at sci.fi (Anssi Saari) Date: Wed, 29 Dec 2010 11:48:08 +0200 Subject: Noob question on 2 vs 3 Python releases References: Message-ID: Franck Ditter writes: > Pardon my noobness (?) but why is there a 2.x and 3.x development > teams working concurrently in Python ? Well, Python 2.7 is the last major 2.x release, only bugfixes are done for it, like the 2.7.1 release. Actual developement is in the 3.x branch now. > Which one should I choose to start with, to cope with > the future ? I started with a good book covering both. The basics are mostly the same anyways. From steve.gnulinux at gmail.com Wed Dec 29 05:39:02 2010 From: steve.gnulinux at gmail.com (Steve) Date: Wed, 29 Dec 2010 02:39:02 -0800 (PST) Subject: A wrap for a multi-tabbed terminal. Some questions Message-ID: http://pastie.org/763792/wrap This in IMHO, a really useful piece of code, to wrap and run terminal commands, on a gtk+vte python based gui. I would to make some improvements, in order to wrap some terminal applications. How can SET_FOCUS (at start) to the first vte frame? (Avoiding to click on terminal to get focus) How can fork a command thru the menus? thank you, Steve, From dickinsm at gmail.com Wed Dec 29 05:52:52 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 29 Dec 2010 02:52:52 -0800 (PST) Subject: round in 2.6 and 2.7 References: <87sjxoco6u.fsf@xemacs.org> <5f07e3a7-5f13-4ca0-bcde-75a916ac9210@r29g2000yqj.googlegroups.com> <4D1A5ADA.5040500@v.loewis.de> Message-ID: <2c68a5e7-91b9-400d-a706-afae5090ecf7@z9g2000yqz.googlegroups.com> On Dec 28, 9:47?pm, "Martin v. Loewis" wrote: > >> "Float-to-string and string-to-float conversions are correctly rounded. > >> The round() function is also now correctly rounded." > > >> Not sure that this is correct English; I think it means that the > >> round() function is now correct. > > > Well, the correct result of the example the OP gave would be 9.9 > > exactly. ?But since 9.9 isn't exactly representable as a Python float, > > we necessarily get an approximation. ?The language above is intended > > to convey that it's the 'correctly rounded' approximation > > I see. Shouldn't it say then "The round() function > gives/produces/returns correctly rounded results now", instead of saying > that > the round function *is* correctly rounded? ISTM that the round > function cannot be rounded (correctly or not): > > py> round(round) > Traceback (most recent call last): > ? File "", line 1, in > TypeError: a float is required > > But then, I'm not a native speaker (of English). I dare say that you're just as much a native speaker as anyone else when it comes to the language of floating-point arithmetic. Not sure English comes into it that much. :-) Sure, I agree it's probably a slight abuse of language to refer to a function as 'correctly rounded', but I think it's a fairly standard abuse. From the two nearest references to hand: IEEE 754-2008 has a whole section entitled 'Recommended correctly rounded functions' (nit: shouldn't there be a hyphen in that title?), and persists in referring to 'correctly rounded' conversions. The more formal uses in that document do indeed refer to single values, though. ("A conforming function shall return results correctly rounded ...") The 'Handbook of Floating-Point Arithmetic' by Muller et. al. gives a definition of a correctly rounded function in section 2.2. "When the exact result of a function is rounded according to a given rounding mode ..., one says that the function is *correctly rounded*." It's not so dissimilar from other mathematical abuses, like describing a real-valued function as 'positive', when what you actually mean is that all its values are positive. It's also slightly unsettling usage for me, not least because the statement 'f is correctly rounded' for a floating-point function f is really a statement about *two* functions: namely, f (a function from floating-point numbers to floating-point numbers) and the true mathematical function that it's based on; the identity of the underlying mathematical function is left implicit. -- Mark From skarra at gmail.com Wed Dec 29 05:57:31 2010 From: skarra at gmail.com (Karra) Date: Wed, 29 Dec 2010 02:57:31 -0800 (PST) Subject: Making urllib2's POST 302 handle same as Perl LWP's behaviour Message-ID: <1c165589-a054-4065-b050-50f2535b0897@37g2000prx.googlegroups.com> I am doing a POST to a webserver and get a 302 Found response (redirect). urllib2's default behaviour is to do a GET on the new url from the Location: URI in the 302 response. This is different from what I have found with LWP::UserAgent- >request() in perl. After much searching I understand there is a view that automatic redirection for a 302 in response to a POST is not in conformance to the relevant RFCs. Therefore, I believe urllib2's behaviour appears to be non-conformant (as, I believe are many browsers). Now, regardless of what is the "correct" approach to handling the 302, there is some information in the returned html of the 302 which I am losing because of the subsequent GET. I tried to raise a HTTPError from redirect_request() but that just kills the connection with the server. I tried returning None, same result. Can someone point me to how I can get the default LWP:UserAgent behaviour of handling this scenario using urllib2? From meitham at meitham.com Wed Dec 29 06:05:27 2010 From: meitham at meitham.com (meitham) Date: Wed, 29 Dec 2010 03:05:27 -0800 (PST) Subject: etl tool!!!!! References: Message-ID: <1e7b9314-1186-4a94-ad3b-79ea856dafe8@i18g2000yqn.googlegroups.com> BOn Dec 28, 1:14?pm, Stefan Sonnenberg-Carstens wrote: > Am 28.12.2010 13:57, schrieb krishna kumar:> Is there any efficient etl tool developed in python? > > Yes, Python. I use SQLAlchemy for both sources and targets, just because I hate to type sql queries :-) I am convincing clients to ditch solutions such informatica and talend in favour of plain python. I don't understand the mentality that learning an ETL graphical tool can be easier than learning a programming language, why don't just hire programmers and teach them business, after all, programmers are cheaper and often more intelligent. From hniksic at xemacs.org Wed Dec 29 06:25:29 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Wed, 29 Dec 2010 12:25:29 +0100 Subject: Interning own classes like strings for speed and size? References: <8nra78Foh3U1@mid.uni-berlin.de> <4d19203f$0$29993$c3e8da3$5496439d@news.astraweb.com> <8nu4a2Fp63U1@mid.uni-berlin.de> <4d19f02c$0$29993$c3e8da3$5496439d@news.astraweb.com> <878vz9d558.fsf@xemacs.org> Message-ID: <87zkrobz2u.fsf@xemacs.org> Christian Heimes writes: > You are right as long as you don't try to rebind the variable. And then only if you assign through an instance, which doesn't make sense for a class-level cache. Assignment like Example2._cache = {} would work. From scbunn at sbunn.org Wed Dec 29 06:39:54 2010 From: scbunn at sbunn.org (Stephen Bunn) Date: Wed, 29 Dec 2010 20:39:54 +0900 Subject: O'Reilly Python Certification In-Reply-To: References: <4D0900D3.10000@stoneleaf.us> <4D0927C1.5080209@tim.thechases.com> <4D093176.3010109@pythonmeister.com> <4D0A3306.3090100@stoneleaf.us> Message-ID: <87fwtgolit.wl%scbunn@sbunn.org> At Tue, 28 Dec 2010 20:07:29 +0000 (UTC), J. Altman wrote: > > I have a general question. > > Does it seem odd that a certificate in Python, an Open Source > language; taught at O'Reilly, which offers an Open Source Programming > Certificate and is something like waist-deep in Open Source > publishing; is offered to the world at large but only (IIUC) if one > runs some version of Windows by MS? > > Based on what I am given to understand from my correspondence with > OST, it seems that I *must* install an instance of Windows to take the > certificate's courses. This is not true. You can take the course on any operating system that supports a RDP client. I am enrolled with in the python course and I use GNU/Linux. They even have instructions on their website on how to configure it. I would have preferred them to use a UNIX shell. I'm still waiting for somebody to come up with a course that teaches me a programming language, while teaching me a VCS and allows me to write code and submit to a repo with other students contributing. You want to bring people into F/OSS -- That is how you do it! The complaint that I do have with OST (at least the Python course) and the reason I have not completed (or even worked on the course in almost a year) it, is that its just plain boring. It's almost 2011! Give me some interactive flash, a video, something. Reading some pages of dry text just doesn't cut it for me. I can do that on my own. If I'm going to pay for a course I want a teacher that is going to teach me something. I can buy plenty of books and read them. The entire course is just plain dry text. I don't even remeber seeing an image diagram. On top of that the text is horribly ugly to look at. From scbunn at sbunn.org Wed Dec 29 06:40:24 2010 From: scbunn at sbunn.org (Stephen Bunn) Date: Wed, 29 Dec 2010 20:40:24 +0900 Subject: O'Reilly Python Certification In-Reply-To: References: <4D0900D3.10000@stoneleaf.us> <4D0927C1.5080209@tim.thechases.com> <4D093176.3010109@pythonmeister.com> <4D0A3306.3090100@stoneleaf.us> Message-ID: <87ei90olhz.wl%scbunn@sbunn.org> At Tue, 28 Dec 2010 20:07:29 +0000 (UTC), J. Altman wrote: > > I have a general question. > > Does it seem odd that a certificate in Python, an Open Source > language; taught at O'Reilly, which offers an Open Source Programming > Certificate and is something like waist-deep in Open Source > publishing; is offered to the world at large but only (IIUC) if one > runs some version of Windows by MS? > > Based on what I am given to understand from my correspondence with > OST, it seems that I *must* install an instance of Windows to take the > certificate's courses. This is not true. You can take the course on any operating system that supports a RDP client. I am enrolled with in the python course and I use GNU/Linux. They even have instructions on their website on how to configure it. I would have preferred them to use a UNIX shell. I'm still waiting for somebody to come up with a course that teaches me a programming language, while teaching me a VCS and allows me to write code and submit to a repo with other students contributing. You want to bring people into F/OSS -- That is how you do it! The complaint that I do have with OST (at least the Python course) and the reason I have not completed (or even worked on the course in almost a year) it, is that its just plain boring. It's almost 2011! Give me some interactive flash, a video, something. Reading some pages of dry text just doesn't cut it for me. I can do that on my own. If I'm going to pay for a course I want a teacher that is going to teach me something. I can buy plenty of books and read them. The entire course is just plain dry text. I don't even remeber seeing an image diagram. On top of that the text is horribly ugly to look at. From scbunn at sbunn.org Wed Dec 29 06:41:15 2010 From: scbunn at sbunn.org (Stephen Bunn) Date: Wed, 29 Dec 2010 20:41:15 +0900 Subject: O'Reilly Python Certification In-Reply-To: References: <4D0900D3.10000@stoneleaf.us> <4D0927C1.5080209@tim.thechases.com> <4D093176.3010109@pythonmeister.com> <4D0A3306.3090100@stoneleaf.us> Message-ID: <87d3okolgk.wl%scbunn@sbunn.org> At Tue, 28 Dec 2010 20:07:29 +0000 (UTC), J. Altman wrote: > > I have a general question. > > Does it seem odd that a certificate in Python, an Open Source > language; taught at O'Reilly, which offers an Open Source Programming > Certificate and is something like waist-deep in Open Source > publishing; is offered to the world at large but only (IIUC) if one > runs some version of Windows by MS? > > Based on what I am given to understand from my correspondence with > OST, it seems that I *must* install an instance of Windows to take the > certificate's courses. This is not true. You can take the course on any operating system that supports a RDP client. I am enrolled with in the python course and I use GNU/Linux. They even have instructions on their website on how to configure it. I would have preferred them to use a UNIX shell. I'm still waiting for somebody to come up with a course that teaches me a programming language, while teaching me a VCS and allows me to write code and submit to a repo with other students contributing. You want to bring people into F/OSS -- That is how you do it! The complaint that I do have with OST (at least the Python course) and the reason I have not completed (or even worked on the course in almost a year) it, is that its just plain boring. It's almost 2011! Give me some interactive flash, a video, something. Reading some pages of dry text just doesn't cut it for me. I can do that on my own. If I'm going to pay for a course I want a teacher that is going to teach me something. I can buy plenty of books and read them. The entire course is just plain dry text. I don't even remeber seeing an image diagram. On top of that the text is horribly ugly to look at. From skarra at gmail.com Wed Dec 29 07:35:42 2010 From: skarra at gmail.com (Karra) Date: Wed, 29 Dec 2010 04:35:42 -0800 (PST) Subject: Making urllib2's POST 302 handle same as Perl LWP's behaviour References: <1c165589-a054-4065-b050-50f2535b0897@37g2000prx.googlegroups.com> Message-ID: <753d3952-2b21-4939-ae47-d714d9b02bf1@h17g2000pre.googlegroups.com> On Dec 29, 3:57?pm, Karra wrote: > Can someone point me to how I can get the default LWP:UserAgent > behaviour of handling this scenario using urllib2? Out of frustration, I decided to give 'mechanize' a try. It came as an awesome surprise that mechanize implements the exact api of urllib2 - meaning all I had to do was a query-replace of urllib2 to mechanize, and lo-and-behold I got what I wanted! Which is to say, the behaviour of mechanize matches Perl's LWP::UserAgent as afar as handling of POST redirects go. From orasnita at gmail.com Wed Dec 29 09:03:18 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Wed, 29 Dec 2010 16:03:18 +0200 Subject: Making urllib2's POST 302 handle same as Perl LWP's behaviour References: <1c165589-a054-4065-b050-50f2535b0897@37g2000prx.googlegroups.com> <753d3952-2b21-4939-ae47-d714d9b02bf1@h17g2000pre.googlegroups.com> Message-ID: <47800B33A68E4A648FC008806599BB85@teddy> I have tried: In httpd.conf: Redirect /one/ http://localhost/two/ Redirect /two/ http://localhost/three/ redirect /three/ http://www.google.com/ Then I made a POST request with LWP::UserAgent to /one: use LWP::UserAgent; print LWP::UserAgent->new->post('http://localhost/one/')->as_string; And the result was: HTTP/1.1 302 Found Connection: close Date: Wed, 29 Dec 2010 13:58:37 GMT Location: http://localhost/two/ Server: Apache/2.2.15 (Win32) mod_perl/2.0.4-dev Perl/v5.10.1 ... Exactly as you described. Then I made a POST request with WWW::Mechanize: use WWW::Mechanize; print WWW::Mechanize->new->post('http://localhost/one/')->as_string; And the result was: HTTP/1.1 200 OK Cache-Control: private, max-age=0 Connection: close Date: Wed, 29 Dec 2010 14:00:44 GMT Server: gws So it seems that LWP::UserAgent works similarly with mechanize and WWW::Mechanize similarly to urllib. Nice. :-) Octavian ----- Original Message ----- From: "Karra" Newsgroups: comp.lang.python To: Sent: Wednesday, December 29, 2010 2:35 PM Subject: Re: Making urllib2's POST 302 handle same as Perl LWP's behaviour On Dec 29, 3:57 pm, Karra wrote: > Can someone point me to how I can get the default LWP:UserAgent > behaviour of handling this scenario using urllib2? Out of frustration, I decided to give 'mechanize' a try. It came as an awesome surprise that mechanize implements the exact api of urllib2 - meaning all I had to do was a query-replace of urllib2 to mechanize, and lo-and-behold I got what I wanted! Which is to say, the behaviour of mechanize matches Perl's LWP::UserAgent as afar as handling of POST redirects go. -- http://mail.python.org/mailman/listinfo/python-list From inigoserna at gmail.com Wed Dec 29 10:05:23 2010 From: inigoserna at gmail.com (=?UTF-8?B?ScOxaWdvIFNlcm5h?=) Date: Wed, 29 Dec 2010 16:05:23 +0100 Subject: ANN: MyNewspaper v3.0 Message-ID: Hi there, I'm really pleased to announce a new release of MyNewspaper, a web-based personal RSS aggregator and feeds reader. Although no public releases in last years, I've been improving MyNewspaper continually for my personal use, but I think it's the time to publish it again. Some technical points of interest: - backend based on CherryPy web framework, FeedParser, SQLObject, SQLite - frontend with javascript (jQuery, jQueryUI, jQuery-mobile) More information, complete requirements and download link at: [main] https://inigo.katxi.org/devel/mynewspaper/ [mirror] http://www.terra.es/personal7/inigoserna/mynewspaper/ Of course, all comments, suggestions etc. are welcome. Best regards, I?igo Serna From stagi.andrea at gmail.com Wed Dec 29 10:57:18 2010 From: stagi.andrea at gmail.com (Andrea Stagi) Date: Wed, 29 Dec 2010 07:57:18 -0800 (PST) Subject: Tiny4py, a little python wrapper to make shorten urls and QRCodes Message-ID: Hi, I would announce you my new python wrapper to make shorten urls and QRCodes, using main used services: goo.gl, bit.ly and tinyurl. Please, visit http://code.google.com/p/tiny4py/ Bests From wxjmfauth at gmail.com Wed Dec 29 11:07:25 2010 From: wxjmfauth at gmail.com (jmfauth) Date: Wed, 29 Dec 2010 08:07:25 -0800 (PST) Subject: Does Python 3.1 accept \r\n in compile()? Message-ID: <5c7ae38a-4302-427b-98f0-2900eaf2a974@l24g2000vby.googlegroups.com> I wrote miscellaneous interactive interpreters and I fall on this. In Python 2.7 (understand Python > 2.6), a source code can be compiled with "native" '\r\n' as eol. In Python 3.1, it does not seem to be the case. (Python 3.2.a/b not checked). Bug, regression, deliberate choice? >>> sys.version 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] >>> compile('if True:\n print 999\n', '', 'exec') at 02858DA0, file "", line 1> >>> compile('if True:\r\n print 999\r\n', '', 'exec') at 02858E30, file "", line 1> >>> exec(compile('if True:\r\n print 999\r\n', '', 'exec')) 999 >>> sys.version '3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit (Intel)]' compile('if True:\n print(999)\n', '', 'exec') at 0x01FE5458, file "", line 2> >>> exec(compile('if True:\n print(999)\n', '', 'exec')) 999 >>> # this fails >>> compile('if True:\r\n print(999)\r\n', '', 'exec') Traceback (most recent call last): File "", line 1, in File "", line 1 if True: ^ SyntaxError: invalid syntax From wingogoo at gmail.com Wed Dec 29 11:22:57 2010 From: wingogoo at gmail.com (wingoo) Date: Wed, 29 Dec 2010 08:22:57 -0800 (PST) Subject: Trying to parse a HUGE(1gb) xml file In-Reply-To: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> Message-ID: maybe you can try http://vtd-xml.sourceforge.net/ From jwhughes at hughesconcepts.com Wed Dec 29 11:40:07 2010 From: jwhughes at hughesconcepts.com (Joe Hughes) Date: Wed, 29 Dec 2010 11:40:07 -0500 Subject: Python 3 and SNMP Traps Message-ID: <38B73ABD-4C3D-465E-877E-78CEA323D59E@hughesconcepts.com> All: I'm using Python 3.1.3 and need to incorporate sending SNMP traps from my script. I've researched and I found pysnmp and net-snmp with python bindings. The first appears to be only for Python 2.x. The second I'm not certain about. Has anyone experience with this and able to give suggestions? Thanks, Joe From wander.lairson at gmail.com Wed Dec 29 13:18:35 2010 From: wander.lairson at gmail.com (wander.lairson) Date: Wed, 29 Dec 2010 16:18:35 -0200 Subject: PyUSB 1.0.0 alpha 1 release Message-ID: Dear all, PyUSB 1.0.0 alpha 1 is out. Since alpha 0, this version : - Standard control requests through usb.control module. - String descriptors through usb.util module. - Complete PyUSB 0.4 API emulation. - Working libusb 1.0 support under Windows. For details check the ReleaseNotes.txt and ChangeLog files. This version can be download through sourceforge: https://sourceforge.net/projects/pyusb/files/PyUSB%201.0/1.0.0-alpha-1/ For further information about PyUSB visit the project website: http://pyusb.sourceforge.net -- Best Regards, Wander Lairson Costa LCoN - Laborat?rio de Computa??o Natural - Natural Computing Laboratory (http://www.mackenzie.com.br/lcon.html) Programa de P?s-Gradua??o em Engenharia El?trica (PPGEE) Faculdade de Computa??o e Inform?tica (FCI) Universidade Presbiteriana Mackenzie - SP - Brazil From tjreedy at udel.edu Wed Dec 29 14:31:37 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 29 Dec 2010 14:31:37 -0500 Subject: Does Python 3.1 accept \r\n in compile()? In-Reply-To: <5c7ae38a-4302-427b-98f0-2900eaf2a974@l24g2000vby.googlegroups.com> References: <5c7ae38a-4302-427b-98f0-2900eaf2a974@l24g2000vby.googlegroups.com> Message-ID: On 12/29/2010 11:07 AM, jmfauth wrote: > I wrote miscellaneous interactive interpreters and > I fall on this. > > In Python 2.7 (understand Python> 2.6), a source code > can be compiled with "native" '\r\n' as eol. I am a bit surprised, but I presume this is one on many back-compatibility holdovers still in 2.7. I believe 2.7 normally reads input with universal newline support, so that line endings are fixed on input, where they should be. Within Python, 'newline' is '\n'. > In Python 3.1, it does not seem to be the case. In 3.0, there were many simplifications where old things got dropped. > (Python 3.2.a/b not checked). I have not heard of any change. The compile() entry has the following: "Changed in version 3.2: Allowed use of Windows and Mac newlines. Also input in 'exec' mode does not have to end in a newline anymore. Added the optimize parameter." The second and third statement are true, but >>> compile('print(999)\r\n', '', 'exec') Traceback (most recent call last): File "", line 1, in compile('print(999)\r\n', '', 'exec') File "", line 1 print(999) ^ SyntaxError: invalid syntax I will inquire on pydev. > Bug, regression, deliberate choice? I presume deliberate simplification, but you can wait for another answer or check svn logs of the appropriate source file. Or there might be an entry in 3.0 NEWS or What's New files. -- Terry Jan Reedy From tjreedy at udel.edu Wed Dec 29 15:14:45 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 29 Dec 2010 15:14:45 -0500 Subject: Does Python 3.1 accept \r\n in compile()? In-Reply-To: References: <5c7ae38a-4302-427b-98f0-2900eaf2a974@l24g2000vby.googlegroups.com> Message-ID: On 12/29/2010 2:31 PM, Terry Reedy wrote: > "Changed in version 3.2: Allowed use of Windows and Mac newlines. Also > input in 'exec' mode does not have to end in a newline anymore. Added > the optimize parameter." Retest shows that above is correct. >>> compile("print(999)\r\n", "blah", "exec") at 0x00F5EC50, file "blah", line 1> For most development purposes (not just yours), 3.2b2 is already better than 3.1. Terry Jan Reedy From wxjmfauth at gmail.com Wed Dec 29 16:06:38 2010 From: wxjmfauth at gmail.com (jmfauth) Date: Wed, 29 Dec 2010 13:06:38 -0800 (PST) Subject: Does Python 3.1 accept \r\n in compile()? References: <5c7ae38a-4302-427b-98f0-2900eaf2a974@l24g2000vby.googlegroups.com> Message-ID: <19d5330a-1237-4e7a-b9aa-47ce312ce8f9@d7g2000vbv.googlegroups.com> On 29 Dez., 21:14, Terry Reedy wrote: > On 12/29/2010 2:31 PM, Terry Reedy wrote: > > > "Changed in version 3.2: Allowed use of Windows and Mac newlines. Also > > input in 'exec' mode does not have to end in a newline anymore. Added > > the optimize parameter." > > Retest shows that above is correct. > > ?>>> compile("print(999)\r\n", "blah", "exec") > > at 0x00F5EC50, file "blah", line 1> > Ok, I see. Thanks. The '\r\n' acceptance has been introduced in Python 2.7 and I was a little bit suprised with Python 3.1. For the story, I'm not using directly the compile() command, but something like: .runsource(source) where source is coming from a GUI toolkit text widget. From tjreedy at udel.edu Wed Dec 29 18:11:14 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 29 Dec 2010 18:11:14 -0500 Subject: Does Python 3.1 accept \r\n in compile()? In-Reply-To: <19d5330a-1237-4e7a-b9aa-47ce312ce8f9@d7g2000vbv.googlegroups.com> References: <5c7ae38a-4302-427b-98f0-2900eaf2a974@l24g2000vby.googlegroups.com> <19d5330a-1237-4e7a-b9aa-47ce312ce8f9@d7g2000vbv.googlegroups.com> Message-ID: On 12/29/2010 4:06 PM, jmfauth wrote: > On 29 Dez., 21:14, Terry Reedy wrote: >> On 12/29/2010 2:31 PM, Terry Reedy wrote: >> >>> "Changed in version 3.2: Allowed use of Windows and Mac newlines. Also >>> input in 'exec' mode does not have to end in a newline anymore. Added >>> the optimize parameter." >> >> Retest shows that above is correct. >> >> >>> compile("print(999)\r\n", "blah", "exec") >> >> at 0x00F5EC50, file "blah", line 1> >> > > Ok, I see. Thanks. > > The '\r\n' acceptance has been introduced in Python 2.7 > and I was a little bit suprised with Python 3.1. 2.6 was followed by 3.0 and then 3.1. 2.7 will be followed by 3.2 in a couple more month. That feature was added to 2.7 and 3.2 in Nov 2009 long after 3.1. -- Terry Jan Reedy From gervaz at gmail.com Wed Dec 29 18:31:20 2010 From: gervaz at gmail.com (gervaz) Date: Wed, 29 Dec 2010 15:31:20 -0800 (PST) Subject: Interrput a thread Message-ID: <81c24eb1-41b6-442a-a971-8a44d2cd6c1b@p8g2000vbs.googlegroups.com> Hi all, I need to stop a threaded (using CTR+C or kill) application if it runs too much or if I decide to resume the work later. I come up with the following test implementation but I wanted some suggestion from you on how I can implement what I need in a better or more pythonic way. Here the code: import os import signal import time from threading import Thread, current_thread from queue import LifoQueue, Empty COMMAND = {"STOP": 0, "NORMAL": 1} THREAD_NUM = 5 lq = LifoQueue() print("{0}\n".format(os.getpid())) class InterceptInterrupt(Exception): pass class Handler: def __init__(self, queue): self._queue = queue def __del__(self): print("Bye bye!") def getHandler(self, signum, frame): print("Interrupt raised!") for _ in range(THREAD_NUM): self._queue.put((COMMAND["STOP"], None)) raise InterceptInterrupt h = Handler(lq) signal.signal(signal.SIGINT, h.getHandler) for i in range(25): lq.put((COMMAND["NORMAL"], i)) def do_work(queue): while True: time.sleep(5) try: cmd, value = queue.get(block=False) if cmd == COMMAND["STOP"]: print("{0}: STOP command received!".format(current_thread().name)) break elif cmd == COMMAND["NORMAL"]: print(value) except Empty: break threads = [Thread(target=do_work, args=(lq,)) for _ in range(THREAD_NUM)] for t in threads: t.start() while not lq.empty(): try: time.sleep(1) except (IOError, InterceptInterrupt): break for t in threads: t.join() if lq.empty(): print("The queue is empty.") else: print("The queue is NOT empty. Some additional work has to be done.") Thank you, Mattia From Philippe.vouters at laposte.net Wed Dec 29 18:31:36 2010 From: Philippe.vouters at laposte.net (A famous IT technical writer) Date: Wed, 29 Dec 2010 15:31:36 -0800 (PST) Subject: gSOAP and Python/ctypes Message-ID: <365e2387-5459-4783-b497-1937ccb37eb5@l32g2000yqc.googlegroups.com> For the moment onlly studied under Linux Fedora 13, here is a gSOAP + Python/ctypes + ctypesgen introduction available at http://vouters.dyndns.org/tima/Linux-gSOAP-C-Python-ctypes-Why_and_when_using_gSOAP-a_quick_introduction.html Hoping this will help some of you. From rantingrick at gmail.com Wed Dec 29 18:58:53 2010 From: rantingrick at gmail.com (rantingrick) Date: Wed, 29 Dec 2010 15:58:53 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! Message-ID: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> Tkinter: The good, the bad, and the ugly! ----------------------------------------- An expose by rantingrick ---------------------- The Good ---------------------- Back in the early days of Python --when this simplistic beauty of programming bliss we enjoy today was just a tiny glimmer of hope in a archaic world plagued by dark forest of braces and jagged caverns of cryptic syntaxes-- our beloved dictator (Mr. Van Rossum) had the foresight to include a simplistic GUI toolkit that we call Tkinter into the stdlib. And he saw that it was great, and that it was good, and so he rested. And when the first python programmers used this gift handed down from the gods they were pleased. They could see that all of the heavy work of cross-platform-ism landed square on the shoulders of TCL/Tk and all Python had to do was wrap a few methods to wield the beast we all know as graphical user interfaces. Life was good, people were happy...but darkness loomed on the horizon... ---------------- Enter the Bad ---------------- However as we all know there exists no real Utopian bliss without many pitfalls and snares. Since Tkinter is just a wrapping of some TclTk calls the people realized that they are now at the perilous mercy of another group of developers (psst: thats the TCL folks!) who have only their own goals and dreams in mind and could care less for the troubles of others. They realized that Tkinter was lacking. However this lacking was not Tkinters fault, no, the fault lye with TclTk. And to compound these problems they also realized that in order to fix the design problems inherit in TclTk they must learn an obscure and mostly useless language... TclTk!! -------------------------------- Utterly destroyed by the Ugly! -------------------------------- And then the people became very angry... "What a double cross!" they chanted. Why should we learn a language like TclTk just to fix problems that the TclTk folks need to fix themselves? Would not that time be more wisely spent in looking over code that is 100% Python and modifying it? Not only would our community benefit but we can propagate the maintainece and/or improvements to a wider group of folks by removing the high entrance requirements. When we elevate every python programmer to a PythonGUI maintainer then we will have achieved community nirvana! We have now reached a point where the very simplicity we have embraced (Tkinter) has become a stumbling block not only for the users of Tkinter, but more devastating is the damage this TCL/Tk monkey has done to keep our fellow Python brothers and sisters from learning how a GUI kit works (behind the scenes) with each OS to bring all this graphical stuff to life. ------------------------ So what should we do? ------------------------ The answer is simple. We need a 100% Python GUI. A GUI coded in Python from top to bottom. A GUI that is cross platform to the big three (Windows, Linux, and Mac). A GUI that not only is easy as Tkinter but also a GUI that can be manipulated by the average python programmer. A GUI that not only teaches the fundamentals of using a GUI, but also a GUI that teaches how a GUI works under the hood Then and only then will Python be truly what GvR intended. I want everyone here to consider what i am proposing and offer some opinions because it is time for change. From katie at coderstack.co.uk Wed Dec 29 19:07:16 2010 From: katie at coderstack.co.uk (Katie T) Date: Thu, 30 Dec 2010 00:07:16 +0000 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> Message-ID: On Wed, Dec 29, 2010 at 11:58 PM, rantingrick wrote: > > Then and only then will Python be truly what GvR intended. I want > everyone here to consider what i am proposing and offer some opinions > because it is time for change. What's your opinion of the other gui toolkits with Python bindings like PyQt and PyGtk? Katie -- CoderStack http://www.coderstack.co.uk/perl-jobs The Software Developer Job Board From rantingrick at gmail.com Wed Dec 29 19:15:54 2010 From: rantingrick at gmail.com (rantingrick) Date: Wed, 29 Dec 2010 16:15:54 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> Message-ID: <18c2f4d8-0cce-4cdf-a386-80831dc2f114@m37g2000vbn.googlegroups.com> On Dec 29, 6:07?pm, Katie T wrote: > On Wed, Dec 29, 2010 at 11:58 PM, rantingrick wrote: > > What's your opinion of the other gui toolkits with Python bindings > like PyQt and PyGtk? Hello KateT, Well i like wxPython as it is quite well rounded but we all know it has some shortcomings too and wx is far too bloated for the stdlib! pyQt and pyGtk i cannot comment on because i have no experience with them. However i need to stress that my intention is towards a 100% Python GUI. Not a binding, not a wrapping (except for OS calls!) but a *real* Python GUI. The only thing that i know of at this point is pyGUI although there are probably others. Allowing the average Python programmer the ability to read OS specific calls written in Python would not only benefit their GUI knowledge, but also there knowledge of OS's in general. I guess you could sum it as "Getting the most bang for your community buck". From alex.kapps at web.de Wed Dec 29 19:34:32 2010 From: alex.kapps at web.de (Alexander Kapps) Date: Thu, 30 Dec 2010 01:34:32 +0100 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> Message-ID: <4D1BD398.3070003@web.de> On 30.12.2010 00:58, rantingrick preached: > > Tkinter: The good, the bad, and the ugly! > ----------------------------------------- > An expose by rantingrick You are seriously starting to sound like Xah Lee. > our beloved dictator (Mr. Van Rossum) had the foresight to include a simplistic GUI toolkit that we call Tkinter > into the stdlib. And he saw that it was great, and that it was good, and so he rested. For a technocrat (and that's an insult, in my book), you have a really annoying bible-style type of speech (or do you just play too much WoW?). Would you please stop to consider your own, what 4 or 5, years of programming experience to be enough to judge on such reasons? Some thought-food for you: What other GUI toolkit even just *could* had been included by Pan, Jesus, Mohammed, Budda, or God herself? (it's *your* wording that makes me include such names) > The answer is simple. We need a 100% Python GUI. How many times did you say that now? Have you done anything to archive that goal? Have you even tried to support existing projects? I'm going to bet my right arm, that you haven't. > Then and only then will Python be truly what GvR intended. I must admit, you keep true with yourself and even advance on that. Now you not only claim to speech for the whole Python community, but for Guide himself. Sorry, but how megalomaniac are you? From greno at verizon.net Wed Dec 29 19:41:43 2010 From: greno at verizon.net (Gerry Reno) Date: Wed, 29 Dec 2010 19:41:43 -0500 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: <18c2f4d8-0cce-4cdf-a386-80831dc2f114@m37g2000vbn.googlegroups.com> References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <18c2f4d8-0cce-4cdf-a386-80831dc2f114@m37g2000vbn.googlegroups.com> Message-ID: <4D1BD547.3090707@verizon.net> wxPython looks good but I don't see anyone developing support for things like smartphones. Also, what do you think about frameworks such as pyjamas? It lets you write in python and compiles everything down to Javascript so it can be used across the Web as well as on the desktop. From orasnita at gmail.com Wed Dec 29 19:48:59 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Thu, 30 Dec 2010 02:48:59 +0200 Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> Message-ID: <4208D3E6AF924DDABBC2411E051E7DB2@teddy> From: "rantingrick" > Back in the early days of Python --when this simplistic beauty of > programming bliss we enjoy today was just a tiny glimmer of hope in a > archaic world plagued by dark forest of braces and jagged caverns of > cryptic syntaxes-- our beloved dictator (Mr. Van Rossum) had the > foresight to include a simplistic GUI toolkit that we call Tkinter > into the stdlib. And he saw that it was great, and that it was good, > and so he rested. Yes, for that time it was good. > Life was good, people were happy...but darkness loomed on the > horizon... Not all the people were happy because the darkness disappeared partially for some of them and more and more blind people started to use a computer, and discovered that the Tk interfaces are absolutely inaccessible for them. > The answer is simple. We need a 100% Python GUI. A GUI coded in Python > from top to bottom. A GUI that is cross platform to the big three > (Windows, Linux, and Mac). A GUI that not only is easy as Tkinter but > also a GUI that can be manipulated by the average python programmer. A > GUI that not only teaches the fundamentals of using a GUI, but also a > GUI that teaches how a GUI works under the hood So it should be a kind of SWING library made in Python, right? It is a good idea, but it should not have the problems of SWING and in that case it would be very hard to do. First, the interface should look exactly as the native interfaces for each system named, and it should provide the same features, because otherwise the interface would look strange for all the users on all the operating systems. And of course, it should not only look OK, but it should also follow the accessibility standards for beeing accessible for screen readers also. WxPython is the best GUI because it is fast, even though it is bloated, it uses the native GUI elements on all those 3 operating systems and a relatively good accessibility for screen readers. But WxPython still have problems because not all operating systems native GUIS offer the same widgets and features and those features custom-made don't respect the accessibility standards. WxPython is fast because it is made in C - it uses the native GUI elements of the OS which are also made in C. Would a Python - only GUI have the same speed? If yes, it would be great. Octavian From orasnita at gmail.com Wed Dec 29 19:50:47 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Thu, 30 Dec 2010 02:50:47 +0200 Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> Message-ID: <893CF2EE06BA4AF79D4282AE2D475CAD@teddy> From: "Katie T" > What's your opinion of the other gui toolkits with Python bindings > like PyQt and PyGtk? > > Katie > -- They are not accessible at all for screen readers, so the programs that still use them won't be accessible to all potential users. Octavian From almar.klein at gmail.com Wed Dec 29 20:01:30 2010 From: almar.klein at gmail.com (Almar Klein) Date: Thu, 30 Dec 2010 02:01:30 +0100 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> Message-ID: On 30 December 2010 00:58, rantingrick wrote: > > Tkinter: The good, the bad, and the ugly! > ----------------------------------------- > An expose by rantingrick > > > ---------------------- > The Good > ---------------------- > Back in the early days of Python --when this simplistic beauty of > programming bliss we enjoy today was just a tiny glimmer of hope in a > archaic world plagued by dark forest of braces and jagged caverns of > cryptic syntaxes-- our beloved dictator (Mr. Van Rossum) had the > foresight to include a simplistic GUI toolkit that we call Tkinter > into the stdlib. And he saw that it was great, and that it was good, > and so he rested. > > And when the first python programmers used this gift handed down from > the gods they were pleased. They could see that all of the heavy work > of cross-platform-ism landed square on the shoulders of TCL/Tk and all > Python had to do was wrap a few methods to wield the beast we all know > as graphical user interfaces. > > Life was good, people were happy...but darkness loomed on the > horizon... > > > ---------------- > Enter the Bad > ---------------- > However as we all know there exists no real Utopian bliss without many > pitfalls and snares. Since Tkinter is just a wrapping of some TclTk > calls the people realized that they are now at the perilous mercy of > another group of developers (psst: thats the TCL folks!) who have only > their own goals and dreams in mind and could care less for the > troubles of others. They realized that Tkinter was lacking. However > this lacking was not Tkinters fault, no, the fault lye with TclTk. And > to compound these problems they also realized that in order to fix the > design problems inherit in TclTk they must learn an obscure and mostly > useless language... TclTk!! > > -------------------------------- > Utterly destroyed by the Ugly! > -------------------------------- > And then the people became very angry... "What a double cross!" they > chanted. Why should we learn a language like TclTk just to fix > problems that the TclTk folks need to fix themselves? Would not that > time be more wisely spent in looking over code that is 100% Python and > modifying it? Not only would our community benefit but we can > propagate the maintainece and/or improvements to a wider group of > folks by removing the high entrance requirements. When we elevate > every python programmer to a PythonGUI maintainer then we will have > achieved community nirvana! > > We have now reached a point where the very simplicity we have embraced > (Tkinter) has become a stumbling block not only for the users of > Tkinter, but more devastating is the damage this TCL/Tk monkey has > done to keep our fellow Python brothers and sisters from learning how > a GUI kit works (behind the scenes) with each OS to bring all this > graphical stuff to life. > > ------------------------ > So what should we do? > ------------------------ > The answer is simple. We need a 100% Python GUI. A GUI coded in Python > from top to bottom. A GUI that is cross platform to the big three > (Windows, Linux, and Mac). A GUI that not only is easy as Tkinter but > also a GUI that can be manipulated by the average python programmer. A > GUI that not only teaches the fundamentals of using a GUI, but also a > GUI that teaches how a GUI works under the hood > > Then and only then will Python be truly what GvR intended. I want > everyone here to consider what i am proposing and offer some opinions > because it is time for change. > -- > http://mail.python.org/mailman/listinfo/python-list > A lot of ranting indeed... I agree that Tk has a few shortcomings (I never use it myself), but since many people are currently using it, I don't see an easy way of replacing Tk with anything else. FWIW, I like the ideas of FLTK (very lightweight, just draw all widgets itself + has good OpenGl support), although the project seems to have lost its momentum. I think that you are suggesting something like that, but written in Python. Almar -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrick at gmail.com Wed Dec 29 20:03:38 2010 From: rantingrick at gmail.com (rantingrick) Date: Wed, 29 Dec 2010 17:03:38 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <18c2f4d8-0cce-4cdf-a386-80831dc2f114@m37g2000vbn.googlegroups.com> Message-ID: On Dec 29, 6:41?pm, Gerry Reno wrote: > wxPython looks good but I don't see anyone developing support for things > like smartphones. No wx is not the answer to our problems > Also, what do you think about frameworks such as pyjamas? ?It lets you > write in python and compiles everything down to Javascript so it can be > used across the Web as well as on the desktop. Hmm, this is like two double edged swords smashing one another in battle. Sword One: On one hand web frameworks are going to be really big soon -- however legacy GUI's are not going away any time soon! Sword Two: On the other hand web frameworks provide awesome cross platform ability that is surly only going to get better as time goes -- however i utterly hate JavaScript (although much worse web languages exist!). And sending requests back and forth between Python, JavaScript, and BrowserX is also a real PITA. Because even though everyone knows this is coming all the major browsers are trying to insert their API into the mix. So that Joe Scripter has to write code that is compatible between many browsers. Until the world agrees on a unified API --AND IMPLEMENTS IT SERIOUSLY-- we are at the mercy of drunken sailors at the helm. I believe pyjamas has a bright future in the web playground, however we still need to focus our community efforts towards a Python based GUI. I can see a pythonGUI and pyjamas existing side by side in mutual harmony for many years. From stef.mientki at gmail.com Wed Dec 29 21:05:35 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Thu, 30 Dec 2010 03:05:35 +0100 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <18c2f4d8-0cce-4cdf-a386-80831dc2f114@m37g2000vbn.googlegroups.com> Message-ID: <4D1BE8EF.8030900@gmail.com> On 30-12-2010 02:03, rantingrick wrote: > On Dec 29, 6:41 pm, Gerry Reno wrote: >> wxPython looks good but I don't see anyone developing support for things >> like smartphones. > No wx is not the answer to our problems Just partial ;-) Why not write a (Pythonic) wrapper and choose what will be under neat it ? My personal situation at this moment: * for desktop applications we basically use wxPython * the use of sizers in wxPython is not easy and full of cross-pointers with useless names. Therefor we already used a wrapper for wxPython. * for components missing in wxPython, we embed PySide-QT and Delphi components in wxPython * for server-side web applications we use web2py * for client-side web applications we use PyJamas * for mobile devices we use PocketPyGUI * as PySide-QT is making a huge progress at the moment and has improved licenses, (and might be usable for mobile devices) we might want to move gradually from wxPython to PySide-QT Right at this moment, I'm writing a new wrapper, that already can handle (in a simple way) wxPython and PySide-QT(partial). After this works fully, PyJamas and Web2pY will be added (PockectPyGui can probably fully be replaced by QT) cheers, Stef -------------- next part -------------- An HTML attachment was scrubbed... URL: From hankfay at gmail.com Wed Dec 29 21:11:12 2010 From: hankfay at gmail.com (Hank Fay) Date: Wed, 29 Dec 2010 18:11:12 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: Message-ID: <6f2af238-2d5c-4d81-8adf-02d6e782ebae@glegroupsg2000goo.googlegroups.com> 1) pyjamas has a desktop version. 2) I don't consider JSONRpc to be a deal-breaker, and since that's what pyjamas uses naturally, and since it's incredibly easy to use the Python middleware of your choice for the JSONRpc server, running in different browsers is unlikely to be an issue. 3) I don't think legacy apps should be a consideration in deciding what tooling is going to be built today: building for all the yesterdays is a recipe for stagnation. Besides, the legacy apps have their own toolsets for maintenance: if they are to be converted, converting them to a form that can run anywhere (using, e.g., PhoneGap to access native UI hooks) seems to me the best choice. That said, pyjamas has only the beginnings of a visual designer (pyjsglade at http://sourceforge.net/projects/pyjsglade/). It's being written in Python, too, which should please you (as it does me -- so much so that I volunteered to be a documenter for the project). I think pyjamas combined with pyjsglade could be the foundation for a pythonic ui development environment that could carry us forward for many years to come, unlike those available today in Python. Hank PS: At first I thought you were going to do a riff on "The Plan" from years ago. I had broken 5 ribs in multiple places in a bicycling accident 2 days before when a friend faxed it to me (it was that far back): I can't tell you how much it hurt to laugh so hard. But this isn't a laughing matter: I see it as the main impediment to opening up Python to the kinds of programmers who used Access, VB6 and VFP to build the kinds of domain-knowledge-specific apps that continue to enhance many workplaces. From hankfay at gmail.com Wed Dec 29 21:11:12 2010 From: hankfay at gmail.com (Hank Fay) Date: Wed, 29 Dec 2010 18:11:12 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: Message-ID: <6f2af238-2d5c-4d81-8adf-02d6e782ebae@glegroupsg2000goo.googlegroups.com> 1) pyjamas has a desktop version. 2) I don't consider JSONRpc to be a deal-breaker, and since that's what pyjamas uses naturally, and since it's incredibly easy to use the Python middleware of your choice for the JSONRpc server, running in different browsers is unlikely to be an issue. 3) I don't think legacy apps should be a consideration in deciding what tooling is going to be built today: building for all the yesterdays is a recipe for stagnation. Besides, the legacy apps have their own toolsets for maintenance: if they are to be converted, converting them to a form that can run anywhere (using, e.g., PhoneGap to access native UI hooks) seems to me the best choice. That said, pyjamas has only the beginnings of a visual designer (pyjsglade at http://sourceforge.net/projects/pyjsglade/). It's being written in Python, too, which should please you (as it does me -- so much so that I volunteered to be a documenter for the project). I think pyjamas combined with pyjsglade could be the foundation for a pythonic ui development environment that could carry us forward for many years to come, unlike those available today in Python. Hank PS: At first I thought you were going to do a riff on "The Plan" from years ago. I had broken 5 ribs in multiple places in a bicycling accident 2 days before when a friend faxed it to me (it was that far back): I can't tell you how much it hurt to laugh so hard. But this isn't a laughing matter: I see it as the main impediment to opening up Python to the kinds of programmers who used Access, VB6 and VFP to build the kinds of domain-knowledge-specific apps that continue to enhance many workplaces. From ben+python at benfinney.id.au Wed Dec 29 23:04:21 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 30 Dec 2010 15:04:21 +1100 Subject: Building sys.path at run-time? References: Message-ID: <87k4irhpoa.fsf@benfinney.id.au> Roy Smith writes: > I've got a problem that I'm sure many people have solved many times. > > Our project has a bunch of python scripts A very common problem. The solution is to switch to Perl. (Merry solstice silliness, everyone :-) -- \ ?An idea isn't responsible for the people who believe in it.? | `\ ?Donald Robert Perry Marquis | _o__) | Ben Finney From roy at panix.com Wed Dec 29 23:24:09 2010 From: roy at panix.com (Roy Smith) Date: Wed, 29 Dec 2010 23:24:09 -0500 Subject: Building sys.path at run-time? References: <87k4irhpoa.fsf@benfinney.id.au> Message-ID: In article <87k4irhpoa.fsf at benfinney.id.au>, Ben Finney wrote: > Roy Smith writes: > > > I've got a problem that I'm sure many people have solved many times. > > > > Our project has a bunch of python scripts > > A very common problem. The solution is to switch to Perl. > > (Merry solstice silliness, everyone :-) I have another problem. I hit the "Post" button by accident. Please ignore. From steve+comp.lang.python at pearwood.info Thu Dec 30 02:09:49 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Dec 2010 07:09:49 GMT Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> Message-ID: <4d1c303d$0$29967$c3e8da3$5496439d@news.astraweb.com> On Wed, 29 Dec 2010 15:58:53 -0800, rantingrick wrote: > Tkinter: The good, the bad, and the ugly! > ----------------------------------------- > An expose by rantingrick Your ideas are intriguing to me and I wish to subscribe to your newsletter. > The answer is simple. We need a 100% Python GUI. A GUI coded in Python > from top to bottom. A GUI that is cross platform to the big three > (Windows, Linux, and Mac). A GUI that not only is easy as Tkinter but > also a GUI that can be manipulated by the average python programmer. A > GUI that not only teaches the fundamentals of using a GUI, but also a > GUI that teaches how a GUI works under the hood I look forward to seeing this software of yours. Let us know when you've got some code, and not just empty talk. -- Steven From s.selvamsiva at gmail.com Thu Dec 30 02:30:58 2010 From: s.selvamsiva at gmail.com (Selvam) Date: Thu, 30 Dec 2010 13:00:58 +0530 Subject: Removing an attribute from html with Regex Message-ID: Hi all, I have some HTML string which I would like to feed to BeautifulSoup. But, One malformed attribute breaks BeautifulSoup.

My String

I would like it to replace all the occurances of that attribute with an empty string. I am unable to figure out the exact regex, which can do this job. This is what, I have managed so far, m = re.compile("rml_except='([^']*)") As you see, it will stop at the first occurance of single quote. Any suggestions will be useful. -- Regards, S.Selvam SG E-ndicus Infotech Pvt Ltd. http://e-ndicus.com/ " I am because we are " -------------- next part -------------- An HTML attachment was scrubbed... URL: From wxjmfauth at gmail.com Thu Dec 30 03:13:50 2010 From: wxjmfauth at gmail.com (jmfauth) Date: Thu, 30 Dec 2010 00:13:50 -0800 (PST) Subject: Does Python 3.1 accept \r\n in compile()? References: <5c7ae38a-4302-427b-98f0-2900eaf2a974@l24g2000vby.googlegroups.com> <19d5330a-1237-4e7a-b9aa-47ce312ce8f9@d7g2000vbv.googlegroups.com> Message-ID: On 30 Dez., 00:11, Terry Reedy wrote: > On 12/29/2010 4:06 PM, jmfauth wrote: > > > > > On 29 Dez., 21:14, Terry Reedy ?wrote: > >> On 12/29/2010 2:31 PM, Terry Reedy wrote: > > >>> "Changed in version 3.2: Allowed use of Windows and Mac newlines. Also > >>> input in 'exec' mode does not have to end in a newline anymore. Added > >>> the optimize parameter." > > >> Retest shows that above is correct. > > >> ? >>> ?compile("print(999)\r\n", "blah", "exec") > > >> ?at 0x00F5EC50, file "blah", line 1> > > > Ok, I see. Thanks. > > > The '\r\n' acceptance has been introduced in Python 2.7 > > and I was a little bit suprised with Python 3.1. > > 2.6 was followed by 3.0 and then 3.1. > 2.7 will be followed by 3.2 in a couple more month. > That feature was added to 2.7 and 3.2 in Nov 2009 long after 3.1. > > -- > Terry Jan Reedy Thanks for these precisions and don't worry too much, it's not a real isssue. (I'v seen the "noise" on the pydev list). Thanks again. From smainklh at free.fr Thu Dec 30 03:36:06 2010 From: smainklh at free.fr (smainklh at free.fr) Date: Thu, 30 Dec 2010 09:36:06 +0100 Subject: os.path.isfile and wildcard for directory name Message-ID: <1293698166.4d1c447655828@imp.free.fr> Hi everyone, I'm just beginning to learn python language and i'm trying to do something and i can't figure it out. I want to test if a file exists but my path contain a directory name that differs from a server to another. In shell i would have done something like that : #!/bin/bash mypath=/dire*/directory02/ myfile=filename myfile=toto if [ -f $mypath/$myfile ] then echo "File $file exists" fi How can i do the same thing (wildcard in a directory name) in python please ? Thanks for your help ! Smaine From javier.collado at gmail.com Thu Dec 30 03:52:37 2010 From: javier.collado at gmail.com (Javier Collado) Date: Thu, 30 Dec 2010 09:52:37 +0100 Subject: os.path.isfile and wildcard for directory name In-Reply-To: <1293698166.4d1c447655828@imp.free.fr> References: <1293698166.4d1c447655828@imp.free.fr> Message-ID: Hello, 2010/12/30 : > How can i do the same thing (wildcard in a directory name) in python please ? You can get the contents of a directory with os.listdir and filter with fnmatch.fnmatch more or less as in the example from the documentation: --------------------- import fnmatch import os for file in os.listdir('.'): if fnmatch.fnmatch(file, '*.txt'): print file --------------------- Regards, Javier From stefan_ml at behnel.de Thu Dec 30 03:53:53 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 30 Dec 2010 09:53:53 +0100 Subject: Removing an attribute from html with Regex In-Reply-To: References: Message-ID: Selvam, 30.12.2010 08:30: > I have some HTML string which I would like to feed to BeautifulSoup. > > But, One malformed attribute breaks BeautifulSoup. > >

class='terp_header'> My String

Didn't try with BS (and you forgot to say what "breaks" means exactly in your case), but it parses in a somewhat reasonable way with lxml: Python 3.2b2 (py3k:87572, Dec 29 2010, 21:25:38) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import lxml.html as H >>> doc = H.fromstring(''' ...

My String

... ''') >>> H.tostring(doc) b'

My String

' >>> doc.attrib {'text2': '', 'and': '', 'style': 'terp_header', \ 'wrong_tag': ' text1 ', 'class': 'terp_header'} > I would like it to replace all the occurances of that attribute with an > empty string. > > I am unable to figure out the exact regex, which can do this job. > > This is what, I have managed so far, > > m = re.compile("rml_except='([^']*)") I assume "rml_accept" is the real name of the attribute? You may be able to do this with a look-ahead expression, e.g.: replace = re.compile('(wrong_tag\s*=\s*[^>=]*)(?=>|\s+\w+\s*=)').sub html_data = replace('', html_data) The trick is to match everything up to the next character that looks reasonable again, i.e. a closing tag character (">") or another attribute. Stefan From __peter__ at web.de Thu Dec 30 04:01:36 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 30 Dec 2010 10:01:36 +0100 Subject: os.path.isfile and wildcard for directory name References: Message-ID: smainklh at free.fr wrote: > I'm just beginning to learn python language and i'm trying to do something > and i can't figure it out. > > I want to test if a file exists but my path contain a directory name that > differs from a server to another. > In shell i would have done something like that : > > #!/bin/bash > > mypath=/dire*/directory02/ > myfile=filename > > myfile=toto > > if [ -f $mypath/$myfile ] > then > echo "File $file exists" > fi > > > How can i do the same thing (wildcard in a directory name) in python > please ? Given $ mkdir yadda{1..10} $ touch yadda{5,7}/alpha $ mkdir yadda{2,4}/alpha You can get a list of candidates with >>> import glob >>> candidates = glob.glob("yadda*/alpha") >>> candidates ['yadda5/alpha', 'yadda2/alpha', 'yadda4/alpha', 'yadda7/alpha'] and then use isfile() to find the actual files: >>> import os >>> [f for f in candidates if os.path.isfile(f)] ['yadda5/alpha', 'yadda7/alpha'] Peter From cs at zip.com.au Thu Dec 30 04:04:44 2010 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 30 Dec 2010 20:04:44 +1100 Subject: os.path.isfile and wildcard for directory name In-Reply-To: <1293698166.4d1c447655828@imp.free.fr> References: <1293698166.4d1c447655828@imp.free.fr> Message-ID: <20101230090444.GA15318@cskk.homeip.net> On 30Dec2010 09:36, smainklh at free.fr wrote: | I want to test if a file exists but my path contain a directory name that | differs from a server to another. | In shell i would have done something like that : | #!/bin/bash | mypath=/dire*/directory02/ | myfile=filename | myfile=toto | if [ -f $mypath/$myfile ] [...] Check out the glob module: http://docs.python.org/library/glob.html#module-glob Use it to do the glob, then os.path.isfile with a path constructed from the result: http://docs.python.org/library/os.path.html#os.path.isfile Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Any company large enough to have a research lab is large enough not to listen to it. - Alan Kay From grahn+nntp at snipabacken.se Thu Dec 30 04:41:25 2010 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 30 Dec 2010 09:41:25 GMT Subject: Digitally Signing a XML Document (using SHA1+RSA or SHA1+DSA) References: Message-ID: On Tue, 2010-12-28, Adam Tauno Williams wrote: > On Tue, 2010-12-28 at 03:25 +0530, Anurag Chourasia wrote: >> Hi All, > >> I have a requirement to digitally sign a XML Document using SHA1+RSA >> or SHA1+DSA >> Could someone give me a lead on a library that I can use to fulfill >> this requirement? > > Never used it though. > >> The XML Document has values such as >> -----BEGIN RSA PRIVATE KEY----- >> MIIBOgIBAAJBANWzHfF5Bppe4JKlfZDqFUpNLrwNQqguw76g/jmeO6f4i31rDLVQ >> n7sYilu65C8vN+qnEGnPB824t/A3yfMu1G0CAQMCQQCOd2lLpgRm6esMblO18WOG ... > Is this any kind of standard or just something someone made up? Is > there a namespace for the document? > > It seems quite odd that the document contains a *private* key. > > If all you need to do is parse to document to retrieve the values that > seems straight-forward enough. > >> And the XML also has another node that has a Public Key with Modules >> and Exponents etc that I apparently need to utilize. >> >> 1bMd8XkGml7gkqV9kOoVSk0uvA1CqC7DvqD >> +OZ47p/iLfWsMtVCfuxiKW7rkLy836qcQac8Hzbi38DfJ8y7UbQ== >> Aw== >> > >> I am a little thin on this concept and expecting if you could guide me >> to a library/documentation that I could utilize. [The original posting by Anurag Chourasia did not reach my news server.] I'd simply invoke GnuPG. A simple example: % gpg --sign --armor foo You need a passphrase to unlock the secret key for user: ... % head foo.asc -----BEGIN PGP MESSAGE----- Version: GnuPG v1.4.9 (GNU/Linux) owGs+TuuLdGWRQu9B1hTwsAHaRUhPjN+DjVAWBRgxs+nGAgHA58aUA88RHVw6K3N 2PfefJn5Mg2ko6N99lkrYn7G6KN//m//6//l//C/+N/8X/5P/6//+//u//r/+P/+ ... The result isn't XML, but it *is* a standardized file format readable by anyone. That's worth a lot. You can also create a detached signature and ship it together with the original file, or skip the '--armor' and get a binary signed file. If you really *do* have a requirement to make the result XML-like and incompatible with anything else, I'm afraid you're on your own, and will have a lot of extra work testing and making sure it's all secure. /Jorgen -- // Jorgen Grahn O o . From stefan_ml at behnel.de Thu Dec 30 05:23:03 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 30 Dec 2010 11:23:03 +0100 Subject: Digitally Signing a XML Document (using SHA1+RSA or SHA1+DSA) In-Reply-To: References: Message-ID: Jorgen Grahn, 30.12.2010 10:41: > If you really *do* have a requirement to make the result XML-like and > incompatible with anything else, I'm afraid you're on your own Well, there's always xmlsec if you need it. http://www.aleksey.com/xmlsec/ Stefan From sathish at solitontech.com Thu Dec 30 06:15:41 2010 From: sathish at solitontech.com (Sathish S) Date: Thu, 30 Dec 2010 16:45:41 +0530 Subject: Embedding a Python IDE on Windows based Application Message-ID: Hi Ppl, I'm trying to use python for a macro recorder. In short I have a windows based application, which has a macro recorder. The macros are captured as a python script and when the script is executed they accomplish the user action done on my application. I've written python scripts that can invoke the user events on the application through ActiveX server of my application. I've been trying to run these macro python scripts using the command line option from my application. I also explored the extending and embedding the python interpreter option for executing my python scripts from my application. But I feel it will be great if I can embed a simple xpython IDE on my application to write these macro python scripts and debug them. I tried searching for any python IDE's which are available as ActiveX or .net containers, so that I can easily embed them. But I had no success. Is there any way I can accomplish this? Thanks, Sathish -------------- next part -------------- An HTML attachment was scrubbed... URL: From smainklh at free.fr Thu Dec 30 08:35:20 2010 From: smainklh at free.fr (smainklh at free.fr) Date: Thu, 30 Dec 2010 14:35:20 +0100 Subject: os.path.isfile and wildcard for directory name In-Reply-To: <20101230090444.GA15318@cskk.homeip.net> References: <1293698166.4d1c447655828@imp.free.fr> <20101230090444.GA15318@cskk.homeip.net> Message-ID: <1293716120.4d1c8a9875275@imp.free.fr> Hi Cameron, Ok, i'll try that :) Thanks Smaine Selon Cameron Simpson : > On 30Dec2010 09:36, smainklh at free.fr wrote: > | I want to test if a file exists but my path contain a directory name that > | differs from a server to another. > | In shell i would have done something like that : > | #!/bin/bash > | mypath=/dire*/directory02/ > | myfile=filename > | myfile=toto > | if [ -f $mypath/$myfile ] > [...] > > Check out the glob module: > http://docs.python.org/library/glob.html#module-glob > > Use it to do the glob, then os.path.isfile with a path constructed from > the result: > > http://docs.python.org/library/os.path.html#os.path.isfile > > Cheers, > -- > Cameron Simpson DoD#743 > http://www.cskk.ezoshosting.com/cs/ > > Any company large enough to have a research lab > is large enough not to listen to it. - Alan Kay > From wentlv at gmail.com Thu Dec 30 08:52:06 2010 From: wentlv at gmail.com (crow) Date: Thu, 30 Dec 2010 05:52:06 -0800 (PST) Subject: Is there anyway to run JavaScript in python? Message-ID: Hi, I'm writing a test tool to simulate Web browser. Is there anyway to run JavaScript in python? Thanks in advance. From askutt at gmail.com Thu Dec 30 08:53:52 2010 From: askutt at gmail.com (Adam Skutt) Date: Thu, 30 Dec 2010 05:53:52 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> Message-ID: <1a532380-8166-4bb7-ba15-3b2f146b759d@f8g2000yqd.googlegroups.com> On Dec 29, 7:48?pm, "Octavian Rasnita" wrote: > First, the interface should look exactly as the native interfaces for each system named, and it should provide the same features, because otherwise the interface would look strange for all the users on all the operating systems. > And of course, it should not only look OK, but it should also follow the accessibility standards for beeing accessible for screen readers also. > Which is where the contradiction comes into play: to use the actual native widgets, you have to write some C (or Objective-C). Of course, on Windows, people have faked the native widgets so many times that you could probably get away with it if you made a really good fake, though there are still a lot of gotchas that go with that (accessibility and all that "other stuff"). On Linux, it's not like there's really a standard anyway. That leaves OS X as the really troublesome one. >WxPython is fast because it is made in C - it uses the native GUI elements of the OS which are also made in C. Would a Python - only GUI have the same speed? If yes, it would be great. > Speed is not even on the list of things I'd be worried about first. Adam From roy at panix.com Thu Dec 30 09:11:09 2010 From: roy at panix.com (Roy Smith) Date: Thu, 30 Dec 2010 09:11:09 -0500 Subject: Is there anyway to run JavaScript in python? References: Message-ID: In article , crow wrote: > Hi, I'm writing a test tool to simulate Web browser. Is there anyway > to run JavaScript in python? Thanks in advance. The answer to the question you asked is, "Probably. You might want to check out SpiderMonkey as a starting point". The answer to the question you didn't ask is, "Before you invest a lot of effort in this, check out Selenium". http://en.wikipedia.org/wiki/SpiderMonkey_(JavaScript_engine) http://en.wikipedia.org/wiki/Selenium_(software) Another thing to think about is whether you really do need JS to test your web app. Depending on how much your app depends on JS for its core functionality, you may find that just using urllib to fetch pages, parsing the HTML with lxml, and verifying that certain data exists in the appropriate HTML elements might get you 80% of the testing value for 20% of the effort. But, I digress. From kw at codebykevin.com Thu Dec 30 09:59:09 2010 From: kw at codebykevin.com (Kevin Walzer) Date: Thu, 30 Dec 2010 09:59:09 -0500 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> Message-ID: On 12/29/10 6:58 PM, rantingrick wrote: > The answer is simple. We need a 100% Python GUI. A GUI coded in Python > from top to bottom. A GUI that is cross platform to the big three > (Windows, Linux, and Mac). A GUI that not only is easy as Tkinter but > also a GUI that can be manipulated by the average python programmer. A > GUI that not only teaches the fundamentals of using a GUI, but also a > GUI that teaches how a GUI works under the hood Any GUI framework is going to require at least some heavy lifting in C, C++ or Objective-C (depending on the platform). A pure-Python approach to GUI development is technically infeasible. -- Kevin Walzer Code by Kevin http://www.codebykevin.com From martin at v.loewis.de Thu Dec 30 09:59:17 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Thu, 30 Dec 2010 15:59:17 +0100 Subject: Is there anyway to run JavaScript in python? In-Reply-To: References: Message-ID: <4D1C9E45.3060209@v.loewis.de> Am 30.12.2010 14:52, schrieb crow: > Hi, I'm writing a test tool to simulate Web browser. Is there anyway > to run JavaScript in python? Thanks in advance. See PyV8: http://pypi.python.org/pypi/PyV8 Regards, Martin From rantingrick at gmail.com Thu Dec 30 10:24:04 2010 From: rantingrick at gmail.com (rantingrick) Date: Thu, 30 Dec 2010 07:24:04 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> Message-ID: <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> On Dec 30, 8:59?am, Kevin Walzer wrote: > On 12/29/10 6:58 PM, rantingrick wrote: > Any GUI framework is going to require at least some heavy lifting in C, > C++ or Objective-C (depending on the platform). A pure-Python approach > to GUI development is technically infeasible. This is a very good point Kevin however i would much rather spend time learning a language like C --which is hugely useful in many contexts!-- than to waste one second of my time on a domain specific language like TCl which is created only for drawing GUIs using Tk. I think everyone can agree that learning C is of benefit far more benefit to anyone in the programming field. Also one could argue that C and Python are very similar. However Python and Tcl are like night and day. This monkey on our back (TclTk) is dead weight. We need to free ourselves of this GUI prison and bring Python into the 21st century. Tk is old and ugly. Tk is slow. Tk is incomplete and it will never be complete or extensible within our community. There is no OpenGL canvas readily available. Sure you can use Togl (as i have successfully!) however Togl is old and unmaintained. Any GUI library in this day and age must support opengl out of the box! Look, losing Tkinter will be very painful for me as i have tons of code written already. However the more i learn about Tkinter the more i realize how Tkinter is a dead end street. Why let a rotting dinosaur stagnate in the stdlib? Anybody that has foresight knows Tkinter is dying and cannot be revived. It is time to move on. Tkinter served us well for a time but we must let go and evolve -- lest we wither and die ourselves! From hankfay at gmail.com Thu Dec 30 10:28:13 2010 From: hankfay at gmail.com (Hank Fay) Date: Thu, 30 Dec 2010 07:28:13 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: Message-ID: <3dc7137f-465a-4337-a83b-57418d352485@glegroupsg2000goo.googlegroups.com> On Thursday, December 30, 2010 9:59:09 AM UTC-5, kw wrote: > Any GUI framework is going to require at least some heavy lifting in C, > C++ or Objective-C (depending on the platform). A pure-Python approach > to GUI development is technically infeasible. > > -- > Kevin Walzer > Code by Kevin > http://www.codebykevin.com So I thought. Then I came across a framework (Cappucinno.org) and a Visual Designer (280Atlas.com) written entirely in JavaScript (well, Objective-J which gets compiled to JavaScript). Check out 280Slides.com or http://githubissues.heroku.com/#280north/cappuccino for examples of what can be done using JavaScript, and 280Atlas.com for a video of their visual designer. If that designer can be written in JavasScript (it runs on the web, BTW, and only as an after-thought as a desktop app), then it can be done in Python. Having worked for 20 years in a windows-based development tool that painted controls (giving them fake hwnd's) to get enough speed to run on Windows, this was a real game-changer for me. Hank From kw at codebykevin.com Thu Dec 30 10:51:30 2010 From: kw at codebykevin.com (Kevin Walzer) Date: Thu, 30 Dec 2010 10:51:30 -0500 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> Message-ID: <49a1c$4d1caa6e$4275d90a$419@FUSE.NET> On 12/30/10 10:24 AM, rantingrick wrote: > On Dec 30, 8:59 am, Kevin Walzer wrote: >> On 12/29/10 6:58 PM, rantingrick wrote: > >> Any GUI framework is going to require at least some heavy lifting in C, >> C++ or Objective-C (depending on the platform). A pure-Python approach >> to GUI development is technically infeasible. > > > This is a very good point Kevin however i would much rather spend time > learning a language like C --which is hugely useful in many > contexts!-- than to waste one second of my time on a domain specific > language like TCl which is created only for drawing GUIs using Tk. I > think everyone can agree that learning C is of benefit far more > benefit to anyone in the programming field. Also one could argue that > C and Python are very similar. However Python and Tcl are like night > and day. Tcl is not a domain-specific language for creating GUI's. Tcl is a full-featured, general-purpose programming language that is a peer to Python in its capabilities, and surpasses Python in some respects. > > This monkey on our back (TclTk) is dead weight. We need to free > ourselves of this GUI prison and bring Python into the 21st century. > Tk is old and ugly. Tk is slow. Tk is incomplete and it will never be > complete or extensible within our community. In 2010, Tk only lacks two major features common to GUI toolkits: 1. A cross-platform printing API. This is mainly an issue on Windows, which lacks a rich command-line printing framework. The canvas widget can generate PostScript, and the text widget can export its contents to a text file, and then "lpr" can handle the rest on Unix systems (including the Mac). Still, if you want native dialogs and full integration with a platform-specific printing API, you will have to utilize one of several, incompatible, platform-specific extensions. 2. A robust widget for HTML display. The old TkHTML widget (authored by D. Richard Hipp, the author of SQLite) works, but it's very dated (last updated in 2002) and lacks modern features like CSS support. An effort to produce a next-generation HTML widget, TkHTML 3, yielded an alpha-quality widget that is enormously complex, somewhat buggy, and little used. These days, Tkinter has pretty much everything that other GUI toolkits have: tree views, multi-column listboxes, plus all the basics, available through the core widget, the themed ttk widgets, or extension packages. Today, there's no excuse for developing an ugly Tk GUI--if a new Tk app is ugly, that's a reflection on the developer, not the toolkit. > > There is no OpenGL canvas readily available. Sure you can use Togl (as > i have successfully!) however Togl is old and unmaintained. Any GUI > library in this day and age must support opengl out of the box! Togl is still developed. One of its maintainers, Greg Couch, is a developer on the UCSF Chimera project (a Python-Tkinter based molecule viewer). > Look, losing Tkinter will be very painful for me as i have tons of > code written already. However the more i learn about Tkinter the more > i realize how Tkinter is a dead end street. Why let a rotting dinosaur > stagnate in the stdlib? Anybody that has foresight knows Tkinter is > dying and cannot be revived. It is time to move on. Tkinter served us > well for a time but we must let go and evolve -- lest we wither and > die ourselves! > I have nothing against other toolkits, and if one happens to catch on, fine. But your assertions that Tkinter/Tk is dying have no basis in fact. I'm an active developer in Tk with both Tcl and Python, and the reason I have stayed with the toolkit is precisely because it isn't dying. Check out the screenshots at my website--all those GUI's are developed in Tk. Here's one in Tkinter/Python: http://www.codebykevin.com/phynchronicity-running.png --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From stefan_ml at behnel.de Thu Dec 30 10:52:22 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 30 Dec 2010 16:52:22 +0100 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> Message-ID: rantingrick, 30.12.2010 00:58: > So what should we do? > ------------------------ > The answer is simple. We need a 100% Python GUI. A GUI coded in Python > from top to bottom. A GUI that is cross platform to the big three > (Windows, Linux, and Mac). A GUI that not only is easy as Tkinter but > also a GUI that can be manipulated by the average python programmer. A > GUI that not only teaches the fundamentals of using a GUI, but also a > GUI that teaches how a GUI works under the hood I hope you invested as much time into writing this "expose" as you did searching the web before writing it. http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ (the site is currently broken for me, you can use the following instead: http://webcache.googleusercontent.com/search?q=cache:WsGrJKw6ABoJ:www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ Stefan From kw at codebykevin.com Thu Dec 30 10:57:50 2010 From: kw at codebykevin.com (Kevin Walzer) Date: Thu, 30 Dec 2010 10:57:50 -0500 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: <3dc7137f-465a-4337-a83b-57418d352485@glegroupsg2000goo.googlegroups.com> References: <3dc7137f-465a-4337-a83b-57418d352485@glegroupsg2000goo.googlegroups.com> Message-ID: <5d77f$4d1cabea$4275d90a$419@FUSE.NET> On 12/30/10 10:28 AM, Hank Fay wrote: > On Thursday, December 30, 2010 9:59:09 AM UTC-5, kw wrote: > >> Any GUI framework is going to require at least some heavy lifting in C, >> C++ or Objective-C (depending on the platform). A pure-Python approach >> to GUI development is technically infeasible. >> >> -- >> Kevin Walzer >> Code by Kevin >> http://www.codebykevin.com > > So I thought. Then I came across a framework (Cappucinno.org) and a Visual Designer (280Atlas.com) written entirely in JavaScript (well, Objective-J which gets compiled to JavaScript). Check out 280Slides.com or http://githubissues.heroku.com/#280north/cappuccino for examples of what can be done using JavaScript, and 280Atlas.com for a video of their visual designer. If that designer can be written in JavasScript (it runs on the web, BTW, and only as an after-thought as a desktop app), then it can be done in Python. > > Having worked for 20 years in a windows-based development tool that painted controls (giving them fake hwnd's) to get enough speed to run on Windows, this was a real game-changer for me. > > Hank > Yes, this is slick, and it looks nearly native, but, um...it's still running inside a browser. It's not a desktop app. -- Kevin Walzer Code by Kevin http://www.codebykevin.com From aahz at pythoncraft.com Thu Dec 30 11:01:52 2010 From: aahz at pythoncraft.com (Aahz) Date: 30 Dec 2010 08:01:52 -0800 Subject: How to initialize each multithreading Pool worker with an individual value? References: Message-ID: In article , Valery Khamenya wrote: > >However it doesn't look possible to use it to initialize each Pool's >worker with some individual value (I'd wish to be wrong here) > >So, how to initialize each multithreading Pool worker with the >individual values? > >The typical use case might be a connection pool, say, of 3 workers, >where each of 3 workers has its own TCP/IP port. > >from multiprocessing.pool import Pool > >def port_initializer(_port): > global port > port = _port > >def use_connection(some_packet): > global _port > print "sending data over port # %s" % port > >if __name__ == "__main__": > ports=((4001,4002, 4003), ) > p = Pool(3, port_initializer, ports) # oops... :-) You probably can't use initargs here. Your port_initializer needs to be some kind of class instance that works with multiprocessing and emits one port number when its __call__() method gets invoked. (There may be other ways to accomplish the same effect, but that's what springs to mind.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Think of it as evolution in action." --Tony Rand From kw at codebykevin.com Thu Dec 30 11:02:02 2010 From: kw at codebykevin.com (Kevin Walzer) Date: Thu, 30 Dec 2010 11:02:02 -0500 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> Message-ID: <1045b$4d1cad0c$4275d90a$10596@FUSE.NET> On 12/30/10 10:52 AM, Stefan Behnel wrote: > rantingrick, 30.12.2010 00:58: >> So what should we do? >> ------------------------ >> The answer is simple. We need a 100% Python GUI. A GUI coded in Python >> from top to bottom. A GUI that is cross platform to the big three >> (Windows, Linux, and Mac). A GUI that not only is easy as Tkinter but >> also a GUI that can be manipulated by the average python programmer. A >> GUI that not only teaches the fundamentals of using a GUI, but also a >> GUI that teaches how a GUI works under the hood > > I hope you invested as much time into writing this "expose" as you did > searching the web before writing it. > > http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ > > (the site is currently broken for me, you can use the following instead: > > http://webcache.googleusercontent.com/search?q=cache:WsGrJKw6ABoJ:www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ This library isn't much different from other Python GUI toolkits--it's dependent on underlying, rather large, platform-specific implementations--but it provides an even higher level of abstraction. On the Mac, it is dependent on PyObjC; on Windows, pywin32; and on X11, pygtk. In short, it's a wrapper over other wrappers. -- Kevin Walzer Code by Kevin http://www.codebykevin.com From rantingrick at gmail.com Thu Dec 30 11:02:46 2010 From: rantingrick at gmail.com (rantingrick) Date: Thu, 30 Dec 2010 08:02:46 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> Message-ID: On Dec 30, 9:52?am, Stefan Behnel wrote: > I hope you invested as much time into writing this "expose" as you did > searching the web before writing it. And ditto to you. If you would have followed the thread so far, in my second post i said... """However i need to stress that my intention is towards a 100% Python GUI. Not a binding, not a wrapping (except for OS calls!) but a *real* Python GUI. The only thing that i know of at this point is pyGUI although there are probably others."""[198:203] From stefan_ml at behnel.de Thu Dec 30 11:31:04 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 30 Dec 2010 17:31:04 +0100 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> Message-ID: rantingrick, 30.12.2010 17:02: > On Dec 30, 9:52 am, Stefan Behnel wrote: > >> I hope you invested as much time into writing this "expose" as you did >> searching the web before writing it. > > in my second post i said... > > """However i need to stress that my intention is towards a 100% Python > GUI. Not a binding, not a wrapping (except for OS calls!) but a *real* > Python GUI. The only thing that i know of at this point is pyGUI > although there are probably others.""" Sure, fine, just making sure you know the terrain. If that's not enough for you, you should follow Steven's advice to get started implementing something, because this may become a lengthy undertaking. Stefan From python at bdurham.com Thu Dec 30 12:03:54 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 30 Dec 2010 12:03:54 -0500 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: <49a1c$4d1caa6e$4275d90a$419@FUSE.NET> References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com><56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <49a1c$4d1caa6e$4275d90a$419@FUSE.NET> Message-ID: <1293728634.14849.1412816669@webmail.messagingengine.com> > These days, Tkinter has pretty much everything that other GUI toolkits have: tree views, multi-column listboxes, plus all the basics, available through the core widget, the themed ttk widgets, or extension packages. ***Today, there's no excuse for developing an ugly Tk GUI--if a new Tk app is ugly, that's a reflection on the developer, not the toolkit*** +1 (emphasis added) Other tk/ttk benefits: - Very stable - Cross platform (w/native look and feel via Python 2.7/3.1 ttk) - Light weight - Easy to distribute - Extensible Regarding lack of print support: All GUI frameworks suck in this regard. The best approach is to use a technology designed for generating hard copy output - something like PDF, TeX, or RTF library. Malcolm From awilliam at whitemice.org Thu Dec 30 12:17:14 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Thu, 30 Dec 2010 12:17:14 -0500 Subject: How to initialize each multithreading Pool worker with an individual value? In-Reply-To: References: Message-ID: <1293729434.7735.8.camel@linux-yu4c.site> On Thu, 2010-12-30 at 08:01 -0800, Aahz wrote: > In article , > Valery Khamenya wrote: > >However it doesn't look possible to use it to initialize each Pool's > >worker with some individual value (I'd wish to be wrong here) > >So, how to initialize each multithreading Pool worker with the > >individual values? > >The typical use case might be a connection pool, say, of 3 workers, > >where each of 3 workers has its own TCP/IP port. > >from multiprocessing.pool import Pool > >def port_initializer(_port): > > global port > > port = _port > >def use_connection(some_packet): > > global _port > > print "sending data over port # %s" % port > >if __name__ == "__main__": > > ports=((4001,4002, 4003), ) > > p = Pool(3, port_initializer, ports) # oops... :-) > You probably can't use initargs here. Your port_initializer needs to be > some kind of class instance that works with multiprocessing and emits one > port number when its __call__() method gets invoked. (There may be other > ways to accomplish the same effect, but that's what springs to mind.) Maybe this is obvious; but it is possible to create a pool of workers all listening on the same socket. An idle worker will pick-up the connection. Just open the socket in the initial process and then fork your workers - they will inherit the file handle and can accept() on it. From rantingrick at gmail.com Thu Dec 30 12:36:05 2010 From: rantingrick at gmail.com (rantingrick) Date: Thu, 30 Dec 2010 09:36:05 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <49a1c$4d1caa6e$4275d90a$419@FUSE.NET> Message-ID: <6028c783-e960-417d-894d-7afe87f6a2e7@s9g2000vby.googlegroups.com> On Dec 30, 9:51?am, Kevin Walzer wrote: > > Tcl is not a domain-specific language for creating GUI's. Tcl is a > full-featured, general-purpose programming language that is a peer to > Python in its capabilities, Anybody can gloat and gush about their favorite programming language however what separates fantasy from reality is evidence of these "theories". Or rather, Illusions of grandeur! > and surpasses Python in some respects. The only thing that Tcl has over Python is building Tk GUI's. Please post evidence otherwise if you dare! In the meantime i will not be holding my breath. > In 2010, Tk only lacks two major features common to GUI toolkits: > > 1. A cross-platform printing API. This is mainly an issue on Windows, > which lacks a rich command-line printing framework. True windows has no "one-liner" "send-to-print-function" but what it does have is GDI and GDI+ which are far more powerful for windows programmers. Sure you may have to issue a few dc.MoveTo(x,y) and dc.LineTo(x,y) and dc.TextOut(blah) but what is so hard about that? Really, if you want a one liner just wrap up some Python code into a nice interface. This argument is either completely bogus or utterly idiotic. > 2. A robust widget for HTML display. The fact that Tkinter lacks an HTML widget is of no concern to me. Actually if i had a choice of including HTML support or not i would opt for not. Why? Because the simple fact is that Python needs a simplistic GUI and not bloat-ware in the stdlib. HTML widgets, handy dandy anolog clocks, happy faces and dancing bananas widgets belong in 3rd party extension library's and not in the Python stdlib. However we must make sure that any GUI we support not only has these widgets available as extension libraries but that these libraries are currently maintained. If you are going to complain about lacking widgets then Togl would be a good starting point. > These days, Tkinter has pretty much everything that other GUI toolkits > have: tree views, multi-column listboxes, plus all the basics, available > through the core widget, the themed ttk widgets, or extension packages. > Today, there's no excuse for developing an ugly Tk GUI--if a new Tk app > is ugly, that's a reflection on the developer, not the toolkit. Yes Tk is not all bad for TclTk, however it IS all bad for Python. Let the Tcl folks use Tk and we will use a python GUI. Nuff said. > Togl is still developed. One of its maintainers, Greg Couch, is a > developer on the UCSF Chimera project (a Python-Tkinter based molecule > viewer). Have you seen the code in togl.py yourself? I mean really read it from beginning to end? It's a hodgepodge of poorly written code. I know this because i had to update the code myself for one of my projects. Look i have nothing against you Kevin. However i know you and Tkinter (and Tcl) are in bed together. So this is more of a *personal* decision for you instead of a *community* decision. Whether Tkinter exists in the stdlib or not should't matter to you because you can just download it from a 3rd party site. And *if* enough people really love Tkinter as you suggest then removing it will not kill it. However you know as well as i do that Tkinter is a drain on this community and the only thing keeping it alive is the fact that it is packaged in the stdlib. Once Tkinter is removed it will die as it should and something better will take it's place. Something more Pythonic. And most importantly something that is completely and totally under the direct control of the Python community. From rantingrick at gmail.com Thu Dec 30 13:04:19 2010 From: rantingrick at gmail.com (rantingrick) Date: Thu, 30 Dec 2010 10:04:19 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <1045b$4d1cad0c$4275d90a$10596@FUSE.NET> Message-ID: On Dec 30, 10:02?am, Kevin Walzer wrote: > >http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ > This library isn't much different from other Python GUI toolkits--it's > dependent on underlying, rather large, platform-specific > implementations--but it provides an even higher level of abstraction. On > the Mac, it is dependent on PyObjC; ?on Windows, pywin32; and on X11, > pygtk. In short, it's a wrapper over other wrappers. hmm. And what is Tkinter exactly? And more importantly how is it better than pyGUI (design wise)? And even more importanly, how will it be better in the long run? Is this just more FUD Kevin "Gates"? From python at bdurham.com Thu Dec 30 13:05:48 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 30 Dec 2010 13:05:48 -0500 Subject: Tkinter accessability options (was Re: Tkinter: The good, the bad, and the ugly!) In-Reply-To: <4208D3E6AF924DDABBC2411E051E7DB2@teddy> References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <4208D3E6AF924DDABBC2411E051E7DB2@teddy> Message-ID: <1293732348.1669.1412824707@webmail.messagingengine.com> Octavian, > Not all the people were happy because the darkness disappeared partially for some of them and more and more blind people started to use a computer, and discovered that the Tk interfaces are absolutely inaccessible for them. Might this package help? (I have no experience with this project) Tka11y 0.1.1 - accessibility-aware Tkinter http://pypi.python.org/pypi/Tka11y Another idea: Use Tkinters events to speak TTS descriptions of the current control and/or its contents? I would love to hear from anyone using either of techniques ... or other techniques or screen reader products ... to make their Tkinter applications accessible to low vision/blind users. Malcolm From hankfay at gmail.com Thu Dec 30 13:08:23 2010 From: hankfay at gmail.com (Hank Fay) Date: Thu, 30 Dec 2010 10:08:23 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: <5d77f$4d1cabea$4275d90a$419@FUSE.NET> Message-ID: That (the desktop app issue) was the big game-change for me. It looks like a desktop app, it acts like a desktop app, and our enterprise customers would be delighted to a) have no installs to do for fat clients; or b) not have to run a TS or Citrix farm. From orasnita at gmail.com Thu Dec 30 14:13:59 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Thu, 30 Dec 2010 21:13:59 +0200 Subject: Tkinter: The good, the bad, and the ugly! References: Message-ID: From: "Hank Fay" Subject: Re: Tkinter: The good, the bad, and the ugly! > That (the desktop app issue) was the big game-change for me. It looks like a desktop app, it acts like a desktop app, and our enterprise customers would be delighted to a) have no installs to do for fat clients; or b) not have to run a TS or Citrix farm. > It looks like a desktop app, but it doesn't fully act like a desktop app. Not all the computer users are using a mouse and not all of them can see, but the good desktop apps are very accessible for those users who can't do those things. Octavian From orasnita at gmail.com Thu Dec 30 14:18:43 2010 From: orasnita at gmail.com (Octavian Rasnita) Date: Thu, 30 Dec 2010 21:18:43 +0200 Subject: Tkinter accessability options (was Re: Tkinter: The good, the bad, and the ugly!) References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <4208D3E6AF924DDABBC2411E051E7DB2@teddy> <1293732348.1669.1412824707@webmail.messagingengine.com> Message-ID: <77CB511375AB4D75A8E67881C866DB90@teddy> From: Subject: Tkinter accessability options (was Re: Tkinter: The good, the bad, and the ugly!) > Octavian, > >> Not all the people were happy because the darkness disappeared partially for some of them and more and more blind people started to use a computer, and discovered that the Tk interfaces are absolutely inaccessible for them. > > Might this package help? (I have no experience with this project) > > Tka11y 0.1.1 - accessibility-aware Tkinter > http://pypi.python.org/pypi/Tka11y > > Another idea: Use Tkinters events to speak TTS descriptions of > the current control and/or its contents? > > I would love to hear from anyone using either of techniques ... or other > techniques or screen reader products ... to make their Tkinter > applications accessible to low vision/blind users. > > Malcolm Thank you very much for those projects! I will test them. Unfortunately they are not a solution because if I want to create an accessible app I can do it using an accessible library, but if the other programmers of the world use a non-accessible by default GUI, than their programs won't be accessible, or they will offer a limited accessibility like Java Access Bridge offers to SWING-based apps. If Tkinter would use that project that should offer the accessibility by default, that would be a real solution. Octavian From devplayer at gmail.com Thu Dec 30 14:26:50 2010 From: devplayer at gmail.com (DevPlayer) Date: Thu, 30 Dec 2010 11:26:50 -0800 (PST) Subject: default argument in method References: <4d0955ae$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9f77af4a-83b0-47b6-9e38-5ac5d2214c66@29g2000yqq.googlegroups.com> There's some_object.some_method.func_defaults and some_function.func_defaults both are a settable attribute. How to set the methods func_defaults? You'd have to have code in _getattribute__(yourmethod) if not __getattr__(yourmethod) def __getattribute__(self, attr): if attr == self.my_method: # something like this, but i'm probably a little off # you might need to use super or something to prevent recursive __getattribute__ calls here self.my_method.func_defaults = self.foo From steve+comp.lang.python at pearwood.info Thu Dec 30 14:51:48 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Dec 2010 19:51:48 GMT Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> Message-ID: <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> On Thu, 30 Dec 2010 07:24:04 -0800, rantingrick wrote: > Also one could argue that C and Python are very similar. One could also argue that black is white, that diamond is softer than chalk, and that bananas are a type of spaceship. Doesn't make it so. How to add two numbers in C: #include int main() { int a, b; scanf("%d%d", &a, &b); printf("%d\n", a + b); return 0; } And in Python: a, b = input().split() # use raw_input in Python 2 print(int(a) + int(b)) And in Tcl: scan [gets stdin] "%d %d" x y puts [expr {$x + $y}] None of the three are exactly clones of each other, but it seems to me that Tcl and Python are quite close in spirit, if not syntax. -- Steven From tjreedy at udel.edu Thu Dec 30 15:03:41 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 30 Dec 2010 15:03:41 -0500 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: <49a1c$4d1caa6e$4275d90a$419@FUSE.NET> References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <49a1c$4d1caa6e$4275d90a$419@FUSE.NET> Message-ID: On 12/30/2010 10:51 AM, Kevin Walzer wrote: > In 2010, Tk only lacks two major features common to GUI toolkits: > > 1. A cross-platform printing API. This is mainly an issue on Windows, > which lacks a rich command-line printing framework. The canvas widget > can generate PostScript, Uh. 1. Postscript is somewhat obsolete; being superseded somewhat by svg. 2. It is not as useful on Windows as it seems to be on *nux and macs -- not easy to either view or print. 3. The files it calls '.eps' are not readable by OOo. They can be read by Photoshop, which can then write a file, supposedly the same but actually not, that *can* be read by OOo. There was a thread on this list about the issue. I do not know whether tk is too sloppy in what it writes (and the file I look for a trivial drawing did look sloppy, with lots of near repetition) or whether OOo is too strict. But clearly, TK *could* write better .eps files (like Photoshop does). And the current output is clearly limited for my purposes. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Thu Dec 30 15:03:55 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Dec 2010 20:03:55 GMT Subject: default argument in method References: <4d0955ae$0$29997$c3e8da3$5496439d@news.astraweb.com> <9f77af4a-83b0-47b6-9e38-5ac5d2214c66@29g2000yqq.googlegroups.com> Message-ID: <4d1ce5ab$0$29968$c3e8da3$5496439d@news.astraweb.com> On Thu, 30 Dec 2010 11:26:50 -0800, DevPlayer wrote: > There's some_object.some_method.func_defaults Not quite -- method objects don't expose the function attributes directly. You need some_object.some_method.im_func to get the function object, which then has a func_defaults attribute. > and > some_function.func_defaults both are a settable attribute. How to set > the methods func_defaults? (1) You shouldn't mess with func_defaults unless you know what you're doing. (2) If you do know what you are doing, you probably won't want to mess with func_defaults. (3) But if you insist, then you would so the same way you would set any other object's attribute. >>> class C(object): ... def method(self, x=[]): ... print x ... >>> C().method() [] >>> function = inst.method.im_func >>> function.func_defaults ([],) >>> function.func_defaults = ("spam",) >>> inst.method() spam (4) Seriously, don't do this. > You'd have to have code in > _getattribute__(yourmethod) if not __getattr__(yourmethod) > > def __getattribute__(self, attr): > if attr == self.my_method: > # something like this, but i'm probably a little off > # you might need to use super or something to prevent > recursive __getattribute__ calls here > self.my_method.func_defaults = self.foo *cries* A much better solution would be: class MyClass: def my_method(self, x=None): if x is None: x = self.foo ... Don't write slow, confusing, complex, convoluted, self-modifying code when you can write fast, simple, straight-forward, obvious code. Unless you're doing it to win a bet. -- Steven From mwilson at the-wire.com Thu Dec 30 15:26:39 2010 From: mwilson at the-wire.com (Mel) Date: Thu, 30 Dec 2010 15:26:39 -0500 Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Thu, 30 Dec 2010 07:24:04 -0800, rantingrick wrote: > >> Also one could argue that C and Python are very similar. > > One could also argue that black is white, that diamond is softer than > chalk, and that bananas are a type of spaceship. Doesn't make it so. > > How to add two numbers in C: > > #include > int main() > { > int a, b; > scanf("%d%d", &a, &b); > printf("%d\n", a + b); > return 0; > } > > And in Python: > > a, b = input().split() # use raw_input in Python 2 > print(int(a) + int(b)) > > > And in Tcl: > > scan [gets stdin] "%d %d" x y > puts [expr {$x + $y}] > > > None of the three are exactly clones of each other, but it seems to me > that Tcl and Python are quite close in spirit, if not syntax. They both have the interpreter spirit. Very different under the hood; Tcl is the LISP of strings. They could have called it STRP. Mel. From harijay at gmail.com Thu Dec 30 16:46:35 2010 From: harijay at gmail.com (harijay) Date: Thu, 30 Dec 2010 13:46:35 -0800 (PST) Subject: OSError: [Errno 26] Text file busy during subprocess.check_call() :seems os dependent Message-ID: <7592441b-301d-4c98-bcb5-56b32947ade1@d8g2000yqf.googlegroups.com> Hi, I am writing some multithreaded code which aims to automate three sequential data processing applications and distribute the processing on my 16GB RAM, 64 bit Ubuntu box running Python 2.6.5 The basic class that orchestrates these jobs use Queue.Queue() to feed the product of the first job into the Queue for the next job. Each Thread receives a dynamically generated shell script from some classes I wrote and then runs the script using subprocess.call(["shell_script_file.sh"]) I tested the code on a mac laptop and also on ubuntu. Curiously on Mac OSX 32 bit Core duo running snow leopard, the code always runs fine. However on my ubuntu box I get sporadic errors detailed below. I tried replacing the subprocess.call() with subprocess.Popen(["shellscriptfile.sh"],stdout=open("unique_process_id.log","w"),stderr=open("unique_error_log.log","w") But I get the same "OSError: [Errno 26] Text file busy" error Everytime I run the same job queue a different part of the job fails. Unfortunately I dont see anybody else reporting this OSError. ANy help in troubleshooting my "newbie" thread code will be greatly appreciated. Thanks hari The orchestrator class is at: https://github.com/harijay/auriga/blob/master/process_multi.py A sample thread subclass is at : https://github.com/harijay/auriga/blob/master/scatomtzrunthread.py Detailed error: Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python2.6/threading.py", line 532, in __bootstrap_inner self.run() File "/home/hari/Dropbox/auriga/scatomtzrunthread.py", line 28, in run stat = subprocess.call([file]) File "/usr/lib/python2.6/subprocess.py", line 480, in call return Popen(*popenargs, **kwargs).wait() File "/usr/lib/python2.6/subprocess.py", line 633, in __init__ errread, errwrite) File "/usr/lib/python2.6/subprocess.py", line 1139, in _execute_child raise child_exception OSError: [Errno 26] Text file busy From tshinnic at io.com Thu Dec 30 17:34:11 2010 From: tshinnic at io.com (Thomas L. Shinnick) Date: Thu, 30 Dec 2010 16:34:11 -0600 Subject: OSError: [Errno 26] Text file busy during subprocess.check_call() :seems os dependent In-Reply-To: <7592441b-301d-4c98-bcb5-56b32947ade1@d8g2000yqf.googlegrou ps.com> References: <7592441b-301d-4c98-bcb5-56b32947ade1@d8g2000yqf.googlegroups.com> Message-ID: <64.94.12606.7E80D1D4@hrndva-omtalb.mail.rr.com> At 03:46 PM 12/30/2010, harijay wrote: >Hi, >I am writing some multithreaded code which aims to automate three >sequential data processing applications and distribute the processing >on my 16GB RAM, 64 bit Ubuntu box running Python 2.6.5 > >The basic class that orchestrates these jobs use Queue.Queue() to feed >the product of the first job into the Queue for the next job. > >Each Thread receives a dynamically generated shell script from some >classes I wrote and then runs the script using > >subprocess.call(["shell_script_file.sh"]) You say dynamically generated. Any chance you are (re)using the same filename each time? Is it possible that two uses of that filename could occur at the same time? That is, is it possible that at the same time while one process is running from the script file, another process is trying to re-write the script file? And so maybe you need to have dynamically generated and unique filenames Most often I see references to binary executable files for the error message, but I've also seen references to script files, e.g. http://www.cyberciti.biz/faq/binbash-bad-interpreter-text-file-busy/ >I tested the code on a mac laptop and also on ubuntu. Curiously on Mac >OSX 32 bit Core duo running snow leopard, the code always runs fine. >However on my ubuntu box I get sporadic errors detailed below. > >I tried replacing the >subprocess.call() with > >subprocess.Popen(["shellscriptfile.sh"],stdout=open("unique_process_id.log","w"),stderr=open("unique_error_log.log","w") > >But I get the same "OSError: [Errno 26] Text file busy" error > >Everytime I run the same job queue a different part of the job fails. > >Unfortunately I dont see anybody else reporting this OSError. ANy help >in troubleshooting my "newbie" thread code will be greatly >appreciated. > >Thanks >hari > >The orchestrator class is at: >https://github.com/harijay/auriga/blob/master/process_multi.py > >A sample thread subclass is at : >https://github.com/harijay/auriga/blob/master/scatomtzrunthread.py > > >Detailed error: > >Exception in thread Thread-1: >Traceback (most recent call last): > File "/usr/lib/python2.6/threading.py", line 532, in >__bootstrap_inner > self.run() > File "/home/hari/Dropbox/auriga/scatomtzrunthread.py", line 28, in >run > stat = subprocess.call([file]) > File "/usr/lib/python2.6/subprocess.py", line 480, in call > return Popen(*popenargs, **kwargs).wait() > File "/usr/lib/python2.6/subprocess.py", line 633, in __init__ > errread, errwrite) > File "/usr/lib/python2.6/subprocess.py", line 1139, in >_execute_child > raise child_exception >OSError: [Errno 26] Text file busy From kw at codebykevin.com Thu Dec 30 17:44:10 2010 From: kw at codebykevin.com (Kevin Walzer) Date: Thu, 30 Dec 2010 17:44:10 -0500 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: <6028c783-e960-417d-894d-7afe87f6a2e7@s9g2000vby.googlegroups.com> References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <49a1c$4d1caa6e$4275d90a$419@FUSE.NET> <6028c783-e960-417d-894d-7afe87f6a2e7@s9g2000vby.googlegroups.com> Message-ID: On 12/30/10 12:36 PM, rantingrick wrote: > On Dec 30, 9:51 am, Kevin Walzer wrote: >> >> Tcl is not a domain-specific language for creating GUI's. Tcl is a >> full-featured, general-purpose programming language that is a peer to >> Python in its capabilities, > > Anybody can gloat and gush about their favorite programming language > however what separates fantasy from reality is evidence of these > "theories". Or rather, Illusions of grandeur! You can build web servers, database tools, FTP clients, test suite/automation tools, chat clients, and drivers of other CLI tools with Tcl, just to name a few. In terms of what can be done with the language, I'm not aware of anything that can be done in Python that can't be done in Tcl. The size of Python's community and its large standard library are an advantage over Tcl. While Tcl is technically capable of many things, it's often easier to find a Python library already coded for specific functions--for instance, while Tcl has XML parsing and can parse RSS, it doesn't have a rich library like feedparser all wrapped up and ready to go. > >> and surpasses Python in some respects. > > The only thing that Tcl has over Python is building Tk GUI's. Please > post evidence otherwise if you dare! In the meantime i will not be > holding my breath. I find that Tcl's "everything is a string" representation offers a more flexible and expressive approach in certain contexts. Tcl's "exec" function makes interacting with external tools simpler than os.popen and subprocess--I can get the output of a command with less code. Of course, this is partly a matter of taste. --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From tjreedy at udel.edu Thu Dec 30 17:46:17 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 30 Dec 2010 17:46:17 -0500 Subject: OSError: [Errno 26] Text file busy during subprocess.check_call() :seems os dependent In-Reply-To: <7592441b-301d-4c98-bcb5-56b32947ade1@d8g2000yqf.googlegroups.com> References: <7592441b-301d-4c98-bcb5-56b32947ade1@d8g2000yqf.googlegroups.com> Message-ID: On 12/30/2010 4:46 PM, harijay wrote: > "OSError: [Errno 26] Text file busy" error Searching 'errno 26', the third Google response suggests that you are trying to write to a file (especially an executable or shared library?) that is already in use. Perhaps just trying to read when locked will trigger? -- Terry Jan Reedy From rantingrick at gmail.com Thu Dec 30 18:12:21 2010 From: rantingrick at gmail.com (rantingrick) Date: Thu, 30 Dec 2010 15:12:21 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> On Dec 30, 1:51?pm, Steven D'Aprano wrote: > How to add two numbers in C: > > [...snip code example...] > > None of the three are exactly clones of each other, but it seems to me > that Tcl and Python are quite close in spirit, if not syntax. Yes i'll agree to that if you also agree that Python and Perl are the same. Then i "maybe" your "suggestion" holds water, maybe. But you forgot to comment on the other big point which is... What language would you rather spend your time learning if you only had C and Tcl to choose from? If you answer Tcl you are either foolish or just trying to win the argument by playing devils advocate, and in that case you're even more foolish! The moral is that C and Python are far more useful to any programmer than Tcl will ever be -- whether you consider them together or apart does not matter. Tcl is too limited whereas Python and especially C are far more useful in various situations. From rantingrick at gmail.com Thu Dec 30 18:17:57 2010 From: rantingrick at gmail.com (rantingrick) Date: Thu, 30 Dec 2010 15:17:57 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <49a1c$4d1caa6e$4275d90a$419@FUSE.NET> <6028c783-e960-417d-894d-7afe87f6a2e7@s9g2000vby.googlegroups.com> Message-ID: On Dec 30, 4:44?pm, Kevin Walzer wrote: > You can build web servers, database tools, FTP clients, test > suite/automation tools, chat clients, and drivers of other CLI tools > with Tcl, just to name a few. Ok, thats swell. But do you have any real examples, links, or some evidence of this? Or are we witnessing more wishful thinking? > In terms of what can be done with the > language, I'm not aware of anything that can be done in Python that > can't be done in Tcl. Again the proof is in the pudding my friend! > The size of Python's community and its large standard library are an > advantage over Tcl. Yes, go on... > While Tcl is technically capable of many things, > it's often easier to find a Python library already coded for specific > functions--for instance, while Tcl has XML parsing and can parse RSS, it > doesn't have a rich library like feedparser all wrapped up and ready to go. Thanks, well i must say that it it getting easier to win this argument. > I find that Tcl's "everything is a string" representation offers a more > flexible and expressive approach in certain contexts. Maybe but that is hardly going to "woo" the masses is it? > Tcl's "exec" > function makes interacting with external tools simpler than os.popen and > subprocess--I can get the output of a command with less code. Newsflash!, NewsFlash!, Python has an exec function. Am i missing something here? :) > Of course, this is partly a matter of taste. Well your posts so far are leaning heavily that way Kevin :) From joncle at googlemail.com Thu Dec 30 18:51:20 2010 From: joncle at googlemail.com (Jon Clements) Date: Thu, 30 Dec 2010 15:51:20 -0800 (PST) Subject: Building sys.path at run-time? References: <87k4irhpoa.fsf@benfinney.id.au> Message-ID: <758cd28c-d6c9-4b37-8467-26d62ae4e90b@30g2000yql.googlegroups.com> On Dec 30, 4:24?am, Roy Smith wrote: > In article <87k4irhpoa.... at benfinney.id.au>, > ?Ben Finney wrote: > > > Roy Smith writes: > > > > I've got a problem that I'm sure many people have solved many times. > > > > Our project has a bunch of python scripts > > > A very common problem. The solution is to switch to Perl. > > > (Merry solstice silliness, everyone :-) > > I have another problem. ?I hit the "Post" button by accident. ?Please > ignore. Sorry all, festive joy and all that. +1 for a laugh that your problem is "[a] bunch of python scripts", and another +1 'cos "I have another problem"... Damn it, if this was 10-15 years ago, with bash.org/qdb.us etc..., I'd have posted that... Thanks Roy for the laugh, Jon. From arndt.roger at addcom.de Thu Dec 30 18:55:21 2010 From: arndt.roger at addcom.de (Arndt Roger Schneider) Date: Fri, 31 Dec 2010 00:55:21 +0100 Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <18c2f4d8-0cce-4cdf-a386-80831dc2f114@m37g2000vbn.googlegroups.com> Message-ID: rantingrick schrieb: > On Dec 29, 6:41 pm, Gerry Reno wrote: > >>wxPython looks good but I don't see anyone developing support for things >>like smartphones. > > > No wx is not the answer to our problems > Rather: ... to *your* problem... > >>Also, what do you think about frameworks such as pyjamas? It lets you >>write in python and compiles everything down to Javascript so it can be >>used across the Web as well as on the desktop. > > > Hmm, this is like two double edged swords smashing one another in > battle. > > Sword One: On one hand web frameworks are going to be really big soon > -- however legacy GUI's are not going away any time soon! There are enough out there in the wild, they will last quite for awhile indeed; but it's time for them to die. > > Sword Two: On the other hand web frameworks provide awesome cross > platform ability that is surly only going to get better as time goes > -- however i utterly hate JavaScript (although much worse web > languages exist!). And sending requests back and forth between Python, > JavaScript, Apparently the authors do know that, too: MessageID:, *sigh* no svg. BTW: Look in comp.lang.javascript: javascript is framework/toolkit resistent. and BrowserX is also a real PITA. Because even though > everyone knows this is coming all the major browsers are trying to > insert their API into the mix. So that Joe Scripter has to write code > that is compatible between many browsers. Until the world agrees on a > unified API --AND IMPLEMENTS IT SERIOUSLY-- we are at the mercy of > drunken sailors at the helm. svg: opera, chrome, safari(including ios), ie9, firefox. Although svg is missing under webkit/android --Apple kept the hardware accelerated part to themeselves. Goolge is currently implementing hardware acceleration for svg in chrome/webkit, likewise Microsoft/ie. Lets wait and see when svg becomes available in android, too. Although smil is quiet another subject. > > I believe pyjamas has a bright future in the web playground, however > we still need to focus our community efforts towards a Python based > GUI. I can see a pythonGUI and pyjamas existing side by side in mutual > harmony for many years. > pyjamas: Perhaps without javascript. -roger From harijay at gmail.com Thu Dec 30 18:59:40 2010 From: harijay at gmail.com (harijay) Date: Thu, 30 Dec 2010 15:59:40 -0800 (PST) Subject: OSError: [Errno 26] Text file busy during subprocess.check_call() :seems os dependent References: <7592441b-301d-4c98-bcb5-56b32947ade1@d8g2000yqf.googlegroups.com> Message-ID: I am writing to a unique script file . Each script file has prefixes like script1.sh script2.sh and they reside in different directories . The scripts will never trample each other since they are all sequential and shell scripts and no directory will have more than one shell script. The only thing I am doing is dir1 and dir2 will each have a script1.sh . But that still makes it mutually exclusive paths. Hari On Dec 30, 5:34?pm, "Thomas L. Shinnick" wrote: > At 03:46 PM 12/30/2010, harijay wrote: > > >Hi, > >I am writing some multithreaded code which aims to automate three > >sequential data processing applications and distribute the processing > >on my 16GB RAM, 64 bit Ubuntu box running Python 2.6.5 > > >The basic class that orchestrates these jobs use Queue.Queue() to feed > >the product of the first job into the Queue for the next job. > > >Each Thread receives a dynamically generated shell script from some > >classes I wrote and then runs the script using > > >subprocess.call(["shell_script_file.sh"]) > > You say dynamically generated. ?Any chance you are (re)using the same > filename each time? ?Is it possible that two uses of that filename > could occur at the same time? ?That is, is it possible that at the > same time while one process is running from the script file, another > process is trying to re-write the script file? ?And so maybe you need > to have dynamically generated and unique filenames > > Most often I see references to binary executable files for the error > message, but I've also seen references to script files, e.g. > ? ? ?http://www.cyberciti.biz/faq/binbash-bad-interpreter-text-file-busy/ > > > > >I tested the code on a mac laptop and also on ubuntu. Curiously on Mac > >OSX 32 bit Core duo running snow leopard, the code always runs fine. > >However on my ubuntu box I get sporadic errors detailed below. > > >I tried replacing the > >subprocess.call() with > > >subprocess.Popen(["shellscriptfile.sh"],stdout=open("unique_process_id.log ","w"),stderr=open("unique_error_log.log","w") > > >But I get the same "OSError: [Errno 26] Text file busy" ?error > > >Everytime I run the same job queue a different part of the job fails. > > >Unfortunately I dont see anybody else reporting this OSError. ANy help > >in troubleshooting my "newbie" thread code will be greatly > >appreciated. > > >Thanks > >hari > > >The orchestrator class is at: > >https://github.com/harijay/auriga/blob/master/process_multi.py > > >A sample thread subclass is at : > >https://github.com/harijay/auriga/blob/master/scatomtzrunthread.py > > >Detailed error: > > >Exception in thread Thread-1: > >Traceback (most recent call last): > > ? File "/usr/lib/python2.6/threading.py", line 532, in > >__bootstrap_inner > > ? ? self.run() > > ? File "/home/hari/Dropbox/auriga/scatomtzrunthread.py", line 28, in > >run > > ? ? stat = subprocess.call([file]) > > ? File "/usr/lib/python2.6/subprocess.py", line 480, in call > > ? ? return Popen(*popenargs, **kwargs).wait() > > ? File "/usr/lib/python2.6/subprocess.py", line 633, in __init__ > > ? ? errread, errwrite) > > ? File "/usr/lib/python2.6/subprocess.py", line 1139, in > >_execute_child > > ? ? raise child_exception > >OSError: [Errno 26] Text file busy From kw at codebykevin.com Thu Dec 30 19:01:04 2010 From: kw at codebykevin.com (Kevin Walzer) Date: Thu, 30 Dec 2010 19:01:04 -0500 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <49a1c$4d1caa6e$4275d90a$419@FUSE.NET> <6028c783-e960-417d-894d-7afe87f6a2e7@s9g2000vby.googlegroups.com> Message-ID: <9eb33$4d1d1d29$4275d90a$30950@FUSE.NET> On 12/30/10 6:17 PM, rantingrick wrote: > Ok, thats swell. But do you have any real examples, links, or some > evidence of this? Or are we witnessing more wishful thinking? http://tcl.apache.org/rivet/ http://www.amsn-project.net/ http://thecoccinella.org/ http://personal5.iddeo.es/andresgarci/tclcurl/english/ http://openacs.org/ http://www.aolserver.com/ http://www.macports.org/ http://www.nist.gov/el/msid/expect.cfm http://www.simulistics.com/ http://personal5.iddeo.es/andresgarci/getleft/english/ http://model.com/ http://sqlitestudio.one.pl/index.rvt http://www.speech.kth.se/wavesurfer/ http://www.ellogon.org/ http://moodss.sourceforge.net/ http://www.projectforum.com/ http://www.eggheads.org/ http://brlcad.org/ http://www.muonics.com/ -- Kevin Walzer Code by Kevin http://www.codebykevin.com From sigzero at gmail.com Thu Dec 30 19:16:14 2010 From: sigzero at gmail.com (Robert) Date: Thu, 30 Dec 2010 19:16:14 -0500 Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <1045b$4d1cad0c$4275d90a$10596@FUSE.NET> Message-ID: On 2010-12-30 13:04:19 -0500, rantingrick said: > On Dec 30, 10:02?am, Kevin Walzer wrote: > >>> http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ > >> This library isn't much different from other Python GUI toolkits--it's >> dependent on underlying, rather large, platform-specific >> implementations--but it provides an even higher level of abstraction. On >> the Mac, it is dependent on PyObjC; ?on Windows, pywin32; and on X11, >> pygtk. In short, it's a wrapper over other wrappers. > > > hmm. And what is Tkinter exactly? And more importantly how is it > better than pyGUI (design wise)? And even more importanly, how will it > be better in the long run? Is this just more FUD Kevin "Gates"? I am sorry, are you always an inconsiderate idiot? That is exactly what you are coming across as. -- Robert From sigzero at gmail.com Thu Dec 30 19:16:56 2010 From: sigzero at gmail.com (Robert) Date: Thu, 30 Dec 2010 19:16:56 -0500 Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> Message-ID: On 2010-12-30 11:02:46 -0500, rantingrick said: > On Dec 30, 9:52?am, Stefan Behnel wrote: > >> I hope you invested as much time into writing this "expose" as you did >> searching the web before writing it. > > And ditto to you. If you would have followed the thread so far, in my > second post i said... > > """However i need to stress that my intention is towards a 100% Python > GUI. Not a binding, not a wrapping (except for OS calls!) but a *real* > Python GUI. The only thing that i know of at this point is pyGUI > although there are probably others."""[198:203] Good luck with that. -- Robert From sigzero at gmail.com Thu Dec 30 19:32:26 2010 From: sigzero at gmail.com (Robert) Date: Thu, 30 Dec 2010 19:32:26 -0500 Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> Message-ID: On 2010-12-30 18:12:21 -0500, rantingrick said: > On Dec 30, 1:51?pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> How to add two numbers in C: >> >> [...snip code example...] >> >> None of the three are exactly clones of each other, but it seems to me >> that Tcl and Python are quite close in spirit, if not syntax. > > Yes i'll agree to that if you also agree that Python and Perl are the > same. Then i "maybe" your "suggestion" holds water, maybe. But you > forgot to comment on the other big point which is... What language > would you rather spend your time learning if you only had C and Tcl to > choose from? If you answer Tcl you are either foolish or just trying > to win the argument by playing devils advocate, and in that case > you're even more foolish! > > The moral is that C and Python are far more useful to any programmer > than Tcl will ever be -- whether you consider them together or apart > does not matter. Tcl is too limited whereas Python and especially C > are far more useful in various situations. I'll bite. Exactly how is Tcl too limited in your view? -- Robert From greno at verizon.net Thu Dec 30 19:43:21 2010 From: greno at verizon.net (Gerry Reno) Date: Thu, 30 Dec 2010 19:43:21 -0500 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> Message-ID: <4D1D2729.3070806@verizon.net> For those that are lurking, this might provide a little background: http://journal.dedasys.com/2010/03/30/where-tcl-and-tk-went-wrong Essentially, there is nothing "wrong" with Tcl and Tkinter. They are part of a long evolutionary chain of how we got to where we are today. They deserve to be respected for the contributions that they have made. The question now is whether Python needs to evolve its own GUI toolset. Regards, Gerry From rantingrick at gmail.com Thu Dec 30 19:46:24 2010 From: rantingrick at gmail.com (rantingrick) Date: Thu, 30 Dec 2010 16:46:24 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> Message-ID: <661858a7-2eaa-4ba5-a014-0805707f0a3f@p8g2000vbs.googlegroups.com> On Dec 30, 6:32?pm, Robert wrote: > Exactly how is Tcl too limited in your view? Well Robert if have explain to you why C and Python make Tcl look limited by comparison then explaining will probably do neither of us any good. But if you think Tcl is so great by all means go spend the next couple of years writing legacy code until you realize one day it was all for nothing. But let's get back on topic here shall we. I have some questions specifically for you Robert... 1. Have you ever used Tkinter? 2. If so, explain what you created with it in detail? 3. What is your opinion of Tkinter as to it's usefulness within the stdlib? 4. How long should we keep Tkinter in the stdlib? 5. Should Python even have a GUI in the stdlib? 6. If Python should have a GUI, then what traits would serve our community best? I will be really surprised if you answer any of these questions. And sorry, but i did not have time to spec out a multiple choice Q&A for you. So take your time Robert. :) From sschwarzer at sschwarzer.net Thu Dec 30 19:51:22 2010 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Fri, 31 Dec 2010 01:51:22 +0100 Subject: using python ftp In-Reply-To: References: Message-ID: <4D1D290A.7080507@sschwarzer.net> Hello Matt, On 2010-12-23 01:03, Matt Funk wrote: > i was wondering whether someone can point me whether the following > already exists. > > I want to connect to a server , download various files (for whose name i > want to be able to use a wildcard), and store those files in a given > location on the hard drive. If the file already exists i do not want to > download it. > [...] You might want to check out ftputil: http://ftputil.sschwarzer.net/ http://ftputil.sschwarzer.net/trac/wiki/Documentation > Otherwise i was going to do it "by hand" using ftplib: > 1) connect to server, > 2) change to directory on server > 3) get listing > 4) match the file pattern i want to the listing > 5) check if file already exists > 6) download file if matched and doesn't exist > > Can anyone offer any advice whether this already done somewhere? ftputil will do most of these tasks easily. For step 4 you probably want to use Python's fnmatch module, see http://docs.python.org/library/fnmatch.html . If you have questions on ftputil, there's also a mailing list: http://ftputil.sschwarzer.net/trac/wiki/MailingList (You need to be subscribed to the list to post, though.) Stefan From aahz at pythoncraft.com Thu Dec 30 19:59:09 2010 From: aahz at pythoncraft.com (Aahz) Date: 30 Dec 2010 16:59:09 -0800 Subject: Catching user switching and getting current active user from root on linux References: <3d190cbf-be7d-4973-b85f-c030bb258742@glegroupsg2000goo.googlegroups.com> Message-ID: In article , mpnordland wrote: > >First, to pacify those who hate google groups: What is a good usenet >client? trn3.6 ;-) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Think of it as evolution in action." --Tony Rand From katie at coderstack.co.uk Thu Dec 30 20:54:32 2010 From: katie at coderstack.co.uk (Katie T) Date: Fri, 31 Dec 2010 01:54:32 +0000 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: <18c2f4d8-0cce-4cdf-a386-80831dc2f114@m37g2000vbn.googlegroups.com> References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <18c2f4d8-0cce-4cdf-a386-80831dc2f114@m37g2000vbn.googlegroups.com> Message-ID: On Thu, Dec 30, 2010 at 12:15 AM, rantingrick wrote: > > However i need to stress that my intention is towards a 100% Python > GUI. Not a binding, not a wrapping (except for OS calls!) but a *real* > Python GUI. The only thing that i know of at this point is pyGUI > although there are probably others. Allowing the average Python > programmer the ability to read OS specific calls written in Python > would not only benefit their GUI knowledge, but also there knowledge > of OS's in general. It's very hard to write a good gui framework, very very few people have managed to do it well. Microsoft, Sun and Google have all had the resources to hire very good developers and designers to dedicate to the task and still haven't managed to do it well. There's not the expertise or the investment in the Python community to build a strong Python GUI solution. From an educational viewpoint I see that there could be value in having a pure Python solution, but in terms of having a GUI solution that people will actually want to use in their apps, I'm dubious that it's achievable. Katie -- CoderStack http://www.coderstack.co.uk/perl-jobs The Software Developer Job Board From data.2 at rediff.com Thu Dec 30 21:26:29 2010 From: data.2 at rediff.com (gaurav) Date: Thu, 30 Dec 2010 18:26:29 -0800 (PST) Subject: Management careers. Message-ID: Big chance in Management careers. Careers recruitment in Management work. http://topcareer.webs.com/executivemanager.htm http://topcareer.webs.com/executivemanager.htm Government Jobs in site lot of opportunities for graduates. http://rojgars1.webs.com/gov.htm http://printmediajobs.webs.com/fl.htm From sigzero at gmail.com Thu Dec 30 21:30:41 2010 From: sigzero at gmail.com (Robert) Date: Thu, 30 Dec 2010 21:30:41 -0500 Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> <4D1D2729.3070806@verizon.net> Message-ID: On 2010-12-30 19:43:21 -0500, Gerry Reno said: > For those that are lurking, this might provide a little background: > > http://journal.dedasys.com/2010/03/30/where-tcl-and-tk-went-wrong > > > > Essentially, there is nothing "wrong" with Tcl and Tkinter. They are > part of a long evolutionary chain of how we got to where we are today. > They deserve to be respected for the contributions that they have made. > > The question now is whether Python needs to evolve its own GUI toolset. > > > Regards, > Gerry You mean outside of wxPython or PySide/PyQt? I don't see the need really. -- Robert From steve+comp.lang.python at pearwood.info Thu Dec 30 21:39:38 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 31 Dec 2010 02:39:38 GMT Subject: OSError: [Errno 26] Text file busy during subprocess.check_call() :seems os dependent References: <7592441b-301d-4c98-bcb5-56b32947ade1@d8g2000yqf.googlegroups.com> Message-ID: <4d1d426a$0$29968$c3e8da3$5496439d@news.astraweb.com> On Thu, 30 Dec 2010 13:46:35 -0800, harijay wrote: [...] > But I get the same "OSError: [Errno 26] Text file busy" error > > Everytime I run the same job queue a different part of the job fails. > > Unfortunately I dont see anybody else reporting this OSError. ANy help > in troubleshooting my "newbie" thread code will be greatly appreciated. Try catching the OSError exception and inspecting the filename attribute. Something like this might help: # Untested def report_error(type, value, traceback): if type is OSError: print value.filename sys.__excepthook__(type, value, traceback) sys.excepthook = report_error -- Steven From sigzero at gmail.com Thu Dec 30 21:41:23 2010 From: sigzero at gmail.com (Robert) Date: Thu, 30 Dec 2010 21:41:23 -0500 Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> <661858a7-2eaa-4ba5-a014-0805707f0a3f@p8g2000vbs.googlegroups.com> Message-ID: On 2010-12-30 19:46:24 -0500, rantingrick said: > On Dec 30, 6:32?pm, Robert wrote: >> Exactly how is Tcl too limited in your view? > > Well Robert if have explain to you why C and Python make Tcl look > limited by comparison then explaining will probably do neither of us > any good. But if you think Tcl is so great by all means go spend the > next couple of years writing legacy code until you realize one day it > was all for nothing. You make a big assumption. That I program in Tcl. I do not. I am simply curious why you are being such a non-gentleman. If I was going to program in Tcl, I would use Gnocl (a GTk binding) and not Tk. Tcl and C will get anyone just as far as Python and C or you suck as a programmer. Just to clarify...I like Python. I am learning it at the moment. > > But let's get back on topic here shall we. I have some questions > specifically for you Robert... > > 1. Have you ever used Tkinter? Yes...nothing big though. > 2. If so, explain what you created with it in detail? Simple utilities is all. Simple meaning ~500-1000 LOC. I have done a few of those just to scratch an itch. > 3. What is your opinion of Tkinter as to it's usefulness within the > stdlib? No, I really don't see the need for it to be in the stdlib but that isn't my call. I am not a huge fan of Tk as it is. > 4. How long should we keep Tkinter in the stdlib? See the last answer. I would yank it. > 5. Should Python even have a GUI in the stdlib? I would say "no" but that is my opinion only and it doesn't matter. Python's domain isn't GUI programming so having it readily available on the sidelines would be fine for me. > 6. If Python should have a GUI, then what traits would serve our > community best? This is a good one. It should be: - cross platform - Pythonic - as "native" as possible Cross platform and native are hard. Just look at all the work with PyQt/PySide and wxPython. It took them years to get where they are. > > I will be really surprised if you answer any of these questions. And > sorry, but i did not have time to spec out a multiple choice Q&A for > you. So take your time Robert. :) Hey, there you go. At least I have real answers. :-) -- Robert From rantingrick at gmail.com Thu Dec 30 21:43:14 2010 From: rantingrick at gmail.com (rantingrick) Date: Thu, 30 Dec 2010 18:43:14 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> Message-ID: <1368b119-2af0-45d3-9a9b-b7d13440e036@p1g2000yqm.googlegroups.com> On Dec 30, 6:43?pm, Gerry Reno wrote: > For those that are lurking, this might provide a little background: > > ? ?http://journal.dedasys.com/2010/03/30/where-tcl-and-tk-went-wrong That was a great and thought provoking article Gerry. Thanks! From data.2 at rediff.com Thu Dec 30 21:47:56 2010 From: data.2 at rediff.com (gaurav) Date: Thu, 30 Dec 2010 18:47:56 -0800 (PST) Subject: Career in IT and management Message-ID: <6a2cf77e-df97-4da7-83b2-e4e0bce8256a@c13g2000prc.googlegroups.com> Latest job listing with IT manager job search and government jobs http://topcareer.webs.com/itmanagement.htm Are you looking for a job in government, this is the right place to start. http://rojgars1.webs.com/gov.htm http://printmediajobs.webs.com/fl.htm From rantingrick at gmail.com Thu Dec 30 22:06:57 2010 From: rantingrick at gmail.com (rantingrick) Date: Thu, 30 Dec 2010 19:06:57 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <18c2f4d8-0cce-4cdf-a386-80831dc2f114@m37g2000vbn.googlegroups.com> Message-ID: On Dec 30, 7:54?pm, Katie T wrote: > It's very hard to write a good gui framework, very very few people > have managed to do it well. This is a very good point Katie. Creating a Python GUI is a huge undertaking and it will take much time to work out the bugs. A truly Pythonic GUI may be (i must admit) a pipe dream at this time. However i know that unless we start thinking about something new right now, it will be two, three, ten years down the road and we will be in the same situation. A lot of folks are probably thinking that since Python3000 is here that Python is up to current technology but i must differ with that opinion. Yes Python3 is much better than the 2.x line however Tkinter and IDLE are so dated and antique that Py3000 is a bit lackluster. Look, when Guido breathed life into Tkinter many years ago he did so with good intentions. I believe at that time (and for a while after) Tkinter was an asset to this community. However, now Tkinter just looks old and dumpy. Actually i would't mind keeping Tkinter and just tweaking it a bit but that is impossible! There will always be a glass ceiling between us and Tcl. We are confined from the Tcl folks and there is nothing we can do about. Tkinter has had a decade to become more relevant in the 21st century however the Tcl folks have failed to deliver. We cannot keep depending on outsiders, we must start the transition to something better. > There's not the expertise or the investment in the Python community to > build a strong Python GUI solution. From an educational viewpoint I > see that there could be value in having a pure Python solution, but in > terms of having a GUI solution that people will actually want to use > in their apps, I'm dubious that it's achievable. Also a good point Katie. But i think i have just a little more optimism than you :). I will conceded that if we cannot build a truly Pythonic GUI then we must at least pick a GUI that is up to date with Python3000. A good choice might be a limited version of wxPython in the stdlib and a 3rd party extension module available for download. We can use Tkinter as the template. All you need in the stdlib are the same widgets that are in Tkinter now. However unlike Tkinter, now a rich 3rd party module will be available. By doing this we will have removed the glass ceiling, and we did not have to re-invent the wheel to do it. What is your opinion (or anyone) on wxPython? From rantingrick at gmail.com Thu Dec 30 22:28:39 2010 From: rantingrick at gmail.com (rantingrick) Date: Thu, 30 Dec 2010 19:28:39 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> <661858a7-2eaa-4ba5-a014-0805707f0a3f@p8g2000vbs.googlegroups.com> Message-ID: On Dec 30, 8:41?pm, Robert wrote: > On 2010-12-30 19:46:24 -0500, rantingrick said: > Just to clarify...I like Python. I am learning it at the moment. Glad to have you aboard Robert! > > 3. What is your opinion of Tkinter as to it's usefulness within the > > stdlib? > > No, I really don't see the need for it to be in the stdlib but that > isn't my call. But it is your call Robert. Anyone who writes Python code --whether they be a beginner with no prior programming experience or a fire breathing Python Guru-- has a right to inject their opinion into th community. We really need input from first time users as they carry the very perspective that we have completely lost! > > 5. Should Python even have a GUI in the stdlib? > > I would say "no" but that is my opinion only and it doesn't matter. > Python's domain isn't GUI programming so having it readily available on > the sidelines would be fine for me. I agree that Python's domain is not "specifically" GUI programming however to understand why Tkinter and IDLE exists you need to understand what Guido's dream was in the beginning. GvR wanted to bring Programming to everyone (just one of his many heroic goals!). He believed (i think) that GUI programming is very important , and that was 20 years ago!!. So he included Tkinter mainly so new Python programmers could hack away at GUI's with little or no effort. He also created a wonderful IDE for beginners called IDLE. His idea was perfect, however his faith in TclTk was flawed and so we find ourselves in the current situation we have today. With the decay of Tkinter the dream has faded. However we can revive this dream and truly bring Python into the 21st century! > > 6. If Python should have a GUI, then what traits would serve our > > community best? > > This is a good one. > > It should be: > > - cross platform > - Pythonic > - as "native" as possible > > Cross platform and native are hard. Just look at all the work with > PyQt/PySide and wxPython. It took them years to get where they are. Hmm, wxPython is starting to look like the answer to all our problems. WxPython already has an IDE so there is no need to rewrite IDLE completely. What do we have to loose by integrating wx into the stdlib, really? From greno at verizon.net Thu Dec 30 22:44:52 2010 From: greno at verizon.net (Gerry Reno) Date: Thu, 30 Dec 2010 22:44:52 -0500 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> <661858a7-2eaa-4ba5-a014-0805707f0a3f@p8g2000vbs.googlegroups.com> Message-ID: <4D1D51B4.6080707@verizon.net> On 12/30/2010 10:28 PM, rantingrick wrote: > > Hmm, wxPython is starting to look like the answer to all our problems. > WxPython already has an IDE so there is no need to rewrite IDLE > completely. What do we have to loose by integrating wx into the > stdlib, really? > > In the spirit of "batteries included", Python needs to have "something" in the stdlib as far as gui. But it cannot be overwhelming. The problem with wx is that it is BIG. And so if we want something like wx to be in the stdlib then it would have to be refactored so that there was a small basic wx that was part of stdlib and then import wx-the-whole-enchilada if you need heavy gui artillery. From sigzero at gmail.com Thu Dec 30 22:51:49 2010 From: sigzero at gmail.com (Robert) Date: Thu, 30 Dec 2010 22:51:49 -0500 Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <18c2f4d8-0cce-4cdf-a386-80831dc2f114@m37g2000vbn.googlegroups.com> Message-ID: On 2010-12-30 22:06:57 -0500, rantingrick said: > > > What is your opinion (or anyone) on wxPython? Ok, I am curious again. Have you even tried wxPython or PySide/PyQt? -- Robert From sigzero at gmail.com Thu Dec 30 22:54:33 2010 From: sigzero at gmail.com (Robert) Date: Thu, 30 Dec 2010 22:54:33 -0500 Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> <661858a7-2eaa-4ba5-a014-0805707f0a3f@p8g2000vbs.googlegroups.com> <4D1D51B4.6080707@verizon.net> Message-ID: On 2010-12-30 22:44:52 -0500, Gerry Reno said: > On 12/30/2010 10:28 PM, rantingrick wrote: >> >> Hmm, wxPython is starting to look like the answer to all our problems. >> WxPython already has an IDE so there is no need to rewrite IDLE >> completely. What do we have to loose by integrating wx into the >> stdlib, really? >> >> > > In the spirit of "batteries included", Python needs to have "something" > in the stdlib as far as gui. But it cannot be overwhelming. > > The problem with wx is that it is BIG. And so if we want something like > wx to be in the stdlib then it would have to be refactored so that there > was a small basic wx that was part of stdlib and then import > wx-the-whole-enchilada if you need heavy gui artillery. It's BIG. The question really is, do we need a GUI toolkit in the stdlib. I would say "no". In wxPython's case it is a no-brainer to install (even as a second package). I am not sure if PySide is "that easy" but it could be. -- Robert From sigzero at gmail.com Thu Dec 30 23:04:33 2010 From: sigzero at gmail.com (Robert) Date: Thu, 30 Dec 2010 23:04:33 -0500 Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> <661858a7-2eaa-4ba5-a014-0805707f0a3f@p8g2000vbs.googlegroups.com> Message-ID: On 2010-12-30 22:28:39 -0500, rantingrick said: > On Dec 30, 8:41?pm, Robert wrote: >> On 2010-12-30 19:46:24 -0500, rantingrick said: >> Just to clarify...I like Python. I am learning it at the moment. > > Glad to have you aboard Robert! Thanks! > >>> 3. What is your opinion of Tkinter as to it's usefulness within the >>> stdlib? >> >> No, I really don't see the need for it to be in the stdlib but that >> isn't my call. > > But it is your call Robert. Anyone who writes Python code --whether > they be a beginner with no prior programming experience or a fire > breathing Python Guru-- has a right to inject their opinion into th > community. We really need input from first time users as they carry > the very perspective that we have completely lost! I speak up. :-) > >>> 5. Should Python even have a GUI in the stdlib? >> >> I would say "no" but that is my opinion only and it doesn't matter. >> Python's domain isn't GUI programming so having it readily available on >> the sidelines would be fine for me. > > I agree that Python's domain is not "specifically" GUI programming > however to understand why Tkinter and IDLE exists you need to > understand what Guido's dream was in the beginning. GvR wanted to > bring Programming to everyone (just one of his many heroic goals!). He > believed (i think) that GUI programming is very important , and that > was 20 years ago!!. So he included Tkinter mainly so new Python > programmers could hack away at GUI's with little or no effort. He also > created a wonderful IDE for beginners called IDLE. His idea was > perfect, however his faith in TclTk was flawed and so we find > ourselves in the current situation we have today. With the decay of > Tkinter the dream has faded. However we can revive this dream and > truly bring Python into the 21st century! I don't think Tkinter was in there for "large" programming. Tkinter is crufty and probably should be moved out. For whipping up quick gui things to scratch an itch it is good. I lurk more on the Tcl side of things. When the mention of "separating" Tcl and Tk development, I fall on the side of separating them. Tcl, like Python should stand on its own. Widget frameworks are extras to me. One way the Tcl community has "stagnated" has been its insistence on Tk. There was a wxTcl project...it died. That would have been good for the Tcl community. Luckily there is a GTk framework (Gnocl) that is really good. But it still doesn't get the props that it deserves. The second way the Tcl community irks me is the "not invented here" attitude. I like the syntax of Tcl and I like the community. They are some good folks. Try asking "I want to build a Nagios clone in Tcl" type question and invariably you get "Why? There is already Nagios?". That stems from the "glue" language roots I think but to me that is the wrong attitude. You want people to take a look at a language (any language), you build stuff with it that people want to use. Ruby would not be as big as it is if Rails hadn't come along. Nuff of that... ;-) > > >>> 6. If Python should have a GUI, then what traits would serve our >>> community best? >> >> This is a good one. >> >> It should be: >> >> - cross platform >> - Pythonic >> - as "native" as possible >> >> Cross platform and native are hard. Just look at all the work with >> PyQt/PySide and wxPython. It took them years to get where they are. > > Hmm, wxPython is starting to look like the answer to all our problems. > WxPython already has an IDE so there is no need to rewrite IDLE > completely. What do we have to loose by integrating wx into the > stdlib, really? wxPython is really good. The downside is that is shows (or did show) its C++ roots. Nokia is making a run with PySide (their version of the PyQt framework) and since it has a company behind it might go pretty far. Qt can be used for a lot of problem domains. Anyway, I wasn't meaning to be rough with you. Just trying to figure out where you were coming from. I am acquianted with Kevin Walzer and he is a good guy. -- Robert From steve+comp.lang.python at pearwood.info Thu Dec 30 23:20:59 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 31 Dec 2010 04:20:59 GMT Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> <661858a7-2eaa-4ba5-a014-0805707f0a3f@p8g2000vbs.googlegroups.com> Message-ID: <4d1d5a2b$0$29968$c3e8da3$5496439d@news.astraweb.com> On Thu, 30 Dec 2010 23:04:33 -0500, Robert wrote: > The > second way the Tcl community irks me is the "not invented here" > attitude. I like the syntax of Tcl and I like the community. They are > some good folks. Try asking "I want to build a Nagios clone in Tcl" type > question and invariably you get "Why? There is already Nagios?". You're the one who wants to re-write Nagios in Tcl, the Tcl community are perfectly happy using the existing Nagios instead of re-inventing the wheel, and you accuse *them* of suffering from NIH syndrome. Oh the irony. -- Steven From rantingrick at gmail.com Thu Dec 30 23:24:05 2010 From: rantingrick at gmail.com (rantingrick) Date: Thu, 30 Dec 2010 20:24:05 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> <661858a7-2eaa-4ba5-a014-0805707f0a3f@p8g2000vbs.googlegroups.com> Message-ID: <6895332e-26dd-4306-ada9-d44533a3c7ab@l8g2000yqh.googlegroups.com> On Dec 30, 9:44?pm, Gerry Reno wrote: > In the spirit of "batteries included", Python needs to have "something" > in the stdlib as far as gui. ?But it cannot be overwhelming. Agreed! > The problem with wx is that it is BIG. ?And so if we want something like > wx to be in the stdlib then it would have to be refactored so that there > was a small basic wx that was part of stdlib and then import > wx-the-whole-enchilada if you need heavy gui artillery. Exactly! All we need to do is replace the existing Tkinter with a small sub-set of wxPython widgets that mirrors exactly what we have now... Toplevel Label Entry Button Radiobutton Checkbutton Canvas Textbox Listbox Menu Scale Scrollbar ...thats all you need in the std library "widget wise". The rest of what makes up wx can exist in the "wxPython Extension Library". Python needs this change! We have already made incompatible changes so now is the time to start seriously brainstorming on how we can integrate the beauty, elegance, and feature rich power of wxPython. From rantingrick at gmail.com Thu Dec 30 23:27:55 2010 From: rantingrick at gmail.com (rantingrick) Date: Thu, 30 Dec 2010 20:27:55 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <18c2f4d8-0cce-4cdf-a386-80831dc2f114@m37g2000vbn.googlegroups.com> Message-ID: <3550c472-80be-46f8-bd78-c1e814c4901f@30g2000yql.googlegroups.com> On Dec 30, 9:51?pm, Robert wrote: > Ok, I am curious again. Have you even tried wxPython or PySide/PyQt? Yes i have used wxPython on a few projects and was very happy with the feature rich nature of it. I found previously (with Tkinter) i would have to build my own compound widgets due to non-existence or just plain poor design. That was not the case in wx as it has more eye candy than i could ever put to good use ;) From askutt at gmail.com Thu Dec 30 23:41:39 2010 From: askutt at gmail.com (Adam Skutt) Date: Thu, 30 Dec 2010 20:41:39 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> <661858a7-2eaa-4ba5-a014-0805707f0a3f@p8g2000vbs.googlegroups.com> <6895332e-26dd-4306-ada9-d44533a3c7ab@l8g2000yqh.googlegroups.com> Message-ID: <7de8ad23-5613-46e4-8330-0eaa3d428935@j29g2000yqm.googlegroups.com> On Dec 30, 11:24?pm, rantingrick wrote: > > > The problem with wx is that it is BIG. ?And so if we want something like > > wx to be in the stdlib then it would have to be refactored so that there > > was a small basic wx that was part of stdlib and then import > > wx-the-whole-enchilada if you need heavy gui artillery. > > Exactly! All we need to do is replace the existing Tkinter with a > small sub-set of wxPython widgets that mirrors exactly what we have > now... > > Toplevel > Label > Entry > Button > Radiobutton > Checkbutton > Canvas > Textbox > Listbox > Menu > Scale > Scrollbar > > ...thats all you need in the std library "widget wise". The rest of > what makes up wx can exist in the ?"wxPython Extension Library". > Python needs this change! We have already made incompatible changes so > now is the time to start seriously brainstorming on how we can > integrate the beauty, elegance, and feature rich power of wxPython. I have never, ever, made a GUI that consistent only of those options excep when following a tutorial, sorry. While I won't claim to stand for anyone else, I'm hardly alone, judging by /every application running on my desktop right now/. Well, maybe notepad. Interesting applications require interesting features. Anything you end up writing is going to be at least as complicated as TkInter for the standard library, if not vastly more so, and have all of the same faults you find in TkInter. This would be because such problems are fundamentally inescapable, a simple fact of reality you have yet to even grasp, AFAICT, much yet acknowledge. Adam From rantingrick at gmail.com Thu Dec 30 23:51:16 2010 From: rantingrick at gmail.com (rantingrick) Date: Thu, 30 Dec 2010 20:51:16 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> <661858a7-2eaa-4ba5-a014-0805707f0a3f@p8g2000vbs.googlegroups.com> Message-ID: On Dec 30, 10:04?pm, Robert wrote: > wxPython is really good. The downside is that is shows (or did show) > its C++ roots. Well i will admit the api is not as simplistic as Tkinter. However i noticed over time that wx had started adopting a slight Tkinter "feel" to the API and that is a good thing. So they are coming around. :) > Anyway, I wasn't meaning to be rough with you. Just trying to figure > out where you were coming from. I am acquianted with Kevin Walzer and > he is a good guy. No harm done Robert my skin is far thicker than your average grape. We just ended up on opposite sides of a passionate argument. I hope you stick around with us because I look forward to hearing more of your opinions and ideas. And i agree that Kevin is a great guy! I've never met him but i can tell from his writing style and mannerisms that he is truly an honest and virtuous soul. And i totally understand why he wants to keep Tkinter alive as he and i both have tons of code that depends on Tkinter. I wish we could keep Tkinter forever as it really is a great starter GUI. I wrote my first GUI code with it and fell in love just like with Python! However i know we will always be lacking our full potential with Tkinter as developers and as a community. Sadly i see no other way but to replace it with something more up-to-date. Sometimes we have to "take one for the team". What is in our best interest may not necessarily be in the community's best interest. If we *do* replace Tkinter, it will be a very painful adjustment because it has been with us for such a long time. However, just as Py3000 was painful at first, and then started slowly gaining speed into a much better language, i also believe this change will move us forward into an even greater language. From rantingrick at gmail.com Fri Dec 31 00:21:19 2010 From: rantingrick at gmail.com (rantingrick) Date: Thu, 30 Dec 2010 21:21:19 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> <661858a7-2eaa-4ba5-a014-0805707f0a3f@p8g2000vbs.googlegroups.com> <6895332e-26dd-4306-ada9-d44533a3c7ab@l8g2000yqh.googlegroups.com> <7de8ad23-5613-46e4-8330-0eaa3d428935@j29g2000yqm.googlegroups.com> Message-ID: <23b1017b-2b14-457d-b4df-0219989940db@f30g2000yqa.googlegroups.com> On Dec 30, 10:41?pm, Adam Skutt wrote: > On Dec 30, 11:24?pm, rantingrick wrote: > > Exactly! All we need to do is replace the existing Tkinter with a > > small sub-set of wxPython widgets that mirrors exactly what we have > > now... > > > Toplevel > > Label > > Entry > > Button > > Radiobutton > > Checkbutton > > Canvas > > Textbox > > Listbox > > Menu > > Scale > > Scrollbar > I have never, ever, made a GUI that consistent only of those options > excep when following a tutorial, sorry. ?While I won't claim to stand > for anyone else, I'm hardly alone, judging by /every application > running on my desktop right now/. ?Well, maybe notepad. Of course a tiny widget set like this is not going to handle extensive GUI coding, thats a no brainer. But currently that is EXACTLY what we have to work with in the stdlib. Sure you have TIX and a few other extensions but they will never compare to the vast features of wxPython. Have you even aquinted yourself with wxPython Adam? What i (and others) are proposing is to replace the existing Tkinter library with a matching wxPython libray. Then allocate the remaining wxPython library (which is ginormous btw!) into a 3rd party module available for download. My argument is that because wxPython is soooo feature rich. We will break the glass ceiling that exist now with Tkinter. > Interesting applications require interesting features. ?Anything you > end up writing is going to be at least as complicated as TkInter for > the standard library, if not vastly more so, Agreed! We need at least the same capability that Tkinter offers in the stdlib. Why would we sacrifice? > and have all of the same > faults you find in TkInter. Thats not true. Yes all projects have faults of some kind. I am not suggesting that wxPython is some sort of "miracle" library. However anyone of average intelligence can do a side by side comparison and agree that wx is far superior to TclTk in many, many ways. If you have a valid argument as to how Tkinter is better feel free to share this information with us. > ?This would be because such problems are > fundamentally inescapable, a simple fact of reality you have yet to > even grasp, AFAICT, much yet acknowledge. Adam, Adam. I feel you are desperately trying to inject negative energy into what is now the very beginnings of a healthy and positive community discussion on the future of Python's GUI library. If you do care about Python's future then you should get involved with this discussion in a positive way. You can disagree with me and still be positive. I wish you would spend more energy bringing forth your own ideas and thoughtful discussion instead of resorting to these wasteful and vengeful tactics. So with that in mind i ask you some direct questions... 1. Do you use Tkinter yourself? 2. Explain some of the applications you have created with Tkinter. 3. How do you feel about Tkinter being in the stdlib? 4. Should Python even include a GUI library? 5. If so, what traits should this library encompass? 6. If you could choose what library do you think would be in the communities best interest? From nuptyu at 163.com Fri Dec 31 01:05:14 2010 From: nuptyu at 163.com (=?GBK?B?0+DBwe64?=) Date: Fri, 31 Dec 2010 14:05:14 +0800 (CST) Subject: A quesstion with matplotlib Message-ID: Dear all, I have a quesstion about change the width of the ylabel.You know the width of the ylabel is relaete to the x axi,how can i change the width of the ylabel not depend on the width of the x-axis? Thank you! George -------------- next part -------------- An HTML attachment was scrubbed... URL: From nobody at nowhere.com Fri Dec 31 01:58:01 2010 From: nobody at nowhere.com (Nobody) Date: Fri, 31 Dec 2010 06:58:01 +0000 Subject: OSError: [Errno 26] Text file busy during subprocess.check_call() :seems os dependent References: <7592441b-301d-4c98-bcb5-56b32947ade1@d8g2000yqf.googlegroups.com> Message-ID: On Thu, 30 Dec 2010 13:46:35 -0800, harijay wrote: > Each Thread receives a dynamically generated shell script from some > classes I wrote and then runs the script using > > subprocess.call(["shell_script_file.sh"]) > But I get the same "OSError: [Errno 26] Text file busy" error "Text file busy" aka ETXTBSY occurs if you try to execute a file which is open for write by any process. Be sure to explicitly close() the script before attempting to execute it. Don't rely upon the destructor closing it, as that may be deferred. Also, if you spawn any child processes, ensure that they don't inherit the descriptor being used to write to the script. Ideally, you should set the close-on-exec flag on the descriptor as soon as the file is opened. Using close_fds=True in subprocess.Popen() will solve the issue for processes spawned that way, but you also need to consider subprocesses which may be spawned "behind the scenes" by library functions. From baptiste.lepilleur at gmail.com Fri Dec 31 02:40:39 2010 From: baptiste.lepilleur at gmail.com (Baptiste Lepilleur) Date: Fri, 31 Dec 2010 08:40:39 +0100 Subject: Change in scope of handled exception variable in Python 3? Message-ID: Hi, I stumbled on a small bug with httplib2 that I reduced to the example below. It seems that with Python 3, when an exception is handled it "unbound" the previously declared local variable. This did not occurs with Python 2.5. It is a Python 3 feature? I did not find anything in the what's news, but it's hard to search... (notes: I'm using Python 3.1.2) --- def main(): msg = 'a message' try: raise ValueError( 'An error' ) except ValueError as msg: pass return msg main() python localmask.py Traceback (most recent call last): File "localmask.py", line 12, in main() File "localmask.py", line 10, in main return msg UnboundLocalError: local variable 'msg' referenced before assignment --- -------------- next part -------------- An HTML attachment was scrubbed... URL: From aman.6677 at gmail.com Fri Dec 31 02:47:17 2010 From: aman.6677 at gmail.com (Aman) Date: Thu, 30 Dec 2010 23:47:17 -0800 (PST) Subject: Python3 Web Framework Message-ID: <5a863ddc-20bf-4c00-83e6-61d4a4551c7d@c13g2000prc.googlegroups.com> Hey all... I just started with Python, and I chose Python3 because it seemed a subtle choice as compared to doing Pthon 2.x now and then porting to Python3.x later... I plan to start with Web Development soon... I wanted to know what all web frameworks are available for Python3... I heard the Django is still not compatible with 3.x... Any idea guys? From angrybaldguy at gmail.com Fri Dec 31 02:48:35 2010 From: angrybaldguy at gmail.com (Owen Jacobson) Date: Fri, 31 Dec 2010 02:48:35 -0500 Subject: Put up or shut up (Was Re: Tkinter: The good, the bad, and the ugly!) References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <49a1c$4d1caa6e$4275d90a$419@FUSE.NET> <6028c783-e960-417d-894d-7afe87f6a2e7@s9g2000vby.googlegroups.com> Message-ID: <2010123102483513840-angrybaldguy@gmailcom> On 2010-12-30 12:36:05 -0500, rantingrick said: > On Dec 30, 9:51?am, Kevin Walzer wrote: >> >> Tcl is not a domain-specific language for creating GUI's. Tcl is a >> full-featured, general-purpose programming language that is a peer to >> Python in its capabilities, > > Anybody can gloat and gush about their favorite programming language > however what separates fantasy from reality is evidence of these > "theories". Or rather, Illusions of grandeur! One: it's "delusions" of grandeur. >> and surpasses Python in some respects. > > The only thing that Tcl has over Python is building Tk GUI's. Please > post evidence otherwise if you dare! In the meantime i will not be > holding my breath. Two: were you raised in a barn? How the hell did you get so up on yourself that you think this is an okay way to respond to a perfectly civil post? Abusing people's opinions and soldiering around demanding everyone justify themselves to you is a great way to get people to ignore whatever point you were trying to make. >From your other posts, I gather that you have a very clear idea of what your ideal Python GUI framework would look like. That puts you in the best possible position to implement it. If you're successful, share it around; if it's good, it will gain traction on its own merit. You're not earning any traction on rhetorical grounds here. -o From angrybaldguy at gmail.com Fri Dec 31 03:14:44 2010 From: angrybaldguy at gmail.com (Owen Jacobson) Date: Fri, 31 Dec 2010 03:14:44 -0500 Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> Message-ID: <2010123103144482179-angrybaldguy@gmailcom> On 2010-12-30 19:43:21 -0500, Gerry Reno said: > For those that are lurking, this might provide a little background: > > http://journal.dedasys.com/2010/03/30/where-tcl-and-tk-went-wrong > > > > Essentially, there is nothing "wrong" with Tcl and Tkinter. They are > part of a long evolutionary chain of how we got to where we are today. > They deserve to be respected for the contributions that they have made. > > The question now is whether Python needs to evolve its own GUI toolset. My two cents, given freely: I'd rather have better integration with each platform's GUI libraries and desktop services than one cross-platform GUI library. There are so many fundamental differences in accepted behaviour between each of the major GUI platforms (Gnome, KDE, Mac OS, and Windows, at minimum; you could include Blackberry, iOS, and Android in here as well, if you wanted something really different) that being able to put the same window with the same widgets on all of them is of limited value. Consider Java's Swing toolkit - a passable cross-platform GUI library, whether you like its API or not. Swing apps almost *never* feel as pleasant to use as a native application, even on modern JVMs where performance isn't the problem and even using the native look & feel. Little things like keyboard shortcut conventions, mouse button conventions, and menu organization guidelines don't quite mesh. Then there are more complex issues, like process management, library packaging, software updates, and user notification, where the conventions on each platform differ more dramatically. Python's native UI capabilities, on the other hand, give programmers the tools they need to write the core of their application using portable code while being able to write a UI (or UIs) that actually takes advantage of the underlying platform's features and that plays nicely with the underlying platform's conventions and interfaces - all without switching languages. I don't see having to maintain two or three UI codebases as being that much worse than riddling a single UI codebase with conditionals or extension points for handling each platform's idiosyncracies. Fortunately for me and my opinions, Python is already shaped like that. PyObjC provides bindings for writing OS X applications; PyGTK and PyQt support Gnome and KDE respectively (as well as any other X11 desktop); PyWin32 provides passable support for Windows UIs, or you can use IronPython and .Net's GUI APIs. It is absolutely zero skin off of my nose if someone decides I'm utterly out of my tree, figures out that cross-platform GUIs are the future, and goes on to write an amazing pure-Python GUI stack that works everywhere with a colour monitor. Cheers, -o From alice at gothcandy.com Fri Dec 31 03:47:11 2010 From: alice at gothcandy.com (=?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=) Date: Fri, 31 Dec 2010 00:47:11 -0800 Subject: Python3 Web Framework References: <5a863ddc-20bf-4c00-83e6-61d4a4551c7d@c13g2000prc.googlegroups.com> Message-ID: On 2010-12-30 23:47:17 -0800, Aman said: > Hey all... I just started with Python, and I chose Python3 because it > seemed a subtle choice as compared to doing Pthon 2.x now and then > porting to Python3.x later... I plan to start with Web Development > soon... I wanted to know what all web frameworks are available for > Python3... I heard the Django is still not compatible with 3.x... Any > idea guys? Python 3 has a number of issues with web development thus far: WSGI[1] (PEP 333) isn't directly compatible with Python 3, for one. However, PEP 3333 is looking good[2] for making web framework code compatible with Python 3 without needing too much modification. I'm not sure what the state of affairs is for PEP 3333 or Python 3 compatible frameworks, however. (CherryPy -might- be compatible, I can not recall.) Basically this means that using Python 3, you'll be "roughing it" for a while. On the other hand, I'm working on PEP 444[3] (WSGI 2) and have a highly performant web server compatible with Python 3 available[4] that is compatible with PEP 444 as published on Python.org[5] (master branch) and with my rewritten draft (draft branch, to be merged when my rewrite is complete and published on Python.org). Another developer and I have been working on the WebOb-style helper exceptions and wrappers, from which a microframework can quickly spawn. The HTTP server has 100% coverage (master) and near-100% coverage (draft) and compatibility with Python 2.6+ and 3.1+. Have a great day, - Alice. [1] http://www.python.org/dev/peps/pep-0333/ [2] http://www.python.org/dev/peps/pep-3333/ [3] http://bit.ly/e7rtI6 [4] http://bit.ly/fLfamO [5] http://bit.ly/gmT17O From steve+comp.lang.python at pearwood.info Fri Dec 31 04:16:01 2010 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 31 Dec 2010 09:16:01 GMT Subject: ANN: stats0.1.2a calculator statistics for Python Message-ID: <4d1d9f51$0$29968$c3e8da3$5496439d@news.astraweb.com> I am pleased to announce the third public release of stats for Python. This is a minor point release, mostly consisting of improved tests and documentation, plus the addition of six new statistics functions: midhinge, quartile_skewness, cumulative_sum, running_sum, stderrskewness, stderrkurtosis. http://pypi.python.org/pypi/stats stats is a pure-Python module providing basic statistics functions similar to those found on scientific calculators. It has over 40 statistics functions, including: Univariate statistics: * arithmetic, harmonic, geometric and quadratic means * median, mode, midrange, trimean * mean of angular quantities * running and weighted averages * quartiles, hinges and quantiles * variance and standard deviation (sample and population) * average deviation and median average deviation (MAD) * skewness and kurtosis * standard error of the mean Multivariate statistics: * Pearson's correlation coefficient * Q-correlation coefficient * covariance (sample and population) * linear regression * sums Sxx, Syy and Sxy and others. This is an unstable alpha release of the software. Feedback and contributions are welcome. -- Steven D'Aprano From __peter__ at web.de Fri Dec 31 04:29:03 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 31 Dec 2010 10:29:03 +0100 Subject: Change in scope of handled exception variable in Python 3? References: Message-ID: Baptiste Lepilleur wrote: > I stumbled on a small bug with httplib2 that I reduced to the example > below. > > It seems that with Python 3, when an exception is handled it "unbound" the > previously declared local variable. This did not occurs with Python 2.5. > > It is a Python 3 feature? I did not find anything in the what's news, but > it's hard to search... (notes: I'm using Python 3.1.2) > > --- > def main(): > msg = 'a message' > try: > raise ValueError( 'An error' ) > except ValueError as msg: > pass > return msg > > main() > > python localmask.py > Traceback (most recent call last): > File "localmask.py", line 12, in > main() > File "localmask.py", line 10, in main > return msg > UnboundLocalError: local variable 'msg' referenced before assignment > --- Yes, that's intentional, see http://docs.python.org/dev/py3k/whatsnew/3.0.html#changes-to-exceptions http://www.python.org/dev/peps/pep-3110/#semantic-changes From python at bdurham.com Fri Dec 31 04:45:06 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 31 Dec 2010 04:45:06 -0500 Subject: Tkinter: The good, the bad, and the ugly! In-Reply-To: References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com><18c2f4d8-0cce-4cdf-a386-80831dc2f114@m37g2000vbn.googlegroups.com> Message-ID: <1293788706.6120.1412904363@webmail.messagingengine.com> Rick, > However, now Tkinter just looks old and dumpy. Have you taken a look at the ttk module (based on tile) that ships with Python 2.7/3.1? This adds native/theme-aware widgets to Tkinter. And it adds additional widgets such as a treeview (which can also be used as a grid), notebook, progressbar, scales, panedwindow (splitters), etc. The widgets in ttk match each platform's standards and look as professional as the equivalents found in wxPython/pyQt. Take a look at the screenshots on this rather long page to get an idea of what is now possible - "out-of-box" with Python 2.7/3.1. http://www.tkdocs.com/tutorial/onepage.html I've done GUI development in wxPython and pyQt, and until recently *never* considered Tkinter. Once I saw what was possible with the ttk module, I've started moving a lot of new GUI projects from these other platforms back to Tkinter/ttk (enhanced with PIL module). Why Tkinter/ttk vs. wxPython or pyQt - professional looking apps are now possible (really!) - very light weight install and distribution - works with both 2.x/3.x (not possible with wx) - very robust (wx can be finicky at times) Subjective: I also prefer Tk's geometry managers to wx's sizers even though I learned sizers first. You seem to be very enamored with wxPython. What have you found in wxPython that's not available with the latest versions of Tkinter/ttk other than an AUI equivalent and better support for RTL languages? Malcolm From xrgtn at yandex.ru Fri Dec 31 05:09:22 2010 From: xrgtn at yandex.ru (Alexander Gattin) Date: Fri, 31 Dec 2010 12:09:22 +0200 Subject: I am not able to verify the integrity of python.2.5.4.msi In-Reply-To: References: Message-ID: <20101231100922.GA18741@xrgtn-q40> Hello, On Sun, Dec 26, 2010 at 05:44:22AM +0530, Varuna Seneviratna wrote: > > D:\Python>gpg --verify python-2.5.4.msi.asc > gpg: no valid OpenPGP data found. > gpg: the signature could not be verified. > Please remember that the signature file (.sig or .asc) > should be the first file given on the command line > > What am I doing wrong in this process? probably you should try to perform LF=>CRLF conversion on the downloaded python-2.5.4.msi.asc file -- With best regards, xrgtn From tjreedy at udel.edu Fri Dec 31 05:20:47 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 31 Dec 2010 05:20:47 -0500 Subject: Python3 Web Framework In-Reply-To: References: <5a863ddc-20bf-4c00-83e6-61d4a4551c7d@c13g2000prc.googlegroups.com> Message-ID: On 12/31/2010 3:47 AM, Alice Bevan?McGregor wrote: > Python 3 has a number of issues with web development thus far: I believe some will be improved or even solved in 3.2. -- Terry Jan Reedy From flebber.crue at gmail.com Fri Dec 31 06:28:07 2010 From: flebber.crue at gmail.com (flebber) Date: Fri, 31 Dec 2010 03:28:07 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> <661858a7-2eaa-4ba5-a014-0805707f0a3f@p8g2000vbs.googlegroups.com> Message-ID: <8378996c-b463-4e99-9bc3-a19bb6208542@k14g2000pre.googlegroups.com> On Dec 31, 3:04?pm, Robert wrote: > On 2010-12-30 22:28:39 -0500, rantingrick said: > > > ?On Dec 30, 8:41???pm, Robert wrote: > >> On 2010-12-30 19:46:24 -0500, rantingrick said: > >> Just to clarify...I like Python. I am learning it at the moment. > > > Glad to have you aboard Robert! > > Thanks! > > > > >>> 3. What is your opinion of Tkinter as to it's usefulness within the > >>> stdlib? > > >> No, I really don't see the need for it to be in the stdlib but that > >> isn't my call. > > > But it is your call Robert. Anyone who writes Python code --whether > > they be a beginner with no prior programming experience or a fire > > breathing Python Guru-- has a right to inject their opinion into th > > community. We really need input from first time users as they carry > > the very perspective that we have completely lost! > > I speak up. ?:-) > > > > > > >>> 5. Should Python even have a GUI in the stdlib? > > >> I would say "no" but that is my opinion only and it doesn't matter. > >> Python's domain isn't GUI programming so having it readily available on > >> the sidelines would be fine for me. > > > I agree that Python's domain is not "specifically" GUI programming > > however to understand why Tkinter and IDLE exists you need to > > understand what Guido's dream was in the beginning. GvR wanted to > > bring Programming to everyone (just one of his many heroic goals!). He > > believed (i think) that GUI programming is very important , and that > > was 20 years ago!!. So he included Tkinter mainly so new Python > > programmers could hack away at GUI's with little or no effort. He also > > created a wonderful IDE for beginners called IDLE. His idea was > > perfect, however his faith in TclTk was flawed and so we find > > ourselves in the current situation we have today. With the decay of > > Tkinter the dream has faded. However we can revive this dream and > > truly bring Python into the 21st century! > > I don't think Tkinter was in there for "large" programming. Tkinter is > crufty and probably should be moved out. For whipping up quick gui > things to scratch an itch it is good. > > I lurk more on the Tcl side of things. When the mention of "separating" > Tcl and Tk development, I fall on the side of separating them. Tcl, > like Python should stand on its own. Widget frameworks are extras to > me. One way the Tcl community has "stagnated" has been its insistence > on Tk. There was a wxTcl project...it died. That would have been good > for the Tcl community. Luckily there is a GTk framework (Gnocl) that is > really good. But it still doesn't get the props that it deserves. The > second way the Tcl community irks me is the "not invented here" > attitude. I like the syntax of Tcl and I like the community. They are > some good folks. Try asking "I want to build a Nagios clone in Tcl" > type question and invariably you get "Why? There is already Nagios?". > That stems from the "glue" language roots I think but to me that is the > wrong attitude. You want people to take a look at a language (any > language), you build stuff with it that people want to use. Ruby would > not be as big as it is if Rails hadn't come along. > > Nuff of that... ?;-) > > > > > > >>> 6. If Python should have a GUI, then what traits would serve our > >>> community best? > > >> This is a good one. > > >> It should be: > > >> - cross platform > >> - Pythonic > >> - as "native" as possible > > >> Cross platform and native are hard. Just look at all the work with > >> PyQt/PySide and wxPython. It took them years to get where they are. > > > Hmm, wxPython is starting to look like the answer to all our problems. > > WxPython already has an IDE so there is no need to rewrite IDLE > > completely. What do we have to loose by integrating wx into the > > stdlib, really? > > wxPython is really good. The downside is that is shows (or did show) > its C++ roots. > > Nokia is making a run with PySide (their version of the PyQt framework) > and since it has a company behind it might go pretty far. Qt can be > used for a lot of problem domains. > > Anyway, I wasn't meaning to be rough with you. Just trying to figure > out where you were coming from. I am acquianted with Kevin Walzer and > he is a good guy. > > -- > Robert I thank this thread for putting me onto Pyside +1 From flebber.crue at gmail.com Fri Dec 31 09:11:17 2010 From: flebber.crue at gmail.com (flebber) Date: Fri, 31 Dec 2010 06:11:17 -0800 (PST) Subject: User input masks - Access Style References: <385bcaf1-81a5-405a-b7f0-28d7994a2e95@a28g2000prb.googlegroups.com> Message-ID: <33855355-0417-408d-b9bf-3c9a387d9eb0@21g2000prv.googlegroups.com> On Dec 28 2010, 12:21?am, Adam Tauno Williams wrote: > On Sun, 2010-12-26 at 20:37 -0800, flebber wrote: > > Is there anyay to use input masks in python? Similar to the function > > found in access where a users input is limited to a type, length and > > format. > > > > Typically this is handled by a callback on a keypress event. Can I get some clarification on the re module specifically on matching string Line 137 of the Re module def match(pattern, string, flags=0): """Try to apply the pattern at the start of the string, returning a match object, or None if no match was found.""" return _compile(pattern, flags).match(string) From flebber.crue at gmail.com Fri Dec 31 09:15:52 2010 From: flebber.crue at gmail.com (flebber) Date: Fri, 31 Dec 2010 06:15:52 -0800 (PST) Subject: User input masks - Access Style References: <385bcaf1-81a5-405a-b7f0-28d7994a2e95@a28g2000prb.googlegroups.com> Message-ID: <7a7e3beb-380a-4d09-8bf6-71a3ecac17e8@p7g2000prb.googlegroups.com> On Dec 28 2010, 12:21?am, Adam Tauno Williams wrote: > On Sun, 2010-12-26 at 20:37 -0800, flebber wrote: > > Is there anyay to use input masks in python? Similar to the function > > found in access where a users input is limited to a type, length and > > format. > > > > Typically this is handled by a callback on a keypress event. Sorry Regarding 137 of the re module, relating to the code above. # validate the input is in the correct format (usually this would be in # loop that continues until the user enters acceptable data) if re.match(r'''^[0-9]{2}:[0-9]{2}:[0-9]{2}$''', timeInput) == None: print("I'm sorry, your input is improperly formated.") sys.exit(1) EDIT: I just needed to use raw_input rather than input to stop this input error. Please enter time in the format 'MM:SS:HH': 11:12:13 Traceback (most recent call last): File "C:\Documents and Settings\renshaw\workspace\Testing\src \Time.py", line 13, in timeInput = input() File "C:\Eclipse\plugins\org.python.pydev_1.6.3.2010100422\PySrc \pydev_sitecustomize\sitecustomize.py", line 176, in input return eval(raw_input(prompt)) File "", line 1 11:12:13 ^ SyntaxError: invalid syntax From martin at v.loewis.de Fri Dec 31 09:44:10 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Fri, 31 Dec 2010 15:44:10 +0100 Subject: Python3 Web Framework In-Reply-To: <5a863ddc-20bf-4c00-83e6-61d4a4551c7d@c13g2000prc.googlegroups.com> References: <5a863ddc-20bf-4c00-83e6-61d4a4551c7d@c13g2000prc.googlegroups.com> Message-ID: <4D1DEC3A.6060905@v.loewis.de> Am 31.12.2010 08:47, schrieb Aman: > Hey all... I just started with Python, and I chose Python3 because it > seemed a subtle choice as compared to doing Pthon 2.x now and then > porting to Python3.x later... I plan to start with Web Development > soon... I wanted to know what all web frameworks are available for > Python3... I heard the Django is still not compatible with 3.x... Any > idea guys? You could try my port of Django to Py3k: https://bitbucket.org/loewis/django-3k Regards, Martin From askutt at gmail.com Fri Dec 31 09:47:53 2010 From: askutt at gmail.com (Adam Skutt) Date: Fri, 31 Dec 2010 06:47:53 -0800 (PST) Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> <661858a7-2eaa-4ba5-a014-0805707f0a3f@p8g2000vbs.googlegroups.com> <6895332e-26dd-4306-ada9-d44533a3c7ab@l8g2000yqh.googlegroups.com> <7de8ad23-5613-46e4-8330-0eaa3d428935@j29g2000yqm.googlegroups.com> <23b1017b-2b14-457d-b4df-0219989940db@f30g2000yqa.googlegroups.com> Message-ID: On Dec 31, 12:21?am, rantingrick wrote: > Of course a tiny widget set like this is not going to handle extensive > GUI coding, thats a no brainer. No, it's not going to handle any GUI coding except notepad.exe. That's already been written, so we're left with no new application that can be written with this proposed minimal widget set. Why do you think Tix exists? Why do you think there are Python bindings for it in the standard library (to say nothing of a bunch of other additional Tk controls)? > But currently that is EXACTLY what we > have to work with in the stdlib. Sure you have TIX and a few other > extensions but they will never compare to the vast features of > wxPython. Have you even aquinted yourself with wxPython Adam? > It is nothing of the sort even if you erroneously believe it is. Have you looked at Tix? The fact you dismiss it away as some "extension" like it is a leper really betrays your argument. Others (not you) have already described the legitimate deficiencies at length, I will defer to them. > ?What i (and others) are proposing is to replace the existing Tkinter > library with a matching wxPython libray. Then allocate the remaining > wxPython library (which is ginormous btw!) into a 3rd party module > available for download. My argument is that because wxPython is soooo > feature rich. We will break the glass ceiling that exist now with > Tkinter. > And what I pointed out is that wxWidgets (and Qt, and Swing, and Tk+Tix +whatever, and every other GUI toolkit in existence) is so feature rich for a reason: you actually need all of that stuff in order to build rich, functional, useful GUI applications. I think you'll find that it's very hard to cut any functionality, even functionality Python more or less entirely replicates (e.g., wxNet, wxODBC). Why? Because useful widgets rely on such low-level functionality (blame C+ +'s rather anemic standard library). Moreover, even if you find things to cut, coming to a consensus about what belongs outside of the stdlib will be difficult, if not impossible; plus, it's considerable work for very little gain: I still need a full install of wxwidgets to even build your useless minimal set. There's definitely no point in minimizing the python side of things if it doesn't minimize the native code side of things. Note how the divisions with the Tk bindings follow the divisions of the native libraries. > Agreed! We need at least the same capability that Tkinter offers in > the stdlib. Why would we sacrifice? I don't know, but a sacrifice is precisely what you proposed. > Thats not true. Yes all projects have faults of some kind. I am not > suggesting that wxPython is some sort of "miracle" library. However > anyone of average intelligence can do a side by side comparison and > agree that wx is far superior to TclTk in many, many ways. If you have > a valid argument as to how Tkinter is better feel free to share this > information with us. >From this claim I've forced to conclude you are not of average intelligence, because you haven't managed yet to do an actual, factual side-by-side comparison of wxWidgets and Tk. Here is one to start: the native footprint of Tk has fewer dependencies than the native footprint of wxWidgets. > Adam, Adam. I feel you are desperately trying to inject negative > energy into what is now the very beginnings of a healthy and positive > community discussion on the future of Python's GUI library. There's nothing positive about this discussion, since it's being spearheaded by arrogance and ignorance. It's highly improbable, in fact, for this discussion to ever be healthy and positive without a desperate attitude and behavior chance on your part. Seriously, given that widget set you listed, what applications am I supposed to write? I can't write a web browser. I can't write an audio player. I can't write a terminal. I can't write an IM client. I can't write a social media client/application/mashup. I can't write a web browser. I can't write a game community client/launcher. I can't write office productivity applications. So what can I write? The fact your proposal shows you're entirely disconnected with reality isn't my fault in the least, nor does it mean I'm "trying to inject negative energy", nor that I'm "resorting to these wasteful and vengeful tactics." You want to be told your proposal isn't disconnected with reality? Then propose ideas that actually have technical merit and that can be actually accomplished, instead of proposing things that plainly lack merit to anyone who's ever written a complicated GUI application before and/or that are flat-out impossible. Calling a bad proposal a bad proposal is a positive thing, like it or not. If you can't accept that, you should consider a pastime that involves less criticism. > If you do care about Python's future then you should get involved with this > discussion in a positive way. I have, I told you what you want to do isn't possible. The fact you don't want to nor like to hear that doesn't mean it is not positive. A pure Python GUI toolkit isn't really possible. Even if we agreed that "pure" means something akin to AWT, it's still a really awful idea (again, for really obvious reasons). Building something like WPF would be worthwhile, but won't free you from needing a traditional GUI library for quite some time, so you're still right back where we started. Replacing TkInter with some sort of minimized wxwidgets is a dumb idea for some very obvious reasons, reasons that are obvious if you simply look at a widget gallery and then the applications you run on your own computer. Quite honestly, if you're not capable of that, there's little reason to believe you'll ever be able to bring forth a coherent, cogent proposal. Adam From gervaz at gmail.com Fri Dec 31 10:22:26 2010 From: gervaz at gmail.com (gervaz) Date: Fri, 31 Dec 2010 07:22:26 -0800 (PST) Subject: String building using join Message-ID: Hi all, I would like to ask you how I can use the more efficient join operation in a code like this: >>> class Test: ... def __init__(self, v1, v2): ... self.v1 = v1 ... self.v2 = v2 ... >>> def prg(l): ... txt = "" ... for x in l: ... if x.v1 is not None: ... txt += x.v1 + "\n" ... if x.v2 is not None: ... txt += x.v2 + "\n" ... return txt ... >>> t1 = Test("hello", None) >>> t2 = Test(None, "ciao") >>> t3 = Test("salut", "hallo") >>> t = [t1, t2, t3] >>> >>> prg(t) 'hello\nciao\nsalut\nhallo\n' The idea would be create a new list with the values not None and then use the join function... but I don't know if it is really worth it. Any hint? >>> def prg2(l): ... e = [] ... for x in l: ... if x.v1 is not None: ... e.append(x.v1) ... if x.v2 is not None: ... e.append(x.v2) ... return "\n".join(e) ... >>> prg2(t) 'hello\nciao\nsalut\nhallo' Thanks, Mattia From grappale at hotmail.it Fri Dec 31 10:41:48 2010 From: grappale at hotmail.it (Ale Ghelfi) Date: Fri, 31 Dec 2010 16:41:48 +0100 Subject: kinterbasdb error connection References: Message-ID: On 09/12/2010 15:17, Uwe Grauer wrote: > On 12/07/2010 04:35 PM, Ale Ghelfi wrote: >> (i'm under Ubuntu 10.10 amd64 and python 2.6 and kinterbasdb 3.2 ) >> I try to connect my database of firebird 2.5 by kinterbasdb. >> But python return this error : > > > You are not using the current kinterbasdb version. > See: > http://firebirdsql.org/index.php?op=devel&sub=python > > Uwe > kinterbasdb 3.2.3 is the Really current version for Ubuntu 10.10 AMD64. Kinterbasdb 3.3.0 exists only for ubuntu 10.10 i386 I've check in the repository. From emile at fenx.com Fri Dec 31 10:43:27 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 31 Dec 2010 07:43:27 -0800 Subject: String building using join In-Reply-To: References: Message-ID: On 12/31/2010 7:22 AM gervaz said... > Hi all, I would like to ask you how I can use the more efficient join > operation in a code like this: > >>>> class Test: > ... def __init__(self, v1, v2): > ... self.v1 = v1 > ... self.v2 = v2 > ... >>>> def prg(l): > ... txt = "" > ... for x in l: > ... if x.v1 is not None: > ... txt += x.v1 + "\n" > ... if x.v2 is not None: > ... txt += x.v2 + "\n" > ... return txt > ... >>>> t1 = Test("hello", None) >>>> t2 = Test(None, "ciao") >>>> t3 = Test("salut", "hallo") >>>> t = [t1, t2, t3] >>>> >>>> prg(t) > 'hello\nciao\nsalut\nhallo\n' > > The idea would be create a new list with the values not None and then > use the join function... but I don't know if it is really worth it. > Any hint? > >>>> def prg2(l): return "\n".join([x for x in l if x]) Emile > ... e = [] > ... for x in l: > ... if x.v1 is not None: > ... e.append(x.v1) > ... if x.v2 is not None: > ... e.append(x.v2) > ... return "\n".join(e) > ... >>>> prg2(t) > 'hello\nciao\nsalut\nhallo' > > Thanks, Mattia From cheungtifan at gmail.com Fri Dec 31 11:34:39 2010 From: cheungtifan at gmail.com (Alex Zhang) Date: Sat, 01 Jan 2011 00:34:39 +0800 Subject: Compile on SunOS? Message-ID: Hi All, I'm trying to build Python 2.7.1 on Sun Solaris 10 amd64, however end up with: Python build finished, but the necessary bits to build these modules were not found: _bsddb _tkinter bsddb185 gdbm linuxaudiodev ossaudiodev To find the necessary bits, look in setup.py in detect_modules() for the module's name. Failed to build these modules: _bisect _codecs_cn _codecs_hk _codecs_iso2022 _codecs_jp _codecs_kr _codecs_tw _collections _csv _ctypes _ctypes_test _curses _curses_panel _elementtree _functools _hashlib _heapq _hotshot _io _json _locale _lsprof _multibytecodec _multiprocessing _random _socket _sqlite3 _ssl _struct _testcapi array audioop binascii bz2 cmath cPickle crypt cStringIO datetime dbm dl fcntl future_builtins grp imageop itertools math mmap nis operator parser pyexpat resource select spwd strop sunaudiodev syslog termios time unicodedata zlib running build_scripts I am using cc provided in Solaris 10, readline downloaded from GNU and compiled in 32bit. Also, I added this entry: readline readline.c -I/local32/include -L/local32/lib -R/local32/lib -lreadline -ltermcap to Modules/Setup.local in order to get readline running. Currently: dns# /opt/python/bin/python Python 2.7.1 (r271:86832, Dec 31 2010, 07:21:22) [C] on sunos5 Type "help", "copyright", "credits" or "license" for more information. >>> import hashlib Traceback (most recent call last): File "", line 1, in File "/opt/python/lib/python2.7/hashlib.py", line 136, in globals()[__func_name] = __get_hash(__func_name) File "/opt/python/lib/python2.7/hashlib.py", line 71, in __get_builtin_constructor import _md5 ImportError: No module named _md5 I can not use hashlib and many other modules however I can use the rest modules. Thanks for all your kind reply. -- OSQDU::Alex From nagle at animats.com Fri Dec 31 13:28:26 2010 From: nagle at animats.com (John Nagle) Date: Fri, 31 Dec 2010 10:28:26 -0800 Subject: Interrput a thread In-Reply-To: <81c24eb1-41b6-442a-a971-8a44d2cd6c1b@p8g2000vbs.googlegroups.com> References: <81c24eb1-41b6-442a-a971-8a44d2cd6c1b@p8g2000vbs.googlegroups.com> Message-ID: <4d1e20c5$0$43986$742ec2ed@news.sonic.net> On 12/29/2010 3:31 PM, gervaz wrote: > Hi all, I need to stop a threaded (using CTR+C or kill) application if > it runs too much or if I decide to resume the work later. > I come up with the following test implementation but I wanted some > suggestion from you on how I can implement what I need in a better or > more pythonic way. You can't send signals to individual threads under CPython. Even where the OS supports it, CPython does not. See "http://docs.python.org/library/signal.html" Nor can you kill a thread. All you can do is ask it nicely to stop itself. Even worse, sending control-C to a multi-thread program is unreliable in CPython. See "http://blip.tv/file/2232410" for why. It's painful. John Nagle From sigzero at gmail.com Fri Dec 31 14:01:15 2010 From: sigzero at gmail.com (Robert) Date: Fri, 31 Dec 2010 14:01:15 -0500 Subject: Tkinter: The good, the bad, and the ugly! References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> <661858a7-2eaa-4ba5-a014-0805707f0a3f@p8g2000vbs.googlegroups.com> <4d1d5a2b$0$29968$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2010-12-30 23:20:59 -0500, Steven D'Aprano said: > On Thu, 30 Dec 2010 23:04:33 -0500, Robert wrote: > >> The >> second way the Tcl community irks me is the "not invented here" >> attitude. I like the syntax of Tcl and I like the community. They are >> some good folks. Try asking "I want to build a Nagios clone in Tcl" type >> question and invariably you get "Why? There is already Nagios?". > > You're the one who wants to re-write Nagios in Tcl, the Tcl community are > perfectly happy using the existing Nagios instead of re-inventing the > wheel, and you accuse *them* of suffering from NIH syndrome. > > Oh the irony. No, that was just an example! My goodness.... -- Robert From solipsis at pitrou.net Fri Dec 31 16:52:30 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Fri, 31 Dec 2010 22:52:30 +0100 Subject: Nagios References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> <661858a7-2eaa-4ba5-a014-0805707f0a3f@p8g2000vbs.googlegroups.com> <4d1d5a2b$0$29968$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20101231225230.38992926@pitrou.net> On 31 Dec 2010 04:20:59 GMT Steven D'Aprano wrote: > On Thu, 30 Dec 2010 23:04:33 -0500, Robert wrote: > > > The > > second way the Tcl community irks me is the "not invented here" > > attitude. I like the syntax of Tcl and I like the community. They are > > some good folks. Try asking "I want to build a Nagios clone in Tcl" type > > question and invariably you get "Why? There is already Nagios?". > > You're the one who wants to re-write Nagios in Tcl, the Tcl community are > perfectly happy using the existing Nagios instead of re-inventing the > wheel, and you accuse *them* of suffering from NIH syndrome. Well, I don't know about Tcl but Nagios was re-written in Python: http://www.shinken-monitoring.org/features/ Regards Antoine. From fabiofz at gmail.com Fri Dec 31 17:03:39 2010 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Fri, 31 Dec 2010 20:03:39 -0200 Subject: Python - NAWIT / Community In-Reply-To: <2895ecca-b978-4899-9ab3-0032422b908f@o9g2000pre.googlegroups.com> References: <2895ecca-b978-4899-9ab3-0032422b908f@o9g2000pre.googlegroups.com> Message-ID: > My question relates to community contribution. My concern arose when > recently installing the pydev.org extensions in Eclipse. Now as far as > my understanding goes the licensing on both is open source GPL. > However Pydev became open source as part of aptana's acquistion, and > for the moment pydev can be installed as part of the Aptana studio 2/3 > releases individually as a plugin, but moving on if you vist the > aptana site there is sweet little about python on their site, their > site is dominated by Radrails. Just a little fix there, Pydev is open source EPL (not GPL). Also, yes, there's little content about Pydev in the Aptana homepage, but it points to the main Pydev homepage (http://pydev.org) which has the proper content related to Python (and it's currently being actively developed and also integrated in Aptana Studio 3, which is where the current efforts are targeted within Aptana now). Sorry if this causes the (wrong) perception that Pydev doesn't get as much attention. > Can't help thinking they open sourced Pydev so they could bench it. So > I started thinking that the only consistent env each python person has > is idle as it ships in the install. Sorry, but I don't follow your thoughts here... there are many consistent environments for python development which are properly supported (Pydev being only one of them as you can see at http://stackoverflow.com/questions/81584/what-ide-to-use-for-python ). > Sometimes we can contribute with money and sometimes with time, if I > was to contribute money to ensure that I and all new coming python > programmers could have a first class development environment to use > what would I donate to? At the moment no particular group seems > applicable. > > Is pydev actively being developed and for who? SPE is a great idea but > is Stan still developing? Pyscripter is good but not 64 capable. Plus > none of these projects seem community centric. I'm the current Pydev maintainer (since 2005)... and while I cannot state that I'll be in that role forever (forever is quite a long time), I do think it's well maintained and there are occasional patches from the community that uses it (although I still get to review all that goes in). > Maybe its just my wish, maybe something already exists, but to my mind > why is there not a central python community ide or plugin setup like > pydev or using pydev(since currently it is very good - to me), which I > know or at least could confidently donate time or money to further > python. > > This could apply to many python area's does python use easy_install or > pypm, well if you want camelot or zope (unless you have business > edition) its easy_install, but you wont find an ide with built in egg > or pypm support? I think the issue is that only recently (if you compare with the others) has easy_install became the de facto standard in python (so, it'd be more an issue of interest adding such a feature to the ide). > Why every Ruby ide has gems manager, and for that > fact look at netbeans, the ide is good but support for python is > mentioned on a far flung community page where some developers are > trying to maintain good python support. PS they seem to be doing a > good job, but a review of the mailing list archives shows little > activity. > One could say that activestate puts in good support but then they do > not provide an ide within the means of the average part time person > retailing its main edition at over $300, Pycharm a good ide at $99 but > then where is my money going. > > I think a community plugin architecture which contained components > like pydev, pyscripter, eclipse and eggs/pypm packages would give a > place I can contribute time as my skills grow and confidently donate > money knowing I am assisting the development of community tools and > packages we all can use. No need to reinvent the wheel most things > already exist, for example apt-get & rpm style package management time > tested and could be easily used to manage python eggs for example. > Anyway I have had my 2 cents, if someone is contributing more than I > know, and this wasn't intended to dimnish anyone's effort, just > wanting to look to growing and fostering a stronger python community. > Well, I can only comment from the Pydev side here, but do you think it'd be worth reinventing all that's already done in it just for having it in Python? When I started contributing to Pydev back in 2004 I didn't go that way because Eclipse itself has a huge community that's already in place and is properly maintained, which takes a lot of effort, so, I'm not sure it'd be worth reproducing all that just to have it 100% Python code -- I say 100% because Pydev does have a number of things that are in Python, such as the debugger and Jython for the scripting engine, although the major portion is really in java. Another important aspect is that it's much better if you can get an experience that can later be replicated to other languages (which Eclipse provides). Cheers, Fabio From alice at gothcandy.com Fri Dec 31 17:24:56 2010 From: alice at gothcandy.com (=?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=) Date: Fri, 31 Dec 2010 14:24:56 -0800 Subject: Python3 Web Framework References: <5a863ddc-20bf-4c00-83e6-61d4a4551c7d@c13g2000prc.googlegroups.com> Message-ID: On 2010-12-31 02:20:47 -0800, Terry Reedy said: > I believe some will be improved or even solved in 3.2. Evidence to back this statement up would be appreciated. ;) - Alice. From alice at gothcandy.com Fri Dec 31 17:25:57 2010 From: alice at gothcandy.com (=?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=) Date: Fri, 31 Dec 2010 14:25:57 -0800 Subject: Interrput a thread References: <81c24eb1-41b6-442a-a971-8a44d2cd6c1b@p8g2000vbs.googlegroups.com> <4d1e20c5$0$43986$742ec2ed@news.sonic.net> Message-ID: On 2010-12-31 10:28:26 -0800, John Nagle said: > Even worse, sending control-C to a multi-thread program > is unreliable in CPython. See "http://blip.tv/file/2232410" > for why. It's painful. AFIK, that has been resolved in Python 3.2 with the introduction of an intelligent thread scheduler as part of the GIL release/acquire process. - Alice. From roy at panix.com Fri Dec 31 17:37:16 2010 From: roy at panix.com (Roy Smith) Date: Fri, 31 Dec 2010 17:37:16 -0500 Subject: tempfile.NamedTemporaryFile use case? Message-ID: What is the use case for tempfile.NamedTemporaryFile? As far as I can tell, the only way it differs from TemporaryFile is that it is guaranteed to have a name in the file system. BUT, it's not guaranteed that you can open the file a second time via that name. So, what's the point? In what situations would NamedTemporaryFile do what you want but TemporaryFile not? I'm writing a unit test where I want to verify operation of my code on a path which can't be opened (i.e. that it raises IOError). NamedTemporaryFile almost gives me what I want. It creates a file, tells me what the path is (so I can os.chmod() it to mode 0), and cleans it up when I'm done (so I don't have to write my own context manager or whatever). But, it's not guaranteed that I can open the path, so the whole test is moot. I can work around that (plain old mktemp() or mkstemp() and have my tearDown() method do the cleanup), but the more I look at this, the more I'm scratching my head why NamedTemporaryFile exists. From drsalists at gmail.com Fri Dec 31 17:52:57 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 31 Dec 2010 14:52:57 -0800 Subject: Keeping track of the N largest values In-Reply-To: References: Message-ID: On Sat, Dec 25, 2010 at 7:42 AM, Roy Smith wrote: > I'm processing a stream of N numbers and want to keep track of the K > largest. ?There's too many numbers in the stream (i.e. N is too large) > to keep in memory at once. ?K is small (100 would be typical). > > >From a theoretical point of view, I should be able to do this in N log K > time. ?What I'm doing now is essentially: > > top = [-1] ? ?# Assume all x are >= 0 > for x in input(): > ? ?if x <= top[0]: > ? ? ? ?continue > ? ?top.append(x) > ? ?if len(top) > K: > ? ? ? ?top.sort() > ? ? ? ?top.pop(0) > > I can see pathological cases (say, all input values the same) where > running time would be N K log K, but on average (N >> K and random > distribution of values), this should be pretty close to N. > > Is there a better way to do this, either from a theoretical running time > point of view, or just a nicer way to code this in Python? > -- > http://mail.python.org/mailman/listinfo/python-list > heapq is probably fine, but I've empirically found a treap faster than a heap under some conditions: http://stromberg.dnsalias.org/~strombrg/treap/ http://stromberg.dnsalias.org/~strombrg/highest/ From alice at gothcandy.com Fri Dec 31 17:58:58 2010 From: alice at gothcandy.com (=?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=) Date: Fri, 31 Dec 2010 14:58:58 -0800 Subject: tempfile.NamedTemporaryFile use case? References: Message-ID: I'm a bad person, but one use case I have is for shuffling templates around such that: * An inherited ('parent') template can be stored in a database. * The 'views' of my application are told to either use the real master template or the db parent template. * The rendering engine loads the parent from disk. Thus I create a NamedTemporaryFile (with some custom prefix and suffix stuff), write the parent template from DB to it, flush, then let the rendering engine do its thing. Works like a hot damn, and lets the users of my CMS manage custom layouts from within the CMS. Templates are cached using the CMS template path as the dict key, and a 2-tuple of modification time and the NamedTemporaryFile as the value. Cleanup of old versions on-disk is simple: just close the file! - Alice. From usernet at ilthio.net Fri Dec 31 19:13:00 2010 From: usernet at ilthio.net (Tim Harig) Date: Sat, 1 Jan 2011 00:13:00 +0000 (UTC) Subject: User input masks - Access Style References: <385bcaf1-81a5-405a-b7f0-28d7994a2e95@a28g2000prb.googlegroups.com> <7a7e3beb-380a-4d09-8bf6-71a3ecac17e8@p7g2000prb.googlegroups.com> Message-ID: On 2010-12-31, flebber wrote: > On Dec 28 2010, 12:21?am, Adam Tauno Williams > wrote: >> On Sun, 2010-12-26 at 20:37 -0800, flebber wrote: >> > Is there anyay to use input masks in python? Similar to the function >> > found in access where a users input is limited to a type, length and >> > format. >> >> >> >> Typically this is handled by a callback on a keypress event. > > Regarding 137 of the re module, relating to the code above. 137? I am not sure what you are referencing? > EDIT: I just needed to use raw_input rather than input to stop this > input error. Sorry, I used input() because that is what you had used in your example and it worked for my system. Normally, I would have used window.getstr() from the curses module, or whatever the platform equivilant is, for getting line buffered input. From bchang2002 at gmail.com Fri Dec 31 19:55:05 2010 From: bchang2002 at gmail.com (dontcare) Date: Fri, 31 Dec 2010 16:55:05 -0800 (PST) Subject: Trying to parse a HUGE(1gb) xml file References: <5f734c26-a804-4370-9e0d-5f1e1bb31105@glegroupsg2000goo.googlegroups.com> Message-ID: You should look into vtd-xml, available in c, c++, java and c#. On Dec 20, 11:34?am, spaceman-spiff wrote: > Hi c.l.p folks > > This is a rather long post, but i wanted to include all the details & everything i have tried so far myself, so please bear with me & read the entire boringly long post. > > I am trying to parse a ginormous ( ~ 1gb) xml file. > > 0. I am a python & xml n00b, s& have been relying on the excellent beginner book DIP(Dive_Into_Python3 by MP(Mark Pilgrim).... Mark , if u are readng this, you are AWESOME & so is your witty & humorous writing style) > > 1. Almost all exmaples pf parsing xml in python, i have seen, start off with these 4 lines of code. > > import xml.etree.ElementTree as etree > tree = etree.parse('*path_to_ginormous_xml*') > root = tree.getroot() ?#my huge xml has 1 root at the top level > print root > > 2. In the 2nd line of code above, as Mark explains in DIP, the parse function builds & returns a tree object, in-memory(RAM), which represents the entire document. > I tried this code, which works fine for a small ( ~ 1MB), but when i run this simple 4 line py code in a terminal for my HUGE target file (1GB), nothing happens. > In a separate terminal, i run the top command, & i can see a python process, with memory (the VIRT column) increasing from 100MB , all the way upto 2100MB. > > I am guessing, as this happens (over the course of 20-30 mins), the tree representing is being slowly built in memory, but even after 30-40 mins, nothing happens. > I dont get an error, seg fault or out_of_memory exception. > > My hardware setup : I have a win7 pro box with 8gb of RAM & intel core2 quad cpuq9400. > On this i am running sun virtualbox(3.2.12), with ubuntu 10.10 as guest os, with 23gb disk space & 2gb(2048mb) ram, assigned to the guest ubuntu os. > > 3. I also tried using lxml, but an lxml tree is much more expensive, as it retains more info about a node's context, including references to it's parent. > [http://www.ibm.com/developerworks/xml/library/x-hiperfparse/] > > When i ran the same 4line code above, but with lxml's elementree ( using the import below in line1of the code above) > import lxml.etree as lxml_etree > > i can see the memory consumption of the python process(which is running the code) shoot upto ~ 2700mb & then, python(or the os ?) kills the process as it nears the total system memory(2gb) > > I ran the code from 1 terminal window (screenshot :http://imgur.com/ozLkB.png) > & ran top from another terminal (http://imgur.com/HAoHA.png) > > 4. I then investigated some streaming libraries, but am confused - there is SAX[http://en.wikipedia.org/wiki/Simple_API_for_XML] , the iterparse interface[http://effbot.org/zone/element-iterparse.htm] > > Which one is the best for my situation ? > > Any & all code_snippets/wisdom/thoughts/ideas/suggestions/feedback/comments/ of the c.l.p community would be greatly appreciated. > Plz feel free to email me directly too. > > thanks a ton > > cheers > ashish > > email : > ashish.makani > domain:gmail.com > > p.s. > Other useful links on xml parsing in python > 0.http://diveintopython3.org/xml.html > 1.http://stackoverflow.com/questions/1513592/python-is-there-an-xml-par... > 2.http://codespeak.net/lxml/tutorial.html > 3.https://groups.google.com/forum/?hl=en&lnk=gst&q=parsing+a+huge+xml#!... > 4.http://www.ibm.com/developerworks/xml/library/x-hiperfparse/ > 5.http://effbot.org/zone/element-index.htmhttp://effbot.org/zone/element-iterparse.htm > 6. SAX :http://en.wikipedia.org/wiki/Simple_API_for_XML From flebber.crue at gmail.com Fri Dec 31 20:08:08 2010 From: flebber.crue at gmail.com (flebber) Date: Fri, 31 Dec 2010 17:08:08 -0800 (PST) Subject: Python - NAWIT / Community References: <2895ecca-b978-4899-9ab3-0032422b908f@o9g2000pre.googlegroups.com> Message-ID: <75bb7ce4-3542-420e-8a66-70e15bd21030@f20g2000prn.googlegroups.com> On Jan 1, 9:03?am, Fabio Zadrozny wrote: > > My question relates to community contribution. My concern arose when > > recently installing the pydev.org extensions in Eclipse. Now as far as > > my understanding goes the licensing on both is open source GPL. > > However Pydev became open source as part of aptana's acquistion, and > > for the moment pydev can be installed as part of the Aptana studio 2/3 > > releases individually as a plugin, but moving on if you vist the > > aptana site there is sweet little about python on their site, their > > site is dominated by Radrails. > > Just a little fix there, Pydev is open source EPL (not GPL). > > Also, yes, there's little content about Pydev in the Aptana homepage, > but it points to the main Pydev homepage (http://pydev.org) which has > the proper content related to Python (and it's currently being > actively developed and also integrated in Aptana Studio 3, which is > where the current efforts are targeted within Aptana now). Sorry if > this causes the (wrong) perception that Pydev doesn't get as much > attention. > > > Can't help thinking they open sourced Pydev so they could bench it. So > > I started thinking that the only consistent env each python person has > > is idle as it ships in the install. > > Sorry, but I don't follow your thoughts here... there are many > consistent environments for python development which are properly > supported (Pydev being only one of them as you can see athttp://stackoverflow.com/questions/81584/what-ide-to-use-for-python). > > > Sometimes we can contribute with money and sometimes with time, if I > > was to contribute money to ensure that I and all new coming python > > programmers could have a first class development environment to use > > what would I donate to? At the moment no particular group seems > > applicable. > > > Is pydev actively being developed and for who? SPE is a great idea but > > is Stan still developing? Pyscripter is good but not 64 capable. Plus > > none of these projects seem community centric. > > I'm the current Pydev maintainer (since 2005)... and while I cannot > state that I'll be in that role forever (forever is quite a long > time), I do think it's well maintained and there are occasional > patches from the community that uses it (although I still get to > review all that goes in). > > > Maybe its just my wish, maybe something already exists, but to my mind > > why is there not a central python community ide or plugin setup like > > pydev or using pydev(since currently it is very good - to me), which I > > know or at least could confidently donate time or money to further > > python. > > > This could apply to many python area's does python use easy_install or > > pypm, well if you want camelot or zope (unless you have business > > edition) its easy_install, but you wont find an ide with built in egg > > or pypm support? > > I think the issue is that only recently (if you compare with the > others) has easy_install became the de facto standard in python (so, > it'd be more an issue of interest adding such a feature to the ide). > > > > > Why every Ruby ide has gems manager, and for that > > fact look at netbeans, the ide is good but support for python is > > mentioned on a far flung community page where some developers are > > trying to maintain good python support. PS they seem to be doing a > > good job, but a review of the mailing list archives shows little > > activity. > > One could say that activestate puts in good support but then they do > > not provide an ide within the means of the average part time person > > retailing its main edition at over $300, Pycharm a good ide at $99 but > > then where is my money going. > > > I think a community plugin architecture which contained components > > like pydev, pyscripter, eclipse and eggs/pypm packages would give a > > place I can contribute time as my skills grow and confidently donate > > money knowing I am assisting the development of community tools and > > packages we all can use. No need to reinvent the wheel most things > > already exist, for example apt-get & rpm style package management time > > tested and could be easily used to manage python eggs for example. > > Anyway I have had my 2 cents, if someone is contributing more than I > > know, and this wasn't intended to dimnish anyone's effort, just > > wanting to look to growing and fostering a stronger python community. > > Well, I can only comment from the Pydev side here, but do you think > it'd be worth reinventing all that's already done in it just for > having it in Python? When I started contributing to Pydev back in 2004 > I didn't go that way because Eclipse itself has a huge community > that's already in place and is properly maintained, which takes a lot > of effort, so, I'm not sure it'd be worth reproducing all that just to > have it 100% Python code -- I say 100% because Pydev does have a > number of things that are in Python, such as the debugger and Jython > for the scripting engine, although the major portion is really in > java. > > Another important aspect is that it's much better if you can get an > experience that can later be replicated to other languages (which > Eclipse provides). > > Cheers, > > Fabio Fabio right off the bat let me thank you for your work on Pydev, I use eclipse and the Pydev plugin and enjoy it very much. My question and statement come to think of it should have been, is the python community framework the most efficient it could be? If not what framework would reduce duplication, value contributor effort and allow rapid development and utilisation of python projects Zope/Django/ Pyjamas/SQLAlchemy...etc. Would a new framework being clearer allow more investment from both commercial and community sources(time resources & financial resources) and ensure python has the ability to stay current. >Well, I can only comment from the Pydev side here, but do you think >it'd be worth reinventing all that's already done in it just for >having it in Python? No, not at all worth the effort. My main post could have clearer but I became somewhat passionate & less clear. Main points were supposed to reflect 1. Both Netbeans, Aptana and Activestate represent commercial companies. - netbeans and Aptana by perception don't seem to have python as their main focus - Activestate has python at pride of place but both ide and package mgt are at cost and not cheap. Even a free package such as camelot, sqlalchemy require you to pay eg pypm camelot - will give you a message "you need business edition python to access this program" 2. I highly valuable contributors like yourself and had concern that via unecessary duplication could reduce the potential impact and gains that could be had. For example Eclipse and Netbeans are both java ide's that feature mulit syntax programming environments. So is it potentially necessary for both sets of developers to work separately, is it the most productive efficient framework. In my head, and thats the only place this may exist, if for example the pydev plugins where the central community python plugin for syntax features, debugging etc then the commuity could re-use these. This would mean to me that if I want to build an ide with its main focus as Zope/Grok for example(could be anything Pyjamas etc) I wouldn't have to re-write code I could build a base ide and plugin the pydev syntax features to give me full python support and then focus on the part of the implementation I want to develop. Reducing my duplication and increasing productivity And over and over this could be done an ide for python desktop apps, plugin, plugin develop new code for Pyside etc. Whether these apps are 100% python is not the main focus. From drsalists at gmail.com Fri Dec 31 20:15:44 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 31 Dec 2010 17:15:44 -0800 Subject: Is there anyway to run JavaScript in python? In-Reply-To: References: Message-ID: On Thu, Dec 30, 2010 at 5:52 AM, crow wrote: > Hi, I'm writing a test tool to simulate Web browser. Is there anyway > to run JavaScript in python? Thanks in advance. > -- > http://mail.python.org/mailman/listinfo/python-list > You might also consider Pyjamas, which translates Python (somewhere between 2.5 and 2.6) to Javascript. Then your python code ends up running on a javascript interpreter with interlanguage calling available. From mrjean1 at gmail.com Fri Dec 31 20:18:43 2010 From: mrjean1 at gmail.com (MrJean1) Date: Fri, 31 Dec 2010 17:18:43 -0800 (PST) Subject: Compile on SunOS? References: Message-ID: <04608d49-9922-464c-aad7-3fc80b892edb@j25g2000yqa.googlegroups.com> These command lines used to build 32-bit Python 2.4 and 2.5 on Solaris 10 Opteron using SUN's compilers: setenv LD_LIBRARY_PATH .... env CCSHARED="-KPIC" LDSHARED="cc -xtarget=native -G" LDFLAGS="- xtarget=native" CC="cc" \ CPP="cc-xtarget=native -E" BASECFLAGS="-xtarget=native" OPT="-xO5" CFLAGS="-xtarget=native" \ CXX="CC -xtarget=native" ./configure --enable-shared --without-gcc --disable-ipv6 --prefix=.... make Replace the ....'s accordingly. Use BASECFLAGS="-xtarget=native - xlibmieee" for IEEE floating point. Disclaimer, I have not tried building Python 2.6 nor 2.7. /Jean On Dec 31, 8:34?am, Alex Zhang wrote: > Hi All, > I'm trying to build Python 2.7.1 on Sun Solaris 10 amd64, however end up > with: > > Python build finished, but the necessary bits to build these modules > were not found: > _bsddb ? ? ? ? ? ? _tkinter ? ? ? ? ? bsddb185 > gdbm ? ? ? ? ? ? ? linuxaudiodev ? ? ?ossaudiodev > To find the necessary bits, look in setup.py in detect_modules() for the > module's name. > > Failed to build these modules: > _bisect ? ? ? ? ? ?_codecs_cn ? ? ? ? _codecs_hk > _codecs_iso2022 ? ?_codecs_jp ? ? ? ? _codecs_kr > _codecs_tw ? ? ? ? _collections ? ? ? _csv > _ctypes ? ? ? ? ? ?_ctypes_test ? ? ? _curses > _curses_panel ? ? ?_elementtree ? ? ? _functools > _hashlib ? ? ? ? ? _heapq ? ? ? ? ? ? _hotshot > _io ? ? ? ? ? ? ? ?_json ? ? ? ? ? ? ?_locale > _lsprof ? ? ? ? ? ?_multibytecodec ? ?_multiprocessing > _random ? ? ? ? ? ?_socket ? ? ? ? ? ?_sqlite3 > _ssl ? ? ? ? ? ? ? _struct ? ? ? ? ? ?_testcapi > array ? ? ? ? ? ? ?audioop ? ? ? ? ? ?binascii > bz2 ? ? ? ? ? ? ? ?cmath ? ? ? ? ? ? ?cPickle > crypt ? ? ? ? ? ? ?cStringIO ? ? ? ? ?datetime > dbm ? ? ? ? ? ? ? ?dl ? ? ? ? ? ? ? ? fcntl > future_builtins ? ?grp ? ? ? ? ? ? ? ?imageop > itertools ? ? ? ? ?math ? ? ? ? ? ? ? mmap > nis ? ? ? ? ? ? ? ?operator ? ? ? ? ? parser > pyexpat ? ? ? ? ? ?resource ? ? ? ? ? select > spwd ? ? ? ? ? ? ? strop ? ? ? ? ? ? ?sunaudiodev > syslog ? ? ? ? ? ? termios ? ? ? ? ? ?time > unicodedata ? ? ? ?zlib > > running build_scripts > > I am using cc provided in Solaris 10, readline downloaded from GNU and > compiled in 32bit. Also, I added this entry: > > readline readline.c -I/local32/include -L/local32/lib -R/local32/lib > -lreadline -ltermcap > > to Modules/Setup.local in order to get readline running. > Currently: > > dns# /opt/python/bin/python > Python 2.7.1 (r271:86832, Dec 31 2010, 07:21:22) [C] on sunos5 > Type "help", "copyright", "credits" or "license" for more information. > ?>>> import hashlib > Traceback (most recent call last): > ? ?File "", line 1, in > ? ?File "/opt/python/lib/python2.7/hashlib.py", line 136, in > ? ? ?globals()[__func_name] = __get_hash(__func_name) > ? ?File "/opt/python/lib/python2.7/hashlib.py", line 71, in > __get_builtin_constructor > ? ? ?import _md5 > ImportError: No module named _md5 > > I can not use hashlib and many other modules however I can use the rest > modules. > Thanks for all your kind reply. > -- > OSQDU::Alex From sigzero at gmail.com Fri Dec 31 21:53:49 2010 From: sigzero at gmail.com (Robert) Date: Fri, 31 Dec 2010 21:53:49 -0500 Subject: Python3 Web Framework References: <5a863ddc-20bf-4c00-83e6-61d4a4551c7d@c13g2000prc.googlegroups.com> Message-ID: On 2010-12-31 17:24:56 -0500, Alice Bevan?McGregor said: > On 2010-12-31 02:20:47 -0800, Terry Reedy said: > >> I believe some will be improved or even solved in 3.2. > > Evidence to back this statement up would be appreciated. ;) > > - Alice. - wsgiref now implements and validates PEP 3333, rather than an experimental extension of PEP 333. (Note: earlier versions of Python 3.x may have incorrectly validated some non-compliant applications as WSGI compliant; if your app validates with Python <3.2b1+, but not on this version, it is likely the case that your app was not compliant.) That is from the changes file...so they are working to fix it all. HTH -- Robert From sigzero at gmail.com Fri Dec 31 21:56:02 2010 From: sigzero at gmail.com (Robert) Date: Fri, 31 Dec 2010 21:56:02 -0500 Subject: Nagios References: <6dc986a5-bcc2-4d2c-8fc2-5b4732096d3b@j29g2000yqm.googlegroups.com> <56d4ecc8-03fb-432a-b728-bebc53f11dec@e16g2000pri.googlegroups.com> <4d1ce2d4$0$29968$c3e8da3$5496439d@news.astraweb.com> <4c682692-dc0f-4055-9587-eb7cce169ef6@g26g2000vbz.googlegroups.com> <661858a7-2eaa-4ba5-a014-0805707f0a3f@p8g2000vbs.googlegroups.com> <4d1d5a2b$0$29968$c3e8da3$5496439d@news.astraweb.com> <20101231225230.38992926@pitrou.net> Message-ID: On 2010-12-31 16:52:30 -0500, Antoine Pitrou said: > On 31 Dec 2010 04:20:59 GMT > Steven D'Aprano wrote: >> On Thu, 30 Dec 2010 23:04:33 -0500, Robert wrote: >> >>> The >>> second way the Tcl community irks me is the "not invented here" >>> attitude. I like the syntax of Tcl and I like the community. They are >>> some good folks. Try asking "I want to build a Nagios clone in Tcl" type >>> question and invariably you get "Why? There is already Nagios?". >> >> You're the one who wants to re-write Nagios in Tcl, the Tcl community are >> perfectly happy using the existing Nagios instead of re-inventing the >> wheel, and you accuse *them* of suffering from NIH syndrome. > > Well, I don't know about Tcl but Nagios was re-written in Python: > http://www.shinken-monitoring.org/features/ > > Regards > > Antoine. It was forked to be written in Python, yes. The whole point (and it wasn't a Nagios port to Tcl) was that the Tcl community (and I like the Tcl community a lot) has a strange fixation with not reinventing the wheel, even when the wheel would be in Tcl and it might give Tcl more exposure. It is what it is though. -- Robert From flebber.crue at gmail.com Fri Dec 31 22:36:26 2010 From: flebber.crue at gmail.com (flebber) Date: Fri, 31 Dec 2010 19:36:26 -0800 (PST) Subject: GUI Tools for Python 3.1 References: Message-ID: <09e67821-46cb-4199-91e1-ab31663ced75@c13g2000prc.googlegroups.com> On Dec 26 2010, 8:41?pm, "Hans-Peter Jansen" wrote: > On Friday 24 December 2010, 03:58:15 Randy Given wrote: > > > Lots of stuff for 2.6 and 2.7 -- what GUI tools are there for 3.1? > > PyQt4 of course. > > http://www.riverbankcomputing.com > > Pete Pyside, Nokia have split with riverbank computing and are quickly developing pyside. Currently not supported in Py3000 but have already a roadmap for implementation when they finalise Python 2 support. Here is what they see as roadblocks(not insurmountble) to python3. http://developer.qt.nokia.com/wiki/PySide_Python_3_Issues From askutt at gmail.com Fri Dec 31 23:57:24 2010 From: askutt at gmail.com (Adam Skutt) Date: Fri, 31 Dec 2010 20:57:24 -0800 (PST) Subject: Nagios In-Reply-To: Message-ID: <3f7e76bf-3d62-4314-987f-62b9fda71f91@glegroupsg2000goo.googlegroups.com> On Friday, December 31, 2010 9:56:02 PM UTC-5, Robert H wrote: > It was forked to be written in Python, yes. The whole point (and it > wasn't a Nagios port to Tcl) was that the Tcl community (and I like the > Tcl community a lot) has a strange fixation with not reinventing the > wheel, even when the wheel would be in Tcl and it might give Tcl more > exposure. It is what it is though. > > -- Perhaps because they'd rather do something useful with the tool they've created instead of trying to win some sort of nonexistent popularity contest? What value would there be in that? Not trying to reinvent the wheel whenever feasible is both good programming and good engineering most of the time. Unfortunately, the fact you see this as irksome only paints you in a negative light. Adam From askutt at gmail.com Fri Dec 31 23:57:24 2010 From: askutt at gmail.com (Adam Skutt) Date: Fri, 31 Dec 2010 20:57:24 -0800 (PST) Subject: Nagios In-Reply-To: Message-ID: <3f7e76bf-3d62-4314-987f-62b9fda71f91@glegroupsg2000goo.googlegroups.com> On Friday, December 31, 2010 9:56:02 PM UTC-5, Robert H wrote: > It was forked to be written in Python, yes. The whole point (and it > wasn't a Nagios port to Tcl) was that the Tcl community (and I like the > Tcl community a lot) has a strange fixation with not reinventing the > wheel, even when the wheel would be in Tcl and it might give Tcl more > exposure. It is what it is though. > > -- Perhaps because they'd rather do something useful with the tool they've created instead of trying to win some sort of nonexistent popularity contest? What value would there be in that? Not trying to reinvent the wheel whenever feasible is both good programming and good engineering most of the time. Unfortunately, the fact you see this as irksome only paints you in a negative light. Adam