Re: pickle alternative
I think you should implement it as a C extension and/or write a PEP. This has been an unfilled need in Python for a while (SF RFE 467384). I've submitted a proto PEP to python-dev. It coming up against many of the same objections to the RFE. Sw. -- http://mail.python.org/mailman/listinfo/python-list
Re: pickle alternative
[EMAIL PROTECTED] writes: I think you should implement it as a C extension and/or write a PEP. This has been an unfilled need in Python for a while (SF RFE 467384). I've submitted a proto PEP to python-dev. It coming up against many of the same objections to the RFE. See also bug# 471893 where jhylton suggests a PEP. Something really ought to be done about this. -- http://mail.python.org/mailman/listinfo/python-list
Re: Help implementing an idea
[EMAIL PROTECTED] wrote: Well, I'm a total python n00b, but I was playing around with exception handling yesterday, and was stricken by how incredibly easy it is to use the op system to create nice scripts... I did the following: import sys lines = sys.stdin.readlines() lines.sort() for stuff in lines: print stuff , Or sys.stdout.writelines( lines ). just to copy stuff from one file to another, and was quite impressed with the results. Now, I was thinking today, I'd really like to create a program that can go to a specific directory and upload all the files in the directory to a specific url for backup purposes, and I have the feeling that the python implementation would be ruthlessly small and efficient, like the aboveanyone who could point me in the right direction as to how to actually do it? How do you want to do the upload? FTP? That's easy. Check ftplib.py. -- - Tim Roberts, [EMAIL PROTECTED] Providenza Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Embedding Python - How to create a class instance
Hello All, I'm trying to embed Python in a C application. What I didn't find is how to create an instance once I have a class object. I'd like to do the equivalent of: from a import A obj = A() obj.foo(10) The following code omits error checking for clarity. --- a.py --- class A: def foo(self, x): print A got %d % x --- a.py --- --- a.c --- int main() { PyObject *module, *A, *dict, *a, *args; PyObject *obj; Py_Initialize(); PyRun_SimpleString(import sys; sys.path.append('.')); module = PyImport_ImportModule(a); dict = PyModule_GetDict(module); A = PyDict_GetItemString(dict, A); /* FIXME: Create obj as instance of A (a = A()) */ obj = ??? foo = PyObject_GetAttrString(obj, foo); args = Py_BuildValue((O, i), obj, 49); PyObject_CallObject(foo, args); Py_Finalize(); return 0; } --- a.c --- Thanks. -- Miki Tebeka [EMAIL PROTECTED] http://tebeka.bizhat.com The only difference between children and adults is the price of the toys pgpqE1lixwEsS.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: pickle alternative
See also bug# 471893 where jhylton suggests a PEP. Something really ought to be done about this. I know this, you know this... I don't understand why the suggestion is meeting so much resistance. This is something I needed for a real world system which moves lots of data around to untrusted clients. Surely other people have had similar needs? Pickle and xmlrpclib simply are not up to the task, but, perhaps Joe Programmer is content to use a pickle, and not care for the security issues. Owell. I'm not sure what I can say to make the case any clearer... Sw. -- http://mail.python.org/mailman/listinfo/python-list
Re: What platforms have Python Virtual Machines and what version(s) ofPython do they support?
Casey Hawthorne [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] What platforms have Python Virtual Machines and what version(s) of Python do they support? In particular: Palm OS PocketPC Try using Google (Python PocketPC, for instance) or the equivalent TJR -- http://mail.python.org/mailman/listinfo/python-list
Re: What platforms have Python Virtual Machines and what version(s) ofPython do they support?
http://dmoz.org/Computers/Programming/Languages/Python/Ports/ -- http://mail.python.org/mailman/listinfo/python-list
Re: regarding popen function
Peter Hansen wrote: Michael, tai64nlocal is a program that converts a special packed timestamp to human-readable form. Thanks Peter. I was asking somewhat rhetorically but I have a love of UNIX arcana and now I know. :) -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is there no instancemethod builtin?
John Roth wrote: you need _both_ isinstance and the types module to do a correct check for any string type: isinstance(fubar, types.StringTypes). That's because both string and unicode are subtypes of one base. But basestring, their base class is a built-in. -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
Re: Help implementing an idea
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/299271 or the nice recipe, page 403 of cookbook2, that i can't find in ASPN -- http://mail.python.org/mailman/listinfo/python-list
Re: Help implementing an idea
[EMAIL PROTECTED] wrote: [snip..] results. Now, I was thinking today, I'd really like to create a program that can go to a specific directory and upload all the files in the directory to a specific url for backup purposes, and I have the feeling that the python implementation would be ruthlessly small and efficient, like the aboveanyone who could point me in the right direction as to how to actually do it? Upload to a URL *sounds* like you want to do the upload by http rather than ftp. In this case you can do it with a Python CGI on the server and a script on the client that communicates with the CGI. When voidspace is back up you can find a pair of scripts that do just that : http://www.voidspace.org.uk/python/cgi.shtml#upload Hint - filelist = [os.path.join(directory, entry) for entry in os.listdir(directory)] Regards, Fuzzy http://www.voidspace.org.uk/python -- http://mail.python.org/mailman/listinfo/python-list
Re: oddness in super()
Martin Blume [EMAIL PROTECTED] writes: A great analysis, but what's a pogo stick and where can I get one? http://search.ebay.com/pogo-stick -- Bjrn Lindstrm [EMAIL PROTECTED] Student of computational linguistics, Uppsala University, Sweden -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there something similar to ?: operator (C/C++) in Python?
[EMAIL PROTECTED], Bo Peng [EMAIL PROTECTED] wrote: I have around 10 of them. Using these if/else, it will take 50 lines for a function call. It also bothers me to have 10 variables left in the namespace, in addition to finding 10 meaningful names. If you've got 10 different conditional branches in a single function, that's pretty messy logic no matter what language you write it in or what syntactic sugar you've got to let you write it compactly. Can you give us some idea of what it is that you're trying to do? It pretty unusual to see a requirement like that. The FAQ provides two solutions, neither of them are elegant. I guess I will use if/else for reasability purpose. I agree that the and/or hack is ugly, and I generally stay away from it because I think if/else is easier to read and understand. But if you've got 10 of them, the compactness (and, as you say, avoiding having to create 10 temp variables) of the and/or probably means the hack is worth doing. Somthing like: myComplicatedFunction (cond1 and value1a or value1b, cond2 and value2a or value2b, cond3 and value3a or value3b, cond4 and value4a or value4b, cond5 and value5a or value5b, cond6 and value6a or value6b, cond7 and value7a or value7b, cond8 and value8a or value8b, cond9 and value9a or value9b, cond10 and value10a or value10b) is kind of ugly, but at least you only have to understand what's going on with the and/or ONCE, and then you can apply that understanding to the 10 repetitions of the construct. Having 50 lines of if/else makes it much harder to get your head around what's going on. -- http://mail.python.org/mailman/listinfo/python-list
Re: oddness in super()
Bjrn Lindstrm schrieb A great analysis, but what's a pogo stick and where can I get one? http://search.ebay.com/pogo-stick Yes, that explains the bouncing with the pogo stick; I would have poked around with a stick. ROTFL, thank you. Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: What platforms have Python Virtual Machines and what version(s) ofPython do they support?
Hmmm... the page is a *bit* out of date (which is to be expected I suppose). There is a port of Python 2.3 for Pocket PC. I think pippy is pretty dead and wasn't that useable. On this newsgroup not long ago someone announced they were working on a new PalmOS port. To the best of my knowledge jython is languishing at Python 2.1. The PSF has funded a push to implement new style classes which will allow it to be brought up to date. I don't know the answer to the other jython questions thougj. Best Regards, Fuzzy http://www.voidspace.org.uk/python -- http://mail.python.org/mailman/listinfo/python-list
Re: pickle alternative
If anyone is interested, I've implemented a faster and more space efficient gherkin with a few bug fixes. http://developer.berlios.de/project/showfiles.php?group_id=2847 -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there something similar to ?: operator (C/C++) in Python?
If your test variable has specific values to branch on, the standard way is to have those values be keys in a dictionary, and do: branched_func_obj = dict_of_values.get(testvar) And the lambda hack is here, courtesy of Peter Norvig http://www.norvig.com/python-iaq.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is there no instancemethod builtin?
In this case I have used hasattr(obj, __iter__) instead of isinstance(obj, list) (strings are iterable but do not have __iter__ method). I think hasattr is much better since it works for tuples and custom iterables too. Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Re: Migrating from Windows to OS X
On 2005-06-18, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: How are the development tools for the Mac? I'll use IDLE if it's available, but I like Scintilla better. Idle is /System/Library/Frameworks/Python.framework/Versions/2.3/bin/idle First thing you want to do is install readline to make the interactive interpreter useable: http://pythonmac.org/packages/ Other things to try: Aquamacs with python-mode http://www.aquamacs.org http://sourceforge.net/projects/python-mode/ http://www.emacswiki.org/cgi-bin/wiki/CustomizeAquamacs (instructions) I prefer a less aggressively aquafied emacs like: http://www.emacswiki.org/cgi-bin/emacs-en/CarbonEmacsPackage but someone who has never used emacs before might not care. Eclipse + pydev: http://www.eclipse.org http://pydev.sourceforge.net/ SPE or Eric3: http://www.wordtech-software.com/python.html Dave Cook -- http://mail.python.org/mailman/listinfo/python-list
Re: pysqlite - Checking the existance of a table
On 2005-06-17, rh0dium [EMAIL PROTECTED] wrote: I am starting to play with pysqlite, and would like to know if there is a function to determine if a table exists or not. sqlite_master has already been mentioned, so I'll point out some useful pragmas (under Pragmas to query the database schema): http://sqlite.org/pragma.html Dave Cook -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there something similar to ?: operator (C/C++) in Python?
Roy Smith wrote: Can you give us some idea of what it is that you're trying to do? It pretty unusual to see a requirement like that. def func(type_of_obj1, type_of_obj2, .): callfunc( [ type_of_obj1 and obj1a() or obj1b(), type_of_obj2 and obj2a() or obj2b(), ]) callfunc can take arbitrary number of objects whose types are determined by type_of_obj1 etc. I was using a bunch of if/else to create objects and pass them to callfunc. Since type_of_obj1 etc are usually binary and obj1a() etc will never be false, the and/or solution does not look so bad in this case. Thanks. Bo -- http://mail.python.org/mailman/listinfo/python-list
Re: extreme newbie
On 2005-06-18, cpunerd4 [EMAIL PROTECTED] wrote: thanks all for the advice. The reason I was thinking about using java (or C or something) was that it is a little more secure than distributing the source code isn't it? sigh 14 and he already wants to horde his source code. Dave Cook -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there something similar to ?: operator (C/C++) in Python?
In article [EMAIL PROTECTED], Bo Peng [EMAIL PROTECTED] wrote: Roy Smith wrote: Can you give us some idea of what it is that you're trying to do? It pretty unusual to see a requirement like that. def func(type_of_obj1, type_of_obj2, .): callfunc( [ type_of_obj1 and obj1a() or obj1b(), type_of_obj2 and obj2a() or obj2b(), ]) I'm still not sure what the big picture is, but I suspect if you're switching on object types, you're doing something wrong, or at least unpythonic. -- http://mail.python.org/mailman/listinfo/python-list
Re: Shortcut to initialize variables
Kent Johnson wrote: letters = {} for letter in ascii_lowercase: letters[letter] = 0 Or more simply: letters = dict.fromkeys(ascii_lowercase, 0) -- http://mail.python.org/mailman/listinfo/python-list
Re: extreme newbie
On 2005-06-18, cpunerd4 [EMAIL PROTECTED] wrote: I see your point, although I don't think there is much a 14 year old can do to sue someone. . . I'm sure my code won't be that valuable untill I'm older though. Thanks It's valuable as something to show prospective employers or clients: I wrote and maintained blahblah.sourceforge.net and foobar.sourceforge.net. Dave Cook -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there something similar to ?: operator (C/C++) in Python?
Bo Peng wrote: Roy Smith wrote: Can you give us some idea of what it is that you're trying to do? It pretty unusual to see a requirement like that. def func(type_of_obj1, type_of_obj2, .): callfunc( [ type_of_obj1 and obj1a() or obj1b(), type_of_obj2 and obj2a() or obj2b(), ]) callfunc can take arbitrary number of objects whose types are determined by type_of_obj1 etc. Unless the obj_i_a and obj_i_b are totally unrelated (very unlikely), I think this might/should be refactored so that the decision between each obj_i_a and obj_i_b is done in a separate obj_i_factory callable. If you provide an example or two of specific triples (type_of_obj_i, obj_i_a, obj_i_b), we'll have a better idea of whether factories are an overkill in this case or not. George -- http://mail.python.org/mailman/listinfo/python-list
Re: extreme newbie
Dave Cook wrote: On 2005-06-18, cpunerd4 [EMAIL PROTECTED] wrote: thanks all for the advice. The reason I was thinking about using java (or C or something) was that it is a little more secure than distributing the source code isn't it? sigh 14 and he already wants to horde his source code. Be gentle. Most of us have been there (those fortunate enough to have been in a position to write source code at 14), and it felt like a sensible viewpoint at the time. I suspect that the attitude will be less and less common in the future, as the open source movement continues to prove successful. -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is there no instancemethod builtin?
Michele Simionato wrote: In this case I have used hasattr(obj, __iter__) instead of isinstance(obj, list) (strings are iterable but do not have __iter__ method). I think hasattr is much better since it works for tuples and custom iterables too. The fact that strings don't have __iter__ is an implementation detail (I can't think of any reason other than historic and perhaps backwards compatibility for this; iterables should IMHO by definition be exactly the objects with __iter__). Also, what if tuples and any other iterables except for lists are considered atomic ? An implementation of s-expressions would use a single data structure for the nesting (e.g. a builtin list or a custom linked list) and objects of all other types should be considered atoms, even if they happen to be iterable. George -- http://mail.python.org/mailman/listinfo/python-list
Re: New WYSIWYG Python IDE in the works
McBooCzech [EMAIL PROTECTED] wrote: sorry for bothering you with my comment. From my point of view, the situation on the IDE (GUI??) development field for Python is really strange. Just try to imagine the same situation around the Python. Plenty of different approaches, versions, philosophies etc. Why people they really know the ways how to develop really good, prime and functional SW (I mean different developers of IDEs) do not do it together as a team (like in Python)? Why are there so many programming languages and people do not just concentrate on improving Fortran and Lisp? Why are there so many text editors and people do not just concentrate on improving vi and emacs? Different people have different needs and different ideas on how things should be done, so sometimes so want to have different software. Florian -- begin signature_virus Hi! I'm a signature virus. Please copy me to your signature to help me spread. end -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is there no instancemethod builtin?
I think strings do not have __iter__ on purpose, exactly to distinguish them from other iterables, since sometimes it is nice to consider them atomic, but I am not sure of this. You should ask the developers. Anyway, the right definition of iterable is (as I was told) an object X such that iter(X) does not throw an exception. Objects following the __getitem__ protocol - such as strings -are iterables even if they do not have an __iter__ method. Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is there no instancemethod builtin?
Michele Simionato wrote: I think strings do not have __iter__ on purpose, exactly to distinguish them from other iterables, since sometimes it is nice to consider them atomic, but I am not sure of this. You should ask the developers. Anyway, the right definition of iterable is (as I was told) an object X such that iter(X) does not throw an exception. Hmm.. not a very insightful definition unless someone knows the implementation of iter(). Objects following the __getitem__ protocol - such as strings - are iterables even if they do not have an __iter__ method. It would be more uniform if the default 'type' metaclass added an __iter__ method to classes that define __getitem__ but not __iter__ with something like: from itertools import count def __iter__(self): for i in count(): try: yield self[i] except IndexError: raise StopIteration George -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there something similar to ?: operator (C/C++) in Python?
Bo Peng wrote: Roy Smith wrote: Can you give us some idea of what it is that you're trying to do? It pretty unusual to see a requirement like that. def func(type_of_obj1, type_of_obj2, .): callfunc( [ type_of_obj1 and obj1a() or obj1b(), type_of_obj2 and obj2a() or obj2b(), ]) callfunc can take arbitrary number of objects whose types are determined by type_of_obj1 etc. I was using a bunch of if/else to create objects and pass them to callfunc. Since type_of_obj1 etc are usually binary and obj1a() etc will never be false, the and/or solution does not look so bad in this case. Thanks. Bo Are you matching the order to the obj_type? objlist = [ (type_obj1, obj1a, obj2b), (typ_obj2, obj2a, obj2b), etc...] objs = [type_of_obj1, type_of_obj2, etc...] for n in range(len(objs)): if objs[n] == objlist[n][0]: objlist[n][1]() else: objlist[n][2]() What significance does the order have? You might be able to use a dictionary of tuples. call_obj = {(type_obj1,0):obj1a, (type_obj1,0):obj1b, (type_boj2,1):obj2a, (type_obj2,1):obj2b, etc... } call_obj[(type_of_obj,order)]() Regards, Ron -- http://mail.python.org/mailman/listinfo/python-list
tab 2 into tab 4 ?
Hello, I have python code which use tab=2. Recently I would like to change it into tab=4. Anyone has suggestion to convert easily and safely ? pujo -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is there no instancemethod builtin?
George Sakkis [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Michele Simionato wrote: I think strings do not have __iter__ on purpose, exactly to distinguish them from other iterables, since sometimes it is nice to consider them atomic, but I am not sure of this. You should ask the developers. Anyway, the right definition of iterable is (as I was told) an object X such that iter(X) does not throw an exception. Hmm.. not a very insightful definition unless someone knows the implementation of iter(). Objects following the __getitem__ protocol - such as strings - are iterables even if they do not have an __iter__ method. It would be more uniform if the default 'type' metaclass added an __iter__ method to classes that define __getitem__ but not __iter__ with something like: from itertools import count def __iter__(self): for i in count(): try: yield self[i] except IndexError: raise StopIteration Unfortunately it doesn't work: getitem can be defined for a class that acts like a dictionary: that is, the items are not integers, let alone integers that extend in a strict sequence from 0. John Roth George -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is there no instancemethod builtin?
John Roth wrote: Unfortunately it doesn't work: getitem can be defined for a class that acts like a dictionary: that is, the items are not integers, let alone integers that extend in a strict sequence from 0. This is true, but that's the current behaviour of iterators for classes that define __getitem__ without __iter__: class AnIterable(object): def __init__(self, it): self._it = it def __getitem__(self,i): return self._it[i] x = AnIterable(dict(a=1,b=2)) list(x) KeyError: 0 George -- http://mail.python.org/mailman/listinfo/python-list
Re: tab 2 into tab 4 ?
[EMAIL PROTECTED] schrieb im Newsbeitrag news:[EMAIL PROTECTED] | Hello, | | I have python code which use tab=2. Recently I would like to change it | into tab=4. | | Anyone has suggestion to convert easily and safely ? Look at reindent.py in Tools\Scripts. -- Vincent Wehren | | pujo | -- http://mail.python.org/mailman/listinfo/python-list
Re: What platforms have Python Virtual Machines and what version(s) ofPython do they support?
Fuzzyman wrote: To the best of my knowledge jython is languishing at Python 2.1. The PSF has funded a push to implement new style classes which will allow it to be brought up to date. It's really not languishing any more. There is a lot of activity spearheaded by Brian Zimmer (who received the PSF grant) with help from several volunteers. They are planning an alpha release soon. I think the current released Jython will run on Java 1.1 but the new one will require Java 1.2. Kent -- http://mail.python.org/mailman/listinfo/python-list
Re: pickle alternative
[EMAIL PROTECTED] writes: See also bug# 471893 where jhylton suggests a PEP. Something really ought to be done about this. I know this, you know this... I don't understand why the suggestion is meeting so much resistance. This is something I needed for a real world system which moves lots of data around to untrusted clients. Surely other people have had similar needs? Pickle and xmlrpclib simply are not up to the task, but, perhaps Joe Programmer is content to use a pickle, and not care for the security issues. I don't think there's serious objection to a PEP, but I don't read python-dev. Maybe there was objection to some specific technical point in your PEP. Why don't you post it here? -- http://mail.python.org/mailman/listinfo/python-list
calling subclass constructor question
Hello everyone and thank you for being such a good community. Anyway, I was wondering...I have an super class which is the superclass for 5 other classes. However, I want to be able to call the subclass constructors from the super class. Is this possible? Thank you in advance -- http://mail.python.org/mailman/listinfo/python-list
Re: tab 2 into tab 4 ?
Thanks it works! pujo -- http://mail.python.org/mailman/listinfo/python-list
Re: calling subclass constructor question
In Han Kang wrote: Hello everyone and thank you for being such a good community. Anyway, I was wondering...I have an super class which is the superclass for 5 other classes. However, I want to be able to call the subclass constructors from the super class. Is this possible? If you have a subclass, it's constructor is called - so why do you want to call it again ? It smells after bad design here - you might consider providing more dtail on the problem you want to solve by this, thus we might be able to suggest a more viable solution (or actually, a solution at all...) Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: functions with unlimeted variable arguments...
oops... it is in the tutorial... sorry. though, where would one find it in the python reference? i.e. the function def with variable/default parameters. This is not a rhetorical question, but where would one start to look for it in the python ref? a language is used by programers. Subroutine definition with variable/default parameters is a basic issue a programer wants to know, and different languages differs very much in how they handle this. This is what i mean that the language doc should be programing oriented, as opposed to computer-sciency or implementation oriented... Xah [EMAIL PROTECTED] http://xahlee.org/ -- http://mail.python.org/mailman/listinfo/python-list
Re: pickle alternative
[EMAIL PROTECTED] writes: If anyone is interested, I've implemented a faster and more space efficient gherkin with a few bug fixes. It would be nice if you just posted the PEP. -- http://mail.python.org/mailman/listinfo/python-list
Re: calling subclass constructor question
No. You will go into an infinite loop - at least I get there when I try someting like this: class Base: def __init__(self): Derived.__init__(self) print 'Base' class Derived(Base): def __init__(self): Base.__init__(self) print 'Derived' d = Derived() -- http://mail.python.org/mailman/listinfo/python-list
Re: functions with unlimeted variable arguments...
Xah Lee wrote: oops... it is in the tutorial... sorry. though, where would one find it in the python reference? i.e. the function def with variable/default parameters. This is not a rhetorical question, but where would one start to look for it in the python ref? Oddly enough, http://docs.python.org/ref/function.html -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
references/addrresses in imperative languages
in coding Python yesterday, i was quite stung by the fact that lists appened to another list goes by as some so-called reference. e.g. t=range(5) n=range(3) n[0]='m' t.append(n) n[0]='h' t.append(n) print t in the following code, after some 1 hour, finally i found the solution of h[:]. (and that's cheating thru a google search) def parti(l,j): '''parti(l,j) returns l partitioned with j elements per group. If j is not a factor of length of l, then the reminder elements are dropped. Example: parti([1,2,3,4,5,6],2) returns [[1,2],[3,4],[5,6]] Example: parti([1,2,3,4,5,6,7],3) returns [[1,2,3],[4,5,6]]''' n=len(l)/j r=[] # result list h=range(j) # temp holder for sublist for n1 in range(n): for j1 in range(j): h[j1]=l[n1*j+j1] r.append( h[:] ) return r interesting that a dictionary has copy method, but not list. (the pain is coupled with the uselessness of the Python doc) -- Btw, behavior such as this one, common in imperative languages and info tech industry, is a criminality arose out of hacks C, Unix, and from there all associated imperative langs. (C++, csh, perl, Java... but each generation improves slightly) The gist of the matter is that these behaviors being the way they are really is because they are the easiest, most brainless implementation, as oppose to being a design decision. In hindsight analysis, such language behavior forces the programer to fuse mathematical or algorithmic ideas with implementation details. A easy way to see this, is to ask yourself: how come in mathematics there's no such thing as addresses/pointers/references. - PS is there any difference between t=t+[li] t.append(li) - References: for a analysis of the same situation in Java, see http://xahlee.org/java-a-day/assign_array_to_list.html How to write a tutorial http://xahlee.org/Periodic_dosage_dir/t2/xlali_skami_cukta.html Xah [EMAIL PROTECTED] http://xahlee.org/ -- http://mail.python.org/mailman/listinfo/python-list
Re: functions with unlimeted variable arguments...
Xah Lee wrote: oops... it is in the tutorial... sorry. though, where would one find it in the python reference? i.e. the function def with variable/default parameters. This is not a rhetorical question, but where would one start to look for it in the python ref? a language is used by programers. Subroutine definition with variable/default parameters is a basic issue a programer wants to know, and different languages differs very much in how they handle this. This is what i mean that the language doc should be programing oriented, as opposed to computer-sciency or implementation oriented... Basically this boils down to you being to stupid to know the difference between a library reference and a language reference. And still you consider yourself to be above reading the tutorial in the first place to grasp even the simplest aspects about python? Gosh, this certainly isn't the first, but certainly one of the most enjoyable moronities you've been presenting to us. When does it occur to you that that type of moron-centric documentation you're bragging about is not needed by anybody else than you? So start writing An introduction to Python for morons, by a moron - the Xah Lee Files yourself - take your time, apart from you nobody needs it. Really. And stop annoying people who are willing to help others seeking advice who do show the will and abilities to actually dig into something and learn instead of crying out in rage all the time because python (or it's docs for that matter) doesn't seem to fit what your obviously severely limited understanding of concepts behind programming and computers in general tells you it should be. But I have the feeling you won't restrain yourself from blathering away in this NG - so thank god to killfiles... Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: references/addrresses in imperative languages
In hindsight analysis, such language behavior forces the programer to fuse mathematical or algorithmic ideas with implementation details. A easy way to see this, is to ask yourself: how come in mathematics there's no such thing as addresses/pointers/references. Mathematics also has no notion of computational complexity - solving the TSP for a million cities is a matter of a single term in math - but in the real world, you'll have time for a cup of coffee or two waiting for that - including the time it takes you to travel to the restaurant at the end of the universe to drink it there. So even the more simple minded can see that math and programming aren't equivalent. But obviously that's too much to comprehend for you - as is everything regarding programming. How about stop using a computer, and stick to an abacus, a pencil and a piece of paper? A positive sideeffect would be that you wouldn't be able to post in NGs. But I somehow think you won't show us that courtesy. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: calling subclass constructor question
In Han Kang wrote: Anyway, I was wondering...I have an super class which is the superclass for 5 other classes. However, I want to be able to call the subclass constructors from the super class. Is this possible? Are you trying to use your superclass as a factory? If so, one option is something like: py class A(object): ... @staticmethod ... def subclass(i): ... return A.__subclasses__()[i]() ... py class B(A): ... pass ... py class C(A): ... pass ... py A() __main__.A object at 0x011861B0 py A.subclass(0) __main__.B object at 0x01186070 py A.subclass(1) __main__.C object at 0x011861B0 I've never used this strategy, but I know that others have. You can probably search the list for __subclasses__ and find some more information. STeVe -- http://mail.python.org/mailman/listinfo/python-list
calling subclass constructor question
So each of the sub classes plots a different type of graph. The superclass defines methods that are the same for all the plots. I want to be able to pick some points and be able to generate a more plots. What I was wondering if I could define in a method in the superclass of an object the ability to make a brand new subclass (new plot). So basically, one plot makes another plot, but it'd be nice if i could put all the code in the superclass. Thank you again for all your thoughts and helps. -- http://mail.python.org/mailman/listinfo/python-list
RE: functions with unlimited variable arguments...
Xah said unto the world: oops... it is in the tutorial... sorry. though, where would one find it in the python reference? i.e. the function def with variable/default parameters. This is not a rhetorical question, but where would one start to look for it in the python ref? a language is used by programers. Subroutine definition with variable/default parameters is a basic issue a programer wants to know, and different languages differs very much in how they handle this. This is what i mean that the language doc should be programing oriented, as opposed to computer-sciency or implementation oriented... I don't get to the reference docs much. Mostly I use the quick reference guide and it's noted there in an easy to find manner. If you have not checked it out then see: http://rgruet.free.fr/#QuickRef Lee C -- http://mail.python.org/mailman/listinfo/python-list
Re: What is different with Python ?
Peter Hansen wrote: D H wrote: So you say he has done relatively little serious development and that he may not even know about Python. I didn't see any evidence from those pages to draw either conclusion. In fact the 4th paragraph quite contradicts them both. Clearly this is a matter of opinion. You're kidding right? Did you even read the about page you cited? The guy has been doing C++ development for decades, he wrote a book on it, and yet you say he has done little serious development??? That's absurd. And he was the president of ACCU, which if you look on the ACCU page at the very top is a mention of Python. And yet you suggested that he hasn't even heard of Python before. Again, absurd. -- http://mail.python.org/mailman/listinfo/python-list
login website that using PHP
Hi, I am trying to login a website that using PHP and javascript. This is what happend if you browse that website using IE, after you login, you can go anywhere without enter your name and password again, as long as you keep that IE open, but after you close that IE, then later on open that website in a new window, you need to login again. I guess some session is created as long as your original login window dose not close. How I can handle this in python? I want get some information from that website. But the login page is not what I want, how can I simulate regular IE browser? I mean after I login, I can get to other pages from it, but I find my programe can't go other place except the login page. Hope you could understand my question. Thank you very much! -- http://mail.python.org/mailman/listinfo/python-list
Re: case/switch statement?
Peter Hansen wrote: D H wrote: Peter Hansen wrote: [some stuff Doug didn't like] Actually, this is what you snipped, stuff you didn't like, because the very mention of boo causes you such fits: Since you and Steve Holden agree that a case statement is useful, why don't you propose it for python, or add it to the wiki page for Python 3000. Here is the syntax the developers of your favorite language boo ( http://boo.codehaus.org/ ) are using: given x: when 1: ... when 2: ... otherwise: ... -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there something similar to ?: operator (C/C++) in Python?
Peter Hansen wrote: Bo Peng wrote: I need to pass a bunch of parameters conditionally. In C/C++, I can do func(cond1?a:b,cond2?c:d,.) Is there an easier way to do this in Python? Please read the FAQ to learn the answer and much other useful ... The answer is no. Use if statements. -- http://mail.python.org/mailman/listinfo/python-list
Re: Loop until condition is true
Joseph Garvin wrote: Peter Otten wrote: I found 136 occurrences of do { versus 754 of while ( and 1224 of for ( in the Python 2.4 source, so using these rough estimates do-while still qualifies as rarely used. Peter That's 136 times you'd have to use an ugly hack instead. I definitely wouldn't mind an until or do/while. Yeah a do while loop was proposed over 2 years ago, but nothing ever came of it: http://www.python.org/peps/pep-0315.html It's been discussed for many many years, and again recently: http://mail.python.org/pipermail/python-dev/2005-June/054167.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Using swig to use an existing dll/library
You should be able to access regular dlls and handle callbacks with the ctypes module without needing to resort to any real c code: http://starship.python.net/crew/theller/ctypes/ -Chris On 18 Jun 2005 02:10:59 -0700, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi together, i have a Windows DLL in C that is internally multithreaded and provides a callback function to signal specific events. As I understood one can use normal C-code with swig. Is it also possible to use existing DLLs? Does swig can also handel the callback method? If not - is there another wrapper toolkit that can do that? Thanks, Peter -- http://mail.python.org/mailman/listinfo/python-list -- Christopher Lambacher [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: calling subclass constructor question
In Han Kang wrote: So each of the sub classes plots a different type of graph. The superclass defines methods that are the same for all the plots. I want to be able to pick some points and be able to generate a more plots. What I was wondering if I could define in a method in the superclass of an object the ability to make a brand new subclass (new plot). So basically, one plot makes another plot, but it'd be nice if i could put all the code in the superclass. Right, I agree with Steven, that you are probably wanting something like the factory pattern. Here's something modified from Steven's example more like what you are asking for: class Plot(object): #you need to subclass object to get __subclasses__ @staticmethod def getplot(name): return [plot for plot in Plot.__subclasses__() if plot.__name__ == name][0]() class LinePlot(Plot): pass class BarGraph(Plot): pass lp = Plot.getplot(LinePlot) bar = Plot.getplot(BarGraph) See also: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/86900 -- http://mail.python.org/mailman/listinfo/python-list
Re: Extensions on Linux: import without underscore?
On Saturday 18 June 2005 10:35 pm, James Carroll wrote: Hi, I'm creating an extension called _bright.so on linux. I can import it with import _bright, but how can I import bright and get the package? On windows, I've been able to import bright instead of import _bright, but on Linux it seems to need the underscore. I'm tempted to create a bright.py with from _bright import *, but I'm wondering if there's a more direct way. Okay, you may want a more elegant way to do this and other people have already responded to that point, but you do at least know you can just give it a new name: import _bright bright = _bright right? You can attach a new name to any Python object trivially (this is akin to a pointer assignment in C, it does not copy any significant amount of data). -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com -- http://mail.python.org/mailman/listinfo/python-list
Re: references/addrresses in imperative languages
I think the only reason I read your posts is for comedy, seeing if this is yet another Xah Lee just threw a tantrum post. I don't know why I'm wasting my time responding, though... It's against my better judgment and my previous advice to the group. Xah Lee wrote: in coding Python yesterday, i was quite stung by the fact that lists appened to another list goes by as some so-called reference. e.g. What would you have it do? A list is just a collection of objects. If I want to append my object to some list, I don't want a copy of it appended. If I did, I'd pass in a copy of it. Otherwise, a reference gets appended. t=range(5) n=range(3) n[0]='m' t.append(n) n[0]='h' t.append(n) print t in the following code, after some 1 hour,finally i found the solution of h[:]. (and that's cheating thru a google search) def parti(l,j): '''parti(l,j) returns l partitioned with j elements per group. If j is not a factor of length of l, then the reminder elements are dropped. Example: parti([1,2,3,4,5,6],2) returns [[1,2],[3,4],[5,6]] Example: parti([1,2,3,4,5,6,7],3) returns [[1,2,3],[4,5,6]]''' n=len(l)/j r=[] # result list h=range(j) # temp holder for sublist for n1 in range(n): for j1 in range(j): h[j1]=l[n1*j+j1] r.append( h[:] ) return r interesting that a dictionary has copy method, but not list. (the pain is coupled with the uselessness of the Python doc) You keep blasting the Python documentation. You have *yet* to produce anything of 1/10th the quality of any piece of the Python documentation. Until you are able to do so, I recommend shutting your proverbial trap. You have no grounds for raising the first criticism of the Python documentation since you have obviously not spent a significant amount of time reading them. In another thread from yesterday (entitled functions with unlimited variable arguments...), you asked where one could find a certain feature in the documentation (functionality which is, in my opinion, pretty basic). You appear to have found a reference in the tutorial by yourself and one person kindly pointed to a reference in the Python reference doc. -- You really don't do a good job making a good point in this section. Maybe it's the poor English, although I can typically extract good thought from poor English. Maybe it really is just poor thought. Btw, behavior such as this one, common in imperative languages and info tech industry, is a criminality Nice. If you don't like something, just call it a criminality. Let me try: the criminality of Xah Lee's postings caused all occupants of at least 4 continents to roll their eyes. You know - even though I think my assertion had some validity, I think even there it's ridiculous to make such a forceful assertion without a foundation for it. arose out of hacks C, Unix, and from there all associated imperative langs. (C++, csh, perl, Java... but each generation improves slightly) The gist of the matter is that these behaviors being the way they are really is because they are the easiest, most brainless implementation, as oppose to being a design decision. Again, prove it. Why is passing references (or appending references - you're not totally clear on what your beef is) brainless? What better implementation do you have to offer the world, oh great one? In hindsight analysis, such language behavior forces the programer to fuse mathematical or algorithmic ideas with implementation details. A easy way to see this, is to ask yourself: how come in mathematics there's no such thing as addresses/pointers/references. Maybe because in pure mathematics there isn't the need for a computer. Although, if we updated Descartes, Pascal, Fermat, Newton, and Leibnitz with some of Rambaldi's works, you might see the concept of addresses/pointers/references in pure mathematics. - PS is there any difference between t=t+[li] t.append(li) In [1]: def summit(lst, item): ...: lst = lst + item ...: print lst ...: In [2]: def appender(lst, item): ...: lst.append(item) ...: print lst ...: In [3]: def plus_equals(lst, item): ...: lst += item ...: print lst ...: In [5]: import dis In [6]: dis.dis(summit) 2 0 LOAD_FAST0 (lst) 3 LOAD_FAST1 (item) 6 BINARY_ADD 7 STORE_FAST 0 (lst) 3 10 LOAD_FAST0 (lst) 13 PRINT_ITEM 14 PRINT_NEWLINE 15 LOAD_CONST 0 (None) 18 RETURN_VALUE In [7]: dis.dis(appender) 2 0 LOAD_FAST0 (lst) 3 LOAD_ATTR1 (append) 6 LOAD_FAST1 (item) 9 CALL_FUNCTION1 12 POP_TOP 3 13 LOAD_FAST0 (lst) 16 PRINT_ITEM
Re: references/addrresses in imperative languages
On Sunday 19 June 2005 05:34 pm, Xah Lee wrote: in coding Python yesterday, i was quite stung by the fact that lists appened to another list goes by as some so-called reference. e.g. t=range(5) n=range(3) n[0]='m' t.append(n) n[0]='h' t.append(n) print t Day one in learning Python, yes --- names bind to objects NOT variables are filled with values. This is one case where prior experience with C warps your brain. in the following code, after some 1 hour, finally i found the solution of h[:]. (and that's cheating thru a google search) def parti(l,j): '''parti(l,j) returns l partitioned with j elements per group. If j is not a factor of length of l, then the reminder elements are dropped. Example: parti([1,2,3,4,5,6],2) returns [[1,2],[3,4],[5,6]] Example: parti([1,2,3,4,5,6,7],3) returns [[1,2,3],[4,5,6]]''' n=len(l)/j r=[] # result list h=range(j) # temp holder for sublist for n1 in range(n): for j1 in range(j): h[j1]=l[n1*j+j1] r.append( h[:] ) return r Too bulky? How about: def parti(L, j): return [L[k*j:(k+1)*j] for k in range(len(L)/j)] e.g.: parti([1,2,3,4,5,6,7],3) [[1, 2, 3], [4, 5, 6]] parti([1,2,3,4,5,6],2) [[1, 2], [3, 4], [5, 6]] PS is there any difference between t=t+[li] t.append(li) No, but t=t+[li] is quite different from t.append([li]) -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com -- http://mail.python.org/mailman/listinfo/python-list
Using print with format to stdout generates unwanted space
#!/usr/bin/env python # Using a print statement to stdout results in an # unwanted space character being generated at the # end of each print output. Same results on # DOS/Windows and AIX. # # I need precise control over the bytes that are # produced. Why is print doing this? # import sys # If this is a DOS/Windows platform, then put stdout # into binary mode so that only the UNIX compatible newline # will be generated. # try: import msvcrt, os msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) except: print 'This is not an msvcrt platform.' pass # Using print with newline suppressed generates a space at the # end of each print statement. # for i in range(3): print '%d,60,' % (i), for j in range(10): print '%d,' % (j), print '' # Using a list and doing a join does not result in the space # character being generated. # for i in range(3): alist = [] alist.append('%d,60,' % (i)) for j in range(10): alist.append('%d,' % (j)) print ''.join(alist) sys.exit(0) -- http://mail.python.org/mailman/listinfo/python-list
Re: static data descriptors and possibly spurious calls to __set__?
...it's this last one that causes the problem. In the real code, the call to type.__setattr__ referred to above seems to lead to a call to something like cls.__base__.__dict__[attr].__set__(cls, value). Uhm ... sounds right, but I a bit confused. Could you please give us a doctest showing us what you get and what you would like to get? Michele Simionato Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Re: Using print with format to stdout generates unwanted space
Don't use print, write directly to sys.stdout. Print is not intended for precise output formatting; it's intended for quick outputs that are useable most of the time. John Roth Paul Watson [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] #!/usr/bin/env python # Using a print statement to stdout results in an # unwanted space character being generated at the # end of each print output. Same results on # DOS/Windows and AIX. # # I need precise control over the bytes that are # produced. Why is print doing this? # import sys # If this is a DOS/Windows platform, then put stdout # into binary mode so that only the UNIX compatible newline # will be generated. # try: import msvcrt, os msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) except: print 'This is not an msvcrt platform.' pass # Using print with newline suppressed generates a space at the # end of each print statement. # for i in range(3): print '%d,60,' % (i), for j in range(10): print '%d,' % (j), print '' # Using a list and doing a join does not result in the space # character being generated. # for i in range(3): alist = [] alist.append('%d,60,' % (i)) for j in range(10): alist.append('%d,' % (j)) print ''.join(alist) sys.exit(0) -- http://mail.python.org/mailman/listinfo/python-list
Re: New WYSIWYG Python IDE in the works
wxDesigner + XRCed = The best. I would like the Boa approach but with xrc exports. It would reaally be the best of the best! And don't get me wrong too, but to be better than the competition you need to be better than the competition - Christoph Rackwitz Daniel -- http://mail.python.org/mailman/listinfo/python-list
Re: case/switch statement?
On 6/18/05, D H [EMAIL PROTECTED] wrote: I would hardly call using a dictionary as a switch statement, the equivalent. The fact that people use a dictionary as a conditional is a python wart. Not at all. A case statement is nothing more than a literal mapping of constant values to the execution of code blocks; a dictionary is a (not necessarily literal) mapping of hashable (not just constant) values to other values. A dictionary is a very close match for the operation of a case statement. In the common (in my experience) instance where the case statement is like (using C notation): switch(x) { case 1: y = foo; break; case 2: y = bar; break; case 3: y = baz; break; default: y = qux; } In this case the dictionary is obviously a better and clearer choice. I've generally found for other circumstances where I've used switch statements that the code ends up more readable if it's reorganised so that the switch statements are all of the form above, or are eliminated entirely--so I don't miss a switch/case statement in Python. And, just because we can, the most direct equivalent (in terms of written code) of a switch/case statement in Python is: exec { 1: y = foo, 2: y = bar, 3: y = baz }.get(x,y = qux) But I didn't say it was nice... -- http://mail.python.org/mailman/listinfo/python-list
Re: references/addrresses in imperative languages
In article [EMAIL PROTECTED], Xah Lee [EMAIL PROTECTED] wrote: A[n] easy way to see this, is to ask yourself: how come in mathematics there's no such thing as addresses/pointers/references. Yes there are such things in mathematics, though not necessarily under that name. For instance, in graph theory, edges can be considered as pointers. After all, make a change to a node, and that change is visible via all edges pointing to that node. -- http://mail.python.org/mailman/listinfo/python-list