ANN: firehose-0.2 released
firehose is a Python package intended for managing the results from code analysis tools (e.g. compiler warnings, static analysis, linters, etc). It currently provides parsers for the output of gcc, clang-analyzer and cppcheck. These parsers convert the results into a common data model of Python objects, with methods for lossless roundtrips through a provided XML format. There is also a JSON equivalent. It is available on pypi here: https://pypi.python.org/pypi/firehose and via git from: https://github.com/fedora-static-analysis/firehose The mailing list is: https://admin.fedoraproject.org/mailman/listinfo/firehose-devel Firehose is Free Software, licensed under the LGPLv2.1 or (at your option) any later version. It requires Python 2.7 or 3.2 onwards, and has been successfully tested with PyPy. Changes since 0.1: * ensure that the test suite, license, and RELAX-NG schema are packaged in the tarball * revamp of the README Enjoy! Dave -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
[ANN] GMPY2 2.0.0 has been released
I'm pleased to announce the release of GMPY2 2.0.0. GMPY2 provides access to the GMP/MPIR, MPFR, and MPC arbitrary precision arithmetic libraries. Highlights -- * Support for correctly rounded arbitrary precision real arithmetic, including trigonometric, logarithmic, exponential, and special functions. * Support for correctly rounded arbitrary precision complex arithmetic, including trigonometric, logarithmic, and exponential functions. * Support for contexts that control precision, rounding modes, exponent limits, and the behavior of exceptions. * Support for various pseudoprime tests. (Based on code by David Cleaver.) * Support for a mutable (!) integer type that supports the slice syntax to read/write individual bits. Read-only slicing is supported on the standard integer type. Compatibility with GMPY --- GMPY2 is the successor to GMPY. The behavior of some functions in GMPY conflicted with the expected behavior of real/complex arithmetic. In GMPY, sqrt() returned an integer result. In GMPY2, sqrt() returns a real/complex value and isqrt() returns an integer. The development versions of mpmath and Sympy support GMPY2. Availability The home page is: https://code.google.com/p/gmpy/ Documentation: https://gmpy2.readthedocs.org/en/latest/ Case Van Horsen -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
[RELEASED] Python 3.2.4 rc 1 and Python 3.3.1 rc 1
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On behalf of the Python development team, I am pleased to announce the first release candidates of Python 3.2.4 and 3.3.1. Python 3.2.4 will be the last regular maintenance release for the Python 3.2 series, while Python 3.3.1 is the first maintenance release for the 3.3 series. Both releases include hundreds of bugfixes. There has recently been a lot of discussion about XML-based denial of service attacks. Specifically, certain XML files can cause XML parsers, including ones in the Python stdlib, to consume gigabytes of RAM and swamp the CPU. These releases do not include any changes in Python XML code to address these issues. Interested parties should examine the defusedxml package on PyPI: https://pypi.python.org/pypi/defusedxml These are testing releases: Please consider trying them with your code and reporting any bugs you may notice to: http://bugs.python.org/ To download Python 3.2.4 or Python 3.3.1, visit: http://www.python.org/download/releases/3.2.4/ or http://www.python.org/download/releases/3.3.1/ respectively. Enjoy! - -- Georg Brandl, Release Manager georg at python.org (on behalf of the entire python-dev team and all contributors) -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.19 (GNU/Linux) iEYEARECAAYFAlFRRIoACgkQN9GcIYhpnLD6jACgnzYdYRKZ4kwkKeN3zSLSZ3Zr M/IAn17vlpxI3a3xk+i/ODOrCkMnRZro =B5sA -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
Re: Performance of int/long in Python 3
On Tue, Mar 26, 2013 at 4:01 PM, Steven D'Aprano No string methods? You were lucky. When I were a lad, you couldn't even use delimiters for strings. b string Parsing error: file stdin, line 1: b string ^ Unhandled exception: run-time error: syntax error Python 0.9.1. Well of course that's an error. Anyone can see it should have been: a string *duck* ChrisA -- http://mail.python.org/mailman/listinfo/python-list
At a loss on python scoping.
Hi, suppose I have a file like this: class A: r = 5 def func(self, s): self.s = s a = A() print(a.r)# this should print 5, but where does py store the name of r a.func(3) print(a.s)# this should print 3, also where does py store this name. what's the underlying difference between the above example? -- My gpg pubring is available via: gpg --keyserver subkeys.pgp.net--recv-keys 307CF736 More on: http://about.me/introom -- http://mail.python.org/mailman/listinfo/python-list
Re: python3 string format
On Mon, Mar 25, 2013 at 10:24 PM, Shiyao Ma i...@introo.me wrote: HI. one thing confuses me. It is said in the pep3101 that {}.format (x) will invoke the method x.__format__ However, I looked at the src of python3 and found: in class str(object), the format simply contains a pass statement in class int(object), things is the same. I don't know what source you're looking at. In CPython, both of those types are implemented in C, not Python, so there would be no pass statements involved. The int.__format__ method is implemented at: http://hg.python.org/cpython/file/3c437e591499/Objects/longobject.c#l4373 It mainly just calls the _PyLong_FormatAdvancedWriter function, which is at: http://hg.python.org/cpython/file/3c437e591499/Python/formatter_unicode.c#l1399 The str.__format__ method similarly is implemented at: http://hg.python.org/cpython/file/3c437e591499/Objects/unicodeobject.c#l12851 and calls the _PyUnicode_FormatAdvancedWriter function at: http://hg.python.org/cpython/file/3c437e591499/Python/formatter_unicode.c#l1363 -- http://mail.python.org/mailman/listinfo/python-list
Re: At a loss on python scoping.
PS, I now python's scoping rule is lexical rule (aka static rule). How does LEGB apply to class? On Tue, Mar 26, 2013 at 2:17 PM, Shiyao Ma i...@introo.me wrote: Hi, suppose I have a file like this: class A: r = 5 def func(self, s): self.s = s a = A() print(a.r)# this should print 5, but where does py store the name of r a.func(3) print(a.s)# this should print 3, also where does py store this name. what's the underlying difference between the above example? -- My gpg pubring is available via: gpg --keyserver subkeys.pgp.net--recv-keys 307CF736 More on: http://about.me/introom -- My gpg pubring is available via: gpg --keyserver subkeys.pgp.net--recv-keys 307CF736 More on: http://about.me/introom -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On Tue, Mar 26, 2013 at 10:35 AM, Cousin Stanley cousinstan...@gmail.com wrote: Chris Angelico wrote: The Python 3 merge of int and long has effectively penalized small-number arithmetic by removing an optimization. The cost is clear. The cost isn't quite as clear under Debian Wheezy here Stanley C. Kitching Debian Wheezy python inline range_sum forloop forloop_offset 2.7.3 3.1359 3.0725 9.0778 15.6475 3.2.3 2.8226 2.807413.47624 13.6430 Interesting, so your 3.x sum() is optimizing something somewhere. Strange. Are we both running the same Python? I got those from apt-get, aiming for consistency (rather than building a 3.3 from source). The cost is still visible in the for-loop versions, though, and you're still seeing the 2^31 and 2^31 for-loops behave the same way in 3.x but perform quite differently in 2.x. So it's looking like things are mostly the same. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: At a loss on python scoping.
On Tue, Mar 26, 2013 at 5:17 PM, Shiyao Ma i...@introo.me wrote: class A: r = 5 def func(self, s): self.s = s a = A() print(a.r)# this should print 5, but where does py store the name of r What do you mean by the name of r? ChrisA -- http://mail.python.org/mailman/listinfo/python-list
[RELEASED] Python 3.2.4 rc 1 and Python 3.3.1 rc 1
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On behalf of the Python development team, I am pleased to announce the first release candidates of Python 3.2.4 and 3.3.1. Python 3.2.4 will be the last regular maintenance release for the Python 3.2 series, while Python 3.3.1 is the first maintenance release for the 3.3 series. Both releases include hundreds of bugfixes. There has recently been a lot of discussion about XML-based denial of service attacks. Specifically, certain XML files can cause XML parsers, including ones in the Python stdlib, to consume gigabytes of RAM and swamp the CPU. These releases do not include any changes in Python XML code to address these issues. Interested parties should examine the defusedxml package on PyPI: https://pypi.python.org/pypi/defusedxml These are testing releases: Please consider trying them with your code and reporting any bugs you may notice to: http://bugs.python.org/ To download Python 3.2.4 or Python 3.3.1, visit: http://www.python.org/download/releases/3.2.4/ or http://www.python.org/download/releases/3.3.1/ respectively. Enjoy! - -- Georg Brandl, Release Manager georg at python.org (on behalf of the entire python-dev team and all contributors) -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.19 (GNU/Linux) iEYEARECAAYFAlFRRIoACgkQN9GcIYhpnLD6jACgnzYdYRKZ4kwkKeN3zSLSZ3Zr M/IAn17vlpxI3a3xk+i/ODOrCkMnRZro =B5sA -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: import in Python3.3
On 3/24/2013 7:12 PM, Fabian von Romberg wrote: Hi, I have a package name collections and inside of my package I want to import the collections package from the standard library, but there is name conflicts. Yes. I strongly advise against trying to do this. How do I import explicitly from the standard library? Manipulate sys.path. If you don't know how, either read about sys.path (see index) or don't do it. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: At a loss on python scoping.
On 3/26/2013 2:17 AM, Shiyao Ma wrote: Hi, suppose I have a file like this: class A: r = 5 def func(self, s): self.s = s a = A() print(a.r)# this should print 5, but where does py store the name of r a.func(3) print(a.s)# this should print 3, also where does py store this name. what's the underlying difference between the above example? For CPython, both the class A and the instance a have a .__dict__ attribute that stores names and values. But that is intended to be hidden and transparent for normal usage. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Separate Rows in reader
On Tuesday, March 26, 2013 1:48:10 PM UTC+10, MRAB wrote: On 26/03/2013 03:33, Jiewei Huang wrote: On Tuesday, March 26, 2013 11:40:51 AM UTC+10, Dave Angel wrote: On 03/25/2013 09:05 PM, Jiewei Huang wrote: On Monday, March 25, 2013 11:51:51 PM UTC+10, rusi wrote: If you insist on using GoogleGroups, then make sure you keep your quotes small. I'm about to stop reading messages that are double-spaced by buggy software. SNIP Have you tried the split (and perhaps strip) methods from http://docs.python.org/2/library/stdtypes.html#string-methods ? You got lots of specific advice from your previous thread. So which version did you end up using? It'd make a good starting place for this problem. can show me one line of how to implement it base on my problem? As long as the input data is constrained not to have any embedded commas, just use: mylist = line.split(,) instead of print, send your output to a list. Then for each line in the list, fix the bracket problem to your strange specs. outline = outline.replace([, () Hi Dave thanks for the tips, I manage to code this: f = open('Book1.csv', 'rU') for row in f: print zip([row for (row) in f]) however my output is [('John Konon Ministry of Moon Walks 4567882 27-Feb\n',), ('Stacy Kisha Ministry of Man Power 1234567 17-Jan\n',)] is there any method to remove the \n ? Use the .rstrip method: print zip(row.rstrip('\n') for row in f) thanks ! got it working! -- http://mail.python.org/mailman/listinfo/python-list
Re: This mail never gets delivered. Any ideas why?
Τη Τρίτη, 12 Μαρτίου 2013 12:34:50 π.μ. UTC+2, ο χρήστης Thomas Rachel έγραψε: Am 10.03.2013 19:39 schrieb οΏ½οΏ½οΏ½οΏ½οΏ½ οΏ½οΏ½οΏ½33οΏ½: Hey man this worked via Python! [...] if( os.system( 'echo %s | mail -s %s supp...@superhost.gr' % (MESSAGE, FROM) ) ): [...] Thank you! I beleive this is the simplest way of sending an email! Until you get a MESSAGE which has a sign in it, or a FROM. (Sorry, didn't see this message before.) In order to prevent trouble with this, it might be better to use subprocess and to do sp = subprocess.Popen(['mail', '-f', FROM, '-s', SUBJECT, 'supp...@superhost.gr], stdin=subprocess.PIPE) sp.communicate(MESSAGE) res = sp.wait() if res: ... else: ... If you do so, you can have FROMs, SUBJECTs and MESSAGEs conaining every character you want, including and ', an no shell will complain about it or be confused. (Note that I changed the arguments for mail a little bit, because -s prevedes the subject and -f the from.) Thomas Hello and sorry for beign so much late to respond. Yout solution is clearly betetr than the simple mail solution i found to be working but i think subprocess requires that i use Python3 interpeter which of course my web host supports, but it would fail running my MYSQLdbd module. So is there still a way to use your solution? -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me pick an API design (OO vs functional)
On Monday, March 25, 2013 10:08:53 PM UTC+1, Chris Angelico wrote: ... I kind of like the context manager solution because the indentation makes it very obvious what happens in which window. You are right about our target group though. Also, the with is not as explicit as it probably should be. What happens at the __exit__ of the context manager? What happens if context managers are nested? I'd be inclined to the simpler option of an explicit switch (since focus doesn't really stack and it'd feel weird for focus to *sometimes* switch away when you're done working with one window), though the context manager syntax does have its advantages too. You are right, an __exit__ for a window doesn't really make sense and neither does stacking. There's also the problem that the focus window may change - for instance when closing it. What happens if you're still inside the with ... then? At first glance, I think the context manager solution looks nice syntactically, but maybe it isn't the way to go here. ... We'd of course love to support other platforms but don't currently have the resources to do this. We actually just wrote a blog entry about this and some related questions: http://www.getautoma.com/blog/automa-faq If we have something wrong, do let us know in the comments over there! Make the API clean enough and someone else might well write a Linux equivalent. Then it'll be as simple as a try/import/except/import at the top and multiple platforms will work. Yes, that's a good point. A clean API is very important to us (hence my posting here). Thanks for your answer! Michael -- http://mail.python.org/mailman/listinfo/python-list
Screencast: Creating and deploying an advanced python web application in under 15 minutes!
Hi, I've created a screen cast showing how a message board with live-validation and Ajax calls written in python can be built and deployed in under 15 minutes. You can view it here: http://www.youtube.com/watch?v=ucougrZK9wI I hope some of you find it useful, Thanks! Timothy -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me pick an API design (OO vs functional)
On Tuesday, March 26, 2013 12:11:34 AM UTC+1, Ethan Furman wrote: On 03/25/2013 12:29 PM, Michael Herrmann wrote: ... notepad_1 = start(Notepad) notepad_2 = start(Notepad) notepad_1.write(Hello World!) notepad_1.press(CTRL + 'a', CTRL + 'c') notepad_2.press(CTRL + 'v') This is the way to go. Just move your global functions into the Window object (or whatever you call it), break backwards compatibility (major version number change, perhaps?), and call it good. It makes much more sense to call methods of several different objects (which is explicit -- you always know which object is being used) than having a magic function that changes the object in the background (plus you now have to search backwards for the last magic invocation to know -- and what if a called function changes it?). Your points are valid and I cannot really say anything against them. The problem with moving all global functions into the Window object is that this adds a lot of syntactic baggage that isn't needed in 90% of the cases. We really prefer the simplicity of start(Notepad) write(Hello World!) press(CTRL + 's') write(test.txt, into=File name) click(Save) press(ALT + F4) over notepad = start(Notepad) notepad.write(Hello World!) notepad.press(CTRL + 's') notepad.write(test.txt, into=File name) notepad.click(Save) notepad.press(ALT + F4). Also, there's a problem here: The Save dialogue that opens in the above script is technically a different window so in theory you would have to introduce a new object to distinguish between the original window that lets you edit your text document from the Save window. This is very tedious and error-prone. You are right, though, that we have to do some logic in the background to remember the last window. In light of this, could you live with something along the lines of design #4? notepad_1 = start(Notepad) notepad_2 = start(Notepad) notepad_1.focus() write(Hello World!) press(CTRL + 'a', CTRL + 'c') notepad_2.focus() press(CTRL + 'v') Thanks, Michael -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me pick an API design (OO vs functional)
On Tuesday, March 26, 2013 12:40:45 AM UTC+1, Mitya Sirenef wrote: ... I think I would prefer context managers. I don't think it's a big problem for win users because this behaviour would be one of the first things documented in the start guide and would be all over example scripts, so a new user missing or forgetting it is not a realistic scenario. The advantages are that it's explicit, blocks are indented and it's impossible to miss which window is the action applied to, and at the same time actions are short and easy to type and read. Thank you for your reply. What do you think of Chris Angelico's points? He wrote: What happens at the __exit__ of the context manager? What happens if context managers are nested? I'd be inclined to the simpler option of an explicit switch (since focus doesn't really stack and it'd feel weird for focus to *sometimes* switch away when you're done working with one window), though the context manager syntax does have its advantages too. What I am most afraid of: that the window that's currently the context disappears: notepad = start(Notepad) with notepad: press(ALT + TAB) write(Am I in Notepad now?) What do you think of designs #3 and #4? notepad_1 = start(Notepad) notepad_2 = start(Notepad) switch_to(notepad_1) write(Hello World!) press(CTRL + 'a', CTRL + 'c') switch_to(notepad_2) press(CTRL + 'v') notepad_1 = start(Notepad) notepad_2 = start(Notepad) notepad_1.activate() write(Hello World!) press(CTRL + 'a', CTRL + 'c') notepad_2.activate() press(CTRL + 'v') I somehow prefer activate over focus as in my feeling, you'd normally say that you focus *on* something, so it should be called focus_on or give_focus[_to]. Can you say, in everyday English, that you focus a window? I'm not a native speaker so maybe my feeling is misguided. Thanks, Michael -- http://mail.python.org/mailman/listinfo/python-list
Processing user input as it's entered
Hello, Is there a way (ideally cross platform but a *nix OS solution would be great) to process user input as they type? What I aim to achieve is to count the number of characters a user has entered and display it while they are typing. The entered text will also need to be captured once the user has finished typing. This is a gui-less CLI tool for python 2.7 I've seen some information on tty.setraw but I'm not sure how you'd go about wiring that up. Thanks -- ./Sven -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me pick an API design (OO vs functional)
- Original Message - notepad_1 = start(Notepad) notepad_2 = start(Notepad) notepad_1.write(Hello World!) notepad_1.press(CTRL + 'a', CTRL + 'c') notepad_2.press(CTRL + 'v') The problem with this design is that it effectively duplicates our API: We want to keep our global functions because they are so easy to read. So is the example above. This is the best solution in my opinion. I think you're having the same issue that some other APIs, let's say matplotlib for example. They try to accommodate scientists (matlab) and programmers(python) by having a double API style. One looks like legend() title() plot() save() the other looks like fig = figure() fig.add_legend() fig.title() fig.plot() fig.save() The problem is, when searching for example on the net, you'll end up with a mix of both, it can become a nightmare. I definitely prefer the later, for the reasons that have already been given to you in this thread and by the fact that with the correct (I)python shell, you can create your window object and get auto-completion on its methods just by hitting tab, very helpful when introspecting objects. Can be achieved of course in any python shell with function like dir() ; my point being that OOO design keeps things in their place, see the zen of python Namespaces are one honking great idea -- let's do more of those! JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: At a loss on python scoping.
On 03/26/2013 02:17 AM, Shiyao Ma wrote: Hi, suppose I have a file like this: class A: r = 5 def func(self, s): self.s = s a = A() print(a.r)# this should print 5, but where does py store the name of r a.func(3) print(a.s)# this should print 3, also where does py store this name. what's the underlying difference between the above example? I don't think this is a scoping question at all. These references are fully qualified, so scoping doesn't enter in. The class A has a dictionary containing the names of r and func. These are class attributes. Each instance has a dictionary which will contain the name s AFTER the A.func() is called. Ideally such an attribute will be assigned in the __init__() method, in which case every instance will have s in its dictionary. When you use a.qqq the attribute qqq is searched for in the instance dictionary and, if not found, in the class dictionary. If still not found, in the parent classes' dictionary(s). You can use dir(A) and dir(a) to look at these dictionaries, but it shows you the combination of them, so it's not as clear. In other words, dir(a) shows you both dictionaries, merged. (Seems to me dir also sometimes censors some of the names, but that's a vague memory. It's never left out anything I cared about, so maybe it's things like single-underscore names, or maybe just a poor memory.) -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me pick an API design (OO vs functional)
On 03/26/2013 05:06 AM, Michael Herrmann wrote: On Tuesday, March 26, 2013 12:11:34 AM UTC+1, Ethan Furman wrote: On 03/25/2013 12:29 PM, Michael Herrmann wrote: ... notepad_1 = start(Notepad) notepad_2 = start(Notepad) notepad_1.write(Hello World!) notepad_1.press(CTRL + 'a', CTRL + 'c') notepad_2.press(CTRL + 'v') This is the way to go. Just move your global functions into the Window object (or whatever you call it), break backwards compatibility (major version number change, perhaps?), and call it good. It makes much more sense to call methods of several different objects (which is explicit -- you always know which object is being used) than having a magic function that changes the object in the background (plus you now have to search backwards for the last magic invocation to know -- and what if a called function changes it?). Your points are valid and I cannot really say anything against them. The problem with moving all global functions into the Window object is that this adds a lot of syntactic baggage that isn't needed in 90% of the cases. We really prefer the simplicity of start(Notepad) write(Hello World!) press(CTRL + 's') write(test.txt, into=File name) click(Save) press(ALT + F4) over notepad = start(Notepad) notepad.write(Hello World!) notepad.press(CTRL + 's') notepad.write(test.txt, into=File name) notepad.click(Save) notepad.press(ALT + F4). Also, there's a problem here: The Save dialogue that opens in the above script is technically a different window so in theory you would have to introduce a new object to distinguish between the original window that lets you edit your text document from the Save window. This is very tedious and error-prone. You are right, though, that we have to do some logic in the background to remember the last window. In light of this, could you live with something along the lines of design #4? notepad_1 = start(Notepad) notepad_2 = start(Notepad) notepad_1.focus() write(Hello World!) press(CTRL + 'a', CTRL + 'c') notepad_2.focus() press(CTRL + 'v') Thanks, Michael Seems to me that the official interface should all be methods. However, you could have a new object which always represents the focus window. Then the USER could define trivial functions: def write(*args): focused.write(*args) Somewhere in this thread you mention that save() creates a new window, so a method-oriented approach would require that the user get that window object, and call its methods rather than the original window's. I say that's a very good thing, since the things you send may very well have very different meanings to the save dialog than they do in the original one. Another concern I'd have is what happens if the user changes focus with his mouse? Does that change the meaning you had for focus() in the above exchange? Do you want your press() method to apply to a different window when the user changes to that window? -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: This mail never gets delivered. Any ideas why?
Because Python 3 doesnt support MySQLdb moudle yet i decided to use mypysql-0.5.5.tar.gz which i found in google. problem is that i dont know how to run this file in my webost account so it cant be utilized and so i can pass to Python 3 at last. i ahve uplaoded the file viua cPnael in webhost but then what? How doi embed this in python so to make use of it? -- http://mail.python.org/mailman/listinfo/python-list
JES account balance function help urgent!
I am supposed to complete the following five functions, i have no idea how to do this. I will greatly appreciate any help The following five functions allow you to maintain the running balance of an account and print out lines relating to each transaction. You'll also need a global variable (balance?) to maintain the running balance of the account. 1. def setBalance(amt): # Defines (but doesn't print) the value of the account balance 2. def printBalance(): # Displays current balance as a money value with a heading 3. def printLedgerLine(date, amount, details): # with items (and the balance) spaced and formatted 4. def deposit (date, details, amount): # Alter the balance and print ledger line 5. def withdraw(date, details, amount): # Alter the balance and print ledger line Your task is to: complete the five (very short) functions by creating the code for the body of each function, and demonstrate that you code works by calling the functions, as is demonstrated below. So when these functions are called e.g. setBalance(500) printBalance() withdraw(17-12-2012, BP - petrol, 72.50) withdraw(19-12-2012, Countdown, 55.50) withdraw(20-12-2012, munchies, 1.99) withdraw(22-12-2012, Vodafone, 20) deposit (23-12-2012, Income, 225) withdraw(24-12-2012, Presents, 99.02) printBalance() The output is something like this: Current Balance is $ 500.00 17-12-2012 BP - petrol $ 72.50 $ 427.50 19-12-2012 Countdown $ 55.50 $ 372.00 20-12-2012 munchies $ 1.99 $ 370.01 22-12-2012 Vodafone $ 20.00 $ 350.01 23-12-2012 Income $ 225.00 $ 575.01 24-12-2012 Presents $ 99.02 $ 475.99 Current Balance is $ 475.99 So far i got: def setBalance(amount): global balance assert isinstance(amount,numbers.number) balance = euros printNow(balance) Im not sure whats wrong, i only started programming a week ago, im so lost, please help me with this assignment thnx -- http://mail.python.org/mailman/listinfo/python-list
Re: At a loss on python scoping.
Sorry for my obscure description. the name of r , AFAIK, everything in python is just a reference. For example, a = 3, means a points to a small integer; b= [] means b points to a list somewhere in the memory. So I call r as the name of r. To clarify my question. say I wanna look up a.r I guess the first step is to look inside a, maybe in the __dict__? As proved in my ipython, the __dict__ is empty. So, it will look up in A.__dict__ Here comes my first question, where does the scope of class A falls in when considering LEGB. On Tue, Mar 26, 2013 at 2:29 PM, Chris Angelico ros...@gmail.com wrote: On Tue, Mar 26, 2013 at 5:17 PM, Shiyao Ma i...@introo.me wrote: class A: r = 5 def func(self, s): self.s = s a = A() print(a.r)# this should print 5, but where does py store the name of r What do you mean by the name of r? ChrisA -- http://mail.python.org/mailman/listinfo/python-list -- My gpg pubring is available via: gpg --keyserver subkeys.pgp.net--recv-keys 307CF736 More on: http://about.me/introom -- http://mail.python.org/mailman/listinfo/python-list
Re: python3 string format
Thx for your reply. I am using pycharm and simply press go to declaration which directs me to a py file, containing the following code: def format(*args, **kwargs): # known special case of str.format S.format(*args, **kwargs) - string Return a formatted version of S, using substitutions from args and kwargs. The substitutions are identified by braces ('{' and '}'). pass I am curious how you find the corresponding c source code. On Tue, Mar 26, 2013 at 2:16 PM, Ian Kelly ian.g.ke...@gmail.com wrote: On Mon, Mar 25, 2013 at 10:24 PM, Shiyao Ma i...@introo.me wrote: HI. one thing confuses me. It is said in the pep3101 that {}.format (x) will invoke the method x.__format__ However, I looked at the src of python3 and found: in class str(object), the format simply contains a pass statement in class int(object), things is the same. I don't know what source you're looking at. In CPython, both of those types are implemented in C, not Python, so there would be no pass statements involved. The int.__format__ method is implemented at: http://hg.python.org/cpython/file/3c437e591499/Objects/longobject.c#l4373 It mainly just calls the _PyLong_FormatAdvancedWriter function, which is at: http://hg.python.org/cpython/file/3c437e591499/Python/formatter_unicode.c#l1399 The str.__format__ method similarly is implemented at: http://hg.python.org/cpython/file/3c437e591499/Objects/unicodeobject.c#l12851 and calls the _PyUnicode_FormatAdvancedWriter function at: http://hg.python.org/cpython/file/3c437e591499/Python/formatter_unicode.c#l1363 -- http://mail.python.org/mailman/listinfo/python-list -- My gpg pubring is available via: gpg --keyserver subkeys.pgp.net--recv-keys 307CF736 More on: http://about.me/introom -- http://mail.python.org/mailman/listinfo/python-list
Re: JES account balance function help urgent!
On 03/26/2013 06:30 AM, kidom...@gmail.com wrote: I am supposed to complete the following five functions, i have no idea how to do this. I will greatly appreciate any help The following five functions allow you to maintain the running balance of an account and print out lines relating to each transaction. You'll also need a global variable (balance?) to maintain the running balance of the account. 1. def setBalance(amt): # Defines (but doesn't print) the value of the account balance 2. def printBalance(): # Displays current balance as a money value with a heading 3. def printLedgerLine(date, amount, details): # with items (and the balance) spaced and formatted 4. def deposit (date, details, amount): # Alter the balance and print ledger line 5. def withdraw(date, details, amount): # Alter the balance and print ledger line Your task is to: complete the five (very short) functions by creating the code for the body of each function, and demonstrate that you code works by calling the functions, as is demonstrated below. So when these functions are called e.g. setBalance(500) printBalance() withdraw(17-12-2012, BP - petrol, 72.50) withdraw(19-12-2012, Countdown, 55.50) withdraw(20-12-2012, munchies, 1.99) withdraw(22-12-2012, Vodafone, 20) deposit (23-12-2012, Income, 225) withdraw(24-12-2012, Presents, 99.02) printBalance() The output is something like this: Current Balance is $ 500.00 17-12-2012 BP - petrol $ 72.50 $ 427.50 19-12-2012 Countdown $ 55.50 $ 372.00 20-12-2012 munchies $ 1.99 $ 370.01 22-12-2012 Vodafone $ 20.00 $ 350.01 23-12-2012 Income $ 225.00 $ 575.01 24-12-2012 Presents $ 99.02 $ 475.99 Current Balance is $ 475.99 So far i got: def setBalance(amount): global balance assert isinstance(amount,numbers.number) balance = euros printNow(balance) Im not sure whats wrong, i only started programming a week ago, im so lost, please help me with this assignment thnx I'm not sure how literally to take your proposal. You have no indentation in the function body, so that's one serious problem. And you're apparently calling printNow() from within that function, which is NOT what was called for. And the function takes amount as its parameter, but then uses 'euros' in the body. That's a big spelling error. You're also going to need to import numbers, if you want that isinstance to work. The layout of your code should be something like: shebang line (optional) imports global variables def's testing code (supplied by instructor) Write all the functions, making sure each takes the expected parameters, even if the function does nothing more than print its name and parameters. Then when the code runs, refine the function bodies till they're all correct. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: At a loss on python scoping.
Thx, really a nice and detailed explanation. On Tue, Mar 26, 2013 at 6:07 PM, Dave Angel da...@davea.name wrote: On 03/26/2013 02:17 AM, Shiyao Ma wrote: Hi, suppose I have a file like this: class A: r = 5 def func(self, s): self.s = s a = A() print(a.r)# this should print 5, but where does py store the name of r a.func(3) print(a.s)# this should print 3, also where does py store this name. what's the underlying difference between the above example? I don't think this is a scoping question at all. These references are fully qualified, so scoping doesn't enter in. The class A has a dictionary containing the names of r and func. These are class attributes. Each instance has a dictionary which will contain the name s AFTER the A.func() is called. Ideally such an attribute will be assigned in the __init__() method, in which case every instance will have s in its dictionary. When you use a.qqq the attribute qqq is searched for in the instance dictionary and, if not found, in the class dictionary. If still not found, in the parent classes' dictionary(s). You can use dir(A) and dir(a) to look at these dictionaries, but it shows you the combination of them, so it's not as clear. In other words, dir(a) shows you both dictionaries, merged. (Seems to me dir also sometimes censors some of the names, but that's a vague memory. It's never left out anything I cared about, so maybe it's things like single-underscore names, or maybe just a poor memory.) -- DaveA -- http://mail.python.org/**mailman/listinfo/python-listhttp://mail.python.org/mailman/listinfo/python-list -- My gpg pubring is available via: gpg --keyserver subkeys.pgp.net--recv-keys 307CF736 More on: http://about.me/introom -- http://mail.python.org/mailman/listinfo/python-list
Re: At a loss on python scoping.
After read Dave's answer, I think I confused LEGB with attribute lookup. So, a.r has nothing to do with LEGB. On Tue, Mar 26, 2013 at 7:03 PM, Shiyao Ma i...@introo.me wrote: Thx, really a nice and detailed explanation. On Tue, Mar 26, 2013 at 6:07 PM, Dave Angel da...@davea.name wrote: On 03/26/2013 02:17 AM, Shiyao Ma wrote: Hi, suppose I have a file like this: class A: r = 5 def func(self, s): self.s = s a = A() print(a.r)# this should print 5, but where does py store the name of r a.func(3) print(a.s)# this should print 3, also where does py store this name. what's the underlying difference between the above example? I don't think this is a scoping question at all. These references are fully qualified, so scoping doesn't enter in. The class A has a dictionary containing the names of r and func. These are class attributes. Each instance has a dictionary which will contain the name s AFTER the A.func() is called. Ideally such an attribute will be assigned in the __init__() method, in which case every instance will have s in its dictionary. When you use a.qqq the attribute qqq is searched for in the instance dictionary and, if not found, in the class dictionary. If still not found, in the parent classes' dictionary(s). You can use dir(A) and dir(a) to look at these dictionaries, but it shows you the combination of them, so it's not as clear. In other words, dir(a) shows you both dictionaries, merged. (Seems to me dir also sometimes censors some of the names, but that's a vague memory. It's never left out anything I cared about, so maybe it's things like single-underscore names, or maybe just a poor memory.) -- DaveA -- http://mail.python.org/**mailman/listinfo/python-listhttp://mail.python.org/mailman/listinfo/python-list -- My gpg pubring is available via: gpg --keyserver subkeys.pgp.net--recv-keys 307CF736 More on: http://about.me/introom -- My gpg pubring is available via: gpg --keyserver subkeys.pgp.net--recv-keys 307CF736 More on: http://about.me/introom -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me pick an API design (OO vs functional)
On Tue, Mar 26, 2013 at 7:53 PM, Michael Herrmann michael.herrm...@getautoma.com wrote: On Monday, March 25, 2013 10:08:53 PM UTC+1, Chris Angelico wrote: ... I kind of like the context manager solution because the indentation makes it very obvious what happens in which window. You are right about our target group though. Also, the with is not as explicit as it probably should be. What happens at the __exit__ of the context manager? What happens if context managers are nested? I'd be inclined to the simpler option of an explicit switch (since focus doesn't really stack and it'd feel weird for focus to *sometimes* switch away when you're done working with one window), though the context manager syntax does have its advantages too. You are right, an __exit__ for a window doesn't really make sense and neither does stacking. There's also the problem that the focus window may change - for instance when closing it. What happens if you're still inside the with ... then? At first glance, I think the context manager solution looks nice syntactically, but maybe it isn't the way to go here. Fundamental point: As I understand the API, it doesn't *actually* tie to a window. You don't locate the Notepad window and send it keys - you switch focus to Notepad and then send keys to the whole system. Is this correct? I'm basing my understanding on this paragraph from your original post: We do not (yet) have a functionality that allows you to explicitly switch to a specific window. Such a functionality would for instance make it possible to open two Notepad windows using the start(...) command, and copy text between them. If so, then all of the method-based options are effectively lying, because they imply a binding that's not there. The actual sequence of actions includes imperatives of switch to some other window, so I think that's what the API should reflect. Otherwise, there's risk that something will get horribly horribly confused between the programmer's brain and the end result (which could happen on either side of your code). But if you can unambiguously identify a running instance of something and switch to it, then a method on the object that start() returns would be absolutely correct. So I'd be looking at either your second or fourth options from the original post. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me pick an API design (OO vs functional)
On Tue, Mar 26, 2013 at 8:38 PM, Michael Herrmann michael.herrm...@getautoma.com wrote: What do you think of designs #3 and #4? notepad_1 = start(Notepad) notepad_2 = start(Notepad) switch_to(notepad_1) write(Hello World!) press(CTRL + 'a', CTRL + 'c') switch_to(notepad_2) press(CTRL + 'v') notepad_1 = start(Notepad) notepad_2 = start(Notepad) notepad_1.activate() write(Hello World!) press(CTRL + 'a', CTRL + 'c') notepad_2.activate() press(CTRL + 'v') Ehh, I referred to these as options 2 and 4. Got lost in the indexing somewhere. These are the same two I meant, though - these are the options I think are the most plausible. (Hindsight being 20/20, it'd have been awesome if the original snippets had had identifiers next to them. Oh well, no matter.) ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me pick an API design (OO vs functional)
On Tuesday, March 26, 2013 11:07:45 AM UTC+1, Jean-Michel Pichavant wrote: - Original Message - notepad_1 = start(Notepad) notepad_2 = start(Notepad) notepad_1.write(Hello World!) notepad_1.press(CTRL + 'a', CTRL + 'c') notepad_2.press(CTRL + 'v') The problem with this design is that it effectively duplicates our API: We want to keep our global functions because they are so easy to read. So is the example above. This is the best solution in my opinion. Thanks for your reply. What do you mean by So is the example above though? I think you're having the same issue that some other APIs, let's say matplotlib for example. They try to accommodate scientists (matlab) and programmers(python) by having a double API style. One looks like legend() title() plot() save() the other looks like fig = figure() fig.add_legend() fig.title() fig.plot() fig.save() The problem is, when searching for example on the net, you'll end up with a mix of both, it can become a nightmare. Interesting point. I'll google a little about matplotlib. I definitely prefer the later, for the reasons that have already been given to you in this thread and by the fact that with the correct (I)python shell, you can create your window object and get auto-completion on its methods just by hitting tab, very helpful when introspecting objects. Can be achieved of course in any python shell with function like dir() ; my point being that OOO design keeps things in their place, see the zen of python Namespaces are one honking great idea -- let's do more of those! Doesn't the IPython do auto-completion for global functions? Thanks, Michael (www.getautoma.com) -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me pick an API design (OO vs functional)
On Tue, Mar 26, 2013 at 10:52 PM, Michael Herrmann michael.herrm...@getautoma.com wrote: Doesn't the IPython do auto-completion for global functions? Even if it does, it'll be polluted with every other global. Methods don't have that problem. On the flip side, since presumably this is (will be) a module, anyone who wants autocomplete of its top-level functions can simply import module instead of from module import *, which will do the same namespacing. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me pick an API design (OO vs functional)
On Tuesday, March 26, 2013 11:26:30 AM UTC+1, Dave Angel wrote: ... Seems to me that the official interface should all be methods. However, you could have a new object which always represents the focus window. Then the USER could define trivial functions: def write(*args): focused.write(*args) It's an interesting idea. But why not give this write(...) to them in the first place? Am I the only one who appreciates the simplicity of start(Notepad) write(Hello World!) press(CTRL + 's') write(test.txt, into=File name) click(Save) press(ALT + F4) over notepad = start(Notepad) notepad.write(Hello World!) notepad.press(CTRL + 's') notepad.write(test.txt, into=File name) notepad.click(Save) notepad.press(ALT + F4)? Somewhere in this thread you mention that save() creates a new window, so a method-oriented approach would require that the user get that window object, and call its methods rather than the original window's. I say that's a very good thing, since the things you send may very well have very different meanings to the save dialog than they do in the original one. save() is not a function, but I assume you mean the action that opens the Save dialogue (I think that'd be `press(CTRL + 's')`). You are right that it's nice for it to be explicit. However, in 95% of cases, the window you want the next action to be performed in is the window that is currently active. I appreciate the explicitness, but to force it on the user for only 5% of cases seems a bit much. Another concern I'd have is what happens if the user changes focus with his mouse? Does that change the meaning you had for focus() in the above exchange? Do you want your press() method to apply to a different window when the user changes to that window? No. Internally, we remember which window is the currently active window. If you just run a script without user-intervention, this will be the respective foreground window. If some other window is in the foreground - which most typically happens when the user is interactively entering commands one after the other, so the foreground window is the console window, we do switch to the window that's supposed to be the active one. It may sound like black magic, but it works very well in practice, and really is not too ambiguous. When you read a script like start(Notepad) write(Hello World) press(CTRL + 's') write(test.txt, into=File name) click(Save) click(Close) I hold that you intuitively know what's going on, without even thinking about window switching. Best, Michael www.getautoma.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me pick an API design (OO vs functional)
On Tuesday, March 26, 2013 12:38:35 PM UTC+1, Chris Angelico wrote: ... Fundamental point: As I understand the API, it doesn't *actually* tie to a window. You don't locate the Notepad window and send it keys - you switch focus to Notepad and then send keys to the whole system. Is this correct? I'm basing my understanding on this paragraph from your original post: We do not (yet) have a functionality that allows you to explicitly switch to a specific window. Such a functionality would for instance make it possible to open two Notepad windows using the start(...) command, and copy text between them. If so, then all of the method-based options are effectively lying, because they imply a binding that's not there. The actual sequence of actions includes imperatives of switch to some other window, so I think that's what the API should reflect. Otherwise, there's risk that something will get horribly horribly confused between the programmer's brain and the end result (which could happen on either side of your code). As I just wrote in my reply to Dave, internally we know very well which window an action is to be performed in. This window is the window that'd be in the foreground after the previous action, if nothing interferes with the system while the script is being executed. A common exception is when you enter commands in the interactive interpreter: say you write start(Notepad) The Notepad window opens, but for you to enter the next command, you have to switch back to the interpreter window. If you do that, and enter write(Hello World) then we remember that you were previously working with the Notepad window and activate this window before performing the key strokes to type Hello World. But if you can unambiguously identify a running instance of something and switch to it, then a method on the object that start() returns would be absolutely correct. So I'd be looking at either your second or fourth options from the original post. Those are also my favorites at the moment :) Michael www.getautoma.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me pick an API design (OO vs functional)
- Original Message - On Tuesday, March 26, 2013 11:07:45 AM UTC+1, Jean-Michel Pichavant wrote: - Original Message - notepad_1 = start(Notepad) notepad_2 = start(Notepad) notepad_1.write(Hello World!) notepad_1.press(CTRL + 'a', CTRL + 'c') notepad_2.press(CTRL + 'v') ^ | here, this is an above example :D The problem with this design is that it effectively duplicates our API: We want to keep our global functions because they are so easy to read. So is the example above. This is the best solution in my opinion. Thanks for your reply. What do you mean by So is the example above though? Well the example above :). [snip] Doesn't the IPython do auto-completion for global functions? Yes it does, but as Chris pointed out, your global/module namespace will be polluted by a lot of names. By using completion on an object, you get the method it has access to, which is very useful to narrow down what you can do with it. JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me pick an API design (OO vs functional)
On Tuesday, March 26, 2013 12:43:18 PM UTC+1, Chris Angelico wrote: On Tue, Mar 26, 2013 at 8:38 PM, Michael Herrmann What do you think of designs #3 and #4? notepad_1 = start(Notepad) notepad_2 = start(Notepad) switch_to(notepad_1) write(Hello World!) press(CTRL + 'a', CTRL + 'c') switch_to(notepad_2) press(CTRL + 'v') notepad_1 = start(Notepad) notepad_2 = start(Notepad) notepad_1.activate() write(Hello World!) press(CTRL + 'a', CTRL + 'c') notepad_2.activate() press(CTRL + 'v') Ehh, I referred to these as options 2 and 4. Got lost in the indexing somewhere. These are the same two I meant, though - these are the options I think are the most plausible. (Hindsight being 20/20, it'd have been awesome if the original snippets had had identifiers next to them. Oh well, no matter.) True, and the indexing mistake was my fault... Here goes: Design #1: notepad_1 = start(Notepad) notepad_2 = start(Notepad) notepad_1.write(Hello World!) notepad_1.press(CTRL + 'a', CTRL + 'c') notepad_2.press(CTRL + 'v') Design #2: notepad_1 = start(Notepad) notepad_2 = start(Notepad) switch_to(notepad_1) write(Hello World!) press(CTRL + 'a', CTRL + 'c') switch_to(notepad_2) press(CTRL + 'v') Design #3: notepad_1 = start(Notepad) notepad_2 = start(Notepad) with notepad_1: write(Hello World!) press(CTRL + 'a', CTRL + 'c') with notepad_2: press(CTRL + 'v') Design #4: notepad_1 = start(Notepad) notepad_2 = start(Notepad) notepad_1.activate() write(Hello World!) press(CTRL + 'a', CTRL + 'c') notepad_2.activate() press(CTRL + 'v') Michael www.getautoma.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me pick an API design (OO vs functional)
On Tuesday, March 26, 2013 12:57:21 PM UTC+1, Chris Angelico wrote: On Tue, Mar 26, 2013 at 10:52 PM, Michael Herrmann Doesn't the IPython do auto-completion for global functions? Even if it does, it'll be polluted with every other global. Methods don't have that problem. On the flip side, since presumably this is (will be) a module, anyone who wants autocomplete of its top-level functions can simply import module instead of from module import *, which will do the same namespacing. True! I don't think polluting the global namespace is that much of an issue. -- http://mail.python.org/mailman/listinfo/python-list
[WSGI] Tell Python to listen to LAN interface?
Hello I'm following this tutorial to learn about writing Python apps in WSGI: http://webpython.codepoint.net/wsgi_tutorial On a Linux host with Python 2.6.6 installed, I launched the Environment dictionary sample, but can't connect to it from my remote Windows host since the application only accepts local queries: # netstat -tunlp ... tcp0 0 127.0.0.1:8051 0.0.0.0:* LISTEN 13110/python How can I tell the Python interpreter to listen on 0.0.0.0 or at least 192.168.0.0/24? Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me pick an API design (OO vs functional)
On Tuesday, March 26, 2013 1:16:56 PM UTC+1, Jean-Michel Pichavant wrote: - Original Message - notepad_1 = start(Notepad) notepad_2 = start(Notepad) notepad_1.write(Hello World!) notepad_1.press(CTRL + 'a', CTRL + 'c') notepad_2.press(CTRL + 'v') ^ | here, this is an above example :D The problem with this design is that it effectively duplicates our API: We want to keep our global functions because they are so easy to read. So is the example above. This is the best solution in my opinion. Ah, so you meant is also easy to read ;) I agree but the example with global functions is even easier to read. I guess I am being pretty anal about these issues, but I see every unnecessary syntax we can save as a win. [snip] Doesn't the IPython do auto-completion for global functions? Yes it does, but as Chris pointed out, your global/module namespace will be polluted by a lot of names. By using completion on an object, you get the method it has access to, which is very useful to narrow down what you can do with it. I see. I know you prefer design #1 but that would at least place design #4 over #3, right? Thanks. Michael www.getautoma.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me pick an API design (OO vs functional)
On 03/26/2013 08:04 AM, Michael Herrmann wrote: On Tuesday, March 26, 2013 11:26:30 AM UTC+1, Dave Angel wrote: ... Seems to me that the official interface should all be methods. However, you could have a new object which always represents the focus window. Then the USER could define trivial functions: def write(*args): focused.write(*args) It's an interesting idea. But why not give this write(...) to them in the first place? Just to be clear, I was avoiding the problem of having two ways of accessing each function, since most of us prefer the methods, and you have some users who prefer simple functions. Am I the only one who appreciates the simplicity of start(Notepad) write(Hello World!) press(CTRL + 's') write(test.txt, into=File name) click(Save) press(ALT + F4) over notepad = start(Notepad) notepad.write(Hello World!) notepad.press(CTRL + 's') notepad.write(test.txt, into=File name) notepad.click(Save) notepad.press(ALT + F4)? Somewhere in this thread you mention that save() creates a new window, so a method-oriented approach would require that the user get that window object, and call its methods rather than the original window's. I say that's a very good thing, since the things you send may very well have very different meanings to the save dialog than they do in the original one. save() is not a function, but I assume you mean the action that opens the Save dialogue (I think that'd be `press(CTRL + 's')`). You are right that it's nice for it to be explicit. However, in 95% of cases, the window you want the next action to be performed in is the window that is currently active. I appreciate the explicitness, but to force it on the user for only 5% of cases seems a bit much. Another concern I'd have is what happens if the user changes focus with his mouse? Does that change the meaning you had for focus() in the above exchange? Do you want your press() method to apply to a different window when the user changes to that window? No. Internally, we remember which window is the currently active window. If you just run a script without user-intervention, this will be the respective foreground window. If some other window is in the foreground - which most typically happens when the user is interactively entering commands one after the other, so the foreground window is the console window, we do switch to the window that's supposed to be the active one. It may sound like black magic, but it works very well in practice, and really is not too ambiguous. When you read a script like start(Notepad) write(Hello World) press(CTRL + 's') write(test.txt, into=File name) click(Save) click(Close) I hold that you intuitively know what's going on, without even thinking about window switching. Until the program you're scripting makes some minor change in its interface, or has something conditional on an attribute not intuitively obvious. Also, it seems that in this thread, we are using window both to refer to a particular application instance (like Notepad1 and Notepad2), and to refer to windows within a single application. Anyway, if you're only automating a few specific apps, you're not likely to run into the problems that methods were intended to address. After all, Notepad's bugs haven't seemed to change for a couple of decades, so why should they fix anything now? Having a selected window be an implied object for those global functions yields at least the same problems as any writable global. Multithreading, unexpected side effects from certain functions, callbacks, etc. As long as you know the program is going to be simple, pile on the globals. But as soon as it advances, each of them is a trap to fall into. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: At a loss on python scoping.
On Tue, 26 Mar 2013 14:19:21 +0800, Shiyao Ma wrote: PS, I now python's scoping rule is lexical rule (aka static rule). How does LEGB apply to class? It doesn't. Python does not use the same lookup rules for attributes and unqualified names. Attribute lookups follow inheritance rules. `instance.name` searches in this order, from first to last: if it exists, call instance.__class__.__getattribute__(name); look in the instance __dict__; look in the class __dict__; for each superclass in the inheritance chain: look in the superclass __dict__; if it exists, call instance.__class__.__getattr__(name) (the above is a little simplified, but is close enough for ordinary work). Unqualified `name` follow this lookup rule: if name is recognised by the compiler as a local name: look in the local function namespace; otherwise: look in any enclosing function scopes; look in the global scope; look in the builtins. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: [WSGI] Tell Python to listen to LAN interface?
On Tue, Mar 26, 2013 at 11:26 PM, Gilles nos...@nospam.com wrote: Hello I'm following this tutorial to learn about writing Python apps in WSGI: http://webpython.codepoint.net/wsgi_tutorial I'm guessing you're using the initialization code from here? http://webpython.codepoint.net/wsgi_environment_dictionary According to the docstring, the first argument to make_server() is the host name to bind to. Using localhost means you're bound to 127.0.0.1, as you see. Use your LAN IP address there, or to bind to all local addresses - or possibly :: to bind to all IPv6 addresses (try it and see - some systems work with one or the other, others work happily with both together). ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: [WSGI] Tell Python to listen to LAN interface?
On Tue, 26 Mar 2013 23:50:36 +1100, Chris Angelico ros...@gmail.com wrote: According to the docstring, the first argument to make_server() is the host name to bind to. Using localhost means you're bound to 127.0.0.1, as you see. Use your LAN IP address there, or to bind to all local addresses - or possibly :: to bind to all IPv6 addresses (try it and see - some systems work with one or the other, others work happily with both together). Thanks Chris. I was thinking it was due to how Python was configured, and didn't first check that it could be some instruction in the script itself. It works fine now. -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me pick an API design (OO vs functional)
On Tue, 26 Mar 2013 05:04:43 -0700, Michael Herrmann wrote: On Tuesday, March 26, 2013 11:26:30 AM UTC+1, Dave Angel wrote: ... Seems to me that the official interface should all be methods. However, you could have a new object which always represents the focus window. Then the USER could define trivial functions: def write(*args): focused.write(*args) It's an interesting idea. But why not give this write(...) to them in the first place? Am I the only one who appreciates the simplicity of start(Notepad) write(Hello World!) press(CTRL + 's') write(test.txt, into=File name) click(Save) press(ALT + F4) over notepad = start(Notepad) notepad.write(Hello World!) notepad.press(CTRL + 's') notepad.write(test.txt, into=File name) notepad.click(Save) notepad.press(ALT + F4)? You are not the only one. I suggest that you have a set of functions that work on the current window, whatever that is. Preferably there should always be a current window, but if not, ensure that you give a clear error message. Then you have syntax for operating on any named(?) window. So a user can implicitly operate on the current window: select(notepad) write(goodbye cruel world) save() or explicitly on any window they like: excel.quit() I suggest you dig up an old book on Hypercard, for Apple Macs in the 1980s and 90s. Back in the day, Macs could only run a single application at a time, and Hypercard was limited to a single window at a time (called a stack). But that stack (think: window) could have multiple cards (think: window tabs), one of which was always current. Hypercard's built-in programming language Hypertalk let you do things like this: go to stack Notepad type goodbye cruel world in field main of card 7 click button Save click button Quit of card Main of stack Excel (more or less... it's been a few years since I've had a classic Mac capable of running Hypercard.) -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
In article 51512bb5$0$29973$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Mon, 25 Mar 2013 20:55:03 -0400, Roy Smith wrote: In article 5150e900$0$29998$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Also, speaking as somebody who remembers a time when ints where not automatically promoted to longs (introduced in, Python 2.2, I think?) let me say that having a single unified int type is *fantastic*, And incredibly useful when solving Project Euler problems :-) [I remember when strings didn't have methods] No string methods? You were lucky. When I were a lad, you couldn't even use delimiters for strings. b string Parsing error: file stdin, line 1: b string ^ Unhandled exception: run-time error: syntax error Python 0.9.1. OK, you've got me beat. For Python. Am I going to have to go dig out my old IBM-1130 assembler decks? -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me pick an API design (OO vs functional)
On 03/26/2013 05:38 AM, Michael Herrmann wrote: On Tuesday, March 26, 2013 12:40:45 AM UTC+1, Mitya Sirenef wrote: ... I think I would prefer context managers. I don't think it's a big problem for win users because this behaviour would be one of the first things documented in the start guide and would be all over example scripts, so a new user missing or forgetting it is not a realistic scenario. The advantages are that it's explicit, blocks are indented and it's impossible to miss which window is the action applied to, and at the same time actions are short and easy to type and read. Thank you for your reply. What do you think of Chris Angelico's points? At the __exit__, further commands are no longer routed to that window; if it was a nested context, window is switched to the outer context, WHEN there are commands in it (i.e. on the first command). This seems pretty intuitive to me: with notepad1: ^S with notepad2: ^S write('something') He wrote: What happens at the __exit__ of the context manager? What happens if context managers are nested? I'd be inclined to the simpler option of an explicit switch (since focus doesn't really stack and it'd feel weird for focus to *sometimes* switch away when you're done working with one window), though the context manager syntax does have its advantages too. What I am most afraid of: that the window that's currently the context disappears: notepad = start(Notepad) with notepad: press(ALT + TAB) write(Am I in Notepad now?) Alt-tab needs to be handled by a wrapper function that gives you the object of the window you've switched to: otherwin = alt_tab() with otherwin: ... If window is changed within 'with' block, the rest of block should be ignored. Perhaps there could also be a way to switch this behaviour off, for the entire script or for current block only. What do you think of designs #3 and #4? notepad_1 = start(Notepad) notepad_2 = start(Notepad) switch_to(notepad_1) write(Hello World!) press(CTRL + 'a', CTRL + 'c') switch_to(notepad_2) press(CTRL + 'v') notepad_1 = start(Notepad) notepad_2 = start(Notepad) notepad_1.activate() write(Hello World!) press(CTRL + 'a', CTRL + 'c') notepad_2.activate() press(CTRL + 'v') I somehow prefer activate over focus as in my feeling, you'd normally say that you focus *on* something, so it should be called focus_on or give_focus[_to]. Can you say, in everyday English, that you focus a window? I'm not a native speaker so maybe my feeling is misguided. These are ok, too, but I feel it's much easier to send commands to a wrong window vs. context managers. The same command in a different window can have vastly different and dangerous effect. In other python code that's generally not common at all, and would be bad style: lst = lst1 lst.append('x') del lst[3] lst.insert(0, 'a') lst = lst2 del lst[2] lst.append('y') lst = lst3 lst.insert(0, 'x') lst += [1,2] I think current window should also be acquired explicitly: with get_current_window(): type(some kind of snippet) For usage when a command should apply to all types of windows. HTH, -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ Food is an important part of a balanced diet. Fran Lebowitz -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
Chris Angelico wrote: Interesting, so your 3.x sum() is optimizing something somewhere. Strange. Are we both running the same Python ? I got those from apt-get I also installed python here under Debian Wheezy via apt-get and our versions look to be the same -sk- 2.7.3 (default, Jan 2 2013, 16:53:07) [GCC 4.7.2] 3.2.3 (default, Feb 20 2013, 17:02:41) [GCC 4.7.2] CPU : Intel(R) Celeron(R) D CPU 3.33GHz -ca- 2.7.3 (default, Jan 2 2013, 13:56:14) [GCC 4.7.2] 3.2.3 (default, Feb 20 2013, 14:44:27) [GCC 4.7.2] CPU : ??? Could differences in underlying CPU architecture lead to our differing python integer results ? -- Stanley C. Kitching Human Being Phoenix, Arizona -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On Wed, Mar 27, 2013 at 12:38 AM, Cousin Stanley cousinstan...@gmail.com wrote: Chris Angelico wrote: Interesting, so your 3.x sum() is optimizing something somewhere. Strange. Are we both running the same Python ? I got those from apt-get I also installed python here under Debian Wheezy via apt-get and our versions look to be the same -sk- 2.7.3 (default, Jan 2 2013, 16:53:07) [GCC 4.7.2] 3.2.3 (default, Feb 20 2013, 17:02:41) [GCC 4.7.2] CPU : Intel(R) Celeron(R) D CPU 3.33GHz -ca- 2.7.3 (default, Jan 2 2013, 13:56:14) [GCC 4.7.2] 3.2.3 (default, Feb 20 2013, 14:44:27) [GCC 4.7.2] CPU : ??? Could differences in underlying CPU architecture lead to our differing python integer results ? Doubtful. I have Intel(R) Core(TM) i5-2500 CPU @ 3.30GHz quad-core with hyperthreading, but I'm only using one core for this job. I've run the tests several times and each time, Py2 is a shade under two seconds for inline/range_sum, and Py3 is about 2.5 seconds for each. Fascinating. Just for curiosity's sake, I spun up the tests on my reiplophobic server, still running Ubuntu Karmic. Pentium(R) Dual-Core CPU E6500 @ 2.93GHz. gideon@gideon:~$ python inttime.py 2.6.4 (r264:75706, Dec 7 2009, 18:45:15) [GCC 4.4.1] inline: 2147450880 2.7050409317 range_sum: 2147450880 2.64918494225 forloop: 2147450880 6.58765792847 forloop_offset: 2147450880L 16.5167789459 gideon@gideon:~$ python3 inttime.py 3.1.1+ (r311:74480, Nov 2 2009, 14:49:22) [GCC 4.4.1] inline: 2147450880 4.44533085823 range_sum: 2147450880 4.37314105034 forloop: 2147450880 12.4834370613 forloop_offset: 2147450880 13.5000522137 Once again, Py3 is slower on small integers than Py2. So where's the difference with your system? This is really weird! I assume you can repeat the tests and get the same result every time? ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me pick an API design (OO vs functional)
On 2013-03-25, Mitya Sirenef msire...@lightbird.net wrote: I think I would prefer context managers. I don't think it's a big problem for win users because this behaviour would be one of the first things documented in the start guide and would be all over example scripts, so a new user missing or forgetting it is not a realistic scenario. If window focus switching is really a rarity, and only done briefly then I agree that a context manager makes a nice and neat solution. But it's too powerful a generalisation for such a small corner case. Have you considered adding a keyword argument to each of your global functions, which is normally None, but allows a user to provide a prefered focus window? enter_text(test.txt, focus=save_dialog) press_button(Savebutton, focus=save_dialog) (Those are just guesses at your API functions; sorry.) When focus remains None, your usual assumptions about focus would apply, otherwise the user preference overrides it. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
Is it me or is the python-vobject documentation rather lacking?
I'm trying to use the python vobject package instead of what I use at the moment (the icalendar package) because it's more widely supported and available from my Linux repository. However I'm having a really hard time actually working out how to use it. The 'Usage examples' at http://vobject.skyhouseconsulting.com/usage.html have very little about parsing existing .ics files and say More examples can be found in source code doctests. I can't find those examples at all. The only test code I can see comprises direct data entry using the python interpreter directly and is just a mess. I can open a .ics file and vobject parses it:- f = open(orage.ics) p = vobject.readOne(f) p.vevent.dtstart.value datetime.date(2012, 3, 16) ... but then I need to know how to iterate through the .ics file and how to get all the other fields out of an event entry. Can anyone point me at some examples that do something rather more extensive than the above example? Alternatively where do I find how to extract other fields from a vevent as values like vevent.dtstart.value? These don't seem to be documented anywhere obvious in http://vobject.skyhouseconsulting.com/epydoc/. -- Chris Green -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me pick an API design (OO vs functional)
On Tuesday, March 26, 2013 1:59:58 PM UTC+1, Steven D'Aprano wrote: On Tue, 26 Mar 2013 05:04:43 -0700, Michael Herrmann wrote: ... Am I the only one who appreciates the simplicity of start(Notepad) write(Hello World!) press(CTRL + 's') write(test.txt, into=File name) click(Save) press(ALT + F4) over notepad = start(Notepad) notepad.write(Hello World!) notepad.press(CTRL + 's') notepad.write(test.txt, into=File name) notepad.click(Save) notepad.press(ALT + F4)? You are not the only one. I suggest that you have a set of functions that work on the current window, whatever that is. Preferably there should always be a current window, but if not, ensure that you give a clear error message. This is exactly the way it is currently. I am glad you also see it that way. Then you have syntax for operating on any named(?) window. So a user can implicitly operate on the current window: select(notepad) write(goodbye cruel world) save() One idea would be to use the Window(...) constructor to select windows: notepad = Window('Untitled - Notepad') select(notepad) save() One advantage of using a global method to switch to a window is that this would allow you to directly switch to a Window without having to call Window(...): switch_to('Untitled - Notepad') I'm still not fully convinced of a global method though, for the reasons several people here have already mentioned. or explicitly on any window they like: excel.quit() This example makes it look likely that there will have to be other operations that can be performed on windows (/running applications as Dave pointed out). So, a 'quit()' method that closes a window in addition to the already mentioned focus/select/activate method. This in turn makes the global function less attractive as once we start going down that route, global functions will proliferate. I suggest you dig up an old book on Hypercard, for Apple Macs in the 1980s and 90s. Back in the day, Macs could only run a single application at a time, and Hypercard was limited to a single window at a time (called a stack). But that stack (think: window) could have multiple cards (think: window tabs), one of which was always current. Hypercard's built-in programming language Hypertalk let you do things like this: go to stack Notepad type goodbye cruel world in field main of card 7 click button Save click button Quit of card Main of stack Excel (more or less... it's been a few years since I've had a classic Mac capable of running Hypercard.) Very interesting. I had never heard of HyperCard. I read up on it a little and it sounds very similar to the model we are internally building of open applications (stacks) and their windows (cards). Also funny that HyperCard was one of Ward Cunningham's inspirations for coming up with the Wiki idea: http://c2.com/cgi/wiki?WikiWikiHyperCard Thanks for this! Michael www.getautoma.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me pick an API design (OO vs functional)
On Tuesday, March 26, 2013 1:42:26 PM UTC+1, Dave Angel wrote: ... Also, it seems that in this thread, we are using window both to refer to a particular application instance (like Notepad1 and Notepad2), and to refer to windows within a single application. Anyway, if you're only automating a few specific apps, you're not likely to run into the problems that methods were intended to address. After all, Notepad's bugs haven't seemed to change for a couple of decades, so why should they fix anything now? Having a selected window be an implied object for those global functions yields at least the same problems as any writable global. Multithreading, unexpected side effects from certain functions, callbacks, etc. As long as you know the program is going to be simple, pile on the globals. But as soon as it advances, each of them is a trap to fall into. You're right with everything you say. globals are bad and it may happen that this will bite me. I'm just not sure whether we should sacrifice the simpler syntax useful in say 80% of cases for something I'm not yet sure will ever become a real problem. -- http://mail.python.org/mailman/listinfo/python-list
Re: Processing user input as it's entered
On 26 March 2013 10:07, Sven sven...@gmail.com wrote: Hello, Is there a way (ideally cross platform but a *nix OS solution would be great) to process user input as they type? What I aim to achieve is to count the number of characters a user has entered and display it while they are typing. The entered text will also need to be captured once the user has finished typing. This is a gui-less CLI tool for python 2.7 I've seen some information on tty.setraw but I'm not sure how you'd go about wiring that up. Can you use curses (http://docs.python.org/2/library/curses.html) -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me pick an API design (OO vs functional)
On Tuesday, March 26, 2013 3:13:30 PM UTC+1, Neil Cerutti wrote: On 2013-03-25, Mitya Sirenef wrote: I think I would prefer context managers. I don't think it's a big problem for win users because this behaviour would be one of the first things documented in the start guide and would be all over example scripts, so a new user missing or forgetting it is not a realistic scenario. If window focus switching is really a rarity, and only done briefly then I agree that a context manager makes a nice and neat solution. But it's too powerful a generalisation for such a small corner case. Have you considered adding a keyword argument to each of your global functions, which is normally None, but allows a user to provide a prefered focus window? enter_text(test.txt, focus=save_dialog) press_button(Savebutton, focus=save_dialog) It's an interesting new idea but I somehow feel it makes the existing functions too complicated. Also, having to add it to all existing, and future functions sounds a bit too cumbersome to me. (Those are just guesses at your API functions; sorry.) No worries! Thank you for your suggestion! Michael www.getautoma.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me pick an API design (OO vs functional)
On Tuesday, March 26, 2013 2:41:38 PM UTC+1, Mitya Sirenef wrote: ... At the __exit__, further commands are no longer routed to that window; if it was a nested context, window is switched to the outer context, WHEN there are commands in it (i.e. on the first command). This seems pretty intuitive to me: with notepad1: ^S with notepad2: ^S write('something') ... What I am most afraid of: that the window that's currently the context disappears: notepad = start(Notepad) with notepad: press(ALT + TAB) write(Am I in Notepad now?) Alt-tab needs to be handled by a wrapper function that gives you the object of the window you've switched to: otherwin = alt_tab() with otherwin: ... If window is changed within 'with' block, the rest of block should be ignored. Perhaps there could also be a way to switch this behaviour off, for the entire script or for current block only. What do you think of designs #3 and #4? ... These are ok, too, but I feel it's much easier to send commands to a wrong window vs. context managers. The same command in a different window can have vastly different and dangerous effect. In other python code that's generally not common at all, and would be bad style: lst = lst1 lst.append('x') del lst[3] lst.insert(0, 'a') lst = lst2 del lst[2] lst.append('y') lst = lst3 lst.insert(0, 'x') lst += [1,2] I think current window should also be acquired explicitly: with get_current_window(): type(some kind of snippet) For usage when a command should apply to all types of windows. I was skeptical of your suggestion at first but trying it out on an example script made me see its appeal: notepad_main = start(Notepad) with notepad_main: write(Hello World!) save_dialogue = press(CTRL + 's') with save_dialogue: write(test.txt, into=File name) click(Save) click(Close) Forcing the library user to always use the with ... seems like overkill though. I think the gained precision does not justify this burden on the library user. Hm -- http://mail.python.org/mailman/listinfo/python-list
Re: python3 string format
On Tue, Mar 26, 2013 at 4:51 AM, Shiyao Ma i...@introo.me wrote: Thx for your reply. I am using pycharm and simply press go to declaration which directs me to a py file, containing the following code: def format(*args, **kwargs): # known special case of str.format S.format(*args, **kwargs) - string Return a formatted version of S, using substitutions from args and kwargs. The substitutions are identified by braces ('{' and '}'). pass I would guess that Python declaration is maintained and used by PyCharm for code intelligence. I am curious how you find the corresponding c source code. The str object is mostly implemented in Objects/unicodeobject.c. The int object is mostly implemented in Objects/longobject.c. Other built-in types can also be found in that directory. Each has a PyMethodDef[] global array that declares the implementations of the object's methods. Finding the implementation is then just a matter of grepping the source for its name. The function I pointed you to before implements the str.__format__ method. The str.format method itself is at: http://hg.python.org/cpython/file/84e73ace3d7e/Objects/stringlib/unicode_format.h#l942 I'm not sure why that one is implemented in a .h file. -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me pick an API design (OO vs functional)
On Wed, Mar 27, 2013 at 1:59 AM, Michael Herrmann michael.herrm...@getautoma.com wrote: save_dialogue = press(CTRL + 's') Does every single API need to then consider the possibility of focus changing? How does the press() function know that this will (or might - if the file's already been named, Ctrl-S won't open a dlg) change focus? How does the caller know? ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Processing user input as it's entered
On 26 March 2013 14:41, Arnaud Delobelle arno...@gmail.com wrote: On 26 March 2013 10:07, Sven sven...@gmail.com wrote: Hello, Is there a way (ideally cross platform but a *nix OS solution would be great) to process user input as they type? What I aim to achieve is to count the number of characters a user has entered and display it while they are typing. The entered text will also need to be captured once the user has finished typing. This is a gui-less CLI tool for python 2.7 I've seen some information on tty.setraw but I'm not sure how you'd go about wiring that up. Can you use curses (http://docs.python.org/2/library/curses.html This could work. I've not used it before so I am having some issues echoing out the text. I assume I can use this without having to create an ncurses UI? -- ./Sven -- http://mail.python.org/mailman/listinfo/python-list
Re: import in Python3.3
On Tuesday, March 26, 2013 3:04:44 AM UTC-4, Terry Reedy wrote: On 3/24/2013 7:12 PM, Fabian von Romberg wrote: Hi, I have a package name collections and inside of my package I want to import the collections package from the standard library, but there is name conflicts. Yes. I strongly advise against trying to do this. How do I import explicitly from the standard library? Manipulate sys.path. This is a common suggestion for working *around* the issue, but it has problems of its own. In my opinion using sys.path is clunky - you may want to save an restore the value around use especially if the the place you are using it is not at the top level but in some inner less-exposed sub module. And make sure to restore sys.path in the presence of exceptions getting thrown somewhere inside the import. It is also a bit of a security nightmare. If something evil gets injected in there what does it effect and how would you know it? sys.path provides a series of directories where and evil masquerading Python program can linger. And again, I get the impression that for the use case asked about, there isn't much ambiguity. If I am in mypackage.foo and I want to access mypackage.collections I should be able to say something like that without ambiguity or that much inference or directory searching. If mypackage.colletions is not found inside the same directory as mypackage.foo, often I DON'T WANT Python to helpfully go searching around other places for it which sys.path will do. Instead what I probably want is Python to give me an error. So again I come to import_relative, http://code.google.com/p/pyimport-relative/. And again, I wish this package didn't have to exist. If you don't know how, either read about sys.path (see index) or don't do it. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
I need a neat way to print nothing or a number
What's a neat way to print columns of numbers with blanks where a number is zero or None? E.g. I want to output something like:- Credit Debit Description 100.00 Initial balance 123.45 Payment for cabbages 202.00 Telephone bill For each line I have either the credit or the debit amount and the other is 0 or None. However you can't get number formatting (old or new) to output a blank for 0 and it barfs on None. -- Chris Green -- http://mail.python.org/mailman/listinfo/python-list
Re: I need a neat way to print nothing or a number
On Wed, Mar 27, 2013 at 2:50 AM, c...@isbd.net wrote: What's a neat way to print columns of numbers with blanks where a number is zero or None? E.g. I want to output something like:- Credit Debit Description 100.00 Initial balance 123.45 Payment for cabbages 202.00 Telephone bill For each line I have either the credit or the debit amount and the other is 0 or None. However you can't get number formatting (old or new) to output a blank for 0 and it barfs on None. Try printing out this expression: %.2f%value if value else '' Without the rest of your code I can't tell you how to plug that in, but a ternary expression is a good fit here. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Simple example of how to use importlib to create a loader
I'm trying to write my own loader using importlib. And frankly, I'm getting nowhere. I'm struggling to understand precisely which methods of the various ABCs I need to implement, and in some cases what they should do. Could anyone point me to a simple example (say, something that implements zip imports using the zipfile module - that was what I initially tried to get working as a proof of concept). Where I've got to is the following stub implementation to try to log the sequence of calls: from importlib.abc import PathEntryFinder, SourceLoader class MyFinder(PathEntryFinder): def __init__(self, pathentry): Create a finder for the given `pathentry` if pathentry == 'foo': return raise ImportError def find_loader(self, fullname): Return a loader for the module `fullname` print(find_loader('{}').format(fullname)) return MyLoader(), ['foo'] class MyLoader(SourceLoader): def module_repr(self): print(module_repr()) return True def is_package(self, fullname): print(is_package('{}').format(fullname)) return True def get_data(self, path): Return an open binary file object for `path` print(get_data('{}').format(path)) return bprint('hello from foo!') def get_filename(self, fullname): Return the filename for module `fullname` print(get_filename('{}').format(fullname)) return '/this/is/foo' if __name__ == '__main__': import sys sys.path_hooks.append(lambda p: MyFinder(p)) sys.path.insert(0, 'foo') import a import a.b from a.b.c import x It prints out py .\loader.py find_loader('a') is_package('a') get_filename('a') get_data('/this/is/foo') get_filename('a') is_package('a') hello from foo! Traceback (most recent call last): File .\loader.py, line 46, in module import a.b ImportError: No module named 'a.b' which is a good start, but I don't know why it isn't willing to check for 'a.b' (after all, I tell it that 'a' is a package). I'm quite probably doing something trivially wrong here - after all, I'm not even *trying* to implement a sane view of a package structure here. But I'd have expected at least a find_loader('a.b') call... Thanks for any help, Paul. -- http://mail.python.org/mailman/listinfo/python-list
Re: I need a neat way to print nothing or a number
In jms82a-6sl@chris.zbmc.eu c...@isbd.net writes: What's a neat way to print columns of numbers with blanks where a number is zero or None? print number or ' ' -- John Gordon A is for Amy, who fell down the stairs gor...@panix.com B is for Basil, assaulted by bears -- Edward Gorey, The Gashlycrumb Tinies -- http://mail.python.org/mailman/listinfo/python-list
Samsung Galaxy Mini
Samsung Galaxy Mini http://natigtas7ab.blogspot.com/2012/10/samsung-galaxy-mini.html -- http://mail.python.org/mailman/listinfo/python-list
Re: import in Python3.3
On Mon, Mar 25, 2013 at 11:49 PM, rocky ro...@gnu.org wrote: On Sun, 24 Mar 2013 18:12:49 -0500, Fabian von Romberg wrote: I have a package name collections and inside of my package I want to I find this kind of thing sad: it feels to me that programmers are working around somewhat arbitrary and changing restrictions. Rather than avoid names like collections, why not try to address the underlying problem? There isn't an ambiguity here in my view: the fullname is mypackage.collections You've said a couple of times now that the original author has a package named mypackage with a module collections in it. As far as I can tell, that's untrue. The original post claims to have a package named collections, which is colliding with the builtin module of the same name. As far as I can tell, all of your suggestions about using your pyimport-relative tool aren't helpful unless the author re-names his package from collections to mypackage and then moves all of their code into a collections module inside mypackage, right? -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me pick an API design (OO vs functional)
On 03/26/2013 10:40 AM, Michael Herrmann wrote: On Tuesday, March 26, 2013 3:13:30 PM UTC+1, Neil Cerutti wrote: SNIP Have you considered adding a keyword argument to each of your global functions, which is normally None, but allows a user to provide a prefered focus window? enter_text(test.txt, focus=save_dialog) press_button(Savebutton, focus=save_dialog) It's an interesting new idea but I somehow feel it makes the existing functions too complicated. Also, having to add it to all existing, and future functions sounds a bit too cumbersome to me. Perhaps Neil didn't make it clear enough. I figure he meant a keyword argument with an explicit default value of None. (or if you followed my earlier discussion, default value of focused) That way your user can keep using the functions for when there's no ambiguity, but add a focus= parameter only when needed. To go back to my sample wrapper functions, they'd look something like (untested): def write(*args, focus=focused): focus.write(*args) Of course, the user should only use the wrappers when things are sure to remain simple. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
Chris Angelico wrote: Once again, Py3 is slower on small integers than Py2. Chris Angelico Ubuntu Karmic. Pentium(R) Dual-Core CPU E6500 @ 2.93GHz. python inline range_sum forloop forloop_offset 2.6.4 2.7050 2.6492 6.5877 16.5168 3.1.1 4.4453 4.3731 12.4834 13.5001 You do seem to have a slight py3 improvement under ubuntu for the forloop_offset case So where's the difference with your system ? CPU This is really weird ! Yep ... I assume you can repeat the tests and get the same result every time ? Yes First lines of numbers below are from yesterday while second lines are from today Stanley C. Kitching Debian Wheezy Intel(R) Celeron(R) D CPU 3.33GH Single Core python inline range_sum forloop forloop_offset 2.7.3 3.1359 3.0725 9.0778 15.6475 2.7.3 3.0382 3.1452 9.8799 16.8579 3.2.3 2.8226 2.807413.47624 13.6430 3.2.3 2.8331 2.822813.54151 13.8716 -- Stanley C. Kitching Human Being Phoenix, Arizona -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On Wed, Mar 27, 2013 at 3:41 AM, Cousin Stanley cousinstan...@gmail.com wrote: Chris Angelico wrote: Once again, Py3 is slower on small integers than Py2. Chris Angelico Ubuntu Karmic. Pentium(R) Dual-Core CPU E6500 @ 2.93GHz. python inline range_sum forloop forloop_offset 2.6.4 2.7050 2.6492 6.5877 16.5168 3.1.1 4.4453 4.3731 12.4834 13.5001 You do seem to have a slight py3 improvement under ubuntu for the forloop_offset case Yes, that's correct. The forloop_offset one is using long integers in all cases. (Well, on Py2 it's adding a series of ints to a long, but the arithmetic always has to be done with longs.) Python 3 has had some improvements done, but the main thing is that there's a massive spike in the Py2 time, while Py3 has _already paid_ that cost - as evidenced by the closeness of the forloop and forloop_offset times on Py3. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: I need a neat way to print nothing or a number
Chris Angelico rosuav at gmail.com writes: Try printing out this expression: %.2f%value if value else '' Without the rest of your code I can't tell you how to plug that in, but a ternary expression is a good fit here. ChrisA Unfortunately, that's not working, but gives a TypeError: a float is required when the first value evaluates to False. Apparently it's not that easy to combine number formatting with logical operators - the same happens with my idea ('{:.2f}').format(value or ''). Wolfgang -- http://mail.python.org/mailman/listinfo/python-list
Help with zip in a Python exercise
I've been working through a Python tutorial online and one of the exercises uses the zip command. The only problem is that the command doesn't work. I've read through the man page for zip and it looks like what I'm attempting should work, but it doesn't. The command is: zip -qr /media/backup/backups/test/20130326100218.zip -i /home/luggw1/Documents/ /home/luggw1/Code/ The error it produces is: zip error: Invalid command arguments (nothing to select from) Can anybody point out the error of my ways? Thanks. Bill Lugg -- http://mail.python.org/mailman/listinfo/python-list
Re: I need a neat way to print nothing or a number
On Wed, Mar 27, 2013 at 4:06 AM, Wolfgang Maier wolfgang.ma...@biologie.uni-freiburg.de wrote: Chris Angelico rosuav at gmail.com writes: Try printing out this expression: %.2f%value if value else '' Without the rest of your code I can't tell you how to plug that in, but a ternary expression is a good fit here. ChrisA Unfortunately, that's not working, but gives a TypeError: a float is required when the first value evaluates to False. Apparently it's not that easy to combine number formatting with logical operators - the same happens with my idea ('{:.2f}').format(value or ''). Really? Works for me in 3.3: value=1.2 %.2f%value if value else '' '1.20' value=0 %.2f%value if value else '' '' value=None %.2f%value if value else '' '' What's the full context? The way I've written the expression, it's guaranteed to return a string (either %.2f5value or the literal '', and yes, I'm aware that I was inconsistent with the quotes). I tried it in 2.6 and it worked there, too. Now, if you parenthesize the bit after the percent sign, the TypeError comes up. But that wasn't the intention of the code (and value if value else something-else is just value or something-else, anyway). ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: I need a neat way to print nothing or a number
Wolfgang Maier wrote: Chris Angelico rosuav at gmail.com writes: Try printing out this expression: %.2f%value if value else '' Without the rest of your code I can't tell you how to plug that in, but a ternary expression is a good fit here. ChrisA Unfortunately, that's not working, but gives a TypeError: a float is required when the first value evaluates to False. Apparently it's not that easy to combine number formatting with logical operators - the same happens with my idea ('{:.2f}').format(value or ''). Here's a round-about way: class Prepare: def __init__(self, value): self.value = value def __format__(self, spec): if self.value is None or self.value == 0: return format(0.0, spec).replace(., ).replace(0, ) elif isinstance(self.value, str): return self.value.rjust(len(format(0.0, spec))) return format(self.value, spec) def prepare(row): return map(Prepare, row) data = [ (Credit, Debit, Description), (100, 0, Initial balance), (123.45, None, Payment for cabbages), (0.0, 202.0, Telephone bill), ] for row in data: print({:10.2f} {:10.2f} {}.format(*prepare(row))) -- http://mail.python.org/mailman/listinfo/python-list
problem with sys import argv
hi python community, i wrote the following programm: from sys import argv script, userName = argv prompt = ' ' print 'hi %s, i am the %s script' % (userName, script) print i'd like to ask you a few questions. print 'do you like me %s' % userName likes = raw_input(prompt) print where do you live %s? % userName lives = raw_input(prompt) print 'what kind of computer do you have?' computer = raw_input(prompt) print alright so you said %r about liking me. you live in %r. not sure where that is. and you have a %r computer. nice % (likes, lives, computer) and i got the following error: Traceback (most recent call last): File /var/folders/89/84z7tw3d3rv39gny3n2p963mgn/T/pythonInTerm.GUF6PWCM, line 3, in module script, userName = argv ValueError: need more than 1 value to unpack what can i do? thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with zip in a Python exercise
On Tue, Mar 26, 2013 at 1:06 PM, lug...@elpasotel.net wrote: I've been working through a Python tutorial online and one of the exercises uses the zip command. The only problem is that the command doesn't work. I've read through the man page for zip and it looks like what I'm attempting should work, but it doesn't. The command is: zip -qr /media/backup/backups/test/20130326100218.zip -i /home/luggw1/Documents/ /home/luggw1/Code/ The error it produces is: zip error: Invalid command arguments (nothing to select from) Can anybody point out the error of my ways? Not sure what os you are using. If linux, then the zip command looks odd. -q is quiet mode, you might want to remove that til it works. Also not sure your -i is set up propery. Try to google zip tutorial as this isn't a python question at all Thanks. Bill Lugg -- http://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: I need a neat way to print nothing or a number
On 03/26/2013 10:06 AM, Wolfgang Maier wrote: Chris Angelico rosuav at gmail.com writes: Try printing out this expression: %.2f%value if value else '' Without the rest of your code I can't tell you how to plug that in, but a ternary expression is a good fit here. ChrisA Unfortunately, that's not working, but gives a TypeError: a float is required when the first value evaluates to False. Apparently it's not that easy to combine number formatting with logical operators - the same happens with my idea ('{:.2f}').format(value or ''). Use parens then: (%.2f % value) if value else '' -- ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: problem with sys import argv
On 26/03/2013 17:26, leonardo selmi wrote: hi python community, i wrote the following programm: from sys import argv script, userName = argv prompt = ' ' print 'hi %s, i am the %s script' % (userName, script) print i'd like to ask you a few questions. print 'do you like me %s' % userName likes = raw_input(prompt) print where do you live %s? % userName lives = raw_input(prompt) print 'what kind of computer do you have?' computer = raw_input(prompt) print alright so you said %r about liking me. you live in %r. not sure where that is. and you have a %r computer. nice % (likes, lives, computer) and i got the following error: Traceback (most recent call last): File /var/folders/89/84z7tw3d3rv39gny3n2p963mgn/T/pythonInTerm.GUF6PWCM, line 3, in module script, userName = argv ValueError: need more than 1 value to unpack what can i do? thanks! Write some error handling to allow for the script being run without the user name. -- If you're using GoogleCrap™ please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me pick an API design (OO vs functional)
On 2013-03-26, Dave Angel da...@davea.name wrote: On 03/26/2013 10:40 AM, Michael Herrmann wrote: On Tuesday, March 26, 2013 3:13:30 PM UTC+1, Neil Cerutti wrote: SNIP Have you considered adding a keyword argument to each of your global functions, which is normally None, but allows a user to provide a prefered focus window? enter_text(test.txt, focus=save_dialog) press_button(Savebutton, focus=save_dialog) It's an interesting new idea but I somehow feel it makes the existing functions too complicated. Also, having to add it to all existing, and future functions sounds a bit too cumbersome to me. Perhaps Neil didn't make it clear enough. I figure he meant a keyword argument with an explicit default value of None. (or if you followed my earlier discussion, default value of focused) That way your user can keep using the functions for when there's no ambiguity, but add a focus= parameter only when needed. To go back to my sample wrapper functions, they'd look something like (untested): def write(*args, focus=focused): focus.write(*args) Of course, the user should only use the wrappers when things are sure to remain simple. Yes, along those lines. Most code would never need to provide the focus= keyword. Only when setting focus in a weird way would it be needed. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
Re: problem with sys import argv
On 03/26/2013 01:26 PM, leonardo selmi wrote: hi python community, i wrote the following programm: from sys import argv script, userName = argv prompt = ' ' print 'hi %s, i am the %s script' % (userName, script) print i'd like to ask you a few questions. print 'do you like me %s' % userName likes = raw_input(prompt) print where do you live %s? % userName lives = raw_input(prompt) print 'what kind of computer do you have?' computer = raw_input(prompt) print alright so you said %r about liking me. you live in %r. not sure where that is. and you have a %r computer. nice % (likes, lives, computer) and i got the following error: Traceback (most recent call last): File /var/folders/89/84z7tw3d3rv39gny3n2p963mgn/T/pythonInTerm.GUF6PWCM, line 3, in module script, userName = argv ValueError: need more than 1 value to unpack what can i do? thanks! Since the script takes a mandatory argument, run it with one. python myscript.py Dave Better would be to change the script to check len(argv) for exactly 2, and tell the user how he should have run it. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: How to define exec method on a class object? Get syntax error due to built in command
On Monday, March 25, 2013 4:28:34 PM UTC-4, Kyle wrote: I am using swig to generate our CLI for TCL and Python. In this CLI, we have a subcommand exec that is failing to compile in the python case. There seems to be some built-in python command exec which is giving a syntax error in the .py file generated by swig when I try to import it: def exec(*args): return _wbt_daemon.dm_cli_exec(*args) ^ SyntaxError: invalid syntax I don't really want to change the CLI commands or make them different between languages. Is there any way to define a method called exec on a class? It would be executed as obj.exec() so I don't see why it should conflict with the built in exec command. class dm_cli(_object): __swig_setmethods__ = {} __setattr__ = lambda self, name, value: _swig_setattr(self, dm_cli, name, value) __swig_getmethods__ = {} __getattr__ = lambda self, name: _swig_getattr(self, dm_cli, name) def __init__(self): raise RuntimeError, No constructor defined ... def exec(*args): return _wbt_daemon.dm_cli_exec(*args) ... } Thanks for the suggestion. Looks like we currently use 2.3.4. This still wouldn't solve the problem because now the user would need to call something like getattr(wbt, exec)(args) instead of wbt.exec(args) like all the other commands. I think the easiest thing for me to do would be to just change the command name from exec to something else. -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On 3/26/2013 12:41 PM, Cousin Stanley wrote: So where's the difference with your system ? CPU Compilers and compiler settings can also make a difference. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: import in Python3.3
On Tuesday, March 26, 2013 12:33:54 PM UTC-4, Jerry Hill wrote: On Mon, Mar 25, 2013 at 11:49 PM, rocky wrote: On Sun, 24 Mar 2013 18:12:49 -0500, Fabian von Romberg wrote: I have a package name collections and inside of my package I want to I find this kind of thing sad: it feels to me that programmers are working around somewhat arbitrary and changing restrictions. Rather than avoid names like collections, why not try to address the underlying problem? There isn't an ambiguity here in my view: the fullname is mypackage.collections You've said a couple of times now that the original author has a package named mypackage with a module collections in it. As far as I can tell, that's untrue. The original post claims to have a package named collections, which is colliding with the builtin module of the same name. As far as I can tell, all of your suggestions about using your pyimport-relative tool aren't helpful unless the author re-names his package from collections to mypackage and then moves all of their code into a collections module inside mypackage, right? Right. Perhaps then I misunderstand. Having a package called collections when there is something out there already called collections clearly ill advised. But in that case, using sys.path to get around this is still a bad idea: the clash should be fixed. Sure, only in the case that this really can't be addressed would I use sys.path. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: How to define exec method on a class object? Get syntax error due to built in command
On 03/26/2013 11:13 AM, Kyle wrote: On Monday, March 25, 2013 4:28:34 PM UTC-4, Kyle wrote: I am using swig to generate our CLI for TCL and Python. In this CLI, we have a subcommand exec that is failing to compile in the python case. There seems to be some built-in python command exec which is giving a syntax error in the .py file generated by swig when I try to import it: def exec(*args): return _wbt_daemon.dm_cli_exec(*args) ^ SyntaxError: invalid syntax I don't really want to change the CLI commands or make them different between languages. Is there any way to define a method called exec on a class? It would be executed as obj.exec() so I don't see why it should conflict with the built in exec command. class dm_cli(_object): __swig_setmethods__ = {} __setattr__ = lambda self, name, value: _swig_setattr(self, dm_cli, name, value) __swig_getmethods__ = {} __getattr__ = lambda self, name: _swig_getattr(self, dm_cli, name) def __init__(self): raise RuntimeError, No constructor defined ... def exec(*args): return _wbt_daemon.dm_cli_exec(*args) ... } Thanks for the suggestion. Looks like we currently use 2.3.4. This still wouldn't solve the problem because now the user would need to call something like getattr(wbt, exec)(args) instead of wbt.exec(args) like all the other commands. I think the easiest thing for me to do would be to just change the command name from exec to something else. Yeah, that's unfortunate. I suggest 'execute'. :) -- ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: How to define exec method on a class object? Get syntax error due to built in command
On Wed, Mar 27, 2013 at 5:13 AM, Kyle stalker...@gmail.com wrote: Thanks for the suggestion. Looks like we currently use 2.3.4. This still wouldn't solve the problem because now the user would need to call something like getattr(wbt, exec)(args) instead of wbt.exec(args) like all the other commands. I think the easiest thing for me to do would be to just change the command name from exec to something else. . that's pretty ancient. Any chance you can upgrade at least to 2.7.3? ChrisA -- http://mail.python.org/mailman/listinfo/python-list
[job] Python AWS /Back-End Developer in New York, NY
We are looking for a strong Python Developer to work with our young and energetic team on the Next generation of clients website. This project is the first to implement the modern concepts of Cloud and MongoDB. Job Responsibilities - Creates new and modifies existing software, integrates software applications and modules based on specifications created in partnership with others - Designs and runs unit and integration tests to ensure that software meets requirements - Contributes and leads in the design process for less complex components - Provides technical support to operations and/or to other development teams - Creates, reviews, and maintains technical documentation related to assigned software - Reviews work of both peers and more junior developers - Helps identify and implement short- and long-term solution options including risk assessments - Participates in devising and implementing solutions for problem remediation - Participates in project planning sessions with team members - Provides work breakdown and estimates for small software development tasks - Provides timely status updates for areas of individual responsibilities in projects - Develops software using disciplined software development processes, adhering to team/company standards and software best practice guidelines, and corporate policies - Works independently with limited technical and management guidance, taking ownership of problems within own area of knowledge - Makes decisions within ambiguous guidelines with limited review by appropriate people - Is accountable for the quality of work - Delivers results within agreed procedures and timeframes - Attends to the needs of internal and/or external customer - Reviews and may approve decisions of junior engineers Qualifications: - Development experience with object-oriented languages - 1-2 years of Python development experience - Knowledge of HTML5 concepts is a plus to coordinate with the front-end development - Agile development experience a plus - Demonstrated ability to work in a team environment - Good unit testing practices - Good communication and documentation skills - Willingness to interact and work with different teams across organizations in different time zones - Willingness to work overtime and weekends if required - Bachelors degree in Computer Science is an added advantage Required Skills: - Strong in object-oriented concepts and Python language - Proficient with concepts of virtual environments and familiarity with Fabric tool - Knowledgeable about MVC pattern - Experienced working with Tornado web server - Familiar with REST API and JSON - Familiar with asynchronous programming - Familiar with AWS infrastructure - Knowledgeable about NoSQL concepts -- http://mail.python.org/mailman/listinfo/python-list
Re: I need a neat way to print nothing or a number
On Wed, Mar 27, 2013 at 4:21 AM, Ethan Furman et...@stoneleaf.us wrote: On 03/26/2013 10:06 AM, Wolfgang Maier wrote: Chris Angelico rosuav at gmail.com writes: Try printing out this expression: %.2f%value if value else '' Without the rest of your code I can't tell you how to plug that in, but a ternary expression is a good fit here. ChrisA Unfortunately, that's not working, but gives a TypeError: a float is required when the first value evaluates to False. Apparently it's not that easy to combine number formatting with logical operators - the same happens with my idea ('{:.2f}').format(value or ''). Use parens then: (%.2f % value) if value else '' According to the operator precedence table, the parens are unnecessary there. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On 25 mar, 22:51, Chris Angelico ros...@gmail.com wrote: The Python 3 merge of int and long has effectively penalized small-number arithmetic by removing an optimization. As we've seen from PEP 393 strings (jmf aside), there can be huge benefits from having a single type with multiple representations internally ... -- A character is not an integer (short form). jmf -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On Wed, Mar 27, 2013 at 5:50 AM, jmfauth wxjmfa...@gmail.com wrote: On 25 mar, 22:51, Chris Angelico ros...@gmail.com wrote: The Python 3 merge of int and long has effectively penalized small-number arithmetic by removing an optimization. As we've seen from PEP 393 strings (jmf aside), there can be huge benefits from having a single type with multiple representations internally ... -- A character is not an integer (short form). So? ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: How to define exec method on a class object? Get syntax error due to built in command
On Mar 26, 2:43 pm, Chris Angelico ros...@gmail.com wrote: On Wed, Mar 27, 2013 at 5:13 AM, Kyle stalker...@gmail.com wrote: Thanks for the suggestion. Looks like we currently use 2.3.4. This still wouldn't solve the problem because now the user would need to call something like getattr(wbt, exec)(args) instead of wbt.exec(args) like all the other commands. I think the easiest thing for me to do would be to just change the command name from exec to something else. . that's pretty ancient. Any chance you can upgrade at least to 2.7.3? ChrisA Unfortunately, while I could update my machine, there's no guarantee others would have the same version--the 2.3.4 seems to be the default on our machines and in the automount dirs. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to define exec method on a class object? Get syntax error due to built in command
On Wed, Mar 27, 2013 at 6:24 AM, Kyle stalker...@gmail.com wrote: On Mar 26, 2:43 pm, Chris Angelico ros...@gmail.com wrote: On Wed, Mar 27, 2013 at 5:13 AM, Kyle stalker...@gmail.com wrote: Thanks for the suggestion. Looks like we currently use 2.3.4. This still wouldn't solve the problem because now the user would need to call something like getattr(wbt, exec)(args) instead of wbt.exec(args) like all the other commands. I think the easiest thing for me to do would be to just change the command name from exec to something else. . that's pretty ancient. Any chance you can upgrade at least to 2.7.3? ChrisA Unfortunately, while I could update my machine, there's no guarantee others would have the same version--the 2.3.4 seems to be the default on our machines and in the automount dirs. I strongly recommend upgrading. 2.3.4 dates back to 2004, that's roughly a decade of bug fixes and feature enhancements behind the times. 2.7.3 is the latest 2.x release, and most likely your code will run unchanged on it; if you can switch to 3.3.0 (the latest 3.x release), that would actually fix your exec problem, for what that's worth. (Moving to 3.3.0 would be a much bigger change, though, and one that's likely to require code edits.) It's a good thing Python has neither the number nor breadth of security vulnerabilities as Windows; you're using something nearly as old as an unpatched Windows XP, no service packs, no Windows Update, nothing... no sane systems administrator would let you put that on the internet. It may not be suicidal like that, but it's still ten years' worth of updates you're missing out on! ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: problem with sys import argv
Dave Angel wrote: Since the script takes a mandatory argument, run it with one. python myscript.py Dave Better would be to change the script to check len(argv) for exactly 2, and tell the user how he should have run it. I would use argparse.ArgumentParser instead. http://docs.python.org/dev/library/argparse.html -- PointedEars Twitter: @PointedEars2 Please do not Cc: me. / Bitte keine Kopien per E-Mail. -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On 26 mar, 20:03, Chris Angelico ros...@gmail.com wrote: On Wed, Mar 27, 2013 at 5:50 AM, jmfauth wxjmfa...@gmail.com wrote: On 25 mar, 22:51, Chris Angelico ros...@gmail.com wrote: The Python 3 merge of int and long has effectively penalized small-number arithmetic by removing an optimization. As we've seen from PEP 393 strings (jmf aside), there can be huge benefits from having a single type with multiple representations internally ... -- A character is not an integer (short form). So? ChrisA A character is not an integer. jmf -- http://mail.python.org/mailman/listinfo/python-list
Re: problem with sys import argv
On 03/26/2013 04:12 PM, Thomas 'PointedEars' Lahn wrote: Dave Angel wrote: Since the script takes a mandatory argument, run it with one. python myscript.py Dave Better would be to change the script to check len(argv) for exactly 2, and tell the user how he should have run it. I would use argparse.ArgumentParser instead. http://docs.python.org/dev/library/argparse.html As would I. But that would be out of proportion of the rest of the code, and therefore presumably beyond the needs or interest of the OP. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On Wed, Mar 27, 2013 at 7:44 AM, jmfauth wxjmfa...@gmail.com wrote: On 26 mar, 20:03, Chris Angelico ros...@gmail.com wrote: On Wed, Mar 27, 2013 at 5:50 AM, jmfauth wxjmfa...@gmail.com wrote: On 25 mar, 22:51, Chris Angelico ros...@gmail.com wrote: The Python 3 merge of int and long has effectively penalized small-number arithmetic by removing an optimization. As we've seen from PEP 393 strings (jmf aside), there can be huge benefits from having a single type with multiple representations internally ... -- A character is not an integer (short form). So? ChrisA A character is not an integer. Yes, I heard you the first time. And I repeat: A needle pulling thread? You have not made any actual, uhh, _point_. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On 26/03/2013 20:44, jmfauth wrote: On 26 mar, 20:03, Chris Angelico ros...@gmail.com wrote: On Wed, Mar 27, 2013 at 5:50 AM, jmfauth wxjmfa...@gmail.com wrote: On 25 mar, 22:51, Chris Angelico ros...@gmail.com wrote: The Python 3 merge of int and long has effectively penalized small-number arithmetic by removing an optimization. As we've seen from PEP 393 strings (jmf aside), there can be huge benefits from having a single type with multiple representations internally ... -- A character is not an integer (short form). So? ChrisA A character is not an integer. jmf But you are an idiot. -- If you're using GoogleCrap™ please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On 2013-03-26, Mark Lawrence breamore...@yahoo.co.uk wrote: On 26/03/2013 20:44, jmfauth wrote: A character is not an integer (short form). So? A character is not an integer. jmf But you are an idiot. I think we all agree that jmf is a character. So we've established that no characters are integers, but some characters are idiots. Does that allow us to determine wheter integers are idiots or not? -- Grant Edwards grant.b.edwardsYow! All of life is a blur at of Republicans and meat! gmail.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On Wed, Mar 27, 2013 at 8:08 AM, Grant Edwards invalid@invalid.invalid wrote: On 2013-03-26, Mark Lawrence breamore...@yahoo.co.uk wrote: On 26/03/2013 20:44, jmfauth wrote: A character is not an integer (short form). So? A character is not an integer. jmf But you are an idiot. I think we all agree that jmf is a character. So we've established that no characters are integers, but some characters are idiots. Does that allow us to determine wheter integers are idiots or not? No, it doesn't. I'm fairly confident that most of them are not... however, I have my eye on 42. He gets around, a bit, but never seems to do anything very useful. I'd think twice before hiring him. But 1, now, he's a good fellow. Even when things get divisive, he's the voice of unity. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: import in Python3.3
On Tue, Mar 26, 2013 at 08:37:00AM -0700, rocky wrote: And again, I get the impression that for the use case asked about, there isn't much ambiguity. If I am in mypackage.foo and I want to access mypackage.collections I should be able to say something like that without ambiguity or that much inference or directory searching. If mypackage.colletions is not found inside the same directory as mypackage.foo, often I DON'T WANT Python to helpfully go searching around other places for it which sys.path will do. Instead what I probably want is Python to give me an error. So again I come to import_relative, http://code.google.com/p/pyimport-relative/. And again, I wish this package didn't have to exist. What's wrong with PEP 328 relative imports? In mypackage.foo, use from . import collections to import mypackage.collections. This has been part of the language since ~2.5 -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On 26/03/2013 21:14, Chris Angelico wrote: On Wed, Mar 27, 2013 at 8:08 AM, Grant Edwards invalid@invalid.invalid wrote: On 2013-03-26, Mark Lawrence breamore...@yahoo.co.uk wrote: On 26/03/2013 20:44, jmfauth wrote: A character is not an integer (short form). So? A character is not an integer. jmf But you are an idiot. I think we all agree that jmf is a character. So we've established that no characters are integers, but some characters are idiots. Does that allow us to determine wheter integers are idiots or not? No, it doesn't. I'm fairly confident that most of them are not... however, I have my eye on 42. He gets around, a bit, but never seems to do anything very useful. I'd think twice before hiring him. But 1, now, he's a good fellow. Even when things get divisive, he's the voice of unity. ChrisA Which reminds me, why do people on newsgroups often refer to 101, my favourite number? I mean, do we really care about the number of a room that Eric Blair worked in when he was at the BBC? -- If you're using GoogleCrap™ please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On 03/26/2013 05:14 PM, Chris Angelico wrote: snip Does that allow us to determine wheter integers are idiots or not? No, it doesn't. I'm fairly confident that most of them are not... however, I have my eye on 42. He gets around, a bit, but never seems to do anything very useful. I'd think twice before hiring him. Ah, 42, the Answer to Life, the Universe, and Everything -- DaveA -- http://mail.python.org/mailman/listinfo/python-list