WSDL and SSL certification
Hi, I have a problem with processing WSDL file using SOAP. I want to call Rhapsody webservice using Python. But i have SSL certification key and cert , how to pass this information when i calling wsdl file. eg: Expand|Select|Wrap|Line Numbers file = 'RhapsodyDirectSearch.wsdl' file1= "RhapsodyDirectPlayback.wsdl" server = WSDL.Proxy(file) print server.methods.keys() print "Number is ", server.getVersionString() I am using playback wsdl ,but it required ssl certification, when i call these methods , i get an error like Expand|Select|Wrap|Line Numbers File "C:\Python25\Lib\site-packages\SOAPpy\Client.py", line 347, in __call config = self.config) File "C:\Python25\Lib\site-packages\SOAPpy\Client.py", line 187, in call r.endheaders() File "C:\Python25\lib\httplib.py", line 860, in endheaders self._send_output() File "C:\Python25\lib\httplib.py", line 732, in _send_output self.send(msg) File "C:\Python25\lib\httplib.py", line 699, in send self.connect() File "C:\Python25\lib\httplib.py", line 1135, in connect ssl = socket.ssl(sock, self.key_file, self.cert_file) File "C:\Python25\lib\socket.py", line 74, in ssl return _realssl(sock, keyfile, certfile) socket.sslerror: (1, 'error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure') server.startPlaybackSession() How to solve these Please help me How to pass ssl certificaction to process wsdl file.I am using SOAP method Please give me answer ,it is very urgent -- http://mail.python.org/mailman/listinfo/python-list
Re: asp versus cgi
davidj411 <[EMAIL PROTECTED]> wrote: > >when i use cgi, i never get a 500 error but i can see how it might >take on overhead if many users are hitting the site at once. so to >avoid this, i looked into registering the python engine for ASP >requests. It is easy to overestimate the overhead of CGI. Unless you are getting tens of requests every second, the overhead is insignificant, and CGI is pretty easy to handle and debug. > >this is the ASP code when using GET method: > ><%@ LANGUAGE = Python%> > ><% >import sys >sys.stdout=sys.stdin What do you believe that statement is doing? >POST by the way seems to have a 100 kb limit so why ever use it unless >you need to keep the data out of the URL?) No, POST doesn't have a 100 kB limit. When you upload a file to a web site, it's sent through a POST request. However, keeping data out of the URL is a big factor. -- Tim Roberts, [EMAIL PROTECTED] Providenza & Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: end of print = lower productivity ?
[EMAIL PROTECTED] wrote: > >When I write "print", it is both effortless and instantaneous : my >hands do not move, a wave goes through my fingers, it all happens in a >tenth of a second. > >Contrast this with what one has to go through to catch the SHIFT key, >and then the "(" : move the left hand, press SHIFT, move the right >hand, aim "(", press, miss, press again. Same thing at the end of the >function call. > >I know it sounds ridiculous, but it does *impair* my debugging >productivity. Taylor would agree. Although I'm not sure I will have the same issue with "print", I can sympathize with what you are saying. I spend virtually all of my time in a command line. As a Windows driver guy, I work a lot in the \windows\system32\drivers directory. I got used to typing that as \wi \syst \dr letting tab completion fill it in. Well, in Windows XP, Microsoft introduced a new utility in "system32" called "driverquery.exe". Because it is alphabetically before "drivers", that now appears. Now, you would think that this is just a trivially minor inconvenience, but to this day, 6 years after XP, I still find myself looking at "driverquery.exe" instead of the "drivers" directory. -- Tim Roberts, [EMAIL PROTECTED] Providenza & Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: special editor support for indentation needed.
Andreas Roehler wrote: > > with python-mode.el from > > http://sourceforge.net/projects/python-mode/ I think there's something wrong with the site because it tells me it's version 1.0 from year 2005. > Meanwhile I'll reflect a draft addressing your needs. there is a rather sizable set of things that could be added to assist speech during programming. I'm mostly concerned about the editing aspect of speech driven programming. > > BTW, what about this stuff?: > > http://www.cb1.com/~john/computing/emacs/handsfree/index.html it's interesting but most of it is very low level user interface orientation. Lo level stuff is relatively easy to implement. High-level stuff is much more difficult than the equivalent GUI abstraction. a narrow channel interface stuff is very interesting especially if you take full advantage of the concept. With regards to programming, a narrow channel interface would let you choose a relatively low number of "big" items in the field of vision and then let you continue to narrow until you can easily operate on the item of interest. -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting in to metaprogramming
On Nov 27, 12:11 pm, Rafe <[EMAIL PROTECTED]> wrote: > On Nov 27, 11:41 am, "Hendrik van Rooyen" <[EMAIL PROTECTED]> > wrote: > > > > > "Steven D'Aprano" wrote: > > > > Well, I don't know about "any problem". And it's not so much about > > > whether metaprograms can solve problems that can't be solved by anything > > > else, as whether metaprograms can solve problems more effectively than > > > other techniques. > > > > If you include factory functions, class factories, the builder design > > > pattern, metaclasses, etc. as "metaprogramming", then I use it all the > > > time, and find it an excellent technique to use. > > > > But if you mean using a Python program to generate Python source code, > > > then I can't think of any time I used it. Which doesn't mean that others > > > don't find it helpful, only that I haven't yet. > > > I am using the term in the restricted sense of Python writing Python source. > > > Given that, can anybody think of an example that you could not do with > > a class? (excepting the "stored procedure" aspect) > > > Or can I claim a new a new meta - rule - I would call it van Rooyen's > > folly... > > > > Thinking further back, when I was young and programming in Apple's > > > Hypercard 4GL, I used to frequently use Hypercard scripts to generate new > > > Hypercard scripts. That was to work around the limitations of the > > > scripting language. > > > What sort of stuff did you do, and would having had simple OO available > > have rendered it unnecessary? > > > > I don't think metaprogramming in the limited sense (programs to output > > > source code) is a bad idea, but I do think that there are probably better > > > alternatives in a language like Python. > > > True. No argument here - I was just wondering if the relationship holds. > > > - Hendrik > > "Given that, can anybody think of an example that you could not do > with a class?" > > Generating a template for a specific script application. For example, > a script with pre-defined callbacks that only require the addition of > the contents. > > I was really interested in exploring the idea of using python output, > instead of XML, to record something a user did in a GUI. I have seen > it done and it is really advantageous in the 3D industry because it > means the script files can be edited directly, in a pinch, to generate > something slightly different. > > For example, say we have code which generates a cube by plotting it's > points. A user then changes a point position in the GUI. The change is > saved by outputting the function call to a file with new arguments > (the new point location). If I wanted to make 100s of copies of the > cube, but with a slightly different point position, I could edit the > custom cube's python code and hand it back for creation without using > the GUI. I could do this with XML, but it can be harder to work with > in a text editor (though I have seen some XML editors that make it a > bit easier.) In fact, in most 3D applications, the app prints > everything the user does to a log. Sometimes in a choice of languages, > so I guess I am looking to do the same thing with my own custom tools. > > In a real situation the generated code file can build some pretty > complex 3D object hierarchies. It moves beyond simple storage of data > and becomes a real script that can be hacked as necessary. > > It is nice to have everything as python scripts because we always have > a blend of GUI users and developers to get a job done. > > -Rafe I was just thinking (hopefully i get some time to try this soon) that it wouldn't be difficult to decorate a function so that when called, a line of code is output. as long as the arguments can be stored as a string (strings, numbers, lists, etc. but no 'object' instances) it should be able to be executed to get the same result. I think it would just have to: 1) Dynamically write the name with a '(' 2) Gather all the args in a list and ", ".join(args) 3) Gather kwargs as a list of ['%s = %s' % key, value] and then and ", ".join(kwlist) 4) Add ')\n' - Rafe -- http://mail.python.org/mailman/listinfo/python-list
Confused about class relationships
Apologies if this is a D.Q., I'm still learning to use classes, and this little problem has proved too specific to find in the tutorials. I have two classes with a relationship that I find confusing. One is called Engine, and it has a method (bar_builder) which generates instances of the other class, called Bar (not as in Foo but as in bar of music; inherits from list). Also, Bar takes the generating instance of Engine as an argument to its __init__ method: class Bar(list): def __init__(self, a_bar, args, engine): list.__init__ (self, a_bar) self[:] = a_bar self.args = args self.engine = engine #more instance attributes... #methods... class Engine: def __init__(self, args): self.args = args #more instance attributes... def bar_builder(self): #body of method generates lists... yield Bar([generated_list], args, self) #more methods... #(other stuff...) def main(args): engine = Engine(args) bars = engine.bar_builder() for a_bar in bars: #play the music!... While this works (to my surprise!) and solves the problem which motivated it (i.e. Engine instances need to pass some attributes to Bar instances ), it seems too convoluted. Should one class inherit the other? If so, which way around? Or is it fine as is? I'm hoping this is a common trap I've fallen into; I just haven't been able to get my head around it. (I'm a musician...) John O'Hagan -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie question
On Nov 27, 6:11 am, Nan <[EMAIL PROTECTED]> wrote: > Hello, > I just started to use Python. I wrote the following code and > expected 'main' would be called. > > def main(): > print "hello" > > main Not an answer to your question, but I dislike functions named 'main' because the situation they occur in would better be dealt with by exploiting the name of the built-in module '__main__'. But maybe that's just me. However, consider your code rewritten thusly: def greet () : print "hello" if __name__ == '__main__' : greet() (A more literal translation of your program would be: if __name__ == '__main__' : print 'hello') This little trick ensures that greet() will execute if the module is itself executed as a script, but that it won't if you import it from elsewhere (ie. another script or the intepreter). IMHO, it's good practice, wherever you may be tempted to write 'def main()', intending this to be the glue code for your various functions etc, instead to test whether the code is running as __main__ as above. -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting in to metaprogramming
On Nov 27, 11:41 am, "Hendrik van Rooyen" <[EMAIL PROTECTED]> wrote: > "Steven D'Aprano" wrote: > > > > > Well, I don't know about "any problem". And it's not so much about > > whether metaprograms can solve problems that can't be solved by anything > > else, as whether metaprograms can solve problems more effectively than > > other techniques. > > > If you include factory functions, class factories, the builder design > > pattern, metaclasses, etc. as "metaprogramming", then I use it all the > > time, and find it an excellent technique to use. > > > But if you mean using a Python program to generate Python source code, > > then I can't think of any time I used it. Which doesn't mean that others > > don't find it helpful, only that I haven't yet. > > I am using the term in the restricted sense of Python writing Python source. > > Given that, can anybody think of an example that you could not do with > a class? (excepting the "stored procedure" aspect) > > Or can I claim a new a new meta - rule - I would call it van Rooyen's folly... > > > > > Thinking further back, when I was young and programming in Apple's > > Hypercard 4GL, I used to frequently use Hypercard scripts to generate new > > Hypercard scripts. That was to work around the limitations of the > > scripting language. > > What sort of stuff did you do, and would having had simple OO available > have rendered it unnecessary? > > > > > I don't think metaprogramming in the limited sense (programs to output > > source code) is a bad idea, but I do think that there are probably better > > alternatives in a language like Python. > > True. No argument here - I was just wondering if the relationship holds. > > - Hendrik "Given that, can anybody think of an example that you could not do with a class?" Generating a template for a specific script application. For example, a script with pre-defined callbacks that only require the addition of the contents. I was really interested in exploring the idea of using python output, instead of XML, to record something a user did in a GUI. I have seen it done and it is really advantageous in the 3D industry because it means the script files can be edited directly, in a pinch, to generate something slightly different. For example, say we have code which generates a cube by plotting it's points. A user then changes a point position in the GUI. The change is saved by outputting the function call to a file with new arguments (the new point location). If I wanted to make 100s of copies of the cube, but with a slightly different point position, I could edit the custom cube's python code and hand it back for creation without using the GUI. I could do this with XML, but it can be harder to work with in a text editor (though I have seen some XML editors that make it a bit easier.) In fact, in most 3D applications, the app prints everything the user does to a log. Sometimes in a choice of languages, so I guess I am looking to do the same thing with my own custom tools. In a real situation the generated code file can build some pretty complex 3D object hierarchies. It moves beyond simple storage of data and becomes a real script that can be hacked as necessary. It is nice to have everything as python scripts because we always have a blend of GUI users and developers to get a job done. - Rafe -- http://mail.python.org/mailman/listinfo/python-list
Re: Exhaustive Unit Testing
On Wed, 26 Nov 2008 18:54:52 -0800, Emanuele D'Arrigo wrote: > Hi everybody, > > another question on unit testing, admittedly not necessarily a python- > specific one... > > I have a class method about 60 lines long (*) and due to some 9 non- > trivial IFs statements (3 and 2 of which nested) the number of possible > paths the program flow can take is uncomfortably large, each path > characterized by an uncomfortably long list of careful turns to take. Nine non-trivial if statements, some of which are nested... uncomfortably large... uncomfortably long... these are all warning signs that your method is a monster. I would say the obvious solution is to refactor that method into multiple simpler methods, then call those. Not only does that make maintaining that class method easier, but you can also unit-test each method individually. With nine if-statements, you have 512 program paths that need testing. (In practice, there may be fewer because some of the statements are nested, and presumably some paths will be mutually exclusive.) Refactor the if...else blocks into methods, and you might have as many as 18 paths to test. So in theory you should reduce the number of unit-tests significantly. > Given that all paths have large portions of them overlapping with each > other, is there a strategy that would allow me to collapse the many > cases into only a few representative ones? That would be impossible to answer without knowing what the method specifically does and how the many cases interact with each other. > I can sense that exhaustively testing all paths is probably overkill. I don't agree. If you don't test all the paths, then by definition you have program paths which have never been tested. Unless those paths are so trivially simple that you can see that they must be correct just by looking at the code, then the chances are very high that they will hide bugs. > On > the other hand just going through all nodes and edges between the nodes > -at least once- is probably not enough. Is there any technique to find > the right(ish) middle? Refactor until your code is simple enough to unit-test effectively, then unit-test effectively. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
rejecting newlines with re.match
Hi, I want to use a regex to match a string "poo" but not "poo\n" or "poo"+chr(13) or "poo"+chr(10) or "poo"+chr(10)+chr(13) According to http://docs.python.org/library/re.html '.' (Dot.) In the default mode, this matches any character except a newline. If the DOTALL flag has been specified, this matches any character including a newline. So I tried a = re.compile(r'^.{1,50}$') print a.match("poo\n") <_sre.SRE_Match object at 0xb7767988> :-( The library says... '$' Matches the end of the string or just before the newline at the end of the string, and in MULTILINE mode also matches before a newline. foo matches both ‘foo’ and ‘foobar’, while the regular expression foo$ matches only ‘foo’. More interestingly, searching for foo.$ in 'foo1\nfoo2\n' matches ‘foo2’ normally, but ‘foo1’ in MULTILINE mode; searching for a single $ in 'foo\n' will find two (empty) matches: one just before the newline, and one at the end of the string. So that explains it but what am I to do then? I assume it isn't matching the newline itself as the returned string does not contain one but is there a switch that can stop $ matching 'just before the newline at the end of the string' or is there another character class I could use here? Any ideas greatly appreciated! Thanks, Roger. -- http://mail.python.org/mailman/listinfo/python-list
datig girls - Free Access
datig girls . . . Free Online Dating . ***CLICK HERE*** http://dating365.co.cc/datig-girls * . Free Online Dating . . . . . . . . . . datig girls -- http://mail.python.org/mailman/listinfo/python-list
online dateing service - Free Access
online dateing service . . . Free Online Dating . ***CLICK HERE*** http://dating365.co.cc/online-dateing-service * . Free Online Dating . . . . . . . . . . online dateing service -- http://mail.python.org/mailman/listinfo/python-list
internet dateing - Free Access
internet dateing . . . Free Online Dating . ***CLICK HERE*** http://dating365.co.cc/internet-dateing * . Free Online Dating . . . . . . . . . . internet dateing -- http://mail.python.org/mailman/listinfo/python-list
black dateing - Free Access
black dateing . . . Free Online Dating . ***CLICK HERE*** http://dating365.co.cc/black-dateing * . Free Online Dating . . . . . . . . . . black dateing -- http://mail.python.org/mailman/listinfo/python-list
free online dateing - Free Access
free online dateing . . . Free Online Dating . ***CLICK HERE*** http://dating365.co.cc/free-online-dateing * . Free Online Dating . . . . . . . . . . free online dateing -- http://mail.python.org/mailman/listinfo/python-list
dateing girls - Free Access
dateing girls . . . Free Online Dating . ***CLICK HERE*** http://dating365.co.cc/dateing-girls * . Free Online Dating . . . . . . . . . . dateing girls -- http://mail.python.org/mailman/listinfo/python-list
Re: Is the behavior expected?
all the discussions are very helpful to me. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is the behavior expected?
On 11月27日, 上午12时07分, Peter Otten <[EMAIL PROTECTED]> wrote: > Alphones wrote: > > On 11月26日, 下午9时28分, [EMAIL PROTECTED] wrote: > >> Alphones: > > >> > it is a little deferent from other script language. > > >> See also here:http://en.wikipedia.org/wiki/Dynamic_scope#Dynamic_scoping > > >> Python doesn't have such automatic closures, probably for performance > >> reasons and/or maybe to keep its C implementation simpler (maybe other > >> people here can give you an explanation of this, I too am curious). > > >> Bye, > >> bearophile > > > i encountered this problem when i'm writing a program for packaging > > files. > > the program generates tasks according to description file. > > and tasks are deferent from each other, and should be excuted at the > > last of program. > > > i have experience on Lua and have learned about scheme and haskell, so > > i wrote the wrong code in python. > > > now my solution is, using class taskCreator to create tasks and put > > them into tasklist. > > class taskCreator: > > def __init__(self, proc, input, output): > > self.proc = proc > > self.input = input > > self.output = output > > def call(self): > > return self.proc.call(self.input, self.output) > > 'proc' is generated by procCreators, it's specified. > > > it looks more complex than lambda one. > > > is there any other simple way to implement it? > > Yes, you can have closures in Python (you already had one, the getFunc() > function in your initial post). > > Random remarks: > > You don't need an explicit call() method, you can make instances callable:>>> > class A: > > ... def __init__(self, name): > ... self.name = name > ... def __call__(self): > ... print "calling", self.name > ...>>> a = A("foo") > >>> a() > > calling foo > > If your object has just this one method you can instead use a closure: > > >>> def make_a(name): > > ... def call(): > ... print "calling", name > ... return call > ...>>> a = make_a("bar") > >>> a() > > calling bar > > This can be simplified further with some help from the library: > > >>> from functools import partial > >>> def call(name): > > ... print "calling", name > ...>>> a = partial(call, "baz") > >>> a() > > calling baz > > Here is a complete example: > > import sys > from functools import partial > > def lower(input, output): > output.writelines(line.lower() for line in input) > > def prefix(input, output): > for index_line in enumerate(input): > output.write("%d: %s" % index_line) > > tasks = [partial(lower, open("tmp.py"), sys.stdout), > partial(prefix, open("tmp.py"), sys.stdout)] > > for t in tasks: > t() > > Peter functools.partial is useful to my program. i wrote task = partial(lambda input, output, proc: proc(input, output), archive_input.name, archive_output, proc) self.todo.append(task) instead of those TaskCreators. and wrote def __getExportor(self, name): if not self.exportors.has_key(name): return lambda input, ouput: False return partial(lambda input, output, cmdline: filter( # filter successed exit code to make list not empty, and it means success lambda x: x == 0 or x == 36, # hack, 36 is the success code for kzip, i hope there isn't any program use 36 as it's failed exit code. map(lambda l: os.system(l), self.interpret(cmdline, input, output))), cmdline=self.exportors[name]) instead of ProcCreators. I know it looks more obscure and not in the 'Python Style', it's just for me to understand these discussions :P -- http://mail.python.org/mailman/listinfo/python-list
Re: hello from colombia
On Nov 26, 8:19 pm, "Tim Rowe" <[EMAIL PROTECTED]> wrote: > 2008/11/26 fel <[EMAIL PROTECTED]>: > > > how can I convince them that Python is better > > You can't, because it isn't. you are right, it isn't, but for the particular task at hand (DB Sybase programming) I feel somehow that the team isn't moving fast enough, perhaps the Language is the problem? the team doesn't know much about java, and altough IDEs help, I see litle or no advancement and time is running short. I believe Python is the answer, I saw an app called Bado (look it up), and as I saw the guy that wrote all the stuff make screen casts to show it off, I tought to myself, "the reason he did all of this, is because HE COULD", the language dodn't get in the way, it was simple and consice, just as I remember it) so why not ditch java and give it a try? I think I need a page with 100 reasons why Python is better than Java ( it is, or at least, it MUST be) and if it isn't , we cana lways improve it (in java that's a no go) > > I'd better explain that, before I'm lynched. The thing is, no language > is better than another language. A language is better than another > language *for a particular purpose*. SPARK Ada is better than Python > for safety-critical software (if only because it's easier to get > regulatory approval). INTERCAL is better than Python for > obfustication. Before you try to convert them to Python, you need to > find out all the reasons for the existing language choice and work out > whether Python actually /would/ be better. If you can do that, in the > process you will have gathered the evidence you need. that's a lot of bytes for "do your own homework" but thanks, I'll do it. > If you can't do > that, why are you assuming that Python will be better? > > -- > Tim Rowe -- http://mail.python.org/mailman/listinfo/python-list
Exhaustive Unit Testing
Hi everybody, another question on unit testing, admittedly not necessarily a python- specific one... I have a class method about 60 lines long (*) and due to some 9 non- trivial IFs statements (3 and 2 of which nested) the number of possible paths the program flow can take is uncomfortably large, each path characterized by an uncomfortably long list of careful turns to take. Given that all paths have large portions of them overlapping with each other, is there a strategy that would allow me to collapse the many cases into only a few representative ones? I can sense that exhaustively testing all paths is probably overkill. On the other hand just going through all nodes and edges between the nodes -at least once- is probably not enough. Is there any technique to find the right(ish) middle? Thanks for your help! Manu (*) for the 50/500 purists: it's my only method/function with more than 50 lines so far... and it include comments! -- http://mail.python.org/mailman/listinfo/python-list
Re: what's so difficult about namespace?
Hi Xah, I myself am proponent of namespace-lessness... That was until I discovered CLOS and the multi-methods... For any other language I would pick Apple's approach approach to Objective C, and the frameworks that they've put (libraries) - e.g. use couple of letters to prefix your class/functions - like NSObject, ABAdressBok, UIButton. For these languages, where only single-dispatch is available, there is no need to prefix their methods, as they are always send to one object, and this object itself becomes a "package" - basically it would grok certain "words", "messages", "id-s" whatever you call them. But let's go back to CLOS: Take for example the Lispworks CAPI gui library. To display a component you normally do: (display ...) If you haven't added the CAPI library to the (:use) list then you do: (capi:display ...) But let's say you have another library used in your application, that has the same multi-method "display". For example a PDF library might have such. To call it, you would again do: (display ...) And if you haven't added the PDF library to the use list: (pdf:display ...) In the case where both libraries (:use "CAPI" "PDF") are used, there would most likely be a problem, but at least you can solve it by prefixing it with capi: and pdf:, but this would still keep short-naming in the rest of the modules where that's not needed. The more decoupled the system, the less you would run into such problems, and most of the coupling is in the actual application code (not libraries) where you assemble stuff. And overall it would be better than naming your methods like this: (capi-display) (pdf-display) Yes this would be safe everywhere, and granted such naming works well for functions, classes, global variables, etc - but really for METHODS, being a MESSAGE it makes it unattractive. Other than that, packages (namespaces) in Common-Lisp are also used for special cases: The KEYWORD package, The SETF one, and COMMON-LISP would always be the bible :) Dimiter "malkia" Stanev. Xah Lee wrote: comp.lang.lisp,comp.lang.functional,comp.lang.perl.misc,comp.lang.python,comp.lang.java.programmer 2008-11-25 Recently, Steve Yegge implemented Javascript in Emacs lisp, and compared the 2 languages. http://steve-yegge.blogspot.com/ http://code.google.com/p/ejacs/ One of his point is about emacs lisp's lack of namespace. Btw, there's a question i have about namespace that always puzzled me. In many languages, they don't have namespace and is often a well known sour point for the lang. For example, Scheme has this problem up till R6RS last year. PHP didn't have namespace for the past decade till about this year. Javascript, which i only have working expertise, didn't have namespace as he mentioned in his blog. Elisp doesn't have name space and it is a well known major issue. Of languages that do have namespace that i have at least working expertise: Mathematica, Perl, Python, Java. Knowing these langs sufficiently well, i do not see anything special about namespace. The _essence_ of namespace is that a char is choosen as a separator, and the compiler just use this char to split/connect identifiers. Although i have close to zero knowledge about compiler or parser, but from a math point of view and my own 18 years of programing experience, i cannot fathom what could possibly be difficult of introducing or implementing a namespace mechanism into a language. I do not understand, why so many languages that lacks so much needed namespace for so long? If it is a social problem, i don't imagine they would last so long. It must be some technical issue? Could any compiler expert give some explanation? Thanks. Xah ∑ http://xahlee.org/ ☄ -- http://mail.python.org/mailman/listinfo/python-list
Re: help with class
On Wed, Nov 26, 2008 at 5:21 PM, tekion <[EMAIL PROTECTED]> wrote: > Hi, > so I am assuming global name space refers to the location of where the > module is imported, for example my previous example where I call the > gzip module from test_class class, like so: > > class test_class: > import gzip > > did not work because of scoping. So global name space in this case is > declaring the import outside of test_class like so: > > import gzip > class test_class: > etc.. > > Is my assumption correct? Thanks. Yes. Global == module-level. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: help with class
Hi, so I am assuming global name space refers to the location of where the module is imported, for example my previous example where I call the gzip module from test_class class, like so: class test_class: import gzip did not work because of scoping. So global name space in this case is declaring the import outside of test_class like so: import gzip class test_class: etc.. Is my assumption correct? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: what's so difficult about namespace?
On Nov 26, 6:57 pm, Kaz Kylheku <[EMAIL PROTECTED]> wrote: > The theory is that the adoption of some technology is driven by > a function of the ratio: > > perceived crisis > > perceived pain of adoption > > These perceptions may not be accurate. The crisis may be larger than > perceived, > or the pain of adoption may be smaller than perceived. > > But, you missed the point that I don't necessarily agree or disagree with the > perceptions. They are what they are. > > > Nobody is saying that lacking namespace is a CRISIS. > > I.e. you agree that it's not widely perceived as a crisis. Hence, small > numerator in the above ratio. OT. Don't forget the 'ignorance is bliss' variable. If you don't know your language sucks, it's not as painful to stick with it. -- http://mail.python.org/mailman/listinfo/python-list
Re: hello from colombia
2008/11/26 fel <[EMAIL PROTECTED]>: > how can I convince them that Python is better You can't, because it isn't. I'd better explain that, before I'm lynched. The thing is, no language is better than another language. A language is better than another language *for a particular purpose*. SPARK Ada is better than Python for safety-critical software (if only because it's easier to get regulatory approval). INTERCAL is better than Python for obfustication. Before you try to convert them to Python, you need to find out all the reasons for the existing language choice and work out whether Python actually /would/ be better. If you can do that, in the process you will have gathered the evidence you need. If you can't do that, why are you assuming that Python will be better? -- Tim Rowe -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting in to metaprogramming
On Nov 26, 6:29 pm, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Thu, 27 Nov 2008 06:41:47 +0200, Hendrik van Rooyen wrote: > > I am using the term in the restricted sense of Python writing Python > > source. > > > Given that, can anybody think of an example that you could not do with a > > class? (excepting the "stored procedure" aspect) > > GUI designer. You write a program to let the user create code by clicking > buttons, dragging objects, drawing lines, etc. The GUI designer may use > classes, but the purpose of those classes is to generate source code. I want to disagree with this example. I hold that the proper output of a GUI designer is in XML, or another data format. > Testing code speed... you might have some functions with a loop, and you > want to unroll the loop as an optimization. If you have one function, you > can unroll it yourself. If you have a hundred such functions, you might > want to write a program to do it. (Yes, I'm stretching...) > > Don't like that Python doesn't optimize tail-recursion? Then write a > source-code analyzer that detects tail-recursion and re-writes the > function using a while loop. I've seen a preprocessor come up a few times. The input is a program's source, and the output is source. Of course you can do it with quotes and 'exec' at run-time, but if your whole file is quoted, it may be a better option. (Part of my rationale was I wanted syntax-coloring.) > >> Thinking further back, when I was young and programming in Apple's > >> Hypercard 4GL, I used to frequently use Hypercard scripts to generate > >> new Hypercard scripts. That was to work around the limitations of the > >> scripting language. > > > What sort of stuff did you do, and would having had simple OO available > > have rendered it unnecessary? > > It's been 20-odd years, and the examples were pretty trivial... I don't > really recall exactly, but it would have been something like this: > > * design a GUI involving lots of buttons on screen, each one with quite > similar but not identical code; > > * since Hypercard didn't have a layout manager, write a script to > generate each button, place it where needed, and set the button's code. snip (Above.) I'm not sure if you'd count something like 'perlmodule': import perl # Simple arithmetics six = perl.eval("3+3") # Eval can also return functions sum = perl.eval("sub { my $s = shift; $s += shift while @_; $s }") print sum(1,2,3) http://aspn.activestate.com/ASPN/CodeDoc/pyperl/perlmodule.html but speaking of quoted code and all... -- http://mail.python.org/mailman/listinfo/python-list
Re: is it possible to integrate Python into VBS ?
On Nov 27, 10:15 am, Stef Mientki <[EMAIL PROTECTED]> wrote: > How can I call Python from within VBS ? Hey Stef, The Windows Scripting Host (WSH) allows you to add other scripting languages, such as Python (I _think_ this might even happen automatically with ActivePython.) Script Components are a way of creating COM objects in languages that supported by your WSH installation. It uses an XML-based language to define the interface for the COM object and how it interacts with the original script. There's even a wizard for helping with this process. It's been over 4+ years, but I did manage to successfully expose a Python class using it, which could then be instantiated within VBS using the standard CreateObject() call. This might help you out: http://msdn.microsoft.com/en-au/library/asxw6z3c(VS.85).aspx -- http://mail.python.org/mailman/listinfo/python-list
Re: [2.5.1] ShiftJIS to Unicode?
Gilles Ganault wrote: Hello I'm trying to read pages from Amazon JP, whose web pages are supposed to be encoded in ShiftJIS, and decode contents into Unicode to keep Python happy: www.amazon.co.jp /> But this doesn't work: == m = try.search(the_page) How can you have name "try"? It's a reserved word! if m: #UnicodeEncodeError: 'charmap' codec can't encode characters in position 49-55: character maps to title = m.group(1).decode('shift_jis').strip() == Has someone successfully accessed Shift-JIS-encoded Japanese contents with Python? No problem here: >>> import urllib >>> data = urllib.urlopen("http://www.amazon.co.jp/";).read() >>> decoded_data = data.decode("shift-jis") >>> -- http://mail.python.org/mailman/listinfo/python-list
Re: Python surpasses Perl in popularity?
On Wed, 26 Nov 2008 11:17:21 -0500, Steve Holden wrote: > Xah Lee wrote: ... >> your remark is a bit overzealous. After all, we all know that site is >> websearh based. Although it not some kinda scientific report, but it >> does give some good indication of language popularity, however you >> define that. >> > [... rant omitted ...] > I wondered how long you would be able to resist making your vituperative > remarks. Please stop this rubbish. Oh please Steve. Did you read Xah's post or stop after the second paragraph? It was amazingly *non* vituperative, and I don't just mean "for Xah". I only counted two uses of the f-word and one of the a-word, none of which I personally would object to (we're grown-ups, naughty words shouldn't shock us). The only things which were even *close* to a vituperative rant were a short comment about Brian Harvey being unhappy with Scheme 6, and that Sun Microsystems use inferior versions of shell tools. Maybe half a dozen lines expressing strong opinions, out of a 300 line post. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: what's so difficult about namespace?
On 2008-11-26, Xah Lee <[EMAIL PROTECTED]> wrote: > Can you see, how you latched your personal beef about anti software > crisis philosophy into this no namespace thread? I did no such thing. My post was about explaining the decision process that causes humans to either adopt some technical solution or not. In doing so, I put on the ``hat'' of an Emacs Lisp, Javascript or C programmer. If enough programmers share this type of perception (be it right or wrong), that explains why there is no rush to add namespace support to these languages. The theory is that the adoption of some technology is driven by a function of the ratio: perceived crisis perceived pain of adoption These perceptions may not be accurate. The crisis may be larger than perceived, or the pain of adoption may be smaller than perceived. But, you missed the point that I don't necessarily agree or disagree with the perceptions. They are what they are. > Nobody is saying that lacking namespace is a CRISIS. I.e. you agree that it's not widely perceived as a crisis. Hence, small numerator in the above ratio. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it possible (and wise) to extend the None-type ?
On Wed, 26 Nov 2008 13:24:25 -0800, Jason Scheirer wrote: > On Nov 26, 11:40 am, Terry Reedy <[EMAIL PROTECTED]> wrote: >> def Skipper(object): >> def Skip(): pass >> skipper = Skipper() >> >> def _On_Menu_File_Open ( self, event = skipper ): >> event.Skip () >> >> etc. > > I think this methods works best, but quite frankly, if a method is only > two lines long, then you've likely got a code smell and no amount of > over-design is going to cover for it. That's nuts. Methods should be as short as they need to be. Except in code where performance is *REALLY* a bottleneck, you should be factoring out common code into methods, even if the common code is only one or two lines. Sometimes the entire class is just two lines: class MyModuleError(ValueError): pass It's unusual for something to be that short, simply because you can't do much in just two lines (especially if you are counting the method definition as one of those lines) but something isn't wrong just because it's short. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: what's so difficult about namespace?
On Wed, 26 Nov 2008 17:42:43 +0100, Stefan Behnel wrote: > Xah Lee wrote: >>> The IT community has enough trouble getting a few ISPs to upgrade >>> their DNS software. How are you going to get millions of general users >>> to upgrade? >> >> alright, that's speaks for Javascript. >> >> But how's that apply to, say, Scheme lisp, Emacs lisp, PHP? > > Think before you write. It's exactly the same thing. How would you get > all Emacs users in the world to upgrade? Perhaps you should take your own advice. There have been many new features added to computer languages over the decades, and some of them have been backward incompatible. Python has added new features over the years: nested scopes, decorators, new style classes, etc. Those who don't upgrade can't run programs written for the new version. Those who want to run programs written for the new version will upgrade. Python is going through one such change *right now* with Python 3. Other languages have gone through similar changes in the past, and will continue to do so in the future. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: what's so difficult about namespace?
On Nov 27, 9:28 am, Xah Lee <[EMAIL PROTECTED]> wrote: > Hi Stefan, try not to be a moron. Hi Xah, try not to be an asshole. [and in a separate post] > your post is too much verbiage and enthusiasm. The hypocrisy here would be funny if I didn't think you were serious. -- http://mail.python.org/mailman/listinfo/python-list
Iowa Python Users Group Meeting (Dec. 1, 2008)
Hi, The 3rd meeting of the Iowa Python Users Group (Pyowa) is getting together next Monday, December 1st, 7-9 p.m. Be sure to mark your calendars! We currently have one presentation scheduled and a workshop where we hope to have teams work on easy to intermediate problems in an effort to learn and improve one's Python programming skills. There will probably be time for Lightning Talks (http://en.wikipedia.org/ wiki/Lightning_Talk) as well if you're interested in sharing something. We are meeting at the following location: Marshall County Sheriff's Office 2369 Jessup Ave Marshalltown, IA 50158 This group is open to new and experienced programmers. Come and network with local IT personnel. If you know you can make it, could you please let me know? It's nice to have a general idea of how many will be there (there is plenty of room though). We hope to see you there! Mike Driscoll Pyowa Organizer http://www.pyowa.org -- http://mail.python.org/mailman/listinfo/python-list
Re: [2.5.1] ShiftJIS to Unicode?
Gilles> == Gilles> m = try.search(the_page) Gilles> if m: Gilles> #UnicodeEncodeError: 'charmap' codec can't encode characters in Gilles> position 49-55: character maps to Gilles> title = m.group(1).decode('shift_jis').strip() Gilles> == Gilles> Has someone successfully accessed Shift-JIS-encoded Japanese Gilles> contents with Python? Have you verified that the characters in position 49-55 are actually Shift-JIS characters? In my experience problems decoding a source string in any given character set are because of errors in the source, not errors in Python. OTOH, the characters in position 49-55 look like plain old ASCII to me. Does Shift-JIS have ASCII as a proper subset? -- Skip Montanaro - [EMAIL PROTECTED] - http://smontanaro.dyndns.org/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting in to metaprogramming
On Thu, 27 Nov 2008 06:41:47 +0200, Hendrik van Rooyen wrote: > I am using the term in the restricted sense of Python writing Python > source. > > Given that, can anybody think of an example that you could not do with a > class? (excepting the "stored procedure" aspect) GUI designer. You write a program to let the user create code by clicking buttons, dragging objects, drawing lines, etc. The GUI designer may use classes, but the purpose of those classes is to generate source code. Testing code speed... you might have some functions with a loop, and you want to unroll the loop as an optimization. If you have one function, you can unroll it yourself. If you have a hundred such functions, you might want to write a program to do it. (Yes, I'm stretching...) Don't like that Python doesn't optimize tail-recursion? Then write a source-code analyzer that detects tail-recursion and re-writes the function using a while loop. >> Thinking further back, when I was young and programming in Apple's >> Hypercard 4GL, I used to frequently use Hypercard scripts to generate >> new Hypercard scripts. That was to work around the limitations of the >> scripting language. > > What sort of stuff did you do, and would having had simple OO available > have rendered it unnecessary? It's been 20-odd years, and the examples were pretty trivial... I don't really recall exactly, but it would have been something like this: * design a GUI involving lots of buttons on screen, each one with quite similar but not identical code; * since Hypercard didn't have a layout manager, write a script to generate each button, place it where needed, and set the button's code. Hypercard did have a message passing hierarchy (like inheritance for objects), so often you could take the button's code and place it in a higher level of the hierarchy (the card, the background, the stack), but there were odd cases where that wasn't enough. Another example: Hypercard had a very limited number of GUI elements (text fields and buttons, basically) but I designed a slider control using a few buttons, each button with a custom script. To avoid needing to create and place the buttons by hand each time I wanted a slider, I had a script that did it for me. The script not only created the buttons, but it created the scripts used by the buttons. This wasn't as difficult as it sounds -- it was basically taking a template and doing some text replacements, then telling the button to use it as a script. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: hello from colombia
On Nov 27, 8:25 am, fel <[EMAIL PROTECTED]> wrote: > perhaps a python advocacy page? http://www.google.com/search?q=python advocacy -- http://mail.python.org/mailman/listinfo/python-list
[2.5.1] ShiftJIS to Unicode?
Hello I'm trying to read pages from Amazon JP, whose web pages are supposed to be encoded in ShiftJIS, and decode contents into Unicode to keep Python happy: www.amazon.co.jp But this doesn't work: == m = try.search(the_page) if m: #UnicodeEncodeError: 'charmap' codec can't encode characters in position 49-55: character maps to title = m.group(1).decode('shift_jis').strip() == Has someone successfully accessed Shift-JIS-encoded Japanese contents with Python? Thank you. -- http://mail.python.org/mailman/listinfo/python-list
is it possible to integrate Python into VBS ?
hello, We use a commercial database application (Ultimo), that has embedded VBS (Visual Basic Script) editor / execution. Knowing Python now, VBS seems quit clumsy. We can't replace the build-in scripting completely, because the VBS (which has to have some predefined strctures) is interpreted by the database program, before it's executed. But as far as we know there are no restrictions on the VBS. So it should be possible to do the real work in Python. How can I call Python from within VBS ? I googled, but didn't find any relevant pages (probably used the wrong words). thanks, Stef Mientki -- http://mail.python.org/mailman/listinfo/python-list
Re: Python+Pyjamas+V8=ftw
On Nov 27, 6:20 am, "inhahe" <[EMAIL PROTECTED]> wrote: > Python should [...] The problem with statements like this is that Python itself can't do anything, only members of the Python community can. But I do understand and agree with your main point. I'm hoping that the PyPy project will allow for more rapid experimentation with new JIT & VM techniques, with the more successful making their way into the CPython VM over time. The project isn't quite at the point yet, but they're still heading in that direction: http://morepypy.blogspot.com/2008/10/sprint-discussions-jit-generator.html Another project similar-ish to Pyjamas is HotRuby: http://hotruby.yukoba.jp/ However, it doesn't use the code-to-JS approach, rather it has implemented the Ruby VM (or a subset thereof) in JavaScript and runs Ruby bytecodes directly. Under Chrome, this results in a 16x increase over the Ruby 1.9 VM. It certainly looks like some interesting times are ahead for dynamic languages: http://steve-yegge.blogspot.com/2008/05/dynamic-languages-strike-back.html -- http://mail.python.org/mailman/listinfo/python-list
Re: tkFileDialog, askopenfiles in v2.6 question
fransstil wrote: To select a group of files works fine in 2.5 ... from tkFileDialog import askopenfiles fnames = askopenfiles(title = "Select files", initialdir = "C:\\temp", filetypes=[("All", "*.*")]) for i in range(len(fnames)): fnames[i] = fnames[i].name ... return fnames ... As far as I can see, "tkFileDialog.py" hasn't changed, but it looks like one of the modules it uses is 'broken' in some way. but now 2.6 strange results - IOError: [Errno 2] No such file or directory: u'{' Internally it's expecting a method to return a list and is then iterating through it, but the method is returning a string instead, so it's actually iterating through that... - ERROR '.name' no longer exists in 2.6 - If '.name' removed the return of 'askopenfiles' is no longer a list, it contains braces for some?! of the directories example: {C:/temp/file1.ext} {C:/temp/file2.ext} {C:/temp/file3.ext} This a what is being returned internally and it should be splitting it into a list. - askopenfilenames gives the same results Can someone gave me a hint Thanks in advance A short-term fix is to use askopenfilenames and split the string yourself. It's a space-separated list of paths, each path delimited by braces (and a path might contain a space). -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get a directory file descriptor?
Steve Holden wrote: Anyway, when I try to use O_RDONLY on Vista I get "Permission denied": According to the library ref, fchdir() is Unix-only, so there probably isn't a use case for getting a file descriptor for a directory on Windows in the first place. -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting in to metaprogramming
On Nov 26, 10:41 pm, "Hendrik van Rooyen" <[EMAIL PROTECTED]> wrote: > "Steven D'Aprano" wrote: > > > > > Well, I don't know about "any problem". And it's not so much about > > whether metaprograms can solve problems that can't be solved by anything > > else, as whether metaprograms can solve problems more effectively than > > other techniques. > > > If you include factory functions, class factories, the builder design > > pattern, metaclasses, etc. as "metaprogramming", then I use it all the > > time, and find it an excellent technique to use. > > > But if you mean using a Python program to generate Python source code, > > then I can't think of any time I used it. Which doesn't mean that others > > don't find it helpful, only that I haven't yet. > > I am using the term in the restricted sense of Python writing Python source. > > Given that, can anybody think of an example that you could not do with > a class? (excepting the "stored procedure" aspect) > > Or can I claim a new a new meta - rule - I would call it van Rooyen's folly... The example I think of is the Visitor Pattern of Gamma and all. One class's method calls another's method with its own class's name in the name. class Visitor: def visit_A( self, arg ):... def visit_B( self, arg ):... class A: def visit( self, vis ): vis.visit_A( self ) class B: def visit( self, vis ): vis.visit_B( self ) As you can see, the 'visit' method is mechanical for classes A and B. One might want to autogenerate those in some languages, but Python has introspection: class BaseAB: def visit( self, vis ): getattr( vis, 'visit_%s'% self.__class__.__name__ )( self ) And it's easier to modify the default behavior this way than in autogenerated code too. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python C/API simple debugging
On Nov 26, 5:27 am, k3xji <[EMAIL PROTECTED]> wrote: > Hi all, > > I am new to Python C API and finding it difficult to debug C > extensions. So, basically I want to see the value of an integer value > during the C API. Here is the code: > > #define LAST_MIX_VAL 0xDEADBEEF > > static PyObject * > chash(PyObject *self, PyObject *args) > { > unsigned int key,result; //treat key like an usinged int. > unsigned char a,b,c,d; > > key = result = 0; > if (!PyArg_ParseTuple(args, "i", &key)) > return NULL; > > printf("Key:%i\n",Py_BuildValue("i", key)); > . > . > > So, I just want to see the contents of local variable key. If I call > printf(..) without Py_BuildValue(), the interpreter shuts down, because > (I am assuming) printf is allocating some value in heap that is not in > the interpreter's heap itself which is causing the corruption. > > This way it works, but this time I cannot see correct key content. > > So, questions are: > - What I am doing wrong here? > - What is the preffered approach for these kind simple-debugging > issue? I searched C/API ref but cannot see any help on that? > > Thanks, This works fine for me: static PyObject * methA(PyObject *self, PyObject *args) { int a; PyArg_ParseTuple( args, "i", &a ); printf( "%i\n", a ); Py_INCREF(Py_None); return Py_None; } Did you want capital-I for 'unsigned int'? -- http://mail.python.org/mailman/listinfo/python-list
Re: asp oddness , why specify ASP twice
davidj411 wrote in news:a08906ab-ba98-4ce0-a5f9-330f4b287423 @z27g2000prd.googlegroups.com in comp.lang.python: > > for some reason this code works: > * > <%@ LANGUAGE = Python%> The above is a Directive, in this case it tells ASP what language to use, but other options like the enocding of the script can be specified. There can only be one directive block It must be the first thing in the asp file and it starts with an @ sign. There is manual, http://msdn.microsoft.com/en-us/library/ms524664.aspx Being MSDN I suggest you read it now as by next week microsoft will have moved the content elsewhere (I'd add a smiley here, but it really isn't funny). > <% > Response.Write ("test") > %> Rob. -- http://www.victim-prime.dsl.pipex.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: what's so difficult about namespace?
Dear Kaz Kylheku, your post is too much verbiage and enthusiasm. Why? because you went into the la la land of philosophy. Although, i do think you did give some good exposition on your views. Now, let me detail some analysis of your post. In summary, you are saying a few things about namespaces, for example, you gave some reasons javascript doesn't really need namespaces that much, and in general, your thesis is that although lack of namespace is bad, but overall it's ok, and the pain of adding namespaces is more than the problem it solves. You cite C and linux, and some joe blog's philosophy on the multi-core crisis as support. On the whole, given your post as is, i don't disagree with your general point of view. However, you seem to went onto your own gripe about alarmists, by the magic of vodoo speak and future-predicting formula, wantonly applied it to the namespace “crisis”. And in the process, you seems to brush it off, almost sounding like lacking namespace is a none-problem. Nobody is saying that lacking namespace is a CRISIS. But it is a problem, a problem that is rather seriously, practically, hampering software development, in PHP, in Scheme Lisp, in Emacs Lisp, a widely acknowledged problem by programers in these communities, counting myself. Nobody is saying that linux development is crumbling just because C lacks namespace. Nobody is saying that human animal couldn't land on the moon when people are still using slide rules and punch cards. (note that the issue proper of this thread is about technical issues of introducing namespace into a existing lang. Am not accusing you of derailing, but just pointing out a background fact.) Can you see, how you latched your personal beef about anti software crisis philosophy into this no namespace thread? In your fervor to dispel the software crisis beliefs, you painted a picture that lacking namespace in C, Javascript, Emacs Lisp, Scheme Lisp, PHP, as trivial, unimportant, none problems. Do you actually, seriously, believe, that lacking namespaces in these languages is not a problem? Sure, if a programer got a accident and fell into a manhole and broke his legs, i bet he can still live long and program well. But that doesn't mean being a cricrublempple is cool, right? In your hot haste, you got a few things factually wrong too. • Javascript, although used in browser mainly, but that is not its only use. It has huge potential as a general purpose lang. It is adopted here and there as the scripting lang. Check out Wikipedia on it. It lists about 20 such adoptions by various tech or software app as scripting lang. • You mentioned that adding prefix is a workable solution. Yes, but only to some extent. For example, in elisp, it lacks lexical scoping, lacks closure, and its manual suggest that names shouldn't be more than 32 chars. These, seriously put a dent on the workaroundibilities of the no namespace problem. I do a lot emacs lisp scripting, i already felt the pain. Steve Yegge in his blog, for his work of implementing javascript interpreter in elisp gave detail. Similarly, lacking namespace in PHP is also a major, practical, problem to web app developers. Scheme lisp's lack of namespace is also a major sore point, being one of its major problems that in their view prevented them from going outside of academia. These are not just made-up scenarios. These are widely acknowledged, practicality oriented, problems. Yeah sure, you can always find some workaround, and the world won't crumble by it, just like cripples and dumb and blind can all still lead a happy and fruitful life. There is no crisis! Xah ∑ http://xahlee.org/ ☄ On Nov 26, 1:32 pm, Kaz Kylheku <[EMAIL PROTECTED]> wrote: > On 2008-11-26, Xah Lee <[EMAIL PROTECTED]> wrote: > > > > > comp.lang.lisp,comp.lang.functional,comp.lang.perl.misc,comp.lang.python,co > > mp.lang.java.programmer > > > 2008-11-25 > > > Recently, Steve Yegge implemented Javascript in Emacs lisp, and > > compared the 2 languages. > > >http://steve-yegge.blogspot.com/ > >http://code.google.com/p/ejacs/ > > > One of his point is about emacs lisp's lack of namespace. > > > Btw, there's a question i have about namespace that always puzzled me. > > > In many languages, they don't have namespace and is often a well known > > sour point for the lang. For example, Scheme has this problem up till > > R6RS last year. > > Scheme hasn't officially supported breaking a program into multiple files > until > R6RS. If the language is defined in terms of one translation unit, it doesn't > make sense to have a namespace feature. > > > PHP didn't have namespace for the past decade till > > about this year. Javascript, which i only have working expertise, > > didn't have namespace as he mentioned in his blog. > > Javascript programs are scanned at the character level by the browser as part > of loading a page. So there are severe practical limitations on how large > Javascript programs can be. > > Namespaces are useful only i
Matplotlib on Leopard Mac OS
Hi everyone, I've got some problems trying to install matplotlib on my mac (Leopard OS). I'm following the instructions I found in the official site to install it from the egg file (http:// matplotlib.sourceforge.net/users/installing.html), but when I run easy_install ./matplotlib-0.98.3-py2.5-macosx-10.3.egg, I get this error message: BUILDING MATPLOTLIB matplotlib: 0.98.3 python: 2.5.1 (r251:54863, Apr 15 2008, 22:57:26) [GCC 4.0.1 (Apple Inc. build 5465)] platform: darwin REQUIRED DEPENDENCIES * numpy 1.1 or later is required; you have 1.0.1 error: Setup script exited with 1 In fact I did install numpy 1.2.1, so I can't understand why it doesn't fin it! Any help? Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list
tkFileDialog, askopenfiles in v2.6 question
To select a group of files works fine in 2.5 ... from tkFileDialog import askopenfiles fnames = askopenfiles(title = "Select files", initialdir = "C:\\temp", filetypes=[("All", "*.*")]) for i in range(len(fnames)): fnames[i] = fnames[i].name ... return fnames ... but now 2.6 strange results - IOError: [Errno 2] No such file or directory: u'{' - ERROR '.name' no longer exists in 2.6 - If '.name' removed the return of 'askopenfiles' is no longer a list, it contains braces for some?! of the directories example: {C:/temp/file1.ext} {C:/temp/file2.ext} {C:/temp/file3.ext} - askopenfilenames gives the same results Can someone gave me a hint Thanks in advance Frans Stil --= Posted using GrabIt = --= Binary Usenet downloading made easy =- -= Get GrabIt for free from http://www.shemes.com/ =- -- http://mail.python.org/mailman/listinfo/python-list
Re: hello from colombia
fel: > they are starting a new project (insurance stuff) using Java, and I > just hate that eventually I'l be debugging someone-else's java code > how can I convince them that Python is better, and get them to re- > think their strategy? The choice of the language for a program isn't easy. Maintaining "large" codebases of Java code written by many programmers with mixed levels of experience may be less difficult than an Python code, because Python gives you more freedom, and such freedom may be used for the bad too. Also note that Java gives you powerful IDE tools, may give you support from some corporations, and for the firm it may be simpler to find and replace Java programmers, compared to Python ones (this is probably true where I live, but I don't know if it's true where you live). Java may also have some software already done that you can use in your insurance field, I don't know. Today Java may be the most widely used language, so this diffusion gives you some advantages. So even if Python is better, a firm has to consider many other things. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: hello from colombia
On Nov 26, 5:17 pm, r <[EMAIL PROTECTED]> wrote: > On Nov 26, 2:58 pm, fel <[EMAIL PROTECTED]> wrote: > > > I work in a small software company using php all day, I wish the usage > > of Python was more common within my company > > they are starting a new project (insurance stuff) using Java, and I > > just hate that eventually I'l be debugging someone-else's java code > > how can I convince them that Python is better, and get them to re- > > think their strategy? > > > also, kuddos on the language, you serve mankind as few do. > > > fel. > > Just show them a side by side comparison of Python and Java, the > choice will be obvious! ;) the problem is that they are moving to Java due to it app- marketability (java is more business-enterprisey), while python isn't : ( perhaps a python advocacy page? -- http://mail.python.org/mailman/listinfo/python-list
Re: Python/C API: using from a shared library
On Nov 26, 10:29 pm, Robie Basak <[EMAIL PROTECTED]> wrote: > On 2008-11-25, Robie Basak <[EMAIL PROTECTED]> wrote: > > > If I use dlopen() to open a shared library that I've written, and that > > shared library tries to use the Python/C API, then it fails. I've > > reduced the problem to the test case below. The error is: > > > ImportError: /usr/lib/python2.5/lib-dynload/time.so: undefined symbol: > > PyExc_ValueError > > I've submitted a bug for this. Seehttp://bugs.python.org/issue4434for > an more detailed explanation and a workaround. It isn't a bug in Python. You need to link the Python shared library to your shared library properly. You appear not to be doing this. Graham -- http://mail.python.org/mailman/listinfo/python-list
Re: Apache & mod_python: I don't receive anything with POST method
On Nov 27, 12:21 am, [EMAIL PROTECTED] wrote: > Hi, > > I'm using a simple form to make possible the users of our site upload > files. > > > > > > > > > > > > The "upload.py" looks like this: > > from mod_python import apache, util; > > def index(req): > form = util.FieldStorage(req, keep_blank_values=1) > try: > # form is empty here > # return form --> I get "{}" > ufile = form.get('upfile', None) > > if not form.has_key('upfile'): > return ":( No 'upfile' key" > > # some checks. I never get beyond here > > ufile = form['upfile'] > if ufile.file: > return ufile.file.name > else: > return ":( It's not a file" > except Exception, e: > return 'Fail: ' + str(e) > > I'm getting an empty 'form'. No 'upfile' key at all. I've tried to add > some other text fields but the result is the same: empty. If I use GET > method with text fields, it works properly. > > Currently I'm using: > Apache 2.2.9 (initially I used Apache 2.2.3 too) > mod_python 3.3.1 (initially I used mod_python 3.2.10 too) > Python 2.5.2 Which is the correct result for the code you are using. The problem is that you appear to be using mod_python.publisher which does its own form handling before you are even getting a chance, thus it is consuming the request content. For how to handle forms in mod_python.publisher see: http://webpython.codepoint.net/mod_python_publisher_forms Graham -- http://mail.python.org/mailman/listinfo/python-list
Re: hello from colombia
On Nov 26, 2:58 pm, fel <[EMAIL PROTECTED]> wrote: > I work in a small software company using php all day, I wish the usage > of Python was more common within my company > they are starting a new project (insurance stuff) using Java, and I > just hate that eventually I'l be debugging someone-else's java code > how can I convince them that Python is better, and get them to re- > think their strategy? > > also, kuddos on the language, you serve mankind as few do. > > fel. Just show them a side by side comparison of Python and Java, the choice will be obvious! ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: what's so difficult about namespace?
Kaz Kylheku wrote : Javascript programs are scanned at the character level by the browser as part of loading a page. So there are severe practical limitations on how large Javascript programs can be. Namespaces are useful only in very large programs. But even more useful where you are getting libraries from several sources. Without a generally acknowledged name space scheme different developers will tend to walk all over each others variable/function names. Especially as Javascript has global variables. -- Wojtek :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: help with class
On Nov 26, 4:08 pm, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > tekion <[EMAIL PROTECTED]> writes: > > Hello, > > I am playing with class. Below is the code snippet: > > #!/usr/bin/python > > 2 > > 3 class test_class: > > 4 #import gzip > > 5 def __init__(self,file): > > 6 self.file = file > > 7 def open_file(self): > > 8 try: > > 9 print "file: %s" % self.file > > 10 self.xml_file = gzip.GzipFile(self.file,'r') > > 11 except: > > 12 print "an exception has occured" > > 13 for line in self.xml_file: > > 14 print "line: %s" % line > > 15 self.xml_file.close() > > 16 > > 17 > > 18 if __name__ == '__main__': > > 19 import gzip > > 20 import sys > > 21 t = test_class( sys.argv[1] ) > > 22 t.open_file() > > > My question are: > > 1. Why do I need to use "import gzip" on main section to get it the > > script to work? I would assume you need the import of gzip in the > > class section. > > This is how Python works. Here is the relevant extract from the > Reference Manual: > > A scope defines the visibility of a name within a block. If a local > variable is defined in a block, its scope includes that block. If > the definition occurs in a function block, the scope extends to any > blocks contained within the defining one, unless a contained block > introduces a different binding for the name. The scope of names > defined in a class block is limited to the class block; it does not > extend to the code blocks of methods – this includes generator > expressions since they are implemented using a function scope. > > (Quoted fromhttp://docs.python.org/reference/executionmodel.html) > > > 2. What is the proper way of using module in a class you are creating? > > import it into the global namespace of the module in which you are > defining your class. > > -- > Arnaud That's funny...this same question was asked at 11:30 this morning see thread: http://groups.google.com/group/comp.lang.python/browse_thread/thread/a42bf1e9504c3c3f?hl=en# -- http://mail.python.org/mailman/listinfo/python-list
Re: help with class
tekion <[EMAIL PROTECTED]> writes: > Hello, > I am playing with class. Below is the code snippet: > #!/usr/bin/python > 2 > 3 class test_class: > 4#import gzip > 5def __init__(self,file): > 6 self.file = file > 7def open_file(self): > 8 try: > 9 print "file: %s" % self.file > 10 self.xml_file = gzip.GzipFile(self.file,'r') > 11 except: > 12 print "an exception has occured" > 13 for line in self.xml_file: > 14 print "line: %s" % line > 15 self.xml_file.close() > 16 > 17 > 18 if __name__ == '__main__': > 19import gzip > 20import sys > 21t = test_class( sys.argv[1] ) > 22t.open_file() > > My question are: > 1. Why do I need to use "import gzip" on main section to get it the > script to work? I would assume you need the import of gzip in the > class section. This is how Python works. Here is the relevant extract from the Reference Manual: A scope defines the visibility of a name within a block. If a local variable is defined in a block, its scope includes that block. If the definition occurs in a function block, the scope extends to any blocks contained within the defining one, unless a contained block introduces a different binding for the name. The scope of names defined in a class block is limited to the class block; it does not extend to the code blocks of methods – this includes generator expressions since they are implemented using a function scope. (Quoted from http://docs.python.org/reference/executionmodel.html) > 2. What is the proper way of using module in a class you are creating? import it into the global namespace of the module in which you are defining your class. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter and asyncronous socket
On 26 Nov, 13:42, Steve Holden <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > Hi all, I'm new to python and I've been spending the last week on GUI > > that refresh its content based on data periodically coming from a > > remote socket. > > I succeded in doing it (thanks newsgroups and online manual!) using > > theTkinter.after method to implement a busy wait on the socket (which > > I had previously set to non blocking) > > I should be happy with it, but on windows (application must be multi- > > platform) the busy wait leads to a 100% CPU usage. I'm trying to > > implement it the other way round: a "socket process" that updates a > > label (or a queue object) in the GUI. I can't figure out how to do > > this. Anyone can post hints? With some details, maybe? > > Processes are probably a bit heavyweight for this purpose: they create > difficulties in communication (unless you use the new multiprocessing > library in 2.6). > > One approach would be to run the socket code in blocking mode in a > separate thread started by the (main program) GUI thread at program > startup, and communicating results back via a Queue.Queue or similar to > the GUI thread. That thread wakes itself up once every (say) 500 mS to > check for updates from the socket side. > > You should see your CPU utilization go down then. The threading.thread > library is actually much easier to use than you would think, though it's > possible to get things wrong by assuming data sharing will work in ways > it actually doesn't. But if you have the main thread pass a Queue to the > networking thread, that should be a reliable means of communication. > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > Holden Web LLC http://www.holdenweb.com/ Thankk you Steve, I have now a GUI and a threaded socket client receiving data on its socket. I pass to it a queue object from the GUI, but when it tries to push a value on the queue, the GUI does not see any value. My last work with OOP is as far in time as the beginning of Java, I'm surely missing something simple but very important. Anyway, the goal to have a responsive GUI and a functional socket has been achieved, thanks again. If you have hints on the queue problem, your help is welcome. Bye Max -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it possible (and wise) to extend the None-type ?
On 2008-11-26 18:55, Stef Mientki wrote: > hello, > > I've the idea that I always have a lot of useless code in my programs, > like the next example. > > def _On_Menu_File_Open ( self, event = None ): >if event : > event.Skip () > > instead of > > def _On_Menu_File_Open ( self, event = None ): > event.Skip () > > So I would like to extend the None-type (if that's possible), > with a dummy Skip() method. > > Is it wise to do ? > If not what are the disadvantages ? This doesn't work. None is a Python singleton that cannot be subclassed. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Nov 26 2008) >>> Python/Zope Consulting and Support ...http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/ 2008-11-12: Released mxODBC.Connect 0.9.3 http://python.egenix.com/ Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 -- http://mail.python.org/mailman/listinfo/python-list
Re: what's so difficult about namespace?
On Wed, 26 Nov 2008 21:32:24 +, Kaz Kylheku wrote: > See: > http://arcfn.com/2008/07/why-your-favorite-programming-language-is- unpopular.html That was 404 for me, but http://arcfn.com/2008/07/why-your-favorite-language-is-unpopular.html works. Interesting, thanks for mentioning it. Tamas -- http://mail.python.org/mailman/listinfo/python-list
Re: Python surpasses Perl in popularity?
Xah Lee <[EMAIL PROTECTED]> writes: > Bourne Shell, is pretty much replaced by Bash since several years ago. > For example, as far as i know, linuxes today don't have Bourne Shell > anymore. “sh” is just a alias to bash with some compatibility > parameter. That used to be the case, but these days 'sh' is as often an alias to a lighter shell program, a free reimplementation of sh that includes a much smaller superset of the original sh functionality than that of bash. For example, on default Ubuntu installations, sh is a symlink to dash, "a lightweight POSIX-compliant shell derived from ash." -- http://mail.python.org/mailman/listinfo/python-list
help with class
Hello, I am playing with class. Below is the code snippet: #!/usr/bin/python 2 3 class test_class: 4#import gzip 5def __init__(self,file): 6 self.file = file 7def open_file(self): 8 try: 9 print "file: %s" % self.file 10 self.xml_file = gzip.GzipFile(self.file,'r') 11 except: 12 print "an exception has occured" 13 for line in self.xml_file: 14 print "line: %s" % line 15 self.xml_file.close() 16 17 18 if __name__ == '__main__': 19import gzip 20import sys 21t = test_class( sys.argv[1] ) 22t.open_file() My question are: 1. Why do I need to use "import gzip" on main section to get it the script to work? I would assume you need the import of gzip in the class section. 2. What is the proper way of using module in a class you are creating? -- http://mail.python.org/mailman/listinfo/python-list
Re: what's so difficult about namespace?
Kaz Kylheku wrote: On 2008-11-26, Xah Lee <[EMAIL PROTECTED]> wrote: comp.lang.lisp,comp.lang.functional,comp.lang.perl.misc,comp.lang.python,comp.lang.java.programmer 2008-11-25 Recently, Steve Yegge implemented Javascript in Emacs lisp, and compared the 2 languages. http://steve-yegge.blogspot.com/ http://code.google.com/p/ejacs/ One of his point is about emacs lisp's lack of namespace. Btw, there's a question i have about namespace that always puzzled me. In many languages, they don't have namespace and is often a well known sour point for the lang. For example, Scheme has this problem up till R6RS last year. Scheme hasn't officially supported breaking a program into multiple files until R6RS. If the language is defined in terms of one translation unit, it doesn't make sense to have a namespace feature. PHP didn't have namespace for the past decade till about this year. Javascript, which i only have working expertise, didn't have namespace as he mentioned in his blog. Javascript programs are scanned at the character level by the browser as part of loading a page. So there are severe practical limitations on how large Javascript programs can be. Namespaces are useful only in very large programs. Elisp doesn't have name space and it is a well known major issue. C doesn't have namespaces, and yet you have projects like the Linux kernel which get by without this. Given that the Linux kernel can do without namespaces, it's easy to see how Javascript and Elisp can survive without it. Of languages that do have namespace that i have at least working expertise: Mathematica, Perl, Python, Java. Knowing these langs sufficiently well, i do not see anything special about namespace. The _essence_ of namespace is that a char is choosen as a separator, and the compiler just use this char to split/connect identifiers. The essence of a true namespace or package system or whatever is that you can establish situations in which you use the unqualified names. You can emulate namespaces by adding prefixes to identifiers, which is how people get by in C. In C, you can even get the functionality of short names using the preprocessor. I have done this before (but only once). In a widely-used public header file, I prefixed all of the names of struct members (because struct members are not immune to clashes: they clash with preprocessor symbols!) struct foo { int foo_category; time_t foo_timestamp; /* ... */ } Inside the implementation module, I made macros for myself: #define category foo_category #define timestamp foo_timestamp In this way, I didn't have to edit any of the code in order to move the struct members into the namespace. Expressions like ``pf->category'' continued to work as before. Although i have close to zero knowledge about compiler or parser, but from a math point of view and my own 18 years of programing experience, i cannot fathom what could possibly be difficult of introducing or implementing a namespace mechanism into a language. The same things that make it difficult to add anything to a language, namely the stupid way in which languages are designed to get in the way of extension. What would it take to add namespaces to C, for instance? If you have any proposal for a new C feature, the ISO C people encourage you to develop a proof-of-concept, which means: hack it into an existing implementation to demonstrate that it's feasible. If you need new syntax, hacking it into an implementation means hacking it into the parser. Everyone who wants to experiment with your feature needs to get your compiler patches (for GCC for instance) and rebuild the compiler. The process is painful enough that it's only worth doing if it solves something that is perceived as being a critical issue. do not understand, why so many languages that lacks so much needed namespace for so long? If it is a social problem, i don't imagine they would last so long. It must be some technical issue? I recently read about a very useful theory which explains why technologies succeed or fail. See: http://arcfn.com/2008/07/why-your-favorite-programming-language-is-unpopular.html [snip] The correct URL is http://arcfn.com/2008/07/why-your-favorite-language-is-unpopular.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it possible (and wise) to extend the None-type ?
Jason Scheirer wrote: On Nov 26, 11:40 am, Terry Reedy <[EMAIL PROTECTED]> wrote: Stef Mientki wrote: hello, I've the idea that I always have a lot of useless code in my programs, like the next example. def _On_Menu_File_Open ( self, event = None ): if event : event.Skip () instead of def _O So I would like to extend the None-type (if that's possible), with a dummy Skip() method. def Skipper(object): def Skip(): pass skipper = Skipper() def _On_Menu_File_Open ( self, event = skipper ): event.Skip () etc. I think this methods works best, but quite frankly, if a method is only two lines long, then you've likely got a code smell and no amount of over-design is going to cover for it. Sorry I should have said that I only showed the relevant (to this issue) part, and this kind of if statements occurs quit a lot. Probably I should not say this here on this list, but to give you the whole truth, I often forget the if-statement ( because it has really nothing to do with the functionality I intend to write), and then my program crashes (unexpected) :-( cheers, Stef -- http://mail.python.org/mailman/listinfo/python-list
Re: what's so difficult about namespace?
On 2008-11-26, Xah Lee <[EMAIL PROTECTED]> wrote: > comp.lang.lisp,comp.lang.functional,comp.lang.perl.misc,comp.lang.python,comp.lang.java.programmer > > 2008-11-25 > > Recently, Steve Yegge implemented Javascript in Emacs lisp, and > compared the 2 languages. > > http://steve-yegge.blogspot.com/ > http://code.google.com/p/ejacs/ > > One of his point is about emacs lisp's lack of namespace. > > Btw, there's a question i have about namespace that always puzzled me. > > In many languages, they don't have namespace and is often a well known > sour point for the lang. For example, Scheme has this problem up till > R6RS last year. Scheme hasn't officially supported breaking a program into multiple files until R6RS. If the language is defined in terms of one translation unit, it doesn't make sense to have a namespace feature. > PHP didn't have namespace for the past decade till > about this year. Javascript, which i only have working expertise, > didn't have namespace as he mentioned in his blog. Javascript programs are scanned at the character level by the browser as part of loading a page. So there are severe practical limitations on how large Javascript programs can be. Namespaces are useful only in very large programs. > Elisp doesn't have > name space and it is a well known major issue. C doesn't have namespaces, and yet you have projects like the Linux kernel which get by without this. Given that the Linux kernel can do without namespaces, it's easy to see how Javascript and Elisp can survive without it. > Of languages that do have namespace that i have at least working > expertise: Mathematica, Perl, Python, Java. Knowing these langs > sufficiently well, i do not see anything special about namespace. The > _essence_ of namespace is that a char is choosen as a separator, and > the compiler just use this char to split/connect identifiers. The essence of a true namespace or package system or whatever is that you can establish situations in which you use the unqualified names. You can emulate namespaces by adding prefixes to identifiers, which is how people get by in C. In C, you can even get the functionality of short names using the preprocessor. I have done this before (but only once). In a widely-used public header file, I prefixed all of the names of struct members (because struct members are not immune to clashes: they clash with preprocessor symbols!) struct foo { int foo_category; time_t foo_timestamp; /* ... */ } Inside the implementation module, I made macros for myself: #define category foo_category #define timestamp foo_timestamp In this way, I didn't have to edit any of the code in order to move the struct members into the namespace. Expressions like ``pf->category'' continued to work as before. > Although i have close to zero knowledge about compiler or parser, but > from a math point of view and my own 18 years of programing > experience, i cannot fathom what could possibly be difficult of > introducing or implementing a namespace mechanism into a language. The same things that make it difficult to add anything to a language, namely the stupid way in which languages are designed to get in the way of extension. What would it take to add namespaces to C, for instance? If you have any proposal for a new C feature, the ISO C people encourage you to develop a proof-of-concept, which means: hack it into an existing implementation to demonstrate that it's feasible. If you need new syntax, hacking it into an implementation means hacking it into the parser. Everyone who wants to experiment with your feature needs to get your compiler patches (for GCC for instance) and rebuild the compiler. The process is painful enough that it's only worth doing if it solves something that is perceived as being a critical issue. > do not understand, why so many languages that lacks so much needed > namespace for so long? If it is a social problem, i don't imagine they > would last so long. It must be some technical issue? I recently read about a very useful theory which explains why technologies succeed or fail. See: http://arcfn.com/2008/07/why-your-favorite-programming-language-is-unpopular.html The perceived crisis which namespaces solve is not sigificant enough relative to the pain of adoption. No, wrong, let's restate that. Programmers do use namespaces even when there is no language feature. It's not about adoption of namespaces, but adoption of proper support for namespaces. Not using namespaces is a crisis in a software project, but (at least in the perception held by many programmers) that crisis is adequately mitigated by using a naming convention. Proper namespaces only address the small remaining vestiges of the original crisis. Thus: the perceived crisis which is solved by properly incorporating namespaces into a programming language (rather than living with a prefix-based emulation) is not significant enough relative to the perceived pain of adopting pr
Re: Is it possible (and wise) to extend the None-type ?
Alternative (if you *really* want to save the explicit test) is to attach the behaviour modification to the *relevant* class: class NonEvent(Event): def do_nothing(self): pass skip = jump = hop = waltz = saunter = do_nothing def __len__(self): return 0 NON_EVENT = NonEvent() del NonEvent # later: def amethod(self, event=NON_EVENT): if event: # still works thanks to __len__ above event.skip() # now can avoid test, if desired event.skip() thanks guys, the Null, Dummy, Skipper, Nonevent class works great HTH ... BTW, ever heard of PEP 8? I guess Python is missing some kind of CSS ;-) cheers, Stef -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it possible (and wise) to extend the None-type ?
On Nov 26, 11:40 am, Terry Reedy <[EMAIL PROTECTED]> wrote: > Stef Mientki wrote: > > hello, > > > I've the idea that I always have a lot of useless code in my programs, > > like the next example. > > > def _On_Menu_File_Open ( self, event = None ): > > if event : > > event.Skip () > > > instead of > > > def _O > > > So I would like to extend the None-type (if that's possible), > > with a dummy Skip() method. > > def Skipper(object): > def Skip(): pass > skipper = Skipper() > > def _On_Menu_File_Open ( self, event = skipper ): > event.Skip () > > etc. I think this methods works best, but quite frankly, if a method is only two lines long, then you've likely got a code smell and no amount of over-design is going to cover for it. -- http://mail.python.org/mailman/listinfo/python-list
asp oddness , why specify ASP twice
for some reason this code works: * <%@ LANGUAGE = Python%> <% Response.Write ("test") %> * but this code does NOT: * <%@ LANGUAGE = Python Response.Write ("test") %> * the difference between the two is that i remove "%>" from the first line and removed "<%" from the next line. it would seem that this should put all the code into one "ASP block" but for some reason it does not run. any ideas? thanks -- http://mail.python.org/mailman/listinfo/python-list
hello from colombia
I work in a small software company using php all day, I wish the usage of Python was more common within my company they are starting a new project (insurance stuff) using Java, and I just hate that eventually I'l be debugging someone-else's java code how can I convince them that Python is better, and get them to re- think their strategy? also, kuddos on the language, you serve mankind as few do. fel. -- http://mail.python.org/mailman/listinfo/python-list
asp versus cgi
when i use cgi, i never get a 500 error but i can see how it might take on overhead if many users are hitting the site at once. so to avoid this, i looked into registering the python engine for ASP requests. when i use asp (C:\WINDOWS\system32\inetsrv\asp.dll fileversion info:"--a-- W32i DLL ENU 5.1.2600.5512 shp369,664 04-14-2008 asp.dll") , i get intermittent results. it either works or generates a 500 error. the error pattern is 200, 500, 200, 500, 200, 500 and so on. this is the ASP code when using GET method: <%@ LANGUAGE = Python%> <% import sys sys.stdout=sys.stdin usr = Request.QueryString("usr") Response.Write ("usr") %> ** this is the ASP code when using the POST method <%@ LANGUAGE = Python%> <% import sys sys.stdout=sys.stdin usr = Request.Form ("usr") Response.Write (str(usr)) %> ** POST by the way seems to have a 100 kb limit so why ever use it unless you need to keep the data out of the URL?) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python equivalent of Common Lisp Macros?
On Nov 26, 2:30 pm, "Chris Rebert" <[EMAIL PROTECTED]> wrote: > On Wed, Nov 26, 2008 at 11:13 AM, dpapathanasiou > > <[EMAIL PROTECTED]> wrote: > > I'm using the feedparser library to extract data from rss feed items. > > > After I wrote this function, which returns a list of item titles, I > > noticed that most item attributes would be retrieved the same way, > > i.e., the function would look exactly the same, except for the single > > data.append line inside the for loop. > > > In CL, I could simply write a macro, then replace the data.append line > > depending on which attribute I wanted. > > > Is there anything similar in Python? > > Yes, use higher-order functions. See below. > > > > > Here's the function: > > > def item_titles (feed_url): > > Replace previous line with: > def item_titles(feed_url, attr_getter):>"""Return a list of the item > titles found in this feed url""" > >data = [] > >feed = feedparser.parse(feed_url) > >if feed: > >if len(feed.version) > 0: > >for e in feed.entries: > >data.append(e.title.encode('utf-8')) > > Replace previous line with: > data.append(attr_getter(e)) > > >return data > > Example usage: > > def title_getter(entry): > return entry.title.encode('utf-8') > > titles = item_titles("some feed url here", title_getter) Thanks; this is exactly what I was looking for. -- http://mail.python.org/mailman/listinfo/python-list
Python+Pyjamas+V8=ftw
I don't know how much the community knows about this - i haven't been participating much of late - but here's something amazing. Apparently javascript is just as dynamic as python, because someone made a python-to-javascript converter in just 1200 line (pyjamas). Meanwhile google's new javascript engine (v8) blew all the others out the water, raising the bar - and now safari and firefox already have already risen to that bar with their own jit js engines. The exciting thing is that python code converted to javascript runs on v8 10 times faster (http://www.advogato.org/article/985.html). Thus google's strategy in making the JIT compiler represents what Python could (and should) be. Python should either adapt v8, Tamarin (http://en.wikipedia.org/wiki/Tamarin_(JavaScript_engine), or similar to make its own JIT, or take their basic principles (http://www.youtube.com/watch?v=lZnaaUoHPhs) and recreate them for its own JIT from scratch. Until then, we can always install v8/tamarin/tracemonkey/squirrelfish and easily make a front-end that automatically uses pyjamas to convert python script to JS and runs it. Perhaps pyjamas needs some improvement to fully implement Python - the homepage isn't very clear on how exactly the JS implementation mirrors the Python implementation. Also I suppose it doesn't support Python 3.0 and would have to be changed to support that. -- http://mail.python.org/mailman/listinfo/python-list
Re: what's so difficult about namespace?
On Nov 26, 9:15 am, Xah Lee <[EMAIL PROTECTED]> wrote: > On Nov 26, 5:45 am, Joshua Cranmer <[EMAIL PROTECTED]> wrote: > > > > i cannot fathom what could possibly be difficult of > > > introducing or implementing a namespace mechanism into a language. > > > Namespaces go to the very core of a language, name resolution. > > Retroactively adding such a feature is extremely difficult because there > > is a strong chance of accidentally breaking existing code. > > could you give some technical detail on this? > > i don't know compiler so am probably being foolish here... but i > suppose ultimately name resolution and storage at heart is something > like a hashtable... namely, > > put ‹identifier 1› table > put ‹identifier 2› table > > and lookup is just > > retrieve ‹identifier› table > > and now suppose we introduced namespace, so i imagine the compiler > simply just concat namespace component befor put, and split before > retrieve? > > Xah > ∑http://xahlee.org/ > > ☄ I'm sorry for the earlier post. I read your question too quickly. I've implemented a few research compilers; none in production. You're totally right in the case where the language has general nested lexical scoping. Namespaces just add an "outermost" scope. If you've done a good engineering job, the compiler change is trivial. In fact I added namespaces like this to an assembler that had lexical scoping. It took about an hour including writing a test suite. If you already have a bunch of compilers for a language like pre- namespace C or Javascript or Basic that doesn't allow for lexical scoping, then the addition is likely to be non-trivial because the implementation compiler language is often C and C programmers will tend to declare a single, global symbol table. So adding a separate outer scope involves hunting down all the global references and replacing them with references to the current namespace table. We can tut tut about this being bad design, but there you have it... -- http://mail.python.org/mailman/listinfo/python-list
Re: Python equivalent of Common Lisp Macros?
dpapathanasiou <[EMAIL PROTECTED]> writes: > I'm using the feedparser library to extract data from rss feed items. > > After I wrote this function, which returns a list of item titles, I > noticed that most item attributes would be retrieved the same way, > i.e., the function would look exactly the same, except for the single > data.append line inside the for loop. > > In CL, I could simply write a macro, then replace the data.append line > depending on which attribute I wanted. > > Is there anything similar in Python? > > Here's the function: > > def item_titles (feed_url): > """Return a list of the item titles found in this feed url""" > data = [] > feed = feedparser.parse(feed_url) > if feed: > if len(feed.version) > 0: > for e in feed.entries: > data.append(e.title.encode('utf-8')) > return data No macros -- need the whole "code as data" paradigm which doesn't exist in python. The pythonic way to create the sort of abstraction you're looking for would be to use the *attr functions and either a map of attribute identities or inspect the attributes from the objects. Some UNTESTED code... def extract_entry(e, attrs=['title', 'datetime', 'article']): out = [] for attr in attrs: assert hasattr(e, attr) out.append(getattr(e, attr)) return out Using the inspect module would give an even more generic function, but with more complex code of course. Then your code would look more like: def items(feed_url): feed = feedparser.feed(feed_url) if feed and len(feed) > 0: return [extract_entry(entry) for entry in feed.entries] Of course, I'm making liberal assumptions about what you're looking for in your ouput here... but it's just an example, not a full solution. YMMV. Hope it helps. :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it possible (and wise) to extend the None-type ?
Stef Mientki wrote: hello, I've the idea that I always have a lot of useless code in my programs, like the next example. def _On_Menu_File_Open ( self, event = None ): if event : event.Skip () instead of def _O So I would like to extend the None-type (if that's possible), with a dummy Skip() method. def Skipper(object): def Skip(): pass skipper = Skipper() def _On_Menu_File_Open ( self, event = skipper ): event.Skip () etc. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python equivalent of Common Lisp Macros?
dpapathanasiou <[EMAIL PROTECTED]> writes: > I'm using the feedparser library to extract data from rss feed items. > > After I wrote this function, which returns a list of item titles, I > noticed that most item attributes would be retrieved the same way, > i.e., the function would look exactly the same, except for the single > data.append line inside the for loop. > > In CL, I could simply write a macro, then replace the data.append line > depending on which attribute I wanted. > > Is there anything similar in Python? > > Here's the function: > > def item_titles (feed_url): > """Return a list of the item titles found in this feed url""" > data = [] > feed = feedparser.parse(feed_url) > if feed: > if len(feed.version) > 0: > for e in feed.entries: > data.append(e.title.encode('utf-8')) > return data Something like this? def item_attrs (feed_url, attr): """Return a list of the item titles found in this feed url""" data = [] feed = feedparser.parse(feed_url) if feed: if len(feed.version) > 0: for e in feed.entries: data.append(getattr(e, attr).encode('utf-8')) return data You're not making it clear how the data.append... line changes so it's hard to know exactly. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting in to metaprogramming
Hendrik van Rooyen wrote: I am using the term in the restricted sense of Python writing Python source. Given that, can anybody think of an example that you could not do with a class? (excepting the "stored procedure" aspect) I am not sure I understand your question. def iterize(recursive_function_text): return equivalent_iterative_function_text where input and output are both Python code. If one were to implement this by compiling the input to AST form and then walking the tree, the AST node classes would be involved, but I would scarely say the translation was done by the classes, as opposed to functions which might or might not be attacked to a class as methods. tjr -- http://mail.python.org/mailman/listinfo/python-list
Re: Python equivalent of Common Lisp Macros?
dpapathanasiou schrieb: I'm using the feedparser library to extract data from rss feed items. After I wrote this function, which returns a list of item titles, I noticed that most item attributes would be retrieved the same way, i.e., the function would look exactly the same, except for the single data.append line inside the for loop. In CL, I could simply write a macro, then replace the data.append line depending on which attribute I wanted. Is there anything similar in Python? Here's the function: def item_titles (feed_url): """Return a list of the item titles found in this feed url""" data = [] feed = feedparser.parse(feed_url) if feed: if len(feed.version) > 0: for e in feed.entries: data.append(e.title.encode('utf-8')) return data No, there are no macros. Yet it has - amongst other options, such as callbacks - decorators, that would allow you to write your code like this: def items (feed_url): feed = feedparser.parse(feed_url) if feed: if len(feed.version) > 0: for e in feed.entries: yield e titles = [] other_things = [] for item in items(url): titles.append(item.title.encode('utf-8')) other_things.append(item.other_thing) Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Python equivalent of Common Lisp Macros?
On Wed, Nov 26, 2008 at 11:13 AM, dpapathanasiou <[EMAIL PROTECTED]> wrote: > I'm using the feedparser library to extract data from rss feed items. > > After I wrote this function, which returns a list of item titles, I > noticed that most item attributes would be retrieved the same way, > i.e., the function would look exactly the same, except for the single > data.append line inside the for loop. > > In CL, I could simply write a macro, then replace the data.append line > depending on which attribute I wanted. > > Is there anything similar in Python? Yes, use higher-order functions. See below. > > Here's the function: > > def item_titles (feed_url): Replace previous line with: def item_titles(feed_url, attr_getter): >"""Return a list of the item titles found in this feed url""" >data = [] >feed = feedparser.parse(feed_url) >if feed: >if len(feed.version) > 0: >for e in feed.entries: >data.append(e.title.encode('utf-8')) Replace previous line with: data.append(attr_getter(e)) >return data Example usage: def title_getter(entry): return entry.title.encode('utf-8') titles = item_titles("some feed url here", title_getter) As I'm not familiar with feedparser, you might want to move where the .encode() takes place, but you get the idea. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Instance attributes vs method arguments
In article <[EMAIL PROTECTED]>, M.-A. Lemburg <[EMAIL PROTECTED]> wrote: > >It is always good practice to provide default values for instance >variables in the class definition, both to enhance readability and to >allow adding documentation regarding the variables, e.g. Actually, my company uses an occasional pattern of detecting whether an attribute has ever been set with hasattr(). I am not particularly fond of that mechanism because it has been the occasional source of subtle bugs, but I also see the utility. -- Aahz ([EMAIL PROTECTED]) <*> http://www.pythoncraft.com/ "It is easier to optimize correct code than to correct optimized code." --Bill Harlan -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie question
On Wed, Nov 26, 2008 at 11:11 AM, Nan <[EMAIL PROTECTED]> wrote: > Hello, > I just started to use Python. I wrote the following code and > expected 'main' would be called. > > def main(): > print "hello" > > main > > But I was wrong. I have to use 'main()' to invoke main. The python > interpreter does not give any warnings for the above code. Is there > any way/tool to easily detect this kind of errors ? Python has first-class functions, so you can pass a function to another function (so the line `main` has a meaning, just not a useful one). Also, Python doesn't do compile-time typechecking, so it has no way of knowing that `main` is a function and not a plain variable until runtime. Thus, the parentheses are required for a function call even when there are no arguments. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com > > Thanks ! > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie question
On Wed, 2008-11-26 at 11:11 -0800, Nan wrote: > Hello, >I just started to use Python. I wrote the following code and > expected 'main' would be called. > > def main(): > print "hello" > > main > > But I was wrong. I have to use 'main()' to invoke main. The python > interpreter does not give any warnings for the above code. Is there > any way/tool to easily detect this kind of errors ? > Syntactically your code is correct, so the interpreter just goes about its business. You can usually use tools such as pylint or pychecker to find find such issues. For example, pylint reports (among other things): W: 4: Statement seems to have no effect -- http://mail.python.org/mailman/listinfo/python-list
Python equivalent of Common Lisp Macros?
I'm using the feedparser library to extract data from rss feed items. After I wrote this function, which returns a list of item titles, I noticed that most item attributes would be retrieved the same way, i.e., the function would look exactly the same, except for the single data.append line inside the for loop. In CL, I could simply write a macro, then replace the data.append line depending on which attribute I wanted. Is there anything similar in Python? Here's the function: def item_titles (feed_url): """Return a list of the item titles found in this feed url""" data = [] feed = feedparser.parse(feed_url) if feed: if len(feed.version) > 0: for e in feed.entries: data.append(e.title.encode('utf-8')) return data -- http://mail.python.org/mailman/listinfo/python-list
newbie question
Hello, I just started to use Python. I wrote the following code and expected 'main' would be called. def main(): print "hello" main But I was wrong. I have to use 'main()' to invoke main. The python interpreter does not give any warnings for the above code. Is there any way/tool to easily detect this kind of errors ? Thanks ! -- http://mail.python.org/mailman/listinfo/python-list
Re: best IDE
On Nov 26, 11:59 am, asit <[EMAIL PROTECTED]> wrote: > Which one is the best IDE for python You'll probably also want to take a look at the Python wiki: http://wiki.python.org/moin/PythonEditors Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it possible (and wise) to extend the None-type ?
On Nov 27, 4:55 am, Stef Mientki <[EMAIL PROTECTED]> wrote: > hello, > > I've the idea that I always have a lot of useless code in my programs, > like the next example. > > def _On_Menu_File_Open ( self, event = None ): > if event : > event.Skip () > > instead of > > def _On_Menu_File_Open ( self, event = None ): > event.Skip () > > So I would like to extend the None-type (if that's possible), > with a dummy Skip() method. > > Is it wise to do ? No. > If not what are the disadvantages ? Assume that as well as your Event class, you also have a Foo class with a dothis method and a Bar class with a dothat1 and a dothat2 method: you would need to extend the None-type (if that's possible) to have dummy skip, dothis, dothat1 and dothat2 methods. Each time you invent a new class, you need to consider adding one or more new dummy methods to your extended None-type. Alternative (if you *really* want to save the explicit test) is to attach the behaviour modification to the *relevant* class: class NonEvent(Event): def do_nothing(self): pass skip = jump = hop = waltz = saunter = do_nothing def __len__(self): return 0 NON_EVENT = NonEvent() del NonEvent # later: def amethod(self, event=NON_EVENT): if event: # still works thanks to __len__ above event.skip() # now can avoid test, if desired event.skip() HTH ... BTW, ever heard of PEP 8? Cheers, John -- http://mail.python.org/mailman/listinfo/python-list
Re: Reg Expression - Get position of >
On Wed, 26 Nov 2008 01:48:59 -0800 (PST), M_H <[EMAIL PROTECTED]> wrote: > On Nov 25, 11:06 pm, r <[EMAIL PROTECTED]> wrote: >> On Nov 25, 4:33 pm, Jorgen Grahn <[EMAIL PROTECTED]> wrote: ... >> > Depends on if you have an irrational fear of REs or not ... I agree >> > that REs are overused for things which are better done with split, but >> > in this case I think an RE would be clearer. >> >> > >>> re.sub('.*>', '', 'dkjk>djdd') ... > I want to have the end-position of the mimetype tag (position as > mystr.find('>') returns, so I can use the number for a loop) > However, I can't use just the '>' because the character > could also > be in the string of mimetype (I know, actually not in mimetype, but > let's assume it). > So that is why the filter shall be bulletproof and check for '">' - > with possible spaces between both characters. OK. I am too tired to think it through, but if you need to handle nesting brackets or escaped brackets (e.g. ignore brackets inside double-quoted strings) then an RE is not the best solution. /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting in to metaprogramming
On 27 Nov., 05:41, "Hendrik van Rooyen" <[EMAIL PROTECTED]> wrote: > Given that, can anybody think of an example that you could not do with > a class? (excepting the "stored procedure" aspect) I just noticed that corepy 1.0 [1] has been released. Corepy is an embedded DSL for synthesizing machine code from chaining Python commands. This means it provides objects and exploits control structures used to create machine code that can finally be executed interactively. Let's say you have an ordinary Python function that computes a CRC 32. Now you could attempt to translate the function into other Python code that expresses a corepy routine. You could create a decorator that works as follows 1) reads the source of the decorated function 2) transforms the source into corepy source and compiles it or 3) if 2) fails it just returns the passed code object. Kay [1] http://www.corepy.org/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it possible (and wise) to extend the None-type ?
On Wed, Nov 26, 2008 at 9:55 AM, Stef Mientki <[EMAIL PROTECTED]> wrote: > hello, > > I've the idea that I always have a lot of useless code in my programs, > like the next example. > > def _On_Menu_File_Open ( self, event = None ): > if event : >event.Skip () > > instead of > > def _On_Menu_File_Open ( self, event = None ): > event.Skip () > > So I would like to extend the None-type (if that's possible), It's not. You can't graft new methods onto NoneType (a.k.a. type(None)), and you can't subclass NoneType either. You might be interested in the recipe for a "Null" type: http://code.activestate.com/recipes/68205/ Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com > with a dummy Skip() method. > > Is it wise to do ? > If not what are the disadvantages ? > > thanks, > Stef Mientki > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: best IDE
On Nov 26, 11:09 pm, "Chris Rebert" <[EMAIL PROTECTED]> wrote: > On Wed, Nov 26, 2008 at 9:59 AM, asit <[EMAIL PROTECTED]> wrote: > > Which one is the best IDE for python > > This was recently discussed. To avoid needlessly rehashing said > discussion, see the thread > athttp://groups.google.com/group/comp.lang.python/browse_thread/thread/... > > Cheers, > Chris > -- > Follow the path of the Iguana...http://rebertia.com > > > -- > >http://mail.python.org/mailman/listinfo/python-list Thanx -- http://mail.python.org/mailman/listinfo/python-list
Re: best IDE
On Wed, Nov 26, 2008 at 9:59 AM, asit <[EMAIL PROTECTED]> wrote: > Which one is the best IDE for python This was recently discussed. To avoid needlessly rehashing said discussion, see the thread at http://groups.google.com/group/comp.lang.python/browse_thread/thread/7fd136aef1c63e47/fbaff90068f0fe02 Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
best IDE
Which one is the best IDE for python -- http://mail.python.org/mailman/listinfo/python-list
Is it possible (and wise) to extend the None-type ?
hello, I've the idea that I always have a lot of useless code in my programs, like the next example. def _On_Menu_File_Open ( self, event = None ): if event : event.Skip () instead of def _On_Menu_File_Open ( self, event = None ): event.Skip () So I would like to extend the None-type (if that's possible), with a dummy Skip() method. Is it wise to do ? If not what are the disadvantages ? thanks, Stef Mientki -- http://mail.python.org/mailman/listinfo/python-list
Re: import in a class
On Wed, Nov 26, 2008 at 9:30 AM, TP <[EMAIL PROTECTED]> wrote: > Hi everybody, > > Here is a file "test_import_scope.py": > ## > class a(): > import re > def __init__( self ): > if re.search( "to", "toto" ): > self.se = "ok!" > def print_se( self ): > print self.se > a().print_se() > ## > > When python executes this file, we obtain an error: > > $ python test_import_scope.py > [...] > NameError: global name 're' is not defined > > Why? Because Python doesn't look in class-scope when doing name resolution. It checks the local [function] namespace, then any nested [function] scopes (not applicable in this case), then the module/global namespace, and finally the builtins namespace. The class' namespace never comes into the equation. Consider this simpler example (remember that `import` assigns a module to its name in the importing scope): >>> class Foo(object): ... A=1 ... def foo(self): print A ... >>> Foo().foo() Traceback (most recent call last): File "", line 1, in File "", line 3, in foo NameError: global name 'A' is not defined So in foo(), `A` can be accessed by Foo.A or self.A, but not just plain `A`. I agree it's not entirely intuitive, but remember that Python != Java. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com > > When the re module is imported in the __init__ function or out of the class > (at the top of the file), it works obviously perfectly. > > Thanks in advance, > > Julien > > -- > python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.9&1+,\'Z > (55l4('])" > > "When a distinguished but elderly scientist states that something is > possible, he is almost certainly right. When he states that something is > impossible, he is very probably wrong." (first law of AC Clarke) > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
import in a class
Hi everybody, Here is a file "test_import_scope.py": ## class a(): import re def __init__( self ): if re.search( "to", "toto" ): self.se = "ok!" def print_se( self ): print self.se a().print_se() ## When python executes this file, we obtain an error: $ python test_import_scope.py [...] NameError: global name 're' is not defined Why? When the re module is imported in the __init__ function or out of the class (at the top of the file), it works obviously perfectly. Thanks in advance, Julien -- python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.9&1+,\'Z (55l4('])" "When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong." (first law of AC Clarke) -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting in to metaprogramming
"Steven D'Aprano" wrote: > > Well, I don't know about "any problem". And it's not so much about > whether metaprograms can solve problems that can't be solved by anything > else, as whether metaprograms can solve problems more effectively than > other techniques. > > If you include factory functions, class factories, the builder design > pattern, metaclasses, etc. as "metaprogramming", then I use it all the > time, and find it an excellent technique to use. > > But if you mean using a Python program to generate Python source code, > then I can't think of any time I used it. Which doesn't mean that others > don't find it helpful, only that I haven't yet. I am using the term in the restricted sense of Python writing Python source. Given that, can anybody think of an example that you could not do with a class? (excepting the "stored procedure" aspect) Or can I claim a new a new meta - rule - I would call it van Rooyen's folly... > > Thinking further back, when I was young and programming in Apple's > Hypercard 4GL, I used to frequently use Hypercard scripts to generate new > Hypercard scripts. That was to work around the limitations of the > scripting language. What sort of stuff did you do, and would having had simple OO available have rendered it unnecessary? > > I don't think metaprogramming in the limited sense (programs to output > source code) is a bad idea, but I do think that there are probably better > alternatives in a language like Python. > > True. No argument here - I was just wondering if the relationship holds. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: what's so difficult about namespace?
"Steve Holden" <[EMAIL PROTECTED]> wrote: > And before anyone bothers to point it out, yes, I know PHO now (finally) > has namespaces. I cannot resist oulling the oiss... Its not the first time... :-) - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: what's so difficult about namespace?
Xah Lee wrote: > i cannot fathom what could possibly be difficult of > introducing or implementing a namespace mechanism into a language. Joshua Cranmer wrote: >> Namespaces go to the very core of a language, name resolution. >> Retroactively adding such a feature is extremely difficult because there >> is a strong chance of accidentally breaking existing code. Xah Lee wrote: > > could you give some technical detail on this? > > > i don't know compiler so am probably being foolish here... but i > > suppose ultimately name resolution and storage at heart is something > > like a hashtable... namely, > > > put ‹identifier 1› table > > put ‹identifier 2› table > > > and lookup is just > > > retrieve ‹identifier› table > > > and now suppose we introduced namespace, so i imagine the compiler > > simply just concat namespace component befor put, and split before > > retrieve? Steve Holden wrote: > And therein lies the danger of imagination. > Typically the namespace components are looked up one by one, so for > >this.that.theother > > first "this" will be looked up and (hopefully) yield an object with a > namespace, which will then be searched for "that", yielding another > object with a namespace in which "theother" can be looked up. That's > certainly how it works in Python: yes, but Steve, what is your point? The question is, what is the technical difficulty, if any, of introducing namespace into a existing language. You pointed out that identifier lookup at least from the perspective of language user is somewhat like a tree walking processing. However, that does not answer the main question. Xah ∑ http://xahlee.org/ ☄ -- http://mail.python.org/mailman/listinfo/python-list
Re: what's so difficult about namespace?
On Nov 26, 8:42 am, Stefan Behnel <[EMAIL PROTECTED]> wrote: > XahLeewrote: > >> The IT community has enough trouble getting a few ISPs to upgrade their > >> DNS software. How are you going to get millions of general users to > >> upgrade? > > > alright, that's speaks for Javascript. > > > But how's that apply to, say, Scheme lisp, Emacs lisp, PHP? > > Think before you write. It's exactly the same thing. How would you get all > Emacs users in the world to upgrade? Hi Stefan, try not to be a moron. In the case of javascript, it involves web servers and clients (web browsers). In the case of Scheme Lisp or Emacs Lisp, there's no such server/client issue. There is still the compatibilty issue, but not the same scenario as javascript. As compatibility issue, that doesn't just apply to namespaces but to any othe function or change in the language. And as you know, language changes all the time, in big or small dosages. Small changes happens almost every release. Major changes happens every few years (e.g. Java versions thru the year, Perl4 to perl5, each iteration of Scheme's RnRS) So, in general, backward compatibility does not fully answer the question of the no namespace problem. Even if it does, the detail or reason is not given in the above and is not something obvious at least to me. Xah ∑ http://xahlee.org/ ☄ -- http://mail.python.org/mailman/listinfo/python-list
Re: what's so difficult about namespace?
On Nov 26, 11:42 am, Stefan Behnel <[EMAIL PROTECTED]> wrote: > Xah Lee wrote: > >> The IT community has enough trouble getting a few ISPs to upgrade their > >> DNS software. How are you going to get millions of general users to > >> upgrade? > > > alright, that's speaks for Javascript. > > > But how's that apply to, say, Scheme lisp, Emacs lisp, PHP? > > Think before you write. It's exactly the same thing. How would you get all > Emacs users in the world to upgrade? The same way you would get all Python users to upgrade to 3.0 ? It's not like Joe User runs emacs to edit his grocery store list. George -- http://mail.python.org/mailman/listinfo/python-list
Re: what's so difficult about namespace?
Xah Lee wrote: >> The IT community has enough trouble getting a few ISPs to upgrade their >> DNS software. How are you going to get millions of general users to >> upgrade? > > alright, that's speaks for Javascript. > > But how's that apply to, say, Scheme lisp, Emacs lisp, PHP? Think before you write. It's exactly the same thing. How would you get all Emacs users in the world to upgrade? Stefan -- http://mail.python.org/mailman/listinfo/python-list