Forum: Python 8 Days Ago |
| Replies: 4 Views: 2,511 Those are forward slashes, which do not need to be escaped (the escape character is \, which is backslash) |
Forum: Python 19 Days Ago |
| Replies: 1 Views: 205 The method os.getcwd() can only ever return a single string. There's ever only one current working directory, so when you're saying for d in os.getcwd(), you're actually iterating over the string... |
Forum: Python 21 Days Ago |
| Replies: 14 Views: 538 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 21 Days Ago |
| Replies: 8 Views: 273 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 25 Days Ago |
| Replies: 6 Views: 299 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 26 Days Ago |
| Replies: 2 Views: 166 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 26 Days Ago |
| Replies: 8 Views: 253 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 Oct 26th, 2009 |
| Replies: 17 Views: 476 So if getpos() is a function for a class object, then you forgot the most important detail. The parameter self!
Your function should be defined as such:
def getpos(self):
r1 = x,y =... |
Forum: Python Oct 24th, 2009 |
| Replies: 2 Views: 174 In the if statement you are using w[i+5].
This means that you need to make sure the maximum i plus 5 does not go out of bounds for the string. Let me demonstrate:
>>> w = 'aabbccdd'
>>> print... |
Forum: Python Oct 24th, 2009 |
| Replies: 1 Views: 455 This (http://docs.python.org/library/cgi.html#installing-your-cgi-script-on-a-unix-system) should help. Don't ever underestimate the power of documentation. |
Forum: Python Oct 23rd, 2009 |
| Replies: 10 Views: 416 Unless you run your script on a compatible platform, you will not be able to experience the joy of curses, no. If you're on windows you can either download and burn a linux live CD to boot from... |
Forum: Python Oct 23rd, 2009 |
| Replies: 10 Views: 416 The platform can be simplified to mean your operating system. If you load up a python interpreter try the following exercise:
>>> import sys
>>> sys.platform
'win32'
>>> import curses... |
Forum: Python Oct 22nd, 2009 |
| Replies: 4 Views: 502 Gribouillis
I'm not sure if this has been fixed or not (perhaps you're using a newer version of Python where this bug has been eliminated) but when I use your path.join this is what I get:
>>>... |
Forum: Python Oct 22nd, 2009 |
| Replies: 8 Views: 340 Actually, it is printing the current value of name. The employee.name is always a space (' '), because you never change it. In your get_details function, you have created a new variable called name... |
Forum: Python Oct 20th, 2009 |
| Replies: 6 Views: 371 In that case you'll want this:
c.execute("INSERT INTO a (Category, Value) VALUES (%s, %s)", tuple(row[0].split()))
Basically this takes the element [0], which represents that string 'test... |
Forum: Python Oct 14th, 2009 |
| Replies: 7 Views: 552 Eval is what you're looking for:
>>> sports = [1,23,4]
>>> eval( 'sports' )
[1, 23, 4]
>>> |
Forum: Python Oct 13th, 2009 |
| Replies: 4 Views: 191 When you open your file you should be opening it in append mode using the 'a' flag (right now you're opening it in write mode, 'w'). |
Forum: Python Oct 13th, 2009 |
| Replies: 7 Views: 552 This is a very hacked solution but:
>>> sports = ## Defined as above - snipped for length
>>> def build_html(chosenCategory):
... up_locals = sys._getframe(1).f_locals
... for each_var... |
Forum: Python Oct 10th, 2009 |
| Replies: 7 Views: 435 Note that GetValue returns a string. In order to use sum you'll need to convert all elements of self.marks to integers or floating points. You could probably get away with using a try/except block... |
Forum: Python Oct 9th, 2009 |
| Replies: 1 Views: 295 1) This program has no indentation. To preserve formatting on this forum you must wrap your code in #Code tags. However after looking closer at your post it appears that your code has no... |
Forum: Python Oct 7th, 2009 |
| Replies: 11 Views: 443 Mensa: your code was very well structured and a nice example of reading user input then using it for calculation. Here's how I've modified your code:
def calc_payment(int_rate, num_pmnts,... |
Forum: Python Sep 22nd, 2009 |
| Replies: 12 Views: 424 This process is pretty easy with Postgresql; just download and install from here (http://www.postgresql.org/). There's documentation and help resources there for you if you're a command line junkie.... |
Forum: Python Aug 14th, 2009 |
| Replies: 4 Views: 447 No. Here's the code I just used to check this:
>>> def a():
... print 'a'
... return False
...
>>> def b():
... print 'b'
... return True
... |
Forum: Python Aug 8th, 2009 |
| Replies: 7 Views: 534 This is a great site to keep in mind when you're posed with this question in the future...
www.downforeveryoneorjustme.com |
Forum: Python Aug 4th, 2009 |
| Replies: 1 Views: 211 sys.stdin is an "always open" file handle to the stdin and likewise sys.stdout. To use them, import sys. |
Forum: Python Jun 30th, 2009 |
| Replies: 2 Views: 217 I think you'll probably need to make use of eval in this case:
>>> myLengths = [3, 8, 5]
>>> for eachLength in myLengths:
... print eval("'%0" + str(eachLength) + "d' % 2")
...
002... |
Forum: Python Jun 26th, 2009 |
| Replies: 7 Views: 353 Try os.getcwd() at the beginning of your script to make sure you're actually in the TPP/engine directory.
Unless you're actually running the script from within the TPP/engine directory you'll need... |
Forum: Python Jun 26th, 2009 |
| Replies: 4 Views: 299 And also diveintopython.org (http://diveintopython.org) |
Forum: Python Jun 25th, 2009 |
| Replies: 4 Views: 601 Use os.makedirs() to make directories.
Use os.walk() or os.chdir() to move between directories. |
Forum: Python Jun 23rd, 2009 |
| Replies: 6 Views: 350 |
Forum: Python Jun 16th, 2009 |
| Replies: 3 Views: 263 I provided an answer to the question that you asked, which was
Now it is up to you to take that principal and implement it in a simple loop to finish this task. We're not here to create custom... |
Forum: Python Jun 10th, 2009 |
| Replies: 2 Views: 205 To take a series of lines in a text file that are separated by newline characters and mash them into a single line of text:
# Read from your input file using readlines(), then:
out_txt = '%s %s'... |
Forum: Python Jun 9th, 2009 |
| Replies: 3 Views: 183 loadWords()
This is your problem. While the function actually returns the dictionary, you're never actually "catching" with anything. You should be doing something like this:
my_results =... |
Forum: Geeks' Lounge Jun 9th, 2009 |
| Replies: 75 Views: 4,822 Fight Club
Reminds us that material possessions mean nothing in the end. What legacy will you leave behind? |
Forum: Python Jun 8th, 2009 |
| Replies: 4 Views: 244 import os
os.system( 'cat file.txt | grep "line2="' )
Sometimes the simplest solution is the best one. |
Forum: Python May 22nd, 2009 |
| Replies: 7 Views: 561 Here's some clues to help you!
>>> ord('A')
65
>>> ord('a')
97
>>> ord('Z')
90
>>> ord('z') |
Forum: Python May 19th, 2009 |
| Replies: 50 Views: 2,367 I suggest downloading the 'Docs and Demos' along with your wxPython install, as it gives you a great launch pad to start writing your own GUIs by giving you sample code of almost every single type of... |
Forum: Python May 19th, 2009 |
| Replies: 3 Views: 213 Your problems all stem from the fact that you aren't recognizing the 'scope' of your variables. You shouldn't be using global variables at all in fact, and your code could use a more coherent... |
Forum: Python May 15th, 2009 |
| Replies: 3 Views: 262 Holy crap no. Jython is the scourge of humanity, and in my opinion utter and complete garbage. I don't even know why it exists except to astound and bewilder. I used it once to make an application... |
Forum: Python May 10th, 2009 |
| Replies: 1 Views: 314 No, you should never be declaring classes inside a function... Your class definitions should go out on the main level and then call them from within the functions...
Also, get rid of your calls... |