I was wondering if it was possible to use pygments with wxPython?
I want to use it on the text_ctrl widget.
If it is not possible on that widget but is possible on an other please tell me...
I was wondering if it was possible to use pygments with wxPython?
I want to use it on the text_ctrl widget.
If it is not possible on that widget but is possible on an other please tell me...
Do you know something about queries? like mysql,sqlite,...
http://docs.djangoproject.com/en/dev/topics/db/queries/
-> this is the way to make queries in django
In the again loop
you don't specify the max value for main
]if again == "":
main() #main(3) f.e.
btw why do you use the max anyway?
#!/usr/bin/python
def sums(n):
total = 0
next_odd=1
while next_odd <= n:
total += next_odd
next_odd+=2
return total
def main():
n = input('Enter a number: ')
s = sums(n)
print 'The sum of the numbers is', s
while n <= 0:
print "Please Enter a positive number."
break
main()
I'm learning pygame and followed a tutorial about a pong game.
Everything is from the tutorial except the score system, I implemented.
It does work, but instead that the score is updated, the new score is printed over the previous score.. Which isn't a nice view. How can I solve this?
(I think only the main function is important for this problem, but I'm giving whole the code to be sure)
#!/usr/bin/python
try:
import sys
import random
import math
import os
import getopt
import pygame
from socket import *
from pygame.locals import *
except ImportError, err:
print "couldn't load module. %s" % (err)
sys.exit(2)
def load_png(name):
"""Load image and return image object"""
fullname = os.path.join('data',name)
try:
image=pygame.image.load(fullname)
if image.get_alpha() is None:
image = image.convert()
else:
image = image.convert_alpha()
except pygame.error, message:
print 'Cannot load image:', fullname
raise SystemExit,message
return image, image.get_rect()
class Ball(pygame.sprite.Sprite):
def __init__(self,(xy),vector):
pygame.sprite.Sprite.__init__(self)
self.image, self.rect = load_png("ball.png")
screen = pygame.display.get_surface()
self.area = screen.get_rect()
self.vector = vector
self.hit = 0
def update(self):
newpos = self.calcnewpos(self.rect,self.vector)
self.rect = newpos
(angle,z) = self.vector
if not self.area.contains(newpos):
tl = not self.area.collidepoint(newpos.topleft)
tr = not self.area.collidepoint(newpos.topright)
bl = not self.area.collidepoint(newpos.bottomleft)
br = not self.area.collidepoint(newpos.bottomright)
if tr and tl or (br and bl):
angle = -angle
if tl and bl:
angle = math.pi - angle
player2.score+=1
if tr and br:
angle = math.pi - angle
player1.score+=1
else:
player1.rect.inflate(-3,-3)
player2.rect.inflate(-3,-3)
if self.rect.colliderect(player1.rect) == 1 and not self.hit:
angle = math.pi - angle
self.hit = not self.hit
elif self.rect.colliderect(player2.rect) == 1 and …
emhkm1 solved the problem,
almostbob your way didn't do what I wanted...
Okay ,I don't know tkinter, but I googled it in the syntax is right, are you sure that self.errorInformation is properly defined?
I don't think you would use errorInformation.insert() to update a text widget.
Which GUI are you using?
if it is wxPython you would do self.errorInformation.SetValue("value")
I have this id that should be default 15px from the bottom (which works).
But if I have content larger, the content box should grow in height, how can I specify this?
#content {
position:absolute;
top: 85px;
left:15px;
right:130px;
bottom:15px;
background-color:#00CC00;
font-family: Arial, Helvetica, Tahoma, sans-serif;
}
Thief >> Runescape
It's really odd, with some strings copy-pasting does work and with others it don't =(
I think those that fail all have in common that they have a backslash..?
how can I solve this?
Yes indeed, I was planning to build a GUI anyway, but it would be nice if I also had a command line utility =(
but I'm afraid there is no other solution
hm, i will google a bit more to find a workaround for the copy-paste problem without using your function, because the input can contain any character so I can't choose which one I should use as filter
I see, can you replace the colon with the enter?
caus the problem only occurs when I copy-paste a long string, if I just type it, it will work without your function =)
I have a code in which the user should pass something through raw_input, this works fine for strings less then one line,
but when I copy-paste a longer string, only the first line is passed by raw_input, how can I also past the rest of the string?
I found out that I had lowercased every character in the text variable, this caused the error
I have to pass a dictionary trough raw_input,
but raw_input makes it a string so I thought using eval() it would convert to a dictionary? am I wrong @ this point?
I'm using the rsa module (easy_install rsa), and if I use it from command line:
import rsa
public,private = rsa.gen_pubpriv_keys(3)
cipher=rsa.encrypt("test",public)
rsa.decrypt("cipher",private)
this will return test again. (like expected)
but in my code it gives a zlib error -3 incorrect headers
def RSA(txt):
global crypt
if crypt=="en":
key=raw_input("Public key:")
ciphertext=rsa.encrypt(txt,eval(key))
else:
key=raw_input("Private key:")
ciphertext=rsa.decrypt(txt,eval(key))
return ciphertext
I really don't know where the problem is =( txt is a string, eval(key) is a dict...
and it is btw only the decryption that fails, the encryption works like a charm...
please help me =)
Here's the 2.0 version (I hope):
string='\xb4\xe0\xa0LH/\xefO\xc9|y7&"Af' code = [ord(char) for char in string] print "This is your code:"," ".join([str(char) for char in code]) #User inputs the code later: usercode = raw_input("What's your code, seperated by spaces: ") usercode = usercode.split(" ") decode = [chr(int(char)) for char in usercode] str2 = "".join(decode) print string == str2 ## The user inputted string becomes the original ## string at line 1
That works perfect :) thanks
there is though one thing I don't get,
Why is in this case the '\xb4\xe0\xa0LH/\xefO\xc9|y7&"Af' interpreted different as in my first code?
God Dammit, I'm a 2.6 programmer ;p
2.6 doesn't support the for loop on the end in the first code part.
You don't know perhaps how it should be in 2.6?
b'' would be the best, since you are working with hex strings
'\xb4\xe0\xa0LH/\xefO\xc9|y7&"Af' is actually:
0x180, 0x224, 0x160, 0x76, 0x72, 0x47, 0x239, 0x79, 0x201, 0x124, 0x121, 0x55, 0x38, 0x34,, 0x65, 0x102So if someone were to input that,
they would type 180, then 224, then etc,
and you unichr it into one string
Okay I can follow a bit,
suppose someone encrypts a text with AES and get as output:\xb4\xe0\xa0lh/\xefo\xc9|y7&"af
After a while the person wants to get the original text and wants to decrypt it with AES, he inserts as text \xb4\xe0\xa0lh/\xefo\xc9|y7&"af and uses the same pass as he previously used. How should my program format the input? It has to give as length 16.
string=b'\xb4\xe0\xa0LH/\xefO\xc9|y7&"Af'
str=u'\xb4\xe0\xa0LH/\xefO\xc9|y7&"Af'
len(string) # 16
len(str) #also 16
Which one is the best to use?
btw in this case I can append the b or u before the quotes but what if it's a variable?
string=input #string = binput or uinpit won't work...
Lol you did exactly the reverse of what I want :D
I want to know how to make it length 16 like command prompt says
I have found a module pycrypto which has an AES encryption and decryption function, in commandline everything works fine both encryption and decryption,
but if I want to implement it in my program, it fails =(
def aes(txt):
global crypt
message="".join(txt) #format the message which has to be encrypted/decrypted to a string
c=0
plist="".join(pflist)
while len(plist)<15:
plist+="a"
c+=1
#loop is to be sure the password has at least 16 characters.
plist+=str(c)
obj=AES.new(plist[:16], AES.MODE_ECB)
if crypt == "en":
c=0
while len(message)/16 != len(message)//16:
message+="a"
c+=1
#loop is to be sure the message is a multiple of 16
ciphertext=obj.encrypt(message)
else:
print message,len(message)
ciphertext=obj.decrypt(message)
return ciphertext
The encryption system succeeds, but the decryption system fails
if I decrypt it with \xb4\xe0\xa0LH/\xefO\xc9|y7&"Af
the program says it has a length of 31 (which strictly seen is also true),
but if you do the following in command line it will say that the length is 16
string='\xb4\xe0\xa0LH/\xefO\xc9|y7&"Af'
len(string)
I don't know what's wrong... I think it has to do something with the type in which the \xb4\xe0\xa0LH/\xefO\xc9|y7&"Af is passed but I'm not sure...
SELECT * FROM data WHERE url = "daniweb.com";
you mean something like that?
But like your code, if I don't search for a word that is in the list, it gives ne an index error. That's not converting anything, just spitting out the same word. I was thinking like the integer 10 to "ten"
Okay if U give a number in words larger then nine it will throw an error,
but I just used the same example as the topic starter.
the thing you ask is the reverse, if U want that you have to do:
def numtoword(num):
wordlist=["zero","one","two","three","four","five","six","seven","eight","nine"]
if int(num)>len(wordlist):
print "sorry that number is not in the list"
else:
return wordlist[int(num)]
So what is the program supposed to do? Are you supposed to input a number and get the word form of the number? Or input the word and get the integer it represents?
And incase you didn't know the code tags they are [COD'E] [/COD'E] with out the ' in them.this is code......
I think he means that you have to pass a word and convert it in an integer.
just like my code does ...
camigirl4k3,
you got to learn to use the necessary indentations with your statement blocks.
The indentations are maybe changed because camigirl4k3 doesn't use code tags
and what is your question?
In your case it's actually much easier to use:
def wordtonum(word):
wordList = ["zero","one","two","three","four","five","six","seven","eight","nine"]
return int(wordList.index(word))
that's why I used the d+=1,
but you can forget about that, with your tip about using a larger polibius square, I was able to solve my problem!
(I used a 8x8 square though)
if digit is in string form: digit[:1]
if the digit is an integer: str(digit)[:1]
*or even easier: str(digit)[0]
Okay your right,
thanks, but beside do you know why it didn't work with 2 spaces after each other
I think the easiest way is to go the ajax way,
this can collect things from the server and show them on the webpage dynamicly without refreshing the page
I don't see any reason why a space and number characters couldn't be added to your Polybius square.
I know it is possible, but just in this case why won't it work?
*It is possible with a 6x6 like the adfgvx code, but then I still have the problems with other chars like "!","&",...
so after all I still need this...
First: Please use code tags! [code=c]code[/code]
Second: I think this :
window.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
should be:
window.addWindowListener(new WindowAdapter()){
public void windowClosing(WindowEvent e){
System.exit(0);
}
};
Can someone tell me why the following code does not work if there are 2 spaces after each other(in txt)?, one off the two spaces stays in l6 although it should be stored in nonascii and deleted form l6 :confused:
c=0
d=0
nonascii=[]
l6=list(txt)
for char in l6:
print char + "dd"
if char in ascii_lowercase:
pass
else:
nonascii.append([d,char])
l6.pop(c)
d+=1
c+=1
d+=1
Nevermind I found the solution myself, I just delete all non-ascii characters before I do the crypting and store the location + the char in a list.
After the encryption I restore them ;)
I have created a script to encrypt and decrypt a text message based on the bifid cipher(wiki about bifid)
everything works fine IF the text message does only contain letters.
How can I integrate the ability off spaces etc... the best way?
by adding them to my alphabet might solve it?
It will be very difficult to understand the code because I didn't add help messages, but I just follow the way like it is described on the wikipedia page.
(the pf is the passphrase which is passed by globals)
def bifid(txt):
global crypt
l1=[]
l2=[]
l3=[]
l4=[]
l5=[]
l0=[]
i=0
temp=list(pf)
while i < len(temp):
if temp[0] in l1 or temp[0] in l2 or temp[0] in l3 or temp[0] in l4 or temp[0] in l5:
pass
else:
if len(l1)<5: l1.append(temp[0])
elif len(l2)<5: l2.append(temp[0])
elif len(l3)<5: l3.append(temp[0])
elif len(l4)<5: l4.append(temp[0])
elif len(l5)<5: l5.append(temp[0])
temp.pop(0)
alph=list(ascii_lowercase)
while i < len(alph):
if alph[0] in l1 or alph[0] in l2 or alph[0] in l3 or alph[0] in l4 or alph[0] in l5:
pass
else:
if len(l1)<5: l1.append(alph[0])
elif len(l2)<5: l2.append(alph[0])
elif len(l3)<5: l3.append(alph[0])
elif len(l4)<5: l4.append(alph[0])
elif len(l5)<5: l5.append(alph[0])
alph.pop(0)
if crypt=="en":
l6=list(txt)
l7=[]
l8=[]
for i in l6:
if i in l1: l7.append('1');l8.append(str(l1.index(i)+1))
elif i in l2: l7.append('2');l8.append(str(l2.index(i)+1))
elif i in l3: l7.append('3');l8.append(str(l3.index(i)+1))
elif i in l4: l7.append('4');l8.append(str(l4.index(i)+1))
else: l7.append('5');l8.append(str(l5.index(i)+1))
l9="".join(l7)+"".join(l8)
l9=[l9[i:i+2] for i in range(0,len(l9),2)]
l10=[]
for i in l9:
r=list(i)
if r[0]=="1": l10.append(l1[int(r[1])-1])
elif r[0]=="2": l10.append(l2[int(r[1])-1])
elif r[0]=="3": l10.append(l3[int(r[1])-1])
elif …
Indiana-Jones-->Cowboys =D
To make some things clear:
-Ditz you were not allowed to post twice in a row!
-Anastacia, you just skipped 759 pages :f
Yogi bear was the last post of the first page
I go on with Paramore...
Paramore --> Paramount
Bump*
I'm currently winning
Nevermind It did not work...
can you give an example + expected output
I recently started with developing D-CM, a tool for web-programmers.
It is a GUI that bundles a file manager, mysql, ftp, text-editor in one
I wanted to know what the daniweb community thought about this so if there are people willing to test it
-goto http://code.google.com/p/d-cm and download the latest tar.gz
(if you prefer the most recent version you can download the project using svn)
btw it is made in python using wxPython