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
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
Regards,
Ryan
--
Ryan Ginstrom
[EMAIL PROTECTED]
http://ginstrom.com/
--
http://mail.python.org/mailman/listinfo/python-list
om_error, details:
log_error( "Exception getting shape text", details )
Regards,
Ryan
--
Ryan Ginstrom
--
http://mail.python.org/mailman/listinfo/python-list
.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
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
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
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
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
apanese) before using PyParsing.
Regards,
Ryan Ginstrom
--
http://mail.python.org/mailman/listinfo/python-list
> 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
>
return winreg.QueryValueEx(key,
'path')[0]
finally:
winreg.CloseKey(key)
winreg.CloseKey(reg)
##
Regards,
Ryan Ginstrom
--
http://mail.python.org/mailman/listinfo/python-list
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
04/pretty-printing-a-table-in-python/
Regards,
Ryan Ginstrom
--
http://mail.python.org/mailman/listinfo/python-list
ce of class
instances much of the time.
Regards,
Ryan Ginstrom
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
"
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
> 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
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
see the benefits, you'll probably seem them as less onerous,
of course.
Regards,
Ryan Ginstrom
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
...
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
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
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
-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
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
a function has
two decorators? -- but I think the basic idea will work.
Regards,
Ryan Ginstrom
--
http://mail.python.org/mailman/listinfo/python-list
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
#x27;] = "me"
browser['password'] = "secret"
browser.submit()
Regards,
Ryan Ginstrom
--
http://mail.python.org/mailman/listinfo/python-list
> 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
h you can automate from Python.
Regards,
Ryan Ginstrom
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
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
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
y with the spacer layout concept.
--
Regards,
Ryan Ginstrom
--
http://mail.python.org/mailman/listinfo/python-list
> 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
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
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
> 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
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
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
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
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
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
> 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
ost of
them came to Python for a reason.
Regards,
Ryan Ginstrom
--
http://mail.python.org/mailman/listinfo/python-list
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
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
> 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
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
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
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
tions)
I get the following output for your strings:
Быстровыполнимо и малозатратно
érdekeshibák
Regards,
Ryan Ginstrom
--
http://mail.python.org/mailman/listinfo/python-list
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
>>>
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
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
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
_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
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
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
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
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
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
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
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
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
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
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
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
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
76 matches
Mail list logo