Re: anomaly
On 12/05/2015 1:39 AM, zipher wrote: On Monday, May 11, 2015 at 10:34:24 AM UTC-5, Grant Edwards wrote: That Python, like COBOL, is an eminently practical language. LOL! Good one. I would make an incredibly substantial wager that you've never developed anything of note in either Python or COBOL. -- https://mail.python.org/mailman/listinfo/python-list
Re: A question on the creation of list of lists
On 23/04/2015 2:18 AM, subhabrata.bane...@gmail.com wrote: I have a list of file names of a directory, I want to read each one of them. After reading each one of them, I want to put the results of each file in a list. These lists would again be inserted to create a list of lists. While there's nothing wrong with for loops, Python does provide list comprehensions which can help simplify list creation. If you just want a list with each element being a list of the contents of a file: all_content = [ open(x, 'r').readlines() for x in list_of_files ] If you want a list containing a list of filenames and another list holding the content lists (which you seem to be wanting from your code): files_and_content = zip(list_of_files, all_content) Another useful way of storing data such as this is in a dictionary, using the filenames as keys: file_content = { x:open(x, 'r').readlines() for x in list_of_files } What structure is most important is, of course, dependent on what you want to do with it next. -- https://mail.python.org/mailman/listinfo/python-list
Re: Automation of Windows app?
On 23/03/2015 1:43 PM, Michael Torrie wrote: As near as I can tell the standard go-to utility for this is a program called AutoIt. https://www.autoitscript.com/site/autoit/ Nothing to do with Python, and its scripting language is maybe not that appealing to many, but it does the job, and does it pretty well. Actually, it's not *entirely* unrelated, as there's a Python wrapper for it: https://pypi.python.org/pypi/PyAutoIt/0.3 It's 2.7 only, though, so if 3.x is required, it's also possible to create your own wrapper using win32com: http://stackoverflow.com/questions/151846/get-other-running-processes-window-sizes-in-python/155587#155587 -- https://mail.python.org/mailman/listinfo/python-list
Re: An object is an instance (or not)?
On 28/01/2015 10:35 AM, Mario Figueiredo wrote: I admit it was a contrived example. I couldn't think of a way to demonstrate that a class object does not participate in its own inheritance rules. Only instances of it can. A class object isn't an instance of itself, it's an instance of the Class (to be extact, 'type') class. Method dispatching will also traverse the base classes when refering to the class object, too: class Master: ... @classmethod ... def func(cls): ... return cls ... class Sub(Master): ... pass ... type(Sub) class 'type' Sub.func() class '__main__.Sub' -- https://mail.python.org/mailman/listinfo/python-list
Re: An object is an instance (or not)?
On 28/01/2015 10:24 AM, Mario Figueiredo wrote: In other words, the object know as Sub class is not an instance object. True, it is an instance of the object 'type'. class Foo: ... pass ... isinstance(Foo, type) True isinstance(Foo, object) True A class is an object that is an instance of the class type. I'm still failing to see what distinction you're trying to make here. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python is DOOMED! Again!
On 22/01/2015 7:37 PM, Nicholas Cole wrote: Still, it would have been nicer to be able to write something like this (where the Unions are implicit): Coincidentally, you also demonstrate what makes this a lesser idea :) def handle_employees(employees, rasie): ^ # raise: float, Sequence[float] ^ There is a distinct advantage in not repeating yourself. -- https://mail.python.org/mailman/listinfo/python-list
Re: What killed Smalltalk could kill Python
On 22/01/2015 11:45 AM, Chris Angelico wrote: It's not a terrible justification for getting into programming. But writing games is (almost always) a terrible way to start programming. However, modifying games, I would argue, is a great way. The ComputerCraft mod for Minecraft, for example, added Lua-based control of in-game entities. It allows new developers to focus on internal game logic without being overwhelmed by the set up required to make it work. An extreme example is DoubleFine's Hack'n'Slash, wihch exposes its underlying logic in-game (also in Lua) and provides the user with tools to modify them: http://www.hacknslashthegame.com/ Initially the player starts off by modifying globals (to, say, add or remove entities from a room, or change their movement direction), and ends with them having full access to the game (but not engine) code. -- https://mail.python.org/mailman/listinfo/python-list
Re: What killed Smalltalk could kill Python
On 22/01/2015 1:23 PM, Steven D'Aprano wrote: Modern games *are* part of today's complex application systems, and games developers may need the same skills used by serious developers I wish more game developers would understand this. I've lost count of the number of games that have failed during development because all of the source code was stolen or destroyed. I've had arguments with game devs (some who've worked at some of the bigger studios) because they're convinced that nothing outside of game development has anything to teach them...when their (for eg) revision control entails zipping up their daily changes and emailing them to the rest of the team... -- https://mail.python.org/mailman/listinfo/python-list
Re: How to wow someone new to Python
On 17/01/2015 1:03 AM, Chris Angelico wrote: Scenario: You're introducing someone to Python for the first time. S/he may have some previous programming experience, or may be new to the whole idea of giving a computer instructions. You have a couple of minutes to show off how awesome Python is. What do you do? When demoing to people with a reasonable amount of experience, I've found they're often impressed by showing them list comprehensions, then generators, then chained generators. -- https://mail.python.org/mailman/listinfo/python-list
Re: List of python -m tools
On 14/01/2015 7:33 PM, Albert-Jan Roskam wrote: You say Python 2.7.9 and 3.x comes with an easy way to install pip. Run python -m ensurepip and pypi is at your service. . But here https://docs.python.org/3/library/ensurepip.html it says that This module does not access the internet. All of the components needed to bootstrap pip are included as internal parts of the package. So pypi is not involved, right? The original comment doesn't mean that PyPI is involved in the installation, but that installing it allows for packages to be installed via PyPI. Obviously that isn't true if you're not net-enabled, but pip can still handy for installing local packages. -- https://mail.python.org/mailman/listinfo/python-list
Re: PyWart: Poor Documentation Examples
On 11/01/2015 7:31 PM, Steven D'Aprano wrote: If that isn't a form of stupidity, I don't know what is. Maybe you're just eternally optimistic that people can change for the better. -- https://mail.python.org/mailman/listinfo/python-list
Re: OFF TOPIC Snow Crash [was Re: Hello World]
On 24/12/2014 2:20 AM, Grant Edwards wrote: And even _with_ all the technical jibber-jabber, none of it explained or justified the whole writing a virus to infect the brain through the optic nerve thing which might just have well been magick and witches. While I love SNOW CRASH, I do think it'd fundamentally flawed. The worst for me is that in a fictional universe with a VR system capable of displaying anything, the crux of the book revolves around a couple of characters having a long, long discussion about Sumerian history. A: blah blah blah blah blah Sumeria B: And then what? A: blah blah blah blah B: etc It's been at least a decade since I read it, but wasn't that also the explanation for how the virus worked? -- https://mail.python.org/mailman/listinfo/python-list
Re: OFF TOPIC Snow Crash [was Re: Hello World]
On 24/12/2014 9:50 PM, alister wrote: what feels like 3 or 4 chapters in it is still trying to set the scene, an exercise in stylish writing with very little content so far. even early scifi written for magazines on a per word basis were not this excessive (because if they were they would probably have been rejected or seriously edited). My personal theory is that Stephenson polishes and polishes the first few chapters until the whole creative process really engages - the first chapter is especially overwritten - and then tears through the novel in an increasingly unrefined way, until it arrives at its anticlimactic conclusion. He was notorious for a while for not providing satisfying endings to his books. Hopefully it will finally settle down amend my current impression. SNOW CRASH doesn't, I'm afraid, but Stephenson himself does as a writer. CRYPTONOMICON is a great geek read. ANATHEM is a fantastic piece of SF (possibly my favourite of his) THE SYSTEM OF THE WORLD is an amazing accomplishment and really shows that modern infotech didn't spring out of nothing like Venus from the foam. -- https://mail.python.org/mailman/listinfo/python-list
Re: If One Line
On 26/12/2014 1:18 AM, JC wrote: Is it possible in python: if ((x = a(b,c)) == 'TRUE'): print x One approach is to use a function in the condition to do the assignment: x = None def assign_to_x(val): global x x = val return val def a(x, y): return 'TRUE' b, c = 'foo', 'bar' if assign_to_x(a(b,c)) == 'TRUE': print(x) -- https://mail.python.org/mailman/listinfo/python-list
Re: If One Line
On 26/12/2014 1:37 PM, Steven D'Aprano wrote: One approach is to use a function in the condition to do the assignment: Let me fix that for you: /s/approach/bad idea/ I never said it was a _good_ approach ;) And you don't even save any lines! Instead of a one-liner, you have six lines! While I'm _definitely_ not going to advocate for this approach as a valid solution, I have to disagree with this being an issue. While it's more lines in the given example, if there were dozens of such assignment-within-conditional calls in the same code, the additional LOCs become negligible. Just because a programming language allows something doesn't make it a good idea. This is true. But conversely, just because I think something is a bad idea doesn't mean someone else can't have found a valid use for it. -- https://mail.python.org/mailman/listinfo/python-list
Re: How to fix those errors?
On 19/11/2014 1:40 PM, Chris Angelico wrote: On Wed, Nov 19, 2014 at 2:02 PM, alex23 wuwe...@gmail.com wrote: The first time I got a T_PAAMAYIM_NEKUDOTAYIM error, I just about flipped my desk in rage. If that were Hebrew for scope resolution operator, would it be less rage-inducing? Not especially. I prefer errors to actually use the syntax of the language where possible. -- https://mail.python.org/mailman/listinfo/python-list
Re: PyWart: Python's import statement and the history of external dependencies
On 16/11/2014 3:01 PM, Rick Johnson wrote: Python's attempt to solve the external dependencies problem has yet to produce the results that many people, including myself, would like. I'd say this was an argumentum ad populum, only you didn't cite anything that shows the many you claim you speak for. Actually, Python is not alone in this deficiency, no, Python is just *ANOTHER* language in a *STRING* of languages over the years who has *YET AGAIN* implemented the same old crusty design patterns, packaged them in a shiny metallic wrapping paper with a big red bow on top, and hoped that no one would notice the stench... Are you sure that's not just you? 1. Name clashes! 2. Smaller name pool! Just off the top of my head, we have several solutions for this: 1) Rebinding imports import foo as foo2 2) Namespace packages import mypackage.foo 3) Filepath imports (deprecated in 3.4 but under discussion for reprecation or replacement) import importlib.machinery loader = importlib.machinery.SourceFileLoader(module.name, /path /to/file.py) foo = loader.load_module() foo.MyClass() 4) Virtual environments In before but WHY so MANY different WAYS OMG PYTHON you M.F.P.O.S.: because they offer flexibility. 3. Machinery is too implicit! See: importlib 4. Circular imports are inevitable! They're also clear indication of bad design. That's not something Python should explicitly set out to support. 5. Much too difficult to use and/or explain! Well sure, if your reaction to things you don't understand is to rant against them instead of asking questions, then I can see how that would be true. Also: citation needed. 6. Too many gotchas! Is this the sequel to Too Many Cooks? Awesome. In closing, there is only one thing you need to know about Python's import statement: it is deceptively easy to underestimate it's ability to *EFF UP* your expectations! There's your problem right there: a language conforms to its specification, not your random expectation. I'm eager to see how you resolve your concerns in RickPython3000. -- https://mail.python.org/mailman/listinfo/python-list
Re: How to fix those errors?
On 17/11/2014 1:06 PM, Chris Angelico wrote: You could then name it in Hebrew: Paamayim Nekudotayim. There is excellent precedent for this - it's done by a language in whose footsteps Python strives to follow. The first time I got a T_PAAMAYIM_NEKUDOTAYIM error, I just about flipped my desk in rage. -- https://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] Dinamically set __call__ method
On 11/04/2014 08:52 AM, Roberto Martínez wrote: I am trying to replace dinamically the __call__ method of an object using setattr. Example: $ cat testcall.py class A: def __init__(self): setattr(self, '__call__', self.newcall) def __call__(self): print(OLD) def newcall(self): print(NEW) a=A() a() I expect to get NEW instead of OLD, but in Python 3.4 I get OLD. Given that special methods can only be replaced on the class and not the instance, you could create a new version of the class within __init__ and assign it to the instance: class A: def __init__(self, call_method=None): if call_method: methods = {'__call__': call_method} self.__class__ = type('Custom_A', (A,), ) def __call__(self): return 'original' a = A() a() old b = A(lambda self: 'new') b() new -- https://mail.python.org/mailman/listinfo/python-list
Re: Anyone know the solution
On 29/10/2014 11:28 AM, Anton wrote: Can you elaborate why it is an NP-complete problem or maybe a link to description of problem you are referring to? While not the exact problem, it's tangentially related to: http://kenlevine.blogspot.com.au/2011/03/reducing-humor-to-equation.html -- https://mail.python.org/mailman/listinfo/python-list
Re: % symbol in python
On 29/10/2014 2:41 PM, satishmlm...@gmail.com wrote: kindly let me know what is $ROWS$ along with % symbol's meaning It's a token, a static value added to the template to indicate where additional data will be added. So $ROW$ in this section: table trthkeytdinput type=text name=key value=%(key)s $ROWS$ /table Will be replaced by whatever rowshtml contains at this point: replyhtml = replyhtml.replace('$ROWS$', rowshtml) Of note: the template section above has opening tags for tr, th and td but no closing ones. It's not valid html. Also I don't think this is doing what you think it is: rowhtml = 'trth%stdinput type=text name=%s value=%%(%s)s\n' rowshtml = '' for fieldname in fieldnames: rowshtml += (rowhtml % ((fieldname, ) * 3)) replyhtml = replyhtml.replace('$ROWS$', rowshtml) After the first fieldname ('name' in this case), the token $ROWS$ will be replaced by the string : 'trthnametdinput type=text name=name value=%%(name)s\n'. On the second iteration of the loop, when fieldname is 'age', rowshtml will equal: 'trthnametdinput type=text name=name value=%%(name)s\ntrthagetdinput type=text name=age value=%%(age)s\n' ...but nothing will happen with it as $ROWS$ has already been replaced during the first time through the loop. Either the `replyhtml = ...` line is mis-indented or the code is terribly broken. Unless this is for homework, I highly recommend just using one of the many templating libraries that exist for Python, such as Jinja2. -- https://mail.python.org/mailman/listinfo/python-list
Re: Anyone know the solution
On 28/10/2014 1:10 AM, emmanuel...@gmail.com wrote: Write a program that reads the contents of the two files into two separate lists. The user should be able to enter a boy's name, a girl's name or both, and the application will display messages indicating whether the names were among the most popular. This is actually a trick question. This is a classic unsolvable problem in computer science, known as the Dual Baskets problem. It is NP-complete, meaning that there is no easy solution. It requires brute-forcing and can take an indefinite period of time to complete, if at all. The correct answer is Not possible. -- https://mail.python.org/mailman/listinfo/python-list
Re: I am out of trial and error again Lists
On 23/10/2014 10:02 AM, Seymore4Head wrote: On Thu, 23 Oct 2014 00:44:01 +0100, Mark Lawrence breamore...@yahoo.co.uk wrote: One more question. if y in str(range(10) Why doesn't that work. I suggest you try str(range(10)) from the interactive prompt and see exactly what you get, as it's nothing like what you expect :) I see that now. So there may not be a short hand solution. There are two 'short hand solutions' to do what you want here: import string if y in string.digits: Or even simpler: if y.isdigit(): ... -- https://mail.python.org/mailman/listinfo/python-list
Re: Is there an easy way to control indents in Python
On 15/10/2014 12:23 PM, Juan Christian wrote: Using PyCharm is easy: File Settings (IDE Settings) Editor Smart Keys Reformat on paste choose Reformat Block This isn't as straight forward as you imply. Say I have misindented code like this: if True: print 'true' else: print 'false' print 'done' If I select this block in PyCharm and reformat it, I get: if True: print 'true' else: print 'false' print 'done' Which is still invalid. Even if it did work more fully, though, how would it determine the correct placement of the last line of code? -- https://mail.python.org/mailman/listinfo/python-list
Re: Is there an easy way to control indents in Python
On 16/10/2014 12:32 AM, Chris “Kwpolska” Warrick wrote: It should parse this as else: print 'false' print 'done' Why? Because things like `print 'done'` usually have an empty line before it: if True: print 'true' else: print 'false' print 'done' That should be parsed the way you want it done. Makes perfect sense when you look at it. I don't think it makes any sense at all, for two reasons: 1) Empty lines have no such semantic meaning in Python. 2) Anything that strips tabs is just as likely to strip EOLs. -- https://mail.python.org/mailman/listinfo/python-list
Re: TypeError: 'kwarg' is an invalid keyword argument for this function
On 13/10/2014 8:04 PM, Dave Angel wrote: It would also help to spell it the same. In the OP's implementation, he defined kwargs, and tried to use it as kwarg. That's perfectly okay, though: if `kwargs` is the name used to reference the dictionary of keyword arguments, `kwarg` would be an instance of a keyword argument. -- https://mail.python.org/mailman/listinfo/python-list
Re: Need help in pulling SQL query out of log file...
On 14/10/2014 11:47 AM, Sagar Deshmukh wrote: I have a log file which has lot of information like..SQL query.. number of records read...records loaded etc.. My requirement is i would like to read the SQL query completly and write it to another txt file.. Generally we encourage people to post what they've tried to the list. It helps us identify what you know and what you need help with. However, given: the log file may not be always same so can not make static choices... You'll probably want to use regular expressions: https://docs.python.org/howto/regex.html Regexps let you search through the text for known patterns and extract any that match. To extract all SQL query sections, you'll need to come up with a way of uniquely identifying them from all other sections. Looking at your example log file, it looks like they're all of the format: SQL Query [the actual sql query] From that we can determine that all SQL queries are prefixed by 'SQL Query [' and suffixed by ']', so the content you want is everything between those markers. So a possible regular expression might be: SQL Query \[(.*?)\] To quickly explain this: 1. SQL Query matches on that string 2. Because [] have meaning for regexes, to match on literal brackets you need to escape them via \[ and \] 3. ( ) is a group, whats contained in here will be returned 4. .* means to grab all matching text 5. ? means to do an ungreedy grab ie it'll stop at the first \] it encounters. Pulling the queries out of your log file should be as simple as: import re log = open('logfile').read() queries = re.findall(SQL Query \[(.*?)\], log, re.DOTALL) Because the queries can fall across multiple lines, the re.DOTALL flag is required to treat EOL markers as characters. Hope this helps. -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
On 23/09/2014 4:25 AM, Chris Angelico wrote: On Tue, Sep 23, 2014 at 4:24 AM, Chris Kaynor ckay...@zindagigames.com wrote: But the thing that requires the comment is the 2, not the print or the cells. And that comes to a more common issue: any number other than 0 or 1 in code most likely needs a comment (that comment could be merely a variable name). Values of 0 or 1 may need a comment, but there are plenty of cases where they are used quite clearly - its much less likely that other numbers have obvious meaning. Or in this case, replacing the list with a namedtuple is probably more useful. Depending on the use case, binding a slice to a name can also help clarify things. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python vs C++
On 26/08/2014 6:12 PM, Amirouche Boubekki wrote: 2014-08-26 6:02 GMT+02:00 Ian Kelly ian.g.ke...@gmail.com mailto:ian.g.ke...@gmail.com: It would be just as easy or easier in Python, or one could save a lot more effort by just using RPG Maker like every other indie RPG developer seems to do. I don't think there is FLOSS equivalent. There is indeed: http://openrpgmaker.sourceforge.net/ -- https://mail.python.org/mailman/listinfo/python-list
Re: Python vs C++
On 24/08/2014 7:14 PM, Robert Kern wrote: On 2014-08-22 01:26, Chris Angelico wrote: Every time Cython gets discussed, I get a renewed desire to learn it. Trouble is, I don't have any project that calls for it - there's nothing I'm desperately wanting to do that involves both Python and C/C++. Anyone got any suggestions? :) Class-based, Python 3-compatible bindings for libtcod? http://doryen.eptalys.net/libtcod/ I would definitely fund a Kickstarter for this. -- https://mail.python.org/mailman/listinfo/python-list
Re: Why can not initialize the class?
On 23/08/2014 1:17 AM, Steven D'Aprano wrote: Luofeiyu, you are getting stuck on basic questions. Before working with advanced features like properties, you should learn the simply features. Has luofeiyu ever actually acknowledged any such comment or request people have made? I see we've given up on trying to get em to stop top-posting, so I'm guessing no. -- https://mail.python.org/mailman/listinfo/python-list
Re: Working with decimals part 2
On 26/08/2014 3:55 AM, Seymore4Head wrote: I changed the program just a little to give myself a little practice with number formats. The main thing I wanted to do was make the decimal points line up. The problem I am having is with the print (count)(payment)(balance) line. While I don't want to discourage you from learning how to do it the long way, when you have a handle on it I highly recommend using a library for producing tabular data. tabulate is a very handy one, which supports lining up decimal points, amongst many other features: https://pypi.python.org/pypi/tabulate I personally find formatting text to be a pain and will always look for a better method. -- https://mail.python.org/mailman/listinfo/python-list
Re: Switching from nose to unittest2 - how to continue after an error?
On 26/08/2014 6:12 AM, Mark Lawrence wrote: Whatever happened to There should be one-- and preferably only one --obvious way to do it.? :) Ignoring for a moment that one obvious way only applies to Python-the-language, when it comes to libraries, there's a few factors (IMO) that affect this: 1. Some people find it easier to write something from scratch that read docs for an existing product. 2. It's easier to reimplement an existing concept than come up with something new. This is actually a good thing, though, as monocultures die. Just chalk it up to evolutionary pressure :) -- https://mail.python.org/mailman/listinfo/python-list
Re: proposed syntax for multiline anony-functions (hopefully?)
On 21/08/2014 7:30 PM, icefap...@gmail.com wrote: On Thursday, August 21, 2014 2:27:08 AM UTC-7, Marko Rauhamaa wrote: In practice, your proposal would not make life easier for Python programmers. neither did the lambda, yours truly supposes? alex23 disagrees. alex23 finds the lambda extremely convenient for things like sort, filter etc where alex23 wants to provide a function. alex23 finds this to be very readable: odds_list = filter(lambda x: bool(x % 2), some_list) By comparison, alex23 finds this to be more cumbersome for little gain: def odds_only(x): return bool(x % 2) odds_list = filter(odds_only, some_list) alex23 finds most examples for multiline anonymous functions to be far more difficult to parse than the both restricted lambda form and the separate function approach: odds_list = filter((def(x): return bool(x % 2)), some_list) alex23 isn't even sure if that's the correct format for your proposed syntax, or whether `, some_list)` has to appear on a separate line, or even if the () around the anonymous function is even necessary (alex23 assumed it was from your description of the closing parenthesis popping the space-sensitivity-stack). -- https://mail.python.org/mailman/listinfo/python-list
Re: Suitable Python code to scrape specific details from web pages.
On 13/08/2014 7:28 AM, Roy Smith wrote: Second, if you're going to be parsing web pages, trying to use regexes is a losing game. You need something that knows how to parse HTML. The canonical answer is lxml (http://lxml.de/), but Beautiful Soup (http://www.crummy.com/software/BeautifulSoup/) is less intimidating to use. lxml also has a BeautifulSoup parser, so you can easily mix and match approaches: http://lxml.de/elementsoup.html -- https://mail.python.org/mailman/listinfo/python-list
Re: Topological Overlap
On 17/08/2014 4:10 AM, lavanya addepalli wrote: Actually it is a huge project and topological overlap is one part in that inputfile: 0_node_1 0_node_2 w0 1_node_1 1_node_2 w1 2_node_1 2_node_2 w2 3_node_1 3_node_2 w3 4_node_1 4_node_2 w4 5_node_1 5_node_2 w5 2 nodes in pair and w is the weight. I have to find the topological overlap in the network including the weights Have you looked at the library NetworkX? I'd start by loading your data into a weighted graph and working from there: https://networkx.github.io/documentation/latest/examples/drawing/weighted_graph.html -- https://mail.python.org/mailman/listinfo/python-list
Re: Captcha identify
On 15/08/2014 5:43 AM, Eric S. Johansson wrote: On 8/14/2014 2:37 PM, Peter Pearson wrote: Which of the following eight sentences are sarcastic in tone? and responses on this list alone show problems with detecting sarcasm (or snark). It can be especially difficult for people on the autism spectrum. Something to consider when advocating changes to a system that disadvantages you is to not pass the problem on to others. -- https://mail.python.org/mailman/listinfo/python-list
Re: how to write file into my android phone?
On 10/08/2014 7:08 PM, Chris “Kwpolska” Warrick wrote: 2) the phone isn't necessarily visible on a pc as a drive at all. For example the Samsung gs4. This is actually true for ALL android devices, starting with Android 3.0. This isn't true for my Samsung gs2 running Android 4.1.2. -- https://mail.python.org/mailman/listinfo/python-list
Re: Wikibooks example doesn't work
On 7/08/2014 1:25 PM, Seymore4Head wrote: This part was added as an exercise. A counter is added to give 3 tries to guess the number. It is supposed to stop after count gets to 3. It doesn't. It just keeps looping back and asking for another guess. You've misread the exercise: Modify the higher or lower program from this section to keep track of how many times the user has entered the wrong number. If it is more than 3 times, print That must have been complicated. at the end, otherwise print Good job! There's nothing there about breaking out of the loop after 3 attempts, just producing a different end message on successful completion based on how many attempts were made. The Wikibooks example works as specified. -- https://mail.python.org/mailman/listinfo/python-list
Re: Making every no-arg method a property?
On 6/08/2014 9:49 AM, Ben Finney wrote: Christian Calderon calderon.christian...@gmail.com writes: I like that in ruby I don't have to type parenthesis at the end of each function call if I don't need to provide extra arguments. Having the same name sometimes refer to “get this as a value” and other times “call this as a function and get the return value” imposes a cognitive load on the reader, IMO an unnecessary one. It also makes it impossible to use such methods in dispatch patterns or as callbacks. -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about Pass-by-object-reference?
On 23/07/2014 10:27 AM, Terry Reedy wrote: When you call a function, Python binds function parameter names to argument objects in the function's local namespace, the same as in name assignments. Given def f(a, b): pass a call f(1, 'x') starts by executing a, b = 1, 'x' in the local namespace. Nothing is being 'passed'. The Dude: Look, nothing is passed, here, man. The Big Lebowski: Nothing is passed? The god damn argument has crashed into the parameter! ...sorry, it's been a long week. -- https://mail.python.org/mailman/listinfo/python-list
Re: Multiple python versions, one dev environment???
On 18/07/2014 9:44 AM, Roy Smith wrote: In article mailman.11957.1405626121.18130.python-l...@python.org, Ned Batchelder n...@nedbatchelder.com wrote: Virtualenv is definitely the right way to isolate different Python environments from each other. Absolutely. Don't even consider any other alternative. Just do it. Not even buildout? :) -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3 is killing Python
On 17/07/2014 1:14 PM, Steven D'Aprano wrote: There will never be a Python 2.8. When push comes to shove, the people bitching about Python 3 will not do the work necessary to fork Python 2.7 and make a version 2.8. +1 The idea that forking and maintaining Python 2.8 is somehow _less effort_ than porting code to Python 3.x is batshit crazy. The Py2.8 claims seem to me to be nothing more than a shallow attempt to blackmail the core devs. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3 is killing Python
On 18/07/2014 10:26 AM, Mark Lawrence wrote: I'm looking forward to see the massive number of fixes that come from rr I'm still waiting for RickPython, the One True Python. Remember when he used to rant as if he was actually working on it and not just pissing in the wind? -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3 is killing Python
On 18/07/2014 10:45 AM, Andrew Berg wrote: Maybe he's too busy working on RickPy 4000 (or whatever it was called). I believe the new working name is PypeDream. -- https://mail.python.org/mailman/listinfo/python-list
Re: initializing parameters class in Python only once?
On 15/07/2014 3:28 PM, Steven D'Aprano wrote: # === module params.py === class Params(object): a = 1 b = 2 @property def c(self): return self.a**2 + self.b**2 - self.a + 1 params = Params() del Params # hide the class Then callers just say: from params import params print params.c I'd replace the instantiation deletion of the class in params.py with: import sys sys.modules[__name__] = Params() ..and replace the module itself with the parameter object. I'd also add: __file__ = __file__ ...to the class definition to help with debugging. But this is really just bikeshedding. It's a shame the property decorator doesn't work at the module level, though. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3 is killing Python
On 15/07/2014 11:57 PM, Kevin Walzer wrote: The number of language revisions that result in deliberate, code-level incompatibility out there is pretty small. People rightly expect that code written for version 2.x of a language will continue to work with version 3.x, even if 3.x is designed to go in another direction. PHP regularly breaks compatibility between _minor_ version releases: http://php.net/manual/en/migration53.incompatible.php Even more so with major releases: http://php.net/manual/en/migration5.incompatible.php And yet I never see anywhere near as much angst and agony as Python 3.x has caused. -- https://mail.python.org/mailman/listinfo/python-list
Re: Create flowcharts from Python
On 18/06/2014 1:32 AM, Nagy László Zsolt wrote: Is there a library for Python that can easily create flowcharts using a simple API? The diagram application Dia comes with a Python API: https://wiki.gnome.org/Apps/Dia/Python -- https://mail.python.org/mailman/listinfo/python-list
Re: OT: This Swift thing
On 6/06/2014 9:11 PM, Alain Ketterlin wrote: The nice thing with optional type annotations and an hypothetical Python compiler would be that you could, e.g., continue using the interpreter during development and then compile for production use. s/annotations/decorators/ and you effectively have Cython's pure Python mode. -- https://mail.python.org/mailman/listinfo/python-list
Re: Everything you did not want to know about Unicode in Python 3
On 13/05/2014 11:39 AM, Chris Angelico wrote: On Tue, May 13, 2014 at 11:18 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: - have a bytes version of sys.argv (bargv? argvb?) and read the file names from that; argb? :) I tried and failed to come up with an argy bargy joke here so decided to go for a meta-reference instead. -- https://mail.python.org/mailman/listinfo/python-list
Re: a better way to operate svn with python(better than pysvn)?
On 13/05/2014 1:16 AM, xs.nep...@gmail.com wrote: ... Rather than just send an empty message, why not explain what you don't like about pysvn so that someone could provide more pertinant advice? But since you didn't: https://pypi.python.org/pypi?%3Aaction=searchterm=svnsubmit=search -- https://mail.python.org/mailman/listinfo/python-list
Re: Teaching python to non-programmers
On 11/04/2014 3:42 PM, Rustom Mody wrote: On Friday, April 11, 2014 10:41:26 AM UTC+5:30, Chris Angelico wrote: On Fri, Apr 11, 2014 at 2:37 PM, Rustom Mody wrote: Right. Its true that when I was at a fairly large corporate, I was not told: Please always top post! What I was very gently and super politely told was: Please dont delete mail context Then you were told that by someone who does not understand email. You seem to be cocksure who is right. Im just curious who you think it is :-) http://www.ietf.org/rfc/rfc1855.txt If you are sending a reply to a message or a posting be sure you summarize the original at the top of the message, or include just enough text of the original to give a context. This will make sure readers understand when they start to read your response. Since NetNews, especially, is proliferated by distributing the postings from one host to another, it is possible to see a response to a message before seeing the original. Giving context helps everyone. But do not include the entire original! RFC1855 is the PEP8 of posting online :) -- https://mail.python.org/mailman/listinfo/python-list
Re: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing?
On 9/04/2014 6:55 PM, Mark Lawrence wrote: And the worst thing about terrible code is when you first realise just how bad it is and wonder why you wrote it like that in the first place. For me, it's nearly always due to time constraints. Usually caused by a comment like: we absolutely need this extensive feature added before launch, can you start it right now? oh and we're still good for release tomorrow, right? Because we promised the client etc etc etc -- https://mail.python.org/mailman/listinfo/python-list
Re: [OFF-TOPIC] How do I find a mentor when no one I work with knows what they are doing?
On 9/04/2014 3:29 AM, Chris Angelico wrote: My code would make for terrible PHP. :) Don't feel bad about that. It's a truism for every language, including PHP. -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)
On 8/04/2014 6:21 PM, Steven D'Aprano wrote: Functions which are intended to return a value may be named as verbs: [...] or as nouns: int Shorthand for 'integerise'. str 'stringify' dict 'dictionarate' coordinate array These are both verbs. ...I'll get me coat. -- https://mail.python.org/mailman/listinfo/python-list
Re: Keeping track of things with dictionaries
On 8/04/2014 6:31 PM, Frank Millman wrote: Here is an idea, inspired by Peter Otten's suggestion earlier in this thread. Instead of defaultdict, subclass dict and use __missing__() to supply the default values. When the dictionary is set up, delete __missing__ from the subclass! Ugly, but it seems to work. Ugly indeed. Replicating the behaviour of defaultdict and then deleting a method from the class seems a very heavyhanded 'solution', especially when you can just override a public attribute on defaultdict, as mentioned by Peter. -- https://mail.python.org/mailman/listinfo/python-list
Re: Keeping track of things with dictionaries
On 9/04/2014 12:33 PM, Chris Angelico wrote: Unfortunately I seem to be missing antidisestablishmentarianism, because the longest words in my dict are only 24 characters, excluding the '\n'. Should I ask for my money back? I think you should. That's a fundamental flaw in the dictionary. Everyone knows that word's the longest! It depends on whether you count 'supercalifragilisticexpialidocious'. If you don't, then 'pseudopseudohypoparathyroidism' is still slightly longer :) -- https://mail.python.org/mailman/listinfo/python-list
Re: Compact way to assign values by slicing list in Python
On 3/04/2014 11:50 PM, Marco Buttu wrote: I prefere this one: bar = ['a','b','c','x','y','z'] v1, _, _, v2, v3, _ = bar I also like the solution with itemgetter: v1, v2, v3 = itemgetter(0, 3, 4)(bar) but I think it is less readable than the previous one What if you wanted the 2nd, 37th, and 1007th items from a list? Personally, I find the 2nd form far more readable, once I got past my initial surprise that it would access a list of items. -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)
On 4/04/2014 2:38 AM, Mark H Harris wrote: If I speak of the python community, and I rarely do Maybe you speak of them rarely but you claim to speak for them fairly often. Python3 is not perfect; but python3 is *way* more consistent than python2 and consequently *way* more useful than python2. It's possible for something to become more useful and for the original to *also* be useful: Py2 old-style classes were useful even though new-style classes were more so. Plone uses Py2's unicode extensively and at no point have I thought it useless. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python to be replaced by the new language called Cookie !
On 2/04/2014 3:42 PM, Chris Angelico wrote: Python 2.8 is supported only on Windows XP 64-bit, and you should upgrade to 32-bit Python That would be Python 1.4 -- https://mail.python.org/mailman/listinfo/python-list
Re: meta language to define forms
On 28/03/2014 6:56 AM, Sells, Fred wrote: The idea is to use a nice clean syntax like Python to define form content, then render it as HTML but only as a review tool for users, The actual rendering would go into a database to let a vendor's tool generate the form in a totally non-standard syntax that's really clunky. Class FyFormNumber001(GeneralForm): Section1 = Section(title=Enter Patient Vital Signs) Question1 = NumberQuestion(title=Enter pulse rate, format=%d3) Question2 = Dropdown(title=Enter current status) Question2.choices = [ (1, Alive and Kicking), (2, Comatose), (3, Dead), ...] Is there anything out there that would be close or do you have any suggestions. Are you familiar with z3c.form? https://pypi.python.org/pypi/z3c.form Given that it's part of the Zope web framework, it's fairly heavily geared towards working with HTTP requests, but it's quite possible to only use the parts that want. For your requirement, you could probably get a long way with using zope.schema for defining the forms, and then customising some of the templates to render them appropriately. The provided widgets are easily extensible, so adding support for the vendor form syntax - possibly as additional templates alongside the HTML ones - should be doable. -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)
On 25/03/2014 12:39 PM, Mark H Harris wrote: my version semantically is how it is perceived by the user Could you please stop claiming to have insight into the comprehension of anyone other than yourself? Hasty generalisations don't help your argument. -- https://mail.python.org/mailman/listinfo/python-list
Re: running python 2 vs 3
On 3/20/2014 3:07 PM, John Gordon wrote: There are two ways (at least!) to run a python script: On 21/03/2014 8:05 AM, Terry Reedy wrote: 3. [...] Our chief weapon is... -- https://mail.python.org/mailman/listinfo/python-list
Re: Balanced trees
On 11/03/2014 8:12 PM, Marko Rauhamaa wrote: Python should let skilled professionals do their work. Thankfully, for the most part, it does. Skilled professionals don't solely rely on the standard library, either. If you know you need a balanced tree, you'll also know where to find an implementation of one. -- https://mail.python.org/mailman/listinfo/python-list
Re: Reference
On 6/03/2014 10:52 AM, Marko Rauhamaa wrote: I was just saying talking about id() as a memory address isn't all that bad. It's a bit like rolling down your power windows or turning up the volume, when there's nothing to roll or turn. There's no risk of getting your program wrong. Unless you're talking about, say, the PyPy implementation, for which id is _not_ a memory address at all. Why insist on using memory address rather than unique identifier, when the latter is fundamentally more correct? -- https://mail.python.org/mailman/listinfo/python-list
Re: How do I process this?
On 4/03/2014 2:03 PM, Igor Korot wrote: Hi, ALL, I have a csv file which depending on how it was produced gives 2 different strings as shown in the example below (test1 and test2). I am only interested in the first field in test1 and obviously in the whole string of test2. test1 = a test2 = a Try using the csv module: from StringIO import StringIO csvfile = StringIO() csvfile.write('a\n') csvfile.write('a\n') csvfile.seek(0) import csv reader = csv.reader(csvfile) [x[0] for x in reader] ['a', 'a'] -- https://mail.python.org/mailman/listinfo/python-list
Re: Reference
On 5/03/2014 3:47 PM, Rustom Mody wrote: That python is a hll means that machine reprs are intended to be abstracted away. 'is' fails to do that -- proof of that being the discrepancy between is and == The discrepancy is because _they're fundamentally different_: a = b = [1,2] c = [1,2] a is b True a is c False a == b True a == c True `is` is used to determine if two names refer to the same object. `==` is used to determine if they're equivalent in value. Both have their uses. -- https://mail.python.org/mailman/listinfo/python-list
Re: Reference
On 5/03/2014 4:10 PM, Rustom Mody wrote: A python programmer who needs/wants to think of same/is in this sense should probably be using C or assembly Any programmer who is obsessing about some idea of philosophical purity should probably not be using Python. -- https://mail.python.org/mailman/listinfo/python-list
Re: Coding a simple state machine in python
On 25/02/2014 8:01 PM, Peter Otten wrote: alex23 wrote: No, the _easy_ solution is [find a suitable package on PyPI] Easy? By the time I have evaluated these I've written my own ;) It's never writing a solution that's the problem...it's maintaining it over time :) -- https://mail.python.org/mailman/listinfo/python-list
Re: end quote help for a newbie
On 27/02/2014 8:41 PM, Chris Angelico wrote: On Thu, Feb 27, 2014 at 9:30 PM, Peter Clark artomis...@yahoo.co.uk wrote: # Dragons and dungeons, based on CP/M program messages from ca. 1966 # This version designed and produced by peter clark beginning in December 2013 def startandload(n):# introduce program and allow messages to be loaded/amended x = str(input(Welcome Adventurer, what is your name?)) if x==('load'): y = str(input(messages, places or things?)) if y in(messages, places,things): print(OK) else: print(Wrong) if x==('restart'): y = str(input(game reference)) if y in(messages, places,things): print(*** to be done - load and restart game ***) else: print(Wrong) while True: startandload The problem is right at the end: you don't actually call the function. You always need parentheses to call a function. `startandload` also takes a parameter that doesn't seem to be used. I'm also a bit confused as to your reason for running a function called startandload (which seems to be initialization) in an infinite loop; you possibly just want to call it once. Or perhaps: if __name__ == '__main__': startandload() -- https://mail.python.org/mailman/listinfo/python-list
Re: Coding a simple state machine in python
On 25/02/2014 1:27 PM, Tim Daneliuk wrote: On 02/24/2014 08:55 PM, William Ray Wing wrote: On Feb 24, 2014, at 8:30 PM, Ronaldo abhishek1...@gmail.com wrote: How do I write a state machine in python? Stackoverflow has a couple of compact examples here: Now you're making it TOO easy Bill ;) No, the _easy_ solution is: https://pypi.python.org/pypi?%3Aaction=searchterm=state++machinesubmit=search -- https://mail.python.org/mailman/listinfo/python-list
Re: [Baypiggies] Class decorator to capture the creation and deletion of objects
On 25/02/2014 12:34 PM, Chris Angelico wrote: On Tue, Feb 25, 2014 at 1:24 PM, Alex Martelli al...@google.com wrote: At this point, all entries in the table should be deleted; query should return an empty list! You can't actually depend on del resulting in __del__ being called. Mind those attributions, Chris, it was actually Sangeeth Saravanaraj who wrote what you quoted. I'm pretty sure Alex knows all about __del__ :) -- https://mail.python.org/mailman/listinfo/python-list
Re: Functions help
On 23/02/2014 3:43 PM, Scott W Dunning wrote: I had a question regarding functions. Is there a way to call a function multiple times without recalling it over and over. Meaning is there a way I can call a function and then add *5 or something like that? The same way you repeat anything in Python: with a loop construct. for _ in range(5): func() -- https://mail.python.org/mailman/listinfo/python-list
Re: Functions help
On 24/02/2014 11:09 AM, Mark Lawrence wrote: On 24/02/2014 00:55, alex23 wrote: for _ in range(5): func() the obvious indentation error above Stupid cutpaste :( -- https://mail.python.org/mailman/listinfo/python-list
Re: Wikipedia XML Dump
On 28/01/2014 9:45 PM, kevinglove...@gmail.com wrote: I have downloaded and unzipped the xml dump of Wikipedia (40+GB). I want to use Python and the SAX module (running under Windows 7) to carry out off-line phrase-searches of Wikipedia and to return a count of the number of hits for each search. Typical phrase-searches might be of the dog and dog's. I have some limited prior programming experience (from many years ago) and I am currently learning Python from a course of YouTube tutorials. Before I get much further, I wanted to ask: Is what I am trying to do actually feasible? Rather than parsing through 40GB+ every time you need to do a search, you should get better performance using an XML database which will allow you to do queries directly on the xml data. http://basex.org/ is one such db, and comes with a Python API: http://docs.basex.org/wiki/Clients -- https://mail.python.org/mailman/listinfo/python-list
Re: Need Help with Programming Science Project
On 24/01/2014 8:05 PM, theguy wrote: I have a science project that involves designing a program which can examine a bit of text with the author's name given, then figure out who the author is if another piece of example text without the name is given. This sounds like exactly the sort of thing NLTK was made for. Here's an example of using it for this requirement: http://www.aicbt.com/authorship-attribution/ -- https://mail.python.org/mailman/listinfo/python-list
Re: Newbie question. Are those different objects ?
On 21/12/2013 2:00 AM, Mark Lawrence wrote: Shall I write a PEP asking for a language change which requires that that stupid = sign is replaced by a keyword reading something like thenameonthelefthandsideisassignedtheobjectontherighthandside ? I propose: tag obj with name -- https://mail.python.org/mailman/listinfo/python-list
Re: Figuring out what dependencies are needed
On 12/12/2013 4:53 PM, sal i wrote: This is the entire testing file along with the error at the bottom. data = load_from_yahoo() You're _still_ not passing into `load_from_yahoo` either `indexes` or `stocks` parameters, as I tried to point out by highlighting: assert indexes is not None or stocks is not None, Either `indexes` must have a value or stocks must. AssertionError: must specify stocks or indexes Which is exactly what the error is telling you. This isn't a dependency issue. You just need to read the documentation, work out what format it requires indexes or stocks to be specified in, and then pass them to `load_from_yahoo`. Calling it without _any_ arguments will give you the exception you're seeing. Look at the file examples/dual_moving_average.py, it shows you exactly what you need: data = load_from_yahoo(stocks=['AAPL'], indexes={}, start=start, end=end) -- https://mail.python.org/mailman/listinfo/python-list
Re: Comparing values of counter in python 3.3
On 12/12/2013 5:49 PM, Amjad Syed wrote: Hello, I have 2 counters generated from list using Collections.counter() I want to print only key,values in Counter2 which have values then corresponding value in Counter1. E.g Counter1={97:1,99:2,196:2,198:1} Counter2={97:1 ,99:3, 196:1,198:1} # Output [99,3] # Need to compare values of counter and reject in function/routine in value in counter2 is higher then value in counter1 for a current key [(k,Counter2[k]) for k in Counter2 - Counter1] Counters are awesome. -- https://mail.python.org/mailman/listinfo/python-list
Re: Experiences/guidance on teaching Python as a first programming language
On 11/12/2013 8:45 PM, Chris Angelico wrote: A round of applause for jmf, folks, for doing a brilliant impression of the uninformed-yet-fanatical Knight Templar villain! Jacques de Molay, thou are avenged! -- https://mail.python.org/mailman/listinfo/python-list
Re: Figuring out what dependencies are needed
On 11/12/2013 10:44 PM, s...@nearlocal.com wrote: I'm a Python beginner. I want to use it for stats work, so I downloaded Anaconda which has several of the popular libraries already packaged for Mac OS X. Now I'd like to use the backtesting package from zipline (zipline.io), but while running the test script in iPython, I receive the following error: AssertionErrorTraceback (most recent call last) ipython-input-6-f921351f78e2 in module() 1 data = load_from_yahoo() 2 dma = DualMovingAverage() 3 results = dma.run(data) 1) I assume that I'm missing some packages that aren't included in Anaconda, but how do I know which ones to upload? You're not missing a package, you're missing parameters. This is the signature for load_from_yahoo: def load_from_yahoo(indexes=None, stocks=None, start=None, end=None, adjusted=True): The first thing it does is call a helper function `_load_raw_yahoo_data`, which has this assertion: assert indexes is not None or stocks is not None, As you're passing no parameters into `load_from_yahoo`, both `indexes` and `stocks` default to None, so the assertion fails. Take a look at the examples in the zipline library to see what it is expecting. 2) Often I'll just unzip a library file and put the main folder in the iPython folder, but I notice there's usually a setup.py file in the main library folder. I've been ignoring this. Should I be using it? Thanks -- https://mail.python.org/mailman/listinfo/python-list
Re: load_module for import entire package
On 11/12/2013 5:28 PM, Sergey wrote: def get_obj(): pkg = load_package_strict(tmp, basedir) from tmp import main return main.TTT() It is working, but if package code changes on disc at runtime and I call get_obj again, it returns instance of class, loaded for the first time previously. How to replace line from tmp import main by getting properties of pkg? Your `load_package_strict` function loads the `tmp` module and binds it to the name `pkg`. You then use a regular import to load `tmp.main`, which is _cached_; all subsequent occurrences reuse the initially imported value. This should work: def get_obj(): tmp = load_package_strict(tmp, basedir) return tmp.main.TTT() -- https://mail.python.org/mailman/listinfo/python-list
Re: interactive help on the base object
On 10/12/2013 7:37 PM, Mark Lawrence wrote: One of the great joys of reading this list is how wonderfully OT it can get. I have the right to make this statement as I started *THIS* thread. Now what *WERE* we talking about? :) The God Object (or Higgs Object for the non-theists). -- https://mail.python.org/mailman/listinfo/python-list
Re: [OT] Managing Google Groups headaches
On 3/12/2013 5:13 PM, Steven D'Aprano wrote: You poor fools you, this is what happens when you give control of the tools you use to a (near) monopolist whose incentives are not your incentives. To paraphrase Franklin: those who would give up control to purchase convenience deserve neither. A lesson hard learned :( -- https://mail.python.org/mailman/listinfo/python-list
Re: [OT] Managing Google Groups headaches
On 3/12/2013 11:17 AM, Michael Torrie wrote: And Gmail is also becoming less useful to me. I don't want to use hangouts; xmpp and google talk worked just fine. But alas that's disappearing. I really hate Hangouts. If I wanted to use Skype I would be using Skype. I'm also still unable to understand why Google scrapped Reader and kept Groups, although I suspect it's because the latter will eventually integrate more closely with Plus Hangouts. -- https://mail.python.org/mailman/listinfo/python-list
Re: Extending the 'function' built-in class
On 2/12/2013 5:18 AM, G. wrote: Hi, I can't figure out how I can extend the 'function' built-in class. I tried: class test(function): def test(self): print(test) but I get an error. Is it possible ? Others have pointed out that you cannot subclass the function type. Could you explain what you're trying to achieve? It's possible you could use a decorator instead: def test(fn): def _test(): print('test') fn.test = _test return fn @test def foo(): pass foo.test() test (Note that I've only included _test inside the decorator to show that you can create a closure to include the wrapped function, as a way of replicating 'self' in your class definition.) -- https://mail.python.org/mailman/listinfo/python-list
Re: Got a Doubt ! Wanting for your Help ! Plz make it ASAP !
On 27/11/2013 7:12 PM, Antoon Pardon wrote: However that there is no perfect solution doesn't imply we can't expect some effort from those with english as a mother tongue to search for ways in which to express themselves that are more likely to be understood by those who had to learn english as a foreign language than just to use their local idiom/dialect. How do you expect people to know they're using a local idiom? -- https://mail.python.org/mailman/listinfo/python-list
Re: Access and write .mp3 metadata/tags using Python 3
On 27/11/2013 1:41 AM, andonefi...@gmail.com wrote: I also want to be able to read the length of the mp3. For this, try the eyed3 library: import eyed3 mp3 = eyed3.load(r'pygame\examples\data\house_lo.mp3') mp3.info.time_secs 7 https://pypi.python.org/pypi/eyeD3/0.7.4 -- https://mail.python.org/mailman/listinfo/python-list
Re: If you continue being rude i will continue doing this
On 19/11/2013 2:15 AM, Ferrous Cranus wrote: [...] Any chance you could stop acting like a troll and generating new email addresses in an apparent attempt to get around people's filters? You claim you're acting in good faith, so stop appearing to do otherwise. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python classes for reading/writing/parsing MIDI files
On 20/11/2013 12:12 AM, Chris Angelico wrote: On Wed, Nov 20, 2013 at 12:50 AM, Annmarina Nagy anagy4...@gmail.com wrote: the command label gets stuck A bit of context would help hugely. Are you replying to someone else's post? All we have is a subject line. They appear to be resurrecting a 12 year old thread. -- https://mail.python.org/mailman/listinfo/python-list
Re: How can I get the variable to subtract the input please?
On 19/11/2013 9:56 AM, Ed Taylor wrote: This will be very simple to most of you I guess but it's killing me! print (Please type in your age) age = input () leave = 16 print (You have + leave - age + years left at school) I want to have an input where the users age is inserted and then subtracted from the variable age which is set to 16 and the answer displayed as You have x years left at school. Help much appreciated. Hey there, When asking code questions, if you get a traceback it's often handy to include it so we can see exactly what problem you've hit. Luckily, it's pretty obvious here: 1. input() binds a string to 'age', whereas 'leave' is an integer; you cannot subtract a string from an integer, you need to turn the string into an integer first. Try: age = int(input()) 2. With this done, you still have a similar issue: 'leave - age' produces an integer, and you cannot concatenate strings integers. You can use string formatting to take care of this: print(You have {} years left at school.format(leave - age)) There's a lot more to formatting than this, make sure to check out the docs for it: http://docs.python.org/3.1/library/string.html#format-string-syntax Hope this helps. -- https://mail.python.org/mailman/listinfo/python-list
Re: Most discussion on comp.lang.python is about developing with Python
On 14/11/2013 9:48 AM, Steven D'Aprano wrote: I believe that whatever negative effect Nikos the help-vampire is having, it is long ago overwhelmed by the negative of the anti-Nikos vigilantes. I don't know, the anti-Nikos-vigilante vigilantes are beginning to give them a run for their money, especially when their criticisms are just as applicable to their own behaviour. -- https://mail.python.org/mailman/listinfo/python-list
Re: توقيت وموعد اذاعة مباراة الزمالك ووادى دجلة فى نهائى كأس مصر اليوم السبت 9/11/2013 والقنوات الناقلة
On 12/11/2013 6:32 AM, Tony the Tiger wrote: May your woman betray you, your son be gay, and your daughter screw pigs for a living. Now go eat some pork and choke on it, like a good little terrorist. This is completely unacceptable and has no place on this list. -- https://mail.python.org/mailman/listinfo/python-list
Re: datetime question
On 12/11/2013 2:49 PM, Grant Edwards wrote: Don't forget that there are also some differences between American and Imperial whitespace. Since it's ASCII whitespace, you should probably assume American... sys.getsizeof(' ') 34 sys.getsizeof(u' ') 52 bad by design -- https://mail.python.org/mailman/listinfo/python-list
Re: Code with random module faster on the vm than the vm host...
On 9/11/2013 3:48 AM, Pascal Bit wrote: from random import random [...] Running on win7 python 2.7 32 bit it uses around 30 seconds avg. Running on xubuntu, 32 bit, on vmware on windows 7: 20 seconds! The code runs faster on vm, than the computer itself... The python version in this case is 1.5 times faster... I don't understand. What causes this? The random module uses os.urandom, which relies on OS implementations of randomness functionality: On a UNIX-like system this will query /dev/urandom, and on Windows it will use CryptGenRandom(). http://docs.python.org/2/library/os.html#miscellaneous-functions The linux implementation appears to be faster. -- https://mail.python.org/mailman/listinfo/python-list
Re: Code with random module faster on the vm than the vm host...
On 11/11/2013 11:19 AM, Robert Kern wrote: On 2013-11-11 00:49, alex23 wrote: The random module uses os.urandom, No, it doesn't. random.random() is an alias to the random() method on the random.Random class, which uses the Mersenne Twister to generate values. os.urandom() gets called in the initial default seeding, but not for each value. That's what I get for rapidly skimming the module rather than looking at it carefully. Cheers. -- https://mail.python.org/mailman/listinfo/python-list
Re: To whoever hacked into my Database
On 8/11/2013 7:39 AM, Ian Kelly wrote: Unless the Python installation on Nikos' system has become self-aware and is actively objecting to his code, I think that messages like Read a manual and Learn to code inserted into a database (as seen in the images that Nikos linked earlier) would normally suggest a hacker. I just assumed he'd written himself a to-do app and couldn't be bothered with the hussle of creating a separate table to store its items. -- https://mail.python.org/mailman/listinfo/python-list
Re: Show off your Python chops and compete with others
On 8/11/2013 11:02 AM, Roy Smith wrote: Well, if you want to be truly pedantic about it (*), this defines a function without an explicit return and which does not return None: def foo(): raise Exception In [2]: import dis In [3]: dis.dis(foo) 2 0 LOAD_GLOBAL 0 (Exception) 3 RAISE_VARARGS1 6 LOAD_CONST 0 (None) 9 RETURN_VALUE Seeing as we're being pedantic, the function *does* return None, it's just that the return value is never seen because an exception is raise. -- https://mail.python.org/mailman/listinfo/python-list
Re: Show off your Python chops and compete with others
On 8/11/2013 11:54 AM, Roy Smith wrote: Dead code doesn't count. Neither do shifting goalposts. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Practice Problems
On 4/11/2013 12:06 PM, yungwong@gmail.com wrote: Hi, who has some problems to practice using Python? Try http://projecteuler.net/ -- https://mail.python.org/mailman/listinfo/python-list