|
Did you remember to strip the newlines away before making the comparison?
|
# ? Mar 31, 2011 06:09 |
|
|
# ? May 9, 2024 06:52 |
|
FoiledAgain posted:Did you remember to strip the newlines away before making the comparison? Yes, I think I'm doing it correctly but still no luck.
|
# ? Mar 31, 2011 06:15 |
|
Hughmoris posted:Ok, I am stumped. I want this function to take a value, search through a text file of dictionary words and tell me if the value is a word. I understand that you're just doing this for learning Python but the developer in me cringes at what that function does. Every single time you call dictLook(), it re-opens and re-reads *every* line in that file. Every time. Do yourself a favor and just read in the entire file once. Keep it in memory for everything you need to do. Odds are also extremely likely that the reason "line == word" isn't working is because there's a trailing newline character. Try this: code:
line 2 is a list comprehension which constructs a single list of each line in the file, after its been stripped of any leading or trailing whitespace. If you're using Python 3.2 you can do even more fun: code:
If it can't find 'oklo' in the cache, it'll proceed with the rest of the function which searches the wordlist in memory. Before True or False returns, the answer will be cached in the lru_cache. That way, the second time you call the function with the same word, it'll simply return the cache entry instead of scanning the entire list.
|
# ? Mar 31, 2011 06:20 |
|
spankweasel posted:Great stuff Thanks for taking the time to write all of that up. I'll see what I can do with it.
|
# ? Mar 31, 2011 06:30 |
|
e: already answered, that'll teach me to look on the next page
|
# ? Mar 31, 2011 06:32 |
|
Hughmoris posted:Yes, I think I'm doing it correctly but still no luck. Hmm. I copied your code and the dictionary and it worked for me. What tripped me up all the time when I started Python is that strip functions don't have side effects. Did you make the mistake I use to: code:
|
# ? Mar 31, 2011 08:08 |
|
Just do line.strip()
|
# ? Mar 31, 2011 08:10 |
|
I'm a complete beginner at Python, and I want to read values incoming from a serial port and list them in some sort of dynamic view so that I can see them as come in to the port. I'm curious what the best way is to approach this. First thought is something like the "top" program in unix, a console program that updates all information instead of printing it out all the time, but I don't know how to do or what this type of "GUI" is called. Is it harder to do than to use Tkinter? Are there easier ways for a beginner? edit: solved original but question above still remains Mopp fucked around with this message at 14:43 on Mar 31, 2011 |
# ? Mar 31, 2011 08:29 |
|
Mopp posted:I'm a complete beginner at Python, and I want to read values incoming from a serial port and list them in some sort of dynamic view so that I can see them as come in to the port. I'm curious what the best way is to approach this. First thought is something like the "top" program in unix, a console program that updates all information instead of printing it out all the time, but I don't know how to do or what this type of "GUI" is called. Is it harder to do than to use Tkinter? Are there easier ways for a beginner? What is the nature of the data you want to show? The simplest solution is just to print stuff as it passes by, maybe with a few newlines in between. Next, you could look at faking a console GUI by running "clear" before each update, so that the data always appears by itself in the console window. In addition, you can use the carriage-return character ('\r') to move the cursor to the front of a line and overwrite that line -- that's how things like the wget progress bar work. Moving up, a proper console GUI is usually built out of something like ncurses, which I have very little knowledge of. That's how things like 'top' work. If you want an actual windows GUI, then I guess Tkinter or wxWindows is your best bet, but I suspect you can get by with one of the above.
|
# ? Mar 31, 2011 16:46 |
|
What is code:
code:
At least I assume it's syntactic sugar for something string-specific because it's not working on other sequence types, but I can't find anything with Google, probably because the stupid keyword is 'in'
|
# ? Mar 31, 2011 17:34 |
|
Munkeymon posted:because it's not working on other sequence types code:
|
# ? Mar 31, 2011 17:48 |
|
Well, to be honest, "str1 in str2" means something different than "item1 in list". The former really means "is a substring of"...if it literally meant "is an element of", then only individual chars would be possible to be in the string sequence.
|
# ? Mar 31, 2011 18:05 |
|
Stabby McDamage posted:Well, to be honest, "str1 in str2" means something different than "item1 in list". The former really means "is a substring of"...if it literally meant "is an element of", then only individual chars would be possible to be in the string sequence. Right. I assumed he meant that syntax didn't work on other sequence types, not that the ... intention or whatever ... didn't work on other sequence types. I sit on the edge of my seat waiting to find out what he really meant!
|
# ? Mar 31, 2011 18:10 |
|
Thermopyle posted:
Yep, I was thinking code:
|
# ? Mar 31, 2011 19:55 |
|
I believe that in general x in y is syntactic sugar for y.__contains__(x). This page has some details.
|
# ? Mar 31, 2011 20:11 |
|
FoiledAgain posted:Hmm. I copied your code and the dictionary and it worked for me. What tripped me up all the time when I started Python is that strip functions don't have side effects. I got it working! Thanks for the help.
|
# ? Mar 31, 2011 22:03 |
|
Space Prostitute posted:I believe that in general x in y is syntactic sugar for y.__contains__(x). This page has some details. I guess it's just defined differently on strings and lists.
|
# ? Mar 31, 2011 22:56 |
|
Does anybody have any resources for working with a SOAP based API? Specifically with Python but I know absolutely nothing about SOAP. I am trying to communicate with the FedEx API and it's proving to be very difficult as I know nothing about SOAP.
|
# ? Apr 1, 2011 00:32 |
|
Probably the best resources for working with SOAP APIs are a bottle of rye, a revolver and a bullet.
|
# ? Apr 1, 2011 00:35 |
|
Otto Skorzeny posted:Probably the best resources for working with SOAP APIs are a bottle of rye, a revolver and a bullet. This is the conclusion I have come to as well.
|
# ? Apr 1, 2011 00:37 |
|
It's not any easier trying to write them and test them with soapui.
|
# ? Apr 1, 2011 00:46 |
|
Yakattak posted:Does anybody have any resources for working with a SOAP based API? Specifically with Python but I know absolutely nothing about SOAP. I am trying to communicate with the FedEx API and it's proving to be very difficult as I know nothing about SOAP. My work recently released Scio, which I think is a pretty decent SOAP library (relatively speaking). It won't make SOAP any less painful, but it will let you experience that pain more directly, without any other, more pythonic pains getting in the way.
|
# ? Apr 1, 2011 01:25 |
|
Any recommendations on an elegant way for the following problem: I have 7 letters, and I want to print out every possible combination of those letters(think Scrabble). I've done this in a long-handed way for 4 letters but with 7 letters it would be a pain to write all that out. Is there a clever way to tackle this?
|
# ? Apr 1, 2011 02:11 |
|
Hughmoris posted:Any recommendations on an elegant way for the following problem: itertools.permutations should do it.
|
# ? Apr 1, 2011 02:16 |
|
Yeah gently caress it. I found a package for talking with FedEx, just gonna use that instead.
|
# ? Apr 1, 2011 02:19 |
|
I'm so confused. This looks like really simple code:code:
code:
FoiledAgain fucked around with this message at 05:32 on Apr 1, 2011 |
# ? Apr 1, 2011 05:29 |
|
is there a simple cross-platform method of determining the height and width of the console with python?
|
# ? Apr 1, 2011 05:44 |
|
Thanks to everyone in the thread, I finished my first real project! The program is for scrabble players. It will take any amount of letters, and let you know every possible word that could be used with them. It is ungodly slow if you choose to use all 7 letters but it works. Now I will try to optimize it a little bit and maybe add in a "points" feature. Stabby McDamage posted:itertools.permutations should do it. This is what I needed, thank you.
|
# ? Apr 1, 2011 06:34 |
|
boak posted:is there a simple cross-platform method of determining the height and width of the console with python? Nope, because consoles are different on different platforms. On windows I doubt that theres anything out of the box thats going to tell you terminal size, but it may be hidden somewhere in pywin32. On unixey systems you want the tty and/or termios modules. edit: code:
tripwire fucked around with this message at 10:44 on Apr 1, 2011 |
# ? Apr 1, 2011 07:40 |
|
Yakattak posted:Does anybody have any resources for working with a SOAP based API? Specifically with Python but I know absolutely nothing about SOAP. I am trying to communicate with the FedEx API and it's proving to be very difficult as I know nothing about SOAP. It's easy as dirt to use, presuming you're using their web service. EDIT: I read thread good. Oh well, if anybody's using SOAP web services in the future, I'm pretty sure suds is the easiest way to go.
|
# ? Apr 1, 2011 08:45 |
|
FoiledAgain posted:I'm so confused. This looks like really simple code: Assuming treeline is a typo in copying the error message, could you post a larger sample? It's not clear what could make treelist be None. By the way, for convenience you can declare an empty list like this: code:
code:
|
# ? Apr 1, 2011 10:03 |
|
Hughmoris posted:Thanks to everyone in the thread, I finished my first real project! The program is for scrabble players. It will take any amount of letters, and let you know every possible word that could be used with them. It is ungodly slow if you choose to use all 7 letters but it works. Now I will try to optimize it a little bit and maybe add in a "points" feature. That's great. Making it fast could be a tricky problem, but there are some coarse-grained things you could do to get started. First, are you loading your word list in a lookup-friendly way (a dictionary or set)? If your words are in a list, then "x in wordlist" has to walk through the whole list to see if x is there. If it's a dictionary ("wordlist[x]") or a set ("x in wordlist"), it runs a lot faster. (Technically, we say it runs in "constant time"* -- i.e. adding more stuff to the list doesn't make it take proportionally longer.) For this project, you probably want a set, which you can get just by saying "wordlist = set( <<whatever was here before >> )". If you want to go faster than that, you'll probably need to get into some sophisticated algorithms (or reuse the right piece of existing code). * I'm assuming python dictionaries and sets use something like extensible hashing to achieve O(1) performance. Let me know if this isn't the case.
|
# ? Apr 1, 2011 20:07 |
|
dicts and sets are both backed by hash tables, if you're interested in the implementation: http://hg.python.org/cpython/file/default/Objects/dictnotes.txt
|
# ? Apr 1, 2011 21:07 |
|
Hughmoris posted:Thanks to everyone in the thread, I finished my first real project! The program is for scrabble players. It will take any amount of letters, and let you know every possible word that could be used with them. It is ungodly slow if you choose to use all 7 letters but it works. Now I will try to optimize it a little bit and maybe add in a "points" feature. This is probably beyond what kind of thing you are interested in attempting at the moment, but there are two main techniques used to generate a list of possibilities for Scrabble:
The DAWGs/CDAWGs are conceptually simpler. GADDAGs run in about half the time of DAWGs/CDAWGs, but are much more complicated. There is also more literature about DAWG/CDAWG generation, but you'd want to start with Appel and Jacobson either way. You may also be interested in the following paper (which is a nice paper even if you have no intention of making a full-blown AI): World-championship-caliber scrabble. by Brian Sheppard. Artif. Intell., 134:241–275, January 2002. These should all be easy to find (particularly with Google Scholar), but if you're having problems, feel free to PM me.
|
# ? Apr 2, 2011 02:12 |
|
I'm reacquainting myself with an old project of mine, and noticing that there's very few method docstrings, and the ones that are there are inconsistent and potentially unclear. Is there a nice clean standard that it'd be good to stick to? I don't necessarily want to go out of my way to support an automated documentation system, but if that's a good idea or easy then I guess I may as well.
|
# ? Apr 4, 2011 01:58 |
|
Jonnty posted:I'm reacquainting myself with an old project of mine, and noticing that there's very few method docstrings, and the ones that are there are inconsistent and potentially unclear. Is there a nice clean standard that it'd be good to stick to? I don't necessarily want to go out of my way to support an automated documentation system, but if that's a good idea or easy then I guess I may as well.
|
# ? Apr 4, 2011 03:40 |
|
If someone has time, I would love to get some feedback on the tetris clone I wrote. Style, program structure, anything would be great. https://github.com/mcmt/disappeartheblocks
|
# ? Apr 5, 2011 05:18 |
|
n/m
|
# ? Apr 5, 2011 10:30 |
|
Question for a program i'm writing. For what basically amounts to a web spider that needs to be able to spider multiple sites at a time would it be better to use something event based like Twisted, Circuits or Gevent, MultiProcessing or threads?
|
# ? Apr 5, 2011 18:05 |
|
|
# ? May 9, 2024 06:52 |
|
I used something similar to gevent (eventlet) and it seemed like the best approach compared to threads/processe/twisted. Never used circuits.
|
# ? Apr 5, 2011 19:18 |