Re: nested functions

2006-06-15 Thread Kent Johnson
FAST 0 (h) 12 RETURN_VALUE Thanks Fredrik! Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: unittest behaving oddly

2006-06-20 Thread Mike Kent
David Vincent wrote: > > import unittest > > > > class IntegerArithmenticTestCase(unittest.TestCase): > > def testAdd(self): ## test method names begin 'test*' > > assertEquals((1 + 2), 3) > > assertEquals(0 + 1, 1) assertEquals is a member function, inherited from unittest.T

Re: Standard Yes / No Windows Dialog box creation

2006-06-21 Thread Kent Johnson
[EMAIL PROTECTED] wrote: > I found a way to create "Open File" or "Open Folder" windows dialog > boxes, but not to create an easier Yes / No dialog box... > Maybe someone has a solution for this? Maybe you would like EasyGui http://www.ferg.org/easygui/ Kent -- h

Re: List Manipulation

2006-07-04 Thread Mike Kent
Roman wrote: > I would appreciate it if somebody could tell me where I went wrong in > the following snipet: > > When I run I get no result > > cnt = 0 > p=[] > reader = csv.reader(file("f:\webserver\inp.txt"), dialect="excel", > quotechar="'", delimiter='\t') > for line in

Re: List Manipulation

2006-07-04 Thread Mike Kent
Roman wrote: > Thanks for your help > > My intention is to create matrix based on parsed csv file. So, I would > like to have a list of columns (which are also lists). > > I have made the following changes and it still doesn't work. > > > cnt = 0 > p=[[], [], [], [], [], [], [], [], [], [], []] >

Re: Easier way to save result of a function?

2006-07-04 Thread Mike Kent
James Mitchelhill wrote: > Sorry for the clunky subject line - I have a feeling that not knowing > the proper terms for this is part of my problem. > > I'm trying to write a class that analyses some data. I only want it to > do as much work as necessary, so it saves method results to a > dictionary

Re: 2 problems

2006-07-07 Thread Mike Kent
[EMAIL PROTECTED] wrote: > Hello,Im using Python 2.4.2 and I'm starting a few very basic > programs,but theres two problems I've not found the answers for. > My first problem is I need code that will count the number of letters > in a string and return that number to a variable. >>> s = "hello" >

Re: Python newbie with a problem writing files

2006-09-03 Thread Mike Kent
> feed_list = open("feed_listing.conf","r") What could it be about the above line that means "Open this file for READ ONLY"? -- http://mail.python.org/mailman/listinfo/python-list

Re: Looking for the Perfect Editor

2006-09-10 Thread Kent Johnson
le Init fldr: $FileDir regex to match output: ^.*"([^"]+)", *line ([0-9]+) with File: 1, Line: 2 Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Looking for the Perfect Editor

2006-09-10 Thread Kent Johnson
ad of IDLE? You're kidding, right? Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Looking for the Perfect Editor

2006-09-11 Thread Kent Johnson
Dick Moores wrote: > At 06:30 PM 9/10/2006, Kent Johnson wrote: >> Dick Moores wrote: >>> Also, why do you use TextPad instead of IDLE? >> You're kidding, right? > > No. Tell me, please. Macros? Comparing files? What else? OK...please, no one interpret this as

Re: efficient text file search.

2006-09-11 Thread Kent Johnson
noro wrote: > Is there a more efficient method to find a string in a text file then: > > f=file('somefile') > for line in f: > if 'string' in line: > print 'FOUND' Probably better to read the whole file at once if it isn't too big: f = file('somefile') data = f.read() if 'string' in

Re: windev vs python SOS

2006-09-29 Thread Kent Johnson
[EMAIL PROTECTED] wrote: > Hi Stéphane, > > stéphane bard wrote: >> hello, my boss ask me to prefer windev to python. >> I have to argue > > First, no matter how good is Python, you should not desagree with your > boss. > Second, Windew is quite good and fun, you will love it. Yes, the boss is a

Re: preemptive OOP?

2006-09-30 Thread Kent Johnson
so clearly at work the difference between projects that practice YAGNI and those that are designed to meet any possible contingency. It's the difference between running with running shoes on or wet, muddy boots. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: a quickie: range - x

2006-11-30 Thread Kent Johnson
Steven D'Aprano wrote: > On Wed, 29 Nov 2006 19:42:16 -0800, rjtucke wrote: > >> I want an iterable from 0 to N except for element m (<=M). > x = range(m-1) + range(m+1, N) Should be range(m) + range(m+1, N) Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Functions, callable objects, and bound/unbound methods

2006-12-01 Thread Kent Johnson
gly, and a callable class is the Right Thing -- if there's a > way to actually make it work. If the only reason for a callable class is to save a single value (the original function), you could instead store it as an attribute of the wrapper function. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Functions, callable objects, and bound/unbound methods

2006-12-01 Thread Kent Johnson
gly, and a callable class is the Right Thing -- if there's a > way to actually make it work. If the only reason for a callable class is to save a single value (the original function), you could instead store it as an attribute of the wrapper function. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: reloading modules

2006-12-15 Thread Kent Johnson
;>> reload(main) > ### Execution Occurs ### If you edit music.py you will have to import music reload(music) to get the new music module, then reload(main) to run again. You could just type > python main.py at the command line each time you want to run, or use an editor that lets you run the program from within the editor. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Common Python Idioms

2006-12-15 Thread Kent Johnson
Fredrik Lundh wrote: > Stephen Eilert wrote: > >> I do think that, if it is faster, Python should translate >> "x.has_key(y)" to "y in x". > > http://svn.python.org/view/sandbox/trunk/2to3/fix_has_key.py?view=markup Seems to have moved to here: http://svn.python.org/view/sandbox/trunk/2to3/fixes

Re: One module per class, bad idea?

2006-12-22 Thread Kent Johnson
a module - but in general my major classes are each to a module. It does make the imports look funny - I tend to give the module the same name as the class, Java style, so I have from foo.bar.MyClass import MyClass but that is a minor point IMO. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: One module per class, bad idea?

2006-12-25 Thread Kent Johnson
Carl Banks wrote: > Kent Johnson wrote: >> Carl Banks wrote: >>> Now, I think this is the best way to use modules, but you don't need to >>> use modules to do get higher-level organization; you could use packages >>> instead. It's a pain if you'

Re: Slowdown in Jython

2006-12-29 Thread Kent Johnson
s Task Manager or the equivalent. Jython is a Java application and you can increase the max heap available the same as for other java apps, using the command line switch -Xmx, e.g. -Xmx512m to set the max heap to 512 megabytes. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Some basic newbie questions...

2007-01-02 Thread Kent Johnson
ds-for-some-functionality-e-g-list-index-but-functions-for-other-e-g-len-list.htm Kent -- http://mail.python.org/mailman/listinfo/python-list

Filename encoding on XP

2007-01-02 Thread kent sin
What encoding does the NTFS store the filename? I got some downloaded files, some with Chinese filename, I can not backup them to CD because the name is not accepted. I use walk, then print the filename, there are some ? in it, but some Chinese characters were display with no problem. I suspect t

Re: newbie: working iwth list of tuples

2006-01-29 Thread Kent Johnson
e to do it in a more > 'functional' style (executing a database query by using map, reduce, > filter, etc. You might be interested in a similar attempt: http://www.jtauber.com/relational_python Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: dynamic class instantiation

2006-01-30 Thread Kent Johnson
efinition of page is in my_objects.py, and that file is on the Python search path, you can use import my_module cls = getattr(my_module, 'path') instance = cls() to create an instance of my_module.path. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Fuzzy Lookups

2006-01-31 Thread Kent Johnson
idea is then applied recursively to the pieces of the sequences to the left and to the right of the matching subsequence. So no, it doesn't seem to be using Levenshtein distance. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: dynamic class instantiation

2006-02-02 Thread Kent Johnson
: self.name = None self.caption = None self.functions = [] With the above definitions, an equivalent class is created by calling page = classFactory( 'page', { 'name' : None, 'caption': None, 'functions' : []} ) Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: locals() and dictionaries

2006-02-02 Thread Kent Johnson
with a > work-around (I'm getting pretty good at this one :), so my question > stands: > > is it possible to access the individual members of a dictionary using % > locals() when creating a string? You might want to use a more powerful templating engine, for example http://c

Re: rexec in jython??

2006-02-06 Thread Kent Johnson
in or long integer division yields an integer of the same type; the result is that of mathematical division with the `floor' function applied to the result." so this seems to be intentional. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: fairly large webapp: from Java to Python. experiences?

2006-02-06 Thread Kent Johnson
In my experience the original point is valid - Python is usually (always?) more concise than equivalent Java code, and often dramatically so. Python makes common operations easy; Java sometimes seems to go out of its way to make them awkward. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Learning Python

2006-02-06 Thread Kent Johnson
Many beginners' tutorials listed here: http://wiki.python.org/moin/BeginnersGuide/NonProgrammers Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: a question regarding call-by-reference

2006-02-06 Thread Kent Johnson
to the list variable it just modifies the local > (to the function) name space, and that those changes aren't reflected > in the list in the original name space. Try list[:] = response.get('args') this will change the value of the list passed in. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: UnboundMethodType and MethodType

2006-02-08 Thread Kent Johnson
you didn't bind B.bar and b.bar to anything so the id was reused. >>> class B(object): ... def bar(self): pass ... >>> Bbar = B.bar >>> bbar = B().bar >>> Bbar >>> bbar > >>> id(Bbar) 10751312 >>> id(bbar) 10736624 >>> Bbar is bbar False Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Jython inherit from Java class

2006-02-08 Thread Kent Johnson
same way...) You might get the behaviour you want if you put the line import sys fit.FitServer.main(sys.argv) at the end of your file. This will run the main() function of the Java class. Kent > > I think this is because I do not understand the jython mechanism for > inheritance

Re: module with __call__ defined is not callable?

2006-02-09 Thread Kent Johnson
appens. IIUC type.__call__ implements the standard class creation calling __new__ and __init__. Kent -- http://mail.python.org/mailman/listinfo/python-list

super(...).__init__() vs Base.__init__(self)

2006-02-09 Thread Kent Johnson
e __init__(). Any other opinions? Any consensus about the "best" way to do this? BTW I understand what super() does, I know why the original code is broken, I'm not asking for help with that. I'm wondering what others think best practices are. Thanks, Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: line wrapping problem

2006-02-09 Thread Kent Johnson
mytextfile, '\n' will print two newlines, one explicit and one implicit in the print. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Finding the public callables of self

2006-02-09 Thread Kent Johnson
h('_') and callable(getattr(self, s)) ] At first I thought self.__dict__ would do it, but callable methods > seem to be excluded so I had to resort to dir, and deal with the > strings it gives me. The callables are attributes of the class and its base classes, not of self. self.__d

Re: Too Many if Statements?

2006-02-10 Thread Kent Johnson
ing module. A single log entry can be written to multiple destinations based on level or source of the entry. The distribution of log entries is controlled by the logging configuration which can be stored in a text file if you like. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Jython inherit from Java class

2006-02-10 Thread Kent Johnson
yObject message) { > Looks like something in the Jython core causes the problem > (org\python\core\Py.java) any Ideas what I can do? I think jythonc is not compatible with Java 1.5, try compiling with 1.4. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Jython inherit from Java class

2006-02-11 Thread Kent Johnson
Frank LaFond wrote: > Jython 2.2 Alpha 1 supports Java 1.5 It is also buggy and IIRC has a broken jythonc which is what the OP is trying to use. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Jython inherit from Java class

2006-02-11 Thread Kent Johnson
ruct and that this implementation path would always be > so slow. On the other hand would a 100% Jython solution be faster? Inheritance from Java works well and I have never seen performance problems like this. Java JUnit uses introspection to find test methods so it won't find methods

Re: Jython inherit from Java class

2006-02-11 Thread Kent Johnson
Mark Fink wrote: > Alan, Kent, many thanks this really helped! > But there is still a problem I guess with inheritance. I use the java > testsuit supplied with the original to test the server. If I use the > Java FitServer the testsuite can be completed. I commented everything > ou

Re: Jython socket typecasting problems

2006-02-12 Thread Kent Johnson
uot;", line 1, in ? File "C:\Downloads\Java\jython-2.1\Lib\socket.py", line 135, in connect TypeError: java.net.Socket(): 1st arg can't be coerced to java.net.InetAddress or String Note it complains about the first arg; this may well be your error. In general Python does not coerce argumentt types for you. Jython will translate between Java and Python types but it won't go as far as converting a String to an int. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Can I get the 8bit-string representation of any unicode string

2006-02-12 Thread Kent Johnson
x27;. Likely candidates are b.encode('utf-8') b.encode('utf_16_be') b.encode('utf_16_le') Kent > > Suppose I get a unicode string: > a = u'\xc8\xce\xcf\xcd\xc6\xeb'; > then, by > a.encode('latin-1'); > I can get the 8bit-string re

Re: Python equivilant to msgbox()

2006-02-12 Thread Kent Johnson
a file open browser box as well? Take a look at EasyGUI: http://www.ferg.org/easygui/ Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Jython inherit from Java class

2006-02-13 Thread Kent Johnson
Mark Fink wrote: > Hi Kent, > many thanks for your help! In the meantime I received my "Jython > Essentials" book and hope that I have much fewer questions in the near > future. > One last question for this thread. I tried to inherit from a Java class > and override on

Re: Jython socket typecasting problems

2006-02-13 Thread Kent Johnson
g as explicit typecasting. What to do? The problem is that the second arg is not an int. The second problem is that the error message errorneously points to the first arg. See my earlier post. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: readlines and break apart based on letters

2006-02-13 Thread Kent Johnson
rtilley wrote: > Hi, > > While trying to better understand security descriptors on Windows. I've > been examining text-based security descriptors. I have the security > descriptors on individual lines stored in a text file. I want to break > these lines apart based on owner, group, dacl and sac

Re: 88k regex = RuntimeError

2006-02-14 Thread Kent Johnson
jodawi wrote: > I need to find a bunch of C function declarations by searching > thousands of source or html files for thousands of known function > names. My initial simple approach was to do this: > > rxAllSupported = re.compile(r"\b(" + "|".join(gAllSupported) + r")\b") > # giving a regex of

Re: Embedding an Application in a Web browser

2006-02-15 Thread Kent Johnson
paron wrote: > I forgot -- I like the idea of Kerrigell, too. It runs on top of > CherryPy Karrigell is independent of CherryPy, it has it's own web server built in. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Code organization

2006-02-15 Thread Kent Johnson
imports module in A). If you follow this rule your packages will be more testable and reusable. The alternative tends to devolve into everything-depends-on-everything-else which makes testing harder and reuse nearly impossible. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Best way of finding terminal width/height?

2006-02-15 Thread Kent Johnson
Grant Edwards wrote: > I've got no complaints about the way things work, I was just > going to suggest changing the documentation to correctly > describe the way things work. Too mundane a solution? Submit a patch, it's quick and easy and fun: http://docs.python.org/about.

Re: Which is faster? (if not b in m) or (if m.count(b) > 0)

2006-02-15 Thread Kent Johnson
st = range(1000)" "lst.count(1001) > 1" 1 loops, best of 3: 55.5 usec per loop D:\>python -m timeit -s "lst = range(100)" "lst.count(-1) > 1" 10 loops, best of 3: 62.2 msec per loop D:\>python -m timeit -s "lst = range(100)" &

Re: how to get function names from the file

2006-02-15 Thread Kent Johnson
s=('printFoo', 'printFOO') for function in functions: globals()[function]() If the functions are in a 'functions' module: funcs=('printFoo', 'printFOO') for function in funcs: getattr(functions, function)() Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Jython Pythonpath question

2006-02-21 Thread Kent Johnson
hat > "D:\AUT_TEST\workspace\JyFIT" should be included in the pythonpath but > it does not work. Nor does it work to include this path in the java > classpath. Any idea whats wrong? Do you have a file D:\AUT_TEST\workspace\JyFIT\testutil\__init__.py ? Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Module question

2006-02-21 Thread Kent Johnson
program does, but try to identify code that does the actual work and put it in separate modules that implement a data model or business logic for the program. These modules should be independent of Tkinter. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: May i customize basic operator (such as 1==3)?

2006-02-22 Thread Kent Johnson
Thomas Heller wrote: > The standard unittest module can do this also: replace > calls to failUnless(a == b) with failUnlessEqual(a, b). or assertEquals(a, b) -- http://mail.python.org/mailman/listinfo/python-list

Re: Python CGI not working in Firefox but does in IE

2006-02-22 Thread Kent Johnson
2c shows how do do a redirect with HTTP headers. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: No

2006-02-22 Thread Kent Johnson
ut now i see this > is not correct. > > Now i need a script for uploading the files from MY pc and then use the > sendmail thingie. Any tips about that script? > google 'python cgi file upload' for many examples. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: reviews of unit test frameworks

2006-02-23 Thread Kent Johnson
kanchy kang wrote: > Is there any reviews/remarks on these frameworks? > nose, OOBTest,testosterone, py.test, Sancho. http://agiletesting.blogspot.com/2005/02/articles-and-tutorials.html -- http://mail.python.org/mailman/listinfo/python-list

Re: why don't many test frameworks support file-output?

2006-02-23 Thread Kent Johnson
kanchy kang wrote: > i browsed the following frameworks briefly: nose, OOBTest, > testosterone, py.test, Sancho ... and found out they do support > imediate screen-output only. unittest.TextTestRunner() has an optional stream argument that would let you output to a file. Kent

Re: No (and a meaningless subject here too!)

2006-02-23 Thread Kent Johnson
Gaz wrote: > Aye, but i dont need to run an FTP daemon every time i want to upload > an image to Imageshack or any other website. Did you google 'python cgi file upload' yet? Several people have pointed you to an answer that doesn't use FTP. -- http://mail.python.org/mailman/listinfo/python-list

Re: Unexpected timing results

2006-02-23 Thread Kent Johnson
the cost of getting the time in the second call. On my computer with Python 2.4: D:\Projects\CB>python -m timeit -s "import time;timer=time.time" "t=timer()" 100 loops, best of 3: 0.498 usec per loop which is almost exactly the same as the difference between timer1() and timer2() on my machine: timer1 0.3094278 timer2 0.812000274658 using Python 2.4.2 on Win2k. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: need help regarding compilation

2006-02-23 Thread Kent Johnson
ava 1.4, or just run the class in the jython interpreter without compiling it first. For simple examples like this you don't need to compile, just run it with jython factor.py Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: How would you open this file?

2006-02-23 Thread Kent Johnson
it contains a file object, not a string. Maybe call it f instead. ('file' is also a bad name because it is the name of a Python built-in function.) Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: What's up with this code?

2006-02-23 Thread Kent Johnson
low. Current success is nearly 4x speedup, and now it seems > to me that decimals are the bottleneck. Is anybody working on C version > of decimals? Is it a really hard work? (I am thinking about > re-implementing decimals in C by myself) Maybe gmpy would help? http://gmpy.so

Re: A C-like if statement

2006-02-24 Thread Kent Johnson
ontains: import sys sys.ps1 = ' >>> ' sys.ps2 = ' ... ' Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: problem(s) with import from parent dir: "from ../brave.py import sir_robin"

2006-02-24 Thread Kent Johnson
nice > ImportError: No module named raw2nice_def.py Maybe it will work without the .py extension which is the correct form for an import (and what worked from the command line). Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: a little more help with python server-side scripting

2006-02-24 Thread Kent Johnson
t; with ASP.NET), instead of writing my code in Python. Is that not the case? See http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B276494 The last example on this page is exactly what you have been asking for. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: a little more help with python server-side scripting

2006-02-24 Thread Kent Johnson
John Salerno wrote: > Kent Johnson wrote: > >> John Salerno wrote: >> >>> Magnus Lycka wrote: >>> >>>> The other option is ASP. You have been given information about >>>> that already. Be aware that ASP does not imply VBScript. You can &

Re: Playing with modules

2006-02-25 Thread Kent Johnson
to some part of cassidy. > > But I was wondering whether I could fool or "backend" the normal import > mechanism. Even in Java, I can write my own class loader which can > quick compile Java snippets and load the anonymous byte code. See http://www.python.org/doc/2.3/whatsnew/section-pep302.html Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: unicode question

2006-02-25 Thread Kent Johnson
eplace('abc \xff\xe8 def') > u'abc \\xff\\xe8 def' >>> s='abc \xff\xe8 def' >>> s.encode('string_escape') 'abc \\xff\\xe8 def' >>> unicode(s.encode('string_escape')) u'abc \\xff\\xe8 def' Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Import in a separate thread

2006-02-25 Thread Kent Johnson
programs, where importing java packages can be noticably slow. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Is Python a Zen language?

2006-02-25 Thread Kent Johnson
I don't think anyone claims it leads to computational satori - it's more an attitude of "try it, you'll like it!". Using Python does seem to spoil people - I for one hate to code in Java now. Maybe "bliss" is a better word for it than "satori". Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: How to send an email with non-ascii characters in Python

2006-02-25 Thread Kent Johnson
Gabriel B. wrote: > what does a string became when it's decoded? > > I mean, it must be encoded in something, right? Unicode, for encodings like latin-1 or utf-8. A few special cases like str.decode('string_escape') yield byte strings again. Kent -- http://mail.pyt

Re: sort one list using the values from another list

2006-02-26 Thread Kent Johnson
of 3: 6.29 usec per loop D:\Projects\CB>python -m timeit -s "A=['hello','there','this','that'];B=[3,4,2,5]" "[a for b,a in sorted(zip(B,A))]" 10 loops, best of 3: 5.53 usec per loop (I'm bored this morning :-) There's probably a clever way to do it using the key parameter to sort but I can't think of it... > > The sort method on lists does in-place sorting. Is there a way to do > what I want here? The example above does not sort in place, if you want it to be in place use A[:] = [a for b,a in sorted(zip(B,A))] Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Coding Problem (arbitrary thread sych)

2006-02-26 Thread Kent Johnson
r patter in The Little Book of Semaphores: http://greenteapress.com/semaphores/ It requires that you know in advance how many threads need to rendezvous so you will have to preprocess your args a little. Kent -- http://mail.python.org/mailman/listinfo/python-list

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

2006-02-26 Thread Kent Johnson
al: def getText(nodelist): global colorIndex for str in strings: print colors[colorIndex % colors.length] colorIndex += 1 Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: ls files --> list packer

2006-02-26 Thread Kent Johnson
all else fails try the index: http://docs.python.org/lib/genindex.html > > how do i either grab the full path or append it later ... Use os.path.join(): base = '/some/useful/path' for f in os.listdir(base): full_path_to_file = os.path.join(base, f) Kent -- http://mail.python.or

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

2006-02-27 Thread Kent Johnson
6:'B', 56:'C'} >>> dict((key, dict2[value]) for key, value in dict1.iteritems()) {1: 'A', 2: 'B', 4: 'C'} Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Waiting for Connection

2006-02-27 Thread Kent Johnson
ve you have to run the socket in a separate thread; this recipe may give you some help though it may be more complex than you need: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/82965 Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: different ways to strip strings

2006-02-27 Thread Kent Johnson
ll this method, you have to provide the instance as the first argument: >>> f=spam.ham >>> f(s, 'Ha!') Ha! So... s.strip() gets a bound method object from the class and calls it with no additional argument. str.strip(s) gets an unbound method object from the class and calls it, passing a class instance as the first argument. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: different ways to strip strings

2006-02-27 Thread Kent Johnson
n the string module. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: type = "instance" instead of "dict"

2006-02-27 Thread Kent Johnson
you can still use for k in myDictionary.keys() There is also UserDict.IterableUserDict which does support iteration. I don't think there is much reason to use UserDict in modern Python as dict can be subclassed. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: type = "instance" instead of "dict"

2006-02-27 Thread Kent Johnson
AttributeError: Dict instance has no > attribute 'itervalues' What version of Python are you using? itervalues() is in Python 2.2 and later. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: sort one list using the values from another list

2006-02-27 Thread Kent Johnson
und `_' is a valid variable name. So I don't know it is a just > a plain variable or like something pattern matching in Haskell. _ is just a plain variable name in Python. It is sometimes when a variable is needed to receive a value that won't be used. So your example was correct

Re: Fetching the Return results of a spawned Thread

2006-02-28 Thread Kent Johnson
7 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/435883 Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Thread Question

2006-02-28 Thread Kent Johnson
x usage you may want a class. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: error: argument after ** must be a dictionary

2006-03-01 Thread Kent Johnson
s): > threading.Thread(target=self.blah, >*args, >**kwargs).start() No. threading.Thread() doesn't use *args, **kwargs, it uses explicit named parameters. Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: in need of some sorting help

2006-03-02 Thread Kent Johnson
place it will affect the subsequent walk. So you could use for base, dirs, walk_files in os.walk(root): dirs.sort(key=str.lower) # note no need for lambda walk_files.sort(key=str.lower) # etc Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Proper class initialization

2006-03-02 Thread Kent Johnson
e(10)) I think you should call the superclass __init__ as well: class __metaclass__(type): def __init__(cls, name, bases, classdict): super(__metaclass__, cls).__init__(name, bases, classdict) cls.sum = sum(xrange(10)) Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: setattr question

2006-03-02 Thread Kent Johnson
gt; docs, and I suppose I was curious how to do the same sort of thing > without 'apply'. Apply has been replaced by 'extended call syntax', that is why it is deprecated. Instead of return apply(self._function,_args,_kargs) write return self._function(*_a

Re: how to overload sqrt in a module?

2006-03-02 Thread Kent Johnson
th in the module that uses it. Imports in one module don't (in general) affect the variables available in another module. module_f.py from math import sqrt # more explicit than from math import * def f(x): """ Compute sqrt of x """ return sqrt(x) Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: in need of some sorting help

2006-03-03 Thread Kent Johnson
nction that returns a tuple of the two values you want to sort on: def make_key(f): return (os.path.dirname(f), f.lower()) files.sort(key=make_key) Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: object's list index

2006-03-03 Thread Kent Johnson
if item is o: return i raise ValueError, "%s not in list" % o If you just want the index available inside the loop, this replaces your original loop: for i, object in enumerate(lst): print i Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Convert dictionary to HTTP POST

2006-03-03 Thread Kent Johnson
mlentitydefs&rnum=2#fce6c2f6c3d46e9c Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Package organization: where to put 'common' modules?

2006-03-04 Thread Kent Johnson
above. What I do is run always from the base directory (violates your first requirement). I make a util package to hold commonly used code. Then B and D both use from util import foo In Python 2.5 you will be able to say (in D, for example) from ..util import foo http://www.python.org/peps/pep-0328.html Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: spliting on ":"

2006-03-04 Thread Kent Johnson
yy > yyy > yyy > > > yyy That's not what I get: In [2]: data='''xxx.xxx.xxx.xxx:yyy ...: xxx.xxx.xxx.xxx:yyy ...: xxx.xxx.xxx.xxx:yyy ...: xxx.xxx.xxx.xxx ...: xxx.xxx.xxx.xxx ...: xxx.xxx.xxx.xxx:yyy'''.splitlines() In [3]: for line in data: ...: print line.split(':')[-1] ...: ...: yyy yyy yyy xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx yyy Kent -- http://mail.python.org/mailman/listinfo/python-list

<    1   2   3   4   5   6   7   8   >