s is fairly pedestrian as gotchas go, but it has bitten me:
If you are working with data that is representable as either an integer
or a string, choose one and stick to it. Treating it as both/either will
eventually lead to grief.
Or, in other words: 1 != '1'
--
John Gordon
In John Gordon writes:
> I'm writing an application that interacts with ldap, and I'm looking
> for advice on how to handle the connection. Specifically, how to
> close the ldap connection when the application is done.
> I wrote a class to wrap an LDAP conne
modules?
How to package and distribute your own modules once they're finished?
How to install modules that other people have developed?
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Bas
I need to convert this to
> this: ['ksals', '', 'alsdkfj', '3', '']
That looks like a tuple which contains five strings. But you said it's
a string, so I'll believe you.
>>> x = "('ksals', '
g.multenterbox(msg1,title, fieldNames, choice)
> fieldNames has 5 fields.
If you just need to convert a tuple to a list, that's easy. Call the
built-in function list() and pass the tuple as an intializer:
>>> choice = ('ksals', '', 'alsdkfj', '
r "TooLong". But that's not
enough; I also need to know the outer class name, i.e. "Question.TooShort"
or "Question.TooLong". How do I get the outer class name?
Thanks,
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
--
http://mail.python.org/mailman/listinfo/python-list
In John Gordon writes:
> class QuestionTooShortError(NetIDAppsError):
> """User entered a security question which is too short."""
> pass
> class QuestionTooLongError(NetIDAppsError):
> """User entered a security que
eyword can't be an expression" error.
The general syntax for assigning to a dictionary is:
my_dictionary[key] = value
What are you trying that isn't working?
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.
In msmucr
writes:
> Do I have something wrong or is it simply broken and unmaintained now?
We have no idea if you did anything wrong, because you didn't tell us
exactly what you did and exactly what error message you received.
--
John Gordon A is for Amy, who fell
In <6e534661-0823-4c42-8f60-3052e43b7...@googlegroups.com>
"psaff...@googlemail.com" writes:
> How do I force the memory for these soup objects to be freed?
Have you tried deleting them, using the "del" command?
--
John Gordon A is for Amy,
g that looks like a leak. It reported that there were 19 objects
which are unreachable and therefore are candidates for being collected.
What makes you think there is a leak?
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assa
ave a method and a list that are both called dogAppend. Try naming
one of them something different.
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "
ference
If you're starting new, use 3.2. All code will eventually move to this
newer style, so you'll have to learn it eventually.
The only reason to use 2.6 is if you have to maintain an existing code
base that was written with 2.6 (or older).
--
John Gordon A is for Amy,
yping it by hand, specifically to avoid errors like this.
Please repost a transcript of your real session.
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, &
t, what did you specifically have in mind?
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
--
http://mail.python.org/mailman/listinfo/python-list
t;cn=My-Group-1,ou=Groups,o=CUST", ldap.SCOPE_BASE)
for result in results:
result_dn = result[0]
result_attrs = result[1]
if "member" in result_attrs:
for member in result_attrs["member"]:
print member
ldapClient.unbind_s()
--
John Gordo
In Cousin Stanley
writes:
> How or why this behavior was cultivated
> and continues to spread is mind boggling
The behavior of writing in all caps, or the behavior of equating such
writing with shouting?
--
John Gordon A is for Amy, who fell down the stai
In
pipehappy writes:
> Why people want print() instead of print str? That's not a big deal
> and the old choice is more natural. Anyone has some clue?
Because the new Python uses print(). print "str" is the old way.
--
John Gordon A is for Amy, who
e:
python samples.py > textfile
And it will save the output in "textfile".
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
--
http://mail.python.org/mailman/listinfo/python-list
ctor warns me not to add a link, although perhaps it's
> time for recalibration (after all, summer season started) :-)
He's not asking for a link to the "Implicit initialization is EVIL"
thread; he's asking for a link to the original article he read elsewhere
which praised
In John Gordon writes:
> which praised the bendfists of implicit initialization.
Wow, that's quite a typo! I meant "benefits", of course.
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil,
ed character hanging at the end of the
input line, which upsets the palindromic balance?)
By the way, I could not make your program work as you provided it; I had
to replace input() with raw_input(). Does it really work for you this way?
--
John Gordon A is for Amy, who fell
it silly, but I'm a novice when it comes to
> design. Plus, there's not really supposed to be "more than one way to do
> it" in Python.
Concatenation feels ugly/clunky to me.
I prefer this usage:
logger.error('%s could not be stored - %s' % \
(self.preset_
list of methods that are defined by that object.
Hopefully one of them will be called something helpful like set_text()
or set_property(). Once you know the method name, you might try a Google
search to determine the exact usage and arguments.
--
John Gordon A is for Amy, who
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
--
http://mail.python.org/mailman/listinfo/python-list
None]?
It might help if you posted the method signature of the Oracle stored
procedure you're trying to call.
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
-- Edward
ot;, which is the prodecure
called by your code. Where is this procedure?
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
he OUT variable p, with some value. It doesn't have to be a
> cursor fetch; even a minor text assignment.
That procedure is defined as taking one parameter, but you're passing
an empty parameter list. Why?
--
John Gordon A is for Amy, who fell down the stairs
gor
ven't worked with OUT parameters so I don't know if this will work,
but try it and see what happens:
my_string = ""
p = [my_string]
c.callproc('c2_pkg.RS22', p);
print p
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.
s that is how the
example code does it.
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
--
http://mail.python.org/mailman/listinfo/python-list
ckage, actually works, but
> then you lose access to private data; which is while I used a package.
Did you try changing RS22 from a procedure to a function inside the
package?
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for B
ized.
Why did you say he was wrong?
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
--
http://mail.python.org/mailman/listinfo/python-list
is to help
the poor sod who will eventually get stuck working with your code on an
80-column fixed width terminal window.
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
-- Edw
n; the bitwise OR of both values is
computed and that value is returned.
It seems that you don't understand what the term "bitwise or" means.
Perhaps a Google search might help.
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.c
results from os.path.dirname:
>>> import os
>>> os.path.dirname('foo.py')
''
>>>
Are you trying to obtain the full pathname of the program? That's an
entirely different question.
--
John Gordon A is for Amy, who fell down the s
sure what you mean by "extension", but it might not be relevant.
Are these extensions, whatever they may be, part of the same program?
Or are they separate?
> This doesn't work. When one of my extensions changes the variable value, the
> other extension does not see the change.
In <4e3bf554$0$29976$c3e8da3$54964...@news.astraweb.com> Steven D'Aprano
writes:
> Doh! I *always* conflate env and which. Thank you for the correction.
Way to say "conflate"! :-)
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.c
that is a very naive solution
and can easily fail based on lots of factors.
What's your context: A single source file? Many source files? A live
application with persistent data?
What are your two objects? Do they provide an identical interface?
--
John Gordon A is for
In John Gordon writes:
> In Jack Bates
> writes:
> > I have two objects, and I want to replace all references to the first
> > object - everywhere - with references to the second object. What can I
> > try?
> The simplest answer to your question is to assign ob
administrators.
And what does this question have to do with python?
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
--
s problem when you haven't shown us the
code for Univariate.
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
--
http://mail.python.org/mailman/listinfo/python-list
It almost
seems like Apache is maintaining its own persistent session or something,
and restarting Apache causes the session to be flushed.
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
x27;m somewhat pressed for time. I was just
hoping that someone would recognize the problem from the few symptoms I
gave.
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
-- Edwa
In John Gordon writes:
> The problem is that I get conflicting results as to whether these temporary
> records have reached their expiration date, depending if I search for them
> via an Apache web call or if I do the search locally from a python shell.
> And to make it weirder, t
ion you're running, the version number
should be displayed when you start up a python shell, like this:
command prompt> python
Python 2.3.4 (#1, Apr 15 2011, 17:38:51)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-11)] on linux2
Type "help", "copyright", "cr
t convey the same meaning as "used to wear."
"wore" means you have worn them in the past.
"used to wear" means you have worn them in the past AND don't intend
to do so again.
--
John Gordon A is for Amy, who fell dow
ure. Not even YOU can predict whether or not
Of course -- that's why the word "intend" was part of my answer. Did you
overlook that crucial word?
I stand by my assertion that the phrase "I used to do X" carries the
meaning that you have done X in the past but DO NOT INTEND t
easured the memory used by a Python program? How did
> you do it?
I generally use 'top' to do this for any program.
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
ed", "one", "maple"]
list_of_variables = []
for x in list_of_strings:
list_of_variables.append(eval(x))
for y in list_of_variables:
print y
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assa
work than learning wordperfect macros.
Just my two cents.
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
--
http://mail
regexp account for the space in between each float? I can't tell
due to your post having a linebreak at a really inconvenient spot.
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
be better if this script runs from the clients' side.
> Could any one suggest any Python modules, articles, tutorials, ect. that
> might be helpful?
Mechanize seems like what you want. It's built on top of urllib2.
http://wwwsearch.sourceforge.net/mechanize/
--
John Gordon
s? Thank you.
You can catch all exceptions by catching the base class Exception:
try:
some_method()
except Exception, e:
print "some error happened, here is the explanation:"
print str(e)
--
John Gordon A is for Amy, who fell
which should be caught.
> You should always catch the absolute minimum you need to catch.
I agree, but it did seem to be exactly what he was asking for.
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for
l in eclipse
> but failed when using python f:\project\src\a.py, what's wrong?
> (the error msg shows a.py cannot find b.py) , what should i do in
> order to run a.py using command line?
What is your PYTHONPATH environment variable setting?
--
John Gordon A
you explain how it works?
> Thanks for you help.
> Vince
When a function calls itself, as fib() does, it's called recursion.
http://en.wikipedia.org/wiki/Recursion_(computer_science)
Basically the fib() method keeps calling itself with smaller and smaller
arguments until it gets 1 or 0.
; Could some one explain it for me? I can't understand how it works.
Reposting the exact same question doesn't help us answer it. Perhaps you
could explain why the previous responses weren't helpful.
--
John Gordon A is for Amy, who fell down the stairs
go
I'm writing a module that needs to fetch user details from an LDAP
server, it might be worthwhile to put all of the LDAP-specific code in
its own method, even if it's only used once. That way the main module
can just contain a line like this:
user_info = get_ldap_results("cn=john gord
, value):
> print("setting %s to %s" % (key, repr(value)))
> if key in ([]):
> self.legs.append(key)
> super(Centipede, self).__setattr__(self, key,value)
How will this if statement ever be true? You're checking if 'key
wouldn't be able to access
instance variable x and it wouldn't be able to call say_hello().
If you have a method that doesn't need to access other variables or
methods within the class, you can declare it with the @staticmethod
decorator.
--
John Gordon A is for
ge.
How would a method access instance variables without 'self'?
They probably could have made 'self' a magical attribute that just
appears out of thin air instead of being passed as an argument, like
'this' in C++. But would that really provide any benefit?
--
In <2a4f542c-a8c1-46c7-9899-a3fad0940...@x11g2000yqc.googlegroups.com> bclark76
writes:
> mypackage
> __init__.py
> myfunc.py
> MyClass.py
> from mypackage import MyClass
Try this instead:
from mypackage.MyClass import MyClass
--
John Gordon
ou meant by "real-time".
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
--
http://mail.python.org/mailman/listinfo/python-list
ent environments do I need to use?
You might try learning Tkinter; it is python's standard GUI interface
package.
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
--
and record their answer
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
--
http://mail.python.org/mailman/listinfo/python-list
4 1250 1125
1-1 1 5 1000 1000
grand total chars 23024400
The two loops do not produce the same numbers of characters, so I'm not
surprised they do not consume the same amount of
different, but surely that won't
always be the case with real data.
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
eys and values swapped.
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
--
http://mail.python.org/mailman/listinfo/python-list
In <8uh0rcfe1...@mid.individual.net> Neil Cerutti writes:
> RIIght. What's a cubit?
How long can you tread water?
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assa
much better. (However, I'm not sure it will do what
you were expecting with the tilde in the file path.)
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
-- Edward Gor
e a file named
"typescript" containing all of the input and output which occurred.
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
--
http://mail.python.org/mailman/listinfo/python-list
ne argument which is the name of the file to be written."
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
--
http://mail.python.org/mailman/listinfo/python-list
In
tazz_ben writes:
> So, any ideas? Why is including a $ eating both the dollar signa and the 1?
Unix command lines tend to assume any $ inside double-quotes is a shell
variable name. Try enclosing in single-quotes instead.
--
John Gordon A is for Amy, who fell down
er of a class? The presence of the "self"
parameter suggests that it is, but your code omits this detail.
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
-- Edward Gor
Bryan Cantrill gave an interesting talk recently at a Node conference about
"platform values" [1]. The talk lead me to think about what the core values
of the Python "platform" are and I thought it would be good to ask this
question of the community. What would you consider the top (<= 5) core
valu
r
> So "text" seems to be a string. Why does json.loads return an error?
Because, although text is the right type, it does not contain a
valid json string.
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by b
hy should software be any different?
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
--
https://mail.python.org/mailman/listinfo/python-list
In <151517608506.368831.5093080329614058603@welt.netz> "Kim of K."
writes:
> print(emo('now you see emos'))
> OF COURSE THIS SHIT DOES NOT WORK.
What device did you run this on? Your average terminal window isn't
going to support emojis...
--
John
te column.
Without this screenshot, we would have had only the user's (incorrect)
assertion that the file existed, and no way to diagnose the true issue.
Granted, this was an environment issue and not a code issue, but I can
imagine situations where the same sort of thing could apply t
whack-job newsgroups that would love to
> discuss that aspect of it.
Sounds like the plot to the latest Kingsman movie.
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
for x in newlist:
print(x)
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
--
https://mail.python.org/mailman/listinfo/python-list
default logging format; it's used when you haven't supplied any
format of your own. The snippet of xlreader.py does not define any format,
so it seems like that's where it's coming from.
(This seems pretty straightforward; am I missing something?)
--
John Gordon
particular group
Do the same search as above, returning the "member" attribute. Get
the search result and then inspect the list of returned members.
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for
fine even if group doesn't exist,
> It always says that user is member of
The query returns a user who is not a member of the named group?
That's odd.
What is the search base and scope?
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com
has been mutated in the very statement that
> you are quoting
No. An entirely new tuple is created, and 'a' is rebound to it. The
existing tuple is not mutated.
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assa
controls whether new pages
are opened in a new tab or a new window. Perhaps that is your issue?
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gash
sented as a string*. The same is
not true for integers.
* Okay, python 2.7 does have some issues with Unicode.
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
-- Edward Go
thing; it modifies the existing list in-place.
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
--
https://mail.python.org/mailman/listinfo/python-list
(0)
Or, if you really want to use a list comprehension:
[f.append(0) for f in fups if len(f) < 5]
However there's no reason to use a list comprehension here. The whole
point of list comprehensions is to create a *new* list, which you don't
appear to need; you just need to modify
child in root:
print(child.tag)
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
--
https://mail.python.org/mailman/listinfo/python-list
ed that they were all fairly short,
none more than 80 pages or so. I suspect these books are somewhat lighter
fare than the typical O'Reilly tome.
Not necessarily a bad thing, but worth mentioning.
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com
omething which runs
locally on your computer, such as Microsoft Word or a game.
But Django is for building websites, not local applications.
So Django probably isn't what you want.
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for B
le(a)
> print(b[:3])
> For example here i just want to slice the first 3 numbers which should
> be shuffled. However you can't slice a noneType object that b becomes.
> So how do i get shuffle to give me my numbers?
a = [1,2,3,4,5]
shuffle(a)
print(a[:3])
--
John Gord
In <9d24f23c-b578-4029-ab80-f117599e2...@googlegroups.com> Sayth Renshaw
writes:
> So why can't i assign the result slice to a variable b?
Because shuffle() modifies the list directly, and returns None.
It does NOT return the shuffled list.
--
John Gordon A i
In <8500044a-c8d1-43ad-91d9-e836d52bd...@googlegroups.com> SS
writes:
> I would like to be able to handle that error a bit better. Any ideas?
Wrap the socket.gethostbyname() call in a try/except block.
--
John Gordon A is for Amy, who fell down the stairs
gor...@
Then I ran it:
> ~$ python test.py argument1 argument2
> ['test.py', 'argument1', 'argument2']
Options cannot be passed *on the hash-bang line*.
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basi
In <6e030fd0-93c1-4d23-8656-e06c411b6...@googlegroups.com> chris alindi
writes:
> simple while loop range(10) if user press esc exits loop
range() is typically used with for loops, not while loops.
what is your while condition?
what use is the range() value?
--
Jo
object has no attribute 'modlist'
>>> ldap.dn
>>> import ldap.modlist
>>> ldap.modlist
Why the difference?
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
--
https://mail.python.org/mailman/listinfo/python-list
value.
That data looks like a list of dictionaries:
import json
with open("json.dat", "r") as fp:
data = json.load(fp)
for item in data:
if item['name'] == 'myField2':
print item['id']
-
In John Gordon writes:
> In
> mike.rei...@gmail.com writes:
> with open("json.dat", "r") as fp:
> data = json.load(fp)
> for item in data:
> if item['name'] == 'myField2':
Oops, that should be 'm
101 - 200 of 604 matches
Mail list logo