RE: Classes referencing each other

2006-11-06 Thread Ryan Ginstrom
o']: str_vals.append( str( obj ) ) print '\tconnections from:', str_vals ##### Output: object: A (A) connections from: ['B', 'C'] object: C (C) connections from: ['B'] object: B (B) connections from: ['A'] object: D (None) connections from: ['C'] Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: Python, Dutch, English, Chinese, Japanese, etc.

2007-06-04 Thread Ryan Ginstrom
Japanese programmers would probably prefer their programs to be accessible outside Japan, and poorly named variables are a much lower barrier to understanding than Japanese would be. Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: Obtaining hte currently running script under windows

2007-06-08 Thread Ryan Ginstrom
Regards, Ryan -- Ryan Ginstrom [EMAIL PROTECTED] http://ginstrom.com/ -- http://mail.python.org/mailman/listinfo/python-list

RE: win32com ppt embedded object

2007-07-10 Thread Ryan Ginstrom
om_error, details: log_error( "Exception getting shape text", details ) Regards, Ryan -- Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: testing with coverage.py problem

2007-07-16 Thread Ryan Ginstrom
.py (i.e. class inherited from > unittest.TestCase). How to do that with coverage.py? Where i > should put the code that runs the tests? The easiest way is probably by using nose http://somethingaboutorange.com/mrl/projects/nose/ In particular, check out the "--with-coverage" flag. Rega

RE: code packaging

2007-07-20 Thread Ryan Ginstrom
nd sends an email to the testers stating that a new version is ready, with a list of additions/improvements. Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: From D

2007-07-26 Thread Ryan Ginstrom
rscore idea from D, and I like it better than the "concatenation" idea, even though I agree that it is more consistent with Python's string-format rules. Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: Utilizing a raw IDispatch Pointer from Python

2007-07-31 Thread Ryan Ginstrom
automatically? If I understand you correctly, you can use client.Dispatch from win32com import client com_object = client.Dispatch(idispatch_pointer_from_cpp) Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: Using Regular Expresions to change .htm to .php in files

2007-08-26 Thread Ryan Ginstrom
if link.has_key("href") and not link["href"].startswith("http")] (4) Do straight string replacements on those links (no regex needed) (5) Save each html file to *.html.bak before changing Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: Parser Generator?

2007-08-26 Thread Ryan Ginstrom
apanese) before using PyParsing. Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: Parser Generator?

2007-08-26 Thread Ryan Ginstrom
> On Behalf Of Paul McGuire > > On Aug 26, 8:05 pm, "Ryan Ginstrom" <[EMAIL PROTECTED]> wrote: > > The only caveat being that since Chinese and Japanese scripts don't > > typically delimit "words" with spaces, I think you'd have >

RE: How to use os.putenv() ?

2007-08-29 Thread Ryan Ginstrom
return winreg.QueryValueEx(key, 'path')[0] finally: winreg.CloseKey(key) winreg.CloseKey(reg) ## Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: status of Programming by Contract (PEP 316)?

2007-08-30 Thread Ryan Ginstrom
ssembly-language hack). I personally found it neater having such code in unit tests, but obviously, it's a matter of preference. Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: Printing lists in columns

2007-09-05 Thread Ryan Ginstrom
04/pretty-printing-a-table-in-python/ Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: newbie: self.member syntax seems /really/ annoying

2007-09-12 Thread Ryan Ginstrom
ce of class instances much of the time. Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: newbie: self.member syntax seems /really/ annoying

2007-09-12 Thread Ryan Ginstrom
fine. In fact, for testability/reliability, they're preferred, because when a method twiddles some internal state, it's much harder to test. It's valuable to have a function that always gives output x for input y, with no side effects. That (to me) is the appeal of the funct

RE: Coming from Perl

2007-09-12 Thread Ryan Ginstrom
mplate = """ %(title)s %(content)s """ >>> print template % data Python Rocks! I heart Python >>> You might also want to check out string.Template (http://docs.python.org/lib/node40.html), or even move on to one of the many, many templating languages (Mako, Cheetah, Kid, etc.) Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: Setting stdout encoding

2007-09-13 Thread Ryan Ginstrom
in print >> out, nihongo UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128) >>> out = OutStreamEncoder(out, "utf-8") >>> print >> out, nihongo >>> val = out.getvalue() >>> print val.decode("utf-8") 日本語 >>> Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: Setting stdout encoding

2007-09-13 Thread Ryan Ginstrom
" if isinstance(obj, unicode): self.out.write(obj.encode(self.encoding)) else: self.out.write(obj) def __getattr__(self, attr): """Delegate everything but write to the stream""" return getattr(self.out, attr) Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: Python statements not forcing whitespace is messy?

2007-09-15 Thread Ryan Ginstrom
> On Behalf Of J. Cliff Dyer > On the other hand, this is just as bad: > > [ ( y ) for ( x , y ) in [ ( "foo" , 2 ) , ( "bar" , 4 ) ] if > "foo" in ( x ) ] I think that's allowed in order to recruit C/C++ programmers. Regards, Ryan Ginstrom

RE: lambda-funcs problem

2007-09-19 Thread Ryan Ginstrom
return x+i return adder >>> funcs = [make_adder(i) for i in xrange(10)] >>> print [func(10) for func in funcs] [10, 11, 12, 13, 14, 15, 16, 17, 18, 19] >>> Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: Test-driven development and code size

2007-09-26 Thread Ryan Ginstrom
see the benefits, you'll probably seem them as less onerous, of course. Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: Wrapper functions and arguments

2007-10-01 Thread Ryan Ginstrom
return wrapped x.append(wrapper(func)) >>> x[0](1, 2, 3) wrapped! 1 2 3 >>> x[1](1, 2) wrapped! 1 2 fruitbat >>> --- Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: interfacing Python interpreter with a VB6 frontend

2007-10-03 Thread Ryan Ginstrom
f text and then collect results of execution for display. win32com has demos of COM servers. -- Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: unit testing

2007-10-04 Thread Ryan Ginstrom
duce bugs in the development process, but their main benefits are making code more modular (writing for testing tends to reduce dependencies) and easier to modify (less fear in refactoring). Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: Entering username & password automatically using urllib.urlopen

2007-10-14 Thread Ryan Ginstrom
... browser['user'] = USERNAME browser['pass'] = PASSWORD browser.submit() # Content goodness follows... ## Of course, this assumes that the site doesn't use some kind of JavaScript trickery to prevent automation like the above. In that case, you'd have to use something like PAMIE

RE: Wrapping stdout in a codec

2007-10-21 Thread Ryan Ginstrom
ot;"Delegate everything but write to the stream""" return getattr(self.out, attr) You can wrap sys.stdout easily: sys.stdout = OutStreamEncoder(sys.stdout) The code, with unit tests: http://www.ginstrom.com/code/streamencode.zip Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: ignoring chinese characters parsing xml file

2007-10-22 Thread Ryan Ginstrom
x27;s a way: def strip_asian(text): """"Returns the Unicode string text, minus any Asian characters""" return u''.join([x for x in text if ord(x) < 0x3000]) Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: japanese encoding iso-2022-jp in python vs. perl

2007-10-23 Thread Ryan Ginstrom
-jp without problems. Another possible thing to look at is whether your Python output terminal can print Japanese OK. Does it choke when printing the string as Unicode? Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: list (range) syntax

2007-10-24 Thread Ryan Ginstrom
ke "the 4th through the 7th" and "the 4th to the 7th, inclusive" when one wants to be sure. At any rate, I also think that having range(1, 10) or a similar construct mean one to ten (inclusive ) is a bad idea. Ruby's philosophy is obviously different, which is probably fi

RE: Finding decorators in a file

2007-10-26 Thread Ryan Ginstrom
a function has two decorators? -- but I think the basic idea will work. Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: simple question on dictionary usage

2007-10-26 Thread Ryan Ginstrom
ord[key] Not much more concise, but another way: egt = dict((key, record[key]) for key in record if key.startswith('E')) Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: posting to a form with no form name

2007-11-01 Thread Ryan Ginstrom
#x27;] = "me" browser['password'] = "secret" browser.submit() Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: How to Create pyd by C#

2007-11-05 Thread Ryan Ginstrom
> On Behalf Of jane janet > I'm wondering how to create extension fill (.pyd) or anything > that seem like DLL file by C# language. If you are going to be using C#, I would suggest that you create an ordinary assembly, and call it via IronPython. Regards, Ryan Gins

RE: Catching and automating a win32 MessageBox

2007-11-08 Thread Ryan Ginstrom
h you can automate from Python. Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: VB6 frontend GUI with Python

2007-11-20 Thread Ryan Ginstrom
method on the COM server that says "submit text line" * The COM server examines the last line of text in the form's text box, and takes any necessary action, including: + Eval a line of interactive Python code + Write a result to the VB form's text box Do the above steps sound

RE: Equivalent of perl's Pod::Usage?

2007-12-10 Thread Ryan Ginstrom
with an error > """ > print >>sys.stderr, globals()['__doc__'] > print >>sys.stderr, error > sys.exit(1) argparse[1] also prints out very pretty usage for you. [1] http://argparse.python-hosting.com/ Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: tail a file (win)

2006-04-20 Thread Ryan Ginstrom
CreateFile CreateFileMapping MapViewOfFile I'm sorry, but I'm not a ctypes guru so can't tell you how you would accomplish this in python. (The C(++) code is fairly straightforward, however). --- Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

Hooking things up in GUI application

2006-04-24 Thread Ryan Ginstrom
generally handled through code generation and/or macros, but IMO these are brittle and ugly. So my question: Is there a Pythonic way to make these tedious hookups easier? --- Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: Counting elements in a list wildcard

2006-04-24 Thread Ryan Ginstrom
malize for string length using the following score function: def score( a, b ): "Calculates the similarity score of the two strings based on edit distance." high_len = max( len(a), len(b) ) return float( high_len - distance( a, b ) ) / float( high_len ) >>> for line in my_strings: ... if score( line, 'Susie' ) > .75: print line ... Susi -- Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: Hooking things up in GUI application

2006-04-25 Thread Ryan Ginstrom
y with the spacer layout concept. -- Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: Hooking things up in GUI application

2006-04-25 Thread Ryan Ginstrom
> Behalf Of sturlamolden > Ryan Ginstrom wrote: > > > Yes, I've tried something similar with wxGlade. > > But GLADE is not wxGlade :-) Yes, I'm just saying that I've done something similar to your example. In fact, wxCard also does this auto-generation o

RE: Look for a string on a file and get its line number

2008-01-08 Thread Ryan Ginstrom
t;>> for num, line in enumerate(open("/python25/readme.txt")): if "Guido" in line: print "Found Guido on line", num break Found Guido on line 1296 >>> Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: docstrings style question

2008-01-10 Thread Ryan Ginstrom
later "fix" code back to the buggy version Some of the things I use docstrings for: * Describe interface (inputs/outputs) * Sample usage I personally don't use doctests, but that's one more use of docstrings. Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: Win32com and Excel

2008-01-10 Thread Ryan Ginstrom
> On Behalf Of Mike P > Does anyone have any code that does something similar? My > guess is i have to do something like thefollowing to enable > python to read xl? I think that what you want is UsedRange for row in sheet.UsedRange.Value: ... Regards, Ryan Ginstr

RE: for loop without variable

2008-01-10 Thread Ryan Ginstrom
d also why has it not come up in this thread)? > I realize the topic has probably been beaten to death in > earlier thread(s), but does anyone have the short answer? data_out = [[] for item in data_in] Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: [OT] "Code Friendly" Blog?

2008-01-17 Thread Ryan Ginstrom
w it turns out: http://ginstrom.com/scribbles/2007/11/17/fixing-jis-mojibake-with-python/ [1] http://www.deanlee.cn/wordpress/code_highlighter_plugin_for_wordpress/ Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: Has Anyone Worked with Gene Expression Programming???????????????????????????

2008-01-30 Thread Ryan Ginstrom
lease don't ask > questions. It's not safe to know too much about this stuff. > One day, my son, you'll understand. You'll understand. The first rule of Gene Expression Programming is - you do not talk about Gene Expression Programming. Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: dict comprehension

2008-01-31 Thread Ryan Ginstrom
dict([(a, b) for a, b in zip(keys, values)]) >>> D {'a': 1, 'c': 3, 'b': 2} Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: Automating GUI interaction with Python

2008-02-20 Thread Ryan Ginstrom
cursor to and from specified screen coordinates, clicking, etc. > Thanks a lot. For Windows, try pyWinAuto http://pywinauto.openqa.org/ Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: Article of interest: Python pros/cons for the enterprise

2008-02-21 Thread Ryan Ginstrom
> languages. So, yes, your big company is likely to be safer > with newbie C++ programmers than with Python newbie programmers. The danger of memory leaks alone makes C++ a decidedly newbie-unfriendly language. Java I might go along with, but C++? Regards, Ryan Ginstrom (who learned C++ befo

RE: Article of interest: Python pros/cons for the enterprise

2008-02-23 Thread Ryan Ginstrom
ost of them came to Python for a reason. Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: Hyphenation module PyHyphen-0.3 released

2008-02-23 Thread Ryan Ginstrom
x27;t provide > the appropriate runtime, you would have to track that down. Here's another way. Go to /MinGW/lib/gcc/mingw32/3.4.2/spec, and modify the libgcc directive as follows: *libgcc: %{mthreads:-lmingwthrd} -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcr71 Regards, Ryan Ginstrom -- ht

RE: Unit testing Web applications

2008-03-05 Thread Ryan Ginstrom
code == 200, response.code def test_index_title(self): response = self.mech.open("http://honyaku-archive.org/";) assert self.mech.title().strip() == "Honyaku Archive :: Home", self.mech.title() Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: SV: Regarding coding style

2008-03-08 Thread Ryan Ginstrom
> On Behalf Of Grant Edwards > I think docstrings are a great idea. What's needed is a way > to document the signature that can't get out-of-sync with > what the fucntion really expects. Like doctests? (I know, smart-ass response) Regards, Ryan Ginstrom -- http://m

RE: any chance regular expressions are cached?

2008-03-09 Thread Ryan Ginstrom
pam spam spam spam spam spam spam >>> # strip leading/trailing space >>> text = " spam " >>> print text.lstrip() spam >>> print text.rstrip() spam >>> print text.strip() spam Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: Edit and continue?

2008-03-10 Thread Ryan Ginstrom
ng a lot easier. There are two angles of approach: "driving" the GUI automatically, and stubbing out/mocking the windowing methods so that you can test GUI components in a unit-testing framework. Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: Dispatch("Excel.Application") failed

2008-03-13 Thread Ryan Ginstrom
doesn't appear to have made it to the list) that the call to Dispatch on Excel will fail if the formula bar edit box is active. Just another idea. Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: Decode email subjects into unicode

2008-03-18 Thread Ryan Ginstrom
tions) I get the following output for your strings: Быстровыполнимо и малозатратно érdekeshibák Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: Duplicating list of lists [newbie]

2008-03-23 Thread Ryan Ginstrom
oing as deep as possible? Or it can be > done only manually? I'd suggest checking out copy.deepcopy. >>> a = [1, [1, 2, 3], 2] >>> b = a[:] >>> a[1][2] = 'spam' >>> b [1, [1, 2, 'spam'], 2] >>> from copy import deepcopy >>>

RE: Testing for an empty dictionary in Python

2008-03-23 Thread Ryan Ginstrom
ict_is_empty(D): for k in D: return False return True >>> dict_is_empty(dict(a=1)) False >>> dict_is_empty({}) True Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: Breaking the barrier of a broken paradigm... part 1

2008-03-24 Thread Ryan Ginstrom
bout for starters: import os for line in open("/etc/passwd"): user, _pwd = line.split(":") user_home = os.path.join("/expirt/home", user) > try: > os.makedirs('usrHome' ) > except Exception, e: > pr

RE: Breaking the barrier of a broken paradigm... part 1

2008-03-25 Thread Ryan Ginstrom
is has the benefit of allowing me to test create_user_dirs without touching the file system (by passing in a list of lines). Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: unittest: Calling tests in liner number order

2008-05-25 Thread Ryan Ginstrom
_ones() Now you do something like run the unit tests every time a file is saved, and run the whole shebang nightly and every time a build is performed. Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: [Business apps for Windows] Good grid + calendar, etc.?

2008-06-01 Thread Ryan Ginstrom
ess plugging, I wrote an overview of Python GUI platforms for Windows a month or two ago: http://ginstrom.com/scribbles/2008/02/26/python-gui-programming-platforms-fo r-windows/ For your stated needs, I'd advise checking out IronPython or Python.NET (which allow use of .NET GUI libraries). Re

RE: [Business apps for Windows] Good grid + calendar, etc.?

2008-06-01 Thread Ryan Ginstrom
Drag & Drop. I've yet to deploy this approach in an application, but from my prototypes I'm liking it. Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: [Business apps for Windows] Good grid + calendar, etc.?

2008-06-01 Thread Ryan Ginstrom
te the same. Also, using COM you can manipulate the DOM from Python, removing the need for AJAX. In that case, your only need for JavaScript would be for prebuilt library functionality (assuming you like Python better than JavaScript). Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: Build complete, now I just need to "install" it...

2008-03-30 Thread Ryan Ginstrom
ficient to edit the specs (e.g. in C:\MinGW\lib\gcc\mingw32\3.4.2) like so: *libgcc: %{mthreads:-lmingwthrd} -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcr71 And tell distutils to use mingw, by putting this in lib/distutils/distutils.cfg: [build] compiler=mingw32 [build_ext] compiler=mingw32 Reg

RE: Automatically fill in forms on line

2008-03-31 Thread Ryan Ginstrom
write code for step 2, 4 and 5. I suggest looking at mechanize: http://wwwsearch.sourceforge.net/mechanize/ If you're going to do this frequently, you also might want to check out the site's policy on robots. Mechanize does have a function to automatically handle a site's robots

RE: Copy Stdout to string

2008-04-01 Thread Ryan Ginstrom
bj): """Writes obj to the output stream, storing it to a buffer as well""" self.out.write(obj) self.buffer.write(obj) def getvalue(self): """Retrieves the buffer value""" return

RE: ANN: pry unit testing framework

2008-04-06 Thread Ryan Ginstrom
s sophisticated options. Thus it appears that the potential user base is rather small... Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: Splitting MainWindow Class over several modules.

2008-04-16 Thread Ryan Ginstrom
lay code in a > separate file and imported them into my main program. There are also several signaling techniques that make it easy to separate the GUI logic from the message-processing logic. Or you could simply have a controller class that instantiates the GUI class and registers itself as the

RE: firefox add-on to grab python code handily?

2008-05-10 Thread Ryan Ginstrom
many people would actually use it. Not that I'm going to implement it, but it would be really neat to tie something together with codepad[1] [1] http://codepad.org/ (With the site owner's permission, of course!) Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: Registration Code

2006-04-04 Thread Ryan Ginstrom
g legitimate users. And of course, it would enable cross-platform (commercial) use of your application. A variation of this strategy is the subscription model. Regards, Ryan --- Ryan Ginstrom http://ginstrom.com -- http://mail.python.org/mailman/listinfo/python-list

Framework/module for generating HTML documentation

2006-04-04 Thread Ryan Ginstrom
from scratch, but if this has been tackled before (as I suspect it has), I'd like to stand on those developers' shoulders . Regards, Ryan --- Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list

RE: Using PythonWin32 to copy text to Windoze Clipboard for Unix-stylerandom .sig rotator?

2006-04-06 Thread Ryan Ginstrom
to type the text in directly. Another (much more ambitious) project would be to create a private clipboard, save the current clipboard contents there, and then swap them back in when you are done. Regards, Ryan --- Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list