Re: Writing a MUD Console

2011-07-22 Thread Jonathan Gardner
whirl! > That code is surprisingly simple. Let me write one that uses asyncore so that the looping can incorporate other async processes as well. -- Jonathan Gardner jgard...@jonathangardner.net -- http://mail.python.org/mailman/listinfo/python-list

Writing a MUD Console

2011-07-22 Thread Jonathan Gardner
character's name. 1 Traceback (most recent call last): File "./telnetsubprocess.py", line 17, in cmd = raw_input() EOFError Connection closed by foreign host. Any ideas on what is going on here? -- Jonathan Gardner jgard...@jonathangardner.net -- http://mail.python.org/mailman/listinfo/python-list

Re: Newby Python help needed with functions

2011-06-03 Thread Jonathan Gardner
dict.get(inp, None) That returned value is actually callable! That is, you can then do something like: fn("This is the input string") Of course, as you already know, you should test fn to see if it is None. If so, they typed in an option you don't recognize. Secondly

Re: continuing development on modules after they're installed

2010-12-10 Thread Jonathan Gardner
are just as trivial as the Unix ones.) Now, there is a link from the lib/python2.6/site-packages files to YourProject. (Or Python2.7 or whatever version you are using.) I'd also look at using Paster to create the package. It gives you a pretty decent setup for straight up Python packages. -- Jonathan Gardner jgard...@jonathangardner.net -- http://mail.python.org/mailman/listinfo/python-list

Re: using optparser

2010-10-16 Thread Jonathan Gardner
On Oct 16, 7:59 pm, jimgardener wrote: > hi > I have a program which I call  findmatch that expects these arguments > 1.a person name > 2.a group name > 3.an integer > 4.a float value > > I thought I would allow user to call this program either using options > or using positional arguments in a pr

Re: Class-level variables - a scoping issue

2010-10-12 Thread Jonathan Gardner
On Oct 10, 12:07 pm, John Nagle wrote: >      (If you want default values for an instance, you define them > in __init__, not as class-level attributes.) > I beg to differ. I've seen plenty of code where defaults are set at the class level. It makes for some rather nice code. I'm thinking of lxm

Re: Class-level variables - a scoping issue

2010-10-10 Thread Jonathan Gardner
On Oct 9, 10:30 pm, John Nagle wrote: >     Here's an obscure bit of Python semantics which > is close to being a bug: > >  >>> class t(object) : > ...     classvar = 1 > ... > ...     def fn1(self) : > ...         print("fn1: classvar = %d" % (self.classvar,)) > ...         self.classvar = 2 > ..

Re: to pass self or not to pass self

2010-03-16 Thread Jonathan Gardner
gs in the Python language proper, this is probably the most confusing thing for new programmers. Heck, even experienced programmers get tangled up because they project how they think things should work on to the Python model. The second most confusing thing is probably how objects get instantiated.

Re: NoSQL Movement?

2010-03-14 Thread Jonathan Gardner
On Sun, Mar 14, 2010 at 6:55 AM, D'Arcy J.M. Cain wrote: > On Sat, 13 Mar 2010 23:42:31 -0800 > Jonathan Gardner wrote: >> On Fri, Mar 12, 2010 at 11:23 AM, Paul Rubin wrote: >> > "D'Arcy J.M. Cain" writes: >> >> Just curious, what databas

Re: NoSQL Movement?

2010-03-13 Thread Jonathan Gardner
require reading as well as writing > remote parts of the disk, so buffering doesn't help avoid every disk > seek. > Plus the fact that your other DB operations slow down under the load. -- Jonathan Gardner jgard...@jonathangardner.net -- http://mail.python.org/mailman/listinfo/python-list

Re: Need advice on starting a Python group

2010-03-12 Thread Jonathan Gardner
ate whatever code your org has with Python, and manage and maintain that code so others can use it. Finally, advertise. The more people see "Python", the more they will be interested. Coca-cola and Pepsi are really good at this! -- Jonathan Gardner jgard...@jonathangardner.net -- http://mail.python.org/mailman/listinfo/python-list

Re: NoSQL Movement?

2010-03-12 Thread Jonathan Gardner
On Wed, Mar 3, 2010 at 2:41 PM, Avid Fan wrote: > Jonathan Gardner wrote: >> >> I see it as a sign of maturity with sufficiently scaled software that >> they no longer use an SQL database to manage their data. At some point >> in the project's lifetime, the data is

Re: start function in new process

2010-03-05 Thread Jonathan Gardner
def g(): >    pidID = os.fork() >    if pidID == 0: >        # child do something here >        f(2,3,c) You'll need to exit here -- not return. http://docs.python.org/library/os.html#os._exit >    else: >        # parent do something here >        print "Parent > >

Re: Evaluate my first python script, please

2010-03-04 Thread Jonathan Gardner
osts.append(hostname) It may be clearer to do set arithmetic as well. > if len(hosts) == 1: >        os.system("ssh -A " + hosts[0]) You probably want one of the os.exec* methods instead, since you aren't going to do anything after this. > else: >        print '\n'.join(hosts) Rather, the idiom is usually: for host in hosts: print host -- Jonathan Gardner jgard...@jonathangardner.net -- http://mail.python.org/mailman/listinfo/python-list

Re: PYTHONPATH and eggs

2010-03-03 Thread Jonathan Gardner
x27;ve seen this issue has been discussed elsewhere and flagged as a > problem (e.g. > http://mail.python.org/pipermail/distutils-sig/2009-January/010755.html) > > but I've been unable to find any suggestions for workarounds or > indications whether this will be/has been fixed. > Sounds li

Re: NoSQL Movement?

2010-03-03 Thread Jonathan Gardner
tood well enough that the general nature of the SQL database is unnecessary. -- Jonathan Gardner jgard...@jonathangardner.net -- http://mail.python.org/mailman/listinfo/python-list

Re: Generic singleton

2010-03-03 Thread Jonathan Gardner
On Wed, Mar 3, 2010 at 1:11 PM, mk wrote: > > Or I could make my life simpler and use global variable. :-) > Ding ding ding! 90% of Design Patterns is making Java suck less. Other languages don't necessarily suffer from Java's design flaws. -- Jonathan Gardner jgard...@

Re: Working group for Python CPAN-equivalence?

2010-03-03 Thread Jonathan Gardner
iencies in Perl that Python doesn't suffer from. I am sure we could do well not to replicate those features. Regardless, Python's packages are distributed in a number of ways. PyPI is only one of them. Fedora and Ubuntu are two other ways. -- Jonathan Gardner jgard...@jon

Re: Sort Big File Help

2010-03-03 Thread Jonathan Gardner
be appreciated. Thank you. > You may also want to look at the GNU tools "sort" and "cut". If your job is to process files, I'd recommend tools designed to process files for the task. -- Jonathan Gardner jgard...@jonathangardner.net -- http://mail.python.org/mailman/listinfo/python-list

Re: Docstrings considered too complicated

2010-02-24 Thread Jonathan Gardner
stuff""" > def doStuff(): >    while not wise(up): >        yield scorn > > Now my question is this: How do I kill these people without the > authorities thinking they didn't deserve it? > kill -9 seems to work for me. You may want to explain, one day, wh

Re: SMTPServerDisconnected

2010-02-23 Thread Jonathan Gardner
t; unix  2      [ ]         DGRAM                    10370 >  @/org/kernel/udev/udevd > unix  2      [ ]         DGRAM                    6077731 > unix  3      [ ]         STREAM     CONNECTED     6077679 > unix  3      [ ]         STREAM     CONNECTED     6077678 > unix  2      [ ]

Re: When will Python go mainstream like Java?

2010-02-22 Thread Jonathan Gardner
On Mon, Feb 22, 2010 at 1:56 PM, AON LAZIO wrote: > That will be superb > It already has. -- Jonathan Gardner jgard...@jonathangardner.net -- http://mail.python.org/mailman/listinfo/python-list

Re: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility.

2010-02-22 Thread Jonathan Gardner
th the statement-based approach. A minority understand let alone appreciate the functional approach. -- Jonathan Gardner jgard...@jonathangardner.net -- http://mail.python.org/mailman/listinfo/python-list

Re: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility.

2010-02-22 Thread Jonathan Gardner
On Sun, Feb 21, 2010 at 10:22 AM, John Bokma wrote: > Jonathan Gardner writes: >> On Fri, Feb 19, 2010 at 11:16 PM, Lie Ryan wrote: >>> >>> Now, why don't we start a PEP to make python a fully-functional language >>> then? >> >> Because peop

Re: Use eval() safely?

2010-02-22 Thread Jonathan Gardner
t string? > > Which Python built-ins and math functions would I have to add to > the functions dictionary to make it unsafe? > Why would you ever run untrusted code on any machine in any language, let alone Python? If you're writing a web app, make it so that you only run truste

Re: Can I make sqlite3 or shelve work reliably on any Win/Linux/Mac?

2010-02-22 Thread Jonathan Gardner
ls your code, he must also install the requisite modules that you list as dependencies. -- Jonathan Gardner jgard...@jonathangardner.net -- http://mail.python.org/mailman/listinfo/python-list

Re: Efficient way to break up a list into two pieces

2010-02-21 Thread Jonathan Gardner
On Sat, Feb 20, 2010 at 10:48 PM, Steven D'Aprano wrote: > On Sat, 20 Feb 2010 21:21:47 -0800, Jonathan Gardner wrote: >> For ten items, though, is it really faster to muck around with array >> lengths than just copying the data over? Array copies are extremely fast >

Re: if not global -- then what?

2010-02-20 Thread Jonathan Gardner
On Sat, Feb 20, 2010 at 5:53 PM, Steven D'Aprano wrote: > On Sat, 20 Feb 2010 17:34:15 -0800, Jonathan Gardner wrote: >> In terms of "global", you should only really use "global" when you are >> need to assign to a lexically scoped variable that is share

Re: Not sure why this is filling my sys memory

2010-02-20 Thread Jonathan Gardner
On Sat, Feb 20, 2010 at 5:53 PM, Vincent Davis wrote: >> On Sat, Feb 20, 2010 at 6:44 PM, Jonathan >> Gardner  wrote: >> >> With this kind of data set, you should start looking at BDBs or >> PostgreSQL to hold your data. While processing files this large is >>

Re: lists of variables

2010-02-20 Thread Jonathan Gardner
>> vars['b'] = 2 >>> mylist = ['a', 'b'] >>> print [vars[i] for i in mylist] # Here's your dereference [1,2] >>> vars['a'] = 3 >>> print [vars[i] for i in mylist] [3,2] -- Jonathan Gardner jgard...@jonathangardner.net -- http://mail.python.org/mailman/listinfo/python-list

Re: Efficient way to break up a list into two pieces

2010-02-20 Thread Jonathan Gardner
array lengths than just copying the data over? Array copies are extremely fast on modern processors. Programmer time and processor time being what it is, I still think my answer is the correct one. No, it's not what he says he wants, but it is what he needs. -- Jonathan Gardner jgard...@

Re: Not sure why this is filling my sys memory

2010-02-20 Thread Jonathan Gardner
cessing files this large is possible, it isn't easy. Your time is better spent letting the DB figure out how to arrange your data for you. -- Jonathan Gardner jgard...@jonathangardner.net -- http://mail.python.org/mailman/listinfo/python-list

Re: speed question, reading csv using takewhile() and dropwhile()

2010-02-20 Thread Jonathan Gardner
g. > It may be that the csvfile is reading the entire file in, rather than line-by-line. -- Jonathan Gardner jgard...@jonathangardner.net -- http://mail.python.org/mailman/listinfo/python-list

Re: /usr/bin/ld: cannot find -lz on Cent OS - Python 2.4

2010-02-20 Thread Jonathan Gardner
fferent version of libz than what's installed on your box. If so, you'll need to see if you can find the right version. The MySQL-python people should have more help for you. -- Jonathan Gardner jgard...@jonathangardner.net -- http://mail.python.org/mailman/listinfo/python-list

Re: if not global -- then what?

2010-02-20 Thread Jonathan Gardner
lexically scoped variable that is shared among other functions. For instance: def foo(): i = 0 def inc(): global i; i+=1 def dec(): global i; i-=1 def get(): return i return (inc, dec, get) This really isn't that common, although it is useful. Note that the above might be better organized into a class instance. Good luck. -- Jonathan Gardner jgard...@jonathangardner.net -- http://mail.python.org/mailman/listinfo/python-list

Re: speed question, reading csv using takewhile() and dropwhile()

2010-02-20 Thread Jonathan Gardner
is global state involved, you may want to save yourself some trouble in the future and put the above in a class where separate parsers can be kept separate. It looks like your program is turning into a regular old parser. Any format that is a little more than trivial to parse will need a real parser like the above. -- Jonathan Gardner jgard...@jonathangardner.net -- http://mail.python.org/mailman/listinfo/python-list

Re: Efficient way to break up a list into two pieces

2010-02-20 Thread Jonathan Gardner
assigning a slice the elements will be copied. > Basically, I'm looking for something like l1.pop(10,len(l1)) which > returns and removes a whole chunk of data. Is there such a thing (and > if not, why not?) > The idiom is: >>> l1, l2 = l1[:10], l1[10:] Don't know

Re: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility.

2010-02-20 Thread Jonathan Gardner
On Fri, Feb 19, 2010 at 11:16 PM, Lie Ryan wrote: > > Now, why don't we start a PEP to make python a fully-functional language > then? > Because people don't think the same way that programs are written in functional languages. -- Jonathan Gardner jgard...@jonath

Re: Scalable python dict {'key_is_a_string': [count, some_val]}

2010-02-19 Thread Jonathan Gardner
leneck is the 'sort' command. > > Any suggestions, comments? > You should be using BDBs or even something like PostgreSQL. The indexes there will give you the scalability you need. I doubt you will be able to write anything that will select, update, insert or delete data

Re: speed question, reading csv using takewhile() and dropwhile()

2010-02-19 Thread Jonathan Gardner
some mathematics on them and > compare different files. So my interest was in making it faster to open them > as needed. I guess part of it is that they are about 5mb so I guess it might > be disk speed in part.nks > > Record your numbers in an array and then work your magic on the

Re: Can't Access ANY url from python (errno 61)

2010-02-19 Thread Jonathan Gardner
> Are you running behind a firewall? See if Firefox is configured with a proxy. You'll have to use that to talk to any website. -- Jonathan Gardner jgard...@jonathangardner.net -- http://mail.python.org/mailman/listinfo/python-list

Re: Chaining 501 generators breaks everything?

2010-02-19 Thread Jonathan Gardner
n: if i%s == 0: break else: # Run if the for loop doesn't break seen.append(i) yield i start = time() for i in islice(primes(), 0, 1): print i print time() - start -- Jonathan Gardner jgard...@jonathangardner.net -- http://mail.python.org/mailman/listinfo/python-list

Re: speed question, reading csv using takewhile() and dropwhile()

2010-02-19 Thread Jonathan Gardner
doesn't mean you get to be silly in how you move data around. Avoid copies as much as possible, and try to avoid slurping in large files all at once. Line-by-line processing is best. I think you should invert this operation into a for loop. Most people tend to think of things better that w

Re: Creating Import Hooks

2010-02-18 Thread Jonathan Gardner
On Feb 18, 1:28 am, Sreejith K wrote: > On Feb 18, 1:57 pm, Steven D'Aprano > > > > wrote: > > On Thu, 18 Feb 2010 00:03:51 -0800, Jonathan Gardner wrote: > > > On Feb 17, 10:48 pm, Sreejith K wrote: > > >> Hi everyone, > > > >&

Re: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility.

2010-02-18 Thread Jonathan Gardner
On Feb 18, 3:04 pm, "sjdevn...@yahoo.com" wrote: > > You could do it without intermediate names or lambdas in Python as: > def print_numbers(): >     for i in [ cube for (square, cube) in >                          [(n*n, n*n*n) for n in [1,2,3,4,5,6]] >                if square!=25 and cube!=64 ]

Re: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility.

2010-02-18 Thread Jonathan Gardner
On Feb 18, 8:15 am, Steve Howell wrote: > >     def print_numbers() >         [1, 2, 3, 4, 5, 6].map { |n| >             [n * n, n * n * n] >         }.reject { |square, cube| >             square == 25 || cube == 64 >         }.map { |square, cube| >             cube >         }.each { |n| >    

Re: Help with lambda

2010-02-18 Thread Jonathan Gardner
On Feb 18, 4:28 am, lallous wrote: > > f = [lambda x: x ** n for n in xrange(2, 5)] This is (pretty much) what the above code does. >>> f = [] >>> n = 2 >>> f.append(lambda x: x**n) >>> n = 3 >>> f.append(lambda x: x**n) >>> n = 4 >>> f.append(lambda x: x**n) >>> n = 5 >>> f.append(lambda x: x**

Re: Creating Import Hooks

2010-02-18 Thread Jonathan Gardner
On Feb 17, 10:48 pm, Sreejith K wrote: > Hi everyone, > > I need to implement custom import hooks for an application > (http://www.python.org/dev/peps/pep-0302/). I want to restrict an application > to import certain modules (say socket module). Google app engine is > using a module hook to do th

Re: How to efficiently extract information from structured text file

2010-02-17 Thread Jonathan Gardner
On Feb 16, 3:48 pm, Imaginationworks wrote: > Hi, > > I am trying to read object information from a text file (approx. > 30,000 lines) with the following format, each line corresponds to a > line in the text file.  Currently, the whole file was read into a > string list using readlines(), then use

Re: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility.

2010-02-17 Thread Jonathan Gardner
On Feb 17, 12:02 am, Lawrence D'Oliveiro wrote: > In message <60b1abce-4381-46ab-91ed- > > f2ab2154c...@g19g2000yqe.googlegroups.com>, Andrej Mitrovic wrote: > > Also, lambda's are expressions, not statements ... > > Is such a distinction Pythonic, or not? For example, does Python distinguish > be

Re: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility.

2010-02-17 Thread Jonathan Gardner
On Feb 17, 12:02 am, Lawrence D'Oliveiro wrote: > In message > <8ca440b2-6094-4b35-80c5-81d000517...@v20g2000prb.googlegroups.com>, > > Jonathan Gardner wrote: > > I used to think anonymous functions (AKA blocks, etc...) would be a > > nice feature for Python. &

Re: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility.

2010-02-17 Thread Jonathan Gardner
On Feb 17, 10:39 am, John Bokma wrote: > Jonathan Gardner writes: > > Then I looked at a stack trace from a different programming language > > with lots of anonymous functions. (I believe it was perl.) > > > I became enlightened. > > If it was Perl [1], I doub

Re: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility.

2010-02-16 Thread Jonathan Gardner
On Feb 16, 11:41 am, Andrej Mitrovic wrote: > On Feb 16, 7:38 pm, Casey Hawthorne > wrote: > > > Interesting talk on Python vs. Ruby and how he would like Python to > > have just a bit more syntactic flexibility. > > >http://blog.extracheese.org/2010/02/python-vs-ruby-a-battle-to-the-de... > > --

Re: Time out a regular expression in Python 2.6.4?

2010-02-15 Thread Jonathan Gardner
On Feb 15, 7:59 am, Steve Holden wrote: > pyt...@bdurham.com wrote: > > Is there any way to time out a regular expression in Python 2.6.4? > > > Motiviation: Our application allows users to enter regular expressions > > as validation criteria. If a user enters a pathological regular > > expression

Re: Few Small Questions Regarding CGI

2010-02-15 Thread Jonathan Gardner
On Feb 15, 2:04 pm, joy99 wrote: > > I am trying to learn CGI. I was checking Python Docs. There are > multiple modules. Which one to start with? > Is there any other material or URL for step by step learning of CGI. > I would suggest skipping 15 years of internet progress and going with a more m

Re: Parsing for email addresses

2010-02-15 Thread Jonathan Gardner
On Feb 15, 3:34 pm, galileo228 wrote: > > I'm trying to write python code that will open a textfile and find the > email addresses inside it. I then want the code to take just the > characters to the left of the "@" symbol, and place them in a list. > (So if galileo...@gmail.com was in the file, '

Re: Please help with MemoryError

2010-02-11 Thread Jonathan Gardner
On Feb 11, 3:39 pm, Jeremy wrote: > I have been using Python for several years now and have never run into > memory errors… > > until now. > Yes, Python does a good job of making memory errors the least of your worries as a programmer. Maybe it's doing too good of a job... > My Python program no

Re: Is a merge interval function available?

2010-02-11 Thread Jonathan Gardner
On Feb 10, 3:23 pm, Peng Yu wrote: > I'm wondering there is already a function in python library that can > merge intervals. For example, if I have the following intervals ('[' > and ']' means closed interval as > inhttp://en.wikipedia.org/wiki/Interval_(mathematics)#Excluding_the_end...) > > [1,

Re: Need debugging knowhow for my creeping Unicodephobia

2010-02-10 Thread Jonathan Gardner
On Feb 10, 11:09 am, kj wrote: > > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 0: > ordinal not in range(128) > You'll have to understand some terminology first. "codec" is a description of how to encode and decode unicode data to a stream of bytes. "decode" means you

Re: PostgreSQL driver for Python applications that supports bytea correctly?

2010-02-09 Thread Jonathan Gardner
On Feb 9, 7:27 am, CyclingGuy wrote: > Can anyone recommend a PostgreSQL driver for Python that supports > selecting and inserting bytea types? > Can you name some that don't? -- http://mail.python.org/mailman/listinfo/python-list

Re: Python and Ruby

2010-02-09 Thread Jonathan Gardner
On Feb 9, 1:51 am, waku wrote: > 'stupid', 'wrong', 'deficient', 'terrible', ...  you're using strong > words instead of concrete arguments, it might intimidate your > opponents, but is hardly helpful in a fair discussion. > In today's day and age, I don't know how a text editor which cannot do s

Re: Python and Ruby

2010-02-04 Thread Jonathan Gardner
On Feb 3, 3:39 pm, Steve Holden wrote: > Robert Kern wrote: > > On 2010-02-03 15:32 PM, Jonathan Gardner wrote: > > >> I can explain all of Python in an hour; I doubt anyone will understand > >> all of Python in an hour. > > > With all respect, talking abou

Re: Python and Ruby

2010-02-03 Thread Jonathan Gardner
On Feb 2, 9:11 pm, John Bokma wrote: > Jonathan Gardner writes: > > I can explain, in an hour, every single feature of the Python language > > to an experienced programmer, all the way up to metaclasses, > > Either you're a hell of a talker, or I am far, far away f

Re: Python and Ruby

2010-02-02 Thread Jonathan Gardner
On Feb 1, 6:50 pm, Nobody wrote: > On Mon, 01 Feb 2010 14:13:38 -0800, Jonathan Gardner wrote: > > I judge a language's simplicity by how long it takes to explain the > > complete language. That is, what minimal set of documentation do you > > need to describe all of th

Re: Python and Ruby

2010-02-02 Thread Jonathan Gardner
On Feb 2, 7:23 am, "bartc" wrote: > Jonathan Gardner wrote: > > One of the bad things with languages like perl and Ruby that call > > without parentheses is that getting a function ref is not obvious. You > > need even more syntax to do so. In perl: > > >

Re: Python and Ruby

2010-02-02 Thread Jonathan Gardner
On Feb 1, 6:36 pm, John Bokma wrote: > Jonathan Gardner writes: > > One of the bad things with languages like perl > > FYI: the language is called Perl, the program that executes a Perl > program is called perl. > > > without parentheses is that getting a funct

Re: Python and Ruby

2010-02-02 Thread Jonathan Gardner
On Feb 1, 6:21 pm, Nobody wrote: > > You don't need to know the entire language before you can use any of it > (if you did, Python would be deader than a certain parrot; Python's dark > corners are *really* dark). > I'm curious. What dark corners are you referring to? I can't think of any. Especi

Re: Python and Ruby

2010-02-02 Thread Jonathan Gardner
On Feb 2, 2:21 am, waku wrote: > > for writing new code, it's not necessarily that helpful to be *forced* > to keep with strict indenting rules.  in early development phases, > code is often experimental, and parts of it may need to be blocked or > unblocked as the codebase grows, and for experime

Re: How to guard against bugs like this one?

2010-02-02 Thread Jonathan Gardner
On Feb 1, 6:34 pm, kj wrote: > > An innocuous little script, let's call it buggy.py, only 10 lines > long, and whose output should have been, at most two lines, was > quickly dumping tens of megabytes of non-printable characters to > my screen (aka gobbledygook), and in the process was messing up

Re: python admin abuse complaint

2010-02-02 Thread Jonathan Gardner
On Feb 2, 12:40 pm, Xah Lee wrote: > > (12:12:16 PM) xahlee: is hash={} and hash.clean() identical? > I think you mean hash.clear() instead of hash.clean() The answer is that "hash = {}" will create a new dict and assign it to "hash", while "hash.clear()" simply guts the dict that "hash" is poin

Re: For loop searching takes too long!

2010-02-02 Thread Jonathan Gardner
On Jan 29, 7:07 pm, Steven D'Aprano wrote: > On Fri, 29 Jan 2010 14:49:06 -0800, Jonathan Gardner wrote: > > On Jan 28, 3:52 pm, elsa wrote: > > >> I've got a problem with my program, in that the code just takes too > >> long to run. Here's what

Re: Python and Ruby

2010-02-01 Thread Jonathan Gardner
On Jan 31, 12:43 pm, Nobody wrote: > > If it was common-place to use Curried functions and partial application in > Python, you'd probably prefer "f a b c" to "f(a)(b)(c)" as well. > That's just the point. It isn't common to play with curried functions or monads or anything like that in computer

Re: Python and Ruby

2010-02-01 Thread Jonathan Gardner
On Jan 31, 3:01 am, rantingrick wrote: > On Jan 30, 10:43 am, Nobody wrote: > > > That's also true for most functional languages, e.g. Haskell and ML, as > > well as e.g. Tcl and most shells. Why require "f(x)" or "(f x)" if "f x" > > will suffice? > > yuck! wrapping the arg list with parenthesis

Re: Python and Ruby

2010-02-01 Thread Jonathan Gardner
On Jan 30, 8:43 am, Nobody wrote: > On Wed, 27 Jan 2010 15:29:05 -0800, Jonathan Gardner wrote: > > Python is much, much cleaner. I don't know how anyone can honestly say > > Ruby is cleaner than Python. > > I'm not familiar with Ruby, but most languages are cle

Re: For loop searching takes too long!

2010-01-29 Thread Jonathan Gardner
On Jan 28, 3:52 pm, elsa wrote: > > I've got a problem with my program, in that the code just takes too > long to run. Here's what I'm doing. If anyone has any tips, they'd be > much appreciated! > First of all, don't play with large lists. Large lists have a tendency to grow larger over time, un

Re: which one is faster?

2010-01-29 Thread Jonathan Gardner
On Jan 28, 10:29 pm, "Stephen.Wu" <54wut...@gmail.com> wrote: > str.find(targetStr) > str.index(targetStr) with exception > str.count(targetStr) > targetStr in str > > which is the fastest way to check whether targetStr is in str? > The fastest way of all is to forget about this and finish the res

Re: Threading issue with SQLite

2010-01-29 Thread Jonathan Gardner
On Jan 29, 8:37 am, Alan Harris-Reid wrote: > > Questions... > 1.  Is there a large overhead in opening a new SQLite connection for > each thread (ie. within each method)? Yes, but not as bad as some other DBs. > 2.  Is there any way to use the same connection for the whole class (or > should I

Re: Keyboard input

2010-01-29 Thread Jonathan Gardner
On Jan 29, 8:53 am, "Mr.SpOOn" wrote: > Hi, > I need to get keyboard input in a python program. I need it to let the > user choose some options, for example: > > 1) option 1 > 2) option 2 > 3) option 3 > > and then to input some data to the program. > > I'm using the raw_input method and it works

Re: Wrap a function

2010-01-28 Thread Jonathan Gardner
On Jan 28, 2:16 pm, Joan Miller wrote: > > There would be to make a function for each system command to use so it > would be too inefficient, and follow the problem with the quotes. > > The best is make a parser into a compiled language > Yeah, you could do that. Or you can simply rely on /bin/sh

Re: Wrap a function

2010-01-28 Thread Jonathan Gardner
On Jan 28, 10:20 am, Joan Miller wrote: > I've to call to many functions with the format: > > >>> run("cmd") > > were "cmd" is a command with its arguments to pass them to the shell > and run it, i.e. > > > > >>>  run("pwd") > or > >>> run("ls /home") > > Does anybody knows any library to help me

Re: python 3's adoption

2010-01-27 Thread Jonathan Gardner
On Jan 27, 4:25 pm, Paul Rubin wrote: > What about assert and pass? > If you're going to have statements, you're going to need the null statement. That's "pass". It could be renamed "null_statement" but "pass" is a better description. "None" and "pass" are cousins of sorts, since "None" is the n

Re: python 3's adoption

2010-01-27 Thread Jonathan Gardner
On Jan 27, 3:54 pm, Paul Rubin wrote: > Steven D'Aprano writes: > > always much better written with key rather than cmp: key adds an O(N) > > overheard to the sorting, while cmp makes sorting O(N**2). > > Whaa ..  No I don't think so. You're referring to the O(N**2) bit, right?

Re: python 3's adoption

2010-01-27 Thread Jonathan Gardner
On Jan 27, 12:36 am, Paul Rubin wrote: > Steven D'Aprano writes: > > Without becoming a purely functional language, you won't get rid of all > > statements. > > Why not?  GCC lets you use any statement in an expression: > >     #include > >     main() >     { >       int i, x, p=0; >       x = (

Re: python 3's adoption

2010-01-27 Thread Jonathan Gardner
On Jan 26, 10:12 pm, Steven D'Aprano wrote: > > I did too, when I first heard cmp was to be dumped. But I changed my mind > and now agree with the decision to drop cmp. Custom sorts are nearly > always much better written with key rather than cmp: key adds an O(N) > overheard to the sorting, while

Re: python 3's adoption

2010-01-27 Thread Jonathan Gardner
On Jan 27, 9:38 am, Luis M. González wrote: > > Please don't post more noise and ad hominem attacks to the group, Steve. > > "Ad hominem"? > Please, operor non utor lingua non notus per vulgaris populus. > Gratias ago vos... My rough, machine-assisted translation: "Don't try to use language that

Re: Python and Ruby

2010-01-27 Thread Jonathan Gardner
On Jan 27, 6:56 am, Roald de Vries wrote: > On Jan 27, 2010, at 2:01 PM, Jean Guillaume Pyraksos wrote: > > > What are the arguments for choosing Python against Ruby > > for introductory programming? > > I think the main difference is in culture, especially for   > *introductory* programming. To

Re: Python and Ruby

2010-01-27 Thread Jonathan Gardner
On Jan 27, 5:47 am, Simon Brunning wrote: > > I think Python is a little cleaner, but I'm sure you'd find Ruby fans > who'd argue the complete opposite. > Are you sure about that? There's a lot of line noise in Ruby. How are you supposed to pronounce "@@"? What about "{|..| ... }"? There's a lo

Re: Recommended "new" way for config files

2010-01-19 Thread Jonathan Gardner
On Jan 8, 2:54 pm, Ben Finney wrote: > Chris Rebert writes: > > JSON is one option:http://docs.python.org/library/json.html > > YAML http://en.wikipedia.org/wiki/YAML> is another contender. > Compared to JSON, it is yet to gain as much mind-share, but even more > human-friendly and no less expres

Re: PyQt event recognition

2010-01-13 Thread Jonathan Gardner
On Jan 13, 12:21 pm, Zabin wrote: > On Jan 14, 9:00 am, Zabin wrote: > > > I am a new pyqt programmer. I have a tab widget with lots of line > > edits, radiobuttons and combo boxes. I want to trigger a single sub > > the moment any one of these widgets listed are modified. I tried using > > the c

Re: Exception as the primary error handling mechanism?

2010-01-01 Thread Jonathan Gardner
On Jan 1, 12:43 am, a...@pythoncraft.com (Aahz) wrote: > In article , > Benjamin Kaplan   wrote: > >In Python, throwing exceptions for expected outcomes is considered > >very bad form [...] > > Who says that?  I certainly don't. Agreed. int("asdf") is supposed to return what, exactly? Any languag

Re: Bored.

2009-11-30 Thread Jonathan Gardner
On Nov 30, 2:14 pm, Necronymouse wrote: > Hello, I am learning python for about 2 years and I am bored. Not with > python but I have a little problem, when i want to write something I > realise that somebody had alredy written it! So i don´t want to make a > copy of something but i wanna get bette

Re: How would you design scalable solution?

2009-10-27 Thread Jonathan Gardner
On Oct 27, 10:10 am, Bryan wrote: > > How else to keep a record of every transaction, but not have the speed > of the > question "How many Things in Bucket x" depend on looking @ every > transaction > record ever made? You can have three different tables in your database: (1) The transaction log

Re: epydoc - can I provide multiple dirs to parse

2009-10-02 Thread Jonathan Gardner
On Oct 2, 11:38 am, Medi wrote: > Can I present multiple directories to epydoc to process. For example > > epydoc -option -option -option dir_1 dir_2 dir_3 > I know nothing of epydoc. However, it looks like it should be something like: epydoc -option dir_1 -option dir_2 -option dir_3 ...if a

Re: store encrypted data in sqlite ?

2009-10-02 Thread Jonathan Gardner
On Oct 2, 11:53 am, Stef Mientki wrote: > > Will this method work always ? > Are there better methods ? > I SQLite doesn't like raw data (with all its \0 glory), you're out of luck, unfortunately. Base64 encoding is a really good solution for places like this. You are aware, of course, of the da

Re: How python source code in large projects are organized?

2009-09-29 Thread Jonathan Gardner
On Sep 20, 8:19 am, Peng Yu wrote: > > I am wondering what is the best way of organizing python source code > in a large projects. There are package code, testing code. I'm > wondering if there has been any summary on previous practices. > (Sorry for the late reply.) My advice: Don't write big p

Re: Logging contents of IRC channel

2009-08-31 Thread Jonathan Gardner
On Aug 31, 10:23 am, devaru wrote: > I am new to Python. I want to log the activities in an IRC channel. > Any pointers regarding this would be of great help. How are you going to plug into the chat server to obtain the data? How will you store the data? The in between parts are really easy. --

Re: Does Class implements Interface?

2009-08-27 Thread Jonathan Gardner
On Aug 27, 3:09 pm, "Emanuele D'Arrigo" wrote: > On Aug 27, 9:42 pm, Jonathan Gardner > wrote: > > > Have you heard of duck typing? > > Yes. > > I was just wondering then if this has been somewhat dealt with and has > been wrapped in a neat package,

Re: Does Class implements Interface?

2009-08-27 Thread Jonathan Gardner
On Aug 27, 3:09 pm, "Emanuele D'Arrigo" wrote: > > Apologies, my fault, No apology is necessary. > I didn't explain that humans are out of the loop > entirely. It's only at runtime that the program obtains the class > object that might or might not conform to an expected interface. In > fact the

Re: Learning Python advanced features

2009-08-27 Thread Jonathan Gardner
On Aug 27, 5:13 am, jvpic wrote: > Hi, > > Learning Python, I understand the mechanism of : closure, __new__, > descriptors, decorators and __metaclass__, but I interrogate myself on > the interest of those technics ? > > May somebody explain me the interest ? > I assume you are asking, "Why do t

Re: Does Class implements Interface?

2009-08-27 Thread Jonathan Gardner
On Aug 27, 6:16 am, "Emanuele D'Arrigo" wrote: > Greetings everybody, > > let's say I have a Class C and I'd like to verify if it implements > Interface I. If I is available to me as a class object I can use > issubclass(C, I) and I can at least verify that I is a superclass of > C. There are a co

  1   2   3   >