Extending dict (dict's) to allow for multidimensional dictionary
I can extend dictionary to allow for the my own special look-up tables. However now I want to be able to define multidimensional dictionary which supports look-up like this: d[1]['abc'][40] = 'dummy' and if d[1] and d[1][abc] raise KeyError just create them. for d[1] I can override __getitem__() but how to do the same for the d[1][abc]? -- http://mail.python.org/mailman/listinfo/python-list
Re: Extending dict (dict's) to allow for multidimensional dictionary
I found a solution here: http://parand.com/say/index.php/2007/07/13/simple-multi-dimensional-dictionaries-in-python/ Please tell how good is it? -- http://mail.python.org/mailman/listinfo/python-list
Re: Extending dict (dict's) to allow for multidimensional dictionary
That's a very nice suggestion. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Cluto like library for Python
I like Cluto as a data clustering software a lot. But its library binding is available only in C. Is there any python library which is similar to Cluto? -- http://mail.python.org/mailman/listinfo/python-list
help in understanding the stackless code
hi, I am new to python and need to know why the calling of switch(1) invokes the function "listen" twice in the below program? import stackless class EventHandler: def __init__(self,*outputs): if outputs==None: self.outputs=[] else: self.outputs=list(outputs) self.channel = stackless.channel() stackless.tasklet(self.listen)() def listen(self): print "in listen()..." while 1: val = self.channel.receive() self.processMessage(val) for output in self.outputs: self.notify(output) def processMessage(self,val): pass def notify(self,output): pass def registerOutput(self,output): print "in registerOutput()..." self.outputs.append(output) def __call__(self,val): print "in __call__ ..." self.channel.send(val) class Switch(EventHandler): def __init__(self,initialState=0,*outputs): EventHandler.__init__(self,*outputs) self.state = initialState def processMessage(self,val): print "in processMessage() of Switch..." self.state = val def notify(self,output): print "in notify() of switch..." output((self,self.state)) class Reporter(EventHandler): def __init__(self,msg="%(sender)s send message %(value)s"): EventHandler.__init__(self) self.msg = msg def processMessage(self,msg): print "in processMessage() of Reporter..." sender,value=msg print self.msg % {'sender':sender,'value':value} if __name__ == "__main__": reporter = Reporter() switch = Switch(0,reporter) switch(1) output: = in __call__ ... in listen()... in listen()... in processMessage() of Switch... in notify() of switch... in __call__ ... in processMessage() of Reporter... <__main__.Switch instance at 0x8d822cc> send message 1 thanks. -- https://mail.python.org/mailman/listinfo/python-list
Re: help in understanding the stackless code
yes It has instance of both Reporter and Switch. moreover I could not get why instance "reporter" is passed to class Switch as a parameter ? > > reporter = Reporter() > > switch = Switch(0,reporter) > > switch(1) thanks On Thursday, June 18, 2015 at 5:45:08 PM UTC+5:30, MRAB wrote: > On 2015-06-18 08:41, ravi wrote: > > hi, > > I am new to python and need to know why the calling of switch(1) invokes > > the function "listen" twice in the below program? > > > > > > > > import stackless > > > > class EventHandler: > > def __init__(self,*outputs): > > if outputs==None: > > self.outputs=[] > > else: > > self.outputs=list(outputs) > > > > self.channel = stackless.channel() > > stackless.tasklet(self.listen)() > > > > def listen(self): > > print "in listen()..." > > while 1: > > val = self.channel.receive() > > self.processMessage(val) > > for output in self.outputs: > > self.notify(output) > > > > def processMessage(self,val): > > pass > > > > def notify(self,output): > > pass > > > > def registerOutput(self,output): > > print "in registerOutput()..." > > self.outputs.append(output) > > > > def __call__(self,val): > > print "in __call__ ..." > > self.channel.send(val) > > > > class Switch(EventHandler): > > def __init__(self,initialState=0,*outputs): > > EventHandler.__init__(self,*outputs) > > self.state = initialState > > > > def processMessage(self,val): > > print "in processMessage() of Switch..." > > self.state = val > > > > def notify(self,output): > > print "in notify() of switch..." > > output((self,self.state)) > > > > class Reporter(EventHandler): > > def __init__(self,msg="%(sender)s send message %(value)s"): > > EventHandler.__init__(self) > > self.msg = msg > > > > def processMessage(self,msg): > > print "in processMessage() of Reporter..." > > sender,value=msg > > print self.msg % {'sender':sender,'value':value} > > > > > > if __name__ == "__main__": > > reporter = Reporter() > > switch = Switch(0,reporter) > > switch(1) > > > > > > > > > > output: > > = > > > > in __call__ ... > > in listen()... > > in listen()... > > in processMessage() of Switch... > > in notify() of switch... > > in __call__ ... > > in processMessage() of Reporter... > > <__main__.Switch instance at 0x8d822cc> send message 1 > > > Is it because EventHandler has 2 subclasses, namely Switch and > Reporter, and you have an instance of each? -- https://mail.python.org/mailman/listinfo/python-list
python program without stackless.run()
Hi, I could not understand how the below program executes function "fun" without calling stackless.run() in the program? Here "fun" runs as a tasklet and as per my knowledge for that stackless.run() is must. - import stackless class A: def __init__(self,name): self.name = name self.ch = stackless.channel() stackless.tasklet(self.fun)() def __call__(self,val): self.ch.send(val) def fun(self): while 1: v = self.ch.receive() print "hi" , v if __name__ == "__main__": obj = A("sh") obj(6) ----- output: -- hi 6 thanks, ravi -- https://mail.python.org/mailman/listinfo/python-list
how to dump tasklets status in python
hi, I have a complex python program running 100 tasklets simultaneously. I want to take dump of all the running tasklets including their current status and back trace at the time of exception. Can any one let me know how can this be done ? Thanks, ravi -- https://mail.python.org/mailman/listinfo/python-list
Re: python program without stackless.run()
On Friday, June 19, 2015 at 1:41:36 AM UTC+5:30, Ian wrote: > On Thu, Jun 18, 2015 at 1:47 PM, ravi wrote: > > I could not understand how the below program executes function "fun" > > without calling stackless.run() in the program? Here "fun" runs as a > > tasklet and as per my knowledge for that stackless.run() is must. > > You seem to have a lot of questions about stackless. You might find > that you get a better, more focused response if you ask your questions > on the stackless mailing list: > http://www.stackless.com/mailman/listinfo/stackless thanks for your pointer. I will post my queries to stackless mailing list. -- https://mail.python.org/mailman/listinfo/python-list
Difference between Python 2.2.2 and Python 2.5
I am developing for PyS60 1.4.4 which supports Python 2.2.2 while what I know is Python 2.5 . Can you please tell me differences between the two so that I can save myself from incompatible code. -- http://mail.python.org/mailman/listinfo/python-list
Re: Difference between Python 2.2.2 and Python 2.5
On Jan 18, 8:44 pm, Steven D'Aprano wrote: > On Sun, 18 Jan 2009 07:30:52 -0800, Ravi wrote: > > I am developing for PyS60 1.4.4 which supports Python 2.2.2 while what I > > know is Python 2.5 . > > > Can you please tell me differences between the two so that I can save > > myself from incompatible code. > > Everything new mentioned here: > > http://www.python.org/doc/2.5/whatsnew/whatsnew25.htmlhttp://www.python.org/doc/2.4/whatsnew/whatsnew24.htmlhttp://www.python.org/doc/2.3/whatsnew/whatsnew23.html > > won't exist in Python 2.2. > > -- > Steven This is a list too big! Is there any checker which can be applied to the Python code. (of course any solution other than running python 2.2 over the code) -- http://mail.python.org/mailman/listinfo/python-list
Byte oriented data types in python
I have following packet format which I have to send over Bluetooth. packet_type (1 byte unsigned) || packet_length (1 byte unsigned) || packet_data(variable) How to construct these using python data types, as int and float have no limits and their sizes are not well defined. -- http://mail.python.org/mailman/listinfo/python-list
Re: Byte oriented data types in python
> Take a look at the struct and ctypes modules. struct is really not the choice. it returns an expanded string of the data and this means larger latency over bluetooth. ctypes is basically for the interface with libraries written in C (this I read from the python docs) -- http://mail.python.org/mailman/listinfo/python-list
Re: Byte oriented data types in python
On Jan 25, 12:52 am, "Martin v. Löwis" wrote: > > packet_type (1 byte unsigned) || packet_length (1 byte unsigned) || > > packet_data(variable) > > > How to construct these using python data types, as int and float have > > no limits and their sizes are not well defined. > > In Python 2.x, use the regular string type: chr(n) will create a single > byte, and the + operator will do the concatenation. > > In Python 3.x, use the bytes type (bytes() instead of chr()). This looks really helpful thanks! -- http://mail.python.org/mailman/listinfo/python-list
Forwarding keyword arguments from one function to another
The following code didn't work: class X(object): def f(self, **kwds): print kwds try: print kwds['i'] * 2 except KeyError: print "unknown keyword argument" self.g("string", **kwds) def g(self, s, kwds): print s print kwds if __name__ == "__main__": x = X() x.f(k = 2, j = 10) However the following did: class X(object): def f(self, **kwds): print kwds try: print kwds['i'] * 2 except KeyError: print "unknown keyword argument" self.g("string", **kwds) def g(self, s, **kwds): print s print kwds if __name__ == "__main__": x = X() x.f(k = 2, j = 10) Please explain -- http://mail.python.org/mailman/listinfo/python-list
Re: Forwarding keyword arguments from one function to another
I am sorry about the typo mistake, well the code snippets are as: # Non Working: class X(object): def f(self, **kwds): print kwds try: print kwds['i'] * 2 except KeyError: print "unknown keyword argument" self.g("string", kwds) def g(self, s, **kwds): print s print kwds if __name__ == "__main__": x = X() x.f(k = 2, j = 10) # Working One class X(object): def f(self, **kwds): print kwds try: print kwds['i'] * 2 except KeyError: print "unknown keyword argument" self.g("string", **kwds) def g(self, s, **kwds): print s print kwds if __name__ == "__main__": x = X() x.f(k = 2, j = 10) -- http://mail.python.org/mailman/listinfo/python-list
MRO inconsistency: why?
Why the following code gives inconsistent method resolution order error: class X(object): x = 4 def f(self): print 'f in X' print dir(X) X.g(self) def g(self): print 'g in X' class Y(object, X): def g(self): print 'g in Y' o = Y() o.f() While this code doesn't: class X(object): x = 4 def f(self): print 'f in X' print dir(X) X.g(self) def g(self): print 'g in X' class Y(X, object): def g(self): print 'g in Y' o = Y() o.f() -- http://mail.python.org/mailman/listinfo/python-list
Re: Forwarding keyword arguments from one function to another
Thnak you all. > In the future, explain "didn't work". > Wrong output? give actual (copy and paste) and expected. > Error message? give traceback (copy and paste). I will be careful. -- http://mail.python.org/mailman/listinfo/python-list
Make a python property with the same name as the class member name
Is it possible in python to create a property with the same name as the member variable name of the class. e.g. Class X: ... self.i = 10 # marker ... property(fget = get_i, fset = set_i) Please tell me how I can do so. Because if I do so, for the statement at marker I get stack overflow for the assingm -- http://mail.python.org/mailman/listinfo/python-list
Imports in python are static, any solution?
foo.py : i = 10 def fi(): global i i = 99 bar.py : import foo from foo import i print i, foo.i foo.fi() print i, foo.i This is problematic. Well I want i to change with foo.fi() . -- http://mail.python.org/mailman/listinfo/python-list
Re: Imports in python are static, any solution?
On Apr 14, 1:23 am, norseman wrote: > AJ Mayorga wrote: > > For something like this I generally create a superclass to hold > > configuration variables that will change overtime, doing that will save you > > from insanity. > > > Class configVar: > > > #set initial values > > Def __init__(self): > > Self.A = 5 > > Self.B = 10 > > Self.C = 20 > > > Class myMath(configVars): > > def __init__(self): > > pass > > > def SubAandB(self): > > return self.A - self.B > > > def AddCandB(self): > > return self.C + self.B > > > def MultiplyXbyA(self, x): > > return self.A * x > > > m = myMath() > > X = m.SubAandB() > > Y = m.AddCandB() > > Z = m.MultiplyXbyA(32) > > > Keeps your vars in a safer easier to handle, debug, and change kinda way > > Good luck > > > AJ > > > -Original Message- > > From: python-list-bounces+aj=xernova@python.org > > [mailto:python-list-bounces+aj=xernova@python.org] On Behalf Of David > > Stanek > > Sent: Monday, April 13, 2009 12:12 PM > > To: Ravi > > Cc: python-l...@python.org > > Subject: Re: Imports in python are static, any solution? > > > On Mon, Apr 13, 2009 at 11:59 AM, Ravi wrote: > >> foo.py : > > >> i = 10 > > >> def fi(): > >> global i > >> i = 99 > > >> bar.py : > > >> import foo > >> from foo import i > > >> print i, foo.i > >> foo.fi() > >> print i, foo.i > > >> This is problematic. Well I want i to change with foo.fi() . > > > Why not only import foo and using foo.i? In fi() when you set i = 99 > > you are creating a new object called i in foo's namespace. > > === > > Aj is right. In foo.py there are two definitions for 'i'. The initial > and the replacement initiated by fi(). While initially there is no 'i' > definition in bar itself. > > To test, use my changes to bar.py > > import foo > #from foo import i > > i= foo.i > print i, foo.i > x= foo.fi() > print i, x, foo.i > x= foo.i > print i, x, foo.i > > the output will be: > 10 10 > 10 None 99 > 10 99 99 > > output is same if you uncomment #from... and comment i=... > The '...import i' creates the "same" var as the i=... in the current run > If you comment out both the from and the i= then the print i will fail > because i has not been defined in current space. > foo.fi() returns None (nothing) per it's definition. > whereas the first foo.i returns the initial i value and the foo.i after > foo.fi() returns the 2nd value, foo's i reset to 99 by fi() inside foo. > > Clear as Mud??? > > Steve Yes I find the difference. Thank you all. -- http://mail.python.org/mailman/listinfo/python-list
Choose: class with static methods or module with functions
I have to create a few helper/utility application-wide functions. There are two options: 1. Create a Utility class and all functions as static method of that class. 2. Create a module, utility.py and member functions. Which is a better approach. My personal view is that I should create a module with functions. Classes are appropriate only when I am creating new types. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to generate random numbers that satisfy certain distribution
On Jan 23, 10:37 pm, thinke365 wrote: > such as uniform distribution, Normal distribution or poisson distribution. > is there any package that can be used to generate such random numbers. > > -- > View this message in > context:http://old.nabble.com/how-to-generate-random-numbers-that-satisfy-cer... > Sent from the Python - python-list mailing list archive at Nabble.com. Did you try random package? -- http://mail.python.org/mailman/listinfo/python-list
SQLite is quite SQL compliant
The documentation of the sqlite module at http://docs.python.org/library/sqlite3.html says: "...allows accessing the database using a nonstandard variant of the SQL..." But if you see SQLite website they clearly say at http://sqlite.org/omitted.html that only very few of the SQL is not implemented. I think docs should clarify on that. Many users might be scared of using SQLite just because of this. -- http://mail.python.org/mailman/listinfo/python-list
Re: Popen Question
On Nov 4, 7:06 pm, moogyd wrote: > Hi, > I usually use csh for my simulation control scripts, but these scripts > are becoming more complex, so I plan to use python for the next > project. > To this end, I am looking at subprocess.Popen() to actually call the > simulations, and have a very basic question which is demonstrated > below. > > [sde:st...@lbux03 ~]$ python > Python 2.6 (r26:66714, Feb 21 2009, 02:16:04) > [GCC 4.3.2 [gcc-4_3-branch revision 141291]] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > > >>> import os, subprocess > >>> os.environ['MYVAR'] = "myval" > >>> p = subprocess.Popen(['echo', '$MYVAR'],shell=True) > > >>> p = subprocess.Popen(['echo', '$MYVAR']) > >>> $MYVAR > >>> p = subprocess.Popen('echo $MYVAR',shell=True) > >>> myval > >>> p = subprocess.Popen('echo $MYVAR') > > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib64/python2.6/subprocess.py", line 595, in __init__ > errread, errwrite) > File "/usr/lib64/python2.6/subprocess.py", line 1106, in > _execute_child > raise child_exception > OSError: [Errno 2] No such file or directory > > I am not really sure I understand these results. > 1) No idea what is going on > 2) As (1). What isn't myval printed out (rather than $MYVAR) > 3) Works as I wanted it to > 4) Why do I need shell=True ? > The documentation isn't very clear to me (it seems you need to > understand the underlying system calls). > > Can anyone explain (or provide link) for this behaviour in simple > English? > Thanks, > Steven try giving /bin/echo -- http://mail.python.org/mailman/listinfo/python-list
sqlite3 doesn't raise exception if database is not present/inaccessible
try this: import sqlite3 con = sqlite3.connect("any string here") and there is no error reported. You will get an error you do some operations on the database which is confusing. I think sqlite3 should change this behavior. -- http://mail.python.org/mailman/listinfo/python-list
Re: sqlite3 doesn't raise exception if database is not present/inaccessible
I understand it now. Thanks for the responses. -- http://mail.python.org/mailman/listinfo/python-list
***************************Hai***************************
http://www.workfrominter.com/ http://www.workfrominter.com/ http://girlsdailysex.blogspot.com/ http://girlsdailysex.blogspot.com/ Just See What Is this Website Are Msg For You -- http://mail.python.org/mailman/listinfo/python-list
Re: Is Python weak on the web side?
Too many options. Google: python web frameworks The first couple of links will point you to enough resources. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there an equivalent to Java Webstart in Python?
Hi Kent, Too complicated example :-). Jythonc works just fine to create a regular jar file that you can reference in your jnlp file. Ravi Teja. -- http://mail.python.org/mailman/listinfo/python-list
Re: Embedding Python in other programs
http://www.python.org/windows/win32com/QuickStartServerCom.html If you are using ActivePython, that tutorial is included (PyWin32 documentation -> Python COM -> Overviews) along with the needed win32all module. -- http://mail.python.org/mailman/listinfo/python-list
Re: Embedding Python in other programs
Greg, I don't recall touching VB6 in 4 years. From whatever I remember, you are trying to do early binding (trying to find a registered type library). You need to do late binding instead (use CreateObject) to dynamically instantiate the COM object. Ravi Teja. -- http://mail.python.org/mailman/listinfo/python-list
Re: Extend Python
SIP is not a commercial product and is released on a different license than PyQt. >From the SIP docs (http://www.river-bank.demon.co.uk/docs/sip/sipref.html#license) 1.1 License SIP is licensed under the same terms as Python itself. SIP places no restrictions on the license you may apply to the bindings you create. On a side note.. there will be a GPL edition of PyQt sometime in the future. http://www.riverbankcomputing.co.uk/pyqt/roadmap.php -- http://mail.python.org/mailman/listinfo/python-list
Concatenate string list to number list to form title - Logic needed.
Hi, I'm completely new to python. I just need simple logic to get output without any loops. I have list of string and list of list of numbers. Each string should be concatenated with every third and fourth values to generate proper titles in list of strings. t = ['Start','End'] a = [[1,2,3,4], [5,6,7,8]] Expected Result : ( list of strings ) ['Start - 3 , End - 4', 'Start - 7 , End - 8'] Note : First 2 values from each list should be ignored. Could anyone please guide me with best solution without loops ? Thanks Ravi -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Data Analysis Recommendations
On 1/1/16 1:24 PM, Mark Lawrence wrote: > On 31/12/2015 17:15, Rob Gaddi wrote: >> I'm looking for some advice on handling data collection/analysis in >> Python. ... >> The whole process feels a bit grindy; like I keep having to do a lot of >> ad-hoc stitching things together. And I keep hearing about pandas, >> PyTables, and HDF5. Would that be making my life notably easier? If >> so, does anyone have any references on it that they've found >> particularly useful? The tutorials I've seen so far seem to not give >> much detail on what the point of what they're doing is; it's all "how >> you write the code" rather than "why you write the code". Paying money >> for books is acceptable; this is all on the company's time/dime. >> >> Thanks, >> Rob Cyrille Rossant's books may meet your needs. The Interactive Computing and Visualization Cookbook offers more than just recipes. As the topics get advanced, he explains the whys in addition to the hows. It may not have specific answers to parameter sweep experiments but I understood more about Python's internals and packages as they related to my work. It helped me to refine when to use Python and when to use other languages. Currently US $5 via the publisher: https://www.packtpub.com/books/info/authors/cyrille-rossant (I have no affiliation with the author or publisher) Mark Lawrence writes: > I don't understand your comment about tutorials. Once they've given you > an introduction to the tool, isn't it your responsibility to manipulate > your data in the way that suits you? If you can't do that, either > you're doing something wrong, or the tool is inadequate for the task. > For the latter I believe you've two options, find another tool or write > your own. Without second-guessing the OP, I've found Python tutorials and documents to be helpful but not always complete in a way that beginners and casual users would need. There is usually a package that will do some job but one first has to find it. A lot of power can also be located deep within a hierarchy of dots: package.something.subsomething.subsubsomething ... Some documentation sets are very complete, others aren't. I often have the nagging feeling that if I just knew what question to ask and knew the right terminology, that I could benefit from code someone has already written and/or develop a smarter plan of attack. Ravi Narasimhan http://www.rettacs.org -- https://mail.python.org/mailman/listinfo/python-list
Re: JUST GOT HACKED
On Tuesday, October 1, 2013 7:54:35 PM UTC+5:30, Daniel Stojanov wrote: > 2) I just signed up the this mailing list. To the regulars, is this what > normally happens on this list? > > 3) I'm a bit late to the party. Is Nikos a real sysadmin or is this some > horrible inside joke I don't get? Thanks Daniel!!! Lurker here: I too was wondering whether I have got into the wrong place -- https://mail.python.org/mailman/listinfo/python-list
Re: JUST GOT HACKED
On Wed, Oct 2, 2013 at 12:19 PM, Ben Finney wrote: > Antoon Pardon writes: > >> Op 02-10-13 00:06, Ben Finney schreef: >> > This is an unmoderated forum, so we have occasional spates of >> > persistent nuisances, and those who respond with the maturity level >> > and impulse control of an average six-year-old. > […] >> >> And what about the impuls control and the maturity of people who can't >> stop answering [a nuisance], knowing they contribute to the nuisance >> to the group? > > Yes, we are in firm agreement here. So Ben,Antoon you are saying that Nikos is a minor problem -- spam-like -- Whereas people answering him are a bigger problem??! I find this real confused!! Why they are answering then?!?! As far as I can make out everyone who is answering (helping!) doing it frustratation and disgust. But still they keep answering and answering!! Makes no sense [Sorry -- old programmer (C,C++ etc) -- new to python. If there is some secret to this list's culture that I missed will be pleased to be educated! ] -- - Ravi -- https://mail.python.org/mailman/listinfo/python-list
Re: JUST GOT HACKED
On Wed, Oct 2, 2013 at 12:54 PM, Ben Finney wrote: > > Ravi Sahni writes: > > > So Ben,Antoon you are saying that [demands for off-topic help with > > demonstrated history of unwillingness to learn] is a minor problem […] > > Whereas [baiting and enabling that behaviour is] a bigger problem??! > > (I edited the above to focus on behaviour, not people. Let's not vilify > a person when what is objectionable is the behaviour.) Good... Sorry > > No, I'm not saying that. I'm saying that both those behaviours are > significant nuisances, both are against our community guidelines of > mutual respect, and both should stop. > > Comparing the magnitude of those problems to see which is worse isn't of > interest to me, they're both objectionable to the point of noise and > disruption. > > I'd like them both to stop, in the interest of keeping this forum > functional for its intended purposes. > Thanks Ben for clarification and understanding -- - Ravi -- https://mail.python.org/mailman/listinfo/python-list
Re: JUST GOT HACKED
On Wed, Oct 2, 2013 at 1:21 PM, Antoon Pardon wrote: > Op 02-10-13 09:02, Ravi Sahni schreef: >> On Wed, Oct 2, 2013 at 12:19 PM, Ben Finney >> wrote: >>> Antoon Pardon writes: >>> >>>> Op 02-10-13 00:06, Ben Finney schreef: >>>>> This is an unmoderated forum, so we have occasional spates of >>>>> persistent nuisances, and those who respond with the maturity level >>>>> and impulse control of an average six-year-old. >>> […] >>>> >>>> And what about the impuls control and the maturity of people who can't >>>> stop answering [a nuisance], knowing they contribute to the nuisance >>>> to the group? >>> >>> Yes, we are in firm agreement here. >> >> So Ben,Antoon you are saying that Nikos is a minor problem -- spam-like -- >> Whereas people answering him are a bigger problem??! >> >> I find this real confused!! Why they are answering then?!?! >> As far as I can make out everyone who is answering (helping!) doing it >> frustratation and disgust. But still they keep answering and >> answering!! > > You should understand that what is a bigger problem and what is a minor > problem is a personal, subjective judgement and people come to different > conclusions. > > So group1 finds Nikos a minor nuisance and is willing to answer him. > Probably because it gives them warm fuzzy feelings knowing they tried > to help someone or because they found the problem interresting to solve. > > Now group2 may find Nikos himself not that big a nuisance but they > certainly find Nikos in combination with group1 a major nuisance. > Because it keeps the cycle going and even if they kill file Nikos, > they keep being confronted with his contributions through the responses > of group1. > > So frustration builds for those in group2, until it reaches a level > that some of them feel the need to vent that frustration. That can > sometimes be rather ugly to observe and I am sure that some venters > weren't that happy with their own reaction afterwards, but I think > it is an understandable, human reaction. > > Now for a number of people in group1, the venting of group2 is a > major nuisance and they start venting their own frustration with that. > Unfortunately, their own need for venting doesn't create any empathy > for the need of group2 for venting. They only see groups2 as the > cause for their own frustration with very little willingness to see > their own contribution to the original built up. Thanks Antoon for explaining so clearly and taking trouble to explain. As said above, Im newbie to python and to this group, (done C, C++ before) and was too confused by the BS to ask/speak. Daniel's post gave me courage to ask. Hope to get back to python now! -- Ravi -- https://mail.python.org/mailman/listinfo/python-list
Re: Lowest Value in List
On Wed, Oct 2, 2013 at 3:34 PM, wrote: > Dear Group, > > I am trying to work out a solution to the following problem in Python. > > The Problem: > Suppose I have three lists. > Each list is having 10 elements in ascending order. > I have to construct one list having 10 elements which are of the lowest value > among these 30 elements present in the three given lists. > > The Solution: > > I tried to address the issue in the following ways: > > a) I took three lists, like, > list1=[1,2,3,4,5,6,7,8,9,10] > list2=[0,1,2,3,4,5,6,7,8,9] > list3=[-5,-4,-3,-2,-1,0,1,2,3,4] > > I tried to make sum and convert them as set to drop the repeating elements: > set_sum=set(list1+list2+list3) > set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, -5, -4, -3, -2]) > > In the next step I tried to convert it back to list as, > list_set=list(set_sum) > gave the value as, > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, -5, -4, -3, -2] > > Now, I imported heapq as, > import heapq > > and took the result as, > result=heapq.nsmallest(10,list_set) > it gave as, > [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4] > > b) I am thinking to work out another approach. > I am taking the lists again as, > > list1=[1,2,3,4,5,6,7,8,9,10] > list2=[0,1,2,3,4,5,6,7,8,9] > list3=[-5,-4,-3,-2,-1,0,1,2,3,4] > > as they are in ascending order, I am trying to take first four/five elements > of each list,like, > > list1_4=list1[:4] >>>> list2_4=list2[:4] >>>> list3_4=list3[:4] > > Now, I am trying to add them as, > > list11=list1_4+list2_4+list3_4 > > thus, giving us the result > > [1, 2, 3, 4, 0, 1, 2, 3, -5, -4, -3, -2] > > Now, we are trying to sort the list of the set of the sum as, > > sort_sum=sorted(list(set(list11))) > > giving us the required result as, > > [-5, -4, -3, -2, 0, 1, 2, 3, 4] > > If by taking the value of each list portion as 4 gives as less number of > elements in final value, as we are making set to avoid repeating numbers, we > increase element count by one or two and if final result becomes more than 10 > we take first ten. > > Are these approaches fine. Or should we think some other way. > > If any learned member of the group can kindly let me know how to solve I > would be helpful enough. > > Thanking in Advance, > Subhabrata. > > > -- > https://mail.python.org/mailman/listinfo/python-list [Disclaimer: Beginner myself] The heapq module has merge Since the lists are already sorted what's wrong with just this? list(merge(list1, list2, list3))[:10] -- - Ravi -- https://mail.python.org/mailman/listinfo/python-list
Re: Can arbitrary code run in a server if someone's know just the MySQL password?
On Wed, Oct 2, 2013 at 8:04 PM, Alister wrote: > On Wed, 02 Oct 2013 16:41:40 +0300, Νίκος wrote: > >> Στις 2/10/2013 4:25 μμ, ο/η Steven D'Aprano έγραψε: >>> On Wed, 02 Oct 2013 15:20:00 +0300, Νίκος wrote: >>> >>>> Is it possible for someone that knows the MYSQL password of a server >>>> to run arbitrary code on a linux server? >>> >>> Yes, it is possible. >> >> Is that what might have happened and someone managed to upload the .html >> file in '~/home/nikos/www/' ? >> >> Can you think of any other way? > > > There are many other ways (i am not a hacker so i would not know whre to > start) > Against my better judgement I am going to give some advise (more to > protect your customers than you) > > 1) tie down access to your server, nothing should be accessable from the > internet unless absolutly necessary. > certainly your database should not be accessible and this should be > blocked in multiple ways (protection in depth) > > you should close down any un-necessary services. > shut your firewall to all trafffix except http & https (ports 80 ,443) > unless absolutely necessary. > set your database accounts to only allow log in from localhost & and any > explicit IP addresses that must have access > > & please google for further advise on server security & post questions in > a suitable forum (not here) > > as many have said, security is not our area of expertise & this is the > wrong place to ask. > > when correctly secured knowing your username & password should not be > enough to allow access to your server. Thank you Alister for ansering the needs of needy persons. I am also needy. Please be kind to me as well: There is poverty and injustice in the world. Why?? I NEED to know People suffer and die. How come? I MUST know And there are morons... Why?? PLEASE TELL -- Ravi -- https://mail.python.org/mailman/listinfo/python-list
Re: JUST GOT HACKED
On Wed, Oct 2, 2013 at 10:14 PM, wrote: > On 10/02/2013 01:02 AM, Ravi Sahni wrote: >> On Wed, Oct 2, 2013 at 12:19 PM, Ben Finney >> wrote: >>> Antoon Pardon writes: >>> >>>> Op 02-10-13 00:06, Ben Finney schreef: >>>> > This is an unmoderated forum, so we have occasional spates of >>>> > persistent nuisances, and those who respond with the maturity level >>>> > and impulse control of an average six-year-old. >>> […] >>>> >>>> And what about the impuls control and the maturity of people who can't >>>> stop answering [a nuisance], knowing they contribute to the nuisance >>>> to the group? >>> >>> Yes, we are in firm agreement here. >> >> So Ben,Antoon you are saying that Nikos is a minor problem -- spam-like -- >> Whereas people answering him are a bigger problem??! >> >> I find this real confused!! Why they are answering then?!?! >> As far as I can make out everyone who is answering (helping!) doing it >> frustratation and disgust. But still they keep answering and >> answering!! >> >> Makes no sense >> >> [Sorry -- old programmer (C,C++ etc) -- new to python. If there is >> some secret to this list's culture that I missed will be pleased to be >> educated!] > > Actually it does make sense when one thinks of the psychology. > It is fun to bash other people on the internet. There are few > consequences and it makes up for the lack of authority and > control we experience in our real daily lives. > > When someone like Nikos appears and irritates enough people > to exceed a critical mass, it becomes socially ok to bash > him and one gets a _Lord of the Flies_ [*1] effect. > > Further it is nothing new -- this kind of spiral down > into chaos and noise of an unmoderated online community > has been happening since the earliest days of the internet. > > For decades a useful way to combat this has been summarized > in the phase "don't feed the trolls". But that only works > when people are able sacrifice their own fun (giving up the > joy of joining in publicly bashing a scapegoat by simply not > responding to inflammatory posts) for a common good (a mailing > list with a good signal-to-noise ratio and non-hostile atmosphere.) > > It would seem that enough Python regulars here get enjoyment > from the current state of affairs that the situation is likely > to last indefinitely. > > The rest of us try to make do by using restraint, filtering and > alternate forums (Stackoverflow, etc). > > > [*1] > http://www.cliffsnotes.com/literature/l/lord-of-the-flies/lord-of-the-flies-at-a-glance That (link) is an ugly stupid view of humanness. Why should I want to piss on you and flame you and shoot you for fun? I have never met anyone like that and dont believe that anyone is like that. [We are told about Hitler and Stalin and so on. I have never met them :-) ] And if you believe everyone is like that -- sorry - please go to psychatrist -- serious! Basically I am a software engineer. A engineer believes in right design. Mess happens with wrong design. Something is making ppl behave crazy. What is it? If we are engineers we should do analysis. No I dont think it is Nikos. I think it is ppl answering nonsense questions and shouting and keep on answering nonsense with more nonsense and keep on shouting. Why this crazy behavior?? So far Anton has given me the best explanaton -- Ravi -- https://mail.python.org/mailman/listinfo/python-list
Re: Goodbye: was JUST GOT HACKED
On Thu, Oct 3, 2013 at 2:43 AM, Walter Hurry wrote: > Ding ding! Nikos is simply trolling. It's easy enough to killfile him but > inconvenient to skip all the answers to his lengthy threads. If only > people would just ignore him! Hello Walter Hurry please wait! Did I do/say something wrong?! If one of us should go it should be me -- Im just a newbie here. I have little time/efforts invested in python anyway. I was for a long time wasting time choosing upgrading myself from C/C++ to python or javascript. javascript -- universal and unavoidable in today's web world, but a mess python -- looks cleaner and well-designed (and not for heavyweight phds like FP languages like haskell ) So I finally went with python Now given the mess out here I need to rethink anyway! -- Ravi -- https://mail.python.org/mailman/listinfo/python-list
Re: Goodbye: was JUST GOT HACKED
On Thu, Oct 3, 2013 at 5:05 PM, Steven D'Aprano wrote: > On Thu, 03 Oct 2013 09:21:08 +0530, Ravi Sahni wrote: > >> On Thu, Oct 3, 2013 at 2:43 AM, Walter Hurry >> wrote: >>> Ding ding! Nikos is simply trolling. It's easy enough to killfile him >>> but inconvenient to skip all the answers to his lengthy threads. If >>> only people would just ignore him! >> >> Hello Walter Hurry please wait! >> >> Did I do/say something wrong?! > > Don't worry about it Ravi, you haven't done anything wrong. > > Walter is not a regular here. At best he is a lurker who neither asks > Python questions nor answers them. In the last four months, I can see > four posts from him: three are complaining about Nikos, and one is a two- > line "Me to!" response to a post about defensive programming. > > > >> If one of us should go it should be me -- Im just a newbie here. > > No, you are welcome here. You've posted more in just a few days than > Walter has in months. We need more people like you. Thanks for the welcome! But No thanks for the non-welcome -- I dont figure why Walter Hurry (or anyone else) should be unwelcome just because I am welcome. The world (and the python list hopefully!!) is big enough for all of us -- Ravi -- https://mail.python.org/mailman/listinfo/python-list
Re: Tail recursion to while iteration in 2 easy steps
On Wed, Oct 2, 2013 at 10:46 AM, rusi wrote: > 4. There is a whole spectrum of such optimizaitons -- > 4a eg a single-call structural recursion example, does not need to push > return address on the stack. It only needs to store the recursion depth: > > If zero jump to outside return add; if > 0 jump to internal return address > > 4b An example like quicksort in which one call is a tail call can be > optimized with your optimization and the other, inner one with 4a above I am interested in studying more this 'whole spectrum of optimizations' Any further pointers? Thanks -- Ravi -- https://mail.python.org/mailman/listinfo/python-list
Re: howto check programs and C libraries
On Fri, Oct 4, 2013 at 3:00 PM, David Palao wrote: > Hello, > I'm in charge of preparing a computer room for the practices of > "introduction to programming". > One of the tasks is checking that from all the computers in the room > one can execute some programs and link (and compile) against some > libraries. > My first idea was using Autotools (or cmake), but as I'm a big fan of > python, I was thinking how to do that with python, and I don't have a > clear solution yet. > I know that distutils includes the distutils.command.config module, > and I think it could do the job (when properly subclassed). > Do you have a better idea? I have ruby on rails friends who speak of capistrano and puppet. google puppet python gives me : http://stackful-dev.com/cuisine-the-lightweight-chefpuppet-alternative If you find it good I shall be interested to know. -- Ravi -- https://mail.python.org/mailman/listinfo/python-list
Re: how to read list from file
On Sun, Oct 6, 2013 at 10:11 PM, Harvey Greenberg wrote: > On Saturday, October 5, 2013 7:24:39 PM UTC-6, Tim Chase wrote: >> Python 2.7.3 (default, Jan 2 2013, 13:56:14) >> [GCC 4.7.2] on linux2 >> Type "help", "copyright", "credits" or "license" for more >> information. >> >>> s = "[{'a':1, 'b':2}, [1,2,3], 10]" >> >>> import ast >> >>> print repr(ast.literal_eval(s)) >> [{'a': 1, 'b': 2}, [1, 2, 3], 10] >> >> >> >> -tkc > > that didn't work. printing it looks like the list because it's the input, > but try printing len(repr(ast.literal_eval(s))). It should give 3, but it > gives 72 (number of chars). Please to remove the repr and try again? Thank you! -- Ravi -- https://mail.python.org/mailman/listinfo/python-list
Re: how to read list from file
On Sun, Oct 6, 2013 at 10:27 PM, Harvey Greenberg wrote: > On Saturday, October 5, 2013 7:08:08 PM UTC-6, Harvey Greenberg wrote: >> I am looping as for L in file.readlines(), where file is csv. >> >> >> >> L is a list of 3 items, eg, [{'a':1, 'b':2}, [1,2,3], 10] Note that the >> first item is a dir and 2nd is a list, so parsing with split doesn't work. >> Is there a way to convert L, which is a string, to the list of 3 items I >> want? > > Yay It worked. Thanks! Which method working? Literal_eval method? JSON method? Some third method? [I am newbie so interested. Please to excuse!!] -- Ravi -- https://mail.python.org/mailman/listinfo/python-list
Re: Goodbye: was JUST GOT HACKED
On Mon, Oct 7, 2013 at 5:56 PM, Walter Hurry wrote: > On Thu, 03 Oct 2013 11:35:00 +, Steven D'Aprano wrote: > >> On Thu, 03 Oct 2013 09:21:08 +0530, Ravi Sahni wrote: >> >>> On Thu, Oct 3, 2013 at 2:43 AM, Walter Hurry >>> wrote: >>>> Ding ding! Nikos is simply trolling. It's easy enough to killfile him >>>> but inconvenient to skip all the answers to his lengthy threads. If >>>> only people would just ignore him! >>> >>> Hello Walter Hurry please wait! >>> >>> Did I do/say something wrong?! >> >> Don't worry about it Ravi, you haven't done anything wrong. >> >> Walter is not a regular here. At best he is a lurker who neither asks >> Python questions nor answers them. In the last four months, I can see >> four posts from him: three are complaining about Nikos, and one is a >> two- >> line "Me to!" response to a post about defensive programming. >> >> >> >>> If one of us should go it should be me -- Im just a newbie here. >> >> No, you are welcome here. You've posted more in just a few days than >> Walter has in months. We need more people like you. > > Steven, > > You make a fair point. I have posted very little recently, for the > following reasons: > > a) I'm not really competent enough to answer python questions, at least > not yet. > > b) I try not to post my own Python questions unless as a last resort. I > prefer to try to solve my own problems by reading the fine documentation, > and DuckDuckGoing. > > However, I do lurk assiduously and have learned much by reading excellent > 'answering' posts from many such as you. > > The 'Goodbye' post was made in rather a fit of pique, for which I > apologise. If I am allowed a second chance, there is actually something > puzzling me at the moment. It's a UnicodeDecodeError, but I shall start > a separate thread about it. > > Sorry again. Thanks! For changing decision! -- https://mail.python.org/mailman/listinfo/python-list
Re: Formal-ity and the Church-Turing thesis
On Tue, Oct 8, 2013 at 8:47 AM, rusi wrote: > I can only say how ironic it sounds to someone who is familiar with the > history of our field: > Turing was not a computer scientist (the term did not exist then) but a > mathematician. And his major contribution was to create a form of argument > so much more rigorous than what erstwhile mathematicians were used to that he > was justified in calling that math as a machine. > > The irony is that today's generation assumes that 'some-machine' implies its > something like 'Intel-machine'. > To get out of this confusion ask yourself: Is it finite or infinite? > If the TM were finite it would be a DFA > If the Intel-machine (and like) were infinite they would need to exist in a > different universe. With due respect Sir, you saying that Turing machine not a machine? Very confusion Sir!!! > > And so when you understand that TMs are just a kind of mathematical rewrite > system (as is λ calculus as are context free grammars as is school arithmetic > etc etc) you will not find the equivalence so surprising -- Ravi -- https://mail.python.org/mailman/listinfo/python-list
Re: Formal-ity and the Church-Turing thesis
On Tue, Oct 8, 2013 at 1:20 PM, Steven D'Aprano wrote: > On Tue, 08 Oct 2013 10:46:50 +0530, Ravi Sahni wrote: > >> On Tue, Oct 8, 2013 at 8:47 AM, rusi wrote: >>> I can only say how ironic it sounds to someone who is familiar with the >>> history of our field: Turing was not a computer scientist (the term did >>> not exist then) but a mathematician. And his major contribution was to >>> create a form of argument so much more rigorous than what erstwhile >>> mathematicians were used to that he was justified in calling that math >>> as a machine. >>> >>> The irony is that today's generation assumes that 'some-machine' >>> implies its something like 'Intel-machine'. To get out of this >>> confusion ask yourself: Is it finite or infinite? If the TM were finite >>> it would be a DFA If the Intel-machine (and like) were infinite they >>> would need to exist in a different universe. >> >> With due respect Sir, you saying that Turing machine not a machine? Very >> confusion Sir!!! > > The mathematical ideal Turing Machine has an infinitely long tape, > equivalent to infinite memory, and may take an unbounded amount of time > to complete the computation. Since no *actual* physical machine can be > infinitely big, and in practice there are strict limits on how long we > are willing to wait for a computation to complete, in the *literal* > sense, Turing Machines are not *actual* machines. They are a mathematical > abstraction. > > But in practice, we can wave our hands and ignore this fact, and consider > only not-quite-Turing Machines with finite amounts of tape, and note that > they are equivalent to physical machines with finite amounts of memory. > One could even build such a finite Turing Machine, although of course it > would be very slow. Or one can simulate it in software. > > So in that sense, computers are Turing Machines. Anything a physical > computing device can compute, a Turing Machine could too. The converse is > not true though: a Turing Machine with infinite tape can compute things > where a real physical device would run out of memory, although it might > take longer than anyone is willing to wait. Thanks Sir the detailed explanation. You are offering me many thoughts inside few words so I will need some time to meditate upon the same. Presently Sir, I wish to ask single question: What you mean "wave our hands"?? Thanks -- Ravi -- https://mail.python.org/mailman/listinfo/python-list
Re: Formal-ity and the Church-Turing thesis
On Tue, Oct 8, 2013 at 11:14 AM, rusi wrote: > To explain at length will be too long and OT (off-topic) for this list. > I'll just give you a link and you tell me what you make of it: > http://sloan.stanford.edu/mousesite/Secondary/Whorfframe2.html I am trying to read link. Very new idea: Buildings can catch fire by wrong boards!! Later part difficult for me to read. (My English not powerful --please excuse.) I will make my fullest efforts to read on your recommend but I not clear the connection with computers, programming, computer science and so on. Also this Mr. Mark Lawrence question. -- Ravi -- https://mail.python.org/mailman/listinfo/python-list
Re: Visual Python, really "Visual"?
No! Visual Python does not have a WYSIWYG GUI Builder. Boa Constructor is the closest. PythonCard is another contender. Once, XAML comes in, this will become less of an issue. -- http://mail.python.org/mailman/listinfo/python-list
Re: Still Loving Python
Nothing beats Delphi for the raw design speed and choices for GUI development. .NET is another good option. The good news is you don't have to loose their benefits just because we chose Python. Python for Delphi works quite well to get you the best of both worlds. I develop the app in Python as a library first (Python is great for quick prototyping), make my GUI in Delphi and simply call my library from it. Bundling Python manually into an installer can be a chore but you will get used to it. Once IronPython is complete, it should do the same for .NET. I currently use Boo in a similar fashion. For simpler UIs, libglade does a great job of seperating concerns. > Are there any easy GUI > builders for any Python-supported toolkits? Most UI toolkits have sort of builders GTK - Glade wxWindows - wxGlade Fox - Fox Dialog Editor FLTK - Fluid TkInter - SpecTcl (I think I remember it exporting to Python) Ofcourse, none are as robust as Delphi's. -- http://mail.python.org/mailman/listinfo/python-list
Re: scrape url out of brackets?
Regular Expressions are the most common way. http://docs.python.org/lib/module-re.html HTML parser is another http://docs.python.org/lib/module-htmllib.html -- http://mail.python.org/mailman/listinfo/python-list
Re: IDE for Python ?
[EMAIL PROTECTED] wrote: > I'm getting realy tired of learning new languages. > And especially frustrated at the 'syntax errors' when switching > between them. > > There are basically only a few common concepts needed for > all the languages. Hence linux's p2c: Pascal to C translator. > > A good IDE could hide the irrelevant details of the syntax, > much like DOS/Norton-commander--Linux/mc hides the > details, and makes visual, the common actions on files: > move, copy, view ...edit ...search etc. > > Besides, I guess Python itself would be good to make such > an IDE ? Is there any such tool available/recomended ? > > == Chris Glur. You obviously have not learnt many languages. First you have a very wrong notion that all languages are very similar. Pascal and C are similar languages (Hence P2C, BCX etc). But Pascal and C do not constitute *all* languages. There is a world of a difference between (Lisp and C) or (Haskell and Pascal) or (Prolog and Javascript). The differences between languages is not syntax but the theory and the favored model of solving problems behind them. Java, for example favors problem decomposition into objects. Lisp primarily decomposes problems to lists. Prolog to rules. Haskell to functions etc. Model representation (syntax) is secondary to this model. It is possible to represent problems at a higher level for a given model. For example OOP models can be represented in UML. MDA attempts to create executable programs based on these abstract models. These typically succeed only in well defined domains as 4GL tools. Can there be a common rendition between models of all languages? Yes. It is called machine code / byte code and it does not *hide* details from you. It is the detail. That is the marketing buzz behind .NET's CLR. Similarly there are about 200 languages / mini languages that compile to Java byte code. There have been attempts to create point and click tools for low level programming constructs like if clauses and for loops in the past. I came across atleast one for Java. I cannot remember the name now. Needless to say, none have succeeded. In short, there is no escape. If you want to create software, you must learn languages. The more you know (from different models), the better software you create, even if you can't use them all. -- http://mail.python.org/mailman/listinfo/python-list
Re: Re.'Compressing folders in Windows using Python'
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/299412 -- http://mail.python.org/mailman/listinfo/python-list
Re: Python for Lazarus (not Delphi)
Uwe Grauer wrote: > Does anyone know if something similar to Python for Delphi > does exist for lazarus? > > Thanks for any pointers, > Uwe Python for Delphi does support Lazarus since Version 3.29 http://mmm-experts.com/VersionHistory.aspx?ProductId=3 -- http://mail.python.org/mailman/listinfo/python-list
Re: python and JMS
> I am looking to use python to talk to JMS. Can some please point me to > such resources if this is possible. JPype http://jpype.sourceforge.net/ Jython http://www.jython.org/ -- http://mail.python.org/mailman/listinfo/python-list
Re: python and JMS
Alan Kennedy wrote: > [tksri2000] > > I am looking to use python to talk to JMS. Can some please point me to > > such resources if this is possible. > > PyHJB is the python-to-JMS gateway. ... via HJB, the HTTP JMS bridge. > http://hjb.python-hosting.com/ > > HJB (HTTP JMS Bridge) > http://hjb.berlios.de/ Neat. Apparently ActiveMQ supports multi-language clients through STOMP too. http://www.activemq.org/site/cross-language-clients.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Programming newbie coming from Ruby: a few Python questions
> 'Clever is not considered a compliment in Python.' (don't know where I > read that...) On a similar note. "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." -- Brian Kernighan of C -- http://mail.python.org/mailman/listinfo/python-list
Re: Programming newbie coming from Ruby: a few Python questions
> Is this kind of cleverness what is usually known as "magic"? > I suspect that this has something to do with it, but not completely > sure... :-). It must be. Now Django has a "magic removal branch". -- http://mail.python.org/mailman/listinfo/python-list
Re: New to Python-- Help
Philippe Martin wrote: > John & Mary Cook wrote: > > > I just installed Python on Windows XP Pro. When I enter 'python' at the > > >>> prompt in Pythonwin IDE I get the following: > > > > Traceback (most recent call last): > >File "", line 1, in ? > > Name Error: name 'python' is not defined > > > > Can anyone help? > > > > Thank you, > > > > J. T. Cook > > Did you install Python, or Pythonwin ? > > Cannot use #2 without #1. He probably used ActivePython. It includes both. Besides PythonWin IDE won't start without Python :-) John: Try this tutorial. It does not assume a programming background. http://honors.montana.edu/~jjc/easytut/easytut/ You already started Python when you started PythonWin IDE. You won't need to type python in it again :-) In the tutorial I linked, PythonWin is analogous to IDLE (another IDE) mentioned in it. You should also have IDLE installed in your menus. -- http://mail.python.org/mailman/listinfo/python-list
Re: The decentralized nature of the Python community is driving me crazy
> But I must say the one thing I miss about Perl is my ability to stay on > top of all the latest modules and apps in one place: CPAN. With Python, > code is EVERYWHERE - people's local boxes, sourceforge, freshmeat, > codezoo, parnassus, etc, etc. Python CheeseShop is equivalent to CPAN http://www.python.org/pypi Easy Install provides a nice client http://peak.telecommunity.com/DevCenter/EasyInstall -- http://mail.python.org/mailman/listinfo/python-list
Re: Easy to use distributed system?
Jim Jones wrote: > I am looking for a system in Python that will easily allow me to distribute > processes across multiple systems?So, if I have a function 'foo', I'd > like to be able to call something along the lines of > > distribute(foo(x)) > > And have the system figure out which node is available for process, and then > have the results returned in some sort of callback fashion. > > Any insight is greatly appreciated. Sounds like Grid computing. Google for Globus toolkit and ActiveGrid. Good luck. -- http://mail.python.org/mailman/listinfo/python-list
Re: recommended general-purpose string template packages?
> In general, I'm mainly interested in a template engine for dynamic web > pages but would like a general purpose one to avoid learning yet > another package for generating e-mail messages, form letters, source > code, whatever. > > In particular, does anyone have much experience with the Python > interface to Terence Parr's StringTemplate > (http://www.stringtemplate.org/)? Reading the website, I'm attracted by > the approach, but a Google search (both generally and in this > newsgroup) gives me the impression that it's little used in the Python > world. Most Python templating engines are general purpose. Choice between them however is sometimes a matter of preference, like editors. I settled down on Cheetah for most part. Here is a list of some popular ones. http://wiki.python.org/moin/Templating -- http://mail.python.org/mailman/listinfo/python-list
Re: sqlite3 or mysqldb?
> To learn SQL SQLite should be enough - it has all the basics, just as > MySQL, while it doesn't require any server/client configuration > (encoding configuration in MySQL is real PITA). But if you want any > "serious SQL", go with any freely available *real SQL server*, like > Firebird or PostgreSQL. I'd consider Firebird, as it's pretty lightweight. Firebird can be used as an embedded database just like SQLite as well. This gives a much more powerful database that can still be used without the administration overhead. Aside from flexibility, the reason I prefer FireBird is that it has much more sophisticated visual tools available. -- http://mail.python.org/mailman/listinfo/python-list
Re: Text to MP3 using pyTTS - Non-programmer question
[EMAIL PROTECTED] wrote: > Thanks for the script. Are there any online python intrepreters? > > I'd like to play around with the script. I don't have access to my home > PC. You probably will have to wait till you get to yours. There were some AJAXian ones but I doubt that you will find a free (assuming that you meant that) online interpreter on a MS Windows box that allows you to install your modules and give you an FTP or such account to get the recorded file back. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to catch these kind of bugs in Python?
asincero wrote: > Is there anyway to catch the following type of bug in Python code: > > message = 'This is a message' > # some code > # some more code > if some_obscure_condition: >nessage = 'Some obscure condition occured.' > # yet more code > # still more code > print message > > > In the above example, message should be set to 'Some obscure condition > occured.' if some_obscure_condition is True. But due to a lack of > sleep, and possibly even being drunk, the programmer has mistyped > message. These types of bugs would easily be caught in languages that > have a specific keyword or syntax for declaring variables before use. > I'm still fairly new to using Python on a more than casual basis, so I > don't know if Python has anyway to help me out here. The keyword is "obscure condition". The solution is to use a coverage tool and create unit tests that give you 100% code coverage. -- http://mail.python.org/mailman/listinfo/python-list
Re: What would be the best way to run python client in the background
gel wrote: > Hi > I have written a python client server app that keeps an eye on > processes starting and ending on a client and makes decision on what to > do based on information from the server end. I want to run the client > end of the app more or less invisibly (no console) on the XP clients > when ever a users logs on. What would be the best way to get this > done? A bit more info on the purpose of the app... it is to act as a > licence server, where we have a limited number of licences for software > and the software installed on all PCs. The app will only allow a pre > defined number of clients to run the software at any one time. To run a python script without a console - use *.pyw extension. But from what you stated you perhaps don't want to do this. Whether you deploy this check as a service (through py2exe for example) or a straight script, the users may simply kill it if they want to bypass the check. Plus it is not common to use a seperate persistant process to check for licenses. A better way is to incorporate the check directly into the process of the software. -- http://mail.python.org/mailman/listinfo/python-list
Re: What would be the best way to run python client in the background
> The reason for the a seperate persistant check is because it will be > used to enable software to be installed in whole lab of PCs but only > allow a predifined number to run the software at any time one time. > And then when a user stop using the software a licence will become > available to for someone else on the same or another PC to use the > software. The reason that the process of the software being check is > not used is because it will be used for software written by other > people. I hope this makes what and why a little clearer. Let me know > if you think that I have misunderstoood you. Hmm... I don't have experience with such architecture personally. The software being managed must have some sort of dependency on the license manager if the manager is to be external. I don't know how you can reliably manage external programs that are decoupled from the license manager. You can however create a plug-in of sorts if the other authors would be willing to incorporate it without much work to them. I mostly explored license management in Delphi apps. Since Delphi is/was a Shareware favorite, it has quite a few open source / commercial components available to manage such licensing, usually with trivial effort from the component user. You could take a look at them (http://www.torry.net/quicksearchd.php?String=shareware&Title=No). Some of them might even compile on Lazarus to expose them to Python. By large, the culture of Python is open source and such expertise may not be common place here. You might want to subscribe to the mailing lists of "Association of Shareware Professionals" (http://www.asp-shareware.org/). I have not been on this path in 5 years and so am out of touch. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Editor with Autocorrection
Laurentiu wrote: > hello! > > > i am searching for a free python editor with > autocorrection capabillities. > > for example:" the wrong setfocus() call to become > SetFocus(), etc." > > > thanks Python is a dynamic language, which means that methods that may not exist in your source code may spring to being at runtime at any point. So it may be undesirable to have such feature. (For example, take a look at an XML binding tool such as Amara which creates objects at runtime after parsing an XML file). Most good editors (Scintilla based editors, Emacs, Vi etc) have auto-completion for symbols that have occured in the current file; and some advanced IDEs (PyDev, WingIDE, SPE, Komodo etc) will auto-complete to some degree based on your imports through static analysis. -- http://mail.python.org/mailman/listinfo/python-list
Re: text editor suggestion?
> I also just started using Scite, and I really like it, except I find its > syntax highlighting to be very inflexible. You aren't able to define > your own groups of words -- you have to use what's given, basically. One > thing I like about UltraEdit is that you simply define as many groups of > keywords as you want and then assign a style to each one. Scite has a > very strange and rigid method of highlighting. Stick to SciTE. It takes almost no learning effort and meets everyone of those requirements. As far as customerization goes, SciTE can be customerized quite well. In fact, it can even be scripted with Lua. You seem to be using the single file executable which does not come with the configuration files. Otherwise, I cannot see how you could be missing this ability. Try this one instead if you are on Windows. http://gisdeveloper.tripod.com/scite.html You need to edit the file python.properties to add keywords. Windows - C:\Program Files\SciTe\python.properties Debian - /usr/share/scite/python.properties -- http://mail.python.org/mailman/listinfo/python-list
Re: text editor suggestion?
John Salerno wrote: > Ravi Teja wrote: > > > Stick to SciTE. It takes almost no learning effort and meets everyone > > of those requirements. As far as customerization goes, SciTE can be > > customerized quite well. In fact, it can even be scripted with Lua. You > > seem to be using the single file executable which does not come with > > the configuration files. Otherwise, I cannot see how you could be > > missing this ability. > > I really like Scite, but I find it's syntax highlighting abilities to be > quite limited. You can't specify your own groups of words, you can only > use what is already preset in the lexer files. ??? In the same file, near the top. keywordclass.python=and assert break class continue def del elif \ else except exec finally for from global if import in is lambda None \ not or pass print raise return try while yield I could add my own keywords to it. -- http://mail.python.org/mailman/listinfo/python-list
Re: text editor suggestion?
John Salerno wrote: > Ravi Teja wrote: > > > ??? > > > > In the same file, near the top. > > > > keywordclass.python=and assert break class continue def del elif \ > > else except exec finally for from global if import in is lambda None \ > > not or pass print raise return try while yield > > > > I could add my own keywords to it. > > > > But I don't want all my keywords to be highlighted in the same way. I > have different colors for Python keywords, functions and methods, > exceptions, other words like 'self', etc. and there's no way to do this > without rewriting the lexer file (which is in C++) and recompiling Scite > to build the changes into it. I don't know if SciTE somehow supports function highlighting but the properties file for php will perhaps give you some ideas on having seperate groups with different highlight properties. I recall repurposing something similar when I used to use Spyce for web apps. http://mailman.lyra.org/pipermail/scite-interest/attachments/20050912/c9d5e51b/html-0001.obj -- http://mail.python.org/mailman/listinfo/python-list
Re: ADO with Python
Ralf wrote: > Is their anybody with xperience in using the both and can provide me with > some xamples. Googling for python ado returns this simple tutorial http://www.markcarter.me.uk/computing/python/ado.html COM access in Python is straight forward with win32all. -- http://mail.python.org/mailman/listinfo/python-list
Re: More Noob Questions
> 1) I'm also learning to program flash movies while I learn to do > python. How can one implement flash movies into their python code? Depending on what "implementing flash movies into Python code" means. Python and Flash can be complementary. You can develop the UI in Flash and have it talk to Python via web services. I suppose that you can embed the Flash Player control in a wxPython app as well and drive it from there. But such integrations typically deal with some slightly advanced issues that are best left aside in context of a beginner. -- http://mail.python.org/mailman/listinfo/python-list
Re: Rapid desktop application development
Stephen Eilert wrote: > Hi all, > > There has been much hype lately about web "megaframeworks", like > TurboGears, Django and Rails(Ruby side). Those are all fantastic > frameworks, nicely integrated so that the user can focus on solving his > problem, instead of doing all the scaffolding and framework integration > by hand. > > Now, I am not a fan of web applications so I'm creating a few GUI > applications using Python. Thanks to wxPython, those are all > native-looking, with powerful components. This is quite nice. Now, I > want to use some OR-Mapper, so I chose SQLObjects. This is nice too. I > do have to write controllers, model, and all the glue code between the > frameworks by hand. > > However, I don't have to do that with a framework such as TurboGears, > for web applications. Everything is neatly integrated so that I just > have to "fill in the blanks". It would be the same application, except > that the presentation is GUI-based, instead of Web-based. MVC > architecture too and so on. > > Are there any frameworks like those, for GUI applications? It would be > interesting to abstract away that repetitive work. Dabo http://dabodev.com/ TraitsUI http://code.enthought.com/traits/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Programming Language that is Spreadsheet/Table Based
Omar wrote: > I'm looking for a programming language or module that sorta looks and > feels like MS Excel (I love and think in tables), yet has the power and > open-endedness of python or javascript. I'm still pretty new to > python. PyCells http://pycells.pdxcb.net/ http://pycells.pdxcb.net/wiki/index.php?title=Basic_Tutorial > any ideas? i've been having some fun with VBA in excel > but I want something I can save as en exe and call my own creation, y'know? You can also do Excel automation using Python. http://www.markcarter.me.uk/computing/python/excel.html There are many packaging tools for Python. Py2exe is the most popular. Although in Excel's case, it would be difficult to make stand alone. -- http://mail.python.org/mailman/listinfo/python-list
Re: Will GPL Java eat into Python marketshare?
> Personally, I've never gotten jpype to work. Is it just me, or is it > a troublesome install? > > Harry George > PLM Engineering Architecture It works fine for me now. However, I do recall having an issue a while ago (most likely me, rather than JPype). -- http://mail.python.org/mailman/listinfo/python-list
Re: Fancy GUI with Python
> Hi all. I just downloaded and installed the new Office suite from MS > with their new 'ribbon' based UI. I think it's pretty cool and AFT* > for a new UI paradigm. I hope it sticks. > Anyway, I'm wondering how to implement a gui like this with Python. I haven't seen their new Office suit (apart form a few screenshots). Judging from the past, the code is probably statically linked to MS Office. Many of the previous iterations of MS Office did introduce their own look and feels, effects and widgets. Third party Windows developers soon followed suit reimplementing the widgets. Delphi community for example focuses a lot on UI and UI effects (Python community does not). VCL libraries can be compiled to ActiveX components and you should then be able to use them from Python, at least on Windows. Or maybe someone will make a .NET assembly and you will be able to drive it from IronPython or Python for .NET. If you are lucky, it may even be cross-platform via Mono. > So I'm not sure if this is a Python question, a xxx-Python question > (where xxx is the widget toolkit of choice), or a windows API type of > question. This is NOT a Python specific issue. It is a widget library and FFI (Foreign Function Interface) issue. If another language can get at the functionality, so can Python. -- http://mail.python.org/mailman/listinfo/python-list
Re: html 2 plain text
> i remember seeing this simple python function which would take raw html > and output the content (body?) of the page as plain text (no <..> tags > etc) http://www.aaronsw.com/2002/html2text/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Need C# Coding for MD5 Algorithm...
> I need C# code for Implementing MD5 Algorithm. So ask in a C# group. Python's is here http://docs.python.org/lib/module-md5.html > please Send... ITs URgent http://www.catb.org/~esr/faqs/smart-questions.html#urgent -- http://mail.python.org/mailman/listinfo/python-list
Re: How to access the content of notepad with Python?
> I have a software running on my computer that really looks like notepad > ( same interface, different name). I need to write a script that will > capture the content of this software --> the text written inside. > > Is it possible using win32 libs? any clue? http://www.openqa.org/pywinauto/ The example on their home page is in fact how to automate Notepad. I am sure you can work from there. -- http://mail.python.org/mailman/listinfo/python-list
Re: New to Python: Do we have the concept of Hash in Python?
A.M wrote: > "Fredrik Lundh" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > A.M wrote: > > > >> This is my 1st day that I am seriously diving into Python and I have to > >> finish this application by the end of today. Maybe it wasn't a good idea > >> to choose the language that I don't know when I have to deliver my work > >> in such short time. > > > > are your boss aware of this ? > > > > > > > > > > are your boss aware of this ? > > In fact my boss is quite impressed with my progress so far. > > > > I am a little confused about the fact that you got frustrated with my posts > today. I am not asking for a big tutorial or > > deepest philosophy behind the concepts. The answer to this post could be > just the word "Dictionary" which is 10 key stroke ! > > Does this hurt? IRC is a better place to request 10 key stroke answers. And it is faster for you to get answers there too. Usenet is archived these days and it adds value to all of us that it is filled with discussions of questions that are more intellectual than those which can be looked up at a glance at the documentation. -- http://mail.python.org/mailman/listinfo/python-list
Re: in python , could I accomplish the purpose that "a=Console.read()" used in C?
Bruno Desthuilliers wrote: > python a écrit : > > in python , could I accomplish the purpose that "a=Console.read()" used > > in C? > > > There's nothing like "Console.read()" in ansi-C. > He probably got it mixed up with C# which ( almost - Console.Read() ) has that. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python or Ajax?
> I've been hearing a ot about AJAX lately. I may have to build a web > application in the near future, and I was curoius: > > How does a web application that uses Python compare with one that uses AJAX? > > I've done some basic web page design with HTML and CSS, but never any > web applications. I don't want to learn a new language if I can use > Python. Would AJAX offer me any significant advantages? AJAX is *NOT* a programming language. It is a certain way of building web applications. Any Python (or any other language) web framework may be used, though some (TurboGears / LivePage etc) have explicit support for it. I bit of googling does not hurt. -- http://mail.python.org/mailman/listinfo/python-list
Re: Combining The Best Of Python, Ruby, & Java??????
Tim Daneliuk wrote: > So it is claimed: > > > http://www.infoq.com/news/Scala--combing-the-best-of-Ruby-;jsessionid=CC7C8366455E67B04EE5864B7319F5EC > > Has anyone taken a look at this that can provide a meaningful contrast > with Python? I find the language very interesting but it is not like Python or Ruby at all. Feels a lot more like OCaml + Haskell for JVM with a more mainstream (Java) syntax. -- http://mail.python.org/mailman/listinfo/python-list
Re: Combining The Best Of Python, Ruby, & Java??????
> Ok, here's the Hello World example from the Scala website: > > object HelloWorld { > def main(args: Array[String]) = { > Console.println("Hello, world!") > } > } > > Opening and closing braces? > "def main(args: Array[String])"? > Console.println? > > About the only Pythonic thing I can see here is the "def" keyword. > Otherwise, it looks too much like Java - no, thanks! > > -- Paul Don't be too harsh on it though. It is a language built for the JVM/CLR. The author perhaps intended the library to be natural to the users of the respective SDKs regardless of its' aesthetics and it explicitly seems to provide a unified API for Java and .NET. Of course, that is nothing new. Many languages have interchangeable backends for these platforms these days but there seems to be a specific focus on that here. The syntax does resemble Java/C#, which is also important if you want buy in from the Java/C# crowd. But semantically it is a proper functional language. The features may not attract Python users who might prefer Boo/Jython/IronPython. But it does offer something to disillusioned Groovy users. But on the other hand, there are some neat features even for Python programmers. Tail recursion Pattern matching Currrying Macros Concurrency Native XML support Of course, you can get by without some of these in Python with workarounds, libraries or hacks. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496691 http://www.python.org/dev/peps/pep-0309/ (in 2.5) http://logix.livelogix.com/ (offline) -- http://mail.python.org/mailman/listinfo/python-list
Re: Combining The Best Of Python, Ruby, & Java??????
Diez B. Roggisch wrote: > > But semantically it is a proper functional language. The features may > > not attract Python users who might prefer Boo/Jython/IronPython. But it > > does offer something to disillusioned Groovy users. > > Are they disillusioned? Just wondering. Nah! Just a poor passing attempt at humor. Groovy is a great language too. I should watch out. Maybe Groovy programmers have knives too :-). http://cardboard.nu/blog/2005_02_02/gosling_on_jvm_scripting.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Combining The Best Of Python, Ruby, & Java??????
Luis M. González wrote: > Diez B. Roggisch wrote: > > > But semantically it is a proper functional language. The features may > > > not attract Python users who might prefer Boo/Jython/IronPython. But it > > > does offer something to disillusioned Groovy users. > > > > Are they disillusioned? Just wondering. > > > > Diez > > Whay talking about disillutioned programmers? > These are tools, not religions... > I love python, and I like it more everyday. And with the advent of > Pypy, its future looks brighter than ever. > But I also find very interesting these new options that are coming up. > Although I'm not a professional programmer (not even a serious > aficionado), I love to be able to translate my python skills very > easily to .NET through Boo, for example. > I even find it more appealing than Ironpython, because it was created > from the ground up to take advantage of the CLR. > On the other hand, porting pure python to .NET is in many aspects like > trying to fit a square on a circle (I don't know if this sentence makes > sense in english...). > Because many of the design choices taken by GvR back in the early > nineties were surely conditioned by the platform he chose to write > python, which is the c language. > The good thing is that python is having a lot of influence in these new > languages. > As far as I could see, even C# 3.0 is showing up some pythonic traits. I did not realize the flame potential of that remark. Just to clarify, I have no criticism of any kind on Groovy. I mentioned Groovy since Scala, the original topic of the thread addresses the needs of the same group (a modern language with a Java friendly syntax). I am not a language bigot. Note that I am defending Scala, a new language, in this thread so far. I do not want this thread to break into a language war from my remark. I hope that Python gets some of the features listed in my above post in it's own unique Pythonic way eventually. The discussion perhaps is more constructive if we can see some good in Scala that is worth adopting. -- http://mail.python.org/mailman/listinfo/python-list
Re: code is data
Paddy wrote: > Anton Vredegoor wrote: > > With the inclusion of ElementTree (an XML-parser) in Python25 and recent > > developments concerning JSON (a very Pythonesque but somewhat limited > > XML notation scheme, let's call it statically typed XML) > > > > Your thoughts please. > > > > Anton > > Hi Anton. > If you mean this JSON: http://www.json.org/example.html > then I'd just point out that JSON isn't XML-like at all. In fact the > examples look like valid Python nested dictionaries. It is the same JSON. JSON is typically seen as a human friendly replacement for some of the functions that XML is otherwise used for, where the full blown XML spec is an overkill and JSON does not need complicated parsers in some common languages because it can express hierarchical data just like XML. -- http://mail.python.org/mailman/listinfo/python-list
Re: code is data
Anton Vredegoor wrote: > With the inclusion of ElementTree (an XML-parser) in Python25 and recent > developments concerning JSON (a very Pythonesque but somewhat limited > XML notation scheme, let's call it statically typed XML) Python seems to > have reached a stage where it now seems to be possible to completely > swallow lesser languages code, modify it, and spit out new source code > targeting the original language the code was written in, or even make a > translation to other languages. > > The idea is that we now have a fast parser (ElementTree) with a > reasonable 'API' and a data type (XML or JSON) that can be used as an > intermediate form to store parsing trees. Especially statically typed > little languages seem to be very swallow-able. Maybe I will be able to > reimplement GFABasic (my first love computer language, although not my > first relationship) someday, just for fun. > > Then there are things like cTypes (calling functions from native DLL's) > and PyPy (implementing Python in Python). > > All this taken together, to me it starts looking like we're now entering > a territory that traditionally was exclusively in the Lisp domain. > > Yes, Python had eval and exec for a long time already, and metatypes and > generators are having some strange unexplored possibilities too, but the > day will come soon (and at last when PyPy is reaching execution speeds > close to cPython) where Python will be able to swallow smaller > languages, and finally it will be able to swallow its own tail, like > Lisp but then more powerful (because of the widely used standard data > types and the code exchange between languages that that makes possible). > > Your thoughts please. I don't share your optimism at all. Most of the things you mentioned have existed for long. Just because some of them are now included in the standard library isn't going to change things drastically. Installing them earlier was never hard at all. People like to call everything with the lightest semblence, a DSL. That gives the feel that the language is more powerful. Ruby people do it all the time. Python cannot be called a DSL language until, creating them is a natural language feature (like Lisp). And that does not seem to be happening anytime soon. Boo for example allows you to write new constructs with it's AST library. It still cannot be called a DSL "language". People have however written various language interpreters (Scheme, Forth and yes, even Basic) in Python, just for kicks. Still does not make it a DSL language anymore than it makes C a DSL language. At present, the closest thing to writing a DSL in Python is Logix http://livelogix.net/logix/ Too bad though, the project is defunct and there has never been enough interest in it. Personally, I would like to see macros in Python (actually Logix succeeding is good enough). But I am no language designer and the community has no interest in it. When I absolutely need macros, I will go elsewhere. -- http://mail.python.org/mailman/listinfo/python-list
Re: Standard Yes / No Windows Dialog box creation
[EMAIL PROTECTED] wrote: > I found a way to create "Open File" or "Open Folder" windows dialog > boxes, but not to create an easier Yes / No dialog box... > Maybe someone has a solution for this? Assuming you are on MS Windows. import win32api, win32con win32api.MessageBox(0, "Question", "Title", win32con.MB_YESNO) -- http://mail.python.org/mailman/listinfo/python-list
Re: code is data
BJörn Lindqvist wrote: > > Personally, I would like to see macros in Python (actually Logix > > succeeding is good enough). But I am no language designer and the > > community has no interest in it. When I absolutely need macros, I will > > go elsewhere. > > One must wonder, when is that? When do you absolutely need macros? Whenever there is significant boiler plate code that functions and classes cannot eliminate alone. Whenever there is a more elegant way to express your code. Python 2.5 introduced conditional expressions and with statement. With macros, one would not have to wait for the language team to implement them. More so for features which only a small part of the community has an interest in. I *like* 1..5 (ada, ruby) instead of range(5). If I had macros, I would have done it myself for *my* code. I would like special behaviour code blocks in my programs, for say DBC (I am aware of the work arounds). -- http://mail.python.org/mailman/listinfo/python-list
Re: code is data
Paddy wrote: > Ravi Teja wrote: > > BJörn Lindqvist wrote: > > > > Personally, I would like to see macros in Python (actually Logix > > > > succeeding is good enough). But I am no language designer and the > > > > community has no interest in it. When I absolutely need macros, I will > > > > go elsewhere. > > > > > > One must wonder, when is that? When do you absolutely need macros? > > > > Whenever there is significant boiler plate code that functions and > > classes cannot eliminate alone. > > Whenever there is a more elegant way to express your code. > > > > Me, I am torn. I should now better. I have listened to the arguments > against Macros in Python and the ones that struck home were the > argument for maintainability: > Without macros, Python is Python. Statements do what you expect. Yes! I heard those arguments too. And I am not convinced. Static language programmer: Lack of static typing removes the necessary safeguards. The code is more error prone. Objects have behavior that is not obvious. Dynamic language programmer: Really? I don't seem to have any more bugs than in my statically typed code. And my code is compact and reads better. I don't want to go back. No to macros proponent: Macros introduce a lot of potential for abuse. Code will be worse to read than Perl. Macros proponent: Really? We have been doing macros for decades. We all think our code is better for macros, not worse. We are not going back. I just don't get it. Don't we often invoke the "We are all adults here" argument. Writing a macro is not as simple as writing a function. Sort of like metaclasses. Many will stay off them. Those that really need them will walk that extra mile. Don't we all believe that "Simple should be possible. Complex should be doable" > And the argument against DSLs altogether: > Make Python your DSL! If you design your own DSL before long you start > to embellish it with more statements or data types and before long it > becomes complex. If you used Python from the beginning then you would > have a community for support. Python has a low cognitive overhead. But it not a DSL by definition. No language can be. The idea is that when the domain changes, a DSL should be driven by the new domain as warranted. In other words, driven "by the problem, not the tool". I don't want "a DSL". I want a language that allows me to make "my DSL" based on it. That means I don't loose the community connection. I can still use all the rich libraries in my DSL. I like Python for its indentation syntax, sensible semantics and readability. I invested a lot of time in Python. After much language hopping, I settled with Python. I like the community and the code base available for it. The libraries just seem to be designed at the right level of abstraction for me (as opposed to say, Java). When I need to do something, I know where to go. But all this ties me to the language tightly that I cannot change. > I know the arguments, but every once in a while I think if only I could > craft my own ??? statement or My thoughts exactly. Web frameworks, which seem to be the rage now in Python community could have benefited tremendously from Macro capabilities since they have a lot of boiler plate. -- http://mail.python.org/mailman/listinfo/python-list
Re: code is data
Fredrik Lundh wrote: > Ravi Teja wrote: > > > Web frameworks, which seem to be the rage now in Python community could > > have benefited tremendously from Macro capabilities since they have a > > lot of boiler plate. > > they do? methinks you haven't done much web programming lately... > > You blogged on Django. Let's use that. Don't you think model creation in Django can be represented better, given that it is done often enough? Let's take an example from the official tutorial from http://www.djangoproject.com/documentation/tutorial1/#creating-models class Poll(models.Model): question = models.CharField(maxlength=200) pub_date = models.DateTimeField('date published') class Choice(models.Model): poll = models.ForeignKey(Poll) choice = models.CharField(maxlength=200) votes = models.IntegerField() I don't use Django and I made this up quickly, so please don't pick on subtleties. @Poll: question: char length 200 pub_date('date published'): date @Choice: poll -> Poll choice: char length 200 votes: int The following is my rationale. Annoted variables, symbols and code layout visually cue more efficiently to the object nature than do explicit text definitions. Of course, this is only sensible when there aren't too many of any of those. In that case, the cognitive cost of notation outweighs the representational cost of text. Representational minimalism is troublesome in general code (ala Perl), but not so in a DSL where the context is constrained. I would also like to symbolize field types since they occur so commonly in a definition file and only a few of them are commonly used. I admit though that I find the code below a bit visually jarring and I might use something else. But it serves to illustrate the point. I chose the respective symbols based on their colloquial use and association with the field types. @Poll: $question: length 200 %pub_date('date published') @Choice: poll -> Poll $choice: length 200 #votes Since you are on thread and are a prominent and involved member of the Python community, I would like it if you (or any such other) can provide feedback on the rest of my previous post rather than be dismissive by just a small portion of it. Perhaps, that will give me some insight how these language design decisions are rationally made (I am not strictly a programmer by profession, much less a language designer). -- http://mail.python.org/mailman/listinfo/python-list
Re: code is data
BJörn Lindqvist wrote: > > > > community has no interest in it. When I absolutely need macros, I will > > > > go elsewhere. > > I *like* 1..5 (ada, ruby) instead of range(5). If I had macros, I would > > have done it myself for *my* code. > I think this example more is a symptom of a childish need to get > things your way than of a deficiency in Python. I thought I had enough asterisks in there to indicate that it is a preference that I will not be defending on rational grounds. I had a better argument before it in the same post. But you had to choose only the trivial one to dismiss me as childish. Didn't you? :-) > BTW, range(5) = 0..4 in Ada and Ruby. My bad. I usually write range(1, 5 + 1) to get 1..5. I could write range(1, 6). But I would like to see the upper bound explicitly. Of course, I could write a function to wrap that up. > You said "when I absolutely need macros" but none of your examples > demonstrate any "absolute need." I can't see your point. Did you miss the word - *WHEN*? I don't need them absolutely now. And I know, that I won't get them here. And just so you don't misinterpret, I don't call that a "deficiency". Just a mismatch between the personal and the community mindset. BTW, the recent language changes - decorators, conditional expressions and with statements are not absolute either. That did not stop them from being welcome additions. -- http://mail.python.org/mailman/listinfo/python-list
Re: code is data
Kay Schluehr wrote: > Ravi Teja wrote: > > > People have however written various language interpreters (Scheme, > > Forth and yes, even Basic) in Python, just for kicks. Still does not > > make it a DSL language anymore than it makes C a DSL language. > > > > At present, the closest thing to writing a DSL in Python is Logix > > http://livelogix.net/logix/ > > Too bad though, the project is defunct and there has never been enough > > interest in it. > > You might be interested in EasyExtend: > > http://www.fiber-space.de/EasyExtend/doc/EE.html Your framework does look very interesting and might just be what I am looking for. Will give it a try. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: code is data
> Or... maybe to be more specific, the hard work later on goes into > *code*. If you are enhancing your model, you do so with methods on the > model classes, and those methods don't effect the DSL, they are just > "code". You create some raw XML in the beginning, but quickly it's > just a matter of gluing those pieces together, using functions instead > of DSLs, and that's just "code". > That doesn't look that much better. How do you create it > programmatically? I know how to pass a variable to > CharField(maxlength=200); can I pass a variable to "char length 200" > just as easily? Can I use **kw? Can I read it from a CSV file and > construct the class that way? Maybe, but only by recreating all the > native patterns that I can infer easily looking at the Django class. I am looking at it from the cognitive perspective. You are looking at it from the compiler perspective. I think you are talking about full blown DSLs like SQL which try to be self contained for a given domain. The ones I am referring are only thin layers on Python. > Words are great. Python is light on symbols, and that is good. Agreed. When I came to Python from Perl, I loved the clean syntax. Scalars, arrays, hashes occur too frequently in Perl code that using symbols to denote them causes more noise than cognitive assistance. On the other hand, using symbols to denote an occational special construct is helpful (as in decorators). > Even the Lisps stick to an incredibly homogenous syntax (far more > homogeneous than Python) to make macros feel familiar. Yes! The parser friendly, "everything is a list" syntax does help. I did consider that to be an essential feature to enable dynamic macros. However I changed my mind when I saw Logix macro syntax. > Constrained context is a step backward! How do you add methods? How > do you do looping? How do you write *code*? If you aren't going to > allow those things, then just make a parser and build the structure > from the file, and make it a DSL implemented entirely external to > Python. That's completely okay, though in my experience it's not very > satisfying for something like a model definition (see MiddleKit for an > example of an ORM that doesn't use Python code). I agree that constrained context is a step back in terms flexibility. But it is a strategic step backwards, in this case to trade for representational benefits. The extent of constraints is a judgement call. And proof of utility can only be emperical. However I think that you are seeing my sample differently than I meant it. I did not mean to create a special syntax file that would be parsed as a text file such that it would loose all the benefits of Python. It is just a thin layer over Python code for specific representational benefits. Kay Schluehr does a good job of identifying it as such in his reply. -- http://mail.python.org/mailman/listinfo/python-list