I'm in a computer security class and am working on a project involving linux viruses.
That's a little difficult to believe. If you want to know how to combat viruses, then look at Bastille or Security-Enhanced Linux from the NSA.
I'm in a computer security class and am working on a project involving linux viruses.
That's a little difficult to believe. If you want to know how to combat viruses, then look at Bastille or Security-Enhanced Linux from the NSA.
easygui is a better solution for a simple interface. If you want to learn how to program using GUIs, use Tkinter or one of the other toolsboxes. http://www.ferg.org/easygui/
So when you make the change to the attritutes of objects, it will change other attributes in other copied objects.
This is what a copy is. I think you may want separate instances of the class.
class some_class:
def __init__(self, msg):
print msg
self.var=0
if __name__== "__main__":
class_list=[some_class("test "+str(x)) for x in range(0, 2)]
print "two different classes...see"
for j in range(0, 2):
print " id for", j, id(class_list[j])
class_list[0].var=1
class_list[1].var=2
print "first var=%d but second var=%d" % (class_list[0].var, class_list[1].var)
For the time being, __always__ print the class id's during testing. It is possible to think you have 2 instances of the class when you instead have two pointers to the same class.
Edit: If this in not what you want, post again with more detail on what result you want to achieve.
Are you really too lazy to Google for "python install gasp on windows"
The standard way is
if not os.path.isfile(full_file_name):
CREATE Table
The Python Cookbook is the first place to look. The following link states "- Added conversion to and from Julian Day number". I haven't tried it.
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/117215
Some online books and tutorials are here
http://www.python-eggs.org/?row=0
click on the Python link here http://ubuntuforums.org/showthread.php?t=333867#5
Google will list many, many more.
A split on a number followed by a letter is the obvious place to start. It would be nice if all of the symbols were camel case, but I don't think you can rely on that. For the "OOH" in "C6H3Cl2COOH" (no pun intended), you can look for a match in a dictionary of symbols, but would have to allow for "He" and not stop at the "H". Just some off the top of my head thoughts.
The link
http://www.daniweb.com/forums/thread94059.html&highlight=five+click+house yields a 404 File Not Found. Try one of these (and learn how to search)
http://www.daniweb.com/forums/thread94059.html
http://www.daniweb.com/forums/thread40738.html
You want to seriously consider studying the "Starting Python" thread at the top of the forum, especially the third post (I think) which explains returning a value from a function. You obviously are not getting enough out of class and will have to compliment class with outside work. The following returns the number of days needed to exceed the goal but is not a complete solution
def threshold(dailyGains, goal):
days = 0
profit = 0
for each_value in dailyGains:
profit += each_value
days += 1
if profit > goal:
return days
Since no one else has answered, I use one string to do the job, but don't think that this is Pythonic or "SQLic". So
cursor.execute("""
INSERT INTO %s (name, gender, job, level, str, dex, intel, cha, luc)
VALUES
(%s, %s, %s, %s, %s, %s, %s, %s, %s)
""", (CharAccount, CharName, CharGender, CharJob, CharLevel, Strength, Dexterity, Inteligence, Charm, Luck))
becomes
cursor.execute(stmt)
I'm sure you can go from step a to step b, but as I said, surely there is another way.
EDIT: There has to be a MySQL forum somewhere which might be a better place to ask.
Somewhere in the function you will have to add x (list item value) to a cumulative total and compare it to goal. If total is greater than goal then return number of days (can also be a total or the for loop index+1 or iter if you use a for loop, whichever of the options is most comfortable).
I think you would use a function and pass variables to it. So if the Laplace operator is a+b-c you could do something like
def laplace_func(a, b, c):
return a+b-c
#
if __name__ == '__main__':
laplace_list=[ [1 ,2 ,3],
[3, 2, 1],
[1, 3, 2]]
for eachlist in laplace_list:
result = laplace_func(eachlist[0], eachlist[1], eachlist[2])
print "result =", result, "for", eachlist
If this isn't even close to what you want, post some sample data and describe what you want to do with it
Not too many people will open an attached pdf file. What is wrong with plain text and posting it with the thread? It can't be that long. This is the Dr Python forum which will likely know more about this.
http://sourceforge.net/forum/?group_id=83074
With most GUI's you can pass parameters with the function call, so button 1 would use button_press("1") and button 2 would use button_press("2"). If this does not work with the graphics you are using, use a pass-through function
def button_pressed():
##do common stuff here
def button_one():
print "button one pressed"
button_pressed()
def button_two():
print "button two pressed"
button_pressed()
"So the result of printSubs([1,2,3])"
You would increment a counter or use a for() loop in the range of 0-->len(list_passed) to append an increasing number of items to the "sublist_list" based on another counter or for() loop. So the first pass would append one/each individual item, the second pass would append items 0 and 1, then 1 and 2, etc., the third pass would append 3 items each, until this counter is greater than the length of the list. Perhaps someone has a more elegant solution. This brute force method will work, and if the list isn't huge, won't take all that long.
Convert them to sets and use the intersection.
Try one or more of the "Learning Python" links here. There are a lot of tutorials available elsewhere on the web
http://python-eggs.org/?row=0
Yes you can. There is more than one way. The accepted method is to use a class so try it out. Then you can use self.user_defined_character_names_list (or something shorter) anywhere in the class. The 'self' just means that it is a member (belongs to) the class. This looks like a good learning project as it covers a lot. Next, you might want to try storing data in a database. This should get you there http://www.python.org/doc/current/tut/node11.html but as an example, you basically just have to do something like
import arius ## assume this function is in a separate file
class SomeClass:
def __init__(self, variables, passed):
self.user_defined_character_names_list = []
self.prompt_main() ## calls the main prompt
def prompt_main(self):
if training2: ## or whatever
arius.training2() ## assume this is still in separate file
self.user_defined_character_names_list.append(something)
if __name__ == "__main__":
SC=SomeClass( any, variables )
IMHO a dictionary works better for menus. prompt_main() could be written as
def prompt_main():
prompt_dic={'more':'training1()', 'm':'training1()',
'phone':'phone_desc()',
'LOOK START':'room_start_desc()',
'follow':'print_follow()'} ## etc
prompt = raw_input().lower()
if prompt in prompt_dic:
eval(prompt_dic[prompt])
else:
prompt_main()
print "\n"
Some people don't like using eval() because it will execute any code given to it, but the sky won't fall when using it with the code you have written.
It is possibly the video header that is resizing. You should be able to resize and move the window manually depending on your operating system. Something along the lines of
wx.Frame.__init__(self, parent, -1, title, pos=(10,10), size=(640, 480), etc
should work also (with the emphasis on 'should').
Zero evidently means that nothing was read and it will probably continue trying to read until you tell it to stop, which is why there are multiple zeros.
With some additions to the data, note that it reports "1. first different line" as a difference when it is not and doesn't find "Another line that is different". Sorting text1Lines and text2Lines should solve the first problem since it seems to be comparing in file order. This may not make a difference since the file appears to be in ascending date order already. If there are lines in the 2nd file that are not in the first, then you will also have to insert a
diffList = list(diffInstance.compare(text2Lines, text1Lines)) routine. In general, when comparing we want to know how it is comparing.
#!/usr/bin/python
# find the difference between two texts
# tested with Python24 vegaseat 6/2/2005
import difflib
text1 = """The World's Shortest Books:
Human Rights Advances in China
Add some text lines that are not in either
1. first different line
2. line 2 added
3. also a third
"My Plan to Find the Real Killers" by OJ Simpson
"Strom Thurmond: Intelligent Quotes"
America's Most Popular Lawyers
Career Opportunities for History Majors
Different Ways to Spell "Bob"
Dr. Kevorkian's Collection of Motivational Speeches
Spotted Owl Recipes by the EPA
The Engineer's Guide to Fashion
Ralph Nader's List of Pleasures
"""
text2 = """The World's Shortest Books:
Human Rights Advances in China
"My Plan to Find the Real Killers" by OJ Simpson
"Strom Thurmond: Intelligent Quotes"
America's Most Popular Lawyers
Career Opportunities for History Majors
Different Ways to Sell "Bob"
Dr. Kevorkian's Collection of Motivational Speeches
Spotted …
Again, I would suggest using an existing and tested tool, such as imagemagick called by os.system or subprocess to convert.
They are not printable characters (probably) and so who knows where they come from. To test this, try printing the decimal value of each character. It might just be a bunch of decimal zeroes (which is zero, the printable zero is decimal 48), or EOFs, or garbage created by some sort of "noise".
for each_char in charout:
print ord(each_char),
print
You can use lists or 2 sets. But you would want both set1.difference(set2) and set2.difference(set1). You can set up a process to read both files like a merge sort would, but the set solution seems more pythonic. Depends on how large the files are though.
I have never heard of, let alone used graphics22. That being said, in general you have to declare a string variable, (which is different from a python string variable in Tkinter), and then use the graphics22 variation of "setText". Likewise, to retrieve text you would use some form of "getText". If you search whatever documentation you have for "string variable' and/or "settext" you will probably find an example that does display text. HTH
How can I combine 30 attributes into a tuple as you mentioned above so that I loop through thousands of people?
You don't have to use a tuple. That was just a convenient container for the example presented above. As vegaseat already stated, a little more info would be helpful. Give a few examples of input and what it should look like on output. It you take this from a file, and that from a list, etc. be sure to mention that. This should be fairly simple to do with python.
You have to convert the background color to a transparent color. With imagemagick you would use the convert -transparency options, but whatever method you choose, the computer does not know what is background and what is not so you have to tell it what to do. Here is Google's result for "imagemagick transparent background".
http://www.google.com/search?hl=en&q=imagemagick+transparent+background&btnG=Google+Search
Use string.split() instead and split on the commas. Python has a csv module (comma separated variables), but it looks like that would be overkill here.
I still can not figure out how to get rid of punctuation
One of the earlier posts already mentioned this.
s = raw_input("Enter string to be checked: ")
s = s.lower() ## don't use string as it is deprecated
s_ltrs_only = ""
for each_char in s:
if (each_char >= "a") and (each_char <= "z"):
s_ltrs_only += each_char
print s, s_ltrs_only
# You can use a for loop
for line in open(fname, "r"): ## One line at a time
print line
#
# or a while loop
fp=open(fname, "r")
line = fp.readline()
while line:
print line
line = fp.readline()
fp.close()
This will work for the entire file. If you mean that you would want, say the first 100 lines, the while loop would be
while (line) and (ctr < 100):
I am guessing that there are no replys here because the problem was not explained well enough. Perhaps a simple step by step example or some pseudo-code will garner more response. Example:
User enters data
Data is saved when user clicks save button
etc
I would not use root permissions, but make this an exception to the redundancy rule and create a redundant program/function with a different name that does what you want.
Have you seen this link. If all else fails you will have to convert to some known image format (pbm/netpbm?) and display that.
http://effbot.org/tkinterbook/bitmapimage.htm
You can also combine them and Python's garbage collector will then automatically close the file for you
for line in open(fname, "r"): ## One line at a time
## or
data = open(fname, "r").readlines()
for line in data:
First, when you call isprime() on the last line, you have to pass a number to test to the function, and you have to receive the result. Then you want to print out the result. As far as error messages, while testing, put some print statements in the body of the program to see what it is doing. Also, use code tags. Your response will be much greater since you aren't being rude.
## added print statements
stop = int(math.sqrt(n) + 1)
for x in range(3, stop, 2):
print "for loop", x, stop, "n%x =", n%x
if n % x == 0:
return False
I modified the earlier code for recursion. I do not like recursion and don't use it. A loop is easier to debug and understand. Unless you are specifically told that you have to use recursion, don't. Basically, the function calls itself until the length of the string is zero, or the condition is false. It then returns True or False. The print statement shows each recursion. There has to be a more elegant way to do this but I don't use recursion and haven't tested this code beyond a few simple examples.
def is_palindrome(string_in):
if (string_in):
if (string_in[0] == string_in[-1]):
result = is_palindrome(string_in[1:-1])
print string_in, "is palindrome"
if result:
return True
else:
return True ## no more letters
return False
##----------------------------------------------------------
if __name__ == "__main__":
s = raw_input("Enter palindrome string ")
result = is_palindrome( s )
print "The final result is", s,
if not result:
print "is NOT a palindrome"
else:
print "is a palindrome"
There are a few links to tutorials here. Qt seems to be the least documented of all the GUI toolkits for Python. http://www.python-eggs.org/?row=2
I'm not real sure either but perhaps something more on the line of (forgive the clumsiness of the code. I'm in a hurry)
def is_palindrome(string_in):
if string_in[0] == string_in[-1]:
return True, string_in[1:-1]
return False, string_in
##----------------------------------------------------------
if __name__ == "__main__":
s = raw_input("Enter palindrome string ")
orig_s = s
ok=1
while s:
result, s = is_palindrome( s )
if not result:
print orig_s, "is NOT a palindrome"
s=""
ok=0
if ok:
print orig_s, "is a palindrome"
P.S. you have way too much untested code. Your if statements will not work. Code one function or 20 lines, whichever is less, and then test it. Rinse and repeat.
You can also use:
if score < 60:
grade="F"
elif score < 70:
grade="D"
elif score < 80:
grade="C"
elif score < 90:
grade="B"
elif score < 101:
grade="A"
else:
print score, "is bogus"
but as stated earlier, it depends on what makes sense to you. i.e. what the outline is. Also, do you want to keep track of multiple scores for mulitple people. If so, that adds another dimension to the problem.
main() in the first program block calls itself, so yes it is an infinite loop. I think what you want is
if __name__ == "__main__":
main()
This calls main() once and then exits when main() is finished - assuming you also removed main() from def main()
Also, you can do this and avoid the extra print statements
print "Welcome to 'Textual Encounters'.\n\n"
print "Programmed by the one and only, Matthew Ruane.\n\n\n\n\n"
Here is an example using Tkinter. A Google for "graph python" will turn up all kinds of examples
http://www.daniweb.com/code/snippet583.html
Sourceforge seems to have a few possibilities like Forum Handler. You'll have to see what works for you.
http://sourceforge.net/search/?words=python+forum&type_of_search=soft&pmode=0&inex=1&sortselect=trove__160®istration_date__0=&trove__225=456&trove__274=369&trove__160=178&trove__199=426&trove__13=14&trove__1=534&trove__6=7&trove__496=499&newfilter=Apply
Code something up and try it for yourself. If you get an error message then post the code here for some help.
Also, you might subprocess instead. From the Python docs:
"The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes."
http://blog.doughellmann.com/2007/07/pymotw-subprocess.html
You will not exit the while() loop because c is never "", you want to use
while c > 2: as 1 is a break (exits the while loop), and 2 is what executes exit()-and do you want sys.exit(0) instead to exit the program?
c=3
while c > 2:
c = int(raw_input(menu))
if c ==2 :
exit()
elif c ==3 :
printScore()
elif c == 1 :
n=0
print " nieuwe spel begint nu"
a = random.randint(0,1000)
break
else :
print " verkeerde input"
but the 10,11 appear before the 6,9
like this:
10 : mathijs
11 : mathijs
13 : mathijs
6 : mathijs
8 : mathijs
9 : mathijs
and the sort+print code
A string like you are using in key list sorts left to right so the "1" in "10" is less than the 9. Convert to an int. This would not be necessary if you can use an int for the dictionary key to begin with.
def printScore():
keylist = [int(key) for key in topscore.keys()]
keylist.sort()
for key in keylist:
print " %d : %s " %(key,topscore[str(key)]