404 Posted Topics

Member Avatar for DamagePlan

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', …

Member Avatar for DamagePlan
0
72
Member Avatar for ZZucker

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"] >>> …

Member Avatar for vegaseat
0
173
Member Avatar for Valmian

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 …

Member Avatar for Valmian
0
7K
Member Avatar for knish

Looks like either a port is closed or else there's a credentials problem. But that's a guess. Jeff

Member Avatar for katharnakh
0
147
Member Avatar for Racoon200

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, …

Member Avatar for Racoon200
0
188
Member Avatar for sneekula
Member Avatar for gusbear

...for squares oriented along the axes, but not ones like (0,0), (3,4), (-1,7), (-4, 3) Jeff

Member Avatar for Narue
0
112
Member Avatar for Mr.popo

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

Member Avatar for Mr.popo
0
1K
Member Avatar for boni_go

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

Member Avatar for SteveWhite
0
453
Member Avatar for mccarthp

Also, if you are sitting behind a firewall, you might well get blocked unless you enable Python. Jeff

Member Avatar for jrcagle
0
517
Member Avatar for jem00

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 …

Member Avatar for jrcagle
0
82
Member Avatar for jem00

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 …

Member Avatar for jrcagle
0
279
Member Avatar for Roadphantom13

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, …

Member Avatar for jrcagle
0
115
Member Avatar for neverlander

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.

Member Avatar for jrcagle
0
112
Member Avatar for jem00

"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 …

Member Avatar for jem00
0
77
Member Avatar for mruane

<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) …

Member Avatar for woooee
0
83
Member Avatar for acwbrat

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 …

Member Avatar for acwbrat
0
3K
Member Avatar for Racoon200

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

Member Avatar for Racoon200
0
146
Member Avatar for Seagull One

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

Member Avatar for jrcagle
0
226
Member Avatar for eleonora

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

Member Avatar for eleonora
0
209
Member Avatar for jobs

I've resorted to creating a function: [code="Python"] def fuzzyequals(a,b,delta = 0.00001): return -delta < a-b < delta [/code] Jeff

Member Avatar for BearofNH
0
79
Member Avatar for jliu66

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), …

Member Avatar for woooee
0
167
Member Avatar for aot

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 …

Member Avatar for Quarks
0
15K
Member Avatar for maddog39

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

Member Avatar for maddog39
0
136
Member Avatar for mruane

Also, check out the cPickle module, which automagically serializes data for you into a file which then can be read back at will. Jeff

Member Avatar for jrcagle
0
120
Member Avatar for CoolFool

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, …

Member Avatar for woooee
0
166
Member Avatar for Fox5

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

Member Avatar for Fox5
0
82
Member Avatar for axn
Member Avatar for jliu66

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 …

Member Avatar for jliu66
0
13K
Member Avatar for Haze

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

Member Avatar for jrcagle
0
85
Member Avatar for mathijs

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 …

Member Avatar for mathijs
0
148
Member Avatar for Agentbob

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.

Member Avatar for Agentbob
0
147
Member Avatar for jliu66

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 …

Member Avatar for Lardmeister
0
169
Member Avatar for jobs

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 …

Member Avatar for jrcagle
0
111
Member Avatar for MakingMoney

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 …

Member Avatar for jrcagle
0
89
Member Avatar for jrcagle

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 …

Member Avatar for jrcagle
0
115
Member Avatar for mjsinpl

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

Member Avatar for paddy3118
0
80
Member Avatar for MakingMoney

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 …

Member Avatar for jrcagle
0
331
Member Avatar for muddpigeon

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, …

Member Avatar for jrcagle
0
532
Member Avatar for renochew

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), …

Member Avatar for jrcagle
0
123
Member Avatar for MakingMoney

(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 …

Member Avatar for MakingMoney
0
273
Member Avatar for thompsongunner

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 …

Member Avatar for jrcagle
0
288
Member Avatar for jrcagle

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 …

Member Avatar for jrcagle
0
100
Member Avatar for MrShoot

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 …

Member Avatar for Ene Uran
0
161
Member Avatar for Yee
Member Avatar for Yee
0
296
Member Avatar for Eclipse77

OK Vega, fess up: how do you get the bolded [ code = Python ] text in there?! I tried several kludges and failed. Jeff

Member Avatar for jrcagle
0
175
Member Avatar for slunk

[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 …

Member Avatar for jrcagle
0
762
Member Avatar for tesak

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 …

Member Avatar for jrcagle
0
106
Member Avatar for Jusa

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 …

Member Avatar for pandu22
0
519
Member Avatar for dt2611

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?

Member Avatar for bumsfeld
0
84

The End.