Re: [Tutor] Linux/Window Differences in Python?
Thanks to everyone for their comments on Python. I am glad to hear that, aside from specific modules, it is pretty much cross-platform as I thought, I just wanted to make certain that my understanding was correct. I am NOT a programmer, though my job responsibilities keep dragging me closer and closer to that point :) What little I have seen of Python so far I have liked, mainly because the statements seemed pretty straightforward. Someone noted that the list has already seen some ESRI related traffic, and I suspect that may increase - though as more people learn more about it there will likely be more Python-related help in the ESRI forums. There is some traffic there now on this topic, but not much (yet). Just to summarize what is happening, a search of the ESRI website indicates that ArcGIS 9.0 and 9.1 installs Python 2.1 (because of problems running a silent install of Pythonwin). To solve this problem ArcGIS 9.2 will support a native Python module for ArcGIS which will remove the dependence on Pythonwin so the latest version of Python will be shipped at that time. It will be interesting to see if VBA will still be supported at that time, no one seems to know (or telling) Thanks again! I am quite sure I will be back with newbie Python questions :) I have a book at home that teaches python by creating little games, can't remember the name... Catherine ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Expanding _treeList in TreeCtrl
Hi to all, list: Well, I wanted to ask for some help on some subject. I have a TreeCtrl with a _treeList variable: _treeList = [ ( 'Parent 1', ['Child 1.1','Child 1.2'] ), ( 'Parent 2', [] ), ( 'Parent 3', [ 'Child 3.1', 'Child 3.2'] ), ( 'Parent 4', ['Child 4'] ) ] self.tree = wx.TreeCtrl(... self.root = self.tree.AddRoot("Main") # I make the menu with: for item in _treeList: child = self.tree.AppendItem(self.root, item[0]) for childItem in item[1]: self.tree.AppendItem(child, childItem) # Then expand the root self.tree.Expand(root) Now, I'm looking for some code that would expand all trees branches, and not just the root. And I don't seem to manage to code something like that. Any ideas on how this could be done? Thanks. Daniel __ Renovamos el Correo Yahoo! Nuevos servicios, más seguridad http://correo.yahoo.es ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] hi HELP
I want to unsubscribe from your python mailing list and anything related that keeps sending un imagned amount of emails that anrt spam but a bit of shit. pls Unsubscribe me. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] hi HELP
On 8/14/05, Suranga Sarukkali <[EMAIL PROTECTED]> wrote: > I want to unsubscribe from your python mailing list and anything related > that keeps sending un imagned amount of emails that anrt spam but a bit > of shit. pls Unsubscribe me. > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor Do you see the last line of _every_ email you receive? I've left it intact so you cannot miss it - have you ever considered clicking on it? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] hi HELP
At 09:57 PM 8/14/2005, Suranga Sarukkali wrote: >I want to unsubscribe from your python mailing list and anything related >that keeps sending un imagned amount of emails that anrt spam but a bit >of shit. pls Unsubscribe me. You are on this list because you subscribed. You must also unsubscribe. Click >http://mail.python.org/mailman/listinfo/tutor and look for unsubscribe under the subscribe section. Bob Gailer 303 442 2625 home 720 938 2625 cell ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Searching Sorted Lists
Hi, Can someone tell me if there is a bulit in Binary search function for python lists ? I am currently building lists and sorting them with a comparison function. The only list search function I know is List.Index(X), which is pretty inefficient I reckon, especially hen the lists are likely to contain 100's or 100's of members. Is there a search function that uses a compariosn function / binary chop ? or will I have to implement my own ? Regards, Daniel Smith. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Searching Sorted Lists
> Hi, Can someone tell me if there is a bulit in Binary search function > for python lists ? > > I am currently building lists and sorting them with a comparison > function. The only list search function I know is List.Index(X), which > is pretty inefficient I reckon, especially hen the lists are likely to > contain 100's or 100's of members. Hi Daniel, Out of curiosity, why are you sorting the lists? Just wondering --- it may be that a sorted list is the appropriate data structure for your problem, but perhaps another might be better suited. There is a binary search method in the 'bisect' module: http://www.python.org/doc/lib/module-bisect.html It doesn't appear to take in a customized comparison, but it shouldn't be too hard to modify it so that it does. I'd recommend taking the source to bisect_left, and work from there. Best of wishes to you! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Searching Sorted Lists
[EMAIL PROTECTED] wrote: > > Hi, Can someone tell me if there is a bulit in Binary search function for > python lists ? The bisect module implements a binary search though it doesn't support custom comparison functions. You could make your list elements be instances of a class with a __cmp__() method that does what you want. You should also consider whether you can use a dict to hold your data - if you need fast lookup and order is not important that is the way to go. Kent > I am currently building lists and sorting them with a comparison function. > The only list search function I know is List.Index(X), which is pretty > inefficient I reckon, especially hen the lists are likely to contain 100's > or 100's of members. > > Is there a search function that uses a compariosn function / binary chop ? > or will I have to implement my own ? > > Regards, > > Daniel Smith. > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] How do you turn something into a number?
Hello, Not understanding the proper phraseology for my question I can’t search the faq so here goes: I have what I think is a string from socket.recvfrom(…). I want to turn it into numbers so I tried: from socket import * from array import * data, address = recvfrom (...stuff...) s = “” number =int(s.join(data[10:13],16)) # turn two bytes of the string into a python number, do this a lot to parse all numbers from # socket stream This yaks and says something about improper argument to int. I don’t understand python’s type system at all so any help here will be greatly appreciated. Thanks, Frank ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 18, Issue 78
I want to unsubscribe from your python mailing list and anything relatedthat keeps sending un imagned amount of emails that anrt spam but a bit of shit. pls Unsubscribe me. If you're still subscribed, you may want to switch over to the digest mode and only get a few emails a day. This is an active list, and should be. Switching to "digest" (click the link below and you'll be fine) should help. Kind Regards, --greg ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How do you turn something into a number?
> I have what I think is a string from socket.recvfrom(...). I want to > turn it into numbers Hi Frank, If you know how those bytes should be interpreted, you may want to look at the 'struct' module to destructure them back into integers: http://www.python.org/doc/lib/module-struct.html > from socket import * > from array import * Side note: you may want to avoid doing the 'from import *' form in Python, just because there's a high chance that one module will munge the names of another. If you want to avoid typing, you can always abbreviate module names by doing something like this: ## import socket as S import array as A ## For more information on this, see: http://www.python.org/doc/tut/node8.html#SECTION00841 Ok, let's continue looking at some code: [some code cut] > number =int(s.join(data[10:13],16)) I think you meant to write: number = int(data[10:13], 16) But even with the correction, this will probably not work: int() expects to see string literals, not arbitrary byte patterns that come off the socket.recv_from. I think you want to use 'struct' instead. For example: ## >>> import struct >>> struct.calcsize("h") 2 ## On my platform, a "short" is two bytes. ## >>> def parse_short(bytes): ... """Given two bytes, interprets those bytes as a short.""" ... return struct.unpack("h", bytes)[0] ... >>> parse_short('\x01\x00') 1 >>> parse_short('\x00\x01') 256 ## And from this example, we can see that I'm on a "little-endian" system. http://catb.org/~esr/jargon/html/L/little-endian.html So we probably do need to take care to tell 'struct' to interpret the bytes in "network" order, bu using the '!' prefix during the byte unpacking: ## >>> def parse_short(bytes): ... """Given two bytes, interprets those bytes as a short.""" ... return struct.unpack("!h", bytes)[0] ... >>> parse_short('\x01\x00') 256 >>> parse_short('\x00\x01') 1 ## Please feel free to ask questions on this. Hope this helps! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Silly loop question
Hehe, Yah, I should've read the tutorial again, I do apologise, it was a 3 in the morning-coffee not working question. Regards, Liam Clarke On 8/17/05, Alan G <[EMAIL PROTECTED]> wrote: > > changeIndex = None > > al = len(line) > > for i in range(al): > > And theres the problem. > Pythonprovides two loops, for is really a *foreach* so if you don't > want to process *each* item - eg by jumping forward - then you really > should use while and manage the index thataway. > > You can hack about with the indexin a for but basically its abusing > the intent of a for loop. Beter to explicitly hack about in a while > loop! > > So: > > while i < len(line): >if changeIndex and i < changeIndex > i = changeIndex > >if line[i] == "{": > nextRightBracket = line.find("}",i) > #other stuff happens > changeIndex = nextRightBracket + 1 >else: > i += 1 > > > read Alan's tutorial again. *grin* > > Umm, well the section on branching does refer to the two loops and > when > each is most appropriate, so... :-) > > Alan G > Author of the Learn to Program web tutor > http://www.freenetpages.co.uk/hp/alan.gauld > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Declaring encoding question
Hi all, I've got some source code which will be handling non-ASCII chars like umlauts and what not, and I've got a testing portion stored in the code. I get this deprecation warning when I run my code - __main__:1: DeprecationWarning: Non-ASCII character '\xfc' in file C:\Python24\testit.py on line 733, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details I'm reading this - http://www.python.org/peps/pep-0263.html Now, the non-ASCII character is in the test data, so it's not actually part of my code. Will Python be able to handle \xfc and company in data without my telling it to use a different form of encoding? When I run the code, and get my returned data, it looks like this in Pythonwin - >>> print j["landunits"].keys() ['"J\xe4ger"', '"Deutschmeister"', '"Army of Bohemia"', '"Gardegrenadiere"', '"K.u.K Armee"', '"Erzherzog"', '"Army of Italy"', '"Army of Silesia"', '"Army of Hungary"'] So J\xe4ger is actually Jäger. When I run it slightly differently - >>> for item in j["landunits"].keys(): ... print item ... "Jäger" "Deutschmeister" "Army of Bohemia" "Gardegrenadiere" "K.u.K Armee" "Erzherzog" "Army of Italy" "Army of Silesia" "Army of Hungary" It prints the umlauted 'a' fine and dandy. So, do I have to do anything to ensure that Python will continue to display the non-ASCII chars? I intend to have my output delivered via a Pythoncard/wxPython GUI, and I'm not sure if it's the Python interpreter displaying it properly, or Pythonwin making a special effort. Regards, Liam Clarke ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Sorting a list of lists aka nested lists
No-one's mentioned a Schwartzian Transform yet ; ) On 8/15/05, Kent Johnson <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > Note that in Python2.4+, you can use key= instead: > > > > def sortKey(lst): > > return lst[2] > > Quant.sort(key=sortKey) > > > > This is more effient than specifying a different comparison function, > > because > > the key function is only called once for each element. > > And instead of defining your own function you can use itertools.itemgetter() > which is intended for this purpose: > import itertools > Quant.sort(key=itertools.itemgetter(2)) > > Kent > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] UTf-8 to Entity
You'll need the csv module. And that should be about it, I think. The rest would just be using string methods. On 8/15/05, Diaz, Wendell <[EMAIL PROTECTED]> wrote: > > > > Hey guys, > > > > Hope you can help me on this. > > > > I want to make a python program which opens an XML (UTF-8 encoding) and do a > search & replace. It will search the Unicode and replace them with their > equivalent entity name. The program will read a look-up table (a tab > delimited text file) which list the unicodes that needs to be replace with > enity names. > > > > Example of the look-up table: > > > > &nobreakspace; [tab] 000A0 > > > > Thanks in advance, > > > > Wendell > > > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Sorting a list of lists aka nested lists
mailing list wrote: > No-one's mentioned a Schwartzian Transform yet ; ) because it's obsoleted by the key parameter to sort... > > > > On 8/15/05, Kent Johnson <[EMAIL PROTECTED]> wrote: > >>[EMAIL PROTECTED] wrote: >> >>>Note that in Python2.4+, you can use key= instead: >>> >>>def sortKey(lst): >>> return lst[2] >>>Quant.sort(key=sortKey) >>> >>>This is more effient than specifying a different comparison function, because >>>the key function is only called once for each element. >> >>And instead of defining your own function you can use itertools.itemgetter() >>which is intended for this purpose: >>import itertools >>Quant.sort(key=itertools.itemgetter(2)) >> >>Kent >> >>___ >>Tutor maillist - Tutor@python.org >>http://mail.python.org/mailman/listinfo/tutor >> > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor