Search Results

Showing results 1 to 40 of 216
Search took 0.02 seconds.
Search: Posts Made By: jrcagle ; Forum: Python and child forums
Forum: Python Mar 1st, 2009
Replies: 6
Views: 441
Posted By jrcagle
The phrase


for line in data:
...


assigns the variable "line" to each interated string terminated by '\n' within the data.

So if you inserted the statement
Forum: Python Feb 27th, 2009
Replies: 4
Views: 1,784
Posted By jrcagle
Search this forum for Vega's decimal to binary converter. Your code is reading the data correctly; now you just have to find the right way to display it.

Jeff
Forum: Python Feb 27th, 2009
Replies: 9
Views: 1,143
Posted By jrcagle
Interesting concept. Two potential problems:

(1) What if the images are not all the same size?

(2) How does the code decide what framerate to use?

Jeff
Forum: Python Feb 27th, 2009
Replies: 9
Views: 1,140
Posted By jrcagle
Mark as solved and give Bear of NH props. :)

Jeff
Forum: Python Feb 25th, 2009
Replies: 9
Views: 1,140
Posted By jrcagle
That's cool. I didn't even know there was a PySerial module.

First, the error messages are confusing. Are those the result of the print motor.read(motor.InWaiting()) command?

Second, just to...
Forum: Python Feb 22nd, 2009
Replies: 3
Views: 2,000
Posted By jrcagle
Lists of lists work fine as container arrays (not mathematical arrays, but you don't seem to be wanting that). So:


nlat=10
mylist = []

for x in range(0,nlat):
tmp = []

for y in...
Forum: Python Feb 16th, 2009
Replies: 8
Views: 1,824
Posted By jrcagle
I really like the text we used for my high-school level class: Python Programming for the Absolute Beginner. Two caveats -- it's game-oriented, and it doesn't use Python 3.0.

That said, it...
Forum: Python Feb 14th, 2009
Replies: 5
Views: 635
Posted By jrcagle
One more thought: lists of lists in Python function reasonably well as arrays:


mylist = [[1,2,3],[4,5,6],[7,8,9]]

print mylist[0][2]
3


I say "reasonably well" -- there aren't any linear...
Forum: Python Feb 14th, 2009
Replies: 3
Views: 860
Posted By jrcagle
>>> class Thing(object):
pass

>>> t = Thing()
>>> dir(t)
['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__',...
Forum: Python Feb 14th, 2009
Replies: 3
Views: 508
Posted By jrcagle
Can't speak to IPython, but a simple file copy will solve the first problem.
Forum: Python Feb 14th, 2009
Replies: 2
Views: 504
Posted By jrcagle
Two thoughts.

(1) You're writing code as if it were C or Pascal. A better way is to write a class:


class Bird(object):

def __init__(self, nID=0, ter=0, year=0, fled=0, age=0.0):
...
Forum: Python Jan 31st, 2009
Replies: 2
Views: 752
Posted By jrcagle
This appears to work:

>>> im = Image.open("24bit test.bmp")
>>> im2 = im.convert("P")
>>> im2.save("256bit test.bmp")

The bit-depth of the output file is 8, so I assume that's what you were...
Forum: Python Jul 12th, 2008
Replies: 16
Views: 2,980
Posted By jrcagle
Or this:


try:
val = int(item)
if val > 0:
do stuff for positive numbers
elif val < 0:
do stuff for negative numbers
else: # don't omit zero!
Forum: Python Jul 9th, 2008
Replies: 8
Views: 1,829
Posted By jrcagle
Good news: the convention for scientific notation

2.72e-2 (which is the correct rendering)

is so well-recognized that superscripting is not required.

Jeff
Forum: Python Jun 6th, 2008
Replies: 2
Solved: keys problem
Views: 485
Posted By jrcagle
Well, that question may not have an answer if the values are not unique; for example, if

book['key1'] = {'keya':valuea, 'keyb':valueb}

and

book['key2'] = {'keya':valuec, 'keyd':valued}
...
Forum: Python Jun 4th, 2008
Replies: 4
Views: 589
Posted By jrcagle
Absolutely. You need ... dictionaries.


store_dict = {}
f1 = open("ITEMS.txt")
for line in f1:
store, item = line.strip("/n").split(" ")
store_dict[store] = item
f1.close()
Forum: Python May 29th, 2008
Replies: 1
Solved: Network help
Views: 672
Posted By jrcagle
Yes, the standard way of writing a shell (which is what you are doing) is like this:


while True:
inputline = raw_input(myprompt)
parse inputline into command, operands
if command...
Forum: Python May 25th, 2008
Replies: 8
Views: 1,559
Posted By jrcagle
OK, wait. In your source code directory, you have

myprog.pyw
myprog.pyc

Yes?

What happens if you double-click "myprog.pyw"?
Forum: Python May 25th, 2008
Replies: 1
Solved: If and Else
Views: 429
Posted By jrcagle
That code won't work. Here's why:

"or" doesn't mean "one of these" in Python, or any other computing language. Instead, "or" means "True if one or both operands is True; False if both are...
Forum: Python May 25th, 2008
Replies: 8
Views: 1,559
Posted By jrcagle
Two things:

(1) I can double-click on your program and get a nice little Hello, World window, along with the command-prompt window. Do you get something else?

(2) If you manually rename the...
Forum: Python May 25th, 2008
Replies: 7
Views: 1,393
Posted By jrcagle
OK, so give an idea of what the tag looks like, and we might be able to help.

Jeff
Forum: Python May 25th, 2008
Replies: 8
Views: 1,559
Posted By jrcagle
Actually, it probably does something and then closes the window immediately -- which means you can't see it!

Try this:


print "Hello, World"
raw_input("Press <Enter> to exit.")


If you...
Forum: Python May 25th, 2008
Replies: 7
Views: 1,393
Posted By jrcagle
well, you might consider the BeautifulSoup module.

link:

http://www.crummy.com/software/BeautifulSoup/

It has the capability to extract tags and values relatively easily.

Jeff
Forum: Python May 24th, 2008
Replies: 1
Views: 509
Posted By jrcagle
It can be due to any exception whatsoever. To find out, you'll need to isolate the offending lines.

I often run my code through IDLE, which prints exceptions. There might be another solution...
Forum: Python May 24th, 2008
Replies: 2
Views: 588
Posted By jrcagle
There's a second way to think about this as well, and it's well adapted to real-time operating systems (read: robotics).

Suppose you have a speaker object, a listener object, and a thinker object...
Forum: Python May 24th, 2008
Replies: 2
Views: 588
Posted By jrcagle
what about


class MySpeechParser(...):
self.topic = "Dinosaurs"
sentence = self.GetSentence()
topic = self.DiscernTopic(sentence)
if topic != self.topic:
...
Forum: Python May 24th, 2008
Replies: 2
Views: 664
Posted By jrcagle
Look for a delimiter between the rows and .count() them.

Jeff
Forum: Python May 19th, 2008
Replies: 7
Solved: Type Erorr nr2
Views: 673
Posted By jrcagle
Instead of debugging, if it's OK, I'll talk about *how* to debug.

Since the error is coming from line 42 (line 31 in the code above), insert a print statement just prior to line 31:


...
pile...
Forum: Python Apr 27th, 2008
Replies: 3
Solved: new to python
Views: 575
Posted By jrcagle
Here's one possibility:


def get_four(mylist, index):
retval = ""
for i in range(index, min(index+4, len(mylist))):
retval += str(mylist[i])+"\t"
return retval

def...
Forum: Python Apr 27th, 2008
Replies: 3
Solved: new to python
Views: 575
Posted By jrcagle
So you want something like this (formatting not to scale!):


Prime Non-prime
2 3 5 7 1 4 6 8
11 13 17 19 9 10 12 14


?
Forum: Python Apr 23rd, 2008
Replies: 5
Solved: while loop?
Views: 1,266
Posted By jrcagle
Hm. I wonder if it's the same one I've used, which is a wrapper for pygame that works reasonably well; it's out of the Dawson book "Python Prog. for the Absolute Beginner."

Jeff
Forum: Python Apr 21st, 2008
Replies: 5
Solved: while loop?
Views: 1,266
Posted By jrcagle
What's the issue with livewires?

Jeff
Forum: Python Apr 18th, 2008
Replies: 1
Views: 580
Posted By jrcagle
I think you want a dictionary, if I understand correctly. The dictionary is the standard way of mapping one set of items to another.

So you have

mydict = {URL1: 13, URL2: 0, URL3: 3, URL4: 2,...
Forum: Python Apr 12th, 2008
Replies: 4
Views: 543
Posted By jrcagle
I would do this:

print hour + ":" + minute

The , character in a print statement means "print on the same line and insert a space."

By contrast, the + operator on strings joins them together...
Forum: Python Apr 12th, 2008
Replies: 2
Views: 506
Posted By jrcagle
Check out the eval() function.

Jeff
Forum: Python Apr 12th, 2008
Replies: 4
Views: 543
Posted By jrcagle
Yes, yes, and yes. Welcome to the freedom of Python. :)

First of all, as is typical for Python, there is a module called time (and another one, datetime) that does exactly this stuff...
Forum: Python Apr 12th, 2008
Replies: 1
Views: 449
Posted By jrcagle
Hi. A couple of suggestions.

(1) (minor) mydict2 should be generated dynamically from mydict1 so that if you ever decide to change mydict1, it will automagically change along with it.

Here's...
Forum: Python Apr 12th, 2008
Replies: 6
Views: 925
Posted By jrcagle
I've never used VPython, but the documentation looks accessible. Can you post your code?

Jeff
Forum: Python Apr 9th, 2008
Replies: 8
Solved: need help!
Views: 690
Posted By jrcagle
It is a bit tricky. Can you explain the problem more precisely? For example, what do each of the fields in the string

"1lghB H i 71.9 H H -19.94"

mean?

Jeff
Forum: Python Apr 9th, 2008
Replies: 6
Views: 925
Posted By jrcagle
I'm guessing that what you want is an event loop:


while True:
check for events
respond to events


and then all of your many while loops could be separate events. What do you have...
Showing results 1 to 40 of 216

 


About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC