Re: Is there any advantage to using a main() in python scripts?

2013-12-11 Thread marduk
I would agree with the previous post but also add that I've stopped calling the main function "main()" and usually give it a more descriptive name, such as "bake_cookies()" or whatever. I think that that makes it clearer what it's doing when used as a library and the 'if __name__ == '__main__'" a

Re: Sexism in the Ruby community: how does the Python community manage it?

2013-10-17 Thread marduk
On Wed, Oct 16, 2013, at 11:13 PM, Owen Jacobson wrote: [...] > 2. What kind of social pressure can we bring to bear to _keep_ Python's > package naming conventions as socially neutral as they are, if and when > some high-profile dirtbag decides this language is the best language? > How can w

Re: sub-classing datetime

2013-02-07 Thread marduk
On Thu, Feb 7, 2013, at 10:13 AM, Colin J. Williams wrote: > I'm just making the transition from 2 to 3 for one module. > > With Python 2.7, I had the benefit of mx datetime, but this is not yet > available for Python 3.2. > > I find that the 3.2 datetime is not subclassable, for reasons that

Re: Issue with my code

2013-02-05 Thread marduk
On Tue, Feb 5, 2013, at 04:37 PM, darnold wrote: > On Feb 5, 2:19 pm, maiden129 wrote: > > How to reverse the two loops? > > > > s=input("Enter a string, eg(4856w23874): ") > > checkS=['0','1','2','3','4','5','6','7','8','9'] > > for digit in checkS: > t = s.count(digit) > if t == 0:

Re: Issue with my code

2013-02-05 Thread marduk
On Tue, Feb 5, 2013, at 01:38 PM, maiden129 wrote: > Hi, > > I'm trying to create this program that counts the occurrences of each > digit in a string which the user have to enter. > > Here is my code: > > s=input("Enter a string, eg(4856w23874): ") > s=list(s) > > checkS=['0','1','2','3','4'

Re: How to tell how many weeks apart two datetimes are?

2013-01-08 Thread marduk
On Tue, Jan 8, 2013, at 04:22 PM, Roy Smith wrote: > How do you tell how many weeks apart two datetimes (t1 and t2) are? > The "obvious" solution would be: > > weeks = (t2 - t1) / timedelta(days=7) > > but that doesn't appear to be allowed. Is there some fundamental > reason why timedelta divi

Re: Over 30 types of variables available in python ?

2013-01-07 Thread marduk
So I guess if one *really* wanted to compare C variables to Python variables, you could say that all python variables are of type void* except Python does all mallocs/frees and the casting for you. -- http://mail.python.org/mailman/listinfo/python-list

Re: Problem with Unicode char in Python 3.3.0

2013-01-06 Thread marduk
On Sun, Jan 6, 2013, at 11:43 AM, Franck Ditter wrote: > Hi ! > I work on MacOS-X Lion and IDLE/Python 3.3.0 > I can't get the treble key (U1D11E) ! > > >>> "\U1D11E" > SyntaxError: (unicode error) 'unicodeescape' codec can't > decode bytes in position 0-6: end of string in escape sequence >

Re: Iterating over files of a huge directory

2012-12-17 Thread marduk
On Mon, Dec 17, 2012, at 10:28 AM, Gilles Lenfant wrote: > Hi, > > I have googled but did not find an efficient solution to my problem. My > customer provides a directory with a hge list of files (flat, > potentially 10+) and I cannot reasonably use os.listdir(this_path) > unless creatin

Re: the one python book

2007-08-04 Thread marduk
On Sat, 2007-08-04 at 15:10 +, Michael Tobis wrote: > Like most people I eventually plan to read Moby Dick, War and Peace, > and Lutz's Programming Python. Maybe when I retire. LOL. Lutz's Programming Python is actually how I learned Python. -- http://mail.python.org/mailman/listinfo/python

Re: Berkely Db. How to iterate over large number of keys "quickly"

2007-08-02 Thread marduk
On Thu, 2007-08-02 at 19:43 +, lazy wrote: > I have a berkely db and Im using the bsddb module to access it. The Db > is quite huge (anywhere from 2-30GB). I want to iterate over the keys > serially. > I tried using something basic like > > for key in db.keys() > > but this takes lot of time.

Re: space / nonspace

2007-07-22 Thread marduk
On Sun, 2007-07-22 at 22:33 +0200, Peter Kleiweg wrote: > >>> import re > >>> s = u'a b\u00A0c d' > >>> s.split() > [u'a', u'b', u'c', u'd'] > >>> re.findall(r'\S+', s) > [u'a', u'b\xa0c', u'd'] > If you want the Unicode interpretation of \S+, etc, you pass the re.UNICODE fl

Re: A way to re-organize a list

2007-07-19 Thread marduk
On Thu, 2007-07-19 at 15:05 +, beginner wrote: > Hi Everyone, > > I have a simple list reconstruction problem, but I don't really know > how to do it. > > I have a list that looks like this: > > l=[ ("A", "a", 1), ("A", "a", 2), ("A", "a", 3), ("A", "b", 1), ("A", > "b", 2), ("B", "a", 1), (

Re: In a dynamic language, why % operator asks user for type info?

2007-07-16 Thread marduk
On Mon, 2007-07-16 at 17:33 -0700, Karthik Gurusamy wrote: > Thanks. The above surprised me as I didn't expect that %s will accept > 42. > > Looks like the implicit conversion doesn't work the other way. > > >>> '%s' % 42 > '42' > >>> '%d' % '42' > Traceback (most recent call last): > File "",

Re: Break up list into groups

2007-07-16 Thread marduk
On Mon, 2007-07-16 at 16:31 -0500, marduk wrote: > Assuming you meant '0xF0' instead of '0x80' do you mean any value > >=240 starts a new group? If so: > > groups = [] > current = [] # probably not necessary, but as a safety > for i i

Re: Break up list into groups

2007-07-16 Thread marduk
On Mon, 2007-07-16 at 14:11 -0700, [EMAIL PROTECTED] wrote: > I can't seem to find an answer to this question anywhere, but I'm > still looking. My problem is I have a list of values like this: > > l = [0xF0, 1, 2, 3, 0xF0, 4, 5, 6, 0xF1, 7, 8, 0xF2, 9, 10, 11, 12, > 13, 0xF0, 14, 0xF1, 15] > > A

Re: Best method for inter process communications

2007-07-16 Thread marduk
On Mon, 2007-07-16 at 17:22 +, JamesHoward wrote: > I am looking for a way of performing inter process communication over > XML between a python program and something else creating XML data. > > What is the best way of performing this communication? I could bind a > socket to localhost and pe

Re: How to pop random item from a list?

2006-03-09 Thread marduk
On Thu, 2006-03-09 at 21:59 -0800, flamesrock wrote: > Hi, > > It's been a while since I've played with python. > > My question is... whats the best way to pop a random item from a list?? import random # ... item = mylist.pop(random.randint(0,len(mylist))) -- http://mail.python.org/mailman/l

Re: is parameter an iterable?

2005-11-15 Thread marduk
On Tue, 2005-11-15 at 11:01 -0800, py wrote: > I have function which takes an argument. My code needs that argument > to be an iterable (something i can loop over)...so I dont care if its a > list, tuple, etc. So I need a way to make sure that the argument is an > iterable before using it. I kno

Re: strip not working on strings?

2005-11-13 Thread marduk
On Sun, 2005-11-13 at 13:16 -0800, [EMAIL PROTECTED] wrote: > I'm using Python 2.3.5 and when I type the following in the interactive > prompt I see that strip() is not working as advertised: > > >>>s = 'p p:p' > >>>s.strip(' :') > 'p p:p' > > Is this just me or does it not work? I want to get ri

Re: I Need Motivation Part 2

2005-11-04 Thread marduk
On Fri, 2005-11-04 at 17:06 +0100, Magnus Lycka wrote: > If Python appears more complex > than C++, you must be using a really weird approach. Or a really weird editor ;-) -m > -- http://mail.python.org/mailman/listinfo/python-list

Re: pickle

2005-10-25 Thread marduk
On Mon, 2005-10-24 at 23:55 -0700, Shi Mu wrote: > I got a sample code and tested it but really can not understand the > use of pickle and dump: > > >>> import pickle > >>> f = open("try.txt", "w") > >>> pickle.dump(3.14, f) > >>> pickle.dump([1,2,3,4], f) > >>> f.close() The pickle module "seria

Re: grep

2005-10-25 Thread marduk
On Tue, 2005-10-25 at 06:45 +, David Isaac wrote: > What's the standard replacement for the obsolete grep module? AFAIK there never was a "grep" module. There does, however exist a deprecated "regex" module: >>> import regex __main__:1: DeprecationWarning: the regex module is deprecated; ple

Re: piping out binaries properly

2005-10-11 Thread marduk
On Wed, 2005-10-12 at 00:16 -0400, Mike Meyer wrote: [...] > It's not normal to write binary content to stdout - you normally write > it to a file. Open the file with open(name, 'wb') to write binaries. > It is interesting that as a "Unix consultant" you should make that claim. Especially since

Re: Let My Terminal Go

2005-10-10 Thread marduk
On Mon, 2005-10-10 at 22:58 -0700, [EMAIL PROTECTED] wrote: > Hello, > > A user of my application points me to a behavior in gVim, > the text editor, that I would like to implement in my > application. > > When gVim is launched from a shell terminal, it completely > frees the terminal. You can co

Re: how to keep collection of existing instances and return one on instantiation

2005-10-05 Thread marduk
On Wed, 2005-10-05 at 19:24 +0200, Peter Otten wrote: > Use a weakref.WeakValueDictionary as the cache instead of a normal > dict. > > Peter Thanks for the reference to the weakref module. Until now I've never had a use for it, but it sounds like what I'm looking for. -m -- http://mail.pytho

Re: how to keep collection of existing instances and return one on instantiation

2005-10-05 Thread marduk
On Wed, 2005-10-05 at 19:37 +0200, Diez B. Roggisch wrote: > > What I wanted is multiple calls to create a new object with the same > > parameters points to the "original" object instead of creating a new > > one. > > Read the comments. What you say is essentially the same - the data > matters, a

Re: how to keep collection of existing instances and return one on instantiation

2005-10-05 Thread marduk
On Wed, 2005-10-05 at 12:56 -0400, Jonathan LaCour wrote: > > class Spam(object): > > cache = {} > > def __new__(cls, x): > > if cls.cache.has_key(x): > > return cls.cache[x] > > def __init__(self, x): > > self.x = x > > self.cache[x] = self > > > > a

Re: how to keep collection of existing instances and return one on instantiation

2005-10-05 Thread marduk
On Wed, 2005-10-05 at 18:28 +0200, Diez B. Roggisch wrote: > Use the BORG-pattern. See > > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531 > > Together with your caching, that should do the trick. > I looked at the Borg Pattern, but I don't think it was exactly what I want. Th

Re: how to keep collection of existing instances and return one on instantiation

2005-10-05 Thread marduk
On Wed, 2005-10-05 at 12:56 -0400, Jonathan LaCour wrote: > Oops, you forgot to return object.__new__(cls, x) in the case the > object isn't in the cache. That should fix it. Ahh, that did it. I didn't even think of calling object... so the new class looks like: class Spam(object): cach

how to keep collection of existing instances and return one on instantiation

2005-10-05 Thread marduk
I couldn't think of a good subject.. Basically, say I have a class class Spam: def __init__(self, x): self.x = x then if I create two instances: a = Spam('foo') b = Spam('foo') a == b # False What I *really* want is to keep a collection of all the Spam instances, and if i try to

Re: Jargons of Info Tech industry

2005-10-04 Thread marduk
[Removed X-posting] On Tue, 2005-10-04 at 17:14 +, Roedy Green wrote: > On Tue, 23 Aug 2005 08:32:09 -0500, l v <[EMAIL PROTECTED]> wrote or quoted : > > >I think e-mail should be text only. > > I disagree. Your problem is spam, not HTML. Spam is associated with > HTML and people have in

Re: "no variable or argument declarations are necessary."

2005-10-04 Thread marduk
On Tue, 2005-10-04 at 11:43 -0700, Paul Rubinhttp: wrote: > What's the big deal? Perl has an option for flagging undeclared > variables with warnings ("perl -w") or errors ("use strict") and Perl > docs I've seen advise using at least "perl -w" routinely. Those > didn't have much impact. Python

Re: "no variable or argument declarations are necessary."

2005-10-03 Thread marduk
> egold = 0: > while egold < 10: > if test(): > ego1d = egold + 1 > Both pylint and pychecker pick this up. I wrapped the code in a function (to prevent importing from running in an infinite loop) and ran both pylint and pychecker: plyint: W: 5:myfunc: Unused variable 'ego1d' py

Re: Class Help

2005-10-01 Thread marduk
On Sat, 2005-10-01 at 18:58 -0400, Ivan Shevanski wrote: > To continue with my previous problems, now I'm trying out classes. But I > have a problem (which I bet is easily solveable) that I really don't get. > The numerous tutorials I've looked at just confsed me.For intance: > > >>>class Xyz:

Re: What is "self"?

2005-09-22 Thread marduk
On Thu, 2005-09-22 at 21:36 -0400, Wayne Sutton wrote: > OK, I'm a newbie... > I'm trying to learn Python & have had fun with it so far. But I'm having > trouble following the many code examples with the object "self." Can > someone explain this usage in plain english? "self" references the ob

Re: FTP status problems. (Again)

2005-09-16 Thread marduk
On Sat, 2005-09-17 at 04:42 +, marduk wrote: > > ... and I haven't tried this myself, but you should be able to subclass > the builtin file object and prepare your own read() method. Something > like > > class ProgressFile(file): > > def read(self,

Re: FTP status problems. (Again)

2005-09-16 Thread marduk
On Fri, 2005-09-16 at 19:27 -0700, Nainto wrote: > Hello, I have posted before about trying to find the status of an FTP > uplaod but couldn't get anything to work. After some more searching I > found > http://groups.google.com/group/comp.lang.python/browse_thread/thread/76be9a994547db4/91917c906cd

Re: Problems with os.system

2005-09-02 Thread marduk
On Fri, 2005-09-02 at 13:45 -0700, alexLIGO wrote: > Hi, > > I am trying to run a python script that executes several other programs > on the bash (under linux) and reads some of the output of those > programs. This works fine for a couple of os.system() calls, but then > it does not work anymore.