Re: sort one list using the values from another list

2006-02-26 Thread Kent Johnson
Brian Blais wrote: Hello, I have two lists, one with strings (filenames, actually), and one with a real-number rank, like: A=['hello','there','this','that'] B=[3,4,2,5] I'd like to sort list A using the values from B, so the result would be in this example,

Re: Coding Problem (arbitrary thread sych)

2006-02-26 Thread Kent Johnson
peleme wrote: The threads which arrives to the s function should wait for each other until the last one. So A, B, and C executes the last function 'together', while D executes it seperate. I only know that three threads have to be in synch. Take a look at the Barrier patter in The Little Book

Re: How can I find the remainder when dividing 2 integers

2006-02-26 Thread Kent Johnson
Diez B. Roggisch wrote: [EMAIL PROTECTED] schrieb: okay, I try you suggestion, and re-write my code like this: colors = [#ff, #00FF00, #FF] colorIndex = 0 def getText(nodelist): for str in strings: print colors[colorIndex % colors.length]

Re: ls files -- list packer

2006-02-26 Thread Kent Johnson
kpp9c wrote: os.listdir works great ... just one problem, it packs the filenames only into a list... i need the full path and seach as i might i se NO documentation on python.org for os.listdir() Docs for os.listdir() are here: http://docs.python.org/lib/os-file-dir.html When all else fails

Re: How to do an 'inner join' with dictionaries

2006-02-27 Thread Kent Johnson
[EMAIL PROTECTED] wrote: Let's say I have two dictionaries: dict1 is 1:23, 2:76, 4:56 dict2 is 23:A, 76:B, 56:C How do I get a dictionary that is 1:A, 2:B, 4:C dict1 = {1:23, 2:76, 4:56} dict2 = {23:'A', 76:'B', 56:'C'} dict((key, dict2[value]) for key, value in

Re: Waiting for Connection

2006-02-27 Thread Kent Johnson
D wrote: I am trying to do the following using Python and Tkinter: 1) Display a window with 1 button 2) When user clicks the button, Python attempts to call a function that opens a socket and listens for a connection - what I want to do is, if the socket has been successfully opened and

Re: different ways to strip strings

2006-02-27 Thread Kent Johnson
rtilley wrote: s = ' qazwsx ' # How are these different? print s.strip() print str.strip(s) They are equivalent ways of calling the same method of a str object. Do string objects all have the attribute strip()? If so, why is str.strip() needed? Really, I'm just curious... there's a lot

Re: different ways to strip strings

2006-02-27 Thread Kent Johnson
Crutcher wrote: It is something of a navel (left over feature). xyz.strip() is (I think) newer than string.strip() Yes, but the question as written was about str.strip() which is an unbound method of the str class, not string.strip() which is a deprecated function in the string module. Kent

Re: type = instance instead of dict

2006-02-27 Thread Kent Johnson
Cruella DeVille wrote: I'm trying to implement a bookmark-url program, which accepts user input and puts the strings in a dictionary. Somehow I'm not able to iterate myDictionary of type Dict{} When I write print type(myDictionary) I get that the type is instance, which makes no sense to

Re: type = instance instead of dict

2006-02-27 Thread Kent Johnson
Cruella DeVille wrote: So what you are saying is that my class Dict is a subclass of Dict, and user defined dicts does not support iteration? I don't know what your class Dict is, I was guessing. The built-in is dict, not Dict. What I'm doing is that I want to write the content of a

Re: sort one list using the values from another list

2006-02-27 Thread Kent Johnson
Simon Sun wrote: Magnus Lycka wrote: Is there something here I can't see, or did you just change a variable name and present that as another solution? Heh, I have use python for a very short time. Base your statements, I test in python, found `_' is a valid variable name. So I don't know it

Re: Fetching the Return results of a spawned Thread

2006-02-28 Thread Kent Johnson
Alvin A. Delagon wrote: Is there any way to fetch the Return results of spawned threads within the parent script? There are several examples of this in the threading section of the Python Cookbook for example http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/84317

Re: lambda closure question

2005-02-19 Thread Kent Johnson
Ted Lilley wrote: What I want to do is pre-load functions with arguments by iterating through a list like so: class myclass: ...pass def func(self, arg): ...print arg mylist = [my, sample, list] for item in mylist: ...setattr(myclass, item, lamdba self: func(self, item)) This attaches

Re: could that be a mutable object issue ?

2005-02-19 Thread Kent Johnson
Philippe C. Martin wrote: If I do this: print 'LEN OF BOOK BEFORE APPEND: ', len(pickle.dumps(self.__m_rw)) self.__m_rw.books.append( [p_col1,p_col2,p_col3] ) print 'LEN OF BOOK AFTER APPEND: ', len(pickle.dumps(self.__m_rw)) I get the same length before and after append. when I print

Re: How Do I get Know What Attributes/Functions In A Class?

2005-02-21 Thread Kent Johnson
Hans Nowak wrote: [EMAIL PROTECTED] wrote: Hi, I'm new to python. Given a class, how can I get know what attributes/functins in it without dig into the source? Use the dir function: from smtplib import SMTP dir(SMTP) ['__doc__', '__init__', '__module__', 'close', 'connect', 'data',

Re: recommended way of generating HTML from Python

2005-02-21 Thread Kent Johnson
Michele Simionato wrote: The problem is a problem of standardization, indeed. There plenty of recipes to do the same job, I just would like to use a blessed one (I am teaching a Python course and I do not know what to recommend to my students). Why not teach your students to use a template system?

Re: On eval and its substitution of globals

2005-02-23 Thread Kent Johnson
Paddy wrote: Hi, I got tripped up on the way eval works with respect to modules and so wrote a test. It seems that a function carries around knowledge of the globals() present when it was defined. (The .func_globals attribute)? When evaluated using eval(...) the embedded globals can be overridden

Re: Style guide for subclassing built-in types?

2005-02-23 Thread Kent Johnson
[EMAIL PROTECTED] wrote: p.s. the reason I'm not sticking to reversed or even reverse : suppose the size of the list is huge. reversed() returns an iterator so list size shouldn't be an issue. What problem are you actually trying to solve? Kent --

Re: unicode(obj, errors='foo') raises TypeError - bug?

2005-02-23 Thread Kent Johnson
Steven Bethard wrote: Mike Brown wrote: class C: ... def __str__(self): ... return 'asdf\xff' ... o = C() unicode(o, errors='replace') Traceback (most recent call last): File stdin, line 1, in ? TypeError: coercing to Unicode: need string or buffer, instance found [snip] What am I doing

Re: unicode(obj, errors='foo') raises TypeError - bug?

2005-02-23 Thread Kent Johnson
Martin v. Lwis wrote: Steven Bethard wrote: Yeah, I agree it's weird. I suspect if someone supplied a patch for this behavior it would be accepted -- I don't think this should break backwards compatibility (much). Notice that the right thing to do would be to pass encoding and errors to

Re: Communication between JAVA and python

2005-02-23 Thread Kent Johnson
Jacques Daussy wrote: Hello How can I transfert information between a JAVA application and a python script application. I can't use jython because, I must use python interpreter.I think to socket or semaphore, but can I use it on Windows plateform ? Jython has an interpreter and Windows has

Re: On eval and its substitution of globals

2005-02-23 Thread Kent Johnson
Paddy wrote: I do in fact have the case you mention. I am writing a module that will manipulate functions of global variables where the functions are defined in another module. Would it be possible to have your functions take arguments instead of globals? That would seem to be a better design.

Re: split a directory string into a list

2005-02-25 Thread Kent Johnson
[EMAIL PROTECTED] wrote: QUESTION: How do I split a directory string into a list in Python, eg. '/foo/bar/beer/sex/cigarettes/drugs/alcohol/' becomes ['foo','bar','beer','sex','cigarettes','drugs','alcohol'] '/foo/bar/beer/sex/cigarettes/drugs/alcohol/'.strip('/').split('/') ['foo', 'bar',

Re: Converting HTML to ASCII

2005-02-25 Thread Kent Johnson
gf gf wrote: Hi. I'm looking for a Python lib to convert HTML to ASCII. You might find these threads on comp.lang.python interesting: http://tinyurl.com/5zmpn http://tinyurl.com/6mxmb Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: class factory example needed (long)

2005-03-01 Thread Kent Johnson
Gary Ruben wrote: OK, I've managed to get this to work with Rainer's method, but I realised it is not the best way to do it, since the methods are being added by the constructor, i.e. they are instance methods. This means that every time a foo object is created, a whole lot of code is being

Re: Regular Expressions: large amount of or's

2005-03-01 Thread Kent Johnson
André Søreng wrote: Hi! Given a string, I want to find all ocurrences of certain predefined words in that string. Problem is, the list of words that should be detected can be in the order of thousands. With the re module, this can be solved something like this: import re r =

Re: Regular Expressions: large amount of or's

2005-03-01 Thread Kent Johnson
André Søreng wrote: Hi! Given a string, I want to find all ocurrences of certain predefined words in that string. Problem is, the list of words that should be detected can be in the order of thousands. With the re module, this can be solved something like this: import re r =

Re: Help- Simple recursive function to build a list

2005-03-01 Thread Kent Johnson
actuary77 wrote: I am trying to write simple recursive function to build a list: def rec(n,alist=[]): _nl=alist[:] print n,_nl if n == 0: print n,_nl return _nl else: _nl=_nl+[n] rec(n-1,_nl) should be return rec(n-1,_nl) def

Re: Help- Recursion v. Iter Speed comparison

2005-03-02 Thread Kent Johnson
Roy Smith wrote: I believe Edouard Manet said it best, Damn your recursion, Henri. Iteration, however complex, is always more efficient. (extra points if you can identify the source of that quote). It's not clear what language Manet was talking about when he said that, but it's pretty much a

Re: Multiline regex help

2005-03-03 Thread Kent Johnson
Yatima wrote: Hey Folks, I've got some info in a bunch of files that kind of looks like so: Gibberish 53 MoreGarbage 12 RelevantInfo1 10/10/04 NothingImportant ThisDoesNotMatter 44 RelevantInfo2 22 BlahBlah 343 RelevantInfo3 23 Hubris Crap 34 and so on... Anyhow, these fields repeat several times

Re: binutils strings like functionality?

2005-03-03 Thread Kent Johnson
cjl wrote: Hey all: I am working on a little script that needs to pull the strings out of a binary file, and then manipulate them with python. The command line utility strings (part of binutils) has exactly the functionality I need, but I was thinking about trying to implement this in pure python.

Re: greedy match wanted

2005-03-03 Thread Kent Johnson
alexk wrote: My problem is as follows. I want to match urls, and therefore I have a group of long valid domain names in my regex: (?:com|org|net|biz|info|ac|cc|gs|ms| sh|st|tc|tf|tj|to|vg|ad|ae|af|ag| com\.ag|ai|off\.ai|al|an|ao|aq|

Re: problem with recursion

2005-03-03 Thread Kent Johnson
vegetax wrote: I am trying to make convert a directory tree in a list of list, but cant find the algoritm =( ,for example a directory tree like : #!/usr/bin/python from os import listdir from os.path import isdir,join,basename dirpath = '/tmp/test/' res = [] def rec(f): print f for ele in

Re: Multiline regex help

2005-03-03 Thread Kent Johnson
Here is another attempt. I'm still not sure I understand what form you want the data in. I made a dict - dict - list structure so if you lookup e.g. scores['10/11/04']['60'] you get a list of all the RelevantInfo2 values for Relevant1='10/11/04' and Relevant2='60'. The parser is a simple-minded

Re: Multiline regex help

2005-03-03 Thread Kent Johnson
Steven Bethard wrote: Kent Johnson wrote: for line in raw_data: if line.startswith('RelevantInfo1'): info1 = raw_data.next().strip() elif line.startswith('RelevantInfo2'): info2 = raw_data.next().strip() elif line.startswith('RelevantInfo3'): info3

Re: There's GOT to be a better way!

2005-03-03 Thread Kent Johnson
[EMAIL PROTECTED] wrote: This would be a good case to use OO design, imo. The following works fine. Simply instantiate the object, call the method, and you can access (and manipulate) the module's variable to your heart's content. module.py class object: Ouch. Use a different name than

Re: jython question (interesting behavior)

2005-03-03 Thread Kent Johnson
pythonUser_07 wrote: Is this the correct place to post a jython question? I posted the following in the jython group, but I figured I'd post here too: _ I am assuming that the PythonInterpreter environment is not a unique environment from within a jvm. Here

Re: Setting default option values for Tkinter widgets

2005-03-04 Thread Kent Johnson
Steve Holden wrote: [EMAIL PROTECTED] wrote: Eric, your tagline doesn't parse correctly on my Python 2.4 shell. So, are you using Windows? If you interchange single and double quotes it works on Windows too python -c print ''.join([chr(154 - ord(c)) for c in

Re: Integer From A Float List?!?

2005-03-05 Thread Kent Johnson
[EMAIL PROTECTED] wrote: Hello NG, sorry to bother you again with this question... I never used the timeit function, and I would like to ask you if the call I am doing is correct: C:\Python23\Libpython timeit.py -n 1000 -s from Numeric import ones -s floa ts=ones((1000,1),'f') -s ints =

Re: Accessing Python parse trees

2005-03-05 Thread Kent Johnson
Manlio Perillo wrote: Anyway, here is an example of what I would like to do: #begin def foo(**kwargs): print kwargs foo(a = 1, b = 2, c = 3) #end In the current implementation kwargs is a dict, but I need to have the keyword argument sorted. Unfortunately subclassing fron dict and installing the

Re: Relative imports

2005-03-05 Thread Kent Johnson
Chris wrote: After reading that link I tried to change my imports like this: from .myPythonFileInTheSameFolder import MyClass This style of import is not yet implemented. I'm getting more and more confused... How can I correctly do a relative import ? I think your choices are - keep doing what

Re: Equality operator

2005-03-05 Thread Kent Johnson
italy wrote: Why doesn't this statement execute in Python: 1 == not 0 I get a syntax error, but I don't know why. Because == has higher precedence than 'not', so you are asking for (1 == not) 0 Try 1 == (not 0) True Kent Thanks, Adam Roan -- http://mail.python.org/mailman/listinfo/python-list

Re: Can a method in one class change an object in another class?

2005-03-06 Thread Kent Johnson
Stewart Midwinter wrote: I've got an app that creates an object in its main class (it also creates a GUI). My problem is that I need to pass this object, a list, to a dialog that is implemented as a second class. I want to edit the contents of that list and then pass back the results to the first

Re: function with a state

2005-03-06 Thread Kent Johnson
Patrick Useldinger wrote: The short answer is to use the global statement: globe=0 def myFun(): global globe globe=globe+1 return globe more elegant is: globe=0 globe=myfun(globe) def myFun(var): return var+1 This mystifies me. What is myfun()? What is var intended to be? Kent --

Re: function with a state

2005-03-06 Thread Kent Johnson
Patrick Useldinger wrote: Kent Johnson wrote: globe=0 globe=myfun(globe) def myFun(var): return var+1 This mystifies me. What is myfun()? What is var intended to be? myfun is an error ;-) should be myFun, of course. var is parameter of function myFun. If you call myFun with variable globe

Re: reversed heapification?

2005-03-07 Thread Kent Johnson
Stefan Behnel wrote: Hi! I need a general-purpose best-k sorting algorithm and I'd like to use heapq for that (heapify + heappop*k). The problem is that heapify and heappop do not support the reverse keyword as known from sorted() and list.sort(). While the decorate-sort-undecorate pattern allows

Re: reversed heapification?

2005-03-07 Thread Kent Johnson
Stefan Behnel wrote: Kent Johnson wrote: heapq.nlargest() heapq.nsmallest() On second thought, that doesn't actually get me very far. I do not know in advance how many I must select since I need to remove duplicates *after* sorting (they are not necessarily 'duplicate' enough to fall

Re: shuffle the lines of a large file

2005-03-07 Thread Kent Johnson
Joerg Schuster wrote: Hello, I am looking for a method to shuffle the lines of a large file. I have a corpus of sorted and uniqed English sentences that has been produced with (1): (1) sort corpus | uniq corpus.uniq corpus.uniq is 80G large. The fact that every sentence appears only once in

Re: looking for way to include many times some .py code from anotherpython code

2005-03-08 Thread Kent Johnson
Martin MOKREJ wrote: Hi, I'm looking for some easy way to do something like include in c or PHP. Imagine I would like to have: cat somefile.py a = 222 b = 111 c = 9 cat somefile2.py self.xxx = a self.zzz = b self.c = c self.d = d cat anotherfile.py def a(): include somefile postprocess(a)

Re: looking for way to include many times some .py code fromanotherpython code

2005-03-08 Thread Kent Johnson
Martin MOKREJ wrote: Oh, I've picked up not the best example. I wanted to set the variables not under __init__, but under some other method. So this is actually what I really wanted. class klass(somefile2.base): def __init__(): pass def set_them(self, a, b, c, d):

Re: Best way to make a list unique?

2005-03-09 Thread Kent Johnson
Delaney, Timothy C (Timothy) wrote: Diez B. Roggisch wrote: This is actually one thing that Java 1.5 has that I'd like to see in Python - the LinkedHashSet and LinkedHashMap. Very useful data structures. Implementing these is fairly simple. There are two Ordered Dictionary recipes in the cookbook

Re: Working on a log in script to my webpage

2005-03-09 Thread Kent Johnson
Pete. wrote: Hi all I am working on a log in script for my webpage. I have the username and the password stored in a PostgreSQL database. You might want to look at Snakelets and CherryPy. Snakelets is a very simple-to-use Python web application server. One of the features is Easy user

Re: Is there a short-circuiting dictionary get method?

2005-03-09 Thread Kent Johnson
F. Petitjean wrote: Le Wed, 09 Mar 2005 09:45:41 -0800, Dave Opstad a écrit : Is there a short-circuit version of get that doesn't evaluate the second argument if the first is a valid key? For now I'll code around it, but this behavior surprised me a bit... def scary(): print scary called

Re: a RegEx puzzle

2005-03-11 Thread Kent Johnson
Charles Hartman wrote: I'm still shaky on some of sre's syntax. Here's the task: I've got strings (never longer than about a dozen characters) that are guaranteed to be made only of characters 'x' and '/'. In each string I want to find the longest continuous stretch of pairs whose first

Re: Bind Escape to Exit

2005-03-13 Thread Kent Johnson
Binny V A wrote: Hello Everyone, I am new to python and I am trying to get a program to close a application when the Escape Key is pressed. Here is a version that works. The changes from yours: - Bind Escape, not Key-Escape - Bind the key to the root, not the frame - Define a quit() method that

Re: Encodings and printing unicode

2005-03-14 Thread Kent Johnson
Fuzzyman wrote: How does the print statement decode unicode strings itis passed ? (By that I mean which encoding does it use). sys.stdout.encoding Under windows it doesn't appear to use defaultencoding. On my system the default encoding is ascii, yet the terminal encoding is latin1 (or cp1252 or

Re: RotatingFileHandler and logging config file

2005-03-15 Thread Kent Johnson
Rob Cranfill wrote: [BTW, has anyone else noticed that RotatingFileHandler isn't documented in the docs? All the other file handlers have at least a paragraph on their options, but nothing for RFH!] It is in the latest docs. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Python becoming less Lisp-like

2005-03-15 Thread Kent Johnson
Steven Bethard wrote: Bruno Desthuilliers wrote: class CommandMenuSelectionCallback: def __init__(self, key): self.key = key def __call__(self): print self.key Looks like Java. When was the last time you used Java? It has no support for using classes as callable objects.

When is a thread garbage collected?

2005-03-16 Thread Kent Johnson
If I create and start a thread without keeping a reference to the thread, when is the thread garbage collected? What I would like is for the thread to run to completion, then be GCed. I can't find anything in the docs that specifies this behavior; nor can I think of any other behaviour that

Re: Good use for Jython

2005-03-16 Thread Kent Johnson
Mike Wimpe wrote: Other than being used to wrap Java classes, what other real use is there for Jython being that Python has many other GUI toolkits available? Also, these toolkits like Tkinter are so much better for client usage (and faster) than Swing, so what would be the advantage for using

Re: I can do it in sed...

2005-03-17 Thread Kent Johnson
Kotlin Sam wrote: Also, I frequently use something like s/^[A-Z]/~/ to pre-pend a tilde or some other string to the beginning of the matched string. I know how to find the matched string, but I don't know how to change the beginning of it while still keeping the matched part. Something like

Re: list of unique non-subset sets

2005-03-17 Thread Kent Johnson
Raymond Hettinger wrote: [EMAIL PROTECTED] I have many set objects some of which can contain same group of object while others can be subset of the other. Given a list of sets, I need to get a list of unique sets such that non of the set is an subset of another or contain exactly the same members.

Re: MySQL problem

2005-03-18 Thread Kent Johnson
wes weston wrote: Dennis Lee Bieber wrote: Try neither, the recommended method is to let the execute() do the formatting... That way /it/ can apply the needed quoting of arguments based upon the type of the data. cursor.execute(insert into produkt1 (MyNumber) values (%d), (MyValue)) Dennis,

Re: Simple XML-to-Python conversion

2005-03-19 Thread Kent Johnson
[EMAIL PROTECTED] wrote: I've tried xmltramp and element tree, but these tools aren't what I had in mind. What I'm looking to use are basic structures such as: root.path root.input.method root.input.filename root.output.filename I haven't used xmltramp but it seems to allow this style of

Re: Pre-PEP: Dictionary accumulator methods

2005-03-19 Thread Kent Johnson
Bengt Richter wrote: On Sat, 19 Mar 2005 01:24:57 GMT, Raymond Hettinger [EMAIL PROTECTED] wrote: I would like to get everyone's thoughts on two new dictionary methods: def count(self, value, qty=1): try: self[key] += qty except KeyError:

Re: Pre-PEP: Dictionary accumulator methods

2005-03-19 Thread Kent Johnson
Brian van den Broek wrote: Raymond Hettinger said unto the world upon 2005-03-18 20:24: I would like to get everyone's thoughts on two new dictionary methods: def appendlist(self, key, *values): try: self[key].extend(values) except KeyError:

Re: Overloaded Constructors?!?

2005-03-20 Thread Kent Johnson
[EMAIL PROTECTED] wrote: Hello NG, I am trying to port a useful class from wxWidgets (C++) to a pure Python/wxPython implementation. In the C++ source code, a unique class is initialized with 2 different methods (???). This is what it seems to me. I have this declarations: class

Re: Simple account program

2005-03-24 Thread Kent Johnson
Igorati wrote: ah thank you again. Anyone know of a good place to get information about TK inter. I am gonna try and make this program somewhat of a GUI. Thank you again. http://docs.python.org/lib/module-Tkinter.html http://www.pythonware.com/library/tkinter/introduction/index.htm

Re: string join() method

2005-03-24 Thread Kent Johnson
Derek Basch wrote: Can anyone tell me why this CGI code outputs a blank page? Maybe because it needs a blank line between the header and the body? self.output = [] self.setContentType(text/plain) ascii_temp.seek(0) self.output.extend(ascii_temp.read())

Re: Suggestions for a Java programmer

2005-03-24 Thread Kent Johnson
Ray wrote: Ville Vainio wrote: Regarding a Java programmer moving to Python, a lot of the mindset change is about the abundant use of built in data types of Python. So a Java programmer, when confronted with a problem, should think how can I solve this using lists, dicts and tuples? (and perhaps

Re: newbie help

2005-03-24 Thread Kent Johnson
[EMAIL PROTECTED] wrote: Here it is again. I did something like this. index is passed from the command line. def __getBuffer( index): if index == 1: buf1 = [None] * 512 print Buffer: %s % (buf1) return buf1 elif index == 2: buf2 = [None] * 512 print

Re: Grouping code by indentation - feature or ******?

2005-03-25 Thread Kent Johnson
Tim Tyler wrote: What do you guys think about Python's grouping of code via indentation? Is it good - perhaps because it saves space and eliminates keypresses? Or is it bad - perhaps because it makes program flow dependent on invisible, and unpronouncable characters - and results in more manual

Re: breaking up is hard to do

2005-03-25 Thread Kent Johnson
bbands wrote: For example I have a class named Indicators. If I cut it out and put it in a file call Ind.py then from Ind import Indicators the class can no longer see my globals. This is true even when the import occurs after the config file has been read and parsed. globals aren't all that

Re: breaking up is hard to do

2005-03-25 Thread Kent Johnson
bbands wrote: For example I have a class named Indicators. If I cut it out and put it in a file call Ind.py then from Ind import Indicators the class can no longer see my globals. This is true even when the import occurs after the config file has been read and parsed. globals aren't all that

Re: left padding zeroes on a string...

2005-03-25 Thread Kent Johnson
cjl wrote: Hey all: I want to convert strings (ex. '3', '32') to strings with left padded zeroes (ex. '003', '032') In Python 2.4 you can use rjust with the optional fill argument: '3'.rjust(3, '0') '003' In earlier versions you can define your own: def rjust(s, l, c): ... return ( c*l + s

Re: Python slogan, was Re: Grouping code by indentation - feature or ******?

2005-03-26 Thread Kent Johnson
Peter Otten wrote: Tim Roberts wrote: Or, paraphrasing Mark Twain, Python is the worst possible programming language, except for all the others. I've been trying to establish that a while ago, but would attribute it to Winston Churchill -- so I'm a little confused now. Can you provide the text

Re: Python slogan, was Re: Grouping code by indentation - feature or ******?

2005-03-26 Thread Kent Johnson
Peter Otten wrote: Skip Montanaro wrote: Or, paraphrasing Mark Twain, Python is the worst possible programming language, except for all the others. Google thinks it's Winston Churchill as well. I did come across a quote wiki: http://www.wikiquote.org/ Wikiquote is nice. I missed it

Re: Get document as normal text and not as binary data

2005-03-28 Thread Kent Johnson
Markus Franz wrote: Hi. I used urllib2 to load a html-document through http. But my problem is: The loaded contents are returned as binary data, that means that every character is displayed like lt, for example. How can I get the contents as normal text? My guess is the html is utf-8 encoded -

Re: Which is easier? Translating from C++ or from Java...

2005-03-28 Thread Kent Johnson
cjl wrote: Hey all: I'm working on a 'pure' python port of some existing software. Implementations of what I'm trying to accomplish are available (open source) in C++ and in Java. Which would be easier for me to use as a reference? I haven't touched C++ in a long time, my experience porting Java

Re: What's the best GUI toolkit in Python,Tkinter,wxPython,QT,GTK?

2005-03-30 Thread Kent Johnson
Fuzzyman wrote: Undoubtably Wax :-) Easier to learn than TKinter, with none of the limitations (it's built on top of wxPython). See http://zephyfalcon.org http://zephyrfalcon.org/labs/wax.html works better. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Optimisation Hints (dict processing and strings)

2005-03-30 Thread Kent Johnson
OPQ wrote: for (2): for k in hash.keys()[:]: # Note : Their may be a lot of keys here if len(hash[k])2: del hash[k] - use the dict.iter* methods to prevent building a list in memory. You shouldn't use these values directly to delete the entry as this could break the iterator: for key

Re: problem running the cgi module

2005-03-31 Thread Kent Johnson
chris patton wrote: Hi everyone. I'm trying to code an HTML file on my computer to make it work with the cgi module. For some reason I can't get it running. This is my HTML script: -- form method=post action=C:\chris_on_c\hacking\formprinter.py

Re: pre-PEP: Suite-Based Keywords

2005-04-15 Thread Kent Johnson
Brian Sabbey wrote: Here is a pre-PEP for what I call suite-based keyword arguments. The mechanism described here is intended to act as a complement to thunks. Please let me know what you think. Suite-Based Keyword Arguments - Passing complicated arguments to

Re: XML parsing per record

2005-04-16 Thread Kent Johnson
Willem Ligtenberg wrote: I want to parse a very large (2.4 gig) XML file (bioinformatics ofcourse :)) But I have no clue how to do that. Most things I see read the entire xml file at once. That isn't going to work here ofcourse. So I would like to parse a XML file one record at a time and then be

Re:

2005-04-16 Thread Kent Johnson
[EMAIL PROTECTED] wrote: All, I have been going through the manuals and not having much luck with the following code. This is basically an issue of giving 'split' multiple patterns to split a string. If it had an ignore case switch, the problem would be solved. Instead, I have to code the

Re: pydoc preference for triple double over triple single quotes -- anyreason?

2005-04-16 Thread Kent Johnson
Brian van den Broek wrote: Hi all, I'm posting partly so my problem and solution might be more easily found by google, and partly out of mere curiosity. I've just spent a frustrating bit of time figuring out why pydoc didn't extract a description from my module docstrings. Even though I had a

Re: Pattern Matching Given # of Characters and no String Input; useRegularExpressions?

2005-04-17 Thread Kent Johnson
tiissa wrote: Synonymous wrote: Can regular expressions compare file names to one another. It seems RE can only compare with input i give it, while I want it to compare amongst itself and give me matches if the first x characters are similiar. Do you have to use regular expressions? If you know

Re: sscanf needed

2005-04-17 Thread Kent Johnson
Uwe Mayer wrote: Hi, I've got a ISO 8601 formatted date-time string which I need to read into a datetime object. Something like this (adjust the format to suit): import datetime, time dt = datetime.datetime(*time.strptime(data, %Y-%m-%d %H:%M:%S)[:6]) Kent --

Re: Accessing multidimensional lists with an index list

2005-04-17 Thread Kent Johnson
Gabriel Birke wrote: Given the multidimensional list l: l = [ {'v1': 1, 'v2': 2}, [ {'v1':4, 'v2': 7}, {'v1': 9, 'v2': 86}, [ {'v1': 77, 'v2': 88}] ] ] I want to access specific items the indices of which are stored in another list. For now,

Re: pydoc preference for triple double over triple single quotes--anyreason?

2005-04-18 Thread Kent Johnson
Brian van den Broek wrote: Kent Johnson said unto the world upon 2005-04-17 16:17: Brian van den Broek wrote: Kent Johnson said unto the world upon 2005-04-16 16:41: Brian van den Broek wrote: I've just spent a frustrating bit of time figuring out why pydoc didn't extract a description from my

Re: Can a function be called within a function ?

2005-04-18 Thread Kent Johnson
Peter Moscatt wrote: Is it possible to write code and allow a function to be called within another like I have shown below ? Yes, of course. In fact you do it six times in the code below, to call open(), readline(), append(), close(), main() and populatelist(). Kent Pete def populatelist():

Re: uploading/streaming a file to a java servlet

2005-04-19 Thread Kent Johnson
Vasil Slavov wrote: I am working on a school project written in Python (using mod_python) and I need to upload a file to a java servlet. Here are the high-level instructions given by the servlet authors: - Open the file for reading. - Open an HTTP connection to the servlet and get the

Re: Update Label when Scale value changes

2005-04-19 Thread Kent Johnson
codecraig wrote: Yea that is what i needed. Can you recommend a good Tkinter site (or book, but preferably site) about learning Tkinter. I've tried: http://www.python.org/moin/TkInter http://www.pythonware.com/library/tkinter/introduction/ I also like

Re: Encoding Questions

2005-04-19 Thread Kent Johnson
[EMAIL PROTECTED] wrote: 1. I download a page in python using urllib and now want to convert and keep it as utf-8? I already know the original encoding of the page. What calls should I make to convert the encoding of the page to utf8? For example, let's say the page is encoded in gb2312 (simple

Re: XML parsing per record

2005-04-20 Thread Kent Johnson
Willem Ligtenberg wrote: Willem Ligtenberg [EMAIL PROTECTED] wrote: I want to parse a very large (2.4 gig) XML file (bioinformatics ofcourse :)) But I have no clue how to do that. Most things I see read the entire xml file at once. That isn't going to work here ofcourse. So I would like to parse a

Re: Python instances

2005-04-20 Thread Kent Johnson
[EMAIL PROTECTED] wrote: Guess i shouldn't think of the __init__(self) function as a constructor then. No, that's not it. You shouldn't think of variables defined outside of a method as instance variables. In Java for example you can write something like public class MyClass { private List

Re: Faster os.walk()

2005-04-20 Thread Kent Johnson
fuzzylollipop wrote: after extensive profiling I found out that the way that os.walk() is implemented it calls os.stat() on the dirs and files multiple times and that is where all the time is going. os.walk() is pretty simple, you could copy it and make your own version that calls os.stat() just

Re: Array of Chars to String

2005-04-20 Thread Kent Johnson
Michael Spencer wrote: Anyway, here are the revised timings... ... print shell.timefunc(func_translate1, Bob Carol Ted Alice * multiplier, 'adB') What is shell.timefunc? Thanks, Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Python instances

2005-04-21 Thread Kent Johnson
Bengt Richter wrote: The following shows nothing static anywhere, yet a class has been defined, an instance created, and __init__ called with initial value, and the value retrieved as an attribute of the returned instance, and it's all an expression. type('C', (), {'__init__': lambda

Re: Using Jython in Ant Build Process

2005-04-21 Thread Kent Johnson
Maurice LING wrote: I am looking for a way to use Jython in Ant build process. I have some pure Python scripts (not using any C extensions) that I'll like to incorporate into Java using Jython. I heard that this can be done but you can I set up Ant to do this? Sorry, I'm no expert with Ant. The

<    1   2   3   4   5   6   7   >