Re: Is it possible monkey patch like this?

2012-12-18 Thread Steven D'Aprano
On Tue, 18 Dec 2012 02:26:42 -0800, Marc Aymerich wrote: > Dear all, > I want to monkey patch a method that has lots of code so I want to avoid > copying all the original method for changing just two lines. The thing > is that I don't know how to do this kind of monkey patching. The only types of

Re: Pattern-match & Replace - help required

2012-12-19 Thread Steven D'Aprano
On Wed, 19 Dec 2012 02:42:26 -0800, AT wrote: > Hi, > > I am new to python and web2py framework. Need urgent help to match a > pattern in an string and replace the matched text. > > I've this string (basically an sql statement): > > stmnt = 'SELECT taxpayer.id, > taxpayer.enc_name, >

Re: counting how often the same word appears in a txt file...But my code only prints the last line entry in the txt file

2012-12-19 Thread Steven D'Aprano
On Wed, 19 Dec 2012 02:45:13 -0800, dgcosgrave wrote: > Hi Iam just starting out with python...My code below changes the txt > file into a list and add them to an empty dictionary and print how often > the word occurs, but it only seems to recognise and print the last entry > of the txt file. Any

Re: Pattern-match & Replace - help required

2012-12-19 Thread Steven D'Aprano
On Wed, 19 Dec 2012 03:01:32 -0800, AT wrote: > I just wanted to change taxpayer.enc_name in stmnt to > decrypt(taxpayer.enc_name) > > hope it clarifies? Maybe. Does this help? lunch = "Bread, ham, cheese and tomato." # replace ham with spam offset = lunch.find('ham') if offset != -1: lunch

Re: Py 3.3, unicode / upper()

2012-12-19 Thread Steven D'Aprano
On Thu, 20 Dec 2012 00:32:42 -0500, Terry Reedy wrote: > In the unicode case, Jim discovered that find was several times slower > in 3.3 than 3.2 and claimed that that was a reason to not use 3.2. I ran > the complete stringbency.py and discovered that find (and consequently > find and replace) ar

Re: Data Driven Process

2012-12-20 Thread Steven D'Aprano
On Thu, 20 Dec 2012 10:08:20 -0800, balparmak wrote: > Thank you for your reply Grant, > > I am trying to attach mxd's but no chance. As you said that i dont have > much experience in python. I used to work with VBA but its not an option > anymore with new ArcGIS 10. > > How can I add mxd's here

Re: Data Driven Process

2012-12-20 Thread Steven D'Aprano
On Thu, 20 Dec 2012 12:39:38 -0800, balparmak wrote: > I am working with the python code below in ArcGIS to zoom into a > shapefile's attribute table row features without selected until the end > of table one by one. > > I am trying to use this code but this one requires that a row is > selected.

Re: Strange effect with import

2012-12-20 Thread Steven D'Aprano
On Thu, 20 Dec 2012 20:39:19 +, Jens Thoms Toerring wrote: > Hi, > >I hope that this isn't a stupid question, asked already a > hundred times, but I haven't found anything definitive on the problem I > got bitten by. I have two Python files like this: > > S1.py -- > import ra

Re: Py 3.3, unicode / upper()

2012-12-20 Thread Steven D'Aprano
On Thu, 20 Dec 2012 11:40:21 -0800, wxjmfauth wrote: > I do not care > about this optimization. I'm not an ascii user. As a non ascii user, > this optimization is just irrelevant. WRONG. Every Python user is an ASCII user. Every Python program has hundreds or thousands of ASCII strings. # ===

Re: Brython - Python in the browser

2012-12-20 Thread Steven D'Aprano
On Thu, 20 Dec 2012 18:59:39 -0500, Terry Reedy wrote: >> On Thu, Dec 20, 2012 at 8:37 PM, Pierre Quentel >> wrote: >>> I'm afraid I am going to disagree. The document is a tree structure, >>> and today Python doesn't have a syntax for easily manipulating trees. > > What Python does have is 11 v

Re: Pass and return

2012-12-21 Thread Steven D'Aprano
On Thu, 20 Dec 2012 21:23:58 -0800, iMath wrote: > Pass and return > Are these two functions the same ? They are neither functions, nor are they the same. Check if they are functions: - can you pass them arguments? - can you assign their result to a target? No. py> pass(23) File "", line 1

Re: Brython - Python in the browser

2012-12-21 Thread Steven D'Aprano
On Fri, 21 Dec 2012 12:25:01 +0100, Stefan Behnel wrote: > If that's your intention, then instead of coming up with something > totally new, unpythonic and ugly, why not take the normal Python route > and implement a subset of the ElementTree API? Yo mean something old, unpythonic and ugly? :-P

Re: Brython - Python in the browser

2012-12-22 Thread Steven D'Aprano
On Sat, 22 Dec 2012 20:08:25 +1100, Chris Angelico wrote: > I don't see "string % tuple" as a good syntax; I prefer to spell it > sprintf("format",arg,arg,arg). Very possibly one of the worst names ever from a language that excels at bad names. "Sprint f"? WTF? Certainly not appropriate for Py

Re: urllib.error.HTTPError: HTTP Error 403: Forbidden

2012-12-23 Thread Steven D'Aprano
On Sun, 23 Dec 2012 17:05:47 -0800, iMath wrote: import urllib.request response = urllib.request.urlopen('http://en.wikipedia.org/wiki/ Internet_media_type') > Traceback (most recent call last): > File "", line 1, in > response = > urllib.request.urlopen('http://en.wikipe

Re: how to detect the character encoding in a web page ?

2012-12-24 Thread Steven D'Aprano
On Mon, 24 Dec 2012 13:16:16 +0100, Kwpolska wrote: > On Mon, Dec 24, 2012 at 9:34 AM, Kurt Mueller > wrote: >> $ wget -q -O - http://python.org/ | chardetect.py stdin: ISO-8859-2 >> with confidence 0.803579722043 $ > > And it sucks, because it uses magic, and not reading the HTML tags. The > RI

Re: Custom alphabetical sort

2012-12-24 Thread Steven D'Aprano
On Mon, 24 Dec 2012 11:18:37 -0500, Roy Smith wrote: > In article <40d108ec-b019-4829-a969-c8ef51386...@googlegroups.com>, > Pander Musubi wrote: > >> Hi all, >> >> I would like to sort according to this order: [...] > I'm assuming that doesn't correspond to some standard locale's collating > o

Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)

2012-12-25 Thread Steven D'Aprano
On Mon, 24 Dec 2012 00:19:18 -0500, Dave Angel wrote: > Nobody's going to be able to understand your code if you persist in > using self in unpythonic ways. It's used as the first argument of a > class method. Period. To be pedantic, "self" is the conventional argument for *instance* methods, n

Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)

2012-12-25 Thread Steven D'Aprano
On Tue, 25 Dec 2012 12:16:16 -0800, Rick Johnson wrote: > On Tuesday, December 25, 2012 11:10:49 AM UTC-6, Dave Angel wrote: > >> We all make mistakes, like my referring to class methods when I meant >> instance methods. > > This mistake reminded of how people in this group (maybe not you in > p

Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)

2012-12-26 Thread Steven D'Aprano
On Tue, 25 Dec 2012 16:19:21 -0800, Rick Johnson wrote: > On Tuesday, December 25, 2012 4:56:44 PM UTC-6, Steven D'Aprano wrote: > >> Rick, what makes you think that this is logically inconsistent? >> "Method" is the accepted name for functions attached to clas

Re: How to get time.strptime()?

2012-12-26 Thread Steven D'Aprano
On Wed, 26 Dec 2012 08:33:42 -0800, Gnarlodious wrote: > Error: AttributeError: 'module' object has no attribute '_strptime' > > This problem is driving me crazy. It only happens in Python 3.3.0, while > on my server running 3.1.3 it behaves as expected. When I try to access > time.strptime() it

Re: How to get time.strptime()?

2012-12-26 Thread Steven D'Aprano
On Wed, 26 Dec 2012 19:09:51 -0800, Gnarlodious wrote: > This is problem that has unduly vexed me. When you start learning Python > they don't tell you about these sharp edges. "Hi, I've just started learning Python today, and I have a question. How do I print a list?" "Before I answer that qu

Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)

2012-12-26 Thread Steven D'Aprano
On Wed, 26 Dec 2012 20:07:53 -0800, Rick Johnson wrote: > My specific point is that the English word "variable" is unambiguous I'm sorry, do you mean "variable" the noun, or "variable" the adjective? If you mean the adjective, do you mean something which naturally changes, in the sense that the

Re: Finding the name of a function while defining it

2012-12-27 Thread Steven D'Aprano
On Wed, 26 Dec 2012 23:46:31 -0800, Abhas Bhattacharya wrote: >> > two = lamba : "one" >> > one = two >> >> > Which one of these is the "name" of the function? [...] > If i call one() and two() respectively, i would like to see "one" and > "two". I'm afraid you're going to be disappointed. There

Re: Finding the name of a function while defining it

2012-12-27 Thread Steven D'Aprano
On Tue, 25 Dec 2012 22:11:28 -0500, Roy Smith wrote: > I've only ever wanted the name. If you need the actual function object, > I suppose you might eval() the name, or something like that. Oh look, I found a peanut! Let me get a 50lb sledgehammer to crack it open! *wink* Please do not use ev

Re: Finding the name of a function while defining it

2012-12-27 Thread Steven D'Aprano
On Tue, 25 Dec 2012 18:00:38 -0800, Abhas Bhattacharya wrote: > While I am defining a function, how can I access the name (separately as > string as well as object) of the function without explicitly naming > it(hard-coding the name)? For eg. I am writing like: > def abc(): > #how do i access

Re: Finding the name of a function while defining it

2012-12-27 Thread Steven D'Aprano
On Thu, 27 Dec 2012 07:32:16 -0600, Tim Chase wrote: > Depending on where in the code you are, the same function object also > has a local name of "fn". It's madness until you understand it, and > then it's beauty :) "This is madness!" "No, this is PYTHON!!!" -- Steven -- http://mail.pytho

Re: Finding the name of a function while defining it

2012-12-27 Thread Steven D'Aprano
On Thu, 27 Dec 2012 10:09:01 -0500, Roy Smith wrote: > In article <50dc29e9$0$29967$c3e8da3$54964...@news.astraweb.com>, > Steven D'Aprano wrote: > >> On Wed, 26 Dec 2012 23:46:31 -0800, Abhas Bhattacharya wrote: >> >> >> > two = lamba : &quo

Re: New to python, do I need an IDE or is vim still good enough?

2012-12-27 Thread Steven D'Aprano
On Thu, 27 Dec 2012 12:01:16 -0800, mogul wrote: > 'Aloha! > > I'm new to python, got 10-20 years perl and C experience, all gained on > unix alike machines hacking happily in vi, and later on in vim. > > Now it's python, and currently mainly on my kubuntu desktop. > > Do I really need a real I

Re: noob can't install python modules/scripts

2012-12-28 Thread Steven D'Aprano
On Fri, 28 Dec 2012 17:45:56 -0800, lostguru wrote: > using easy_install as an example, I downloaded the .py script the > website told me to use for 64-bit installations, and ran it; "The website"? There's more than one website on the Internet. Which website are you referring to? What .py scrip

Re: Confused about logger config from within Python (3)

2012-12-28 Thread Steven D'Aprano
On Fri, 28 Dec 2012 11:57:29 -0800, andrew cooke wrote: > When I use a config file things seem to work (in other projects), but > for my current code I hoped to configure logging from Python. > > I distilled my problem down to the following test, which does not print > anything. Please can someo

Re: Confused about logger config from within Python (3)

2012-12-28 Thread Steven D'Aprano
On Fri, 28 Dec 2012 16:41:20 -0800, andrew cooke wrote: > similarly, if i run the following, i see only "done": > > from logging import DEBUG, root, getLogger > > if __name__ == '__main__': > root.setLevel(DEBUG) > getLogger(__name__).debug("hello world") > print('done')

Re: dict comprehension question.

2012-12-31 Thread Steven D'Aprano
On Sat, 29 Dec 2012 18:56:57 -0500, Terry Reedy wrote: > On 12/29/2012 2:48 PM, Quint Rankid wrote: > >> Given a list like: >> w = [1, 2, 3, 1, 2, 4, 4, 5, 6, 1] >> I would like to be able to do the following as a dict comprehension. >> a = {} >> for x in w: >> a[x] = a.get(x,0) + 1 >> resu

Re: father class name

2012-12-31 Thread Steven D'Aprano
On Mon, 31 Dec 2012 20:23:44 +1100, Ben Finney wrote: > Chris Rebert writes: > >> By contrast, in the first part of the *expression* >> `haha(object).theprint()`, you passed an argument (namely, `object`). >> Since __init__() wasn't expecting any arguments whatsoever, you >> therefore got an err

Re: New to python, do I need an IDE or is vim still good enough?

2012-12-31 Thread Steven D'Aprano
On Sat, 29 Dec 2012 14:00:23 -0500, Mitya Sirenef wrote: > I think the general idea is that with editors like Vim you don't get > distracted by having to do some kind of an editor task, letting you keep > your full attention on the code logic. For instance, if I need to change > a block inside par

Re: New to python, do I need an IDE or is vim still good enough?

2012-12-31 Thread Steven D'Aprano
On Sun, 30 Dec 2012 09:30:10 +1100, Chris Angelico wrote: > Absolutely! Though it's roughly as good to have the current cursor > position shown in a status line somewhere, and takes up less real > estate. But yes, vital to be able to see that. Even when I'm sitting > *right next to* my boss and co

Re: ignore case only for a part of the regex?

2012-12-31 Thread Steven D'Aprano
On Sun, 30 Dec 2012 10:20:19 -0500, Roy Smith wrote: > The way I would typically do something like this is build my regexes in > all lower case and .lower() the text I was matching against them. I'm > curious what you're doing where you want to enforce case sensitivity in > one part of a header,

Re: pygame - importing GL - very bad...

2013-01-01 Thread Steven D'Aprano
On Tue, 01 Jan 2013 12:00:32 +0100, someone wrote: > See this code (understand why I commented out first line): > > # from OpenGL.GL import * [...] > The reason why I commented out the first line is that I use "pylint" and > it reports: "[W] Redefining built-in 'format'" for this line. > > From:

Re: Handling Special characters in python

2013-01-01 Thread Steven D'Aprano
On Tue, 01 Jan 2013 03:35:56 -0800, anilkumar.dannina wrote: > I am facing one issue in my module. I am gathering data from sql server > database. In the data that I got from db contains special characters > like "endash". Python was taking it as "\x96". I require the same > character(endash). How

Re: numpy has got newtonsmethod?

2013-01-01 Thread Steven D'Aprano
On Tue, 01 Jan 2013 16:42:13 -0800, Usama Khan wrote: > Traceback (most recent call last): > File "C:/Python27/12.py", line 4, in > import scipy # also has log > File "C:/Python27\scipy\__init__.py", line 114, in > raise ImportError(msg) > ImportError: Error importing scipy: you can

Re: pygame - importing GL - very bad...

2013-01-01 Thread Steven D'Aprano
On Wed, 02 Jan 2013 00:49:36 +0100, someone wrote: > On 01/01/2013 12:49 PM, Steven D'Aprano wrote: > > On Tue, 01 Jan 2013 12:00:32 +0100, someone wrote: > > > >> See this code (understand why I commented out first line): > >> > >> # from OpenG

Re: pylint, was Re: pygame - importing GL - very bad...

2013-01-02 Thread Steven D'Aprano
On Wed, 02 Jan 2013 09:26:32 -0500, Dave Angel wrote: > On 01/02/2013 09:09 AM, someone wrote: >> On 01/02/2013 01:07 PM, Peter Otten wrote: >>> pylint wants global names to be uppercase (what PEP 8 recommends for >>> constants) or "special" (two leading and two trailing underscores): >>> >>> THA

Re: Important questions about __future__

2013-01-03 Thread Steven D'Aprano
On Thu, 03 Jan 2013 03:27:42 -0600, Andrew Berg wrote: > Does 'from __future__ import barry_as_FLUFL' do anything? Yes, it re-enables <> and disables != as not equal: py> sys.version '3.3.0rc3 (default, Sep 27 2012, 18:44:58) \n[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)]' py> 1 <> 2 File "", lin

Re: Question on for loop

2013-01-03 Thread Steven D'Aprano
On Thu, 03 Jan 2013 12:04:03 -0800, subhabangalore wrote: > Dear Group, > If I take a list like the following: > > fruits = ['banana', 'apple', 'mango'] > for fruit in fruits: >print 'Current fruit :', fruit > > Now, > if I want variables like var1,var2,var3 be assigned to them, we may > t

Re: Yet another attempt at a safe eval() call

2013-01-03 Thread Steven D'Aprano
On Thu, 03 Jan 2013 23:25:51 +, Grant Edwards wrote: > I've written a small assembler in Python 2.[67], and it needs to > evaluate integer-valued arithmetic expressions in the context of a > symbol table that defines integer values for a set of names. The > "right" thing is probably an expres

Re: Yet another attempt at a safe eval() call

2013-01-04 Thread Steven D'Aprano
On Fri, 04 Jan 2013 07:24:04 -0500, Terry Reedy wrote: > On 1/3/2013 6:25 PM, Grant Edwards wrote: >> >> I've written a small assembler in Python 2.[67], and it needs to >> evaluate integer-valued arithmetic expressions in the context of a >> symbol table that defines integer values for a set of n

Re: Need a specific sort of string modification. Can someone help?

2013-01-06 Thread Steven D'Aprano
On Sun, 06 Jan 2013 12:28:55 -0500, Roy Smith wrote: > I've been doing some log analysis. It's been taking a grovelingly long > time, so I decided to fire up the profiler and see what's taking so > long. I had a pretty good idea of where the ONLY TWO POSSIBLE hotspots > might be (looking up IP a

Re: Numpy outlier removal

2013-01-06 Thread Steven D'Aprano
On Sun, 06 Jan 2013 19:44:08 +, Joseph L. Casale wrote: > I have a dataset that consists of a dict with text descriptions and > values that are integers. If required, I collect the values into a list > and create a numpy array running it through a simple routine:  > > data[abs(data - mean(d

Re: Numpy outlier removal

2013-01-06 Thread Steven D'Aprano
On Mon, 07 Jan 2013 02:29:27 +, Oscar Benjamin wrote: > On 7 January 2013 01:46, Steven D'Aprano > wrote: >> On Sun, 06 Jan 2013 19:44:08 +, Joseph L. Casale wrote: >> >>> I have a dataset that consists of a dict with text descriptions and >>>

Re: Over 30 types of variables available in python ?

2013-01-07 Thread Steven D'Aprano
On Mon, 07 Jan 2013 00:53:26 -0800, chaouche yacine wrote: > Thanks for all your comments. It appears to me that there is a slight > confusion between types and classes then, plus other entities (protocols > ?) In Python 3, types and classes are synonyms. They mean the same thing. In Python 2,

Re: regular expression : the dollar sign ($) work with re.match() or re.search() ?

2013-01-07 Thread Steven D'Aprano
On Mon, 07 Jan 2013 01:45:58 -0800, iMath wrote: > 在 2012年9月26日星期三UTC+8下午3时38分50秒,iMath写道: >> I only know the dollar sign ($) will match a pattern from the >> >> end of a string,but which method does it work with ,re.match() or >> re.search() ? > > I thought re.match('h.$', 'hbxihi') will matc

Re: what’s the difference between socket.send() and socket.sendall() ?

2013-01-07 Thread Steven D'Aprano
On Mon, 07 Jan 2013 18:35:20 +0800, iMath wrote: > what’s the > difference between socket style="font-size: 12pt; ">.send() and socket.sendall() > ? Please re-send your question as text, instead of as HTML (so-called "rich text"). Since many people are reading this forum via Usenet, sending HT

[Offtopic] Line fitting [was Re: Numpy outlier removal]

2013-01-07 Thread Steven D'Aprano
On Mon, 07 Jan 2013 15:20:57 +, Oscar Benjamin wrote: > There are sometimes good reasons to get a line of best fit by eye. In > particular if your data contains clusters that are hard to separate, > sometimes it's useful to just pick out roughly where you think a line > through a subset of the

Re: [Offtopic] Line fitting [was Re: Numpy outlier removal]

2013-01-07 Thread Steven D'Aprano
On Mon, 07 Jan 2013 22:32:54 +, Oscar Benjamin wrote: > An example: Earlier today I was looking at some experimental data. A > simple model of the process underlying the experiment suggests that two > variables x and y will vary in direct proportion to one another and the > data broadly reflec

Re: [Offtopic] Line fitting [was Re: Numpy outlier removal]

2013-01-07 Thread Steven D'Aprano
On Tue, 08 Jan 2013 06:43:46 +1100, Chris Angelico wrote: > On Tue, Jan 8, 2013 at 4:58 AM, Steven D'Aprano > wrote: >> Anyone can fool themselves into placing a line through a subset of non- >> linear data. Or, sadly more often, *deliberately* cherry picking fake >&

Re: [Offtopic] Line fitting [was Re: Numpy outlier removal]

2013-01-08 Thread Steven D'Aprano
On Tue, 08 Jan 2013 04:07:08 -0500, Terry Reedy wrote: >> But that is not fitting a line by eye, which is what I am talking >> about. > > With the line constrained to go through 0,0 a line eyeballed with a > clear ruler could easily be better than either regression line, as a > human will tend t

Re: [Offtopic] Line fitting [was Re: Numpy outlier removal]

2013-01-08 Thread Steven D'Aprano
On Wed, 09 Jan 2013 07:14:51 +1100, Chris Angelico wrote: > Three types of lies. Oh, surely more than that. White lies. Regular or garden variety lies. Malicious lies. Accidental or innocent lies. FUD -- "fear, uncertainty, doubt". Half-truths. Lying by omission. Exaggeration and underst

Re: Regex not matching a string

2013-01-09 Thread Steven D'Aprano
On Wed, 09 Jan 2013 02:08:23 -0800, python.prog29 wrote: > Hi All - > > > In the following code ,am trying to remove a multi line - comment that > contains "This is a test comment" for some reason the regex is not > matching.. can anyone provide inputs on why it is so? It works for me. Some ob

Re: How to call wget by python ?

2013-01-09 Thread Steven D'Aprano
On Wed, 09 Jan 2013 18:11:34 -0800, iMath wrote: > can you give me an example code ? Is the web broken where you are? If you google for "python wget", you will find example of how to call wget as an external process, as well as examples of downloading files from the web like wget would do but

RIse and fall of languages in 2012

2013-01-09 Thread Steven D'Aprano
"In general-purpose scripting languages, Python continues to grow slowly, JavaScript and Ruby are treading water, and Perl continues its long decline. According to Google trends, the number of searches for Perl is 19% of what it was in 2004. Its declining role in open-source communities further

Re: RIse and fall of languages in 2012

2013-01-10 Thread Steven D'Aprano
On Thu, 10 Jan 2013 12:42:49 -0700, Michael Torrie wrote: >> And from the TIOBE Index, Python is steady at number 8: >> >> http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html > > The TIOBE index is meaningless. Since it's based on google searches, > one could probably guess that an

Re: Probabilistic unit tests?

2013-01-10 Thread Steven D'Aprano
On Thu, 10 Jan 2013 17:59:05 -0800, Nick Mellor wrote: > Hi, > > I've got a unit test that will usually succeed but sometimes fails. An > occasional failure is expected and fine. It's failing all the time I > want to test for. Well, that's not really a task for unit testing. Unit tests, like mos

Re: pylint or similar to test version-specific language constructs?

2013-01-11 Thread Steven D'Aprano
On Fri, 11 Jan 2013 10:06:30 -0500, Dave Angel wrote: > On 01/11/2013 03:29 AM, The Night Tripper wrote: >> Gisle Vanem wrote: >> >>> "jkn" wrote: >>> I have to write python code which must run on an old version of python (v2.4) as well as a newer (v2.7). I am using pylint and would

Re: PyWart: Module access syntax

2013-01-11 Thread Steven D'Aprano
On Thu, 10 Jan 2013 22:01:37 -0800, Rick Johnson wrote: > Python's module/package access uses dot notation. > > mod1.mod2.mod3.modN > > Like many warts of the language, this wart is not so apparent when first > learning the language. The dot seems innocently sufficient, however, in > truth it

Re: Probabilistic unit tests?

2013-01-11 Thread Steven D'Aprano
On Fri, 11 Jan 2013 16:26:20 +, Alister wrote: > On Thu, 10 Jan 2013 17:59:05 -0800, Nick Mellor wrote: > >> Hi, >> >> I've got a unit test that will usually succeed but sometimes fails. An >> occasional failure is expected and fine. It's failing all the time I >> want to test for. >> >> Wh

Re: PyWart: Module access syntax

2013-01-11 Thread Steven D'Aprano
On Fri, 11 Jan 2013 20:34:20 -0800, Rick Johnson wrote: >> > import lib:gui:tkinter:dialogs.SimpleDialog as Blah >> >> Which names are packages, modules, classes, methods, functions, or >> other objects? >> >> Why do you have lib:gui but dialogs.SimpleDialog? Is the rule "classes >> should alw

Re: PyWart: Module access syntax

2013-01-11 Thread Steven D'Aprano
On Fri, 11 Jan 2013 21:46:36 -0800, Rick Johnson wrote: > On Friday, January 11, 2013 10:40:36 PM UTC-6, Chris Angelico wrote: >> On Sat, Jan 12, 2013 at 3:34 PM, Rick Johnson > >> > *The problem:* >> > ... is readability. The current dot syntax used ubiquitously in paths >> > is not conveying th

Re: ANN: Python training "text movies"

2013-01-12 Thread Steven D'Aprano
On Sun, 13 Jan 2013 00:11:53 -0500, AK wrote: > I don't know what to call these, so for now I'll call them "training > text movies" until I come up with a better name.. > > I hope these will be helpful, especially to new students of Python. > > http://lightbird.net/larks/tmovies.html For the b

Re: Subgraph Drawing

2013-01-13 Thread Steven D'Aprano
On Sun, 13 Jan 2013 12:05:54 -0800, subhabangalore wrote: > Dear Group, > > I have two questions, if I take a subseries of the matrix as in > eigenvalue here, provided I have one graph of the full form in G, how > may I show it, as if I do the nx.draw(G) it takes only the original > graph. Is th

Re: Subgraph Drawing

2013-01-13 Thread Steven D'Aprano
On Sun, 13 Jan 2013 20:01:21 -0800, subhabangalore wrote: > there are other solution of converting back the matrix to graph should I > try that? Yes. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: PyWart (Terminolgy): "Class"

2013-01-14 Thread Steven D'Aprano
On Sun, 13 Jan 2013 22:46:44 -0800, Rick Johnson wrote: > I have believed for a very long time that "class" was a poor choice of > keyword to designate an "object definition". > > Firstly, the word /class/ does not transform smoothly into CS from > English. NO English definition of "class" comes

Re: PyWart: Module access syntax

2013-01-14 Thread Steven D'Aprano
On Sun, 13 Jan 2013 21:22:57 -0800, Rick Johnson wrote: > On Saturday, January 12, 2013 12:45:03 AM UTC-6, Steven D'Aprano wrote: >> On Fri, 11 Jan 2013 20:34:20 -0800, Rick Johnson wrote: >> > [...] >> So what do you do for, say, os.path? According to the first

Re: PyWart (Terminolgy): "Class"

2013-01-14 Thread Steven D'Aprano
On Tue, 15 Jan 2013 07:57:58 +1100, Chris Angelico wrote: > Rick Johnson is a well-known troll. I disagree that Rick is a troll. Trolling requires that the troll makes statements that he doesn't believe are true, simply in order to get a response. I do not believe that Rick is doing that. I thi

Re: strace of python shows nonsense

2013-01-14 Thread Steven D'Aprano
On Tue, 15 Jan 2013 00:50:01 +0100, Joep van Delft wrote: > Hi there, > > > I am puzzled at how I borked my installation. Python loads slow on my > machine, and I decided to use strace and /usr/bin/time to see what is > actually happening. Before dropping down to such a low level, I suggest you

Re: code explanation

2013-01-14 Thread Steven D'Aprano
On Mon, 14 Jan 2013 23:00:16 -0500, Rodrick Brown wrote: > Can someone explain what's going on here. > > def _build_magic_dispatcher(method): > def inner(self, *args, **kwargs): > return self.__dict__[method](*args, **kwargs) > inner.__name__ = method > return inner > > Thank

Re: PyWart (Terminolgy): "Class"

2013-01-15 Thread Steven D'Aprano
On Mon, 14 Jan 2013 22:54:10 -0800, Rick Johnson wrote: > No, classes DO NOT exist at runtime OR compile time! Classes are only > *structured text* (or code if you prefer) that instruct Python to build > *real* MEMORY OBJECTS for us. The "magic" that you are witnessing is > Python, not classes. U

Re: Is there a more elegant way to handle determing fail status?

2013-01-15 Thread Steven D'Aprano
On Tue, 15 Jan 2013 18:24:44 -0500, J wrote: > The problem is that my exit determination looks like this: > > if fail_priority == fail_levels['FAILED_CRITICAL']: > if critical_fails: > return 1 > if fail_priority == fail_levels['FAILED_HIGH']: > if critical_fa

Re: PyWart: Exception error paths far too verbose

2013-01-16 Thread Steven D'Aprano
On Tue, 15 Jan 2013 21:59:42 -0800, Rick Johnson wrote: > Python needs to trim the path to the source file from which the > exception was caught and only display the relative path starting from > your personal library folder. What personal library folder? > For example. Say your personal librar

Re: Using inner dict as class interface

2013-01-16 Thread Steven D'Aprano
On Wed, 16 Jan 2013 15:42:42 +0100, Florian Lindner wrote: > Hello, > > I have a: > > class C: >def __init__(self): > d = dict_like_object_created_somewhere_else() > > def some_other_methods(self): > pass > > > class C should behave like a it was the dict d. Then make it a d

Re: To make a method or attribute private

2013-01-16 Thread Steven D'Aprano
On Thu, 17 Jan 2013 08:34:22 +0800, iMath wrote: > To make a method or attribute private (inaccessible from the > outside), simply start its name with two > underscores《Beginning Python From Novice > to Professional》but there is another saying > goes:Beginning a variable name with a single und

Re: Param decorator - can you suggest improvements

2013-01-17 Thread Steven D'Aprano
On Thu, 17 Jan 2013 06:35:29 -0800, Mark Carter wrote: > I thought it would be interesting to try to implement Scheme SRFI 39 > (Parameter objects) in Python. > > The idea is that you define a function that returns a default value. If > you call that function with no arguments, it returns the cur

Warning for users of the Python and Jython wiki

2013-01-17 Thread Steven D'Aprano
Hello all, Some time recently, the wiki at http://wiki.python.org/ was hacked. The vandal who broke in deleted all the wiki data. However, it is possible that before destroying the data, he may have gained access to user passwords. If you had an account on the wiki, and use the same password e

Re: [HELP!] a doubt about entering password in python

2013-01-17 Thread Steven D'Aprano
On Fri, 18 Jan 2013 10:49:30 +0800, douxin wrote: > i use Popen to execute "su -c 'fdisk -l'" in sub process,and > assigned subprocess.PIPE to stdin,stdout i tried to enter password > by doing "stdin.write("password"+"\n")" and i expected i could get > the output of "fdisk -l" by d

Re: Param decorator - can you suggest improvements

2013-01-18 Thread Steven D'Aprano
On Fri, 18 Jan 2013 03:38:08 +, Dan Sommers wrote: > On Thu, 17 Jan 2013 15:21:08 +0000, Steven D'Aprano wrote: > >> On Thu, 17 Jan 2013 06:35:29 -0800, Mark Carter wrote: >> >>> I thought it would be interesting to try to implement Scheme SRFI 39 &

Re: Any built-in ishashable method ?

2013-01-18 Thread Steven D'Aprano
On Fri, 18 Jan 2013 12:56:09 +0100, Jean-Michel Pichavant wrote: >> So I'm guessing you had a key where >> >> key1 == key2 did not imply hash(key1) == hash(key2) >> >> I don't see a way to avoid that problem in a look-before-you-leap test. >> >> -- >> http://mail.python.org/mailman/listinfo/pyt

Re: Safely add a key to a dict only if it does not already exist?

2013-01-19 Thread Steven D'Aprano
On Fri, 18 Jan 2013 20:15:26 -0800, Chris Rebert wrote: > On Friday, January 18, 2013, Steven D'Aprano wrote: > >> I wish to add a key to a dict only if it doesn't already exist, but do >> it in a thread-safe manner. [...] > I'm not entirely sure, but h

Re: Messing with the GC

2013-01-19 Thread Steven D'Aprano
On Sat, 19 Jan 2013 14:47:16 +, Jens Thoms Toerring wrote: > Ok, the destrucor for the first instance of the X class is called only > after printing out "After", so the GC didn't delete the object before. > But then there are obviously no calls of the destructors of neither the > second instan

Re: Messing with the GC

2013-01-19 Thread Steven D'Aprano
On Sat, 19 Jan 2013 16:24:37 +, Steven D'Aprano wrote: > On Sat, 19 Jan 2013 14:47:16 +, Jens Thoms Toerring wrote: > >> Ok, the destrucor for the first instance of the X class is called only >> after printing out "After", so the GC didn't delete th

Re: Messing with the GC

2013-01-19 Thread Steven D'Aprano
And further thoughts... On Sat, 19 Jan 2013 14:47:16 +, Jens Thoms Toerring wrote: > Hi, > >triggered by some problems I had with PySide I got a bit > confused about what the GC may do in certain situations. Here's a small > test program I cobbled together: > > import sys > > class X(

How do functions get access to builtins?

2013-01-19 Thread Steven D'Aprano
I've been playing around with ChainedMap in Python 3.3, and run into something which perplexes me. Let's start with an ordinary function that accesses one global and one builtin. x = 42 def f(): print(x) If you call f(), it works as expected. But let's make a version with no access to bu

Re: PyWart: Exception error paths far too verbose

2013-01-19 Thread Steven D'Aprano
On Sat, 19 Jan 2013 19:15:55 -0800, Ramchandra Apte wrote: [snip dozens of irrelevant quoted lines] > Right-click the file in the traceback and there is an "Go to file/line" > option. Please trim your replies so that the reader doesn't have to scroll through page after page of irrelevant text t

Re: To make a method or attribute private

2013-01-20 Thread Steven D'Aprano
On Sun, 20 Jan 2013 06:52:32 -0800, iMath wrote: [snip many dozens of lines of irrelevant text] > what's the meaning of 'object' in > class A(object) > and > class B(object) ? Please trim your replies. We don't need to scroll past page after page of irrelevant text which we have already read.

Re: ANN: Python training "text movies"

2013-01-20 Thread Steven D'Aprano
On Sun, 20 Jan 2013 18:54:03 +0100, Franck Ditter wrote: [snip quoting NINE levels deep] > When executing jstmovie.py, it complains : 'template.html' not found in > tmovies... Please trim unnecessary quoted text out of your replies. We don't need to read page after page of irrelevant comments t

Re: To make a method or attribute private

2013-01-20 Thread Steven D'Aprano
On Sun, 20 Jan 2013 17:14:36 -0800, iMath wrote: [...] > so there is no REAL private variable in Python but conversion exists in > it that python programmer should follow and recognize .right ? There are no "REAL private variables" in most languages. Consider the C++ trick "#define private publi

Re: Else statement executing when it shouldnt

2013-01-21 Thread Steven D'Aprano
On Sun, 20 Jan 2013 22:00:10 -0800, alex23 wrote: > On Jan 21, 2:54 pm, eli m wrote: >> hint: Use the comments in the code to find out where my error is. > > Pro-tip: when people you're asking for help tell you how you can make it > easier for them to help you, a snide response isn't the correct

Re: why not?

2013-01-21 Thread Steven D'Aprano
On Mon, 21 Jan 2013 11:02:10 -0600, kwakukwatiah wrote: > f = open(r'c:\text\somefile.txt') > for i in range(3): >print str(i) + ': ' + f.readline(), > > please with the print str(i) + ‘: ‘ + f.readline(), > why not print str(i) + f.readline(), Because the output will be different. The

Re: need explanation

2013-01-21 Thread Steven D'Aprano
On Mon, 21 Jan 2013 10:06:41 -0600, kwakukwatiah wrote: > please I need some explanation on sys.stdin and sys.stdout, and piping > out "stdin" and "stdout" (and also stderr) are three special, standard, system files used by console programs that read and write text. That's nearly all of them.

Re: Using filepath method to identify an .html page

2013-01-22 Thread Steven D'Aprano
On Tue, 22 Jan 2013 02:07:54 -0800, Ferrous Cranus wrote: > Hello, i decided to switch from embedding string into .html to actually > grab the filepath in order to identify it: What do you think "the filepath" means, and how do you think you would grab it? I can only guess you mean the full pat

Re: Using filepath method to identify an .html page

2013-01-22 Thread Steven D'Aprano
On Tue, 22 Jan 2013 04:47:16 -0800, Ferrous Cranus wrote: > htmlpage = a string respresenting the absolute path of the requested > .html file That is a very misleading name for a variable. The contents of the variable are not a html page, but a file name. htmlpage = "/home/steve/my-web-page.ht

Re: Using filepath method to identify an .html page

2013-01-22 Thread Steven D'Aprano
On Tue, 22 Jan 2013 11:36:31 -0700, Michael Torrie wrote: > I'm sorry you are getting so frustrated. There's obviously a language > barrier here, I don't think there is. The OP's posts have been written in excellent English. I think we've been well and truly trolled, by somebody who even uses

Re: Using filepath method to identify an .html page

2013-01-22 Thread Steven D'Aprano
On Tue, 22 Jan 2013 11:36:31 -0700, Michael Torrie wrote: > I'm sorry you are getting so frustrated. There's obviously a language > barrier here, I don't think there is. The OP's posts have been written in excellent English. I think we've been well and truly trolled, by somebody who even uses

<    7   8   9   10   11   12   13   14   15   16   >