Re: A desperate lunge for on-topic-ness

2012-10-18 Thread Chris Angelico
On Fri, Oct 19, 2012 at 3:16 AM, Evan Driscoll wrote: >Python isn't as bad as C++ though (my main other language), where >80 characters can go by *very* quickly. > > 2. Backslash continuations are *terrible*. I hate them with a firery >passion. :-) A line could be 1000 characters long

Re: [2.5.1 + CGI] Which interpreter and files?

2012-10-19 Thread Chris Angelico
On Fri, Oct 19, 2012 at 9:02 PM, Gilles wrote: > 1. Mongoose must be told in the shebang file where to locate the > interpreter, but ActivePython 2.5.1 comes with fours files that look > like the interpreter (actually, two files, since the other two have > the same size so they are probably left o

Re: Python does not take up available physical memory

2012-10-19 Thread Chris Angelico
On Sat, Oct 20, 2012 at 4:08 AM, Pradipto Banerjee wrote: > I am trying to read a file into memory. The size of the file is around 1 GB. > I have a 3GB memory PC and the Windows Task Manager shows 2.3 GB available > physical memory when I was trying to read the file. I tried to read the file > as

Re: use of exec()

2012-10-19 Thread Chris Angelico
On Sat, Oct 20, 2012 at 10:43 AM, lars van gemerden wrote: > Do you have any ideas about to what extend the "lambda" version of the code > (custom code is only the 'body' of the lambda function) has the same issues? The lambda version definitely has the same issues. You can do pretty much anythi

Re: Python does not take up available physical memory

2012-10-19 Thread Chris Angelico
On Sat, Oct 20, 2012 at 9:22 AM, Pradipto Banerjee wrote: > Dennis, > > 1. Yes, .readlines() work where .read() fails. Thanks for the suggestion - > this has really given a big boost to the size of the data I can read. If at all possible, consider reading the file iteratively and retaining only

Re: A desperate lunge for on-topic-ness

2012-10-21 Thread Chris Angelico
On Sun, Oct 21, 2012 at 7:07 PM, Steven D'Aprano wrote: > On Sat, 20 Oct 2012 14:18:47 +, Grant Edwards wrote: >> True, but nobody prints source code out on paper do they? > > I do. > > There's nothing better than spreading out a dozen sheets of source code > over a table to get a good, high-l

Re: A desperate lunge for on-topic-ness

2012-10-21 Thread Chris Angelico
On Sun, Oct 21, 2012 at 9:00 PM, Steven D'Aprano wrote: > Er, no. Note spelling of "source code" vs "souce code". Hence the grin. Ahh. I totally didn't see that, I'm way too used to reading past typos. Sure. Printing out *source* code, that's altogether different. Me, though, I don't print anyth

Re: A desperate lunge for on-topic-ness

2012-10-21 Thread Chris Angelico
On Mon, Oct 22, 2012 at 6:11 AM, Steven D'Aprano wrote: > On Sun, 21 Oct 2012 22:43:07 +1100, Chris Angelico wrote: > >> On Sun, Oct 21, 2012 at 9:00 PM, Steven D'Aprano >> wrote: >>> Er, no. Note spelling of "source code" vs "souce code&qu

Re: A desperate lunge for on-topic-ness

2012-10-21 Thread Chris Angelico
On Mon, Oct 22, 2012 at 7:19 AM, Roy Smith wrote: > Of course, the same can happen in Python. I could do: > > foo = "default value" > if blah == 47: >fooo = "some other value" > print foo > > No syntax error, no NameError, just the wrong thing printing. Yeah, that's the worst kind of bug. No

Re: A desperate lunge for on-topic-ness

2012-10-22 Thread Chris Angelico
On Mon, Oct 22, 2012 at 5:30 PM, Steven D'Aprano wrote: > For languages without static types, what other reasons for declaring > variables are there? The main one is scope nesting. Compare a few different languages. Python: If you don't declare, it's global if you don't rebind it, but local if y

Re: Python input function not working in 2.7 version

2012-10-24 Thread Chris Angelico
On Wed, Oct 24, 2012 at 9:37 PM, Morten Engvoldsen wrote: > I am facing issue with input() of Python 2.7. When i run the program it > doesn't display any line to take user input . Below is the code: > > But the above print function doesn't display the out put in same way. I am > new to Python and

Re: classes

2012-10-24 Thread Chris Angelico
On Wed, Oct 24, 2012 at 11:11 PM, inshu chauhan wrote: > print " Adding twice of %4.2f gives " % (y.addtwice()) > > > Error is : > > Traceback (most recent call last): > File "Z:\learning Python\learn5.py", line 35, in > print " Adding twice of %4.2f gives " % (y.addtwice()) > TypeError: ad

Re: classes

2012-10-24 Thread Chris Angelico
On Thu, Oct 25, 2012 at 12:02 AM, inshu chauhan wrote: > I changed the programme to this : > def addtwice(self, x): > self.add(x) > self.add(x) > return x > y = Bag() > print y.addtwice(4) > > Now its not showing any error but result is same as the number passed for

Re: classes

2012-10-24 Thread Chris Angelico
On Thu, Oct 25, 2012 at 1:02 AM, inshu chauhan wrote: > ok.. This was an example i was trying to run from > http://docs.python.org/tutorial/classes.html ... I would strongly recommend going back a bit in the tutorial and reading about functions: http://docs.python.org/tutorial/controlflow.html

Re: classes

2012-10-24 Thread Chris Angelico
On Thu, Oct 25, 2012 at 2:14 AM, Zero Piraeus wrote: > By the way ... while Bag.addtwice() is legal Python [and I understand > that you're just playing around here], a method that both "does > something" [changes the object] and "gives something" [returns a > useful value] when that's not strictly

Re: classes

2012-10-24 Thread Chris Angelico
On Thu, Oct 25, 2012 at 3:10 AM, Zero Piraeus wrote: > On 24 October 2012 11:18, Chris Angelico wrote: >> On Thu, Oct 25, 2012 at 2:14 AM, Zero Piraeus wrote: >>> [... on return values and side effects ...] >> >> Side point: It's not that it's *bad* code

Re: while expression feature proposal

2012-10-24 Thread Chris Angelico
On Thu, Oct 25, 2012 at 9:26 AM, Cameron Simpson wrote: > If I could write this as: > > if re_FUNKYPATTERN.match(test_string) as m: > do stuff with the results of the match, using "m" Then you'd be right there with C-like languages where assignment is an expression :) while (tok = strtok(b

Re: resume execution after catching with an excepthook?

2012-10-25 Thread Chris Angelico
On Thu, Oct 25, 2012 at 12:15 PM, Steven D'Aprano wrote: > I don't believe that there is any > way to jump back to the line of code that just failed (and why would you, > it will just fail again) There are several reasons to retry something after an exception, mainly if some external state gets c

Re: bit count or bit set && Python3

2012-10-25 Thread Chris Angelico
On Fri, Oct 26, 2012 at 2:25 AM, Christian Heimes wrote: > Simple, easy, faster than a Python loop but not very elegant: > >bin(number).count("1") Unlikely to be fast. What you may want is some sort of hybrid loop/lookup approach. Do you know what your highest bit number is going to be? For

Re: resume execution after catching with an excepthook?

2012-10-25 Thread Chris Angelico
On Fri, Oct 26, 2012 at 2:31 AM, Hans Mulder wrote: > This seems to work; I'm not sure how robust it is: > > import signal > > def handler(signum, frame): > while True: > q = raw_input("This will quit the program, are you sure? [y/N]") > if q[:1] in "yY": > raise Ke

Re: bit count or bit set && Python3

2012-10-25 Thread Chris Angelico
On Fri, Oct 26, 2012 at 3:17 AM, rusi wrote: > On Oct 25, 8:57 pm, Steven D'Aprano +comp.lang.pyt...@pearwood.info> wrote: >> py> min(t.repeat(number=1, repeat=7)) >> 0.6819710731506348 >> py> min(t.repeat(number=100, repeat=7)) >> 4.141788959503174 >> >> That makes the "inelegant" solution u

Re: while expression feature proposal

2012-10-25 Thread Chris Angelico
On Fri, Oct 26, 2012 at 5:06 PM, Paul Rubin wrote: > Dan Loewenherz writes: >> In this case, profile_id is "None" when the loop breaks. It would be >> much more straightforward (and more Pythonic, IMO), to write: >> >> client = StrictRedis() >> while client.spop("profile_ids") as profile_

Re: a.index(float('nan')) fails

2012-10-26 Thread Chris Angelico
On Sat, Oct 27, 2012 at 3:23 AM, Steven D'Aprano wrote: > In real life, you are *much* more likely to run into these examples of > "insanity" of floats than to be troubled by NANs: > > - associativity of addition is lost > - distributivity of multiplication is lost > - commutativity of addition is

Re: while expression feature proposal

2012-10-26 Thread Chris Angelico
On Sat, Oct 27, 2012 at 10:19 AM, Devin Jeanpierre wrote: > On Fri, Oct 26, 2012 at 2:23 AM, Chris Angelico wrote: >> while (client.spop("profile_ids") as profile_id) is not None: >> print profile_id >> >> Why is everyone skirting around C-style assign

Re:

2012-10-27 Thread Chris Angelico
On Sun, Oct 28, 2012 at 12:13 AM, Shaojun Li wrote: > nothing Step aside, 'import this', we've found the true Zen of Python! ChrisA -- http://mail.python.org/mailman/listinfo/python-list

Re: ctypes free memory which is allocated in C DLL

2012-10-27 Thread Chris Angelico
On Sun, Oct 28, 2012 at 1:42 AM, wrote: > Hi Guys, > > I have a DLL which written in C language, one of the function is to allocate > a structure, fill the members and then return the pointer of the structure. > > After Python called this function, and done with the returned structure, I > woul

Re: ctypes free memory which is allocated in C DLL

2012-10-27 Thread Chris Angelico
On Sun, Oct 28, 2012 at 2:40 AM, Ken Chen wrote: > Yes, I agree writing a corresponding API to free the memory is the best > practice and best bet. > Sometimes, the third party API may not provide that. Then that's a majorly dangerous third party API. The only time it's safe to provide a half-on

Re: attaching names to subexpressions

2012-10-27 Thread Chris Angelico
On Sun, Oct 28, 2012 at 4:57 PM, Devin Jeanpierre wrote: > What if he wants to avoid both downsides A and B? What solution does > he use then? He switches to a language whose BDFL is not Steven D'Aprano. :) No offense meant Steven... ChrisA -- http://mail.python.org/mailman/listinfo/python-lis

Re: attaching names to subexpressions

2012-10-28 Thread Chris Angelico
On Sun, Oct 28, 2012 at 6:12 PM, F.R. wrote: > > How about: > > line = True > while line: > > line = function(x, y, z) > do something with(line) > > ? That's going to go through the body of the loop with a false line before breaking out. In some situations that's not a problem, bu

Re: Help understanding an Object Oriented Program example

2012-10-28 Thread Chris Angelico
plementable code. Actually, it's quite workable. It's enough to paste into the interactive interpreter and play with. That's one of Python's best features - it's really easy to play with. And if you put parentheses around your print argument, it'll be fully Python 3 compatible (though when you run it in Python 2, you get an old-style class - but since the book's assuming Py3, new-style is what you want anyway). >>> for i in Contact.all_contacts: print(i.name + ' ' + i.email) Hope that helps! Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list

Re: Simple Python question for some

2012-10-28 Thread Chris Angelico
On Mon, Oct 29, 2012 at 10:51 AM, Mark L. Hotz wrote: > At the IDLE prompt, when I enter “b” > 99, it responds True. In fact, it > doesn’t matter which number is entered here, “b” is always greater (e.g. “b” >> 1 == True; “b” > 10 == True, or “b” < 99 = False). To Python, different object typ

Re: Re: Simple Python question for some

2012-10-28 Thread Chris Angelico
On Mon, Oct 29, 2012 at 3:30 PM, Evan Driscoll wrote: > On 10/28/2012 7:18 PM, Chris Angelico wrote: >> Which means that strings will ALWAYS be compared as strings, and >> numbers will ALWAYS be compared as numbers, and ne'er the twain shall >> conflict. I can trust Py

Re: Negative array indicies and slice()

2012-10-29 Thread Chris Angelico
On Mon, Oct 29, 2012 at 10:19 PM, Steven D'Aprano wrote: >> In 'C', where Python is written, > > That's a popular misapprehension. Python is written in Java, or Lisp, or > Haskell, or CLR (dot Net), or RPython, or Ocaml, or Parrot. Each of those > languages have, or had, at least one Python implem

Re: Negative array indicies and slice()

2012-10-29 Thread Chris Angelico
On Mon, Oct 29, 2012 at 3:52 PM, Andrew Robinson wrote: > I am curious as to how quickly it constructs the result compared to a slice > operation. > > Eg: > a[1:5] > vs. > [ a[i] for i in xrange[1:5] ] For the most part, don't concern yourself with performance. Go with functionality and readabili

Re: Negative array indicies and slice()

2012-10-29 Thread Chris Angelico
On Mon, Oct 29, 2012 at 5:01 PM, Andrew Robinson wrote: > Looking at some of the online programming notes -- a slice apparently > doesn't use an integer storage variable that is capable of arbitrary > expansion. =-O -- and hence, won't work for very large sized lists. That > actually explains so

Re: Immutability and Python

2012-10-29 Thread Chris Angelico
On Tue, Oct 30, 2012 at 2:55 AM, Paul Rubin wrote: > andrea crotti writes: >> and we want to change its state incrementing the number ... >> the immutability purists would instead suggest to do this: >> def increment(self): >> return NumWrapper(self.number + 1) > > Immutability puris

Re: Nice solution wanted: Hide internal interfaces

2012-10-29 Thread Chris Angelico
On Tue, Oct 30, 2012 at 3:33 AM, Johannes Bauer wrote: > Hi there, > > I'm currently looking for a good solution to the following problem: I > have two classes A and B, which interact with each other and which > interact with the user. Instances of B are always created by A. > > Now I want A to ca

Re: Immutability and Python

2012-10-29 Thread Chris Angelico
On Tue, Oct 30, 2012 at 6:23 AM, Ian Kelly wrote: > _MyImmutableClass = namedtuple('MyImmutableClass', 'field1 field2 > field3 field4') > > class MyImmutableClass(_MyImmutableClass): Question: Is it clearer to take advantage of the fact that the base class can be an arbitrary expression? class M

Re: Negative array indicies and slice()

2012-10-29 Thread Chris Angelico
On Tue, Oct 30, 2012 at 2:42 AM, Andrew Robinson wrote: > No, there was no error at all. Pthon just crashed & exited; not even an > exception that I can recall. It was if it exited normally! Can you create a reproducible test case? There's usually a cause to these sorts of things. ChrisA --

Re: date and time comparison how to

2012-10-29 Thread Chris Angelico
On Tue, Oct 30, 2012 at 3:20 PM, noydb wrote: > But for the user supplied date... I'm not sure of the format just yet... > testing with a string for now (actual date-date might be possible, tbd > later), so like '10292012213000' (oct 29, 2012 9:30pm). How would you get > that input into a form

Re: exec with partial globals

2012-10-30 Thread Chris Angelico
On Tue, Oct 30, 2012 at 11:00 PM, Helmut Jarausch wrote: > Hi, > > I'd like to give the user the ability to enter code which may only rebind > a given set of names but not all ones. > > How can 'filter' the gobal namespace such that modifying 'A' is allowed > but any attempt to modify 'B' should g

Re: exec with partial globals

2012-10-30 Thread Chris Angelico
On Tue, Oct 30, 2012 at 11:57 PM, Helmut Jarausch wrote: > Given spreadsheet S (Source) and D (Destination) as objects (wrapping a > dictionary) a possible (legal) input would be > > D.price= D.price-S.discount > > No other fields of 'D' should be modifiable. That's a bit harder. What you're des

Re: Negative array indicies and slice()

2012-10-30 Thread Chris Angelico
On Wed, Oct 31, 2012 at 8:47 AM, Ian Kelly wrote: > On Tue, Oct 30, 2012 at 3:33 PM, Mark Lawrence > wrote: >> On 30/10/2012 18:02, Ian Kelly wrote: >>> >>> On Tue, Oct 30, 2012 at 10:14 AM, Ethan Furman wrote: File a bug report? >>> >>> >>> Looks like it's already been wontfixed back

Re: sort order for strings of digits

2012-10-31 Thread Chris Angelico
On Thu, Nov 1, 2012 at 10:44 AM, Steven D'Aprano wrote: > On the contrary. If you are using cmp with sort, your sorts are slow, and > you should upgrade to using a key function as soon as possible. > But cmp_to_key doesn't actually improve anything. So I'm not sure how Py3 has achieved anything;

Re: Negative array indicies and slice()

2012-11-01 Thread Chris Angelico
On Fri, Nov 2, 2012 at 1:12 AM, Ethan Furman wrote: > In other words, the slice contains the strings, and my code calculates > the offsets -- Python doesn't do it for me. That's correct, but you're still translating those strings into numeric indices. You can slice a database record based on colu

Re: Negative array indicies and slice()

2012-11-01 Thread Chris Angelico
On Thu, Nov 1, 2012 at 10:32 PM, Andrew Robinson wrote: > presently slice() allows memory leaks through GC loops. Forgive me if I've missed something here, but isn't it only possible to make a refloop by decidedly abnormal behaviour? Stuff like: a=[]; a.append(slice(a)) Seriously, who does this

Re: Obnoxious postings from Google Groups

2012-11-01 Thread Chris Angelico
On Fri, Nov 2, 2012 at 9:08 AM, wrote: > On 11/01/2012 03:55 AM, Jamie Paul Griffin wrote: >> Anybody serious about programming should be using a form of >> UNIX/Linux if you ask me. It's inconceivable that these systems >> should be avoided if you're serious about Software Engineering and >> Com

Re: Avoiding defunct processes

2012-11-01 Thread Chris Angelico
On Fri, Nov 2, 2012 at 1:16 PM, Richard wrote: > Hello, > > I create child processes with subprocess.Popen(). > Then I either wait for them to finish or kill them. > Either way these processes end up as defunct until the parent process > completes: > $ ps e > 6851 pts/5Z+ 1:29 [python] >

Re: pythonic way

2012-11-02 Thread Chris Angelico
On Fri, Nov 2, 2012 at 6:14 PM, jack wrote: > Sometimes, I need to alter the element as traverse a list like this (it's a > sample): > c = range(10) > i = 0 > for ele in c: > # do something > # branch: > c[i] = # value > i += 1 > > How to be pythonic

Re: pythonic way

2012-11-02 Thread Chris Angelico
On Fri, Nov 2, 2012 at 7:58 PM, jack wrote: > thanks,but I don't think enumerate() is my want > Have some ways to operate the reference of element,not a copy when I tried > to traverse a list? > > I'm so sorry about my poor English, hope you don't mind it. No probs, I'll be a little less vague an

Re: Organisation of python classes and their methods

2012-11-02 Thread Chris Angelico
On Fri, Nov 2, 2012 at 7:08 PM, Martin Hewitson wrote: > > On 2, Nov, 2012, at 08:38 AM, Paul Rubin wrote: > >> Martin Hewitson writes: >>> So, is there a way to put these methods in their own files and have >>> them 'included' in the class somehow? ... Is there an official python >>> way to do

Re: What the diferences : web.py Tornado Twisted ?!

2012-11-02 Thread Chris Angelico
On Sat, Nov 3, 2012 at 12:04 PM, Mark Lawrence wrote: > On 02/11/2012 15:50, nepaul wrote: >> >> What the diferences : web.py Tornado Twisted ?! >> > > Web.py is spelt w e b . p y. Tornado is spelt T o r n a d o. Twisted is > spelt T w i s t e d. Wow! That's profound! Oh, the insights made avai

Re: Obnoxious postings from Google Groups

2012-11-03 Thread Chris Angelico
On Sun, Nov 4, 2012 at 1:24 AM, Dave Angel wrote: > For the DOS world, real programmers have written a "complete" *.com > program using only echo. Only as an exercise. It was satisfying to prove to myself that I could do it, but pretty useless. Normally I used DEBUG.EXE to build my code - it has

Re: is implemented with id ?

2012-11-03 Thread Chris Angelico
On Sun, Nov 4, 2012 at 9:18 AM, Steven D'Aprano wrote: > On Sat, 03 Nov 2012 22:49:07 +0100, Hans Mulder wrote: > Actually, for many applications, the space "savings" may actually be > *costs*, since interning forces Python to hold onto strings even after > they would normally be garbage collected

Re: is implemented with id ?

2012-11-03 Thread Chris Angelico
On Sun, Nov 4, 2012 at 12:14 PM, Oscar Benjamin wrote: > On 3 November 2012 22:50, Chris Angelico wrote: >> This one I haven't checked the source for, but ISTR discussions on >> this list about comparison of two unequal interned strings not being >> optimized, so the

Re: is implemented with id ?

2012-11-03 Thread Chris Angelico
On Sun, Nov 4, 2012 at 2:10 PM, Steven D'Aprano wrote: > /* Shortcut for empty or interned objects */ > if (v == u) { > Py_DECREF(u); > Py_DECREF(v); > return 0; > } > result = unicode_compare(u, v); > > where v and u are pointers to the unicode object. There's a shortcut if they're t

Re: Obnoxious postings from Google Groups

2012-11-04 Thread Chris Angelico
On Mon, Nov 5, 2012 at 5:10 PM, rusi wrote: > Among people who know me, I am a linux nerd: My sister scolded me > yesterday because I put files on her computer without spaces: > DoesAnyoneWriteLikeThis?!?! My filenames seldom have spaces in them, but that has nothing to do with how I write Englis

Re: Multi-dimensional list initialization

2012-11-04 Thread Chris Angelico
On Mon, Nov 5, 2012 at 6:07 PM, Chris Rebert wrote: x = None x.a = 42 > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'NoneType' object has no attribute 'a' Python needs a YouGottaBeKiddingMeError for times when you do something utterly insane like this.

Re: [Python-ideas] sys.py3k

2012-11-04 Thread Chris Angelico
On Mon, Nov 5, 2012 at 9:33 AM, Steven D'Aprano wrote: > On 05/11/12 08:49, anatoly techtonik wrote: >> >> if sys.py3k: >># some py2k specific code >>pass > > # Bring back reload in Python 3. > try: > reload > except NameError: > from imp import reload > > try: > any > except N

Re: No more Python support in NetBeans 7.0

2012-11-04 Thread Chris Angelico
On Mon, Nov 5, 2012 at 5:29 PM, Demian Brecht wrote: > > On 2012-11-04, at 4:45 PM, bkube...@gmail.com wrote: >> However I am not happy about having to use different IDEs as I find myself >> coding in both python and php from project to project. > > One of the many reasons Vim is my editor of cho

Re: Multi-dimensional list initialization

2012-11-05 Thread Chris Angelico
On Mon, Nov 5, 2012 at 6:54 PM, Andrew Robinson wrote: > On 11/04/2012 11:27 PM, Chris Angelico wrote: >> >> On Mon, Nov 5, 2012 at 6:07 PM, Chris Rebert wrote: >>>>>> >>>>>> x = None >>>>>> x.a = 42 >>> >&g

Re: Obnoxious postings from Google Groups

2012-11-05 Thread Chris Angelico
On Mon, Nov 5, 2012 at 11:56 PM, Roy Smith wrote: > That's a very ascii-esqe attitude. In a fully unicode world, I could > easily see using U+00A0 (NO-BREAK SPACE) in file names, and still have > space-delimited CLI work just fine. > Oh, do you have a "U+00A0-bar" on your keyboard? ChrisA -- h

Re: Coordination between developers in the Python project

2012-11-05 Thread Chris Angelico
On Tue, Nov 6, 2012 at 6:09 AM, Terry Reedy wrote: >> I would like to remind you that the participation is absolutely >> anonymous and voluntary, and you can quit it at any time. Your answers >> will be strictly confidential and will be used only for research purpose >> (no commercial use of any i

Re: Coordination between developers in the Python project

2012-11-05 Thread Chris Angelico
On Fri, Nov 2, 2012 at 7:49 AM, Tengy Td wrote: > It would be a great help for me if you could answer a short online survey > (it should take approximately 5 minutes). > > This survey is designed to reach a better understanding of the cooperation > and coordination between developers in Free/libre

Re: Multi-dimensional list initialization

2012-11-05 Thread Chris Angelico
On Tue, Nov 6, 2012 at 12:32 PM, Oscar Benjamin wrote: > I was just thinking to myself that it would be a hard thing to change > because the list would need to know how to instantiate copies of all > the different types of the elements in the list. Then I realised it > doesn't. It is simply a case

Re: problem with eval and time

2012-11-05 Thread Chris Angelico
On Tue, Nov 6, 2012 at 3:29 PM, Wincent wrote: > Thanks. > > I fetch data from social networking sites and want to mark the time of > access. I store all the information in a redis database, which converts > everything into strings and I need to convert those strings back to original > python o

Re: How to only get a list of the names of the non-directory files in current directory ('.')?

2012-11-05 Thread Chris Angelico
On Tue, Nov 6, 2012 at 4:19 PM, iMath wrote: > How to only get a list of the names of the non-directory files in current > directory ('.')? > (Note excluding its subdirectories ). > > I need the code : ) Start by getting a list of names of everything in the current directory. Then filter that l

Re: Multi-dimensional list initialization

2012-11-05 Thread Chris Angelico
On Tue, Nov 6, 2012 at 4:51 PM, Andrew Robinson wrote: > I really don't think doing a shallow copy of lists would break anyone's > program. Well, it's a change, a semantic change. It's almost certainly going to break _something_. But for the sake of argument, we can suppose that the change could

Re: Coordination between developers in the Python project

2012-11-06 Thread Chris Angelico
On Tue, Nov 6, 2012 at 7:49 PM, Ian Kelly wrote: > On Mon, Nov 5, 2012 at 3:01 PM, Chris Angelico wrote: >> By "URL unshortening service" you mean a simple HTTP request to >> bit.ly:80, right? :) Though I admit there aren't many easy and >> convenient

Re: [Python-ideas] sys.py3k

2012-11-07 Thread Chris Angelico
On Thu, Nov 8, 2012 at 5:35 AM, anatoly techtonik wrote: > I thought of sys.py3k check as an explicit way to guard the code that should > be maintained extra carefully for Python 3 compatibility, so that you can > grep the source for this constant and remove all the hacks (such as bytes to > strin

Re: [Python-ideas] sys.py3k

2012-11-07 Thread Chris Angelico
On Thu, Nov 8, 2012 at 10:56 AM, Steven D'Aprano wrote: > On Thu, 08 Nov 2012 10:14:35 +1100, Chris Angelico wrote: > >> On Thu, Nov 8, 2012 at 5:35 AM, anatoly techtonik >> wrote: >>> I thought of sys.py3k check ... > > Chris, you regularly reply to t

Re: isinstance(.., file) for Python 3

2012-11-08 Thread Chris Angelico
On Thu, Nov 8, 2012 at 11:05 PM, Ulrich Eckhardt wrote: > Firstly, I have code that allows either a file or a string representing its > content as parameter. If the parameter is a file, the content is read from > the file. In Python 2, I used "isinstance(p, file)" to determine whether the > parame

Re: accuracy problem in calculation

2012-11-08 Thread Chris Angelico
On Fri, Nov 9, 2012 at 4:05 AM, Debashish Saha wrote: > (15+1.00067968)-(15+1.00067961) > Out[102]: 2.384185791015625e-07 > > 1.00067968-(1.00067961) > Out[103]: 7.1866624e-08 > > above i am showing the two different results,though the two outputs > should be same if we do

Re: Multi-dimensional list initialization

2012-11-08 Thread Chris Angelico
On Fri, Nov 9, 2012 at 12:39 PM, Mark Lawrence wrote: > On 07/11/2012 01:55, Steven D'Aprano wrote: >> >> >> Who knows? Who cares? Nobody does: >> >> n -= n >> > > But I've seen this scattered through code: > > x := x - x - x Can you enlighten us as to how this is better than either: x := -x or

Re: duck typing assert

2012-11-08 Thread Chris Angelico
On Fri, Nov 9, 2012 at 12:00 PM, Ian Kelly wrote: > looks(Foo).like(IFoo), on the other hand, is crystal clear about which > argument is which. I'm not so sure that it is, tbh. If you read it like an English sentence, it's clearly testing whether Foo matches the template in IFoo, but which are yo

Re: Multi-dimensional list initialization

2012-11-08 Thread Chris Angelico
On Fri, Nov 9, 2012 at 5:37 PM, Steven D'Aprano wrote: > On Fri, 09 Nov 2012 17:07:09 +1100, Chris Angelico wrote: >> Can you enlighten us as to how this is better than either: >> x := -x >> or >> x := 0 - x >> ? I'm not seeing it. > > I'

Re: Python3.3 str() bug?

2012-11-09 Thread Chris Angelico
On Fri, Nov 9, 2012 at 10:08 PM, Helmut Jarausch wrote: > For me it's not funny, at all. His description "funny" was in reference to the fact that you described this as a bug. This is a heavily-used mature language; bugs as fundamental as you imply are unlikely to exist (consequences of design de

Re: duck typing assert

2012-11-09 Thread Chris Angelico
On Sat, Nov 10, 2012 at 1:01 AM, Andriy Kornatskyy wrote: > > 1. In looks-like we check features of Foo (that may be superset) of what IFoo > offers. > > assert looks(Foo).like(IFoo) > > 2. We can check if Foo is limited to IFoo only: > > assert looks(IFoo).like(Foo) > > So it valid to have both

Re: Multi-dimensional list initialization

2012-11-09 Thread Chris Angelico
On Sat, Nov 10, 2012 at 2:05 AM, rusi wrote: > In x86 assembler > mov ax, 0 > is 4 bytes Three bytes actually, B8 00 00 if my memory hasn't failed me. BA for DX, B9 ought to be BX and BB CX, I think. But yes, the xor or sub is two bytes and one clock. ChrisA -- http://mail.python.org/mailman/li

Re: Want to add dictionary keys to namespace?

2012-11-09 Thread Chris Angelico
On Sat, Nov 10, 2012 at 11:00 AM, Jeff Jeffries wrote: > Smart people, Is there a way I can add a dictionaries keys to the python > namespace? It would just be temporary as I am working with a large > dictionary, and it would speed up work using an IDE. I look and find > nothing... none of the ke

Re: Is there a simpler way to modify all arguments in a function before using the arguments?

2012-11-09 Thread Chris Angelico
On Sat, Nov 10, 2012 at 1:52 PM, Paul Rubin wrote: > bruceg113...@gmail.com writes: >> Is there a simpler way to modify all arguments in a function before >> using the arguments? > > Why do you want to do that? > Contrived example: def send_email(from, to, subj, body, whatever, other, headers, y

Re: Is there a simpler way to modify all arguments in a function before using the arguments?

2012-11-10 Thread Chris Angelico
On Sat, Nov 10, 2012 at 3:05 PM, Paul Rubin wrote: > Chris Angelico writes: >> Contrived example: >> def send_email(from, to, subj, body, whatever, other, headers, you, like): > > That should be a dictionary with the header names as indexes. In fact > there are alr

Re: Is there a simpler way to modify all arguments in a function before using the arguments?

2012-11-10 Thread Chris Angelico
On Sun, Nov 11, 2012 at 12:15 AM, wrote: > Thanks to all. > Steve's example is the one I will try next week. > Passing in lists, will work but it requires extra coding from the calling > routines to build the list. Not necessarily! Watch: def foo(*args): print(repr(args)) foo("Hello","wor

Re: Method default argument whose type is the class not yet defined

2012-11-10 Thread Chris Angelico
On Sun, Nov 11, 2012 at 6:33 AM, Jennie wrote: > ... def distance(self, point=None): > ... p = point if point else Point() I'd go with this one. Definitely not the third one, which mutates the class according to a current global every time a Point is instantiated - could be *extremely

Re: Method default argument whose type is the class not yet defined

2012-11-10 Thread Chris Angelico
On Sun, Nov 11, 2012 at 12:13 PM, Steven D'Aprano wrote: > Almost but not quite. I assume that, in a full Point class, you would > want Point(0, 0) to count as false in a boolean context. (A "falsey" > value, like None, [], 0.0, etc.) I would not assume that. The origin is a point, just like any

Re: Method default argument whose type is the class not yet defined

2012-11-10 Thread Chris Angelico
On Sun, Nov 11, 2012 at 1:43 PM, Ian Kelly wrote: > On Sat, Nov 10, 2012 at 7:13 PM, Chris Angelico wrote: >> I would not assume that. The origin is a point, just like any other. >> With a Line class, you could deem a zero-length line to be like a >> zero-element list, b

Re: skip Trackback error for ftp checking

2012-11-12 Thread Chris Angelico
On Mon, Nov 12, 2012 at 8:25 PM, moonhkt wrote: > On Nov 10, 2:50 pm, Steven D'Aprano +comp.lang.pyt...@pearwood.info> wrote: >> >> The same way you would skip any other error when you do something wrong: >> catch the exception. > > Thank. Added below. > try: >ftp = FTP(options.remote_host_ad

Re: Is there a way to creat a func that returns a cursor that can be used?

2012-11-12 Thread Chris Angelico
On Mon, Nov 12, 2012 at 9:45 PM, Khalid Al-Ghamdi wrote: > Is there a way to create a func that returns a cursor that can be used to > execute sql statements? Yes, and you're almost there! > I tried this (after importing sqlite3), but it gave me the error below: > def connect(): > retu

Re: How to only get a list of the names of the non-directory files in current directory ('.')?

2012-11-13 Thread Chris Angelico
On Wed, Nov 14, 2012 at 5:16 AM, emile wrote: > BTW, googling for "python how to get a list of names of everything in the > current directory" yields some good information as well. Google is your > friend for this level of question. Not sure anymore beyond that... It yields it? You mean Google

Re: How to only get a list of the names of the non-directory files in current directory ('.')?

2012-11-13 Thread Chris Angelico
On Wed, Nov 14, 2012 at 8:05 AM, John Gordon wrote: > In Chris Angelico > writes: > >> It yields it? You mean Google is an iterator? > > ITYM generator. Yeah, that thing. Troll fail. *whoops* ChrisA -- http://mail.python.org/mailman/listinfo/python-list

Re: Generate unique ID for URL

2012-11-13 Thread Chris Angelico
On Wed, Nov 14, 2012 at 2:25 PM, Richard wrote: > So the use case - I'm storing webpages on disk and want a quick retrieval > system based on URL. > I can't store the files in a single directory because of OS limitations so > have been using a sub folder structure. > For example to store data at

Re: Simple Question regarding running .py program

2012-11-13 Thread Chris Angelico
On Wed, Nov 14, 2012 at 2:31 PM, Caroline Hou wrote: > Thank you Dave and everybody here for your helpful comments!This place is > awesome! I found this group when I googled python-list. Seems like this is > not the usual way you guys access the list? There are several ways to communicate with

Re: Simple Question regarding running .py program

2012-11-13 Thread Chris Angelico
On Wed, Nov 14, 2012 at 4:08 PM, wrote: > On 11/13/2012 09:10 PM, Chris Angelico wrote: >> * Use a news-to-web gateway such as Google Groups. That >> specific one is deprecated on this list, as there's more >> noise than signal from Google Groups. > > Caroline,

Re: stackoverflow quote on Python

2012-11-14 Thread Chris Angelico
On Wed, Nov 14, 2012 at 7:56 PM, wrote: > I'am still fascinated by the mathematically absurd "negative > logic" used in and by the flexible string representation > (algorithm). I am still fascinated that you persist in comparing a buggy old Python against a bug-free new Python and haven't notice

Re: Simple Question regarding running .py program

2012-11-14 Thread Chris Angelico
On Wed, Nov 14, 2012 at 6:02 PM, wrote: > On 11/13/2012 11:02 PM, Chris Angelico wrote: >> To be more accurate: This is deprecated *by members of* this list. As >> there is no commanding/controlling entity here, it's up to each >> individual to make a decision - for i

Re: Subprocess puzzle and two questions

2012-11-14 Thread Chris Angelico
On Thu, Nov 15, 2012 at 1:22 AM, Roy Smith wrote: > Oh, my. You're using DNS as a replacement for ping? Fair enough. In > that case, all you really care about is that you can connect to port 53 > on the server... > > import socket > import time > s = socket.socket() > t0 = time.time() > s.conne

Re: Error

2012-11-14 Thread Chris Angelico
On Thu, Nov 15, 2012 at 2:18 AM, inshu chauhan wrote: > > for this code m getting this error : > > CODE : > def ComputeClasses(data): > if data[cy,cx] != (0.0,0.0,0.0): > centre = data[cy, cx] > ... > dist = distance(centre, point) > > ERROR

Re: Subprocess puzzle and two questions

2012-11-14 Thread Chris Angelico
> s = socket.socket() >>> s.connect(('8.8.8.8', 53)) > > In article , > Chris Angelico wrote: >>That assumes that (a) the remote server supports TCP for DNS > > This is true. I honestly don't know what percentage of DNS servers > out there only suppor

Re: Python questions help

2012-11-14 Thread Chris Angelico
fficulties you're having. If we write the code for you, it won't help you to learn, will it? Once you have some code that isn't working, we can help you to figure out what it is that isn't working. But do your best to write the code yourself first. Chris Angelico -- http://ma

Re: Subprocess puzzle and two questions

2012-11-14 Thread Chris Angelico
On Thu, Nov 15, 2012 at 12:49 PM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> I'm slightly surprised that there's no way with the Python stdlib to >> point a DNS query at a specific server > > Me too, including the "only slightly&

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