Re: Parsing a search string
Freddie wrote: I'm trying to parse a search string so I can use it for SQL WHERE constraints, preferably without horrifying regular expressions. Uhh yeah. If you're interested, I've written a function that parses query strings using a customizable version of Google's search syntax. Features include: - Binary operators like OR - Unary operators like '-' for exclusion - Customizable modifiers like Google's site:, intitle:, inurl: syntax - *No* query is an error (invalid characters are fixed up, etc.) - Result is a dictionary in one of two possible forms, both geared towards being input to an search method for your database I'd be glad to post the code, although I'd probably want to have a last look at it before I let others see it... -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: What can I do with Python ??
Alex Martelli wrote: You _gotta_ be kidding, right...? The Beginner's Guide link takes you right to the BeginnersGuide page which starts with the reassurance that Python is easy to learn even if you're new to programming and continues with a zillion useful links. The Python Books link takes you to a huge While I agree that there is much useful content on the official Python site, I particularly hate the BeginnersGuide and much of the resulting introduction pages. Often when I happily refer Python to someone who wants to learn a simple language, I go to the Python site and imagine where I would start if I were them. Once I get to the BeginnersGuide I don't see anything immediately useful, and when I look for it I get frustrated. -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: alternatives to mod python
Anyone have any suggestions? The only other thing I looked at was twisted, which I'm still evaluating. Might as well check out CherryPy as well. www.cherrypy.org Might turn out to be simpler for your needs. -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: advice needed for simple python web app
Dan Perl wrote: Basically, what I'm looking for is a web server that accepts an HTTP request and invokes a python script. But I would like a "pythonic" solution so a web server like Apache is a solution that I would like to avoid. The server should also be as simple as possible to administrate. As M.E.Farmer suggested, CherryPy is definitely what you are looking for. I have done a bit of shopping around and this is pretty much as straightforward as you can get. From my experience, this appears to be the order from low-level to high-level interfaces: 1. mod_python: As complex as you need it to be, since you can control anything about the request & response process. But more up-front work and decisions to make than CherryPy. 2. mod_python with Vampire: Directs you toward a specific publishing framework that is similar to CherryPy. 3. CherryPy: Like Vampire but simpler and doesn't require mod_python. The simplest blend between low-level server interface and ease-of-publishing. 4. Twisted: Seems like this is a big package to work with, not sure how easy it makes publishing once you get started-- better that someone else comment on this. 5. Zope: The most complex solution, doesn't necessarily make the 'easy things easy.' But covers all fronts in terms of what a user would ever need. 6. Zope with Plone: Adds a ton of publishing functionality. Has many ways to extend, but none of them are fun. You'll have to learn such complex APIs that Python will rarely help you. Of course there are more, like Webware, but you didn't mention that and I don't have experience with it. -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: OT: why are LAMP sites slow?
Refactoring a database on a live system is a giant pain in the ass,
simpler file-based approaches make incremental updates easier.
The Wikipedia example has been thrown around, I haven't looked at the
code either; except for search why would they need a database to
look up an individual WikiWord? Going to the database requires reading
an index when pickle.load(open('words/W/WikiWord')) would seem sufficient.
I'm not so sure about this. If whatever is at, for example,
words/W/WikiWord is just the contents of the entry, sure. But what about
all the metadeta that goes along with that record? If you were to add a
new field that is mandatory for all word records, you'd have to traverse
the words directory and update each file, and that would require your
own home-spun update scripts (of questionable quality). Worse, if the
modifications are conditional.
As much as I hate working with relational databases, I think you're
forgetting the reliability even the most poorly-designed database
provides. Continuing with the words example: assuming all words would
otherwise be stored in a table, consider the process of updating the
database schema--all entries are guaranteed to conform to the new
schema. With separate files on a filesystem, there is a much higher
chance of malformed or outdated entries. Of course, this all depends on
how reliable your implementation is, but consider which aspect you'd
rather leave open to experimentation: loss of data integrity and
possibly even data itself, or speed and efficiency?
--
Brian Beck
Adventurer of the First Order
--
http://mail.python.org/mailman/listinfo/python-list
Re: How do I access avariable named "return"?
> I think this seems to be a problem due to the use of a forbidden word. But I > have no chance to change the WSDL definition, so: How can I get the > variable resp.return? Any suggestions? To get it: getattr(resp, 'return') To set it: setattr(resp, 'return', value) -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: string methods
anthonyberet wrote: > I know this touches on immutability etc, but I can't find string methods > to return the first 3 characters, and then the last 2 characters, which > I could concatenate with newchar to make a new string. As tiissa said, you want slicing: py> s = "foobar" py> s[:3] 'foo' py> s[:3] + "B" + s[4:] 'fooBar' py> -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: [path-PEP] Path inherits from basestring again
Ivan Van Laningham wrote: > I like / as a shortcut to joinwith(). I like it a lot. I like it so > much I'll give you a +2. +1 here. Extremely practical. -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting not derived members of a class
George Sakkis wrote: >>>>z = Z() >>>>z.__class__.__mro__ > > (, , , > , ) > > Old style classes don't have __mro__, so you have to write it yourself; > in any case, writing old style classes in new code is discouraged. Notice also that George's __mro__ solution returns the bases in reverse order than what you requested (in your example, you said B should come last). So use list(reversed(z.__class__.__mro__)) or z.__class__.__mro__[::-1] -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: Path as a dictionary tree key? (was Re: PEP on path module for standard library)
Ron Adam wrote: > This give a more general purpose for path objects. Working out ways to > retrieve path objects from a dictionary_tree also would be useful I > think. I think a Tree class would also be a useful addition as well. > > Any thoughts on this? I don't think this would be as useful as you think, for Path objects at least. Path objects represent *a* path, and building a tree as you have proposed involves storing much more information than necessary. For instance, if I have the path /A/B/X, a tree-structured object would logically also store the siblings of X and B (subpaths of B and A). -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: Application Error (referenced error)
David Blomstrom wrote: > I downloaded a content management system called Plone > and get the following error message when I try to > start it: Plone isn't a stand-alone application, it's a skin and collection of products for the Zope application server. You'll have to get Zope up and running before you can use Plone. See www.zope.org. There are also specific mailing lists (on Gmane, www.gmane.org) dedicated to Zope, Plone, and their related packages. -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: Application Error (referenced error)
David Blomstrom wrote: > This is my first post on this list, and I'm new to > Python. Oh, and I forgot to mention: welcome to Python and our community! -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: Python -- (just) a successful experiment?
Eric Pederson wrote: > Raise your hand if you think the best technology wins! > > > For those of you with your hands in the air, tell me: if Python is so good, > why has PHP achieved such greater adoption and mindshare? Why do web > scripters still cling to their Perl, even in corporate environments? Why > hasn't Python made inroads against Java? Why is Ruby, and Ruby on Rails, > getting such strong play? > > Are these better programming languages, or is it other factors? You make some good points and I agree that more needs to be done to make python accessible, but you basically ruined the rest of your post right off the bat. Replace Python with, say, Linux and PHP with, say, Windows. How the respective technologies got where they are today is not important to the analogy (except maybe being in the right place at the right time). There is such a huge counter-example of "the best technology wins" staring everyone in the face every day, that the first part of your post doesn't really do anything for me. But ultimately I am on your side. Python has a long way to go, and it has nothing to do with the language design... -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: Iterate through dictionary of file objects and file names
Julian Yap wrote:
In this particular coding snippet, I was thinking of creating a
dictionary of file objects and file names. These would be optional
files that I could open and parse. At the end, I would easily close off
the files by iterating through the dictionary.
Hi,
File objects as keys sounds pretty dangerous. I'm curious why the first
thought that popped into your head wasn't using the file NAMES as keys
instead? Here's my go at it. (Is Google Groups nice to indentation using
spaces? I can't remember.)
optionalFiles = dict.fromkeys(['areacode.11', 'build.11'], None)
# To open optionalFiles...
for fileName in optionalFiles:
try:
optionalFiles[fileName] = open(fileName, "r")
print "Opened: %s" % fileName
except IOError:
# Values are already initialized to None.
print "File not found: %s" % fileName
# To close optionalFiles...
for fileName, fileObject in optionalFiles.iteritems():
if fileObject:
fileObject.close()
print "Closed: %s" % fileName
# Rebinding fileObject here won't modify the dictionary,
# so access it through the key.
optionalFiles[fileName] = None
--
Brian Beck
Adventurer of the First Order
--
http://mail.python.org/mailman/listinfo/python-list
Re: Iterate through dictionary of file objects and file names
jfj wrote: Call me a pedant, but what'd wrong with: print 'closed: ' + filename or print 'closed:', filename ? I always figure that debug-oriented output like that in example code is very likely to be changed in format, or to include more information, by the person actually using it. So string substitution makes it more flexible; less work for them. -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: builtin functions for and and or?
Roose wrote:
I need this a lot: a one line way to do a n-ary and or 'or'.
Looks like there are itertools recipes for those, similar to what
Michael just posted. Taken from here:
http://docs.python.org/lib/itertools-recipes.html
def all(seq, pred=bool):
"Returns True if pred(x) is True for every element in the iterable"
for elem in ifilterfalse(pred, seq):
return False
return True
def any(seq, pred=bool):
"Returns True if pred(x) is True for at least one element in the
iterable"
for elem in ifilter(pred, seq):
return True
return False
--
Brian Beck
Adventurer of the First Order
--
http://mail.python.org/mailman/listinfo/python-list
Re: builtin functions for and and or?
Brian Beck wrote: def all(seq, pred=bool): "Returns True if pred(x) is True for every element in the iterable" for elem in ifilterfalse(pred, seq): return False return True def any(seq, pred=bool): "Returns True if pred(x) is True for at least one element in the iterable" for elem in ifilter(pred, seq): return True return False I should probably note, you'll have to from itertools import ifilter, ifilterfalse to use these. -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: builtin functions for and and or?
Roose wrote: I need this a lot: a one line way to do a n-ary and or 'or'. Here's a one-liner for the n-ary and: bool(min(bool(x) for x in L)) py> bool(min(bool(x) for x in [1, 1, 1, 0])) False py> bool(min(bool(x) for x in [1, 1, 1, 1])) True py> bool(min(bool(x) for x in ['a', '', 'b', 'c'])) False py> bool(min(bool(x) for x in ['a', 'b', 'c', 'd'])) True -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: builtin functions for and and or?
Steven Bethard wrote: Another alternative: not False in (bool(x) for x in L) Note that this should short-circuit, where min won't. Steve Whoops, for some reason the thought that short-circuiting didn't apply to And entered my mind while trying to post a nice solution. Hard to say why considering I have to do stuff like this on a daily basis! Ignore mine except as a novelty, then. -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: builtin functions for and and or?
George Sakkis wrote: You're right, it doesn't short circuit, as most of the examples posted above. Here's one that it does: ... I also looked into taking advantage of itertools' dropwhile, but the all and any recipes included in the itertools documentation do short-circuit and don't require the setup of a try/except/else. -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: [EVALUATION] - E02 - Support for MinGW Open Source Compiler
Ilias Lazaridis wrote: > this answer do not fit in most questions. > > please review them again. Actually, it does. Please review them again. My questions: > a) Why does the Python Foundation not provide additionally a binary version, compiled with MinGW or another open-source compiler? Because no one has yet volunteered their time and effort to get the job done. b) Why does the Python Foundation not ensure, that the python source-code is directly compilable with MinGW? Because no one has yet volunteered their time and effort to get the job done. c) Why are the following efforts not _directly_ included in the python source code base? Because no one has yet volunteered their time and effort to get the job done. d) Is it really neccessary that I dive into such adventures, to be able to do the most natural thing like: "developing python extensions with MinGW"? Yes, because no one has yet volunteered their time and effort to get the job done. f) Are there any official (Python Foundation) statements / rationales available, which explain why the MinGW compiler is unsupported, although parts of the community obviously like to use it? The most likely response you will get is: Because no one has yet volunteered their time and effort to get the job done. I ask some questions and suggest some things. Voluntarlily and without beeing paid. What a martyr you are. There are many commercial systems around python. So please stop this volunteerism-stuff. If the support you're looking for is beneficial to your commercial application a.k.a. business, then why aren't you making it happen? Obviously the existing commercial development teams are doing fine without it, otherwise it would exist. Even then, a commercial developer providing their development work to enhance the standard Python distribution IS volunteering. -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: super not working in __del__ ?
Duncan Booth wrote: There was one, but for some reason you trimmed it out of your quote: The original code before you trimmed it was: Look carefully, he was commenting on the contents of class Base (which does omit the line he suggests), not class B. Whether he's correct or not, I'm not wizardly enough to comment on. -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting milliseconds in Python
mjs7231 wrote: This is no good, I am looking for milliseconds, not seconds.. as stated above. That IS what you want. seconds * 100 = milliseconds -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting milliseconds in Python
Fredrik Lundh wrote: Brian Beck wrote: That IS what you want. seconds * 100 = milliseconds are you sure you know what a millisecond is? (duck) Touché. But it was a typo. -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting milliseconds in Python
Curt wrote: Oh, you meant 'seconds / 100 = milliseconds'? (canard) I assume you're suggesting that there are two typos in my original post (the * and the 100)... Despite a millisecond being a thousandth of a second, given the number of seconds provided by the time module, he does have to *multiply* by a thousand to get the number of milliseconds. 2 seconds * 1000 = 2000 milliseconds So, aside from the 100 in the original post, it may look misleading, but that is what he would need to do... -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting milliseconds in Python
Martin Christensen wrote: A math teacher! A math teacher! My kingdom for a math teacher! Martin Man, this is the hottest topic on c.l.py since that Lazaridis guy... -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: selecting dictionaries to maximize counts
Steven Bethard wrote: I have a list of dictionaries. Each dictionary holds counts of various 'words', e.g.: py> countdicts = [ ... dict(a=9, b=9, c=9), ... dict(a=8, b=7), ... dict(a=4, b=5, c=12)] I need to select dicts with the constraint that the number of each 'word' totalled over all selected dicts doesn't exceed a given MAX_VALUE. Right now, I do this by: Not that you can't still improve performance of course, but this is an NP-complete problem if you didn't know, so don't bang your head too hard... -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: selecting dictionaries to maximize counts
Steven Bethard wrote: > Anyway, do you know what name this problem is usually discussed under? If I knew what to google for, I could probably find at least a few simple heuristics to try... I think the closest thing would be the 'knapsack problem' or the 'subset sum problem.' http://en.wikipedia.org/wiki/Subset_sum_problem http://en.wikipedia.org/wiki/Knapsack_problem -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: [perl-python] exercise: partition a list by equivalence
Xah Lee wrote: merge($pairings) takes a list of pairs, each pair indicates the sameness of the two indexes. Returns a partitioned list of same indexes. For example, if the input is merge( [ [1,2], [2,4], [5,6] ] ); that means 1 and 2 are the same. 2 and 4 are the same. Therefore 1==2==4. The result returned is [[4,2,1],[6,5]]; Not sure how efficient this is, but I decided to take advantage of the operations provided by sets: def merge(pairs): pairs = set(tuple(sorted(p)) for p in pairings) merged = [] # Each loop will result in a new, complete sublist in the result. while pairs: p = set(pairings.pop()) remove = set([]) for pair in pairs: pairSet = set(pair) if pairSet & p: p |= pairSet remove.add(pair) pairs -= remove merged.append(list(p)) return merged -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: [perl-python] exercise: partition a list by equivalence
Brian Beck wrote: > [code] Whoops, that should say: def merge(pairs): pairs = set(tuple(sorted(p)) for p in pairs) merged = [] # Each loop will result in a new, complete sublist in the result. while pairs: p = set(pairs.pop()) remove = set([]) for pair in pairs: pairSet = set(pair) if pairSet & p: p |= pairSet remove.add(pair) pairs -= remove merged.append(list(p)) return merged -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: [perl-python] exercise: partition a list by equivalence
Brian Beck wrote: Brian Beck wrote: > [code] Ah heck, nevermind... it worked for my small test cases but the algorithm is just wrong. -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: [perl-python] exercise: partition a list by equivalence
Well, it looks like David posted a good solution, but I haven't tested
it (I'm assuming his works fine). I fixed mine up anyway... it actually
works now. If you're not using 2.4 you'll have to import sets.Set as set.
def merge(pairList):
pairList = set(tuple(sorted(p)) for p in pairList)
# Sort & set to remove duplicates, tuple to make hashable
merged = []
removePairs = set([])
# Each loop will result in a new, complete sublist in the result
while pairList:
if removePairs:
removePairs = set([])
else:
subList = set(pairList.pop()) # Start a new sublist
for pair in pairList:
pairSet = set(pair)
# True when pairSet and subList share at least one element
if pairSet & subList:
subList |= pairSet # Merge pair with subList
removePairs.add(pair) # Mark pair for removal
if removePairs:
pairList -= removePairs
else:
merged.append(list(subList))
return merged
--
Brian Beck
Adventurer of the First Order
--
http://mail.python.org/mailman/listinfo/python-list
Re: [perl-python] exercise: partition a list by equivalence
Reinhold Birkenfeld wrote:
def merge(pairings):
sets = {}
for x1, x2 in pairings:
newset = (sets.get(x1, frozenset([x1]))
| sets.get(x2, frozenset([x2])))
for i in newset:
sets[i] = newset
return [list(aset) for aset in set(sets.itervalues())]
Looks good. I used it as inspiration for this new one, which takes less
time for large datasets, and especially for those where a good number of
merges are expected (at least that looks to be the pattern; with some
large datasets this takes less than a quarter of the time as the one
above). I'm sure it can be improved still -- yours is still faster in
many cases.
def merge2(pairings):
elements = {}
sets = []
for x1, x2 in pairings:
i = [elements.get(x1, -1), elements.get(x2, -1)]
i.sort()
if i[1] == -1:
i[1] = len(sets)
sets.append(set([x1, x2]))
elif i[0] == -1:
sets[i[1]] |= set([x1, x2])
elif i[0] == i[1]:
continue
else:
sets[i[1]] |= sets[i[0]]
sets[i[0]].clear()
for x in sets[i[1]]:
elements[x] = i[1]
return [list(s) for s in sets if s]
# Comparison
import profile
import random
# Play with these values
xMax, nPairs = 1000, 5000
l = [[random.randint(0, xMax), random.randint(0, xMax)] for i in
range(nPairs)]
print 'merge2:'
profile.run('merge2(l)') # Mine
print 'merge:'
profile.run('merge(l)') # Reinhold's
--
Brian Beck
Adventurer of the First Order
--
http://mail.python.org/mailman/listinfo/python-list
Re: Moving to Python from PHP - 3 questions
Michal Migurski wrote: Thank you. My impression of Zope in the past has been that it does what I need, along with 10,000 other things I don't (built in WebDAV server?!), but clearly I owe it another chance. I've been initially attracted to mod_python because of its raw simplicity and its apparent similarity to mod_php and mod_perl, which I am familiar with. I'll give Zope a try. Personally, I'd have to say that your impression was right. Once you start using Zope, you'll start to feel locked in. Sure, it does a lot for you, but it's also a big investment. I can't really help you to get mod_python working on OS X, but concerning your other two points, did you notice these two sections in the documentation? http://modpython.org/live/current/doc-html/pyapi-sess.html http://modpython.org/live/current/doc-html/pyapi-mprequest.html mod_python and Zope are not your only options by far. In fact, they're at completely opposite ends of the spectrum; mod_python being low-level in that you are in control of everything and have the necessary tools to build a framework, and Zope being the highest-level in that it does tons of stuff for you. There are dozens of frameworks in between. If you do manage to get mod_python working, I suggest taking a look at Vampire as well: http://www.dscpl.com.au/projects/vampire/ I have had good experience with it. Once you start using mod_python you'll realize you can really go anywhere you want; and that's not necessarily a good thing. Vampire points you in a nice direction (I don't want to say 'the right' direction). -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: Moving to Python from PHP - 3 questions
Maybe this can help you get it working on OS X: http://thread.gmane.org/gmane.comp.python.mod-python/4039 But as stated in my other post, you may want to take a look at your other options first. Web development with Python is really nothing like PHP, unless you really want it to be. -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: python2.4 generator expression > python2.3 list expression
Duncan Booth wrote: The difference between the original "reset the rightmost '1' bit", and your interpretation: "reset the rightmost bit" is the "'1'". The rightmost bit that is set is reset. So 0x10 -> 0, and 0x1010 -> 0x1000. If you want to extract the least significant set bit from a number 'x' you can use (x&-x): My interpretation of Bryan's (mis?)interpretation (heh) was that since in the numbers 2 and 10 (as in his examples), the least significant bit was already 0, performing an operation that set it to 0 should result in the number unchanged. As his tests show, this is not the case. This is because the operation works only if the least significant bit actually NEEDS to be unset. To zero the least significant bit unconditionally, we can use: x &= ~1 -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie help for mod_python
Jochen Kaechelin wrote: I run debian sid and apache2 with libapache2-mod-python2.3 and I added these lines AddHandler mod_python .py PythonDebug On in a virtualhost container. Were those the only lines you added? You also should have actually loaded the module somewhere by adding something resembling: LoadModule python_module modules/mod_python.so -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: py.test anyone?
Robert Brewer wrote: http://www.google.com/search?q=%22py.test%22 Just a little OT note, but Google ignores the '.' and, in fact, any punctuation whether it is in a quoted string or not. And while on the subject, many people incorrectly assume that Google supports parentheses to change precedence or to clear search term ambiguity. These are likewise completely ignored. ;) Have a helpful day. -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: The python2.4 IDLE can't be lanuched.
AnkyHe wrote: I downloaded the python 2.4 final from the offical website and installed it on the WindowsXP+SP2 (Chinese version). There was not any problem in this process, but the IDLE can't be lanuched without any warnning. Is there anybody else encount this problem and how to resolve it? Thanks! I have the exact same problem. The IDLE window just never opens, and checking the process list shows that is was never even launched. So I can't make much use of Python 2.4 since I use IDLE as my IDE... -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: The python2.4 IDLE can't be lanuched.
Brian Beck wrote: I have the exact same problem. The IDLE window just never opens, and checking the process list shows that is was never even launched. So I can't make much use of Python 2.4 since I use IDLE as my IDE... I forgot to note that I am also using Windows XP SP2 and this happens on two completely different machines of mine. -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: The python2.4 IDLE can't be lanuched.
Abe Mathews wrote: I'm not running SP 2 on any machines, so I can't test it for you, but it may be that the personal firewall being activated on SP 2 is blocking IDLE from starting up. You might try turning that off and seeing if that helps. IIRC, part of SP 2 was port disabling. I do remember seeing that message but thought "no way" since the Windows firewall is pretty forgiving in my experience. But after a bit of tweaking and even disabling the firewall completely, the problem persists. -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: Python mascot proposal
Dimitri Tcaciuc wrote: While I'm not absolutely positive, it looks like Python still doesn't have any official mascot or logo. Hence, here's something I came up with yesterday. Its by no means a final version, but rather just a draft to show an idea. Here's a link to png file. http://www.sfu.ca/~dtcaciuc/art/pymascot.png Nice work! I admit it's just too tempting not to design around snake imagery for Python. Here are a couple of images/logos (quite a bit different from a mascot) I've been working on... http://exogen.cwru.edu/python.png http://exogen.cwru.edu/python2.png If anyone can think of a way to break free of the reptile-oriented thought process but maintain clear, symbolic imagery, I'd love to see more suggestions or renditions! -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: from string to raw string
Dan Perl wrote: Is there a way to convert a regular string to a raw string so that one could get from '\bblah' to r'\bblah' other than parsing the string and modifying the escapes? There's no such thing as a raw string, only raw string literals. In other words, it's a syntax to tell the Python interpreter which characters in your string are 'special' and has no effect on strings not input as literals directly within your code. Strings from files or any input besides the interactive Python shell will already be what you're looking for. -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: Are tuple really immutable?
Terry Reedy wrote: No, not in the way intended by the word 'mutable'. A tuple is like an ordered club roster written in indelible ink before the time of whiteout. The members of the club may change (change jobs, residence, relationships, etc) but the roster remains the same: same members, same ranking. Good analogy. -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: argument type
It's me wrote: How do I know if arg1 is a single type (like a number), or a list? isinstance is probably good enough for your needs. if isinstance(arg1, (list, tuple, dict)): print "arg1 is a container" else: print "arg1 is (probably) not a container" -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: Why tuples use parentheses ()'s instead of something else like <>'s?
[EMAIL PROTECTED] wrote:
Wouldn't it have been better to define tuples with <>'s or {}'s or
something else to avoid this confusion??
Well, to comment on the part that nobody else did...
< and > are binary operators, a la 3 > 1, "one" < "two"
and {}'s are clearly already used for dictionaries.
--
Brian Beck
Adventurer of the First Order
--
http://mail.python.org/mailman/listinfo/python-list
Re: Help with splitting
RickMuller wrote:
There's a chance I was instead thinking of something in the re module,
but I also spent some time there without luck. Could someone point me
to the right function, if it exists?
The re solution Jeremy Bowers is what you want. Here's another (probably
much slower) way for fun (with no surrounding empty strings):
py> from itertools import groupby
py> [''.join(g) for k, g in groupby(' test ing ', lambda x: x.isspace())]
[' ', 'test', ' ', 'ing', ' ']
I tried replacing the lambda thing with an attrgetter, but apparently my
understanding of that isn't perfect... it groups by the identify of the
bound method instead of calling it...
--
Brian Beck
Adventurer of the First Order
--
http://mail.python.org/mailman/listinfo/python-list
Re: Which IDE is recommended?
monkey wrote: > Read through python site for programming tool, really plenty of choices :-) > (For c++, I just can't breath with very very limited choices) > > Tried Spe, it come with wxGlade built-in very nice(is Spe still actively > develop?). But seem that Boa Constructor and PyDev(the plug-in for Eclipse) > also worth looking. Actually which one are you guys using? and why? I think > it is also valuable for those who are new to python as me. Here's been my experience: * Don't underestimate IDLE, it's surprisingly capable considering it's just a dinky little thing * PyDev isn't yet mature enough to make it practical for me * SPE has great features, but the pure-Python-ness makes it slow! Even just typing at a steady pace is slowed down due to all the name lookups. Plus, I still haven't found a way to reset the built-in Python shell, so if you run/import your module into it, you have to reload the entire app to reuse the shell. del doesn't help because the classes will still be in the registry * WingIDE is the most advanced by far, but isn't free. Its built-in Python shell also suffers from not easily being able to test _the module you're writing_ without a bunch of path switching. I remember the interface feeling slow on Windows, but on Linux everything is snappy. The quickness of the autocompletion for even seperate module members amazes me * If you're running KDE, KDevelop is very capable. The autocompletion is very generic though, it'll happily complete any word you've typed before. The auto-indentation isn't nearly as spot-on as WingIDE's * I hate PythonWin or whatever it's called. Dunno what more to say -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: Which IDE is recommended?
Ville Vainio wrote: > What version? PyDev has increased in maturity quite a bit lately. PyDev 0.9.2 with Eclipse 3.0.2. It's a nice effort currently, but some of my issues are: * Code completion doesn't work properly for me, and I have no idea why. I have to type the '.' then ADD A SPACE, *then* press Ctrl+Space. If I type Ctrl+Space after the dot, nothing happens. So basically it's not very useful, because I'd have to go back and get rid of the stupid space. * Code completion isn't nearly as fast as WingIDE. * Auto-indentation could be smarter, such as dedenting after a 'return' statement. * The Problems view finds 52 errors in a file with 0. * Run As doesn't dump me into an interactive shell. -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: Which IDE is recommended?
Oh yeah, and what's with not being able to configure the code completion key sequence. How about *no* key sequence? That's the way every other IDE I've used does it. This is more like semi-automatic code completion. -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: Which IDE is recommended?
Brian Beck wrote: >>What version? PyDev has increased in maturity quite a bit lately. I realize 0.9.3 is the latest release, but the installation fails through the Eclipse updater: Unable to complete action for feature "PyDev for Eclipse" due to errors. Unable to create file "/opt/eclipse-extensions-3/eclipse/plugins/org.python.pydev_0.9.3/PySrc/SocketTestRunner.py". [/opt/eclipse-extensions-3/eclipse/plugins/org.python.pydev_0.9.3/PySrc/SocketTestRunner.py (No such file or directory)] -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: Which IDE is recommended?
Brian Beck wrote: > I realize 0.9.3 is the latest release, but the installation fails > through the Eclipse updater: > > Unable to complete action for feature "PyDev for Eclipse" due to errors. > Unable to create file > "/opt/eclipse-extensions-3/eclipse/plugins/org.python.pydev_0.9.3/PySrc/SocketTestRunner.py". > [/opt/eclipse-extensions-3/eclipse/plugins/org.python.pydev_0.9.3/PySrc/SocketTestRunner.py > (No such file or directory)] Okay, sorry for spamming the newsgroup so much, but I installed 0.9.3 properly and the same issues I mentioned before persist. Code completion for imports or locals don't work at all -- the space thing was PyDev just listing all the built-ins, with none of my modules or locals included in the list. -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: Which IDE is recommended?
Ville Vainio wrote: > Perhaps you are just being impatient? > > Also, make sure that Preferences/pydev/code completion has > "Autocomplete on '.'" box checked. Yeah, that option is enabled. I actually just discovered that it does work in the example you give and for other modules in the standard library. But calls to standard library modules only occur maybe twice in any of my big scripts... the problem is I've been trying code completion with third-party modules and local classes, which still doesn't work. -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: Which IDE is recommended?
Ville Vainio wrote: > Does this help? Not really, my PYTHONPATH is fine. I found out that modules imported in the format "import mx" work fine, but "from mx import DateTime" doesn't work -- it will still only auto-complete when I type "mx." instead of realizing that it's in the local scope now. So it's fine all the modules fine, just placing them wrong in the auto-complete search tree, or however it works. -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: slice notation as values?
Antoon Pardon wrote: > Will it ever be possible to write things like: > > a = 4:9 I made a silly recipe to do something like this a while ago, not that I'd recommend using it. But I also think it wouldn't be too far-fetched to allow slice creation using a syntax like the above... http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/415500 -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: OO in Python? ^^
Matthias Kaeppler wrote:
> class Base:
>def foo(self): # I'd like to say that children must implement foo
> pass
def foo(self):
raise NotImplementedError("Subclasses must implement foo")
Now calling foo on a child instance will fail if it hasn't implemented foo.
> And how do I formulate polymorphism in Python? Example:
>
> class D1(Base):
>def foo(self):
> print "D1"
>
> class D2(Base):
>def foo(self):
> print "D2"
> obj = Base() # I want a base class reference which is polymorphic
> if ():
>obj = D1()
> else:
>obj = D2()
I have no idea what you're trying to do here and how it relates to
polymorphism.
--
Brian Beck
Adventurer of the First Order
--
http://mail.python.org/mailman/listinfo/python-list
Re: python coding contest
anonymous wrote: > are you importing zlib or bz2 ? I don't think either of these would help in this case. While the length of the compressed string might be significantly shorter than your solution, the resulting string *literal* you decompress will contain a bunch of \-escaped characters, so it will end up being longer. -- http://mail.python.org/mailman/listinfo/python-list
Re: python coding contest
> I don't think either of these would help in this case. While the > length of the compressed string might be significantly shorter than > your solution, the resulting string *literal* you decompress will > contain a bunch of \-escaped characters, so it will end up being longer. PS: I'm at 155, damn you taroso... -- http://mail.python.org/mailman/listinfo/python-list
Re: Functions, Operators, and Overloading?
Michael Yanowitz wrote: >Maybe I am missing something, but from what I've seen, > it is not possible to overload functions in Python. That > is I can't have a > def func1 (int1, string1): >and a > def func1 (int1, int3, string1, string2): > without the second func1 overwriting the first. Correct. >However, operators can be overloaded. >So can I define a new operator? If so, can I > define func1 as an operator? No. Operators in Python are merely syntax for "magic methods" on the corresponding type. For instance, x + y would call x.__add__(y). In this sense you are not really "overloading" the operator, you are simply defining or overwriting its behavior (just like above, where the second func1 overwrites the previous). > (on the side, I have always wanted to define the > ++ operator as +=1. Is that possible?) No, for the reason above -- there is no magic method associated with ++, which isn't a real Python operator. -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: Zipping files/zipfile module
OriginalBrownster wrote:
> I want to zip all the files within a directory called "temp"
> and have the zip archive saved in a directory with temp called ziptemp
>
> I was trying to read up on how to use the zipfile module python
> provides, but I cannot seem to find adequate documentation on function
> itself.
>
> Perhaps someone could help me in this task?
Hello,
This isn't completely tested, but perhaps it will help you get started:
from os import listdir, mkdir
from os.path import join, basename, isfile
from zipfile import ZipFile
def zip_dir(path, output_path, include_hidden=True):
files = [join(path, f) for f in listdir(path) if isfile(join(path, f))]
try:
mkdir(output_path)
except OSError, e:
if e.errno == 17: # Path exists
pass
zip_file = ZipFile(join(output_path, 'temp.zip'), 'w')
for f in files:
if basename(f).startswith('.') and not include_hidden:
continue
print "Adding %s to archive..." % (f,)
zip_file.write(f)
zip_file.close()
Use like:
zip_dir('temp', 'temp/ziptemp')
Note that if you want to add the entire contents of a directory
(subdirectories, recursively), you should consider using os.walk or
something similar. This will only add the file contents of the directory.
I'm not sure if the zipfile module provides any nice ways to write
directories to the archive, but I'm assuming it just involves writing an
arcname with a '/' in it (see help(zipfile.ZipFile)).
--
Brian Beck
Adventurer of the First Order
--
http://mail.python.org/mailman/listinfo/python-list
Re: Zipping files/zipfile module
Yves Lange wrote: > Other solutions: > you can try the rar command line from WinRar but it's not recommended. > This is a very slow manner to compress file. Are you sure? This worked about 4 times faster than the zip command line utility in Linux, compressing the same files... -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: Nice unicode -> ascii translation?
[EMAIL PROTECTED] wrote: > The trick is finding the right . Has someone attempted this > before, or am I stuck writing my own solution? You want ASCII, Dammit: http://www.crummy.com/cgi-bin/msm/map.cgi/ASCII +Dammit -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: unicode "table of character" implementation in python
Nicolas Pontoizeau wrote: > I am handling a mixed languages text file encoded in UTF-8. Theres is > mainly French, English and Asian languages. I need to detect every > asian characters in order to enclose it by a special tag for latex. > Does anybody know if there is a unicode "table of character" > implementation in python? I mean, I give a character and python replys > me with the language in which the character occurs. Nicolas, check out the unicodedata module: http://docs.python.org/lib/module-unicodedata.html Find "import unicodedata" on this page for how to use it: http://www.amk.ca/python/howto/unicode I'm not sure if it has built-in support for finding which language block a character is in, but a table like this might help you: http://www.unicode.org/Public/UNIDATA/Blocks.txt -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
ANN: geopy 0.93 - Geocoding Toolbox for Python
Hi everyone,
geopy 0.93 was released tonight.
What is geopy?
==
geopy is a geocoding toolbox for Python. It includes support for many
popular geocoders including Google Maps, Yahoo! Maps, Virtual Earth,
geocoder.us, GeoNames, MediaWiki (with the GIS extension), and Semantic
MediaWiki. It also includes a module for calculating geodesic distances
using different models (spherical and ellipsoidal).
Where can I get it?
===
setuptools: sudo easy_install geopy
Cheese Shop: http://cheeseshop.python.org/pypi/geopy
svn: svn co http://geopy.googlecode.com/svn/tags/release-0.93 geopy-0.93
Documentation: http://exogen.case.edu/projects/geopy
What's new in this version?
===
geopy.geocoders now includes GeoNames (www.geonames.org).
geopy.distance module was added: calculate geodesic distances.
geopy.util module was added: geocoders.Geocoder.parse_geo was moved there.
geopy.geocoders.Google can now be used with different domains (such
as 'maps.google.co.uk') and different resources ('maps' for the standard
Google Maps interface, 'maps/geo' for the HTTP geocoder interface).
How about an example?
=
py> from geopy import geocoders
py> us = geocoders.GeocoderDotUS()
py> place, (lat, lng) = us.geocode("1600 Pennsylvania Ave, Washington DC")
py> print "%s: %.5f, %.5f" % (place, lat, lng)
1600 Pennsylvania Ave NW, Washington, DC 20502: 38.89875, -77.03768
py> from geopy import distance
py> _, a = us.geocode('10900 Euclid Ave, Cleveland, OH 44106')
py> _, b = us.geocode('1600 Pennsylvania Ave, Washington, DC')
py> distance.distance(a, b).miles
301.35526872700962
py> from geopy import util
py> util.parse_geo(u"23° 26m 22s N 23° 27m 30s E")
(23.439, 23.4583332)
--
Brian Beck
Adventurer of the First Order
--
http://mail.python.org/mailman/listinfo/python-list
Re: Dealing with multiple sets
John Henry wrote: > What's the cleanest way to say: > > 1) Give me a list of the items that are in all of the sets? (3 in the > above example) > 2) Give me a list of the items that are not in all of the sets? (1,2 in > the above example) > > Thanks, If you have an arbitrary list of sets, reduce comes in handy: See this recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/476215 py> sets = [set((1, 2, 3)), set((2, 3)), set((1, 3))] py> reduce(set.intersection, sets) set([3]) py> reduce(set.union, sets) set([1, 2, 3]) py> reduce(set.union, sets) - reduce(set.intersection, sets) set([1, 2]) -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: chained attrgetter
Alexey Borzenkov wrote:
> Do you mean something like
>
> class cattrgetter:
> def __init__(self, name):
> self.names = name.split('.')
> def __call__(self, obj):
> for name in self.names:
> obj = getattr(obj, name)
> return obj
I'll raise you one:
def cattrgetter(attr):
return lambda obj: reduce(getattr, attr.split('.'), obj)
py> class A: pass
py> a = A
py> a.b = A
py> a.b.c = "Hey!"
py> cattrgetter('b.c')(a)
'Hey!'
--
Brian Beck
Adventurer of the First Order
--
http://mail.python.org/mailman/listinfo/python-list
Re: chained attrgetter
David S. wrote: > Does something like operator.getattr exist to perform a chained attr > lookup? > > I came up with the following, but I can not help but think it is > already done and done better. You were on the right track, but the built-in getattr is a perfectly good argument to reduce(), using operator.attrgetter just makes the definition more complicated (see my other post). -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
[ANN] geopy: a Geocoding Toolbox for Python
Hello Pythonistas, I'm happy to announce the first (alpha) release of geopy, a geocoding toolbox for Python: http://exogen.case.edu/projects/geopy/ ABOUT geopy includes five geocoders and some methods to make dealing with geocoded data easier (such as parsing numerous latitude & longitude formats). The geocoders are: Google, Yahoo!, geocoder.us, MediaWiki (with the GIS extension), and Semantic MediaWiki. Examples of using each are given on the site: http://exogen.case.edu/projects/geopy/ The source is only in Subversion for now. INSTALL >From the Subversion repository: $ svn co svn://exogen.case.edu/geopy/trunk geopy-trunk $ cd geopy-trunk/ $ sudo python setup.py install ...or use easy_install: $ sudo easy_install svn://exogen.case.edu/geopy/trunk Questions, comments, and bug reports can be directed to: [EMAIL PROTECTED] -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: [ANN] geopy: a Geocoding Toolbox for Python
Brian Beck wrote: > I'm happy to announce the first (alpha) release of geopy, a geocoding > toolbox for Python: http://exogen.case.edu/projects/geopy/ For anyone interested, there is now a mailing list on Google Groups: http://groups.google.com/group/geopy geopy also now supports the Virtual Earth geocoder and better support for UK addresses using the Google geocoder. -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
ANN: dmath 0.9 - Math routines for the Decimal type
Hi all,
I'm pleased to announce the first release of my new library, dmath. It is
available under the MIT/X11 license.
Download
Cheese Shop: http://cheeseshop.python.org/pypi/dmath/0.9
Google Code: http://code.google.com/p/dmath/
What is dmath?
==
dmath provides the standard math routines for Python's arbitrary-precision
Decimal type. These include acos, asin, atan, atan2, ceil, cos, cosh,
degrees, e, exp, floor, golden_ratio, hypot, log, log10, pi, pow, radians,
sign, sin, sinh, sqrt, tan, and tanh.
About this release:
===
This is the first release and I'm calling this release 0.9 because it just
needs some testing and maybe some speed improvements, otherwise it's ready
to use. There is currently some work being done in Python sandbox/trunk to
convert the decimal module to C, and maybe they'll include fast versions of
all these routines.
You can follow development details and announcements on my blog here:
http://blog.case.edu/bmb12/
How do I use it?
=
Use it just like math and cmath, but make sure you give it Decimals:
>>> from dmath import *
>>> from decimal import Decimal as D, getcontext
>>> getcontext().prec = 50
>>> asin(D(1))
Decimal("1.5707963267948966192313216916397514420985846996876")
>>> golden_ratio()
Decimal("1.6180339887498948482045868343656381177203091798058")
--
Brian Beck
Adventurer of the First Order
--
http://mail.python.org/mailman/listinfo/python-list
Re: ANN: dmath 0.9 - Math routines for the Decimal type
Brian Beck wrote: > What is dmath? > == > dmath provides the standard math routines for Python's arbitrary-precision > Decimal type. These include acos, asin, atan, atan2, ceil, cos, cosh, > degrees, e, exp, floor, golden_ratio, hypot, log, log10, pi, pow, radians, > sign, sin, sinh, sqrt, tan, and tanh. Oh yeah, you may be wondering how this differs from decimalfuncs: http://cheeseshop.python.org/pypi/decimalfuncs/1.4 The answer is that dmath has the complete set of math routines (not just a subset), it's faster (from what I can tell), doesn't require its own precision-setting method, and it's MIT instead of GPL licensed. -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: dmath 0.9 - Math routines for the Decimal type
km wrote: > and how different is MIT licence to GPL ? > could u elaborate on that ? > regards, > KM The GPL license is a copyleft license, meaning: "The GPL does not give the licensee unlimited redistribution rights. The right to redistribute is granted only if the licensee includes the source code (or a legally-binding offer to provide the source code), including any modifications made. Furthermore, the distributed copies, including the modifications, must also be licensed under the terms of the GPL." (Wikipedia) The MIT license is non-copyleft, meaning anyone has the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies provided they keep the license text with the library. -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: find login name of user?
Martin P. Hellwig wrote: > Speaking of that, is there any reason why there isn't any syntactic > sugar that gives the illusion of platform neutral fetching of the user > name? getpass.getuser() might come the closest: http://docs.python.org/lib/module-getpass.html -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: More Efficient fnmatch.fnmatch for multiple patterns?
abcd wrote: > I am using fnmatch.fnmatch to find some files. The only problem I have > is that it only takes one pattern...so if I want to search using > multiple patterns I have to do something like > > patterns = ['abc*.txt', 'foo*'] > > for p in patterns: > if fnmatch.fnmatch(some_file_name, p): > return True I don't see anything in the fnmatch and glob modules... but I didn't look very hard because what the heck is wrong with the four line solution you have? Looks fine to me. -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: strange error I can't figure out...
John Zenger wrote: > Also, get rid of the comma at the end of that last print statement. This would break the progress bar functionality I think, which is meant to update a single line. -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: Returning Date As String ?
Peter Moscatt wrote:
> I am wanting to return the system date using the following:
>
> date.today()
>
> How would I then convert this to a string ?
Use the strftime method. The formatting directives are documented here:
http://docs.python.org/lib/module-time.html
Example: date.today().strftime("%B %d, %Y")
--
Brian Beck
Adventurer of the First Order
--
http://mail.python.org/mailman/listinfo/python-list
Re: converting a set into a sorted list
Robert Kern wrote: > MackS wrote: > >> Dear all, >> >> I've got several large sets in my program. After performing several >> operations on these I wish to present one set to the user [as a list] >> sorted according to a certain criterion. Is there any direct way to do >> so? Or must I >> >> list = [] >> >> for item in set1: >>list.append(item) >> >> list.sort() So, for this example, just do: sorted(set1) -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: appending key-value pairs to a dict
rbt wrote:
> I know how to setup an empty list and loop thru something... appending
> to the list on each loop... how does this work with dicts?
>
> I'm looping thru a list of files and I want to put the file's name and
> its sha hash into a dict on each loop.
Like so:
d = {}
for filename in files:
d[sha_func(filename)] = filename
Or like so:
d = dict([(sha_func(filename), filename) for filename in files])
--
Brian Beck
Adventurer of the First Order
--
http://mail.python.org/mailman/listinfo/python-list
Re: Intellisense and the psychology of typing
Well, there are two distinct features of IntelliSense as you know it. One is auto-completion and the other is contextual help. Auto-completion is included almost all beefy Python IDE's. Contextual help is included even in IDLE, where if you begin typing a function call, its docstring pops up around where you are typing. Since many functions have dynamic arguments, I think this really is the best solution, since the implementor of the function knows what would be the most helpful to show. Open the interactive IDLE prompt and type max(, iter(, help(, for example -- although most of those are pretty minimal. -- http://mail.python.org/mailman/listinfo/python-list
Re: Pressing A Webpage Button
Elliot Temple wrote: > How do I make Python press a button on a webpage? I looked at > urllib, but I only see how to open a URL with that. I searched > google but no luck. Check out mechanize: http://wwwsearch.sourceforge.net/mechanize/ -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
ANN: consensus 0.1.1 - Collaborative filtering library for Python
Last night was the first release of a new (maybe the only?) collaborative filtering library in Python. www: http://exogen.case.edu/projects/consensus/ pypi: http://python.org/pypi/consensus/0.1.1 svn: svn://exogen.case.edu/consensus/tags/0.1.1 consensus currently includes three collaborative filtering models: vector distance, simple similarity, and constrained Pearson correlation. Several additional models are in development, as well as improvements to the current models. # Usage Adapting the rating histories of users to fit into consensus is simple: feed is a dictionary mapping any unique user object (usernames, id numbers, your own hashable user class) to a dictionary mapping items that user has rated to their rating for each item. # Examples In the repository you'll find a real-world example of using consensus: recommending songs based on the listening histories of AudioScrobbler users. A 1,000 user dataset is included and demonstrates how easy it is to make suggestions. The recommendations we've seen so far look pretty good. # Feedback This is the first release, so feedback is welcome and encouraged. We're currently looking into making a better interface to our classes to support models that rely on caching, etc. -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: New-style Python icons
[EMAIL PROTECTED] wrote: > http://www.doxdesk.com/img/software/py/icons.png Great work! Add an icon for Python egg files and you've covered all the bases. -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: Strange problem when running python code
For certain errors like Syntax Errors, you'll get a much more helpful response if you post some actual code. Strip it down if you have to, but make sure we can reproduce the errors. -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: enviroment for Python similar to Visual C++
Tomás Rodriguez Orta wrote: > I am new programator in python, and I am looking for an enviroment > graphics similar to visual c++, or delphi, where Can I create application > and forms, but over python? > sombody have any idea? Tomás, PythonCard is a good place to start: http://pythoncard.sourceforge.net/ -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
