Re: Future standard GUI library

2013-05-19 Thread Vito De Tullio
Terry Jan Reedy wrote: >> Do you think tkinter is going to be the standard python built-in gui >> solution as long as python exists? > > AT the moment, there is nothing really comparable that is a realistic > candidate to replace tkinter. FLTK? (http://www.fltk.org/index.php) -- ZeD -- http:

Re: Short-circuit Logic

2013-05-26 Thread Vito De Tullio
Cameron Simpson wrote: > if s is not None and len(s) > 0: > ... do something with the non-empty string `s` ... > > In this example, None is a sentinel value for "no valid string" and > calling "len(s)" would raise an exception because None doesn't have > a length. obviously in this case an

Re: Python error codes and messages location

2013-05-27 Thread Vito De Tullio
Fábio Santos wrote: >> This should make life easier for us > http://docs.python.org/3/whatsnew/3.3.html#pep-3151-reworking-the-os-and-io-exception-hierarchy > > Speaking of PEPs and exceptions. When do we get localized exceptions? What do you mean by "localized exceptions"? Please, tell me it's

Re: Python error codes and messages location

2013-05-27 Thread Vito De Tullio
Fábio Santos wrote: >> > > Speaking of PEPs and exceptions. When do we get localized exceptions? >> > >> > What do you mean by "localized exceptions"? >> > >> > Please, tell me it's *NOT* a proposal to send the exception message in >> > the >> > locale language! >> It is. I think I read it mention

Re: PyWart: The problem with "print"

2013-06-03 Thread Vito De Tullio
Rick Johnson wrote: > Take your > standard yes/no/cancel dialog, i would expect it to return > True|False|None respectively, you clearly mean True / False / FileNotFound. ( http://thedailywtf.com/Articles/What_Is_Truth_0x3f_.aspx ) -- ZeD -- http://mail.python.org/mailman/listinfo/python-lis

a little more explicative error message?

2013-07-15 Thread Vito De Tullio
Hi I was writing a decorator and lost half an hour for a stupid bug in my code, but honestly the error the python interpreter returned to me doesn't helped... $ python3 Python 3.3.0 (default, Feb 24 2013, 09:34:27) [GCC 4.7.2] on linux Type "help", "copyright", "credits" or "license" for more i

Re: PEP8 79 char max

2013-07-30 Thread Vito De Tullio
Ed Leafe wrote: > I had read about a developer who switched to using proportional fonts for > coding, and somewhat skeptically, tried it out. After a day or so it > stopped looking strange, and after a week it seemed so much easier to > read. By my (limited) experience with proportional fonts, th

Re: PEP8 79 char max

2013-07-30 Thread Vito De Tullio
Joshua Landau wrote: >> By my (limited) experience with proportional fonts, they can be useful >> only with something like elastic tabstops[0]. But, as a general rule, I >> simply found more "squared" to just use a fixed-width font. > Not if you give up on the whole "aligning" thing. and this i

Re: Safely add a key to a dict only if it does not already exist?

2013-01-18 Thread Vito De Tullio
Steven D'Aprano wrote: > I wish to add a key to a dict only if it doesn't already exist, but do it > in a thread-safe manner. > > The naive code is: > > if key not in dict: > dict[key] = value > > > but of course there is a race condition there: it is possible that > another thread may hav

Re: Safely add a key to a dict only if it does not already exist?

2013-01-18 Thread Vito De Tullio
Chris Rebert wrote: >> How can I add a key in a thread-safe manner? > I'm not entirely sure, but have you investigated dict.setdefault() ? but how setdefault makes sense in this context? It's used to set a default value when you try to retrieve an element from the dict, not when you try to set

Re: Safely add a key to a dict only if it does not already exist?

2013-01-19 Thread Vito De Tullio
Peter Otten wrote: How can I add a key in a thread-safe manner? >>> I'm not entirely sure, but have you investigated dict.setdefault() ? >> >> but how setdefault makes sense in this context? It's used to set a >> default value when you try to retrieve an element from the dict, not when >> yo

Re: Safely add a key to a dict only if it does not already exist?

2013-01-19 Thread Vito De Tullio
Peter Otten wrote: uhhmm.. I think I misread the example d = {} d.setdefault(1, 2) > 2 d > {1: 2} d.setdefault(1, 3) > 2 d > {1: 2} yeah, sure it can be useful for the OP... -- ZeD -- http://mail.python.org/mailman/listinfo/python-list

Re: Increase value in hash table

2013-01-24 Thread Vito De Tullio
moonhkt wrote: > Data file > V1 > V2 > V3 > V4 > V4 > V3 > > How to using count number of data ? > > Output > V1 = 1 > V2 = 1 > V3 =2 > V4 = 2 import collections with open(data_file) as f: print(collections.Counter(f.readlines())) it's a start -- ZeD -- http://mail.python.org/mai

Re: Retrieving an object from a set

2013-01-25 Thread Vito De Tullio
MRAB wrote: > It turns out that both S & {x} and {x} & S return {x}, not {y}. curious. $ python Python 2.7.3 (default, Jul 3 2012, 19:58:39) [GCC 4.7.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> x = (1,2,3) >>> y = (1,2,3) >>> s = set([y]) >>> (s & se

Re: Comparing offset-aware and offset-naive datetimes?

2013-01-26 Thread Vito De Tullio
Roy Smith wrote: > I have two datetimes. One is offset-naive. The other is offset-aware, > but I happen to know its offset is 0 (i.e. GMT). How can I compare > these? http://pytz.sourceforge.net/#localized-times-and-date-arithmetic -- ZeD -- http://mail.python.org/mailman/listinfo/python-l

Re: How to compute a delta: the difference between lists of strings

2012-05-05 Thread Vito De Tullio
J. Mwebaze wrote: > This is out of curiosity, i know this can be done with python diffllib > module, but been figuring out how to compute the delta, Consider two lists > below. > > s1 = ['e', 'f', 'g', 'A', 'B', 'C', 'D', 'C'] > s2 =['e', 'A', 'B', 'f', 'g', 'C', 'D', 'z'] > > This is the result

Re: GUI toolkits and dynamic table browser widget

2012-05-18 Thread Vito De Tullio
Simon Cropper wrote: >>> I would like to create windows with grids (AKA rows and column of a >>> table like excel). Do any of the GUI interfaces have these types of >>> widgets? i have looked but can't find any and I have not stumbled on >>> program that presents data in this way so I can see how

Re: Best way to insert sorted in a list

2011-06-19 Thread Vito De Tullio
SherjilOzair wrote: > There are basically two ways to go about this. [...] > What has the community to say about this ? What is the best (fastest) > way to insert sorted in a list ? a third way maybe using a SkipList instead of a list on http://infohost.nmt.edu/tcc/help/lang/python/examples/py

Re: ANN: dedent 0.5 released

2016-09-29 Thread Vito De Tullio
Christian Tismer wrote: > $ python -c """some code""" totally offtopic but... since when bash support python-style triple quote?? Is it another shell?? -- By ZeD -- https://mail.python.org/mailman/listinfo/python-list

Re: ESR "Waning of Python" post

2018-10-12 Thread Vito De Tullio
Chris Angelico wrote: >> Reference counting was likely a bad idea to begin with. > > Then prove CPython wrong by making a fantastically better > implementation that uses some other form of garbage collection. I'm not talking about the "goodness" of the implemetations, but AFAIK jython and ironp

Re: repeat items in a list

2016-03-29 Thread Vito De Tullio
Random832 wrote: > How do you turn ['a', 'c', 'b'] into ['a', 'a', 'a', 'c', 'c', 'c', 'b', > 'b', 'b']? >>> sum([[e]*3 for e in ['a', 'c', 'b']], []) ['a', 'a', 'a', 'c', 'c', 'c', 'b', 'b', 'b'] -- By ZeD -- https://mail.python.org/mailman/listinfo/python-list

Re: [OT] C# -- sharp or carp? was Re: Learning Python (or Haskell) makes you a worse programmer

2016-03-29 Thread Vito De Tullio
Sven R. Kunze wrote: >>> My question to those who know a bit of C#: what is the state-of-the-art >>> equivalent to >>> >>> "\n".join(foo.description() for foo in mylist >>> if foo.description() != "") > Friend of mine told me something like this: > > String.Join("\n", m

Re: Drowning in a teacup?

2016-04-01 Thread Vito De Tullio
Fillmore wrote: > I need to scan a list of strings. If one of the elements matches the > beginning of a search keyword, that element needs to snap to the front > of the list. I know this post regards the function passing, but, on you specific problem, can't you just ... sort the list with a cust

Re: Drowning in a teacup?

2016-04-01 Thread Vito De Tullio
Michael Selik wrote: >> > I need to scan a list of strings. If one of the elements matches the >> > beginning of a search keyword, that element needs to snap to the front >> > of the list. >> >> I know this post regards the function passing, but, on you specific >> problem, >> can't you just ... s

Re: how to setup for localhost:8000

2016-04-14 Thread Vito De Tullio
Chris Angelico wrote: >> Just a note, some browsers will try to resolve this as www.localhost.com >> - try http://127.0.0.1:8000 . > > Huh? Why should the name 'localhost' get a dot com added? ask browser vendors... -- By ZeD -- https://mail.python.org/mailman/listinfo/python-list

Re: Highlighting program variables instead of keywords?

2014-01-27 Thread Vito De Tullio
Skip Montanaro wrote: > My son sent me a link to an essay about highlighting program data instead > of keywords: > > https://medium.com/p/3a6db2743a1e/ > > I think this might have value, especially if to could bounce back and > forth between both schemes. Is anyone aware of tools like this for P

Re: (test) ? a:b

2014-10-22 Thread Vito De Tullio
Dennis Lee Bieber wrote: >> x = [f(), g()] [cond] >> >>the latter evaluates both f() and g() instead of just one. Apart from >>being inefficient, it can have unintended side-effects. > > Ah, but what would > > x = [f, g][cond]() > > produce? headache -- By ZeD -- https://mail.python.org/m

Re: How about some syntactic sugar for " __name__ == '__main__' "?

2014-11-16 Thread Vito De Tullio
Steven D'Aprano wrote: > Chris Kaynor wrote: > >> I was thinking along the lines of replacing: >> >> if __name__ == "__main__": >> <<>> >> >> with >> >> @main >> def myFunction() >> <<<> >> >> Both blocks of code will be called at the same time. > > > You can't guarantee that, because you c

Re: How about some syntactic sugar for " __name__ == '__main__' "?

2014-11-16 Thread Vito De Tullio
Ian Kelly wrote: >> def main(func): >> if func.__module__ == "__main__": >> func() >> return func # The return could be omitted to block the function from >> being manually called after import. >> >> Just decorate the "main" function of the script with that, and it will be >> a

Re: learning to use iterators

2014-12-24 Thread Vito De Tullio
Seb wrote: def n_grams(a, n): > ... z = (islice(a, i, None) for i in range(n)) > ... return zip(*z) > ... > > I'm impressed at how succinctly this islice helps to build a list of > tuples with indices for all the required windows. If you want it succinctly, there is this variation o

Re: dunder-docs (was Python is DOOMED! Again!)

2015-02-01 Thread Vito De Tullio
Steven D'Aprano wrote: > Checking the REPL first would have revealed that [].__dir__ raises > AttributeError. In other words, lists don't have a __dir__ method. ? Python 3.4.2 (default, Nov 29 2014, 00:45:45) [GCC 4.8.3] on linux Type "help", "copyright", "credits" or "license" for more informa

Re: pymongo and attribute dictionaries

2015-02-04 Thread Vito De Tullio
Steven D'Aprano wrote: >> This just does not roll of the fingers well. Too many “reach for modifier >> keys” in a row. > > *One* modifier key in a row is too many? > > s o m e SHIFT D o c [ ' SHIFT _ i d ' ] I'm not OP, but as side note... not everyone has "[" as a direct character on the keyb

Re: Does Python 'enable' poke and hope programming?

2013-08-01 Thread Vito De Tullio
CM wrote: > Basically this amounts to: with an interpreted language (so of course > this is not really just about Python--I just think in terms of Python), > it's easier to be mentally lazy. But, ironically, being lazy winds up > creating *way* more work ultimately, since one winds up programmin

Re: Can someone suggest better resources for learning sqlite3? I wanted to use the Python library but I don't know sql.

2013-08-03 Thread Vito De Tullio
Aseem Bansal wrote: > I have tried sql.learncodethehardway but it isn't complete yet. I tired > looking on stackoverflow's sql tag also but nothing much there. Can > someone suggest me better resources for learning sql/sqlite3? a start is the sqlite homepage: http://www.sqlite.org/docs.html --

Re: new to While statements

2013-08-06 Thread Vito De Tullio
Joshua Landau wrote: > while "asking for reponse": > while "adventuring": that's a funny way to say `while True:`... -- By ZeD -- http://mail.python.org/mailman/listinfo/python-list

Re: new to While statements

2013-08-07 Thread Vito De Tullio
Dan Sommers wrote: >>> while "asking for reponse": >> >>> while "adventuring": >> >> that's a funny way to say `while True:`... > > Funny, perhaps, the first time you see it, but way more informative than > the other way to the next one who comes along and reads it. While I und

Re: Language design

2013-09-13 Thread Vito De Tullio
Chris Angelico wrote: > Making line breaks significant usually throws people. It took my > players a lot of time and hints to figure this out: > http://rosuav.com/1/?id=969 fukin' Gaston! -- By ZeD -- https://mail.python.org/mailman/listinfo/python-list

Re: Functional Programming and python

2013-09-23 Thread Vito De Tullio
rusi wrote: > [Not everything said there is correct; eg python supports currying better > [than haskell which is surprising considering that Haskell's surname is > [Curry!] AFAIK python does not support currying at all (if not via some decorators or something like that). Instead every function

Re: Obfuscated factorial

2013-10-26 Thread Vito De Tullio
Steven D'Aprano wrote: > Just for fun: [...] you miss a FactoryFactory and a couple of *Manager. Oh, and it should be xml-config-driven. -- By ZeD -- https://mail.python.org/mailman/listinfo/python-list

Re: Obfuscated factorial

2013-10-27 Thread Vito De Tullio
Joshua Landau wrote: > Python already supports the factorial operator, -ⵘ. why use ⵘ (TIFINAGH LETTER AYER YAGH) when you can have the BANG? 방 (HANGUL SYLLABLE BANG) > You just have to > import it. > > # Import statement > ⵘ = type("",(),{"__rsub__":lambda s,n:(lambda f,n:f(f,n))(lambda > f,z

Re: should "self" be changed?

2015-05-26 Thread Vito De Tullio
Mark Lawrence wrote: >> def __init__(ስ): >> ስ.dummy = None > Apart from breaking all the tools that rely on "self" being spelt "self" > this looks like an excellent idea. too bad for the tools: using the name "self" is just a convention, not a rule. -- By ZeD -- https://mail.pyt

Re: Python Newbie

2013-02-24 Thread Vito De Tullio
piterrr.dolin...@gmail.com wrote: > You see, Javascript, for one, behaves the same way as Python (no variable > declaration) but JS has curly braces and you know the variable you have > just used is limited in scope to the code within the { }. With Python, you > have to search the whole file. I d

Re: An error when i switched from python v2.6.6 => v3.2.3

2013-03-07 Thread Vito De Tullio
Νίκος Γκρ33κ wrote: >> -c ''; rm -rf /; oops.py > > Yes its being pulled by http request! > > But please try to do it, i dont think it will work! try yourself and tell us what happened -- ZeD -- http://mail.python.org/mailman/listinfo/python-list

Re: pyqt4 & qt license

2013-03-09 Thread Vito De Tullio
D. Xenakis wrote: > Can someone develop a closed source but NON-commercial software, by using > PyQT4 GPL license? no, by definition of GPL: if you are using a GPL library, you must distribute your software as GPL. (the GPL does not care about commercial / non commercial) http://www.gnu.org/li

Re: vb2py status?

2009-01-17 Thread Vito De Tullio
axtens wrote: > So is vb2py dead? If not, any idea when it'll support python 3? I don't know this vb2py, but you can do a 2 pass conversion [vb] -> (vb2py) -> [py2] -> (2to3) -> [py3] -- By ZeD -- http://mail.python.org/mailman/listinfo/python-list

Re: vb2py status?

2009-01-17 Thread Vito De Tullio
Giampaolo Rodola' wrote: >> > So is vb2py dead? If not, any idea when it'll support python 3? >> I don't know this vb2py, but you can do a 2 pass conversion >> [vb] -> (vb2py) -> [py2] -> (2to3) -> [py3] > ...and presumibly get something which doesn't work at all. =) why? AFAIK there aren't probl

Re: Removing None objects from a sequence

2008-12-12 Thread Vito De Tullio
Filip Gruszczyński wrote: > I checked itertools, but the only thing that > seemed ok, was ifilter - this requires seperate function though, so > doesn't seem too short. is this too much long? >>> from itertools import ifilter >>> for element in ifilter(lambda x: x is not None, [0,1,2,None,3,Non

Re: Why is lambda allowed as a key in a dict?

2009-03-10 Thread Vito De Tullio
MRAB wrote: > >>> (lambda arg: arg) == (lambda arg: arg) > False curious... I somehow thinked that, whereas >>> (lambda: 0) is (lambda: 0) should be False (obviously) >>> (lambda: 0) == (lambda: 0) could be True... maybe because `{} == {} and {} is not {}` (also for []) -- By ZeD -- http://

Re: How complex is complex?

2009-03-20 Thread Vito De Tullio
Tim Roberts wrote: > bearophileh...@lycos.com wrote: >> >>In Python 3 those lines become shorter: >> >>for k, v in a.items(): >>{k: v+1 for k, v in a.items()} > > That's a syntax I have not seen in the 2-to-3 difference docs, so I'm not > familiar with it. How does that cause "a" to be updated?

Re: Reading 3 objects at a time from list

2009-04-11 Thread Vito De Tullio
Matteo wrote: > it works and I like slices, but I was wondering if there was another > way of doing the same thing, maybe reading the numbers in groups of > arbitrary length n... from http://docs.python.org/library/itertools.html#recipes def grouper(n, iterable, fillvalue=None): "grouper(3,

Re: Man Bites Python

2009-04-17 Thread Vito De Tullio
Mikael Olofsson wrote: > I don't think the guy in question finds it that funny. I don't think the python in question finds it that funny. -- By ZeD -- http://mail.python.org/mailman/listinfo/python-list

problem with pylint + PyQt4

2009-05-29 Thread Vito De Tullio
I'm having probles using pylint on a PyQt4 application. $ cat TEST_pylint.py import PyQt4.QtCore from PyQt4.QtGui import QApplication $ python TEST_pylint.py # no import errors $ pylint --disable-msg=C0103 --disable-msg=C0111 --disable-msg=W0611 \ > TEST_pylint.py **

Re: how can i check whether a variable is iterable in my code?

2008-09-20 Thread Vito De Tullio
satoru wrote: > hi, all > i want to check if a variable is iterable like a list, how can i > implement this? untested def is_iterable(param): try: iter(param) except TypeError: return False else: return True -- By ZeD -- http://mail.python.org/mailman/listinfo/python-list

Re: Perl's @foo[3,7,1,-1] ?

2009-06-13 Thread Vito De Tullio
Jack Diederich wrote: > the square brackets always expect an int or a slice. true only for lists :) In [1]: mydict = {} In [2]: mydict[1,2,3] = 'hi' In [3]: print mydict[1,2,3] --> print(mydict[1,2,3]) hi -- By ZeD -- http://mail.python.org/mailman/listinfo/python-list