Wednesday, February 24, 2010

comp.lang.python - 25 new messages in 8 topics - digest

comp.lang.python
http://groups.google.com/group/comp.lang.python?hl=en

comp.lang.python@googlegroups.com

Today's topics:

* Intra-package C extensions with freeze.py - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/d24467f0e560e269?hl=en
* WANTED: Regular expressions for breaking TeX/LaTeX document into tokens - 1
messages, 1 author
http://groups.google.com/group/comp.lang.python/t/ef9f01798e857e5e?hl=en
* A tool for find dependencies relationships behind Python projects - 1
messages, 1 author
http://groups.google.com/group/comp.lang.python/t/6a1ffadaf0ebde9d?hl=en
* Is this secure? - 9 messages, 5 authors
http://groups.google.com/group/comp.lang.python/t/ffff2b290db4e811?hl=en
* Noob raw_input question - 6 messages, 5 authors
http://groups.google.com/group/comp.lang.python/t/47e7188c2bce081c?hl=en
* parametrizing a sqlite query - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/3e6109bdf7336729?hl=en
* What's the word on using """ to comment-out? - 4 messages, 3 authors
http://groups.google.com/group/comp.lang.python/t/fe1249d63dfc8f4b?hl=en
* Can't Connect To SMTP - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/42623032f1393d5f?hl=en

==============================================================================
TOPIC: Intra-package C extensions with freeze.py
http://groups.google.com/group/comp.lang.python/t/d24467f0e560e269?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Feb 24 2010 9:47 am
From: mk


On 2010-01-13 20:52, Pascal Chambon wrote:

> I've managed to solve that by manually "monkey patching" sys.modules,
> before fusemodule's actual import. But this looks like an unsatisfying
> solution, to me.

Geez..

> Does anyone have a clue about how to freeze a python program cleanly, in
> case such inner C extensions are involved ? Does any of the freezers
> (freeze.py, py2exe, pyrex, cx_freeze...) do that ? I haven't seen such
> things so far in their docs.

Go for pyinstaller, I have successfully packaged an app using compiled C
extensions this way. Although you will have to add those extensions in
"hook" script.

Regards,
mk


==============================================================================
TOPIC: WANTED: Regular expressions for breaking TeX/LaTeX document into tokens
http://groups.google.com/group/comp.lang.python/t/ef9f01798e857e5e?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Feb 24 2010 9:49 am
From: Wes James


On Wed, Feb 24, 2010 at 5:03 AM, Jonathan Fine <J.Fine@open.ac.uk> wrote:
> Hi
>
> Does anyone know of a collection of regular expressions that will break a
> TeX/LaTeX document into tokens?  Assume that there is no verbatim or other
> category code changes.

I'm not sure how this does it, but it might help:

http://plastex.sourceforge.net/plastex/sect0025.html

-wes

==============================================================================
TOPIC: A tool for find dependencies relationships behind Python projects
http://groups.google.com/group/comp.lang.python/t/6a1ffadaf0ebde9d?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Feb 24 2010 9:49 am
From: Victor Lin


On 2月23日, 上午12時32分, Hellmut Weber <m...@hellmutweber.de> wrote:
> Hi Victor,
> I would be intereseted to use your tool ;-)
>
> My system is Sabayon-5.1 on Lenovo T61.
> Trying for the first time easy_install I get the following error:
>
> ====================
>
> root@sylvester ~ # easy_install gluttony
> Searching for gluttony
> Readinghttp://pypi.python.org/simple/gluttony/
> Readinghttp://code.google.com/p/python-gluttony/
> Best match: Gluttony 0.3
>
> Downloadinghttp://pypi.python.org/packages/source/G/Gluttony/Gluttony-0.3.zip#md...
>
> Processing Gluttony-0.3.zip
> Running Gluttony-0.3/setup.py -q bdist_egg --dist-dir
> /tmp/easy_install-uPz7qO/Gluttony-0.3/egg-dist-tmp-CJI_LD
> Traceback (most recent call last):
>    File "/usr/bin/easy_install", line 9, in <module>
>      load_entry_point('distribute==0.6.8', 'console_scripts',
> 'easy_install')()
>    File
> "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py",
> line 1708, in main
>      with_ei_usage(lambda:
>    File
> "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py",
> line 1696, in with_ei_usage
>      return f()
>    File
> "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py",
> line 1712, in <lambda>
>      distclass=DistributionWithoutHelpCommands, **kw
>    File "/usr/lib64/python2.6/distutils/core.py", line 152, in setup
>      dist.run_commands()
>    File "/usr/lib64/python2.6/distutils/dist.py", line 975, in run_commands
>      self.run_command(cmd)
>    File "/usr/lib64/python2.6/distutils/dist.py", line 995, in run_command
>      cmd_obj.run()
>    File
> "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py",
> line 236, in run
>      self.easy_install(spec, not self.no_deps)
>    File
> "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py",
> line 471, in easy_install
>      return self.install_item(spec, dist.location, tmpdir, deps)
>    File
> "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py",
> line 501, in install_item
>      dists = self.install_eggs(spec, download, tmpdir)
>    File
> "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py",
> line 680, in install_eggs
>      return self.build_and_install(setup_script, setup_base)
>    File
> "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py",
> line 957, in build_and_install
>      self.run_setup(setup_script, setup_base, args)
>    File
> "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py",
> line 946, in run_setup
>      run_setup(setup_script, args)
>    File "/usr/lib64/python2.6/site-packages/setuptools/sandbox.py", line
> 29, in run_setup
>      lambda: execfile(
>    File "/usr/lib64/python2.6/site-packages/setuptools/sandbox.py", line
> 70, in run
>      return func()
>    File "/usr/lib64/python2.6/site-packages/setuptools/sandbox.py", line
> 31, in <lambda>
>      {'__file__':setup_script, '__name__':'__main__'}
>    File "setup.py", line 9, in <module>
>    File "/tmp/easy_install-uPz7qO/Gluttony-0.3/gluttony/__init__.py",
> line 1, in <module>
>      #
>    File "/tmp/easy_install-uPz7qO/Gluttony-0.3/gluttony/gluttony.py",
> line 13, in <module>
> ImportError: No module named pip.log
> root@sylvester ~ #
>
> ====================
>
> I emerged app-misc/pip, but that didn't help, the error remains the same
>
> What is missing?
>
> Any help appreciated
>
> Best regards
>
> Hellmut
>
> Am 19.02.2010 17:16, schrieb Victor Lin:
>
>
>
>
>
> > Hi,
>
> > I just wrote a tool for drawing dependencies relationships diagram of
> > Python project on Pypi.  Here is the home page of the tool:
>
> >http://code.google.com/p/python-gluttony/
>
> > Some examples:
> > Sprox:
> >http://static.ez2learn.com/gluttony/sprox_dot.png
>
> > TurboGears2:
> >http://static.ez2learn.com/gluttony/tg2_dot.png
>
> > Hope this could be helpful :P
>
> > Regards.
> > Victor Lin.
>
> --
> Dr. Hellmut Weber         m...@hellmutweber.de
> Degenfeldstraße 2         tel   +49-89-3081172
> D-80803 München-Schwabing mobil +49-172-8450321
> please: No DOCs, no PPTs. why: tinyurl.com/cbgq

Hi,

That is a mistake I made in when I am making the distribute. Thanks
your reporting. I have already fixed the problem and released
Gluttony 0.4, and I tried to install that, it works fine.

Victor Lin.

==============================================================================
TOPIC: Is this secure?
http://groups.google.com/group/comp.lang.python/t/ffff2b290db4e811?hl=en
==============================================================================

== 1 of 9 ==
Date: Wed, Feb 24 2010 9:56 am
From: Michael Rudolf


Am 24.02.2010 18:23, schrieb mk:
> Even then I'm not getting completely uniform distribution for some reason:
> d 39411
> l 39376
> f 39288
> a 39275
> s 39225
> r 39172
> p 39159
> t 39073
> k 39071
> u 39064
> e 39005
> o 39005
> n 38995
> j 38993
> h 38975
> q 38958
> c 38938
> b 38906
> g 38894
> i 38847
> m 38819
> v 38712
> z 35321
> y 35228
> w 35189
> x 35075
>
> Code:
>
> import operator
>
> def gen_rand_word(n):
> with open('/dev/urandom') as f:
> return ''.join([chr(ord('a') + ord(x) % 26) for x in f.read(n)])

The reason is 256 % 26 != 0
256 mod 26 equals 22, thus your code is hitting a-v about 10% (256/26 is
approx. 10) more often than w-z. You might want to skip the values 0-22
to achieve a truly uniform distribution.

FYI: Electronic Cash PINs in europe (dont know about the rest of the
world) were computed the same way (random hexdigit and just mod it when
it's too large) leading to a high probability that your first digit was
a 1 :)

Regards,
Michael


== 2 of 9 ==
Date: Wed, Feb 24 2010 9:59 am
From: Steve Holden


mk wrote:
> On 2010-02-24 03:50, Paul Rubin wrote:
>> The stuff about converting 4 random bytes to a decimal string and then
>> peeling off 2 digits at a time is pretty awful, and notice that since
>> 2**32 is 4294967296, in the cases where you get 10 digits, the first
>> 2-digit pair is never higher than 42.
>
> Yikes! I didn't think about that. This is probably where (some part of)
> probability skewing comes from.
>
> Anyway, the passwords for authorized users will be copied and pasted
> from email into in the application GUI which will remember it for them,
> so they will not have to remember and type them in. So I have little in
> the way of limitations of password length - even though in *some* cases
> somebody might have to (or be ignorant enough) to retype the password
> instead of pasting it in.
>
> In that case the "diceware" approach is not necessary, even though I
> will certainly remember this approach for a case when users will have to
> remember & type the passwords in.
>
> The main application will access the data using HTTP (probably), so the
> main point is that an attacker is not able to guess passwords using
> brute force.
>
> Using A-z with 10-char password seems to provide 3 orders of magnitude
> more combinations than a-z:
>
>>>> 57 ** 10
> 362033331456891249L
>>>> 25 ** 10
> 95367431640625L
>
> Even though I'm not sure it is worth it, assuming 1000 brute-force
> guesses per second (which over the web would amount pretty much to DOS),
> this would take # days:
>
>>>> 57 ** 10 / (1000 * 3600 * 24)
> 4190200595L
>>>> 25 ** 10 / (1000 * 3600 * 24)
> 1103789L
>
> Even then I'm not getting completely uniform distribution for some reason:
>
> d 39411
> l 39376
> f 39288
> a 39275
> s 39225
> r 39172
> p 39159
> t 39073
> k 39071
> u 39064
> e 39005
> o 39005
> n 38995
> j 38993
> h 38975
> q 38958
> c 38938
> b 38906
> g 38894
> i 38847
> m 38819
> v 38712
> z 35321
> y 35228
> w 35189
> x 35075
>
> Code:
>
> import operator
>
> def gen_rand_word(n):
> with open('/dev/urandom') as f:
> return ''.join([chr(ord('a') + ord(x) % 26) for x in f.read(n)])
>
> def count_chars(chardict, word):
> for c in word:
> try:
> chardict[c] += 1
> except KeyError:
> chardict[c] = 0
>
> if __name__ == "__main__":
> chardict = {}
> for i in range(100000):
> w = gen_rand_word(10)
> count_chars(chardict, w)
> counts = list(chardict.items())
> counts.sort(key = operator.itemgetter(1), reverse = True)
> for char, count in counts:
> print char, count
>
>> I'd write your code something like this:
>>
>> nletters = 5
>>
>> def randomword(n):
>> with open('/dev/urandom') as f:
>> return ''.join([chr(ord('a')+ord(c)%26) for c in f.read(n)])
>>
>> print randomword(nletters)
>
> Aw shucks when will I learn to do the stuff in 3 lines well instead of
> 20, poorly. :-/
>
When you've got as much experience as Paul?

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS: http://holdenweb.eventbrite.com/

== 3 of 9 ==
Date: Wed, Feb 24 2010 10:13 am
From: mk


On 2010-02-24 18:59, Steve Holden wrote:

>> Aw shucks when will I learn to do the stuff in 3 lines well instead of
>> 20, poorly. :-/
>>
> When you've got as much experience as Paul?

And how much experience does Paul have? (this is mostly not a facile
question)

For my part, my more serious effort (on and off) with programming in
Python is under a year.

Regards,
mk

== 4 of 9 ==
Date: Wed, Feb 24 2010 10:35 am
From: mk


On 2010-02-24 18:56, Michael Rudolf wrote:

> The reason is 256 % 26 != 0
> 256 mod 26 equals 22, thus your code is hitting a-v about 10% (256/26 is
> approx. 10) more often than w-z.

<Barbie voice>writing secure code is hard...

I'm going to switch to PHP: Python world wouldn't lose much, but PHP
would gain a lot.

> You might want to skip the values 0-22
> to achieve a truly uniform distribution.

Hmm perhaps you meant to skip values over 256 - 22 ? Bc I'm getting this
(reduced the run to 1000 generated strings):

def gen_rand_word(n):
with open('/dev/urandom') as f:
return ''.join([chr(ord('a') + ord(x) % 26) for x in f.read(n)
if ord(x) > 22])


z 3609
b 3608
s 3567
e 3559
j 3556
r 3555
g 3548
p 3540
m 3538
q 3532
h 3528
y 3526
v 3524
i 3500
x 3496
c 3488
k 3488
l 3487
u 3487
a 3469
o 3465
d 3455
t 3439
f 3437
n 3417
w 3175

While with this:

def gen_rand_word(n):
with open('/dev/urandom') as f:
return ''.join([chr(ord('a') + ord(x) % 26) for x in f.read(n)
if ord(x) < 235])

a 3852
w 3630
s 3623
v 3582
y 3569
p 3568
c 3558
k 3558
b 3556
r 3553
x 3546
m 3534
n 3522
o 3515
h 3510
d 3505
u 3487
t 3486
i 3482
f 3477
e 3474
g 3460
q 3453
l 3437
z 3386
j 3382

1. I'm systematically getting 'a' outlier: have no idea why for now.

2. This is somewhat better (except 'a') but still not uniform.


> FYI: Electronic Cash PINs in europe (dont know about the rest of the
> world) were computed the same way (random hexdigit and just mod it when
> it's too large) leading to a high probability that your first digit was
> a 1 :)

Schadenfreude is deriving joy from others' misfortunes; what is the
German word, if any, for deriving solace from others' misfortunes? ;-)

Regards,
mk


== 5 of 9 ==
Date: Wed, Feb 24 2010 11:01 am
From: Robert Kern


On 2010-02-24 12:35 PM, mk wrote:

> While with this:
>
> def gen_rand_word(n):
> with open('/dev/urandom') as f:
> return ''.join([chr(ord('a') + ord(x) % 26) for x in f.read(n) if ord(x)
> < 235])
>
> a 3852
...

> 1. I'm systematically getting 'a' outlier: have no idea why for now.
>
> 2. This is somewhat better (except 'a') but still not uniform.

I will repeat my advice to just use random.SystemRandom.choice() instead of
trying to interpret the bytes from /dev/urandom directly.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

== 6 of 9 ==
Date: Wed, Feb 24 2010 11:09 am
From: mk


On 2010-02-24 20:01, Robert Kern wrote:
> I will repeat my advice to just use random.SystemRandom.choice() instead
> of trying to interpret the bytes from /dev/urandom directly.

Oh I hear you -- for production use I would (will) certainly consider
this. However, now I'm interested in the problem itself: why is the damn
distribution not uniform?

Regards,
mk


== 7 of 9 ==
Date: Wed, Feb 24 2010 11:19 am
From: Robert Kern


On 2010-02-24 13:09 PM, mk wrote:
> On 2010-02-24 20:01, Robert Kern wrote:
>> I will repeat my advice to just use random.SystemRandom.choice() instead
>> of trying to interpret the bytes from /dev/urandom directly.
>
> Oh I hear you -- for production use I would (will) certainly consider
> this. However, now I'm interested in the problem itself: why is the damn
> distribution not uniform?

You want "< 234", not "< 235". (234 % 26 == 0), so you get some extra 'a's.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

== 8 of 9 ==
Date: Wed, Feb 24 2010 11:16 am
From: mk


On 2010-02-24 20:01, Robert Kern wrote:
> I will repeat my advice to just use random.SystemRandom.choice() instead
> of trying to interpret the bytes from /dev/urandom directly.

Out of curiosity:

def gen_rand_string(length):
prng = random.SystemRandom()
chars = []
for i in range(length):
chars.append(prng.choice('abcdefghijklmnopqrstuvwxyz'))
return ''.join(chars)

if __name__ == "__main__":
chardict = {}
for i in range(10000):
## w = gen_rand_word(10)
w = gen_rand_string(10)
count_chars(chardict, w)
counts = list(chardict.items())
counts.sort(key = operator.itemgetter(1), reverse = True)
for char, count in counts:
print char, count


s 3966
d 3912
g 3909
h 3905
a 3901
u 3900
q 3891
m 3888
k 3884
b 3878
x 3875
v 3867
w 3864
y 3851
l 3825
z 3821
c 3819
e 3819
r 3816
n 3808
o 3797
f 3795
t 3784
p 3765
j 3730
i 3704

Better, although still not perfect.

Regards,
mk

== 9 of 9 ==
Date: Wed, Feb 24 2010 11:09 am
From: Paul Rubin


Robert Kern <robert.kern@gmail.com> writes:
> I will repeat my advice to just use random.SystemRandom.choice()
> instead of trying to interpret the bytes from /dev/urandom directly.

SystemRandom is something pretty new so I wasn't aware of it. But
yeah, if I were thinking more clearly I would have suggested os.urandom
instead of opening /dev/urandom.

==============================================================================
TOPIC: Noob raw_input question
http://groups.google.com/group/comp.lang.python/t/47e7188c2bce081c?hl=en
==============================================================================

== 1 of 6 ==
Date: Wed, Feb 24 2010 9:39 am
From: "Abigail"


Yesterday I downloaded and installed Python 3.1 and working through some
examples but I have hit a problem

>>> a = raw_input("Enter a number" )
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
a = raw_input("Enter a number" )
NameError: name 'raw_input' is not defined>>>a = raw_input("Enter a number
")

What am I doing wrong?


== 2 of 6 ==
Date: Wed, Feb 24 2010 10:16 am
From: Chris Rebert


On Wed, Feb 24, 2010 at 9:39 AM, Abigail <spam@removethis.btinternet.com> wrote:
> Yesterday I downloaded and installed Python 3.1 and working through some
> examples but I have hit a problem
>
>>>> a = raw_input("Enter a number" )
> Traceback (most recent call last):
>  File "<pyshell#6>", line 1, in <module>
>    a = raw_input("Enter a number" )
> NameError: name 'raw_input' is not defined>>>a = raw_input("Enter a number
> ")
>
> What am I doing wrong?

raw_input() got renamed to just input().
Please read the 3.x transition docs at
http://docs.python.org/3.1/whatsnew/3.0.html

Cheers,
Chris
--
http://blog.rebertia.com


== 3 of 6 ==
Date: Wed, Feb 24 2010 10:21 am
From: Robert Kern


On 2010-02-24 11:39 AM, Abigail wrote:
> Yesterday I downloaded and installed Python 3.1 and working through some
> examples but I have hit a problem
>
>>>> a = raw_input("Enter a number" )
> Traceback (most recent call last):
> File "<pyshell#6>", line 1, in<module>
> a = raw_input("Enter a number" )
> NameError: name 'raw_input' is not defined>>>a = raw_input("Enter a number
> ")
>
> What am I doing wrong?

Python 3 changed the name of raw_input() to input() (and the old input() method
that evaluates the string was simply thrown out as being redundant and unsafe).

http://docs.python.org/dev/3.0/whatsnew/3.0.html

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

== 4 of 6 ==
Date: Wed, Feb 24 2010 10:29 am
From: John Posner


On 2/24/2010 12:39 PM, Abigail wrote:
> Yesterday I downloaded and installed Python 3.1 and working through some
> examples but I have hit a problem
>
>>>> a = raw_input("Enter a number" )
> Traceback (most recent call last):
> File "<pyshell#6>", line 1, in<module>
> a = raw_input("Enter a number" )
> NameError: name 'raw_input' is not defined>>>a = raw_input("Enter a number
> ")
>
> What am I doing wrong?
>
>

The Python 2 built-in function "raw_input" has been renamed to "input"
in Python 3. You'll probably run into this, too:

Python 2: print "hello, world"
Python 3: print("hello, world")

You might want to install Python 2 if you're working your way through a
tutorial that's targeted at that "generation" of the language.

-John


== 5 of 6 ==
Date: Wed, Feb 24 2010 10:33 am
From: "Abigail"


Thank You


== 6 of 6 ==
Date: Wed, Feb 24 2010 10:33 am
From: Steve Holden


Abigail wrote:
> Yesterday I downloaded and installed Python 3.1 and working through some
> examples but I have hit a problem
>
>>>> a = raw_input("Enter a number" )
> Traceback (most recent call last):
> File "<pyshell#6>", line 1, in <module>
> a = raw_input("Enter a number" )
> NameError: name 'raw_input' is not defined>>>a = raw_input("Enter a number
> ")
>
> What am I doing wrong?
>
>
In Python 3 raw_input() is now simply called input()

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS: http://holdenweb.eventbrite.com/


==============================================================================
TOPIC: parametrizing a sqlite query
http://groups.google.com/group/comp.lang.python/t/3e6109bdf7336729?hl=en
==============================================================================

== 1 of 2 ==
Date: Wed, Feb 24 2010 10:12 am
From: "Diez B. Roggisch"


Am 24.02.10 18:07, schrieb Sebastian Bassi:
> c.execute("SELECT bin FROM bins WHERE qtl LIKE '%:keys%'",{'keys':keywords})
>
> This query returns empty. When it is executed, keywords = 'harvest'.
> To check it, I do it on the command line and it works as expected:
>
> sqlite> SELECT bin FROM bins WHERE qtl LIKE '%harvest%';
> 11C
> 11D
> 12F
>
> I guess there is a problem with the "%".

You aren't supposed to put ' into the query. The thing you pass needs to
be the full literal.

Use

c.execute("select ... qtl like :keys", dict(keys="%%%s%%" % keywords))


Diez


== 2 of 2 ==
Date: Wed, Feb 24 2010 10:41 am
From: Dennis Lee Bieber


On Wed, 24 Feb 2010 14:07:07 -0300, Sebastian Bassi
<sbassi@clubdelarazon.org> declaimed the following in
gmane.comp.python.general:

> c.execute("SELECT bin FROM bins WHERE qtl LIKE '%:keys%'",{'keys':keywords})
>
> This query returns empty. When it is executed, keywords = 'harvest'.
> To check it, I do it on the command line and it works as expected:
>
> sqlite> SELECT bin FROM bins WHERE qtl LIKE '%harvest%';
> 11C
> 11D
> 12F
>
> I guess there is a problem with the "%".

No there isn't... The problem is that you need to put the wildcards
into the parameter instead of the placeholder.

c.execute("select bin from bins where qtl like :keys",
{"keys" : "%" + keywords + "%"} )

Note -- no quotes IN the SQL... any quotes and escaping of data is
done before the data value is put into the query. Your original
formulation will result in:

select bin from bins where qtl like '%'harvest'%'

See the extra quotes?
--
Wulfraed Dennis Lee Bieber KD6MOG
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/


==============================================================================
TOPIC: What's the word on using """ to comment-out?
http://groups.google.com/group/comp.lang.python/t/fe1249d63dfc8f4b?hl=en
==============================================================================

== 1 of 4 ==
Date: Wed, Feb 24 2010 10:18 am
From: kj

I think I remember, early in my learning of Python, coming across
the commandment "THOU SHALT NOT USE TRIPLE-QUOTES TO COMMENT-OUT
LINES OF CODE", or something to that effect. But now I can't find
it!

Is my memory playing me a trick?

After all, from what I've seen since then, the practice of
triple-quote-commenting (or TQC, pardon the TCA) is in fact quite
common.

Is TQC OK after all?

If not, what's the case against it?

Also, has the BDFL expressed an opinion on the subject? Alternatively,
is there any other more or less "authoritative" opinion on TQC?

TIA!

~K

P.S. I can think of at least one reason to avoid TQC: it has
basically the same problems with nesting that C's /**/ has. (Sure,
in the case of TQC one could use "the other" triple quote, but it's
not hard to see that this workaround goes only so far.) But this
reason does not seem to bother many programmers, most of whom,
after all, cut their teeth with C and /**/.

P.S.2 I'm disregarding "it's un-Pythonic" as a reason against TQC,
because it's not the kind of reason that carries much weight out
here "in the trenches", as I've discovered. But, yes, I happen to
think that TQC is un-Pythonic. After all, in my programming
environment, it takes half as many keystrokes to comment a block
of code with # than it does with """. I imagine that any decent
programming environment makes #-commenting at least as easy.
Therefore, there goes convenience as an argument in defense of TQC.
Which leaves TMTOWTDI as the only possible defense for TQC, and
TMTOWTDI is pretty un-Pythonic, no? :)


== 2 of 4 ==
Date: Wed, Feb 24 2010 11:03 am
From: rantingrick


On Feb 24, 12:18 pm, kj <no.em...@please.post> wrote:
> I think I remember, early in my learning of Python, coming across
> the commandment "THOU SHALT NOT USE TRIPLE-QUOTES TO COMMENT-OUT
> LINES OF CODE", or something to that effect.  But now I can't find
> it!

Your going to get many opinions on this subject but my stance is --
use quotes for stings and hash chars for comments -- thats the end of
it for me ;)


== 3 of 4 ==
Date: Wed, Feb 24 2010 11:12 am
From: mk

Get a decent editor, like PyScripter, and press Ctrl-' (toggle comment).

Regards,
mk


== 4 of 4 ==
Date: Wed, Feb 24 2010 11:12 am
From: mk

Get a decent editor, like PyScripter, and press Ctrl-' (toggle comment).

Regards,
mk


==============================================================================
TOPIC: Can't Connect To SMTP
http://groups.google.com/group/comp.lang.python/t/42623032f1393d5f?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Feb 24 2010 10:41 am
From: Dennis Lee Bieber


On Wed, 24 Feb 2010 10:32:43 -0400, Victor Subervi
<victorsubervi@gmail.com> declaimed the following in
gmane.comp.python.general:

> Hi;
> I'm getting this error:
>
> A problem occurred in a Python script. Here is the sequence of function
> calls leading up to the error, in the order they occurred.
>
Unfortunately, the intermingling of code and mystery output makes it
very difficult to tell what is happening anywhere...

> /var/www/html/globalsolutionsgroup.vi/simplemail/mail2.py
> 52 </head>
> 53 <body>'''
> 54 my_mail()
> 55 print '''
> 56 </body>
> my_mail = <function my_mail>
> /var/www/html/globalsolutionsgroup.vi/simplemail/mail2.py in my_mail()

Like where is that being output? After all, you are calling
my_mail() two lines further up...

> 33 to_address = ourEmail1,

And now we have line numbers coming from somewhere else -- but no
complete code to compare against.

> 34 subject = subject,
> 35 message = message
> 36 ).send()
> 37 Email(
> message = 'Name: beno -\nMessage: test'
> /var/www/html/globalsolutionsgroup.vi/simplemail/simplemail.py in
> send(self=<simplemail.Email object>)
> 344 smtp = smtplib.SMTP()
> 345 if self.smtp_server:
> 346 smtp.connect(self.smtp_server)
> 347 else:
> 348 smtp.connect()
> smtp = <smtplib.SMTP instance>, smtp.connect = <bound method SMTP.connect of
> <smtplib.SMTP instance>>, self = <simplemail.Email object>, self.smtp_server
> = 'localhost'
> /usr/lib64/python2.4/smtplib.py in connect(self=<smtplib.SMTP instance>,
> host='localhost', port=25)
> 305 if not self.sock:
> 306 raise socket.error, msg
> 307 (code, msg) = self.getreply()
> 308 if self.debuglevel > 0: print>>stderr, "connect:", msg
> 309 return (code, msg)
> code undefined, msg = 'getaddrinfo returns an empty list', self =
> <smtplib.SMTP instance>, self.getreply = <bound method SMTP.getreply of
> <smtplib.SMTP instance>>
> /usr/lib64/python2.4/smtplib.py in getreply(self=<smtplib.SMTP instance>)
> 349 if line == '':
> 350 self.close()
> 351 raise SMTPServerDisconnected("Connection unexpectedly
> closed")
> 352 if self.debuglevel > 0: print>>stderr, 'reply:',
> repr(line)
> 353 resp.append(line[4:].strip())
> global SMTPServerDisconnected = <class smtplib.SMTPServerDisconnected>
> SMTPServerDisconnected: Connection unexpectedly closed
> args = ('Connection unexpectedly closed',)
>
> I'm having a hard time reading this and making sense of it. Please help me
> understand where I should look to fix the problem.

Normal advice is to trim your program down to the absolute minimum
that reproduces your problem, and post that, with a traceback if such is
produced...

Snippets of code interspersed by out-of-sync debug print statements
(no where in the above is ANY statement producing the displayed output
seen).

Second approach... Get a copy of the SMTP RFCs, open a command
console (NOT PYTHON)

telnet localhost 25

and try to follow the RFCs to handshake and form a message... See if the
SMTPd disconnects on you. If you can't create/send a message via telnet,
nothing you do in Python is going to help. And note that the message
indicates that it is the SMTPd that is dropping you...

--
Wulfraed Dennis Lee Bieber KD6MOG
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/

==============================================================================

You received this message because you are subscribed to the Google Groups "comp.lang.python"
group.

To post to this group, visit http://groups.google.com/group/comp.lang.python?hl=en

To unsubscribe from this group, send email to comp.lang.python+unsubscribe@googlegroups.com

To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.python/subscribe?hl=en

To report abuse, send email explaining the problem to abuse@googlegroups.com

==============================================================================
Google Groups: http://groups.google.com/?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate