404 Posted Topics
Re: sha is decent, I think. Here's a simple example: [code="Python"] >>> import sha >>> pwd = "Thingy3!2" # Not remotely related to my real pwd's >>> my_encrypt = sha.new(pwd) >>> my_encrypt.hexdigest() '1f10b40bb3bf2c3493ae9b151549a6526c69b79d' >>> dir(my_encrypt) ['__class__', '__delattr__', '__doc__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', 'block_size', 'copy', 'digest', 'digest_size', … | |
Re: A list with the brackets and commas? The easiest way is also taboo: [code="Python"] >>> eval(raw_input("Enter a list: ")) Enter a list: [1,2,3] [1, 2, 3] [/code] IMO, eval() should almost never be used for the simple reason that it allows the user to type ANYTHING. As in [code="Python"] >>> … | |
Re: I agree with G-Do's advice, but if you are stuck using Tkinter, then you want to think like this: events instead of timeline. In other words, something has to trigger your application to move the circle. Here's a version that fixes a bug and also moves the circles on every … | |
Re: Looks like either a port is closed or else there's a credentials problem. But that's a guess. Jeff | |
Re: Without seeing the code, I'm just guessing. But that error often happens when a method mistakenly assigns a None return value to the object that called it. Here's an example: [code="python"] >>> mylist = [3,1,2] >>> mylist = mylist.sort() >>> len(mylist) Traceback (most recent call last): File "<pyshell#2>", line 1, … | |
| |
Re: ...for squares oriented along the axes, but not ones like (0,0), (3,4), (-1,7), (-4, 3) Jeff | |
Re: 1. /usr/Lib/python2.5 OR /usr/Lib/python2.5/site-packages OR (for specialized modules) in the same directory as the files that will use them. 2. It's probably a file permissions problem. Jeff | |
Re: You aren't getting an error message from Python. You're getting an error message from the OS. It's unlikely that Windows Error 3 has any relationship to errno 3 Jeff | |
Re: Also, if you are sitting behind a firewall, you might well get blocked unless you enable Python. Jeff | |
Re: Just a miscellaneous thing: all import statements belong at the top of the file (rule of thumb, can be broken if needed, but usually good). [quote] I was wondering if my code was too mesy with the branched if statements [/quote] Yes, a bit. But it's not terrible, and sometimes … | |
Re: quoting from the documentation of the time module in Python docs, [quote] %a Locale's abbreviated weekday name. %A Locale's full weekday name. %b Locale's abbreviated month name. %B Locale's full month name. %c Locale's appropriate date and time representation. %d Day of the month as a decimal number [01,31]. %H … | |
Re: Well, the code that you are using for addition, subtraction, multiplication, and division problems is all very redundant. I would work on getting a more general problem solved: * Pick an operator from +,-,*,/. * Create a problem * (1) Display it onscreen * Get user input. * If right, … | |
Re: Check [url]http://www.riverbankcomputing.com/Docs/PyQt4/html/qinputdialog.html[/url] and [url]http://www.riverbankcomputing.com/Docs/PyQt4/html/classes.html[/url] here. | |
Re: "mod" is your friend. The idea behind mod n is that it simulates going around a clock with n hours. The arithmetic is simple: mod divides by n and takes the remainder: >>> 23 % 5 3 (because 23/5 is 4 remainder 3) Which is equivalent to saying, "On a … | |
Re: <quote>maybe somebody could help me better organize it.</quote> A couple of suggestions for tightening up your code: (1) importing code need only be done once. Thus, your main file should import phenomenu, lux, arius, male, etc. at the top, and then call functions out of those files as needed. (2) … | |
Re: This would be a text-based version, I hope? Start with a plan: Pretend to be the computer and work out a nice high-level description of how you, the computer, would let the user play pac-man. Good coding is about 50% planning, 10% coding, and 40% debugging (or so). Even more … | |
Re: I'm confused. Do you need to figure out how to get the text out of the textbox? Also, what GUI toolkit are you using? Jeff | |
Re: Almost certainly. BTW, this is an amazingly cool project. /gush How does the input take place? For example: I speak a sentence. How is that sentence represented internally in Python? Does the speech recognition module return a list of words, or what? Jeff | |
Re: With both programs, the place to start is with a couple of examples: "8-MAR-85", "12-DEC-1970", etc. and (a) work them out by hand, (b) describe to yourself how you did it, and (c) write code to do the same. That's how I write my code. Jeff | |
Re: I've resorted to creating a function: [code="Python"] def fuzzyequals(a,b,delta = 0.00001): return -delta < a-b < delta [/code] Jeff | |
Re: Well, wrap your posts in (code = Python) (/code) tags for greater clarity. My favorite way to do this would be to pull the information out of tuples like this: class person(): def __init__(self): self.name = ' ' self.job = ' ' self.age = 0 people = [('abc','worker',20), ('efg', 'student',22), … | |
Re: In elec eng., this problem is called 'key debouncing.' When I type here at the keyboard, the keyboard device (or its driver) has to decide whether my keypresses that last tens of milliseconds ... practically forever! ... are supposed to be single keypresses or multiple presses or press-and-hold. The usual … | |
Re: Well, first off there are two versions of popen2(). One is os.popen2(command), and it returns (child_stdin, child_stdout). The other is popen2.popen2(command), and perversely, it returns (child_stdout, child_stdin). So make sure that you don't have the two reversed. (Who made that decision, anyways?! Grr...) Jeff | |
Re: Also, check out the cPickle module, which automagically serializes data for you into a file which then can be read back at will. Jeff | |
Re: Suppose that you were the computer; how would you solve this problem? For example, I give you an 86. How do you know to return a 'B'? Write a short plan that a human could follow; then turn it into a Python program. Post your plan here, if you like, … | |
Re: I tried to test it, but I don't have a Network module, nor could I find such on Google. Where is that module coming from? Jeff | |
Re: This code runs fine: [code="Python"] def ols(x, y): class output: pass results = output() results.method = 'ols' results.y = y #results.nobs = n #results.nvar = nvar #results.beta = B return results r = ols(1,2) print r [/code] I think the problem with yours might have been that you were accessing … | |
Re: I don't recall off the top. The manual is found here: [url]http://infohost.nmt.edu/tcc/help/pubs/tkinter/tkinter.pdf[/url] It's well-organized; just go down to the Text widget. Jeff | |
Re: It's funny to me that, armed with English and German, I can read printed Dutch pretty well...but spoken Dutch might as well be Arabic to me! Several things strike me about the code. (1) All import statements should occur at the top of the main code, before functions are defined … | |
Re: So the idea is, you have two binary numbers represented as strings, and then you want to add them? I'm not seeing any obvious errors in the code above. | |
Re: It looks more like an array of 5 strings? [code="Python"] first_list = [" marek brutalski 20", "zenia markownikowa 10", "teresa parufkowa 90", "bogumila pierdawa 40", "genowefa tempawa 50"] [/code] What you will need to do is to split it into a real 5x3 array: [code="Python"] first_list = [" marek brutalski … | |
Re: The problem is that Python does assignment by reference. So the line _link2 = _link operates by making _link2 and _link both point to the same object. Change one, and you've changed them both. If you want to copy the contents, do a slice: _link2 = _link[:] The operation on … | |
Re: If you walk through your code carefully, you'll see that the drawface() function does *way* too much. As a result, it clobbers any old faces that might be on the screen. The solution is to move the initialization out of the drawface() function, and then let drawface() do one single … | |
Hi all, I see a lot of books teaching beginning Python students to code like this: [code="Python"] def func1(): ... def func2(): ... class Blah(object): ... def main(): ... main() [/code] It strikes me that having people "def main():" and then call main() is a bit silly. In fact, it … | |
Re: Yeah, I can't read the large version of the scan either. I would recommend talking to the TA for the class immediately, because this will only be the beginning. In the meantime, you might check out a beginning Python book. Zelle is good, and Dawson is easy. Jeff | |
Re: Two problems: (1) A function should only do one thing, and do it well. So you really want two functions: One to take a string and split it into a list of numbers. Another to take a list of numbers and return a list of squares of those numbers. The … | |
Re: Hi muddpigeon, So I have some questions about your code: (1) I don't know what 'withdraw with' and withdraw without' mean ... (2) It looks like you want the code to execute sequentially from top to bottom. Is that correct? If so, I have a suggestion about organization. If not, … | |
Re: It looks like the part of the code that parses the object file name has no provision for name globbing (that is, interpreting "*" as "all files"). I don't think it's supposed to work that way. It may be that when you run it under a *NIX environment (pun intended), … | |
Re: (1) use [B][noparse][code="Python"][/code][/noparse][/B] tags to show indentation correctly. (2) Your return value for the function acronym is the function acronym. Thus, the line "print acronym(phrase)" is printing the object acronym, which is a function. You want something like [code="Python"] import string def acronym(phrase): x = "" phrase = string.capwords(phrase) for … | |
Re: Well, I don't have an 'odict' module, so my error message was on line 1. :) Below is an example of how to do inheritance correctly. If you uncomment lines 21 and 24, you should get an error message similar to the one you were getting. Basically, the problem with … | |
I'm writing a lesson on debugging for my students. They will have already had a lesson on how to read code and do walkthroughs, either manually or using the debugger. They currently know about [B]if[/B], [B]while[/B], types, math operators, and have some experience with but no formal training in functions … | |
Re: depending on what you want ... [code="Python"] >>> s = "now is the time for ALL good men..." >>> s.capitalize() 'Now is the time for all good men...' >>> s.title() 'Now Is The Time For All Good Men...' >>> [/code] strings have number of powerful methods; you might poke around … | |
Re: [b]return[/b] Since __init__() is a method, you can return out of it. | |
Re: OK Vega, fess up: how do you get the bolded [ code = Python ] text in there?! I tried several kludges and failed. Jeff | |
Re: [quote] It appears to me that the issue is whether the value assigned to the function argument is a value (fundamental type) or a reference (to an object). [/quote] Exactly so, except for the wording. replace "value (fundamental type)" with "immutable object" replace "a reference (to an object)" with "mutable … | |
Re: Well, there are actually three issues in the code: (1) is a matter of efficiency, which woooee already raised. [code="Python"] status = 0 for i in range(10): status = status + 0.1 print status [/code] does what you wanted to do, and is cleaner to read. One payoff of this … | |
Re: Good one, mawe. If you need to filter the list in a more complicated way, you can also do this: [code=Python] for item in mylist[:]: if item_is_a_reject(): #whatever test you need to run goes here mylist.remove(item) [/code] so we iterate through a *copy* of mylist, but remove items from the … | |
Re: When you use wxPython, as with Tkinter, the application has to be initialized first in order to set all kinds of screen parameters. So the code you are trying to compile is only partially there. Did you write it yourself, or is it someone else's? |
The End.