Re: Python Gotcha's?

2012-04-05 Thread John Gordon
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

Re: Best way to disconnect from ldap?

2012-04-05 Thread 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

Re: Python Gotcha's?

2012-04-05 Thread John O'Hagan
On Thu, 05 Apr 2012 10:15:03 -0400 John Posner wrote: > On 4/4/2012 7:32 PM, Chris Angelico wrote: > > Don't know if it's what's meant on that page by the += operator, > > Yes, it is. > > >> a=([1],) > >> a[0].append(2) # This is fine &

Re: Reading Live Output from a Subprocess

2012-04-06 Thread John O'Hagan
y difficult to find out how to do at first. To get your test script working, you just need to flush stdout from there; add: sys.stdout.flush() to your for loop above. However, if there is a real process you need to use which you "can't modify", then it seems you'll have to use one of the more complex solutions offered here. Regards, John -- http://mail.python.org/mailman/listinfo/python-list

Re: ordering with duck typing in 3.1

2012-04-07 Thread John O'Hagan
and <) to derive any of the other comparisons; but not to imply that a class that only defines those two will automatically possess the others. However, you can do that, with functools.total_ordering. Regards, John -- http://mail.python.org/mailman/listinfo/python-list

Re: Python Gotcha's?

2012-04-07 Thread John Nagle
ion. This can stall servers. 9. Some libraries aren't thread-safe. Guess which ones. 10. Python 3 isn't upward compatible with Python 2. John Nagle -- http://mail.python.org/mailman/listinfo/python-list

Re: Python Gotcha's?

2012-04-08 Thread John Nagle
is method to support more appropriate behavior if needed." A related "gotcha" is knowing that "urllib" sucks and you should use "urllib2". John Nagle -- http://mail.python.org/mailman/listinfo/python-list

Re: python module development workflow

2012-04-11 Thread John Gordon
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

Re: Donald E. Knuth in Python, cont'd

2012-04-11 Thread John Nagle
t on the EDVAC", for background on how things work down at the bottom. But they're no longer essential desk references for most programmers. John Nagle -- http://mail.python.org/mailman/listinfo/python-list

Coping with risk of decision - modeling of scenarios of parameters of the model in python

2012-04-12 Thread John Oksz
this decision problem. Can you suggest any paper/book/example about: - scenario analysis in pyhon - stochastic simulation in pyhon - coping with uncertenises and risk in python (VaR, CVaR)? Thanks in advance for any help. John -- http://mail.python.org/mailman/listinfo/python-list

Re: python module development workflow

2012-04-12 Thread John Nagle
works. Don't use the "rotten egg" distribution system. (http://packages.python.org/distribute/easy_install.html) John Nagle -- http://mail.python.org/mailman/listinfo/python-list

Re: Deep merge two dicts?

2012-04-12 Thread John Nagle
On 4/12/2012 10:41 AM, Roy Smith wrote: Is there a simple way to deep merge two dicts? I'm looking for Perl's Hash::Merge (http://search.cpan.org/~dmuey/Hash-Merge-0.12/Merge.pm) in Python. def dmerge(a, b) : for k in a : v = a[k] if isinstance(v, dict) and k in b:

Re: Deep merge two dicts?

2012-04-13 Thread John O'Hagan
On Thu, 12 Apr 2012 12:35:21 -0600 Ian Kelly wrote: > On Thu, Apr 12, 2012 at 11:59 AM, John Nagle wrote: > > On 4/12/2012 10:41 AM, Roy Smith wrote: > >> > >> Is there a simple way to deep merge two dicts?  I'm looking for Perl's > >> Hash::Merge

Re: Deep merge two dicts?

2012-04-13 Thread John O'Hagan
On Fri, 13 Apr 2012 10:50:15 -0600 Ian Kelly wrote: > On Fri, Apr 13, 2012 at 5:11 AM, John O'Hagan wrote: > > I think you also have to check if a[k] is a dict before making the recursive > > call, else for example dmerge({'a': 1}, {'a': {'b':

Re: Bug in Python

2012-04-17 Thread John O'Hagan
d where n < 5 or thereabouts. However, if it doesn't happen when the command is issued, it happens when 'exit' is called. Hopefully some of this is a clue. Regards, John -- http://mail.python.org/mailman/listinfo/python-list

Re: why () is () and [] is [] work in other way?

2012-04-20 Thread John O'Hagan
first one. OTOH, "is" hangs on to both objects in order to compare them. c.f.: >>> l, m = [], [] >>> id(l) == id(m) False Is that right? -- John -- http://mail.python.org/mailman/listinfo/python-list

Re: why () is () and [] is [] work in other way?

2012-04-20 Thread john . tantalo
On Friday, April 20, 2012 12:34:46 PM UTC-7, Rotwang wrote: > I believe it says somewhere in the Python docs that it's undefined and > implementation-dependent whether two identical expressions have the same > identity when the result of each is immutable I was curious where that might be on my

Re: why () is () and [] is [] work in other way?

2012-04-22 Thread John Nagle
s, like "None". You can't assign to None, but you can assign to True, usually with unwanted results. It's not clear why True and False weren't locked down when None was.) John Nagle -- http://mail.python.org/mailman/listinfo/python-list

Re: global vars across modules

2012-04-22 Thread John Nagle
ings in everything in the other module, which often results in a name clash. Just do import file_1 and, if desired localnamefora = file_1.a John Nagle -- http://mail.python.org/mailman/listinfo/python-list

Re: why () is () and [] is [] work in other way?

2012-04-22 Thread John Roth
On Sunday, April 22, 2012 1:43:36 PM UTC-6, John Nagle wrote: > On 4/20/2012 9:34 PM, john.tant...@gmail.com wrote: > > On Friday, April 20, 2012 12:34:46 PM UTC-7, Rotwang wrote: > > > >> I believe it says somewhere in the Python docs that it's undefined and > >

Re: why () is () and [] is [] work in other way?

2012-04-22 Thread John Nagle
On 4/22/2012 3:17 PM, John Roth wrote: On Sunday, April 22, 2012 1:43:36 PM UTC-6, John Nagle wrote: On 4/20/2012 9:34 PM, john.tant...@gmail.com wrote: On Friday, April 20, 2012 12:34:46 PM UTC-7, Rotwang wrote: I believe it says somewhere in the Python docs that it's undefine

Re: why () is () and [] is [] work in other way?

2012-04-23 Thread John Nagle
On 4/22/2012 9:34 PM, Steven D'Aprano wrote: On Sun, 22 Apr 2012 12:43:36 -0700, John Nagle wrote: On 4/20/2012 9:34 PM, john.tant...@gmail.com wrote: On Friday, April 20, 2012 12:34:46 PM UTC-7, Rotwang wrote: I believe it says somewhere in the Python docs that it's und

Re: why () is () and [] is [] work in other way?

2012-04-25 Thread John Nagle
t; have to force the creation of a temporary boxed object? The concept of "object" vs. the implementation of objects is one reason you don't necessarily want to expose the implementation. John Nagle -- http://mail.python.org/mailman/listinfo/python-list

Re: why () is () and [] is [] work in other way?

2012-04-26 Thread John Nagle
On 4/26/2012 4:45 AM, Adam Skutt wrote: On Apr 26, 1:48 am, John Nagle wrote: On 4/25/2012 5:01 PM, Steven D'Aprano wrote: On Wed, 25 Apr 2012 13:49:24 -0700, Adam Skutt wrote: Though, maybe it's better to use a different keyword than 'is' though, due to the plain Eng

Re: Half-baked idea: list comprehensions with "while"

2012-04-27 Thread John O'Hagan
or i in iterable: x = expensive_call(i) if condition(x): results.append(x) -- John -- http://mail.python.org/mailman/listinfo/python-list

CPython thread starvation

2012-04-27 Thread John Nagle
re copies of the Python interpreter. The threads are usually I/O bound, but when they hit unusually long web pages, they go compute-bound during parsing.) Setting "sys.setcheckinterval" from the default to 1 seems to have little effect. This is on Windows 7.

Re: CPython thread starvation

2012-04-27 Thread John Nagle
On 4/27/2012 6:25 PM, Adam Skutt wrote: On Apr 27, 2:54 pm, John Nagle wrote: I have a multi-threaded CPython program, which has up to four threads. One thread is simply a wait loop monitoring the other three and waiting for them to finish, so it can give them more work to do. When the

Re: CPython thread starvation

2012-04-27 Thread John Nagle
On 4/27/2012 9:20 PM, Paul Rubin wrote: John Nagle writes: The code that stored them looked them up with "getaddrinfo()", and did this while a lock was set. Don't do that!! Added a local cache in the program to prevent this. Performance much improved. Better to r

Re: CPython thread starvation

2012-04-27 Thread John Nagle
On 4/27/2012 9:55 PM, Paul Rubin wrote: John Nagle writes: I may do that to prevent the stall. But the real problem was all those DNS requests. Parallizing them wouldn't help much when it took hours to grind through them all. True dat. But building a DNS cache into the applic

Re: Learn Technical Writing from Unix Man in 10 Days

2012-04-29 Thread John O'Hagan
e sentence you quote sensibly obviates repeating the semantics of "install", which have just been described in detail in the immediately preceding paragraph. If it did repeat them, wouldn't you mock the docs anyway, for redundancy? Regards, -- John -- http://mail.python.org/mailman/listinfo/python-list

Re: confusing doc: mutable and hashable

2012-04-29 Thread John O'Hagan
ges, it will be in the wrong > hash bucket)." [...] How do function objects fit into this scheme? They have __hash__, __eq__, seem to work as dict keys and are mutable. Is it because their hash value doesn't change? Under what circumstances does an object's hash value change? -- John -- http://mail.python.org/mailman/listinfo/python-list

Re: CPython thread starvation

2012-04-29 Thread John Nagle
ot;Know who you're dealing with" system, SiteTruth.) John Nagle -- http://mail.python.org/mailman/listinfo/python-list

Re: why () is () and [] is [] work in other way?

2012-04-29 Thread John Nagle
r than Ada, which requires it, few languages handle such exceptions as language level exceptions. John Nagle -- http://mail.python.org/mailman/listinfo/python-list

Re: Creating a directory structure and modifying files automatically in Python

2012-04-30 Thread John Nagle
data storage. John Nagle -- http://mail.python.org/mailman/listinfo/python-list

Re: Converting a string to list for submission to easygui multenterb​ox

2012-05-01 Thread John Gordon
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', '

Re: Re: Converting a string to list for submission to easygui multenterb​ox

2012-05-01 Thread John Gordon
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', '

Re: Python SOAP library

2012-05-02 Thread John Nagle
edorahosted.org/suds/ John Nagle -- http://mail.python.org/mailman/listinfo/python-list

"

2012-05-03 Thread John Nagle
An HTML page for a major site (http://www.chase.com) has some incorrect HTML. It contains

Re: pyjamas / pyjs

2012-05-03 Thread John O'Hagan
o do in cases where the boss is too FOSS for your taste, or whatever the problem was. Seems like a great deal of hurt has occurred, both to people and to the project, just to save the administrative hassle of forking. In the words of the hijacker, he was going to fork but "an opportunity pr

Re: key/value store optimized for disk storage

2012-05-06 Thread John Nagle
That's awful. There's no point in compressing six characters with zlib. Zlib has a minimum overhead of 11 bytes. You just made the data bigger. John Nagle -- http://mail.python.org/mailman/listinfo/python-list

Re: Creating a directory structure and modifying files automatically in Python

2012-05-07 Thread John Nagle
system for a million item db is ridiculous even for prototyping. Right. Steve Bellovin wrote that back when UNIX didn't have any database programs, let alone free ones. John Nagle -- http://mail.python.org/mailman/listinfo/python-list

Re: Creating a directory structure and modifying files automatically in Python

2012-05-07 Thread John Nagle
On 5/7/2012 9:09 PM, Steve Howell wrote: On May 7, 8:46 pm, John Nagle wrote: On 5/6/2012 9:59 PM, Paul Rubin wrote: Javierwrites: Or not... Using directories may be a way to do rapid prototyping, and check quickly how things are going internally, without needing to resort to complex

How to get outer class name from an inner class?

2012-05-08 Thread John Gordon
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

Re: How to get outer class name from an inner class?

2012-05-08 Thread John Gordon
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

Re: Real time event accuracy

2012-05-10 Thread John O'Hagan
pyPortMidi as a way to send MIDI messages between software packages on the same computer." HTH, John -- http://mail.python.org/mailman/listinfo/python-list

Newbie naive question ... int() throws ValueError

2012-05-10 Thread John Terrak
be returned instead. """ Thanks for your help - and sorry again for such a naive question. John T. -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie naive question ... int() throws ValueError

2012-05-11 Thread John Terrak
Thank you all for your help. Greatly appreciated. John -- http://mail.python.org/mailman/listinfo/python-list

Minor gripe about module names

2012-05-12 Thread John O'Hagan
filename, turned out to really be called pyeca. Are there any rules about this kind of thing? (I did say "minor gripe".) -- John -- http://mail.python.org/mailman/listinfo/python-list

Re: Extracting DB schema (newbie Q)

2012-05-14 Thread John Gordon
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.

Re: Carbon Event Manager (Carbon.CarbonEvt module) - working?

2012-05-15 Thread John Gordon
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

Re: argparse - option with optional value

2012-05-17 Thread John O'Hagan
me this value is the editor > program to run. This looks like a job for 'const': parser.add_argument('-e', '--edit', help='open editor on log', nargs='?', const="$EDITOR") I think that does what you want. HTH, John -- http://mail.python.org/mailman/listinfo/python-list

How to generate only rotationally-unique permutations?

2012-05-18 Thread John O'Hagan
ss. I also get the feeling I'm barking up the wrong tree. Any suggestion? Thanks, -- John -- http://mail.python.org/mailman/listinfo/python-list

Re: How to generate only rotationally-unique permutations?

2012-05-19 Thread John O'Hagan
On Sat, 19 May 2012 09:15:39 +0100 Arnaud Delobelle wrote: > On 19 May 2012 06:23, John O'Hagan wrote: [...] > > > > How to generate only the distinct permutations of a sequence which are not > > rotationally equivalent to any others? More precisely, to generate only

Re: How to generate only rotationally-unique permutations?

2012-05-19 Thread John O'Hagan
On Sat, 19 May 2012 04:21:35 -0400 Zero Piraeus wrote: > : > > On 19 May 2012 01:23, John O'Hagan wrote: > > How to generate only the distinct permutations of a sequence which are not > > rotationally equivalent to any others? More precisely, to generate only the >

Re: serial module

2012-05-22 Thread John Nagle
9,200 baud is enough for you, don't worry about it. John Nagle -- http://mail.python.org/mailman/listinfo/python-list

Re: serial module

2012-05-22 Thread John Nagle
On 5/22/2012 2:07 PM, Paul Rubin wrote: John Nagle writes: If a device is registered as /dev/ttyUSBnn, one would hope that the Linux USB insertion event handler, which assigns that name, determined that the device was a serial port emulator. Unfortunately, the USB standard device classes

Re: escaping/encoding/formatting in python

2012-05-23 Thread John Nagle
ase of the first. For a quoted alternative to regular expression syntax, see SNOBOL or Icon. SNOBOL allows naming patterns, and those patterns can then be used as components of other patterns. SNOBOL is obsolete, but that approach produced much more readable code.

Re: Email Id Verification

2012-05-24 Thread John Nagle
It matches anything that looks like a mail user name followed by an @ followed by anything that looks more or less like a domain name. The domain name must contain at least one ".", and cannot end with a ".", which is not strictly correct but usually works.

Re: Object cleanup

2012-05-30 Thread John Gordon
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,

Re: sqlite INSERT performance

2012-05-30 Thread John Nagle
able, you may be approaching the problem incorrectly. John Nagle -- http://mail.python.org/mailman/listinfo/python-list

Re: Why does this leak memory?

2012-06-07 Thread John Gordon
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

Internationalized domain names not working with URLopen

2012-06-12 Thread John Nagle
ters in position 0-5: ordinal not in range(128) >>> The HTTP library is trying to put the URL in the header as ASCII. Why isn't "urllib2" handling that? What does "urllib2" want? Percent escapes? Punycode? John Nagle -- http://mail.python.org/mailman/listinfo/python-list

RE: network protocols

2012-06-13 Thread John Sutterfield
Tarek, There doesn't appear to be a function in stdlib to cover that particular case. Doug Hellman has a nice section on finding service info here: http://www.doughellmann.com/PyMOTW/socket/addressing.html It wouldn't be "built-in", but it looks like it would be pretty simple to get the in

Re: Internationalized domain names not working with URLopen

2012-06-13 Thread John Nagle
On 6/12/2012 11:42 PM, Andrew Berg wrote: On 6/13/2012 1:17 AM, John Nagle wrote: What does "urllib2" want? Percent escapes? Punycode? Looks like Punycode is the correct answer: https://en.wikipedia.org/wiki/Internationalized_domain_name#ToASCII_and_ToUnicode I haven't t

Threads vs subprocesses

2012-06-15 Thread John O'Hagan
em as subprocesses. That way there would be fewer threads, but each subprocess would be doing more work. My question is, on a single core machine, what are the pros and cons of threads vs subprocesses in a setup like this? Thanks, John -- http://mail.python.org/mailman/listinfo/python-list

Re: Threads vs subprocesses

2012-06-15 Thread John O'Hagan
On Fri, 15 Jun 2012 11:51:01 -0400 Dave Angel wrote: > On 06/15/2012 09:49 AM, John O'Hagan wrote: > > I have a program in which the main thread launches a number of CPU-intensive > > worker threads. For each worker thread two python subprocesses are started, [...] > &g

Re: Threads vs subprocesses

2012-06-16 Thread John O'Hagan
On Fri, 15 Jun 2012 16:34:57 -0400 Dennis Lee Bieber wrote: > On Sat, 16 Jun 2012 03:24:13 +1000, John O'Hagan > declaimed the following in > gmane.comp.python.general: > > > > I should have made it clear that I'm not using threads to speed anything

Re: Threads vs subprocesses

2012-06-17 Thread John O'Hagan
On Sat, 16 Jun 2012 13:27:45 -0400 Dennis Lee Bieber wrote: > On Sat, 16 Jun 2012 20:01:12 +1000, John O'Hagan > declaimed the following in > gmane.comp.python.general: > > > > > That looks like a possible way to do all the streams in a single thread, &

Re: Py3.3 unicode literal and input()

2012-06-18 Thread John Roth
3.x the equivalent of Python 2.x's input() function is eval(input()). It poses the same security risk: acting on unchecked user data. John Roth > jmf -- http://mail.python.org/mailman/listinfo/python-list

Re: feedparser hanging after I/O error

2011-06-03 Thread John Nagle
On 6/2/2011 4:40 AM, xDog Walker wrote: On Wednesday 2011 June 01 10:34, John Nagle wrote: I have a program which uses "feedparser". It occasionally hangs when the network connection has been lost, and remains hung after the network connection is restored. My solution is to downloa

Re: Lambda question

2011-06-05 Thread John Posner
n%count==0 ] print group('abcdefghij', 3) # ['abc', 'def', 'ghi', 'j'] print group('abcdefghijk' * 2, 7) # ['abcdefg', 'hijkabc', 'defghij', 'k'] print group('', 42) # [] -John -- http://mail.python.org/mailman/listinfo/python-list

Re: Dynamic Zero Padding.

2011-06-07 Thread John Posner
to try "new style" string formatting [1], which I think is better than the "old style" in this particular case: >>> "Testing {0:0{1}d}".format(42, 4) 'Testing 0042' >>> "Testing {0:0{1}d}".format(42, 9) '

Re: Of Functions, Objects, and Methods-I NEED HELP PLEASE

2011-06-08 Thread John Gordon
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, "

Re: Python 2.6 OR 3.2

2011-06-09 Thread John Gordon
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,

Re: Help with a piping error

2011-06-10 Thread John Gordon
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, &

Re: Function declarations ?

2011-06-13 Thread John Nagle
that's what "hoisted" means in this context.. John Nagle -- http://mail.python.org/mailman/listinfo/python-list

How do you copy files from one location to another?

2011-06-16 Thread John Salerno
Based on what I've read, it seems os.rename is the proper function to use, but I'm a little confused about the syntax. Basically I just want to write a simple script that will back up my saved game files when I run it. So I want it to copy a set of files/directories from a location on my C:\ drive

Re: integer to binary 0-padded

2011-06-17 Thread John S
On Jun 15, 9:33 am, Olivier LEMAIRE wrote: > You're right, I use Python 2.6.6 This works great in 2.6.5 and later (and probably earlier). You just have to number your placeholders. The first set of braces formats i (your value), the second set specifies the field with (i.e., 8): >>> for i in xra

Re: How do you copy files from one location to another?

2011-06-17 Thread John Salerno
On Jun 17, 2:25 am, Gregory Ewing wrote: > John Salerno wrote: > > I want it to copy a set of files/directories from a > > location on my C:\ drive to another directory on my E:\ drive. I don't > > want to rename or delete the originals, > > It sounds like shutil

Re: How do you copy files from one location to another?

2011-06-17 Thread John Salerno
On Jun 17, 2:23 pm, Terry Reedy wrote: > If you follow the second part of Greg's suggestion 'or one of the other > related function in the shutil module', you will find copytree() > "Recursively copy an entire directory tree rooted at src. " Yeah, but shutil.copytree says: "The destination dire

Re: How do you copy files from one location to another?

2011-06-17 Thread John Salerno
On Jun 17, 5:15 pm, Ethan Furman wrote: > John Salerno wrote: > > On Jun 17, 2:23 pm, Terry Reedy wrote: > > >> If you follow the second part of Greg's suggestion 'or one of the other > >> related function in the shutil module', you will find copytree

What's the best way to write this base class?

2011-06-17 Thread John Salerno
Let's say I'm writing a game (really I'm just practicing OOP) and I want to create a "Character" base class, which more specific classes will subclass, such as Warrior, Wizard, etc. Which of the following ways is better, or is there another way? Note: I have in mind that when a specific subclass (

Re: What's the best way to write this base class?

2011-06-18 Thread John Salerno
Whew, thanks for all the responses! I will think about it carefully and decide on a way. I was leaning toward simply assigning the health, resource, etc. variables in the __init__ method, like this: def __init__(self, name): self.name = name self.health = 50 self.resource = 10 I never

Re: What's the best way to write this base class?

2011-06-19 Thread John Salerno
On Jun 19, 8:52 pm, Chris Kaynor wrote: > Having a character class (along with possibly player character, non-player > character, etc), make sense; however you probably want to make stuff like > health, resources, damage, and any other attributes not be handles by any > classes or inheritance

Do we still need to inherit from "object" to create new-style classes?

2011-06-20 Thread John Salerno
I can't quite seem to find the answer to this anywhere. The book I'm reading right now was written for Python 3.1 and doesn't use (object), so I'm thinking that was just a way to force new-style classes in 2.x and is no longer necessary in 3.x. Is that right? (The documentation doesn't mention obj

Re: Do we still need to inherit from "object" to create new-style classes?

2011-06-20 Thread John Salerno
On Jun 20, 8:33 pm, Benjamin Kaplan wrote: > On Mon, Jun 20, 2011 at 6:26 PM, John Salerno wrote: > > I can't quite seem to find the answer to this anywhere. The book I'm > > reading right now was written for Python 3.1 and doesn't use (object), > > so I

PEP 8 and indentation of continuation lines

2011-06-20 Thread John Yeung
for the continuation lines? (There was also discussion of this in a comp.lang.python thread last year, subject: if, continuation and indentation, started May 27.) John Y. -- http://mail.python.org/mailman/listinfo/python-list

How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread John Salerno
I'm working on the Project Euler exercises and I'm stumped on problem 3: "What is the largest prime factor of the number 600851475143 ?" Now, I've actually written functions to get a list of the factors of any given number, and then another function to get the prime numbers from that list. It wor

Re: sorry, possibly too much info. was: Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread John Salerno
On Jun 21, 3:22 pm, Irmen de Jong wrote: > On 21-06-11 22:10, Irmen de Jong wrote: > [stuff] > > I didn't read the last paragraph of John's message until just now, and > now realize that what I wrote is likely way too much information for > what he asked. > I'm sorry. Next time I'll read everythin

Re: sorry, possibly too much info. was: Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread John Salerno
On Jun 21, 4:41 pm, Ian Kelly wrote: > On Tue, Jun 21, 2011 at 3:09 PM, John Salerno wrote: > > Don't worry, I was still unclear about what to do after reading all > > the responses, even yours! But one thing that made me feel better was > > that I wasn't havin

Re: sorry, possibly too much info. was: Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread John Salerno
::sigh:: Well, I'm stuck again and it has to do with my get_factors function again, I think. Even with the slight optimization, it's taking forever on 20! (factorial, not excitement) :) It's frustrating because I have the Python right, but I'm getting stuck on the math. The problem: "What is the

Re: sorry, possibly too much info. was: Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread John Salerno
On Jun 21, 9:09 pm, Paul Rubin wrote: > John Salerno writes: > > It's frustrating because I have the Python right, but I'm getting > > stuck on the math > > "What is the smallest positive number that is evenly divisible by all > > of the numbers f

Re: sorry, possibly too much info. was: Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread John Salerno
On Jun 21, 10:02 pm, Mel wrote: > John Salerno wrote: > > ::sigh:: Well, I'm stuck again and it has to do with my get_factors > > function again, I think. Even with the slight optimization, it's > > taking forever on 20! (factorial, not excitement)  :) It'

Re: doing cross platform file work

2011-06-22 Thread John Gordon
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

How do you print a string after it's been searched for an RE?

2011-06-23 Thread John Salerno
After I've run the re.search function on a string and no match was found, how can I access that string? When I try to print it directly, it's an empty string, I assume because it has been "consumed." How do I prevent this? It seems to work fine for this 2.x code: import urllib.request import re

Re: How do you print a string after it's been searched for an RE?

2011-06-23 Thread John Salerno
On Jun 23, 3:47 pm, Ian Kelly wrote: > On Thu, Jun 23, 2011 at 1:58 PM, John Salerno wrote: > > After I've run the re.search function on a string and no match was > > found, how can I access that string? When I try to print it directly, > > it's an empty strin

Re: How do you print a string after it's been searched for an RE?

2011-06-23 Thread John Salerno
On Jun 23, 4:47 pm, "Thomas L. Shinnick" wrote: > There is also >        print(match_obj.string) > which gives you a copy of the string searched.  See end of section > 6.2.5. Match Objects I tried that, but the only time I wanted the string printed was when there *wasn't* a match, so the match ob

Re: LDAP: How get all users belongs to a group.

2011-06-24 Thread John Gordon
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

Re: NEED HELP-process words in a text file

2011-06-24 Thread John Gordon
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

Re: what's the big deal for print()

2011-06-24 Thread John Gordon
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

<    1   2   3   4   5   6   7   8   9   10   >