Search Results

Showing results 1 to 40 of 110
Search took 0.01 seconds.
Search: Posts Made By: solsteel ; Forum: Python and child forums
Forum: Python Oct 21st, 2009
Replies: 2
Views: 203
Posted By solsteel
If it's not builtin, it must be imported from another module.>>> getattr(list, '__module__')
'__builtin__'
>>>
Forum: Python May 3rd, 2009
Replies: 5
Views: 465
Posted By solsteel
No. The work I have done interfaces with SDS/2 (http://www.sds2.com/) software. SDS/2 has a built-in interpreter, and we run scripts inside the SDS/2 3D model to automate tasks, extract and...
Forum: Python May 3rd, 2009
Replies: 5
Views: 465
Posted By solsteel
You are welcome, daviddoria. I added this routine to the geometry library I have been developing for about three years.

-BV
Forum: Python May 3rd, 2009
Replies: 5
Views: 465
Posted By solsteel
I don't know of one. This code requires a radial coordinate.
class Pt(object):
def __init__(self, x=0.0, y=0.0, z=0.0):
self.x = x
self.y = y
self.z = z

...
Forum: Python Apr 6th, 2009
Replies: 6
Views: 618
Posted By solsteel
I think NineTrails solved the error. You should use code tags. Your code would be easier to read.

Are you trying to print a string backwards?
>>> x = 'something'
>>> x[::-1]
'gnihtemos'
>>>
Forum: Python Apr 6th, 2009
Replies: 8
Views: 276
Posted By solsteel
Here's my contribution:
>>> def age_input(lower=1, upper=200):
... while True:
... age = raw_input("Enter an age between %d and %d" % (lower,upper))
... if age.isdigit():
... age =...
Forum: Python Apr 6th, 2009
Replies: 4
Views: 971
Posted By solsteel
The readlines() file method returns a list. The read() method returns a string. A str object has no insert() method but a list object does.
Forum: Python Apr 6th, 2009
Replies: 4
Views: 274
Posted By solsteel
It appears that req is an open file object of some type. Try flushing the output buffers (obj.flush()) or close the file.

-BV
Forum: Python Apr 6th, 2009
Replies: 4
Views: 971
Posted By solsteel
Changefilestring = f.read() tofilestring = f.readlines()

-BV
Forum: Python Jan 4th, 2009
Replies: 3
Views: 878
Posted By solsteel
Supply a starting index for str.find() and update it each iteration. Example:
users = '''Users
<a>User 1</a>
<a>User 2</a>
<a>User 3</a>
<a>User 4</a>
<a>User 5</a>
'''

userList = []
Forum: Python Dec 24th, 2008
Replies: 6
Views: 468
Posted By solsteel
I think Murtan is right about the histogram, but I never would have thought about that from reading the OP's posts. Instead of showing a solution, I will try to describe it and show some sample code....
Forum: Python Dec 21st, 2008
Replies: 2
Views: 352
Posted By solsteel
Here is one way to do it:
>>> class test(object):
... def change_var(self, name, value):
... globals()[name] = value
...
>>> var = 123
>>> obj = test()
>>> obj.change_var('var', 456)...
Forum: Python Dec 13th, 2008
Replies: 3
Views: 1,049
Posted By solsteel
Built-in function round() and string formatting.
>>> round(math.pi, 5)
3.1415899999999999
>>> "%0.5f" % math.pi
'3.14159'
>>> sig_digits = 6
>>> num = 123.456789
>>> "%0.*f" %...
Forum: Python Dec 11th, 2008
Replies: 3
Views: 1,466
Posted By solsteel
Please use code tags when posting code.

Are you receiving an error message? If so, please post it.

Initialize a maximum score variable (maxscore). Loop on the file object for line in file_obj:....
Forum: Python Dec 7th, 2008
Replies: 3
Views: 313
Posted By solsteel
An appropriate variable name in the for loop would be key instead of value, because you are iterating on the keys of the dictionary.
if answer == testwords[key]:
Forum: Python Dec 6th, 2008
Replies: 4
Views: 444
Posted By solsteel
Not to be picky, but string method isalpha() is preferable by some. This will avoid the string module:def phone_alpha_number(phone_num):
nums = '22233344455566677778889999'
alphas =...
Forum: Python Dec 4th, 2008
Replies: 4
Solved: Prime number
Views: 684
Posted By solsteel
If you want to determine if a number is prime or not, you should return True (if prime) or False (if not prime). Use the modulo operator to determine if the entered number is divisible by loop...
Forum: Python Dec 3rd, 2008
Replies: 5
Solved: Empty 2D Array
Views: 2,548
Posted By solsteel
I like using list comprehensions for this kind of task.
>>> cols = 4
>>> rows = 5
>>> array = [[0 for i in range(cols)] for j in range(rows)]
>>> array
[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0],...
Forum: Python Dec 2nd, 2008
Replies: 3
Views: 608
Posted By solsteel
When variables are assigned inside a function, they are always bound to the function's local namespace. The global namespace is never checked for name switch, therefore the error.
Example:
>>>...
Forum: Python Nov 29th, 2008
Replies: 5
Views: 692
Posted By solsteel
It's almost impossible to follow your code without code tags. Please use them! Like this:

.....code goes here......

You can determine the symbols defined in zipfile with dir(zipfile). 'ZipFile'...
Forum: Python Nov 29th, 2008
Replies: 5
Views: 692
Posted By solsteel
Here's another problem:
for files in files:
Should be:
import zipfile, os, time, sys, ConfigParser, zlib
def zip_fh():
zip = zipfile.ZipFile('%s.zip' % (path), 'w')
for root,...
Forum: Python Nov 28th, 2008
Replies: 3
Views: 302
Posted By solsteel
You can encapsulate your array variables in a dictionary.
>>> dd = {}
>>> for i in range(6):
... dd['Array%s' % i] = ['-']
...
>>> dd
{'Array3': ['-'], 'Array2': ['-'], 'Array1': ['-'],...
Forum: Python Nov 24th, 2008
Replies: 2
Views: 1,499
Posted By solsteel
I would like to share this function that converts a number in base 10 to any base between 2 and 36. Originally it was limited to bases 2-16.
import string

def convDecToBase(num, base, dd=False):...
Forum: Python Nov 24th, 2008
Replies: 3
Views: 404
Posted By solsteel
It depends on the type of data and how you intend to use it.
>>> adam = "john"
>>> adam += "mike"
>>> adam
'johnmike'
>>> ' '.join([adam, 'fred'])
'johnmike fred'
>>>
Forum: Python Nov 21st, 2008
Replies: 9
Views: 713
Posted By solsteel
You opened the file in mode 'r'. Try mode 'w'.
Forum: Python Nov 20th, 2008
Replies: 19
Views: 2,289
Posted By solsteel
What is the hang-up you have with CODE TAGS? Your code would look like below, and other people may actually read it!

......code goes here....
....and here....
Forum: Python Nov 18th, 2008
Replies: 19
Views: 2,289
Posted By solsteel
Here's a hint:
guess = random.choice(possible_guesses)Update possible_guesses every time a guess is made, eliminating the numbers that are greater than or less than the last guess.
Forum: Python Nov 18th, 2008
Replies: 19
Views: 2,289
Posted By solsteel
You are very welcome!
Forum: Python Nov 18th, 2008
Replies: 19
Views: 2,289
Posted By solsteel
Think about it. tries starts out as 0. Make a guess. tries is incremented to 1.
guess - 2
guess - 3

That's 3 guesses! How could it only be 2? Remember, I omitted the guess outside of the loop...
Forum: Python Nov 18th, 2008
Replies: 3
Views: 452
Posted By solsteel
In that case, you can use a try/except block to catch the error.

try:
rs.moveFirst()
# other code as needed
except Exception, e: # substitute the actual exception raised
# do...
Forum: Python Nov 18th, 2008
Replies: 3
Views: 452
Posted By solsteel
The object assigned to rs should evaluate False if empty. Have you tried:
if rs:
rs.moveFirst()
Forum: Python Nov 18th, 2008
Replies: 9
Views: 713
Posted By solsteel
Well, of course it won't work. If you pickle.dump() some data to disk, you need to pickle.load() to get the data from disk. Example:
>>> dd = {'s3': 'This is a string', 'r3': 1.5, 'i3': 1}
>>> f =...
Forum: Python Nov 17th, 2008
Replies: 19
Views: 2,289
Posted By solsteel
Are you referring to the code I posted?. Variable tries is equal to 3 after 3 guesses. Are you going to allow 4 guesses?
Forum: Python Nov 17th, 2008
Replies: 2
Views: 822
Posted By solsteel
If I understand the problem correctly, there is no need to pass q as an argument to enqueue() and dequeue().
def enqueue(self,z):
self.q.append(z)
return self.qTo reverse the...
Forum: Python Nov 17th, 2008
Replies: 19
Views: 2,289
Posted By solsteel
Oops! Accidental duplicate post.
Forum: Python Nov 17th, 2008
Replies: 19
Views: 2,289
Posted By solsteel
I cannot read your code without code tags!

Change the loop to while True. Omit the first guess. Initialize tries to 0, and increment tries after guess. Modify your if/else to if/elif/else. The...
Forum: Python Nov 14th, 2008
Replies: 9
Views: 713
Posted By solsteel
To load the values, you could do something like this:
Example config file:
Tom
10
9.7
[1,2,3]
fn = 'config.txt'
f = open(fn)
vartypes = [str,int,float,eval]
varnames =...
Forum: Python Nov 13th, 2008
Replies: 5
Views: 518
Posted By solsteel
Here's another variation:
lineList = ['Los Angeles 13,583 17,073 25.70%',
'Orange 3,882 5,692 46.60%',
'San Diego 5,673 7,062 24.50%',
'Riverside 9,250 11,714...
Forum: Python Nov 10th, 2008
Replies: 5
Views: 872
Posted By solsteel
If I understand you correctly, you want to substitute the "VALUE" of a residence feature which would be a "KEY" in a dictionary. For each different value, there will be a different key. A dictionary...
Forum: Python Nov 8th, 2008
Replies: 7
Views: 1,438
Posted By solsteel
import string

numbers = set('1234567890')
alpha = set(string.ascii_letters)
mixed = set('1234567890')
mixed.add(alpha)

file_name = 'data5.txt'

f = open(file_name)
Showing results 1 to 40 of 110

 


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

©2003 - 2009 DaniWeb® LLC