Yeah i just double checked and i am getting the same error. Sorry about that, it looked rather promising!
hmm.. if you only have 13 files, then maybe you could make a dictionary with the values of the length.
Yeah i just double checked and i am getting the same error. Sorry about that, it looked rather promising!
hmm.. if you only have 13 files, then maybe you could make a dictionary with the values of the length.
Well i could be a bit biased, i am very much a wxPython guy, i love it, its a smart, easy to use GUI. Oh and also, wxPython is cross platform
People tend to not use Tkinter, as it is not that powerful and does not have that many things going for it.
If you know GTK then there really would be no hard in using pyGTK, but i have found with switching between wxWidgets and wxPython that there isnt that much that is actually the same apart from what is looks like. The general things will stay the same, such as widgets and such, but the code style will be different.
I would say after reading Dive into Python is probably all you need in the way of a book, because in the end after you know all that book has to offer you will know practically all that you need to just muck around with python.
If you are looking for GUI's and books/tutorials for that then i would reccomend zetcode.com, it has a great wxPython tutorial.
Personally wxPython is my favourite GUI in python, if you have used Qt then there is pyQt if you are familliar with that.
There is a thread on this forum about learning wxPython as well if you need some extra tips. I would reccomend getting a full understanding of python before starting GUI's but it is a lot lot lot lot simpler then C++ guis! :)
Personally i would definitely go for Dive Into Python, it is a long and very comprehensive book. I went back to one of its chapters just the other day to read up on unit testing and found it to be a great help.
Seeing you already know C++ the migration to python will be most likely quick and easy.
Hmm i found this with some files too. Does it do that for all files? Or just a couple?
If you want to make python into an executable file, thats easy with py2exe!
http://www.py2exe.org/
I started learning C++ as my first language a couple of years ago but was almost killed by the amount of syntax i didnt understand, so i started python instead. Its easy, simple and great fun. I still use C++ today (as you would know, been posting on C++ forum) but not as much as python. I really only use C++ for things i cant do in python, because at the end of the day, python is easier and great fun!
Hold the phone, the actual thing you need to import is pympgedit.
And when you install it you need to log on and off before it works.. changes to the PYTHONPATH
What i would do is just sleep the program until the next song is ready, to find out how long to sleep though is the hard thing, so you can either make a dictionary with all the songs and their times. Or you can use something like this:
>>> import mpgedit
>>> play = mpgedit.Play('example.mp3')
>>> play.total_time()
(213, 129)
>>> secs, msecs = play.total_time()
>>> mins = secs / 60
>>> secs = secs - mins * 60
>>> print "%d:%02d minutes" % (mins, secs)
3:33 minutes
from http://simonwillison.net/2003/Dec/4/mp3lengths/
This of course needs a module, that is:
http://www.mpgedit.org/mpgedit/download_sdks.html
It worked fine on my computer so hopefully it will work on yours.
Okay so i have windows XP, Microsoft Visual C++ 2008 Express Edition, what SDK do i need?
Yeah just reading it through a little more we come to this:
Block layout should be as illustrated in example 1 below (recommended) or example 2, and must not be as shown in example 3 [4]. Function and class blocks must use the block layout of example 2.
example 1:
while (!done) {
doSomething();
done = moreToDo();
}
example 2
while (!done)
{
doSomething();
done = moreToDo();
}
example 3 -- The wrong way
while (!done)
{
doSomething();
done = moreToDo();
}
So hopefully that clears it up! :)
It seems that it is really up to personal preference. At the style guide at
http://geosoft.no/development/cppstyle.html
it seems that is it often interchanged, so whatever feels right to you.
I know i always use the one with the brace on the next line.
Thanks Ancient Dragon, that fixed the issues with winnt.h, but winbase.h is stuffed. I think this comes from my brother trying direct x with no success some time ago.
So does anyone know where i can get a replacement winbase.h?
Or perhaps where i could just re-download all headers?
Self is useful in classes as it attaches it to the class, put simply if self. is in front of a variable you can then access it from any function in the class as well as outside the class.
Here is an example
class test(object):
def __init__(self):
self.x = 1
def printer(self):
print self.x
t = test()
t.printer()
print t.x
Hope that sorts things out.
Yay 500th post!
All you have to do is do something like:
self.page1.campus.GetValue()
And that would return the value of that textCtrl, all of what you need is accessed through self.pagenumber.textctrl
Yeah it runs on my second computer fine.. The only problem seems to be with winnt.h.. Should i just redownload that file from somewhere? And i am using XP, and Visual C++ 6
Yeah i am using the "Win32 Project" and even the default one dosent compile. Do i have to reinstall an SDK? Or is there something else?
I am using this code here:
#include "stdafx.h"
#include "windows.h"
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
MessageBox(NULL, "Goodbye, cruel world!", "Note", MB_OK);
return 0;
}
But no matter what i do i keep getting this built error:
------ Build started: Project: Gui, Configuration: Debug Win32 ------
Compiling...
Gui.cpp
c:\program files\microsoft sdks\windows\v6.0a\include\winnt.h(236) : error C2146: syntax error : missing ';' before identifier 'PVOID64'
c:\program files\microsoft sdks\windows\v6.0a\include\winnt.h(236) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\program files\microsoft sdks\windows\v6.0a\include\winnt.h(7818) : error C2146: syntax error : missing ';' before identifier 'Buffer'
c:\program files\microsoft sdks\windows\v6.0a\include\winnt.h(7818) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\program files\microsoft sdks\windows\v6.0a\include\winnt.h(7818) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
I was wondering if anyone will be able to help me out so it will be able to compile.
Cheers
Paul
Just a word of advice, instead of using
from wxpython.wx import *
Use
import wx
And then you just refer to things like wx.TextCtrl, rather then wxTextCtrl. So just add a dot.
And i cant find a fault on my computer, or i am not looking in the right place, what is meant to show up when you click audit? Can you give a tad more info?
Thanks
Ah thats a lot, that helps me out greatly.
Yeah, really now. Look i had a brain fade, im not a complete idiot. Found it, thanks for your info, it is very useful.
Cheers
Use a list with them all in. And you only need strings, not checkBox Items
self.box = wxCheckListBox ( self.panel, 100, size = ( 250, 200 ), choices = ["One",'Two','Three'], style = wx.LB_HSCROLL )
how do i get to project properties?
Firstly yes, i stuffed up what i was trying to include in the first post. Woops.
But when coding should i use #include <something.h> as a standard or does is change all the time.
Hey everyone!
I was wondering apart from
[noparse]
[code]
[icode]
[url]
What other tags are there?
Its a way of communicating between two computers, you open a socket between the two (think of it as a pipeline) and then along that pipeline data is transferred. Have a look here:
http://www.devshed.com/c/a/Python/Sockets-in-Python/ that is the one i used to learn them.
I was just wondering, in all of the code snippets i see there is no
#include "stdafx.h"
in them, but i cannot compile a program without it.
Is this a Microsoft Visual C++ that is the problem or am i just missing the point here?
Hi guys,
When i run my programs in c i always use things like
include "stdio"
But then i see things like
include "stdio.h"
and
include <stdio>
I was wondering which one i should use and also why there are so many different ways.
Cheers
Try having a look at some socket tutorials. They are great for network tutorials
Yeah thats it! Well done, there are other ways to do it as well.
class disk(object):
y = 1
x = 2
This means you dont have to make an instance of the class
print disk.x
print disk.y
#output
#1
#2
Write a module, it can be whatever you like, then fill it with lots of useful function and stuff that will be able to make you codeing quicker later!
You have to install it if your wondering. But on linux its different. Repositries and such.
This is the problem:
self.money - self.deposit = self.bankbalance
Change it to this
self.bankbalance = self.money - self.deposit
Your operations always have to be on the Right side of the "=" sign
Ah what you have to do is have an __init__ method, this is a method that runs when the class is instantiated (when you make a variable of it)
import random
class NorbertQuest(object):
def __init__(self):
self.w = 0
self.level = 1
self.m = random.randrange(50)+1+level*5
self.cost = 0
self.xp = 0
self.health = 150
self.ehealth = 100
self.money = 0
def Shop():
self.weapon1 = "Steel Knuckles"
self.weapon2 = "Knife"
self.weapon3 = "Sword"
self.weapon4 = "Gun"
self.weapon5 = "Rocket Launcher"
print \
"""
What'll it be?
1 - Steel Knuckles 20$
2 - Knife 30$
3 - Sword 100$
4 - Gun 300$
5 - Rocket Launcher 1000$
Type exit to quit.
"""
self.z = input("Which weapon do you want?")
if self.z == 1:
self.cost = 20
if self.money >= self.cost:
print"You have bought",self.weapon1
self.money = self.money - self.cost
self.w = 1
self.mode = "restart"
elif self.money < self.cost:
print"You don't have enough gold to buy this."
raw_input("Press [enter] to exit.")
self.mode = "restart"
elif self.z == 2:
self.cost = 30
if self.money >= self.cost:
print"You have bought",self.weapon2
self.money = self.money - self.cost
self.w = 2
self.mode = "restart"
elif self.money < self.cost:
print"You don't have enough gold to buy this."
raw_input("Press [enter] to exit.")
self.mode = "restart"
elif self.z == 3:
self.cost = 100
if money >= self.cost:
print"You have bought",self.weapon3
self.money = self.money - self.cost
self.w = 3
self.mode = "restart"
elif self.money < self.cost:
print"You don't have enough gold to buy this."
raw_input("Press [enter] to exit.")
self.mode = …
Okay so here is some working code. Make sure you can understand everything in it, if you dont ask questions make sure you can understand why things are the way there are:
import random
def chance():
number = raw_input("How many random numbers do you want?: ")
l = []
for each in range(int(number)):
n = random.randrange(100)+1
l.append(n)
return l
def extreme(x):
z = x + 5
y = z - 3
return z, y
#main
repeat = 0
while repeat != 2:
x = input("Enter a value for x: ")
z, y = extreme(x)
print x,"+ 5 =",z
print z,"- 2 =",y
for f in chance():
print f
repeat=input("Do you want to go again? Yes [1] or no [2]: ")
raw_input("Press Enter to exit!")
What about the number variable, i cant find where it is made:
import random
def chance(number):
number = input
for each in xrange(number):
n = random.randrange(100)+1
return n
def extreme(x):
z = x + 5
y = z - 3
return z, y
#main
repeat = 0
while repeat != 2:
x = input("Enter a value for x: ")
z, y = extreme(x)
print x," + 5 = ",z
print z," - 2 = ",y
n = chance(number) #<--------- Where is number made
input = raw_input("How many random numbers do you want?: ")
#also never use the word input as a word, otherwise when you call input() again it will not work. Use a different variable name
print n
repeat=input("Do you want to go again? Yes [1] or no [1]: ")
raw_input("Press Enter to exit!")
You can return it like this:
def returnTwoThings():
return 1,2
a,b = returnTwoThings()
print a
print b
#output
#1
#2
I simply find this thread amazing, almost 200,000 views. It is now the top viewed python thread, beating second by almost 50 000 views. Im dumfounded how this works.. some google search i think must be leading here. Or norbert has 200 000 friends :)
sourceforge definitley!
Peronally grib, i do a lot of projects that are already done. I mean for the most part there a very few things that havent been done before and there is a learning experience in it so i can understand exactly why he is doing it.
Use a try, except statement:
import os, sys
folder = os.path.abs("pathtoscriptsfolder")
sys.path.append(folder)
for script in os.listdir(folder):
if script.endswith(".py"):
try:
mod = __import__(script)
res = mod.run_test()
fh = open("tests.res", "a")
fh.writeline(str(res))
except TypeOfErrorHere:
print "Test case didnt work... continuing"
I hope that helps
#first:
class NorbertQuest(object):
#every function goes in here
#every variable is renamed self.variable
#so if i was "health" it would be "self.health"
#then you can get rid of all the global this and global that
#because using "self" means that is can be accessed all over the class
n = NorbertQuest()
n.RunWhateverIsYourMainFunction()
I used this tutorial and then modified it a bit to make my own chat program
http://www.devshed.com/c/a/Python/Sockets-in-Python-Into-the-World-of-Python-Network-Programming/
You can use pickle, that is useful because it saves the data as it is, so if you have a class you can save the class, and then you load it and it is exactly the same as it was when you saved it.
For that you would need to change norbert quest to a class, that shouldn't take too long.
The module you need is Pickle or shelve, google them if you havent used them before
For that you will need to use a GUI toolkit, have a look at Tkinter, wxPython, or pyQT. They are good ones. We have a whole sticky on learning wx so if you want to learn there are lots of resources here.
Tkinter comes packaged
wxPython can be downloaded from wxpython.org
and i have no idea about pyQT
Yeah there sure is
#use the current directory or absolute path
f = open("File.txt",'w') #write mode 'w'
answer = 5*3
#make a string, only stings can be added to files
answer = str(answer)
f.write(answer)
f.close()
#then open it back up
o = open("File.txt",'r') #read mode 'r'
print o.readline()
#Output:
#15
I think you should just make a reset heath function
while True:
print \
"""
Welcome to NorbertQuest!
Type:
- [battle] to hunt monsters
- [shop] to buy weapons
- [exit] to quit the game.
"""
mode = raw_input("What do you want to do?: ")
if mode == "shop":
Shop()
while mode == "battle":
fight = random.randrange(10)+1
if fight == 1:
monster = "Dragon!"
elif fight == 2:
monster = "Wild Cayote!"
elif fight == 3:
monster == "Jaguar!"
elif fight == 4:
monster = "Orc Lord!"
elif fight == 5:
monster = "Goblin!"
elif fight == 6:
monster = "Crazy Robot!"
elif fight == 7:
monster = "Werewolf!"
elif fight == 8:
monster = "Vampire!"
elif fight == 9:
monster = "Giant Spider!"
elif fight == 10:
monster = "Pirate King"
turn = raw_input("Do you want to Attack or Defend?")
if"attack"in turn:
print"You're attacking!"
EnemyHP()
HP()
elif"defend"in turn:
print"You're defending!"
print"Monster's HP is",ehealth
print"Your HP is",health
else:
print"Type attack or Defend!"
if health <= 0:
print"You are dead!"
mode = "restart"
elif ehealth <= 0:
print "You win the battle! You earn",m,"$!"
money = money + m
resetHP()
def resetHP():
global health
heath = 150
Also this code is dying to be put into a class.
Yeah i would reccomend you do not use python 3.0 for a while, the modules just arent out for it yet.
If you use python 2.5 then you will find that you can get modules for everything you need.
wxPython, XRCed, BoaConstrictor will all have modules for python 2.5.
Here is a site where they do just what you are doing, the first bit talks about unit testing, just ignore that and keep going on, it shows you how to make a roman numeral converter that is almost impossible to break:
http://www.diveintopython.org/unit_testing/index.html
Well if you want them to all be in a different category then you have to get a new number each time. Also you can use random.choice() to get a random choice from a list.
Here is what i would do
import random
house = ["a mansion", "an apartment", "a shack", "a house"]
spouse = ["name1", "name2", "name3", "name4"]
car = ["car1", "car2", "car3", "car4"]
kids = ["no kids", "1 kid", "2 kids", "5 kids"]
print"List 3 people you want to marry in the future:"
spouse[0] = raw_input("1. ")
spouse[1] = raw_input("2. ")
spouse[2] = raw_input("3. ")
print"List 1 person who you don't like: "
spouse[3] = raw_input("1. ")
print"List 3 cars you want in the future:"
car[0] = raw_input("1. ")
car[1] = raw_input("2. ")
car[2] = raw_input("3. ")
print"List 1 car that you don't like: "
car[3] = raw_input("1. ")
#main
while True:
raw_input("Now mashing... Press [enter] for your results")
print "You will live in",random.choice(house)
print "Married to",random.choice(spouse)
print "Driving a",random.choice(car)
print "With",random.choice(kids),"running around the house"
choice = raw_input("Do you want a second chance? Type [n] to quit. ")
if"n"in choice:
break
raw_input("Press [Enter] to exit.")