Re: Fallen Angels, Originators of Evil on Planet Earth?
I don't believe that angels originated evil. Take a look at this book http://www.amazon.com/The-Change-Freiderici-Ms/dp/147508076X/ref=sr_1_1?ie=UTF8qid=1337792796sr=8-1 -- http://mail.python.org/mailman/listinfo/python-list
Applying a patch from a diff in python (if possible)
Hi, I'm trying to synch up two databases that are very far from each other using diff and patch. Currently, what happens is a mysqldump on database A (which is linux) which is sent over to database B and over time the diff of this mysql is sent over to database B. The database B lives on a NAS server without any linux machines available (all of them are windows 7s) to apply the patch to the diff. I've been looking into the python diff modules and it seems that most can't deal with files (these .diff files are large and binary since the data in the database is all sorts of binary). Also I've had a look at the patch.exe program for windows which also complains about the file being binary (or something. i've tried all sorts of flags and they don't seem to work). Are there any patch modules out there that I'm missing? The diff_patch_match module doesn't seem to like the diffs with angle brackets Thanks for any help -- http://mail.python.org/mailman/listinfo/python-list
PyDev IPython Confusion
I have two versions of Python and Ipython; Python 2.6.6 with Ipython 0.11 and Python 2.7.3 with Ipython 0.12. When I run the Eclipse PyDev console for the Python 2.7.3 it says it is using Ipython 0.11 as the interpreter. Ipython 0.11 should not be in the Path for Python 2.7.3. Is this a bug in Ipython 0.12? Is there a command to check the Ipython version to verify it is Ipython 0.11 and not Ipython 0.12? Could this be something in the Windows registry that Ipython 0.11 is the 'registered' version of Ipython? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Applying a patch from a diff in python (if possible)
On May 24, 1:24 pm, Astan astan.c...@rhubarbfizz.com wrote: Hi, I'm trying to synch up two databases that are very far from each other using diff and patch. Currently, what happens is a mysqldump on database A (which is linux) which is sent over to database B and over time the diff of this mysql is sent over to database B. The database B lives on a NAS server without any linux machines available (all of them are windows 7s) to apply the patch to the diff. I've been looking into the python diff modules and it seems that most can't deal with files (these .diff files are large and binary since the data in the database is all sorts of binary). Also I've had a look at the patch.exe program for windows which also complains about the file being binary (or something. i've tried all sorts of flags and they don't seem to work). Are there any patch modules out there that I'm missing? The diff_patch_match module doesn't seem to like the diffs with angle brackets Thanks for any help Ignore me. I just figured out cygwin. -- http://mail.python.org/mailman/listinfo/python-list
Re: A better contextlib.contextmanager
Michele Simionato wrote: but I am asking a question instead: should I add this feature to the next release of the decorator module? I think it would be an excellent addition to your module. ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Book for a C Programmer?
hi, take 'Pro Python' (by Marty Alchin) regards Michael * hsa...@gmail.com hsa...@gmail.com [2012-05-24 07:54]: I am trying to join an online class that uses python. I need to brush up on the language quickly. Is there a good book or resource that covers it well but does not have to explain what an if..then..else statement is? Thanks. -- http://mail.python.org/mailman/listinfo/python-list -- Michael Poeltl Computational Materials Physics voice: +43-1-4277-51409 Univ. Wien, Sensengasse 8/12 fax: +43-1-4277-9514 (or 9513) A-1090 Wien, AUSTRIA cmp.mpi.univie.ac.at --- ubuntu-11.10 | vim-7.3 | python-3.2.2 | mutt-1.5.21 | elinks-0.12 --- -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Book for a C Programmer?
Am 24.05.2012 01:45, schrieb hsa...@gmail.com: I am trying to join an online class that uses python. I need to brush up on the language quickly. Is there a good book or resource that covers it well but does not have to explain what an if..then..else statement is? First thing to check first is whether the online course uses Python 2 or Python 3. For Python 2, try starting at docs.python.org. There you will find library documentation, language specifications and also tutorials. Uli -- http://mail.python.org/mailman/listinfo/python-list
Re: Wish: Allow all log Handlers to accept the level argument
Fayaz Yusuf Khan wrote: ***TRIVIAL ISSUE***, but this has been irking me for a while now. The main logging.Handler class' __init__ accepts a level argument while none of its children do. The poor minions seem to be stuck with the setLevel method which considerably lengthens the code. In short: Let's do this: root.addHandler(FileHandler('debug.log', level=DEBUG) Instead of this: debug_file_handler = FileHandler('debug.log') debug_file_handler.setLevel(DEBUG) root.addHandler(debug_file_handler) Python 2.7 Your suggestion comes too late for Python 2 for which only bugfixes are accepted. For Python 3.3 you could write a patch and make a feature request on http://bugs.python.org/ . -- http://mail.python.org/mailman/listinfo/python-list
Working with dates : complex problem
Hi, I've a list of python objects with dates attributes. This list is ordered by one of these date. Elements mandatory follow each other : Element #1 Element #2 Element #3 |-|--|--| Now, I want to insert an element in this timeline. This imply that I will have to resize some elements : Element #1 Element #2 Element #3 |-|--|--| New element |--| And after resize : Element #1 New element Element #2 Element #3 |-|--|-|--| |--| My question is the following : how can I know (easily) which elements my New element is over, which, in my example would have returned ['Element #1', 'Element #2']. Elements objets are simple Python objects with dates : obj.begin = datetime() obj.end = datetime() I'm looking for the more Pythonic way to handle this problem, thanks ! -- http://mail.python.org/mailman/listinfo/python-list
Namespace hack
From the Zen of Python (import this): Namespaces are one honking great idea -- let's do more of those! Inspired by this, I have a decorator that abuses function closures to create a namespace type with the following properties: - all methods are static methods that do not take a self parameter; - methods can see class variables; - external callers can see selected methods and attributes. An example may make this clearer. In a regular class: class C: x = 42 def spam(self, y): return self.x + y def ham(self, z): return self.spam(z+1) Notice that the class attribute x is visible to the outside caller, but methods spam and ham cannot see it except by prefixing it with a reference to self. Here's an example using my namespace hack example: @namespace def C(): # Abuse nested functions to make this work. x = 42 def spam(y): return x + y def ham(z): return spam(z+1) return (spam, ham) # Need an explicit return to make methods visible. However, class attribute x is not exposed. You may consider this a feature, rather than a bug. To expose a class attribute, define it in the outer function argument list: @namespace def C(x=42): def spam(y): return x + y def ham(z): return spam(z+1) return (spam, ham) And in use: C.x 42 C.spam(100) 142 C.ham(999) 1042 Here's the namespace decorator: import inspect def namespace(func): spec = inspect.getargspec(func) ns = {'__doc__': func.__doc__} for name, value in zip(spec.args, spec.defaults or ()): ns[name] = value function = type(lambda: None) exported = func() or () try: len(exported) except TypeError: exported = (exported,) for obj in exported: if isinstance(obj, function): ns[obj.__name__] = staticmethod(obj) else: raise TypeError('bad export') Namespace = type(func.__name__, (), ns) return Namespace() Have fun! -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Working with dates : complex problem
Thibaut DIRLIK wrote: Hi, I've a list of python objects with dates attributes. This list is ordered by one of these date. Elements mandatory follow each other : Element #1 Element #2 Element #3 |-|--|--| Now, I want to insert an element in this timeline. This imply that I will have to resize some elements : Element #1 Element #2 Element #3 |-|--|--| New element |--| And after resize : Element #1 New element Element #2 Element #3 |-|--|-|--| |--| My question is the following : how can I know (easily) which elements my New element is over, which, in my example would have returned ['Element #1', 'Element #2']. Elements objets are simple Python objects with dates : obj.begin = datetime() obj.end = datetime() I'm looking for the more Pythonic way to handle this problem, thanks ! Untested: def insert(timeline, interval): keys = [item.begin for item in timeline] where = bisect.bisect(keys, interval.begin) if where 0: # adjust previous interval to avoid a gap or an intersection timeline[where-1].end = interval.begin # remove intervals covered by the new interval while where len(timeline) and timeline[where].end interval.end: del timeline[where] if where len(timeline): # adjust subsequent interval to avoid gap or intersection timeline[where].begin = interval.end timeline.insert(where, interval) If you implement comparison for your interval type you won't need the intermediate keys list. The functools.total_ordering decorator may help you with that. -- http://mail.python.org/mailman/listinfo/python-list
Re: Korean fonts on Python 2.6 (MacOsX)
Am 23.05.2012 11:30, schrieb 20_feet_tall: I have a problem with the visualization of korean fonts on Python. When I try to type in the characters only squares come out. I have tried to install the CJK codec, the hangul 1.0 codec but still no result. What exactly do you mean with visualization? Python itself doesn't do any visualization, all it does is to manage data. This data can be bytes exchanged with e.g. a terminal window or a file. If the file uses encoding A for some text, but Python interprets the bytes according to encoding B, no good will come of it. Similarly, if the console window expects Python to output one encoding and Python uses a different encoding, bad things happen. Further, but that now has almost nothing to do with Python directly, if the console window tries to render a character that is not contained in the current font, it will fail. The typical behaviour then is to fall back to some placeholder char, like the square you describe. Summary: It's not clear enough what you did, so it's impossible to tell what went wrong. It could also help if you told us what you wanted to achieve. That said, Python 2.7 has been out for a while, and I'd consider upgrading. Uli -- http://mail.python.org/mailman/listinfo/python-list
Re: Wish: Allow all log Handlers to accept the level argument
Fayaz Yusuf Khan wrote: Jean-Michel Pichavant wrote: Meanwhile you can shorten the code this way: root.addHandler(FileHandler('debug.log')) root.handlers[-1].setLevel(DEBUG) Eh? Readability was the aim. I fail to see how it's not readable, code is short and no magic is involved provided you know about slicing list items. Anyway, to answer your question on why addHandler do not return the handler, I'll quote Dave Angel from a recent thread about why s.append(5) does not return s: It's simpler than that. Methods/functions either modify the object (or one of their arguments), or return the results, but generally not both. So sorted() returns a sorted list without modifying the input. And the sort() method modifies the list, but does not return it. So you're right that methods on non-mutables must return the new value, since they can't modify the object. JM -- http://mail.python.org/mailman/listinfo/python-list
Re: Wish: Allow all log Handlers to accept the level argument
Jean-Michel Pichavant wrote: Fayaz Yusuf Khan wrote: Jean-Michel Pichavant wrote: Meanwhile you can shorten the code this way: root.addHandler(FileHandler('debug.log')) root.handlers[-1].setLevel(DEBUG) Eh? Readability was the aim. I fail to see how it's not readable, code is short and no magic is involved provided you know about slicing list items. Anyway, to answer You have to know or verify that .addHandler() appends to the .handlers list, you have to check if or under which conditions h = SomeHandler() root.addHandler(h) assert h is root.handlers[-1] can fail. In short, if I see such a hack my trust in the author of that code is significantly lowered. -- http://mail.python.org/mailman/listinfo/python-list
Re: Wish: Allow all log Handlers to accept the level argument
Peter Otten wrote: Jean-Michel Pichavant wrote: Fayaz Yusuf Khan wrote: Jean-Michel Pichavant wrote: Meanwhile you can shorten the code this way: root.addHandler(FileHandler('debug.log')) root.handlers[-1].setLevel(DEBUG) Eh? Readability was the aim. I fail to see how it's not readable, code is short and no magic is involved provided you know about slicing list items. Anyway, to answer You have to know or verify that .addHandler() appends to the .handlers list, you have to check if or under which conditions h = SomeHandler() root.addHandler(h) assert h is root.handlers[-1] can fail. In short, if I see such a hack my trust in the author of that code is significantly lowered. I now fail to see how it's a hack. handlers is a public attribute of loggers. FYI def addHandler(self, hdlr): Add the specified handler to this logger. if not (hdlr in self.handlers): self.handlers.append(hdlr) Cheers, JM -- http://mail.python.org/mailman/listinfo/python-list
Re: Wish: Allow all log Handlers to accept the level argument
Jean-Michel Pichavant wrote: Peter Otten wrote: Jean-Michel Pichavant wrote: Fayaz Yusuf Khan wrote: Jean-Michel Pichavant wrote: Meanwhile you can shorten the code this way: root.addHandler(FileHandler('debug.log')) root.handlers[-1].setLevel(DEBUG) Eh? Readability was the aim. I fail to see how it's not readable, code is short and no magic is involved provided you know about slicing list items. Anyway, to answer You have to know or verify that .addHandler() appends to the .handlers list, you have to check if or under which conditions h = SomeHandler() root.addHandler(h) assert h is root.handlers[-1] can fail. In short, if I see such a hack my trust in the author of that code is significantly lowered. I now fail to see how it's a hack. handlers is a public attribute of loggers. Can you come up with a setup that makes the above assertion fail? I can think of three: - adding a handler twice - adding a singleton handler - adding handlers from multiple threads FYI def addHandler(self, hdlr): Add the specified handler to this logger. Subject to change. I think in current Python if not (hdlr in self.handlers): self.handlers.append(hdlr) is protected by a lock. -- http://mail.python.org/mailman/listinfo/python-list
other languages API to python
Hello, A vendor provided a C, C++ and Java API for a application. They dont support python so I would like to create a library for it. My question is, how hard/easy would it be to create something like this? Is there a simple HOWTO or examples I can follow? Can someone shed home light on this? TIA -- --- Get your facts first, then you can distort them as you please.-- -- http://mail.python.org/mailman/listinfo/python-list
Re: problem loading matlab data with ompc and python
On May 23, 5:10 pm, no1 no1.w...@gmail.com wrote: Hi, we're investigating transitioning our company from matlab to python. We found OMPC as a MATLAB m-file-to Python translator, but we're encountering a problem using the translated code to import MATLAB data structures into Python. For example, when we save data within MATLAB this way: x.a = 5; x.b = 6; save -v6 test x this saves data in test.mat, with MATLAB version 6 compatibility (OMPC says it's not compatible with the latest versions of MATLAB). The code to read in data in MATLAB is just load test and when we run it through OMPC we get load(mstring('test.mat')) but when we run it we get the error message File ompclib\ompclib_numpy.py, line 1496, in load KeyError: [('a', '|O4'), ('b', '|O4')] Reading in simpler data (up to arrays) does not have this problem. To get other people in the company to transition, we were hoping that the translation process could be done in one step or on the fly. We could read in MATLAB data using I/O functions imported from scipy, but then the transition isn't seamless any more. Is there a simple fix to using OMPC? Or a similar alternative that would work better? Thanks Have you tried using loadmat from the scipy.io module? http://docs.scipy.org/doc/scipy/reference/io.html -- http://mail.python.org/mailman/listinfo/python-list
Re: other languages API to python
On Thu, May 24, 2012 at 9:58 PM, Rita rmorgan...@gmail.com wrote: Hello, A vendor provided a C, C++ and Java API for a application. They dont support python so I would like to create a library for it. My question is, how hard/easy would it be to create something like this? Is there a simple HOWTO or examples I can follow? Can someone shed home light on this? The best way would be to write something in C that exposes the API to Python. Check out the docs on Extending and Embedding Python: For Python 2.x: http://docs.python.org/extending/ For Python 3.x: http://docs.python.org/py3k/extending/ You'll need to learn Python's own API, of course, but if you're a competent C programmer, you should find it fairly straightforward. There's an alternative, too, though I haven't personally used it. The ctypes module allows you to directly call a variety of C-provided functions. http://docs.python.org/library/ctypes.html http://docs.python.org/py3k/library/ctypes.html The resulting code isn't nearly as Pythonic as it could be if you write a proper wrapper, but you save the work of writing C code. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list
Email Id Verification
Hello everyone.. I am new to asp.net... I want to use Regular Expression validator in Email id verification.. Can anyone tell me how to use this and what is the meaning of this \w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* -- http://mail.python.org/mailman/listinfo/python-list
Re: Email Id Verification
On Thu, May 24, 2012 at 10:32 PM, niks nikunjparmar...@gmail.com wrote: Hello everyone.. I am new to asp.net... I want to use Regular Expression validator in Email id verification.. Can anyone tell me how to use this and what is the meaning of this \w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* This is a mailing list about Python, not ASP, and not regular expressions. Every regex library is different, some more than others, so your best bet is to find documentation on the actual function/library you'll be using. But I would strongly recommend NOT using a regex to validate an email address. It's prone to false positives and false negatives. There are, unfortunately, many systems around which do not accept legal addresses (for instance, this.is.vali...@rosuav.com is, as the name suggests, quite valid - as is fred_foobar@[203.214.67.43]); part of the blame can be laid on PHP's inbuilt validation functions, but I know that several are implemented using a fairly simple and brutally wrong check. Validate the domain part (the bit after the @) with a DNS lookup, nothing more and nothing less. If you absolutely must do a syntactic/charset check, read the appropriate RFCs and figure out what really is and isn't legal. You will be surprised. (For instance, foo@localhost is a perfectly valid address, because localhost is a top-level domain.) Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Book for a C Programmer?
On May 23, 2012, at 7:45 PM, hsa...@gmail.com wrote: I am trying to join an online class that uses python. I need to brush up on the language quickly. Is there a good book or resource that covers it well but does not have to explain what an if..then..else statement is? Thanks. -- http://mail.python.org/mailman/listinfo/python-list My preference is Python Essential Reference by Beazley. You can find it and several reviews here: http://www.amazon.com/Python-Essential-Reference-David-Beazley/dp/0672329786/ref=sr_1_1?s=booksie=UTF8qid=1337859988sr=1-1 -Bill -- http://mail.python.org/mailman/listinfo/python-list
Re: Email Id Verification
On Thu, 24 May 2012 05:32:16 -0700, niks wrote: Hello everyone.. I am new to asp.net... I want to use Regular Expression validator in Email id verification.. Can anyone tell me how to use this and what is the meaning of this \w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* this is not really a python question. I would suggest you locate a good regular expression tutorial then try to break it down otherwise you could try asking in an asp.net forum -- Sometimes when presented with a problem you will think I know I will use regular expressions Now you have two problems. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Book for a C Programmer?
On Wed, 23 May 2012 16:45:05 -0700, hsaziz wrote: I am trying to join an online class that uses python. I need to brush up on the language quickly. Is there a good book or resource that covers it well but does not have to explain what an if..then..else statement is? Thanks. Dive into python seems to be quite popular can be read online fro free -- If life gives you lemons, make lemonade. -- http://mail.python.org/mailman/listinfo/python-list
Re: Namespace hack
From the Zen of Python (import this): Namespaces are one honking great idea -- let's do more of those! Inspired by this, I have a decorator that abuses function closures to create a namespace type with the following properties: - all methods are static methods that do not take a self parameter; - methods can see class variables; - external callers can see selected methods and attributes. An example may make this clearer. In a regular class: class C: x = 42 def spam(self, y): return self.x + y def ham(self, z): return self.spam(z+1) Notice that the class attribute x is visible to the outside caller, but methods spam and ham cannot see it except by prefixing it with a reference to self. Here's an example using my namespace hack example: @namespace def C(): # Abuse nested functions to make this work. x = 42 def spam(y): return x + y def ham(z): return spam(z+1) return (spam, ham) # Need an explicit return to make methods visible. However, class attribute x is not exposed. You may consider this a feature, rather than a bug. To expose a class attribute, define it in the outer function argument list: @namespace def C(x=42): def spam(y): return x + y def ham(z): return spam(z+1) return (spam, ham) And in use: C.x 42 C.spam(100) 142 C.ham(999) 1042 Here's the namespace decorator: import inspect def namespace(func): spec = inspect.getargspec(func) ns = {'__doc__': func.__doc__} for name, value in zip(spec.args, spec.defaults or ()): ns[name] = value function = type(lambda: None) exported = func() or () try: len(exported) except TypeError: exported = (exported,) for obj in exported: if isinstance(obj, function): ns[obj.__name__] = staticmethod(obj) else: raise TypeError('bad export') Namespace = type(func.__name__, (), ns) return Namespace() Have fun! Funny, you got to the last line of import this but apparently skipped the second line: Explicit is better than implicit. And you didn't even post your message on April 1 so no, I can't laugh even though I'd like to. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Book for a C Programmer?
On 2012-05-24, alister alister.w...@ntlworld.com wrote: On Wed, 23 May 2012 16:45:05 -0700, hsaziz wrote: I am trying to join an online class that uses python. I need to brush up on the language quickly. Is there a good book or resource that covers it well but does not have to explain what an if..then..else statement is? Thanks. Dive into python seems to be quite popular can be read online fro free Learning Python by Mark Lutz, from O'Reilly is a good one, I've been reading it and it also enforces a comparison between C programming and Python. However, it's focused on Python 2, but it also mentions Python 3 things in the text... -- Javier Novoa C. --- Posted via news://freenews.netfront.net/ - Complaints to n...@netfront.net --- -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Book for a C Programmer?
On Thu, May 24, 2012 at 8:28 AM, Javier Novoa C. jsti...@invernalia.homelinux.net wrote: On 2012-05-24, alister alister.w...@ntlworld.com wrote: On Wed, 23 May 2012 16:45:05 -0700, hsaziz wrote: I am trying to join an online class that uses python. I need to brush up on the language quickly. Is there a good book or resource that covers it well but does not have to explain what an if..then..else statement is? Thanks. Dive into python seems to be quite popular can be read online fro free Learning Python by Mark Lutz, from O'Reilly is a good one, I've been reading it and it also enforces a comparison between C programming and Python. However, it's focused on Python 2, but it also mentions Python 3 things in the text... There is a new edition out, copyright 2010 if I recall correctly, that updates its coverage to Python 3.x, which is the book's primary focus, though it points out where 3.x syntax does not work in version 2.x. Cheers! boB -- http://mail.python.org/mailman/listinfo/python-list
Dynamic comparison operators
I would like to pass something like this into a function test(val1,val2,'=') and it should come back with True or False. Is there a way to dynamically compare 2 values like this or will I have to code each operator individually? -- http://mail.python.org/mailman/listinfo/python-list
Re: Dynamic comparison operators
Hello, You can pass an operator as an argument to your function. See : http://docs.python.org/library/operator.html Regards, -- Forwarded message -- From: mlangenho...@gmail.com Date: 2012/5/24 Subject: Dynamic comparison operators To: python-list@python.org I would like to pass something like this into a function test(val1,val2,'=') and it should come back with True or False. Is there a way to dynamically compare 2 values like this or will I have to code each operator individually? -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Dynamic comparison operators
mlangenho...@gmail.com writes: I would like to pass something like this into a function test(val1,val2,'=') and it should come back with True or False. def test(x,y,c): return c(x,y) Call with: test(v1,v2, lambda x,y:x=y ). A bit noisy imho. If you have a finite number of comparison operators, put them in a dict: compares = dict([ (,lambda x,y:xy), (|,lambda x,y: x.startswith(y)), ... ]) and use them like: test(v1,v2,compares[=]), or simply: compares[=](v1,v2) -- Alain. -- http://mail.python.org/mailman/listinfo/python-list
Re: Dynamic comparison operators
On 05/24/12 09:32, Phil Le Bienheureux wrote: I would like to pass something like this into a function test(val1,val2,'=') You can pass an operator as an argument to your function. See : http://docs.python.org/library/operator.html And if you want to use strings, you can map them to the functions: import operator as o OPERATOR_MAP = { '=': o.eq, '==': o.eq, '!=': o.ne, '=': o.ge, # ... } def test(v1, v2, op): return OPERATOR_MAP[op](v1, v2) -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: Dynamic comparison operators
Alain Ketterlin writes: mlangenho...@gmail.com writes: I would like to pass something like this into a function test(val1,val2,'=') and it should come back with True or False. def test(x,y,c): return c(x,y) Call with: test(v1,v2, lambda x,y:x=y ). A bit noisy imho. Re noisy: import operator as o test(v1, v2, o.le) -- http://mail.python.org/mailman/listinfo/python-list
Re: Email Id Verification
On Thu, May 24, 2012 at 11:45 PM, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: And maybe follow-up with a review of this monster: http://www.ex-parrot.com/pdw/Mail-RFC822-Address.html That is awesome. Epic. Eyeball-bleeding. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Dynamic comparison operators
On 24/05/2012 10:14 AM, mlangenho...@gmail.com wrote: I would like to pass something like this into a function test(val1,val2,'=') and it should come back with True or False. Is there a way to dynamically compare 2 values like this or will I have to code each operator individually? Would something like the following meet your need? Yes, it would be nice if there were a b.__name__ constant. Colin W. ''' I would like to pass something like this into a function test(val1,val2,'=') and it should come back with True or False. Is there a way to dynamically compare 2 values like this or will I have to code each operator individually? ''' def test(text): return eval(text) a= 25 b= 50 print test('a == b') print test('a != b') print test('a = b') -- http://mail.python.org/mailman/listinfo/python-list
Czy dysponujesz dwoma wolnymi godzinami w tygodniu? Oto jak zarobc 185 EUR w tym czasie.
Dzien dobry! Dziekujemy bardzo za zainteresowanie pozycja regionalnego przedstawiciela dostepna obecnie w Polsce i krajach Europy Srodkowej. Chcialem by przedstawic, bardzo krotko - nasza wybitna firme. W.U.G. Inc zostala zalozona w 1992 roku i obecnie stala sie jedna z najbardziej uznawanych firm biznesowych, ktore zapewniaja kompleksowa obsluge swoim klientom. Siec przedstawicielstw West Union Group jest reprezentowana w ponad 32 krajach i swiadczy uslugi do 46 krajow. Specjalizujemy sie w doradztwie w zakresie planowania podatkowego, rejestracji firm, nadajac rowniez dodatkowe finansowe uslugi wsparcia dla firm zagranicznych. WUG jest dobrze znana w USA, Kanadzie i niektorych panstwach Unii Europejskiej. Nasza firma nie moze pozwolic na stworzenie regionalnego biura w kazdym kraju z powodu wysokich kosztow operacyjnych, z tego powodu pragniemy wynajac przedstawiciela regionalnego wypelniac powierzone mu zadania. Wiekszosc naszych operacji z klientami sa przeprowadzane w Internecie. Kiedy klient jest gotowy oplacic za korzystanie z naszych uslug, regionalny przedstawiciel bedzie musial pomoc mu / jej przetworzyc platnosci i upewnic sie, ze fundusze zostaly otrzymane w naleznym czasie. Regionalny Przedstawiciel bedzie odpowiedzialny za pomoc naszym klientom z niektorymi ugodami i przetwarzanie przelewow. Gwarantujemy wynagrodzenie w wysokosci 2500 EUR miesiecznie wyplacane co dwa tygodnie. Nalezy pamietac, ze duza czesc zadan zostanie przedstawiona w ciagu dziennego czasu. Zwroccie uwage, ze proponujemu pozycje o niepelnym wymiarze godzin, wiec trzeba bedzie wydac tylko 2-3 godzin dziennie na tej prace. WUG Inc zabezpieczy nowego pretendenta w calosci oplacalnym dwutygodniowym treningowym okresem. Otrzymaja Panstwo wszystkie niezbedne informacje na temat szkolen od naszego specjalisty po zatrudnieniu. Jesli znajdujecie to interesujacym, zyczliwie prosimy was podac nam wasze dane kontaktowe (naprzyklad numer telefonu, imie i nazwisko), abysmy mogli skontaktowac sie z wami dla dalszej komunikacji. Prosimy nie wahajcie sie z nami skontaktowac w kazdej chwili, jesli macie jakiekolwiek dodatkowe pytania dotyczace tej pozycji. Nasz e-mail: maksymil...@toppolandjobs.com,Najcieplej pozdrawiamy, Maksymilian Skrzypinski Menadzer personelu WUG Inc -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Book for a C Programmer?
On Thu, May 24, 2012 at 08:34:24AM -0500, boB Stepp wrote: On Thu, May 24, 2012 at 8:28 AM, Javier Novoa C. jsti...@invernalia.homelinux.net wrote: On 2012-05-24, alister alister.w...@ntlworld.com wrote: On Wed, 23 May 2012 16:45:05 -0700, hsaziz wrote: I am trying to join an online class that uses python. I need to brush up on the language quickly. Is there a good book or resource that covers it well but does not have to explain what an if..then..else statement is? Thanks. Dive into python seems to be quite popular can be read online fro free Learning Python by Mark Lutz, from O'Reilly is a good one, I've been reading it and it also enforces a comparison between C programming and Python. However, it's focused on Python 2, but it also mentions Python 3 things in the text... There is a new edition out, copyright 2010 if I recall correctly, that updates its coverage to Python 3.x, which is the book's primary focus, though it points out where 3.x syntax does not work in version 2.x. Cheers! boB Oh thanks! that I didn't knew... -- Javier Novoa C. -- http://mail.python.org/mailman/listinfo/python-list
Embedding Python27 in C++ on Windows: CRT compatibility issues with VS2010?
Hello, I'm a relative python newbie but I've been tasked to figure out how to embed calls to a python library in an Excel XLL add-in. The Python/C API for doing this seems pretty straightforward, but I seem to have read somewhere online that it's important that the C++ program or DLL linking to and embedding Python must be using the same CRT as what the Python implementation dll is using. Is this true, or is the Python API written in such a way that there is no dependency on a common CRT? If there is a dependency, does that mean that I cannot use VS2010 to develop this XLL, but should use VS2008 instead, or are there other workarounds? Thanks for the help, Stephen -- http://mail.python.org/mailman/listinfo/python-list
Re: Email Id Verification
On 5/24/2012 5:32 AM, niks wrote: Hello everyone.. I am new to asp.net... I want to use Regular Expression validator in Email id verification.. Can anyone tell me how to use this and what is the meaning of this \w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* Not a Python question. It matches anything that looks like a mail user name followed by an @ followed by anything that looks more or less like a domain name. The domain name must contain at least one ., and cannot end with a ., which is not strictly correct but usually works. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Book for a C Programmer?
On 05/23/2012 07:45 PM, hsa...@gmail.com wrote: I am trying to join an online class that uses python. I need to brush up on the language quickly. Is there a good book or resource that covers it well but does not have to explain what an if..then..else statement is? Thanks. My opinion: Martelli's Python in a Nutshell is the KR of Python. Alas, it does discuss if statements, but it doesn't slap you silly with them. -- http://mail.python.org/mailman/listinfo/python-list
Help doing it the python way
Hello, I am an experienced programmer but a beginner to python. As such, I can figure out a way to code most algorithms using more C style syntax. I am doing something now that I am sure is a more python way but i can't quite get it right. I was hoping someone might help. So I have a list of grid coordinates (x, y). From that list, I want to create a new list that for each coordinate, I add the coordinate just above and just below (x,y+1) and (x,y-1) right now I am using a for loop to go through all the coordinates and then separate append statements to add the top and bottom. is there a way to do something like: [(x,y-1), (x,y+1) for zzz in coord_list] or something along those lines? thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Help doing it the python way
Scott Siegler scott.sieg...@gmail.com wrote: Hello, I am an experienced programmer but a beginner to python. As such, I can figure out a way to code most algorithms using more C style syntax. I am doing something now that I am sure is a more python way but i can't quite get it right. I was hoping someone might help. So I have a list of grid coordinates (x, y). From that list, I want to create a new list that for each coordinate, I add the coordinate just above and just below (x,y+1) and (x,y-1) right now I am using a for loop to go through all the coordinates and then separate append statements to add the top and bottom. is there a way to do something like: [(x,y-1), (x,y+1) for zzz in coord_list] or something along those lines? thanks! def vertical_neighbours(coords): for x, y in coords: yield x, y-1 yield x, y+1 new_coords = list(vertical_neighbours(coords)) -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Help doing it the python way
Scott Siegler scott.sieg...@gmail.com writes: is there a way to do something like: [(x,y-1), (x,y+1) for zzz in coord_list] or something along those lines? You should read the docs of the itertools module on general principles, since they are very enlightening in many ways. Your particular problem can be handled with itertools.chain: from itertools import chain new_list = chain( ((x,y-1), (x,y+1)) for x,y in coord_list ) You can alternatively write an iterative loop: def gen_expand(coord_list): for x,y in coord_list: yield (x-1,y) yield (x+1, y) new_list = list(gen_expand(coord_list)) -- http://mail.python.org/mailman/listinfo/python-list
Re: Help doing it the python way
On 05/24/2012 04:22 PM, Scott Siegler wrote: Hello, I am an experienced programmer but a beginner to python. As such, I can figure out a way to code most algorithms using more C style syntax. I am doing something now that I am sure is a more python way but i can't quite get it right. I was hoping someone might help. So I have a list of grid coordinates (x, y). From that list, I want to create a new list that for each coordinate, I add the coordinate just above and just below (x,y+1) and (x,y-1) right now I am using a for loop to go through all the coordinates and then separate append statements to add the top and bottom. is there a way to do something like: [(x,y-1), (x,y+1) for zzz in coord_list] or something along those lines? thanks! So, where's the code that works? That you want optimized, or pythonified ? Your algorithm description is sufficiently confusing that I'm going to have make some wild guesses about what you're after. Apparently you have a list of tuples, and you want to create a second list that's related to the first in the sense that each item (i) of list2 is the sum of the items (i-1) and (i+1) of list1. Presumably you mean sum as in vector sum, where we add the x and y values, respectively. Easiest way to handle edge conditions is to stick an extra (0,0) at both the beginning and end of the list. list1 = [ (3,7), (2,2), (944, -2), (12, 12) ] def sumtuple(mytuple1, mytuple2): return ( mytuple1[0] + mytuple2[0] , mytuple1[1] + mytuple2[1]) def makesum(list1): list2 = [] list1a = [(0, 0)] + list1 + [(0, 0)] for item1, item2 in zip(list1a, list1a[2:]): list2.append( sumtuple(item1, item2) ) return list2 print makesum(list1) output: [(2, 2), (947, 5), (14, 14), (944, -2)] Now, that undoubtedly isn't what you wanted, but perhaps you could clarify the algorithm, so we could refine it. No point in making it more compact till it solves the problem you're actually interested in. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Help doing it the python way
Paul Rubin no.email@nospam.invalid writes: new_list = chain( ((x,y-1), (x,y+1)) for x,y in coord_list ) Sorry: new_list = list(chain( ((x,y-1), (x,y+1)) for x,y in coord_list)) -- http://mail.python.org/mailman/listinfo/python-list
Re: problem loading matlab data with ompc and python
On Thursday, May 24, 2012 5:06:41 AM UTC-7, Tim Williams wrote: On May 23, 5:10 pm, no1 no1.w...@gmail.com wrote: Hi, we're investigating transitioning our company from matlab to python. We found OMPC as a MATLAB m-file-to Python translator, but we're encountering a problem using the translated code to import MATLAB data structures into Python. For example, when we save data within MATLAB this way: x.a = 5; x.b = 6; save -v6 test x this saves data in test.mat, with MATLAB version 6 compatibility (OMPC says it's not compatible with the latest versions of MATLAB). The code to read in data in MATLAB is just load test and when we run it through OMPC we get load(mstring('test.mat')) but when we run it we get the error message File ompclib\ompclib_numpy.py, line 1496, in load KeyError: [('a', '|O4'), ('b', '|O4')] Reading in simpler data (up to arrays) does not have this problem. To get other people in the company to transition, we were hoping that the translation process could be done in one step or on the fly. We could read in MATLAB data using I/O functions imported from scipy, but then the transition isn't seamless any more. Is there a simple fix to using OMPC? Or a similar alternative that would work better? Thanks Have you tried using loadmat from the scipy.io module? http://docs.scipy.org/doc/scipy/reference/io.html Yes (I mentioned the scipi I/O module near the end of my original post) but we were hoping not to have to require the users to learn any Python to start. The simpler the process, the less resistance to using the new Python methodology; we were hoping the use of a single black box like translator (OMPC) would be enough. We'd really like to avoid any additional steps for the user, like rewriting code, otherwise the users are going to resist the transition. -- http://mail.python.org/mailman/listinfo/python-list
Re: Email Id Verification
John Nagle na...@animats.com writes: It matches anything that looks like a mail user name followed by an @ followed by anything that looks more or less like a domain name. The domain name must contain at least one ., and cannot end with a ., which is not strictly correct but usually works. It will reject many valid email addresses. For better guidance on verifying email address values, see the official recommendations in RFC 3696 URL:https://tools.ietf.org/html/rfc3696. In short: don't bother validating email addresses, the email system is best placed to do that. Just try using them and catch the failures when they happen. -- \ “He was the mildest-mannered man / That ever scuttled ship or | `\ cut a throat.” —“Lord” George Gordon Noel Byron, _Don Juan_ | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Wish: Allow all log Handlers to accept the level argument
On 24May2012 12:48, Jean-Michel Pichavant jeanmic...@sequans.com wrote: | Peter Otten wrote: | Jean-Michel Pichavant wrote: | Fayaz Yusuf Khan wrote: | Jean-Michel Pichavant wrote: | Meanwhile you can shorten the code this way: | root.addHandler(FileHandler('debug.log')) | root.handlers[-1].setLevel(DEBUG) | | Eh? Readability was the aim. | | I fail to see how it's not readable, code is short and no magic is | involved provided you know about slicing list items. Anyway, to answer | | You have to know or verify that .addHandler() appends to the .handlers list, | you have to check if or under which conditions | | h = SomeHandler() | root.addHandler(h) | assert h is root.handlers[-1] | | can fail. In short, if I see such a hack my trust in the author of that code | is significantly lowered. | | I now fail to see how it's a hack. handlers is a public attribute of | loggers. | | FYI | | def addHandler(self, hdlr): | | Add the specified handler to this logger. | | if not (hdlr in self.handlers): | self.handlers.append(hdlr) Nothing there says handlers is a list. (Nothing in the docs says that the .handlers even exists, AFAICS.) Might be a set or something more esoteric. Particularly, if I wanted to add and remove handlers a lot I might well expect (or at least imagine) it to be a set. So I too find: root.handlers[-1] a risky thing to say, and harder to read because it assumes something I would not want to rely on. Versus the original proposal that avoids all need to know how logging tracks its handler internally. Cheers, -- Cameron Simpson c...@zip.com.au DoD#743 http://www.cskk.ezoshosting.com/cs/ The reason that God was able to create the world in seven days is that he didn't have to worry about the installed base. - Enzo Torresi -- http://mail.python.org/mailman/listinfo/python-list
Re: Email Id Verification
On 25May2012 01:20, Chris Angelico ros...@gmail.com wrote: | On Thu, May 24, 2012 at 11:45 PM, Dennis Lee Bieber | wlfr...@ix.netcom.com wrote: | And maybe follow-up with a review of this monster: | http://www.ex-parrot.com/pdw/Mail-RFC822-Address.html | | That is awesome. Epic. Eyeball-bleeding. +1 !! I hope someone's validated that regexp before using it to validate email addresses:-) I'm amazed. (And amazed that the sheer code smell doesn't drive the author away from suggesting it.) The mere presence of nesting comments in RFC2822 addresses prevents using a single regexp to parse them. -- Cameron Simpson c...@zip.com.au DoD#743 http://www.cskk.ezoshosting.com/cs/ It's state-of-the-art But it doesn't work! That is the state-of-the-art. -- http://mail.python.org/mailman/listinfo/python-list
Re: Email Id Verification
On 24May2012 05:32, niks nikunjparmar...@gmail.com wrote: | Hello everyone.. | I am new to asp.net... Time to run away fast before you're commited then:-) You're aware this is a _python_ list/group, yes? | I want to use Regular Expression validator in Email id verification.. You can't. Valid addresses including nesting comments. Regexps don't do recursion. | Can anyone tell me how to use this and what is the meaning of | this | \w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* If you don't understand it, DON'T use it. And in any case, it is simplistic (== wrong). As pointed out by others in this thread. -- Cameron Simpson c...@zip.com.au DoD#743 http://www.cskk.ezoshosting.com/cs/ Men are four: He who knows and knows that he knows; he is wise, follow him. He who knows and knows not that he knows; he is asleep, wake him. He who knows not and knows that he knows not; he is ignorant, teach him. He who knows not and knows not that he knows not; he is a fool, spurn him! -- http://mail.python.org/mailman/listinfo/python-list
Re: Help doing it the python way
On 5/24/2012 2:30 PM Paul Rubin said... Paul Rubinno.email@nospam.invalid writes: new_list = chain( ((x,y-1), (x,y+1)) for x,y in coord_list ) Sorry: new_list = list(chain( ((x,y-1), (x,y+1)) for x,y in coord_list)) from itertools import chain coord_list = zip(range(20,30),range(30,40)) a = [((x,y-1),(x,y+1)) for x,y in coord_list] b = list(chain(((x,y-1),(x,y+1)) for x,y in coord_list)) a == b True So, why use chain? Is it a premature optimization? Similar to the practice of using .join(targets) vs targeta+targetb+...+targetn? Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: Email Id Verification
On Fri, May 25, 2012 at 9:03 AM, Cameron Simpson c...@zip.com.au wrote: On 24May2012 05:32, niks nikunjparmar...@gmail.com wrote: | Hello everyone.. | I am new to asp.net... Time to run away fast before you're commited then:-) You're aware this is a _python_ list/group, yes? Committed to an asylum or to source control? Python is an asylum. Ruled by a Benevolent Inmate For Life. And yes, it's a life sentence. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Email Id Verification
On Thu, 24 May 2012 05:32:16 -0700, niks wrote: Hello everyone.. I am new to asp.net... I want to use Regular Expression validator in Email id verification.. Why do you want to write buggy code that makes your users hate your program? Don't do it! Write good code, useful code! Validating email addresses is the wrong thing to do. The only way to validate an email address is to ACTUALLY SEND AN EMAIL TO IT. That is all. Just because an address is syntactically valid doesn't mean it is deliverable. You can't validate postal addresses. How would you even try? Even if you could, you wouldn't use a regex for it. That's the post office's job to decide whether mail can be delivered, not yours. Who are you to say that some address in Russia or Bolivia or Kuwait is invalid? Email addresses are no different. It is the job of the mail server to decide whether email can be delivered, not yours. http://northernplanets.blogspot.com.au/2007/03/how-not-to-validate-email-addresses.html http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx http://haacked.com/archive/2007/08/26/dont-be-a-validation-nazi.aspx -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Email Id Verification
On 25/05/2012 00:03, Cameron Simpson wrote: On 24May2012 05:32, niksnikunjparmar...@gmail.com wrote: | Hello everyone.. | I am new to asp.net... Time to run away fast before you're commited then:-) You're aware this is a _python_ list/group, yes? | I want to use Regular Expression validator in Email id verification.. You can't. Valid addresses including nesting comments. Regexps don't do recursion. Some regex implementations _can_ do recursion. | Can anyone tell me how to use this and what is the meaning of | this | \w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* If you don't understand it, DON'T use it. And in any case, it is simplistic (== wrong). As pointed out by others in this thread. True, it's the wrong tool for the job. -- http://mail.python.org/mailman/listinfo/python-list
Re: Dynamic comparison operators
On Thu, 24 May 2012 11:22:37 -0400, Colin J. Williams wrote: On 24/05/2012 10:14 AM, mlangenho...@gmail.com wrote: I would like to pass something like this into a function test(val1,val2,'=') and it should come back with True or False. Is there a way to dynamically compare 2 values like this or will I have to code each operator individually? Would something like the following meet your need? Yes, it would be nice if there were a b.__name__ constant. What is a b.__name__ constant, and how will it be useful? As for your solution using eval, please, please, PLEASE do not encourage newbies to write slow, insecure, dangerous code. There are enough security holes in software without you encouraging people to create more. * eval is slow. * eval is dangerous. * eval is using a 200lb sledgehammer to crack a peanut. Any time you find yourself thinking that you want to use eval to solve a problem, take a long, cold shower until the urge goes away. If you have to ask why eval is dangerous, then you don't know enough about programming to use it safely. Scrub it out of your life until you have learned about code injection attacks, data sanitation, trusted and untrusted input. Then you can come back to eval and use it safely and appropriately. Today, your test function using eval is used only by yourself, at the interactive interpreter. Tomorrow, it ends up in a web application, and random hackers in China and script-kiddies in Bulgaria now have total control of your server. Any time you hear about some piece of malware or some virus infecting people's systems when they look at a PDF file, chances are high that it is a code injection attack. To learn more, you can start here: http://cwe.mitre.org/top25/index.html Two of the top three most common vulnerabilities are code injection attacks, similar to the improper use of eval. Here is the eval injection vulnerability: http://cwe.mitre.org/data/definitions/95.html Also google on code injection for many more examples. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Scoping Issues
def adder(): s = 0 def a(x): s += x return sum return a pos, neg = adder(), adder() for i in range(10): print pos(i), neg(-2*i) This should work, right? Why does it not? Checkout slide no. 37 of a Tour of Go to know inspiration. Just wanted to see if python was the same as Go in this regard. Sorry, if I'm being rude, or anything. -- http://mail.python.org/mailman/listinfo/python-list
Re: Email Id Verification
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes: Why do you want to write buggy code that makes your users hate your program? ... The only way to validate an email address is to ACTUALLY SEND AN EMAIL TO IT. Of course spamming people will make them hate you even more. Insisting that people give you a valid email address (unless you have a demonstrably legitimate use for it) is a variant of that. -- http://mail.python.org/mailman/listinfo/python-list
Re: Dynamic comparison operators
mlangenho...@gmail.com writes: I would like to pass something like this into a function test(val1,val2,'=') and it should come back with True or False. import operator test(val1, val2, operator.ge) -- http://mail.python.org/mailman/listinfo/python-list
Re: Scoping Issues
On 25/05/2012 02:23, SherjilOzair wrote: def adder(): s = 0 def a(x): s += x return sum return a pos, neg = adder(), adder() for i in range(10): print pos(i), neg(-2*i) This should work, right? Why does it not? Checkout slide no. 37 of a Tour of Go to know inspiration. Just wanted to see if python was the same as Go in this regard. Sorry, if I'm being rude, or anything. If you bind to a name (assign to a variable) in a function, that name is by default local to the function unless it's declared as global (which means in this module's namespace) or nonlocal (which means in the enclosing function's namespace) (Python 3 only). -- http://mail.python.org/mailman/listinfo/python-list
Re: Email Id Verification
On Thu, 24 May 2012 18:35:21 -0700, Paul Rubin wrote: Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes: Why do you want to write buggy code that makes your users hate your program? ... The only way to validate an email address is to ACTUALLY SEND AN EMAIL TO IT. Of course spamming people will make them hate you even more. Insisting that people give you a valid email address (unless you have a demonstrably legitimate use for it) is a variant of that. Ha, of course. I assumed that the OP actually has a valid reason for requesting an email address from the user. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Scoping Issues
On Thu, 24 May 2012 18:23:18 -0700, SherjilOzair wrote: def adder(): s = 0 def a(x): s += x return sum return a I think you mean return s, not sum. This should work, right? Why does it not? No, it shouldn't. When you have an assignment, such as s += x, Python treats s as a local variable. Since s is local to the inner function a(), it has no initial value, and the += fails. In Python 3, you can declare s to be a non-local variable with the nonlocal keyword: def adder(): s = 0 def a(x): nonlocal s s += x return s return a which now works the way you should expect: add = adder() add(1) 1 add(2) 3 add(5) 8 But in Python 2, which you are using, there is no nonlocal keyword and you can only write to globals (declaring them with the global keyword) or locals (with no declaration), not nonlocals. There are a number of work-arounds to this. One is to use a callable class: class Adder: def __init__(self): self.s = 0 def __call__(self, x): self.s += x return self.s Another is to use an extra level of indirection, and a mutable argument. Instead of rebinding the non-local, you simply modify it in place: def adder(): s = [0] def a(x): s[0] += x return s[0] return a -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Scoping Issues
On Thu, May 24, 2012 at 6:23 PM, SherjilOzair sherjiloz...@gmail.com wrote: def adder(): s = 0 def a(x): Add a nonlocal s declaration right here. See http://www.python.org/dev/peps/pep-3104/ s += x return sum return a pos, neg = adder(), adder() for i in range(10): print pos(i), neg(-2*i) This should work, right? Why does it not? Python doesn't have a C-like variable declaration scheme. So without a `global` or `nonlocal` declaration, you can only assign to names which reside in the innermost scope. Checkout slide no. 37 of a Tour of Go to know inspiration. You mean slide #38 (And functions are full closures.). Just wanted to see if python was the same as Go in this regard. Sorry, if I'm being rude, or anything. I would suggest reading through the Python Language Reference (http://docs.python.org/release/3.1.5/reference/index.html ) prior to asking further questions, as it may well answer them for you. Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: Embedding Python27 in C++ on Windows: CRT compatibility issues with VS2010?
On 25/05/2012 2:10 AM, Stephen Lin wrote: Hello, I'm a relative python newbie but I've been tasked to figure out how to embed calls to a python library in an Excel XLL add-in. The Python/C API for doing this seems pretty straightforward, but I seem to have read somewhere online that it's important that the C++ program or DLL linking to and embedding Python must be using the same CRT as what the Python implementation dll is using. Is this true, or is the Python API written in such a way that there is no dependency on a common CRT? It depends on the APIs you use. eg, some APIs take a FILE * and some may take ownership of memory - such APIs needs to use the same CRT. APIs that don't attempt to share CRT objects should be fine. Mark If there is a dependency, does that mean that I cannot use VS2010 to develop this XLL, but should use VS2008 instead, or are there other workarounds? Thanks for the help, Stephen -- http://mail.python.org/mailman/listinfo/python-list
Re: Scoping Issues
On 05/24/2012 09:23 PM, SherjilOzair wrote: def adder(): s = 0 def a(x): s += x return sum return a pos, neg = adder(), adder() for i in range(10): print pos(i), neg(-2*i) This should work, right? Why does it not? Guess that depends on what you mean by work. First, it gets a syntax error on the print function call, because you omitted the parens. When I fixed that, I got UnboundLocalError: local variable 's' referenced before assignment so I fixed that, and got inconsistent use of tabs and spaces in indentation because you mistakenly used tabs for indentation. Then I got the output built-in function sum built-in function sum because sum is a built-in function. Presumably you meant to return s, not sum. Here's what I end up with, and it seems to work fine in Python 3.2 on Linux: def adder(): s = 0 def a(x): nonlocal s s += x return s return a pos, neg = adder(), adder() for i in range(10): print (pos(i), neg(-2*i)) . Output is: 0 0 1 -2 3 -6 6 -12 10 -20 15 -30 21 -42 28 -56 36 -72 45 -90 -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Email Id Verification
On Fri, May 25, 2012 at 11:35 AM, Paul Rubin no.email@nospam.invalid wrote: Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes: Why do you want to write buggy code that makes your users hate your program? ... The only way to validate an email address is to ACTUALLY SEND AN EMAIL TO IT. Of course spamming people will make them hate you even more. Insisting that people give you a valid email address (unless you have a demonstrably legitimate use for it) is a variant of that. But why do you want to validate the email address? That's the question. Usually it's because you're going to be sending emails to that address, in which case you not only want to ensure that it's a real address, you want to ensure that the person who keyed it in is legitimately allowed to do so - the usual implementation of that being please check your emails for the confirmation code. There are, however, ways of not-quite-sending an email. For instance, you can connect to the domain's MX, give your HELO, MAIL FROM, and RCPT TO commands, and then quit before sending any DATA. That won't give a 100% guarantee, but it'll certainly tell you about a lot of failures (most of them in that first megastep of looking up the domain in DNS to find its MX record, and then attempting a connection). Now, if your goal is to recognize email addresses in plain text (eg to make them clickable), then you probably don't want true validation - you want more of a DWIM setup where common tails aren't included [for instance, an email address followed by a close bracket, like f...@bar.com]. That's completely different. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Scoping Issues
On 5/24/2012 8:59 PM, Dave Angel wrote: so I fixed that, and got inconsistent use of tabs and spaces in indentation because you mistakenly used tabs for indentation. Not to start another tabs-vs.-spaces discussion, but tabs are perfectly legal indentation in Python. That exception is raised when the interpreter can't determine how much a line is indented because tabs and spaces are both used. -- CPython 3.3.0a3 | Windows NT 6.1.7601.17790 -- http://mail.python.org/mailman/listinfo/python-list
Re: Namespace hack
Pardon me for breaking threading, but Daniel's response is not available on my ISP's news server, and I only discovered it by accident. On Thu May 24 15:04:34 CEST 2012, Daniel Fetchinson fetchinson at googlemail.com wrote: On Thu, 24 May 2012 08:50:59 +, Steven D'Aprano wrote: From the Zen of Python (import this): Namespaces are one honking great idea -- let's do more of those! [...] Funny, you got to the last line of import this but apparently skipped the second line: Explicit is better than implicit. And you didn't even post your message on April 1 so no, I can't laugh even though I'd like to. Do you object to the ability to write standard Python modules? # module.py def spam(obj, n): return len(obj) + n def ham(obj): return spam(obj, 23) By your apparent misunderstanding of the Zen, you think that this should be written with oodles of more explicitness, 'cos explicit is always better, right? keyword.def globals.spam(locals.obj, locals.n): keyword.return builtin.len(locals.obj) + locals.n keyword.def globals.ham(locals.obj): keyword.return globals.spam(locals.obj, 23) Python, like most (all?) non-trivial languages, has scoping rules so that you can refer to names without explicitly specifying which namespace they are in. So long as this is unambiguous, Explicit vs Implicit is irrelevant if not outright wrong. My namespace decorator simply applies a slightly different set of scoping rules to the ones you are already used to in modules. It's no worse than nested functions (hardly a surprise, because it is built on nested functions!) or module-level scoping rules. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Is there a custom fields plugin or component of django
I want to find a plugin of django what it can custom fields in the form. The functions include custom fields in web page and create the fields in database. plugin's flow like these: 1.we can define fields in web page -- 2.create the table in database(table includes all custom fields) -- 3.generate CURD operations in web server -- 4.we can CURD records in web pages. I want to know whether there is a plugin or component of django, If there is please tell me. Maybe there is the other plugin like this as well. -- http://mail.python.org/mailman/listinfo/python-list
Re: Help doing it the python way
On 5/24/2012 4:53 PM, Duncan Booth wrote: Scott Sieglerscott.sieg...@gmail.com wrote: Hello, I am an experienced programmer but a beginner to python. As such, I can figure out a way to code most algorithms using more C style syntax. Hi, welcome to Python. I came here from C also. I am doing something now that I am sure is a more python way but i can't quite get it right. I was hoping someone might help. So I have a list of grid coordinates (x, y). From that list, I want to create a new list that for each coordinate, I add the coordinate just above and just below (x,y+1) and (x,y-1) The Python way, especially the Python 3 way, is to not make the new sequence into a concrete list unless you actually need a list to append or sort or otherwise mutate. In many use cases, that is not necessary. right now I am using a for loop to go through all the coordinates and then separate append statements to add the top and bottom. is there a way to do something like: [(x,y-1), (x,y+1) for zzz in coord_list] or something along those lines? def vertical_neighbours(coords): for x, y in coords: yield x, y-1 yield x, y+1 new_coords = list(vertical_neighbours(coords)) -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Scoping Issues
On 05/24/2012 10:27 PM, Andrew Berg wrote: On 5/24/2012 8:59 PM, Dave Angel wrote: so I fixed that, and got inconsistent use of tabs and spaces in indentation because you mistakenly used tabs for indentation. Not to start another tabs-vs.-spaces discussion, but tabs are perfectly legal indentation in Python. That exception is raised when the interpreter can't determine how much a line is indented because tabs and spaces are both used. I configure my editor(s) to always use spaces for indentation. So a file that currently uses tabs is unusable to me. You of course are right that tabs are syntactically correct, but until I find another editor that makes tabs visible (like the one I used 20 years ago) they're unacceptable to me. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Email Id Verification
Paul Rubin no.email@nospam.invalid writes: Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes: Why do you want to write buggy code that makes your users hate your program? ... The only way to validate an email address is to ACTUALLY SEND AN EMAIL TO IT. Of course spamming people will make them hate you even more. Use the email address without spamming, then. The point is that, having collected the email address, it's useless unless one actually uses it *as an email address*, by sending a message to it. Before then, “validating” it tells you nothing. Insisting that people give you a valid email address (unless you have a demonstrably legitimate use for it) is a variant of that. And matching it against a regex is going to either get it wrong (rejecting many valid email addresses), or be useless (accepting just about anything as “valid”). The test which matters is to use the value as an email address, by sending a message when the time comes to do that. -- \ “It's my belief we developed language because of our deep inner | `\ need to complain.” —Jane Wagner, via Lily Tomlin | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Namespace hack
[Default] On 25 May 2012 02:47:11 GMT, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Do you object to the ability to write standard Python modules? # module.py def spam(obj, n): return len(obj) + n def ham(obj): return spam(obj, 23) By your apparent misunderstanding of the Zen, you think that this should be written with oodles of more explicitness, 'cos explicit is always better, right? keyword.def globals.spam(locals.obj, locals.n): keyword.return builtin.len(locals.obj) + locals.n keyword.def globals.ham(locals.obj): keyword.return globals.spam(locals.obj, 23) Python, like most (all?) non-trivial languages, has scoping rules so that you can refer to names without explicitly specifying which namespace they are in. So long as this is unambiguous, Explicit vs Implicit is irrelevant if not outright wrong. My namespace decorator simply applies a slightly different set of scoping rules to the ones you are already used to in modules. It's no worse than nested functions (hardly a surprise, because it is built on nested functions!) or module-level scoping rules. -- Steven But then we've got Simple is better than complex, and Complex is better than complicated. Of course if we decided to start iterating through the zen of Python's verses and continually modifying the example code to fit, it would get rather silly rather fast. ~Temia -- When on earth, do as the earthlings do. -- http://mail.python.org/mailman/listinfo/python-list
Re: Email Id Verification
Ben Finney ben+pyt...@benfinney.id.au writes: The point is that, having collected the email address, it's useless unless one actually uses it *as an email address*, by sending a message to it. Before then, “validating” it tells you nothing. Right, the only legitimate use of an email address is sending legitimate email to it. An example might be collecting an address so that service staff can respond to a help request. If there is not an up-front, good reason to want to email the address, then collecting it is not legitimate. An example is web sites where users have to supply addresses to register. This is why mailinator.com was invented, but it's annoying even if you use mailinator. -- http://mail.python.org/mailman/listinfo/python-list
Re: Namespace hack
On Fri, May 25, 2012 at 1:02 PM, Temia Eszteri lamial...@cleverpun.com wrote: But then we've got Simple is better than complex, and Complex is better than complicated. Of course if we decided to start iterating through the zen of Python's verses and continually modifying the example code to fit, it would get rather silly rather fast. Silly but amusing. As with all these sorts of documents, the Zen of Python is self-contradictory; it's always left up to an intelligent human to decide when to apply which rule. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
[issue14877] No option to run bdist_wininst against newer msvc versions on non-windows systems
Aaron Staley usaa...@gmail.com added the comment: Hi Eric, Quick rundown: There are template 'exe' inside distutils/command. bdist_wininst appends to the template to build a customized installer. First the 64 bit bug: http://bugs.python.org/issue6792 With that bug active, I must be able to make 64 bit windows installers for users of 64 bit windows python to install my package. Unfortunately, the only 64 bit template is wininst-9.0-amd64.exe. Due to this bug, there is no way to use that installer, preventing one from creating universal windows installers on *nix, which bdist_wininst is supposed to allowed (per documentaiton). Furthermore, I have empirically found that a 32-bit installer built against wininst-6.0 will not behave correctly either. Specifically, the pre-install-script I used would not execute. When I switched to the wininst-9.0 template, all worked fine. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14877 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14897] struct.pack raises unexpected error message
New submission from mesheb82 meshe...@gmail.com: I found some unexpected behavior while working with the struct module. import struct This works as expected: struct.pack('1s1s','3','4') '34' In this case, with bad input, the error message says I need 2 arguments, when I provide 2 arguments. struct.pack('1s1s','33') Traceback (most recent call last): File stdin, line 1, in module struct.error: pack requires exactly 2 arguments -- components: IO messages: 161481 nosy: mesheb82 priority: normal severity: normal status: open title: struct.pack raises unexpected error message type: behavior versions: Python 2.7, Python 3.2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14897 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14897] struct.pack raises unexpected error message
mesheb82 meshe...@gmail.com added the comment: Also, I tested this on Windows in Python 3.2.3 and Windows in Python 2.7.2 -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14897 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14889] PyBytes_FromObject(bytes_object) fails
Stefan Krah stefan-use...@bytereef.org added the comment: I also wonder how the buffer interface section can fail. PyBuffer_ToContiguous() should translate to a simple memcpy() for a bytes object. What is going on? -- nosy: +skrah ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14889 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14744] Use _PyUnicodeWriter API in str.format() internals
Serhiy Storchaka storch...@gmail.com added the comment: For Python 3.3, _PyUnicodeWriter API is faster than the Py_UCS4 buffer API and PyAccu API in quite all cases, with a speedup between 30% and 100%. But there are some cases where the _PyUnicodeWriter API is slower: Perhaps most of these problems can be solved if instead of the boolean flag (overallocate/no overallocate) to use the Py_ssize_t parameter that indicates by how much should you overallocate (it is the length of the suffix in the format). -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14744 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14889] PyBytes_FromObject(bytes_object) fails
Larry Hastings la...@hastings.org added the comment: I can't reproduce this, and it was pretty late in my day when I saw it, so let's assume I was mistaken and PyBytes_CheckBuffer() works fine. Nevertheless I think the patch is a good idea--why create a new object when you don't have to? Unless I hear otherwise I'll check it in in the next day or so. As for what I saw, I suspect it was a deliberate TypeError from the regression test suite, passing in an integer 0 as a filename to os.rename(). Naturally PyBytes_FromObject() fails to convert that to a bytes object. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14889 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14890] typo in difflib
ninsen jcsla...@gmail.com added the comment: My bad, closing... -- status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14890 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14897] struct.pack raises unexpected error message
Mark Dickinson dicki...@gmail.com added the comment: Hmm. Yes, that's not very clear. The same message is used both for struct.pack and for Struct.pack (which struct.pack is really just a convenient alias for); it makes a bit more sense for the latter: struct.Struct('1s1s').pack('33') Traceback (most recent call last): File stdin, line 1, in module struct.error: pack requires exactly 2 arguments -- nosy: +mark.dickinson versions: +Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14897 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14897] struct.pack raises unexpected error message
Serhiy Storchaka storch...@gmail.com added the comment: Funny. struct.pack(fmt, args...) is just an alias to struct.Struct(fmt).pack(args...). The error message should be changed to explicitly state that we are talking about the data for packing, and not about the arguments of function. Or should remove mention of the number of arguments at all (leave only too much or too little). -- nosy: +storchaka ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14897 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14897] struct.pack raises unexpected error message
Mark Dickinson dicki...@gmail.com added the comment: It might help if the error message also stated how many arguments were actually received, like the TypeError message already does for bad function / method calls. E.g., struct.error: pack expected 2 items for packing (got 1) -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14897 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14894] distutils.LooseVersion fails to compare number and a word
Natalia natalia.frydr...@gmail.com added the comment: Hello, as a GSoC student, I'm working on PyPI to Debian repository converter. I wanted to compare versions of packages available in PyPI and it broke while comparing appwsgi, wsgi-design ('default') and gar ('prototype.1') versions. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14894 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5767] xmlrpclib expat
Changes by Phil Daintree phildaint...@gmail.com: -- title: xmlrpclib loads invalid documents - xmlrpclib expat versions: +Python 2.7 -Python 2.5, Python 2.6 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5767 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11804] expat parser not xml 1.1 (breaks xmlrpclib)
Phil Daintree phildaint...@gmail.com added the comment: The field in question contains the utf-8 text: PEÇAS -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11804 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14855] IPv6 support for logging.handlers
Vinay Sajip vinay_sa...@yahoo.co.uk added the comment: Or should it go to the separate ticket? Yes, please. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14855 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14897] struct.pack raises unexpected error message
Serhiy Storchaka storch...@gmail.com added the comment: It might help if the error message also stated how many arguments were actually received, like the TypeError message already does for bad function / method calls. E.g., struct.error: pack expected 2 items for packing (got 1) Yes, this would be useful. But seldom implemented. Traceback (most recent call last): File stdin, line 1, in module TypeError: not enough arguments for format string '%s %s'%(123,456,789) Traceback (most recent call last): File stdin, line 1, in module TypeError: not all arguments converted during string formatting struct.pack also inconsistent in other error messages. Traceback (most recent call last): File stdin, line 1, in module struct.error: argument for 's' must be a bytes object struct.pack('i', '123') Traceback (most recent call last): File stdin, line 1, in module struct.error: required argument is not an integer For s is mentioned format, and for i no. It would be helpful to mention also the number of the item. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14897 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14744] Use _PyUnicodeWriter API in str.format() internals
STINNER Victor victor.stin...@gmail.com added the comment: For Python 3.3, _PyUnicodeWriter API is faster than the Py_UCS4 buffer API and PyAccu API in quite all cases, with a speedup between 30% and 100%. But there are some cases where the _PyUnicodeWriter API is slower: Perhaps most of these problems can be solved if instead of the boolean flag (overallocate/no overallocate) to use the Py_ssize_t parameter that indicates by how much should you overallocate (it is the length of the suffix in the format). There is not only a flag (flags.overallocate): there is also the min_length, which is used and helps for str%args and str.format(args). My patch contains a lot of tricks to limit overallocation, e.g. don't overallocate if we are writing the last part of the output. Computing exactly the size of the buffer gives the best performance because it avoids a resize in _PyUnicodeWriter_Finish(). I tried for example to modify PyUnicode_Format() to parse the format string twice: first to compute the size of the output buffer, second to write characters. In my experience, parsing the format string twice is more expensive than reallocating the buffer (PyUnicode_READ is expensive), especially on short and simple format strings. I tried different methods to allocate the buffer of _PyUnicodeWriter: change the overallocation factor (0%, 25%, 50%, 100%), only overallocate +100 characters, etc. But I failed to find something better than the proposed patch. At least I can say than always disabling overallocation slows done many cases: when there is a suffix after an argument, or when there are more than one argument. Feel free to experiment other methods to estimate the size of the output buffer. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14744 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14814] Implement PEP 3144 (the ipaddress module)
Hynek Schlawack h...@ox.cx added the comment: Here is a patch with some more pep8-wankery + some dead code removal. Feel free to add only what you like, no hard feelings. :) -- Added file: http://bugs.python.org/file25694/ipaddress-pep8-and-dead-code.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14814 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14886] json C vs pure-python implementation difference
Antoine Pitrou pit...@free.fr added the comment: class pseudo_list(object): __class__ = list # fake isinstance Why not inherit from list directly? Setting __class__ to something else isn't widely supported in the Python code base. It may work or may not work, depending on the API, but it's not something we design or test for. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14886 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14898] Dict collision on boolean and integer values
New submission from Sasha B sbermeis...@gmail.com: Not sure if this is predicted behaviour, but if I make a dict like: x = {0: 'bar', True: 'foo'} and modify True with 1, or 0 with False: x[False] = 'boo' x[1] = 'far' the modifications happen: x {0: 'boo', True: 'far'} Is this expected behaviour? It seems that the hashes for 'False' and 0 are confused, as are the hashes for 'True' and 1. -- messages: 161497 nosy: sbermeister priority: normal severity: normal status: open title: Dict collision on boolean and integer values ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14898 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14898] Dict collision on boolean and integer values
Changes by Sasha B sbermeis...@gmail.com: -- components: +Build type: - behavior versions: +Python 2.7 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14898 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14898] Dict collision on boolean and integer values
Mark Dickinson dicki...@gmail.com added the comment: Thanks for the report. Yes, this is expected. Dictionary membership is based on equality of keys. Since True and 1 are equal, only one of them can be present in a dictionary at a time (and a key lookup works with either). x = {0: 'bar'} x[0] 'bar' x[False] 'bar' x[0.0] 'bar' 0 == False True -- nosy: +mark.dickinson resolution: - invalid status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14898 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14898] Dict collision on boolean and integer values
Sasha B sbermeis...@gmail.com added the comment: Ahh, I see. You are correct. Thanks. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14898 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14822] Build unusable when compiled for Win 64-bit release
Jason R. Coombs jar...@jaraco.com added the comment: I tested against the latest tip and the issue no longer exists. -- resolution: - works for me status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14822 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14821] _ctypes and other modules not built with msbuild on vs2010 solution
Jason R. Coombs jar...@jaraco.com added the comment: Excellent! The latest tip now builds nicely using msbuild. -- resolution: - fixed status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14821 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14899] Naming conventions and guidelines for packages and namespace packages
New submission from Benoît Bryon ben...@marmelune.net: Scope: * Python documentation lacks conventions, or at least guidelines, to choose a name for a package. * Python has tools to create and distribute packages. Not covered by this issue. * Python has tools to create namespace packages. Not covered by this issue. * Python has conventions about syntax of module names in PEP 8. Not covered by this issue. Goal: add guidelines+conventions about package names in Doc/packaging/ Discussion started at http://mail.python.org/pipermail/distutils-sig/2012-May/018551.html Jim Fulton said in http://mail.python.org/pipermail/distutils-sig/2012-May/018553.html: +1 for an official document (or addition to an existinhg document) providing a rational for namespace packages and their naming Here is a ticket where proposals can be referenced. Contributions can be pushed on the doc-package-naming-conventions branch of https://bitbucket.org/benoitbryon/cpython -- assignee: docs@python components: Documentation hgrepos: 128 messages: 161502 nosy: benoitbryon, docs@python priority: normal severity: normal status: open title: Naming conventions and guidelines for packages and namespace packages type: enhancement ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14899 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11804] expat parser not xml 1.1 (breaks xmlrpclib)
Amaury Forgeot d'Arc amaur...@gmail.com added the comment: Yes, but where does this data come from? how did you feed it to the parser? And this does not relate to xml 1.1. BTW, I found this page about XML 1.1: http://www.cafeconleche.org/books/effectivexml/chapters/03.html Everything you need to know about XML 1.1 can be summed up in two rules: - Don't use it. - (For experts only) If you speak Mongolian, Yi, Cambodian, Amharic, Dhivehi, Burmese or a very few other languages and you want to write your markup (not your text but your markup) in these languages, then you can set the version attribute of the XML declaration to 1.1. Otherwise, refer to rule 1. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11804 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14899] Naming conventions and guidelines for packages and namespace packages
Benoît Bryon ben...@marmelune.net added the comment: Use branch doc-package-names (not only conventions) instead. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14899 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com