Re: Newbie Question: Obtain element from list of tuples

2011-12-19 Thread DevPlayer
On Dec 19, 1:46 am, "Frank Millman" wrote: > "Steven D'Aprano" wrote in message > > news:4eeea8eb$0$11091$c3e8...@news.astraweb.com... > > > On Sun, 18 Dec 2011 18:35:47 -0800, alex23 wrote: > > >> Pre-namedtuple, I used to like using named slices for this: > > >>     cPID = slice(19) > >>     pi

Re: python 2.5 and ast

2011-12-02 Thread DevPlayer
On Nov 30, 1:03 pm, Andrea Crotti wrote: > Another thing about the AST, I am having fun trying to for example list > out all > the unused imports. > > I have already a visitor which works quite nicely I think, but now I > would like > to get a way to find all the unused imports, so I need more vis

Re: Using the Python Interpreter as a Reference

2011-12-01 Thread DevPlayer
On Nov 29, 3:04 am, Steven D'Aprano wrote: > On Tue, 29 Nov 2011 12:49:49 +1100, Chris Angelico wrote: > > On Tue, Nov 29, 2011 at 11:54 AM, DevPlayer wrote: > >> To me, I would think the interpreter finding the coder's intended > >> indent wouldn'

Re: Using the Python Interpreter as a Reference

2011-11-28 Thread DevPlayer
> I do not understand why the interpreter preprocesses each logical line > of source code using something as simple as this: correction: I do not understand why the interpreter - does not- preprocess each logical line of source code using something as simple as this: -- http://mail.python.org/m

Re: Using the Python Interpreter as a Reference

2011-11-28 Thread DevPlayer
On Nov 27, 6:55 pm, Steven D'Aprano wrote: > On Sun, 27 Nov 2011 14:21:01 -0800, Travis Parks wrote: > > Personally, I find a lot of good things in Python. I thinking tabs are > > out-of-date. Even the MAKE community wishes that the need for tabs would > > go away and many implementations have don

Re: python shell that saves history of typed in commands that will persist between reboots

2011-11-27 Thread DevPlayer
On Nov 15, 10:38 pm, goldtech wrote: > Hi, > > Using Windows. Is there a python shell that has a history of typed in > commands? > > I don't need output of commands just what I typed it. I need it to > save between sessions - something that no shell seems to do. If I > reboot there will still be a

Re: String splitting by spaces question

2011-11-23 Thread DevPlayer
This is an 'example string' Don't for get to watch for things like: Don't, Can't, Won't, I'll, He'll, Hor'davors, Mc'Kinly -- http://mail.python.org/mailman/listinfo/python-list

Re: Is there any way to unimport a library

2011-11-23 Thread DevPlayer
btw if you like processing text outside of python (say using grep or something) python -c "help('modules')" > all_imports.log which you might note on windows get's processed to: python -c "help('modules')" 1> all_imports.log on windows from within a batch file -- http://mail.python.org/mailman/

Re: Is there any way to unimport a library

2011-11-23 Thread DevPlayer
Seems so far the common way to fully unload any import is to exit the Python session. Only if this is true do I offer this hackish idea: Therefore you might wish to run an os script instead of a python script right off. Here is my hack at it... Something like this: file myapp.bat -- p

Re: Is there any way to unimport a library

2011-11-21 Thread DevPlayer
On Nov 20, 12:21 pm, Gelonida N wrote: > I forgot to mention, that this is at the moment more a thought > experiment, than a real need. > > At the moment I will do exactly what you suggested. I will make sure, > that always the first import fails. > > But I wanted to learn more what is possible an

Re: simple import hook

2011-11-14 Thread DevPlayer
An alternative approach: http://pastebin.com/z6pNqFYE or: # devpla...@gmail.com # 2011-Nov-15 # recordimports.py # my Import Hook Hack in response to: # http://groups.google.com/group/comp.lang.python/browse_thread/thread/5a5d5c724f142eb5?hl=en # as an initial learning exercise # This code ne

Re: Opportunity missed by Python ?

2011-11-14 Thread DevPlayer
What I don't get is, having seen Python's syntax with indentation instead of open and closing puncuation and other -readability- structures in Python's syntax, is if someone is going to invent any new language, how could they NOT take Python's visual structures (read as readability) and copy it, wh

Re: Usefulness of the "not in" operator

2011-11-06 Thread DevPlayer
On Oct 16, 12:05 am, Steven D'Aprano wrote: > On Sat, 15 Oct 2011 15:04:24 -0700, DevPlayer wrote: > > I thought "x not in y" was later added as syntax sugar for "not x in y" > > meaning they used the same set of tokens. (Too lazy to check the actual > &

Re: How to mix-in __getattr__ after the fact?

2011-11-01 Thread DevPlayer
On Oct 31, 8:01 am, dhyams wrote: > Thanks for all of the responses; everyone was exactly correct, and > obeying the binding rules for special methods did work in the example > above.  Unfortunately, I only have read-only access to the class > itself (it was a VTK class wrapped with SWIG), so I ha

Re: Review Python site with useful code snippets

2011-10-31 Thread DevPlayer
When visitors visit your site to post their code; often such posts ask for username and email address; consider adding additional fields to generate some Python documenting feature like Sphinx or epydoc. and let your site inject the docstring (module string) into the snippet; primarily, author, u

Re: locate executables for different platforms

2011-10-31 Thread DevPlayer
On Oct 31, 10:00 am, Andrea Crotti wrote: > Suppose that I have a project which (should be)/is multiplatform in python, > which, however, uses some executables as black-boxes. > > These executables are platform-dependent and at the moment they're just > thrown inside the same egg, and using pkg_re

Re: Dynamically creating properties?

2011-10-30 Thread DevPlayer
To be honest, I was hoping someone would have posted a link to a well known and tested recipe. You'd think this function would be in the standard library or a specific Exception tied directly with setattr() and getattr() (and possibly __getattr__(), __getattribute__(), __setattr__()) The main thin

Re: Dynamically creating properties?

2011-10-27 Thread DevPlayer
Second error def isvalid_named_reference( astring ): # "varible name" is really a named_reference import __builtin__# add line -- http://mail.python.org/mailman/listinfo/python-list

Re: Dynamically creating properties?

2011-10-27 Thread DevPlayer
At least one error: change: > for astr in dir(__builtins__): to: for astr in __builtins__.__dict__: -- http://mail.python.org/mailman/listinfo/python-list

Re: Dynamically creating properties?

2011-10-27 Thread DevPlayer
Personally I like to use this function instead of a "try: except:" because try-except will allow names like __metaclass__. Remember, setattr(obj, attr_name, value) allows attr_name to be any valid str(). For example: '!@kdafk11', or '1_1', '1e-20', '0.0', '*one', '\n%%', etc. def isvalid_named_re

Re: Dynamically creating properties?

2011-10-27 Thread DevPlayer
On Oct 27, 3:59 pm, Andy Dingley wrote: > I have some XML, with a variable and somewhat unknown structure. I'd > like to encapsulate this in a Python class and expose the text of the > elements within as properties. > > How can I dynamically generate properties (or methods) and add them to > my cl

Re: Benefit and belief

2011-10-17 Thread DevPlayer
On Oct 17, 10:34 am, Steven D'Aprano wrote: > On Mon, 17 Oct 2011 05:59:04 -0700, DevPlayer wrote: > > As has been said for example does 1+1 = 2. Only in one small > > persepective. Whaa? what wack job says stuff like that? 1+1 = 10. In the > > bigger picture there is m

Re: Benefit and belief

2011-10-17 Thread DevPlayer
> DevPlayer  wrote: > >I still assert that contradiction is caused by narrow perspective. > >By that I mean: just because an objects scope may not see a certain > >condition, doesn't mean that condition is non-existant. > Groetjes Albert wrote: > This is a far

Re: Usefulness of the "not in" operator

2011-10-15 Thread DevPlayer
On Oct 8, 8:41 am, Alain Ketterlin wrote: > candide writes: > > Python provides > > >     -- the not operator, meaning logical negation > >     -- the in operator, meaning membership > > > On the other hand, Python provides the not in operator meaning > > non-membership. However, it seems we can

Re: I am a newbie for python and try to understand class Inheritance.

2011-10-15 Thread DevPlayer
On Oct 15, 2:20 am, aaabb...@hotmail.com wrote: > Test.py > --- > #!/usr/bin/python > > from my_lib import my_function > > class MyClass(my_function): # usually class names start capital > > """We know you're not forgetting to document.""" > >     def __init__(self, name): > sup

Re: Can I search a list for a range of values?

2011-10-15 Thread DevPlayer
On Oct 14, 7:46 pm, Ian Kelly wrote: > On Fri, Oct 14, 2011 at 5:36 PM, Troy S wrote: > (Python 3) > date_range = {d:v for d, v in source_dict.items() if '20110809' <= d > <= '20110911'} > Ian- Hide quoted text - > - Show quoted text - (Python 2.7) supports dictionary comprehensions. I prehaps a

Re: Benefit and belief

2011-09-30 Thread DevPlayer
I still assert that contradiction is caused by narrow perspective. By that I mean: just because an objects scope may not see a certain condition, doesn't mean that condition is non-existant. I also propose that just because something seems to contradict doesn't mean it is false. Take for instance

Re: Benefit and belief

2011-09-30 Thread DevPlayer
from attitude import humour Funny. url link to gif. Funny. Youtube video. Funny. True Pythonees do not speak in English they speak in Python. Shame, this discussion will be sent to the Pearly gates or the Flaming Iron Bars in 5 days. Well, not so much a shame. -- http://mail.python.org/mailman

Re: Suggested coding style

2011-09-28 Thread DevPlayer
Oh I was just testing my intellecual-enlightenment-from-ranter- conversation algorithm found in a previous post. I think my OOP model failed as I'm just too tired to finished that pattern test. He had some good points which fit the process I layed out. But the original topic is just so much better:

Re: Suggested coding style

2011-09-28 Thread DevPlayer
On Sep 27, 10:25 pm, alex23 wrote: > rantingrick wrote: > > Since, like the bible > > the zen is self contradicting, any argument utilizing the zen can be > > defeated utilizing the zen. > > And like the Bible, the Zen was created by humans as a joke. If you're > taking it too seriously, that's y

Re: Suggested coding style

2011-09-26 Thread DevPlayer
By the way OP Passiday the title of the topic is "Suggested coding style". Are you suggesting a coding style or asking for a Python coding style or are you asking what IS the Python coding style. If you are asking what is the Python coding style. Google The Zen of Python. It's pretty much the dic

Re: Suggested coding style

2011-09-26 Thread DevPlayer
On Sep 25, 11:41 pm, Chris Angelico wrote: > On Mon, Sep 26, 2011 at 12:59 PM, Tim Johnson wrote: > > BTW: If you like ranting as a spectator sport, I have found the > >  Common Lisp newsgroup to be among the most spectacular. But that's > >  just me. > > I do, actually, but I don't need to add a

Re: How to populate all possible hierarchical clusterings from a set of elements?

2011-01-13 Thread DevPlayer
Ah. out of my depth. -- http://mail.python.org/mailman/listinfo/python-list

Re: How to populate all possible hierarchical clusterings from a set of elements?

2011-01-13 Thread DevPlayer
tuple([ (tuple(lst[x-1:x+1]) if len(tuple(lst[x-1:x+1]))==2 else lst[x-1]) for x in lst[::2]]) ((1, 2), (3, 4), 5) # or x = ((tuple(lst[x-1:x+1]) if len(tuple(lst[x-1:x+1]))==2 else lst[x-1]) for x in lst[::2]) x.next() (1, 2) x.next() (3, 4) x.next() 5 -- http://mail.python.org/mailman/listinf

Re: How to populate all possible hierarchical clusterings from a set of elements?

2011-01-13 Thread DevPlayer
def maketup(lst): if len(lst) == 1: return lst[0] elif len(lst) == 2: return (lst[0],lst[1]) elif len(lst) > 2: return ( (maketup(lst[:-2]), lst[-2]), lst[-1]) maketup(lst) 1, 2), 3), 4), 5) -- http://mail.python.org/mailman/listinfo/python-list

Re: How to populate all possible hierarchical clusterings from a set of elements?

2011-01-13 Thread DevPlayer
lst = [1, 2, 3, 4, 5] def maketup(lst): cur_item = lst[-1] lst = lst[:-1] if len(lst): return maketup(lst), cur_item else: return cur_item print maketup(lst) 1, 2), 3), 4), 5) But I'm confused as to what you mean by : > Among them, I want to pair up terminals

Re: Nested structures question

2011-01-12 Thread DevPlayer
looping = True while looping: guess = int(raw_input("Take a guess: ")) tries += 1 if guess > the_number: print "Lower..." elif guess < the_number: print "Higher..." else: print "You guessed it! The number was", the_number print "And it only took y

Re: Which coding style is better? public API or private method inside class definition

2011-01-12 Thread DevPlayer
On Jan 4, 11:46 pm, Inyeol wrote: > Which coding style do you prefer? I'm more toward public API way, > since it requires less code change if I refactor private data > structure later. > Plz give pros and cons of these. Great question. It gets at the heart of Python style. It's a tricky question

Re: list 2 dict?

2011-01-04 Thread DevPlayer
The shorter version: This doesn't need any x = iter(list) line. perhaps more useful if you have a bunch of lists to be converted through out your code. def dictit(lyst): i = 0 while i < len(lyst): yield lyst[i], lyst[i+1] i = i + 2 l = [1, 2, 3, 4, 5, 6, 7, 'a', 8, 'b'] {

Re: list 2 dict?

2011-01-04 Thread DevPlayer
Here is something totally the opposite of a nice one liner: A hackish module with a bloated generator. Feel free to comment, so I can learn the errors of my ways. Try not to be too mean though. Try to think of the attached file as a demonstration of ideas instead of good coding practices. Don't b

Re: Matrix multiplication

2011-01-04 Thread DevPlayer
See section titled: "'array' or 'matrix'? Which should I use?" at http://www.scipy.org/NumPy_for_Matlab_Users BTW http://www.python.org/dev/peps/pep-0211/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Matrix multiplication

2011-01-04 Thread DevPlayer
BTW http://www.python.org/dev/peps/pep-0211/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Matrix multiplication

2011-01-04 Thread DevPlayer
I would be very suprised if you achieve faster results threading this problem. There's been much discussed on benefits or lack thereof to threading in Python (or in general). Threading is best used in situations where you are doing different kinds of tasks. For example if you want to do your matri

Re: Python comparison matrix

2011-01-04 Thread DevPlayer
Awesome, thanks so much for you efforts and sharing. Idea: It would be great if we put this table into a python program where I can run a script against this table and a Python source code module (file) so that it would spit out a list of strings showing what python versions work with said source

Re: list 2 dict?

2011-01-04 Thread DevPlayer
or only convert the item when you need it leaving the lists as the source lyst = [1, 2, 3, 4, 5, 6, 7, 'a', 8, 'b'] func = lambda alist, index: dict([(lyst[index*2], lyst[(index*2)+1]),]) func(lyst, 0) {1: 2} func(lyst, 2) {5: 6} ## or as a function def func(lyst, index):

Re: list 2 dict?

2011-01-03 Thread DevPlayer
An adaptation to Hrvoje Niksic's recipe Use a dictionary comprehention instead of a list comprehension or function call: lyst = [1, 2, 3, 4, 5, 6, 7, 'a', 8, 'b'] it = iter( lyst ) dyct = {i:it.next() for i in it} # I'm using {} and not [] for those with tiny fonts. #print dyct {8: 'b', 1: 2,

Re: Multiple instances and wrong parental links

2011-01-03 Thread DevPlayer
Mere are my ramblings of a novice (bad) Hobbyst programmer. You mentioned that your having a hard time coming up with a solution to your complex problem. Complex means you are doing lots of different things to different things all over the place where timing is an issue. First it seems you are t

Re: default argument in method

2010-12-31 Thread DevPlayer
I agree with you Steven that the OP should avoid __getattribute__ and the like for many a thing. I also agree with your last statement. I try to answer the OP's question without much "You shouldn't do this's and don't do that's". I trust them to make thier own decisions. I'd say "A much better solu

Re: default argument in method

2010-12-30 Thread DevPlayer
There's some_object.some_method.func_defaults and some_function.func_defaults both are a settable attribute. How to set the methods func_defaults? You'd have to have code in _getattribute__(yourmethod) if not __getattr__(yourmethod) def __getattribute__(self, attr): if attr == self.my_method:

Re: Dynamic list name from a string

2010-12-28 Thread DevPlayer
# dynamic_named_obj.py # comp.lang.python # 2010-12 Dec-28 # Topic: Dynamic list name from a string Options # attempts to answer OP's question # DevPlayer - not a solution I'd use # TO Original Poster OP: # Start from the bottom OPTION, the one you requested. # Work your way up and

Re: Partition Recursive

2010-12-27 Thread DevPlayer
# parse_url11.py # devpla...@gmail.com # 2010-12 (Dec)-27 # A brute force ugly hack from a novice programmer. # You're welcome to use the code, clean it up, make positive suggestions # for improvement. """ Parse a url string into a list using a generator. """ #special_itemMeaning = ";?:@=&#."

Re: How can a function find the function that called it?

2010-12-25 Thread DevPlayer
> Original Poster > I thought I'd implement it as a subclass of collections.OrderedDict > that prohibits all modifications to the dictionary after it has > been initialized. I thought the __new__() method was for customizing how objects where instantated. Where in __new__() you would get an object

Python on wikipedia

2010-12-12 Thread DevPlayer
Snapshot in time, hey look at that; someone used Python as THE example of what a programming language is on Wikipedia. http://en.wikipedia.org/wiki/Programming_language -- http://mail.python.org/mailman/listinfo/python-list

Re: Replacing globals in exec by custom class

2010-12-08 Thread DevPlayer
Shouldn't return 'xx' be return self['xx' I don't know why precisely you're using a class as a global namespace, not that I personally find fault with it. But here are some other things you can do. Idea one: == class NS(object): """plac

Re: Replacing globals in exec by custom class

2010-12-08 Thread DevPlayer
Shouldn't return 'xx' be return self['xx'] -- http://mail.python.org/mailman/listinfo/python-list

Re: Replacing globals in exec by custom class

2010-12-08 Thread DevPlayer
Couple of things: I don't think this is what you want: def __getitem__(self, key): import __builtin__ if key == 'xx': return 'xx' I won't return a KeyError for any string you give g[] It will return 'xx' only if you supply key='xx' and ignore every other key=??? Wit