Well give us a look at an example file that you are using. That will help greatly.
lllllIllIlllI 178 Veteran Poster
lllllIllIlllI 178 Veteran Poster
Well give us a look at an example file that you are using. That will help greatly.
Okay, so that will store it fine. not quite in a readable state. But really what exactly do you want? Do you need to read the file as a text. Do you need to load it back into python. Cause at the moent i dont see exactly why pickle wouldn't do.
just put raw_input("Press enter to close")
at the end of your code and then it will wait until you press enter to close. This is how i got around that problem.
Usually if you want to save something like a dictionary you will use something along the lines of pickle, what that does is it saves the dictionary/class/anything practically using an algorithm and then you can load that file again and the dictionary/class/anything will be back like you had it before.
Here is a thread describing the use of pickle
http://www.daniweb.com/forums/showthread.php?t=172900
Well it must somehow, the site says it does and im sure they wouldnt say that without some foundation at least.
http://www.crummy.com/software/BeautifulSoup/ says
Beautiful Soup is known to work with Python versions 2.4, 2.5, and (after an automatic conversion) 3.0. Currently the 3.0.x series is better at parsing bad HTML than the 3.1 series.
If you are using Python30, please note that the module md5 is gone! The md5 algorithm has shown some obvious weaknesses and has been replaced with improved hashes, check the module hashlib. For those who need backwards compatibility there is hashlib.md5()
Wow thanks for the heads up sneekula!
If you want really safe encryption that will stop people just looking at your source code and finding the password you need to use something like md5. This can encrypt a string (password) and then it is nigh impossible to decrypt it.
Here is an example i whacked together
# a great encryption tool
import md5
import sys
# i already made an md5 hash of the password: PASSWORD
password = "319f4d26e3c536b5dd871bb2c52e3178"
def checkPassword():
for key in range(3):
#get the key
p = raw_input("Enter the password >>")
#make an md5 object
mdpass = md5.new(p)
#hexdigest returns a string of the encrypted password
if mdpass.hexdigest() == password:
#password correct
return True
else:
print 'wrong password, try again'
print 'you have failed'
return False
def main():
if checkPassword():
print "Your in"
#continue to do stuff
else:
sys.exit()
if __name__ == '__main__':
main()
I think that should be as secure as you'll ever need it to be, any questions about the code, ask away! :)
Well i think i can post the first one. Beautiful Soup!
http://www.crummy.com/software/BeautifulSoup/
All you need to do is an automatic python 3 conversion on it and then it works fine with python 3. So enjoy :)
Well only if you expect the employee to work for lets say 14.5 hours, then you would have to use
if h<1:
print "error"
But if you are only dealing with whole numbers then you can stick with what you have got
if h <=0:
print "error"
Does that make sense?
I had the answer for this an hour ago but suddenly the site stopped responding. For this problem you have to split the string into bits and the count the amount of bits.. that sounds really bad.. here is some code that demonstrates this
def Digit(line):
line = line[line.rindex("J")+1:]
line = line.split()[0]
line = line.split(',')
return len(line)
Digit("28 J=5202,5204,7497,7498 SEC=WALL1")
#output 3
What this does is it first takes off all the line after the = sign and makes line equal that then we split it by the spaces and get the first bit of that. Then we are only left with the "234,14,21" bit (i just made up those numbers). Then we just split it by the comma and count the amount of things in the list and return that value. It should word every time. If it dosent it should be just a simple coding error, i havent actually tested the code :P
Shouldn't
if h <= 0: print "Can't work less than 1 hour a week!"
be changed to
if h < 1: print "Can't work less than 1 hour a week!"
That wont change anything because h<=0 will be true if h is 0 or below, the same will be for h<1. That is though, if we are only working with integers. So if the user enters a float or the program is working with floats then you would be correct shadwickman.
Umm.. i would edit those passwords there. Just asterisk them or something.
No thats correct, thats the way i had it in my example. But you are very correct :) Apart from the fact that you have not got self as a argument in __init__.
self should be the first one
Just wondering shadwickman, you know why the name has to be in the __init__ function parameters dont you? Just wondering seeing name is in your def thing, but hey, that might just be cause you completely forgot about classes :P
Is there any way to check posts per day now apart from the obvious add up the days and do the maths?
Yeah +1 to tomtetlaw. Classes are definitely the way to go. They provide a great way to put all your functions together as well as data that needs to interact can and will.
If you need to have a peek at classes then have a look here
http://www.python.org/doc/2.5.2/tut/node11.html
B
But also remember about new style classes. Now we use
class Warrior(object):
#code
That is rather than without the "(object)". This means it has more attributes and is the standard way of doing things now.
Also above i think tomtetlaw made an error when he went
def CreateWarrior(name):
def __init__( self ):
self.attributes = {
#ID
"name": name,
"age": 18,
#Developed
"strength": 0,
##Wrestling
"reflexes": 0,
"speed": 0,
"intelligence": 0,
"discipline": 0,
"physcondition": 0,
#Body
"fat": 0,
"muscle": 0,
"hunger": 0,
"sleepiness": 0,
"health": 0,
"damage": 0,
#Psychological
"mood": 0, # 0 = ultrahappy, 1 = happy, 2 = normal, 3 = mad, 4 = ultramad
"moral": 0
}
There are a few things wrong, first name should be in the init argument and he used the word def rather then class so instead what is should look like is:
class Warrior(object):
def __init__( self,name ):
self.attributes = {
#ID
"name": name,
"age": 18,
#Developed
"strength": 0,
##Wrestling
"reflexes": 0,
"speed": 0,
"intelligence": 0,
"discipline": 0,
"physcondition": 0,
#Body
"fat": 0,
"muscle": 0,
"hunger": 0,
"sleepiness": 0,
"health": 0,
"damage": 0,
#Psychological
"mood": 0, # 0 = ultrahappy, 1 = happy, 2 …
Just wondering what people thought about the update to how the profile gets viewed. Personally i kind of like it but then there is no posts/day thing. Im not sure whether thats a good thing or not personally.
To the site admins and such, is there any reason for this removal of the posts/day and to everyone else, what do you think of the update? Good or bad?
Yeah shadwickman is right, i did just that for one of my programs i used this kind of loop:
unsorted = #list of all image values RGB
ROWS = #amount of rows in image
COLLS = #amount of collumns
imagevals = []
count = 0
for f in range(len(unsorted)/ROWS):
temp = []
for f in range(COLLS):
temp.append(unsorted[count])
count += 1
imagevals.append(temp)
Note that this is untested code but it should work or be close to it, the main thing i am trying to show is how you would go about doing it.
Worth noting: This was "fixed" in Python 3; 5/10 now gives 0.5
Correct me if i'm wrong but to do an integer division in python 3 don't you now do // rather than just the usual /.
Wait just checked it, to do integer division in python 3 you use the double slash.
Ha ha ha, i just finished my science assignment on Energy Drinks and their effect on the body. Most energy drinks only have about 80mg/250mL of caffeine. But in Australia there have been about 20 deaths a year occur from people getting all caffeined up and dying.
I brought up practically exactly the same issue as you did a few months ago.
http://www.daniweb.com/forums/thread148140.html
Eventually though i used VPython instead:
http://vpython.org/
It does 3D and is pretty easy to understand. Have a look at the thread to see some of the things that is can do, all thanks to vegaseat
No worries! glad it helped someone else.
I fixed that on my machine (XP) by opening up task manager, and going to process and ending any "python.exe" processes. That fixed it for me every time.
But it really depends, sometimes it works others it dosent do a thing.
WWOOOOOO!!! Thankyou! That is perfect!
<APPLET codebase="classes" code="sort2/Main.class" width=800 height=300></APPLET>
That is the code that worked in the end. Gosh, i am so happy now. Thanks for all your help Ezzaral.
I think its because of a thing called polymorphism.. i could be wrong and sorry if i am but have a look at it here:
http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming#Python
You can read the text file word by word! :)
d = {'flight':[]}
f = #text file
for line in f:
for word in line.split():
if word == what_you_want:
d['flight'].append(word)
Hows that? Im a bit confused by exactly what you want but that will read a text file by each word. Replace the if statement with your own one that does something more relevant.
Just wondering, if no-one can solve this where should i go for help? Is there a specific java forum somewhere on the web that would be able to help me with this?
Ooh, now its all back to normal! yay!
Well my post count is back to normal now.. im still "Practically a master poster" but oh well. its not going to kill me.
Yeah for me daniweb didnt even load there for a couple of hours!
Hi everyone,
I just became a community sponsor and i was fiddling around with my account doing some changes to some things that i could do now and i realized that my post count has jumped from 524 to 604 without a single post from me!
I looked at recent posts and nothing is there. My post count after this post should be 525. Hopefully it will fix itself but if anyone can help out that would be wonderful.
Cheers
Paul
I think this is what your code needs to look like
def main():
print (" PC : Hi there.whats your name?")
userit = raw_input (" user :")
print (" Pc : Nice to meet you " ) , userit ,
userit = raw_input(" Do you like python? (A=Its Great, B=Its Ok, C=Its Rotten)")
if userit == A:
userit = userit.upper()
print ("\n Thats good. I like it too ") ,userit ,
elif userit = B:
userit = userit.upper()
print ("\n really what ever you say ") ,userit ,
elif userit = C:
userit = userit.upper()
print ("\n Thats bad ") ,userit ,
else:
print ("\n Please enter from the Above options ") ,userit
usergame = raw_input(" whats your rating in tennis? (A=best, B=better, C=better)")
if usergame == A:
usergame = userit.upper()
print ("\n wonderful i think you must compete federer ") ,userit ,
elif usergame = B:
usergame = userit.upper()
print ("\n good to play with me ") ,userit ,
elif usergame = C:
usergame = userit.upper()
print ("\n need more learn the game ") ,userit ,
else:
print ("\n Please enter from the Above options ") ,userit
userpl = raw_input(" which country do you like the most? (A=united states, B=Dubai, C=england)")
if userpl == A:
userpl = userit.upper()
print ("\n nice place to live ") ,userit ,
elif userpl = B:
userpl = userit.upper()
print ("\n Too expensive ") ,userit ,
elif userpl = C:
userpl = userit.upper()
print ("\n good choice ") ,userit ,
else:
print ("\n …
What that means is that the indentation level is not correct, this is best explained by examples:
if True:
print "this"
print "That" ##Error!! The indentation is not standard
if True:
print "this" ##Error!! No indentation
if True:
print "This"
print "That"#Error, indentation not correct.
if True:
print "This" #works Fine!! Yay
All you have to do is clean up your indentation, if you are not using an IDE i would recommend starting, they really help with indentation! :)
Threading is used to run two things at once so it could help you if needed a collision detection method to run and to run the cars as well. But personally i think you could do it without threading in pygame, all you would do is use image.rect.colliderect() and that would tell you if it collided with the rect that you provide.
Hope that helps
I have a tutorial that i wrote at this address that goes through how to display images in a wxPython way.
http://wxpython.webs.com/tutorial5.htm
Hope it helps you!
Personally i think in the end that it would be easier if you used a GUI, that way you could control everything so much easier. If you are interested in a GUI it will mean added control as well as less difficulty with some things such as making sure that the webbrowser loads fast enough to let you look at the image for 5 seconds
Yeah now i get this:
load: class Main not found.
java.lang.ClassNotFoundException: Main
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.FileNotFoundException: C:\Documents and Settings\Paul\My Documents\NetBeansProjects\Sort2\build\classes\Main.class (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
... 7 more
Exception: java.lang.ClassNotFoundException: Main
But when i put the html file in the same directory as the classes then i get this error
java.lang.NoClassDefFoundError: Main (wrong name: sort2/Main)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception: java.lang.NoClassDefFoundError: Main (wrong name: sort2/Main)
Oh and by the way i renamed the class main, and refactored it so it is still all working in netbeans.
Yeah JBennet you are exactly right.
When you remove something from a list it is unallocated from memory therefore freeing that memory up for later use.
It checks to see if l is existant, if there are no elelments in l then it will return False because your key cant be in an empty list! Therefore avoiding any unwanted Exceptions! :)
Yeah also have a look at www.pythonchallenge.com.
If you want practice have a look at the projects for beginners,
Also for other skills it might be useful to be able to document all your code very well and check up of the python style guide.http://www.python.org/dev/peps/pep-0008/
Apart from that, just try things. The more your program, your right, the better you become.
Personally i think if your that worried about efficiency then you should try a language like C++ which is a lot faster then python anyway.
But my bet would be on the larger one as that would take up less memory on your computer then lots of smaller ones.
So now my file looks like this:
<html>
<applet code="Sorter"
width="800" height="300"
CODEBASE="C:\Documents and
Settings\Paul\My
Documents\NetBeansProjects\Sort2\build
\classes\Sort2\">
</applet>
</html>
But i still get this error
oad: class Sorter not found.
java.lang.ClassNotFoundException: Sorter
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.FileNotFoundException: C:\Documents and Settings\Paul\My Documents\NetBeansProjects\Sort2\build\classes\sort2\Sorter.class (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
... 7 more
Exception: java.lang.ClassNotFoundException: Sorter
I am so confused right now, it works fine in the netbeans applet viewer
Hi
I have a sorting applet that implements Bubble Sort and Insertion sort, and i have a couple of classes in my program. I made it using netbeans and i have no main class, and when i run it using this code:
<html>
<applet code=Sorter.class
width=800 height=300>
</applet>
</html>
I get the following
java.lang.NoClassDefFoundError: Sorter (wrong name: sort2/Sorter)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception: java.lang.NoClassDefFoundError: Sorter (wrong name: sort2/Sorter)
It is in a package called sort2 in netbeans, i just wondered whats going wrong.
Cheers
Paul
Here is an A* Path finding tutorial, it will be able to help, because path finding is probably the easiest way to get through this problem.
http://www.policyalmanac.org/games/aStarTutorial.htm
Pygame can be what you make of it. It is very suited to games certainly. It is very efficient at moving things around and taking events, though its harder to write applications in, its really not meant to apps.
But traffic simulation. I reckon that that could be done rather well. Just make the right classes and start of with some pyGame tutorials to learn the basics of it and there you go!
And yes you would be able to do a slide bar game in pygame as well, as i said. Just learn the basics first.
There really arent many wxPython books at all, i think the above poster is right, wxPython in Action is one, but the problem is that
was written a long time ago and so it is slowly out dating.
If you want to learn wx then have a look over at zetcode.com for great tutorials on wxPython
What is does, is it counts the number of occurrences of the words RAF, Air Force, and History. If they do count 1 or more, then the count() function will return the amount counted,
So if you had a bit of text with only RAF and History, then you wouldn't get a match because when something is not counted it returns -1.
So you could make it more accurate by having it ask for a specific number of things, and how many of them should there be. So you could have if body.count("RAF")>4.....
That way you can make sure the whole page is about the RAF's History!
Oh and replace that large string above with what text you download from the website.
You could just do a quick count function to see if enough relevant words are in your page.
So for example:
body = "The Royal Air Force (RAF) is the United Kingdom's air force, the oldest independent air force in the world.[2] Formed on 1 April 1918,[3] the RAF has taken a significant role in British military history ever since, playing a large part in World War II and in more recent conflicts. The RAF operates almost 1,100 aircraft and, as of 31 March 2008, had a projected trained strength of 41,440 regular personnel.[4]The majority of the RAF's aircraft and personnel are based in the UK with many others serving on operations (principally Iraq, Afghanistan, Middle East, Balkans, and South Atlantic) or at long-established overseas bases (notably the Falkland Islands, Qatar, Germany, Cyprus, and Gibraltar)."
if body.count('RAF') and body.count("History") and\
body.count("air force"):
print "This source is good! :)"
Do you see what i mean? Then you can just make it more accurate and things like that!
What is the error that you are getting? Or whats going wrong, how do you know it fails?
Cheers, i re-installed all of the headers and its worked!
Thanks guys,
Cheers