Forum: Python 4 Hours Ago |
| Replies: 5 Views: 129 So you literally take your object and perform a str(object)? And that's what you're trying to turn back into a proper python object? For that you would use a simple eval():
to = ['This is my... |
Forum: Python 12 Days Ago |
| Replies: 8 Views: 269 In a function declaration, the items inside the parenthesis are called parameters. These are basically variables that are "passed" to the function. By assigning a value (of 100) to a parameter you... |
Forum: Python 12 Days Ago |
| Replies: 8 Views: 269 You need to call the function costTotal and provide the parameters if needed. So your line that says print self.costTotal should actually be print costTotal()... then in your costTotal function I... |
Forum: Python 13 Days Ago |
| Replies: 8 Views: 269 Yes, you could create a general Student class and then go about creating instances of the class. Each instance would represent a different student and would contain the necessary data to... |
Forum: Python 13 Days Ago |
| Replies: 2 Views: 231 Here's a regular expression that should work for you:
re.split('([.!?] *)', a)
If you need it broken down and explained for you I can do that; otherwise, it may be more fun to investigate using the... |
Forum: Python 19 Days Ago |
| Replies: 9 Views: 323 Wow, that code is pretty long!
Here's a shortened version:
import string
# Strings are already iterable so we don't need to convert to list
message = raw_input('Enter a string: ')
# Make a... |
Forum: Python 27 Days Ago |
| Replies: 3 Views: 273 Is this psuedo-code that you're supposed to translate into Python? |
Forum: Python 29 Days Ago |
| Replies: 10 Views: 396 Hah, that's awesome...
This indicates that the "from" file is not located at C:/Python26/Renamer 3... Is that correct? C:/Python26 is likely the current working directory (it's where python.exe is... |
Forum: Python 29 Days Ago |
| Replies: 6 Views: 493 So you want to use the value of Templng for the default value of the to parameter in the translate function? |
Forum: Python 29 Days Ago |
| Replies: 6 Views: 493 It's hard to tell whether you did this or not since you didn't give us all your code, but I'm assuming that before assigning to Templng you used global Templng to let the local scope know you meant... |
Forum: Python 33 Days Ago |
| Replies: 4 Views: 283 Type your python command (*if you haven't set it up you'll need to use the full pathname to python.exe or pythonw.exe), then the name of your script, then the command line arguments... here's an... |
Forum: Python 34 Days Ago |
| Replies: 3 Views: 362 You have a number of issues in your code revolving around scope.
Here are the first few that jumped out at me:
1) In your dig_sum function, you refer to i but never define it (in your while... |
Forum: Python Nov 13th, 2009 |
| Replies: 2 Views: 235 When you return an object it isn't just automagically added to the current namespace... you need to actually store it in something.
All you'll need to do is say graph = plot_it(...), savvy? |
Forum: Python Nov 13th, 2009 |
| Replies: 11 Views: 545 Yes, but be forewarned it's psuedo-private. You can still see and access the variable, it's just obfuscated with the Class name. Look:
>>> class Cpriv(object):
... def __init__(self):
... ... |
Forum: Python Nov 13th, 2009 |
| Replies: 3 Views: 247 A dictionary. The key is the number, the value is the function.
Generate random number, then do something like my_function_dict[my_random_number](). Get it?
EDIT: To illustrate:
>>> def... |
Forum: Python Nov 13th, 2009 |
| Replies: 4 Views: 219 What is that? What are you doing?
EDIT: Also remember that dict is a reserved word in Python I suggest that you change the name |
Forum: Python Nov 13th, 2009 |
| Replies: 7 Views: 296 What functions?
The first code is not working because you're not iterating over your input anymore.
The second code is not working because your indentation is royally screwed up. Everything... |
Forum: Python Nov 13th, 2009 |
| Replies: 7 Views: 296 Unless your teacher is specifically telling you to use them in this manner, you really don't. And if he/she is, then I feel bad for you because your teacher is a terrible programmer.
If you're... |
Forum: Python Nov 13th, 2009 |
| Replies: 7 Views: 296 My first suggestion is to remove the giant try/except block. If you make a syntax error your program will quit and never tell you the reason why. That is extremely poor Python coding and opens the... |
Forum: Python Nov 10th, 2009 |
| Replies: 4 Views: 196 If you search the forum you'll see this question has been asked a bajillion times.
Here's an example from earlier today (http://www.daniweb.com/forums/post1041001.html#post1041001). |
Forum: Python Nov 10th, 2009 |
| Replies: 3 Views: 233 Just a minor logic error. This should be:
if player[0] != "r" and player[0] != "p" and player[0] != "s":
print "incorrect choice entered" |
Forum: Python Nov 10th, 2009 |
| Replies: 14 Views: 595 Okay... how about this:
>>> data_dict = {
... '1234': ['Matt', '2.5', 'CS'],
... '1000': ['John', '4.0', 'Music'],
... '1023': ['Aaron', '3.1', 'PreMed'],
... '1001': ['Paul', '3.9',... |
Forum: Python Nov 10th, 2009 |
| Replies: 8 Views: 331 Because a string is an iterable object. When using the list() method, it converts any such object to a list by iterating over it. Example:
>>> list( (1,2,3,4,5) )
[1, 2, 3, 4, 5]
>>> list( 'Hi... |
Forum: Python Nov 10th, 2009 |
| Replies: 14 Views: 595 Is this what you mean?
>>> my_dict = {'a':1, 'b':2, 'c':3}
>>> my_dict.keys()
['a', 'c', 'b']
>>> my_dict.values()
[1, 3, 2]
>>> |
Forum: Python Nov 10th, 2009 |
| Replies: 8 Views: 331 Why, yes! This case would be a good one to use the dictionary's get method, which will allow you to determine if the key is already in the dictionary or not, and act accordingly.
def... |
Forum: Python Nov 10th, 2009 |
| Replies: 2 Views: 301 The function readlines() already gives you an "array" (it's list in Python). So I guess that part's solved :icon_lol:
Welcome to the forum Linky. Please, in the future use code tags (or any... |
Forum: Python Nov 10th, 2009 |
| Replies: 12 Views: 563 If I'm not mistaken \b means "backspace". So in this example you're writing a seven digit numeral to the screen with %07d and then seven "backspaces" to clear those numerals before writing the next... |
Forum: Python Nov 9th, 2009 |
| Replies: 18 Views: 460 Here's an indexing example:
>>> mydata = [0.0] * 5
>>> mydata
[0.0, 0.0, 0.0, 0.0, 0.0]
>>> mydata[2] = 45
>>> mydata
[0.0, 0.0, 45, 0.0, 0.0]
>>> mydata[0] = 1.0
>>> mydata |
Forum: Python Nov 9th, 2009 |
| Replies: 18 Views: 460 Yes, but when you're inserting to an index, that index must exist. Index 2 does not exist in a single element list (only index 0 and index 1). When you insert, you're also extending your list by... |
Forum: Python Nov 9th, 2009 |
| Replies: 18 Views: 460 Why don't you just fire up your interpreter and see what's happening:
>>> mydata = [0.0]
>>> mydata
[0.0]
>>> # mydata only has one element
>>> mydata = [0.0] * 5
>>> mydata
[0.0, 0.0, 0.0,... |
Forum: Python Nov 9th, 2009 |
| Replies: 12 Views: 563 To overwrite the previous output you could use the system command os.system('cls') on Windows or os.system('clear') on Linux.
But if you're looking for single character control you'll need to look... |
Forum: Python Nov 9th, 2009 |
| Replies: 18 Views: 460 Create an empty list:
my_list = []
Create a list of specified length with all "blank" values:
my_list = [''] * my_length |
Forum: Python Nov 6th, 2009 |
| Replies: 6 Views: 411 I think that this may simply be the same thing using different logic:
user_input = [ 1, 2, 3 ] #all are integers
int_data = [ 1, 2, 3, 4, 5 ] #all are integers
for num in user_input:
if num... |
Forum: Python Nov 6th, 2009 |
| Replies: 6 Views: 411 Here's some examples of converting between strings, lists, lists of strings, and ints using list, str and int:
>>> usr_inp = '123456'
>>> usr_inp2 = '1,2,3,4,5,6'
>>> list(usr_inp)
['1', '2',... |
Forum: Python Nov 5th, 2009 |
| Replies: 9 Views: 297 Try this trick (I'm assuming you're using Windows)
1) Open up a terminal (command prompt window) Ctrl+R -> cmd -> [Enter]
2) Type/find path to Python executable dir C:\Py* -> [Enter]
# You... |
Forum: Python Nov 5th, 2009 |
| Replies: 7 Views: 416 We can't really do your homework for you, but the basics of a while loop are like this.
some_flag = initial_state
while some_flag (does not meet) my_condition:
perform action
update... |
Forum: Python Nov 5th, 2009 |
| Replies: 9 Views: 297 He also is using parenthesis in his print statements. I'd surmise that he's using Python 3.0, in which case the use of input is the only option. (input has been replaced by raw_input)
EDIT:... |
Forum: Python Nov 5th, 2009 |
| Replies: 2 Views: 192 def main():
print "This program illustrates a chaotic function."
print "Please enter two numbers between 0 and 1."
x = input ("Enter first number: ")
y = input ("Enter second... |
Forum: Python Nov 5th, 2009 |
| Replies: 8 Views: 312 Why not use one that does then?
I use Notepad++, but I know that even python-specific IDEs like PyScripter have parenthesis highlighting, etc. In fact, PyScripter will have a red underline on any... |
Forum: Python Nov 4th, 2009 |
| Replies: 14 Views: 476 Use replace to swap out the punctuation for an empty string (''). Then use upper on both the original and the reversed string when you compare them so that the cases are the same. |