|
hlfrk414 posted:Use shelve? I used shelve in a personal project and it worked fine. I'm a sucker for anything that is used like a dictionary. edit: king_kilr posted:I used shelve for a personal project and I spent a lot of time cursing. It's not advertised but len(shelve) is O(n) and pull all of the objects into memory and doesn't dealloc then. Not a big deal if you're using shelve for persistance, but it means shelve is poor if you have a dataset who's size is greater than available RAM. My data sets were pretty small, so I never risked the situation you're talking about. VVVV Lurchington fucked around with this message at 20:47 on Oct 24, 2009 |
# ? Oct 24, 2009 20:30 |
|
|
# ? May 9, 2024 13:28 |
|
I used shelve for a personal project and I spent a lot of time cursing. It's not advertised but len(shelve) is O(n) and pull all of the objects into memory and doesn't dealloc then. Not a big deal if you're using shelve for persistance, but it means shelve is poor if you have a dataset who's size is greater than available RAM.
|
# ? Oct 24, 2009 20:32 |
|
code:
|
# ? Oct 24, 2009 21:25 |
|
What are you using the matches for? Extract the information or functionality you need from the matches, storing them in some other kind of format, and pickle that instead.
|
# ? Oct 24, 2009 21:27 |
|
This very well may have been answered in this thread already but can anyone recommend a good IDE for Python in Mac OS X?
|
# ? Oct 28, 2009 06:33 |
|
GuyGizmo posted:This very well may have been answered in this thread already but can anyone recommend a good IDE for Python in Mac OS X? Textmate is pretty great, with a lot of different themes and a ridiculous number of syntax colorizers. If you don't want to pay money, TextWrangler is also pretty good.
|
# ? Oct 28, 2009 09:29 |
|
GuyGizmo posted:This very well may have been answered in this thread already but can anyone recommend a good IDE for Python in Mac OS X? Here's a link to the suggestions from when I asked it. Honestly, I'm lead-developing on windows again just thanks to PyScripter
|
# ? Oct 28, 2009 17:53 |
|
Lurchington posted:Here's a link to the suggestions from when I asked it.
|
# ? Oct 28, 2009 18:01 |
|
Hah! I thought this looked funny. I sometimes found myself writing a flattening function that would take any nested sequence and flatten it into a list. It would work fine except that I couldn't figure out how to flatten to an arbitrary depth without the ability to recurse to arbitrary depths. Well I saw this code posted by a guy called Danny Yoo for how to do this using continuation passing style. code:
|
# ? Oct 30, 2009 12:33 |
|
tripwire posted:Has anyone heard of "trampoline" style programming before, to avoid overflowing the stack? It seems like such an evil concept James Tauber has! http://jtauber.com/blog/2008/03/30/thunks,_trampolines_and_continuation_passing/ (disclaimer: he's my boss)
|
# ? Oct 30, 2009 15:12 |
|
tripwire posted:Has anyone heard of "trampoline" style programming before, to avoid overflowing the stack? It seems like such an evil concept Sure, but it's easier to keep an explicit stack sometimes: code:
|
# ? Oct 30, 2009 16:25 |
|
I have a specialized url shortener Django app that works on base64 translations of a database ID. My boss is concerned that it could possibly generate offensive words as the base64 keys, and to be safe would like me to skip any ID whose base64 representation is a dictionary word. I've found a couple of random aspell libraries for python, but they don't seem very well maintained. Is there a simpler way I can just check if a string is a word in the dictionary? My app runs on a linux (Ubuntu) server.
|
# ? Oct 30, 2009 16:39 |
|
Looking around I found this: http://rightfootin.blogspot.com/2006/09/more-on-python-flatten.html And it claimed a rather odd method was fastest,So I decided to run it against my own: http://pastebin.ca/1649364 is the test code. Mine: $ time python flattentest.py flatten 1000000 1000000 real 0m5.209s user 0m4.934s sys 0m0.145s The one that 'whoops all of the others for speed, nesting level support and elegance': $ time python flattentest.py flatten2 1000000 1000000 real 10m32.296s user 9m55.045s sys 0m4.894s Edit: and the trampoline doesn't perform well either tef fucked around with this message at 17:10 on Oct 30, 2009 |
# ? Oct 30, 2009 17:04 |
|
SlightlyMadman posted:I've found a couple of random aspell libraries for python, but they don't seem very well maintained. Is there a simpler way I can just check if a string is a word in the dictionary? My app runs on a linux (Ubuntu) server. dictionary = ['word1','word2','word3'] if word.lower() in dictionary: # try again
|
# ? Oct 30, 2009 17:43 |
|
tef posted:Looking around I found this: http://rightfootin.blogspot.com/2006/09/more-on-python-flatten.html
|
# ? Oct 30, 2009 18:07 |
|
A A 2 3 5 8 K posted:dictionary = ['word1','word2','word3'] Haha, I think that list might be a little bit inefficient for storing every word in the dictionary, but thanks. I actually finally came across an enchant module which works very well. edit: actually, my problem is still not 100% resolved. If a word is very close to a dictionary word, (i.e. "sh1t") it could still get through. It seems like this would be a common enough task that there should be a library specifically for it? SlightlyMadman fucked around with this message at 18:31 on Oct 30, 2009 |
# ? Oct 30, 2009 18:25 |
|
SlightlyMadman posted:I have a specialized url shortener Django app that works on base64 translations of a database ID. It might be easier to come up with an encoding that won't generate offensive language, than to repeatedly generate new ids if they happen to look like words.
|
# ? Oct 30, 2009 18:44 |
|
tef posted:It might be easier to come up with an encoding that won't generate offensive language, than to repeatedly generate new ids if they happen to look like words. Can you suggest any algorithms specifically? It's a url shortener, so it would need to at least be close to base64 in efficiency (both in number of characters and speed to encode/decode). I've implemented a simple levenshtein algorithm in the meantime, but it only counts the number of letters a word is off by, not similarities in the letters themselves (i.e. "5h1t" is as far from "poo poo" as "xhbt" is).
|
# ? Oct 30, 2009 19:09 |
|
http://thedailywtf.com/Articles/The-Automated-Curse-Generator.aspx Sorry I don't have anything else to add . I mean that guys solution could have been ok if he'd just used consonants.
|
# ? Oct 30, 2009 19:25 |
|
tripwire posted:Haha, thats the same page that I found the snippet I posted on. Your version beats theirs on elegance as well. The trampoline version is still running p.s your chaos maps are drat awesome
|
# ? Oct 30, 2009 19:43 |
|
tef posted:It might be easier to come up with an encoding that won't generate offensive language, than to repeatedly generate new ids if they happen to look like words. Another option is Base-32: http://en.wikipedia.org/wiki/Base32 http://www.crockford.com/wrmg/base32.html A nice side-effect is that "u" isn't part of the encoding, so generating swear words becomes more difficult. Edit: Looks like there's already support for this in Python! http://docs.python.org/library/base64.html Jjust search that page for "b32". NadaTooma fucked around with this message at 20:23 on Oct 30, 2009 |
# ? Oct 30, 2009 20:21 |
|
NadaTooma posted:Another option is Base-32: That's a good idea, but it would make my IDs twice as long. Since the actual point of url generation isn't as much as a bottleneck as resolution, I don't see a problem in using a more efficient encoding at the cost of a bit of analysis.
|
# ? Oct 31, 2009 05:41 |
|
So I've long been sick of MySQLdb for being a horrible mysql driver as well as just being horribly written in general. Of course, there's also frequent questions on #python regarding either how horrible MySQLdb is or why the maintainer hasn't released any 2.6 binary packages for windows. To solve all of this, I wrote my own mysql driver from scratch using Cython: oursql! It's still very much in-development and I haven't finished writing a comprehensive tutorial, but it works pretty well as far as I've tested. There's also a windows binary package for python 2.6! It's a standard DB-API driver, so you can use it mostly the same way as MySQLdb previously. I haven't tested to see if you can easy_install it yet. Packages for the main package manager systems are being submitted as I figure out how to write them. Hopefully there's some folks in this thread who are as tired of MySQLdb as I was and don't mind testing out a new driver.
|
# ? Oct 31, 2009 13:33 |
|
Habnabit posted:To solve all of this, I wrote my own mysql driver from scratch using Cython: oursql! It's still very much in-development and I haven't finished writing a comprehensive tutorial, but it works pretty well as far as I've tested. There's also a windows binary package for python 2.6! Good on you. I've had constant problems with installing MySQLdb, problems that shift and change: it won't install on OSX, it won't install on Fedora, it puts the libraries in the wrong place, configs wrong or (worse of all) installs and looks functional but isn't. So I'm relieved to see a possible replacement. Any reason for using Cython, or does it just make things easier?
|
# ? Oct 31, 2009 13:42 |
|
outlier posted:Good on you. I've had constant problems with installing MySQLdb, problems that shift and change: it won't install on OSX, it won't install on Fedora, it puts the libraries in the wrong place, configs wrong or (worse of all) installs and looks functional but isn't. So I'm relieved to see a possible replacement. While I'm definitely comfortable writing stuff in C, Cython removes all of the boilerplate associated with writing C extensions for python. It means I don't have to think about class structures, method structures, documentation structures, refcounts, exceptions, or the refcounts of everything I'm working with when an exception is raised. In the end, I write less code that has the potential to really screw up python. So yes: I use Cython to make things easier.
|
# ? Oct 31, 2009 13:49 |
|
Habnabit posted:So I've long been sick of MySQLdb for being a horrible mysql driver as well as just being horribly written in general. Of course, there's also frequent questions on #python regarding either how horrible MySQLdb is or why the maintainer hasn't released any 2.6 binary packages for windows. Good for you! Awhile back I almost got to the point where I was going to teach myself how to do the same. Instead, I figured out how to compile MySQLdb for Windows myself (get it here if anyone needs it). I'll be keeping an eye on your project, though.
|
# ? Oct 31, 2009 18:21 |
|
Just got my very first python script running. It's just a Word of the Day, with a word list stored in a text file, and a "lookup" button that opens the definition in the web browser. Being the first thing I've done in python, I want to make sure my code is nice and pythonic, as it were. Any suggestions on how to clean it up?code:
|
# ? Nov 2, 2009 08:31 |
|
Depending on how bored you are, read the Python style guide. http://www.python.org/dev/peps/pep-0008/
|
# ? Nov 2, 2009 08:55 |
|
Well it looks fine to me, but why use the linecache module? The biggest wordlists I can see on packetstorm are like a megabyte, so unless memory is at an extreme premium, why not load the word list from the file once? I don't think theres a lot of overlap with most user interface libraries like tkinter or wxwidgets and "pythonic" code; no matter how you slice it, you'll always get a lot of verbose boilerplate in there. Some may disagree. Also, the random module provides a handy "choice" function that returns a random element from any sequence type, just for cases like this. If I want a random word I'll usually do something like this: code:
|
# ? Nov 2, 2009 09:43 |
|
Thanks tripwire. I learned alot from that.
|
# ? Nov 2, 2009 11:42 |
|
Ok design question: I have several related C interfaces which may or may not be present in a given implementation. The interfaces look like:code:
A) For FooBar/FooExt, create modules that inject new methods into the base Foo class. e.g. code:
|
# ? Nov 2, 2009 19:46 |
|
Avenging Dentist posted:Ok design question: I have several related C interfaces which may or may not be present in a given implementation. The interfaces look like: Really I'm not seeing why you can't just put it all in one class. What's the overlap between Foo_a, FooBar_b, and FooExt_c?
|
# ? Nov 2, 2009 23:41 |
|
Habnabit posted:Really I'm not seeing why you can't just put it all in one class. What's the overlap between Foo_a, FooBar_b, and FooExt_c? If I put it in one class (without injection) I'd be relying entirely on conditional compilation to find and include the appropriate C interfaces which would a) be pretty loving confusing for users trying to write stuff that works across implementations (you wouldn't want to use FooMyImplementationsSpecialStuff_d), and b) would break the ability for other people to add new interfaces modifying the base interface (Foo) without recompiling the entire package.
|
# ? Nov 3, 2009 00:21 |
|
Avenging Dentist posted:If I put it in one class (without injection) I'd be relying entirely on conditional compilation to find and include the appropriate C interfaces which would a) be pretty loving confusing for users trying to write stuff that works across implementations (you wouldn't want to use FooMyImplementationsSpecialStuff_d), and b) would break the ability for other people to add new interfaces modifying the base interface (Foo) without recompiling the entire package. There's a precedent for just using conditional compilation that's even in the python stdlib; look at things like the fcntl or socket modules. Anyway, the solution that makes the most sense to me would be to have subclasses to represent the different extensions, assuming that you wouldn't use more than one extension at a time. Otherwise I'd just jam it all in one class and provide some sort of compatibility layer on top.
|
# ? Nov 3, 2009 03:44 |
|
I just downloaded pydev for eclipse and I am having a lot of trouble figuring out why I get unresolved imports when the code runs without errors. The code that I'm working with is very basic and the problem still happens.code:
|
# ? Nov 4, 2009 16:14 |
|
FYI: The talks for PyCon have been announced: http://us.pycon.org/2010/conference/talks/ Ya'll should come.
|
# ? Nov 5, 2009 03:45 |
|
m0nk3yz posted:FYI: The talks for PyCon have been announced: http://us.pycon.org/2010/conference/talks/ Yeah you should, it's going to kick rear end.
|
# ? Nov 5, 2009 03:49 |
|
I want to see talks: 13, 30, 48, *52*, *55*, 64, 81, 93, 96, 116, 171, 186, 188
I think my company may be interested in sending me Lurchington fucked around with this message at 18:45 on Nov 5, 2009 |
# ? Nov 5, 2009 16:16 |
|
m0nk3yz posted:FYI: The talks for PyCon have been announced: http://us.pycon.org/2010/conference/talks/ Considering I can walk to the conference.. I should be there Already on my to see list
|
# ? Nov 5, 2009 17:57 |
|
|
# ? May 9, 2024 13:28 |
|
virtualenv nub here. Whats the recommend way to install a module from svn or git or something? Do you just navigate to the /site-packages/ directory within the virtualenv then do a checkout?
|
# ? Nov 5, 2009 18:15 |