On Aug 2, 7:34 pm, John Nagle wrote:
> >>> s2 = " HELLO THERE "
> >>> kresplit4 = re.compile(r'\W+', re.UNICODE)
> >>> kresplit4.split(s2)
> ['', 'HELLO', 'THERE', '']
>
> I still get empty strings.
>>> re.findall(r"\w+", " a b c ")
['a', 'b', 'c']
--
http://mail.python.org/mailman/list
$ python -c "import this"
--
http://mail.python.org/mailman/listinfo/python-list
On 10 Nov., 17:03, NickC wrote:
> Many thanks for the replies. getattr() works great:
You can get a little more versatile and even specify the location of
the name (i.e. the module / package name) without pre-importing it,
like this...
def importName(modulename, name=None):
""" Import ident
On 16 Okt., 02:18, Mensanator wrote:
> All I wanted to do is split a binary number into two lists,
> a list of blocks of consecutive ones and another list of
> blocks of consecutive zeroes.
Back to the OP's problem, the obvious (if you know the std lib) and
easy solution is:
>>> c = '0010100
> except:
> return 0
So wrong on so many levels...
--
http://mail.python.org/mailman/listinfo/python-list
Assuming those survived the switch to 3.0, you can use site.py und
sys.displayhook to customize to the old behaviour (i.e. change it to a
version using ascii instead of repr). Since this only affects
interactive use, it's also no problem for portability of code, unlike
"solutions" like forcing the
On 13 Nov., 20:20, "Chris Rebert" <[EMAIL PROTECTED]> wrote:
> try:
> unittest.main()
> except SystemExit:
> pass
You most probably want this instead:
try:
unittest.main()
except SystemExit, exc:
# only exit if tests failed
if exc.code:
raise
--
> >>> P=P.replace('\\','').replace(']','\\]') # escape both of them.
re.escape() does this w/o any assumptions by your code about the regex
implementation.
--
http://mail.python.org/mailman/listinfo/python-list
c.execute("select * from stocks")
for s in list(c):
print s[0]
c.execute("select * from stocks where price<20")
for sp in c:
print ' '+sp[0]
c.close()
The simple addition of list() should do away with the dependency on
mysql's implementation, since it forces the instant fetch of al
Our solution consists of:
* our own base python distribution, decoupled from the OS one (for
various reasons, one being version independency)
* distutils / setuptools / virtualenv is included in that python
installation, no other eggs installed in site-packages
* virtualenv + Paver to manage bui
I didn't see this mentioned in the thread yet: the double-lambda is
unnecessary (and a hack). What you should do when you need early
binding is... early binding. ;)
Namely:
f = [lambda n=n: n for n in range(10)]
print f[0]()
print f[1]()
Note the "n=n", this prints 0 and 1 instead of 9/9.
--
htt
Since nobody mentioned textwrap.dedent yet as an alternative to the
old "if 1:" trick, I thought I should do so. :)
--
http://mail.python.org/mailman/listinfo/python-list
12 matches
Mail list logo